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