@salty-css/vite 0.0.1-alpha.197 → 0.0.1-alpha.199

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