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.98 kB
"use strict";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 o=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var a=function(e,t){return function(){return t||e((t={exports:{}}).exports,t),t.exports}},c=function(e,t){for(var r in t)n(e,r,{get:t[r],enumerable:!0})},s=function(e,r,u,a){var c=true,s=false,l=undefined;if(r&&(typeof r==="undefined"?"undefined":t(r))=="object"||typeof r=="function")try{var d=function(){var t=p.value;!f.call(e,t)&&t!==u&&n(e,t,{get:function(){return r[t]},enumerable:!(a=o(r,t))||a.enumerable})};for(var h=i(r)[Symbol.iterator](),p;!(c=(p=h.next()).done);c=true)d()}catch(e){s=true;l=e}finally{try{if(!c&&h.return!=null){h.return()}}finally{if(s){throw l}}}return e};var l=function(e,t,o){return o=e!=null?r(u(e)):{},s(t||!e||!e.__esModule?n(o,"default",{value:e,enumerable:!0}):o,e)},d=function(e){return s(n({},"__esModule",{value:!0}),e)};var h=a(function(e,t){"use strict";var r=function e(e,t,r){var n,o,i,u,f;t==null&&(t=100);function a(){var c=Date.now()-u;c<t&&c>=0?n=setTimeout(a,t-c):(n=null,r||(f=e.apply(i,o),i=o=null))}var c=function c(){i=this,o=arguments,u=Date.now();var c=r&&!n;return n||(n=setTimeout(a,t)),c&&(f=e.apply(i,o),i=o=null),f};return c.clear=function(){n&&(clearTimeout(n),n=null)},c.flush=function(){n&&(f=e.apply(i,o),i=o=null,clearTimeout(n),n=null)},c};r.debounce=r;t.exports=r});var p=a(function(r,n){"use strict";(function(){var r;function o(t,n){var i=e(this,o)?this:r;if(i.reset(n),typeof t=="string"&&t.length>0&&i.hash(t),i!==this)return i}o.prototype.hash=function(e){var t,r,n,o,i;switch(i=e.length,this.len+=i,r=this.k1,n=0,this.rem){case 0:r^=i>n?e.charCodeAt(n++)&65535:0;case 1:r^=i>n?(e.charCodeAt(n++)&65535)<<8:0;case 2:r^=i>n?(e.charCodeAt(n++)&65535)<<16:0;case 3:r^=i>n?(e.charCodeAt(n)&255)<<24:0,r^=i>n?(e.charCodeAt(n++)&65280)>>8:0}if(this.rem=i+this.rem&3,i-=this.rem,i>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>=i);)r=e.charCodeAt(n++)&65535^(e.charCodeAt(n++)&65535)<<8^(e.charCodeAt(n++)&65535)<<16,o=e.charCodeAt(n++),r^=(o&255)<<24^(o&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},o.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},o.prototype.reset=function(e){return this.h1=typeof e=="number"?e:0,this.rem=this.k1=this.len=0,this},r=new o,(typeof n==="undefined"?"undefined":t(n))<"u"?n.exports=o:this.MurmurHash3=o})()});var v={};c(v,{SVG_ID:function(){return b},SYMBOL_ID_PREFIX:function(){return w},USAGES_COUNT_ATTR:function(){return g},onSrcUpdate:function(){return x},onUnmount:function(){return A}});module.exports=d(v);var m=l(h()),y=l(p()),b="svg-symbols",w="svg-",g="data-count";function x(e,r){if((typeof window==="undefined"?"undefined":t(window))>"u"||e===r)return{};var n=document.getElementById(b);if(n||(n=document.createElementNS("http://www.w3.org/2000/svg","svg"),n.id=b,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 o=w+new y.default(e).result();S(document.getElementById(o))}var i=w+new y.default(r).result(),u=document.getElementById(i);if(u)return u.setAttribute(g,O(u)+1+""),{id:i,attrs:I(u)};var f=new DOMParser().parseFromString(r,"application/xml").firstElementChild;if(f===null||f===void 0?void 0:f.querySelector("parsererror"))return console.error("Provided source code is not a valid SVG: "+r),{id:i};if(!f)return console.error("Missing child in SVG: "+r),{id:i};var a=document.createElementNS("http://www.w3.org/2000/svg","symbol");for(var c=0;c<f.attributes.length;c++){var s=f.attributes[c];a.setAttribute(s.name,s.value)}for(a.id=i,a.setAttribute(g,"1");f.children.length;)a.appendChild(f.children[0]);return n.appendChild(a),{id:i,attrs:I(a)}}function A(e){!e||(typeof window==="undefined"?"undefined":t(window))>"u"||S(typeof e=="string"?document.getElementById(e):e)}function S(e){if(!e)return;var t=O(e,1)-1;e.setAttribute(g,t+""),t<=0&&(C.push(e),_())}var C=[],_=(0,m.default)(function(){for(var e=C.length-1;e>=0;e--){var t=C[e];t.parentElement&&O(t)<=0&&t.parentElement.removeChild(t),C.pop()}},5e3);function O(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;if(!e)return t;var r=parseInt(e.getAttribute(g)||"1");return isNaN(r)?t:r}function I(e){var t=e.getAttribute("viewBox")||"";if(!t)for(var r=0,n=["x","y","width","height"];r<n.length;r++){var o=n[r];var i=e.getAttribute(o);t+=(i||"0")+" "}return{viewBox:t,width:"100%",height:"100%"}}0&&(module.exports={SVG_ID:SVG_ID,SYMBOL_ID_PREFIX:SYMBOL_ID_PREFIX,USAGES_COUNT_ATTR:USAGES_COUNT_ATTR,onSrcUpdate:onSrcUpdate,onUnmount: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.js.map