framer-motion 9.0.2 → 9.0.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.
Files changed (76) hide show
  1. package/dist/cjs/index.js +3344 -3260
  2. package/dist/es/animation/hooks/use-animated-state.mjs +3 -3
  3. package/dist/es/animation/index.mjs +3 -5
  4. package/dist/es/animation/legacy-popmotion/index.mjs +6 -2
  5. package/dist/es/animation/legacy-popmotion/inertia.mjs +4 -5
  6. package/dist/es/components/AnimatePresence/use-presence.mjs +0 -1
  7. package/dist/es/events/add-dom-event.mjs +6 -0
  8. package/dist/es/events/add-pointer-event.mjs +8 -0
  9. package/dist/es/events/use-dom-event.mjs +2 -5
  10. package/dist/es/gestures/drag/VisualElementDragControls.mjs +31 -30
  11. package/dist/es/gestures/drag/index.mjs +27 -0
  12. package/dist/es/gestures/focus.mjs +42 -0
  13. package/dist/es/gestures/hover.mjs +32 -0
  14. package/dist/es/gestures/{PanSession.mjs → pan/PanSession.mjs} +8 -8
  15. package/dist/es/gestures/pan/index.mjs +38 -0
  16. package/dist/es/gestures/press.mjs +109 -0
  17. package/dist/es/index.mjs +1 -1
  18. package/dist/es/motion/features/Feature.mjs +9 -0
  19. package/dist/es/motion/features/animation/exit.mjs +32 -0
  20. package/dist/es/motion/features/animation/index.mjs +38 -0
  21. package/dist/es/motion/features/animations.mjs +8 -37
  22. package/dist/es/motion/features/definitions.mjs +17 -23
  23. package/dist/es/motion/features/drag.mjs +12 -5
  24. package/dist/es/motion/features/gestures.mjs +16 -9
  25. package/dist/es/motion/features/layout/MeasureLayout.mjs +5 -5
  26. package/dist/es/motion/features/layout.mjs +11 -0
  27. package/dist/es/motion/features/load-features.mjs +4 -6
  28. package/dist/es/motion/features/viewport/index.mjs +96 -0
  29. package/dist/es/motion/index.mjs +12 -13
  30. package/dist/es/motion/utils/use-visual-element.mjs +8 -2
  31. package/dist/es/projection/geometry/delta-apply.mjs +9 -2
  32. package/dist/es/projection/geometry/delta-calc.mjs +2 -2
  33. package/dist/es/projection/geometry/delta-remove.mjs +2 -2
  34. package/dist/es/projection/node/DocumentProjectionNode.mjs +1 -1
  35. package/dist/es/projection/node/create-projection-node.mjs +65 -57
  36. package/dist/es/projection/node/group.mjs +5 -3
  37. package/dist/es/projection/shared/stack.mjs +7 -5
  38. package/dist/es/render/VisualElement.mjs +68 -47
  39. package/dist/es/render/dom/DOMVisualElement.mjs +1 -2
  40. package/dist/es/render/dom/features-max.mjs +2 -4
  41. package/dist/es/render/dom/motion.mjs +5 -6
  42. package/dist/es/render/dom/utils/create-config.mjs +1 -2
  43. package/dist/es/render/dom/value-types/animatable-none.mjs +3 -2
  44. package/dist/es/render/svg/SVGVisualElement.mjs +2 -2
  45. package/dist/es/render/utils/animation-state.mjs +6 -2
  46. package/dist/es/render/utils/animation.mjs +4 -4
  47. package/dist/es/render/utils/motion-values.mjs +1 -1
  48. package/dist/es/render/utils/setters.mjs +14 -9
  49. package/dist/es/value/index.mjs +1 -1
  50. package/dist/es/value/utils/is-motion-value.mjs +1 -1
  51. package/dist/framer-motion.dev.js +3341 -3257
  52. package/dist/framer-motion.js +1 -1
  53. package/dist/index.d.ts +85 -77
  54. package/dist/projection.dev.js +217 -177
  55. package/dist/size-rollup-dom-animation-assets.js +1 -1
  56. package/dist/size-rollup-dom-animation-m.js +1 -1
  57. package/dist/size-rollup-dom-animation.js +1 -1
  58. package/dist/size-rollup-dom-max-assets.js +1 -1
  59. package/dist/size-rollup-dom-max.js +1 -1
  60. package/dist/size-rollup-m.js +1 -1
  61. package/dist/size-rollup-motion.js +1 -1
  62. package/dist/size-webpack-dom-animation.js +1 -1
  63. package/dist/size-webpack-dom-max.js +1 -1
  64. package/dist/size-webpack-m.js +1 -1
  65. package/dist/three-entry.d.ts +74 -38
  66. package/package.json +8 -8
  67. package/dist/es/events/use-pointer-event.mjs +0 -11
  68. package/dist/es/gestures/drag/use-drag.mjs +0 -20
  69. package/dist/es/gestures/use-focus-gesture.mjs +0 -37
  70. package/dist/es/gestures/use-hover-gesture.mjs +0 -32
  71. package/dist/es/gestures/use-pan-gesture.mjs +0 -46
  72. package/dist/es/gestures/use-tap-gesture.mjs +0 -115
  73. package/dist/es/motion/features/layout/index.mjs +0 -7
  74. package/dist/es/motion/features/viewport/use-viewport.mjs +0 -97
  75. package/dist/es/motion/utils/VisualElementHandler.mjs +0 -19
  76. package/dist/es/motion/utils/make-renderless-component.mjs +0 -6
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Projection = {}, global.React));
5
- })(this, (function (exports, react) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Projection = {}));
5
+ })(this, (function (exports) { 'use strict';
6
6
 
7
7
  /*
8
8
  Detect and load appropriate clock setting for the execution environment
@@ -1110,7 +1110,6 @@
1110
1110
  };
1111
1111
  };
1112
1112
  function animate$1({ duration, driver = framesync, elapsed = 0, repeat: repeatMax = 0, repeatType = "loop", repeatDelay = 0, keyframes: keyframes$1, autoplay = true, onPlay, onStop, onComplete, onRepeat, onUpdate, type = "keyframes", ...options }) {
1113
- var _a, _b;
1114
1113
  const initialElapsed = elapsed;
1115
1114
  let driverControls;
1116
1115
  let repeatCount = 0;
@@ -1122,7 +1121,12 @@
1122
1121
  const origin = keyframes$1[0];
1123
1122
  const target = keyframes$1[keyframes$1.length - 1];
1124
1123
  let state = { done: false, value: origin };
1125
- if ((_b = (_a = animator).needsInterpolation) === null || _b === void 0 ? void 0 : _b.call(_a, origin, target)) {
1124
+ /**
1125
+ * If this value needs interpolation (ie is non-numerical), set up an interpolator.
1126
+ * TODO: Keyframes animation also performs this step. This could be removed so it only happens here.
1127
+ */
1128
+ const { needsInterpolation } = animator;
1129
+ if (needsInterpolation && needsInterpolation(origin, target)) {
1126
1130
  interpolateFromNumber = interpolate([0, 100], [origin, target], {
1127
1131
  clamp: false,
1128
1132
  });
@@ -1426,16 +1430,15 @@
1426
1430
  return Math.abs(min - v) < Math.abs(max - v) ? min : max;
1427
1431
  }
1428
1432
  function startAnimation(options) {
1429
- currentAnimation === null || currentAnimation === void 0 ? void 0 : currentAnimation.stop();
1433
+ currentAnimation && currentAnimation.stop();
1430
1434
  currentAnimation = animate$1({
1431
1435
  keyframes: [0, 1],
1432
1436
  velocity: 0,
1433
1437
  ...options,
1434
1438
  driver,
1435
1439
  onUpdate: (v) => {
1436
- var _a;
1437
- onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate(v);
1438
- (_a = options.onUpdate) === null || _a === void 0 ? void 0 : _a.call(options, v);
1440
+ onUpdate && onUpdate(v);
1441
+ options.onUpdate && options.onUpdate(v);
1439
1442
  },
1440
1443
  onComplete,
1441
1444
  onStop,
@@ -1494,7 +1497,7 @@
1494
1497
  });
1495
1498
  }
1496
1499
  return {
1497
- stop: () => currentAnimation === null || currentAnimation === void 0 ? void 0 : currentAnimation.stop(),
1500
+ stop: () => currentAnimation && currentAnimation.stop(),
1498
1501
  };
1499
1502
  }
1500
1503
 
@@ -1696,12 +1699,13 @@
1696
1699
  const getDefaultValueType = (key) => defaultValueTypes[key];
1697
1700
 
1698
1701
  function getAnimatableNone(key, value) {
1699
- var _a;
1700
1702
  let defaultValueType = getDefaultValueType(key);
1701
1703
  if (defaultValueType !== filter)
1702
1704
  defaultValueType = complex;
1703
1705
  // If value is not recognised as animatable, ie "none", create an animatable version origin based on the target
1704
- return (_a = defaultValueType.getAnimatableNone) === null || _a === void 0 ? void 0 : _a.call(defaultValueType, value);
1706
+ return defaultValueType.getAnimatableNone
1707
+ ? defaultValueType.getAnimatableNone(value)
1708
+ : undefined;
1705
1709
  }
1706
1710
 
1707
1711
  /**
@@ -1841,14 +1845,12 @@
1841
1845
  if (options.repeatDelay) {
1842
1846
  options.repeatDelay = secondsToMilliseconds(options.repeatDelay);
1843
1847
  }
1844
- const visualElement = value.owner;
1845
- const element = visualElement && visualElement.current;
1846
1848
  /**
1847
1849
  * Animate via WAAPI if possible.
1848
1850
  */
1849
- if (visualElement &&
1850
- element instanceof HTMLElement &&
1851
- !(visualElement === null || visualElement === void 0 ? void 0 : visualElement.getProps().onUpdate)) {
1851
+ if (value.owner &&
1852
+ value.owner.current instanceof HTMLElement &&
1853
+ !value.owner.getProps().onUpdate) {
1852
1854
  const acceleratedAnimation = createAcceleratedAnimation(value, valueName, options);
1853
1855
  if (acceleratedAnimation)
1854
1856
  return acceleratedAnimation;
@@ -1929,7 +1931,7 @@
1929
1931
  * This will be replaced by the build step with the latest version number.
1930
1932
  * When MotionValues are provided to motion components, warn if versions are mixed.
1931
1933
  */
1932
- this.version = "9.0.2";
1934
+ this.version = "9.0.3";
1933
1935
  /**
1934
1936
  * Duration, in milliseconds, since last updating frame.
1935
1937
  *
@@ -2229,7 +2231,7 @@
2229
2231
  return new MotionValue(init, options);
2230
2232
  }
2231
2233
 
2232
- const isMotionValue = (value) => !!(value === null || value === void 0 ? void 0 : value.getVelocity);
2234
+ const isMotionValue = (value) => Boolean(value && value.getVelocity);
2233
2235
 
2234
2236
  /**
2235
2237
  * Animate a single value or a `MotionValue`.
@@ -2433,7 +2435,6 @@
2433
2435
  * This is the final nested loop within updateLayoutDelta for future refactoring
2434
2436
  */
2435
2437
  function applyTreeDeltas(box, treeScale, treePath, isSharedTransition = false) {
2436
- var _a, _b;
2437
2438
  const treeLength = treePath.length;
2438
2439
  if (!treeLength)
2439
2440
  return;
@@ -2444,8 +2445,16 @@
2444
2445
  for (let i = 0; i < treeLength; i++) {
2445
2446
  node = treePath[i];
2446
2447
  delta = node.projectionDelta;
2447
- if (((_b = (_a = node.instance) === null || _a === void 0 ? void 0 : _a.style) === null || _b === void 0 ? void 0 : _b.display) === "contents")
2448
+ /**
2449
+ * TODO: Prefer to remove this, but currently we have motion components with
2450
+ * display: contents in Framer.
2451
+ */
2452
+ const instance = node.instance;
2453
+ if (instance &&
2454
+ instance.style &&
2455
+ instance.style.display === "contents") {
2448
2456
  continue;
2457
+ }
2449
2458
  if (isSharedTransition &&
2450
2459
  node.options.layoutScroll &&
2451
2460
  node.scroll &&
@@ -2524,8 +2533,8 @@
2524
2533
  delta.translate = 0;
2525
2534
  }
2526
2535
  function calcBoxDelta(delta, source, target, origin) {
2527
- calcAxisDelta(delta.x, source.x, target.x, origin === null || origin === void 0 ? void 0 : origin.originX);
2528
- calcAxisDelta(delta.y, source.y, target.y, origin === null || origin === void 0 ? void 0 : origin.originY);
2536
+ calcAxisDelta(delta.x, source.x, target.x, origin ? origin.originX : undefined);
2537
+ calcAxisDelta(delta.y, source.y, target.y, origin ? origin.originY : undefined);
2529
2538
  }
2530
2539
  function calcRelativeAxis(target, relative, parent) {
2531
2540
  target.min = parent.min + relative.min;
@@ -2589,8 +2598,8 @@
2589
2598
  * and acts as a bridge between motion values and removeAxisDelta
2590
2599
  */
2591
2600
  function removeBoxTransforms(box, transforms, originBox, sourceBox) {
2592
- removeAxisTransforms(box.x, transforms, xKeys, originBox === null || originBox === void 0 ? void 0 : originBox.x, sourceBox === null || sourceBox === void 0 ? void 0 : sourceBox.x);
2593
- removeAxisTransforms(box.y, transforms, yKeys, originBox === null || originBox === void 0 ? void 0 : originBox.y, sourceBox === null || sourceBox === void 0 ? void 0 : sourceBox.y);
2601
+ removeAxisTransforms(box.x, transforms, xKeys, originBox ? originBox.x : undefined, sourceBox ? sourceBox.x : undefined);
2602
+ removeAxisTransforms(box.y, transforms, yKeys, originBox ? originBox.y : undefined, sourceBox ? sourceBox.y : undefined);
2594
2603
  }
2595
2604
 
2596
2605
  const createAxisDelta = () => ({
@@ -2669,7 +2678,6 @@
2669
2678
  }
2670
2679
  }
2671
2680
  promote(node, preserveFollowOpacity) {
2672
- var _a;
2673
2681
  const prevLead = this.lead;
2674
2682
  if (node === prevLead)
2675
2683
  return;
@@ -2688,7 +2696,7 @@
2688
2696
  node.snapshot.latestValues =
2689
2697
  prevLead.animationValues || prevLead.latestValues;
2690
2698
  }
2691
- if ((_a = node.root) === null || _a === void 0 ? void 0 : _a.isUpdating) {
2699
+ if (node.root && node.root.isUpdating) {
2692
2700
  node.isLayoutDirty = true;
2693
2701
  }
2694
2702
  const { crossfade } = node.options;
@@ -2711,9 +2719,12 @@
2711
2719
  }
2712
2720
  exitAnimationComplete() {
2713
2721
  this.members.forEach((node) => {
2714
- var _a, _b, _c, _d, _e;
2715
- (_b = (_a = node.options).onExitComplete) === null || _b === void 0 ? void 0 : _b.call(_a);
2716
- (_e = (_c = node.resumingFrom) === null || _c === void 0 ? void 0 : (_d = _c.options).onExitComplete) === null || _e === void 0 ? void 0 : _e.call(_d);
2722
+ const { options, resumingFrom } = node;
2723
+ options.onExitComplete && options.onExitComplete();
2724
+ if (resumingFrom) {
2725
+ resumingFrom.options.onExitComplete &&
2726
+ resumingFrom.options.onExitComplete();
2727
+ }
2717
2728
  });
2718
2729
  }
2719
2730
  scheduleRender() {
@@ -2975,7 +2986,7 @@
2975
2986
  }
2976
2987
  notifyListeners(name, ...args) {
2977
2988
  const subscriptionManager = this.eventHandlers.get(name);
2978
- subscriptionManager === null || subscriptionManager === void 0 ? void 0 : subscriptionManager.notify(...args);
2989
+ subscriptionManager && subscriptionManager.notify(...args);
2979
2990
  }
2980
2991
  hasListeners(name) {
2981
2992
  return this.eventHandlers.has(name);
@@ -2987,7 +2998,6 @@
2987
2998
  * Lifecycles
2988
2999
  */
2989
3000
  mount(instance, isLayoutDirty = false) {
2990
- var _a;
2991
3001
  if (this.instance)
2992
3002
  return;
2993
3003
  this.isSVG =
@@ -2998,7 +3008,7 @@
2998
3008
  visualElement.mount(instance);
2999
3009
  }
3000
3010
  this.root.nodes.add(this);
3001
- (_a = this.parent) === null || _a === void 0 ? void 0 : _a.children.add(this);
3011
+ this.parent && this.parent.children.add(this);
3002
3012
  this.elementId && this.root.potentialNodes.delete(this.elementId);
3003
3013
  if (isLayoutDirty && (layout || layoutId)) {
3004
3014
  this.isLayoutDirty = true;
@@ -3024,14 +3034,15 @@
3024
3034
  visualElement &&
3025
3035
  (layoutId || layout)) {
3026
3036
  this.addEventListener("didUpdate", ({ delta, hasLayoutChanged, hasRelativeTargetChanged, layout: newLayout, }) => {
3027
- var _a, _b, _c, _d, _e;
3028
3037
  if (this.isTreeAnimationBlocked()) {
3029
3038
  this.target = undefined;
3030
3039
  this.relativeTarget = undefined;
3031
3040
  return;
3032
3041
  }
3033
3042
  // TODO: Check here if an animation exists
3034
- const layoutTransition = (_b = (_a = this.options.transition) !== null && _a !== void 0 ? _a : visualElement.getDefaultTransition()) !== null && _b !== void 0 ? _b : defaultLayoutTransition;
3043
+ const layoutTransition = this.options.transition ||
3044
+ visualElement.getDefaultTransition() ||
3045
+ defaultLayoutTransition;
3035
3046
  const { onLayoutAnimationStart, onLayoutAnimationComplete, } = visualElement.getProps();
3036
3047
  /**
3037
3048
  * The target layout of the element might stay the same,
@@ -3047,7 +3058,7 @@
3047
3058
  */
3048
3059
  const hasOnlyRelativeTargetChanged = !hasLayoutChanged && hasRelativeTargetChanged;
3049
3060
  if (this.options.layoutRoot ||
3050
- ((_c = this.resumeFrom) === null || _c === void 0 ? void 0 : _c.instance) ||
3061
+ (this.resumeFrom && this.resumeFrom.instance) ||
3051
3062
  hasOnlyRelativeTargetChanged ||
3052
3063
  (hasLayoutChanged &&
3053
3064
  (targetChanged || !this.currentAnimation))) {
@@ -3078,18 +3089,20 @@
3078
3089
  this.animationProgress === 0) {
3079
3090
  finishAnimation(this);
3080
3091
  }
3081
- this.isLead() && ((_e = (_d = this.options).onExitComplete) === null || _e === void 0 ? void 0 : _e.call(_d));
3092
+ if (this.isLead() && this.options.onExitComplete) {
3093
+ this.options.onExitComplete();
3094
+ }
3082
3095
  }
3083
3096
  this.targetLayout = newLayout;
3084
3097
  });
3085
3098
  }
3086
3099
  }
3087
3100
  unmount() {
3088
- var _a, _b;
3089
3101
  this.options.layoutId && this.willUpdate();
3090
3102
  this.root.nodes.remove(this);
3091
- (_a = this.getStack()) === null || _a === void 0 ? void 0 : _a.remove(this);
3092
- (_b = this.parent) === null || _b === void 0 ? void 0 : _b.children.delete(this);
3103
+ const stack = this.getStack();
3104
+ stack && stack.remove(this);
3105
+ this.parent && this.parent.children.delete(this);
3093
3106
  this.instance = undefined;
3094
3107
  cancelSync.preRender(this.updateProjection);
3095
3108
  }
@@ -3104,28 +3117,25 @@
3104
3117
  return this.updateManuallyBlocked || this.updateBlockedByResize;
3105
3118
  }
3106
3119
  isTreeAnimationBlocked() {
3107
- var _a;
3108
3120
  return (this.isAnimationBlocked ||
3109
- ((_a = this.parent) === null || _a === void 0 ? void 0 : _a.isTreeAnimationBlocked()) ||
3121
+ (this.parent && this.parent.isTreeAnimationBlocked()) ||
3110
3122
  false);
3111
3123
  }
3112
3124
  // Note: currently only running on root node
3113
3125
  startUpdate() {
3114
- var _a;
3115
3126
  if (this.isUpdateBlocked())
3116
3127
  return;
3117
3128
  this.isUpdating = true;
3118
- (_a = this.nodes) === null || _a === void 0 ? void 0 : _a.forEach(resetRotation);
3129
+ this.nodes && this.nodes.forEach(resetRotation);
3119
3130
  this.animationId++;
3120
3131
  }
3121
3132
  getTransformTemplate() {
3122
- var _a;
3123
- return (_a = this.options.visualElement) === null || _a === void 0 ? void 0 : _a.getProps().transformTemplate;
3133
+ const { visualElement } = this.options;
3134
+ return visualElement && visualElement.getProps().transformTemplate;
3124
3135
  }
3125
3136
  willUpdate(shouldNotifyListeners = true) {
3126
- var _a, _b, _c;
3127
3137
  if (this.root.isUpdateBlocked()) {
3128
- (_b = (_a = this.options).onExitComplete) === null || _b === void 0 ? void 0 : _b.call(_a);
3138
+ this.options.onExitComplete && this.options.onExitComplete();
3129
3139
  return;
3130
3140
  }
3131
3141
  !this.root.isUpdating && this.root.startUpdate();
@@ -3143,7 +3153,10 @@
3143
3153
  const { layoutId, layout } = this.options;
3144
3154
  if (layoutId === undefined && !layout)
3145
3155
  return;
3146
- this.prevTransformTemplateValue = (_c = this.getTransformTemplate()) === null || _c === void 0 ? void 0 : _c(this.latestValues, "");
3156
+ const transformTemplate = this.getTransformTemplate();
3157
+ this.prevTransformTemplateValue = transformTemplate
3158
+ ? transformTemplate(this.latestValues, "")
3159
+ : undefined;
3147
3160
  this.updateSnapshot();
3148
3161
  shouldNotifyListeners && this.notifyListeners("willUpdate");
3149
3162
  }
@@ -3223,7 +3236,6 @@
3223
3236
  this.snapshot = this.measure();
3224
3237
  }
3225
3238
  updateLayout() {
3226
- var _a;
3227
3239
  if (!this.instance)
3228
3240
  return;
3229
3241
  // TODO: Incorporate into a forwarded scroll offset
@@ -3251,7 +3263,9 @@
3251
3263
  this.isLayoutDirty = false;
3252
3264
  this.projectionDelta = undefined;
3253
3265
  this.notifyListeners("measure", this.layout.layoutBox);
3254
- (_a = this.options.visualElement) === null || _a === void 0 ? void 0 : _a.notify("LayoutMeasure", this.layout.layoutBox, prevLayout === null || prevLayout === void 0 ? void 0 : prevLayout.layoutBox);
3266
+ const { visualElement } = this.options;
3267
+ visualElement &&
3268
+ visualElement.notify("LayoutMeasure", this.layout.layoutBox, prevLayout ? prevLayout.layoutBox : undefined);
3255
3269
  }
3256
3270
  updateScroll(phase = "measure") {
3257
3271
  let needsMeasurement = Boolean(this.options.layoutScroll && this.instance);
@@ -3270,12 +3284,14 @@
3270
3284
  }
3271
3285
  }
3272
3286
  resetTransform() {
3273
- var _a;
3274
3287
  if (!resetTransform)
3275
3288
  return;
3276
3289
  const isResetRequested = this.isLayoutDirty || this.shouldResetTransform;
3277
3290
  const hasProjection = this.projectionDelta && !isDeltaZero(this.projectionDelta);
3278
- const transformTemplateValue = (_a = this.getTransformTemplate()) === null || _a === void 0 ? void 0 : _a(this.latestValues, "");
3291
+ const transformTemplate = this.getTransformTemplate();
3292
+ const transformTemplateValue = transformTemplate
3293
+ ? transformTemplate(this.latestValues, "")
3294
+ : undefined;
3279
3295
  const transformTemplateHasChanged = transformTemplateValue !== this.prevTransformTemplateValue;
3280
3296
  if (isResetRequested &&
3281
3297
  (hasProjection ||
@@ -3376,7 +3392,6 @@
3376
3392
  return withTransforms;
3377
3393
  }
3378
3394
  removeTransform(box) {
3379
- var _a;
3380
3395
  const boxWithoutTransform = createBox();
3381
3396
  copyBoxInto(boxWithoutTransform, box);
3382
3397
  for (let i = 0; i < this.path.length; i++) {
@@ -3389,7 +3404,7 @@
3389
3404
  const sourceBox = createBox();
3390
3405
  const nodeBox = node.measurePageBox();
3391
3406
  copyBoxInto(sourceBox, nodeBox);
3392
- removeBoxTransforms(boxWithoutTransform, node.latestValues, (_a = node.snapshot) === null || _a === void 0 ? void 0 : _a.layoutBox, sourceBox);
3407
+ removeBoxTransforms(boxWithoutTransform, node.latestValues, node.snapshot ? node.snapshot.layoutBox : undefined, sourceBox);
3393
3408
  }
3394
3409
  if (hasTransform(this.latestValues)) {
3395
3410
  removeBoxTransforms(boxWithoutTransform, this.latestValues);
@@ -3424,7 +3439,6 @@
3424
3439
  * Frame calculations
3425
3440
  */
3426
3441
  resolveTargetDelta() {
3427
- var _a;
3428
3442
  /**
3429
3443
  * Once the dirty status of nodes has been spread through the tree, we also
3430
3444
  * need to check if we have a shared node of a different depth that has itself
@@ -3483,7 +3497,8 @@
3483
3497
  */
3484
3498
  if (this.relativeTarget &&
3485
3499
  this.relativeTargetOrigin &&
3486
- ((_a = this.relativeParent) === null || _a === void 0 ? void 0 : _a.target)) {
3500
+ this.relativeParent &&
3501
+ this.relativeParent.target) {
3487
3502
  calcRelativeBox(this.target, this.relativeTarget, this.relativeParent.target);
3488
3503
  /**
3489
3504
  * If we've only got a targetDelta, resolve it into a target
@@ -3544,7 +3559,6 @@
3544
3559
  }
3545
3560
  }
3546
3561
  calcProjection() {
3547
- var _a;
3548
3562
  const { isProjectionDirty, isTransformDirty } = this;
3549
3563
  this.isProjectionDirty = this.isTransformDirty = false;
3550
3564
  const lead = this.getLead();
@@ -3561,7 +3575,7 @@
3561
3575
  * If this section of the tree isn't animating we can
3562
3576
  * delete our target sources for the following frame.
3563
3577
  */
3564
- this.isTreeAnimating = Boolean(((_a = this.parent) === null || _a === void 0 ? void 0 : _a.isTreeAnimating) ||
3578
+ this.isTreeAnimating = Boolean((this.parent && this.parent.isTreeAnimating) ||
3565
3579
  this.currentAnimation ||
3566
3580
  this.pendingAnimation);
3567
3581
  if (!this.isTreeAnimating) {
@@ -3617,17 +3631,20 @@
3617
3631
  // TODO: Schedule render
3618
3632
  }
3619
3633
  scheduleRender(notifyAll = true) {
3620
- var _a, _b, _c;
3621
- (_b = (_a = this.options).scheduleRender) === null || _b === void 0 ? void 0 : _b.call(_a);
3622
- notifyAll && ((_c = this.getStack()) === null || _c === void 0 ? void 0 : _c.scheduleRender());
3634
+ this.options.scheduleRender && this.options.scheduleRender();
3635
+ if (notifyAll) {
3636
+ const stack = this.getStack();
3637
+ stack && stack.scheduleRender();
3638
+ }
3623
3639
  if (this.resumingFrom && !this.resumingFrom.instance) {
3624
3640
  this.resumingFrom = undefined;
3625
3641
  }
3626
3642
  }
3627
3643
  setAnimationOrigin(delta, hasOnlyRelativeTargetChanged = false) {
3628
- var _a, _b;
3629
3644
  const snapshot = this.snapshot;
3630
- const snapshotLatestValues = (snapshot === null || snapshot === void 0 ? void 0 : snapshot.latestValues) || {};
3645
+ const snapshotLatestValues = snapshot
3646
+ ? snapshot.latestValues
3647
+ : {};
3631
3648
  const mixedValues = { ...this.latestValues };
3632
3649
  const targetDelta = createDelta();
3633
3650
  if (!this.relativeParent ||
@@ -3636,15 +3653,17 @@
3636
3653
  }
3637
3654
  this.attemptToResolveRelativeTarget = !hasOnlyRelativeTargetChanged;
3638
3655
  const relativeLayout = createBox();
3639
- const isSharedLayoutAnimation = (snapshot === null || snapshot === void 0 ? void 0 : snapshot.source) !== ((_a = this.layout) === null || _a === void 0 ? void 0 : _a.source);
3640
- const isOnlyMember = (((_b = this.getStack()) === null || _b === void 0 ? void 0 : _b.members.length) || 0) <= 1;
3656
+ const snapshotSource = snapshot ? snapshot.source : undefined;
3657
+ const layoutSource = this.layout ? this.layout.source : undefined;
3658
+ const isSharedLayoutAnimation = snapshotSource !== layoutSource;
3659
+ const stack = this.getStack();
3660
+ const isOnlyMember = !stack || stack.members.length <= 1;
3641
3661
  const shouldCrossfadeOpacity = Boolean(isSharedLayoutAnimation &&
3642
3662
  !isOnlyMember &&
3643
3663
  this.options.crossfade === true &&
3644
3664
  !this.path.some(hasOpacityCrossfade));
3645
3665
  this.animationProgress = 0;
3646
3666
  this.mixTargetDelta = (latest) => {
3647
- var _a;
3648
3667
  const progress = latest / 1000;
3649
3668
  mixAxisDelta(targetDelta.x, delta.x, progress);
3650
3669
  mixAxisDelta(targetDelta.y, delta.y, progress);
@@ -3652,7 +3671,8 @@
3652
3671
  if (this.relativeTarget &&
3653
3672
  this.relativeTargetOrigin &&
3654
3673
  this.layout &&
3655
- ((_a = this.relativeParent) === null || _a === void 0 ? void 0 : _a.layout)) {
3674
+ this.relativeParent &&
3675
+ this.relativeParent.layout) {
3656
3676
  calcRelativePosition(relativeLayout, this.layout.layoutBox, this.relativeParent.layout.layoutBox);
3657
3677
  mixBox(this.relativeTarget, this.relativeTargetOrigin, relativeLayout, progress);
3658
3678
  }
@@ -3667,11 +3687,10 @@
3667
3687
  this.mixTargetDelta(this.options.layoutRoot ? 1000 : 0);
3668
3688
  }
3669
3689
  startAnimation(options) {
3670
- var _a, _b;
3671
3690
  this.notifyListeners("animationStart");
3672
- (_a = this.currentAnimation) === null || _a === void 0 ? void 0 : _a.stop();
3673
- if (this.resumingFrom) {
3674
- (_b = this.resumingFrom.currentAnimation) === null || _b === void 0 ? void 0 : _b.stop();
3691
+ this.currentAnimation && this.currentAnimation.stop();
3692
+ if (this.resumingFrom && this.resumingFrom.currentAnimation) {
3693
+ this.resumingFrom.currentAnimation.stop();
3675
3694
  }
3676
3695
  if (this.pendingAnimation) {
3677
3696
  cancelSync.update(this.pendingAnimation);
@@ -3687,13 +3706,11 @@
3687
3706
  this.currentAnimation = animate(0, animationTarget, {
3688
3707
  ...options,
3689
3708
  onUpdate: (latest) => {
3690
- var _a;
3691
3709
  this.mixTargetDelta(latest);
3692
- (_a = options.onUpdate) === null || _a === void 0 ? void 0 : _a.call(options, latest);
3710
+ options.onUpdate && options.onUpdate(latest);
3693
3711
  },
3694
3712
  onComplete: () => {
3695
- var _a;
3696
- (_a = options.onComplete) === null || _a === void 0 ? void 0 : _a.call(options);
3713
+ options.onComplete && options.onComplete();
3697
3714
  this.completeAnimation();
3698
3715
  },
3699
3716
  });
@@ -3704,12 +3721,12 @@
3704
3721
  });
3705
3722
  }
3706
3723
  completeAnimation() {
3707
- var _a;
3708
3724
  if (this.resumingFrom) {
3709
3725
  this.resumingFrom.currentAnimation = undefined;
3710
3726
  this.resumingFrom.preserveOpacity = undefined;
3711
3727
  }
3712
- (_a = this.getStack()) === null || _a === void 0 ? void 0 : _a.exitAnimationComplete();
3728
+ const stack = this.getStack();
3729
+ stack && stack.exitAnimationComplete();
3713
3730
  this.resumingFrom =
3714
3731
  this.currentAnimation =
3715
3732
  this.animationValues =
@@ -3717,9 +3734,8 @@
3717
3734
  this.notifyListeners("animationComplete");
3718
3735
  }
3719
3736
  finishAnimation() {
3720
- var _a;
3721
3737
  if (this.currentAnimation) {
3722
- (_a = this.mixTargetDelta) === null || _a === void 0 ? void 0 : _a.call(this, animationTarget);
3738
+ this.mixTargetDelta && this.mixTargetDelta(animationTarget);
3723
3739
  this.currentAnimation.stop();
3724
3740
  }
3725
3741
  this.completeAnimation();
@@ -3762,15 +3778,17 @@
3762
3778
  calcBoxDelta(this.projectionDeltaWithTransform, this.layoutCorrected, targetWithTransforms, latestValues);
3763
3779
  }
3764
3780
  registerSharedNode(layoutId, node) {
3765
- var _a, _b, _c;
3766
3781
  if (!this.sharedNodes.has(layoutId)) {
3767
3782
  this.sharedNodes.set(layoutId, new NodeStack());
3768
3783
  }
3769
3784
  const stack = this.sharedNodes.get(layoutId);
3770
3785
  stack.add(node);
3786
+ const config = node.options.initialPromotionConfig;
3771
3787
  node.promote({
3772
- transition: (_a = node.options.initialPromotionConfig) === null || _a === void 0 ? void 0 : _a.transition,
3773
- preserveFollowOpacity: (_c = (_b = node.options.initialPromotionConfig) === null || _b === void 0 ? void 0 : _b.shouldPreserveFollowOpacity) === null || _c === void 0 ? void 0 : _c.call(_b, node),
3788
+ transition: config ? config.transition : undefined,
3789
+ preserveFollowOpacity: config && config.shouldPreserveFollowOpacity
3790
+ ? config.shouldPreserveFollowOpacity(node)
3791
+ : undefined,
3774
3792
  });
3775
3793
  }
3776
3794
  isLead() {
@@ -3844,7 +3862,7 @@
3844
3862
  }
3845
3863
  // Force a render of this element to apply the transform with all rotations
3846
3864
  // set to 0.
3847
- visualElement === null || visualElement === void 0 ? void 0 : visualElement.render();
3865
+ visualElement.render();
3848
3866
  // Put back all the values we reset
3849
3867
  for (const key in resetValues) {
3850
3868
  visualElement.setStaticValue(key, resetValues[key]);
@@ -3983,7 +4001,7 @@
3983
4001
  node.updateLayout();
3984
4002
  }
3985
4003
  function notifyLayoutUpdate(node) {
3986
- var _a, _b, _c;
4004
+ var _a;
3987
4005
  const snapshot = ((_a = node.resumeFrom) === null || _a === void 0 ? void 0 : _a.snapshot) || node.snapshot;
3988
4006
  if (node.isLead() &&
3989
4007
  node.layout &&
@@ -4058,7 +4076,8 @@
4058
4076
  });
4059
4077
  }
4060
4078
  else if (node.isLead()) {
4061
- (_c = (_b = node.options).onExitComplete) === null || _c === void 0 ? void 0 : _c.call(_b);
4079
+ const { onExitComplete } = node.options;
4080
+ onExitComplete && onExitComplete();
4062
4081
  }
4063
4082
  /**
4064
4083
  * Clearing transition
@@ -4086,7 +4105,7 @@
4086
4105
  }
4087
4106
  function resetTransformStyle(node) {
4088
4107
  const { visualElement } = node.options;
4089
- if (visualElement === null || visualElement === void 0 ? void 0 : visualElement.getProps().onBeforeLayoutMeasure) {
4108
+ if (visualElement && visualElement.getProps().onBeforeLayoutMeasure) {
4090
4109
  visualElement.notify("BeforeLayoutMeasure");
4091
4110
  }
4092
4111
  node.resetTransform();
@@ -4207,10 +4226,12 @@
4207
4226
  subscriptions.set(node, node.addEventListener("willUpdate", dirtyAll));
4208
4227
  },
4209
4228
  remove: (node) => {
4210
- var _a;
4211
4229
  nodes.delete(node);
4212
- (_a = subscriptions.get(node)) === null || _a === void 0 ? void 0 : _a();
4213
- subscriptions.delete(node);
4230
+ const unsubscribe = subscriptions.get(node);
4231
+ if (unsubscribe) {
4232
+ unsubscribe();
4233
+ subscriptions.delete(node);
4234
+ }
4214
4235
  dirtyAll();
4215
4236
  },
4216
4237
  dirty: dirtyAll,
@@ -4724,14 +4745,18 @@
4724
4745
  return valueTransition.from;
4725
4746
  }
4726
4747
  function getOrigin(target, transition, visualElement) {
4727
- var _a;
4728
4748
  const origin = {};
4729
4749
  for (const key in target) {
4730
4750
  const transitionOrigin = getOriginFromTransition(key, transition);
4731
- origin[key] =
4732
- transitionOrigin !== undefined
4733
- ? transitionOrigin
4734
- : (_a = visualElement.getValue(key)) === null || _a === void 0 ? void 0 : _a.get();
4751
+ if (transitionOrigin !== undefined) {
4752
+ origin[key] = transitionOrigin;
4753
+ }
4754
+ else {
4755
+ const value = visualElement.getValue(key);
4756
+ if (value) {
4757
+ origin[key] = value.get();
4758
+ }
4759
+ }
4735
4760
  }
4736
4761
  return origin;
4737
4762
  }
@@ -4968,39 +4993,6 @@
4968
4993
  return unitConversion(visualElement, target, origin, transitionEnd);
4969
4994
  };
4970
4995
 
4971
- const createDefinition = (propNames) => ({
4972
- isEnabled: (props) => propNames.some((name) => !!props[name]),
4973
- });
4974
- const featureDefinitions = {
4975
- measureLayout: createDefinition(["layout", "layoutId", "drag"]),
4976
- animation: createDefinition([
4977
- "animate",
4978
- "exit",
4979
- "variants",
4980
- "whileHover",
4981
- "whileTap",
4982
- "whileFocus",
4983
- "whileDrag",
4984
- "whileInView",
4985
- ]),
4986
- exit: createDefinition(["exit"]),
4987
- drag: createDefinition(["drag", "dragControls"]),
4988
- focus: createDefinition(["whileFocus"]),
4989
- hover: createDefinition(["whileHover", "onHoverStart", "onHoverEnd"]),
4990
- tap: createDefinition(["whileTap", "onTap", "onTapStart", "onTapCancel"]),
4991
- pan: createDefinition([
4992
- "onPan",
4993
- "onPanStart",
4994
- "onPanSessionStart",
4995
- "onPanEnd",
4996
- ]),
4997
- inView: createDefinition([
4998
- "whileInView",
4999
- "onViewportEnter",
5000
- "onViewportLeave",
5001
- ]),
5002
- };
5003
-
5004
4996
  function isRefObject(ref) {
5005
4997
  return (typeof ref === "object" &&
5006
4998
  Object.prototype.hasOwnProperty.call(ref, "current"));
@@ -5108,7 +5100,7 @@
5108
5100
  * and warn against mismatches.
5109
5101
  */
5110
5102
  {
5111
- warnOnce(nextValue.version === "9.0.2", `Attempting to mix Framer Motion versions ${nextValue.version} with 9.0.2 may not work as expected.`);
5103
+ warnOnce(nextValue.version === "9.0.3", `Attempting to mix Framer Motion versions ${nextValue.version} with 9.0.3 may not work as expected.`);
5112
5104
  }
5113
5105
  }
5114
5106
  else if (isMotionValue(prevValue)) {
@@ -5146,6 +5138,33 @@
5146
5138
  return next;
5147
5139
  }
5148
5140
 
5141
+ const featureProps = {
5142
+ animation: [
5143
+ "animate",
5144
+ "exit",
5145
+ "variants",
5146
+ "whileHover",
5147
+ "whileTap",
5148
+ "whileFocus",
5149
+ "whileDrag",
5150
+ "whileInView",
5151
+ ],
5152
+ exit: ["exit"],
5153
+ drag: ["drag", "dragControls"],
5154
+ focus: ["whileFocus"],
5155
+ hover: ["whileHover", "onHoverStart", "onHoverEnd"],
5156
+ tap: ["whileTap", "onTap", "onTapStart", "onTapCancel"],
5157
+ pan: ["onPan", "onPanStart", "onPanSessionStart", "onPanEnd"],
5158
+ inView: ["whileInView", "onViewportEnter", "onViewportLeave"],
5159
+ layout: ["layout", "layoutId"],
5160
+ };
5161
+ const featureDefinitions = {};
5162
+ for (const key in featureProps) {
5163
+ featureDefinitions[key] = {
5164
+ isEnabled: (props) => featureProps[key].some((name) => !!props[name]),
5165
+ };
5166
+ }
5167
+
5149
5168
  const featureNames = Object.keys(featureDefinitions);
5150
5169
  const numFeatures = featureNames.length;
5151
5170
  const propEventHandlers = [
@@ -5162,7 +5181,7 @@
5162
5181
  * HTMLElement, SVGElement, Three.Object3D etc.
5163
5182
  */
5164
5183
  class VisualElement {
5165
- constructor({ parent, props, reducedMotionConfig, visualState, }, options = {}) {
5184
+ constructor({ parent, props, presenceContext, reducedMotionConfig, visualState, }, options = {}) {
5166
5185
  /**
5167
5186
  * A reference to the current underlying Instance, e.g. a HTMLElement
5168
5187
  * or Three.Mesh etc.
@@ -5192,10 +5211,9 @@
5192
5211
  */
5193
5212
  this.values = new Map();
5194
5213
  /**
5195
- * Tracks whether this VisualElement's React component is currently present
5196
- * within the defined React tree.
5214
+ * Cleanup functions for active features (hover/tap/exit etc)
5197
5215
  */
5198
- this.isPresent = true;
5216
+ this.features = {};
5199
5217
  /**
5200
5218
  * A map of every subscription that binds the provided or generated
5201
5219
  * motion values onChange listeners to this visual element.
@@ -5232,6 +5250,7 @@
5232
5250
  this.renderState = renderState;
5233
5251
  this.parent = parent;
5234
5252
  this.props = props;
5253
+ this.presenceContext = presenceContext;
5235
5254
  this.depth = parent ? parent.depth + 1 : 0;
5236
5255
  this.reducedMotionConfig = reducedMotionConfig;
5237
5256
  this.options = options;
@@ -5273,13 +5292,12 @@
5273
5292
  return {};
5274
5293
  }
5275
5294
  mount(instance) {
5276
- var _a;
5277
5295
  this.current = instance;
5278
5296
  if (this.projection) {
5279
5297
  this.projection.mount(instance);
5280
5298
  }
5281
5299
  if (this.parent && this.isVariantNode && !this.isControllingVariants) {
5282
- this.removeFromVariantTree = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.addVariantChild(this);
5300
+ this.removeFromVariantTree = this.parent.addVariantChild(this);
5283
5301
  }
5284
5302
  this.values.forEach((value, key) => this.bindToMotionValue(key, value));
5285
5303
  if (!hasReducedMotionListener.current) {
@@ -5296,19 +5314,21 @@
5296
5314
  }
5297
5315
  if (this.parent)
5298
5316
  this.parent.children.add(this);
5299
- this.setProps(this.props);
5317
+ this.update(this.props, this.presenceContext);
5300
5318
  }
5301
5319
  unmount() {
5302
- var _a, _b, _c;
5303
- (_a = this.projection) === null || _a === void 0 ? void 0 : _a.unmount();
5320
+ this.projection && this.projection.unmount();
5304
5321
  cancelSync.update(this.notifyUpdate);
5305
5322
  cancelSync.render(this.render);
5306
5323
  this.valueSubscriptions.forEach((remove) => remove());
5307
- (_b = this.removeFromVariantTree) === null || _b === void 0 ? void 0 : _b.call(this);
5308
- (_c = this.parent) === null || _c === void 0 ? void 0 : _c.children.delete(this);
5324
+ this.removeFromVariantTree && this.removeFromVariantTree();
5325
+ this.parent && this.parent.children.delete(this);
5309
5326
  for (const key in this.events) {
5310
5327
  this.events[key].clear();
5311
5328
  }
5329
+ for (const key in this.features) {
5330
+ this.features[key].unmount();
5331
+ }
5312
5332
  this.current = null;
5313
5333
  }
5314
5334
  bindToMotionValue(key, value) {
@@ -5333,12 +5353,14 @@
5333
5353
  */
5334
5354
  if (!this.current ||
5335
5355
  !this.sortInstanceNodePosition ||
5336
- this.type !== other.type)
5356
+ this.type !== other.type) {
5337
5357
  return 0;
5358
+ }
5338
5359
  return this.sortInstanceNodePosition(this.current, other.current);
5339
5360
  }
5340
- loadFeatures({ children, ...renderedProps }, isStrict, preloadedFeatures, projectionId, ProjectionNodeConstructor, initialLayoutGroupConfig) {
5341
- const features = [];
5361
+ loadFeatures({ children, ...renderedProps }, isStrict, preloadedFeatures, projectionId, initialLayoutGroupConfig) {
5362
+ let ProjectionNodeConstructor;
5363
+ let MeasureLayout;
5342
5364
  /**
5343
5365
  * If we're in development mode, check to make sure we're not rendering a motion component
5344
5366
  * as a child of LazyMotion, as this will break the file-size benefits of using it.
@@ -5352,18 +5374,16 @@
5352
5374
  }
5353
5375
  for (let i = 0; i < numFeatures; i++) {
5354
5376
  const name = featureNames[i];
5355
- const { isEnabled, Component } = featureDefinitions[name];
5356
- /**
5357
- * It might be possible in the future to use this moment to
5358
- * dynamically request functionality. In initial tests this
5359
- * was producing a lot of duplication amongst bundles.
5360
- */
5361
- if (isEnabled(renderedProps) && Component) {
5362
- features.push(react.createElement(Component, {
5363
- key: name,
5364
- ...renderedProps,
5365
- visualElement: this,
5366
- }));
5377
+ const { isEnabled, Feature: FeatureConstructor, ProjectionNode, MeasureLayout: MeasureLayoutComponent, } = featureDefinitions[name];
5378
+ if (ProjectionNode)
5379
+ ProjectionNodeConstructor = ProjectionNode;
5380
+ if (isEnabled(renderedProps)) {
5381
+ if (!this.features[name] && FeatureConstructor) {
5382
+ this.features[name] = new FeatureConstructor(this);
5383
+ }
5384
+ if (MeasureLayoutComponent) {
5385
+ MeasureLayout = MeasureLayoutComponent;
5386
+ }
5367
5387
  }
5368
5388
  }
5369
5389
  if (!this.projection && ProjectionNodeConstructor) {
@@ -5389,7 +5409,19 @@
5389
5409
  layoutRoot,
5390
5410
  });
5391
5411
  }
5392
- return features;
5412
+ return MeasureLayout;
5413
+ }
5414
+ updateFeatures() {
5415
+ for (const key in this.features) {
5416
+ const feature = this.features[key];
5417
+ if (feature.isMounted) {
5418
+ feature.update(this.props, this.prevProps);
5419
+ }
5420
+ else {
5421
+ feature.mount();
5422
+ feature.isMounted = true;
5423
+ }
5424
+ }
5393
5425
  }
5394
5426
  triggerBuild() {
5395
5427
  this.build(this.renderState, this.latestValues, this.options, this.props);
@@ -5424,12 +5456,14 @@
5424
5456
  * Update the provided props. Ensure any newly-added motion values are
5425
5457
  * added to our map, old ones removed, and listeners updated.
5426
5458
  */
5427
- setProps(props) {
5459
+ update(props, presenceContext) {
5428
5460
  if (props.transformTemplate || this.props.transformTemplate) {
5429
5461
  this.scheduleRender();
5430
5462
  }
5431
- const prevProps = this.props;
5463
+ this.prevProps = this.props;
5432
5464
  this.props = props;
5465
+ this.prevPresenceContext = this.presenceContext;
5466
+ this.presenceContext = presenceContext;
5433
5467
  /**
5434
5468
  * Update prop event handlers ie onAnimationStart, onAnimationComplete
5435
5469
  */
@@ -5444,7 +5478,7 @@
5444
5478
  this.propEventSubscriptions[key] = this.on(key, listener);
5445
5479
  }
5446
5480
  }
5447
- this.prevMotionValues = updateMotionValuesFromProps(this, this.scrapeMotionValuesFromProps(props, prevProps), this.prevMotionValues);
5481
+ this.prevMotionValues = updateMotionValuesFromProps(this, this.scrapeMotionValuesFromProps(props, this.prevProps), this.prevMotionValues);
5448
5482
  if (this.handleChildMotionValue) {
5449
5483
  this.handleChildMotionValue();
5450
5484
  }
@@ -5456,8 +5490,7 @@
5456
5490
  * Returns the variant definition with a given name.
5457
5491
  */
5458
5492
  getVariant(name) {
5459
- var _a;
5460
- return (_a = this.props.variants) === null || _a === void 0 ? void 0 : _a[name];
5493
+ return this.props.variants ? this.props.variants[name] : undefined;
5461
5494
  }
5462
5495
  /**
5463
5496
  * Returns the defined default transition on this component.
@@ -5469,15 +5502,20 @@
5469
5502
  return this.props.transformPagePoint;
5470
5503
  }
5471
5504
  getClosestVariantNode() {
5472
- var _a;
5473
- return this.isVariantNode ? this : (_a = this.parent) === null || _a === void 0 ? void 0 : _a.getClosestVariantNode();
5505
+ return this.isVariantNode
5506
+ ? this
5507
+ : this.parent
5508
+ ? this.parent.getClosestVariantNode()
5509
+ : undefined;
5474
5510
  }
5475
5511
  getVariantContext(startAtParent = false) {
5476
- var _a, _b;
5477
- if (startAtParent)
5478
- return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.getVariantContext();
5512
+ if (startAtParent) {
5513
+ return this.parent ? this.parent.getVariantContext() : undefined;
5514
+ }
5479
5515
  if (!this.isControllingVariants) {
5480
- const context = ((_b = this.parent) === null || _b === void 0 ? void 0 : _b.getVariantContext()) || {};
5516
+ const context = this.parent
5517
+ ? this.parent.getVariantContext() || {}
5518
+ : {};
5481
5519
  if (this.props.initial !== undefined) {
5482
5520
  context.initial = this.props.initial;
5483
5521
  }
@@ -5497,10 +5535,10 @@
5497
5535
  * Add a child visual element to our set of children.
5498
5536
  */
5499
5537
  addVariantChild(child) {
5500
- var _a;
5501
5538
  const closestVariantNode = this.getClosestVariantNode();
5502
5539
  if (closestVariantNode) {
5503
- (_a = closestVariantNode.variantChildren) === null || _a === void 0 ? void 0 : _a.add(child);
5540
+ closestVariantNode.variantChildren &&
5541
+ closestVariantNode.variantChildren.add(child);
5504
5542
  return () => closestVariantNode.variantChildren.delete(child);
5505
5543
  }
5506
5544
  }
@@ -5520,10 +5558,12 @@
5520
5558
  * Remove a motion value and unbind any active subscriptions.
5521
5559
  */
5522
5560
  removeValue(key) {
5523
- var _a;
5524
5561
  this.values.delete(key);
5525
- (_a = this.valueSubscriptions.get(key)) === null || _a === void 0 ? void 0 : _a();
5526
- this.valueSubscriptions.delete(key);
5562
+ const unsubscribe = this.valueSubscriptions.get(key);
5563
+ if (unsubscribe) {
5564
+ unsubscribe();
5565
+ this.valueSubscriptions.delete(key);
5566
+ }
5527
5567
  delete this.latestValues[key];
5528
5568
  this.removeValueFromRenderState(key, this.renderState);
5529
5569
  }
@@ -5600,8 +5640,9 @@
5600
5640
  return this.events[eventName].add(callback);
5601
5641
  }
5602
5642
  notify(eventName, ...args) {
5603
- var _a;
5604
- (_a = this.events[eventName]) === null || _a === void 0 ? void 0 : _a.notify(...args);
5643
+ if (this.events[eventName]) {
5644
+ this.events[eventName].notify(...args);
5645
+ }
5605
5646
  }
5606
5647
  }
5607
5648
  const variantProps = ["initial", ...variantPriorityOrder];
@@ -5617,8 +5658,7 @@
5617
5658
  return a.compareDocumentPosition(b) & 2 ? 1 : -1;
5618
5659
  }
5619
5660
  getBaseTargetFromProps(props, key) {
5620
- var _a;
5621
- return (_a = props.style) === null || _a === void 0 ? void 0 : _a[key];
5661
+ return props.style ? props.style[key] : undefined;
5622
5662
  }
5623
5663
  removeValueFromRenderState(key, { vars, style }) {
5624
5664
  delete vars[key];