clava 0.1.19 → 0.2.1
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/CHANGELOG.md +39 -0
- package/dist/index.d.ts +13 -30
- package/dist/index.js +569 -370
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/perfs/component.bench.ts +233 -0
- package/src/index.ts +759 -609
- package/src/types.ts +13 -4
- package/src/utils.ts +100 -32
- package/tests/_utils.ts +176 -0
- package/tests/class-style-test.ts +341 -0
- package/tests/component-api-test.ts +214 -0
- package/tests/computed-test.ts +800 -0
- package/tests/computed-variants-test.ts +298 -0
- package/tests/extend-test.ts +301 -0
- package/{src/test-language-service.ts → tests/language-service-test.ts} +6 -2
- package/{src/test-react.ts → tests/react-test.ts} +3 -3
- package/{src/test-solid.ts → tests/solid-test.ts} +3 -5
- package/tests/split-props-test.ts +590 -0
- package/tests/variants-test.ts +380 -0
- package/tsconfig.json +1 -1
- package/src/test.ts +0 -2873
package/dist/index.js
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import clsx from "clsx";
|
|
2
2
|
//#region src/utils.ts
|
|
3
|
-
|
|
4
|
-
* Returns the appropriate class property name based on the mode.
|
|
5
|
-
* @example
|
|
6
|
-
* getClassPropertyName("jsx") // "className"
|
|
7
|
-
* getClassPropertyName("html") // "class"
|
|
8
|
-
*/
|
|
9
|
-
function getClassPropertyName(mode) {
|
|
10
|
-
return mode === "jsx" ? "className" : "class";
|
|
11
|
-
}
|
|
3
|
+
const hasOwn$1 = Object.prototype.hasOwnProperty;
|
|
12
4
|
/**
|
|
13
5
|
* Converts a hyphenated CSS property name to camelCase.
|
|
14
6
|
* @example
|
|
@@ -16,7 +8,8 @@ function getClassPropertyName(mode) {
|
|
|
16
8
|
* hyphenToCamel("--custom-var") // "--custom-var" (CSS variables are preserved)
|
|
17
9
|
*/
|
|
18
10
|
function hyphenToCamel(str) {
|
|
19
|
-
if (str.
|
|
11
|
+
if (str.length >= 2 && str.charCodeAt(0) === 45 && str.charCodeAt(1) === 45) return str;
|
|
12
|
+
if (str.indexOf("-") === -1) return str;
|
|
20
13
|
return str.replace(/-([a-z])/gi, (_, letter) => letter.toUpperCase());
|
|
21
14
|
}
|
|
22
15
|
/**
|
|
@@ -26,7 +19,7 @@ function hyphenToCamel(str) {
|
|
|
26
19
|
* camelToHyphen("--customVar") // "--customVar" (CSS variables are preserved)
|
|
27
20
|
*/
|
|
28
21
|
function camelToHyphen(str) {
|
|
29
|
-
if (str.
|
|
22
|
+
if (str.length >= 2 && str.charCodeAt(0) === 45 && str.charCodeAt(1) === 45) return str;
|
|
30
23
|
return str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
31
24
|
}
|
|
32
25
|
/**
|
|
@@ -48,16 +41,54 @@ function parseLengthValue(value) {
|
|
|
48
41
|
function htmlStyleToStyleValue(styleString) {
|
|
49
42
|
if (!styleString) return {};
|
|
50
43
|
const result = {};
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (
|
|
60
|
-
|
|
44
|
+
const len = styleString.length;
|
|
45
|
+
let i = 0;
|
|
46
|
+
while (i < len) {
|
|
47
|
+
while (i < len) {
|
|
48
|
+
const c = styleString.charCodeAt(i);
|
|
49
|
+
if (c !== 32 && c !== 9 && c !== 10 && c !== 13 && c !== 59) break;
|
|
50
|
+
i++;
|
|
51
|
+
}
|
|
52
|
+
if (i >= len) break;
|
|
53
|
+
const propStart = i;
|
|
54
|
+
while (i < len) {
|
|
55
|
+
const c = styleString.charCodeAt(i);
|
|
56
|
+
if (c === 58 || c === 59) break;
|
|
57
|
+
i++;
|
|
58
|
+
}
|
|
59
|
+
if (i >= len || styleString.charCodeAt(i) === 59) {
|
|
60
|
+
if (i < len) i++;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
let propEnd = i;
|
|
64
|
+
while (propEnd > propStart) {
|
|
65
|
+
const c = styleString.charCodeAt(propEnd - 1);
|
|
66
|
+
if (c !== 32 && c !== 9 && c !== 10 && c !== 13) break;
|
|
67
|
+
propEnd--;
|
|
68
|
+
}
|
|
69
|
+
if (propEnd === propStart) {
|
|
70
|
+
while (i < len && styleString.charCodeAt(i) !== 59) i++;
|
|
71
|
+
if (i < len) i++;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const property = styleString.slice(propStart, propEnd);
|
|
75
|
+
i++;
|
|
76
|
+
while (i < len) {
|
|
77
|
+
const c = styleString.charCodeAt(i);
|
|
78
|
+
if (c !== 32 && c !== 9 && c !== 10 && c !== 13) break;
|
|
79
|
+
i++;
|
|
80
|
+
}
|
|
81
|
+
const valStart = i;
|
|
82
|
+
while (i < len && styleString.charCodeAt(i) !== 59) i++;
|
|
83
|
+
let valEnd = i;
|
|
84
|
+
while (valEnd > valStart) {
|
|
85
|
+
const c = styleString.charCodeAt(valEnd - 1);
|
|
86
|
+
if (c !== 32 && c !== 9 && c !== 10 && c !== 13) break;
|
|
87
|
+
valEnd--;
|
|
88
|
+
}
|
|
89
|
+
if (i < len) i++;
|
|
90
|
+
if (valEnd === valStart) continue;
|
|
91
|
+
const value = styleString.slice(valStart, valEnd);
|
|
61
92
|
result[hyphenToCamel(property)] = value;
|
|
62
93
|
}
|
|
63
94
|
return result;
|
|
@@ -70,7 +101,9 @@ function htmlStyleToStyleValue(styleString) {
|
|
|
70
101
|
*/
|
|
71
102
|
function htmlObjStyleToStyleValue(style) {
|
|
72
103
|
const result = {};
|
|
73
|
-
for (const
|
|
104
|
+
for (const key in style) {
|
|
105
|
+
if (!hasOwn$1.call(style, key)) continue;
|
|
106
|
+
const value = style[key];
|
|
74
107
|
if (value == null) continue;
|
|
75
108
|
result[hyphenToCamel(key)] = parseLengthValue(value);
|
|
76
109
|
}
|
|
@@ -84,7 +117,9 @@ function htmlObjStyleToStyleValue(style) {
|
|
|
84
117
|
*/
|
|
85
118
|
function jsxStyleToStyleValue(style) {
|
|
86
119
|
const result = {};
|
|
87
|
-
for (const
|
|
120
|
+
for (const key in style) {
|
|
121
|
+
if (!hasOwn$1.call(style, key)) continue;
|
|
122
|
+
const value = style[key];
|
|
88
123
|
if (value == null) continue;
|
|
89
124
|
result[key] = parseLengthValue(value);
|
|
90
125
|
}
|
|
@@ -97,13 +132,18 @@ function jsxStyleToStyleValue(style) {
|
|
|
97
132
|
* // "background-color: red; font-size: 16px;"
|
|
98
133
|
*/
|
|
99
134
|
function styleValueToHTMLStyle(style) {
|
|
100
|
-
|
|
101
|
-
for (const
|
|
135
|
+
let result = "";
|
|
136
|
+
for (const key in style) {
|
|
137
|
+
if (!hasOwn$1.call(style, key)) continue;
|
|
138
|
+
const value = style[key];
|
|
102
139
|
if (value == null) continue;
|
|
103
|
-
|
|
140
|
+
if (result) result += "; ";
|
|
141
|
+
result += camelToHyphen(key);
|
|
142
|
+
result += ": ";
|
|
143
|
+
result += value;
|
|
104
144
|
}
|
|
105
|
-
if (!
|
|
106
|
-
return `${
|
|
145
|
+
if (!result) return "";
|
|
146
|
+
return `${result};`;
|
|
107
147
|
}
|
|
108
148
|
/**
|
|
109
149
|
* Converts a StyleValue object to a hyphenated style object.
|
|
@@ -113,10 +153,11 @@ function styleValueToHTMLStyle(style) {
|
|
|
113
153
|
*/
|
|
114
154
|
function styleValueToHTMLObjStyle(style) {
|
|
115
155
|
const result = {};
|
|
116
|
-
for (const
|
|
156
|
+
for (const key in style) {
|
|
157
|
+
if (!hasOwn$1.call(style, key)) continue;
|
|
158
|
+
const value = style[key];
|
|
117
159
|
if (value == null) continue;
|
|
118
|
-
|
|
119
|
-
result[property] = value;
|
|
160
|
+
result[camelToHyphen(key)] = value;
|
|
120
161
|
}
|
|
121
162
|
return result;
|
|
122
163
|
}
|
|
@@ -136,13 +177,19 @@ function styleValueToJSXStyle(style) {
|
|
|
136
177
|
* isHTMLObjStyle({ backgroundColor: "red" }); // false
|
|
137
178
|
*/
|
|
138
179
|
function isHTMLObjStyle(style) {
|
|
139
|
-
|
|
180
|
+
for (const key in style) {
|
|
181
|
+
if (!hasOwn$1.call(style, key)) continue;
|
|
182
|
+
if (key.length >= 2 && key.charCodeAt(0) === 45 && key.charCodeAt(1) === 45) continue;
|
|
183
|
+
if (key.indexOf("-") !== -1) return true;
|
|
184
|
+
}
|
|
185
|
+
return false;
|
|
140
186
|
}
|
|
141
187
|
//#endregion
|
|
142
188
|
//#region src/index.ts
|
|
143
189
|
const META_KEY = "__meta";
|
|
144
190
|
const SKIP_STYLE_KEYS = Symbol("skipStyleKeys");
|
|
145
191
|
const SKIP_STYLE_VARIANT_VALUES = Symbol("skipStyleVariantValues");
|
|
192
|
+
const hasOwn = Object.prototype.hasOwnProperty;
|
|
146
193
|
function getComponentMeta(component) {
|
|
147
194
|
return component[META_KEY];
|
|
148
195
|
}
|
|
@@ -155,7 +202,7 @@ function setComponentMeta(component, meta) {
|
|
|
155
202
|
*/
|
|
156
203
|
function assign(target, source) {
|
|
157
204
|
for (const key in source) {
|
|
158
|
-
if (!
|
|
205
|
+
if (!hasOwn.call(source, key)) continue;
|
|
159
206
|
target[key] = source[key];
|
|
160
207
|
}
|
|
161
208
|
}
|
|
@@ -184,28 +231,22 @@ function normalizeStyle(style) {
|
|
|
184
231
|
}
|
|
185
232
|
return {};
|
|
186
233
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
*/
|
|
190
|
-
function extractStyleClass(value) {
|
|
234
|
+
function extractStyleClassPrebuilt(value) {
|
|
235
|
+
const styleNorm = normalizeStyle(value.style);
|
|
191
236
|
return {
|
|
192
|
-
class: value.class,
|
|
193
|
-
style:
|
|
237
|
+
class: value.class ?? null,
|
|
238
|
+
style: styleNorm && Object.keys(styleNorm).length > 0 ? styleNorm : null
|
|
194
239
|
};
|
|
195
240
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
* style-class object).
|
|
199
|
-
*/
|
|
200
|
-
function extractClassAndStyle(value) {
|
|
201
|
-
if (isStyleClassValue(value)) return extractStyleClass(value);
|
|
241
|
+
function extractClassAndStylePrebuilt(value) {
|
|
242
|
+
if (isStyleClassValue(value)) return extractStyleClassPrebuilt(value);
|
|
202
243
|
if (isRecordObject(value)) return {
|
|
203
244
|
class: null,
|
|
204
|
-
style:
|
|
245
|
+
style: null
|
|
205
246
|
};
|
|
206
247
|
return {
|
|
207
248
|
class: value,
|
|
208
|
-
style:
|
|
249
|
+
style: null
|
|
209
250
|
};
|
|
210
251
|
}
|
|
211
252
|
/**
|
|
@@ -214,15 +255,22 @@ function extractClassAndStyle(value) {
|
|
|
214
255
|
*/
|
|
215
256
|
function collectVariantKeys(config) {
|
|
216
257
|
const keys = /* @__PURE__ */ new Set();
|
|
217
|
-
if (config.extend) for (const ext of config.extend)
|
|
218
|
-
|
|
219
|
-
|
|
258
|
+
if (config.extend) for (const ext of config.extend) {
|
|
259
|
+
const extKeys = ext.variantKeys;
|
|
260
|
+
for (let i = 0; i < extKeys.length; i++) keys.add(extKeys[i]);
|
|
261
|
+
}
|
|
262
|
+
if (config.variants) for (const key in config.variants) {
|
|
263
|
+
if (!hasOwn.call(config.variants, key)) continue;
|
|
264
|
+
if (config.variants[key] === null) {
|
|
220
265
|
keys.delete(key);
|
|
221
266
|
continue;
|
|
222
267
|
}
|
|
223
268
|
keys.add(key);
|
|
224
269
|
}
|
|
225
|
-
if (config.computedVariants) for (const key
|
|
270
|
+
if (config.computedVariants) for (const key in config.computedVariants) {
|
|
271
|
+
if (!hasOwn.call(config.computedVariants, key)) continue;
|
|
272
|
+
keys.add(key);
|
|
273
|
+
}
|
|
226
274
|
return Array.from(keys);
|
|
227
275
|
}
|
|
228
276
|
function isVariantDisabled(config, key) {
|
|
@@ -240,118 +288,35 @@ function isVariantValueDisabled(config, key, value) {
|
|
|
240
288
|
if (!isRecordObject(variant)) return false;
|
|
241
289
|
return variant[valueKey] === null;
|
|
242
290
|
}
|
|
243
|
-
function filterDisabledVariants(config, variants) {
|
|
244
|
-
const filtered = {};
|
|
245
|
-
for (const [key, value] of Object.entries(variants)) {
|
|
246
|
-
if (isVariantDisabled(config, key)) continue;
|
|
247
|
-
if (isVariantValueDisabled(config, key, value)) continue;
|
|
248
|
-
filtered[key] = value;
|
|
249
|
-
}
|
|
250
|
-
return filtered;
|
|
251
|
-
}
|
|
252
291
|
function collectDisabledVariantKeys(config) {
|
|
253
292
|
const keys = /* @__PURE__ */ new Set();
|
|
254
293
|
if (!config.variants) return keys;
|
|
255
|
-
for (const
|
|
294
|
+
for (const key in config.variants) {
|
|
295
|
+
if (!hasOwn.call(config.variants, key)) continue;
|
|
296
|
+
if (config.variants[key] === null) keys.add(key);
|
|
297
|
+
}
|
|
256
298
|
return keys;
|
|
257
299
|
}
|
|
258
300
|
function collectDisabledVariantValues(config) {
|
|
259
301
|
const values = {};
|
|
260
302
|
if (!config.variants) return values;
|
|
261
|
-
for (const
|
|
303
|
+
for (const key in config.variants) {
|
|
304
|
+
if (!hasOwn.call(config.variants, key)) continue;
|
|
305
|
+
const variant = config.variants[key];
|
|
262
306
|
if (!isRecordObject(variant)) continue;
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
if (!
|
|
266
|
-
|
|
307
|
+
let bucket;
|
|
308
|
+
for (const variantValue in variant) {
|
|
309
|
+
if (!hasOwn.call(variant, variantValue)) continue;
|
|
310
|
+
if (variant[variantValue] !== null) continue;
|
|
311
|
+
if (!bucket) {
|
|
312
|
+
bucket = /* @__PURE__ */ new Set();
|
|
313
|
+
values[key] = bucket;
|
|
314
|
+
}
|
|
315
|
+
bucket.add(variantValue);
|
|
267
316
|
}
|
|
268
317
|
}
|
|
269
318
|
return values;
|
|
270
319
|
}
|
|
271
|
-
function mergeDisabledVariantValues(base, override) {
|
|
272
|
-
const merged = {};
|
|
273
|
-
for (const [key, values] of Object.entries(base)) merged[key] = new Set(values);
|
|
274
|
-
for (const [key, values] of Object.entries(override)) {
|
|
275
|
-
if (!merged[key]) merged[key] = /* @__PURE__ */ new Set();
|
|
276
|
-
for (const value of values) merged[key].add(value);
|
|
277
|
-
}
|
|
278
|
-
return merged;
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Collects static default variants from extended components and the current
|
|
282
|
-
* config. Also handles implicit boolean defaults (when only `false` key
|
|
283
|
-
* exists). This does NOT trigger computed functions - use collectDefaultVariants
|
|
284
|
-
* for that.
|
|
285
|
-
*/
|
|
286
|
-
function collectStaticDefaults(config) {
|
|
287
|
-
const defaults = {};
|
|
288
|
-
if (config.extend) for (const ext of config.extend) {
|
|
289
|
-
const meta = getComponentMeta(ext);
|
|
290
|
-
if (meta) Object.assign(defaults, meta.staticDefaults);
|
|
291
|
-
}
|
|
292
|
-
if (config.variants) for (const [variantName, variantDef] of Object.entries(config.variants)) {
|
|
293
|
-
if (!isRecordObject(variantDef)) continue;
|
|
294
|
-
if (Object.keys(variantDef).includes("false") && !defaults[variantName]) defaults[variantName] = false;
|
|
295
|
-
}
|
|
296
|
-
if (config.defaultVariants) Object.assign(defaults, config.defaultVariants);
|
|
297
|
-
return filterDisabledVariants(config, defaults);
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Collects default variants from extended components and the current config.
|
|
301
|
-
* This includes both static defaults and computed defaults (from
|
|
302
|
-
* setDefaultVariants in extended components' computed functions). Priority:
|
|
303
|
-
* parent static < child static < parent computed < child computed.
|
|
304
|
-
*/
|
|
305
|
-
function collectDefaultVariants(config, propsVariants = {}) {
|
|
306
|
-
const defaults = collectStaticDefaults(config);
|
|
307
|
-
if (!config.extend) return defaults;
|
|
308
|
-
for (const ext of config.extend) {
|
|
309
|
-
const meta = getComponentMeta(ext);
|
|
310
|
-
if (!meta) continue;
|
|
311
|
-
Object.assign(defaults, meta.resolveDefaults(defaults, propsVariants));
|
|
312
|
-
}
|
|
313
|
-
return filterDisabledVariants(config, defaults);
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Filters out keys with undefined values from an object.
|
|
317
|
-
*/
|
|
318
|
-
function filterUndefined(obj) {
|
|
319
|
-
const result = {};
|
|
320
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
321
|
-
if (value === void 0) continue;
|
|
322
|
-
result[key] = value;
|
|
323
|
-
}
|
|
324
|
-
return result;
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Resolves variant values by merging defaults with provided props. Props with
|
|
328
|
-
* undefined values are filtered out so they don't override defaults.
|
|
329
|
-
*/
|
|
330
|
-
function resolveVariants(config, props = {}) {
|
|
331
|
-
return filterDisabledVariants(config, {
|
|
332
|
-
...collectDefaultVariants(config, props),
|
|
333
|
-
...filterUndefined(props)
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Gets the value for a single variant based on the variant definition and the
|
|
338
|
-
* selected value.
|
|
339
|
-
*/
|
|
340
|
-
function getVariantResult(variantDef, selectedValue) {
|
|
341
|
-
if (!isRecordObject(variantDef)) {
|
|
342
|
-
if (selectedValue === true) return extractClassAndStyle(variantDef);
|
|
343
|
-
return {
|
|
344
|
-
class: null,
|
|
345
|
-
style: {}
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
const value = variantDef[String(selectedValue)];
|
|
349
|
-
if (value === void 0) return {
|
|
350
|
-
class: null,
|
|
351
|
-
style: {}
|
|
352
|
-
};
|
|
353
|
-
return extractClassAndStyle(value);
|
|
354
|
-
}
|
|
355
320
|
/**
|
|
356
321
|
* Extracts classes from fullClass that are not in baseClass. Uses string
|
|
357
322
|
* comparison optimization: if fullClass starts with baseClass, just take the
|
|
@@ -364,125 +329,15 @@ function extractVariantClasses(fullClass, baseClass) {
|
|
|
364
329
|
const baseClassSet = new Set(baseClass.split(" ").filter(Boolean));
|
|
365
330
|
return fullClass.split(" ").filter((c) => c && !baseClassSet.has(c)).join(" ");
|
|
366
331
|
}
|
|
367
|
-
function computeExtendedStyles(config, resolvedVariants, overrideVariantKeys = /* @__PURE__ */ new Set(), overrideVariantValues = {}) {
|
|
368
|
-
const baseClasses = [];
|
|
369
|
-
const variantClasses = [];
|
|
370
|
-
const style = {};
|
|
371
|
-
if (!config.extend) return {
|
|
372
|
-
baseClasses,
|
|
373
|
-
variantClasses,
|
|
374
|
-
style
|
|
375
|
-
};
|
|
376
|
-
const hasOverrideVariantKeys = overrideVariantKeys.size > 0;
|
|
377
|
-
const hasOverrideVariantValues = Object.keys(overrideVariantValues).length > 0;
|
|
378
|
-
for (const ext of config.extend) {
|
|
379
|
-
const propsForExt = { ...resolvedVariants };
|
|
380
|
-
if (hasOverrideVariantKeys) propsForExt[SKIP_STYLE_KEYS] = overrideVariantKeys;
|
|
381
|
-
if (hasOverrideVariantValues) propsForExt[SKIP_STYLE_VARIANT_VALUES] = overrideVariantValues;
|
|
382
|
-
const extResult = ext(propsForExt);
|
|
383
|
-
assign(style, normalizeStyle(extResult.style));
|
|
384
|
-
const baseClass = getComponentMeta(ext)?.baseClass ?? "";
|
|
385
|
-
baseClasses.push(baseClass);
|
|
386
|
-
const variantPortion = extractVariantClasses("className" in extResult ? extResult.className : extResult.class, baseClass);
|
|
387
|
-
if (variantPortion) variantClasses.push(variantPortion);
|
|
388
|
-
}
|
|
389
|
-
return {
|
|
390
|
-
baseClasses,
|
|
391
|
-
variantClasses,
|
|
392
|
-
style
|
|
393
|
-
};
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* Computes class and style from the component's own variants and
|
|
397
|
-
* computedVariants (not extended components).
|
|
398
|
-
*/
|
|
399
|
-
function computeVariantStyles(config, resolvedVariants, skipStyleKeys = /* @__PURE__ */ new Set(), skipVariantValues = {}) {
|
|
400
|
-
const classes = [];
|
|
401
|
-
const style = {};
|
|
402
|
-
if (config.variants) for (const [variantName, variantDef] of Object.entries(config.variants)) {
|
|
403
|
-
if (skipStyleKeys.has(variantName)) continue;
|
|
404
|
-
const selectedValue = resolvedVariants[variantName];
|
|
405
|
-
if (selectedValue === void 0) continue;
|
|
406
|
-
const selectedKey = getVariantValueKey(selectedValue);
|
|
407
|
-
if (selectedKey && skipVariantValues[variantName]?.has(selectedKey)) continue;
|
|
408
|
-
const result = getVariantResult(variantDef, selectedValue);
|
|
409
|
-
classes.push(result.class);
|
|
410
|
-
assign(style, result.style);
|
|
411
|
-
}
|
|
412
|
-
if (config.computedVariants) for (const [variantName, computeFn] of Object.entries(config.computedVariants)) {
|
|
413
|
-
if (skipStyleKeys.has(variantName)) continue;
|
|
414
|
-
const selectedValue = resolvedVariants[variantName];
|
|
415
|
-
if (selectedValue === void 0) continue;
|
|
416
|
-
const selectedKey = getVariantValueKey(selectedValue);
|
|
417
|
-
if (selectedKey && skipVariantValues[variantName]?.has(selectedKey)) continue;
|
|
418
|
-
const result = extractClassAndStyle(computeFn(selectedValue));
|
|
419
|
-
classes.push(result.class);
|
|
420
|
-
assign(style, result.style);
|
|
421
|
-
}
|
|
422
|
-
return {
|
|
423
|
-
classes,
|
|
424
|
-
style
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* Runs the computed function if present, returning classes, styles, and updated
|
|
429
|
-
* variants.
|
|
430
|
-
*/
|
|
431
|
-
function runComputedFunction(config, resolvedVariants, propsVariants) {
|
|
432
|
-
const classes = [];
|
|
433
|
-
const style = {};
|
|
434
|
-
const updatedVariants = { ...resolvedVariants };
|
|
435
|
-
if (!config.computed) return {
|
|
436
|
-
classes,
|
|
437
|
-
style,
|
|
438
|
-
updatedVariants
|
|
439
|
-
};
|
|
440
|
-
const context = {
|
|
441
|
-
variants: resolvedVariants,
|
|
442
|
-
setVariants: (newVariants) => {
|
|
443
|
-
Object.assign(updatedVariants, filterDisabledVariants(config, newVariants));
|
|
444
|
-
},
|
|
445
|
-
setDefaultVariants: (newDefaults) => {
|
|
446
|
-
for (const [key, value] of Object.entries(newDefaults)) if (propsVariants[key] === void 0) {
|
|
447
|
-
if (isVariantDisabled(config, key)) continue;
|
|
448
|
-
if (isVariantValueDisabled(config, key, value)) continue;
|
|
449
|
-
updatedVariants[key] = value;
|
|
450
|
-
}
|
|
451
|
-
},
|
|
452
|
-
addClass: (className) => {
|
|
453
|
-
classes.push(className);
|
|
454
|
-
},
|
|
455
|
-
addStyle: (newStyle) => {
|
|
456
|
-
assign(style, newStyle);
|
|
457
|
-
}
|
|
458
|
-
};
|
|
459
|
-
const computedResult = config.computed(context);
|
|
460
|
-
if (computedResult != null) {
|
|
461
|
-
const result = extractClassAndStyle(computedResult);
|
|
462
|
-
classes.push(result.class);
|
|
463
|
-
assign(style, result.style);
|
|
464
|
-
}
|
|
465
|
-
return {
|
|
466
|
-
classes,
|
|
467
|
-
style,
|
|
468
|
-
updatedVariants: filterDisabledVariants(config, updatedVariants)
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
332
|
const EMPTY_SOURCE = {
|
|
472
333
|
keys: [],
|
|
473
334
|
variantKeys: [],
|
|
474
|
-
defaults: {},
|
|
475
335
|
isComponent: false
|
|
476
336
|
};
|
|
477
|
-
/**
|
|
478
|
-
* Normalizes a key source (array or component) to an object with keys,
|
|
479
|
-
* variantKeys, defaults, and isComponent flag.
|
|
480
|
-
*/
|
|
481
337
|
function normalizeKeySource(source) {
|
|
482
338
|
if (Array.isArray(source)) return {
|
|
483
339
|
keys: source,
|
|
484
340
|
variantKeys: source,
|
|
485
|
-
defaults: {},
|
|
486
341
|
isComponent: false
|
|
487
342
|
};
|
|
488
343
|
if (!source) return EMPTY_SOURCE;
|
|
@@ -491,9 +346,8 @@ function normalizeKeySource(source) {
|
|
|
491
346
|
if (!("variantKeys" in source)) return EMPTY_SOURCE;
|
|
492
347
|
const typed = source;
|
|
493
348
|
return {
|
|
494
|
-
keys:
|
|
495
|
-
variantKeys:
|
|
496
|
-
defaults: typed.getVariants?.() ?? {},
|
|
349
|
+
keys: typed.keys,
|
|
350
|
+
variantKeys: typed.variantKeys,
|
|
497
351
|
isComponent: true
|
|
498
352
|
};
|
|
499
353
|
}
|
|
@@ -504,24 +358,46 @@ function normalizeKeySource(source) {
|
|
|
504
358
|
* claim styling props.
|
|
505
359
|
*/
|
|
506
360
|
function splitPropsImpl(selfKeys, selfIsComponent, props, sources) {
|
|
507
|
-
const
|
|
361
|
+
const sourcesLength = sources.length;
|
|
508
362
|
const results = [];
|
|
509
363
|
let stylingClaimed = selfIsComponent;
|
|
510
364
|
const selfResult = {};
|
|
511
|
-
|
|
365
|
+
const selfKeysLength = selfKeys.length;
|
|
366
|
+
for (let i = 0; i < selfKeysLength; i++) {
|
|
367
|
+
const key = selfKeys[i];
|
|
368
|
+
if (key !== void 0 && key in props) selfResult[key] = props[key];
|
|
369
|
+
}
|
|
512
370
|
results.push(selfResult);
|
|
513
|
-
|
|
371
|
+
const effectiveKeyArrays = [selfKeys];
|
|
372
|
+
for (let s = 0; s < sourcesLength; s++) {
|
|
373
|
+
const source = sources[s];
|
|
374
|
+
if (source === void 0) continue;
|
|
514
375
|
const sourceResult = {};
|
|
515
376
|
const effectiveKeys = source.isComponent && stylingClaimed ? source.variantKeys : source.keys;
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
377
|
+
const effectiveKeysLength = effectiveKeys.length;
|
|
378
|
+
for (let i = 0; i < effectiveKeysLength; i++) {
|
|
379
|
+
const key = effectiveKeys[i];
|
|
380
|
+
if (key !== void 0 && key in props) sourceResult[key] = props[key];
|
|
519
381
|
}
|
|
520
382
|
results.push(sourceResult);
|
|
383
|
+
effectiveKeyArrays.push(effectiveKeys);
|
|
521
384
|
if (source.isComponent && !stylingClaimed) stylingClaimed = true;
|
|
522
385
|
}
|
|
523
386
|
const rest = {};
|
|
524
|
-
|
|
387
|
+
const propKeys = Object.keys(props);
|
|
388
|
+
const propKeysLength = propKeys.length;
|
|
389
|
+
const groupCount = sourcesLength + 1;
|
|
390
|
+
outer: for (let i = 0; i < propKeysLength; i++) {
|
|
391
|
+
const key = propKeys[i];
|
|
392
|
+
if (key === void 0) continue;
|
|
393
|
+
for (let g = 0; g < groupCount; g++) {
|
|
394
|
+
const arr = effectiveKeyArrays[g];
|
|
395
|
+
if (arr === void 0) continue;
|
|
396
|
+
const arrLength = arr.length;
|
|
397
|
+
for (let j = 0; j < arrLength; j++) if (arr[j] === key) continue outer;
|
|
398
|
+
}
|
|
399
|
+
rest[key] = props[key];
|
|
400
|
+
}
|
|
525
401
|
results.push(rest);
|
|
526
402
|
return results;
|
|
527
403
|
}
|
|
@@ -532,45 +408,75 @@ function splitPropsImpl(selfKeys, selfIsComponent, props, sources) {
|
|
|
532
408
|
* only receive variant props. Arrays receive their listed keys but don't claim
|
|
533
409
|
* styling props. The last element is always the "rest" containing keys not
|
|
534
410
|
* claimed by any source.
|
|
535
|
-
* @example
|
|
536
|
-
* ```ts
|
|
537
|
-
* const [buttonProps, inputProps, rest] = splitProps(
|
|
538
|
-
* props,
|
|
539
|
-
* buttonComponent,
|
|
540
|
-
* inputComponent,
|
|
541
|
-
* );
|
|
542
|
-
* // buttonProps has class/style + button variants
|
|
543
|
-
* // inputProps has only input variants (no class/style)
|
|
544
|
-
* ```
|
|
545
411
|
*/
|
|
546
412
|
const splitProps = ((props, source1, ...sources) => {
|
|
547
413
|
const normalizedSource1 = normalizeKeySource(source1);
|
|
548
|
-
const
|
|
414
|
+
const sourcesLength = sources.length;
|
|
415
|
+
const normalizedSources = [];
|
|
416
|
+
for (let i = 0; i < sourcesLength; i++) normalizedSources.push(normalizeKeySource(sources[i]));
|
|
549
417
|
return splitPropsImpl(normalizedSource1.keys, normalizedSource1.isComponent, props, normalizedSources);
|
|
550
418
|
});
|
|
419
|
+
function buildPrebuiltVariant(variantDef) {
|
|
420
|
+
if (!isRecordObject(variantDef)) return {
|
|
421
|
+
values: null,
|
|
422
|
+
shorthand: extractClassAndStylePrebuilt(variantDef),
|
|
423
|
+
disabledValues: null
|
|
424
|
+
};
|
|
425
|
+
const values = {};
|
|
426
|
+
let disabledValues = null;
|
|
427
|
+
for (const key in variantDef) {
|
|
428
|
+
if (!hasOwn.call(variantDef, key)) continue;
|
|
429
|
+
const value = variantDef[key];
|
|
430
|
+
if (value === null) {
|
|
431
|
+
if (!disabledValues) disabledValues = /* @__PURE__ */ new Set();
|
|
432
|
+
disabledValues.add(key);
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
values[key] = extractClassAndStylePrebuilt(value);
|
|
436
|
+
}
|
|
437
|
+
return {
|
|
438
|
+
values,
|
|
439
|
+
shorthand: null,
|
|
440
|
+
disabledValues
|
|
441
|
+
};
|
|
442
|
+
}
|
|
551
443
|
/**
|
|
552
444
|
* Creates the resolveDefaults function for a component. This function returns
|
|
553
445
|
* only the variants set via setDefaultVariants in the computed function. Used
|
|
554
446
|
* by child components to get parent's computed defaults.
|
|
555
447
|
*/
|
|
556
|
-
function createResolveDefaults(config) {
|
|
448
|
+
function createResolveDefaults(config, staticDefaults) {
|
|
449
|
+
const computed = config.computed;
|
|
450
|
+
const extend = config.extend;
|
|
557
451
|
return (childDefaults, userProps = {}) => {
|
|
558
|
-
const resolvedVariants = {
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
452
|
+
const resolvedVariants = {};
|
|
453
|
+
Object.assign(resolvedVariants, staticDefaults);
|
|
454
|
+
for (const key in childDefaults) {
|
|
455
|
+
if (!hasOwn.call(childDefaults, key)) continue;
|
|
456
|
+
const v = childDefaults[key];
|
|
457
|
+
if (v === void 0) continue;
|
|
458
|
+
resolvedVariants[key] = v;
|
|
459
|
+
}
|
|
460
|
+
for (const key in userProps) {
|
|
461
|
+
if (!hasOwn.call(userProps, key)) continue;
|
|
462
|
+
const v = userProps[key];
|
|
463
|
+
if (v === void 0) continue;
|
|
464
|
+
resolvedVariants[key] = v;
|
|
465
|
+
}
|
|
563
466
|
const computedDefaults = {};
|
|
564
|
-
if (
|
|
467
|
+
if (extend) for (const ext of extend) {
|
|
565
468
|
const meta = getComponentMeta(ext);
|
|
566
469
|
if (!meta) continue;
|
|
567
|
-
|
|
470
|
+
const extDefaults = meta.resolveDefaults(childDefaults, userProps);
|
|
471
|
+
for (const k in extDefaults) if (hasOwn.call(extDefaults, k)) computedDefaults[k] = extDefaults[k];
|
|
568
472
|
}
|
|
569
|
-
if (
|
|
473
|
+
if (computed) computed({
|
|
570
474
|
variants: resolvedVariants,
|
|
571
475
|
setVariants: () => {},
|
|
572
476
|
setDefaultVariants: (newDefaults) => {
|
|
573
|
-
for (const
|
|
477
|
+
for (const key in newDefaults) {
|
|
478
|
+
if (!hasOwn.call(newDefaults, key)) continue;
|
|
479
|
+
const value = newDefaults[key];
|
|
574
480
|
if (userProps[key] !== void 0) continue;
|
|
575
481
|
if (isVariantDisabled(config, key)) continue;
|
|
576
482
|
if (isVariantValueDisabled(config, key, value)) continue;
|
|
@@ -586,106 +492,399 @@ function createResolveDefaults(config) {
|
|
|
586
492
|
/**
|
|
587
493
|
* Creates the cv and cx functions.
|
|
588
494
|
*/
|
|
589
|
-
function create({
|
|
495
|
+
function create({ transformClass = (className) => className } = {}) {
|
|
590
496
|
const cx = (...classes) => transformClass(clsx(...classes));
|
|
591
497
|
const cv = (config = {}) => {
|
|
592
498
|
const variantKeys = collectVariantKeys(config);
|
|
593
499
|
const disabledVariantKeys = collectDisabledVariantKeys(config);
|
|
594
500
|
const disabledVariantValues = collectDisabledVariantValues(config);
|
|
595
|
-
const
|
|
596
|
-
|
|
501
|
+
const hasDisabledVariantKeys = disabledVariantKeys.size > 0;
|
|
502
|
+
const hasDisabledVariantValues = Object.keys(disabledVariantValues).length > 0;
|
|
503
|
+
const hasAnyDisabled = hasDisabledVariantKeys || hasDisabledVariantValues;
|
|
504
|
+
const inputPropsKeys = [
|
|
505
|
+
"class",
|
|
506
|
+
"className",
|
|
597
507
|
"style",
|
|
598
508
|
...variantKeys
|
|
599
509
|
];
|
|
510
|
+
const extend = config.extend;
|
|
511
|
+
const hasExtend = !!extend && extend.length > 0;
|
|
512
|
+
const variants = config.variants;
|
|
513
|
+
const computedVariantsCfg = config.computedVariants;
|
|
514
|
+
const computed = config.computed;
|
|
515
|
+
const baseStyle = config.style;
|
|
516
|
+
const baseClass = config.class === void 0 ? null : config.class;
|
|
517
|
+
const variantEntryNames = [];
|
|
518
|
+
const variantEntryDefs = [];
|
|
519
|
+
if (variants) for (const name in variants) {
|
|
520
|
+
if (!hasOwn.call(variants, name)) continue;
|
|
521
|
+
const variant = variants[name];
|
|
522
|
+
if (variant === null) continue;
|
|
523
|
+
variantEntryNames.push(name);
|
|
524
|
+
variantEntryDefs.push(buildPrebuiltVariant(variant));
|
|
525
|
+
}
|
|
526
|
+
const variantEntryCount = variantEntryNames.length;
|
|
527
|
+
const computedVariantNames = [];
|
|
528
|
+
const computedVariantFns = [];
|
|
529
|
+
if (computedVariantsCfg) for (const name in computedVariantsCfg) {
|
|
530
|
+
if (!hasOwn.call(computedVariantsCfg, name)) continue;
|
|
531
|
+
computedVariantNames.push(name);
|
|
532
|
+
computedVariantFns.push(computedVariantsCfg[name]);
|
|
533
|
+
}
|
|
534
|
+
const computedVariantCount = computedVariantNames.length;
|
|
535
|
+
const staticDefaults = {};
|
|
536
|
+
if (extend) for (const ext of extend) {
|
|
537
|
+
const meta = getComponentMeta(ext);
|
|
538
|
+
if (meta) Object.assign(staticDefaults, meta.staticDefaults);
|
|
539
|
+
}
|
|
540
|
+
if (variants) for (const name in variants) {
|
|
541
|
+
if (!hasOwn.call(variants, name)) continue;
|
|
542
|
+
const variantDef = variants[name];
|
|
543
|
+
if (!isRecordObject(variantDef)) continue;
|
|
544
|
+
if (hasOwn.call(variantDef, "false") && staticDefaults[name] === void 0) staticDefaults[name] = false;
|
|
545
|
+
}
|
|
546
|
+
if (config.defaultVariants) Object.assign(staticDefaults, config.defaultVariants);
|
|
547
|
+
if (hasAnyDisabled) for (const key in staticDefaults) {
|
|
548
|
+
if (!hasOwn.call(staticDefaults, key)) continue;
|
|
549
|
+
if (disabledVariantKeys.has(key)) {
|
|
550
|
+
delete staticDefaults[key];
|
|
551
|
+
continue;
|
|
552
|
+
}
|
|
553
|
+
if (hasDisabledVariantValues) {
|
|
554
|
+
const value = staticDefaults[key];
|
|
555
|
+
const valueKey = getVariantValueKey(value);
|
|
556
|
+
if (valueKey != null && disabledVariantValues[key]?.has(valueKey)) delete staticDefaults[key];
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
const extEntries = extend ? extend : [];
|
|
560
|
+
const extBaseClassesArr = [];
|
|
561
|
+
const extMetas = [];
|
|
562
|
+
if (extend) for (const ext of extend) {
|
|
563
|
+
const meta = getComponentMeta(ext);
|
|
564
|
+
extMetas.push(meta);
|
|
565
|
+
extBaseClassesArr.push(meta?.baseClass ?? "");
|
|
566
|
+
}
|
|
567
|
+
const extCount = extEntries.length;
|
|
568
|
+
function filterDisabledInto(input, out) {
|
|
569
|
+
if (!hasAnyDisabled) {
|
|
570
|
+
for (const key in input) if (hasOwn.call(input, key)) out[key] = input[key];
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
for (const key in input) {
|
|
574
|
+
if (!hasOwn.call(input, key)) continue;
|
|
575
|
+
if (disabledVariantKeys.has(key)) continue;
|
|
576
|
+
const value = input[key];
|
|
577
|
+
if (hasDisabledVariantValues) {
|
|
578
|
+
const valueKey = getVariantValueKey(value);
|
|
579
|
+
if (valueKey != null && disabledVariantValues[key]?.has(valueKey)) continue;
|
|
580
|
+
}
|
|
581
|
+
out[key] = value;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
const resolveDefaultsFn = createResolveDefaults(config, staticDefaults);
|
|
585
|
+
function resolveVariantsHot(propsVariants) {
|
|
586
|
+
const defaults = {};
|
|
587
|
+
Object.assign(defaults, staticDefaults);
|
|
588
|
+
if (hasExtend) for (let i = 0; i < extCount; i++) {
|
|
589
|
+
const meta = extMetas[i];
|
|
590
|
+
if (!meta) continue;
|
|
591
|
+
const extComputed = meta.resolveDefaults(defaults, propsVariants);
|
|
592
|
+
for (const k in extComputed) if (hasOwn.call(extComputed, k)) defaults[k] = extComputed[k];
|
|
593
|
+
}
|
|
594
|
+
for (const k in propsVariants) {
|
|
595
|
+
if (!hasOwn.call(propsVariants, k)) continue;
|
|
596
|
+
const v = propsVariants[k];
|
|
597
|
+
if (v === void 0) continue;
|
|
598
|
+
defaults[k] = v;
|
|
599
|
+
}
|
|
600
|
+
const result = {};
|
|
601
|
+
filterDisabledInto(defaults, result);
|
|
602
|
+
return result;
|
|
603
|
+
}
|
|
600
604
|
const computeResult = (props = {}) => {
|
|
605
|
+
const skipStyleKeysIn = props[SKIP_STYLE_KEYS];
|
|
606
|
+
const skipStyleVariantValuesIn = props[SKIP_STYLE_VARIANT_VALUES];
|
|
607
|
+
const variantProps = {};
|
|
608
|
+
for (let i = 0; i < variantKeys.length; i++) {
|
|
609
|
+
const key = variantKeys[i];
|
|
610
|
+
if (key in props) variantProps[key] = props[key];
|
|
611
|
+
}
|
|
612
|
+
let resolvedVariants = resolveVariantsHot(variantProps);
|
|
613
|
+
let computedClassesArr = null;
|
|
614
|
+
let computedStyleObj = null;
|
|
615
|
+
if (computed) {
|
|
616
|
+
const updatedVariants = {};
|
|
617
|
+
Object.assign(updatedVariants, resolvedVariants);
|
|
618
|
+
const cClasses = [];
|
|
619
|
+
let cStyle = null;
|
|
620
|
+
const result = computed({
|
|
621
|
+
variants: resolvedVariants,
|
|
622
|
+
setVariants: (newVariants) => {
|
|
623
|
+
const filtered = {};
|
|
624
|
+
filterDisabledInto(newVariants, filtered);
|
|
625
|
+
Object.assign(updatedVariants, filtered);
|
|
626
|
+
},
|
|
627
|
+
setDefaultVariants: (newDefaults) => {
|
|
628
|
+
for (const key in newDefaults) {
|
|
629
|
+
if (!hasOwn.call(newDefaults, key)) continue;
|
|
630
|
+
if (variantProps[key] !== void 0) continue;
|
|
631
|
+
if (disabledVariantKeys.has(key)) continue;
|
|
632
|
+
const value = newDefaults[key];
|
|
633
|
+
const valueKey = getVariantValueKey(value);
|
|
634
|
+
if (valueKey != null && disabledVariantValues[key]?.has(valueKey)) continue;
|
|
635
|
+
updatedVariants[key] = value;
|
|
636
|
+
}
|
|
637
|
+
},
|
|
638
|
+
addClass: (className) => {
|
|
639
|
+
cClasses.push(className);
|
|
640
|
+
},
|
|
641
|
+
addStyle: (newStyle) => {
|
|
642
|
+
if (!cStyle) cStyle = {};
|
|
643
|
+
assign(cStyle, newStyle);
|
|
644
|
+
}
|
|
645
|
+
});
|
|
646
|
+
if (result != null) {
|
|
647
|
+
const r = extractClassAndStylePrebuilt(result);
|
|
648
|
+
if (r.class != null) cClasses.push(r.class);
|
|
649
|
+
if (r.style) {
|
|
650
|
+
if (!cStyle) cStyle = {};
|
|
651
|
+
assign(cStyle, r.style);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
const filteredUpdated = {};
|
|
655
|
+
filterDisabledInto(updatedVariants, filteredUpdated);
|
|
656
|
+
resolvedVariants = filteredUpdated;
|
|
657
|
+
computedClassesArr = cClasses;
|
|
658
|
+
computedStyleObj = cStyle;
|
|
659
|
+
}
|
|
660
|
+
const hasSkipKeys = !!skipStyleKeysIn || disabledVariantKeys.size > 0;
|
|
661
|
+
let currentVariantKeys = null;
|
|
662
|
+
if (hasSkipKeys) {
|
|
663
|
+
currentVariantKeys = /* @__PURE__ */ new Set();
|
|
664
|
+
if (skipStyleKeysIn) for (const k of skipStyleKeysIn) currentVariantKeys.add(k);
|
|
665
|
+
for (const k of disabledVariantKeys) currentVariantKeys.add(k);
|
|
666
|
+
}
|
|
667
|
+
let computedVariantKeysSet = null;
|
|
668
|
+
if (hasExtend) {
|
|
669
|
+
if (currentVariantKeys || computedVariantNames.length > 0) {
|
|
670
|
+
computedVariantKeysSet = /* @__PURE__ */ new Set();
|
|
671
|
+
if (currentVariantKeys) for (const k of currentVariantKeys) computedVariantKeysSet.add(k);
|
|
672
|
+
for (let i = 0; i < computedVariantNames.length; i++) computedVariantKeysSet.add(computedVariantNames[i]);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
let computedVariantValues = null;
|
|
676
|
+
const hasInValues = !!skipStyleVariantValuesIn;
|
|
677
|
+
const disabledValuesKeys = Object.keys(disabledVariantValues);
|
|
678
|
+
const hasDisabledValues = disabledValuesKeys.length > 0;
|
|
679
|
+
if (hasExtend && (hasInValues || hasDisabledValues)) {
|
|
680
|
+
computedVariantValues = {};
|
|
681
|
+
if (hasInValues) for (const k in skipStyleVariantValuesIn) {
|
|
682
|
+
if (!hasOwn.call(skipStyleVariantValuesIn, k)) continue;
|
|
683
|
+
const set = /* @__PURE__ */ new Set();
|
|
684
|
+
for (const v of skipStyleVariantValuesIn[k]) set.add(v);
|
|
685
|
+
computedVariantValues[k] = set;
|
|
686
|
+
}
|
|
687
|
+
for (let i = 0; i < disabledValuesKeys.length; i++) {
|
|
688
|
+
const k = disabledValuesKeys[i];
|
|
689
|
+
let bucket = computedVariantValues[k];
|
|
690
|
+
if (!bucket) {
|
|
691
|
+
bucket = /* @__PURE__ */ new Set();
|
|
692
|
+
computedVariantValues[k] = bucket;
|
|
693
|
+
}
|
|
694
|
+
for (const v of disabledVariantValues[k]) bucket.add(v);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
601
697
|
const allClasses = [];
|
|
602
698
|
const allStyle = {};
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
699
|
+
if (hasExtend) {
|
|
700
|
+
const hasComputedVariantKeysSet = !!computedVariantKeysSet && computedVariantKeysSet.size > 0;
|
|
701
|
+
const hasComputedVariantValues = !!computedVariantValues && Object.keys(computedVariantValues).length > 0;
|
|
702
|
+
const hasSkipForExt = hasComputedVariantKeysSet || hasComputedVariantValues;
|
|
703
|
+
const extVariantClasses = [];
|
|
704
|
+
for (let i = 0; i < extCount; i++) {
|
|
705
|
+
const ext = extEntries[i];
|
|
706
|
+
const extBaseClass = extBaseClassesArr[i];
|
|
707
|
+
let propsForExt;
|
|
708
|
+
if (hasSkipForExt) {
|
|
709
|
+
propsForExt = {};
|
|
710
|
+
for (const k in resolvedVariants) if (hasOwn.call(resolvedVariants, k)) propsForExt[k] = resolvedVariants[k];
|
|
711
|
+
if (hasComputedVariantKeysSet) propsForExt[SKIP_STYLE_KEYS] = computedVariantKeysSet;
|
|
712
|
+
if (hasComputedVariantValues) propsForExt[SKIP_STYLE_VARIANT_VALUES] = computedVariantValues;
|
|
713
|
+
} else propsForExt = resolvedVariants;
|
|
714
|
+
const extResult = ext(propsForExt);
|
|
715
|
+
if (extResult.style != null) assign(allStyle, normalizeStyle(extResult.style));
|
|
716
|
+
allClasses.push(extBaseClass);
|
|
717
|
+
const variantPortion = extractVariantClasses("className" in extResult ? extResult.className : extResult.class, extBaseClass);
|
|
718
|
+
if (variantPortion) extVariantClasses.push(variantPortion);
|
|
719
|
+
}
|
|
720
|
+
allClasses.push(baseClass);
|
|
721
|
+
if (baseStyle) assign(allStyle, baseStyle);
|
|
722
|
+
for (let i = 0; i < extVariantClasses.length; i++) allClasses.push(extVariantClasses[i]);
|
|
723
|
+
} else {
|
|
724
|
+
allClasses.push(baseClass);
|
|
725
|
+
if (baseStyle) assign(allStyle, baseStyle);
|
|
726
|
+
}
|
|
727
|
+
for (let i = 0; i < variantEntryCount; i++) {
|
|
728
|
+
const variantName = variantEntryNames[i];
|
|
729
|
+
const variant = variantEntryDefs[i];
|
|
730
|
+
if (currentVariantKeys && currentVariantKeys.has(variantName)) continue;
|
|
731
|
+
const selectedValue = resolvedVariants[variantName];
|
|
732
|
+
if (selectedValue === void 0) continue;
|
|
733
|
+
const selectedKey = getVariantValueKey(selectedValue);
|
|
734
|
+
if (variant.disabledValues && selectedKey != null && variant.disabledValues.has(selectedKey)) continue;
|
|
735
|
+
if (skipStyleVariantValuesIn && selectedKey != null && skipStyleVariantValuesIn[variantName]?.has(selectedKey)) continue;
|
|
736
|
+
if (variant.values) {
|
|
737
|
+
if (selectedKey == null) continue;
|
|
738
|
+
const v = variant.values[selectedKey];
|
|
739
|
+
if (!v) continue;
|
|
740
|
+
if (v.class != null) allClasses.push(v.class);
|
|
741
|
+
if (v.style) assign(allStyle, v.style);
|
|
742
|
+
} else if (variant.shorthand) {
|
|
743
|
+
if (selectedValue === true) {
|
|
744
|
+
const v = variant.shorthand;
|
|
745
|
+
if (v.class != null) allClasses.push(v.class);
|
|
746
|
+
if (v.style) assign(allStyle, v.style);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
for (let i = 0; i < computedVariantCount; i++) {
|
|
751
|
+
const variantName = computedVariantNames[i];
|
|
752
|
+
const fn = computedVariantFns[i];
|
|
753
|
+
if (currentVariantKeys && currentVariantKeys.has(variantName)) continue;
|
|
754
|
+
const selectedValue = resolvedVariants[variantName];
|
|
755
|
+
if (selectedValue === void 0) continue;
|
|
756
|
+
const selectedKey = getVariantValueKey(selectedValue);
|
|
757
|
+
if (skipStyleVariantValuesIn && selectedKey != null && skipStyleVariantValuesIn[variantName]?.has(selectedKey)) continue;
|
|
758
|
+
const computedResult = fn(selectedValue);
|
|
759
|
+
if (computedResult == null) continue;
|
|
760
|
+
const r = extractClassAndStylePrebuilt(computedResult);
|
|
761
|
+
if (r.class != null) allClasses.push(r.class);
|
|
762
|
+
if (r.style) assign(allStyle, r.style);
|
|
763
|
+
}
|
|
764
|
+
if (computedClassesArr) for (let i = 0; i < computedClassesArr.length; i++) allClasses.push(computedClassesArr[i]);
|
|
765
|
+
if (computedStyleObj) assign(allStyle, computedStyleObj);
|
|
626
766
|
if ("class" in props) allClasses.push(props.class);
|
|
627
767
|
if ("className" in props) allClasses.push(props.className);
|
|
628
|
-
|
|
768
|
+
const psv = props.style;
|
|
769
|
+
if (psv != null) {
|
|
770
|
+
if (typeof psv === "string") {
|
|
771
|
+
if (psv.length > 0) assign(allStyle, htmlStyleToStyleValue(psv));
|
|
772
|
+
} else if (typeof psv === "object") {
|
|
773
|
+
let hasAnyKey = false;
|
|
774
|
+
for (const _ in psv) {
|
|
775
|
+
hasAnyKey = true;
|
|
776
|
+
break;
|
|
777
|
+
}
|
|
778
|
+
if (hasAnyKey) assign(allStyle, normalizeStyle(psv));
|
|
779
|
+
}
|
|
780
|
+
}
|
|
629
781
|
return {
|
|
630
782
|
className: cx(...allClasses),
|
|
631
783
|
style: allStyle
|
|
632
784
|
};
|
|
633
785
|
};
|
|
634
|
-
const
|
|
635
|
-
const
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
786
|
+
const getVariants = (variants) => {
|
|
787
|
+
const variantProps = variants ?? {};
|
|
788
|
+
let resolvedVariants = resolveVariantsHot(variantProps);
|
|
789
|
+
if (computed) {
|
|
790
|
+
const updatedVariants = {};
|
|
791
|
+
Object.assign(updatedVariants, resolvedVariants);
|
|
792
|
+
computed({
|
|
793
|
+
variants: resolvedVariants,
|
|
794
|
+
setVariants: (newVariants) => {
|
|
795
|
+
const filtered = {};
|
|
796
|
+
filterDisabledInto(newVariants, filtered);
|
|
797
|
+
Object.assign(updatedVariants, filtered);
|
|
798
|
+
},
|
|
799
|
+
setDefaultVariants: (newDefaults) => {
|
|
800
|
+
for (const key in newDefaults) {
|
|
801
|
+
if (!hasOwn.call(newDefaults, key)) continue;
|
|
802
|
+
if (variantProps[key] !== void 0) continue;
|
|
803
|
+
if (disabledVariantKeys.has(key)) continue;
|
|
804
|
+
const value = newDefaults[key];
|
|
805
|
+
const valueKey = getVariantValueKey(value);
|
|
806
|
+
if (valueKey != null && disabledVariantValues[key]?.has(valueKey)) continue;
|
|
807
|
+
updatedVariants[key] = value;
|
|
808
|
+
}
|
|
809
|
+
},
|
|
810
|
+
addClass: () => {},
|
|
811
|
+
addStyle: () => {}
|
|
812
|
+
});
|
|
813
|
+
const filteredUpdated = {};
|
|
814
|
+
filterDisabledInto(updatedVariants, filteredUpdated);
|
|
815
|
+
resolvedVariants = filteredUpdated;
|
|
816
|
+
}
|
|
817
|
+
return resolvedVariants;
|
|
818
|
+
};
|
|
819
|
+
const computedBaseClass = cx(...extBaseClassesArr, config.class);
|
|
820
|
+
const classFn = (props = {}) => {
|
|
821
|
+
return computeResult(props).className;
|
|
822
|
+
};
|
|
823
|
+
const meta = {
|
|
824
|
+
baseClass: computedBaseClass,
|
|
825
|
+
staticDefaults,
|
|
826
|
+
resolveDefaults: resolveDefaultsFn
|
|
827
|
+
};
|
|
828
|
+
const initComponent = (c, keys, style) => {
|
|
829
|
+
c.class = classFn;
|
|
830
|
+
c.style = style;
|
|
831
|
+
c.getVariants = getVariants;
|
|
832
|
+
c.keys = keys;
|
|
833
|
+
c.variantKeys = variantKeys;
|
|
834
|
+
c.propKeys = keys;
|
|
835
|
+
setComponentMeta(c, meta);
|
|
836
|
+
return c;
|
|
837
|
+
};
|
|
838
|
+
const defaultComponent = ((props = {}) => {
|
|
839
|
+
const { className, style } = computeResult(props);
|
|
840
|
+
return {
|
|
841
|
+
class: className,
|
|
842
|
+
style
|
|
653
843
|
};
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
844
|
+
});
|
|
845
|
+
initComponent(defaultComponent, inputPropsKeys, (props = {}) => {
|
|
846
|
+
return computeResult(props).style;
|
|
847
|
+
});
|
|
848
|
+
const jsxComponent = ((props = {}) => {
|
|
849
|
+
const { className, style } = computeResult(props);
|
|
850
|
+
return {
|
|
851
|
+
className,
|
|
852
|
+
style: styleValueToJSXStyle(style)
|
|
659
853
|
};
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
854
|
+
});
|
|
855
|
+
initComponent(jsxComponent, [
|
|
856
|
+
"className",
|
|
857
|
+
"style",
|
|
858
|
+
...variantKeys
|
|
859
|
+
], (props = {}) => styleValueToJSXStyle(computeResult(props).style));
|
|
860
|
+
const htmlComponent = ((props = {}) => {
|
|
861
|
+
const { className, style } = computeResult(props);
|
|
862
|
+
return {
|
|
863
|
+
class: className,
|
|
864
|
+
style: styleValueToHTMLStyle(style)
|
|
664
865
|
};
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
component.htmlObj = htmlObjComponent;
|
|
688
|
-
return component;
|
|
866
|
+
});
|
|
867
|
+
initComponent(htmlComponent, [
|
|
868
|
+
"class",
|
|
869
|
+
"style",
|
|
870
|
+
...variantKeys
|
|
871
|
+
], (props = {}) => styleValueToHTMLStyle(computeResult(props).style));
|
|
872
|
+
const htmlObjComponent = ((props = {}) => {
|
|
873
|
+
const { className, style } = computeResult(props);
|
|
874
|
+
return {
|
|
875
|
+
class: className,
|
|
876
|
+
style: styleValueToHTMLObjStyle(style)
|
|
877
|
+
};
|
|
878
|
+
});
|
|
879
|
+
initComponent(htmlObjComponent, [
|
|
880
|
+
"class",
|
|
881
|
+
"style",
|
|
882
|
+
...variantKeys
|
|
883
|
+
], (props = {}) => styleValueToHTMLObjStyle(computeResult(props).style));
|
|
884
|
+
defaultComponent.jsx = jsxComponent;
|
|
885
|
+
defaultComponent.html = htmlComponent;
|
|
886
|
+
defaultComponent.htmlObj = htmlObjComponent;
|
|
887
|
+
return defaultComponent;
|
|
689
888
|
};
|
|
690
889
|
return {
|
|
691
890
|
cv,
|