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/CHANGELOG.md +26 -0
- package/README.md +32 -11
- package/dist/index.d.ts +1 -1
- package/dist/index.js +586 -547
- package/dist/index.js.map +1 -1
- package/package.json +8 -7
- package/src/index.ts +1111 -1021
- package/src/refine-warning.ts +9 -5
- 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",
|
|
@@ -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
|
-
|
|
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
|
-
|
|
358
|
+
ownKeyDifference--;
|
|
322
359
|
}
|
|
323
|
-
return
|
|
324
|
-
}
|
|
325
|
-
function getExtUserVariantProps(userVariantProps, protectedVariants) {
|
|
326
|
-
return Object.assign({}, userVariantProps, protectedVariants);
|
|
360
|
+
return ownKeyDifference === 0;
|
|
327
361
|
}
|
|
328
|
-
function mergeProtectedIntoBase(baseResolved,
|
|
329
|
-
|
|
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
|
-
|
|
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
|
|
353
|
-
const style = normalizeStyle(styleClassValue.style);
|
|
393
|
+
const style = normalizeStyle(styleValue);
|
|
354
394
|
return {
|
|
355
|
-
class:
|
|
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
|
|
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(
|
|
491
|
+
function create(params = {}) {
|
|
492
|
+
const transformClass = getOwn(params, "transformClass") ?? identityClass;
|
|
452
493
|
const cx = (...classes) => transformClass(clsx(classes));
|
|
453
|
-
const
|
|
454
|
-
const extend = config
|
|
455
|
-
const
|
|
456
|
-
const
|
|
457
|
-
const
|
|
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
|
|
462
|
-
const
|
|
463
|
-
const
|
|
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
|
-
|
|
476
|
-
|
|
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
|
|
516
|
+
const initialExtensions = originalExtMetas.length > 1 ? deduplicateExtensions(originalExtMetas) : originalExtMetas;
|
|
517
|
+
const ownStaticDefaults = {};
|
|
485
518
|
const disabledVariantKeys = /* @__PURE__ */ new Set();
|
|
486
|
-
|
|
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
|
-
|
|
511
|
-
|
|
542
|
+
disabledValuesBuilder ??= {};
|
|
543
|
+
disabledValuesBuilder[name] = prebuiltVariant.disabledValues;
|
|
512
544
|
}
|
|
513
|
-
if (prebuiltVariant.values
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
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
|
-
|
|
552
|
-
|
|
553
|
-
const
|
|
554
|
-
if (
|
|
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
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
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
|
-
|
|
578
|
-
|
|
579
|
-
|
|
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
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
const
|
|
601
|
-
|
|
602
|
-
|
|
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
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
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
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
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
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
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
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
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
|
-
|
|
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
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
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 (
|
|
680
|
-
const
|
|
681
|
-
const
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
if (
|
|
685
|
-
|
|
686
|
-
|
|
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
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
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 (
|
|
694
|
-
|
|
697
|
+
if (!hasAnyDisabled) return defaults;
|
|
698
|
+
const result = {};
|
|
699
|
+
filterDisabledInto(defaults, result);
|
|
700
|
+
return result;
|
|
695
701
|
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
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
|
|
708
|
-
if (hasOwn(resolved,
|
|
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
|
|
718
|
-
updatedVariants =
|
|
719
|
-
return
|
|
718
|
+
const updated = Object.assign({}, resolved);
|
|
719
|
+
updatedVariants = updated;
|
|
720
|
+
return updated;
|
|
720
721
|
};
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
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
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
if (
|
|
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
|
-
|
|
736
|
-
|
|
737
|
-
|
|
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
|
-
|
|
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
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
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
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
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
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
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
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
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
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
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
|
-
|
|
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 (
|
|
905
|
-
|
|
906
|
-
|
|
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 (
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
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
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
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,
|
|
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
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
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
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
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
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
resolved[k] = v;
|
|
1024
|
+
if (hasAnyDisabled) {
|
|
1025
|
+
const filtered = {};
|
|
1026
|
+
filterDisabledInto(resolved, filtered);
|
|
1027
|
+
resolved = filtered;
|
|
982
1028
|
}
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
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
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
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
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
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
|
-
|
|
1026
|
-
|
|
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
|
-
|
|
1059
|
-
|
|
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
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
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
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
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
|
-
|
|
1089
|
-
|
|
1134
|
+
component: defaultComponent,
|
|
1135
|
+
meta
|
|
1090
1136
|
};
|
|
1091
|
-
}
|
|
1092
|
-
|
|
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
|