@salty-css/vite 0.0.1-alpha.24 → 0.0.1-alpha.240
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 +469 -26
- package/index.cjs +40 -16
- package/index.d.ts +3 -8
- package/index.js +656 -232
- package/package.json +9 -4
package/index.js
CHANGED
@@ -1,272 +1,696 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
import
|
5
|
-
import {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
1
|
+
var vt = Object.defineProperty;
|
2
|
+
var Jt = (e, t, s) => t in e ? vt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
|
3
|
+
var nt = (e, t, s) => Jt(e, typeof t != "symbol" ? t + "" : t, s);
|
4
|
+
import * as Pt from "esbuild";
|
5
|
+
import { execSync as zt } from "child_process";
|
6
|
+
import { join as u, parse as rt } from "path";
|
7
|
+
import { existsSync as mt, mkdirSync as K, statSync as Wt, readdirSync as At, readFileSync as R, writeFileSync as x } from "fs";
|
8
|
+
import { readFile as ht } from "fs/promises";
|
9
|
+
import { createLogger as Ht, format as ut, transports as It } from "winston";
|
10
|
+
import pt from "typescript";
|
11
|
+
const Ct = (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 = Ct(n % 52) + s;
|
14
|
+
return s = Ct(n % 52) + s, s.length < t ? s = s.padStart(t, "a") : s.length > t && (s = s.slice(-t)), s;
|
15
|
+
}, Gt = (e, t) => {
|
16
|
+
let s = t.length;
|
17
|
+
for (; s; ) e = e * 33 ^ t.charCodeAt(--s);
|
18
|
+
return e;
|
19
|
+
}, I = (e, t = 5) => {
|
20
|
+
const s = Gt(5381, JSON.stringify(e)) >>> 0;
|
21
|
+
return Qt(s, t);
|
17
22
|
};
|
18
|
-
function
|
19
|
-
return
|
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
|
22
|
-
if (typeof t != "string") return
|
23
|
-
|
24
|
-
const
|
25
|
-
return Object.values(
|
26
|
-
const { pattern:
|
27
|
-
|
28
|
-
const { value:
|
29
|
-
return
|
26
|
+
const Kt = (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: $, css: d } = r(m);
|
34
|
+
return d && n.push(d), $;
|
30
35
|
});
|
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
|
-
|
36
|
+
}), { transformed: s, additionalCss: n };
|
37
|
+
}, Nt = (e) => (t) => typeof t != "string" || !/\{[^{}]+\}/g.test(t) ? void 0 : { transformed: t.replace(/\{([^{}]+)\}/g, (...o) => `var(--${J(o[1].replaceAll(".", "-"))})`) }, Lt = Nt(), Zt = [
|
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
|
+
], Bt = (e, t, s) => Zt.some((o) => typeof o == "string" ? o === e : o.test(e)) ? `${t}px` : `${t}`, Ut = ["Webkit", "Moz", "ms", "O"], qt = (e) => e.startsWith("-") ? e : Ut.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 ([p, f]) => {
|
61
|
+
const w = p.trim(), F = qt(w), _ = (v, D = ";") => `${F}:${v}${D}`, E = { scope: t, config: s };
|
62
|
+
if (typeof f == "function") return r([p, f(E)]);
|
63
|
+
if (f instanceof Promise) return r([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 k = Object.entries(f);
|
70
|
+
for (const [i, y] of k) {
|
71
|
+
if (!y) return;
|
72
|
+
const S = Object.entries(y);
|
73
|
+
for (const [l, j] of S) {
|
74
|
+
if (!j) return;
|
75
|
+
const P = `${t}.${i}-${l}`;
|
76
|
+
(await ot(j, P, s)).forEach((W) => o.add(W));
|
77
|
+
}
|
78
|
+
}
|
79
|
+
return;
|
80
|
+
}
|
81
|
+
if (w === "compoundVariants") {
|
82
|
+
for (const k of f) {
|
83
|
+
const { css: i, ...y } = k, S = Object.entries(y).reduce((j, [P, O]) => `${j}.${P}-${O}`, t);
|
84
|
+
(await ot(i, S, s)).forEach((j) => o.add(j));
|
85
|
+
}
|
86
|
+
return;
|
60
87
|
}
|
61
|
-
|
62
|
-
|
88
|
+
if (w.startsWith("@")) {
|
89
|
+
const k = w, i = await Y(f, t, s), y = `${k} { ${i} }`;
|
90
|
+
o.add(y);
|
91
|
+
return;
|
92
|
+
}
|
93
|
+
const v = p.includes("&") ? w.replace("&", t) : w.startsWith(":") ? `${t}${w}` : `${t} ${w}`;
|
94
|
+
(await ot(f, v, s)).forEach((k) => o.add(k));
|
95
|
+
return;
|
63
96
|
}
|
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
|
-
|
97
|
+
if (typeof f == "number") {
|
98
|
+
const v = Bt(F, 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 ${F}`);
|
104
|
+
return _(f);
|
105
|
+
}, m = a.map(r), { modifiers: $ } = {}, d = [Nt(), Kt($)], g = (await Promise.all(m).then((p) => Promise.all(
|
106
|
+
p.map((f) => d.reduce(async (w, F) => {
|
107
|
+
const _ = await w;
|
108
|
+
if (!_) return _;
|
109
|
+
const E = await F(_);
|
110
|
+
if (!E) return _;
|
111
|
+
const { transformed: v, additionalCss: D } = E;
|
112
|
+
let k = "";
|
113
|
+
if (D)
|
114
|
+
for (const i of D)
|
115
|
+
k += await Y(i, "");
|
116
|
+
return `${k}${v}`;
|
117
|
+
}, Promise.resolve(f)))
|
118
|
+
))).filter((p) => p !== void 0).join(`
|
119
|
+
`);
|
120
|
+
if (!g.trim()) return Array.from(o);
|
121
|
+
const h = t ? `${t} {
|
122
|
+
${g}
|
123
|
+
}` : g;
|
124
|
+
return o.has(h) ? Array.from(o) : [h, ...o];
|
125
|
+
}, Y = async (e, t, s, n = !1) => (await ot(e, t, s, n)).join(`
|
126
|
+
`), _t = 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 _t(a, [...t, r]);
|
132
|
+
s.push(m);
|
93
133
|
} else
|
94
|
-
n[
|
95
|
-
|
96
|
-
const
|
97
|
-
|
134
|
+
n[o] = a;
|
135
|
+
if (Object.keys(n).length) {
|
136
|
+
const o = t.map(J).join("-"), a = "t_" + I(o, 4), r = await Y(n, `.${o}, .${a}`);
|
137
|
+
s.push(r);
|
98
138
|
}
|
99
|
-
return
|
139
|
+
return s.join(`
|
100
140
|
`);
|
101
|
-
},
|
102
|
-
const
|
103
|
-
|
104
|
-
|
141
|
+
}, Xt = (e) => e ? Object.entries(e).reduce((t, [s, n]) => (typeof n == "function" ? t[s] = "any" : typeof n == "object" && (t[s] = xt(n).map((o) => `"${o}"`).join(" | ")), t), {}) : {}, xt = (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" ? xt(o, a, s) : s.add(t);
|
144
|
+
}), [...s]) : [], Tt = (e) => {
|
145
|
+
if (!e || e === "/") throw new Error("Could not find package.json file");
|
146
|
+
const t = u(e, "package.json");
|
147
|
+
return mt(t) ? t : Tt(u(e, ".."));
|
148
|
+
}, Yt = async (e) => {
|
149
|
+
const t = Tt(e);
|
150
|
+
return await ht(t, "utf-8").then(JSON.parse).catch(() => {
|
151
|
+
});
|
152
|
+
}, te = async (e) => {
|
153
|
+
const t = await Yt(e);
|
154
|
+
if (t)
|
155
|
+
return t.type;
|
156
|
+
};
|
157
|
+
let G;
|
158
|
+
const Dt = async (e) => {
|
159
|
+
if (G) return G;
|
160
|
+
const t = await te(e);
|
161
|
+
return t === "module" ? G = "esm" : (t === "commonjs" || import.meta.url.endsWith(".cjs")) && (G = "cjs"), G || "esm";
|
162
|
+
}, dt = Ht({
|
163
|
+
level: "debug",
|
164
|
+
format: ut.combine(ut.colorize(), ut.cli()),
|
165
|
+
transports: [new It.Console({})]
|
166
|
+
});
|
167
|
+
function kt(e) {
|
168
|
+
return e ? typeof e != "string" ? kt(String(e)) : e.replace(/[^\d\w]/g, ".") : "";
|
169
|
+
}
|
170
|
+
const ee = {
|
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 }, {}), se = (...e) => e.flat().reduce((t, s) => ({ ...t, ...s._children }), {});
|
217
|
+
class ne {
|
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 oe {
|
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 ne({
|
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 re = (e) => new oe(e), ae = (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 $ = m.getStart(), d = m.getEnd();
|
267
|
+
clearTimeout(o), s([$, d]);
|
268
|
+
}
|
269
|
+
m.forEachChild(r);
|
270
|
+
}
|
271
|
+
r(a);
|
272
|
+
}), z = {
|
273
|
+
externalModules: [],
|
274
|
+
rcFile: void 0,
|
275
|
+
destDir: void 0
|
276
|
+
}, Et = (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
|
+
}, Q = async (e) => {
|
283
|
+
if (z.destDir) return z.destDir;
|
284
|
+
const t = await yt(e), s = u(e, (t == null ? void 0 : t.saltygenDir) || "saltygen");
|
285
|
+
return z.destDir = s, s;
|
286
|
+
}, Ot = ["salty", "css", "styles", "styled"], ie = (e = []) => new RegExp(`\\.(${[...Ot, ...e].join("|")})\\.`), Z = (e, t = []) => ie(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
|
+
}, yt = 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
|
+
}, ce = async (e) => {
|
297
|
+
const t = await yt(e), s = await Q(e), n = u(e, (t == null ? void 0 : t.configDir) || "", "salty.config.ts"), o = u(s, "salty.config.js"), a = await Dt(e), r = Et(n);
|
298
|
+
await Pt.build({
|
299
|
+
entryPoints: [n],
|
105
300
|
minify: !0,
|
106
301
|
treeShaking: !0,
|
107
302
|
bundle: !0,
|
108
|
-
outfile:
|
109
|
-
format:
|
110
|
-
external:
|
303
|
+
outfile: o,
|
304
|
+
format: a,
|
305
|
+
external: r
|
111
306
|
});
|
112
|
-
const
|
113
|
-
return
|
114
|
-
},
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
const
|
131
|
-
C
|
132
|
-
const
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
307
|
+
const m = Date.now(), { config: $ } = await import(`${o}?t=${m}`);
|
308
|
+
return { config: $, path: o };
|
309
|
+
}, le = async (e, t) => {
|
310
|
+
var $t, bt;
|
311
|
+
const s = await Q(e), n = {
|
312
|
+
mediaQueries: [],
|
313
|
+
globalStyles: [],
|
314
|
+
variables: [],
|
315
|
+
templates: []
|
316
|
+
};
|
317
|
+
await Promise.all(
|
318
|
+
[...t].map(async (C) => {
|
319
|
+
const { contents: N, outputFilePath: q } = await at(e, C, s);
|
320
|
+
Object.entries(N).forEach(([V, T]) => {
|
321
|
+
T.isMedia ? n.mediaQueries.push([V, T]) : T.isGlobalDefine ? n.globalStyles.push(T) : T.isDefineVariables ? n.variables.push(T) : T.isDefineTemplates && n.templates.push(T._setPath(`${V};;${q}`));
|
322
|
+
});
|
323
|
+
})
|
324
|
+
);
|
325
|
+
const { config: o, path: a } = await ce(e), r = { ...o }, { mediaQueries: m } = n;
|
326
|
+
r.mediaQueries = Object.fromEntries(m.map(([C, N]) => [`@${C}`, N]));
|
327
|
+
const $ = m.map(([C]) => `'@${C}'`).join(" | "), d = /* @__PURE__ */ new Set(), c = async (C, N = []) => {
|
328
|
+
if (!C) return [];
|
329
|
+
const q = Object.entries(C).map(async ([T, H]) => {
|
330
|
+
const X = async (M) => {
|
331
|
+
if (!M) return;
|
332
|
+
if (M instanceof Promise) return await X(await M);
|
333
|
+
if (typeof M == "function") return await X(await M());
|
334
|
+
if (typeof M == "object") return await c(M, [...N, T]);
|
335
|
+
const ct = kt(T), lt = J(T), ft = [...N, ct].join(".");
|
336
|
+
d.add(`"${ft}"`);
|
337
|
+
const st = [...N.map(J), lt].join("-"), St = Lt(M);
|
338
|
+
return St ? `--${st}: ${St.transformed};` : `--${st}: ${M};`;
|
339
|
+
};
|
340
|
+
return await X(H);
|
341
|
+
});
|
342
|
+
return (await Promise.all(q)).flat();
|
343
|
+
}, g = async (C) => {
|
344
|
+
if (!C) return [];
|
345
|
+
const N = Object.entries(C).map(async ([V, T]) => {
|
346
|
+
const H = await c(T);
|
347
|
+
return V === "base" ? H.join("") : r.mediaQueries[V] ? `${r.mediaQueries[V]} { ${H.join("")} }` : `${V} { ${H.join("")} }`;
|
348
|
+
});
|
349
|
+
return (await Promise.all(N)).flat();
|
350
|
+
}, h = async (C) => {
|
351
|
+
if (!C) return [];
|
352
|
+
const N = Object.entries(C).map(async ([V, T]) => {
|
353
|
+
const H = Object.entries(T).map(async ([M, ct]) => {
|
354
|
+
const lt = await c(ct, [V]), ft = `.${V}-${M}, [data-${V}="${M}"]`, st = lt.join("");
|
355
|
+
return `${ft} { ${st} }`;
|
356
|
+
});
|
357
|
+
return (await Promise.all(H)).flat();
|
358
|
+
});
|
359
|
+
return (await Promise.all(N)).flat();
|
360
|
+
}, b = (C) => ({ ...C, responsive: void 0, conditional: void 0 }), p = (C) => n.variables.map((N) => C === "static" ? b(N._current) : N._current[C]), f = L(b(o.variables), p("static")), w = await c(f), F = L(($t = o.variables) == null ? void 0 : $t.responsive, p("responsive")), _ = await g(F), E = L((bt = o.variables) == null ? void 0 : bt.conditional, p("conditional")), v = await h(E), D = u(s, "css/_variables.css"), k = `:root { ${w.join("")} ${_.join("")} } ${v.join("")}`;
|
361
|
+
x(D, k), r.staticVariables = f;
|
362
|
+
const i = u(s, "css/_global.css"), y = L(o.global, n.globalStyles), S = await Y(y, "");
|
363
|
+
x(i, `@layer global { ${S} }`);
|
364
|
+
const l = u(s, "css/_reset.css"), P = o.reset === "none" ? {} : typeof o.reset == "object" ? o.reset : ee, O = await Y(P, "");
|
365
|
+
x(l, `@layer reset { ${O} }`);
|
366
|
+
const W = u(s, "css/_templates.css"), A = L(o.templates, n.templates), B = await _t(A), tt = Xt(A);
|
367
|
+
x(W, `@layer templates { ${B} }`), r.templates = A;
|
368
|
+
const it = o.templates ? [re(o.templates)._setPath(`config;;${a}`)] : [], U = se(n.templates, it);
|
369
|
+
r.templatePaths = Object.fromEntries(Object.entries(U).map(([C, N]) => [C, N._path]));
|
370
|
+
const et = u(s, "types/css-tokens.d.ts"), Mt = `
|
371
|
+
// Variable types
|
372
|
+
type VariableTokens = ${[...d].join("|")};
|
373
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
374
|
+
|
375
|
+
// Template types
|
376
|
+
type TemplateTokens = {
|
377
|
+
${Object.entries(tt).map(([C, N]) => `${C}?: ${N}`).join(`
|
378
|
+
`)}
|
379
|
+
}
|
380
|
+
|
381
|
+
// Media query types
|
382
|
+
type MediaQueryKeys = ${$ || "''"};
|
383
|
+
`;
|
384
|
+
x(et, Mt);
|
385
|
+
const Rt = u(s, "cache/config-cache.json");
|
386
|
+
x(Rt, JSON.stringify(r, null, 2));
|
387
|
+
}, jt = (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 (Ot.some((d) => m == null ? void 0 : m.includes(d))) return t;
|
395
|
+
}
|
396
|
+
return "styled('div',";
|
397
|
+
}), fe = (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 = I(t), o = u(s, "./temp");
|
410
|
+
mt(o) || K(o);
|
411
|
+
const a = rt(t);
|
412
|
+
let r = R(t, "utf8");
|
413
|
+
r = jt(r), r = fe(r, e);
|
414
|
+
const m = u(s, "js", n + ".js"), $ = await yt(e), d = u(e, ($ == null ? void 0 : $.configDir) || "", "salty.config.ts"), c = Et(d), g = await Dt(e);
|
415
|
+
await Pt.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:
|
144
|
-
format:
|
145
|
-
target: ["
|
425
|
+
outfile: m,
|
426
|
+
format: g,
|
427
|
+
target: ["node20"],
|
146
428
|
keepNames: !0,
|
147
|
-
external:
|
429
|
+
external: c,
|
430
|
+
packages: "external",
|
431
|
+
plugins: [
|
432
|
+
{
|
433
|
+
name: "test",
|
434
|
+
setup: (p) => {
|
435
|
+
p.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (f) => {
|
436
|
+
const w = R(f.path, "utf8");
|
437
|
+
return { contents: jt(w), loader: "ts" };
|
438
|
+
});
|
439
|
+
}
|
440
|
+
}
|
441
|
+
]
|
148
442
|
});
|
149
|
-
const
|
150
|
-
return await import(`${
|
151
|
-
},
|
152
|
-
const
|
153
|
-
|
154
|
-
|
443
|
+
const h = Date.now();
|
444
|
+
return { contents: await import(`${m}?t=${h}`), outputFilePath: m };
|
445
|
+
}, ue = async (e) => {
|
446
|
+
const t = await Q(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
|
+
}, gt = async (e) => {
|
450
|
+
const t = await ue(e), s = await Q(e), n = u(s, "salty.config.js"), o = Date.now(), { config: a } = await import(`${n}?t=${o}`);
|
451
|
+
return L(a, t);
|
452
|
+
}, wt = () => {
|
155
453
|
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);
|
454
|
+
return process.env.NODE_ENV === "production";
|
455
|
+
} catch {
|
456
|
+
return !1;
|
457
|
+
}
|
458
|
+
}, pe = async (e, t = wt(), s = !0) => {
|
459
|
+
try {
|
460
|
+
const n = Date.now();
|
461
|
+
t ? dt.info("Generating CSS in production mode! 🔥") : dt.info("Generating CSS in development mode! 🚀");
|
462
|
+
const o = [], a = [], r = await Q(e), m = u(r, "index.css");
|
463
|
+
s && (() => {
|
464
|
+
mt(r) && zt("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 d = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set();
|
467
|
+
async function g(i) {
|
468
|
+
const y = ["node_modules", "saltygen"], S = Wt(i);
|
469
|
+
if (S.isDirectory()) {
|
470
|
+
const l = At(i);
|
471
|
+
if (y.some((P) => i.includes(P))) return;
|
472
|
+
await Promise.all(l.map((P) => g(u(i, P))));
|
473
|
+
} else if (S.isFile() && Z(i)) {
|
474
|
+
d.add(i);
|
475
|
+
const j = R(i, "utf8");
|
476
|
+
/define[\w\d]+\(/.test(j) && c.add(i);
|
186
477
|
}
|
187
478
|
}
|
188
|
-
await
|
189
|
-
const
|
479
|
+
await g(e), await le(e, c);
|
480
|
+
const h = {
|
481
|
+
keyframes: [],
|
482
|
+
components: [],
|
483
|
+
classNames: []
|
484
|
+
};
|
485
|
+
await Promise.all(
|
486
|
+
[...d].map(async (i) => {
|
487
|
+
const { contents: y } = await at(e, i, r);
|
488
|
+
for (let [S, l] of Object.entries(y))
|
489
|
+
l instanceof Promise && (l = await l), l.isKeyframes ? h.keyframes.push({
|
490
|
+
value: l,
|
491
|
+
src: i,
|
492
|
+
name: S
|
493
|
+
}) : l.isClassName ? h.classNames.push({
|
494
|
+
...l,
|
495
|
+
src: i,
|
496
|
+
name: S
|
497
|
+
}) : l.generator && h.components.push({
|
498
|
+
...l,
|
499
|
+
src: i,
|
500
|
+
name: S
|
501
|
+
});
|
502
|
+
})
|
503
|
+
);
|
504
|
+
const b = await gt(e);
|
505
|
+
for (const i of h.keyframes) {
|
506
|
+
const { value: y } = i, S = `a_${y.animationName}.css`, l = `css/${S}`, j = u(r, l);
|
507
|
+
o.push(S), x(j, y.css);
|
508
|
+
}
|
509
|
+
const p = {};
|
510
|
+
for (const i of h.components) {
|
511
|
+
const { src: y, name: S } = i;
|
512
|
+
p[y] || (p[y] = []);
|
513
|
+
const l = i.generator._withBuildContext({
|
514
|
+
callerName: S,
|
515
|
+
isProduction: t,
|
516
|
+
config: b
|
517
|
+
});
|
518
|
+
a[l.priority] || (a[l.priority] = []);
|
519
|
+
const j = await l.css;
|
520
|
+
if (!j) continue;
|
521
|
+
a[l.priority].push(l.cssFileName);
|
522
|
+
const P = `css/${l.cssFileName}`, O = u(r, P);
|
523
|
+
x(O, j), b.importStrategy === "component" && p[y].push(l.cssFileName);
|
524
|
+
}
|
525
|
+
for (const i of h.classNames) {
|
526
|
+
const { src: y, name: S } = i;
|
527
|
+
p[y] || (p[y] = []);
|
528
|
+
const l = i.generator._withBuildContext({
|
529
|
+
callerName: S,
|
530
|
+
isProduction: t,
|
531
|
+
config: b
|
532
|
+
}), j = await l.css;
|
533
|
+
if (!j) continue;
|
534
|
+
a[l.priority] || (a[l.priority] = []), a[l.priority].push(l.cssFileName);
|
535
|
+
const P = `css/${l.cssFileName}`, O = u(r, P);
|
536
|
+
x(O, j), b.importStrategy === "component" && p[y].push(l.cssFileName);
|
537
|
+
}
|
538
|
+
b.importStrategy === "component" && Object.entries(p).forEach(([i, y]) => {
|
539
|
+
const S = y.map((W) => `@import url('./${W}');`).join(`
|
540
|
+
`), l = I(i, 6), j = rt(i), P = J(j.name), O = u(r, `css/f_${P}-${l}.css`);
|
541
|
+
x(O, S || "/* Empty file */");
|
542
|
+
});
|
543
|
+
const f = o.map((i) => `@import url('./css/${i}');`).join(`
|
190
544
|
`);
|
191
|
-
let
|
545
|
+
let E = `@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
192
546
|
|
193
|
-
${["
|
547
|
+
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((i) => {
|
548
|
+
try {
|
549
|
+
return R(u(r, "css", i), "utf8").length > 0;
|
550
|
+
} catch {
|
551
|
+
return !1;
|
552
|
+
}
|
553
|
+
}).map((i) => `@import url('./css/${i}');`).join(`
|
194
554
|
`)}
|
195
555
|
${f}`;
|
196
|
-
if (
|
197
|
-
const
|
198
|
-
|
199
|
-
|
556
|
+
if (b.importStrategy !== "component") {
|
557
|
+
const i = a.reduce((y, S, l) => {
|
558
|
+
const j = S.reduce((A, B) => {
|
559
|
+
var et;
|
560
|
+
const tt = u(r, "css", B), it = R(tt, "utf8"), U = ((et = /.*-([^-]+)-\d+.css/.exec(B)) == null ? void 0 : et.at(1)) || I(tt, 6);
|
561
|
+
return A.includes(U) ? A : `${A}
|
562
|
+
/*start:${U}-${B}*/
|
563
|
+
${it}
|
564
|
+
/*end:${U}*/
|
565
|
+
`;
|
566
|
+
}, ""), P = `l_${l}.css`, O = u(r, "css", P), W = `@layer l${l} { ${j}
|
567
|
+
}`;
|
568
|
+
return x(O, W), `${y}
|
569
|
+
@import url('./css/${P}');`;
|
570
|
+
}, "");
|
571
|
+
E += i;
|
200
572
|
}
|
201
|
-
|
202
|
-
|
203
|
-
|
573
|
+
x(m, E);
|
574
|
+
const D = Date.now() - n, k = D < 200 ? "🔥" : D < 500 ? "🚀" : D < 1e3 ? "🎉" : D < 2e3 ? "🚗" : D < 5e3 ? "🤔" : "🥴";
|
575
|
+
dt.info(`Generated CSS in ${D}ms! ${k}`);
|
576
|
+
} catch (n) {
|
577
|
+
console.error(n);
|
204
578
|
}
|
205
|
-
},
|
579
|
+
}, de = async (e, t, s = wt()) => {
|
206
580
|
try {
|
207
|
-
const
|
208
|
-
if (
|
209
|
-
const
|
210
|
-
Object.entries(
|
211
|
-
if (
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
}
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
581
|
+
const n = await Q(e);
|
582
|
+
if (Z(t)) {
|
583
|
+
const a = [], r = await gt(e), { contents: m } = await at(e, t, n);
|
584
|
+
for (const [$, d] of Object.entries(m)) {
|
585
|
+
if (d.isKeyframes && d.css) {
|
586
|
+
const f = `css/${`a_${d.animationName}.css`}`, w = u(n, f);
|
587
|
+
x(w, await d.css);
|
588
|
+
return;
|
589
|
+
}
|
590
|
+
if (d.isClassName) {
|
591
|
+
const p = d.generator._withBuildContext({
|
592
|
+
callerName: $,
|
593
|
+
isProduction: s,
|
594
|
+
config: r
|
595
|
+
}), f = await p.css;
|
596
|
+
if (!f) continue;
|
597
|
+
a[p.priority] || (a[p.priority] = []), a[p.priority].push(p.cssFileName);
|
598
|
+
const w = `css/${p.cssFileName}`, F = u(n, w);
|
599
|
+
x(F, f);
|
600
|
+
}
|
601
|
+
if (!d.generator) return;
|
602
|
+
const c = d.generator._withBuildContext({
|
603
|
+
callerName: $,
|
604
|
+
isProduction: s,
|
605
|
+
config: r
|
606
|
+
}), g = await c.css;
|
607
|
+
if (!g) continue;
|
608
|
+
const h = `css/${c.cssFileName}`, b = u(n, h);
|
609
|
+
x(b, g), a[c.priority] || (a[c.priority] = []), a[c.priority].push(c.cssFileName);
|
610
|
+
}
|
611
|
+
if (r.importStrategy !== "component")
|
612
|
+
a.forEach(($, d) => {
|
613
|
+
const c = `l_${d}.css`, g = u(n, "css", c);
|
614
|
+
let h = R(g, "utf8");
|
615
|
+
$.forEach((b) => {
|
616
|
+
var F;
|
617
|
+
const p = u(n, "css", b), f = ((F = /.*-([^-]+)-\d+.css/.exec(b)) == null ? void 0 : F.at(1)) || I(p, 6);
|
618
|
+
if (!h.includes(f)) {
|
619
|
+
const _ = R(p, "utf8"), E = `/*start:${f}-${b}*/
|
620
|
+
${_}
|
621
|
+
/*end:${f}*/
|
622
|
+
`;
|
623
|
+
h = `${h.replace(/\}$/, "")}
|
624
|
+
${E}
|
625
|
+
}`;
|
626
|
+
}
|
627
|
+
}), x(g, h);
|
628
|
+
});
|
629
|
+
else {
|
630
|
+
const $ = a.flat().map((b) => `@import url('./${b}');`).join(`
|
631
|
+
`), d = I(t, 6), c = rt(t), g = J(c.name), h = u(n, `css/f_${g}-${d}.css`);
|
632
|
+
x(h, $ || "/* Empty file */");
|
633
|
+
}
|
222
634
|
}
|
223
|
-
} catch (
|
224
|
-
console.error(
|
635
|
+
} catch (n) {
|
636
|
+
console.error(n);
|
225
637
|
}
|
226
|
-
},
|
638
|
+
}, me = async (e, t, s = wt()) => {
|
639
|
+
var n, o;
|
227
640
|
try {
|
228
|
-
const
|
229
|
-
if (
|
230
|
-
const
|
231
|
-
|
232
|
-
const
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
console.log("value", p);
|
238
|
-
return;
|
239
|
-
}
|
240
|
-
if (!p.generator) return;
|
241
|
-
const h = p.generator._withBuildContext({
|
242
|
-
name: i,
|
641
|
+
const a = await Q(e);
|
642
|
+
if (Z(t)) {
|
643
|
+
const m = R(t, "utf8"), $ = await gt(e), { contents: d } = await at(e, t, a);
|
644
|
+
let c = m;
|
645
|
+
for (const [g, h] of Object.entries(d)) {
|
646
|
+
if (h.isKeyframes || !h.generator) continue;
|
647
|
+
const b = h.generator._withBuildContext({
|
648
|
+
callerName: g,
|
649
|
+
isProduction: s,
|
243
650
|
config: $
|
244
|
-
}),
|
245
|
-
if (
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
651
|
+
}), [p, f] = await ae(c, g), w = c.slice(p, f);
|
652
|
+
if (h.isClassName) {
|
653
|
+
const F = c, _ = ` ${g} = className("${b.classNames}")`;
|
654
|
+
c = c.replace(w, _), F === c && console.error("Minimize file failed to change content", { name: g });
|
655
|
+
}
|
656
|
+
if (w.includes("styled")) {
|
657
|
+
const F = (o = (n = /styled\(([^,]+),/.exec(w)) == null ? void 0 : n.at(1)) == null ? void 0 : o.trim(), _ = c, E = ` ${g} = styled(${F}, "${b.classNames}", ${JSON.stringify(b.clientProps)})`;
|
658
|
+
c = c.replace(w, E), _ === c && console.error("Minimize file failed to change content", { name: g, tagName: F });
|
659
|
+
}
|
660
|
+
}
|
661
|
+
if ($.importStrategy === "component") {
|
662
|
+
const g = I(t, 6), h = rt(t);
|
663
|
+
c = `import '../../saltygen/css/${`f_${J(h.name)}-${g}.css`}';
|
664
|
+
${c}`;
|
665
|
+
}
|
666
|
+
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
667
|
}
|
254
|
-
} catch (
|
255
|
-
console.error(
|
668
|
+
} catch (a) {
|
669
|
+
console.error("Error in minimizeFile:", a);
|
256
670
|
}
|
257
|
-
},
|
671
|
+
}, Ft = async (e) => {
|
672
|
+
if (!e || e.includes("node_modules") || e.includes("saltygen")) return !1;
|
673
|
+
if (e.includes("salty.config")) return !0;
|
674
|
+
if (!Z(e)) return !1;
|
675
|
+
const n = await ht(e, "utf-8");
|
676
|
+
return !!/.+define[A-Z]\w+/.test(n);
|
677
|
+
}, je = (e) => ({
|
258
678
|
name: "stylegen",
|
259
|
-
buildStart: () =>
|
260
|
-
load: async (
|
261
|
-
if (
|
262
|
-
return await
|
679
|
+
buildStart: () => pe(e),
|
680
|
+
load: async (t) => {
|
681
|
+
if (Z(t))
|
682
|
+
return await me(e, t);
|
683
|
+
},
|
684
|
+
handleHotUpdate: async ({ file: t, server: s }) => {
|
685
|
+
await Ft(t) && s.restart();
|
263
686
|
},
|
264
687
|
watchChange: {
|
265
|
-
handler: async (
|
266
|
-
|
688
|
+
handler: async (t) => {
|
689
|
+
Z(t) && (await Ft(t) || await de(e, t));
|
267
690
|
}
|
268
691
|
}
|
269
692
|
});
|
270
693
|
export {
|
271
|
-
|
694
|
+
je as default,
|
695
|
+
je as saltyPlugin
|
272
696
|
};
|