@salty-css/vite 0.0.1-alpha.26 → 0.0.1-alpha.260

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