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.

15 lines (14 loc) 5.59 kB
function e(e,t){if(t!=null&&typeof Symbol!=="undefined"&&t[Symbol.hasInstance]){return!!t[Symbol.hasInstance](e)}else{return e instanceof t}}function t(e){"@swc/helpers - typeof";return e&&typeof Symbol!=="undefined"&&e.constructor===Symbol?"symbol":typeof e}var r=Object.create;var n=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var o=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var a=function(e,t){return function(){return t||e((t={exports:{}}).exports,t),t.exports}};var s=function(e,r,f,a){var s=true,c=false,l=undefined;if(r&&(typeof r==="undefined"?"undefined":t(r))=="object"||typeof r=="function")try{var d=function(){var t=p.value;!u.call(e,t)&&t!==f&&n(e,t,{get:function(){return r[t]},enumerable:!(a=i(r,t))||a.enumerable})};for(var h=o(r)[Symbol.iterator](),p;!(s=(p=h.next()).done);s=true)d()}catch(e){c=true;l=e}finally{try{if(!s&&h.return!=null){h.return()}}finally{if(c){throw l}}}return e};var c=function(e,t,i){return i=e!=null?r(f(e)):{},s(t||!e||!e.__esModule?n(i,"default",{value:e,enumerable:!0}):i,e)};var l=a(function(e,t){"use strict";var r=function e(e,t,r){var n,i,o,f,u;t==null&&(t=100);function a(){var s=Date.now()-f;s<t&&s>=0?n=setTimeout(a,t-s):(n=null,r||(u=e.apply(o,i),o=i=null))}var s=function s(){o=this,i=arguments,f=Date.now();var s=r&&!n;return n||(n=setTimeout(a,t)),s&&(u=e.apply(o,i),o=i=null),u};return s.clear=function(){n&&(clearTimeout(n),n=null)},s.flush=function(){n&&(u=e.apply(o,i),o=i=null,clearTimeout(n),n=null)},s};r.debounce=r;t.exports=r});var d=a(function(r,n){"use strict";(function(){var r;function i(t,n){var o=e(this,i)?this:r;if(o.reset(n),typeof t=="string"&&t.length>0&&o.hash(t),o!==this)return o}i.prototype.hash=function(e){var t,r,n,i,o;switch(o=e.length,this.len+=o,r=this.k1,n=0,this.rem){case 0:r^=o>n?e.charCodeAt(n++)&65535:0;case 1:r^=o>n?(e.charCodeAt(n++)&65535)<<8:0;case 2:r^=o>n?(e.charCodeAt(n++)&65535)<<16:0;case 3:r^=o>n?(e.charCodeAt(n)&255)<<24:0,r^=o>n?(e.charCodeAt(n++)&65280)>>8:0}if(this.rem=o+this.rem&3,o-=this.rem,o>0){for(t=this.h1;r=r*11601+(r&65535)*0xcc9e0000&0xffffffff,r=r<<15|r>>>17,r=r*13715+(r&65535)*0x1b870000&0xffffffff,t^=r,t=t<<13|t>>>19,t=t*5+0xe6546b64&0xffffffff,!(n>=o);)r=e.charCodeAt(n++)&65535^(e.charCodeAt(n++)&65535)<<8^(e.charCodeAt(n++)&65535)<<16,i=e.charCodeAt(n++),r^=(i&255)<<24^(i&65280)>>8;switch(r=0,this.rem){case 3:r^=(e.charCodeAt(n+2)&65535)<<16;case 2:r^=(e.charCodeAt(n+1)&65535)<<8;case 1:r^=e.charCodeAt(n)&65535}this.h1=t}return this.k1=r,this},i.prototype.result=function(){var e,t;return e=this.k1,t=this.h1,e>0&&(e=e*11601+(e&65535)*0xcc9e0000&0xffffffff,e=e<<15|e>>>17,e=e*13715+(e&65535)*0x1b870000&0xffffffff,t^=e),t^=this.len,t^=t>>>16,t=t*51819+(t&65535)*0x85eb0000&0xffffffff,t^=t>>>13,t=t*44597+(t&65535)*0xc2b20000&0xffffffff,t^=t>>>16,t>>>0},i.prototype.reset=function(e){return this.h1=typeof e=="number"?e:0,this.rem=this.k1=this.len=0,this},r=new i,(typeof n==="undefined"?"undefined":t(n))<"u"?n.exports=i:this.MurmurHash3=i})()});var h=c(l()),p=c(d()),v="svg-symbols",y="svg-",m="data-count";function b(e,r){if((typeof window==="undefined"?"undefined":t(window))>"u"||e===r)return{};var n=document.getElementById(v);if(n||(n=document.createElementNS("http://www.w3.org/2000/svg","svg"),n.id=v,n.setAttribute("aria-hidden","true"),n.setAttribute("style","position:fixed;top:-99999px;left:-99999px;z-index:0;opacity:0;"),document.body.appendChild(n)),e){var i=y+new p.default(e).result();g(document.getElementById(i))}var o=y+new p.default(r).result(),f=document.getElementById(o);if(f)return f.setAttribute(m,C(f)+1+""),{id:o,attrs:S(f)};var u=new DOMParser().parseFromString(r,"application/xml").firstElementChild;if(u===null||u===void 0?void 0:u.querySelector("parsererror"))return console.error("Provided source code is not a valid SVG: "+r),{id:o};if(!u)return console.error("Missing child in SVG: "+r),{id:o};var a=document.createElementNS("http://www.w3.org/2000/svg","symbol");for(var s=0;s<u.attributes.length;s++){var c=u.attributes[s];a.setAttribute(c.name,c.value)}for(a.id=o,a.setAttribute(m,"1");u.children.length;)a.appendChild(u.children[0]);return n.appendChild(a),{id:o,attrs:S(a)}}function w(e){!e||(typeof window==="undefined"?"undefined":t(window))>"u"||g(typeof e=="string"?document.getElementById(e):e)}function g(e){if(!e)return;var t=C(e,1)-1;e.setAttribute(m,t+""),t<=0&&(x.push(e),A())}var x=[],A=(0,h.default)(function(){for(var e=x.length-1;e>=0;e--){var t=x[e];t.parentElement&&C(t)<=0&&t.parentElement.removeChild(t),x.pop()}},5e3);function C(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;if(!e)return t;var r=parseInt(e.getAttribute(m)||"1");return isNaN(r)?t:r}function S(e){var t=e.getAttribute("viewBox")||"";if(!t)for(var r=0,n=["x","y","width","height"];r<n.length;r++){var i=n[r];var o=e.getAttribute(i);t+=(o||"0")+" "}return{viewBox:t,width:"100%",height:"100%"}}export{v as SVG_ID,y as SYMBOL_ID_PREFIX,m as USAGES_COUNT_ATTR,b as onSrcUpdate,w as onUnmount};/*! 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/ *) *///# sourceMappingURL=index.mjs.map