@thi.ng/meta-css 0.19.5 → 0.19.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/index.js +20 -20
- package/package.json +19 -19
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -2758,7 +2758,7 @@ The toolchain itself is distributed as CLI bundle with **no runtime
|
|
|
2758
2758
|
dependencies**. The following dependencies are only shown for informational
|
|
2759
2759
|
purposes and are (partially) included in the bundle.
|
|
2760
2760
|
|
|
2761
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 14.
|
|
2761
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 14.08 KB
|
|
2762
2762
|
|
|
2763
2763
|
## Dependencies
|
|
2764
2764
|
|
package/index.js
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
3
|
-
`),this.parent?.logEntry(t)}}var Oo={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
|
|
4
|
-
`};var
|
|
5
|
-
`,start:()=>"",end:""};var
|
|
6
|
-
`)},Kt=(t)=>D(t)?{...
|
|
2
|
+
var Eo={default:95,command:92,hint:90,multi:90,param:96,required:33};var At=(t)=>t;function W(t,o=Object.create(null)){return(...n)=>{let r=n.join("-");return r in o?o[r]:o[r]=t(...n)}}var ot=W((t,o)=>t.repeat(o));var Xo=(t)=>/^[a-f0-9]+$/i.test(t);var bo=(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 Sr=U(()=>"illegal argument(s)"),i=(t)=>{throw new Sr(t)};var Go=(t)=>Zo(t)?parseFloat(t):i(`not a numeric value: ${t}`),Ko=(t)=>t.map(Go),eo=(t)=>Xo(t)?parseInt(t,16):i(`not a hex value: ${t}`),po=(t)=>t.map(eo),No=(t)=>bo(t)?parseInt(t):i(`not an integer: ${t}`),Vo=(t)=>t.map(No);var Wt=(t,o)=>(n)=>({coerce:t,hint:o,group:"main",...n}),Ut=(t,o)=>(n)=>({hint:Hr(o,n.delim),multi:!0,coerce:t,group:"main",...n}),Hr=(t,o)=>t+(o?`[${o}..]`:""),R=(t)=>({flag:!0,default:!1,group:"flags",...t}),Y=Wt(At,"STR"),Yt=Ut(At,"STR"),Cf=Wt(Go,"NUM"),Lf=Wt(eo,"HEX"),Dt=Wt(No,"INT"),Bf=Ut(Ko,"NUM"),Af=Ut(po,"HEX"),$f=Ut(Vo,"INT");var $=((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})($||{});var yr=0;class $t{constructor(t,o=$.FINE,n){this.parent=n,this.id=t||`logger-${yr++}`,this.level=typeof o==="string"?$[o]:o}id;level;addChild(t){return t.parent=this,t}enabled(t){return this.level<=t}fine(...t){this.log($.FINE,t)}debug(...t){this.log($.DEBUG,t)}info(...t){this.log($.INFO,t)}warn(...t){this.log($.WARN,t)}severe(...t){this.log($.SEVERE,t)}none(){}log(t,o){this.level<=t&&this.logEntry([t,this.id,Date.now(),...o])}}var qo=(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 Jt extends $t{constructor(t,o,n,r){super(o,n,r);this.target=t}childLogger(t,o){return new Jt(this.target,t,o??this.level,this)}logEntry(t){if(t[0]<this.level)return;this.target.write(`[${$[t[0]]}] ${t[1]}: ${qo(t.slice(3))}
|
|
3
|
+
`),this.parent?.logEntry(t)}}var Oo={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 Mr=(t,o)=>(n)=>t.format(o,n),ho=(t)=>Object.keys(Oo).reduce((o,n)=>(o[n]=Mr(t,Oo[n]),o),{format:t});var Qo="\x1B[0m";var Ir=["","1","2","1;2","4","1;4","2;4","1;2;4"],zt={format:(t,o)=>zt.start(t)+o+zt.end,start:W((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(Ir[n]),"\x1B["+o.join(";")+"m"}),end:Qo,prefix:Qo,suffix:`
|
|
4
|
+
`};var ko={format:(t,o)=>String(o),prefix:"",suffix:`
|
|
5
|
+
`,start:()=>"",end:""};var ut=ho(zt),_o=ho(ko);var u=Array.isArray;var Rr=(t)=>t.toUpperCase(),vo=(t)=>t.toLowerCase(),jt=(t)=>t.length?t[0].toUpperCase()+t.substring(1):t,lo=(t,o="-")=>vo(t.replace(/([a-z0-9\u00e0-\u00fd])([A-Z\u00c0-\u00dd])/g,(n,r,m)=>r+o+m));var go=(t,o="-")=>vo(t).replace(new RegExp(`\\${o}+(\\w)`,"g"),(n,r)=>Rr(r));var xo=(t=!1,o)=>(n)=>t||typeof n!=="string"&&typeof n!=="number"?JSON.stringify(n,null,o):String(n);var ao=Object.getPrototypeOf,D=(t)=>{let o;return t!=null&&typeof t==="object"&&((o=ao(t))===null||ao(o)===null)};var Wr=/\x1b\[[0-9;]+m/g,Ur=(t)=>t.replace(Wr,"");var Pt=(t)=>Ur(t).length;function*nt(t,o=/\r?\n/g,n=!1){let r=0,m=t.length,f=~~n,E;if(typeof o==="string")E=new RegExp(o,"g");else if(!o.flags.includes("g"))E=new RegExp(o,o.flags+"g");else E=o;for(;r<m;){let G=E.exec(t);if(!G){yield t.substring(r);return}let e=G[0].length;yield t.substring(r,G.index+f*e),r=G.index+e}}class io{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},co={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}},so=(t,o,n,r)=>{let m=t[t.length-1];m&&r-m.n>n?m.add(o,n):t.push(new io(o,n))},Dr=(t,{width:o,min:n,hard:r,splitter:m},f=0,E=[])=>{let G=m.length(t),e=o-f;if(e<n&&e<G)e=o;while(r&&G>e){let N=m.split(t,e),O=t.substring(0,N);so(E,O,e,o),t=t.substring(N),e=o,G=m.length(t)}return so(E,t,G,o),E},Jr=(t,o,n=[])=>{if(!t.length)return n.push(new io),n;let r={width:80,min:4,hard:!1,splitter:Yr,...o};for(let m of nt(t,o.delimWord||/\s/g)){let f=n[n.length-1];Dr(m,r,f&&f.n>0?f.n+1:0,n)}return n},tn=(t,o)=>{let n=[];for(let r of nt(t,o.delimLine))n=n.concat(Jr(r,o));return n};var on=W((t,o=" ")=>{let n=ot(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 Z=(t,o)=>o!=null?`\x1B[${o}m${t}\x1B[0m`:t,Xt=(t,o)=>on(o)(t,Pt(t)),bt=(t,o)=>t?tn(t,{width:o,splitter:co,hard:!1}):[],Zt=(t,o,n)=>{let r=ot(" ",o);return bt(t,n-o).map((m,f)=>f?r+m:m).join(`
|
|
6
|
+
`)},Kt=(t)=>D(t)?{...Eo,...t}:t?Eo:{};var Tt=(t,o={})=>{o={lineWidth:80,paramWidth:32,showDefaults:!0,prefix:"",suffix:"",groups:["flags","main"],...o};let n=Kt(o.color),r=(E)=>E.map((G)=>zr(G,t[G],o,n,o.paramWidth)),m=Object.keys(t).sort(),f=o.groups?o.groups.map((E)=>[E,m.filter((G)=>t[G].group===E)]).filter((E)=>!!E[1].length):[["options",m]];return[...bt(o.prefix,o.lineWidth),...f.map(([E,G])=>[...o.showGroupNames?[`${jt(E)}:
|
|
7
7
|
`]:[],...r(G),""].join(`
|
|
8
8
|
`)),...bt(o.suffix,o.lineWidth)].join(`
|
|
9
|
-
`)},zr=(t,o,n,r,m)=>{let f=
|
|
9
|
+
`)},zr=(t,o,n,r,m)=>{let f=jr(o,r),E=Pr(o,r,f),G=Z(`--${lo(t)}`,r.param),e=`${E}${G}${f}`,N=o.optional===!1&&o.default===void 0,O=[];N&&O.push("required"),o.multi&&O.push("multiple");let _=Xr(O,r,N)+(o.desc||"")+br(o,n,r);return Xt(e,n.paramWidth)+Zt(_,m,n.lineWidth)},jr=(t,o)=>t.hint?Z(" "+t.hint,o.hint):"",Pr=(t,o,n)=>t.alias?`${Z("-"+t.alias,o.param)}${n}, `:"",Xr=(t,o,n)=>t.length?Z(`[${t.join(", ")}] `,n?o.required:o.multi):"",br=(t,o,n)=>o.showDefaults&&t.default!=null&&t.default!==!1?Z(` (default: ${xo(!0)(t.defaultHint!=null?t.defaultHint:t.default)})`,n.default):"";var Zr=U(()=>"parse error"),nn=(t,o,n)=>{n={start:2,showUsage:!0,help:["--help","-h"],...n};try{return Kr(t,o,n)}catch(r){if(n.showUsage)console.log(r.message+`
|
|
10
10
|
|
|
11
|
-
`+
|
|
11
|
+
`+Tt(t,n.usageOpts));throw new Zr(r.message)}},Kr=(t,o,n)=>{let r=pr(t),m={},f,E,G=n.start;for(;G<o.length;){let e=o[G];if(!f){if(n.help.includes(e)){console.log(Tt(t,n.usageOpts));return}let N=Vr(t,r,m,e);if(f=N.id,E=N.spec,G=G+~~(N.state<2),N.state)break}else{if(qr(E,m,f,e))break;f=null,G++}}return f&&i(`missing value for: --${f}`),{result:Qr(t,m),index:G,rest:o.slice(G),done:G>=o.length}},pr=(t)=>Object.entries(t).reduce((o,[n,r])=>r.alias?(o[r.alias]=n,o):o,{}),Vr=(t,o,n,r)=>{if(r[0]==="-"){let m;if(r[1]==="-"){if(r==="--")return{state:1};m=go(r.substring(2))}else m=o[r.substring(1)],!m&&i(`unknown option: ${r}`);let f=t[m];if(!f&&i(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}},qr=(t,o,n,r)=>{if(t.multi)u(o[n])?o[n].push(r):o[n]=[r];else o[n]=r;return t.fn&&!t.fn(r)},Qr=(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)i(`missing arg: --${r}`)}else if(n.coerce)kr(n,o,r);return o},kr=(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 rn=async(t)=>{let o=t.argv||process.argv,n=!process.env.NO_COLOR,r=n?ut:_o,m={prefix:"",color:n,...t.usage};try{let f,E,G=t.start??2;if(t.single){if(f=Object.keys(t.commands)[0],!f)i("no command provided");E=t.commands[f]}else{if(f=o[G],E=t.commands[f],!E)m.prefix+=vr(t.commands,m),Co(t,m);G++}let e;try{e=nn({...t.opts,...E.opts},o,{showUsage:!1,usageOpts:m,start:G})}catch(O){Lo(O.message,r)}if(!e)Co(t,m),process.exit(1);if(E.inputs!==void 0&&E.inputs!==e.rest.length)Lo(`expected ${E.inputs||0} input(s)`,r),Co(t,m);let N=await t.ctx({logger:new Jt(process.stderr,t.name,"INFO"),format:n?ut:_o,opts:e.result,inputs:e.rest},E);if(await E.fn(N),t.post)await t.post(N,E)}catch(f){Lo(f.message,r),process.exit(1)}},Co=(t,o)=>{process.stderr.write(Tt(t.opts,o)),process.exit(1)},vr=(t,{color:o,lineWidth:n=80}={})=>{let r=Object.keys(t),m=Math.max(...r.map((E)=>E.length)),f=Kt(o);return[`
|
|
12
12
|
Available commands:
|
|
13
|
-
`,...r.map((E)=>`${
|
|
13
|
+
`,...r.map((E)=>`${Xt(Z(E,f.command),m)} : ${Zt(t[E].desc,m+3,n)}`),`
|
|
14
14
|
`].join(`
|
|
15
|
-
`)},
|
|
15
|
+
`)},Lo=(t,o)=>process.stderr.write(o.red(t)+`
|
|
16
16
|
|
|
17
|
-
`);var
|
|
17
|
+
`);var mn=(t,o,n)=>`
|
|
18
18
|
\u2588 \u2588 \u2588 \u2502
|
|
19
19
|
\u2588\u2588 \u2588 \u2502
|
|
20
20
|
\u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2502 ${t} v${o}
|
|
21
21
|
\u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2502 ${n}
|
|
22
22
|
\u2588 \u2502
|
|
23
|
-
\u2588 \u2588 \u2502`;import{existsSync as
|
|
24
|
-
`):o,"utf-8",n,r);var
|
|
23
|
+
\u2588 \u2588 \u2502`;var A=(t)=>typeof t==="string";var lr=[[process.env.HOME?new RegExp(process.env.HOME,"g"):/~/,"~"]];var pt=(t)=>{for(let[o,n]of lr)t=t.replace(o,n);return t};import{existsSync as dr,mkdirSync as gr,statSync as HE}from"fs";import{dirname as xr}from"path";var ar=(t)=>t.length>0&&!dr(t)?(gr(t,{recursive:!0}),!0):!1,fn=(t)=>ar(xr(t));var P=(t)=>typeof t==="function";import{readFileSync as tm}from"fs";import{writeFileSync as sr}from"fs";var En=(t,o,n,r,m=!1)=>cr(sr,t,o,n,r,m);var cr=(t,o,n,r,m,f=!1)=>{if(m?.info(`${f?"[dryrun] ":""}writing file: ${pt(o)}`),f)return;return fn(o),t(o,n,!r&&A(n)?"utf-8":r)};var F=(t,o,n="utf-8")=>{return o?.debug("reading file:",pt(t)),tm(t,n)};var Bo=(t,o,n,r=!1)=>En(t,u(o)?o.join(`
|
|
24
|
+
`):o,"utf-8",n,r);var X=(t,o)=>JSON.parse(F(t,o));var K=Symbol(),Ao=()=>{};var wt=Object.freeze({level:$.NONE,addChild(t){return t},childLogger:()=>wt,enabled:()=>!1,fine(){},debug(){},info(){},warn(){},severe(){},none(){},logEntry(){}});class $o extends $t{set(t){this.parent=t}childLogger(t,o){return new $o(t,o??this.level,this)}logEntry(t){this.parent.logEntry(t)}}var Gn=new $o("root",$.FINE,wt);import{join as km}from"path";var uo=(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 om=U(()=>"Assertion failed"),Vt=(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 om(typeof o==="function"?o():o)}:()=>{};var qt=(t)=>t!=null&&typeof t!=="function"&&t.length!==void 0;var en=(t)=>{return(t==null||!t[Symbol.iterator])&&i(`value is not iterable: ${t}`),t};var Nn=(t)=>qt(t)?t:[...en(t)];var Ft=(t)=>t[t.length-1];var Qt=(t,o)=>typeof t?.[o]==="function";var T=(t)=>typeof t?.[Symbol.iterator]==="function";var kt=(t)=>t!=null&&typeof t!=="string"&&typeof t[Symbol.iterator]==="function";var nm=U(()=>"illegal arity"),rt=(t)=>{throw new nm(t)};var rm=U(()=>"illegal state"),mt=(t)=>{throw new rm(t)};var On=["-moz-","-ms-","-o-","-webkit-"],ft={rules:"",ruleSep:",",valSep:"",decls:"",declStart:"{",declEnd:"}",indent:"",comments:!1},vt={rules:`
|
|
25
25
|
`,ruleSep:", ",valSep:" ",decls:`
|
|
26
26
|
`,declStart:` {
|
|
27
27
|
`,declEnd:`}
|
|
28
|
-
`,indent:" ",comments:!0};function
|
|
28
|
+
`,indent:" ",comments:!0};function To(...t){let[o,n,r,m,f,E,G,e,N,O]=t;switch(t.length){case 0:rt(0);case 1:return o;case 2:return(...h)=>o(n(...h));case 3:return(...h)=>o(n(r(...h)));case 4:return(...h)=>o(n(r(m(...h))));case 5:return(...h)=>o(n(r(m(f(...h)))));case 6:return(...h)=>o(n(r(m(f(E(...h))))));case 7:return(...h)=>o(n(r(m(f(E(G(...h)))))));case 8:return(...h)=>o(n(r(m(f(E(G(e(...h))))))));case 9:return(...h)=>o(n(r(m(f(E(G(e(N(...h)))))))));case 10:default:let _=(...h)=>o(n(r(m(f(E(G(e(N(O(...h))))))))));return t.length===10?_:To(_,...t.slice(10))}}var d=(t)=>Qt(t,"xform")?t.xform():t;function J(...t){return t=t.map(d),To.apply(null,t)}var p=(t,o)=>[t[0],t[1],o];class St{value;constructor(t){this.value=t}deref(){return this.value}}var S=(t)=>t instanceof St,hn=(t)=>t instanceof St?t:new St(t),z=(t)=>t instanceof St?t.deref():t;var mm=(t)=>t.length===2?[void 0,t[1]]:t.length===3?[t[1],t[2]]:rt(t.length);function Et(...t){let o=t[0],n=o[0],r=o[1],m=o[2];t=mm(t);let f=t[0]==null?n():t[0],E=t[1];return z(r(Qt(E,"$reduce")?E.$reduce(m,f):qt(E)?fm(m,f,E):Em(m,f,E)))}var fm=(t,o,n)=>{for(let r=0,m=n.length;r<m;r++)if(o=t(o,n[r]),S(o)){o=o.deref();break}return o},Em=(t,o,n)=>{for(let r of n)if(o=t(o,r),S(o)){o=o.deref();break}return o},Gt=(t,o)=>[t,At,o],_n=(t,o)=>{let n=o.length-1;return T(o[n])?o.length>1?Et(t.apply(null,o.slice(0,n)),o[n]):Et(t(),o[0]):void 0};function et(t){return t?[...t]:Gt(()=>[],(o,n)=>(o.push(n),o))}function*Nt(t,o){let n=d(t)(et()),r=n[1],m=n[2];for(let f of o){let E=m([],f);if(S(E)){yield*z(r(E.deref()));return}if(E.length)yield*E}yield*z(r([]))}function*g(t,o){let n=d(t)([Ao,Ao,(r,m)=>m])[2];for(let r of o){let m=n(K,r);if(S(m)){if(m=z(m.deref()),m!==K)yield m;return}if(m!==K)yield m}}var lt=(t,o,n=g)=>{let r=o.length-1;return T(o[r])?o.length>1?n(t.apply(null,o.slice(0,r)),o[r]):n(t(),o[0]):void 0};function wo(t,o){return T(o)?Nt(wo(t),A(o)?[o]:o):(n)=>{let r=n[2],m=(f,E)=>{let G=t(E);if(G){for(let e of G)if(f=m(f,e),S(f))break;return f}return r(f,E)};return p(n,m)}}function Cn(t){return wo((o)=>kt(o)?o:void 0,t)}function B(t,o){return T(o)?g(B(t),o):(n)=>{let r=n[2];return p(n,(m,f)=>r(m,t(f)))}}function*dt(...t){let o=t.length-1;if(o<0)return;let n=new Array(o+1).fill(0),r=t.map(Nn),m=r.reduce((f,E)=>f*E.length,1);for(let f=0;f<m;f++){let E=[];for(let G=o;G>=0;G--){let e=r[G],N=n[G];if(N===e.length)n[G]=N=0,G>0&&n[G-1]++;E[G]=e[N]}n[o]++,yield E}}function*Ln(t,o=1/0){while(o-- >0)yield t}function Fo(t,o){t=t||"";let n=!0;return o?[...o].join(t):Gt(()=>"",(r,m)=>(r=n?r+m:r+t+m,n=!1,r))}function gt(...t){return Gm(gt,Et,t)}var Gm=(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 B((f)=>t(n[0],n[1],f));default:rt(n.length)}return o(d(n[0])(n[1]),r,m)};var em=new Set,Nm=":[",Bn=J(Cn(),B((t)=>t[0]==="&"?t.substring(1):Nm.includes(t[0])?t:" "+t)),Om=(t,o)=>J(t,B((n)=>A(n)&&n.startsWith(" .")?n+o:n)),Ot=(t,o,n,r)=>{let m=n.length,f=[],E,G,e=(N,O)=>{let _=null;if(u(O))Ot(t,So(o,f),O,r);else if(T(O)&&!A(O))Ot(t,So(o,f),[...O],r);else if((G=P(O))||(_=r.fns[O]))if(!o.length){if(_)return _.apply(null,n.slice(N+1))(t,r),!0;O(t,r)}else if(G)e(N,O());else i(`quoted fn ('${O}') only allowed at head position`);else if(D(O))E=Object.assign(E||{},O);else if(O!=null)f.push(O)};for(let N=0;N<m;N++)if(e(N,n[N]))return t;return E&&t.push(hm(o,f,E,r)),t},So=(t,o)=>t.length?[...dt(t,o)]:o,hm=(t,o,n,r)=>{let m=r.format,f=j(r),E=r.scope?Om(Bn,r.scope):Bn;return[f,gt(B((G)=>gt(E,Fo(),u(G)?G:[G]).trim()),Fo(m.ruleSep),So(t,o)),m.declStart,Ht(n,r),f,m.declEnd].join("")},Ht=(t,o)=>{let n=o.format,r=o.autoprefix||em,m=j(o,o.depth+1),f=[];for(let E in t)if(t.hasOwnProperty(E)){let G=t[E];if(P(G))G=G(t);if(u(G))G=G.map((e)=>u(e)?e.join(" "):e).join(n.ruleSep);if(r.has(E))for(let e of o.vendors)f.push(`${m}${e}${E}:${n.valSep}${G};`);f.push(`${m}${E}:${n.valSep}${G};`)}return f.join(n.decls)+n.decls},j=(t,o=t.depth)=>o>1?[...Ln(t.format.indent,o)].join(""):o>0?t.format.indent:"";function An(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 E=j(m);r.push(`${f}@keyframes ${t}${m.format.declStart}`);for(let G in n)if(n.hasOwnProperty(G))r.push([E,G+"%",m.format.declStart,Ht(n[G],m),E,m.format.declEnd].join(""));return m.depth--,r.push(f+m.format.declEnd),r}}var $n=(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(`
|
|
29
29
|
`).map((E)=>f+E).join(`
|
|
30
|
-
`),m+"*/");return n};var gt=(t,o,n)=>(r,m)=>{let f=j(m);return r.push(`${f}${t} ${Om(o)}${m.format.declStart}`),m.depth++,ht(r,[],n,m),m.depth--,r.push(f+m.format.declEnd),r},Om=(t)=>{if(T(t))return t;let o=[];for(let n in t)if(t.hasOwnProperty(n)){let r=t[n];if(r===!0)r=Tn.has(n)?n:`(${n})`;else if(r===!1)r=`(not ${Tn.has(n)?n:`(${n})`})`;else if(r==="only")r+=" "+n;else r=`(${n}:${r})`;o.push(r)}return o.join(" and ")},Tn=new Set(["all","print","screen"]);var x=(t,o)=>{return o={format:ft,vendors:On,fns:{},depth:0,...o},i(o.autoprefix)&&(o.autoprefix=new Set(o.autoprefix)),D(t)?Ht(t,o):X(t)?t([],o).join(o.format.rules):ht([],[],i(t)?t:Qt(t)?[...t]:_("invalid rules"),o).join(o.format.rules)};var en=(t,...o)=>(n,r)=>(n.push(o.length?`@import url(${t}) ${o.join(r.format.ruleSep)};`:`@import url(${t});`),n);var Ct=(t,o)=>gt("@media",t,o);function un(...t){return(o,n)=>(o.push(t.length>1?`@namespace ${t[0]} url(${t[1]});`:`@namespace url(${t[0]});`),o)}var Fn=(t,o)=>gt("@supports",t,o);var xt={"@comment":An,"@import":en,"@keyframes":$n,"@media":Ct,"@namespace":un,"@supports":Fn};var wn=4,Sn=(t)=>wn=t,M=(t)=>t===(t|0)?String(t):t.toFixed(wn).replace(/^0./,".").replace(/^-0./,"-.").replace(/0+$/,"");var Hn=(t)=>`${M(t)}em`,In=(t)=>`${M(t)}ex`;var Mn=(t)=>`${M(t)}rem`,So=(t)=>`${M(t)}%`,yn=(t)=>`${M(t)}px`,Wn=(t)=>`${M(t)}vh`,Rn=(t)=>`${M(t)}vw`,Un=(t)=>`${M(t)}vmin`,Yn=(t)=>`${M(t)}vmax`,Dn=(t)=>`${t|0}ms`,zn=(t)=>`${M(t)}s`;var Jn=(t)=>`${M(t)}deg`,jn=(t)=>`${M(t)}rad`,Xn=(t)=>`${M(t)}turn`,Pn=(t)=>`url(${t})`;var F=((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})(F||{});var hm=0,Cm=()=>hm++,a=(t,o)=>!o||!o.id?{...o,id:t+"-"+Cm()}:o;var H=En.childLogger("rstream");class q{constructor(t,o){this.wrapped=t,o=a("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(Nt()))}id;closeIn;closeOut;parent;__owner;xform;cacheLast;last=K;state=F.IDLE;subs=[];deref(){return this.last!==K?this.last:void 0}getState(){return this.state}setState(t){this.state=t}subscribe(t,o={}){this.ensureState();let n;if(t instanceof q&&!o.xform)t.ensureState(),Vt(!t.parent,`sub '${t.id}' already has a parent`),t.parent=this,n=t;else n=new q(t,{...o,parent:this});return this.subs.push(n),this.setState(F.ACTIVE),n.setState(F.ACTIVE),this.last!=K&&n.next(this.last),n}transform(...t){let o,n;if(D(wt(t)))n=t.pop(),o={error:n.error};return this.subscribe(o,a("xform",t.length>0?{...n,xform:z(...t)}:n))}map(t,o){return this.transform(A(t),o||{})}unsubscribe(t){return t?this.unsubscribeChild(t):this.unsubscribeSelf()}unsubscribeSelf(){return H.debug(this.id,"unsub self"),this.parent?.unsubscribe(this),this.state<F.UNSUBSCRIBED&&(this.state=F.UNSUBSCRIBED),this.release(),!0}unsubscribeChild(t){H.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>=F.DONE)return;this.xform?this.dispatchXform(t):this.dispatch(t)}done(){if(H.debug(this.id,"entering done()"),this.state>=F.DONE)return;if(this.xform){if(!this.dispatchXformDone())return}if(this.state=F.DONE,this.dispatchTo("done"))this.state<F.UNSUBSCRIBED&&this.unsubscribe();H.debug(this.id,"exiting done()")}error(t){let n=this.wrapped?.error;return n&&H.debug(this.id,"attempting wrapped error handler"),n?.(t)||this.unhandledError(t)}unhandledError(t){return(H.parent!==Ft?H:console).warn(this.id,"unhandled error:",t),this.unsubscribe(),this.state=F.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){H.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))S(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<F.DONE;n++)this.dispatch(o[n]);return this.state<F.ERROR}ensureState(){if(this.state>=F.DONE)mt(`operation not allowed in state ${F[this.state]}`)}release(){this.subs.length=0,delete this.parent,delete this.xform,delete this.last}}var bn=(t,o)=>{let n=new Zn(o);return n.next(t),n};class Zn extends q{src;_cancel;_inited;constructor(t,o){let[n,r]=X(t)?[t,o||{}]:[void 0,t||{}];super(r.error?{error:r.error}:void 0,a("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){H.debug(this.id,"cancel");let t=this._cancel;delete this._cancel,t()}}}var Kn=(t,o)=>t==="first"||t==="last"&&!o;function Ho(t){return t?Et(Ho(),t):Gt(()=>({}),(o,[n,r])=>(o[n]=r,o))}var Vn=()=>(t)=>{let o=t[2];return V(t,(n,r)=>{if(r){for(let m of J(r)||[])if(n=o(n,m),S(n))break}return S(r)?hn(n):n})};function Io(t,o){return u(o)?Ot(Io(t),o):z(A(t),Vn())}function Mo(t,o){return u(o)?g(Mo(t),o):A(X(t)?(n)=>[t(n),n]:(n)=>[t,n])}function yo(...t){let o=vt(yo,t);if(o)return o;let n=t[0],r=t[1]!==!1;return A((m)=>{let f=r?{}:m;for(let E in m)f[E]=n(m[E]);return f})}var qn=(t)=>t;function Wo(...t){let o=vt(Wo,t,Ot);if(o)return o;let{key:n=qn,mergeOnly:r=!1,reset:m=!0,all:f=!0,backPressure:E=0}=t[1],G=i(t[0])?new Set(t[0]):t[0],N=new Set,O=new Map,h={},L=([C,B,y])=>{let v=!0;if(r||E<1)return[C,($)=>{if(m&&f&&N.size>0||!m&&v)$=y($,h),h={},N.clear(),v=!1;return B($)},($,l)=>{let I=n(l);if(G.has(I)){if(h[I]=l,N.add(I),r||pn(G,N))if($=y($,h),v=!1,m)h={},N.clear();else h={...h}}return $}];else return[C,($)=>{if(f&&N.size>0)$=y($,Qn(O,N)),O.clear(),N.clear();return B($)},($,l)=>{let I=n(l);if(G.has(I)){let b=O.get(I);!b&&O.set(I,b=[]),b.length>=E&&mt(`max back pressure (${E}) exceeded for input: ${String(I)}`),b.push(l),N.add(I);while(pn(G,N))if($=y($,Qn(O,N)),v=!1,S($))break}return $}]};return L.keys=()=>G,L.clear=()=>{O.clear(),G.clear(),N.clear(),h={}},L.add=(C)=>{G.add(C)},L.delete=(C,B=!0)=>{if(O.delete(C),G.delete(C),B)N.delete(C),delete h[C]},L}var pn=(t,o)=>{if(o.size<t.size)return!1;for(let n of t)if(!o.has(n))return!1;return!0},Qn=(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 at=(t)=>new vn(t);class vn extends q{sources;idSources;realSourceIDs;invRealSourceIDs;psync;clean;constructor(t){let o=Wo(new Set,{key:(r)=>r[0],mergeOnly:t.mergeOnly===!0,reset:t.reset===!0,all:t.all!==!1,backPressure:t.backPressure||0}),n=yo((r)=>r[1]);super(void 0,a("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 q?this.add(n[1]):this.next(n),done:()=>this.markDone(t),__owner:this},{xform:Mo(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 H.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){H.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),Kn(this.closeIn,this.sources.size)&&this.done()}}var Ro=R((t,o=" ")=>{let n=ot(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}}),aG=Ro(2,"0"),sG=Ro(3,"0"),ln=Ro(4,"0");var Lm=/\{(\d+)\}/g;var Uo=(t,...o)=>o.length>0?t.replace(Lm,(n,r)=>String(o[parseInt(r,10)])):t;var dn=(t)=>({key:(o)=>o,group:Nt(),...t});function Yo(...t){let o=Cn(Yo,t);if(o)return o;let n=dn(t[0]),[r,m,f]=n.group;return[()=>({}),(E)=>{for(let G in E)E[G]=m(E[G]);return E},(E,G)=>{let N=n.key(G);return E[N]=E[N]?f(E[N],G):f(r(),G),E}]}function Do(t,o){return u(o)?g(Do(t),o):(n)=>{let r=n[2];return V(n,(m,f)=>t(f)?r(m,f):m)}}import{watch as cn}from"fs";import{resolve as s}from"path";var gn={specs:Y({alias:"s",optional:!1,desc:"Path to generated JSON defs"})},st={bundle:W({alias:"b",desc:"Bundle inputs (see `out` option)"})},Lt={include:Yt({alias:"I",desc:"Include CSS files (prepend)"})},ct={eval:Y({alias:"e",desc:"eval meta stylesheet in given string (ignores other inputs & includes)"})},to={force:Yt({alias:"f",hint:"STR",desc:"CSS classes to force include (wildcards are supported, @-prefix will read from file)",delim:","})},xn={media:Yt({alias:"m",hint:"ID",desc:"Media query IDs (use 'ALL' for all)",delim:","})},an={onlyDecls:W({desc:"Only emit framework decls"})},p={out:Y({alias:"o",desc:"Output file (or stdout)"})},oo={prec:Dt({default:3,desc:"Number of fractional digits"})},Q={pretty:W({alias:"p",desc:"Pretty print output"})},_t={noDecls:W({alias:"d",desc:"Don't emit framework decls"})},Bt={noHeader:W({desc:"Don't emit generated header comment"})},$t={scope:Y({desc:"Suffix for CSS class names"})},At={watch:W({alias:"w",desc:"Watch input files for changes"})};import{watch as _m}from"fs";import{resolve as sn}from"path";var k=(t,o,n)=>{o=T(o)?o:o.join(`
|
|
31
|
-
`),t
|
|
32
|
-
`)},no=({info:{name:t,version:o}})=>`/*! ${t} v${o} - generated by thi.ng/meta-css @ ${new Date().toISOString()} */`,It=(t,o)=>{let n=()=>{o.info("closing watchers..."),r.forEach((m)=>m.watcher.close())},r=t.map((m,f)=>{m=sn(m);let E=bn(w(m,o),{id:`in${ln(f)}`});return{input:E,watcher:_m(m,{},(G)=>{if(G==="change")try{E.next(w(m,o))}catch(N){o.warn(N.message),n()}else o.warn("input removed:",m),n()})}});return process.on("SIGINT",n),at({src:Ho(A(({input:m})=>[m.id,m],r))})},ro=(t)=>Object.keys(t).reduce((o,n)=>{if(!n.startsWith("__"))o[n]=t[n];return o},{});var or={desc:"Transpile (and optionally bundle) meta stylesheets to CSS",opts:{...st,...ct,...to,...Lt,..._t,...Bt,...p,...Q,...$t,...gn,...At,noWrite:W({desc:"Don't write files, use stdout only"})},fn:zo};async function zo(t){let o=P(s(t.opts.specs),t.logger),n=em(o,t.opts.force||[],t.logger);if(t.opts.bundle)if(t.opts.watch)await $m(t,n);else yt(t,o,n,t.opts.eval?[t.opts.eval]:t.inputs.map((r)=>w(s(r),t.logger)),t.opts.out);else if(t.opts.watch)await Bm(t,o,n);else if(t.opts.eval)try{yt(t,o,n,[t.opts.eval])}catch(r){t.logger.warn(r.message)}else for(let r of t.inputs)try{r=s(r);let m=!t.opts.noWrite?r.replace(/\.mcss$/,".css"):void 0;yt(t,o,n,[w(r,t.logger)],m)}catch(m){t.logger.warn(m.message)}}var Bm=async(t,o,n)=>{let r=s(t.opts.specs),m,f={process:()=>{try{return o=P(r,t.logger),m.forEach((G)=>G.process()),!0}catch(G){return t.logger.warn(G.message+": "+r),!1}},watcher:cn(r,{},(G)=>{if(G==="change")f.process();else t.logger.warn("specs file removed:",r),E()})},E=()=>{t.logger.info("closing watchers..."),f.watcher.close(),m.forEach((G)=>G.watcher.close())};m=t.inputs.map((G)=>{G=s(G);let N=!t.opts.noWrite?G.replace(/\.mcss$/,".css"):void 0,O=()=>{try{return yt(t,o,n,[w(G,t.logger)],N),!0}catch(h){if(t.logger.warn(h.message+": "+G),m)E();return!1}};if(!O())process.exit(1);return{process:O,watcher:cn(G,{},(h)=>{if(h==="change")O();else t.logger.warn("input removed:",G),E()})}}),t.logger.info("waiting for changes, press ctrl+c to cancel..."),process.on("SIGINT",E)},$m=async(t,o)=>{at({src:{styles:It(t.inputs,t.logger),specs:It([t.opts.specs],t.logger).map((n)=>JSON.parse(Object.values(n)[0]))}}).subscribe({next({styles:n,specs:r}){try{yt(t,r,o,Object.keys(n).sort().map((m)=>n[m]),t.opts.out)}catch(m){t.logger.warn(m.message)}}})},yt=({logger:t,opts:{include:o,noDecls:n,noHeader:r,pretty:m,scope:f}},E,G,N,O)=>{let h={logger:t,specs:E,css:{format:m?kt:ft,fns:xt,scope:f},mediaQueryIDs:new Set(Object.keys(E.media)),mediaQueryRules:{...G.mediaQueryRules},plainRules:{...G.plainRules}},L=o?o.map((C)=>w(s(C),t).trim()):[];if(!r)L.push(no(E));if(!n&&E.decls.length)L.push(x(E.decls,h.css));N.forEach((C)=>im(C,h)),Tm(L,h),Am(L,h),k(O,L,t)},Am=(t,{css:o,logger:n,mediaQueryRules:r,specs:m})=>{for(let f in r){let E=rr(r[f],m);n.debug("mediaquery rules",f,E),t.push(x(Ct(Sm(m.media,f),E),o))}},Tm=(t,{css:o,logger:n,plainRules:r,specs:m})=>{let f=rr(r,m);n.debug("plain rules",f),t.push(x(f,o))},em=(t,o,n)=>{let r=new Set(Object.keys(t.media)),m=new Set(Object.keys(t.classes)),f={},E={};if(o.length&&o[0][0]==="@")o=[...nt(w(s(o[0].substring(1)),n))];for(let G of o){if(!G||G.startsWith("//"))continue;let{token:N,query:O}=mr(G,r),h;if(N.includes("*")){let L=new RegExp(`^${N.replace("*",".*")}$`);h=[...Do((C)=>L.test(C),m)]}else if(m.has(N))h=[N];else{n.warn(`unknown include rule ID: ${G}, skipping...`);continue}for(let L of h)n.debug("including class:",L),O?fr(f,O,`.${L}`,L):Er(E,`.${L}`,L)}return{mediaQueryRules:f,plainRules:E}},im=(t,{specs:o,mediaQueryIDs:n,mediaQueryRules:r,plainRules:m})=>{let f=Wt(),E=Wt(f),G={root:f,curr:E,scopes:[E]};for(let N of nt(t)){if(!N||/^\s*\/\//.test(N))continue;for(let O of um(N)){if(!O)continue;let h=G.curr;switch(h.state){case"sel":case"nest":if(O==="{"){if(h.state==="sel")h.sel=h.sel.map((L)=>L.replace(",","")),h.path=Fm(G.scopes);h.state="class"}else if(O==="}")tr(G);else{let L=wt(h.sel);if(!L||L.endsWith(","))h.sel.push(O);else h.sel[h.sel.length-1]+=" "+O}break;case"class":if(O==="{")h.state="nest",G.scopes.push(G.curr=Wt(h));else if(O==="}")tr(G);else{let{token:L,query:C}=mr(O,n);if(!o.classes[L]&&!(Gr(L)||Or(L)||Nr(L)))_(`unknown class ID: ${L}`);if(C)fr(r,C,h.path,L);else Er(m,h.path,L)}break;default:mt(h.state)}}}};function*um(t){let o=-1,n=t.length,r=0,m=0,f=!1;for(let E=0;E<n;E++){let G=t[E];if(G==='"'&&!(r||m))if(f)yield t.substring(o,E+1),o=-1,f=!1;else f=!0;else if(G===" "||G==="\t"){if(!(r||m||f)&&o>=0)yield t.substring(o,E),o=-1}else if(G==="{"||G==="}"){if(o>=0)yield t.substring(o,E);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=E;m++}else if(G==="]"){if(--m<0)_(`invalid arg nesting in line: '${t}'`)}else if(o<0)o=E}if(f)_("string literals must be fully on a single line");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 Mt=":",nr="///",Wt=(t)=>({state:"sel",sel:t?[]:["<root>"],path:"",parent:t}),tr=(t)=>{let o=!t.curr.sel.length;if(Vt(!!t.curr.parent,"stack underflow"),t.scopes.pop(),t.scopes.length>0){if(t.curr=wt(t.scopes),!o&&t.curr.state==="nest")t.scopes.push(t.curr=Wt(t.curr))}else t.scopes.push(t.curr=Wt(t.root))},Fm=(t)=>t.map((o)=>o.sel.join(",")).join(nr),rr=(t,o)=>Object.entries(t).map(([n,r])=>wm(n,r,o)),wm=(t,o,n)=>{let r=[],m=r,f=t.split(nr);for(let E=0;E<f.length;E++){let G=f[E].split(",");if(E==f.length-1){let N=Object.assign({},...A((O)=>Or(O)?Mm(O):Gr(O)?Hm(O):Nr(O)?Im(n,O):ro(n.classes[O]),o));G.push(N)}m.push(G),m=G}return r[0]},mr=(t,o)=>{if(/^::?/.test(t))return{token:t};let n=t.lastIndexOf(Mt);if(n<0)return{token:t};let r=t.indexOf("("),m=t.indexOf("[");if(r>0||m>0){let G=r>0?m>0?Math.min(r,m):r:m;if(G<n&&t.indexOf(Mt)>G)return{token:t};n=t.substring(0,G).lastIndexOf(Mt)}let f=t.substring(0,n);if(!f.split(Mt).every((G)=>o.has(G)))_(`invalid media query in token: ${t}`);return{token:t.substring(n+1),query:f}},Sm=(t,o)=>o.split(Mt).reduce((n,r)=>Object.assign(n,t[r]),{}),fr=(t,o,n,r)=>{if(!t[o])t[o]={};(t[o][n]||(t[o][n]=new Set)).add(r)},Er=(t,o,n)=>(t[o]||(t[o]=new Set)).add(n),Hm=(t)=>{let o=t.indexOf("="),n=t.substring(0,o),r=t.substring(o+1);return{[`--${n}`]:r[0]==='"'?r.slice(1,-1):r}},Im=(t,o)=>{let n=o.indexOf("("),r=o.substring(0,n),m=o.substring(n+1,o.length-1).split(/(?<!\\),/g).map((E)=>E.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((E,[G,N])=>{if(!G.startsWith("__")){if(G=Uo(G,...m),T(N))N=Uo(N,...m);E[G]=N}return E},{})},Mm=(t)=>{let[o,n,r]=/^(.+)-\[(.+)\]/.exec(t);return{[n]:r}},Gr=(t)=>/^[a-z0-9:_-]+=.+/i.test(t),Nr=(t)=>t.includes("(")&&t.endsWith(")"),Or=(t)=>t.indexOf("-[")>0&&t.endsWith("]");var Cr={deg:Jn,em:Hn,ex:In,ms:Dn,percent:So,px:yn,rad:jn,rem:Mn,second:zn,turn:Xn,url:Pn,vh:Wn,vmax:Yn,vmin:Un,vw:Rn,"%":So},ym={percent:"{0}%",second:"{0}s",url:"url({0})"},Wm={"":[""],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:[""]},Lr={desc:"Generate framework rules from specs",opts:{...p,...oo,...Q,...At},fn:Jo};async function Jo(t){if(t.opts.watch)await Rm(t);else await _r(t.inputs.map((o)=>w(o,t.logger)),t.opts,t.logger)}var Rm=async(t)=>{It(t.inputs,t.logger).subscribe({next(o){try{_r(Object.keys(o).sort().map((n)=>o[n]),t.opts,t.logger)}catch(n){t.logger.warn(n.message)}}})},_r=async(t,o,n)=>{let r={info:{name:"TODO",version:"0.0.0"},media:{},classes:{},templates:{},decls:[]};Sn(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 E of f.specs)try{Br(f,E,r.classes,n)}catch(G){n.warn(`error processing spec: ${E.name}`,G,", skipping...")}if(f.templates)for(let E of f.templates)Um(f,E,r.templates,n)}return k(o.out,JSON.stringify(r,null,o.pretty?4:0),n),r},Br=(t,o,n,r,m=!1)=>{let f=i(o.vars)?o.vars:[""],E=T(o.props)?{[o.props]:"<v>"}:o.props,G=Ym(o,t),N=new Set;for(let O of f){let h=t.vars?.[O]||Wm[O];if(!h)_(`unknown variation ID: ${O}`);for(let[L,C]of lt(h,Object.keys(G))){let B=c(o.name,O,L,C,G[C]),y=o.unit?c(o.unit,O,L,C,G[C]):void 0,v=m?zm(y):Dm(G[C],y);if(!n[B]){if(n[B]={},o.user!=null)n[B].__user=o.user;if(o.doc!=null)n[B].__doc=Jm(o.doc,O,L,C,v)}else if(!N.has(B))_(`duplicate class ID: ${B}`);N.add(B);let $=-1;for(let[l,I]of Object.entries(E)){let b=c(l,O,L,C,G[C]),mo=c(!y||T(I)?String(I):Cr[y](I),O,L,C,v);if(n[B][b]=mo,r.debug(B,b,mo),m)$=hr(mo,hr(b,$))}if(m)n[B].__arity=$+1}}return n},Um=(t,o,n,r)=>Br(t,{...o,values:[""]},n,r,!0),hr=(t,o)=>{let n=/\{(\d+)\}/g,r;while(r=n.exec(t))o=Math.max(o,+r[1]);return o},Ym=(t,o)=>{let n=T(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,E)=>{return m[r(f,E)]=f,m},{})},Dm=(t,o)=>{if(!o||T(t))return t;let n=Cr[o];if(!n)_(`invalid unit: ${o}`);return n(t)},zm=(t)=>t?ym[t]||"{0}"+t:"{0}",c=(t,o,n,r,m)=>t.replace(/<vid>/g,o).replace(/<var>/g,n).replace(/<k>/g,r).replace(/<v>/g,String(m)),Jm=({group:t,desc:o,args:n},r,m,f,E)=>({group:t?c(t,r,m,f,E):"TODO",desc:o?c(o,r,m,f,E):void 0,args:n?n.map((G)=>c(G,r,m,f,E)):void 0});var $r={desc:"Combination of the generate & convert commands",opts:{...st,...ct,...to,...Lt,..._t,...Bt,...oo,...Q,...$t,...At,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((G,N)=>(G[N.endsWith(".json")?0:1].push(N),G),[[],[]]),f={inputs:r,format:t.format,logger:t.logger,opts:{...o,out:o.outSpecs}},E={inputs:m,format:t.format,logger:t.logger,opts:{...o,noWrite:!1,out:o.outCss,scope:o.scope,specs:o.outSpecs}};await Jo(f),await zo(E)}};import{resolve as jm}from"path";var er={desc:"Generate Markdown documentation for framework specs",opts:{...p,level:Dt({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(jm(r[0]),o),f=Xm(m,n);k(n.out,f,o)}},Xm=(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}):`,"",`${tt(o+1)} Classes by category`,"",...Tr(t.classes,bm,o+2),`${tt(o+1)} Templates by category`,"",...Tr(t.templates,Zm,o+2),`${tt(o+1)} Media queries`,"",...Object.entries(t.media).map(([E,G])=>`- **${E}**: \`${JSON.stringify(G)}\``),""];if(n!=="NONE")f.unshift(`${tt(o)} ${n??t.info.name}
|
|
33
|
-
`);return f},Ar=(t)=>t.split(/(\d+)/).map((o)=>{let n=parseInt(o);return isNaN(n)?o:n}),
|
|
30
|
+
`),m+"*/");return n};var xt=(t,o,n)=>(r,m)=>{let f=j(m);return r.push(`${f}${t} ${_m(o)}${m.format.declStart}`),m.depth++,Ot(r,[],n,m),m.depth--,r.push(f+m.format.declEnd),r},_m=(t)=>{if(A(t))return t;let o=[];for(let n in t)if(t.hasOwnProperty(n)){let r=t[n];if(r===!0)r=un.has(n)?n:`(${n})`;else if(r===!1)r=`(not ${un.has(n)?n:`(${n})`})`;else if(r==="only")r+=" "+n;else r=`(${n}:${r})`;o.push(r)}return o.join(" and ")},un=new Set(["all","print","screen"]);var x=(t,o)=>{return o={format:ft,vendors:On,fns:{},depth:0,...o},u(o.autoprefix)&&(o.autoprefix=new Set(o.autoprefix)),D(t)?Ht(t,o):P(t)?t([],o).join(o.format.rules):Ot([],[],u(t)?t:kt(t)?[...t]:i("invalid rules"),o).join(o.format.rules)};var Tn=(t,...o)=>(n,r)=>(n.push(o.length?`@import url(${t}) ${o.join(r.format.ruleSep)};`:`@import url(${t});`),n);var ht=(t,o)=>xt("@media",t,o);function wn(...t){return(o,n)=>(o.push(t.length>1?`@namespace ${t[0]} url(${t[1]});`:`@namespace url(${t[0]});`),o)}var Fn=(t,o)=>xt("@supports",t,o);var at={"@comment":$n,"@import":Tn,"@keyframes":An,"@media":ht,"@namespace":wn,"@supports":Fn};var Sn=4,Hn=(t)=>Sn=t,M=(t)=>t===(t|0)?String(t):t.toFixed(Sn).replace(/^0./,".").replace(/^-0./,"-.").replace(/0+$/,"");var yn=(t)=>`${M(t)}em`,Mn=(t)=>`${M(t)}ex`;var In=(t)=>`${M(t)}rem`,Ho=(t)=>`${M(t)}%`,Rn=(t)=>`${M(t)}px`,Wn=(t)=>`${M(t)}vh`,Un=(t)=>`${M(t)}vw`,Yn=(t)=>`${M(t)}vmin`,Dn=(t)=>`${M(t)}vmax`,Jn=(t)=>`${t|0}ms`,zn=(t)=>`${M(t)}s`;var jn=(t)=>`${M(t)}deg`,Pn=(t)=>`${M(t)}rad`,Xn=(t)=>`${M(t)}turn`,bn=(t)=>`url(${t})`;var w=((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})(w||{});var im=0,Cm=()=>im++,a=(t,o)=>!o||!o.id?{...o,id:t+"-"+Cm()}:o;var H=Gn.childLogger("rstream");class V{constructor(t,o){this.wrapped=t,o=a("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(et()))}id;closeIn;closeOut;parent;__owner;xform;cacheLast;last=K;state=w.IDLE;subs=[];deref(){return this.last!==K?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(),Vt(!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(w.ACTIVE),n.setState(w.ACTIVE),this.last!=K&&n.next(this.last),n}transform(...t){let o,n;if(D(Ft(t)))n=t.pop(),o={error:n.error};return this.subscribe(o,a("xform",t.length>0?{...n,xform:J(...t)}:n))}map(t,o){return this.transform(B(t),o||{})}unsubscribe(t){return t?this.unsubscribeChild(t):this.unsubscribeSelf()}unsubscribeSelf(){return H.debug(this.id,"unsub self"),this.parent?.unsubscribe(this),this.state<w.UNSUBSCRIBED&&(this.state=w.UNSUBSCRIBED),this.release(),!0}unsubscribeChild(t){H.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>=w.DONE)return;this.xform?this.dispatchXform(t):this.dispatch(t)}done(){if(H.debug(this.id,"entering done()"),this.state>=w.DONE)return;if(this.xform){if(!this.dispatchXformDone())return}if(this.state=w.DONE,this.dispatchTo("done"))this.state<w.UNSUBSCRIBED&&this.unsubscribe();H.debug(this.id,"exiting done()")}error(t){let n=this.wrapped?.error;return n&&H.debug(this.id,"attempting wrapped error handler"),n?.(t)||this.unhandledError(t)}unhandledError(t){return(H.parent!==wt?H:console).warn(this.id,"unhandled error:",t),this.unsubscribe(),this.state=w.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){H.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))S(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=z(t);for(let n=0,r=o.length;n<r&&this.state<w.DONE;n++)this.dispatch(o[n]);return this.state<w.ERROR}ensureState(){if(this.state>=w.DONE)mt(`operation not allowed in state ${w[this.state]}`)}release(){this.subs.length=0,delete this.parent,delete this.xform,delete this.last}}var Zn=(t,o)=>{let n=new Kn(o);return n.next(t),n};class Kn extends V{src;_cancel;_inited;constructor(t,o){let[n,r]=P(t)?[t,o||{}]:[void 0,t||{}];super(r.error?{error:r.error}:void 0,a("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){H.debug(this.id,"cancel");let t=this._cancel;delete this._cancel,t()}}}var pn=(t,o)=>t==="first"||t==="last"&&!o;function yo(t){return t?Et(yo(),t):Gt(()=>({}),(o,[n,r])=>(o[n]=r,o))}var Vn=()=>(t)=>{let o=t[2];return p(t,(n,r)=>{if(r){for(let m of z(r)||[])if(n=o(n,m),S(n))break}return S(r)?hn(n):n})};function Mo(t,o){return T(o)?Nt(Mo(t),o):J(B(t),Vn())}function Io(t,o){return T(o)?g(Io(t),o):B(P(t)?(n)=>[t(n),n]:(n)=>[t,n])}function Ro(...t){let o=lt(Ro,t);if(o)return o;let n=t[0],r=t[1]!==!1;return B((m)=>{let f=r?{}:m;for(let E in m)f[E]=n(m[E]);return f})}var qn=(t)=>t;function Wo(...t){let o=lt(Wo,t,Nt);if(o)return o;let{key:n=qn,mergeOnly:r=!1,reset:m=!0,all:f=!0,backPressure:E=0}=t[1],G=u(t[0])?new Set(t[0]):t[0],e=new Set,N=new Map,O={},_=([h,C,I])=>{let v=!0;if(r||E<1)return[h,(L)=>{if(m&&f&&e.size>0||!m&&v)L=I(L,O),O={},e.clear(),v=!1;return C(L)},(L,l)=>{let y=n(l);if(G.has(y)){if(O[y]=l,e.add(y),r||Qn(G,e))if(L=I(L,O),v=!1,m)O={},e.clear();else O={...O}}return L}];else return[h,(L)=>{if(f&&e.size>0)L=I(L,kn(N,e)),N.clear(),e.clear();return C(L)},(L,l)=>{let y=n(l);if(G.has(y)){let b=N.get(y);!b&&N.set(y,b=[]),b.length>=E&&mt(`max back pressure (${E}) exceeded for input: ${String(y)}`),b.push(l),e.add(y);while(Qn(G,e))if(L=I(L,kn(N,e)),v=!1,S(L))break}return L}]};return _.keys=()=>G,_.clear=()=>{N.clear(),G.clear(),e.clear(),O={}},_.add=(h)=>{G.add(h)},_.delete=(h,C=!0)=>{if(N.delete(h),G.delete(h),C)e.delete(h),delete O[h]},_}var Qn=(t,o)=>{if(o.size<t.size)return!1;for(let n of t)if(!o.has(n))return!1;return!0},kn=(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 vn=(t,o)=>{let n=!0;for(let r of o)n=t.removeID(r)&&n;return n};var st=(t)=>new ln(t);class ln extends V{sources;idSources;realSourceIDs;invRealSourceIDs;psync;clean;constructor(t){let o=Wo(new Set,{key:(r)=>r[0],mergeOnly:t.mergeOnly===!0,reset:t.reset===!0,all:t.all!==!1,backPressure:t.backPressure||0}),n=Ro((r)=>r[1]);super(void 0,a("streamsync",{...t,xform:t.xform?J(o,n,t.xform):J(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:Io(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 H.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 vn(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){H.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),pn(this.closeIn,this.sources.size)&&this.done()}}var Uo=W((t,o=" ")=>{let n=ot(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}}),E1=Uo(2,"0"),G1=Uo(3,"0"),dn=Uo(4,"0");var Lm=/\{(\d+)\}/g;var Yo=(t,...o)=>o.length>0?t.replace(Lm,(n,r)=>String(o[parseInt(r,10)])):t;var gn=(t)=>({key:(o)=>o,group:et(),...t});function Do(...t){let o=_n(Do,t);if(o)return o;let n=gn(t[0]),[r,m,f]=n.group;return[()=>({}),(E)=>{for(let G in E)E[G]=m(E[G]);return E},(E,G)=>{let e=n.key(G);return E[e]=E[e]?f(E[e],G):f(r(),G),E}]}function Jo(t,o){return T(o)?g(Jo(t),o):(n)=>{let r=n[2];return p(n,(m,f)=>t(f)?r(m,f):m)}}import{watch as tr}from"fs";import{resolve as s}from"path";var xn={specs:Y({alias:"s",optional:!1,desc:"Path to generated JSON defs"})},ct={bundle:R({alias:"b",desc:"Bundle inputs (see `out` option)"})},_t={include:Yt({alias:"I",desc:"Include CSS files (prepend)"})},to={eval:Y({alias:"e",desc:"eval meta stylesheet in given string (ignores other inputs & includes)"})},oo={force:Yt({alias:"f",hint:"STR",desc:"CSS classes to force include (wildcards are supported, @-prefix will read from file)",delim:","})},an={media:Yt({alias:"m",hint:"ID",desc:"Media query IDs (use 'ALL' for all)",delim:","})},sn={onlyDecls:R({desc:"Only emit framework decls"})},q={out:Y({alias:"o",desc:"Output file (or stdout)"})},no={prec:Dt({default:3,desc:"Number of fractional digits"})},Q={pretty:R({alias:"p",desc:"Pretty print output"})},it={noDecls:R({alias:"d",desc:"Don't emit framework decls"})},Ct={noHeader:R({desc:"Don't emit generated header comment"})},Lt={scope:Y({desc:"Suffix for CSS class names"})},Bt={watch:R({alias:"w",desc:"Watch input files for changes"})};import{watch as Bm}from"fs";import{resolve as cn}from"path";var k=(t,o,n)=>{o=A(o)?o:o.join(`
|
|
31
|
+
`),t?Bo(cn(t),o,n):process.stdout.write(o+`
|
|
32
|
+
`)},ro=({info:{name:t,version:o}})=>`/*! ${t} v${o} - generated by thi.ng/meta-css @ ${new Date().toISOString()} */`,yt=(t,o)=>{let n=()=>{o.info("closing watchers..."),r.forEach((m)=>m.watcher.close())},r=t.map((m,f)=>{m=cn(m);let E=Zn(F(m,o),{id:`in${dn(f)}`});return{input:E,watcher:Bm(m,{},(G)=>{if(G==="change")try{E.next(F(m,o))}catch(e){o.warn(e.message),n()}else o.warn("input removed:",m),n()})}});return process.on("SIGINT",n),st({src:yo(B(({input:m})=>[m.id,m],r))})},mo=(t)=>Object.keys(t).reduce((o,n)=>{if(!n.startsWith("__"))o[n]=t[n];return o},{});var nr={desc:"Transpile (and optionally bundle) meta stylesheets to CSS",opts:{...ct,...to,...oo,..._t,...it,...Ct,...q,...Q,...Lt,...xn,...Bt,noWrite:R({desc:"Don't write files, use stdout only"})},fn:zo};async function zo(t){let o=X(s(t.opts.specs),t.logger),n=wm(o,t.opts.force||[],t.logger);if(t.opts.bundle)if(t.opts.watch)await $m(t,n);else It(t,o,n,t.opts.eval?[t.opts.eval]:t.inputs.map((r)=>F(s(r),t.logger)),t.opts.out);else if(t.opts.watch)await Am(t,o,n);else if(t.opts.eval)try{It(t,o,n,[t.opts.eval])}catch(r){t.logger.warn(r.message)}else for(let r of t.inputs)try{r=s(r);let m=!t.opts.noWrite?r.replace(/\.mcss$/,".css"):void 0;It(t,o,n,[F(r,t.logger)],m)}catch(m){t.logger.warn(m.message)}}var Am=async(t,o,n)=>{let r=s(t.opts.specs),m,f={process:()=>{try{return o=X(r,t.logger),m.forEach((G)=>G.process()),!0}catch(G){return t.logger.warn(G.message+": "+r),!1}},watcher:tr(r,{},(G)=>{if(G==="change")f.process();else t.logger.warn("specs file removed:",r),E()})},E=()=>{t.logger.info("closing watchers..."),f.watcher.close(),m.forEach((G)=>G.watcher.close())};m=t.inputs.map((G)=>{G=s(G);let e=!t.opts.noWrite?G.replace(/\.mcss$/,".css"):void 0,N=()=>{try{return It(t,o,n,[F(G,t.logger)],e),!0}catch(O){if(t.logger.warn(O.message+": "+G),m)E();return!1}};if(!N())process.exit(1);return{process:N,watcher:tr(G,{},(O)=>{if(O==="change")N();else t.logger.warn("input removed:",G),E()})}}),t.logger.info("waiting for changes, press ctrl+c to cancel..."),process.on("SIGINT",E)},$m=async(t,o)=>{st({src:{styles:yt(t.inputs,t.logger),specs:yt([t.opts.specs],t.logger).map((n)=>JSON.parse(Object.values(n)[0]))}}).subscribe({next({styles:n,specs:r}){try{It(t,r,o,Object.keys(n).sort().map((m)=>n[m]),t.opts.out)}catch(m){t.logger.warn(m.message)}}})},It=({logger:t,opts:{include:o,noDecls:n,noHeader:r,pretty:m,scope:f}},E,G,e,N)=>{let O={logger:t,specs:E,css:{format:m?vt:ft,fns:at,scope:f},mediaQueryIDs:new Set(Object.keys(E.media)),mediaQueryRules:{...G.mediaQueryRules},plainRules:{...G.plainRules}},_=o?o.map((h)=>F(s(h),t).trim()):[];if(!r)_.push(ro(E));if(!n&&E.decls.length)_.push(x(E.decls,O.css));e.forEach((h)=>Fm(h,O)),Tm(_,O),um(_,O),k(N,_,t)},um=(t,{css:o,logger:n,mediaQueryRules:r,specs:m})=>{for(let f in r){let E=mr(r[f],m);n.debug("mediaquery rules",f,E),t.push(x(ht(Mm(m.media,f),E),o))}},Tm=(t,{css:o,logger:n,plainRules:r,specs:m})=>{let f=mr(r,m);n.debug("plain rules",f),t.push(x(f,o))},wm=(t,o,n)=>{let r=new Set(Object.keys(t.media)),m=new Set(Object.keys(t.classes)),f={},E={};if(o.length&&o[0][0]==="@")o=[...nt(F(s(o[0].substring(1)),n))];for(let G of o){if(!G||G.startsWith("//"))continue;let{token:e,query:N}=fr(G,r),O;if(e.includes("*")){let _=new RegExp(`^${e.replace("*",".*")}$`);O=[...Jo((h)=>_.test(h),m)]}else if(m.has(e))O=[e];else{n.warn(`unknown include rule ID: ${G}, skipping...`);continue}for(let _ of O)n.debug("including class:",_),N?Er(f,N,`.${_}`,_):Gr(E,`.${_}`,_)}return{mediaQueryRules:f,plainRules:E}},Fm=(t,{specs:o,mediaQueryIDs:n,mediaQueryRules:r,plainRules:m})=>{let f=Rt(),E=Rt(f),G={root:f,curr:E,scopes:[E]};for(let e of nt(t)){if(!e||/^\s*\/\//.test(e))continue;for(let N of Sm(e)){if(!N)continue;let O=G.curr;switch(O.state){case"sel":case"nest":if(N==="{"){if(O.state==="sel")O.sel=O.sel.map((_)=>_.replace(",","")),O.path=Hm(G.scopes);O.state="class"}else if(N==="}")or(G);else{let _=Ft(O.sel);if(!_||_.endsWith(","))O.sel.push(N);else O.sel[O.sel.length-1]+=" "+N}break;case"class":if(N==="{")O.state="nest",G.scopes.push(G.curr=Rt(O));else if(N==="}")or(G);else{let{token:_,query:h}=fr(N,n);if(!o.classes[_]&&!(er(_)||Or(_)||Nr(_)))i(`unknown class ID: ${_}`);if(h)Er(r,h,O.path,_);else Gr(m,O.path,_)}break;default:mt(O.state)}}}};function*Sm(t){let o=-1,n=t.length,r=0,m=0,f=!1;for(let E=0;E<n;E++){let G=t[E];if(G==='"'&&!(r||m))if(f)yield t.substring(o,E+1),o=-1,f=!1;else f=!0;else if(G===" "||G==="\t"){if(!(r||m||f)&&o>=0)yield t.substring(o,E),o=-1}else if(G==="{"||G==="}"){if(o>=0)yield t.substring(o,E);yield G,o=-1}else if(G==="(")r++;else if(G===")"){if(--r<0)i(`invalid nesting in line: '${t}'`)}else if(G==="["){if(o<0)o=E;m++}else if(G==="]"){if(--m<0)i(`invalid arg nesting in line: '${t}'`)}else if(o<0)o=E}if(f)i("string literals must be fully on a single line");if(r)i("template calls must be fully on a single line");if(m)i("verbatim properties must be fully on a single line");if(o>=0)yield t.substring(o,n)}var Mt=":",rr="///",Rt=(t)=>({state:"sel",sel:t?[]:["<root>"],path:"",parent:t}),or=(t)=>{let o=!t.curr.sel.length;if(Vt(!!t.curr.parent,"stack underflow"),t.scopes.pop(),t.scopes.length>0){if(t.curr=Ft(t.scopes),!o&&t.curr.state==="nest")t.scopes.push(t.curr=Rt(t.curr))}else t.scopes.push(t.curr=Rt(t.root))},Hm=(t)=>t.map((o)=>o.sel.join(",")).join(rr),mr=(t,o)=>Object.entries(t).map(([n,r])=>ym(n,r,o)),ym=(t,o,n)=>{let r=[],m=r,f=t.split(rr);for(let E=0;E<f.length;E++){let G=f[E].split(",");if(E==f.length-1){let e=Object.assign({},...B((N)=>Or(N)?Wm(N):er(N)?Im(N):Nr(N)?Rm(n,N):mo(n.classes[N]),o));G.push(e)}m.push(G),m=G}return r[0]},fr=(t,o)=>{if(/^::?/.test(t))return{token:t};let n=t.lastIndexOf(Mt);if(n<0)return{token:t};let r=t.indexOf("("),m=t.indexOf("[");if(r>0||m>0){let G=r>0?m>0?Math.min(r,m):r:m;if(G<n&&t.indexOf(Mt)>G)return{token:t};n=t.substring(0,G).lastIndexOf(Mt)}let f=t.substring(0,n);if(!f.split(Mt).every((G)=>o.has(G)))i(`invalid media query in token: ${t}`);return{token:t.substring(n+1),query:f}},Mm=(t,o)=>o.split(Mt).reduce((n,r)=>Object.assign(n,t[r]),{}),Er=(t,o,n,r)=>{if(!t[o])t[o]={};(t[o][n]||(t[o][n]=new Set)).add(r)},Gr=(t,o,n)=>(t[o]||(t[o]=new Set)).add(n),Im=(t)=>{let o=t.indexOf("="),n=t.substring(0,o),r=t.substring(o+1);return{[`--${n}`]:r[0]==='"'?r.slice(1,-1):r}},Rm=(t,o)=>{let n=o.indexOf("("),r=o.substring(0,n),m=o.substring(n+1,o.length-1).split(/(?<!\\),/g).map((E)=>E.trim().replace("\\,",",")),f=t.templates[r];if(!f)i(`unknown template: ${r}`);if(m.length!==f.__arity)i(`template "${r}" expected ${f.__arity} arguments`);return Object.entries(f).reduce((E,[G,e])=>{if(!G.startsWith("__")){if(G=Yo(G,...m),A(e))e=Yo(e,...m);E[G]=e}return E},{})},Wm=(t)=>{let[o,n,r]=/^(.+)-\[(.+)\]/.exec(t);return{[n]:r}},er=(t)=>/^[a-z0-9:_-]+=.+/i.test(t),Nr=(t)=>t.includes("(")&&t.endsWith(")"),Or=(t)=>t.indexOf("-[")>0&&t.endsWith("]");var _r={deg:jn,em:yn,ex:Mn,ms:Jn,percent:Ho,px:Rn,rad:Pn,rem:In,second:zn,turn:Xn,url:bn,vh:Wn,vmax:Dn,vmin:Yn,vw:Un,"%":Ho},Um={percent:"{0}%",second:"{0}s",url:"url({0})"},Ym={"":[""],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:[""]},ir={desc:"Generate framework rules from specs",opts:{...q,...no,...Q,...Bt},fn:jo};async function jo(t){if(t.opts.watch)await Dm(t);else await Cr(t.inputs.map((o)=>F(o,t.logger)),t.opts,t.logger)}var Dm=async(t)=>{yt(t.inputs,t.logger).subscribe({next(o){try{Cr(Object.keys(o).sort().map((n)=>o[n]),t.opts,t.logger)}catch(n){t.logger.warn(n.message)}}})},Cr=async(t,o,n)=>{let r={info:{name:"TODO",version:"0.0.0"},media:{},classes:{},templates:{},decls:[]};Hn(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 E of f.specs)try{Lr(f,E,r.classes,n)}catch(G){n.warn(`error processing spec: ${E.name}`,G,", skipping...")}if(f.templates)for(let E of f.templates)Jm(f,E,r.templates,n)}return k(o.out,JSON.stringify(r,null,o.pretty?4:0),n),r},Lr=(t,o,n,r,m=!1)=>{let f=u(o.vars)?o.vars:[""],E=A(o.props)?{[o.props]:"<v>"}:o.props,G=zm(o,t),e=new Set;for(let N of f){let O=t.vars?.[N]||Ym[N];if(!O)i(`unknown variation ID: ${N}`);for(let[_,h]of dt(O,Object.keys(G))){let C=c(o.name,N,_,h,G[h]),I=o.unit?c(o.unit,N,_,h,G[h]):void 0,v=m?Pm(I):jm(G[h],I);if(!n[C]){if(n[C]={},o.user!=null)n[C].__user=o.user;if(o.doc!=null)n[C].__doc=Xm(o.doc,N,_,h,v)}else if(!e.has(C))i(`duplicate class ID: ${C}`);e.add(C);let L=-1;for(let[l,y]of Object.entries(E)){let b=c(l,N,_,h,G[h]),fo=c(!I||A(y)?String(y):_r[I](y),N,_,h,v);if(n[C][b]=fo,r.debug(C,b,fo),m)L=hr(fo,hr(b,L))}if(m)n[C].__arity=L+1}}return n},Jm=(t,o,n,r)=>Lr(t,{...o,values:[""]},n,r,!0),hr=(t,o)=>{let n=/\{(\d+)\}/g,r;while(r=n.exec(t))o=Math.max(o,+r[1]);return o},zm=(t,o)=>{let n=A(t.values)?o.tables?.[t.values]||i(`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):i(`invalid key type: ${t.key}`);return n.reduce((m,f,E)=>{return m[r(f,E)]=f,m},{})},jm=(t,o)=>{if(!o||A(t))return t;let n=_r[o];if(!n)i(`invalid unit: ${o}`);return n(t)},Pm=(t)=>t?Um[t]||"{0}"+t:"{0}",c=(t,o,n,r,m)=>t.replace(/<vid>/g,o).replace(/<var>/g,n).replace(/<k>/g,r).replace(/<v>/g,String(m)),Xm=({group:t,desc:o,args:n},r,m,f,E)=>({group:t?c(t,r,m,f,E):"TODO",desc:o?c(o,r,m,f,E):void 0,args:n?n.map((G)=>c(G,r,m,f,E)):void 0});var Br={desc:"Combination of the generate & convert commands",opts:{...ct,...to,...oo,..._t,...it,...Ct,...no,...Q,...Lt,...Bt,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((G,e)=>(G[e.endsWith(".json")?0:1].push(e),G),[[],[]]),f={inputs:r,format:t.format,logger:t.logger,opts:{...o,out:o.outSpecs}},E={inputs:m,format:t.format,logger:t.logger,opts:{...o,noWrite:!1,out:o.outCss,scope:o.scope,specs:o.outSpecs}};await jo(f),await zo(E)}};import{resolve as bm}from"path";var ur={desc:"Generate Markdown documentation for framework specs",opts:{...q,level:Dt({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=X(bm(r[0]),o),f=Zm(m,n);k(n.out,f,o)}},Zm=(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}):`,"",`${tt(o+1)} Classes by category`,"",...$r(t.classes,pm,o+2),`${tt(o+1)} Templates by category`,"",...$r(t.templates,Vm,o+2),`${tt(o+1)} Media queries`,"",...Object.entries(t.media).map(([E,G])=>`- **${E}**: \`${JSON.stringify(G)}\``),""];if(n!=="NONE")f.unshift(`${tt(o)} ${n??t.info.name}
|
|
33
|
+
`);return f},Ar=(t)=>t.split(/(\d+)/).map((o)=>{let n=parseInt(o);return isNaN(n)?o:n}),Km=(t,o)=>{if(/\d+/.test(t)&&/\d+/.test(o)){let n=Ar(t),r=Ar(o),m=n.length;if(m===r.length){for(let f=0;f<m;f++)if(n[f]!==r[f])return uo(n[f],r[f]);return 0}return n.length-r.length}return uo(t,o)},$r=(t,o,n)=>{let r=Do({key:([m,{__doc:f}])=>f?.group||"TODO",group:[()=>[],(m)=>m.sort(),(m,f)=>(m.push(f[0]),m)]},Object.entries(t));return Mo((m)=>{let f=r[m].sort(Km).map((G)=>o(G,t[G].__doc,n+1)),E=f.length;return[`${tt(n)} ${jt(m)}`,E>3?`
|
|
34
34
|
<details><summary>${E} items:</summary>
|
|
35
35
|
`:"",f.join(`
|
|
36
36
|
`),E>3?`</details>
|
|
37
|
-
`:""]},Object.keys(r).sort())},
|
|
37
|
+
`:""]},Object.keys(r).sort())},pm=(t,o)=>{if(!o?.desc)return`- \`${t}\``;let n=o.desc;if(/^-[a-z]/.test(n))n=n.substring(1);return`- \`${t}\` (${n})`},Vm=(t,o,n)=>{if(!o?.args)return`${tt(n)} ${t}(...)
|
|
38
38
|
|
|
39
|
-
TODO`;let r=o.args.map((m)=>/^\w+/.exec(m)[0]).join(", ");return[`${tt(n)} \`${t}(${r})\``,"",...o.args.map(
|
|
39
|
+
TODO`;let r=o.args.map((m)=>/^\w+/.exec(m)[0]).join(", ");return[`${tt(n)} \`${t}(${r})\``,"",...o.args.map(qm),o.desc?`
|
|
40
40
|
${o.desc}
|
|
41
41
|
`:""].join(`
|
|
42
|
-
`)},
|
|
42
|
+
`)},qm=(t)=>`- ${t.replace(/^(\w+)/,(o,n)=>`**${n}**`)}`,tt=W((t)=>"#".repeat(t));import{resolve as Tr}from"path";var Fr={desc:"Export entire generated framework as CSS",opts:{..._t,...it,...sn,...q,...Q,...Ct,...an,...Lt},inputs:1,fn:async(t)=>{let{logger:o,opts:{include:n,media:r,noDecls:m,noHeader:f,onlyDecls:E,out:G,pretty:e,scope:N},inputs:O}=t,_={format:e?vt:ft,fns:at,scope:N},h=X(Tr(O[0]),o),C=n?n.map((I)=>F(Tr(I),o).trim()):[];if(!f)C.push(ro(h));if(!m&&h.decls.length)C.push(x(h.decls,_));if(!E)C.push(Qm(h,r,_,o));k(G,C,o)}},Qm=(t,o,n,r)=>{let m=wr("",t);if(o){let f=o[0]==="ALL"?Object.keys(t.media):o;for(let E of f)if(t.media[E])m.push(ht(t.media[E],wr("-"+E,t)));else r.warn(`invalid media query ID: ${E}, skipping...`)}return x(m,n)},wr=(t,o)=>Object.entries(o.classes).map(([n,r])=>[`.${n}${t}`,mo(r)]);var Po=X(km(process.argv[2],"package.json"));rn({name:"metacss",start:3,opts:{verbose:R({alias:"v",desc:"Display extra process information"})},commands:{convert:nr,develop:Br,doc:ur,export:Fr,generate:ir},ctx:async(t)=>{if(t.opts.verbose)t.logger.level=$.DEBUG;return{...t,format:ut}},usage:{prefix:`${mn(Po.name,Po.version,Po.description)}
|
|
43
43
|
|
|
44
44
|
Usage: metacss <cmd> [opts] input [...]
|
|
45
45
|
metacss <cmd> --help
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/meta-css",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.7",
|
|
4
4
|
"description": "Data-driven CSS framework codegen, transpiler & bundler",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -44,25 +44,25 @@
|
|
|
44
44
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@thi.ng/api": "^8.11.
|
|
48
|
-
"@thi.ng/args": "^2.6.
|
|
49
|
-
"@thi.ng/arrays": "^2.13.
|
|
50
|
-
"@thi.ng/checks": "^3.7.
|
|
51
|
-
"@thi.ng/compare": "^2.4.
|
|
52
|
-
"@thi.ng/errors": "^2.5.
|
|
53
|
-
"@thi.ng/file-io": "^2.2.
|
|
54
|
-
"@thi.ng/hiccup-css": "^2.7.
|
|
55
|
-
"@thi.ng/logger": "^3.1.
|
|
56
|
-
"@thi.ng/memoize": "^4.0.
|
|
57
|
-
"@thi.ng/rstream": "^9.2.
|
|
58
|
-
"@thi.ng/strings": "^3.9.
|
|
59
|
-
"@thi.ng/text-format": "^2.2.
|
|
60
|
-
"@thi.ng/transducers": "^9.
|
|
47
|
+
"@thi.ng/api": "^8.11.30",
|
|
48
|
+
"@thi.ng/args": "^2.6.4",
|
|
49
|
+
"@thi.ng/arrays": "^2.13.2",
|
|
50
|
+
"@thi.ng/checks": "^3.7.10",
|
|
51
|
+
"@thi.ng/compare": "^2.4.22",
|
|
52
|
+
"@thi.ng/errors": "^2.5.36",
|
|
53
|
+
"@thi.ng/file-io": "^2.2.1",
|
|
54
|
+
"@thi.ng/hiccup-css": "^2.7.54",
|
|
55
|
+
"@thi.ng/logger": "^3.1.11",
|
|
56
|
+
"@thi.ng/memoize": "^4.0.20",
|
|
57
|
+
"@thi.ng/rstream": "^9.2.28",
|
|
58
|
+
"@thi.ng/strings": "^3.9.16",
|
|
59
|
+
"@thi.ng/text-format": "^2.2.35",
|
|
60
|
+
"@thi.ng/transducers": "^9.5.1"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@types/node": "^
|
|
64
|
-
"esbuild": "^0.25.
|
|
65
|
-
"typedoc": "^0.28.
|
|
63
|
+
"@types/node": "^24.0.12",
|
|
64
|
+
"esbuild": "^0.25.6",
|
|
65
|
+
"typedoc": "^0.28.7",
|
|
66
66
|
"typescript": "^5.8.3"
|
|
67
67
|
},
|
|
68
68
|
"keywords": [
|
|
@@ -113,5 +113,5 @@
|
|
|
113
113
|
"status": "alpha",
|
|
114
114
|
"year": 2023
|
|
115
115
|
},
|
|
116
|
-
"gitHead": "
|
|
116
|
+
"gitHead": "56d8f088389b22192a06e9a395b5eecebf47697a\n"
|
|
117
117
|
}
|