ranui
Version:
A framework-agnostic Web Components UI library built on native custom elements, with TypeScript types, light/dark theming, SSR and PWA support.
2 lines (1 loc) • 6.34 kB
JavaScript
const v=require("./chunk-Y2CYZVJY-DPaYLFFP.cjs"),w=require("./src-C9EhKhbk.cjs"),k=require("./chunk-WYO6CB5R-u4mJNOcO.cjs");var A=Object.freeze({left:0,top:0,width:16,height:16}),x=Object.freeze({rotate:0,vFlip:!1,hFlip:!1}),_=Object.freeze({...A,...x}),C=Object.freeze({..._,body:"",hidden:!1}),V=Object.freeze({width:null,height:null}),G=Object.freeze({...V,...x}),q=(t,n,i,r="")=>{const e=t.split(":");if(t.slice(0,1)==="@"){if(e.length<2||e.length>3)return null;r=e.shift().slice(1)}if(e.length>3||!e.length)return null;if(e.length>1){const l=e.pop(),f=e.pop(),u={provider:e.length>0?e[0]:r,prefix:f,name:l};return n&&!m(u)?null:u}const o=e[0],s=o.split("-");if(s.length>1){const l={provider:r,prefix:s.shift(),name:s.join("-")};return n&&!m(l)?null:l}if(i&&r===""){const l={provider:r,prefix:"",name:o};return n&&!m(l,i)?null:l}return null},m=(t,n)=>t?!!((n&&t.prefix===""||t.prefix)&&t.name):!1;function R(t,n){const i={};!t.hFlip!=!n.hFlip&&(i.hFlip=!0),!t.vFlip!=!n.vFlip&&(i.vFlip=!0);const r=((t.rotate||0)+(n.rotate||0))%4;return r&&(i.rotate=r),i}function D(t,n){const i=R(t,n);for(const r in C)r in x?r in t&&!(r in i)&&(i[r]=x[r]):r in n?i[r]=n[r]:r in t&&(i[r]=t[r]);return i}function z(t,n){const i=t.icons,r=t.aliases||Object.create(null),e=Object.create(null);function o(s){if(i[s])return e[s]=[];if(!(s in e)){e[s]=null;const l=r[s]&&r[s].parent,f=l&&o(l);f&&(e[s]=[l].concat(f))}return e[s]}return(n||Object.keys(i).concat(Object.keys(r))).forEach(o),e}function j(t,n,i){const r=t.icons,e=t.aliases||Object.create(null);let o={};function s(l){o=D(r[l]||e[l],o)}return s(n),i.forEach(s),D(t,o)}function H(t,n){if(t.icons[n])return j(t,n,[]);const i=z(t,[n])[n];return i?j(t,n,i):null}var Y=/(-?[0-9.]*[0-9]+[0-9.]*)/g,B=/^-?[0-9.]*[0-9]+[0-9.]*$/g;function E(t,n,i){if(n===1)return t;if(i=i||100,typeof t=="number")return Math.ceil(t*n*i)/i;if(typeof t!="string")return t;const r=t.split(Y);if(r===null||!r.length)return t;const e=[];let o=r.shift(),s=B.test(o);for(;;){if(s){const l=parseFloat(o);isNaN(l)?e.push(o):e.push(Math.ceil(l*n*i)/i)}else e.push(o);if(o=r.shift(),o===void 0)return e.join("");s=!s}}function L(t,n="defs"){let i="";const r=t.indexOf("<"+n);for(;r>=0;){const e=t.indexOf(">",r),o=t.indexOf("</"+n);if(e===-1||o===-1)break;const s=t.indexOf(">",o);if(s===-1)break;i+=t.slice(e+1,o).trim(),t=t.slice(0,r).trim()+t.slice(s+1)}return{defs:i,content:t}}function W(t,n){return t?"<defs>"+t+"</defs>"+n:n}function J(t,n,i){const r=L(t);return W(r.defs,n+r.content+i)}var K=t=>t==="unset"||t==="undefined"||t==="none";function U(t,n){const i={..._,...t},r={...G,...n},e={left:i.left,top:i.top,width:i.width,height:i.height};let o=i.body;[i,r].forEach(g=>{const c=[],T=g.hFlip,O=g.vFlip;let h=g.rotate;T?O?h+=2:(c.push("translate("+(e.width+e.left).toString()+" "+(0-e.top).toString()+")"),c.push("scale(-1 1)"),e.top=e.left=0):O&&(c.push("translate("+(0-e.left).toString()+" "+(e.height+e.top).toString()+")"),c.push("scale(1 -1)"),e.top=e.left=0);let a;switch(h<0&&(h-=Math.floor(h/4)*4),h=h%4,h){case 1:a=e.height/2+e.top,c.unshift("rotate(90 "+a.toString()+" "+a.toString()+")");break;case 2:c.unshift("rotate(180 "+(e.width/2+e.left).toString()+" "+(e.height/2+e.top).toString()+")");break;case 3:a=e.width/2+e.left,c.unshift("rotate(-90 "+a.toString()+" "+a.toString()+")");break}h%2===1&&(e.left!==e.top&&(a=e.left,e.left=e.top,e.top=a),e.width!==e.height&&(a=e.width,e.width=e.height,e.height=a)),c.length&&(o=J(o,'<g transform="'+c.join(" ")+'">',"</g>"))});const s=r.width,l=r.height,f=e.width,u=e.height;let p,d;s===null?(d=l===null?"1em":l==="auto"?u:l,p=E(d,f/u)):(p=s==="auto"?f:s,d=l===null?E(p,u/f):l==="auto"?u:l);const I={},S=(g,c)=>{K(c)||(I[g]=c.toString())};S("width",p),S("height",d);const y=[e.left,e.top,f,u];return I.viewBox=y.join(" "),{attributes:I,viewBox:y,body:o}}var Z=/\sid="(\S+)"/g,F=new Map;function N(t){t=t.replace(/[0-9]+$/,"")||"a";const n=F.get(t)||0;return F.set(t,n+1),n?`${t}${n}`:t}function Q(t){const n=[];let i;for(;i=Z.exec(t);)n.push(i[1]);if(!n.length)return t;const r="suffix"+(Math.random()*16777216|Date.now()).toString(16);return n.forEach(e=>{const o=N(e),s=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");t=t.replace(new RegExp('([#;"])('+s+')([")]|\\.[a-z])',"g"),"$1"+o+r+"$3")}),t=t.replace(new RegExp(r,"g"),""),t}function X(t,n){let i=t.indexOf("xlink:")===-1?"":' xmlns:xlink="http://www.w3.org/1999/xlink"';for(const r in n)i+=" "+r+'="'+n[r]+'"';return'<svg xmlns="http://www.w3.org/2000/svg"'+i+">"+t+"</svg>"}var $={body:'<g><rect width="80" height="80" style="fill: #087ebf; stroke-width: 0px;"/><text transform="translate(21.16 64.67)" style="fill: #fff; font-family: ArialMT, Arial; font-size: 67.75px;"><tspan x="0" y="0">?</tspan></text></g>',height:80,width:80},b=new Map,M=new Map,tt=v.__name(t=>{for(const n of t){if(!n.name)throw new Error('Invalid icon loader. Must have a "name" property with non-empty string value.');if(w.log.debug("Registering icon pack:",n.name),"loader"in n)M.set(n.name,n.loader);else if("icons"in n)b.set(n.name,n.icons);else throw w.log.error("Invalid icon loader:",n),new Error('Invalid icon loader. Must have either "icons" or "loader" property.')}},"registerIconPacks"),P=v.__name(async(t,n)=>{const i=q(t,!0,n!==void 0);if(!i)throw new Error(`Invalid icon name: ${t}`);const r=i.prefix||n;if(!r)throw new Error(`Icon name must contain a prefix: ${t}`);let e=b.get(r);if(!e){const s=M.get(r);if(!s)throw new Error(`Icon set not found: ${i.prefix}`);try{e={...await s(),prefix:r},b.set(r,e)}catch(l){throw w.log.error(l),new Error(`Failed to load icon set: ${i.prefix}`)}}const o=H(e,i.name);if(!o)throw new Error(`Icon not found: ${t}`);return o},"getRegisteredIconData"),et=v.__name(async t=>{try{return await P(t),!0}catch{return!1}},"isIconAvailable"),nt=v.__name(async(t,n,i)=>{let r;try{r=await P(t,n?.fallbackPrefix)}catch(o){w.log.error(o),r=$}const e=U(r,n);return k.sanitizeText(X(Q(e.body),{...e.attributes,...i}),k.getConfig())},"getIconSVG");Object.defineProperty(exports,"getIconSVG",{enumerable:!0,get:function(){return nt}});Object.defineProperty(exports,"isIconAvailable",{enumerable:!0,get:function(){return et}});Object.defineProperty(exports,"registerIconPacks",{enumerable:!0,get:function(){return tt}});Object.defineProperty(exports,"unknownIcon",{enumerable:!0,get:function(){return $}});