@salty-css/core 0.1.0-alpha.3 → 0.1.0-alpha.30
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/README.md +209 -0
- package/astro-component-5hrNTCJ5.js +4 -0
- package/astro-component-Dj3enX6K.cjs +4 -0
- package/bin/commands/build.d.ts +2 -0
- package/bin/commands/generate.d.ts +2 -0
- package/bin/commands/init.d.ts +2 -0
- package/bin/commands/update.d.ts +2 -0
- package/bin/commands/version.d.ts +2 -0
- package/bin/confirm-install.d.ts +34 -0
- package/bin/context.d.ts +22 -0
- package/bin/detection/css-file.d.ts +5 -0
- package/bin/frameworks/astro.d.ts +4 -0
- package/bin/frameworks/index.d.ts +13 -0
- package/bin/frameworks/react.d.ts +2 -0
- package/bin/frameworks/types.d.ts +27 -0
- package/bin/integrations/astro.d.ts +11 -0
- package/bin/integrations/eslint.d.ts +6 -0
- package/bin/integrations/index.d.ts +21 -0
- package/bin/integrations/next.d.ts +9 -0
- package/bin/integrations/types.d.ts +29 -0
- package/bin/integrations/vite.d.ts +8 -0
- package/bin/main.cjs +653 -336
- package/bin/main.d.ts +8 -0
- package/bin/main.js +653 -336
- package/bin/package-json.d.ts +21 -0
- package/bin/saltyrc.d.ts +31 -0
- package/bin/templates.d.ts +14 -0
- package/{class-name-generator-YeSQe_Ik.js → class-name-generator-B0WkxoIg.js} +17 -2
- package/{class-name-generator-B2Pb2obX.cjs → class-name-generator-BEOEMEKX.cjs} +17 -2
- package/compiler/resolve-import.d.ts +17 -0
- package/compiler/salty-compiler.cjs +131 -30
- package/compiler/salty-compiler.d.ts +8 -1
- package/compiler/salty-compiler.js +133 -31
- package/config/index.cjs +4 -0
- package/config/index.js +5 -1
- package/css/dynamic-styles.cjs +15 -0
- package/css/dynamic-styles.d.ts +10 -0
- package/css/dynamic-styles.js +15 -0
- package/css/index.cjs +3 -0
- package/css/index.d.ts +1 -0
- package/css/index.js +3 -0
- package/css/keyframes.cjs +1 -1
- package/css/keyframes.js +1 -1
- package/factories/define-font.d.ts +28 -0
- package/factories/define-import.d.ts +14 -0
- package/factories/index.cjs +141 -0
- package/factories/index.d.ts +2 -0
- package/factories/index.js +141 -0
- package/generators/index.cjs +1 -1
- package/generators/index.js +2 -2
- package/instances/classname-instance.cjs +1 -1
- package/instances/classname-instance.js +1 -1
- package/package.json +5 -1
- package/parse-styles-BBJ3PWyV.js +514 -0
- package/parse-styles-lOMGe_c5.cjs +513 -0
- package/parsers/index.cjs +93 -3
- package/parsers/index.d.ts +1 -0
- package/parsers/index.js +97 -7
- package/parsers/parse-templates.d.ts +10 -0
- package/parsers/parser-regexes.d.ts +3 -0
- package/parsers/resolve-template-variants.d.ts +21 -0
- package/parsers/strict.d.ts +2 -0
- package/runtime/index.cjs +1 -1
- package/runtime/index.js +1 -1
- package/{salty.config-cqavVm2t.cjs → salty.config-DogY_sSQ.cjs} +1 -1
- package/salty.config-GV37Q-D2.js +4 -0
- package/styled-file-BzmB9_Ez.cjs +12 -0
- package/{react-styled-file-U02jek-B.cjs → styled-file-CPd_rTW2.cjs} +2 -2
- package/{react-styled-file-B99mwk0w.js → styled-file-Cda3EeR6.js} +2 -2
- package/styled-file-DLcgYmGN.js +12 -0
- package/types/config-types.d.ts +42 -2
- package/types/font-types.d.ts +53 -0
- package/{react-vanilla-file-D9px70iK.js → vanilla-file-1kOqbCIM.js} +2 -2
- package/{react-vanilla-file-Bj6XC8GS.cjs → vanilla-file-r0fp2q_m.cjs} +2 -2
- package/parse-styles-BTIoYnBr.js +0 -232
- package/parse-styles-CA3TP5n1.cjs +0 -231
- package/salty.config-DjosWdPw.js +0 -4
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
import { d as dashCase } from "./dash-case-DblXvymC.js";
|
|
2
|
+
import { d as defineViewportClamp } from "./viewport-clamp-K553uXu3.js";
|
|
3
|
+
const parseValueModifiers = (modifiers) => (value) => {
|
|
4
|
+
if (typeof value !== "string") return void 0;
|
|
5
|
+
if (!modifiers) return void 0;
|
|
6
|
+
let transformed = value;
|
|
7
|
+
const additionalCss = [];
|
|
8
|
+
Object.values(modifiers).forEach((modifier) => {
|
|
9
|
+
const { pattern, transform } = modifier;
|
|
10
|
+
transformed = transformed.replace(pattern, (match) => {
|
|
11
|
+
const { value: _value, css } = transform(match);
|
|
12
|
+
if (css) additionalCss.push(css);
|
|
13
|
+
return _value;
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
return { transformed, additionalCss };
|
|
17
|
+
};
|
|
18
|
+
const parseValueTokens = (tokenNames) => (value) => {
|
|
19
|
+
if (typeof value !== "string") return void 0;
|
|
20
|
+
const hasToken = /\{[^{}]+\}/g.test(value);
|
|
21
|
+
if (!hasToken) return void 0;
|
|
22
|
+
const transformed = value.replace(/\{([^{}]+)\}/g, (...args) => {
|
|
23
|
+
const variable = dashCase(args[1].trim().replaceAll(".", "-"));
|
|
24
|
+
if (tokenNames && !tokenNames.includes(variable)) console.warn(`Token ${variable} might not exist`);
|
|
25
|
+
if (variable.startsWith("-")) return `-${variable}`;
|
|
26
|
+
return `var(--${variable})`;
|
|
27
|
+
});
|
|
28
|
+
return { transformed };
|
|
29
|
+
};
|
|
30
|
+
const parseVariableTokens = parseValueTokens();
|
|
31
|
+
const pxProperties = [
|
|
32
|
+
"top",
|
|
33
|
+
"right",
|
|
34
|
+
"bottom",
|
|
35
|
+
"left",
|
|
36
|
+
"min-width",
|
|
37
|
+
/.*width.*/,
|
|
38
|
+
/^[^line]*height.*/,
|
|
39
|
+
// Exclude line-height
|
|
40
|
+
/padding.*/,
|
|
41
|
+
/margin.*/,
|
|
42
|
+
/border.*/,
|
|
43
|
+
/inset.*/,
|
|
44
|
+
/.*radius.*/,
|
|
45
|
+
/.*spacing.*/,
|
|
46
|
+
/.*gap.*/,
|
|
47
|
+
/.*indent.*/,
|
|
48
|
+
/.*offset.*/,
|
|
49
|
+
/.*size.*/,
|
|
50
|
+
/.*thickness.*/,
|
|
51
|
+
/.*font-size.*/
|
|
52
|
+
];
|
|
53
|
+
const addUnit = (key, value, config) => {
|
|
54
|
+
const isPxProperty = pxProperties.some((pxProperty) => {
|
|
55
|
+
return typeof pxProperty === "string" ? pxProperty === key : pxProperty.test(key);
|
|
56
|
+
});
|
|
57
|
+
if (isPxProperty) {
|
|
58
|
+
const unit = (config == null ? void 0 : config.defaultUnit) || "px";
|
|
59
|
+
const isClamp = unit.startsWith("viewport-clamp:");
|
|
60
|
+
if (isClamp) {
|
|
61
|
+
try {
|
|
62
|
+
const screenSize = unit.split(":")[1];
|
|
63
|
+
const viewportClamp = defineViewportClamp({
|
|
64
|
+
screenSize: parseInt(screenSize)
|
|
65
|
+
});
|
|
66
|
+
return viewportClamp(Number(value));
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error(error);
|
|
69
|
+
throw new Error(`Invalid viewport-clamp value: ${unit}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return `${value}${unit}`;
|
|
73
|
+
}
|
|
74
|
+
return `${value}`;
|
|
75
|
+
};
|
|
76
|
+
const vendorPrefixes = ["Webkit", "Moz", "ms", "O"];
|
|
77
|
+
const isVendorPrefixed = (key) => {
|
|
78
|
+
return vendorPrefixes.some((prefix) => {
|
|
79
|
+
if (!key.startsWith(prefix)) return false;
|
|
80
|
+
const next = key.charAt(prefix.length);
|
|
81
|
+
return next >= "A" && next <= "Z";
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
const propertyNameCheck = (key) => {
|
|
85
|
+
if (key.startsWith("-")) return key;
|
|
86
|
+
if (isVendorPrefixed(key)) return `-${dashCase(key)}`;
|
|
87
|
+
return dashCase(key);
|
|
88
|
+
};
|
|
89
|
+
const reportParserIssue = (strict, message) => {
|
|
90
|
+
if (strict === true) throw new Error(`[salty-css] ${message}`);
|
|
91
|
+
if (strict === "warn") console.warn(`[salty-css] ${message}`);
|
|
92
|
+
};
|
|
93
|
+
const pseudoTypoRegex = /^&(hover|focus(-(visible|within))?|active|visited|checked|disabled|enabled|empty|target|first-child|last-child|first-of-type|last-of-type|placeholder|placeholder-shown|root)\b/;
|
|
94
|
+
const templateLiteralLeftoverRegex = /\$\{[^}]+\}/;
|
|
95
|
+
const bareAtRuleRegex = /^@(media|supports|container|layer)\s*$/;
|
|
96
|
+
const isRichTemplateNode = (node) => {
|
|
97
|
+
if (!node || typeof node !== "object") return false;
|
|
98
|
+
if (Array.isArray(node)) return false;
|
|
99
|
+
const keys = Object.keys(node);
|
|
100
|
+
return keys.includes("base") || keys.includes("variants");
|
|
101
|
+
};
|
|
102
|
+
const parseTemplateCallSite = (value) => {
|
|
103
|
+
if (typeof value === "string") {
|
|
104
|
+
const [rawPath, rawQuery] = value.split("@", 2);
|
|
105
|
+
const path = rawPath.split(".").filter(Boolean);
|
|
106
|
+
if (!path.length) return void 0;
|
|
107
|
+
const variants = {};
|
|
108
|
+
if (rawQuery) {
|
|
109
|
+
for (const segment of rawQuery.split("&")) {
|
|
110
|
+
if (!segment) continue;
|
|
111
|
+
const eq = segment.indexOf("=");
|
|
112
|
+
if (eq === -1) {
|
|
113
|
+
variants[segment.trim()] = true;
|
|
114
|
+
} else {
|
|
115
|
+
const axis = segment.slice(0, eq).trim();
|
|
116
|
+
const raw = segment.slice(eq + 1).trim();
|
|
117
|
+
if (!axis) continue;
|
|
118
|
+
if (raw === "true") variants[axis] = true;
|
|
119
|
+
else if (raw === "false") variants[axis] = false;
|
|
120
|
+
else variants[axis] = raw;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return { path, variants };
|
|
125
|
+
}
|
|
126
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
127
|
+
const obj = value;
|
|
128
|
+
const name = obj["name"];
|
|
129
|
+
if (typeof name !== "string") return void 0;
|
|
130
|
+
const path = name.split(".").filter(Boolean);
|
|
131
|
+
if (!path.length) return void 0;
|
|
132
|
+
const variants = {};
|
|
133
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
134
|
+
if (k === "name") continue;
|
|
135
|
+
if (typeof v === "string" || typeof v === "boolean") variants[k] = v;
|
|
136
|
+
}
|
|
137
|
+
return { path, variants };
|
|
138
|
+
}
|
|
139
|
+
return void 0;
|
|
140
|
+
};
|
|
141
|
+
const normalizeAxisValue = (v) => {
|
|
142
|
+
if (v === void 0) return void 0;
|
|
143
|
+
return typeof v === "boolean" ? String(v) : v;
|
|
144
|
+
};
|
|
145
|
+
const buildPathStack = (root, path) => {
|
|
146
|
+
const stack = [{ node: root, isRich: isRichTemplateNode(root) }];
|
|
147
|
+
let cursor = root;
|
|
148
|
+
for (const segment of path) {
|
|
149
|
+
if (cursor == null || typeof cursor !== "object") return void 0;
|
|
150
|
+
const next = cursor[segment];
|
|
151
|
+
if (next === void 0) return void 0;
|
|
152
|
+
stack.push({ node: next, isRich: isRichTemplateNode(next) });
|
|
153
|
+
cursor = next;
|
|
154
|
+
}
|
|
155
|
+
return stack;
|
|
156
|
+
};
|
|
157
|
+
const pathHasRichNode = (root, path) => {
|
|
158
|
+
const stack = buildPathStack(root, path);
|
|
159
|
+
if (!stack) return false;
|
|
160
|
+
return stack.some((entry) => entry.isRich);
|
|
161
|
+
};
|
|
162
|
+
const matchesAll = (entry, effective) => {
|
|
163
|
+
for (const [axis, raw] of Object.entries(entry)) {
|
|
164
|
+
if (axis === "css") continue;
|
|
165
|
+
if (effective[axis] !== normalizeAxisValue(raw)) return false;
|
|
166
|
+
}
|
|
167
|
+
return true;
|
|
168
|
+
};
|
|
169
|
+
const matchesAny = (entry, effective) => {
|
|
170
|
+
let any = false;
|
|
171
|
+
for (const [axis, raw] of Object.entries(entry)) {
|
|
172
|
+
if (axis === "css") continue;
|
|
173
|
+
any = true;
|
|
174
|
+
if (effective[axis] === normalizeAxisValue(raw)) return true;
|
|
175
|
+
}
|
|
176
|
+
return !any;
|
|
177
|
+
};
|
|
178
|
+
const resolveRichTemplate = (root, path, callSiteVariants, templateName) => {
|
|
179
|
+
var _a, _b, _c, _d;
|
|
180
|
+
const stack = buildPathStack(root, path);
|
|
181
|
+
if (!stack) return void 0;
|
|
182
|
+
const rich = stack.map((entry) => {
|
|
183
|
+
if (entry.isRich) return entry.node;
|
|
184
|
+
if (entry.node && typeof entry.node === "object" && !Array.isArray(entry.node)) {
|
|
185
|
+
const onlyChildKeys = Object.keys(entry.node).every((k) => entry.node[k] && typeof entry.node[k] === "object" && !isRichTemplateNode(entry.node[k]));
|
|
186
|
+
return onlyChildKeys ? {} : { base: entry.node };
|
|
187
|
+
}
|
|
188
|
+
return {};
|
|
189
|
+
});
|
|
190
|
+
const declaredAxes = /* @__PURE__ */ new Set();
|
|
191
|
+
for (const r of rich) {
|
|
192
|
+
if (r.variants) for (const k of Object.keys(r.variants)) declaredAxes.add(k);
|
|
193
|
+
}
|
|
194
|
+
for (const r of rich) {
|
|
195
|
+
if (r.defaultVariants) for (const k of Object.keys(r.defaultVariants)) declaredAxes.add(k);
|
|
196
|
+
}
|
|
197
|
+
const effective = {};
|
|
198
|
+
for (const axis of declaredAxes) {
|
|
199
|
+
if (axis in callSiteVariants) {
|
|
200
|
+
effective[axis] = normalizeAxisValue(callSiteVariants[axis]);
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
for (let i = rich.length - 1; i >= 0; i--) {
|
|
204
|
+
const d = (_a = rich[i].defaultVariants) == null ? void 0 : _a[axis];
|
|
205
|
+
if (d !== void 0) {
|
|
206
|
+
effective[axis] = normalizeAxisValue(d);
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
for (const [axis, raw] of Object.entries(callSiteVariants)) {
|
|
212
|
+
if (!declaredAxes.has(axis)) {
|
|
213
|
+
console.warn(`Template "${templateName}" path "${path.join(".")}" has no variant axis "${axis}"; ignored.`);
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
const wanted = normalizeAxisValue(raw);
|
|
217
|
+
let found = false;
|
|
218
|
+
for (const r of rich) {
|
|
219
|
+
if (((_b = r.variants) == null ? void 0 : _b[axis]) && wanted !== void 0 && wanted in r.variants[axis]) {
|
|
220
|
+
found = true;
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (!found && wanted !== void 0) {
|
|
225
|
+
const anyBundle = rich.some((r) => r.variants && axis in r.variants);
|
|
226
|
+
if (anyBundle) {
|
|
227
|
+
console.warn(`Template "${templateName}" axis "${axis}" has no value "${wanted}" on path "${path.join(".")}"; ignored.`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const acc = {};
|
|
232
|
+
for (const r of rich) {
|
|
233
|
+
if (r.base) Object.assign(acc, r.base);
|
|
234
|
+
}
|
|
235
|
+
for (const axis of Object.keys(effective)) {
|
|
236
|
+
const value = effective[axis];
|
|
237
|
+
if (value === void 0) continue;
|
|
238
|
+
for (let i = rich.length - 1; i >= 0; i--) {
|
|
239
|
+
const bundle = (_d = (_c = rich[i].variants) == null ? void 0 : _c[axis]) == null ? void 0 : _d[value];
|
|
240
|
+
if (bundle) {
|
|
241
|
+
Object.assign(acc, bundle);
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
for (const r of rich) {
|
|
247
|
+
if (r.compoundVariants) {
|
|
248
|
+
for (const entry of r.compoundVariants) {
|
|
249
|
+
if (matchesAll(entry, effective) && entry.css) Object.assign(acc, entry.css);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (r.anyOfVariants) {
|
|
253
|
+
for (const entry of r.anyOfVariants) {
|
|
254
|
+
if (matchesAny(entry, effective) && entry.css) Object.assign(acc, entry.css);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return acc;
|
|
259
|
+
};
|
|
260
|
+
const parseStyles = async (styles, currentScope = "", config, omitTemplates = false) => {
|
|
261
|
+
if (!styles) throw new Error("No styles provided to parseStyles function!");
|
|
262
|
+
const cssStyles = /* @__PURE__ */ new Set();
|
|
263
|
+
const entries = Object.entries(styles);
|
|
264
|
+
const strict = config == null ? void 0 : config.strict;
|
|
265
|
+
const processStyleEntry = async ([key, value]) => {
|
|
266
|
+
var _a, _b;
|
|
267
|
+
const _key = key.trim().replace(/^\?+/g, "");
|
|
268
|
+
const propertyName = propertyNameCheck(_key);
|
|
269
|
+
const toString = (val, eol = ";") => `${propertyName}:${val}${eol}`;
|
|
270
|
+
const context = { scope: currentScope, config };
|
|
271
|
+
if (typeof value === "function") {
|
|
272
|
+
try {
|
|
273
|
+
return await processStyleEntry([key, value(context)]);
|
|
274
|
+
} catch (error) {
|
|
275
|
+
reportParserIssue(strict, `Function value for "${_key}" threw: ${(error == null ? void 0 : error.message) ?? error}`);
|
|
276
|
+
return void 0;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
if (value instanceof Promise) return processStyleEntry([key, await value]);
|
|
280
|
+
if ((config == null ? void 0 : config.templates) && ((_a = config.templatePaths) == null ? void 0 : _a[_key])) {
|
|
281
|
+
try {
|
|
282
|
+
const [name, path] = config.templatePaths[_key].split(";;");
|
|
283
|
+
const functions = await import(
|
|
284
|
+
/* webpackIgnore: true */
|
|
285
|
+
/* @vite-ignore */
|
|
286
|
+
path
|
|
287
|
+
);
|
|
288
|
+
const isSaltyConfig = path.includes("salty.config");
|
|
289
|
+
const values = isSaltyConfig ? functions[name].templates : functions[name];
|
|
290
|
+
const template = isSaltyConfig ? values[_key] : values.params[_key];
|
|
291
|
+
if (values && typeof template === "function") {
|
|
292
|
+
const templateStyles = await template(value);
|
|
293
|
+
const [result] = await parseStyles(templateStyles, "");
|
|
294
|
+
return result;
|
|
295
|
+
}
|
|
296
|
+
} catch (error) {
|
|
297
|
+
console.error(`Error loading template "${_key}" from path "${config.templatePaths[_key]}"`, error);
|
|
298
|
+
return void 0;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if ((config == null ? void 0 : config.templates) && config.templates[_key]) {
|
|
302
|
+
if (omitTemplates) return void 0;
|
|
303
|
+
const root = config.templates[_key];
|
|
304
|
+
const callSite = parseTemplateCallSite(value);
|
|
305
|
+
if (callSite) {
|
|
306
|
+
const { path, variants } = callSite;
|
|
307
|
+
const hasCallSiteVariants = Object.keys(variants).length > 0;
|
|
308
|
+
if (hasCallSiteVariants || pathHasRichNode(root, path)) {
|
|
309
|
+
const resolved2 = resolveRichTemplate(root, path, variants, _key);
|
|
310
|
+
if (resolved2) {
|
|
311
|
+
const [result] = await parseStyles(resolved2, "");
|
|
312
|
+
return result;
|
|
313
|
+
}
|
|
314
|
+
console.warn(`Template "${_key}" with path of "${path.join(".")}" was not found in config!`);
|
|
315
|
+
return void 0;
|
|
316
|
+
}
|
|
317
|
+
const templateStyles = path.reduce((acc, key2) => acc == null ? void 0 : acc[key2], root);
|
|
318
|
+
if (templateStyles) {
|
|
319
|
+
const [result] = await parseStyles(templateStyles, "");
|
|
320
|
+
return result;
|
|
321
|
+
}
|
|
322
|
+
console.warn(`Template "${_key}" with path of "${path.join(".")}" was not found in config!`);
|
|
323
|
+
return void 0;
|
|
324
|
+
}
|
|
325
|
+
console.warn(`Template "${_key}" received an unsupported call-site value.`);
|
|
326
|
+
return void 0;
|
|
327
|
+
}
|
|
328
|
+
const isVariantArrayKey = _key === "compoundVariants" || _key === "anyOfVariants";
|
|
329
|
+
if (!isVariantArrayKey && Array.isArray(value)) {
|
|
330
|
+
if (value.length === 0) return void 0;
|
|
331
|
+
return processStyleEntry([key, value.join(", ")]);
|
|
332
|
+
}
|
|
333
|
+
if (typeof value === "object") {
|
|
334
|
+
if (!value) return void 0;
|
|
335
|
+
if (value.isColor) return toString(value.toString());
|
|
336
|
+
if (value.isDefineFont) return toString(value.toString());
|
|
337
|
+
if (_key === "defaultVariants") return void 0;
|
|
338
|
+
if (_key === "variants") {
|
|
339
|
+
const variantEntries = Object.entries(value);
|
|
340
|
+
for (const [prop, conditions] of variantEntries) {
|
|
341
|
+
if (!conditions) continue;
|
|
342
|
+
const entries2 = Object.entries(conditions);
|
|
343
|
+
for (const [val, styles2] of entries2) {
|
|
344
|
+
if (!styles2) continue;
|
|
345
|
+
const scope2 = `${currentScope}.${prop}-${val}`;
|
|
346
|
+
const results2 = await parseStyles(styles2, scope2, config);
|
|
347
|
+
results2.forEach((res) => cssStyles.add(res));
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return void 0;
|
|
351
|
+
}
|
|
352
|
+
if (_key === "compoundVariants") {
|
|
353
|
+
for (const variant of value) {
|
|
354
|
+
const { css: css2, ...rest } = variant;
|
|
355
|
+
const scope2 = Object.entries(rest).reduce((acc, [prop, val]) => {
|
|
356
|
+
return `${acc}.${prop}-${val}`;
|
|
357
|
+
}, currentScope);
|
|
358
|
+
const results2 = await parseStyles(css2, scope2, config);
|
|
359
|
+
results2.forEach((res) => cssStyles.add(res));
|
|
360
|
+
}
|
|
361
|
+
return void 0;
|
|
362
|
+
}
|
|
363
|
+
if (_key === "anyOfVariants") {
|
|
364
|
+
for (const variant of value) {
|
|
365
|
+
const { css: css2, ...rest } = variant;
|
|
366
|
+
const scopes = Object.entries(rest).map(([prop, val]) => {
|
|
367
|
+
return `.${prop}-${val}`;
|
|
368
|
+
});
|
|
369
|
+
const scope2 = `${currentScope}:where(${scopes.join(", ")})`;
|
|
370
|
+
const results2 = await parseStyles(css2, scope2, config);
|
|
371
|
+
results2.forEach((res) => cssStyles.add(res));
|
|
372
|
+
}
|
|
373
|
+
return void 0;
|
|
374
|
+
}
|
|
375
|
+
if (_key.startsWith("@")) {
|
|
376
|
+
if (bareAtRuleRegex.test(_key)) reportParserIssue(strict, `At-rule "${_key}" is missing its condition (e.g. "@media (min-width: 600px)").`);
|
|
377
|
+
const mediaQuery = ((_b = config == null ? void 0 : config.mediaQueries) == null ? void 0 : _b[_key]) || _key;
|
|
378
|
+
const results2 = await parseAndJoinStyles(value, currentScope, config);
|
|
379
|
+
const query = `${mediaQuery} { ${results2} }`;
|
|
380
|
+
cssStyles.add(query);
|
|
381
|
+
return void 0;
|
|
382
|
+
}
|
|
383
|
+
if (Object.keys(value).length === 0) return void 0;
|
|
384
|
+
if (pseudoTypoRegex.test(_key)) {
|
|
385
|
+
reportParserIssue(strict, `Selector "${_key}" looks like a missing-colon typo (did you mean "&:${_key.slice(1)}"?).`);
|
|
386
|
+
}
|
|
387
|
+
const scope = combineSelectors(currentScope, _key);
|
|
388
|
+
const results = await parseStyles(value, scope, config);
|
|
389
|
+
results.forEach((result) => cssStyles.add(result));
|
|
390
|
+
return void 0;
|
|
391
|
+
}
|
|
392
|
+
if (_key.startsWith("$")) {
|
|
393
|
+
reportParserIssue(strict, `Property key "${_key}" looks like a SCSS variable — Salty does not support those.`);
|
|
394
|
+
return void 0;
|
|
395
|
+
}
|
|
396
|
+
if (_key.includes(":")) {
|
|
397
|
+
reportParserIssue(strict, `Property key "${_key}" contains a colon — did you accidentally paste a whole declaration as a key?`);
|
|
398
|
+
return void 0;
|
|
399
|
+
}
|
|
400
|
+
if (value === void 0 || value === null) {
|
|
401
|
+
reportParserIssue(strict, `Property "${_key}" has a ${value === void 0 ? "undefined" : "null"} value — skipping.`);
|
|
402
|
+
return void 0;
|
|
403
|
+
}
|
|
404
|
+
if (typeof value === "boolean") {
|
|
405
|
+
reportParserIssue(strict, `Property "${_key}" has a boolean value (${value}) — skipping.`);
|
|
406
|
+
return void 0;
|
|
407
|
+
}
|
|
408
|
+
if (value === "") return void 0;
|
|
409
|
+
if (typeof value === "number") {
|
|
410
|
+
if (!Number.isFinite(value)) {
|
|
411
|
+
reportParserIssue(strict, `Property "${_key}" has a non-finite numeric value (${value}) — skipping.`);
|
|
412
|
+
return void 0;
|
|
413
|
+
}
|
|
414
|
+
const withUnit = addUnit(propertyName, value, config);
|
|
415
|
+
return toString(withUnit);
|
|
416
|
+
}
|
|
417
|
+
if (typeof value !== "string") {
|
|
418
|
+
if (value && typeof value === "object" && "toString" in value) value = value.toString();
|
|
419
|
+
else {
|
|
420
|
+
reportParserIssue(strict, `Property "${_key}" has an unsupported value type (${typeof value}) — skipping.`);
|
|
421
|
+
return void 0;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
if (typeof value === "string" && templateLiteralLeftoverRegex.test(value)) {
|
|
425
|
+
reportParserIssue(strict, `Property "${_key}" value "${value}" contains an unresolved \`\${...}\` — did you forget to interpolate?`);
|
|
426
|
+
}
|
|
427
|
+
return toString(value);
|
|
428
|
+
};
|
|
429
|
+
const promises = entries.map(processStyleEntry);
|
|
430
|
+
const { modifiers } = config || {};
|
|
431
|
+
const afterFunctions = [parseValueTokens(), parseValueModifiers(modifiers)];
|
|
432
|
+
const resolved = await Promise.all(promises).then((styles2) => {
|
|
433
|
+
return Promise.all(
|
|
434
|
+
styles2.map((str) => {
|
|
435
|
+
return afterFunctions.reduce(async (acc, fn) => {
|
|
436
|
+
const current = await acc;
|
|
437
|
+
if (!current) return current;
|
|
438
|
+
const result = await fn(current);
|
|
439
|
+
if (!result) return current;
|
|
440
|
+
const { transformed, additionalCss } = result;
|
|
441
|
+
let before = "";
|
|
442
|
+
if (additionalCss) {
|
|
443
|
+
for (const css2 of additionalCss) {
|
|
444
|
+
before += await parseAndJoinStyles(css2, "");
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
return `${before}${transformed}`;
|
|
448
|
+
}, Promise.resolve(str));
|
|
449
|
+
})
|
|
450
|
+
);
|
|
451
|
+
});
|
|
452
|
+
const mapped = resolved.filter((value) => value !== void 0).join("\n ");
|
|
453
|
+
if (!mapped.trim()) return Array.from(cssStyles);
|
|
454
|
+
const css = currentScope ? `${currentScope} {
|
|
455
|
+
${mapped}
|
|
456
|
+
}` : mapped;
|
|
457
|
+
const alreadyExists = cssStyles.has(css);
|
|
458
|
+
if (alreadyExists) return Array.from(cssStyles);
|
|
459
|
+
return [css, ...cssStyles];
|
|
460
|
+
};
|
|
461
|
+
const parseAndJoinStyles = async (styles, currentClass, config, omitTemplates = false) => {
|
|
462
|
+
const css = await parseStyles(styles, currentClass, config, omitTemplates);
|
|
463
|
+
return css.join("\n");
|
|
464
|
+
};
|
|
465
|
+
const splitTopLevelCommas = (selector) => {
|
|
466
|
+
const parts = [];
|
|
467
|
+
let depth = 0;
|
|
468
|
+
let buf = "";
|
|
469
|
+
for (const ch of selector) {
|
|
470
|
+
if (ch === "(" || ch === "[") depth++;
|
|
471
|
+
else if (ch === ")" || ch === "]") depth = Math.max(0, depth - 1);
|
|
472
|
+
if (ch === "," && depth === 0) {
|
|
473
|
+
const trimmed2 = buf.trim();
|
|
474
|
+
if (trimmed2) parts.push(trimmed2);
|
|
475
|
+
buf = "";
|
|
476
|
+
} else {
|
|
477
|
+
buf += ch;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
const trimmed = buf.trim();
|
|
481
|
+
if (trimmed) parts.push(trimmed);
|
|
482
|
+
return parts;
|
|
483
|
+
};
|
|
484
|
+
const joinSelector = (parent, child) => {
|
|
485
|
+
if (child.includes("&")) return child.replaceAll("&", parent);
|
|
486
|
+
if (child.startsWith(":")) return `${parent}${child}`;
|
|
487
|
+
return `${parent} ${child}`;
|
|
488
|
+
};
|
|
489
|
+
const combineSelectors = (currentScope, key) => {
|
|
490
|
+
if (!currentScope) return key;
|
|
491
|
+
const parents = splitTopLevelCommas(currentScope);
|
|
492
|
+
const children = splitTopLevelCommas(key);
|
|
493
|
+
if (!children.length) return currentScope;
|
|
494
|
+
if (parents.length <= 1 && children.length <= 1) {
|
|
495
|
+
return joinSelector(parents[0] ?? currentScope, children[0]);
|
|
496
|
+
}
|
|
497
|
+
const combos = [];
|
|
498
|
+
for (const p of parents) {
|
|
499
|
+
for (const c of children) {
|
|
500
|
+
combos.push(joinSelector(p, c));
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
return combos.join(", ");
|
|
504
|
+
};
|
|
505
|
+
export {
|
|
506
|
+
parseStyles as a,
|
|
507
|
+
parseTemplateCallSite as b,
|
|
508
|
+
parseVariableTokens as c,
|
|
509
|
+
parseValueModifiers as d,
|
|
510
|
+
parseValueTokens as e,
|
|
511
|
+
isRichTemplateNode as i,
|
|
512
|
+
parseAndJoinStyles as p,
|
|
513
|
+
reportParserIssue as r
|
|
514
|
+
};
|