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.

198 lines (196 loc) 8.63 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 { jsx as h } from "react/jsx-runtime"; import { useRef as x, useState as y, useEffect as g } from "react"; function N(n, r) { return r != null && typeof Symbol < "u" && r[Symbol.hasInstance] ? !!r[Symbol.hasInstance](n) : n instanceof r; } function v(n) { "@swc/helpers - typeof"; return n && typeof Symbol < "u" && n.constructor === Symbol ? "symbol" : typeof n; } var k = Object.create, O = Object.defineProperty, D = Object.getOwnPropertyDescriptor, M = Object.getOwnPropertyNames, H = Object.getPrototypeOf, T = Object.prototype.hasOwnProperty, E = function(n, r) { return function() { return r || n((r = { exports: {} }).exports, r), r.exports; }; }, G = function(n, r, f, u) { var t = !0, i = !1, e = void 0; if (r && (typeof r > "u" ? "undefined" : v(r)) == "object" || typeof r == "function") try { for (var o = function() { var c = s.value; !T.call(n, c) && c !== f && O(n, c, { get: function() { return r[c]; }, enumerable: !(u = D(r, c)) || u.enumerable }); }, a = M(r)[Symbol.iterator](), s; !(t = (s = a.next()).done); t = !0) o(); } catch (c) { i = !0, e = c; } finally { try { !t && a.return != null && a.return(); } finally { if (i) throw e; } } return n; }, j = function(n, r, f) { return f = n != null ? k(H(n)) : {}, G(!n || !n.__esModule ? O(f, "default", { value: n, enumerable: !0 }) : f, n); }, V = E(function(n, r) { var f = function(u, t, i) { var e, o, a, s, c; t == null && (t = 100); function w() { var l = Date.now() - s; l < t && l >= 0 ? e = setTimeout(w, t - l) : (e = null, i || (c = u.apply(a, o), a = o = null)); } var m = function() { a = this, o = arguments, s = Date.now(); var B = i && !e; return e || (e = setTimeout(w, t)), B && (c = u.apply(a, o), a = o = null), c; }; return m.clear = function() { e && (clearTimeout(e), e = null); }, m.flush = function() { e && (c = u.apply(a, o), a = o = null, clearTimeout(e), e = null); }, m; }; f.debounce = f, r.exports = f; }), W = E(function(n, r) { (function() { var f; function u(t, i) { var e = N(this, u) ? this : f; if (e.reset(i), typeof t == "string" && t.length > 0 && e.hash(t), e !== this) return e; } u.prototype.hash = function(t) { var i, e, o, a, s; switch (s = t.length, this.len += s, e = this.k1, o = 0, this.rem) { case 0: e ^= s > o ? t.charCodeAt(o++) & 65535 : 0; case 1: e ^= s > o ? (t.charCodeAt(o++) & 65535) << 8 : 0; case 2: e ^= s > o ? (t.charCodeAt(o++) & 65535) << 16 : 0; case 3: e ^= s > o ? (t.charCodeAt(o) & 255) << 24 : 0, e ^= s > o ? (t.charCodeAt(o++) & 65280) >> 8 : 0; } if (this.rem = s + this.rem & 3, s -= this.rem, s > 0) { for (i = this.h1; e = e * 11601 + (e & 65535) * 3432906752 & 4294967295, e = e << 15 | e >>> 17, e = e * 13715 + (e & 65535) * 461832192 & 4294967295, i ^= e, i = i << 13 | i >>> 19, i = i * 5 + 3864292196 & 4294967295, !(o >= s); ) e = t.charCodeAt(o++) & 65535 ^ (t.charCodeAt(o++) & 65535) << 8 ^ (t.charCodeAt(o++) & 65535) << 16, a = t.charCodeAt(o++), e ^= (a & 255) << 24 ^ (a & 65280) >> 8; switch (e = 0, this.rem) { case 3: e ^= (t.charCodeAt(o + 2) & 65535) << 16; case 2: e ^= (t.charCodeAt(o + 1) & 65535) << 8; case 1: e ^= t.charCodeAt(o) & 65535; } this.h1 = i; } return this.k1 = e, this; }, u.prototype.result = function() { var t, i; return t = this.k1, i = this.h1, t > 0 && (t = t * 11601 + (t & 65535) * 3432906752 & 4294967295, t = t << 15 | t >>> 17, t = t * 13715 + (t & 65535) * 461832192 & 4294967295, i ^= t), i ^= this.len, i ^= i >>> 16, i = i * 51819 + (i & 65535) * 2246770688 & 4294967295, i ^= i >>> 13, i = i * 44597 + (i & 65535) * 3266445312 & 4294967295, i ^= i >>> 16, i >>> 0; }, u.prototype.reset = function(t) { return this.h1 = typeof t == "number" ? t : 0, this.rem = this.k1 = this.len = 0, this; }, f = new u(), (typeof r > "u" ? "undefined" : v(r)) < "u" ? r.exports = u : this.MurmurHash3 = u; })(); }), _ = j(V()), A = j(W()), S = "svg-symbols", C = "svg-", p = "data-count"; function q(n, r) { if ((typeof window > "u" ? "undefined" : v(window)) > "u" || n === r) return {}; var f = document.getElementById(S); if (f || (f = document.createElementNS("http://www.w3.org/2000/svg", "svg"), f.id = S, f.setAttribute("aria-hidden", "true"), f.setAttribute("style", "position:fixed;top:-99999px;left:-99999px;z-index:0;opacity:0;"), document.body.appendChild(f)), n) { var u = C + new A.default(n).result(); P(document.getElementById(u)); } var t = C + new A.default(r).result(), i = document.getElementById(t); if (i) return i.setAttribute(p, b(i) + 1 + ""), { id: t, attrs: I(i) }; 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 o = document.createElementNS("http://www.w3.org/2000/svg", "symbol"), a = 0; a < e.attributes.length; a++) { var s = e.attributes[a]; o.setAttribute(s.name, s.value); } for (o.id = t, o.setAttribute(p, "1"); e.children.length; ) o.appendChild(e.children[0]); return f.appendChild(o), { id: t, attrs: I(o) }; } function F(n) { !n || (typeof window > "u" ? "undefined" : v(window)) > "u" || P(typeof n == "string" ? document.getElementById(n) : n); } function P(n) { if (n) { var r = b(n, 1) - 1; n.setAttribute(p, r + ""), r <= 0 && (d.push(n), R()); } } var d = [], R = (0, _.default)(function() { for (var n = d.length - 1; n >= 0; n--) { var r = d[n]; r.parentElement && b(r) <= 0 && r.parentElement.removeChild(r), d.pop(); } }, 5e3); function b(n) { var r = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0; if (!n) return r; var f = parseInt(n.getAttribute(p) || "1"); return isNaN(f) ? r : f; } function I(n) { var r = n.getAttribute("viewBox") || ""; if (!r) for (var f = 0, u = ["x", "y", "width", "height"]; f < u.length; f++) { var t = u[f], i = n.getAttribute(t); r += (i || "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/ *) */ function U({ src: n, useElAttrs: r, ...f }) { const u = x(""), t = x(""), [i, e] = y(u.current), [o, a] = y({}), s = () => { const c = q(t.current, n); c.id && (e(c.id), u.current = c.id), c.attrs && a(c.attrs), t.current = n; }; return g(() => (s(), () => { F(u.current), t.current = ""; }), []), g(s, [n]), /* @__PURE__ */ h("svg", { alt: "", ...f, ...o, children: /* @__PURE__ */ h("use", { ...r, href: "#" + i }) }); } function L({ src: n, size: r, color: f, colorTransition: u, ...t }) { const i = () => { const a = { ...t.style || {} }; if (r && r !== "unset") for (const s of ["width", "minWidth", "maxWidth", "height", "minHeight", "maxHeight"]) a[s] = r; return f && (a["--icon-color"] = f), a["--icon-transition"] = u || "0.3s linear", a; }, [e, o] = y(i); return g(() => o(i()), [r, f, u]), /* @__PURE__ */ h( "span", { ...t, className: "awesome-svg-loader-icon icon", style: e, children: /* @__PURE__ */ h( U, { src: n, "aria-hidden": "true" } ) } ); } export { L as SvgIcon, U as SvgImage }; //# sourceMappingURL=index.js.map