@salty-css/vite 0.0.1-alpha.134 → 0.0.1-alpha.136

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