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