@salty-css/vite 0.0.1-alpha.104 → 0.0.1-alpha.106

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