clava 0.6.2 → 0.6.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 +22 -0
- package/README.md +28 -11
- package/dist/index.d.ts +1 -1
- package/dist/index.js +127 -129
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/index.ts +243 -202
- package/src/refine-warning.ts +4 -3
- package/src/utils.ts +14 -0
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",
|
|
@@ -280,7 +284,8 @@ function setVariantChange(into, key, from, to) {
|
|
|
280
284
|
function accumulateUnstableVariantChanges(into, prev, next) {
|
|
281
285
|
for (const key in next) {
|
|
282
286
|
if (!hasOwn(next, key)) continue;
|
|
283
|
-
|
|
287
|
+
const from = getOwn(prev, key);
|
|
288
|
+
if (!Object.is(from, next[key])) setVariantChange(into, key, from, next[key]);
|
|
284
289
|
}
|
|
285
290
|
for (const key in prev) {
|
|
286
291
|
if (!hasOwn(prev, key)) continue;
|
|
@@ -312,23 +317,27 @@ const META_KEY = "__meta";
|
|
|
312
317
|
const EMPTY_DEFAULTS = {};
|
|
313
318
|
const MAX_REFINE_RUNS = 50;
|
|
314
319
|
function areVariantsEqual(a, b) {
|
|
320
|
+
let ownKeyDifference = 0;
|
|
315
321
|
for (const key in a) {
|
|
316
322
|
if (!hasOwn(a, key)) continue;
|
|
323
|
+
if (!hasOwn(b, key)) return false;
|
|
317
324
|
if (!Object.is(a[key], b[key])) return false;
|
|
325
|
+
ownKeyDifference++;
|
|
318
326
|
}
|
|
319
327
|
for (const key in b) {
|
|
320
328
|
if (!hasOwn(b, key)) continue;
|
|
321
|
-
|
|
329
|
+
ownKeyDifference--;
|
|
322
330
|
}
|
|
323
|
-
return
|
|
324
|
-
}
|
|
325
|
-
function getExtUserVariantProps(userVariantProps, protectedVariants) {
|
|
326
|
-
return Object.assign({}, userVariantProps, protectedVariants);
|
|
331
|
+
return ownKeyDifference === 0;
|
|
327
332
|
}
|
|
328
|
-
function mergeProtectedIntoBase(baseResolved,
|
|
329
|
-
|
|
333
|
+
function mergeProtectedIntoBase(baseResolved, protection) {
|
|
334
|
+
const protectedVariants = protection?.variants;
|
|
335
|
+
if (!protectedVariants) return baseResolved;
|
|
330
336
|
return Object.assign({}, baseResolved, protectedVariants);
|
|
331
337
|
}
|
|
338
|
+
function identityClass(className) {
|
|
339
|
+
return className;
|
|
340
|
+
}
|
|
332
341
|
function isRecordObject(value) {
|
|
333
342
|
if (typeof value !== "object") return false;
|
|
334
343
|
if (value == null) return false;
|
|
@@ -345,14 +354,16 @@ function extractClassAndStylePrebuilt(value) {
|
|
|
345
354
|
class: value,
|
|
346
355
|
style: null
|
|
347
356
|
};
|
|
348
|
-
|
|
357
|
+
const styleClassValue = value;
|
|
358
|
+
const classValue = hasOwn(value, "class") ? styleClassValue.class : void 0;
|
|
359
|
+
const styleValue = hasOwn(value, "style") ? styleClassValue.style : void 0;
|
|
360
|
+
if (classValue === void 0 && styleValue === void 0) return {
|
|
349
361
|
class: null,
|
|
350
362
|
style: null
|
|
351
363
|
};
|
|
352
|
-
const
|
|
353
|
-
const style = normalizeStyle(styleClassValue.style);
|
|
364
|
+
const style = normalizeStyle(styleValue);
|
|
354
365
|
return {
|
|
355
|
-
class:
|
|
366
|
+
class: classValue ?? null,
|
|
356
367
|
style: Object.keys(style).length > 0 ? style : null
|
|
357
368
|
};
|
|
358
369
|
}
|
|
@@ -430,7 +441,7 @@ function buildPrebuiltVariant(variantDef) {
|
|
|
430
441
|
shorthand: extractClassAndStylePrebuilt(variantDef),
|
|
431
442
|
disabledValues: null
|
|
432
443
|
};
|
|
433
|
-
const values =
|
|
444
|
+
const values = /* @__PURE__ */ new Map();
|
|
434
445
|
let disabledValues = null;
|
|
435
446
|
for (const key in variantDef) {
|
|
436
447
|
if (!hasOwn(variantDef, key)) continue;
|
|
@@ -440,7 +451,7 @@ function buildPrebuiltVariant(variantDef) {
|
|
|
440
451
|
disabledValues.add(key);
|
|
441
452
|
continue;
|
|
442
453
|
}
|
|
443
|
-
values
|
|
454
|
+
values.set(key, extractClassAndStylePrebuilt(value));
|
|
444
455
|
}
|
|
445
456
|
return {
|
|
446
457
|
values,
|
|
@@ -448,15 +459,17 @@ function buildPrebuiltVariant(variantDef) {
|
|
|
448
459
|
disabledValues
|
|
449
460
|
};
|
|
450
461
|
}
|
|
451
|
-
function create(
|
|
462
|
+
function create(params = {}) {
|
|
463
|
+
const transformClass = getOwn(params, "transformClass") ?? identityClass;
|
|
452
464
|
const cx = (...classes) => transformClass(clsx(classes));
|
|
453
465
|
const cv = (config = {}) => {
|
|
454
|
-
const extend = config
|
|
466
|
+
const extend = getOwn(config, "extend");
|
|
455
467
|
const hasExtend = !!extend && extend.length > 0;
|
|
456
|
-
const variants = config
|
|
457
|
-
const refine = config
|
|
458
|
-
const baseStyle = config
|
|
468
|
+
const variants = getOwn(config, "variants");
|
|
469
|
+
const refine = getOwn(config, "refine");
|
|
470
|
+
const baseStyle = getOwn(config, "style");
|
|
459
471
|
const hasBaseStyle = !!baseStyle;
|
|
472
|
+
const baseClass = getOwn(config, "class");
|
|
460
473
|
const variantKeySet = /* @__PURE__ */ new Set();
|
|
461
474
|
const staticDefaults = {};
|
|
462
475
|
const extMetas = [];
|
|
@@ -483,8 +496,7 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
483
496
|
}
|
|
484
497
|
const extCount = extMetas.length;
|
|
485
498
|
const disabledVariantKeys = /* @__PURE__ */ new Set();
|
|
486
|
-
|
|
487
|
-
let hasDisabledVariantValues = false;
|
|
499
|
+
let disabledValuesBuilder = null;
|
|
488
500
|
const variantEntryNames = [];
|
|
489
501
|
const variantEntryDefs = [];
|
|
490
502
|
const functionVariantNames = [];
|
|
@@ -507,17 +519,18 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
507
519
|
variantEntryNames.push(name);
|
|
508
520
|
variantEntryDefs.push(prebuiltVariant);
|
|
509
521
|
if (prebuiltVariant.disabledValues) {
|
|
510
|
-
|
|
511
|
-
|
|
522
|
+
disabledValuesBuilder ??= {};
|
|
523
|
+
disabledValuesBuilder[name] = prebuiltVariant.disabledValues;
|
|
512
524
|
}
|
|
513
|
-
if (prebuiltVariant.values
|
|
525
|
+
if (prebuiltVariant.values?.has("false") && !hasOwn(staticDefaults, name)) staticDefaults[name] = false;
|
|
514
526
|
}
|
|
515
527
|
const variantKeys = Array.from(variantKeySet);
|
|
516
528
|
const variantKeysLength = variantKeys.length;
|
|
517
529
|
const variantEntryCount = variantEntryNames.length;
|
|
518
530
|
const functionVariantCount = functionVariantNames.length;
|
|
519
531
|
const hasDisabledVariantKeys = disabledVariantKeys.size > 0;
|
|
520
|
-
const
|
|
532
|
+
const disabledVariantValues = disabledValuesBuilder;
|
|
533
|
+
const hasAnyDisabled = hasDisabledVariantKeys || disabledVariantValues !== null;
|
|
521
534
|
const inputPropsKeys = [
|
|
522
535
|
"class",
|
|
523
536
|
"className",
|
|
@@ -526,7 +539,7 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
526
539
|
];
|
|
527
540
|
const computedDefaultNames = [];
|
|
528
541
|
const computedDefaultFns = [];
|
|
529
|
-
const defaultVariants = config
|
|
542
|
+
const defaultVariants = getOwn(config, "defaultVariants");
|
|
530
543
|
if (defaultVariants) for (const name in defaultVariants) {
|
|
531
544
|
if (!hasOwn(defaultVariants, name)) continue;
|
|
532
545
|
const value = defaultVariants[name];
|
|
@@ -548,10 +561,10 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
548
561
|
delete staticDefaults[key];
|
|
549
562
|
continue;
|
|
550
563
|
}
|
|
551
|
-
if (
|
|
564
|
+
if (disabledVariantValues) {
|
|
552
565
|
const value = staticDefaults[key];
|
|
553
566
|
const valueKey = getVariantValueKey(value);
|
|
554
|
-
if (valueKey != null && disabledVariantValues
|
|
567
|
+
if (valueKey != null && getOwn(disabledVariantValues, key)?.has(valueKey)) delete staticDefaults[key];
|
|
555
568
|
}
|
|
556
569
|
}
|
|
557
570
|
const inheritedComputedDefaultKeys = /* @__PURE__ */ new Set();
|
|
@@ -565,6 +578,8 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
565
578
|
if (meta.resolveRefine) extMetasWithRefine.push(meta);
|
|
566
579
|
}
|
|
567
580
|
const extMetasWithRefineCount = extMetasWithRefine.length;
|
|
581
|
+
const canProtectVariants = !!refine || extMetasWithRefineCount > 0;
|
|
582
|
+
const needsUserVariantProps = computedDefaultCount > 0 || inheritedComputedDefaultKeys.size > 0;
|
|
568
583
|
const creationFrame = (!!refine || computedDefaultCount > 0 || extMetasWithRefineCount > 0) && process.env.NODE_ENV !== "production" ? captureCreationFrame(cv) : void 0;
|
|
569
584
|
const functionVariantKeys = /* @__PURE__ */ new Set();
|
|
570
585
|
for (let i = 0; i < extCount; i++) {
|
|
@@ -592,24 +607,24 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
592
607
|
break;
|
|
593
608
|
}
|
|
594
609
|
}
|
|
595
|
-
const staticExtSkipValues =
|
|
610
|
+
const staticExtSkipValues = disabledVariantValues;
|
|
596
611
|
function filterDisabledInto(input, out) {
|
|
597
612
|
for (const key in input) {
|
|
598
613
|
if (!hasOwn(input, key)) continue;
|
|
599
614
|
if (disabledVariantKeys.has(key)) continue;
|
|
600
615
|
const value = input[key];
|
|
601
|
-
if (
|
|
616
|
+
if (disabledVariantValues) {
|
|
602
617
|
const valueKey = getVariantValueKey(value);
|
|
603
|
-
if (valueKey != null && disabledVariantValues
|
|
618
|
+
if (valueKey != null && getOwn(disabledVariantValues, key)?.has(valueKey)) continue;
|
|
604
619
|
}
|
|
605
620
|
out[key] = value;
|
|
606
621
|
}
|
|
607
622
|
}
|
|
608
623
|
const isOwnDisabledValue = (key, value) => {
|
|
609
624
|
if (disabledVariantKeys.has(key)) return true;
|
|
610
|
-
if (
|
|
625
|
+
if (disabledVariantValues) {
|
|
611
626
|
const valueKey = getVariantValueKey(value);
|
|
612
|
-
if (valueKey != null && disabledVariantValues
|
|
627
|
+
if (valueKey != null && getOwn(disabledVariantValues, key)?.has(valueKey)) return true;
|
|
613
628
|
}
|
|
614
629
|
return false;
|
|
615
630
|
};
|
|
@@ -633,7 +648,7 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
633
648
|
filtered[key] = value;
|
|
634
649
|
continue;
|
|
635
650
|
}
|
|
636
|
-
const fallbackValue = fallback
|
|
651
|
+
const fallbackValue = getOwn(fallback, key);
|
|
637
652
|
if (fallbackValue !== void 0 && !isOwnDisabledValue(key, fallbackValue)) filtered[key] = fallbackValue;
|
|
638
653
|
}
|
|
639
654
|
return filtered;
|
|
@@ -652,7 +667,8 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
652
667
|
filterDisabledInto(defaults, result);
|
|
653
668
|
return result;
|
|
654
669
|
}
|
|
655
|
-
const runComputedDefaults = (resolved, defaultResolved, userVariantProps, filterOwnVariants,
|
|
670
|
+
const runComputedDefaults = (resolved, defaultResolved, userVariantProps, filterOwnVariants, protection) => {
|
|
671
|
+
const protectedVariants = protection?.variants;
|
|
656
672
|
let ownVariants = filterOwnVariants ? null : resolved;
|
|
657
673
|
const getOwnVariants = () => {
|
|
658
674
|
if (ownVariants) return ownVariants;
|
|
@@ -676,26 +692,28 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
676
692
|
if (hasOwn(userVariantProps, key)) {
|
|
677
693
|
if (userVariantProps[key] !== void 0) continue;
|
|
678
694
|
}
|
|
679
|
-
if (
|
|
695
|
+
if (protectedVariants && hasOwn(protectedVariants, key)) continue;
|
|
680
696
|
const variantSnapshot = getOwnVariants();
|
|
681
|
-
const defaultValue = inheritedComputedDefaultKeys.has(key) ? variantSnapshot
|
|
697
|
+
const defaultValue = inheritedComputedDefaultKeys.has(key) ? getOwn(variantSnapshot, key) : getOwn(defaultResolved, key);
|
|
682
698
|
const value = computedDefaultFns[i](defaultValue, variantSnapshot);
|
|
683
699
|
if (hasAnyDisabled) {
|
|
684
700
|
if (disabledVariantKeys.has(key)) continue;
|
|
685
|
-
|
|
686
|
-
|
|
701
|
+
if (disabledVariantValues) {
|
|
702
|
+
const valueKey = getVariantValueKey(value);
|
|
703
|
+
if (valueKey != null && getOwn(disabledVariantValues, key)?.has(valueKey)) continue;
|
|
704
|
+
}
|
|
687
705
|
}
|
|
688
706
|
if (value === void 0) {
|
|
689
707
|
if (!hasOwn(variantSnapshot, key)) continue;
|
|
690
708
|
delete ensureUpdated()[key];
|
|
691
709
|
continue;
|
|
692
710
|
}
|
|
693
|
-
if (Object.is(variantSnapshot
|
|
711
|
+
if (Object.is(getOwn(variantSnapshot, key), value)) continue;
|
|
694
712
|
ensureUpdated()[key] = value;
|
|
695
713
|
}
|
|
696
714
|
return updatedVariants ?? resolved;
|
|
697
715
|
};
|
|
698
|
-
const runRefineContext = (resolved, filterOwnVariants, collectOutput, applyVariantUpdates,
|
|
716
|
+
const runRefineContext = (resolved, filterOwnVariants, collectOutput, applyVariantUpdates, protection) => {
|
|
699
717
|
let workingResolved = resolved;
|
|
700
718
|
let cClasses = null;
|
|
701
719
|
let cStyle = null;
|
|
@@ -709,73 +727,56 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
709
727
|
}
|
|
710
728
|
ownVariants = filteredVariants;
|
|
711
729
|
}
|
|
712
|
-
let
|
|
713
|
-
|
|
730
|
+
let assignedVariants = null;
|
|
731
|
+
let localCClasses = null;
|
|
714
732
|
let localCStyle = null;
|
|
715
|
-
const ensureUpdated = () => {
|
|
716
|
-
if (updatedVariants) return updatedVariants;
|
|
717
|
-
const u = Object.assign({}, ownVariants);
|
|
718
|
-
updatedVariants = u;
|
|
719
|
-
return u;
|
|
720
|
-
};
|
|
721
|
-
const protectVariant = (key, value) => {
|
|
722
|
-
if (protectedVariants) {
|
|
723
|
-
protectedVariants[key] = value;
|
|
724
|
-
protectedVariantKeys?.add(key);
|
|
725
|
-
}
|
|
726
|
-
};
|
|
727
733
|
const result = refine({
|
|
728
734
|
variants: ownVariants,
|
|
729
735
|
setVariants: (newVariants) => {
|
|
730
736
|
if (!applyVariantUpdates) return;
|
|
731
|
-
if (!hasAnyDisabled) {
|
|
732
|
-
for (const key in newVariants) {
|
|
733
|
-
if (!hasOwn(newVariants, key)) continue;
|
|
734
|
-
const value = newVariants[key];
|
|
735
|
-
protectVariant(key, value);
|
|
736
|
-
if (Object.is((updatedVariants ?? ownVariants)[key], value)) continue;
|
|
737
|
-
ensureUpdated()[key] = value;
|
|
738
|
-
}
|
|
739
|
-
return;
|
|
740
|
-
}
|
|
741
737
|
for (const key in newVariants) {
|
|
742
738
|
if (!hasOwn(newVariants, key)) continue;
|
|
743
739
|
if (disabledVariantKeys.has(key)) continue;
|
|
744
740
|
const value = newVariants[key];
|
|
745
|
-
if (
|
|
741
|
+
if (disabledVariantValues) {
|
|
746
742
|
const valueKey = getVariantValueKey(value);
|
|
747
|
-
if (valueKey != null && disabledVariantValues
|
|
743
|
+
if (valueKey != null && getOwn(disabledVariantValues, key)?.has(valueKey)) continue;
|
|
748
744
|
}
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
745
|
+
if (protection) {
|
|
746
|
+
const protectedVariants = protection.variants ??= {};
|
|
747
|
+
protectedVariants[key] = value;
|
|
748
|
+
}
|
|
749
|
+
const current = assignedVariants && hasOwn(assignedVariants, key) ? assignedVariants[key] : getOwn(ownVariants, key);
|
|
750
|
+
if (Object.is(current, value)) continue;
|
|
751
|
+
assignedVariants ??= {};
|
|
752
|
+
assignedVariants[key] = value;
|
|
752
753
|
}
|
|
753
754
|
},
|
|
754
755
|
addClass: (className) => {
|
|
755
|
-
|
|
756
|
+
if (!collectOutput) return;
|
|
757
|
+
localCClasses ??= [];
|
|
758
|
+
localCClasses.push(className);
|
|
756
759
|
},
|
|
757
760
|
addStyle: (newStyle) => {
|
|
758
761
|
if (!collectOutput) return;
|
|
759
|
-
|
|
762
|
+
localCStyle ??= {};
|
|
760
763
|
Object.assign(localCStyle, newStyle);
|
|
761
764
|
}
|
|
762
765
|
});
|
|
763
766
|
if (collectOutput && result != null) {
|
|
764
767
|
const r = extractClassAndStylePrebuilt(result);
|
|
765
|
-
if (r.class != null)
|
|
768
|
+
if (r.class != null) {
|
|
769
|
+
localCClasses ??= [];
|
|
770
|
+
localCClasses.push(r.class);
|
|
771
|
+
}
|
|
766
772
|
if (r.style) {
|
|
767
|
-
|
|
773
|
+
localCStyle ??= {};
|
|
768
774
|
Object.assign(localCStyle, r.style);
|
|
769
775
|
}
|
|
770
776
|
}
|
|
771
777
|
cClasses = localCClasses;
|
|
772
778
|
cStyle = localCStyle;
|
|
773
|
-
if (
|
|
774
|
-
const nextResolved = Object.assign({}, workingResolved);
|
|
775
|
-
if (hasAnyDisabled) filterDisabledInto(updatedVariants, nextResolved);
|
|
776
|
-
else Object.assign(nextResolved, updatedVariants);
|
|
777
|
-
workingResolved = nextResolved;
|
|
778
|
-
}
|
|
779
|
+
if (assignedVariants) workingResolved = Object.assign({}, workingResolved, assignedVariants);
|
|
779
780
|
}
|
|
780
781
|
return {
|
|
781
782
|
workingResolved,
|
|
@@ -783,7 +784,7 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
783
784
|
style: cStyle
|
|
784
785
|
};
|
|
785
786
|
};
|
|
786
|
-
const computeOnce = (resolved, userVariantProps, skipKeys, skipValues, classesOut, styleOut,
|
|
787
|
+
const computeOnce = (resolved, userVariantProps, skipKeys, skipValues, classesOut, styleOut, protection, defaultResolved = resolved, renderOnly = false) => {
|
|
787
788
|
let workingResolved = resolved;
|
|
788
789
|
let cClasses = null;
|
|
789
790
|
let cStyle = null;
|
|
@@ -800,33 +801,36 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
800
801
|
else if (staticExtSkipValues === null) extSkipVals = skipValues;
|
|
801
802
|
else {
|
|
802
803
|
extSkipVals = {};
|
|
803
|
-
for (const k in skipValues)
|
|
804
|
+
for (const k in skipValues) {
|
|
805
|
+
if (!hasOwn(skipValues, k)) continue;
|
|
806
|
+
extSkipVals[k] = skipValues[k];
|
|
807
|
+
}
|
|
804
808
|
for (const k in staticExtSkipValues) {
|
|
805
|
-
|
|
809
|
+
if (!hasOwn(staticExtSkipValues, k)) continue;
|
|
810
|
+
const values = staticExtSkipValues[k];
|
|
811
|
+
const existing = getOwn(extSkipVals, k);
|
|
806
812
|
if (existing) {
|
|
807
813
|
const merged = new Set(existing);
|
|
808
|
-
for (const v of
|
|
814
|
+
for (const v of values) merged.add(v);
|
|
809
815
|
extSkipVals[k] = merged;
|
|
810
|
-
} else extSkipVals[k] =
|
|
816
|
+
} else extSkipVals[k] = values;
|
|
811
817
|
}
|
|
812
818
|
}
|
|
813
|
-
const extUserVariantProps = extMetasWithRefineCount > 0 ? getExtUserVariantProps(userVariantProps, protectedVariants ?? null) : userVariantProps;
|
|
814
819
|
for (let i = 0; i < extCount; i++) {
|
|
815
820
|
if (hasIsolatedExt && extIsolated[i]) {
|
|
816
821
|
const extClasses = [];
|
|
817
|
-
workingResolved = extMetas[i].compute(workingResolved,
|
|
822
|
+
workingResolved = extMetas[i].compute(workingResolved, userVariantProps, extSkipKeys, extSkipVals, extClasses, styleOut, protection, defaultResolved, renderOnly);
|
|
818
823
|
if (extClasses.length > 0) {
|
|
819
824
|
const joined = clsx(extClasses);
|
|
820
825
|
if (joined.length > 0) classesOut.push(extMetas[i].transformClass(joined));
|
|
821
826
|
}
|
|
822
|
-
} else workingResolved = extMetas[i].compute(workingResolved,
|
|
827
|
+
} else workingResolved = extMetas[i].compute(workingResolved, userVariantProps, extSkipKeys, extSkipVals, classesOut, styleOut, protection, defaultResolved, renderOnly);
|
|
823
828
|
workingResolved = filterOwnDisabledVariants(workingResolved, defaultResolved);
|
|
824
|
-
if (protectedVariants && extMetasWithRefineCount > 0) Object.assign(extUserVariantProps, protectedVariants);
|
|
825
829
|
}
|
|
826
830
|
}
|
|
827
|
-
if (!renderOnly && computedDefaultCount > 0) workingResolved = runComputedDefaults(workingResolved, defaultResolved, userVariantProps, true,
|
|
831
|
+
if (!renderOnly && computedDefaultCount > 0) workingResolved = runComputedDefaults(workingResolved, defaultResolved, userVariantProps, true, protection);
|
|
828
832
|
if (refine) {
|
|
829
|
-
const refineResult = runRefineContext(workingResolved, true, true, !renderOnly,
|
|
833
|
+
const refineResult = runRefineContext(workingResolved, true, true, !renderOnly, protection);
|
|
830
834
|
workingResolved = refineResult.workingResolved;
|
|
831
835
|
cClasses = refineResult.classes;
|
|
832
836
|
cStyle = refineResult.style;
|
|
@@ -839,14 +843,15 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
839
843
|
if (ownSkipKeys && ownSkipKeys.has(variantName)) continue;
|
|
840
844
|
const selectedValue = workingResolved[variantName];
|
|
841
845
|
if (selectedValue === void 0) continue;
|
|
846
|
+
if (!hasOwn(workingResolved, variantName)) continue;
|
|
842
847
|
const selectedKey = getVariantValueKey(selectedValue);
|
|
843
848
|
const variant = variantEntryDefs[i];
|
|
844
849
|
if (variant.disabledValues && selectedKey != null && variant.disabledValues.has(selectedKey)) continue;
|
|
845
|
-
if (ownSkipValues && selectedKey != null && ownSkipValues
|
|
850
|
+
if (ownSkipValues && selectedKey != null && getOwn(ownSkipValues, variantName)?.has(selectedKey)) continue;
|
|
846
851
|
let value;
|
|
847
852
|
if (variant.values) {
|
|
848
853
|
if (selectedKey == null) continue;
|
|
849
|
-
value = variant.values
|
|
854
|
+
value = variant.values.get(selectedKey);
|
|
850
855
|
} else if (selectedValue === true) value = variant.shorthand;
|
|
851
856
|
if (!value) continue;
|
|
852
857
|
if (value.class != null) classesOut.push(value.class);
|
|
@@ -857,8 +862,9 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
857
862
|
if (ownSkipKeys && ownSkipKeys.has(variantName)) continue;
|
|
858
863
|
const selectedValue = workingResolved[variantName];
|
|
859
864
|
if (selectedValue === void 0) continue;
|
|
865
|
+
if (!hasOwn(workingResolved, variantName)) continue;
|
|
860
866
|
const selectedKey = getVariantValueKey(selectedValue);
|
|
861
|
-
if (ownSkipValues && selectedKey != null && ownSkipValues
|
|
867
|
+
if (ownSkipValues && selectedKey != null && getOwn(ownSkipValues, variantName)?.has(selectedKey)) continue;
|
|
862
868
|
const fn = functionVariantFns[i];
|
|
863
869
|
const computedResult = fn(selectedValue);
|
|
864
870
|
if (computedResult == null) continue;
|
|
@@ -872,8 +878,7 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
872
878
|
};
|
|
873
879
|
const compute = !refine && computedDefaultCount === 0 && extMetasWithRefineCount === 0 ? computeOnce : (resolved, userVariantProps, skipKeys, skipValues, classesOut, styleOut) => {
|
|
874
880
|
let remaining = MAX_REFINE_RUNS;
|
|
875
|
-
const
|
|
876
|
-
const protectedVariantKeys = /* @__PURE__ */ new Set();
|
|
881
|
+
const protection = canProtectVariants ? { variants: null } : null;
|
|
877
882
|
const incomingDefaultResolved = resolved;
|
|
878
883
|
let workingResolved = resolved;
|
|
879
884
|
let unstableChanges = null;
|
|
@@ -886,22 +891,22 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
886
891
|
const classCount = classesOut.length;
|
|
887
892
|
const nextClasses = useDirectOutput ? classesOut : [];
|
|
888
893
|
const nextStyle = useDirectOutput ? styleOut : {};
|
|
889
|
-
const defaultResolved = mergeProtectedIntoBase(incomingDefaultResolved,
|
|
890
|
-
const nextResolved = computeOnce(workingResolved, userVariantProps, skipKeys, skipValues, nextClasses, nextStyle,
|
|
894
|
+
const defaultResolved = mergeProtectedIntoBase(incomingDefaultResolved, protection);
|
|
895
|
+
const nextResolved = computeOnce(workingResolved, userVariantProps, skipKeys, skipValues, nextClasses, nextStyle, protection, defaultResolved);
|
|
891
896
|
if (nextResolved === workingResolved || areVariantsEqual(workingResolved, nextResolved)) {
|
|
892
897
|
if (nextResolved !== workingResolved) {
|
|
893
898
|
if (useDirectOutput) {
|
|
894
899
|
classesOut.length = classCount;
|
|
895
900
|
for (const key in styleOut) if (hasOwn(styleOut, key)) Reflect.deleteProperty(styleOut, key);
|
|
896
901
|
}
|
|
897
|
-
computeOnce(nextResolved, userVariantProps, skipKeys, skipValues, classesOut, styleOut,
|
|
902
|
+
computeOnce(nextResolved, userVariantProps, skipKeys, skipValues, classesOut, styleOut, protection, defaultResolved, true);
|
|
898
903
|
} else if (!useDirectOutput) {
|
|
899
904
|
for (let i = 0; i < nextClasses.length; i++) classesOut.push(nextClasses[i]);
|
|
900
905
|
Object.assign(styleOut, nextStyle);
|
|
901
906
|
}
|
|
902
907
|
return nextResolved;
|
|
903
908
|
}
|
|
904
|
-
if (process.env.NODE_ENV !== "production"
|
|
909
|
+
if (remaining < 10 && process.env.NODE_ENV !== "production") {
|
|
905
910
|
if (!unstableChanges) unstableChanges = /* @__PURE__ */ new Map();
|
|
906
911
|
accumulateUnstableVariantChanges(unstableChanges, workingResolved, nextResolved);
|
|
907
912
|
}
|
|
@@ -923,35 +928,30 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
923
928
|
Object.assign(styleOut, lastStyle);
|
|
924
929
|
return workingResolved;
|
|
925
930
|
};
|
|
926
|
-
const resolveRefineOnce = (resolved, userVariantProps, filterOwnVariants = true,
|
|
931
|
+
const resolveRefineOnce = (resolved, userVariantProps, filterOwnVariants = true, protection, defaultResolved = resolved) => {
|
|
927
932
|
let workingResolved = resolved;
|
|
928
|
-
|
|
929
|
-
const
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
workingResolved = resolveRefine(workingResolved, extUserVariantProps, true, protectedVariants, protectedVariantKeys, defaultResolved);
|
|
934
|
-
workingResolved = filterOwnDisabledVariants(workingResolved, defaultResolved);
|
|
935
|
-
if (protectedVariants) Object.assign(extUserVariantProps, protectedVariants);
|
|
936
|
-
}
|
|
933
|
+
for (let i = 0; i < extMetasWithRefineCount; i++) {
|
|
934
|
+
const resolveRefine = extMetasWithRefine[i].resolveRefine;
|
|
935
|
+
if (!resolveRefine) continue;
|
|
936
|
+
workingResolved = resolveRefine(workingResolved, userVariantProps, true, protection, defaultResolved);
|
|
937
|
+
workingResolved = filterOwnDisabledVariants(workingResolved, defaultResolved);
|
|
937
938
|
}
|
|
938
|
-
if (computedDefaultCount > 0) workingResolved = runComputedDefaults(workingResolved, defaultResolved, userVariantProps, filterOwnVariants,
|
|
939
|
-
if (refine) workingResolved = runRefineContext(workingResolved, filterOwnVariants, false, true,
|
|
939
|
+
if (computedDefaultCount > 0) workingResolved = runComputedDefaults(workingResolved, defaultResolved, userVariantProps, filterOwnVariants, protection);
|
|
940
|
+
if (refine) workingResolved = runRefineContext(workingResolved, filterOwnVariants, false, true, protection).workingResolved;
|
|
940
941
|
return workingResolved;
|
|
941
942
|
};
|
|
942
943
|
const resolveRefine = refine || computedDefaultCount > 0 || extMetasWithRefineCount > 0 ? (resolved, userVariantProps, filterOwnVariants = true) => {
|
|
943
944
|
let remaining = MAX_REFINE_RUNS;
|
|
944
|
-
const
|
|
945
|
-
const protectedVariantKeys = /* @__PURE__ */ new Set();
|
|
945
|
+
const protection = canProtectVariants ? { variants: null } : null;
|
|
946
946
|
const incomingDefaultResolved = resolved;
|
|
947
947
|
let workingResolved = resolved;
|
|
948
948
|
let unstableChanges = null;
|
|
949
949
|
while (remaining > 0) {
|
|
950
950
|
remaining -= 1;
|
|
951
|
-
const defaultResolved = mergeProtectedIntoBase(incomingDefaultResolved,
|
|
952
|
-
const nextResolved = resolveRefineOnce(workingResolved, userVariantProps, filterOwnVariants,
|
|
951
|
+
const defaultResolved = mergeProtectedIntoBase(incomingDefaultResolved, protection);
|
|
952
|
+
const nextResolved = resolveRefineOnce(workingResolved, userVariantProps, filterOwnVariants, protection, defaultResolved);
|
|
953
953
|
if (nextResolved === workingResolved || areVariantsEqual(workingResolved, nextResolved)) return nextResolved;
|
|
954
|
-
if (process.env.NODE_ENV !== "production"
|
|
954
|
+
if (remaining < 10 && process.env.NODE_ENV !== "production") {
|
|
955
955
|
if (!unstableChanges) unstableChanges = /* @__PURE__ */ new Map();
|
|
956
956
|
accumulateUnstableVariantChanges(unstableChanges, workingResolved, nextResolved);
|
|
957
957
|
}
|
|
@@ -968,17 +968,15 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
968
968
|
let resolved = {};
|
|
969
969
|
Object.assign(resolved, staticDefaults);
|
|
970
970
|
let userVariantProps;
|
|
971
|
-
if (
|
|
971
|
+
if (needsUserVariantProps) {
|
|
972
972
|
const variantProps = {};
|
|
973
973
|
for (let i = 0; i < variantKeysLength; i++) {
|
|
974
974
|
const key = variantKeys[i];
|
|
975
|
-
if (hasOwn(propsRecord, key))
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
if (
|
|
979
|
-
|
|
980
|
-
if (v === void 0) continue;
|
|
981
|
-
resolved[k] = v;
|
|
975
|
+
if (!hasOwn(propsRecord, key)) continue;
|
|
976
|
+
const value = propsRecord[key];
|
|
977
|
+
variantProps[key] = value;
|
|
978
|
+
if (value === void 0) continue;
|
|
979
|
+
resolved[key] = value;
|
|
982
980
|
}
|
|
983
981
|
userVariantProps = variantProps;
|
|
984
982
|
} else {
|
|
@@ -999,10 +997,10 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
999
997
|
const allClasses = [computedBaseClass];
|
|
1000
998
|
const style = {};
|
|
1001
999
|
compute(resolved, userVariantProps, null, null, allClasses, style);
|
|
1002
|
-
if ("class"
|
|
1003
|
-
if ("className"
|
|
1000
|
+
if (hasOwn(propsRecord, "class")) allClasses.push(propsRecord.class);
|
|
1001
|
+
if (hasOwn(propsRecord, "className")) allClasses.push(propsRecord.className);
|
|
1004
1002
|
const psv = propsRecord.style;
|
|
1005
|
-
if (psv != null) {
|
|
1003
|
+
if (psv != null && hasOwn(propsRecord, "style")) {
|
|
1006
1004
|
if (typeof psv === "string") {
|
|
1007
1005
|
if (psv.length > 0) htmlStyleToStyleValue(psv, style);
|
|
1008
1006
|
} else if (typeof psv === "object") htmlObjStyleToStyleValue(psv, style);
|
|
@@ -1026,7 +1024,7 @@ function create({ transformClass = (className) => className } = {}) {
|
|
|
1026
1024
|
if (resolveRefine) resolvedVariants = resolveRefine(resolvedVariants, variantProps, false);
|
|
1027
1025
|
return resolvedVariants;
|
|
1028
1026
|
};
|
|
1029
|
-
const computedBaseClass = hasExtend ? clsx(extBaseClassesArr,
|
|
1027
|
+
const computedBaseClass = hasExtend ? clsx(extBaseClassesArr, baseClass) : clsx(baseClass);
|
|
1030
1028
|
const classFn = (props = {}) => {
|
|
1031
1029
|
return computeResult(props).className;
|
|
1032
1030
|
};
|