clava 0.2.0 → 0.2.2

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