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