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

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