@salty-css/webpack 0.0.1-alpha.179 → 0.0.1-alpha.180
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-B5p2PCY4.js +487 -0
- package/index-CLeyuKRw.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-B8Y5B15R.cjs +0 -36
- package/index-ChWI7ezV.js +0 -487
@@ -0,0 +1,487 @@
|
|
1
|
+
import * as rt from "esbuild";
|
2
|
+
import { execSync as $t } from "child_process";
|
3
|
+
import { join as f, parse as X } from "path";
|
4
|
+
import { existsSync as Y, writeFileSync as E, readFileSync as M, mkdirSync as z, statSync as bt, readdirSync as St } from "fs";
|
5
|
+
import { readFile as it, writeFile as wt } from "fs/promises";
|
6
|
+
import { createLogger as jt, format as Q, transports as Ct } from "winston";
|
7
|
+
const nt = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), Ft = (t, e) => {
|
8
|
+
let s = "", n;
|
9
|
+
for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = nt(n % 52) + s;
|
10
|
+
return s = nt(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
|
11
|
+
}, xt = (t, e) => {
|
12
|
+
let s = e.length;
|
13
|
+
for (; s; ) t = t * 33 ^ e.charCodeAt(--s);
|
14
|
+
return t;
|
15
|
+
}, L = (t, e = 5) => {
|
16
|
+
const s = xt(5381, JSON.stringify(t)) >>> 0;
|
17
|
+
return Ft(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 kt = (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: c, transform: a } = n;
|
28
|
+
t = t.replace(c, (i) => {
|
29
|
+
const { value: p, css: r } = a(i);
|
30
|
+
return r && s.push(r), p;
|
31
|
+
});
|
32
|
+
}), { result: t, additionalCss: s };
|
33
|
+
}, ct = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${A(n[1].replaceAll(".", "-"))})`) } : { result: t }, J = (t, e, s) => {
|
34
|
+
if (!t) return "";
|
35
|
+
const n = [], c = Object.entries(t).reduce((i, [p, r]) => {
|
36
|
+
const o = p.trim();
|
37
|
+
if (typeof r == "function" && (r = r()), typeof r == "object") {
|
38
|
+
if (!r) return i;
|
39
|
+
if (o === "variants")
|
40
|
+
return Object.entries(r).forEach(([D, $]) => {
|
41
|
+
$ && Object.entries($).forEach(([O, l]) => {
|
42
|
+
if (!l) return;
|
43
|
+
const S = `${e}.${D}-${O}`, y = J(l, S);
|
44
|
+
n.push(y);
|
45
|
+
});
|
46
|
+
}), i;
|
47
|
+
if (o === "defaultVariants")
|
48
|
+
return i;
|
49
|
+
if (o === "compoundVariants")
|
50
|
+
return r.forEach((D) => {
|
51
|
+
const { css: $, ...O } = D, l = Object.entries(O).reduce((y, [w, m]) => `${y}.${w}-${m}`, e), S = J($, l);
|
52
|
+
n.push(S);
|
53
|
+
}), i;
|
54
|
+
if (o.startsWith("@")) {
|
55
|
+
const D = J(r, e), $ = `${o} {
|
56
|
+
${D.replace(`
|
57
|
+
`, `
|
58
|
+
`)}
|
59
|
+
}`;
|
60
|
+
return n.push($), i;
|
61
|
+
}
|
62
|
+
const b = p.includes("&") ? o.replace("&", e) : o.startsWith(":") ? `${e}${o}` : `${e} ${o}`, j = J(r, b);
|
63
|
+
return n.push(j), i;
|
64
|
+
}
|
65
|
+
const g = o.startsWith("-") ? o : A(o), u = (b, j = ";") => i = `${i}${b}${j}`, d = (b) => u(`${g}:${b}`);
|
66
|
+
if (typeof r == "number") return d(r);
|
67
|
+
if (typeof r != "string")
|
68
|
+
if ("toString" in r) r = r.toString();
|
69
|
+
else return i;
|
70
|
+
const { modifiers: x } = {}, T = function* () {
|
71
|
+
yield ct(r), yield kt(r, x);
|
72
|
+
}();
|
73
|
+
for (const { result: b, additionalCss: j = [] } of T)
|
74
|
+
r = b, j.forEach((D) => {
|
75
|
+
const $ = J(D, "");
|
76
|
+
u($, "");
|
77
|
+
});
|
78
|
+
return d(r);
|
79
|
+
}, "");
|
80
|
+
return c ? e ? [`${e} { ${c} }`, ...n].join(`
|
81
|
+
`) : c : n.join(`
|
82
|
+
`);
|
83
|
+
}, at = (t, e = []) => {
|
84
|
+
if (!t) return "";
|
85
|
+
const s = [], n = {};
|
86
|
+
if (Object.entries(t).forEach(([c, a]) => {
|
87
|
+
if (typeof a == "object") {
|
88
|
+
if (!a) return;
|
89
|
+
const i = c.trim(), p = at(a, [...e, i]);
|
90
|
+
s.push(p);
|
91
|
+
} else
|
92
|
+
n[c] = a;
|
93
|
+
}), Object.keys(n).length) {
|
94
|
+
const c = e.map(A).join("-"), a = J(n, `.${c}`);
|
95
|
+
s.push(a);
|
96
|
+
}
|
97
|
+
return s.join(`
|
98
|
+
`);
|
99
|
+
}, Nt = (t) => t ? Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = lt(n).map((c) => `"${c}"`).join(" | ")), e), {}) : {}, lt = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, c]) => {
|
100
|
+
const a = e ? `${e}.${n}` : n;
|
101
|
+
return typeof c == "object" ? lt(c, a, s) : s.add(e);
|
102
|
+
}), [...s]) : [], ft = (t) => {
|
103
|
+
if (!t || t === "/") throw new Error("Could not find package.json file");
|
104
|
+
const e = f(t, "package.json");
|
105
|
+
return Y(e) ? e : ft(f(t, ".."));
|
106
|
+
}, Dt = async (t) => {
|
107
|
+
const e = ft(t);
|
108
|
+
return await it(e, "utf-8").then(JSON.parse).catch(() => {
|
109
|
+
});
|
110
|
+
}, Pt = async (t) => {
|
111
|
+
const e = await Dt(t);
|
112
|
+
if (e)
|
113
|
+
return e.type;
|
114
|
+
};
|
115
|
+
let W;
|
116
|
+
const pt = async (t) => {
|
117
|
+
if (W) return W;
|
118
|
+
const e = await Pt(t);
|
119
|
+
return e === "module" ? W = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (W = "cjs"), W || "esm";
|
120
|
+
}, U = jt({
|
121
|
+
level: "debug",
|
122
|
+
format: Q.combine(Q.colorize(), Q.cli()),
|
123
|
+
transports: [new Ct.Console({})]
|
124
|
+
});
|
125
|
+
function ut(t) {
|
126
|
+
return t ? typeof t != "string" ? ut(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 Et = {
|
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
|
+
}, G = (...t) => t.flat().reduce((e, s) => s != null && s._current ? { ...e, ...s._current } : { ...e, ...s }, {}), _ = {
|
175
|
+
externalModules: [],
|
176
|
+
rcFile: void 0,
|
177
|
+
destDir: void 0
|
178
|
+
}, dt = (t) => {
|
179
|
+
if (_.externalModules.length > 0) return _.externalModules;
|
180
|
+
const s = M(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
181
|
+
if (!s) return [];
|
182
|
+
const n = s[1].split(",").map((c) => c.replace(/['"`]/g, "").trim());
|
183
|
+
return _.externalModules = n, n;
|
184
|
+
}, Z = async (t) => {
|
185
|
+
if (_.destDir) return _.destDir;
|
186
|
+
const e = await tt(t), s = f(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
|
187
|
+
return _.destDir = s, s;
|
188
|
+
}, gt = ["salty", "css", "styles", "styled"], Tt = (t = []) => new RegExp(`\\.(${[...gt, ...t].join("|")})\\.`), v = (t, e = []) => Tt(e).test(t), mt = async (t) => {
|
189
|
+
if (_.rcFile) return _.rcFile;
|
190
|
+
if (t === "/") throw new Error("Could not find .saltyrc.json file");
|
191
|
+
const e = f(t, ".saltyrc.json"), s = await it(e, "utf-8").then(JSON.parse).catch(() => {
|
192
|
+
});
|
193
|
+
return s ? (_.rcFile = s, s) : mt(f(t, ".."));
|
194
|
+
}, tt = async (t) => {
|
195
|
+
var n, c;
|
196
|
+
const e = await mt(t), s = (n = e.projects) == null ? void 0 : n.find((a) => t.endsWith(a.dir || ""));
|
197
|
+
return s || ((c = e.projects) == null ? void 0 : c.find((a) => a.dir === e.defaultProject));
|
198
|
+
}, Ot = async (t) => {
|
199
|
+
const e = await tt(t), s = await Z(t), n = f(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), c = f(s, "salty.config.js"), a = await pt(t), i = dt(n);
|
200
|
+
await rt.build({
|
201
|
+
entryPoints: [n],
|
202
|
+
minify: !0,
|
203
|
+
treeShaking: !0,
|
204
|
+
bundle: !0,
|
205
|
+
outfile: c,
|
206
|
+
format: a,
|
207
|
+
external: i
|
208
|
+
});
|
209
|
+
const p = Date.now(), { config: r } = await import(`${c}?t=${p}`);
|
210
|
+
return r;
|
211
|
+
}, Vt = async (t, e) => {
|
212
|
+
const s = await Ot(t), n = { ...s }, c = /* @__PURE__ */ new Set(), a = (k, F = []) => k ? Object.entries(k).flatMap(([V, P]) => {
|
213
|
+
if (!P) return;
|
214
|
+
if (typeof P == "object") return a(P, [...F, V]);
|
215
|
+
const R = ut(V), B = A(V), K = [...F, R].join(".");
|
216
|
+
c.add(`"${K}"`);
|
217
|
+
const q = [...F.map(A), B].join("-"), { result: yt } = ct(P);
|
218
|
+
return `--${q}: ${yt};`;
|
219
|
+
}) : [], i = (k) => k ? Object.entries(k).flatMap(([F, V]) => {
|
220
|
+
const P = a(V);
|
221
|
+
return F === "base" ? P.join("") : `${F} { ${P.join("")} }`;
|
222
|
+
}) : [], p = (k) => k ? Object.entries(k).flatMap(([F, V]) => Object.entries(V).flatMap(([P, R]) => {
|
223
|
+
const B = a(R, [F]), K = `.${F}-${P}, [data-${F}="${P}"]`, q = B.join("");
|
224
|
+
return `${K} { ${q} }`;
|
225
|
+
})) : [], r = (k) => e.variables.map((F) => F._current[k]), o = a(G(s.variables, r("variables"))), g = i(G(s.responsiveVariables, r("responsiveVariables"))), u = p(G(s.conditionalVariables, r("conditionalVariables"))), d = await Z(t), x = f(d, "css/_variables.css"), N = `:root { ${o.join("")} ${g.join("")} } ${u.join("")}`;
|
226
|
+
E(x, N);
|
227
|
+
const T = f(d, "css/_global.css"), b = G(s.global, e.globalStyles), j = J(b, "");
|
228
|
+
E(T, `@layer global { ${j} }`);
|
229
|
+
const D = f(d, "css/_reset.css"), O = s.reset === "none" ? {} : typeof s.reset == "object" ? s.reset : Et, l = J(O, "");
|
230
|
+
E(D, `@layer reset { ${l} }`);
|
231
|
+
const S = f(d, "css/_templates.css"), y = G(s.templates, e.templates);
|
232
|
+
console.log("all", y);
|
233
|
+
const w = at(y), m = Nt(y);
|
234
|
+
E(S, w), n.templates = y;
|
235
|
+
const C = f(d, "types/css-tokens.d.ts"), H = `
|
236
|
+
// Variable types
|
237
|
+
type VariableTokens = ${[...c].join("|")};
|
238
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
239
|
+
|
240
|
+
// Template types
|
241
|
+
type TemplateTokens = {
|
242
|
+
${Object.entries(m).map(([k, F]) => `${k}?: ${F}`).join(`
|
243
|
+
`)}
|
244
|
+
}
|
245
|
+
`;
|
246
|
+
E(C, H);
|
247
|
+
const I = f(d, "cache/config-cache.json");
|
248
|
+
E(I, JSON.stringify(n, null, 2));
|
249
|
+
}, ot = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
|
250
|
+
if (/^['"`]/.test(s)) return e;
|
251
|
+
const c = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
|
252
|
+
if (!c.test(t)) return e;
|
253
|
+
const i = c.exec(t);
|
254
|
+
if (i) {
|
255
|
+
const p = i.at(1);
|
256
|
+
if (gt.some((o) => p == null ? void 0 : p.includes(o))) return e;
|
257
|
+
}
|
258
|
+
return "styled('div',";
|
259
|
+
}), et = async (t, e, s) => {
|
260
|
+
const n = L(e), c = f(s, "./temp");
|
261
|
+
Y(c) || z(c);
|
262
|
+
const a = X(e);
|
263
|
+
let i = M(e, "utf8");
|
264
|
+
i = ot(i);
|
265
|
+
const p = f(s, "js", n + ".js"), r = await tt(t), o = f(t, (r == null ? void 0 : r.configDir) || "", "salty.config.ts"), g = dt(o), u = await pt(t);
|
266
|
+
await rt.build({
|
267
|
+
stdin: {
|
268
|
+
contents: i,
|
269
|
+
sourcefile: a.base,
|
270
|
+
resolveDir: a.dir,
|
271
|
+
loader: "tsx"
|
272
|
+
},
|
273
|
+
minify: !1,
|
274
|
+
treeShaking: !0,
|
275
|
+
bundle: !0,
|
276
|
+
outfile: p,
|
277
|
+
format: u,
|
278
|
+
target: ["node20"],
|
279
|
+
keepNames: !0,
|
280
|
+
external: g,
|
281
|
+
packages: "external",
|
282
|
+
plugins: [
|
283
|
+
{
|
284
|
+
name: "test",
|
285
|
+
setup: (N) => {
|
286
|
+
N.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (T) => {
|
287
|
+
const b = M(T.path, "utf8");
|
288
|
+
return { contents: ot(b), loader: "ts" };
|
289
|
+
});
|
290
|
+
}
|
291
|
+
}
|
292
|
+
]
|
293
|
+
});
|
294
|
+
const d = Date.now();
|
295
|
+
return await import(`${p}?t=${d}`);
|
296
|
+
}, st = async (t) => {
|
297
|
+
const e = await Z(t), s = f(e, "cache/config-cache.json"), n = M(s, "utf8");
|
298
|
+
if (!n) throw new Error("Could not find config cache file");
|
299
|
+
return JSON.parse(n);
|
300
|
+
}, ht = () => {
|
301
|
+
try {
|
302
|
+
return process.env.NODE_ENV === "production";
|
303
|
+
} catch {
|
304
|
+
return !1;
|
305
|
+
}
|
306
|
+
}, Wt = async (t, e = ht(), s = !0) => {
|
307
|
+
try {
|
308
|
+
const n = Date.now();
|
309
|
+
e ? U.info("Generating CSS in production mode! 🔥") : U.info("Generating CSS in development mode! 🚀");
|
310
|
+
const c = [], a = [], i = await Z(t), p = f(i, "index.css");
|
311
|
+
s && (() => {
|
312
|
+
Y(i) && $t("rm -rf " + i), z(i, { recursive: !0 }), z(f(i, "css")), z(f(i, "types")), z(f(i, "js")), z(f(i, "cache"));
|
313
|
+
})();
|
314
|
+
const o = {
|
315
|
+
keyframes: [],
|
316
|
+
mediaQueries: [],
|
317
|
+
globalStyles: [],
|
318
|
+
variables: [],
|
319
|
+
components: [],
|
320
|
+
templates: []
|
321
|
+
};
|
322
|
+
async function g(l) {
|
323
|
+
const S = ["node_modules", "saltygen"], y = bt(l);
|
324
|
+
if (y.isDirectory()) {
|
325
|
+
const w = St(l);
|
326
|
+
if (S.some((C) => l.includes(C))) return;
|
327
|
+
await Promise.all(w.map((C) => g(f(l, C))));
|
328
|
+
} else if (y.isFile() && v(l)) {
|
329
|
+
const m = await et(t, l, i);
|
330
|
+
Object.entries(m).forEach(([C, h]) => {
|
331
|
+
h.isKeyframes ? o.keyframes.push({
|
332
|
+
value: h,
|
333
|
+
src: l,
|
334
|
+
name: C
|
335
|
+
}) : h.isMedia ? o.mediaQueries.push(h) : h.isGlobalDefine ? o.globalStyles.push(h) : h.isDefineVariables ? o.variables.push(h) : h.isDefineTemplates ? o.templates.push(h) : h.generator && o.components.push({
|
336
|
+
value: h.generator,
|
337
|
+
src: l,
|
338
|
+
name: C
|
339
|
+
});
|
340
|
+
});
|
341
|
+
}
|
342
|
+
}
|
343
|
+
await g(t), await Vt(t, o);
|
344
|
+
const u = await st(t);
|
345
|
+
for (const l of o.keyframes) {
|
346
|
+
const { value: S } = l, y = `a_${S.animationName}.css`, w = `css/${y}`, m = f(i, w);
|
347
|
+
c.push(y), E(m, S.css);
|
348
|
+
}
|
349
|
+
const d = {};
|
350
|
+
for (const l of o.components) {
|
351
|
+
const { value: S, name: y, src: w } = l, m = S._withBuildContext({
|
352
|
+
name: y,
|
353
|
+
config: u,
|
354
|
+
prod: e
|
355
|
+
});
|
356
|
+
a[m.priority] || (a[m.priority] = []), a[m.priority].push(m.cssFileName), u.importStrategy === "component" && (d[w] ? d[w].push(m.cssFileName) : d[w] = [m.cssFileName]);
|
357
|
+
const C = `css/${m.cssFileName}`, h = f(i, C);
|
358
|
+
E(h, m.css);
|
359
|
+
}
|
360
|
+
u.importStrategy === "component" && Object.entries(d).forEach(([l, S]) => {
|
361
|
+
const y = S.map((H) => `@import url('./${H}');`).join(`
|
362
|
+
`), w = L(l, 6), m = X(l), C = A(m.name), h = f(i, `css/f_${C}-${w}.css`);
|
363
|
+
E(h, y);
|
364
|
+
});
|
365
|
+
const x = c.map((l) => `@import url('./css/${l}');`).join(`
|
366
|
+
`);
|
367
|
+
let j = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
368
|
+
|
369
|
+
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) => {
|
370
|
+
try {
|
371
|
+
return M(f(i, "css", l), "utf8").length > 0;
|
372
|
+
} catch {
|
373
|
+
return !1;
|
374
|
+
}
|
375
|
+
}).map((l) => `@import url('./css/${l}');`).join(`
|
376
|
+
`)}
|
377
|
+
${x}`;
|
378
|
+
if (u.importStrategy !== "component") {
|
379
|
+
const l = a.reduce((S, y, w) => {
|
380
|
+
const m = y.reduce((I, k) => {
|
381
|
+
var R;
|
382
|
+
const F = f(i, "css", k), V = M(F, "utf8"), P = ((R = /.*-([^-]+)-\d+.css/.exec(k)) == null ? void 0 : R.at(1)) || L(F, 6);
|
383
|
+
return I.includes(P) ? I : `${I}
|
384
|
+
/*start:${P}*/
|
385
|
+
${V}
|
386
|
+
/*end:${P}*/
|
387
|
+
`;
|
388
|
+
}, ""), C = `l_${w}.css`, h = f(i, "css", C), H = `@layer l${w} { ${m}
|
389
|
+
}`;
|
390
|
+
return E(h, H), `${S}
|
391
|
+
@import url('./css/${C}');`;
|
392
|
+
}, "");
|
393
|
+
j += l;
|
394
|
+
}
|
395
|
+
E(p, j);
|
396
|
+
const $ = Date.now() - n, O = $ < 200 ? "🔥" : $ < 500 ? "🚀" : $ < 1e3 ? "🎉" : $ < 2e3 ? "🚗" : $ < 5e3 ? "🤔" : "🥴";
|
397
|
+
U.info(`Generated CSS in ${$}ms! ${O}`);
|
398
|
+
} catch (n) {
|
399
|
+
console.error(n);
|
400
|
+
}
|
401
|
+
}, zt = async (t, e) => {
|
402
|
+
try {
|
403
|
+
const s = await Z(t);
|
404
|
+
if (v(e)) {
|
405
|
+
const c = [], a = await st(t), i = await et(t, e, s);
|
406
|
+
Object.entries(i).forEach(([p, r]) => {
|
407
|
+
if (r.isKeyframes && r.css) {
|
408
|
+
const x = `css/${`a_${r.animationName}.css`}`, N = f(s, x);
|
409
|
+
E(N, r.css);
|
410
|
+
return;
|
411
|
+
}
|
412
|
+
if (!r.generator) return;
|
413
|
+
const o = r.generator._withBuildContext({
|
414
|
+
name: p,
|
415
|
+
config: a
|
416
|
+
}), g = `css/${o.cssFileName}`, u = f(s, g);
|
417
|
+
E(u, o.css), c[o.priority] || (c[o.priority] = []), c[o.priority].push(o.cssFileName);
|
418
|
+
}), a.importStrategy !== "component" && c.forEach((p, r) => {
|
419
|
+
const o = `l_${r}.css`, g = f(s, "css", o);
|
420
|
+
let u = M(g, "utf8");
|
421
|
+
p.forEach((d) => {
|
422
|
+
var b;
|
423
|
+
const x = f(s, "css", d), N = ((b = /.*-([^-]+)-\d+.css/.exec(d)) == null ? void 0 : b.at(1)) || L(x, 6);
|
424
|
+
if (!u.includes(N)) {
|
425
|
+
const j = M(x, "utf8"), D = `/*start:${N}*/
|
426
|
+
${j}
|
427
|
+
/*end:${N}*/
|
428
|
+
`;
|
429
|
+
u = `${u.replace(/\}$/, "")}
|
430
|
+
${D}
|
431
|
+
}`;
|
432
|
+
}
|
433
|
+
}), E(g, u);
|
434
|
+
});
|
435
|
+
}
|
436
|
+
} catch (s) {
|
437
|
+
console.error(s);
|
438
|
+
}
|
439
|
+
}, Zt = async (t, e, s = ht()) => {
|
440
|
+
try {
|
441
|
+
const n = await Z(t);
|
442
|
+
if (v(e)) {
|
443
|
+
const a = M(e, "utf8");
|
444
|
+
a.replace(/^(?!export\s)const\s.*/gm, (g) => `export ${g}`) !== a && await wt(e, a);
|
445
|
+
const p = await st(t), r = await et(t, e, n);
|
446
|
+
let o = a;
|
447
|
+
if (Object.entries(r).forEach(([g, u]) => {
|
448
|
+
var C;
|
449
|
+
if (u.isKeyframes || !u.generator) return;
|
450
|
+
const d = u.generator._withBuildContext({
|
451
|
+
name: g,
|
452
|
+
config: p,
|
453
|
+
prod: s
|
454
|
+
}), x = new RegExp(`\\s${g}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(a);
|
455
|
+
if (!x) return console.error("Could not find the original declaration");
|
456
|
+
const N = (C = x.at(1)) == null ? void 0 : C.trim(), T = new RegExp(`\\s${g}[=\\s]+styled\\(`, "g").exec(o);
|
457
|
+
if (!T) return console.error("Could not find the original declaration");
|
458
|
+
const { index: b } = T;
|
459
|
+
let j = !1;
|
460
|
+
const D = setTimeout(() => j = !0, 5e3);
|
461
|
+
let $ = 0, O = !1, l = 0;
|
462
|
+
for (; !O && !j; ) {
|
463
|
+
const h = o[b + $];
|
464
|
+
h === "(" && l++, h === ")" && l--, l === 0 && h === ")" && (O = !0), $ > o.length && (j = !0), $++;
|
465
|
+
}
|
466
|
+
if (!j) clearTimeout(D);
|
467
|
+
else throw new Error("Failed to find the end of the styled call and timed out");
|
468
|
+
const S = b + $, y = o.slice(b, S), w = o, m = ` ${g} = styled(${N}, "${d.classNames}", ${JSON.stringify(d.props)});`;
|
469
|
+
o = o.replace(y, m), w === o && console.error("Minimize file failed to change content", { name: g, tagName: N });
|
470
|
+
}), p.importStrategy === "component") {
|
471
|
+
const g = L(e, 6), u = X(e);
|
472
|
+
o = `import '../../saltygen/css/${`f_${A(u.name)}-${g}.css`}';
|
473
|
+
${o}`;
|
474
|
+
}
|
475
|
+
return o = o.replace("{ styled }", "{ styledClient as styled }"), o = o.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), o;
|
476
|
+
}
|
477
|
+
} catch (n) {
|
478
|
+
console.error("Error in minimizeFile:", n);
|
479
|
+
}
|
480
|
+
};
|
481
|
+
export {
|
482
|
+
zt as a,
|
483
|
+
Wt as g,
|
484
|
+
v as i,
|
485
|
+
Zt as m,
|
486
|
+
Tt as s
|
487
|
+
};
|
@@ -0,0 +1,36 @@
|
|
1
|
+
"use strict";const me=require("esbuild"),he=require("child_process"),l=require("path"),u=require("fs"),X=require("fs/promises"),Z=require("winston");var U=typeof document<"u"?document.currentScript:null;function Se(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const ne=Se(me),te=e=>String.fromCharCode(e+(e>25?39:97)),be=(e,t)=>{let s="",n;for(n=Math.abs(e);n>52;n=n/52|0)s=te(n%52)+s;return s=te(n%52)+s,s.length<t?s=s.padStart(t,"a"):s.length>t&&(s=s.slice(-t)),s},je=(e,t)=>{let s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return e},H=(e,t=5)=>{const s=je(5381,JSON.stringify(e))>>>0;return be(s,t)};function R(e){return e?typeof e!="string"?R(String(e)):e.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?"-":"")+t.toLowerCase()):""}const $e=(e,t)=>{if(typeof e!="string")return{result:e};if(!t)return{result:e};const s=[];return Object.values(t).forEach(n=>{const{pattern:c,transform:a}=n;e=e.replace(c,i=>{const{value:p,css:r}=a(i);return r&&s.push(r),p})}),{result:e,additionalCss:s}},oe=e=>typeof e!="string"?{result:e}:/\{[^{}]+\}/g.test(e)?{result:e.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${R(n[1].replaceAll(".","-"))})`)}:{result:e},M=(e,t,s)=>{if(!e)return"";const n=[],c=Object.entries(e).reduce((i,[p,r])=>{const o=p.trim();if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return i;if(o==="variants")return Object.entries(r).forEach(([P,b])=>{b&&Object.entries(b).forEach(([E,f])=>{if(!f)return;const $=`${t}.${P}-${E}`,S=M(f,$);n.push(S)})}),i;if(o==="defaultVariants")return i;if(o==="compoundVariants")return r.forEach(P=>{const{css:b,...E}=P,f=Object.entries(E).reduce((S,[w,m])=>`${S}.${w}-${m}`,t),$=M(b,f);n.push($)}),i;if(o.startsWith("@")){const P=M(r,t),b=`${o} {
|
2
|
+
${P.replace(`
|
3
|
+
`,`
|
4
|
+
`)}
|
5
|
+
}`;return n.push(b),i}const j=p.includes("&")?o.replace("&",t):o.startsWith(":")?`${t}${o}`:`${t} ${o}`,F=M(r,j);return n.push(F),i}const g=o.startsWith("-")?o:R(o),d=(j,F=";")=>i=`${i}${j}${F}`,y=j=>d(`${g}:${j}`);if(typeof r=="number")return y(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return i;const{modifiers:k}={},_=function*(){yield oe(r),yield $e(r,k)}();for(const{result:j,additionalCss:F=[]}of _)r=j,F.forEach(P=>{const b=M(P,"");d(b,"")});return y(r)},"");return c?t?[`${t} { ${c} }`,...n].join(`
|
6
|
+
`):c:n.join(`
|
7
|
+
`)},re=(e,t=[])=>{if(!e)return"";const s=[],n={};if(Object.entries(e).forEach(([c,a])=>{if(typeof a=="object"){if(!a)return;const i=c.trim(),p=re(a,[...t,i]);s.push(p)}else n[c]=a}),Object.keys(n).length){const c=t.map(R).join("-"),a=M(n,`.${c}`);s.push(a)}return s.join(`
|
8
|
+
`)},we=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="object"&&(t[s]=ie(n).map(c=>`"${c}"`).join(" | ")),t),{}):{},ie=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,c])=>{const a=t?`${t}.${n}`:n;return typeof c=="object"?ie(c,a,s):s.add(t)}),[...s]):[],ce=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=l.join(e,"package.json");return u.existsSync(t)?t:ce(l.join(e,".."))},Fe=async e=>{const t=ce(e);return await X.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Ce=async e=>{const t=await Fe(e);if(t)return t.type};let A;const ae=async e=>{if(A)return A;const t=await Ce(e);return t==="module"?A="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:U&&U.tagName.toUpperCase()==="SCRIPT"&&U.src||new URL("index-CLeyuKRw.cjs",document.baseURI).href).endsWith(".cjs"))&&(A="cjs"),A||"esm"},Q=Z.createLogger({level:"debug",format:Z.format.combine(Z.format.colorize(),Z.format.cli()),transports:[new Z.transports.Console({})]});function le(e){return e?typeof e!="string"?le(String(e)):e.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?".":"")+t.toLowerCase()):""}const xe={"*, *::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=(...e)=>e.flat().reduce((t,s)=>s!=null&&s._current?{...t,...s._current}:{...t,...s},{}),V={externalModules:[],rcFile:void 0,destDir:void 0},fe=e=>{if(V.externalModules.length>0)return V.externalModules;const s=u.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(c=>c.replace(/['"`]/g,"").trim());return V.externalModules=n,n},W=async e=>{if(V.destDir)return V.destDir;const t=await Y(e),s=l.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return V.destDir=s,s},ue=["salty","css","styles","styled"],pe=(e=[])=>new RegExp(`\\.(${[...ue,...e].join("|")})\\.`),L=(e,t=[])=>pe(t).test(e),de=async e=>{if(V.rcFile)return V.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=l.join(e,".saltyrc.json"),s=await X.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(V.rcFile=s,s):de(l.join(e,".."))},Y=async e=>{var n,c;const t=await de(e),s=(n=t.projects)==null?void 0:n.find(a=>e.endsWith(a.dir||""));return s||((c=t.projects)==null?void 0:c.find(a=>a.dir===t.defaultProject))},ke=async e=>{const t=await Y(e),s=await W(e),n=l.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),c=l.join(s,"salty.config.js"),a=await ae(e),i=fe(n);await ne.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:c,format:a,external:i});const p=Date.now(),{config:r}=await import(`${c}?t=${p}`);return r},Ne=async(e,t)=>{const s=await ke(e),n={...s},c=new Set,a=(N,x=[])=>N?Object.entries(N).flatMap(([O,T])=>{if(!T)return;if(typeof T=="object")return a(T,[...x,O]);const J=le(O),G=R(O),B=[...x,J].join(".");c.add(`"${B}"`);const K=[...x.map(R),G].join("-"),{result:ge}=oe(T);return`--${K}: ${ge};`}):[],i=N=>N?Object.entries(N).flatMap(([x,O])=>{const T=a(O);return x==="base"?T.join(""):`${x} { ${T.join("")} }`}):[],p=N=>N?Object.entries(N).flatMap(([x,O])=>Object.entries(O).flatMap(([T,J])=>{const G=a(J,[x]),B=`.${x}-${T}, [data-${x}="${T}"]`,K=G.join("");return`${B} { ${K} }`})):[],r=N=>t.variables.map(x=>x._current[N]),o=a(q(s.variables,r("variables"))),g=i(q(s.responsiveVariables,r("responsiveVariables"))),d=p(q(s.conditionalVariables,r("conditionalVariables"))),y=await W(e),k=l.join(y,"css/_variables.css"),D=`:root { ${o.join("")} ${g.join("")} } ${d.join("")}`;u.writeFileSync(k,D);const _=l.join(y,"css/_global.css"),j=q(s.global,t.globalStyles),F=M(j,"");u.writeFileSync(_,`@layer global { ${F} }`);const P=l.join(y,"css/_reset.css"),E=s.reset==="none"?{}:typeof s.reset=="object"?s.reset:xe,f=M(E,"");u.writeFileSync(P,`@layer reset { ${f} }`);const $=l.join(y,"css/_templates.css"),S=q(s.templates,t.templates);console.log("all",S);const w=re(S),m=we(S);u.writeFileSync($,w),n.templates=S;const C=l.join(y,"types/css-tokens.d.ts"),z=`
|
9
|
+
// Variable types
|
10
|
+
type VariableTokens = ${[...c].join("|")};
|
11
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
12
|
+
|
13
|
+
// Template types
|
14
|
+
type TemplateTokens = {
|
15
|
+
${Object.entries(m).map(([N,x])=>`${N}?: ${x}`).join(`
|
16
|
+
`)}
|
17
|
+
}
|
18
|
+
`;u.writeFileSync(C,z);const I=l.join(y,"cache/config-cache.json");u.writeFileSync(I,JSON.stringify(n,null,2))},se=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const c=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!c.test(e))return t;const i=c.exec(e);if(i){const p=i.at(1);if(ue.some(o=>p==null?void 0:p.includes(o)))return t}return"styled('div',"}),v=async(e,t,s)=>{const n=H(t),c=l.join(s,"./temp");u.existsSync(c)||u.mkdirSync(c);const a=l.parse(t);let i=u.readFileSync(t,"utf8");i=se(i);const p=l.join(s,"js",n+".js"),r=await Y(e),o=l.join(e,(r==null?void 0:r.configDir)||"","salty.config.ts"),g=fe(o),d=await ae(e);await ne.build({stdin:{contents:i,sourcefile:a.base,resolveDir:a.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:p,format:d,target:["node20"],keepNames:!0,external:g,packages:"external",plugins:[{name:"test",setup:D=>{D.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},_=>{const j=u.readFileSync(_.path,"utf8");return{contents:se(j),loader:"ts"}})}}]});const y=Date.now();return await import(`${p}?t=${y}`)},ee=async e=>{const t=await W(e),s=l.join(t,"cache/config-cache.json"),n=u.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ye=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},De=async(e,t=ye(),s=!0)=>{try{const n=Date.now();t?Q.info("Generating CSS in production mode! 🔥"):Q.info("Generating CSS in development mode! 🚀");const c=[],a=[],i=await W(e),p=l.join(i,"index.css");s&&(()=>{u.existsSync(i)&&he.execSync("rm -rf "+i),u.mkdirSync(i,{recursive:!0}),u.mkdirSync(l.join(i,"css")),u.mkdirSync(l.join(i,"types")),u.mkdirSync(l.join(i,"js")),u.mkdirSync(l.join(i,"cache"))})();const o={keyframes:[],mediaQueries:[],globalStyles:[],variables:[],components:[],templates:[]};async function g(f){const $=["node_modules","saltygen"],S=u.statSync(f);if(S.isDirectory()){const w=u.readdirSync(f);if($.some(C=>f.includes(C)))return;await Promise.all(w.map(C=>g(l.join(f,C))))}else if(S.isFile()&&L(f)){const m=await v(e,f,i);Object.entries(m).forEach(([C,h])=>{h.isKeyframes?o.keyframes.push({value:h,src:f,name:C}):h.isMedia?o.mediaQueries.push(h):h.isGlobalDefine?o.globalStyles.push(h):h.isDefineVariables?o.variables.push(h):h.isDefineTemplates?o.templates.push(h):h.generator&&o.components.push({value:h.generator,src:f,name:C})})}}await g(e),await Ne(e,o);const d=await ee(e);for(const f of o.keyframes){const{value:$}=f,S=`a_${$.animationName}.css`,w=`css/${S}`,m=l.join(i,w);c.push(S),u.writeFileSync(m,$.css)}const y={};for(const f of o.components){const{value:$,name:S,src:w}=f,m=$._withBuildContext({name:S,config:d,prod:t});a[m.priority]||(a[m.priority]=[]),a[m.priority].push(m.cssFileName),d.importStrategy==="component"&&(y[w]?y[w].push(m.cssFileName):y[w]=[m.cssFileName]);const C=`css/${m.cssFileName}`,h=l.join(i,C);u.writeFileSync(h,m.css)}d.importStrategy==="component"&&Object.entries(y).forEach(([f,$])=>{const S=$.map(z=>`@import url('./${z}');`).join(`
|
19
|
+
`),w=H(f,6),m=l.parse(f),C=R(m.name),h=l.join(i,`css/f_${C}-${w}.css`);u.writeFileSync(h,S)});const k=c.map(f=>`@import url('./css/${f}');`).join(`
|
20
|
+
`);let F=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
21
|
+
|
22
|
+
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(f=>{try{return u.readFileSync(l.join(i,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
|
23
|
+
`)}
|
24
|
+
${k}`;if(d.importStrategy!=="component"){const f=a.reduce(($,S,w)=>{const m=S.reduce((I,N)=>{var J;const x=l.join(i,"css",N),O=u.readFileSync(x,"utf8"),T=((J=/.*-([^-]+)-\d+.css/.exec(N))==null?void 0:J.at(1))||H(x,6);return I.includes(T)?I:`${I}
|
25
|
+
/*start:${T}*/
|
26
|
+
${O}
|
27
|
+
/*end:${T}*/
|
28
|
+
`},""),C=`l_${w}.css`,h=l.join(i,"css",C),z=`@layer l${w} { ${m}
|
29
|
+
}`;return u.writeFileSync(h,z),`${$}
|
30
|
+
@import url('./css/${C}');`},"");F+=f}u.writeFileSync(p,F);const b=Date.now()-n,E=b<200?"🔥":b<500?"🚀":b<1e3?"🎉":b<2e3?"🚗":b<5e3?"🤔":"🥴";Q.info(`Generated CSS in ${b}ms! ${E}`)}catch(n){console.error(n)}},Pe=async(e,t)=>{try{const s=await W(e);if(L(t)){const c=[],a=await ee(e),i=await v(e,t,s);Object.entries(i).forEach(([p,r])=>{if(r.isKeyframes&&r.css){const k=`css/${`a_${r.animationName}.css`}`,D=l.join(s,k);u.writeFileSync(D,r.css);return}if(!r.generator)return;const o=r.generator._withBuildContext({name:p,config:a}),g=`css/${o.cssFileName}`,d=l.join(s,g);u.writeFileSync(d,o.css),c[o.priority]||(c[o.priority]=[]),c[o.priority].push(o.cssFileName)}),a.importStrategy!=="component"&&c.forEach((p,r)=>{const o=`l_${r}.css`,g=l.join(s,"css",o);let d=u.readFileSync(g,"utf8");p.forEach(y=>{var j;const k=l.join(s,"css",y),D=((j=/.*-([^-]+)-\d+.css/.exec(y))==null?void 0:j.at(1))||H(k,6);if(!d.includes(D)){const F=u.readFileSync(k,"utf8"),P=`/*start:${D}*/
|
31
|
+
${F}
|
32
|
+
/*end:${D}*/
|
33
|
+
`;d=`${d.replace(/\}$/,"")}
|
34
|
+
${P}
|
35
|
+
}`}}),u.writeFileSync(g,d)})}}catch(s){console.error(s)}},Te=async(e,t,s=ye())=>{try{const n=await W(e);if(L(t)){const a=u.readFileSync(t,"utf8");a.replace(/^(?!export\s)const\s.*/gm,g=>`export ${g}`)!==a&&await X.writeFile(t,a);const p=await ee(e),r=await v(e,t,n);let o=a;if(Object.entries(r).forEach(([g,d])=>{var C;if(d.isKeyframes||!d.generator)return;const y=d.generator._withBuildContext({name:g,config:p,prod:s}),k=new RegExp(`\\s${g}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(a);if(!k)return console.error("Could not find the original declaration");const D=(C=k.at(1))==null?void 0:C.trim(),_=new RegExp(`\\s${g}[=\\s]+styled\\(`,"g").exec(o);if(!_)return console.error("Could not find the original declaration");const{index:j}=_;let F=!1;const P=setTimeout(()=>F=!0,5e3);let b=0,E=!1,f=0;for(;!E&&!F;){const h=o[j+b];h==="("&&f++,h===")"&&f--,f===0&&h===")"&&(E=!0),b>o.length&&(F=!0),b++}if(!F)clearTimeout(P);else throw new Error("Failed to find the end of the styled call and timed out");const $=j+b,S=o.slice(j,$),w=o,m=` ${g} = styled(${D}, "${y.classNames}", ${JSON.stringify(y.props)});`;o=o.replace(S,m),w===o&&console.error("Minimize file failed to change content",{name:g,tagName:D})}),p.importStrategy==="component"){const g=H(t,6),d=l.parse(t);o=`import '../../saltygen/css/${`f_${R(d.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=De;exports.generateFile=Pe;exports.isSaltyFile=L;exports.minimizeFile=Te;exports.saltyFileRegExp=pe;
|
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-CLeyuKRw.cjs"),y=require("fs/promises"),g=require("fs"),p=async e=>{if(!e||e.includes("node_modules")||e.includes("saltygen"))return!1;if(e.includes("salty.config"))return!0;if(!t.isSaltyFile(e))return!1;const a=await y.readFile(e,"utf-8");return!!/.+define[A-Z]\w+/.test(a)},c=(e,s,l=!1,a=!1)=>{var n,u,i;(u=(n=e.module)==null?void 0:n.rules)==null||u.push({test:t.saltyFileRegExp(),use:[{loader:d.resolve(__dirname,a?"./loader.cjs":"./loader.js"),options:{dir:s}}]}),l||(i=e.plugins)==null||i.push({apply:f=>{let o=!1;f.hooks.watchRun.tapPromise({name:"generateCss"},async()=>{o||(o=!0,await t.generateCss(s),g.watch(s,{recursive:!0},async(h,r)=>{await p(r)?await t.generateCss(s):t.isSaltyFile(r)&&await t.generateFile(s,r)}))})}})};exports.default=c;exports.saltyPlugin=c;
|
package/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { resolve as d } from "path";
|
2
|
-
import { i as c, s as p, g as u, a as y } from "./index-
|
2
|
+
import { i as c, s as p, g as u, a as y } from "./index-B5p2PCY4.js";
|
3
3
|
import { readFile as g } from "fs/promises";
|
4
4
|
import { watch as m } from "fs";
|
5
5
|
const w = async (s) => {
|
package/loader.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";const i=require("./index-
|
1
|
+
"use strict";const i=require("./index-CLeyuKRw.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.180",
|
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.180",
|
38
38
|
"webpack": ">=5.x"
|
39
39
|
}
|
40
40
|
}
|
package/index-B8Y5B15R.cjs
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
"use strict";const me=require("esbuild"),he=require("child_process"),a=require("path"),l=require("fs"),X=require("fs/promises"),z=require("winston");var U=typeof document<"u"?document.currentScript:null;function Se(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const ne=Se(me),te=e=>String.fromCharCode(e+(e>25?39:97)),be=(e,t)=>{let s="",n;for(n=Math.abs(e);n>52;n=n/52|0)s=te(n%52)+s;return s=te(n%52)+s,s.length<t?s=s.padStart(t,"a"):s.length>t&&(s=s.slice(-t)),s},je=(e,t)=>{let s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return e},Z=(e,t=5)=>{const s=je(5381,JSON.stringify(e))>>>0;return be(s,t)};function R(e){return e?typeof e!="string"?R(String(e)):e.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?"-":"")+t.toLowerCase()):""}const $e=(e,t)=>{if(typeof e!="string")return{result:e};if(!t)return{result:e};const s=[];return Object.values(t).forEach(n=>{const{pattern:c,transform:r}=n;e=e.replace(c,u=>{const{value:p,css:o}=r(u);return o&&s.push(o),p})}),{result:e,additionalCss:s}},oe=e=>typeof e!="string"?{result:e}:/\{[^{}]+\}/g.test(e)?{result:e.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${R(n[1].replaceAll(".","-"))})`)}:{result:e},M=(e,t,s)=>{if(!e)return"";const n=[],c=Object.entries(e).reduce((u,[p,o])=>{const i=p.trim();if(typeof o=="function"&&(o=o()),typeof o=="object"){if(!o)return u;if(i==="variants")return Object.entries(o).forEach(([$,x])=>{x&&Object.entries(x).forEach(([f,S])=>{if(!S)return;const w=`${t}.${$}-${f}`,g=M(S,w);n.push(g)})}),u;if(i==="defaultVariants")return u;if(i==="compoundVariants")return o.forEach($=>{const{css:x,...f}=$,S=Object.entries(f).reduce((g,[m,F])=>`${g}.${m}-${F}`,t),w=M(x,S);n.push(w)}),u;if(i.startsWith("@")){const $=M(o,t),x=`${i} {
|
2
|
-
${$.replace(`
|
3
|
-
`,`
|
4
|
-
`)}
|
5
|
-
}`;return n.push(x),u}const j=p.includes("&")?i.replace("&",t):i.startsWith(":")?`${t}${i}`:`${t} ${i}`,C=M(o,j);return n.push(C),u}const d=i.startsWith("-")?i:R(i),y=(j,C=";")=>u=`${u}${j}${C}`,b=j=>y(`${d}:${j}`);if(typeof o=="number")return b(o);if(typeof o!="string")if("toString"in o)o=o.toString();else return u;const{modifiers:D}={},E=function*(){yield oe(o),yield $e(o,D)}();for(const{result:j,additionalCss:C=[]}of E)o=j,C.forEach($=>{const x=M($,"");y(x,"")});return b(o)},"");return c?t?[`${t} { ${c} }`,...n].join(`
|
6
|
-
`):c:n.join(`
|
7
|
-
`)},re=(e,t=[])=>{if(!e)return"";const s=[],n={};if(Object.entries(e).forEach(([c,r])=>{if(typeof r=="object"){if(!r)return;const u=c.trim(),p=re(r,[...t,u]);s.push(p)}else n[c]=r}),Object.keys(n).length){const c=t.map(R).join("-"),r=M(n,`.${c}`);s.push(r)}return s.join(`
|
8
|
-
`)},we=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="object"&&(t[s]=ie(n).map(c=>`"${c}"`).join(" | ")),t),{}):{},ie=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,c])=>{const r=t?`${t}.${n}`:n;return typeof c=="object"?ie(c,r,s):s.add(t)}),[...s]):[],ce=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=a.join(e,"package.json");return l.existsSync(t)?t:ce(a.join(e,".."))},Fe=async e=>{const t=ce(e);return await X.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Ce=async e=>{const t=await Fe(e);if(t)return t.type};let J;const ae=async e=>{if(J)return J;const t=await Ce(e);return t==="module"?J="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:U&&U.tagName.toUpperCase()==="SCRIPT"&&U.src||new URL("index-B8Y5B15R.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 le(e){return e?typeof e!="string"?le(String(e)):e.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?".":"")+t.toLowerCase()):""}const xe={"*, *::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"}},I=(...e)=>e.flat().reduce((t,s)=>s!=null&&s._current?{...t,...s._current}:{...t,...s},{}),O={externalModules:[],rcFile:void 0,destDir:void 0},fe=e=>{if(O.externalModules.length>0)return O.externalModules;const s=l.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(c=>c.replace(/['"`]/g,"").trim());return O.externalModules=n,n},A=async e=>{if(O.destDir)return O.destDir;const t=await Y(e),s=a.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return O.destDir=s,s},ue=["salty","css","styles","styled"],pe=(e=[])=>new RegExp(`\\.(${[...ue,...e].join("|")})\\.`),H=(e,t=[])=>pe(t).test(e),de=async e=>{if(O.rcFile)return O.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=a.join(e,".saltyrc.json"),s=await X.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(O.rcFile=s,s):de(a.join(e,".."))},Y=async e=>{var n,c;const t=await de(e),s=(n=t.projects)==null?void 0:n.find(r=>e.endsWith(r.dir||""));return s||((c=t.projects)==null?void 0:c.find(r=>r.dir===t.defaultProject))},ke=async e=>{const t=await Y(e),s=await A(e),n=a.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),c=a.join(s,"salty.config.js"),r=await ae(e),u=fe(n);await ne.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:c,format:r,external:u});const p=Date.now(),{config:o}=await import(`${c}?t=${p}`);return o},Ne=async(e,t)=>{const s=await ke(e),n={...s},c=new Set,r=(N,k=[])=>N?Object.entries(N).flatMap(([_,T])=>{if(!T)return;if(typeof T=="object")return r(T,[...k,_]);const L=le(_),G=R(_),B=[...k,L].join(".");c.add(`"${B}"`);const K=[...k.map(R),G].join("-"),{result:ge}=oe(T);return`--${K}: ${ge};`}):[],u=N=>N?Object.entries(N).flatMap(([k,_])=>{const T=r(_);return k==="base"?T.join(""):`${k} { ${T.join("")} }`}):[],p=N=>N?Object.entries(N).flatMap(([k,_])=>Object.entries(_).flatMap(([T,L])=>{const G=r(L,[k]),B=`.${k}-${T}, [data-${k}="${T}"]`,K=G.join("");return`${B} { ${K} }`})):[],o=N=>t.variables.map(k=>k._current[N]),i=r(I(s.variables,o("variables"))),d=u(I(s.responsiveVariables,o("responsiveVariables"))),y=p(I(s.conditionalVariables,o("conditionalVariables"))),b=await A(e),D=a.join(b,"css/_variables.css"),P=`:root { ${i.join("")} ${d.join("")} } ${y.join("")}`;l.writeFileSync(D,P);const E=a.join(b,"css/_global.css"),j=I(s.global,t.globalStyles),C=M(j,"");l.writeFileSync(E,`@layer global { ${C} }`);const $=a.join(b,"css/_reset.css"),f=s.reset==="none"?{}:typeof s.reset=="object"?s.reset:xe,S=M(f,"");l.writeFileSync($,`@layer reset { ${S} }`);const w=a.join(b,"css/_templates.css"),g=I(s.templates,t.templates);console.log("all",g);const m=re(g),F=we(g);l.writeFileSync(w,m),n.templates=g;const h=a.join(b,"types/css-tokens.d.ts"),W=`
|
9
|
-
// Variable types
|
10
|
-
type VariableTokens = ${[...c].join("|")};
|
11
|
-
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
12
|
-
|
13
|
-
// Template types
|
14
|
-
type TemplateTokens = {
|
15
|
-
${Object.entries(F).map(([N,k])=>`${N}?: ${k}`).join(`
|
16
|
-
`)}
|
17
|
-
}
|
18
|
-
`;l.writeFileSync(h,W);const q=a.join(b,"cache/config-cache.json");l.writeFileSync(q,JSON.stringify(n,null,2))},se=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const c=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!c.test(e))return t;const u=c.exec(e);if(u){const p=u.at(1);if(ue.some(i=>p==null?void 0:p.includes(i)))return t}return"styled('div',"}),v=async(e,t,s)=>{const n=Z(t),c=a.join(s,"./temp");l.existsSync(c)||l.mkdirSync(c);const r=a.parse(t);let u=l.readFileSync(t,"utf8");u=se(u);const p=a.join(s,"js",n+".js"),o=await Y(e),i=a.join(e,(o==null?void 0:o.configDir)||"","salty.config.ts"),d=fe(i),y=await ae(e);await ne.build({stdin:{contents:u,sourcefile:r.base,resolveDir:r.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:p,format:y,target:["node20"],keepNames:!0,external:d,packages:"external",plugins:[{name:"test",setup:P=>{P.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},E=>{const j=l.readFileSync(E.path,"utf8");return{contents:se(j),loader:"ts"}})}}]});const b=Date.now();return await import(`${p}?t=${b}`)},ee=async e=>{const t=await A(e),s=a.join(t,"cache/config-cache.json"),n=l.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ye=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},De=async(e,t=ye())=>{try{const s=Date.now();t?Q.info("Generating CSS in production mode! 🔥"):Q.info("Generating CSS in development mode! 🚀");const n=[],c=[],r=await A(e),u=a.join(r,"index.css");(()=>{l.existsSync(r)&&he.execSync("rm -rf "+r),l.mkdirSync(r,{recursive:!0}),l.mkdirSync(a.join(r,"css")),l.mkdirSync(a.join(r,"types")),l.mkdirSync(a.join(r,"js")),l.mkdirSync(a.join(r,"cache"))})();const o={keyframes:[],mediaQueries:[],globalStyles:[],variables:[],components:[],templates:[]};async function i(f){const S=["node_modules","saltygen"],w=l.statSync(f);if(w.isDirectory()){const g=l.readdirSync(f);if(S.some(F=>f.includes(F)))return;await Promise.all(g.map(F=>i(a.join(f,F))))}else if(w.isFile()&&H(f)){const m=await v(e,f,r);Object.entries(m).forEach(([F,h])=>{h.isKeyframes?o.keyframes.push({value:h,src:f,name:F}):h.isMedia?o.mediaQueries.push(h):h.isGlobalDefine?o.globalStyles.push(h):h.isDefineVariables?o.variables.push(h):h.isDefineTemplates?o.templates.push(h):h.generator&&o.components.push({value:h.generator,src:f,name:F})})}}await i(e),await Ne(e,o);const d=await ee(e);for(const f of o.keyframes){const{value:S}=f,w=`a_${S.animationName}.css`,g=`css/${w}`,m=a.join(r,g);n.push(w),l.writeFileSync(m,S.css)}const y={};for(const f of o.components){const{value:S,name:w,src:g}=f,m=S._withBuildContext({name:w,config:d,prod:t});c[m.priority]||(c[m.priority]=[]),c[m.priority].push(m.cssFileName),d.importStrategy==="component"&&(y[g]?y[g].push(m.cssFileName):y[g]=[m.cssFileName]);const F=`css/${m.cssFileName}`,h=a.join(r,F);l.writeFileSync(h,m.css)}d.importStrategy==="component"&&Object.entries(y).forEach(([f,S])=>{const w=S.map(V=>`@import url('./${V}');`).join(`
|
19
|
-
`),g=Z(f,6),m=a.parse(f),F=R(m.name),h=a.join(r,`css/f_${F}-${g}.css`);l.writeFileSync(h,w)});const b=n.map(f=>`@import url('./css/${f}');`).join(`
|
20
|
-
`);let j=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
21
|
-
|
22
|
-
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(f=>{try{return l.readFileSync(a.join(r,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
|
23
|
-
`)}
|
24
|
-
${b}`;if(d.importStrategy!=="component"){const f=c.reduce((S,w,g)=>{const m=w.reduce((W,q)=>{var T;const N=a.join(r,"css",q),k=l.readFileSync(N,"utf8"),_=((T=/.*-([^-]+)-\d+.css/.exec(q))==null?void 0:T.at(1))||Z(N,6);return W.includes(_)?W:`${W}
|
25
|
-
/*start:${_}*/
|
26
|
-
${k}
|
27
|
-
/*end:${_}*/
|
28
|
-
`},""),F=`l_${g}.css`,h=a.join(r,"css",F),V=`@layer l${g} { ${m}
|
29
|
-
}`;return l.writeFileSync(h,V),`${S}
|
30
|
-
@import url('./css/${F}');`},"");j+=f}l.writeFileSync(u,j);const $=Date.now()-s,x=$<200?"🔥":$<500?"🚀":$<1e3?"🎉":$<2e3?"🚗":$<5e3?"🤔":"🥴";Q.info(`Generated CSS in ${$}ms! ${x}`)}catch(s){console.error(s)}},Pe=async(e,t)=>{try{const s=await A(e);if(H(t)){const c=[],r=await ee(e),u=await v(e,t,s);Object.entries(u).forEach(([p,o])=>{if(o.isKeyframes&&o.css){const D=`css/${`a_${o.animationName}.css`}`,P=a.join(s,D);l.writeFileSync(P,o.css);return}if(!o.generator)return;const i=o.generator._withBuildContext({name:p,config:r}),d=`css/${i.cssFileName}`,y=a.join(s,d);l.writeFileSync(y,i.css),c[i.priority]||(c[i.priority]=[]),c[i.priority].push(i.cssFileName)}),r.importStrategy!=="component"&&c.forEach((p,o)=>{const i=`l_${o}.css`,d=a.join(s,"css",i);let y=l.readFileSync(d,"utf8");p.forEach(b=>{var j;const D=a.join(s,"css",b),P=((j=/.*-([^-]+)-\d+.css/.exec(b))==null?void 0:j.at(1))||Z(D,6);if(!y.includes(P)){const C=l.readFileSync(D,"utf8"),$=`/*start:${P}*/
|
31
|
-
${C}
|
32
|
-
/*end:${P}*/
|
33
|
-
`;y=`${y.replace(/\}$/,"")}
|
34
|
-
${$}
|
35
|
-
}`}}),l.writeFileSync(d,y)})}}catch(s){console.error(s)}},Te=async(e,t,s=ye())=>{try{const n=await A(e);if(H(t)){const r=l.readFileSync(t,"utf8");r.replace(/^(?!export\s)const\s.*/gm,d=>`export ${d}`)!==r&&await X.writeFile(t,r);const p=await ee(e),o=await v(e,t,n);let i=r;if(Object.entries(o).forEach(([d,y])=>{var h;if(y.isKeyframes||!y.generator)return;const b=y.generator._withBuildContext({name:d,config:p,prod:s}),D=new RegExp(`\\s${d}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(r);if(!D)return console.error("Could not find the original declaration");const P=(h=D.at(1))==null?void 0:h.trim(),E=new RegExp(`\\s${d}[=\\s]+styled\\(`,"g").exec(i);if(!E)return console.error("Could not find the original declaration");const{index:j}=E;let C=!1;const $=setTimeout(()=>C=!0,5e3);let x=0,f=!1,S=0;for(;!f&&!C;){const V=i[j+x];V==="("&&S++,V===")"&&S--,S===0&&V===")"&&(f=!0),x>i.length&&(C=!0),x++}if(!C)clearTimeout($);else throw new Error("Failed to find the end of the styled call and timed out");const w=j+x,g=i.slice(j,w),m=i,F=` ${d} = styled(${P}, "${b.classNames}", ${JSON.stringify(b.props)});`;i=i.replace(g,F),m===i&&console.error("Minimize file failed to change content",{name:d,tagName:P})}),p.importStrategy==="component"){const d=Z(t,6),y=a.parse(t);i=`import '../../saltygen/css/${`f_${R(y.name)}-${d}.css`}';
|
36
|
-
${i}`}return i=i.replace("{ styled }","{ styledClient as styled }"),i=i.replace("@salty-css/react/styled","@salty-css/react/styled-client"),i}}catch(n){console.error("Error in minimizeFile:",n)}};exports.generateCss=De;exports.generateFile=Pe;exports.isSaltyFile=H;exports.minimizeFile=Te;exports.saltyFileRegExp=pe;
|
package/index-ChWI7ezV.js
DELETED
@@ -1,487 +0,0 @@
|
|
1
|
-
import * as rt from "esbuild";
|
2
|
-
import { execSync as $t } from "child_process";
|
3
|
-
import { join as a, parse as X } from "path";
|
4
|
-
import { existsSync as Y, writeFileSync as P, readFileSync as _, mkdirSync as W, statSync as bt, readdirSync as St } from "fs";
|
5
|
-
import { readFile as it, writeFile as wt } from "fs/promises";
|
6
|
-
import { createLogger as jt, format as Q, transports as Ct } from "winston";
|
7
|
-
const nt = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), Ft = (t, e) => {
|
8
|
-
let s = "", o;
|
9
|
-
for (o = Math.abs(t); o > 52; o = o / 52 | 0) s = nt(o % 52) + s;
|
10
|
-
return s = nt(o % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
|
11
|
-
}, xt = (t, e) => {
|
12
|
-
let s = e.length;
|
13
|
-
for (; s; ) t = t * 33 ^ e.charCodeAt(--s);
|
14
|
-
return t;
|
15
|
-
}, I = (t, e = 5) => {
|
16
|
-
const s = xt(5381, JSON.stringify(t)) >>> 0;
|
17
|
-
return Ft(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 kt = (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((o) => {
|
27
|
-
const { pattern: c, transform: r } = o;
|
28
|
-
t = t.replace(c, (f) => {
|
29
|
-
const { value: p, css: n } = r(f);
|
30
|
-
return n && s.push(n), p;
|
31
|
-
});
|
32
|
-
}), { result: t, additionalCss: s };
|
33
|
-
}, ct = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...o) => `var(--${A(o[1].replaceAll(".", "-"))})`) } : { result: t }, J = (t, e, s) => {
|
34
|
-
if (!t) return "";
|
35
|
-
const o = [], c = Object.entries(t).reduce((f, [p, n]) => {
|
36
|
-
const i = p.trim();
|
37
|
-
if (typeof n == "function" && (n = n()), typeof n == "object") {
|
38
|
-
if (!n) return f;
|
39
|
-
if (i === "variants")
|
40
|
-
return Object.entries(n).forEach(([S, F]) => {
|
41
|
-
F && Object.entries(F).forEach(([l, y]) => {
|
42
|
-
if (!y) return;
|
43
|
-
const w = `${e}.${S}-${l}`, g = J(y, w);
|
44
|
-
o.push(g);
|
45
|
-
});
|
46
|
-
}), f;
|
47
|
-
if (i === "defaultVariants")
|
48
|
-
return f;
|
49
|
-
if (i === "compoundVariants")
|
50
|
-
return n.forEach((S) => {
|
51
|
-
const { css: F, ...l } = S, y = Object.entries(l).reduce((g, [m, j]) => `${g}.${m}-${j}`, e), w = J(F, y);
|
52
|
-
o.push(w);
|
53
|
-
}), f;
|
54
|
-
if (i.startsWith("@")) {
|
55
|
-
const S = J(n, e), F = `${i} {
|
56
|
-
${S.replace(`
|
57
|
-
`, `
|
58
|
-
`)}
|
59
|
-
}`;
|
60
|
-
return o.push(F), f;
|
61
|
-
}
|
62
|
-
const b = p.includes("&") ? i.replace("&", e) : i.startsWith(":") ? `${e}${i}` : `${e} ${i}`, C = J(n, b);
|
63
|
-
return o.push(C), f;
|
64
|
-
}
|
65
|
-
const u = i.startsWith("-") ? i : A(i), d = (b, C = ";") => f = `${f}${b}${C}`, $ = (b) => d(`${u}:${b}`);
|
66
|
-
if (typeof n == "number") return $(n);
|
67
|
-
if (typeof n != "string")
|
68
|
-
if ("toString" in n) n = n.toString();
|
69
|
-
else return f;
|
70
|
-
const { modifiers: N } = {}, O = function* () {
|
71
|
-
yield ct(n), yield kt(n, N);
|
72
|
-
}();
|
73
|
-
for (const { result: b, additionalCss: C = [] } of O)
|
74
|
-
n = b, C.forEach((S) => {
|
75
|
-
const F = J(S, "");
|
76
|
-
d(F, "");
|
77
|
-
});
|
78
|
-
return $(n);
|
79
|
-
}, "");
|
80
|
-
return c ? e ? [`${e} { ${c} }`, ...o].join(`
|
81
|
-
`) : c : o.join(`
|
82
|
-
`);
|
83
|
-
}, at = (t, e = []) => {
|
84
|
-
if (!t) return "";
|
85
|
-
const s = [], o = {};
|
86
|
-
if (Object.entries(t).forEach(([c, r]) => {
|
87
|
-
if (typeof r == "object") {
|
88
|
-
if (!r) return;
|
89
|
-
const f = c.trim(), p = at(r, [...e, f]);
|
90
|
-
s.push(p);
|
91
|
-
} else
|
92
|
-
o[c] = r;
|
93
|
-
}), Object.keys(o).length) {
|
94
|
-
const c = e.map(A).join("-"), r = J(o, `.${c}`);
|
95
|
-
s.push(r);
|
96
|
-
}
|
97
|
-
return s.join(`
|
98
|
-
`);
|
99
|
-
}, Nt = (t) => t ? Object.entries(t).reduce((e, [s, o]) => (typeof o == "object" && (e[s] = lt(o).map((c) => `"${c}"`).join(" | ")), e), {}) : {}, lt = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([o, c]) => {
|
100
|
-
const r = e ? `${e}.${o}` : o;
|
101
|
-
return typeof c == "object" ? lt(c, r, s) : s.add(e);
|
102
|
-
}), [...s]) : [], ft = (t) => {
|
103
|
-
if (!t || t === "/") throw new Error("Could not find package.json file");
|
104
|
-
const e = a(t, "package.json");
|
105
|
-
return Y(e) ? e : ft(a(t, ".."));
|
106
|
-
}, Dt = async (t) => {
|
107
|
-
const e = ft(t);
|
108
|
-
return await it(e, "utf-8").then(JSON.parse).catch(() => {
|
109
|
-
});
|
110
|
-
}, Pt = async (t) => {
|
111
|
-
const e = await Dt(t);
|
112
|
-
if (e)
|
113
|
-
return e.type;
|
114
|
-
};
|
115
|
-
let R;
|
116
|
-
const pt = async (t) => {
|
117
|
-
if (R) return R;
|
118
|
-
const e = await Pt(t);
|
119
|
-
return e === "module" ? R = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (R = "cjs"), R || "esm";
|
120
|
-
}, U = jt({
|
121
|
-
level: "debug",
|
122
|
-
format: Q.combine(Q.colorize(), Q.cli()),
|
123
|
-
transports: [new Ct.Console({})]
|
124
|
-
});
|
125
|
-
function ut(t) {
|
126
|
-
return t ? typeof t != "string" ? ut(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 Et = {
|
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
|
-
}, H = (...t) => t.flat().reduce((e, s) => s != null && s._current ? { ...e, ...s._current } : { ...e, ...s }, {}), V = {
|
175
|
-
externalModules: [],
|
176
|
-
rcFile: void 0,
|
177
|
-
destDir: void 0
|
178
|
-
}, dt = (t) => {
|
179
|
-
if (V.externalModules.length > 0) return V.externalModules;
|
180
|
-
const s = _(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
181
|
-
if (!s) return [];
|
182
|
-
const o = s[1].split(",").map((c) => c.replace(/['"`]/g, "").trim());
|
183
|
-
return V.externalModules = o, o;
|
184
|
-
}, z = async (t) => {
|
185
|
-
if (V.destDir) return V.destDir;
|
186
|
-
const e = await tt(t), s = a(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
|
187
|
-
return V.destDir = s, s;
|
188
|
-
}, gt = ["salty", "css", "styles", "styled"], Tt = (t = []) => new RegExp(`\\.(${[...gt, ...t].join("|")})\\.`), v = (t, e = []) => Tt(e).test(t), mt = 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 it(e, "utf-8").then(JSON.parse).catch(() => {
|
192
|
-
});
|
193
|
-
return s ? (V.rcFile = s, s) : mt(a(t, ".."));
|
194
|
-
}, tt = async (t) => {
|
195
|
-
var o, c;
|
196
|
-
const e = await mt(t), s = (o = e.projects) == null ? void 0 : o.find((r) => t.endsWith(r.dir || ""));
|
197
|
-
return s || ((c = e.projects) == null ? void 0 : c.find((r) => r.dir === e.defaultProject));
|
198
|
-
}, Ot = async (t) => {
|
199
|
-
const e = await tt(t), s = await z(t), o = a(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), c = a(s, "salty.config.js"), r = await pt(t), f = dt(o);
|
200
|
-
await rt.build({
|
201
|
-
entryPoints: [o],
|
202
|
-
minify: !0,
|
203
|
-
treeShaking: !0,
|
204
|
-
bundle: !0,
|
205
|
-
outfile: c,
|
206
|
-
format: r,
|
207
|
-
external: f
|
208
|
-
});
|
209
|
-
const p = Date.now(), { config: n } = await import(`${c}?t=${p}`);
|
210
|
-
return n;
|
211
|
-
}, Vt = async (t, e) => {
|
212
|
-
const s = await Ot(t), o = { ...s }, c = /* @__PURE__ */ new Set(), r = (k, x = []) => k ? Object.entries(k).flatMap(([T, E]) => {
|
213
|
-
if (!E) return;
|
214
|
-
if (typeof E == "object") return r(E, [...x, T]);
|
215
|
-
const L = ut(T), B = A(T), K = [...x, L].join(".");
|
216
|
-
c.add(`"${K}"`);
|
217
|
-
const q = [...x.map(A), B].join("-"), { result: yt } = ct(E);
|
218
|
-
return `--${q}: ${yt};`;
|
219
|
-
}) : [], f = (k) => k ? Object.entries(k).flatMap(([x, T]) => {
|
220
|
-
const E = r(T);
|
221
|
-
return x === "base" ? E.join("") : `${x} { ${E.join("")} }`;
|
222
|
-
}) : [], p = (k) => k ? Object.entries(k).flatMap(([x, T]) => Object.entries(T).flatMap(([E, L]) => {
|
223
|
-
const B = r(L, [x]), K = `.${x}-${E}, [data-${x}="${E}"]`, q = B.join("");
|
224
|
-
return `${K} { ${q} }`;
|
225
|
-
})) : [], n = (k) => e.variables.map((x) => x._current[k]), i = r(H(s.variables, n("variables"))), u = f(H(s.responsiveVariables, n("responsiveVariables"))), d = p(H(s.conditionalVariables, n("conditionalVariables"))), $ = await z(t), N = a($, "css/_variables.css"), D = `:root { ${i.join("")} ${u.join("")} } ${d.join("")}`;
|
226
|
-
P(N, D);
|
227
|
-
const O = a($, "css/_global.css"), b = H(s.global, e.globalStyles), C = J(b, "");
|
228
|
-
P(O, `@layer global { ${C} }`);
|
229
|
-
const S = a($, "css/_reset.css"), l = s.reset === "none" ? {} : typeof s.reset == "object" ? s.reset : Et, y = J(l, "");
|
230
|
-
P(S, `@layer reset { ${y} }`);
|
231
|
-
const w = a($, "css/_templates.css"), g = H(s.templates, e.templates);
|
232
|
-
console.log("all", g);
|
233
|
-
const m = at(g), j = Nt(g);
|
234
|
-
P(w, m), o.templates = g;
|
235
|
-
const h = a($, "types/css-tokens.d.ts"), Z = `
|
236
|
-
// Variable types
|
237
|
-
type VariableTokens = ${[...c].join("|")};
|
238
|
-
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
239
|
-
|
240
|
-
// Template types
|
241
|
-
type TemplateTokens = {
|
242
|
-
${Object.entries(j).map(([k, x]) => `${k}?: ${x}`).join(`
|
243
|
-
`)}
|
244
|
-
}
|
245
|
-
`;
|
246
|
-
P(h, Z);
|
247
|
-
const G = a($, "cache/config-cache.json");
|
248
|
-
P(G, JSON.stringify(o, null, 2));
|
249
|
-
}, ot = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
|
250
|
-
if (/^['"`]/.test(s)) return e;
|
251
|
-
const c = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
|
252
|
-
if (!c.test(t)) return e;
|
253
|
-
const f = c.exec(t);
|
254
|
-
if (f) {
|
255
|
-
const p = f.at(1);
|
256
|
-
if (gt.some((i) => p == null ? void 0 : p.includes(i))) return e;
|
257
|
-
}
|
258
|
-
return "styled('div',";
|
259
|
-
}), et = async (t, e, s) => {
|
260
|
-
const o = I(e), c = a(s, "./temp");
|
261
|
-
Y(c) || W(c);
|
262
|
-
const r = X(e);
|
263
|
-
let f = _(e, "utf8");
|
264
|
-
f = ot(f);
|
265
|
-
const p = a(s, "js", o + ".js"), n = await tt(t), i = a(t, (n == null ? void 0 : n.configDir) || "", "salty.config.ts"), u = dt(i), d = await pt(t);
|
266
|
-
await rt.build({
|
267
|
-
stdin: {
|
268
|
-
contents: f,
|
269
|
-
sourcefile: r.base,
|
270
|
-
resolveDir: r.dir,
|
271
|
-
loader: "tsx"
|
272
|
-
},
|
273
|
-
minify: !1,
|
274
|
-
treeShaking: !0,
|
275
|
-
bundle: !0,
|
276
|
-
outfile: p,
|
277
|
-
format: d,
|
278
|
-
target: ["node20"],
|
279
|
-
keepNames: !0,
|
280
|
-
external: u,
|
281
|
-
packages: "external",
|
282
|
-
plugins: [
|
283
|
-
{
|
284
|
-
name: "test",
|
285
|
-
setup: (D) => {
|
286
|
-
D.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (O) => {
|
287
|
-
const b = _(O.path, "utf8");
|
288
|
-
return { contents: ot(b), loader: "ts" };
|
289
|
-
});
|
290
|
-
}
|
291
|
-
}
|
292
|
-
]
|
293
|
-
});
|
294
|
-
const $ = Date.now();
|
295
|
-
return await import(`${p}?t=${$}`);
|
296
|
-
}, st = async (t) => {
|
297
|
-
const e = await z(t), s = a(e, "cache/config-cache.json"), o = _(s, "utf8");
|
298
|
-
if (!o) throw new Error("Could not find config cache file");
|
299
|
-
return JSON.parse(o);
|
300
|
-
}, ht = () => {
|
301
|
-
try {
|
302
|
-
return process.env.NODE_ENV === "production";
|
303
|
-
} catch {
|
304
|
-
return !1;
|
305
|
-
}
|
306
|
-
}, Wt = async (t, e = ht()) => {
|
307
|
-
try {
|
308
|
-
const s = Date.now();
|
309
|
-
e ? U.info("Generating CSS in production mode! 🔥") : U.info("Generating CSS in development mode! 🚀");
|
310
|
-
const o = [], c = [], r = await z(t), f = a(r, "index.css");
|
311
|
-
(() => {
|
312
|
-
Y(r) && $t("rm -rf " + r), W(r, { recursive: !0 }), W(a(r, "css")), W(a(r, "types")), W(a(r, "js")), W(a(r, "cache"));
|
313
|
-
})();
|
314
|
-
const n = {
|
315
|
-
keyframes: [],
|
316
|
-
mediaQueries: [],
|
317
|
-
globalStyles: [],
|
318
|
-
variables: [],
|
319
|
-
components: [],
|
320
|
-
templates: []
|
321
|
-
};
|
322
|
-
async function i(l) {
|
323
|
-
const y = ["node_modules", "saltygen"], w = bt(l);
|
324
|
-
if (w.isDirectory()) {
|
325
|
-
const g = St(l);
|
326
|
-
if (y.some((j) => l.includes(j))) return;
|
327
|
-
await Promise.all(g.map((j) => i(a(l, j))));
|
328
|
-
} else if (w.isFile() && v(l)) {
|
329
|
-
const m = await et(t, l, r);
|
330
|
-
Object.entries(m).forEach(([j, h]) => {
|
331
|
-
h.isKeyframes ? n.keyframes.push({
|
332
|
-
value: h,
|
333
|
-
src: l,
|
334
|
-
name: j
|
335
|
-
}) : h.isMedia ? n.mediaQueries.push(h) : h.isGlobalDefine ? n.globalStyles.push(h) : h.isDefineVariables ? n.variables.push(h) : h.isDefineTemplates ? n.templates.push(h) : h.generator && n.components.push({
|
336
|
-
value: h.generator,
|
337
|
-
src: l,
|
338
|
-
name: j
|
339
|
-
});
|
340
|
-
});
|
341
|
-
}
|
342
|
-
}
|
343
|
-
await i(t), await Vt(t, n);
|
344
|
-
const u = await st(t);
|
345
|
-
for (const l of n.keyframes) {
|
346
|
-
const { value: y } = l, w = `a_${y.animationName}.css`, g = `css/${w}`, m = a(r, g);
|
347
|
-
o.push(w), P(m, y.css);
|
348
|
-
}
|
349
|
-
const d = {};
|
350
|
-
for (const l of n.components) {
|
351
|
-
const { value: y, name: w, src: g } = l, m = y._withBuildContext({
|
352
|
-
name: w,
|
353
|
-
config: u,
|
354
|
-
prod: e
|
355
|
-
});
|
356
|
-
c[m.priority] || (c[m.priority] = []), c[m.priority].push(m.cssFileName), u.importStrategy === "component" && (d[g] ? d[g].push(m.cssFileName) : d[g] = [m.cssFileName]);
|
357
|
-
const j = `css/${m.cssFileName}`, h = a(r, j);
|
358
|
-
P(h, m.css);
|
359
|
-
}
|
360
|
-
u.importStrategy === "component" && Object.entries(d).forEach(([l, y]) => {
|
361
|
-
const w = y.map((M) => `@import url('./${M}');`).join(`
|
362
|
-
`), g = I(l, 6), m = X(l), j = A(m.name), h = a(r, `css/f_${j}-${g}.css`);
|
363
|
-
P(h, w);
|
364
|
-
});
|
365
|
-
const $ = o.map((l) => `@import url('./css/${l}');`).join(`
|
366
|
-
`);
|
367
|
-
let b = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
368
|
-
|
369
|
-
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) => {
|
370
|
-
try {
|
371
|
-
return _(a(r, "css", l), "utf8").length > 0;
|
372
|
-
} catch {
|
373
|
-
return !1;
|
374
|
-
}
|
375
|
-
}).map((l) => `@import url('./css/${l}');`).join(`
|
376
|
-
`)}
|
377
|
-
${$}`;
|
378
|
-
if (u.importStrategy !== "component") {
|
379
|
-
const l = c.reduce((y, w, g) => {
|
380
|
-
const m = w.reduce((Z, G) => {
|
381
|
-
var E;
|
382
|
-
const k = a(r, "css", G), x = _(k, "utf8"), T = ((E = /.*-([^-]+)-\d+.css/.exec(G)) == null ? void 0 : E.at(1)) || I(k, 6);
|
383
|
-
return Z.includes(T) ? Z : `${Z}
|
384
|
-
/*start:${T}*/
|
385
|
-
${x}
|
386
|
-
/*end:${T}*/
|
387
|
-
`;
|
388
|
-
}, ""), j = `l_${g}.css`, h = a(r, "css", j), M = `@layer l${g} { ${m}
|
389
|
-
}`;
|
390
|
-
return P(h, M), `${y}
|
391
|
-
@import url('./css/${j}');`;
|
392
|
-
}, "");
|
393
|
-
b += l;
|
394
|
-
}
|
395
|
-
P(f, b);
|
396
|
-
const S = Date.now() - s, F = S < 200 ? "🔥" : S < 500 ? "🚀" : S < 1e3 ? "🎉" : S < 2e3 ? "🚗" : S < 5e3 ? "🤔" : "🥴";
|
397
|
-
U.info(`Generated CSS in ${S}ms! ${F}`);
|
398
|
-
} catch (s) {
|
399
|
-
console.error(s);
|
400
|
-
}
|
401
|
-
}, zt = async (t, e) => {
|
402
|
-
try {
|
403
|
-
const s = await z(t);
|
404
|
-
if (v(e)) {
|
405
|
-
const c = [], r = await st(t), f = await et(t, e, s);
|
406
|
-
Object.entries(f).forEach(([p, n]) => {
|
407
|
-
if (n.isKeyframes && n.css) {
|
408
|
-
const N = `css/${`a_${n.animationName}.css`}`, D = a(s, N);
|
409
|
-
P(D, n.css);
|
410
|
-
return;
|
411
|
-
}
|
412
|
-
if (!n.generator) return;
|
413
|
-
const i = n.generator._withBuildContext({
|
414
|
-
name: p,
|
415
|
-
config: r
|
416
|
-
}), u = `css/${i.cssFileName}`, d = a(s, u);
|
417
|
-
P(d, i.css), c[i.priority] || (c[i.priority] = []), c[i.priority].push(i.cssFileName);
|
418
|
-
}), r.importStrategy !== "component" && c.forEach((p, n) => {
|
419
|
-
const i = `l_${n}.css`, u = a(s, "css", i);
|
420
|
-
let d = _(u, "utf8");
|
421
|
-
p.forEach(($) => {
|
422
|
-
var b;
|
423
|
-
const N = a(s, "css", $), D = ((b = /.*-([^-]+)-\d+.css/.exec($)) == null ? void 0 : b.at(1)) || I(N, 6);
|
424
|
-
if (!d.includes(D)) {
|
425
|
-
const C = _(N, "utf8"), S = `/*start:${D}*/
|
426
|
-
${C}
|
427
|
-
/*end:${D}*/
|
428
|
-
`;
|
429
|
-
d = `${d.replace(/\}$/, "")}
|
430
|
-
${S}
|
431
|
-
}`;
|
432
|
-
}
|
433
|
-
}), P(u, d);
|
434
|
-
});
|
435
|
-
}
|
436
|
-
} catch (s) {
|
437
|
-
console.error(s);
|
438
|
-
}
|
439
|
-
}, Zt = async (t, e, s = ht()) => {
|
440
|
-
try {
|
441
|
-
const o = await z(t);
|
442
|
-
if (v(e)) {
|
443
|
-
const r = _(e, "utf8");
|
444
|
-
r.replace(/^(?!export\s)const\s.*/gm, (u) => `export ${u}`) !== r && await wt(e, r);
|
445
|
-
const p = await st(t), n = await et(t, e, o);
|
446
|
-
let i = r;
|
447
|
-
if (Object.entries(n).forEach(([u, d]) => {
|
448
|
-
var h;
|
449
|
-
if (d.isKeyframes || !d.generator) return;
|
450
|
-
const $ = d.generator._withBuildContext({
|
451
|
-
name: u,
|
452
|
-
config: p,
|
453
|
-
prod: s
|
454
|
-
}), N = new RegExp(`\\s${u}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
|
455
|
-
if (!N) return console.error("Could not find the original declaration");
|
456
|
-
const D = (h = N.at(1)) == null ? void 0 : h.trim(), O = new RegExp(`\\s${u}[=\\s]+styled\\(`, "g").exec(i);
|
457
|
-
if (!O) return console.error("Could not find the original declaration");
|
458
|
-
const { index: b } = O;
|
459
|
-
let C = !1;
|
460
|
-
const S = setTimeout(() => C = !0, 5e3);
|
461
|
-
let F = 0, l = !1, y = 0;
|
462
|
-
for (; !l && !C; ) {
|
463
|
-
const M = i[b + F];
|
464
|
-
M === "(" && y++, M === ")" && y--, y === 0 && M === ")" && (l = !0), F > i.length && (C = !0), F++;
|
465
|
-
}
|
466
|
-
if (!C) clearTimeout(S);
|
467
|
-
else throw new Error("Failed to find the end of the styled call and timed out");
|
468
|
-
const w = b + F, g = i.slice(b, w), m = i, j = ` ${u} = styled(${D}, "${$.classNames}", ${JSON.stringify($.props)});`;
|
469
|
-
i = i.replace(g, j), m === i && console.error("Minimize file failed to change content", { name: u, tagName: D });
|
470
|
-
}), p.importStrategy === "component") {
|
471
|
-
const u = I(e, 6), d = X(e);
|
472
|
-
i = `import '../../saltygen/css/${`f_${A(d.name)}-${u}.css`}';
|
473
|
-
${i}`;
|
474
|
-
}
|
475
|
-
return i = i.replace("{ styled }", "{ styledClient as styled }"), i = i.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), i;
|
476
|
-
}
|
477
|
-
} catch (o) {
|
478
|
-
console.error("Error in minimizeFile:", o);
|
479
|
-
}
|
480
|
-
};
|
481
|
-
export {
|
482
|
-
zt as a,
|
483
|
-
Wt as g,
|
484
|
-
v as i,
|
485
|
-
Zt as m,
|
486
|
-
Tt as s
|
487
|
-
};
|