@salty-css/webpack 0.0.1-alpha.138 → 0.0.1-alpha.139

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.
@@ -26,19 +26,19 @@ const jt = (t, e) => {
26
26
  return Object.values(e).forEach((n) => {
27
27
  const { pattern: i, transform: o } = n;
28
28
  t = t.replace(i, (f) => {
29
- const { value: m, css: a } = o(f);
30
- return a && s.push(a), m;
29
+ const { value: y, css: a } = o(f);
30
+ return a && s.push(a), y;
31
31
  });
32
32
  }), { result: t, additionalCss: s };
33
33
  }, v = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${V(n[1].replaceAll(".", "-"))})`) } : { result: t }, O = (t, e, s) => {
34
34
  if (!t) return "";
35
- const n = [], i = Object.entries(t).reduce((f, [m, a]) => {
36
- const r = m.trim();
35
+ const n = [], i = Object.entries(t).reduce((f, [y, a]) => {
36
+ const r = y.trim();
37
37
  if (typeof a == "function" && (a = a()), typeof a == "object") {
38
38
  if (!a) return f;
39
39
  if (r === "variants")
40
- return Object.entries(a).forEach(([c, d]) => {
41
- d && Object.entries(d).forEach(([x, j]) => {
40
+ return Object.entries(a).forEach(([c, u]) => {
41
+ u && Object.entries(u).forEach(([x, j]) => {
42
42
  if (!j) return;
43
43
  const T = `${e}.${c}-${x}`, k = O(j, T);
44
44
  n.push(k);
@@ -48,32 +48,32 @@ const jt = (t, e) => {
48
48
  return f;
49
49
  if (r === "compoundVariants")
50
50
  return a.forEach((c) => {
51
- const { css: d, ...x } = c, j = Object.entries(x).reduce((k, [p, g]) => `${k}.${p}-${g}`, e), T = O(d, j);
51
+ const { css: u, ...x } = c, j = Object.entries(x).reduce((k, [d, m]) => `${k}.${d}-${m}`, e), T = O(u, j);
52
52
  n.push(T);
53
53
  }), f;
54
54
  if (r.startsWith("@")) {
55
- const c = O(a, e), d = `${r} {
55
+ const c = O(a, e), u = `${r} {
56
56
  ${c.replace(`
57
57
  `, `
58
58
  `)}
59
59
  }`;
60
- return n.push(d), f;
60
+ return n.push(u), f;
61
61
  }
62
- const u = m.includes("&") ? r.replace("&", e) : r.startsWith(":") ? `${e}${r}` : `${e} ${r}`, $ = O(a, u);
63
- return n.push($), f;
62
+ const p = y.includes("&") ? r.replace("&", e) : r.startsWith(":") ? `${e}${r}` : `${e} ${r}`, h = O(a, p);
63
+ return n.push(h), f;
64
64
  }
65
- const y = r.startsWith("-") ? r : V(r), w = (u, $ = ";") => f = `${f}${u}${$}`, S = (u) => w(`${y}:${u}`);
65
+ const $ = r.startsWith("-") ? r : V(r), w = (p, h = ";") => f = `${f}${p}${h}`, S = (p) => w(`${$}:${p}`);
66
66
  if (typeof a == "number") return S(a);
67
67
  if (typeof a != "string")
68
68
  if ("toString" in a) a = a.toString();
69
69
  else return f;
70
- const { modifiers: h } = {}, P = function* () {
71
- yield v(a), yield jt(a, h);
70
+ const { modifiers: g } = {}, P = function* () {
71
+ yield v(a), yield jt(a, g);
72
72
  }();
73
- for (const { result: u, additionalCss: $ = [] } of P)
74
- a = u, $.forEach((c) => {
75
- const d = O(c, "");
76
- w(d, "");
73
+ for (const { result: p, additionalCss: h = [] } of P)
74
+ a = p, h.forEach((c) => {
75
+ const u = O(c, "");
76
+ w(u, "");
77
77
  });
78
78
  return S(a);
79
79
  }, "");
@@ -86,8 +86,8 @@ const jt = (t, e) => {
86
86
  if (Object.entries(t).forEach(([i, o]) => {
87
87
  if (typeof o == "object") {
88
88
  if (!o) return;
89
- const f = i.trim(), m = tt(o, [...e, f]);
90
- s.push(m);
89
+ const f = i.trim(), y = tt(o, [...e, f]);
90
+ s.push(y);
91
91
  } else
92
92
  n[i] = o;
93
93
  }), Object.keys(n).length) {
@@ -190,30 +190,30 @@ const Ct = {
190
190
  format: i,
191
191
  external: o
192
192
  });
193
- const f = Date.now(), { config: m } = await import(`${n}?t=${f}`);
194
- return m;
193
+ const f = Date.now(), { config: y } = await import(`${n}?t=${f}`);
194
+ return y;
195
195
  }, Pt = async (t) => {
196
- const e = await Nt(t), s = /* @__PURE__ */ new Set(), n = (p, g = []) => p ? Object.entries(p).flatMap(([F, b]) => {
196
+ const e = await Nt(t), s = /* @__PURE__ */ new Set(), n = (d, m = []) => d ? Object.entries(d).flatMap(([F, b]) => {
197
197
  if (!b) return;
198
- if (typeof b == "object") return n(b, [...g, F]);
199
- const M = ot(F), J = V(F), _ = [...g, M].join(".");
198
+ if (typeof b == "object") return n(b, [...m, F]);
199
+ const M = ot(F), J = V(F), _ = [...m, M].join(".");
200
200
  s.add(`"${_}"`);
201
- const D = [...g.map(V), J].join("-"), { result: E } = v(b);
201
+ const D = [...m.map(V), J].join("-"), { result: E } = v(b);
202
202
  return `--${D}: ${E};`;
203
- }) : [], i = (p) => p ? Object.entries(p).flatMap(([g, F]) => {
203
+ }) : [], i = (d) => d ? Object.entries(d).flatMap(([m, F]) => {
204
204
  const b = n(F);
205
- return g === "base" ? b.join("") : `${g} { ${b.join("")} }`;
206
- }) : [], o = (p) => p ? Object.entries(p).flatMap(([g, F]) => Object.entries(F).flatMap(([b, M]) => {
207
- const J = n(M, [g]), _ = `.${g}-${b}, [data-${g}="${b}"]`, D = J.join("");
205
+ return m === "base" ? b.join("") : `${m} { ${b.join("")} }`;
206
+ }) : [], o = (d) => d ? Object.entries(d).flatMap(([m, F]) => Object.entries(F).flatMap(([b, M]) => {
207
+ const J = n(M, [m]), _ = `.${m}-${b}, [data-${m}="${b}"]`, D = J.join("");
208
208
  return `${_} { ${D} }`;
209
- })) : [], f = n(e.variables), m = i(e.responsiveVariables), a = o(e.conditionalVariables), r = z(t), y = l(r, "css/_variables.css"), w = `:root { ${f.join("")} ${m.join("")} } ${a.join("")}`;
210
- N(y, w);
211
- const S = l(r, "css/_global.css"), h = O(e.global, "");
212
- N(S, `@layer global { ${h} }`);
213
- const C = l(r, "css/_reset.css"), u = e.reset === "none" ? {} : typeof e.reset == "object" ? e.reset : Ct, $ = O(u, "");
214
- N(C, `@layer reset { ${$} }`);
215
- const c = l(r, "css/_templates.css"), d = tt(e.templates), x = wt(e.templates);
216
- N(c, d);
209
+ })) : [], f = n(e.variables), y = i(e.responsiveVariables), a = o(e.conditionalVariables), r = z(t), $ = l(r, "css/_variables.css"), w = `:root { ${f.join("")} ${y.join("")} } ${a.join("")}`;
210
+ N($, w);
211
+ const S = l(r, "css/_global.css"), g = O(e.global, "");
212
+ N(S, `@layer global { ${g} }`);
213
+ const C = l(r, "css/_reset.css"), p = e.reset === "none" ? {} : typeof e.reset == "object" ? e.reset : Ct, h = O(p, "");
214
+ N(C, `@layer reset { ${h} }`);
215
+ const c = l(r, "css/_templates.css"), u = tt(e.templates), x = wt(e.templates);
216
+ N(c, u);
217
217
  const j = l(r, "types/css-tokens.d.ts"), k = `
218
218
  // Variable types
219
219
  type VariableTokens = ${[...s].join("|")};
@@ -221,7 +221,7 @@ const Ct = {
221
221
 
222
222
  // Template types
223
223
  type TemplateTokens = {
224
- ${Object.entries(x).map(([p, g]) => `${p}?: ${g}`).join(`
224
+ ${Object.entries(x).map(([d, m]) => `${d}?: ${m}`).join(`
225
225
  `)}
226
226
  }
227
227
  `;
@@ -231,18 +231,18 @@ const Ct = {
231
231
  K(i) || W(i);
232
232
  const o = B(e);
233
233
  let f = R(e, "utf8");
234
- f = f.replace(/styled\(([^"'`{,]+),/g, (S, h) => {
235
- if (/^['"`]/.test(h)) return S;
236
- const P = new RegExp(`import[^;]*${h}[,\\s{][^;]*from\\s?([^{};]+);`);
237
- if (!P.test(f)) return S;
238
- const $ = P.exec(f);
239
- if ($) {
240
- const c = $.at(1);
241
- if (it.some((x) => c == null ? void 0 : c.includes(x))) return S;
234
+ f = f.replace(/styled\(([^"'`{,]+),/g, (S, g) => {
235
+ if (/^['"`]/.test(g)) return S;
236
+ const P = new RegExp(`import[^;]*${g}[,\\s{][^;]*from\\s?([^{};]+);`), p = P.test(f);
237
+ if (p || console.log("Not imported", g), !p) return S;
238
+ const h = P.exec(f);
239
+ if (h) {
240
+ const c = h.at(1), u = it.some((x) => c == null ? void 0 : c.includes(x));
241
+ if (u && console.log("Salty import", g, h.at(0)), u) return S;
242
242
  }
243
- return "styled('div',";
243
+ return console.log("Replacing", g), "styled('div',";
244
244
  });
245
- const m = l(s, "js", n + ".js"), a = rt(t), r = await nt(t);
245
+ const y = l(s, "js", n + ".js"), a = rt(t), r = await nt(t);
246
246
  await Q.build({
247
247
  stdin: {
248
248
  contents: f,
@@ -253,15 +253,15 @@ const Ct = {
253
253
  minify: !1,
254
254
  treeShaking: !0,
255
255
  bundle: !0,
256
- outfile: m,
256
+ outfile: y,
257
257
  format: r,
258
258
  target: ["node20"],
259
259
  keepNames: !0,
260
260
  external: a,
261
261
  packages: "external"
262
262
  });
263
- const y = Date.now();
264
- return await import(`${m}?t=${y}`);
263
+ const $ = Date.now();
264
+ return await import(`${y}?t=${$}`);
265
265
  }, U = async (t) => {
266
266
  const e = z(t), s = l(e, "salty.config.js"), n = Date.now(), { config: i } = await import(`${s}?t=${n}`);
267
267
  return i;
@@ -280,14 +280,14 @@ const Ct = {
280
280
  K(o) && ut("rm -rf " + o), W(o), W(l(o, "css")), W(l(o, "types"));
281
281
  })(), await Pt(t);
282
282
  const a = await U(t);
283
- async function r(c, d) {
283
+ async function r(c, u) {
284
284
  const x = ["node_modules", "saltygen"], j = dt(c);
285
285
  if (j.isDirectory()) {
286
286
  const T = gt(c);
287
- if (x.some((p) => c.includes(p))) return;
288
- await Promise.all(T.map((p) => r(l(c, p), l(d, p))));
287
+ if (x.some((d) => c.includes(d))) return;
288
+ await Promise.all(T.map((d) => r(l(c, d), l(u, d))));
289
289
  } else if (j.isFile() && L(c)) {
290
- const k = await q(t, c, o), p = [];
290
+ const k = await q(t, c, o), d = [];
291
291
  Object.entries(k).forEach(([_, D]) => {
292
292
  if (D.isKeyframes && D.css) {
293
293
  const X = `a_${D.animationName}.css`, ft = `css/${X}`, pt = l(o, ft);
@@ -300,17 +300,17 @@ const Ct = {
300
300
  config: a,
301
301
  prod: e
302
302
  });
303
- i[E.priority] || (i[E.priority] = []), i[E.priority].push(E.cssFileName), p.push(E.cssFileName);
303
+ i[E.priority] || (i[E.priority] = []), i[E.priority].push(E.cssFileName), d.push(E.cssFileName);
304
304
  const at = `css/${E.cssFileName}`, lt = l(o, at);
305
305
  N(lt, E.css);
306
306
  });
307
- const g = p.map((_) => `@import url('./${_}');`).join(`
307
+ const m = d.map((_) => `@import url('./${_}');`).join(`
308
308
  `), F = G(c, 6), b = B(c), M = V(b.name), J = l(o, `css/f_${M}-${F}.css`);
309
- N(J, g);
309
+ N(J, m);
310
310
  }
311
311
  }
312
312
  await r(t, o);
313
- const y = n.map((c) => `@import url('./css/${c}');`).join(`
313
+ const $ = n.map((c) => `@import url('./css/${c}');`).join(`
314
314
  `);
315
315
  let C = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
316
316
 
@@ -322,22 +322,22 @@ ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((c) =
322
322
  }
323
323
  }).map((c) => `@import url('./css/${c}');`).join(`
324
324
  `)}
325
- ${y}`;
325
+ ${$}`;
326
326
  if (a.importStrategy !== "component") {
327
- const c = i.reduce((d, x, j) => {
327
+ const c = i.reduce((u, x, j) => {
328
328
  const T = x.reduce((F, b) => {
329
329
  const M = R(l(o, "css", b), "utf8");
330
330
  return `${F}
331
331
  ${M}`;
332
- }, ""), k = `l_${j}.css`, p = l(o, "css", k), g = `@layer l${j} { ${T} }`;
333
- return N(p, g), `${d}
332
+ }, ""), k = `l_${j}.css`, d = l(o, "css", k), m = `@layer l${j} { ${T} }`;
333
+ return N(d, m), `${u}
334
334
  @import url('./css/${k}');`;
335
335
  }, "");
336
336
  C += c;
337
337
  }
338
338
  N(f, C);
339
- const u = Date.now() - s, $ = u < 200 ? "🔥" : u < 500 ? "🚀" : u < 1e3 ? "🎉" : u < 2e3 ? "🚗" : u < 5e3 ? "🤔" : "🥴";
340
- I.info(`Generated CSS in ${u}ms! ${$}`);
339
+ const p = Date.now() - s, h = p < 200 ? "🔥" : p < 500 ? "🚀" : p < 1e3 ? "🎉" : p < 2e3 ? "🚗" : p < 5e3 ? "🤔" : "🥴";
340
+ I.info(`Generated CSS in ${p}ms! ${h}`);
341
341
  } catch (s) {
342
342
  console.error(s);
343
343
  }
@@ -345,19 +345,19 @@ ${M}`;
345
345
  try {
346
346
  const s = [], n = l(t, "./saltygen"), i = l(n, "index.css");
347
347
  if (L(e)) {
348
- const f = await U(t), m = await q(t, e, n);
349
- Object.entries(m).forEach(([S, h]) => {
350
- if (h.isKeyframes && h.css) {
351
- const c = `css/${`a_${h.animationName}.css`}`, d = l(n, c);
352
- N(d, h.css);
348
+ const f = await U(t), y = await q(t, e, n);
349
+ Object.entries(y).forEach(([S, g]) => {
350
+ if (g.isKeyframes && g.css) {
351
+ const c = `css/${`a_${g.animationName}.css`}`, u = l(n, c);
352
+ N(u, g.css);
353
353
  return;
354
354
  }
355
- if (!h.generator) return;
356
- const C = h.generator._withBuildContext({
355
+ if (!g.generator) return;
356
+ const C = g.generator._withBuildContext({
357
357
  name: S,
358
358
  config: f
359
- }), P = `css/${C.cssFileName}`, u = l(n, P);
360
- s.push(C.cssFileName), N(u, C.css);
359
+ }), P = `css/${C.cssFileName}`, p = l(n, P);
360
+ s.push(C.cssFileName), N(p, C.css);
361
361
  });
362
362
  const a = R(i, "utf8").split(`
363
363
  `), r = s.map((S) => `@import url('../saltygen/css/${S}');`), w = [.../* @__PURE__ */ new Set([...a, ...r])].join(`
@@ -372,35 +372,35 @@ ${M}`;
372
372
  const n = l(t, "./saltygen");
373
373
  if (L(e)) {
374
374
  const o = R(e, "utf8");
375
- o.replace(/^(?!export\s)const\s.*/gm, (y) => `export ${y}`) !== o && await yt(e, o);
376
- const m = await U(t), a = await q(t, e, n);
375
+ o.replace(/^(?!export\s)const\s.*/gm, ($) => `export ${$}`) !== o && await yt(e, o);
376
+ const y = await U(t), a = await q(t, e, n);
377
377
  let r = o;
378
- if (Object.entries(a).forEach(([y, w]) => {
378
+ if (Object.entries(a).forEach(([$, w]) => {
379
379
  var F;
380
380
  if (w.isKeyframes || !w.generator) return;
381
381
  const S = w.generator._withBuildContext({
382
- name: y,
383
- config: m,
382
+ name: $,
383
+ config: y,
384
384
  prod: s
385
- }), h = new RegExp(`\\s${y}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(o);
386
- if (!h) return console.error("Could not find the original declaration");
387
- const C = (F = h.at(1)) == null ? void 0 : F.trim(), P = new RegExp(`\\s${y}[=\\s]+styled\\(`, "g").exec(r);
385
+ }), g = new RegExp(`\\s${$}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(o);
386
+ if (!g) return console.error("Could not find the original declaration");
387
+ const C = (F = g.at(1)) == null ? void 0 : F.trim(), P = new RegExp(`\\s${$}[=\\s]+styled\\(`, "g").exec(r);
388
388
  if (!P) return console.error("Could not find the original declaration");
389
- const { index: u } = P;
390
- let $ = !1;
391
- const c = setTimeout(() => $ = !0, 5e3);
392
- let d = 0, x = !1, j = 0;
393
- for (; !x && !$; ) {
394
- const b = r[u + d];
395
- b === "(" && j++, b === ")" && j--, j === 0 && b === ")" && (x = !0), d > r.length && ($ = !0), d++;
389
+ const { index: p } = P;
390
+ let h = !1;
391
+ const c = setTimeout(() => h = !0, 5e3);
392
+ let u = 0, x = !1, j = 0;
393
+ for (; !x && !h; ) {
394
+ const b = r[p + u];
395
+ b === "(" && j++, b === ")" && j--, j === 0 && b === ")" && (x = !0), u > r.length && (h = !0), u++;
396
396
  }
397
- if (!$) clearTimeout(c);
397
+ if (!h) clearTimeout(c);
398
398
  else throw new Error("Failed to find the end of the styled call and timed out");
399
- const T = u + d, k = r.slice(u, T), p = r, g = ` ${y} = styled(${C}, "${S.classNames}", ${JSON.stringify(S.props)});`;
400
- r = r.replace(k, g), p === r && console.error("Minimize file failed to change content", { name: y, tagName: C });
401
- }), m.importStrategy === "component") {
402
- const y = G(e, 6), w = B(e);
403
- r = `import '../../saltygen/css/${`f_${V(w.name)}-${y}.css`}';
399
+ const T = p + u, k = r.slice(p, T), d = r, m = ` ${$} = styled(${C}, "${S.classNames}", ${JSON.stringify(S.props)});`;
400
+ r = r.replace(k, m), d === r && console.error("Minimize file failed to change content", { name: $, tagName: C });
401
+ }), y.importStrategy === "component") {
402
+ const $ = G(e, 6), w = B(e);
403
+ r = `import '../../saltygen/css/${`f_${V(w.name)}-${$}.css`}';
404
404
  ${r}`;
405
405
  }
406
406
  return r = r.replace("{ styled }", "{ styledClient as styled }"), r = r.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), r;
@@ -0,0 +1,29 @@
1
+ "use strict";const ue=require("esbuild"),pe=require("child_process"),l=require("path"),u=require("fs"),U=require("fs/promises"),z=require("winston");var W=typeof document<"u"?document.currentScript:null;function de(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 X=de(ue),G=e=>String.fromCharCode(e+(e>25?39:97)),ye=(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},ge=(e,t)=>{let s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return e},q=(e,t=5)=>{const s=ge(5381,JSON.stringify(e))>>>0;return ye(s,t)};function E(e){return e?typeof e!="string"?E(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 me=(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:o}=n;e=e.replace(i,f=>{const{value:h,css:a}=o(f);return a&&s.push(a),h})}),{result:e,additionalCss:s}},Y=e=>typeof e!="string"?{result:e}:/\{[^{}]+\}/g.test(e)?{result:e.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${E(n[1].replaceAll(".","-"))})`)}:{result:e},O=(e,t,s)=>{if(!e)return"";const n=[],i=Object.entries(e).reduce((f,[h,a])=>{const r=h.trim();if(typeof a=="function"&&(a=a()),typeof a=="object"){if(!a)return f;if(r==="variants")return Object.entries(a).forEach(([c,d])=>{d&&Object.entries(d).forEach(([x,w])=>{if(!w)return;const T=`${t}.${c}-${x}`,N=O(w,T);n.push(N)})}),f;if(r==="defaultVariants")return f;if(r==="compoundVariants")return a.forEach(c=>{const{css:d,...x}=c,w=Object.entries(x).reduce((N,[y,m])=>`${N}.${y}-${m}`,t),T=O(d,w);n.push(T)}),f;if(r.startsWith("@")){const c=O(a,t),d=`${r} {
2
+ ${c.replace(`
3
+ `,`
4
+ `)}
5
+ }`;return n.push(d),f}const p=h.includes("&")?r.replace("&",t):r.startsWith(":")?`${t}${r}`:`${t} ${r}`,$=O(a,p);return n.push($),f}const S=r.startsWith("-")?r:E(r),F=(p,$=";")=>f=`${f}${p}${$}`,j=p=>F(`${S}:${p}`);if(typeof a=="number")return j(a);if(typeof a!="string")if("toString"in a)a=a.toString();else return f;const{modifiers:g}={},P=function*(){yield Y(a),yield me(a,g)}();for(const{result:p,additionalCss:$=[]}of P)a=p,$.forEach(c=>{const d=O(c,"");F(d,"")});return j(a)},"");return i?t?[`${t} { ${i} }`,...n].join(`
6
+ `):i:n.join(`
7
+ `)},Q=(e,t=[])=>{if(!e)return"";const s=[],n={};if(Object.entries(e).forEach(([i,o])=>{if(typeof o=="object"){if(!o)return;const f=i.trim(),h=Q(o,[...t,f]);s.push(h)}else n[i]=o}),Object.keys(n).length){const i=t.map(E).join("-"),o=O(n,`.${i}`);s.push(o)}return s.join(`
8
+ `)},he=e=>Object.entries(e).reduce((t,[s,n])=>(typeof n=="object"&&(t[s]=v(n).map(i=>`"${i}"`).join(" | ")),t),{}),v=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,i])=>{const o=t?`${t}.${n}`:n;return typeof i=="object"?v(i,o,s):s.add(t)}),[...s]):[],ee=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=l.join(e,"package.json");return u.existsSync(t)?t:ee(l.join(e,".."))},$e=async e=>{const t=ee(e);return await U.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Se=async e=>{const t=await $e(e);if(t)return t.type};let R;const te=async e=>{if(R)return R;const t=await Se(e);return t==="module"?R="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:W&&W.tagName.toUpperCase()==="SCRIPT"&&W.src||new URL("index-Cld5pSWN.cjs",document.baseURI).href).endsWith(".cjs"))&&(R="cjs"),R||"esm"},Z=z.createLogger({level:"debug",format:z.format.combine(z.format.colorize(),z.format.cli()),transports:[new z.transports.Console({})]});function se(e){return e?typeof e!="string"?se(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 be={"*, *::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"}},I={externalModules:[]},ne=e=>{if(I.externalModules.length>0)return I.externalModules;const t=l.join(e,"salty.config.ts"),n=u.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!n)return[];const i=n[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return I.externalModules=i,i},J=e=>l.join(e,"./saltygen"),oe=["salty","css","styles","styled"],re=(e=[])=>new RegExp(`\\.(${[...oe,...e].join("|")})\\.`),H=(e,t=[])=>re(t).test(e),je=async e=>{const t=J(e),s=l.join(e,"salty.config.ts"),n=l.join(t,"salty.config.js"),i=await te(e),o=ne(e);await X.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:i,external:o});const f=Date.now(),{config:h}=await import(`${n}?t=${f}`);return h},we=async e=>{const t=await je(e),s=new Set,n=(y,m=[])=>y?Object.entries(y).flatMap(([C,b])=>{if(!b)return;if(typeof b=="object")return n(b,[...m,C]);const M=se(C),A=E(C),V=[...m,M].join(".");s.add(`"${V}"`);const _=[...m.map(E),A].join("-"),{result:D}=Y(b);return`--${_}: ${D};`}):[],i=y=>y?Object.entries(y).flatMap(([m,C])=>{const b=n(C);return m==="base"?b.join(""):`${m} { ${b.join("")} }`}):[],o=y=>y?Object.entries(y).flatMap(([m,C])=>Object.entries(C).flatMap(([b,M])=>{const A=n(M,[m]),V=`.${m}-${b}, [data-${m}="${b}"]`,_=A.join("");return`${V} { ${_} }`})):[],f=n(t.variables),h=i(t.responsiveVariables),a=o(t.conditionalVariables),r=J(e),S=l.join(r,"css/_variables.css"),F=`:root { ${f.join("")} ${h.join("")} } ${a.join("")}`;u.writeFileSync(S,F);const j=l.join(r,"css/_global.css"),g=O(t.global,"");u.writeFileSync(j,`@layer global { ${g} }`);const k=l.join(r,"css/_reset.css"),p=t.reset==="none"?{}:typeof t.reset=="object"?t.reset:be,$=O(p,"");u.writeFileSync(k,`@layer reset { ${$} }`);const c=l.join(r,"css/_templates.css"),d=Q(t.templates),x=he(t.templates);u.writeFileSync(c,d);const w=l.join(r,"types/css-tokens.d.ts"),N=`
9
+ // Variable types
10
+ type VariableTokens = ${[...s].join("|")};
11
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
12
+
13
+ // Template types
14
+ type TemplateTokens = {
15
+ ${Object.entries(x).map(([y,m])=>`${y}?: ${m}`).join(`
16
+ `)}
17
+ }
18
+ `;u.writeFileSync(w,N)},L=async(e,t,s)=>{const n=q(t),i=l.join(s,"./temp");u.existsSync(i)||u.mkdirSync(i);const o=l.parse(t);let f=u.readFileSync(t,"utf8");f=f.replace(/styled\(([^"'`{,]+),/g,(j,g)=>{if(/^['"`]/.test(g))return j;const P=new RegExp(`import[^;]*${g}[,\\s{][^;]*from\\s?([^{};]+);`),p=P.test(f);if(p||console.log("Not imported",g),!p)return j;const $=P.exec(f);if($){const c=$.at(1),d=oe.some(x=>c==null?void 0:c.includes(x));if(d&&console.log("Salty import",g,$.at(0)),d)return j}return console.log("Replacing",g),"styled('div',"});const h=l.join(s,"js",n+".js"),a=ne(e),r=await te(e);await X.build({stdin:{contents:f,sourcefile:o.base,resolveDir:o.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:h,format:r,target:["node20"],keepNames:!0,external:a,packages:"external"});const S=Date.now();return await import(`${h}?t=${S}`)},B=async e=>{const t=J(e),s=l.join(t,"salty.config.js"),n=Date.now(),{config:i}=await import(`${s}?t=${n}`);return i},ie=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Fe=async(e,t=ie())=>{try{const s=Date.now();t?Z.info("Generating CSS in production mode! 🔥"):Z.info("Generating CSS in development mode! 🚀");const n=[],i=[],o=J(e),f=l.join(o,"index.css");(()=>{u.existsSync(o)&&pe.execSync("rm -rf "+o),u.mkdirSync(o),u.mkdirSync(l.join(o,"css")),u.mkdirSync(l.join(o,"types"))})(),await we(e);const a=await B(e);async function r(c,d){const x=["node_modules","saltygen"],w=u.statSync(c);if(w.isDirectory()){const T=u.readdirSync(c);if(x.some(y=>c.includes(y)))return;await Promise.all(T.map(y=>r(l.join(c,y),l.join(d,y))))}else if(w.isFile()&&H(c)){const N=await L(e,c,o),y=[];Object.entries(N).forEach(([V,_])=>{if(_.isKeyframes&&_.css){const K=`a_${_.animationName}.css`,le=`css/${K}`,fe=l.join(o,le);n.push(K),u.writeFileSync(fe,_.css);return}if(!_.generator)return;const D=_.generator._withBuildContext({name:V,config:a,prod:t});i[D.priority]||(i[D.priority]=[]),i[D.priority].push(D.cssFileName),y.push(D.cssFileName);const ce=`css/${D.cssFileName}`,ae=l.join(o,ce);u.writeFileSync(ae,D.css)});const m=y.map(V=>`@import url('./${V}');`).join(`
19
+ `),C=q(c,6),b=l.parse(c),M=E(b.name),A=l.join(o,`css/f_${M}-${C}.css`);u.writeFileSync(A,m)}}await r(e,o);const S=n.map(c=>`@import url('./css/${c}');`).join(`
20
+ `);let k=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
21
+
22
+ ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(c=>{try{return u.readFileSync(l.join(o,"css",c),"utf8").length>0}catch{return!1}}).map(c=>`@import url('./css/${c}');`).join(`
23
+ `)}
24
+ ${S}`;if(a.importStrategy!=="component"){const c=i.reduce((d,x,w)=>{const T=x.reduce((C,b)=>{const M=u.readFileSync(l.join(o,"css",b),"utf8");return`${C}
25
+ ${M}`},""),N=`l_${w}.css`,y=l.join(o,"css",N),m=`@layer l${w} { ${T} }`;return u.writeFileSync(y,m),`${d}
26
+ @import url('./css/${N}');`},"");k+=c}u.writeFileSync(f,k);const p=Date.now()-s,$=p<200?"🔥":p<500?"🚀":p<1e3?"🎉":p<2e3?"🚗":p<5e3?"🤔":"🥴";Z.info(`Generated CSS in ${p}ms! ${$}`)}catch(s){console.error(s)}},xe=async(e,t)=>{try{const s=[],n=l.join(e,"./saltygen"),i=l.join(n,"index.css");if(H(t)){const f=await B(e),h=await L(e,t,n);Object.entries(h).forEach(([j,g])=>{if(g.isKeyframes&&g.css){const c=`css/${`a_${g.animationName}.css`}`,d=l.join(n,c);u.writeFileSync(d,g.css);return}if(!g.generator)return;const k=g.generator._withBuildContext({name:j,config:f}),P=`css/${k.cssFileName}`,p=l.join(n,P);s.push(k.cssFileName),u.writeFileSync(p,k.css)});const a=u.readFileSync(i,"utf8").split(`
27
+ `),r=s.map(j=>`@import url('../saltygen/css/${j}');`),F=[...new Set([...a,...r])].join(`
28
+ `);u.writeFileSync(i,F)}}catch(s){console.error(s)}},Ce=async(e,t,s=ie())=>{try{const n=l.join(e,"./saltygen");if(H(t)){const o=u.readFileSync(t,"utf8");o.replace(/^(?!export\s)const\s.*/gm,S=>`export ${S}`)!==o&&await U.writeFile(t,o);const h=await B(e),a=await L(e,t,n);let r=o;if(Object.entries(a).forEach(([S,F])=>{var C;if(F.isKeyframes||!F.generator)return;const j=F.generator._withBuildContext({name:S,config:h,prod:s}),g=new RegExp(`\\s${S}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(o);if(!g)return console.error("Could not find the original declaration");const k=(C=g.at(1))==null?void 0:C.trim(),P=new RegExp(`\\s${S}[=\\s]+styled\\(`,"g").exec(r);if(!P)return console.error("Could not find the original declaration");const{index:p}=P;let $=!1;const c=setTimeout(()=>$=!0,5e3);let d=0,x=!1,w=0;for(;!x&&!$;){const b=r[p+d];b==="("&&w++,b===")"&&w--,w===0&&b===")"&&(x=!0),d>r.length&&($=!0),d++}if(!$)clearTimeout(c);else throw new Error("Failed to find the end of the styled call and timed out");const T=p+d,N=r.slice(p,T),y=r,m=` ${S} = styled(${k}, "${j.classNames}", ${JSON.stringify(j.props)});`;r=r.replace(N,m),y===r&&console.error("Minimize file failed to change content",{name:S,tagName:k})}),h.importStrategy==="component"){const S=q(t,6),F=l.parse(t);r=`import '../../saltygen/css/${`f_${E(F.name)}-${S}.css`}';
29
+ ${r}`}return 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=Fe;exports.generateFile=xe;exports.minimizeFile=Ce;exports.saltyFileRegExp=re;
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-DyEDMxfI.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-Cld5pSWN.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-esCBzNKC.js";
2
+ import { s as u, g as i } from "./index-CZ0pA4e_.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-DyEDMxfI.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-Cld5pSWN.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-esCBzNKC.js";
1
+ import { a as e, m as i } from "./index-CZ0pA4e_.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.138",
3
+ "version": "0.0.1-alpha.139",
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.138",
37
+ "@salty-css/core": "^0.0.1-alpha.139",
38
38
  "webpack": ">=5.x"
39
39
  }
40
40
  }
@@ -1,29 +0,0 @@
1
- "use strict";const ue=require("esbuild"),pe=require("child_process"),l=require("path"),u=require("fs"),U=require("fs/promises"),z=require("winston");var W=typeof document<"u"?document.currentScript:null;function de(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 X=de(ue),G=e=>String.fromCharCode(e+(e>25?39:97)),ye=(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},ge=(e,t)=>{let s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return e},q=(e,t=5)=>{const s=ge(5381,JSON.stringify(e))>>>0;return ye(s,t)};function E(e){return e?typeof e!="string"?E(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 me=(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:o}=n;e=e.replace(i,f=>{const{value:m,css:a}=o(f);return a&&s.push(a),m})}),{result:e,additionalCss:s}},Y=e=>typeof e!="string"?{result:e}:/\{[^{}]+\}/g.test(e)?{result:e.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${E(n[1].replaceAll(".","-"))})`)}:{result:e},O=(e,t,s)=>{if(!e)return"";const n=[],i=Object.entries(e).reduce((f,[m,a])=>{const r=m.trim();if(typeof a=="function"&&(a=a()),typeof a=="object"){if(!a)return f;if(r==="variants")return Object.entries(a).forEach(([c,y])=>{y&&Object.entries(y).forEach(([x,w])=>{if(!w)return;const T=`${t}.${c}-${x}`,P=O(w,T);n.push(P)})}),f;if(r==="defaultVariants")return f;if(r==="compoundVariants")return a.forEach(c=>{const{css:y,...x}=c,w=Object.entries(x).reduce((P,[p,g])=>`${P}.${p}-${g}`,t),T=O(y,w);n.push(T)}),f;if(r.startsWith("@")){const c=O(a,t),y=`${r} {
2
- ${c.replace(`
3
- `,`
4
- `)}
5
- }`;return n.push(y),f}const d=m.includes("&")?r.replace("&",t):r.startsWith(":")?`${t}${r}`:`${t} ${r}`,S=O(a,d);return n.push(S),f}const h=r.startsWith("-")?r:E(r),F=(d,S=";")=>f=`${f}${d}${S}`,j=d=>F(`${h}:${d}`);if(typeof a=="number")return j(a);if(typeof a!="string")if("toString"in a)a=a.toString();else return f;const{modifiers:$}={},N=function*(){yield Y(a),yield me(a,$)}();for(const{result:d,additionalCss:S=[]}of N)a=d,S.forEach(c=>{const y=O(c,"");F(y,"")});return j(a)},"");return i?t?[`${t} { ${i} }`,...n].join(`
6
- `):i:n.join(`
7
- `)},Q=(e,t=[])=>{if(!e)return"";const s=[],n={};if(Object.entries(e).forEach(([i,o])=>{if(typeof o=="object"){if(!o)return;const f=i.trim(),m=Q(o,[...t,f]);s.push(m)}else n[i]=o}),Object.keys(n).length){const i=t.map(E).join("-"),o=O(n,`.${i}`);s.push(o)}return s.join(`
8
- `)},he=e=>Object.entries(e).reduce((t,[s,n])=>(typeof n=="object"&&(t[s]=v(n).map(i=>`"${i}"`).join(" | ")),t),{}),v=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,i])=>{const o=t?`${t}.${n}`:n;return typeof i=="object"?v(i,o,s):s.add(t)}),[...s]):[],ee=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=l.join(e,"package.json");return u.existsSync(t)?t:ee(l.join(e,".."))},$e=async e=>{const t=ee(e);return await U.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Se=async e=>{const t=await $e(e);if(t)return t.type};let R;const te=async e=>{if(R)return R;const t=await Se(e);return t==="module"?R="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:W&&W.tagName.toUpperCase()==="SCRIPT"&&W.src||new URL("index-DyEDMxfI.cjs",document.baseURI).href).endsWith(".cjs"))&&(R="cjs"),R||"esm"},I=z.createLogger({level:"debug",format:z.format.combine(z.format.colorize(),z.format.cli()),transports:[new z.transports.Console({})]});function se(e){return e?typeof e!="string"?se(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 be={"*, *::before, *::after":{boxSizing:"border-box"},"*":{margin:0},html:{lineHeight:1.15,textSizeAdjust:"100%",WebkitFontSmoothing:"antialiased"},"img, picture, video, canvas, svg":{display:"block",maxWidth:"100%"},"p, h1, h2, h3, h4, h5, h6":{overflowWrap:"break-word"},p:{textWrap:"pretty"},"h1, h2, h3, h4, h5, h6":{textWrap:"balance"},a:{color:"currentColor"},button:{lineHeight:"1em",color:"currentColor"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},Z={externalModules:[]},ne=e=>{if(Z.externalModules.length>0)return Z.externalModules;const t=l.join(e,"salty.config.ts"),n=u.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!n)return[];const i=n[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return Z.externalModules=i,i},J=e=>l.join(e,"./saltygen"),oe=["salty","css","styles","styled"],re=(e=[])=>new RegExp(`\\.(${[...oe,...e].join("|")})\\.`),H=(e,t=[])=>re(t).test(e),je=async e=>{const t=J(e),s=l.join(e,"salty.config.ts"),n=l.join(t,"salty.config.js"),i=await te(e),o=ne(e);await X.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:i,external:o});const f=Date.now(),{config:m}=await import(`${n}?t=${f}`);return m},we=async e=>{const t=await je(e),s=new Set,n=(p,g=[])=>p?Object.entries(p).flatMap(([C,b])=>{if(!b)return;if(typeof b=="object")return n(b,[...g,C]);const M=se(C),A=E(C),V=[...g,M].join(".");s.add(`"${V}"`);const _=[...g.map(E),A].join("-"),{result:D}=Y(b);return`--${_}: ${D};`}):[],i=p=>p?Object.entries(p).flatMap(([g,C])=>{const b=n(C);return g==="base"?b.join(""):`${g} { ${b.join("")} }`}):[],o=p=>p?Object.entries(p).flatMap(([g,C])=>Object.entries(C).flatMap(([b,M])=>{const A=n(M,[g]),V=`.${g}-${b}, [data-${g}="${b}"]`,_=A.join("");return`${V} { ${_} }`})):[],f=n(t.variables),m=i(t.responsiveVariables),a=o(t.conditionalVariables),r=J(e),h=l.join(r,"css/_variables.css"),F=`:root { ${f.join("")} ${m.join("")} } ${a.join("")}`;u.writeFileSync(h,F);const j=l.join(r,"css/_global.css"),$=O(t.global,"");u.writeFileSync(j,`@layer global { ${$} }`);const k=l.join(r,"css/_reset.css"),d=t.reset==="none"?{}:typeof t.reset=="object"?t.reset:be,S=O(d,"");u.writeFileSync(k,`@layer reset { ${S} }`);const c=l.join(r,"css/_templates.css"),y=Q(t.templates),x=he(t.templates);u.writeFileSync(c,y);const w=l.join(r,"types/css-tokens.d.ts"),P=`
9
- // Variable types
10
- type VariableTokens = ${[...s].join("|")};
11
- type PropertyValueToken = \`{\${VariableTokens}}\`;
12
-
13
- // Template types
14
- type TemplateTokens = {
15
- ${Object.entries(x).map(([p,g])=>`${p}?: ${g}`).join(`
16
- `)}
17
- }
18
- `;u.writeFileSync(w,P)},L=async(e,t,s)=>{const n=q(t),i=l.join(s,"./temp");u.existsSync(i)||u.mkdirSync(i);const o=l.parse(t);let f=u.readFileSync(t,"utf8");f=f.replace(/styled\(([^"'`{,]+),/g,(j,$)=>{if(/^['"`]/.test($))return j;const N=new RegExp(`import[^;]*${$}[,\\s{][^;]*from\\s?([^{};]+);`);if(!N.test(f))return j;const S=N.exec(f);if(S){const c=S.at(1);if(oe.some(x=>c==null?void 0:c.includes(x)))return j}return"styled('div',"});const m=l.join(s,"js",n+".js"),a=ne(e),r=await te(e);await X.build({stdin:{contents:f,sourcefile:o.base,resolveDir:o.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:m,format:r,target:["node20"],keepNames:!0,external:a,packages:"external"});const h=Date.now();return await import(`${m}?t=${h}`)},B=async e=>{const t=J(e),s=l.join(t,"salty.config.js"),n=Date.now(),{config:i}=await import(`${s}?t=${n}`);return i},ie=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Fe=async(e,t=ie())=>{try{const s=Date.now();t?I.info("Generating CSS in production mode! 🔥"):I.info("Generating CSS in development mode! 🚀");const n=[],i=[],o=J(e),f=l.join(o,"index.css");(()=>{u.existsSync(o)&&pe.execSync("rm -rf "+o),u.mkdirSync(o),u.mkdirSync(l.join(o,"css")),u.mkdirSync(l.join(o,"types"))})(),await we(e);const a=await B(e);async function r(c,y){const x=["node_modules","saltygen"],w=u.statSync(c);if(w.isDirectory()){const T=u.readdirSync(c);if(x.some(p=>c.includes(p)))return;await Promise.all(T.map(p=>r(l.join(c,p),l.join(y,p))))}else if(w.isFile()&&H(c)){const P=await L(e,c,o),p=[];Object.entries(P).forEach(([V,_])=>{if(_.isKeyframes&&_.css){const K=`a_${_.animationName}.css`,le=`css/${K}`,fe=l.join(o,le);n.push(K),u.writeFileSync(fe,_.css);return}if(!_.generator)return;const D=_.generator._withBuildContext({name:V,config:a,prod:t});i[D.priority]||(i[D.priority]=[]),i[D.priority].push(D.cssFileName),p.push(D.cssFileName);const ce=`css/${D.cssFileName}`,ae=l.join(o,ce);u.writeFileSync(ae,D.css)});const g=p.map(V=>`@import url('./${V}');`).join(`
19
- `),C=q(c,6),b=l.parse(c),M=E(b.name),A=l.join(o,`css/f_${M}-${C}.css`);u.writeFileSync(A,g)}}await r(e,o);const h=n.map(c=>`@import url('./css/${c}');`).join(`
20
- `);let k=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
21
-
22
- ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(c=>{try{return u.readFileSync(l.join(o,"css",c),"utf8").length>0}catch{return!1}}).map(c=>`@import url('./css/${c}');`).join(`
23
- `)}
24
- ${h}`;if(a.importStrategy!=="component"){const c=i.reduce((y,x,w)=>{const T=x.reduce((C,b)=>{const M=u.readFileSync(l.join(o,"css",b),"utf8");return`${C}
25
- ${M}`},""),P=`l_${w}.css`,p=l.join(o,"css",P),g=`@layer l${w} { ${T} }`;return u.writeFileSync(p,g),`${y}
26
- @import url('./css/${P}');`},"");k+=c}u.writeFileSync(f,k);const d=Date.now()-s,S=d<200?"🔥":d<500?"🚀":d<1e3?"🎉":d<2e3?"🚗":d<5e3?"🤔":"🥴";I.info(`Generated CSS in ${d}ms! ${S}`)}catch(s){console.error(s)}},xe=async(e,t)=>{try{const s=[],n=l.join(e,"./saltygen"),i=l.join(n,"index.css");if(H(t)){const f=await B(e),m=await L(e,t,n);Object.entries(m).forEach(([j,$])=>{if($.isKeyframes&&$.css){const c=`css/${`a_${$.animationName}.css`}`,y=l.join(n,c);u.writeFileSync(y,$.css);return}if(!$.generator)return;const k=$.generator._withBuildContext({name:j,config:f}),N=`css/${k.cssFileName}`,d=l.join(n,N);s.push(k.cssFileName),u.writeFileSync(d,k.css)});const a=u.readFileSync(i,"utf8").split(`
27
- `),r=s.map(j=>`@import url('../saltygen/css/${j}');`),F=[...new Set([...a,...r])].join(`
28
- `);u.writeFileSync(i,F)}}catch(s){console.error(s)}},Ce=async(e,t,s=ie())=>{try{const n=l.join(e,"./saltygen");if(H(t)){const o=u.readFileSync(t,"utf8");o.replace(/^(?!export\s)const\s.*/gm,h=>`export ${h}`)!==o&&await U.writeFile(t,o);const m=await B(e),a=await L(e,t,n);let r=o;if(Object.entries(a).forEach(([h,F])=>{var C;if(F.isKeyframes||!F.generator)return;const j=F.generator._withBuildContext({name:h,config:m,prod:s}),$=new RegExp(`\\s${h}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(o);if(!$)return console.error("Could not find the original declaration");const k=(C=$.at(1))==null?void 0:C.trim(),N=new RegExp(`\\s${h}[=\\s]+styled\\(`,"g").exec(r);if(!N)return console.error("Could not find the original declaration");const{index:d}=N;let S=!1;const c=setTimeout(()=>S=!0,5e3);let y=0,x=!1,w=0;for(;!x&&!S;){const b=r[d+y];b==="("&&w++,b===")"&&w--,w===0&&b===")"&&(x=!0),y>r.length&&(S=!0),y++}if(!S)clearTimeout(c);else throw new Error("Failed to find the end of the styled call and timed out");const T=d+y,P=r.slice(d,T),p=r,g=` ${h} = styled(${k}, "${j.classNames}", ${JSON.stringify(j.props)});`;r=r.replace(P,g),p===r&&console.error("Minimize file failed to change content",{name:h,tagName:k})}),m.importStrategy==="component"){const h=q(t,6),F=l.parse(t);r=`import '../../saltygen/css/${`f_${E(F.name)}-${h}.css`}';
29
- ${r}`}return 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=Fe;exports.generateFile=xe;exports.minimizeFile=Ce;exports.saltyFileRegExp=re;