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