@rootnative/inertia 0.0.0-alpha.7 → 0.0.2

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +1 -1
  3. package/dist/{chunk-ALRHDFZE.mjs → chunk-2DHKV2XY.mjs} +1 -1
  4. package/dist/chunk-34Q4UM6V.js +8 -0
  5. package/dist/{chunk-CWLFUYIY.mjs → chunk-HFDZAHWP.mjs} +1 -1
  6. package/dist/{chunk-7UDYEFBU.js → chunk-IWLU3VDE.js} +361 -288
  7. package/dist/chunk-KYJROYCG.js +8 -0
  8. package/dist/{chunk-DWCLIBYO.mjs → chunk-LYMLQ6WQ.mjs} +362 -289
  9. package/dist/{chunk-TDSO63CJ.js → chunk-NKA6XR77.js} +2 -2
  10. package/dist/{chunk-6SMPIOIC.mjs → chunk-TUMNV4P7.mjs} +1 -1
  11. package/dist/{chunk-2HYD2ZBK.js → chunk-TUYHTHVV.js} +2 -2
  12. package/dist/{chunk-NXDJZD6A.mjs → chunk-V6BTXHZK.mjs} +1 -1
  13. package/dist/chunk-X5J5M3K3.js +8 -0
  14. package/dist/{chunk-JVBXPF2G.mjs → chunk-ZN3PNGHQ.mjs} +1 -1
  15. package/dist/index.d.mts +229 -43
  16. package/dist/index.d.ts +229 -43
  17. package/dist/index.js +199 -23
  18. package/dist/index.mjs +191 -18
  19. package/dist/motion/Image.js +3 -3
  20. package/dist/motion/Image.mjs +2 -2
  21. package/dist/motion/Pressable.js +3 -3
  22. package/dist/motion/Pressable.mjs +2 -2
  23. package/dist/motion/ScrollView.js +3 -3
  24. package/dist/motion/ScrollView.mjs +2 -2
  25. package/dist/motion/Text.js +3 -3
  26. package/dist/motion/Text.mjs +2 -2
  27. package/dist/motion/View.js +3 -3
  28. package/dist/motion/View.mjs +2 -2
  29. package/llms.txt +6 -1
  30. package/package.json +1 -1
  31. package/src/index.ts +10 -0
  32. package/src/motion/createMotionComponent.tsx +624 -501
  33. package/src/values/index.ts +13 -0
  34. package/src/values/useAnimation.ts +15 -1
  35. package/src/values/useAnimator.ts +72 -0
  36. package/src/values/useColorCascade.ts +107 -0
  37. package/src/values/useInterpolatedStyle.ts +319 -0
  38. package/src/values/useMotionValue.ts +20 -2
  39. package/src/values/useSpring.ts +12 -0
  40. package/dist/chunk-3UTJJ4A3.js +0 -8
  41. package/dist/chunk-4QGXK6TF.js +0 -8
  42. package/dist/chunk-Z7HIOFKQ.js +0 -8
@@ -395,28 +395,8 @@ function createMotionComponent(Component) {
395
395
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
396
396
  Component
397
397
  );
398
- const Motion = react.forwardRef(function Motion2(props, ref) {
399
- const {
400
- initial,
401
- animate,
402
- exit,
403
- transition: transitionProp,
404
- variants,
405
- controller,
406
- gesture,
407
- layout: layoutProp,
408
- layoutId,
409
- onAnimationEnd,
410
- style,
411
- onLayout: userOnLayout,
412
- ...rest
413
- } = props;
414
- const namedTransitions = chunk7AOERN53_js.useNamedTransitions();
415
- const transition = chunk7AOERN53_js.resolveNamedTransitionProp(
416
- transitionProp,
417
- namedTransitions
418
- );
419
- const layout = typeof layoutProp === "string" ? chunk7AOERN53_js.lookupNamedTransition(layoutProp, namedTransitions) : layoutProp;
398
+ const PlainHost = react.forwardRef(function PlainHost2(props, ref) {
399
+ const { style, ...rest } = props;
420
400
  if (__DEV__ && typeof style === "function") {
421
401
  throw new Error(
422
402
  "[inertia] `style` must be a style object or array of style objects, not a function. The function-form `style={(state) => ...}` Pressable API is not supported \u2014 use `gesture.pressed` (or `gesture.focused`, etc.) to drive state-dependent styling instead."
@@ -424,293 +404,375 @@ function createMotionComponent(Component) {
424
404
  }
425
405
  const presence = usePresence();
426
406
  const isExiting = presence !== null && presence.isPresent === false;
427
- const shouldReduceMotion = chunk7AOERN53_js.useShouldReduceMotion();
428
- const onAnimationEndRef = react.useRef(onAnimationEnd);
429
- onAnimationEndRef.current = onAnimationEnd;
430
- const variantKey = useControllerKey(controller);
431
- const resolvedAnimate = resolveAnimateInput(
432
- animate,
433
- variants,
434
- variantKey
435
- );
436
- const animateRecord = resolvedAnimate ?? {};
437
- const initialRecord = initial && initial !== false ? initial : void 0;
438
- const exitRecord = exit ? exit : void 0;
439
- const [pressed, setPressed] = react.useState(false);
440
- const [focused, setFocused] = react.useState(false);
441
- const [focusVisible, setFocusVisible] = react.useState(false);
442
- const [hovered, setHovered] = react.useState(false);
443
- const touched = /* @__PURE__ */ new Set();
444
- collectTouchedKeys(touched, animateRecord);
445
- if (initialRecord) collectTouchedKeys(touched, initialRecord);
446
- if (variants) {
447
- for (const variant of Object.values(variants)) {
448
- if (!variant) continue;
449
- collectTouchedKeys(touched, variant);
450
- }
451
- }
452
- if (gesture) {
453
- for (const subState of [
454
- gesture.pressed,
455
- gesture.focused,
456
- gesture.focusVisible,
457
- gesture.hovered
458
- ]) {
459
- if (!subState) continue;
460
- collectTouchedKeys(touched, subState);
461
- }
462
- }
463
- if (exitRecord) collectTouchedKeys(touched, exitRecord);
464
- const activeKeysRef = react.useRef(null);
465
- const hasTransformRef = react.useRef(false);
466
- const hasShadowOffsetRef = react.useRef(false);
467
- const prevActive = activeKeysRef.current;
468
- let grew = prevActive === null;
469
- if (!grew && prevActive) {
470
- for (const k of touched) {
471
- if (!prevActive.includes(k)) {
472
- grew = true;
473
- break;
474
- }
407
+ const safeToRemoveRef = react.useRef(void 0);
408
+ safeToRemoveRef.current = presence?.safeToRemove;
409
+ react.useEffect(() => {
410
+ if (isExiting) safeToRemoveRef.current?.();
411
+ }, [isExiting]);
412
+ return /* @__PURE__ */ jsxRuntime.jsx(
413
+ AnimatedComponent,
414
+ {
415
+ ref,
416
+ ...rest,
417
+ style
475
418
  }
476
- }
477
- if (grew) {
478
- const merged = new Set(prevActive ?? []);
479
- for (const k of touched) merged.add(k);
480
- activeKeysRef.current = ALL_KEYS.filter((k) => merged.has(k));
481
- hasTransformRef.current = activeKeysRef.current.some(
482
- (k) => TRANSFORM_KEY_SET.has(k)
419
+ );
420
+ });
421
+ PlainHost.displayName = `MotionPlain(${Component.displayName ?? Component.name ?? "Component"})`;
422
+ const MotionAnimated = react.forwardRef(
423
+ function MotionAnimated2(props, ref) {
424
+ const {
425
+ initial,
426
+ animate,
427
+ exit,
428
+ transition: transitionProp,
429
+ variants,
430
+ controller,
431
+ gesture,
432
+ layout: layoutProp,
433
+ layoutId,
434
+ onAnimationEnd,
435
+ style,
436
+ onLayout: userOnLayout,
437
+ ...rest
438
+ } = props;
439
+ const namedTransitions = chunk7AOERN53_js.useNamedTransitions();
440
+ const transition = chunk7AOERN53_js.resolveNamedTransitionProp(
441
+ transitionProp,
442
+ namedTransitions
483
443
  );
484
- hasShadowOffsetRef.current = activeKeysRef.current.some(
485
- (k) => SHADOW_OFFSET_KEY_SET.has(k)
444
+ const layout = typeof layoutProp === "string" ? chunk7AOERN53_js.lookupNamedTransition(layoutProp, namedTransitions) : layoutProp;
445
+ if (__DEV__ && typeof style === "function") {
446
+ throw new Error(
447
+ "[inertia] `style` must be a style object or array of style objects, not a function. The function-form `style={(state) => ...}` Pressable API is not supported \u2014 use `gesture.pressed` (or `gesture.focused`, etc.) to drive state-dependent styling instead."
448
+ );
449
+ }
450
+ const presence = usePresence();
451
+ const isExiting = presence !== null && presence.isPresent === false;
452
+ const shouldReduceMotion = chunk7AOERN53_js.useShouldReduceMotion();
453
+ const onAnimationEndRef = react.useRef(onAnimationEnd);
454
+ onAnimationEndRef.current = onAnimationEnd;
455
+ const variantKey = useControllerKey(controller);
456
+ const resolvedAnimate = resolveAnimateInput(
457
+ animate,
458
+ variants,
459
+ variantKey
486
460
  );
487
- }
488
- const sharedValues = useAnimatableSharedValues((key) => {
489
- if (SHADOW_OFFSET_KEY_SET.has(key)) {
490
- const axis = shadowOffsetAxisFor(key);
491
- if (initial === false) {
492
- return shadowOffsetAxisValue(animateRecord.shadowOffset, axis) ?? DEFAULT_RESTING[key];
461
+ const animateRecord = resolvedAnimate ?? {};
462
+ const initialRecord = initial && initial !== false ? initial : void 0;
463
+ const exitRecord = exit ? exit : void 0;
464
+ const [pressed, setPressed] = react.useState(false);
465
+ const [focused, setFocused] = react.useState(false);
466
+ const [focusVisible, setFocusVisible] = react.useState(false);
467
+ const [hovered, setHovered] = react.useState(false);
468
+ const touched = /* @__PURE__ */ new Set();
469
+ collectTouchedKeys(touched, animateRecord);
470
+ if (initialRecord) collectTouchedKeys(touched, initialRecord);
471
+ if (variants) {
472
+ for (const variant of Object.values(variants)) {
473
+ if (!variant) continue;
474
+ collectTouchedKeys(touched, variant);
493
475
  }
494
- return shadowOffsetAxisValue(
495
- initialRecord?.shadowOffset,
496
- axis
497
- ) ?? shadowOffsetAxisValue(animateRecord.shadowOffset, axis) ?? DEFAULT_RESTING[key];
498
- }
499
- if (initial === false) {
500
- const a = animateRecord[key];
501
- return restValue(a) ?? DEFAULT_RESTING[key];
502
- }
503
- return initialRecord?.[key] ?? restValue(animateRecord[key]) ?? DEFAULT_RESTING[key];
504
- });
505
- const pressedProgress = Animated.useSharedValue(0);
506
- const focusedProgress = Animated.useSharedValue(0);
507
- const focusVisibleProgress = Animated.useSharedValue(0);
508
- const hoveredProgress = Animated.useSharedValue(0);
509
- const gestureSV = Animated.useSharedValue(
510
- resolveGestureLayers(gesture)
511
- );
512
- const gestureTargetsSig = chunkPTRF47DA_js.stableSig(gesture);
513
- react.useEffect(() => {
514
- gestureSV.value = resolveGestureLayers(gesture);
515
- }, [gestureTargetsSig]);
516
- const baseRecord = isExiting && exitRecord ? { ...animateRecord, ...exitRecord } : animateRecord;
517
- const baseSig = chunkPTRF47DA_js.stableSig(baseRecord) + (isExiting ? "|exit" : "") + (shouldReduceMotion ? "|rm" : "");
518
- const transitionSig = chunkPTRF47DA_js.stableSig(transition);
519
- const safeToRemoveRef = react.useRef(void 0);
520
- safeToRemoveRef.current = presence?.safeToRemove;
521
- react.useEffect(() => {
522
- if (isExiting && (!exitRecord || Object.keys(exitRecord).length === 0)) {
523
- safeToRemoveRef.current?.();
524
- return;
525
476
  }
526
- let pending = 0;
527
- let done = false;
528
- const onSettle = () => {
529
- if (done) return;
530
- pending--;
531
- if (pending <= 0) {
532
- done = true;
533
- if (isExiting) safeToRemoveRef.current?.();
477
+ if (gesture) {
478
+ for (const subState of [
479
+ gesture.pressed,
480
+ gesture.focused,
481
+ gesture.focusVisible,
482
+ gesture.hovered
483
+ ]) {
484
+ if (!subState) continue;
485
+ collectTouchedKeys(touched, subState);
534
486
  }
535
- };
536
- let transformPending = 0;
537
- for (const k of ALL_KEYS) {
538
- if (TRANSFORM_KEY_SET.has(k) && baseRecord[k] !== void 0) {
539
- transformPending++;
487
+ }
488
+ if (exitRecord) collectTouchedKeys(touched, exitRecord);
489
+ const activeKeysRef = react.useRef(null);
490
+ const hasTransformRef = react.useRef(false);
491
+ const hasShadowOffsetRef = react.useRef(false);
492
+ const prevActive = activeKeysRef.current;
493
+ let grew = prevActive === null;
494
+ if (!grew && prevActive) {
495
+ for (const k of touched) {
496
+ if (!prevActive.includes(k)) {
497
+ grew = true;
498
+ break;
499
+ }
540
500
  }
541
501
  }
542
- const transformGroup = transformPending > 0 ? { remaining: transformPending } : void 0;
543
- for (const key of ALL_KEYS) {
544
- const target = SHADOW_OFFSET_KEY_SET.has(key) ? shadowOffsetAxisValue(
545
- baseRecord.shadowOffset,
546
- shadowOffsetAxisFor(key)
547
- ) : baseRecord[key];
548
- if (target === void 0) continue;
549
- const cfg = shouldReduceMotion ? { type: "no-animation" } : transitionFor(
550
- SHADOW_OFFSET_KEY_SET.has(key) ? "shadowOffset" : key,
551
- transition
552
- );
553
- if (isExiting) pending++;
554
- const factory = makeKeyCallbackFactory(
555
- key,
556
- sharedValues[key],
557
- targetEndValue(target),
558
- onAnimationEndRef,
559
- {
560
- stepCount: stepCountOf(target),
561
- totalIterations: totalIterationsOf(cfg)
562
- },
563
- isExiting ? onSettle : void 0,
564
- TRANSFORM_KEY_SET.has(key) ? transformGroup : void 0
502
+ if (grew) {
503
+ const merged = new Set(prevActive ?? []);
504
+ for (const k of touched) merged.add(k);
505
+ activeKeysRef.current = ALL_KEYS.filter((k) => merged.has(k));
506
+ hasTransformRef.current = activeKeysRef.current.some(
507
+ (k) => TRANSFORM_KEY_SET.has(k)
565
508
  );
566
- sharedValues[key].value = chunkPTRF47DA_js.resolveAnimatableValue(
567
- target,
568
- cfg,
569
- factory
509
+ hasShadowOffsetRef.current = activeKeysRef.current.some(
510
+ (k) => SHADOW_OFFSET_KEY_SET.has(k)
570
511
  );
571
512
  }
572
- if (isExiting && pending === 0) {
573
- safeToRemoveRef.current?.();
574
- }
575
- }, [baseSig, transitionSig]);
576
- useGestureLayerProgress(
577
- pressedProgress,
578
- pressed,
579
- gesture?.pressed != null,
580
- "pressed",
581
- transition,
582
- isExiting,
583
- shouldReduceMotion
584
- );
585
- useGestureLayerProgress(
586
- focusedProgress,
587
- focused,
588
- gesture?.focused != null,
589
- "focused",
590
- transition,
591
- isExiting,
592
- shouldReduceMotion
593
- );
594
- useGestureLayerProgress(
595
- focusVisibleProgress,
596
- focusVisible,
597
- gesture?.focusVisible != null,
598
- "focusVisible",
599
- transition,
600
- isExiting,
601
- shouldReduceMotion
602
- );
603
- useGestureLayerProgress(
604
- hoveredProgress,
605
- hovered,
606
- gesture?.hovered != null,
607
- "hovered",
608
- transition,
609
- isExiting,
610
- shouldReduceMotion
611
- );
612
- const sharedLayout = useSharedLayout({
613
- layoutId,
614
- userRef: ref,
615
- transition: chunkPTRF47DA_js.isTopLevelTransition(transition) ? transition : void 0,
616
- shouldReduceMotion,
617
- userOnLayout
618
- });
619
- const flip = sharedLayout.flip;
620
- const hasLayoutId = layoutId !== void 0;
621
- const animatedStyle = Animated.useAnimatedStyle(() => {
622
- const activeKeys = activeKeysRef.current;
623
- const hasTransform = hasTransformRef.current;
624
- const hasShadowOffset = hasShadowOffsetRef.current;
625
- const out = {};
626
- const transform = [];
627
- let shadowOffsetW = 0;
628
- let shadowOffsetH = 0;
629
- const ph = hoveredProgress.value;
630
- const pf = focusedProgress.value;
631
- const pfv = focusVisibleProgress.value;
632
- const pp = pressedProgress.value;
633
- const layers = gestureSV.value;
634
- const hoveredLayer = layers ? layers.hovered : null;
635
- const focusedLayer = layers ? layers.focused : null;
636
- const focusVisibleLayer = layers ? layers.focusVisible : null;
637
- const pressedLayer = layers ? layers.pressed : null;
638
- for (const key of activeKeys) {
639
- let v = sharedValues[key].value;
640
- const isColor = COLOR_KEY_SET.has(key);
641
- if (hoveredLayer && ph > 0 && hoveredLayer[key] !== void 0) {
642
- const t = hoveredLayer[key];
643
- v = isColor ? Animated.interpolateColor(ph, [0, 1], [v, t]) : v + (t - v) * ph;
513
+ const sharedValues = useAnimatableSharedValues((key) => {
514
+ if (SHADOW_OFFSET_KEY_SET.has(key)) {
515
+ const axis = shadowOffsetAxisFor(key);
516
+ if (initial === false) {
517
+ return shadowOffsetAxisValue(animateRecord.shadowOffset, axis) ?? DEFAULT_RESTING[key];
518
+ }
519
+ return shadowOffsetAxisValue(
520
+ initialRecord?.shadowOffset,
521
+ axis
522
+ ) ?? shadowOffsetAxisValue(animateRecord.shadowOffset, axis) ?? DEFAULT_RESTING[key];
644
523
  }
645
- if (focusedLayer && pf > 0 && focusedLayer[key] !== void 0) {
646
- const t = focusedLayer[key];
647
- v = isColor ? Animated.interpolateColor(pf, [0, 1], [v, t]) : v + (t - v) * pf;
524
+ if (initial === false) {
525
+ const a = animateRecord[key];
526
+ return restValue(a) ?? DEFAULT_RESTING[key];
648
527
  }
649
- if (focusVisibleLayer && pfv > 0 && focusVisibleLayer[key] !== void 0) {
650
- const t = focusVisibleLayer[key];
651
- v = isColor ? Animated.interpolateColor(pfv, [0, 1], [v, t]) : v + (t - v) * pfv;
528
+ return initialRecord?.[key] ?? restValue(animateRecord[key]) ?? DEFAULT_RESTING[key];
529
+ });
530
+ const pressedProgress = Animated.useSharedValue(0);
531
+ const focusedProgress = Animated.useSharedValue(0);
532
+ const focusVisibleProgress = Animated.useSharedValue(0);
533
+ const hoveredProgress = Animated.useSharedValue(0);
534
+ react.useEffect(
535
+ () => () => {
536
+ Animated.cancelAnimation(pressedProgress);
537
+ Animated.cancelAnimation(focusedProgress);
538
+ Animated.cancelAnimation(focusVisibleProgress);
539
+ Animated.cancelAnimation(hoveredProgress);
540
+ },
541
+ // The progress SVs are identity-stable per hook instance.
542
+ // eslint-disable-next-line react-hooks/exhaustive-deps
543
+ []
544
+ );
545
+ const gestureSV = Animated.useSharedValue(
546
+ resolveGestureLayers(gesture)
547
+ );
548
+ const gestureTargetsSig = chunkPTRF47DA_js.stableSig(gesture);
549
+ react.useEffect(() => {
550
+ gestureSV.value = resolveGestureLayers(gesture);
551
+ }, [gestureTargetsSig]);
552
+ const baseRecord = isExiting && exitRecord ? { ...animateRecord, ...exitRecord } : animateRecord;
553
+ const baseSig = chunkPTRF47DA_js.stableSig(baseRecord) + (isExiting ? "|exit" : "") + (shouldReduceMotion ? "|rm" : "");
554
+ const transitionSig = chunkPTRF47DA_js.stableSig(transition);
555
+ const safeToRemoveRef = react.useRef(void 0);
556
+ safeToRemoveRef.current = presence?.safeToRemove;
557
+ react.useEffect(() => {
558
+ if (isExiting && (!exitRecord || Object.keys(exitRecord).length === 0)) {
559
+ safeToRemoveRef.current?.();
560
+ return;
652
561
  }
653
- if (pressedLayer && pp > 0 && pressedLayer[key] !== void 0) {
654
- const t = pressedLayer[key];
655
- v = isColor ? Animated.interpolateColor(pp, [0, 1], [v, t]) : v + (t - v) * pp;
562
+ let pending = 0;
563
+ let done = false;
564
+ const onSettle = () => {
565
+ if (done) return;
566
+ pending--;
567
+ if (pending <= 0) {
568
+ done = true;
569
+ if (isExiting) safeToRemoveRef.current?.();
570
+ }
571
+ };
572
+ let transformPending = 0;
573
+ for (const k of ALL_KEYS) {
574
+ if (TRANSFORM_KEY_SET.has(k) && baseRecord[k] !== void 0) {
575
+ transformPending++;
576
+ }
656
577
  }
657
- if (TRANSFORM_KEY_SET.has(key)) {
658
- transform.push(
659
- ROTATION_KEYS.has(key) ? { [key]: `${v}deg` } : { [key]: v }
578
+ const transformGroup = transformPending > 0 ? { remaining: transformPending } : void 0;
579
+ for (const key of ALL_KEYS) {
580
+ const target = SHADOW_OFFSET_KEY_SET.has(key) ? shadowOffsetAxisValue(
581
+ baseRecord.shadowOffset,
582
+ shadowOffsetAxisFor(key)
583
+ ) : baseRecord[key];
584
+ if (target === void 0) continue;
585
+ const cfg = shouldReduceMotion ? { type: "no-animation" } : transitionFor(
586
+ SHADOW_OFFSET_KEY_SET.has(key) ? "shadowOffset" : key,
587
+ transition
588
+ );
589
+ if (isExiting) pending++;
590
+ const factory = makeKeyCallbackFactory(
591
+ key,
592
+ sharedValues[key],
593
+ targetEndValue(target),
594
+ onAnimationEndRef,
595
+ {
596
+ stepCount: stepCountOf(target),
597
+ totalIterations: totalIterationsOf(cfg)
598
+ },
599
+ isExiting ? onSettle : void 0,
600
+ TRANSFORM_KEY_SET.has(key) ? transformGroup : void 0
601
+ );
602
+ sharedValues[key].value = chunkPTRF47DA_js.resolveAnimatableValue(
603
+ target,
604
+ cfg,
605
+ factory
660
606
  );
661
- } else if (key === "shadowOffsetWidth") {
662
- shadowOffsetW = v;
663
- } else if (key === "shadowOffsetHeight") {
664
- shadowOffsetH = v;
665
- } else {
666
- out[key] = v;
667
607
  }
668
- }
669
- if (hasLayoutId) {
670
- transform.push({ translateX: flip.dx.value });
671
- transform.push({ translateY: flip.dy.value });
672
- transform.push({ scaleX: flip.sx.value });
673
- transform.push({ scaleY: flip.sy.value });
674
- }
675
- if (hasTransform || hasLayoutId) out.transform = transform;
676
- if (hasShadowOffset) {
677
- out.shadowOffset = { width: shadowOffsetW, height: shadowOffsetH };
678
- }
679
- return out;
680
- });
681
- const mergedStyle = react.useMemo(
682
- () => isExiting ? [style, animatedStyle, EXITING_POINTER_EVENTS_STYLE] : [style, animatedStyle],
683
- [style, animatedStyle, isExiting]
684
- );
685
- const gestureHandlers = useGestureHandlers(
686
- gesture,
687
- rest,
688
- setPressed,
689
- setFocused,
690
- setFocusVisible,
691
- setHovered
692
- );
693
- const layoutSig = chunkPTRF47DA_js.stableSig(layout);
694
- const layoutTransition = react.useMemo(
695
- () => shouldReduceMotion ? void 0 : resolveLayoutTransition(layout),
696
- // eslint-disable-next-line react-hooks/exhaustive-deps
697
- [layoutSig, shouldReduceMotion]
698
- );
699
- return /* @__PURE__ */ jsxRuntime.jsx(
700
- AnimatedComponent,
701
- {
702
- ref: sharedLayout.setRef,
703
- ...rest,
704
- ...gestureHandlers,
705
- onLayout: sharedLayout.onLayout,
706
- layout: layoutTransition,
707
- style: mergedStyle
708
- }
709
- );
608
+ if (isExiting && pending === 0) {
609
+ safeToRemoveRef.current?.();
610
+ }
611
+ }, [baseSig, transitionSig]);
612
+ useGestureLayerProgress(
613
+ pressedProgress,
614
+ pressed,
615
+ gesture?.pressed != null,
616
+ "pressed",
617
+ transition,
618
+ isExiting,
619
+ shouldReduceMotion
620
+ );
621
+ useGestureLayerProgress(
622
+ focusedProgress,
623
+ focused,
624
+ gesture?.focused != null,
625
+ "focused",
626
+ transition,
627
+ isExiting,
628
+ shouldReduceMotion
629
+ );
630
+ useGestureLayerProgress(
631
+ focusVisibleProgress,
632
+ focusVisible,
633
+ gesture?.focusVisible != null,
634
+ "focusVisible",
635
+ transition,
636
+ isExiting,
637
+ shouldReduceMotion
638
+ );
639
+ useGestureLayerProgress(
640
+ hoveredProgress,
641
+ hovered,
642
+ gesture?.hovered != null,
643
+ "hovered",
644
+ transition,
645
+ isExiting,
646
+ shouldReduceMotion
647
+ );
648
+ const sharedLayout = useSharedLayout({
649
+ layoutId,
650
+ userRef: ref,
651
+ transition: chunkPTRF47DA_js.isTopLevelTransition(transition) ? transition : void 0,
652
+ shouldReduceMotion,
653
+ userOnLayout
654
+ });
655
+ const flip = sharedLayout.flip;
656
+ const hasLayoutId = layoutId !== void 0;
657
+ const animatedStyle = Animated.useAnimatedStyle(() => {
658
+ const activeKeys = activeKeysRef.current;
659
+ const hasTransform = hasTransformRef.current;
660
+ const hasShadowOffset = hasShadowOffsetRef.current;
661
+ const out = {};
662
+ const transform = [];
663
+ let shadowOffsetW = 0;
664
+ let shadowOffsetH = 0;
665
+ const ph = hoveredProgress.value;
666
+ const pf = focusedProgress.value;
667
+ const pfv = focusVisibleProgress.value;
668
+ const pp = pressedProgress.value;
669
+ const layers = gestureSV.value;
670
+ const hoveredLayer = layers ? layers.hovered : null;
671
+ const focusedLayer = layers ? layers.focused : null;
672
+ const focusVisibleLayer = layers ? layers.focusVisible : null;
673
+ const pressedLayer = layers ? layers.pressed : null;
674
+ for (const key of activeKeys) {
675
+ let v = sharedValues[key].value;
676
+ const isColor = COLOR_KEY_SET.has(key);
677
+ if (hoveredLayer && ph > 0 && hoveredLayer[key] !== void 0) {
678
+ const t = hoveredLayer[key];
679
+ v = isColor ? Animated.interpolateColor(ph, [0, 1], [v, t]) : v + (t - v) * ph;
680
+ }
681
+ if (focusedLayer && pf > 0 && focusedLayer[key] !== void 0) {
682
+ const t = focusedLayer[key];
683
+ v = isColor ? Animated.interpolateColor(pf, [0, 1], [v, t]) : v + (t - v) * pf;
684
+ }
685
+ if (focusVisibleLayer && pfv > 0 && focusVisibleLayer[key] !== void 0) {
686
+ const t = focusVisibleLayer[key];
687
+ v = isColor ? Animated.interpolateColor(pfv, [0, 1], [v, t]) : v + (t - v) * pfv;
688
+ }
689
+ if (pressedLayer && pp > 0 && pressedLayer[key] !== void 0) {
690
+ const t = pressedLayer[key];
691
+ v = isColor ? Animated.interpolateColor(pp, [0, 1], [v, t]) : v + (t - v) * pp;
692
+ }
693
+ if (TRANSFORM_KEY_SET.has(key)) {
694
+ transform.push(
695
+ ROTATION_KEYS.has(key) ? { [key]: `${v}deg` } : { [key]: v }
696
+ );
697
+ } else if (key === "shadowOffsetWidth") {
698
+ shadowOffsetW = v;
699
+ } else if (key === "shadowOffsetHeight") {
700
+ shadowOffsetH = v;
701
+ } else {
702
+ out[key] = v;
703
+ }
704
+ }
705
+ if (hasLayoutId) {
706
+ transform.push({ translateX: flip.dx.value });
707
+ transform.push({ translateY: flip.dy.value });
708
+ transform.push({ scaleX: flip.sx.value });
709
+ transform.push({ scaleY: flip.sy.value });
710
+ }
711
+ if (hasTransform || hasLayoutId) out.transform = transform;
712
+ if (hasShadowOffset) {
713
+ out.shadowOffset = { width: shadowOffsetW, height: shadowOffsetH };
714
+ }
715
+ return out;
716
+ });
717
+ const mergedStyle = react.useMemo(
718
+ () => isExiting ? [style, animatedStyle, EXITING_POINTER_EVENTS_STYLE] : [style, animatedStyle],
719
+ [style, animatedStyle, isExiting]
720
+ );
721
+ const gestureHandlers = useGestureHandlers(
722
+ gesture,
723
+ rest,
724
+ setPressed,
725
+ setFocused,
726
+ setFocusVisible,
727
+ setHovered
728
+ );
729
+ const layoutSig = chunkPTRF47DA_js.stableSig(layout);
730
+ const layoutTransition = react.useMemo(
731
+ () => shouldReduceMotion ? void 0 : resolveLayoutTransition(layout),
732
+ // eslint-disable-next-line react-hooks/exhaustive-deps
733
+ [layoutSig, shouldReduceMotion]
734
+ );
735
+ return /* @__PURE__ */ jsxRuntime.jsx(
736
+ AnimatedComponent,
737
+ {
738
+ ref: sharedLayout.setRef,
739
+ ...rest,
740
+ ...gestureHandlers,
741
+ onLayout: sharedLayout.onLayout,
742
+ layout: layoutTransition,
743
+ style: mergedStyle
744
+ }
745
+ );
746
+ }
747
+ );
748
+ MotionAnimated.displayName = `Motion(${Component.displayName ?? Component.name ?? "Component"})`;
749
+ const Motion = react.forwardRef(function Motion2(props, ref) {
750
+ if (hasMotionProps(props)) {
751
+ return /* @__PURE__ */ jsxRuntime.jsx(MotionAnimated, { ref, ...props });
752
+ }
753
+ return /* @__PURE__ */ jsxRuntime.jsx(PlainHost, { ref, ...props });
710
754
  });
711
755
  Motion.displayName = `Motion(${Component.displayName ?? Component.name ?? "Component"})`;
712
756
  return Motion;
713
757
  }
758
+ var MOTION_PROP_KEYS = [
759
+ "initial",
760
+ "animate",
761
+ "exit",
762
+ "transition",
763
+ "variants",
764
+ "controller",
765
+ "gesture",
766
+ "layout",
767
+ "layoutId",
768
+ "onAnimationEnd"
769
+ ];
770
+ function hasMotionProps(props) {
771
+ for (const key of MOTION_PROP_KEYS) {
772
+ if (props[key] !== void 0) return true;
773
+ }
774
+ return false;
775
+ }
714
776
  function useAnimatableSharedValues(init) {
715
777
  const translateX = Animated.useSharedValue(init("translateX"));
716
778
  const translateY = Animated.useSharedValue(init("translateY"));
@@ -767,6 +829,17 @@ function useAnimatableSharedValues(init) {
767
829
  shadowOffsetHeight
768
830
  };
769
831
  }
832
+ const map = ref.current;
833
+ react.useEffect(
834
+ () => () => {
835
+ for (const key in map) {
836
+ Animated.cancelAnimation(map[key]);
837
+ }
838
+ },
839
+ // `map` is identity-stable per hook instance.
840
+ // eslint-disable-next-line react-hooks/exhaustive-deps
841
+ []
842
+ );
770
843
  return ref.current;
771
844
  }
772
845
  function makeKeyCallbackFactory(key, sharedValue, target, onAnimationEndRef, meta, onSettle, transformGroup) {