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) • 9.17 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)}})();
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function P(e,t){return t!=null&&typeof Symbol<"u"&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t}function _(e){"@swc/helpers - typeof";return e&&typeof Symbol<"u"&&e.constructor===Symbol?"symbol":typeof e}var R=Object.create,C=Object.defineProperty,N=Object.getOwnPropertyDescriptor,W=Object.getOwnPropertyNames,j=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty,x=function(e,t){return function(){return t||e((t={exports:{}}).exports,t),t.exports}},D=function(e,t,i,u){var r=!0,n=!1,s=void 0;if(t&&(typeof t>"u"?"undefined":_(t))=="object"||typeof t=="function")try{for(var o=function(){var f=a.value;!z.call(e,f)&&f!==i&&C(e,f,{get:function(){return t[f]},enumerable:!(u=N(t,f))||u.enumerable})},h=W(t)[Symbol.iterator](),a;!(r=(a=h.next()).done);r=!0)o()}catch(f){n=!0,s=f}finally{try{!r&&h.return!=null&&h.return()}finally{if(n)throw s}}return e},U=function(e,t,i){return i=e!=null?R(j(e)):{},D(!e||!e.__esModule?C(i,"default",{value:e,enumerable:!0}):i,e)},M=x(function(e,t){var i=function(u,r,n){var s,o,h,a,f;r==null&&(r=100);function S(){var c=Date.now()-a;c<r&&c>=0?s=setTimeout(S,r-c):(s=null,n||(f=u.apply(h,o),h=o=null))}var g=function(){h=this,o=arguments,a=Date.now();var B=n&&!s;return s||(s=setTimeout(S,r)),B&&(f=u.apply(h,o),h=o=null),f};return g.clear=function(){s&&(clearTimeout(s),s=null)},g.flush=function(){s&&(f=u.apply(h,o),h=o=null,clearTimeout(s),s=null)},g};i.debounce=i,t.exports=i}),k=x(function(e,t){(function(){var i;function u(r,n){var s=P(this,u)?this:i;if(s.reset(n),typeof r=="string"&&r.length>0&&s.hash(r),s!==this)return s}u.prototype.hash=function(r){var n,s,o,h,a;switch(a=r.length,this.len+=a,s=this.k1,o=0,this.rem){case 0:s^=a>o?r.charCodeAt(o++)&65535:0;case 1:s^=a>o?(r.charCodeAt(o++)&65535)<<8:0;case 2:s^=a>o?(r.charCodeAt(o++)&65535)<<16:0;case 3:s^=a>o?(r.charCodeAt(o)&255)<<24:0,s^=a>o?(r.charCodeAt(o++)&65280)>>8:0}if(this.rem=a+this.rem&3,a-=this.rem,a>0){for(n=this.h1;s=s*11601+(s&65535)*3432906752&4294967295,s=s<<15|s>>>17,s=s*13715+(s&65535)*461832192&4294967295,n^=s,n=n<<13|n>>>19,n=n*5+3864292196&4294967295,!(o>=a);)s=r.charCodeAt(o++)&65535^(r.charCodeAt(o++)&65535)<<8^(r.charCodeAt(o++)&65535)<<16,h=r.charCodeAt(o++),s^=(h&255)<<24^(h&65280)>>8;switch(s=0,this.rem){case 3:s^=(r.charCodeAt(o+2)&65535)<<16;case 2:s^=(r.charCodeAt(o+1)&65535)<<8;case 1:s^=r.charCodeAt(o)&65535}this.h1=n}return this.k1=s,this},u.prototype.result=function(){var r,n;return r=this.k1,n=this.h1,r>0&&(r=r*11601+(r&65535)*3432906752&4294967295,r=r<<15|r>>>17,r=r*13715+(r&65535)*461832192&4294967295,n^=r),n^=this.len,n^=n>>>16,n=n*51819+(n&65535)*2246770688&4294967295,n^=n>>>13,n=n*44597+(n&65535)*3266445312&4294967295,n^=n>>>16,n>>>0},u.prototype.reset=function(r){return this.h1=typeof r=="number"?r:0,this.rem=this.k1=this.len=0,this},i=new u,(typeof t>"u"?"undefined":_(t))<"u"?t.exports=u:this.MurmurHash3=u})()}),G=U(M()),A=U(k()),E="svg-symbols",b="svg-",v="data-count";function H(e,t){if((typeof window>"u"?"undefined":_(window))>"u"||e===t)return{};var i=document.getElementById(E);if(i||(i=document.createElementNS("http://www.w3.org/2000/svg","svg"),i.id=E,i.setAttribute("aria-hidden","true"),i.setAttribute("style","position:fixed;top:-99999px;left:-99999px;z-index:0;opacity:0;"),document.body.appendChild(i)),e){var u=b+new A.default(e).result();T(document.getElementById(u))}var r=b+new A.default(t).result(),n=document.getElementById(r);if(n)return n.setAttribute(v,m(n)+1+""),{id:r,attrs:w(n)};var s=new DOMParser().parseFromString(t,"application/xml").firstElementChild;if(s!=null&&s.querySelector("parsererror"))return console.error("Provided source code is not a valid SVG: "+t),{id:r};if(!s)return console.error("Missing child in SVG: "+t),{id:r};for(var o=document.createElementNS("http://www.w3.org/2000/svg","symbol"),h=0;h<s.attributes.length;h++){var a=s.attributes[h];o.setAttribute(a.name,a.value)}for(o.id=r,o.setAttribute(v,"1");s.children.length;)o.appendChild(s.children[0]);return i.appendChild(o),{id:r,attrs:w(o)}}function O(e){!e||(typeof window>"u"?"undefined":_(window))>"u"||T(typeof e=="string"?document.getElementById(e):e)}function T(e){if(e){var t=m(e,1)-1;e.setAttribute(v,t+""),t<=0&&(d.push(e),L())}}var d=[],L=(0,G.default)(function(){for(var e=d.length-1;e>=0;e--){var t=d[e];t.parentElement&&m(t)<=0&&t.parentElement.removeChild(t),d.pop()}},5e3);function m(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;if(!e)return t;var i=parseInt(e.getAttribute(v)||"1");return isNaN(i)?t:i}function w(e){var t=e.getAttribute("viewBox")||"";if(!t)for(var i=0,u=["x","y","width","height"];i<u.length;i++){var r=u[i],n=e.getAttribute(r);t+=(n||"0")+" "}return{viewBox:t,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 y(e,t){const i=typeof t=="string"?document.querySelector(t):t;if(!i){console.error(`No elements found for selector "${t}"`);return}return i.appendChild(e),i}const q={id:!0,class:!0,style:!0};function l(e,t,i=!1){if(i){const u=[];for(const r of e.attributes)q[r.name]||u.push(r.name);for(const r of u)e.removeAttribute(r)}for(const u in t)e.setAttribute(u,t[u])}function p(e,t,i){i?e.style[t]!==void 0?e.style[t]=i:e.style.setProperty(t,i):e.style[t]!==void 0?e.style[t]="":e.style.removeProperty(t)}class I{constructor(t,i){this._svgAttrs={},this._useElAttrs={},this._updateSrcRes={},this._svgEl=document.createElementNS("http://www.w3.org/2000/svg","svg"),this._useEl=document.createElementNS("http://www.w3.org/2000/svg","use"),this._svgEl.appendChild(this._useEl),this.setSrc(t),i&&this.mount(i)}mount(t){return this._container=y(this._svgEl,t),this}unmount(){var t;return(t=this._svgEl.parentElement)==null||t.removeChild(this._svgEl),this._container=void 0,O(this._updateSrcRes.id),this}setSvgElAttrs(t){return this._svgAttrs=t,this._updateSvgEl()}_updateSvgEl(){return l(this._svgEl,{alt:""},!0),this._updateSvgBeforeUserAttrsSet(),l(this._svgEl,this._svgAttrs),this._updateSvgAfterUserAttrsSet(),this._updateSrcRes.attrs&&l(this._svgEl,this._updateSrcRes.attrs),this}_updateSvgBeforeUserAttrsSet(){}_updateSvgAfterUserAttrsSet(){}setUseElAttrs(t){return this._useElAttrs=t,this._updateUseEl()}_updateUseEl(){return l(this._useEl,{},!0),this._updateUseElBeforeUserAttrsSet(),l(this._useEl,this._useElAttrs),this._updateUseElAfterUserAttrsSet(),this._updateSrcRes.id&&l(this._useEl,{href:"#"+this._updateSrcRes.id}),this}_updateUseElBeforeUserAttrsSet(){}_updateUseElAfterUserAttrsSet(){}setSrc(t){return this._updateSrcRes=H(this._src,t),this._src=t,this._updateSvgEl(),this._updateUseEl(),this}getSrc(){return this._src}getContainer(){return this._container}getSvgEl(){return this._svgEl}getUseEl(){return this._useEl}}const F="0.3s linear";class V extends I{constructor(t,i){super(t),this._span=document.createElement("span"),this._setWrapperClass(),this._span.appendChild(this._svgEl),this.setColorTransition(),i&&this.mount(i)}mount(t){return this._container=y(this._span,t),this}unmount(){var t;return(t=this._span.parentElement)==null||t.removeChild(this._span),this._container=void 0,O(this._updateSrcRes.id),this}_updateSvgBeforeUserAttrsSet(){l(this._svgEl,{"aria-hidden":"true"})}setWrapperAttrs(t){return l(this._span,{},!0),this._updateWrapperBeforeUserAttrsSet(),l(this._span,t),this._updateWrapperAfterUserAttrsSet(),this.setSize(this._size),this.setColor(this._color),this.setColorTransition(this._colorTransition),this._setWrapperClass(),this}_updateWrapperBeforeUserAttrsSet(){}_updateWrapperAfterUserAttrsSet(){}_setWrapperClass(){this._span.classList.add("awesome-svg-loader-icon","icon")}getWrapper(){return this._span}setSize(t){this._size=t;for(const i of["width","minWidth","maxWidth","height","minHeight","maxHeight"])p(this._span,i,this._size);return this}getSize(){return this._size||""}setColor(t){return this._color=t,p(this._span,"--icon-color",t),this}getColor(){return this._color||""}setColorTransition(t=F){return this._colorTransition=t,p(this._span,"--icon-transition",t),this}getColorTransition(){return this._colorTransition||""}}exports.SvgIcon=V;exports.SvgImage=I;exports.mount=y;exports.setAttrs=l;exports.setStyleProperty=p;
//# sourceMappingURL=index.cjs.map