@salty-css/core 0.0.1-alpha.205 → 0.0.1-alpha.206

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,495 @@
1
+ import * as mt from "esbuild";
2
+ import { execSync as Nt } from "child_process";
3
+ import { d as B, t as v } from "./dash-case-DBThphLm.js";
4
+ import { join as i, parse as Y } from "path";
5
+ import { existsSync as it, writeFileSync as j, mkdirSync as W, readFileSync as _, statSync as Pt, readdirSync as kt } from "fs";
6
+ import { readFile as gt, writeFile as Dt } from "fs/promises";
7
+ import { p as at, a as _t } from "./parse-styles-CkaV3OGz.js";
8
+ import { createLogger as Tt, format as ot, transports as Et } from "winston";
9
+ import { mergeObjects as I, mergeFactories as Ot } from "./css/merge.js";
10
+ const yt = async (t, e = []) => {
11
+ if (!t) return "";
12
+ const s = [], o = {};
13
+ for (const [n, a] of Object.entries(t))
14
+ if (typeof a != "function") if (a && typeof a == "object") {
15
+ const r = n.trim(), u = await yt(a, [...e, r]);
16
+ s.push(u);
17
+ } else
18
+ o[n] = a;
19
+ if (Object.keys(o).length) {
20
+ const n = e.map(B).join("-"), a = "t_" + v(n, 4), r = await at(o, `.${n}, .${a}`);
21
+ s.push(r);
22
+ }
23
+ return s.join(`
24
+ `);
25
+ }, Vt = (t) => t ? Object.entries(t).reduce((e, [s, o]) => (typeof o == "function" ? e[s] = "any" : typeof o == "object" && (e[s] = ht(o).map((n) => `"${n}"`).join(" | ")), e), {}) : {}, ht = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([o, n]) => {
26
+ const a = e ? `${e}.${o}` : o;
27
+ return typeof n == "object" ? ht(n, a, s) : s.add(e);
28
+ }), [...s]) : [], bt = (t) => {
29
+ if (!t || t === "/") throw new Error("Could not find package.json file");
30
+ const e = i(t, "package.json");
31
+ return it(e) ? e : bt(i(t, ".."));
32
+ }, Mt = async (t) => {
33
+ const e = bt(t);
34
+ return await gt(e, "utf-8").then(JSON.parse).catch(() => {
35
+ });
36
+ }, vt = async (t) => {
37
+ const e = await Mt(t);
38
+ if (e)
39
+ return e.type;
40
+ };
41
+ let z;
42
+ const $t = async (t) => {
43
+ if (z) return z;
44
+ const e = await vt(t);
45
+ return e === "module" ? z = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (z = "cjs"), z || "esm";
46
+ }, X = Tt({
47
+ level: "debug",
48
+ format: ot.combine(ot.colorize(), ot.cli()),
49
+ transports: [new Et.Console({})]
50
+ }), Ut = (t) => {
51
+ X.error(t);
52
+ };
53
+ function wt(t) {
54
+ return t ? typeof t != "string" ? wt(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "." : "") + e.toLowerCase()) : "";
55
+ }
56
+ const Rt = {
57
+ /** Set box model to border-box */
58
+ "*, *::before, *::after": {
59
+ boxSizing: "border-box"
60
+ },
61
+ /** Remove default margin and padding */
62
+ "*": {
63
+ margin: 0
64
+ },
65
+ /** Remove adjust font properties */
66
+ html: {
67
+ lineHeight: 1.15,
68
+ textSizeAdjust: "100%",
69
+ WebkitFontSmoothing: "antialiased"
70
+ },
71
+ /** Make media elements responsive */
72
+ "img, picture, video, canvas, svg": {
73
+ display: "block",
74
+ maxWidth: "100%"
75
+ },
76
+ /** Avoid overflow of text */
77
+ "p, h1, h2, h3, h4, h5, h6": {
78
+ overflowWrap: "break-word"
79
+ },
80
+ /** Improve text wrapping */
81
+ p: {
82
+ textWrap: "pretty"
83
+ },
84
+ "h1, h2, h3, h4, h5, h6": {
85
+ textWrap: "balance"
86
+ },
87
+ /** Improve link color */
88
+ a: {
89
+ color: "currentColor"
90
+ },
91
+ /** Improve button line height */
92
+ button: {
93
+ lineHeight: "1em",
94
+ color: "currentColor"
95
+ },
96
+ /** Improve form elements */
97
+ "input, optgroup, select, textarea": {
98
+ fontFamily: "inherit",
99
+ fontSize: "100%",
100
+ lineHeight: "1.15em"
101
+ }
102
+ }, M = {
103
+ externalModules: [],
104
+ rcFile: void 0,
105
+ destDir: void 0
106
+ }, St = (t) => {
107
+ if (M.externalModules.length > 0) return M.externalModules;
108
+ const s = _(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
109
+ if (!s) return [];
110
+ const o = s[1].split(",").map((n) => n.replace(/['"`]/g, "").trim());
111
+ return M.externalModules = o, o;
112
+ }, R = async (t) => {
113
+ if (M.destDir) return M.destDir;
114
+ const e = await ct(t), s = i(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
115
+ return M.destDir = s, s;
116
+ }, Ct = ["salty", "css", "styles", "styled"], Jt = (t = []) => new RegExp(`\\.(${[...Ct, ...t].join("|")})\\.`), rt = (t, e = []) => Jt(e).test(t), Ft = async (t) => {
117
+ if (M.rcFile) return M.rcFile;
118
+ if (t === "/") throw new Error("Could not find .saltyrc.json file");
119
+ const e = i(t, ".saltyrc.json"), s = await gt(e, "utf-8").then(JSON.parse).catch(() => {
120
+ });
121
+ return s ? (M.rcFile = s, s) : Ft(i(t, ".."));
122
+ }, ct = async (t) => {
123
+ var o, n;
124
+ const e = await Ft(t), s = (o = e.projects) == null ? void 0 : o.find((a) => t.endsWith(a.dir || ""));
125
+ return s || ((n = e.projects) == null ? void 0 : n.find((a) => a.dir === e.defaultProject));
126
+ }, zt = async (t) => {
127
+ const e = await ct(t), s = await R(t), o = i(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), n = i(s, "salty.config.js"), a = await $t(t), r = St(o);
128
+ await mt.build({
129
+ entryPoints: [o],
130
+ minify: !0,
131
+ treeShaking: !0,
132
+ bundle: !0,
133
+ outfile: n,
134
+ format: a,
135
+ external: r
136
+ });
137
+ const u = Date.now(), { config: d } = await import(`${n}?t=${u}`);
138
+ return d;
139
+ }, Wt = async (t, e) => {
140
+ var ft, ut;
141
+ const s = await R(t), o = {
142
+ mediaQueries: [],
143
+ globalStyles: [],
144
+ variables: [],
145
+ templates: []
146
+ };
147
+ await Promise.all(
148
+ [...e].map(async (y) => {
149
+ const { contents: S, outputFilePath: V } = await tt(t, y, s);
150
+ Object.entries(S).forEach(([P, D]) => {
151
+ D.isMedia ? o.mediaQueries.push([P, D]) : D.isGlobalDefine ? o.globalStyles.push(D) : D.isDefineVariables ? o.variables.push(D) : D.isDefineTemplates && o.templates.push(D._setPath(V));
152
+ });
153
+ })
154
+ );
155
+ const n = await zt(t), a = { ...n }, r = /* @__PURE__ */ new Set(), u = (y, S = []) => y ? Object.entries(y).flatMap(([V, P]) => {
156
+ if (!P) return;
157
+ if (typeof P == "object") return u(P, [...S, V]);
158
+ const D = wt(V), st = B(V), nt = [...S, D].join(".");
159
+ r.add(`"${nt}"`);
160
+ const U = [...S.map(B), st].join("-"), pt = _t(P);
161
+ return pt ? `--${U}: ${pt.transformed};` : `--${U}: ${P};`;
162
+ }) : [], d = (y) => y ? Object.entries(y).flatMap(([S, V]) => {
163
+ const P = u(V);
164
+ return S === "base" ? P.join("") : `${S} { ${P.join("")} }`;
165
+ }) : [], f = (y) => y ? Object.entries(y).flatMap(([S, V]) => Object.entries(V).flatMap(([P, D]) => {
166
+ const st = u(D, [S]), nt = `.${S}-${P}, [data-${S}="${P}"]`, U = st.join("");
167
+ return `${nt} { ${U} }`;
168
+ })) : [], p = (y) => ({ ...y, responsive: void 0, conditional: void 0 }), m = (y) => o.variables.map((S) => y === "static" ? p(S._current) : S._current[y]), h = I(p(n.variables), m("static")), $ = u(h), g = I((ft = n.variables) == null ? void 0 : ft.responsive, m("responsive")), x = d(g), N = I((ut = n.variables) == null ? void 0 : ut.conditional, m("conditional")), T = f(N), J = i(s, "css/_variables.css"), E = `:root { ${$.join("")} ${x.join("")} } ${T.join("")}`;
169
+ j(J, E), a.staticVariables = h;
170
+ const G = i(s, "css/_global.css"), k = I(n.global, o.globalStyles), H = await at(k, "");
171
+ j(G, `@layer global { ${H} }`);
172
+ const c = i(s, "css/_reset.css"), w = n.reset === "none" ? {} : typeof n.reset == "object" ? n.reset : Rt, l = await at(w, "");
173
+ j(c, `@layer reset { ${l} }`);
174
+ const C = i(s, "css/_templates.css"), F = I(n.templates, o.templates), O = await yt(F), K = Vt(F);
175
+ j(C, `@layer templates { ${O} }`), a.templates = F;
176
+ const A = Ot(o.templates);
177
+ a.templatePaths = Object.fromEntries(Object.entries(A).map(([y, S]) => [y, S._path]));
178
+ const { mediaQueries: L } = o;
179
+ a.mediaQueries = Object.fromEntries(L.map(([y, S]) => [`@${y}`, S]));
180
+ const Q = L.map(([y]) => `'@${y}'`).join(" | "), et = i(s, "types/css-tokens.d.ts"), q = `
181
+ // Variable types
182
+ type VariableTokens = ${[...r].join("|")};
183
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
184
+
185
+ // Template types
186
+ type TemplateTokens = {
187
+ ${Object.entries(K).map(([y, S]) => `${y}?: ${S}`).join(`
188
+ `)}
189
+ }
190
+
191
+ // Media query types
192
+ type MediaQueryKeys = ${Q || "''"};
193
+ `;
194
+ j(et, q);
195
+ const xt = i(s, "cache/config-cache.json");
196
+ j(xt, JSON.stringify(a, null, 2));
197
+ }, dt = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
198
+ if (/^['"`]/.test(s)) return e;
199
+ const n = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
200
+ if (!n.test(t)) return e;
201
+ const r = n.exec(t);
202
+ if (r) {
203
+ const u = r.at(1);
204
+ if (Ct.some((f) => u == null ? void 0 : u.includes(f))) return e;
205
+ }
206
+ return "styled('div',";
207
+ }), It = (t, e) => {
208
+ try {
209
+ const s = _(i(e, "saltygen/cache/config-cache.json"), "utf8");
210
+ return s ? `globalThis.saltyConfig = ${s};
211
+
212
+ ${t}` : `globalThis.saltyConfig = {};
213
+
214
+ ${t}`;
215
+ } catch {
216
+ return t;
217
+ }
218
+ }, tt = async (t, e, s) => {
219
+ const o = v(e), n = i(s, "./temp");
220
+ it(n) || W(n);
221
+ const a = Y(e);
222
+ let r = _(e, "utf8");
223
+ r = dt(r), r = It(r, t);
224
+ const u = i(s, "js", o + ".js"), d = await ct(t), f = i(t, (d == null ? void 0 : d.configDir) || "", "salty.config.ts"), p = St(f), m = await $t(t);
225
+ await mt.build({
226
+ stdin: {
227
+ contents: r,
228
+ sourcefile: a.base,
229
+ resolveDir: a.dir,
230
+ loader: "tsx"
231
+ },
232
+ minify: !1,
233
+ treeShaking: !0,
234
+ bundle: !0,
235
+ outfile: u,
236
+ format: m,
237
+ target: ["node20"],
238
+ keepNames: !0,
239
+ external: p,
240
+ packages: "external",
241
+ plugins: [
242
+ {
243
+ name: "test",
244
+ setup: (g) => {
245
+ g.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (x) => {
246
+ const N = _(x.path, "utf8");
247
+ return { contents: dt(N), loader: "ts" };
248
+ });
249
+ }
250
+ }
251
+ ]
252
+ });
253
+ const h = Date.now();
254
+ return { contents: await import(`${u}?t=${h}`), outputFilePath: u };
255
+ }, Bt = async (t) => {
256
+ const e = await R(t), s = i(e, "cache/config-cache.json"), o = _(s, "utf8");
257
+ if (!o) throw new Error("Could not find config cache file");
258
+ return JSON.parse(o);
259
+ }, lt = async (t) => {
260
+ const e = await Bt(t), s = await R(t), o = i(s, "salty.config.js"), n = Date.now(), { config: a } = await import(`${o}?t=${n}`);
261
+ return I(a, e);
262
+ }, jt = () => {
263
+ try {
264
+ return process.env.NODE_ENV === "production";
265
+ } catch {
266
+ return !1;
267
+ }
268
+ }, Xt = async (t, e = jt(), s = !0) => {
269
+ try {
270
+ const o = Date.now();
271
+ e ? X.info("Generating CSS in production mode! 🔥") : X.info("Generating CSS in development mode! 🚀");
272
+ const n = [], a = [], r = await R(t), u = i(r, "index.css");
273
+ s && (() => {
274
+ it(r) && Nt("rm -rf " + r), W(r, { recursive: !0 }), W(i(r, "css")), W(i(r, "types")), W(i(r, "js")), W(i(r, "cache"));
275
+ })();
276
+ const f = /* @__PURE__ */ new Set(), p = /* @__PURE__ */ new Set();
277
+ async function m(c) {
278
+ const b = ["node_modules", "saltygen"], w = Pt(c);
279
+ if (w.isDirectory()) {
280
+ const l = kt(c);
281
+ if (b.some((F) => c.includes(F))) return;
282
+ await Promise.all(l.map((F) => m(i(c, F))));
283
+ } else if (w.isFile() && rt(c)) {
284
+ f.add(c);
285
+ const C = _(c, "utf8");
286
+ /define[\w\d]+\(/.test(C) && p.add(c);
287
+ }
288
+ }
289
+ await m(t), await Wt(t, p);
290
+ const h = {
291
+ keyframes: [],
292
+ components: [],
293
+ classNames: []
294
+ };
295
+ await Promise.all(
296
+ [...f].map(async (c) => {
297
+ const { contents: b } = await tt(t, c, r);
298
+ Object.entries(b).forEach(([w, l]) => {
299
+ l.isKeyframes ? h.keyframes.push({
300
+ value: l,
301
+ src: c,
302
+ name: w
303
+ }) : l.isClassName ? h.classNames.push({
304
+ ...l,
305
+ src: c,
306
+ name: w
307
+ }) : l.generator && h.components.push({
308
+ ...l,
309
+ src: c,
310
+ name: w
311
+ });
312
+ });
313
+ })
314
+ );
315
+ const $ = await lt(t);
316
+ for (const c of h.keyframes) {
317
+ const { value: b } = c, w = `a_${b.animationName}.css`, l = `css/${w}`, C = i(r, l);
318
+ n.push(w), j(C, b.css);
319
+ }
320
+ const g = {};
321
+ for (const c of h.components) {
322
+ const { src: b, name: w } = c, l = c.generator._withBuildContext({
323
+ callerName: w,
324
+ isProduction: e,
325
+ config: $
326
+ });
327
+ a[l.priority] || (a[l.priority] = []);
328
+ const C = await l.css;
329
+ if (!C) continue;
330
+ a[l.priority].push(l.cssFileName);
331
+ const F = `css/${l.cssFileName}`, O = i(r, F);
332
+ j(O, C), $.importStrategy === "component" && (g[b] ? g[b].push(l.cssFileName) : g[b] = [l.cssFileName]);
333
+ }
334
+ for (const c of h.classNames) {
335
+ const { src: b, name: w } = c, l = c.generator._withBuildContext({
336
+ callerName: w,
337
+ isProduction: e,
338
+ config: $
339
+ }), C = await l.css;
340
+ if (!C) continue;
341
+ a[0].push(l.cssFileName);
342
+ const F = `css/${l.cssFileName}`, O = i(r, F);
343
+ j(O, C), $.importStrategy === "component" && (g[b] ? g[b].push(l.cssFileName) : g[b] = [l.cssFileName]);
344
+ }
345
+ $.importStrategy === "component" && Object.entries(g).forEach(([c, b]) => {
346
+ const w = b.map((K) => `@import url('./${K}');`).join(`
347
+ `), l = v(c, 6), C = Y(c), F = B(C.name), O = i(r, `css/f_${F}-${l}.css`);
348
+ j(O, w);
349
+ });
350
+ const x = n.map((c) => `@import url('./css/${c}');`).join(`
351
+ `);
352
+ let E = `@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
353
+
354
+ ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((c) => {
355
+ try {
356
+ return _(i(r, "css", c), "utf8").length > 0;
357
+ } catch {
358
+ return !1;
359
+ }
360
+ }).map((c) => `@import url('./css/${c}');`).join(`
361
+ `)}
362
+ ${x}`;
363
+ if ($.importStrategy !== "component") {
364
+ const c = a.reduce((b, w, l) => {
365
+ const C = w.reduce((A, L) => {
366
+ var q;
367
+ const Q = i(r, "css", L), et = _(Q, "utf8"), Z = ((q = /.*-([^-]+)-\d+.css/.exec(L)) == null ? void 0 : q.at(1)) || v(Q, 6);
368
+ return A.includes(Z) ? A : `${A}
369
+ /*start:${Z}*/
370
+ ${et}
371
+ /*end:${Z}*/
372
+ `;
373
+ }, ""), F = `l_${l}.css`, O = i(r, "css", F), K = `@layer l${l} { ${C}
374
+ }`;
375
+ return j(O, K), `${b}
376
+ @import url('./css/${F}');`;
377
+ }, "");
378
+ E += c;
379
+ }
380
+ j(u, E);
381
+ const k = Date.now() - o, H = k < 200 ? "🔥" : k < 500 ? "🚀" : k < 1e3 ? "🎉" : k < 2e3 ? "🚗" : k < 5e3 ? "🤔" : "🥴";
382
+ X.info(`Generated CSS in ${k}ms! ${H}`);
383
+ } catch (o) {
384
+ console.error(o);
385
+ }
386
+ }, Yt = async (t, e) => {
387
+ try {
388
+ const s = await R(t);
389
+ if (rt(e)) {
390
+ const n = [], a = await lt(t), { contents: r } = await tt(t, e, s);
391
+ for (const [u, d] of Object.entries(r)) {
392
+ if (d.isKeyframes && d.css) {
393
+ const g = `css/${`a_${d.animationName}.css`}`, x = i(s, g);
394
+ j(x, await d.css);
395
+ return;
396
+ }
397
+ if (d.isClassName) {
398
+ const $ = d.generator._withBuildContext({
399
+ name: u
400
+ }), g = await $.css;
401
+ if (!g) continue;
402
+ n[0].push($.cssFileName);
403
+ const x = `css/${$.cssFileName}`, N = i(s, x);
404
+ j(N, g);
405
+ }
406
+ if (!d.generator) return;
407
+ const f = d.generator._withBuildContext({
408
+ name: u,
409
+ config: a
410
+ }), p = await f.css;
411
+ if (!p) continue;
412
+ const m = `css/${f.cssFileName}`, h = i(s, m);
413
+ j(h, p), n[f.priority] || (n[f.priority] = []), n[f.priority].push(f.cssFileName);
414
+ }
415
+ if (a.importStrategy !== "component")
416
+ n.forEach((u, d) => {
417
+ const f = `l_${d}.css`, p = i(s, "css", f);
418
+ let m = _(p, "utf8");
419
+ u.forEach((h) => {
420
+ var N;
421
+ const $ = i(s, "css", h), g = ((N = /.*-([^-]+)-\d+.css/.exec(h)) == null ? void 0 : N.at(1)) || v($, 6);
422
+ if (!m.includes(g)) {
423
+ const T = _($, "utf8"), J = `/*start:${g}*/
424
+ ${T}
425
+ /*end:${g}*/
426
+ `;
427
+ m = `${m.replace(/\}$/, "")}
428
+ ${J}
429
+ }`;
430
+ }
431
+ }), j(p, m);
432
+ });
433
+ else {
434
+ const u = n.flat().map((h) => `@import url('./${h}');`).join(`
435
+ `), d = v(e, 6), f = Y(e), p = B(f.name), m = i(s, `css/f_${p}-${d}.css`);
436
+ j(m, u);
437
+ }
438
+ }
439
+ } catch (s) {
440
+ console.error(s);
441
+ }
442
+ }, te = async (t, e, s = jt()) => {
443
+ try {
444
+ const o = await R(t);
445
+ if (rt(e)) {
446
+ const a = _(e, "utf8");
447
+ a.replace(/^(?!export\s)const\s.*/gm, (p) => `export ${p}`) !== a && await Dt(e, a);
448
+ const u = await lt(t), { contents: d } = await tt(t, e, o);
449
+ let f = a;
450
+ if (Object.entries(d).forEach(([p, m]) => {
451
+ var l;
452
+ if (m.isKeyframes || !m.generator) return;
453
+ const h = m.generator._withBuildContext({
454
+ name: p,
455
+ config: u,
456
+ prod: s
457
+ }), $ = new RegExp(`\\s${p}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(a);
458
+ if (!$) return console.error("Could not find the original declaration");
459
+ const g = (l = $.at(1)) == null ? void 0 : l.trim(), x = new RegExp(`\\s${p}[=\\s]+styled\\(`, "g").exec(f);
460
+ if (!x) return console.error("Could not find the original declaration");
461
+ const { index: N } = x;
462
+ let T = !1;
463
+ const J = setTimeout(() => T = !0, 5e3);
464
+ let E = 0, G = !1, k = 0;
465
+ for (; !G && !T; ) {
466
+ const C = f[N + E];
467
+ C === "(" && k++, C === ")" && k--, k === 0 && C === ")" && (G = !0), E > f.length && (T = !0), E++;
468
+ }
469
+ if (!T) clearTimeout(J);
470
+ else throw new Error("Failed to find the end of the styled call and timed out");
471
+ const H = N + E, c = f.slice(N, H), b = f, w = ` ${p} = styled(${g}, "${h.classNames}", ${JSON.stringify(h.clientProps)});`;
472
+ f = f.replace(c, w), b === f && console.error("Minimize file failed to change content", { name: p, tagName: g });
473
+ }), u.importStrategy === "component") {
474
+ const p = v(e, 6), m = Y(e);
475
+ f = `import '../../saltygen/css/${`f_${B(m.name)}-${p}.css`}';
476
+ ${f}`;
477
+ }
478
+ return f = f.replace("{ styled }", "{ styledClient as styled }"), f = f.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), f;
479
+ }
480
+ } catch (o) {
481
+ console.error("Error in minimizeFile:", o);
482
+ }
483
+ };
484
+ export {
485
+ Ut as a,
486
+ Jt as b,
487
+ Wt as c,
488
+ tt as d,
489
+ Yt as e,
490
+ Xt as g,
491
+ rt as i,
492
+ X as l,
493
+ te as m,
494
+ Ct as s
495
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/core",
3
- "version": "0.0.1-alpha.205",
3
+ "version": "0.0.1-alpha.206",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -0,0 +1,126 @@
1
+ import { d as V } from "./dash-case-DBThphLm.js";
2
+ const A = (i) => (e) => {
3
+ if (typeof e != "string" || !i) return;
4
+ let t = e;
5
+ const f = [];
6
+ return Object.values(i).forEach((n) => {
7
+ const { pattern: y, transform: b } = n;
8
+ t = t.replace(y, (P) => {
9
+ const { value: j, css: E } = b(P);
10
+ return E && f.push(E), j;
11
+ });
12
+ }), { transformed: t, additionalCss: f };
13
+ }, z = (i) => (e) => typeof e != "string" || !/\{[^{}]+\}/g.test(e) ? void 0 : { transformed: e.replace(/\{([^{}]+)\}/g, (...n) => `var(--${V(n[1].replaceAll(".", "-"))})`) }, I = z(), M = [
14
+ "top",
15
+ "right",
16
+ "bottom",
17
+ "left",
18
+ "min-width",
19
+ /.*width.*/,
20
+ /^[^line]*height.*/,
21
+ // Exclude line-height
22
+ /padding.*/,
23
+ /margin.*/,
24
+ /border.*/,
25
+ /inset.*/,
26
+ /.*radius.*/,
27
+ /.*spacing.*/,
28
+ /.*gap.*/,
29
+ /.*indent.*/,
30
+ /.*offset.*/,
31
+ /.*size.*/,
32
+ /.*thickness.*/,
33
+ /.*font-size.*/
34
+ ], Q = (i, e, t) => {
35
+ if (M.some((n) => typeof n == "string" ? n === i : n.test(i))) {
36
+ const n = (t == null ? void 0 : t.defaultUnit) || "px";
37
+ return `${e}${n}`;
38
+ }
39
+ return `${e}`;
40
+ }, _ = ["Webkit", "Moz", "ms", "O"], q = (i) => i.startsWith("-") ? i : _.some((e) => i.startsWith(e)) ? `-${V(i)}` : V(i), l = async (i, e = "", t, f = !1) => {
41
+ if (!i) throw new Error("No styles provided to parseStyles function!");
42
+ const n = /* @__PURE__ */ new Set(), b = Object.entries(i).map(async ([$, s]) => {
43
+ var w;
44
+ const r = $.trim(), h = q(r), c = (a, d = ";") => `${h}:${a}${d}`;
45
+ if (typeof s == "function" && (s = s({ scope: e, config: t })), s instanceof Promise && (s = await s), t != null && t.templates && t.templatePaths[r]) {
46
+ const { default: a } = await import(t.templatePaths[r]);
47
+ if (typeof a.params[r] == "function") {
48
+ const d = await a.params[r](s), [o] = await l(d, "");
49
+ return o;
50
+ }
51
+ }
52
+ if (t != null && t.templates && t.templates[r]) {
53
+ if (f) return;
54
+ const d = s.split(".").reduce((o, p) => o[p], t.templates[r]);
55
+ if (d) {
56
+ const [o] = await l(d, "");
57
+ return o;
58
+ }
59
+ console.warn(`Template "${r}" with path of "${s}" was not found in config!`);
60
+ return;
61
+ }
62
+ if (typeof s == "object") {
63
+ if (!s) return;
64
+ if (s.isColor) return c(s.toString());
65
+ if (r === "defaultVariants") return;
66
+ if (r === "variants") {
67
+ const o = Object.entries(s);
68
+ for (const [p, u] of o) {
69
+ if (!u) return;
70
+ const C = Object.entries(u);
71
+ for (const [W, m] of C) {
72
+ if (!m) return;
73
+ const T = `${e}.${p}-${W}`;
74
+ (await l(m, T, t)).forEach((U) => n.add(U));
75
+ }
76
+ }
77
+ return;
78
+ }
79
+ if (r === "compoundVariants") {
80
+ for (const o of s) {
81
+ const { css: p, ...u } = o, C = Object.entries(u).reduce((m, [T, N]) => `${m}.${T}-${N}`, e);
82
+ (await l(p, C, t)).forEach((m) => n.add(m));
83
+ }
84
+ return;
85
+ }
86
+ if (r.startsWith("@")) {
87
+ const o = ((w = t == null ? void 0 : t.mediaQueries) == null ? void 0 : w[r]) || r, p = await k(s, e, t), u = `${o} { ${p} }`;
88
+ n.add(u);
89
+ return;
90
+ }
91
+ const a = $.includes("&") ? r.replace("&", e) : r.startsWith(":") ? `${e}${r}` : `${e} ${r}`;
92
+ (await l(s, a, t)).forEach((o) => n.add(o));
93
+ return;
94
+ }
95
+ if (typeof s == "number") {
96
+ const a = Q(h, s, t);
97
+ return c(a);
98
+ }
99
+ if (typeof s != "string")
100
+ if ("toString" in s) s = s.toString();
101
+ else throw new Error(`Invalid value type for property ${h}`);
102
+ return c(s);
103
+ }), { modifiers: P } = t || {}, j = [z(), A(P)], x = (await Promise.all(b).then(($) => Promise.all(
104
+ $.map((s) => j.reduce(async (r, h) => {
105
+ const c = await r;
106
+ if (!c) return c;
107
+ const O = await h(c);
108
+ if (!O) return c;
109
+ const { transformed: w, additionalCss: a } = O;
110
+ let d = "";
111
+ if (a)
112
+ for (const o of a)
113
+ d += await k(o, "");
114
+ return `${d}${w}`;
115
+ }, Promise.resolve(s)))
116
+ ))).join(`
117
+ `);
118
+ if (!x.trim()) return n;
119
+ const S = e ? `${e} { ${x} }` : x;
120
+ return n.add(S), n;
121
+ }, k = async (i, e, t, f = !1) => [...await l(i, e, t, f)].join(`
122
+ `);
123
+ export {
124
+ I as a,
125
+ k as p
126
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";const x=require("./dash-case-BJEkFEGQ.cjs"),U=i=>e=>{if(typeof e!="string"||!i)return;let t=e;const c=[];return Object.values(i).forEach(n=>{const{pattern:y,transform:b}=n;t=t.replace(y,P=>{const{value:j,css:C}=b(P);return C&&c.push(C),j})}),{transformed:t,additionalCss:c}},S=i=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${x.dashCase(n[1].replaceAll(".","-"))})`)},q=S(),J=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],M=(i,e,t)=>{if(J.some(n=>typeof n=="string"?n===i:n.test(i))){const n=(t==null?void 0:t.defaultUnit)||"px";return`${e}${n}`}return`${e}`},Q=["Webkit","Moz","ms","O"],_=i=>i.startsWith("-")?i:Q.some(e=>i.startsWith(e))?`-${x.dashCase(i)}`:x.dashCase(i),m=async(i,e="",t,c=!1)=>{if(!i)throw new Error("No styles provided to parseStyles function!");const n=new Set,b=Object.entries(i).map(async([$,s])=>{var w;const r=$.trim(),h=_(r),f=(o,d=";")=>`${h}:${o}${d}`;if(typeof s=="function"&&(s=s({scope:e,config:t})),s instanceof Promise&&(s=await s),t!=null&&t.templates&&t.templatePaths[r]){const{default:o}=await import(t.templatePaths[r]);if(typeof o.params[r]=="function"){const d=await o.params[r](s),[a]=await m(d,"");return a}}if(t!=null&&t.templates&&t.templates[r]){if(c)return;const d=s.split(".").reduce((a,p)=>a[p],t.templates[r]);if(d){const[a]=await m(d,"");return a}console.warn(`Template "${r}" with path of "${s}" was not found in config!`);return}if(typeof s=="object"){if(!s)return;if(s.isColor)return f(s.toString());if(r==="defaultVariants")return;if(r==="variants"){const a=Object.entries(s);for(const[p,u]of a){if(!u)return;const T=Object.entries(u);for(const[k,l]of T){if(!l)return;const V=`${e}.${p}-${k}`;(await m(l,V,t)).forEach(A=>n.add(A))}}return}if(r==="compoundVariants"){for(const a of s){const{css:p,...u}=a,T=Object.entries(u).reduce((l,[V,N])=>`${l}.${V}-${N}`,e);(await m(p,T,t)).forEach(l=>n.add(l))}return}if(r.startsWith("@")){const a=((w=t==null?void 0:t.mediaQueries)==null?void 0:w[r])||r,p=await W(s,e,t),u=`${a} { ${p} }`;n.add(u);return}const o=$.includes("&")?r.replace("&",e):r.startsWith(":")?`${e}${r}`:`${e} ${r}`;(await m(s,o,t)).forEach(a=>n.add(a));return}if(typeof s=="number"){const o=M(h,s,t);return f(o)}if(typeof s!="string")if("toString"in s)s=s.toString();else throw new Error(`Invalid value type for property ${h}`);return f(s)}),{modifiers:P}=t||{},j=[S(),U(P)],E=(await Promise.all(b).then($=>Promise.all($.map(s=>j.reduce(async(r,h)=>{const f=await r;if(!f)return f;const O=await h(f);if(!O)return f;const{transformed:w,additionalCss:o}=O;let d="";if(o)for(const a of o)d+=await W(a,"");return`${d}${w}`},Promise.resolve(s)))))).join(`
2
+ `);if(!E.trim())return n;const z=e?`${e} { ${E} }`:E;return n.add(z),n},W=async(i,e,t,c=!1)=>[...await m(i,e,t,c)].join(`
3
+ `);exports.parseAndJoinStyles=W;exports.parseVariableTokens=q;
@@ -4,9 +4,10 @@ import { CachedConfig, SaltyConfig } from '../types/config-types';
4
4
  * @param styles CSS as JS object
5
5
  * @param currentScope Scope of the styles, for class names full path with dot separator is required
6
6
  * @param config Salty config object to allow use of templates and media queries etc.
7
+ * @param omitTemplates If true, static templates will be ignored
7
8
  * @returns CSS strings that can be injected to the .css file or used inside of styles tag
8
9
  * - First item is the main class with all the styles
9
10
  * - Rest of the items are child selectors or media queries etc.
10
11
  */
11
- export declare const parseStyles: <T extends object>(styles?: T, currentScope?: string, config?: (SaltyConfig & CachedConfig) | undefined) => Promise<Set<string>>;
12
- export declare const parseAndJoinStyles: <T extends object>(styles: T, currentClass: string, config?: (SaltyConfig & CachedConfig) | undefined) => Promise<string>;
12
+ export declare const parseStyles: <T extends object>(styles?: T, currentScope?: string, config?: (SaltyConfig & CachedConfig) | undefined, omitTemplates?: boolean) => Promise<Set<string>>;
13
+ export declare const parseAndJoinStyles: <T extends object>(styles: T, currentClass: string, config?: (SaltyConfig & CachedConfig) | undefined, omitTemplates?: boolean) => Promise<string>;
@@ -3,6 +3,6 @@ export interface ValueParserReturnValue {
3
3
  additionalCss?: object[];
4
4
  }
5
5
  type StyleValueModifierFunctionReturnValue = undefined | ValueParserReturnValue;
6
- export type SyncronousStyleValueModifierFunction = (current: string) => StyleValueModifierFunctionReturnValue;
6
+ export type SyncronousStyleValueModifierFunction = (current: unknown) => StyleValueModifierFunctionReturnValue;
7
7
  export type StyleValueModifierFunction = (current: string) => Promise<StyleValueModifierFunctionReturnValue> | StyleValueModifierFunctionReturnValue;
8
8
  export {};
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-BEJWepok.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-BwBIR0y8.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-BsRtXRDr.js";
2
+ import { i as e } from "../index-ED4VBH54.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;