@salty-css/vite 0.0.1-alpha.194 → 0.0.1-alpha.196

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 +326 -297
  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 $e=require("esbuild"),be=require("child_process"),l=require("path"),u=require("fs"),K=require("fs/promises"),q=require("winston");var v=typeof document<"u"?document.currentScript:null;function we(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 ce=we($e),oe=e=>String.fromCharCode(e+(e>25?39:97)),Fe=(e,t)=>{let s="",n;for(n=Math.abs(e);n>52;n=n/52|0)s=oe(n%52)+s;return s=oe(n%52)+s,s.length<t?s=s.padStart(t,"a"):s.length>t&&(s=s.slice(-t)),s},Ce=(e,t)=>{let s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return e},z=(e,t=5)=>{const s=Ce(5381,JSON.stringify(e))>>>0;return Fe(s,t)};function M(e){return e?typeof e!="string"?M(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 Ne=(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}},ae=e=>typeof e!="string"?{result:e}:/\{[^{}]+\}/g.test(e)?{result:e.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${M(n[1].replaceAll(".","-"))})`)}:{result:e},R=(e,t,s)=>{if(!e)return"";const n=[],i=Object.entries(e).reduce((c,[p,r])=>{const o=p.trim(),h=o.startsWith("-")?o:M(o),g=(F,N=";")=>c=`${c}${F}${N}`,y=F=>g(`${h}:${F}`);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(([_,$])=>{$&&Object.entries($).forEach(([O,f])=>{if(!f)return;const m=`${t}.${_}-${O}`,b=R(f,m);n.push(b)})}),c;if(o==="defaultVariants")return c;if(o==="compoundVariants")return r.forEach(_=>{const{css:$,...O}=_,f=Object.entries(O).reduce((b,[d,x])=>`${b}.${d}-${x}`,t),m=R($,f);n.push(m)}),c;if(o.startsWith("@")){const _=R(r,t),$=`${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($),c}const F=p.includes("&")?o.replace("&",t):o.startsWith(":")?`${t}${o}`:`${t} ${o}`,N=R(r,F);return n.push(N),c}if(typeof r=="number")return y(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return c;const{modifiers:j}={},D=function*(){yield ae(r),yield Ne(r,j)}();for(const{result:F,additionalCss:N=[]}of D)r=F,N.forEach(_=>{const $=R(_,"");g($,"")});return y(r)},"");return i?t?[`${t} { ${i} }`,...n].join(`
6
- `):i:n.join(`
7
- `)},le=(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=le(a,[...t,c]);s.push(p)}else n[i]=a}),Object.keys(n).length){const i=t.map(M).join("-"),a=R(n,`.${i}`);s.push(a)}return s.join(`
8
- `)},xe=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="object"&&(t[s]=fe(n).map(i=>`"${i}"`).join(" | ")),t),{}):{},fe=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,i])=>{const a=t?`${t}.${n}`:n;return typeof i=="object"?fe(i,a,s):s.add(t)}),[...s]):[],ue=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:ue(l.join(e,".."))},ke=async e=>{const t=ue(e);return await K.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Pe=async e=>{const t=await ke(e);if(t)return t.type};let A;const de=async e=>{if(A)return A;const t=await Pe(e);return t==="module"?A="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:v&&v.tagName.toUpperCase()==="SCRIPT"&&v.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(A="cjs"),A||"esm"},ee=q.createLogger({level:"debug",format:q.format.combine(q.format.colorize(),q.format.cli()),transports:[new q.transports.Console({})]});function pe(e){return e?typeof e!="string"?pe(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 _e={"*, *::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},ye=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 te(e),s=l.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return E.destDir=s,s},ge=["salty","css","styles","styled"],De=(e=[])=>new RegExp(`\\.(${[...ge,...e].join("|")})\\.`),Z=(e,t=[])=>De(t).test(e),he=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):he(l.join(e,".."))},te=async e=>{var n,i;const t=await he(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))},Te=async e=>{const t=await te(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 de(e),c=ye(n);await ce.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},Oe=async(e,t)=>{var H,G;const s=await Te(e),n={...s},i=new Set,a=(C,k=[])=>C?Object.entries(C).flatMap(([V,T])=>{if(!T)return;if(typeof T=="object")return a(T,[...k,V]);const U=pe(V),Q=M(V),X=[...k,U].join(".");i.add(`"${X}"`);const Y=[...k.map(M),Q].join("-"),{result:je}=ae(T);return`--${Y}: ${je};`}):[],c=C=>C?Object.entries(C).flatMap(([k,V])=>{const T=a(V);return k==="base"?T.join(""):`${k} { ${T.join("")} }`}):[],p=C=>C?Object.entries(C).flatMap(([k,V])=>Object.entries(V).flatMap(([T,U])=>{const Q=a(U,[k]),X=`.${k}-${T}, [data-${k}="${T}"]`,Y=Q.join("");return`${X} { ${Y} }`})):[],r=C=>({...C,responsive:void 0,conditional:void 0}),o=C=>t.variables.map(k=>C==="static"?r(k._current):k._current[C]),h=a(W(r(s.variables),o("static"))),g=c(W((H=s.variables)==null?void 0:H.responsive,o("responsive"))),y=p(W((G=s.variables)==null?void 0:G.conditional,o("conditional"))),j=await J(e),P=l.join(j,"css/_variables.css"),D=`:root { ${h.join("")} ${g.join("")} } ${y.join("")}`;u.writeFileSync(P,D);const F=l.join(j,"css/_global.css"),N=W(s.global,t.globalStyles),_=R(N,"");u.writeFileSync(F,`@layer global { ${_} }`);const $=l.join(j,"css/_reset.css"),f=s.reset==="none"?{}:typeof s.reset=="object"?s.reset:_e,m=R(f,"");u.writeFileSync($,`@layer reset { ${m} }`);const b=l.join(j,"css/_templates.css"),d=W(s.templates,t.templates),x=le(d),w=xe(d);u.writeFileSync(b,x),n.templates=d;const S=l.join(j,"types/css-tokens.d.ts"),I=`
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(w).map(([C,k])=>`${C}?: ${k}`).join(`
15
+ ${Object.entries(L).map(([x,k])=>`${x}?: ${k}`).join(`
16
16
  `)}
17
17
  }
18
- `;u.writeFileSync(S,I);const B=l.join(j,"cache/config-cache.json");u.writeFileSync(B,JSON.stringify(n,null,2))},re=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(ge.some(o=>p==null?void 0:p.includes(o)))return t}return"styled('div',"}),se=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=re(c);const p=l.join(s,"js",n+".js"),r=await te(e),o=l.join(e,(r==null?void 0:r.configDir)||"","salty.config.ts"),h=ye(o),g=await de(e);await ce.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:P=>{P.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},D=>{const F=u.readFileSync(D.path,"utf8");return{contents:re(F),loader:"ts"}})}}]});const y=Date.now();return await import(`${p}?t=${y}`)},Ee=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)},ne=async e=>{const t=await Ee(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)},me=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Me=async(e,t=me(),s=!0)=>{try{const n=Date.now();t?ee.info("Generating CSS in production mode! 🔥"):ee.info("Generating CSS in development mode! 🚀");const i=[],a=[],c=await J(e),p=l.join(c,"index.css");s&&(()=>{u.existsSync(c)&&be.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 m=["node_modules","saltygen"],b=u.statSync(f);if(b.isDirectory()){const d=u.readdirSync(f);if(m.some(w=>f.includes(w)))return;await Promise.all(d.map(w=>h(l.join(f,w))))}else if(b.isFile()&&Z(f)){const x=await se(e,f,c);Object.entries(x).forEach(([w,S])=>{S.isKeyframes?o.keyframes.push({value:S,src:f,name:w}):S.isMedia?o.mediaQueries.push(S):S.isGlobalDefine?o.globalStyles.push(S):S.isDefineVariables?o.variables.push(S):S.isDefineTemplates?o.templates.push(S):S.isClassName?o.classNames.push({...S,src:f,name:w}):S.generator&&o.components.push({...S,src:f,name:w})})}}await h(e),await Oe(e,o);const g=await ne(e);for(const f of o.keyframes){const{value:m}=f,b=`a_${m.animationName}.css`,d=`css/${b}`,x=l.join(c,d);i.push(b),u.writeFileSync(x,m.css)}const y={};for(const f of o.components){const{src:m,name:b}=f,d=f.generator._withBuildContext({callerName:b,isProduction:t,config:g});a[d.priority]||(a[d.priority]=[]),a[d.priority].push(d.cssFileName);const x=`css/${d.cssFileName}`,w=l.join(c,x);u.writeFileSync(w,d.css),g.importStrategy==="component"&&(y[m]?y[m].push(d.cssFileName):y[m]=[d.cssFileName])}for(const f of o.classNames){const{src:m,name:b}=f,d=f.generator._withBuildContext({callerName:b,isProduction:t,config:g});a[0].push(d.cssFileName);const x=`css/${d.cssFileName}`,w=l.join(c,x);u.writeFileSync(w,d.css),g.importStrategy==="component"&&(y[m]?y[m].push(d.cssFileName):y[m]=[d.cssFileName])}g.importStrategy==="component"&&Object.entries(y).forEach(([f,m])=>{const b=m.map(L=>`@import url('./${L}');`).join(`
19
- `),d=z(f,6),x=l.parse(f),w=M(x.name),S=l.join(c,`css/f_${w}-${d}.css`);u.writeFileSync(S,b)});const j=i.map(f=>`@import url('./css/${f}');`).join(`
20
- `);let N=`@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
- ${j}`;if(g.importStrategy!=="component"){const f=a.reduce((m,b,d)=>{const x=b.reduce((I,B)=>{var k;const H=l.join(c,"css",B),G=u.readFileSync(H,"utf8"),C=((k=/.*-([^-]+)-\d+.css/.exec(B))==null?void 0:k.at(1))||z(H,6);return I.includes(C)?I:`${I}
25
- /*start:${C}*/
26
- ${G}
27
- /*end:${C}*/
28
- `},""),w=`l_${d}.css`,S=l.join(c,"css",w),L=`@layer l${d} { ${x}
29
- }`;return u.writeFileSync(S,L),`${m}
30
- @import url('./css/${w}');`},"");N+=f}u.writeFileSync(p,N);const $=Date.now()-n,O=$<200?"🔥":$<500?"🚀":$<1e3?"🎉":$<2e3?"🚗":$<5e3?"🤔":"🥴";ee.info(`Generated CSS in ${$}ms! ${O}`)}catch(n){console.error(n)}},Re=async(e,t)=>{try{const s=await J(e);if(Z(t)){const i=[],a=await ne(e),c=await se(e,t,s);if(Object.entries(c).forEach(([p,r])=>{if(r.isKeyframes&&r.css){const j=`css/${`a_${r.animationName}.css`}`,P=l.join(s,j);u.writeFileSync(P,r.css);return}if(r.isClassName){const y=r.factory._withBuildContext({name:p});i[0].push(y.cssFileName);const j=`css/${y.cssFileName}`,P=l.join(s,j);u.writeFileSync(P,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 F;const j=l.join(s,"css",y),P=((F=/.*-([^-]+)-\d+.css/.exec(y))==null?void 0:F.at(1))||z(j,6);if(!g.includes(P)){const N=u.readFileSync(j,"utf8"),_=`/*start:${P}*/
31
- ${N}
32
- /*end:${P}*/
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=M(o.name),g=l.join(s,`css/f_${h}-${r}.css`);u.writeFileSync(g,p)}}}catch(s){console.error(s)}},Ve=async(e,t,s=me())=>{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 ne(e),r=await se(e,t,n);let o=a;if(Object.entries(r).forEach(([h,g])=>{var w;if(g.isKeyframes||!g.generator)return;const y=g.generator._withBuildContext({name:h,config:p,prod:s}),j=new RegExp(`\\s${h}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(a);if(!j)return console.error("Could not find the original declaration");const P=(w=j.at(1))==null?void 0:w.trim(),D=new RegExp(`\\s${h}[=\\s]+styled\\(`,"g").exec(o);if(!D)return console.error("Could not find the original declaration");const{index:F}=D;let N=!1;const _=setTimeout(()=>N=!0,5e3);let $=0,O=!1,f=0;for(;!O&&!N;){const S=o[F+$];S==="("&&f++,S===")"&&f--,f===0&&S===")"&&(O=!0),$>o.length&&(N=!0),$++}if(!N)clearTimeout(_);else throw new Error("Failed to find the end of the styled call and timed out");const m=F+$,b=o.slice(F,m),d=o,x=` ${h} = styled(${P}, "${y.classNames}", ${JSON.stringify(y.clientProps)});`;o=o.replace(b,x),d===o&&console.error("Minimize file failed to change content",{name:h,tagName:P})}),p.importStrategy==="component"){const h=z(t,6),g=l.parse(t);o=`import '../../saltygen/css/${`f_${M(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)}},ie=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)},Se=e=>({name:"stylegen",buildStart:()=>Me(e),load:async t=>{if(Z(t))return await Ve(e,t)},handleHotUpdate:async({file:t,server:s})=>{await ie(t)&&await s.restart()},watchChange:{handler:async t=>{Z(t)&&(await ie(t)||await Re(e,t))}}});exports.default=Se;exports.saltyPlugin=Se;
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 ft from "esbuild";
2
- import { execSync as Ct } from "child_process";
3
- import { join as f, parse as Q } from "path";
4
- import { existsSync as st, mkdirSync as z, statSync as jt, readdirSync as Ft, writeFileSync as k, readFileSync as V } from "fs";
5
- import { readFile as nt, writeFile as Nt } from "fs/promises";
6
- import { createLogger as xt, format as tt, transports as kt } from "winston";
7
- const ct = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), Pt = (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 = ct(n % 52) + s;
10
- return s = ct(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
11
- }, Dt = (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 = Dt(5381, JSON.stringify(t)) >>> 0;
17
- return Pt(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 Et = (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
- }, ut = (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, F = ";") => c = `${c}${C}${F}`, d = (C) => g(`${h}:${C}`);
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(([T, l]) => {
44
- if (!l) return;
45
- const m = `${e}.${D}-${T}`, w = R(l, m);
46
- n.push(w);
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, ...T } = D, l = Object.entries(T).reduce((w, [u, N]) => `${w}.${u}-${N}`, e), m = R(b, l);
54
- n.push(m);
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 C = p.includes("&") ? o.replace("&", e) : o.startsWith(":") ? `${e}${o}` : `${e} ${o}`, F = R(r, C);
65
- return n.push(F), 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: $ } = {}, E = function* () {
72
- yield ut(r), yield Et(r, $);
70
+ else return i;
71
+ const { modifiers: b } = {}, E = function* () {
72
+ yield ht(r), yield Ot(r, b);
73
73
  }();
74
- for (const { result: C, additionalCss: F = [] } of E)
75
- r = C, F.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
- }, pt = (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 = pt(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
- }, _t = (t) => t ? Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = dt(n).map((i) => `"${i}"`).join(" | ")), e), {}) : {}, dt = (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" ? dt(i, a, s) : s.add(e);
103
- }), [...s]) : [], gt = (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 st(e) ? e : gt(f(t, ".."));
107
- }, Tt = async (t) => {
108
- const e = gt(t);
109
- return await nt(e, "utf-8").then(JSON.parse).catch(() => {
106
+ return ct(e) ? e : $t(f(t, ".."));
107
+ }, Mt = async (t) => {
108
+ const e = $t(t);
109
+ return await at(e, "utf-8").then(JSON.parse).catch(() => {
110
110
  });
111
- }, Ot = async (t) => {
112
- const e = await Tt(t);
111
+ }, Jt = async (t) => {
112
+ const e = await Mt(t);
113
113
  if (e)
114
114
  return e.type;
115
115
  };
116
- let W;
117
- const ht = async (t) => {
118
- if (W) return W;
119
- const e = await Ot(t);
120
- return e === "module" ? W = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (W = "cjs"), W || "esm";
121
- }, et = xt({
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: tt.combine(tt.colorize(), tt.cli()),
124
- transports: [new kt.Console({})]
123
+ format: rt.combine(rt.colorize(), rt.cli()),
124
+ transports: [new Et.Console({})]
125
125
  });
126
- function mt(t) {
127
- 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()) : "";
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 Vt = {
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 Vt = {
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 }, {}), O = {
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
- }, yt = (t) => {
180
- if (O.externalModules.length > 0) return O.externalModules;
181
- const s = V(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 O.externalModules = n, n;
185
- }, A = async (t) => {
186
- if (O.destDir) return O.destDir;
187
- const e = await ot(t), s = f(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
188
- return O.destDir = s, s;
189
- }, $t = ["salty", "css", "styles", "styled"], Mt = (t = []) => new RegExp(`\\.(${[...$t, ...t].join("|")})\\.`), I = (t, e = []) => Mt(e).test(t), bt = async (t) => {
190
- if (O.rcFile) return O.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 nt(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 ? (O.rcFile = s, s) : bt(f(t, ".."));
195
- }, ot = async (t) => {
196
- var n, i;
197
- const e = await bt(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
- }, Rt = async (t) => {
200
- const e = await ot(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 ht(t), c = yt(n);
201
- await ft.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
- }, Jt = async (t, e) => {
213
- var G, q;
214
- const s = await Rt(t), n = { ...s }, i = /* @__PURE__ */ new Set(), a = (j, x = []) => j ? Object.entries(j).flatMap(([J, _]) => {
215
- if (!_) return;
216
- if (typeof _ == "object") return a(_, [...x, J]);
217
- const U = mt(J), X = M(J), Y = [...x, U].join(".");
218
- i.add(`"${Y}"`);
219
- const v = [...x.map(M), X].join("-"), { result: St } = ut(_);
220
- return `--${v}: ${St};`;
221
- }) : [], c = (j) => j ? Object.entries(j).flatMap(([x, J]) => {
222
- const _ = a(J);
223
- return x === "base" ? _.join("") : `${x} { ${_.join("")} }`;
224
- }) : [], p = (j) => j ? Object.entries(j).flatMap(([x, J]) => Object.entries(J).flatMap(([_, U]) => {
225
- const X = a(U, [x]), Y = `.${x}-${_}, [data-${x}="${_}"]`, v = X.join("");
226
- return `${Y} { ${v} }`;
227
- })) : [], r = (j) => ({ ...j, responsive: void 0, conditional: void 0 }), o = (j) => e.variables.map((x) => j === "static" ? r(x._current) : x._current[j]), h = a(Z(r(s.variables), o("static"))), g = c(Z((G = s.variables) == null ? void 0 : G.responsive, o("responsive"))), d = p(Z((q = s.variables) == null ? void 0 : q.conditional, o("conditional"))), $ = await A(t), P = f($, "css/_variables.css"), E = `:root { ${h.join("")} ${g.join("")} } ${d.join("")}`;
228
- k(P, E);
229
- const C = f($, "css/_global.css"), F = Z(s.global, e.globalStyles), D = R(F, "");
230
- k(C, `@layer global { ${D} }`);
231
- const b = f($, "css/_reset.css"), l = s.reset === "none" ? {} : typeof s.reset == "object" ? s.reset : Vt, m = R(l, "");
232
- k(b, `@layer reset { ${m} }`);
233
- const w = f($, "css/_templates.css"), u = Z(s.templates, e.templates), N = pt(u), S = _t(u);
234
- k(w, N), n.templates = u;
235
- const y = f($, "types/css-tokens.d.ts"), B = `
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(S).map(([j, x]) => `${j}?: ${x}`).join(`
256
+ ${Object.entries(K).map(([N, x]) => `${N}?: ${x}`).join(`
243
257
  `)}
244
258
  }
245
259
  `;
246
- k(y, B);
247
- const K = f($, "cache/config-cache.json");
248
- k(K, JSON.stringify(n, null, 2));
249
- }, at = (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 ($t.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
- }), rt = async (t, e, s) => {
260
- const n = H(e), i = f(s, "./temp");
261
- st(i) || z(i);
262
- const a = Q(e);
263
- let c = V(e, "utf8");
264
- c = at(c);
265
- const p = f(s, "js", n + ".js"), r = await ot(t), o = f(t, (r == null ? void 0 : r.configDir) || "", "salty.config.ts"), h = yt(o), g = await ht(t);
266
- await ft.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 Vt = {
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: (P) => {
286
- P.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (E) => {
287
- const C = V(E.path, "utf8");
288
- return { contents: at(C), 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 Vt = {
293
318
  });
294
319
  const d = Date.now();
295
320
  return await import(`${p}?t=${d}`);
296
- }, At = async (t) => {
297
- const e = await A(t), s = f(e, "cache/config-cache.json"), n = V(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
- }, it = async (t) => {
301
- const e = await At(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
- }, wt = () => {
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
- }, Wt = async (t, e = wt(), s = !0) => {
334
+ }, Bt = async (t, e = Ft(), s = !0) => {
310
335
  try {
311
336
  const n = Date.now();
312
- e ? et.info("Generating CSS in production mode! 🔥") : et.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
- st(c) && Ct("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 m = ["node_modules", "saltygen"], w = jt(l);
328
- if (w.isDirectory()) {
329
- const u = Ft(l);
330
- if (m.some((S) => l.includes(S))) return;
331
- await Promise.all(u.map((S) => h(f(l, S))));
332
- } else if (w.isFile() && I(l)) {
333
- const N = await rt(t, l, c);
334
- Object.entries(N).forEach(([S, y]) => {
335
- y.isKeyframes ? o.keyframes.push({
336
- value: y,
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: S
339
- }) : y.isMedia ? o.mediaQueries.push(y) : y.isGlobalDefine ? o.globalStyles.push(y) : y.isDefineVariables ? o.variables.push(y) : y.isDefineTemplates ? o.templates.push(y) : y.isClassName ? o.classNames.push({
340
- ...y,
368
+ name: $
369
+ }) : u.isClassName ? d.classNames.push({
370
+ ...u,
341
371
  src: l,
342
- name: S
343
- }) : y.generator && o.components.push({
344
- ...y,
372
+ name: $
373
+ }) : u.generator && d.components.push({
374
+ ...u,
345
375
  src: l,
346
- name: S
376
+ name: $
347
377
  });
348
378
  });
349
- }
350
- }
351
- await h(t), await Jt(t, o);
352
- const g = await it(t);
353
- for (const l of o.keyframes) {
354
- const { value: m } = l, w = `a_${m.animationName}.css`, u = `css/${w}`, N = f(c, u);
355
- i.push(w), k(N, m.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: m, name: w } = l, u = l.generator._withBuildContext({
360
- callerName: w,
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 N = `css/${u.cssFileName}`, S = f(c, N);
366
- k(S, u.css), g.importStrategy === "component" && (d[m] ? d[m].push(u.cssFileName) : d[m] = [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: m, name: w } = l, u = l.generator._withBuildContext({
370
- callerName: w,
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 N = `css/${u.cssFileName}`, S = f(c, N);
376
- k(S, u.css), g.importStrategy === "component" && (d[m] ? d[m].push(u.cssFileName) : d[m] = [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, m]) => {
379
- const w = m.map((L) => `@import url('./${L}');`).join(`
380
- `), u = H(l, 6), N = Q(l), S = M(N.name), y = f(c, `css/f_${S}-${u}.css`);
381
- k(y, w);
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 $ = i.map((l) => `@import url('./css/${l}');`).join(`
412
+ const E = o.map((l) => `@import url('./css/${l}');`).join(`
384
413
  `);
385
- let F = `@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 V(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
- ${$}`;
396
- if (g.importStrategy !== "component") {
397
- const l = a.reduce((m, w, u) => {
398
- const N = w.reduce((B, K) => {
399
- var x;
400
- const G = f(c, "css", K), q = V(G, "utf8"), j = ((x = /.*-([^-]+)-\d+.css/.exec(K)) == null ? void 0 : x.at(1)) || H(G, 6);
401
- return B.includes(j) ? B : `${B}
402
- /*start:${j}*/
403
- ${q}
404
- /*end:${j}*/
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
- }, ""), S = `l_${u}.css`, y = f(c, "css", S), L = `@layer l${u} { ${N}
435
+ }, ""), F = `l_${u}.css`, L = f(i, "css", F), K = `@layer l${u} { ${C}
407
436
  }`;
408
- return k(y, L), `${m}
409
- @import url('./css/${S}');`;
437
+ return k(L, K), `${m}
438
+ @import url('./css/${F}');`;
410
439
  }, "");
411
- F += l;
440
+ S += l;
412
441
  }
413
- k(p, F);
414
- const b = Date.now() - n, T = b < 200 ? "🔥" : b < 500 ? "🚀" : b < 1e3 ? "🎉" : b < 2e3 ? "🚗" : b < 5e3 ? "🤔" : "🥴";
415
- et.info(`Generated CSS in ${b}ms! ${T}`);
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
- }, zt = 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 it(t), c = await rt(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 $ = `css/${`a_${r.animationName}.css`}`, P = f(s, $);
427
- k(P, 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 $ = `css/${d.cssFileName}`, P = f(s, $);
436
- k(P, 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
- k(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 = V(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 C;
450
- const $ = f(s, "css", d), P = ((C = /.*-([^-]+)-\d+.css/.exec(d)) == null ? void 0 : C.at(1)) || H($, 6);
451
- if (!g.includes(P)) {
452
- const F = V($, "utf8"), D = `/*start:${P}*/
453
- ${F}
454
- /*end:${P}*/
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
- }), k(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
- k(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
- }, Zt = async (t, e, s = wt()) => {
500
+ }, Lt = async (t, e, s = Ft()) => {
472
501
  try {
473
- const n = await A(t);
474
- if (I(e)) {
475
- const a = V(e, "utf8");
476
- a.replace(/^(?!export\s)const\s.*/gm, (h) => `export ${h}`) !== a && await Nt(e, a);
477
- const p = await it(t), r = await rt(t, e, n);
478
- let o = a;
479
- if (Object.entries(r).forEach(([h, g]) => {
480
- var S;
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
- }), $ = new RegExp(`\\s${h}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(a);
487
- if (!$) return console.error("Could not find the original declaration");
488
- const P = (S = $.at(1)) == null ? void 0 : S.trim(), E = new RegExp(`\\s${h}[=\\s]+styled\\(`, "g").exec(o);
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);
489
518
  if (!E) return console.error("Could not find the original declaration");
490
- const { index: C } = E;
491
- let F = !1;
492
- const D = setTimeout(() => F = !0, 5e3);
493
- let b = 0, T = !1, l = 0;
494
- for (; !T && !F; ) {
495
- const y = o[C + b];
496
- y === "(" && l++, y === ")" && l--, l === 0 && y === ")" && (T = !0), b > o.length && (F = !0), b++;
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 (!F) 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 m = C + b, w = o.slice(C, m), u = o, N = ` ${h} = styled(${P}, "${d.classNames}", ${JSON.stringify(d.clientProps)});`;
501
- o = o.replace(w, N), u === o && console.error("Minimize file failed to change content", { name: h, tagName: P });
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
- }, lt = 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 nt(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
- }, Kt = (t) => ({
547
+ }, Yt = (t) => ({
519
548
  name: "stylegen",
520
- buildStart: () => Wt(t),
549
+ buildStart: () => Bt(t),
521
550
  load: async (e) => {
522
- if (I(e))
523
- return await Zt(t, e);
551
+ if (G(e))
552
+ return await Lt(t, e);
524
553
  },
525
554
  handleHotUpdate: async ({ file: e, server: s }) => {
526
- await lt(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 lt(e) || await zt(t, e));
559
+ G(e) && (await dt(e) || await Gt(t, e));
531
560
  }
532
561
  }
533
562
  });
534
563
  export {
535
- Kt as default,
536
- Kt 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.194",
3
+ "version": "0.0.1-alpha.196",
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.194"
37
+ "@salty-css/core": "^0.0.1-alpha.196"
38
38
  }
39
39
  }