@salty-css/vite 0.0.1-alpha.250 → 0.0.1-alpha.252

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 +14 -14
  2. package/index.js +167 -164
  3. package/package.json +2 -2
package/index.cjs CHANGED
@@ -1,9 +1,9 @@
1
- "use strict";var Rt=Object.defineProperty;var Mt=(t,e,s)=>e in t?Rt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var st=(t,e,s)=>Mt(t,typeof e!="symbol"?e+"":e,s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const zt=require("esbuild"),Jt=require("child_process"),c=require("path"),d=require("fs"),pt=require("fs/promises"),X=require("winston"),ft=require("typescript");var ut=typeof document<"u"?document.currentScript:null;function Wt(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 Ft=Wt(zt),bt=t=>String.fromCharCode(t+(t>25?39:97)),At=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=bt(n%52)+s;return s=bt(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},qt=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},q=(t,e=5)=>{const s=qt(5381,JSON.stringify(t))>>>0;return At(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 It=t=>e=>{if(typeof e!="string"||!t)return;let s=e;const n=[];return Object.values(t).forEach(o=>{const{pattern:r,transform:i}=o;s=s.replace(r,y=>{const{value:$,css:m}=i(y);return m&&n.push(m),$})}),{transformed:s,additionalCss:n}},Ct=t=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...o)=>`var(--${M(o[1].replaceAll(".","-"))})`)},Ht=Ct(),Gt=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Lt=(t,e,s)=>Gt.some(o=>typeof o=="string"?o===t:o.test(t))?`${e}px`:`${e}`,Qt=["Webkit","Moz","ms","O"],Kt=t=>t.startsWith("-")?t:Qt.some(e=>t.startsWith(e))?`-${M(t)}`:M(t),nt=async(t,e="",s,n=!1)=>{if(!t)throw new Error("No styles provided to parseStyles function!");const o=new Set,r=Object.entries(t),i=async([p,u])=>{const w=p.trim(),P=Kt(w),T=(D,J=";")=>`${P}:${D}${J}`,V={scope:e,config:s};if(typeof u=="function")return i([p,u(V)]);if(u instanceof Promise)return i([p,await u]);if(typeof u=="object"){if(!u)return;if(u.isColor)return T(u.toString());if(w==="defaultVariants")return;if(w==="variants"){const N=Object.entries(u);for(const[v,f]of N){if(!f)continue;const b=Object.entries(f);for(const[F,a]of b){if(!a)continue;const C=`${e}.${v}-${F}`;(await nt(a,C,s)).forEach(R=>o.add(R))}}return}if(w==="compoundVariants"){for(const N of u){const{css:v,...f}=N,b=Object.entries(f).reduce((a,[C,_])=>`${a}.${C}-${_}`,e);(await nt(v,b,s)).forEach(a=>o.add(a))}return}if(w.startsWith("@")){const N=w,v=await Y(u,e,s),f=`${N} { ${v} }`;o.add(f);return}const D=p.includes("&")?w.replace("&",e):w.startsWith(":")?`${e}${w}`:`${e} ${w}`;(await nt(u,D,s)).forEach(N=>o.add(N));return}if(typeof u=="number"){const D=Lt(P,u);return T(D)}if(typeof u!="string")if("toString"in u)u=u.toString();else throw new Error(`Invalid value type for property ${P}`);return T(u)},y=r.map(i),{modifiers:$}={},m=[Ct(),It($)],g=(await Promise.all(y).then(p=>Promise.all(p.map(u=>m.reduce(async(w,P)=>{const T=await w;if(!T)return T;const V=await P(T);if(!V)return T;const{transformed:D,additionalCss:J}=V;let N="";if(J)for(const v of J)N+=await Y(v,"");return`${N}${D}`},Promise.resolve(u)))))).filter(p=>p!==void 0).join(`
1
+ "use strict";var vt=Object.defineProperty;var Mt=(t,e,s)=>e in t?vt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var st=(t,e,s)=>Mt(t,typeof e!="symbol"?e+"":e,s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const zt=require("esbuild"),Jt=require("child_process"),c=require("path"),d=require("fs"),pt=require("fs/promises"),X=require("winston"),ft=require("typescript");var ut=typeof document<"u"?document.currentScript:null;function Wt(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 Ft=Wt(zt),St=t=>String.fromCharCode(t+(t>25?39:97)),At=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=St(n%52)+s;return s=St(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},qt=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},q=(t,e=5)=>{const s=qt(5381,JSON.stringify(t))>>>0;return At(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 It=t=>e=>{if(typeof e!="string"||!t)return;let s=e;const n=[];return Object.values(t).forEach(o=>{const{pattern:i,transform:r}=o;s=s.replace(i,y=>{const{value:$,css:m}=r(y);return m&&n.push(m),$})}),{transformed:s,additionalCss:n}},Ct=t=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...o)=>{const i=M(o[1].replaceAll(".","-"));return i.startsWith("-")?`-${i}`:`var(--${i})`})},Ht=Ct(),Gt=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Lt=(t,e,s)=>Gt.some(o=>typeof o=="string"?o===t:o.test(t))?`${e}px`:`${e}`,Qt=["Webkit","Moz","ms","O"],Kt=t=>t.startsWith("-")?t:Qt.some(e=>t.startsWith(e))?`-${M(t)}`:M(t),nt=async(t,e="",s,n=!1)=>{if(!t)throw new Error("No styles provided to parseStyles function!");const o=new Set,i=Object.entries(t),r=async([p,u])=>{const w=p.trim(),P=Kt(w),T=(D,J=";")=>`${P}:${D}${J}`,V={scope:e,config:s};if(typeof u=="function")return r([p,u(V)]);if(u instanceof Promise)return r([p,await u]);if(typeof u=="object"){if(!u)return;if(u.isColor)return T(u.toString());if(w==="defaultVariants")return;if(w==="variants"){const N=Object.entries(u);for(const[R,f]of N){if(!f)continue;const S=Object.entries(f);for(const[F,a]of S){if(!a)continue;const C=`${e}.${R}-${F}`;(await nt(a,C,s)).forEach(v=>o.add(v))}}return}if(w==="compoundVariants"){for(const N of u){const{css:R,...f}=N,S=Object.entries(f).reduce((a,[C,_])=>`${a}.${C}-${_}`,e);(await nt(R,S,s)).forEach(a=>o.add(a))}return}if(w.startsWith("@")){const N=w,R=await Y(u,e,s),f=`${N} { ${R} }`;o.add(f);return}const D=p.includes("&")?w.replaceAll("&",e):w.startsWith(":")?`${e}${w}`:`${e} ${w}`;(await nt(u,D,s)).forEach(N=>o.add(N));return}if(typeof u=="number"){const D=Lt(P,u);return T(D)}if(typeof u!="string")if("toString"in u)u=u.toString();else throw new Error(`Invalid value type for property ${P}`);return T(u)},y=i.map(r),{modifiers:$}={},m=[Ct(),It($)],g=(await Promise.all(y).then(p=>Promise.all(p.map(u=>m.reduce(async(w,P)=>{const T=await w;if(!T)return T;const V=await P(T);if(!V)return T;const{transformed:D,additionalCss:J}=V;let N="";if(J)for(const R of J)N+=await Y(R,"");return`${N}${D}`},Promise.resolve(u)))))).filter(p=>p!==void 0).join(`
2
2
  `);if(!g.trim())return Array.from(o);const h=e?`${e} {
3
3
  ${g}
4
4
  }`:g;return o.has(h)?Array.from(o):[h,...o]},Y=async(t,e,s,n=!1)=>(await nt(t,e,s,n)).join(`
5
- `),Pt=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 i=o.trim(),y=await Pt(r,[...e,i]);s.push(y)}else n[o]=r;if(Object.keys(n).length){const o=e.map(M).join("-"),r="t_"+q(o,4),i=await Y(n,`.${o}, .${r}`);s.push(i)}return s.join(`
6
- `)},Ut=t=>t?Object.entries(t).reduce((e,[s,n])=>(typeof n=="function"?e[s]="any":typeof n=="object"&&(e[s]=Nt(n).map(o=>`"${o}"`).join(" | ")),e),{}):{},Nt=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const r=e?`${e}.${n}`:n;return typeof o=="object"?Nt(o,r,s):s.add(e)}),[...s]):[],_t=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:_t(c.join(t,".."))},Zt=async t=>{const e=_t(t);return await pt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},Bt=async t=>{const e=await Zt(t);if(e)return e.type};let H;const xt=async t=>{if(H)return H;const e=await Bt(t);return e==="module"?H="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:ut&&ut.tagName.toUpperCase()==="SCRIPT"&&ut.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(H="cjs"),H||"esm"},dt=X.createLogger({level:"debug",format:X.format.combine(X.format.colorize(),X.format.cli()),transports:[new X.transports.Console({})]});function Tt(t){return t?typeof t!="string"?Tt(String(t)):t.replace(/[^\d\w]/g,"."):""}const Xt={"*, *::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"}},G=(...t)=>t.flat().reduce((e,s)=>s!=null&&s._current?{...e,...s._current}:{...e,...s},{}),Yt=(...t)=>t.flat().reduce((e,s)=>({...e,...s._children}),{});class te{constructor(e){st(this,"_path");this.params=e}get _current(){return this.params.template}get isDefineTemplate(){return!0}_setPath(e){return this._path=e,this}}class ee{constructor(e){st(this,"_path");st(this,"templates",[]);this.params=e,Object.entries(e).forEach(([s,n])=>{this.templates.push(new te({name:s,template:n}))})}get _current(){return this.params}get _children(){return Object.fromEntries(this.templates.map(e=>[e.params.name,e]))}get isDefineTemplates(){return!0}_setPath(e){return this._path=e,this.templates.forEach(s=>s._setPath(e)),this}}const se=t=>new ee(t),ne=(t,e)=>new Promise((s,n)=>{const o=setTimeout(()=>{n(new Error("Timeout"))},100),r=ft.createSourceFile("temp.ts",t,ft.ScriptTarget.Latest,!0);function i(y){if(ft.isVariableDeclaration(y)&&y.name.getText()===e){const $=y.getStart(),m=y.getEnd();clearTimeout(o),s([$,m])}y.forEachChild(i)}i(r)}),z={externalModules:[],rcFile:void 0,destDir:void 0},kt=t=>{if(z.externalModules.length>0)return z.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 z.externalModules=n,n},I=async t=>{if(z.destDir)return z.destDir;const e=await mt(t),s=c.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return z.destDir=s,s},Dt=["salty","css","styles","styled"],oe=(t=[])=>new RegExp(`\\.(${[...Dt,...t].join("|")})\\.`),L=(t,e=[])=>oe(e).test(t),Ot=async t=>{if(z.rcFile)return z.rcFile;if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=c.join(t,".saltyrc.json"),s=await pt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(z.rcFile=s,s):Ot(c.join(t,".."))},mt=async t=>{var n,o;const e=await Ot(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))},ie=async t=>{const e=await mt(t),s=await I(t),n=c.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),o=c.join(s,"salty.config.js"),r=await xt(t),i=kt(n);await Ft.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:r,external:i});const y=Date.now(),{config:$}=await import(`${o}?t=${y}`);return{config:$,path:o}},re=async(t,e)=>{var gt,wt;const s=await I(t),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...e].map(async j=>{const{contents:x,outputFilePath:Z}=await ot(t,j,s);Object.entries(x).forEach(([O,k])=>{k.isMedia?n.mediaQueries.push([O,k]):k.isGlobalDefine?n.globalStyles.push(k):k.isDefineVariables?n.variables.push(k):k.isDefineTemplates&&n.templates.push(k._setPath(`${O};;${Z}`))})}));const{config:o,path:r}=await ie(t),i={...o},{mediaQueries:y}=n;i.mediaQueries=Object.fromEntries(y.map(([j,x])=>[`@${j}`,x]));const $=y.map(([j])=>`'@${j}'`).join(" | "),m=new Set,l=async(j,x=[])=>{if(!j)return[];const Z=Object.entries(j).map(async([k,A])=>{const B=async E=>{if(!E)return;if(E instanceof Promise)return await B(await E);if(typeof E=="function")return await B(await E());if(typeof E=="object")return await l(E,[...x,k]);const at=Tt(k),ct=M(k),lt=[...x,at].join(".");m.add(`"${lt}"`);const et=[...x.map(M),ct].join("-"),$t=Ht(E);return $t?`--${et}: ${$t.transformed};`:`--${et}: ${E};`};return await B(A)});return(await Promise.all(Z)).flat()},g=async j=>{if(!j)return[];const x=Object.entries(j).map(async([O,k])=>{const A=await l(k);return O==="base"?A.join(""):i.mediaQueries[O]?`${i.mediaQueries[O]} { ${A.join("")} }`:`${O} { ${A.join("")} }`});return(await Promise.all(x)).flat()},h=async j=>{if(!j)return[];const x=Object.entries(j).map(async([O,k])=>{const A=Object.entries(k).map(async([E,at])=>{const ct=await l(at,[O]),lt=`.${O}-${E}, [data-${O}="${E}"]`,et=ct.join("");return`${lt} { ${et} }`});return(await Promise.all(A)).flat()});return(await Promise.all(x)).flat()},S=j=>({...j,responsive:void 0,conditional:void 0}),p=j=>n.variables.map(x=>j==="static"?S(x._current):x._current[j]),u=G(S(o.variables),p("static")),w=await l(u),P=G((gt=o.variables)==null?void 0:gt.responsive,p("responsive")),T=await g(P),V=G((wt=o.variables)==null?void 0:wt.conditional,p("conditional")),D=await h(V),J=c.join(s,"css/_variables.css"),N=`:root { ${w.join("")} ${T.join("")} } ${D.join("")}`;d.writeFileSync(J,N),i.staticVariables=u;const v=c.join(s,"css/_global.css"),f=G(o.global,n.globalStyles),b=await Y(f,"");d.writeFileSync(v,`@layer global { ${b} }`);const F=c.join(s,"css/_reset.css"),C=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:Xt,_=await Y(C,"");d.writeFileSync(F,`@layer reset { ${_} }`);const R=c.join(s,"css/_templates.css"),W=G(o.templates,n.templates),Q=await Pt(W),K=Ut(W);d.writeFileSync(R,`@layer templates { ${Q} }`),i.templates=W;const tt=o.templates?[se(o.templates)._setPath(`config;;${r}`)]:[],it=Yt(n.templates,tt);i.templatePaths=Object.fromEntries(Object.entries(it).map(([j,x])=>[j,x._path]));const U=c.join(s,"types/css-tokens.d.ts"),Vt=`
5
+ `),Pt=async(t,e=[])=>{if(!t)return"";const s=[],n={};for(const[o,i]of Object.entries(t))if(typeof i!="function")if(i&&typeof i=="object"){const r=o.trim(),y=await Pt(i,[...e,r]);s.push(y)}else n[o]=i;if(Object.keys(n).length){const o=e.map(M).join("-"),i="t_"+q(o,4),r=await Y(n,`.${o}, .${i}`);s.push(r)}return s.join(`
6
+ `)},Ut=t=>t?Object.entries(t).reduce((e,[s,n])=>(typeof n=="function"?e[s]="any":typeof n=="object"&&(e[s]=Nt(n).map(o=>`"${o}"`).join(" | ")),e),{}):{},Nt=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const i=e?`${e}.${n}`:n;return typeof o=="object"?Nt(o,i,s):s.add(e)}),[...s]):[],_t=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:_t(c.join(t,".."))},Zt=async t=>{const e=_t(t);return await pt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},Bt=async t=>{const e=await Zt(t);if(e)return e.type};let H;const xt=async t=>{if(H)return H;const e=await Bt(t);return e==="module"?H="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:ut&&ut.tagName.toUpperCase()==="SCRIPT"&&ut.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(H="cjs"),H||"esm"},dt=X.createLogger({level:"debug",format:X.format.combine(X.format.colorize(),X.format.cli()),transports:[new X.transports.Console({})]});function Tt(t){return t?typeof t!="string"?Tt(String(t)):t.replace(/[^\d\w]/g,"."):""}const Xt={"*, *::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"}},G=(...t)=>t.flat().reduce((e,s)=>s!=null&&s._current?{...e,...s._current}:{...e,...s},{}),Yt=(...t)=>t.flat().reduce((e,s)=>({...e,...s._children}),{});class te{constructor(e){st(this,"_path");this.params=e}get _current(){return this.params.template}get isDefineTemplate(){return!0}_setPath(e){return this._path=e,this}}class ee{constructor(e){st(this,"_path");st(this,"templates",[]);this.params=e,Object.entries(e).forEach(([s,n])=>{this.templates.push(new te({name:s,template:n}))})}get _current(){return this.params}get _children(){return Object.fromEntries(this.templates.map(e=>[e.params.name,e]))}get isDefineTemplates(){return!0}_setPath(e){return this._path=e,this.templates.forEach(s=>s._setPath(e)),this}}const se=t=>new ee(t),ne=(t,e)=>new Promise((s,n)=>{const o=setTimeout(()=>{n(new Error("Timeout"))},100),i=ft.createSourceFile("temp.ts",t,ft.ScriptTarget.Latest,!0);function r(y){if(ft.isVariableDeclaration(y)&&y.name.getText()===e){const $=y.getStart(),m=y.getEnd();clearTimeout(o),s([$,m])}y.forEachChild(r)}r(i)}),z={externalModules:[],rcFile:void 0,destDir:void 0},kt=t=>{if(z.externalModules.length>0)return z.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 z.externalModules=n,n},I=async t=>{if(z.destDir)return z.destDir;const e=await mt(t),s=c.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return z.destDir=s,s},Dt=["salty","css","styles","styled"],oe=(t=[])=>new RegExp(`\\.(${[...Dt,...t].join("|")})\\.`),L=(t,e=[])=>oe(e).test(t),Ot=async t=>{if(z.rcFile)return z.rcFile;if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=c.join(t,".saltyrc.json"),s=await pt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(z.rcFile=s,s):Ot(c.join(t,".."))},mt=async t=>{var n,o;const e=await Ot(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))},ie=async t=>{const e=await mt(t),s=await I(t),n=c.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),o=c.join(s,"salty.config.js"),i=await xt(t),r=kt(n);await Ft.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:i,external:r});const y=Date.now(),{config:$}=await import(`${o}?t=${y}`);return{config:$,path:o}},re=async(t,e)=>{var gt,wt;const s=await I(t),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...e].map(async j=>{const{contents:x,outputFilePath:Z}=await ot(t,j,s);Object.entries(x).forEach(([O,k])=>{k.isMedia?n.mediaQueries.push([O,k]):k.isGlobalDefine?n.globalStyles.push(k):k.isDefineVariables?n.variables.push(k):k.isDefineTemplates&&n.templates.push(k._setPath(`${O};;${Z}`))})}));const{config:o,path:i}=await ie(t),r={...o},{mediaQueries:y}=n;r.mediaQueries=Object.fromEntries(y.map(([j,x])=>[`@${j}`,x]));const $=y.map(([j])=>`'@${j}'`).join(" | "),m=new Set,l=async(j,x=[])=>{if(!j)return[];const Z=Object.entries(j).map(async([k,A])=>{const B=async E=>{if(!E)return;if(E instanceof Promise)return await B(await E);if(typeof E=="function")return await B(await E());if(typeof E=="object")return await l(E,[...x,k]);const at=Tt(k),ct=M(k),lt=[...x,at].join(".");m.add(`"${lt}"`);const et=[...x.map(M),ct].join("-"),$t=Ht(E);return $t?`--${et}: ${$t.transformed};`:`--${et}: ${E};`};return await B(A)});return(await Promise.all(Z)).flat()},g=async j=>{if(!j)return[];const x=Object.entries(j).map(async([O,k])=>{const A=await l(k);return O==="base"?A.join(""):r.mediaQueries[O]?`${r.mediaQueries[O]} { ${A.join("")} }`:`${O} { ${A.join("")} }`});return(await Promise.all(x)).flat()},h=async j=>{if(!j)return[];const x=Object.entries(j).map(async([O,k])=>{const A=Object.entries(k).map(async([E,at])=>{const ct=await l(at,[O]),lt=`.${O}-${E}, [data-${O}="${E}"]`,et=ct.join("");return`${lt} { ${et} }`});return(await Promise.all(A)).flat()});return(await Promise.all(x)).flat()},b=j=>({...j,responsive:void 0,conditional:void 0}),p=j=>n.variables.map(x=>j==="static"?b(x._current):x._current[j]),u=G(b(o.variables),p("static")),w=await l(u),P=G((gt=o.variables)==null?void 0:gt.responsive,p("responsive")),T=await g(P),V=G((wt=o.variables)==null?void 0:wt.conditional,p("conditional")),D=await h(V),J=c.join(s,"css/_variables.css"),N=`:root { ${w.join("")} ${T.join("")} } ${D.join("")}`;d.writeFileSync(J,N),r.staticVariables=u;const R=c.join(s,"css/_global.css"),f=G(o.global,n.globalStyles),S=await Y(f,"");d.writeFileSync(R,`@layer global { ${S} }`);const F=c.join(s,"css/_reset.css"),C=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:Xt,_=await Y(C,"");d.writeFileSync(F,`@layer reset { ${_} }`);const v=c.join(s,"css/_templates.css"),W=G(o.templates,n.templates),Q=await Pt(W),K=Ut(W);d.writeFileSync(v,`@layer templates { ${Q} }`),r.templates=W;const tt=o.templates?[se(o.templates)._setPath(`config;;${i}`)]:[],it=Yt(n.templates,tt);r.templatePaths=Object.fromEntries(Object.entries(it).map(([j,x])=>[j,x._path]));const U=c.join(s,"types/css-tokens.d.ts"),Vt=`
7
7
  // Variable types
8
8
  type VariableTokens = ${[...m].join("|")};
9
9
  type PropertyValueToken = \`{\${VariableTokens}}\`;
@@ -16,31 +16,31 @@
16
16
 
17
17
  // Media query types
18
18
  type MediaQueryKeys = ${$||"''"};
19
- `;d.writeFileSync(U,Vt);const vt=c.join(s,"cache/config-cache.json");d.writeFileSync(vt,JSON.stringify(i,null,2))},St=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 i=o.exec(t);if(i){const y=i.at(1);if(Dt.some(m=>y==null?void 0:y.includes(m)))return e}return"styled('div',"}),ae=(t,e)=>{try{const s=d.readFileSync(c.join(e,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
19
+ `;d.writeFileSync(U,Vt);const Rt=c.join(s,"cache/config-cache.json");d.writeFileSync(Rt,JSON.stringify(r,null,2))},bt=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 r=o.exec(t);if(r){const y=r.at(1);if(Dt.some(m=>y==null?void 0:y.includes(m)))return e}return"styled('div',"}),ae=(t,e)=>{try{const s=d.readFileSync(c.join(e,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
20
20
 
21
21
  ${t}`:`globalThis.saltyConfig = {};
22
22
 
23
- ${t}`}catch{return t}},ot=async(t,e,s)=>{const n=q(e),o=c.join(s,"./temp");d.existsSync(o)||d.mkdirSync(o);const r=c.parse(e);let i=d.readFileSync(e,"utf8");i=St(i),i=ae(i,t);const y=c.join(s,"js",n+".js"),$=await mt(t),m=c.join(t,($==null?void 0:$.configDir)||"","salty.config.ts"),l=kt(m),g=await xt(t);await Ft.build({stdin:{contents:i,sourcefile:r.base,resolveDir:r.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:g,target:["node20"],keepNames:!0,external:l,packages:"external",plugins:[{name:"test",setup:p=>{p.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},u=>{const w=d.readFileSync(u.path,"utf8");return{contents:St(w),loader:"ts"}})}}]});const h=Date.now();return{contents:await import(`${y}?t=${h}`),outputFilePath:y}},ce=async t=>{const e=await I(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)},yt=async t=>{const e=await ce(t),s=await I(t),n=c.join(s,"salty.config.js"),o=Date.now(),{config:r}=await import(`${n}?t=${o}`);return G(r,e)},ht=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},le=async(t,e=ht(),s=!0)=>{try{const n=Date.now();e?dt.info("Generating CSS in production mode! 🔥"):dt.info("Generating CSS in development mode! 🚀");const o=[],r=[],i=await I(t),y=c.join(i,"index.css");s&&(()=>{d.existsSync(i)&&Jt.execSync("rm -rf "+i),d.mkdirSync(i,{recursive:!0}),d.mkdirSync(c.join(i,"css")),d.mkdirSync(c.join(i,"types")),d.mkdirSync(c.join(i,"js")),d.mkdirSync(c.join(i,"cache"))})();const m=new Set,l=new Set;async function g(f){const b=["node_modules","saltygen"],F=d.statSync(f);if(F.isDirectory()){const a=d.readdirSync(f);if(b.some(_=>f.includes(_)))return;await Promise.all(a.map(_=>g(c.join(f,_))))}else if(F.isFile()&&L(f)){m.add(f);const C=d.readFileSync(f,"utf8");/define[\w\d]+\(/.test(C)&&l.add(f)}}await g(t),await re(t,l);const h={keyframes:[],components:[],classNames:[]};await Promise.all([...m].map(async f=>{const{contents:b}=await ot(t,f,i);for(let[F,a]of Object.entries(b))a instanceof Promise&&(a=await a),a.isKeyframes?h.keyframes.push({value:a,src:f,name:F}):a.isClassName?h.classNames.push({...a,src:f,name:F}):a.generator&&h.components.push({...a,src:f,name:F})}));const S=await yt(t);for(const f of h.keyframes){const{value:b}=f,F=`a_${b.animationName}.css`,a=`css/${F}`,C=c.join(i,a);o.push(F),d.writeFileSync(C,b.css)}const p={};for(const f of h.components){const{src:b,name:F}=f;p[b]||(p[b]=[]);const a=f.generator._withBuildContext({callerName:F,isProduction:e,config:S});r[a.priority]||(r[a.priority]=[]);const C=await a.css;if(!C)continue;r[a.priority].push(a.cssFileName);const _=`css/${a.cssFileName}`,R=c.join(i,_);d.writeFileSync(R,C),S.importStrategy==="component"&&p[b].push(a.cssFileName)}for(const f of h.classNames){const{src:b,name:F}=f;p[b]||(p[b]=[]);const a=f.generator._withBuildContext({callerName:F,isProduction:e,config:S}),C=await a.css;if(!C)continue;r[a.priority]||(r[a.priority]=[]),r[a.priority].push(a.cssFileName);const _=`css/${a.cssFileName}`,R=c.join(i,_);d.writeFileSync(R,C),S.importStrategy==="component"&&p[b].push(a.cssFileName)}S.importStrategy==="component"&&Object.entries(p).forEach(([f,b])=>{const F=b.map(W=>`@import url('./${W}');`).join(`
24
- `),a=q(f,6),C=c.parse(f),_=M(C.name),R=c.join(i,`css/f_${_}-${a}.css`);d.writeFileSync(R,F||"/* Empty file */")});const u=o.map(f=>`@import url('./css/${f}');`).join(`
23
+ ${t}`}catch{return t}},ot=async(t,e,s)=>{const n=q(e),o=c.join(s,"./temp");d.existsSync(o)||d.mkdirSync(o);const i=c.parse(e);let r=d.readFileSync(e,"utf8");r=bt(r),r=ae(r,t);const y=c.join(s,"js",n+".js"),$=await mt(t),m=c.join(t,($==null?void 0:$.configDir)||"","salty.config.ts"),l=kt(m),g=await xt(t);await Ft.build({stdin:{contents:r,sourcefile:i.base,resolveDir:i.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:g,target:["node20"],keepNames:!0,external:l,packages:"external",plugins:[{name:"test",setup:p=>{p.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},u=>{const w=d.readFileSync(u.path,"utf8");return{contents:bt(w),loader:"ts"}})}}]});const h=Date.now();return{contents:await import(`${y}?t=${h}`),outputFilePath:y}},ce=async t=>{const e=await I(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)},yt=async t=>{const e=await ce(t),s=await I(t),n=c.join(s,"salty.config.js"),o=Date.now(),{config:i}=await import(`${n}?t=${o}`);return G(i,e)},ht=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},le=async(t,e=ht(),s=!0)=>{try{const n=Date.now();e?dt.info("Generating CSS in production mode! 🔥"):dt.info("Generating CSS in development mode! 🚀");const o=[],i=[],r=await I(t),y=c.join(r,"index.css");s&&(()=>{d.existsSync(r)&&Jt.execSync("rm -rf "+r),d.mkdirSync(r,{recursive:!0}),d.mkdirSync(c.join(r,"css")),d.mkdirSync(c.join(r,"types")),d.mkdirSync(c.join(r,"js")),d.mkdirSync(c.join(r,"cache"))})();const m=new Set,l=new Set;async function g(f){const S=["node_modules","saltygen"],F=d.statSync(f);if(F.isDirectory()){const a=d.readdirSync(f);if(S.some(_=>f.includes(_)))return;await Promise.all(a.map(_=>g(c.join(f,_))))}else if(F.isFile()&&L(f)){m.add(f);const C=d.readFileSync(f,"utf8");/define[\w\d]+\(/.test(C)&&l.add(f)}}await g(t),await re(t,l);const h={keyframes:[],components:[],classNames:[]};await Promise.all([...m].map(async f=>{const{contents:S}=await ot(t,f,r);for(let[F,a]of Object.entries(S))a instanceof Promise&&(a=await a),a.isKeyframes?h.keyframes.push({value:a,src:f,name:F}):a.isClassName?h.classNames.push({...a,src:f,name:F}):a.generator&&h.components.push({...a,src:f,name:F})}));const b=await yt(t);for(const f of h.keyframes){const{value:S}=f,F=`a_${S.animationName}.css`,a=`css/${F}`,C=c.join(r,a);o.push(F),d.writeFileSync(C,S.css)}const p={};for(const f of h.components){const{src:S,name:F}=f;p[S]||(p[S]=[]);const a=f.generator._withBuildContext({callerName:F,isProduction:e,config:b});i[a.priority]||(i[a.priority]=[]);const C=await a.css;if(!C)continue;i[a.priority].push(a.cssFileName);const _=`css/${a.cssFileName}`,v=c.join(r,_);d.writeFileSync(v,C),b.importStrategy==="component"&&p[S].push(a.cssFileName)}for(const f of h.classNames){const{src:S,name:F}=f;p[S]||(p[S]=[]);const a=f.generator._withBuildContext({callerName:F,isProduction:e,config:b}),C=await a.css;if(!C)continue;i[a.priority]||(i[a.priority]=[]),i[a.priority].push(a.cssFileName);const _=`css/${a.cssFileName}`,v=c.join(r,_);d.writeFileSync(v,C),b.importStrategy==="component"&&p[S].push(a.cssFileName)}b.importStrategy==="component"&&Object.entries(p).forEach(([f,S])=>{const F=S.map(W=>`@import url('./${W}');`).join(`
24
+ `),a=q(f,6),C=c.parse(f),_=M(C.name),v=c.join(r,`css/f_${_}-${a}.css`);d.writeFileSync(v,F||"/* Empty file */")});const u=o.map(f=>`@import url('./css/${f}');`).join(`
25
25
  `);let D=`/*!
26
26
  * Generated with Salty CSS (https://salty-css.dev)
27
27
  * Do not edit this file directly
28
28
  */
29
29
  @layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
30
30
 
31
- ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(f=>{try{return d.readFileSync(c.join(i,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
31
+ ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(f=>{try{return d.readFileSync(c.join(r,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
32
32
  `)}
33
- ${u}`;if(S.importStrategy!=="component"){const f=r.reduce((b,F,a)=>{const C=F.reduce((Q,K)=>{var rt;const tt=c.join(i,"css",K),it=d.readFileSync(tt,"utf8"),U=((rt=/.*-([^-]+)-\d+.css/.exec(K))==null?void 0:rt.at(1))||q(tt,6);return Q.includes(U)?Q:`${Q}
33
+ ${u}`;if(b.importStrategy!=="component"){const f=i.reduce((S,F,a)=>{const C=F.reduce((Q,K)=>{var rt;const tt=c.join(r,"css",K),it=d.readFileSync(tt,"utf8"),U=((rt=/.*-([^-]+)-\d+.css/.exec(K))==null?void 0:rt.at(1))||q(tt,6);return Q.includes(U)?Q:`${Q}
34
34
  /*start:${U}-${K}*/
35
35
  ${it}
36
36
  /*end:${U}*/
37
- `},""),_=`l_${a}.css`,R=c.join(i,"css",_),W=`@layer l${a} { ${C}
38
- }`;return d.writeFileSync(R,W),`${b}
39
- @import url('./css/${_}');`},"");D+=f}d.writeFileSync(y,D);const N=Date.now()-n,v=N<200?"🔥":N<500?"🚀":N<1e3?"🎉":N<2e3?"🚗":N<5e3?"🤔":"🥴";dt.info(`Generated CSS in ${N}ms! ${v}`)}catch(n){console.error(n)}},fe=async(t,e,s=ht())=>{try{const n=await I(t);if(L(e)){const r=[],i=await yt(t),{contents:y}=await ot(t,e,n);for(const[$,m]of Object.entries(y)){if(m.isKeyframes&&m.css){const u=`css/${`a_${m.animationName}.css`}`,w=c.join(n,u);d.writeFileSync(w,await m.css);continue}if(m.isClassName){const p=m.generator._withBuildContext({callerName:$,isProduction:s,config:i}),u=await p.css;if(!u)continue;r[p.priority]||(r[p.priority]=[]),r[p.priority].push(p.cssFileName);const w=`css/${p.cssFileName}`,P=c.join(n,w);d.writeFileSync(P,u);continue}if(!m.generator)continue;const l=m.generator._withBuildContext({callerName:$,isProduction:s,config:i}),g=await l.css;if(!g)continue;const h=`css/${l.cssFileName}`,S=c.join(n,h);d.writeFileSync(S,g),r[l.priority]||(r[l.priority]=[]),r[l.priority].push(l.cssFileName)}if(i.importStrategy!=="component")r.forEach(($,m)=>{const l=`l_${m}.css`,g=c.join(n,"css",l);let h=d.readFileSync(g,"utf8");$.forEach(S=>{var P;const p=c.join(n,"css",S),u=((P=/.*-([^-]+)-\d+.css/.exec(S))==null?void 0:P.at(1))||q(p,6);if(!h.includes(u)){const T=d.readFileSync(p,"utf8"),V=`/*start:${u}-${S}*/
37
+ `},""),_=`l_${a}.css`,v=c.join(r,"css",_),W=`@layer l${a} { ${C}
38
+ }`;return d.writeFileSync(v,W),`${S}
39
+ @import url('./css/${_}');`},"");D+=f}d.writeFileSync(y,D);const N=Date.now()-n,R=N<200?"🔥":N<500?"🚀":N<1e3?"🎉":N<2e3?"🚗":N<5e3?"🤔":"🥴";dt.info(`Generated CSS in ${N}ms! ${R}`)}catch(n){console.error(n)}},fe=async(t,e,s=ht())=>{try{const n=await I(t);if(L(e)){const i=[],r=await yt(t),{contents:y}=await ot(t,e,n);for(const[$,m]of Object.entries(y)){if(m.isKeyframes&&m.css){const u=`css/${`a_${m.animationName}.css`}`,w=c.join(n,u);d.writeFileSync(w,await m.css);continue}if(m.isClassName){const p=m.generator._withBuildContext({callerName:$,isProduction:s,config:r}),u=await p.css;if(!u)continue;i[p.priority]||(i[p.priority]=[]),i[p.priority].push(p.cssFileName);const w=`css/${p.cssFileName}`,P=c.join(n,w);d.writeFileSync(P,u);continue}if(!m.generator)continue;const l=m.generator._withBuildContext({callerName:$,isProduction:s,config:r}),g=await l.css;if(!g)continue;const h=`css/${l.cssFileName}`,b=c.join(n,h);d.writeFileSync(b,g),i[l.priority]||(i[l.priority]=[]),i[l.priority].push(l.cssFileName)}if(r.importStrategy!=="component")i.forEach(($,m)=>{const l=`l_${m}.css`,g=c.join(n,"css",l);let h=d.readFileSync(g,"utf8");$.forEach(b=>{var P;const p=c.join(n,"css",b),u=((P=/.*-([^-]+)-\d+.css/.exec(b))==null?void 0:P.at(1))||q(p,6);if(!h.includes(u)){const T=d.readFileSync(p,"utf8"),V=`/*start:${u}-${b}*/
40
40
  ${T}
41
41
  /*end:${u}*/
42
42
  `;h=`${h.replace(/\}$/,"")}
43
43
  ${V}
44
- }`}}),d.writeFileSync(g,h)});else{const $=r.flat().map(S=>`@import url('./${S}');`).join(`
45
- `),m=q(e,6),l=c.parse(e),g=M(l.name),h=c.join(n,`css/f_${g}-${m}.css`);d.writeFileSync(h,$||"/* Empty file */")}}}catch(n){console.error(n)}},ue=async(t,e,s=ht())=>{var n,o;try{const r=await I(t);if(L(e)){const y=d.readFileSync(e,"utf8"),$=await yt(t),{contents:m}=await ot(t,e,r);let l=y;for(const[g,h]of Object.entries(m)){if(h.isKeyframes||!h.generator)continue;const S=h.generator._withBuildContext({callerName:g,isProduction:s,config:$}),[p,u]=await ne(l,g),w=l.slice(p,u);if(h.isClassName){const P=l,T=` ${g} = className("${S.classNames}")`;l=l.replace(w,T),P===l&&console.error("Minimize file failed to change content",{name:g})}if(w.includes("styled")){const P=(o=(n=/styled\(([^,]+),/.exec(w))==null?void 0:n.at(1))==null?void 0:o.trim(),T=l,V=` ${g} = styled(${P}, "${S.classNames}", ${JSON.stringify(S.clientProps)})`;l=l.replace(w,V),T===l&&console.error("Minimize file failed to change content",{name:g,tagName:P})}}if($.importStrategy==="component"){const g=q(e,6),h=c.parse(e);l=`import '../../saltygen/css/${`f_${M(h.name)}-${g}.css`}';
46
- ${l}`}return l=l.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),l=l.replace("{ styled }","{ styledClient as styled }"),l=l.replace("@salty-css/react/styled","@salty-css/react/styled-client"),l}}catch(r){console.error("Error in minimizeFile:",r)}},jt=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!L(t))return!1;const n=await pt.readFile(t,"utf-8");return!!(/.+define[A-Z]\w+/.test(n)||/.+keyframes\(.+/.test(n))},Et=t=>({name:"stylegen",buildStart:()=>le(t),load:async e=>{if(L(e))return await ue(t,e)},handleHotUpdate:async({file:e,server:s})=>{await jt(e)&&s.restart()},watchChange:{handler:async(e,s)=>{L(e)&&s.event!=="delete"&&(await jt(e)||await fe(t,e))}}});exports.default=Et;exports.saltyPlugin=Et;
44
+ }`}}),d.writeFileSync(g,h)});else{const $=i.flat().map(b=>`@import url('./${b}');`).join(`
45
+ `),m=q(e,6),l=c.parse(e),g=M(l.name),h=c.join(n,`css/f_${g}-${m}.css`);d.writeFileSync(h,$||"/* Empty file */")}}}catch(n){console.error(n)}},ue=async(t,e,s=ht())=>{var n,o;try{const i=await I(t);if(L(e)){const y=d.readFileSync(e,"utf8"),$=await yt(t),{contents:m}=await ot(t,e,i);let l=y;for(const[g,h]of Object.entries(m)){if(h.isKeyframes||!h.generator)continue;const b=h.generator._withBuildContext({callerName:g,isProduction:s,config:$}),[p,u]=await ne(l,g),w=l.slice(p,u);if(h.isClassName){const P=l,T=` ${g} = className("${b.classNames}")`;l=l.replace(w,T),P===l&&console.error("Minimize file failed to change content",{name:g})}if(w.includes("styled")){const P=(o=(n=/styled\(([^,]+),/.exec(w))==null?void 0:n.at(1))==null?void 0:o.trim(),T=l,V=` ${g} = styled(${P}, "${b.classNames}", ${JSON.stringify(b.clientProps)})`;l=l.replace(w,V),T===l&&console.error("Minimize file failed to change content",{name:g,tagName:P})}}if($.importStrategy==="component"){const g=q(e,6),h=c.parse(e);l=`import '../../saltygen/css/${`f_${M(h.name)}-${g}.css`}';
46
+ ${l}`}return l=l.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),l=l.replace("{ styled }","{ styledClient as styled }"),l=l.replace("@salty-css/react/styled","@salty-css/react/styled-client"),l}}catch(i){console.error("Error in minimizeFile:",i)}},jt=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!L(t))return!1;const n=await pt.readFile(t,"utf-8");return!!(/.+define[A-Z]\w+/.test(n)||/.+keyframes\(.+/.test(n))},Et=t=>({name:"stylegen",buildStart:()=>le(t),load:async e=>{if(L(e))return await ue(t,e)},handleHotUpdate:async({file:e,server:s})=>{await jt(e)&&s.restart()},watchChange:{handler:async(e,s)=>{L(e)&&s.event!=="delete"&&(await jt(e)||await fe(t,e))}}});exports.default=Et;exports.saltyPlugin=Et;
package/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  var Jt = Object.defineProperty;
2
- var zt = (e, t, s) => t in e ? Jt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
3
- var nt = (e, t, s) => zt(e, typeof t != "symbol" ? t + "" : t, s);
2
+ var Wt = (e, t, s) => t in e ? Jt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
3
+ var nt = (e, t, s) => Wt(e, typeof t != "symbol" ? t + "" : t, s);
4
4
  import * as Nt from "esbuild";
5
- import { execSync as Wt } from "child_process";
5
+ import { execSync as zt } from "child_process";
6
6
  import { join as u, parse as rt } from "path";
7
- import { existsSync as yt, mkdirSync as K, statSync as At, readdirSync as Ht, readFileSync as R, writeFileSync as T } from "fs";
8
- import { readFile as ht } from "fs/promises";
7
+ import { existsSync as ht, mkdirSync as K, statSync as At, readdirSync as Ht, readFileSync as v, writeFileSync as T } from "fs";
8
+ import { readFile as yt } from "fs/promises";
9
9
  import { createLogger as Gt, format as dt, transports as It } from "winston";
10
10
  import pt from "typescript";
11
11
  const jt = (e) => String.fromCharCode(e + (e > 25 ? 39 : 97)), Qt = (e, t) => {
@@ -28,13 +28,16 @@ const Lt = (e) => (t) => {
28
28
  let s = t;
29
29
  const n = [];
30
30
  return Object.values(e).forEach((o) => {
31
- const { pattern: a, transform: r } = o;
32
- s = s.replace(a, (m) => {
33
- const { value: w, css: p } = r(m);
31
+ const { pattern: r, transform: a } = o;
32
+ s = s.replace(r, (m) => {
33
+ const { value: w, css: p } = a(m);
34
34
  return p && n.push(p), w;
35
35
  });
36
36
  }), { transformed: s, additionalCss: n };
37
- }, _t = (e) => (t) => typeof t != "string" || !/\{[^{}]+\}/g.test(t) ? void 0 : { transformed: t.replace(/\{([^{}]+)\}/g, (...o) => `var(--${J(o[1].replaceAll(".", "-"))})`) }, Zt = _t(), Bt = [
37
+ }, _t = (e) => (t) => typeof t != "string" || !/\{[^{}]+\}/g.test(t) ? void 0 : { transformed: t.replace(/\{([^{}]+)\}/g, (...o) => {
38
+ const r = J(o[1].replaceAll(".", "-"));
39
+ return r.startsWith("-") ? `-${r}` : `var(--${r})`;
40
+ }) }, Zt = _t(), Bt = [
38
41
  "top",
39
42
  "right",
40
43
  "bottom",
@@ -57,40 +60,40 @@ const Lt = (e) => (t) => {
57
60
  /.*font-size.*/
58
61
  ], Ut = (e, t, s) => Bt.some((o) => typeof o == "string" ? o === e : o.test(e)) ? `${t}px` : `${t}`, qt = ["Webkit", "Moz", "ms", "O"], Xt = (e) => e.startsWith("-") ? e : qt.some((t) => e.startsWith(t)) ? `-${J(e)}` : J(e), ot = async (e, t = "", s, n = !1) => {
59
62
  if (!e) throw new Error("No styles provided to parseStyles function!");
60
- const o = /* @__PURE__ */ new Set(), a = Object.entries(e), r = async ([d, f]) => {
61
- const g = d.trim(), F = Xt(g), x = (k, W = ";") => `${F}:${k}${W}`, V = { scope: t, config: s };
62
- if (typeof f == "function") return r([d, f(V)]);
63
- if (f instanceof Promise) return r([d, await f]);
63
+ const o = /* @__PURE__ */ new Set(), r = Object.entries(e), a = async ([d, f]) => {
64
+ const g = d.trim(), F = Xt(g), x = (k, z = ";") => `${F}:${k}${z}`, V = { scope: t, config: s };
65
+ if (typeof f == "function") return a([d, f(V)]);
66
+ if (f instanceof Promise) return a([d, await f]);
64
67
  if (typeof f == "object") {
65
68
  if (!f) return;
66
69
  if (f.isColor) return x(f.toString());
67
70
  if (g === "defaultVariants") return;
68
71
  if (g === "variants") {
69
72
  const P = Object.entries(f);
70
- for (const [v, l] of P) {
73
+ for (const [M, l] of P) {
71
74
  if (!l) continue;
72
75
  const $ = Object.entries(l);
73
76
  for (const [C, i] of $) {
74
77
  if (!i) continue;
75
- const j = `${t}.${v}-${C}`;
76
- (await ot(i, j, s)).forEach((M) => o.add(M));
78
+ const j = `${t}.${M}-${C}`;
79
+ (await ot(i, j, s)).forEach((R) => o.add(R));
77
80
  }
78
81
  }
79
82
  return;
80
83
  }
81
84
  if (g === "compoundVariants") {
82
85
  for (const P of f) {
83
- const { css: v, ...l } = P, $ = Object.entries(l).reduce((i, [j, N]) => `${i}.${j}-${N}`, t);
84
- (await ot(v, $, s)).forEach((i) => o.add(i));
86
+ const { css: M, ...l } = P, $ = Object.entries(l).reduce((i, [j, N]) => `${i}.${j}-${N}`, t);
87
+ (await ot(M, $, s)).forEach((i) => o.add(i));
85
88
  }
86
89
  return;
87
90
  }
88
91
  if (g.startsWith("@")) {
89
- const P = g, v = await tt(f, t, s), l = `${P} { ${v} }`;
92
+ const P = g, M = await tt(f, t, s), l = `${P} { ${M} }`;
90
93
  o.add(l);
91
94
  return;
92
95
  }
93
- const k = d.includes("&") ? g.replace("&", t) : g.startsWith(":") ? `${t}${g}` : `${t} ${g}`;
96
+ const k = d.includes("&") ? g.replaceAll("&", t) : g.startsWith(":") ? `${t}${g}` : `${t} ${g}`;
94
97
  (await ot(f, k, s)).forEach((P) => o.add(P));
95
98
  return;
96
99
  }
@@ -102,52 +105,52 @@ const Lt = (e) => (t) => {
102
105
  if ("toString" in f) f = f.toString();
103
106
  else throw new Error(`Invalid value type for property ${F}`);
104
107
  return x(f);
105
- }, m = a.map(r), { modifiers: w } = {}, p = [_t(), Lt(w)], h = (await Promise.all(m).then((d) => Promise.all(
108
+ }, m = r.map(a), { modifiers: w } = {}, p = [_t(), Lt(w)], y = (await Promise.all(m).then((d) => Promise.all(
106
109
  d.map((f) => p.reduce(async (g, F) => {
107
110
  const x = await g;
108
111
  if (!x) return x;
109
112
  const V = await F(x);
110
113
  if (!V) return x;
111
- const { transformed: k, additionalCss: W } = V;
114
+ const { transformed: k, additionalCss: z } = V;
112
115
  let P = "";
113
- if (W)
114
- for (const v of W)
115
- P += await tt(v, "");
116
+ if (z)
117
+ for (const M of z)
118
+ P += await tt(M, "");
116
119
  return `${P}${k}`;
117
120
  }, Promise.resolve(f)))
118
121
  ))).filter((d) => d !== void 0).join(`
119
122
  `);
120
- if (!h.trim()) return Array.from(o);
121
- const y = t ? `${t} {
122
- ${h}
123
- }` : h;
124
- return o.has(y) ? Array.from(o) : [y, ...o];
123
+ if (!y.trim()) return Array.from(o);
124
+ const h = t ? `${t} {
125
+ ${y}
126
+ }` : y;
127
+ return o.has(h) ? Array.from(o) : [h, ...o];
125
128
  }, tt = async (e, t, s, n = !1) => (await ot(e, t, s, n)).join(`
126
129
  `), xt = async (e, t = []) => {
127
130
  if (!e) return "";
128
131
  const s = [], n = {};
129
- for (const [o, a] of Object.entries(e))
130
- if (typeof a != "function") if (a && typeof a == "object") {
131
- const r = o.trim(), m = await xt(a, [...t, r]);
132
+ for (const [o, r] of Object.entries(e))
133
+ if (typeof r != "function") if (r && typeof r == "object") {
134
+ const a = o.trim(), m = await xt(r, [...t, a]);
132
135
  s.push(m);
133
136
  } else
134
- n[o] = a;
137
+ n[o] = r;
135
138
  if (Object.keys(n).length) {
136
- const o = t.map(J).join("-"), a = "t_" + G(o, 4), r = await tt(n, `.${o}, .${a}`);
137
- s.push(r);
139
+ const o = t.map(J).join("-"), r = "t_" + G(o, 4), a = await tt(n, `.${o}, .${r}`);
140
+ s.push(a);
138
141
  }
139
142
  return s.join(`
140
143
  `);
141
144
  }, Yt = (e) => e ? Object.entries(e).reduce((t, [s, n]) => (typeof n == "function" ? t[s] = "any" : typeof n == "object" && (t[s] = Tt(n).map((o) => `"${o}"`).join(" | ")), t), {}) : {}, Tt = (e, t = "", s = /* @__PURE__ */ new Set()) => e ? (Object.entries(e).forEach(([n, o]) => {
142
- const a = t ? `${t}.${n}` : n;
143
- return typeof o == "object" ? Tt(o, a, s) : s.add(t);
145
+ const r = t ? `${t}.${n}` : n;
146
+ return typeof o == "object" ? Tt(o, r, s) : s.add(t);
144
147
  }), [...s]) : [], Dt = (e) => {
145
148
  if (!e || e === "/") throw new Error("Could not find package.json file");
146
149
  const t = u(e, "package.json");
147
- return yt(t) ? t : Dt(u(e, ".."));
150
+ return ht(t) ? t : Dt(u(e, ".."));
148
151
  }, te = async (e) => {
149
152
  const t = Dt(e);
150
- return await ht(t, "utf-8").then(JSON.parse).catch(() => {
153
+ return await yt(t, "utf-8").then(JSON.parse).catch(() => {
151
154
  });
152
155
  }, ee = async (e) => {
153
156
  const t = await te(e);
@@ -260,49 +263,49 @@ class re {
260
263
  const ae = (e) => new re(e), ie = (e, t) => new Promise((s, n) => {
261
264
  const o = setTimeout(() => {
262
265
  n(new Error("Timeout"));
263
- }, 100), a = pt.createSourceFile("temp.ts", e, pt.ScriptTarget.Latest, !0);
264
- function r(m) {
266
+ }, 100), r = pt.createSourceFile("temp.ts", e, pt.ScriptTarget.Latest, !0);
267
+ function a(m) {
265
268
  if (pt.isVariableDeclaration(m) && m.name.getText() === t) {
266
269
  const w = m.getStart(), p = m.getEnd();
267
270
  clearTimeout(o), s([w, p]);
268
271
  }
269
- m.forEachChild(r);
272
+ m.forEachChild(a);
270
273
  }
271
- r(a);
272
- }), z = {
274
+ a(r);
275
+ }), W = {
273
276
  externalModules: [],
274
277
  rcFile: void 0,
275
278
  destDir: void 0
276
279
  }, Ot = (e) => {
277
- if (z.externalModules.length > 0) return z.externalModules;
278
- const s = R(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
280
+ if (W.externalModules.length > 0) return W.externalModules;
281
+ const s = v(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
279
282
  if (!s) return [];
280
283
  const n = s[1].split(",").map((o) => o.replace(/['"`]/g, "").trim());
281
- return z.externalModules = n, n;
284
+ return W.externalModules = n, n;
282
285
  }, I = async (e) => {
283
- if (z.destDir) return z.destDir;
286
+ if (W.destDir) return W.destDir;
284
287
  const t = await gt(e), s = u(e, (t == null ? void 0 : t.saltygenDir) || "saltygen");
285
- return z.destDir = s, s;
286
- }, Vt = ["salty", "css", "styles", "styled"], ce = (e = []) => new RegExp(`\\.(${[...Vt, ...e].join("|")})\\.`), Z = (e, t = []) => ce(t).test(e), vt = async (e) => {
287
- if (z.rcFile) return z.rcFile;
288
+ return W.destDir = s, s;
289
+ }, Vt = ["salty", "css", "styles", "styled"], ce = (e = []) => new RegExp(`\\.(${[...Vt, ...e].join("|")})\\.`), Z = (e, t = []) => ce(t).test(e), Mt = async (e) => {
290
+ if (W.rcFile) return W.rcFile;
288
291
  if (e === "/") throw new Error("Could not find .saltyrc.json file");
289
- const t = u(e, ".saltyrc.json"), s = await ht(t, "utf-8").then(JSON.parse).catch(() => {
292
+ const t = u(e, ".saltyrc.json"), s = await yt(t, "utf-8").then(JSON.parse).catch(() => {
290
293
  });
291
- return s ? (z.rcFile = s, s) : vt(u(e, ".."));
294
+ return s ? (W.rcFile = s, s) : Mt(u(e, ".."));
292
295
  }, gt = async (e) => {
293
296
  var n, o;
294
- const t = await vt(e), s = (n = t.projects) == null ? void 0 : n.find((a) => e.endsWith(a.dir || ""));
295
- return s || ((o = t.projects) == null ? void 0 : o.find((a) => a.dir === t.defaultProject));
297
+ const t = await Mt(e), s = (n = t.projects) == null ? void 0 : n.find((r) => e.endsWith(r.dir || ""));
298
+ return s || ((o = t.projects) == null ? void 0 : o.find((r) => r.dir === t.defaultProject));
296
299
  }, le = async (e) => {
297
- const t = await gt(e), s = await I(e), n = u(e, (t == null ? void 0 : t.configDir) || "", "salty.config.ts"), o = u(s, "salty.config.js"), a = await kt(e), r = Ot(n);
300
+ const t = await gt(e), s = await I(e), n = u(e, (t == null ? void 0 : t.configDir) || "", "salty.config.ts"), o = u(s, "salty.config.js"), r = await kt(e), a = Ot(n);
298
301
  await Nt.build({
299
302
  entryPoints: [n],
300
303
  minify: !0,
301
304
  treeShaking: !0,
302
305
  bundle: !0,
303
306
  outfile: o,
304
- format: a,
305
- external: r
307
+ format: r,
308
+ external: a
306
309
  });
307
310
  const m = Date.now(), { config: w } = await import(`${o}?t=${m}`);
308
311
  return { config: w, path: o };
@@ -322,8 +325,8 @@ const ae = (e) => new re(e), ie = (e, t) => new Promise((s, n) => {
322
325
  });
323
326
  })
324
327
  );
325
- const { config: o, path: a } = await le(e), r = { ...o }, { mediaQueries: m } = n;
326
- r.mediaQueries = Object.fromEntries(m.map(([S, _]) => [`@${S}`, _]));
328
+ const { config: o, path: r } = await le(e), a = { ...o }, { mediaQueries: m } = n;
329
+ a.mediaQueries = Object.fromEntries(m.map(([S, _]) => [`@${S}`, _]));
327
330
  const w = m.map(([S]) => `'@${S}'`).join(" | "), p = /* @__PURE__ */ new Set(), c = async (S, _ = []) => {
328
331
  if (!S) return [];
329
332
  const X = Object.entries(S).map(async ([D, H]) => {
@@ -340,14 +343,14 @@ const ae = (e) => new re(e), ie = (e, t) => new Promise((s, n) => {
340
343
  return await Y(H);
341
344
  });
342
345
  return (await Promise.all(X)).flat();
343
- }, h = async (S) => {
346
+ }, y = async (S) => {
344
347
  if (!S) return [];
345
348
  const _ = Object.entries(S).map(async ([E, D]) => {
346
349
  const H = await c(D);
347
- return E === "base" ? H.join("") : r.mediaQueries[E] ? `${r.mediaQueries[E]} { ${H.join("")} }` : `${E} { ${H.join("")} }`;
350
+ return E === "base" ? H.join("") : a.mediaQueries[E] ? `${a.mediaQueries[E]} { ${H.join("")} }` : `${E} { ${H.join("")} }`;
348
351
  });
349
352
  return (await Promise.all(_)).flat();
350
- }, y = async (S) => {
353
+ }, h = async (S) => {
351
354
  if (!S) return [];
352
355
  const _ = Object.entries(S).map(async ([E, D]) => {
353
356
  const H = Object.entries(D).map(async ([O, lt]) => {
@@ -357,17 +360,17 @@ const ae = (e) => new re(e), ie = (e, t) => new Promise((s, n) => {
357
360
  return (await Promise.all(H)).flat();
358
361
  });
359
362
  return (await Promise.all(_)).flat();
360
- }, b = (S) => ({ ...S, responsive: void 0, conditional: void 0 }), d = (S) => n.variables.map((_) => S === "static" ? b(_._current) : _._current[S]), f = L(b(o.variables), d("static")), g = await c(f), F = L((bt = o.variables) == null ? void 0 : bt.responsive, d("responsive")), x = await h(F), V = L((St = o.variables) == null ? void 0 : St.conditional, d("conditional")), k = await y(V), W = u(s, "css/_variables.css"), P = `:root { ${g.join("")} ${x.join("")} } ${k.join("")}`;
361
- T(W, P), r.staticVariables = f;
362
- const v = u(s, "css/_global.css"), l = L(o.global, n.globalStyles), $ = await tt(l, "");
363
- T(v, `@layer global { ${$} }`);
363
+ }, b = (S) => ({ ...S, responsive: void 0, conditional: void 0 }), d = (S) => n.variables.map((_) => S === "static" ? b(_._current) : _._current[S]), f = L(b(o.variables), d("static")), g = await c(f), F = L((bt = o.variables) == null ? void 0 : bt.responsive, d("responsive")), x = await y(F), V = L((St = o.variables) == null ? void 0 : St.conditional, d("conditional")), k = await h(V), z = u(s, "css/_variables.css"), P = `:root { ${g.join("")} ${x.join("")} } ${k.join("")}`;
364
+ T(z, P), a.staticVariables = f;
365
+ const M = u(s, "css/_global.css"), l = L(o.global, n.globalStyles), $ = await tt(l, "");
366
+ T(M, `@layer global { ${$} }`);
364
367
  const C = u(s, "css/_reset.css"), j = o.reset === "none" ? {} : typeof o.reset == "object" ? o.reset : se, N = await tt(j, "");
365
368
  T(C, `@layer reset { ${N} }`);
366
- const M = u(s, "css/_templates.css"), A = L(o.templates, n.templates), B = await xt(A), U = Yt(A);
367
- T(M, `@layer templates { ${B} }`), r.templates = A;
368
- const et = o.templates ? [ae(o.templates)._setPath(`config;;${a}`)] : [], it = ne(n.templates, et);
369
- r.templatePaths = Object.fromEntries(Object.entries(it).map(([S, _]) => [S, _._path]));
370
- const q = u(s, "types/css-tokens.d.ts"), Mt = `
369
+ const R = u(s, "css/_templates.css"), A = L(o.templates, n.templates), B = await xt(A), U = Yt(A);
370
+ T(R, `@layer templates { ${B} }`), a.templates = A;
371
+ const et = o.templates ? [ae(o.templates)._setPath(`config;;${r}`)] : [], it = ne(n.templates, et);
372
+ a.templatePaths = Object.fromEntries(Object.entries(it).map(([S, _]) => [S, _._path]));
373
+ const q = u(s, "types/css-tokens.d.ts"), Rt = `
371
374
  // Variable types
372
375
  type VariableTokens = ${[...p].join("|")};
373
376
  type PropertyValueToken = \`{\${VariableTokens}}\`;
@@ -381,22 +384,22 @@ const ae = (e) => new re(e), ie = (e, t) => new Promise((s, n) => {
381
384
  // Media query types
382
385
  type MediaQueryKeys = ${w || "''"};
383
386
  `;
384
- T(q, Mt);
385
- const Rt = u(s, "cache/config-cache.json");
386
- T(Rt, JSON.stringify(r, null, 2));
387
+ T(q, Rt);
388
+ const vt = u(s, "cache/config-cache.json");
389
+ T(vt, JSON.stringify(a, null, 2));
387
390
  }, Ft = (e) => e.replace(/styled\(([^"'`{,]+),/g, (t, s) => {
388
391
  if (/^['"`]/.test(s)) return t;
389
392
  const o = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
390
393
  if (!o.test(e)) return t;
391
- const r = o.exec(e);
392
- if (r) {
393
- const m = r.at(1);
394
+ const a = o.exec(e);
395
+ if (a) {
396
+ const m = a.at(1);
394
397
  if (Vt.some((p) => m == null ? void 0 : m.includes(p))) return t;
395
398
  }
396
399
  return "styled('div',";
397
400
  }), ue = (e, t) => {
398
401
  try {
399
- const s = R(u(t, "saltygen/cache/config-cache.json"), "utf8");
402
+ const s = v(u(t, "saltygen/cache/config-cache.json"), "utf8");
400
403
  return s ? `globalThis.saltyConfig = ${s};
401
404
 
402
405
  ${e}` : `globalThis.saltyConfig = {};
@@ -407,23 +410,23 @@ ${e}`;
407
410
  }
408
411
  }, at = async (e, t, s) => {
409
412
  const n = G(t), o = u(s, "./temp");
410
- yt(o) || K(o);
411
- const a = rt(t);
412
- let r = R(t, "utf8");
413
- r = Ft(r), r = ue(r, e);
414
- const m = u(s, "js", n + ".js"), w = await gt(e), p = u(e, (w == null ? void 0 : w.configDir) || "", "salty.config.ts"), c = Ot(p), h = await kt(e);
413
+ ht(o) || K(o);
414
+ const r = rt(t);
415
+ let a = v(t, "utf8");
416
+ a = Ft(a), a = ue(a, e);
417
+ const m = u(s, "js", n + ".js"), w = await gt(e), p = u(e, (w == null ? void 0 : w.configDir) || "", "salty.config.ts"), c = Ot(p), y = await kt(e);
415
418
  await Nt.build({
416
419
  stdin: {
417
- contents: r,
418
- sourcefile: a.base,
419
- resolveDir: a.dir,
420
+ contents: a,
421
+ sourcefile: r.base,
422
+ resolveDir: r.dir,
420
423
  loader: "tsx"
421
424
  },
422
425
  minify: !1,
423
426
  treeShaking: !0,
424
427
  bundle: !0,
425
428
  outfile: m,
426
- format: h,
429
+ format: y,
427
430
  target: ["node20"],
428
431
  keepNames: !0,
429
432
  external: c,
@@ -433,22 +436,22 @@ ${e}`;
433
436
  name: "test",
434
437
  setup: (d) => {
435
438
  d.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (f) => {
436
- const g = R(f.path, "utf8");
439
+ const g = v(f.path, "utf8");
437
440
  return { contents: Ft(g), loader: "ts" };
438
441
  });
439
442
  }
440
443
  }
441
444
  ]
442
445
  });
443
- const y = Date.now();
444
- return { contents: await import(`${m}?t=${y}`), outputFilePath: m };
446
+ const h = Date.now();
447
+ return { contents: await import(`${m}?t=${h}`), outputFilePath: m };
445
448
  }, de = async (e) => {
446
- const t = await I(e), s = u(t, "cache/config-cache.json"), n = R(s, "utf8");
449
+ const t = await I(e), s = u(t, "cache/config-cache.json"), n = v(s, "utf8");
447
450
  if (!n) throw new Error("Could not find config cache file");
448
451
  return JSON.parse(n);
449
452
  }, wt = async (e) => {
450
- const t = await de(e), s = await I(e), n = u(s, "salty.config.js"), o = Date.now(), { config: a } = await import(`${n}?t=${o}`);
451
- return L(a, t);
453
+ const t = await de(e), s = await I(e), n = u(s, "salty.config.js"), o = Date.now(), { config: r } = await import(`${n}?t=${o}`);
454
+ return L(r, t);
452
455
  }, $t = () => {
453
456
  try {
454
457
  return process.env.NODE_ENV === "production";
@@ -459,42 +462,42 @@ ${e}`;
459
462
  try {
460
463
  const n = Date.now();
461
464
  t ? mt.info("Generating CSS in production mode! 🔥") : mt.info("Generating CSS in development mode! 🚀");
462
- const o = [], a = [], r = await I(e), m = u(r, "index.css");
465
+ const o = [], r = [], a = await I(e), m = u(a, "index.css");
463
466
  s && (() => {
464
- yt(r) && Wt("rm -rf " + r), K(r, { recursive: !0 }), K(u(r, "css")), K(u(r, "types")), K(u(r, "js")), K(u(r, "cache"));
467
+ ht(a) && zt("rm -rf " + a), K(a, { recursive: !0 }), K(u(a, "css")), K(u(a, "types")), K(u(a, "js")), K(u(a, "cache"));
465
468
  })();
466
469
  const p = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set();
467
- async function h(l) {
470
+ async function y(l) {
468
471
  const $ = ["node_modules", "saltygen"], C = At(l);
469
472
  if (C.isDirectory()) {
470
473
  const i = Ht(l);
471
474
  if ($.some((N) => l.includes(N))) return;
472
- await Promise.all(i.map((N) => h(u(l, N))));
475
+ await Promise.all(i.map((N) => y(u(l, N))));
473
476
  } else if (C.isFile() && Z(l)) {
474
477
  p.add(l);
475
- const j = R(l, "utf8");
478
+ const j = v(l, "utf8");
476
479
  /define[\w\d]+\(/.test(j) && c.add(l);
477
480
  }
478
481
  }
479
- await h(e), await fe(e, c);
480
- const y = {
482
+ await y(e), await fe(e, c);
483
+ const h = {
481
484
  keyframes: [],
482
485
  components: [],
483
486
  classNames: []
484
487
  };
485
488
  await Promise.all(
486
489
  [...p].map(async (l) => {
487
- const { contents: $ } = await at(e, l, r);
490
+ const { contents: $ } = await at(e, l, a);
488
491
  for (let [C, i] of Object.entries($))
489
- i instanceof Promise && (i = await i), i.isKeyframes ? y.keyframes.push({
492
+ i instanceof Promise && (i = await i), i.isKeyframes ? h.keyframes.push({
490
493
  value: i,
491
494
  src: l,
492
495
  name: C
493
- }) : i.isClassName ? y.classNames.push({
496
+ }) : i.isClassName ? h.classNames.push({
494
497
  ...i,
495
498
  src: l,
496
499
  name: C
497
- }) : i.generator && y.components.push({
500
+ }) : i.generator && h.components.push({
498
501
  ...i,
499
502
  src: l,
500
503
  name: C
@@ -502,12 +505,12 @@ ${e}`;
502
505
  })
503
506
  );
504
507
  const b = await wt(e);
505
- for (const l of y.keyframes) {
506
- const { value: $ } = l, C = `a_${$.animationName}.css`, i = `css/${C}`, j = u(r, i);
508
+ for (const l of h.keyframes) {
509
+ const { value: $ } = l, C = `a_${$.animationName}.css`, i = `css/${C}`, j = u(a, i);
507
510
  o.push(C), T(j, $.css);
508
511
  }
509
512
  const d = {};
510
- for (const l of y.components) {
513
+ for (const l of h.components) {
511
514
  const { src: $, name: C } = l;
512
515
  d[$] || (d[$] = []);
513
516
  const i = l.generator._withBuildContext({
@@ -515,14 +518,14 @@ ${e}`;
515
518
  isProduction: t,
516
519
  config: b
517
520
  });
518
- a[i.priority] || (a[i.priority] = []);
521
+ r[i.priority] || (r[i.priority] = []);
519
522
  const j = await i.css;
520
523
  if (!j) continue;
521
- a[i.priority].push(i.cssFileName);
522
- const N = `css/${i.cssFileName}`, M = u(r, N);
523
- T(M, j), b.importStrategy === "component" && d[$].push(i.cssFileName);
524
+ r[i.priority].push(i.cssFileName);
525
+ const N = `css/${i.cssFileName}`, R = u(a, N);
526
+ T(R, j), b.importStrategy === "component" && d[$].push(i.cssFileName);
524
527
  }
525
- for (const l of y.classNames) {
528
+ for (const l of h.classNames) {
526
529
  const { src: $, name: C } = l;
527
530
  d[$] || (d[$] = []);
528
531
  const i = l.generator._withBuildContext({
@@ -531,14 +534,14 @@ ${e}`;
531
534
  config: b
532
535
  }), j = await i.css;
533
536
  if (!j) continue;
534
- a[i.priority] || (a[i.priority] = []), a[i.priority].push(i.cssFileName);
535
- const N = `css/${i.cssFileName}`, M = u(r, N);
536
- T(M, j), b.importStrategy === "component" && d[$].push(i.cssFileName);
537
+ r[i.priority] || (r[i.priority] = []), r[i.priority].push(i.cssFileName);
538
+ const N = `css/${i.cssFileName}`, R = u(a, N);
539
+ T(R, j), b.importStrategy === "component" && d[$].push(i.cssFileName);
537
540
  }
538
541
  b.importStrategy === "component" && Object.entries(d).forEach(([l, $]) => {
539
542
  const C = $.map((A) => `@import url('./${A}');`).join(`
540
- `), i = G(l, 6), j = rt(l), N = J(j.name), M = u(r, `css/f_${N}-${i}.css`);
541
- T(M, C || "/* Empty file */");
543
+ `), i = G(l, 6), j = rt(l), N = J(j.name), R = u(a, `css/f_${N}-${i}.css`);
544
+ T(R, C || "/* Empty file */");
542
545
  });
543
546
  const f = o.map((l) => `@import url('./css/${l}');`).join(`
544
547
  `);
@@ -550,7 +553,7 @@ ${e}`;
550
553
 
551
554
  ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) => {
552
555
  try {
553
- return R(u(r, "css", l), "utf8").length > 0;
556
+ return v(u(a, "css", l), "utf8").length > 0;
554
557
  } catch {
555
558
  return !1;
556
559
  }
@@ -560,25 +563,25 @@ ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) =
560
563
  )}
561
564
  ${f}`;
562
565
  if (b.importStrategy !== "component") {
563
- const l = a.reduce(($, C, i) => {
566
+ const l = r.reduce(($, C, i) => {
564
567
  const j = C.reduce((B, U) => {
565
568
  var ct;
566
- const et = u(r, "css", U), it = R(et, "utf8"), q = ((ct = /.*-([^-]+)-\d+.css/.exec(U)) == null ? void 0 : ct.at(1)) || G(et, 6);
569
+ const et = u(a, "css", U), it = v(et, "utf8"), q = ((ct = /.*-([^-]+)-\d+.css/.exec(U)) == null ? void 0 : ct.at(1)) || G(et, 6);
567
570
  return B.includes(q) ? B : `${B}
568
571
  /*start:${q}-${U}*/
569
572
  ${it}
570
573
  /*end:${q}*/
571
574
  `;
572
- }, ""), N = `l_${i}.css`, M = u(r, "css", N), A = `@layer l${i} { ${j}
575
+ }, ""), N = `l_${i}.css`, R = u(a, "css", N), A = `@layer l${i} { ${j}
573
576
  }`;
574
- return T(M, A), `${$}
577
+ return T(R, A), `${$}
575
578
  @import url('./css/${N}');`;
576
579
  }, "");
577
580
  k += l;
578
581
  }
579
582
  T(m, k);
580
- const P = Date.now() - n, v = P < 200 ? "🔥" : P < 500 ? "🚀" : P < 1e3 ? "🎉" : P < 2e3 ? "🚗" : P < 5e3 ? "🤔" : "🥴";
581
- mt.info(`Generated CSS in ${P}ms! ${v}`);
583
+ const P = Date.now() - n, M = P < 200 ? "🔥" : P < 500 ? "🚀" : P < 1e3 ? "🎉" : P < 2e3 ? "🚗" : P < 5e3 ? "🤔" : "🥴";
584
+ mt.info(`Generated CSS in ${P}ms! ${M}`);
582
585
  } catch (n) {
583
586
  console.error(n);
584
587
  }
@@ -586,7 +589,7 @@ ${it}
586
589
  try {
587
590
  const n = await I(e);
588
591
  if (Z(t)) {
589
- const a = [], r = await wt(e), { contents: m } = await at(e, t, n);
592
+ const r = [], a = await wt(e), { contents: m } = await at(e, t, n);
590
593
  for (const [w, p] of Object.entries(m)) {
591
594
  if (p.isKeyframes && p.css) {
592
595
  const f = `css/${`a_${p.animationName}.css`}`, g = u(n, f);
@@ -597,10 +600,10 @@ ${it}
597
600
  const d = p.generator._withBuildContext({
598
601
  callerName: w,
599
602
  isProduction: s,
600
- config: r
603
+ config: a
601
604
  }), f = await d.css;
602
605
  if (!f) continue;
603
- a[d.priority] || (a[d.priority] = []), a[d.priority].push(d.cssFileName);
606
+ r[d.priority] || (r[d.priority] = []), r[d.priority].push(d.cssFileName);
604
607
  const g = `css/${d.cssFileName}`, F = u(n, g);
605
608
  T(F, f);
606
609
  continue;
@@ -609,84 +612,84 @@ ${it}
609
612
  const c = p.generator._withBuildContext({
610
613
  callerName: w,
611
614
  isProduction: s,
612
- config: r
613
- }), h = await c.css;
614
- if (!h) continue;
615
- const y = `css/${c.cssFileName}`, b = u(n, y);
616
- T(b, h), a[c.priority] || (a[c.priority] = []), a[c.priority].push(c.cssFileName);
615
+ config: a
616
+ }), y = await c.css;
617
+ if (!y) continue;
618
+ const h = `css/${c.cssFileName}`, b = u(n, h);
619
+ T(b, y), r[c.priority] || (r[c.priority] = []), r[c.priority].push(c.cssFileName);
617
620
  }
618
- if (r.importStrategy !== "component")
619
- a.forEach((w, p) => {
620
- const c = `l_${p}.css`, h = u(n, "css", c);
621
- let y = R(h, "utf8");
621
+ if (a.importStrategy !== "component")
622
+ r.forEach((w, p) => {
623
+ const c = `l_${p}.css`, y = u(n, "css", c);
624
+ let h = v(y, "utf8");
622
625
  w.forEach((b) => {
623
626
  var F;
624
627
  const d = u(n, "css", b), f = ((F = /.*-([^-]+)-\d+.css/.exec(b)) == null ? void 0 : F.at(1)) || G(d, 6);
625
- if (!y.includes(f)) {
626
- const x = R(d, "utf8"), V = `/*start:${f}-${b}*/
628
+ if (!h.includes(f)) {
629
+ const x = v(d, "utf8"), V = `/*start:${f}-${b}*/
627
630
  ${x}
628
631
  /*end:${f}*/
629
632
  `;
630
- y = `${y.replace(/\}$/, "")}
633
+ h = `${h.replace(/\}$/, "")}
631
634
  ${V}
632
635
  }`;
633
636
  }
634
- }), T(h, y);
637
+ }), T(y, h);
635
638
  });
636
639
  else {
637
- const w = a.flat().map((b) => `@import url('./${b}');`).join(`
638
- `), p = G(t, 6), c = rt(t), h = J(c.name), y = u(n, `css/f_${h}-${p}.css`);
639
- T(y, w || "/* Empty file */");
640
+ const w = r.flat().map((b) => `@import url('./${b}');`).join(`
641
+ `), p = G(t, 6), c = rt(t), y = J(c.name), h = u(n, `css/f_${y}-${p}.css`);
642
+ T(h, w || "/* Empty file */");
640
643
  }
641
644
  }
642
645
  } catch (n) {
643
646
  console.error(n);
644
647
  }
645
- }, ye = async (e, t, s = $t()) => {
648
+ }, he = async (e, t, s = $t()) => {
646
649
  var n, o;
647
650
  try {
648
- const a = await I(e);
651
+ const r = await I(e);
649
652
  if (Z(t)) {
650
- const m = R(t, "utf8"), w = await wt(e), { contents: p } = await at(e, t, a);
653
+ const m = v(t, "utf8"), w = await wt(e), { contents: p } = await at(e, t, r);
651
654
  let c = m;
652
- for (const [h, y] of Object.entries(p)) {
653
- if (y.isKeyframes || !y.generator) continue;
654
- const b = y.generator._withBuildContext({
655
- callerName: h,
655
+ for (const [y, h] of Object.entries(p)) {
656
+ if (h.isKeyframes || !h.generator) continue;
657
+ const b = h.generator._withBuildContext({
658
+ callerName: y,
656
659
  isProduction: s,
657
660
  config: w
658
- }), [d, f] = await ie(c, h), g = c.slice(d, f);
659
- if (y.isClassName) {
660
- const F = c, x = ` ${h} = className("${b.classNames}")`;
661
- c = c.replace(g, x), F === c && console.error("Minimize file failed to change content", { name: h });
661
+ }), [d, f] = await ie(c, y), g = c.slice(d, f);
662
+ if (h.isClassName) {
663
+ const F = c, x = ` ${y} = className("${b.classNames}")`;
664
+ c = c.replace(g, x), F === c && console.error("Minimize file failed to change content", { name: y });
662
665
  }
663
666
  if (g.includes("styled")) {
664
- const F = (o = (n = /styled\(([^,]+),/.exec(g)) == null ? void 0 : n.at(1)) == null ? void 0 : o.trim(), x = c, V = ` ${h} = styled(${F}, "${b.classNames}", ${JSON.stringify(b.clientProps)})`;
665
- c = c.replace(g, V), x === c && console.error("Minimize file failed to change content", { name: h, tagName: F });
667
+ const F = (o = (n = /styled\(([^,]+),/.exec(g)) == null ? void 0 : n.at(1)) == null ? void 0 : o.trim(), x = c, V = ` ${y} = styled(${F}, "${b.classNames}", ${JSON.stringify(b.clientProps)})`;
668
+ c = c.replace(g, V), x === c && console.error("Minimize file failed to change content", { name: y, tagName: F });
666
669
  }
667
670
  }
668
671
  if (w.importStrategy === "component") {
669
- const h = G(t, 6), y = rt(t);
670
- c = `import '../../saltygen/css/${`f_${J(y.name)}-${h}.css`}';
672
+ const y = G(t, 6), h = rt(t);
673
+ c = `import '../../saltygen/css/${`f_${J(h.name)}-${y}.css`}';
671
674
  ${c}`;
672
675
  }
673
676
  return c = c.replace("@salty-css/react/class-name", "@salty-css/react/class-name-client"), c = c.replace("{ styled }", "{ styledClient as styled }"), c = c.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), c;
674
677
  }
675
- } catch (a) {
676
- console.error("Error in minimizeFile:", a);
678
+ } catch (r) {
679
+ console.error("Error in minimizeFile:", r);
677
680
  }
678
681
  }, Pt = async (e) => {
679
682
  if (!e || e.includes("node_modules") || e.includes("saltygen")) return !1;
680
683
  if (e.includes("salty.config")) return !0;
681
684
  if (!Z(e)) return !1;
682
- const n = await ht(e, "utf-8");
685
+ const n = await yt(e, "utf-8");
683
686
  return !!(/.+define[A-Z]\w+/.test(n) || /.+keyframes\(.+/.test(n));
684
687
  }, je = (e) => ({
685
688
  name: "stylegen",
686
689
  buildStart: () => pe(e),
687
690
  load: async (t) => {
688
691
  if (Z(t))
689
- return await ye(e, t);
692
+ return await he(e, t);
690
693
  },
691
694
  handleHotUpdate: async ({ file: t, server: s }) => {
692
695
  await Pt(t) && s.restart();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/vite",
3
- "version": "0.0.1-alpha.250",
3
+ "version": "0.0.1-alpha.252",
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.250"
37
+ "@salty-css/core": "^0.0.1-alpha.252"
38
38
  }
39
39
  }