@salty-css/vite 0.0.1-alpha.205 → 0.0.1-alpha.207

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