@salty-css/vite 0.0.1-alpha.206 → 0.0.1-alpha.208

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 +24 -22
  2. package/index.js +266 -261
  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"),a=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 mt=Dt(kt),dt=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=dt(n%52)+s;return s=dt(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:c}=o;s=s.replace(r,y=>{const{value:g,css:u}=c(y);return u&&n.push(u),g})}),{transformed:s,additionalCss:n}},gt=t=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...o)=>`var(--${R(o[1].replaceAll(".","-"))})`)},Mt=gt(),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,c=Object.entries(t).map(async([w,i])=>{const p=w.trim(),N=vt(p),F=(O,_=";")=>`${N}:${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 F(i.toString());if(p==="defaultVariants")return;if(p==="variants"){const k=Object.entries(i);for(const[x,E]of k){if(!E)return;const l=Object.entries(E);for(const[$,h]of l){if(!h)return;const f=`${e}.${x}-${$}`;(await Y(h,f,s)).forEach(P=>o.add(P))}}return}if(p==="compoundVariants"){for(const k of i){const{css:x,...E}=k,l=Object.entries(E).reduce((h,[f,S])=>`${h}.${f}-${S}`,e);(await Y(x,l,s)).forEach(h=>o.add(h))}return}if(p.startsWith("@")){const k=p,x=await G(i,e,s),E=`${k} { ${x} }`;o.add(E);return}const O=w.includes("&")?p.replace("&",e):p.startsWith(":")?`${e}${p}`:`${e} ${p}`;(await Y(i,O,s)).forEach(k=>o.add(k));return}if(typeof i=="number"){const O=Vt(N,i);return F(O)}if(typeof i!="string")if("toString"in i)i=i.toString();else throw new Error(`Invalid value type for property ${N}`);return F(i)}),{modifiers:y}={},g=[gt(),Et(y)],m=(await Promise.all(c).then(w=>Promise.all(w.map(i=>g.reduce(async(p,N)=>{const F=await p;if(!F)return F;const D=await N(F);if(!D)return F;const{transformed:O,additionalCss:_}=D;let k="";if(_)for(const x of _)k+=await G(x,"");return`${k}${O}`},Promise.resolve(i)))))).join(`
2
- `);if(!m.trim())return o;const b=e?`${e} { ${m} }`:m;return o.add(b),o},G=async(t,e,s,n=!1)=>[...await Y(t,e,s,n)].join(`
3
- `),ht=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 c=o.trim(),y=await ht(r,[...e,c]);s.push(y)}else n[o]=r;if(Object.keys(n).length){const o=e.map(R).join("-"),r="t_"+z(o,4),c=await G(n,`.${o}, .${r}`);s.push(c)}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]=wt(n).map(o=>`"${o}"`).join(" | ")),e),{}):{},wt=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const r=e?`${e}.${n}`:n;return typeof o=="object"?wt(o,r,s):s.add(e)}),[...s]):[],bt=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=a.join(t,"package.json");return d.existsSync(e)?e:bt(a.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 W;const $t=async t=>{if(W)return W;const e=await Wt(t);return e==="module"?W="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"))&&(W="cjs"),W||"esm"},it=B.createLogger({level:"debug",format:B.format.combine(B.format.colorize(),B.format.cli()),transports:[new B.transports.Console({})]});function St(t){return t?typeof t!="string"?St(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"}},I=(...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},jt=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=a.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return v.destDir=s,s},Ft=["salty","css","styles","styled"],qt=(t=[])=>new RegExp(`\\.(${[...Ft,...t].join("|")})\\.`),Z=(t,e=[])=>qt(e).test(t),Ct=async t=>{if(v.rcFile)return v.rcFile;if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=a.join(t,".saltyrc.json"),s=await tt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(v.rcFile=s,s):Ct(a.join(t,".."))},at=async t=>{var n,o;const e=await Ct(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=a.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),o=a.join(s,"salty.config.js"),r=await $t(t),c=jt(n);await mt.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:r,external:c});const y=Date.now(),{config:g}=await import(`${o}?t=${y}`);return g},Lt=async(t,e)=>{var lt,ft;const s=await A(t),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...e].map(async j=>{const{contents:C,outputFilePath:J}=await et(t,j,s);Object.entries(C).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},c=new Set,y=(j,C=[])=>j?Object.entries(j).flatMap(([J,T])=>{if(!T)return;if(typeof T=="object")return y(T,[...C,J]);const M=St(J),nt=R(J),ot=[...C,M].join(".");c.add(`"${ot}"`);const X=[...C.map(R),nt].join("-"),ut=Mt(T);return ut?`--${X}: ${ut.transformed};`:`--${X}: ${T};`}):[],g=j=>j?Object.entries(j).flatMap(([C,J])=>{const T=y(J);return C==="base"?T.join(""):`${C} { ${T.join("")} }`}):[],u=j=>j?Object.entries(j).flatMap(([C,J])=>Object.entries(J).flatMap(([T,M])=>{const nt=y(M,[C]),ot=`.${C}-${T}, [data-${C}="${T}"]`,X=nt.join("");return`${ot} { ${X} }`})):[],m=j=>({...j,responsive:void 0,conditional:void 0}),b=j=>n.variables.map(C=>j==="static"?m(C._current):C._current[j]),w=I(m(o.variables),b("static")),i=y(w),p=I((lt=o.variables)==null?void 0:lt.responsive,b("responsive")),N=g(p),F=I((ft=o.variables)==null?void 0:ft.conditional,b("conditional")),D=u(F),O=a.join(s,"css/_variables.css"),_=`:root { ${i.join("")} ${N.join("")} } ${D.join("")}`;d.writeFileSync(O,_),r.staticVariables=w;const k=a.join(s,"css/_global.css"),x=I(o.global,n.globalStyles),E=await G(x,"");d.writeFileSync(k,`@layer global { ${E} }`);const l=a.join(s,"css/_reset.css"),h=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:It,f=await G(h,"");d.writeFileSync(l,`@layer reset { ${f} }`);const S=a.join(s,"css/_templates.css"),P=I(o.templates,n.templates),V=await ht(P),q=zt(P);d.writeFileSync(S,`@layer templates { ${V} }`),r.templates=P;const H=Zt(n.templates);r.templatePaths=Object.fromEntries(Object.entries(H).map(([j,C])=>[j,C._path]));const{mediaQueries:L}=n;r.mediaQueries=Object.fromEntries(L.map(([j,C])=>[`@${j}`,C]));const K=L.map(([j])=>`'@${j}'`).join(" | "),st=a.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"),f=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},v=(t,e=5)=>{const s=Tt(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 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,g=>{const{value:C,css:u}=a(g);return u&&n.push(u),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),N=(_,E=";")=>`${k}:${_}${E}`;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 N(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,l]of h){if(!l)return;const S=`${e}.${D}-${b}`;(await Y(l,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((l,[S,x])=>`${l}.${S}-${x}`,e);(await Y(D,h,s)).forEach(l=>o.add(l))}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 N(_)}if(typeof i!="string")if("toString"in i)i=i.toString();else throw new Error(`Invalid value type for property ${k}`);return N(i)}),{modifiers:g}={},C=[ht(),Et(g)],p=(await Promise.all(a).then(m=>Promise.all(m.map(i=>C.reduce(async(y,k)=>{const N=await y;if(!N)return N;const R=await k(N);if(!R)return N;const{transformed:_,additionalCss:E}=R;let j="";if(E)for(const D of E)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=f.join(t,"package.json");return d.existsSync(e)?e:bt(f.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=f.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),Nt=async t=>{if(J.rcFile)return J.rcFile;if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=f.join(t,".saltyrc.json"),s=await tt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(J.rcFile=s,s):Nt(f.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 z(t),n=f.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),o=f.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:P,outputFilePath:A}=await et(t,F,s);Object.entries(P).forEach(([O,T])=>{T.isMedia?n.mediaQueries.push([O,T]):T.isGlobalDefine?n.globalStyles.push(T):T.isDefineVariables?n.variables.push(T):T.isDefineTemplates&&n.templates.push(T._setPath(A))})}));const o=await Ht(t),r={...o},a=new Set,g=(F,P=[])=>F?Object.entries(F).flatMap(([A,O])=>{if(!O)return;if(typeof O=="object")return g(O,[...P,A]);const T=jt(A),nt=V(A),ot=[...P,T].join(".");a.add(`"${ot}"`);const X=[...P.map(V),nt].join("-"),dt=Mt(O);return dt?`--${X}: ${dt.transformed};`:`--${X}: ${O};`}):[],C=F=>F?Object.entries(F).flatMap(([P,A])=>{const O=g(A);return P==="base"?O.join(""):`${P} { ${O.join("")} }`}):[],u=F=>F?Object.entries(F).flatMap(([P,A])=>Object.entries(A).flatMap(([O,T])=>{const nt=g(T,[P]),ot=`.${P}-${O}, [data-${P}="${O}"]`,X=nt.join("");return`${ot} { ${X} }`})):[],p=F=>({...F,responsive:void 0,conditional:void 0}),w=F=>n.variables.map(P=>F==="static"?p(P._current):P._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")),N=u(k),R=f.join(s,"css/_variables.css"),_=`:root { ${m.join("")} ${y.join("")} } ${N.join("")}`;d.writeFileSync(R,_),r.staticVariables=$;const E=f.join(s,"css/_global.css"),j=Z(o.global,n.globalStyles),D=await G(j,"");d.writeFileSync(E,`@layer global { ${D} }`);const c=f.join(s,"css/_reset.css"),b=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:It,l=await G(b,"");d.writeFileSync(c,`@layer reset { ${l} }`);const S=f.join(s,"css/_templates.css"),x=Z(o.templates,n.templates),M=await wt(x),H=vt(x);d.writeFileSync(S,`@layer templates { ${M} }`),r.templates=x;const L=Zt(n.templates);r.templatePaths=Object.fromEntries(Object.entries(L).map(([F,P])=>[F,P._path]));const{mediaQueries:W}=n;r.mediaQueries=Object.fromEntries(W.map(([F,P])=>[`@${F}`,P]));const K=W.map(([F])=>`'@${F}'`).join(" | "),st=f.join(s,"types/css-tokens.d.ts"),Q=`
5
7
  // Variable types
6
- type VariableTokens = ${[...c].join("|")};
8
+ type VariableTokens = ${[...a].join("|")};
7
9
  type PropertyValueToken = \`{\${VariableTokens}}\`;
8
10
 
9
11
  // Template types
10
12
  type TemplateTokens = {
11
- ${Object.entries(q).map(([j,C])=>`${j}?: ${C}`).join(`
13
+ ${Object.entries(H).map(([F,P])=>`${F}?: ${P}`).join(`
12
14
  `)}
13
15
  }
14
16
 
15
17
  // Media query types
16
18
  type MediaQueryKeys = ${K||"''"};
17
- `;d.writeFileSync(st,Q);const Pt=a.join(s,"cache/config-cache.json");d.writeFileSync(Pt,JSON.stringify(r,null,2))},pt=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 c=o.exec(t);if(c){const y=c.at(1);if(Ft.some(u=>y==null?void 0:y.includes(u)))return e}return"styled('div',"}),Bt=(t,e)=>{try{const s=d.readFileSync(a.join(e,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
19
+ `;d.writeFileSync(st,Q);const xt=f.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 g=a.at(1);if(Ct.some(u=>g==null?void 0:g.includes(u)))return e}return"styled('div',"}),Bt=(t,e)=>{try{const s=d.readFileSync(f.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=a.join(s,"./temp");d.existsSync(o)||d.mkdirSync(o);const r=a.parse(e);let c=d.readFileSync(e,"utf8");c=pt(c),c=Bt(c,t);const y=a.join(s,"js",n+".js"),g=await at(t),u=a.join(t,(g==null?void 0:g.configDir)||"","salty.config.ts"),m=jt(u),b=await $t(t);await mt.build({stdin:{contents:c,sourcefile:r.base,resolveDir:r.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:b,target:["node20"],keepNames:!0,external:m,packages:"external",plugins:[{name:"test",setup:p=>{p.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},N=>{const F=d.readFileSync(N.path,"utf8");return{contents:pt(F),loader:"ts"}})}}]});const w=Date.now();return{contents:await import(`${y}?t=${w}`),outputFilePath:y}},Gt=async t=>{const e=await A(t),s=a.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=a.join(s,"salty.config.js"),o=Date.now(),{config:r}=await import(`${n}?t=${o}`);return I(r,e)},xt=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Kt=async(t,e=xt(),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=[],c=await A(t),y=a.join(c,"index.css");s&&(()=>{d.existsSync(c)&&_t.execSync("rm -rf "+c),d.mkdirSync(c,{recursive:!0}),d.mkdirSync(a.join(c,"css")),d.mkdirSync(a.join(c,"types")),d.mkdirSync(a.join(c,"js")),d.mkdirSync(a.join(c,"cache"))})();const u=new Set,m=new Set;async function b(l){const $=["node_modules","saltygen"],h=d.statSync(l);if(h.isDirectory()){const f=d.readdirSync(l);if($.some(P=>l.includes(P)))return;await Promise.all(f.map(P=>b(a.join(l,P))))}else if(h.isFile()&&Z(l)){u.add(l);const S=d.readFileSync(l,"utf8");/define[\w\d]+\(/.test(S)&&m.add(l)}}await b(t),await Lt(t,m);const w={keyframes:[],components:[],classNames:[]};await Promise.all([...u].map(async l=>{const{contents:$}=await et(t,l,c);Object.entries($).forEach(([h,f])=>{f.isKeyframes?w.keyframes.push({value:f,src:l,name:h}):f.isClassName?w.classNames.push({...f,src:l,name:h}):f.generator&&w.components.push({...f,src:l,name:h})})}));const i=await ct(t);for(const l of w.keyframes){const{value:$}=l,h=`a_${$.animationName}.css`,f=`css/${h}`,S=a.join(c,f);o.push(h),d.writeFileSync(S,$.css)}const p={};for(const l of w.components){const{src:$,name:h}=l,f=l.generator._withBuildContext({callerName:h,isProduction:e,config:i});r[f.priority]||(r[f.priority]=[]);const S=await f.css;if(!S)continue;r[f.priority].push(f.cssFileName);const P=`css/${f.cssFileName}`,V=a.join(c,P);d.writeFileSync(V,S),i.importStrategy==="component"&&(p[$]?p[$].push(f.cssFileName):p[$]=[f.cssFileName])}for(const l of w.classNames){const{src:$,name:h}=l,f=l.generator._withBuildContext({callerName:h,isProduction:e,config:i}),S=await f.css;if(!S)continue;r[0].push(f.cssFileName);const P=`css/${f.cssFileName}`,V=a.join(c,P);d.writeFileSync(V,S),i.importStrategy==="component"&&(p[$]?p[$].push(f.cssFileName):p[$]=[f.cssFileName])}i.importStrategy==="component"&&Object.entries(p).forEach(([l,$])=>{const h=$.map(q=>`@import url('./${q}');`).join(`
22
- `),f=z(l,6),S=a.parse(l),P=R(S.name),V=a.join(c,`css/f_${P}-${f}.css`);d.writeFileSync(V,h)});const N=o.map(l=>`@import url('./css/${l}');`).join(`
23
+ ${t}`}catch{return t}},et=async(t,e,s)=>{const n=v(e),o=f.join(s,"./temp");d.existsSync(o)||d.mkdirSync(o);const r=f.parse(e);let a=d.readFileSync(e,"utf8");a=yt(a),a=Bt(a,t);const g=f.join(s,"js",n+".js"),C=await at(t),u=f.join(t,(C==null?void 0:C.configDir)||"","salty.config.ts"),p=Ft(u),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=f.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=f.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=f.join(a,"index.css");s&&(()=>{d.existsSync(a)&&_t.execSync("rm -rf "+a),d.mkdirSync(a,{recursive:!0}),d.mkdirSync(f.join(a,"css")),d.mkdirSync(f.join(a,"types")),d.mkdirSync(f.join(a,"js")),d.mkdirSync(f.join(a,"cache"))})();const u=new Set,p=new Set;async function w(c){const h=["node_modules","saltygen"],b=d.statSync(c);if(b.isDirectory()){const l=d.readdirSync(c);if(h.some(x=>c.includes(x)))return;await Promise.all(l.map(x=>w(f.join(c,x))))}else if(b.isFile()&&q(c)){u.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([...u].map(async c=>{const{contents:h}=await et(t,c,a);Object.entries(h).forEach(([b,l])=>{l.isKeyframes?$.keyframes.push({value:l,src:c,name:b}):l.isClassName?$.classNames.push({...l,src:c,name:b}):l.generator&&$.components.push({...l,src:c,name:b})})}));const m=await ct(t);for(const c of $.keyframes){const{value:h}=c,b=`a_${h.animationName}.css`,l=`css/${b}`,S=f.join(a,l);o.push(b),d.writeFileSync(S,h.css)}const i={};for(const c of $.components){const{src:h,name:b}=c,l=c.generator._withBuildContext({callerName:b,isProduction:e,config:m});r[l.priority]||(r[l.priority]=[]);const S=await l.css;if(!S)continue;r[l.priority].push(l.cssFileName);const x=`css/${l.cssFileName}`,M=f.join(a,x);d.writeFileSync(M,S),m.importStrategy==="component"&&(i[h]?i[h].push(l.cssFileName):i[h]=[l.cssFileName])}for(const c of $.classNames){const{src:h,name:b}=c,l=c.generator._withBuildContext({callerName:b,isProduction:e,config:m}),S=await l.css;if(!S)continue;r[0].push(l.cssFileName);const x=`css/${l.cssFileName}`,M=f.join(a,x);d.writeFileSync(M,S),m.importStrategy==="component"&&(i[h]?i[h].push(l.cssFileName):i[h]=[l.cssFileName])}m.importStrategy==="component"&&Object.entries(i).forEach(([c,h])=>{const b=h.map(H=>`@import url('./${H}');`).join(`
24
+ `),l=v(c,6),S=f.parse(c),x=V(S.name),M=f.join(a,`css/f_${x}-${l}.css`);d.writeFileSync(M,b)});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(l=>{try{return d.readFileSync(a.join(c,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
27
+ ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(c=>{try{return d.readFileSync(f.join(a,"css",c),"utf8").length>0}catch{return!1}}).map(c=>`@import url('./css/${c}');`).join(`
26
28
  `)}
27
- ${N}`;if(i.importStrategy!=="component"){const l=r.reduce(($,h,f)=>{const S=h.reduce((H,L)=>{var Q;const K=a.join(c,"css",L),st=d.readFileSync(K,"utf8"),U=((Q=/.*-([^-]+)-\d+.css/.exec(L))==null?void 0:Q.at(1))||z(K,6);return H.includes(U)?H:`${H}
28
- /*start:${U}*/
29
+ ${y}`;if(m.importStrategy!=="component"){const c=r.reduce((h,b,l)=>{const S=b.reduce((L,W)=>{var Q;const K=f.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}
30
+ /*start:${U}-${W}*/
29
31
  ${st}
30
32
  /*end:${U}*/
31
- `},""),P=`l_${f}.css`,V=a.join(c,"css",P),q=`@layer l${f} { ${S}
32
- }`;return d.writeFileSync(V,q),`${$}
33
- @import url('./css/${P}');`},"");_+=l}d.writeFileSync(y,_);const x=Date.now()-n,E=x<200?"🔥":x<500?"🚀":x<1e3?"🎉":x<2e3?"🚗":x<5e3?"🤔":"🥴";it.info(`Generated CSS in ${x}ms! ${E}`)}catch(n){console.error(n)}},Ut=async(t,e)=>{try{const s=await A(t);if(Z(e)){const o=[],r=await ct(t),{contents:c}=await et(t,e,s);for(const[y,g]of Object.entries(c)){if(g.isKeyframes&&g.css){const p=`css/${`a_${g.animationName}.css`}`,N=a.join(s,p);d.writeFileSync(N,await g.css);return}if(g.isClassName){const i=g.generator._withBuildContext({name:y}),p=await i.css;if(!p)continue;o[0].push(i.cssFileName);const N=`css/${i.cssFileName}`,F=a.join(s,N);d.writeFileSync(F,p)}if(!g.generator)return;const u=g.generator._withBuildContext({name:y,config:r}),m=await u.css;if(!m)continue;const b=`css/${u.cssFileName}`,w=a.join(s,b);d.writeFileSync(w,m),o[u.priority]||(o[u.priority]=[]),o[u.priority].push(u.cssFileName)}if(r.importStrategy!=="component")o.forEach((y,g)=>{const u=`l_${g}.css`,m=a.join(s,"css",u);let b=d.readFileSync(m,"utf8");y.forEach(w=>{var F;const i=a.join(s,"css",w),p=((F=/.*-([^-]+)-\d+.css/.exec(w))==null?void 0:F.at(1))||z(i,6);if(!b.includes(p)){const D=d.readFileSync(i,"utf8"),O=`/*start:${p}*/
34
- ${D}
35
- /*end:${p}*/
36
- `;b=`${b.replace(/\}$/,"")}
37
- ${O}
38
- }`}}),d.writeFileSync(m,b)});else{const y=o.flat().map(w=>`@import url('./${w}');`).join(`
39
- `),g=z(e,6),u=a.parse(e),m=R(u.name),b=a.join(s,`css/f_${m}-${g}.css`);d.writeFileSync(b,y)}}}catch(s){console.error(s)}},Qt=async(t,e,s=xt())=>{try{const n=await A(t);if(Z(e)){const r=d.readFileSync(e,"utf8");r.replace(/^(?!export\s)const\s.*/gm,m=>`export ${m}`)!==r&&await tt.writeFile(e,r);const y=await ct(t),{contents:g}=await et(t,e,n);let u=r;if(Object.entries(g).forEach(([m,b])=>{var f;if(b.isKeyframes||!b.generator)return;const w=b.generator._withBuildContext({name:m,config:y,prod:s}),i=new RegExp(`\\s${m}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(r);if(!i)return console.error("Could not find the original declaration");const p=(f=i.at(1))==null?void 0:f.trim(),N=new RegExp(`\\s${m}[=\\s]+styled\\(`,"g").exec(u);if(!N)return console.error("Could not find the original declaration");const{index:F}=N;let D=!1;const O=setTimeout(()=>D=!0,5e3);let _=0,k=!1,x=0;for(;!k&&!D;){const S=u[F+_];S==="("&&x++,S===")"&&x--,x===0&&S===")"&&(k=!0),_>u.length&&(D=!0),_++}if(!D)clearTimeout(O);else throw new Error("Failed to find the end of the styled call and timed out");const E=F+_,l=u.slice(F,E),$=u,h=` ${m} = styled(${p}, "${w.classNames}", ${JSON.stringify(w.clientProps)});`;u=u.replace(l,h),$===u&&console.error("Minimize file failed to change content",{name:m,tagName:p})}),y.importStrategy==="component"){const m=z(e,6),b=a.parse(e);u=`import '../../saltygen/css/${`f_${R(b.name)}-${m}.css`}';
40
- ${u}`}return u=u.replace("{ styled }","{ styledClient as styled }"),u=u.replace("@salty-css/react/styled","@salty-css/react/styled-client"),u}}catch(n){console.error("Error in minimizeFile:",n)}},yt=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!Z(t))return!1;const n=await tt.readFile(t,"utf-8");return!!/.+define[A-Z]\w+/.test(n)},Nt=t=>({name:"stylegen",buildStart:()=>Kt(t),load:async e=>{if(Z(e))return await Qt(t,e)},handleHotUpdate:async({file:e,server:s})=>{await yt(e)&&await s.restart()},watchChange:{handler:async e=>{Z(e)&&(await yt(e)||await Ut(t,e))}}});exports.default=Nt;exports.saltyPlugin=Nt;
33
+ `},""),x=`l_${l}.css`,M=f.join(a,"css",x),H=`@layer l${l} { ${S}
34
+ }`;return d.writeFileSync(M,H),`${h}
35
+ @import url('./css/${x}');`},"");_+=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,u]of Object.entries(g)){if(u.isKeyframes&&u.css){const y=`css/${`a_${u.animationName}.css`}`,k=f.join(n,y);d.writeFileSync(k,await u.css);return}if(u.isClassName){const i=u.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}`,N=f.join(n,k);d.writeFileSync(N,y)}if(!u.generator)return;const p=u.generator._withBuildContext({callerName:C,isProduction:s,config:a}),w=await p.css;if(!w)continue;const $=`css/${p.cssFileName}`,m=f.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,u)=>{const p=`l_${u}.css`,w=f.join(n,"css",p);let $=d.readFileSync(w,"utf8");C.forEach(m=>{var N;const i=f.join(n,"css",m),y=((N=/.*-([^-]+)-\d+.css/.exec(m))==null?void 0:N.at(1))||v(i,6);if(!$.includes(y)){const R=d.readFileSync(i,"utf8"),_=`/*start:${y}-${m}*/
36
+ ${R}
37
+ /*end:${y}*/
38
+ `;$=`${$.replace(/\}$/,"")}
39
+ ${_}
40
+ }`}}),d.writeFileSync(w,$)});else{const C=r.flat().map(m=>`@import url('./${m}');`).join(`
41
+ `),u=v(e,6),p=f.parse(e),w=V(p.name),$=f.join(n,`css/f_${w}-${u}.css`);d.writeFileSync($,C)}}}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 u=r;if(Object.entries(C).forEach(([p,w])=>{var l;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=(l=m.at(1))==null?void 0:l.trim(),y=new RegExp(`\\s${p}[=\\s]+styled\\(`,"g").exec(u);if(!y)return console.error("Could not find the original declaration");const{index:k}=y;let N=!1;const R=setTimeout(()=>N=!0,5e3);let _=0,E=!1,j=0;for(;!E&&!N;){const S=u[k+_];S==="("&&j++,S===")"&&j--,j===0&&S===")"&&(E=!0),_>u.length&&(N=!0),_++}if(!N)clearTimeout(R);else throw new Error("Failed to find the end of the styled call and timed out");const D=k+_,c=u.slice(k,D),h=u,b=` ${p} = styled(${i}, "${$.classNames}", ${JSON.stringify($.clientProps)});`;u=u.replace(c,b),h===u&&console.error("Minimize file failed to change content",{name:p,tagName:i})}),g.importStrategy==="component"){const p=v(e,6),w=f.parse(e);u=`import '../../saltygen/css/${`f_${V(w.name)}-${p}.css`}';
42
+ ${u}`}return u=u.replace("{ styled }","{ styledClient as styled }"),u=u.replace("@salty-css/react/styled","@salty-css/react/styled-client"),u}}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;
package/index.js CHANGED
@@ -1,36 +1,36 @@
1
- import * as $t from "esbuild";
1
+ import * as wt from "esbuild";
2
2
  import { execSync as _t } from "child_process";
3
3
  import { join as u, parse as et } from "path";
4
- import { existsSync as ct, mkdirSync as H, statSync as Et, readdirSync as Tt, readFileSync as M, writeFileSync as P } from "fs";
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
7
  const gt = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), Rt = (t, e) => {
8
8
  let s = "", n;
9
9
  for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = gt(n % 52) + s;
10
10
  return s = gt(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
11
- }, Jt = (t, e) => {
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
- s = s.replace(r, (p) => {
29
- const { value: g, css: f } = a(p);
30
- return f && n.push(f), g;
28
+ s = s.replace(r, (h) => {
29
+ const { value: j, css: f } = a(h);
30
+ return f && n.push(f), j;
31
31
  });
32
32
  }), { transformed: s, additionalCss: n };
33
- }, wt = (t) => (e) => typeof e != "string" || !/\{[^{}]+\}/g.test(e) ? void 0 : { transformed: e.replace(/\{([^{}]+)\}/g, (...o) => `var(--${R(o[1].replaceAll(".", "-"))})`) }, Wt = wt(), 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,94 +51,96 @@ 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
- const o = /* @__PURE__ */ new Set(), a = Object.entries(t).map(async ([y, i]) => {
57
- const d = y.trim(), x = Ht(d), S = (E, D = ";") => `${x}:${E}${D}`;
56
+ const o = /* @__PURE__ */ new Set(), a = Object.entries(t).map(async ([m, i]) => {
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 S(i.toString());
61
- if (d === "defaultVariants") return;
62
- if (d === "variants") {
63
- const k = Object.entries(i);
64
- for (const [F, O] of k) {
65
- if (!O) return;
66
- const c = Object.entries(O);
67
- for (const [w, h] of c) {
68
- if (!h) return;
69
- const l = `${e}.${F}-${w}`;
70
- (await tt(h, l, s)).forEach((N) => o.add(N));
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 g = Object.entries(c);
67
+ for (const [w, l] of g) {
68
+ if (!l) return;
69
+ const b = `${e}.${_}-${w}`;
70
+ (await tt(l, b, s)).forEach((V) => o.add(V));
71
71
  }
72
72
  }
73
73
  return;
74
74
  }
75
- if (d === "compoundVariants") {
76
- for (const k of i) {
77
- const { css: F, ...O } = k, c = Object.entries(O).reduce((h, [l, b]) => `${h}.${l}-${b}`, e);
78
- (await tt(F, c, s)).forEach((h) => o.add(h));
75
+ if (p === "compoundVariants") {
76
+ for (const C of i) {
77
+ const { css: _, ...c } = C, g = Object.entries(c).reduce((l, [b, x]) => `${l}.${b}-${x}`, e);
78
+ (await tt(_, g, s)).forEach((l) => o.add(l));
79
79
  }
80
80
  return;
81
81
  }
82
- if (d.startsWith("@")) {
83
- const k = d, F = await Q(i, e, s), O = `${k} { ${F} }`;
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 = y.includes("&") ? d.replace("&", e) : d.startsWith(":") ? `${e}${d}` : `${e} ${d}`;
88
- (await tt(i, E, s)).forEach((k) => o.add(k));
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(x, i);
93
- return S(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 ${x}`);
98
- return S(i);
99
- }), { modifiers: p } = {}, g = [wt(), At(p)], m = (await Promise.all(a).then((y) => Promise.all(
100
- y.map((i) => g.reduce(async (d, x) => {
101
- const S = await d;
102
- if (!S) return S;
103
- const _ = await x(S);
104
- if (!_) return S;
105
- const { transformed: E, additionalCss: D } = _;
106
- let k = "";
107
- if (D)
108
- for (const F of D)
109
- k += await Q(F, "");
110
- return `${k}${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 (!m.trim()) return o;
115
- const $ = e ? `${e} { ${m} }` : m;
116
- return o.add($), o;
117
- }, Q = async (t, e, s, n = !1) => [...await tt(t, e, s, n)].join(`
118
- `), bt = async (t, e = []) => {
112
+ ))).filter((m) => m !== void 0).join(`
113
+ `);
114
+ if (!d.trim()) return Array.from(o);
115
+ const y = e ? `${e} {
116
+ ${d}
117
+ }` : d;
118
+ return o.has(y) ? Array.from(o) : [y, ...o];
119
+ }, Q = async (t, e, s, n = !1) => (await tt(t, e, s, n)).join(`
120
+ `), Ct = async (t, e = []) => {
119
121
  if (!t) return "";
120
122
  const s = [], n = {};
121
123
  for (const [o, r] of Object.entries(t))
122
124
  if (typeof r != "function") if (r && typeof r == "object") {
123
- const a = o.trim(), p = await bt(r, [...e, a]);
124
- s.push(p);
125
+ const a = o.trim(), h = await Ct(r, [...e, a]);
126
+ s.push(h);
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(`
132
134
  `);
133
- }, It = (t) => t ? Object.entries(t).reduce((e, [s, n]) => (typeof n == "function" ? e[s] = "any" : typeof n == "object" && (e[s] = Ct(n).map((o) => `"${o}"`).join(" | ")), e), {}) : {}, Ct = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, o]) => {
135
+ }, It = (t) => t ? Object.entries(t).reduce((e, [s, n]) => (typeof n == "function" ? e[s] = "any" : typeof n == "object" && (e[s] = St(n).map((o) => `"${o}"`).join(" | ")), e), {}) : {}, St = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, o]) => {
134
136
  const r = e ? `${e}.${n}` : n;
135
- return typeof o == "object" ? Ct(o, r, s) : s.add(e);
136
- }), [...s]) : [], St = (t) => {
137
+ return typeof o == "object" ? St(o, r, s) : s.add(e);
138
+ }), [...s]) : [], jt = (t) => {
137
139
  if (!t || t === "/") throw new Error("Could not find package.json file");
138
140
  const e = u(t, "package.json");
139
- return ct(e) ? e : St(u(t, ".."));
141
+ return ct(e) ? e : jt(u(t, ".."));
140
142
  }, Bt = async (t) => {
141
- const e = St(t);
143
+ const e = jt(t);
142
144
  return await lt(e, "utf-8").then(JSON.parse).catch(() => {
143
145
  });
144
146
  }, Gt = async (t) => {
@@ -146,18 +148,18 @@ const At = (t) => (e) => {
146
148
  if (e)
147
149
  return e.type;
148
150
  };
149
- let Z;
150
- const jt = async (t) => {
151
- if (Z) return Z;
151
+ let H;
152
+ const Ft = async (t) => {
153
+ if (H) return H;
152
154
  const e = await Gt(t);
153
- return e === "module" ? Z = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (Z = "cjs"), Z || "esm";
155
+ return e === "module" ? H = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (H = "cjs"), H || "esm";
154
156
  }, at = Vt({
155
157
  level: "debug",
156
158
  format: it.combine(it.colorize(), it.cli()),
157
159
  transports: [new Mt.Console({})]
158
160
  });
159
- function Ft(t) {
160
- return t ? typeof t != "string" ? Ft(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 Nt(t) {
162
+ 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
163
  }
162
164
  const Kt = {
163
165
  /** Set box model to border-box */
@@ -205,7 +207,7 @@ const Kt = {
205
207
  fontSize: "100%",
206
208
  lineHeight: "1.15em"
207
209
  }
208
- }, I = (...t) => t.flat().reduce((e, s) => s != null && s._current ? { ...e, ...s._current } : { ...e, ...s }, {}), Lt = (...t) => t.flat().reduce((e, s) => ({ ...e, ...s._children }), {}), W = {
210
+ }, B = (...t) => t.flat().reduce((e, s) => s != null && s._current ? { ...e, ...s._current } : { ...e, ...s }, {}), Lt = (...t) => t.flat().reduce((e, s) => ({ ...e, ...s._children }), {}), W = {
209
211
  externalModules: [],
210
212
  rcFile: void 0,
211
213
  destDir: void 0
@@ -219,19 +221,19 @@ const Kt = {
219
221
  if (W.destDir) return W.destDir;
220
222
  const e = await ft(t), s = u(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
221
223
  return W.destDir = s, s;
222
- }, Nt = ["salty", "css", "styles", "styled"], Qt = (t = []) => new RegExp(`\\.(${[...Nt, ...t].join("|")})\\.`), B = (t, e = []) => Qt(e).test(t), Pt = async (t) => {
224
+ }, Pt = ["salty", "css", "styles", "styled"], Qt = (t = []) => new RegExp(`\\.(${[...Pt, ...t].join("|")})\\.`), G = (t, e = []) => Qt(e).test(t), kt = async (t) => {
223
225
  if (W.rcFile) return W.rcFile;
224
226
  if (t === "/") throw new Error("Could not find .saltyrc.json file");
225
227
  const e = u(t, ".saltyrc.json"), s = await lt(e, "utf-8").then(JSON.parse).catch(() => {
226
228
  });
227
- return s ? (W.rcFile = s, s) : Pt(u(t, ".."));
229
+ return s ? (W.rcFile = s, s) : kt(u(t, ".."));
228
230
  }, ft = async (t) => {
229
231
  var n, o;
230
- const e = await Pt(t), s = (n = e.projects) == null ? void 0 : n.find((r) => t.endsWith(r.dir || ""));
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 jt(t), a = xt(n);
234
- await $t.build({
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 = xt(n);
236
+ await wt.build({
235
237
  entryPoints: [n],
236
238
  minify: !0,
237
239
  treeShaking: !0,
@@ -240,10 +242,10 @@ const Kt = {
240
242
  format: r,
241
243
  external: a
242
244
  });
243
- const p = Date.now(), { config: g } = await import(`${o}?t=${p}`);
244
- return g;
245
+ const h = Date.now(), { config: j } = await import(`${o}?t=${h}`);
246
+ return j;
245
247
  }, qt = async (t, e) => {
246
- var dt, pt;
248
+ var pt, mt;
247
249
  const s = await v(t), n = {
248
250
  mediaQueries: [],
249
251
  globalStyles: [],
@@ -251,63 +253,63 @@ const Kt = {
251
253
  templates: []
252
254
  };
253
255
  await Promise.all(
254
- [...e].map(async (C) => {
255
- const { contents: j, outputFilePath: A } = await st(t, C, s);
256
- Object.entries(j).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: N, outputFilePath: J } = await st(t, S, s);
258
+ Object.entries(N).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(), p = (C, j = []) => C ? Object.entries(C).flatMap(([A, T]) => {
262
- if (!T) return;
263
- if (typeof T == "object") return p(T, [...j, A]);
264
- const V = Ft(A), ot = R(A), rt = [...j, V].join(".");
263
+ const o = await Ut(t), r = { ...o }, a = /* @__PURE__ */ new Set(), h = (S, N = []) => S ? Object.entries(S).flatMap(([J, E]) => {
264
+ if (!E) return;
265
+ if (typeof E == "object") return h(E, [...N, J]);
266
+ const T = Nt(J), ot = A(J), rt = [...N, T].join(".");
265
267
  a.add(`"${rt}"`);
266
- const Y = [...j.map(R), ot].join("-"), mt = Wt(T);
267
- return mt ? `--${Y}: ${mt.transformed};` : `--${Y}: ${T};`;
268
- }) : [], g = (C) => C ? Object.entries(C).flatMap(([j, A]) => {
269
- const T = p(A);
270
- return j === "base" ? T.join("") : `${j} { ${T.join("")} }`;
271
- }) : [], f = (C) => C ? Object.entries(C).flatMap(([j, A]) => Object.entries(A).flatMap(([T, V]) => {
272
- const ot = p(V, [j]), rt = `.${j}-${T}, [data-${j}="${T}"]`, Y = ot.join("");
268
+ const Y = [...N.map(A), ot].join("-"), ht = Wt(E);
269
+ return ht ? `--${Y}: ${ht.transformed};` : `--${Y}: ${E};`;
270
+ }) : [], j = (S) => S ? Object.entries(S).flatMap(([N, J]) => {
271
+ const E = h(J);
272
+ return N === "base" ? E.join("") : `${N} { ${E.join("")} }`;
273
+ }) : [], f = (S) => S ? Object.entries(S).flatMap(([N, J]) => Object.entries(J).flatMap(([E, T]) => {
274
+ const ot = h(T, [N]), rt = `.${N}-${E}, [data-${N}="${E}"]`, Y = ot.join("");
273
275
  return `${rt} { ${Y} }`;
274
- })) : [], m = (C) => ({ ...C, responsive: void 0, conditional: void 0 }), $ = (C) => n.variables.map((j) => C === "static" ? m(j._current) : j._current[C]), y = I(m(o.variables), $("static")), i = p(y), d = I((dt = o.variables) == null ? void 0 : dt.responsive, $("responsive")), x = g(d), S = I((pt = o.variables) == null ? void 0 : pt.conditional, $("conditional")), _ = f(S), E = u(s, "css/_variables.css"), D = `:root { ${i.join("")} ${x.join("")} } ${_.join("")}`;
275
- P(E, D), r.staticVariables = y;
276
- const k = u(s, "css/_global.css"), F = I(o.global, n.globalStyles), O = await Q(F, "");
277
- P(k, `@layer global { ${O} }`);
278
- const c = u(s, "css/_reset.css"), h = o.reset === "none" ? {} : typeof o.reset == "object" ? o.reset : Kt, l = await Q(h, "");
279
- P(c, `@layer reset { ${l} }`);
280
- const b = u(s, "css/_templates.css"), N = I(o.templates, n.templates), J = await bt(N), G = It(N);
281
- P(b, `@layer templates { ${J} }`), r.templates = N;
282
- const K = Lt(n.templates);
283
- r.templatePaths = Object.fromEntries(Object.entries(K).map(([C, j]) => [C, j._path]));
284
- const { mediaQueries: L } = n;
285
- r.mediaQueries = Object.fromEntries(L.map(([C, j]) => [`@${C}`, j]));
286
- const U = L.map(([C]) => `'@${C}'`).join(" | "), nt = u(s, "types/css-tokens.d.ts"), X = `
276
+ })) : [], d = (S) => ({ ...S, responsive: void 0, conditional: void 0 }), y = (S) => n.variables.map((N) => S === "static" ? d(N._current) : N._current[S]), $ = B(d(o.variables), y("static")), m = h($), i = B((pt = o.variables) == null ? void 0 : pt.responsive, y("responsive")), p = j(i), P = B((mt = o.variables) == null ? void 0 : mt.conditional, y("conditional")), F = f(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, l = await Q(w, "");
281
+ D(c, `@layer reset { ${l} }`);
282
+ const b = u(s, "css/_templates.css"), x = B(o.templates, n.templates), V = await Ct(x), K = It(x);
283
+ D(b, `@layer templates { ${V} }`), r.templates = x;
284
+ const L = Lt(n.templates);
285
+ r.templatePaths = Object.fromEntries(Object.entries(L).map(([S, N]) => [S, N._path]));
286
+ const { mediaQueries: Z } = n;
287
+ r.mediaQueries = Object.fromEntries(Z.map(([S, N]) => [`@${S}`, N]));
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(G).map(([C, j]) => `${C}?: ${j}`).join(`
295
+ ${Object.entries(K).map(([S, N]) => `${S}?: ${N}`).join(`
294
296
  `)}
295
297
  }
296
298
 
297
299
  // Media query types
298
300
  type MediaQueryKeys = ${U || "''"};
299
301
  `;
300
- P(nt, X);
302
+ D(nt, X);
301
303
  const Dt = u(s, "cache/config-cache.json");
302
- P(Dt, JSON.stringify(r, null, 2));
303
- }, ht = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
304
+ D(Dt, JSON.stringify(r, null, 2));
305
+ }, yt = (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
- const p = a.at(1);
310
- if (Nt.some((f) => p == null ? void 0 : p.includes(f))) return e;
311
+ const h = a.at(1);
312
+ if (Pt.some((f) => h == null ? void 0 : h.includes(f))) return e;
311
313
  }
312
314
  return "styled('div',";
313
315
  }), Xt = (t, e) => {
@@ -323,12 +325,12 @@ ${t}`;
323
325
  }
324
326
  }, st = async (t, e, s) => {
325
327
  const n = z(e), o = u(s, "./temp");
326
- ct(o) || H(o);
328
+ ct(o) || I(o);
327
329
  const r = et(e);
328
330
  let a = M(e, "utf8");
329
- a = ht(a), a = Xt(a, t);
330
- const p = u(s, "js", n + ".js"), g = await ft(t), f = u(t, (g == null ? void 0 : g.configDir) || "", "salty.config.ts"), m = xt(f), $ = await jt(t);
331
- await $t.build({
331
+ a = yt(a), a = Xt(a, t);
332
+ const h = u(s, "js", n + ".js"), j = await ft(t), f = u(t, (j == null ? void 0 : j.configDir) || "", "salty.config.ts"), d = xt(f), y = await Ft(t);
333
+ await wt.build({
332
334
  stdin: {
333
335
  contents: a,
334
336
  sourcefile: r.base,
@@ -338,124 +340,124 @@ ${t}`;
338
340
  minify: !1,
339
341
  treeShaking: !0,
340
342
  bundle: !0,
341
- outfile: p,
342
- format: $,
343
+ outfile: h,
344
+ format: y,
343
345
  target: ["node20"],
344
346
  keepNames: !0,
345
- external: m,
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/ }, (x) => {
352
- const S = M(x.path, "utf8");
353
- return { contents: ht(S), 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: yt(P), loader: "ts" };
354
356
  });
355
357
  }
356
358
  }
357
359
  ]
358
360
  });
359
- const y = Date.now();
360
- return { contents: await import(`${p}?t=${y}`), outputFilePath: p };
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");
364
366
  return JSON.parse(n);
365
367
  }, ut = async (t) => {
366
368
  const e = await Yt(t), s = await v(t), n = u(s, "salty.config.js"), o = Date.now(), { config: r } = await import(`${n}?t=${o}`);
367
- return I(r, e);
368
- }, kt = () => {
369
+ return B(r, e);
370
+ }, dt = () => {
369
371
  try {
370
372
  return process.env.NODE_ENV === "production";
371
373
  } catch {
372
374
  return !1;
373
375
  }
374
- }, te = async (t, e = kt(), s = !0) => {
376
+ }, te = async (t, e = dt(), s = !0) => {
375
377
  try {
376
378
  const n = Date.now();
377
379
  e ? at.info("Generating CSS in production mode! 🔥") : at.info("Generating CSS in development mode! 🚀");
378
- const o = [], r = [], a = await v(t), p = u(a, "index.css");
380
+ const o = [], r = [], a = await v(t), h = u(a, "index.css");
379
381
  s && (() => {
380
- ct(a) && _t("rm -rf " + a), H(a, { recursive: !0 }), H(u(a, "css")), H(u(a, "types")), H(u(a, "js")), H(u(a, "cache"));
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 f = /* @__PURE__ */ new Set(), m = /* @__PURE__ */ new Set();
383
- async function $(c) {
384
- const w = ["node_modules", "saltygen"], h = Et(c);
385
- if (h.isDirectory()) {
384
+ const f = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Set();
385
+ async function y(c) {
386
+ const g = ["node_modules", "saltygen"], w = Et(c);
387
+ if (w.isDirectory()) {
386
388
  const l = Tt(c);
387
- if (w.some((N) => c.includes(N))) return;
388
- await Promise.all(l.map((N) => $(u(c, N))));
389
- } else if (h.isFile() && B(c)) {
389
+ if (g.some((x) => c.includes(x))) return;
390
+ await Promise.all(l.map((x) => y(u(c, x))));
391
+ } else if (w.isFile() && G(c)) {
390
392
  f.add(c);
391
393
  const b = M(c, "utf8");
392
- /define[\w\d]+\(/.test(b) && m.add(c);
394
+ /define[\w\d]+\(/.test(b) && d.add(c);
393
395
  }
394
396
  }
395
- await $(t), await qt(t, m);
396
- const y = {
397
+ await y(t), await qt(t, d);
398
+ const $ = {
397
399
  keyframes: [],
398
400
  components: [],
399
401
  classNames: []
400
402
  };
401
403
  await Promise.all(
402
404
  [...f].map(async (c) => {
403
- const { contents: w } = await st(t, c, a);
404
- Object.entries(w).forEach(([h, l]) => {
405
- l.isKeyframes ? y.keyframes.push({
405
+ const { contents: g } = await st(t, c, a);
406
+ Object.entries(g).forEach(([w, l]) => {
407
+ l.isKeyframes ? $.keyframes.push({
406
408
  value: l,
407
409
  src: c,
408
- name: h
409
- }) : l.isClassName ? y.classNames.push({
410
+ name: w
411
+ }) : l.isClassName ? $.classNames.push({
410
412
  ...l,
411
413
  src: c,
412
- name: h
413
- }) : l.generator && y.components.push({
414
+ name: w
415
+ }) : l.generator && $.components.push({
414
416
  ...l,
415
417
  src: c,
416
- name: h
418
+ name: w
417
419
  });
418
420
  });
419
421
  })
420
422
  );
421
- const i = await ut(t);
422
- for (const c of y.keyframes) {
423
- const { value: w } = c, h = `a_${w.animationName}.css`, l = `css/${h}`, b = u(a, l);
424
- o.push(h), P(b, w.css);
423
+ const m = await ut(t);
424
+ for (const c of $.keyframes) {
425
+ const { value: g } = c, w = `a_${g.animationName}.css`, l = `css/${w}`, b = u(a, l);
426
+ o.push(w), D(b, g.css);
425
427
  }
426
- const d = {};
427
- for (const c of y.components) {
428
- const { src: w, name: h } = c, l = c.generator._withBuildContext({
429
- callerName: h,
428
+ const i = {};
429
+ for (const c of $.components) {
430
+ const { src: g, name: w } = c, l = c.generator._withBuildContext({
431
+ callerName: w,
430
432
  isProduction: e,
431
- config: i
433
+ config: m
432
434
  });
433
435
  r[l.priority] || (r[l.priority] = []);
434
436
  const b = await l.css;
435
437
  if (!b) continue;
436
438
  r[l.priority].push(l.cssFileName);
437
- const N = `css/${l.cssFileName}`, J = u(a, N);
438
- P(J, b), i.importStrategy === "component" && (d[w] ? d[w].push(l.cssFileName) : d[w] = [l.cssFileName]);
439
+ const x = `css/${l.cssFileName}`, V = u(a, x);
440
+ D(V, b), m.importStrategy === "component" && (i[g] ? i[g].push(l.cssFileName) : i[g] = [l.cssFileName]);
439
441
  }
440
- for (const c of y.classNames) {
441
- const { src: w, name: h } = c, l = c.generator._withBuildContext({
442
- callerName: h,
442
+ for (const c of $.classNames) {
443
+ const { src: g, name: w } = c, l = c.generator._withBuildContext({
444
+ callerName: w,
443
445
  isProduction: e,
444
- config: i
446
+ config: m
445
447
  }), b = await l.css;
446
448
  if (!b) continue;
447
449
  r[0].push(l.cssFileName);
448
- const N = `css/${l.cssFileName}`, J = u(a, N);
449
- P(J, b), i.importStrategy === "component" && (d[w] ? d[w].push(l.cssFileName) : d[w] = [l.cssFileName]);
450
+ const x = `css/${l.cssFileName}`, V = u(a, x);
451
+ D(V, b), m.importStrategy === "component" && (i[g] ? i[g].push(l.cssFileName) : i[g] = [l.cssFileName]);
450
452
  }
451
- i.importStrategy === "component" && Object.entries(d).forEach(([c, w]) => {
452
- const h = w.map((G) => `@import url('./${G}');`).join(`
453
- `), l = z(c, 6), b = et(c), N = R(b.name), J = u(a, `css/f_${N}-${l}.css`);
454
- P(J, h);
453
+ m.importStrategy === "component" && Object.entries(i).forEach(([c, g]) => {
454
+ const w = g.map((K) => `@import url('./${K}');`).join(`
455
+ `), l = z(c, 6), b = et(c), x = A(b.name), V = u(a, `css/f_${x}-${l}.css`);
456
+ D(V, w);
455
457
  });
456
- const x = o.map((c) => `@import url('./css/${c}');`).join(`
458
+ const p = o.map((c) => `@import url('./css/${c}');`).join(`
457
459
  `);
458
- let D = `@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
460
+ let k = `@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
459
461
 
460
462
  ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((c) => {
461
463
  try {
@@ -465,120 +467,123 @@ ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((c) =
465
467
  }
466
468
  }).map((c) => `@import url('./css/${c}');`).join(`
467
469
  `)}
468
- ${x}`;
469
- if (i.importStrategy !== "component") {
470
- const c = r.reduce((w, h, l) => {
471
- const b = h.reduce((K, L) => {
470
+ ${p}`;
471
+ if (m.importStrategy !== "component") {
472
+ const c = r.reduce((g, w, l) => {
473
+ const b = w.reduce((L, Z) => {
472
474
  var X;
473
- const U = u(a, "css", L), nt = M(U, "utf8"), q = ((X = /.*-([^-]+)-\d+.css/.exec(L)) == null ? void 0 : X.at(1)) || z(U, 6);
474
- return K.includes(q) ? K : `${K}
475
- /*start:${q}*/
475
+ 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);
476
+ return L.includes(q) ? L : `${L}
477
+ /*start:${q}-${Z}*/
476
478
  ${nt}
477
479
  /*end:${q}*/
478
480
  `;
479
- }, ""), N = `l_${l}.css`, J = u(a, "css", N), G = `@layer l${l} { ${b}
481
+ }, ""), x = `l_${l}.css`, V = u(a, "css", x), K = `@layer l${l} { ${b}
480
482
  }`;
481
- return P(J, G), `${w}
482
- @import url('./css/${N}');`;
483
+ return D(V, K), `${g}
484
+ @import url('./css/${x}');`;
483
485
  }, "");
484
- D += c;
486
+ k += c;
485
487
  }
486
- P(p, D);
487
- const F = Date.now() - n, O = F < 200 ? "🔥" : F < 500 ? "🚀" : F < 1e3 ? "🎉" : F < 2e3 ? "🚗" : F < 5e3 ? "🤔" : "🥴";
488
- at.info(`Generated CSS in ${F}ms! ${O}`);
488
+ D(h, k);
489
+ const C = Date.now() - n, _ = C < 200 ? "🔥" : C < 500 ? "🚀" : C < 1e3 ? "🎉" : C < 2e3 ? "🚗" : C < 5e3 ? "🤔" : "🥴";
490
+ at.info(`Generated CSS in ${C}ms! ${_}`);
489
491
  } catch (n) {
490
492
  console.error(n);
491
493
  }
492
- }, ee = async (t, e) => {
494
+ }, ee = async (t, e, s = dt()) => {
493
495
  try {
494
- const s = await v(t);
495
- if (B(e)) {
496
- const o = [], r = await ut(t), { contents: a } = await st(t, e, s);
497
- for (const [p, g] of Object.entries(a)) {
498
- if (g.isKeyframes && g.css) {
499
- const d = `css/${`a_${g.animationName}.css`}`, x = u(s, d);
500
- P(x, await g.css);
496
+ const n = await v(t);
497
+ if (G(e)) {
498
+ const r = [], a = await ut(t), { contents: h } = await st(t, e, n);
499
+ for (const [j, f] of Object.entries(h)) {
500
+ if (f.isKeyframes && f.css) {
501
+ const p = `css/${`a_${f.animationName}.css`}`, P = u(n, p);
502
+ D(P, await f.css);
501
503
  return;
502
504
  }
503
- if (g.isClassName) {
504
- const i = g.generator._withBuildContext({
505
- name: p
506
- }), d = await i.css;
507
- if (!d) continue;
508
- o[0].push(i.cssFileName);
509
- const x = `css/${i.cssFileName}`, S = u(s, x);
510
- P(S, d);
505
+ if (f.isClassName) {
506
+ const i = f.generator._withBuildContext({
507
+ callerName: j,
508
+ isProduction: s,
509
+ config: a
510
+ }), p = await i.css;
511
+ if (!p) continue;
512
+ r[0].push(i.cssFileName);
513
+ const P = `css/${i.cssFileName}`, F = u(n, P);
514
+ D(F, p);
511
515
  }
512
- if (!g.generator) return;
513
- const f = g.generator._withBuildContext({
514
- name: p,
515
- config: r
516
- }), m = await f.css;
517
- if (!m) continue;
518
- const $ = `css/${f.cssFileName}`, y = u(s, $);
519
- P(y, m), o[f.priority] || (o[f.priority] = []), o[f.priority].push(f.cssFileName);
516
+ if (!f.generator) return;
517
+ const d = f.generator._withBuildContext({
518
+ callerName: j,
519
+ isProduction: s,
520
+ config: a
521
+ }), y = await d.css;
522
+ if (!y) continue;
523
+ const $ = `css/${d.cssFileName}`, m = u(n, $);
524
+ D(m, y), r[d.priority] || (r[d.priority] = []), r[d.priority].push(d.cssFileName);
520
525
  }
521
- if (r.importStrategy !== "component")
522
- o.forEach((p, g) => {
523
- const f = `l_${g}.css`, m = u(s, "css", f);
524
- let $ = M(m, "utf8");
525
- p.forEach((y) => {
526
- var S;
527
- const i = u(s, "css", y), d = ((S = /.*-([^-]+)-\d+.css/.exec(y)) == null ? void 0 : S.at(1)) || z(i, 6);
528
- if (!$.includes(d)) {
529
- const _ = M(i, "utf8"), E = `/*start:${d}*/
530
- ${_}
531
- /*end:${d}*/
526
+ if (a.importStrategy !== "component")
527
+ r.forEach((j, f) => {
528
+ const d = `l_${f}.css`, y = u(n, "css", d);
529
+ let $ = M(y, "utf8");
530
+ j.forEach((m) => {
531
+ var F;
532
+ const i = u(n, "css", m), p = ((F = /.*-([^-]+)-\d+.css/.exec(m)) == null ? void 0 : F.at(1)) || z(i, 6);
533
+ if (!$.includes(p)) {
534
+ const R = M(i, "utf8"), k = `/*start:${p}-${m}*/
535
+ ${R}
536
+ /*end:${p}*/
532
537
  `;
533
538
  $ = `${$.replace(/\}$/, "")}
534
- ${E}
539
+ ${k}
535
540
  }`;
536
541
  }
537
- }), P(m, $);
542
+ }), D(y, $);
538
543
  });
539
544
  else {
540
- const p = o.flat().map((y) => `@import url('./${y}');`).join(`
541
- `), g = z(e, 6), f = et(e), m = R(f.name), $ = u(s, `css/f_${m}-${g}.css`);
542
- P($, p);
545
+ const j = r.flat().map((m) => `@import url('./${m}');`).join(`
546
+ `), f = z(e, 6), d = et(e), y = A(d.name), $ = u(n, `css/f_${y}-${f}.css`);
547
+ D($, j);
543
548
  }
544
549
  }
545
- } catch (s) {
546
- console.error(s);
550
+ } catch (n) {
551
+ console.error(n);
547
552
  }
548
- }, se = async (t, e, s = kt()) => {
553
+ }, se = async (t, e, s = dt()) => {
549
554
  try {
550
555
  const n = await v(t);
551
- if (B(e)) {
556
+ if (G(e)) {
552
557
  const r = M(e, "utf8");
553
- r.replace(/^(?!export\s)const\s.*/gm, (m) => `export ${m}`) !== r && await Ot(e, r);
554
- const p = await ut(t), { contents: g } = await st(t, e, n);
558
+ r.replace(/^(?!export\s)const\s.*/gm, (d) => `export ${d}`) !== r && await Ot(e, r);
559
+ const h = await ut(t), { contents: j } = await st(t, e, n);
555
560
  let f = r;
556
- if (Object.entries(g).forEach(([m, $]) => {
561
+ if (Object.entries(j).forEach(([d, y]) => {
557
562
  var l;
558
- if ($.isKeyframes || !$.generator) return;
559
- const y = $.generator._withBuildContext({
560
- name: m,
561
- config: p,
562
- prod: s
563
- }), i = new RegExp(`\\s${m}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
564
- if (!i) return console.error("Could not find the original declaration");
565
- const d = (l = i.at(1)) == null ? void 0 : l.trim(), x = new RegExp(`\\s${m}[=\\s]+styled\\(`, "g").exec(f);
566
- if (!x) return console.error("Could not find the original declaration");
567
- const { index: S } = x;
568
- let _ = !1;
569
- const E = setTimeout(() => _ = !0, 5e3);
570
- let D = 0, k = !1, F = 0;
571
- for (; !k && !_; ) {
572
- const b = f[S + D];
573
- b === "(" && F++, b === ")" && F--, F === 0 && b === ")" && (k = !0), D > f.length && (_ = !0), D++;
563
+ if (y.isKeyframes || !y.generator) return;
564
+ const $ = y.generator._withBuildContext({
565
+ callerName: d,
566
+ isProduction: s,
567
+ config: h
568
+ }), m = new RegExp(`\\s${d}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
569
+ if (!m) return console.error("Could not find the original declaration");
570
+ const i = (l = m.at(1)) == null ? void 0 : l.trim(), p = new RegExp(`\\s${d}[=\\s]+styled\\(`, "g").exec(f);
571
+ if (!p) return console.error("Could not find the original declaration");
572
+ const { index: P } = p;
573
+ let F = !1;
574
+ const R = setTimeout(() => F = !0, 5e3);
575
+ let k = 0, O = !1, C = 0;
576
+ for (; !O && !F; ) {
577
+ const b = f[P + k];
578
+ b === "(" && C++, b === ")" && C--, C === 0 && b === ")" && (O = !0), k > f.length && (F = !0), k++;
574
579
  }
575
- if (!_) clearTimeout(E);
580
+ if (!F) clearTimeout(R);
576
581
  else throw new Error("Failed to find the end of the styled call and timed out");
577
- const O = S + D, c = f.slice(S, O), w = f, h = ` ${m} = styled(${d}, "${y.classNames}", ${JSON.stringify(y.clientProps)});`;
578
- f = f.replace(c, h), w === f && console.error("Minimize file failed to change content", { name: m, tagName: d });
579
- }), p.importStrategy === "component") {
580
- const m = z(e, 6), $ = et(e);
581
- f = `import '../../saltygen/css/${`f_${R($.name)}-${m}.css`}';
582
+ const _ = P + k, c = f.slice(P, _), g = f, w = ` ${d} = styled(${i}, "${$.classNames}", ${JSON.stringify($.clientProps)});`;
583
+ f = f.replace(c, w), g === f && console.error("Minimize file failed to change content", { name: d, tagName: i });
584
+ }), h.importStrategy === "component") {
585
+ const d = z(e, 6), y = et(e);
586
+ f = `import '../../saltygen/css/${`f_${A(y.name)}-${d}.css`}';
582
587
  ${f}`;
583
588
  }
584
589
  return f = f.replace("{ styled }", "{ styledClient as styled }"), f = f.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), f;
@@ -586,25 +591,25 @@ ${f}`;
586
591
  } catch (n) {
587
592
  console.error("Error in minimizeFile:", n);
588
593
  }
589
- }, yt = async (t) => {
594
+ }, $t = async (t) => {
590
595
  if (!t || t.includes("node_modules") || t.includes("saltygen")) return !1;
591
596
  if (t.includes("salty.config")) return !0;
592
- if (!B(t)) return !1;
597
+ if (!G(t)) return !1;
593
598
  const n = await lt(t, "utf-8");
594
599
  return !!/.+define[A-Z]\w+/.test(n);
595
600
  }, ce = (t) => ({
596
601
  name: "stylegen",
597
602
  buildStart: () => te(t),
598
603
  load: async (e) => {
599
- if (B(e))
604
+ if (G(e))
600
605
  return await se(t, e);
601
606
  },
602
607
  handleHotUpdate: async ({ file: e, server: s }) => {
603
- await yt(e) && await s.restart();
608
+ await $t(e) && await s.restart();
604
609
  },
605
610
  watchChange: {
606
611
  handler: async (e) => {
607
- B(e) && (await yt(e) || await ee(t, e));
612
+ G(e) && (await $t(e) || await ee(t, e));
608
613
  }
609
614
  }
610
615
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/vite",
3
- "version": "0.0.1-alpha.206",
3
+ "version": "0.0.1-alpha.208",
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.206"
37
+ "@salty-css/core": "^0.0.1-alpha.208"
38
38
  }
39
39
  }