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