@salty-css/webpack 0.0.1-alpha.146 → 0.0.1-alpha.148
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-DRE0kJhP.js +461 -0
- package/index-iYTih5G5.cjs +36 -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-D8HB2lym.js +0 -454
- package/index-D9S9Ox8Q.cjs +0 -36
@@ -0,0 +1,461 @@
|
|
1
|
+
import * as tt from "esbuild";
|
2
|
+
import { execSync as mt } from "child_process";
|
3
|
+
import { join as a, parse as B } from "path";
|
4
|
+
import { existsSync as K, writeFileSync as D, readFileSync as R, mkdirSync as H, statSync as ht, readdirSync as $t } from "fs";
|
5
|
+
import { readFile as et, writeFile as bt } from "fs/promises";
|
6
|
+
import { createLogger as wt, format as I, transports as St } from "winston";
|
7
|
+
const Q = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), jt = (t, e) => {
|
8
|
+
let s = "", n;
|
9
|
+
for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = Q(n % 52) + s;
|
10
|
+
return s = Q(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
|
11
|
+
}, Ct = (t, e) => {
|
12
|
+
let s = e.length;
|
13
|
+
for (; s; ) t = t * 33 ^ e.charCodeAt(--s);
|
14
|
+
return t;
|
15
|
+
}, Z = (t, e = 5) => {
|
16
|
+
const s = Ct(5381, JSON.stringify(t)) >>> 0;
|
17
|
+
return jt(s, e);
|
18
|
+
};
|
19
|
+
function A(t) {
|
20
|
+
return t ? typeof t != "string" ? A(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 Ft = (t, e) => {
|
23
|
+
if (typeof t != "string") return { result: t };
|
24
|
+
if (!e) return { result: t };
|
25
|
+
const s = [];
|
26
|
+
return Object.values(e).forEach((n) => {
|
27
|
+
const { pattern: i, transform: r } = n;
|
28
|
+
t = t.replace(i, (f) => {
|
29
|
+
const { value: u, css: c } = r(f);
|
30
|
+
return c && s.push(c), u;
|
31
|
+
});
|
32
|
+
}), { result: t, additionalCss: s };
|
33
|
+
}, st = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${A(n[1].replaceAll(".", "-"))})`) } : { result: t }, M = (t, e, s) => {
|
34
|
+
if (!t) return "";
|
35
|
+
const n = [], i = Object.entries(t).reduce((f, [u, c]) => {
|
36
|
+
const o = u.trim();
|
37
|
+
if (typeof c == "function" && (c = c()), typeof c == "object") {
|
38
|
+
if (!c) return f;
|
39
|
+
if (o === "variants")
|
40
|
+
return Object.entries(c).forEach(([l, m]) => {
|
41
|
+
m && Object.entries(m).forEach(([N, S]) => {
|
42
|
+
if (!S) return;
|
43
|
+
const P = `${e}.${l}-${N}`, x = M(S, P);
|
44
|
+
n.push(x);
|
45
|
+
});
|
46
|
+
}), f;
|
47
|
+
if (o === "defaultVariants")
|
48
|
+
return f;
|
49
|
+
if (o === "compoundVariants")
|
50
|
+
return c.forEach((l) => {
|
51
|
+
const { css: m, ...N } = l, S = Object.entries(N).reduce((x, [d, h]) => `${x}.${d}-${h}`, e), P = M(m, S);
|
52
|
+
n.push(P);
|
53
|
+
}), f;
|
54
|
+
if (o.startsWith("@")) {
|
55
|
+
const l = M(c, e), m = `${o} {
|
56
|
+
${l.replace(`
|
57
|
+
`, `
|
58
|
+
`)}
|
59
|
+
}`;
|
60
|
+
return n.push(m), f;
|
61
|
+
}
|
62
|
+
const p = u.includes("&") ? o.replace("&", e) : o.startsWith(":") ? `${e}${o}` : `${e} ${o}`, b = M(c, p);
|
63
|
+
return n.push(b), f;
|
64
|
+
}
|
65
|
+
const g = o.startsWith("-") ? o : A(o), y = (p, b = ";") => f = `${f}${p}${b}`, C = (p) => y(`${g}:${p}`);
|
66
|
+
if (typeof c == "number") return C(c);
|
67
|
+
if (typeof c != "string")
|
68
|
+
if ("toString" in c) c = c.toString();
|
69
|
+
else return f;
|
70
|
+
const { modifiers: F } = {}, T = function* () {
|
71
|
+
yield st(c), yield Ft(c, F);
|
72
|
+
}();
|
73
|
+
for (const { result: p, additionalCss: b = [] } of T)
|
74
|
+
c = p, b.forEach((l) => {
|
75
|
+
const m = M(l, "");
|
76
|
+
y(m, "");
|
77
|
+
});
|
78
|
+
return C(c);
|
79
|
+
}, "");
|
80
|
+
return i ? e ? [`${e} { ${i} }`, ...n].join(`
|
81
|
+
`) : i : n.join(`
|
82
|
+
`);
|
83
|
+
}, nt = (t, e = []) => {
|
84
|
+
if (!t) return "";
|
85
|
+
const s = [], n = {};
|
86
|
+
if (Object.entries(t).forEach(([i, r]) => {
|
87
|
+
if (typeof r == "object") {
|
88
|
+
if (!r) return;
|
89
|
+
const f = i.trim(), u = nt(r, [...e, f]);
|
90
|
+
s.push(u);
|
91
|
+
} else
|
92
|
+
n[i] = r;
|
93
|
+
}), Object.keys(n).length) {
|
94
|
+
const i = e.map(A).join("-"), r = M(n, `.${i}`);
|
95
|
+
s.push(r);
|
96
|
+
}
|
97
|
+
return s.join(`
|
98
|
+
`);
|
99
|
+
}, xt = (t) => Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = ot(n).map((i) => `"${i}"`).join(" | ")), e), {}), ot = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, i]) => {
|
100
|
+
const r = e ? `${e}.${n}` : n;
|
101
|
+
return typeof i == "object" ? ot(i, r, s) : s.add(e);
|
102
|
+
}), [...s]) : [], rt = (t) => {
|
103
|
+
if (!t || t === "/") throw new Error("Could not find package.json file");
|
104
|
+
const e = a(t, "package.json");
|
105
|
+
return K(e) ? e : rt(a(t, ".."));
|
106
|
+
}, kt = async (t) => {
|
107
|
+
const e = rt(t);
|
108
|
+
return await et(e, "utf-8").then(JSON.parse).catch(() => {
|
109
|
+
});
|
110
|
+
}, Dt = async (t) => {
|
111
|
+
const e = await kt(t);
|
112
|
+
if (e)
|
113
|
+
return e.type;
|
114
|
+
};
|
115
|
+
let W;
|
116
|
+
const it = async (t) => {
|
117
|
+
if (W) return W;
|
118
|
+
const e = await Dt(t);
|
119
|
+
return e === "module" ? W = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (W = "cjs"), W || "esm";
|
120
|
+
}, L = wt({
|
121
|
+
level: "debug",
|
122
|
+
format: I.combine(I.colorize(), I.cli()),
|
123
|
+
transports: [new St.Console({})]
|
124
|
+
});
|
125
|
+
function ct(t) {
|
126
|
+
return t ? typeof t != "string" ? ct(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "." : "") + e.toLowerCase()) : "";
|
127
|
+
}
|
128
|
+
const Nt = {
|
129
|
+
/** Set box model to border-box */
|
130
|
+
"*, *::before, *::after": {
|
131
|
+
boxSizing: "border-box"
|
132
|
+
},
|
133
|
+
/** Remove default margin and padding */
|
134
|
+
"*": {
|
135
|
+
margin: 0
|
136
|
+
},
|
137
|
+
/** Remove adjust font properties */
|
138
|
+
html: {
|
139
|
+
lineHeight: 1.15,
|
140
|
+
textSizeAdjust: "100%",
|
141
|
+
WebkitFontSmoothing: "antialiased"
|
142
|
+
},
|
143
|
+
/** Make media elements responsive */
|
144
|
+
"img, picture, video, canvas, svg": {
|
145
|
+
display: "block",
|
146
|
+
maxWidth: "100%"
|
147
|
+
},
|
148
|
+
/** Avoid overflow of text */
|
149
|
+
"p, h1, h2, h3, h4, h5, h6": {
|
150
|
+
overflowWrap: "break-word"
|
151
|
+
},
|
152
|
+
/** Improve text wrapping */
|
153
|
+
p: {
|
154
|
+
textWrap: "pretty"
|
155
|
+
},
|
156
|
+
"h1, h2, h3, h4, h5, h6": {
|
157
|
+
textWrap: "balance"
|
158
|
+
},
|
159
|
+
/** Improve link color */
|
160
|
+
a: {
|
161
|
+
color: "currentColor"
|
162
|
+
},
|
163
|
+
/** Improve button line height */
|
164
|
+
button: {
|
165
|
+
lineHeight: "1em",
|
166
|
+
color: "currentColor"
|
167
|
+
},
|
168
|
+
/** Improve form elements */
|
169
|
+
"input, optgroup, select, textarea": {
|
170
|
+
fontFamily: "inherit",
|
171
|
+
fontSize: "100%",
|
172
|
+
lineHeight: "1.15em"
|
173
|
+
}
|
174
|
+
}, V = {
|
175
|
+
externalModules: [],
|
176
|
+
rcFile: void 0,
|
177
|
+
destDir: void 0
|
178
|
+
}, at = (t) => {
|
179
|
+
if (V.externalModules.length > 0) return V.externalModules;
|
180
|
+
const s = R(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
181
|
+
if (!s) return [];
|
182
|
+
const n = s[1].split(",").map((i) => i.replace(/['"`]/g, "").trim());
|
183
|
+
return V.externalModules = n, n;
|
184
|
+
}, z = async (t) => {
|
185
|
+
if (V.destDir) return V.destDir;
|
186
|
+
const e = await q(t), s = a(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
|
187
|
+
return V.destDir = s, s;
|
188
|
+
}, lt = ["salty", "css", "styles", "styled"], Pt = (t = []) => new RegExp(`\\.(${[...lt, ...t].join("|")})\\.`), G = (t, e = []) => Pt(e).test(t), ft = async (t) => {
|
189
|
+
if (V.rcFile) return V.rcFile;
|
190
|
+
if (t === "/") throw new Error("Could not find .saltyrc.json file");
|
191
|
+
const e = a(t, ".saltyrc.json"), s = await et(e, "utf-8").then(JSON.parse).catch(() => {
|
192
|
+
});
|
193
|
+
return s ? (V.rcFile = s, s) : ft(a(t, ".."));
|
194
|
+
}, q = async (t) => {
|
195
|
+
var n, i;
|
196
|
+
const e = await ft(t), s = (n = e.projects) == null ? void 0 : n.find((r) => t.endsWith(r.dir || ""));
|
197
|
+
return s || ((i = e.projects) == null ? void 0 : i.find((r) => r.dir === e.defaultProject));
|
198
|
+
}, Et = async (t) => {
|
199
|
+
const e = await q(t), s = await z(t), n = a(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), i = a(s, "salty.config.js"), r = await it(t), f = at(n);
|
200
|
+
await tt.build({
|
201
|
+
entryPoints: [n],
|
202
|
+
minify: !0,
|
203
|
+
treeShaking: !0,
|
204
|
+
bundle: !0,
|
205
|
+
outfile: i,
|
206
|
+
format: r,
|
207
|
+
external: f
|
208
|
+
});
|
209
|
+
const u = Date.now(), { config: c } = await import(`${i}?t=${u}`);
|
210
|
+
return c;
|
211
|
+
}, Tt = async (t) => {
|
212
|
+
const e = await Et(t), s = /* @__PURE__ */ new Set(), n = (d, h = []) => d ? Object.entries(d).flatMap(([j, $]) => {
|
213
|
+
if (!$) return;
|
214
|
+
if (typeof $ == "object") return n($, [...h, j]);
|
215
|
+
const _ = ct(j), J = A(j), E = [...h, _].join(".");
|
216
|
+
s.add(`"${E}"`);
|
217
|
+
const k = [...h.map(A), J].join("-"), { result: O } = st($);
|
218
|
+
return `--${k}: ${O};`;
|
219
|
+
}) : [], i = (d) => d ? Object.entries(d).flatMap(([h, j]) => {
|
220
|
+
const $ = n(j);
|
221
|
+
return h === "base" ? $.join("") : `${h} { ${$.join("")} }`;
|
222
|
+
}) : [], r = (d) => d ? Object.entries(d).flatMap(([h, j]) => Object.entries(j).flatMap(([$, _]) => {
|
223
|
+
const J = n(_, [h]), E = `.${h}-${$}, [data-${h}="${$}"]`, k = J.join("");
|
224
|
+
return `${E} { ${k} }`;
|
225
|
+
})) : [], f = n(e.variables), u = i(e.responsiveVariables), c = r(e.conditionalVariables), o = await z(t), g = a(o, "css/_variables.css"), y = `:root { ${f.join("")} ${u.join("")} } ${c.join("")}`;
|
226
|
+
D(g, y);
|
227
|
+
const C = a(o, "css/_global.css"), F = M(e.global, "");
|
228
|
+
D(C, `@layer global { ${F} }`);
|
229
|
+
const w = a(o, "css/_reset.css"), p = e.reset === "none" ? {} : typeof e.reset == "object" ? e.reset : Nt, b = M(p, "");
|
230
|
+
D(w, `@layer reset { ${b} }`);
|
231
|
+
const l = a(o, "css/_templates.css"), m = nt(e.templates), N = xt(e.templates);
|
232
|
+
D(l, m);
|
233
|
+
const S = a(o, "types/css-tokens.d.ts"), x = `
|
234
|
+
// Variable types
|
235
|
+
type VariableTokens = ${[...s].join("|")};
|
236
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
237
|
+
|
238
|
+
// Template types
|
239
|
+
type TemplateTokens = {
|
240
|
+
${Object.entries(N).map(([d, h]) => `${d}?: ${h}`).join(`
|
241
|
+
`)}
|
242
|
+
}
|
243
|
+
`;
|
244
|
+
D(S, x);
|
245
|
+
}, v = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
|
246
|
+
if (/^['"`]/.test(s)) return e;
|
247
|
+
const i = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
|
248
|
+
if (!i.test(t)) return e;
|
249
|
+
const f = i.exec(t);
|
250
|
+
if (f) {
|
251
|
+
const u = f.at(1);
|
252
|
+
if (lt.some((o) => u == null ? void 0 : u.includes(o))) return e;
|
253
|
+
}
|
254
|
+
return "styled('div',";
|
255
|
+
}), U = async (t, e, s) => {
|
256
|
+
const n = Z(e), i = a(s, "./temp");
|
257
|
+
K(i) || H(i);
|
258
|
+
const r = B(e);
|
259
|
+
let f = R(e, "utf8");
|
260
|
+
f = v(f);
|
261
|
+
const u = a(s, "js", n + ".js"), c = await q(t), o = a(t, (c == null ? void 0 : c.configDir) || "", "salty.config.ts"), g = at(o), y = await it(t);
|
262
|
+
await tt.build({
|
263
|
+
stdin: {
|
264
|
+
contents: f,
|
265
|
+
sourcefile: r.base,
|
266
|
+
resolveDir: r.dir,
|
267
|
+
loader: "tsx"
|
268
|
+
},
|
269
|
+
minify: !1,
|
270
|
+
treeShaking: !0,
|
271
|
+
bundle: !0,
|
272
|
+
outfile: u,
|
273
|
+
format: y,
|
274
|
+
target: ["node20"],
|
275
|
+
keepNames: !0,
|
276
|
+
external: g,
|
277
|
+
packages: "external",
|
278
|
+
plugins: [
|
279
|
+
{
|
280
|
+
name: "test",
|
281
|
+
setup: (w) => {
|
282
|
+
w.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (T) => {
|
283
|
+
const p = R(T.path, "utf8");
|
284
|
+
return { contents: v(p), loader: "ts" };
|
285
|
+
});
|
286
|
+
}
|
287
|
+
}
|
288
|
+
]
|
289
|
+
});
|
290
|
+
const C = Date.now();
|
291
|
+
return await import(`${u}?t=${C}`);
|
292
|
+
}, X = async (t) => {
|
293
|
+
const e = await z(t), s = a(e, "salty.config.js"), n = Date.now(), { config: i } = await import(`${s}?t=${n}`);
|
294
|
+
return i;
|
295
|
+
}, ut = () => {
|
296
|
+
try {
|
297
|
+
return process.env.NODE_ENV === "production";
|
298
|
+
} catch {
|
299
|
+
return !1;
|
300
|
+
}
|
301
|
+
}, At = async (t, e = ut()) => {
|
302
|
+
try {
|
303
|
+
const s = Date.now();
|
304
|
+
e ? L.info("Generating CSS in production mode! 🔥") : L.info("Generating CSS in development mode! 🚀");
|
305
|
+
const n = [], i = [], r = await z(t), f = a(r, "index.css");
|
306
|
+
(() => {
|
307
|
+
K(r) && mt("rm -rf " + r), H(r, { recursive: !0 }), H(a(r, "css")), H(a(r, "types"));
|
308
|
+
})(), await Tt(t);
|
309
|
+
const c = await X(t);
|
310
|
+
async function o(l, m) {
|
311
|
+
const N = ["node_modules", "saltygen"], S = ht(l);
|
312
|
+
if (S.isDirectory()) {
|
313
|
+
const P = $t(l);
|
314
|
+
if (N.some((d) => l.includes(d))) return;
|
315
|
+
await Promise.all(P.map((d) => o(a(l, d), a(m, d))));
|
316
|
+
} else if (S.isFile() && G(l)) {
|
317
|
+
const x = await U(t, l, r), d = [];
|
318
|
+
Object.entries(x).forEach(([E, k]) => {
|
319
|
+
if (k.isKeyframes && k.css) {
|
320
|
+
const Y = `a_${k.animationName}.css`, gt = `css/${Y}`, yt = a(r, gt);
|
321
|
+
n.push(Y), D(yt, k.css);
|
322
|
+
return;
|
323
|
+
}
|
324
|
+
if (!k.generator) return;
|
325
|
+
const O = k.generator._withBuildContext({
|
326
|
+
name: E,
|
327
|
+
config: c,
|
328
|
+
prod: e
|
329
|
+
});
|
330
|
+
i[O.priority] || (i[O.priority] = []), i[O.priority].push(O.cssFileName), d.push(O.cssFileName);
|
331
|
+
const pt = `css/${O.cssFileName}`, dt = a(r, pt);
|
332
|
+
D(dt, O.css);
|
333
|
+
});
|
334
|
+
const h = d.map((E) => `@import url('./${E}');`).join(`
|
335
|
+
`), j = Z(l, 6), $ = B(l), _ = A($.name), J = a(r, `css/f_${_}-${j}.css`);
|
336
|
+
D(J, h);
|
337
|
+
}
|
338
|
+
}
|
339
|
+
await o(t, r);
|
340
|
+
const g = n.map((l) => `@import url('./css/${l}');`).join(`
|
341
|
+
`);
|
342
|
+
let w = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
343
|
+
|
344
|
+
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) => {
|
345
|
+
try {
|
346
|
+
return R(a(r, "css", l), "utf8").length > 0;
|
347
|
+
} catch {
|
348
|
+
return !1;
|
349
|
+
}
|
350
|
+
}).map((l) => `@import url('./css/${l}');`).join(`
|
351
|
+
`)}
|
352
|
+
${g}`;
|
353
|
+
if (c.importStrategy !== "component") {
|
354
|
+
const l = i.reduce((m, N, S) => {
|
355
|
+
const P = N.reduce((j, $) => {
|
356
|
+
var k;
|
357
|
+
const _ = a(r, "css", $), J = R(_, "utf8"), E = ((k = /.*-([^-]+)-\d+.css/.exec($)) == null ? void 0 : k.at(1)) || Z(_, 6);
|
358
|
+
return j.includes(E) ? j : `${j}
|
359
|
+
/*start:${E}*/
|
360
|
+
${J}
|
361
|
+
/*end:${E}*/
|
362
|
+
`;
|
363
|
+
}, ""), x = `l_${S}.css`, d = a(r, "css", x), h = `@layer l${S} { ${P}
|
364
|
+
}`;
|
365
|
+
return D(d, h), `${m}
|
366
|
+
@import url('./css/${x}');`;
|
367
|
+
}, "");
|
368
|
+
w += l;
|
369
|
+
}
|
370
|
+
D(f, w);
|
371
|
+
const p = Date.now() - s, b = p < 200 ? "🔥" : p < 500 ? "🚀" : p < 1e3 ? "🎉" : p < 2e3 ? "🚗" : p < 5e3 ? "🤔" : "🥴";
|
372
|
+
L.info(`Generated CSS in ${p}ms! ${b}`);
|
373
|
+
} catch (s) {
|
374
|
+
console.error(s);
|
375
|
+
}
|
376
|
+
}, Jt = async (t, e) => {
|
377
|
+
try {
|
378
|
+
const s = await z(t);
|
379
|
+
if (G(e)) {
|
380
|
+
const i = [], r = await X(t), f = await U(t, e, s);
|
381
|
+
Object.entries(f).forEach(([u, c]) => {
|
382
|
+
if (c.isKeyframes && c.css) {
|
383
|
+
const F = `css/${`a_${c.animationName}.css`}`, w = a(s, F);
|
384
|
+
D(w, c.css);
|
385
|
+
return;
|
386
|
+
}
|
387
|
+
if (!c.generator) return;
|
388
|
+
const o = c.generator._withBuildContext({
|
389
|
+
name: u,
|
390
|
+
config: r
|
391
|
+
}), g = `css/${o.cssFileName}`, y = a(s, g);
|
392
|
+
D(y, o.css), i[o.priority] || (i[o.priority] = []), i[o.priority].push(o.cssFileName);
|
393
|
+
}), r.importStrategy !== "component" && i.forEach((u, c) => {
|
394
|
+
const o = `l_${c}.css`, g = a(s, "css", o);
|
395
|
+
let y = R(g, "utf8");
|
396
|
+
u.forEach((C) => {
|
397
|
+
var p;
|
398
|
+
const F = a(s, "css", C), w = ((p = /.*-([^-]+)-\d+.css/.exec(C)) == null ? void 0 : p.at(1)) || Z(F, 6);
|
399
|
+
if (!y.includes(w)) {
|
400
|
+
const b = R(F, "utf8"), l = `/*start:${w}*/
|
401
|
+
${b}
|
402
|
+
/*end:${w}*/
|
403
|
+
`;
|
404
|
+
y = `${y.replace(/\}$/, "")}
|
405
|
+
${l}
|
406
|
+
}`;
|
407
|
+
}
|
408
|
+
}), D(g, y);
|
409
|
+
});
|
410
|
+
}
|
411
|
+
} catch (s) {
|
412
|
+
console.error(s);
|
413
|
+
}
|
414
|
+
}, Wt = async (t, e, s = ut()) => {
|
415
|
+
try {
|
416
|
+
const n = await z(t);
|
417
|
+
if (G(e)) {
|
418
|
+
const r = R(e, "utf8");
|
419
|
+
r.replace(/^(?!export\s)const\s.*/gm, (g) => `export ${g}`) !== r && await bt(e, r);
|
420
|
+
const u = await X(t), c = await U(t, e, n);
|
421
|
+
let o = r;
|
422
|
+
if (Object.entries(c).forEach(([g, y]) => {
|
423
|
+
var j;
|
424
|
+
if (y.isKeyframes || !y.generator) return;
|
425
|
+
const C = y.generator._withBuildContext({
|
426
|
+
name: g,
|
427
|
+
config: u,
|
428
|
+
prod: s
|
429
|
+
}), F = new RegExp(`\\s${g}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
|
430
|
+
if (!F) return console.error("Could not find the original declaration");
|
431
|
+
const w = (j = F.at(1)) == null ? void 0 : j.trim(), T = new RegExp(`\\s${g}[=\\s]+styled\\(`, "g").exec(o);
|
432
|
+
if (!T) return console.error("Could not find the original declaration");
|
433
|
+
const { index: p } = T;
|
434
|
+
let b = !1;
|
435
|
+
const l = setTimeout(() => b = !0, 5e3);
|
436
|
+
let m = 0, N = !1, S = 0;
|
437
|
+
for (; !N && !b; ) {
|
438
|
+
const $ = o[p + m];
|
439
|
+
$ === "(" && S++, $ === ")" && S--, S === 0 && $ === ")" && (N = !0), m > o.length && (b = !0), m++;
|
440
|
+
}
|
441
|
+
if (!b) clearTimeout(l);
|
442
|
+
else throw new Error("Failed to find the end of the styled call and timed out");
|
443
|
+
const P = p + m, x = o.slice(p, P), d = o, h = ` ${g} = styled(${w}, "${C.classNames}", ${JSON.stringify(C.props)});`;
|
444
|
+
o = o.replace(x, h), d === o && console.error("Minimize file failed to change content", { name: g, tagName: w });
|
445
|
+
}), u.importStrategy === "component") {
|
446
|
+
const g = Z(e, 6), y = B(e);
|
447
|
+
o = `import '../../saltygen/css/${`f_${A(y.name)}-${g}.css`}';
|
448
|
+
${o}`;
|
449
|
+
}
|
450
|
+
return o = o.replace("{ styled }", "{ styledClient as styled }"), o = o.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), o;
|
451
|
+
}
|
452
|
+
} catch (n) {
|
453
|
+
console.error("Error in minimizeFile:", n);
|
454
|
+
}
|
455
|
+
};
|
456
|
+
export {
|
457
|
+
Jt as a,
|
458
|
+
At as g,
|
459
|
+
Wt as m,
|
460
|
+
Pt as s
|
461
|
+
};
|
@@ -0,0 +1,36 @@
|
|
1
|
+
"use strict";const yt=require("esbuild"),gt=require("child_process"),a=require("path"),f=require("fs"),H=require("fs/promises"),z=require("winston");var Z=typeof document<"u"?document.currentScript:null;function ht(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 Q=ht(yt),X=t=>String.fromCharCode(t+(t>25?39:97)),mt=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=X(n%52)+s;return s=X(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},$t=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},I=(t,e=5)=>{const s=$t(5381,JSON.stringify(t))>>>0;return mt(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 St=(t,e)=>{if(typeof t!="string")return{result:t};if(!e)return{result:t};const s=[];return Object.values(e).forEach(n=>{const{pattern:i,transform:r}=n;t=t.replace(i,u=>{const{value:d,css:c}=r(u);return c&&s.push(c),d})}),{result:t,additionalCss:s}},v=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${R(n[1].replaceAll(".","-"))})`)}:{result:t},V=(t,e,s)=>{if(!t)return"";const n=[],i=Object.entries(t).reduce((u,[d,c])=>{const o=d.trim();if(typeof c=="function"&&(c=c()),typeof c=="object"){if(!c)return u;if(o==="variants")return Object.entries(c).forEach(([l,m])=>{m&&Object.entries(m).forEach(([D,w])=>{if(!w)return;const N=`${e}.${l}-${D}`,k=V(w,N);n.push(k)})}),u;if(o==="defaultVariants")return u;if(o==="compoundVariants")return c.forEach(l=>{const{css:m,...D}=l,w=Object.entries(D).reduce((k,[y,$])=>`${k}.${y}-${$}`,e),N=V(m,w);n.push(N)}),u;if(o.startsWith("@")){const l=V(c,e),m=`${o} {
|
2
|
+
${l.replace(`
|
3
|
+
`,`
|
4
|
+
`)}
|
5
|
+
}`;return n.push(m),u}const p=d.includes("&")?o.replace("&",e):o.startsWith(":")?`${e}${o}`:`${e} ${o}`,j=V(c,p);return n.push(j),u}const g=o.startsWith("-")?o:R(o),h=(p,j=";")=>u=`${u}${p}${j}`,C=p=>h(`${g}:${p}`);if(typeof c=="number")return C(c);if(typeof c!="string")if("toString"in c)c=c.toString();else return u;const{modifiers:x}={},E=function*(){yield v(c),yield St(c,x)}();for(const{result:p,additionalCss:j=[]}of E)c=p,j.forEach(l=>{const m=V(l,"");h(m,"")});return C(c)},"");return i?e?[`${e} { ${i} }`,...n].join(`
|
6
|
+
`):i:n.join(`
|
7
|
+
`)},tt=(t,e=[])=>{if(!t)return"";const s=[],n={};if(Object.entries(t).forEach(([i,r])=>{if(typeof r=="object"){if(!r)return;const u=i.trim(),d=tt(r,[...e,u]);s.push(d)}else n[i]=r}),Object.keys(n).length){const i=e.map(R).join("-"),r=V(n,`.${i}`);s.push(r)}return s.join(`
|
8
|
+
`)},jt=t=>Object.entries(t).reduce((e,[s,n])=>(typeof n=="object"&&(e[s]=et(n).map(i=>`"${i}"`).join(" | ")),e),{}),et=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,i])=>{const r=e?`${e}.${n}`:n;return typeof i=="object"?et(i,r,s):s.add(e)}),[...s]):[],st=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=a.join(t,"package.json");return f.existsSync(e)?e:st(a.join(t,".."))},bt=async t=>{const e=st(t);return await H.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},wt=async t=>{const e=await bt(t);if(e)return e.type};let J;const nt=async t=>{if(J)return J;const e=await wt(t);return e==="module"?J="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:Z&&Z.tagName.toUpperCase()==="SCRIPT"&&Z.src||new URL("index-iYTih5G5.cjs",document.baseURI).href).endsWith(".cjs"))&&(J="cjs"),J||"esm"},q=z.createLogger({level:"debug",format:z.format.combine(z.format.colorize(),z.format.cli()),transports:[new z.transports.Console({})]});function ot(t){return t?typeof t!="string"?ot(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 Ft={"*, *::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"}},O={externalModules:[],rcFile:void 0,destDir:void 0},rt=t=>{if(O.externalModules.length>0)return O.externalModules;const s=f.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(i=>i.replace(/['"`]/g,"").trim());return O.externalModules=n,n},W=async t=>{if(O.destDir)return O.destDir;const e=await B(t),s=a.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return O.destDir=s,s},it=["salty","css","styles","styled"],ct=(t=[])=>new RegExp(`\\.(${[...it,...t].join("|")})\\.`),L=(t,e=[])=>ct(e).test(t),at=async t=>{if(O.rcFile)return O.rcFile;if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=a.join(t,".saltyrc.json"),s=await H.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(O.rcFile=s,s):at(a.join(t,".."))},B=async t=>{var n,i;const e=await at(t),s=(n=e.projects)==null?void 0:n.find(r=>t.endsWith(r.dir||""));return s||((i=e.projects)==null?void 0:i.find(r=>r.dir===e.defaultProject))},Ct=async t=>{const e=await B(t),s=await W(t),n=a.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),i=a.join(s,"salty.config.js"),r=await nt(t),u=rt(n);await Q.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:i,format:r,external:u});const d=Date.now(),{config:c}=await import(`${i}?t=${d}`);return c},xt=async t=>{const e=await Ct(t),s=new Set,n=(y,$=[])=>y?Object.entries(y).flatMap(([F,S])=>{if(!S)return;if(typeof S=="object")return n(S,[...$,F]);const M=ot(F),A=R(F),T=[...$,M].join(".");s.add(`"${T}"`);const P=[...$.map(R),A].join("-"),{result:_}=v(S);return`--${P}: ${_};`}):[],i=y=>y?Object.entries(y).flatMap(([$,F])=>{const S=n(F);return $==="base"?S.join(""):`${$} { ${S.join("")} }`}):[],r=y=>y?Object.entries(y).flatMap(([$,F])=>Object.entries(F).flatMap(([S,M])=>{const A=n(M,[$]),T=`.${$}-${S}, [data-${$}="${S}"]`,P=A.join("");return`${T} { ${P} }`})):[],u=n(e.variables),d=i(e.responsiveVariables),c=r(e.conditionalVariables),o=await W(t),g=a.join(o,"css/_variables.css"),h=`:root { ${u.join("")} ${d.join("")} } ${c.join("")}`;f.writeFileSync(g,h);const C=a.join(o,"css/_global.css"),x=V(e.global,"");f.writeFileSync(C,`@layer global { ${x} }`);const b=a.join(o,"css/_reset.css"),p=e.reset==="none"?{}:typeof e.reset=="object"?e.reset:Ft,j=V(p,"");f.writeFileSync(b,`@layer reset { ${j} }`);const l=a.join(o,"css/_templates.css"),m=tt(e.templates),D=jt(e.templates);f.writeFileSync(l,m);const w=a.join(o,"types/css-tokens.d.ts"),k=`
|
9
|
+
// Variable types
|
10
|
+
type VariableTokens = ${[...s].join("|")};
|
11
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
12
|
+
|
13
|
+
// Template types
|
14
|
+
type TemplateTokens = {
|
15
|
+
${Object.entries(D).map(([y,$])=>`${y}?: ${$}`).join(`
|
16
|
+
`)}
|
17
|
+
}
|
18
|
+
`;f.writeFileSync(w,k)},Y=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 u=i.exec(t);if(u){const d=u.at(1);if(it.some(o=>d==null?void 0:d.includes(o)))return e}return"styled('div',"}),K=async(t,e,s)=>{const n=I(e),i=a.join(s,"./temp");f.existsSync(i)||f.mkdirSync(i);const r=a.parse(e);let u=f.readFileSync(e,"utf8");u=Y(u);const d=a.join(s,"js",n+".js"),c=await B(t),o=a.join(t,(c==null?void 0:c.configDir)||"","salty.config.ts"),g=rt(o),h=await nt(t);await Q.build({stdin:{contents:u,sourcefile:r.base,resolveDir:r.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:d,format:h,target:["node20"],keepNames:!0,external:g,packages:"external",plugins:[{name:"test",setup:b=>{b.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},E=>{const p=f.readFileSync(E.path,"utf8");return{contents:Y(p),loader:"ts"}})}}]});const C=Date.now();return await import(`${d}?t=${C}`)},G=async t=>{const e=await W(t),s=a.join(e,"salty.config.js"),n=Date.now(),{config:i}=await import(`${s}?t=${n}`);return i},lt=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},kt=async(t,e=lt())=>{try{const s=Date.now();e?q.info("Generating CSS in production mode! 🔥"):q.info("Generating CSS in development mode! 🚀");const n=[],i=[],r=await W(t),u=a.join(r,"index.css");(()=>{f.existsSync(r)&>.execSync("rm -rf "+r),f.mkdirSync(r,{recursive:!0}),f.mkdirSync(a.join(r,"css")),f.mkdirSync(a.join(r,"types"))})(),await xt(t);const c=await G(t);async function o(l,m){const D=["node_modules","saltygen"],w=f.statSync(l);if(w.isDirectory()){const N=f.readdirSync(l);if(D.some(y=>l.includes(y)))return;await Promise.all(N.map(y=>o(a.join(l,y),a.join(m,y))))}else if(w.isFile()&&L(l)){const k=await K(t,l,r),y=[];Object.entries(k).forEach(([T,P])=>{if(P.isKeyframes&&P.css){const U=`a_${P.animationName}.css`,dt=`css/${U}`,pt=a.join(r,dt);n.push(U),f.writeFileSync(pt,P.css);return}if(!P.generator)return;const _=P.generator._withBuildContext({name:T,config:c,prod:e});i[_.priority]||(i[_.priority]=[]),i[_.priority].push(_.cssFileName),y.push(_.cssFileName);const ft=`css/${_.cssFileName}`,ut=a.join(r,ft);f.writeFileSync(ut,_.css)});const $=y.map(T=>`@import url('./${T}');`).join(`
|
19
|
+
`),F=I(l,6),S=a.parse(l),M=R(S.name),A=a.join(r,`css/f_${M}-${F}.css`);f.writeFileSync(A,$)}}await o(t,r);const g=n.map(l=>`@import url('./css/${l}');`).join(`
|
20
|
+
`);let b=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
21
|
+
|
22
|
+
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(l=>{try{return f.readFileSync(a.join(r,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
|
23
|
+
`)}
|
24
|
+
${g}`;if(c.importStrategy!=="component"){const l=i.reduce((m,D,w)=>{const N=D.reduce((F,S)=>{var P;const M=a.join(r,"css",S),A=f.readFileSync(M,"utf8"),T=((P=/.*-([^-]+)-\d+.css/.exec(S))==null?void 0:P.at(1))||I(M,6);return F.includes(T)?F:`${F}
|
25
|
+
/*start:${T}*/
|
26
|
+
${A}
|
27
|
+
/*end:${T}*/
|
28
|
+
`},""),k=`l_${w}.css`,y=a.join(r,"css",k),$=`@layer l${w} { ${N}
|
29
|
+
}`;return f.writeFileSync(y,$),`${m}
|
30
|
+
@import url('./css/${k}');`},"");b+=l}f.writeFileSync(u,b);const p=Date.now()-s,j=p<200?"🔥":p<500?"🚀":p<1e3?"🎉":p<2e3?"🚗":p<5e3?"🤔":"🥴";q.info(`Generated CSS in ${p}ms! ${j}`)}catch(s){console.error(s)}},Pt=async(t,e)=>{try{const s=await W(t);if(L(e)){const i=[],r=await G(t),u=await K(t,e,s);Object.entries(u).forEach(([d,c])=>{if(c.isKeyframes&&c.css){const x=`css/${`a_${c.animationName}.css`}`,b=a.join(s,x);f.writeFileSync(b,c.css);return}if(!c.generator)return;const o=c.generator._withBuildContext({name:d,config:r}),g=`css/${o.cssFileName}`,h=a.join(s,g);f.writeFileSync(h,o.css),i[o.priority]||(i[o.priority]=[]),i[o.priority].push(o.cssFileName)}),r.importStrategy!=="component"&&i.forEach((d,c)=>{const o=`l_${c}.css`,g=a.join(s,"css",o);let h=f.readFileSync(g,"utf8");d.forEach(C=>{var p;const x=a.join(s,"css",C),b=((p=/.*-([^-]+)-\d+.css/.exec(C))==null?void 0:p.at(1))||I(x,6);if(!h.includes(b)){const j=f.readFileSync(x,"utf8"),l=`/*start:${b}*/
|
31
|
+
${j}
|
32
|
+
/*end:${b}*/
|
33
|
+
`;h=`${h.replace(/\}$/,"")}
|
34
|
+
${l}
|
35
|
+
}`}}),f.writeFileSync(g,h)})}}catch(s){console.error(s)}},Dt=async(t,e,s=lt())=>{try{const n=await W(t);if(L(e)){const r=f.readFileSync(e,"utf8");r.replace(/^(?!export\s)const\s.*/gm,g=>`export ${g}`)!==r&&await H.writeFile(e,r);const d=await G(t),c=await K(t,e,n);let o=r;if(Object.entries(c).forEach(([g,h])=>{var F;if(h.isKeyframes||!h.generator)return;const C=h.generator._withBuildContext({name:g,config:d,prod:s}),x=new RegExp(`\\s${g}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(r);if(!x)return console.error("Could not find the original declaration");const b=(F=x.at(1))==null?void 0:F.trim(),E=new RegExp(`\\s${g}[=\\s]+styled\\(`,"g").exec(o);if(!E)return console.error("Could not find the original declaration");const{index:p}=E;let j=!1;const l=setTimeout(()=>j=!0,5e3);let m=0,D=!1,w=0;for(;!D&&!j;){const S=o[p+m];S==="("&&w++,S===")"&&w--,w===0&&S===")"&&(D=!0),m>o.length&&(j=!0),m++}if(!j)clearTimeout(l);else throw new Error("Failed to find the end of the styled call and timed out");const N=p+m,k=o.slice(p,N),y=o,$=` ${g} = styled(${b}, "${C.classNames}", ${JSON.stringify(C.props)});`;o=o.replace(k,$),y===o&&console.error("Minimize file failed to change content",{name:g,tagName:b})}),d.importStrategy==="component"){const g=I(e,6),h=a.parse(e);o=`import '../../saltygen/css/${`f_${R(h.name)}-${g}.css`}';
|
36
|
+
${o}`}return o=o.replace("{ styled }","{ styledClient as styled }"),o=o.replace("@salty-css/react/styled","@salty-css/react/styled-client"),o}}catch(n){console.error("Error in minimizeFile:",n)}};exports.generateCss=kt;exports.generateFile=Pt;exports.minimizeFile=Dt;exports.saltyFileRegExp=ct;
|
package/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=require("path"),u=require("./index-
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=require("path"),u=require("./index-iYTih5G5.cjs"),r=(e,s,o=!1,n=!1)=>{var a,l,t;(l=(a=e.module)==null?void 0:a.rules)==null||l.push({test:u.saltyFileRegExp(),use:[{loader:p.resolve(__dirname,n?"./loader.cjs":"./loader.js"),options:{dir:s}}]}),o||(t=e.plugins)==null||t.push({apply:i=>{i.hooks.afterPlugins.tap({name:"generateCss"},async()=>{await u.generateCss(s)})}})};exports.default=r;exports.saltyPlugin=r;
|
package/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { resolve as n } from "path";
|
2
|
-
import { s as u, g as i } from "./index-
|
2
|
+
import { s as u, g as i } from "./index-DRE0kJhP.js";
|
3
3
|
const g = (s, e, o = !1, r = !1) => {
|
4
4
|
var a, l, t;
|
5
5
|
(l = (a = s.module) == null ? void 0 : a.rules) == null || l.push({
|
package/loader.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";const i=require("./index-
|
1
|
+
"use strict";const i=require("./index-iYTih5G5.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.148",
|
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.148",
|
38
38
|
"webpack": ">=5.x"
|
39
39
|
}
|
40
40
|
}
|
package/index-D8HB2lym.js
DELETED
@@ -1,454 +0,0 @@
|
|
1
|
-
import * as v from "esbuild";
|
2
|
-
import { execSync as mt } from "child_process";
|
3
|
-
import { join as a, parse as B } from "path";
|
4
|
-
import { existsSync as K, writeFileSync as N, readFileSync as M, mkdirSync as z, statSync as ht, readdirSync as $t } from "fs";
|
5
|
-
import { readFile as tt, writeFile as bt } from "fs/promises";
|
6
|
-
import { createLogger as St, format as H, transports as wt } from "winston";
|
7
|
-
const Y = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), jt = (t, e) => {
|
8
|
-
let s = "", n;
|
9
|
-
for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = Y(n % 52) + s;
|
10
|
-
return s = Y(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
|
11
|
-
}, Ct = (t, e) => {
|
12
|
-
let s = e.length;
|
13
|
-
for (; s; ) t = t * 33 ^ e.charCodeAt(--s);
|
14
|
-
return t;
|
15
|
-
}, W = (t, e = 5) => {
|
16
|
-
const s = Ct(5381, JSON.stringify(t)) >>> 0;
|
17
|
-
return jt(s, e);
|
18
|
-
};
|
19
|
-
function R(t) {
|
20
|
-
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()) : "";
|
21
|
-
}
|
22
|
-
const xt = (t, e) => {
|
23
|
-
if (typeof t != "string") return { result: t };
|
24
|
-
if (!e) return { result: t };
|
25
|
-
const s = [];
|
26
|
-
return Object.values(e).forEach((n) => {
|
27
|
-
const { pattern: i, transform: r } = n;
|
28
|
-
t = t.replace(i, (f) => {
|
29
|
-
const { value: p, css: c } = r(f);
|
30
|
-
return c && s.push(c), p;
|
31
|
-
});
|
32
|
-
}), { result: t, additionalCss: s };
|
33
|
-
}, et = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${R(n[1].replaceAll(".", "-"))})`) } : { result: t }, _ = (t, e, s) => {
|
34
|
-
if (!t) return "";
|
35
|
-
const n = [], i = Object.entries(t).reduce((f, [p, c]) => {
|
36
|
-
const o = p.trim();
|
37
|
-
if (typeof c == "function" && (c = c()), typeof c == "object") {
|
38
|
-
if (!c) return f;
|
39
|
-
if (o === "variants")
|
40
|
-
return Object.entries(c).forEach(([l, m]) => {
|
41
|
-
m && Object.entries(m).forEach(([P, w]) => {
|
42
|
-
if (!w) return;
|
43
|
-
const E = `${e}.${l}-${P}`, F = _(w, E);
|
44
|
-
n.push(F);
|
45
|
-
});
|
46
|
-
}), f;
|
47
|
-
if (o === "defaultVariants")
|
48
|
-
return f;
|
49
|
-
if (o === "compoundVariants")
|
50
|
-
return c.forEach((l) => {
|
51
|
-
const { css: m, ...P } = l, w = Object.entries(P).reduce((F, [d, h]) => `${F}.${d}-${h}`, e), E = _(m, w);
|
52
|
-
n.push(E);
|
53
|
-
}), f;
|
54
|
-
if (o.startsWith("@")) {
|
55
|
-
const l = _(c, e), m = `${o} {
|
56
|
-
${l.replace(`
|
57
|
-
`, `
|
58
|
-
`)}
|
59
|
-
}`;
|
60
|
-
return n.push(m), f;
|
61
|
-
}
|
62
|
-
const u = p.includes("&") ? o.replace("&", e) : o.startsWith(":") ? `${e}${o}` : `${e} ${o}`, b = _(c, u);
|
63
|
-
return n.push(b), f;
|
64
|
-
}
|
65
|
-
const g = o.startsWith("-") ? o : R(o), y = (u, b = ";") => f = `${f}${u}${b}`, C = (u) => y(`${g}:${u}`);
|
66
|
-
if (typeof c == "number") return C(c);
|
67
|
-
if (typeof c != "string")
|
68
|
-
if ("toString" in c) c = c.toString();
|
69
|
-
else return f;
|
70
|
-
const { modifiers: x } = {}, D = function* () {
|
71
|
-
yield et(c), yield xt(c, x);
|
72
|
-
}();
|
73
|
-
for (const { result: u, additionalCss: b = [] } of D)
|
74
|
-
c = u, b.forEach((l) => {
|
75
|
-
const m = _(l, "");
|
76
|
-
y(m, "");
|
77
|
-
});
|
78
|
-
return C(c);
|
79
|
-
}, "");
|
80
|
-
return i ? e ? [`${e} { ${i} }`, ...n].join(`
|
81
|
-
`) : i : n.join(`
|
82
|
-
`);
|
83
|
-
}, st = (t, e = []) => {
|
84
|
-
if (!t) return "";
|
85
|
-
const s = [], n = {};
|
86
|
-
if (Object.entries(t).forEach(([i, r]) => {
|
87
|
-
if (typeof r == "object") {
|
88
|
-
if (!r) return;
|
89
|
-
const f = i.trim(), p = st(r, [...e, f]);
|
90
|
-
s.push(p);
|
91
|
-
} else
|
92
|
-
n[i] = r;
|
93
|
-
}), Object.keys(n).length) {
|
94
|
-
const i = e.map(R).join("-"), r = _(n, `.${i}`);
|
95
|
-
s.push(r);
|
96
|
-
}
|
97
|
-
return s.join(`
|
98
|
-
`);
|
99
|
-
}, Ft = (t) => Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = nt(n).map((i) => `"${i}"`).join(" | ")), e), {}), nt = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, i]) => {
|
100
|
-
const r = e ? `${e}.${n}` : n;
|
101
|
-
return typeof i == "object" ? nt(i, r, s) : s.add(e);
|
102
|
-
}), [...s]) : [], ot = (t) => {
|
103
|
-
if (!t || t === "/") throw new Error("Could not find package.json file");
|
104
|
-
const e = a(t, "package.json");
|
105
|
-
return K(e) ? e : ot(a(t, ".."));
|
106
|
-
}, kt = async (t) => {
|
107
|
-
const e = ot(t);
|
108
|
-
return await tt(e, "utf-8").then(JSON.parse).catch(() => {
|
109
|
-
});
|
110
|
-
}, Nt = async (t) => {
|
111
|
-
const e = await kt(t);
|
112
|
-
if (e)
|
113
|
-
return e.type;
|
114
|
-
};
|
115
|
-
let J;
|
116
|
-
const rt = async (t) => {
|
117
|
-
if (J) return J;
|
118
|
-
const e = await Nt(t);
|
119
|
-
return e === "module" ? J = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (J = "cjs"), J || "esm";
|
120
|
-
}, I = St({
|
121
|
-
level: "debug",
|
122
|
-
format: H.combine(H.colorize(), H.cli()),
|
123
|
-
transports: [new wt.Console({})]
|
124
|
-
});
|
125
|
-
function it(t) {
|
126
|
-
return t ? typeof t != "string" ? it(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "." : "") + e.toLowerCase()) : "";
|
127
|
-
}
|
128
|
-
const Pt = {
|
129
|
-
/** Set box model to border-box */
|
130
|
-
"*, *::before, *::after": {
|
131
|
-
boxSizing: "border-box"
|
132
|
-
},
|
133
|
-
/** Remove default margin and padding */
|
134
|
-
"*": {
|
135
|
-
margin: 0
|
136
|
-
},
|
137
|
-
/** Remove adjust font properties */
|
138
|
-
html: {
|
139
|
-
lineHeight: 1.15,
|
140
|
-
textSizeAdjust: "100%",
|
141
|
-
WebkitFontSmoothing: "antialiased"
|
142
|
-
},
|
143
|
-
/** Make media elements responsive */
|
144
|
-
"img, picture, video, canvas, svg": {
|
145
|
-
display: "block",
|
146
|
-
maxWidth: "100%"
|
147
|
-
},
|
148
|
-
/** Avoid overflow of text */
|
149
|
-
"p, h1, h2, h3, h4, h5, h6": {
|
150
|
-
overflowWrap: "break-word"
|
151
|
-
},
|
152
|
-
/** Improve text wrapping */
|
153
|
-
p: {
|
154
|
-
textWrap: "pretty"
|
155
|
-
},
|
156
|
-
"h1, h2, h3, h4, h5, h6": {
|
157
|
-
textWrap: "balance"
|
158
|
-
},
|
159
|
-
/** Improve link color */
|
160
|
-
a: {
|
161
|
-
color: "currentColor"
|
162
|
-
},
|
163
|
-
/** Improve button line height */
|
164
|
-
button: {
|
165
|
-
lineHeight: "1em",
|
166
|
-
color: "currentColor"
|
167
|
-
},
|
168
|
-
/** Improve form elements */
|
169
|
-
"input, optgroup, select, textarea": {
|
170
|
-
fontFamily: "inherit",
|
171
|
-
fontSize: "100%",
|
172
|
-
lineHeight: "1.15em"
|
173
|
-
}
|
174
|
-
}, L = {
|
175
|
-
externalModules: []
|
176
|
-
}, ct = (t) => {
|
177
|
-
if (L.externalModules.length > 0) return L.externalModules;
|
178
|
-
const s = M(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
179
|
-
if (!s) return [];
|
180
|
-
const n = s[1].split(",").map((i) => i.replace(/['"`]/g, "").trim());
|
181
|
-
return L.externalModules = n, n;
|
182
|
-
}, Z = (t) => a(t, "./saltygen"), at = ["salty", "css", "styles", "styled"], Et = (t = []) => new RegExp(`\\.(${[...at, ...t].join("|")})\\.`), G = (t, e = []) => Et(e).test(t), lt = async (t) => {
|
183
|
-
if (t === "/") throw new Error("Could not find .saltyrc.json file");
|
184
|
-
const e = a(t, ".saltyrc.json"), s = await tt(e, "utf-8").then(JSON.parse).catch(() => {
|
185
|
-
});
|
186
|
-
return s || lt(a(t, ".."));
|
187
|
-
}, ft = async (t) => {
|
188
|
-
var n, i;
|
189
|
-
const e = await lt(t), s = (n = e.projects) == null ? void 0 : n.find((r) => t.endsWith(r.dir || ""));
|
190
|
-
return s || ((i = e.projects) == null ? void 0 : i.find((r) => r.dir === e.defaultProject));
|
191
|
-
}, Tt = async (t) => {
|
192
|
-
const e = await ft(t), s = Z(t), n = a(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), i = a(s, "salty.config.js"), r = await rt(t), f = ct(n);
|
193
|
-
await v.build({
|
194
|
-
entryPoints: [n],
|
195
|
-
minify: !0,
|
196
|
-
treeShaking: !0,
|
197
|
-
bundle: !0,
|
198
|
-
outfile: i,
|
199
|
-
format: r,
|
200
|
-
external: f
|
201
|
-
});
|
202
|
-
const p = Date.now(), { config: c } = await import(`${i}?t=${p}`);
|
203
|
-
return c;
|
204
|
-
}, Dt = async (t) => {
|
205
|
-
const e = await Tt(t), s = /* @__PURE__ */ new Set(), n = (d, h = []) => d ? Object.entries(d).flatMap(([j, $]) => {
|
206
|
-
if (!$) return;
|
207
|
-
if (typeof $ == "object") return n($, [...h, j]);
|
208
|
-
const V = it(j), A = R(j), T = [...h, V].join(".");
|
209
|
-
s.add(`"${T}"`);
|
210
|
-
const k = [...h.map(R), A].join("-"), { result: O } = et($);
|
211
|
-
return `--${k}: ${O};`;
|
212
|
-
}) : [], i = (d) => d ? Object.entries(d).flatMap(([h, j]) => {
|
213
|
-
const $ = n(j);
|
214
|
-
return h === "base" ? $.join("") : `${h} { ${$.join("")} }`;
|
215
|
-
}) : [], r = (d) => d ? Object.entries(d).flatMap(([h, j]) => Object.entries(j).flatMap(([$, V]) => {
|
216
|
-
const A = n(V, [h]), T = `.${h}-${$}, [data-${h}="${$}"]`, k = A.join("");
|
217
|
-
return `${T} { ${k} }`;
|
218
|
-
})) : [], f = n(e.variables), p = i(e.responsiveVariables), c = r(e.conditionalVariables), o = Z(t), g = a(o, "css/_variables.css"), y = `:root { ${f.join("")} ${p.join("")} } ${c.join("")}`;
|
219
|
-
N(g, y);
|
220
|
-
const C = a(o, "css/_global.css"), x = _(e.global, "");
|
221
|
-
N(C, `@layer global { ${x} }`);
|
222
|
-
const S = a(o, "css/_reset.css"), u = e.reset === "none" ? {} : typeof e.reset == "object" ? e.reset : Pt, b = _(u, "");
|
223
|
-
N(S, `@layer reset { ${b} }`);
|
224
|
-
const l = a(o, "css/_templates.css"), m = st(e.templates), P = Ft(e.templates);
|
225
|
-
N(l, m);
|
226
|
-
const w = a(o, "types/css-tokens.d.ts"), F = `
|
227
|
-
// Variable types
|
228
|
-
type VariableTokens = ${[...s].join("|")};
|
229
|
-
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
230
|
-
|
231
|
-
// Template types
|
232
|
-
type TemplateTokens = {
|
233
|
-
${Object.entries(P).map(([d, h]) => `${d}?: ${h}`).join(`
|
234
|
-
`)}
|
235
|
-
}
|
236
|
-
`;
|
237
|
-
N(w, F);
|
238
|
-
}, Q = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
|
239
|
-
if (/^['"`]/.test(s)) return e;
|
240
|
-
const i = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
|
241
|
-
if (!i.test(t)) return e;
|
242
|
-
const f = i.exec(t);
|
243
|
-
if (f) {
|
244
|
-
const p = f.at(1);
|
245
|
-
if (at.some((o) => p == null ? void 0 : p.includes(o))) return e;
|
246
|
-
}
|
247
|
-
return "styled('div',";
|
248
|
-
}), q = async (t, e, s) => {
|
249
|
-
const n = W(e), i = a(s, "./temp");
|
250
|
-
K(i) || z(i);
|
251
|
-
const r = B(e);
|
252
|
-
let f = M(e, "utf8");
|
253
|
-
f = Q(f);
|
254
|
-
const p = a(s, "js", n + ".js"), c = await ft(t), o = a(t, (c == null ? void 0 : c.configDir) || "", "salty.config.ts"), g = ct(o), y = await rt(t);
|
255
|
-
await v.build({
|
256
|
-
stdin: {
|
257
|
-
contents: f,
|
258
|
-
sourcefile: r.base,
|
259
|
-
resolveDir: r.dir,
|
260
|
-
loader: "tsx"
|
261
|
-
},
|
262
|
-
minify: !1,
|
263
|
-
treeShaking: !0,
|
264
|
-
bundle: !0,
|
265
|
-
outfile: p,
|
266
|
-
format: y,
|
267
|
-
target: ["node20"],
|
268
|
-
keepNames: !0,
|
269
|
-
external: g,
|
270
|
-
packages: "external",
|
271
|
-
plugins: [
|
272
|
-
{
|
273
|
-
name: "test",
|
274
|
-
setup: (S) => {
|
275
|
-
S.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (D) => {
|
276
|
-
const u = M(D.path, "utf8");
|
277
|
-
return { contents: Q(u), loader: "ts" };
|
278
|
-
});
|
279
|
-
}
|
280
|
-
}
|
281
|
-
]
|
282
|
-
});
|
283
|
-
const C = Date.now();
|
284
|
-
return await import(`${p}?t=${C}`);
|
285
|
-
}, U = async (t) => {
|
286
|
-
const e = Z(t), s = a(e, "salty.config.js"), n = Date.now(), { config: i } = await import(`${s}?t=${n}`);
|
287
|
-
return i;
|
288
|
-
}, pt = () => {
|
289
|
-
try {
|
290
|
-
return process.env.NODE_ENV === "production";
|
291
|
-
} catch {
|
292
|
-
return !1;
|
293
|
-
}
|
294
|
-
}, At = async (t, e = pt()) => {
|
295
|
-
try {
|
296
|
-
const s = Date.now();
|
297
|
-
e ? I.info("Generating CSS in production mode! 🔥") : I.info("Generating CSS in development mode! 🚀");
|
298
|
-
const n = [], i = [], r = Z(t), f = a(r, "index.css");
|
299
|
-
(() => {
|
300
|
-
K(r) && mt("rm -rf " + r), z(r), z(a(r, "css")), z(a(r, "types"));
|
301
|
-
})(), await Dt(t);
|
302
|
-
const c = await U(t);
|
303
|
-
async function o(l, m) {
|
304
|
-
const P = ["node_modules", "saltygen"], w = ht(l);
|
305
|
-
if (w.isDirectory()) {
|
306
|
-
const E = $t(l);
|
307
|
-
if (P.some((d) => l.includes(d))) return;
|
308
|
-
await Promise.all(E.map((d) => o(a(l, d), a(m, d))));
|
309
|
-
} else if (w.isFile() && G(l)) {
|
310
|
-
const F = await q(t, l, r), d = [];
|
311
|
-
Object.entries(F).forEach(([T, k]) => {
|
312
|
-
if (k.isKeyframes && k.css) {
|
313
|
-
const X = `a_${k.animationName}.css`, gt = `css/${X}`, yt = a(r, gt);
|
314
|
-
n.push(X), N(yt, k.css);
|
315
|
-
return;
|
316
|
-
}
|
317
|
-
if (!k.generator) return;
|
318
|
-
const O = k.generator._withBuildContext({
|
319
|
-
name: T,
|
320
|
-
config: c,
|
321
|
-
prod: e
|
322
|
-
});
|
323
|
-
i[O.priority] || (i[O.priority] = []), i[O.priority].push(O.cssFileName), d.push(O.cssFileName);
|
324
|
-
const ut = `css/${O.cssFileName}`, dt = a(r, ut);
|
325
|
-
N(dt, O.css);
|
326
|
-
});
|
327
|
-
const h = d.map((T) => `@import url('./${T}');`).join(`
|
328
|
-
`), j = W(l, 6), $ = B(l), V = R($.name), A = a(r, `css/f_${V}-${j}.css`);
|
329
|
-
N(A, h);
|
330
|
-
}
|
331
|
-
}
|
332
|
-
await o(t, r);
|
333
|
-
const g = n.map((l) => `@import url('./css/${l}');`).join(`
|
334
|
-
`);
|
335
|
-
let S = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
336
|
-
|
337
|
-
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) => {
|
338
|
-
try {
|
339
|
-
return M(a(r, "css", l), "utf8").length > 0;
|
340
|
-
} catch {
|
341
|
-
return !1;
|
342
|
-
}
|
343
|
-
}).map((l) => `@import url('./css/${l}');`).join(`
|
344
|
-
`)}
|
345
|
-
${g}`;
|
346
|
-
if (c.importStrategy !== "component") {
|
347
|
-
const l = i.reduce((m, P, w) => {
|
348
|
-
const E = P.reduce((j, $) => {
|
349
|
-
var k;
|
350
|
-
const V = a(r, "css", $), A = M(V, "utf8"), T = ((k = /.*-([^-]+)-\d+.css/.exec($)) == null ? void 0 : k.at(1)) || W(V, 6);
|
351
|
-
return j.includes(T) ? j : `${j}
|
352
|
-
/*start:${T}*/
|
353
|
-
${A}
|
354
|
-
/*end:${T}*/
|
355
|
-
`;
|
356
|
-
}, ""), F = `l_${w}.css`, d = a(r, "css", F), h = `@layer l${w} { ${E}
|
357
|
-
}`;
|
358
|
-
return N(d, h), `${m}
|
359
|
-
@import url('./css/${F}');`;
|
360
|
-
}, "");
|
361
|
-
S += l;
|
362
|
-
}
|
363
|
-
N(f, S);
|
364
|
-
const u = Date.now() - s, b = u < 200 ? "🔥" : u < 500 ? "🚀" : u < 1e3 ? "🎉" : u < 2e3 ? "🚗" : u < 5e3 ? "🤔" : "🥴";
|
365
|
-
I.info(`Generated CSS in ${u}ms! ${b}`);
|
366
|
-
} catch (s) {
|
367
|
-
console.error(s);
|
368
|
-
}
|
369
|
-
}, Jt = async (t, e) => {
|
370
|
-
try {
|
371
|
-
const s = a(t, "./saltygen");
|
372
|
-
if (G(e)) {
|
373
|
-
const i = [], r = await U(t), f = await q(t, e, s);
|
374
|
-
Object.entries(f).forEach(([p, c]) => {
|
375
|
-
if (c.isKeyframes && c.css) {
|
376
|
-
const x = `css/${`a_${c.animationName}.css`}`, S = a(s, x);
|
377
|
-
N(S, c.css);
|
378
|
-
return;
|
379
|
-
}
|
380
|
-
if (!c.generator) return;
|
381
|
-
const o = c.generator._withBuildContext({
|
382
|
-
name: p,
|
383
|
-
config: r
|
384
|
-
}), g = `css/${o.cssFileName}`, y = a(s, g);
|
385
|
-
N(y, o.css), i[o.priority] || (i[o.priority] = []), i[o.priority].push(o.cssFileName);
|
386
|
-
}), r.importStrategy !== "component" && i.forEach((p, c) => {
|
387
|
-
const o = `l_${c}.css`, g = a(s, "css", o);
|
388
|
-
let y = M(g, "utf8");
|
389
|
-
p.forEach((C) => {
|
390
|
-
var u;
|
391
|
-
const x = a(s, "css", C), S = ((u = /.*-([^-]+)-\d+.css/.exec(C)) == null ? void 0 : u.at(1)) || W(x, 6);
|
392
|
-
if (!y.includes(S)) {
|
393
|
-
const b = M(x, "utf8"), l = `/*start:${S}*/
|
394
|
-
${b}
|
395
|
-
/*end:${S}*/
|
396
|
-
`;
|
397
|
-
y = `${y.replace(/\}$/, "")}
|
398
|
-
${l}
|
399
|
-
}`;
|
400
|
-
}
|
401
|
-
}), N(g, y);
|
402
|
-
});
|
403
|
-
}
|
404
|
-
} catch (s) {
|
405
|
-
console.error(s);
|
406
|
-
}
|
407
|
-
}, Wt = async (t, e, s = pt()) => {
|
408
|
-
try {
|
409
|
-
const n = a(t, "./saltygen");
|
410
|
-
if (G(e)) {
|
411
|
-
const r = M(e, "utf8");
|
412
|
-
r.replace(/^(?!export\s)const\s.*/gm, (g) => `export ${g}`) !== r && await bt(e, r);
|
413
|
-
const p = await U(t), c = await q(t, e, n);
|
414
|
-
let o = r;
|
415
|
-
if (Object.entries(c).forEach(([g, y]) => {
|
416
|
-
var j;
|
417
|
-
if (y.isKeyframes || !y.generator) return;
|
418
|
-
const C = y.generator._withBuildContext({
|
419
|
-
name: g,
|
420
|
-
config: p,
|
421
|
-
prod: s
|
422
|
-
}), x = new RegExp(`\\s${g}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
|
423
|
-
if (!x) return console.error("Could not find the original declaration");
|
424
|
-
const S = (j = x.at(1)) == null ? void 0 : j.trim(), D = new RegExp(`\\s${g}[=\\s]+styled\\(`, "g").exec(o);
|
425
|
-
if (!D) return console.error("Could not find the original declaration");
|
426
|
-
const { index: u } = D;
|
427
|
-
let b = !1;
|
428
|
-
const l = setTimeout(() => b = !0, 5e3);
|
429
|
-
let m = 0, P = !1, w = 0;
|
430
|
-
for (; !P && !b; ) {
|
431
|
-
const $ = o[u + m];
|
432
|
-
$ === "(" && w++, $ === ")" && w--, w === 0 && $ === ")" && (P = !0), m > o.length && (b = !0), m++;
|
433
|
-
}
|
434
|
-
if (!b) clearTimeout(l);
|
435
|
-
else throw new Error("Failed to find the end of the styled call and timed out");
|
436
|
-
const E = u + m, F = o.slice(u, E), d = o, h = ` ${g} = styled(${S}, "${C.classNames}", ${JSON.stringify(C.props)});`;
|
437
|
-
o = o.replace(F, h), d === o && console.error("Minimize file failed to change content", { name: g, tagName: S });
|
438
|
-
}), p.importStrategy === "component") {
|
439
|
-
const g = W(e, 6), y = B(e);
|
440
|
-
o = `import '../../saltygen/css/${`f_${R(y.name)}-${g}.css`}';
|
441
|
-
${o}`;
|
442
|
-
}
|
443
|
-
return o = o.replace("{ styled }", "{ styledClient as styled }"), o = o.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), o;
|
444
|
-
}
|
445
|
-
} catch (n) {
|
446
|
-
console.error("Error in minimizeFile:", n);
|
447
|
-
}
|
448
|
-
};
|
449
|
-
export {
|
450
|
-
Jt as a,
|
451
|
-
At as g,
|
452
|
-
Wt as m,
|
453
|
-
Et as s
|
454
|
-
};
|
package/index-D9S9Ox8Q.cjs
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
"use strict";const yt=require("esbuild"),gt=require("child_process"),a=require("path"),f=require("fs"),H=require("fs/promises"),J=require("winston");var I=typeof document<"u"?document.currentScript:null;function mt(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 Y=mt(yt),U=t=>String.fromCharCode(t+(t>25?39:97)),ht=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=U(n%52)+s;return s=U(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},$t=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},W=(t,e=5)=>{const s=$t(5381,JSON.stringify(t))>>>0;return ht(s,e)};function V(t){return t?typeof t!="string"?V(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 jt=(t,e)=>{if(typeof t!="string")return{result:t};if(!e)return{result:t};const s=[];return Object.values(e).forEach(n=>{const{pattern:i,transform:r}=n;t=t.replace(i,u=>{const{value:p,css:c}=r(u);return c&&s.push(c),p})}),{result:t,additionalCss:s}},Q=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${V(n[1].replaceAll(".","-"))})`)}:{result:t},M=(t,e,s)=>{if(!t)return"";const n=[],i=Object.entries(t).reduce((u,[p,c])=>{const o=p.trim();if(typeof c=="function"&&(c=c()),typeof c=="object"){if(!c)return u;if(o==="variants")return Object.entries(c).forEach(([l,h])=>{h&&Object.entries(h).forEach(([N,w])=>{if(!w)return;const T=`${e}.${l}-${N}`,k=M(w,T);n.push(k)})}),u;if(o==="defaultVariants")return u;if(o==="compoundVariants")return c.forEach(l=>{const{css:h,...N}=l,w=Object.entries(N).reduce((k,[y,$])=>`${k}.${y}-${$}`,e),T=M(h,w);n.push(T)}),u;if(o.startsWith("@")){const l=M(c,e),h=`${o} {
|
2
|
-
${l.replace(`
|
3
|
-
`,`
|
4
|
-
`)}
|
5
|
-
}`;return n.push(h),u}const d=p.includes("&")?o.replace("&",e):o.startsWith(":")?`${e}${o}`:`${e} ${o}`,S=M(c,d);return n.push(S),u}const g=o.startsWith("-")?o:V(o),m=(d,S=";")=>u=`${u}${d}${S}`,C=d=>m(`${g}:${d}`);if(typeof c=="number")return C(c);if(typeof c!="string")if("toString"in c)c=c.toString();else return u;const{modifiers:x}={},_=function*(){yield Q(c),yield jt(c,x)}();for(const{result:d,additionalCss:S=[]}of _)c=d,S.forEach(l=>{const h=M(l,"");m(h,"")});return C(c)},"");return i?e?[`${e} { ${i} }`,...n].join(`
|
6
|
-
`):i:n.join(`
|
7
|
-
`)},v=(t,e=[])=>{if(!t)return"";const s=[],n={};if(Object.entries(t).forEach(([i,r])=>{if(typeof r=="object"){if(!r)return;const u=i.trim(),p=v(r,[...e,u]);s.push(p)}else n[i]=r}),Object.keys(n).length){const i=e.map(V).join("-"),r=M(n,`.${i}`);s.push(r)}return s.join(`
|
8
|
-
`)},St=t=>Object.entries(t).reduce((e,[s,n])=>(typeof n=="object"&&(e[s]=tt(n).map(i=>`"${i}"`).join(" | ")),e),{}),tt=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,i])=>{const r=e?`${e}.${n}`:n;return typeof i=="object"?tt(i,r,s):s.add(e)}),[...s]):[],et=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=a.join(t,"package.json");return f.existsSync(e)?e:et(a.join(t,".."))},bt=async t=>{const e=et(t);return await H.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},wt=async t=>{const e=await bt(t);if(e)return e.type};let A;const st=async t=>{if(A)return A;const e=await wt(t);return e==="module"?A="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:I&&I.tagName.toUpperCase()==="SCRIPT"&&I.src||new URL("index-D9S9Ox8Q.cjs",document.baseURI).href).endsWith(".cjs"))&&(A="cjs"),A||"esm"},Z=J.createLogger({level:"debug",format:J.format.combine(J.format.colorize(),J.format.cli()),transports:[new J.transports.Console({})]});function nt(t){return t?typeof t!="string"?nt(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 Ft={"*, *::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"}},q={externalModules:[]},ot=t=>{if(q.externalModules.length>0)return q.externalModules;const s=f.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(i=>i.replace(/['"`]/g,"").trim());return q.externalModules=n,n},z=t=>a.join(t,"./saltygen"),rt=["salty","css","styles","styled"],it=(t=[])=>new RegExp(`\\.(${[...rt,...t].join("|")})\\.`),L=(t,e=[])=>it(e).test(t),ct=async t=>{if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=a.join(t,".saltyrc.json"),s=await H.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s||ct(a.join(t,".."))},at=async t=>{var n,i;const e=await ct(t),s=(n=e.projects)==null?void 0:n.find(r=>t.endsWith(r.dir||""));return s||((i=e.projects)==null?void 0:i.find(r=>r.dir===e.defaultProject))},Ct=async t=>{const e=await at(t),s=z(t),n=a.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),i=a.join(s,"salty.config.js"),r=await st(t),u=ot(n);await Y.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:i,format:r,external:u});const p=Date.now(),{config:c}=await import(`${i}?t=${p}`);return c},xt=async t=>{const e=await Ct(t),s=new Set,n=(y,$=[])=>y?Object.entries(y).flatMap(([F,j])=>{if(!j)return;if(typeof j=="object")return n(j,[...$,F]);const D=nt(F),R=V(F),E=[...$,D].join(".");s.add(`"${E}"`);const P=[...$.map(V),R].join("-"),{result:O}=Q(j);return`--${P}: ${O};`}):[],i=y=>y?Object.entries(y).flatMap(([$,F])=>{const j=n(F);return $==="base"?j.join(""):`${$} { ${j.join("")} }`}):[],r=y=>y?Object.entries(y).flatMap(([$,F])=>Object.entries(F).flatMap(([j,D])=>{const R=n(D,[$]),E=`.${$}-${j}, [data-${$}="${j}"]`,P=R.join("");return`${E} { ${P} }`})):[],u=n(e.variables),p=i(e.responsiveVariables),c=r(e.conditionalVariables),o=z(t),g=a.join(o,"css/_variables.css"),m=`:root { ${u.join("")} ${p.join("")} } ${c.join("")}`;f.writeFileSync(g,m);const C=a.join(o,"css/_global.css"),x=M(e.global,"");f.writeFileSync(C,`@layer global { ${x} }`);const b=a.join(o,"css/_reset.css"),d=e.reset==="none"?{}:typeof e.reset=="object"?e.reset:Ft,S=M(d,"");f.writeFileSync(b,`@layer reset { ${S} }`);const l=a.join(o,"css/_templates.css"),h=v(e.templates),N=St(e.templates);f.writeFileSync(l,h);const w=a.join(o,"types/css-tokens.d.ts"),k=`
|
9
|
-
// Variable types
|
10
|
-
type VariableTokens = ${[...s].join("|")};
|
11
|
-
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
12
|
-
|
13
|
-
// Template types
|
14
|
-
type TemplateTokens = {
|
15
|
-
${Object.entries(N).map(([y,$])=>`${y}?: ${$}`).join(`
|
16
|
-
`)}
|
17
|
-
}
|
18
|
-
`;f.writeFileSync(w,k)},X=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 u=i.exec(t);if(u){const p=u.at(1);if(rt.some(o=>p==null?void 0:p.includes(o)))return e}return"styled('div',"}),B=async(t,e,s)=>{const n=W(e),i=a.join(s,"./temp");f.existsSync(i)||f.mkdirSync(i);const r=a.parse(e);let u=f.readFileSync(e,"utf8");u=X(u);const p=a.join(s,"js",n+".js"),c=await at(t),o=a.join(t,(c==null?void 0:c.configDir)||"","salty.config.ts"),g=ot(o),m=await st(t);await Y.build({stdin:{contents:u,sourcefile:r.base,resolveDir:r.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:p,format:m,target:["node20"],keepNames:!0,external:g,packages:"external",plugins:[{name:"test",setup:b=>{b.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},_=>{const d=f.readFileSync(_.path,"utf8");return{contents:X(d),loader:"ts"}})}}]});const C=Date.now();return await import(`${p}?t=${C}`)},K=async t=>{const e=z(t),s=a.join(e,"salty.config.js"),n=Date.now(),{config:i}=await import(`${s}?t=${n}`);return i},lt=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},kt=async(t,e=lt())=>{try{const s=Date.now();e?Z.info("Generating CSS in production mode! 🔥"):Z.info("Generating CSS in development mode! 🚀");const n=[],i=[],r=z(t),u=a.join(r,"index.css");(()=>{f.existsSync(r)&>.execSync("rm -rf "+r),f.mkdirSync(r),f.mkdirSync(a.join(r,"css")),f.mkdirSync(a.join(r,"types"))})(),await xt(t);const c=await K(t);async function o(l,h){const N=["node_modules","saltygen"],w=f.statSync(l);if(w.isDirectory()){const T=f.readdirSync(l);if(N.some(y=>l.includes(y)))return;await Promise.all(T.map(y=>o(a.join(l,y),a.join(h,y))))}else if(w.isFile()&&L(l)){const k=await B(t,l,r),y=[];Object.entries(k).forEach(([E,P])=>{if(P.isKeyframes&&P.css){const G=`a_${P.animationName}.css`,pt=`css/${G}`,dt=a.join(r,pt);n.push(G),f.writeFileSync(dt,P.css);return}if(!P.generator)return;const O=P.generator._withBuildContext({name:E,config:c,prod:e});i[O.priority]||(i[O.priority]=[]),i[O.priority].push(O.cssFileName),y.push(O.cssFileName);const ft=`css/${O.cssFileName}`,ut=a.join(r,ft);f.writeFileSync(ut,O.css)});const $=y.map(E=>`@import url('./${E}');`).join(`
|
19
|
-
`),F=W(l,6),j=a.parse(l),D=V(j.name),R=a.join(r,`css/f_${D}-${F}.css`);f.writeFileSync(R,$)}}await o(t,r);const g=n.map(l=>`@import url('./css/${l}');`).join(`
|
20
|
-
`);let b=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
21
|
-
|
22
|
-
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(l=>{try{return f.readFileSync(a.join(r,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
|
23
|
-
`)}
|
24
|
-
${g}`;if(c.importStrategy!=="component"){const l=i.reduce((h,N,w)=>{const T=N.reduce((F,j)=>{var P;const D=a.join(r,"css",j),R=f.readFileSync(D,"utf8"),E=((P=/.*-([^-]+)-\d+.css/.exec(j))==null?void 0:P.at(1))||W(D,6);return F.includes(E)?F:`${F}
|
25
|
-
/*start:${E}*/
|
26
|
-
${R}
|
27
|
-
/*end:${E}*/
|
28
|
-
`},""),k=`l_${w}.css`,y=a.join(r,"css",k),$=`@layer l${w} { ${T}
|
29
|
-
}`;return f.writeFileSync(y,$),`${h}
|
30
|
-
@import url('./css/${k}');`},"");b+=l}f.writeFileSync(u,b);const d=Date.now()-s,S=d<200?"🔥":d<500?"🚀":d<1e3?"🎉":d<2e3?"🚗":d<5e3?"🤔":"🥴";Z.info(`Generated CSS in ${d}ms! ${S}`)}catch(s){console.error(s)}},Pt=async(t,e)=>{try{const s=a.join(t,"./saltygen");if(L(e)){const i=[],r=await K(t),u=await B(t,e,s);Object.entries(u).forEach(([p,c])=>{if(c.isKeyframes&&c.css){const x=`css/${`a_${c.animationName}.css`}`,b=a.join(s,x);f.writeFileSync(b,c.css);return}if(!c.generator)return;const o=c.generator._withBuildContext({name:p,config:r}),g=`css/${o.cssFileName}`,m=a.join(s,g);f.writeFileSync(m,o.css),i[o.priority]||(i[o.priority]=[]),i[o.priority].push(o.cssFileName)}),r.importStrategy!=="component"&&i.forEach((p,c)=>{const o=`l_${c}.css`,g=a.join(s,"css",o);let m=f.readFileSync(g,"utf8");p.forEach(C=>{var d;const x=a.join(s,"css",C),b=((d=/.*-([^-]+)-\d+.css/.exec(C))==null?void 0:d.at(1))||W(x,6);if(!m.includes(b)){const S=f.readFileSync(x,"utf8"),l=`/*start:${b}*/
|
31
|
-
${S}
|
32
|
-
/*end:${b}*/
|
33
|
-
`;m=`${m.replace(/\}$/,"")}
|
34
|
-
${l}
|
35
|
-
}`}}),f.writeFileSync(g,m)})}}catch(s){console.error(s)}},Nt=async(t,e,s=lt())=>{try{const n=a.join(t,"./saltygen");if(L(e)){const r=f.readFileSync(e,"utf8");r.replace(/^(?!export\s)const\s.*/gm,g=>`export ${g}`)!==r&&await H.writeFile(e,r);const p=await K(t),c=await B(t,e,n);let o=r;if(Object.entries(c).forEach(([g,m])=>{var F;if(m.isKeyframes||!m.generator)return;const C=m.generator._withBuildContext({name:g,config:p,prod:s}),x=new RegExp(`\\s${g}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(r);if(!x)return console.error("Could not find the original declaration");const b=(F=x.at(1))==null?void 0:F.trim(),_=new RegExp(`\\s${g}[=\\s]+styled\\(`,"g").exec(o);if(!_)return console.error("Could not find the original declaration");const{index:d}=_;let S=!1;const l=setTimeout(()=>S=!0,5e3);let h=0,N=!1,w=0;for(;!N&&!S;){const j=o[d+h];j==="("&&w++,j===")"&&w--,w===0&&j===")"&&(N=!0),h>o.length&&(S=!0),h++}if(!S)clearTimeout(l);else throw new Error("Failed to find the end of the styled call and timed out");const T=d+h,k=o.slice(d,T),y=o,$=` ${g} = styled(${b}, "${C.classNames}", ${JSON.stringify(C.props)});`;o=o.replace(k,$),y===o&&console.error("Minimize file failed to change content",{name:g,tagName:b})}),p.importStrategy==="component"){const g=W(e,6),m=a.parse(e);o=`import '../../saltygen/css/${`f_${V(m.name)}-${g}.css`}';
|
36
|
-
${o}`}return o=o.replace("{ styled }","{ styledClient as styled }"),o=o.replace("@salty-css/react/styled","@salty-css/react/styled-client"),o}}catch(n){console.error("Error in minimizeFile:",n)}};exports.generateCss=kt;exports.generateFile=Pt;exports.minimizeFile=Nt;exports.saltyFileRegExp=it;
|