@salty-css/vite 0.0.1-alpha.207 → 0.0.1-alpha.209

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.
Files changed (3) hide show
  1. package/index.cjs +21 -19
  2. package/index.js +226 -220
  3. package/package.json +2 -2
package/index.cjs CHANGED
@@ -1,40 +1,42 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const kt=require("esbuild"),_t=require("child_process"),c=require("path"),d=require("fs"),tt=require("fs/promises"),B=require("winston");var rt=typeof document<"u"?document.currentScript:null;function Dt(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return e.default=t,Object.freeze(e)}const gt=Dt(kt),pt=t=>String.fromCharCode(t+(t>25?39:97)),Ot=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=pt(n%52)+s;return s=pt(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},Tt=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},z=(t,e=5)=>{const s=Tt(5381,JSON.stringify(t))>>>0;return Ot(s,e)};function R(t){return t?typeof t!="string"?R(String(t)):t.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?"-":"")+e.toLowerCase()):""}const Et=t=>e=>{if(typeof e!="string"||!t)return;let s=e;const n=[];return Object.values(t).forEach(o=>{const{pattern:r,transform:a}=o;s=s.replace(r,h=>{const{value:F,css:l}=a(h);return l&&n.push(l),F})}),{transformed:s,additionalCss:n}},ht=t=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...o)=>`var(--${R(o[1].replaceAll(".","-"))})`)},Mt=ht(),Rt=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Vt=(t,e,s)=>Rt.some(o=>typeof o=="string"?o===t:o.test(t))?`${e}px`:`${e}`,Jt=["Webkit","Moz","ms","O"],vt=t=>t.startsWith("-")?t:Jt.some(e=>t.startsWith(e))?`-${R(t)}`:R(t),Y=async(t,e="",s,n=!1)=>{if(!t)throw new Error("No styles provided to parseStyles function!");const o=new Set,a=Object.entries(t).map(async([m,i])=>{const p=m.trim(),b=vt(p),C=(O,_=";")=>`${b}:${O}${_}`;if(typeof i=="function"&&(i=i({scope:e,config:s})),i instanceof Promise&&(i=await i),typeof i=="object"){if(!i)return;if(i.isColor)return C(i.toString());if(p==="defaultVariants")return;if(p==="variants"){const D=Object.entries(i);for(const[P,E]of D){if(!E)return;const f=Object.entries(E);for(const[w,g]of f){if(!g)return;const u=`${e}.${P}-${w}`;(await Y(g,u,s)).forEach(x=>o.add(x))}}return}if(p==="compoundVariants"){for(const D of i){const{css:P,...E}=D,f=Object.entries(E).reduce((g,[u,S])=>`${g}.${u}-${S}`,e);(await Y(P,f,s)).forEach(g=>o.add(g))}return}if(p.startsWith("@")){const D=p,P=await G(i,e,s),E=`${D} { ${P} }`;o.add(E);return}const O=m.includes("&")?p.replace("&",e):p.startsWith(":")?`${e}${p}`:`${e} ${p}`;(await Y(i,O,s)).forEach(D=>o.add(D));return}if(typeof i=="number"){const O=Vt(b,i);return C(O)}if(typeof i!="string")if("toString"in i)i=i.toString();else throw new Error(`Invalid value type for property ${b}`);return C(i)}),{modifiers:h}={},F=[ht(),Et(h)],y=(await Promise.all(a).then(m=>Promise.all(m.map(i=>F.reduce(async(p,b)=>{const C=await p;if(!C)return C;const k=await b(C);if(!k)return C;const{transformed:O,additionalCss:_}=k;let D="";if(_)for(const P of _)D+=await G(P,"");return`${D}${O}`},Promise.resolve(i)))))).join(`
2
- `);if(!y.trim())return o;const $=e?`${e} { ${y} }`:y;return o.add($),o},G=async(t,e,s,n=!1)=>[...await Y(t,e,s,n)].join(`
3
- `),wt=async(t,e=[])=>{if(!t)return"";const s=[],n={};for(const[o,r]of Object.entries(t))if(typeof r!="function")if(r&&typeof r=="object"){const a=o.trim(),h=await wt(r,[...e,a]);s.push(h)}else n[o]=r;if(Object.keys(n).length){const o=e.map(R).join("-"),r="t_"+z(o,4),a=await G(n,`.${o}, .${r}`);s.push(a)}return s.join(`
4
- `)},zt=t=>t?Object.entries(t).reduce((e,[s,n])=>(typeof n=="function"?e[s]="any":typeof n=="object"&&(e[s]=$t(n).map(o=>`"${o}"`).join(" | ")),e),{}):{},$t=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const r=e?`${e}.${n}`:n;return typeof o=="object"?$t(o,r,s):s.add(e)}),[...s]):[],bt=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=c.join(t,"package.json");return d.existsSync(e)?e:bt(c.join(t,".."))},At=async t=>{const e=bt(t);return await tt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},Wt=async t=>{const e=await At(t);if(e)return e.type};let I;const St=async t=>{if(I)return I;const e=await Wt(t);return e==="module"?I="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:rt&&rt.tagName.toUpperCase()==="SCRIPT"&&rt.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(I="cjs"),I||"esm"},it=B.createLogger({level:"debug",format:B.format.combine(B.format.colorize(),B.format.cli()),transports:[new B.transports.Console({})]});function jt(t){return t?typeof t!="string"?jt(String(t)):t.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?".":"")+e.toLowerCase()):""}const It={"*, *::before, *::after":{boxSizing:"border-box"},"*":{margin:0},html:{lineHeight:1.15,textSizeAdjust:"100%",WebkitFontSmoothing:"antialiased"},"img, picture, video, canvas, svg":{display:"block",maxWidth:"100%"},"p, h1, h2, h3, h4, h5, h6":{overflowWrap:"break-word"},p:{textWrap:"pretty"},"h1, h2, h3, h4, h5, h6":{textWrap:"balance"},a:{color:"currentColor"},button:{lineHeight:"1em",color:"currentColor"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},Z=(...t)=>t.flat().reduce((e,s)=>s!=null&&s._current?{...e,...s._current}:{...e,...s},{}),Zt=(...t)=>t.flat().reduce((e,s)=>({...e,...s._children}),{}),v={externalModules:[],rcFile:void 0,destDir:void 0},Ft=t=>{if(v.externalModules.length>0)return v.externalModules;const s=d.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return v.externalModules=n,n},A=async t=>{if(v.destDir)return v.destDir;const e=await at(t),s=c.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return v.destDir=s,s},Ct=["salty","css","styles","styled"],qt=(t=[])=>new RegExp(`\\.(${[...Ct,...t].join("|")})\\.`),q=(t,e=[])=>qt(e).test(t),Nt=async t=>{if(v.rcFile)return v.rcFile;if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=c.join(t,".saltyrc.json"),s=await tt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(v.rcFile=s,s):Nt(c.join(t,".."))},at=async t=>{var n,o;const e=await Nt(t),s=(n=e.projects)==null?void 0:n.find(r=>t.endsWith(r.dir||""));return s||((o=e.projects)==null?void 0:o.find(r=>r.dir===e.defaultProject))},Ht=async t=>{const e=await at(t),s=await A(t),n=c.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),o=c.join(s,"salty.config.js"),r=await St(t),a=Ft(n);await gt.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:r,external:a});const h=Date.now(),{config:F}=await import(`${o}?t=${h}`);return F},Lt=async(t,e)=>{var ft,ut;const s=await A(t),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...e].map(async j=>{const{contents:N,outputFilePath:J}=await et(t,j,s);Object.entries(N).forEach(([T,M])=>{M.isMedia?n.mediaQueries.push([T,M]):M.isGlobalDefine?n.globalStyles.push(M):M.isDefineVariables?n.variables.push(M):M.isDefineTemplates&&n.templates.push(M._setPath(J))})}));const o=await Ht(t),r={...o},a=new Set,h=(j,N=[])=>j?Object.entries(j).flatMap(([J,T])=>{if(!T)return;if(typeof T=="object")return h(T,[...N,J]);const M=jt(J),nt=R(J),ot=[...N,M].join(".");a.add(`"${ot}"`);const X=[...N.map(R),nt].join("-"),dt=Mt(T);return dt?`--${X}: ${dt.transformed};`:`--${X}: ${T};`}):[],F=j=>j?Object.entries(j).flatMap(([N,J])=>{const T=h(J);return N==="base"?T.join(""):`${N} { ${T.join("")} }`}):[],l=j=>j?Object.entries(j).flatMap(([N,J])=>Object.entries(J).flatMap(([T,M])=>{const nt=h(M,[N]),ot=`.${N}-${T}, [data-${N}="${T}"]`,X=nt.join("");return`${ot} { ${X} }`})):[],y=j=>({...j,responsive:void 0,conditional:void 0}),$=j=>n.variables.map(N=>j==="static"?y(N._current):N._current[j]),m=Z(y(o.variables),$("static")),i=h(m),p=Z((ft=o.variables)==null?void 0:ft.responsive,$("responsive")),b=F(p),C=Z((ut=o.variables)==null?void 0:ut.conditional,$("conditional")),k=l(C),O=c.join(s,"css/_variables.css"),_=`:root { ${i.join("")} ${b.join("")} } ${k.join("")}`;d.writeFileSync(O,_),r.staticVariables=m;const D=c.join(s,"css/_global.css"),P=Z(o.global,n.globalStyles),E=await G(P,"");d.writeFileSync(D,`@layer global { ${E} }`);const f=c.join(s,"css/_reset.css"),g=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:It,u=await G(g,"");d.writeFileSync(f,`@layer reset { ${u} }`);const S=c.join(s,"css/_templates.css"),x=Z(o.templates,n.templates),V=await wt(x),H=zt(x);d.writeFileSync(S,`@layer templates { ${V} }`),r.templates=x;const L=Zt(n.templates);r.templatePaths=Object.fromEntries(Object.entries(L).map(([j,N])=>[j,N._path]));const{mediaQueries:W}=n;r.mediaQueries=Object.fromEntries(W.map(([j,N])=>[`@${j}`,N]));const K=W.map(([j])=>`'@${j}'`).join(" | "),st=c.join(s,"types/css-tokens.d.ts"),Q=`
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const kt=require("esbuild"),_t=require("child_process"),l=require("path"),d=require("fs"),tt=require("fs/promises"),B=require("winston");var rt=typeof document<"u"?document.currentScript:null;function Dt(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return e.default=t,Object.freeze(e)}const gt=Dt(kt),pt=t=>String.fromCharCode(t+(t>25?39:97)),Ot=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=pt(n%52)+s;return s=pt(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},Et=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},v=(t,e=5)=>{const s=Et(5381,JSON.stringify(t))>>>0;return Ot(s,e)};function V(t){return t?typeof t!="string"?V(String(t)):t.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?"-":"")+e.toLowerCase()):""}const Tt=t=>e=>{if(typeof e!="string"||!t)return;let s=e;const n=[];return Object.values(t).forEach(o=>{const{pattern:r,transform:a}=o;s=s.replace(r,g=>{const{value:C,css:f}=a(g);return f&&n.push(f),C})}),{transformed:s,additionalCss:n}},ht=t=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...o)=>`var(--${V(o[1].replaceAll(".","-"))})`)},Mt=ht(),Rt=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Vt=(t,e,s)=>Rt.some(o=>typeof o=="string"?o===t:o.test(t))?`${e}px`:`${e}`,At=["Webkit","Moz","ms","O"],Jt=t=>t.startsWith("-")?t:At.some(e=>t.startsWith(e))?`-${V(t)}`:V(t),Y=async(t,e="",s,n=!1)=>{if(!t)throw new Error("No styles provided to parseStyles function!");const o=new Set,a=Object.entries(t).map(async([m,i])=>{const y=m.trim(),k=Jt(y),P=(_,T=";")=>`${k}:${_}${T}`;if(typeof i=="function"&&(i=i({scope:e,config:s})),i instanceof Promise&&(i=await i),typeof i=="object"){if(!i)return;if(i.isColor)return P(i.toString());if(y==="defaultVariants")return;if(y==="variants"){const j=Object.entries(i);for(const[D,c]of j){if(!c)return;const h=Object.entries(c);for(const[b,u]of h){if(!u)return;const S=`${e}.${D}-${b}`;(await Y(u,S,s)).forEach(M=>o.add(M))}}return}if(y==="compoundVariants"){for(const j of i){const{css:D,...c}=j,h=Object.entries(c).reduce((u,[S,N])=>`${u}.${S}-${N}`,e);(await Y(D,h,s)).forEach(u=>o.add(u))}return}if(y.startsWith("@")){const j=y,D=await G(i,e,s),c=`${j} { ${D} }`;o.add(c);return}const _=m.includes("&")?y.replace("&",e):y.startsWith(":")?`${e}${y}`:`${e} ${y}`;(await Y(i,_,s)).forEach(j=>o.add(j));return}if(typeof i=="number"){const _=Vt(k,i);return P(_)}if(typeof i!="string")if("toString"in i)i=i.toString();else throw new Error(`Invalid value type for property ${k}`);return P(i)}),{modifiers:g}={},C=[ht(),Tt(g)],p=(await Promise.all(a).then(m=>Promise.all(m.map(i=>C.reduce(async(y,k)=>{const P=await y;if(!P)return P;const R=await k(P);if(!R)return P;const{transformed:_,additionalCss:T}=R;let j="";if(T)for(const D of T)j+=await G(D,"");return`${j}${_}`},Promise.resolve(i)))))).filter(m=>m!==void 0).join(`
2
+ `);if(!p.trim())return Array.from(o);const w=e?`${e} {
3
+ ${p}
4
+ }`:p;return o.has(w)?Array.from(o):[w,...o]},G=async(t,e,s,n=!1)=>(await Y(t,e,s,n)).join(`
5
+ `),wt=async(t,e=[])=>{if(!t)return"";const s=[],n={};for(const[o,r]of Object.entries(t))if(typeof r!="function")if(r&&typeof r=="object"){const a=o.trim(),g=await wt(r,[...e,a]);s.push(g)}else n[o]=r;if(Object.keys(n).length){const o=e.map(V).join("-"),r="t_"+v(o,4),a=await G(n,`.${o}, .${r}`);s.push(a)}return s.join(`
6
+ `)},vt=t=>t?Object.entries(t).reduce((e,[s,n])=>(typeof n=="function"?e[s]="any":typeof n=="object"&&(e[s]=$t(n).map(o=>`"${o}"`).join(" | ")),e),{}):{},$t=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const r=e?`${e}.${n}`:n;return typeof o=="object"?$t(o,r,s):s.add(e)}),[...s]):[],bt=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=l.join(t,"package.json");return d.existsSync(e)?e:bt(l.join(t,".."))},zt=async t=>{const e=bt(t);return await tt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},Wt=async t=>{const e=await zt(t);if(e)return e.type};let I;const St=async t=>{if(I)return I;const e=await Wt(t);return e==="module"?I="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:rt&&rt.tagName.toUpperCase()==="SCRIPT"&&rt.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(I="cjs"),I||"esm"},it=B.createLogger({level:"debug",format:B.format.combine(B.format.colorize(),B.format.cli()),transports:[new B.transports.Console({})]});function jt(t){return t?typeof t!="string"?jt(String(t)):t.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?".":"")+e.toLowerCase()):""}const It={"*, *::before, *::after":{boxSizing:"border-box"},"*":{margin:0},html:{lineHeight:1.15,textSizeAdjust:"100%",WebkitFontSmoothing:"antialiased"},"img, picture, video, canvas, svg":{display:"block",maxWidth:"100%"},"p, h1, h2, h3, h4, h5, h6":{overflowWrap:"break-word"},p:{textWrap:"pretty"},"h1, h2, h3, h4, h5, h6":{textWrap:"balance"},a:{color:"currentColor"},button:{lineHeight:"1em",color:"currentColor"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},Z=(...t)=>t.flat().reduce((e,s)=>s!=null&&s._current?{...e,...s._current}:{...e,...s},{}),Zt=(...t)=>t.flat().reduce((e,s)=>({...e,...s._children}),{}),J={externalModules:[],rcFile:void 0,destDir:void 0},Ft=t=>{if(J.externalModules.length>0)return J.externalModules;const s=d.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return J.externalModules=n,n},z=async t=>{if(J.destDir)return J.destDir;const e=await at(t),s=l.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return J.destDir=s,s},Ct=["salty","css","styles","styled"],qt=(t=[])=>new RegExp(`\\.(${[...Ct,...t].join("|")})\\.`),q=(t,e=[])=>qt(e).test(t),Pt=async t=>{if(J.rcFile)return J.rcFile;if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=l.join(t,".saltyrc.json"),s=await tt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(J.rcFile=s,s):Pt(l.join(t,".."))},at=async t=>{var n,o;const e=await Pt(t),s=(n=e.projects)==null?void 0:n.find(r=>t.endsWith(r.dir||""));return s||((o=e.projects)==null?void 0:o.find(r=>r.dir===e.defaultProject))},Ht=async t=>{const e=await at(t),s=await z(t),n=l.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),o=l.join(s,"salty.config.js"),r=await St(t),a=Ft(n);await gt.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:r,external:a});const g=Date.now(),{config:C}=await import(`${o}?t=${g}`);return C},Lt=async(t,e)=>{var ft,ut;const s=await z(t),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...e].map(async F=>{const{contents:x,outputFilePath:A}=await et(t,F,s);Object.entries(x).forEach(([O,E])=>{E.isMedia?n.mediaQueries.push([O,E]):E.isGlobalDefine?n.globalStyles.push(E):E.isDefineVariables?n.variables.push(E):E.isDefineTemplates&&n.templates.push(E._setPath(A))})}));const o=await Ht(t),r={...o},a=new Set,g=(F,x=[])=>F?Object.entries(F).flatMap(([A,O])=>{if(!O)return;if(typeof O=="object")return g(O,[...x,A]);const E=jt(A),nt=V(A),ot=[...x,E].join(".");a.add(`"${ot}"`);const X=[...x.map(V),nt].join("-"),dt=Mt(O);return dt?`--${X}: ${dt.transformed};`:`--${X}: ${O};`}):[],C=F=>F?Object.entries(F).flatMap(([x,A])=>{const O=g(A);return x==="base"?O.join(""):`${x} { ${O.join("")} }`}):[],f=F=>F?Object.entries(F).flatMap(([x,A])=>Object.entries(A).flatMap(([O,E])=>{const nt=g(E,[x]),ot=`.${x}-${O}, [data-${x}="${O}"]`,X=nt.join("");return`${ot} { ${X} }`})):[],p=F=>({...F,responsive:void 0,conditional:void 0}),w=F=>n.variables.map(x=>F==="static"?p(x._current):x._current[F]),$=Z(p(o.variables),w("static")),m=g($),i=Z((ft=o.variables)==null?void 0:ft.responsive,w("responsive")),y=C(i),k=Z((ut=o.variables)==null?void 0:ut.conditional,w("conditional")),P=f(k),R=l.join(s,"css/_variables.css"),_=`:root { ${m.join("")} ${y.join("")} } ${P.join("")}`;d.writeFileSync(R,_),r.staticVariables=$;const T=l.join(s,"css/_global.css"),j=Z(o.global,n.globalStyles),D=await G(j,"");d.writeFileSync(T,`@layer global { ${D} }`);const c=l.join(s,"css/_reset.css"),b=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:It,u=await G(b,"");d.writeFileSync(c,`@layer reset { ${u} }`);const S=l.join(s,"css/_templates.css"),N=Z(o.templates,n.templates),M=await wt(N),H=vt(N);d.writeFileSync(S,`@layer templates { ${M} }`),r.templates=N;const L=Zt(n.templates);r.templatePaths=Object.fromEntries(Object.entries(L).map(([F,x])=>[F,x._path]));const{mediaQueries:W}=n;r.mediaQueries=Object.fromEntries(W.map(([F,x])=>[`@${F}`,x]));const K=W.map(([F])=>`'@${F}'`).join(" | "),st=l.join(s,"types/css-tokens.d.ts"),Q=`
5
7
  // Variable types
6
8
  type VariableTokens = ${[...a].join("|")};
7
9
  type PropertyValueToken = \`{\${VariableTokens}}\`;
8
10
 
9
11
  // Template types
10
12
  type TemplateTokens = {
11
- ${Object.entries(H).map(([j,N])=>`${j}?: ${N}`).join(`
13
+ ${Object.entries(H).map(([F,x])=>`${F}?: ${x}`).join(`
12
14
  `)}
13
15
  }
14
16
 
15
17
  // Media query types
16
18
  type MediaQueryKeys = ${K||"''"};
17
- `;d.writeFileSync(st,Q);const xt=c.join(s,"cache/config-cache.json");d.writeFileSync(xt,JSON.stringify(r,null,2))},yt=t=>t.replace(/styled\(([^"'`{,]+),/g,(e,s)=>{if(/^['"`]/.test(s))return e;const o=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!o.test(t))return e;const a=o.exec(t);if(a){const h=a.at(1);if(Ct.some(l=>h==null?void 0:h.includes(l)))return e}return"styled('div',"}),Bt=(t,e)=>{try{const s=d.readFileSync(c.join(e,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
19
+ `;d.writeFileSync(st,Q);const Nt=l.join(s,"cache/config-cache.json");d.writeFileSync(Nt,JSON.stringify(r,null,2))},yt=t=>t.replace(/styled\(([^"'`{,]+),/g,(e,s)=>{if(/^['"`]/.test(s))return e;const o=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!o.test(t))return e;const a=o.exec(t);if(a){const g=a.at(1);if(Ct.some(f=>g==null?void 0:g.includes(f)))return e}return"styled('div',"}),Bt=(t,e)=>{try{const s=d.readFileSync(l.join(e,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
18
20
 
19
21
  ${t}`:`globalThis.saltyConfig = {};
20
22
 
21
- ${t}`}catch{return t}},et=async(t,e,s)=>{const n=z(e),o=c.join(s,"./temp");d.existsSync(o)||d.mkdirSync(o);const r=c.parse(e);let a=d.readFileSync(e,"utf8");a=yt(a),a=Bt(a,t);const h=c.join(s,"js",n+".js"),F=await at(t),l=c.join(t,(F==null?void 0:F.configDir)||"","salty.config.ts"),y=Ft(l),$=await St(t);await gt.build({stdin:{contents:a,sourcefile:r.base,resolveDir:r.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:h,format:$,target:["node20"],keepNames:!0,external:y,packages:"external",plugins:[{name:"test",setup:p=>{p.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},b=>{const C=d.readFileSync(b.path,"utf8");return{contents:yt(C),loader:"ts"}})}}]});const m=Date.now();return{contents:await import(`${h}?t=${m}`),outputFilePath:h}},Gt=async t=>{const e=await A(t),s=c.join(e,"cache/config-cache.json"),n=d.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ct=async t=>{const e=await Gt(t),s=await A(t),n=c.join(s,"salty.config.js"),o=Date.now(),{config:r}=await import(`${n}?t=${o}`);return Z(r,e)},lt=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Kt=async(t,e=lt(),s=!0)=>{try{const n=Date.now();e?it.info("Generating CSS in production mode! 🔥"):it.info("Generating CSS in development mode! 🚀");const o=[],r=[],a=await A(t),h=c.join(a,"index.css");s&&(()=>{d.existsSync(a)&&_t.execSync("rm -rf "+a),d.mkdirSync(a,{recursive:!0}),d.mkdirSync(c.join(a,"css")),d.mkdirSync(c.join(a,"types")),d.mkdirSync(c.join(a,"js")),d.mkdirSync(c.join(a,"cache"))})();const l=new Set,y=new Set;async function $(f){const w=["node_modules","saltygen"],g=d.statSync(f);if(g.isDirectory()){const u=d.readdirSync(f);if(w.some(x=>f.includes(x)))return;await Promise.all(u.map(x=>$(c.join(f,x))))}else if(g.isFile()&&q(f)){l.add(f);const S=d.readFileSync(f,"utf8");/define[\w\d]+\(/.test(S)&&y.add(f)}}await $(t),await Lt(t,y);const m={keyframes:[],components:[],classNames:[]};await Promise.all([...l].map(async f=>{const{contents:w}=await et(t,f,a);Object.entries(w).forEach(([g,u])=>{u.isKeyframes?m.keyframes.push({value:u,src:f,name:g}):u.isClassName?m.classNames.push({...u,src:f,name:g}):u.generator&&m.components.push({...u,src:f,name:g})})}));const i=await ct(t);for(const f of m.keyframes){const{value:w}=f,g=`a_${w.animationName}.css`,u=`css/${g}`,S=c.join(a,u);o.push(g),d.writeFileSync(S,w.css)}const p={};for(const f of m.components){const{src:w,name:g}=f,u=f.generator._withBuildContext({callerName:g,isProduction:e,config:i});r[u.priority]||(r[u.priority]=[]);const S=await u.css;if(!S)continue;r[u.priority].push(u.cssFileName);const x=`css/${u.cssFileName}`,V=c.join(a,x);d.writeFileSync(V,S),i.importStrategy==="component"&&(p[w]?p[w].push(u.cssFileName):p[w]=[u.cssFileName])}for(const f of m.classNames){const{src:w,name:g}=f,u=f.generator._withBuildContext({callerName:g,isProduction:e,config:i}),S=await u.css;if(!S)continue;r[0].push(u.cssFileName);const x=`css/${u.cssFileName}`,V=c.join(a,x);d.writeFileSync(V,S),i.importStrategy==="component"&&(p[w]?p[w].push(u.cssFileName):p[w]=[u.cssFileName])}i.importStrategy==="component"&&Object.entries(p).forEach(([f,w])=>{const g=w.map(H=>`@import url('./${H}');`).join(`
22
- `),u=z(f,6),S=c.parse(f),x=R(S.name),V=c.join(a,`css/f_${x}-${u}.css`);d.writeFileSync(V,g)});const b=o.map(f=>`@import url('./css/${f}');`).join(`
23
+ ${t}`}catch{return t}},et=async(t,e,s)=>{const n=v(e),o=l.join(s,"./temp");d.existsSync(o)||d.mkdirSync(o);const r=l.parse(e);let a=d.readFileSync(e,"utf8");a=yt(a),a=Bt(a,t);const g=l.join(s,"js",n+".js"),C=await at(t),f=l.join(t,(C==null?void 0:C.configDir)||"","salty.config.ts"),p=Ft(f),w=await St(t);await gt.build({stdin:{contents:a,sourcefile:r.base,resolveDir:r.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:g,format:w,target:["node20"],keepNames:!0,external:p,packages:"external",plugins:[{name:"test",setup:i=>{i.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},y=>{const k=d.readFileSync(y.path,"utf8");return{contents:yt(k),loader:"ts"}})}}]});const $=Date.now();return{contents:await import(`${g}?t=${$}`),outputFilePath:g}},Gt=async t=>{const e=await z(t),s=l.join(e,"cache/config-cache.json"),n=d.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ct=async t=>{const e=await Gt(t),s=await z(t),n=l.join(s,"salty.config.js"),o=Date.now(),{config:r}=await import(`${n}?t=${o}`);return Z(r,e)},lt=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Kt=async(t,e=lt(),s=!0)=>{try{const n=Date.now();e?it.info("Generating CSS in production mode! 🔥"):it.info("Generating CSS in development mode! 🚀");const o=[],r=[],a=await z(t),g=l.join(a,"index.css");s&&(()=>{d.existsSync(a)&&_t.execSync("rm -rf "+a),d.mkdirSync(a,{recursive:!0}),d.mkdirSync(l.join(a,"css")),d.mkdirSync(l.join(a,"types")),d.mkdirSync(l.join(a,"js")),d.mkdirSync(l.join(a,"cache"))})();const f=new Set,p=new Set;async function w(c){const h=["node_modules","saltygen"],b=d.statSync(c);if(b.isDirectory()){const u=d.readdirSync(c);if(h.some(N=>c.includes(N)))return;await Promise.all(u.map(N=>w(l.join(c,N))))}else if(b.isFile()&&q(c)){f.add(c);const S=d.readFileSync(c,"utf8");/define[\w\d]+\(/.test(S)&&p.add(c)}}await w(t),await Lt(t,p);const $={keyframes:[],components:[],classNames:[]};await Promise.all([...f].map(async c=>{const{contents:h}=await et(t,c,a);Object.entries(h).forEach(([b,u])=>{u.isKeyframes?$.keyframes.push({value:u,src:c,name:b}):u.isClassName?$.classNames.push({...u,src:c,name:b}):u.generator&&$.components.push({...u,src:c,name:b})})}));const m=await ct(t);for(const c of $.keyframes){const{value:h}=c,b=`a_${h.animationName}.css`,u=`css/${b}`,S=l.join(a,u);o.push(b),d.writeFileSync(S,h.css)}const i={};for(const c of $.components){const{src:h,name:b}=c;i[h]||(i[h]=[]);const u=c.generator._withBuildContext({callerName:b,isProduction:e,config:m});r[u.priority]||(r[u.priority]=[]);const S=await u.css;if(!S)continue;r[u.priority].push(u.cssFileName);const N=`css/${u.cssFileName}`,M=l.join(a,N);d.writeFileSync(M,S),m.importStrategy==="component"&&i[h].push(u.cssFileName)}for(const c of $.classNames){const{src:h,name:b}=c;i[h]||(i[h]=[]);const u=c.generator._withBuildContext({callerName:b,isProduction:e,config:m}),S=await u.css;if(!S)continue;r[0].push(u.cssFileName);const N=`css/${u.cssFileName}`,M=l.join(a,N);d.writeFileSync(M,S),m.importStrategy==="component"&&i[h].push(u.cssFileName)}m.importStrategy==="component"&&Object.entries(i).forEach(([c,h])=>{const b=h.map(H=>`@import url('./${H}');`).join(`
24
+ `),u=v(c,6),S=l.parse(c),N=V(S.name),M=l.join(a,`css/f_${N}-${u}.css`);d.writeFileSync(M,b||"/* Empty file */")});const y=o.map(c=>`@import url('./css/${c}');`).join(`
23
25
  `);let _=`@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
24
26
 
25
- ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(f=>{try{return d.readFileSync(c.join(a,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
27
+ ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(c=>{try{return d.readFileSync(l.join(a,"css",c),"utf8").length>0}catch{return!1}}).map(c=>`@import url('./css/${c}');`).join(`
26
28
  `)}
27
- ${b}`;if(i.importStrategy!=="component"){const f=r.reduce((w,g,u)=>{const S=g.reduce((L,W)=>{var Q;const K=c.join(a,"css",W),st=d.readFileSync(K,"utf8"),U=((Q=/.*-([^-]+)-\d+.css/.exec(W))==null?void 0:Q.at(1))||z(K,6);return L.includes(U)?L:`${L}
29
+ ${y}`;if(m.importStrategy!=="component"){const c=r.reduce((h,b,u)=>{const S=b.reduce((L,W)=>{var Q;const K=l.join(a,"css",W),st=d.readFileSync(K,"utf8"),U=((Q=/.*-([^-]+)-\d+.css/.exec(W))==null?void 0:Q.at(1))||v(K,6);return L.includes(U)?L:`${L}
28
30
  /*start:${U}-${W}*/
29
31
  ${st}
30
32
  /*end:${U}*/
31
- `},""),x=`l_${u}.css`,V=c.join(a,"css",x),H=`@layer l${u} { ${S}
32
- }`;return d.writeFileSync(V,H),`${w}
33
- @import url('./css/${x}');`},"");_+=f}d.writeFileSync(h,_);const P=Date.now()-n,E=P<200?"🔥":P<500?"🚀":P<1e3?"🎉":P<2e3?"🚗":P<5e3?"🤔":"🥴";it.info(`Generated CSS in ${P}ms! ${E}`)}catch(n){console.error(n)}},Ut=async(t,e,s=lt())=>{try{const n=await A(t);if(q(e)){const r=[],a=await ct(t),{contents:h}=await et(t,e,n);for(const[F,l]of Object.entries(h)){if(l.isKeyframes&&l.css){const b=`css/${`a_${l.animationName}.css`}`,C=c.join(n,b);d.writeFileSync(C,await l.css);return}if(l.isClassName){const p=l.generator._withBuildContext({callerName:F,isProduction:s,config:a}),b=await p.css;if(!b)continue;r[0].push(p.cssFileName);const C=`css/${p.cssFileName}`,k=c.join(n,C);d.writeFileSync(k,b)}if(!l.generator)return;const y=l.generator._withBuildContext({callerName:F,isProduction:s,config:a}),$=await y.css;if(!$)continue;const m=`css/${y.cssFileName}`,i=c.join(n,m);d.writeFileSync(i,$),r[y.priority]||(r[y.priority]=[]),r[y.priority].push(y.cssFileName)}if(a.importStrategy!=="component")r.forEach((F,l)=>{const y=`l_${l}.css`,$=c.join(n,"css",y);let m=d.readFileSync($,"utf8");F.forEach(i=>{var k;const p=c.join(n,"css",i),b=((k=/.*-([^-]+)-\d+.css/.exec(i))==null?void 0:k.at(1))||z(p,6);if(!m.includes(b)){const O=d.readFileSync(p,"utf8"),_=`/*start:${b}-${i}*/
34
- ${O}
35
- /*end:${b}*/
36
- `;m=`${m.replace(/\}$/,"")}
33
+ `},""),N=`l_${u}.css`,M=l.join(a,"css",N),H=`@layer l${u} { ${S}
34
+ }`;return d.writeFileSync(M,H),`${h}
35
+ @import url('./css/${N}');`},"");_+=c}d.writeFileSync(g,_);const j=Date.now()-n,D=j<200?"🔥":j<500?"🚀":j<1e3?"🎉":j<2e3?"🚗":j<5e3?"🤔":"🥴";it.info(`Generated CSS in ${j}ms! ${D}`)}catch(n){console.error(n)}},Ut=async(t,e,s=lt())=>{try{const n=await z(t);if(q(e)){const r=[],a=await ct(t),{contents:g}=await et(t,e,n);for(const[C,f]of Object.entries(g)){if(f.isKeyframes&&f.css){const y=`css/${`a_${f.animationName}.css`}`,k=l.join(n,y);d.writeFileSync(k,await f.css);return}if(f.isClassName){const i=f.generator._withBuildContext({callerName:C,isProduction:s,config:a}),y=await i.css;if(!y)continue;r[0].push(i.cssFileName);const k=`css/${i.cssFileName}`,P=l.join(n,k);d.writeFileSync(P,y)}if(!f.generator)return;const p=f.generator._withBuildContext({callerName:C,isProduction:s,config:a}),w=await p.css;if(!w)continue;const $=`css/${p.cssFileName}`,m=l.join(n,$);d.writeFileSync(m,w),r[p.priority]||(r[p.priority]=[]),r[p.priority].push(p.cssFileName)}if(a.importStrategy!=="component")r.forEach((C,f)=>{const p=`l_${f}.css`,w=l.join(n,"css",p);let $=d.readFileSync(w,"utf8");C.forEach(m=>{var P;const i=l.join(n,"css",m),y=((P=/.*-([^-]+)-\d+.css/.exec(m))==null?void 0:P.at(1))||v(i,6);if(!$.includes(y)){const R=d.readFileSync(i,"utf8"),_=`/*start:${y}-${m}*/
36
+ ${R}
37
+ /*end:${y}*/
38
+ `;$=`${$.replace(/\}$/,"")}
37
39
  ${_}
38
- }`}}),d.writeFileSync($,m)});else{const F=r.flat().map(i=>`@import url('./${i}');`).join(`
39
- `),l=z(e,6),y=c.parse(e),$=R(y.name),m=c.join(n,`css/f_${$}-${l}.css`);d.writeFileSync(m,F)}}}catch(n){console.error(n)}},Qt=async(t,e,s=lt())=>{try{const n=await A(t);if(q(e)){const r=d.readFileSync(e,"utf8");r.replace(/^(?!export\s)const\s.*/gm,y=>`export ${y}`)!==r&&await tt.writeFile(e,r);const h=await ct(t),{contents:F}=await et(t,e,n);let l=r;if(Object.entries(F).forEach(([y,$])=>{var u;if($.isKeyframes||!$.generator)return;const m=$.generator._withBuildContext({callerName:y,isProduction:s,config:h}),i=new RegExp(`\\s${y}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(r);if(!i)return console.error("Could not find the original declaration");const p=(u=i.at(1))==null?void 0:u.trim(),b=new RegExp(`\\s${y}[=\\s]+styled\\(`,"g").exec(l);if(!b)return console.error("Could not find the original declaration");const{index:C}=b;let k=!1;const O=setTimeout(()=>k=!0,5e3);let _=0,D=!1,P=0;for(;!D&&!k;){const S=l[C+_];S==="("&&P++,S===")"&&P--,P===0&&S===")"&&(D=!0),_>l.length&&(k=!0),_++}if(!k)clearTimeout(O);else throw new Error("Failed to find the end of the styled call and timed out");const E=C+_,f=l.slice(C,E),w=l,g=` ${y} = styled(${p}, "${m.classNames}", ${JSON.stringify(m.clientProps)});`;l=l.replace(f,g),w===l&&console.error("Minimize file failed to change content",{name:y,tagName:p})}),h.importStrategy==="component"){const y=z(e,6),$=c.parse(e);l=`import '../../saltygen/css/${`f_${R($.name)}-${y}.css`}';
40
- ${l}`}return l=l.replace("{ styled }","{ styledClient as styled }"),l=l.replace("@salty-css/react/styled","@salty-css/react/styled-client"),l}}catch(n){console.error("Error in minimizeFile:",n)}},mt=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!q(t))return!1;const n=await tt.readFile(t,"utf-8");return!!/.+define[A-Z]\w+/.test(n)},Pt=t=>({name:"stylegen",buildStart:()=>Kt(t),load:async e=>{if(q(e))return await Qt(t,e)},handleHotUpdate:async({file:e,server:s})=>{await mt(e)&&await s.restart()},watchChange:{handler:async e=>{q(e)&&(await mt(e)||await Ut(t,e))}}});exports.default=Pt;exports.saltyPlugin=Pt;
40
+ }`}}),d.writeFileSync(w,$)});else{const C=r.flat().map(m=>`@import url('./${m}');`).join(`
41
+ `),f=v(e,6),p=l.parse(e),w=V(p.name),$=l.join(n,`css/f_${w}-${f}.css`);d.writeFileSync($,C||"/* Empty file */")}}}catch(n){console.error(n)}},Qt=async(t,e,s=lt())=>{try{const n=await z(t);if(q(e)){const r=d.readFileSync(e,"utf8");r.replace(/^(?!export\s)const\s.*/gm,p=>`export ${p}`)!==r&&await tt.writeFile(e,r);const g=await ct(t),{contents:C}=await et(t,e,n);let f=r;if(Object.entries(C).forEach(([p,w])=>{var u;if(w.isKeyframes||!w.generator)return;const $=w.generator._withBuildContext({callerName:p,isProduction:s,config:g}),m=new RegExp(`\\s${p}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(r);if(!m)return console.error("Could not find the original declaration");const i=(u=m.at(1))==null?void 0:u.trim(),y=new RegExp(`\\s${p}[=\\s]+styled\\(`,"g").exec(f);if(!y)return console.error("Could not find the original declaration");const{index:k}=y;let P=!1;const R=setTimeout(()=>P=!0,5e3);let _=0,T=!1,j=0;for(;!T&&!P;){const S=f[k+_];S==="("&&j++,S===")"&&j--,j===0&&S===")"&&(T=!0),_>f.length&&(P=!0),_++}if(!P)clearTimeout(R);else throw new Error("Failed to find the end of the styled call and timed out");const D=k+_,c=f.slice(k,D),h=f,b=` ${p} = styled(${i}, "${$.classNames}", ${JSON.stringify($.clientProps)});`;f=f.replace(c,b),h===f&&console.error("Minimize file failed to change content",{name:p,tagName:i})}),g.importStrategy==="component"){const p=v(e,6),w=l.parse(e);f=`import '../../saltygen/css/${`f_${V(w.name)}-${p}.css`}';
42
+ ${f}`}return f=f.replace("{ styled }","{ styledClient as styled }"),f=f.replace("@salty-css/react/styled","@salty-css/react/styled-client"),f}}catch(n){console.error("Error in minimizeFile:",n)}},mt=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!q(t))return!1;const n=await tt.readFile(t,"utf-8");return!!/.+define[A-Z]\w+/.test(n)},xt=t=>({name:"stylegen",buildStart:()=>Kt(t),load:async e=>{if(q(e))return await Qt(t,e)},handleHotUpdate:async({file:e,server:s})=>{await mt(e)&&await s.restart()},watchChange:{handler:async e=>{q(e)&&(await mt(e)||await Ut(t,e))}}});exports.default=xt;exports.saltyPlugin=xt;
package/index.js CHANGED
@@ -4,33 +4,33 @@ import { join as u, parse as et } from "path";
4
4
  import { existsSync as ct, mkdirSync as I, statSync as Et, readdirSync as Tt, readFileSync as M, writeFileSync as D } from "fs";
5
5
  import { readFile as lt, writeFile as Ot } from "fs/promises";
6
6
  import { createLogger as Vt, format as it, transports as Mt } from "winston";
7
- const ht = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), Rt = (t, e) => {
7
+ const yt = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), Rt = (t, e) => {
8
8
  let s = "", n;
9
- for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = ht(n % 52) + s;
10
- return s = ht(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
11
- }, Jt = (t, e) => {
9
+ for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = yt(n % 52) + s;
10
+ return s = yt(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
11
+ }, At = (t, e) => {
12
12
  let s = e.length;
13
13
  for (; s; ) t = t * 33 ^ e.charCodeAt(--s);
14
14
  return t;
15
15
  }, z = (t, e = 5) => {
16
- const s = Jt(5381, JSON.stringify(t)) >>> 0;
16
+ const s = At(5381, JSON.stringify(t)) >>> 0;
17
17
  return Rt(s, e);
18
18
  };
19
- function R(t) {
20
- return t ? typeof t != "string" ? R(String(t)) : t.replace(/[\s.]/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "-" : "") + e.toLowerCase()) : "";
19
+ function A(t) {
20
+ return t ? typeof t != "string" ? A(String(t)) : t.replace(/[\s.]/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "-" : "") + e.toLowerCase()) : "";
21
21
  }
22
- const At = (t) => (e) => {
22
+ const Jt = (t) => (e) => {
23
23
  if (typeof e != "string" || !t) return;
24
24
  let s = e;
25
25
  const n = [];
26
26
  return Object.values(t).forEach((o) => {
27
27
  const { pattern: r, transform: a } = o;
28
28
  s = s.replace(r, (h) => {
29
- const { value: S, css: c } = a(h);
30
- return c && n.push(c), S;
29
+ const { value: j, css: l } = a(h);
30
+ return l && n.push(l), j;
31
31
  });
32
32
  }), { transformed: s, additionalCss: n };
33
- }, bt = (t) => (e) => typeof e != "string" || !/\{[^{}]+\}/g.test(e) ? void 0 : { transformed: e.replace(/\{([^{}]+)\}/g, (...o) => `var(--${R(o[1].replaceAll(".", "-"))})`) }, Wt = bt(), zt = [
33
+ }, bt = (t) => (e) => typeof e != "string" || !/\{[^{}]+\}/g.test(e) ? void 0 : { transformed: e.replace(/\{([^{}]+)\}/g, (...o) => `var(--${A(o[1].replaceAll(".", "-"))})`) }, Wt = bt(), zt = [
34
34
  "top",
35
35
  "right",
36
36
  "bottom",
@@ -51,70 +51,72 @@ const At = (t) => (e) => {
51
51
  /.*size.*/,
52
52
  /.*thickness.*/,
53
53
  /.*font-size.*/
54
- ], vt = (t, e, s) => zt.some((o) => typeof o == "string" ? o === t : o.test(t)) ? `${e}px` : `${e}`, Zt = ["Webkit", "Moz", "ms", "O"], Ht = (t) => t.startsWith("-") ? t : Zt.some((e) => t.startsWith(e)) ? `-${R(t)}` : R(t), tt = async (t, e = "", s, n = !1) => {
54
+ ], vt = (t, e, s) => zt.some((o) => typeof o == "string" ? o === t : o.test(t)) ? `${e}px` : `${e}`, Zt = ["Webkit", "Moz", "ms", "O"], Ht = (t) => t.startsWith("-") ? t : Zt.some((e) => t.startsWith(e)) ? `-${A(t)}` : A(t), tt = async (t, e = "", s, n = !1) => {
55
55
  if (!t) throw new Error("No styles provided to parseStyles function!");
56
56
  const o = /* @__PURE__ */ new Set(), a = Object.entries(t).map(async ([m, i]) => {
57
- const d = m.trim(), w = Ht(d), j = (E, k = ";") => `${w}:${E}${k}`;
57
+ const p = m.trim(), P = Ht(p), F = (k, O = ";") => `${P}:${k}${O}`;
58
58
  if (typeof i == "function" && (i = i({ scope: e, config: s })), i instanceof Promise && (i = await i), typeof i == "object") {
59
59
  if (!i) return;
60
- if (i.isColor) return j(i.toString());
61
- if (d === "defaultVariants") return;
62
- if (d === "variants") {
63
- const _ = Object.entries(i);
64
- for (const [N, O] of _) {
65
- if (!O) return;
66
- const l = Object.entries(O);
67
- for (const [y, g] of l) {
68
- if (!g) return;
69
- const f = `${e}.${N}-${y}`;
70
- (await tt(g, f, s)).forEach((x) => o.add(x));
60
+ if (i.isColor) return F(i.toString());
61
+ if (p === "defaultVariants") return;
62
+ if (p === "variants") {
63
+ const C = Object.entries(i);
64
+ for (const [_, c] of C) {
65
+ if (!c) return;
66
+ const y = Object.entries(c);
67
+ for (const [w, f] of y) {
68
+ if (!f) return;
69
+ const b = `${e}.${_}-${w}`;
70
+ (await tt(f, b, s)).forEach((V) => o.add(V));
71
71
  }
72
72
  }
73
73
  return;
74
74
  }
75
- if (d === "compoundVariants") {
76
- for (const _ of i) {
77
- const { css: N, ...O } = _, l = Object.entries(O).reduce((g, [f, b]) => `${g}.${f}-${b}`, e);
78
- (await tt(N, l, s)).forEach((g) => o.add(g));
75
+ if (p === "compoundVariants") {
76
+ for (const C of i) {
77
+ const { css: _, ...c } = C, y = Object.entries(c).reduce((f, [b, N]) => `${f}.${b}-${N}`, e);
78
+ (await tt(_, y, s)).forEach((f) => o.add(f));
79
79
  }
80
80
  return;
81
81
  }
82
- if (d.startsWith("@")) {
83
- const _ = d, N = await Q(i, e, s), O = `${_} { ${N} }`;
84
- o.add(O);
82
+ if (p.startsWith("@")) {
83
+ const C = p, _ = await Q(i, e, s), c = `${C} { ${_} }`;
84
+ o.add(c);
85
85
  return;
86
86
  }
87
- const E = m.includes("&") ? d.replace("&", e) : d.startsWith(":") ? `${e}${d}` : `${e} ${d}`;
88
- (await tt(i, E, s)).forEach((_) => o.add(_));
87
+ const k = m.includes("&") ? p.replace("&", e) : p.startsWith(":") ? `${e}${p}` : `${e} ${p}`;
88
+ (await tt(i, k, s)).forEach((C) => o.add(C));
89
89
  return;
90
90
  }
91
91
  if (typeof i == "number") {
92
- const E = vt(w, i);
93
- return j(E);
92
+ const k = vt(P, i);
93
+ return F(k);
94
94
  }
95
95
  if (typeof i != "string")
96
96
  if ("toString" in i) i = i.toString();
97
- else throw new Error(`Invalid value type for property ${w}`);
98
- return j(i);
99
- }), { modifiers: h } = {}, S = [bt(), At(h)], p = (await Promise.all(a).then((m) => Promise.all(
100
- m.map((i) => S.reduce(async (d, w) => {
101
- const j = await d;
102
- if (!j) return j;
103
- const P = await w(j);
104
- if (!P) return j;
105
- const { transformed: E, additionalCss: k } = P;
106
- let _ = "";
107
- if (k)
108
- for (const N of k)
109
- _ += await Q(N, "");
110
- return `${_}${E}`;
97
+ else throw new Error(`Invalid value type for property ${P}`);
98
+ return F(i);
99
+ }), { modifiers: h } = {}, j = [bt(), Jt(h)], d = (await Promise.all(a).then((m) => Promise.all(
100
+ m.map((i) => j.reduce(async (p, P) => {
101
+ const F = await p;
102
+ if (!F) return F;
103
+ const R = await P(F);
104
+ if (!R) return F;
105
+ const { transformed: k, additionalCss: O } = R;
106
+ let C = "";
107
+ if (O)
108
+ for (const _ of O)
109
+ C += await Q(_, "");
110
+ return `${C}${k}`;
111
111
  }, Promise.resolve(i)))
112
- ))).join(`
113
- `);
114
- if (!p.trim()) return o;
115
- const $ = e ? `${e} { ${p} }` : p;
116
- return o.add($), o;
117
- }, Q = async (t, e, s, n = !1) => [...await tt(t, e, s, n)].join(`
112
+ ))).filter((m) => m !== void 0).join(`
113
+ `);
114
+ if (!d.trim()) return Array.from(o);
115
+ const g = e ? `${e} {
116
+ ${d}
117
+ }` : d;
118
+ return o.has(g) ? Array.from(o) : [g, ...o];
119
+ }, Q = async (t, e, s, n = !1) => (await tt(t, e, s, n)).join(`
118
120
  `), Ct = async (t, e = []) => {
119
121
  if (!t) return "";
120
122
  const s = [], n = {};
@@ -125,7 +127,7 @@ const At = (t) => (e) => {
125
127
  } else
126
128
  n[o] = r;
127
129
  if (Object.keys(n).length) {
128
- const o = e.map(R).join("-"), r = "t_" + z(o, 4), a = await Q(n, `.${o}, .${r}`);
130
+ const o = e.map(A).join("-"), r = "t_" + z(o, 4), a = await Q(n, `.${o}, .${r}`);
129
131
  s.push(a);
130
132
  }
131
133
  return s.join(`
@@ -156,8 +158,8 @@ const Ft = async (t) => {
156
158
  format: it.combine(it.colorize(), it.cli()),
157
159
  transports: [new Mt.Console({})]
158
160
  });
159
- function Nt(t) {
160
- return t ? typeof t != "string" ? Nt(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "." : "") + e.toLowerCase()) : "";
161
+ function xt(t) {
162
+ return t ? typeof t != "string" ? xt(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "." : "") + e.toLowerCase()) : "";
161
163
  }
162
164
  const Kt = {
163
165
  /** Set box model to border-box */
@@ -209,7 +211,7 @@ const Kt = {
209
211
  externalModules: [],
210
212
  rcFile: void 0,
211
213
  destDir: void 0
212
- }, xt = (t) => {
214
+ }, Nt = (t) => {
213
215
  if (W.externalModules.length > 0) return W.externalModules;
214
216
  const s = M(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
215
217
  if (!s) return [];
@@ -230,7 +232,7 @@ const Kt = {
230
232
  const e = await kt(t), s = (n = e.projects) == null ? void 0 : n.find((r) => t.endsWith(r.dir || ""));
231
233
  return s || ((o = e.projects) == null ? void 0 : o.find((r) => r.dir === e.defaultProject));
232
234
  }, Ut = async (t) => {
233
- const e = await ft(t), s = await v(t), n = u(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), o = u(s, "salty.config.js"), r = await Ft(t), a = xt(n);
235
+ const e = await ft(t), s = await v(t), n = u(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), o = u(s, "salty.config.js"), r = await Ft(t), a = Nt(n);
234
236
  await wt.build({
235
237
  entryPoints: [n],
236
238
  minify: !0,
@@ -240,8 +242,8 @@ const Kt = {
240
242
  format: r,
241
243
  external: a
242
244
  });
243
- const h = Date.now(), { config: S } = await import(`${o}?t=${h}`);
244
- return S;
245
+ const h = Date.now(), { config: j } = await import(`${o}?t=${h}`);
246
+ return j;
245
247
  }, qt = async (t, e) => {
246
248
  var pt, mt;
247
249
  const s = await v(t), n = {
@@ -251,46 +253,46 @@ const Kt = {
251
253
  templates: []
252
254
  };
253
255
  await Promise.all(
254
- [...e].map(async (C) => {
255
- const { contents: F, outputFilePath: A } = await st(t, C, s);
256
- Object.entries(F).forEach(([T, V]) => {
257
- V.isMedia ? n.mediaQueries.push([T, V]) : V.isGlobalDefine ? n.globalStyles.push(V) : V.isDefineVariables ? n.variables.push(V) : V.isDefineTemplates && n.templates.push(V._setPath(A));
256
+ [...e].map(async (S) => {
257
+ const { contents: x, outputFilePath: J } = await st(t, S, s);
258
+ Object.entries(x).forEach(([E, T]) => {
259
+ T.isMedia ? n.mediaQueries.push([E, T]) : T.isGlobalDefine ? n.globalStyles.push(T) : T.isDefineVariables ? n.variables.push(T) : T.isDefineTemplates && n.templates.push(T._setPath(J));
258
260
  });
259
261
  })
260
262
  );
261
- const o = await Ut(t), r = { ...o }, a = /* @__PURE__ */ new Set(), h = (C, F = []) => C ? Object.entries(C).flatMap(([A, T]) => {
262
- if (!T) return;
263
- if (typeof T == "object") return h(T, [...F, A]);
264
- const V = Nt(A), ot = R(A), rt = [...F, V].join(".");
263
+ const o = await Ut(t), r = { ...o }, a = /* @__PURE__ */ new Set(), h = (S, x = []) => S ? Object.entries(S).flatMap(([J, E]) => {
264
+ if (!E) return;
265
+ if (typeof E == "object") return h(E, [...x, J]);
266
+ const T = xt(J), ot = A(J), rt = [...x, T].join(".");
265
267
  a.add(`"${rt}"`);
266
- const Y = [...F.map(R), ot].join("-"), gt = Wt(T);
267
- return gt ? `--${Y}: ${gt.transformed};` : `--${Y}: ${T};`;
268
- }) : [], S = (C) => C ? Object.entries(C).flatMap(([F, A]) => {
269
- const T = h(A);
270
- return F === "base" ? T.join("") : `${F} { ${T.join("")} }`;
271
- }) : [], c = (C) => C ? Object.entries(C).flatMap(([F, A]) => Object.entries(A).flatMap(([T, V]) => {
272
- const ot = h(V, [F]), rt = `.${F}-${T}, [data-${F}="${T}"]`, Y = ot.join("");
268
+ const Y = [...x.map(A), ot].join("-"), ht = Wt(E);
269
+ return ht ? `--${Y}: ${ht.transformed};` : `--${Y}: ${E};`;
270
+ }) : [], j = (S) => S ? Object.entries(S).flatMap(([x, J]) => {
271
+ const E = h(J);
272
+ return x === "base" ? E.join("") : `${x} { ${E.join("")} }`;
273
+ }) : [], l = (S) => S ? Object.entries(S).flatMap(([x, J]) => Object.entries(J).flatMap(([E, T]) => {
274
+ const ot = h(T, [x]), rt = `.${x}-${E}, [data-${x}="${E}"]`, Y = ot.join("");
273
275
  return `${rt} { ${Y} }`;
274
- })) : [], p = (C) => ({ ...C, responsive: void 0, conditional: void 0 }), $ = (C) => n.variables.map((F) => C === "static" ? p(F._current) : F._current[C]), m = B(p(o.variables), $("static")), i = h(m), d = B((pt = o.variables) == null ? void 0 : pt.responsive, $("responsive")), w = S(d), j = B((mt = o.variables) == null ? void 0 : mt.conditional, $("conditional")), P = c(j), E = u(s, "css/_variables.css"), k = `:root { ${i.join("")} ${w.join("")} } ${P.join("")}`;
275
- D(E, k), r.staticVariables = m;
276
- const _ = u(s, "css/_global.css"), N = B(o.global, n.globalStyles), O = await Q(N, "");
277
- D(_, `@layer global { ${O} }`);
278
- const l = u(s, "css/_reset.css"), g = o.reset === "none" ? {} : typeof o.reset == "object" ? o.reset : Kt, f = await Q(g, "");
279
- D(l, `@layer reset { ${f} }`);
280
- const b = u(s, "css/_templates.css"), x = B(o.templates, n.templates), J = await Ct(x), K = It(x);
281
- D(b, `@layer templates { ${J} }`), r.templates = x;
276
+ })) : [], d = (S) => ({ ...S, responsive: void 0, conditional: void 0 }), g = (S) => n.variables.map((x) => S === "static" ? d(x._current) : x._current[S]), $ = B(d(o.variables), g("static")), m = h($), i = B((pt = o.variables) == null ? void 0 : pt.responsive, g("responsive")), p = j(i), P = B((mt = o.variables) == null ? void 0 : mt.conditional, g("conditional")), F = l(P), R = u(s, "css/_variables.css"), k = `:root { ${m.join("")} ${p.join("")} } ${F.join("")}`;
277
+ D(R, k), r.staticVariables = $;
278
+ const O = u(s, "css/_global.css"), C = B(o.global, n.globalStyles), _ = await Q(C, "");
279
+ D(O, `@layer global { ${_} }`);
280
+ const c = u(s, "css/_reset.css"), w = o.reset === "none" ? {} : typeof o.reset == "object" ? o.reset : Kt, f = await Q(w, "");
281
+ D(c, `@layer reset { ${f} }`);
282
+ const b = u(s, "css/_templates.css"), N = B(o.templates, n.templates), V = await Ct(N), K = It(N);
283
+ D(b, `@layer templates { ${V} }`), r.templates = N;
282
284
  const L = Lt(n.templates);
283
- r.templatePaths = Object.fromEntries(Object.entries(L).map(([C, F]) => [C, F._path]));
285
+ r.templatePaths = Object.fromEntries(Object.entries(L).map(([S, x]) => [S, x._path]));
284
286
  const { mediaQueries: Z } = n;
285
- r.mediaQueries = Object.fromEntries(Z.map(([C, F]) => [`@${C}`, F]));
286
- const U = Z.map(([C]) => `'@${C}'`).join(" | "), nt = u(s, "types/css-tokens.d.ts"), X = `
287
+ r.mediaQueries = Object.fromEntries(Z.map(([S, x]) => [`@${S}`, x]));
288
+ const U = Z.map(([S]) => `'@${S}'`).join(" | "), nt = u(s, "types/css-tokens.d.ts"), X = `
287
289
  // Variable types
288
290
  type VariableTokens = ${[...a].join("|")};
289
291
  type PropertyValueToken = \`{\${VariableTokens}}\`;
290
292
 
291
293
  // Template types
292
294
  type TemplateTokens = {
293
- ${Object.entries(K).map(([C, F]) => `${C}?: ${F}`).join(`
295
+ ${Object.entries(K).map(([S, x]) => `${S}?: ${x}`).join(`
294
296
  `)}
295
297
  }
296
298
 
@@ -300,14 +302,14 @@ const Kt = {
300
302
  D(nt, X);
301
303
  const Dt = u(s, "cache/config-cache.json");
302
304
  D(Dt, JSON.stringify(r, null, 2));
303
- }, yt = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
305
+ }, gt = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
304
306
  if (/^['"`]/.test(s)) return e;
305
307
  const o = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
306
308
  if (!o.test(t)) return e;
307
309
  const a = o.exec(t);
308
310
  if (a) {
309
311
  const h = a.at(1);
310
- if (Pt.some((c) => h == null ? void 0 : h.includes(c))) return e;
312
+ if (Pt.some((l) => h == null ? void 0 : h.includes(l))) return e;
311
313
  }
312
314
  return "styled('div',";
313
315
  }), Xt = (t, e) => {
@@ -326,8 +328,8 @@ ${t}`;
326
328
  ct(o) || I(o);
327
329
  const r = et(e);
328
330
  let a = M(e, "utf8");
329
- a = yt(a), a = Xt(a, t);
330
- const h = u(s, "js", n + ".js"), S = await ft(t), c = u(t, (S == null ? void 0 : S.configDir) || "", "salty.config.ts"), p = xt(c), $ = await Ft(t);
331
+ a = gt(a), a = Xt(a, t);
332
+ const h = u(s, "js", n + ".js"), j = await ft(t), l = u(t, (j == null ? void 0 : j.configDir) || "", "salty.config.ts"), d = Nt(l), g = await Ft(t);
331
333
  await wt.build({
332
334
  stdin: {
333
335
  contents: a,
@@ -339,25 +341,25 @@ ${t}`;
339
341
  treeShaking: !0,
340
342
  bundle: !0,
341
343
  outfile: h,
342
- format: $,
344
+ format: g,
343
345
  target: ["node20"],
344
346
  keepNames: !0,
345
- external: p,
347
+ external: d,
346
348
  packages: "external",
347
349
  plugins: [
348
350
  {
349
351
  name: "test",
350
- setup: (d) => {
351
- d.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (w) => {
352
- const j = M(w.path, "utf8");
353
- return { contents: yt(j), loader: "ts" };
352
+ setup: (i) => {
353
+ i.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (p) => {
354
+ const P = M(p.path, "utf8");
355
+ return { contents: gt(P), loader: "ts" };
354
356
  });
355
357
  }
356
358
  }
357
359
  ]
358
360
  });
359
- const m = Date.now();
360
- return { contents: await import(`${h}?t=${m}`), outputFilePath: h };
361
+ const $ = Date.now();
362
+ return { contents: await import(`${h}?t=${$}`), outputFilePath: h };
361
363
  }, Yt = async (t) => {
362
364
  const e = await v(t), s = u(e, "cache/config-cache.json"), n = M(s, "utf8");
363
365
  if (!n) throw new Error("Could not find config cache file");
@@ -379,96 +381,100 @@ ${t}`;
379
381
  s && (() => {
380
382
  ct(a) && _t("rm -rf " + a), I(a, { recursive: !0 }), I(u(a, "css")), I(u(a, "types")), I(u(a, "js")), I(u(a, "cache"));
381
383
  })();
382
- const c = /* @__PURE__ */ new Set(), p = /* @__PURE__ */ new Set();
383
- async function $(l) {
384
- const y = ["node_modules", "saltygen"], g = Et(l);
385
- if (g.isDirectory()) {
386
- const f = Tt(l);
387
- if (y.some((x) => l.includes(x))) return;
388
- await Promise.all(f.map((x) => $(u(l, x))));
389
- } else if (g.isFile() && G(l)) {
390
- c.add(l);
391
- const b = M(l, "utf8");
392
- /define[\w\d]+\(/.test(b) && p.add(l);
384
+ const l = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Set();
385
+ async function g(c) {
386
+ const y = ["node_modules", "saltygen"], w = Et(c);
387
+ if (w.isDirectory()) {
388
+ const f = Tt(c);
389
+ if (y.some((N) => c.includes(N))) return;
390
+ await Promise.all(f.map((N) => g(u(c, N))));
391
+ } else if (w.isFile() && G(c)) {
392
+ l.add(c);
393
+ const b = M(c, "utf8");
394
+ /define[\w\d]+\(/.test(b) && d.add(c);
393
395
  }
394
396
  }
395
- await $(t), await qt(t, p);
396
- const m = {
397
+ await g(t), await qt(t, d);
398
+ const $ = {
397
399
  keyframes: [],
398
400
  components: [],
399
401
  classNames: []
400
402
  };
401
403
  await Promise.all(
402
- [...c].map(async (l) => {
403
- const { contents: y } = await st(t, l, a);
404
- Object.entries(y).forEach(([g, f]) => {
405
- f.isKeyframes ? m.keyframes.push({
404
+ [...l].map(async (c) => {
405
+ const { contents: y } = await st(t, c, a);
406
+ Object.entries(y).forEach(([w, f]) => {
407
+ f.isKeyframes ? $.keyframes.push({
406
408
  value: f,
407
- src: l,
408
- name: g
409
- }) : f.isClassName ? m.classNames.push({
409
+ src: c,
410
+ name: w
411
+ }) : f.isClassName ? $.classNames.push({
410
412
  ...f,
411
- src: l,
412
- name: g
413
- }) : f.generator && m.components.push({
413
+ src: c,
414
+ name: w
415
+ }) : f.generator && $.components.push({
414
416
  ...f,
415
- src: l,
416
- name: g
417
+ src: c,
418
+ name: w
417
419
  });
418
420
  });
419
421
  })
420
422
  );
421
- const i = await ut(t);
422
- for (const l of m.keyframes) {
423
- const { value: y } = l, g = `a_${y.animationName}.css`, f = `css/${g}`, b = u(a, f);
424
- o.push(g), D(b, y.css);
423
+ const m = await ut(t);
424
+ for (const c of $.keyframes) {
425
+ const { value: y } = c, w = `a_${y.animationName}.css`, f = `css/${w}`, b = u(a, f);
426
+ o.push(w), D(b, y.css);
425
427
  }
426
- const d = {};
427
- for (const l of m.components) {
428
- const { src: y, name: g } = l, f = l.generator._withBuildContext({
429
- callerName: g,
428
+ const i = {};
429
+ for (const c of $.components) {
430
+ const { src: y, name: w } = c;
431
+ i[y] || (i[y] = []);
432
+ const f = c.generator._withBuildContext({
433
+ callerName: w,
430
434
  isProduction: e,
431
- config: i
435
+ config: m
432
436
  });
433
437
  r[f.priority] || (r[f.priority] = []);
434
438
  const b = await f.css;
435
439
  if (!b) continue;
436
440
  r[f.priority].push(f.cssFileName);
437
- const x = `css/${f.cssFileName}`, J = u(a, x);
438
- D(J, b), i.importStrategy === "component" && (d[y] ? d[y].push(f.cssFileName) : d[y] = [f.cssFileName]);
441
+ const N = `css/${f.cssFileName}`, V = u(a, N);
442
+ D(V, b), m.importStrategy === "component" && i[y].push(f.cssFileName);
439
443
  }
440
- for (const l of m.classNames) {
441
- const { src: y, name: g } = l, f = l.generator._withBuildContext({
442
- callerName: g,
444
+ for (const c of $.classNames) {
445
+ const { src: y, name: w } = c;
446
+ i[y] || (i[y] = []);
447
+ const f = c.generator._withBuildContext({
448
+ callerName: w,
443
449
  isProduction: e,
444
- config: i
450
+ config: m
445
451
  }), b = await f.css;
446
452
  if (!b) continue;
447
453
  r[0].push(f.cssFileName);
448
- const x = `css/${f.cssFileName}`, J = u(a, x);
449
- D(J, b), i.importStrategy === "component" && (d[y] ? d[y].push(f.cssFileName) : d[y] = [f.cssFileName]);
454
+ const N = `css/${f.cssFileName}`, V = u(a, N);
455
+ D(V, b), m.importStrategy === "component" && i[y].push(f.cssFileName);
450
456
  }
451
- i.importStrategy === "component" && Object.entries(d).forEach(([l, y]) => {
452
- const g = y.map((K) => `@import url('./${K}');`).join(`
453
- `), f = z(l, 6), b = et(l), x = R(b.name), J = u(a, `css/f_${x}-${f}.css`);
454
- D(J, g);
457
+ m.importStrategy === "component" && Object.entries(i).forEach(([c, y]) => {
458
+ const w = y.map((K) => `@import url('./${K}');`).join(`
459
+ `), f = z(c, 6), b = et(c), N = A(b.name), V = u(a, `css/f_${N}-${f}.css`);
460
+ D(V, w || "/* Empty file */");
455
461
  });
456
- const w = o.map((l) => `@import url('./css/${l}');`).join(`
462
+ const p = o.map((c) => `@import url('./css/${c}');`).join(`
457
463
  `);
458
464
  let k = `@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
459
465
 
460
- ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) => {
466
+ ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((c) => {
461
467
  try {
462
- return M(u(a, "css", l), "utf8").length > 0;
468
+ return M(u(a, "css", c), "utf8").length > 0;
463
469
  } catch {
464
470
  return !1;
465
471
  }
466
- }).map((l) => `@import url('./css/${l}');`).join(`
472
+ }).map((c) => `@import url('./css/${c}');`).join(`
467
473
  `)}
468
- ${w}`;
469
- if (i.importStrategy !== "component") {
470
- const l = r.reduce((y, g, f) => {
471
- const b = g.reduce((L, Z) => {
474
+ ${p}`;
475
+ if (m.importStrategy !== "component") {
476
+ const c = r.reduce((y, w, f) => {
477
+ const b = w.reduce((L, Z) => {
472
478
  var X;
473
479
  const U = u(a, "css", Z), nt = M(U, "utf8"), q = ((X = /.*-([^-]+)-\d+.css/.exec(Z)) == null ? void 0 : X.at(1)) || z(U, 6);
474
480
  return L.includes(q) ? L : `${L}
@@ -476,16 +482,16 @@ ${w}`;
476
482
  ${nt}
477
483
  /*end:${q}*/
478
484
  `;
479
- }, ""), x = `l_${f}.css`, J = u(a, "css", x), K = `@layer l${f} { ${b}
485
+ }, ""), N = `l_${f}.css`, V = u(a, "css", N), K = `@layer l${f} { ${b}
480
486
  }`;
481
- return D(J, K), `${y}
482
- @import url('./css/${x}');`;
487
+ return D(V, K), `${y}
488
+ @import url('./css/${N}');`;
483
489
  }, "");
484
- k += l;
490
+ k += c;
485
491
  }
486
492
  D(h, k);
487
- const N = Date.now() - n, O = N < 200 ? "🔥" : N < 500 ? "🚀" : N < 1e3 ? "🎉" : N < 2e3 ? "🚗" : N < 5e3 ? "🤔" : "🥴";
488
- at.info(`Generated CSS in ${N}ms! ${O}`);
493
+ const C = Date.now() - n, _ = C < 200 ? "🔥" : C < 500 ? "🚀" : C < 1e3 ? "🎉" : C < 2e3 ? "🚗" : C < 5e3 ? "🤔" : "🥴";
494
+ at.info(`Generated CSS in ${C}ms! ${_}`);
489
495
  } catch (n) {
490
496
  console.error(n);
491
497
  }
@@ -494,55 +500,55 @@ ${nt}
494
500
  const n = await v(t);
495
501
  if (G(e)) {
496
502
  const r = [], a = await ut(t), { contents: h } = await st(t, e, n);
497
- for (const [S, c] of Object.entries(h)) {
498
- if (c.isKeyframes && c.css) {
499
- const w = `css/${`a_${c.animationName}.css`}`, j = u(n, w);
500
- D(j, await c.css);
503
+ for (const [j, l] of Object.entries(h)) {
504
+ if (l.isKeyframes && l.css) {
505
+ const p = `css/${`a_${l.animationName}.css`}`, P = u(n, p);
506
+ D(P, await l.css);
501
507
  return;
502
508
  }
503
- if (c.isClassName) {
504
- const d = c.generator._withBuildContext({
505
- callerName: S,
509
+ if (l.isClassName) {
510
+ const i = l.generator._withBuildContext({
511
+ callerName: j,
506
512
  isProduction: s,
507
513
  config: a
508
- }), w = await d.css;
509
- if (!w) continue;
510
- r[0].push(d.cssFileName);
511
- const j = `css/${d.cssFileName}`, P = u(n, j);
512
- D(P, w);
514
+ }), p = await i.css;
515
+ if (!p) continue;
516
+ r[0].push(i.cssFileName);
517
+ const P = `css/${i.cssFileName}`, F = u(n, P);
518
+ D(F, p);
513
519
  }
514
- if (!c.generator) return;
515
- const p = c.generator._withBuildContext({
516
- callerName: S,
520
+ if (!l.generator) return;
521
+ const d = l.generator._withBuildContext({
522
+ callerName: j,
517
523
  isProduction: s,
518
524
  config: a
519
- }), $ = await p.css;
520
- if (!$) continue;
521
- const m = `css/${p.cssFileName}`, i = u(n, m);
522
- D(i, $), r[p.priority] || (r[p.priority] = []), r[p.priority].push(p.cssFileName);
525
+ }), g = await d.css;
526
+ if (!g) continue;
527
+ const $ = `css/${d.cssFileName}`, m = u(n, $);
528
+ D(m, g), r[d.priority] || (r[d.priority] = []), r[d.priority].push(d.cssFileName);
523
529
  }
524
530
  if (a.importStrategy !== "component")
525
- r.forEach((S, c) => {
526
- const p = `l_${c}.css`, $ = u(n, "css", p);
527
- let m = M($, "utf8");
528
- S.forEach((i) => {
529
- var P;
530
- const d = u(n, "css", i), w = ((P = /.*-([^-]+)-\d+.css/.exec(i)) == null ? void 0 : P.at(1)) || z(d, 6);
531
- if (!m.includes(w)) {
532
- const E = M(d, "utf8"), k = `/*start:${w}-${i}*/
533
- ${E}
534
- /*end:${w}*/
531
+ r.forEach((j, l) => {
532
+ const d = `l_${l}.css`, g = u(n, "css", d);
533
+ let $ = M(g, "utf8");
534
+ j.forEach((m) => {
535
+ var F;
536
+ const i = u(n, "css", m), p = ((F = /.*-([^-]+)-\d+.css/.exec(m)) == null ? void 0 : F.at(1)) || z(i, 6);
537
+ if (!$.includes(p)) {
538
+ const R = M(i, "utf8"), k = `/*start:${p}-${m}*/
539
+ ${R}
540
+ /*end:${p}*/
535
541
  `;
536
- m = `${m.replace(/\}$/, "")}
542
+ $ = `${$.replace(/\}$/, "")}
537
543
  ${k}
538
544
  }`;
539
545
  }
540
- }), D($, m);
546
+ }), D(g, $);
541
547
  });
542
548
  else {
543
- const S = r.flat().map((i) => `@import url('./${i}');`).join(`
544
- `), c = z(e, 6), p = et(e), $ = R(p.name), m = u(n, `css/f_${$}-${c}.css`);
545
- D(m, S);
549
+ const j = r.flat().map((m) => `@import url('./${m}');`).join(`
550
+ `), l = z(e, 6), d = et(e), g = A(d.name), $ = u(n, `css/f_${g}-${l}.css`);
551
+ D($, j || "/* Empty file */");
546
552
  }
547
553
  }
548
554
  } catch (n) {
@@ -553,38 +559,38 @@ ${k}
553
559
  const n = await v(t);
554
560
  if (G(e)) {
555
561
  const r = M(e, "utf8");
556
- r.replace(/^(?!export\s)const\s.*/gm, (p) => `export ${p}`) !== r && await Ot(e, r);
557
- const h = await ut(t), { contents: S } = await st(t, e, n);
558
- let c = r;
559
- if (Object.entries(S).forEach(([p, $]) => {
562
+ r.replace(/^(?!export\s)const\s.*/gm, (d) => `export ${d}`) !== r && await Ot(e, r);
563
+ const h = await ut(t), { contents: j } = await st(t, e, n);
564
+ let l = r;
565
+ if (Object.entries(j).forEach(([d, g]) => {
560
566
  var f;
561
- if ($.isKeyframes || !$.generator) return;
562
- const m = $.generator._withBuildContext({
563
- callerName: p,
567
+ if (g.isKeyframes || !g.generator) return;
568
+ const $ = g.generator._withBuildContext({
569
+ callerName: d,
564
570
  isProduction: s,
565
571
  config: h
566
- }), i = new RegExp(`\\s${p}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
567
- if (!i) return console.error("Could not find the original declaration");
568
- const d = (f = i.at(1)) == null ? void 0 : f.trim(), w = new RegExp(`\\s${p}[=\\s]+styled\\(`, "g").exec(c);
569
- if (!w) return console.error("Could not find the original declaration");
570
- const { index: j } = w;
571
- let P = !1;
572
- const E = setTimeout(() => P = !0, 5e3);
573
- let k = 0, _ = !1, N = 0;
574
- for (; !_ && !P; ) {
575
- const b = c[j + k];
576
- b === "(" && N++, b === ")" && N--, N === 0 && b === ")" && (_ = !0), k > c.length && (P = !0), k++;
572
+ }), m = new RegExp(`\\s${d}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
573
+ if (!m) return console.error("Could not find the original declaration");
574
+ const i = (f = m.at(1)) == null ? void 0 : f.trim(), p = new RegExp(`\\s${d}[=\\s]+styled\\(`, "g").exec(l);
575
+ if (!p) return console.error("Could not find the original declaration");
576
+ const { index: P } = p;
577
+ let F = !1;
578
+ const R = setTimeout(() => F = !0, 5e3);
579
+ let k = 0, O = !1, C = 0;
580
+ for (; !O && !F; ) {
581
+ const b = l[P + k];
582
+ b === "(" && C++, b === ")" && C--, C === 0 && b === ")" && (O = !0), k > l.length && (F = !0), k++;
577
583
  }
578
- if (!P) clearTimeout(E);
584
+ if (!F) clearTimeout(R);
579
585
  else throw new Error("Failed to find the end of the styled call and timed out");
580
- const O = j + k, l = c.slice(j, O), y = c, g = ` ${p} = styled(${d}, "${m.classNames}", ${JSON.stringify(m.clientProps)});`;
581
- c = c.replace(l, g), y === c && console.error("Minimize file failed to change content", { name: p, tagName: d });
586
+ const _ = P + k, c = l.slice(P, _), y = l, w = ` ${d} = styled(${i}, "${$.classNames}", ${JSON.stringify($.clientProps)});`;
587
+ l = l.replace(c, w), y === l && console.error("Minimize file failed to change content", { name: d, tagName: i });
582
588
  }), h.importStrategy === "component") {
583
- const p = z(e, 6), $ = et(e);
584
- c = `import '../../saltygen/css/${`f_${R($.name)}-${p}.css`}';
585
- ${c}`;
589
+ const d = z(e, 6), g = et(e);
590
+ l = `import '../../saltygen/css/${`f_${A(g.name)}-${d}.css`}';
591
+ ${l}`;
586
592
  }
587
- return c = c.replace("{ styled }", "{ styledClient as styled }"), c = c.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), c;
593
+ return l = l.replace("{ styled }", "{ styledClient as styled }"), l = l.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), l;
588
594
  }
589
595
  } catch (n) {
590
596
  console.error("Error in minimizeFile:", n);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/vite",
3
- "version": "0.0.1-alpha.207",
3
+ "version": "0.0.1-alpha.209",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -34,6 +34,6 @@
34
34
  }
35
35
  },
36
36
  "dependencies": {
37
- "@salty-css/core": "^0.0.1-alpha.207"
37
+ "@salty-css/core": "^0.0.1-alpha.209"
38
38
  }
39
39
  }