@salty-css/webpack 0.0.1-alpha.234 → 0.0.1-alpha.235

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.
@@ -0,0 +1,42 @@
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);const vt=require("esbuild"),Rt=require("child_process"),c=require("path"),f=require("fs"),bt=require("fs/promises"),U=require("winston"),lt=require("typescript");var ft=typeof document<"u"?document.currentScript:null;function zt(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 St=zt(vt),wt=t=>String.fromCharCode(t+(t>25?39:97)),Jt=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=wt(n%52)+s;return s=wt(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},Wt=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},W=(t,e=5)=>{const s=Wt(5381,JSON.stringify(t))>>>0;return Jt(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 At=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:g,css:h}=r(y);return h&&n.push(h),g})}),{transformed:s,additionalCss:n}},jt=t=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...o)=>`var(--${R(o[1].replaceAll(".","-"))})`)},qt=jt(),It=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Ht=(t,e,s)=>It.some(o=>typeof o=="string"?o===t:o.test(t))?`${e}px`:`${e}`,Lt=["Webkit","Moz","ms","O"],Gt=t=>t.startsWith("-")?t:Lt.some(e=>t.startsWith(e))?`-${R(t)}`:R(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,d])=>{const b=p.trim(),P=Gt(b),x=(M,k=";")=>`${P}:${M}${k}`,O={scope:e,config:s};if(typeof d=="function")return r([p,d(O)]);if(d instanceof Promise)return r([p,await d]);if(typeof d=="object"){if(!d)return;if(d.isColor)return x(d.toString());if(b==="defaultVariants")return;if(b==="variants"){const D=Object.entries(d);for(const[a,$]of D){if(!$)return;const C=Object.entries($);for(const[l,j]of C){if(!j)return;const N=`${e}.${a}-${l}`;(await nt(j,N,s)).forEach(J=>o.add(J))}}return}if(b==="compoundVariants"){for(const D of d){const{css:a,...$}=D,C=Object.entries($).reduce((j,[N,E])=>`${j}.${N}-${E}`,e);(await nt(a,C,s)).forEach(j=>o.add(j))}return}if(b.startsWith("@")){const D=b,a=await B(d,e,s),$=`${D} { ${a} }`;o.add($);return}const M=p.includes("&")?b.replace("&",e):b.startsWith(":")?`${e}${b}`:`${e} ${b}`;(await nt(d,M,s)).forEach(D=>o.add(D));return}if(typeof d=="number"){const M=Ht(P,d);return x(M)}if(typeof d!="string")if("toString"in d)d=d.toString();else throw new Error(`Invalid value type for property ${P}`);return x(d)},y=i.map(r),{modifiers:g}={},h=[jt(),At(g)],w=(await Promise.all(y).then(p=>Promise.all(p.map(d=>h.reduce(async(b,P)=>{const x=await b;if(!x)return x;const O=await P(x);if(!O)return x;const{transformed:M,additionalCss:k}=O;let D="";if(k)for(const a of k)D+=await B(a,"");return`${D}${M}`},Promise.resolve(d)))))).filter(p=>p!==void 0).join(`
2
+ `);if(!w.trim())return Array.from(o);const m=e?`${e} {
3
+ ${w}
4
+ }`:w;return o.has(m)?Array.from(o):[m,...o]},B=async(t,e,s,n=!1)=>(await nt(t,e,s,n)).join(`
5
+ `),Ft=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 Ft(i,[...e,r]);s.push(y)}else n[o]=i;if(Object.keys(n).length){const o=e.map(R).join("-"),i="t_"+W(o,4),r=await B(n,`.${o}, .${i}`);s.push(r)}return s.join(`
6
+ `)},Kt=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=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const i=e?`${e}.${n}`:n;return typeof o=="object"?Ct(o,i,s):s.add(e)}),[...s]):[],Pt=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=c.join(t,"package.json");return f.existsSync(e)?e:Pt(c.join(t,".."))},Qt=async t=>{const e=Pt(t);return await bt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},Ut=async t=>{const e=await Qt(t);if(e)return e.type};let I;const Nt=async t=>{if(I)return I;const e=await Ut(t);return e==="module"?I="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:ft&&ft.tagName.toUpperCase()==="SCRIPT"&&ft.src||new URL("index-B5IaIfZg.cjs",document.baseURI).href).endsWith(".cjs"))&&(I="cjs"),I||"esm"},ut=U.createLogger({level:"debug",format:U.format.combine(U.format.colorize(),U.format.cli()),transports:[new U.transports.Console({})]});function _t(t){return t?typeof t!="string"?_t(String(t)):t.replace(/[^\d\w]/g,"."):""}const Bt={"*, *::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"}},H=(...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}),{});class Xt{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 Yt{constructor(e){st(this,"_path");st(this,"templates",[]);this.params=e,Object.entries(e).forEach(([s,n])=>{this.templates.push(new Xt({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 te=t=>new Yt(t),ee=(t,e)=>new Promise((s,n)=>{const o=setTimeout(()=>{n(new Error("Timeout"))},100),i=lt.createSourceFile("temp.ts",t,lt.ScriptTarget.Latest,!0);function r(y){if(lt.isVariableDeclaration(y)&&y.name.getText()===e){const g=y.getStart(),h=y.getEnd();clearTimeout(o),s([g,h])}y.forEachChild(r)}r(i)}),z={externalModules:[],rcFile:void 0,destDir:void 0},xt=t=>{if(z.externalModules.length>0)return z.externalModules;const s=f.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},A=async t=>{if(z.destDir)return z.destDir;const e=await dt(t),s=c.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return z.destDir=s,s},Tt=["salty","css","styles","styled"],kt=(t=[])=>new RegExp(`\\.(${[...Tt,...t].join("|")})\\.`),ot=(t,e=[])=>kt(e).test(t),Dt=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 bt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(z.rcFile=s,s):Dt(c.join(t,".."))},dt=async t=>{var n,o;const e=await Dt(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))},se=async t=>{const e=await dt(t),s=await A(t),n=c.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),o=c.join(s,"salty.config.js"),i=await Nt(t),r=xt(n);await St.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:i,external:r});const y=Date.now(),{config:g}=await import(`${o}?t=${y}`);return{config:g,path:o}},ne=async(t,e)=>{var yt,ht;const s=await A(t),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...e].map(async F=>{const{contents:_,outputFilePath:Q}=await it(t,F,s);Object.entries(_).forEach(([v,T])=>{T.isMedia?n.mediaQueries.push([v,T]):T.isGlobalDefine?n.globalStyles.push(T):T.isDefineVariables?n.variables.push(T):T.isDefineTemplates&&n.templates.push(T._setPath(`${v};;${Q}`))})}));const{config:o,path:i}=await se(t),r={...o},y=new Set,g=async(F,_=[])=>{if(!F)return[];const Q=Object.entries(F).map(async([T,q])=>{const tt=async V=>{if(!V)return;if(V instanceof Promise)return await tt(await V);if(typeof V=="function")return await tt(await V());if(typeof V=="object")return await g(V,[..._,T]);const rt=_t(T),at=R(T),ct=[..._,rt].join(".");y.add(`"${ct}"`);const et=[..._.map(R),at].join("-"),gt=qt(V);return gt?`--${et}: ${gt.transformed};`:`--${et}: ${V};`};return await tt(q)});return(await Promise.all(Q)).flat()},h=async F=>{if(!F)return[];const _=Object.entries(F).map(async([v,T])=>{const q=await g(T);return v==="base"?q.join(""):`${v} { ${q.join("")} }`});return(await Promise.all(_)).flat()},u=async F=>{if(!F)return[];const _=Object.entries(F).map(async([v,T])=>{const q=Object.entries(T).map(async([V,rt])=>{const at=await g(rt,[v]),ct=`.${v}-${V}, [data-${v}="${V}"]`,et=at.join("");return`${ct} { ${et} }`});return(await Promise.all(q)).flat()});return(await Promise.all(_)).flat()},w=F=>({...F,responsive:void 0,conditional:void 0}),m=F=>n.variables.map(_=>F==="static"?w(_._current):_._current[F]),S=H(w(o.variables),m("static")),p=await g(S),d=H((yt=o.variables)==null?void 0:yt.responsive,m("responsive")),b=await h(d),P=H((ht=o.variables)==null?void 0:ht.conditional,m("conditional")),x=await u(P),O=c.join(s,"css/_variables.css"),M=`:root { ${p.join("")} ${b.join("")} } ${x.join("")}`;f.writeFileSync(O,M),r.staticVariables=S;const k=c.join(s,"css/_global.css"),D=H(o.global,n.globalStyles),a=await B(D,"");f.writeFileSync(k,`@layer global { ${a} }`);const $=c.join(s,"css/_reset.css"),l=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:Bt,j=await B(l,"");f.writeFileSync($,`@layer reset { ${j} }`);const N=c.join(s,"css/_templates.css"),E=H(o.templates,n.templates),J=await Ft(E),L=Kt(E);f.writeFileSync(N,`@layer templates { ${J} }`),r.templates=E;const G=o.templates?[te(o.templates)._setPath(`config;;${i}`)]:[],Z=Zt(n.templates,G);r.templatePaths=Object.fromEntries(Object.entries(Z).map(([F,_])=>[F,_._path]));const{mediaQueries:X}=n;r.mediaQueries=Object.fromEntries(X.map(([F,_])=>[`@${F}`,_]));const K=X.map(([F])=>`'@${F}'`).join(" | "),Y=c.join(s,"types/css-tokens.d.ts"),Et=`
7
+ // Variable types
8
+ type VariableTokens = ${[...y].join("|")};
9
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
10
+
11
+ // Template types
12
+ type TemplateTokens = {
13
+ ${Object.entries(L).map(([F,_])=>`${F}?: ${_}`).join(`
14
+ `)}
15
+ }
16
+
17
+ // Media query types
18
+ type MediaQueryKeys = ${K||"''"};
19
+ `;f.writeFileSync(Y,Et);const Ot=c.join(s,"cache/config-cache.json");f.writeFileSync(Ot,JSON.stringify(r,null,2))},$t=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(Tt.some(h=>y==null?void 0:y.includes(h)))return e}return"styled('div',"}),oe=(t,e)=>{try{const s=f.readFileSync(c.join(e,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
20
+
21
+ ${t}`:`globalThis.saltyConfig = {};
22
+
23
+ ${t}`}catch{return t}},it=async(t,e,s)=>{const n=W(e),o=c.join(s,"./temp");f.existsSync(o)||f.mkdirSync(o);const i=c.parse(e);let r=f.readFileSync(e,"utf8");r=$t(r),r=oe(r,t);const y=c.join(s,"js",n+".js"),g=await dt(t),h=c.join(t,(g==null?void 0:g.configDir)||"","salty.config.ts"),u=xt(h),w=await Nt(t);await St.build({stdin:{contents:r,sourcefile:i.base,resolveDir:i.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:w,target:["node20"],keepNames:!0,external:u,packages:"external",plugins:[{name:"test",setup:p=>{p.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},d=>{const b=f.readFileSync(d.path,"utf8");return{contents:$t(b),loader:"ts"}})}}]});const m=Date.now();return{contents:await import(`${y}?t=${m}`),outputFilePath:y}},ie=async t=>{const e=await A(t),s=c.join(e,"cache/config-cache.json"),n=f.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},pt=async t=>{const e=await ie(t),s=await A(t),n=c.join(s,"salty.config.js"),o=Date.now(),{config:i}=await import(`${n}?t=${o}`);return H(i,e)},mt=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},re=async(t,e=mt(),s=!0)=>{try{const n=Date.now();e?ut.info("Generating CSS in production mode! 🔥"):ut.info("Generating CSS in development mode! 🚀");const o=[],i=[],r=await A(t),y=c.join(r,"index.css");s&&(()=>{f.existsSync(r)&&Rt.execSync("rm -rf "+r),f.mkdirSync(r,{recursive:!0}),f.mkdirSync(c.join(r,"css")),f.mkdirSync(c.join(r,"types")),f.mkdirSync(c.join(r,"js")),f.mkdirSync(c.join(r,"cache"))})();const h=new Set,u=new Set;async function w(a){const $=["node_modules","saltygen"],C=f.statSync(a);if(C.isDirectory()){const l=f.readdirSync(a);if($.some(N=>a.includes(N)))return;await Promise.all(l.map(N=>w(c.join(a,N))))}else if(C.isFile()&&ot(a)){h.add(a);const j=f.readFileSync(a,"utf8");/define[\w\d]+\(/.test(j)&&u.add(a)}}await w(t),await ne(t,u);const m={keyframes:[],components:[],classNames:[]};await Promise.all([...h].map(async a=>{const{contents:$}=await it(t,a,r);for(let[C,l]of Object.entries($))l instanceof Promise&&(l=await l),l.isKeyframes?m.keyframes.push({value:l,src:a,name:C}):l.isClassName?m.classNames.push({...l,src:a,name:C}):l.generator&&m.components.push({...l,src:a,name:C})}));const S=await pt(t);for(const a of m.keyframes){const{value:$}=a,C=`a_${$.animationName}.css`,l=`css/${C}`,j=c.join(r,l);o.push(C),f.writeFileSync(j,$.css)}const p={};for(const a of m.components){const{src:$,name:C}=a;p[$]||(p[$]=[]);const l=a.generator._withBuildContext({callerName:C,isProduction:e,config:S});i[l.priority]||(i[l.priority]=[]);const j=await l.css;if(!j)continue;i[l.priority].push(l.cssFileName);const N=`css/${l.cssFileName}`,E=c.join(r,N);f.writeFileSync(E,j),S.importStrategy==="component"&&p[$].push(l.cssFileName)}for(const a of m.classNames){const{src:$,name:C}=a;p[$]||(p[$]=[]);const l=a.generator._withBuildContext({callerName:C,isProduction:e,config:S}),j=await l.css;if(!j)continue;i[l.priority]||(i[l.priority]=[]),i[l.priority].push(l.cssFileName);const N=`css/${l.cssFileName}`,E=c.join(r,N);f.writeFileSync(E,j),S.importStrategy==="component"&&p[$].push(l.cssFileName)}S.importStrategy==="component"&&Object.entries(p).forEach(([a,$])=>{const C=$.map(J=>`@import url('./${J}');`).join(`
24
+ `),l=W(a,6),j=c.parse(a),N=R(j.name),E=c.join(r,`css/f_${N}-${l}.css`);f.writeFileSync(E,C||"/* Empty file */")});const d=o.map(a=>`@import url('./css/${a}');`).join(`
25
+ `);let O=`@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
26
+
27
+ ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(a=>{try{return f.readFileSync(c.join(r,"css",a),"utf8").length>0}catch{return!1}}).map(a=>`@import url('./css/${a}');`).join(`
28
+ `)}
29
+ ${d}`;if(S.importStrategy!=="component"){const a=i.reduce(($,C,l)=>{const j=C.reduce((L,G)=>{var Y;const Z=c.join(r,"css",G),X=f.readFileSync(Z,"utf8"),K=((Y=/.*-([^-]+)-\d+.css/.exec(G))==null?void 0:Y.at(1))||W(Z,6);return L.includes(K)?L:`${L}
30
+ /*start:${K}-${G}*/
31
+ ${X}
32
+ /*end:${K}*/
33
+ `},""),N=`l_${l}.css`,E=c.join(r,"css",N),J=`@layer l${l} { ${j}
34
+ }`;return f.writeFileSync(E,J),`${$}
35
+ @import url('./css/${N}');`},"");O+=a}f.writeFileSync(y,O);const k=Date.now()-n,D=k<200?"🔥":k<500?"🚀":k<1e3?"🎉":k<2e3?"🚗":k<5e3?"🤔":"🥴";ut.info(`Generated CSS in ${k}ms! ${D}`)}catch(n){console.error(n)}},ae=async(t,e,s=mt())=>{try{const n=await A(t);if(ot(e)){const i=[],r=await pt(t),{contents:y}=await it(t,e,n);for(const[g,h]of Object.entries(y)){if(h.isKeyframes&&h.css){const d=`css/${`a_${h.animationName}.css`}`,b=c.join(n,d);f.writeFileSync(b,await h.css);return}if(h.isClassName){const p=h.generator._withBuildContext({callerName:g,isProduction:s,config:r}),d=await p.css;if(!d)continue;i[p.priority]||(i[p.priority]=[]),i[p.priority].push(p.cssFileName);const b=`css/${p.cssFileName}`,P=c.join(n,b);f.writeFileSync(P,d)}if(!h.generator)return;const u=h.generator._withBuildContext({callerName:g,isProduction:s,config:r}),w=await u.css;if(!w)continue;const m=`css/${u.cssFileName}`,S=c.join(n,m);f.writeFileSync(S,w),i[u.priority]||(i[u.priority]=[]),i[u.priority].push(u.cssFileName)}if(r.importStrategy!=="component")i.forEach((g,h)=>{const u=`l_${h}.css`,w=c.join(n,"css",u);let m=f.readFileSync(w,"utf8");g.forEach(S=>{var P;const p=c.join(n,"css",S),d=((P=/.*-([^-]+)-\d+.css/.exec(S))==null?void 0:P.at(1))||W(p,6);if(!m.includes(d)){const x=f.readFileSync(p,"utf8"),O=`/*start:${d}-${S}*/
36
+ ${x}
37
+ /*end:${d}*/
38
+ `;m=`${m.replace(/\}$/,"")}
39
+ ${O}
40
+ }`}}),f.writeFileSync(w,m)});else{const g=i.flat().map(S=>`@import url('./${S}');`).join(`
41
+ `),h=W(e,6),u=c.parse(e),w=R(u.name),m=c.join(n,`css/f_${w}-${h}.css`);f.writeFileSync(m,g||"/* Empty file */")}}}catch(n){console.error(n)}},ce=async(t,e,s=mt())=>{var n,o;try{const i=await A(t);if(ot(e)){const y=f.readFileSync(e,"utf8"),g=await pt(t),{contents:h}=await it(t,e,i);let u=y;for(const[w,m]of Object.entries(h)){if(m.isKeyframes||!m.generator)continue;const S=m.generator._withBuildContext({callerName:w,isProduction:s,config:g}),[p,d]=await ee(u,w),b=u.slice(p,d);if(m.isClassName){const P=u,x=` ${w} = className("${S.classNames}")`;u=u.replace(b,x),P===u&&console.error("Minimize file failed to change content",{name:w})}if(b.includes("styled")){const P=(o=(n=/styled\(([^,]+),/.exec(b))==null?void 0:n.at(1))==null?void 0:o.trim(),x=u,O=` ${w} = styled(${P}, "${S.classNames}", ${JSON.stringify(S.clientProps)})`;u=u.replace(b,O),x===u&&console.error("Minimize file failed to change content",{name:w,tagName:P})}}if(g.importStrategy==="component"){const w=W(e,6),m=c.parse(e);u=`import '../../saltygen/css/${`f_${R(m.name)}-${w}.css`}';
42
+ ${u}`}return u=u.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),u=u.replace("{ styled }","{ styledClient as styled }"),u=u.replace("@salty-css/react/styled","@salty-css/react/styled-client"),u}}catch(i){console.error("Error in minimizeFile:",i)}};exports.generateCss=re;exports.generateFile=ae;exports.isSaltyFile=ot;exports.minimizeFile=ce;exports.saltyFileRegExp=kt;
@@ -1,29 +1,29 @@
1
1
  var vt = Object.defineProperty;
2
- var At = (e, t, s) => t in e ? vt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
3
- var nt = (e, t, s) => At(e, typeof t != "symbol" ? t + "" : t, s);
2
+ var Jt = (e, t, s) => t in e ? vt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
3
+ var nt = (e, t, s) => Jt(e, typeof t != "symbol" ? t + "" : t, s);
4
4
  import * as jt from "esbuild";
5
- import { execSync as Jt } from "child_process";
5
+ import { execSync as Rt } from "child_process";
6
6
  import { join as u, parse as rt } from "path";
7
- import { existsSync as mt, writeFileSync as x, readFileSync as M, mkdirSync as G, statSync as Rt, readdirSync as zt } from "fs";
7
+ import { existsSync as mt, writeFileSync as x, readFileSync as M, mkdirSync as K, statSync as zt, readdirSync as Wt } from "fs";
8
8
  import { readFile as Pt } from "fs/promises";
9
- import { createLogger as Wt, format as ft, transports as Zt } from "winston";
9
+ import { createLogger as At, format as ft, transports as Ht } from "winston";
10
10
  import ut from "typescript";
11
- const Ct = (e) => String.fromCharCode(e + (e > 25 ? 39 : 97)), Ht = (e, t) => {
11
+ const Ct = (e) => String.fromCharCode(e + (e > 25 ? 39 : 97)), It = (e, t) => {
12
12
  let s = "", n;
13
13
  for (n = Math.abs(e); n > 52; n = n / 52 | 0) s = Ct(n % 52) + s;
14
14
  return s = Ct(n % 52) + s, s.length < t ? s = s.padStart(t, "a") : s.length > t && (s = s.slice(-t)), s;
15
- }, It = (e, t) => {
15
+ }, Gt = (e, t) => {
16
16
  let s = t.length;
17
17
  for (; s; ) e = e * 33 ^ t.charCodeAt(--s);
18
18
  return e;
19
- }, W = (e, t = 5) => {
20
- const s = It(5381, JSON.stringify(e)) >>> 0;
21
- return Ht(s, t);
19
+ }, A = (e, t = 5) => {
20
+ const s = Gt(5381, JSON.stringify(e)) >>> 0;
21
+ return It(s, t);
22
22
  };
23
- function J(e) {
24
- return e ? typeof e != "string" ? J(String(e)) : e.replace(/[\s.]/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (t, s) => (s > 0 ? "-" : "") + t.toLowerCase()) : "";
23
+ function R(e) {
24
+ return e ? typeof e != "string" ? R(String(e)) : e.replace(/[\s.]/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (t, s) => (s > 0 ? "-" : "") + t.toLowerCase()) : "";
25
25
  }
26
- const Gt = (e) => (t) => {
26
+ const Kt = (e) => (t) => {
27
27
  if (typeof t != "string" || !e) return;
28
28
  let s = t;
29
29
  const n = [];
@@ -34,7 +34,7 @@ const Gt = (e) => (t) => {
34
34
  return h && n.push(h), y;
35
35
  });
36
36
  }), { transformed: s, additionalCss: n };
37
- }, Ft = (e) => (t) => typeof t != "string" || !/\{[^{}]+\}/g.test(t) ? void 0 : { transformed: t.replace(/\{([^{}]+)\}/g, (...o) => `var(--${J(o[1].replaceAll(".", "-"))})`) }, Kt = Ft(), Lt = [
37
+ }, Ft = (e) => (t) => typeof t != "string" || !/\{[^{}]+\}/g.test(t) ? void 0 : { transformed: t.replace(/\{([^{}]+)\}/g, (...o) => `var(--${R(o[1].replaceAll(".", "-"))})`) }, Lt = Ft(), Qt = [
38
38
  "top",
39
39
  "right",
40
40
  "bottom",
@@ -55,7 +55,7 @@ const Gt = (e) => (t) => {
55
55
  /.*size.*/,
56
56
  /.*thickness.*/,
57
57
  /.*font-size.*/
58
- ], Qt = (e, t, s) => Lt.some((o) => typeof o == "string" ? o === e : o.test(e)) ? `${t}px` : `${t}`, Bt = ["Webkit", "Moz", "ms", "O"], qt = (e) => e.startsWith("-") ? e : Bt.some((t) => e.startsWith(t)) ? `-${J(e)}` : J(e), ot = async (e, t = "", s, n = !1) => {
58
+ ], Bt = (e, t, s) => Qt.some((o) => typeof o == "string" ? o === e : o.test(e)) ? `${t}px` : `${t}`, Zt = ["Webkit", "Moz", "ms", "O"], qt = (e) => e.startsWith("-") ? e : Zt.some((t) => e.startsWith(t)) ? `-${R(e)}` : R(e), ot = async (e, t = "", s, n = !1) => {
59
59
  if (!e) throw new Error("No styles provided to parseStyles function!");
60
60
  const o = /* @__PURE__ */ new Set(), r = Object.entries(e), a = async ([p, f]) => {
61
61
  const w = p.trim(), P = qt(w), _ = (v, D = ";") => `${P}:${v}${D}`, O = { scope: t, config: s };
@@ -73,7 +73,7 @@ const Gt = (e) => (t) => {
73
73
  for (const [c, C] of j) {
74
74
  if (!C) return;
75
75
  const F = `${t}.${i}-${c}`;
76
- (await ot(C, F, s)).forEach((z) => o.add(z));
76
+ (await ot(C, F, s)).forEach((W) => o.add(W));
77
77
  }
78
78
  }
79
79
  return;
@@ -95,14 +95,14 @@ const Gt = (e) => (t) => {
95
95
  return;
96
96
  }
97
97
  if (typeof f == "number") {
98
- const v = Qt(P, f);
98
+ const v = Bt(P, f);
99
99
  return _(v);
100
100
  }
101
101
  if (typeof f != "string")
102
102
  if ("toString" in f) f = f.toString();
103
103
  else throw new Error(`Invalid value type for property ${P}`);
104
104
  return _(f);
105
- }, d = r.map(a), { modifiers: y } = {}, h = [Ft(), Gt(y)], g = (await Promise.all(d).then((p) => Promise.all(
105
+ }, d = r.map(a), { modifiers: y } = {}, h = [Ft(), Kt(y)], g = (await Promise.all(d).then((p) => Promise.all(
106
106
  p.map((f) => h.reduce(async (w, P) => {
107
107
  const _ = await w;
108
108
  if (!_) return _;
@@ -133,7 +133,7 @@ const Gt = (e) => (t) => {
133
133
  } else
134
134
  n[o] = r;
135
135
  if (Object.keys(n).length) {
136
- const o = t.map(J).join("-"), r = "t_" + W(o, 4), a = await U(n, `.${o}, .${r}`);
136
+ const o = t.map(R).join("-"), r = "t_" + A(o, 4), a = await U(n, `.${o}, .${r}`);
137
137
  s.push(a);
138
138
  }
139
139
  return s.join(`
@@ -154,18 +154,18 @@ const Gt = (e) => (t) => {
154
154
  if (t)
155
155
  return t.type;
156
156
  };
157
- let I;
157
+ let G;
158
158
  const Tt = async (e) => {
159
- if (I) return I;
159
+ if (G) return G;
160
160
  const t = await Yt(e);
161
- return t === "module" ? I = "esm" : (t === "commonjs" || import.meta.url.endsWith(".cjs")) && (I = "cjs"), I || "esm";
162
- }, pt = Wt({
161
+ return t === "module" ? G = "esm" : (t === "commonjs" || import.meta.url.endsWith(".cjs")) && (G = "cjs"), G || "esm";
162
+ }, pt = At({
163
163
  level: "debug",
164
164
  format: ft.combine(ft.colorize(), ft.cli()),
165
- transports: [new Zt.Console({})]
165
+ transports: [new Ht.Console({})]
166
166
  });
167
167
  function Dt(e) {
168
- return e ? typeof e != "string" ? Dt(String(e)) : e.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (t, s) => (s > 0 ? "." : "") + t.toLowerCase()) : "";
168
+ return e ? typeof e != "string" ? Dt(String(e)) : e.replace(/[^\d\w]/g, ".") : "";
169
169
  }
170
170
  const te = {
171
171
  /** Set box model to border-box */
@@ -213,7 +213,7 @@ const te = {
213
213
  fontSize: "100%",
214
214
  lineHeight: "1.15em"
215
215
  }
216
- }, K = (...e) => e.flat().reduce((t, s) => s != null && s._current ? { ...t, ...s._current } : { ...t, ...s }, {}), ee = (...e) => e.flat().reduce((t, s) => ({ ...t, ...s._children }), {});
216
+ }, L = (...e) => e.flat().reduce((t, s) => s != null && s._current ? { ...t, ...s._current } : { ...t, ...s }, {}), ee = (...e) => e.flat().reduce((t, s) => ({ ...t, ...s._children }), {});
217
217
  class se {
218
218
  constructor(t) {
219
219
  nt(this, "_path");
@@ -269,32 +269,32 @@ const oe = (e) => new ne(e), re = (e, t) => new Promise((s, n) => {
269
269
  d.forEachChild(a);
270
270
  }
271
271
  a(r);
272
- }), R = {
272
+ }), z = {
273
273
  externalModules: [],
274
274
  rcFile: void 0,
275
275
  destDir: void 0
276
276
  }, kt = (e) => {
277
- if (R.externalModules.length > 0) return R.externalModules;
277
+ if (z.externalModules.length > 0) return z.externalModules;
278
278
  const s = M(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
279
279
  if (!s) return [];
280
280
  const n = s[1].split(",").map((o) => o.replace(/['"`]/g, "").trim());
281
- return R.externalModules = n, n;
282
- }, Z = async (e) => {
283
- if (R.destDir) return R.destDir;
281
+ return z.externalModules = n, n;
282
+ }, H = async (e) => {
283
+ if (z.destDir) return z.destDir;
284
284
  const t = await ht(e), s = u(e, (t == null ? void 0 : t.saltygenDir) || "saltygen");
285
- return R.destDir = s, s;
285
+ return z.destDir = s, s;
286
286
  }, Et = ["salty", "css", "styles", "styled"], ae = (e = []) => new RegExp(`\\.(${[...Et, ...e].join("|")})\\.`), dt = (e, t = []) => ae(t).test(e), Ot = async (e) => {
287
- if (R.rcFile) return R.rcFile;
287
+ if (z.rcFile) return z.rcFile;
288
288
  if (e === "/") throw new Error("Could not find .saltyrc.json file");
289
289
  const t = u(e, ".saltyrc.json"), s = await Pt(t, "utf-8").then(JSON.parse).catch(() => {
290
290
  });
291
- return s ? (R.rcFile = s, s) : Ot(u(e, ".."));
291
+ return s ? (z.rcFile = s, s) : Ot(u(e, ".."));
292
292
  }, ht = async (e) => {
293
293
  var n, o;
294
294
  const t = await Ot(e), s = (n = t.projects) == null ? void 0 : n.find((r) => e.endsWith(r.dir || ""));
295
295
  return s || ((o = t.projects) == null ? void 0 : o.find((r) => r.dir === t.defaultProject));
296
296
  }, ie = async (e) => {
297
- const t = await ht(e), s = await Z(e), n = u(e, (t == null ? void 0 : t.configDir) || "", "salty.config.ts"), o = u(s, "salty.config.js"), r = await Tt(e), a = kt(n);
297
+ const t = await ht(e), s = await H(e), n = u(e, (t == null ? void 0 : t.configDir) || "", "salty.config.ts"), o = u(s, "salty.config.js"), r = await Tt(e), a = kt(n);
298
298
  await jt.build({
299
299
  entryPoints: [n],
300
300
  minify: !0,
@@ -308,7 +308,7 @@ const oe = (e) => new ne(e), re = (e, t) => new Promise((s, n) => {
308
308
  return { config: y, path: o };
309
309
  }, ce = async (e, t) => {
310
310
  var $t, wt;
311
- const s = await Z(e), n = {
311
+ const s = await H(e), n = {
312
312
  mediaQueries: [],
313
313
  globalStyles: [],
314
314
  variables: [],
@@ -317,69 +317,69 @@ const oe = (e) => new ne(e), re = (e, t) => new Promise((s, n) => {
317
317
  await Promise.all(
318
318
  [...t].map(async (S) => {
319
319
  const { contents: N, outputFilePath: q } = await at(e, S, s);
320
- Object.entries(N).forEach(([A, T]) => {
321
- T.isMedia ? n.mediaQueries.push([A, T]) : T.isGlobalDefine ? n.globalStyles.push(T) : T.isDefineVariables ? n.variables.push(T) : T.isDefineTemplates && n.templates.push(T._setPath(`${A};;${q}`));
320
+ Object.entries(N).forEach(([J, T]) => {
321
+ T.isMedia ? n.mediaQueries.push([J, T]) : T.isGlobalDefine ? n.globalStyles.push(T) : T.isDefineVariables ? n.variables.push(T) : T.isDefineTemplates && n.templates.push(T._setPath(`${J};;${q}`));
322
322
  });
323
323
  })
324
324
  );
325
325
  const { config: o, path: r } = await ie(e), a = { ...o }, d = /* @__PURE__ */ new Set(), y = async (S, N = []) => {
326
326
  if (!S) return [];
327
- const q = Object.entries(S).map(async ([T, H]) => {
327
+ const q = Object.entries(S).map(async ([T, I]) => {
328
328
  const et = async (V) => {
329
329
  if (!V) return;
330
330
  if (V instanceof Promise) return await et(await V);
331
331
  if (typeof V == "function") return await et(await V());
332
332
  if (typeof V == "object") return await y(V, [...N, T]);
333
- const it = Dt(T), ct = J(T), lt = [...N, it].join(".");
333
+ const it = Dt(T), ct = R(T), lt = [...N, it].join(".");
334
334
  d.add(`"${lt}"`);
335
- const st = [...N.map(J), ct].join("-"), bt = Kt(V);
335
+ const st = [...N.map(R), ct].join("-"), bt = Lt(V);
336
336
  return bt ? `--${st}: ${bt.transformed};` : `--${st}: ${V};`;
337
337
  };
338
- return await et(H);
338
+ return await et(I);
339
339
  });
340
340
  return (await Promise.all(q)).flat();
341
341
  }, h = async (S) => {
342
342
  if (!S) return [];
343
- const N = Object.entries(S).map(async ([A, T]) => {
344
- const H = await y(T);
345
- return A === "base" ? H.join("") : `${A} { ${H.join("")} }`;
343
+ const N = Object.entries(S).map(async ([J, T]) => {
344
+ const I = await y(T);
345
+ return J === "base" ? I.join("") : `${J} { ${I.join("")} }`;
346
346
  });
347
347
  return (await Promise.all(N)).flat();
348
348
  }, l = async (S) => {
349
349
  if (!S) return [];
350
- const N = Object.entries(S).map(async ([A, T]) => {
351
- const H = Object.entries(T).map(async ([V, it]) => {
352
- const ct = await y(it, [A]), lt = `.${A}-${V}, [data-${A}="${V}"]`, st = ct.join("");
350
+ const N = Object.entries(S).map(async ([J, T]) => {
351
+ const I = Object.entries(T).map(async ([V, it]) => {
352
+ const ct = await y(it, [J]), lt = `.${J}-${V}, [data-${J}="${V}"]`, st = ct.join("");
353
353
  return `${lt} { ${st} }`;
354
354
  });
355
- return (await Promise.all(H)).flat();
355
+ return (await Promise.all(I)).flat();
356
356
  });
357
357
  return (await Promise.all(N)).flat();
358
- }, g = (S) => ({ ...S, responsive: void 0, conditional: void 0 }), m = (S) => n.variables.map((N) => S === "static" ? g(N._current) : N._current[S]), b = K(g(o.variables), m("static")), p = await y(b), f = K(($t = o.variables) == null ? void 0 : $t.responsive, m("responsive")), w = await h(f), P = K((wt = o.variables) == null ? void 0 : wt.conditional, m("conditional")), _ = await l(P), O = u(s, "css/_variables.css"), v = `:root { ${p.join("")} ${w.join("")} } ${_.join("")}`;
358
+ }, g = (S) => ({ ...S, responsive: void 0, conditional: void 0 }), m = (S) => n.variables.map((N) => S === "static" ? g(N._current) : N._current[S]), b = L(g(o.variables), m("static")), p = await y(b), f = L(($t = o.variables) == null ? void 0 : $t.responsive, m("responsive")), w = await h(f), P = L((wt = o.variables) == null ? void 0 : wt.conditional, m("conditional")), _ = await l(P), O = u(s, "css/_variables.css"), v = `:root { ${p.join("")} ${w.join("")} } ${_.join("")}`;
359
359
  x(O, v), a.staticVariables = b;
360
- const D = u(s, "css/_global.css"), k = K(o.global, n.globalStyles), i = await U(k, "");
360
+ const D = u(s, "css/_global.css"), k = L(o.global, n.globalStyles), i = await U(k, "");
361
361
  x(D, `@layer global { ${i} }`);
362
362
  const $ = u(s, "css/_reset.css"), c = o.reset === "none" ? {} : typeof o.reset == "object" ? o.reset : te, C = await U(c, "");
363
363
  x($, `@layer reset { ${C} }`);
364
- const F = u(s, "css/_templates.css"), E = K(o.templates, n.templates), z = await Nt(E), L = Ut(E);
365
- x(F, `@layer templates { ${z} }`), a.templates = E;
366
- const Q = o.templates ? [oe(o.templates)._setPath(`config;;${r}`)] : [], X = ee(n.templates, Q);
364
+ const F = u(s, "css/_templates.css"), E = L(o.templates, n.templates), W = await Nt(E), Q = Ut(E);
365
+ x(F, `@layer templates { ${W} }`), a.templates = E;
366
+ const B = o.templates ? [oe(o.templates)._setPath(`config;;${r}`)] : [], X = ee(n.templates, B);
367
367
  a.templatePaths = Object.fromEntries(Object.entries(X).map(([S, N]) => [S, N._path]));
368
368
  const { mediaQueries: Y } = n;
369
369
  a.mediaQueries = Object.fromEntries(Y.map(([S, N]) => [`@${S}`, N]));
370
- const B = Y.map(([S]) => `'@${S}'`).join(" | "), tt = u(s, "types/css-tokens.d.ts"), Vt = `
370
+ const Z = Y.map(([S]) => `'@${S}'`).join(" | "), tt = u(s, "types/css-tokens.d.ts"), Vt = `
371
371
  // Variable types
372
372
  type VariableTokens = ${[...d].join("|")};
373
373
  type PropertyValueToken = \`{\${VariableTokens}}\`;
374
374
 
375
375
  // Template types
376
376
  type TemplateTokens = {
377
- ${Object.entries(L).map(([S, N]) => `${S}?: ${N}`).join(`
377
+ ${Object.entries(Q).map(([S, N]) => `${S}?: ${N}`).join(`
378
378
  `)}
379
379
  }
380
380
 
381
381
  // Media query types
382
- type MediaQueryKeys = ${B || "''"};
382
+ type MediaQueryKeys = ${Z || "''"};
383
383
  `;
384
384
  x(tt, Vt);
385
385
  const Mt = u(s, "cache/config-cache.json");
@@ -406,8 +406,8 @@ ${e}`;
406
406
  return e;
407
407
  }
408
408
  }, at = async (e, t, s) => {
409
- const n = W(t), o = u(s, "./temp");
410
- mt(o) || G(o);
409
+ const n = A(t), o = u(s, "./temp");
410
+ mt(o) || K(o);
411
411
  const r = rt(t);
412
412
  let a = M(t, "utf8");
413
413
  a = St(a), a = le(a, e);
@@ -443,12 +443,12 @@ ${e}`;
443
443
  const m = Date.now();
444
444
  return { contents: await import(`${d}?t=${m}`), outputFilePath: d };
445
445
  }, fe = async (e) => {
446
- const t = await Z(e), s = u(t, "cache/config-cache.json"), n = M(s, "utf8");
446
+ const t = await H(e), s = u(t, "cache/config-cache.json"), n = M(s, "utf8");
447
447
  if (!n) throw new Error("Could not find config cache file");
448
448
  return JSON.parse(n);
449
449
  }, yt = async (e) => {
450
- const t = await fe(e), s = await Z(e), n = u(s, "salty.config.js"), o = Date.now(), { config: r } = await import(`${n}?t=${o}`);
451
- return K(r, t);
450
+ const t = await fe(e), s = await H(e), n = u(s, "salty.config.js"), o = Date.now(), { config: r } = await import(`${n}?t=${o}`);
451
+ return L(r, t);
452
452
  }, gt = () => {
453
453
  try {
454
454
  return process.env.NODE_ENV === "production";
@@ -459,15 +459,15 @@ ${e}`;
459
459
  try {
460
460
  const n = Date.now();
461
461
  t ? pt.info("Generating CSS in production mode! 🔥") : pt.info("Generating CSS in development mode! 🚀");
462
- const o = [], r = [], a = await Z(e), d = u(a, "index.css");
462
+ const o = [], r = [], a = await H(e), d = u(a, "index.css");
463
463
  s && (() => {
464
- mt(a) && Jt("rm -rf " + a), G(a, { recursive: !0 }), G(u(a, "css")), G(u(a, "types")), G(u(a, "js")), G(u(a, "cache"));
464
+ mt(a) && Rt("rm -rf " + a), K(a, { recursive: !0 }), K(u(a, "css")), K(u(a, "types")), K(u(a, "js")), K(u(a, "cache"));
465
465
  })();
466
466
  const h = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Set();
467
467
  async function g(i) {
468
- const $ = ["node_modules", "saltygen"], j = Rt(i);
468
+ const $ = ["node_modules", "saltygen"], j = zt(i);
469
469
  if (j.isDirectory()) {
470
- const c = zt(i);
470
+ const c = Wt(i);
471
471
  if ($.some((F) => i.includes(F))) return;
472
472
  await Promise.all(c.map((F) => g(u(i, F))));
473
473
  } else if (j.isFile() && dt(i)) {
@@ -536,8 +536,8 @@ ${e}`;
536
536
  x(E, C), b.importStrategy === "component" && p[$].push(c.cssFileName);
537
537
  }
538
538
  b.importStrategy === "component" && Object.entries(p).forEach(([i, $]) => {
539
- const j = $.map((z) => `@import url('./${z}');`).join(`
540
- `), c = W(i, 6), C = rt(i), F = J(C.name), E = u(a, `css/f_${F}-${c}.css`);
539
+ const j = $.map((W) => `@import url('./${W}');`).join(`
540
+ `), c = A(i, 6), C = rt(i), F = R(C.name), E = u(a, `css/f_${F}-${c}.css`);
541
541
  x(E, j || "/* Empty file */");
542
542
  });
543
543
  const f = o.map((i) => `@import url('./css/${i}');`).join(`
@@ -555,17 +555,17 @@ ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((i) =
555
555
  ${f}`;
556
556
  if (b.importStrategy !== "component") {
557
557
  const i = r.reduce(($, j, c) => {
558
- const C = j.reduce((L, Q) => {
558
+ const C = j.reduce((Q, B) => {
559
559
  var tt;
560
- const X = u(a, "css", Q), Y = M(X, "utf8"), B = ((tt = /.*-([^-]+)-\d+.css/.exec(Q)) == null ? void 0 : tt.at(1)) || W(X, 6);
561
- return L.includes(B) ? L : `${L}
562
- /*start:${B}-${Q}*/
560
+ const X = u(a, "css", B), Y = M(X, "utf8"), Z = ((tt = /.*-([^-]+)-\d+.css/.exec(B)) == null ? void 0 : tt.at(1)) || A(X, 6);
561
+ return Q.includes(Z) ? Q : `${Q}
562
+ /*start:${Z}-${B}*/
563
563
  ${Y}
564
- /*end:${B}*/
564
+ /*end:${Z}*/
565
565
  `;
566
- }, ""), F = `l_${c}.css`, E = u(a, "css", F), z = `@layer l${c} { ${C}
566
+ }, ""), F = `l_${c}.css`, E = u(a, "css", F), W = `@layer l${c} { ${C}
567
567
  }`;
568
- return x(E, z), `${$}
568
+ return x(E, W), `${$}
569
569
  @import url('./css/${F}');`;
570
570
  }, "");
571
571
  O += i;
@@ -578,7 +578,7 @@ ${Y}
578
578
  }
579
579
  }, be = async (e, t, s = gt()) => {
580
580
  try {
581
- const n = await Z(e);
581
+ const n = await H(e);
582
582
  if (dt(t)) {
583
583
  const r = [], a = await yt(e), { contents: d } = await at(e, t, n);
584
584
  for (const [y, h] of Object.entries(d)) {
@@ -614,7 +614,7 @@ ${Y}
614
614
  let m = M(g, "utf8");
615
615
  y.forEach((b) => {
616
616
  var P;
617
- const p = u(n, "css", b), f = ((P = /.*-([^-]+)-\d+.css/.exec(b)) == null ? void 0 : P.at(1)) || W(p, 6);
617
+ const p = u(n, "css", b), f = ((P = /.*-([^-]+)-\d+.css/.exec(b)) == null ? void 0 : P.at(1)) || A(p, 6);
618
618
  if (!m.includes(f)) {
619
619
  const _ = M(p, "utf8"), O = `/*start:${f}-${b}*/
620
620
  ${_}
@@ -628,7 +628,7 @@ ${O}
628
628
  });
629
629
  else {
630
630
  const y = r.flat().map((b) => `@import url('./${b}');`).join(`
631
- `), h = W(t, 6), l = rt(t), g = J(l.name), m = u(n, `css/f_${g}-${h}.css`);
631
+ `), h = A(t, 6), l = rt(t), g = R(l.name), m = u(n, `css/f_${g}-${h}.css`);
632
632
  x(m, y || "/* Empty file */");
633
633
  }
634
634
  }
@@ -638,7 +638,7 @@ ${O}
638
638
  }, Ce = async (e, t, s = gt()) => {
639
639
  var n, o;
640
640
  try {
641
- const r = await Z(e);
641
+ const r = await H(e);
642
642
  if (dt(t)) {
643
643
  const d = M(t, "utf8"), y = await yt(e), { contents: h } = await at(e, t, r);
644
644
  let l = d;
@@ -659,8 +659,8 @@ ${O}
659
659
  }
660
660
  }
661
661
  if (y.importStrategy === "component") {
662
- const g = W(t, 6), m = rt(t);
663
- l = `import '../../saltygen/css/${`f_${J(m.name)}-${g}.css`}';
662
+ const g = A(t, 6), m = rt(t);
663
+ l = `import '../../saltygen/css/${`f_${R(m.name)}-${g}.css`}';
664
664
  ${l}`;
665
665
  }
666
666
  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;
package/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("path"),t=require("./index-BD4dXHnv.cjs"),y=require("fs/promises"),g=require("fs"),p=async e=>{if(!e||e.includes("node_modules")||e.includes("saltygen"))return!1;if(e.includes("salty.config"))return!0;if(!t.isSaltyFile(e))return!1;const a=await y.readFile(e,"utf-8");return!!/.+define[A-Z]\w+/.test(a)},c=(e,s,l=!1,a=!1)=>{var i,n,u;(n=(i=e.module)==null?void 0:i.rules)==null||n.push({test:t.saltyFileRegExp(),use:[{loader:d.resolve(__dirname,a?"./loader.cjs":"./loader.js"),options:{dir:s}}]}),l||(u=e.plugins)==null||u.push({apply:f=>{let o=!1;f.hooks.beforeCompile.tapPromise({name:"generateCss"},async()=>{o||(o=!0,await t.generateCss(s),g.watch(s,{recursive:!0},async(h,r)=>{await p(r)?await t.generateCss(s,!1,!1):t.isSaltyFile(r)&&await t.generateFile(s,r)}))})}})};exports.default=c;exports.saltyPlugin=c;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("path"),t=require("./index-B5IaIfZg.cjs"),y=require("fs/promises"),g=require("fs"),p=async e=>{if(!e||e.includes("node_modules")||e.includes("saltygen"))return!1;if(e.includes("salty.config"))return!0;if(!t.isSaltyFile(e))return!1;const a=await y.readFile(e,"utf-8");return!!/.+define[A-Z]\w+/.test(a)},c=(e,s,l=!1,a=!1)=>{var i,n,u;(n=(i=e.module)==null?void 0:i.rules)==null||n.push({test:t.saltyFileRegExp(),use:[{loader:d.resolve(__dirname,a?"./loader.cjs":"./loader.js"),options:{dir:s}}]}),l||(u=e.plugins)==null||u.push({apply:f=>{let o=!1;f.hooks.beforeCompile.tapPromise({name:"generateCss"},async()=>{o||(o=!0,await t.generateCss(s),g.watch(s,{recursive:!0},async(h,r)=>{await p(r)?await t.generateCss(s,!1,!1):t.isSaltyFile(r)&&await t.generateFile(s,r)}))})}})};exports.default=c;exports.saltyPlugin=c;
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { resolve as p } from "path";
2
- import { i as f, s as d, g as u, a as y } from "./index-CMGA8uRZ.js";
2
+ import { i as f, s as d, g as u, a as y } from "./index-gNPxxbk_.js";
3
3
  import { readFile as g } from "fs/promises";
4
4
  import { watch as m } from "fs";
5
5
  const w = async (s) => {
package/loader.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";const i=require("./index-BD4dXHnv.cjs");async function n(){const{dir:e}=this.getOptions(),{resourcePath:t}=this;return await i.generateFile(e,t),await i.minimizeFile(e,t)}module.exports=n;
1
+ "use strict";const i=require("./index-B5IaIfZg.cjs");async function n(){const{dir:e}=this.getOptions(),{resourcePath:t}=this;return await i.generateFile(e,t),await i.minimizeFile(e,t)}module.exports=n;
package/loader.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as e, m as i } from "./index-CMGA8uRZ.js";
1
+ import { a as e, m as i } from "./index-gNPxxbk_.js";
2
2
  async function s() {
3
3
  const { dir: t } = this.getOptions(), { resourcePath: a } = this;
4
4
  return await e(t, a), await i(t, a);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/webpack",
3
- "version": "0.0.1-alpha.234",
3
+ "version": "0.0.1-alpha.235",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -34,7 +34,7 @@
34
34
  }
35
35
  },
36
36
  "dependencies": {
37
- "@salty-css/core": "^0.0.1-alpha.234",
37
+ "@salty-css/core": "^0.0.1-alpha.235",
38
38
  "webpack": ">=5.x"
39
39
  }
40
40
  }
@@ -1,42 +0,0 @@
1
- "use strict";var Vt=Object.defineProperty;var Mt=(e,t,s)=>t in e?Vt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var st=(e,t,s)=>Mt(e,typeof t!="symbol"?t+"":t,s);const vt=require("esbuild"),Rt=require("child_process"),c=require("path"),f=require("fs"),bt=require("fs/promises"),Q=require("winston"),lt=require("typescript");var ft=typeof document<"u"?document.currentScript:null;function zt(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const St=zt(vt),wt=e=>String.fromCharCode(e+(e>25?39:97)),At=(e,t)=>{let s="",n;for(n=Math.abs(e);n>52;n=n/52|0)s=wt(n%52)+s;return s=wt(n%52)+s,s.length<t?s=s.padStart(t,"a"):s.length>t&&(s=s.slice(-t)),s},Jt=(e,t)=>{let s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return e},J=(e,t=5)=>{const s=Jt(5381,JSON.stringify(e))>>>0;return At(s,t)};function R(e){return e?typeof e!="string"?R(String(e)):e.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?"-":"")+t.toLowerCase()):""}const Wt=e=>t=>{if(typeof t!="string"||!e)return;let s=t;const n=[];return Object.values(e).forEach(o=>{const{pattern:i,transform:r}=o;s=s.replace(i,y=>{const{value:g,css:h}=r(y);return h&&n.push(h),g})}),{transformed:s,additionalCss:n}},jt=e=>t=>typeof t!="string"||!/\{[^{}]+\}/g.test(t)?void 0:{transformed:t.replace(/\{([^{}]+)\}/g,(...o)=>`var(--${R(o[1].replaceAll(".","-"))})`)},qt=jt(),It=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Zt=(e,t,s)=>It.some(o=>typeof o=="string"?o===e:o.test(e))?`${t}px`:`${t}`,Lt=["Webkit","Moz","ms","O"],Ht=e=>e.startsWith("-")?e:Lt.some(t=>e.startsWith(t))?`-${R(e)}`:R(e),nt=async(e,t="",s,n=!1)=>{if(!e)throw new Error("No styles provided to parseStyles function!");const o=new Set,i=Object.entries(e),r=async([d,p])=>{const b=d.trim(),P=Ht(b),x=(M,k=";")=>`${P}:${M}${k}`,O={scope:t,config:s};if(typeof p=="function")return r([d,p(O)]);if(p instanceof Promise)return r([d,await p]);if(typeof p=="object"){if(!p)return;if(p.isColor)return x(p.toString());if(b==="defaultVariants")return;if(b==="variants"){const D=Object.entries(p);for(const[a,$]of D){if(!$)return;const C=Object.entries($);for(const[l,j]of C){if(!j)return;const N=`${t}.${a}-${l}`;(await nt(j,N,s)).forEach(A=>o.add(A))}}return}if(b==="compoundVariants"){for(const D of p){const{css:a,...$}=D,C=Object.entries($).reduce((j,[N,E])=>`${j}.${N}-${E}`,t);(await nt(a,C,s)).forEach(j=>o.add(j))}return}if(b.startsWith("@")){const D=b,a=await U(p,t,s),$=`${D} { ${a} }`;o.add($);return}const M=d.includes("&")?b.replace("&",t):b.startsWith(":")?`${t}${b}`:`${t} ${b}`;(await nt(p,M,s)).forEach(D=>o.add(D));return}if(typeof p=="number"){const M=Zt(P,p);return x(M)}if(typeof p!="string")if("toString"in p)p=p.toString();else throw new Error(`Invalid value type for property ${P}`);return x(p)},y=i.map(r),{modifiers:g}={},h=[jt(),Wt(g)],w=(await Promise.all(y).then(d=>Promise.all(d.map(p=>h.reduce(async(b,P)=>{const x=await b;if(!x)return x;const O=await P(x);if(!O)return x;const{transformed:M,additionalCss:k}=O;let D="";if(k)for(const a of k)D+=await U(a,"");return`${D}${M}`},Promise.resolve(p)))))).filter(d=>d!==void 0).join(`
2
- `);if(!w.trim())return Array.from(o);const m=t?`${t} {
3
- ${w}
4
- }`:w;return o.has(m)?Array.from(o):[m,...o]},U=async(e,t,s,n=!1)=>(await nt(e,t,s,n)).join(`
5
- `),Ft=async(e,t=[])=>{if(!e)return"";const s=[],n={};for(const[o,i]of Object.entries(e))if(typeof i!="function")if(i&&typeof i=="object"){const r=o.trim(),y=await Ft(i,[...t,r]);s.push(y)}else n[o]=i;if(Object.keys(n).length){const o=t.map(R).join("-"),i="t_"+J(o,4),r=await U(n,`.${o}, .${i}`);s.push(r)}return s.join(`
6
- `)},Gt=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="function"?t[s]="any":typeof n=="object"&&(t[s]=Ct(n).map(o=>`"${o}"`).join(" | ")),t),{}):{},Ct=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,o])=>{const i=t?`${t}.${n}`:n;return typeof o=="object"?Ct(o,i,s):s.add(t)}),[...s]):[],Pt=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=c.join(e,"package.json");return f.existsSync(t)?t:Pt(c.join(e,".."))},Kt=async e=>{const t=Pt(e);return await bt.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Qt=async e=>{const t=await Kt(e);if(t)return t.type};let I;const Nt=async e=>{if(I)return I;const t=await Qt(e);return t==="module"?I="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:ft&&ft.tagName.toUpperCase()==="SCRIPT"&&ft.src||new URL("index-BD4dXHnv.cjs",document.baseURI).href).endsWith(".cjs"))&&(I="cjs"),I||"esm"},ut=Q.createLogger({level:"debug",format:Q.format.combine(Q.format.colorize(),Q.format.cli()),transports:[new Q.transports.Console({})]});function _t(e){return e?typeof e!="string"?_t(String(e)):e.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?".":"")+t.toLowerCase()):""}const Ut={"*, *::before, *::after":{boxSizing:"border-box"},"*":{margin:0},html:{lineHeight:1.15,textSizeAdjust:"100%",WebkitFontSmoothing:"antialiased"},"img, picture, video, canvas, svg":{display:"block",maxWidth:"100%"},"p, h1, h2, h3, h4, h5, h6":{overflowWrap:"break-word"},p:{textWrap:"pretty"},"h1, h2, h3, h4, h5, h6":{textWrap:"balance"},a:{color:"currentColor"},button:{lineHeight:"1em",color:"currentColor"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},Z=(...e)=>e.flat().reduce((t,s)=>s!=null&&s._current?{...t,...s._current}:{...t,...s},{}),Bt=(...e)=>e.flat().reduce((t,s)=>({...t,...s._children}),{});class Xt{constructor(t){st(this,"_path");this.params=t}get _current(){return this.params.template}get isDefineTemplate(){return!0}_setPath(t){return this._path=t,this}}class Yt{constructor(t){st(this,"_path");st(this,"templates",[]);this.params=t,Object.entries(t).forEach(([s,n])=>{this.templates.push(new Xt({name:s,template:n}))})}get _current(){return this.params}get _children(){return Object.fromEntries(this.templates.map(t=>[t.params.name,t]))}get isDefineTemplates(){return!0}_setPath(t){return this._path=t,this.templates.forEach(s=>s._setPath(t)),this}}const te=e=>new Yt(e),ee=(e,t)=>new Promise((s,n)=>{const o=setTimeout(()=>{n(new Error("Timeout"))},100),i=lt.createSourceFile("temp.ts",e,lt.ScriptTarget.Latest,!0);function r(y){if(lt.isVariableDeclaration(y)&&y.name.getText()===t){const g=y.getStart(),h=y.getEnd();clearTimeout(o),s([g,h])}y.forEachChild(r)}r(i)}),z={externalModules:[],rcFile:void 0,destDir:void 0},xt=e=>{if(z.externalModules.length>0)return z.externalModules;const s=f.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return z.externalModules=n,n},W=async e=>{if(z.destDir)return z.destDir;const t=await pt(e),s=c.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return z.destDir=s,s},Tt=["salty","css","styles","styled"],kt=(e=[])=>new RegExp(`\\.(${[...Tt,...e].join("|")})\\.`),ot=(e,t=[])=>kt(t).test(e),Dt=async e=>{if(z.rcFile)return z.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=c.join(e,".saltyrc.json"),s=await bt.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(z.rcFile=s,s):Dt(c.join(e,".."))},pt=async e=>{var n,o;const t=await Dt(e),s=(n=t.projects)==null?void 0:n.find(i=>e.endsWith(i.dir||""));return s||((o=t.projects)==null?void 0:o.find(i=>i.dir===t.defaultProject))},se=async e=>{const t=await pt(e),s=await W(e),n=c.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),o=c.join(s,"salty.config.js"),i=await Nt(e),r=xt(n);await St.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:i,external:r});const y=Date.now(),{config:g}=await import(`${o}?t=${y}`);return{config:g,path:o}},ne=async(e,t)=>{var yt,ht;const s=await W(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async F=>{const{contents:_,outputFilePath:K}=await it(e,F,s);Object.entries(_).forEach(([v,T])=>{T.isMedia?n.mediaQueries.push([v,T]):T.isGlobalDefine?n.globalStyles.push(T):T.isDefineVariables?n.variables.push(T):T.isDefineTemplates&&n.templates.push(T._setPath(`${v};;${K}`))})}));const{config:o,path:i}=await se(e),r={...o},y=new Set,g=async(F,_=[])=>{if(!F)return[];const K=Object.entries(F).map(async([T,q])=>{const tt=async V=>{if(!V)return;if(V instanceof Promise)return await tt(await V);if(typeof V=="function")return await tt(await V());if(typeof V=="object")return await g(V,[..._,T]);const rt=_t(T),at=R(T),ct=[..._,rt].join(".");y.add(`"${ct}"`);const et=[..._.map(R),at].join("-"),gt=qt(V);return gt?`--${et}: ${gt.transformed};`:`--${et}: ${V};`};return await tt(q)});return(await Promise.all(K)).flat()},h=async F=>{if(!F)return[];const _=Object.entries(F).map(async([v,T])=>{const q=await g(T);return v==="base"?q.join(""):`${v} { ${q.join("")} }`});return(await Promise.all(_)).flat()},u=async F=>{if(!F)return[];const _=Object.entries(F).map(async([v,T])=>{const q=Object.entries(T).map(async([V,rt])=>{const at=await g(rt,[v]),ct=`.${v}-${V}, [data-${v}="${V}"]`,et=at.join("");return`${ct} { ${et} }`});return(await Promise.all(q)).flat()});return(await Promise.all(_)).flat()},w=F=>({...F,responsive:void 0,conditional:void 0}),m=F=>n.variables.map(_=>F==="static"?w(_._current):_._current[F]),S=Z(w(o.variables),m("static")),d=await g(S),p=Z((yt=o.variables)==null?void 0:yt.responsive,m("responsive")),b=await h(p),P=Z((ht=o.variables)==null?void 0:ht.conditional,m("conditional")),x=await u(P),O=c.join(s,"css/_variables.css"),M=`:root { ${d.join("")} ${b.join("")} } ${x.join("")}`;f.writeFileSync(O,M),r.staticVariables=S;const k=c.join(s,"css/_global.css"),D=Z(o.global,n.globalStyles),a=await U(D,"");f.writeFileSync(k,`@layer global { ${a} }`);const $=c.join(s,"css/_reset.css"),l=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:Ut,j=await U(l,"");f.writeFileSync($,`@layer reset { ${j} }`);const N=c.join(s,"css/_templates.css"),E=Z(o.templates,n.templates),A=await Ft(E),L=Gt(E);f.writeFileSync(N,`@layer templates { ${A} }`),r.templates=E;const H=o.templates?[te(o.templates)._setPath(`config;;${i}`)]:[],B=Bt(n.templates,H);r.templatePaths=Object.fromEntries(Object.entries(B).map(([F,_])=>[F,_._path]));const{mediaQueries:X}=n;r.mediaQueries=Object.fromEntries(X.map(([F,_])=>[`@${F}`,_]));const G=X.map(([F])=>`'@${F}'`).join(" | "),Y=c.join(s,"types/css-tokens.d.ts"),Et=`
7
- // Variable types
8
- type VariableTokens = ${[...y].join("|")};
9
- type PropertyValueToken = \`{\${VariableTokens}}\`;
10
-
11
- // Template types
12
- type TemplateTokens = {
13
- ${Object.entries(L).map(([F,_])=>`${F}?: ${_}`).join(`
14
- `)}
15
- }
16
-
17
- // Media query types
18
- type MediaQueryKeys = ${G||"''"};
19
- `;f.writeFileSync(Y,Et);const Ot=c.join(s,"cache/config-cache.json");f.writeFileSync(Ot,JSON.stringify(r,null,2))},$t=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const o=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!o.test(e))return t;const r=o.exec(e);if(r){const y=r.at(1);if(Tt.some(h=>y==null?void 0:y.includes(h)))return t}return"styled('div',"}),oe=(e,t)=>{try{const s=f.readFileSync(c.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
20
-
21
- ${e}`:`globalThis.saltyConfig = {};
22
-
23
- ${e}`}catch{return e}},it=async(e,t,s)=>{const n=J(t),o=c.join(s,"./temp");f.existsSync(o)||f.mkdirSync(o);const i=c.parse(t);let r=f.readFileSync(t,"utf8");r=$t(r),r=oe(r,e);const y=c.join(s,"js",n+".js"),g=await pt(e),h=c.join(e,(g==null?void 0:g.configDir)||"","salty.config.ts"),u=xt(h),w=await Nt(e);await St.build({stdin:{contents:r,sourcefile:i.base,resolveDir:i.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:w,target:["node20"],keepNames:!0,external:u,packages:"external",plugins:[{name:"test",setup:d=>{d.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},p=>{const b=f.readFileSync(p.path,"utf8");return{contents:$t(b),loader:"ts"}})}}]});const m=Date.now();return{contents:await import(`${y}?t=${m}`),outputFilePath:y}},ie=async e=>{const t=await W(e),s=c.join(t,"cache/config-cache.json"),n=f.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},dt=async e=>{const t=await ie(e),s=await W(e),n=c.join(s,"salty.config.js"),o=Date.now(),{config:i}=await import(`${n}?t=${o}`);return Z(i,t)},mt=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},re=async(e,t=mt(),s=!0)=>{try{const n=Date.now();t?ut.info("Generating CSS in production mode! 🔥"):ut.info("Generating CSS in development mode! 🚀");const o=[],i=[],r=await W(e),y=c.join(r,"index.css");s&&(()=>{f.existsSync(r)&&Rt.execSync("rm -rf "+r),f.mkdirSync(r,{recursive:!0}),f.mkdirSync(c.join(r,"css")),f.mkdirSync(c.join(r,"types")),f.mkdirSync(c.join(r,"js")),f.mkdirSync(c.join(r,"cache"))})();const h=new Set,u=new Set;async function w(a){const $=["node_modules","saltygen"],C=f.statSync(a);if(C.isDirectory()){const l=f.readdirSync(a);if($.some(N=>a.includes(N)))return;await Promise.all(l.map(N=>w(c.join(a,N))))}else if(C.isFile()&&ot(a)){h.add(a);const j=f.readFileSync(a,"utf8");/define[\w\d]+\(/.test(j)&&u.add(a)}}await w(e),await ne(e,u);const m={keyframes:[],components:[],classNames:[]};await Promise.all([...h].map(async a=>{const{contents:$}=await it(e,a,r);for(let[C,l]of Object.entries($))l instanceof Promise&&(l=await l),l.isKeyframes?m.keyframes.push({value:l,src:a,name:C}):l.isClassName?m.classNames.push({...l,src:a,name:C}):l.generator&&m.components.push({...l,src:a,name:C})}));const S=await dt(e);for(const a of m.keyframes){const{value:$}=a,C=`a_${$.animationName}.css`,l=`css/${C}`,j=c.join(r,l);o.push(C),f.writeFileSync(j,$.css)}const d={};for(const a of m.components){const{src:$,name:C}=a;d[$]||(d[$]=[]);const l=a.generator._withBuildContext({callerName:C,isProduction:t,config:S});i[l.priority]||(i[l.priority]=[]);const j=await l.css;if(!j)continue;i[l.priority].push(l.cssFileName);const N=`css/${l.cssFileName}`,E=c.join(r,N);f.writeFileSync(E,j),S.importStrategy==="component"&&d[$].push(l.cssFileName)}for(const a of m.classNames){const{src:$,name:C}=a;d[$]||(d[$]=[]);const l=a.generator._withBuildContext({callerName:C,isProduction:t,config:S}),j=await l.css;if(!j)continue;i[l.priority]||(i[l.priority]=[]),i[l.priority].push(l.cssFileName);const N=`css/${l.cssFileName}`,E=c.join(r,N);f.writeFileSync(E,j),S.importStrategy==="component"&&d[$].push(l.cssFileName)}S.importStrategy==="component"&&Object.entries(d).forEach(([a,$])=>{const C=$.map(A=>`@import url('./${A}');`).join(`
24
- `),l=J(a,6),j=c.parse(a),N=R(j.name),E=c.join(r,`css/f_${N}-${l}.css`);f.writeFileSync(E,C||"/* Empty file */")});const p=o.map(a=>`@import url('./css/${a}');`).join(`
25
- `);let O=`@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
26
-
27
- ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(a=>{try{return f.readFileSync(c.join(r,"css",a),"utf8").length>0}catch{return!1}}).map(a=>`@import url('./css/${a}');`).join(`
28
- `)}
29
- ${p}`;if(S.importStrategy!=="component"){const a=i.reduce(($,C,l)=>{const j=C.reduce((L,H)=>{var Y;const B=c.join(r,"css",H),X=f.readFileSync(B,"utf8"),G=((Y=/.*-([^-]+)-\d+.css/.exec(H))==null?void 0:Y.at(1))||J(B,6);return L.includes(G)?L:`${L}
30
- /*start:${G}-${H}*/
31
- ${X}
32
- /*end:${G}*/
33
- `},""),N=`l_${l}.css`,E=c.join(r,"css",N),A=`@layer l${l} { ${j}
34
- }`;return f.writeFileSync(E,A),`${$}
35
- @import url('./css/${N}');`},"");O+=a}f.writeFileSync(y,O);const k=Date.now()-n,D=k<200?"🔥":k<500?"🚀":k<1e3?"🎉":k<2e3?"🚗":k<5e3?"🤔":"🥴";ut.info(`Generated CSS in ${k}ms! ${D}`)}catch(n){console.error(n)}},ae=async(e,t,s=mt())=>{try{const n=await W(e);if(ot(t)){const i=[],r=await dt(e),{contents:y}=await it(e,t,n);for(const[g,h]of Object.entries(y)){if(h.isKeyframes&&h.css){const p=`css/${`a_${h.animationName}.css`}`,b=c.join(n,p);f.writeFileSync(b,await h.css);return}if(h.isClassName){const d=h.generator._withBuildContext({callerName:g,isProduction:s,config:r}),p=await d.css;if(!p)continue;i[d.priority]||(i[d.priority]=[]),i[d.priority].push(d.cssFileName);const b=`css/${d.cssFileName}`,P=c.join(n,b);f.writeFileSync(P,p)}if(!h.generator)return;const u=h.generator._withBuildContext({callerName:g,isProduction:s,config:r}),w=await u.css;if(!w)continue;const m=`css/${u.cssFileName}`,S=c.join(n,m);f.writeFileSync(S,w),i[u.priority]||(i[u.priority]=[]),i[u.priority].push(u.cssFileName)}if(r.importStrategy!=="component")i.forEach((g,h)=>{const u=`l_${h}.css`,w=c.join(n,"css",u);let m=f.readFileSync(w,"utf8");g.forEach(S=>{var P;const d=c.join(n,"css",S),p=((P=/.*-([^-]+)-\d+.css/.exec(S))==null?void 0:P.at(1))||J(d,6);if(!m.includes(p)){const x=f.readFileSync(d,"utf8"),O=`/*start:${p}-${S}*/
36
- ${x}
37
- /*end:${p}*/
38
- `;m=`${m.replace(/\}$/,"")}
39
- ${O}
40
- }`}}),f.writeFileSync(w,m)});else{const g=i.flat().map(S=>`@import url('./${S}');`).join(`
41
- `),h=J(t,6),u=c.parse(t),w=R(u.name),m=c.join(n,`css/f_${w}-${h}.css`);f.writeFileSync(m,g||"/* Empty file */")}}}catch(n){console.error(n)}},ce=async(e,t,s=mt())=>{var n,o;try{const i=await W(e);if(ot(t)){const y=f.readFileSync(t,"utf8"),g=await dt(e),{contents:h}=await it(e,t,i);let u=y;for(const[w,m]of Object.entries(h)){if(m.isKeyframes||!m.generator)continue;const S=m.generator._withBuildContext({callerName:w,isProduction:s,config:g}),[d,p]=await ee(u,w),b=u.slice(d,p);if(m.isClassName){const P=u,x=` ${w} = className("${S.classNames}")`;u=u.replace(b,x),P===u&&console.error("Minimize file failed to change content",{name:w})}if(b.includes("styled")){const P=(o=(n=/styled\(([^,]+),/.exec(b))==null?void 0:n.at(1))==null?void 0:o.trim(),x=u,O=` ${w} = styled(${P}, "${S.classNames}", ${JSON.stringify(S.clientProps)})`;u=u.replace(b,O),x===u&&console.error("Minimize file failed to change content",{name:w,tagName:P})}}if(g.importStrategy==="component"){const w=J(t,6),m=c.parse(t);u=`import '../../saltygen/css/${`f_${R(m.name)}-${w}.css`}';
42
- ${u}`}return u=u.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),u=u.replace("{ styled }","{ styledClient as styled }"),u=u.replace("@salty-css/react/styled","@salty-css/react/styled-client"),u}}catch(i){console.error("Error in minimizeFile:",i)}};exports.generateCss=re;exports.generateFile=ae;exports.isSaltyFile=ot;exports.minimizeFile=ce;exports.saltyFileRegExp=kt;