@salty-css/core 0.1.0-refactor-add-additional-paths-to-config-cache.1 → 0.1.0
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 +355 -374
- package/bin/main.cjs +57 -58
- package/bin/main.js +1 -2
- package/{class-name-generator-CMWY5KTJ.js → class-name-generator-CUEoPowv.js} +18 -4
- package/{class-name-generator-DB5aQwC_.cjs → class-name-generator-MtPkBfM_.cjs} +19 -5
- package/compiler/helpers.cjs +10 -2
- package/compiler/helpers.d.ts +3 -2
- package/compiler/helpers.js +11 -3
- package/compiler/resolve-import.d.ts +17 -0
- package/compiler/salty-compiler.cjs +144 -33
- package/compiler/salty-compiler.d.ts +2 -5
- package/compiler/salty-compiler.js +149 -38
- package/config/index.cjs +4 -0
- package/config/index.js +5 -1
- package/css/index.cjs +0 -4
- package/css/index.d.ts +0 -1
- package/css/index.js +0 -4
- package/css/keyframes.cjs +2 -2
- package/css/keyframes.js +2 -2
- package/factories/define-font.d.ts +28 -0
- package/factories/define-import.d.ts +14 -0
- package/factories/index.cjs +140 -0
- package/factories/index.d.ts +2 -0
- package/factories/index.js +140 -0
- package/generators/index.cjs +3 -3
- package/generators/index.js +3 -3
- package/helpers/color.d.ts +6 -0
- package/instances/classname-instance.cjs +1 -1
- package/instances/classname-instance.js +1 -1
- package/package.json +1 -13
- package/{parse-styles-C54MOrPg.cjs → parse-styles-BbI-2wdn.cjs} +196 -11
- package/{parse-styles-CLMTHo2H.js → parse-styles-BgVqQAni.js} +196 -11
- package/parsers/index.cjs +93 -5
- package/parsers/index.js +97 -9
- package/parsers/parse-templates.d.ts +10 -0
- package/parsers/parser-regexes.d.ts +1 -0
- package/parsers/resolve-template-variants.d.ts +21 -0
- package/runtime/index.cjs +16 -3
- package/runtime/index.d.ts +7 -0
- package/runtime/index.js +16 -3
- package/{to-hash-DAN2LcHK.js → to-hash-DSoCPs8D.js} +8 -0
- package/{to-hash-C05Y906F.cjs → to-hash-DT2ImSPA.cjs} +8 -0
- package/types/config-types.d.ts +33 -2
- package/types/font-types.d.ts +53 -0
- package/util/index.cjs +3 -4
- package/util/index.js +1 -2
- package/util/module-type.d.ts +1 -1
- package/cache/resolve-dynamic-config-cache.cjs +0 -64
- package/cache/resolve-dynamic-config-cache.d.ts +0 -20
- package/cache/resolve-dynamic-config-cache.js +0 -64
- package/compiler/copy-config-cache.cjs +0 -39
- package/compiler/copy-config-cache.d.ts +0 -17
- package/compiler/copy-config-cache.js +0 -39
- package/css/dynamic-styles.cjs +0 -28
- package/css/dynamic-styles.d.ts +0 -49
- package/css/dynamic-styles.js +0 -28
- package/dash-case-DIwKaYgE.cjs +0 -9
- package/dash-case-DblXvymC.js +0 -10
- package/logger-7xz0pyAz.cjs +0 -12
- package/logger-hHmCwThj.js +0 -13
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const
|
|
2
|
+
const toHash = require("./to-hash-DT2ImSPA.cjs");
|
|
3
3
|
const viewportClamp = require("./viewport-clamp-CEmzmcSj.cjs");
|
|
4
4
|
const parseValueModifiers = (modifiers) => (value) => {
|
|
5
5
|
if (typeof value !== "string") return void 0;
|
|
@@ -21,7 +21,7 @@ const parseValueTokens = (tokenNames) => (value) => {
|
|
|
21
21
|
const hasToken = /\{[^{}]+\}/g.test(value);
|
|
22
22
|
if (!hasToken) return void 0;
|
|
23
23
|
const transformed = value.replace(/\{([^{}]+)\}/g, (...args) => {
|
|
24
|
-
const variable =
|
|
24
|
+
const variable = toHash.dashCase(args[1].trim().replaceAll(".", "-"));
|
|
25
25
|
if (tokenNames && !tokenNames.includes(variable)) console.warn(`Token ${variable} might not exist`);
|
|
26
26
|
if (variable.startsWith("-")) return `-${variable}`;
|
|
27
27
|
return `var(--${variable})`;
|
|
@@ -84,8 +84,8 @@ const isVendorPrefixed = (key) => {
|
|
|
84
84
|
};
|
|
85
85
|
const propertyNameCheck = (key) => {
|
|
86
86
|
if (key.startsWith("-")) return key;
|
|
87
|
-
if (isVendorPrefixed(key)) return `-${
|
|
88
|
-
return
|
|
87
|
+
if (isVendorPrefixed(key)) return `-${toHash.dashCase(key)}`;
|
|
88
|
+
return toHash.dashCase(key);
|
|
89
89
|
};
|
|
90
90
|
const reportParserIssue = (strict, message) => {
|
|
91
91
|
if (strict === true) throw new Error(`[salty-css] ${message}`);
|
|
@@ -94,6 +94,171 @@ const reportParserIssue = (strict, message) => {
|
|
|
94
94
|
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/;
|
|
95
95
|
const templateLiteralLeftoverRegex = /\$\{[^}]+\}/;
|
|
96
96
|
const bareAtRuleRegex = /^@(media|supports|container|layer)\s*$/;
|
|
97
|
+
const keyframesAtRuleRegex = /^@(?:-(?:webkit|moz|o|ms)-)?keyframes\b/;
|
|
98
|
+
const isRichTemplateNode = (node) => {
|
|
99
|
+
if (!node || typeof node !== "object") return false;
|
|
100
|
+
if (Array.isArray(node)) return false;
|
|
101
|
+
const keys = Object.keys(node);
|
|
102
|
+
return keys.includes("base") || keys.includes("variants");
|
|
103
|
+
};
|
|
104
|
+
const parseTemplateCallSite = (value) => {
|
|
105
|
+
if (typeof value === "string") {
|
|
106
|
+
const [rawPath, rawQuery] = value.split("@", 2);
|
|
107
|
+
const path = rawPath.split(".").filter(Boolean);
|
|
108
|
+
if (!path.length) return void 0;
|
|
109
|
+
const variants = {};
|
|
110
|
+
if (rawQuery) {
|
|
111
|
+
for (const segment of rawQuery.split("&")) {
|
|
112
|
+
if (!segment) continue;
|
|
113
|
+
const eq = segment.indexOf("=");
|
|
114
|
+
if (eq === -1) {
|
|
115
|
+
variants[segment.trim()] = true;
|
|
116
|
+
} else {
|
|
117
|
+
const axis = segment.slice(0, eq).trim();
|
|
118
|
+
const raw = segment.slice(eq + 1).trim();
|
|
119
|
+
if (!axis) continue;
|
|
120
|
+
if (raw === "true") variants[axis] = true;
|
|
121
|
+
else if (raw === "false") variants[axis] = false;
|
|
122
|
+
else variants[axis] = raw;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return { path, variants };
|
|
127
|
+
}
|
|
128
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
129
|
+
const obj = value;
|
|
130
|
+
const name = obj["name"];
|
|
131
|
+
if (typeof name !== "string") return void 0;
|
|
132
|
+
const path = name.split(".").filter(Boolean);
|
|
133
|
+
if (!path.length) return void 0;
|
|
134
|
+
const variants = {};
|
|
135
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
136
|
+
if (k === "name") continue;
|
|
137
|
+
if (typeof v === "string" || typeof v === "boolean") variants[k] = v;
|
|
138
|
+
}
|
|
139
|
+
return { path, variants };
|
|
140
|
+
}
|
|
141
|
+
return void 0;
|
|
142
|
+
};
|
|
143
|
+
const normalizeAxisValue = (v) => {
|
|
144
|
+
if (v === void 0) return void 0;
|
|
145
|
+
return typeof v === "boolean" ? String(v) : v;
|
|
146
|
+
};
|
|
147
|
+
const buildPathStack = (root, path) => {
|
|
148
|
+
const stack = [{ node: root, isRich: isRichTemplateNode(root) }];
|
|
149
|
+
let cursor = root;
|
|
150
|
+
for (const segment of path) {
|
|
151
|
+
if (cursor == null || typeof cursor !== "object") return void 0;
|
|
152
|
+
const next = cursor[segment];
|
|
153
|
+
if (next === void 0) return void 0;
|
|
154
|
+
stack.push({ node: next, isRich: isRichTemplateNode(next) });
|
|
155
|
+
cursor = next;
|
|
156
|
+
}
|
|
157
|
+
return stack;
|
|
158
|
+
};
|
|
159
|
+
const pathHasRichNode = (root, path) => {
|
|
160
|
+
const stack = buildPathStack(root, path);
|
|
161
|
+
if (!stack) return false;
|
|
162
|
+
return stack.some((entry) => entry.isRich);
|
|
163
|
+
};
|
|
164
|
+
const matchesAll = (entry, effective) => {
|
|
165
|
+
for (const [axis, raw] of Object.entries(entry)) {
|
|
166
|
+
if (axis === "css") continue;
|
|
167
|
+
if (effective[axis] !== normalizeAxisValue(raw)) return false;
|
|
168
|
+
}
|
|
169
|
+
return true;
|
|
170
|
+
};
|
|
171
|
+
const matchesAny = (entry, effective) => {
|
|
172
|
+
let any = false;
|
|
173
|
+
for (const [axis, raw] of Object.entries(entry)) {
|
|
174
|
+
if (axis === "css") continue;
|
|
175
|
+
any = true;
|
|
176
|
+
if (effective[axis] === normalizeAxisValue(raw)) return true;
|
|
177
|
+
}
|
|
178
|
+
return !any;
|
|
179
|
+
};
|
|
180
|
+
const resolveRichTemplate = (root, path, callSiteVariants, templateName) => {
|
|
181
|
+
var _a, _b, _c, _d;
|
|
182
|
+
const stack = buildPathStack(root, path);
|
|
183
|
+
if (!stack) return void 0;
|
|
184
|
+
const rich = stack.map((entry) => {
|
|
185
|
+
if (entry.isRich) return entry.node;
|
|
186
|
+
if (entry.node && typeof entry.node === "object" && !Array.isArray(entry.node)) {
|
|
187
|
+
const onlyChildKeys = Object.keys(entry.node).every((k) => entry.node[k] && typeof entry.node[k] === "object" && !isRichTemplateNode(entry.node[k]));
|
|
188
|
+
return onlyChildKeys ? {} : { base: entry.node };
|
|
189
|
+
}
|
|
190
|
+
return {};
|
|
191
|
+
});
|
|
192
|
+
const declaredAxes = /* @__PURE__ */ new Set();
|
|
193
|
+
for (const r of rich) {
|
|
194
|
+
if (r.variants) for (const k of Object.keys(r.variants)) declaredAxes.add(k);
|
|
195
|
+
}
|
|
196
|
+
for (const r of rich) {
|
|
197
|
+
if (r.defaultVariants) for (const k of Object.keys(r.defaultVariants)) declaredAxes.add(k);
|
|
198
|
+
}
|
|
199
|
+
const effective = {};
|
|
200
|
+
for (const axis of declaredAxes) {
|
|
201
|
+
if (axis in callSiteVariants) {
|
|
202
|
+
effective[axis] = normalizeAxisValue(callSiteVariants[axis]);
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
for (let i = rich.length - 1; i >= 0; i--) {
|
|
206
|
+
const d = (_a = rich[i].defaultVariants) == null ? void 0 : _a[axis];
|
|
207
|
+
if (d !== void 0) {
|
|
208
|
+
effective[axis] = normalizeAxisValue(d);
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
for (const [axis, raw] of Object.entries(callSiteVariants)) {
|
|
214
|
+
if (!declaredAxes.has(axis)) {
|
|
215
|
+
console.warn(`Template "${templateName}" path "${path.join(".")}" has no variant axis "${axis}"; ignored.`);
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
const wanted = normalizeAxisValue(raw);
|
|
219
|
+
let found = false;
|
|
220
|
+
for (const r of rich) {
|
|
221
|
+
if (((_b = r.variants) == null ? void 0 : _b[axis]) && wanted !== void 0 && wanted in r.variants[axis]) {
|
|
222
|
+
found = true;
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (!found && wanted !== void 0) {
|
|
227
|
+
const anyBundle = rich.some((r) => r.variants && axis in r.variants);
|
|
228
|
+
if (anyBundle) {
|
|
229
|
+
console.warn(`Template "${templateName}" axis "${axis}" has no value "${wanted}" on path "${path.join(".")}"; ignored.`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const acc = {};
|
|
234
|
+
for (const r of rich) {
|
|
235
|
+
if (r.base) Object.assign(acc, r.base);
|
|
236
|
+
}
|
|
237
|
+
for (const axis of Object.keys(effective)) {
|
|
238
|
+
const value = effective[axis];
|
|
239
|
+
if (value === void 0) continue;
|
|
240
|
+
for (let i = rich.length - 1; i >= 0; i--) {
|
|
241
|
+
const bundle = (_d = (_c = rich[i].variants) == null ? void 0 : _c[axis]) == null ? void 0 : _d[value];
|
|
242
|
+
if (bundle) {
|
|
243
|
+
Object.assign(acc, bundle);
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
for (const r of rich) {
|
|
249
|
+
if (r.compoundVariants) {
|
|
250
|
+
for (const entry of r.compoundVariants) {
|
|
251
|
+
if (matchesAll(entry, effective) && entry.css) Object.assign(acc, entry.css);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (r.anyOfVariants) {
|
|
255
|
+
for (const entry of r.anyOfVariants) {
|
|
256
|
+
if (matchesAny(entry, effective) && entry.css) Object.assign(acc, entry.css);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return acc;
|
|
261
|
+
};
|
|
97
262
|
const parseStyles = async (styles, currentScope = "", config, omitTemplates = false) => {
|
|
98
263
|
if (!styles) throw new Error("No styles provided to parseStyles function!");
|
|
99
264
|
const cssStyles = /* @__PURE__ */ new Set();
|
|
@@ -137,13 +302,29 @@ const parseStyles = async (styles, currentScope = "", config, omitTemplates = fa
|
|
|
137
302
|
}
|
|
138
303
|
if ((config == null ? void 0 : config.templates) && config.templates[_key]) {
|
|
139
304
|
if (omitTemplates) return void 0;
|
|
140
|
-
const
|
|
141
|
-
const
|
|
142
|
-
if (
|
|
143
|
-
const
|
|
144
|
-
|
|
305
|
+
const root = config.templates[_key];
|
|
306
|
+
const callSite = parseTemplateCallSite(value);
|
|
307
|
+
if (callSite) {
|
|
308
|
+
const { path, variants } = callSite;
|
|
309
|
+
const hasCallSiteVariants = Object.keys(variants).length > 0;
|
|
310
|
+
if (hasCallSiteVariants || pathHasRichNode(root, path)) {
|
|
311
|
+
const resolved2 = resolveRichTemplate(root, path, variants, _key);
|
|
312
|
+
if (resolved2) {
|
|
313
|
+
const [result] = await parseStyles(resolved2, "");
|
|
314
|
+
return result;
|
|
315
|
+
}
|
|
316
|
+
console.warn(`Template "${_key}" with path of "${path.join(".")}" was not found in config!`);
|
|
317
|
+
return void 0;
|
|
318
|
+
}
|
|
319
|
+
const templateStyles = path.reduce((acc, key2) => acc == null ? void 0 : acc[key2], root);
|
|
320
|
+
if (templateStyles) {
|
|
321
|
+
const [result] = await parseStyles(templateStyles, "");
|
|
322
|
+
return result;
|
|
323
|
+
}
|
|
324
|
+
console.warn(`Template "${_key}" with path of "${path.join(".")}" was not found in config!`);
|
|
325
|
+
return void 0;
|
|
145
326
|
}
|
|
146
|
-
console.warn(`Template "${_key}"
|
|
327
|
+
console.warn(`Template "${_key}" received an unsupported call-site value.`);
|
|
147
328
|
return void 0;
|
|
148
329
|
}
|
|
149
330
|
const isVariantArrayKey = _key === "compoundVariants" || _key === "anyOfVariants";
|
|
@@ -154,6 +335,7 @@ const parseStyles = async (styles, currentScope = "", config, omitTemplates = fa
|
|
|
154
335
|
if (typeof value === "object") {
|
|
155
336
|
if (!value) return void 0;
|
|
156
337
|
if (value.isColor) return toString(value.toString());
|
|
338
|
+
if (value.isDefineFont) return toString(value.toString());
|
|
157
339
|
if (_key === "defaultVariants") return void 0;
|
|
158
340
|
if (_key === "variants") {
|
|
159
341
|
const variantEntries = Object.entries(value);
|
|
@@ -194,8 +376,9 @@ const parseStyles = async (styles, currentScope = "", config, omitTemplates = fa
|
|
|
194
376
|
}
|
|
195
377
|
if (_key.startsWith("@")) {
|
|
196
378
|
if (bareAtRuleRegex.test(_key)) reportParserIssue(strict, `At-rule "${_key}" is missing its condition (e.g. "@media (min-width: 600px)").`);
|
|
379
|
+
const innerScope = keyframesAtRuleRegex.test(_key) ? "" : currentScope;
|
|
197
380
|
const mediaQuery = ((_b = config == null ? void 0 : config.mediaQueries) == null ? void 0 : _b[_key]) || _key;
|
|
198
|
-
const results2 = await parseAndJoinStyles(value,
|
|
381
|
+
const results2 = await parseAndJoinStyles(value, innerScope, config);
|
|
199
382
|
const query = `${mediaQuery} { ${results2} }`;
|
|
200
383
|
cssStyles.add(query);
|
|
201
384
|
return void 0;
|
|
@@ -322,8 +505,10 @@ const combineSelectors = (currentScope, key) => {
|
|
|
322
505
|
}
|
|
323
506
|
return combos.join(", ");
|
|
324
507
|
};
|
|
508
|
+
exports.isRichTemplateNode = isRichTemplateNode;
|
|
325
509
|
exports.parseAndJoinStyles = parseAndJoinStyles;
|
|
326
510
|
exports.parseStyles = parseStyles;
|
|
511
|
+
exports.parseTemplateCallSite = parseTemplateCallSite;
|
|
327
512
|
exports.parseValueModifiers = parseValueModifiers;
|
|
328
513
|
exports.parseValueTokens = parseValueTokens;
|
|
329
514
|
exports.parseVariableTokens = parseVariableTokens;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { d as dashCase } from "./
|
|
1
|
+
import { d as dashCase } from "./to-hash-DSoCPs8D.js";
|
|
2
2
|
import { d as defineViewportClamp } from "./viewport-clamp-K553uXu3.js";
|
|
3
3
|
const parseValueModifiers = (modifiers) => (value) => {
|
|
4
4
|
if (typeof value !== "string") return void 0;
|
|
@@ -93,6 +93,171 @@ const reportParserIssue = (strict, message) => {
|
|
|
93
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
94
|
const templateLiteralLeftoverRegex = /\$\{[^}]+\}/;
|
|
95
95
|
const bareAtRuleRegex = /^@(media|supports|container|layer)\s*$/;
|
|
96
|
+
const keyframesAtRuleRegex = /^@(?:-(?:webkit|moz|o|ms)-)?keyframes\b/;
|
|
97
|
+
const isRichTemplateNode = (node) => {
|
|
98
|
+
if (!node || typeof node !== "object") return false;
|
|
99
|
+
if (Array.isArray(node)) return false;
|
|
100
|
+
const keys = Object.keys(node);
|
|
101
|
+
return keys.includes("base") || keys.includes("variants");
|
|
102
|
+
};
|
|
103
|
+
const parseTemplateCallSite = (value) => {
|
|
104
|
+
if (typeof value === "string") {
|
|
105
|
+
const [rawPath, rawQuery] = value.split("@", 2);
|
|
106
|
+
const path = rawPath.split(".").filter(Boolean);
|
|
107
|
+
if (!path.length) return void 0;
|
|
108
|
+
const variants = {};
|
|
109
|
+
if (rawQuery) {
|
|
110
|
+
for (const segment of rawQuery.split("&")) {
|
|
111
|
+
if (!segment) continue;
|
|
112
|
+
const eq = segment.indexOf("=");
|
|
113
|
+
if (eq === -1) {
|
|
114
|
+
variants[segment.trim()] = true;
|
|
115
|
+
} else {
|
|
116
|
+
const axis = segment.slice(0, eq).trim();
|
|
117
|
+
const raw = segment.slice(eq + 1).trim();
|
|
118
|
+
if (!axis) continue;
|
|
119
|
+
if (raw === "true") variants[axis] = true;
|
|
120
|
+
else if (raw === "false") variants[axis] = false;
|
|
121
|
+
else variants[axis] = raw;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return { path, variants };
|
|
126
|
+
}
|
|
127
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
128
|
+
const obj = value;
|
|
129
|
+
const name = obj["name"];
|
|
130
|
+
if (typeof name !== "string") return void 0;
|
|
131
|
+
const path = name.split(".").filter(Boolean);
|
|
132
|
+
if (!path.length) return void 0;
|
|
133
|
+
const variants = {};
|
|
134
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
135
|
+
if (k === "name") continue;
|
|
136
|
+
if (typeof v === "string" || typeof v === "boolean") variants[k] = v;
|
|
137
|
+
}
|
|
138
|
+
return { path, variants };
|
|
139
|
+
}
|
|
140
|
+
return void 0;
|
|
141
|
+
};
|
|
142
|
+
const normalizeAxisValue = (v) => {
|
|
143
|
+
if (v === void 0) return void 0;
|
|
144
|
+
return typeof v === "boolean" ? String(v) : v;
|
|
145
|
+
};
|
|
146
|
+
const buildPathStack = (root, path) => {
|
|
147
|
+
const stack = [{ node: root, isRich: isRichTemplateNode(root) }];
|
|
148
|
+
let cursor = root;
|
|
149
|
+
for (const segment of path) {
|
|
150
|
+
if (cursor == null || typeof cursor !== "object") return void 0;
|
|
151
|
+
const next = cursor[segment];
|
|
152
|
+
if (next === void 0) return void 0;
|
|
153
|
+
stack.push({ node: next, isRich: isRichTemplateNode(next) });
|
|
154
|
+
cursor = next;
|
|
155
|
+
}
|
|
156
|
+
return stack;
|
|
157
|
+
};
|
|
158
|
+
const pathHasRichNode = (root, path) => {
|
|
159
|
+
const stack = buildPathStack(root, path);
|
|
160
|
+
if (!stack) return false;
|
|
161
|
+
return stack.some((entry) => entry.isRich);
|
|
162
|
+
};
|
|
163
|
+
const matchesAll = (entry, effective) => {
|
|
164
|
+
for (const [axis, raw] of Object.entries(entry)) {
|
|
165
|
+
if (axis === "css") continue;
|
|
166
|
+
if (effective[axis] !== normalizeAxisValue(raw)) return false;
|
|
167
|
+
}
|
|
168
|
+
return true;
|
|
169
|
+
};
|
|
170
|
+
const matchesAny = (entry, effective) => {
|
|
171
|
+
let any = false;
|
|
172
|
+
for (const [axis, raw] of Object.entries(entry)) {
|
|
173
|
+
if (axis === "css") continue;
|
|
174
|
+
any = true;
|
|
175
|
+
if (effective[axis] === normalizeAxisValue(raw)) return true;
|
|
176
|
+
}
|
|
177
|
+
return !any;
|
|
178
|
+
};
|
|
179
|
+
const resolveRichTemplate = (root, path, callSiteVariants, templateName) => {
|
|
180
|
+
var _a, _b, _c, _d;
|
|
181
|
+
const stack = buildPathStack(root, path);
|
|
182
|
+
if (!stack) return void 0;
|
|
183
|
+
const rich = stack.map((entry) => {
|
|
184
|
+
if (entry.isRich) return entry.node;
|
|
185
|
+
if (entry.node && typeof entry.node === "object" && !Array.isArray(entry.node)) {
|
|
186
|
+
const onlyChildKeys = Object.keys(entry.node).every((k) => entry.node[k] && typeof entry.node[k] === "object" && !isRichTemplateNode(entry.node[k]));
|
|
187
|
+
return onlyChildKeys ? {} : { base: entry.node };
|
|
188
|
+
}
|
|
189
|
+
return {};
|
|
190
|
+
});
|
|
191
|
+
const declaredAxes = /* @__PURE__ */ new Set();
|
|
192
|
+
for (const r of rich) {
|
|
193
|
+
if (r.variants) for (const k of Object.keys(r.variants)) declaredAxes.add(k);
|
|
194
|
+
}
|
|
195
|
+
for (const r of rich) {
|
|
196
|
+
if (r.defaultVariants) for (const k of Object.keys(r.defaultVariants)) declaredAxes.add(k);
|
|
197
|
+
}
|
|
198
|
+
const effective = {};
|
|
199
|
+
for (const axis of declaredAxes) {
|
|
200
|
+
if (axis in callSiteVariants) {
|
|
201
|
+
effective[axis] = normalizeAxisValue(callSiteVariants[axis]);
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
for (let i = rich.length - 1; i >= 0; i--) {
|
|
205
|
+
const d = (_a = rich[i].defaultVariants) == null ? void 0 : _a[axis];
|
|
206
|
+
if (d !== void 0) {
|
|
207
|
+
effective[axis] = normalizeAxisValue(d);
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
for (const [axis, raw] of Object.entries(callSiteVariants)) {
|
|
213
|
+
if (!declaredAxes.has(axis)) {
|
|
214
|
+
console.warn(`Template "${templateName}" path "${path.join(".")}" has no variant axis "${axis}"; ignored.`);
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
const wanted = normalizeAxisValue(raw);
|
|
218
|
+
let found = false;
|
|
219
|
+
for (const r of rich) {
|
|
220
|
+
if (((_b = r.variants) == null ? void 0 : _b[axis]) && wanted !== void 0 && wanted in r.variants[axis]) {
|
|
221
|
+
found = true;
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (!found && wanted !== void 0) {
|
|
226
|
+
const anyBundle = rich.some((r) => r.variants && axis in r.variants);
|
|
227
|
+
if (anyBundle) {
|
|
228
|
+
console.warn(`Template "${templateName}" axis "${axis}" has no value "${wanted}" on path "${path.join(".")}"; ignored.`);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
const acc = {};
|
|
233
|
+
for (const r of rich) {
|
|
234
|
+
if (r.base) Object.assign(acc, r.base);
|
|
235
|
+
}
|
|
236
|
+
for (const axis of Object.keys(effective)) {
|
|
237
|
+
const value = effective[axis];
|
|
238
|
+
if (value === void 0) continue;
|
|
239
|
+
for (let i = rich.length - 1; i >= 0; i--) {
|
|
240
|
+
const bundle = (_d = (_c = rich[i].variants) == null ? void 0 : _c[axis]) == null ? void 0 : _d[value];
|
|
241
|
+
if (bundle) {
|
|
242
|
+
Object.assign(acc, bundle);
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
for (const r of rich) {
|
|
248
|
+
if (r.compoundVariants) {
|
|
249
|
+
for (const entry of r.compoundVariants) {
|
|
250
|
+
if (matchesAll(entry, effective) && entry.css) Object.assign(acc, entry.css);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (r.anyOfVariants) {
|
|
254
|
+
for (const entry of r.anyOfVariants) {
|
|
255
|
+
if (matchesAny(entry, effective) && entry.css) Object.assign(acc, entry.css);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return acc;
|
|
260
|
+
};
|
|
96
261
|
const parseStyles = async (styles, currentScope = "", config, omitTemplates = false) => {
|
|
97
262
|
if (!styles) throw new Error("No styles provided to parseStyles function!");
|
|
98
263
|
const cssStyles = /* @__PURE__ */ new Set();
|
|
@@ -136,13 +301,29 @@ const parseStyles = async (styles, currentScope = "", config, omitTemplates = fa
|
|
|
136
301
|
}
|
|
137
302
|
if ((config == null ? void 0 : config.templates) && config.templates[_key]) {
|
|
138
303
|
if (omitTemplates) return void 0;
|
|
139
|
-
const
|
|
140
|
-
const
|
|
141
|
-
if (
|
|
142
|
-
const
|
|
143
|
-
|
|
304
|
+
const root = config.templates[_key];
|
|
305
|
+
const callSite = parseTemplateCallSite(value);
|
|
306
|
+
if (callSite) {
|
|
307
|
+
const { path, variants } = callSite;
|
|
308
|
+
const hasCallSiteVariants = Object.keys(variants).length > 0;
|
|
309
|
+
if (hasCallSiteVariants || pathHasRichNode(root, path)) {
|
|
310
|
+
const resolved2 = resolveRichTemplate(root, path, variants, _key);
|
|
311
|
+
if (resolved2) {
|
|
312
|
+
const [result] = await parseStyles(resolved2, "");
|
|
313
|
+
return result;
|
|
314
|
+
}
|
|
315
|
+
console.warn(`Template "${_key}" with path of "${path.join(".")}" was not found in config!`);
|
|
316
|
+
return void 0;
|
|
317
|
+
}
|
|
318
|
+
const templateStyles = path.reduce((acc, key2) => acc == null ? void 0 : acc[key2], root);
|
|
319
|
+
if (templateStyles) {
|
|
320
|
+
const [result] = await parseStyles(templateStyles, "");
|
|
321
|
+
return result;
|
|
322
|
+
}
|
|
323
|
+
console.warn(`Template "${_key}" with path of "${path.join(".")}" was not found in config!`);
|
|
324
|
+
return void 0;
|
|
144
325
|
}
|
|
145
|
-
console.warn(`Template "${_key}"
|
|
326
|
+
console.warn(`Template "${_key}" received an unsupported call-site value.`);
|
|
146
327
|
return void 0;
|
|
147
328
|
}
|
|
148
329
|
const isVariantArrayKey = _key === "compoundVariants" || _key === "anyOfVariants";
|
|
@@ -153,6 +334,7 @@ const parseStyles = async (styles, currentScope = "", config, omitTemplates = fa
|
|
|
153
334
|
if (typeof value === "object") {
|
|
154
335
|
if (!value) return void 0;
|
|
155
336
|
if (value.isColor) return toString(value.toString());
|
|
337
|
+
if (value.isDefineFont) return toString(value.toString());
|
|
156
338
|
if (_key === "defaultVariants") return void 0;
|
|
157
339
|
if (_key === "variants") {
|
|
158
340
|
const variantEntries = Object.entries(value);
|
|
@@ -193,8 +375,9 @@ const parseStyles = async (styles, currentScope = "", config, omitTemplates = fa
|
|
|
193
375
|
}
|
|
194
376
|
if (_key.startsWith("@")) {
|
|
195
377
|
if (bareAtRuleRegex.test(_key)) reportParserIssue(strict, `At-rule "${_key}" is missing its condition (e.g. "@media (min-width: 600px)").`);
|
|
378
|
+
const innerScope = keyframesAtRuleRegex.test(_key) ? "" : currentScope;
|
|
196
379
|
const mediaQuery = ((_b = config == null ? void 0 : config.mediaQueries) == null ? void 0 : _b[_key]) || _key;
|
|
197
|
-
const results2 = await parseAndJoinStyles(value,
|
|
380
|
+
const results2 = await parseAndJoinStyles(value, innerScope, config);
|
|
198
381
|
const query = `${mediaQuery} { ${results2} }`;
|
|
199
382
|
cssStyles.add(query);
|
|
200
383
|
return void 0;
|
|
@@ -323,9 +506,11 @@ const combineSelectors = (currentScope, key) => {
|
|
|
323
506
|
};
|
|
324
507
|
export {
|
|
325
508
|
parseStyles as a,
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
509
|
+
parseTemplateCallSite as b,
|
|
510
|
+
parseVariableTokens as c,
|
|
511
|
+
parseValueModifiers as d,
|
|
512
|
+
parseValueTokens as e,
|
|
513
|
+
isRichTemplateNode as i,
|
|
329
514
|
parseAndJoinStyles as p,
|
|
330
515
|
reportParserIssue as r
|
|
331
516
|
};
|
package/parsers/index.cjs
CHANGED
|
@@ -1,11 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const parseStyles = require("../parse-styles-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
3
|
+
const parseStyles = require("../parse-styles-BbI-2wdn.cjs");
|
|
4
|
+
const toHash = require("../to-hash-DT2ImSPA.cjs");
|
|
5
|
+
const RICH_META_KEYS = /* @__PURE__ */ new Set(["base", "variants", "defaultVariants", "compoundVariants", "anyOfVariants"]);
|
|
6
|
+
const isChildEntry = (key, value) => {
|
|
7
|
+
if (RICH_META_KEYS.has(key)) return false;
|
|
8
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
9
|
+
};
|
|
6
10
|
const parseTemplates = async (obj, path = []) => {
|
|
7
11
|
if (!obj) return "";
|
|
8
12
|
const classes = [];
|
|
13
|
+
if (parseStyles.isRichTemplateNode(obj)) {
|
|
14
|
+
const rich = obj;
|
|
15
|
+
const baseClassName = path.map((p) => toHash.dashCase(String(p))).join("-");
|
|
16
|
+
if (rich.base) {
|
|
17
|
+
const hashClass = "t_" + toHash.toHash(baseClassName, 4);
|
|
18
|
+
const result = await parseStyles.parseAndJoinStyles(rich.base, `.${baseClassName}, .${hashClass}`);
|
|
19
|
+
classes.push(result);
|
|
20
|
+
}
|
|
21
|
+
if (rich.variants) {
|
|
22
|
+
for (const [axis, valueMap] of Object.entries(rich.variants)) {
|
|
23
|
+
if (!valueMap || typeof valueMap !== "object") continue;
|
|
24
|
+
for (const [value, styles] of Object.entries(valueMap)) {
|
|
25
|
+
if (!styles || typeof styles !== "object") continue;
|
|
26
|
+
const variantClassName = `${baseClassName}-${toHash.dashCase(axis)}-${toHash.dashCase(value)}`;
|
|
27
|
+
const variantHashClass = "tv_" + toHash.toHash(variantClassName, 4);
|
|
28
|
+
const result = await parseStyles.parseAndJoinStyles(styles, `.${variantClassName}, .${variantHashClass}`);
|
|
29
|
+
classes.push(result);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
for (const [key, value] of Object.entries(rich)) {
|
|
34
|
+
if (!isChildEntry(key, value)) continue;
|
|
35
|
+
const result = await parseTemplates(value, [...path, key.trim()]);
|
|
36
|
+
classes.push(result);
|
|
37
|
+
}
|
|
38
|
+
return classes.join("\n");
|
|
39
|
+
}
|
|
9
40
|
const levelStyles = {};
|
|
10
41
|
for (const [key, value] of Object.entries(obj)) {
|
|
11
42
|
if (typeof value === "function") ;
|
|
@@ -18,7 +49,7 @@ const parseTemplates = async (obj, path = []) => {
|
|
|
18
49
|
}
|
|
19
50
|
}
|
|
20
51
|
if (Object.keys(levelStyles).length) {
|
|
21
|
-
const className = path.map(
|
|
52
|
+
const className = path.map((p) => toHash.dashCase(String(p))).join("-");
|
|
22
53
|
const hashClass = "t_" + toHash.toHash(className, 4);
|
|
23
54
|
const result = await parseStyles.parseAndJoinStyles(levelStyles, `.${className}, .${hashClass}`);
|
|
24
55
|
classes.push(result);
|
|
@@ -40,13 +71,69 @@ const getTemplateTypes = (templates) => {
|
|
|
40
71
|
};
|
|
41
72
|
const getTemplateTokens = (templates, parent = "", templateTokens = /* @__PURE__ */ new Set()) => {
|
|
42
73
|
if (!templates) return [];
|
|
74
|
+
if (parseStyles.isRichTemplateNode(templates)) {
|
|
75
|
+
if (parent) templateTokens.add(parent);
|
|
76
|
+
Object.entries(templates).forEach(([key, value]) => {
|
|
77
|
+
if (!isChildEntry(key, value)) return;
|
|
78
|
+
const keyValue = parent ? `${parent}.${key}` : key;
|
|
79
|
+
getTemplateTokens(value, keyValue, templateTokens);
|
|
80
|
+
});
|
|
81
|
+
return [...templateTokens];
|
|
82
|
+
}
|
|
43
83
|
Object.entries(templates).forEach(([key, value]) => {
|
|
44
84
|
const keyValue = parent ? `${parent}.${key}` : key;
|
|
45
|
-
if (typeof value === "object") return getTemplateTokens(value, keyValue, templateTokens);
|
|
85
|
+
if (value && typeof value === "object") return getTemplateTokens(value, keyValue, templateTokens);
|
|
46
86
|
return templateTokens.add(parent);
|
|
47
87
|
});
|
|
48
88
|
return [...templateTokens];
|
|
49
89
|
};
|
|
90
|
+
const getTemplateVariantMaps = (templates) => {
|
|
91
|
+
const result = {};
|
|
92
|
+
if (!templates) return result;
|
|
93
|
+
for (const [topKey, topNode] of Object.entries(templates)) {
|
|
94
|
+
if (!topNode || typeof topNode !== "object" || typeof topNode === "function") continue;
|
|
95
|
+
walk(topNode, [], result[topKey] || (result[topKey] = {}), {});
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
};
|
|
99
|
+
const mergeAxes = (inherited, node) => {
|
|
100
|
+
const next = {};
|
|
101
|
+
for (const [axis, vals] of Object.entries(inherited)) {
|
|
102
|
+
next[axis] = { ...vals };
|
|
103
|
+
}
|
|
104
|
+
if (parseStyles.isRichTemplateNode(node) && node.variants) {
|
|
105
|
+
for (const [axis, valueMap] of Object.entries(node.variants)) {
|
|
106
|
+
next[axis] = next[axis] || {};
|
|
107
|
+
for (const value of Object.keys(valueMap)) next[axis][value] = true;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return next;
|
|
111
|
+
};
|
|
112
|
+
const walk = (node, path, out, inheritedAxes) => {
|
|
113
|
+
if (!node || typeof node !== "object" || Array.isArray(node)) return;
|
|
114
|
+
const axes = mergeAxes(inheritedAxes, node);
|
|
115
|
+
const dot = path.join(".");
|
|
116
|
+
if (path.length && (parseStyles.isRichTemplateNode(node) || Object.keys(axes).length)) {
|
|
117
|
+
const axisMap = {};
|
|
118
|
+
for (const [axis, valSet] of Object.entries(axes)) {
|
|
119
|
+
const values = Object.keys(valSet);
|
|
120
|
+
const isBooleanOnly = values.length === 1 && values[0] === "true";
|
|
121
|
+
axisMap[axis] = isBooleanOnly ? "boolean" : values.map((v) => `"${v}"`).join(" | ");
|
|
122
|
+
}
|
|
123
|
+
if (Object.keys(axisMap).length) out[dot] = axisMap;
|
|
124
|
+
}
|
|
125
|
+
if (parseStyles.isRichTemplateNode(node)) {
|
|
126
|
+
for (const [key, value] of Object.entries(node)) {
|
|
127
|
+
if (!isChildEntry(key, value)) continue;
|
|
128
|
+
walk(value, [...path, key.trim()], out, axes);
|
|
129
|
+
}
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
for (const [key, value] of Object.entries(node)) {
|
|
133
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) continue;
|
|
134
|
+
walk(value, [...path, key.trim()], out, axes);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
50
137
|
exports.parseAndJoinStyles = parseStyles.parseAndJoinStyles;
|
|
51
138
|
exports.parseStyles = parseStyles.parseStyles;
|
|
52
139
|
exports.parseValueModifiers = parseStyles.parseValueModifiers;
|
|
@@ -56,4 +143,5 @@ exports.reportParserIssue = parseStyles.reportParserIssue;
|
|
|
56
143
|
exports.getTemplateKeys = getTemplateKeys;
|
|
57
144
|
exports.getTemplateTokens = getTemplateTokens;
|
|
58
145
|
exports.getTemplateTypes = getTemplateTypes;
|
|
146
|
+
exports.getTemplateVariantMaps = getTemplateVariantMaps;
|
|
59
147
|
exports.parseTemplates = parseTemplates;
|