diff --git a/last-icon.min.js b/last-icon.min.js index 90ad893..3ff5e73 100644 --- a/last-icon.min.js +++ b/last-icon.min.js @@ -1,2 +1,2 @@ -(()=>{var o="https://cdn.jsdelivr.net/",f={},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:s=>s==="filled"?"material-icons":"material-icons-{type}"},phosphor:{alias:"ph",defaultType:"regular",svgPath:s=>s==="regular"?o+"npm/@phosphor-icons/core@2/assets/{type}/{icon}.svg":o+"npm/@phosphor-icons/core@2/assets/{type}/{icon}-{type}.svg",fontClass:s=>s==="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/svg-400@0.5/{type}/{icon}.svg",fixFill:!0,fontClass:()=>"material-symbols-{type}",opticalFont:!0},tabler:{alias:"tb",svgPath:()=>o+"npm/@tabler/icons@2.17.0/icons/{icon}.svg",useStroke:!0}}},m=new window.IntersectionObserver((s,t)=>{s.forEach(async e=>{e.isIntersecting&&(t.unobserve(e.target),e.target.init())})});function g(s,t,e,r){return s=s.replace("{icon}",t),r?s=s.replaceAll("{type}",r):s=s.replace("-{type}",""),e.prefixes&&e.prefixes[r]&&(s=s.replace("{prefix}",e.prefixes[r])),s}function a(s){n.debug&&console.log(`[l-i] ${s}`)}function b(s,t,e){let r=t.svgPath(e),i=`${t.name}-${s}-${e||"base"}`;return r?(r=g(r,s,t,e),r&&f[i]?(a(`Fetching ${i} from cache`),f[i]):(a(`Fetching ${i} from url ${r}`),f[i]=fetch(r).then(function(l){if(l.ok)return l.text();throw Error(l.status)}),f[i])):new Promise(()=>{console.error(`Icon set ${t} does not exists`)})}function y(s,t,e,r){if(n.replaceName[t]&&(t=n.replaceName[t]),!r&&e.defaultType&&(r=e.defaultType),n.fonts.includes(e.name)){a(`Using font for ${t}`);let i=e.fontClass(r),l=i.includes("{icon}");i=g(i,t,e,r),l?s.innerHTML=``:s.innerHTML=`${t}`,s.stroke&&e.opticalFont&&s.style.setProperty("--weight",s.stroke*100);return}b(t,e,r).then(i=>{i.includes("class=")&&(i=i.replace(/ class="([a-z- ]*)"/g,"")),(s.stroke||e.useStroke)&&(i=i.replace(/stroke-width="([0-9\.]*)"/g,`stroke-width="${s.stroke}"`)),e.fixFill&&(i=i.replace(/(/,'$1 fill="currentColor">')),s.defaultHTML&&(i=i.replace("",`${s.defaultHTML}`)),s.innerHTML=i}).catch(i=>{s.innerHTML="\u26A0\uFE0F",console.error(`Failed to load icon ${t} (error ${i})`)})}function v(s){let t=s.getBoundingClientRect();return t.top>=0&&t.left>=0&&t.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&t.right<=(window.innerWidth||document.documentElement.clientWidth)}function u(...s){let t=e=>e&&typeof e=="object";return s.reduce((e,r)=>(Object.keys(r).forEach(i=>{let l=e[i],c=r[i];Array.isArray(l)&&Array.isArray(c)?e[i]=l.concat(...c):t(l)&&t(c)?e[i]=u(l,c):e[i]=c}),e),{})}var h={};function p(){for(let[s,t]of Object.entries(n.sets))h[t.alias]=s,t.name=s}p();var d=class extends HTMLElement{static configure(t={}){for(let e in t){if(typeof n[e]>"u"){console.error(`Invalid option key ${e}`);return}Array.isArray(t[e])?n[e]=n[e].concat(t[e]):typeof t[e]=="object"?n[e]=u(n[e],t[e]):n[e]=t[e]}return p(),a("configuring options"),n}get type(){return this.getAttribute("type")||null}get set(){let t=this.getAttribute("set")||n.defaultSet;return h[t]||t}get iconSet(){return n.sets[this.set]||null}get stroke(){return this.getAttribute("stroke")||n.defaultStroke}static get observedAttributes(){return["name","stroke","size","set","type"]}connectedCallback(){setTimeout(()=>{n.lazy&&!v(this)?m.observe(this):this.init()})}init(){this.defaultHTML=this.innerHTML,this.loadIcon()}loadIcon(){let t=this.getAttribute("name"),e=this.iconSet;!t||!e||(this.innerHTML="",this.hasAttribute("size")&&this.setSize(this.getAttribute("size")),y(this,t,e,this.type))}setSize(t){this.style.setProperty("--size",`${t}px`),this.iconSet.opticalFont&&this.style.setProperty("--opsz",t)}attributeChangedCallback(t,e,r){typeof this.defaultHTML=="string"&&(a(`Attr ${t} changed from ${e} to ${r}`),t==="size"?this.setSize(r):r&&(a("attribute changed"),this.loadIcon()))}};customElements.define("l-i",d);})(); +(()=>{var o="https://cdn.jsdelivr.net/",f={},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:s=>s==="filled"?"material-icons":"material-icons-{type}"},phosphor:{alias:"ph",defaultType:"regular",svgPath:s=>s==="regular"?o+"npm/@phosphor-icons/core@2/assets/{type}/{icon}.svg":o+"npm/@phosphor-icons/core@2/assets/{type}/{icon}-{type}.svg",fontClass:s=>s==="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/svg-400@0.5/{type}/{icon}.svg",fixFill:!0,fontClass:()=>"material-symbols-{type}",opticalFont:!0},tabler:{alias:"tb",svgPath:()=>o+"npm/@tabler/icons@2/icons/{icon}.svg",useStroke:!0,fontClass:()=>"ti ti-{icon}"}}},m=new window.IntersectionObserver((s,t)=>{s.forEach(async e=>{e.isIntersecting&&(t.unobserve(e.target),e.target.init())})});function g(s,t,e,r){return s=s.replace("{icon}",t),r?s=s.replaceAll("{type}",r):s=s.replace("-{type}",""),e.prefixes&&e.prefixes[r]&&(s=s.replace("{prefix}",e.prefixes[r])),s}function a(s){n.debug&&console.log(`[l-i] ${s}`)}function b(s,t,e){let r=t.svgPath(e),i=`${t.name}-${s}-${e||"base"}`;return r?(r=g(r,s,t,e),r&&f[i]?(a(`Fetching ${i} from cache`),f[i]):(a(`Fetching ${i} from url ${r}`),f[i]=fetch(r).then(function(l){if(l.ok)return l.text();throw Error(l.status)}),f[i])):new Promise(()=>{console.error(`Icon set ${t} does not exists`)})}function y(s,t,e,r){if(n.replaceName[t]&&(t=n.replaceName[t]),!r&&e.defaultType&&(r=e.defaultType),n.fonts.includes(e.name)){a(`Using font for ${t}`);let i=e.fontClass(r),l=i.includes("{icon}");i=g(i,t,e,r),l?s.innerHTML=``:s.innerHTML=`${t}`,s.stroke&&e.opticalFont&&s.style.setProperty("--weight",s.stroke*100);return}b(t,e,r).then(i=>{i.includes("class=")&&(i=i.replace(/ class="([a-z- ]*)"/g,"")),(s.stroke||e.useStroke)&&(i=i.replace(/stroke-width="([0-9\.]*)"/g,`stroke-width="${s.stroke}"`)),e.fixFill&&(i=i.replace(/(/,'$1 fill="currentColor">')),s.defaultHTML&&(i=i.replace("",`${s.defaultHTML}`)),s.innerHTML=i}).catch(i=>{s.innerHTML="\u26A0\uFE0F",console.error(`Failed to load icon ${t} (error ${i})`)})}function v(s){let t=s.getBoundingClientRect();return t.top>=0&&t.left>=0&&t.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&t.right<=(window.innerWidth||document.documentElement.clientWidth)}function u(...s){let t=e=>e&&typeof e=="object";return s.reduce((e,r)=>(Object.keys(r).forEach(i=>{let l=e[i],c=r[i];Array.isArray(l)&&Array.isArray(c)?e[i]=l.concat(...c):t(l)&&t(c)?e[i]=u(l,c):e[i]=c}),e),{})}var h={};function p(){for(let[s,t]of Object.entries(n.sets))h[t.alias]=s,t.name=s}p();var d=class extends HTMLElement{static configure(t={}){for(let e in t){if(typeof n[e]>"u"){console.error(`Invalid option key ${e}`);return}Array.isArray(t[e])?n[e]=n[e].concat(t[e]):typeof t[e]=="object"?n[e]=u(n[e],t[e]):n[e]=t[e]}return p(),a("configuring options"),n}get type(){return this.getAttribute("type")||null}get set(){let t=this.getAttribute("set")||n.defaultSet;return h[t]||t}get iconSet(){return n.sets[this.set]||null}get stroke(){return this.getAttribute("stroke")||n.defaultStroke}static get observedAttributes(){return["name","stroke","size","set","type"]}connectedCallback(){setTimeout(()=>{n.lazy&&!v(this)?m.observe(this):this.init()})}init(){this.defaultHTML=this.innerHTML,this.loadIcon()}loadIcon(){let t=this.getAttribute("name"),e=this.iconSet;!t||!e||(this.innerHTML="",this.hasAttribute("size")&&this.setSize(this.getAttribute("size")),y(this,t,e,this.type))}setSize(t){this.style.setProperty("--size",`${t}px`),this.iconSet.opticalFont&&this.style.setProperty("--opsz",t)}attributeChangedCallback(t,e,r){typeof this.defaultHTML=="string"&&(a(`Attr ${t} changed from ${e} to ${r}`),t==="size"?this.setSize(r):r&&(a("attribute changed"),this.loadIcon()))}};customElements.define("l-i",d);})(); //# sourceMappingURL=last-icon.min.js.map diff --git a/last-icon.min.js.map b/last-icon.min.js.map index ead9077..9350c35 100644 --- a/last-icon.min.js.map +++ b/last-icon.min.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["last-icon.js"], - "sourcesContent": ["const JSDELIVR = \"https://cdn.jsdelivr.net/\";\r\nconst CACHE = {};\r\n\r\n/**\r\n * @typedef IconSet\r\n * @property {String} alias Short two letters alias\r\n * @property {Function} svgPath The svg path\r\n * @property {Boolean} [fixFill] Does this set needs fixing fill:currentColor ?\r\n * @property {String} [useStroke] Add stroke to svg\r\n * @property {String} [defaultStroke] Default stroke to use (if supports stroke)\r\n * @property {String} [defaultType] Default type to use (when there are multiple types)\r\n * @property {Object.} [prefixes] Types to prefixes\r\n * @property {Function} [fontClass] Font class\r\n * @property {Boolean} [opticalFont] Is an optical font?\r\n * @property {String} [name] Full name (injected automatically)\r\n */\r\n\r\n/**\r\n * @typedef Options\r\n * @property {Boolean} debug Should we output messages to console\r\n * @property {Boolean} lazy Load icons lazily\r\n * @property {Object} replaceName Transparently replace icons with other values\r\n * @property {Array} fonts Icon sets using font icons rather than svg\r\n * @property {String} defaultSet Default icon set\r\n * @property {Object.} sets Available iconsets\r\n */\r\nconst options = {\r\n debug: false,\r\n lazy: true,\r\n replaceName: {},\r\n fonts: [],\r\n defaultSet: \"tabler\",\r\n defaultStroke: 2,\r\n sets: {\r\n bootstrap: {\r\n alias: \"bs\",\r\n svgPath: () => JSDELIVR + \"npm/bootstrap-icons@1/icons/{icon}.svg\",\r\n },\r\n boxicons: {\r\n alias: \"bx\",\r\n // types: [\"solid\", \"regular\", \"logos\"],\r\n defaultType: \"solid\",\r\n svgPath: () => JSDELIVR + \"npm/boxicons@2/svg/{type}/{prefix}-{icon}.svg\",\r\n fixFill: true,\r\n fontClass: () => \"bx {prefix}-{icon}\",\r\n prefixes: {\r\n solid: \"bxs\",\r\n regular: \"bx\",\r\n logos: \"bxl\",\r\n },\r\n },\r\n bytesize: {\r\n alias: \"by\",\r\n svgPath: () => JSDELIVR + \"npm/bytesize-icons@1/dist/icons/{icon}.svg\",\r\n useStroke: true,\r\n },\r\n cssgg: {\r\n alias: \"gg\",\r\n svgPath: () => JSDELIVR + \"npm/css.gg@2/icons/svg/{icon}.svg\",\r\n },\r\n emojicc: {\r\n alias: \"em\",\r\n svgPath: () => JSDELIVR + \"npm/emoji-cc@1/svg/{icon}.svg\",\r\n },\r\n eos: {\r\n alias: \"eo\",\r\n // types: [\"solid\", \"outlined\", \"animated\"],\r\n defaultType: \"solid\",\r\n svgPath: () => JSDELIVR + \"gh/lekoala/eos-icons-mirror/{type}/{icon}.svg\",\r\n fixFill: true,\r\n },\r\n feather: {\r\n alias: \"ft\",\r\n svgPath: () => JSDELIVR + \"npm/feather-icons@4/dist/icons/{icon}.svg\",\r\n },\r\n flags: {\r\n alias: \"fl\",\r\n // types: [\"4x3\", \"1x1\"],\r\n defaultType: \"4x3\",\r\n svgPath: () => JSDELIVR + \"npm/flag-svg-collection@1/flags/{type}/{icon}.svg\",\r\n },\r\n fontawesome: {\r\n alias: \"fa\",\r\n // types: [\"solid\", \"regular\", \"brands\", \"light\", \"duotone\"],\r\n defaultType: \"solid\",\r\n svgPath: () => JSDELIVR + \"npm/@fortawesome/fontawesome-free@5/svgs/{type}/{icon}.svg\",\r\n fixFill: true,\r\n fontClass: () => \"{prefix} fa-{icon}\",\r\n prefixes: {\r\n solid: \"fas\",\r\n regular: \"far\",\r\n light: \"fal\",\r\n duotone: \"fad\",\r\n brands: \"fab\",\r\n },\r\n },\r\n iconoir: {\r\n alias: \"in\",\r\n svgPath: () => JSDELIVR + \"gh/lucaburgio/iconoir/icons/{icon}.svg\",\r\n fontClass: () => \"iconoir-{icon}\",\r\n useStroke: true,\r\n },\r\n iconpark: {\r\n alias: \"ip\",\r\n types: [], // see full list here https://github.com/bytedance/IconPark/tree/master/source\r\n svgPath: () => JSDELIVR + \"gh/bytedance/IconPark/source/{type}/{icon}.svg\",\r\n useStroke: true,\r\n },\r\n lucide: {\r\n alias: \"lu\",\r\n svgPath: () => JSDELIVR + \"npm/lucide-static/icons/{icon}.svg\",\r\n },\r\n material: {\r\n alias: \"mi\",\r\n // types: [\"filled\", \"outlined\", \"round\", \"sharp\", \"two-tone\"],\r\n defaultType: \"filled\",\r\n svgPath: () => JSDELIVR + \"npm/@material-design-icons/svg/{type}/{icon}.svg\",\r\n fontClass: (type) => {\r\n if (type === \"filled\") {\r\n return \"material-icons\";\r\n }\r\n return \"material-icons-{type}\";\r\n },\r\n },\r\n phosphor: {\r\n alias: \"ph\",\r\n // types: [\"regular\", \"bold\", \"duotone\", \"fill\", \"light\", \"thin\"],\r\n defaultType: \"regular\",\r\n svgPath: (type) => {\r\n if (type === \"regular\") {\r\n return JSDELIVR + \"npm/@phosphor-icons/core@2/assets/{type}/{icon}.svg\";\r\n }\r\n return JSDELIVR + \"npm/@phosphor-icons/core@2/assets/{type}/{icon}-{type}.svg\";\r\n },\r\n fontClass: (type) => {\r\n if (type === \"regular\") {\r\n return \"ph ph-{icon}\";\r\n }\r\n return \"ph-{type} ph-{icon}\";\r\n },\r\n },\r\n supertiny: {\r\n alias: \"st\",\r\n svgPath: () => JSDELIVR + \"npm/super-tiny-icons/images/svg/{icon}.svg\",\r\n },\r\n symbols: {\r\n alias: \"ms\",\r\n // types: [\"outlined\", \"rounded\", \"sharp\"],\r\n defaultType: \"outlined\",\r\n svgPath: () => JSDELIVR + \"npm/@material-symbols/svg-400@0.5/{type}/{icon}.svg\",\r\n fixFill: true,\r\n fontClass: () => \"material-symbols-{type}\",\r\n opticalFont: true,\r\n },\r\n tabler: {\r\n alias: \"tb\",\r\n svgPath: () => JSDELIVR + \"npm/@tabler/icons@2.17.0/icons/{icon}.svg\",\r\n useStroke: true,\r\n },\r\n },\r\n};\r\n\r\n/**\r\n * @var {IntersectionObserver}\r\n */\r\nconst observer = new window.IntersectionObserver((entries, observerRef) => {\r\n entries.forEach(async (entry) => {\r\n if (entry.isIntersecting) {\r\n observerRef.unobserve(entry.target);\r\n entry.target.init();\r\n }\r\n });\r\n});\r\n\r\n/**\r\n * @param {string} value\r\n * @param {string} iconName\r\n * @param {IconSet} iconSet\r\n * @param {string} iconType\r\n * @return {string}\r\n */\r\nfunction replacePlaceholders(value, iconName, iconSet, iconType) {\r\n value = value.replace(\"{icon}\", iconName);\r\n if (iconType) {\r\n value = value.replaceAll(\"{type}\", iconType);\r\n } else {\r\n // Maybe we want to remove the type like in material icons\r\n value = value.replace(\"-{type}\", \"\");\r\n }\r\n if (iconSet.prefixes && iconSet.prefixes[iconType]) {\r\n value = value.replace(\"{prefix}\", iconSet.prefixes[iconType]);\r\n }\r\n return value;\r\n}\r\n\r\nfunction log(message) {\r\n if (options.debug) {\r\n console.log(`[l-i] ${message}`);\r\n }\r\n}\r\n\r\n/**\r\n * @param {string} iconName\r\n * @param {IconSet} iconSet\r\n * @param {string} iconType\r\n * @return {Promise}\r\n */\r\nfunction getIconSvg(iconName, iconSet, iconType) {\r\n let iconUrl = iconSet.svgPath(iconType);\r\n let cacheKey = `${iconSet.name}-${iconName}-${iconType || \"base\"}`;\r\n if (!iconUrl) {\r\n return new Promise(() => {\r\n console.error(`Icon set ${iconSet} does not exists`);\r\n });\r\n }\r\n\r\n iconUrl = replacePlaceholders(iconUrl, iconName, iconSet, iconType);\r\n\r\n // If we have it in cache\r\n if (iconUrl && CACHE[cacheKey]) {\r\n log(`Fetching ${cacheKey} from cache`);\r\n return CACHE[cacheKey];\r\n }\r\n\r\n // Or resolve\r\n log(`Fetching ${cacheKey} from url ${iconUrl}`);\r\n CACHE[cacheKey] = fetch(iconUrl).then(function (response) {\r\n if (response.ok) {\r\n return response.text();\r\n }\r\n throw Error(response.status);\r\n });\r\n return CACHE[cacheKey];\r\n}\r\n\r\n/**\r\n * @param {LastIcon} inst\r\n * @param {string} iconName\r\n * @param {IconSet} iconSet\r\n * @param {string} iconType\r\n */\r\nfunction refreshIcon(inst, iconName, iconSet, iconType) {\r\n // Replace name\r\n if (options.replaceName[iconName]) {\r\n iconName = options.replaceName[iconName];\r\n }\r\n // Set default type if any\r\n if (!iconType && iconSet.defaultType) {\r\n iconType = iconSet.defaultType;\r\n }\r\n\r\n // Use font\r\n if (options.fonts.includes(iconSet.name)) {\r\n log(`Using font for ${iconName}`);\r\n let iconClass = iconSet.fontClass(iconType);\r\n let nameAsClass = iconClass.includes(\"{icon}\");\r\n iconClass = replacePlaceholders(iconClass, iconName, iconSet, iconType);\r\n if (nameAsClass) {\r\n inst.innerHTML = ``;\r\n } else {\r\n inst.innerHTML = `${iconName}`;\r\n }\r\n if (inst.stroke && iconSet.opticalFont) {\r\n inst.style.setProperty(\"--weight\", inst.stroke * 100);\r\n }\r\n return; // Return early\r\n }\r\n\r\n getIconSvg(iconName, iconSet, iconType)\r\n .then((iconData) => {\r\n // Strip class attribute as it may be affected by css\r\n if (iconData.includes(\"class=\")) {\r\n iconData = iconData.replace(/ class=\"([a-z- ]*)\"/g, \"\");\r\n }\r\n // Add and/or fix stroke\r\n if (inst.stroke || iconSet.useStroke) {\r\n iconData = iconData.replace(/stroke-width=\"([0-9\\.]*)\"/g, `stroke-width=\"${inst.stroke}\"`);\r\n }\r\n // Fix fill to currentColor\r\n if (iconSet.fixFill) {\r\n iconData = iconData.replace(/(/, '$1 fill=\"currentColor\">');\r\n }\r\n // If we have some html, pass it along (useful for svg anim)\r\n if (inst.defaultHTML) {\r\n iconData = iconData.replace(\"\", `${inst.defaultHTML}`);\r\n }\r\n inst.innerHTML = iconData;\r\n })\r\n .catch((error) => {\r\n inst.innerHTML = \"\u26A0\uFE0F\";\r\n console.error(`Failed to load icon ${iconName} (error ${error})`);\r\n });\r\n}\r\n\r\n/**\r\n * @param {HTMLElement} element\r\n * @returns {Boolean}\r\n */\r\nfunction isInViewport(element) {\r\n const rect = element.getBoundingClientRect();\r\n return (\r\n rect.top >= 0 &&\r\n rect.left >= 0 &&\r\n rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&\r\n rect.right <= (window.innerWidth || document.documentElement.clientWidth)\r\n );\r\n}\r\n\r\n/**\r\n * Performs a deep merge of objects and returns new object. Does not modify\r\n * objects (immutable) and merges arrays via concatenation.\r\n *\r\n * @param {...object} objects - Objects to merge\r\n * @returns {object} New object with merged key/values\r\n */\r\nfunction mergeDeep(...objects) {\r\n const isObject = (obj) => obj && typeof obj === \"object\";\r\n\r\n return objects.reduce((prev, obj) => {\r\n Object.keys(obj).forEach((key) => {\r\n const pVal = prev[key];\r\n const oVal = obj[key];\r\n\r\n if (Array.isArray(pVal) && Array.isArray(oVal)) {\r\n prev[key] = pVal.concat(...oVal);\r\n } else if (isObject(pVal) && isObject(oVal)) {\r\n prev[key] = mergeDeep(pVal, oVal);\r\n } else {\r\n prev[key] = oVal;\r\n }\r\n });\r\n\r\n return prev;\r\n }, {});\r\n}\r\n\r\nlet aliases = {};\r\nfunction processIconSets() {\r\n for (const [key, set] of Object.entries(options.sets)) {\r\n // List aliases for easy retrieval\r\n aliases[set.alias] = key;\r\n // Include full name in iconset definition\r\n set.name = key;\r\n }\r\n}\r\nprocessIconSets();\r\n\r\nclass LastIcon extends HTMLElement {\r\n /**\r\n * @param {object} opts\r\n * @returns {Options} The updated option object\r\n */\r\n static configure(opts = {}) {\r\n for (const k in opts) {\r\n if (typeof options[k] === \"undefined\") {\r\n console.error(`Invalid option key ${k}`);\r\n return;\r\n }\r\n if (Array.isArray(opts[k])) {\r\n options[k] = options[k].concat(opts[k]);\r\n } else if (typeof opts[k] === \"object\") {\r\n options[k] = mergeDeep(options[k], opts[k]);\r\n } else {\r\n options[k] = opts[k];\r\n }\r\n }\r\n processIconSets();\r\n // Log after we had the opportunity to change debug flag\r\n log(\"configuring options\");\r\n return options;\r\n }\r\n\r\n /**\r\n * @return {String|null}\r\n */\r\n get type() {\r\n return this.getAttribute(\"type\") || null;\r\n }\r\n\r\n /**\r\n * @return {String}\r\n */\r\n get set() {\r\n let v = this.getAttribute(\"set\") || options.defaultSet;\r\n return aliases[v] || v;\r\n }\r\n\r\n /**\r\n * @return {IconSet|null}\r\n */\r\n get iconSet() {\r\n return options.sets[this.set] || null;\r\n }\r\n\r\n /**\r\n * @return {Number}\r\n */\r\n get stroke() {\r\n return this.getAttribute(\"stroke\") || options.defaultStroke;\r\n }\r\n\r\n static get observedAttributes() {\r\n return [\"name\", \"stroke\", \"size\", \"set\", \"type\"];\r\n }\r\n\r\n connectedCallback() {\r\n // innerHTML is not available because not parsed yet\r\n // setTimeout also allows whenDefined to kick in before init\r\n setTimeout(() => {\r\n if (options.lazy && !isInViewport(this)) {\r\n // observer will call init when element is visible\r\n observer.observe(this);\r\n } else {\r\n // init directly\r\n this.init();\r\n }\r\n });\r\n }\r\n\r\n init() {\r\n // Store default content as we will inject it back later\r\n this.defaultHTML = this.innerHTML;\r\n this.loadIcon();\r\n }\r\n\r\n loadIcon() {\r\n const name = this.getAttribute(\"name\");\r\n const iconSet = this.iconSet;\r\n if (!name || !iconSet) {\r\n return;\r\n }\r\n\r\n // Clear icon\r\n this.innerHTML = \"\";\r\n // Useful for customizing size in css\r\n if (this.hasAttribute(\"size\")) {\r\n this.setSize(this.getAttribute(\"size\"));\r\n }\r\n refreshIcon(this, name, iconSet, this.type);\r\n }\r\n\r\n setSize(size) {\r\n this.style.setProperty(\"--size\", `${size}px`);\r\n if (this.iconSet.opticalFont) {\r\n this.style.setProperty(\"--opsz\", size);\r\n }\r\n }\r\n\r\n attributeChangedCallback(attr, oldVal, newVal) {\r\n // Wait until properly loaded for the first time\r\n if (typeof this.defaultHTML !== \"string\") {\r\n return;\r\n }\r\n log(`Attr ${attr} changed from ${oldVal} to ${newVal}`);\r\n if (attr === \"size\") {\r\n this.setSize(newVal);\r\n } else if (newVal) {\r\n log(\"attribute changed\");\r\n this.loadIcon();\r\n }\r\n }\r\n}\r\n\r\ncustomElements.define(\"l-i\", LastIcon);\r\n"], - "mappings": "MAAA,G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,aAAa,QAAQ,GAAK,EAAQ,aAChD,WAEW,qBAAqB,CAC9B,MAAO,CAAC,OAAQ,SAAU,OAAQ,MAAO,MAAM,CACjD,CAEA,mBAAoB,CAGlB,WAAW,IAAM,CACf,AAAI,EAAQ,MAAQ,CAAC,EAAa,IAAI,EAEpC,EAAS,QAAQ,IAAI,EAGrB,KAAK,KAAK,CAEd,CAAC,CACH,CAEA,MAAO,CAEL,KAAK,YAAc,KAAK,UACxB,KAAK,SAAS,CAChB,CAEA,UAAW,CACT,GAAM,GAAO,KAAK,aAAa,MAAM,EAC/B,EAAU,KAAK,QACrB,AAAI,CAAC,GAAQ,CAAC,GAKd,MAAK,UAAY,GAEb,KAAK,aAAa,MAAM,GAC1B,KAAK,QAAQ,KAAK,aAAa,MAAM,CAAC,EAExC,EAAY,KAAM,EAAM,EAAS,KAAK,IAAI,EAC5C,CAEA,QAAQ,EAAM,CACZ,KAAK,MAAM,YAAY,SAAU,GAAG,KAAQ,EACxC,KAAK,QAAQ,aACf,KAAK,MAAM,YAAY,SAAU,CAAI,CAEzC,CAEA,yBAAyB,EAAM,EAAQ,EAAQ,CAE7C,AAAI,MAAO,MAAK,aAAgB,UAGhC,GAAI,QAAQ,kBAAqB,QAAa,GAAQ,EACtD,AAAI,IAAS,OACX,KAAK,QAAQ,CAAM,EACV,GACT,GAAI,mBAAmB,EACvB,KAAK,SAAS,GAElB,CACF,EAEA,eAAe,OAAO,MAAO,CAAQ", + "sourcesContent": ["const JSDELIVR = \"https://cdn.jsdelivr.net/\";\r\nconst CACHE = {};\r\n\r\n/**\r\n * @typedef IconSet\r\n * @property {String} alias Short two letters alias\r\n * @property {Function} svgPath The svg path\r\n * @property {Boolean} [fixFill] Does this set needs fixing fill:currentColor ?\r\n * @property {String} [useStroke] Add stroke to svg\r\n * @property {String} [defaultStroke] Default stroke to use (if supports stroke)\r\n * @property {String} [defaultType] Default type to use (when there are multiple types)\r\n * @property {Object.} [prefixes] Types to prefixes\r\n * @property {Function} [fontClass] Font class\r\n * @property {Boolean} [opticalFont] Is an optical font?\r\n * @property {String} [name] Full name (injected automatically)\r\n */\r\n\r\n/**\r\n * @typedef Options\r\n * @property {Boolean} debug Should we output messages to console\r\n * @property {Boolean} lazy Load icons lazily\r\n * @property {Object} replaceName Transparently replace icons with other values\r\n * @property {Array} fonts Icon sets using font icons rather than svg\r\n * @property {String} defaultSet Default icon set\r\n * @property {Object.} sets Available iconsets\r\n */\r\nconst options = {\r\n debug: false,\r\n lazy: true,\r\n replaceName: {},\r\n fonts: [],\r\n defaultSet: \"tabler\",\r\n defaultStroke: 2,\r\n sets: {\r\n bootstrap: {\r\n alias: \"bs\",\r\n svgPath: () => JSDELIVR + \"npm/bootstrap-icons@1/icons/{icon}.svg\",\r\n },\r\n boxicons: {\r\n alias: \"bx\",\r\n // types: [\"solid\", \"regular\", \"logos\"],\r\n defaultType: \"solid\",\r\n svgPath: () => JSDELIVR + \"npm/boxicons@2/svg/{type}/{prefix}-{icon}.svg\",\r\n fixFill: true,\r\n fontClass: () => \"bx {prefix}-{icon}\",\r\n prefixes: {\r\n solid: \"bxs\",\r\n regular: \"bx\",\r\n logos: \"bxl\",\r\n },\r\n },\r\n bytesize: {\r\n alias: \"by\",\r\n svgPath: () => JSDELIVR + \"npm/bytesize-icons@1/dist/icons/{icon}.svg\",\r\n useStroke: true,\r\n },\r\n cssgg: {\r\n alias: \"gg\",\r\n svgPath: () => JSDELIVR + \"npm/css.gg@2/icons/svg/{icon}.svg\",\r\n },\r\n emojicc: {\r\n alias: \"em\",\r\n svgPath: () => JSDELIVR + \"npm/emoji-cc@1/svg/{icon}.svg\",\r\n },\r\n eos: {\r\n alias: \"eo\",\r\n // types: [\"solid\", \"outlined\", \"animated\"],\r\n defaultType: \"solid\",\r\n svgPath: () => JSDELIVR + \"gh/lekoala/eos-icons-mirror/{type}/{icon}.svg\",\r\n fixFill: true,\r\n },\r\n feather: {\r\n alias: \"ft\",\r\n svgPath: () => JSDELIVR + \"npm/feather-icons@4/dist/icons/{icon}.svg\",\r\n },\r\n flags: {\r\n alias: \"fl\",\r\n // types: [\"4x3\", \"1x1\"],\r\n defaultType: \"4x3\",\r\n svgPath: () => JSDELIVR + \"npm/flag-svg-collection@1/flags/{type}/{icon}.svg\",\r\n },\r\n fontawesome: {\r\n alias: \"fa\",\r\n // types: [\"solid\", \"regular\", \"brands\", \"light\", \"duotone\"],\r\n defaultType: \"solid\",\r\n svgPath: () => JSDELIVR + \"npm/@fortawesome/fontawesome-free@5/svgs/{type}/{icon}.svg\",\r\n fixFill: true,\r\n fontClass: () => \"{prefix} fa-{icon}\",\r\n prefixes: {\r\n solid: \"fas\",\r\n regular: \"far\",\r\n light: \"fal\",\r\n duotone: \"fad\",\r\n brands: \"fab\",\r\n },\r\n },\r\n iconoir: {\r\n alias: \"in\",\r\n svgPath: () => JSDELIVR + \"gh/lucaburgio/iconoir/icons/{icon}.svg\",\r\n fontClass: () => \"iconoir-{icon}\",\r\n useStroke: true,\r\n },\r\n iconpark: {\r\n alias: \"ip\",\r\n types: [], // see full list here https://github.com/bytedance/IconPark/tree/master/source\r\n svgPath: () => JSDELIVR + \"gh/bytedance/IconPark/source/{type}/{icon}.svg\",\r\n useStroke: true,\r\n },\r\n lucide: {\r\n alias: \"lu\",\r\n svgPath: () => JSDELIVR + \"npm/lucide-static/icons/{icon}.svg\",\r\n },\r\n material: {\r\n alias: \"mi\",\r\n // types: [\"filled\", \"outlined\", \"round\", \"sharp\", \"two-tone\"],\r\n defaultType: \"filled\",\r\n svgPath: () => JSDELIVR + \"npm/@material-design-icons/svg/{type}/{icon}.svg\",\r\n fontClass: (type) => {\r\n if (type === \"filled\") {\r\n return \"material-icons\";\r\n }\r\n return \"material-icons-{type}\";\r\n },\r\n },\r\n phosphor: {\r\n alias: \"ph\",\r\n // types: [\"regular\", \"bold\", \"duotone\", \"fill\", \"light\", \"thin\"],\r\n defaultType: \"regular\",\r\n svgPath: (type) => {\r\n if (type === \"regular\") {\r\n return JSDELIVR + \"npm/@phosphor-icons/core@2/assets/{type}/{icon}.svg\";\r\n }\r\n return JSDELIVR + \"npm/@phosphor-icons/core@2/assets/{type}/{icon}-{type}.svg\";\r\n },\r\n fontClass: (type) => {\r\n if (type === \"regular\") {\r\n return \"ph ph-{icon}\";\r\n }\r\n return \"ph-{type} ph-{icon}\";\r\n },\r\n },\r\n supertiny: {\r\n alias: \"st\",\r\n svgPath: () => JSDELIVR + \"npm/super-tiny-icons/images/svg/{icon}.svg\",\r\n },\r\n symbols: {\r\n alias: \"ms\",\r\n // types: [\"outlined\", \"rounded\", \"sharp\"],\r\n defaultType: \"outlined\",\r\n svgPath: () => JSDELIVR + \"npm/@material-symbols/svg-400@0.5/{type}/{icon}.svg\",\r\n fixFill: true,\r\n fontClass: () => \"material-symbols-{type}\",\r\n opticalFont: true,\r\n },\r\n tabler: {\r\n alias: \"tb\", // maybe we should rename this to ti at some point\r\n svgPath: () => JSDELIVR + \"npm/@tabler/icons@2/icons/{icon}.svg\",\r\n useStroke: true,\r\n fontClass: () => \"ti ti-{icon}\",\r\n },\r\n },\r\n};\r\n\r\n/**\r\n * @var {IntersectionObserver}\r\n */\r\nconst observer = new window.IntersectionObserver((entries, observerRef) => {\r\n entries.forEach(async (entry) => {\r\n if (entry.isIntersecting) {\r\n observerRef.unobserve(entry.target);\r\n entry.target.init();\r\n }\r\n });\r\n});\r\n\r\n/**\r\n * @param {string} value\r\n * @param {string} iconName\r\n * @param {IconSet} iconSet\r\n * @param {string} iconType\r\n * @return {string}\r\n */\r\nfunction replacePlaceholders(value, iconName, iconSet, iconType) {\r\n value = value.replace(\"{icon}\", iconName);\r\n if (iconType) {\r\n value = value.replaceAll(\"{type}\", iconType);\r\n } else {\r\n // Maybe we want to remove the type like in material icons\r\n value = value.replace(\"-{type}\", \"\");\r\n }\r\n if (iconSet.prefixes && iconSet.prefixes[iconType]) {\r\n value = value.replace(\"{prefix}\", iconSet.prefixes[iconType]);\r\n }\r\n return value;\r\n}\r\n\r\nfunction log(message) {\r\n if (options.debug) {\r\n console.log(`[l-i] ${message}`);\r\n }\r\n}\r\n\r\n/**\r\n * @param {string} iconName\r\n * @param {IconSet} iconSet\r\n * @param {string} iconType\r\n * @return {Promise}\r\n */\r\nfunction getIconSvg(iconName, iconSet, iconType) {\r\n let iconUrl = iconSet.svgPath(iconType);\r\n let cacheKey = `${iconSet.name}-${iconName}-${iconType || \"base\"}`;\r\n if (!iconUrl) {\r\n return new Promise(() => {\r\n console.error(`Icon set ${iconSet} does not exists`);\r\n });\r\n }\r\n\r\n iconUrl = replacePlaceholders(iconUrl, iconName, iconSet, iconType);\r\n\r\n // If we have it in cache\r\n if (iconUrl && CACHE[cacheKey]) {\r\n log(`Fetching ${cacheKey} from cache`);\r\n return CACHE[cacheKey];\r\n }\r\n\r\n // Or resolve\r\n log(`Fetching ${cacheKey} from url ${iconUrl}`);\r\n CACHE[cacheKey] = fetch(iconUrl).then(function (response) {\r\n if (response.ok) {\r\n return response.text();\r\n }\r\n throw Error(response.status);\r\n });\r\n return CACHE[cacheKey];\r\n}\r\n\r\n/**\r\n * @param {LastIcon} inst\r\n * @param {string} iconName\r\n * @param {IconSet} iconSet\r\n * @param {string} iconType\r\n */\r\nfunction refreshIcon(inst, iconName, iconSet, iconType) {\r\n // Replace name\r\n if (options.replaceName[iconName]) {\r\n iconName = options.replaceName[iconName];\r\n }\r\n // Set default type if any\r\n if (!iconType && iconSet.defaultType) {\r\n iconType = iconSet.defaultType;\r\n }\r\n\r\n // Use font\r\n if (options.fonts.includes(iconSet.name)) {\r\n log(`Using font for ${iconName}`);\r\n let iconClass = iconSet.fontClass(iconType);\r\n let nameAsClass = iconClass.includes(\"{icon}\");\r\n iconClass = replacePlaceholders(iconClass, iconName, iconSet, iconType);\r\n if (nameAsClass) {\r\n inst.innerHTML = ``;\r\n } else {\r\n inst.innerHTML = `${iconName}`;\r\n }\r\n if (inst.stroke && iconSet.opticalFont) {\r\n inst.style.setProperty(\"--weight\", inst.stroke * 100);\r\n }\r\n return; // Return early\r\n }\r\n\r\n getIconSvg(iconName, iconSet, iconType)\r\n .then((iconData) => {\r\n // Strip class attribute as it may be affected by css\r\n if (iconData.includes(\"class=\")) {\r\n iconData = iconData.replace(/ class=\"([a-z- ]*)\"/g, \"\");\r\n }\r\n // Add and/or fix stroke\r\n if (inst.stroke || iconSet.useStroke) {\r\n iconData = iconData.replace(/stroke-width=\"([0-9\\.]*)\"/g, `stroke-width=\"${inst.stroke}\"`);\r\n }\r\n // Fix fill to currentColor\r\n if (iconSet.fixFill) {\r\n iconData = iconData.replace(/(/, '$1 fill=\"currentColor\">');\r\n }\r\n // If we have some html, pass it along (useful for svg anim)\r\n if (inst.defaultHTML) {\r\n iconData = iconData.replace(\"\", `${inst.defaultHTML}`);\r\n }\r\n inst.innerHTML = iconData;\r\n })\r\n .catch((error) => {\r\n inst.innerHTML = \"\u26A0\uFE0F\";\r\n console.error(`Failed to load icon ${iconName} (error ${error})`);\r\n });\r\n}\r\n\r\n/**\r\n * @param {HTMLElement} element\r\n * @returns {Boolean}\r\n */\r\nfunction isInViewport(element) {\r\n const rect = element.getBoundingClientRect();\r\n return (\r\n rect.top >= 0 &&\r\n rect.left >= 0 &&\r\n rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&\r\n rect.right <= (window.innerWidth || document.documentElement.clientWidth)\r\n );\r\n}\r\n\r\n/**\r\n * Performs a deep merge of objects and returns new object. Does not modify\r\n * objects (immutable) and merges arrays via concatenation.\r\n *\r\n * @param {...object} objects - Objects to merge\r\n * @returns {object} New object with merged key/values\r\n */\r\nfunction mergeDeep(...objects) {\r\n const isObject = (obj) => obj && typeof obj === \"object\";\r\n\r\n return objects.reduce((prev, obj) => {\r\n Object.keys(obj).forEach((key) => {\r\n const pVal = prev[key];\r\n const oVal = obj[key];\r\n\r\n if (Array.isArray(pVal) && Array.isArray(oVal)) {\r\n prev[key] = pVal.concat(...oVal);\r\n } else if (isObject(pVal) && isObject(oVal)) {\r\n prev[key] = mergeDeep(pVal, oVal);\r\n } else {\r\n prev[key] = oVal;\r\n }\r\n });\r\n\r\n return prev;\r\n }, {});\r\n}\r\n\r\nlet aliases = {};\r\nfunction processIconSets() {\r\n for (const [key, set] of Object.entries(options.sets)) {\r\n // List aliases for easy retrieval\r\n aliases[set.alias] = key;\r\n // Include full name in iconset definition\r\n set.name = key;\r\n }\r\n}\r\nprocessIconSets();\r\n\r\nclass LastIcon extends HTMLElement {\r\n /**\r\n * @param {object} opts\r\n * @returns {Options} The updated option object\r\n */\r\n static configure(opts = {}) {\r\n for (const k in opts) {\r\n if (typeof options[k] === \"undefined\") {\r\n console.error(`Invalid option key ${k}`);\r\n return;\r\n }\r\n if (Array.isArray(opts[k])) {\r\n options[k] = options[k].concat(opts[k]);\r\n } else if (typeof opts[k] === \"object\") {\r\n options[k] = mergeDeep(options[k], opts[k]);\r\n } else {\r\n options[k] = opts[k];\r\n }\r\n }\r\n processIconSets();\r\n // Log after we had the opportunity to change debug flag\r\n log(\"configuring options\");\r\n return options;\r\n }\r\n\r\n /**\r\n * @return {String|null}\r\n */\r\n get type() {\r\n return this.getAttribute(\"type\") || null;\r\n }\r\n\r\n /**\r\n * @return {String}\r\n */\r\n get set() {\r\n let v = this.getAttribute(\"set\") || options.defaultSet;\r\n return aliases[v] || v;\r\n }\r\n\r\n /**\r\n * @return {IconSet|null}\r\n */\r\n get iconSet() {\r\n return options.sets[this.set] || null;\r\n }\r\n\r\n /**\r\n * @return {Number}\r\n */\r\n get stroke() {\r\n return this.getAttribute(\"stroke\") || options.defaultStroke;\r\n }\r\n\r\n static get observedAttributes() {\r\n return [\"name\", \"stroke\", \"size\", \"set\", \"type\"];\r\n }\r\n\r\n connectedCallback() {\r\n // innerHTML is not available because not parsed yet\r\n // setTimeout also allows whenDefined to kick in before init\r\n setTimeout(() => {\r\n if (options.lazy && !isInViewport(this)) {\r\n // observer will call init when element is visible\r\n observer.observe(this);\r\n } else {\r\n // init directly\r\n this.init();\r\n }\r\n });\r\n }\r\n\r\n init() {\r\n // Store default content as we will inject it back later\r\n this.defaultHTML = this.innerHTML;\r\n this.loadIcon();\r\n }\r\n\r\n loadIcon() {\r\n const name = this.getAttribute(\"name\");\r\n const iconSet = this.iconSet;\r\n if (!name || !iconSet) {\r\n return;\r\n }\r\n\r\n // Clear icon\r\n this.innerHTML = \"\";\r\n // Useful for customizing size in css\r\n if (this.hasAttribute(\"size\")) {\r\n this.setSize(this.getAttribute(\"size\"));\r\n }\r\n refreshIcon(this, name, iconSet, this.type);\r\n }\r\n\r\n setSize(size) {\r\n this.style.setProperty(\"--size\", `${size}px`);\r\n if (this.iconSet.opticalFont) {\r\n this.style.setProperty(\"--opsz\", size);\r\n }\r\n }\r\n\r\n attributeChangedCallback(attr, oldVal, newVal) {\r\n // Wait until properly loaded for the first time\r\n if (typeof this.defaultHTML !== \"string\") {\r\n return;\r\n }\r\n log(`Attr ${attr} changed from ${oldVal} to ${newVal}`);\r\n if (attr === \"size\") {\r\n this.setSize(newVal);\r\n } else if (newVal) {\r\n log(\"attribute changed\");\r\n this.loadIcon();\r\n }\r\n }\r\n}\r\n\r\ncustomElements.define(\"l-i\", LastIcon);\r\n"], + "mappings": "MAAA,GAAM,GAAW,4BACX,EAAQ,CAAC,EAyBT,EAAU,CACd,MAAO,GACP,KAAM,GACN,YAAa,CAAC,EACd,MAAO,CAAC,EACR,WAAY,SACZ,cAAe,EACf,KAAM,CACJ,UAAW,CACT,MAAO,KACP,QAAS,IAAM,EAAW,wCAC5B,EACA,SAAU,CACR,MAAO,KAEP,YAAa,QACb,QAAS,IAAM,EAAW,gDAC1B,QAAS,GACT,UAAW,IAAM,qBACjB,SAAU,CACR,MAAO,MACP,QAAS,KACT,MAAO,KACT,CACF,EACA,SAAU,CACR,MAAO,KACP,QAAS,IAAM,EAAW,6CAC1B,UAAW,EACb,EACA,MAAO,CACL,MAAO,KACP,QAAS,IAAM,EAAW,mCAC5B,EACA,QAAS,CACP,MAAO,KACP,QAAS,IAAM,EAAW,+BAC5B,EACA,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