@thi.ng/meta-css 0.19.7 → 0.19.8
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/index.js +19 -19
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var Eo={default:95,command:92,hint:90,multi:90,param:96,required:33};var
|
|
3
|
-
`),this.parent?.logEntry(t)}}var
|
|
4
|
-
`};var
|
|
5
|
-
`,start:()=>"",end:""};var
|
|
6
|
-
`)},
|
|
2
|
+
var Eo={default:95,command:92,error:91,hint:90,multi:90,param:96,required:33};var $t=(t)=>t;function U(t,o=Object.create(null)){return(...n)=>{let r=n.join("-");return r in o?o[r]:o[r]=t(...n)}}var nt=U((t,o)=>t.repeat(o));var zo=(t)=>/^[a-f0-9]+$/i.test(t);var Po=(t)=>/^[-+]?\d+$/.test(t),jo=(t)=>/^[-+]?\d*\.?\d+(e[-+]?\d+)?$/i.test(t);var Y=(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=Y(()=>"illegal argument(s)"),L=(t)=>{throw new Sr(t)};var Go=(t)=>jo(t)?parseFloat(t):L(`not a numeric value: ${t}`),Xo=(t)=>t.map(Go),No=(t)=>zo(t)?parseInt(t,16):L(`not a hex value: ${t}`),Zo=(t)=>t.map(No),Oo=(t)=>Po(t)?parseInt(t):L(`not an integer: ${t}`),bo=(t)=>t.map(Oo);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}),D=Wt($t,"STR"),Yt=Ut($t,"STR"),Lf=Wt(Go,"NUM"),_f=Wt(No,"HEX"),Dt=Wt(Oo,"INT"),Bf=Ut(Xo,"NUM"),Af=Ut(Zo,"HEX"),$f=Ut(bo,"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 ut{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 Ko=(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 ut{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]}: ${Ko(t.slice(3))}
|
|
3
|
+
`),this.parent?.logEntry(t)}}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 Mr=(t,o)=>(n)=>t.format(o,n),ho=(t)=>Object.keys(eo).reduce((o,n)=>(o[n]=Mr(t,eo[n]),o),{format:t});var po="\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:U((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:po,prefix:po,suffix:`
|
|
4
|
+
`};var Vo={format:(t,o)=>String(o),prefix:"",suffix:`
|
|
5
|
+
`,start:()=>"",end:""};var Pt=ho(zt),qo=ho(Vo);var u=Array.isArray;var Rr=(t)=>t.toUpperCase(),Qo=(t)=>t.toLowerCase(),jt=(t)=>t.length?t[0].toUpperCase()+t.substring(1):t,ko=(t,o="-")=>Qo(t.replace(/([a-z0-9\u00e0-\u00fd])([A-Z\u00c0-\u00dd])/g,(n,r,m)=>r+o+m));var vo=(t,o="-")=>Qo(t).replace(new RegExp(`\\${o}+(\\w)`,"g"),(n,r)=>Rr(r));var lo=(t=!1,o)=>(n)=>t||typeof n!=="string"&&typeof n!=="number"?JSON.stringify(n,null,o):String(n);var go=Object.getPrototypeOf,J=(t)=>{let o;return t!=null&&typeof t==="object"&&((o=go(t))===null||go(o)===null)};var Wr=/\x1b\[[0-9;]+m/g,Ur=(t)=>t.replace(Wr,"");var Xt=(t)=>Ur(t).length;var xo=U((t,o=" ")=>{let n=nt(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}});function*rt(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 N=G[0].length;yield t.substring(r,G.index+f*N),r=G.index+N}}class Co{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},so={length:Xt,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}},ao=(t,o,n,r)=>{let m=t[t.length-1];m&&r-m.n>n?m.add(o,n):t.push(new Co(o,n))},Dr=(t,{width:o,min:n,hard:r,splitter:m},f=0,E=[])=>{let G=m.length(t),N=o-f;if(N<n&&N<G)N=o;while(r&&G>N){let O=m.split(t,N),e=t.substring(0,O);ao(E,e,N,o),t=t.substring(O),N=o,G=m.length(t)}return ao(E,t,G,o),E},Jr=(t,o,n=[])=>{if(!t.length)return n.push(new Co),n;let r={width:80,min:4,hard:!1,splitter:Yr,...o};for(let m of rt(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},co=(t,o)=>{let n=[];for(let r of rt(t,o.delimLine))n=n.concat(Jr(r,o));return n};var W=(t,o)=>o!=null?`\x1B[${o}m${t}\x1B[0m`:t,Zt=(t,o)=>xo(o)(t,Xt(t)),bt=(t,o)=>t?co(t,{width:o,splitter:so,hard:!1}):[],Kt=(t,o,n)=>{let r=nt(" ",o);return bt(t,n-o).map((m,f)=>f?r+m:m).join(`
|
|
6
|
+
`)},d=(t)=>J(t)?{...Eo,...t}:t?Eo:{};var Tt=(t,o={})=>{o={lineWidth:80,paramWidth:32,showDefaults:!0,prefix:"",suffix:"",groups:["flags","main"],...o};let n=d(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=Pr(o,r),E=jr(o,r,f),G=W(`--${ko(t)}`,r.param),N=`${E}${G}${f}`,O=o.optional===!1&&o.default===void 0,e=[];O&&e.push("required"),o.multi&&e.push("multiple");let C=Xr(e,r,O)+(o.desc||"")+Zr(o,n,r);return Zt(N,n.paramWidth)+Kt(C,m,n.lineWidth)},Pr=(t,o)=>t.hint?W(" "+t.hint,o.hint):"",jr=(t,o,n)=>t.alias?`${W("-"+t.alias,o.param)}${n}, `:"",Xr=(t,o,n)=>t.length?W(`[${t.join(", ")}] `,n?o.required:o.multi):"",Zr=(t,o,n)=>o.showDefaults&&t.default!=null&&t.default!==!1?W(` (default: ${lo(!0)(t.defaultHint!=null?t.defaultHint:t.default)})`,n.default):"";var br=Y(()=>"parse error"),tn=(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(W(r.message,d(n.usageOpts?.color).error)+`
|
|
10
10
|
|
|
11
|
-
`+Tt(t,n.usageOpts));throw new
|
|
11
|
+
`+Tt(t,n.usageOpts));throw new br(r.message)}},Kr=(t,o,n)=>{let r=pr(t),m={},f,E,G=n.start;for(;G<o.length;){let N=o[G];if(!f){if(n.help.includes(N)){console.log(Tt(t,n.usageOpts));return}let O=Vr(t,r,m,N);if(f=O.id,E=O.spec,G=G+~~(O.state<2),O.state)break}else{if(qr(E,m,f,N))break;f=null,G++}}return f&&L(`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=vo(r.substring(2))}else m=o[r.substring(1)],!m&&L(`unknown option: ${r}`);let f=t[m];if(!f&&L(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)L(`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=d(n),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)L("no command provided");E=t.commands[f]}else{if(f=o[G],E=t.commands[f],!E)m.prefix+=vr(t.commands,m),on(t,m);G++}let N;try{N=tn({...t.opts,...E.opts},o,{usageOpts:m,start:G})}catch(e){process.exit(1)}if(!N)process.exit(0);if(E.inputs!==void 0&&E.inputs!==N.rest.length)nn(`expected ${E.inputs||0} input(s)`,r),on(t,m);let O=await t.ctx({logger:new Jt(process.stderr,t.name,"INFO"),format:n?Pt:qo,opts:N.result,inputs:N.rest},E);if(await E.fn(O),t.post)await t.post(O,E)}catch(f){nn(f.message,r),process.exit(1)}},on=(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=d(o);return[`
|
|
12
12
|
Available commands:
|
|
13
|
-
`,...r.map((E)=>`${
|
|
13
|
+
`,...r.map((E)=>`${Zt(W(E,f.command),m)} : ${Kt(t[E].desc,m+3,n)}`),`
|
|
14
14
|
`].join(`
|
|
15
|
-
`)},
|
|
15
|
+
`)},nn=(t,o)=>process.stderr.write(W(t,o.error)+`
|
|
16
16
|
|
|
17
17
|
`);var mn=(t,o,n)=>`
|
|
18
18
|
\u2588 \u2588 \u2588 \u2502
|
|
@@ -20,26 +20,26 @@ Available commands:
|
|
|
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`;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
|
|
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 yE}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 X=(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 Lo=(t,o,n,r=!1)=>En(t,u(o)?o.join(`
|
|
24
|
+
`):o,"utf-8",n,r);var Z=(t,o)=>JSON.parse(F(t,o));var K=Symbol(),_o=()=>{};var wt=Object.freeze({level:$.NONE,addChild(t){return t},childLogger:()=>wt,enabled:()=>!1,fine(){},debug(){},info(){},warn(){},severe(){},none(){},logEntry(){}});class io extends ut{set(t){this.parent=t}childLogger(t,o){return new io(t,o??this.level,this)}logEntry(t){this.parent.logEntry(t)}}var Gn=new io("root",$.FINE,wt);import{join as km}from"path";var Bo=(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=Y(()=>"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 Nn=(t)=>{return(t==null||!t[Symbol.iterator])&&L(`value is not iterable: ${t}`),t};var On=(t)=>qt(t)?t:[...Nn(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=Y(()=>"illegal arity"),mt=(t)=>{throw new nm(t)};var rm=Y(()=>"illegal state"),ft=(t)=>{throw new rm(t)};var en=["-moz-","-ms-","-o-","-webkit-"],Et={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 Ao(...t){let[o,n,r,m,f,E,G,N,O,e]=t;switch(t.length){case 0:mt(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(N(...h))))))));case 9:return(...h)=>o(n(r(m(f(E(G(N(O(...h)))))))));case 10:default:let C=(...h)=>o(n(r(m(f(E(G(N(O(e(...h))))))))));return t.length===10?C:Ao(C,...t.slice(10))}}var g=(t)=>Qt(t,"xform")?t.xform():t;function z(...t){return t=t.map(g),Ao.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),P=(t)=>t instanceof St?t.deref():t;var mm=(t)=>t.length===2?[void 0,t[1]]:t.length===3?[t[1],t[2]]:mt(t.length);function Gt(...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 P(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},Nt=(t,o)=>[t,$t,o],Cn=(t,o)=>{let n=o.length-1;return T(o[n])?o.length>1?Gt(t.apply(null,o.slice(0,n)),o[n]):Gt(t(),o[0]):void 0};function Ot(t){return t?[...t]:Nt(()=>[],(o,n)=>(o.push(n),o))}function*et(t,o){let n=g(t)(Ot()),r=n[1],m=n[2];for(let f of o){let E=m([],f);if(S(E)){yield*P(r(E.deref()));return}if(E.length)yield*E}yield*P(r([]))}function*x(t,o){let n=g(t)([_o,_o,(r,m)=>m])[2];for(let r of o){let m=n(K,r);if(S(m)){if(m=P(m.deref()),m!==K)yield m;return}if(m!==K)yield m}}var lt=(t,o,n=x)=>{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 $o(t,o){return T(o)?et($o(t),A(o)?[o]:o):(n)=>{let r=n[2],m=(f,E)=>{let G=t(E);if(G){for(let N of G)if(f=m(f,N),S(f))break;return f}return r(f,E)};return p(n,m)}}function Ln(t){return $o((o)=>kt(o)?o:void 0,t)}function B(t,o){return T(o)?x(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(On),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 N=r[G],O=n[G];if(O===N.length)n[G]=O=0,G>0&&n[G-1]++;E[G]=N[O]}n[o]++,yield E}}function*_n(t,o=1/0){while(o-- >0)yield t}function uo(t,o){t=t||"";let n=!0;return o?[...o].join(t):Nt(()=>"",(r,m)=>(r=n?r+m:r+t+m,n=!1,r))}function gt(...t){return Gm(gt,Gt,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:mt(n.length)}return o(g(n[0])(n[1]),r,m)};var Nm=new Set,Om=":[",Bn=z(Ln(),B((t)=>t[0]==="&"?t.substring(1):Om.includes(t[0])?t:" "+t)),em=(t,o)=>z(t,B((n)=>A(n)&&n.startsWith(" .")?n+o:n)),ht=(t,o,n,r)=>{let m=n.length,f=[],E,G,N=(O,e)=>{let C=null;if(u(e))ht(t,To(o,f),e,r);else if(T(e)&&!A(e))ht(t,To(o,f),[...e],r);else if((G=X(e))||(C=r.fns[e]))if(!o.length){if(C)return C.apply(null,n.slice(O+1))(t,r),!0;e(t,r)}else if(G)N(O,e());else L(`quoted fn ('${e}') only allowed at head position`);else if(J(e))E=Object.assign(E||{},e);else if(e!=null)f.push(e)};for(let O=0;O<m;O++)if(N(O,n[O]))return t;return E&&t.push(hm(o,f,E,r)),t},To=(t,o)=>t.length?[...dt(t,o)]:o,hm=(t,o,n,r)=>{let m=r.format,f=j(r),E=r.scope?em(Bn,r.scope):Bn;return[f,gt(B((G)=>gt(E,uo(),u(G)?G:[G]).trim()),uo(m.ruleSep),To(t,o)),m.declStart,Ht(n,r),f,m.declEnd].join("")},Ht=(t,o)=>{let n=o.format,r=o.autoprefix||Nm,m=j(o,o.depth+1),f=[];for(let E in t)if(t.hasOwnProperty(E)){let G=t[E];if(X(G))G=G(t);if(u(G))G=G.map((N)=>u(N)?N.join(" "):N).join(n.ruleSep);if(r.has(E))for(let N of o.vendors)f.push(`${m}${N}${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?[..._n(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 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?
|
|
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
|
|
30
|
+
`),m+"*/");return n};var xt=(t,o,n)=>(r,m)=>{let f=j(m);return r.push(`${f}${t} ${Cm(o)}${m.format.declStart}`),m.depth++,ht(r,[],n,m),m.depth--,r.push(f+m.format.declEnd),r},Cm=(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 a=(t,o)=>{return o={format:Et,vendors:en,fns:{},depth:0,...o},u(o.autoprefix)&&(o.autoprefix=new Set(o.autoprefix)),J(t)?Ht(t,o):X(t)?t([],o).join(o.format.rules):ht([],[],u(t)?t:kt(t)?[...t]:L("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 Ct=(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":Ct,"@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`,wo=(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 Pn=(t)=>`${M(t)}deg`,jn=(t)=>`${M(t)}rad`,Xn=(t)=>`${M(t)}turn`,Zn=(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 Lm=0,_m=()=>Lm++,s=(t,o)=>!o||!o.id?{...o,id:t+"-"+_m()}:o;var H=Gn.childLogger("rstream");class V{constructor(t,o){this.wrapped=t,o=s("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(Ot()))}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(J(Ft(t)))n=t.pop(),o={error:n.error};return this.subscribe(o,s("xform",t.length>0?{...n,xform:z(...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=P(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)ft(`operation not allowed in state ${w[this.state]}`)}release(){this.subs.length=0,delete this.parent,delete this.xform,delete this.last}}var bn=(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]=X(t)?[t,o||{}]:[void 0,t||{}];super(r.error?{error:r.error}:void 0,s("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 Fo(t){return t?Gt(Fo(),t):Nt(()=>({}),(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 P(r)||[])if(n=o(n,m),S(n))break}return S(r)?hn(n):n})};function So(t,o){return T(o)?et(So(t),o):z(B(t),Vn())}function Ho(t,o){return T(o)?x(Ho(t),o):B(X(t)?(n)=>[t(n),n]:(n)=>[t,n])}function yo(...t){let o=lt(yo,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 Mo(...t){let o=lt(Mo,t,et);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],N=new Set,O=new Map,e={},C=([h,_,I])=>{let v=!0;if(r||E<1)return[h,(i)=>{if(m&&f&&N.size>0||!m&&v)i=I(i,e),e={},N.clear(),v=!1;return _(i)},(i,l)=>{let y=n(l);if(G.has(y)){if(e[y]=l,N.add(y),r||Qn(G,N))if(i=I(i,e),v=!1,m)e={},N.clear();else e={...e}}return i}];else return[h,(i)=>{if(f&&N.size>0)i=I(i,kn(O,N)),O.clear(),N.clear();return _(i)},(i,l)=>{let y=n(l);if(G.has(y)){let b=O.get(y);!b&&O.set(y,b=[]),b.length>=E&&ft(`max back pressure (${E}) exceeded for input: ${String(y)}`),b.push(l),N.add(y);while(Qn(G,N))if(i=I(i,kn(O,N)),v=!1,S(i))break}return i}]};return C.keys=()=>G,C.clear=()=>{O.clear(),G.clear(),N.clear(),e={}},C.add=(h)=>{G.add(h)},C.delete=(h,_=!0)=>{if(O.delete(h),G.delete(h),_)N.delete(h),delete e[h]},C}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=Mo(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,s("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:Ho(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 Io=U((t,o=" ")=>{let n=nt(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}}),G1=Io(2,"0"),N1=Io(3,"0"),dn=Io(4,"0");var im=/\{(\d+)\}/g;var Ro=(t,...o)=>o.length>0?t.replace(im,(n,r)=>String(o[parseInt(r,10)])):t;var gn=(t)=>({key:(o)=>o,group:Ot(),...t});function Wo(...t){let o=Cn(Wo,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 N=n.key(G);return E[N]=E[N]?f(E[N],G):f(r(),G),E}]}function Uo(t,o){return T(o)?x(Uo(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 c}from"path";var xn={specs:D({alias:"s",optional:!1,desc:"Path to generated JSON defs"})},ct={bundle:R({alias:"b",desc:"Bundle inputs (see `out` option)"})},Lt={include:Yt({alias:"I",desc:"Include CSS files (prepend)"})},to={eval:D({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:D({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"})},_t={noDecls:R({alias:"d",desc:"Don't emit framework decls"})},it={noHeader:R({desc:"Don't emit generated header comment"})},Bt={scope:D({desc:"Suffix for CSS class names"})},At={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?Lo(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=bn(F(m,o),{id:`in${dn(f)}`});return{input:E,watcher:Bm(m,{},(G)=>{if(G==="change")try{E.next(F(m,o))}catch(N){o.warn(N.message),n()}else o.warn("input removed:",m),n()})}});return process.on("SIGINT",n),st({src:Fo(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,...Lt,..._t,...it,...q,...Q,...Bt,...xn,...At,noWrite:R({desc:"Don't write files, use stdout only"})},fn:Yo};async function Yo(t){let o=Z(c(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(c(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=c(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=c(t.opts.specs),m,f={process:()=>{try{return o=Z(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=c(G);let N=!t.opts.noWrite?G.replace(/\.mcss$/,".css"):void 0,O=()=>{try{return It(t,o,n,[F(G,t.logger)],N),!0}catch(e){if(t.logger.warn(e.message+": "+G),m)E();return!1}};if(!O())process.exit(1);return{process:O,watcher:tr(G,{},(e)=>{if(e==="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)=>{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,N,O)=>{let e={logger:t,specs:E,css:{format:m?vt:Et,fns:at,scope:f},mediaQueryIDs:new Set(Object.keys(E.media)),mediaQueryRules:{...G.mediaQueryRules},plainRules:{...G.plainRules}},C=o?o.map((h)=>F(c(h),t).trim()):[];if(!r)C.push(ro(E));if(!n&&E.decls.length)C.push(a(E.decls,e.css));N.forEach((h)=>Fm(h,e)),Tm(C,e),um(C,e),k(O,C,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(a(Ct(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(a(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=[...rt(F(c(o[0].substring(1)),n))];for(let G of o){if(!G||G.startsWith("//"))continue;let{token:N,query:O}=fr(G,r),e;if(N.includes("*")){let C=new RegExp(`^${N.replace("*",".*")}$`);e=[...Uo((h)=>C.test(h),m)]}else if(m.has(N))e=[N];else{n.warn(`unknown include rule ID: ${G}, skipping...`);continue}for(let C of e)n.debug("including class:",C),O?Er(f,O,`.${C}`,C):Gr(E,`.${C}`,C)}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 N of rt(t)){if(!N||/^\s*\/\//.test(N))continue;for(let O of Sm(N)){if(!O)continue;let e=G.curr;switch(e.state){case"sel":case"nest":if(O==="{"){if(e.state==="sel")e.sel=e.sel.map((C)=>C.replace(",","")),e.path=Hm(G.scopes);e.state="class"}else if(O==="}")or(G);else{let C=Ft(e.sel);if(!C||C.endsWith(","))e.sel.push(O);else e.sel[e.sel.length-1]+=" "+O}break;case"class":if(O==="{")e.state="nest",G.scopes.push(G.curr=Rt(e));else if(O==="}")or(G);else{let{token:C,query:h}=fr(O,n);if(!o.classes[C]&&!(Nr(C)||er(C)||Or(C)))L(`unknown class ID: ${C}`);if(h)Er(r,h,e.path,C);else Gr(m,e.path,C)}break;default:ft(e.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)L(`invalid nesting in line: '${t}'`)}else if(G==="["){if(o<0)o=E;m++}else if(G==="]"){if(--m<0)L(`invalid arg nesting in line: '${t}'`)}else if(o<0)o=E}if(f)L("string literals must be fully on a single line");if(r)L("template calls must be fully on a single line");if(m)L("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 N=Object.assign({},...B((O)=>er(O)?Wm(O):Nr(O)?Im(O):Or(O)?Rm(n,O):mo(n.classes[O]),o));G.push(N)}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)))L(`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)L(`unknown template: ${r}`);if(m.length!==f.__arity)L(`template "${r}" expected ${f.__arity} arguments`);return Object.entries(f).reduce((E,[G,N])=>{if(!G.startsWith("__")){if(G=Ro(G,...m),A(N))N=Ro(N,...m);E[G]=N}return E},{})},Wm=(t)=>{let[o,n,r]=/^(.+)-\[(.+)\]/.exec(t);return{[n]:r}},Nr=(t)=>/^[a-z0-9:_-]+=.+/i.test(t),Or=(t)=>t.includes("(")&&t.endsWith(")"),er=(t)=>t.indexOf("-[")>0&&t.endsWith("]");var Cr={deg:Pn,em:yn,ex:Mn,ms:Jn,percent:wo,px:Rn,rad:jn,rem:In,second:zn,turn:Xn,url:Zn,vh:Wn,vmax:Dn,vmin:Yn,vw:Un,"%":wo},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:[""]},Lr={desc:"Generate framework rules from specs",opts:{...q,...no,...Q,...At},fn:Do};async function Do(t){if(t.opts.watch)await Dm(t);else await _r(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{_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:[]};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{ir(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},ir=(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),N=new Set;for(let O of f){let e=t.vars?.[O]||Ym[O];if(!e)L(`unknown variation ID: ${O}`);for(let[C,h]of dt(e,Object.keys(G))){let _=tt(o.name,O,C,h,G[h]),I=o.unit?tt(o.unit,O,C,h,G[h]):void 0,v=m?jm(I):Pm(G[h],I);if(!n[_]){if(n[_]={},o.user!=null)n[_].__user=o.user;if(o.doc!=null)n[_].__doc=Xm(o.doc,O,C,h,v)}else if(!N.has(_))L(`duplicate class ID: ${_}`);N.add(_);let i=-1;for(let[l,y]of Object.entries(E)){let b=tt(l,O,C,h,G[h]),fo=tt(!I||A(y)?String(y):Cr[I](y),O,C,h,v);if(n[_][b]=fo,r.debug(_,b,fo),m)i=hr(fo,hr(b,i))}if(m)n[_].__arity=i+1}}return n},Jm=(t,o,n,r)=>ir(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]||L(`invalid table ID: ${t.values}`):t.values;if(J(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):L(`invalid key type: ${t.key}`);return n.reduce((m,f,E)=>{return m[r(f,E)]=f,m},{})},Pm=(t,o)=>{if(!o||A(t))return t;let n=Cr[o];if(!n)L(`invalid unit: ${o}`);return n(t)},jm=(t)=>t?Um[t]||"{0}"+t:"{0}",tt=(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?tt(t,r,m,f,E):"TODO",desc:o?tt(o,r,m,f,E):void 0,args:n?n.map((G)=>tt(G,r,m,f,E)):void 0});var Br={desc:"Combination of the generate & convert commands",opts:{...ct,...to,...oo,...Lt,..._t,...it,...no,...Q,...Bt,...At,outCss:D({desc:"Output file for CSS bundle",optional:!1}),outSpecs:D({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 Do(f),await Yo(E)}};import{resolve as Zm}from"path";var ur={desc:"Generate Markdown documentation for framework specs",opts:{...q,level:Dt({alias:"l",desc:"Initial heading level",default:1}),title:D({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=Z(Zm(r[0]),o),f=bm(m,n);k(n.out,f,o)}},bm=(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}):`,"",`${ot(o+1)} Classes by category`,"",...$r(t.classes,pm,o+2),`${ot(o+1)} Templates by category`,"",...$r(t.templates,Vm,o+2),`${ot(o+1)} Media queries`,"",...Object.entries(t.media).map(([E,G])=>`- **${E}**: \`${JSON.stringify(G)}\``),""];if(n!=="NONE")f.unshift(`${ot(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 Bo(n[f],r[f]);return 0}return n.length-r.length}return Bo(t,o)},$r=(t,o,n)=>{let r=Wo({key:([m,{__doc:f}])=>f?.group||"TODO",group:[()=>[],(m)=>m.sort(),(m,f)=>(m.push(f[0]),m)]},Object.entries(t));return So((m)=>{let f=r[m].sort(Km).map((G)=>o(G,t[G].__doc,n+1)),E=f.length;return[`${ot(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())},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`${
|
|
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`${ot(n)} ${t}(...)
|
|
38
38
|
|
|
39
|
-
TODO`;let r=o.args.map((m)=>/^\w+/.exec(m)[0]).join(", ");return[`${
|
|
39
|
+
TODO`;let r=o.args.map((m)=>/^\w+/.exec(m)[0]).join(", ");return[`${ot(n)} \`${t}(${r})\``,"",...o.args.map(qm),o.desc?`
|
|
40
40
|
${o.desc}
|
|
41
41
|
`:""].join(`
|
|
42
|
-
`)},qm=(t)=>`- ${t.replace(/^(\w+)/,(o,n)=>`**${n}**`)}`,
|
|
42
|
+
`)},qm=(t)=>`- ${t.replace(/^(\w+)/,(o,n)=>`**${n}**`)}`,ot=U((t)=>"#".repeat(t));import{resolve as Tr}from"path";var Fr={desc:"Export entire generated framework as CSS",opts:{...Lt,..._t,...sn,...q,...Q,...it,...an,...Bt},inputs:1,fn:async(t)=>{let{logger:o,opts:{include:n,media:r,noDecls:m,noHeader:f,onlyDecls:E,out:G,pretty:N,scope:O},inputs:e}=t,C={format:N?vt:Et,fns:at,scope:O},h=Z(Tr(e[0]),o),_=n?n.map((I)=>F(Tr(I),o).trim()):[];if(!f)_.push(ro(h));if(!m&&h.decls.length)_.push(a(h.decls,C));if(!E)_.push(Qm(h,r,C,o));k(G,_,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(Ct(t.media[E],wr("-"+E,t)));else r.warn(`invalid media query ID: ${E}, skipping...`)}return a(m,n)},wr=(t,o)=>Object.entries(o.classes).map(([n,r])=>[`.${n}${t}`,mo(r)]);var Jo=Z(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:Lr},ctx:async(t)=>{if(t.opts.verbose)t.logger.level=$.DEBUG;return{...t,format:Pt}},usage:{prefix:`${mn(Jo.name,Jo.version,Jo.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.8",
|
|
4
4
|
"description": "Data-driven CSS framework codegen, transpiler & bundler",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@thi.ng/api": "^8.11.30",
|
|
48
|
-
"@thi.ng/args": "^2.
|
|
48
|
+
"@thi.ng/args": "^2.7.0",
|
|
49
49
|
"@thi.ng/arrays": "^2.13.2",
|
|
50
50
|
"@thi.ng/checks": "^3.7.10",
|
|
51
51
|
"@thi.ng/compare": "^2.4.22",
|
|
@@ -113,5 +113,5 @@
|
|
|
113
113
|
"status": "alpha",
|
|
114
114
|
"year": 2023
|
|
115
115
|
},
|
|
116
|
-
"gitHead": "
|
|
116
|
+
"gitHead": "c6e23f650c9c5b35e1abb9c450a7eb67c5ab6a8e\n"
|
|
117
117
|
}
|