UNPKG

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