clava 0.2.1 → 0.2.3

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,6 +1,10 @@
1
1
  import clsx from "clsx";
2
2
  //#region src/utils.ts
3
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;
7
+ }
4
8
  /**
5
9
  * Converts a hyphenated CSS property name to camelCase.
6
10
  * @example
@@ -9,8 +13,28 @@ const hasOwn$1 = Object.prototype.hasOwnProperty;
9
13
  */
10
14
  function hyphenToCamel(str) {
11
15
  if (str.length >= 2 && str.charCodeAt(0) === 45 && str.charCodeAt(1) === 45) return str;
12
- if (str.indexOf("-") === -1) return str;
13
- return str.replace(/-([a-z])/gi, (_, letter) => letter.toUpperCase());
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);
14
38
  }
15
39
  /**
16
40
  * Converts a camelCase CSS property name to hyphenated form.
@@ -20,7 +44,18 @@ function hyphenToCamel(str) {
20
44
  */
21
45
  function camelToHyphen(str) {
22
46
  if (str.length >= 2 && str.charCodeAt(0) === 45 && str.charCodeAt(1) === 45) return str;
23
- return str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
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);
24
59
  }
25
60
  /**
26
61
  * Parses a length value, adding "px" if it's a number.
@@ -187,25 +222,14 @@ function isHTMLObjStyle(style) {
187
222
  //#endregion
188
223
  //#region src/index.ts
189
224
  const META_KEY = "__meta";
190
- const SKIP_STYLE_KEYS = Symbol("skipStyleKeys");
191
- const SKIP_STYLE_VARIANT_VALUES = Symbol("skipStyleVariantValues");
192
225
  const hasOwn = Object.prototype.hasOwnProperty;
226
+ const EMPTY_DEFAULTS = Object.freeze({});
193
227
  function getComponentMeta(component) {
194
228
  return component[META_KEY];
195
229
  }
196
230
  function setComponentMeta(component, meta) {
197
231
  component[META_KEY] = meta;
198
232
  }
199
- /**
200
- * Mutates target by assigning all properties from source. Avoids object spread
201
- * overhead in hot paths where we're building up a result object.
202
- */
203
- function assign(target, source) {
204
- for (const key in source) {
205
- if (!hasOwn.call(source, key)) continue;
206
- target[key] = source[key];
207
- }
208
- }
209
233
  function isRecordObject(value) {
210
234
  if (typeof value !== "object") return false;
211
235
  if (value == null) return false;
@@ -317,18 +341,6 @@ function collectDisabledVariantValues(config) {
317
341
  }
318
342
  return values;
319
343
  }
320
- /**
321
- * Extracts classes from fullClass that are not in baseClass. Uses string
322
- * comparison optimization: if fullClass starts with baseClass, just take the
323
- * suffix.
324
- */
325
- function extractVariantClasses(fullClass, baseClass) {
326
- if (!fullClass) return "";
327
- if (!baseClass) return fullClass;
328
- if (fullClass.startsWith(baseClass)) return fullClass.slice(baseClass.length).trim();
329
- const baseClassSet = new Set(baseClass.split(" ").filter(Boolean));
330
- return fullClass.split(" ").filter((c) => c && !baseClassSet.has(c)).join(" ");
331
- }
332
344
  const EMPTY_SOURCE = {
333
345
  keys: [],
334
346
  variantKeys: [],
@@ -370,8 +382,7 @@ function splitPropsImpl(selfKeys, selfIsComponent, props, sources) {
370
382
  results.push(selfResult);
371
383
  const effectiveKeyArrays = [selfKeys];
372
384
  for (let s = 0; s < sourcesLength; s++) {
373
- const source = sources[s];
374
- if (source === void 0) continue;
385
+ const source = normalizeKeySource(sources[s]);
375
386
  const sourceResult = {};
376
387
  const effectiveKeys = source.isComponent && stylingClaimed ? source.variantKeys : source.keys;
377
388
  const effectiveKeysLength = effectiveKeys.length;
@@ -411,10 +422,7 @@ function splitPropsImpl(selfKeys, selfIsComponent, props, sources) {
411
422
  */
412
423
  const splitProps = ((props, source1, ...sources) => {
413
424
  const normalizedSource1 = normalizeKeySource(source1);
414
- const sourcesLength = sources.length;
415
- const normalizedSources = [];
416
- for (let i = 0; i < sourcesLength; i++) normalizedSources.push(normalizeKeySource(sources[i]));
417
- return splitPropsImpl(normalizedSource1.keys, normalizedSource1.isComponent, props, normalizedSources);
425
+ return splitPropsImpl(normalizedSource1.keys, normalizedSource1.isComponent, props, sources);
418
426
  });
419
427
  function buildPrebuiltVariant(variantDef) {
420
428
  if (!isRecordObject(variantDef)) return {
@@ -441,61 +449,13 @@ function buildPrebuiltVariant(variantDef) {
441
449
  };
442
450
  }
443
451
  /**
444
- * Creates the resolveDefaults function for a component. This function returns
445
- * only the variants set via setDefaultVariants in the computed function. Used
446
- * by child components to get parent's computed defaults.
447
- */
448
- function createResolveDefaults(config, staticDefaults) {
449
- const computed = config.computed;
450
- const extend = config.extend;
451
- return (childDefaults, userProps = {}) => {
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
- }
466
- const computedDefaults = {};
467
- if (extend) for (const ext of extend) {
468
- const meta = getComponentMeta(ext);
469
- if (!meta) continue;
470
- const extDefaults = meta.resolveDefaults(childDefaults, userProps);
471
- for (const k in extDefaults) if (hasOwn.call(extDefaults, k)) computedDefaults[k] = extDefaults[k];
472
- }
473
- if (computed) computed({
474
- variants: resolvedVariants,
475
- setVariants: () => {},
476
- setDefaultVariants: (newDefaults) => {
477
- for (const key in newDefaults) {
478
- if (!hasOwn.call(newDefaults, key)) continue;
479
- const value = newDefaults[key];
480
- if (userProps[key] !== void 0) continue;
481
- if (isVariantDisabled(config, key)) continue;
482
- if (isVariantValueDisabled(config, key, value)) continue;
483
- computedDefaults[key] = value;
484
- }
485
- },
486
- addClass: () => {},
487
- addStyle: () => {}
488
- });
489
- return computedDefaults;
490
- };
491
- }
492
- /**
493
452
  * Creates the cv and cx functions.
494
453
  */
495
454
  function create({ transformClass = (className) => className } = {}) {
496
455
  const cx = (...classes) => transformClass(clsx(...classes));
497
456
  const cv = (config = {}) => {
498
457
  const variantKeys = collectVariantKeys(config);
458
+ const variantKeysLength = variantKeys.length;
499
459
  const disabledVariantKeys = collectDisabledVariantKeys(config);
500
460
  const disabledVariantValues = collectDisabledVariantValues(config);
501
461
  const hasDisabledVariantKeys = disabledVariantKeys.size > 0;
@@ -513,7 +473,7 @@ function create({ transformClass = (className) => className } = {}) {
513
473
  const computedVariantsCfg = config.computedVariants;
514
474
  const computed = config.computed;
515
475
  const baseStyle = config.style;
516
- const baseClass = config.class === void 0 ? null : config.class;
476
+ const hasBaseStyle = !!baseStyle;
517
477
  const variantEntryNames = [];
518
478
  const variantEntryDefs = [];
519
479
  if (variants) for (const name in variants) {
@@ -556,15 +516,32 @@ function create({ transformClass = (className) => className } = {}) {
556
516
  if (valueKey != null && disabledVariantValues[key]?.has(valueKey)) delete staticDefaults[key];
557
517
  }
558
518
  }
559
- const extEntries = extend ? extend : [];
560
- const extBaseClassesArr = [];
561
519
  const extMetas = [];
520
+ const extBaseClassesArr = [];
521
+ const extIsolated = [];
522
+ let hasIsolatedExt = false;
562
523
  if (extend) for (const ext of extend) {
563
524
  const meta = getComponentMeta(ext);
525
+ if (!meta) continue;
564
526
  extMetas.push(meta);
565
- extBaseClassesArr.push(meta?.baseClass ?? "");
527
+ const isolated = meta.transformClass !== transformClass;
528
+ extIsolated.push(isolated);
529
+ if (isolated) {
530
+ hasIsolatedExt = true;
531
+ extBaseClassesArr.push(meta.transformClass(meta.baseClass));
532
+ } else extBaseClassesArr.push(meta.baseClass);
533
+ }
534
+ const extCount = extMetas.length;
535
+ const extMetasWithResolveDefaults = [];
536
+ for (let i = 0; i < extCount; i++) if (extMetas[i].resolveDefaults) extMetasWithResolveDefaults.push(extMetas[i]);
537
+ const extMetasWithResolveDefaultsCount = extMetasWithResolveDefaults.length;
538
+ let staticExtSkipKeys = null;
539
+ if (hasDisabledVariantKeys || computedVariantCount > 0) {
540
+ staticExtSkipKeys = /* @__PURE__ */ new Set();
541
+ for (const k of disabledVariantKeys) staticExtSkipKeys.add(k);
542
+ for (let i = 0; i < computedVariantCount; i++) staticExtSkipKeys.add(computedVariantNames[i]);
566
543
  }
567
- const extCount = extEntries.length;
544
+ const staticExtSkipValues = hasDisabledVariantValues ? disabledVariantValues : null;
568
545
  function filterDisabledInto(input, out) {
569
546
  if (!hasAnyDisabled) {
570
547
  for (const key in input) if (hasOwn.call(input, key)) out[key] = input[key];
@@ -581,15 +558,63 @@ function create({ transformClass = (className) => className } = {}) {
581
558
  out[key] = value;
582
559
  }
583
560
  }
584
- const resolveDefaultsFn = createResolveDefaults(config, staticDefaults);
561
+ const resolveDefaultsFn = computed || extMetasWithResolveDefaultsCount > 0 ? (childDefaults, userProps = EMPTY_DEFAULTS) => {
562
+ const resolvedVariants = {};
563
+ Object.assign(resolvedVariants, staticDefaults);
564
+ for (const key in childDefaults) {
565
+ if (!hasOwn.call(childDefaults, key)) continue;
566
+ const v = childDefaults[key];
567
+ if (v === void 0) continue;
568
+ resolvedVariants[key] = v;
569
+ }
570
+ for (const key in userProps) {
571
+ if (!hasOwn.call(userProps, key)) continue;
572
+ const v = userProps[key];
573
+ if (v === void 0) continue;
574
+ resolvedVariants[key] = v;
575
+ }
576
+ const computedDefaults = {};
577
+ for (let i = 0; i < extMetasWithResolveDefaultsCount; i++) {
578
+ const extDefaults = extMetasWithResolveDefaults[i].resolveDefaults(childDefaults, userProps);
579
+ for (const k in extDefaults) {
580
+ if (!hasOwn.call(extDefaults, k)) continue;
581
+ computedDefaults[k] = extDefaults[k];
582
+ }
583
+ }
584
+ if (computed) {
585
+ const ownVariants = {};
586
+ for (let i = 0; i < variantKeysLength; i++) {
587
+ const k = variantKeys[i];
588
+ if (hasOwn.call(resolvedVariants, k)) ownVariants[k] = resolvedVariants[k];
589
+ }
590
+ computed({
591
+ variants: ownVariants,
592
+ setVariants: noop,
593
+ setDefaultVariants: (newDefaults) => {
594
+ for (const key in newDefaults) {
595
+ if (!hasOwn.call(newDefaults, key)) continue;
596
+ const value = newDefaults[key];
597
+ if (userProps[key] !== void 0) continue;
598
+ if (isVariantDisabled(config, key)) continue;
599
+ if (isVariantValueDisabled(config, key, value)) continue;
600
+ computedDefaults[key] = value;
601
+ }
602
+ },
603
+ addClass: noop,
604
+ addStyle: noop
605
+ });
606
+ }
607
+ return computedDefaults;
608
+ } : null;
585
609
  function resolveVariantsHot(propsVariants) {
586
610
  const defaults = {};
587
611
  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];
612
+ for (let i = 0; i < extMetasWithResolveDefaultsCount; i++) {
613
+ const extComputed = extMetasWithResolveDefaults[i].resolveDefaults(defaults, propsVariants);
614
+ for (const k in extComputed) {
615
+ if (!hasOwn.call(extComputed, k)) continue;
616
+ defaults[k] = extComputed[k];
617
+ }
593
618
  }
594
619
  for (const k in propsVariants) {
595
620
  if (!hasOwn.call(propsVariants, k)) continue;
@@ -597,194 +622,222 @@ function create({ transformClass = (className) => className } = {}) {
597
622
  if (v === void 0) continue;
598
623
  defaults[k] = v;
599
624
  }
625
+ if (!hasAnyDisabled) return defaults;
600
626
  const result = {};
601
627
  filterDisabledInto(defaults, result);
602
628
  return result;
603
629
  }
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;
630
+ const compute = (resolved, userVariantProps, skipKeys, skipValues, classesOut, styleOut) => {
631
+ let workingResolved = resolved;
632
+ let cClasses = null;
633
+ let cStyle = null;
615
634
  if (computed) {
616
- const updatedVariants = {};
617
- Object.assign(updatedVariants, resolvedVariants);
618
- const cClasses = [];
619
- let cStyle = null;
635
+ const ownVariants = {};
636
+ for (let i = 0; i < variantKeysLength; i++) {
637
+ const k = variantKeys[i];
638
+ if (hasOwn.call(resolved, k)) ownVariants[k] = resolved[k];
639
+ }
640
+ let updatedVariants = null;
641
+ const localCClasses = [];
642
+ let localCStyle = null;
643
+ const ensureUpdated = () => {
644
+ if (updatedVariants) return updatedVariants;
645
+ const u = {};
646
+ Object.assign(u, ownVariants);
647
+ updatedVariants = u;
648
+ return u;
649
+ };
620
650
  const result = computed({
621
- variants: resolvedVariants,
651
+ variants: ownVariants,
622
652
  setVariants: (newVariants) => {
623
- const filtered = {};
624
- filterDisabledInto(newVariants, filtered);
625
- Object.assign(updatedVariants, filtered);
653
+ if (!hasAnyDisabled) {
654
+ Object.assign(ensureUpdated(), newVariants);
655
+ return;
656
+ }
657
+ for (const key in newVariants) {
658
+ if (!hasOwn.call(newVariants, key)) continue;
659
+ if (disabledVariantKeys.has(key)) continue;
660
+ const value = newVariants[key];
661
+ if (hasDisabledVariantValues) {
662
+ const valueKey = getVariantValueKey(value);
663
+ if (valueKey != null && disabledVariantValues[key]?.has(valueKey)) continue;
664
+ }
665
+ ensureUpdated()[key] = value;
666
+ }
626
667
  },
627
668
  setDefaultVariants: (newDefaults) => {
628
669
  for (const key in newDefaults) {
629
670
  if (!hasOwn.call(newDefaults, key)) continue;
630
- if (variantProps[key] !== void 0) continue;
631
- if (disabledVariantKeys.has(key)) continue;
671
+ if (userVariantProps[key] !== void 0) continue;
632
672
  const value = newDefaults[key];
633
- const valueKey = getVariantValueKey(value);
634
- if (valueKey != null && disabledVariantValues[key]?.has(valueKey)) continue;
635
- updatedVariants[key] = value;
673
+ if (hasAnyDisabled) {
674
+ if (disabledVariantKeys.has(key)) continue;
675
+ const valueKey = getVariantValueKey(value);
676
+ if (valueKey != null && disabledVariantValues[key]?.has(valueKey)) continue;
677
+ }
678
+ ensureUpdated()[key] = value;
636
679
  }
637
680
  },
638
681
  addClass: (className) => {
639
- cClasses.push(className);
682
+ localCClasses.push(className);
640
683
  },
641
684
  addStyle: (newStyle) => {
642
- if (!cStyle) cStyle = {};
643
- assign(cStyle, newStyle);
685
+ if (!localCStyle) localCStyle = {};
686
+ Object.assign(localCStyle, newStyle);
644
687
  }
645
688
  });
646
689
  if (result != null) {
647
690
  const r = extractClassAndStylePrebuilt(result);
648
- if (r.class != null) cClasses.push(r.class);
691
+ if (r.class != null) localCClasses.push(r.class);
649
692
  if (r.style) {
650
- if (!cStyle) cStyle = {};
651
- assign(cStyle, r.style);
693
+ if (!localCStyle) localCStyle = {};
694
+ Object.assign(localCStyle, r.style);
652
695
  }
653
696
  }
654
- const filteredUpdated = {};
655
- filterDisabledInto(updatedVariants, filteredUpdated);
656
- resolvedVariants = filteredUpdated;
657
- computedClassesArr = cClasses;
658
- computedStyleObj = cStyle;
697
+ cClasses = localCClasses;
698
+ cStyle = localCStyle;
699
+ if (updatedVariants) if (hasAnyDisabled) {
700
+ const filteredUpdated = {};
701
+ filterDisabledInto(updatedVariants, filteredUpdated);
702
+ workingResolved = filteredUpdated;
703
+ } else workingResolved = updatedVariants;
659
704
  }
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);
705
+ let extSkipKeys;
706
+ if (skipKeys === null) extSkipKeys = staticExtSkipKeys;
707
+ else if (staticExtSkipKeys === null) extSkipKeys = skipKeys;
708
+ else {
709
+ extSkipKeys = new Set(skipKeys);
710
+ for (const k of staticExtSkipKeys) extSkipKeys.add(k);
666
711
  }
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]);
712
+ let extSkipVals;
713
+ if (skipValues === null) extSkipVals = staticExtSkipValues;
714
+ else if (staticExtSkipValues === null) extSkipVals = skipValues;
715
+ else {
716
+ extSkipVals = {};
717
+ for (const k in skipValues) extSkipVals[k] = skipValues[k];
718
+ for (const k in staticExtSkipValues) {
719
+ const existing = extSkipVals[k];
720
+ if (existing) {
721
+ const merged = new Set(existing);
722
+ for (const v of staticExtSkipValues[k]) merged.add(v);
723
+ extSkipVals[k] = merged;
724
+ } else extSkipVals[k] = staticExtSkipValues[k];
673
725
  }
674
726
  }
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;
727
+ if (hasExtend) for (let i = 0; i < extCount; i++) if (hasIsolatedExt && extIsolated[i]) {
728
+ const extClasses = [];
729
+ extMetas[i].compute(workingResolved, workingResolved, extSkipKeys, extSkipVals, extClasses, styleOut);
730
+ if (extClasses.length > 0) {
731
+ const joined = clsx(extClasses);
732
+ if (joined.length > 0) classesOut.push(extMetas[i].transformClass(joined));
686
733
  }
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
- }
697
- const allClasses = [];
698
- const allStyle = {};
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
- }
734
+ } else extMetas[i].compute(workingResolved, workingResolved, extSkipKeys, extSkipVals, classesOut, styleOut);
735
+ if (hasBaseStyle) Object.assign(styleOut, baseStyle);
736
+ const ownSkipKeys = skipKeys;
737
+ const ownSkipValues = skipValues;
727
738
  for (let i = 0; i < variantEntryCount; i++) {
728
739
  const variantName = variantEntryNames[i];
729
- const variant = variantEntryDefs[i];
730
- if (currentVariantKeys && currentVariantKeys.has(variantName)) continue;
731
- const selectedValue = resolvedVariants[variantName];
740
+ if (ownSkipKeys && ownSkipKeys.has(variantName)) continue;
741
+ const selectedValue = workingResolved[variantName];
732
742
  if (selectedValue === void 0) continue;
733
743
  const selectedKey = getVariantValueKey(selectedValue);
744
+ const variant = variantEntryDefs[i];
734
745
  if (variant.disabledValues && selectedKey != null && variant.disabledValues.has(selectedKey)) continue;
735
- if (skipStyleVariantValuesIn && selectedKey != null && skipStyleVariantValuesIn[variantName]?.has(selectedKey)) continue;
746
+ if (ownSkipValues && selectedKey != null && ownSkipValues[variantName]?.has(selectedKey)) continue;
736
747
  if (variant.values) {
737
748
  if (selectedKey == null) continue;
738
749
  const v = variant.values[selectedKey];
739
750
  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
- }
751
+ if (v.class != null) classesOut.push(v.class);
752
+ if (v.style) Object.assign(styleOut, v.style);
753
+ } else if (variant.shorthand && selectedValue === true) {
754
+ const v = variant.shorthand;
755
+ if (v.class != null) classesOut.push(v.class);
756
+ if (v.style) Object.assign(styleOut, v.style);
748
757
  }
749
758
  }
750
759
  for (let i = 0; i < computedVariantCount; i++) {
751
760
  const variantName = computedVariantNames[i];
752
- const fn = computedVariantFns[i];
753
- if (currentVariantKeys && currentVariantKeys.has(variantName)) continue;
754
- const selectedValue = resolvedVariants[variantName];
761
+ if (ownSkipKeys && ownSkipKeys.has(variantName)) continue;
762
+ const selectedValue = workingResolved[variantName];
755
763
  if (selectedValue === void 0) continue;
756
764
  const selectedKey = getVariantValueKey(selectedValue);
757
- if (skipStyleVariantValuesIn && selectedKey != null && skipStyleVariantValuesIn[variantName]?.has(selectedKey)) continue;
765
+ if (ownSkipValues && selectedKey != null && ownSkipValues[variantName]?.has(selectedKey)) continue;
766
+ const fn = computedVariantFns[i];
758
767
  const computedResult = fn(selectedValue);
759
768
  if (computedResult == null) continue;
760
769
  const r = extractClassAndStylePrebuilt(computedResult);
761
- if (r.class != null) allClasses.push(r.class);
762
- if (r.style) assign(allStyle, r.style);
770
+ if (r.class != null) classesOut.push(r.class);
771
+ if (r.style) Object.assign(styleOut, r.style);
763
772
  }
764
- if (computedClassesArr) for (let i = 0; i < computedClassesArr.length; i++) allClasses.push(computedClassesArr[i]);
765
- if (computedStyleObj) assign(allStyle, computedStyleObj);
766
- if ("class" in props) allClasses.push(props.class);
767
- if ("className" in props) allClasses.push(props.className);
768
- const psv = props.style;
773
+ if (cClasses) for (let i = 0; i < cClasses.length; i++) classesOut.push(cClasses[i]);
774
+ if (cStyle) Object.assign(styleOut, cStyle);
775
+ };
776
+ const computeResult = (props = EMPTY_DEFAULTS) => {
777
+ const propsRecord = props;
778
+ let resolved = {};
779
+ Object.assign(resolved, staticDefaults);
780
+ let userVariantProps;
781
+ if (extMetasWithResolveDefaultsCount > 0) {
782
+ const variantProps = {};
783
+ for (let i = 0; i < variantKeysLength; i++) {
784
+ const key = variantKeys[i];
785
+ if (hasOwn.call(propsRecord, key)) variantProps[key] = propsRecord[key];
786
+ }
787
+ for (let i = 0; i < extMetasWithResolveDefaultsCount; i++) {
788
+ const extComputed = extMetasWithResolveDefaults[i].resolveDefaults(resolved, variantProps);
789
+ for (const k in extComputed) {
790
+ if (!hasOwn.call(extComputed, k)) continue;
791
+ resolved[k] = extComputed[k];
792
+ }
793
+ }
794
+ for (const k in variantProps) {
795
+ if (!hasOwn.call(variantProps, k)) continue;
796
+ const v = variantProps[k];
797
+ if (v === void 0) continue;
798
+ resolved[k] = v;
799
+ }
800
+ userVariantProps = variantProps;
801
+ } else {
802
+ for (let i = 0; i < variantKeysLength; i++) {
803
+ const key = variantKeys[i];
804
+ if (!hasOwn.call(propsRecord, key)) continue;
805
+ const v = propsRecord[key];
806
+ if (v === void 0) continue;
807
+ resolved[key] = v;
808
+ }
809
+ userVariantProps = propsRecord;
810
+ }
811
+ if (hasAnyDisabled) {
812
+ const filtered = {};
813
+ filterDisabledInto(resolved, filtered);
814
+ resolved = filtered;
815
+ }
816
+ const allClasses = [computedBaseClass];
817
+ const style = {};
818
+ compute(resolved, userVariantProps, null, null, allClasses, style);
819
+ if ("class" in propsRecord) allClasses.push(propsRecord.class);
820
+ if ("className" in propsRecord) allClasses.push(propsRecord.className);
821
+ const psv = propsRecord.style;
769
822
  if (psv != null) {
770
823
  if (typeof psv === "string") {
771
- if (psv.length > 0) assign(allStyle, htmlStyleToStyleValue(psv));
824
+ if (psv.length > 0) Object.assign(style, htmlStyleToStyleValue(psv));
772
825
  } else if (typeof psv === "object") {
773
826
  let hasAnyKey = false;
774
827
  for (const _ in psv) {
775
828
  hasAnyKey = true;
776
829
  break;
777
830
  }
778
- if (hasAnyKey) assign(allStyle, normalizeStyle(psv));
831
+ if (hasAnyKey) Object.assign(style, normalizeStyle(psv));
779
832
  }
780
833
  }
781
834
  return {
782
- className: cx(...allClasses),
783
- style: allStyle
835
+ className: transformClass(clsx(allClasses)),
836
+ style
784
837
  };
785
838
  };
786
839
  const getVariants = (variants) => {
787
- const variantProps = variants ?? {};
840
+ const variantProps = variants ?? EMPTY_DEFAULTS;
788
841
  let resolvedVariants = resolveVariantsHot(variantProps);
789
842
  if (computed) {
790
843
  const updatedVariants = {};
@@ -792,38 +845,55 @@ function create({ transformClass = (className) => className } = {}) {
792
845
  computed({
793
846
  variants: resolvedVariants,
794
847
  setVariants: (newVariants) => {
795
- const filtered = {};
796
- filterDisabledInto(newVariants, filtered);
797
- Object.assign(updatedVariants, filtered);
848
+ if (!hasAnyDisabled) {
849
+ Object.assign(updatedVariants, newVariants);
850
+ return;
851
+ }
852
+ for (const key in newVariants) {
853
+ if (!hasOwn.call(newVariants, key)) continue;
854
+ if (disabledVariantKeys.has(key)) continue;
855
+ const value = newVariants[key];
856
+ if (hasDisabledVariantValues) {
857
+ const valueKey = getVariantValueKey(value);
858
+ if (valueKey != null && disabledVariantValues[key]?.has(valueKey)) continue;
859
+ }
860
+ updatedVariants[key] = value;
861
+ }
798
862
  },
799
863
  setDefaultVariants: (newDefaults) => {
800
864
  for (const key in newDefaults) {
801
865
  if (!hasOwn.call(newDefaults, key)) continue;
802
866
  if (variantProps[key] !== void 0) continue;
803
- if (disabledVariantKeys.has(key)) continue;
804
867
  const value = newDefaults[key];
805
- const valueKey = getVariantValueKey(value);
806
- if (valueKey != null && disabledVariantValues[key]?.has(valueKey)) continue;
868
+ if (hasAnyDisabled) {
869
+ if (disabledVariantKeys.has(key)) continue;
870
+ const valueKey = getVariantValueKey(value);
871
+ if (valueKey != null && disabledVariantValues[key]?.has(valueKey)) continue;
872
+ }
807
873
  updatedVariants[key] = value;
808
874
  }
809
875
  },
810
- addClass: () => {},
811
- addStyle: () => {}
876
+ addClass: noop,
877
+ addStyle: noop
812
878
  });
813
- const filteredUpdated = {};
814
- filterDisabledInto(updatedVariants, filteredUpdated);
815
- resolvedVariants = filteredUpdated;
879
+ if (hasAnyDisabled) {
880
+ const filteredUpdated = {};
881
+ filterDisabledInto(updatedVariants, filteredUpdated);
882
+ resolvedVariants = filteredUpdated;
883
+ } else resolvedVariants = updatedVariants;
816
884
  }
817
885
  return resolvedVariants;
818
886
  };
819
- const computedBaseClass = cx(...extBaseClassesArr, config.class);
887
+ const computedBaseClass = clsx(...extBaseClassesArr, config.class);
820
888
  const classFn = (props = {}) => {
821
889
  return computeResult(props).className;
822
890
  };
823
891
  const meta = {
824
892
  baseClass: computedBaseClass,
825
893
  staticDefaults,
826
- resolveDefaults: resolveDefaultsFn
894
+ resolveDefaults: resolveDefaultsFn,
895
+ compute,
896
+ transformClass
827
897
  };
828
898
  const initComponent = (c, keys, style) => {
829
899
  c.class = classFn;
@@ -891,6 +961,7 @@ function create({ transformClass = (className) => className } = {}) {
891
961
  cx
892
962
  };
893
963
  }
964
+ function noop() {}
894
965
  const { cv, cx } = create();
895
966
  //#endregion
896
967
  export { create, cv, cx, splitProps };