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