UNPKG

vite-awesome-svg-loader

Version:

Imports SVGs as source code, base64 and data URI. Preserves stroke width, replaces colors with currentColor. Optimizes SVGs with SVGO. Creates SVG sprites.

210 lines (208 loc) 8.95 kB
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".awesome-svg-loader-icon{display:inline-block;color:var(--icon-color)}.awesome-svg-loader-icon svg{vertical-align:top}.awesome-svg-loader-icon use{transition:color var(--icon-transition)}")),document.head.appendChild(e)}}catch(o){console.error("vite-plugin-css-injected-by-js",o)}})(); import { defineComponent as E, ref as g, watch as N, onMounted as k, onBeforeUnmount as T, openBlock as I, createElementBlock as O, normalizeProps as b, guardReactiveProps as w, createElementVNode as M, computed as D, normalizeStyle as V, createVNode as H } from "vue"; function G(n, r) { return r != null && typeof Symbol < "u" && r[Symbol.hasInstance] ? !!r[Symbol.hasInstance](n) : n instanceof r; } function p(n) { "@swc/helpers - typeof"; return n && typeof Symbol < "u" && n.constructor === Symbol ? "symbol" : typeof n; } var U = Object.create, _ = Object.defineProperty, W = Object.getOwnPropertyDescriptor, $ = Object.getOwnPropertyNames, q = Object.getPrototypeOf, F = Object.prototype.hasOwnProperty, B = function(n, r) { return function() { return r || n((r = { exports: {} }).exports, r), r.exports; }; }, R = function(n, r, a, s) { var t = !0, o = !1, e = void 0; if (r && (typeof r > "u" ? "undefined" : p(r)) == "object" || typeof r == "function") try { for (var i = function() { var c = u.value; !F.call(n, c) && c !== a && _(n, c, { get: function() { return r[c]; }, enumerable: !(s = W(r, c)) || s.enumerable }); }, f = $(r)[Symbol.iterator](), u; !(t = (u = f.next()).done); t = !0) i(); } catch (c) { o = !0, e = c; } finally { try { !t && f.return != null && f.return(); } finally { if (o) throw e; } } return n; }, P = function(n, r, a) { return a = n != null ? U(q(n)) : {}, R(!n || !n.__esModule ? _(a, "default", { value: n, enumerable: !0 }) : a, n); }, J = B(function(n, r) { var a = function(s, t, o) { var e, i, f, u, c; t == null && (t = 100); function y() { var l = Date.now() - u; l < t && l >= 0 ? e = setTimeout(y, t - l) : (e = null, o || (c = s.apply(f, i), f = i = null)); } var v = function() { f = this, i = arguments, u = Date.now(); var z = o && !e; return e || (e = setTimeout(y, t)), z && (c = s.apply(f, i), f = i = null), c; }; return v.clear = function() { e && (clearTimeout(e), e = null); }, v.flush = function() { e && (c = s.apply(f, i), f = i = null, clearTimeout(e), e = null); }, v; }; a.debounce = a, r.exports = a; }), K = B(function(n, r) { (function() { var a; function s(t, o) { var e = G(this, s) ? this : a; if (e.reset(o), typeof t == "string" && t.length > 0 && e.hash(t), e !== this) return e; } s.prototype.hash = function(t) { var o, e, i, f, u; switch (u = t.length, this.len += u, e = this.k1, i = 0, this.rem) { case 0: e ^= u > i ? t.charCodeAt(i++) & 65535 : 0; case 1: e ^= u > i ? (t.charCodeAt(i++) & 65535) << 8 : 0; case 2: e ^= u > i ? (t.charCodeAt(i++) & 65535) << 16 : 0; case 3: e ^= u > i ? (t.charCodeAt(i) & 255) << 24 : 0, e ^= u > i ? (t.charCodeAt(i++) & 65280) >> 8 : 0; } if (this.rem = u + this.rem & 3, u -= this.rem, u > 0) { for (o = this.h1; e = e * 11601 + (e & 65535) * 3432906752 & 4294967295, e = e << 15 | e >>> 17, e = e * 13715 + (e & 65535) * 461832192 & 4294967295, o ^= e, o = o << 13 | o >>> 19, o = o * 5 + 3864292196 & 4294967295, !(i >= u); ) e = t.charCodeAt(i++) & 65535 ^ (t.charCodeAt(i++) & 65535) << 8 ^ (t.charCodeAt(i++) & 65535) << 16, f = t.charCodeAt(i++), e ^= (f & 255) << 24 ^ (f & 65280) >> 8; switch (e = 0, this.rem) { case 3: e ^= (t.charCodeAt(i + 2) & 65535) << 16; case 2: e ^= (t.charCodeAt(i + 1) & 65535) << 8; case 1: e ^= t.charCodeAt(i) & 65535; } this.h1 = o; } return this.k1 = e, this; }, s.prototype.result = function() { var t, o; return t = this.k1, o = this.h1, t > 0 && (t = t * 11601 + (t & 65535) * 3432906752 & 4294967295, t = t << 15 | t >>> 17, t = t * 13715 + (t & 65535) * 461832192 & 4294967295, o ^= t), o ^= this.len, o ^= o >>> 16, o = o * 51819 + (o & 65535) * 2246770688 & 4294967295, o ^= o >>> 13, o = o * 44597 + (o & 65535) * 3266445312 & 4294967295, o ^= o >>> 16, o >>> 0; }, s.prototype.reset = function(t) { return this.h1 = typeof t == "number" ? t : 0, this.rem = this.k1 = this.len = 0, this; }, a = new s(), (typeof r > "u" ? "undefined" : p(r)) < "u" ? r.exports = s : this.MurmurHash3 = s; })(); }), L = P(J()), x = P(K()), A = "svg-symbols", S = "svg-", h = "data-count"; function Q(n, r) { if ((typeof window > "u" ? "undefined" : p(window)) > "u" || n === r) return {}; var a = document.getElementById(A); if (a || (a = document.createElementNS("http://www.w3.org/2000/svg", "svg"), a.id = A, a.setAttribute("aria-hidden", "true"), a.setAttribute("style", "position:fixed;top:-99999px;left:-99999px;z-index:0;opacity:0;"), document.body.appendChild(a)), n) { var s = S + new x.default(n).result(); j(document.getElementById(s)); } var t = S + new x.default(r).result(), o = document.getElementById(t); if (o) return o.setAttribute(h, m(o) + 1 + ""), { id: t, attrs: C(o) }; var e = new DOMParser().parseFromString(r, "application/xml").firstElementChild; if (e != null && e.querySelector("parsererror")) return console.error("Provided source code is not a valid SVG: " + r), { id: t }; if (!e) return console.error("Missing child in SVG: " + r), { id: t }; for (var i = document.createElementNS("http://www.w3.org/2000/svg", "symbol"), f = 0; f < e.attributes.length; f++) { var u = e.attributes[f]; i.setAttribute(u.name, u.value); } for (i.id = t, i.setAttribute(h, "1"); e.children.length; ) i.appendChild(e.children[0]); return a.appendChild(i), { id: t, attrs: C(i) }; } function X(n) { !n || (typeof window > "u" ? "undefined" : p(window)) > "u" || j(typeof n == "string" ? document.getElementById(n) : n); } function j(n) { if (n) { var r = m(n, 1) - 1; n.setAttribute(h, r + ""), r <= 0 && (d.push(n), Y()); } } var d = [], Y = (0, L.default)(function() { for (var n = d.length - 1; n >= 0; n--) { var r = d[n]; r.parentElement && m(r) <= 0 && r.parentElement.removeChild(r), d.pop(); } }, 5e3); function m(n) { var r = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0; if (!n) return r; var a = parseInt(n.getAttribute(h) || "1"); return isNaN(a) ? r : a; } function C(n) { var r = n.getAttribute("viewBox") || ""; if (!r) for (var a = 0, s = ["x", "y", "width", "height"]; a < s.length; a++) { var t = s[a], o = n.getAttribute(t); r += (o || "0") + " "; } return { viewBox: r, width: "100%", height: "100%" }; } /*! Bundled license information: imurmurhash/imurmurhash.js: (** * @preserve * JS Implementation of incremental MurmurHash3 (r150) (as of May 10, 2013) * * @author <a href="mailto:jensyt@gmail.com">Jens Taylor</a> * @see http://github.com/homebrewing/brauhaus-diff * @author <a href="mailto:gary.court@gmail.com">Gary Court</a> * @see http://github.com/garycourt/murmurhash-js * @author <a href="mailto:aappleby@gmail.com">Austin Appleby</a> * @see http://sites.google.com/site/murmurhash/ *) */ const Z = /* @__PURE__ */ E({ inheritAttrs: !1, __name: "SvgImage", props: { src: {}, useElAttrs: {} }, setup(n) { const r = n, a = g(""), s = g({}), t = (o, e) => { const i = Q(o, e); i.id && (a.value = i.id), i.attrs && (s.value = i.attrs); }; return N( () => r.src, (o, e) => t(e, o) ), k(() => t(void 0, r.src)), T(() => X(a.value)), (o, e) => (I(), O("svg", b(w({ alt: "", ...o.$attrs, ...s.value })), [ M("use", b(w({ ...o.useElAttrs || {}, href: "#" + a.value })), null, 16) ], 16)); } }), et = /* @__PURE__ */ E({ __name: "SvgIcon", props: { src: {}, size: {}, color: {}, colorTransition: {} }, setup(n) { const r = n, a = D(() => { const s = {}; if (r.size && r.size !== "unset") for (const t of ["width", "minWidth", "maxWidth", "height", "minHeight", "maxHeight"]) s[t] = r.size; return r.color && (s["--icon-color"] = r.color), s["--icon-transition"] = r.colorTransition || "0.3s linear", s; }); return (s, t) => (I(), O("span", { class: "awesome-svg-loader-icon icon", style: V(a.value) }, [ H(Z, { src: s.src, "aria-hidden": "true" }, null, 8, ["src"]) ], 4)); } }); export { et as SvgIcon, Z as SvgImage }; //# sourceMappingURL=index.js.map