@salty-css/vite 0.0.1-alpha.84 → 0.0.1-alpha.86

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 +14 -14
  2. package/index.js +244 -230
  3. package/package.json +2 -2
package/index.cjs CHANGED
@@ -1,18 +1,18 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const tt=require("esbuild"),et=require("child_process"),u=require("path"),d=require("fs"),B=require("fs/promises");var _=typeof document<"u"?document.currentScript:null;function st(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 Z=st(tt),W=t=>String.fromCharCode(t+(t>25?39:97)),nt=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=W(n%52)+s;return s=W(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},ot=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},R=(t,e=3)=>{const s=ot(5381,JSON.stringify(t))>>>0;return nt(s,e)};function D(t){return t?typeof t!="string"?D(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 rt=(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:y}=n;t=t.replace(o,g=>{const{value:a,css:c}=y(g);return c&&s.push(c),a})}),{result:t,additionalCss:s}},z=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${D(n[1].replaceAll(".","-"))})`)}:{result:t},M=(t,e,s,n)=>{if(!t)return"";const o=[],y=Object.entries(t).reduce((a,[c,r])=>{const f=c.trim();if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return a;if(f==="variants")return Object.entries(r).forEach(([i,p])=>{p&&Object.entries(p).forEach(([j,m])=>{if(!m)return;const F=`${e}.${i}-${j}`,$=M(m,F);o.push($)})}),a;if(f==="defaultVariants")return a;if(f==="compoundVariants")return r.forEach(i=>{const{css:p,...j}=i,m=Object.entries(j).reduce(($,[w,T])=>`${$}.${w}-${T}`,e),F=M(p,m);o.push(F)}),a;if(f.startsWith("@")){const i=M(r,e),p=`${f} {
2
- ${i.replace(`
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const ot=require("esbuild"),rt=require("child_process"),u=require("path"),d=require("fs"),L=require("fs/promises"),V=require("winston");var R=typeof document<"u"?document.currentScript:null;function it(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 U=it(ot),B=t=>String.fromCharCode(t+(t>25?39:97)),ct=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=B(n%52)+s;return s=B(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},at=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},q=(t,e=3)=>{const s=at(5381,JSON.stringify(t))>>>0;return ct(s,e)};function E(t){return t?typeof t!="string"?E(String(t)):t.replace(/\s/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?"-":"")+e.toLowerCase()):""}const lt=(t,e)=>{if(typeof t!="string")return{result:t};if(!e)return{result:t};const s=[];return Object.values(e).forEach(n=>{const{pattern:r,transform:c}=n;t=t.replace(r,m=>{const{value:a,css:j}=c(m);return j&&s.push(j),a})}),{result:t,additionalCss:s}},G=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${E(n[1].replaceAll(".","-"))})`)}:{result:t},T=(t,e,s,n)=>{if(!t)return"";const r=[],c=Object.entries(t).reduce((a,[j,o])=>{const y=j.trim();if(typeof o=="function"&&(o=o()),typeof o=="object"){if(!o)return a;if(y==="variants")return Object.entries(o).forEach(([f,i])=>{i&&Object.entries(i).forEach(([h,p])=>{if(!p)return;const P=`${e}.${f}-${h}`,C=T(p,P);r.push(C)})}),a;if(y==="defaultVariants")return a;if(y==="compoundVariants")return o.forEach(f=>{const{css:i,...h}=f,p=Object.entries(h).reduce((C,[S,x])=>`${C}.${S}-${x}`,e),P=T(i,p);r.push(P)}),a;if(y.startsWith("@")){const f=T(o,e),i=`${y} {
2
+ ${f.replace(`
3
3
  `,`
4
4
  `)}
5
- }`;return o.push(p),a}const h=c.includes("&")?f.replace("&",e):f.startsWith(":")?`${e}${f}`:`${e} ${f}`,C=M(r,h);return o.push(C),a}const x=f.startsWith("-")?f:D(f),b=(h,C=";")=>a=`${a}${h}${C}`,l=h=>b(`${x}:${h}`);if(typeof r=="number")return l(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return a;const{modifiers:S}={},k=function*(){yield z(r),yield rt(r,S)}();for(const{result:h,additionalCss:C=[]}of k)r=h,C.forEach(i=>{const p=M(i,"");b(p,"")});return l(r)},"");if(!y)return o.join(`
6
- `);if(!e)return y;let g="";return g=`${e} { ${y} }`,[g,...o].join(`
7
- `)},U=(t,e=[])=>{if(!t)return"";const s=[],n={};if(Object.entries(t).forEach(([o,y])=>{if(typeof y=="object"){if(!y)return;const g=o.trim(),a=U(y,[...e,g]);s.push(a)}else n[o]=y}),Object.keys(n).length){const o=e.map(D).join("-"),y=M(n,`.${o}`);s.push(y)}return s.join(`
8
- `)},H=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=u.join(t,"package.json");return d.existsSync(e)?e:H(u.join(t,".."))},it=async t=>{const e=H(t);return await B.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},ct=async t=>{const e=await it(t);if(e)return e.type};let O;const L=async t=>{if(O)return O;const e=await ct(t);return e==="module"?O="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:_&&_.tagName.toUpperCase()==="SCRIPT"&&_.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(O="cjs"),O||"esm"},J={externalModules:[]},K=t=>{if(J.externalModules.length>0)return J.externalModules;const e=u.join(t,"salty.config.ts"),n=d.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!n)return[];const o=n[1].split(",").map(y=>y.replace(/['"`]/g,"").trim());return J.externalModules=o,o},V=t=>u.join(t,"./saltygen"),at=["salty","css","styles","styled"],lt=(t=[])=>new RegExp(`\\.(${[...at,...t].join("|")})\\.`),E=(t,e=[])=>lt(e).test(t),ut=async t=>{const e=V(t),s=u.join(t,"salty.config.ts"),n=u.join(e,"salty.config.js"),o=await L(t),y=K(t);await Z.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:o,external:y});const g=Date.now(),{config:a}=await import(`${n}?t=${g}`);return a},G=async t=>{const e=await ut(t),s=new Set,n=(i,p=[])=>i?Object.entries(i).flatMap(([j,m])=>{if(!m)return;if(typeof m=="object")return n(m,[...p,j]);const F=[...p,j].join(".");s.add(`"${F}"`);const $=[...p.map(D),D(j)].join("-"),{result:w}=z(m);return`--${$}: ${w};`}):[],o=i=>i?Object.entries(i).flatMap(([p,j])=>{const m=n(j);return p==="base"?m.join(""):`${p} { ${m.join("")} }`}):[],y=i=>i?Object.entries(i).flatMap(([p,j])=>Object.entries(j).flatMap(([m,F])=>{const $=n(F,[p]),w=`.${p}-${m}, [data-${p}="${m}"]`,T=$.join("");return`${w} { ${T} }`})):[],g=n(e.variables),a=o(e.responsiveVariables),c=y(e.conditionalVariables),r=V(t),f=u.join(r,"css/variables.css"),x=`:root { ${g.join("")} ${a.join("")} } ${c.join("")}`;d.writeFileSync(f,x);const b=u.join(r,"types/css-tokens.d.ts"),S=`type VariableTokens = ${[...s].join("|")||'""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;d.writeFileSync(b,S);const P=u.join(r,"css/global.css"),k=M(e.global,"");d.writeFileSync(P,k);const h=u.join(r,"css/templates.css"),C=U(e.templates);d.writeFileSync(h,C)},A=async(t,e,s)=>{const n=R(e),o=u.join(s,"js",n+".js"),y=await L(t),g=K(t);await Z.build({entryPoints:[e],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:y,target:["es2022"],keepNames:!0,external:g});const a=Date.now();return await import(`${o}?t=${a}`)},q=async t=>{const e=V(t),s=u.join(e,"salty.config.js"),{config:n}=await import(s);return n},ft=async t=>{try{const e=[],s=[],n=V(t),o=u.join(n,"index.css");(()=>{d.existsSync(n)&&et.execSync("rm -rf "+n),d.mkdirSync(n),d.mkdirSync(u.join(n,"css")),d.mkdirSync(u.join(n,"types"))})(),await G(t);const g=await q(t);async function a(l,S){const P=["node_modules","saltygen"],k=d.statSync(l);if(k.isDirectory()){const h=d.readdirSync(l);if(P.some(i=>l.includes(i)))return;await Promise.all(h.map(i=>a(u.join(l,i),u.join(S,i))))}else if(k.isFile()&&E(l)){const C=await A(t,l,n),i=[];Object.entries(C).forEach(([F,$])=>{if($.isKeyframes&&$.css){const I=`${$.animationName}.css`,Q=`css/${I}`,v=u.join(n,Q);e.push(I),d.writeFileSync(v,$.css);return}if(!$.generator)return;const w=$.generator._withBuildContext({name:F,config:g}),T=`${w.hash}-${w.priority}.css`;s[w.priority]||(s[w.priority]=[]),s[w.priority].push(T),i.push(T);const N=`css/${T}`,Y=u.join(n,N);d.writeFileSync(Y,w.css)});const p=i.map(F=>`@import url('./${F}');`).join(`
9
- `),j=R(l,6),m=u.join(n,`css/${j}.css`);d.writeFileSync(m,p)}}await a(t,n);const c=e.map(l=>`@import url('./css/${l}');`).join(`
10
- `);let b=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
5
+ }`;return r.push(i),a}const g=j.includes("&")?y.replace("&",e):y.startsWith(":")?`${e}${y}`:`${e} ${y}`,b=T(o,g);return r.push(b),a}const $=y.startsWith("-")?y:E(y),w=(g,b=";")=>a=`${a}${g}${b}`,k=g=>w(`${$}:${g}`);if(typeof o=="number")return k(o);if(typeof o!="string")if("toString"in o)o=o.toString();else return a;const{modifiers:l}={},O=function*(){yield G(o),yield lt(o,l)}();for(const{result:g,additionalCss:b=[]}of O)o=g,b.forEach(f=>{const i=T(f,"");w(i,"")});return k(o)},"");if(!c)return r.join(`
6
+ `);if(!e)return c;let m="";return m=`${e} { ${c} }`,[m,...r].join(`
7
+ `)},H=(t,e=[])=>{if(!t)return"";const s=[],n={};if(Object.entries(t).forEach(([r,c])=>{if(typeof c=="object"){if(!c)return;const m=r.trim(),a=H(c,[...e,m]);s.push(a)}else n[r]=c}),Object.keys(n).length){const r=e.map(E).join("-"),c=T(n,`.${r}`);s.push(c)}return s.join(`
8
+ `)},K=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=u.join(t,"package.json");return d.existsSync(e)?e:K(u.join(t,".."))},ut=async t=>{const e=K(t);return await L.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},ft=async t=>{const e=await ut(t);if(e)return e.type};let D;const X=async t=>{if(D)return D;const e=await ft(t);return e==="module"?D="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:R&&R.tagName.toUpperCase()==="SCRIPT"&&R.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(D="cjs"),D||"esm"},Z=V.createLogger({level:"debug",format:V.format.combine(V.format.colorize(),V.format.cli()),transports:[new V.transports.Console({})]}),A={externalModules:[]},Y=t=>{if(A.externalModules.length>0)return A.externalModules;const e=u.join(t,"salty.config.ts"),n=d.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!n)return[];const r=n[1].split(",").map(c=>c.replace(/['"`]/g,"").trim());return A.externalModules=r,r},J=t=>u.join(t,"./saltygen"),pt=["salty","css","styles","styled"],dt=(t=[])=>new RegExp(`\\.(${[...pt,...t].join("|")})\\.`),_=(t,e=[])=>dt(e).test(t),yt=async t=>{const e=J(t),s=u.join(t,"salty.config.ts"),n=u.join(e,"salty.config.js"),r=await X(t),c=Y(t);await U.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:r,external:c});const m=Date.now(),{config:a}=await import(`${n}?t=${m}`);return a},Q=async t=>{const e=await yt(t),s=new Set,n=(f,i=[])=>f?Object.entries(f).flatMap(([h,p])=>{if(!p)return;if(typeof p=="object")return n(p,[...i,h]);const P=[...i,h].join(".");s.add(`"${P}"`);const C=[...i.map(E),E(h)].join("-"),{result:S}=G(p);return`--${C}: ${S};`}):[],r=f=>f?Object.entries(f).flatMap(([i,h])=>{const p=n(h);return i==="base"?p.join(""):`${i} { ${p.join("")} }`}):[],c=f=>f?Object.entries(f).flatMap(([i,h])=>Object.entries(h).flatMap(([p,P])=>{const C=n(P,[i]),S=`.${i}-${p}, [data-${i}="${p}"]`,x=C.join("");return`${S} { ${x} }`})):[],m=n(e.variables),a=r(e.responsiveVariables),j=c(e.conditionalVariables),o=J(t),y=u.join(o,"css/variables.css"),$=`:root { ${m.join("")} ${a.join("")} } ${j.join("")}`;d.writeFileSync(y,$);const w=u.join(o,"types/css-tokens.d.ts"),l=`type VariableTokens = ${[...s].join("|")||'""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;d.writeFileSync(w,l);const F=u.join(o,"css/global.css"),O=T(e.global,"");d.writeFileSync(F,O);const g=u.join(o,"css/templates.css"),b=H(e.templates);d.writeFileSync(g,b)},I=async(t,e,s)=>{const n=q(e),r=u.join(s,"js",n+".js"),c=await X(t),m=Y(t);await U.build({entryPoints:[e],minify:!0,treeShaking:!0,bundle:!0,outfile:r,format:c,target:["es2022"],keepNames:!0,external:m});const a=Date.now();return await import(`${r}?t=${a}`)},W=async t=>{const e=J(t),s=u.join(e,"salty.config.js"),{config:n}=await import(s);return n},v=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},gt=async(t,e=v())=>{try{e?Z.info("Generating CSS in production mode! 🔥"):Z.info("Generating CSS in development mode! 🚀");const s=[],n=[],r=J(t),c=u.join(r,"index.css");(()=>{d.existsSync(r)&&rt.execSync("rm -rf "+r),d.mkdirSync(r),d.mkdirSync(u.join(r,"css")),d.mkdirSync(u.join(r,"types"))})(),await Q(t);const a=await W(t);async function j(l,F){const O=["node_modules","saltygen"],g=d.statSync(l);if(g.isDirectory()){const b=d.readdirSync(l);if(O.some(i=>l.includes(i)))return;await Promise.all(b.map(i=>j(u.join(l,i),u.join(F,i))))}else if(g.isFile()&&_(l)){const f=await I(t,l,r),i=[];Object.entries(f).forEach(([C,S])=>{if(S.isKeyframes&&S.css){const z=`${S.animationName}.css`,st=`css/${z}`,nt=u.join(r,st);s.push(z),d.writeFileSync(nt,S.css);return}if(!S.generator)return;const x=S.generator._withBuildContext({name:C,config:a,prod:e}),M=`${x.hash}-${x.priority}.css`;n[x.priority]||(n[x.priority]=[]),n[x.priority].push(M),i.push(M);const N=`css/${M}`,et=u.join(r,N);d.writeFileSync(et,x.css)});const h=i.map(C=>`@import url('./${C}');`).join(`
9
+ `),p=q(l,6),P=u.join(r,`css/${p}.css`);d.writeFileSync(P,h)}}await j(t,r);const o=s.map(l=>`@import url('./css/${l}');`).join(`
10
+ `);let k=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
11
11
 
12
- ${["variables.css","global.css","templates.css"].filter(l=>{try{return d.readFileSync(u.join(n,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
12
+ ${["variables.css","global.css","templates.css"].filter(l=>{try{return d.readFileSync(u.join(r,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
13
13
  `)}
14
- ${c}`;if(g.importStrategy!=="component"){const l=s.flat().map(S=>`@import url('./css/${S}');`).join(`
15
- `);b+=l}d.writeFileSync(o,b)}catch(e){console.error(e)}},pt=async(t,e)=>{try{const s=[],n=u.join(t,"./saltygen"),o=u.join(n,"index.css");if(E(e)){const g=await q(t),a=await A(t,e,n);Object.entries(a).forEach(([b,l])=>{if(!l.generator)return;const S=l.generator._withBuildContext({name:b,config:g}),P=`${S.hash}-${S.priority}.css`,k=`css/${P}`,h=u.join(n,k);s.push(P),d.writeFileSync(h,S.css)});const c=d.readFileSync(o,"utf8").split(`
16
- `),r=s.map(b=>`@import url('../saltygen/css/${b}');`),x=[...new Set([...c,...r])].join(`
17
- `);d.writeFileSync(o,x)}}catch(s){console.error(s)}},yt=async(t,e)=>{try{const s=u.join(t,"./saltygen");if(E(e)){const o=d.readFileSync(e,"utf8");o.replace(/^(?!export\s)const\s.*/gm,f=>`export ${f}`)!==o&&await B.writeFile(e,o);const g=await q(t),a=await A(t,e,s);let c=o;Object.entries(a).forEach(([f,x])=>{var T;if(x.isKeyframes||!x.generator)return;const b=x.generator._withBuildContext({name:f,config:g}),l=new RegExp(`\\s${f}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(o);if(!l)return console.error("Could not find the original declaration");const S=(T=l.at(1))==null?void 0:T.trim(),P=new RegExp(`\\s${f}[=\\s]+styled\\(`,"g").exec(c);if(!P)return console.error("Could not find the original declaration");const{index:k}=P;let h=!1;const C=setTimeout(()=>h=!0,5e3);let i=0,p=!1,j=0;for(;!p&&!h;){const N=c[k+i];N==="("&&j++,N===")"&&j--,j===0&&N===")"&&(p=!0),i>c.length&&(h=!0),i++}if(!h)clearTimeout(C);else throw new Error("Failed to find the end of the styled call and timed out");const m=k+i,F=c.slice(k,m),$=c,w=` ${f} = styled(${S}, "${b.classNames}", "${b._callerName}", ${JSON.stringify(b.props)});`;c=c.replace(F,w),$===c&&console.error("Minimize file failed to change content",{name:f,tagName:S})});const r=R(e,6);return g.importStrategy==="component"&&(c=`import '../../saltygen/css/${r}.css';
18
- ${c}`),c=c.replace("{ styled }","{ styledClient as styled }"),c=c.replace("@salty-css/react/styled","@salty-css/react/styled-client"),c}}catch(s){console.error("Error in minimizeFile:",s)}},X=t=>({name:"stylegen",buildStart:()=>ft(t),load:async e=>{if(E(e))return await yt(t,e)},watchChange:{handler:async e=>{E(e)&&await pt(t,e),e.includes("salty.config")&&await G(t)}}});exports.default=X;exports.saltyPlugin=X;
14
+ ${o}`;if(a.importStrategy!=="component"){const l=n.flat().map(F=>`@import url('./css/${F}');`).join(`
15
+ `);k+=l}d.writeFileSync(c,k)}catch(s){console.error(s)}},mt=async(t,e)=>{try{const s=[],n=u.join(t,"./saltygen"),r=u.join(n,"index.css");if(_(e)){const m=await W(t),a=await I(t,e,n);Object.entries(a).forEach(([w,k])=>{if(!k.generator)return;const l=k.generator._withBuildContext({name:w,config:m}),F=`${l.hash}-${l.priority}.css`,O=`css/${F}`,g=u.join(n,O);s.push(F),d.writeFileSync(g,l.css)});const j=d.readFileSync(r,"utf8").split(`
16
+ `),o=s.map(w=>`@import url('../saltygen/css/${w}');`),$=[...new Set([...j,...o])].join(`
17
+ `);d.writeFileSync(r,$)}}catch(s){console.error(s)}},ht=async(t,e,s=v())=>{try{const n=u.join(t,"./saltygen");if(_(e)){const c=d.readFileSync(e,"utf8");c.replace(/^(?!export\s)const\s.*/gm,$=>`export ${$}`)!==c&&await L.writeFile(e,c);const a=await W(t),j=await I(t,e,n);let o=c;Object.entries(j).forEach(([$,w])=>{var M;if(w.isKeyframes||!w.generator)return;const k=w.generator._withBuildContext({name:$,config:a,prod:s}),l=new RegExp(`\\s${$}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(c);if(!l)return console.error("Could not find the original declaration");const F=(M=l.at(1))==null?void 0:M.trim(),O=new RegExp(`\\s${$}[=\\s]+styled\\(`,"g").exec(o);if(!O)return console.error("Could not find the original declaration");const{index:g}=O;let b=!1;const f=setTimeout(()=>b=!0,5e3);let i=0,h=!1,p=0;for(;!h&&!b;){const N=o[g+i];N==="("&&p++,N===")"&&p--,p===0&&N===")"&&(h=!0),i>o.length&&(b=!0),i++}if(!b)clearTimeout(f);else throw new Error("Failed to find the end of the styled call and timed out");const P=g+i,C=o.slice(g,P),S=o,x=` ${$} = styled(${F}, "${k.classNames}", ${JSON.stringify(k.props)});`;o=o.replace(C,x),S===o&&console.error("Minimize file failed to change content",{name:$,tagName:F})});const y=q(e,6);return a.importStrategy==="component"&&(o=`import '../../saltygen/css/${y}.css';
18
+ ${o}`),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)}},tt=t=>({name:"stylegen",buildStart:()=>gt(t),load:async e=>{if(_(e))return await ht(t,e)},watchChange:{handler:async e=>{_(e)&&await mt(t,e),e.includes("salty.config")&&await Q(t)}}});exports.default=tt;exports.saltyPlugin=tt;
package/index.js CHANGED
@@ -1,313 +1,327 @@
1
- import * as z from "esbuild";
2
- import { execSync as tt } from "child_process";
1
+ import * as K from "esbuild";
2
+ import { execSync as ot } from "child_process";
3
3
  import { join as f } from "path";
4
- import { existsSync as H, writeFileSync as M, mkdirSync as A, statSync as st, readdirSync as et, readFileSync as V } from "fs";
5
- import { readFile as nt, writeFile as ot } from "fs/promises";
6
- const Z = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), rt = (t, s) => {
7
- let e = "", n;
8
- for (n = Math.abs(t); n > 52; n = n / 52 | 0) e = Z(n % 52) + e;
9
- return e = Z(n % 52) + e, e.length < s ? e = e.padStart(s, "a") : e.length > s && (e = e.slice(-s)), e;
10
- }, ct = (t, s) => {
11
- let e = s.length;
12
- for (; e; ) t = t * 33 ^ s.charCodeAt(--e);
4
+ import { existsSync as L, writeFileSync as E, mkdirSync as R, statSync as rt, readdirSync as ct, readFileSync as J } from "fs";
5
+ import { readFile as it, writeFile as at } from "fs/promises";
6
+ import { createLogger as lt, format as _, transports as ft } from "winston";
7
+ const G = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), ut = (t, e) => {
8
+ let s = "", o;
9
+ for (o = Math.abs(t); o > 52; o = o / 52 | 0) s = G(o % 52) + s;
10
+ return s = G(o % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
11
+ }, pt = (t, e) => {
12
+ let s = e.length;
13
+ for (; s; ) t = t * 33 ^ e.charCodeAt(--s);
13
14
  return t;
14
- }, _ = (t, s = 3) => {
15
- const e = ct(5381, JSON.stringify(t)) >>> 0;
16
- return rt(e, s);
15
+ }, B = (t, e = 3) => {
16
+ const s = pt(5381, JSON.stringify(t)) >>> 0;
17
+ return ut(s, e);
17
18
  };
18
- function E(t) {
19
- return t ? typeof t != "string" ? E(String(t)) : t.replace(/\s/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (s, e) => (e > 0 ? "-" : "") + s.toLowerCase()) : "";
19
+ function N(t) {
20
+ return t ? typeof t != "string" ? N(String(t)) : t.replace(/\s/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "-" : "") + e.toLowerCase()) : "";
20
21
  }
21
- const it = (t, s) => {
22
+ const gt = (t, e) => {
22
23
  if (typeof t != "string") return { result: t };
23
- if (!s) return { result: t };
24
- const e = [];
25
- return Object.values(s).forEach((n) => {
26
- const { pattern: o, transform: g } = n;
27
- t = t.replace(o, (y) => {
28
- const { value: a, css: i } = g(y);
29
- return i && e.push(i), a;
24
+ if (!e) return { result: t };
25
+ const s = [];
26
+ return Object.values(e).forEach((o) => {
27
+ const { pattern: r, transform: i } = o;
28
+ t = t.replace(r, (d) => {
29
+ const { value: a, css: h } = i(d);
30
+ return h && s.push(h), a;
30
31
  });
31
- }), { result: t, additionalCss: e };
32
- }, K = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${E(n[1].replaceAll(".", "-"))})`) } : { result: t }, T = (t, s, e, n) => {
32
+ }), { result: t, additionalCss: s };
33
+ }, q = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...o) => `var(--${N(o[1].replaceAll(".", "-"))})`) } : { result: t }, D = (t, e, s, o) => {
33
34
  if (!t) return "";
34
- const o = [], g = Object.entries(t).reduce((a, [i, r]) => {
35
- const u = i.trim();
36
- if (typeof r == "function" && (r = r()), typeof r == "object") {
37
- if (!r) return a;
38
- if (u === "variants")
39
- return Object.entries(r).forEach(([c, p]) => {
40
- p && Object.entries(p).forEach(([m, h]) => {
41
- if (!h) return;
42
- const S = `${s}.${c}-${m}`, $ = T(h, S);
43
- o.push($);
35
+ const r = [], i = Object.entries(t).reduce((a, [h, n]) => {
36
+ const g = h.trim();
37
+ if (typeof n == "function" && (n = n()), typeof n == "object") {
38
+ if (!n) return a;
39
+ if (g === "variants")
40
+ return Object.entries(n).forEach(([u, c]) => {
41
+ c && Object.entries(c).forEach(([m, p]) => {
42
+ if (!p) return;
43
+ const x = `${e}.${u}-${m}`, F = D(p, x);
44
+ r.push(F);
44
45
  });
45
46
  }), a;
46
- if (u === "defaultVariants")
47
+ if (g === "defaultVariants")
47
48
  return a;
48
- if (u === "compoundVariants")
49
- return r.forEach((c) => {
50
- const { css: p, ...m } = c, h = Object.entries(m).reduce(($, [j, P]) => `${$}.${j}-${P}`, s), S = T(p, h);
51
- o.push(S);
49
+ if (g === "compoundVariants")
50
+ return n.forEach((u) => {
51
+ const { css: c, ...m } = u, p = Object.entries(m).reduce((F, [w, k]) => `${F}.${w}-${k}`, e), x = D(c, p);
52
+ r.push(x);
52
53
  }), a;
53
- if (u.startsWith("@")) {
54
- const c = T(r, s), p = `${u} {
55
- ${c.replace(`
54
+ if (g.startsWith("@")) {
55
+ const u = D(n, e), c = `${g} {
56
+ ${u.replace(`
56
57
  `, `
57
58
  `)}
58
59
  }`;
59
- return o.push(p), a;
60
+ return r.push(c), a;
60
61
  }
61
- const d = i.includes("&") ? u.replace("&", s) : u.startsWith(":") ? `${s}${u}` : `${s} ${u}`, k = T(r, d);
62
- return o.push(k), a;
62
+ const y = h.includes("&") ? g.replace("&", e) : g.startsWith(":") ? `${e}${g}` : `${e} ${g}`, $ = D(n, y);
63
+ return r.push($), a;
63
64
  }
64
- const x = u.startsWith("-") ? u : E(u), b = (d, k = ";") => a = `${a}${d}${k}`, l = (d) => b(`${x}:${d}`);
65
- if (typeof r == "number") return l(r);
66
- if (typeof r != "string")
67
- if ("toString" in r) r = r.toString();
65
+ const b = g.startsWith("-") ? g : N(g), S = (y, $ = ";") => a = `${a}${y}${$}`, C = (y) => S(`${b}:${y}`);
66
+ if (typeof n == "number") return C(n);
67
+ if (typeof n != "string")
68
+ if ("toString" in n) n = n.toString();
68
69
  else return a;
69
- const { modifiers: w } = {}, F = function* () {
70
- yield K(r), yield it(r, w);
70
+ const { modifiers: l } = {}, P = function* () {
71
+ yield q(n), yield gt(n, l);
71
72
  }();
72
- for (const { result: d, additionalCss: k = [] } of F)
73
- r = d, k.forEach((c) => {
74
- const p = T(c, "");
75
- b(p, "");
73
+ for (const { result: y, additionalCss: $ = [] } of P)
74
+ n = y, $.forEach((u) => {
75
+ const c = D(u, "");
76
+ S(c, "");
76
77
  });
77
- return l(r);
78
+ return C(n);
78
79
  }, "");
79
- if (!g) return o.join(`
80
+ if (!i) return r.join(`
80
81
  `);
81
- if (!s) return g;
82
- let y = "";
83
- return y = `${s} { ${g} }`, [y, ...o].join(`
82
+ if (!e) return i;
83
+ let d = "";
84
+ return d = `${e} { ${i} }`, [d, ...r].join(`
84
85
  `);
85
- }, q = (t, s = []) => {
86
+ }, U = (t, e = []) => {
86
87
  if (!t) return "";
87
- const e = [], n = {};
88
- if (Object.entries(t).forEach(([o, g]) => {
89
- if (typeof g == "object") {
90
- if (!g) return;
91
- const y = o.trim(), a = q(g, [...s, y]);
92
- e.push(a);
88
+ const s = [], o = {};
89
+ if (Object.entries(t).forEach(([r, i]) => {
90
+ if (typeof i == "object") {
91
+ if (!i) return;
92
+ const d = r.trim(), a = U(i, [...e, d]);
93
+ s.push(a);
93
94
  } else
94
- n[o] = g;
95
- }), Object.keys(n).length) {
96
- const o = s.map(E).join("-"), g = T(n, `.${o}`);
97
- e.push(g);
95
+ o[r] = i;
96
+ }), Object.keys(o).length) {
97
+ const r = e.map(N).join("-"), i = D(o, `.${r}`);
98
+ s.push(i);
98
99
  }
99
- return e.join(`
100
+ return s.join(`
100
101
  `);
101
- }, G = (t) => {
102
+ }, X = (t) => {
102
103
  if (!t || t === "/") throw new Error("Could not find package.json file");
103
- const s = f(t, "package.json");
104
- return H(s) ? s : G(f(t, ".."));
105
- }, at = async (t) => {
106
- const s = G(t);
107
- return await nt(s, "utf-8").then(JSON.parse).catch(() => {
104
+ const e = f(t, "package.json");
105
+ return L(e) ? e : X(f(t, ".."));
106
+ }, yt = async (t) => {
107
+ const e = X(t);
108
+ return await it(e, "utf-8").then(JSON.parse).catch(() => {
108
109
  });
109
- }, lt = async (t) => {
110
- const s = await at(t);
111
- if (s)
112
- return s.type;
110
+ }, dt = async (t) => {
111
+ const e = await yt(t);
112
+ if (e)
113
+ return e.type;
113
114
  };
114
- let D;
115
- const L = async (t) => {
116
- if (D) return D;
117
- const s = await lt(t);
118
- return s === "module" ? D = "esm" : (s === "commonjs" || import.meta.url.endsWith(".cjs")) && (D = "cjs"), D || "esm";
119
- }, R = {
115
+ let T;
116
+ const Y = async (t) => {
117
+ if (T) return T;
118
+ const e = await dt(t);
119
+ return e === "module" ? T = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (T = "cjs"), T || "esm";
120
+ }, H = lt({
121
+ level: "debug",
122
+ format: _.combine(_.colorize(), _.cli()),
123
+ transports: [new ft.Console({})]
124
+ }), W = {
120
125
  externalModules: []
121
- }, U = (t) => {
122
- if (R.externalModules.length > 0) return R.externalModules;
123
- const s = f(t, "salty.config.ts"), n = V(s, "utf8").match(/externalModules:\s?\[(.*)\]/);
124
- if (!n) return [];
125
- const o = n[1].split(",").map((g) => g.replace(/['"`]/g, "").trim());
126
- return R.externalModules = o, o;
127
- }, J = (t) => f(t, "./saltygen"), ft = ["salty", "css", "styles", "styled"], ut = (t = []) => new RegExp(`\\.(${[...ft, ...t].join("|")})\\.`), O = (t, s = []) => ut(s).test(t), pt = async (t) => {
128
- const s = J(t), e = f(t, "salty.config.ts"), n = f(s, "salty.config.js"), o = await L(t), g = U(t);
129
- await z.build({
130
- entryPoints: [e],
126
+ }, Q = (t) => {
127
+ if (W.externalModules.length > 0) return W.externalModules;
128
+ const e = f(t, "salty.config.ts"), o = J(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
129
+ if (!o) return [];
130
+ const r = o[1].split(",").map((i) => i.replace(/['"`]/g, "").trim());
131
+ return W.externalModules = r, r;
132
+ }, A = (t) => f(t, "./saltygen"), mt = ["salty", "css", "styles", "styled"], ht = (t = []) => new RegExp(`\\.(${[...mt, ...t].join("|")})\\.`), V = (t, e = []) => ht(e).test(t), $t = async (t) => {
133
+ const e = A(t), s = f(t, "salty.config.ts"), o = f(e, "salty.config.js"), r = await Y(t), i = Q(t);
134
+ await K.build({
135
+ entryPoints: [s],
131
136
  minify: !0,
132
137
  treeShaking: !0,
133
138
  bundle: !0,
134
- outfile: n,
135
- format: o,
136
- external: g
139
+ outfile: o,
140
+ format: r,
141
+ external: i
137
142
  });
138
- const y = Date.now(), { config: a } = await import(`${n}?t=${y}`);
143
+ const d = Date.now(), { config: a } = await import(`${o}?t=${d}`);
139
144
  return a;
140
- }, X = async (t) => {
141
- const s = await pt(t), e = /* @__PURE__ */ new Set(), n = (c, p = []) => c ? Object.entries(c).flatMap(([m, h]) => {
142
- if (!h) return;
143
- if (typeof h == "object") return n(h, [...p, m]);
144
- const S = [...p, m].join(".");
145
- e.add(`"${S}"`);
146
- const $ = [...p.map(E), E(m)].join("-"), { result: j } = K(h);
147
- return `--${$}: ${j};`;
148
- }) : [], o = (c) => c ? Object.entries(c).flatMap(([p, m]) => {
149
- const h = n(m);
150
- return p === "base" ? h.join("") : `${p} { ${h.join("")} }`;
151
- }) : [], g = (c) => c ? Object.entries(c).flatMap(([p, m]) => Object.entries(m).flatMap(([h, S]) => {
152
- const $ = n(S, [p]), j = `.${p}-${h}, [data-${p}="${h}"]`, P = $.join("");
153
- return `${j} { ${P} }`;
154
- })) : [], y = n(s.variables), a = o(s.responsiveVariables), i = g(s.conditionalVariables), r = J(t), u = f(r, "css/variables.css"), x = `:root { ${y.join("")} ${a.join("")} } ${i.join("")}`;
155
- M(u, x);
156
- const b = f(r, "types/css-tokens.d.ts"), w = `type VariableTokens = ${[...e].join("|") || '""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;
157
- M(b, w);
158
- const C = f(r, "css/global.css"), F = T(s.global, "");
159
- M(C, F);
160
- const d = f(r, "css/templates.css"), k = q(s.templates);
161
- M(d, k);
162
- }, W = async (t, s, e) => {
163
- const n = _(s), o = f(e, "js", n + ".js"), g = await L(t), y = U(t);
164
- await z.build({
165
- entryPoints: [s],
145
+ }, v = async (t) => {
146
+ const e = await $t(t), s = /* @__PURE__ */ new Set(), o = (u, c = []) => u ? Object.entries(u).flatMap(([m, p]) => {
147
+ if (!p) return;
148
+ if (typeof p == "object") return o(p, [...c, m]);
149
+ const x = [...c, m].join(".");
150
+ s.add(`"${x}"`);
151
+ const F = [...c.map(N), N(m)].join("-"), { result: w } = q(p);
152
+ return `--${F}: ${w};`;
153
+ }) : [], r = (u) => u ? Object.entries(u).flatMap(([c, m]) => {
154
+ const p = o(m);
155
+ return c === "base" ? p.join("") : `${c} { ${p.join("")} }`;
156
+ }) : [], i = (u) => u ? Object.entries(u).flatMap(([c, m]) => Object.entries(m).flatMap(([p, x]) => {
157
+ const F = o(x, [c]), w = `.${c}-${p}, [data-${c}="${p}"]`, k = F.join("");
158
+ return `${w} { ${k} }`;
159
+ })) : [], d = o(e.variables), a = r(e.responsiveVariables), h = i(e.conditionalVariables), n = A(t), g = f(n, "css/variables.css"), b = `:root { ${d.join("")} ${a.join("")} } ${h.join("")}`;
160
+ E(g, b);
161
+ const S = f(n, "types/css-tokens.d.ts"), l = `type VariableTokens = ${[...s].join("|") || '""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;
162
+ E(S, l);
163
+ const j = f(n, "css/global.css"), P = D(e.global, "");
164
+ E(j, P);
165
+ const y = f(n, "css/templates.css"), $ = U(e.templates);
166
+ E(y, $);
167
+ }, I = async (t, e, s) => {
168
+ const o = B(e), r = f(s, "js", o + ".js"), i = await Y(t), d = Q(t);
169
+ await K.build({
170
+ entryPoints: [e],
166
171
  minify: !0,
167
172
  treeShaking: !0,
168
173
  bundle: !0,
169
- outfile: o,
170
- format: g,
174
+ outfile: r,
175
+ format: i,
171
176
  target: ["es2022"],
172
177
  keepNames: !0,
173
- external: y
178
+ external: d
174
179
  });
175
180
  const a = Date.now();
176
- return await import(`${o}?t=${a}`);
177
- }, B = async (t) => {
178
- const s = J(t), e = f(s, "salty.config.js"), { config: n } = await import(e);
179
- return n;
180
- }, gt = async (t) => {
181
+ return await import(`${r}?t=${a}`);
182
+ }, Z = async (t) => {
183
+ const e = A(t), s = f(e, "salty.config.js"), { config: o } = await import(s);
184
+ return o;
185
+ }, tt = () => {
181
186
  try {
182
- const s = [], e = [], n = J(t), o = f(n, "index.css");
187
+ return process.env.NODE_ENV === "production";
188
+ } catch {
189
+ return !1;
190
+ }
191
+ }, bt = async (t, e = tt()) => {
192
+ try {
193
+ e ? H.info("Generating CSS in production mode! 🔥") : H.info("Generating CSS in development mode! 🚀");
194
+ const s = [], o = [], r = A(t), i = f(r, "index.css");
183
195
  (() => {
184
- H(n) && tt("rm -rf " + n), A(n), A(f(n, "css")), A(f(n, "types"));
185
- })(), await X(t);
186
- const y = await B(t);
187
- async function a(l, w) {
188
- const C = ["node_modules", "saltygen"], F = st(l);
189
- if (F.isDirectory()) {
190
- const d = et(l);
191
- if (C.some((c) => l.includes(c))) return;
192
- await Promise.all(d.map((c) => a(f(l, c), f(w, c))));
193
- } else if (F.isFile() && O(l)) {
194
- const k = await W(t, l, n), c = [];
195
- Object.entries(k).forEach(([S, $]) => {
196
- if ($.isKeyframes && $.css) {
197
- const I = `${$.animationName}.css`, Q = `css/${I}`, v = f(n, Q);
198
- s.push(I), M(v, $.css);
196
+ L(r) && ot("rm -rf " + r), R(r), R(f(r, "css")), R(f(r, "types"));
197
+ })(), await v(t);
198
+ const a = await Z(t);
199
+ async function h(l, j) {
200
+ const P = ["node_modules", "saltygen"], y = rt(l);
201
+ if (y.isDirectory()) {
202
+ const $ = ct(l);
203
+ if (P.some((c) => l.includes(c))) return;
204
+ await Promise.all($.map((c) => h(f(l, c), f(j, c))));
205
+ } else if (y.isFile() && V(l)) {
206
+ const u = await I(t, l, r), c = [];
207
+ Object.entries(u).forEach(([F, w]) => {
208
+ if (w.isKeyframes && w.css) {
209
+ const z = `${w.animationName}.css`, st = `css/${z}`, nt = f(r, st);
210
+ s.push(z), E(nt, w.css);
199
211
  return;
200
212
  }
201
- if (!$.generator) return;
202
- const j = $.generator._withBuildContext({
203
- name: S,
204
- config: y
205
- }), P = `${j.hash}-${j.priority}.css`;
206
- e[j.priority] || (e[j.priority] = []), e[j.priority].push(P), c.push(P);
207
- const N = `css/${P}`, Y = f(n, N);
208
- M(Y, j.css);
213
+ if (!w.generator) return;
214
+ const k = w.generator._withBuildContext({
215
+ name: F,
216
+ config: a,
217
+ prod: e
218
+ }), M = `${k.hash}-${k.priority}.css`;
219
+ o[k.priority] || (o[k.priority] = []), o[k.priority].push(M), c.push(M);
220
+ const O = `css/${M}`, et = f(r, O);
221
+ E(et, k.css);
209
222
  });
210
- const p = c.map((S) => `@import url('./${S}');`).join(`
211
- `), m = _(l, 6), h = f(n, `css/${m}.css`);
212
- M(h, p);
223
+ const m = c.map((F) => `@import url('./${F}');`).join(`
224
+ `), p = B(l, 6), x = f(r, `css/${p}.css`);
225
+ E(x, m);
213
226
  }
214
227
  }
215
- await a(t, n);
216
- const i = s.map((l) => `@import url('./css/${l}');`).join(`
228
+ await h(t, r);
229
+ const n = s.map((l) => `@import url('./css/${l}');`).join(`
217
230
  `);
218
- let b = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
231
+ let C = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
219
232
 
220
233
  ${["variables.css", "global.css", "templates.css"].filter((l) => {
221
234
  try {
222
- return V(f(n, "css", l), "utf8").length > 0;
235
+ return J(f(r, "css", l), "utf8").length > 0;
223
236
  } catch {
224
237
  return !1;
225
238
  }
226
239
  }).map((l) => `@import url('./css/${l}');`).join(`
227
240
  `)}
228
- ${i}`;
229
- if (y.importStrategy !== "component") {
230
- const l = e.flat().map((w) => `@import url('./css/${w}');`).join(`
241
+ ${n}`;
242
+ if (a.importStrategy !== "component") {
243
+ const l = o.flat().map((j) => `@import url('./css/${j}');`).join(`
231
244
  `);
232
- b += l;
245
+ C += l;
233
246
  }
234
- M(o, b);
247
+ E(i, C);
235
248
  } catch (s) {
236
249
  console.error(s);
237
250
  }
238
- }, yt = async (t, s) => {
251
+ }, wt = async (t, e) => {
239
252
  try {
240
- const e = [], n = f(t, "./saltygen"), o = f(n, "index.css");
241
- if (O(s)) {
242
- const y = await B(t), a = await W(t, s, n);
243
- Object.entries(a).forEach(([b, l]) => {
244
- if (!l.generator) return;
245
- const w = l.generator._withBuildContext({
246
- name: b,
247
- config: y
248
- }), C = `${w.hash}-${w.priority}.css`, F = `css/${C}`, d = f(n, F);
249
- e.push(C), M(d, w.css);
253
+ const s = [], o = f(t, "./saltygen"), r = f(o, "index.css");
254
+ if (V(e)) {
255
+ const d = await Z(t), a = await I(t, e, o);
256
+ Object.entries(a).forEach(([S, C]) => {
257
+ if (!C.generator) return;
258
+ const l = C.generator._withBuildContext({
259
+ name: S,
260
+ config: d
261
+ }), j = `${l.hash}-${l.priority}.css`, P = `css/${j}`, y = f(o, P);
262
+ s.push(j), E(y, l.css);
250
263
  });
251
- const i = V(o, "utf8").split(`
252
- `), r = e.map((b) => `@import url('../saltygen/css/${b}');`), x = [.../* @__PURE__ */ new Set([...i, ...r])].join(`
264
+ const h = J(r, "utf8").split(`
265
+ `), n = s.map((S) => `@import url('../saltygen/css/${S}');`), b = [.../* @__PURE__ */ new Set([...h, ...n])].join(`
253
266
  `);
254
- M(o, x);
267
+ E(r, b);
255
268
  }
256
- } catch (e) {
257
- console.error(e);
269
+ } catch (s) {
270
+ console.error(s);
258
271
  }
259
- }, dt = async (t, s) => {
272
+ }, St = async (t, e, s = tt()) => {
260
273
  try {
261
- const e = f(t, "./saltygen");
262
- if (O(s)) {
263
- const o = V(s, "utf8");
264
- o.replace(/^(?!export\s)const\s.*/gm, (u) => `export ${u}`) !== o && await ot(s, o);
265
- const y = await B(t), a = await W(t, s, e);
266
- let i = o;
267
- Object.entries(a).forEach(([u, x]) => {
268
- var P;
269
- if (x.isKeyframes || !x.generator) return;
270
- const b = x.generator._withBuildContext({
271
- name: u,
272
- config: y
273
- }), l = new RegExp(`\\s${u}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(o);
274
+ const o = f(t, "./saltygen");
275
+ if (V(e)) {
276
+ const i = J(e, "utf8");
277
+ i.replace(/^(?!export\s)const\s.*/gm, (b) => `export ${b}`) !== i && await at(e, i);
278
+ const a = await Z(t), h = await I(t, e, o);
279
+ let n = i;
280
+ Object.entries(h).forEach(([b, S]) => {
281
+ var M;
282
+ if (S.isKeyframes || !S.generator) return;
283
+ const C = S.generator._withBuildContext({
284
+ name: b,
285
+ config: a,
286
+ prod: s
287
+ }), l = new RegExp(`\\s${b}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(i);
274
288
  if (!l) return console.error("Could not find the original declaration");
275
- const w = (P = l.at(1)) == null ? void 0 : P.trim(), C = new RegExp(`\\s${u}[=\\s]+styled\\(`, "g").exec(i);
276
- if (!C) return console.error("Could not find the original declaration");
277
- const { index: F } = C;
278
- let d = !1;
279
- const k = setTimeout(() => d = !0, 5e3);
280
- let c = 0, p = !1, m = 0;
281
- for (; !p && !d; ) {
282
- const N = i[F + c];
283
- N === "(" && m++, N === ")" && m--, m === 0 && N === ")" && (p = !0), c > i.length && (d = !0), c++;
289
+ const j = (M = l.at(1)) == null ? void 0 : M.trim(), P = new RegExp(`\\s${b}[=\\s]+styled\\(`, "g").exec(n);
290
+ if (!P) return console.error("Could not find the original declaration");
291
+ const { index: y } = P;
292
+ let $ = !1;
293
+ const u = setTimeout(() => $ = !0, 5e3);
294
+ let c = 0, m = !1, p = 0;
295
+ for (; !m && !$; ) {
296
+ const O = n[y + c];
297
+ O === "(" && p++, O === ")" && p--, p === 0 && O === ")" && (m = !0), c > n.length && ($ = !0), c++;
284
298
  }
285
- if (!d) clearTimeout(k);
299
+ if (!$) clearTimeout(u);
286
300
  else throw new Error("Failed to find the end of the styled call and timed out");
287
- const h = F + c, S = i.slice(F, h), $ = i, j = ` ${u} = styled(${w}, "${b.classNames}", "${b._callerName}", ${JSON.stringify(b.props)});`;
288
- i = i.replace(S, j), $ === i && console.error("Minimize file failed to change content", { name: u, tagName: w });
301
+ const x = y + c, F = n.slice(y, x), w = n, k = ` ${b} = styled(${j}, "${C.classNames}", ${JSON.stringify(C.props)});`;
302
+ n = n.replace(F, k), w === n && console.error("Minimize file failed to change content", { name: b, tagName: j });
289
303
  });
290
- const r = _(s, 6);
291
- return y.importStrategy === "component" && (i = `import '../../saltygen/css/${r}.css';
292
- ${i}`), i = i.replace("{ styled }", "{ styledClient as styled }"), i = i.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), i;
304
+ const g = B(e, 6);
305
+ return a.importStrategy === "component" && (n = `import '../../saltygen/css/${g}.css';
306
+ ${n}`), n = n.replace("{ styled }", "{ styledClient as styled }"), n = n.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), n;
293
307
  }
294
- } catch (e) {
295
- console.error("Error in minimizeFile:", e);
308
+ } catch (o) {
309
+ console.error("Error in minimizeFile:", o);
296
310
  }
297
- }, wt = (t) => ({
311
+ }, Pt = (t) => ({
298
312
  name: "stylegen",
299
- buildStart: () => gt(t),
300
- load: async (s) => {
301
- if (O(s))
302
- return await dt(t, s);
313
+ buildStart: () => bt(t),
314
+ load: async (e) => {
315
+ if (V(e))
316
+ return await St(t, e);
303
317
  },
304
318
  watchChange: {
305
- handler: async (s) => {
306
- O(s) && await yt(t, s), s.includes("salty.config") && await X(t);
319
+ handler: async (e) => {
320
+ V(e) && await wt(t, e), e.includes("salty.config") && await v(t);
307
321
  }
308
322
  }
309
323
  });
310
324
  export {
311
- wt as default,
312
- wt as saltyPlugin
325
+ Pt as default,
326
+ Pt as saltyPlugin
313
327
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/vite",
3
- "version": "0.0.1-alpha.84",
3
+ "version": "0.0.1-alpha.86",
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.84"
37
+ "@salty-css/core": "^0.0.1-alpha.86"
38
38
  }
39
39
  }