@salty-css/core 0.0.1-alpha.183 → 0.0.1-alpha.184

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 oe from "esbuild";
2
+ import { execSync as me } from "child_process";
3
+ import { t as I, d as H } from "./dash-case-DBThphLm.js";
4
+ import { join as o, parse as L } from "path";
5
+ import { existsSync as U, writeFileSync as C, mkdirSync as z, readFileSync as _, statSync as ge, readdirSync as ye } from "fs";
6
+ import { readFile as ae, writeFile as he } from "fs/promises";
7
+ import { p as se, a as $e } from "./parse-styles-DrLhKtqW.js";
8
+ import { p as be, a as we } from "./parse-templates-DRKlN-pP.js";
9
+ import { createLogger as Se, format as q, transports as Ce } from "winston";
10
+ import { m as W } from "./merge-BVm9us1A.js";
11
+ const re = (e) => {
12
+ if (!e || e === "/") throw new Error("Could not find package.json file");
13
+ const t = o(e, "package.json");
14
+ return U(t) ? t : re(o(e, ".."));
15
+ }, Fe = async (e) => {
16
+ const t = re(e);
17
+ return await ae(t, "utf-8").then(JSON.parse).catch(() => {
18
+ });
19
+ }, xe = async (e) => {
20
+ const t = await Fe(e);
21
+ if (t)
22
+ return t.type;
23
+ };
24
+ let v;
25
+ const ce = async (e) => {
26
+ if (v) return v;
27
+ const t = await xe(e);
28
+ return t === "module" ? v = "esm" : (t === "commonjs" || import.meta.url.endsWith(".cjs")) && (v = "cjs"), v || "esm";
29
+ }, K = Se({
30
+ level: "debug",
31
+ format: q.combine(q.colorize(), q.cli()),
32
+ transports: [new Ce.Console({})]
33
+ }), ze = (e) => {
34
+ K.error(e);
35
+ };
36
+ function ie(e) {
37
+ return e ? typeof e != "string" ? ie(String(e)) : e.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (t, s) => (s > 0 ? "." : "") + t.toLowerCase()) : "";
38
+ }
39
+ const je = {
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
+ }, E = {
86
+ externalModules: [],
87
+ rcFile: void 0,
88
+ destDir: void 0
89
+ }, le = (e) => {
90
+ if (E.externalModules.length > 0) return E.externalModules;
91
+ const s = _(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
92
+ if (!s) return [];
93
+ const f = s[1].split(",").map((i) => i.replace(/['"`]/g, "").trim());
94
+ return E.externalModules = f, f;
95
+ }, M = async (e) => {
96
+ if (E.destDir) return E.destDir;
97
+ const t = await Y(e), s = o(e, (t == null ? void 0 : t.saltygenDir) || "saltygen");
98
+ return E.destDir = s, s;
99
+ }, fe = ["salty", "css", "styles", "styled"], Ne = (e = []) => new RegExp(`\\.(${[...fe, ...e].join("|")})\\.`), X = (e, t = []) => Ne(t).test(e), pe = async (e) => {
100
+ if (E.rcFile) return E.rcFile;
101
+ if (e === "/") throw new Error("Could not find .saltyrc.json file");
102
+ const t = o(e, ".saltyrc.json"), s = await ae(t, "utf-8").then(JSON.parse).catch(() => {
103
+ });
104
+ return s ? (E.rcFile = s, s) : pe(o(e, ".."));
105
+ }, Y = async (e) => {
106
+ var f, i;
107
+ const t = await pe(e), s = (f = t.projects) == null ? void 0 : f.find((r) => e.endsWith(r.dir || ""));
108
+ return s || ((i = t.projects) == null ? void 0 : i.find((r) => r.dir === t.defaultProject));
109
+ }, ke = async (e) => {
110
+ const t = await Y(e), s = await M(e), f = o(e, (t == null ? void 0 : t.configDir) || "", "salty.config.ts"), i = o(s, "salty.config.js"), r = await ce(e), l = le(f);
111
+ await oe.build({
112
+ entryPoints: [f],
113
+ minify: !0,
114
+ treeShaking: !0,
115
+ bundle: !0,
116
+ outfile: i,
117
+ format: r,
118
+ external: l
119
+ });
120
+ const y = Date.now(), { config: p } = await import(`${i}?t=${y}`);
121
+ return p;
122
+ }, De = async (e, t) => {
123
+ const s = await ke(e), f = { ...s }, i = /* @__PURE__ */ new Set(), r = (j, S = []) => j ? Object.entries(j).flatMap(([T, N]) => {
124
+ if (!N) return;
125
+ if (typeof N == "object") return r(N, [...S, T]);
126
+ const R = ie(T), Z = H(T), A = [...S, R].join(".");
127
+ i.add(`"${A}"`);
128
+ const Q = [...S.map(H), Z].join("-"), { result: ue } = $e(N);
129
+ return `--${Q}: ${ue};`;
130
+ }) : [], l = (j) => j ? Object.entries(j).flatMap(([S, T]) => {
131
+ const N = r(T);
132
+ return S === "base" ? N.join("") : `${S} { ${N.join("")} }`;
133
+ }) : [], y = (j) => j ? Object.entries(j).flatMap(([S, T]) => Object.entries(T).flatMap(([N, R]) => {
134
+ const Z = r(R, [S]), A = `.${S}-${N}, [data-${S}="${N}"]`, Q = Z.join("");
135
+ return `${A} { ${Q} }`;
136
+ })) : [], p = (j) => t.variables.map((S) => S._current[j]), n = r(W(s.variables, p("variables"))), g = l(W(s.responsiveVariables, p("responsiveVariables"))), m = y(W(s.conditionalVariables, p("conditionalVariables"))), c = await M(e), x = o(c, "css/_variables.css"), F = `:root { ${n.join("")} ${g.join("")} } ${m.join("")}`;
137
+ C(x, F);
138
+ const V = o(c, "css/_global.css"), P = W(s.global, t.globalStyles), k = se(P, "");
139
+ C(V, `@layer global { ${k} }`);
140
+ const O = o(c, "css/_reset.css"), J = s.reset === "none" ? {} : typeof s.reset == "object" ? s.reset : je, a = se(J, "");
141
+ C(O, `@layer reset { ${a} }`);
142
+ const w = o(c, "css/_templates.css"), h = W(s.templates, t.templates), b = be(h), d = we(h);
143
+ C(w, b), f.templates = h;
144
+ const $ = o(c, "types/css-tokens.d.ts"), B = `
145
+ // Variable types
146
+ type VariableTokens = ${[...i].join("|")};
147
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
148
+
149
+ // Template types
150
+ type TemplateTokens = {
151
+ ${Object.entries(d).map(([j, S]) => `${j}?: ${S}`).join(`
152
+ `)}
153
+ }
154
+ `;
155
+ C($, B);
156
+ const G = o(c, "cache/config-cache.json");
157
+ C(G, JSON.stringify(f, null, 2));
158
+ }, ne = (e) => e.replace(/styled\(([^"'`{,]+),/g, (t, s) => {
159
+ if (/^['"`]/.test(s)) return t;
160
+ const i = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
161
+ if (!i.test(e)) return t;
162
+ const l = i.exec(e);
163
+ if (l) {
164
+ const y = l.at(1);
165
+ if (fe.some((n) => y == null ? void 0 : y.includes(n))) return t;
166
+ }
167
+ return "styled('div',";
168
+ }), ee = async (e, t, s) => {
169
+ const f = I(t), i = o(s, "./temp");
170
+ U(i) || z(i);
171
+ const r = L(t);
172
+ let l = _(t, "utf8");
173
+ l = ne(l);
174
+ const y = o(s, "js", f + ".js"), p = await Y(e), n = o(e, (p == null ? void 0 : p.configDir) || "", "salty.config.ts"), g = le(n), m = await ce(e);
175
+ await oe.build({
176
+ stdin: {
177
+ contents: l,
178
+ sourcefile: r.base,
179
+ resolveDir: r.dir,
180
+ loader: "tsx"
181
+ },
182
+ minify: !1,
183
+ treeShaking: !0,
184
+ bundle: !0,
185
+ outfile: y,
186
+ format: m,
187
+ target: ["node20"],
188
+ keepNames: !0,
189
+ external: g,
190
+ packages: "external",
191
+ plugins: [
192
+ {
193
+ name: "test",
194
+ setup: (F) => {
195
+ F.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (V) => {
196
+ const P = _(V.path, "utf8");
197
+ return { contents: ne(P), loader: "ts" };
198
+ });
199
+ }
200
+ }
201
+ ]
202
+ });
203
+ const c = Date.now();
204
+ return await import(`${y}?t=${c}`);
205
+ }, Pe = async (e) => {
206
+ const t = await M(e), s = o(t, "cache/config-cache.json"), f = _(s, "utf8");
207
+ if (!f) throw new Error("Could not find config cache file");
208
+ return JSON.parse(f);
209
+ }, te = async (e) => {
210
+ const t = await Pe(e), s = await M(e), f = o(s, "salty.config.js"), i = Date.now(), { config: r } = await import(`${f}?t=${i}`);
211
+ return W(r, t);
212
+ }, de = () => {
213
+ try {
214
+ return process.env.NODE_ENV === "production";
215
+ } catch {
216
+ return !1;
217
+ }
218
+ }, We = async (e, t = de(), s = !0) => {
219
+ try {
220
+ const f = Date.now();
221
+ t ? K.info("Generating CSS in production mode! 🔥") : K.info("Generating CSS in development mode! 🚀");
222
+ const i = [], r = [], l = await M(e), y = o(l, "index.css");
223
+ s && (() => {
224
+ U(l) && me("rm -rf " + l), z(l, { recursive: !0 }), z(o(l, "css")), z(o(l, "types")), z(o(l, "js")), z(o(l, "cache"));
225
+ })();
226
+ const n = {
227
+ keyframes: [],
228
+ mediaQueries: [],
229
+ globalStyles: [],
230
+ variables: [],
231
+ templates: [],
232
+ components: [],
233
+ classNames: []
234
+ };
235
+ async function g(a) {
236
+ const w = ["node_modules", "saltygen"], h = ge(a);
237
+ if (h.isDirectory()) {
238
+ const b = ye(a);
239
+ if (w.some(($) => a.includes($))) return;
240
+ await Promise.all(b.map(($) => g(o(a, $))));
241
+ } else if (h.isFile() && X(a)) {
242
+ const d = await ee(e, a, l);
243
+ Object.entries(d).forEach(([$, u]) => {
244
+ u.isKeyframes ? n.keyframes.push({
245
+ value: u,
246
+ src: a,
247
+ name: $
248
+ }) : u.isMedia ? n.mediaQueries.push(u) : u.isGlobalDefine ? n.globalStyles.push(u) : u.isDefineVariables ? n.variables.push(u) : u.isDefineTemplates ? n.templates.push(u) : u.isClassName ? n.classNames.push({
249
+ value: u.factory,
250
+ src: a,
251
+ name: $
252
+ }) : u.generator && n.components.push({
253
+ value: u.generator,
254
+ src: a,
255
+ name: $
256
+ });
257
+ });
258
+ }
259
+ }
260
+ await g(e), await De(e, n);
261
+ const m = await te(e);
262
+ for (const a of n.keyframes) {
263
+ const { value: w } = a, h = `a_${w.animationName}.css`, b = `css/${h}`, d = o(l, b);
264
+ i.push(h), C(d, w.css);
265
+ }
266
+ const c = {};
267
+ for (const a of n.components) {
268
+ const { value: w, name: h, src: b } = a, d = w._withBuildContext({
269
+ name: h,
270
+ config: m,
271
+ prod: t
272
+ });
273
+ r[d.priority] || (r[d.priority] = []), r[d.priority].push(d.cssFileName);
274
+ const $ = `css/${d.cssFileName}`, u = o(l, $);
275
+ C(u, d.css), m.importStrategy === "component" && (c[b] ? c[b].push(d.cssFileName) : c[b] = [d.cssFileName]);
276
+ }
277
+ for (const a of n.classNames) {
278
+ const { value: w, src: h, name: b } = a, d = w._withBuildContext({
279
+ name: b,
280
+ prod: t
281
+ });
282
+ r[0].push(d.cssFileName);
283
+ const $ = `css/${d.cssFileName}`, u = o(l, $);
284
+ C(u, d.css), m.importStrategy === "component" && (c[h] ? c[h].push(d.cssFileName) : c[h] = [d.cssFileName]);
285
+ }
286
+ m.importStrategy === "component" && Object.entries(c).forEach(([a, w]) => {
287
+ const h = w.map((B) => `@import url('./${B}');`).join(`
288
+ `), b = I(a, 6), d = L(a), $ = H(d.name), u = o(l, `css/f_${$}-${b}.css`);
289
+ C(u, h);
290
+ });
291
+ const x = i.map((a) => `@import url('./css/${a}');`).join(`
292
+ `);
293
+ let k = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
294
+
295
+ ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((a) => {
296
+ try {
297
+ return _(o(l, "css", a), "utf8").length > 0;
298
+ } catch {
299
+ return !1;
300
+ }
301
+ }).map((a) => `@import url('./css/${a}');`).join(`
302
+ `)}
303
+ ${x}`;
304
+ if (m.importStrategy !== "component") {
305
+ const a = r.reduce((w, h, b) => {
306
+ const d = h.reduce((G, j) => {
307
+ var R;
308
+ const S = o(l, "css", j), T = _(S, "utf8"), N = ((R = /.*-([^-]+)-\d+.css/.exec(j)) == null ? void 0 : R.at(1)) || I(S, 6);
309
+ return G.includes(N) ? G : `${G}
310
+ /*start:${N}*/
311
+ ${T}
312
+ /*end:${N}*/
313
+ `;
314
+ }, ""), $ = `l_${b}.css`, u = o(l, "css", $), B = `@layer l${b} { ${d}
315
+ }`;
316
+ return C(u, B), `${w}
317
+ @import url('./css/${$}');`;
318
+ }, "");
319
+ k += a;
320
+ }
321
+ C(y, k);
322
+ const D = Date.now() - f, J = D < 200 ? "🔥" : D < 500 ? "🚀" : D < 1e3 ? "🎉" : D < 2e3 ? "🚗" : D < 5e3 ? "🤔" : "🥴";
323
+ K.info(`Generated CSS in ${D}ms! ${J}`);
324
+ } catch (f) {
325
+ console.error(f);
326
+ }
327
+ }, Ie = async (e, t) => {
328
+ try {
329
+ const s = await M(e);
330
+ if (X(t)) {
331
+ const i = [], r = await te(e), l = await ee(e, t, s);
332
+ if (Object.entries(l).forEach(([y, p]) => {
333
+ if (p.isKeyframes && p.css) {
334
+ const x = `css/${`a_${p.animationName}.css`}`, F = o(s, x);
335
+ C(F, p.css);
336
+ return;
337
+ }
338
+ if (p.isClassName) {
339
+ console.log("found className value", p);
340
+ const c = p.factory._withBuildContext({
341
+ name: y
342
+ });
343
+ i[0].push(c.cssFileName);
344
+ const x = `css/${c.cssFileName}`, F = o(s, x);
345
+ C(F, c.css), console.log(F, c.css);
346
+ }
347
+ if (!p.generator) return;
348
+ const n = p.generator._withBuildContext({
349
+ name: y,
350
+ config: r
351
+ }), g = `css/${n.cssFileName}`, m = o(s, g);
352
+ C(m, n.css), i[n.priority] || (i[n.priority] = []), i[n.priority].push(n.cssFileName);
353
+ }), console.log(i), r.importStrategy !== "component")
354
+ i.forEach((y, p) => {
355
+ const n = `l_${p}.css`, g = o(s, "css", n);
356
+ let m = _(g, "utf8");
357
+ y.forEach((c) => {
358
+ var P;
359
+ const x = o(s, "css", c), F = ((P = /.*-([^-]+)-\d+.css/.exec(c)) == null ? void 0 : P.at(1)) || I(x, 6);
360
+ if (!m.includes(F)) {
361
+ const k = _(x, "utf8"), O = `/*start:${F}*/
362
+ ${k}
363
+ /*end:${F}*/
364
+ `;
365
+ m = `${m.replace(/\}$/, "")}
366
+ ${O}
367
+ }`;
368
+ }
369
+ }), C(g, m);
370
+ });
371
+ else {
372
+ const y = i.flat().map((c) => `@import url('./${c}');`).join(`
373
+ `), p = I(t, 6), n = L(t), g = H(n.name), m = o(s, `css/f_${g}-${p}.css`);
374
+ C(m, y);
375
+ }
376
+ }
377
+ } catch (s) {
378
+ console.error(s);
379
+ }
380
+ }, Be = async (e, t, s = de()) => {
381
+ try {
382
+ const f = await M(e);
383
+ if (X(t)) {
384
+ const r = _(t, "utf8");
385
+ r.replace(/^(?!export\s)const\s.*/gm, (g) => `export ${g}`) !== r && await he(t, r);
386
+ const y = await te(e), p = await ee(e, t, f);
387
+ let n = r;
388
+ if (Object.entries(p).forEach(([g, m]) => {
389
+ var $;
390
+ if (m.isKeyframes || !m.generator) return;
391
+ const c = m.generator._withBuildContext({
392
+ name: g,
393
+ config: y,
394
+ prod: s
395
+ }), x = new RegExp(`\\s${g}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
396
+ if (!x) return console.error("Could not find the original declaration");
397
+ const F = ($ = x.at(1)) == null ? void 0 : $.trim(), V = new RegExp(`\\s${g}[=\\s]+styled\\(`, "g").exec(n);
398
+ if (!V) return console.error("Could not find the original declaration");
399
+ const { index: P } = V;
400
+ let k = !1;
401
+ const O = setTimeout(() => k = !0, 5e3);
402
+ let D = 0, J = !1, a = 0;
403
+ for (; !J && !k; ) {
404
+ const u = n[P + D];
405
+ u === "(" && a++, u === ")" && a--, a === 0 && u === ")" && (J = !0), D > n.length && (k = !0), D++;
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 w = P + D, h = n.slice(P, w), b = n, d = ` ${g} = styled(${F}, "${c.classNames}", ${JSON.stringify(c.props)});`;
410
+ n = n.replace(h, d), b === n && console.error("Minimize file failed to change content", { name: g, tagName: F });
411
+ }), y.importStrategy === "component") {
412
+ const g = I(t, 6), m = L(t);
413
+ n = `import '../../saltygen/css/${`f_${H(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 (f) {
419
+ console.error("Error in minimizeFile:", f);
420
+ }
421
+ };
422
+ export {
423
+ ze as a,
424
+ Ne as b,
425
+ De as c,
426
+ ee as d,
427
+ Ie as e,
428
+ We as g,
429
+ X as i,
430
+ K as l,
431
+ Be as m,
432
+ fe 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.183",
3
+ "version": "0.0.1-alpha.184",
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-zPXqhZf1.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-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;
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-BjclEscx.js";
2
+ import { i as e } from "../index-DKkgPK-r.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;