mdi-svelte
Version:
Using Material Design Icons in your Svelte projects.
584 lines (536 loc) • 14.7 kB
JavaScript
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 is_empty(obj) {
return Object.keys(obj).length === 0;
}
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 text(data) {
return document.createTextNode(data);
}
function empty() {
return text('');
}
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_data(text, data) {
data = '' + data;
if (text.wholeText !== data)
text.data = data;
}
let current_component;
function set_current_component(component) {
current_component = component;
}
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);
}
let flushing = false;
const seen_callbacks = new Set();
function flush() {
if (flushing)
return;
flushing = true;
do {
// first, call beforeUpdate functions
// and update components
for (let i = 0; i < dirty_components.length; i += 1) {
const component = dirty_components[i];
set_current_component(component);
update(component.$$);
}
set_current_component(null);
dirty_components.length = 0;
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)) {
// ...so guard against infinite loops
seen_callbacks.add(callback);
callback();
}
}
render_callbacks.length = 0;
} while (dirty_components.length);
while (flush_callbacks.length) {
flush_callbacks.pop()();
}
update_scheduled = false;
flushing = false;
seen_callbacks.clear();
}
function update($$) {
if ($$.fragment !== null) {
$$.update();
run_all($$.before_update);
const dirty = $$.dirty;
$$.dirty = [-1];
$$.fragment && $$.fragment.p($$.ctx, dirty);
$$.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, 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,
skip_bound: false
};
let ready = false;
$$.ctx = instance
? instance(component, prop_values, (i, ret, ...rest) => {
const value = rest.length ? rest[0] : ret;
if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) {
if (!$$.skip_bound && $$.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) {
const nodes = children(options.target);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
$$.fragment && $$.fragment.l(nodes);
nodes.forEach(detach);
}
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($$props) {
if (this.$$set && !is_empty($$props)) {
this.$$.skip_bound = true;
this.$$set($$props);
this.$$.skip_bound = false;
}
}
}
/* src/Index.svelte generated by Svelte v3.28.0 */
function add_css() {
var style = element("style");
style.id = "svelte-dmmfjb-style";
style.textContent = "svg.svelte-dmmfjb{vertical-align:middle}";
append(document.head, style);
}
// (59:0) {#if title}
function create_if_block_2(ctx) {
let title_1;
let t;
return {
c() {
title_1 = svg_element("title");
t = text(/*title*/ ctx[2]);
},
m(target, anchor) {
insert(target, title_1, anchor);
append(title_1, t);
},
p(ctx, dirty) {
if (dirty & /*title*/ 4) set_data(t, /*title*/ ctx[2]);
},
d(detaching) {
if (detaching) detach(title_1);
}
};
}
// (69:3) {:else}
function create_else_block_1(ctx) {
let path_1;
return {
c() {
path_1 = svg_element("path");
attr(path_1, "d", /*path*/ ctx[0]);
},
m(target, anchor) {
insert(target, path_1, anchor);
},
p(ctx, dirty) {
if (dirty & /*path*/ 1) {
attr(path_1, "d", /*path*/ ctx[0]);
}
},
d(detaching) {
if (detaching) detach(path_1);
}
};
}
// (60:0) {#if spin !== false}
function create_if_block(ctx) {
let g;
let path_1;
let g_style_value;
function select_block_type_1(ctx, dirty) {
if (/*inverse*/ ctx[3]) return create_if_block_1;
return create_else_block;
}
let current_block_type = select_block_type_1(ctx);
let if_block = current_block_type(ctx);
return {
c() {
if_block.c();
g = svg_element("g");
path_1 = svg_element("path");
attr(path_1, "d", /*path*/ ctx[0]);
attr(g, "style", g_style_value = `animation: ${/*spinfunc*/ ctx[5]} linear ${/*spintime*/ ctx[4]}s infinite; transform-origin: center`);
},
m(target, anchor) {
if_block.m(target, anchor);
insert(target, g, anchor);
append(g, path_1);
},
p(ctx, dirty) {
if (current_block_type !== (current_block_type = select_block_type_1(ctx))) {
if_block.d(1);
if_block = current_block_type(ctx);
if (if_block) {
if_block.c();
if_block.m(g.parentNode, g);
}
}
if (dirty & /*path*/ 1) {
attr(path_1, "d", /*path*/ ctx[0]);
}
if (dirty & /*spinfunc, spintime*/ 48 && g_style_value !== (g_style_value = `animation: ${/*spinfunc*/ ctx[5]} linear ${/*spintime*/ ctx[4]}s infinite; transform-origin: center`)) {
attr(g, "style", g_style_value);
}
},
d(detaching) {
if_block.d(detaching);
if (detaching) detach(g);
}
};
}
// (63:2) {:else}
function create_else_block(ctx) {
let style_1;
let t;
return {
c() {
style_1 = svg_element("style");
t = text("@keyframes spin { to { transform: rotate(360deg) } }");
},
m(target, anchor) {
insert(target, style_1, anchor);
append(style_1, t);
},
d(detaching) {
if (detaching) detach(style_1);
}
};
}
// (61:2) {#if inverse}
function create_if_block_1(ctx) {
let style_1;
let t;
return {
c() {
style_1 = svg_element("style");
t = text("@keyframes spin-inverse { to { transform: rotate(-360deg) } }");
},
m(target, anchor) {
insert(target, style_1, anchor);
append(style_1, t);
},
d(detaching) {
if (detaching) detach(style_1);
}
};
}
function create_fragment(ctx) {
let svg;
let if_block0_anchor;
let if_block0 = /*title*/ ctx[2] && create_if_block_2(ctx);
function select_block_type(ctx, dirty) {
if (/*spin*/ ctx[1] !== false) return create_if_block;
return create_else_block_1;
}
let current_block_type = select_block_type(ctx);
let if_block1 = current_block_type(ctx);
return {
c() {
svg = svg_element("svg");
if (if_block0) if_block0.c();
if_block0_anchor = empty();
if_block1.c();
attr(svg, "viewBox", "0 0 24 24");
attr(svg, "style", /*style*/ ctx[6]);
attr(svg, "class", "svelte-dmmfjb");
},
m(target, anchor) {
insert(target, svg, anchor);
if (if_block0) if_block0.m(svg, null);
append(svg, if_block0_anchor);
if_block1.m(svg, null);
},
p(ctx, [dirty]) {
if (/*title*/ ctx[2]) {
if (if_block0) {
if_block0.p(ctx, dirty);
} else {
if_block0 = create_if_block_2(ctx);
if_block0.c();
if_block0.m(svg, if_block0_anchor);
}
} else if (if_block0) {
if_block0.d(1);
if_block0 = null;
}
if (current_block_type === (current_block_type = select_block_type(ctx)) && if_block1) {
if_block1.p(ctx, dirty);
} else {
if_block1.d(1);
if_block1 = current_block_type(ctx);
if (if_block1) {
if_block1.c();
if_block1.m(svg, null);
}
}
if (dirty & /*style*/ 64) {
attr(svg, "style", /*style*/ ctx[6]);
}
},
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(svg);
if (if_block0) if_block0.d();
if_block1.d();
}
};
}
function instance($$self, $$props, $$invalidate) {
let { path } = $$props;
let { size = 1 } = $$props;
let { color = null } = $$props;
let { flip = null } = $$props;
let { rotate = 0 } = $$props;
let { spin = false } = $$props;
let { title = "" } = $$props;
// size
if (Number(size)) size = Number(size);
const getStyles = () => {
const transform = [];
const styles = [];
if (size !== null) {
const width = typeof size === "string" ? size : `${size * 1.5}rem`;
styles.push(["width", width]);
styles.push(["height", width]);
}
styles.push(["fill", color !== null ? color : "currentColor"]);
if (flip === true || flip === "h") {
transform.push("scaleX(-1)");
}
if (flip === true || flip === "v") {
transform.push("scaleY(-1)");
}
if (rotate != 0) {
transform.push(`rotate(${rotate}deg)`);
}
if (transform.length > 0) {
styles.push(["transform", transform.join(" ")]);
styles.push(["transform-origin", "center"]);
}
return styles.reduce(
(cur, item) => {
return `${cur} ${item[0]}:${item[1]};`;
},
""
);
};
$$self.$$set = $$props => {
if ("path" in $$props) $$invalidate(0, path = $$props.path);
if ("size" in $$props) $$invalidate(7, size = $$props.size);
if ("color" in $$props) $$invalidate(8, color = $$props.color);
if ("flip" in $$props) $$invalidate(9, flip = $$props.flip);
if ("rotate" in $$props) $$invalidate(10, rotate = $$props.rotate);
if ("spin" in $$props) $$invalidate(1, spin = $$props.spin);
if ("title" in $$props) $$invalidate(2, title = $$props.title);
};
let inverse;
let spintime;
let spinfunc;
let style;
$$self.$$.update = () => {
if ($$self.$$.dirty & /*spin*/ 2) {
// SPIN properties
$$invalidate(3, inverse = typeof spin !== "boolean" && spin < 0 ? true : false);
}
if ($$self.$$.dirty & /*spin*/ 2) {
$$invalidate(4, spintime = Math.abs(spin === true ? 2 : spin));
}
if ($$self.$$.dirty & /*inverse*/ 8) {
$$invalidate(5, spinfunc = inverse ? "spin-inverse" : "spin");
}
if ($$self.$$.dirty & /*size, color, flip, rotate*/ 1920) {
$$invalidate(6, style = getStyles());
}
};
return [
path,
spin,
title,
inverse,
spintime,
spinfunc,
style,
size,
color,
flip,
rotate
];
}
class Index extends SvelteComponent {
constructor(options) {
super();
if (!document.getElementById("svelte-dmmfjb-style")) add_css();
init(this, options, instance, create_fragment, safe_not_equal, {
path: 0,
size: 7,
color: 8,
flip: 9,
rotate: 10,
spin: 1,
title: 2
});
}
}
export default Index;