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