-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlast-icon.min.js
2 lines (2 loc) · 5.37 KB
/
last-icon.min.js
1
2
(()=>{var o="https://cdn.jsdelivr.net/",g={},n={debug:!1,lazy:!0,replaceName:{},fonts:[],defaultSet:"tabler",defaultStroke:2,sets:{bootstrap:{alias:"bs",svgPath:()=>o+"npm/bootstrap-icons@1/icons/{icon}.svg"},boxicons:{alias:"bx",defaultType:"solid",svgPath:()=>o+"npm/boxicons@2/svg/{type}/{prefix}-{icon}.svg",fixFill:!0,fontClass:()=>"bx {prefix}-{icon}",prefixes:{solid:"bxs",regular:"bx",logos:"bxl"}},bytesize:{alias:"by",svgPath:()=>o+"npm/bytesize-icons@1/dist/icons/{icon}.svg",useStroke:!0},cssgg:{alias:"gg",svgPath:()=>o+"npm/css.gg@2/icons/svg/{icon}.svg"},emojicc:{alias:"em",svgPath:()=>o+"npm/emoji-cc@1/svg/{icon}.svg"},eos:{alias:"eo",defaultType:"solid",svgPath:()=>o+"gh/lekoala/eos-icons-mirror/{type}/{icon}.svg",fixFill:!0},feather:{alias:"ft",svgPath:()=>o+"npm/feather-icons@4/dist/icons/{icon}.svg"},flags:{alias:"fl",defaultType:"4x3",svgPath:()=>o+"npm/flag-svg-collection@1/flags/{type}/{icon}.svg"},fontawesome:{alias:"fa",defaultType:"solid",svgPath:()=>o+"npm/@fortawesome/fontawesome-free@5/svgs/{type}/{icon}.svg",fixFill:!0,fontClass:()=>"{prefix} fa-{icon}",prefixes:{solid:"fas",regular:"far",light:"fal",duotone:"fad",brands:"fab"}},iconoir:{alias:"in",svgPath:()=>o+"gh/lucaburgio/iconoir/icons/{icon}.svg",fontClass:()=>"iconoir-{icon}",useStroke:!0},iconpark:{alias:"ip",types:[],svgPath:()=>o+"gh/bytedance/IconPark/source/{type}/{icon}.svg",useStroke:!0},lucide:{alias:"lu",svgPath:()=>o+"npm/lucide-static/icons/{icon}.svg"},material:{alias:"mi",defaultType:"filled",svgPath:()=>o+"npm/@material-design-icons/svg/{type}/{icon}.svg",fontClass:t=>t==="filled"?"material-icons":"material-icons-{type}"},phosphor:{alias:"ph",defaultType:"regular",svgPath:t=>t==="regular"?o+"npm/@phosphor-icons/core@2/assets/{type}/{icon}.svg":o+"npm/@phosphor-icons/core@2/assets/{type}/{icon}-{type}.svg",fontClass:t=>t==="regular"?"ph ph-{icon}":"ph-{type} ph-{icon}"},supertiny:{alias:"st",svgPath:()=>o+"npm/super-tiny-icons/images/svg/{icon}.svg"},symbols:{alias:"ms",defaultType:"outlined",svgPath:()=>o+"npm/@material-symbols/[email protected]/{type}/{icon}.svg",fixFill:!0,fontClass:()=>"material-symbols-{type}",opticalFont:!0},tabler:{alias:"ti",svgPath:()=>o+"npm/@tabler/icons@2/icons/{icon}.svg",useStroke:!0,fontClass:()=>"ti ti-{icon}"}}},b=new window.IntersectionObserver((t,e)=>{t.forEach(async s=>{s.isIntersecting&&(e.unobserve(s.target),s.target.init())})});function u(t,e,s,i){return t=t.replace("{icon}",e),i?t=t.replaceAll("{type}",i):t=t.replace("-{type}",""),s.prefixes&&s.prefixes[i]&&(t=t.replace("{prefix}",s.prefixes[i])),t}function a(t){n.debug&&console.log(`[l-i] ${t}`)}function y(t,e,s){let i=e.svgPath(s);if(!i)throw Error(`Icon set ${e} does not exists`);let r=`${e.name}-${t}-${s||"base"}`;return i=u(i,t,e,s),i&&g[r]?(a(`Fetching ${r} from cache`),g[r]):(a(`Fetching ${r} from url ${i}`),g[r]=fetch(i).then(function(l){if(l.ok)return l.text();throw Error(l.status)}),g[r])}function v(t,e,s,i){if(n.replaceName[e]&&(e=n.replaceName[e]),!i&&s.defaultType&&(i=s.defaultType),n.fonts.includes(s.name)&&!t.hasAttribute("stroke")){a(`Using font for ${e}`);let r=s.fontClass(i),l=r.includes("{icon}");r=u(r,e,s,i),l?t.innerHTML=`<i class="${r}"></i>`:t.innerHTML=`<i class="${r}">${e}</i>`,t.stroke&&s.opticalFont&&t.style.setProperty("--weight",t.stroke*100);return}y(e,s,i).then(r=>{r.includes("class=")&&(r=r.replace(/ class="([a-z- ]*)"/g,"")),(t.stroke||s.useStroke)&&(r=r.replace(/stroke-width="([0-9\.]*)"/g,`stroke-width="${t.stroke}"`)),s.fixFill&&(r=r.replace(/(<svg.*?)>/,'$1 fill="currentColor">')),t.defaultHTML&&(r=r.replace("</svg>",`${t.defaultHTML}</svg>`)),t.innerHTML=r}).catch(r=>{t.innerHTML="<span>\u26A0\uFE0F</span>",console.error(`Failed to load icon ${e} (error ${r})`)})}function x(t){let e=t.getBoundingClientRect();return e.top>=0&&e.left>=0&&e.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&e.right<=(window.innerWidth||document.documentElement.clientWidth)}function h(...t){let e=i=>i&&typeof i=="object",s=Array.isArray;return t.reduce((i,r)=>(Object.keys(r).forEach(l=>{let f=i[l],c=r[l];s(f)&&s(c)?i[l]=f.concat(...c):e(f)&&e(c)?i[l]=h(f,c):i[l]=c}),i),{})}var p={};function d(){for(let[t,e]of Object.entries(n.sets))p[e.alias]=t,e.name=t}d();var m=class extends HTMLElement{static configure(e={}){for(let s in e){if(typeof n[s]>"u"){console.error(`Invalid option key ${s}`);return}Array.isArray(e[s])?n[s]=n[s].concat(e[s]):typeof e[s]=="object"?n[s]=h(n[s],e[s]):n[s]=e[s]}return d(),a("configuring options"),n}get type(){return this.getAttribute("type")||null}get set(){let e=this.getAttribute("set");return p[e]||n.defaultSet}get iconSet(){return n.sets[this.set]}get stroke(){return this.getAttribute("stroke")||n.defaultStroke}static get observedAttributes(){return["name","stroke","size","set","type"]}connectedCallback(){setTimeout(()=>{n.lazy&&!x(this)?b.observe(this):this.init()})}init(){this.defaultHTML=this.innerHTML,this.loadIcon()}loadIcon(){let e=this.getAttribute("name");if(!e)return;let s=this.iconSet;this.innerHTML="";let i=this.getAttribute("size");i&&this.setSize(i),v(this,e,s,this.type)}setSize(e){this.style.setProperty("--size",`${e}px`),this.iconSet.opticalFont&&this.style.setProperty("--opsz",e)}attributeChangedCallback(e,s,i){typeof this.defaultHTML=="string"&&(a(`Attr ${e} changed from ${s} to ${i}`),e==="size"?this.setSize(i):i&&(a("attribute changed"),this.loadIcon()))}};customElements.define("l-i",m);})();
//# sourceMappingURL=last-icon.min.js.map