@salty-css/webpack 0.0.1-alpha.235 → 0.0.1-alpha.236
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/index-C97eBBve.cjs +42 -0
- package/index-CHPE5cnj.js +678 -0
- package/index.cjs +1 -1
- package/index.js +1 -1
- package/loader.cjs +1 -1
- package/loader.js +1 -1
- package/package.json +2 -2
- package/index-B5IaIfZg.cjs +0 -42
- package/index-gNPxxbk_.js +0 -678
@@ -0,0 +1,678 @@
|
|
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 st = (e, t, s) => Jt(e, typeof t != "symbol" ? t + "" : t, s);
|
4
|
+
import * as jt from "esbuild";
|
5
|
+
import { execSync as Rt } from "child_process";
|
6
|
+
import { join as u, parse as ot } from "path";
|
7
|
+
import { existsSync as mt, writeFileSync as x, readFileSync as v, mkdirSync as K, statSync as zt, readdirSync as Wt } from "fs";
|
8
|
+
import { readFile as Pt } from "fs/promises";
|
9
|
+
import { createLogger as At, format as ft, transports as Ht } from "winston";
|
10
|
+
import ut from "typescript";
|
11
|
+
const Ct = (e) => String.fromCharCode(e + (e > 25 ? 39 : 97)), It = (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
|
+
}, Qt = (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 = Qt(5381, JSON.stringify(e)) >>> 0;
|
21
|
+
return It(s, t);
|
22
|
+
};
|
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()) : "";
|
25
|
+
}
|
26
|
+
const Gt = (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: i, transform: r } = o;
|
32
|
+
s = s.replace(i, (d) => {
|
33
|
+
const { value: w, css: m } = r(d);
|
34
|
+
return m && n.push(m), w;
|
35
|
+
});
|
36
|
+
}), { transformed: s, additionalCss: n };
|
37
|
+
}, Ft = (e) => (t) => typeof t != "string" || !/\{[^{}]+\}/g.test(t) ? void 0 : { transformed: t.replace(/\{([^{}]+)\}/g, (...o) => `var(--${R(o[1].replaceAll(".", "-"))})`) }, Kt = Ft(), Lt = [
|
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) => Lt.some((o) => typeof o == "string" ? o === e : o.test(e)) ? `${t}px` : `${t}`, Zt = ["Webkit", "Moz", "ms", "O"], qt = (e) => e.startsWith("-") ? e : Zt.some((t) => e.startsWith(t)) ? `-${R(e)}` : R(e), nt = async (e, t = "", s, n = !1) => {
|
59
|
+
if (!e) throw new Error("No styles provided to parseStyles function!");
|
60
|
+
const o = /* @__PURE__ */ new Set(), i = Object.entries(e), r = async ([p, f]) => {
|
61
|
+
const $ = p.trim(), P = qt($), _ = (J, D = ";") => `${P}:${J}${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 ($ === "defaultVariants") return;
|
68
|
+
if ($ === "variants") {
|
69
|
+
const k = Object.entries(f);
|
70
|
+
for (const [a, y] of k) {
|
71
|
+
if (!y) return;
|
72
|
+
const C = Object.entries(y);
|
73
|
+
for (const [l, j] of C) {
|
74
|
+
if (!j) return;
|
75
|
+
const F = `${t}.${a}-${l}`;
|
76
|
+
(await nt(j, F, s)).forEach((W) => o.add(W));
|
77
|
+
}
|
78
|
+
}
|
79
|
+
return;
|
80
|
+
}
|
81
|
+
if ($ === "compoundVariants") {
|
82
|
+
for (const k of f) {
|
83
|
+
const { css: a, ...y } = k, C = Object.entries(y).reduce((j, [F, O]) => `${j}.${F}-${O}`, t);
|
84
|
+
(await nt(a, C, s)).forEach((j) => o.add(j));
|
85
|
+
}
|
86
|
+
return;
|
87
|
+
}
|
88
|
+
if ($.startsWith("@")) {
|
89
|
+
const k = $, a = await X(f, t, s), y = `${k} { ${a} }`;
|
90
|
+
o.add(y);
|
91
|
+
return;
|
92
|
+
}
|
93
|
+
const J = p.includes("&") ? $.replace("&", t) : $.startsWith(":") ? `${t}${$}` : `${t} ${$}`;
|
94
|
+
(await nt(f, J, s)).forEach((k) => o.add(k));
|
95
|
+
return;
|
96
|
+
}
|
97
|
+
if (typeof f == "number") {
|
98
|
+
const J = Bt(P, f);
|
99
|
+
return _(J);
|
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
|
+
}, d = i.map(r), { modifiers: w } = {}, m = [Ft(), Gt(w)], g = (await Promise.all(d).then((p) => Promise.all(
|
106
|
+
p.map((f) => m.reduce(async ($, P) => {
|
107
|
+
const _ = await $;
|
108
|
+
if (!_) return _;
|
109
|
+
const E = await P(_);
|
110
|
+
if (!E) return _;
|
111
|
+
const { transformed: J, additionalCss: D } = E;
|
112
|
+
let k = "";
|
113
|
+
if (D)
|
114
|
+
for (const a of D)
|
115
|
+
k += await X(a, "");
|
116
|
+
return `${k}${J}`;
|
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
|
+
}, X = async (e, t, s, n = !1) => (await nt(e, t, s, n)).join(`
|
126
|
+
`), Nt = async (e, t = []) => {
|
127
|
+
if (!e) return "";
|
128
|
+
const s = [], n = {};
|
129
|
+
for (const [o, i] of Object.entries(e))
|
130
|
+
if (typeof i != "function") if (i && typeof i == "object") {
|
131
|
+
const r = o.trim(), d = await Nt(i, [...t, r]);
|
132
|
+
s.push(d);
|
133
|
+
} else
|
134
|
+
n[o] = i;
|
135
|
+
if (Object.keys(n).length) {
|
136
|
+
const o = t.map(R).join("-"), i = "t_" + I(o, 4), r = await X(n, `.${o}, .${i}`);
|
137
|
+
s.push(r);
|
138
|
+
}
|
139
|
+
return s.join(`
|
140
|
+
`);
|
141
|
+
}, Ut = (e) => e ? Object.entries(e).reduce((t, [s, n]) => (typeof n == "function" ? t[s] = "any" : typeof n == "object" && (t[s] = _t(n).map((o) => `"${o}"`).join(" | ")), t), {}) : {}, _t = (e, t = "", s = /* @__PURE__ */ new Set()) => e ? (Object.entries(e).forEach(([n, o]) => {
|
142
|
+
const i = t ? `${t}.${n}` : n;
|
143
|
+
return typeof o == "object" ? _t(o, i, s) : s.add(t);
|
144
|
+
}), [...s]) : [], xt = (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 : xt(u(e, ".."));
|
148
|
+
}, Xt = async (e) => {
|
149
|
+
const t = xt(e);
|
150
|
+
return await Pt(t, "utf-8").then(JSON.parse).catch(() => {
|
151
|
+
});
|
152
|
+
}, Yt = async (e) => {
|
153
|
+
const t = await Xt(e);
|
154
|
+
if (t)
|
155
|
+
return t.type;
|
156
|
+
};
|
157
|
+
let G;
|
158
|
+
const Tt = async (e) => {
|
159
|
+
if (G) return G;
|
160
|
+
const t = await Yt(e);
|
161
|
+
return t === "module" ? G = "esm" : (t === "commonjs" || import.meta.url.endsWith(".cjs")) && (G = "cjs"), G || "esm";
|
162
|
+
}, pt = At({
|
163
|
+
level: "debug",
|
164
|
+
format: ft.combine(ft.colorize(), ft.cli()),
|
165
|
+
transports: [new Ht.Console({})]
|
166
|
+
});
|
167
|
+
function Dt(e) {
|
168
|
+
return e ? typeof e != "string" ? Dt(String(e)) : e.replace(/[^\d\w]/g, ".") : "";
|
169
|
+
}
|
170
|
+
const te = {
|
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 }, {}), ee = (...e) => e.flat().reduce((t, s) => ({ ...t, ...s._children }), {});
|
217
|
+
class se {
|
218
|
+
constructor(t) {
|
219
|
+
st(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 ne {
|
233
|
+
constructor(t) {
|
234
|
+
st(this, "_path");
|
235
|
+
st(this, "templates", []);
|
236
|
+
this.params = t, Object.entries(t).forEach(([s, n]) => {
|
237
|
+
this.templates.push(
|
238
|
+
new se({
|
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 oe = (e) => new ne(e), re = (e, t) => new Promise((s, n) => {
|
261
|
+
const o = setTimeout(() => {
|
262
|
+
n(new Error("Timeout"));
|
263
|
+
}, 100), i = ut.createSourceFile("temp.ts", e, ut.ScriptTarget.Latest, !0);
|
264
|
+
function r(d) {
|
265
|
+
if (ut.isVariableDeclaration(d) && d.name.getText() === t) {
|
266
|
+
const w = d.getStart(), m = d.getEnd();
|
267
|
+
clearTimeout(o), s([w, m]);
|
268
|
+
}
|
269
|
+
d.forEachChild(r);
|
270
|
+
}
|
271
|
+
r(i);
|
272
|
+
}), z = {
|
273
|
+
externalModules: [],
|
274
|
+
rcFile: void 0,
|
275
|
+
destDir: void 0
|
276
|
+
}, kt = (e) => {
|
277
|
+
if (z.externalModules.length > 0) return z.externalModules;
|
278
|
+
const s = v(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 ht(e), s = u(e, (t == null ? void 0 : t.saltygenDir) || "saltygen");
|
285
|
+
return z.destDir = s, s;
|
286
|
+
}, Et = ["salty", "css", "styles", "styled"], ie = (e = []) => new RegExp(`\\.(${[...Et, ...e].join("|")})\\.`), dt = (e, t = []) => ie(t).test(e), Ot = 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 Pt(t, "utf-8").then(JSON.parse).catch(() => {
|
290
|
+
});
|
291
|
+
return s ? (z.rcFile = s, s) : Ot(u(e, ".."));
|
292
|
+
}, ht = async (e) => {
|
293
|
+
var n, o;
|
294
|
+
const t = await Ot(e), s = (n = t.projects) == null ? void 0 : n.find((i) => e.endsWith(i.dir || ""));
|
295
|
+
return s || ((o = t.projects) == null ? void 0 : o.find((i) => i.dir === t.defaultProject));
|
296
|
+
}, ae = async (e) => {
|
297
|
+
const t = await ht(e), s = await Q(e), n = u(e, (t == null ? void 0 : t.configDir) || "", "salty.config.ts"), o = u(s, "salty.config.js"), i = await Tt(e), r = kt(n);
|
298
|
+
await jt.build({
|
299
|
+
entryPoints: [n],
|
300
|
+
minify: !0,
|
301
|
+
treeShaking: !0,
|
302
|
+
bundle: !0,
|
303
|
+
outfile: o,
|
304
|
+
format: i,
|
305
|
+
external: r
|
306
|
+
});
|
307
|
+
const d = Date.now(), { config: w } = await import(`${o}?t=${d}`);
|
308
|
+
return { config: w, path: o };
|
309
|
+
}, ce = async (e, t) => {
|
310
|
+
var $t, wt;
|
311
|
+
const s = await Q(e), n = {
|
312
|
+
mediaQueries: [],
|
313
|
+
globalStyles: [],
|
314
|
+
variables: [],
|
315
|
+
templates: []
|
316
|
+
};
|
317
|
+
await Promise.all(
|
318
|
+
[...t].map(async (S) => {
|
319
|
+
const { contents: N, outputFilePath: q } = await rt(e, S, 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: i } = await ae(e), r = { ...o }, { mediaQueries: d } = n;
|
326
|
+
r.mediaQueries = Object.fromEntries(d.map(([S, N]) => [`@${S}`, N]));
|
327
|
+
const w = d.map(([S]) => `'@${S}'`).join(" | "), m = /* @__PURE__ */ new Set(), c = async (S, N = []) => {
|
328
|
+
if (!S) return [];
|
329
|
+
const q = Object.entries(S).map(async ([T, H]) => {
|
330
|
+
const U = async (M) => {
|
331
|
+
if (!M) return;
|
332
|
+
if (M instanceof Promise) return await U(await M);
|
333
|
+
if (typeof M == "function") return await U(await M());
|
334
|
+
if (typeof M == "object") return await c(M, [...N, T]);
|
335
|
+
const at = Dt(T), ct = R(T), lt = [...N, at].join(".");
|
336
|
+
m.add(`"${lt}"`);
|
337
|
+
const et = [...N.map(R), ct].join("-"), bt = Kt(M);
|
338
|
+
return bt ? `--${et}: ${bt.transformed};` : `--${et}: ${M};`;
|
339
|
+
};
|
340
|
+
return await U(H);
|
341
|
+
});
|
342
|
+
return (await Promise.all(q)).flat();
|
343
|
+
}, g = async (S) => {
|
344
|
+
if (!S) return [];
|
345
|
+
const N = Object.entries(S).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 (S) => {
|
351
|
+
if (!S) return [];
|
352
|
+
const N = Object.entries(S).map(async ([V, T]) => {
|
353
|
+
const H = Object.entries(T).map(async ([M, at]) => {
|
354
|
+
const ct = await c(at, [V]), lt = `.${V}-${M}, [data-${V}="${M}"]`, et = ct.join("");
|
355
|
+
return `${lt} { ${et} }`;
|
356
|
+
});
|
357
|
+
return (await Promise.all(H)).flat();
|
358
|
+
});
|
359
|
+
return (await Promise.all(N)).flat();
|
360
|
+
}, b = (S) => ({ ...S, responsive: void 0, conditional: void 0 }), p = (S) => n.variables.map((N) => S === "static" ? b(N._current) : N._current[S]), f = L(b(o.variables), p("static")), $ = await c(f), P = L(($t = o.variables) == null ? void 0 : $t.responsive, p("responsive")), _ = await g(P), E = L((wt = o.variables) == null ? void 0 : wt.conditional, p("conditional")), J = await h(E), D = u(s, "css/_variables.css"), k = `:root { ${$.join("")} ${_.join("")} } ${J.join("")}`;
|
361
|
+
x(D, k), r.staticVariables = f;
|
362
|
+
const a = u(s, "css/_global.css"), y = L(o.global, n.globalStyles), C = await X(y, "");
|
363
|
+
x(a, `@layer global { ${C} }`);
|
364
|
+
const l = u(s, "css/_reset.css"), F = o.reset === "none" ? {} : typeof o.reset == "object" ? o.reset : te, O = await X(F, "");
|
365
|
+
x(l, `@layer reset { ${O} }`);
|
366
|
+
const W = u(s, "css/_templates.css"), A = L(o.templates, n.templates), B = await Nt(A), Y = Ut(A);
|
367
|
+
x(W, `@layer templates { ${B} }`), r.templates = A;
|
368
|
+
const it = o.templates ? [oe(o.templates)._setPath(`config;;${i}`)] : [], Z = ee(n.templates, it);
|
369
|
+
r.templatePaths = Object.fromEntries(Object.entries(Z).map(([S, N]) => [S, N._path]));
|
370
|
+
const tt = u(s, "types/css-tokens.d.ts"), Vt = `
|
371
|
+
// Variable types
|
372
|
+
type VariableTokens = ${[...m].join("|")};
|
373
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
374
|
+
|
375
|
+
// Template types
|
376
|
+
type TemplateTokens = {
|
377
|
+
${Object.entries(Y).map(([S, N]) => `${S}?: ${N}`).join(`
|
378
|
+
`)}
|
379
|
+
}
|
380
|
+
|
381
|
+
// Media query types
|
382
|
+
type MediaQueryKeys = ${w || "''"};
|
383
|
+
`;
|
384
|
+
x(tt, Vt);
|
385
|
+
const Mt = u(s, "cache/config-cache.json");
|
386
|
+
x(Mt, JSON.stringify(r, null, 2));
|
387
|
+
}, St = (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 d = r.at(1);
|
394
|
+
if (Et.some((m) => d == null ? void 0 : d.includes(m))) return t;
|
395
|
+
}
|
396
|
+
return "styled('div',";
|
397
|
+
}), le = (e, t) => {
|
398
|
+
try {
|
399
|
+
const s = v(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
|
+
}, rt = async (e, t, s) => {
|
409
|
+
const n = I(t), o = u(s, "./temp");
|
410
|
+
mt(o) || K(o);
|
411
|
+
const i = ot(t);
|
412
|
+
let r = v(t, "utf8");
|
413
|
+
r = St(r), r = le(r, e);
|
414
|
+
const d = u(s, "js", n + ".js"), w = await ht(e), m = u(e, (w == null ? void 0 : w.configDir) || "", "salty.config.ts"), c = kt(m), g = await Tt(e);
|
415
|
+
await jt.build({
|
416
|
+
stdin: {
|
417
|
+
contents: r,
|
418
|
+
sourcefile: i.base,
|
419
|
+
resolveDir: i.dir,
|
420
|
+
loader: "tsx"
|
421
|
+
},
|
422
|
+
minify: !1,
|
423
|
+
treeShaking: !0,
|
424
|
+
bundle: !0,
|
425
|
+
outfile: d,
|
426
|
+
format: g,
|
427
|
+
target: ["node20"],
|
428
|
+
keepNames: !0,
|
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 $ = v(f.path, "utf8");
|
437
|
+
return { contents: St($), loader: "ts" };
|
438
|
+
});
|
439
|
+
}
|
440
|
+
}
|
441
|
+
]
|
442
|
+
});
|
443
|
+
const h = Date.now();
|
444
|
+
return { contents: await import(`${d}?t=${h}`), outputFilePath: d };
|
445
|
+
}, fe = async (e) => {
|
446
|
+
const t = await Q(e), s = u(t, "cache/config-cache.json"), n = v(s, "utf8");
|
447
|
+
if (!n) throw new Error("Could not find config cache file");
|
448
|
+
return JSON.parse(n);
|
449
|
+
}, yt = async (e) => {
|
450
|
+
const t = await fe(e), s = await Q(e), n = u(s, "salty.config.js"), o = Date.now(), { config: i } = await import(`${n}?t=${o}`);
|
451
|
+
return L(i, t);
|
452
|
+
}, gt = () => {
|
453
|
+
try {
|
454
|
+
return process.env.NODE_ENV === "production";
|
455
|
+
} catch {
|
456
|
+
return !1;
|
457
|
+
}
|
458
|
+
}, we = async (e, t = gt(), s = !0) => {
|
459
|
+
try {
|
460
|
+
const n = Date.now();
|
461
|
+
t ? pt.info("Generating CSS in production mode! 🔥") : pt.info("Generating CSS in development mode! 🚀");
|
462
|
+
const o = [], i = [], r = await Q(e), d = u(r, "index.css");
|
463
|
+
s && (() => {
|
464
|
+
mt(r) && Rt("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 m = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set();
|
467
|
+
async function g(a) {
|
468
|
+
const y = ["node_modules", "saltygen"], C = zt(a);
|
469
|
+
if (C.isDirectory()) {
|
470
|
+
const l = Wt(a);
|
471
|
+
if (y.some((F) => a.includes(F))) return;
|
472
|
+
await Promise.all(l.map((F) => g(u(a, F))));
|
473
|
+
} else if (C.isFile() && dt(a)) {
|
474
|
+
m.add(a);
|
475
|
+
const j = v(a, "utf8");
|
476
|
+
/define[\w\d]+\(/.test(j) && c.add(a);
|
477
|
+
}
|
478
|
+
}
|
479
|
+
await g(e), await ce(e, c);
|
480
|
+
const h = {
|
481
|
+
keyframes: [],
|
482
|
+
components: [],
|
483
|
+
classNames: []
|
484
|
+
};
|
485
|
+
await Promise.all(
|
486
|
+
[...m].map(async (a) => {
|
487
|
+
const { contents: y } = await rt(e, a, r);
|
488
|
+
for (let [C, l] of Object.entries(y))
|
489
|
+
l instanceof Promise && (l = await l), l.isKeyframes ? h.keyframes.push({
|
490
|
+
value: l,
|
491
|
+
src: a,
|
492
|
+
name: C
|
493
|
+
}) : l.isClassName ? h.classNames.push({
|
494
|
+
...l,
|
495
|
+
src: a,
|
496
|
+
name: C
|
497
|
+
}) : l.generator && h.components.push({
|
498
|
+
...l,
|
499
|
+
src: a,
|
500
|
+
name: C
|
501
|
+
});
|
502
|
+
})
|
503
|
+
);
|
504
|
+
const b = await yt(e);
|
505
|
+
for (const a of h.keyframes) {
|
506
|
+
const { value: y } = a, C = `a_${y.animationName}.css`, l = `css/${C}`, j = u(r, l);
|
507
|
+
o.push(C), x(j, y.css);
|
508
|
+
}
|
509
|
+
const p = {};
|
510
|
+
for (const a of h.components) {
|
511
|
+
const { src: y, name: C } = a;
|
512
|
+
p[y] || (p[y] = []);
|
513
|
+
const l = a.generator._withBuildContext({
|
514
|
+
callerName: C,
|
515
|
+
isProduction: t,
|
516
|
+
config: b
|
517
|
+
});
|
518
|
+
i[l.priority] || (i[l.priority] = []);
|
519
|
+
const j = await l.css;
|
520
|
+
if (!j) continue;
|
521
|
+
i[l.priority].push(l.cssFileName);
|
522
|
+
const F = `css/${l.cssFileName}`, O = u(r, F);
|
523
|
+
x(O, j), b.importStrategy === "component" && p[y].push(l.cssFileName);
|
524
|
+
}
|
525
|
+
for (const a of h.classNames) {
|
526
|
+
const { src: y, name: C } = a;
|
527
|
+
p[y] || (p[y] = []);
|
528
|
+
const l = a.generator._withBuildContext({
|
529
|
+
callerName: C,
|
530
|
+
isProduction: t,
|
531
|
+
config: b
|
532
|
+
}), j = await l.css;
|
533
|
+
if (!j) continue;
|
534
|
+
i[l.priority] || (i[l.priority] = []), i[l.priority].push(l.cssFileName);
|
535
|
+
const F = `css/${l.cssFileName}`, O = u(r, F);
|
536
|
+
x(O, j), b.importStrategy === "component" && p[y].push(l.cssFileName);
|
537
|
+
}
|
538
|
+
b.importStrategy === "component" && Object.entries(p).forEach(([a, y]) => {
|
539
|
+
const C = y.map((W) => `@import url('./${W}');`).join(`
|
540
|
+
`), l = I(a, 6), j = ot(a), F = R(j.name), O = u(r, `css/f_${F}-${l}.css`);
|
541
|
+
x(O, C || "/* Empty file */");
|
542
|
+
});
|
543
|
+
const f = o.map((a) => `@import url('./css/${a}');`).join(`
|
544
|
+
`);
|
545
|
+
let E = `@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
546
|
+
|
547
|
+
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((a) => {
|
548
|
+
try {
|
549
|
+
return v(u(r, "css", a), "utf8").length > 0;
|
550
|
+
} catch {
|
551
|
+
return !1;
|
552
|
+
}
|
553
|
+
}).map((a) => `@import url('./css/${a}');`).join(`
|
554
|
+
`)}
|
555
|
+
${f}`;
|
556
|
+
if (b.importStrategy !== "component") {
|
557
|
+
const a = i.reduce((y, C, l) => {
|
558
|
+
const j = C.reduce((A, B) => {
|
559
|
+
var tt;
|
560
|
+
const Y = u(r, "css", B), it = v(Y, "utf8"), Z = ((tt = /.*-([^-]+)-\d+.css/.exec(B)) == null ? void 0 : tt.at(1)) || I(Y, 6);
|
561
|
+
return A.includes(Z) ? A : `${A}
|
562
|
+
/*start:${Z}-${B}*/
|
563
|
+
${it}
|
564
|
+
/*end:${Z}*/
|
565
|
+
`;
|
566
|
+
}, ""), F = `l_${l}.css`, O = u(r, "css", F), W = `@layer l${l} { ${j}
|
567
|
+
}`;
|
568
|
+
return x(O, W), `${y}
|
569
|
+
@import url('./css/${F}');`;
|
570
|
+
}, "");
|
571
|
+
E += a;
|
572
|
+
}
|
573
|
+
x(d, E);
|
574
|
+
const D = Date.now() - n, k = D < 200 ? "🔥" : D < 500 ? "🚀" : D < 1e3 ? "🎉" : D < 2e3 ? "🚗" : D < 5e3 ? "🤔" : "🥴";
|
575
|
+
pt.info(`Generated CSS in ${D}ms! ${k}`);
|
576
|
+
} catch (n) {
|
577
|
+
console.error(n);
|
578
|
+
}
|
579
|
+
}, be = async (e, t, s = gt()) => {
|
580
|
+
try {
|
581
|
+
const n = await Q(e);
|
582
|
+
if (dt(t)) {
|
583
|
+
const i = [], r = await yt(e), { contents: d } = await rt(e, t, n);
|
584
|
+
for (const [w, m] of Object.entries(d)) {
|
585
|
+
if (m.isKeyframes && m.css) {
|
586
|
+
const f = `css/${`a_${m.animationName}.css`}`, $ = u(n, f);
|
587
|
+
x($, await m.css);
|
588
|
+
return;
|
589
|
+
}
|
590
|
+
if (m.isClassName) {
|
591
|
+
const p = m.generator._withBuildContext({
|
592
|
+
callerName: w,
|
593
|
+
isProduction: s,
|
594
|
+
config: r
|
595
|
+
}), f = await p.css;
|
596
|
+
if (!f) continue;
|
597
|
+
i[p.priority] || (i[p.priority] = []), i[p.priority].push(p.cssFileName);
|
598
|
+
const $ = `css/${p.cssFileName}`, P = u(n, $);
|
599
|
+
x(P, f);
|
600
|
+
}
|
601
|
+
if (!m.generator) return;
|
602
|
+
const c = m.generator._withBuildContext({
|
603
|
+
callerName: w,
|
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), i[c.priority] || (i[c.priority] = []), i[c.priority].push(c.cssFileName);
|
610
|
+
}
|
611
|
+
if (r.importStrategy !== "component")
|
612
|
+
i.forEach((w, m) => {
|
613
|
+
const c = `l_${m}.css`, g = u(n, "css", c);
|
614
|
+
let h = v(g, "utf8");
|
615
|
+
w.forEach((b) => {
|
616
|
+
var P;
|
617
|
+
const p = u(n, "css", b), f = ((P = /.*-([^-]+)-\d+.css/.exec(b)) == null ? void 0 : P.at(1)) || I(p, 6);
|
618
|
+
if (!h.includes(f)) {
|
619
|
+
const _ = v(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 w = i.flat().map((b) => `@import url('./${b}');`).join(`
|
631
|
+
`), m = I(t, 6), c = ot(t), g = R(c.name), h = u(n, `css/f_${g}-${m}.css`);
|
632
|
+
x(h, w || "/* Empty file */");
|
633
|
+
}
|
634
|
+
}
|
635
|
+
} catch (n) {
|
636
|
+
console.error(n);
|
637
|
+
}
|
638
|
+
}, Ce = async (e, t, s = gt()) => {
|
639
|
+
var n, o;
|
640
|
+
try {
|
641
|
+
const i = await Q(e);
|
642
|
+
if (dt(t)) {
|
643
|
+
const d = v(t, "utf8"), w = await yt(e), { contents: m } = await rt(e, t, i);
|
644
|
+
let c = d;
|
645
|
+
for (const [g, h] of Object.entries(m)) {
|
646
|
+
if (h.isKeyframes || !h.generator) continue;
|
647
|
+
const b = h.generator._withBuildContext({
|
648
|
+
callerName: g,
|
649
|
+
isProduction: s,
|
650
|
+
config: w
|
651
|
+
}), [p, f] = await re(c, g), $ = c.slice(p, f);
|
652
|
+
if (h.isClassName) {
|
653
|
+
const P = c, _ = ` ${g} = className("${b.classNames}")`;
|
654
|
+
c = c.replace($, _), P === c && console.error("Minimize file failed to change content", { name: g });
|
655
|
+
}
|
656
|
+
if ($.includes("styled")) {
|
657
|
+
const P = (o = (n = /styled\(([^,]+),/.exec($)) == null ? void 0 : n.at(1)) == null ? void 0 : o.trim(), _ = c, E = ` ${g} = styled(${P}, "${b.classNames}", ${JSON.stringify(b.clientProps)})`;
|
658
|
+
c = c.replace($, E), _ === c && console.error("Minimize file failed to change content", { name: g, tagName: P });
|
659
|
+
}
|
660
|
+
}
|
661
|
+
if (w.importStrategy === "component") {
|
662
|
+
const g = I(t, 6), h = ot(t);
|
663
|
+
c = `import '../../saltygen/css/${`f_${R(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;
|
667
|
+
}
|
668
|
+
} catch (i) {
|
669
|
+
console.error("Error in minimizeFile:", i);
|
670
|
+
}
|
671
|
+
};
|
672
|
+
export {
|
673
|
+
be as a,
|
674
|
+
we as g,
|
675
|
+
dt as i,
|
676
|
+
Ce as m,
|
677
|
+
ie as s
|
678
|
+
};
|
package/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("path"),t=require("./index-
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("path"),t=require("./index-C97eBBve.cjs"),y=require("fs/promises"),g=require("fs"),p=async e=>{if(!e||e.includes("node_modules")||e.includes("saltygen"))return!1;if(e.includes("salty.config"))return!0;if(!t.isSaltyFile(e))return!1;const a=await y.readFile(e,"utf-8");return!!/.+define[A-Z]\w+/.test(a)},c=(e,s,l=!1,a=!1)=>{var i,n,u;(n=(i=e.module)==null?void 0:i.rules)==null||n.push({test:t.saltyFileRegExp(),use:[{loader:d.resolve(__dirname,a?"./loader.cjs":"./loader.js"),options:{dir:s}}]}),l||(u=e.plugins)==null||u.push({apply:f=>{let o=!1;f.hooks.beforeCompile.tapPromise({name:"generateCss"},async()=>{o||(o=!0,await t.generateCss(s),g.watch(s,{recursive:!0},async(h,r)=>{await p(r)?await t.generateCss(s,!1,!1):t.isSaltyFile(r)&&await t.generateFile(s,r)}))})}})};exports.default=c;exports.saltyPlugin=c;
|
package/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { resolve as p } from "path";
|
2
|
-
import { i as f, s as d, g as u, a as y } from "./index-
|
2
|
+
import { i as f, s as d, g as u, a as y } from "./index-CHPE5cnj.js";
|
3
3
|
import { readFile as g } from "fs/promises";
|
4
4
|
import { watch as m } from "fs";
|
5
5
|
const w = async (s) => {
|
package/loader.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";const i=require("./index-
|
1
|
+
"use strict";const i=require("./index-C97eBBve.cjs");async function n(){const{dir:e}=this.getOptions(),{resourcePath:t}=this;return await i.generateFile(e,t),await i.minimizeFile(e,t)}module.exports=n;
|