1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
3 | typeof define === 'function' && define.amd ? define(factory) :
|
4 | (global = global || self, global.Ticker = factory());
|
5 | }(this, (function () { 'use strict';
|
6 |
|
7 | function noop() { }
|
8 | function assign(tar, src) {
|
9 |
|
10 | for (const k in src)
|
11 | tar[k] = src[k];
|
12 | return tar;
|
13 | }
|
14 | function run(fn) {
|
15 | return fn();
|
16 | }
|
17 | function blank_object() {
|
18 | return Object.create(null);
|
19 | }
|
20 | function run_all(fns) {
|
21 | fns.forEach(run);
|
22 | }
|
23 | function is_function(thing) {
|
24 | return typeof thing === 'function';
|
25 | }
|
26 | function safe_not_equal(a, b) {
|
27 | return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
28 | }
|
29 | function create_slot(definition, ctx, $$scope, fn) {
|
30 | if (definition) {
|
31 | const slot_ctx = get_slot_context(definition, ctx, $$scope, fn);
|
32 | return definition[0](slot_ctx);
|
33 | }
|
34 | }
|
35 | function get_slot_context(definition, ctx, $$scope, fn) {
|
36 | return definition[1] && fn
|
37 | ? assign($$scope.ctx.slice(), definition[1](fn(ctx)))
|
38 | : $$scope.ctx;
|
39 | }
|
40 | function get_slot_changes(definition, $$scope, dirty, fn) {
|
41 | if (definition[2] && fn) {
|
42 | const lets = definition[2](fn(dirty));
|
43 | if ($$scope.dirty) {
|
44 | const merged = [];
|
45 | const len = Math.max($$scope.dirty.length, lets.length);
|
46 | for (let i = 0; i < len; i += 1) {
|
47 | merged[i] = $$scope.dirty[i] | lets[i];
|
48 | }
|
49 | return merged;
|
50 | }
|
51 | return lets;
|
52 | }
|
53 | return $$scope.dirty;
|
54 | }
|
55 |
|
56 | function append(target, node) {
|
57 | target.appendChild(node);
|
58 | }
|
59 | function insert(target, node, anchor) {
|
60 | target.insertBefore(node, anchor || null);
|
61 | }
|
62 | function detach(node) {
|
63 | node.parentNode.removeChild(node);
|
64 | }
|
65 | function destroy_each(iterations, detaching) {
|
66 | for (let i = 0; i < iterations.length; i += 1) {
|
67 | if (iterations[i])
|
68 | iterations[i].d(detaching);
|
69 | }
|
70 | }
|
71 | function element(name) {
|
72 | return document.createElement(name);
|
73 | }
|
74 | function text(data) {
|
75 | return document.createTextNode(data);
|
76 | }
|
77 | function listen(node, event, handler, options) {
|
78 | node.addEventListener(event, handler, options);
|
79 | return () => node.removeEventListener(event, handler, options);
|
80 | }
|
81 | function attr(node, attribute, value) {
|
82 | if (value == null)
|
83 | node.removeAttribute(attribute);
|
84 | else if (node.getAttribute(attribute) !== value)
|
85 | node.setAttribute(attribute, value);
|
86 | }
|
87 | function children(element) {
|
88 | return Array.from(element.childNodes);
|
89 | }
|
90 | function set_style(node, key, value, important) {
|
91 | node.style.setProperty(key, value, important ? 'important' : '');
|
92 | }
|
93 | function toggle_class(element, name, toggle) {
|
94 | element.classList[toggle ? 'add' : 'remove'](name);
|
95 | }
|
96 |
|
97 | let current_component;
|
98 | function set_current_component(component) {
|
99 | current_component = component;
|
100 | }
|
101 | function get_current_component() {
|
102 | if (!current_component)
|
103 | throw new Error(`Function called outside component initialization`);
|
104 | return current_component;
|
105 | }
|
106 | function onMount(fn) {
|
107 | get_current_component().$$.on_mount.push(fn);
|
108 | }
|
109 |
|
110 | const dirty_components = [];
|
111 | const binding_callbacks = [];
|
112 | const render_callbacks = [];
|
113 | const flush_callbacks = [];
|
114 | const resolved_promise = Promise.resolve();
|
115 | let update_scheduled = false;
|
116 | function schedule_update() {
|
117 | if (!update_scheduled) {
|
118 | update_scheduled = true;
|
119 | resolved_promise.then(flush);
|
120 | }
|
121 | }
|
122 | function add_render_callback(fn) {
|
123 | render_callbacks.push(fn);
|
124 | }
|
125 | function flush() {
|
126 | const seen_callbacks = new Set();
|
127 | do {
|
128 |
|
129 |
|
130 | while (dirty_components.length) {
|
131 | const component = dirty_components.shift();
|
132 | set_current_component(component);
|
133 | update(component.$$);
|
134 | }
|
135 | while (binding_callbacks.length)
|
136 | binding_callbacks.pop()();
|
137 |
|
138 |
|
139 |
|
140 | for (let i = 0; i < render_callbacks.length; i += 1) {
|
141 | const callback = render_callbacks[i];
|
142 | if (!seen_callbacks.has(callback)) {
|
143 | callback();
|
144 |
|
145 | seen_callbacks.add(callback);
|
146 | }
|
147 | }
|
148 | render_callbacks.length = 0;
|
149 | } while (dirty_components.length);
|
150 | while (flush_callbacks.length) {
|
151 | flush_callbacks.pop()();
|
152 | }
|
153 | update_scheduled = false;
|
154 | }
|
155 | function update($$) {
|
156 | if ($$.fragment !== null) {
|
157 | $$.update();
|
158 | run_all($$.before_update);
|
159 | $$.fragment && $$.fragment.p($$.ctx, $$.dirty);
|
160 | $$.dirty = [-1];
|
161 | $$.after_update.forEach(add_render_callback);
|
162 | }
|
163 | }
|
164 | const outroing = new Set();
|
165 | let outros;
|
166 | function group_outros() {
|
167 | outros = {
|
168 | r: 0,
|
169 | c: [],
|
170 | p: outros
|
171 | };
|
172 | }
|
173 | function check_outros() {
|
174 | if (!outros.r) {
|
175 | run_all(outros.c);
|
176 | }
|
177 | outros = outros.p;
|
178 | }
|
179 | function transition_in(block, local) {
|
180 | if (block && block.i) {
|
181 | outroing.delete(block);
|
182 | block.i(local);
|
183 | }
|
184 | }
|
185 | function transition_out(block, local, detach, callback) {
|
186 | if (block && block.o) {
|
187 | if (outroing.has(block))
|
188 | return;
|
189 | outroing.add(block);
|
190 | outros.c.push(() => {
|
191 | outroing.delete(block);
|
192 | if (callback) {
|
193 | if (detach)
|
194 | block.d(1);
|
195 | callback();
|
196 | }
|
197 | });
|
198 | block.o(local);
|
199 | }
|
200 | }
|
201 | function mount_component(component, target, anchor) {
|
202 | const { fragment, on_mount, on_destroy, after_update } = component.$$;
|
203 | fragment && fragment.m(target, anchor);
|
204 |
|
205 | add_render_callback(() => {
|
206 | const new_on_destroy = on_mount.map(run).filter(is_function);
|
207 | if (on_destroy) {
|
208 | on_destroy.push(...new_on_destroy);
|
209 | }
|
210 | else {
|
211 |
|
212 |
|
213 | run_all(new_on_destroy);
|
214 | }
|
215 | component.$$.on_mount = [];
|
216 | });
|
217 | after_update.forEach(add_render_callback);
|
218 | }
|
219 | function destroy_component(component, detaching) {
|
220 | const $$ = component.$$;
|
221 | if ($$.fragment !== null) {
|
222 | run_all($$.on_destroy);
|
223 | $$.fragment && $$.fragment.d(detaching);
|
224 |
|
225 |
|
226 | $$.on_destroy = $$.fragment = null;
|
227 | $$.ctx = [];
|
228 | }
|
229 | }
|
230 | function make_dirty(component, i) {
|
231 | if (component.$$.dirty[0] === -1) {
|
232 | dirty_components.push(component);
|
233 | schedule_update();
|
234 | component.$$.dirty.fill(0);
|
235 | }
|
236 | component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31));
|
237 | }
|
238 | function init(component, options, instance, create_fragment, not_equal, props, dirty = [-1]) {
|
239 | const parent_component = current_component;
|
240 | set_current_component(component);
|
241 | const prop_values = options.props || {};
|
242 | const $$ = component.$$ = {
|
243 | fragment: null,
|
244 | ctx: null,
|
245 |
|
246 | props,
|
247 | update: noop,
|
248 | not_equal,
|
249 | bound: blank_object(),
|
250 |
|
251 | on_mount: [],
|
252 | on_destroy: [],
|
253 | before_update: [],
|
254 | after_update: [],
|
255 | context: new Map(parent_component ? parent_component.$$.context : []),
|
256 |
|
257 | callbacks: blank_object(),
|
258 | dirty
|
259 | };
|
260 | let ready = false;
|
261 | $$.ctx = instance
|
262 | ? instance(component, prop_values, (i, ret, value = ret) => {
|
263 | if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) {
|
264 | if ($$.bound[i])
|
265 | $$.bound[i](value);
|
266 | if (ready)
|
267 | make_dirty(component, i);
|
268 | }
|
269 | return ret;
|
270 | })
|
271 | : [];
|
272 | $$.update();
|
273 | ready = true;
|
274 | run_all($$.before_update);
|
275 |
|
276 | $$.fragment = create_fragment ? create_fragment($$.ctx) : false;
|
277 | if (options.target) {
|
278 | if (options.hydrate) {
|
279 |
|
280 | $$.fragment && $$.fragment.l(children(options.target));
|
281 | }
|
282 | else {
|
283 |
|
284 | $$.fragment && $$.fragment.c();
|
285 | }
|
286 | if (options.intro)
|
287 | transition_in(component.$$.fragment);
|
288 | mount_component(component, options.target, options.anchor);
|
289 | flush();
|
290 | }
|
291 | set_current_component(parent_component);
|
292 | }
|
293 | class SvelteComponent {
|
294 | $destroy() {
|
295 | destroy_component(this, 1);
|
296 | this.$destroy = noop;
|
297 | }
|
298 | $on(type, callback) {
|
299 | const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = []));
|
300 | callbacks.push(callback);
|
301 | return () => {
|
302 | const index = callbacks.indexOf(callback);
|
303 | if (index !== -1)
|
304 | callbacks.splice(index, 1);
|
305 | };
|
306 | }
|
307 | $set() {
|
308 |
|
309 | }
|
310 | }
|
311 |
|
312 |
|
313 |
|
314 | function add_css() {
|
315 | var style = element("style");
|
316 | style.id = "svelte-b51jmc-style";
|
317 | style.textContent = "div.svelte-b51jmc{transform:translate3d(0, 0, 0)}div.horizontal.svelte-b51jmc{display:inline-block;white-space:nowrap}div.vertical.svelte-b51jmc{display:block;white-space:normal}div.horizontal.svelte-b51jmc>*{display:inline-block!important}div.vertical.svelte-b51jmc>*{display:block!important}div.animate.svelte-b51jmc{animation-timing-function:linear}div.pausing.svelte-b51jmc:hover{animation-play-state:paused}div.animate.horizontal.svelte-b51jmc{animation-name:svelte-b51jmc-horizontal}div.animate.vertical.svelte-b51jmc{animation-name:svelte-b51jmc-vertical}@keyframes svelte-b51jmc-horizontal{0%{transform:translateX(0%)}100%{transform:translateX(-50%)}}@keyframes svelte-b51jmc-vertical{0%{transform:translateY(0%)}100%{transform:translateY(-50%)}}";
|
318 | append(document.head, style);
|
319 | }
|
320 |
|
321 | function get_each_context(ctx, list, i) {
|
322 | const child_ctx = ctx.slice();
|
323 | child_ctx[23] = list[i];
|
324 | return child_ctx;
|
325 | }
|
326 |
|
327 |
|
328 | function create_each_block(ctx) {
|
329 | let t;
|
330 | let current;
|
331 | const default_slot_template = ctx[21].default;
|
332 | const default_slot = create_slot(default_slot_template, ctx, ctx[20], null);
|
333 |
|
334 | return {
|
335 | c() {
|
336 | if (!default_slot) {
|
337 | t = text("Ticker default content");
|
338 | }
|
339 |
|
340 | if (default_slot) default_slot.c();
|
341 | },
|
342 | m(target, anchor) {
|
343 | if (!default_slot) {
|
344 | insert(target, t, anchor);
|
345 | }
|
346 |
|
347 | if (default_slot) {
|
348 | default_slot.m(target, anchor);
|
349 | }
|
350 |
|
351 | current = true;
|
352 | },
|
353 | p(ctx, dirty) {
|
354 | if (default_slot && default_slot.p && dirty[0] & 1048576) {
|
355 | default_slot.p(get_slot_context(default_slot_template, ctx, ctx[20], null), get_slot_changes(default_slot_template, ctx[20], dirty, null));
|
356 | }
|
357 | },
|
358 | i(local) {
|
359 | if (current) return;
|
360 | transition_in(default_slot, local);
|
361 | current = true;
|
362 | },
|
363 | o(local) {
|
364 | transition_out(default_slot, local);
|
365 | current = false;
|
366 | },
|
367 | d(detaching) {
|
368 | if (!default_slot) {
|
369 | if (detaching) detach(t);
|
370 | }
|
371 |
|
372 | if (default_slot) default_slot.d(detaching);
|
373 | }
|
374 | };
|
375 | }
|
376 |
|
377 | function create_fragment(ctx) {
|
378 | let div;
|
379 | let current;
|
380 | let dispose;
|
381 | let each_value = Array(1 + ctx[9]);
|
382 | let each_blocks = [];
|
383 |
|
384 | for (let i = 0; i < each_value.length; i += 1) {
|
385 | each_blocks[i] = create_each_block(get_each_context(ctx, each_value, i));
|
386 | }
|
387 |
|
388 | const out = i => transition_out(each_blocks[i], 1, 1, () => {
|
389 | each_blocks[i] = null;
|
390 | });
|
391 |
|
392 | return {
|
393 | c() {
|
394 | div = element("div");
|
395 |
|
396 | for (let i = 0; i < each_blocks.length; i += 1) {
|
397 | each_blocks[i].c();
|
398 | }
|
399 |
|
400 | set_style(div, "animation-duration", ctx[1] + "s");
|
401 | set_style(div, "animation-delay", ctx[2] + "s");
|
402 | set_style(div, "animation-iteration-count", ctx[7]);
|
403 | set_style(div, "animation-direction", ctx[8]);
|
404 | attr(div, "class", "svelte-b51jmc");
|
405 | toggle_class(div, "animate", ctx[3]);
|
406 | toggle_class(div, "horizontal", ctx[5]);
|
407 | toggle_class(div, "vertical", ctx[6]);
|
408 | toggle_class(div, "pausing", ctx[0]);
|
409 | dispose = listen(window, "resize", ctx[10]);
|
410 | },
|
411 | m(target, anchor) {
|
412 | insert(target, div, anchor);
|
413 |
|
414 | for (let i = 0; i < each_blocks.length; i += 1) {
|
415 | each_blocks[i].m(div, null);
|
416 | }
|
417 |
|
418 | ctx[22](div);
|
419 | current = true;
|
420 | },
|
421 | p(ctx, dirty) {
|
422 | if (dirty[0] & 1049088) {
|
423 | each_value = Array(1 + ctx[9]);
|
424 | let i;
|
425 |
|
426 | for (i = 0; i < each_value.length; i += 1) {
|
427 | const child_ctx = get_each_context(ctx, each_value, i);
|
428 |
|
429 | if (each_blocks[i]) {
|
430 | each_blocks[i].p(child_ctx, dirty);
|
431 | transition_in(each_blocks[i], 1);
|
432 | } else {
|
433 | each_blocks[i] = create_each_block(child_ctx);
|
434 | each_blocks[i].c();
|
435 | transition_in(each_blocks[i], 1);
|
436 | each_blocks[i].m(div, null);
|
437 | }
|
438 | }
|
439 |
|
440 | group_outros();
|
441 |
|
442 | for (i = each_value.length; i < each_blocks.length; i += 1) {
|
443 | out(i);
|
444 | }
|
445 |
|
446 | check_outros();
|
447 | }
|
448 |
|
449 | if (!current || dirty[0] & 2) {
|
450 | set_style(div, "animation-duration", ctx[1] + "s");
|
451 | }
|
452 |
|
453 | if (!current || dirty[0] & 4) {
|
454 | set_style(div, "animation-delay", ctx[2] + "s");
|
455 | }
|
456 |
|
457 | if (!current || dirty[0] & 128) {
|
458 | set_style(div, "animation-iteration-count", ctx[7]);
|
459 | }
|
460 |
|
461 | if (!current || dirty[0] & 256) {
|
462 | set_style(div, "animation-direction", ctx[8]);
|
463 | }
|
464 |
|
465 | if (dirty[0] & 8) {
|
466 | toggle_class(div, "animate", ctx[3]);
|
467 | }
|
468 |
|
469 | if (dirty[0] & 32) {
|
470 | toggle_class(div, "horizontal", ctx[5]);
|
471 | }
|
472 |
|
473 | if (dirty[0] & 64) {
|
474 | toggle_class(div, "vertical", ctx[6]);
|
475 | }
|
476 |
|
477 | if (dirty[0] & 1) {
|
478 | toggle_class(div, "pausing", ctx[0]);
|
479 | }
|
480 | },
|
481 | i(local) {
|
482 | if (current) return;
|
483 |
|
484 | for (let i = 0; i < each_value.length; i += 1) {
|
485 | transition_in(each_blocks[i]);
|
486 | }
|
487 |
|
488 | current = true;
|
489 | },
|
490 | o(local) {
|
491 | each_blocks = each_blocks.filter(Boolean);
|
492 |
|
493 | for (let i = 0; i < each_blocks.length; i += 1) {
|
494 | transition_out(each_blocks[i]);
|
495 | }
|
496 |
|
497 | current = false;
|
498 | },
|
499 | d(detaching) {
|
500 | if (detaching) detach(div);
|
501 | destroy_each(each_blocks, detaching);
|
502 | ctx[22](null);
|
503 | dispose();
|
504 | }
|
505 | };
|
506 | }
|
507 |
|
508 | function instance($$self, $$props, $$invalidate) {
|
509 | let { direction = "left" } = $$props,
|
510 | { alternate = false } = $$props,
|
511 | { behavior = "auto" } = $$props,
|
512 | animate = false,
|
513 | { pausing = true } = $$props,
|
514 | { duration = 30 } = $$props,
|
515 | { loop = true } = $$props,
|
516 | { delay = 0 } = $$props,
|
517 | parentSize,
|
518 | size,
|
519 | self;
|
520 |
|
521 | function sizing() {
|
522 | (!rags || !size) && $$invalidate(16, size = self[measure]);
|
523 | $$invalidate(15, parentSize = self.parentNode[measure]);
|
524 | $$invalidate(3, animate = behavior === "always" || size > parentSize);
|
525 | }
|
526 |
|
527 | onMount(sizing);
|
528 | let { $$slots = {}, $$scope } = $$props;
|
529 |
|
530 | function div_binding($$value) {
|
531 | binding_callbacks[$$value ? "unshift" : "push"](() => {
|
532 | $$invalidate(4, self = $$value);
|
533 | });
|
534 | }
|
535 |
|
536 | $$self.$set = $$props => {
|
537 | if ("direction" in $$props) $$invalidate(11, direction = $$props.direction);
|
538 | if ("alternate" in $$props) $$invalidate(12, alternate = $$props.alternate);
|
539 | if ("behavior" in $$props) $$invalidate(13, behavior = $$props.behavior);
|
540 | if ("pausing" in $$props) $$invalidate(0, pausing = $$props.pausing);
|
541 | if ("duration" in $$props) $$invalidate(1, duration = $$props.duration);
|
542 | if ("loop" in $$props) $$invalidate(14, loop = $$props.loop);
|
543 | if ("delay" in $$props) $$invalidate(2, delay = $$props.delay);
|
544 | if ("$$scope" in $$props) $$invalidate(20, $$scope = $$props.$$scope);
|
545 | };
|
546 |
|
547 | let reverse;
|
548 | let horizontal;
|
549 | let vertical;
|
550 | let measure;
|
551 | let iterations;
|
552 | let dir;
|
553 | let ext;
|
554 | let rags;
|
555 |
|
556 | $$self.$$.update = () => {
|
557 | if ($$self.$$.dirty[0] & 2048) {
|
558 | $$invalidate(17, reverse = direction === "right" || direction === "bottom");
|
559 | }
|
560 |
|
561 | if ($$self.$$.dirty[0] & 2048) {
|
562 | $$invalidate(5, horizontal = direction === "left" || direction === "right");
|
563 | }
|
564 |
|
565 | if ($$self.$$.dirty[0] & 32) {
|
566 | $$invalidate(6, vertical = !horizontal);
|
567 | }
|
568 |
|
569 | if ($$self.$$.dirty[0] & 32) {
|
570 | measure = horizontal ? "clientWidth" : "clientHeight";
|
571 | }
|
572 |
|
573 | if ($$self.$$.dirty[0] & 16384) {
|
574 | $$invalidate(7, iterations = typeof loop === "number" ? loop : loop ? "infinite" : 1);
|
575 | }
|
576 |
|
577 | if ($$self.$$.dirty[0] & 135168) {
|
578 | $$invalidate(8, dir = reverse
|
579 | ? alternate ? "alternate-reverse" : "reverse"
|
580 | : alternate ? "alternate" : "normal");
|
581 | }
|
582 |
|
583 | if ($$self.$$.dirty[0] & 106496) {
|
584 | $$invalidate(19, ext = behavior === "always" && parentSize > size
|
585 | ? Math.ceil(parentSize / size)
|
586 | : 0);
|
587 | }
|
588 |
|
589 | if ($$self.$$.dirty[0] & 544776) {
|
590 | $$invalidate(9, rags = ext + (animate && loop && !alternate));
|
591 | }
|
592 | };
|
593 |
|
594 | return [
|
595 | pausing,
|
596 | duration,
|
597 | delay,
|
598 | animate,
|
599 | self,
|
600 | horizontal,
|
601 | vertical,
|
602 | iterations,
|
603 | dir,
|
604 | rags,
|
605 | sizing,
|
606 | direction,
|
607 | alternate,
|
608 | behavior,
|
609 | loop,
|
610 | parentSize,
|
611 | size,
|
612 | reverse,
|
613 | measure,
|
614 | ext,
|
615 | $$scope,
|
616 | $$slots,
|
617 | div_binding
|
618 | ];
|
619 | }
|
620 |
|
621 | class Ticker extends SvelteComponent {
|
622 | constructor(options) {
|
623 | super();
|
624 | if (!document.getElementById("svelte-b51jmc-style")) add_css();
|
625 |
|
626 | init(this, options, instance, create_fragment, safe_not_equal, {
|
627 | direction: 11,
|
628 | alternate: 12,
|
629 | behavior: 13,
|
630 | pausing: 0,
|
631 | duration: 1,
|
632 | loop: 14,
|
633 | delay: 2
|
634 | });
|
635 | }
|
636 | }
|
637 |
|
638 | return Ticker;
|
639 |
|
640 | })));
|