@salty-css/webpack 0.0.1-alpha.145 → 0.0.1-alpha.146

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