@salty-css/vite 0.0.1-alpha.183 → 0.0.1-alpha.186

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