UNPKG

@hopeio/utils

Version:
2 lines (1 loc) 7.83 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("vue"),j=require("@iconify/vue"),A=Object.freeze({left:0,top:0,width:16,height:16}),E=Object.freeze({rotate:0,vFlip:!1,hFlip:!1}),O=Object.freeze({...A,...E});Object.freeze({...O,body:"",hidden:!1});({...A});const P=Object.freeze({width:null,height:null}),N=Object.freeze({...P,...E});function V(t,o){const n={...t};for(const i in o){const e=o[i],r=typeof e;i in P?(e===null||e&&(r==="string"||r==="number"))&&(n[i]=e):r===typeof n[i]&&(n[i]=i==="rotate"?e%4:e)}return n}const G=/[\s,]+/;function U(t,o){o.split(G).forEach(n=>{switch(n.trim()){case"horizontal":t.hFlip=!0;break;case"vertical":t.vFlip=!0;break}})}function q(t,o=0){const n=t.replace(/^-?[0-9.]*/,"");function i(e){for(;e<0;)e+=4;return e%4}if(n===""){const e=parseInt(t);return isNaN(e)?0:i(e)}else if(n!==t){let e=0;switch(n){case"%":e=25;break;case"deg":e=90}if(e){let r=parseFloat(t.slice(0,t.length-n.length));return isNaN(r)?0:(r=r/e,r%1===0?i(r):0)}}return o}const B=/(-?[0-9.]*[0-9]+[0-9.]*)/g,W=/^-?[0-9.]*[0-9]+[0-9.]*$/g;function F(t,o,n){if(o===1)return t;if(n=n||100,typeof t=="number")return Math.ceil(t*o*n)/n;if(typeof t!="string")return t;const i=t.split(B);if(i===null||!i.length)return t;const e=[];let r=i.shift(),l=W.test(r);for(;;){if(l){const a=parseFloat(r);isNaN(a)?e.push(r):e.push(Math.ceil(a*o*n)/n)}else e.push(r);if(r=i.shift(),r===void 0)return e.join("");l=!l}}function K(t,o="defs"){let n="";const i=t.indexOf("<"+o);for(;i>=0;){const e=t.indexOf(">",i),r=t.indexOf("</"+o);if(e===-1||r===-1)break;const l=t.indexOf(">",r);if(l===-1)break;n+=t.slice(e+1,r).trim(),t=t.slice(0,i).trim()+t.slice(l+1)}return{defs:n,content:t}}function _(t,o){return t?"<defs>"+t+"</defs>"+o:o}function J(t,o,n){const i=K(t);return _(i.defs,o+i.content+n)}const Q=t=>t==="unset"||t==="undefined"||t==="none";function X(t,o){const n={...O,...t},i={...N,...o},e={left:n.left,top:n.top,width:n.width,height:n.height};let r=n.body;[n,i].forEach(f=>{const s=[],b=f.hFlip,v=f.vFlip;let d=f.rotate;b?v?d+=2:(s.push("translate("+(e.width+e.left).toString()+" "+(0-e.top).toString()+")"),s.push("scale(-1 1)"),e.top=e.left=0):v&&(s.push("translate("+(0-e.left).toString()+" "+(e.height+e.top).toString()+")"),s.push("scale(1 -1)"),e.top=e.left=0);let h;switch(d<0&&(d-=Math.floor(d/4)*4),d=d%4,d){case 1:h=e.height/2+e.top,s.unshift("rotate(90 "+h.toString()+" "+h.toString()+")");break;case 2:s.unshift("rotate(180 "+(e.width/2+e.left).toString()+" "+(e.height/2+e.top).toString()+")");break;case 3:h=e.width/2+e.left,s.unshift("rotate(-90 "+h.toString()+" "+h.toString()+")");break}d%2===1&&(e.left!==e.top&&(h=e.left,e.left=e.top,e.top=h),e.width!==e.height&&(h=e.width,e.width=e.height,e.height=h)),s.length&&(r=J(r,'<g transform="'+s.join(" ")+'">',"</g>"))});const l=i.width,a=i.height,p=e.width,u=e.height;let g,m;l===null?(m=a===null?"1em":a==="auto"?u:a,g=F(m,p/u)):(g=l==="auto"?p:l,m=a===null?F(g,u/p):a==="auto"?u:a);const y={},w=(f,s)=>{Q(s)||(y[f]=s.toString())};w("width",g),w("height",m);const I=[e.left,e.top,p,u];return y.viewBox=I.join(" "),{attributes:y,viewBox:I,body:r}}const Y=/\sid="(\S+)"/g,Z="IconifyId"+Date.now().toString(16)+(Math.random()*16777216|0).toString(16);let tt=0;function et(t,o=Z){const n=[];let i;for(;i=Y.exec(t);)n.push(i[1]);if(!n.length)return t;const e="suffix"+(Math.random()*16777216|Date.now()).toString(16);return n.forEach(r=>{const l=typeof o=="function"?o(r):o+(tt++).toString(),a=r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");t=t.replace(new RegExp('([#;"])('+a+')([")]|\\.[a-z])',"g"),"$1"+l+e+"$3")}),t=t.replace(new RegExp(e,"g"),""),t}function nt(t,o){let n=t.indexOf("xlink:")===-1?"":' xmlns:xlink="http://www.w3.org/1999/xlink"';for(const i in o)n+=" "+i+'="'+o[i]+'"';return'<svg xmlns="http://www.w3.org/2000/svg"'+n+">"+t+"</svg>"}function ot(t){return t.replace(/"/g,"'").replace(/%/g,"%25").replace(/#/g,"%23").replace(/</g,"%3C").replace(/>/g,"%3E").replace(/\s+/g," ")}function it(t){return"data:image/svg+xml,"+ot(t)}function st(t){return'url("'+it(t)+'")'}const C={...N,inline:!1},rt={xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink","aria-hidden":!0,role:"img"},ct={display:"inline-block"},S={backgroundColor:"currentColor"},R={backgroundColor:"transparent"},T={Image:"var(--svg)",Repeat:"no-repeat",Size:"100% 100%"},$={webkitMask:S,mask:S,background:R};for(const t in $){const o=$[t];for(const n in T)o[t+n]=T[n]}const k={};["horizontal","vertical"].forEach(t=>{const o=t.slice(0,1)+"Flip";k[t+"-flip"]=o,k[t.slice(0,1)+"-flip"]=o,k[t+"Flip"]=o});function D(t){return t+(t.match(/^[-0-9.]+$/)?"px":"")}const lt=(t,o)=>{const n=V(C,o),i={...rt},e=o.mode||"svg",r={},l=o.style,a=typeof l=="object"&&!(l instanceof Array)?l:{};for(let f in o){const s=o[f];if(s!==void 0)switch(f){case"icon":case"style":case"onLoad":case"mode":case"ssr":break;case"inline":case"hFlip":case"vFlip":n[f]=s===!0||s==="true"||s===1;break;case"flip":typeof s=="string"&&U(n,s);break;case"color":r.color=s;break;case"rotate":typeof s=="string"?n[f]=q(s):typeof s=="number"&&(n[f]=s);break;case"ariaHidden":case"aria-hidden":s!==!0&&s!=="true"&&delete i["aria-hidden"];break;default:{const b=k[f];b?(s===!0||s==="true"||s===1)&&(n[b]=!0):C[f]===void 0&&(i[f]=s)}}}const p=X(t,n),u=p.attributes;if(n.inline&&(r.verticalAlign="-0.125em"),e==="svg"){i.style={...r,...a},Object.assign(i,u);let f=0,s=o.id;return typeof s=="string"&&(s=s.replace(/-/g,"_")),i.innerHTML=et(p.body,s?()=>s+"ID"+f++:"iconifyVue"),c.h("svg",i)}const{body:g,width:m,height:y}=t,w=e==="mask"||(e==="bg"?!1:g.indexOf("currentColor")!==-1),I=nt(g,{...u,width:m+"",height:y+""});return i.style={...r,"--svg":st(I),width:D(u.width),height:D(u.height),...ct,...w?S:R,...a},c.h("span",i)},z=Object.create(null);function ft(t,o){z[t]=o}const M=c.defineComponent({inheritAttrs:!1,render(){const t=this.$attrs,o=t.icon,n=typeof o=="string"?z[o]:typeof o=="object"?o:null;return n===null||typeof n!="object"||typeof n.body!="string"?this.$slots.default?this.$slots.default():null:lt({...O,...n},t)}}),at=c.defineComponent({name:"IconifyIconOffline",components:{IconifyIcon:M},props:{icon:{default:null}},render(){typeof this.icon=="object"&&ft(this.icon,this.icon);const t=this.$attrs;return c.h(M,{icon:this.icon,style:t!=null&&t.style?Object.assign(t.style,{outline:"none"}):{outline:"none"},...t},{default:()=>[]})}}),ut=c.defineComponent({name:"IconifyIconOnline",components:{IconifyIcon:j.Icon},props:{icon:{type:String,default:""}},render(){const t=this.$attrs;return c.h(j.Icon,{icon:`${this.icon}`,style:t!=null&&t.style?Object.assign(t.style,{outline:"none"}):{outline:"none"},...t},{default:()=>[]})}}),ht=c.defineComponent({name:"FontIcon",props:{icon:{type:String,default:""}},render(){const t=this.$attrs;return Object.keys(t).includes("uni")||(t==null?void 0:t.iconType)==="uni"?c.h("i",{class:"iconfont",...t},this.icon):Object.keys(t).includes("svg")||(t==null?void 0:t.iconType)==="svg"?c.h("svg",{class:"icon-svg","aria-hidden":!0},{default:()=>[c.h("use",{"xlink:href":`#${this.icon}`})]}):c.h("i",{class:`iconfont ${this.icon}`,...t})}});function dt(t,o){const n=/^IF-/;if(n.test(t)){const i=t.split(n)[1],e=i.slice(0,i.indexOf(" ")==-1?i.length:i.indexOf(" ")),r=i.slice(i.indexOf(" ")+1,i.length);return c.defineComponent({name:"FontIcon",render(){return c.h(L,{icon:e,iconType:r,...o})}})}else return typeof t=="function"||typeof(t==null?void 0:t.render)=="function"?o?c.h(t,{...o}):t:typeof t=="object"?c.defineComponent({name:"OfflineIcon",render(){return c.h(x,{icon:t,...o})}}):c.defineComponent({name:"Icon",render(){const i=t&&t.includes(":")?H:x;return c.h(i,{icon:t,...o})}})}const x=at,H=ut,L=ht;exports.FontIcon=L;exports.IconifyIconOffline=x;exports.IconifyIconOnline=H;exports.useRenderIcon=dt;