@salty-css/vite 0.0.1-alpha.128 → 0.0.1-alpha.129

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