@thi.ng/meta-css
Version:
Data-driven CSS framework codegen, transpiler & bundler
48 lines (43 loc) • 39.2 kB
JavaScript
// @bun
var no={default:95,hint:90,multi:90,param:96,required:33};var $t=(t)=>t;function R(t,o=Object.create(null)){return(...n)=>{let r=n.join("-");return r in o?o[r]:o[r]=t(...n)}}var tt=R((t,o)=>t.repeat(o));var Yo=(t)=>/^[a-f0-9]+$/i.test(t);var Do=(t)=>/^[-+]?\d+$/.test(t),zo=(t)=>/^[-+]?\d*\.?\d+(e[-+]?\d+)?$/i.test(t);var U=(t,o=(n)=>n!==void 0?": "+n:"")=>class extends Error{origMessage;constructor(n){super(t(n)+o(n));this.origMessage=n!==void 0?String(n):""}};var ir=U(()=>"illegal argument(s)"),_=(t)=>{throw new ir(t)};var ro=(t)=>zo(t)?parseFloat(t):_(`not a numeric value: ${t}`),jo=(t)=>t.map(ro),mo=(t)=>Yo(t)?parseInt(t,16):_(`not a hex value: ${t}`),Jo=(t)=>t.map(mo),fo=(t)=>Do(t)?parseInt(t):_(`not an integer: ${t}`),Xo=(t)=>t.map(fo);var Wt=(t,o)=>(n)=>({coerce:t,hint:o,group:"main",...n}),Rt=(t,o)=>(n)=>({hint:Ar(o,n.delim),multi:!0,coerce:t,group:"main",...n}),Ar=(t,o)=>t+(o?`[${o}..]`:""),W=(t)=>({flag:!0,default:!1,group:"flags",...t}),Y=Wt($t,"STR"),Ut=Rt($t,"STR"),ff=Wt(ro,"NUM"),Ef=Wt(mo,"HEX"),Yt=Wt(fo,"INT"),Gf=Rt(jo,"NUM"),Nf=Rt(Jo,"HEX"),Of=Rt(Xo,"INT");var A=((t)=>{return t[t.FINE=0]="FINE",t[t.DEBUG=1]="DEBUG",t[t.INFO=2]="INFO",t[t.WARN=3]="WARN",t[t.SEVERE=4]="SEVERE",t[t.NONE=5]="NONE",t})(A||{});var Tr=0;class it{constructor(t,o=A.FINE,n){this.parent=n,this.id=t||`logger-${Tr++}`,this.level=typeof o==="string"?A[o]:o}id;level;addChild(t){return t.parent=this,t}enabled(t){return this.level<=t}fine(...t){this.log(A.FINE,t)}debug(...t){this.log(A.DEBUG,t)}info(...t){this.log(A.INFO,t)}warn(...t){this.log(A.WARN,t)}severe(...t){this.log(A.SEVERE,t)}none(){}log(t,o){this.level<=t&&this.logEntry([t,this.id,Date.now(),...o])}}var Po=(t)=>t.map((o)=>{if(typeof o==="function")o=o();if(!(typeof o==="string"||typeof o==="number"))o=JSON.stringify(o);return o}).join(" ");class Dt extends it{constructor(t,o,n,r){super(o,n,r);this.target=t}childLogger(t,o){return new Dt(this.target,t,o??this.level,this)}logEntry(t){if(t[0]<this.level)return;this.target.write(`[${A[t[0]]}] ${t[1]}: ${Po(t.slice(3))}
`),this.parent?.logEntry(t)}}var zt=R((t,o=" ")=>{let n=tt(String(o),t);return(r,m)=>{if(r==null)return n;return r=r.toString(),m=m!==void 0?m:r.length,m<t?r+n.substring(m):r}});var Eo={black:1,blue:5,cyan:7,gray:17,green:3,magenta:6,red:2,white:24,yellow:4,lightBlue:21,lightCyan:23,lightGray:8,lightGreen:19,lightMagenta:22,lightRed:18,lightYellow:20,bgBlack:32,bgBlue:160,bgCyan:224,bgGray:544,bgGreen:96,bgMagenta:192,bgRed:64,bgWhite:768,bgYellow:128,bgLightBlue:672,bgLightCyan:736,bgLightGray:256,bgLightGreen:608,bgLightMagenta:704,bgLightRed:576,bgLightYellow:640};var Fr=(t,o)=>(n)=>t.format(o,n),Go=(t)=>Object.keys(Eo).reduce((o,n)=>(o[n]=Fr(t,Eo[n]),o),{format:t});var bo="\x1B[0m";var Sr=["","1","2","1;2","4","1;4","2;4","1;2;4"],jt={format:(t,o)=>jt.start(t)+o+jt.end,start:R((t)=>{let o=[],n=t&15;return n&&o.push(29+(t>>4&1)*60+n),n=t>>5&15,n&&o.push(39+(t>>9&1)*60+n),n=t>>10,n&&o.push(Sr[n]),"\x1B["+o.join(";")+"m"}),end:bo,prefix:bo,suffix:`
`};var Zo={format:(t,o)=>String(o),prefix:"",suffix:`
`,start:()=>"",end:""};var Jt=Go(jt),Ko=Go(Zo);var T=Array.isArray;var wr=(t)=>t.toUpperCase(),Vo=(t)=>t.toLowerCase(),Xt=(t)=>t.length?t[0].toUpperCase()+t.substring(1):t,qo=(t,o="-")=>Vo(t.replace(/([a-z0-9\u00e0-\u00fd])([A-Z\u00c0-\u00dd])/g,(n,r,m)=>r+o+m));var po=(t,o="-")=>Vo(t).replace(new RegExp(`\\${o}+(\\w)`,"g"),(n,r)=>wr(r));var Qo=Object.getPrototypeOf,D=(t)=>{let o;return t!=null&&typeof t==="object"&&((o=Qo(t))===null||Qo(o)===null)};var Hr=/\x1b\[[0-9;]+m/g,ur=(t)=>t.replace(Hr,"");var Pt=(t)=>ur(t).length;var ko=(t=!1,o)=>(n)=>t||typeof n!=="string"&&typeof n!=="number"?JSON.stringify(n,null,o):String(n);function*ot(t,o=/\r?\n/g,n=!1){let r=0,m=t.length,f=~~n,G;if(typeof o==="string")G=new RegExp(o,"g");else if(!o.flags.includes("g"))G=new RegExp(o,o.flags+"g");else G=o;for(;r<m;){let E=G.exec(t);if(!E){yield t.substring(r);return}let N=E[0].length;yield t.substring(r,E.index+f*N),r=E.index+N}}class No{n=0;w=[];constructor(t,o){t!=null&&this.add(t,o)}add(t,o=t.length){return this.w.push(t),this.n+=o+~~(this.n>0),this}toString(){return this.w.join(" ")}}var yr={length:(t)=>t.length,split:(t,o)=>o},lo={length:Pt,split:(t,o)=>{let n=/\x1b\[[0-9;]+m/g,r=o,m;while(m=n.exec(t)){if(m.index>=o)break;let f=m[0].length;r+=f,o+=f}return r}},vo=(t,o,n,r)=>{let m=t[t.length-1];m&&r-m.n>n?m.add(o,n):t.push(new No(o,n))},Mr=(t,{width:o,min:n,hard:r,splitter:m},f=0,G=[])=>{let E=m.length(t),N=o-f;if(N<n&&N<E)N=o;while(r&&E>N){let O=m.split(t,N),h=t.substring(0,O);vo(G,h,N,o),t=t.substring(O),N=o,E=m.length(t)}return vo(G,t,E,o),G},Ir=(t,o,n=[])=>{if(!t.length)return n.push(new No),n;let r={width:80,min:4,hard:!1,splitter:yr,...o};for(let m of ot(t,o.delimWord||/\s/g)){let f=n[n.length-1];Mr(m,r,f&&f.n>0?f.n+1:0,n)}return n},go=(t,o)=>{let n=[];for(let r of ot(t,o.delimLine))n=n.concat(Ir(r,o));return n};var At=(t,o={})=>{o={lineWidth:80,paramWidth:32,showDefaults:!0,prefix:"",suffix:"",groups:["flags","main"],...o};let n=D(o.color)?{...no,...o.color}:o.color?no:{},r=tt(" ",o.paramWidth),m=(E)=>E.map((N)=>Wr(N,t[N],o,n,r)),f=Object.keys(t).sort(),G=o.groups?o.groups.map((E)=>[E,f.filter((N)=>t[N].group===E)]).filter((E)=>!!E[1].length):[["options",f]];return[...Oo(o.prefix,o.lineWidth),...G.map(([E,N])=>[...o.showGroupNames?[`${Xt(E)}:
`]:[],...m(N),""].join(`
`)),...Oo(o.suffix,o.lineWidth)].join(`
`)},Wr=(t,o,n,r,m)=>{let f=Rr(o,r),G=Ur(o,r,f),E=Tt(`--${qo(t)}`,r.param),N=`${G}${E}${f}`,O=o.optional===!1&&o.default===void 0,h=[];O&&h.push("required"),o.multi&&h.push("multiple");let C=Yr(h,r,O)+(o.desc||"")+Dr(o,n,r);return zt(n.paramWidth)(N,Pt(N))+Oo(C,n.lineWidth-n.paramWidth).map((L,B)=>B>0?m+L:L).join(`
`)},Rr=(t,o)=>t.hint?Tt(" "+t.hint,o.hint):"",Ur=(t,o,n)=>t.alias?`${Tt("-"+t.alias,o.param)}${n}, `:"",Yr=(t,o,n)=>t.length?Tt(`[${t.join(", ")}] `,n?o.required:o.multi):"",Dr=(t,o,n)=>o.showDefaults&&t.default!=null&&t.default!==!1?Tt(` (default: ${ko(!0)(t.defaultHint!=null?t.defaultHint:t.default)})`,n.default):"",Tt=(t,o)=>o!=null?`\x1B[${o}m${t}\x1B[0m`:t,Oo=(t,o)=>t?go(t,{width:o,splitter:lo,hard:!1}):[];var zr=U(()=>"parse error"),xo=(t,o,n)=>{n={start:2,showUsage:!0,help:["--help","-h"],...n};try{return jr(t,o,n)}catch(r){if(n.showUsage)console.log(r.message+`
`+At(t,n.usageOpts));throw new zr(r.message)}},jr=(t,o,n)=>{let r=Jr(t),m={},f,G,E=n.start;for(;E<o.length;){let N=o[E];if(!f){if(n.help.includes(N)){console.log(At(t,n.usageOpts));return}let O=Xr(t,r,m,N);if(f=O.id,G=O.spec,E=E+~~(O.state<2),O.state)break}else{if(Pr(G,m,f,N))break;f=null,E++}}return f&&_(`missing value for: --${f}`),{result:br(t,m),index:E,rest:o.slice(E),done:E>=o.length}},Jr=(t)=>Object.entries(t).reduce((o,[n,r])=>r.alias?(o[r.alias]=n,o):o,{}),Xr=(t,o,n,r)=>{if(r[0]==="-"){let m;if(r[1]==="-"){if(r==="--")return{state:1};m=po(r.substring(2))}else m=o[r.substring(1)],!m&&_(`unknown option: ${r}`);let f=t[m];if(!f&&_(m),f.flag){if(n[m]=!0,m=void 0,f.fn&&!f.fn("true"))return{state:1,spec:f}}return{state:0,id:m,spec:f}}return{state:2}},Pr=(t,o,n,r)=>{if(/^-[a-z]/i.test(r)&&_(`missing value for: --${n}`),t.multi)T(o[n])?o[n].push(r):o[n]=[r];else o[n]=r;return t.fn&&!t.fn(r)},br=(t,o)=>{let n;for(let r in t)if(n=t[r],o[r]===void 0){if(n.default!==void 0)o[r]=n.default;else if(n.optional===!1)_(`missing arg: --${r}`)}else if(n.coerce)Zr(n,o,r);return o},Zr=(t,o,n)=>{try{if(t.multi&&t.delim)o[n]=o[n].reduce((r,m)=>(r.push(...m.split(t.delim)),r),[]);o[n]=t.coerce(o[n])}catch(r){throw new Error(`arg --${n}: ${r.message}`)}};var so=async(t)=>{let o=t.argv||process.argv,n=!process.env.NO_COLOR,r={prefix:"",color:n,...t.usage};try{let m,f,G=t.start??2;if(t.single){if(m=Object.keys(t.commands)[0],!m)_("no command provided");f=t.commands[m]}else{if(m=o[G],f=t.commands[m],r.prefix+=Kr(t.commands),!f)ao(t,r);G++}let E;try{E=xo({...t.opts,...f.opts},o,{showUsage:!0,usageOpts:r,start:G})}catch(O){}if(!E)process.exit(1);if(f.inputs!==void 0&&f.inputs!==E.rest.length)process.stderr.write(`expected ${f.inputs||0} input(s)
`),ao(t,r);let N=await t.ctx({logger:new Dt(process.stderr,t.name,"INFO"),format:n?Jt:Ko,opts:E.result,inputs:E.rest},f);if(await f.fn(N),t.post)await t.post(N,f)}catch(m){process.stderr.write(m.message+`
`),process.exit(1)}},ao=(t,o)=>{process.stderr.write(At(t.opts,o)),process.exit(1)},Kr=(t)=>[`
Available commands:
`,...Object.keys(t).map((o)=>`${zt(16)(o)}: ${t[o].desc}`),`
`].join(`
`);import{existsSync as Vr,mkdirSync as qr,statSync as LE}from"fs";import{dirname as pr}from"path";var Qr=(t)=>t.length>0&&!Vr(t)?(qr(t,{recursive:!0}),!0):!1,co=(t)=>Qr(pr(t));var X=(t)=>typeof t==="function";var i=(t)=>typeof t==="string";import{readFileSync as vr}from"fs";import{writeFileSync as kr}from"fs";var tn=(t,o,n,r,m=!1)=>{if(r?.info(`${m?"[dryrun] ":""}writing file: ${t}`),m)return;co(t),kr(t,o,!n&&i(o)?"utf-8":n)};var w=(t,o,n="utf-8")=>{return o?.debug("reading file:",t),vr(t,n)},ho=(t,o,n,r=!1)=>tn(t,T(o)?o.join(`
`):o,"utf-8",n,r);var P=(t,o)=>JSON.parse(w(t,o));var Z=Symbol(),Lo=()=>{};var Ft=Object.freeze({level:A.NONE,addChild(t){return t},childLogger:()=>Ft,enabled:()=>!1,fine(){},debug(){},info(){},warn(){},severe(){},none(){},logEntry(){}});class Co extends it{set(t){this.parent=t}childLogger(t,o){return new Co(t,o??this.level,this)}logEntry(t){this.parent.logEntry(t)}}var on=new Co("root",A.FINE,Ft);import{join as Pm}from"path";var _o=(t,o)=>{if(t===o)return 0;if(t==null)return o==null?0:-1;if(o==null)return t==null?0:1;if(typeof t.compare==="function")return t.compare(o);if(typeof o.compare==="function")return-o.compare(t);return t<o?-1:t>o?1:0};var lr=U(()=>"Assertion failed"),bt=(typeof process!=="undefined"&&process.env!==void 0?!0:import.meta.env?import.meta.env.MODE!=="production"||!!import.meta.env.UMBRELLA_ASSERTS||!!import.meta.env.VITE_UMBRELLA_ASSERTS:!0)?(t,o)=>{if(typeof t==="function"&&!t()||!t)throw new lr(typeof o==="function"?o():o)}:()=>{};var Zt=(t)=>t!=null&&typeof t!=="function"&&t.length!==void 0;var nn=(t)=>{return(t==null||!t[Symbol.iterator])&&_(`value is not iterable: ${t}`),t};var rn=(t)=>Zt(t)?t:[...nn(t)];var St=(t)=>t[t.length-1];var Kt=(t,o)=>typeof t?.[o]==="function";var F=(t)=>typeof t?.[Symbol.iterator]==="function";var Vt=(t)=>t!=null&&typeof t!=="string"&&typeof t[Symbol.iterator]==="function";var dr=U(()=>"illegal arity"),nt=(t)=>{throw new dr(t)};var gr=U(()=>"illegal state"),rt=(t)=>{throw new gr(t)};var mn=["-moz-","-ms-","-o-","-webkit-"],mt={rules:"",ruleSep:",",valSep:"",decls:"",declStart:"{",declEnd:"}",indent:"",comments:!1},qt={rules:`
`,ruleSep:", ",valSep:" ",decls:`
`,declStart:` {
`,declEnd:`}
`,indent:" ",comments:!0};function Bo(...t){let[o,n,r,m,f,G,E,N,O,h]=t;switch(t.length){case 0:nt(0);case 1:return o;case 2:return(...L)=>o(n(...L));case 3:return(...L)=>o(n(r(...L)));case 4:return(...L)=>o(n(r(m(...L))));case 5:return(...L)=>o(n(r(m(f(...L)))));case 6:return(...L)=>o(n(r(m(f(G(...L))))));case 7:return(...L)=>o(n(r(m(f(G(E(...L)))))));case 8:return(...L)=>o(n(r(m(f(G(E(N(...L))))))));case 9:return(...L)=>o(n(r(m(f(G(E(N(O(...L)))))))));case 10:default:let C=(...L)=>o(n(r(m(f(G(E(N(O(h(...L))))))))));return t.length===10?C:Bo(C,...t.slice(10))}}var l=(t)=>Kt(t,"xform")?t.xform():t;function z(...t){return t=t.map(l),Bo.apply(null,t)}var K=(t,o)=>[t[0],t[1],o];class wt{value;constructor(t){this.value=t}deref(){return this.value}}var H=(t)=>t instanceof wt,fn=(t)=>t instanceof wt?t:new wt(t),j=(t)=>t instanceof wt?t.deref():t;var xr=(t)=>t.length===2?[void 0,t[1]]:t.length===3?[t[1],t[2]]:nt(t.length);function ft(...t){let o=t[0],n=o[0],r=o[1],m=o[2];t=xr(t);let f=t[0]==null?n():t[0],G=t[1];return j(r(Kt(G,"$reduce")?G.$reduce(m,f):Zt(G)?ar(m,f,G):sr(m,f,G)))}var ar=(t,o,n)=>{for(let r=0,m=n.length;r<m;r++)if(o=t(o,n[r]),H(o)){o=o.deref();break}return o},sr=(t,o,n)=>{for(let r of n)if(o=t(o,r),H(o)){o=o.deref();break}return o},Et=(t,o)=>[t,$t,o],En=(t,o)=>{let n=o.length-1;return F(o[n])?o.length>1?ft(t.apply(null,o.slice(0,n)),o[n]):ft(t(),o[0]):void 0};function Gt(t){return t?[...t]:Et(()=>[],(o,n)=>(o.push(n),o))}function*Nt(t,o){let n=l(t)(Gt()),r=n[1],m=n[2];for(let f of o){let G=m([],f);if(H(G)){yield*j(r(G.deref()));return}if(G.length)yield*G}yield*j(r([]))}function*d(t,o){let n=l(t)([Lo,Lo,(r,m)=>m])[2];for(let r of o){let m=n(Z,r);if(H(m)){if(m=j(m.deref()),m!==Z)yield m;return}if(m!==Z)yield m}}var pt=(t,o,n=d)=>{let r=o.length-1;return F(o[r])?o.length>1?n(t.apply(null,o.slice(0,r)),o[r]):n(t(),o[0]):void 0};function eo(t,o){return F(o)?Nt(eo(t),i(o)?[o]:o):(n)=>{let r=n[2],m=(f,G)=>{let E=t(G);if(E){for(let N of E)if(f=m(f,N),H(f))break;return f}return r(f,G)};return K(n,m)}}function Gn(t){return eo((o)=>Vt(o)?o:void 0,t)}function $(t,o){return F(o)?d($(t),o):(n)=>{let r=n[2];return K(n,(m,f)=>r(m,t(f)))}}function*Qt(...t){let o=t.length-1;if(o<0)return;let n=new Array(o+1).fill(0),r=t.map(rn),m=r.reduce((f,G)=>f*G.length,1);for(let f=0;f<m;f++){let G=[];for(let E=o;E>=0;E--){let N=r[E],O=n[E];if(O===N.length)n[E]=O=0,E>0&&n[E-1]++;G[E]=N[O]}n[o]++,yield G}}function*Nn(t,o=1/0){while(o-- >0)yield t}function $o(t,o){t=t||"";let n=!0;return o?[...o].join(t):Et(()=>"",(r,m)=>(r=n?r+m:r+t+m,n=!1,r))}function kt(...t){return cr(kt,ft,t)}var cr=(t,o,n)=>{let r,m;switch(n.length){case 4:m=n[3],r=n[2];break;case 3:m=n[2];break;case 2:return $((f)=>t(n[0],n[1],f));default:nt(n.length)}return o(l(n[0])(n[1]),r,m)};var tm=new Set,om=":[",On=z(Gn(),$((t)=>t[0]==="&"?t.substring(1):om.includes(t[0])?t:" "+t)),nm=(t,o)=>z(t,$((n)=>i(n)&&n.startsWith(" .")?n+o:n)),Ot=(t,o,n,r)=>{let m=n.length,f=[],G,E,N=(O,h)=>{let C=null;if(T(h))Ot(t,io(o,f),h,r);else if(F(h)&&!i(h))Ot(t,io(o,f),[...h],r);else if((E=X(h))||(C=r.fns[h]))if(!o.length){if(C)return C.apply(null,n.slice(O+1))(t,r),!0;h(t,r)}else if(E)N(O,h());else _(`quoted fn ('${h}') only allowed at head position`);else if(D(h))G=Object.assign(G||{},h);else if(h!=null)f.push(h)};for(let O=0;O<m;O++)if(N(O,n[O]))return t;return G&&t.push(rm(o,f,G,r)),t},io=(t,o)=>t.length?[...Qt(t,o)]:o,rm=(t,o,n,r)=>{let m=r.format,f=J(r),G=r.scope?nm(On,r.scope):On;return[f,kt($((E)=>kt(G,$o(),T(E)?E:[E]).trim()),$o(m.ruleSep),io(t,o)),m.declStart,Ht(n,r),f,m.declEnd].join("")},Ht=(t,o)=>{let n=o.format,r=o.autoprefix||tm,m=J(o,o.depth+1),f=[];for(let G in t)if(t.hasOwnProperty(G)){let E=t[G];if(X(E))E=E(t);if(T(E))E=E.map((N)=>T(N)?N.join(" "):N).join(n.ruleSep);if(r.has(G))for(let N of o.vendors)f.push(`${m}${N}${G}:${n.valSep}${E};`);f.push(`${m}${G}:${n.valSep}${E};`)}return f.join(n.decls)+n.decls},J=(t,o=t.depth)=>o>1?[...Nn(t.format.indent,o)].join(""):o>0?t.format.indent:"";function hn(t,...o){let n=o.length===1?o[0]:o.reduce((r,m,f)=>{return r[f/(o.length-1)*100|0]=m,r},{});return(r,m)=>{let f=J(m);m.depth++;let G=J(m);r.push(`${f}@keyframes ${t}${m.format.declStart}`);for(let E in n)if(n.hasOwnProperty(E))r.push([G,E+"%",m.format.declStart,Ht(n[E],m),G,m.format.declEnd].join(""));return m.depth--,r.push(f+m.format.declEnd),r}}var Ln=(t,o=!1)=>(n,r)=>{let m=J(r),f=J(r,r.depth+1);if(r.format.comments||o)n.push(m+"/*",t.split(`
`).map((G)=>f+G).join(`
`),m+"*/");return n};var vt=(t,o,n)=>(r,m)=>{let f=J(m);return r.push(`${f}${t} ${mm(o)}${m.format.declStart}`),m.depth++,Ot(r,[],n,m),m.depth--,r.push(f+m.format.declEnd),r},mm=(t)=>{if(i(t))return t;let o=[];for(let n in t)if(t.hasOwnProperty(n)){let r=t[n];if(r===!0)r=Cn.has(n)?n:`(${n})`;else if(r===!1)r=`(not ${Cn.has(n)?n:`(${n})`})`;else if(r==="only")r+=" "+n;else r=`(${n}:${r})`;o.push(r)}return o.join(" and ")},Cn=new Set(["all","print","screen"]);var g=(t,o)=>{return o={format:mt,vendors:mn,fns:{},depth:0,...o},T(o.autoprefix)&&(o.autoprefix=new Set(o.autoprefix)),D(t)?Ht(t,o):X(t)?t([],o).join(o.format.rules):Ot([],[],T(t)?t:Vt(t)?[...t]:_("invalid rules"),o).join(o.format.rules)};var _n=(t,...o)=>(n,r)=>(n.push(o.length?`@import url(${t}) ${o.join(r.format.ruleSep)};`:`@import url(${t});`),n);var ht=(t,o)=>vt("@media",t,o);function Bn(...t){return(o,n)=>(o.push(t.length>1?`@namespace ${t[0]} url(${t[1]});`:`@namespace url(${t[0]});`),o)}var en=(t,o)=>vt("@supports",t,o);var lt={"@comment":Ln,"@import":_n,"@keyframes":hn,"@media":ht,"@namespace":Bn,"@supports":en};var $n=4,An=(t)=>$n=t,M=(t)=>t===(t|0)?String(t):t.toFixed($n).replace(/^0./,".").replace(/^-0./,"-.").replace(/0+$/,"");var Tn=(t)=>`${M(t)}em`,Fn=(t)=>`${M(t)}ex`;var Sn=(t)=>`${M(t)}rem`,Ao=(t)=>`${M(t)}%`,wn=(t)=>`${M(t)}px`,Hn=(t)=>`${M(t)}vh`,un=(t)=>`${M(t)}vw`,yn=(t)=>`${M(t)}vmin`,Mn=(t)=>`${M(t)}vmax`,In=(t)=>`${t|0}ms`,Wn=(t)=>`${M(t)}s`;var Rn=(t)=>`${M(t)}deg`,Un=(t)=>`${M(t)}rad`,Yn=(t)=>`${M(t)}turn`,Dn=(t)=>`url(${t})`;var S=((t)=>{return t[t.IDLE=0]="IDLE",t[t.ACTIVE=1]="ACTIVE",t[t.DONE=2]="DONE",t[t.UNSUBSCRIBED=3]="UNSUBSCRIBED",t[t.ERROR=4]="ERROR",t})(S||{});var fm=0,Em=()=>fm++,x=(t,o)=>!o||!o.id?{...o,id:t+"-"+Em()}:o;var u=on.childLogger("rstream");class V{constructor(t,o){this.wrapped=t,o=x("sub",{closeIn:"last",closeOut:"last",cache:!0,...o}),this.parent=o.parent,this.id=o.id,this.closeIn=o.closeIn,this.closeOut=o.closeOut,this.cacheLast=o.cache,o.xform&&(this.xform=o.xform(Gt()))}id;closeIn;closeOut;parent;__owner;xform;cacheLast;last=Z;state=S.IDLE;subs=[];deref(){return this.last!==Z?this.last:void 0}getState(){return this.state}setState(t){this.state=t}subscribe(t,o={}){this.ensureState();let n;if(t instanceof V&&!o.xform)t.ensureState(),bt(!t.parent,`sub '${t.id}' already has a parent`),t.parent=this,n=t;else n=new V(t,{...o,parent:this});return this.subs.push(n),this.setState(S.ACTIVE),n.setState(S.ACTIVE),this.last!=Z&&n.next(this.last),n}transform(...t){let o,n;if(D(St(t)))n=t.pop(),o={error:n.error};return this.subscribe(o,x("xform",t.length>0?{...n,xform:z(...t)}:n))}map(t,o){return this.transform($(t),o||{})}unsubscribe(t){return t?this.unsubscribeChild(t):this.unsubscribeSelf()}unsubscribeSelf(){return u.debug(this.id,"unsub self"),this.parent?.unsubscribe(this),this.state<S.UNSUBSCRIBED&&(this.state=S.UNSUBSCRIBED),this.release(),!0}unsubscribeChild(t){u.debug(this.id,"unsub child",t.id);let o=this.subs.indexOf(t);if(o>=0){if(this.subs.splice(o,1),this.closeOut==="first"||!this.subs.length&&this.closeOut!=="never")this.unsubscribe();return!0}return!1}next(t){if(this.state>=S.DONE)return;this.xform?this.dispatchXform(t):this.dispatch(t)}done(){if(u.debug(this.id,"entering done()"),this.state>=S.DONE)return;if(this.xform){if(!this.dispatchXformDone())return}if(this.state=S.DONE,this.dispatchTo("done"))this.state<S.UNSUBSCRIBED&&this.unsubscribe();u.debug(this.id,"exiting done()")}error(t){let n=this.wrapped?.error;return n&&u.debug(this.id,"attempting wrapped error handler"),n?.(t)||this.unhandledError(t)}unhandledError(t){return(u.parent!==Ft?u:console).warn(this.id,"unhandled error:",t),this.unsubscribe(),this.state=S.ERROR,!1}dispatchTo(t,o){let n=this.wrapped;if(n)try{n[t]&&n[t](o)}catch(m){if(!this.error(m))return!1}let r=t==="next"?this.subs:[...this.subs];for(let m=r.length;m-- >0;){n=r[m];try{n[t]&&n[t](o)}catch(f){if(t==="error"||!n.error||!n.error(f))return this.unhandledError(f)}}return!0}dispatch(t){u.debug(this.id,"dispatch",t),this.cacheLast&&(this.last=t),this.dispatchTo("next",t)}dispatchXform(t){let o;try{o=this.xform[2]([],t)}catch(n){this.error(n);return}if(this.dispatchXformVals(o))H(o)&&this.done()}dispatchXformDone(){let t;try{t=this.xform[1]([])}catch(o){return this.error(o)}return this.dispatchXformVals(t)}dispatchXformVals(t){let o=j(t);for(let n=0,r=o.length;n<r&&this.state<S.DONE;n++)this.dispatch(o[n]);return this.state<S.ERROR}ensureState(){if(this.state>=S.DONE)rt(`operation not allowed in state ${S[this.state]}`)}release(){this.subs.length=0,delete this.parent,delete this.xform,delete this.last}}var zn=(t,o)=>{let n=new jn(o);return n.next(t),n};class jn extends V{src;_cancel;_inited;constructor(t,o){let[n,r]=X(t)?[t,o||{}]:[void 0,t||{}];super(r.error?{error:r.error}:void 0,x("stream",r));this.src=n,this._inited=!1}subscribe(t,o={}){let n=super.subscribe(t,o);if(!this._inited){if(this.src)try{this._cancel=this.src(this)||(()=>{return})}catch(r){let m=this.wrapped;if(!m||!m.error||!m.error(r))this.unhandledError(r)}this._inited=!0}return n}unsubscribe(t){let o=super.unsubscribe(t);if(o&&(!t||(!this.subs||!this.subs.length)&&this.closeOut!=="never"))this.cancel();return o}done(){this.cancel(),super.done(),delete this.src,delete this._cancel}error(t){if(super.error(t))return!0;return this.cancel(),!1}cancel(){if(this._cancel){u.debug(this.id,"cancel");let t=this._cancel;delete this._cancel,t()}}}var Jn=(t,o)=>t==="first"||t==="last"&&!o;function To(t){return t?ft(To(),t):Et(()=>({}),(o,[n,r])=>(o[n]=r,o))}var Xn=()=>(t)=>{let o=t[2];return K(t,(n,r)=>{if(r){for(let m of j(r)||[])if(n=o(n,m),H(n))break}return H(r)?fn(n):n})};function Fo(t,o){return F(o)?Nt(Fo(t),o):z($(t),Xn())}function So(t,o){return F(o)?d(So(t),o):$(X(t)?(n)=>[t(n),n]:(n)=>[t,n])}function wo(...t){let o=pt(wo,t);if(o)return o;let n=t[0],r=t[1]!==!1;return $((m)=>{let f=r?{}:m;for(let G in m)f[G]=n(m[G]);return f})}var Pn=(t)=>t;function Ho(...t){let o=pt(Ho,t,Nt);if(o)return o;let{key:n=Pn,mergeOnly:r=!1,reset:m=!0,all:f=!0,backPressure:G=0}=t[1],E=T(t[0])?new Set(t[0]):t[0],N=new Set,O=new Map,h={},C=([L,B,I])=>{let k=!0;if(r||G<1)return[L,(e)=>{if(m&&f&&N.size>0||!m&&k)e=I(e,h),h={},N.clear(),k=!1;return B(e)},(e,v)=>{let y=n(v);if(E.has(y)){if(h[y]=v,N.add(y),r||bn(E,N))if(e=I(e,h),k=!1,m)h={},N.clear();else h={...h}}return e}];else return[L,(e)=>{if(f&&N.size>0)e=I(e,Zn(O,N)),O.clear(),N.clear();return B(e)},(e,v)=>{let y=n(v);if(E.has(y)){let b=O.get(y);!b&&O.set(y,b=[]),b.length>=G&&rt(`max back pressure (${G}) exceeded for input: ${String(y)}`),b.push(v),N.add(y);while(bn(E,N))if(e=I(e,Zn(O,N)),k=!1,H(e))break}return e}]};return C.keys=()=>E,C.clear=()=>{O.clear(),E.clear(),N.clear(),h={}},C.add=(L)=>{E.add(L)},C.delete=(L,B=!0)=>{if(O.delete(L),E.delete(L),B)N.delete(L),delete h[L]},C}var bn=(t,o)=>{if(o.size<t.size)return!1;for(let n of t)if(!o.has(n))return!1;return!0},Zn=(t,o)=>{let n={};for(let r of o){let m=t.get(r);n[r]=m.shift(),!m.length&&o.delete(r)}return n};var Kn=(t,o)=>{let n=!0;for(let r of o)n=t.removeID(r)&&n;return n};var dt=(t)=>new Vn(t);class Vn extends V{sources;idSources;realSourceIDs;invRealSourceIDs;psync;clean;constructor(t){let o=Ho(new Set,{key:(r)=>r[0],mergeOnly:t.mergeOnly===!0,reset:t.reset===!0,all:t.all!==!1,backPressure:t.backPressure||0}),n=wo((r)=>r[1]);super(void 0,x("streamsync",{...t,xform:t.xform?z(o,n,t.xform):z(o,n)}));this.sources=new Map,this.realSourceIDs=new Map,this.invRealSourceIDs=new Map,this.idSources=new Map,this.psync=o,this.clean=!!t.clean,t.src&&this.addAll(t.src)}add(t,o){o||(o=t.id),this.ensureState(),this.psync.add(o),this.realSourceIDs.set(o,t.id),this.invRealSourceIDs.set(t.id,o),this.idSources.set(t.id,t),this.sources.set(t,t.subscribe({next:(n)=>n[1]instanceof V?this.add(n[1]):this.next(n),done:()=>this.markDone(t),__owner:this},{xform:So(o),id:`in-${o}`}))}addAll(t){for(let o in t)this.psync.add(o);for(let o in t)this.add(t[o],o)}remove(t){let o=this.sources.get(t);if(o){let n=this.invRealSourceIDs.get(t.id);return u.info(`removing src: ${t.id} (${n})`),this.psync.delete(n,this.clean),this.realSourceIDs.delete(n),this.invRealSourceIDs.delete(t.id),this.idSources.delete(t.id),this.sources.delete(t),o.unsubscribe(),!0}return!1}removeID(t){let o=this.getSourceForID(t);return o?this.remove(o):!1}removeAll(t){for(let n of t)this.psync.delete(this.invRealSourceIDs.get(n.id));let o=!0;for(let n of t)o=this.remove(n)&&o;return o}removeAllIDs(t){return Kn(this,t)}getSourceForID(t){return this.idSources.get(this.realSourceIDs.get(t))}getSources(){let t={};for(let[o,n]of this.idSources)t[this.invRealSourceIDs.get(o)]=n;return t}unsubscribe(t){if(!t){u.debug(this.id,"unsub sources");for(let o of this.sources.values())o.unsubscribe();this.sources.clear(),this.psync.clear(),this.realSourceIDs.clear(),this.invRealSourceIDs.clear(),this.idSources.clear()}return super.unsubscribe(t)}markDone(t){this.remove(t),Jn(this.closeIn,this.sources.size)&&this.done()}}var uo=R((t,o=" ")=>{let n=tt(String(o),t);return(r,m)=>{if(r==null)return n;return r=r.toString(),m=m!==void 0?m:r.length,m<t?n.substring(m)+r:r}}),p1=uo(2,"0"),Q1=uo(3,"0"),qn=uo(4,"0");var Gm=/\{(\d+)\}/g;var yo=(t,...o)=>o.length>0?t.replace(Gm,(n,r)=>String(o[parseInt(r,10)])):t;var pn=(t)=>({key:(o)=>o,group:Gt(),...t});function Mo(...t){let o=En(Mo,t);if(o)return o;let n=pn(t[0]),[r,m,f]=n.group;return[()=>({}),(G)=>{for(let E in G)G[E]=m(G[E]);return G},(G,E)=>{let N=n.key(E);return G[N]=G[N]?f(G[N],E):f(r(),E),G}]}function Io(t,o){return F(o)?d(Io(t),o):(n)=>{let r=n[2];return K(n,(m,f)=>t(f)?r(m,f):m)}}import{watch as dn}from"fs";import{resolve as a}from"path";var Qn={specs:Y({alias:"s",optional:!1,desc:"Path to generated JSON defs"})},gt={bundle:W({alias:"b",desc:"Bundle inputs (see `out` option)"})},Lt={include:Ut({alias:"I",desc:"Include CSS files (prepend)"})},xt={eval:Y({alias:"e",desc:"eval meta stylesheet in given string (ignores other inputs & includes)"})},at={force:Ut({alias:"f",hint:"STR",desc:"CSS classes to force include (wildcards are supported, @-prefix will read from file)",delim:","})},kn={media:Ut({alias:"m",hint:"ID",desc:"Media query IDs (use 'ALL' for all)",delim:","})},vn={onlyDecls:W({desc:"Only emit framework decls"})},q={out:Y({alias:"o",desc:"Output file (or stdout)"})},st={prec:Yt({default:3,desc:"Number of fractional digits"})},p={pretty:W({alias:"p",desc:"Pretty print output"})},Ct={noDecls:W({alias:"d",desc:"Don't emit framework decls"})},_t={noHeader:W({desc:"Don't emit generated header comment"})},Bt={scope:Y({desc:"Suffix for CSS class names"})},et={watch:W({alias:"w",desc:"Watch input files for changes"})};import{watch as Nm}from"fs";import{resolve as ln}from"path";var Q=(t,o,n)=>{o=i(o)?o:o.join(`
`),t?ho(ln(t),o,n):process.stdout.write(o+`
`)},ct=({info:{name:t,version:o}})=>`/*! ${t} v${o} - generated by thi.ng/meta-css @ ${new Date().toISOString()} */`,ut=(t,o)=>{let n=()=>{o.info("closing watchers..."),r.forEach((m)=>m.watcher.close())},r=t.map((m,f)=>{m=ln(m);let G=zn(w(m,o),{id:`in${qn(f)}`});return{input:G,watcher:Nm(m,{},(E)=>{if(E==="change")try{G.next(w(m,o))}catch(N){o.warn(N.message),n()}else o.warn("input removed:",m),n()})}});return process.on("SIGINT",n),dt({src:To($(({input:m})=>[m.id,m],r))})},to=(t)=>Object.keys(t).reduce((o,n)=>{if(!n.startsWith("__"))o[n]=t[n];return o},{});var xn={desc:"Transpile (and optionally bundle) meta stylesheets to CSS",opts:{...gt,...xt,...at,...Lt,...Ct,..._t,...q,...p,...Bt,...Qn,...et,noWrite:W({desc:"Don't write files, use stdout only"})},fn:Wo};async function Wo(t){let o=P(a(t.opts.specs),t.logger),n=_m(o,t.opts.force||[],t.logger);if(t.opts.bundle)if(t.opts.watch)await hm(t,n);else Mt(t,o,n,t.opts.eval?[t.opts.eval]:t.inputs.map((r)=>w(a(r),t.logger)),t.opts.out);else if(t.opts.watch)await Om(t,o,n);else if(t.opts.eval)try{Mt(t,o,n,[t.opts.eval])}catch(r){t.logger.warn(r.message)}else for(let r of t.inputs)try{r=a(r);let m=!t.opts.noWrite?r.replace(/\.mcss$/,".css"):void 0;Mt(t,o,n,[w(r,t.logger)],m)}catch(m){t.logger.warn(m.message)}}var Om=async(t,o,n)=>{let r=a(t.opts.specs),m,f={process:()=>{try{return o=P(r,t.logger),m.forEach((E)=>E.process()),!0}catch(E){return t.logger.warn(E.message+": "+r),!1}},watcher:dn(r,{},(E)=>{if(E==="change")f.process();else t.logger.warn("specs file removed:",r),G()})},G=()=>{t.logger.info("closing watchers..."),f.watcher.close(),m.forEach((E)=>E.watcher.close())};m=t.inputs.map((E)=>{E=a(E);let N=!t.opts.noWrite?E.replace(/\.mcss$/,".css"):void 0,O=()=>{try{return Mt(t,o,n,[w(E,t.logger)],N),!0}catch(h){if(t.logger.warn(h.message+": "+E),m)G();return!1}};if(!O())process.exit(1);return{process:O,watcher:dn(E,{},(h)=>{if(h==="change")O();else t.logger.warn("input removed:",E),G()})}}),t.logger.info("waiting for changes, press ctrl+c to cancel..."),process.on("SIGINT",G)},hm=async(t,o)=>{dt({src:{styles:ut(t.inputs,t.logger),specs:ut([t.opts.specs],t.logger).map((n)=>JSON.parse(Object.values(n)[0]))}}).subscribe({next({styles:n,specs:r}){try{Mt(t,r,o,Object.keys(n).sort().map((m)=>n[m]),t.opts.out)}catch(m){t.logger.warn(m.message)}}})},Mt=({logger:t,opts:{include:o,noDecls:n,noHeader:r,pretty:m,scope:f}},G,E,N,O)=>{let h={logger:t,specs:G,css:{format:m?qt:mt,fns:lt,scope:f},mediaQueryIDs:new Set(Object.keys(G.media)),mediaQueryRules:{...E.mediaQueryRules},plainRules:{...E.plainRules}},C=o?o.map((L)=>w(a(L),t).trim()):[];if(!r)C.push(ct(G));if(!n&&G.decls.length)C.push(g(G.decls,h.css));N.forEach((L)=>Bm(L,h)),Cm(C,h),Lm(C,h),Q(O,C,t)},Lm=(t,{css:o,logger:n,mediaQueryRules:r,specs:m})=>{for(let f in r){let G=sn(r[f],m);n.debug("mediaquery rules",f,G),t.push(g(ht(Am(m.media,f),G),o))}},Cm=(t,{css:o,logger:n,plainRules:r,specs:m})=>{let f=sn(r,m);n.debug("plain rules",f),t.push(g(f,o))},_m=(t,o,n)=>{let r=new Set(Object.keys(t.media)),m=new Set(Object.keys(t.classes)),f={},G={};if(o.length&&o[0][0]==="@")o=[...ot(w(a(o[0].substring(1)),n))];for(let E of o){if(!E||E.startsWith("//"))continue;let{token:N,query:O}=cn(E,r),h;if(N.includes("*")){let C=new RegExp(`^${N.replace("*",".*")}$`);h=[...Io((L)=>C.test(L),m)]}else if(m.has(N))h=[N];else{n.warn(`unknown include rule ID: ${E}, skipping...`);continue}for(let C of h)n.debug("including class:",C),O?tr(f,O,`.${C}`,C):or(G,`.${C}`,C)}return{mediaQueryRules:f,plainRules:G}},Bm=(t,{specs:o,mediaQueryIDs:n,mediaQueryRules:r,plainRules:m})=>{let f=It(),G=It(f),E={root:f,curr:G,scopes:[G]};for(let N of ot(t)){if(!N||/^\s*\/\//.test(N))continue;for(let O of em(N)){if(!O)continue;let h=E.curr;switch(h.state){case"sel":case"nest":if(O==="{"){if(h.state==="sel")h.sel=h.sel.map((C)=>C.replace(",","")),h.path=$m(E.scopes);h.state="class"}else if(O==="}")gn(E);else{let C=St(h.sel);if(!C||C.endsWith(","))h.sel.push(O);else h.sel[h.sel.length-1]+=" "+O}break;case"class":if(O==="{")h.state="nest",E.scopes.push(E.curr=It(h));else if(O==="}")gn(E);else{let{token:C,query:L}=cn(O,n);if(!o.classes[C]&&!(nr(C)||mr(C)||rr(C)))_(`unknown class ID: ${C}`);if(L)tr(r,L,h.path,C);else or(m,h.path,C)}break;default:rt(h.state)}}}};function*em(t){let o=-1,n=t.length,r=0,m=0;for(let f=0;f<n;f++){let G=t[f];if(G===" "||G==="\t"){if(!(r||m)&&o>=0)yield t.substring(o,f),o=-1}else if(G==="{"||G==="}"){if(o>=0)yield t.substring(o,f);yield G,o=-1}else if(G==="(")r++;else if(G===")"){if(--r<0)_(`invalid nesting in line: '${t}'`)}else if(G==="["){if(o<0)o=f;m++}else if(G==="]"){if(--m<0)_(`invalid arg nesting in line: '${t}'`)}else if(o<0)o=f}if(r)_("template calls must be fully on a single line");if(m)_("verbatim properties must be fully on a single line");if(o>=0)yield t.substring(o,n)}var yt=":",an="///",It=(t)=>({state:"sel",sel:t?[]:["<root>"],path:"",parent:t}),gn=(t)=>{let o=!t.curr.sel.length;if(bt(!!t.curr.parent,"stack underflow"),t.scopes.pop(),t.scopes.length>0){if(t.curr=St(t.scopes),!o&&t.curr.state==="nest")t.scopes.push(t.curr=It(t.curr))}else t.scopes.push(t.curr=It(t.root))},$m=(t)=>t.map((o)=>o.sel.join(",")).join(an),sn=(t,o)=>Object.entries(t).map(([n,r])=>im(n,r,o)),im=(t,o,n)=>{let r=[],m=r,f=t.split(an);for(let G=0;G<f.length;G++){let E=f[G].split(",");if(G==f.length-1){let N=Object.assign({},...$((O)=>mr(O)?Sm(O):nr(O)?Tm(O):rr(O)?Fm(n,O):to(n.classes[O]),o));E.push(N)}m.push(E),m=E}return r[0]},cn=(t,o)=>{if(/^::?/.test(t))return{token:t};let n=t.lastIndexOf(yt);if(n<0)return{token:t};let r=t.indexOf("("),m=t.indexOf("[");if(r>0||m>0){let E=r>0?m>0?Math.min(r,m):r:m;if(E<n&&t.indexOf(yt)>E)return{token:t};n=t.substring(0,E).lastIndexOf(yt)}let f=t.substring(0,n);if(!f.split(yt).every((E)=>o.has(E)))_(`invalid media query in token: ${t}`);return{token:t.substring(n+1),query:f}},Am=(t,o)=>o.split(yt).reduce((n,r)=>Object.assign(n,t[r]),{}),tr=(t,o,n,r)=>{if(!t[o])t[o]={};(t[o][n]||(t[o][n]=new Set)).add(r)},or=(t,o,n)=>(t[o]||(t[o]=new Set)).add(n),Tm=(t)=>{let o=t.indexOf("=");return{[`--${t.substring(0,o)}`]:t.substring(o+1)}},Fm=(t,o)=>{let n=o.indexOf("("),r=o.substring(0,n),m=o.substring(n+1,o.length-1).split(/(?<!\\),/g).map((G)=>G.trim().replace("\\,",",")),f=t.templates[r];if(!f)_(`unknown template: ${r}`);if(m.length!==f.__arity)_(`template "${r}" expected ${f.__arity} arguments`);return Object.entries(f).reduce((G,[E,N])=>{if(!E.startsWith("__")){if(E=yo(E,...m),i(N))N=yo(N,...m);G[E]=N}return G},{})},Sm=(t)=>{let[o,n,r]=/^(.+)-\[(.+)\]/.exec(t);return{[n]:r}},nr=(t)=>/^[a-z0-9:_-]+=.+/i.test(t),rr=(t)=>t.includes("(")&&t.endsWith(")"),mr=(t)=>t.indexOf("-[")>0&&t.endsWith("]");var Er={deg:Rn,em:Tn,ex:Fn,ms:In,percent:Ao,px:wn,rad:Un,rem:Sn,second:Wn,turn:Yn,url:Dn,vh:Hn,vmax:Mn,vmin:yn,vw:un,"%":Ao},wm={percent:"{0}%",second:"{0}s",url:"url({0})"},Hm={"":[""],a:[""],h:["-left","-right"],v:["-top","-bottom"],t:["-top"],top:["top"],b:["-bottom"],bottom:["bottom"],r:["-right"],right:["right"],l:["-left"],left:["left"],x:["-x"],y:["-y"],in:[""],out:[""]},Gr={desc:"Generate framework rules from specs",opts:{...q,...st,...p,...et},fn:Ro};async function Ro(t){if(t.opts.watch)await um(t);else await Nr(t.inputs.map((o)=>w(o,t.logger)),t.opts,t.logger)}var um=async(t)=>{ut(t.inputs,t.logger).subscribe({next(o){try{Nr(Object.keys(o).sort().map((n)=>o[n]),t.opts,t.logger)}catch(n){t.logger.warn(n.message)}}})},Nr=async(t,o,n)=>{let r={info:{name:"TODO",version:"0.0.0"},media:{},classes:{},templates:{},decls:[]};An(o.prec);for(let m of t){let f=JSON.parse(m);if(Object.assign(r.info,f.info),Object.assign(r.media,f.media),f.decls)r.decls.push(...f.decls);if(f.specs)for(let G of f.specs)try{Or(f,G,r.classes,n)}catch(E){n.warn(`error processing spec: ${G.name}`,E,", skipping...")}if(f.templates)for(let G of f.templates)ym(f,G,r.templates,n)}return Q(o.out,JSON.stringify(r,null,o.pretty?4:0),n),r},Or=(t,o,n,r,m=!1)=>{let f=T(o.vars)?o.vars:[""],G=i(o.props)?{[o.props]:"<v>"}:o.props,E=Mm(o,t),N=new Set;for(let O of f){let h=t.vars?.[O]||Hm[O];if(!h)_(`unknown variation ID: ${O}`);for(let[C,L]of Qt(h,Object.keys(E))){let B=s(o.name,O,C,L,E[L]),I=o.unit?s(o.unit,O,C,L,E[L]):void 0,k=m?Wm(I):Im(E[L],I);if(!n[B]){if(n[B]={},o.user!=null)n[B].__user=o.user;if(o.doc!=null)n[B].__doc=Rm(o.doc,O,C,L,k)}else if(!N.has(B))_(`duplicate class ID: ${B}`);N.add(B);let e=-1;for(let[v,y]of Object.entries(G)){let b=s(v,O,C,L,E[L]),oo=s(!I||i(y)?String(y):Er[I](y),O,C,L,k);if(n[B][b]=oo,r.debug(B,b,oo),m)e=fr(oo,fr(b,e))}if(m)n[B].__arity=e+1}}return n},ym=(t,o,n,r)=>Or(t,{...o,values:[""]},n,r,!0),fr=(t,o)=>{let n=/\{(\d+)\}/g,r;while(r=n.exec(t))o=Math.max(o,+r[1]);return o},Mm=(t,o)=>{let n=i(t.values)?o.tables?.[t.values]||_(`invalid table ID: ${t.values}`):t.values;if(D(n))return n;let r=t.key==="v"?(m)=>String(m):t.key==="i+1"?(m,f)=>String(f+1):t.key==="i"||t.key===void 0?(m,f)=>String(f):_(`invalid key type: ${t.key}`);return n.reduce((m,f,G)=>{return m[r(f,G)]=f,m},{})},Im=(t,o)=>{if(!o||i(t))return t;let n=Er[o];if(!n)_(`invalid unit: ${o}`);return n(t)},Wm=(t)=>t?wm[t]||"{0}"+t:"{0}",s=(t,o,n,r,m)=>t.replace(/<vid>/g,o).replace(/<var>/g,n).replace(/<k>/g,r).replace(/<v>/g,String(m)),Rm=({group:t,desc:o,args:n},r,m,f,G)=>({group:t?s(t,r,m,f,G):"TODO",desc:o?s(o,r,m,f,G):void 0,args:n?n.map((E)=>s(E,r,m,f,G)):void 0});var hr={desc:"Combination of the generate & convert commands",opts:{...gt,...xt,...at,...Lt,...Ct,..._t,...st,...p,...Bt,...et,outCss:Y({desc:"Output file for CSS bundle",optional:!1}),outSpecs:Y({desc:"Output file for framework",optional:!1})},fn:async(t)=>{let{opts:o,inputs:n}=t,[r,m]=n.reduce((E,N)=>(E[N.endsWith(".json")?0:1].push(N),E),[[],[]]),f={inputs:r,format:t.format,logger:t.logger,opts:{...o,out:o.outSpecs}},G={inputs:m,format:t.format,logger:t.logger,opts:{...o,noWrite:!1,out:o.outCss,scope:o.scope,specs:o.outSpecs}};await Ro(f),await Wo(G)}};import{resolve as Um}from"path";var _r={desc:"Generate Markdown documentation for framework specs",opts:{...q,level:Yt({alias:"l",desc:"Initial heading level",default:1}),title:Y({alias:"t",desc:"Custom main title, set to NONE to disable"})},inputs:1,fn:async(t)=>{let{logger:o,opts:n,inputs:r}=t,m=P(Um(r[0]),o),f=Ym(m,n);Q(n.out,f,o)}},Ym=(t,{level:o,title:n})=>{let r=Object.keys(t.classes).length,m=Object.keys(t.templates).length,f=[`Currently, there are ${r+m} CSS utility classes (incl. ${m} templates) defined in "${t.info.name}" (v${t.info.version}):`,"",`${c(o+1)} Classes by category`,"",...Cr(t.classes,zm,o+2),`${c(o+1)} Templates by category`,"",...Cr(t.templates,jm,o+2),`${c(o+1)} Media queries`,"",...Object.entries(t.media).map(([G,E])=>`- **${G}**: \`${JSON.stringify(E)}\``),""];if(n!=="NONE")f.unshift(`${c(o)} ${n??t.info.name}
`);return f},Lr=(t)=>t.split(/(\d+)/).map((o)=>{let n=parseInt(o);return isNaN(n)?o:n}),Dm=(t,o)=>{if(/\d+/.test(t)&&/\d+/.test(o)){let n=Lr(t),r=Lr(o),m=n.length;if(m===r.length){for(let f=0;f<m;f++)if(n[f]!==r[f])return _o(n[f],r[f]);return 0}return n.length-r.length}return _o(t,o)},Cr=(t,o,n)=>{let r=Mo({key:([m,{__doc:f}])=>f?.group||"TODO",group:[()=>[],(m)=>m.sort(),(m,f)=>(m.push(f[0]),m)]},Object.entries(t));return Fo((m)=>{let f=r[m].sort(Dm).map((E)=>o(E,t[E].__doc,n+1)),G=f.length;return[`${c(n)} ${Xt(m)}`,G>3?`
<details><summary>${G} items:</summary>
`:"",f.join(`
`),G>3?`</details>
`:""]},Object.keys(r).sort())},zm=(t,o)=>{if(!o?.desc)return`- \`${t}\``;let n=o.desc;if(/^-[a-z]/.test(n))n=n.substring(1);return`- \`${t}\` (${n})`},jm=(t,o,n)=>{if(!o?.args)return`${c(n)} ${t}(...)
TODO`;let r=o.args.map((m)=>/^\w+/.exec(m)[0]).join(", ");return[`${c(n)} \`${t}(${r})\``,"",...o.args.map(Jm),o.desc?`
${o.desc}
`:""].join(`
`)},Jm=(t)=>`- ${t.replace(/^(\w+)/,(o,n)=>`**${n}**`)}`,c=R((t)=>"#".repeat(t));import{resolve as Br}from"path";var $r={desc:"Export entire generated framework as CSS",opts:{...Lt,...Ct,...vn,...q,...p,..._t,...kn,...Bt},inputs:1,fn:async(t)=>{let{logger:o,opts:{include:n,media:r,noDecls:m,noHeader:f,onlyDecls:G,out:E,pretty:N,scope:O},inputs:h}=t,C={format:N?qt:mt,fns:lt,scope:O},L=P(Br(h[0]),o),B=n?n.map((I)=>w(Br(I),o).trim()):[];if(!f)B.push(ct(L));if(!m&&L.decls.length)B.push(g(L.decls,C));if(!G)B.push(Xm(L,r,C,o));Q(E,B,o)}},Xm=(t,o,n,r)=>{let m=er("",t);if(o){let f=o[0]==="ALL"?Object.keys(t.media):o;for(let G of f)if(t.media[G])m.push(ht(t.media[G],er("-"+G,t)));else r.warn(`invalid media query ID: ${G}, skipping...`)}return g(m,n)},er=(t,o)=>Object.entries(o.classes).map(([n,r])=>[`.${n}${t}`,to(r)]);var Uo=P(Pm(process.argv[2],"package.json"));so({name:"metacss",opts:{verbose:W({alias:"v",desc:"Display extra process information"})},commands:{convert:xn,develop:hr,doc:_r,export:$r,generate:Gr},ctx:async(t)=>{if(t.opts.verbose)t.logger.level=A.DEBUG;return{...t,format:Jt}},start:3,usage:{prefix:`
\u2588 \u2588 \u2588 \u2502
\u2588\u2588 \u2588 \u2502
\u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2502 ${Uo.name} ${Uo.version}
\u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2502 ${Uo.description}
\u2588 \u2502
\u2588 \u2588 \u2502
Usage: metacss <cmd> [opts] input [...]
metacss <cmd> --help
`,showGroupNames:!0,paramWidth:24}});