-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSVGIcon-bundle.min.js
More file actions
1 lines (1 loc) · 2.34 KB
/
SVGIcon-bundle.min.js
File metadata and controls
1 lines (1 loc) · 2.34 KB
1
!function(t,e){var s,i=[];"function"==typeof define&&define.amd?define(i,e):"object"==typeof module&&module.exports?(s=function(t){return require(t)},module.exports=e.apply(t,i.map(s))):(s=function(e){return t[e]},t.SVGIcon=e.apply(t,i.map(s)))}("undefined"!=typeof self?self:this,function(){"use strict";Array.prototype.slice.call(arguments);const t=document.createElementNS.bind(document,"http://www.w3.org/2000/svg");class e{add(t,e="push"){void 0===this._listeners&&(this._listeners=[]),this._listeners[e](t)}serveAll(t){if(void 0===this._listeners)return!0;let e;for(;e=this._listeners.shift();)t(e);this.clear()}clear(){Reflect.deleteProperty(this,"_listeners")}}const s=(t,e)=>t.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",e),i={options:{allow:!0,fit:"contain",size_variable:"--svg-icon-size"},is_created:!1,create(){if(!this.options.allow||this.is_created)return!1;const t=document.createElement("style");t.type="text/css";const{size_variable:e,fit:s}=this.options;t.innerHTML=`svg-icon { display: block; width: var(${e}, 1em); height: var(${e}, 1em); }`+`svg-icon svg { width: 100%; height: 100%; object-fit: ${s}; }`,document.head.appendChild(t),this.is_created=!0}},n={options:{separator:"-"},list:null,has:function(t){return Boolean(this.list)&&this.list.has(t)},get:function(t){return this.list.get(t)}};class o extends HTMLElement{constructor(){super(),i.create(),this._icon=null,this._onmount_attributes=new e}renderIcon(){const e=t("svg"),s=t("use");return e.appendChild(s),this.appendChild(e),s}setIcon(t){if(!t||!this._icon)return!1;const{separator:e}=n.options,[i,...o]=t.split(e);s(this._icon,n.has(i)?n.get(i)+o.join(e):t)}connectedCallback(){this._icon=this.renderIcon(),this._onmount_attributes.serveAll(t=>this.attributeChangedCallback(...t))}disconnectedCallback(){this._onmount_attributes.clear(),this._onmount_attributes=null,this._icon=null}static get observedAttributes(){return["use"]}attributeChangedCallback(...t){const[e,s,i]=t;return s!==i&&"use"===e&&(this._icon?this.setIcon(i):this._onmount_attributes.add(t))}}return customElements.define("svg-icon",o),{setAlias:function(t,e){return n.list||(n.list=new Map),n.list.set(t,e)},removeAlias:function(t){return!!n.list&&(n.list.delete(t),n.list.size||(n.list=null),!0)},changeOptions:function({style:t,aliases:e}={}){t&&Object.assign(i.options,t),e&&Object.assign(n.options,e)},SVGIconElement:o}});