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