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.97 kB
JavaScript
(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)}})();
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("vue");function I(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 _=Object.create,S=Object.defineProperty,j=Object.getOwnPropertyDescriptor,k=Object.getOwnPropertyNames,z=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty,C=function(n,r){return function(){return r||n((r={exports:{}}).exports,r),r.exports}},T=function(n,r,a,s){var e=!0,o=!1,t=void 0;if(r&&(typeof r>"u"?"undefined":v(r))=="object"||typeof r=="function")try{for(var i=function(){var l=u.value;!N.call(n,l)&&l!==a&&S(n,l,{get:function(){return r[l]},enumerable:!(s=j(r,l))||s.enumerable})},f=k(r)[Symbol.iterator](),u;!(e=(u=f.next()).done);e=!0)i()}catch(l){o=!0,t=l}finally{try{!e&&f.return!=null&&f.return()}finally{if(o)throw t}}return n},E=function(n,r,a){return a=n!=null?_(z(n)):{},T(!n||!n.__esModule?S(a,"default",{value:n,enumerable:!0}):a,n)},M=C(function(n,r){var a=function(s,e,o){var t,i,f,u,l;e==null&&(e=100);function g(){var d=Date.now()-u;d<e&&d>=0?t=setTimeout(g,e-d):(t=null,o||(l=s.apply(f,i),f=i=null))}var m=function(){f=this,i=arguments,u=Date.now();var B=o&&!t;return t||(t=setTimeout(g,e)),B&&(l=s.apply(f,i),f=i=null),l};return m.clear=function(){t&&(clearTimeout(t),t=null)},m.flush=function(){t&&(l=s.apply(f,i),f=i=null,clearTimeout(t),t=null)},m};a.debounce=a,r.exports=a}),D=C(function(n,r){(function(){var a;function s(e,o){var t=I(this,s)?this:a;if(t.reset(o),typeof e=="string"&&e.length>0&&t.hash(e),t!==this)return t}s.prototype.hash=function(e){var o,t,i,f,u;switch(u=e.length,this.len+=u,t=this.k1,i=0,this.rem){case 0:t^=u>i?e.charCodeAt(i++)&65535:0;case 1:t^=u>i?(e.charCodeAt(i++)&65535)<<8:0;case 2:t^=u>i?(e.charCodeAt(i++)&65535)<<16:0;case 3:t^=u>i?(e.charCodeAt(i)&255)<<24:0,t^=u>i?(e.charCodeAt(i++)&65280)>>8:0}if(this.rem=u+this.rem&3,u-=this.rem,u>0){for(o=this.h1;t=t*11601+(t&65535)*3432906752&4294967295,t=t<<15|t>>>17,t=t*13715+(t&65535)*461832192&4294967295,o^=t,o=o<<13|o>>>19,o=o*5+3864292196&4294967295,!(i>=u);)t=e.charCodeAt(i++)&65535^(e.charCodeAt(i++)&65535)<<8^(e.charCodeAt(i++)&65535)<<16,f=e.charCodeAt(i++),t^=(f&255)<<24^(f&65280)>>8;switch(t=0,this.rem){case 3:t^=(e.charCodeAt(i+2)&65535)<<16;case 2:t^=(e.charCodeAt(i+1)&65535)<<8;case 1:t^=e.charCodeAt(i)&65535}this.h1=o}return this.k1=t,this},s.prototype.result=function(){var e,o;return e=this.k1,o=this.h1,e>0&&(e=e*11601+(e&65535)*3432906752&4294967295,e=e<<15|e>>>17,e=e*13715+(e&65535)*461832192&4294967295,o^=e),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(e){return this.h1=typeof e=="number"?e:0,this.rem=this.k1=this.len=0,this},a=new s,(typeof r>"u"?"undefined":v(r))<"u"?r.exports=s:this.MurmurHash3=s})()}),V=E(M()),b=E(D()),w="svg-symbols",x="svg-",p="data-count";function H(n,r){if((typeof window>"u"?"undefined":v(window))>"u"||n===r)return{};var a=document.getElementById(w);if(a||(a=document.createElementNS("http://www.w3.org/2000/svg","svg"),a.id=w,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=x+new b.default(n).result();O(document.getElementById(s))}var e=x+new b.default(r).result(),o=document.getElementById(e);if(o)return o.setAttribute(p,y(o)+1+""),{id:e,attrs:A(o)};var t=new DOMParser().parseFromString(r,"application/xml").firstElementChild;if(t!=null&&t.querySelector("parsererror"))return console.error("Provided source code is not a valid SVG: "+r),{id:e};if(!t)return console.error("Missing child in SVG: "+r),{id:e};for(var i=document.createElementNS("http://www.w3.org/2000/svg","symbol"),f=0;f<t.attributes.length;f++){var u=t.attributes[f];i.setAttribute(u.name,u.value)}for(i.id=e,i.setAttribute(p,"1");t.children.length;)i.appendChild(t.children[0]);return a.appendChild(i),{id:e,attrs:A(i)}}function q(n){!n||(typeof window>"u"?"undefined":v(window))>"u"||O(typeof n=="string"?document.getElementById(n):n)}function O(n){if(n){var r=y(n,1)-1;n.setAttribute(p,r+""),r<=0&&(h.push(n),G())}}var h=[],G=(0,V.default)(function(){for(var n=h.length-1;n>=0;n--){var r=h[n];r.parentElement&&y(r)<=0&&r.parentElement.removeChild(r),h.pop()}},5e3);function y(n){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;if(!n)return r;var a=parseInt(n.getAttribute(p)||"1");return isNaN(a)?r:a}function A(n){var r=n.getAttribute("viewBox")||"";if(!r)for(var a=0,s=["x","y","width","height"];a<s.length;a++){var e=s[a],o=n.getAttribute(e);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 P=c.defineComponent({inheritAttrs:!1,__name:"SvgImage",props:{src:{},useElAttrs:{}},setup(n){const r=n,a=c.ref(""),s=c.ref({}),e=(o,t)=>{const i=H(o,t);i.id&&(a.value=i.id),i.attrs&&(s.value=i.attrs)};return c.watch(()=>r.src,(o,t)=>e(t,o)),c.onMounted(()=>e(void 0,r.src)),c.onBeforeUnmount(()=>q(a.value)),(o,t)=>(c.openBlock(),c.createElementBlock("svg",c.normalizeProps(c.guardReactiveProps({alt:"",...o.$attrs,...s.value})),[c.createElementVNode("use",c.normalizeProps(c.guardReactiveProps({...o.useElAttrs||{},href:"#"+a.value})),null,16)],16))}}),R=c.defineComponent({__name:"SvgIcon",props:{src:{},size:{},color:{},colorTransition:{}},setup(n){const r=n,a=c.computed(()=>{const s={};if(r.size&&r.size!=="unset")for(const e of["width","minWidth","maxWidth","height","minHeight","maxHeight"])s[e]=r.size;return r.color&&(s["--icon-color"]=r.color),s["--icon-transition"]=r.colorTransition||"0.3s linear",s});return(s,e)=>(c.openBlock(),c.createElementBlock("span",{class:"awesome-svg-loader-icon icon",style:c.normalizeStyle(a.value)},[c.createVNode(P,{src:s.src,"aria-hidden":"true"},null,8,["src"])],4))}});exports.SvgIcon=R;exports.SvgImage=P;
//# sourceMappingURL=index.cjs.map