@thi.ng/meta-css 0.19.26 → 0.19.28
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 +7 -1
- package/index.js +21 -21
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2025-09-
|
|
3
|
+
- **Last updated**: 2025-09-26T11:53:06Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -11,6 +11,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
11
11
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
12
12
|
and/or version bumps of transitive dependencies.
|
|
13
13
|
|
|
14
|
+
### [0.19.28](https://github.com/thi-ng/umbrella/tree/@thi.ng/meta-css@0.19.28) (2025-09-26)
|
|
15
|
+
|
|
16
|
+
#### ♻️ Refactoring
|
|
17
|
+
|
|
18
|
+
- update CLI arg specs ([34596a3](https://github.com/thi-ng/umbrella/commit/34596a3))
|
|
19
|
+
|
|
14
20
|
### [0.19.21](https://github.com/thi-ng/umbrella/tree/@thi.ng/meta-css@0.19.21) (2025-08-06)
|
|
15
21
|
|
|
16
22
|
#### ♻️ Refactoring
|
package/index.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var Go={default:95,command:92,error:91,hint:90,multi:90,param:96,required:33};var Tt=(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 nt=W((t,o)=>t.repeat(o));var
|
|
3
|
-
`),this.parent?.logEntry(t)}}var
|
|
4
|
-
`};var
|
|
5
|
-
`,start:()=>"",end:""};var jt=
|
|
6
|
-
`)},
|
|
2
|
+
var Go={default:95,command:92,error:91,hint:90,multi:90,param:96,required:33};var Tt=(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 nt=W((t,o)=>t.repeat(o));var zo=(t)=>/^[a-f0-9]+$/i.test(t);var jo=(t)=>/^[-+]?\d+$/.test(t),Xo=(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)"),_=(t)=>{throw new Sr(t)};var Oo=(t)=>Xo(t)?parseFloat(t):_(`not a numeric value: ${t}`),No=(t)=>zo(t)?parseInt(t,16):_(`not a hex value: ${t}`),io=(t)=>jo(t)?parseInt(t):_(`not an integer: ${t}`);var yr=(t,o)=>t+(o?`[${o}..]`:""),Wt=(t,o,n)=>(r)=>({type:t,coerce:o,hint:n,group:"main",...r}),Yt=(t,o,n,r=",")=>(m)=>({type:t,delim:r,hint:yr(n,m.delim??r),coerce:(f)=>f.map(o),group:"main",multi:!0,...m}),M=(t)=>({type:"flag",group:"flags",default:!1,...t}),D=Wt("string",Tt,"STR"),Dt=Yt("strings",Tt,"STR"),_f=Wt("float",Oo,"NUM"),Cf=Yt("floats",Oo,"NUM"),Jt=Wt("int",io,"INT"),uf=Yt("ints",io,"INT"),Af=Wt("hex",No,"HEX"),Lf=Yt("hexes",No,"HEX");var Bf={dryRun:M({desc:"Dry run (no changes applied)"})},Tf={quiet:M({alias:"q",desc:"Disable all logging"})},Zo={verbose:M({alias:"v",desc:"Display extra information"})};var L=Array.isArray;var B=((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})(B||{});var Hr=0;class $t{constructor(t,o=B.FINE,n){this.parent=n,this.id=t||`logger-${Hr++}`,this.level=typeof o==="string"?B[o]:o}id;level;addChild(t){return t.parent=this,t}enabled(t){return this.level<=t}fine(...t){this.log(B.FINE,t)}debug(...t){this.log(B.DEBUG,t)}info(...t){this.log(B.INFO,t)}warn(...t){this.log(B.WARN,t)}severe(...t){this.log(B.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});class Pt extends $t{constructor(t,o,n,r){super(o,n,r);this.target=t}childLogger(t,o){return new Pt(this.target,t,o??this.level,this)}logEntry(t){if(t[0]<this.level)return;this.target.write(`[${B[t[0]]}] ${t[1]}: ${Ko(t.slice(3)).join(" ")}
|
|
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 Rr=(t,o)=>(n)=>t.format(o,n),ho=(t)=>Object.keys(eo).reduce((o,n)=>(o[n]=Rr(t,eo[n]),o),{format:t});var bo="\x1B[0m";var Mr=["","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(Mr[n]),"\x1B["+o.join(";")+"m"}),end:bo,prefix:bo,suffix:`
|
|
4
|
+
`};var Vo={format:(t,o)=>String(o),prefix:"",suffix:`
|
|
5
|
+
`,start:()=>"",end:""};var jt=ho(zt),qo=ho(Vo);var Ir=(t)=>t.toUpperCase(),po=(t)=>t.toLowerCase(),Xt=(t)=>t.length?t[0].toUpperCase()+t.substring(1):t,rt=(t,o="-")=>po(t.replace(/([a-z0-9\u00e0-\u00fd])([A-Z\u00c0-\u00dd])/g,(n,r,m)=>r+o+m));var Qo=(t,o="-")=>po(t).replace(new RegExp(`\\${o}+(\\w)`,"g"),(n,r)=>Ir(r));var ko=(t=!1,o)=>(n)=>t||typeof n!=="string"&&typeof n!=="number"?JSON.stringify(n,null,o):String(n);var vo=Object.getPrototypeOf,J=(t)=>{let o;return t!=null&&typeof t==="object"&&((o=vo(t))===null||vo(o)===null)};var Ur=/\x1b\[[0-9;]+m/g,Wr=(t)=>t.replace(Ur,"");var Zt=(t)=>Wr(t).length;var lo=W((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*mt(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 O=G[0].length;yield t.substring(r,G.index+f*O),r=G.index+O}}class _o{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},xo={length:Zt,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}},go=(t,o,n,r)=>{let m=t[t.length-1];m&&r-m.n>n?m.add(o,n):t.push(new _o(o,n))},Dr=(t,{width:o,min:n,hard:r,splitter:m},f=0,E=[])=>{let G=m.length(t),O=o-f;if(O<n&&O<G)O=o;while(r&&G>O){let N=m.split(t,O),i=t.substring(0,N);go(E,i,O,o),t=t.substring(N),O=o,G=m.length(t)}return go(E,t,G,o),E},Jr=(t,o,n=[])=>{if(!t.length)return n.push(new _o),n;let r={width:80,min:4,hard:!1,splitter:Yr,...o};for(let m of mt(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},ao=(t,o)=>{let n=[];for(let r of mt(t,o.delimLine))n=n.concat(Jr(r,o));return n};var U=(t,o)=>o!=null?`\x1B[${o}m${t}\x1B[0m`:t,Kt=(t,o)=>lo(o)(t,Zt(t)),bt=(t,o)=>t?ao(t,{width:o,splitter:xo,hard:!1}):[],Vt=(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)?{...Go,...t}:t!==!1?Go:{};var Ft=(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)=>Pr(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?[`${Xt(E)}:
|
|
7
7
|
`]:[],...r(G),""].join(`
|
|
8
8
|
`)),...bt(o.suffix,o.lineWidth)].join(`
|
|
9
|
-
`)},
|
|
9
|
+
`)},Pr=(t,o,n,r,m)=>{let f=zr(o,r),E=jr(o,r,f),G=U(`--${rt(t)}`,r.param),O=`${E}${G}${f}`,N=!!o.required&&o.default===void 0,i=[];N&&i.push("required"),o.multi&&i.push("multiple");let e=Xr(i,r,N)+(o.desc||"")+Zr(o,n,r);return Kt(O,n.paramWidth)+Vt(e,m,n.lineWidth)},zr=(t,o)=>t.hint?U(" "+t.hint,o.hint):"",jr=(t,o,n)=>t.alias?`${U("-"+t.alias,o.param)}${n}, `:"",Xr=(t,o,n)=>t.length?U(`[${t.join(", ")}] `,n?o.required:o.multi):"",Zr=(t,o,n)=>o.showDefaults&&t.default!=null&&t.default!==!1?U(` (default: ${ko(!0)(t.defaultHint!=null?t.defaultHint:t.default)})`,n.default):"";var Kr=Y(()=>"parse error"),so=(t,o,n)=>{n={start:2,showUsage:!0,help:["--help","-h"],...n};try{return br(t,o,n)}catch(r){if(n.showUsage)console.log(U(r.message,d(n.usageOpts?.color).error)+`
|
|
10
10
|
|
|
11
|
-
`+Ft(t,n.usageOpts));throw new
|
|
11
|
+
`+Ft(t,n.usageOpts));throw new Kr(r.message)}},br=(t,o,n)=>{let r=Vr(t),m={},f,E,G=n.start;for(;G<o.length;){let O=o[G];if(!f){if(n.help.includes(O)){console.log(Ft(t,n.usageOpts));return}let N=qr(t,r,m,O);if(f=N.id,E=N.spec,G=G+~~(N.state<2),N.state)break}else{if(pr(E,m,f,O))break;f=null,G++}}return f&&_(`missing value for: --${rt(f)}`),{result:Qr(t,m),index:G,rest:o.slice(G),done:G>=o.length}},Vr=(t)=>Object.entries(t).reduce((o,[n,r])=>r.alias?(o[r.alias]=n,o):o,{}),qr=(t,o,n,r)=>{if(r[0]!=="-")return{state:2};let m;if(r[1]==="-"){if(r.length===2)return{state:1};m=Qo(r.substring(2))}else m=o[r.substring(1)],!m&&_(`unknown option: ${r}`);let f=t[m];if(!f&&_(m),f.type==="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}},pr=(t,o,n,r)=>{if(t.multi)L(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.required)_(`missing arg: --${rt(r)}`)}else if(n.coerce)kr(n,o,r);return o},kr=(t,o,n)=>{try{if(t.multi&&t.delim&&t.split!==!1)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 --${rt(n)}: ${r.message}`)}};var nn=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)_("no command provided");E=t.commands[f]}else{if(f=o[G],E=t.commands[f],!E)m.prefix+=tn(t.commands,m),co(t,m);else m.prefix+=tn({[f]:E},m,`
|
|
12
12
|
Current command:
|
|
13
|
-
`);G++}let O;try{O=
|
|
13
|
+
`);G++}let O;try{O=so({...t.opts,...E.opts},o,{usageOpts:m,start:G})}catch(i){process.exit(1)}if(!O)process.exit(0);if(E.inputs!==void 0){let i=O.rest.length,e;if(L(E.inputs)){let[h,C]=E.inputs;if(i<h||i>C)e=C<1/0?`expected ${h}-${C} inputs`:`expected at least ${h} input(s)`}else if(i!==E.inputs)e=`expected ${E.inputs} input(s)`;if(e)on(e,r),co(t,m)}let N=await t.ctx({logger:new Pt(process.stderr,t.name,"INFO"),format:n?jt:qo,opts:O.result,inputs:O.rest},E);if(await E.fn(N),t.post)await t.post(N,E)}catch(f){on(f.message,r),process.exit(1)}},co=(t,o)=>{process.stderr.write(Ft(t.opts,o)),process.exit(1)},tn=(t,{color:o,lineWidth:n=80}={},r=`
|
|
14
14
|
Available commands:
|
|
15
|
-
`)=>{let m=Object.keys(t),f=Math.max(...m.map((G)=>G.length)),E=
|
|
15
|
+
`)=>{let m=Object.keys(t),f=Math.max(...m.map((G)=>G.length)),E=d(o);return[r,...m.map((G)=>`${Kt(U(G,E.command),f)} : ${Vt(t[G].desc,f+3,n)}`),`
|
|
16
16
|
`].join(`
|
|
17
|
-
`)},
|
|
17
|
+
`)},on=(t,o)=>process.stderr.write(U(t,o.error)+`
|
|
18
18
|
|
|
19
|
-
`);var
|
|
19
|
+
`);var rn=(t,o,n=!1)=>{if(n)t.level=B.NONE;else if(o)t.level=B.DEBUG};var mn=(t,o,n)=>`
|
|
20
20
|
\u2588 \u2588 \u2588 \u2502
|
|
21
21
|
\u2588\u2588 \u2588 \u2502
|
|
22
22
|
\u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2502 ${t} v${o}
|
|
23
23
|
\u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2502 ${n}
|
|
24
24
|
\u2588 \u2502
|
|
25
|
-
\u2588 \u2588 \u2502`;var T=(t)=>typeof t==="string";var
|
|
26
|
-
`):o,"utf-8",n,r);var Z=(t,o)=>JSON.parse(w(t,o));var b=Symbol(),
|
|
25
|
+
\u2588 \u2588 \u2502`;var T=(t)=>typeof t==="string";var vr=[[process.env.HOME?new RegExp(process.env.HOME,"g"):/~/,"~"]];var qt=(t)=>{for(let[o,n]of vr)t=t.replace(o,n);return t};import{existsSync as lr,mkdirSync as dr,statSync as IE}from"fs";import{dirname as gr}from"path";var xr=(t)=>t.length>0&&!lr(t)?(dr(t,{recursive:!0}),!0):!1,fn=(t)=>xr(gr(t));var X=(t)=>typeof t==="function";import{readFileSync as cr}from"fs";import{writeFileSync as ar}from"fs";var En=(t,o,n,r,m=!1)=>sr(ar,t,o,n,r,m);var sr=(t,o,n,r,m,f=!1)=>{if(m?.info(`${f?"[dryrun] ":""}writing file: ${qt(o)}`),f)return;return fn(o),t(o,n,!r&&T(n)?"utf-8":r)};var w=(t,o,n="utf-8")=>{return o?.debug("reading file:",qt(t)),cr(t,n)};var Co=(t,o,n,r=!1)=>En(t,L(o)?o.join(`
|
|
26
|
+
`):o,"utf-8",n,r);var Z=(t,o)=>JSON.parse(w(t,o));var b=Symbol(),uo=()=>{};var wt=Object.freeze({level:B.NONE,addChild(t){return t},childLogger:()=>wt,enabled:()=>!1,fine(){},debug(){},info(){},warn(){},severe(){},none(){},logEntry(){}});import{join as Qm}from"path";var Ao=(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 tm=Y(()=>"Assertion failed"),pt=(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 tm(typeof o==="function"?o():o)}:()=>{};var Qt=(t)=>t!=null&&typeof t!=="function"&&t.length!==void 0;var Gn=(t)=>{return(t==null||!t[Symbol.iterator])&&_(`value is not iterable: ${t}`),t};var On=(t)=>Qt(t)?t:[...Gn(t)];var St=(t)=>t[t.length-1];var kt=(t,o)=>typeof t?.[o]==="function";var $=(t)=>typeof t?.[Symbol.iterator]==="function";var vt=(t)=>t!=null&&typeof t!=="string"&&typeof t[Symbol.iterator]==="function";var om=Y(()=>"illegal arity"),ft=(t)=>{throw new om(t)};var nm=Y(()=>"illegal state"),Et=(t)=>{throw new nm(t)};var Nn=["-moz-","-ms-","-o-","-webkit-"],Gt={rules:"",ruleSep:",",valSep:"",decls:"",declStart:"{",declEnd:"}",indent:"",comments:!1},lt={rules:`
|
|
27
27
|
`,ruleSep:", ",valSep:" ",decls:`
|
|
28
28
|
`,declStart:` {
|
|
29
29
|
`,declEnd:`}
|
|
30
|
-
`,indent:" ",comments:!0};function
|
|
30
|
+
`,indent:" ",comments:!0};function Lo(...t){let[o,n,r,m,f,E,G,O,N,i]=t;switch(t.length){case 0:ft(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(O(...h))))))));case 9:return(...h)=>o(n(r(m(f(E(G(O(N(...h)))))))));case 10:default:let e=(...h)=>o(n(r(m(f(E(G(O(N(i(...h))))))))));return t.length===10?e:Lo(e,...t.slice(10))}}var g=(t)=>kt(t,"xform")?t.xform():t;function P(...t){return t=t.map(g),Lo.apply(null,t)}var V=(t,o)=>[t[0],t[1],o];class yt{value;constructor(t){this.value=t}deref(){return this.value}}var S=(t)=>t instanceof yt,en=(t)=>t instanceof yt?t:new yt(t),z=(t)=>t instanceof yt?t.deref():t;var rm=(t)=>t.length===2?[void 0,t[1]]:t.length===3?[t[1],t[2]]:ft(t.length);function Ot(...t){let o=t[0],n=o[0],r=o[1],m=o[2];t=rm(t);let f=t[0]==null?n():t[0],E=t[1];return z(r(kt(E,"$reduce")?E.$reduce(m,f):Qt(E)?mm(m,f,E):fm(m,f,E)))}var mm=(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},fm=(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,Tt,o],hn=(t,o)=>{let n=o.length-1;return $(o[n])?o.length>1?Ot(t.apply(null,o.slice(0,n)),o[n]):Ot(t(),o[0]):void 0};function it(t){return t?[...t]:Nt(()=>[],(o,n)=>(o.push(n),o))}function*et(t,o){let n=g(t)(it()),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*x(t,o){let n=g(t)([uo,uo,(r,m)=>m])[2];for(let r of o){let m=n(b,r);if(S(m)){if(m=z(m.deref()),m!==b)yield m;return}if(m!==b)yield m}}var dt=(t,o,n=x)=>{let r=o.length-1;return $(o[r])?o.length>1?n(t.apply(null,o.slice(0,r)),o[r]):n(t(),o[0]):void 0};function Bo(t,o){return $(o)?et(Bo(t),T(o)?[o]:o):(n)=>{let r=n[2],m=(f,E)=>{let G=t(E);if(G){for(let O of G)if(f=m(f,O),S(f))break;return f}return r(f,E)};return V(n,m)}}function _n(t){return Bo((o)=>vt(o)?o:void 0,t)}function A(t,o){return $(o)?x(A(t),o):(n)=>{let r=n[2];return V(n,(m,f)=>r(m,t(f)))}}function*gt(...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 O=r[G],N=n[G];if(N===O.length)n[G]=N=0,G>0&&n[G-1]++;E[G]=O[N]}n[o]++,yield E}}function*Cn(t,o=1/0){while(o-- >0)yield t}function To(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 xt(...t){return Em(xt,Ot,t)}var Em=(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 A((f)=>t(n[0],n[1],f));default:ft(n.length)}return o(g(n[0])(n[1]),r,m)};var Gm=new Set,Om=":[",un=P(_n(),A((t)=>t[0]==="&"?t.substring(1):Om.includes(t[0])?t:" "+t)),Nm=(t,o)=>P(t,A((n)=>T(n)&&n.startsWith(" .")?n+o:n)),ht=(t,o,n,r)=>{let m=n.length,f=[],E,G,O=(N,i)=>{let e=null;if(L(i))ht(t,$o(o,f),i,r);else if($(i)&&!T(i))ht(t,$o(o,f),[...i],r);else if((G=X(i))||(e=r.fns[i]))if(!o.length){if(e)return e.apply(null,n.slice(N+1))(t,r),!0;i(t,r)}else if(G)O(N,i());else _(`quoted fn ('${i}') only allowed at head position`);else if(J(i))E=Object.assign(E||{},i);else if(i!=null)f.push(i)};for(let N=0;N<m;N++)if(O(N,n[N]))return t;return E&&t.push(im(o,f,E,r)),t},$o=(t,o)=>t.length?[...gt(t,o)]:o,im=(t,o,n,r)=>{let m=r.format,f=j(r),E=r.scope?Nm(un,r.scope):un;return[f,xt(A((G)=>xt(E,To(),L(G)?G:[G]).trim()),To(m.ruleSep),$o(t,o)),m.declStart,Ht(n,r),f,m.declEnd].join("")},Ht=(t,o)=>{let n=o.format,r=o.autoprefix||Gm,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(L(G))G=G.map((O)=>L(O)?O.join(" "):O).join(n.ruleSep);if(r.has(E))for(let O of o.vendors)f.push(`${m}${O}${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?[...Cn(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 Ln=(t,o=!1)=>(n,r)=>{let m=j(r),f=j(r,r.depth+1);if(r.format.comments||o)n.push(m+"/*",t.split(`
|
|
31
31
|
`).map((E)=>f+E).join(`
|
|
32
|
-
`),m+"*/");return n};var at=(t,o,n)=>(r,m)=>{let f=j(m);return r.push(`${f}${t} ${Am(o)}${m.format.declStart}`),m.depth++,Ct(r,[],n,m),m.depth--,r.push(f+m.format.declEnd),r},Am=(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=Fn.has(n)?n:`(${n})`;else if(r===!1)r=`(not ${Fn.has(n)?n:`(${n})`})`;else if(r==="only")r+=" "+n;else r=`(${n}:${r})`;o.push(r)}return o.join(" and ")},Fn=new Set(["all","print","screen"]);var a=(t,o)=>{return o={format:Gt,vendors:Cn,fns:{},depth:0,...o},e(o.autoprefix)&&(o.autoprefix=new Set(o.autoprefix)),J(t)?Rt(t,o):X(t)?t([],o).join(o.format.rules):Ct([],[],e(t)?t:vt(t)?[...t]:i("invalid rules"),o).join(o.format.rules)};var wn=(t,...o)=>(n,r)=>(n.push(o.length?`@import url(${t}) ${o.join(r.format.ruleSep)};`:`@import url(${t});`),n);var it=(t,o)=>at("@media",t,o);function Sn(...t){return(o,n)=>(o.push(t.length>1?`@namespace ${t[0]} url(${t[1]});`:`@namespace url(${t[0]});`),o)}var Hn=(t,o)=>at("@supports",t,o);var st={"@comment":un,"@import":wn,"@keyframes":Tn,"@media":it,"@namespace":Sn,"@supports":Hn};var Rn=4,yn=(t)=>Rn=t,y=(t)=>t===(t|0)?String(t):t.toFixed(Rn).replace(/^0./,".").replace(/^-0./,"-.").replace(/0+$/,"");var Mn=(t)=>`${y(t)}em`,In=(t)=>`${y(t)}ex`;var Un=(t)=>`${y(t)}rem`,Fo=(t)=>`${y(t)}%`,Wn=(t)=>`${y(t)}px`,Yn=(t)=>`${y(t)}vh`,Dn=(t)=>`${y(t)}vw`,Jn=(t)=>`${y(t)}vmin`,zn=(t)=>`${y(t)}vmax`,Pn=(t)=>`${t|0}ms`,jn=(t)=>`${y(t)}s`;var Xn=(t)=>`${y(t)}deg`,Zn=(t)=>`${y(t)}rad`,Kn=(t)=>`${y(t)}turn`,bn=(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 Lm=0,Bm=()=>Lm++,s=(t,o)=>!o||!o.id?{...o,id:t+"-"+Bm()}:o;class wo extends ut{set(t){this.parent=t}childLogger(t,o){return new wo(t,o??this.level,this)}logEntry(t){this.parent.logEntry(t)}}var Vn=new wo("root",$.FINE,wt);var H=Vn.childLogger("rstream");class p{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(ht()))}id;closeIn;closeOut;parent;__owner;xform;cacheLast;last=b;state=F.IDLE;subs=[];deref(){return this.last!==b?this.last:void 0}getState(){return this.state}setState(t){this.state=t}subscribe(t,o={}){this.ensureState();let n;if(t instanceof p&&!o.xform)t.ensureState(),qt(!t.parent,`sub '${t.id}' already has a parent`),t.parent=this,n=t;else n=new p(t,{...o,parent:this});return this.subs.push(n),this.setState(F.ACTIVE),n.setState(F.ACTIVE),this.last!=b&&n.next(this.last),n}transform(...t){let o,n;if(J(St(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<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!==wt?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=P(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)Et(`operation not allowed in state ${F[this.state]}`)}release(){this.subs.length=0,delete this.parent,delete this.xform,delete this.last}}var pn=(t,o)=>{let n=new qn(o);return n.next(t),n};class qn extends p{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 Qn=(t,o)=>t==="first"||t==="last"&&!o;function So(t){return t?Ot(So(),t):Nt(()=>({}),(o,[n,r])=>(o[n]=r,o))}var kn=()=>(t)=>{let o=t[2];return V(t,(n,r)=>{if(r){for(let m of P(r)||[])if(n=o(n,m),S(n))break}return S(r)?An(n):n})};function Ho(t,o){return u(o)?_t(Ho(t),o):z(B(t),kn())}function Ro(t,o){return u(o)?x(Ro(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 vn=(t)=>t;function Mo(...t){let o=lt(Mo,t,_t);if(o)return o;let{key:n=vn,mergeOnly:r=!1,reset:m=!0,all:f=!0,backPressure:E=0}=t[1],G=e(t[0])?new Set(t[0]):t[0],O=new Set,N=new Map,h={},_=([C,A,I])=>{let v=!0;if(r||E<1)return[C,(L)=>{if(m&&f&&O.size>0||!m&&v)L=I(L,h),h={},O.clear(),v=!1;return A(L)},(L,d)=>{let R=n(d);if(G.has(R)){if(h[R]=d,O.add(R),r||dn(G,O))if(L=I(L,h),v=!1,m)h={},O.clear();else h={...h}}return L}];else return[C,(L)=>{if(f&&O.size>0)L=I(L,ln(N,O)),N.clear(),O.clear();return A(L)},(L,d)=>{let R=n(d);if(G.has(R)){let K=N.get(R);!K&&N.set(R,K=[]),K.length>=E&&Et(`max back pressure (${E}) exceeded for input: ${String(R)}`),K.push(d),O.add(R);while(dn(G,O))if(L=I(L,ln(N,O)),v=!1,S(L))break}return L}]};return _.keys=()=>G,_.clear=()=>{N.clear(),G.clear(),O.clear(),h={}},_.add=(C)=>{G.add(C)},_.delete=(C,A=!0)=>{if(N.delete(C),G.delete(C),A)O.delete(C),delete h[C]},_}var dn=(t,o)=>{if(o.size<t.size)return!1;for(let n of t)if(!o.has(n))return!1;return!0},ln=(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 gn=(t,o)=>{let n=!0;for(let r of o)n=t.removeID(r)&&n;return n};var ct=(t)=>new xn(t);class xn extends p{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 p?this.add(n[1]):this.next(n),done:()=>this.markDone(t),__owner:this},{xform:Ro(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 gn(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),Qn(this.closeIn,this.sources.size)&&this.done()}}var Io=W((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}}),iO=Io(2,"0"),AO=Io(3,"0"),an=Io(4,"0");var em=/\{(\d+)\}/g;var Uo=(t,...o)=>o.length>0?t.replace(em,(n,r)=>String(o[parseInt(r,10)])):t;var sn=(t)=>({key:(o)=>o,group:ht(),...t});function Wo(...t){let o=Ln(Wo,t);if(o)return o;let n=sn(t[0]),[r,m,f]=n.group;return[()=>({}),(E)=>{for(let G in E)E[G]=m(E[G]);return E},(E,G)=>{let O=n.key(G);return E[O]=E[O]?f(E[O],G):f(r(),G),E}]}function Yo(t,o){return u(o)?x(Yo(t),o):(n)=>{let r=n[2];return V(n,(m,f)=>t(f)?r(m,f):m)}}import{watch as rr}from"fs";import{resolve as c}from"path";var cn={specs:D({alias:"s",optional:!1,desc:"Path to generated JSON defs"})},to={bundle:M({alias:"b",desc:"Bundle inputs (see `out` option)"})},At={include:Dt({alias:"I",desc:"Include CSS files (prepend)"})},oo={eval:D({alias:"e",desc:"eval meta stylesheet in given string (ignores other inputs & includes)"})},no={force:Dt({alias:"f",hint:"STR",desc:"CSS classes to force include (wildcards are supported, @-prefix will read from file)",delim:","})},tr={media:Dt({alias:"m",hint:"ID",desc:"Media query IDs (use 'ALL' for all)",delim:","})},or={onlyDecls:M({desc:"Only emit framework decls"})},q={out:D({alias:"o",desc:"Output file (or stdout)"})},ro={prec:Jt({default:3,desc:"Number of fractional digits"})},Q={pretty:M({alias:"p",desc:"Pretty print output"})},Lt={noDecls:M({alias:"d",desc:"Don't emit framework decls"})},Bt={noHeader:M({desc:"Don't emit generated header comment"})},et={scope:D({desc:"Suffix for CSS class names"})},$t={watch:M({alias:"w",desc:"Watch input files for changes"})};import{watch as $m}from"fs";import{resolve as nr}from"path";var k=(t,o,n)=>{o=T(o)?o:o.join(`
|
|
33
|
-
`),t?
|
|
34
|
-
`)},mo=({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=nr(m);let E=pn(w(m,o),{id:`in${an(f)}`});return{input:E,watcher:$m(m,{},(G)=>{if(G==="change")try{E.next(w(m,o))}catch(O){o.warn(O.message),n()}else o.warn("input removed:",m),n()})}});return process.on("SIGINT",n),ct({src:So(B(({input:m})=>[m.id,m],r))})},fo=(t)=>Object.keys(t).reduce((o,n)=>{if(!n.startsWith("__"))o[n]=t[n];return o},{});var fr={desc:"Transpile (and optionally bundle) meta stylesheets to CSS",opts:{...to,...oo,...no,...At,...Lt,...Bt,...q,...Q,...et,...cn,...$t,noWrite:M({desc:"Don't write files, use stdout only"})},fn:Do};async function Do(t){let o=Z(c(t.opts.specs),t.logger),n=Sm(o,t.opts.force||[],t.logger);if(t.opts.bundle)if(t.opts.watch)await um(t,n);else It(t,o,n,t.opts.eval?[t.opts.eval]:t.inputs.map((r)=>w(c(r),t.logger)),t.opts.out);else if(t.opts.watch)await Tm(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,[w(r,t.logger)],m)}catch(m){t.logger.warn(m.message)}}var Tm=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:rr(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 O=!t.opts.noWrite?G.replace(/\.mcss$/,".css"):void 0,N=()=>{try{return It(t,o,n,[w(G,t.logger)],O),!0}catch(h){if(t.logger.warn(h.message+": "+G),m)E();return!1}};if(!N())process.exit(1);return{process:N,watcher:rr(G,{},(h)=>{if(h==="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)},um=async(t,o)=>{ct({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,O,N)=>{let h={logger:t,specs:E,css:{format:m?dt:Gt,fns:st,scope:f},mediaQueryIDs:new Set(Object.keys(E.media)),mediaQueryRules:{...G.mediaQueryRules},plainRules:{...G.plainRules}},_=o?o.map((C)=>w(c(C),t).trim()):[];if(!r)_.push(mo(E));if(!n&&E.decls.length)_.push(a(E.decls,h.css));O.forEach((C)=>Hm(C,h)),wm(_,h),Fm(_,h),k(N,_,t)},Fm=(t,{css:o,logger:n,mediaQueryRules:r,specs:m})=>{for(let f in r){let E=Gr(r[f],m);n.debug("mediaquery rules",f,E),t.push(a(it(Im(m.media,f),E),o))}},wm=(t,{css:o,logger:n,plainRules:r,specs:m})=>{let f=Gr(r,m);n.debug("plain rules",f),t.push(a(f,o))},Sm=(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=[...mt(w(c(o[0].substring(1)),n))];for(let G of o){if(!G||G.startsWith("//"))continue;let{token:O,query:N}=Or(G,r),h;if(O.includes("*")){let _=new RegExp(`^${O.replace("*",".*")}$`);h=[...Yo((C)=>_.test(C),m)]}else if(m.has(O))h=[O];else{n.warn(`unknown include rule ID: ${G}, skipping...`);continue}for(let _ of h)n.debug("including class:",_),N?Nr(f,N,`.${_}`,_):hr(E,`.${_}`,_)}return{mediaQueryRules:f,plainRules:E}},Hm=(t,{specs:o,mediaQueryIDs:n,mediaQueryRules:r,plainRules:m})=>{let f=Ut(),E=Ut(f),G={root:f,curr:E,scopes:[E]};for(let O of mt(t)){if(!O||/^\s*\/\//.test(O))continue;for(let N of Rm(O)){if(!N)continue;let h=G.curr;switch(h.state){case"sel":case"nest":if(N==="{"){if(h.state==="sel")h.sel=h.sel.map((_)=>_.replace(",","")),h.path=ym(G.scopes);h.state="class"}else if(N==="}")mr(G);else{let _=St(h.sel);if(!_||_.endsWith(","))h.sel.push(N);else h.sel[h.sel.length-1]+=" "+N}break;case"class":if(N==="{")h.state="nest",G.scopes.push(G.curr=Ut(h));else if(N==="}")mr(G);else{let{token:_,query:C}=Or(N,n);if(!o.classes[_]&&!(_r(_)||ir(_)||Cr(_)))i(`unknown class ID: ${_}`);if(C)Nr(r,C,h.path,_);else hr(m,h.path,_)}break;default:Et(h.state)}}}};function*Rm(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=":",Er="///",Ut=(t)=>({state:"sel",sel:t?[]:["<root>"],path:"",parent:t}),mr=(t)=>{let o=!t.curr.sel.length;if(qt(!!t.curr.parent,"stack underflow"),t.scopes.pop(),t.scopes.length>0){if(t.curr=St(t.scopes),!o&&t.curr.state==="nest")t.scopes.push(t.curr=Ut(t.curr))}else t.scopes.push(t.curr=Ut(t.root))},ym=(t)=>t.map((o)=>o.sel.join(",")).join(Er),Gr=(t,o)=>Object.entries(t).map(([n,r])=>Mm(n,r,o)),Mm=(t,o,n)=>{let r=[],m=r,f=t.split(Er);for(let E=0;E<f.length;E++){let G=f[E].split(",");if(E==f.length-1){let O=Object.assign({},...B((N)=>ir(N)?Ym(N):_r(N)?Um(N):Cr(N)?Wm(n,N):fo(n.classes[N]),o));G.push(O)}m.push(G),m=G}return r[0]},Or=(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}},Im=(t,o)=>o.split(Mt).reduce((n,r)=>Object.assign(n,t[r]),{}),Nr=(t,o,n,r)=>{if(!t[o])t[o]={};(t[o][n]||(t[o][n]=new Set)).add(r)},hr=(t,o,n)=>(t[o]||(t[o]=new Set)).add(n),Um=(t)=>{let o=t.indexOf("="),n=t.substring(0,o),r=t.substring(o+1);return{[`--${n}`]:r[0]==='"'?r.slice(1,-1):r}},Wm=(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,O])=>{if(!G.startsWith("__")){if(G=Uo(G,...m),T(O))O=Uo(O,...m);E[G]=O}return E},{})},Ym=(t)=>{let[o,n,r]=/^(.+)-\[(.+)\]/.exec(t);return{[n]:r}},_r=(t)=>/^[a-z0-9:_-]+=.+/i.test(t),Cr=(t)=>t.includes("(")&&t.endsWith(")"),ir=(t)=>t.indexOf("-[")>0&&t.endsWith("]");var Lr={deg:Xn,em:Mn,ex:In,ms:Pn,percent:Fo,px:Wn,rad:Zn,rem:Un,second:jn,turn:Kn,url:bn,vh:Yn,vmax:zn,vmin:Jn,vw:Dn,"%":Fo},Dm={percent:"{0}%",second:"{0}s",url:"url({0})"},Jm={"":[""],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:[""]},Br={desc:"Generate framework rules from specs",opts:{...q,...ro,...Q,...$t},fn:Jo};async function Jo(t){if(t.opts.watch)await zm(t);else await er(t.inputs.map((o)=>w(o,t.logger)),t.opts,t.logger)}var zm=async(t)=>{yt(t.inputs,t.logger).subscribe({next(o){try{er(Object.keys(o).sort().map((n)=>o[n]),t.opts,t.logger)}catch(n){t.logger.warn(n.message)}}})},er=async(t,o,n)=>{let r={info:{name:"TODO",version:"0.0.0"},media:{},classes:{},templates:{},decls:[]};yn(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{$r(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)Pm(f,E,r.templates,n)}return k(o.out,JSON.stringify(r,null,o.pretty?4:0),n),r},$r=(t,o,n,r,m=!1)=>{let f=e(o.vars)?o.vars:[""],E=T(o.props)?{[o.props]:"<v>"}:o.props,G=jm(o,t),O=new Set;for(let N of f){let h=t.vars?.[N]||Jm[N];if(!h)i(`unknown variation ID: ${N}`);for(let[_,C]of gt(h,Object.keys(G))){let A=tt(o.name,N,_,C,G[C]),I=o.unit?tt(o.unit,N,_,C,G[C]):void 0,v=m?Zm(I):Xm(G[C],I);if(!n[A]){if(n[A]={},o.user!=null)n[A].__user=o.user;if(o.doc!=null)n[A].__doc=Km(o.doc,N,_,C,v)}else if(!O.has(A))i(`duplicate class ID: ${A}`);O.add(A);let L=-1;for(let[d,R]of Object.entries(E)){let K=tt(d,N,_,C,G[C]),Eo=tt(!I||T(R)?String(R):Lr[I](R),N,_,C,v);if(n[A][K]=Eo,r.debug(A,K,Eo),m)L=Ar(Eo,Ar(K,L))}if(m)n[A].__arity=L+1}}return n},Pm=(t,o,n,r)=>$r(t,{...o,values:[""]},n,r,!0),Ar=(t,o)=>{let n=/\{(\d+)\}/g,r;while(r=n.exec(t))o=Math.max(o,+r[1]);return o},jm=(t,o)=>{let n=T(t.values)?o.tables?.[t.values]||i(`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):i(`invalid key type: ${t.key}`);return n.reduce((m,f,E)=>{return m[r(f,E)]=f,m},{})},Xm=(t,o)=>{if(!o||T(t))return t;let n=Lr[o];if(!n)i(`invalid unit: ${o}`);return n(t)},Zm=(t)=>t?Dm[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)),Km=({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 Tr={desc:"Combination of the generate & convert commands",opts:{...to,...oo,...no,...At,...Lt,...Bt,...ro,...Q,...et,...$t,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,O)=>(G[O.endsWith(".json")?0:1].push(O),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 Do(E)}};import{resolve as bm}from"path";var wr={desc:"Generate Markdown documentation for framework specs",opts:{...q,level:Jt({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(bm(r[0]),o),f=Vm(m,n);k(n.out,f,o)}},Vm=(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`,"",...Fr(t.classes,qm,o+2),`${ot(o+1)} Templates by category`,"",...Fr(t.templates,Qm,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}
|
|
35
|
-
`);return f},
|
|
32
|
+
`),m+"*/");return n};var at=(t,o,n)=>(r,m)=>{let f=j(m);return r.push(`${f}${t} ${em(o)}${m.format.declStart}`),m.depth++,ht(r,[],n,m),m.depth--,r.push(f+m.format.declEnd),r},em=(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=Bn.has(n)?n:`(${n})`;else if(r===!1)r=`(not ${Bn.has(n)?n:`(${n})`})`;else if(r==="only")r+=" "+n;else r=`(${n}:${r})`;o.push(r)}return o.join(" and ")},Bn=new Set(["all","print","screen"]);var a=(t,o)=>{return o={format:Gt,vendors:Nn,fns:{},depth:0,...o},L(o.autoprefix)&&(o.autoprefix=new Set(o.autoprefix)),J(t)?Ht(t,o):X(t)?t([],o).join(o.format.rules):ht([],[],L(t)?t:vt(t)?[...t]:_("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 _t=(t,o)=>at("@media",t,o);function $n(...t){return(o,n)=>(o.push(t.length>1?`@namespace ${t[0]} url(${t[1]});`:`@namespace url(${t[0]});`),o)}var Fn=(t,o)=>at("@supports",t,o);var st={"@comment":Ln,"@import":Tn,"@keyframes":An,"@media":_t,"@namespace":$n,"@supports":Fn};var wn=4,Sn=(t)=>wn=t,R=(t)=>t===(t|0)?String(t):t.toFixed(wn).replace(/^0./,".").replace(/^-0./,"-.").replace(/0+$/,"");var yn=(t)=>`${R(t)}em`,Hn=(t)=>`${R(t)}ex`;var Rn=(t)=>`${R(t)}rem`,Fo=(t)=>`${R(t)}%`,Mn=(t)=>`${R(t)}px`,In=(t)=>`${R(t)}vh`,Un=(t)=>`${R(t)}vw`,Wn=(t)=>`${R(t)}vmin`,Yn=(t)=>`${R(t)}vmax`,Dn=(t)=>`${t|0}ms`,Jn=(t)=>`${R(t)}s`;var Pn=(t)=>`${R(t)}deg`,zn=(t)=>`${R(t)}rad`,jn=(t)=>`${R(t)}turn`,Xn=(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,_m=()=>hm++,s=(t,o)=>!o||!o.id?{...o,id:t+"-"+_m()}:o;class wo extends $t{set(t){this.parent=t}childLogger(t,o){return new wo(t,o??this.level,this)}logEntry(t){this.parent.logEntry(t)}}var Zn=new wo("root",B.FINE,wt);var y=Zn.childLogger("rstream");class q{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(it()))}id;closeIn;closeOut;parent;__owner;xform;cacheLast;last=b;state=F.IDLE;subs=[];deref(){return this.last!==b?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(),pt(!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!=b&&n.next(this.last),n}transform(...t){let o,n;if(J(St(t)))n=t.pop(),o={error:n.error};return this.subscribe(o,s("xform",t.length>0?{...n,xform:P(...t)}:n))}map(t,o){return this.transform(A(t),o||{})}unsubscribe(t){return t?this.unsubscribeChild(t):this.unsubscribeSelf()}unsubscribeSelf(){return y.debug(this.id,"unsub self"),this.parent?.unsubscribe(this),this.state<F.UNSUBSCRIBED&&(this.state=F.UNSUBSCRIBED),this.release(),!0}unsubscribeChild(t){y.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(y.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();y.debug(this.id,"exiting done()")}error(t){let n=this.wrapped?.error;return n&&y.debug(this.id,"attempting wrapped error handler"),n?.(t)||this.unhandledError(t)}unhandledError(t){return(y.parent!==wt?y: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){y.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<F.DONE;n++)this.dispatch(o[n]);return this.state<F.ERROR}ensureState(){if(this.state>=F.DONE)Et(`operation not allowed in state ${F[this.state]}`)}release(){this.subs.length=0,delete this.parent,delete this.xform,delete this.last}}var Kn=(t,o)=>{let n=new bn(o);return n.next(t),n};class bn 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,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){y.debug(this.id,"cancel");let t=this._cancel;delete this._cancel,t()}}}var Vn=(t,o)=>t==="first"||t==="last"&&!o;function So(t){return t?Ot(So(),t):Nt(()=>({}),(o,[n,r])=>(o[n]=r,o))}var qn=()=>(t)=>{let o=t[2];return V(t,(n,r)=>{if(r){for(let m of z(r)||[])if(n=o(n,m),S(n))break}return S(r)?en(n):n})};function yo(t,o){return $(o)?et(yo(t),o):P(A(t),qn())}function Ho(t,o){return $(o)?x(Ho(t),o):A(X(t)?(n)=>[t(n),n]:(n)=>[t,n])}function Ro(...t){let o=dt(Ro,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 pn=(t)=>t;function Mo(...t){let o=dt(Mo,t,et);if(o)return o;let{key:n=pn,mergeOnly:r=!1,reset:m=!0,all:f=!0,backPressure:E=0}=t[1],G=L(t[0])?new Set(t[0]):t[0],O=new Set,N=new Map,i={},e=([h,C,I])=>{let v=!0;if(r||E<1)return[h,(u)=>{if(m&&f&&O.size>0||!m&&v)u=I(u,i),i={},O.clear(),v=!1;return C(u)},(u,l)=>{let H=n(l);if(G.has(H)){if(i[H]=l,O.add(H),r||Qn(G,O))if(u=I(u,i),v=!1,m)i={},O.clear();else i={...i}}return u}];else return[h,(u)=>{if(f&&O.size>0)u=I(u,kn(N,O)),N.clear(),O.clear();return C(u)},(u,l)=>{let H=n(l);if(G.has(H)){let K=N.get(H);!K&&N.set(H,K=[]),K.length>=E&&Et(`max back pressure (${E}) exceeded for input: ${String(H)}`),K.push(l),O.add(H);while(Qn(G,O))if(u=I(u,kn(N,O)),v=!1,S(u))break}return u}]};return e.keys=()=>G,e.clear=()=>{N.clear(),G.clear(),O.clear(),i={}},e.add=(h)=>{G.add(h)},e.delete=(h,C=!0)=>{if(N.delete(h),G.delete(h),C)O.delete(h),delete i[h]},e}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 ct=(t)=>new ln(t);class ln extends q{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=Ro((r)=>r[1]);super(void 0,s("streamsync",{...t,xform:t.xform?P(o,n,t.xform):P(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: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 y.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){y.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),Vn(this.closeIn,this.sources.size)&&this.done()}}var Io=W((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}}),iO=Io(2,"0"),eO=Io(3,"0"),dn=Io(4,"0");var Cm=/\{(\d+)\}/g;var Uo=(t,...o)=>o.length>0?t.replace(Cm,(n,r)=>String(o[parseInt(r,10)])):t;var gn=(t)=>({key:(o)=>o,group:it(),...t});function Wo(...t){let o=hn(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 O=n.key(G);return E[O]=E[O]?f(E[O],G):f(r(),G),E}]}function Yo(t,o){return $(o)?x(Yo(t),o):(n)=>{let r=n[2];return V(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",required:!0,desc:"Path to generated JSON defs"})},to={bundle:M({alias:"b",desc:"Bundle inputs (see `out` option)"})},Ct={include:Dt({alias:"I",desc:"Include CSS files (prepend)"})},oo={eval:D({alias:"e",desc:"eval meta stylesheet in given string (ignores other inputs & includes)"})},no={force:Dt({alias:"f",hint:"STR",desc:"CSS classes to force include (wildcards are supported, @-prefix will read from file)",delim:","})},an={media:Dt({alias:"m",hint:"ID",desc:"Media query IDs (use 'ALL' for all)",delim:","})},sn={onlyDecls:M({desc:"Only emit framework decls"})},p={out:D({alias:"o",desc:"Output file (or stdout)"})},ro={prec:Jt({default:3,desc:"Number of fractional digits"})},Q={pretty:M({alias:"p",desc:"Pretty print output"})},ut={noDecls:M({alias:"d",desc:"Don't emit framework decls"})},At={noHeader:M({desc:"Don't emit generated header comment"})},Lt={scope:D({desc:"Suffix for CSS class names"})},Bt={watch:M({alias:"w",desc:"Watch input files for changes"})};import{watch as um}from"fs";import{resolve as cn}from"path";var k=(t,o,n)=>{o=T(o)?o:o.join(`
|
|
33
|
+
`),t?Co(cn(t),o,n):process.stdout.write(o+`
|
|
34
|
+
`)},mo=({info:{name:t,version:o}})=>`/*! ${t} v${o} - generated by thi.ng/meta-css @ ${new Date().toISOString()} */`,Rt=(t,o)=>{let n=()=>{o.info("closing watchers..."),r.forEach((m)=>m.watcher.close())},r=t.map((m,f)=>{m=cn(m);let E=Kn(w(m,o),{id:`in${dn(f)}`});return{input:E,watcher:um(m,{},(G)=>{if(G==="change")try{E.next(w(m,o))}catch(O){o.warn(O.message),n()}else o.warn("input removed:",m),n()})}});return process.on("SIGINT",n),ct({src:So(A(({input:m})=>[m.id,m],r))})},fo=(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:{...to,...oo,...no,...Ct,...ut,...At,...p,...Q,...Lt,...xn,...Bt,noWrite:M({desc:"Don't write files, use stdout only"})},fn:Do};async function Do(t){let o=Z(c(t.opts.specs),t.logger),n=$m(o,t.opts.force||[],t.logger);if(t.opts.bundle)if(t.opts.watch)await Lm(t,n);else It(t,o,n,t.opts.eval?[t.opts.eval]:t.inputs.map((r)=>w(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,[w(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 O=!t.opts.noWrite?G.replace(/\.mcss$/,".css"):void 0,N=()=>{try{return It(t,o,n,[w(G,t.logger)],O),!0}catch(i){if(t.logger.warn(i.message+": "+G),m)E();return!1}};if(!N())process.exit(1);return{process:N,watcher:tr(G,{},(i)=>{if(i==="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)},Lm=async(t,o)=>{ct({src:{styles:Rt(t.inputs,t.logger),specs:Rt([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,O,N)=>{let i={logger:t,specs:E,css:{format:m?lt:Gt,fns:st,scope:f},mediaQueryIDs:new Set(Object.keys(E.media)),mediaQueryRules:{...G.mediaQueryRules},plainRules:{...G.plainRules}},e=o?o.map((h)=>w(c(h),t).trim()):[];if(!r)e.push(mo(E));if(!n&&E.decls.length)e.push(a(E.decls,i.css));O.forEach((h)=>Fm(h,i)),Tm(e,i),Bm(e,i),k(N,e,t)},Bm=(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(_t(Hm(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))},$m=(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=[...mt(w(c(o[0].substring(1)),n))];for(let G of o){if(!G||G.startsWith("//"))continue;let{token:O,query:N}=fr(G,r),i;if(O.includes("*")){let e=new RegExp(`^${O.replace("*",".*")}$`);i=[...Yo((h)=>e.test(h),m)]}else if(m.has(O))i=[O];else{n.warn(`unknown include rule ID: ${G}, skipping...`);continue}for(let e of i)n.debug("including class:",e),N?Er(f,N,`.${e}`,e):Gr(E,`.${e}`,e)}return{mediaQueryRules:f,plainRules:E}},Fm=(t,{specs:o,mediaQueryIDs:n,mediaQueryRules:r,plainRules:m})=>{let f=Ut(),E=Ut(f),G={root:f,curr:E,scopes:[E]};for(let O of mt(t)){if(!O||/^\s*\/\//.test(O))continue;for(let N of wm(O)){if(!N)continue;let i=G.curr;switch(i.state){case"sel":case"nest":if(N==="{"){if(i.state==="sel")i.sel=i.sel.map((e)=>e.replace(",","")),i.path=Sm(G.scopes);i.state="class"}else if(N==="}")or(G);else{let e=St(i.sel);if(!e||e.endsWith(","))i.sel.push(N);else i.sel[i.sel.length-1]+=" "+N}break;case"class":if(N==="{")i.state="nest",G.scopes.push(G.curr=Ut(i));else if(N==="}")or(G);else{let{token:e,query:h}=fr(N,n);if(!o.classes[e]&&!(Or(e)||ir(e)||Nr(e)))_(`unknown class ID: ${e}`);if(h)Er(r,h,i.path,e);else Gr(m,i.path,e)}break;default:Et(i.state)}}}};function*wm(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=":",rr="///",Ut=(t)=>({state:"sel",sel:t?[]:["<root>"],path:"",parent:t}),or=(t)=>{let o=!t.curr.sel.length;if(pt(!!t.curr.parent,"stack underflow"),t.scopes.pop(),t.scopes.length>0){if(t.curr=St(t.scopes),!o&&t.curr.state==="nest")t.scopes.push(t.curr=Ut(t.curr))}else t.scopes.push(t.curr=Ut(t.root))},Sm=(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 O=Object.assign({},...A((N)=>ir(N)?Im(N):Or(N)?Rm(N):Nr(N)?Mm(n,N):fo(n.classes[N]),o));G.push(O)}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)))_(`invalid media query in token: ${t}`);return{token:t.substring(n+1),query:f}},Hm=(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),Rm=(t)=>{let o=t.indexOf("="),n=t.substring(0,o),r=t.substring(o+1);return{[`--${n}`]:r[0]==='"'?r.slice(1,-1):r}},Mm=(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,O])=>{if(!G.startsWith("__")){if(G=Uo(G,...m),T(O))O=Uo(O,...m);E[G]=O}return E},{})},Im=(t)=>{let[o,n,r]=/^(.+)-\[(.+)\]/.exec(t);return{[n]:r}},Or=(t)=>/^[a-z0-9:_-]+=.+/i.test(t),Nr=(t)=>t.includes("(")&&t.endsWith(")"),ir=(t)=>t.indexOf("-[")>0&&t.endsWith("]");var hr={deg:Pn,em:yn,ex:Hn,ms:Dn,percent:Fo,px:Mn,rad:zn,rem:Rn,second:Jn,turn:jn,url:Xn,vh:In,vmax:Yn,vmin:Wn,vw:Un,"%":Fo},Um={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:[""]},_r={desc:"Generate framework rules from specs",opts:{...p,...ro,...Q,...Bt},fn:Jo};async function Jo(t){if(t.opts.watch)await Ym(t);else await Cr(t.inputs.map((o)=>w(o,t.logger)),t.opts,t.logger)}var Ym=async(t)=>{Rt(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:[]};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{ur(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)Dm(f,E,r.templates,n)}return k(o.out,JSON.stringify(r,null,o.pretty?4:0),n),r},ur=(t,o,n,r,m=!1)=>{let f=L(o.vars)?o.vars:[""],E=T(o.props)?{[o.props]:"<v>"}:o.props,G=Jm(o,t),O=new Set;for(let N of f){let i=t.vars?.[N]||Wm[N];if(!i)_(`unknown variation ID: ${N}`);for(let[e,h]of gt(i,Object.keys(G))){let C=tt(o.name,N,e,h,G[h]),I=o.unit?tt(o.unit,N,e,h,G[h]):void 0,v=m?zm(I):Pm(G[h],I);if(!n[C]){if(n[C]={},o.user!=null)n[C].__user=o.user;if(o.doc!=null)n[C].__doc=jm(o.doc,N,e,h,v)}else if(!O.has(C))_(`duplicate class ID: ${C}`);O.add(C);let u=-1;for(let[l,H]of Object.entries(E)){let K=tt(l,N,e,h,G[h]),Eo=tt(!I||T(H)?String(H):hr[I](H),N,e,h,v);if(n[C][K]=Eo,r.debug(C,K,Eo),m)u=er(Eo,er(K,u))}if(m)n[C].__arity=u+1}}return n},Dm=(t,o,n,r)=>ur(t,{...o,values:[""]},n,r,!0),er=(t,o)=>{let n=/\{(\d+)\}/g,r;while(r=n.exec(t))o=Math.max(o,+r[1]);return o},Jm=(t,o)=>{let n=T(t.values)?o.tables?.[t.values]||_(`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):_(`invalid key type: ${t.key}`);return n.reduce((m,f,E)=>{return m[r(f,E)]=f,m},{})},Pm=(t,o)=>{if(!o||T(t))return t;let n=hr[o];if(!n)_(`invalid unit: ${o}`);return n(t)},zm=(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)),jm=({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 Ar={desc:"Combination of the generate & convert commands",opts:{...to,...oo,...no,...Ct,...ut,...At,...ro,...Q,...Lt,...Bt,outCss:D({desc:"Output file for CSS bundle",required:!0}),outSpecs:D({desc:"Output file for framework",required:!0})},fn:async(t)=>{let{opts:o,inputs:n}=t,[r,m]=n.reduce((G,O)=>(G[O.endsWith(".json")?0:1].push(O),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 Do(E)}};import{resolve as Xm}from"path";var Tr={desc:"Generate Markdown documentation for framework specs",opts:{...p,level:Jt({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(Xm(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}):`,"",`${ot(o+1)} Classes by category`,"",...Br(t.classes,bm,o+2),`${ot(o+1)} Templates by category`,"",...Br(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}
|
|
35
|
+
`);return f},Lr=(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=Lr(t),r=Lr(o),m=n.length;if(m===r.length){for(let f=0;f<m;f++)if(n[f]!==r[f])return Ao(n[f],r[f]);return 0}return n.length-r.length}return Ao(t,o)},Br=(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 yo((m)=>{let f=r[m].sort(Km).map((G)=>o(G,t[G].__doc,n+1)),E=f.length;return[`${ot(n)} ${Xt(m)}`,E>3?`
|
|
36
36
|
<details><summary>${E} items:</summary>
|
|
37
37
|
`:"",f.join(`
|
|
38
38
|
`),E>3?`</details>
|
|
39
|
-
`:""]},Object.keys(r).sort())},
|
|
39
|
+
`:""]},Object.keys(r).sort())},bm=(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}(...)
|
|
40
40
|
|
|
41
|
-
TODO`;let r=o.args.map((m)=>/^\w+/.exec(m)[0]).join(", ");return[`${ot(n)} \`${t}(${r})\``,"",...o.args.map(
|
|
41
|
+
TODO`;let r=o.args.map((m)=>/^\w+/.exec(m)[0]).join(", ");return[`${ot(n)} \`${t}(${r})\``,"",...o.args.map(qm),o.desc?`
|
|
42
42
|
${o.desc}
|
|
43
43
|
`:""].join(`
|
|
44
|
-
`)},
|
|
44
|
+
`)},qm=(t)=>`- ${t.replace(/^(\w+)/,(o,n)=>`**${n}**`)}`,ot=W((t)=>"#".repeat(t));import{resolve as $r}from"path";var wr={desc:"Export entire generated framework as CSS",opts:{...Ct,...ut,...sn,...p,...Q,...At,...an,...Lt},inputs:1,fn:async(t)=>{let{logger:o,opts:{include:n,media:r,noDecls:m,noHeader:f,onlyDecls:E,out:G,pretty:O,scope:N},inputs:i}=t,e={format:O?lt:Gt,fns:st,scope:N},h=Z($r(i[0]),o),C=n?n.map((I)=>w($r(I),o).trim()):[];if(!f)C.push(mo(h));if(!m&&h.decls.length)C.push(a(h.decls,e));if(!E)C.push(pm(h,r,e,o));k(G,C,o)}},pm=(t,o,n,r)=>{let m=Fr("",t);if(o){let f=o[0]==="ALL"?Object.keys(t.media):o;for(let E of f)if(t.media[E])m.push(_t(t.media[E],Fr("-"+E,t)));else r.warn(`invalid media query ID: ${E}, skipping...`)}return a(m,n)},Fr=(t,o)=>Object.entries(o.classes).map(([n,r])=>[`.${n}${t}`,fo(r)]);var Po=Z(Qm(process.argv[2],"package.json"));nn({name:"metacss",start:3,opts:{...Zo},commands:{convert:nr,develop:Ar,doc:Tr,export:wr,generate:_r},ctx:async(t)=>{return rn(t.logger,t.opts.verbose),{...t,format:jt}},usage:{prefix:`${mn(Po.name,Po.version,Po.description)}
|
|
45
45
|
|
|
46
46
|
Usage: metacss <cmd> [opts] input [...]
|
|
47
47
|
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.28",
|
|
4
4
|
"description": "Data-driven CSS framework codegen, transpiler & bundler",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -45,16 +45,16 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@thi.ng/api": "^8.12.2",
|
|
48
|
-
"@thi.ng/args": "^
|
|
48
|
+
"@thi.ng/args": "^3.0.0",
|
|
49
49
|
"@thi.ng/arrays": "^2.13.11",
|
|
50
50
|
"@thi.ng/checks": "^3.7.18",
|
|
51
51
|
"@thi.ng/compare": "^2.4.28",
|
|
52
52
|
"@thi.ng/errors": "^2.5.42",
|
|
53
|
-
"@thi.ng/file-io": "^2.2.
|
|
53
|
+
"@thi.ng/file-io": "^2.2.10",
|
|
54
54
|
"@thi.ng/hiccup-css": "^2.7.65",
|
|
55
|
-
"@thi.ng/logger": "^3.
|
|
55
|
+
"@thi.ng/logger": "^3.2.0",
|
|
56
56
|
"@thi.ng/memoize": "^4.0.26",
|
|
57
|
-
"@thi.ng/rstream": "^9.2.
|
|
57
|
+
"@thi.ng/rstream": "^9.2.42",
|
|
58
58
|
"@thi.ng/strings": "^3.9.22",
|
|
59
59
|
"@thi.ng/text-format": "^2.2.41",
|
|
60
60
|
"@thi.ng/transducers": "^9.6.10"
|
|
@@ -113,5 +113,5 @@
|
|
|
113
113
|
"status": "alpha",
|
|
114
114
|
"year": 2023
|
|
115
115
|
},
|
|
116
|
-
"gitHead": "
|
|
116
|
+
"gitHead": "f3fa7a4798132f2faf9eb1ef12d99b9ca2148ec3\n"
|
|
117
117
|
}
|