@salty-css/vite 0.0.1-alpha.120 → 0.0.1-alpha.122

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