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.

18 lines (16 loc) 6.71 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)}})(); "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("react/jsx-runtime"),l=require("react");function B(n,r){return r!=null&&typeof Symbol<"u"&&r[Symbol.hasInstance]?!!r[Symbol.hasInstance](n):n instanceof r}function m(n){"@swc/helpers - typeof";return n&&typeof Symbol<"u"&&n.constructor===Symbol?"symbol":typeof n}var N=Object.create,C=Object.defineProperty,M=Object.getOwnPropertyDescriptor,k=Object.getOwnPropertyNames,D=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty,I=function(n,r){return function(){return r||n((r={exports:{}}).exports,r),r.exports}},q=function(n,r,u,f){var t=!0,i=!1,e=void 0;if(r&&(typeof r>"u"?"undefined":m(r))=="object"||typeof r=="function")try{for(var o=function(){var c=s.value;!T.call(n,c)&&c!==u&&C(n,c,{get:function(){return r[c]},enumerable:!(f=M(r,c))||f.enumerable})},a=k(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,u){return u=n!=null?N(D(n)):{},q(!n||!n.__esModule?C(u,"default",{value:n,enumerable:!0}):u,n)},H=I(function(n,r){var u=function(f,t,i){var e,o,a,s,c;t==null&&(t=100);function b(){var d=Date.now()-s;d<t&&d>=0?e=setTimeout(b,t-d):(e=null,i||(c=f.apply(a,o),a=o=null))}var y=function(){a=this,o=arguments,s=Date.now();var P=i&&!e;return e||(e=setTimeout(b,t)),P&&(c=f.apply(a,o),a=o=null),c};return y.clear=function(){e&&(clearTimeout(e),e=null)},y.flush=function(){e&&(c=f.apply(a,o),a=o=null,clearTimeout(e),e=null)},y};u.debounce=u,r.exports=u}),R=I(function(n,r){(function(){var u;function f(t,i){var e=B(this,f)?this:u;if(e.reset(i),typeof t=="string"&&t.length>0&&e.hash(t),e!==this)return e}f.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},f.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},f.prototype.reset=function(t){return this.h1=typeof t=="number"?t:0,this.rem=this.k1=this.len=0,this},u=new f,(typeof r>"u"?"undefined":m(r))<"u"?r.exports=f:this.MurmurHash3=f})()}),G=j(H()),w=j(R()),x="svg-symbols",S="svg-",p="data-count";function V(n,r){if((typeof window>"u"?"undefined":m(window))>"u"||n===r)return{};var u=document.getElementById(x);if(u||(u=document.createElementNS("http://www.w3.org/2000/svg","svg"),u.id=x,u.setAttribute("aria-hidden","true"),u.setAttribute("style","position:fixed;top:-99999px;left:-99999px;z-index:0;opacity:0;"),document.body.appendChild(u)),n){var f=S+new w.default(n).result();E(document.getElementById(f))}var t=S+new w.default(r).result(),i=document.getElementById(t);if(i)return i.setAttribute(p,g(i)+1+""),{id:t,attrs:A(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 u.appendChild(o),{id:t,attrs:A(o)}}function W(n){!n||(typeof window>"u"?"undefined":m(window))>"u"||E(typeof n=="string"?document.getElementById(n):n)}function E(n){if(n){var r=g(n,1)-1;n.setAttribute(p,r+""),r<=0&&(h.push(n),_())}}var h=[],_=(0,G.default)(function(){for(var n=h.length-1;n>=0;n--){var r=h[n];r.parentElement&&g(r)<=0&&r.parentElement.removeChild(r),h.pop()}},5e3);function g(n){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;if(!n)return r;var u=parseInt(n.getAttribute(p)||"1");return isNaN(u)?r:u}function A(n){var r=n.getAttribute("viewBox")||"";if(!r)for(var u=0,f=["x","y","width","height"];u<f.length;u++){var t=f[u],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 O({src:n,useElAttrs:r,...u}){const f=l.useRef(""),t=l.useRef(""),[i,e]=l.useState(f.current),[o,a]=l.useState({}),s=()=>{const c=V(t.current,n);c.id&&(e(c.id),f.current=c.id),c.attrs&&a(c.attrs),t.current=n};return l.useEffect(()=>(s(),()=>{W(f.current),t.current=""}),[]),l.useEffect(s,[n]),v.jsx("svg",{alt:"",...u,...o,children:v.jsx("use",{...r,href:"#"+i})})}function F({src:n,size:r,color:u,colorTransition:f,...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 u&&(a["--icon-color"]=u),a["--icon-transition"]=f||"0.3s linear",a},[e,o]=l.useState(i);return l.useEffect(()=>o(i()),[r,u,f]),v.jsx("span",{...t,className:"awesome-svg-loader-icon icon",style:e,children:v.jsx(O,{src:n,"aria-hidden":"true"})})}exports.SvgIcon=F;exports.SvgImage=O; //# sourceMappingURL=index.cjs.map