@salty-css/vite 0.0.1-alpha.246 → 0.0.1-alpha.247

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 +6 -6
  2. package/index.js +58 -58
  3. package/package.json +2 -2
package/index.cjs CHANGED
@@ -1,9 +1,9 @@
1
- "use strict";var Rt=Object.defineProperty;var vt=(t,e,s)=>e in t?Rt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var st=(t,e,s)=>vt(t,typeof e!="symbol"?e+"":e,s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const Mt=require("esbuild"),zt=require("child_process"),c=require("path"),d=require("fs"),dt=require("fs/promises"),B=require("winston"),lt=require("typescript");var ft=typeof document<"u"?document.currentScript:null;function Jt(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return e.default=t,Object.freeze(e)}const jt=Jt(Mt),$t=t=>String.fromCharCode(t+(t>25?39:97)),Wt=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=$t(n%52)+s;return s=$t(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},At=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},q=(t,e=5)=>{const s=At(5381,JSON.stringify(t))>>>0;return Wt(s,e)};function M(t){return t?typeof t!="string"?M(String(t)):t.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?"-":"")+e.toLowerCase()):""}const qt=t=>e=>{if(typeof e!="string"||!t)return;let s=e;const n=[];return Object.values(t).forEach(o=>{const{pattern:r,transform:i}=o;s=s.replace(r,y=>{const{value:b,css:m}=i(y);return m&&n.push(m),b})}),{transformed:s,additionalCss:n}},Ft=t=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...o)=>`var(--${M(o[1].replaceAll(".","-"))})`)},It=Ft(),Ht=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Lt=(t,e,s)=>Ht.some(o=>typeof o=="string"?o===t:o.test(t))?`${e}px`:`${e}`,Qt=["Webkit","Moz","ms","O"],Gt=t=>t.startsWith("-")?t:Qt.some(e=>t.startsWith(e))?`-${M(t)}`:M(t),nt=async(t,e="",s,n=!1)=>{if(!t)throw new Error("No styles provided to parseStyles function!");const o=new Set,r=Object.entries(t),i=async([p,u])=>{const $=p.trim(),P=Gt($),x=(v,k=";")=>`${P}:${v}${k}`,O={scope:e,config:s};if(typeof u=="function")return i([p,u(O)]);if(u instanceof Promise)return i([p,await u]);if(typeof u=="object"){if(!u)return;if(u.isColor)return x(u.toString());if($==="defaultVariants")return;if($==="variants"){const D=Object.entries(u);for(const[a,g]of D){if(!g)continue;const j=Object.entries(g);for(const[f,C]of j){if(!C)continue;const N=`${e}.${a}-${f}`;(await nt(C,N,s)).forEach(J=>o.add(J))}}return}if($==="compoundVariants"){for(const D of u){const{css:a,...g}=D,j=Object.entries(g).reduce((C,[N,E])=>`${C}.${N}-${E}`,e);(await nt(a,j,s)).forEach(C=>o.add(C))}return}if($.startsWith("@")){const D=$,a=await X(u,e,s),g=`${D} { ${a} }`;o.add(g);return}const v=p.includes("&")?$.replace("&",e):$.startsWith(":")?`${e}${$}`:`${e} ${$}`;(await nt(u,v,s)).forEach(D=>o.add(D));return}if(typeof u=="number"){const v=Lt(P,u);return x(v)}if(typeof u!="string")if("toString"in u)u=u.toString();else throw new Error(`Invalid value type for property ${P}`);return x(u)},y=r.map(i),{modifiers:b}={},m=[Ft(),qt(b)],w=(await Promise.all(y).then(p=>Promise.all(p.map(u=>m.reduce(async($,P)=>{const x=await $;if(!x)return x;const O=await P(x);if(!O)return x;const{transformed:v,additionalCss:k}=O;let D="";if(k)for(const a of k)D+=await X(a,"");return`${D}${v}`},Promise.resolve(u)))))).filter(p=>p!==void 0).join(`
1
+ "use strict";var Rt=Object.defineProperty;var vt=(t,e,s)=>e in t?Rt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var st=(t,e,s)=>vt(t,typeof e!="symbol"?e+"":e,s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const Mt=require("esbuild"),zt=require("child_process"),c=require("path"),d=require("fs"),dt=require("fs/promises"),B=require("winston"),lt=require("typescript");var ft=typeof document<"u"?document.currentScript:null;function Jt(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return e.default=t,Object.freeze(e)}const jt=Jt(Mt),$t=t=>String.fromCharCode(t+(t>25?39:97)),Wt=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=$t(n%52)+s;return s=$t(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},At=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},q=(t,e=5)=>{const s=At(5381,JSON.stringify(t))>>>0;return Wt(s,e)};function M(t){return t?typeof t!="string"?M(String(t)):t.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?"-":"")+e.toLowerCase()):""}const qt=t=>e=>{if(typeof e!="string"||!t)return;let s=e;const n=[];return Object.values(t).forEach(o=>{const{pattern:r,transform:i}=o;s=s.replace(r,y=>{const{value:b,css:m}=i(y);return m&&n.push(m),b})}),{transformed:s,additionalCss:n}},Ft=t=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...o)=>`var(--${M(o[1].replaceAll(".","-"))})`)},It=Ft(),Ht=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Lt=(t,e,s)=>Ht.some(o=>typeof o=="string"?o===t:o.test(t))?`${e}px`:`${e}`,Qt=["Webkit","Moz","ms","O"],Gt=t=>t.startsWith("-")?t:Qt.some(e=>t.startsWith(e))?`-${M(t)}`:M(t),nt=async(t,e="",s,n=!1)=>{if(!t)throw new Error("No styles provided to parseStyles function!");const o=new Set,r=Object.entries(t),i=async([p,u])=>{const $=p.trim(),P=Gt($),x=(v,T=";")=>`${P}:${v}${T}`,O={scope:e,config:s};if(typeof u=="function")return i([p,u(O)]);if(u instanceof Promise)return i([p,await u]);if(typeof u=="object"){if(!u)return;if(u.isColor)return x(u.toString());if($==="defaultVariants")return;if($==="variants"){const D=Object.entries(u);for(const[a,g]of D){if(!g)continue;const j=Object.entries(g);for(const[f,C]of j){if(!C)continue;const N=`${e}.${a}-${f}`;(await nt(C,N,s)).forEach(J=>o.add(J))}}return}if($==="compoundVariants"){for(const D of u){const{css:a,...g}=D,j=Object.entries(g).reduce((C,[N,E])=>`${C}.${N}-${E}`,e);(await nt(a,j,s)).forEach(C=>o.add(C))}return}if($.startsWith("@")){const D=$,a=await X(u,e,s),g=`${D} { ${a} }`;o.add(g);return}const v=p.includes("&")?$.replace("&",e):$.startsWith(":")?`${e}${$}`:`${e} ${$}`;(await nt(u,v,s)).forEach(D=>o.add(D));return}if(typeof u=="number"){const v=Lt(P,u);return x(v)}if(typeof u!="string")if("toString"in u)u=u.toString();else throw new Error(`Invalid value type for property ${P}`);return x(u)},y=r.map(i),{modifiers:b}={},m=[Ft(),qt(b)],w=(await Promise.all(y).then(p=>Promise.all(p.map(u=>m.reduce(async($,P)=>{const x=await $;if(!x)return x;const O=await P(x);if(!O)return x;const{transformed:v,additionalCss:T}=O;let D="";if(T)for(const a of T)D+=await X(a,"");return`${D}${v}`},Promise.resolve(u)))))).filter(p=>p!==void 0).join(`
2
2
  `);if(!w.trim())return Array.from(o);const h=e?`${e} {
3
3
  ${w}
4
4
  }`:w;return o.has(h)?Array.from(o):[h,...o]},X=async(t,e,s,n=!1)=>(await nt(t,e,s,n)).join(`
5
5
  `),Ct=async(t,e=[])=>{if(!t)return"";const s=[],n={};for(const[o,r]of Object.entries(t))if(typeof r!="function")if(r&&typeof r=="object"){const i=o.trim(),y=await Ct(r,[...e,i]);s.push(y)}else n[o]=r;if(Object.keys(n).length){const o=e.map(M).join("-"),r="t_"+q(o,4),i=await X(n,`.${o}, .${r}`);s.push(i)}return s.join(`
6
- `)},Kt=t=>t?Object.entries(t).reduce((e,[s,n])=>(typeof n=="function"?e[s]="any":typeof n=="object"&&(e[s]=Pt(n).map(o=>`"${o}"`).join(" | ")),e),{}):{},Pt=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const r=e?`${e}.${n}`:n;return typeof o=="object"?Pt(o,r,s):s.add(e)}),[...s]):[],Nt=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=c.join(t,"package.json");return d.existsSync(e)?e:Nt(c.join(t,".."))},Ut=async t=>{const e=Nt(t);return await dt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},Zt=async t=>{const e=await Ut(t);if(e)return e.type};let H;const _t=async t=>{if(H)return H;const e=await Zt(t);return e==="module"?H="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:ft&&ft.tagName.toUpperCase()==="SCRIPT"&&ft.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(H="cjs"),H||"esm"},ut=B.createLogger({level:"debug",format:B.format.combine(B.format.colorize(),B.format.cli()),transports:[new B.transports.Console({})]});function xt(t){return t?typeof t!="string"?xt(String(t)):t.replace(/[^\d\w]/g,"."):""}const Bt={"*, *::before, *::after":{boxSizing:"border-box"},"*":{margin:0},html:{lineHeight:1.15,textSizeAdjust:"100%",WebkitFontSmoothing:"antialiased"},"img, picture, video, canvas, svg":{display:"block",maxWidth:"100%"},"p, h1, h2, h3, h4, h5, h6":{overflowWrap:"break-word"},p:{textWrap:"pretty"},"h1, h2, h3, h4, h5, h6":{textWrap:"balance"},a:{color:"currentColor"},button:{lineHeight:"1em",color:"currentColor"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},L=(...t)=>t.flat().reduce((e,s)=>s!=null&&s._current?{...e,...s._current}:{...e,...s},{}),Xt=(...t)=>t.flat().reduce((e,s)=>({...e,...s._children}),{});class Yt{constructor(e){st(this,"_path");this.params=e}get _current(){return this.params.template}get isDefineTemplate(){return!0}_setPath(e){return this._path=e,this}}class te{constructor(e){st(this,"_path");st(this,"templates",[]);this.params=e,Object.entries(e).forEach(([s,n])=>{this.templates.push(new Yt({name:s,template:n}))})}get _current(){return this.params}get _children(){return Object.fromEntries(this.templates.map(e=>[e.params.name,e]))}get isDefineTemplates(){return!0}_setPath(e){return this._path=e,this.templates.forEach(s=>s._setPath(e)),this}}const ee=t=>new te(t),se=(t,e)=>new Promise((s,n)=>{const o=setTimeout(()=>{n(new Error("Timeout"))},100),r=lt.createSourceFile("temp.ts",t,lt.ScriptTarget.Latest,!0);function i(y){if(lt.isVariableDeclaration(y)&&y.name.getText()===e){const b=y.getStart(),m=y.getEnd();clearTimeout(o),s([b,m])}y.forEachChild(i)}i(r)}),z={externalModules:[],rcFile:void 0,destDir:void 0},Tt=t=>{if(z.externalModules.length>0)return z.externalModules;const s=d.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return z.externalModules=n,n},I=async t=>{if(z.destDir)return z.destDir;const e=await pt(t),s=c.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return z.destDir=s,s},kt=["salty","css","styles","styled"],ne=(t=[])=>new RegExp(`\\.(${[...kt,...t].join("|")})\\.`),Q=(t,e=[])=>ne(e).test(t),Dt=async t=>{if(z.rcFile)return z.rcFile;if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=c.join(t,".saltyrc.json"),s=await dt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(z.rcFile=s,s):Dt(c.join(t,".."))},pt=async t=>{var n,o;const e=await Dt(t),s=(n=e.projects)==null?void 0:n.find(r=>t.endsWith(r.dir||""));return s||((o=e.projects)==null?void 0:o.find(r=>r.dir===e.defaultProject))},oe=async t=>{const e=await pt(t),s=await I(t),n=c.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),o=c.join(s,"salty.config.js"),r=await _t(t),i=Tt(n);await jt.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:r,external:i});const y=Date.now(),{config:b}=await import(`${o}?t=${y}`);return{config:b,path:o}},ie=async(t,e)=>{var ht,gt;const s=await I(t),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...e].map(async F=>{const{contents:_,outputFilePath:U}=await ot(t,F,s);Object.entries(_).forEach(([V,T])=>{T.isMedia?n.mediaQueries.push([V,T]):T.isGlobalDefine?n.globalStyles.push(T):T.isDefineVariables?n.variables.push(T):T.isDefineTemplates&&n.templates.push(T._setPath(`${V};;${U}`))})}));const{config:o,path:r}=await oe(t),i={...o},{mediaQueries:y}=n;i.mediaQueries=Object.fromEntries(y.map(([F,_])=>[`@${F}`,_]));const b=y.map(([F])=>`'@${F}'`).join(" | "),m=new Set,l=async(F,_=[])=>{if(!F)return[];const U=Object.entries(F).map(async([T,A])=>{const Z=async R=>{if(!R)return;if(R instanceof Promise)return await Z(await R);if(typeof R=="function")return await Z(await R());if(typeof R=="object")return await l(R,[..._,T]);const rt=xt(T),at=M(T),ct=[..._,rt].join(".");m.add(`"${ct}"`);const et=[..._.map(M),at].join("-"),wt=It(R);return wt?`--${et}: ${wt.transformed};`:`--${et}: ${R};`};return await Z(A)});return(await Promise.all(U)).flat()},w=async F=>{if(!F)return[];const _=Object.entries(F).map(async([V,T])=>{const A=await l(T);return V==="base"?A.join(""):i.mediaQueries[V]?`${i.mediaQueries[V]} { ${A.join("")} }`:`${V} { ${A.join("")} }`});return(await Promise.all(_)).flat()},h=async F=>{if(!F)return[];const _=Object.entries(F).map(async([V,T])=>{const A=Object.entries(T).map(async([R,rt])=>{const at=await l(rt,[V]),ct=`.${V}-${R}, [data-${V}="${R}"]`,et=at.join("");return`${ct} { ${et} }`});return(await Promise.all(A)).flat()});return(await Promise.all(_)).flat()},S=F=>({...F,responsive:void 0,conditional:void 0}),p=F=>n.variables.map(_=>F==="static"?S(_._current):_._current[F]),u=L(S(o.variables),p("static")),$=await l(u),P=L((ht=o.variables)==null?void 0:ht.responsive,p("responsive")),x=await w(P),O=L((gt=o.variables)==null?void 0:gt.conditional,p("conditional")),v=await h(O),k=c.join(s,"css/_variables.css"),D=`:root { ${$.join("")} ${x.join("")} } ${v.join("")}`;d.writeFileSync(k,D),i.staticVariables=u;const a=c.join(s,"css/_global.css"),g=L(o.global,n.globalStyles),j=await X(g,"");d.writeFileSync(a,`@layer global { ${j} }`);const f=c.join(s,"css/_reset.css"),N=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:Bt,E=await X(N,"");d.writeFileSync(f,`@layer reset { ${E} }`);const J=c.join(s,"css/_templates.css"),W=L(o.templates,n.templates),G=await Ct(W),Y=Kt(W);d.writeFileSync(J,`@layer templates { ${G} }`),i.templates=W;const it=o.templates?[ee(o.templates)._setPath(`config;;${r}`)]:[],K=Xt(n.templates,it);i.templatePaths=Object.fromEntries(Object.entries(K).map(([F,_])=>[F,_._path]));const tt=c.join(s,"types/css-tokens.d.ts"),Et=`
6
+ `)},Kt=t=>t?Object.entries(t).reduce((e,[s,n])=>(typeof n=="function"?e[s]="any":typeof n=="object"&&(e[s]=Pt(n).map(o=>`"${o}"`).join(" | ")),e),{}):{},Pt=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const r=e?`${e}.${n}`:n;return typeof o=="object"?Pt(o,r,s):s.add(e)}),[...s]):[],Nt=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=c.join(t,"package.json");return d.existsSync(e)?e:Nt(c.join(t,".."))},Ut=async t=>{const e=Nt(t);return await dt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},Zt=async t=>{const e=await Ut(t);if(e)return e.type};let H;const _t=async t=>{if(H)return H;const e=await Zt(t);return e==="module"?H="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:ft&&ft.tagName.toUpperCase()==="SCRIPT"&&ft.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(H="cjs"),H||"esm"},ut=B.createLogger({level:"debug",format:B.format.combine(B.format.colorize(),B.format.cli()),transports:[new B.transports.Console({})]});function xt(t){return t?typeof t!="string"?xt(String(t)):t.replace(/[^\d\w]/g,"."):""}const Bt={"*, *::before, *::after":{boxSizing:"border-box"},"*":{margin:0},html:{lineHeight:1.15,textSizeAdjust:"100%",WebkitFontSmoothing:"antialiased"},"img, picture, video, canvas, svg":{display:"block",maxWidth:"100%"},"p, h1, h2, h3, h4, h5, h6":{overflowWrap:"break-word"},p:{textWrap:"pretty"},"h1, h2, h3, h4, h5, h6":{textWrap:"balance"},a:{color:"currentColor"},button:{lineHeight:"1em",color:"currentColor"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},L=(...t)=>t.flat().reduce((e,s)=>s!=null&&s._current?{...e,...s._current}:{...e,...s},{}),Xt=(...t)=>t.flat().reduce((e,s)=>({...e,...s._children}),{});class Yt{constructor(e){st(this,"_path");this.params=e}get _current(){return this.params.template}get isDefineTemplate(){return!0}_setPath(e){return this._path=e,this}}class te{constructor(e){st(this,"_path");st(this,"templates",[]);this.params=e,Object.entries(e).forEach(([s,n])=>{this.templates.push(new Yt({name:s,template:n}))})}get _current(){return this.params}get _children(){return Object.fromEntries(this.templates.map(e=>[e.params.name,e]))}get isDefineTemplates(){return!0}_setPath(e){return this._path=e,this.templates.forEach(s=>s._setPath(e)),this}}const ee=t=>new te(t),se=(t,e)=>new Promise((s,n)=>{const o=setTimeout(()=>{n(new Error("Timeout"))},100),r=lt.createSourceFile("temp.ts",t,lt.ScriptTarget.Latest,!0);function i(y){if(lt.isVariableDeclaration(y)&&y.name.getText()===e){const b=y.getStart(),m=y.getEnd();clearTimeout(o),s([b,m])}y.forEachChild(i)}i(r)}),z={externalModules:[],rcFile:void 0,destDir:void 0},kt=t=>{if(z.externalModules.length>0)return z.externalModules;const s=d.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return z.externalModules=n,n},I=async t=>{if(z.destDir)return z.destDir;const e=await pt(t),s=c.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return z.destDir=s,s},Tt=["salty","css","styles","styled"],ne=(t=[])=>new RegExp(`\\.(${[...Tt,...t].join("|")})\\.`),Q=(t,e=[])=>ne(e).test(t),Dt=async t=>{if(z.rcFile)return z.rcFile;if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=c.join(t,".saltyrc.json"),s=await dt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(z.rcFile=s,s):Dt(c.join(t,".."))},pt=async t=>{var n,o;const e=await Dt(t),s=(n=e.projects)==null?void 0:n.find(r=>t.endsWith(r.dir||""));return s||((o=e.projects)==null?void 0:o.find(r=>r.dir===e.defaultProject))},oe=async t=>{const e=await pt(t),s=await I(t),n=c.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),o=c.join(s,"salty.config.js"),r=await _t(t),i=kt(n);await jt.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:r,external:i});const y=Date.now(),{config:b}=await import(`${o}?t=${y}`);return{config:b,path:o}},ie=async(t,e)=>{var ht,gt;const s=await I(t),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...e].map(async F=>{const{contents:_,outputFilePath:U}=await ot(t,F,s);Object.entries(_).forEach(([V,k])=>{k.isMedia?n.mediaQueries.push([V,k]):k.isGlobalDefine?n.globalStyles.push(k):k.isDefineVariables?n.variables.push(k):k.isDefineTemplates&&n.templates.push(k._setPath(`${V};;${U}`))})}));const{config:o,path:r}=await oe(t),i={...o},{mediaQueries:y}=n;i.mediaQueries=Object.fromEntries(y.map(([F,_])=>[`@${F}`,_]));const b=y.map(([F])=>`'@${F}'`).join(" | "),m=new Set,l=async(F,_=[])=>{if(!F)return[];const U=Object.entries(F).map(async([k,A])=>{const Z=async R=>{if(!R)return;if(R instanceof Promise)return await Z(await R);if(typeof R=="function")return await Z(await R());if(typeof R=="object")return await l(R,[..._,k]);const rt=xt(k),at=M(k),ct=[..._,rt].join(".");m.add(`"${ct}"`);const et=[..._.map(M),at].join("-"),wt=It(R);return wt?`--${et}: ${wt.transformed};`:`--${et}: ${R};`};return await Z(A)});return(await Promise.all(U)).flat()},w=async F=>{if(!F)return[];const _=Object.entries(F).map(async([V,k])=>{const A=await l(k);return V==="base"?A.join(""):i.mediaQueries[V]?`${i.mediaQueries[V]} { ${A.join("")} }`:`${V} { ${A.join("")} }`});return(await Promise.all(_)).flat()},h=async F=>{if(!F)return[];const _=Object.entries(F).map(async([V,k])=>{const A=Object.entries(k).map(async([R,rt])=>{const at=await l(rt,[V]),ct=`.${V}-${R}, [data-${V}="${R}"]`,et=at.join("");return`${ct} { ${et} }`});return(await Promise.all(A)).flat()});return(await Promise.all(_)).flat()},S=F=>({...F,responsive:void 0,conditional:void 0}),p=F=>n.variables.map(_=>F==="static"?S(_._current):_._current[F]),u=L(S(o.variables),p("static")),$=await l(u),P=L((ht=o.variables)==null?void 0:ht.responsive,p("responsive")),x=await w(P),O=L((gt=o.variables)==null?void 0:gt.conditional,p("conditional")),v=await h(O),T=c.join(s,"css/_variables.css"),D=`:root { ${$.join("")} ${x.join("")} } ${v.join("")}`;d.writeFileSync(T,D),i.staticVariables=u;const a=c.join(s,"css/_global.css"),g=L(o.global,n.globalStyles),j=await X(g,"");d.writeFileSync(a,`@layer global { ${j} }`);const f=c.join(s,"css/_reset.css"),N=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:Bt,E=await X(N,"");d.writeFileSync(f,`@layer reset { ${E} }`);const J=c.join(s,"css/_templates.css"),W=L(o.templates,n.templates),G=await Ct(W),Y=Kt(W);d.writeFileSync(J,`@layer templates { ${G} }`),i.templates=W;const it=o.templates?[ee(o.templates)._setPath(`config;;${r}`)]:[],K=Xt(n.templates,it);i.templatePaths=Object.fromEntries(Object.entries(K).map(([F,_])=>[F,_._path]));const tt=c.join(s,"types/css-tokens.d.ts"),Et=`
7
7
  // Variable types
8
8
  type VariableTokens = ${[...m].join("|")};
9
9
  type PropertyValueToken = \`{\${VariableTokens}}\`;
@@ -16,11 +16,11 @@
16
16
 
17
17
  // Media query types
18
18
  type MediaQueryKeys = ${b||"''"};
19
- `;d.writeFileSync(tt,Et);const Vt=c.join(s,"cache/config-cache.json");d.writeFileSync(Vt,JSON.stringify(i,null,2))},bt=t=>t.replace(/styled\(([^"'`{,]+),/g,(e,s)=>{if(/^['"`]/.test(s))return e;const o=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!o.test(t))return e;const i=o.exec(t);if(i){const y=i.at(1);if(kt.some(m=>y==null?void 0:y.includes(m)))return e}return"styled('div',"}),re=(t,e)=>{try{const s=d.readFileSync(c.join(e,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
19
+ `;d.writeFileSync(tt,Et);const Vt=c.join(s,"cache/config-cache.json");d.writeFileSync(Vt,JSON.stringify(i,null,2))},bt=t=>t.replace(/styled\(([^"'`{,]+),/g,(e,s)=>{if(/^['"`]/.test(s))return e;const o=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!o.test(t))return e;const i=o.exec(t);if(i){const y=i.at(1);if(Tt.some(m=>y==null?void 0:y.includes(m)))return e}return"styled('div',"}),re=(t,e)=>{try{const s=d.readFileSync(c.join(e,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
20
20
 
21
21
  ${t}`:`globalThis.saltyConfig = {};
22
22
 
23
- ${t}`}catch{return t}},ot=async(t,e,s)=>{const n=q(e),o=c.join(s,"./temp");d.existsSync(o)||d.mkdirSync(o);const r=c.parse(e);let i=d.readFileSync(e,"utf8");i=bt(i),i=re(i,t);const y=c.join(s,"js",n+".js"),b=await pt(t),m=c.join(t,(b==null?void 0:b.configDir)||"","salty.config.ts"),l=Tt(m),w=await _t(t);await jt.build({stdin:{contents:i,sourcefile:r.base,resolveDir:r.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:w,target:["node20"],keepNames:!0,external:l,packages:"external",plugins:[{name:"test",setup:p=>{p.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},u=>{const $=d.readFileSync(u.path,"utf8");return{contents:bt($),loader:"ts"}})}}]});const h=Date.now();return{contents:await import(`${y}?t=${h}`),outputFilePath:y}},ae=async t=>{const e=await I(t),s=c.join(e,"cache/config-cache.json"),n=d.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},mt=async t=>{const e=await ae(t),s=await I(t),n=c.join(s,"salty.config.js"),o=Date.now(),{config:r}=await import(`${n}?t=${o}`);return L(r,e)},yt=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},ce=async(t,e=yt(),s=!0)=>{try{const n=Date.now();e?ut.info("Generating CSS in production mode! 🔥"):ut.info("Generating CSS in development mode! 🚀");const o=[],r=[],i=await I(t),y=c.join(i,"index.css");s&&(()=>{d.existsSync(i)&&zt.execSync("rm -rf "+i),d.mkdirSync(i,{recursive:!0}),d.mkdirSync(c.join(i,"css")),d.mkdirSync(c.join(i,"types")),d.mkdirSync(c.join(i,"js")),d.mkdirSync(c.join(i,"cache"))})();const m=new Set,l=new Set;async function w(a){const g=["node_modules","saltygen"],j=d.statSync(a);if(j.isDirectory()){const f=d.readdirSync(a);if(g.some(N=>a.includes(N)))return;await Promise.all(f.map(N=>w(c.join(a,N))))}else if(j.isFile()&&Q(a)){m.add(a);const C=d.readFileSync(a,"utf8");/define[\w\d]+\(/.test(C)&&l.add(a)}}await w(t),await ie(t,l);const h={keyframes:[],components:[],classNames:[]};await Promise.all([...m].map(async a=>{const{contents:g}=await ot(t,a,i);for(let[j,f]of Object.entries(g))f instanceof Promise&&(f=await f),f.isKeyframes?h.keyframes.push({value:f,src:a,name:j}):f.isClassName?h.classNames.push({...f,src:a,name:j}):f.generator&&h.components.push({...f,src:a,name:j})}));const S=await mt(t);for(const a of h.keyframes){const{value:g}=a,j=`a_${g.animationName}.css`,f=`css/${j}`,C=c.join(i,f);o.push(j),d.writeFileSync(C,g.css)}const p={};for(const a of h.components){const{src:g,name:j}=a;p[g]||(p[g]=[]);const f=a.generator._withBuildContext({callerName:j,isProduction:e,config:S});r[f.priority]||(r[f.priority]=[]);const C=await f.css;if(!C)continue;r[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,E=c.join(i,N);d.writeFileSync(E,C),S.importStrategy==="component"&&p[g].push(f.cssFileName)}for(const a of h.classNames){const{src:g,name:j}=a;p[g]||(p[g]=[]);const f=a.generator._withBuildContext({callerName:j,isProduction:e,config:S}),C=await f.css;if(!C)continue;r[f.priority]||(r[f.priority]=[]),r[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,E=c.join(i,N);d.writeFileSync(E,C),S.importStrategy==="component"&&p[g].push(f.cssFileName)}S.importStrategy==="component"&&Object.entries(p).forEach(([a,g])=>{const j=g.map(J=>`@import url('./${J}');`).join(`
23
+ ${t}`}catch{return t}},ot=async(t,e,s)=>{const n=q(e),o=c.join(s,"./temp");d.existsSync(o)||d.mkdirSync(o);const r=c.parse(e);let i=d.readFileSync(e,"utf8");i=bt(i),i=re(i,t);const y=c.join(s,"js",n+".js"),b=await pt(t),m=c.join(t,(b==null?void 0:b.configDir)||"","salty.config.ts"),l=kt(m),w=await _t(t);await jt.build({stdin:{contents:i,sourcefile:r.base,resolveDir:r.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:w,target:["node20"],keepNames:!0,external:l,packages:"external",plugins:[{name:"test",setup:p=>{p.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},u=>{const $=d.readFileSync(u.path,"utf8");return{contents:bt($),loader:"ts"}})}}]});const h=Date.now();return{contents:await import(`${y}?t=${h}`),outputFilePath:y}},ae=async t=>{const e=await I(t),s=c.join(e,"cache/config-cache.json"),n=d.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},mt=async t=>{const e=await ae(t),s=await I(t),n=c.join(s,"salty.config.js"),o=Date.now(),{config:r}=await import(`${n}?t=${o}`);return L(r,e)},yt=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},ce=async(t,e=yt(),s=!0)=>{try{const n=Date.now();e?ut.info("Generating CSS in production mode! 🔥"):ut.info("Generating CSS in development mode! 🚀");const o=[],r=[],i=await I(t),y=c.join(i,"index.css");s&&(()=>{d.existsSync(i)&&zt.execSync("rm -rf "+i),d.mkdirSync(i,{recursive:!0}),d.mkdirSync(c.join(i,"css")),d.mkdirSync(c.join(i,"types")),d.mkdirSync(c.join(i,"js")),d.mkdirSync(c.join(i,"cache"))})();const m=new Set,l=new Set;async function w(a){const g=["node_modules","saltygen"],j=d.statSync(a);if(j.isDirectory()){const f=d.readdirSync(a);if(g.some(N=>a.includes(N)))return;await Promise.all(f.map(N=>w(c.join(a,N))))}else if(j.isFile()&&Q(a)){m.add(a);const C=d.readFileSync(a,"utf8");/define[\w\d]+\(/.test(C)&&l.add(a)}}await w(t),await ie(t,l);const h={keyframes:[],components:[],classNames:[]};await Promise.all([...m].map(async a=>{const{contents:g}=await ot(t,a,i);for(let[j,f]of Object.entries(g))f instanceof Promise&&(f=await f),f.isKeyframes?h.keyframes.push({value:f,src:a,name:j}):f.isClassName?h.classNames.push({...f,src:a,name:j}):f.generator&&h.components.push({...f,src:a,name:j})}));const S=await mt(t);for(const a of h.keyframes){const{value:g}=a,j=`a_${g.animationName}.css`,f=`css/${j}`,C=c.join(i,f);o.push(j),d.writeFileSync(C,g.css)}const p={};for(const a of h.components){const{src:g,name:j}=a;p[g]||(p[g]=[]);const f=a.generator._withBuildContext({callerName:j,isProduction:e,config:S});r[f.priority]||(r[f.priority]=[]);const C=await f.css;if(!C)continue;r[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,E=c.join(i,N);d.writeFileSync(E,C),S.importStrategy==="component"&&p[g].push(f.cssFileName)}for(const a of h.classNames){const{src:g,name:j}=a;p[g]||(p[g]=[]);const f=a.generator._withBuildContext({callerName:j,isProduction:e,config:S}),C=await f.css;if(!C)continue;r[f.priority]||(r[f.priority]=[]),r[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,E=c.join(i,N);d.writeFileSync(E,C),S.importStrategy==="component"&&p[g].push(f.cssFileName)}S.importStrategy==="component"&&Object.entries(p).forEach(([a,g])=>{const j=g.map(J=>`@import url('./${J}');`).join(`
24
24
  `),f=q(a,6),C=c.parse(a),N=M(C.name),E=c.join(i,`css/f_${N}-${f}.css`);d.writeFileSync(E,j||"/* Empty file */")});const u=o.map(a=>`@import url('./css/${a}');`).join(`
25
25
  `);let O=`@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
26
26
 
@@ -32,11 +32,11 @@ ${it}
32
32
  /*end:${K}*/
33
33
  `},""),N=`l_${f}.css`,E=c.join(i,"css",N),J=`@layer l${f} { ${C}
34
34
  }`;return d.writeFileSync(E,J),`${g}
35
- @import url('./css/${N}');`},"");O+=a}d.writeFileSync(y,O);const k=Date.now()-n,D=k<200?"🔥":k<500?"🚀":k<1e3?"🎉":k<2e3?"🚗":k<5e3?"🤔":"🥴";ut.info(`Generated CSS in ${k}ms! ${D}`)}catch(n){console.error(n)}},le=async(t,e,s=yt())=>{try{const n=await I(t);if(Q(e)){const r=[],i=await mt(t),{contents:y}=await ot(t,e,n);for(const[b,m]of Object.entries(y)){if(m.isKeyframes&&m.css){const u=`css/${`a_${m.animationName}.css`}`,$=c.join(n,u);d.writeFileSync($,await m.css);continue}if(m.isClassName){const p=m.generator._withBuildContext({callerName:b,isProduction:s,config:i}),u=await p.css;if(!u)continue;r[p.priority]||(r[p.priority]=[]),r[p.priority].push(p.cssFileName);const $=`css/${p.cssFileName}`,P=c.join(n,$);d.writeFileSync(P,u);continue}if(!m.generator)continue;const l=m.generator._withBuildContext({callerName:b,isProduction:s,config:i}),w=await l.css;if(!w)continue;const h=`css/${l.cssFileName}`,S=c.join(n,h);d.writeFileSync(S,w),r[l.priority]||(r[l.priority]=[]),r[l.priority].push(l.cssFileName)}if(i.importStrategy!=="component")r.forEach((b,m)=>{const l=`l_${m}.css`,w=c.join(n,"css",l);let h=d.readFileSync(w,"utf8");b.forEach(S=>{var P;const p=c.join(n,"css",S),u=((P=/.*-([^-]+)-\d+.css/.exec(S))==null?void 0:P.at(1))||q(p,6);if(!h.includes(u)){const x=d.readFileSync(p,"utf8"),O=`/*start:${u}-${S}*/
35
+ @import url('./css/${N}');`},"");O+=a}d.writeFileSync(y,O);const T=Date.now()-n,D=T<200?"🔥":T<500?"🚀":T<1e3?"🎉":T<2e3?"🚗":T<5e3?"🤔":"🥴";ut.info(`Generated CSS in ${T}ms! ${D}`)}catch(n){console.error(n)}},le=async(t,e,s=yt())=>{try{const n=await I(t);if(Q(e)){const r=[],i=await mt(t),{contents:y}=await ot(t,e,n);for(const[b,m]of Object.entries(y)){if(m.isKeyframes&&m.css){const u=`css/${`a_${m.animationName}.css`}`,$=c.join(n,u);d.writeFileSync($,await m.css);continue}if(m.isClassName){const p=m.generator._withBuildContext({callerName:b,isProduction:s,config:i}),u=await p.css;if(!u)continue;r[p.priority]||(r[p.priority]=[]),r[p.priority].push(p.cssFileName);const $=`css/${p.cssFileName}`,P=c.join(n,$);d.writeFileSync(P,u);continue}if(!m.generator)continue;const l=m.generator._withBuildContext({callerName:b,isProduction:s,config:i}),w=await l.css;if(!w)continue;const h=`css/${l.cssFileName}`,S=c.join(n,h);d.writeFileSync(S,w),r[l.priority]||(r[l.priority]=[]),r[l.priority].push(l.cssFileName)}if(i.importStrategy!=="component")r.forEach((b,m)=>{const l=`l_${m}.css`,w=c.join(n,"css",l);let h=d.readFileSync(w,"utf8");b.forEach(S=>{var P;const p=c.join(n,"css",S),u=((P=/.*-([^-]+)-\d+.css/.exec(S))==null?void 0:P.at(1))||q(p,6);if(!h.includes(u)){const x=d.readFileSync(p,"utf8"),O=`/*start:${u}-${S}*/
36
36
  ${x}
37
37
  /*end:${u}*/
38
38
  `;h=`${h.replace(/\}$/,"")}
39
39
  ${O}
40
40
  }`}}),d.writeFileSync(w,h)});else{const b=r.flat().map(S=>`@import url('./${S}');`).join(`
41
41
  `),m=q(e,6),l=c.parse(e),w=M(l.name),h=c.join(n,`css/f_${w}-${m}.css`);d.writeFileSync(h,b||"/* Empty file */")}}}catch(n){console.error(n)}},fe=async(t,e,s=yt())=>{var n,o;try{const r=await I(t);if(Q(e)){const y=d.readFileSync(e,"utf8"),b=await mt(t),{contents:m}=await ot(t,e,r);let l=y;for(const[w,h]of Object.entries(m)){if(h.isKeyframes||!h.generator)continue;const S=h.generator._withBuildContext({callerName:w,isProduction:s,config:b}),[p,u]=await se(l,w),$=l.slice(p,u);if(h.isClassName){const P=l,x=` ${w} = className("${S.classNames}")`;l=l.replace($,x),P===l&&console.error("Minimize file failed to change content",{name:w})}if($.includes("styled")){const P=(o=(n=/styled\(([^,]+),/.exec($))==null?void 0:n.at(1))==null?void 0:o.trim(),x=l,O=` ${w} = styled(${P}, "${S.classNames}", ${JSON.stringify(S.clientProps)})`;l=l.replace($,O),x===l&&console.error("Minimize file failed to change content",{name:w,tagName:P})}}if(b.importStrategy==="component"){const w=q(e,6),h=c.parse(e);l=`import '../../saltygen/css/${`f_${M(h.name)}-${w}.css`}';
42
- ${l}`}return l=l.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),l=l.replace("{ styled }","{ styledClient as styled }"),l=l.replace("@salty-css/react/styled","@salty-css/react/styled-client"),l}}catch(r){console.error("Error in minimizeFile:",r)}},St=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!Q(t))return!1;const n=await dt.readFile(t,"utf-8");return!!/.+define[A-Z]\w+/.test(n)},Ot=t=>({name:"stylegen",buildStart:()=>ce(t),load:async e=>{if(Q(e))return await fe(t,e)},handleHotUpdate:async({file:e,server:s})=>{await St(e)&&s.restart()},watchChange:{handler:async(e,s)=>{Q(e)&&s.event!=="delete"&&(await St(e)||await le(t,e))}}});exports.default=Ot;exports.saltyPlugin=Ot;
42
+ ${l}`}return l=l.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),l=l.replace("{ styled }","{ styledClient as styled }"),l=l.replace("@salty-css/react/styled","@salty-css/react/styled-client"),l}}catch(r){console.error("Error in minimizeFile:",r)}},St=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!Q(t))return!1;const n=await dt.readFile(t,"utf-8");return!!(/.+define[A-Z]\w+/.test(n)||/.+keyframes\(.+/.test(n))},Ot=t=>({name:"stylegen",buildStart:()=>ce(t),load:async e=>{if(Q(e))return await fe(t,e)},handleHotUpdate:async({file:e,server:s})=>{await St(e)&&s.restart()},watchChange:{handler:async(e,s)=>{Q(e)&&s.event!=="delete"&&(await St(e)||await le(t,e))}}});exports.default=Ot;exports.saltyPlugin=Ot;
package/index.js CHANGED
@@ -5,7 +5,7 @@ import * as Pt from "esbuild";
5
5
  import { execSync as zt } from "child_process";
6
6
  import { join as u, parse as rt } from "path";
7
7
  import { existsSync as mt, mkdirSync as K, statSync as Wt, readdirSync as At, readFileSync as R, writeFileSync as x } from "fs";
8
- import { readFile as ht } from "fs/promises";
8
+ import { readFile as yt } from "fs/promises";
9
9
  import { createLogger as Ht, format as ut, transports as It } from "winston";
10
10
  import pt from "typescript";
11
11
  const Ct = (e) => String.fromCharCode(e + (e > 25 ? 39 : 97)), Qt = (e, t) => {
@@ -67,9 +67,9 @@ const Kt = (e) => (t) => {
67
67
  if (w === "defaultVariants") return;
68
68
  if (w === "variants") {
69
69
  const k = Object.entries(f);
70
- for (const [i, y] of k) {
71
- if (!y) continue;
72
- const S = Object.entries(y);
70
+ for (const [i, h] of k) {
71
+ if (!h) continue;
72
+ const S = Object.entries(h);
73
73
  for (const [l, j] of S) {
74
74
  if (!j) continue;
75
75
  const P = `${t}.${i}-${l}`;
@@ -80,14 +80,14 @@ const Kt = (e) => (t) => {
80
80
  }
81
81
  if (w === "compoundVariants") {
82
82
  for (const k of f) {
83
- const { css: i, ...y } = k, S = Object.entries(y).reduce((j, [P, O]) => `${j}.${P}-${O}`, t);
83
+ const { css: i, ...h } = k, S = Object.entries(h).reduce((j, [P, O]) => `${j}.${P}-${O}`, t);
84
84
  (await ot(i, S, s)).forEach((j) => o.add(j));
85
85
  }
86
86
  return;
87
87
  }
88
88
  if (w.startsWith("@")) {
89
- const k = w, i = await Y(f, t, s), y = `${k} { ${i} }`;
90
- o.add(y);
89
+ const k = w, i = await Y(f, t, s), h = `${k} { ${i} }`;
90
+ o.add(h);
91
91
  return;
92
92
  }
93
93
  const v = p.includes("&") ? w.replace("&", t) : w.startsWith(":") ? `${t}${w}` : `${t} ${w}`;
@@ -118,10 +118,10 @@ const Kt = (e) => (t) => {
118
118
  ))).filter((p) => p !== void 0).join(`
119
119
  `);
120
120
  if (!g.trim()) return Array.from(o);
121
- const h = t ? `${t} {
121
+ const y = t ? `${t} {
122
122
  ${g}
123
123
  }` : g;
124
- return o.has(h) ? Array.from(o) : [h, ...o];
124
+ return o.has(y) ? Array.from(o) : [y, ...o];
125
125
  }, Y = async (e, t, s, n = !1) => (await ot(e, t, s, n)).join(`
126
126
  `), _t = async (e, t = []) => {
127
127
  if (!e) return "";
@@ -147,7 +147,7 @@ const Kt = (e) => (t) => {
147
147
  return mt(t) ? t : Tt(u(e, ".."));
148
148
  }, Yt = async (e) => {
149
149
  const t = Tt(e);
150
- return await ht(t, "utf-8").then(JSON.parse).catch(() => {
150
+ return await yt(t, "utf-8").then(JSON.parse).catch(() => {
151
151
  });
152
152
  }, te = async (e) => {
153
153
  const t = await Yt(e);
@@ -281,20 +281,20 @@ const re = (e) => new oe(e), ae = (e, t) => new Promise((s, n) => {
281
281
  return z.externalModules = n, n;
282
282
  }, Q = async (e) => {
283
283
  if (z.destDir) return z.destDir;
284
- const t = await yt(e), s = u(e, (t == null ? void 0 : t.saltygenDir) || "saltygen");
284
+ const t = await ht(e), s = u(e, (t == null ? void 0 : t.saltygenDir) || "saltygen");
285
285
  return z.destDir = s, s;
286
286
  }, Ot = ["salty", "css", "styles", "styled"], ie = (e = []) => new RegExp(`\\.(${[...Ot, ...e].join("|")})\\.`), Z = (e, t = []) => ie(t).test(e), Vt = async (e) => {
287
287
  if (z.rcFile) return z.rcFile;
288
288
  if (e === "/") throw new Error("Could not find .saltyrc.json file");
289
- const t = u(e, ".saltyrc.json"), s = await ht(t, "utf-8").then(JSON.parse).catch(() => {
289
+ const t = u(e, ".saltyrc.json"), s = await yt(t, "utf-8").then(JSON.parse).catch(() => {
290
290
  });
291
291
  return s ? (z.rcFile = s, s) : Vt(u(e, ".."));
292
- }, yt = async (e) => {
292
+ }, ht = async (e) => {
293
293
  var n, o;
294
294
  const t = await Vt(e), s = (n = t.projects) == null ? void 0 : n.find((a) => e.endsWith(a.dir || ""));
295
295
  return s || ((o = t.projects) == null ? void 0 : o.find((a) => a.dir === t.defaultProject));
296
296
  }, ce = async (e) => {
297
- const t = await yt(e), s = await Q(e), n = u(e, (t == null ? void 0 : t.configDir) || "", "salty.config.ts"), o = u(s, "salty.config.js"), a = await Dt(e), r = Et(n);
297
+ const t = await ht(e), s = await Q(e), n = u(e, (t == null ? void 0 : t.configDir) || "", "salty.config.ts"), o = u(s, "salty.config.js"), a = await Dt(e), r = Et(n);
298
298
  await Pt.build({
299
299
  entryPoints: [n],
300
300
  minify: !0,
@@ -347,7 +347,7 @@ const re = (e) => new oe(e), ae = (e, t) => new Promise((s, n) => {
347
347
  return V === "base" ? H.join("") : r.mediaQueries[V] ? `${r.mediaQueries[V]} { ${H.join("")} }` : `${V} { ${H.join("")} }`;
348
348
  });
349
349
  return (await Promise.all(N)).flat();
350
- }, h = async (C) => {
350
+ }, y = async (C) => {
351
351
  if (!C) return [];
352
352
  const N = Object.entries(C).map(async ([V, T]) => {
353
353
  const H = Object.entries(T).map(async ([M, ct]) => {
@@ -357,9 +357,9 @@ const re = (e) => new oe(e), ae = (e, t) => new Promise((s, n) => {
357
357
  return (await Promise.all(H)).flat();
358
358
  });
359
359
  return (await Promise.all(N)).flat();
360
- }, b = (C) => ({ ...C, responsive: void 0, conditional: void 0 }), p = (C) => n.variables.map((N) => C === "static" ? b(N._current) : N._current[C]), f = L(b(o.variables), p("static")), w = await c(f), F = L(($t = o.variables) == null ? void 0 : $t.responsive, p("responsive")), _ = await g(F), E = L((bt = o.variables) == null ? void 0 : bt.conditional, p("conditional")), v = await h(E), D = u(s, "css/_variables.css"), k = `:root { ${w.join("")} ${_.join("")} } ${v.join("")}`;
360
+ }, b = (C) => ({ ...C, responsive: void 0, conditional: void 0 }), p = (C) => n.variables.map((N) => C === "static" ? b(N._current) : N._current[C]), f = L(b(o.variables), p("static")), w = await c(f), F = L(($t = o.variables) == null ? void 0 : $t.responsive, p("responsive")), _ = await g(F), E = L((bt = o.variables) == null ? void 0 : bt.conditional, p("conditional")), v = await y(E), D = u(s, "css/_variables.css"), k = `:root { ${w.join("")} ${_.join("")} } ${v.join("")}`;
361
361
  x(D, k), r.staticVariables = f;
362
- const i = u(s, "css/_global.css"), y = L(o.global, n.globalStyles), S = await Y(y, "");
362
+ const i = u(s, "css/_global.css"), h = L(o.global, n.globalStyles), S = await Y(h, "");
363
363
  x(i, `@layer global { ${S} }`);
364
364
  const l = u(s, "css/_reset.css"), P = o.reset === "none" ? {} : typeof o.reset == "object" ? o.reset : ee, O = await Y(P, "");
365
365
  x(l, `@layer reset { ${O} }`);
@@ -411,7 +411,7 @@ ${e}`;
411
411
  const a = rt(t);
412
412
  let r = R(t, "utf8");
413
413
  r = jt(r), r = fe(r, e);
414
- const m = u(s, "js", n + ".js"), $ = await yt(e), d = u(e, ($ == null ? void 0 : $.configDir) || "", "salty.config.ts"), c = Et(d), g = await Dt(e);
414
+ const m = u(s, "js", n + ".js"), $ = await ht(e), d = u(e, ($ == null ? void 0 : $.configDir) || "", "salty.config.ts"), c = Et(d), g = await Dt(e);
415
415
  await Pt.build({
416
416
  stdin: {
417
417
  contents: r,
@@ -440,8 +440,8 @@ ${e}`;
440
440
  }
441
441
  ]
442
442
  });
443
- const h = Date.now();
444
- return { contents: await import(`${m}?t=${h}`), outputFilePath: m };
443
+ const y = Date.now();
444
+ return { contents: await import(`${m}?t=${y}`), outputFilePath: m };
445
445
  }, ue = async (e) => {
446
446
  const t = await Q(e), s = u(t, "cache/config-cache.json"), n = R(s, "utf8");
447
447
  if (!n) throw new Error("Could not find config cache file");
@@ -465,10 +465,10 @@ ${e}`;
465
465
  })();
466
466
  const d = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set();
467
467
  async function g(i) {
468
- const y = ["node_modules", "saltygen"], S = Wt(i);
468
+ const h = ["node_modules", "saltygen"], S = Wt(i);
469
469
  if (S.isDirectory()) {
470
470
  const l = At(i);
471
- if (y.some((P) => i.includes(P))) return;
471
+ if (h.some((P) => i.includes(P))) return;
472
472
  await Promise.all(l.map((P) => g(u(i, P))));
473
473
  } else if (S.isFile() && Z(i)) {
474
474
  d.add(i);
@@ -477,24 +477,24 @@ ${e}`;
477
477
  }
478
478
  }
479
479
  await g(e), await le(e, c);
480
- const h = {
480
+ const y = {
481
481
  keyframes: [],
482
482
  components: [],
483
483
  classNames: []
484
484
  };
485
485
  await Promise.all(
486
486
  [...d].map(async (i) => {
487
- const { contents: y } = await at(e, i, r);
488
- for (let [S, l] of Object.entries(y))
489
- l instanceof Promise && (l = await l), l.isKeyframes ? h.keyframes.push({
487
+ const { contents: h } = await at(e, i, r);
488
+ for (let [S, l] of Object.entries(h))
489
+ l instanceof Promise && (l = await l), l.isKeyframes ? y.keyframes.push({
490
490
  value: l,
491
491
  src: i,
492
492
  name: S
493
- }) : l.isClassName ? h.classNames.push({
493
+ }) : l.isClassName ? y.classNames.push({
494
494
  ...l,
495
495
  src: i,
496
496
  name: S
497
- }) : l.generator && h.components.push({
497
+ }) : l.generator && y.components.push({
498
498
  ...l,
499
499
  src: i,
500
500
  name: S
@@ -502,14 +502,14 @@ ${e}`;
502
502
  })
503
503
  );
504
504
  const b = await gt(e);
505
- for (const i of h.keyframes) {
506
- const { value: y } = i, S = `a_${y.animationName}.css`, l = `css/${S}`, j = u(r, l);
507
- o.push(S), x(j, y.css);
505
+ for (const i of y.keyframes) {
506
+ const { value: h } = i, S = `a_${h.animationName}.css`, l = `css/${S}`, j = u(r, l);
507
+ o.push(S), x(j, h.css);
508
508
  }
509
509
  const p = {};
510
- for (const i of h.components) {
511
- const { src: y, name: S } = i;
512
- p[y] || (p[y] = []);
510
+ for (const i of y.components) {
511
+ const { src: h, name: S } = i;
512
+ p[h] || (p[h] = []);
513
513
  const l = i.generator._withBuildContext({
514
514
  callerName: S,
515
515
  isProduction: t,
@@ -520,11 +520,11 @@ ${e}`;
520
520
  if (!j) continue;
521
521
  a[l.priority].push(l.cssFileName);
522
522
  const P = `css/${l.cssFileName}`, O = u(r, P);
523
- x(O, j), b.importStrategy === "component" && p[y].push(l.cssFileName);
523
+ x(O, j), b.importStrategy === "component" && p[h].push(l.cssFileName);
524
524
  }
525
- for (const i of h.classNames) {
526
- const { src: y, name: S } = i;
527
- p[y] || (p[y] = []);
525
+ for (const i of y.classNames) {
526
+ const { src: h, name: S } = i;
527
+ p[h] || (p[h] = []);
528
528
  const l = i.generator._withBuildContext({
529
529
  callerName: S,
530
530
  isProduction: t,
@@ -533,10 +533,10 @@ ${e}`;
533
533
  if (!j) continue;
534
534
  a[l.priority] || (a[l.priority] = []), a[l.priority].push(l.cssFileName);
535
535
  const P = `css/${l.cssFileName}`, O = u(r, P);
536
- x(O, j), b.importStrategy === "component" && p[y].push(l.cssFileName);
536
+ x(O, j), b.importStrategy === "component" && p[h].push(l.cssFileName);
537
537
  }
538
- b.importStrategy === "component" && Object.entries(p).forEach(([i, y]) => {
539
- const S = y.map((W) => `@import url('./${W}');`).join(`
538
+ b.importStrategy === "component" && Object.entries(p).forEach(([i, h]) => {
539
+ const S = h.map((W) => `@import url('./${W}');`).join(`
540
540
  `), l = I(i, 6), j = rt(i), P = J(j.name), O = u(r, `css/f_${P}-${l}.css`);
541
541
  x(O, S || "/* Empty file */");
542
542
  });
@@ -554,7 +554,7 @@ ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((i) =
554
554
  `)}
555
555
  ${f}`;
556
556
  if (b.importStrategy !== "component") {
557
- const i = a.reduce((y, S, l) => {
557
+ const i = a.reduce((h, S, l) => {
558
558
  const j = S.reduce((A, B) => {
559
559
  var et;
560
560
  const tt = u(r, "css", B), it = R(tt, "utf8"), U = ((et = /.*-([^-]+)-\d+.css/.exec(B)) == null ? void 0 : et.at(1)) || I(tt, 6);
@@ -565,7 +565,7 @@ ${it}
565
565
  `;
566
566
  }, ""), P = `l_${l}.css`, O = u(r, "css", P), W = `@layer l${l} { ${j}
567
567
  }`;
568
- return x(O, W), `${y}
568
+ return x(O, W), `${h}
569
569
  @import url('./css/${P}');`;
570
570
  }, "");
571
571
  E += i;
@@ -606,31 +606,31 @@ ${it}
606
606
  config: r
607
607
  }), g = await c.css;
608
608
  if (!g) continue;
609
- const h = `css/${c.cssFileName}`, b = u(n, h);
609
+ const y = `css/${c.cssFileName}`, b = u(n, y);
610
610
  x(b, g), a[c.priority] || (a[c.priority] = []), a[c.priority].push(c.cssFileName);
611
611
  }
612
612
  if (r.importStrategy !== "component")
613
613
  a.forEach(($, d) => {
614
614
  const c = `l_${d}.css`, g = u(n, "css", c);
615
- let h = R(g, "utf8");
615
+ let y = R(g, "utf8");
616
616
  $.forEach((b) => {
617
617
  var F;
618
618
  const p = u(n, "css", b), f = ((F = /.*-([^-]+)-\d+.css/.exec(b)) == null ? void 0 : F.at(1)) || I(p, 6);
619
- if (!h.includes(f)) {
619
+ if (!y.includes(f)) {
620
620
  const _ = R(p, "utf8"), E = `/*start:${f}-${b}*/
621
621
  ${_}
622
622
  /*end:${f}*/
623
623
  `;
624
- h = `${h.replace(/\}$/, "")}
624
+ y = `${y.replace(/\}$/, "")}
625
625
  ${E}
626
626
  }`;
627
627
  }
628
- }), x(g, h);
628
+ }), x(g, y);
629
629
  });
630
630
  else {
631
631
  const $ = a.flat().map((b) => `@import url('./${b}');`).join(`
632
- `), d = I(t, 6), c = rt(t), g = J(c.name), h = u(n, `css/f_${g}-${d}.css`);
633
- x(h, $ || "/* Empty file */");
632
+ `), d = I(t, 6), c = rt(t), g = J(c.name), y = u(n, `css/f_${g}-${d}.css`);
633
+ x(y, $ || "/* Empty file */");
634
634
  }
635
635
  }
636
636
  } catch (n) {
@@ -643,14 +643,14 @@ ${E}
643
643
  if (Z(t)) {
644
644
  const m = R(t, "utf8"), $ = await gt(e), { contents: d } = await at(e, t, a);
645
645
  let c = m;
646
- for (const [g, h] of Object.entries(d)) {
647
- if (h.isKeyframes || !h.generator) continue;
648
- const b = h.generator._withBuildContext({
646
+ for (const [g, y] of Object.entries(d)) {
647
+ if (y.isKeyframes || !y.generator) continue;
648
+ const b = y.generator._withBuildContext({
649
649
  callerName: g,
650
650
  isProduction: s,
651
651
  config: $
652
652
  }), [p, f] = await ae(c, g), w = c.slice(p, f);
653
- if (h.isClassName) {
653
+ if (y.isClassName) {
654
654
  const F = c, _ = ` ${g} = className("${b.classNames}")`;
655
655
  c = c.replace(w, _), F === c && console.error("Minimize file failed to change content", { name: g });
656
656
  }
@@ -660,8 +660,8 @@ ${E}
660
660
  }
661
661
  }
662
662
  if ($.importStrategy === "component") {
663
- const g = I(t, 6), h = rt(t);
664
- c = `import '../../saltygen/css/${`f_${J(h.name)}-${g}.css`}';
663
+ const g = I(t, 6), y = rt(t);
664
+ c = `import '../../saltygen/css/${`f_${J(y.name)}-${g}.css`}';
665
665
  ${c}`;
666
666
  }
667
667
  return c = c.replace("@salty-css/react/class-name", "@salty-css/react/class-name-client"), c = c.replace("{ styled }", "{ styledClient as styled }"), c = c.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), c;
@@ -673,8 +673,8 @@ ${c}`;
673
673
  if (!e || e.includes("node_modules") || e.includes("saltygen")) return !1;
674
674
  if (e.includes("salty.config")) return !0;
675
675
  if (!Z(e)) return !1;
676
- const n = await ht(e, "utf-8");
677
- return !!/.+define[A-Z]\w+/.test(n);
676
+ const n = await yt(e, "utf-8");
677
+ return !!(/.+define[A-Z]\w+/.test(n) || /.+keyframes\(.+/.test(n));
678
678
  }, je = (e) => ({
679
679
  name: "stylegen",
680
680
  buildStart: () => pe(e),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/vite",
3
- "version": "0.0.1-alpha.246",
3
+ "version": "0.0.1-alpha.247",
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.246"
37
+ "@salty-css/core": "^0.0.1-alpha.247"
38
38
  }
39
39
  }