framer-motion 7.0.3 → 7.1.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 (186) hide show
  1. package/dist/cjs/index.js +2090 -2304
  2. package/dist/es/animation/animate.mjs +4 -5
  3. package/dist/es/animation/animation-controls.mjs +22 -24
  4. package/dist/es/animation/use-animated-state.mjs +23 -25
  5. package/dist/es/animation/use-animation.mjs +2 -2
  6. package/dist/es/animation/utils/default-transitions.mjs +13 -14
  7. package/dist/es/animation/utils/easing.mjs +20 -21
  8. package/dist/es/animation/utils/is-animatable.mjs +1 -1
  9. package/dist/es/animation/utils/is-keyframes-target.mjs +1 -1
  10. package/dist/es/animation/utils/transitions.mjs +30 -31
  11. package/dist/es/components/AnimatePresence/PresenceChild.mjs +18 -31
  12. package/dist/es/components/AnimatePresence/index.mjs +33 -35
  13. package/dist/es/components/AnimatePresence/use-presence.mjs +5 -5
  14. package/dist/es/components/AnimateSharedLayout.mjs +4 -5
  15. package/dist/es/components/LayoutGroup/index.mjs +12 -16
  16. package/dist/es/components/LazyMotion/index.mjs +9 -10
  17. package/dist/es/components/MotionConfig/index.mjs +5 -5
  18. package/dist/es/components/Reorder/Group.mjs +16 -16
  19. package/dist/es/components/Reorder/Item.mjs +14 -18
  20. package/dist/es/components/Reorder/index.mjs +3 -3
  21. package/dist/es/components/Reorder/utils/check-reorder.mjs +6 -6
  22. package/dist/es/context/DeprecatedLayoutGroupContext.mjs +1 -1
  23. package/dist/es/context/LayoutGroupContext.mjs +1 -1
  24. package/dist/es/context/LazyContext.mjs +1 -1
  25. package/dist/es/context/MotionConfigContext.mjs +2 -2
  26. package/dist/es/context/MotionContext/create.mjs +2 -2
  27. package/dist/es/context/MotionContext/index.mjs +1 -1
  28. package/dist/es/context/MotionContext/utils.mjs +1 -1
  29. package/dist/es/context/PresenceContext.mjs +1 -1
  30. package/dist/es/context/ReorderContext.mjs +1 -1
  31. package/dist/es/context/SwitchLayoutGroupContext.mjs +1 -1
  32. package/dist/es/events/event-info.mjs +11 -17
  33. package/dist/es/events/use-dom-event.mjs +4 -5
  34. package/dist/es/events/use-pointer-event.mjs +2 -2
  35. package/dist/es/events/utils.mjs +3 -9
  36. package/dist/es/gestures/PanSession.mjs +42 -47
  37. package/dist/es/gestures/drag/VisualElementDragControls.mjs +147 -157
  38. package/dist/es/gestures/drag/use-drag-controls.mjs +10 -12
  39. package/dist/es/gestures/drag/use-drag.mjs +4 -4
  40. package/dist/es/gestures/drag/utils/constraints.mjs +12 -17
  41. package/dist/es/gestures/drag/utils/lock.mjs +17 -17
  42. package/dist/es/gestures/use-focus-gesture.mjs +3 -4
  43. package/dist/es/gestures/use-hover-gesture.mjs +2 -3
  44. package/dist/es/gestures/use-pan-gesture.mjs +9 -10
  45. package/dist/es/gestures/use-tap-gesture.mjs +5 -6
  46. package/dist/es/gestures/utils/event-type.mjs +1 -1
  47. package/dist/es/gestures/utils/is-node-or-child.mjs +1 -1
  48. package/dist/es/index.mjs +1 -0
  49. package/dist/es/motion/features/animations.mjs +9 -11
  50. package/dist/es/motion/features/definitions.mjs +5 -5
  51. package/dist/es/motion/features/drag.mjs +1 -1
  52. package/dist/es/motion/features/gestures.mjs +1 -1
  53. package/dist/es/motion/features/layout/MeasureLayout.mjs +32 -40
  54. package/dist/es/motion/features/layout/index.mjs +1 -1
  55. package/dist/es/motion/features/use-features.mjs +8 -9
  56. package/dist/es/motion/features/use-projection.mjs +10 -11
  57. package/dist/es/motion/features/viewport/observers.mjs +12 -12
  58. package/dist/es/motion/features/viewport/use-viewport.mjs +17 -20
  59. package/dist/es/motion/index.mjs +13 -16
  60. package/dist/es/motion/utils/VisualElementHandler.mjs +10 -16
  61. package/dist/es/motion/utils/is-forced-motion-value.mjs +1 -2
  62. package/dist/es/motion/utils/make-renderless-component.mjs +2 -2
  63. package/dist/es/motion/utils/use-motion-ref.mjs +1 -1
  64. package/dist/es/motion/utils/use-visual-element.mjs +13 -13
  65. package/dist/es/motion/utils/use-visual-state.mjs +26 -31
  66. package/dist/es/motion/utils/valid-prop.mjs +1 -1
  67. package/dist/es/projection/animation/mix-values.mjs +12 -16
  68. package/dist/es/projection/geometry/conversion.mjs +4 -6
  69. package/dist/es/projection/geometry/delta-apply.mjs +14 -20
  70. package/dist/es/projection/geometry/delta-calc.mjs +2 -5
  71. package/dist/es/projection/geometry/delta-remove.mjs +6 -13
  72. package/dist/es/projection/geometry/models.mjs +7 -7
  73. package/dist/es/projection/node/DocumentProjectionNode.mjs +5 -5
  74. package/dist/es/projection/node/HTMLProjectionNode.mjs +8 -10
  75. package/dist/es/projection/node/create-projection-node.mjs +283 -307
  76. package/dist/es/projection/node/group.mjs +6 -8
  77. package/dist/es/projection/node/id.mjs +2 -2
  78. package/dist/es/projection/node/state.mjs +1 -1
  79. package/dist/es/projection/shared/stack.mjs +26 -27
  80. package/dist/es/projection/styles/scale-border-radius.mjs +5 -5
  81. package/dist/es/projection/styles/scale-box-shadow.mjs +18 -19
  82. package/dist/es/projection/styles/scale-correction.mjs +1 -1
  83. package/dist/es/projection/styles/transform.mjs +12 -12
  84. package/dist/es/projection/use-reset-projection.mjs +2 -2
  85. package/dist/es/projection/utils/has-transform.mjs +1 -2
  86. package/dist/es/projection/utils/measure.mjs +2 -2
  87. package/dist/es/render/dom/create-visual-element.mjs +1 -1
  88. package/dist/es/render/dom/features-animation.mjs +1 -2
  89. package/dist/es/render/dom/features-max.mjs +1 -2
  90. package/dist/es/render/dom/motion-minimal.mjs +1 -1
  91. package/dist/es/render/dom/motion-proxy.mjs +3 -4
  92. package/dist/es/render/dom/motion.mjs +2 -5
  93. package/dist/es/render/dom/use-render.mjs +6 -9
  94. package/dist/es/render/dom/utils/camel-to-dash.mjs +3 -5
  95. package/dist/es/render/dom/utils/create-config.mjs +5 -5
  96. package/dist/es/render/dom/utils/css-variables-conversion.mjs +19 -20
  97. package/dist/es/render/dom/utils/filter-props.mjs +4 -6
  98. package/dist/es/render/dom/utils/parse-dom-variant.mjs +2 -2
  99. package/dist/es/render/dom/utils/unit-conversion.mjs +68 -99
  100. package/dist/es/render/dom/value-types/animatable-none.mjs +1 -1
  101. package/dist/es/render/dom/value-types/defaults.mjs +4 -5
  102. package/dist/es/render/dom/value-types/dimensions.mjs +2 -4
  103. package/dist/es/render/dom/value-types/find.mjs +2 -3
  104. package/dist/es/render/dom/value-types/get-as-type.mjs +1 -1
  105. package/dist/es/render/dom/value-types/number.mjs +2 -2
  106. package/dist/es/render/dom/value-types/test.mjs +1 -1
  107. package/dist/es/render/dom/value-types/type-auto.mjs +3 -3
  108. package/dist/es/render/dom/value-types/type-int.mjs +1 -2
  109. package/dist/es/render/html/config-motion.mjs +1 -1
  110. package/dist/es/render/html/use-props.mjs +11 -13
  111. package/dist/es/render/html/utils/build-styles.mjs +8 -8
  112. package/dist/es/render/html/utils/build-transform.mjs +11 -16
  113. package/dist/es/render/html/utils/create-render-state.mjs +2 -2
  114. package/dist/es/render/html/utils/render.mjs +2 -3
  115. package/dist/es/render/html/utils/scrape-motion-values.mjs +3 -3
  116. package/dist/es/render/html/utils/transform.mjs +6 -10
  117. package/dist/es/render/html/visual-element.mjs +22 -23
  118. package/dist/es/render/index.mjs +359 -364
  119. package/dist/es/render/svg/config-motion.mjs +2 -3
  120. package/dist/es/render/svg/lowercase-elements.mjs +1 -1
  121. package/dist/es/render/svg/use-props.mjs +5 -6
  122. package/dist/es/render/svg/utils/build-attrs.mjs +2 -2
  123. package/dist/es/render/svg/utils/camel-case-attrs.mjs +1 -1
  124. package/dist/es/render/svg/utils/create-render-state.mjs +1 -2
  125. package/dist/es/render/svg/utils/path.mjs +7 -10
  126. package/dist/es/render/svg/utils/render.mjs +1 -1
  127. package/dist/es/render/svg/utils/scrape-motion-values.mjs +3 -3
  128. package/dist/es/render/svg/utils/transform-origin.mjs +3 -3
  129. package/dist/es/render/svg/visual-element.mjs +6 -4
  130. package/dist/es/render/utils/animation-state.mjs +71 -87
  131. package/dist/es/render/utils/animation.mjs +48 -60
  132. package/dist/es/render/utils/compare-by-depth.mjs +1 -3
  133. package/dist/es/render/utils/flat-tree.mjs +9 -10
  134. package/dist/es/render/utils/lifecycles.mjs +12 -19
  135. package/dist/es/render/utils/motion-values.mjs +16 -8
  136. package/dist/es/render/utils/setters.mjs +19 -19
  137. package/dist/es/render/utils/variants.mjs +6 -8
  138. package/dist/es/utils/array.mjs +9 -10
  139. package/dist/es/utils/is-browser.mjs +1 -1
  140. package/dist/es/utils/is-numerical-string.mjs +1 -1
  141. package/dist/es/utils/is-zero-value-string.mjs +1 -1
  142. package/dist/es/utils/process.mjs +2 -2
  143. package/dist/es/utils/resolve-value.mjs +2 -2
  144. package/dist/es/utils/shallow-compare.mjs +2 -2
  145. package/dist/es/utils/subscription-manager.mjs +15 -17
  146. package/dist/es/utils/time-conversion.mjs +1 -1
  147. package/dist/es/utils/transform.mjs +10 -15
  148. package/dist/es/utils/use-animation-frame.mjs +5 -6
  149. package/dist/es/utils/use-constant.mjs +1 -1
  150. package/dist/es/utils/use-cycle.mjs +9 -10
  151. package/dist/es/utils/use-force-update.mjs +4 -5
  152. package/dist/es/utils/use-in-view.mjs +7 -9
  153. package/dist/es/utils/use-instant-transition-state.mjs +1 -1
  154. package/dist/es/utils/use-instant-transition.mjs +6 -9
  155. package/dist/es/utils/use-is-mounted.mjs +3 -3
  156. package/dist/es/utils/use-isomorphic-effect.mjs +1 -1
  157. package/dist/es/utils/use-reduced-motion.mjs +8 -11
  158. package/dist/es/utils/use-unmount-effect.mjs +1 -1
  159. package/dist/es/utils/warn-once.mjs +1 -1
  160. package/dist/es/value/index.mjs +53 -59
  161. package/dist/es/value/use-combine-values.mjs +3 -3
  162. package/dist/es/value/use-inverted-scale.mjs +9 -11
  163. package/dist/es/value/use-motion-template.mjs +5 -9
  164. package/dist/es/value/use-motion-value.mjs +4 -5
  165. package/dist/es/value/use-on-change.mjs +4 -4
  166. package/dist/es/value/use-scroll.mjs +9 -11
  167. package/dist/es/value/use-spring.mjs +8 -10
  168. package/dist/es/value/use-time.mjs +2 -2
  169. package/dist/es/value/use-transform.mjs +6 -10
  170. package/dist/es/value/use-velocity.mjs +3 -3
  171. package/dist/es/value/use-will-change/index.mjs +50 -0
  172. package/dist/es/value/use-will-change/is.mjs +7 -0
  173. package/dist/es/value/utils/is-motion-value.mjs +1 -1
  174. package/dist/es/value/utils/resolve-motion-value.mjs +1 -1
  175. package/dist/framer-motion.dev.js +2134 -2414
  176. package/dist/framer-motion.js +1 -1
  177. package/dist/index.d.ts +9 -2
  178. package/dist/projection.dev.js +1154 -1300
  179. package/dist/size-rollup-dom-animation.js +1 -1
  180. package/dist/size-rollup-dom-max.js +1 -1
  181. package/dist/size-rollup-m.js +1 -1
  182. package/dist/size-webpack-dom-animation.js +1 -1
  183. package/dist/size-webpack-dom-max.js +1 -1
  184. package/dist/size-webpack-m.js +1 -1
  185. package/dist/three-entry.d.ts +0 -1
  186. package/package.json +12 -12
@@ -1,4 +1,3 @@
1
- import { __read } from 'tslib';
2
1
  import { mix, progress, clamp } from 'popmotion';
3
2
  import { calcLength } from '../../../projection/geometry/delta-calc.mjs';
4
3
 
@@ -7,8 +6,7 @@ import { calcLength } from '../../../projection/geometry/delta-calc.mjs';
7
6
  * axis, and an elastic factor that determines how much to constrain the point
8
7
  * by if it does lie outside the defined parameters.
9
8
  */
10
- function applyConstraints(point, _a, elastic) {
11
- var min = _a.min, max = _a.max;
9
+ function applyConstraints(point, { min, max }, elastic) {
12
10
  if (min !== undefined && point < min) {
13
11
  // If we have a min point defined, and this is outside of that, constrain
14
12
  point = elastic ? mix(min, point, elastic.min) : Math.max(point, min);
@@ -36,8 +34,7 @@ function calcRelativeAxisConstraints(axis, min, max) {
36
34
  * Calculate constraints in terms of the viewport when
37
35
  * defined relatively to the measured bounding box.
38
36
  */
39
- function calcRelativeConstraints(layoutBox, _a) {
40
- var top = _a.top, left = _a.left, bottom = _a.bottom, right = _a.right;
37
+ function calcRelativeConstraints(layoutBox, { top, left, bottom, right }) {
41
38
  return {
42
39
  x: calcRelativeAxisConstraints(layoutBox.x, left, right),
43
40
  y: calcRelativeAxisConstraints(layoutBox.y, top, bottom),
@@ -47,16 +44,15 @@ function calcRelativeConstraints(layoutBox, _a) {
47
44
  * Calculate viewport constraints when defined as another viewport-relative axis
48
45
  */
49
46
  function calcViewportAxisConstraints(layoutAxis, constraintsAxis) {
50
- var _a;
51
- var min = constraintsAxis.min - layoutAxis.min;
52
- var max = constraintsAxis.max - layoutAxis.max;
47
+ let min = constraintsAxis.min - layoutAxis.min;
48
+ let max = constraintsAxis.max - layoutAxis.max;
53
49
  // If the constraints axis is actually smaller than the layout axis then we can
54
50
  // flip the constraints
55
51
  if (constraintsAxis.max - constraintsAxis.min <
56
52
  layoutAxis.max - layoutAxis.min) {
57
- _a = __read([max, min], 2), min = _a[0], max = _a[1];
53
+ [min, max] = [max, min];
58
54
  }
59
- return { min: min, max: max };
55
+ return { min, max };
60
56
  }
61
57
  /**
62
58
  * Calculate viewport constraints when defined as another viewport-relative box
@@ -72,9 +68,9 @@ function calcViewportConstraints(layoutBox, constraintsBox) {
72
68
  * in an asthetically pleasing scale/transform needed to project from source to target.
73
69
  */
74
70
  function calcOrigin(source, target) {
75
- var origin = 0.5;
76
- var sourceLength = calcLength(source);
77
- var targetLength = calcLength(target);
71
+ let origin = 0.5;
72
+ const sourceLength = calcLength(source);
73
+ const targetLength = calcLength(target);
78
74
  if (targetLength > sourceLength) {
79
75
  origin = progress(target.min, target.max - sourceLength, source.min);
80
76
  }
@@ -87,7 +83,7 @@ function calcOrigin(source, target) {
87
83
  * Rebase the calculated viewport constraints relative to the layout.min point.
88
84
  */
89
85
  function rebaseAxisConstraints(layout, constraints) {
90
- var relativeConstraints = {};
86
+ const relativeConstraints = {};
91
87
  if (constraints.min !== undefined) {
92
88
  relativeConstraints.min = constraints.min - layout.min;
93
89
  }
@@ -96,12 +92,11 @@ function rebaseAxisConstraints(layout, constraints) {
96
92
  }
97
93
  return relativeConstraints;
98
94
  }
99
- var defaultElastic = 0.35;
95
+ const defaultElastic = 0.35;
100
96
  /**
101
97
  * Accepts a dragElastic prop and returns resolved elastic values for each axis.
102
98
  */
103
- function resolveDragElastic(dragElastic) {
104
- if (dragElastic === void 0) { dragElastic = defaultElastic; }
99
+ function resolveDragElastic(dragElastic = defaultElastic) {
105
100
  if (dragElastic === false) {
106
101
  dragElastic = 0;
107
102
  }
@@ -1,7 +1,7 @@
1
1
  function createLock(name) {
2
- var lock = null;
3
- return function () {
4
- var openLock = function () {
2
+ let lock = null;
3
+ return () => {
4
+ const openLock = () => {
5
5
  lock = null;
6
6
  };
7
7
  if (lock === null) {
@@ -11,10 +11,10 @@ function createLock(name) {
11
11
  return false;
12
12
  };
13
13
  }
14
- var globalHorizontalLock = createLock("dragHorizontal");
15
- var globalVerticalLock = createLock("dragVertical");
14
+ const globalHorizontalLock = createLock("dragHorizontal");
15
+ const globalVerticalLock = createLock("dragVertical");
16
16
  function getGlobalLock(drag) {
17
- var lock = false;
17
+ let lock = false;
18
18
  if (drag === "y") {
19
19
  lock = globalVerticalLock();
20
20
  }
@@ -22,20 +22,20 @@ function getGlobalLock(drag) {
22
22
  lock = globalHorizontalLock();
23
23
  }
24
24
  else {
25
- var openHorizontal_1 = globalHorizontalLock();
26
- var openVertical_1 = globalVerticalLock();
27
- if (openHorizontal_1 && openVertical_1) {
28
- lock = function () {
29
- openHorizontal_1();
30
- openVertical_1();
25
+ const openHorizontal = globalHorizontalLock();
26
+ const openVertical = globalVerticalLock();
27
+ if (openHorizontal && openVertical) {
28
+ lock = () => {
29
+ openHorizontal();
30
+ openVertical();
31
31
  };
32
32
  }
33
33
  else {
34
34
  // Release the locks because we don't use them
35
- if (openHorizontal_1)
36
- openHorizontal_1();
37
- if (openVertical_1)
38
- openVertical_1();
35
+ if (openHorizontal)
36
+ openHorizontal();
37
+ if (openVertical)
38
+ openVertical();
39
39
  }
40
40
  }
41
41
  return lock;
@@ -43,7 +43,7 @@ function getGlobalLock(drag) {
43
43
  function isDragActive() {
44
44
  // Check the gesture lock - if we get it, it means no drag gesture is active
45
45
  // and we can safely fire the tap gesture.
46
- var openGestureLock = getGlobalLock(true);
46
+ const openGestureLock = getGlobalLock(true);
47
47
  if (!openGestureLock)
48
48
  return true;
49
49
  openGestureLock();
@@ -7,13 +7,12 @@ import { useDomEvent } from '../events/use-dom-event.mjs';
7
7
  * @param ref
8
8
  * @internal
9
9
  */
10
- function useFocusGesture(_a) {
11
- var whileFocus = _a.whileFocus, visualElement = _a.visualElement;
12
- var onFocus = function () {
10
+ function useFocusGesture({ whileFocus, visualElement }) {
11
+ const onFocus = () => {
13
12
  var _a;
14
13
  (_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.Focus, true);
15
14
  };
16
- var onBlur = function () {
15
+ const onBlur = () => {
17
16
  var _a;
18
17
  (_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.Focus, false);
19
18
  };
@@ -4,7 +4,7 @@ import { usePointerEvent } from '../events/use-pointer-event.mjs';
4
4
  import { isDragActive } from './drag/utils/lock.mjs';
5
5
 
6
6
  function createHoverEvent(visualElement, isActive, callback) {
7
- return function (event, info) {
7
+ return (event, info) => {
8
8
  var _a;
9
9
  if (!isMouseEvent(event) || isDragActive())
10
10
  return;
@@ -15,8 +15,7 @@ function createHoverEvent(visualElement, isActive, callback) {
15
15
  callback === null || callback === void 0 ? void 0 : callback(event, info);
16
16
  };
17
17
  }
18
- function useHoverGesture(_a) {
19
- var onHoverStart = _a.onHoverStart, onHoverEnd = _a.onHoverEnd, whileHover = _a.whileHover, visualElement = _a.visualElement;
18
+ function useHoverGesture({ onHoverStart, onHoverEnd, whileHover, visualElement, }) {
20
19
  usePointerEvent(visualElement, "pointerenter", onHoverStart || whileHover
21
20
  ? createHoverEvent(visualElement, true, onHoverStart)
22
21
  : undefined, { passive: !onHoverStart });
@@ -16,32 +16,31 @@ import { PanSession } from './PanSession.mjs';
16
16
  *
17
17
  * @internal
18
18
  */
19
- function usePanGesture(_a) {
20
- var onPan = _a.onPan, onPanStart = _a.onPanStart, onPanEnd = _a.onPanEnd, onPanSessionStart = _a.onPanSessionStart, visualElement = _a.visualElement;
21
- var hasPanEvents = onPan || onPanStart || onPanEnd || onPanSessionStart;
22
- var panSession = useRef(null);
23
- var transformPagePoint = useContext(MotionConfigContext).transformPagePoint;
24
- var handlers = {
19
+ function usePanGesture({ onPan, onPanStart, onPanEnd, onPanSessionStart, visualElement, }) {
20
+ const hasPanEvents = onPan || onPanStart || onPanEnd || onPanSessionStart;
21
+ const panSession = useRef(null);
22
+ const { transformPagePoint } = useContext(MotionConfigContext);
23
+ const handlers = {
25
24
  onSessionStart: onPanSessionStart,
26
25
  onStart: onPanStart,
27
26
  onMove: onPan,
28
- onEnd: function (event, info) {
27
+ onEnd: (event, info) => {
29
28
  panSession.current = null;
30
29
  onPanEnd && onPanEnd(event, info);
31
30
  },
32
31
  };
33
- useEffect(function () {
32
+ useEffect(() => {
34
33
  if (panSession.current !== null) {
35
34
  panSession.current.updateHandlers(handlers);
36
35
  }
37
36
  });
38
37
  function onPointerDown(event) {
39
38
  panSession.current = new PanSession(event, handlers, {
40
- transformPagePoint: transformPagePoint,
39
+ transformPagePoint,
41
40
  });
42
41
  }
43
42
  usePointerEvent(visualElement, "pointerdown", hasPanEvents && onPointerDown);
44
- useUnmountEffect(function () { return panSession.current && panSession.current.end(); });
43
+ useUnmountEffect(() => panSession.current && panSession.current.end());
45
44
  }
46
45
 
47
46
  export { usePanGesture };
@@ -10,15 +10,14 @@ import { isDragActive } from './drag/utils/lock.mjs';
10
10
  * @param handlers -
11
11
  * @internal
12
12
  */
13
- function useTapGesture(_a) {
14
- var onTap = _a.onTap, onTapStart = _a.onTapStart, onTapCancel = _a.onTapCancel, whileTap = _a.whileTap, visualElement = _a.visualElement;
15
- var hasPressListeners = onTap || onTapStart || onTapCancel || whileTap;
16
- var isPressing = useRef(false);
17
- var cancelPointerEndListeners = useRef(null);
13
+ function useTapGesture({ onTap, onTapStart, onTapCancel, whileTap, visualElement, }) {
14
+ const hasPressListeners = onTap || onTapStart || onTapCancel || whileTap;
15
+ const isPressing = useRef(false);
16
+ const cancelPointerEndListeners = useRef(null);
18
17
  /**
19
18
  * Only set listener to passive if there are no external listeners.
20
19
  */
21
- var eventOptions = {
20
+ const eventOptions = {
22
21
  passive: !(onTapStart || onTap || onTapCancel || onPointerDown),
23
22
  };
24
23
  function removePointerEndListener() {
@@ -6,7 +6,7 @@ function isMouseEvent(event) {
6
6
  return event instanceof MouseEvent;
7
7
  }
8
8
  function isTouchEvent(event) {
9
- var hasTouches = !!event.touches;
9
+ const hasTouches = !!event.touches;
10
10
  return hasTouches;
11
11
  }
12
12
 
@@ -5,7 +5,7 @@
5
5
  * @param parent - Element to find
6
6
  * @param child - Element to test against parent
7
7
  */
8
- var isNodeOrChild = function (parent, child) {
8
+ const isNodeOrChild = (parent, child) => {
9
9
  if (!child) {
10
10
  return false;
11
11
  }
package/dist/es/index.mjs CHANGED
@@ -19,6 +19,7 @@ export { useScroll } from './value/use-scroll.mjs';
19
19
  export { useElementScroll } from './value/scroll/use-element-scroll.mjs';
20
20
  export { useViewportScroll } from './value/scroll/use-viewport-scroll.mjs';
21
21
  export { useTime } from './value/use-time.mjs';
22
+ export { useWillChange } from './value/use-will-change/index.mjs';
22
23
  export { useReducedMotion, useReducedMotionConfig } from './utils/use-reduced-motion.mjs';
23
24
  export { animationControls } from './animation/animation-controls.mjs';
24
25
  export { useAnimation, useAnimationControls } from './animation/use-animation.mjs';
@@ -1,4 +1,3 @@
1
- import { __read } from 'tslib';
2
1
  import { useEffect, useContext } from 'react';
3
2
  import { isAnimationControls } from '../../animation/utils/is-animation-controls.mjs';
4
3
  import { usePresence } from '../../components/AnimatePresence/use-presence.mjs';
@@ -7,9 +6,8 @@ import { createAnimationState } from '../../render/utils/animation-state.mjs';
7
6
  import { AnimationType } from '../../render/utils/types.mjs';
8
7
  import { makeRenderlessComponent } from '../utils/make-renderless-component.mjs';
9
8
 
10
- var animations = {
11
- animation: makeRenderlessComponent(function (_a) {
12
- var visualElement = _a.visualElement, animate = _a.animate;
9
+ const animations = {
10
+ animation: makeRenderlessComponent(({ visualElement, animate }) => {
13
11
  /**
14
12
  * We dynamically generate the AnimationState manager as it contains a reference
15
13
  * to the underlying animation library. We only want to load that if we load this,
@@ -20,17 +18,17 @@ var animations = {
20
18
  * Subscribe any provided AnimationControls to the component's VisualElement
21
19
  */
22
20
  if (isAnimationControls(animate)) {
23
- useEffect(function () { return animate.subscribe(visualElement); }, [animate]);
21
+ useEffect(() => animate.subscribe(visualElement), [animate]);
24
22
  }
25
23
  }),
26
- exit: makeRenderlessComponent(function (props) {
27
- var custom = props.custom, visualElement = props.visualElement;
28
- var _a = __read(usePresence(), 2), isPresent = _a[0], safeToRemove = _a[1];
29
- var presenceContext = useContext(PresenceContext);
30
- useEffect(function () {
24
+ exit: makeRenderlessComponent((props) => {
25
+ const { custom, visualElement } = props;
26
+ const [isPresent, safeToRemove] = usePresence();
27
+ const presenceContext = useContext(PresenceContext);
28
+ useEffect(() => {
31
29
  var _a, _b;
32
30
  visualElement.isPresent = isPresent;
33
- var animation = (_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.Exit, !isPresent, { custom: (_b = presenceContext === null || presenceContext === void 0 ? void 0 : presenceContext.custom) !== null && _b !== void 0 ? _b : custom });
31
+ const animation = (_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.Exit, !isPresent, { custom: (_b = presenceContext === null || presenceContext === void 0 ? void 0 : presenceContext.custom) !== null && _b !== void 0 ? _b : custom });
34
32
  !isPresent && (animation === null || animation === void 0 ? void 0 : animation.then(safeToRemove));
35
33
  }, [isPresent]);
36
34
  }),
@@ -1,7 +1,7 @@
1
- var createDefinition = function (propNames) { return ({
2
- isEnabled: function (props) { return propNames.some(function (name) { return !!props[name]; }); },
3
- }); };
4
- var featureDefinitions = {
1
+ const createDefinition = (propNames) => ({
2
+ isEnabled: (props) => propNames.some((name) => !!props[name]),
3
+ });
4
+ const featureDefinitions = {
5
5
  measureLayout: createDefinition(["layout", "layoutId", "drag"]),
6
6
  animation: createDefinition([
7
7
  "animate",
@@ -31,7 +31,7 @@ var featureDefinitions = {
31
31
  ]),
32
32
  };
33
33
  function loadFeatures(features) {
34
- for (var key in features) {
34
+ for (const key in features) {
35
35
  if (features[key] === null)
36
36
  continue;
37
37
  if (key === "projectionNodeConstructor") {
@@ -2,7 +2,7 @@ import { useDrag } from '../../gestures/drag/use-drag.mjs';
2
2
  import { usePanGesture } from '../../gestures/use-pan-gesture.mjs';
3
3
  import { makeRenderlessComponent } from '../utils/make-renderless-component.mjs';
4
4
 
5
- var drag = {
5
+ const drag = {
6
6
  pan: makeRenderlessComponent(usePanGesture),
7
7
  drag: makeRenderlessComponent(useDrag),
8
8
  };
@@ -4,7 +4,7 @@ import { useTapGesture } from '../../gestures/use-tap-gesture.mjs';
4
4
  import { useViewport } from './viewport/use-viewport.mjs';
5
5
  import { makeRenderlessComponent } from '../utils/make-renderless-component.mjs';
6
6
 
7
- var gestureAnimations = {
7
+ const gestureAnimations = {
8
8
  inView: makeRenderlessComponent(useViewport),
9
9
  tap: makeRenderlessComponent(useTapGesture),
10
10
  focus: makeRenderlessComponent(useFocusGesture),
@@ -1,4 +1,3 @@
1
- import { __extends, __assign, __read } from 'tslib';
2
1
  import sync from 'framesync';
3
2
  import React__default, { useContext } from 'react';
4
3
  import { usePresence } from '../../../components/AnimatePresence/use-presence.mjs';
@@ -9,20 +8,15 @@ import { correctBorderRadius } from '../../../projection/styles/scale-border-rad
9
8
  import { correctBoxShadow } from '../../../projection/styles/scale-box-shadow.mjs';
10
9
  import { addScaleCorrector } from '../../../projection/styles/scale-correction.mjs';
11
10
 
12
- var MeasureLayoutWithContext = /** @class */ (function (_super) {
13
- __extends(MeasureLayoutWithContext, _super);
14
- function MeasureLayoutWithContext() {
15
- return _super !== null && _super.apply(this, arguments) || this;
16
- }
11
+ class MeasureLayoutWithContext extends React__default.Component {
17
12
  /**
18
13
  * This only mounts projection nodes for components that
19
14
  * need measuring, we might want to do it for all components
20
15
  * in order to incorporate transforms
21
16
  */
22
- MeasureLayoutWithContext.prototype.componentDidMount = function () {
23
- var _this = this;
24
- var _a = this.props, visualElement = _a.visualElement, layoutGroup = _a.layoutGroup, switchLayoutGroup = _a.switchLayoutGroup, layoutId = _a.layoutId;
25
- var projection = visualElement.projection;
17
+ componentDidMount() {
18
+ const { visualElement, layoutGroup, switchLayoutGroup, layoutId } = this.props;
19
+ const { projection } = visualElement;
26
20
  addScaleCorrector(defaultScaleCorrectors);
27
21
  if (projection) {
28
22
  if (layoutGroup === null || layoutGroup === void 0 ? void 0 : layoutGroup.group)
@@ -31,17 +25,16 @@ var MeasureLayoutWithContext = /** @class */ (function (_super) {
31
25
  switchLayoutGroup.register(projection);
32
26
  }
33
27
  projection.root.didUpdate();
34
- projection.addEventListener("animationComplete", function () {
35
- _this.safeToRemove();
28
+ projection.addEventListener("animationComplete", () => {
29
+ this.safeToRemove();
36
30
  });
37
- projection.setOptions(__assign(__assign({}, projection.options), { onExitComplete: function () { return _this.safeToRemove(); } }));
31
+ projection.setOptions(Object.assign(Object.assign({}, projection.options), { onExitComplete: () => this.safeToRemove() }));
38
32
  }
39
33
  globalProjectionState.hasEverUpdated = true;
40
- };
41
- MeasureLayoutWithContext.prototype.getSnapshotBeforeUpdate = function (prevProps) {
42
- var _this = this;
43
- var _a = this.props, layoutDependency = _a.layoutDependency, visualElement = _a.visualElement, drag = _a.drag, isPresent = _a.isPresent;
44
- var projection = visualElement.projection;
34
+ }
35
+ getSnapshotBeforeUpdate(prevProps) {
36
+ const { layoutDependency, visualElement, drag, isPresent } = this.props;
37
+ const projection = visualElement.projection;
45
38
  if (!projection)
46
39
  return null;
47
40
  /**
@@ -70,28 +63,28 @@ var MeasureLayoutWithContext = /** @class */ (function (_super) {
70
63
  * it's in charge of the exit animation and therefore should
71
64
  * be in charge of the safe to remove. Otherwise we call it here.
72
65
  */
73
- sync.postRender(function () {
66
+ sync.postRender(() => {
74
67
  var _a;
75
68
  if (!((_a = projection.getStack()) === null || _a === void 0 ? void 0 : _a.members.length)) {
76
- _this.safeToRemove();
69
+ this.safeToRemove();
77
70
  }
78
71
  });
79
72
  }
80
73
  }
81
74
  return null;
82
- };
83
- MeasureLayoutWithContext.prototype.componentDidUpdate = function () {
84
- var projection = this.props.visualElement.projection;
75
+ }
76
+ componentDidUpdate() {
77
+ const { projection } = this.props.visualElement;
85
78
  if (projection) {
86
79
  projection.root.didUpdate();
87
80
  if (!projection.currentAnimation && projection.isLead()) {
88
81
  this.safeToRemove();
89
82
  }
90
83
  }
91
- };
92
- MeasureLayoutWithContext.prototype.componentWillUnmount = function () {
93
- var _a = this.props, visualElement = _a.visualElement, layoutGroup = _a.layoutGroup, promoteContext = _a.switchLayoutGroup;
94
- var projection = visualElement.projection;
84
+ }
85
+ componentWillUnmount() {
86
+ const { visualElement, layoutGroup, switchLayoutGroup: promoteContext, } = this.props;
87
+ const { projection } = visualElement;
95
88
  if (projection) {
96
89
  projection.scheduleCheckAfterUnmount();
97
90
  if (layoutGroup === null || layoutGroup === void 0 ? void 0 : layoutGroup.group)
@@ -99,23 +92,22 @@ var MeasureLayoutWithContext = /** @class */ (function (_super) {
99
92
  if (promoteContext === null || promoteContext === void 0 ? void 0 : promoteContext.deregister)
100
93
  promoteContext.deregister(projection);
101
94
  }
102
- };
103
- MeasureLayoutWithContext.prototype.safeToRemove = function () {
104
- var safeToRemove = this.props.safeToRemove;
95
+ }
96
+ safeToRemove() {
97
+ const { safeToRemove } = this.props;
105
98
  safeToRemove === null || safeToRemove === void 0 ? void 0 : safeToRemove();
106
- };
107
- MeasureLayoutWithContext.prototype.render = function () {
99
+ }
100
+ render() {
108
101
  return null;
109
- };
110
- return MeasureLayoutWithContext;
111
- }(React__default.Component));
102
+ }
103
+ }
112
104
  function MeasureLayout(props) {
113
- var _a = __read(usePresence(), 2), isPresent = _a[0], safeToRemove = _a[1];
114
- var layoutGroup = useContext(LayoutGroupContext);
115
- return (React__default.createElement(MeasureLayoutWithContext, __assign({}, props, { layoutGroup: layoutGroup, switchLayoutGroup: useContext(SwitchLayoutGroupContext), isPresent: isPresent, safeToRemove: safeToRemove })));
105
+ const [isPresent, safeToRemove] = usePresence();
106
+ const layoutGroup = useContext(LayoutGroupContext);
107
+ return (React__default.createElement(MeasureLayoutWithContext, Object.assign({}, props, { layoutGroup: layoutGroup, switchLayoutGroup: useContext(SwitchLayoutGroupContext), isPresent: isPresent, safeToRemove: safeToRemove })));
116
108
  }
117
- var defaultScaleCorrectors = {
118
- borderRadius: __assign(__assign({}, correctBorderRadius), { applyTo: [
109
+ const defaultScaleCorrectors = {
110
+ borderRadius: Object.assign(Object.assign({}, correctBorderRadius), { applyTo: [
119
111
  "borderTopLeftRadius",
120
112
  "borderTopRightRadius",
121
113
  "borderBottomLeftRadius",
@@ -1,6 +1,6 @@
1
1
  import { MeasureLayout } from './MeasureLayout.mjs';
2
2
 
3
- var layoutFeatures = {
3
+ const layoutFeatures = {
4
4
  measureLayout: MeasureLayout,
5
5
  };
6
6
 
@@ -1,4 +1,3 @@
1
- import { __assign } from 'tslib';
2
1
  import * as React from 'react';
3
2
  import { useContext } from 'react';
4
3
  import { env } from '../../utils/process.mjs';
@@ -6,14 +5,14 @@ import { featureDefinitions } from './definitions.mjs';
6
5
  import { invariant } from 'hey-listen';
7
6
  import { LazyContext } from '../../context/LazyContext.mjs';
8
7
 
9
- var featureNames = Object.keys(featureDefinitions);
10
- var numFeatures = featureNames.length;
8
+ const featureNames = Object.keys(featureDefinitions);
9
+ const numFeatures = featureNames.length;
11
10
  /**
12
11
  * Load features via renderless components based on the provided MotionProps.
13
12
  */
14
13
  function useFeatures(props, visualElement, preloadedFeatures) {
15
- var features = [];
16
- var lazyContext = useContext(LazyContext);
14
+ const features = [];
15
+ const lazyContext = useContext(LazyContext);
17
16
  if (!visualElement)
18
17
  return null;
19
18
  /**
@@ -23,16 +22,16 @@ function useFeatures(props, visualElement, preloadedFeatures) {
23
22
  if (env !== "production" && preloadedFeatures && lazyContext.strict) {
24
23
  invariant(false, "You have rendered a `motion` component within a `LazyMotion` component. This will break tree shaking. Import and render a `m` component instead.");
25
24
  }
26
- for (var i = 0; i < numFeatures; i++) {
27
- var name_1 = featureNames[i];
28
- var _a = featureDefinitions[name_1], isEnabled = _a.isEnabled, Component = _a.Component;
25
+ for (let i = 0; i < numFeatures; i++) {
26
+ const name = featureNames[i];
27
+ const { isEnabled, Component } = featureDefinitions[name];
29
28
  /**
30
29
  * It might be possible in the future to use this moment to
31
30
  * dynamically request functionality. In initial tests this
32
31
  * was producing a lot of duplication amongst bundles.
33
32
  */
34
33
  if (isEnabled(props) && Component) {
35
- features.push(React.createElement(Component, __assign({ key: name_1 }, props, { visualElement: visualElement })));
34
+ features.push(React.createElement(Component, Object.assign({ key: name }, props, { visualElement: visualElement })));
36
35
  }
37
36
  }
38
37
  return features;
@@ -2,22 +2,21 @@ import { isRefObject } from '../../utils/is-ref-object.mjs';
2
2
  import { useContext } from 'react';
3
3
  import { SwitchLayoutGroupContext } from '../../context/SwitchLayoutGroupContext.mjs';
4
4
 
5
- function useProjection(projectionId, _a, visualElement, ProjectionNodeConstructor) {
6
- var _b;
7
- var layoutId = _a.layoutId, layout = _a.layout, drag = _a.drag, dragConstraints = _a.dragConstraints, layoutScroll = _a.layoutScroll;
8
- var initialPromotionConfig = useContext(SwitchLayoutGroupContext);
5
+ function useProjection(projectionId, { layoutId, layout, drag, dragConstraints, layoutScroll }, visualElement, ProjectionNodeConstructor) {
6
+ var _a;
7
+ const initialPromotionConfig = useContext(SwitchLayoutGroupContext);
9
8
  if (!ProjectionNodeConstructor ||
10
9
  !visualElement ||
11
10
  (visualElement === null || visualElement === void 0 ? void 0 : visualElement.projection)) {
12
11
  return;
13
12
  }
14
- visualElement.projection = new ProjectionNodeConstructor(projectionId, visualElement.getLatestValues(), (_b = visualElement.parent) === null || _b === void 0 ? void 0 : _b.projection);
13
+ visualElement.projection = new ProjectionNodeConstructor(projectionId, visualElement.getLatestValues(), (_a = visualElement.parent) === null || _a === void 0 ? void 0 : _a.projection);
15
14
  visualElement.projection.setOptions({
16
- layoutId: layoutId,
17
- layout: layout,
15
+ layoutId,
16
+ layout,
18
17
  alwaysMeasureLayout: Boolean(drag) || (dragConstraints && isRefObject(dragConstraints)),
19
- visualElement: visualElement,
20
- scheduleRender: function () { return visualElement.scheduleRender(); },
18
+ visualElement,
19
+ scheduleRender: () => visualElement.scheduleRender(),
21
20
  /**
22
21
  * TODO: Update options in an effect. This could be tricky as it'll be too late
23
22
  * to update by the time layout animations run.
@@ -26,8 +25,8 @@ function useProjection(projectionId, _a, visualElement, ProjectionNodeConstructo
26
25
  *
27
26
  */
28
27
  animationType: typeof layout === "string" ? layout : "both",
29
- initialPromotionConfig: initialPromotionConfig,
30
- layoutScroll: layoutScroll,
28
+ initialPromotionConfig,
29
+ layoutScroll,
31
30
  });
32
31
  }
33
32