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

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