@salty-css/vite 0.0.1-alpha.23 → 0.0.1-alpha.231

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