@salty-css/vite 0.0.1-alpha.22 → 0.0.1-alpha.221

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