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

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