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