@salty-css/webpack 0.0.1-alpha.115 → 0.0.1-alpha.116

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.
@@ -0,0 +1,28 @@
1
+ "use strict";const rt=require("esbuild"),it=require("child_process"),l=require("path"),u=require("fs"),L=require("fs/promises"),V=require("winston");var _=typeof document<"u"?document.currentScript:null;function ct(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const s=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,s.get?s:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const K=ct(rt),W=t=>String.fromCharCode(t+(t>25?39:97)),at=(t,e)=>{let n="",s;for(s=Math.abs(t);s>52;s=s/52|0)n=W(s%52)+n;return n=W(s%52)+n,n.length<e?n=n.padStart(e,"a"):n.length>e&&(n=n.slice(-e)),n},lt=(t,e)=>{let n=e.length;for(;n;)t=t*33^e.charCodeAt(--n);return t},R=(t,e=3)=>{const n=lt(5381,JSON.stringify(t))>>>0;return at(n,e)};function N(t){return t?typeof t!="string"?N(String(t)):t.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,n)=>(n>0?"-":"")+e.toLowerCase()):""}const ft=(t,e)=>{if(typeof t!="string")return{result:t};if(!e)return{result:t};const n=[];return Object.values(e).forEach(s=>{const{pattern:o,transform:i}=s;t=t.replace(o,g=>{const{value:a,css:j}=i(g);return j&&n.push(j),a})}),{result:t,additionalCss:n}},U=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...s)=>`var(--${N(s[1].replaceAll(".","-"))})`)}:{result:t},E=(t,e,n,s)=>{if(!t)return"";const o=[],i=Object.entries(t).reduce((a,[j,r])=>{const d=j.trim();if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return a;if(d==="variants")return Object.entries(r).forEach(([S,c])=>{c&&Object.entries(c).forEach(([p,m])=>{if(!m)return;const h=`${e}.${S}-${p}`,T=E(m,h);o.push(T)})}),a;if(d==="defaultVariants")return a;if(d==="compoundVariants")return r.forEach(S=>{const{css:c,...p}=S,m=Object.entries(p).reduce((T,[w,F])=>`${T}.${w}-${F}`,e),h=E(c,m);o.push(h)}),a;if(d.startsWith("@")){const S=E(r,e),c=`${d} {
2
+ ${S.replace(`
3
+ `,`
4
+ `)}
5
+ }`;return o.push(c),a}const y=j.includes("&")?d.replace("&",e):d.startsWith(":")?`${e}${d}`:`${e} ${d}`,b=E(r,y);return o.push(b),a}const $=d.startsWith("-")?d:N(d),C=(y,b=";")=>a=`${a}${y}${b}`,k=y=>C(`${$}:${y}`);if(typeof r=="number")return k(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return a;const{modifiers:f}={},P=function*(){yield U(r),yield ft(r,f)}();for(const{result:y,additionalCss:b=[]}of P)r=y,b.forEach(S=>{const c=E(S,"");C(c,"")});return k(r)},"");if(!i)return o.join(`
6
+ `);if(!e)return i;let g="";return g=`${e} { ${i} }`,[g,...o].join(`
7
+ `)},G=(t,e=[])=>{if(!t)return"";const n=[],s={};if(Object.entries(t).forEach(([o,i])=>{if(typeof i=="object"){if(!i)return;const g=o.trim(),a=G(i,[...e,g]);n.push(a)}else s[o]=i}),Object.keys(s).length){const o=e.map(N).join("-"),i=E(s,`.${o}`);n.push(i)}return n.join(`
8
+ `)},ut=t=>Object.entries(t).reduce((e,[n,s])=>(typeof s=="object"&&(e[n]=H(s).map(o=>`"${o}"`).join(" | ")),e),{}),H=(t,e="",n=new Set)=>t?(Object.entries(t).forEach(([s,o])=>{const i=e?`${e}.${s}`:s;return typeof o=="object"?H(o,i,n):n.add(e)}),[...n]):[],X=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:X(l.join(t,".."))},pt=async t=>{const e=X(t);return await L.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},dt=async t=>{const e=await pt(t);if(e)return e.type};let M;const Y=async t=>{if(M)return M;const e=await dt(t);return e==="module"?M="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:_&&_.tagName.toUpperCase()==="SCRIPT"&&_.src||new URL("index-55a7q00M.cjs",document.baseURI).href).endsWith(".cjs"))&&(M="cjs"),M||"esm"},B=V.createLogger({level:"debug",format:V.format.combine(V.format.colorize(),V.format.cli()),transports:[new V.transports.Console({})]});function Q(t){return t?typeof t!="string"?Q(String(t)):t.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,n)=>(n>0?".":"")+e.toLowerCase()):""}const J={externalModules:[]},v=t=>{if(J.externalModules.length>0)return J.externalModules;const e=l.join(t,"salty.config.ts"),s=u.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const o=s[1].split(",").map(i=>i.replace(/['"`]/g,"").trim());return J.externalModules=o,o},A=t=>l.join(t,"./saltygen"),gt=["salty","css","styles","styled"],tt=(t=[])=>new RegExp(`\\.(${[...gt,...t].join("|")})\\.`),Z=(t,e=[])=>tt(e).test(t),yt=async t=>{const e=A(t),n=l.join(t,"salty.config.ts"),s=l.join(e,"salty.config.js"),o=await Y(t),i=v(t);await K.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:s,format:o,external:i});const g=Date.now(),{config:a}=await import(`${s}?t=${g}`);return a},mt=async t=>{const e=await yt(t),n=new Set,s=(c,p=[])=>c?Object.entries(c).flatMap(([m,h])=>{if(!h)return;if(typeof h=="object")return s(h,[...p,m]);const T=Q(m),w=N(m),F=[...p,T].join(".");n.add(`"${F}"`);const O=[...p.map(N),w].join("-"),{result:D}=U(h);return`--${O}: ${D};`}):[],o=c=>c?Object.entries(c).flatMap(([p,m])=>{const h=s(m);return p==="base"?h.join(""):`${p} { ${h.join("")} }`}):[],i=c=>c?Object.entries(c).flatMap(([p,m])=>Object.entries(m).flatMap(([h,T])=>{const w=s(T,[p]),F=`.${p}-${h}, [data-${p}="${h}"]`,O=w.join("");return`${F} { ${O} }`})):[],g=s(e.variables),a=o(e.responsiveVariables),j=i(e.conditionalVariables),r=A(t),d=l.join(r,"css/variables.css"),$=`:root { ${g.join("")} ${a.join("")} } ${j.join("")}`;u.writeFileSync(d,$);const C=l.join(r,"css/global.css"),k=E(e.global,"");u.writeFileSync(C,k);const f=l.join(r,"css/templates.css"),x=G(e.templates),P=ut(e.templates);u.writeFileSync(f,x);const y=l.join(r,"types/css-tokens.d.ts"),S=`
9
+ // Variable types
10
+ type VariableTokens = ${[...n].join("|")};
11
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
12
+
13
+ // Template types
14
+ type TemplateTokens = {
15
+ ${Object.entries(P).map(([c,p])=>`${c}?: ${p}`).join(`
16
+ `)}
17
+ }
18
+ `;u.writeFileSync(y,S)},q=async(t,e,n)=>{const s=R(e),o=l.join(n,"./temp");u.existsSync(o)||u.mkdirSync(o);const i=l.parse(e);let g=u.readFileSync(e,"utf8");g=g.replace(/styled\([^"'`{,]+,/g,"styled('div',");const a=l.join(n,"js",s+".js"),j=v(t),r=await Y(t);await K.build({stdin:{contents:g,sourcefile:i.base,resolveDir:i.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:a,format:r,target:["node20"],keepNames:!0,external:j,packages:"external"});const d=Date.now();return await import(`${a}?t=${d}`)},I=async t=>{const e=A(t),n=l.join(e,"salty.config.js"),{config:s}=await import(n);return s},et=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},ht=async(t,e=et())=>{try{e?B.info("Generating CSS in production mode! 🔥"):B.info("Generating CSS in development mode! 🚀");const n=[],s=[],o=A(t),i=l.join(o,"index.css");(()=>{u.existsSync(o)&&it.execSync("rm -rf "+o),u.mkdirSync(o),u.mkdirSync(l.join(o,"css")),u.mkdirSync(l.join(o,"types"))})(),await mt(t);const a=await I(t);async function j(f,x){const P=["node_modules","saltygen"],y=u.statSync(f);if(y.isDirectory()){const b=u.readdirSync(f);if(P.some(c=>f.includes(c)))return;await Promise.all(b.map(c=>j(l.join(f,c),l.join(x,c))))}else if(y.isFile()&&Z(f)){const S=await q(t,f,o),c=[];Object.entries(S).forEach(([T,w])=>{if(w.isKeyframes&&w.css){const z=`${w.animationName}.css`,st=`css/${z}`,ot=l.join(o,st);n.push(z),u.writeFileSync(ot,w.css);return}if(!w.generator)return;const F=w.generator._withBuildContext({name:T,config:a,prod:e}),O=`${F.hash}-${F.priority}.css`;s[F.priority]||(s[F.priority]=[]),s[F.priority].push(O),c.push(O);const D=`css/${O}`,nt=l.join(o,D);u.writeFileSync(nt,F.css)});const p=c.map(T=>`@import url('./${T}');`).join(`
19
+ `),m=R(f,6),h=l.join(o,`css/${m}.css`);u.writeFileSync(h,p)}}await j(t,o);const r=n.map(f=>`@import url('./css/${f}');`).join(`
20
+ `);let k=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
21
+
22
+ ${["variables.css","global.css","templates.css"].filter(f=>{try{return u.readFileSync(l.join(o,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
23
+ `)}
24
+ ${r}`;if(a.importStrategy!=="component"){const f=s.flat().map(x=>`@import url('./css/${x}');`).join(`
25
+ `);k+=f}u.writeFileSync(i,k)}catch(n){console.error(n)}},jt=async(t,e)=>{try{const n=[],s=l.join(t,"./saltygen"),o=l.join(s,"index.css");if(Z(e)){const g=await I(t),a=await q(t,e,s);Object.entries(a).forEach(([C,k])=>{if(!k.generator)return;const f=k.generator._withBuildContext({name:C,config:g}),x=`${f.hash}-${f.priority}.css`,P=`css/${x}`,y=l.join(s,P);n.push(x),u.writeFileSync(y,f.css)});const j=u.readFileSync(o,"utf8").split(`
26
+ `),r=n.map(C=>`@import url('../saltygen/css/${C}');`),$=[...new Set([...j,...r])].join(`
27
+ `);u.writeFileSync(o,$)}}catch(n){console.error(n)}},$t=async(t,e,n=et())=>{try{const s=l.join(t,"./saltygen");if(Z(e)){const i=u.readFileSync(e,"utf8");i.replace(/^(?!export\s)const\s.*/gm,$=>`export ${$}`)!==i&&await L.writeFile(e,i);const a=await I(t),j=await q(t,e,s);let r=i;Object.entries(j).forEach(([$,C])=>{var O;if(C.isKeyframes||!C.generator)return;const k=C.generator._withBuildContext({name:$,config:a,prod:n}),f=new RegExp(`\\s${$}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(i);if(!f)return console.error("Could not find the original declaration");const x=(O=f.at(1))==null?void 0:O.trim(),P=new RegExp(`\\s${$}[=\\s]+styled\\(`,"g").exec(r);if(!P)return console.error("Could not find the original declaration");const{index:y}=P;let b=!1;const S=setTimeout(()=>b=!0,5e3);let c=0,p=!1,m=0;for(;!p&&!b;){const D=r[y+c];D==="("&&m++,D===")"&&m--,m===0&&D===")"&&(p=!0),c>r.length&&(b=!0),c++}if(!b)clearTimeout(S);else throw new Error("Failed to find the end of the styled call and timed out");const h=y+c,T=r.slice(y,h),w=r,F=` ${$} = styled(${x}, "${k.classNames}", ${JSON.stringify(k.props)});`;r=r.replace(T,F),w===r&&console.error("Minimize file failed to change content",{name:$,tagName:x})});const d=R(e,6);return a.importStrategy==="component"&&(r=`import '../../saltygen/css/${d}.css';
28
+ ${r}`),r=r.replace("{ styled }","{ styledClient as styled }"),r=r.replace("@salty-css/react/styled","@salty-css/react/styled-client"),r}}catch(s){console.error("Error in minimizeFile:",s)}};exports.generateCss=ht;exports.generateFile=jt;exports.minimizeFile=$t;exports.saltyFileRegExp=tt;
@@ -1,25 +1,25 @@
1
1
  import * as L from "esbuild";
2
- import { execSync as ot } from "child_process";
3
- import { join as f, parse as rt } from "path";
4
- import { existsSync as W, writeFileSync as P, readFileSync as N, mkdirSync as J, statSync as it, readdirSync as ct } from "fs";
5
- import { readFile as at, writeFile as lt } from "fs/promises";
6
- import { createLogger as ft, format as R, transports as pt } from "winston";
7
- const H = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), ut = (t, e) => {
2
+ import { execSync as rt } from "child_process";
3
+ import { join as f, parse as it } from "path";
4
+ import { existsSync as _, writeFileSync as E, readFileSync as N, mkdirSync as A, statSync as ct, readdirSync as at } from "fs";
5
+ import { readFile as lt, writeFile as ft } from "fs/promises";
6
+ import { createLogger as pt, format as Z, transports as ut } from "winston";
7
+ const G = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), gt = (t, e) => {
8
8
  let s = "", n;
9
- for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = H(n % 52) + s;
10
- return s = H(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
11
- }, gt = (t, e) => {
9
+ for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = G(n % 52) + s;
10
+ return s = G(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
11
+ }, dt = (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 = 3) => {
16
- const s = gt(5381, JSON.stringify(t)) >>> 0;
17
- return ut(s, e);
15
+ }, W = (t, e = 3) => {
16
+ const s = dt(5381, JSON.stringify(t)) >>> 0;
17
+ return gt(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 dt = (t, e) => {
22
+ const yt = (t, e) => {
23
23
  if (typeof t != "string") return { result: t };
24
24
  if (!e) return { result: t };
25
25
  const s = [];
@@ -30,7 +30,7 @@ const dt = (t, e) => {
30
30
  return h && s.push(h), a;
31
31
  });
32
32
  }), { result: t, additionalCss: s };
33
- }, q = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${V(n[1].replaceAll(".", "-"))})`) } : { result: t }, D = (t, e, s, n) => {
33
+ }, q = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${M(n[1].replaceAll(".", "-"))})`) } : { result: t }, O = (t, e, s, n) => {
34
34
  if (!t) return "";
35
35
  const o = [], i = Object.entries(t).reduce((a, [h, r]) => {
36
36
  const u = h.trim();
@@ -40,7 +40,7 @@ const dt = (t, e) => {
40
40
  return Object.entries(r).forEach(([j, c]) => {
41
41
  c && Object.entries(c).forEach(([p, y]) => {
42
42
  if (!y) return;
43
- const m = `${e}.${j}-${p}`, F = D(y, m);
43
+ const m = `${e}.${j}-${p}`, F = O(y, m);
44
44
  o.push(F);
45
45
  });
46
46
  }), a;
@@ -48,34 +48,34 @@ const dt = (t, e) => {
48
48
  return a;
49
49
  if (u === "compoundVariants")
50
50
  return r.forEach((j) => {
51
- const { css: c, ...p } = j, y = Object.entries(p).reduce((F, [w, S]) => `${F}.${w}-${S}`, e), m = D(c, y);
51
+ const { css: c, ...p } = j, y = Object.entries(p).reduce((F, [w, S]) => `${F}.${w}-${S}`, e), m = O(c, y);
52
52
  o.push(m);
53
53
  }), a;
54
54
  if (u.startsWith("@")) {
55
- const j = D(r, e), c = `${u} {
55
+ const j = O(r, e), c = `${u} {
56
56
  ${j.replace(`
57
57
  `, `
58
58
  `)}
59
59
  }`;
60
60
  return o.push(c), a;
61
61
  }
62
- const d = h.includes("&") ? u.replace("&", e) : u.startsWith(":") ? `${e}${u}` : `${e} ${u}`, b = D(r, d);
62
+ const d = h.includes("&") ? u.replace("&", e) : u.startsWith(":") ? `${e}${u}` : `${e} ${u}`, b = O(r, d);
63
63
  return o.push(b), a;
64
64
  }
65
- const $ = u.startsWith("-") ? u : V(u), k = (d, b = ";") => a = `${a}${d}${b}`, x = (d) => k(`${$}:${d}`);
66
- if (typeof r == "number") return x(r);
65
+ const $ = u.startsWith("-") ? u : M(u), C = (d, b = ";") => a = `${a}${d}${b}`, k = (d) => C(`${$}:${d}`);
66
+ if (typeof r == "number") return k(r);
67
67
  if (typeof r != "string")
68
68
  if ("toString" in r) r = r.toString();
69
69
  else return a;
70
70
  const { modifiers: l } = {}, T = function* () {
71
- yield q(r), yield dt(r, l);
71
+ yield q(r), yield yt(r, l);
72
72
  }();
73
73
  for (const { result: d, additionalCss: b = [] } of T)
74
74
  r = d, b.forEach((j) => {
75
- const c = D(j, "");
76
- k(c, "");
75
+ const c = O(j, "");
76
+ C(c, "");
77
77
  });
78
- return x(r);
78
+ return k(r);
79
79
  }, "");
80
80
  if (!i) return o.join(`
81
81
  `);
@@ -94,46 +94,50 @@ const dt = (t, e) => {
94
94
  } else
95
95
  n[o] = i;
96
96
  }), Object.keys(n).length) {
97
- const o = e.map(V).join("-"), i = D(n, `.${o}`);
97
+ const o = e.map(M).join("-"), i = O(n, `.${o}`);
98
98
  s.push(i);
99
99
  }
100
100
  return s.join(`
101
101
  `);
102
- }, yt = (t) => Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = X(n).map((o) => `"${o}"`).join(" | ")), e), {}), X = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, o]) => {
102
+ }, mt = (t) => Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = X(n).map((o) => `"${o}"`).join(" | ")), e), {}), X = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, o]) => {
103
103
  const i = e ? `${e}.${n}` : n;
104
104
  return typeof o == "object" ? X(o, i, s) : s.add(e);
105
105
  }), [...s]) : [], Y = (t) => {
106
106
  if (!t || t === "/") throw new Error("Could not find package.json file");
107
107
  const e = f(t, "package.json");
108
- return W(e) ? e : Y(f(t, ".."));
109
- }, mt = async (t) => {
108
+ return _(e) ? e : Y(f(t, ".."));
109
+ }, ht = async (t) => {
110
110
  const e = Y(t);
111
- return await at(e, "utf-8").then(JSON.parse).catch(() => {
111
+ return await lt(e, "utf-8").then(JSON.parse).catch(() => {
112
112
  });
113
- }, ht = async (t) => {
114
- const e = await mt(t);
113
+ }, $t = async (t) => {
114
+ const e = await ht(t);
115
115
  if (e)
116
116
  return e.type;
117
117
  };
118
- let O;
118
+ let V;
119
119
  const Q = async (t) => {
120
- if (O) return O;
121
- const e = await ht(t);
122
- return e === "module" ? O = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (O = "cjs"), O || "esm";
123
- }, K = ft({
120
+ if (V) return V;
121
+ const e = await $t(t);
122
+ return e === "module" ? V = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (V = "cjs"), V || "esm";
123
+ }, H = pt({
124
124
  level: "debug",
125
- format: R.combine(R.colorize(), R.cli()),
126
- transports: [new pt.Console({})]
127
- }), _ = {
125
+ format: Z.combine(Z.colorize(), Z.cli()),
126
+ transports: [new ut.Console({})]
127
+ });
128
+ function v(t) {
129
+ 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()) : "";
130
+ }
131
+ const R = {
128
132
  externalModules: []
129
- }, v = (t) => {
130
- if (_.externalModules.length > 0) return _.externalModules;
133
+ }, tt = (t) => {
134
+ if (R.externalModules.length > 0) return R.externalModules;
131
135
  const e = f(t, "salty.config.ts"), n = N(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
132
136
  if (!n) return [];
133
137
  const o = n[1].split(",").map((i) => i.replace(/['"`]/g, "").trim());
134
- return _.externalModules = o, o;
135
- }, A = (t) => f(t, "./saltygen"), $t = ["salty", "css", "styles", "styled"], bt = (t = []) => new RegExp(`\\.(${[...$t, ...t].join("|")})\\.`), I = (t, e = []) => bt(e).test(t), jt = async (t) => {
136
- const e = A(t), s = f(t, "salty.config.ts"), n = f(e, "salty.config.js"), o = await Q(t), i = v(t);
138
+ return R.externalModules = o, o;
139
+ }, J = (t) => f(t, "./saltygen"), bt = ["salty", "css", "styles", "styled"], jt = (t = []) => new RegExp(`\\.(${[...bt, ...t].join("|")})\\.`), B = (t, e = []) => jt(e).test(t), wt = async (t) => {
140
+ const e = J(t), s = f(t, "salty.config.ts"), n = f(e, "salty.config.js"), o = await Q(t), i = tt(t);
137
141
  await L.build({
138
142
  entryPoints: [s],
139
143
  minify: !0,
@@ -145,26 +149,26 @@ const Q = async (t) => {
145
149
  });
146
150
  const g = Date.now(), { config: a } = await import(`${n}?t=${g}`);
147
151
  return a;
148
- }, wt = async (t) => {
149
- const e = await jt(t), s = /* @__PURE__ */ new Set(), n = (c, p = []) => c ? Object.entries(c).flatMap(([y, m]) => {
152
+ }, St = async (t) => {
153
+ const e = await wt(t), s = /* @__PURE__ */ new Set(), n = (c, p = []) => c ? Object.entries(c).flatMap(([y, m]) => {
150
154
  if (!m) return;
151
155
  if (typeof m == "object") return n(m, [...p, y]);
152
- const F = [...p, y].join(".");
153
- s.add(`"${F}"`);
154
- const w = [...p.map(V), V(y)].join("-"), { result: S } = q(m);
155
- return `--${w}: ${S};`;
156
+ const F = v(y), w = M(y), S = [...p, F].join(".");
157
+ s.add(`"${S}"`);
158
+ const P = [...p.map(M), w].join("-"), { result: D } = q(m);
159
+ return `--${P}: ${D};`;
156
160
  }) : [], o = (c) => c ? Object.entries(c).flatMap(([p, y]) => {
157
161
  const m = n(y);
158
162
  return p === "base" ? m.join("") : `${p} { ${m.join("")} }`;
159
163
  }) : [], i = (c) => c ? Object.entries(c).flatMap(([p, y]) => Object.entries(y).flatMap(([m, F]) => {
160
- const w = n(F, [p]), S = `.${p}-${m}, [data-${p}="${m}"]`, E = w.join("");
161
- return `${S} { ${E} }`;
162
- })) : [], g = n(e.variables), a = o(e.responsiveVariables), h = i(e.conditionalVariables), r = A(t), u = f(r, "css/variables.css"), $ = `:root { ${g.join("")} ${a.join("")} } ${h.join("")}`;
163
- P(u, $);
164
- const k = f(r, "css/global.css"), x = D(e.global, "");
165
- P(k, x);
166
- const l = f(r, "css/templates.css"), C = U(e.templates), T = yt(e.templates);
167
- P(l, C);
164
+ const w = n(F, [p]), S = `.${p}-${m}, [data-${p}="${m}"]`, P = w.join("");
165
+ return `${S} { ${P} }`;
166
+ })) : [], g = n(e.variables), a = o(e.responsiveVariables), h = i(e.conditionalVariables), r = J(t), u = f(r, "css/variables.css"), $ = `:root { ${g.join("")} ${a.join("")} } ${h.join("")}`;
167
+ E(u, $);
168
+ const C = f(r, "css/global.css"), k = O(e.global, "");
169
+ E(C, k);
170
+ const l = f(r, "css/templates.css"), x = U(e.templates), T = mt(e.templates);
171
+ E(l, x);
168
172
  const d = f(r, "types/css-tokens.d.ts"), j = `
169
173
  // Variable types
170
174
  type VariableTokens = ${[...s].join("|")};
@@ -176,14 +180,14 @@ const Q = async (t) => {
176
180
  `)}
177
181
  }
178
182
  `;
179
- P(d, j);
180
- }, Z = async (t, e, s) => {
181
- const n = B(e), o = f(s, "./temp");
182
- W(o) || J(o);
183
- const i = rt(e);
183
+ E(d, j);
184
+ }, I = async (t, e, s) => {
185
+ const n = W(e), o = f(s, "./temp");
186
+ _(o) || A(o);
187
+ const i = it(e);
184
188
  let g = N(e, "utf8");
185
189
  g = g.replace(/styled\([^"'`{,]+,/g, "styled('div',");
186
- const a = f(s, "js", n + ".js"), h = v(t), r = await Q(t);
190
+ const a = f(s, "js", n + ".js"), h = tt(t), r = await Q(t);
187
191
  await L.build({
188
192
  stdin: {
189
193
  contents: g,
@@ -204,34 +208,34 @@ const Q = async (t) => {
204
208
  const u = Date.now();
205
209
  return await import(`${a}?t=${u}`);
206
210
  }, z = async (t) => {
207
- const e = A(t), s = f(e, "salty.config.js"), { config: n } = await import(s);
211
+ const e = J(t), s = f(e, "salty.config.js"), { config: n } = await import(s);
208
212
  return n;
209
- }, tt = () => {
213
+ }, et = () => {
210
214
  try {
211
215
  return process.env.NODE_ENV === "production";
212
216
  } catch {
213
217
  return !1;
214
218
  }
215
- }, Tt = async (t, e = tt()) => {
219
+ }, Pt = async (t, e = et()) => {
216
220
  try {
217
- e ? K.info("Generating CSS in production mode! 🔥") : K.info("Generating CSS in development mode! 🚀");
218
- const s = [], n = [], o = A(t), i = f(o, "index.css");
221
+ e ? H.info("Generating CSS in production mode! 🔥") : H.info("Generating CSS in development mode! 🚀");
222
+ const s = [], n = [], o = J(t), i = f(o, "index.css");
219
223
  (() => {
220
- W(o) && ot("rm -rf " + o), J(o), J(f(o, "css")), J(f(o, "types"));
221
- })(), await wt(t);
224
+ _(o) && rt("rm -rf " + o), A(o), A(f(o, "css")), A(f(o, "types"));
225
+ })(), await St(t);
222
226
  const a = await z(t);
223
- async function h(l, C) {
224
- const T = ["node_modules", "saltygen"], d = it(l);
227
+ async function h(l, x) {
228
+ const T = ["node_modules", "saltygen"], d = ct(l);
225
229
  if (d.isDirectory()) {
226
- const b = ct(l);
230
+ const b = at(l);
227
231
  if (T.some((c) => l.includes(c))) return;
228
- await Promise.all(b.map((c) => h(f(l, c), f(C, c))));
229
- } else if (d.isFile() && I(l)) {
230
- const j = await Z(t, l, o), c = [];
232
+ await Promise.all(b.map((c) => h(f(l, c), f(x, c))));
233
+ } else if (d.isFile() && B(l)) {
234
+ const j = await I(t, l, o), c = [];
231
235
  Object.entries(j).forEach(([F, w]) => {
232
236
  if (w.isKeyframes && w.css) {
233
- const G = `${w.animationName}.css`, st = `css/${G}`, nt = f(o, st);
234
- s.push(G), P(nt, w.css);
237
+ const K = `${w.animationName}.css`, nt = `css/${K}`, ot = f(o, nt);
238
+ s.push(K), E(ot, w.css);
235
239
  return;
236
240
  }
237
241
  if (!w.generator) return;
@@ -239,20 +243,20 @@ const Q = async (t) => {
239
243
  name: F,
240
244
  config: a,
241
245
  prod: e
242
- }), E = `${S.hash}-${S.priority}.css`;
243
- n[S.priority] || (n[S.priority] = []), n[S.priority].push(E), c.push(E);
244
- const M = `css/${E}`, et = f(o, M);
245
- P(et, S.css);
246
+ }), P = `${S.hash}-${S.priority}.css`;
247
+ n[S.priority] || (n[S.priority] = []), n[S.priority].push(P), c.push(P);
248
+ const D = `css/${P}`, st = f(o, D);
249
+ E(st, S.css);
246
250
  });
247
251
  const p = c.map((F) => `@import url('./${F}');`).join(`
248
- `), y = B(l, 6), m = f(o, `css/${y}.css`);
249
- P(m, p);
252
+ `), y = W(l, 6), m = f(o, `css/${y}.css`);
253
+ E(m, p);
250
254
  }
251
255
  }
252
256
  await h(t, o);
253
257
  const r = s.map((l) => `@import url('./css/${l}');`).join(`
254
258
  `);
255
- let x = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
259
+ let k = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
256
260
 
257
261
  ${["variables.css", "global.css", "templates.css"].filter((l) => {
258
262
  try {
@@ -264,68 +268,68 @@ ${["variables.css", "global.css", "templates.css"].filter((l) => {
264
268
  `)}
265
269
  ${r}`;
266
270
  if (a.importStrategy !== "component") {
267
- const l = n.flat().map((C) => `@import url('./css/${C}');`).join(`
271
+ const l = n.flat().map((x) => `@import url('./css/${x}');`).join(`
268
272
  `);
269
- x += l;
273
+ k += l;
270
274
  }
271
- P(i, x);
275
+ E(i, k);
272
276
  } catch (s) {
273
277
  console.error(s);
274
278
  }
275
- }, Pt = async (t, e) => {
279
+ }, Et = async (t, e) => {
276
280
  try {
277
281
  const s = [], n = f(t, "./saltygen"), o = f(n, "index.css");
278
- if (I(e)) {
279
- const g = await z(t), a = await Z(t, e, n);
280
- Object.entries(a).forEach(([k, x]) => {
281
- if (!x.generator) return;
282
- const l = x.generator._withBuildContext({
283
- name: k,
282
+ if (B(e)) {
283
+ const g = await z(t), a = await I(t, e, n);
284
+ Object.entries(a).forEach(([C, k]) => {
285
+ if (!k.generator) return;
286
+ const l = k.generator._withBuildContext({
287
+ name: C,
284
288
  config: g
285
- }), C = `${l.hash}-${l.priority}.css`, T = `css/${C}`, d = f(n, T);
286
- s.push(C), P(d, l.css);
289
+ }), x = `${l.hash}-${l.priority}.css`, T = `css/${x}`, d = f(n, T);
290
+ s.push(x), E(d, l.css);
287
291
  });
288
292
  const h = N(o, "utf8").split(`
289
- `), r = s.map((k) => `@import url('../saltygen/css/${k}');`), $ = [.../* @__PURE__ */ new Set([...h, ...r])].join(`
293
+ `), r = s.map((C) => `@import url('../saltygen/css/${C}');`), $ = [.../* @__PURE__ */ new Set([...h, ...r])].join(`
290
294
  `);
291
- P(o, $);
295
+ E(o, $);
292
296
  }
293
297
  } catch (s) {
294
298
  console.error(s);
295
299
  }
296
- }, Et = async (t, e, s = tt()) => {
300
+ }, Dt = async (t, e, s = et()) => {
297
301
  try {
298
302
  const n = f(t, "./saltygen");
299
- if (I(e)) {
303
+ if (B(e)) {
300
304
  const i = N(e, "utf8");
301
- i.replace(/^(?!export\s)const\s.*/gm, ($) => `export ${$}`) !== i && await lt(e, i);
302
- const a = await z(t), h = await Z(t, e, n);
305
+ i.replace(/^(?!export\s)const\s.*/gm, ($) => `export ${$}`) !== i && await ft(e, i);
306
+ const a = await z(t), h = await I(t, e, n);
303
307
  let r = i;
304
- Object.entries(h).forEach(([$, k]) => {
305
- var E;
306
- if (k.isKeyframes || !k.generator) return;
307
- const x = k.generator._withBuildContext({
308
+ Object.entries(h).forEach(([$, C]) => {
309
+ var P;
310
+ if (C.isKeyframes || !C.generator) return;
311
+ const k = C.generator._withBuildContext({
308
312
  name: $,
309
313
  config: a,
310
314
  prod: s
311
315
  }), l = new RegExp(`\\s${$}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(i);
312
316
  if (!l) return console.error("Could not find the original declaration");
313
- const C = (E = l.at(1)) == null ? void 0 : E.trim(), T = new RegExp(`\\s${$}[=\\s]+styled\\(`, "g").exec(r);
317
+ const x = (P = l.at(1)) == null ? void 0 : P.trim(), T = new RegExp(`\\s${$}[=\\s]+styled\\(`, "g").exec(r);
314
318
  if (!T) return console.error("Could not find the original declaration");
315
319
  const { index: d } = T;
316
320
  let b = !1;
317
321
  const j = setTimeout(() => b = !0, 5e3);
318
322
  let c = 0, p = !1, y = 0;
319
323
  for (; !p && !b; ) {
320
- const M = r[d + c];
321
- M === "(" && y++, M === ")" && y--, y === 0 && M === ")" && (p = !0), c > r.length && (b = !0), c++;
324
+ const D = r[d + c];
325
+ D === "(" && y++, D === ")" && y--, y === 0 && D === ")" && (p = !0), c > r.length && (b = !0), c++;
322
326
  }
323
327
  if (!b) clearTimeout(j);
324
328
  else throw new Error("Failed to find the end of the styled call and timed out");
325
- const m = d + c, F = r.slice(d, m), w = r, S = ` ${$} = styled(${C}, "${x.classNames}", ${JSON.stringify(x.props)});`;
326
- r = r.replace(F, S), w === r && console.error("Minimize file failed to change content", { name: $, tagName: C });
329
+ const m = d + c, F = r.slice(d, m), w = r, S = ` ${$} = styled(${x}, "${k.classNames}", ${JSON.stringify(k.props)});`;
330
+ r = r.replace(F, S), w === r && console.error("Minimize file failed to change content", { name: $, tagName: x });
327
331
  });
328
- const u = B(e, 6);
332
+ const u = W(e, 6);
329
333
  return a.importStrategy === "component" && (r = `import '../../saltygen/css/${u}.css';
330
334
  ${r}`), r = r.replace("{ styled }", "{ styledClient as styled }"), r = r.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), r;
331
335
  }
@@ -334,8 +338,8 @@ ${r}`), r = r.replace("{ styled }", "{ styledClient as styled }"), r = r.replace
334
338
  }
335
339
  };
336
340
  export {
337
- Pt as a,
338
- Tt as g,
339
- Et as m,
340
- bt as s
341
+ Et as a,
342
+ Pt as g,
343
+ Dt as m,
344
+ jt as s
341
345
  };
package/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=require("path"),u=require("./index-Br4T7QQ3.cjs"),r=(e,s,o=!1,n=!1)=>{var a,l,t;(l=(a=e.module)==null?void 0:a.rules)==null||l.push({test:u.saltyFileRegExp(),use:[{loader:p.resolve(__dirname,n?"./loader.cjs":"./loader.js"),options:{dir:s}}]}),o||(t=e.plugins)==null||t.push({apply:i=>{i.hooks.afterPlugins.tap({name:"generateCss"},async()=>{await u.generateCss(s)})}})};exports.default=r;exports.saltyPlugin=r;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=require("path"),u=require("./index-55a7q00M.cjs"),r=(e,s,o=!1,n=!1)=>{var a,l,t;(l=(a=e.module)==null?void 0:a.rules)==null||l.push({test:u.saltyFileRegExp(),use:[{loader:p.resolve(__dirname,n?"./loader.cjs":"./loader.js"),options:{dir:s}}]}),o||(t=e.plugins)==null||t.push({apply:i=>{i.hooks.afterPlugins.tap({name:"generateCss"},async()=>{await u.generateCss(s)})}})};exports.default=r;exports.saltyPlugin=r;
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { resolve as n } from "path";
2
- import { s as u, g as i } from "./index-B6c67i1F.js";
2
+ import { s as u, g as i } from "./index-BVNy6_ZE.js";
3
3
  const g = (s, e, o = !1, r = !1) => {
4
4
  var a, l, t;
5
5
  (l = (a = s.module) == null ? void 0 : a.rules) == null || l.push({
package/loader.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";const i=require("./index-Br4T7QQ3.cjs");async function n(){const{dir:e}=this.getOptions(),{resourcePath:t}=this;return await i.generateFile(e,t),await i.minimizeFile(e,t)}module.exports=n;
1
+ "use strict";const i=require("./index-55a7q00M.cjs");async function n(){const{dir:e}=this.getOptions(),{resourcePath:t}=this;return await i.generateFile(e,t),await i.minimizeFile(e,t)}module.exports=n;
package/loader.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as e, m as i } from "./index-B6c67i1F.js";
1
+ import { a as e, m as i } from "./index-BVNy6_ZE.js";
2
2
  async function s() {
3
3
  const { dir: t } = this.getOptions(), { resourcePath: a } = this;
4
4
  return await e(t, a), await i(t, a);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/webpack",
3
- "version": "0.0.1-alpha.115",
3
+ "version": "0.0.1-alpha.116",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -34,7 +34,7 @@
34
34
  }
35
35
  },
36
36
  "dependencies": {
37
- "@salty-css/core": "^0.0.1-alpha.115",
37
+ "@salty-css/core": "^0.0.1-alpha.116",
38
38
  "webpack": ">=5.x"
39
39
  }
40
40
  }
@@ -1,28 +0,0 @@
1
- "use strict";const ot=require("esbuild"),rt=require("child_process"),l=require("path"),u=require("fs"),L=require("fs/promises"),V=require("winston");var J=typeof document<"u"?document.currentScript:null;function it(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 U=it(ot),B=t=>String.fromCharCode(t+(t>25?39:97)),ct=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=B(n%52)+s;return s=B(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},at=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},A=(t,e=3)=>{const s=at(5381,JSON.stringify(t))>>>0;return ct(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 lt=(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:i}=n;t=t.replace(o,y=>{const{value:a,css:j}=i(y);return j&&s.push(j),a})}),{result:t,additionalCss:s}},G=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${M(n[1].replaceAll(".","-"))})`)}:{result:t},D=(t,e,s,n)=>{if(!t)return"";const o=[],i=Object.entries(t).reduce((a,[j,r])=>{const d=j.trim();if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return a;if(d==="variants")return Object.entries(r).forEach(([S,c])=>{c&&Object.entries(c).forEach(([p,m])=>{if(!m)return;const h=`${e}.${S}-${p}`,T=D(m,h);o.push(T)})}),a;if(d==="defaultVariants")return a;if(d==="compoundVariants")return r.forEach(S=>{const{css:c,...p}=S,m=Object.entries(p).reduce((T,[w,F])=>`${T}.${w}-${F}`,e),h=D(c,m);o.push(h)}),a;if(d.startsWith("@")){const S=D(r,e),c=`${d} {
2
- ${S.replace(`
3
- `,`
4
- `)}
5
- }`;return o.push(c),a}const g=j.includes("&")?d.replace("&",e):d.startsWith(":")?`${e}${d}`:`${e} ${d}`,$=D(r,g);return o.push($),a}const b=d.startsWith("-")?d:M(d),k=(g,$=";")=>a=`${a}${g}${$}`,C=g=>k(`${b}:${g}`);if(typeof r=="number")return C(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return a;const{modifiers:f}={},P=function*(){yield G(r),yield lt(r,f)}();for(const{result:g,additionalCss:$=[]}of P)r=g,$.forEach(S=>{const c=D(S,"");k(c,"")});return C(r)},"");if(!i)return o.join(`
6
- `);if(!e)return i;let y="";return y=`${e} { ${i} }`,[y,...o].join(`
7
- `)},H=(t,e=[])=>{if(!t)return"";const s=[],n={};if(Object.entries(t).forEach(([o,i])=>{if(typeof i=="object"){if(!i)return;const y=o.trim(),a=H(i,[...e,y]);s.push(a)}else n[o]=i}),Object.keys(n).length){const o=e.map(M).join("-"),i=D(n,`.${o}`);s.push(i)}return s.join(`
8
- `)},ft=t=>Object.entries(t).reduce((e,[s,n])=>(typeof n=="object"&&(e[s]=K(n).map(o=>`"${o}"`).join(" | ")),e),{}),K=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const i=e?`${e}.${n}`:n;return typeof o=="object"?K(o,i,s):s.add(e)}),[...s]):[],X=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:X(l.join(t,".."))},ut=async t=>{const e=X(t);return await L.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},pt=async t=>{const e=await ut(t);if(e)return e.type};let E;const Y=async t=>{if(E)return E;const e=await pt(t);return e==="module"?E="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:J&&J.tagName.toUpperCase()==="SCRIPT"&&J.src||new URL("index-Br4T7QQ3.cjs",document.baseURI).href).endsWith(".cjs"))&&(E="cjs"),E||"esm"},Z=V.createLogger({level:"debug",format:V.format.combine(V.format.colorize(),V.format.cli()),transports:[new V.transports.Console({})]}),R={externalModules:[]},Q=t=>{if(R.externalModules.length>0)return R.externalModules;const e=l.join(t,"salty.config.ts"),n=u.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!n)return[];const o=n[1].split(",").map(i=>i.replace(/['"`]/g,"").trim());return R.externalModules=o,o},_=t=>l.join(t,"./saltygen"),dt=["salty","css","styles","styled"],v=(t=[])=>new RegExp(`\\.(${[...dt,...t].join("|")})\\.`),q=(t,e=[])=>v(e).test(t),yt=async t=>{const e=_(t),s=l.join(t,"salty.config.ts"),n=l.join(e,"salty.config.js"),o=await Y(t),i=Q(t);await U.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:o,external:i});const y=Date.now(),{config:a}=await import(`${n}?t=${y}`);return a},gt=async t=>{const e=await yt(t),s=new Set,n=(c,p=[])=>c?Object.entries(c).flatMap(([m,h])=>{if(!h)return;if(typeof h=="object")return n(h,[...p,m]);const T=[...p,m].join(".");s.add(`"${T}"`);const w=[...p.map(M),M(m)].join("-"),{result:F}=G(h);return`--${w}: ${F};`}):[],o=c=>c?Object.entries(c).flatMap(([p,m])=>{const h=n(m);return p==="base"?h.join(""):`${p} { ${h.join("")} }`}):[],i=c=>c?Object.entries(c).flatMap(([p,m])=>Object.entries(m).flatMap(([h,T])=>{const w=n(T,[p]),F=`.${p}-${h}, [data-${p}="${h}"]`,O=w.join("");return`${F} { ${O} }`})):[],y=n(e.variables),a=o(e.responsiveVariables),j=i(e.conditionalVariables),r=_(t),d=l.join(r,"css/variables.css"),b=`:root { ${y.join("")} ${a.join("")} } ${j.join("")}`;u.writeFileSync(d,b);const k=l.join(r,"css/global.css"),C=D(e.global,"");u.writeFileSync(k,C);const f=l.join(r,"css/templates.css"),x=H(e.templates),P=ft(e.templates);u.writeFileSync(f,x);const g=l.join(r,"types/css-tokens.d.ts"),S=`
9
- // Variable types
10
- type VariableTokens = ${[...s].join("|")};
11
- type PropertyValueToken = \`{\${VariableTokens}}\`;
12
-
13
- // Template types
14
- type TemplateTokens = {
15
- ${Object.entries(P).map(([c,p])=>`${c}?: ${p}`).join(`
16
- `)}
17
- }
18
- `;u.writeFileSync(g,S)},I=async(t,e,s)=>{const n=A(e),o=l.join(s,"./temp");u.existsSync(o)||u.mkdirSync(o);const i=l.parse(e);let y=u.readFileSync(e,"utf8");y=y.replace(/styled\([^"'`{,]+,/g,"styled('div',");const a=l.join(s,"js",n+".js"),j=Q(t),r=await Y(t);await U.build({stdin:{contents:y,sourcefile:i.base,resolveDir:i.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:a,format:r,target:["node20"],keepNames:!0,external:j,packages:"external"});const d=Date.now();return await import(`${a}?t=${d}`)},z=async t=>{const e=_(t),s=l.join(e,"salty.config.js"),{config:n}=await import(s);return n},tt=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},mt=async(t,e=tt())=>{try{e?Z.info("Generating CSS in production mode! 🔥"):Z.info("Generating CSS in development mode! 🚀");const s=[],n=[],o=_(t),i=l.join(o,"index.css");(()=>{u.existsSync(o)&&rt.execSync("rm -rf "+o),u.mkdirSync(o),u.mkdirSync(l.join(o,"css")),u.mkdirSync(l.join(o,"types"))})(),await gt(t);const a=await z(t);async function j(f,x){const P=["node_modules","saltygen"],g=u.statSync(f);if(g.isDirectory()){const $=u.readdirSync(f);if(P.some(c=>f.includes(c)))return;await Promise.all($.map(c=>j(l.join(f,c),l.join(x,c))))}else if(g.isFile()&&q(f)){const S=await I(t,f,o),c=[];Object.entries(S).forEach(([T,w])=>{if(w.isKeyframes&&w.css){const W=`${w.animationName}.css`,st=`css/${W}`,nt=l.join(o,st);s.push(W),u.writeFileSync(nt,w.css);return}if(!w.generator)return;const F=w.generator._withBuildContext({name:T,config:a,prod:e}),O=`${F.hash}-${F.priority}.css`;n[F.priority]||(n[F.priority]=[]),n[F.priority].push(O),c.push(O);const N=`css/${O}`,et=l.join(o,N);u.writeFileSync(et,F.css)});const p=c.map(T=>`@import url('./${T}');`).join(`
19
- `),m=A(f,6),h=l.join(o,`css/${m}.css`);u.writeFileSync(h,p)}}await j(t,o);const r=s.map(f=>`@import url('./css/${f}');`).join(`
20
- `);let C=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
21
-
22
- ${["variables.css","global.css","templates.css"].filter(f=>{try{return u.readFileSync(l.join(o,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
23
- `)}
24
- ${r}`;if(a.importStrategy!=="component"){const f=n.flat().map(x=>`@import url('./css/${x}');`).join(`
25
- `);C+=f}u.writeFileSync(i,C)}catch(s){console.error(s)}},ht=async(t,e)=>{try{const s=[],n=l.join(t,"./saltygen"),o=l.join(n,"index.css");if(q(e)){const y=await z(t),a=await I(t,e,n);Object.entries(a).forEach(([k,C])=>{if(!C.generator)return;const f=C.generator._withBuildContext({name:k,config:y}),x=`${f.hash}-${f.priority}.css`,P=`css/${x}`,g=l.join(n,P);s.push(x),u.writeFileSync(g,f.css)});const j=u.readFileSync(o,"utf8").split(`
26
- `),r=s.map(k=>`@import url('../saltygen/css/${k}');`),b=[...new Set([...j,...r])].join(`
27
- `);u.writeFileSync(o,b)}}catch(s){console.error(s)}},jt=async(t,e,s=tt())=>{try{const n=l.join(t,"./saltygen");if(q(e)){const i=u.readFileSync(e,"utf8");i.replace(/^(?!export\s)const\s.*/gm,b=>`export ${b}`)!==i&&await L.writeFile(e,i);const a=await z(t),j=await I(t,e,n);let r=i;Object.entries(j).forEach(([b,k])=>{var O;if(k.isKeyframes||!k.generator)return;const C=k.generator._withBuildContext({name:b,config:a,prod:s}),f=new RegExp(`\\s${b}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(i);if(!f)return console.error("Could not find the original declaration");const x=(O=f.at(1))==null?void 0:O.trim(),P=new RegExp(`\\s${b}[=\\s]+styled\\(`,"g").exec(r);if(!P)return console.error("Could not find the original declaration");const{index:g}=P;let $=!1;const S=setTimeout(()=>$=!0,5e3);let c=0,p=!1,m=0;for(;!p&&!$;){const N=r[g+c];N==="("&&m++,N===")"&&m--,m===0&&N===")"&&(p=!0),c>r.length&&($=!0),c++}if(!$)clearTimeout(S);else throw new Error("Failed to find the end of the styled call and timed out");const h=g+c,T=r.slice(g,h),w=r,F=` ${b} = styled(${x}, "${C.classNames}", ${JSON.stringify(C.props)});`;r=r.replace(T,F),w===r&&console.error("Minimize file failed to change content",{name:b,tagName:x})});const d=A(e,6);return a.importStrategy==="component"&&(r=`import '../../saltygen/css/${d}.css';
28
- ${r}`),r=r.replace("{ styled }","{ styledClient as styled }"),r=r.replace("@salty-css/react/styled","@salty-css/react/styled-client"),r}}catch(n){console.error("Error in minimizeFile:",n)}};exports.generateCss=mt;exports.generateFile=ht;exports.minimizeFile=jt;exports.saltyFileRegExp=v;