clava 0.6.2 → 0.6.4

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 = Object.hasOwn;
4
+ function getOwn(record, key) {
5
+ if (!hasOwn(record, key)) return void 0;
6
+ return record[key];
7
+ }
4
8
  const unitlessNumberProperties = /* @__PURE__ */ new Set([
5
9
  "animationIterationCount",
6
10
  "aspectRatio",
@@ -252,6 +256,9 @@ function formatCreationStack(frame) {
252
256
  }
253
257
  function isInternalCreationFrame(line) {
254
258
  if (line.includes("captureCreationFrame")) return true;
259
+ if (line.startsWith("at buildComponent ")) return true;
260
+ if (line.startsWith("at buildComponent(")) return true;
261
+ if (line.startsWith("buildComponent@")) return true;
255
262
  if (line.startsWith("at cv ")) return true;
256
263
  if (line.startsWith("at cv(")) return true;
257
264
  if (line.startsWith("cv@")) return true;
@@ -280,7 +287,8 @@ function setVariantChange(into, key, from, to) {
280
287
  function accumulateUnstableVariantChanges(into, prev, next) {
281
288
  for (const key in next) {
282
289
  if (!hasOwn(next, key)) continue;
283
- if (!Object.is(prev[key], next[key])) setVariantChange(into, key, prev[key], next[key]);
290
+ const from = getOwn(prev, key);
291
+ if (!Object.is(from, next[key])) setVariantChange(into, key, from, next[key]);
284
292
  }
285
293
  for (const key in prev) {
286
294
  if (!hasOwn(prev, key)) continue;
@@ -310,25 +318,55 @@ function warnRefineLimit({ creationFrame, unstableChanges }) {
310
318
  //#region src/index.ts
311
319
  const META_KEY = "__meta";
312
320
  const EMPTY_DEFAULTS = {};
321
+ function deduplicateExtensions(extensions, seen = /* @__PURE__ */ new Set()) {
322
+ if (extensions.length === 0) return extensions;
323
+ const result = [];
324
+ let changed = false;
325
+ for (const meta of extensions) {
326
+ const identity = getOwn(meta, "identity") ?? meta;
327
+ if (seen.has(identity)) {
328
+ changed = true;
329
+ continue;
330
+ }
331
+ seen.add(identity);
332
+ const inheritedExtensions = getOwn(meta, "extends");
333
+ const rebuild = getOwn(meta, "rebuild");
334
+ if (!inheritedExtensions || !rebuild) {
335
+ result.push(meta);
336
+ continue;
337
+ }
338
+ const children = deduplicateExtensions(inheritedExtensions, seen);
339
+ if (children === inheritedExtensions) result.push(meta);
340
+ else {
341
+ result.push(rebuild(children));
342
+ changed = true;
343
+ }
344
+ }
345
+ return changed ? result : extensions;
346
+ }
313
347
  const MAX_REFINE_RUNS = 50;
314
348
  function areVariantsEqual(a, b) {
349
+ let ownKeyDifference = 0;
315
350
  for (const key in a) {
316
351
  if (!hasOwn(a, key)) continue;
352
+ if (!hasOwn(b, key)) return false;
317
353
  if (!Object.is(a[key], b[key])) return false;
354
+ ownKeyDifference++;
318
355
  }
319
356
  for (const key in b) {
320
357
  if (!hasOwn(b, key)) continue;
321
- if (!hasOwn(a, key)) return false;
358
+ ownKeyDifference--;
322
359
  }
323
- return true;
324
- }
325
- function getExtUserVariantProps(userVariantProps, protectedVariants) {
326
- return Object.assign({}, userVariantProps, protectedVariants);
360
+ return ownKeyDifference === 0;
327
361
  }
328
- function mergeProtectedIntoBase(baseResolved, protectedVariants, protectedVariantKeys) {
329
- if (protectedVariantKeys.size === 0) return baseResolved;
362
+ function mergeProtectedIntoBase(baseResolved, protection) {
363
+ const protectedVariants = protection?.variants;
364
+ if (!protectedVariants) return baseResolved;
330
365
  return Object.assign({}, baseResolved, protectedVariants);
331
366
  }
367
+ function identityClass(className) {
368
+ return className;
369
+ }
332
370
  function isRecordObject(value) {
333
371
  if (typeof value !== "object") return false;
334
372
  if (value == null) return false;
@@ -345,14 +383,16 @@ function extractClassAndStylePrebuilt(value) {
345
383
  class: value,
346
384
  style: null
347
385
  };
348
- if (!("style" in value || "class" in value)) return {
386
+ const styleClassValue = value;
387
+ const classValue = hasOwn(value, "class") ? styleClassValue.class : void 0;
388
+ const styleValue = hasOwn(value, "style") ? styleClassValue.style : void 0;
389
+ if (classValue === void 0 && styleValue === void 0) return {
349
390
  class: null,
350
391
  style: null
351
392
  };
352
- const styleClassValue = value;
353
- const style = normalizeStyle(styleClassValue.style);
393
+ const style = normalizeStyle(styleValue);
354
394
  return {
355
- class: styleClassValue.class ?? null,
395
+ class: classValue ?? null,
356
396
  style: Object.keys(style).length > 0 ? style : null
357
397
  };
358
398
  }
@@ -430,7 +470,7 @@ function buildPrebuiltVariant(variantDef) {
430
470
  shorthand: extractClassAndStylePrebuilt(variantDef),
431
471
  disabledValues: null
432
472
  };
433
- const values = {};
473
+ const values = /* @__PURE__ */ new Map();
434
474
  let disabledValues = null;
435
475
  for (const key in variantDef) {
436
476
  if (!hasOwn(variantDef, key)) continue;
@@ -440,7 +480,7 @@ function buildPrebuiltVariant(variantDef) {
440
480
  disabledValues.add(key);
441
481
  continue;
442
482
  }
443
- values[key] = extractClassAndStylePrebuilt(value);
483
+ values.set(key, extractClassAndStylePrebuilt(value));
444
484
  }
445
485
  return {
446
486
  values,
@@ -448,22 +488,20 @@ function buildPrebuiltVariant(variantDef) {
448
488
  disabledValues
449
489
  };
450
490
  }
451
- function create({ transformClass = (className) => className } = {}) {
491
+ function create(params = {}) {
492
+ const transformClass = getOwn(params, "transformClass") ?? identityClass;
452
493
  const cx = (...classes) => transformClass(clsx(classes));
453
- const cv = (config = {}) => {
454
- const extend = config.extend;
455
- const hasExtend = !!extend && extend.length > 0;
456
- const variants = config.variants;
457
- const refine = config.refine;
458
- const baseStyle = config.style;
494
+ const buildComponent = (config = {}) => {
495
+ const extend = getOwn(config, "extend");
496
+ const variants = getOwn(config, "variants");
497
+ const refine = getOwn(config, "refine");
498
+ const baseStyle = getOwn(config, "style");
459
499
  const hasBaseStyle = !!baseStyle;
500
+ const baseClassValue = getOwn(config, "class");
460
501
  const variantKeySet = /* @__PURE__ */ new Set();
461
- const staticDefaults = {};
462
- const extMetas = [];
463
- const extBaseClassesArr = [];
464
- const extIsolated = [];
465
- let hasIsolatedExt = false;
466
- if (hasExtend) for (const ext of extend) {
502
+ const inheritedComputedDefaultKeys = /* @__PURE__ */ new Set();
503
+ const originalExtMetas = [];
504
+ if (extend) for (const ext of extend) {
467
505
  const extKeys = ext.variantKeys;
468
506
  for (let i = 0; i < extKeys.length; i++) {
469
507
  const key = extKeys[i];
@@ -472,19 +510,13 @@ function create({ transformClass = (className) => className } = {}) {
472
510
  }
473
511
  const meta = ext[META_KEY];
474
512
  if (!meta) continue;
475
- extMetas.push(meta);
476
- Object.assign(staticDefaults, meta.staticDefaults);
477
- const isolated = meta.transformClass !== transformClass;
478
- extIsolated.push(isolated);
479
- if (isolated) {
480
- hasIsolatedExt = true;
481
- extBaseClassesArr.push(meta.transformClass(meta.baseClass));
482
- } else extBaseClassesArr.push(meta.baseClass);
513
+ originalExtMetas.push(meta);
514
+ for (const key of meta.computedDefaultKeys) inheritedComputedDefaultKeys.add(key);
483
515
  }
484
- const extCount = extMetas.length;
516
+ const initialExtensions = originalExtMetas.length > 1 ? deduplicateExtensions(originalExtMetas) : originalExtMetas;
517
+ const ownStaticDefaults = {};
485
518
  const disabledVariantKeys = /* @__PURE__ */ new Set();
486
- const disabledVariantValues = {};
487
- let hasDisabledVariantValues = false;
519
+ let disabledValuesBuilder = null;
488
520
  const variantEntryNames = [];
489
521
  const variantEntryDefs = [];
490
522
  const functionVariantNames = [];
@@ -507,17 +539,18 @@ function create({ transformClass = (className) => className } = {}) {
507
539
  variantEntryNames.push(name);
508
540
  variantEntryDefs.push(prebuiltVariant);
509
541
  if (prebuiltVariant.disabledValues) {
510
- disabledVariantValues[name] = prebuiltVariant.disabledValues;
511
- hasDisabledVariantValues = true;
542
+ disabledValuesBuilder ??= {};
543
+ disabledValuesBuilder[name] = prebuiltVariant.disabledValues;
512
544
  }
513
- if (prebuiltVariant.values && hasOwn(prebuiltVariant.values, "false") && staticDefaults[name] === void 0) staticDefaults[name] = false;
545
+ if (prebuiltVariant.values?.has("false") && !initialExtensions.some((meta) => hasOwn(meta.staticDefaults, name))) ownStaticDefaults[name] = false;
514
546
  }
515
547
  const variantKeys = Array.from(variantKeySet);
516
548
  const variantKeysLength = variantKeys.length;
517
549
  const variantEntryCount = variantEntryNames.length;
518
550
  const functionVariantCount = functionVariantNames.length;
519
551
  const hasDisabledVariantKeys = disabledVariantKeys.size > 0;
520
- const hasAnyDisabled = hasDisabledVariantKeys || hasDisabledVariantValues;
552
+ const disabledVariantValues = disabledValuesBuilder;
553
+ const hasAnyDisabled = hasDisabledVariantKeys || disabledVariantValues !== null;
521
554
  const inputPropsKeys = [
522
555
  "class",
523
556
  "className",
@@ -526,579 +559,585 @@ function create({ transformClass = (className) => className } = {}) {
526
559
  ];
527
560
  const computedDefaultNames = [];
528
561
  const computedDefaultFns = [];
529
- const defaultVariants = config.defaultVariants;
562
+ const defaultVariants = getOwn(config, "defaultVariants");
530
563
  if (defaultVariants) for (const name in defaultVariants) {
531
564
  if (!hasOwn(defaultVariants, name)) continue;
532
565
  const value = defaultVariants[name];
533
566
  if (typeof value === "function") {
534
567
  computedDefaultNames.push(name);
535
568
  computedDefaultFns.push(value);
536
- continue;
537
- }
538
- if (value === void 0) {
539
- delete staticDefaults[name];
540
- continue;
541
- }
542
- staticDefaults[name] = value;
569
+ } else ownStaticDefaults[name] = value;
543
570
  }
544
571
  const computedDefaultCount = computedDefaultNames.length;
545
- if (hasAnyDisabled) for (const key in staticDefaults) {
546
- if (!hasOwn(staticDefaults, key)) continue;
547
- if (disabledVariantKeys.has(key)) {
548
- delete staticDefaults[key];
549
- continue;
572
+ const baseClass = clsx(baseClassValue);
573
+ const identity = {};
574
+ const creationFrame = (!!refine || computedDefaultCount > 0 || initialExtensions.some((meta) => meta.resolveRefine)) && process.env.NODE_ENV !== "production" ? captureCreationFrame(cv) : void 0;
575
+ const build = (extMetas) => {
576
+ const hasExtend = extMetas.length > 0;
577
+ const extCount = extMetas.length;
578
+ const staticDefaults = {};
579
+ const extBaseClassesArr = [];
580
+ const extIsolated = [];
581
+ let hasIsolatedExt = false;
582
+ for (const meta of extMetas) {
583
+ Object.assign(staticDefaults, meta.staticDefaults);
584
+ const isolated = meta.transformClass !== transformClass;
585
+ extIsolated.push(isolated);
586
+ if (isolated) {
587
+ hasIsolatedExt = true;
588
+ extBaseClassesArr.push(meta.transformClass(meta.baseClass));
589
+ } else extBaseClassesArr.push(meta.baseClass);
550
590
  }
551
- if (hasDisabledVariantValues) {
552
- const value = staticDefaults[key];
553
- const valueKey = getVariantValueKey(value);
554
- if (valueKey != null && disabledVariantValues[key]?.has(valueKey)) delete staticDefaults[key];
591
+ for (const name in ownStaticDefaults) {
592
+ if (!hasOwn(ownStaticDefaults, name)) continue;
593
+ const value = ownStaticDefaults[name];
594
+ if (value === void 0) delete staticDefaults[name];
595
+ else staticDefaults[name] = value;
555
596
  }
556
- }
557
- const inheritedComputedDefaultKeys = /* @__PURE__ */ new Set();
558
- for (let i = 0; i < extCount; i++) {
559
- const keys = extMetas[i].computedDefaultKeys;
560
- for (const key of keys) inheritedComputedDefaultKeys.add(key);
561
- }
562
- const extMetasWithRefine = [];
563
- for (let i = 0; i < extCount; i++) {
564
- const meta = extMetas[i];
565
- if (meta.resolveRefine) extMetasWithRefine.push(meta);
566
- }
567
- const extMetasWithRefineCount = extMetasWithRefine.length;
568
- const creationFrame = (!!refine || computedDefaultCount > 0 || extMetasWithRefineCount > 0) && process.env.NODE_ENV !== "production" ? captureCreationFrame(cv) : void 0;
569
- const functionVariantKeys = /* @__PURE__ */ new Set();
570
- for (let i = 0; i < extCount; i++) {
571
- const fnKeys = extMetas[i].functionVariantKeys;
572
- for (const k of fnKeys) {
573
- if (disabledVariantKeys.has(k)) continue;
574
- functionVariantKeys.add(k);
597
+ if (hasAnyDisabled) for (const key in staticDefaults) {
598
+ if (!hasOwn(staticDefaults, key)) continue;
599
+ if (disabledVariantKeys.has(key)) {
600
+ delete staticDefaults[key];
601
+ continue;
602
+ }
603
+ if (disabledVariantValues) {
604
+ const valueKey = getVariantValueKey(staticDefaults[key]);
605
+ if (valueKey != null && getOwn(disabledVariantValues, key)?.has(valueKey)) delete staticDefaults[key];
606
+ }
575
607
  }
576
- }
577
- for (let i = 0; i < functionVariantCount; i++) functionVariantKeys.add(functionVariantNames[i]);
578
- for (let i = 0; i < variantEntryCount; i++) functionVariantKeys.delete(variantEntryNames[i]);
579
- const computedDefaultKeys = new Set(inheritedComputedDefaultKeys);
580
- for (let i = 0; i < computedDefaultCount; i++) computedDefaultKeys.add(computedDefaultNames[i]);
581
- let staticExtSkipKeys = null;
582
- if (hasDisabledVariantKeys || functionVariantCount > 0) {
583
- staticExtSkipKeys = /* @__PURE__ */ new Set();
584
- for (const k of disabledVariantKeys) staticExtSkipKeys.add(k);
585
- for (let i = 0; i < functionVariantCount; i++) staticExtSkipKeys.add(functionVariantNames[i]);
586
- }
587
- if (variantEntryCount > 0 && extCount > 0) for (let i = 0; i < variantEntryCount; i++) {
588
- const name = variantEntryNames[i];
589
- for (let j = 0; j < extCount; j++) if (extMetas[j].functionVariantKeys.has(name)) {
590
- staticExtSkipKeys ??= /* @__PURE__ */ new Set();
591
- staticExtSkipKeys.add(name);
592
- break;
608
+ const extMetasWithRefine = [];
609
+ for (let i = 0; i < extCount; i++) {
610
+ const meta = extMetas[i];
611
+ if (meta.resolveRefine) extMetasWithRefine.push(meta);
593
612
  }
594
- }
595
- const staticExtSkipValues = hasDisabledVariantValues ? disabledVariantValues : null;
596
- function filterDisabledInto(input, out) {
597
- for (const key in input) {
598
- if (!hasOwn(input, key)) continue;
599
- if (disabledVariantKeys.has(key)) continue;
600
- const value = input[key];
601
- if (hasDisabledVariantValues) {
602
- const valueKey = getVariantValueKey(value);
603
- if (valueKey != null && disabledVariantValues[key]?.has(valueKey)) continue;
613
+ const extMetasWithRefineCount = extMetasWithRefine.length;
614
+ const canProtectVariants = !!refine || extMetasWithRefineCount > 0;
615
+ const needsUserVariantProps = computedDefaultCount > 0 || inheritedComputedDefaultKeys.size > 0;
616
+ const functionVariantKeys = /* @__PURE__ */ new Set();
617
+ for (let i = 0; i < extCount; i++) {
618
+ const fnKeys = extMetas[i].functionVariantKeys;
619
+ for (const k of fnKeys) {
620
+ if (disabledVariantKeys.has(k)) continue;
621
+ functionVariantKeys.add(k);
604
622
  }
605
- out[key] = value;
606
623
  }
607
- }
608
- const isOwnDisabledValue = (key, value) => {
609
- if (disabledVariantKeys.has(key)) return true;
610
- if (hasDisabledVariantValues) {
611
- const valueKey = getVariantValueKey(value);
612
- if (valueKey != null && disabledVariantValues[key]?.has(valueKey)) return true;
624
+ for (let i = 0; i < functionVariantCount; i++) functionVariantKeys.add(functionVariantNames[i]);
625
+ for (let i = 0; i < variantEntryCount; i++) functionVariantKeys.delete(variantEntryNames[i]);
626
+ const computedDefaultKeys = new Set(inheritedComputedDefaultKeys);
627
+ for (let i = 0; i < computedDefaultCount; i++) computedDefaultKeys.add(computedDefaultNames[i]);
628
+ let staticExtSkipKeys = null;
629
+ if (hasDisabledVariantKeys || functionVariantCount > 0) {
630
+ staticExtSkipKeys = /* @__PURE__ */ new Set();
631
+ for (const k of disabledVariantKeys) staticExtSkipKeys.add(k);
632
+ for (let i = 0; i < functionVariantCount; i++) staticExtSkipKeys.add(functionVariantNames[i]);
613
633
  }
614
- return false;
615
- };
616
- const filterOwnDisabledVariants = (input, fallback) => {
617
- if (!hasAnyDisabled) return input;
618
- let hasOwnDisabledValue = false;
619
- for (const key in input) {
620
- if (!hasOwn(input, key)) continue;
621
- const value = input[key];
622
- if (isOwnDisabledValue(key, value)) {
623
- hasOwnDisabledValue = true;
634
+ if (variantEntryCount > 0 && extCount > 0) for (let i = 0; i < variantEntryCount; i++) {
635
+ const name = variantEntryNames[i];
636
+ for (let j = 0; j < extCount; j++) if (extMetas[j].functionVariantKeys.has(name)) {
637
+ staticExtSkipKeys ??= /* @__PURE__ */ new Set();
638
+ staticExtSkipKeys.add(name);
624
639
  break;
625
640
  }
626
641
  }
627
- if (!hasOwnDisabledValue) return input;
628
- const filtered = {};
629
- for (const key in input) {
630
- if (!hasOwn(input, key)) continue;
631
- const value = input[key];
632
- if (!isOwnDisabledValue(key, value)) {
633
- filtered[key] = value;
634
- continue;
642
+ const staticExtSkipValues = disabledVariantValues;
643
+ function filterDisabledInto(input, out) {
644
+ for (const key in input) {
645
+ if (!hasOwn(input, key)) continue;
646
+ if (disabledVariantKeys.has(key)) continue;
647
+ const value = input[key];
648
+ if (disabledVariantValues) {
649
+ const valueKey = getVariantValueKey(value);
650
+ if (valueKey != null && getOwn(disabledVariantValues, key)?.has(valueKey)) continue;
651
+ }
652
+ out[key] = value;
635
653
  }
636
- const fallbackValue = fallback[key];
637
- if (fallbackValue !== void 0 && !isOwnDisabledValue(key, fallbackValue)) filtered[key] = fallbackValue;
638
654
  }
639
- return filtered;
640
- };
641
- function resolveVariantsHot(propsVariants) {
642
- const defaults = Object.assign({}, staticDefaults);
643
- for (let i = 0; i < variantKeysLength; i++) {
644
- const k = variantKeys[i];
645
- if (!hasOwn(propsVariants, k)) continue;
646
- const v = propsVariants[k];
647
- if (v === void 0) continue;
648
- defaults[k] = v;
649
- }
650
- if (!hasAnyDisabled) return defaults;
651
- const result = {};
652
- filterDisabledInto(defaults, result);
653
- return result;
654
- }
655
- const runComputedDefaults = (resolved, defaultResolved, userVariantProps, filterOwnVariants, protectedVariantKeys) => {
656
- let ownVariants = filterOwnVariants ? null : resolved;
657
- const getOwnVariants = () => {
658
- if (ownVariants) return ownVariants;
659
- const filteredVariants = {};
660
- for (let i = 0; i < variantKeysLength; i++) {
661
- const key = variantKeys[i];
662
- if (hasOwn(resolved, key)) filteredVariants[key] = resolved[key];
655
+ const isOwnDisabledValue = (key, value) => {
656
+ if (disabledVariantKeys.has(key)) return true;
657
+ if (disabledVariantValues) {
658
+ const valueKey = getVariantValueKey(value);
659
+ if (valueKey != null && getOwn(disabledVariantValues, key)?.has(valueKey)) return true;
663
660
  }
664
- ownVariants = filteredVariants;
665
- return filteredVariants;
666
- };
667
- let updatedVariants = null;
668
- const ensureUpdated = () => {
669
- if (updatedVariants) return updatedVariants;
670
- const updated = Object.assign({}, resolved);
671
- updatedVariants = updated;
672
- return updated;
661
+ return false;
673
662
  };
674
- for (let i = 0; i < computedDefaultCount; i++) {
675
- const key = computedDefaultNames[i];
676
- if (hasOwn(userVariantProps, key)) {
677
- if (userVariantProps[key] !== void 0) continue;
663
+ const filterOwnDisabledVariants = (input, fallback) => {
664
+ if (!hasAnyDisabled) return input;
665
+ let hasOwnDisabledValue = false;
666
+ for (const key in input) {
667
+ if (!hasOwn(input, key)) continue;
668
+ const value = input[key];
669
+ if (isOwnDisabledValue(key, value)) {
670
+ hasOwnDisabledValue = true;
671
+ break;
672
+ }
678
673
  }
679
- if (protectedVariantKeys?.has(key)) continue;
680
- const variantSnapshot = getOwnVariants();
681
- const defaultValue = inheritedComputedDefaultKeys.has(key) ? variantSnapshot[key] : defaultResolved[key];
682
- const value = computedDefaultFns[i](defaultValue, variantSnapshot);
683
- if (hasAnyDisabled) {
684
- if (disabledVariantKeys.has(key)) continue;
685
- const valueKey = getVariantValueKey(value);
686
- if (valueKey != null && disabledVariantValues[key]?.has(valueKey)) continue;
674
+ if (!hasOwnDisabledValue) return input;
675
+ const filtered = {};
676
+ for (const key in input) {
677
+ if (!hasOwn(input, key)) continue;
678
+ const value = input[key];
679
+ if (!isOwnDisabledValue(key, value)) {
680
+ filtered[key] = value;
681
+ continue;
682
+ }
683
+ const fallbackValue = getOwn(fallback, key);
684
+ if (fallbackValue !== void 0 && !isOwnDisabledValue(key, fallbackValue)) filtered[key] = fallbackValue;
687
685
  }
688
- if (value === void 0) {
689
- if (!hasOwn(variantSnapshot, key)) continue;
690
- delete ensureUpdated()[key];
691
- continue;
686
+ return filtered;
687
+ };
688
+ function resolveVariantsHot(propsVariants) {
689
+ const defaults = Object.assign({}, staticDefaults);
690
+ for (let i = 0; i < variantKeysLength; i++) {
691
+ const k = variantKeys[i];
692
+ if (!hasOwn(propsVariants, k)) continue;
693
+ const v = propsVariants[k];
694
+ if (v === void 0) continue;
695
+ defaults[k] = v;
692
696
  }
693
- if (Object.is(variantSnapshot[key], value)) continue;
694
- ensureUpdated()[key] = value;
697
+ if (!hasAnyDisabled) return defaults;
698
+ const result = {};
699
+ filterDisabledInto(defaults, result);
700
+ return result;
695
701
  }
696
- return updatedVariants ?? resolved;
697
- };
698
- const runRefineContext = (resolved, filterOwnVariants, collectOutput, applyVariantUpdates, protectedVariants, protectedVariantKeys) => {
699
- let workingResolved = resolved;
700
- let cClasses = null;
701
- let cStyle = null;
702
- if (refine) {
703
- let ownVariants = resolved;
704
- if (filterOwnVariants) {
702
+ const runComputedDefaults = (resolved, defaultResolved, userVariantProps, filterOwnVariants, protection) => {
703
+ const protectedVariants = protection?.variants;
704
+ let ownVariants = filterOwnVariants ? null : resolved;
705
+ const getOwnVariants = () => {
706
+ if (ownVariants) return ownVariants;
705
707
  const filteredVariants = {};
706
708
  for (let i = 0; i < variantKeysLength; i++) {
707
- const k = variantKeys[i];
708
- if (hasOwn(resolved, k)) filteredVariants[k] = resolved[k];
709
+ const key = variantKeys[i];
710
+ if (hasOwn(resolved, key)) filteredVariants[key] = resolved[key];
709
711
  }
710
712
  ownVariants = filteredVariants;
711
- }
713
+ return filteredVariants;
714
+ };
712
715
  let updatedVariants = null;
713
- const localCClasses = collectOutput ? [] : null;
714
- let localCStyle = null;
715
716
  const ensureUpdated = () => {
716
717
  if (updatedVariants) return updatedVariants;
717
- const u = Object.assign({}, ownVariants);
718
- updatedVariants = u;
719
- return u;
718
+ const updated = Object.assign({}, resolved);
719
+ updatedVariants = updated;
720
+ return updated;
720
721
  };
721
- const protectVariant = (key, value) => {
722
- if (protectedVariants) {
723
- protectedVariants[key] = value;
724
- protectedVariantKeys?.add(key);
722
+ for (let i = 0; i < computedDefaultCount; i++) {
723
+ const key = computedDefaultNames[i];
724
+ if (hasOwn(userVariantProps, key)) {
725
+ if (userVariantProps[key] !== void 0) continue;
725
726
  }
726
- };
727
- const result = refine({
728
- variants: ownVariants,
729
- setVariants: (newVariants) => {
730
- if (!applyVariantUpdates) return;
731
- if (!hasAnyDisabled) {
727
+ if (protectedVariants && hasOwn(protectedVariants, key)) continue;
728
+ const variantSnapshot = getOwnVariants();
729
+ const defaultValue = inheritedComputedDefaultKeys.has(key) ? getOwn(variantSnapshot, key) : getOwn(defaultResolved, key);
730
+ const value = computedDefaultFns[i](defaultValue, variantSnapshot);
731
+ if (hasAnyDisabled) {
732
+ if (disabledVariantKeys.has(key)) continue;
733
+ if (disabledVariantValues) {
734
+ const valueKey = getVariantValueKey(value);
735
+ if (valueKey != null && getOwn(disabledVariantValues, key)?.has(valueKey)) continue;
736
+ }
737
+ }
738
+ if (value === void 0) {
739
+ if (!hasOwn(variantSnapshot, key)) continue;
740
+ delete ensureUpdated()[key];
741
+ continue;
742
+ }
743
+ if (Object.is(getOwn(variantSnapshot, key), value)) continue;
744
+ ensureUpdated()[key] = value;
745
+ }
746
+ return updatedVariants ?? resolved;
747
+ };
748
+ const runRefineContext = (resolved, filterOwnVariants, collectOutput, applyVariantUpdates, protection) => {
749
+ let workingResolved = resolved;
750
+ let cClasses = null;
751
+ let cStyle = null;
752
+ if (refine) {
753
+ let ownVariants = resolved;
754
+ if (filterOwnVariants) {
755
+ const filteredVariants = {};
756
+ for (let i = 0; i < variantKeysLength; i++) {
757
+ const k = variantKeys[i];
758
+ if (hasOwn(resolved, k)) filteredVariants[k] = resolved[k];
759
+ }
760
+ ownVariants = filteredVariants;
761
+ }
762
+ let assignedVariants = null;
763
+ let localCClasses = null;
764
+ let localCStyle = null;
765
+ const result = refine({
766
+ variants: ownVariants,
767
+ setVariants: (newVariants) => {
768
+ if (!applyVariantUpdates) return;
732
769
  for (const key in newVariants) {
733
770
  if (!hasOwn(newVariants, key)) continue;
771
+ if (disabledVariantKeys.has(key)) continue;
734
772
  const value = newVariants[key];
735
- protectVariant(key, value);
736
- if (Object.is((updatedVariants ?? ownVariants)[key], value)) continue;
737
- ensureUpdated()[key] = value;
773
+ if (disabledVariantValues) {
774
+ const valueKey = getVariantValueKey(value);
775
+ if (valueKey != null && getOwn(disabledVariantValues, key)?.has(valueKey)) continue;
776
+ }
777
+ if (protection) {
778
+ const protectedVariants = protection.variants ??= {};
779
+ protectedVariants[key] = value;
780
+ }
781
+ const current = assignedVariants && hasOwn(assignedVariants, key) ? assignedVariants[key] : getOwn(ownVariants, key);
782
+ if (Object.is(current, value)) continue;
783
+ assignedVariants ??= {};
784
+ assignedVariants[key] = value;
738
785
  }
739
- return;
786
+ },
787
+ addClass: (className) => {
788
+ if (!collectOutput) return;
789
+ localCClasses ??= [];
790
+ localCClasses.push(className);
791
+ },
792
+ addStyle: (newStyle) => {
793
+ if (!collectOutput) return;
794
+ localCStyle ??= {};
795
+ Object.assign(localCStyle, newStyle);
740
796
  }
741
- for (const key in newVariants) {
742
- if (!hasOwn(newVariants, key)) continue;
743
- if (disabledVariantKeys.has(key)) continue;
744
- const value = newVariants[key];
745
- if (hasDisabledVariantValues) {
746
- const valueKey = getVariantValueKey(value);
747
- if (valueKey != null && disabledVariantValues[key]?.has(valueKey)) continue;
748
- }
749
- protectVariant(key, value);
750
- if (Object.is((updatedVariants ?? ownVariants)[key], value)) continue;
751
- ensureUpdated()[key] = value;
797
+ });
798
+ if (collectOutput && result != null) {
799
+ const r = extractClassAndStylePrebuilt(result);
800
+ if (r.class != null) {
801
+ localCClasses ??= [];
802
+ localCClasses.push(r.class);
803
+ }
804
+ if (r.style) {
805
+ localCStyle ??= {};
806
+ Object.assign(localCStyle, r.style);
752
807
  }
753
- },
754
- addClass: (className) => {
755
- localCClasses?.push(className);
756
- },
757
- addStyle: (newStyle) => {
758
- if (!collectOutput) return;
759
- if (!localCStyle) localCStyle = {};
760
- Object.assign(localCStyle, newStyle);
761
- }
762
- });
763
- if (collectOutput && result != null) {
764
- const r = extractClassAndStylePrebuilt(result);
765
- if (r.class != null) localCClasses?.push(r.class);
766
- if (r.style) {
767
- if (!localCStyle) localCStyle = {};
768
- Object.assign(localCStyle, r.style);
769
808
  }
809
+ cClasses = localCClasses;
810
+ cStyle = localCStyle;
811
+ if (assignedVariants) workingResolved = Object.assign({}, workingResolved, assignedVariants);
770
812
  }
771
- cClasses = localCClasses;
772
- cStyle = localCStyle;
773
- if (updatedVariants) {
774
- const nextResolved = Object.assign({}, workingResolved);
775
- if (hasAnyDisabled) filterDisabledInto(updatedVariants, nextResolved);
776
- else Object.assign(nextResolved, updatedVariants);
777
- workingResolved = nextResolved;
778
- }
779
- }
780
- return {
781
- workingResolved,
782
- classes: cClasses,
783
- style: cStyle
813
+ return {
814
+ workingResolved,
815
+ classes: cClasses,
816
+ style: cStyle
817
+ };
784
818
  };
785
- };
786
- const computeOnce = (resolved, userVariantProps, skipKeys, skipValues, classesOut, styleOut, protectedVariants, protectedVariantKeys, defaultResolved = resolved, renderOnly = false) => {
787
- let workingResolved = resolved;
788
- let cClasses = null;
789
- let cStyle = null;
790
- if (hasExtend) {
791
- let extSkipKeys;
792
- if (skipKeys === null) extSkipKeys = staticExtSkipKeys;
793
- else if (staticExtSkipKeys === null) extSkipKeys = skipKeys;
794
- else {
795
- extSkipKeys = new Set(skipKeys);
796
- for (const k of staticExtSkipKeys) extSkipKeys.add(k);
797
- }
798
- let extSkipVals;
799
- if (skipValues === null) extSkipVals = staticExtSkipValues;
800
- else if (staticExtSkipValues === null) extSkipVals = skipValues;
801
- else {
802
- extSkipVals = {};
803
- for (const k in skipValues) extSkipVals[k] = skipValues[k];
804
- for (const k in staticExtSkipValues) {
805
- const existing = extSkipVals[k];
806
- if (existing) {
807
- const merged = new Set(existing);
808
- for (const v of staticExtSkipValues[k]) merged.add(v);
809
- extSkipVals[k] = merged;
810
- } else extSkipVals[k] = staticExtSkipValues[k];
819
+ const computeOnce = (resolved, userVariantProps, skipKeys, skipValues, classesOut, styleOut, protection, defaultResolved = resolved, renderOnly = false) => {
820
+ let workingResolved = resolved;
821
+ let cClasses = null;
822
+ let cStyle = null;
823
+ if (hasExtend) {
824
+ let extSkipKeys;
825
+ if (skipKeys === null) extSkipKeys = staticExtSkipKeys;
826
+ else if (staticExtSkipKeys === null) extSkipKeys = skipKeys;
827
+ else {
828
+ extSkipKeys = new Set(skipKeys);
829
+ for (const k of staticExtSkipKeys) extSkipKeys.add(k);
811
830
  }
812
- }
813
- const extUserVariantProps = extMetasWithRefineCount > 0 ? getExtUserVariantProps(userVariantProps, protectedVariants ?? null) : userVariantProps;
814
- for (let i = 0; i < extCount; i++) {
815
- if (hasIsolatedExt && extIsolated[i]) {
816
- const extClasses = [];
817
- workingResolved = extMetas[i].compute(workingResolved, extUserVariantProps, extSkipKeys, extSkipVals, extClasses, styleOut, protectedVariants, protectedVariantKeys, defaultResolved, renderOnly);
818
- if (extClasses.length > 0) {
819
- const joined = clsx(extClasses);
820
- if (joined.length > 0) classesOut.push(extMetas[i].transformClass(joined));
831
+ let extSkipVals;
832
+ if (skipValues === null) extSkipVals = staticExtSkipValues;
833
+ else if (staticExtSkipValues === null) extSkipVals = skipValues;
834
+ else {
835
+ extSkipVals = {};
836
+ for (const k in skipValues) {
837
+ if (!hasOwn(skipValues, k)) continue;
838
+ extSkipVals[k] = skipValues[k];
821
839
  }
822
- } else workingResolved = extMetas[i].compute(workingResolved, extUserVariantProps, extSkipKeys, extSkipVals, classesOut, styleOut, protectedVariants, protectedVariantKeys, defaultResolved, renderOnly);
823
- workingResolved = filterOwnDisabledVariants(workingResolved, defaultResolved);
824
- if (protectedVariants && extMetasWithRefineCount > 0) Object.assign(extUserVariantProps, protectedVariants);
825
- }
826
- }
827
- if (!renderOnly && computedDefaultCount > 0) workingResolved = runComputedDefaults(workingResolved, defaultResolved, userVariantProps, true, protectedVariantKeys);
828
- if (refine) {
829
- const refineResult = runRefineContext(workingResolved, true, true, !renderOnly, protectedVariants, protectedVariantKeys);
830
- workingResolved = refineResult.workingResolved;
831
- cClasses = refineResult.classes;
832
- cStyle = refineResult.style;
833
- }
834
- if (hasBaseStyle) Object.assign(styleOut, baseStyle);
835
- const ownSkipKeys = skipKeys;
836
- const ownSkipValues = skipValues;
837
- for (let i = 0; i < variantEntryCount; i++) {
838
- const variantName = variantEntryNames[i];
839
- if (ownSkipKeys && ownSkipKeys.has(variantName)) continue;
840
- const selectedValue = workingResolved[variantName];
841
- if (selectedValue === void 0) continue;
842
- const selectedKey = getVariantValueKey(selectedValue);
843
- const variant = variantEntryDefs[i];
844
- if (variant.disabledValues && selectedKey != null && variant.disabledValues.has(selectedKey)) continue;
845
- if (ownSkipValues && selectedKey != null && ownSkipValues[variantName]?.has(selectedKey)) continue;
846
- let value;
847
- if (variant.values) {
848
- if (selectedKey == null) continue;
849
- value = variant.values[selectedKey];
850
- } else if (selectedValue === true) value = variant.shorthand;
851
- if (!value) continue;
852
- if (value.class != null) classesOut.push(value.class);
853
- if (value.style) Object.assign(styleOut, value.style);
854
- }
855
- for (let i = 0; i < functionVariantCount; i++) {
856
- const variantName = functionVariantNames[i];
857
- if (ownSkipKeys && ownSkipKeys.has(variantName)) continue;
858
- const selectedValue = workingResolved[variantName];
859
- if (selectedValue === void 0) continue;
860
- const selectedKey = getVariantValueKey(selectedValue);
861
- if (ownSkipValues && selectedKey != null && ownSkipValues[variantName]?.has(selectedKey)) continue;
862
- const fn = functionVariantFns[i];
863
- const computedResult = fn(selectedValue);
864
- if (computedResult == null) continue;
865
- const r = extractClassAndStylePrebuilt(computedResult);
866
- if (r.class != null) classesOut.push(r.class);
867
- if (r.style) Object.assign(styleOut, r.style);
868
- }
869
- if (cClasses) for (let i = 0; i < cClasses.length; i++) classesOut.push(cClasses[i]);
870
- if (cStyle) Object.assign(styleOut, cStyle);
871
- return workingResolved;
872
- };
873
- const compute = !refine && computedDefaultCount === 0 && extMetasWithRefineCount === 0 ? computeOnce : (resolved, userVariantProps, skipKeys, skipValues, classesOut, styleOut) => {
874
- let remaining = MAX_REFINE_RUNS;
875
- const protectedVariants = {};
876
- const protectedVariantKeys = /* @__PURE__ */ new Set();
877
- const incomingDefaultResolved = resolved;
878
- let workingResolved = resolved;
879
- let unstableChanges = null;
880
- let lastClasses = [];
881
- let lastStyle = {};
882
- let isFirstRun = true;
883
- while (remaining > 0) {
884
- remaining -= 1;
885
- const useDirectOutput = isFirstRun;
886
- const classCount = classesOut.length;
887
- const nextClasses = useDirectOutput ? classesOut : [];
888
- const nextStyle = useDirectOutput ? styleOut : {};
889
- const defaultResolved = mergeProtectedIntoBase(incomingDefaultResolved, protectedVariants, protectedVariantKeys);
890
- const nextResolved = computeOnce(workingResolved, userVariantProps, skipKeys, skipValues, nextClasses, nextStyle, protectedVariants, protectedVariantKeys, defaultResolved);
891
- if (nextResolved === workingResolved || areVariantsEqual(workingResolved, nextResolved)) {
892
- if (nextResolved !== workingResolved) {
893
- if (useDirectOutput) {
894
- classesOut.length = classCount;
895
- for (const key in styleOut) if (hasOwn(styleOut, key)) Reflect.deleteProperty(styleOut, key);
840
+ for (const k in staticExtSkipValues) {
841
+ if (!hasOwn(staticExtSkipValues, k)) continue;
842
+ const values = staticExtSkipValues[k];
843
+ const existing = getOwn(extSkipVals, k);
844
+ if (existing) {
845
+ const merged = new Set(existing);
846
+ for (const v of values) merged.add(v);
847
+ extSkipVals[k] = merged;
848
+ } else extSkipVals[k] = values;
896
849
  }
897
- computeOnce(nextResolved, userVariantProps, skipKeys, skipValues, classesOut, styleOut, protectedVariants, protectedVariantKeys, defaultResolved, true);
898
- } else if (!useDirectOutput) {
899
- for (let i = 0; i < nextClasses.length; i++) classesOut.push(nextClasses[i]);
900
- Object.assign(styleOut, nextStyle);
901
850
  }
902
- return nextResolved;
851
+ for (let i = 0; i < extCount; i++) {
852
+ if (hasIsolatedExt && extIsolated[i]) {
853
+ const extClasses = [];
854
+ workingResolved = extMetas[i].compute(workingResolved, userVariantProps, extSkipKeys, extSkipVals, extClasses, styleOut, protection, defaultResolved, renderOnly);
855
+ if (extClasses.length > 0) {
856
+ const joined = clsx(extClasses);
857
+ if (joined.length > 0) classesOut.push(extMetas[i].transformClass(joined));
858
+ }
859
+ } else workingResolved = extMetas[i].compute(workingResolved, userVariantProps, extSkipKeys, extSkipVals, classesOut, styleOut, protection, defaultResolved, renderOnly);
860
+ workingResolved = filterOwnDisabledVariants(workingResolved, defaultResolved);
861
+ }
903
862
  }
904
- if (process.env.NODE_ENV !== "production" && remaining < 10) {
905
- if (!unstableChanges) unstableChanges = /* @__PURE__ */ new Map();
906
- accumulateUnstableVariantChanges(unstableChanges, workingResolved, nextResolved);
863
+ if (!renderOnly && computedDefaultCount > 0) workingResolved = runComputedDefaults(workingResolved, defaultResolved, userVariantProps, true, protection);
864
+ if (refine) {
865
+ const refineResult = runRefineContext(workingResolved, true, true, !renderOnly, protection);
866
+ workingResolved = refineResult.workingResolved;
867
+ cClasses = refineResult.classes;
868
+ cStyle = refineResult.style;
907
869
  }
908
- if (useDirectOutput) {
909
- classesOut.length = classCount;
910
- for (const key in styleOut) if (hasOwn(styleOut, key)) Reflect.deleteProperty(styleOut, key);
911
- } else {
912
- lastClasses = nextClasses;
913
- lastStyle = nextStyle;
870
+ if (hasBaseStyle) Object.assign(styleOut, baseStyle);
871
+ const ownSkipKeys = skipKeys;
872
+ const ownSkipValues = skipValues;
873
+ for (let i = 0; i < variantEntryCount; i++) {
874
+ const variantName = variantEntryNames[i];
875
+ if (ownSkipKeys && ownSkipKeys.has(variantName)) continue;
876
+ const selectedValue = workingResolved[variantName];
877
+ if (selectedValue === void 0) continue;
878
+ if (!hasOwn(workingResolved, variantName)) continue;
879
+ const selectedKey = getVariantValueKey(selectedValue);
880
+ const variant = variantEntryDefs[i];
881
+ if (variant.disabledValues && selectedKey != null && variant.disabledValues.has(selectedKey)) continue;
882
+ if (ownSkipValues && selectedKey != null && getOwn(ownSkipValues, variantName)?.has(selectedKey)) continue;
883
+ let value;
884
+ if (variant.values) {
885
+ if (selectedKey == null) continue;
886
+ value = variant.values.get(selectedKey);
887
+ } else if (selectedValue === true) value = variant.shorthand;
888
+ if (!value) continue;
889
+ if (value.class != null) classesOut.push(value.class);
890
+ if (value.style) Object.assign(styleOut, value.style);
914
891
  }
915
- workingResolved = nextResolved;
916
- isFirstRun = false;
917
- }
918
- if (process.env.NODE_ENV !== "production") warnRefineLimit({
919
- creationFrame,
920
- unstableChanges
921
- });
922
- for (let i = 0; i < lastClasses.length; i++) classesOut.push(lastClasses[i]);
923
- Object.assign(styleOut, lastStyle);
924
- return workingResolved;
925
- };
926
- const resolveRefineOnce = (resolved, userVariantProps, filterOwnVariants = true, protectedVariants, protectedVariantKeys, defaultResolved = resolved) => {
927
- let workingResolved = resolved;
928
- if (extMetasWithRefineCount > 0) {
929
- const extUserVariantProps = getExtUserVariantProps(userVariantProps, protectedVariants ?? null);
892
+ for (let i = 0; i < functionVariantCount; i++) {
893
+ const variantName = functionVariantNames[i];
894
+ if (ownSkipKeys && ownSkipKeys.has(variantName)) continue;
895
+ const selectedValue = workingResolved[variantName];
896
+ if (selectedValue === void 0) continue;
897
+ if (!hasOwn(workingResolved, variantName)) continue;
898
+ const selectedKey = getVariantValueKey(selectedValue);
899
+ if (ownSkipValues && selectedKey != null && getOwn(ownSkipValues, variantName)?.has(selectedKey)) continue;
900
+ const fn = functionVariantFns[i];
901
+ const computedResult = fn(selectedValue);
902
+ if (computedResult == null) continue;
903
+ const r = extractClassAndStylePrebuilt(computedResult);
904
+ if (r.class != null) classesOut.push(r.class);
905
+ if (r.style) Object.assign(styleOut, r.style);
906
+ }
907
+ if (cClasses) for (let i = 0; i < cClasses.length; i++) classesOut.push(cClasses[i]);
908
+ if (cStyle) Object.assign(styleOut, cStyle);
909
+ return workingResolved;
910
+ };
911
+ const compute = !refine && computedDefaultCount === 0 && extMetasWithRefineCount === 0 ? computeOnce : (resolved, userVariantProps, skipKeys, skipValues, classesOut, styleOut) => {
912
+ let remaining = MAX_REFINE_RUNS;
913
+ const protection = canProtectVariants ? { variants: null } : null;
914
+ const incomingDefaultResolved = resolved;
915
+ let workingResolved = resolved;
916
+ let unstableChanges = null;
917
+ let lastClasses = [];
918
+ let lastStyle = {};
919
+ let isFirstRun = true;
920
+ while (remaining > 0) {
921
+ remaining -= 1;
922
+ const useDirectOutput = isFirstRun;
923
+ const classCount = classesOut.length;
924
+ const nextClasses = useDirectOutput ? classesOut : [];
925
+ const nextStyle = useDirectOutput ? styleOut : {};
926
+ const defaultResolved = mergeProtectedIntoBase(incomingDefaultResolved, protection);
927
+ const nextResolved = computeOnce(workingResolved, userVariantProps, skipKeys, skipValues, nextClasses, nextStyle, protection, defaultResolved);
928
+ if (nextResolved === workingResolved || areVariantsEqual(workingResolved, nextResolved)) {
929
+ if (nextResolved !== workingResolved) {
930
+ if (useDirectOutput) {
931
+ classesOut.length = classCount;
932
+ for (const key in styleOut) if (hasOwn(styleOut, key)) Reflect.deleteProperty(styleOut, key);
933
+ }
934
+ computeOnce(nextResolved, userVariantProps, skipKeys, skipValues, classesOut, styleOut, protection, defaultResolved, true);
935
+ } else if (!useDirectOutput) {
936
+ for (let i = 0; i < nextClasses.length; i++) classesOut.push(nextClasses[i]);
937
+ Object.assign(styleOut, nextStyle);
938
+ }
939
+ return nextResolved;
940
+ }
941
+ if (remaining < 10 && process.env.NODE_ENV !== "production") {
942
+ if (!unstableChanges) unstableChanges = /* @__PURE__ */ new Map();
943
+ accumulateUnstableVariantChanges(unstableChanges, workingResolved, nextResolved);
944
+ }
945
+ if (useDirectOutput) {
946
+ classesOut.length = classCount;
947
+ for (const key in styleOut) if (hasOwn(styleOut, key)) Reflect.deleteProperty(styleOut, key);
948
+ } else {
949
+ lastClasses = nextClasses;
950
+ lastStyle = nextStyle;
951
+ }
952
+ workingResolved = nextResolved;
953
+ isFirstRun = false;
954
+ }
955
+ if (process.env.NODE_ENV !== "production") warnRefineLimit({
956
+ creationFrame,
957
+ unstableChanges
958
+ });
959
+ for (let i = 0; i < lastClasses.length; i++) classesOut.push(lastClasses[i]);
960
+ Object.assign(styleOut, lastStyle);
961
+ return workingResolved;
962
+ };
963
+ const resolveRefineOnce = (resolved, userVariantProps, filterOwnVariants = true, protection, defaultResolved = resolved) => {
964
+ let workingResolved = resolved;
930
965
  for (let i = 0; i < extMetasWithRefineCount; i++) {
931
966
  const resolveRefine = extMetasWithRefine[i].resolveRefine;
932
967
  if (!resolveRefine) continue;
933
- workingResolved = resolveRefine(workingResolved, extUserVariantProps, true, protectedVariants, protectedVariantKeys, defaultResolved);
968
+ workingResolved = resolveRefine(workingResolved, userVariantProps, true, protection, defaultResolved);
934
969
  workingResolved = filterOwnDisabledVariants(workingResolved, defaultResolved);
935
- if (protectedVariants) Object.assign(extUserVariantProps, protectedVariants);
936
970
  }
937
- }
938
- if (computedDefaultCount > 0) workingResolved = runComputedDefaults(workingResolved, defaultResolved, userVariantProps, filterOwnVariants, protectedVariantKeys);
939
- if (refine) workingResolved = runRefineContext(workingResolved, filterOwnVariants, false, true, protectedVariants, protectedVariantKeys).workingResolved;
940
- return workingResolved;
941
- };
942
- const resolveRefine = refine || computedDefaultCount > 0 || extMetasWithRefineCount > 0 ? (resolved, userVariantProps, filterOwnVariants = true) => {
943
- let remaining = MAX_REFINE_RUNS;
944
- const protectedVariants = {};
945
- const protectedVariantKeys = /* @__PURE__ */ new Set();
946
- const incomingDefaultResolved = resolved;
947
- let workingResolved = resolved;
948
- let unstableChanges = null;
949
- while (remaining > 0) {
950
- remaining -= 1;
951
- const defaultResolved = mergeProtectedIntoBase(incomingDefaultResolved, protectedVariants, protectedVariantKeys);
952
- const nextResolved = resolveRefineOnce(workingResolved, userVariantProps, filterOwnVariants, protectedVariants, protectedVariantKeys, defaultResolved);
953
- if (nextResolved === workingResolved || areVariantsEqual(workingResolved, nextResolved)) return nextResolved;
954
- if (process.env.NODE_ENV !== "production" && remaining < 10) {
955
- if (!unstableChanges) unstableChanges = /* @__PURE__ */ new Map();
956
- accumulateUnstableVariantChanges(unstableChanges, workingResolved, nextResolved);
971
+ if (computedDefaultCount > 0) workingResolved = runComputedDefaults(workingResolved, defaultResolved, userVariantProps, filterOwnVariants, protection);
972
+ if (refine) workingResolved = runRefineContext(workingResolved, filterOwnVariants, false, true, protection).workingResolved;
973
+ return workingResolved;
974
+ };
975
+ const resolveRefine = refine || computedDefaultCount > 0 || extMetasWithRefineCount > 0 ? (resolved, userVariantProps, filterOwnVariants = true) => {
976
+ let remaining = MAX_REFINE_RUNS;
977
+ const protection = canProtectVariants ? { variants: null } : null;
978
+ const incomingDefaultResolved = resolved;
979
+ let workingResolved = resolved;
980
+ let unstableChanges = null;
981
+ while (remaining > 0) {
982
+ remaining -= 1;
983
+ const defaultResolved = mergeProtectedIntoBase(incomingDefaultResolved, protection);
984
+ const nextResolved = resolveRefineOnce(workingResolved, userVariantProps, filterOwnVariants, protection, defaultResolved);
985
+ if (nextResolved === workingResolved || areVariantsEqual(workingResolved, nextResolved)) return nextResolved;
986
+ if (remaining < 10 && process.env.NODE_ENV !== "production") {
987
+ if (!unstableChanges) unstableChanges = /* @__PURE__ */ new Map();
988
+ accumulateUnstableVariantChanges(unstableChanges, workingResolved, nextResolved);
989
+ }
990
+ workingResolved = nextResolved;
957
991
  }
958
- workingResolved = nextResolved;
959
- }
960
- if (process.env.NODE_ENV !== "production") warnRefineLimit({
961
- creationFrame,
962
- unstableChanges
963
- });
964
- return workingResolved;
965
- } : null;
966
- const computeResult = (props = EMPTY_DEFAULTS) => {
967
- const propsRecord = props;
968
- let resolved = {};
969
- Object.assign(resolved, staticDefaults);
970
- let userVariantProps;
971
- if (refine || computedDefaultCount > 0 || extMetasWithRefineCount > 0) {
972
- const variantProps = {};
973
- for (let i = 0; i < variantKeysLength; i++) {
974
- const key = variantKeys[i];
975
- if (hasOwn(propsRecord, key)) variantProps[key] = propsRecord[key];
992
+ if (process.env.NODE_ENV !== "production") warnRefineLimit({
993
+ creationFrame,
994
+ unstableChanges
995
+ });
996
+ return workingResolved;
997
+ } : null;
998
+ const computeResult = (props = EMPTY_DEFAULTS) => {
999
+ const propsRecord = props;
1000
+ let resolved = {};
1001
+ Object.assign(resolved, staticDefaults);
1002
+ let userVariantProps;
1003
+ if (needsUserVariantProps) {
1004
+ const variantProps = {};
1005
+ for (let i = 0; i < variantKeysLength; i++) {
1006
+ const key = variantKeys[i];
1007
+ if (!hasOwn(propsRecord, key)) continue;
1008
+ const value = propsRecord[key];
1009
+ variantProps[key] = value;
1010
+ if (value === void 0) continue;
1011
+ resolved[key] = value;
1012
+ }
1013
+ userVariantProps = variantProps;
1014
+ } else {
1015
+ for (let i = 0; i < variantKeysLength; i++) {
1016
+ const key = variantKeys[i];
1017
+ if (!hasOwn(propsRecord, key)) continue;
1018
+ const v = propsRecord[key];
1019
+ if (v === void 0) continue;
1020
+ resolved[key] = v;
1021
+ }
1022
+ userVariantProps = propsRecord;
976
1023
  }
977
- for (const k in variantProps) {
978
- if (!hasOwn(variantProps, k)) continue;
979
- const v = variantProps[k];
980
- if (v === void 0) continue;
981
- resolved[k] = v;
1024
+ if (hasAnyDisabled) {
1025
+ const filtered = {};
1026
+ filterDisabledInto(resolved, filtered);
1027
+ resolved = filtered;
982
1028
  }
983
- userVariantProps = variantProps;
984
- } else {
985
- for (let i = 0; i < variantKeysLength; i++) {
986
- const key = variantKeys[i];
987
- if (!hasOwn(propsRecord, key)) continue;
988
- const v = propsRecord[key];
989
- if (v === void 0) continue;
990
- resolved[key] = v;
1029
+ const allClasses = [computedBaseClass];
1030
+ const style = {};
1031
+ compute(resolved, userVariantProps, null, null, allClasses, style);
1032
+ if (hasOwn(propsRecord, "class")) allClasses.push(propsRecord.class);
1033
+ if (hasOwn(propsRecord, "className")) allClasses.push(propsRecord.className);
1034
+ const psv = propsRecord.style;
1035
+ if (psv != null && hasOwn(propsRecord, "style")) {
1036
+ if (typeof psv === "string") {
1037
+ if (psv.length > 0) htmlStyleToStyleValue(psv, style);
1038
+ } else if (typeof psv === "object") htmlObjStyleToStyleValue(psv, style);
991
1039
  }
992
- userVariantProps = propsRecord;
993
- }
994
- if (hasAnyDisabled) {
995
- const filtered = {};
996
- filterDisabledInto(resolved, filtered);
997
- resolved = filtered;
998
- }
999
- const allClasses = [computedBaseClass];
1000
- const style = {};
1001
- compute(resolved, userVariantProps, null, null, allClasses, style);
1002
- if ("class" in propsRecord) allClasses.push(propsRecord.class);
1003
- if ("className" in propsRecord) allClasses.push(propsRecord.className);
1004
- const psv = propsRecord.style;
1005
- if (psv != null) {
1006
- if (typeof psv === "string") {
1007
- if (psv.length > 0) htmlStyleToStyleValue(psv, style);
1008
- } else if (typeof psv === "object") htmlObjStyleToStyleValue(psv, style);
1009
- }
1010
- return {
1011
- className: transformClass(clsx(allClasses)),
1012
- style
1040
+ return {
1041
+ className: transformClass(clsx(allClasses)),
1042
+ style
1043
+ };
1013
1044
  };
1014
- };
1015
- const getVariants = (variants) => {
1016
- const variantsRecord = variants ?? EMPTY_DEFAULTS;
1017
- let variantProps = variantsRecord;
1018
- if (variants && extMetasWithRefineCount > 0) {
1019
- variantProps = {};
1020
- for (let i = 0; i < variantKeysLength; i++) {
1021
- const key = variantKeys[i];
1022
- if (hasOwn(variantsRecord, key)) variantProps[key] = variantsRecord[key];
1045
+ const getVariants = (variants) => {
1046
+ const variantsRecord = variants ?? EMPTY_DEFAULTS;
1047
+ let variantProps = variantsRecord;
1048
+ if (variants && extMetasWithRefineCount > 0) {
1049
+ variantProps = {};
1050
+ for (let i = 0; i < variantKeysLength; i++) {
1051
+ const key = variantKeys[i];
1052
+ if (hasOwn(variantsRecord, key)) variantProps[key] = variantsRecord[key];
1053
+ }
1023
1054
  }
1024
- }
1025
- let resolvedVariants = resolveVariantsHot(variantProps);
1026
- if (resolveRefine) resolvedVariants = resolveRefine(resolvedVariants, variantProps, false);
1027
- return resolvedVariants;
1028
- };
1029
- const computedBaseClass = hasExtend ? clsx(extBaseClassesArr, config.class) : clsx(config.class);
1030
- const classFn = (props = {}) => {
1031
- return computeResult(props).className;
1032
- };
1033
- const meta = {
1034
- baseClass: computedBaseClass,
1035
- staticDefaults,
1036
- compute: computeOnce,
1037
- resolveRefine: resolveRefine ? resolveRefineOnce : null,
1038
- transformClass,
1039
- functionVariantKeys,
1040
- computedDefaultKeys
1041
- };
1042
- const initComponent = (c, propKeys, style) => {
1043
- c.class = classFn;
1044
- c.style = style;
1045
- c.getVariants = getVariants;
1046
- c.variantKeys = variantKeys;
1047
- c.propKeys = propKeys;
1048
- c[META_KEY] = meta;
1049
- return c;
1050
- };
1051
- const defaultComponent = ((props = {}) => {
1052
- const { className, style } = computeResult(props);
1053
- return {
1054
- class: className,
1055
- style
1055
+ let resolvedVariants = resolveVariantsHot(variantProps);
1056
+ if (resolveRefine) resolvedVariants = resolveRefine(resolvedVariants, variantProps, false);
1057
+ return resolvedVariants;
1056
1058
  };
1057
- });
1058
- initComponent(defaultComponent, inputPropsKeys, (props = {}) => {
1059
- return computeResult(props).style;
1060
- });
1061
- const jsxComponent = ((props = {}) => {
1062
- const { className, style } = computeResult(props);
1063
- return {
1064
- className,
1065
- style
1059
+ const computedBaseClass = hasExtend ? clsx(extBaseClassesArr, baseClass) : baseClass;
1060
+ const classFn = (props = {}) => {
1061
+ return computeResult(props).className;
1066
1062
  };
1067
- });
1068
- initComponent(jsxComponent, [
1069
- "className",
1070
- "style",
1071
- ...variantKeys
1072
- ], (props = {}) => computeResult(props).style);
1073
- const htmlComponent = ((props = {}) => {
1074
- const { className, style } = computeResult(props);
1075
- return {
1076
- class: className,
1077
- style: styleValueToHTMLStyle(style)
1063
+ const meta = {
1064
+ identity,
1065
+ extends: extMetas,
1066
+ rebuild: (extensions) => build(extensions).meta,
1067
+ baseClass: computedBaseClass,
1068
+ staticDefaults,
1069
+ compute: computeOnce,
1070
+ resolveRefine: resolveRefine ? resolveRefineOnce : null,
1071
+ transformClass,
1072
+ functionVariantKeys,
1073
+ computedDefaultKeys
1078
1074
  };
1079
- });
1080
- initComponent(htmlComponent, [
1081
- "class",
1082
- "style",
1083
- ...variantKeys
1084
- ], (props = {}) => styleValueToHTMLStyle(computeResult(props).style));
1085
- const htmlObjComponent = ((props = {}) => {
1086
- const { className, style } = computeResult(props);
1075
+ const initComponent = (c, propKeys, style) => {
1076
+ c.class = classFn;
1077
+ c.style = style;
1078
+ c.getVariants = getVariants;
1079
+ c.variantKeys = variantKeys;
1080
+ c.propKeys = propKeys;
1081
+ c[META_KEY] = meta;
1082
+ return c;
1083
+ };
1084
+ const defaultComponent = ((props = {}) => {
1085
+ const { className, style } = computeResult(props);
1086
+ return {
1087
+ class: className,
1088
+ style
1089
+ };
1090
+ });
1091
+ initComponent(defaultComponent, inputPropsKeys, (props = {}) => {
1092
+ return computeResult(props).style;
1093
+ });
1094
+ const jsxComponent = ((props = {}) => {
1095
+ const { className, style } = computeResult(props);
1096
+ return {
1097
+ className,
1098
+ style
1099
+ };
1100
+ });
1101
+ initComponent(jsxComponent, [
1102
+ "className",
1103
+ "style",
1104
+ ...variantKeys
1105
+ ], (props = {}) => computeResult(props).style);
1106
+ const htmlComponent = ((props = {}) => {
1107
+ const { className, style } = computeResult(props);
1108
+ return {
1109
+ class: className,
1110
+ style: styleValueToHTMLStyle(style)
1111
+ };
1112
+ });
1113
+ initComponent(htmlComponent, [
1114
+ "class",
1115
+ "style",
1116
+ ...variantKeys
1117
+ ], (props = {}) => styleValueToHTMLStyle(computeResult(props).style));
1118
+ const htmlObjComponent = ((props = {}) => {
1119
+ const { className, style } = computeResult(props);
1120
+ return {
1121
+ class: className,
1122
+ style: styleValueToHTMLObjStyle(style)
1123
+ };
1124
+ });
1125
+ initComponent(htmlObjComponent, [
1126
+ "class",
1127
+ "style",
1128
+ ...variantKeys
1129
+ ], (props = {}) => styleValueToHTMLObjStyle(computeResult(props).style));
1130
+ defaultComponent.jsx = jsxComponent;
1131
+ defaultComponent.html = htmlComponent;
1132
+ defaultComponent.htmlObj = htmlObjComponent;
1087
1133
  return {
1088
- class: className,
1089
- style: styleValueToHTMLObjStyle(style)
1134
+ component: defaultComponent,
1135
+ meta
1090
1136
  };
1091
- });
1092
- initComponent(htmlObjComponent, [
1093
- "class",
1094
- "style",
1095
- ...variantKeys
1096
- ], (props = {}) => styleValueToHTMLObjStyle(computeResult(props).style));
1097
- defaultComponent.jsx = jsxComponent;
1098
- defaultComponent.html = htmlComponent;
1099
- defaultComponent.htmlObj = htmlObjComponent;
1100
- return defaultComponent;
1137
+ };
1138
+ return build(initialExtensions);
1101
1139
  };
1140
+ const cv = (config = {}) => buildComponent(config).component;
1102
1141
  return {
1103
1142
  cv,
1104
1143
  cx