@salty-css/webpack 0.0.1-alpha.23 → 0.0.1-alpha.230
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-BLikDM5S.cjs +42 -0
- package/index-DTqX17j6.js +658 -0
- package/index.cjs +1 -15
- package/index.d.ts +2 -1
- package/index.js +25 -215
- package/loader.cjs +1 -0
- package/loader.js +8 -0
- package/package.json +9 -4
@@ -0,0 +1,658 @@
|
|
1
|
+
var Et = Object.defineProperty;
|
2
|
+
var Ot = (e, t, s) => t in e ? Et(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
|
3
|
+
var tt = (e, t, s) => Ot(e, typeof t != "symbol" ? t + "" : t, s);
|
4
|
+
import * as bt from "esbuild";
|
5
|
+
import { execSync as Vt } from "child_process";
|
6
|
+
import { join as u, parse as st } from "path";
|
7
|
+
import { existsSync as lt, writeFileSync as x, readFileSync as M, mkdirSync as I, statSync as Mt, readdirSync as vt } from "fs";
|
8
|
+
import { readFile as wt } from "fs/promises";
|
9
|
+
import { createLogger as At, format as it, transports as Jt } from "winston";
|
10
|
+
import at from "typescript";
|
11
|
+
const yt = (e) => String.fromCharCode(e + (e > 25 ? 39 : 97)), Rt = (e, t) => {
|
12
|
+
let s = "", n;
|
13
|
+
for (n = Math.abs(e); n > 52; n = n / 52 | 0) s = yt(n % 52) + s;
|
14
|
+
return s = yt(n % 52) + s, s.length < t ? s = s.padStart(t, "a") : s.length > t && (s = s.slice(-t)), s;
|
15
|
+
}, zt = (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 = zt(5381, JSON.stringify(e)) >>> 0;
|
21
|
+
return Rt(s, t);
|
22
|
+
};
|
23
|
+
function A(e) {
|
24
|
+
return e ? typeof e != "string" ? A(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 Wt = (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: g, css: h } = i(m);
|
34
|
+
return h && n.push(h), g;
|
35
|
+
});
|
36
|
+
}), { transformed: s, additionalCss: n };
|
37
|
+
}, Ct = (e) => (t) => typeof t != "string" || !/\{[^{}]+\}/g.test(t) ? void 0 : { transformed: t.replace(/\{([^{}]+)\}/g, (...o) => `var(--${A(o[1].replaceAll(".", "-"))})`) }, Zt = Ct(), Ht = [
|
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
|
+
], It = (e, t, s) => Ht.some((o) => typeof o == "string" ? o === e : o.test(e)) ? `${t}px` : `${t}`, Gt = ["Webkit", "Moz", "ms", "O"], Kt = (e) => e.startsWith("-") ? e : Gt.some((t) => e.startsWith(t)) ? `-${A(e)}` : A(e), et = 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 b = p.trim(), P = Kt(b), _ = (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 (b === "defaultVariants") return;
|
68
|
+
if (b === "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 et(C, N, s)).forEach((z) => o.add(z));
|
77
|
+
}
|
78
|
+
}
|
79
|
+
return;
|
80
|
+
}
|
81
|
+
if (b === "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 et(a, j, s)).forEach((C) => o.add(C));
|
85
|
+
}
|
86
|
+
return;
|
87
|
+
}
|
88
|
+
if (b.startsWith("@")) {
|
89
|
+
const D = b, a = await B(f, t, s), $ = `${D} { ${a} }`;
|
90
|
+
o.add($);
|
91
|
+
return;
|
92
|
+
}
|
93
|
+
const v = p.includes("&") ? b.replace("&", t) : b.startsWith(":") ? `${t}${b}` : `${t} ${b}`;
|
94
|
+
(await et(f, v, s)).forEach((D) => o.add(D));
|
95
|
+
return;
|
96
|
+
}
|
97
|
+
if (typeof f == "number") {
|
98
|
+
const v = It(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: g } = {}, h = [Ct(), Wt(g)], y = (await Promise.all(m).then((p) => Promise.all(
|
106
|
+
p.map((f) => h.reduce(async (b, P) => {
|
107
|
+
const _ = await b;
|
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 B(a, "");
|
116
|
+
return `${D}${v}`;
|
117
|
+
}, Promise.resolve(f)))
|
118
|
+
))).filter((p) => p !== void 0).join(`
|
119
|
+
`);
|
120
|
+
if (!y.trim()) return Array.from(o);
|
121
|
+
const d = t ? `${t} {
|
122
|
+
${y}
|
123
|
+
}` : y;
|
124
|
+
return o.has(d) ? Array.from(o) : [d, ...o];
|
125
|
+
}, B = async (e, t, s, n = !1) => (await et(e, t, s, n)).join(`
|
126
|
+
`), St = 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 St(r, [...t, i]);
|
132
|
+
s.push(m);
|
133
|
+
} else
|
134
|
+
n[o] = r;
|
135
|
+
if (Object.keys(n).length) {
|
136
|
+
const o = t.map(A).join("-"), r = "t_" + W(o, 4), i = await B(n, `.${o}, .${r}`);
|
137
|
+
s.push(i);
|
138
|
+
}
|
139
|
+
return s.join(`
|
140
|
+
`);
|
141
|
+
}, Lt = (e) => e ? Object.entries(e).reduce((t, [s, n]) => (typeof n == "function" ? t[s] = "any" : typeof n == "object" && (t[s] = jt(n).map((o) => `"${o}"`).join(" | ")), t), {}) : {}, jt = (e, t = "", s = /* @__PURE__ */ new Set()) => e ? (Object.entries(e).forEach(([n, o]) => {
|
142
|
+
const r = t ? `${t}.${n}` : n;
|
143
|
+
return typeof o == "object" ? jt(o, r, s) : s.add(t);
|
144
|
+
}), [...s]) : [], Ft = (e) => {
|
145
|
+
if (!e || e === "/") throw new Error("Could not find package.json file");
|
146
|
+
const t = u(e, "package.json");
|
147
|
+
return lt(t) ? t : Ft(u(e, ".."));
|
148
|
+
}, Qt = async (e) => {
|
149
|
+
const t = Ft(e);
|
150
|
+
return await wt(t, "utf-8").then(JSON.parse).catch(() => {
|
151
|
+
});
|
152
|
+
}, Bt = async (e) => {
|
153
|
+
const t = await Qt(e);
|
154
|
+
if (t)
|
155
|
+
return t.type;
|
156
|
+
};
|
157
|
+
let H;
|
158
|
+
const Pt = async (e) => {
|
159
|
+
if (H) return H;
|
160
|
+
const t = await Bt(e);
|
161
|
+
return t === "module" ? H = "esm" : (t === "commonjs" || import.meta.url.endsWith(".cjs")) && (H = "cjs"), H || "esm";
|
162
|
+
}, ct = At({
|
163
|
+
level: "debug",
|
164
|
+
format: it.combine(it.colorize(), it.cli()),
|
165
|
+
transports: [new Jt.Console({})]
|
166
|
+
});
|
167
|
+
function Nt(e) {
|
168
|
+
return e ? typeof e != "string" ? Nt(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 }, {}), Ut = (...e) => e.flat().reduce((t, s) => ({ ...t, ...s._children }), {});
|
217
|
+
class Xt {
|
218
|
+
constructor(t) {
|
219
|
+
tt(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 Yt {
|
233
|
+
constructor(t) {
|
234
|
+
tt(this, "_path");
|
235
|
+
tt(this, "templates", []);
|
236
|
+
this.params = t, Object.entries(t).forEach(([s, n]) => {
|
237
|
+
this.templates.push(
|
238
|
+
new Xt({
|
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 te = (e) => new Yt(e), ee = (e, t) => new Promise((s, n) => {
|
261
|
+
const o = setTimeout(() => {
|
262
|
+
n(new Error("Timeout"));
|
263
|
+
}, 100), r = at.createSourceFile("temp.ts", e, at.ScriptTarget.Latest, !0);
|
264
|
+
function i(m) {
|
265
|
+
if (at.isVariableDeclaration(m) && m.name.getText() === t) {
|
266
|
+
const g = m.getStart(), h = m.getEnd();
|
267
|
+
clearTimeout(o), s([g, h]);
|
268
|
+
}
|
269
|
+
m.forEachChild(i);
|
270
|
+
}
|
271
|
+
i(r);
|
272
|
+
}), R = {
|
273
|
+
externalModules: [],
|
274
|
+
rcFile: void 0,
|
275
|
+
destDir: void 0
|
276
|
+
}, _t = (e) => {
|
277
|
+
if (R.externalModules.length > 0) return R.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 R.externalModules = n, n;
|
282
|
+
}, Z = async (e) => {
|
283
|
+
if (R.destDir) return R.destDir;
|
284
|
+
const t = await ut(e), s = u(e, (t == null ? void 0 : t.saltygenDir) || "saltygen");
|
285
|
+
return R.destDir = s, s;
|
286
|
+
}, xt = ["salty", "css", "styles", "styled"], se = (e = []) => new RegExp(`\\.(${[...xt, ...e].join("|")})\\.`), ft = (e, t = []) => se(t).test(e), Tt = async (e) => {
|
287
|
+
if (R.rcFile) return R.rcFile;
|
288
|
+
if (e === "/") throw new Error("Could not find .saltyrc.json file");
|
289
|
+
const t = u(e, ".saltyrc.json"), s = await wt(t, "utf-8").then(JSON.parse).catch(() => {
|
290
|
+
});
|
291
|
+
return s ? (R.rcFile = s, s) : Tt(u(e, ".."));
|
292
|
+
}, ut = async (e) => {
|
293
|
+
var n, o;
|
294
|
+
const t = await Tt(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
|
+
}, ne = async (e) => {
|
297
|
+
const t = await ut(e), s = await Z(e), n = u(e, (t == null ? void 0 : t.configDir) || "", "salty.config.ts"), o = u(s, "salty.config.js"), r = await Pt(e), i = _t(n);
|
298
|
+
await bt.build({
|
299
|
+
entryPoints: [n],
|
300
|
+
minify: !0,
|
301
|
+
treeShaking: !0,
|
302
|
+
bundle: !0,
|
303
|
+
outfile: o,
|
304
|
+
format: r,
|
305
|
+
external: i
|
306
|
+
});
|
307
|
+
const m = Date.now(), { config: g } = await import(`${o}?t=${m}`);
|
308
|
+
return { config: g, path: o };
|
309
|
+
}, oe = async (e, t) => {
|
310
|
+
var mt, ht;
|
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: J } = await nt(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};;${J}`));
|
322
|
+
});
|
323
|
+
})
|
324
|
+
);
|
325
|
+
const { config: o, path: r } = await ne(e), i = { ...o }, m = /* @__PURE__ */ new Set(), g = (S, F = []) => S ? Object.entries(S).flatMap(([J, E]) => {
|
326
|
+
if (!E) return;
|
327
|
+
if (typeof E == "object") return g(E, [...F, J]);
|
328
|
+
const V = Nt(J), ot = A(J), rt = [...F, V].join(".");
|
329
|
+
m.add(`"${rt}"`);
|
330
|
+
const Y = [...F.map(A), ot].join("-"), gt = Zt(E);
|
331
|
+
return gt ? `--${Y}: ${gt.transformed};` : `--${Y}: ${E};`;
|
332
|
+
}) : [], h = (S) => S ? Object.entries(S).flatMap(([F, J]) => {
|
333
|
+
const E = g(J);
|
334
|
+
return F === "base" ? E.join("") : `${F} { ${E.join("")} }`;
|
335
|
+
}) : [], l = (S) => S ? Object.entries(S).flatMap(([F, J]) => Object.entries(J).flatMap(([E, V]) => {
|
336
|
+
const ot = g(V, [F]), rt = `.${F}-${E}, [data-${F}="${E}"]`, Y = ot.join("");
|
337
|
+
return `${rt} { ${Y} }`;
|
338
|
+
})) : [], y = (S) => ({ ...S, responsive: void 0, conditional: void 0 }), d = (S) => n.variables.map((F) => S === "static" ? y(F._current) : F._current[S]), w = G(y(o.variables), d("static")), p = g(w), f = G((mt = o.variables) == null ? void 0 : mt.responsive, d("responsive")), b = h(f), P = G((ht = o.variables) == null ? void 0 : ht.conditional, d("conditional")), _ = l(P), O = u(s, "css/_variables.css"), v = `:root { ${p.join("")} ${b.join("")} } ${_.join("")}`;
|
339
|
+
x(O, v), i.staticVariables = w;
|
340
|
+
const T = u(s, "css/_global.css"), D = G(o.global, n.globalStyles), a = await B(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 B(c, "");
|
343
|
+
x($, `@layer reset { ${C} }`);
|
344
|
+
const N = u(s, "css/_templates.css"), k = G(o.templates, n.templates), z = await St(k), K = Lt(k);
|
345
|
+
x(N, `@layer templates { ${z} }`), i.templates = k;
|
346
|
+
const L = o.templates ? [te(o.templates)._setPath(`config;;${r}`)] : [], q = Ut(n.templates, L);
|
347
|
+
i.templatePaths = Object.fromEntries(Object.entries(q).map(([S, F]) => [S, F._path]));
|
348
|
+
const { mediaQueries: U } = n;
|
349
|
+
i.mediaQueries = Object.fromEntries(U.map(([S, F]) => [`@${S}`, F]));
|
350
|
+
const Q = U.map(([S]) => `'@${S}'`).join(" | "), X = u(s, "types/css-tokens.d.ts"), Dt = `
|
351
|
+
// Variable types
|
352
|
+
type VariableTokens = ${[...m].join("|")};
|
353
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
354
|
+
|
355
|
+
// Template types
|
356
|
+
type TemplateTokens = {
|
357
|
+
${Object.entries(K).map(([S, F]) => `${S}?: ${F}`).join(`
|
358
|
+
`)}
|
359
|
+
}
|
360
|
+
|
361
|
+
// Media query types
|
362
|
+
type MediaQueryKeys = ${Q || "''"};
|
363
|
+
`;
|
364
|
+
x(X, Dt);
|
365
|
+
const kt = u(s, "cache/config-cache.json");
|
366
|
+
x(kt, JSON.stringify(i, null, 2));
|
367
|
+
}, $t = (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 (xt.some((h) => m == null ? void 0 : m.includes(h))) return t;
|
375
|
+
}
|
376
|
+
return "styled('div',";
|
377
|
+
}), re = (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
|
+
}, nt = async (e, t, s) => {
|
389
|
+
const n = W(t), o = u(s, "./temp");
|
390
|
+
lt(o) || I(o);
|
391
|
+
const r = st(t);
|
392
|
+
let i = M(t, "utf8");
|
393
|
+
i = $t(i), i = re(i, e);
|
394
|
+
const m = u(s, "js", n + ".js"), g = await ut(e), h = u(e, (g == null ? void 0 : g.configDir) || "", "salty.config.ts"), l = _t(h), y = await Pt(e);
|
395
|
+
await bt.build({
|
396
|
+
stdin: {
|
397
|
+
contents: i,
|
398
|
+
sourcefile: r.base,
|
399
|
+
resolveDir: r.dir,
|
400
|
+
loader: "tsx"
|
401
|
+
},
|
402
|
+
minify: !1,
|
403
|
+
treeShaking: !0,
|
404
|
+
bundle: !0,
|
405
|
+
outfile: m,
|
406
|
+
format: y,
|
407
|
+
target: ["node20"],
|
408
|
+
keepNames: !0,
|
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 b = M(f.path, "utf8");
|
417
|
+
return { contents: $t(b), loader: "ts" };
|
418
|
+
});
|
419
|
+
}
|
420
|
+
}
|
421
|
+
]
|
422
|
+
});
|
423
|
+
const d = Date.now();
|
424
|
+
return { contents: await import(`${m}?t=${d}`), outputFilePath: m };
|
425
|
+
}, ie = 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
|
+
}, pt = async (e) => {
|
430
|
+
const t = await ie(e), s = await Z(e), n = u(s, "salty.config.js"), o = Date.now(), { config: r } = await import(`${n}?t=${o}`);
|
431
|
+
return G(r, t);
|
432
|
+
}, dt = () => {
|
433
|
+
try {
|
434
|
+
return process.env.NODE_ENV === "production";
|
435
|
+
} catch {
|
436
|
+
return !1;
|
437
|
+
}
|
438
|
+
}, he = async (e, t = dt(), s = !0) => {
|
439
|
+
try {
|
440
|
+
const n = Date.now();
|
441
|
+
t ? ct.info("Generating CSS in production mode! 🔥") : ct.info("Generating CSS in development mode! 🚀");
|
442
|
+
const o = [], r = [], i = await Z(e), m = u(i, "index.css");
|
443
|
+
s && (() => {
|
444
|
+
lt(i) && Vt("rm -rf " + i), I(i, { recursive: !0 }), I(u(i, "css")), I(u(i, "types")), I(u(i, "js")), I(u(i, "cache"));
|
445
|
+
})();
|
446
|
+
const h = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Set();
|
447
|
+
async function y(a) {
|
448
|
+
const $ = ["node_modules", "saltygen"], j = Mt(a);
|
449
|
+
if (j.isDirectory()) {
|
450
|
+
const c = vt(a);
|
451
|
+
if ($.some((N) => a.includes(N))) return;
|
452
|
+
await Promise.all(c.map((N) => y(u(a, N))));
|
453
|
+
} else if (j.isFile() && ft(a)) {
|
454
|
+
h.add(a);
|
455
|
+
const C = M(a, "utf8");
|
456
|
+
/define[\w\d]+\(/.test(C) && l.add(a);
|
457
|
+
}
|
458
|
+
}
|
459
|
+
await y(e), await oe(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 nt(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 w = await pt(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: w
|
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), w.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: w
|
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), w.importStrategy === "component" && p[$].push(c.cssFileName);
|
517
|
+
}
|
518
|
+
w.importStrategy === "component" && Object.entries(p).forEach(([a, $]) => {
|
519
|
+
const j = $.map((z) => `@import url('./${z}');`).join(`
|
520
|
+
`), c = W(a, 6), C = st(a), N = A(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(`
|
524
|
+
`);
|
525
|
+
let O = `@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
526
|
+
|
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(`
|
534
|
+
`)}
|
535
|
+
${f}`;
|
536
|
+
if (w.importStrategy !== "component") {
|
537
|
+
const a = r.reduce(($, j, c) => {
|
538
|
+
const C = j.reduce((K, L) => {
|
539
|
+
var X;
|
540
|
+
const q = u(i, "css", L), U = M(q, "utf8"), Q = ((X = /.*-([^-]+)-\d+.css/.exec(L)) == null ? void 0 : X.at(1)) || W(q, 6);
|
541
|
+
return K.includes(Q) ? K : `${K}
|
542
|
+
/*start:${Q}-${L}*/
|
543
|
+
${U}
|
544
|
+
/*end:${Q}*/
|
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;
|
552
|
+
}
|
553
|
+
x(m, O);
|
554
|
+
const T = Date.now() - n, D = T < 200 ? "🔥" : T < 500 ? "🚀" : T < 1e3 ? "🎉" : T < 2e3 ? "🚗" : T < 5e3 ? "🤔" : "🥴";
|
555
|
+
ct.info(`Generated CSS in ${T}ms! ${D}`);
|
556
|
+
} catch (n) {
|
557
|
+
console.error(n);
|
558
|
+
}
|
559
|
+
}, ge = async (e, t, s = dt()) => {
|
560
|
+
try {
|
561
|
+
const n = await Z(e);
|
562
|
+
if (ft(t)) {
|
563
|
+
const r = [], i = await pt(e), { contents: m } = await nt(e, t, n);
|
564
|
+
for (const [g, h] of Object.entries(m)) {
|
565
|
+
if (h.isKeyframes && h.css) {
|
566
|
+
const f = `css/${`a_${h.animationName}.css`}`, b = u(n, f);
|
567
|
+
x(b, await h.css);
|
568
|
+
return;
|
569
|
+
}
|
570
|
+
if (h.isClassName) {
|
571
|
+
const p = h.generator._withBuildContext({
|
572
|
+
callerName: g,
|
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 b = `css/${p.cssFileName}`, P = u(n, b);
|
579
|
+
x(P, f);
|
580
|
+
}
|
581
|
+
if (!h.generator) return;
|
582
|
+
const l = h.generator._withBuildContext({
|
583
|
+
callerName: g,
|
584
|
+
isProduction: s,
|
585
|
+
config: i
|
586
|
+
}), y = await l.css;
|
587
|
+
if (!y) continue;
|
588
|
+
const d = `css/${l.cssFileName}`, w = u(n, d);
|
589
|
+
x(w, y), r[l.priority] || (r[l.priority] = []), r[l.priority].push(l.cssFileName);
|
590
|
+
}
|
591
|
+
if (i.importStrategy !== "component")
|
592
|
+
r.forEach((g, h) => {
|
593
|
+
const l = `l_${h}.css`, y = u(n, "css", l);
|
594
|
+
let d = M(y, "utf8");
|
595
|
+
g.forEach((w) => {
|
596
|
+
var P;
|
597
|
+
const p = u(n, "css", w), f = ((P = /.*-([^-]+)-\d+.css/.exec(w)) == null ? void 0 : P.at(1)) || W(p, 6);
|
598
|
+
if (!d.includes(f)) {
|
599
|
+
const _ = M(p, "utf8"), O = `/*start:${f}-${w}*/
|
600
|
+
${_}
|
601
|
+
/*end:${f}*/
|
602
|
+
`;
|
603
|
+
d = `${d.replace(/\}$/, "")}
|
604
|
+
${O}
|
605
|
+
}`;
|
606
|
+
}
|
607
|
+
}), x(y, d);
|
608
|
+
});
|
609
|
+
else {
|
610
|
+
const g = r.flat().map((w) => `@import url('./${w}');`).join(`
|
611
|
+
`), h = W(t, 6), l = st(t), y = A(l.name), d = u(n, `css/f_${y}-${h}.css`);
|
612
|
+
x(d, g || "/* Empty file */");
|
613
|
+
}
|
614
|
+
}
|
615
|
+
} catch (n) {
|
616
|
+
console.error(n);
|
617
|
+
}
|
618
|
+
}, ye = async (e, t, s = dt()) => {
|
619
|
+
var n, o;
|
620
|
+
try {
|
621
|
+
const r = await Z(e);
|
622
|
+
if (ft(t)) {
|
623
|
+
const m = M(t, "utf8"), g = await pt(e), { contents: h } = await nt(e, t, r);
|
624
|
+
let l = m;
|
625
|
+
for (const [y, d] of Object.entries(h)) {
|
626
|
+
if (d.isKeyframes || !d.generator) continue;
|
627
|
+
const w = d.generator._withBuildContext({
|
628
|
+
callerName: y,
|
629
|
+
isProduction: s,
|
630
|
+
config: g
|
631
|
+
}), [p, f] = await ee(l, y), b = l.slice(p, f);
|
632
|
+
if (d.isClassName) {
|
633
|
+
const P = l, _ = ` ${y} = className("${w.classNames}")`;
|
634
|
+
l = l.replace(b, _), P === l && console.error("Minimize file failed to change content", { name: y });
|
635
|
+
}
|
636
|
+
if (b.includes("styled")) {
|
637
|
+
const P = (o = (n = /styled\(([^,]+),/.exec(b)) == null ? void 0 : n.at(1)) == null ? void 0 : o.trim(), _ = l, O = ` ${y} = styled(${P}, "${w.classNames}", ${JSON.stringify(w.clientProps)})`;
|
638
|
+
l = l.replace(b, O), _ === l && console.error("Minimize file failed to change content", { name: y, tagName: P });
|
639
|
+
}
|
640
|
+
}
|
641
|
+
if (g.importStrategy === "component") {
|
642
|
+
const y = W(t, 6), d = st(t);
|
643
|
+
l = `import '../../saltygen/css/${`f_${A(d.name)}-${y}.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;
|
647
|
+
}
|
648
|
+
} catch (r) {
|
649
|
+
console.error("Error in minimizeFile:", r);
|
650
|
+
}
|
651
|
+
};
|
652
|
+
export {
|
653
|
+
ge as a,
|
654
|
+
he as g,
|
655
|
+
ft as i,
|
656
|
+
ye as m,
|
657
|
+
se as s
|
658
|
+
};
|
package/index.cjs
CHANGED
@@ -1,15 +1 @@
|
|
1
|
-
"use strict";Object.
|
2
|
-
${f.replace(`
|
3
|
-
`,`
|
4
|
-
`)}
|
5
|
-
}`;return r.push(i),l}const j=$.includes("&")?y.replace("&",s):y.startsWith(":")?`${s}${y}`:`${s} ${y}`,d=k(o,j);return r.push(d),l}const g=y.startsWith("-")?y:V(y),w=(j,d=";")=>l=`${l}${j}${d}`,O=j=>w(`${g}:${j}`);if(typeof o=="number")return O(o);if(typeof o!="string")if("toString"in o)o=o.toString();else return l;const{modifiers:C}={},D=function*(){yield M(o),yield G(o,C)}();for(const{result:j,additionalCss:d=[]}of D)o=j,d.forEach(f=>{const i=k(f,"");w(i,"")});return O(o)},"");if(!a)return r.join(`
|
6
|
-
`);if(!s)return a;let b="";return b=`${s} { ${a} }`,[b,...r].join(`
|
7
|
-
`)},_=(t,s=[])=>{if(!t)return"";const e=[],n={};if(Object.entries(t).forEach(([r,a])=>{if(typeof a=="object"){if(!a)return;const b=r.trim(),l=_(a,[...s,b]);e.push(l)}else n[r]=a}),Object.keys(n).length){const r=s.map(V).join("-"),a=k(n,`.${r}`);e.push(a)}return e.join(`
|
8
|
-
`)},N=t=>u.join(t,"./saltygen"),J=["salty","css","styles","styled"],q=(t=[])=>new RegExp(`\\.(${[...J,...t].join("|")})\\.`),K=(t,s=[])=>q(s).test(t),L=async t=>{const s=N(t),e=u.join(t,"salty.config.ts"),n=u.join(s,"salty.config.js");await x.build({entryPoints:[e],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:"esm",external:["react"]});const r=Date.now(),{config:a}=await import(`${n}?t=${r}`);return a},U=async t=>{const s=await L(t),e=new Set,n=(f,i=[])=>f?Object.entries(f).flatMap(([p,c])=>{if(!c)return;if(typeof c=="object")return n(c,[...i,p]);const h=[...i,p].join(".");e.add(`"${h}"`);const S=[...i.map(V),V(p)].join("-"),{result:P}=M(c);return`--${S}: ${P};`}):[],r=f=>f?Object.entries(f).flatMap(([i,p])=>{const c=n(p);return i==="base"?c.join(""):`${i} { ${c.join("")} }`}):[],a=f=>f?Object.entries(f).flatMap(([i,p])=>Object.entries(p).flatMap(([c,h])=>{const S=n(h,[i]),P=`.${i}-${c}, [data-${i}="${c}"]`,T=S.join("");return`${P} { ${T} }`})):[],b=n(s.variables),l=r(s.responsiveVariables),$=a(s.conditionalVariables),o=N(t),y=u.join(o,"css/variables.css"),g=`:root { ${b.join("")} ${l.join("")} } ${$.join("")}`;m.writeFileSync(y,g);const w=u.join(o,"types/css-tokens.d.ts"),C=`type VariableTokens = ${[...e].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;m.writeFileSync(w,C);const F=u.join(o,"css/global.css"),D=k(s.global,"");m.writeFileSync(F,D);const j=u.join(o,"css/templates.css"),d=_(s.templates);m.writeFileSync(j,d)},X=async(t,s)=>{const e=A(t),n=u.join(s,"js",e+".js");await x.build({entryPoints:[t],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:"esm",target:["es2022"],keepNames:!0,external:["react"]});const r=Date.now();return await import(`${n}?t=${r}`)},Y=async t=>{const s=N(t),e=u.join(s,"salty.config.js"),{config:n}=await import(e);return n},Q=async t=>{try{const s=[],e=[],n=N(t),r=u.join(n,"index.css");(()=>{m.existsSync(n)&&W.execSync("rm -rf "+n),m.mkdirSync(n),m.mkdirSync(u.join(n,"css")),m.mkdirSync(u.join(n,"types"))})(),await U(t);const b=await Y(t);async function l(g,w){const O=m.statSync(g);if(O.isDirectory()){const C=m.readdirSync(g);await Promise.all(C.map(F=>l(u.join(g,F),u.join(w,F))))}else if(O.isFile()&&K(g)){const F=await X(g,n),D=[];Object.entries(F).forEach(([i,p])=>{if(p.isKeyframes&&p.css){const T=`${p.animationName}.css`,Z=`css/${T}`,R=u.join(n,Z);s.push(T),m.writeFileSync(R,p.css);return}if(!p.generator)return;const c=p.generator._withBuildContext({name:i,config:b}),h=`${c.hash}-${c.priority}.css`;e[c.priority]||(e[c.priority]=[]),e[c.priority].push(h),D.push(h);const S=`css/${h}`,P=u.join(n,S);m.writeFileSync(P,c.css)});const j=D.map(i=>`@import url('./${i}');`).join(`
|
9
|
-
`),d=A(g,6),f=u.join(n,`css/${d}.css`);m.writeFileSync(f,j)}}await l(t,n);const $=s.map(g=>`@import url('./css/${g}');`).join(`
|
10
|
-
`);let y=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
11
|
-
|
12
|
-
${["@import url('./css/variables.css');","@import url('./css/global.css');","@import url('./css/templates.css');"].join(`
|
13
|
-
`)}
|
14
|
-
${$}`;if(b.importStrategy!=="component"){const g=e.flat().map(w=>`@import url('./css/${w}');`).join(`
|
15
|
-
`);y+=g}m.writeFileSync(r,y)}catch(s){console.error(s)}},v=(t,s)=>{var e,n,r;(n=(e=t.module)==null?void 0:e.rules)==null||n.push({test:q(),use:[{loader:u.resolve("./loader.js"),options:{dir:s}}]}),(r=t.plugins)==null||r.push({apply:a=>{a.hooks.afterPlugins.tap({name:"generateCss"},async()=>{await Q(s)})}})};exports.saltyPlugin=v;
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("path"),t=require("./index-BLikDM5S.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;
|