@salty-css/core 0.0.1-alpha.287 → 0.0.1-alpha.289

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