@salty-css/webpack 0.0.1-alpha.253 → 0.0.1-alpha.255
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 +1 -1
- package/{index-BKx-Znt3.js → index-Da-_jI3O.js} +69 -69
- package/index-vma-mOTH.cjs +46 -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-CCi9INHt.cjs +0 -46
package/README.md
CHANGED
@@ -242,7 +242,7 @@ Example usage:
|
|
242
242
|
styled('span', {
|
243
243
|
base: {
|
244
244
|
// Use of static font family variable
|
245
|
-
fontFamily: '{
|
245
|
+
fontFamily: '{fontFamily.heading}',
|
246
246
|
// Use of responsive font size variable
|
247
247
|
fontSize: '{fontSize.heading.regular}',
|
248
248
|
// Use of conditional theme text color variable
|
@@ -6,7 +6,7 @@ import { execSync as Wt } from "child_process";
|
|
6
6
|
import { join as u, parse as ot } from "path";
|
7
7
|
import { existsSync as dt, writeFileSync as T, readFileSync as J, mkdirSync as K, statSync as zt, readdirSync as At } from "fs";
|
8
8
|
import { readFile as Ft } from "fs/promises";
|
9
|
-
import { createLogger as Gt,
|
9
|
+
import { createLogger as Gt, transports as Ht, format as ut } from "winston";
|
10
10
|
import pt from "typescript";
|
11
11
|
const Ct = (e) => String.fromCharCode(e + (e > 25 ? 39 : 97)), It = (e, t) => {
|
12
12
|
let s = "", n;
|
@@ -61,8 +61,8 @@ const Kt = (e) => (t) => {
|
|
61
61
|
], Zt = (e, t, s) => Bt.some((o) => typeof o == "string" ? o === e : o.test(e)) ? `${t}px` : `${t}`, qt = ["Webkit", "Moz", "ms", "O"], Ut = (e) => e.startsWith("-") ? e : qt.some((t) => e.startsWith(t)) ? `-${R(e)}` : R(e), nt = async (e, t = "", s, n = !1) => {
|
62
62
|
if (!e) throw new Error("No styles provided to parseStyles function!");
|
63
63
|
const o = /* @__PURE__ */ new Set(), r = Object.entries(e), i = async ([p, f]) => {
|
64
|
-
const g = p.trim(), P = Ut(g), _ = (
|
65
|
-
if (typeof f == "function") return i([p, f(
|
64
|
+
const g = p.trim(), P = Ut(g), _ = (v, z = ";") => `${P}:${v}${z}`, O = { scope: t, config: s };
|
65
|
+
if (typeof f == "function") return i([p, f(O)]);
|
66
66
|
if (f instanceof Promise) return i([p, await f]);
|
67
67
|
if (typeof f == "object") {
|
68
68
|
if (!f) return;
|
@@ -70,36 +70,36 @@ const Kt = (e) => (t) => {
|
|
70
70
|
if (g === "defaultVariants") return;
|
71
71
|
if (g === "variants") {
|
72
72
|
const F = Object.entries(f);
|
73
|
-
for (const [
|
73
|
+
for (const [V, l] of F) {
|
74
74
|
if (!l) continue;
|
75
75
|
const w = Object.entries(l);
|
76
76
|
for (const [C, a] of w) {
|
77
77
|
if (!a) continue;
|
78
|
-
const j = `${t}.${
|
79
|
-
(await nt(a, j, s)).forEach((
|
78
|
+
const j = `${t}.${V}-${C}`;
|
79
|
+
(await nt(a, j, s)).forEach((M) => o.add(M));
|
80
80
|
}
|
81
81
|
}
|
82
82
|
return;
|
83
83
|
}
|
84
84
|
if (g === "compoundVariants") {
|
85
85
|
for (const F of f) {
|
86
|
-
const { css:
|
87
|
-
(await nt(
|
86
|
+
const { css: V, ...l } = F, w = Object.entries(l).reduce((a, [j, N]) => `${a}.${j}-${N}`, t);
|
87
|
+
(await nt(V, w, s)).forEach((a) => o.add(a));
|
88
88
|
}
|
89
89
|
return;
|
90
90
|
}
|
91
91
|
if (g.startsWith("@")) {
|
92
|
-
const F = g,
|
92
|
+
const F = g, V = await Y(f, t, s), l = `${F} { ${V} }`;
|
93
93
|
o.add(l);
|
94
94
|
return;
|
95
95
|
}
|
96
|
-
const
|
97
|
-
(await nt(f,
|
96
|
+
const v = p.includes("&") ? g.replaceAll("&", t) : g.startsWith(":") ? `${t}${g}` : `${t} ${g}`;
|
97
|
+
(await nt(f, v, s)).forEach((F) => o.add(F));
|
98
98
|
return;
|
99
99
|
}
|
100
100
|
if (typeof f == "number") {
|
101
|
-
const
|
102
|
-
return _(
|
101
|
+
const v = Zt(P, f);
|
102
|
+
return _(v);
|
103
103
|
}
|
104
104
|
if (typeof f != "string")
|
105
105
|
if ("toString" in f) f = f.toString();
|
@@ -109,14 +109,14 @@ const Kt = (e) => (t) => {
|
|
109
109
|
p.map((f) => m.reduce(async (g, P) => {
|
110
110
|
const _ = await g;
|
111
111
|
if (!_) return _;
|
112
|
-
const
|
113
|
-
if (!
|
114
|
-
const { transformed:
|
112
|
+
const O = await P(_);
|
113
|
+
if (!O) return _;
|
114
|
+
const { transformed: v, additionalCss: z } = O;
|
115
115
|
let F = "";
|
116
116
|
if (z)
|
117
|
-
for (const
|
118
|
-
F += await Y(
|
119
|
-
return `${F}${
|
117
|
+
for (const V of z)
|
118
|
+
F += await Y(V, "");
|
119
|
+
return `${F}${v}`;
|
120
120
|
}, Promise.resolve(f)))
|
121
121
|
))).filter((p) => p !== void 0).join(`
|
122
122
|
`);
|
@@ -167,8 +167,8 @@ const Dt = async (e) => {
|
|
167
167
|
format: ut.combine(ut.colorize(), ut.cli()),
|
168
168
|
transports: [new Ht.Console({})]
|
169
169
|
});
|
170
|
-
function
|
171
|
-
return e ? typeof e != "string" ?
|
170
|
+
function vt(e) {
|
171
|
+
return e ? typeof e != "string" ? vt(String(e)) : e.replace(/[^\d\w]/g, ".") : "";
|
172
172
|
}
|
173
173
|
const ee = {
|
174
174
|
/** Set box model to border-box */
|
@@ -276,7 +276,7 @@ const re = (e) => new oe(e), ie = (e, t) => new Promise((s, n) => {
|
|
276
276
|
externalModules: [],
|
277
277
|
rcFile: void 0,
|
278
278
|
destDir: void 0
|
279
|
-
},
|
279
|
+
}, kt = (e) => {
|
280
280
|
if (W.externalModules.length > 0) return W.externalModules;
|
281
281
|
const s = J(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
282
282
|
if (!s) return [];
|
@@ -286,18 +286,18 @@ const re = (e) => new oe(e), ie = (e, t) => new Promise((s, n) => {
|
|
286
286
|
if (W.destDir) return W.destDir;
|
287
287
|
const t = await yt(e), s = u(e, (t == null ? void 0 : t.saltygenDir) || "saltygen");
|
288
288
|
return W.destDir = s, s;
|
289
|
-
},
|
289
|
+
}, Et = ["salty", "css", "styles", "styled"], ae = (e = []) => new RegExp(`\\.(${[...Et, ...e].join("|")})\\.`), ht = (e, t = []) => ae(t).test(e), Ot = async (e) => {
|
290
290
|
if (W.rcFile) return W.rcFile;
|
291
291
|
if (e === "/") throw new Error("Could not find .saltyrc.json file");
|
292
292
|
const t = u(e, ".saltyrc.json"), s = await Ft(t, "utf-8").then(JSON.parse).catch(() => {
|
293
293
|
});
|
294
|
-
return s ? (W.rcFile = s, s) :
|
294
|
+
return s ? (W.rcFile = s, s) : Ot(u(e, ".."));
|
295
295
|
}, yt = async (e) => {
|
296
296
|
var n, o;
|
297
|
-
const t = await
|
297
|
+
const t = await Ot(e), s = (n = t.projects) == null ? void 0 : n.find((r) => e.endsWith(r.dir || ""));
|
298
298
|
return s || ((o = t.projects) == null ? void 0 : o.find((r) => r.dir === t.defaultProject));
|
299
299
|
}, ce = async (e) => {
|
300
|
-
const t = await yt(e), s = await I(e), n = u(e, (t == null ? void 0 : t.configDir) || "", "salty.config.ts"), o = u(s, "salty.config.js"), r = await Dt(e), i =
|
300
|
+
const t = await yt(e), s = await I(e), n = u(e, (t == null ? void 0 : t.configDir) || "", "salty.config.ts"), o = u(s, "salty.config.js"), r = await Dt(e), i = kt(n);
|
301
301
|
await Pt.build({
|
302
302
|
entryPoints: [n],
|
303
303
|
minify: !0,
|
@@ -320,8 +320,8 @@ const re = (e) => new oe(e), ie = (e, t) => new Promise((s, n) => {
|
|
320
320
|
await Promise.all(
|
321
321
|
[...t].map(async (S) => {
|
322
322
|
const { contents: x, outputFilePath: U } = await rt(e, S, s);
|
323
|
-
Object.entries(x).forEach(([
|
324
|
-
D.isMedia ? n.mediaQueries.push([
|
323
|
+
Object.entries(x).forEach(([k, D]) => {
|
324
|
+
D.isMedia ? n.mediaQueries.push([k, D]) : D.isGlobalDefine ? n.globalStyles.push(D) : D.isDefineVariables ? n.variables.push(D) : D.isDefineTemplates && n.templates.push(D._setPath(`${k};;${U}`));
|
325
325
|
});
|
326
326
|
})
|
327
327
|
);
|
@@ -330,47 +330,47 @@ const re = (e) => new oe(e), ie = (e, t) => new Promise((s, n) => {
|
|
330
330
|
const $ = d.map(([S]) => `'@${S}'`).join(" | "), m = /* @__PURE__ */ new Set(), c = async (S, x = []) => {
|
331
331
|
if (!S) return [];
|
332
332
|
const U = Object.entries(S).map(async ([D, G]) => {
|
333
|
-
const X = async (
|
334
|
-
if (!
|
335
|
-
if (
|
336
|
-
if (typeof
|
337
|
-
if (typeof
|
338
|
-
const ct =
|
333
|
+
const X = async (E) => {
|
334
|
+
if (!E) return;
|
335
|
+
if (E instanceof Promise) return await X(await E);
|
336
|
+
if (typeof E == "function") return await X(await E());
|
337
|
+
if (typeof E == "object") return await c(E, [...x, D]);
|
338
|
+
const ct = vt(D), lt = R(D), ft = [...x, ct].join(".");
|
339
339
|
m.add(`"${ft}"`);
|
340
|
-
const et = [...x.map(R), lt].join("-"), St = Lt(
|
341
|
-
return St ? `--${et}: ${St.transformed};` : `--${et}: ${
|
340
|
+
const et = [...x.map(R), lt].join("-"), St = Lt(E);
|
341
|
+
return St ? `--${et}: ${St.transformed};` : `--${et}: ${E};`;
|
342
342
|
};
|
343
343
|
return await X(G);
|
344
344
|
});
|
345
345
|
return (await Promise.all(U)).flat();
|
346
346
|
}, y = async (S) => {
|
347
347
|
if (!S) return [];
|
348
|
-
const x = Object.entries(S).map(async ([
|
348
|
+
const x = Object.entries(S).map(async ([k, D]) => {
|
349
349
|
const G = await c(D);
|
350
|
-
return
|
350
|
+
return k === "base" ? G.join("") : i.mediaQueries[k] ? `${i.mediaQueries[k]} { ${G.join("")} }` : `${k} { ${G.join("")} }`;
|
351
351
|
});
|
352
352
|
return (await Promise.all(x)).flat();
|
353
353
|
}, h = async (S) => {
|
354
354
|
if (!S) return [];
|
355
|
-
const x = Object.entries(S).map(async ([
|
356
|
-
const G = Object.entries(D).map(async ([
|
357
|
-
const lt = await c(ct, [
|
355
|
+
const x = Object.entries(S).map(async ([k, D]) => {
|
356
|
+
const G = Object.entries(D).map(async ([E, ct]) => {
|
357
|
+
const lt = await c(ct, [k]), ft = `.${k}-${E}, [data-${k}="${E}"]`, et = lt.join("");
|
358
358
|
return `${ft} { ${et} }`;
|
359
359
|
});
|
360
360
|
return (await Promise.all(G)).flat();
|
361
361
|
});
|
362
362
|
return (await Promise.all(x)).flat();
|
363
|
-
}, b = (S) => ({ ...S, responsive: void 0, conditional: void 0 }), p = (S) => n.variables.map((x) => S === "static" ? b(x._current) : x._current[S]), f = L(b(o.variables), p("static")), g = await c(f), P = L((wt = o.variables) == null ? void 0 : wt.responsive, p("responsive")), _ = await y(P),
|
363
|
+
}, b = (S) => ({ ...S, responsive: void 0, conditional: void 0 }), p = (S) => n.variables.map((x) => S === "static" ? b(x._current) : x._current[S]), f = L(b(o.variables), p("static")), g = await c(f), P = L((wt = o.variables) == null ? void 0 : wt.responsive, p("responsive")), _ = await y(P), O = L((bt = o.variables) == null ? void 0 : bt.conditional, p("conditional")), v = await h(O), z = u(s, "css/_variables.css"), F = `:root { ${g.join("")} ${_.join("")} } ${v.join("")}`;
|
364
364
|
T(z, F), i.staticVariables = f;
|
365
|
-
const
|
366
|
-
T(
|
365
|
+
const V = u(s, "css/_global.css"), l = L(o.global, n.globalStyles), w = await Y(l, "");
|
366
|
+
T(V, `@layer global { ${w} }`);
|
367
367
|
const C = u(s, "css/_reset.css"), j = o.reset === "none" ? {} : typeof o.reset == "object" ? o.reset : ee, N = await Y(j, "");
|
368
368
|
T(C, `@layer reset { ${N} }`);
|
369
|
-
const
|
370
|
-
T(
|
369
|
+
const M = u(s, "css/_templates.css"), A = L(o.templates, n.templates), B = await xt(A), Z = Xt(A);
|
370
|
+
T(M, `@layer templates { ${B} }`), i.templates = A;
|
371
371
|
const tt = o.templates ? [re(o.templates)._setPath(`config;;${r}`)] : [], it = se(n.templates, tt);
|
372
372
|
i.templatePaths = Object.fromEntries(Object.entries(it).map(([S, x]) => [S, x._path]));
|
373
|
-
const q = u(s, "types/css-tokens.d.ts"),
|
373
|
+
const q = u(s, "types/css-tokens.d.ts"), Vt = `
|
374
374
|
// Variable types
|
375
375
|
type VariableTokens = ${[...m].join("|")};
|
376
376
|
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
@@ -384,9 +384,9 @@ const re = (e) => new oe(e), ie = (e, t) => new Promise((s, n) => {
|
|
384
384
|
// Media query types
|
385
385
|
type MediaQueryKeys = ${$ || "''"};
|
386
386
|
`;
|
387
|
-
T(q,
|
388
|
-
const
|
389
|
-
T(
|
387
|
+
T(q, Vt);
|
388
|
+
const Mt = u(s, "cache/config-cache.json");
|
389
|
+
T(Mt, JSON.stringify(i, null, 2));
|
390
390
|
}, jt = (e) => e.replace(/styled\(([^"'`{,]+),/g, (t, s) => {
|
391
391
|
if (/^['"`]/.test(s)) return t;
|
392
392
|
const o = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
|
@@ -394,7 +394,7 @@ const re = (e) => new oe(e), ie = (e, t) => new Promise((s, n) => {
|
|
394
394
|
const i = o.exec(e);
|
395
395
|
if (i) {
|
396
396
|
const d = i.at(1);
|
397
|
-
if (
|
397
|
+
if (Et.some((m) => d == null ? void 0 : d.includes(m))) return t;
|
398
398
|
}
|
399
399
|
return "styled('div',";
|
400
400
|
}), fe = (e, t) => {
|
@@ -414,7 +414,7 @@ ${e}`;
|
|
414
414
|
const r = ot(t);
|
415
415
|
let i = J(t, "utf8");
|
416
416
|
i = jt(i), i = fe(i, e);
|
417
|
-
const d = u(s, "js", n + ".js"), $ = await yt(e), m = u(e, ($ == null ? void 0 : $.configDir) || "", "salty.config.ts"), c =
|
417
|
+
const d = u(s, "js", n + ".js"), $ = await yt(e), m = u(e, ($ == null ? void 0 : $.configDir) || "", "salty.config.ts"), c = kt(m), y = await Dt(e);
|
418
418
|
await Pt.build({
|
419
419
|
stdin: {
|
420
420
|
contents: i,
|
@@ -522,8 +522,8 @@ ${e}`;
|
|
522
522
|
const j = await a.css;
|
523
523
|
if (!j) continue;
|
524
524
|
r[a.priority].push(a.cssFileName);
|
525
|
-
const N = `css/${a.cssFileName}`,
|
526
|
-
T(
|
525
|
+
const N = `css/${a.cssFileName}`, M = u(i, N);
|
526
|
+
T(M, j), b.importStrategy === "component" && p[w].push(a.cssFileName);
|
527
527
|
}
|
528
528
|
for (const l of h.classNames) {
|
529
529
|
const { src: w, name: C } = l;
|
@@ -535,17 +535,17 @@ ${e}`;
|
|
535
535
|
}), j = await a.css;
|
536
536
|
if (!j) continue;
|
537
537
|
r[a.priority] || (r[a.priority] = []), r[a.priority].push(a.cssFileName);
|
538
|
-
const N = `css/${a.cssFileName}`,
|
539
|
-
T(
|
538
|
+
const N = `css/${a.cssFileName}`, M = u(i, N);
|
539
|
+
T(M, j), b.importStrategy === "component" && p[w].push(a.cssFileName);
|
540
540
|
}
|
541
541
|
b.importStrategy === "component" && Object.entries(p).forEach(([l, w]) => {
|
542
542
|
const C = w.map((A) => `@import url('./${A}');`).join(`
|
543
|
-
`), a = H(l, 6), j = ot(l), N = R(j.name),
|
544
|
-
T(
|
543
|
+
`), a = H(l, 6), j = ot(l), N = R(j.name), M = u(i, `css/f_${N}-${a}.css`);
|
544
|
+
T(M, C || "/* Empty file */");
|
545
545
|
});
|
546
546
|
const f = o.map((l) => `@import url('./css/${l}');`).join(`
|
547
547
|
`);
|
548
|
-
let
|
548
|
+
let v = `/*!
|
549
549
|
* Generated with Salty CSS (https://salty-css.dev)
|
550
550
|
* Do not edit this file directly
|
551
551
|
*/
|
@@ -572,16 +572,16 @@ ${f}`;
|
|
572
572
|
${it}
|
573
573
|
/*end:${q}*/
|
574
574
|
`;
|
575
|
-
}, ""), N = `l_${a}.css`,
|
575
|
+
}, ""), N = `l_${a}.css`, M = u(i, "css", N), A = `@layer l${a} { ${j}
|
576
576
|
}`;
|
577
|
-
return T(
|
577
|
+
return T(M, A), `${w}
|
578
578
|
@import url('./css/${N}');`;
|
579
579
|
}, "");
|
580
|
-
|
580
|
+
v += l;
|
581
581
|
}
|
582
|
-
T(d,
|
583
|
-
const F = Date.now() - n,
|
584
|
-
mt.info(`Generated CSS in ${F}ms! ${
|
582
|
+
T(d, v);
|
583
|
+
const F = Date.now() - n, V = F < 200 ? "🔥" : F < 500 ? "🚀" : F < 1e3 ? "🎉" : F < 2e3 ? "🚗" : F < 5e3 ? "🤔" : "🥴";
|
584
|
+
mt.info(`Generated CSS in ${F}ms! ${V}`);
|
585
585
|
} catch (n) {
|
586
586
|
console.error(n);
|
587
587
|
}
|
@@ -626,12 +626,12 @@ ${it}
|
|
626
626
|
var P;
|
627
627
|
const p = u(n, "css", b), f = ((P = /.*-([^-]+)-\d+.css/.exec(b)) == null ? void 0 : P.at(1)) || H(p, 6);
|
628
628
|
if (!h.includes(f)) {
|
629
|
-
const _ = J(p, "utf8"),
|
629
|
+
const _ = J(p, "utf8"), O = `/*start:${f}-${b}*/
|
630
630
|
${_}
|
631
631
|
/*end:${f}*/
|
632
632
|
`;
|
633
633
|
h = `${h.replace(/\}$/, "")}
|
634
|
-
${
|
634
|
+
${O}
|
635
635
|
}`;
|
636
636
|
}
|
637
637
|
}), T(y, h);
|
@@ -664,8 +664,8 @@ ${V}
|
|
664
664
|
c = c.replace(g, _), P === c && console.error("Minimize file failed to change content", { name: y });
|
665
665
|
}
|
666
666
|
if (g.includes("styled")) {
|
667
|
-
const P = (o = (n = /styled\(([^,]+),/.exec(g)) == null ? void 0 : n.at(1)) == null ? void 0 : o.trim(), _ = c,
|
668
|
-
c = c.replace(g,
|
667
|
+
const P = (o = (n = /styled\(([^,]+),/.exec(g)) == null ? void 0 : n.at(1)) == null ? void 0 : o.trim(), _ = c, O = ` ${y} = styled(${P}, "${b.classNames}", ${JSON.stringify(b.clientProps)})`;
|
668
|
+
c = c.replace(g, O), _ === c && console.error("Minimize file failed to change content", { name: y, tagName: P });
|
669
669
|
}
|
670
670
|
}
|
671
671
|
if ($.importStrategy === "component") {
|
@@ -0,0 +1,46 @@
|
|
1
|
+
"use strict";var Vt=Object.defineProperty;var Mt=(t,e,s)=>e in t?Vt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var et=(t,e,s)=>Mt(t,typeof e!="symbol"?e+"":e,s);const Rt=require("esbuild"),zt=require("child_process"),c=require("path"),p=require("fs"),St=require("fs/promises"),Z=require("winston"),ft=require("typescript");var ut=typeof document<"u"?document.currentScript:null;function Jt(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return e.default=t,Object.freeze(e)}const jt=Jt(Rt),$t=t=>String.fromCharCode(t+(t>25?39:97)),Wt=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=$t(n%52)+s;return s=$t(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},At=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},q=(t,e=5)=>{const s=At(5381,JSON.stringify(t))>>>0;return Wt(s,e)};function R(t){return t?typeof t!="string"?R(String(t)):t.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?"-":"")+e.toLowerCase()):""}const qt=t=>e=>{if(typeof e!="string"||!t)return;let s=e;const n=[];return Object.values(t).forEach(o=>{const{pattern:i,transform:r}=o;s=s.replace(i,y=>{const{value:$,css:m}=r(y);return m&&n.push(m),$})}),{transformed:s,additionalCss:n}},Ft=t=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...o)=>{const i=R(o[1].replaceAll(".","-"));return i.startsWith("-")?`-${i}`:`var(--${i})`})},It=Ft(),Gt=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Ht=(t,e,s)=>Gt.some(o=>typeof o=="string"?o===t:o.test(t))?`${e}px`:`${e}`,Lt=["Webkit","Moz","ms","O"],Qt=t=>t.startsWith("-")?t:Lt.some(e=>t.startsWith(e))?`-${R(t)}`:R(t),st=async(t,e="",s,n=!1)=>{if(!t)throw new Error("No styles provided to parseStyles function!");const o=new Set,i=Object.entries(t),r=async([d,u])=>{const w=d.trim(),P=Qt(w),T=(D,J=";")=>`${P}:${D}${J}`,O={scope:e,config:s};if(typeof u=="function")return r([d,u(O)]);if(u instanceof Promise)return r([d,await u]);if(typeof u=="object"){if(!u)return;if(u.isColor)return T(u.toString());if(w==="defaultVariants")return;if(w==="variants"){const N=Object.entries(u);for(const[V,f]of N){if(!f)continue;const b=Object.entries(f);for(const[F,a]of b){if(!a)continue;const C=`${e}.${V}-${F}`;(await st(a,C,s)).forEach(M=>o.add(M))}}return}if(w==="compoundVariants"){for(const N of u){const{css:V,...f}=N,b=Object.entries(f).reduce((a,[C,_])=>`${a}.${C}-${_}`,e);(await st(V,b,s)).forEach(a=>o.add(a))}return}if(w.startsWith("@")){const N=w,V=await X(u,e,s),f=`${N} { ${V} }`;o.add(f);return}const D=d.includes("&")?w.replaceAll("&",e):w.startsWith(":")?`${e}${w}`:`${e} ${w}`;(await st(u,D,s)).forEach(N=>o.add(N));return}if(typeof u=="number"){const D=Ht(P,u);return T(D)}if(typeof u!="string")if("toString"in u)u=u.toString();else throw new Error(`Invalid value type for property ${P}`);return T(u)},y=i.map(r),{modifiers:$}={},m=[Ft(),qt($)],g=(await Promise.all(y).then(d=>Promise.all(d.map(u=>m.reduce(async(w,P)=>{const T=await w;if(!T)return T;const O=await P(T);if(!O)return T;const{transformed:D,additionalCss:J}=O;let N="";if(J)for(const V of J)N+=await X(V,"");return`${N}${D}`},Promise.resolve(u)))))).filter(d=>d!==void 0).join(`
|
2
|
+
`);if(!g.trim())return Array.from(o);const h=e?`${e} {
|
3
|
+
${g}
|
4
|
+
}`:g;return o.has(h)?Array.from(o):[h,...o]},X=async(t,e,s,n=!1)=>(await st(t,e,s,n)).join(`
|
5
|
+
`),Ct=async(t,e=[])=>{if(!t)return"";const s=[],n={};for(const[o,i]of Object.entries(t))if(typeof i!="function")if(i&&typeof i=="object"){const r=o.trim(),y=await Ct(i,[...e,r]);s.push(y)}else n[o]=i;if(Object.keys(n).length){const o=e.map(R).join("-"),i="t_"+q(o,4),r=await X(n,`.${o}, .${i}`);s.push(r)}return s.join(`
|
6
|
+
`)},Kt=t=>t?Object.entries(t).reduce((e,[s,n])=>(typeof n=="function"?e[s]="any":typeof n=="object"&&(e[s]=Pt(n).map(o=>`"${o}"`).join(" | ")),e),{}):{},Pt=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const i=e?`${e}.${n}`:n;return typeof o=="object"?Pt(o,i,s):s.add(e)}),[...s]):[],Nt=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=c.join(t,"package.json");return p.existsSync(e)?e:Nt(c.join(t,".."))},Ut=async t=>{const e=Nt(t);return await St.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},Bt=async t=>{const e=await Ut(t);if(e)return e.type};let G;const _t=async t=>{if(G)return G;const e=await Bt(t);return e==="module"?G="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:ut&&ut.tagName.toUpperCase()==="SCRIPT"&&ut.src||new URL("index-vma-mOTH.cjs",document.baseURI).href).endsWith(".cjs"))&&(G="cjs"),G||"esm"},pt=Z.createLogger({level:"debug",format:Z.format.combine(Z.format.colorize(),Z.format.cli()),transports:[new Z.transports.Console({})]});function xt(t){return t?typeof t!="string"?xt(String(t)):t.replace(/[^\d\w]/g,"."):""}const Zt={"*, *::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"}},H=(...t)=>t.flat().reduce((e,s)=>s!=null&&s._current?{...e,...s._current}:{...e,...s},{}),Xt=(...t)=>t.flat().reduce((e,s)=>({...e,...s._children}),{});class Yt{constructor(e){et(this,"_path");this.params=e}get _current(){return this.params.template}get isDefineTemplate(){return!0}_setPath(e){return this._path=e,this}}class te{constructor(e){et(this,"_path");et(this,"templates",[]);this.params=e,Object.entries(e).forEach(([s,n])=>{this.templates.push(new Yt({name:s,template:n}))})}get _current(){return this.params}get _children(){return Object.fromEntries(this.templates.map(e=>[e.params.name,e]))}get isDefineTemplates(){return!0}_setPath(e){return this._path=e,this.templates.forEach(s=>s._setPath(e)),this}}const ee=t=>new te(t),se=(t,e)=>new Promise((s,n)=>{const o=setTimeout(()=>{n(new Error("Timeout"))},100),i=ft.createSourceFile("temp.ts",t,ft.ScriptTarget.Latest,!0);function r(y){if(ft.isVariableDeclaration(y)&&y.name.getText()===e){const $=y.getStart(),m=y.getEnd();clearTimeout(o),s([$,m])}y.forEachChild(r)}r(i)}),z={externalModules:[],rcFile:void 0,destDir:void 0},Tt=t=>{if(z.externalModules.length>0)return z.externalModules;const s=p.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return z.externalModules=n,n},I=async t=>{if(z.destDir)return z.destDir;const e=await dt(t),s=c.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return z.destDir=s,s},kt=["salty","css","styles","styled"],Dt=(t=[])=>new RegExp(`\\.(${[...kt,...t].join("|")})\\.`),nt=(t,e=[])=>Dt(e).test(t),vt=async t=>{if(z.rcFile)return z.rcFile;if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=c.join(t,".saltyrc.json"),s=await St.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(z.rcFile=s,s):vt(c.join(t,".."))},dt=async t=>{var n,o;const e=await vt(t),s=(n=e.projects)==null?void 0:n.find(i=>t.endsWith(i.dir||""));return s||((o=e.projects)==null?void 0:o.find(i=>i.dir===e.defaultProject))},ne=async t=>{const e=await dt(t),s=await I(t),n=c.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),o=c.join(s,"salty.config.js"),i=await _t(t),r=Tt(n);await jt.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:i,external:r});const y=Date.now(),{config:$}=await import(`${o}?t=${y}`);return{config:$,path:o}},oe=async(t,e)=>{var ht,gt;const s=await I(t),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...e].map(async j=>{const{contents:x,outputFilePath:U}=await ot(t,j,s);Object.entries(x).forEach(([v,k])=>{k.isMedia?n.mediaQueries.push([v,k]):k.isGlobalDefine?n.globalStyles.push(k):k.isDefineVariables?n.variables.push(k):k.isDefineTemplates&&n.templates.push(k._setPath(`${v};;${U}`))})}));const{config:o,path:i}=await ne(t),r={...o},{mediaQueries:y}=n;r.mediaQueries=Object.fromEntries(y.map(([j,x])=>[`@${j}`,x]));const $=y.map(([j])=>`'@${j}'`).join(" | "),m=new Set,l=async(j,x=[])=>{if(!j)return[];const U=Object.entries(j).map(async([k,A])=>{const B=async E=>{if(!E)return;if(E instanceof Promise)return await B(await E);if(typeof E=="function")return await B(await E());if(typeof E=="object")return await l(E,[...x,k]);const at=xt(k),ct=R(k),lt=[...x,at].join(".");m.add(`"${lt}"`);const tt=[...x.map(R),ct].join("-"),wt=It(E);return wt?`--${tt}: ${wt.transformed};`:`--${tt}: ${E};`};return await B(A)});return(await Promise.all(U)).flat()},g=async j=>{if(!j)return[];const x=Object.entries(j).map(async([v,k])=>{const A=await l(k);return v==="base"?A.join(""):r.mediaQueries[v]?`${r.mediaQueries[v]} { ${A.join("")} }`:`${v} { ${A.join("")} }`});return(await Promise.all(x)).flat()},h=async j=>{if(!j)return[];const x=Object.entries(j).map(async([v,k])=>{const A=Object.entries(k).map(async([E,at])=>{const ct=await l(at,[v]),lt=`.${v}-${E}, [data-${v}="${E}"]`,tt=ct.join("");return`${lt} { ${tt} }`});return(await Promise.all(A)).flat()});return(await Promise.all(x)).flat()},S=j=>({...j,responsive:void 0,conditional:void 0}),d=j=>n.variables.map(x=>j==="static"?S(x._current):x._current[j]),u=H(S(o.variables),d("static")),w=await l(u),P=H((ht=o.variables)==null?void 0:ht.responsive,d("responsive")),T=await g(P),O=H((gt=o.variables)==null?void 0:gt.conditional,d("conditional")),D=await h(O),J=c.join(s,"css/_variables.css"),N=`:root { ${w.join("")} ${T.join("")} } ${D.join("")}`;p.writeFileSync(J,N),r.staticVariables=u;const V=c.join(s,"css/_global.css"),f=H(o.global,n.globalStyles),b=await X(f,"");p.writeFileSync(V,`@layer global { ${b} }`);const F=c.join(s,"css/_reset.css"),C=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:Zt,_=await X(C,"");p.writeFileSync(F,`@layer reset { ${_} }`);const M=c.join(s,"css/_templates.css"),W=H(o.templates,n.templates),L=await Ct(W),Q=Kt(W);p.writeFileSync(M,`@layer templates { ${L} }`),r.templates=W;const Y=o.templates?[ee(o.templates)._setPath(`config;;${i}`)]:[],it=Xt(n.templates,Y);r.templatePaths=Object.fromEntries(Object.entries(it).map(([j,x])=>[j,x._path]));const K=c.join(s,"types/css-tokens.d.ts"),Et=`
|
7
|
+
// Variable types
|
8
|
+
type VariableTokens = ${[...m].join("|")};
|
9
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
10
|
+
|
11
|
+
// Template types
|
12
|
+
type TemplateTokens = {
|
13
|
+
${Object.entries(Q).map(([j,x])=>`${j}?: ${x}`).join(`
|
14
|
+
`)}
|
15
|
+
}
|
16
|
+
|
17
|
+
// Media query types
|
18
|
+
type MediaQueryKeys = ${$||"''"};
|
19
|
+
`;p.writeFileSync(K,Et);const Ot=c.join(s,"cache/config-cache.json");p.writeFileSync(Ot,JSON.stringify(r,null,2))},bt=t=>t.replace(/styled\(([^"'`{,]+),/g,(e,s)=>{if(/^['"`]/.test(s))return e;const o=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!o.test(t))return e;const r=o.exec(t);if(r){const y=r.at(1);if(kt.some(m=>y==null?void 0:y.includes(m)))return e}return"styled('div',"}),ie=(t,e)=>{try{const s=p.readFileSync(c.join(e,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
|
20
|
+
|
21
|
+
${t}`:`globalThis.saltyConfig = {};
|
22
|
+
|
23
|
+
${t}`}catch{return t}},ot=async(t,e,s)=>{const n=q(e),o=c.join(s,"./temp");p.existsSync(o)||p.mkdirSync(o);const i=c.parse(e);let r=p.readFileSync(e,"utf8");r=bt(r),r=ie(r,t);const y=c.join(s,"js",n+".js"),$=await dt(t),m=c.join(t,($==null?void 0:$.configDir)||"","salty.config.ts"),l=Tt(m),g=await _t(t);await jt.build({stdin:{contents:r,sourcefile:i.base,resolveDir:i.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:g,target:["node20"],keepNames:!0,external:l,packages:"external",plugins:[{name:"test",setup:d=>{d.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},u=>{const w=p.readFileSync(u.path,"utf8");return{contents:bt(w),loader:"ts"}})}}]});const h=Date.now();return{contents:await import(`${y}?t=${h}`),outputFilePath:y}},re=async t=>{const e=await I(t),s=c.join(e,"cache/config-cache.json"),n=p.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},mt=async t=>{const e=await re(t),s=await I(t),n=c.join(s,"salty.config.js"),o=Date.now(),{config:i}=await import(`${n}?t=${o}`);return H(i,e)},yt=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},ae=async(t,e=yt(),s=!0)=>{try{const n=Date.now();e?pt.info("Generating CSS in production mode! 🔥"):pt.info("Generating CSS in development mode! 🚀");const o=[],i=[],r=await I(t),y=c.join(r,"index.css");s&&(()=>{p.existsSync(r)&&zt.execSync("rm -rf "+r),p.mkdirSync(r,{recursive:!0}),p.mkdirSync(c.join(r,"css")),p.mkdirSync(c.join(r,"types")),p.mkdirSync(c.join(r,"js")),p.mkdirSync(c.join(r,"cache"))})();const m=new Set,l=new Set;async function g(f){const b=["node_modules","saltygen"],F=p.statSync(f);if(F.isDirectory()){const a=p.readdirSync(f);if(b.some(_=>f.includes(_)))return;await Promise.all(a.map(_=>g(c.join(f,_))))}else if(F.isFile()&&nt(f)){m.add(f);const C=p.readFileSync(f,"utf8");/define[\w\d]+\(/.test(C)&&l.add(f)}}await g(t),await oe(t,l);const h={keyframes:[],components:[],classNames:[]};await Promise.all([...m].map(async f=>{const{contents:b}=await ot(t,f,r);for(let[F,a]of Object.entries(b))a instanceof Promise&&(a=await a),a.isKeyframes?h.keyframes.push({value:a,src:f,name:F}):a.isClassName?h.classNames.push({...a,src:f,name:F}):a.generator&&h.components.push({...a,src:f,name:F})}));const S=await mt(t);for(const f of h.keyframes){const{value:b}=f,F=`a_${b.animationName}.css`,a=`css/${F}`,C=c.join(r,a);o.push(F),p.writeFileSync(C,b.css)}const d={};for(const f of h.components){const{src:b,name:F}=f;d[b]||(d[b]=[]);const a=f.generator._withBuildContext({callerName:F,isProduction:e,config:S});i[a.priority]||(i[a.priority]=[]);const C=await a.css;if(!C)continue;i[a.priority].push(a.cssFileName);const _=`css/${a.cssFileName}`,M=c.join(r,_);p.writeFileSync(M,C),S.importStrategy==="component"&&d[b].push(a.cssFileName)}for(const f of h.classNames){const{src:b,name:F}=f;d[b]||(d[b]=[]);const a=f.generator._withBuildContext({callerName:F,isProduction:e,config:S}),C=await a.css;if(!C)continue;i[a.priority]||(i[a.priority]=[]),i[a.priority].push(a.cssFileName);const _=`css/${a.cssFileName}`,M=c.join(r,_);p.writeFileSync(M,C),S.importStrategy==="component"&&d[b].push(a.cssFileName)}S.importStrategy==="component"&&Object.entries(d).forEach(([f,b])=>{const F=b.map(W=>`@import url('./${W}');`).join(`
|
24
|
+
`),a=q(f,6),C=c.parse(f),_=R(C.name),M=c.join(r,`css/f_${_}-${a}.css`);p.writeFileSync(M,F||"/* Empty file */")});const u=o.map(f=>`@import url('./css/${f}');`).join(`
|
25
|
+
`);let D=`/*!
|
26
|
+
* Generated with Salty CSS (https://salty-css.dev)
|
27
|
+
* Do not edit this file directly
|
28
|
+
*/
|
29
|
+
@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
30
|
+
|
31
|
+
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(f=>{try{return p.readFileSync(c.join(r,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
|
32
|
+
`)}
|
33
|
+
${u}`;if(S.importStrategy!=="component"){const f=i.reduce((b,F,a)=>{const C=F.reduce((L,Q)=>{var rt;const Y=c.join(r,"css",Q),it=p.readFileSync(Y,"utf8"),K=((rt=/.*-([^-]+)-\d+.css/.exec(Q))==null?void 0:rt.at(1))||q(Y,6);return L.includes(K)?L:`${L}
|
34
|
+
/*start:${K}-${Q}*/
|
35
|
+
${it}
|
36
|
+
/*end:${K}*/
|
37
|
+
`},""),_=`l_${a}.css`,M=c.join(r,"css",_),W=`@layer l${a} { ${C}
|
38
|
+
}`;return p.writeFileSync(M,W),`${b}
|
39
|
+
@import url('./css/${_}');`},"");D+=f}p.writeFileSync(y,D);const N=Date.now()-n,V=N<200?"🔥":N<500?"🚀":N<1e3?"🎉":N<2e3?"🚗":N<5e3?"🤔":"🥴";pt.info(`Generated CSS in ${N}ms! ${V}`)}catch(n){console.error(n)}},ce=async(t,e,s=yt())=>{try{const n=await I(t);if(nt(e)){const i=[],r=await mt(t),{contents:y}=await ot(t,e,n);for(const[$,m]of Object.entries(y)){if(m.isKeyframes&&m.css){const u=`css/${`a_${m.animationName}.css`}`,w=c.join(n,u);p.writeFileSync(w,await m.css);continue}if(m.isClassName){const d=m.generator._withBuildContext({callerName:$,isProduction:s,config:r}),u=await d.css;if(!u)continue;i[d.priority]||(i[d.priority]=[]),i[d.priority].push(d.cssFileName);const w=`css/${d.cssFileName}`,P=c.join(n,w);p.writeFileSync(P,u);continue}if(!m.generator)continue;const l=m.generator._withBuildContext({callerName:$,isProduction:s,config:r}),g=await l.css;if(!g)continue;const h=`css/${l.cssFileName}`,S=c.join(n,h);p.writeFileSync(S,g),i[l.priority]||(i[l.priority]=[]),i[l.priority].push(l.cssFileName)}if(r.importStrategy!=="component")i.forEach(($,m)=>{const l=`l_${m}.css`,g=c.join(n,"css",l);let h=p.readFileSync(g,"utf8");$.forEach(S=>{var P;const d=c.join(n,"css",S),u=((P=/.*-([^-]+)-\d+.css/.exec(S))==null?void 0:P.at(1))||q(d,6);if(!h.includes(u)){const T=p.readFileSync(d,"utf8"),O=`/*start:${u}-${S}*/
|
40
|
+
${T}
|
41
|
+
/*end:${u}*/
|
42
|
+
`;h=`${h.replace(/\}$/,"")}
|
43
|
+
${O}
|
44
|
+
}`}}),p.writeFileSync(g,h)});else{const $=i.flat().map(S=>`@import url('./${S}');`).join(`
|
45
|
+
`),m=q(e,6),l=c.parse(e),g=R(l.name),h=c.join(n,`css/f_${g}-${m}.css`);p.writeFileSync(h,$||"/* Empty file */")}}}catch(n){console.error(n)}},le=async(t,e,s=yt())=>{var n,o;try{const i=await I(t);if(nt(e)){const y=p.readFileSync(e,"utf8"),$=await mt(t),{contents:m}=await ot(t,e,i);let l=y;for(const[g,h]of Object.entries(m)){if(h.isKeyframes||!h.generator)continue;const S=h.generator._withBuildContext({callerName:g,isProduction:s,config:$}),[d,u]=await se(l,g),w=l.slice(d,u);if(h.isClassName){const P=l,T=` ${g} = className("${S.classNames}")`;l=l.replace(w,T),P===l&&console.error("Minimize file failed to change content",{name:g})}if(w.includes("styled")){const P=(o=(n=/styled\(([^,]+),/.exec(w))==null?void 0:n.at(1))==null?void 0:o.trim(),T=l,O=` ${g} = styled(${P}, "${S.classNames}", ${JSON.stringify(S.clientProps)})`;l=l.replace(w,O),T===l&&console.error("Minimize file failed to change content",{name:g,tagName:P})}}if($.importStrategy==="component"){const g=q(e,6),h=c.parse(e);l=`import '../../saltygen/css/${`f_${R(h.name)}-${g}.css`}';
|
46
|
+
${l}`}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}}catch(i){console.error("Error in minimizeFile:",i)}};exports.generateCss=ae;exports.generateFile=ce;exports.isSaltyFile=nt;exports.minimizeFile=le;exports.saltyFileRegExp=Dt;
|
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-vma-mOTH.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 r=await y.readFile(e,"utf-8");return!!(/.+define[A-Z]\w+/.test(r)||/.+keyframes\(.+/.test(r))},c=(e,s,l=!1,r=!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,r?"./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,a)=>{await p(a)?await t.generateCss(s,!1,!1):t.isSaltyFile(a)&&await t.generateFile(s,a)}))})}})};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 y, g as u, a as d } from "./index-
|
2
|
+
import { i as f, s as y, g as u, a as d } from "./index-Da-_jI3O.js";
|
3
3
|
import { readFile as g } from "fs/promises";
|
4
4
|
import { watch as m } from "fs";
|
5
5
|
const w = async (e) => {
|
package/loader.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";const i=require("./index-
|
1
|
+
"use strict";const i=require("./index-vma-mOTH.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;
|
package/loader.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@salty-css/webpack",
|
3
|
-
"version": "0.0.1-alpha.
|
3
|
+
"version": "0.0.1-alpha.255",
|
4
4
|
"main": "./dist/index.js",
|
5
5
|
"module": "./dist/index.mjs",
|
6
6
|
"typings": "./dist/index.d.ts",
|
@@ -34,7 +34,7 @@
|
|
34
34
|
}
|
35
35
|
},
|
36
36
|
"dependencies": {
|
37
|
-
"@salty-css/core": "^0.0.1-alpha.
|
37
|
+
"@salty-css/core": "^0.0.1-alpha.255",
|
38
38
|
"webpack": ">=5.x"
|
39
39
|
}
|
40
40
|
}
|
package/index-CCi9INHt.cjs
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
"use strict";var Mt=Object.defineProperty;var vt=(t,e,s)=>e in t?Mt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var et=(t,e,s)=>vt(t,typeof e!="symbol"?e+"":e,s);const Rt=require("esbuild"),zt=require("child_process"),c=require("path"),d=require("fs"),St=require("fs/promises"),Z=require("winston"),ft=require("typescript");var ut=typeof document<"u"?document.currentScript:null;function Jt(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return e.default=t,Object.freeze(e)}const jt=Jt(Rt),$t=t=>String.fromCharCode(t+(t>25?39:97)),Wt=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=$t(n%52)+s;return s=$t(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},At=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},q=(t,e=5)=>{const s=At(5381,JSON.stringify(t))>>>0;return Wt(s,e)};function R(t){return t?typeof t!="string"?R(String(t)):t.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?"-":"")+e.toLowerCase()):""}const qt=t=>e=>{if(typeof e!="string"||!t)return;let s=e;const n=[];return Object.values(t).forEach(i=>{const{pattern:o,transform:r}=i;s=s.replace(o,y=>{const{value:$,css:m}=r(y);return m&&n.push(m),$})}),{transformed:s,additionalCss:n}},Ft=t=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...i)=>{const o=R(i[1].replaceAll(".","-"));return o.startsWith("-")?`-${o}`:`var(--${o})`})},It=Ft(),Gt=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Ht=(t,e,s)=>Gt.some(i=>typeof i=="string"?i===t:i.test(t))?`${e}px`:`${e}`,Lt=["Webkit","Moz","ms","O"],Qt=t=>t.startsWith("-")?t:Lt.some(e=>t.startsWith(e))?`-${R(t)}`:R(t),st=async(t,e="",s,n=!1)=>{if(!t)throw new Error("No styles provided to parseStyles function!");const i=new Set,o=Object.entries(t),r=async([p,u])=>{const w=p.trim(),P=Qt(w),T=(D,J=";")=>`${P}:${D}${J}`,V={scope:e,config:s};if(typeof u=="function")return r([p,u(V)]);if(u instanceof Promise)return r([p,await u]);if(typeof u=="object"){if(!u)return;if(u.isColor)return T(u.toString());if(w==="defaultVariants")return;if(w==="variants"){const N=Object.entries(u);for(const[M,f]of N){if(!f)continue;const b=Object.entries(f);for(const[F,a]of b){if(!a)continue;const C=`${e}.${M}-${F}`;(await st(a,C,s)).forEach(v=>i.add(v))}}return}if(w==="compoundVariants"){for(const N of u){const{css:M,...f}=N,b=Object.entries(f).reduce((a,[C,_])=>`${a}.${C}-${_}`,e);(await st(M,b,s)).forEach(a=>i.add(a))}return}if(w.startsWith("@")){const N=w,M=await X(u,e,s),f=`${N} { ${M} }`;i.add(f);return}const D=p.includes("&")?w.replaceAll("&",e):w.startsWith(":")?`${e}${w}`:`${e} ${w}`;(await st(u,D,s)).forEach(N=>i.add(N));return}if(typeof u=="number"){const D=Ht(P,u);return T(D)}if(typeof u!="string")if("toString"in u)u=u.toString();else throw new Error(`Invalid value type for property ${P}`);return T(u)},y=o.map(r),{modifiers:$}={},m=[Ft(),qt($)],g=(await Promise.all(y).then(p=>Promise.all(p.map(u=>m.reduce(async(w,P)=>{const T=await w;if(!T)return T;const V=await P(T);if(!V)return T;const{transformed:D,additionalCss:J}=V;let N="";if(J)for(const M of J)N+=await X(M,"");return`${N}${D}`},Promise.resolve(u)))))).filter(p=>p!==void 0).join(`
|
2
|
-
`);if(!g.trim())return Array.from(i);const h=e?`${e} {
|
3
|
-
${g}
|
4
|
-
}`:g;return i.has(h)?Array.from(i):[h,...i]},X=async(t,e,s,n=!1)=>(await st(t,e,s,n)).join(`
|
5
|
-
`),Ct=async(t,e=[])=>{if(!t)return"";const s=[],n={};for(const[i,o]of Object.entries(t))if(typeof o!="function")if(o&&typeof o=="object"){const r=i.trim(),y=await Ct(o,[...e,r]);s.push(y)}else n[i]=o;if(Object.keys(n).length){const i=e.map(R).join("-"),o="t_"+q(i,4),r=await X(n,`.${i}, .${o}`);s.push(r)}return s.join(`
|
6
|
-
`)},Kt=t=>t?Object.entries(t).reduce((e,[s,n])=>(typeof n=="function"?e[s]="any":typeof n=="object"&&(e[s]=Pt(n).map(i=>`"${i}"`).join(" | ")),e),{}):{},Pt=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,i])=>{const o=e?`${e}.${n}`:n;return typeof i=="object"?Pt(i,o,s):s.add(e)}),[...s]):[],Nt=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=c.join(t,"package.json");return d.existsSync(e)?e:Nt(c.join(t,".."))},Ut=async t=>{const e=Nt(t);return await St.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},Bt=async t=>{const e=await Ut(t);if(e)return e.type};let G;const _t=async t=>{if(G)return G;const e=await Bt(t);return e==="module"?G="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:ut&&ut.tagName.toUpperCase()==="SCRIPT"&&ut.src||new URL("index-CCi9INHt.cjs",document.baseURI).href).endsWith(".cjs"))&&(G="cjs"),G||"esm"},dt=Z.createLogger({level:"debug",format:Z.format.combine(Z.format.colorize(),Z.format.cli()),transports:[new Z.transports.Console({})]});function xt(t){return t?typeof t!="string"?xt(String(t)):t.replace(/[^\d\w]/g,"."):""}const Zt={"*, *::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"}},H=(...t)=>t.flat().reduce((e,s)=>s!=null&&s._current?{...e,...s._current}:{...e,...s},{}),Xt=(...t)=>t.flat().reduce((e,s)=>({...e,...s._children}),{});class Yt{constructor(e){et(this,"_path");this.params=e}get _current(){return this.params.template}get isDefineTemplate(){return!0}_setPath(e){return this._path=e,this}}class te{constructor(e){et(this,"_path");et(this,"templates",[]);this.params=e,Object.entries(e).forEach(([s,n])=>{this.templates.push(new Yt({name:s,template:n}))})}get _current(){return this.params}get _children(){return Object.fromEntries(this.templates.map(e=>[e.params.name,e]))}get isDefineTemplates(){return!0}_setPath(e){return this._path=e,this.templates.forEach(s=>s._setPath(e)),this}}const ee=t=>new te(t),se=(t,e)=>new Promise((s,n)=>{const i=setTimeout(()=>{n(new Error("Timeout"))},100),o=ft.createSourceFile("temp.ts",t,ft.ScriptTarget.Latest,!0);function r(y){if(ft.isVariableDeclaration(y)&&y.name.getText()===e){const $=y.getStart(),m=y.getEnd();clearTimeout(i),s([$,m])}y.forEachChild(r)}r(o)}),z={externalModules:[],rcFile:void 0,destDir:void 0},Tt=t=>{if(z.externalModules.length>0)return z.externalModules;const s=d.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(i=>i.replace(/['"`]/g,"").trim());return z.externalModules=n,n},I=async t=>{if(z.destDir)return z.destDir;const e=await pt(t),s=c.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return z.destDir=s,s},kt=["salty","css","styles","styled"],Dt=(t=[])=>new RegExp(`\\.(${[...kt,...t].join("|")})\\.`),nt=(t,e=[])=>Dt(e).test(t),Et=async t=>{if(z.rcFile)return z.rcFile;if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=c.join(t,".saltyrc.json"),s=await St.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(z.rcFile=s,s):Et(c.join(t,".."))},pt=async t=>{var n,i;const e=await Et(t),s=(n=e.projects)==null?void 0:n.find(o=>t.endsWith(o.dir||""));return s||((i=e.projects)==null?void 0:i.find(o=>o.dir===e.defaultProject))},ne=async t=>{const e=await pt(t),s=await I(t),n=c.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),i=c.join(s,"salty.config.js"),o=await _t(t),r=Tt(n);await jt.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:i,format:o,external:r});const y=Date.now(),{config:$}=await import(`${i}?t=${y}`);return{config:$,path:i}},ie=async(t,e)=>{var ht,gt;const s=await I(t),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...e].map(async j=>{const{contents:x,outputFilePath:U}=await it(t,j,s);Object.entries(x).forEach(([E,k])=>{k.isMedia?n.mediaQueries.push([E,k]):k.isGlobalDefine?n.globalStyles.push(k):k.isDefineVariables?n.variables.push(k):k.isDefineTemplates&&n.templates.push(k._setPath(`${E};;${U}`))})}));const{config:i,path:o}=await ne(t),r={...i},{mediaQueries:y}=n;r.mediaQueries=Object.fromEntries(y.map(([j,x])=>[`@${j}`,x]));const $=y.map(([j])=>`'@${j}'`).join(" | "),m=new Set,l=async(j,x=[])=>{if(!j)return[];const U=Object.entries(j).map(async([k,A])=>{const B=async O=>{if(!O)return;if(O instanceof Promise)return await B(await O);if(typeof O=="function")return await B(await O());if(typeof O=="object")return await l(O,[...x,k]);const at=xt(k),ct=R(k),lt=[...x,at].join(".");m.add(`"${lt}"`);const tt=[...x.map(R),ct].join("-"),wt=It(O);return wt?`--${tt}: ${wt.transformed};`:`--${tt}: ${O};`};return await B(A)});return(await Promise.all(U)).flat()},g=async j=>{if(!j)return[];const x=Object.entries(j).map(async([E,k])=>{const A=await l(k);return E==="base"?A.join(""):r.mediaQueries[E]?`${r.mediaQueries[E]} { ${A.join("")} }`:`${E} { ${A.join("")} }`});return(await Promise.all(x)).flat()},h=async j=>{if(!j)return[];const x=Object.entries(j).map(async([E,k])=>{const A=Object.entries(k).map(async([O,at])=>{const ct=await l(at,[E]),lt=`.${E}-${O}, [data-${E}="${O}"]`,tt=ct.join("");return`${lt} { ${tt} }`});return(await Promise.all(A)).flat()});return(await Promise.all(x)).flat()},S=j=>({...j,responsive:void 0,conditional:void 0}),p=j=>n.variables.map(x=>j==="static"?S(x._current):x._current[j]),u=H(S(i.variables),p("static")),w=await l(u),P=H((ht=i.variables)==null?void 0:ht.responsive,p("responsive")),T=await g(P),V=H((gt=i.variables)==null?void 0:gt.conditional,p("conditional")),D=await h(V),J=c.join(s,"css/_variables.css"),N=`:root { ${w.join("")} ${T.join("")} } ${D.join("")}`;d.writeFileSync(J,N),r.staticVariables=u;const M=c.join(s,"css/_global.css"),f=H(i.global,n.globalStyles),b=await X(f,"");d.writeFileSync(M,`@layer global { ${b} }`);const F=c.join(s,"css/_reset.css"),C=i.reset==="none"?{}:typeof i.reset=="object"?i.reset:Zt,_=await X(C,"");d.writeFileSync(F,`@layer reset { ${_} }`);const v=c.join(s,"css/_templates.css"),W=H(i.templates,n.templates),L=await Ct(W),Q=Kt(W);d.writeFileSync(v,`@layer templates { ${L} }`),r.templates=W;const Y=i.templates?[ee(i.templates)._setPath(`config;;${o}`)]:[],ot=Xt(n.templates,Y);r.templatePaths=Object.fromEntries(Object.entries(ot).map(([j,x])=>[j,x._path]));const K=c.join(s,"types/css-tokens.d.ts"),Ot=`
|
7
|
-
// Variable types
|
8
|
-
type VariableTokens = ${[...m].join("|")};
|
9
|
-
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
10
|
-
|
11
|
-
// Template types
|
12
|
-
type TemplateTokens = {
|
13
|
-
${Object.entries(Q).map(([j,x])=>`${j}?: ${x}`).join(`
|
14
|
-
`)}
|
15
|
-
}
|
16
|
-
|
17
|
-
// Media query types
|
18
|
-
type MediaQueryKeys = ${$||"''"};
|
19
|
-
`;d.writeFileSync(K,Ot);const Vt=c.join(s,"cache/config-cache.json");d.writeFileSync(Vt,JSON.stringify(r,null,2))},bt=t=>t.replace(/styled\(([^"'`{,]+),/g,(e,s)=>{if(/^['"`]/.test(s))return e;const i=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!i.test(t))return e;const r=i.exec(t);if(r){const y=r.at(1);if(kt.some(m=>y==null?void 0:y.includes(m)))return e}return"styled('div',"}),oe=(t,e)=>{try{const s=d.readFileSync(c.join(e,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
|
20
|
-
|
21
|
-
${t}`:`globalThis.saltyConfig = {};
|
22
|
-
|
23
|
-
${t}`}catch{return t}},it=async(t,e,s)=>{const n=q(e),i=c.join(s,"./temp");d.existsSync(i)||d.mkdirSync(i);const o=c.parse(e);let r=d.readFileSync(e,"utf8");r=bt(r),r=oe(r,t);const y=c.join(s,"js",n+".js"),$=await pt(t),m=c.join(t,($==null?void 0:$.configDir)||"","salty.config.ts"),l=Tt(m),g=await _t(t);await jt.build({stdin:{contents:r,sourcefile:o.base,resolveDir:o.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:g,target:["node20"],keepNames:!0,external:l,packages:"external",plugins:[{name:"test",setup:p=>{p.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},u=>{const w=d.readFileSync(u.path,"utf8");return{contents:bt(w),loader:"ts"}})}}]});const h=Date.now();return{contents:await import(`${y}?t=${h}`),outputFilePath:y}},re=async t=>{const e=await I(t),s=c.join(e,"cache/config-cache.json"),n=d.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},mt=async t=>{const e=await re(t),s=await I(t),n=c.join(s,"salty.config.js"),i=Date.now(),{config:o}=await import(`${n}?t=${i}`);return H(o,e)},yt=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},ae=async(t,e=yt(),s=!0)=>{try{const n=Date.now();e?dt.info("Generating CSS in production mode! 🔥"):dt.info("Generating CSS in development mode! 🚀");const i=[],o=[],r=await I(t),y=c.join(r,"index.css");s&&(()=>{d.existsSync(r)&&zt.execSync("rm -rf "+r),d.mkdirSync(r,{recursive:!0}),d.mkdirSync(c.join(r,"css")),d.mkdirSync(c.join(r,"types")),d.mkdirSync(c.join(r,"js")),d.mkdirSync(c.join(r,"cache"))})();const m=new Set,l=new Set;async function g(f){const b=["node_modules","saltygen"],F=d.statSync(f);if(F.isDirectory()){const a=d.readdirSync(f);if(b.some(_=>f.includes(_)))return;await Promise.all(a.map(_=>g(c.join(f,_))))}else if(F.isFile()&&nt(f)){m.add(f);const C=d.readFileSync(f,"utf8");/define[\w\d]+\(/.test(C)&&l.add(f)}}await g(t),await ie(t,l);const h={keyframes:[],components:[],classNames:[]};await Promise.all([...m].map(async f=>{const{contents:b}=await it(t,f,r);for(let[F,a]of Object.entries(b))a instanceof Promise&&(a=await a),a.isKeyframes?h.keyframes.push({value:a,src:f,name:F}):a.isClassName?h.classNames.push({...a,src:f,name:F}):a.generator&&h.components.push({...a,src:f,name:F})}));const S=await mt(t);for(const f of h.keyframes){const{value:b}=f,F=`a_${b.animationName}.css`,a=`css/${F}`,C=c.join(r,a);i.push(F),d.writeFileSync(C,b.css)}const p={};for(const f of h.components){const{src:b,name:F}=f;p[b]||(p[b]=[]);const a=f.generator._withBuildContext({callerName:F,isProduction:e,config:S});o[a.priority]||(o[a.priority]=[]);const C=await a.css;if(!C)continue;o[a.priority].push(a.cssFileName);const _=`css/${a.cssFileName}`,v=c.join(r,_);d.writeFileSync(v,C),S.importStrategy==="component"&&p[b].push(a.cssFileName)}for(const f of h.classNames){const{src:b,name:F}=f;p[b]||(p[b]=[]);const a=f.generator._withBuildContext({callerName:F,isProduction:e,config:S}),C=await a.css;if(!C)continue;o[a.priority]||(o[a.priority]=[]),o[a.priority].push(a.cssFileName);const _=`css/${a.cssFileName}`,v=c.join(r,_);d.writeFileSync(v,C),S.importStrategy==="component"&&p[b].push(a.cssFileName)}S.importStrategy==="component"&&Object.entries(p).forEach(([f,b])=>{const F=b.map(W=>`@import url('./${W}');`).join(`
|
24
|
-
`),a=q(f,6),C=c.parse(f),_=R(C.name),v=c.join(r,`css/f_${_}-${a}.css`);d.writeFileSync(v,F||"/* Empty file */")});const u=i.map(f=>`@import url('./css/${f}');`).join(`
|
25
|
-
`);let D=`/*!
|
26
|
-
* Generated with Salty CSS (https://salty-css.dev)
|
27
|
-
* Do not edit this file directly
|
28
|
-
*/
|
29
|
-
@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
30
|
-
|
31
|
-
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(f=>{try{return d.readFileSync(c.join(r,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
|
32
|
-
`)}
|
33
|
-
${u}`;if(S.importStrategy!=="component"){const f=o.reduce((b,F,a)=>{const C=F.reduce((L,Q)=>{var rt;const Y=c.join(r,"css",Q),ot=d.readFileSync(Y,"utf8"),K=((rt=/.*-([^-]+)-\d+.css/.exec(Q))==null?void 0:rt.at(1))||q(Y,6);return L.includes(K)?L:`${L}
|
34
|
-
/*start:${K}-${Q}*/
|
35
|
-
${ot}
|
36
|
-
/*end:${K}*/
|
37
|
-
`},""),_=`l_${a}.css`,v=c.join(r,"css",_),W=`@layer l${a} { ${C}
|
38
|
-
}`;return d.writeFileSync(v,W),`${b}
|
39
|
-
@import url('./css/${_}');`},"");D+=f}d.writeFileSync(y,D);const N=Date.now()-n,M=N<200?"🔥":N<500?"🚀":N<1e3?"🎉":N<2e3?"🚗":N<5e3?"🤔":"🥴";dt.info(`Generated CSS in ${N}ms! ${M}`)}catch(n){console.error(n)}},ce=async(t,e,s=yt())=>{try{const n=await I(t);if(nt(e)){const o=[],r=await mt(t),{contents:y}=await it(t,e,n);for(const[$,m]of Object.entries(y)){if(m.isKeyframes&&m.css){const u=`css/${`a_${m.animationName}.css`}`,w=c.join(n,u);d.writeFileSync(w,await m.css);continue}if(m.isClassName){const p=m.generator._withBuildContext({callerName:$,isProduction:s,config:r}),u=await p.css;if(!u)continue;o[p.priority]||(o[p.priority]=[]),o[p.priority].push(p.cssFileName);const w=`css/${p.cssFileName}`,P=c.join(n,w);d.writeFileSync(P,u);continue}if(!m.generator)continue;const l=m.generator._withBuildContext({callerName:$,isProduction:s,config:r}),g=await l.css;if(!g)continue;const h=`css/${l.cssFileName}`,S=c.join(n,h);d.writeFileSync(S,g),o[l.priority]||(o[l.priority]=[]),o[l.priority].push(l.cssFileName)}if(r.importStrategy!=="component")o.forEach(($,m)=>{const l=`l_${m}.css`,g=c.join(n,"css",l);let h=d.readFileSync(g,"utf8");$.forEach(S=>{var P;const p=c.join(n,"css",S),u=((P=/.*-([^-]+)-\d+.css/.exec(S))==null?void 0:P.at(1))||q(p,6);if(!h.includes(u)){const T=d.readFileSync(p,"utf8"),V=`/*start:${u}-${S}*/
|
40
|
-
${T}
|
41
|
-
/*end:${u}*/
|
42
|
-
`;h=`${h.replace(/\}$/,"")}
|
43
|
-
${V}
|
44
|
-
}`}}),d.writeFileSync(g,h)});else{const $=o.flat().map(S=>`@import url('./${S}');`).join(`
|
45
|
-
`),m=q(e,6),l=c.parse(e),g=R(l.name),h=c.join(n,`css/f_${g}-${m}.css`);d.writeFileSync(h,$||"/* Empty file */")}}}catch(n){console.error(n)}},le=async(t,e,s=yt())=>{var n,i;try{const o=await I(t);if(nt(e)){const y=d.readFileSync(e,"utf8"),$=await mt(t),{contents:m}=await it(t,e,o);let l=y;for(const[g,h]of Object.entries(m)){if(h.isKeyframes||!h.generator)continue;const S=h.generator._withBuildContext({callerName:g,isProduction:s,config:$}),[p,u]=await se(l,g),w=l.slice(p,u);if(h.isClassName){const P=l,T=` ${g} = className("${S.classNames}")`;l=l.replace(w,T),P===l&&console.error("Minimize file failed to change content",{name:g})}if(w.includes("styled")){const P=(i=(n=/styled\(([^,]+),/.exec(w))==null?void 0:n.at(1))==null?void 0:i.trim(),T=l,V=` ${g} = styled(${P}, "${S.classNames}", ${JSON.stringify(S.clientProps)})`;l=l.replace(w,V),T===l&&console.error("Minimize file failed to change content",{name:g,tagName:P})}}if($.importStrategy==="component"){const g=q(e,6),h=c.parse(e);l=`import '../../saltygen/css/${`f_${R(h.name)}-${g}.css`}';
|
46
|
-
${l}`}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}}catch(o){console.error("Error in minimizeFile:",o)}};exports.generateCss=ae;exports.generateFile=ce;exports.isSaltyFile=nt;exports.minimizeFile=le;exports.saltyFileRegExp=Dt;
|