@salty-css/vite 0.0.1-alpha.201 → 0.0.1-alpha.203

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 +25 -29
  2. package/index.js +361 -346
  3. package/package.json +2 -2
package/index.cjs CHANGED
@@ -1,44 +1,40 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const Nt=require("esbuild"),Pt=require("child_process"),l=require("path"),u=require("fs"),X=require("fs/promises"),G=require("winston");var nt=typeof document<"u"?document.currentScript:null;function kt(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 pt=kt(Nt),ft=t=>String.fromCharCode(t+(t>25?39:97)),_t=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=ft(n%52)+s;return s=ft(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},Dt=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},I=(t,e=5)=>{const s=Dt(5381,JSON.stringify(t))>>>0;return _t(s,e)};function E(t){return t?typeof t!="string"?E(String(t)):t.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?"-":"")+e.toLowerCase()):""}const Ot=(t,e)=>{if(typeof t!="string")return{result:t};if(!e)return{result:t};const s=[];return Object.values(e).forEach(n=>{const{pattern:o,transform:a}=n;t=t.replace(o,i=>{const{value:p,css:r}=a(i);return r&&s.push(r),p})}),{result:t,additionalCss:s}},yt=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${E(n[1].replaceAll(".","-"))})`)}:{result:t},Tt=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Et=(t,e,s)=>Tt.some(o=>typeof o=="string"?o===t:o.test(t))?`${e}px`:`${e}`,Mt=["Webkit","Moz","ms","O"],Rt=t=>t.startsWith("-")?t:Mt.some(e=>t.startsWith(e))?`-${E(t)}`:E(t),z=(t,e,s)=>{if(!t)return"";const n=[],o=Object.entries(t).reduce((i,[p,r])=>{const c=p.trim(),g=Rt(c),h=(j,_=";")=>i=`${i}${j}${_}`,y=j=>h(`${g}:${j}`);if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return i;if(r.isColor)return y(r.toString()),i;if(c==="variants")return Object.entries(r).forEach(([D,x])=>{x&&Object.entries(x).forEach(([T,P])=>{if(!P)return;const M=`${e}.${D}-${T}`,f=z(P,M);n.push(f)})}),i;if(c==="defaultVariants")return i;if(c==="compoundVariants")return r.forEach(D=>{const{css:x,...T}=D,P=Object.entries(T).reduce((f,[m,b])=>`${f}.${m}-${b}`,e),M=z(x,P);n.push(M)}),i;if(c.startsWith("@")){const D=c,x=z(r,e),T=`${D} {
2
- ${x.replace(`
3
- `,`
4
- `)}
5
- }`;return n.push(T),i}const j=p.includes("&")?c.replace("&",e):c.startsWith(":")?`${e}${c}`:`${e} ${c}`,_=z(r,j);return n.push(_),i}if(typeof r=="number"){const j=Et(g,r);return y(j)}if(typeof r!="string")if("toString"in r)r=r.toString();else return i;const{modifiers:$}={},O=function*(){yield yt(r),yield Ot(r,$)}();for(const{result:j,additionalCss:_=[]}of O)r=j,_.forEach(D=>{const x=z(D,"");h(x,"")});return y(r)},"");return o?e?[`${e} { ${o} }`,...n].join(`
6
- `):o:n.join(`
7
- `)},gt=(t,e=[])=>{if(!t)return"";const s=[],n={};if(Object.entries(t).forEach(([o,a])=>{if(typeof a=="object"){if(!a)return;const i=o.trim(),p=gt(a,[...e,i]);s.push(p)}else n[o]=a}),Object.keys(n).length){const o=e.map(E).join("-"),a=z(n,`.${o}`);s.push(a)}return s.join(`
8
- `)},Vt=t=>t?Object.entries(t).reduce((e,[s,n])=>(typeof n=="object"&&(e[s]=ht(n).map(o=>`"${o}"`).join(" | ")),e),{}):{},ht=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const a=e?`${e}.${n}`:n;return typeof o=="object"?ht(o,a,s):s.add(e)}),[...s]):[],mt=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=l.join(t,"package.json");return u.existsSync(e)?e:mt(l.join(t,".."))},zt=async t=>{const e=mt(t);return await X.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},Jt=async t=>{const e=await zt(t);if(e)return e.type};let A;const St=async t=>{if(A)return A;const e=await Jt(t);return e==="module"?A="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:nt&&nt.tagName.toUpperCase()==="SCRIPT"&&nt.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(A="cjs"),A||"esm"},ot=G.createLogger({level:"debug",format:G.format.combine(G.format.colorize(),G.format.cli()),transports:[new G.transports.Console({})]});function bt(t){return t?typeof t!="string"?bt(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 Wt={"*, *::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"}},Z=(...t)=>t.flat().reduce((e,s)=>s!=null&&s._current?{...e,...s._current}:{...e,...s},{}),V={externalModules:[],rcFile:void 0,destDir:void 0},$t=t=>{if(V.externalModules.length>0)return V.externalModules;const s=u.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return V.externalModules=n,n},J=async t=>{if(V.destDir)return V.destDir;const e=await rt(t),s=l.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return V.destDir=s,s},jt=["salty","css","styles","styled"],At=(t=[])=>new RegExp(`\\.(${[...jt,...t].join("|")})\\.`),q=(t,e=[])=>At(e).test(t),wt=async t=>{if(V.rcFile)return V.rcFile;if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=l.join(t,".saltyrc.json"),s=await X.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(V.rcFile=s,s):wt(l.join(t,".."))},rt=async t=>{var n,o;const e=await wt(t),s=(n=e.projects)==null?void 0:n.find(a=>t.endsWith(a.dir||""));return s||((o=e.projects)==null?void 0:o.find(a=>a.dir===e.defaultProject))},Zt=async t=>{const e=await rt(t),s=await J(t),n=l.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),o=l.join(s,"salty.config.js"),a=await St(t),i=$t(n);await pt.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:a,external:i});const p=Date.now(),{config:r}=await import(`${o}?t=${p}`);return r},It=async(t,e)=>{var at,lt;const s=await J(t),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...e].map(async w=>{const F=await Y(t,w,s);Object.entries(F).forEach(([R,C])=>{C.isMedia?n.mediaQueries.push([R,C]):C.isGlobalDefine?n.globalStyles.push(C):C.isDefineVariables?n.variables.push(C):C.isDefineTemplates&&n.templates.push(C)})}));const o=await Zt(t),a={...o},i=new Set,p=(w,F=[])=>w?Object.entries(w).flatMap(([R,C])=>{if(!C)return;if(typeof C=="object")return p(C,[...F,R]);const v=bt(R),tt=E(R),et=[...F,v].join(".");i.add(`"${et}"`);const st=[...F.map(E),tt].join("-"),{result:xt}=yt(C);return`--${st}: ${xt};`}):[],r=w=>w?Object.entries(w).flatMap(([F,R])=>{const C=p(R);return F==="base"?C.join(""):`${F} { ${C.join("")} }`}):[],c=w=>w?Object.entries(w).flatMap(([F,R])=>Object.entries(R).flatMap(([C,v])=>{const tt=p(v,[F]),et=`.${F}-${C}, [data-${F}="${C}"]`,st=tt.join("");return`${et} { ${st} }`})):[],g=w=>({...w,responsive:void 0,conditional:void 0}),h=w=>n.variables.map(F=>w==="static"?g(F._current):F._current[w]),y=Z(g(o.variables),h("static")),$=p(y),S=Z((at=o.variables)==null?void 0:at.responsive,h("responsive")),O=r(S),j=Z((lt=o.variables)==null?void 0:lt.conditional,h("conditional")),_=c(j),D=l.join(s,"css/_variables.css"),x=`:root { ${$.join("")} ${O.join("")} } ${_.join("")}`;u.writeFileSync(D,x),a.staticVariables=y;const T=l.join(s,"css/_global.css"),P=Z(o.global,n.globalStyles),M=z(P,"");u.writeFileSync(T,`@layer global { ${M} }`);const f=l.join(s,"css/_reset.css"),b=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:Wt,d=z(b,"");u.writeFileSync(f,`@layer reset { ${d} }`);const N=l.join(s,"css/_templates.css"),k=Z(o.templates,n.templates),H=gt(k),L=Vt(k);u.writeFileSync(N,H),a.templates=k;const{mediaQueries:W}=n;a.mediaQueries=Object.fromEntries(W.map(([w,F])=>[`@${w}`,F]));const K=W.map(([w])=>`'@${w}'`).join(" | "),U=l.join(s,"types/css-tokens.d.ts"),B=`
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const kt=require("esbuild"),_t=require("child_process"),c=require("path"),d=require("fs"),tt=require("fs/promises"),B=require("winston");var rt=typeof document<"u"?document.currentScript:null;function Dt(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 mt=Dt(kt),dt=t=>String.fromCharCode(t+(t>25?39:97)),Ot=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=dt(n%52)+s;return s=dt(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},Tt=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},W=(t,e=5)=>{const s=Tt(5381,JSON.stringify(t))>>>0;return Ot(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 Et=t=>e=>{if(typeof e!="string"||!t)return;let s=e;const n=[];return Object.values(t).forEach(o=>{const{pattern:i,transform:l}=o;s=s.replace(i,y=>{const{value:w,css:a}=l(y);return a&&n.push(a),w})}),{transformed:s,additionalCss:n}},gt=t=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...o)=>`var(--${M(o[1].replaceAll(".","-"))})`)},Mt=gt(),Rt=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Vt=(t,e,s)=>Rt.some(o=>typeof o=="string"?o===t:o.test(t))?`${e}px`:`${e}`,vt=["Webkit","Moz","ms","O"],Jt=t=>t.startsWith("-")?t:vt.some(e=>t.startsWith(e))?`-${M(t)}`:M(t),Y=async(t,e="",s)=>{if(!t)throw new Error("No styles provided to parseStyles function!");const n=new Set,i=Object.entries(t).map(async([g,r])=>{const p=g.trim(),h=Jt(p),N=(P,T=";")=>`${h}:${P}${T}`;if(typeof r=="function"&&(r=r({scope:e,config:s})),r instanceof Promise&&(r=await r),typeof r=="object"){if(!r)return;if(r.isColor)return N(r.toString());if(p==="defaultVariants")return;if(p==="variants"){const F=Object.entries(r);for(const[D,x]of F){if(!x)return;const R=Object.entries(x);for(const[f,m]of R){if(!m)return;const b=`${e}.${D}-${f}`;(await Y(m,b,s)).forEach(C=>n.add(C))}}return}if(p==="compoundVariants"){for(const F of r){const{css:D,...x}=F,R=Object.entries(x).reduce((m,[b,u])=>`${m}.${b}-${u}`,e);(await Y(D,R,s)).forEach(m=>n.add(m))}return}if(p.startsWith("@")){const F=p,D=await G(r,e,s),x=`${F} { ${D} }`;n.add(x);return}const P=g.includes("&")?p.replace("&",e):p.startsWith(":")?`${e}${p}`:`${e} ${p}`;(await Y(r,P,s)).forEach(F=>n.add(F));return}if(typeof r=="number"){const P=Vt(h,r);return N(P)}if(typeof r!="string")if("toString"in r)r=r.toString();else throw new Error(`Invalid value type for property ${h}`);return N(r)}),{modifiers:l}={},y=[gt(),Et(l)],a=(await Promise.all(i).then(g=>Promise.all(g.map(r=>y.reduce(async(p,h)=>{const N=await p;if(!N)return N;const _=await h(N);if(!_)return N;const{transformed:P,additionalCss:T}=_;let F="";if(T)for(const D of T)F+=await G(D,"");return`${F}${P}`},Promise.resolve(r)))))).join(`
2
+ `);if(!a.trim())return n;const S=e?`${e} { ${a} }`:a;return n.add(S),n},G=async(t,e,s)=>[...await Y(t,e,s)].join(`
3
+ `),ht=async(t,e=[])=>{if(!t)return"";const s=[],n={};for(const[o,i]of Object.entries(t))if(typeof i=="function")console.log("Function found",o);else if(i&&typeof i=="object"){const l=o.trim(),y=await ht(i,[...e,l]);s.push(y)}else n[o]=i;if(Object.keys(n).length){const o=e.map(M).join("-"),i=await G(n,`.${o}`);s.push(i)}return s.join(`
4
+ `)},zt=t=>t?Object.entries(t).reduce((e,[s,n])=>(typeof n=="object"&&(e[s]=wt(n).map(o=>`"${o}"`).join(" | ")),e),{}):{},wt=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const i=e?`${e}.${n}`:n;return typeof o=="object"?wt(o,i,s):s.add(e)}),[...s]):[],St=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:St(c.join(t,".."))},At=async t=>{const e=St(t);return await tt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},Wt=async t=>{const e=await At(t);if(e)return e.type};let z;const bt=async t=>{if(z)return z;const e=await Wt(t);return e==="module"?z="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:rt&&rt.tagName.toUpperCase()==="SCRIPT"&&rt.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(z="cjs"),z||"esm"},it=B.createLogger({level:"debug",format:B.format.combine(B.format.colorize(),B.format.cli()),transports:[new B.transports.Console({})]});function $t(t){return t?typeof t!="string"?$t(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 It={"*, *::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"}},A=(...t)=>t.flat().reduce((e,s)=>s!=null&&s._current?{...e,...s._current}:{...e,...s},{}),Zt=(...t)=>t.flat().reduce((e,s)=>({...e,...s._children}),{}),v={externalModules:[],rcFile:void 0,destDir:void 0},jt=t=>{if(v.externalModules.length>0)return v.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 v.externalModules=n,n},J=async t=>{if(v.destDir)return v.destDir;const e=await at(t),s=c.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return v.destDir=s,s},Ft=["salty","css","styles","styled"],qt=(t=[])=>new RegExp(`\\.(${[...Ft,...t].join("|")})\\.`),I=(t,e=[])=>qt(e).test(t),Ct=async t=>{if(v.rcFile)return v.rcFile;if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=c.join(t,".saltyrc.json"),s=await tt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(v.rcFile=s,s):Ct(c.join(t,".."))},at=async t=>{var n,o;const e=await Ct(t),s=(n=e.projects)==null?void 0:n.find(i=>t.endsWith(i.dir||""));return s||((o=e.projects)==null?void 0:o.find(i=>i.dir===e.defaultProject))},Ht=async t=>{const e=await at(t),s=await J(t),n=c.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),o=c.join(s,"salty.config.js"),i=await bt(t),l=jt(n);await mt.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:i,external:l});const y=Date.now(),{config:w}=await import(`${o}?t=${y}`);return w},Lt=async(t,e)=>{var lt,ft;const s=await J(t),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...e].map(async $=>{const{contents:j,outputFilePath:V}=await et(t,$,s);Object.entries(j).forEach(([O,E])=>{E.isMedia?n.mediaQueries.push([O,E]):E.isGlobalDefine?n.globalStyles.push(E):E.isDefineVariables?n.variables.push(E):E.isDefineTemplates&&n.templates.push(E._setPath(V))})}));const o=await Ht(t),i={...o},l=new Set,y=($,j=[])=>$?Object.entries($).flatMap(([V,O])=>{if(!O)return;if(typeof O=="object")return y(O,[...j,V]);const E=$t(V),nt=M(V),ot=[...j,E].join(".");l.add(`"${ot}"`);const X=[...j.map(M),nt].join("-"),ut=Mt(O);return ut?`--${X}: ${ut.transformed};`:`--${X}: ${O};`}):[],w=$=>$?Object.entries($).flatMap(([j,V])=>{const O=y(V);return j==="base"?O.join(""):`${j} { ${O.join("")} }`}):[],a=$=>$?Object.entries($).flatMap(([j,V])=>Object.entries(V).flatMap(([O,E])=>{const nt=y(E,[j]),ot=`.${j}-${O}, [data-${j}="${O}"]`,X=nt.join("");return`${ot} { ${X} }`})):[],S=$=>({...$,responsive:void 0,conditional:void 0}),g=$=>n.variables.map(j=>$==="static"?S(j._current):j._current[$]),r=A(S(o.variables),g("static")),p=y(r),h=A((lt=o.variables)==null?void 0:lt.responsive,g("responsive")),N=w(h),_=A((ft=o.variables)==null?void 0:ft.conditional,g("conditional")),P=a(_),T=c.join(s,"css/_variables.css"),F=`:root { ${p.join("")} ${N.join("")} } ${P.join("")}`;d.writeFileSync(T,F),i.staticVariables=r;const D=c.join(s,"css/_global.css"),x=A(o.global,n.globalStyles),R=await G(x,"");d.writeFileSync(D,`@layer global { ${R} }`);const f=c.join(s,"css/_reset.css"),b=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:It,u=await G(b,"");d.writeFileSync(f,`@layer reset { ${u} }`);const C=c.join(s,"css/_templates.css"),k=A(o.templates,n.templates),Z=await ht(k),q=zt(k);d.writeFileSync(C,Z),i.templates=k;const H=Zt(n.templates);i.templatePaths=Object.fromEntries(Object.entries(H).map(([$,j])=>[$,j._path||"nope"]));const{mediaQueries:L}=n;i.mediaQueries=Object.fromEntries(L.map(([$,j])=>[`@${$}`,j]));const K=L.map(([$])=>`'@${$}'`).join(" | "),st=c.join(s,"types/css-tokens.d.ts"),Q=`
9
5
  // Variable types
10
- type VariableTokens = ${[...i].join("|")};
6
+ type VariableTokens = ${[...l].join("|")};
11
7
  type PropertyValueToken = \`{\${VariableTokens}}\`;
12
8
 
13
9
  // Template types
14
10
  type TemplateTokens = {
15
- ${Object.entries(L).map(([w,F])=>`${w}?: ${F}`).join(`
11
+ ${Object.entries(q).map(([$,j])=>`${$}?: ${j}`).join(`
16
12
  `)}
17
13
  }
18
14
 
19
15
  // Media query types
20
16
  type MediaQueryKeys = ${K||"''"};
21
- `;u.writeFileSync(U,B);const Q=l.join(s,"cache/config-cache.json");u.writeFileSync(Q,JSON.stringify(a,null,2))},ut=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 p=i.at(1);if(jt.some(c=>p==null?void 0:p.includes(c)))return e}return"styled('div',"}),qt=(t,e)=>{try{const s=u.readFileSync(l.join(e,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
17
+ `;d.writeFileSync(st,Q);const Pt=c.join(s,"cache/config-cache.json");d.writeFileSync(Pt,JSON.stringify(i,null,2))},pt=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 l=o.exec(t);if(l){const y=l.at(1);if(Ft.some(a=>y==null?void 0:y.includes(a)))return e}return"styled('div',"}),Bt=(t,e)=>{try{const s=d.readFileSync(c.join(e,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
22
18
 
23
19
  ${t}`:`globalThis.saltyConfig = {};
24
20
 
25
- ${t}`}catch{return t}},Y=async(t,e,s)=>{const n=I(e),o=l.join(s,"./temp");u.existsSync(o)||u.mkdirSync(o);const a=l.parse(e);let i=u.readFileSync(e,"utf8");i=ut(i),i=qt(i,t);const p=l.join(s,"js",n+".js"),r=await rt(t),c=l.join(t,(r==null?void 0:r.configDir)||"","salty.config.ts"),g=$t(c),h=await St(t);await pt.build({stdin:{contents:i,sourcefile:a.base,resolveDir:a.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:p,format:h,target:["node20"],keepNames:!0,external:g,packages:"external",plugins:[{name:"test",setup:S=>{S.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},O=>{const j=u.readFileSync(O.path,"utf8");return{contents:ut(j),loader:"ts"}})}}]});const y=Date.now();return await import(`${p}?t=${y}`)},Ht=async t=>{const e=await J(t),s=l.join(e,"cache/config-cache.json"),n=u.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},it=async t=>{const e=await Ht(t),s=await J(t),n=l.join(s,"salty.config.js"),o=Date.now(),{config:a}=await import(`${n}?t=${o}`);return Z(a,e)},Ft=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Lt=async(t,e=Ft(),s=!0)=>{try{const n=Date.now();e?ot.info("Generating CSS in production mode! 🔥"):ot.info("Generating CSS in development mode! 🚀");const o=[],a=[],i=await J(t),p=l.join(i,"index.css");s&&(()=>{u.existsSync(i)&&Pt.execSync("rm -rf "+i),u.mkdirSync(i,{recursive:!0}),u.mkdirSync(l.join(i,"css")),u.mkdirSync(l.join(i,"types")),u.mkdirSync(l.join(i,"js")),u.mkdirSync(l.join(i,"cache"))})();const c=new Set,g=new Set;async function h(f){const m=["node_modules","saltygen"],b=u.statSync(f);if(b.isDirectory()){const d=u.readdirSync(f);if(m.some(k=>f.includes(k)))return;await Promise.all(d.map(k=>h(l.join(f,k))))}else if(b.isFile()&&q(f)){c.add(f);const N=u.readFileSync(f,"utf8");/define[\w\d]+\(/.test(N)&&g.add(f)}}await h(t),await It(t,g);const y={keyframes:[],components:[],classNames:[]};await Promise.all([...c].map(async f=>{const m=await Y(t,f,i);Object.entries(m).forEach(([b,d])=>{d.isKeyframes?y.keyframes.push({value:d,src:f,name:b}):d.isClassName?y.classNames.push({...d,src:f,name:b}):d.generator&&y.components.push({...d,src:f,name:b})})}));const $=await it(t);for(const f of y.keyframes){const{value:m}=f,b=`a_${m.animationName}.css`,d=`css/${b}`,N=l.join(i,d);o.push(b),u.writeFileSync(N,m.css)}const S={};for(const f of y.components){const{src:m,name:b}=f,d=f.generator._withBuildContext({callerName:b,isProduction:e,config:$});a[d.priority]||(a[d.priority]=[]),a[d.priority].push(d.cssFileName);const N=`css/${d.cssFileName}`,k=l.join(i,N);u.writeFileSync(k,d.css),$.importStrategy==="component"&&(S[m]?S[m].push(d.cssFileName):S[m]=[d.cssFileName])}for(const f of y.classNames){const{src:m,name:b}=f,d=f.generator._withBuildContext({callerName:b,isProduction:e,config:$});a[0].push(d.cssFileName);const N=`css/${d.cssFileName}`,k=l.join(i,N);u.writeFileSync(k,d.css),$.importStrategy==="component"&&(S[m]?S[m].push(d.cssFileName):S[m]=[d.cssFileName])}$.importStrategy==="component"&&Object.entries(S).forEach(([f,m])=>{const b=m.map(L=>`@import url('./${L}');`).join(`
26
- `),d=I(f,6),N=l.parse(f),k=E(N.name),H=l.join(i,`css/f_${k}-${d}.css`);u.writeFileSync(H,b)});const O=o.map(f=>`@import url('./css/${f}');`).join(`
27
- `);let x=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
21
+ ${t}`}catch{return t}},et=async(t,e,s)=>{const n=W(e),o=c.join(s,"./temp");d.existsSync(o)||d.mkdirSync(o);const i=c.parse(e);let l=d.readFileSync(e,"utf8");l=pt(l),l=Bt(l,t);const y=c.join(s,"js",n+".js"),w=await at(t),a=c.join(t,(w==null?void 0:w.configDir)||"","salty.config.ts"),S=jt(a),g=await bt(t);await mt.build({stdin:{contents:l,sourcefile:i.base,resolveDir:i.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:g,target:["node20"],keepNames:!0,external:S,packages:"external",plugins:[{name:"test",setup:h=>{h.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},N=>{const _=d.readFileSync(N.path,"utf8");return{contents:pt(_),loader:"ts"}})}}]});const r=Date.now();return{contents:await import(`${y}?t=${r}`),outputFilePath:y}},Gt=async t=>{const e=await J(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)},ct=async t=>{const e=await Gt(t),s=await J(t),n=c.join(s,"salty.config.js"),o=Date.now(),{config:i}=await import(`${n}?t=${o}`);return A(i,e)},xt=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Kt=async(t,e=xt(),s=!0)=>{try{const n=Date.now();e?it.info("Generating CSS in production mode! 🔥"):it.info("Generating CSS in development mode! 🚀");const o=[],i=[],l=await J(t),y=c.join(l,"index.css");s&&(()=>{d.existsSync(l)&&_t.execSync("rm -rf "+l),d.mkdirSync(l,{recursive:!0}),d.mkdirSync(c.join(l,"css")),d.mkdirSync(c.join(l,"types")),d.mkdirSync(c.join(l,"js")),d.mkdirSync(c.join(l,"cache"))})();const a=new Set,S=new Set;async function g(f){const m=["node_modules","saltygen"],b=d.statSync(f);if(b.isDirectory()){const u=d.readdirSync(f);if(m.some(k=>f.includes(k)))return;await Promise.all(u.map(k=>g(c.join(f,k))))}else if(b.isFile()&&I(f)){a.add(f);const C=d.readFileSync(f,"utf8");/define[\w\d]+\(/.test(C)&&S.add(f)}}await g(t),await Lt(t,S);const r={keyframes:[],components:[],classNames:[]};await Promise.all([...a].map(async f=>{const{contents:m}=await et(t,f,l);Object.entries(m).forEach(([b,u])=>{u.isKeyframes?r.keyframes.push({value:u,src:f,name:b}):u.isClassName?r.classNames.push({...u,src:f,name:b}):u.generator&&r.components.push({...u,src:f,name:b})})}));const p=await ct(t);for(const f of r.keyframes){const{value:m}=f,b=`a_${m.animationName}.css`,u=`css/${b}`,C=c.join(l,u);o.push(b),d.writeFileSync(C,m.css)}const h={};for(const f of r.components){const{src:m,name:b}=f,u=f.generator._withBuildContext({callerName:b,isProduction:e,config:p});i[u.priority]||(i[u.priority]=[]),i[u.priority].push(u.cssFileName);const C=`css/${u.cssFileName}`,k=c.join(l,C);d.writeFileSync(k,await u.css),p.importStrategy==="component"&&(h[m]?h[m].push(u.cssFileName):h[m]=[u.cssFileName])}for(const f of r.classNames){const{src:m,name:b}=f,u=f.generator._withBuildContext({callerName:b,isProduction:e,config:p});i[0].push(u.cssFileName);const C=`css/${u.cssFileName}`,k=c.join(l,C);d.writeFileSync(k,await u.css),p.importStrategy==="component"&&(h[m]?h[m].push(u.cssFileName):h[m]=[u.cssFileName])}p.importStrategy==="component"&&Object.entries(h).forEach(([f,m])=>{const b=m.map(q=>`@import url('./${q}');`).join(`
22
+ `),u=W(f,6),C=c.parse(f),k=M(C.name),Z=c.join(l,`css/f_${k}-${u}.css`);d.writeFileSync(Z,b)});const N=o.map(f=>`@import url('./css/${f}');`).join(`
23
+ `);let F=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
28
24
 
29
- ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(f=>{try{return u.readFileSync(l.join(i,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
25
+ ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(f=>{try{return d.readFileSync(c.join(l,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
30
26
  `)}
31
- ${O}`;if($.importStrategy!=="component"){const f=a.reduce((m,b,d)=>{const N=b.reduce((W,K)=>{var Q;const U=l.join(i,"css",K),ct=u.readFileSync(U,"utf8"),B=((Q=/.*-([^-]+)-\d+.css/.exec(K))==null?void 0:Q.at(1))||I(U,6);return W.includes(B)?W:`${W}
32
- /*start:${B}*/
33
- ${ct}
34
- /*end:${B}*/
35
- `},""),k=`l_${d}.css`,H=l.join(i,"css",k),L=`@layer l${d} { ${N}
36
- }`;return u.writeFileSync(H,L),`${m}
37
- @import url('./css/${k}');`},"");x+=f}u.writeFileSync(p,x);const P=Date.now()-n,M=P<200?"🔥":P<500?"🚀":P<1e3?"🎉":P<2e3?"🚗":P<5e3?"🤔":"🥴";ot.info(`Generated CSS in ${P}ms! ${M}`)}catch(n){console.error(n)}},Bt=async(t,e)=>{try{const s=await J(t);if(q(e)){const o=[],a=await it(t),i=await Y(t,e,s);if(Object.entries(i).forEach(([p,r])=>{if(r.isKeyframes&&r.css){const $=`css/${`a_${r.animationName}.css`}`,S=l.join(s,$);u.writeFileSync(S,r.css);return}if(r.isClassName){const y=r.factory._withBuildContext({name:p});o[0].push(y.cssFileName);const $=`css/${y.cssFileName}`,S=l.join(s,$);u.writeFileSync(S,y.css)}if(!r.generator)return;const c=r.generator._withBuildContext({name:p,config:a}),g=`css/${c.cssFileName}`,h=l.join(s,g);u.writeFileSync(h,c.css),o[c.priority]||(o[c.priority]=[]),o[c.priority].push(c.cssFileName)}),a.importStrategy!=="component")o.forEach((p,r)=>{const c=`l_${r}.css`,g=l.join(s,"css",c);let h=u.readFileSync(g,"utf8");p.forEach(y=>{var j;const $=l.join(s,"css",y),S=((j=/.*-([^-]+)-\d+.css/.exec(y))==null?void 0:j.at(1))||I($,6);if(!h.includes(S)){const _=u.readFileSync($,"utf8"),D=`/*start:${S}*/
38
- ${_}
39
- /*end:${S}*/
40
- `;h=`${h.replace(/\}$/,"")}
41
- ${D}
42
- }`}}),u.writeFileSync(g,h)});else{const p=o.flat().map(y=>`@import url('./${y}');`).join(`
43
- `),r=I(e,6),c=l.parse(e),g=E(c.name),h=l.join(s,`css/f_${g}-${r}.css`);u.writeFileSync(h,p)}}}catch(s){console.error(s)}},Gt=async(t,e,s=Ft())=>{try{const n=await J(t);if(q(e)){const a=u.readFileSync(e,"utf8");a.replace(/^(?!export\s)const\s.*/gm,g=>`export ${g}`)!==a&&await X.writeFile(e,a);const p=await it(t),r=await Y(t,e,n);let c=a;if(Object.entries(r).forEach(([g,h])=>{var d;if(h.isKeyframes||!h.generator)return;const y=h.generator._withBuildContext({name:g,config:p,prod:s}),$=new RegExp(`\\s${g}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(a);if(!$)return console.error("Could not find the original declaration");const S=(d=$.at(1))==null?void 0:d.trim(),O=new RegExp(`\\s${g}[=\\s]+styled\\(`,"g").exec(c);if(!O)return console.error("Could not find the original declaration");const{index:j}=O;let _=!1;const D=setTimeout(()=>_=!0,5e3);let x=0,T=!1,P=0;for(;!T&&!_;){const N=c[j+x];N==="("&&P++,N===")"&&P--,P===0&&N===")"&&(T=!0),x>c.length&&(_=!0),x++}if(!_)clearTimeout(D);else throw new Error("Failed to find the end of the styled call and timed out");const M=j+x,f=c.slice(j,M),m=c,b=` ${g} = styled(${S}, "${y.classNames}", ${JSON.stringify(y.clientProps)});`;c=c.replace(f,b),m===c&&console.error("Minimize file failed to change content",{name:g,tagName:S})}),p.importStrategy==="component"){const g=I(e,6),h=l.parse(e);c=`import '../../saltygen/css/${`f_${E(h.name)}-${g}.css`}';
44
- ${c}`}return c=c.replace("{ styled }","{ styledClient as styled }"),c=c.replace("@salty-css/react/styled","@salty-css/react/styled-client"),c}}catch(n){console.error("Error in minimizeFile:",n)}},dt=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 X.readFile(t,"utf-8");return!!/.+define[A-Z]\w+/.test(n)},Ct=t=>({name:"stylegen",buildStart:()=>Lt(t),load:async e=>{if(q(e))return await Gt(t,e)},handleHotUpdate:async({file:e,server:s})=>{await dt(e)&&await s.restart()},watchChange:{handler:async e=>{q(e)&&(await dt(e)||await Bt(t,e))}}});exports.default=Ct;exports.saltyPlugin=Ct;
27
+ ${N}`;if(p.importStrategy!=="component"){const f=i.reduce((m,b,u)=>{const C=b.reduce((H,L)=>{var Q;const K=c.join(l,"css",L),st=d.readFileSync(K,"utf8"),U=((Q=/.*-([^-]+)-\d+.css/.exec(L))==null?void 0:Q.at(1))||W(K,6);return H.includes(U)?H:`${H}
28
+ /*start:${U}*/
29
+ ${st}
30
+ /*end:${U}*/
31
+ `},""),k=`l_${u}.css`,Z=c.join(l,"css",k),q=`@layer l${u} { ${C}
32
+ }`;return d.writeFileSync(Z,q),`${m}
33
+ @import url('./css/${k}');`},"");F+=f}d.writeFileSync(y,F);const x=Date.now()-n,R=x<200?"🔥":x<500?"🚀":x<1e3?"🎉":x<2e3?"🚗":x<5e3?"🤔":"🥴";it.info(`Generated CSS in ${x}ms! ${R}`)}catch(n){console.error(n)}},Ut=async(t,e)=>{try{const s=await J(t);if(I(e)){const o=[],i=await ct(t),{contents:l}=await et(t,e,s);for(const[y,w]of Object.entries(l)){if(w.isKeyframes&&w.css){const p=`css/${`a_${w.animationName}.css`}`,h=c.join(s,p);d.writeFileSync(h,await w.css);return}if(w.isClassName){const r=w.factory._withBuildContext({name:y});o[0].push(r.cssFileName);const p=`css/${r.cssFileName}`,h=c.join(s,p);d.writeFileSync(h,await r.css)}if(!w.generator)return;const a=w.generator._withBuildContext({name:y,config:i}),S=`css/${a.cssFileName}`,g=c.join(s,S);d.writeFileSync(g,await a.css),o[a.priority]||(o[a.priority]=[]),o[a.priority].push(a.cssFileName)}if(i.importStrategy!=="component")o.forEach((y,w)=>{const a=`l_${w}.css`,S=c.join(s,"css",a);let g=d.readFileSync(S,"utf8");y.forEach(r=>{var _;const p=c.join(s,"css",r),h=((_=/.*-([^-]+)-\d+.css/.exec(r))==null?void 0:_.at(1))||W(p,6);if(!g.includes(h)){const P=d.readFileSync(p,"utf8"),T=`/*start:${h}*/
34
+ ${P}
35
+ /*end:${h}*/
36
+ `;g=`${g.replace(/\}$/,"")}
37
+ ${T}
38
+ }`}}),d.writeFileSync(S,g)});else{const y=o.flat().map(r=>`@import url('./${r}');`).join(`
39
+ `),w=W(e,6),a=c.parse(e),S=M(a.name),g=c.join(s,`css/f_${S}-${w}.css`);d.writeFileSync(g,y)}}}catch(s){console.error(s)}},Qt=async(t,e,s=xt())=>{try{const n=await J(t);if(I(e)){const i=d.readFileSync(e,"utf8");i.replace(/^(?!export\s)const\s.*/gm,S=>`export ${S}`)!==i&&await tt.writeFile(e,i);const y=await ct(t),{contents:w}=await et(t,e,n);let a=i;if(Object.entries(w).forEach(([S,g])=>{var u;if(g.isKeyframes||!g.generator)return;const r=g.generator._withBuildContext({name:S,config:y,prod:s}),p=new RegExp(`\\s${S}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(i);if(!p)return console.error("Could not find the original declaration");const h=(u=p.at(1))==null?void 0:u.trim(),N=new RegExp(`\\s${S}[=\\s]+styled\\(`,"g").exec(a);if(!N)return console.error("Could not find the original declaration");const{index:_}=N;let P=!1;const T=setTimeout(()=>P=!0,5e3);let F=0,D=!1,x=0;for(;!D&&!P;){const C=a[_+F];C==="("&&x++,C===")"&&x--,x===0&&C===")"&&(D=!0),F>a.length&&(P=!0),F++}if(!P)clearTimeout(T);else throw new Error("Failed to find the end of the styled call and timed out");const R=_+F,f=a.slice(_,R),m=a,b=` ${S} = styled(${h}, "${r.classNames}", ${JSON.stringify(r.clientProps)});`;a=a.replace(f,b),m===a&&console.error("Minimize file failed to change content",{name:S,tagName:h})}),y.importStrategy==="component"){const S=W(e,6),g=c.parse(e);a=`import '../../saltygen/css/${`f_${M(g.name)}-${S}.css`}';
40
+ ${a}`}return a=a.replace("{ styled }","{ styledClient as styled }"),a=a.replace("@salty-css/react/styled","@salty-css/react/styled-client"),a}}catch(n){console.error("Error in minimizeFile:",n)}},yt=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!I(t))return!1;const n=await tt.readFile(t,"utf-8");return!!/.+define[A-Z]\w+/.test(n)},Nt=t=>({name:"stylegen",buildStart:()=>Kt(t),load:async e=>{if(I(e))return await Qt(t,e)},handleHotUpdate:async({file:e,server:s})=>{await yt(e)&&await s.restart()},watchChange:{handler:async e=>{I(e)&&(await yt(e)||await Ut(t,e))}}});exports.default=Nt;exports.saltyPlugin=Nt;
package/index.js CHANGED
@@ -1,36 +1,36 @@
1
- import * as mt from "esbuild";
2
- import { execSync as kt } from "child_process";
3
- import { join as f, parse as Y } from "path";
4
- import { existsSync as it, mkdirSync as H, statSync as Dt, readdirSync as _t, readFileSync as O, writeFileSync as k } from "fs";
5
- import { readFile as ct, writeFile as Et } from "fs/promises";
6
- import { createLogger as Tt, format as ot, transports as Ot } from "winston";
7
- const pt = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), Vt = (t, e) => {
1
+ import * as $t from "esbuild";
2
+ import { execSync as _t } from "child_process";
3
+ import { join as u, parse as et } from "path";
4
+ import { existsSync as ct, mkdirSync as v, statSync as Et, readdirSync as Tt, readFileSync as V, writeFileSync as k } from "fs";
5
+ import { readFile as lt, writeFile as Ot } from "fs/promises";
6
+ import { createLogger as Vt, format as it, transports as Mt } from "winston";
7
+ const gt = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), Rt = (t, e) => {
8
8
  let s = "", n;
9
- for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = pt(n % 52) + s;
10
- return s = pt(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
11
- }, Mt = (t, e) => {
9
+ for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = gt(n % 52) + s;
10
+ return s = gt(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
11
+ }, Jt = (t, e) => {
12
12
  let s = e.length;
13
13
  for (; s; ) t = t * 33 ^ e.charCodeAt(--s);
14
14
  return t;
15
- }, B = (t, e = 5) => {
16
- const s = Mt(5381, JSON.stringify(t)) >>> 0;
17
- return Vt(s, e);
15
+ }, H = (t, e = 5) => {
16
+ const s = Jt(5381, JSON.stringify(t)) >>> 0;
17
+ return Rt(s, e);
18
18
  };
19
- function V(t) {
20
- return t ? typeof t != "string" ? V(String(t)) : t.replace(/[\s.]/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "-" : "") + e.toLowerCase()) : "";
19
+ function M(t) {
20
+ 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()) : "";
21
21
  }
22
- const Rt = (t, e) => {
23
- if (typeof t != "string") return { result: t };
24
- if (!e) return { result: t };
25
- const s = [];
26
- return Object.values(e).forEach((n) => {
27
- const { pattern: o, transform: a } = n;
28
- t = t.replace(o, (i) => {
29
- const { value: d, css: r } = a(i);
30
- return r && s.push(r), d;
22
+ const At = (t) => (e) => {
23
+ if (typeof e != "string" || !t) return;
24
+ let s = e;
25
+ const n = [];
26
+ return Object.values(t).forEach((o) => {
27
+ const { pattern: i, transform: c } = o;
28
+ s = s.replace(i, (p) => {
29
+ const { value: y, css: a } = c(p);
30
+ return a && n.push(a), y;
31
31
  });
32
- }), { result: t, additionalCss: s };
33
- }, yt = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${V(n[1].replaceAll(".", "-"))})`) } : { result: t }, Jt = [
32
+ }), { transformed: s, additionalCss: n };
33
+ }, wt = (t) => (e) => typeof e != "string" || !/\{[^{}]+\}/g.test(e) ? void 0 : { transformed: e.replace(/\{([^{}]+)\}/g, (...o) => `var(--${M(o[1].replaceAll(".", "-"))})`) }, Wt = wt(), zt = [
34
34
  "top",
35
35
  "right",
36
36
  "bottom",
@@ -51,106 +51,116 @@ const Rt = (t, e) => {
51
51
  /.*size.*/,
52
52
  /.*thickness.*/,
53
53
  /.*font-size.*/
54
- ], Wt = (t, e, s) => Jt.some((o) => typeof o == "string" ? o === t : o.test(t)) ? `${e}px` : `${e}`, zt = ["Webkit", "Moz", "ms", "O"], At = (t) => t.startsWith("-") ? t : zt.some((e) => t.startsWith(e)) ? `-${V(t)}` : V(t), W = (t, e, s) => {
55
- if (!t) return "";
56
- const n = [], o = Object.entries(t).reduce((i, [d, r]) => {
57
- const c = d.trim(), g = At(c), h = (w, D = ";") => i = `${i}${w}${D}`, p = (w) => h(`${g}:${w}`);
58
- if (typeof r == "function" && (r = r()), typeof r == "object") {
59
- if (!r) return i;
60
- if (r.isColor)
61
- return p(r.toString()), i;
62
- if (c === "variants")
63
- return Object.entries(r).forEach(([_, F]) => {
64
- F && Object.entries(F).forEach(([T, N]) => {
65
- if (!N) return;
66
- const M = `${e}.${_}-${T}`, l = W(N, M);
67
- n.push(l);
68
- });
69
- }), i;
70
- if (c === "defaultVariants")
71
- return i;
72
- if (c === "compoundVariants")
73
- return r.forEach((_) => {
74
- const { css: F, ...T } = _, N = Object.entries(T).reduce((l, [m, $]) => `${l}.${m}-${$}`, e), M = W(F, N);
75
- n.push(M);
76
- }), i;
77
- if (c.startsWith("@")) {
78
- const _ = c, F = W(r, e), T = `${_} {
79
- ${F.replace(`
80
- `, `
81
- `)}
82
- }`;
83
- return n.push(T), i;
54
+ ], vt = (t, e, s) => zt.some((o) => typeof o == "string" ? o === t : o.test(t)) ? `${e}px` : `${e}`, Zt = ["Webkit", "Moz", "ms", "O"], Ht = (t) => t.startsWith("-") ? t : Zt.some((e) => t.startsWith(e)) ? `-${M(t)}` : M(t), tt = async (t, e = "", s) => {
55
+ if (!t) throw new Error("No styles provided to parseStyles function!");
56
+ const n = /* @__PURE__ */ new Set(), i = Object.entries(t).map(async ([g, r]) => {
57
+ const d = g.trim(), h = Ht(d), x = (N, T = ";") => `${h}:${N}${T}`;
58
+ if (typeof r == "function" && (r = r({ scope: e, config: s })), r instanceof Promise && (r = await r), typeof r == "object") {
59
+ if (!r) return;
60
+ if (r.isColor) return x(r.toString());
61
+ if (d === "defaultVariants") return;
62
+ if (d === "variants") {
63
+ const S = Object.entries(r);
64
+ for (const [_, F] of S) {
65
+ if (!F) return;
66
+ const R = Object.entries(F);
67
+ for (const [l, m] of R) {
68
+ if (!m) return;
69
+ const w = `${e}.${_}-${l}`;
70
+ (await tt(m, w, s)).forEach((j) => n.add(j));
71
+ }
72
+ }
73
+ return;
74
+ }
75
+ if (d === "compoundVariants") {
76
+ for (const S of r) {
77
+ const { css: _, ...F } = S, R = Object.entries(F).reduce((m, [w, f]) => `${m}.${w}-${f}`, e);
78
+ (await tt(_, R, s)).forEach((m) => n.add(m));
79
+ }
80
+ return;
84
81
  }
85
- const w = d.includes("&") ? c.replace("&", e) : c.startsWith(":") ? `${e}${c}` : `${e} ${c}`, D = W(r, w);
86
- return n.push(D), i;
82
+ if (d.startsWith("@")) {
83
+ const S = d, _ = await Q(r, e, s), F = `${S} { ${_} }`;
84
+ n.add(F);
85
+ return;
86
+ }
87
+ const N = g.includes("&") ? d.replace("&", e) : d.startsWith(":") ? `${e}${d}` : `${e} ${d}`;
88
+ (await tt(r, N, s)).forEach((S) => n.add(S));
89
+ return;
87
90
  }
88
91
  if (typeof r == "number") {
89
- const w = Wt(g, r);
90
- return p(w);
92
+ const N = vt(h, r);
93
+ return x(N);
91
94
  }
92
95
  if (typeof r != "string")
93
96
  if ("toString" in r) r = r.toString();
94
- else return i;
95
- const { modifiers: b } = {}, E = function* () {
96
- yield yt(r), yield Rt(r, b);
97
- }();
98
- for (const { result: w, additionalCss: D = [] } of E)
99
- r = w, D.forEach((_) => {
100
- const F = W(_, "");
101
- h(F, "");
102
- });
103
- return p(r);
104
- }, "");
105
- return o ? e ? [`${e} { ${o} }`, ...n].join(`
106
- `) : o : n.join(`
97
+ else throw new Error(`Invalid value type for property ${h}`);
98
+ return x(r);
99
+ }), { modifiers: c } = {}, p = [wt(), At(c)], a = (await Promise.all(i).then((g) => Promise.all(
100
+ g.map((r) => p.reduce(async (d, h) => {
101
+ const x = await d;
102
+ if (!x) return x;
103
+ const D = await h(x);
104
+ if (!D) return x;
105
+ const { transformed: N, additionalCss: T } = D;
106
+ let S = "";
107
+ if (T)
108
+ for (const _ of T)
109
+ S += await Q(_, "");
110
+ return `${S}${N}`;
111
+ }, Promise.resolve(r)))
112
+ ))).join(`
107
113
  `);
108
- }, $t = (t, e = []) => {
114
+ if (!a.trim()) return n;
115
+ const $ = e ? `${e} { ${a} }` : a;
116
+ return n.add($), n;
117
+ }, Q = async (t, e, s) => [...await tt(t, e, s)].join(`
118
+ `), bt = async (t, e = []) => {
109
119
  if (!t) return "";
110
120
  const s = [], n = {};
111
- if (Object.entries(t).forEach(([o, a]) => {
112
- if (typeof a == "object") {
113
- if (!a) return;
114
- const i = o.trim(), d = $t(a, [...e, i]);
115
- s.push(d);
121
+ for (const [o, i] of Object.entries(t))
122
+ if (typeof i == "function") console.log("Function found", o);
123
+ else if (i && typeof i == "object") {
124
+ const c = o.trim(), p = await bt(i, [...e, c]);
125
+ s.push(p);
116
126
  } else
117
- n[o] = a;
118
- }), Object.keys(n).length) {
119
- const o = e.map(V).join("-"), a = W(n, `.${o}`);
120
- s.push(a);
127
+ n[o] = i;
128
+ if (Object.keys(n).length) {
129
+ const o = e.map(M).join("-"), i = await Q(n, `.${o}`);
130
+ s.push(i);
121
131
  }
122
132
  return s.join(`
123
133
  `);
124
- }, Zt = (t) => t ? Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = bt(n).map((o) => `"${o}"`).join(" | ")), e), {}) : {}, bt = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, o]) => {
125
- const a = e ? `${e}.${n}` : n;
126
- return typeof o == "object" ? bt(o, a, s) : s.add(e);
127
- }), [...s]) : [], wt = (t) => {
134
+ }, It = (t) => t ? Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = Ct(n).map((o) => `"${o}"`).join(" | ")), e), {}) : {}, Ct = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, o]) => {
135
+ const i = e ? `${e}.${n}` : n;
136
+ return typeof o == "object" ? Ct(o, i, s) : s.add(e);
137
+ }), [...s]) : [], St = (t) => {
128
138
  if (!t || t === "/") throw new Error("Could not find package.json file");
129
- const e = f(t, "package.json");
130
- return it(e) ? e : wt(f(t, ".."));
131
- }, Ht = async (t) => {
132
- const e = wt(t);
133
- return await ct(e, "utf-8").then(JSON.parse).catch(() => {
139
+ const e = u(t, "package.json");
140
+ return ct(e) ? e : St(u(t, ".."));
141
+ }, Bt = async (t) => {
142
+ const e = St(t);
143
+ return await lt(e, "utf-8").then(JSON.parse).catch(() => {
134
144
  });
135
- }, It = async (t) => {
136
- const e = await Ht(t);
145
+ }, Gt = async (t) => {
146
+ const e = await Bt(t);
137
147
  if (e)
138
148
  return e.type;
139
149
  };
140
- let Z;
141
- const St = async (t) => {
142
- if (Z) return Z;
143
- const e = await It(t);
144
- return e === "module" ? Z = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (Z = "cjs"), Z || "esm";
145
- }, rt = Tt({
150
+ let z;
151
+ const jt = async (t) => {
152
+ if (z) return z;
153
+ const e = await Gt(t);
154
+ return e === "module" ? z = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (z = "cjs"), z || "esm";
155
+ }, at = Vt({
146
156
  level: "debug",
147
- format: ot.combine(ot.colorize(), ot.cli()),
148
- transports: [new Ot.Console({})]
157
+ format: it.combine(it.colorize(), it.cli()),
158
+ transports: [new Mt.Console({})]
149
159
  });
150
- function Ct(t) {
151
- return t ? typeof t != "string" ? Ct(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "." : "") + e.toLowerCase()) : "";
160
+ function Ft(t) {
161
+ return t ? typeof t != "string" ? Ft(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "." : "") + e.toLowerCase()) : "";
152
162
  }
153
- const Bt = {
163
+ const Kt = {
154
164
  /** Set box model to border-box */
155
165
  "*, *::before, *::after": {
156
166
  boxSizing: "border-box"
@@ -196,112 +206,116 @@ const Bt = {
196
206
  fontSize: "100%",
197
207
  lineHeight: "1.15em"
198
208
  }
199
- }, I = (...t) => t.flat().reduce((e, s) => s != null && s._current ? { ...e, ...s._current } : { ...e, ...s }, {}), J = {
209
+ }, Z = (...t) => t.flat().reduce((e, s) => s != null && s._current ? { ...e, ...s._current } : { ...e, ...s }, {}), Lt = (...t) => t.flat().reduce((e, s) => ({ ...e, ...s._children }), {}), A = {
200
210
  externalModules: [],
201
211
  rcFile: void 0,
202
212
  destDir: void 0
203
- }, jt = (t) => {
204
- if (J.externalModules.length > 0) return J.externalModules;
205
- const s = O(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
213
+ }, xt = (t) => {
214
+ if (A.externalModules.length > 0) return A.externalModules;
215
+ const s = V(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
206
216
  if (!s) return [];
207
217
  const n = s[1].split(",").map((o) => o.replace(/['"`]/g, "").trim());
208
- return J.externalModules = n, n;
209
- }, z = async (t) => {
210
- if (J.destDir) return J.destDir;
211
- const e = await at(t), s = f(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
212
- return J.destDir = s, s;
213
- }, Ft = ["salty", "css", "styles", "styled"], Gt = (t = []) => new RegExp(`\\.(${[...Ft, ...t].join("|")})\\.`), G = (t, e = []) => Gt(e).test(t), xt = async (t) => {
214
- if (J.rcFile) return J.rcFile;
218
+ return A.externalModules = n, n;
219
+ }, W = async (t) => {
220
+ if (A.destDir) return A.destDir;
221
+ const e = await ft(t), s = u(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
222
+ return A.destDir = s, s;
223
+ }, Nt = ["salty", "css", "styles", "styled"], Qt = (t = []) => new RegExp(`\\.(${[...Nt, ...t].join("|")})\\.`), I = (t, e = []) => Qt(e).test(t), Pt = async (t) => {
224
+ if (A.rcFile) return A.rcFile;
215
225
  if (t === "/") throw new Error("Could not find .saltyrc.json file");
216
- const e = f(t, ".saltyrc.json"), s = await ct(e, "utf-8").then(JSON.parse).catch(() => {
226
+ const e = u(t, ".saltyrc.json"), s = await lt(e, "utf-8").then(JSON.parse).catch(() => {
217
227
  });
218
- return s ? (J.rcFile = s, s) : xt(f(t, ".."));
219
- }, at = async (t) => {
228
+ return s ? (A.rcFile = s, s) : Pt(u(t, ".."));
229
+ }, ft = async (t) => {
220
230
  var n, o;
221
- const e = await xt(t), s = (n = e.projects) == null ? void 0 : n.find((a) => t.endsWith(a.dir || ""));
222
- return s || ((o = e.projects) == null ? void 0 : o.find((a) => a.dir === e.defaultProject));
223
- }, Kt = async (t) => {
224
- const e = await at(t), s = await z(t), n = f(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), o = f(s, "salty.config.js"), a = await St(t), i = jt(n);
225
- await mt.build({
231
+ const e = await Pt(t), s = (n = e.projects) == null ? void 0 : n.find((i) => t.endsWith(i.dir || ""));
232
+ return s || ((o = e.projects) == null ? void 0 : o.find((i) => i.dir === e.defaultProject));
233
+ }, Ut = async (t) => {
234
+ const e = await ft(t), s = await W(t), n = u(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), o = u(s, "salty.config.js"), i = await jt(t), c = xt(n);
235
+ await $t.build({
226
236
  entryPoints: [n],
227
237
  minify: !0,
228
238
  treeShaking: !0,
229
239
  bundle: !0,
230
240
  outfile: o,
231
- format: a,
232
- external: i
241
+ format: i,
242
+ external: c
233
243
  });
234
- const d = Date.now(), { config: r } = await import(`${o}?t=${d}`);
235
- return r;
236
- }, Lt = async (t, e) => {
237
- var ut, dt;
238
- const s = await z(t), n = {
244
+ const p = Date.now(), { config: y } = await import(`${o}?t=${p}`);
245
+ return y;
246
+ }, qt = async (t, e) => {
247
+ var dt, pt;
248
+ const s = await W(t), n = {
239
249
  mediaQueries: [],
240
250
  globalStyles: [],
241
251
  variables: [],
242
252
  templates: []
243
253
  };
244
254
  await Promise.all(
245
- [...e].map(async (S) => {
246
- const C = await v(t, S, s);
247
- Object.entries(C).forEach(([R, j]) => {
248
- j.isMedia ? n.mediaQueries.push([R, j]) : j.isGlobalDefine ? n.globalStyles.push(j) : j.isDefineVariables ? n.variables.push(j) : j.isDefineTemplates && n.templates.push(j);
255
+ [...e].map(async (b) => {
256
+ const { contents: C, outputFilePath: J } = await st(t, b, s);
257
+ Object.entries(C).forEach(([E, O]) => {
258
+ O.isMedia ? n.mediaQueries.push([E, O]) : O.isGlobalDefine ? n.globalStyles.push(O) : O.isDefineVariables ? n.variables.push(O) : O.isDefineTemplates && n.templates.push(O._setPath(J));
249
259
  });
250
260
  })
251
261
  );
252
- const o = await Kt(t), a = { ...o }, i = /* @__PURE__ */ new Set(), d = (S, C = []) => S ? Object.entries(S).flatMap(([R, j]) => {
253
- if (!j) return;
254
- if (typeof j == "object") return d(j, [...C, R]);
255
- const tt = Ct(R), et = V(R), st = [...C, tt].join(".");
256
- i.add(`"${st}"`);
257
- const nt = [...C.map(V), et].join("-"), { result: Pt } = yt(j);
258
- return `--${nt}: ${Pt};`;
259
- }) : [], r = (S) => S ? Object.entries(S).flatMap(([C, R]) => {
260
- const j = d(R);
261
- return C === "base" ? j.join("") : `${C} { ${j.join("")} }`;
262
- }) : [], c = (S) => S ? Object.entries(S).flatMap(([C, R]) => Object.entries(R).flatMap(([j, tt]) => {
263
- const et = d(tt, [C]), st = `.${C}-${j}, [data-${C}="${j}"]`, nt = et.join("");
264
- return `${st} { ${nt} }`;
265
- })) : [], g = (S) => ({ ...S, responsive: void 0, conditional: void 0 }), h = (S) => n.variables.map((C) => S === "static" ? g(C._current) : C._current[S]), p = I(g(o.variables), h("static")), b = d(p), y = I((ut = o.variables) == null ? void 0 : ut.responsive, h("responsive")), E = r(y), w = I((dt = o.variables) == null ? void 0 : dt.conditional, h("conditional")), D = c(w), _ = f(s, "css/_variables.css"), F = `:root { ${b.join("")} ${E.join("")} } ${D.join("")}`;
266
- k(_, F), a.staticVariables = p;
267
- const T = f(s, "css/_global.css"), N = I(o.global, n.globalStyles), M = W(N, "");
268
- k(T, `@layer global { ${M} }`);
269
- const l = f(s, "css/_reset.css"), $ = o.reset === "none" ? {} : typeof o.reset == "object" ? o.reset : Bt, u = W($, "");
270
- k(l, `@layer reset { ${u} }`);
271
- const x = f(s, "css/_templates.css"), P = I(o.templates, n.templates), K = $t(P), L = Zt(P);
272
- k(x, K), a.templates = P;
273
- const { mediaQueries: A } = n;
274
- a.mediaQueries = Object.fromEntries(A.map(([S, C]) => [`@${S}`, C]));
275
- const U = A.map(([S]) => `'@${S}'`).join(" | "), q = f(s, "types/css-tokens.d.ts"), Q = `
262
+ const o = await Ut(t), i = { ...o }, c = /* @__PURE__ */ new Set(), p = (b, C = []) => b ? Object.entries(b).flatMap(([J, E]) => {
263
+ if (!E) return;
264
+ if (typeof E == "object") return p(E, [...C, J]);
265
+ const O = Ft(J), ot = M(J), rt = [...C, O].join(".");
266
+ c.add(`"${rt}"`);
267
+ const Y = [...C.map(M), ot].join("-"), mt = Wt(E);
268
+ return mt ? `--${Y}: ${mt.transformed};` : `--${Y}: ${E};`;
269
+ }) : [], y = (b) => b ? Object.entries(b).flatMap(([C, J]) => {
270
+ const E = p(J);
271
+ return C === "base" ? E.join("") : `${C} { ${E.join("")} }`;
272
+ }) : [], a = (b) => b ? Object.entries(b).flatMap(([C, J]) => Object.entries(J).flatMap(([E, O]) => {
273
+ const ot = p(O, [C]), rt = `.${C}-${E}, [data-${C}="${E}"]`, Y = ot.join("");
274
+ return `${rt} { ${Y} }`;
275
+ })) : [], $ = (b) => ({ ...b, responsive: void 0, conditional: void 0 }), g = (b) => n.variables.map((C) => b === "static" ? $(C._current) : C._current[b]), r = Z($(o.variables), g("static")), d = p(r), h = Z((dt = o.variables) == null ? void 0 : dt.responsive, g("responsive")), x = y(h), D = Z((pt = o.variables) == null ? void 0 : pt.conditional, g("conditional")), N = a(D), T = u(s, "css/_variables.css"), S = `:root { ${d.join("")} ${x.join("")} } ${N.join("")}`;
276
+ k(T, S), i.staticVariables = r;
277
+ const _ = u(s, "css/_global.css"), F = Z(o.global, n.globalStyles), R = await Q(F, "");
278
+ k(_, `@layer global { ${R} }`);
279
+ const l = u(s, "css/_reset.css"), w = o.reset === "none" ? {} : typeof o.reset == "object" ? o.reset : Kt, f = await Q(w, "");
280
+ k(l, `@layer reset { ${f} }`);
281
+ const j = u(s, "css/_templates.css"), P = Z(o.templates, n.templates), B = await bt(P), G = It(P);
282
+ k(j, B), i.templates = P;
283
+ const K = Lt(n.templates);
284
+ i.templatePaths = Object.fromEntries(
285
+ Object.entries(K).map(([b, C]) => [b, C._path || "nope"])
286
+ );
287
+ const { mediaQueries: L } = n;
288
+ i.mediaQueries = Object.fromEntries(L.map(([b, C]) => [`@${b}`, C]));
289
+ const U = L.map(([b]) => `'@${b}'`).join(" | "), nt = u(s, "types/css-tokens.d.ts"), X = `
276
290
  // Variable types
277
- type VariableTokens = ${[...i].join("|")};
291
+ type VariableTokens = ${[...c].join("|")};
278
292
  type PropertyValueToken = \`{\${VariableTokens}}\`;
279
293
 
280
294
  // Template types
281
295
  type TemplateTokens = {
282
- ${Object.entries(L).map(([S, C]) => `${S}?: ${C}`).join(`
296
+ ${Object.entries(G).map(([b, C]) => `${b}?: ${C}`).join(`
283
297
  `)}
284
298
  }
285
299
 
286
300
  // Media query types
287
301
  type MediaQueryKeys = ${U || "''"};
288
302
  `;
289
- k(q, Q);
290
- const X = f(s, "cache/config-cache.json");
291
- k(X, JSON.stringify(a, null, 2));
292
- }, gt = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
303
+ k(nt, X);
304
+ const Dt = u(s, "cache/config-cache.json");
305
+ k(Dt, JSON.stringify(i, null, 2));
306
+ }, ht = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
293
307
  if (/^['"`]/.test(s)) return e;
294
308
  const o = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
295
309
  if (!o.test(t)) return e;
296
- const i = o.exec(t);
297
- if (i) {
298
- const d = i.at(1);
299
- if (Ft.some((c) => d == null ? void 0 : d.includes(c))) return e;
310
+ const c = o.exec(t);
311
+ if (c) {
312
+ const p = c.at(1);
313
+ if (Nt.some((a) => p == null ? void 0 : p.includes(a))) return e;
300
314
  }
301
315
  return "styled('div',";
302
- }), Qt = (t, e) => {
316
+ }), Xt = (t, e) => {
303
317
  try {
304
- const s = O(f(e, "saltygen/cache/config-cache.json"), "utf8");
318
+ const s = V(u(e, "saltygen/cache/config-cache.json"), "utf8");
305
319
  return s ? `globalThis.saltyConfig = ${s};
306
320
 
307
321
  ${t}` : `globalThis.saltyConfig = {};
@@ -310,286 +324,287 @@ ${t}`;
310
324
  } catch {
311
325
  return t;
312
326
  }
313
- }, v = async (t, e, s) => {
314
- const n = B(e), o = f(s, "./temp");
315
- it(o) || H(o);
316
- const a = Y(e);
317
- let i = O(e, "utf8");
318
- i = gt(i), i = Qt(i, t);
319
- const d = f(s, "js", n + ".js"), r = await at(t), c = f(t, (r == null ? void 0 : r.configDir) || "", "salty.config.ts"), g = jt(c), h = await St(t);
320
- await mt.build({
327
+ }, st = async (t, e, s) => {
328
+ const n = H(e), o = u(s, "./temp");
329
+ ct(o) || v(o);
330
+ const i = et(e);
331
+ let c = V(e, "utf8");
332
+ c = ht(c), c = Xt(c, t);
333
+ const p = u(s, "js", n + ".js"), y = await ft(t), a = u(t, (y == null ? void 0 : y.configDir) || "", "salty.config.ts"), $ = xt(a), g = await jt(t);
334
+ await $t.build({
321
335
  stdin: {
322
- contents: i,
323
- sourcefile: a.base,
324
- resolveDir: a.dir,
336
+ contents: c,
337
+ sourcefile: i.base,
338
+ resolveDir: i.dir,
325
339
  loader: "tsx"
326
340
  },
327
341
  minify: !1,
328
342
  treeShaking: !0,
329
343
  bundle: !0,
330
- outfile: d,
331
- format: h,
344
+ outfile: p,
345
+ format: g,
332
346
  target: ["node20"],
333
347
  keepNames: !0,
334
- external: g,
348
+ external: $,
335
349
  packages: "external",
336
350
  plugins: [
337
351
  {
338
352
  name: "test",
339
- setup: (y) => {
340
- y.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (E) => {
341
- const w = O(E.path, "utf8");
342
- return { contents: gt(w), loader: "ts" };
353
+ setup: (h) => {
354
+ h.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (x) => {
355
+ const D = V(x.path, "utf8");
356
+ return { contents: ht(D), loader: "ts" };
343
357
  });
344
358
  }
345
359
  }
346
360
  ]
347
361
  });
348
- const p = Date.now();
349
- return await import(`${d}?t=${p}`);
350
- }, Ut = async (t) => {
351
- const e = await z(t), s = f(e, "cache/config-cache.json"), n = O(s, "utf8");
362
+ const r = Date.now();
363
+ return { contents: await import(`${p}?t=${r}`), outputFilePath: p };
364
+ }, Yt = async (t) => {
365
+ const e = await W(t), s = u(e, "cache/config-cache.json"), n = V(s, "utf8");
352
366
  if (!n) throw new Error("Could not find config cache file");
353
367
  return JSON.parse(n);
354
- }, lt = async (t) => {
355
- const e = await Ut(t), s = await z(t), n = f(s, "salty.config.js"), o = Date.now(), { config: a } = await import(`${n}?t=${o}`);
356
- return I(a, e);
357
- }, Nt = () => {
368
+ }, ut = async (t) => {
369
+ const e = await Yt(t), s = await W(t), n = u(s, "salty.config.js"), o = Date.now(), { config: i } = await import(`${n}?t=${o}`);
370
+ return Z(i, e);
371
+ }, kt = () => {
358
372
  try {
359
373
  return process.env.NODE_ENV === "production";
360
374
  } catch {
361
375
  return !1;
362
376
  }
363
- }, qt = async (t, e = Nt(), s = !0) => {
377
+ }, te = async (t, e = kt(), s = !0) => {
364
378
  try {
365
379
  const n = Date.now();
366
- e ? rt.info("Generating CSS in production mode! 🔥") : rt.info("Generating CSS in development mode! 🚀");
367
- const o = [], a = [], i = await z(t), d = f(i, "index.css");
380
+ e ? at.info("Generating CSS in production mode! 🔥") : at.info("Generating CSS in development mode! 🚀");
381
+ const o = [], i = [], c = await W(t), p = u(c, "index.css");
368
382
  s && (() => {
369
- it(i) && kt("rm -rf " + i), H(i, { recursive: !0 }), H(f(i, "css")), H(f(i, "types")), H(f(i, "js")), H(f(i, "cache"));
383
+ ct(c) && _t("rm -rf " + c), v(c, { recursive: !0 }), v(u(c, "css")), v(u(c, "types")), v(u(c, "js")), v(u(c, "cache"));
370
384
  })();
371
- const c = /* @__PURE__ */ new Set(), g = /* @__PURE__ */ new Set();
372
- async function h(l) {
373
- const m = ["node_modules", "saltygen"], $ = Dt(l);
374
- if ($.isDirectory()) {
375
- const u = _t(l);
385
+ const a = /* @__PURE__ */ new Set(), $ = /* @__PURE__ */ new Set();
386
+ async function g(l) {
387
+ const m = ["node_modules", "saltygen"], w = Et(l);
388
+ if (w.isDirectory()) {
389
+ const f = Tt(l);
376
390
  if (m.some((P) => l.includes(P))) return;
377
- await Promise.all(u.map((P) => h(f(l, P))));
378
- } else if ($.isFile() && G(l)) {
379
- c.add(l);
380
- const x = O(l, "utf8");
381
- /define[\w\d]+\(/.test(x) && g.add(l);
391
+ await Promise.all(f.map((P) => g(u(l, P))));
392
+ } else if (w.isFile() && I(l)) {
393
+ a.add(l);
394
+ const j = V(l, "utf8");
395
+ /define[\w\d]+\(/.test(j) && $.add(l);
382
396
  }
383
397
  }
384
- await h(t), await Lt(t, g);
385
- const p = {
398
+ await g(t), await qt(t, $);
399
+ const r = {
386
400
  keyframes: [],
387
401
  components: [],
388
402
  classNames: []
389
403
  };
390
404
  await Promise.all(
391
- [...c].map(async (l) => {
392
- const m = await v(t, l, i);
393
- Object.entries(m).forEach(([$, u]) => {
394
- u.isKeyframes ? p.keyframes.push({
395
- value: u,
405
+ [...a].map(async (l) => {
406
+ const { contents: m } = await st(t, l, c);
407
+ Object.entries(m).forEach(([w, f]) => {
408
+ f.isKeyframes ? r.keyframes.push({
409
+ value: f,
396
410
  src: l,
397
- name: $
398
- }) : u.isClassName ? p.classNames.push({
399
- ...u,
411
+ name: w
412
+ }) : f.isClassName ? r.classNames.push({
413
+ ...f,
400
414
  src: l,
401
- name: $
402
- }) : u.generator && p.components.push({
403
- ...u,
415
+ name: w
416
+ }) : f.generator && r.components.push({
417
+ ...f,
404
418
  src: l,
405
- name: $
419
+ name: w
406
420
  });
407
421
  });
408
422
  })
409
423
  );
410
- const b = await lt(t);
411
- for (const l of p.keyframes) {
412
- const { value: m } = l, $ = `a_${m.animationName}.css`, u = `css/${$}`, x = f(i, u);
413
- o.push($), k(x, m.css);
424
+ const d = await ut(t);
425
+ for (const l of r.keyframes) {
426
+ const { value: m } = l, w = `a_${m.animationName}.css`, f = `css/${w}`, j = u(c, f);
427
+ o.push(w), k(j, m.css);
414
428
  }
415
- const y = {};
416
- for (const l of p.components) {
417
- const { src: m, name: $ } = l, u = l.generator._withBuildContext({
418
- callerName: $,
429
+ const h = {};
430
+ for (const l of r.components) {
431
+ const { src: m, name: w } = l, f = l.generator._withBuildContext({
432
+ callerName: w,
419
433
  isProduction: e,
420
- config: b
434
+ config: d
421
435
  });
422
- a[u.priority] || (a[u.priority] = []), a[u.priority].push(u.cssFileName);
423
- const x = `css/${u.cssFileName}`, P = f(i, x);
424
- k(P, u.css), b.importStrategy === "component" && (y[m] ? y[m].push(u.cssFileName) : y[m] = [u.cssFileName]);
436
+ i[f.priority] || (i[f.priority] = []), i[f.priority].push(f.cssFileName);
437
+ const j = `css/${f.cssFileName}`, P = u(c, j);
438
+ k(P, await f.css), d.importStrategy === "component" && (h[m] ? h[m].push(f.cssFileName) : h[m] = [f.cssFileName]);
425
439
  }
426
- for (const l of p.classNames) {
427
- const { src: m, name: $ } = l, u = l.generator._withBuildContext({
428
- callerName: $,
440
+ for (const l of r.classNames) {
441
+ const { src: m, name: w } = l, f = l.generator._withBuildContext({
442
+ callerName: w,
429
443
  isProduction: e,
430
- config: b
444
+ config: d
431
445
  });
432
- a[0].push(u.cssFileName);
433
- const x = `css/${u.cssFileName}`, P = f(i, x);
434
- k(P, u.css), b.importStrategy === "component" && (y[m] ? y[m].push(u.cssFileName) : y[m] = [u.cssFileName]);
446
+ i[0].push(f.cssFileName);
447
+ const j = `css/${f.cssFileName}`, P = u(c, j);
448
+ k(P, await f.css), d.importStrategy === "component" && (h[m] ? h[m].push(f.cssFileName) : h[m] = [f.cssFileName]);
435
449
  }
436
- b.importStrategy === "component" && Object.entries(y).forEach(([l, m]) => {
437
- const $ = m.map((L) => `@import url('./${L}');`).join(`
438
- `), u = B(l, 6), x = Y(l), P = V(x.name), K = f(i, `css/f_${P}-${u}.css`);
439
- k(K, $);
450
+ d.importStrategy === "component" && Object.entries(h).forEach(([l, m]) => {
451
+ const w = m.map((G) => `@import url('./${G}');`).join(`
452
+ `), f = H(l, 6), j = et(l), P = M(j.name), B = u(c, `css/f_${P}-${f}.css`);
453
+ k(B, w);
440
454
  });
441
- const E = o.map((l) => `@import url('./css/${l}');`).join(`
455
+ const x = o.map((l) => `@import url('./css/${l}');`).join(`
442
456
  `);
443
- let F = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
457
+ let S = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
444
458
 
445
459
  ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) => {
446
460
  try {
447
- return O(f(i, "css", l), "utf8").length > 0;
461
+ return V(u(c, "css", l), "utf8").length > 0;
448
462
  } catch {
449
463
  return !1;
450
464
  }
451
465
  }).map((l) => `@import url('./css/${l}');`).join(`
452
466
  `)}
453
- ${E}`;
454
- if (b.importStrategy !== "component") {
455
- const l = a.reduce((m, $, u) => {
456
- const x = $.reduce((A, U) => {
467
+ ${x}`;
468
+ if (d.importStrategy !== "component") {
469
+ const l = i.reduce((m, w, f) => {
470
+ const j = w.reduce((K, L) => {
457
471
  var X;
458
- const q = f(i, "css", U), ft = O(q, "utf8"), Q = ((X = /.*-([^-]+)-\d+.css/.exec(U)) == null ? void 0 : X.at(1)) || B(q, 6);
459
- return A.includes(Q) ? A : `${A}
460
- /*start:${Q}*/
461
- ${ft}
462
- /*end:${Q}*/
472
+ const U = u(c, "css", L), nt = V(U, "utf8"), q = ((X = /.*-([^-]+)-\d+.css/.exec(L)) == null ? void 0 : X.at(1)) || H(U, 6);
473
+ return K.includes(q) ? K : `${K}
474
+ /*start:${q}*/
475
+ ${nt}
476
+ /*end:${q}*/
463
477
  `;
464
- }, ""), P = `l_${u}.css`, K = f(i, "css", P), L = `@layer l${u} { ${x}
478
+ }, ""), P = `l_${f}.css`, B = u(c, "css", P), G = `@layer l${f} { ${j}
465
479
  }`;
466
- return k(K, L), `${m}
480
+ return k(B, G), `${m}
467
481
  @import url('./css/${P}');`;
468
482
  }, "");
469
- F += l;
483
+ S += l;
470
484
  }
471
- k(d, F);
472
- const N = Date.now() - n, M = N < 200 ? "🔥" : N < 500 ? "🚀" : N < 1e3 ? "🎉" : N < 2e3 ? "🚗" : N < 5e3 ? "🤔" : "🥴";
473
- rt.info(`Generated CSS in ${N}ms! ${M}`);
485
+ k(p, S);
486
+ const F = Date.now() - n, R = F < 200 ? "🔥" : F < 500 ? "🚀" : F < 1e3 ? "🎉" : F < 2e3 ? "🚗" : F < 5e3 ? "🤔" : "🥴";
487
+ at.info(`Generated CSS in ${F}ms! ${R}`);
474
488
  } catch (n) {
475
489
  console.error(n);
476
490
  }
477
- }, Xt = async (t, e) => {
491
+ }, ee = async (t, e) => {
478
492
  try {
479
- const s = await z(t);
480
- if (G(e)) {
481
- const o = [], a = await lt(t), i = await v(t, e, s);
482
- if (Object.entries(i).forEach(([d, r]) => {
483
- if (r.isKeyframes && r.css) {
484
- const b = `css/${`a_${r.animationName}.css`}`, y = f(s, b);
485
- k(y, r.css);
493
+ const s = await W(t);
494
+ if (I(e)) {
495
+ const o = [], i = await ut(t), { contents: c } = await st(t, e, s);
496
+ for (const [p, y] of Object.entries(c)) {
497
+ if (y.isKeyframes && y.css) {
498
+ const d = `css/${`a_${y.animationName}.css`}`, h = u(s, d);
499
+ k(h, await y.css);
486
500
  return;
487
501
  }
488
- if (r.isClassName) {
489
- const p = r.factory._withBuildContext({
490
- name: d
502
+ if (y.isClassName) {
503
+ const r = y.factory._withBuildContext({
504
+ name: p
491
505
  });
492
- o[0].push(p.cssFileName);
493
- const b = `css/${p.cssFileName}`, y = f(s, b);
494
- k(y, p.css);
506
+ o[0].push(r.cssFileName);
507
+ const d = `css/${r.cssFileName}`, h = u(s, d);
508
+ k(h, await r.css);
495
509
  }
496
- if (!r.generator) return;
497
- const c = r.generator._withBuildContext({
498
- name: d,
499
- config: a
500
- }), g = `css/${c.cssFileName}`, h = f(s, g);
501
- k(h, c.css), o[c.priority] || (o[c.priority] = []), o[c.priority].push(c.cssFileName);
502
- }), a.importStrategy !== "component")
503
- o.forEach((d, r) => {
504
- const c = `l_${r}.css`, g = f(s, "css", c);
505
- let h = O(g, "utf8");
506
- d.forEach((p) => {
507
- var w;
508
- const b = f(s, "css", p), y = ((w = /.*-([^-]+)-\d+.css/.exec(p)) == null ? void 0 : w.at(1)) || B(b, 6);
509
- if (!h.includes(y)) {
510
- const D = O(b, "utf8"), _ = `/*start:${y}*/
511
- ${D}
512
- /*end:${y}*/
510
+ if (!y.generator) return;
511
+ const a = y.generator._withBuildContext({
512
+ name: p,
513
+ config: i
514
+ }), $ = `css/${a.cssFileName}`, g = u(s, $);
515
+ k(g, await a.css), o[a.priority] || (o[a.priority] = []), o[a.priority].push(a.cssFileName);
516
+ }
517
+ if (i.importStrategy !== "component")
518
+ o.forEach((p, y) => {
519
+ const a = `l_${y}.css`, $ = u(s, "css", a);
520
+ let g = V($, "utf8");
521
+ p.forEach((r) => {
522
+ var D;
523
+ const d = u(s, "css", r), h = ((D = /.*-([^-]+)-\d+.css/.exec(r)) == null ? void 0 : D.at(1)) || H(d, 6);
524
+ if (!g.includes(h)) {
525
+ const N = V(d, "utf8"), T = `/*start:${h}*/
526
+ ${N}
527
+ /*end:${h}*/
513
528
  `;
514
- h = `${h.replace(/\}$/, "")}
515
- ${_}
529
+ g = `${g.replace(/\}$/, "")}
530
+ ${T}
516
531
  }`;
517
532
  }
518
- }), k(g, h);
533
+ }), k($, g);
519
534
  });
520
535
  else {
521
- const d = o.flat().map((p) => `@import url('./${p}');`).join(`
522
- `), r = B(e, 6), c = Y(e), g = V(c.name), h = f(s, `css/f_${g}-${r}.css`);
523
- k(h, d);
536
+ const p = o.flat().map((r) => `@import url('./${r}');`).join(`
537
+ `), y = H(e, 6), a = et(e), $ = M(a.name), g = u(s, `css/f_${$}-${y}.css`);
538
+ k(g, p);
524
539
  }
525
540
  }
526
541
  } catch (s) {
527
542
  console.error(s);
528
543
  }
529
- }, Yt = async (t, e, s = Nt()) => {
544
+ }, se = async (t, e, s = kt()) => {
530
545
  try {
531
- const n = await z(t);
532
- if (G(e)) {
533
- const a = O(e, "utf8");
534
- a.replace(/^(?!export\s)const\s.*/gm, (g) => `export ${g}`) !== a && await Et(e, a);
535
- const d = await lt(t), r = await v(t, e, n);
536
- let c = a;
537
- if (Object.entries(r).forEach(([g, h]) => {
538
- var u;
539
- if (h.isKeyframes || !h.generator) return;
540
- const p = h.generator._withBuildContext({
541
- name: g,
542
- config: d,
546
+ const n = await W(t);
547
+ if (I(e)) {
548
+ const i = V(e, "utf8");
549
+ i.replace(/^(?!export\s)const\s.*/gm, ($) => `export ${$}`) !== i && await Ot(e, i);
550
+ const p = await ut(t), { contents: y } = await st(t, e, n);
551
+ let a = i;
552
+ if (Object.entries(y).forEach(([$, g]) => {
553
+ var f;
554
+ if (g.isKeyframes || !g.generator) return;
555
+ const r = g.generator._withBuildContext({
556
+ name: $,
557
+ config: p,
543
558
  prod: s
544
- }), b = new RegExp(`\\s${g}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(a);
545
- if (!b) return console.error("Could not find the original declaration");
546
- const y = (u = b.at(1)) == null ? void 0 : u.trim(), E = new RegExp(`\\s${g}[=\\s]+styled\\(`, "g").exec(c);
547
- if (!E) return console.error("Could not find the original declaration");
548
- const { index: w } = E;
549
- let D = !1;
550
- const _ = setTimeout(() => D = !0, 5e3);
551
- let F = 0, T = !1, N = 0;
552
- for (; !T && !D; ) {
553
- const x = c[w + F];
554
- x === "(" && N++, x === ")" && N--, N === 0 && x === ")" && (T = !0), F > c.length && (D = !0), F++;
559
+ }), d = new RegExp(`\\s${$}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(i);
560
+ if (!d) return console.error("Could not find the original declaration");
561
+ const h = (f = d.at(1)) == null ? void 0 : f.trim(), x = new RegExp(`\\s${$}[=\\s]+styled\\(`, "g").exec(a);
562
+ if (!x) return console.error("Could not find the original declaration");
563
+ const { index: D } = x;
564
+ let N = !1;
565
+ const T = setTimeout(() => N = !0, 5e3);
566
+ let S = 0, _ = !1, F = 0;
567
+ for (; !_ && !N; ) {
568
+ const j = a[D + S];
569
+ j === "(" && F++, j === ")" && F--, F === 0 && j === ")" && (_ = !0), S > a.length && (N = !0), S++;
555
570
  }
556
- if (!D) clearTimeout(_);
571
+ if (!N) clearTimeout(T);
557
572
  else throw new Error("Failed to find the end of the styled call and timed out");
558
- const M = w + F, l = c.slice(w, M), m = c, $ = ` ${g} = styled(${y}, "${p.classNames}", ${JSON.stringify(p.clientProps)});`;
559
- c = c.replace(l, $), m === c && console.error("Minimize file failed to change content", { name: g, tagName: y });
560
- }), d.importStrategy === "component") {
561
- const g = B(e, 6), h = Y(e);
562
- c = `import '../../saltygen/css/${`f_${V(h.name)}-${g}.css`}';
563
- ${c}`;
573
+ const R = D + S, l = a.slice(D, R), m = a, w = ` ${$} = styled(${h}, "${r.classNames}", ${JSON.stringify(r.clientProps)});`;
574
+ a = a.replace(l, w), m === a && console.error("Minimize file failed to change content", { name: $, tagName: h });
575
+ }), p.importStrategy === "component") {
576
+ const $ = H(e, 6), g = et(e);
577
+ a = `import '../../saltygen/css/${`f_${M(g.name)}-${$}.css`}';
578
+ ${a}`;
564
579
  }
565
- return c = c.replace("{ styled }", "{ styledClient as styled }"), c = c.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), c;
580
+ return a = a.replace("{ styled }", "{ styledClient as styled }"), a = a.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), a;
566
581
  }
567
582
  } catch (n) {
568
583
  console.error("Error in minimizeFile:", n);
569
584
  }
570
- }, ht = async (t) => {
585
+ }, yt = async (t) => {
571
586
  if (!t || t.includes("node_modules") || t.includes("saltygen")) return !1;
572
587
  if (t.includes("salty.config")) return !0;
573
- if (!G(t)) return !1;
574
- const n = await ct(t, "utf-8");
588
+ if (!I(t)) return !1;
589
+ const n = await lt(t, "utf-8");
575
590
  return !!/.+define[A-Z]\w+/.test(n);
576
- }, oe = (t) => ({
591
+ }, ce = (t) => ({
577
592
  name: "stylegen",
578
- buildStart: () => qt(t),
593
+ buildStart: () => te(t),
579
594
  load: async (e) => {
580
- if (G(e))
581
- return await Yt(t, e);
595
+ if (I(e))
596
+ return await se(t, e);
582
597
  },
583
598
  handleHotUpdate: async ({ file: e, server: s }) => {
584
- await ht(e) && await s.restart();
599
+ await yt(e) && await s.restart();
585
600
  },
586
601
  watchChange: {
587
602
  handler: async (e) => {
588
- G(e) && (await ht(e) || await Xt(t, e));
603
+ I(e) && (await yt(e) || await ee(t, e));
589
604
  }
590
605
  }
591
606
  });
592
607
  export {
593
- oe as default,
594
- oe as saltyPlugin
608
+ ce as default,
609
+ ce as saltyPlugin
595
610
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/vite",
3
- "version": "0.0.1-alpha.201",
3
+ "version": "0.0.1-alpha.203",
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.201"
37
+ "@salty-css/core": "^0.0.1-alpha.203"
38
38
  }
39
39
  }