clava 0.2.2 → 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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # clava
2
2
 
3
+ ## 0.2.3
4
+
5
+ ### Improved runtime performance of `extend` chains and `getVariants` in `cv`
6
+
7
+ Extending components no longer round-trips through the public component (`clsx` join → regex split to recover variant classes) — extends now contribute classes and styles directly via an internal compute path, avoiding intermediate string parsing and array allocations on every render.
8
+
9
+ Per-render benchmarks improve roughly 2.5× for extended components and 2.7× for `getVariants`, with no public API changes.
10
+
11
+ ### Fixed `computed`'s `ctx.variants` leaking foreign variant keys when extended
12
+
13
+ When the same `cv` was used as an `extend` by a parent component that defined additional variant keys, the `computed` callback's `ctx.variants` could include those parent-only keys. It is now filtered to the component's own `variantKeys`, matching the public `VariantValues<V>` contract — both during render and during the `setDefaultVariants` pass that backs `getVariants`.
14
+
15
+ ### Fixed non-idempotent `transformClass` compounding across `extend` chains
16
+
17
+ A non-idempotent `transformClass` (e.g. one that prefixes every class word) was applied multiple times to base classes contributed by extended components — once per level in the extend chain. It now runs exactly once per render, so prefixing transforms no longer compound across `extend`. The fix also covers cross-factory extends: when a component from one `create()` factory is extended by a component from another, the extend's transform applies to its own contribution before the parent's transform runs on the joined string.
18
+
3
19
  ## 0.2.2
4
20
 
5
21
  - Improved runtime prop resolution, style normalization, and [`splitProps`](https://clava.style/docs/reference/split-props) performance.
package/dist/index.js CHANGED
@@ -222,25 +222,14 @@ function isHTMLObjStyle(style) {
222
222
  //#endregion
223
223
  //#region src/index.ts
224
224
  const META_KEY = "__meta";
225
- const SKIP_STYLE_KEYS = Symbol("skipStyleKeys");
226
- const SKIP_STYLE_VARIANT_VALUES = Symbol("skipStyleVariantValues");
227
225
  const hasOwn = Object.prototype.hasOwnProperty;
226
+ const EMPTY_DEFAULTS = Object.freeze({});
228
227
  function getComponentMeta(component) {
229
228
  return component[META_KEY];
230
229
  }
231
230
  function setComponentMeta(component, meta) {
232
231
  component[META_KEY] = meta;
233
232
  }
234
- /**
235
- * Mutates target by assigning all properties from source. Avoids object spread
236
- * overhead in hot paths where we're building up a result object.
237
- */
238
- function assign(target, source) {
239
- for (const key in source) {
240
- if (!hasOwn.call(source, key)) continue;
241
- target[key] = source[key];
242
- }
243
- }
244
233
  function isRecordObject(value) {
245
234
  if (typeof value !== "object") return false;
246
235
  if (value == null) return false;
@@ -352,18 +341,6 @@ function collectDisabledVariantValues(config) {
352
341
  }
353
342
  return values;
354
343
  }
355
- /**
356
- * Extracts classes from fullClass that are not in baseClass. Uses string
357
- * comparison optimization: if fullClass starts with baseClass, just take the
358
- * suffix.
359
- */
360
- function extractVariantClasses(fullClass, baseClass) {
361
- if (!fullClass) return "";
362
- if (!baseClass) return fullClass;
363
- if (fullClass.startsWith(baseClass)) return fullClass.slice(baseClass.length).trim();
364
- const baseClassSet = new Set(baseClass.split(" ").filter(Boolean));
365
- return fullClass.split(" ").filter((c) => c && !baseClassSet.has(c)).join(" ");
366
- }
367
344
  const EMPTY_SOURCE = {
368
345
  keys: [],
369
346
  variantKeys: [],
@@ -472,66 +449,17 @@ function buildPrebuiltVariant(variantDef) {
472
449
  };
473
450
  }
474
451
  /**
475
- * Creates the resolveDefaults function for a component. This function returns
476
- * only the variants set via setDefaultVariants in the computed function. Used
477
- * by child components to get parent's computed defaults.
478
- */
479
- function createResolveDefaults(config, staticDefaults) {
480
- const computed = config.computed;
481
- const extend = config.extend;
482
- return (childDefaults, userProps = {}) => {
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
- }
497
- const computedDefaults = {};
498
- if (extend) for (const ext of extend) {
499
- const meta = getComponentMeta(ext);
500
- if (!meta) continue;
501
- const extDefaults = meta.resolveDefaults(childDefaults, userProps);
502
- for (const k in extDefaults) if (hasOwn.call(extDefaults, k)) computedDefaults[k] = extDefaults[k];
503
- }
504
- if (computed) computed({
505
- variants: resolvedVariants,
506
- setVariants: () => {},
507
- setDefaultVariants: (newDefaults) => {
508
- for (const key in newDefaults) {
509
- if (!hasOwn.call(newDefaults, key)) continue;
510
- const value = newDefaults[key];
511
- if (userProps[key] !== void 0) continue;
512
- if (isVariantDisabled(config, key)) continue;
513
- if (isVariantValueDisabled(config, key, value)) continue;
514
- computedDefaults[key] = value;
515
- }
516
- },
517
- addClass: () => {},
518
- addStyle: () => {}
519
- });
520
- return computedDefaults;
521
- };
522
- }
523
- /**
524
452
  * Creates the cv and cx functions.
525
453
  */
526
454
  function create({ transformClass = (className) => className } = {}) {
527
455
  const cx = (...classes) => transformClass(clsx(...classes));
528
456
  const cv = (config = {}) => {
529
457
  const variantKeys = collectVariantKeys(config);
458
+ const variantKeysLength = variantKeys.length;
530
459
  const disabledVariantKeys = collectDisabledVariantKeys(config);
531
460
  const disabledVariantValues = collectDisabledVariantValues(config);
532
461
  const hasDisabledVariantKeys = disabledVariantKeys.size > 0;
533
- const disabledVariantValueKeys = Object.keys(disabledVariantValues);
534
- const hasDisabledVariantValues = disabledVariantValueKeys.length > 0;
462
+ const hasDisabledVariantValues = Object.keys(disabledVariantValues).length > 0;
535
463
  const hasAnyDisabled = hasDisabledVariantKeys || hasDisabledVariantValues;
536
464
  const inputPropsKeys = [
537
465
  "class",
@@ -545,7 +473,7 @@ function create({ transformClass = (className) => className } = {}) {
545
473
  const computedVariantsCfg = config.computedVariants;
546
474
  const computed = config.computed;
547
475
  const baseStyle = config.style;
548
- const baseClass = config.class === void 0 ? null : config.class;
476
+ const hasBaseStyle = !!baseStyle;
549
477
  const variantEntryNames = [];
550
478
  const variantEntryDefs = [];
551
479
  if (variants) for (const name in variants) {
@@ -588,15 +516,32 @@ function create({ transformClass = (className) => className } = {}) {
588
516
  if (valueKey != null && disabledVariantValues[key]?.has(valueKey)) delete staticDefaults[key];
589
517
  }
590
518
  }
591
- const extEntries = extend ? extend : [];
592
- const extBaseClassesArr = [];
593
519
  const extMetas = [];
520
+ const extBaseClassesArr = [];
521
+ const extIsolated = [];
522
+ let hasIsolatedExt = false;
594
523
  if (extend) for (const ext of extend) {
595
524
  const meta = getComponentMeta(ext);
525
+ if (!meta) continue;
596
526
  extMetas.push(meta);
597
- 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]);
598
543
  }
599
- const extCount = extEntries.length;
544
+ const staticExtSkipValues = hasDisabledVariantValues ? disabledVariantValues : null;
600
545
  function filterDisabledInto(input, out) {
601
546
  if (!hasAnyDisabled) {
602
547
  for (const key in input) if (hasOwn.call(input, key)) out[key] = input[key];
@@ -613,15 +558,63 @@ function create({ transformClass = (className) => className } = {}) {
613
558
  out[key] = value;
614
559
  }
615
560
  }
616
- 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;
617
609
  function resolveVariantsHot(propsVariants) {
618
610
  const defaults = {};
619
611
  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];
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
+ }
625
618
  }
626
619
  for (const k in propsVariants) {
627
620
  if (!hasOwn.call(propsVariants, k)) continue;
@@ -634,195 +627,217 @@ function create({ transformClass = (className) => className } = {}) {
634
627
  filterDisabledInto(defaults, result);
635
628
  return result;
636
629
  }
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;
630
+ const compute = (resolved, userVariantProps, skipKeys, skipValues, classesOut, styleOut) => {
631
+ let workingResolved = resolved;
632
+ let cClasses = null;
633
+ let cStyle = null;
648
634
  if (computed) {
649
- const updatedVariants = {};
650
- Object.assign(updatedVariants, resolvedVariants);
651
- const cClasses = [];
652
- 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
+ };
653
650
  const result = computed({
654
- variants: resolvedVariants,
651
+ variants: ownVariants,
655
652
  setVariants: (newVariants) => {
656
- if (!hasAnyDisabled) Object.assign(updatedVariants, newVariants);
657
- else {
658
- const filtered = {};
659
- filterDisabledInto(newVariants, filtered);
660
- 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;
661
666
  }
662
667
  },
663
668
  setDefaultVariants: (newDefaults) => {
664
669
  for (const key in newDefaults) {
665
670
  if (!hasOwn.call(newDefaults, key)) continue;
666
- if (variantProps[key] !== void 0) continue;
671
+ if (userVariantProps[key] !== void 0) continue;
667
672
  const value = newDefaults[key];
668
673
  if (hasAnyDisabled) {
669
674
  if (disabledVariantKeys.has(key)) continue;
670
675
  const valueKey = getVariantValueKey(value);
671
676
  if (valueKey != null && disabledVariantValues[key]?.has(valueKey)) continue;
672
677
  }
673
- updatedVariants[key] = value;
678
+ ensureUpdated()[key] = value;
674
679
  }
675
680
  },
676
681
  addClass: (className) => {
677
- cClasses.push(className);
682
+ localCClasses.push(className);
678
683
  },
679
684
  addStyle: (newStyle) => {
680
- if (!cStyle) cStyle = {};
681
- assign(cStyle, newStyle);
685
+ if (!localCStyle) localCStyle = {};
686
+ Object.assign(localCStyle, newStyle);
682
687
  }
683
688
  });
684
689
  if (result != null) {
685
690
  const r = extractClassAndStylePrebuilt(result);
686
- if (r.class != null) cClasses.push(r.class);
691
+ if (r.class != null) localCClasses.push(r.class);
687
692
  if (r.style) {
688
- if (!cStyle) cStyle = {};
689
- assign(cStyle, r.style);
693
+ if (!localCStyle) localCStyle = {};
694
+ Object.assign(localCStyle, r.style);
690
695
  }
691
696
  }
692
- if (hasAnyDisabled) {
697
+ cClasses = localCClasses;
698
+ cStyle = localCStyle;
699
+ if (updatedVariants) if (hasAnyDisabled) {
693
700
  const filteredUpdated = {};
694
701
  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);
702
+ workingResolved = filteredUpdated;
703
+ } else workingResolved = updatedVariants;
706
704
  }
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
- }
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);
714
711
  }
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);
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];
733
725
  }
734
726
  }
735
- const allClasses = [];
736
- const allStyle = {};
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);
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));
757
733
  }
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
- }
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;
765
738
  for (let i = 0; i < variantEntryCount; i++) {
766
739
  const variantName = variantEntryNames[i];
767
- const variant = variantEntryDefs[i];
768
- if (currentVariantKeys && currentVariantKeys.has(variantName)) continue;
769
- const selectedValue = resolvedVariants[variantName];
740
+ if (ownSkipKeys && ownSkipKeys.has(variantName)) continue;
741
+ const selectedValue = workingResolved[variantName];
770
742
  if (selectedValue === void 0) continue;
771
743
  const selectedKey = getVariantValueKey(selectedValue);
744
+ const variant = variantEntryDefs[i];
772
745
  if (variant.disabledValues && selectedKey != null && variant.disabledValues.has(selectedKey)) continue;
773
- if (skipStyleVariantValuesIn && selectedKey != null && skipStyleVariantValuesIn[variantName]?.has(selectedKey)) continue;
746
+ if (ownSkipValues && selectedKey != null && ownSkipValues[variantName]?.has(selectedKey)) continue;
774
747
  if (variant.values) {
775
748
  if (selectedKey == null) continue;
776
749
  const v = variant.values[selectedKey];
777
750
  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
- }
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);
786
757
  }
787
758
  }
788
759
  for (let i = 0; i < computedVariantCount; i++) {
789
760
  const variantName = computedVariantNames[i];
790
- const fn = computedVariantFns[i];
791
- if (currentVariantKeys && currentVariantKeys.has(variantName)) continue;
792
- const selectedValue = resolvedVariants[variantName];
761
+ if (ownSkipKeys && ownSkipKeys.has(variantName)) continue;
762
+ const selectedValue = workingResolved[variantName];
793
763
  if (selectedValue === void 0) continue;
794
764
  const selectedKey = getVariantValueKey(selectedValue);
795
- if (skipStyleVariantValuesIn && selectedKey != null && skipStyleVariantValuesIn[variantName]?.has(selectedKey)) continue;
765
+ if (ownSkipValues && selectedKey != null && ownSkipValues[variantName]?.has(selectedKey)) continue;
766
+ const fn = computedVariantFns[i];
796
767
  const computedResult = fn(selectedValue);
797
768
  if (computedResult == null) continue;
798
769
  const r = extractClassAndStylePrebuilt(computedResult);
799
- if (r.class != null) allClasses.push(r.class);
800
- 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);
772
+ }
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;
801
810
  }
802
- if (computedClassesArr) for (let i = 0; i < computedClassesArr.length; i++) allClasses.push(computedClassesArr[i]);
803
- if (computedStyleObj) assign(allStyle, computedStyleObj);
804
- if ("class" in props) allClasses.push(props.class);
805
- if ("className" in props) allClasses.push(props.className);
806
- const psv = props.style;
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;
807
822
  if (psv != null) {
808
823
  if (typeof psv === "string") {
809
- if (psv.length > 0) assign(allStyle, htmlStyleToStyleValue(psv));
824
+ if (psv.length > 0) Object.assign(style, htmlStyleToStyleValue(psv));
810
825
  } else if (typeof psv === "object") {
811
826
  let hasAnyKey = false;
812
827
  for (const _ in psv) {
813
828
  hasAnyKey = true;
814
829
  break;
815
830
  }
816
- if (hasAnyKey) assign(allStyle, normalizeStyle(psv));
831
+ if (hasAnyKey) Object.assign(style, normalizeStyle(psv));
817
832
  }
818
833
  }
819
834
  return {
820
- className: cx(...allClasses),
821
- style: allStyle
835
+ className: transformClass(clsx(allClasses)),
836
+ style
822
837
  };
823
838
  };
824
839
  const getVariants = (variants) => {
825
- const variantProps = variants ?? {};
840
+ const variantProps = variants ?? EMPTY_DEFAULTS;
826
841
  let resolvedVariants = resolveVariantsHot(variantProps);
827
842
  if (computed) {
828
843
  const updatedVariants = {};
@@ -830,11 +845,19 @@ function create({ transformClass = (className) => className } = {}) {
830
845
  computed({
831
846
  variants: resolvedVariants,
832
847
  setVariants: (newVariants) => {
833
- if (!hasAnyDisabled) Object.assign(updatedVariants, newVariants);
834
- else {
835
- const filtered = {};
836
- filterDisabledInto(newVariants, filtered);
837
- 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;
838
861
  }
839
862
  },
840
863
  setDefaultVariants: (newDefaults) => {
@@ -850,8 +873,8 @@ function create({ transformClass = (className) => className } = {}) {
850
873
  updatedVariants[key] = value;
851
874
  }
852
875
  },
853
- addClass: () => {},
854
- addStyle: () => {}
876
+ addClass: noop,
877
+ addStyle: noop
855
878
  });
856
879
  if (hasAnyDisabled) {
857
880
  const filteredUpdated = {};
@@ -861,14 +884,16 @@ function create({ transformClass = (className) => className } = {}) {
861
884
  }
862
885
  return resolvedVariants;
863
886
  };
864
- const computedBaseClass = cx(...extBaseClassesArr, config.class);
887
+ const computedBaseClass = clsx(...extBaseClassesArr, config.class);
865
888
  const classFn = (props = {}) => {
866
889
  return computeResult(props).className;
867
890
  };
868
891
  const meta = {
869
892
  baseClass: computedBaseClass,
870
893
  staticDefaults,
871
- resolveDefaults: resolveDefaultsFn
894
+ resolveDefaults: resolveDefaultsFn,
895
+ compute,
896
+ transformClass
872
897
  };
873
898
  const initComponent = (c, keys, style) => {
874
899
  c.class = classFn;
@@ -936,6 +961,7 @@ function create({ transformClass = (className) => className } = {}) {
936
961
  cx
937
962
  };
938
963
  }
964
+ function noop() {}
939
965
  const { cv, cx } = create();
940
966
  //#endregion
941
967
  export { create, cv, cx, splitProps };