-
Notifications
You must be signed in to change notification settings - Fork 0
/
icons.min.js
2 lines (2 loc) · 3.71 KB
/
icons.min.js
1
2
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).icons=t()}(this,(function(){"use strict";const e=e=>Object.prototype.toString.apply(e),t=t=>Array.isArray?Array.isArray(t):"[object Array]"===e(t),n=e=>"string"==typeof e,o=[],i=e=>{if(!e)return!1;t(e)&&e.length>0?e.forEach((e=>{-1===o.indexOf(e)&&n(e)&&o.push(e)})):n(e)&&o.push(e)},s=(e,t="icon")=>{const n=/id="(.*?)"/,i=/^(\w+)-/;return o.find((o=>{const s=n.exec(o)[1];return i.exec(s)[1]===t&&s===("icon"===t?`${t}-${e}`:`${t}-icon-${e}`)}))},r=(e,t="icon")=>n(e)?s(e,t):[...o],c=t=>{return("[object Object]"===e(t)||"object"==typeof t||("function"==typeof(n=t)||"[object Function]"===e(n)))&&null!==t;var n},l=(e,t)=>{if(!e||!c(t))return!1;Object.keys(t).forEach((n=>{const o=t[n];((e,t)=>{const n=Object.prototype.hasOwnProperty;return e&&n.call(e,t)})(t,n)&&((e,t,n)=>{let o=e.tagName.toLowerCase();switch(t){case"style":e.style.cssText=n;break;case"value":"input"===o||"textarea"===o?e.value=n:e.setAttribute(t,n);break;case"className":e.className=n;break;case"innerHTML":e.innerHTML=n;break;case"innerText":e.innerText=n;break;default:e.setAttribute(t,n)}})(e,n,o)}))},a=(e,o={})=>{const i="ijs-icon",s=o.size||0,r=t(s),c=o.color||"",a=o.iconSet||"",u=r?s[0]:s,d=r?s[1]:s,h=s?`width:${u}px;height:${d}px;`:"",m=c?h+`color:${c}`:h,y=o.attrs||{},p=document.createElement("i");let f,g="",b="";return n(e)?((e=>{const t=new RegExp("^\\s*(?:<\\?xml[^>]*>\\s*)?(?:<\\!doctype svg[^>]*\\s*(?:\\[?(?:\\s*<![^>]*>\\s*)*\\]?)*[^>]*>\\s*)?<svg[^>]*>[^]*<\\/svg>\\s*$\\s*$","i");return n(e)&&t.test(e)})(e)?b=e:(g=a&&"icon"!==a?`xlink:href="#${a}-icon-${e}"`:`xlink:href="#icon-${e}"`,b=`<svg><use ${g}></use></svg>`),p.innerHTML=b,y.className?y.className=`${i} ${y.className}`:y.className=`${i}`,l(p,y),f=p.querySelector("svg"),l(f,{"aria-hidden":!0,xmlns:"http://www.w3.org/2000/svg",class:"ijs-icon__svg",width:200,height:200,style:m}),p):null},u=(e,t,o)=>{let i;var s;if(c(s=e)&&s.nodeName&&s.tagName&&1===s.nodeType?i=e:n(e)&&(i=document.querySelector(e)||document.getElementById(e)),!i||!t)return!1;i.appendChild(a(t,o))};return{paint(e=[]){return((e="")=>{const t=document.body;let n=document.querySelector("#ijs-icons"),o=[];if(i(e),o=r(),o.length<1)return!1;n?n.innerHTML=o.join(""):(n=document.createElement("div"),n.innerHTML=`<svg id="ijs-icons" aria-hidden="true" style="position:absolute;display:none;width:0;height:0;overflow:hidden;">${o.join("")}</svg>`,t.insertBefore(n.firstChild,t.firstChild))})(e),this},createElement:(e,t)=>a(e,t),icon:(e,t)=>((e,t={})=>a(e,t))(e,t),appendTo(e,t,n){return u(e,t,n),this},add(e){return i(e),this},remove(e,t="icon"){return((e,t="icon")=>{const i=document.querySelector("#ijs-icons"),r=s(e,t);let c,l,a=-1;if(!n(e))return!1;a=o.indexOf(r),a>-1&&o.splice(a,1),i&&(l=`#${"icon"===t?"icon":t+"-icon"}-${e}`,c=i.querySelector(l),i.removeChild(c))})(e,t),this},clear(){return(()=>{const e=document.querySelector("#ijs-icons");e&&e.parentNode.removeChild(e),o.length=0})(),this},getSymbol:(e,t="icon")=>r(e,t),getSymbolName:(e,t=!1)=>((e,t=!1)=>{const o=t?/id="(.*?)"/:/id="icon-(.*?)"/;return n(e)?e.match(o)[1]:""})(e,t),getSymbolPath:(e,t="icon")=>((e,t="icon")=>{const o=/<symbol(([\s\S])*?)>(.*?)<\/symbol>/,i=s(e,t);let r=[],c="";return n(e)?(c=i||(o.test(e)?e:""),c&&(r=c.match(o)),c?r[3]:""):""})(e,t),getSymbolSize:(e,t="icon")=>((e,t="icon")=>{const o=s(e,t);let i,r=[];return n(e)?(i=o||(/<symbol(([\s\S])*?)>(.*?)<\/symbol>/.test(e)?e:""),i?(r=i.match(/viewBox="0 0 (.*?)"/)[1].split(" "),{width:parseInt(r[0],10),height:parseInt(r[1],10)}):null):null})(e,t),symbols:(e,t="icon")=>r(e,t),count:()=>o.length}}));
//# sourceMappingURL=icons.min.js.map