svelte-spinner
Advanced tools
Comparing version 2.0.1 to 2.0.2
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = global || self, global.Spinner = factory()); | ||
}(this, function () { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = global || self, global.Spinner = factory()); | ||
}(this, (function () { 'use strict'; | ||
function noop() {} | ||
function noop() { } | ||
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 run(fn) { | ||
return fn(); | ||
} | ||
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 element(name) { | ||
return document.createElement(name); | ||
} | ||
function svg_element(name) { | ||
return document.createElementNS('http://www.w3.org/2000/svg', name); | ||
} | ||
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 blank_object() { | ||
return Object.create(null); | ||
} | ||
let current_component; | ||
function set_current_component(component) { | ||
current_component = component; | ||
} | ||
function run_all(fns) { | ||
fns.forEach(run); | ||
} | ||
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($$.dirty); | ||
run_all($$.before_update); | ||
$$.fragment && $$.fragment.p($$.dirty, $$.ctx); | ||
$$.dirty = null; | ||
$$.after_update.forEach(add_render_callback); | ||
} | ||
} | ||
const outroing = new Set(); | ||
function transition_in(block, local) { | ||
if (block && block.i) { | ||
outroing.delete(block); | ||
block.i(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, key) { | ||
if (!component.$$.dirty) { | ||
dirty_components.push(component); | ||
schedule_update(); | ||
component.$$.dirty = blank_object(); | ||
} | ||
component.$$.dirty[key] = true; | ||
} | ||
function init(component, options, instance, create_fragment, not_equal, props) { | ||
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: null | ||
}; | ||
let ready = false; | ||
$$.ctx = instance | ||
? instance(component, prop_values, (key, ret, value = ret) => { | ||
if ($$.ctx && not_equal($$.ctx[key], $$.ctx[key] = value)) { | ||
if ($$.bound[key]) | ||
$$.bound[key](value); | ||
if (ready) | ||
make_dirty(component, key); | ||
} | ||
return ret; | ||
}) | ||
: prop_values; | ||
$$.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 | ||
} | ||
} | ||
function is_function(thing) { | ||
return typeof thing === 'function'; | ||
} | ||
/* src/index.svelte generated by Svelte v3.15.0 */ | ||
function safe_not_equal(a, b) { | ||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); | ||
} | ||
function add_css() { | ||
var style = element("style"); | ||
style.id = "svelte-1bbsd2f-style"; | ||
style.textContent = ".svelte-spinner.svelte-1bbsd2f{transition-property:transform;animation-name:svelte-1bbsd2f-svelte-spinner_infinite-spin;animation-iteration-count:infinite;animation-timing-function:linear}@keyframes svelte-1bbsd2f-svelte-spinner_infinite-spin{from{transform:rotate(0deg)}to{transform:rotate(360deg)}}"; | ||
append(document.head, style); | ||
} | ||
function append(target, node) { | ||
target.appendChild(node); | ||
} | ||
function create_fragment(ctx) { | ||
let svg; | ||
let circle; | ||
let circle_stroke_dasharray_value; | ||
function insert(target, node, anchor) { | ||
target.insertBefore(node, anchor); | ||
} | ||
return { | ||
c() { | ||
svg = svg_element("svg"); | ||
circle = svg_element("circle"); | ||
attr(circle, "role", "presentation"); | ||
attr(circle, "cx", "16"); | ||
attr(circle, "cy", "16"); | ||
attr(circle, "r", ctx.radius); | ||
attr(circle, "stroke", ctx.color); | ||
attr(circle, "fill", "none"); | ||
attr(circle, "stroke-width", ctx.thickness); | ||
attr(circle, "stroke-dasharray", circle_stroke_dasharray_value = "" + (ctx.dash + ",100")); | ||
attr(circle, "stroke-linecap", "round"); | ||
attr(svg, "height", ctx.size); | ||
attr(svg, "width", ctx.size); | ||
set_style(svg, "animation-duration", ctx.speed + "ms"); | ||
attr(svg, "class", "svelte-spinner svelte-1bbsd2f"); | ||
attr(svg, "viewBox", "0 0 32 32"); | ||
}, | ||
m(target, anchor) { | ||
insert(target, svg, anchor); | ||
append(svg, circle); | ||
}, | ||
p(changed, ctx) { | ||
if (changed.radius) { | ||
attr(circle, "r", ctx.radius); | ||
} | ||
function detach(node) { | ||
node.parentNode.removeChild(node); | ||
} | ||
if (changed.color) { | ||
attr(circle, "stroke", ctx.color); | ||
} | ||
function element(name) { | ||
return document.createElement(name); | ||
} | ||
if (changed.thickness) { | ||
attr(circle, "stroke-width", ctx.thickness); | ||
} | ||
function svg_element(name) { | ||
return document.createElementNS('http://www.w3.org/2000/svg', name); | ||
} | ||
if (changed.dash && circle_stroke_dasharray_value !== (circle_stroke_dasharray_value = "" + (ctx.dash + ",100"))) { | ||
attr(circle, "stroke-dasharray", circle_stroke_dasharray_value); | ||
} | ||
function attr(node, attribute, value) { | ||
if (value == null) node.removeAttribute(attribute); | ||
else node.setAttribute(attribute, value); | ||
} | ||
if (changed.size) { | ||
attr(svg, "height", ctx.size); | ||
} | ||
function children(element) { | ||
return Array.from(element.childNodes); | ||
} | ||
if (changed.size) { | ||
attr(svg, "width", ctx.size); | ||
} | ||
function set_style(node, key, value) { | ||
node.style.setProperty(key, value); | ||
} | ||
if (changed.speed) { | ||
set_style(svg, "animation-duration", ctx.speed + "ms"); | ||
} | ||
}, | ||
i: noop, | ||
o: noop, | ||
d(detaching) { | ||
if (detaching) detach(svg); | ||
} | ||
}; | ||
} | ||
let current_component; | ||
function instance($$self, $$props, $$invalidate) { | ||
let { size = 25 } = $$props; | ||
let { speed = 750 } = $$props; | ||
let { color = "rgba(0,0,0,0.4)" } = $$props; | ||
let { thickness = 2 } = $$props; | ||
let { gap = 40 } = $$props; | ||
let { radius = 10 } = $$props; | ||
let dash; | ||
function set_current_component(component) { | ||
current_component = component; | ||
} | ||
$$self.$set = $$props => { | ||
if ("size" in $$props) $$invalidate("size", size = $$props.size); | ||
if ("speed" in $$props) $$invalidate("speed", speed = $$props.speed); | ||
if ("color" in $$props) $$invalidate("color", color = $$props.color); | ||
if ("thickness" in $$props) $$invalidate("thickness", thickness = $$props.thickness); | ||
if ("gap" in $$props) $$invalidate("gap", gap = $$props.gap); | ||
if ("radius" in $$props) $$invalidate("radius", radius = $$props.radius); | ||
}; | ||
const dirty_components = []; | ||
$$self.$$.update = (changed = { radius: 1, gap: 1 }) => { | ||
if (changed.radius || changed.gap) { | ||
$$invalidate("dash", dash = 2 * Math.PI * radius * (100 - gap) / 100); | ||
} | ||
}; | ||
let update_promise; | ||
const binding_callbacks = []; | ||
const render_callbacks = []; | ||
const flush_callbacks = []; | ||
return { | ||
size, | ||
speed, | ||
color, | ||
thickness, | ||
gap, | ||
radius, | ||
dash | ||
}; | ||
} | ||
function schedule_update() { | ||
if (!update_promise) { | ||
update_promise = Promise.resolve(); | ||
update_promise.then(flush); | ||
} | ||
} | ||
class Src extends SvelteComponent { | ||
constructor(options) { | ||
super(); | ||
if (!document.getElementById("svelte-1bbsd2f-style")) add_css(); | ||
function add_render_callback(fn) { | ||
render_callbacks.push(fn); | ||
} | ||
init(this, options, instance, create_fragment, safe_not_equal, { | ||
size: 0, | ||
speed: 0, | ||
color: 0, | ||
thickness: 0, | ||
gap: 0, | ||
radius: 0 | ||
}); | ||
} | ||
} | ||
function flush() { | ||
const seen_callbacks = new Set(); | ||
return Src; | ||
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.shift()(); | ||
// then, once components are updated, call | ||
// afterUpdate functions. This may cause | ||
// subsequent updates... | ||
while (render_callbacks.length) { | ||
const callback = render_callbacks.pop(); | ||
if (!seen_callbacks.has(callback)) { | ||
callback(); | ||
// ...so guard against infinite loops | ||
seen_callbacks.add(callback); | ||
} | ||
} | ||
} while (dirty_components.length); | ||
while (flush_callbacks.length) { | ||
flush_callbacks.pop()(); | ||
} | ||
update_promise = null; | ||
} | ||
function update($$) { | ||
if ($$.fragment) { | ||
$$.update($$.dirty); | ||
run_all($$.before_render); | ||
$$.fragment.p($$.dirty, $$.ctx); | ||
$$.dirty = null; | ||
$$.after_render.forEach(add_render_callback); | ||
} | ||
} | ||
function mount_component(component, target, anchor) { | ||
const { fragment, on_mount, on_destroy, after_render } = component.$$; | ||
fragment.m(target, anchor); | ||
// onMount happens after the initial afterUpdate. Because | ||
// afterUpdate callbacks happen in reverse order (inner first) | ||
// we schedule onMount callbacks before afterUpdate callbacks | ||
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_render.forEach(add_render_callback); | ||
} | ||
function destroy(component, detaching) { | ||
if (component.$$) { | ||
run_all(component.$$.on_destroy); | ||
component.$$.fragment.d(detaching); | ||
// TODO null out other refs, including component.$$ (but need to | ||
// preserve final state?) | ||
component.$$.on_destroy = component.$$.fragment = null; | ||
component.$$.ctx = {}; | ||
} | ||
} | ||
function make_dirty(component, key) { | ||
if (!component.$$.dirty) { | ||
dirty_components.push(component); | ||
schedule_update(); | ||
component.$$.dirty = {}; | ||
} | ||
component.$$.dirty[key] = true; | ||
} | ||
function init(component, options, instance, create_fragment, not_equal$$1, prop_names) { | ||
const parent_component = current_component; | ||
set_current_component(component); | ||
const props = options.props || {}; | ||
const $$ = component.$$ = { | ||
fragment: null, | ||
ctx: null, | ||
// state | ||
props: prop_names, | ||
update: noop, | ||
not_equal: not_equal$$1, | ||
bound: blank_object(), | ||
// lifecycle | ||
on_mount: [], | ||
on_destroy: [], | ||
before_render: [], | ||
after_render: [], | ||
context: new Map(parent_component ? parent_component.$$.context : []), | ||
// everything else | ||
callbacks: blank_object(), | ||
dirty: null | ||
}; | ||
let ready = false; | ||
$$.ctx = instance | ||
? instance(component, props, (key, value) => { | ||
if ($$.ctx && not_equal$$1($$.ctx[key], $$.ctx[key] = value)) { | ||
if ($$.bound[key]) $$.bound[key](value); | ||
if (ready) make_dirty(component, key); | ||
} | ||
}) | ||
: props; | ||
$$.update(); | ||
ready = true; | ||
run_all($$.before_render); | ||
$$.fragment = create_fragment($$.ctx); | ||
if (options.target) { | ||
if (options.hydrate) { | ||
$$.fragment.l(children(options.target)); | ||
} else { | ||
$$.fragment.c(); | ||
} | ||
if (options.intro && component.$$.fragment.i) component.$$.fragment.i(); | ||
mount_component(component, options.target, options.anchor); | ||
flush(); | ||
} | ||
set_current_component(parent_component); | ||
} | ||
class SvelteComponent { | ||
$destroy() { | ||
destroy(this, true); | ||
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/index.svelte generated by Svelte v3.0.0 */ | ||
function add_css() { | ||
var style = element("style"); | ||
style.id = 'svelte-1bbsd2f-style'; | ||
style.textContent = ".svelte-spinner.svelte-1bbsd2f{transition-property:transform;animation-name:svelte-1bbsd2f-svelte-spinner_infinite-spin;animation-iteration-count:infinite;animation-timing-function:linear}@keyframes svelte-1bbsd2f-svelte-spinner_infinite-spin{from{transform:rotate(0deg)}to{transform:rotate(360deg)}}"; | ||
append(document.head, style); | ||
} | ||
function create_fragment(ctx) { | ||
var svg, circle, circle_stroke_dasharray_value; | ||
return { | ||
c() { | ||
svg = svg_element("svg"); | ||
circle = svg_element("circle"); | ||
attr(circle, "role", "presentation"); | ||
attr(circle, "cx", "16"); | ||
attr(circle, "cy", "16"); | ||
attr(circle, "r", ctx.radius); | ||
attr(circle, "stroke", ctx.color); | ||
attr(circle, "fill", "none"); | ||
attr(circle, "stroke-width", ctx.thickness); | ||
attr(circle, "stroke-dasharray", circle_stroke_dasharray_value = "" + ctx.dash + ",100"); | ||
attr(circle, "stroke-linecap", "round"); | ||
attr(svg, "height", ctx.size); | ||
attr(svg, "width", ctx.size); | ||
set_style(svg, "animation-duration", "" + ctx.speed + "ms"); | ||
attr(svg, "class", "svelte-spinner svelte-1bbsd2f"); | ||
attr(svg, "viewBox", "0 0 32 32"); | ||
}, | ||
m(target, anchor) { | ||
insert(target, svg, anchor); | ||
append(svg, circle); | ||
}, | ||
p(changed, ctx) { | ||
if (changed.radius) { | ||
attr(circle, "r", ctx.radius); | ||
} | ||
if (changed.color) { | ||
attr(circle, "stroke", ctx.color); | ||
} | ||
if (changed.thickness) { | ||
attr(circle, "stroke-width", ctx.thickness); | ||
} | ||
if ((changed.dash) && circle_stroke_dasharray_value !== (circle_stroke_dasharray_value = "" + ctx.dash + ",100")) { | ||
attr(circle, "stroke-dasharray", circle_stroke_dasharray_value); | ||
} | ||
if (changed.size) { | ||
attr(svg, "height", ctx.size); | ||
attr(svg, "width", ctx.size); | ||
} | ||
if (changed.speed) { | ||
set_style(svg, "animation-duration", "" + ctx.speed + "ms"); | ||
} | ||
}, | ||
i: noop, | ||
o: noop, | ||
d(detaching) { | ||
if (detaching) { | ||
detach(svg); | ||
} | ||
} | ||
}; | ||
} | ||
function instance($$self, $$props, $$invalidate) { | ||
let { size = 25, speed = 750, color = 'rgba(0,0,0,0.4)', thickness = 2, gap = 40, radius = 10 } = $$props; | ||
let dash; | ||
$$self.$set = $$props => { | ||
if ('size' in $$props) $$invalidate('size', size = $$props.size); | ||
if ('speed' in $$props) $$invalidate('speed', speed = $$props.speed); | ||
if ('color' in $$props) $$invalidate('color', color = $$props.color); | ||
if ('thickness' in $$props) $$invalidate('thickness', thickness = $$props.thickness); | ||
if ('gap' in $$props) $$invalidate('gap', gap = $$props.gap); | ||
if ('radius' in $$props) $$invalidate('radius', radius = $$props.radius); | ||
}; | ||
$$self.$$.update = ($$dirty = { radius: 1, gap: 1 }) => { | ||
if ($$dirty.radius || $$dirty.gap) { $$invalidate('dash', dash = 2 * Math.PI * radius * (100 - gap) / 100); } | ||
}; | ||
return { | ||
size, | ||
speed, | ||
color, | ||
thickness, | ||
gap, | ||
radius, | ||
dash | ||
}; | ||
} | ||
class Index extends SvelteComponent { | ||
constructor(options) { | ||
super(); | ||
if (!document.getElementById("svelte-1bbsd2f-style")) add_css(); | ||
init(this, options, instance, create_fragment, safe_not_equal, ["size", "speed", "color", "thickness", "gap", "radius"]); | ||
} | ||
} | ||
return Index; | ||
})); | ||
}))); |
{ | ||
"name": "svelte-spinner", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "A Svelte SVG loading spinner", | ||
@@ -12,6 +12,6 @@ "svelte": "src/index.svelte", | ||
"devDependencies": { | ||
"rollup": "^1.10.1", | ||
"rollup-plugin-node-resolve": "^4.2.3", | ||
"rollup-plugin-svelte": "^5.0.3", | ||
"svelte": "^3.0.0" | ||
"rollup": "^1.27.5", | ||
"rollup-plugin-node-resolve": "^5.2.0", | ||
"rollup-plugin-svelte": "^5.1.1", | ||
"svelte": "^3.15.0" | ||
}, | ||
@@ -18,0 +18,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
89543
467