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

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