@salty-css/core 0.0.1-alpha.187 → 0.0.1-alpha.189

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