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