@salty-css/webpack 0.0.1-alpha.25 → 0.0.1-alpha.250

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,685 @@
1
+ var Jt = Object.defineProperty;
2
+ var Rt = (e, t, s) => t in e ? Jt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
3
+ var st = (e, t, s) => Rt(e, typeof t != "symbol" ? t + "" : t, s);
4
+ import * as Pt from "esbuild";
5
+ import { execSync as zt } from "child_process";
6
+ import { join as u, parse as ot } from "path";
7
+ import { existsSync as dt, writeFileSync as T, readFileSync as J, mkdirSync as K, statSync as Wt, readdirSync as At } from "fs";
8
+ import { readFile as Ft } from "fs/promises";
9
+ import { createLogger as Gt, format as ut, transports as Ht } from "winston";
10
+ import pt from "typescript";
11
+ const Ct = (e) => String.fromCharCode(e + (e > 25 ? 39 : 97)), It = (e, t) => {
12
+ let s = "", n;
13
+ for (n = Math.abs(e); n > 52; n = n / 52 | 0) s = Ct(n % 52) + s;
14
+ return s = Ct(n % 52) + s, s.length < t ? s = s.padStart(t, "a") : s.length > t && (s = s.slice(-t)), s;
15
+ }, Qt = (e, t) => {
16
+ let s = t.length;
17
+ for (; s; ) e = e * 33 ^ t.charCodeAt(--s);
18
+ return e;
19
+ }, H = (e, t = 5) => {
20
+ const s = Qt(5381, JSON.stringify(e)) >>> 0;
21
+ return It(s, t);
22
+ };
23
+ function R(e) {
24
+ return e ? typeof e != "string" ? R(String(e)) : e.replace(/[\s.]/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (t, s) => (s > 0 ? "-" : "") + t.toLowerCase()) : "";
25
+ }
26
+ const Kt = (e) => (t) => {
27
+ if (typeof t != "string" || !e) return;
28
+ let s = t;
29
+ const n = [];
30
+ return Object.values(e).forEach((o) => {
31
+ const { pattern: i, transform: r } = o;
32
+ s = s.replace(i, (d) => {
33
+ const { value: $, css: m } = r(d);
34
+ return m && n.push(m), $;
35
+ });
36
+ }), { transformed: s, additionalCss: n };
37
+ }, Nt = (e) => (t) => typeof t != "string" || !/\{[^{}]+\}/g.test(t) ? void 0 : { transformed: t.replace(/\{([^{}]+)\}/g, (...o) => `var(--${R(o[1].replaceAll(".", "-"))})`) }, Lt = Nt(), Bt = [
38
+ "top",
39
+ "right",
40
+ "bottom",
41
+ "left",
42
+ "min-width",
43
+ /.*width.*/,
44
+ /^[^line]*height.*/,
45
+ // Exclude line-height
46
+ /padding.*/,
47
+ /margin.*/,
48
+ /border.*/,
49
+ /inset.*/,
50
+ /.*radius.*/,
51
+ /.*spacing.*/,
52
+ /.*gap.*/,
53
+ /.*indent.*/,
54
+ /.*offset.*/,
55
+ /.*size.*/,
56
+ /.*thickness.*/,
57
+ /.*font-size.*/
58
+ ], Zt = (e, t, s) => Bt.some((o) => typeof o == "string" ? o === e : o.test(e)) ? `${t}px` : `${t}`, qt = ["Webkit", "Moz", "ms", "O"], Ut = (e) => e.startsWith("-") ? e : qt.some((t) => e.startsWith(t)) ? `-${R(e)}` : R(e), nt = async (e, t = "", s, n = !1) => {
59
+ if (!e) throw new Error("No styles provided to parseStyles function!");
60
+ const o = /* @__PURE__ */ new Set(), i = Object.entries(e), r = async ([p, f]) => {
61
+ const g = p.trim(), P = Ut(g), _ = (k, W = ";") => `${P}:${k}${W}`, V = { scope: t, config: s };
62
+ if (typeof f == "function") return r([p, f(V)]);
63
+ if (f instanceof Promise) return r([p, await f]);
64
+ if (typeof f == "object") {
65
+ if (!f) return;
66
+ if (f.isColor) return _(f.toString());
67
+ if (g === "defaultVariants") return;
68
+ if (g === "variants") {
69
+ const F = Object.entries(f);
70
+ for (const [M, l] of F) {
71
+ if (!l) continue;
72
+ const w = Object.entries(l);
73
+ for (const [C, a] of w) {
74
+ if (!a) continue;
75
+ const j = `${t}.${M}-${C}`;
76
+ (await nt(a, j, s)).forEach((v) => o.add(v));
77
+ }
78
+ }
79
+ return;
80
+ }
81
+ if (g === "compoundVariants") {
82
+ for (const F of f) {
83
+ const { css: M, ...l } = F, w = Object.entries(l).reduce((a, [j, N]) => `${a}.${j}-${N}`, t);
84
+ (await nt(M, w, s)).forEach((a) => o.add(a));
85
+ }
86
+ return;
87
+ }
88
+ if (g.startsWith("@")) {
89
+ const F = g, M = await Y(f, t, s), l = `${F} { ${M} }`;
90
+ o.add(l);
91
+ return;
92
+ }
93
+ const k = p.includes("&") ? g.replace("&", t) : g.startsWith(":") ? `${t}${g}` : `${t} ${g}`;
94
+ (await nt(f, k, s)).forEach((F) => o.add(F));
95
+ return;
96
+ }
97
+ if (typeof f == "number") {
98
+ const k = Zt(P, f);
99
+ return _(k);
100
+ }
101
+ if (typeof f != "string")
102
+ if ("toString" in f) f = f.toString();
103
+ else throw new Error(`Invalid value type for property ${P}`);
104
+ return _(f);
105
+ }, d = i.map(r), { modifiers: $ } = {}, m = [Nt(), Kt($)], y = (await Promise.all(d).then((p) => Promise.all(
106
+ p.map((f) => m.reduce(async (g, P) => {
107
+ const _ = await g;
108
+ if (!_) return _;
109
+ const V = await P(_);
110
+ if (!V) return _;
111
+ const { transformed: k, additionalCss: W } = V;
112
+ let F = "";
113
+ if (W)
114
+ for (const M of W)
115
+ F += await Y(M, "");
116
+ return `${F}${k}`;
117
+ }, Promise.resolve(f)))
118
+ ))).filter((p) => p !== void 0).join(`
119
+ `);
120
+ if (!y.trim()) return Array.from(o);
121
+ const h = t ? `${t} {
122
+ ${y}
123
+ }` : y;
124
+ return o.has(h) ? Array.from(o) : [h, ...o];
125
+ }, Y = async (e, t, s, n = !1) => (await nt(e, t, s, n)).join(`
126
+ `), xt = async (e, t = []) => {
127
+ if (!e) return "";
128
+ const s = [], n = {};
129
+ for (const [o, i] of Object.entries(e))
130
+ if (typeof i != "function") if (i && typeof i == "object") {
131
+ const r = o.trim(), d = await xt(i, [...t, r]);
132
+ s.push(d);
133
+ } else
134
+ n[o] = i;
135
+ if (Object.keys(n).length) {
136
+ const o = t.map(R).join("-"), i = "t_" + H(o, 4), r = await Y(n, `.${o}, .${i}`);
137
+ s.push(r);
138
+ }
139
+ return s.join(`
140
+ `);
141
+ }, Xt = (e) => e ? Object.entries(e).reduce((t, [s, n]) => (typeof n == "function" ? t[s] = "any" : typeof n == "object" && (t[s] = _t(n).map((o) => `"${o}"`).join(" | ")), t), {}) : {}, _t = (e, t = "", s = /* @__PURE__ */ new Set()) => e ? (Object.entries(e).forEach(([n, o]) => {
142
+ const i = t ? `${t}.${n}` : n;
143
+ return typeof o == "object" ? _t(o, i, s) : s.add(t);
144
+ }), [...s]) : [], Tt = (e) => {
145
+ if (!e || e === "/") throw new Error("Could not find package.json file");
146
+ const t = u(e, "package.json");
147
+ return dt(t) ? t : Tt(u(e, ".."));
148
+ }, Yt = async (e) => {
149
+ const t = Tt(e);
150
+ return await Ft(t, "utf-8").then(JSON.parse).catch(() => {
151
+ });
152
+ }, te = async (e) => {
153
+ const t = await Yt(e);
154
+ if (t)
155
+ return t.type;
156
+ };
157
+ let Q;
158
+ const Dt = async (e) => {
159
+ if (Q) return Q;
160
+ const t = await te(e);
161
+ return t === "module" ? Q = "esm" : (t === "commonjs" || import.meta.url.endsWith(".cjs")) && (Q = "cjs"), Q || "esm";
162
+ }, mt = Gt({
163
+ level: "debug",
164
+ format: ut.combine(ut.colorize(), ut.cli()),
165
+ transports: [new Ht.Console({})]
166
+ });
167
+ function kt(e) {
168
+ return e ? typeof e != "string" ? kt(String(e)) : e.replace(/[^\d\w]/g, ".") : "";
169
+ }
170
+ const ee = {
171
+ /** Set box model to border-box */
172
+ "*, *::before, *::after": {
173
+ boxSizing: "border-box"
174
+ },
175
+ /** Remove default margin and padding */
176
+ "*": {
177
+ margin: 0
178
+ },
179
+ /** Remove adjust font properties */
180
+ html: {
181
+ lineHeight: 1.15,
182
+ textSizeAdjust: "100%",
183
+ WebkitFontSmoothing: "antialiased"
184
+ },
185
+ /** Make media elements responsive */
186
+ "img, picture, video, canvas, svg": {
187
+ display: "block",
188
+ maxWidth: "100%"
189
+ },
190
+ /** Avoid overflow of text */
191
+ "p, h1, h2, h3, h4, h5, h6": {
192
+ overflowWrap: "break-word"
193
+ },
194
+ /** Improve text wrapping */
195
+ p: {
196
+ textWrap: "pretty"
197
+ },
198
+ "h1, h2, h3, h4, h5, h6": {
199
+ textWrap: "balance"
200
+ },
201
+ /** Improve link color */
202
+ a: {
203
+ color: "currentColor"
204
+ },
205
+ /** Improve button line height */
206
+ button: {
207
+ lineHeight: "1em",
208
+ color: "currentColor"
209
+ },
210
+ /** Improve form elements */
211
+ "input, optgroup, select, textarea": {
212
+ fontFamily: "inherit",
213
+ fontSize: "100%",
214
+ lineHeight: "1.15em"
215
+ }
216
+ }, L = (...e) => e.flat().reduce((t, s) => s != null && s._current ? { ...t, ...s._current } : { ...t, ...s }, {}), se = (...e) => e.flat().reduce((t, s) => ({ ...t, ...s._children }), {});
217
+ class ne {
218
+ constructor(t) {
219
+ st(this, "_path");
220
+ this.params = t;
221
+ }
222
+ get _current() {
223
+ return this.params.template;
224
+ }
225
+ get isDefineTemplate() {
226
+ return !0;
227
+ }
228
+ _setPath(t) {
229
+ return this._path = t, this;
230
+ }
231
+ }
232
+ class oe {
233
+ constructor(t) {
234
+ st(this, "_path");
235
+ st(this, "templates", []);
236
+ this.params = t, Object.entries(t).forEach(([s, n]) => {
237
+ this.templates.push(
238
+ new ne({
239
+ name: s,
240
+ template: n
241
+ })
242
+ );
243
+ });
244
+ }
245
+ get _current() {
246
+ return this.params;
247
+ }
248
+ get _children() {
249
+ return Object.fromEntries(
250
+ this.templates.map((t) => [t.params.name, t])
251
+ );
252
+ }
253
+ get isDefineTemplates() {
254
+ return !0;
255
+ }
256
+ _setPath(t) {
257
+ return this._path = t, this.templates.forEach((s) => s._setPath(t)), this;
258
+ }
259
+ }
260
+ const re = (e) => new oe(e), ie = (e, t) => new Promise((s, n) => {
261
+ const o = setTimeout(() => {
262
+ n(new Error("Timeout"));
263
+ }, 100), i = pt.createSourceFile("temp.ts", e, pt.ScriptTarget.Latest, !0);
264
+ function r(d) {
265
+ if (pt.isVariableDeclaration(d) && d.name.getText() === t) {
266
+ const $ = d.getStart(), m = d.getEnd();
267
+ clearTimeout(o), s([$, m]);
268
+ }
269
+ d.forEachChild(r);
270
+ }
271
+ r(i);
272
+ }), z = {
273
+ externalModules: [],
274
+ rcFile: void 0,
275
+ destDir: void 0
276
+ }, Et = (e) => {
277
+ if (z.externalModules.length > 0) return z.externalModules;
278
+ const s = J(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
279
+ if (!s) return [];
280
+ const n = s[1].split(",").map((o) => o.replace(/['"`]/g, "").trim());
281
+ return z.externalModules = n, n;
282
+ }, I = async (e) => {
283
+ if (z.destDir) return z.destDir;
284
+ const t = await yt(e), s = u(e, (t == null ? void 0 : t.saltygenDir) || "saltygen");
285
+ return z.destDir = s, s;
286
+ }, Ot = ["salty", "css", "styles", "styled"], ae = (e = []) => new RegExp(`\\.(${[...Ot, ...e].join("|")})\\.`), ht = (e, t = []) => ae(t).test(e), Vt = async (e) => {
287
+ if (z.rcFile) return z.rcFile;
288
+ if (e === "/") throw new Error("Could not find .saltyrc.json file");
289
+ const t = u(e, ".saltyrc.json"), s = await Ft(t, "utf-8").then(JSON.parse).catch(() => {
290
+ });
291
+ return s ? (z.rcFile = s, s) : Vt(u(e, ".."));
292
+ }, yt = async (e) => {
293
+ var n, o;
294
+ const t = await Vt(e), s = (n = t.projects) == null ? void 0 : n.find((i) => e.endsWith(i.dir || ""));
295
+ return s || ((o = t.projects) == null ? void 0 : o.find((i) => i.dir === t.defaultProject));
296
+ }, ce = async (e) => {
297
+ const t = await yt(e), s = await I(e), n = u(e, (t == null ? void 0 : t.configDir) || "", "salty.config.ts"), o = u(s, "salty.config.js"), i = await Dt(e), r = Et(n);
298
+ await Pt.build({
299
+ entryPoints: [n],
300
+ minify: !0,
301
+ treeShaking: !0,
302
+ bundle: !0,
303
+ outfile: o,
304
+ format: i,
305
+ external: r
306
+ });
307
+ const d = Date.now(), { config: $ } = await import(`${o}?t=${d}`);
308
+ return { config: $, path: o };
309
+ }, le = async (e, t) => {
310
+ var wt, bt;
311
+ const s = await I(e), n = {
312
+ mediaQueries: [],
313
+ globalStyles: [],
314
+ variables: [],
315
+ templates: []
316
+ };
317
+ await Promise.all(
318
+ [...t].map(async (S) => {
319
+ const { contents: x, outputFilePath: U } = await rt(e, S, s);
320
+ Object.entries(x).forEach(([E, D]) => {
321
+ D.isMedia ? n.mediaQueries.push([E, D]) : D.isGlobalDefine ? n.globalStyles.push(D) : D.isDefineVariables ? n.variables.push(D) : D.isDefineTemplates && n.templates.push(D._setPath(`${E};;${U}`));
322
+ });
323
+ })
324
+ );
325
+ const { config: o, path: i } = await ce(e), r = { ...o }, { mediaQueries: d } = n;
326
+ r.mediaQueries = Object.fromEntries(d.map(([S, x]) => [`@${S}`, x]));
327
+ const $ = d.map(([S]) => `'@${S}'`).join(" | "), m = /* @__PURE__ */ new Set(), c = async (S, x = []) => {
328
+ if (!S) return [];
329
+ const U = Object.entries(S).map(async ([D, G]) => {
330
+ const X = async (O) => {
331
+ if (!O) return;
332
+ if (O instanceof Promise) return await X(await O);
333
+ if (typeof O == "function") return await X(await O());
334
+ if (typeof O == "object") return await c(O, [...x, D]);
335
+ const ct = kt(D), lt = R(D), ft = [...x, ct].join(".");
336
+ m.add(`"${ft}"`);
337
+ const et = [...x.map(R), lt].join("-"), St = Lt(O);
338
+ return St ? `--${et}: ${St.transformed};` : `--${et}: ${O};`;
339
+ };
340
+ return await X(G);
341
+ });
342
+ return (await Promise.all(U)).flat();
343
+ }, y = async (S) => {
344
+ if (!S) return [];
345
+ const x = Object.entries(S).map(async ([E, D]) => {
346
+ const G = await c(D);
347
+ return E === "base" ? G.join("") : r.mediaQueries[E] ? `${r.mediaQueries[E]} { ${G.join("")} }` : `${E} { ${G.join("")} }`;
348
+ });
349
+ return (await Promise.all(x)).flat();
350
+ }, h = async (S) => {
351
+ if (!S) return [];
352
+ const x = Object.entries(S).map(async ([E, D]) => {
353
+ const G = Object.entries(D).map(async ([O, ct]) => {
354
+ const lt = await c(ct, [E]), ft = `.${E}-${O}, [data-${E}="${O}"]`, et = lt.join("");
355
+ return `${ft} { ${et} }`;
356
+ });
357
+ return (await Promise.all(G)).flat();
358
+ });
359
+ return (await Promise.all(x)).flat();
360
+ }, b = (S) => ({ ...S, responsive: void 0, conditional: void 0 }), p = (S) => n.variables.map((x) => S === "static" ? b(x._current) : x._current[S]), f = L(b(o.variables), p("static")), g = await c(f), P = L((wt = o.variables) == null ? void 0 : wt.responsive, p("responsive")), _ = await y(P), V = L((bt = o.variables) == null ? void 0 : bt.conditional, p("conditional")), k = await h(V), W = u(s, "css/_variables.css"), F = `:root { ${g.join("")} ${_.join("")} } ${k.join("")}`;
361
+ T(W, F), r.staticVariables = f;
362
+ const M = u(s, "css/_global.css"), l = L(o.global, n.globalStyles), w = await Y(l, "");
363
+ T(M, `@layer global { ${w} }`);
364
+ const C = u(s, "css/_reset.css"), j = o.reset === "none" ? {} : typeof o.reset == "object" ? o.reset : ee, N = await Y(j, "");
365
+ T(C, `@layer reset { ${N} }`);
366
+ const v = u(s, "css/_templates.css"), A = L(o.templates, n.templates), B = await xt(A), Z = Xt(A);
367
+ T(v, `@layer templates { ${B} }`), r.templates = A;
368
+ const tt = o.templates ? [re(o.templates)._setPath(`config;;${i}`)] : [], it = se(n.templates, tt);
369
+ r.templatePaths = Object.fromEntries(Object.entries(it).map(([S, x]) => [S, x._path]));
370
+ const q = u(s, "types/css-tokens.d.ts"), Mt = `
371
+ // Variable types
372
+ type VariableTokens = ${[...m].join("|")};
373
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
374
+
375
+ // Template types
376
+ type TemplateTokens = {
377
+ ${Object.entries(Z).map(([S, x]) => `${S}?: ${x}`).join(`
378
+ `)}
379
+ }
380
+
381
+ // Media query types
382
+ type MediaQueryKeys = ${$ || "''"};
383
+ `;
384
+ T(q, Mt);
385
+ const vt = u(s, "cache/config-cache.json");
386
+ T(vt, JSON.stringify(r, null, 2));
387
+ }, jt = (e) => e.replace(/styled\(([^"'`{,]+),/g, (t, s) => {
388
+ if (/^['"`]/.test(s)) return t;
389
+ const o = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
390
+ if (!o.test(e)) return t;
391
+ const r = o.exec(e);
392
+ if (r) {
393
+ const d = r.at(1);
394
+ if (Ot.some((m) => d == null ? void 0 : d.includes(m))) return t;
395
+ }
396
+ return "styled('div',";
397
+ }), fe = (e, t) => {
398
+ try {
399
+ const s = J(u(t, "saltygen/cache/config-cache.json"), "utf8");
400
+ return s ? `globalThis.saltyConfig = ${s};
401
+
402
+ ${e}` : `globalThis.saltyConfig = {};
403
+
404
+ ${e}`;
405
+ } catch {
406
+ return e;
407
+ }
408
+ }, rt = async (e, t, s) => {
409
+ const n = H(t), o = u(s, "./temp");
410
+ dt(o) || K(o);
411
+ const i = ot(t);
412
+ let r = J(t, "utf8");
413
+ r = jt(r), r = fe(r, e);
414
+ const d = u(s, "js", n + ".js"), $ = await yt(e), m = u(e, ($ == null ? void 0 : $.configDir) || "", "salty.config.ts"), c = Et(m), y = await Dt(e);
415
+ await Pt.build({
416
+ stdin: {
417
+ contents: r,
418
+ sourcefile: i.base,
419
+ resolveDir: i.dir,
420
+ loader: "tsx"
421
+ },
422
+ minify: !1,
423
+ treeShaking: !0,
424
+ bundle: !0,
425
+ outfile: d,
426
+ format: y,
427
+ target: ["node20"],
428
+ keepNames: !0,
429
+ external: c,
430
+ packages: "external",
431
+ plugins: [
432
+ {
433
+ name: "test",
434
+ setup: (p) => {
435
+ p.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (f) => {
436
+ const g = J(f.path, "utf8");
437
+ return { contents: jt(g), loader: "ts" };
438
+ });
439
+ }
440
+ }
441
+ ]
442
+ });
443
+ const h = Date.now();
444
+ return { contents: await import(`${d}?t=${h}`), outputFilePath: d };
445
+ }, ue = async (e) => {
446
+ const t = await I(e), s = u(t, "cache/config-cache.json"), n = J(s, "utf8");
447
+ if (!n) throw new Error("Could not find config cache file");
448
+ return JSON.parse(n);
449
+ }, gt = async (e) => {
450
+ const t = await ue(e), s = await I(e), n = u(s, "salty.config.js"), o = Date.now(), { config: i } = await import(`${n}?t=${o}`);
451
+ return L(i, t);
452
+ }, $t = () => {
453
+ try {
454
+ return process.env.NODE_ENV === "production";
455
+ } catch {
456
+ return !1;
457
+ }
458
+ }, we = async (e, t = $t(), s = !0) => {
459
+ try {
460
+ const n = Date.now();
461
+ t ? mt.info("Generating CSS in production mode! 🔥") : mt.info("Generating CSS in development mode! 🚀");
462
+ const o = [], i = [], r = await I(e), d = u(r, "index.css");
463
+ s && (() => {
464
+ dt(r) && zt("rm -rf " + r), K(r, { recursive: !0 }), K(u(r, "css")), K(u(r, "types")), K(u(r, "js")), K(u(r, "cache"));
465
+ })();
466
+ const m = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set();
467
+ async function y(l) {
468
+ const w = ["node_modules", "saltygen"], C = Wt(l);
469
+ if (C.isDirectory()) {
470
+ const a = At(l);
471
+ if (w.some((N) => l.includes(N))) return;
472
+ await Promise.all(a.map((N) => y(u(l, N))));
473
+ } else if (C.isFile() && ht(l)) {
474
+ m.add(l);
475
+ const j = J(l, "utf8");
476
+ /define[\w\d]+\(/.test(j) && c.add(l);
477
+ }
478
+ }
479
+ await y(e), await le(e, c);
480
+ const h = {
481
+ keyframes: [],
482
+ components: [],
483
+ classNames: []
484
+ };
485
+ await Promise.all(
486
+ [...m].map(async (l) => {
487
+ const { contents: w } = await rt(e, l, r);
488
+ for (let [C, a] of Object.entries(w))
489
+ a instanceof Promise && (a = await a), a.isKeyframes ? h.keyframes.push({
490
+ value: a,
491
+ src: l,
492
+ name: C
493
+ }) : a.isClassName ? h.classNames.push({
494
+ ...a,
495
+ src: l,
496
+ name: C
497
+ }) : a.generator && h.components.push({
498
+ ...a,
499
+ src: l,
500
+ name: C
501
+ });
502
+ })
503
+ );
504
+ const b = await gt(e);
505
+ for (const l of h.keyframes) {
506
+ const { value: w } = l, C = `a_${w.animationName}.css`, a = `css/${C}`, j = u(r, a);
507
+ o.push(C), T(j, w.css);
508
+ }
509
+ const p = {};
510
+ for (const l of h.components) {
511
+ const { src: w, name: C } = l;
512
+ p[w] || (p[w] = []);
513
+ const a = l.generator._withBuildContext({
514
+ callerName: C,
515
+ isProduction: t,
516
+ config: b
517
+ });
518
+ i[a.priority] || (i[a.priority] = []);
519
+ const j = await a.css;
520
+ if (!j) continue;
521
+ i[a.priority].push(a.cssFileName);
522
+ const N = `css/${a.cssFileName}`, v = u(r, N);
523
+ T(v, j), b.importStrategy === "component" && p[w].push(a.cssFileName);
524
+ }
525
+ for (const l of h.classNames) {
526
+ const { src: w, name: C } = l;
527
+ p[w] || (p[w] = []);
528
+ const a = l.generator._withBuildContext({
529
+ callerName: C,
530
+ isProduction: t,
531
+ config: b
532
+ }), j = await a.css;
533
+ if (!j) continue;
534
+ i[a.priority] || (i[a.priority] = []), i[a.priority].push(a.cssFileName);
535
+ const N = `css/${a.cssFileName}`, v = u(r, N);
536
+ T(v, j), b.importStrategy === "component" && p[w].push(a.cssFileName);
537
+ }
538
+ b.importStrategy === "component" && Object.entries(p).forEach(([l, w]) => {
539
+ const C = w.map((A) => `@import url('./${A}');`).join(`
540
+ `), a = H(l, 6), j = ot(l), N = R(j.name), v = u(r, `css/f_${N}-${a}.css`);
541
+ T(v, C || "/* Empty file */");
542
+ });
543
+ const f = o.map((l) => `@import url('./css/${l}');`).join(`
544
+ `);
545
+ let k = `/*!
546
+ * Generated with Salty CSS (https://salty-css.dev)
547
+ * Do not edit this file directly
548
+ */
549
+ @layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
550
+
551
+ ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) => {
552
+ try {
553
+ return J(u(r, "css", l), "utf8").length > 0;
554
+ } catch {
555
+ return !1;
556
+ }
557
+ }).map((l) => `@import url('./css/${l}');`).join(
558
+ `
559
+ `
560
+ )}
561
+ ${f}`;
562
+ if (b.importStrategy !== "component") {
563
+ const l = i.reduce((w, C, a) => {
564
+ const j = C.reduce((B, Z) => {
565
+ var at;
566
+ const tt = u(r, "css", Z), it = J(tt, "utf8"), q = ((at = /.*-([^-]+)-\d+.css/.exec(Z)) == null ? void 0 : at.at(1)) || H(tt, 6);
567
+ return B.includes(q) ? B : `${B}
568
+ /*start:${q}-${Z}*/
569
+ ${it}
570
+ /*end:${q}*/
571
+ `;
572
+ }, ""), N = `l_${a}.css`, v = u(r, "css", N), A = `@layer l${a} { ${j}
573
+ }`;
574
+ return T(v, A), `${w}
575
+ @import url('./css/${N}');`;
576
+ }, "");
577
+ k += l;
578
+ }
579
+ T(d, k);
580
+ const F = Date.now() - n, M = F < 200 ? "🔥" : F < 500 ? "🚀" : F < 1e3 ? "🎉" : F < 2e3 ? "🚗" : F < 5e3 ? "🤔" : "🥴";
581
+ mt.info(`Generated CSS in ${F}ms! ${M}`);
582
+ } catch (n) {
583
+ console.error(n);
584
+ }
585
+ }, be = async (e, t, s = $t()) => {
586
+ try {
587
+ const n = await I(e);
588
+ if (ht(t)) {
589
+ const i = [], r = await gt(e), { contents: d } = await rt(e, t, n);
590
+ for (const [$, m] of Object.entries(d)) {
591
+ if (m.isKeyframes && m.css) {
592
+ const f = `css/${`a_${m.animationName}.css`}`, g = u(n, f);
593
+ T(g, await m.css);
594
+ continue;
595
+ }
596
+ if (m.isClassName) {
597
+ const p = m.generator._withBuildContext({
598
+ callerName: $,
599
+ isProduction: s,
600
+ config: r
601
+ }), f = await p.css;
602
+ if (!f) continue;
603
+ i[p.priority] || (i[p.priority] = []), i[p.priority].push(p.cssFileName);
604
+ const g = `css/${p.cssFileName}`, P = u(n, g);
605
+ T(P, f);
606
+ continue;
607
+ }
608
+ if (!m.generator) continue;
609
+ const c = m.generator._withBuildContext({
610
+ callerName: $,
611
+ isProduction: s,
612
+ config: r
613
+ }), y = await c.css;
614
+ if (!y) continue;
615
+ const h = `css/${c.cssFileName}`, b = u(n, h);
616
+ T(b, y), i[c.priority] || (i[c.priority] = []), i[c.priority].push(c.cssFileName);
617
+ }
618
+ if (r.importStrategy !== "component")
619
+ i.forEach(($, m) => {
620
+ const c = `l_${m}.css`, y = u(n, "css", c);
621
+ let h = J(y, "utf8");
622
+ $.forEach((b) => {
623
+ var P;
624
+ const p = u(n, "css", b), f = ((P = /.*-([^-]+)-\d+.css/.exec(b)) == null ? void 0 : P.at(1)) || H(p, 6);
625
+ if (!h.includes(f)) {
626
+ const _ = J(p, "utf8"), V = `/*start:${f}-${b}*/
627
+ ${_}
628
+ /*end:${f}*/
629
+ `;
630
+ h = `${h.replace(/\}$/, "")}
631
+ ${V}
632
+ }`;
633
+ }
634
+ }), T(y, h);
635
+ });
636
+ else {
637
+ const $ = i.flat().map((b) => `@import url('./${b}');`).join(`
638
+ `), m = H(t, 6), c = ot(t), y = R(c.name), h = u(n, `css/f_${y}-${m}.css`);
639
+ T(h, $ || "/* Empty file */");
640
+ }
641
+ }
642
+ } catch (n) {
643
+ console.error(n);
644
+ }
645
+ }, Se = async (e, t, s = $t()) => {
646
+ var n, o;
647
+ try {
648
+ const i = await I(e);
649
+ if (ht(t)) {
650
+ const d = J(t, "utf8"), $ = await gt(e), { contents: m } = await rt(e, t, i);
651
+ let c = d;
652
+ for (const [y, h] of Object.entries(m)) {
653
+ if (h.isKeyframes || !h.generator) continue;
654
+ const b = h.generator._withBuildContext({
655
+ callerName: y,
656
+ isProduction: s,
657
+ config: $
658
+ }), [p, f] = await ie(c, y), g = c.slice(p, f);
659
+ if (h.isClassName) {
660
+ const P = c, _ = ` ${y} = className("${b.classNames}")`;
661
+ c = c.replace(g, _), P === c && console.error("Minimize file failed to change content", { name: y });
662
+ }
663
+ if (g.includes("styled")) {
664
+ const P = (o = (n = /styled\(([^,]+),/.exec(g)) == null ? void 0 : n.at(1)) == null ? void 0 : o.trim(), _ = c, V = ` ${y} = styled(${P}, "${b.classNames}", ${JSON.stringify(b.clientProps)})`;
665
+ c = c.replace(g, V), _ === c && console.error("Minimize file failed to change content", { name: y, tagName: P });
666
+ }
667
+ }
668
+ if ($.importStrategy === "component") {
669
+ const y = H(t, 6), h = ot(t);
670
+ c = `import '../../saltygen/css/${`f_${R(h.name)}-${y}.css`}';
671
+ ${c}`;
672
+ }
673
+ return c = c.replace("@salty-css/react/class-name", "@salty-css/react/class-name-client"), c = c.replace("{ styled }", "{ styledClient as styled }"), c = c.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), c;
674
+ }
675
+ } catch (i) {
676
+ console.error("Error in minimizeFile:", i);
677
+ }
678
+ };
679
+ export {
680
+ be as a,
681
+ we as g,
682
+ ht as i,
683
+ Se as m,
684
+ ae as s
685
+ };