@salty-css/core 0.0.1-alpha.195 → 0.0.1-alpha.197
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.d.ts +1 -28
- package/compiler/index.js +1 -1
- package/helpers/color.d.ts +4 -0
- package/helpers/index.cjs +1 -1
- package/helpers/index.js +30 -28
- package/index-DZmq1drj.js +481 -0
- package/index-UDCa37Mh.cjs +35 -0
- package/package.json +1 -1
- package/server/index.cjs +1 -1
- package/server/index.js +1 -1
- package/types/config-types.d.ts +4 -0
- package/index-B17K1OjT.js +0 -452
- package/index-jY7-PED3.cjs +0 -31
package/index-B17K1OjT.js
DELETED
@@ -1,452 +0,0 @@
|
|
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
|
-
};
|
package/index-jY7-PED3.cjs
DELETED
@@ -1,31 +0,0 @@
|
|
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;
|