-
Notifications
You must be signed in to change notification settings - Fork 20
/
svg-loader.min.js
2 lines (2 loc) · 7.53 KB
/
svg-loader.min.js
1
2
(()=>{"use strict";var t={701:t=>{let e=0;t.exports={incr:()=>++e,decr:()=>--e,curr:()=>e}},941:t=>{t.exports=(t,e,r="")=>{const n=/url\(['"]?#([\w:.-]+)['"]?\)/g,o=/#([\w:.-]+)/g;return e.match(n)&&(e=e.replace(n,(function(e,r){return t[r]?`url(#${t[r]})`:e}))),["href","xlink:href"].includes(r)&&e.match(o)&&(e=e.replace(o,(function(e,r){return t[r]?`#${t[r]}`:e}))),e}},905:t=>{t.exports=(t,e,r)=>{const n=new RegExp("([^\r\n,{}]+)(,(?=[^}]*{)|s*{)","g");return t.replace(n,(function(t,n,o){if(n.match(/^\s*(@media|@.*keyframes|to|from|@font-face|1?[0-9]?[0-9])/))return n+o;const a=n.match(/#(\w+)/);return a&&r[a[1]]&&(n=n.replace(a[0],`#${r[a[1]]}`)),(n=n.replace(/^(\s*)/,"$1"+e+" "))+o}))}},678:(t,e,r)=>{function n(t){return new Promise(((e,r)=>{t.oncomplete=t.onsuccess=()=>e(t.result),t.onabort=t.onerror=()=>r(t.error)}))}function o(t,e){const r=indexedDB.open(t);r.onupgradeneeded=()=>r.result.createObjectStore(e);const o=n(r);return(t,r)=>o.then((n=>r(n.transaction(e,t).objectStore(e))))}let a;function s(){return a||(a=o("keyval-store","keyval")),a}function i(t,e=s()){return e("readonly",(e=>n(e.get(t))))}function c(t,e,r=s()){return r("readwrite",(r=>(r.put(e,t),n(r.transaction))))}function u(t,e=s()){return e("readwrite",(e=>(t.forEach((t=>e.put(t[1],t[0]))),n(e.transaction))))}function l(t,e=s()){return e("readonly",(e=>Promise.all(t.map((t=>n(e.get(t)))))))}function d(t,e,r=s()){return r("readwrite",(r=>new Promise(((o,a)=>{r.get(t).onsuccess=function(){try{r.put(e(this.result),t),o(n(r.transaction))}catch(t){a(t)}}}))))}function f(t,e=s()){return e("readwrite",(e=>(e.delete(t),n(e.transaction))))}function h(t,e=s()){return e("readwrite",(e=>(t.forEach((t=>e.delete(t))),n(e.transaction))))}function b(t=s()){return t("readwrite",(t=>(t.clear(),n(t.transaction))))}function g(t,e){return t.openCursor().onsuccess=function(){this.result&&(e(this.result),this.result.continue())},n(t.transaction)}function p(t=s()){return t("readonly",(t=>{if(t.getAllKeys)return n(t.getAllKeys());const e=[];return g(t,(t=>e.push(t.key))).then((()=>e))}))}function y(t=s()){return t("readonly",(t=>{if(t.getAll)return n(t.getAll());const e=[];return g(t,(t=>e.push(t.value))).then((()=>e))}))}function m(t=s()){return t("readonly",(e=>{if(e.getAll&&e.getAllKeys)return Promise.all([n(e.getAllKeys()),n(e.getAll())]).then((([t,e])=>t.map(((t,r)=>[t,e[r]]))));const r=[];return t("readonly",(t=>g(t,(t=>r.push([t.key,t.value]))).then((()=>r))))}))}r.r(e),r.d(e,{clear:()=>b,createStore:()=>o,del:()=>f,delMany:()=>h,entries:()=>m,get:()=>i,getMany:()=>l,keys:()=>p,promisifyRequest:()=>n,set:()=>c,setMany:()=>u,update:()=>d,values:()=>y})}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var a=e[n]={exports:{}};return t[n](a,a.exports,r),a.exports}r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},(()=>{const{get:t,set:e,del:n,entries:o}=r(678),a=r(905),s=r(941),i=r(701),c=[],u={},l=(t,e,r)=>{const{enableJs:n,disableUniqueIds:o,disableCssScoping:l,spriteIconId:d}=e,f=!!d,h=(new DOMParser).parseFromString(r,"text/html"),b=f?h.getElementById(d):h.querySelector("svg"),g=(()=>{if(c.length)return c;for(const t in document.body)t.startsWith("on")&&c.push(t);return c.push("onbegin","onend","onrepeat"),c.push("onfocusin","onfocusout","onbounce","onfinish","onshow"),c})(),p=u[t.getAttribute("data-id")]||new Set,y=t.getAttribute("data-id")||`svg-loader_${i.incr()}`,m={};if(o||Array.from(b.querySelectorAll("[id]")).forEach((t=>{const e=t.getAttribute("id"),r=`${e}_${i.incr()}`;t.setAttribute("id",r),m[e]=r})),Array.from(b.querySelectorAll("*")).concat(b).forEach((e=>{if("script"===e.tagName){if(e.remove(),!n)return;{const r=document.createElement("script");r.appendChild(e.childNodes[0]),t.appendChild(r)}}const r=[];for(let t=0;t<e.attributes.length;t++){const{name:o,value:a}=e.attributes[t],i=s(m,a,o);a!==i&&e.setAttribute(o,i),!g.includes(o.toLowerCase())||n?["href","xlink:href","values"].includes(o)&&a.startsWith("javascript")&&!n&&r.push(o):r.push(o)}if(r.forEach((t=>e.removeAttribute(t))),"style"===e.tagName&&!l){let t=a(e.innerHTML,`[data-id="${y}"]`,m);t=s(m,t),t!==e.innerHTML&&(e.innerHTML=t)}})),t.innerHTML=d?b.outerHTML:b.innerHTML,!f)for(let e=0;e<b.attributes.length;e++){const{name:r,value:n}=b.attributes[e];t.getAttribute(r)&&!p.has(r)||(p.add(r),t.setAttribute(r,n))}u[y]=p,t.setAttribute("data-id",y);const v=new CustomEvent("iconload",{bubbles:!0});if(t.dispatchEvent(v),t.getAttribute("oniconload")){t.setAttribute("onauxclick",t.getAttribute("oniconload"));const e=new CustomEvent("auxclick",{bubbles:!1,view:window});t.dispatchEvent(e),t.removeAttribute("onauxclick")}},d={},f={},h=async r=>{const o=new URL(r.getAttribute("data-src"),globalThis.location),a=o.toString().replace(o.hash,""),s=o.hash.replace("#",""),i=r.getAttribute("data-cache"),c="enabled"===r.getAttribute("data-js"),u="disabled"===r.getAttribute("data-unique-ids"),b="disabled"===r.getAttribute("data-css-scoping"),g=await(async e=>{let r;try{r=await t(`loader_${e}`)}catch(t){}if(!r)try{r=localStorage.getItem(`loader_${e}`)}catch(t){}if(r)return r=JSON.parse(r),Date.now()<r.expiry?r.data:void n(`loader_${e}`)})(a),p="disabled"!==i,y=l.bind(self,r,{enableJs:c,disableUniqueIds:u,disableCssScoping:b,spriteIconId:s});if(f[a]||p&&g){const t=f[a]||g;y(t)}else{if(d[a])return void setTimeout((()=>h(r)),20);d[a]=!0,fetch(a).then((t=>{if(!t.ok)throw Error(`Request for '${a}' returned ${t.status} (${t.statusText})`);return t.text()})).then((t=>{const r=t.toLowerCase().trim();if(!(r.startsWith("<svg")||r.startsWith("<?xml")||r.startsWith("<!doctype")))throw Error(`Resource '${a}' returned an invalid SVG file`);p&&(async(t,r,n)=>{const o=parseInt(n,10),a=JSON.stringify({data:r,expiry:Date.now()+(Number.isNaN(o)?2592e6:1e3*o)});try{await e(`loader_${t}`,a)}catch(e){try{localStorage.setItem(`loader_${t}`,a)}catch(t){console.warn("Failed to set cache: ",t)}}})(a,t,i),f[a]=t,y(t)})).catch((t=>{console.error(t);const e=new CustomEvent("iconloaderror",{bubbles:!0,detail:t.toString()});r.dispatchEvent(e),r.getAttribute("oniconloaderror")&&Function("error",r.getAttribute("oniconloaderror"))(t)})).finally((()=>{delete d[a]}))}};let b;globalThis.IntersectionObserver&&(b=new IntersectionObserver((t=>{t.forEach((t=>{t.isIntersecting&&(h(t.target),b.unobserve(t.target))}))}),{rootMargin:"1200px"}));const g=[];function p(){Array.from(document.querySelectorAll("svg[data-src]:not([data-id])")).forEach((t=>{-1===g.indexOf(t)&&(g.push(t),"lazy"===t.getAttribute("data-loading")?b.observe(t):h(t))}))}let y=!1;if(globalThis.addEventListener){const m=setInterval((()=>{p()}),100);function v(){clearInterval(m),p(),y||(y=!0,new MutationObserver((t=>{t.some((t=>Array.from(t.addedNodes).some((t=>t.nodeType===Node.ELEMENT_NODE&&(t.getAttribute("data-src")&&!t.getAttribute("data-id")||t.querySelector("svg[data-src]:not([data-id])"))))))&&p(),t.forEach((t=>{"attributes"===t.type&&h(t.target)}))})).observe(document.documentElement,{attributeFilter:["data-src"],attributes:!0,childList:!0,subtree:!0}))}"interactive"===document.readyState?v():globalThis.addEventListener("DOMContentLoaded",(()=>{v()}))}globalThis.SVGLoader={},globalThis.SVGLoader.destroyCache=async()=>{try{const t=await o();for(const e of t)e[0].startsWith("loader_")&&await n(e[0])}catch(t){}Object.keys(localStorage).forEach((t=>{t.startsWith("loader_")&&localStorage.removeItem(t)}))}})()})();
//# sourceMappingURL=svg-loader.min.js.map