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