UNPKG

svelte-ticker

Version:
641 lines (583 loc) 20.4 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global = global || self, global.Ticker = factory()); }(this, (function () { 'use strict'; function noop() { } function assign(tar, src) { // @ts-ignore for (const k in src) tar[k] = src[k]; return tar; } function run(fn) { return fn(); } function blank_object() { return Object.create(null); } function run_all(fns) { fns.forEach(run); } function is_function(thing) { return typeof thing === 'function'; } function safe_not_equal(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function create_slot(definition, ctx, $$scope, fn) { if (definition) { const slot_ctx = get_slot_context(definition, ctx, $$scope, fn); return definition[0](slot_ctx); } } function get_slot_context(definition, ctx, $$scope, fn) { return definition[1] && fn ? assign($$scope.ctx.slice(), definition[1](fn(ctx))) : $$scope.ctx; } function get_slot_changes(definition, $$scope, dirty, fn) { if (definition[2] && fn) { const lets = definition[2](fn(dirty)); if ($$scope.dirty) { const merged = []; const len = Math.max($$scope.dirty.length, lets.length); for (let i = 0; i < len; i += 1) { merged[i] = $$scope.dirty[i] | lets[i]; } return merged; } return lets; } return $$scope.dirty; } function append(target, node) { target.appendChild(node); } function insert(target, node, anchor) { target.insertBefore(node, anchor || null); } function detach(node) { node.parentNode.removeChild(node); } function destroy_each(iterations, detaching) { for (let i = 0; i < iterations.length; i += 1) { if (iterations[i]) iterations[i].d(detaching); } } function element(name) { return document.createElement(name); } function text(data) { return document.createTextNode(data); } function listen(node, event, handler, options) { node.addEventListener(event, handler, options); return () => node.removeEventListener(event, handler, options); } function attr(node, attribute, value) { if (value == null) node.removeAttribute(attribute); else if (node.getAttribute(attribute) !== value) node.setAttribute(attribute, value); } function children(element) { return Array.from(element.childNodes); } function set_style(node, key, value, important) { node.style.setProperty(key, value, important ? 'important' : ''); } function toggle_class(element, name, toggle) { element.classList[toggle ? 'add' : 'remove'](name); } let current_component; function set_current_component(component) { current_component = component; } function get_current_component() { if (!current_component) throw new Error(`Function called outside component initialization`); return current_component; } function onMount(fn) { get_current_component().$$.on_mount.push(fn); } const dirty_components = []; const binding_callbacks = []; const render_callbacks = []; const flush_callbacks = []; const resolved_promise = Promise.resolve(); let update_scheduled = false; function schedule_update() { if (!update_scheduled) { update_scheduled = true; resolved_promise.then(flush); } } function add_render_callback(fn) { render_callbacks.push(fn); } function flush() { const seen_callbacks = new Set(); do { // first, call beforeUpdate functions // and update components while (dirty_components.length) { const component = dirty_components.shift(); set_current_component(component); update(component.$$); } while (binding_callbacks.length) binding_callbacks.pop()(); // then, once components are updated, call // afterUpdate functions. This may cause // subsequent updates... for (let i = 0; i < render_callbacks.length; i += 1) { const callback = render_callbacks[i]; if (!seen_callbacks.has(callback)) { callback(); // ...so guard against infinite loops seen_callbacks.add(callback); } } render_callbacks.length = 0; } while (dirty_components.length); while (flush_callbacks.length) { flush_callbacks.pop()(); } update_scheduled = false; } function update($$) { if ($$.fragment !== null) { $$.update(); run_all($$.before_update); $$.fragment && $$.fragment.p($$.ctx, $$.dirty); $$.dirty = [-1]; $$.after_update.forEach(add_render_callback); } } const outroing = new Set(); let outros; function group_outros() { outros = { r: 0, c: [], p: outros // parent group }; } function check_outros() { if (!outros.r) { run_all(outros.c); } outros = outros.p; } function transition_in(block, local) { if (block && block.i) { outroing.delete(block); block.i(local); } } function transition_out(block, local, detach, callback) { if (block && block.o) { if (outroing.has(block)) return; outroing.add(block); outros.c.push(() => { outroing.delete(block); if (callback) { if (detach) block.d(1); callback(); } }); block.o(local); } } function mount_component(component, target, anchor) { const { fragment, on_mount, on_destroy, after_update } = component.$$; fragment && fragment.m(target, anchor); // onMount happens before the initial afterUpdate add_render_callback(() => { const new_on_destroy = on_mount.map(run).filter(is_function); if (on_destroy) { on_destroy.push(...new_on_destroy); } else { // Edge case - component was destroyed immediately, // most likely as a result of a binding initialising run_all(new_on_destroy); } component.$$.on_mount = []; }); after_update.forEach(add_render_callback); } function destroy_component(component, detaching) { const $$ = component.$$; if ($$.fragment !== null) { run_all($$.on_destroy); $$.fragment && $$.fragment.d(detaching); // TODO null out other refs, including component.$$ (but need to // preserve final state?) $$.on_destroy = $$.fragment = null; $$.ctx = []; } } function make_dirty(component, i) { if (component.$$.dirty[0] === -1) { dirty_components.push(component); schedule_update(); component.$$.dirty.fill(0); } component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31)); } function init(component, options, instance, create_fragment, not_equal, props, dirty = [-1]) { const parent_component = current_component; set_current_component(component); const prop_values = options.props || {}; const $$ = component.$$ = { fragment: null, ctx: null, // state props, update: noop, not_equal, bound: blank_object(), // lifecycle on_mount: [], on_destroy: [], before_update: [], after_update: [], context: new Map(parent_component ? parent_component.$$.context : []), // everything else callbacks: blank_object(), dirty }; let ready = false; $$.ctx = instance ? instance(component, prop_values, (i, ret, value = ret) => { if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) { if ($$.bound[i]) $$.bound[i](value); if (ready) make_dirty(component, i); } return ret; }) : []; $$.update(); ready = true; run_all($$.before_update); // `false` as a special case of no DOM component $$.fragment = create_fragment ? create_fragment($$.ctx) : false; if (options.target) { if (options.hydrate) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion $$.fragment && $$.fragment.l(children(options.target)); } else { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion $$.fragment && $$.fragment.c(); } if (options.intro) transition_in(component.$$.fragment); mount_component(component, options.target, options.anchor); flush(); } set_current_component(parent_component); } class SvelteComponent { $destroy() { destroy_component(this, 1); this.$destroy = noop; } $on(type, callback) { const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = [])); callbacks.push(callback); return () => { const index = callbacks.indexOf(callback); if (index !== -1) callbacks.splice(index, 1); }; } $set() { // overridden by instance, if it has props } } /* src/Ticker.svelte generated by Svelte v3.16.4 */ function add_css() { var style = element("style"); style.id = "svelte-b51jmc-style"; 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%)}}"; append(document.head, style); } function get_each_context(ctx, list, i) { const child_ctx = ctx.slice(); child_ctx[23] = list[i]; return child_ctx; } // (12:0) {#each Array(1 + rags) as _} function create_each_block(ctx) { let t; let current; const default_slot_template = /*$$slots*/ ctx[21].default; const default_slot = create_slot(default_slot_template, ctx, /*$$scope*/ ctx[20], null); return { c() { if (!default_slot) { t = text("Ticker default content"); } if (default_slot) default_slot.c(); }, m(target, anchor) { if (!default_slot) { insert(target, t, anchor); } if (default_slot) { default_slot.m(target, anchor); } current = true; }, p(ctx, dirty) { if (default_slot && default_slot.p && dirty[0] & /*$$scope*/ 1048576) { 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)); } }, i(local) { if (current) return; transition_in(default_slot, local); current = true; }, o(local) { transition_out(default_slot, local); current = false; }, d(detaching) { if (!default_slot) { if (detaching) detach(t); } if (default_slot) default_slot.d(detaching); } }; } function create_fragment(ctx) { let div; let current; let dispose; let each_value = Array(1 + /*rags*/ ctx[9]); let each_blocks = []; for (let i = 0; i < each_value.length; i += 1) { each_blocks[i] = create_each_block(get_each_context(ctx, each_value, i)); } const out = i => transition_out(each_blocks[i], 1, 1, () => { each_blocks[i] = null; }); return { c() { div = element("div"); for (let i = 0; i < each_blocks.length; i += 1) { each_blocks[i].c(); } set_style(div, "animation-duration", /*duration*/ ctx[1] + "s"); set_style(div, "animation-delay", /*delay*/ ctx[2] + "s"); set_style(div, "animation-iteration-count", /*iterations*/ ctx[7]); set_style(div, "animation-direction", /*dir*/ ctx[8]); attr(div, "class", "svelte-b51jmc"); toggle_class(div, "animate", /*animate*/ ctx[3]); toggle_class(div, "horizontal", /*horizontal*/ ctx[5]); toggle_class(div, "vertical", /*vertical*/ ctx[6]); toggle_class(div, "pausing", /*pausing*/ ctx[0]); dispose = listen(window, "resize", /*sizing*/ ctx[10]); }, m(target, anchor) { insert(target, div, anchor); for (let i = 0; i < each_blocks.length; i += 1) { each_blocks[i].m(div, null); } /*div_binding*/ ctx[22](div); current = true; }, p(ctx, dirty) { if (dirty[0] & /*$$scope, rags*/ 1049088) { each_value = Array(1 + /*rags*/ ctx[9]); let i; for (i = 0; i < each_value.length; i += 1) { const child_ctx = get_each_context(ctx, each_value, i); if (each_blocks[i]) { each_blocks[i].p(child_ctx, dirty); transition_in(each_blocks[i], 1); } else { each_blocks[i] = create_each_block(child_ctx); each_blocks[i].c(); transition_in(each_blocks[i], 1); each_blocks[i].m(div, null); } } group_outros(); for (i = each_value.length; i < each_blocks.length; i += 1) { out(i); } check_outros(); } if (!current || dirty[0] & /*duration*/ 2) { set_style(div, "animation-duration", /*duration*/ ctx[1] + "s"); } if (!current || dirty[0] & /*delay*/ 4) { set_style(div, "animation-delay", /*delay*/ ctx[2] + "s"); } if (!current || dirty[0] & /*iterations*/ 128) { set_style(div, "animation-iteration-count", /*iterations*/ ctx[7]); } if (!current || dirty[0] & /*dir*/ 256) { set_style(div, "animation-direction", /*dir*/ ctx[8]); } if (dirty[0] & /*animate*/ 8) { toggle_class(div, "animate", /*animate*/ ctx[3]); } if (dirty[0] & /*horizontal*/ 32) { toggle_class(div, "horizontal", /*horizontal*/ ctx[5]); } if (dirty[0] & /*vertical*/ 64) { toggle_class(div, "vertical", /*vertical*/ ctx[6]); } if (dirty[0] & /*pausing*/ 1) { toggle_class(div, "pausing", /*pausing*/ ctx[0]); } }, i(local) { if (current) return; for (let i = 0; i < each_value.length; i += 1) { transition_in(each_blocks[i]); } current = true; }, o(local) { each_blocks = each_blocks.filter(Boolean); for (let i = 0; i < each_blocks.length; i += 1) { transition_out(each_blocks[i]); } current = false; }, d(detaching) { if (detaching) detach(div); destroy_each(each_blocks, detaching); /*div_binding*/ ctx[22](null); dispose(); } }; } function instance($$self, $$props, $$invalidate) { let { direction = "left" } = $$props, { alternate = false } = $$props, { behavior = "auto" } = $$props, animate = false, { pausing = true } = $$props, { duration = 30 } = $$props, { loop = true } = $$props, { delay = 0 } = $$props, parentSize, size, self; function sizing() { (!rags || !size) && $$invalidate(16, size = self[measure]); $$invalidate(15, parentSize = self.parentNode[measure]); $$invalidate(3, animate = behavior === "always" || size > parentSize); } onMount(sizing); let { $$slots = {}, $$scope } = $$props; function div_binding($$value) { binding_callbacks[$$value ? "unshift" : "push"](() => { $$invalidate(4, self = $$value); }); } $$self.$set = $$props => { if ("direction" in $$props) $$invalidate(11, direction = $$props.direction); if ("alternate" in $$props) $$invalidate(12, alternate = $$props.alternate); if ("behavior" in $$props) $$invalidate(13, behavior = $$props.behavior); if ("pausing" in $$props) $$invalidate(0, pausing = $$props.pausing); if ("duration" in $$props) $$invalidate(1, duration = $$props.duration); if ("loop" in $$props) $$invalidate(14, loop = $$props.loop); if ("delay" in $$props) $$invalidate(2, delay = $$props.delay); if ("$$scope" in $$props) $$invalidate(20, $$scope = $$props.$$scope); }; let reverse; let horizontal; let vertical; let measure; let iterations; let dir; let ext; let rags; $$self.$$.update = () => { if ($$self.$$.dirty[0] & /*direction*/ 2048) { $$invalidate(17, reverse = direction === "right" || direction === "bottom"); } if ($$self.$$.dirty[0] & /*direction*/ 2048) { $$invalidate(5, horizontal = direction === "left" || direction === "right"); } if ($$self.$$.dirty[0] & /*horizontal*/ 32) { $$invalidate(6, vertical = !horizontal); } if ($$self.$$.dirty[0] & /*horizontal*/ 32) { measure = horizontal ? "clientWidth" : "clientHeight"; } if ($$self.$$.dirty[0] & /*loop*/ 16384) { $$invalidate(7, iterations = typeof loop === "number" ? loop : loop ? "infinite" : 1); } if ($$self.$$.dirty[0] & /*reverse, alternate*/ 135168) { $$invalidate(8, dir = reverse ? alternate ? "alternate-reverse" : "reverse" : alternate ? "alternate" : "normal"); } if ($$self.$$.dirty[0] & /*behavior, parentSize, size*/ 106496) { $$invalidate(19, ext = behavior === "always" && parentSize > size ? Math.ceil(parentSize / size) : 0); } if ($$self.$$.dirty[0] & /*ext, animate, loop, alternate*/ 544776) { $$invalidate(9, rags = ext + (animate && loop && !alternate)); } }; return [ pausing, duration, delay, animate, self, horizontal, vertical, iterations, dir, rags, sizing, direction, alternate, behavior, loop, parentSize, size, reverse, measure, ext, $$scope, $$slots, div_binding ]; } class Ticker extends SvelteComponent { constructor(options) { super(); if (!document.getElementById("svelte-b51jmc-style")) add_css(); init(this, options, instance, create_fragment, safe_not_equal, { direction: 11, alternate: 12, behavior: 13, pausing: 0, duration: 1, loop: 14, delay: 2 }); } } return Ticker; })));