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

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