motion 12.0.0-alpha.2 → 12.0.0

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 (157) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +7 -24
  3. package/dist/cjs/index.js +2792 -2446
  4. package/dist/cjs/mini.js +629 -193
  5. package/dist/cjs/react-client.js +3624 -3434
  6. package/dist/cjs/react-m.js +397 -351
  7. package/dist/cjs/react-mini.js +225 -191
  8. package/dist/es/framer-motion/dist/es/animation/animate/index.mjs +3 -2
  9. package/dist/es/framer-motion/dist/es/animation/animate/resolve-subjects.mjs +2 -1
  10. package/dist/es/framer-motion/dist/es/animation/animate/single-value.mjs +1 -1
  11. package/dist/es/framer-motion/dist/es/animation/animate/subject.mjs +1 -1
  12. package/dist/es/framer-motion/dist/es/animation/animators/AcceleratedAnimation.mjs +16 -12
  13. package/dist/es/framer-motion/dist/es/animation/animators/BaseAnimation.mjs +3 -2
  14. package/dist/es/framer-motion/dist/es/animation/animators/MainThreadAnimation.mjs +10 -10
  15. package/dist/es/framer-motion/dist/es/animation/animators/utils/can-animate.mjs +2 -2
  16. package/dist/es/framer-motion/dist/es/animation/animators/waapi/NativeAnimation.mjs +30 -89
  17. package/dist/es/framer-motion/dist/es/animation/animators/waapi/animate-elements.mjs +4 -4
  18. package/dist/es/framer-motion/dist/es/animation/animators/waapi/animate-sequence.mjs +14 -0
  19. package/dist/es/framer-motion/dist/es/animation/animators/waapi/animate-style.mjs +2 -1
  20. package/dist/es/framer-motion/dist/es/animation/animators/waapi/index.mjs +2 -1
  21. package/dist/es/framer-motion/dist/es/animation/animators/waapi/utils/supports-partial-keyframes.mjs +2 -1
  22. package/dist/es/framer-motion/dist/es/animation/animators/waapi/utils/supports-waapi.mjs +2 -1
  23. package/dist/es/framer-motion/dist/es/animation/generators/spring/defaults.mjs +27 -0
  24. package/dist/es/framer-motion/dist/es/animation/generators/spring/find.mjs +10 -13
  25. package/dist/es/framer-motion/dist/es/animation/generators/spring/index.mjs +57 -18
  26. package/dist/es/framer-motion/dist/es/animation/hooks/animation-controls.mjs +1 -1
  27. package/dist/es/framer-motion/dist/es/animation/interfaces/motion-value.mjs +7 -6
  28. package/dist/es/framer-motion/dist/es/animation/interfaces/visual-element-target.mjs +6 -5
  29. package/dist/es/framer-motion/dist/es/animation/optimized-appear/start.mjs +2 -1
  30. package/dist/es/framer-motion/dist/es/animation/optimized-appear/store-id.mjs +1 -1
  31. package/dist/es/framer-motion/dist/es/animation/sequence/create.mjs +32 -6
  32. package/dist/es/framer-motion/dist/es/animation/sequence/utils/calc-repeat-duration.mjs +5 -0
  33. package/dist/es/framer-motion/dist/es/animation/sequence/utils/normalize-times.mjs +13 -0
  34. package/dist/es/framer-motion/dist/es/animation/utils/default-transitions.mjs +1 -1
  35. package/dist/es/framer-motion/dist/es/components/AnimatePresence/index.mjs +10 -7
  36. package/dist/es/framer-motion/dist/es/components/AnimatePresence/use-presence.mjs +6 -3
  37. package/dist/es/framer-motion/dist/es/components/AnimateSharedLayout.mjs +1 -1
  38. package/dist/es/framer-motion/dist/es/components/Reorder/Group.mjs +1 -1
  39. package/dist/es/framer-motion/dist/es/components/Reorder/Item.mjs +1 -1
  40. package/dist/es/framer-motion/dist/es/easing/cubic-bezier.mjs +2 -1
  41. package/dist/es/framer-motion/dist/es/easing/utils/map.mjs +6 -6
  42. package/dist/es/framer-motion/dist/es/events/event-info.mjs +5 -4
  43. package/dist/es/framer-motion/dist/es/frameloop/frame.mjs +2 -1
  44. package/dist/es/framer-motion/dist/es/frameloop/render-step.mjs +3 -2
  45. package/dist/es/framer-motion/dist/es/gestures/drag/VisualElementDragControls.mjs +12 -15
  46. package/dist/es/framer-motion/dist/es/gestures/drag/index.mjs +2 -1
  47. package/dist/es/framer-motion/dist/es/gestures/drag/utils/constraints.mjs +2 -1
  48. package/dist/es/framer-motion/dist/es/gestures/hover.mjs +20 -22
  49. package/dist/es/framer-motion/dist/es/gestures/pan/PanSession.mjs +6 -5
  50. package/dist/es/framer-motion/dist/es/gestures/pan/index.mjs +2 -1
  51. package/dist/es/framer-motion/dist/es/gestures/press.mjs +20 -119
  52. package/dist/es/framer-motion/dist/es/motion/index.mjs +11 -7
  53. package/dist/es/framer-motion/dist/es/motion/utils/is-forced-motion-value.mjs +1 -1
  54. package/dist/es/framer-motion/dist/es/motion/utils/use-motion-ref.mjs +3 -1
  55. package/dist/es/framer-motion/dist/es/motion/utils/use-visual-element.mjs +1 -1
  56. package/dist/es/framer-motion/dist/es/motion/utils/use-visual-state.mjs +11 -5
  57. package/dist/es/framer-motion/dist/es/projection/animation/mix-values.mjs +3 -2
  58. package/dist/es/framer-motion/dist/es/projection/node/create-projection-node.mjs +15 -14
  59. package/dist/es/framer-motion/dist/es/render/VisualElement.mjs +15 -13
  60. package/dist/es/framer-motion/dist/es/render/dom/DOMKeyframesResolver.mjs +4 -3
  61. package/dist/es/framer-motion/dist/es/render/dom/DOMVisualElement.mjs +15 -0
  62. package/dist/es/framer-motion/dist/es/render/dom/resize/handle-element.mjs +2 -1
  63. package/dist/es/framer-motion/dist/es/render/dom/scroll/index.mjs +4 -4
  64. package/dist/es/framer-motion/dist/es/render/dom/scroll/info.mjs +2 -1
  65. package/dist/es/framer-motion/dist/es/render/dom/scroll/offsets/index.mjs +6 -5
  66. package/dist/es/framer-motion/dist/es/render/dom/utils/css-variables-conversion.mjs +1 -1
  67. package/dist/es/framer-motion/dist/es/render/dom/utils/unit-conversion.mjs +2 -14
  68. package/dist/es/framer-motion/dist/es/render/dom/viewport/index.mjs +4 -3
  69. package/dist/es/framer-motion/dist/es/render/html/HTMLVisualElement.mjs +6 -20
  70. package/dist/es/framer-motion/dist/es/render/html/utils/build-styles.mjs +2 -2
  71. package/dist/es/framer-motion/dist/es/render/html/utils/build-transform.mjs +1 -1
  72. package/dist/es/framer-motion/dist/es/render/html/utils/keys-position.mjs +13 -0
  73. package/dist/es/framer-motion/dist/es/render/svg/SVGVisualElement.mjs +6 -6
  74. package/dist/es/framer-motion/dist/es/render/svg/config-motion.mjs +57 -24
  75. package/dist/es/framer-motion/dist/es/render/svg/utils/build-attrs.mjs +1 -1
  76. package/dist/es/framer-motion/dist/es/render/svg/utils/scrape-motion-values.mjs +1 -1
  77. package/dist/es/framer-motion/dist/es/render/utils/motion-values.mjs +1 -1
  78. package/dist/es/framer-motion/dist/es/utils/delay.mjs +2 -1
  79. package/dist/es/framer-motion/dist/es/utils/get-context-window.mjs +1 -1
  80. package/dist/es/framer-motion/dist/es/utils/interpolate.mjs +8 -5
  81. package/dist/es/framer-motion/dist/es/utils/mix/color.mjs +1 -1
  82. package/dist/es/framer-motion/dist/es/utils/mix/complex.mjs +1 -1
  83. package/dist/es/framer-motion/dist/es/utils/offsets/fill.mjs +2 -1
  84. package/dist/es/framer-motion/dist/es/utils/use-instant-transition.mjs +1 -1
  85. package/dist/es/framer-motion/dist/es/value/index.mjs +2 -2
  86. package/dist/es/framer-motion/dist/es/value/use-inverted-scale.mjs +1 -1
  87. package/dist/es/framer-motion/dist/es/value/use-scroll.mjs +1 -1
  88. package/dist/es/framer-motion/dist/es/value/use-spring.mjs +3 -3
  89. package/dist/es/framer-motion/dist/es/value/use-will-change/get-will-change-name.mjs +1 -1
  90. package/dist/es/motion/lib/index.mjs +12 -7
  91. package/dist/es/motion/lib/mini.mjs +1 -0
  92. package/dist/es/motion/lib/react.mjs +41 -37
  93. package/dist/es/{framer-motion/dist/es/animation/GroupPlaybackControls.mjs → motion-dom/dist/es/animation/controls/BaseGroup.mjs} +7 -6
  94. package/dist/es/motion-dom/dist/es/animation/controls/Group.mjs +13 -0
  95. package/dist/es/{framer-motion/dist/es/easing → motion-dom/dist/es/animation/generators}/utils/create-generator-easing.mjs +6 -3
  96. package/dist/es/motion-dom/dist/es/animation/waapi/NativeAnimationControls.mjs +85 -0
  97. package/dist/es/{framer-motion/dist/es/animation/animators/waapi → motion-dom/dist/es/animation/waapi/utils}/easing.mjs +3 -3
  98. package/dist/es/{framer-motion/dist/es/animation/animators → motion-dom/dist/es/animation}/waapi/utils/linear.mjs +4 -4
  99. package/dist/es/motion-dom/dist/es/gestures/drag/state/is-active.mjs +9 -0
  100. package/dist/es/motion-dom/dist/es/gestures/drag/state/set-active.mjs +28 -0
  101. package/dist/es/motion-dom/dist/es/gestures/hover.mjs +37 -0
  102. package/dist/es/motion-dom/dist/es/gestures/press/index.mjs +76 -0
  103. package/dist/es/motion-dom/dist/es/gestures/press/utils/is-keyboard-accessible.mjs +13 -0
  104. package/dist/es/motion-dom/dist/es/gestures/press/utils/keyboard.mjs +38 -0
  105. package/dist/es/motion-dom/dist/es/gestures/press/utils/state.mjs +3 -0
  106. package/dist/es/motion-dom/dist/es/gestures/utils/setup.mjs +15 -0
  107. package/dist/es/motion-dom/dist/es/utils/resolve-elements.mjs +22 -0
  108. package/dist/es/{framer-motion/dist/es/animation/animators/waapi/utils/supports-linear-easing.mjs → motion-dom/dist/es/utils/supports/linear-easing.mjs} +1 -1
  109. package/dist/es/{framer-motion/dist/es/animation/animators/waapi/utils/memo-supports.mjs → motion-dom/dist/es/utils/supports/memo.mjs} +3 -2
  110. package/dist/es/motion-dom/dist/es/utils/supports/scroll-timeline.mjs +6 -0
  111. package/dist/es/{framer-motion/dist/es/utils → motion-utils/dist/es}/memo.mjs +1 -0
  112. package/dist/es/{framer-motion/dist/es/utils → motion-utils/dist/es}/noop.mjs +1 -0
  113. package/dist/es/{framer-motion/dist/es/utils → motion-utils/dist/es}/progress.mjs +1 -0
  114. package/dist/es/{framer-motion/dist/es/utils → motion-utils/dist/es}/time-conversion.mjs +2 -0
  115. package/dist/motion.dev.js +2792 -2446
  116. package/dist/motion.js +1 -1
  117. package/package.json +6 -6
  118. package/.turbo/turbo-build.log +0 -47
  119. package/dist/es/framer-motion/dist/es/gestures/drag/utils/lock.mjs +0 -53
  120. package/dist/es/framer-motion/dist/es/render/dom/scroll/supports.mjs +0 -5
  121. package/dist/es/framer-motion/dist/es/render/dom/utils/resolve-element.mjs +0 -28
  122. package/lib/index.js +0 -2
  123. package/lib/index.js.map +0 -1
  124. package/lib/mini.js +0 -2
  125. package/lib/mini.js.map +0 -1
  126. package/lib/react-client.js +0 -3
  127. package/lib/react-client.js.map +0 -1
  128. package/lib/react-m.js +0 -3
  129. package/lib/react-m.js.map +0 -1
  130. package/lib/react-mini.js +0 -3
  131. package/lib/react-mini.js.map +0 -1
  132. package/lib/react.js +0 -3
  133. package/lib/react.js.map +0 -1
  134. package/rollup.config.mjs +0 -210
  135. package/src/index.ts +0 -1
  136. package/src/mini.ts +0 -1
  137. package/src/react-client.ts +0 -3
  138. package/src/react-m.ts +0 -3
  139. package/src/react-mini.ts +0 -3
  140. package/src/react.ts +0 -3
  141. package/tsconfig.json +0 -25
  142. package/types/index.d.ts +0 -1
  143. package/types/mini.d.ts +0 -1
  144. package/types/react-client.d.ts +0 -1
  145. package/types/react-m.d.ts +0 -1
  146. package/types/react-mini.d.ts +0 -1
  147. package/types/react.d.ts +0 -1
  148. /package/dist/es/framer-motion/dist/es/render/html/utils/{transform.mjs → keys-transform.mjs} +0 -0
  149. /package/dist/es/{framer-motion → motion-dom}/dist/es/animation/generators/utils/calc-duration.mjs +0 -0
  150. /package/dist/es/{framer-motion → motion-dom}/dist/es/animation/generators/utils/is-generator.mjs +0 -0
  151. /package/dist/es/{framer-motion → motion-dom}/dist/es/animation/utils/get-value-transition.mjs +0 -0
  152. /package/dist/es/{framer-motion/dist/es/animation/animators → motion-dom/dist/es/animation}/waapi/utils/attach-timeline.mjs +0 -0
  153. /package/dist/es/{framer-motion → motion-dom}/dist/es/gestures/utils/is-node-or-child.mjs +0 -0
  154. /package/dist/es/{framer-motion/dist/es/events → motion-dom/dist/es/gestures}/utils/is-primary-pointer.mjs +0 -0
  155. /package/dist/es/{framer-motion/dist/es/easing → motion-dom/dist/es}/utils/is-bezier-definition.mjs +0 -0
  156. /package/dist/es/{framer-motion/dist/es/animation/animators/waapi/utils/supports-flags.mjs → motion-dom/dist/es/utils/supports/flags.mjs} +0 -0
  157. /package/dist/es/{framer-motion/dist/es/utils → motion-utils/dist/es}/errors.mjs +0 -0
@@ -1,4 +1,4 @@
1
- import { transformProps } from '../../render/html/utils/transform.mjs';
1
+ import { transformProps } from '../../render/html/utils/keys-transform.mjs';
2
2
 
3
3
  const underDampedSpring = {
4
4
  type: "spring",
@@ -1,10 +1,10 @@
1
1
  "use client";
2
2
  import { jsx, Fragment } from 'react/jsx-runtime';
3
3
  import { useMemo, useRef, useState, useContext } from 'react';
4
- import { PresenceChild } from './PresenceChild.mjs';
5
4
  import { LayoutGroupContext } from '../../context/LayoutGroupContext.mjs';
6
- import { invariant } from '../../utils/errors.mjs';
7
5
  import { useConstant } from '../../utils/use-constant.mjs';
6
+ import { PresenceChild } from './PresenceChild.mjs';
7
+ import { usePresence } from './use-presence.mjs';
8
8
  import { onlyElements, getChildKey } from './utils.mjs';
9
9
  import { useIsomorphicLayoutEffect } from '../../utils/use-isomorphic-effect.mjs';
10
10
 
@@ -41,8 +41,8 @@ import { useIsomorphicLayoutEffect } from '../../utils/use-isomorphic-effect.mjs
41
41
  *
42
42
  * @public
43
43
  */
44
- const AnimatePresence = ({ children, exitBeforeEnter, custom, initial = true, onExitComplete, presenceAffectsLayout = true, mode = "sync", }) => {
45
- invariant(!exitBeforeEnter, "Replace exitBeforeEnter with mode='wait'");
44
+ const AnimatePresence = ({ children, custom, initial = true, onExitComplete, presenceAffectsLayout = true, mode = "sync", propagate = false, }) => {
45
+ const [isParentPresent, safeToRemove] = usePresence(propagate);
46
46
  /**
47
47
  * Filter any children that aren't ReactElements. We can only track components
48
48
  * between renders with a props.key.
@@ -52,7 +52,7 @@ const AnimatePresence = ({ children, exitBeforeEnter, custom, initial = true, on
52
52
  * Track the keys of the currently rendered children. This is used to
53
53
  * determine which children are exiting.
54
54
  */
55
- const presentKeys = presentChildren.map(getChildKey);
55
+ const presentKeys = propagate && !isParentPresent ? [] : presentChildren.map(getChildKey);
56
56
  /**
57
57
  * If `initial={false}` we only want to pass this to components in the first render.
58
58
  */
@@ -134,8 +134,10 @@ const AnimatePresence = ({ children, exitBeforeEnter, custom, initial = true, on
134
134
  const { forceRender } = useContext(LayoutGroupContext);
135
135
  return (jsx(Fragment, { children: renderedChildren.map((child) => {
136
136
  const key = getChildKey(child);
137
- const isPresent = presentChildren === renderedChildren ||
138
- presentKeys.includes(key);
137
+ const isPresent = propagate && !isParentPresent
138
+ ? false
139
+ : presentChildren === renderedChildren ||
140
+ presentKeys.includes(key);
139
141
  const onExit = () => {
140
142
  if (exitComplete.has(key)) {
141
143
  exitComplete.set(key, true);
@@ -151,6 +153,7 @@ const AnimatePresence = ({ children, exitBeforeEnter, custom, initial = true, on
151
153
  if (isEveryExitComplete) {
152
154
  forceRender === null || forceRender === void 0 ? void 0 : forceRender();
153
155
  setRenderedChildren(pendingPresentChildren.current);
156
+ propagate && (safeToRemove === null || safeToRemove === void 0 ? void 0 : safeToRemove());
154
157
  onExitComplete && onExitComplete();
155
158
  }
156
159
  };
@@ -24,7 +24,7 @@ import { PresenceContext } from '../../context/PresenceContext.mjs';
24
24
  *
25
25
  * @public
26
26
  */
27
- function usePresence() {
27
+ function usePresence(subscribe = true) {
28
28
  const context = useContext(PresenceContext);
29
29
  if (context === null)
30
30
  return [true, null];
@@ -32,8 +32,11 @@ function usePresence() {
32
32
  // It's safe to call the following hooks conditionally (after an early return) because the context will always
33
33
  // either be null or non-null for the lifespan of the component.
34
34
  const id = useId();
35
- useEffect(() => register(id), []);
36
- const safeToRemove = useCallback(() => onExitComplete && onExitComplete(id), [id, onExitComplete]);
35
+ useEffect(() => {
36
+ if (subscribe)
37
+ register(id);
38
+ }, [subscribe]);
39
+ const safeToRemove = useCallback(() => subscribe && onExitComplete && onExitComplete(id), [id, onExitComplete, subscribe]);
37
40
  return !isPresent && onExitComplete ? [false, safeToRemove] : [true];
38
41
  }
39
42
  /**
@@ -1,5 +1,5 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
- import { invariant } from '../utils/errors.mjs';
2
+ import { invariant } from '../../../../motion-utils/dist/es/errors.mjs';
3
3
  import * as React from 'react';
4
4
  import { useConstant } from '../utils/use-constant.mjs';
5
5
  import { LayoutGroup } from './LayoutGroup/index.mjs';
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx } from 'react/jsx-runtime';
3
- import { invariant } from '../../utils/errors.mjs';
3
+ import { invariant } from '../../../../../motion-utils/dist/es/errors.mjs';
4
4
  import { forwardRef, useRef, useEffect } from 'react';
5
5
  import { ReorderContext } from '../../context/ReorderContext.mjs';
6
6
  import { motion } from '../../render/components/motion/proxy.mjs';
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx } from 'react/jsx-runtime';
3
- import { invariant } from '../../utils/errors.mjs';
3
+ import { invariant } from '../../../../../motion-utils/dist/es/errors.mjs';
4
4
  import { forwardRef, useContext } from 'react';
5
5
  import { ReorderContext } from '../../context/ReorderContext.mjs';
6
6
  import { motion } from '../../render/components/motion/proxy.mjs';
@@ -1,4 +1,5 @@
1
- import { noop } from '../utils/noop.mjs';
1
+ import '../../../../motion-utils/dist/es/errors.mjs';
2
+ import { noop } from '../../../../motion-utils/dist/es/noop.mjs';
2
3
 
3
4
  /*
4
5
  Bezier function generator
@@ -1,11 +1,11 @@
1
- import { invariant } from '../../utils/errors.mjs';
1
+ import { invariant } from '../../../../../motion-utils/dist/es/errors.mjs';
2
+ import { noop } from '../../../../../motion-utils/dist/es/noop.mjs';
3
+ import { isBezierDefinition } from '../../../../../motion-dom/dist/es/utils/is-bezier-definition.mjs';
4
+ import { anticipate } from '../anticipate.mjs';
5
+ import { backIn, backInOut, backOut } from '../back.mjs';
6
+ import { circIn, circInOut, circOut } from '../circ.mjs';
2
7
  import { cubicBezier } from '../cubic-bezier.mjs';
3
- import { noop } from '../../utils/noop.mjs';
4
8
  import { easeIn, easeInOut, easeOut } from '../ease.mjs';
5
- import { circIn, circInOut, circOut } from '../circ.mjs';
6
- import { backIn, backInOut, backOut } from '../back.mjs';
7
- import { anticipate } from '../anticipate.mjs';
8
- import { isBezierDefinition } from './is-bezier-definition.mjs';
9
9
 
10
10
  const easingLookup = {
11
11
  linear: noop,
@@ -1,10 +1,11 @@
1
- import { isPrimaryPointer } from './utils/is-primary-pointer.mjs';
1
+ import '../../../../motion-utils/dist/es/errors.mjs';
2
+ import { isPrimaryPointer } from '../../../../motion-dom/dist/es/gestures/utils/is-primary-pointer.mjs';
2
3
 
3
- function extractEventInfo(event, pointType = "page") {
4
+ function extractEventInfo(event) {
4
5
  return {
5
6
  point: {
6
- x: event[`${pointType}X`],
7
- y: event[`${pointType}Y`],
7
+ x: event.pageX,
8
+ y: event.pageY,
8
9
  },
9
10
  };
10
11
  }
@@ -1,4 +1,5 @@
1
- import { noop } from '../utils/noop.mjs';
1
+ import '../../../../motion-utils/dist/es/errors.mjs';
2
+ import { noop } from '../../../../motion-utils/dist/es/noop.mjs';
2
3
  import { createRenderBatcher } from './batcher.mjs';
3
4
 
4
5
  const { schedule: frame, cancel: cancelFrame, state: frameData, steps: frameSteps, } = createRenderBatcher(typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : noop, true);
@@ -63,10 +63,11 @@ function createRenderStep(runNextFrame) {
63
63
  }
64
64
  isProcessing = true;
65
65
  [thisFrame, nextFrame] = [nextFrame, thisFrame];
66
- // Clear the next frame queue
67
- nextFrame.clear();
68
66
  // Execute this frame
69
67
  thisFrame.forEach(triggerCallback);
68
+ // Clear the frame so no callbacks remain. This is to avoid
69
+ // memory leaks should this render step not run for a while.
70
+ thisFrame.clear();
70
71
  isProcessing = false;
71
72
  if (flushNextFrame) {
72
73
  flushNextFrame = false;
@@ -1,6 +1,6 @@
1
- import { invariant } from '../../utils/errors.mjs';
1
+ import { invariant } from '../../../../../motion-utils/dist/es/errors.mjs';
2
+ import { setDragLock } from '../../../../../motion-dom/dist/es/gestures/drag/state/set-active.mjs';
2
3
  import { PanSession } from '../pan/PanSession.mjs';
3
- import { getGlobalLock } from './utils/lock.mjs';
4
4
  import { isRefObject } from '../../utils/is-ref-object.mjs';
5
5
  import { addPointerEvent } from '../../events/add-pointer-event.mjs';
6
6
  import { applyConstraints, calcRelativeConstraints, resolveDragElastic, calcViewportConstraints, rebaseAxisConstraints, calcOrigin, defaultElastic } from './utils/constraints.mjs';
@@ -25,10 +25,7 @@ const elementDragControls = new WeakMap();
25
25
  // let latestPointerEvent: PointerEvent
26
26
  class VisualElementDragControls {
27
27
  constructor(visualElement) {
28
- // This is a reference to the global drag gesture lock, ensuring only one component
29
- // can "capture" the drag of one or both axes.
30
- // TODO: Look into moving this into pansession?
31
- this.openGlobalLock = null;
28
+ this.openDragLock = null;
32
29
  this.isDragging = false;
33
30
  this.currentDirection = null;
34
31
  this.originPoint = { x: 0, y: 0 };
@@ -56,18 +53,18 @@ class VisualElementDragControls {
56
53
  // the component.
57
54
  dragSnapToOrigin ? this.pauseAnimation() : this.stopAnimation();
58
55
  if (snapToCursor) {
59
- this.snapToCursor(extractEventInfo(event, "page").point);
56
+ this.snapToCursor(extractEventInfo(event).point);
60
57
  }
61
58
  };
62
59
  const onStart = (event, info) => {
63
60
  // Attempt to grab the global drag gesture lock - maybe make this part of PanSession
64
61
  const { drag, dragPropagation, onDragStart } = this.getProps();
65
62
  if (drag && !dragPropagation) {
66
- if (this.openGlobalLock)
67
- this.openGlobalLock();
68
- this.openGlobalLock = getGlobalLock(drag);
63
+ if (this.openDragLock)
64
+ this.openDragLock();
65
+ this.openDragLock = setDragLock(drag);
69
66
  // If we don 't have the lock, don't start dragging
70
- if (!this.openGlobalLock)
67
+ if (!this.openDragLock)
71
68
  return;
72
69
  }
73
70
  this.isDragging = true;
@@ -109,7 +106,7 @@ class VisualElementDragControls {
109
106
  // latestPointerEvent = event
110
107
  const { dragPropagation, dragDirectionLock, onDirectionLock, onDrag, } = this.getProps();
111
108
  // If we didn't successfully receive the gesture lock, early return.
112
- if (!dragPropagation && !this.openGlobalLock)
109
+ if (!dragPropagation && !this.openDragLock)
113
110
  return;
114
111
  const { offset } = info;
115
112
  // Attempt to detect drag direction if directionLock is true
@@ -177,9 +174,9 @@ class VisualElementDragControls {
177
174
  this.panSession && this.panSession.end();
178
175
  this.panSession = undefined;
179
176
  const { dragPropagation } = this.getProps();
180
- if (!dragPropagation && this.openGlobalLock) {
181
- this.openGlobalLock();
182
- this.openGlobalLock = null;
177
+ if (!dragPropagation && this.openDragLock) {
178
+ this.openDragLock();
179
+ this.openDragLock = null;
183
180
  }
184
181
  animationState && animationState.setActive("whileDrag", false);
185
182
  }
@@ -1,5 +1,6 @@
1
1
  import { Feature } from '../../motion/features/Feature.mjs';
2
- import { noop } from '../../utils/noop.mjs';
2
+ import '../../../../../motion-utils/dist/es/errors.mjs';
3
+ import { noop } from '../../../../../motion-utils/dist/es/noop.mjs';
3
4
  import { VisualElementDragControls } from './VisualElementDragControls.mjs';
4
5
 
5
6
  class DragGesture extends Feature {
@@ -1,4 +1,5 @@
1
- import { progress } from '../../../utils/progress.mjs';
1
+ import '../../../../../../motion-utils/dist/es/errors.mjs';
2
+ import { progress } from '../../../../../../motion-utils/dist/es/progress.mjs';
2
3
  import { calcLength } from '../../../projection/geometry/delta-calc.mjs';
3
4
  import { clamp } from '../../../utils/clamp.mjs';
4
5
  import { mixNumber } from '../../../utils/mix/number.mjs';
@@ -1,31 +1,29 @@
1
- import { addPointerEvent } from '../events/add-pointer-event.mjs';
2
- import { pipe } from '../utils/pipe.mjs';
3
- import { isDragActive } from './drag/utils/lock.mjs';
1
+ import '../../../../motion-utils/dist/es/errors.mjs';
2
+ import { hover } from '../../../../motion-dom/dist/es/gestures/hover.mjs';
3
+ import { extractEventInfo } from '../events/event-info.mjs';
4
4
  import { Feature } from '../motion/features/Feature.mjs';
5
5
  import { frame } from '../frameloop/frame.mjs';
6
6
 
7
- function addHoverEvent(node, isActive) {
8
- const eventName = isActive ? "pointerenter" : "pointerleave";
9
- const callbackName = isActive ? "onHoverStart" : "onHoverEnd";
10
- const handleEvent = (event, info) => {
11
- if (event.pointerType === "touch" || isDragActive())
12
- return;
13
- const props = node.getProps();
14
- if (node.animationState && props.whileHover) {
15
- node.animationState.setActive("whileHover", isActive);
16
- }
17
- const callback = props[callbackName];
18
- if (callback) {
19
- frame.postRender(() => callback(event, info));
20
- }
21
- };
22
- return addPointerEvent(node.current, eventName, handleEvent, {
23
- passive: !node.getProps()[callbackName],
24
- });
7
+ function handleHoverEvent(node, event, lifecycle) {
8
+ const { props } = node;
9
+ if (node.animationState && props.whileHover) {
10
+ node.animationState.setActive("whileHover", lifecycle === "Start");
11
+ }
12
+ const eventName = ("onHover" + lifecycle);
13
+ const callback = props[eventName];
14
+ if (callback) {
15
+ frame.postRender(() => callback(event, extractEventInfo(event)));
16
+ }
25
17
  }
26
18
  class HoverGesture extends Feature {
27
19
  mount() {
28
- this.unmount = pipe(addHoverEvent(this.node, true), addHoverEvent(this.node, false));
20
+ const { current } = this.node;
21
+ if (!current)
22
+ return;
23
+ this.unmount = hover(current, (_element, startEvent) => {
24
+ handleHoverEvent(this.node, startEvent, "Start");
25
+ return (endEvent) => handleHoverEvent(this.node, endEvent, "End");
26
+ });
29
27
  }
30
28
  unmount() { }
31
29
  }
@@ -1,16 +1,17 @@
1
- import { extractEventInfo } from '../../events/event-info.mjs';
2
- import { secondsToMilliseconds, millisecondsToSeconds } from '../../utils/time-conversion.mjs';
1
+ import '../../../../../motion-utils/dist/es/errors.mjs';
2
+ import { secondsToMilliseconds, millisecondsToSeconds } from '../../../../../motion-utils/dist/es/time-conversion.mjs';
3
+ import { isPrimaryPointer } from '../../../../../motion-dom/dist/es/gestures/utils/is-primary-pointer.mjs';
3
4
  import { addPointerEvent } from '../../events/add-pointer-event.mjs';
4
- import { pipe } from '../../utils/pipe.mjs';
5
+ import { extractEventInfo } from '../../events/event-info.mjs';
5
6
  import { distance2D } from '../../utils/distance.mjs';
6
- import { isPrimaryPointer } from '../../events/utils/is-primary-pointer.mjs';
7
+ import { pipe } from '../../utils/pipe.mjs';
7
8
  import { frame, cancelFrame, frameData } from '../../frameloop/frame.mjs';
8
9
 
9
10
  /**
10
11
  * @internal
11
12
  */
12
13
  class PanSession {
13
- constructor(event, handlers, { transformPagePoint, contextWindow, dragSnapToOrigin = false } = {}) {
14
+ constructor(event, handlers, { transformPagePoint, contextWindow, dragSnapToOrigin = false, } = {}) {
14
15
  /**
15
16
  * @internal
16
17
  */
@@ -1,7 +1,8 @@
1
1
  import { PanSession } from './PanSession.mjs';
2
2
  import { addPointerEvent } from '../../events/add-pointer-event.mjs';
3
3
  import { Feature } from '../../motion/features/Feature.mjs';
4
- import { noop } from '../../utils/noop.mjs';
4
+ import '../../../../../motion-utils/dist/es/errors.mjs';
5
+ import { noop } from '../../../../../motion-utils/dist/es/noop.mjs';
5
6
  import { getContextWindow } from '../../utils/get-context-window.mjs';
6
7
  import { frame } from '../../frameloop/frame.mjs';
7
8
 
@@ -1,130 +1,31 @@
1
+ import '../../../../motion-utils/dist/es/errors.mjs';
2
+ import { press } from '../../../../motion-dom/dist/es/gestures/press/index.mjs';
1
3
  import { extractEventInfo } from '../events/event-info.mjs';
2
- import { addDomEvent } from '../events/add-dom-event.mjs';
3
- import { addPointerEvent } from '../events/add-pointer-event.mjs';
4
4
  import { Feature } from '../motion/features/Feature.mjs';
5
- import { pipe } from '../utils/pipe.mjs';
6
- import { isDragActive } from './drag/utils/lock.mjs';
7
- import { isNodeOrChild } from './utils/is-node-or-child.mjs';
8
- import { noop } from '../utils/noop.mjs';
9
5
  import { frame } from '../frameloop/frame.mjs';
10
6
 
11
- function fireSyntheticPointerEvent(name, handler) {
12
- if (!handler)
13
- return;
14
- const syntheticPointerEvent = new PointerEvent("pointer" + name);
15
- handler(syntheticPointerEvent, extractEventInfo(syntheticPointerEvent));
16
- }
17
- class PressGesture extends Feature {
18
- constructor() {
19
- super(...arguments);
20
- this.removeStartListeners = noop;
21
- this.removeEndListeners = noop;
22
- this.removeAccessibleListeners = noop;
23
- this.startPointerPress = (startEvent, startInfo) => {
24
- if (this.isPressing)
25
- return;
26
- this.removeEndListeners();
27
- const props = this.node.getProps();
28
- const endPointerPress = (endEvent, endInfo) => {
29
- if (!this.checkPressEnd())
30
- return;
31
- const { onTap, onTapCancel, globalTapTarget } = this.node.getProps();
32
- /**
33
- * We only count this as a tap gesture if the event.target is the same
34
- * as, or a child of, this component's element
35
- */
36
- const handler = !globalTapTarget &&
37
- !isNodeOrChild(this.node.current, endEvent.target)
38
- ? onTapCancel
39
- : onTap;
40
- if (handler) {
41
- frame.update(() => handler(endEvent, endInfo));
42
- }
43
- };
44
- const removePointerUpListener = addPointerEvent(window, "pointerup", endPointerPress, {
45
- passive: !(props.onTap || props["onPointerUp"]),
46
- });
47
- const removePointerCancelListener = addPointerEvent(window, "pointercancel", (cancelEvent, cancelInfo) => this.cancelPress(cancelEvent, cancelInfo), {
48
- passive: !(props.onTapCancel ||
49
- props["onPointerCancel"]),
50
- });
51
- this.removeEndListeners = pipe(removePointerUpListener, removePointerCancelListener);
52
- this.startPress(startEvent, startInfo);
53
- };
54
- this.startAccessiblePress = () => {
55
- const handleKeydown = (keydownEvent) => {
56
- if (keydownEvent.key !== "Enter" || this.isPressing)
57
- return;
58
- const handleKeyup = (keyupEvent) => {
59
- if (keyupEvent.key !== "Enter" || !this.checkPressEnd())
60
- return;
61
- fireSyntheticPointerEvent("up", (event, info) => {
62
- const { onTap } = this.node.getProps();
63
- if (onTap) {
64
- frame.postRender(() => onTap(event, info));
65
- }
66
- });
67
- };
68
- this.removeEndListeners();
69
- this.removeEndListeners = addDomEvent(this.node.current, "keyup", handleKeyup);
70
- fireSyntheticPointerEvent("down", (event, info) => {
71
- this.startPress(event, info);
72
- });
73
- };
74
- const removeKeydownListener = addDomEvent(this.node.current, "keydown", handleKeydown);
75
- const handleBlur = () => {
76
- if (!this.isPressing)
77
- return;
78
- fireSyntheticPointerEvent("cancel", (cancelEvent, cancelInfo) => this.cancelPress(cancelEvent, cancelInfo));
79
- };
80
- const removeBlurListener = addDomEvent(this.node.current, "blur", handleBlur);
81
- this.removeAccessibleListeners = pipe(removeKeydownListener, removeBlurListener);
82
- };
83
- }
84
- startPress(event, info) {
85
- this.isPressing = true;
86
- const { onTapStart, whileTap } = this.node.getProps();
87
- /**
88
- * Ensure we trigger animations before firing event callback
89
- */
90
- if (whileTap && this.node.animationState) {
91
- this.node.animationState.setActive("whileTap", true);
92
- }
93
- if (onTapStart) {
94
- frame.postRender(() => onTapStart(event, info));
95
- }
7
+ function handlePressEvent(node, event, lifecycle) {
8
+ const { props } = node;
9
+ if (node.animationState && props.whileTap) {
10
+ node.animationState.setActive("whileTap", lifecycle === "Start");
96
11
  }
97
- checkPressEnd() {
98
- this.removeEndListeners();
99
- this.isPressing = false;
100
- const props = this.node.getProps();
101
- if (props.whileTap && this.node.animationState) {
102
- this.node.animationState.setActive("whileTap", false);
103
- }
104
- return !isDragActive();
105
- }
106
- cancelPress(event, info) {
107
- if (!this.checkPressEnd())
108
- return;
109
- const { onTapCancel } = this.node.getProps();
110
- if (onTapCancel) {
111
- frame.postRender(() => onTapCancel(event, info));
112
- }
12
+ const eventName = ("onTap" + (lifecycle === "End" ? "" : lifecycle));
13
+ const callback = props[eventName];
14
+ if (callback) {
15
+ frame.postRender(() => callback(event, extractEventInfo(event)));
113
16
  }
17
+ }
18
+ class PressGesture extends Feature {
114
19
  mount() {
115
- const props = this.node.getProps();
116
- const removePointerListener = addPointerEvent(props.globalTapTarget ? window : this.node.current, "pointerdown", this.startPointerPress, {
117
- passive: !(props.onTapStart ||
118
- props["onPointerStart"]),
119
- });
120
- const removeFocusListener = addDomEvent(this.node.current, "focus", this.startAccessiblePress);
121
- this.removeStartListeners = pipe(removePointerListener, removeFocusListener);
122
- }
123
- unmount() {
124
- this.removeStartListeners();
125
- this.removeEndListeners();
126
- this.removeAccessibleListeners();
20
+ const { current } = this.node;
21
+ if (!current)
22
+ return;
23
+ this.unmount = press(current, (_element, startEvent) => {
24
+ handlePressEvent(this.node, startEvent, "Start");
25
+ return (endEvent, { success }) => handlePressEvent(this.node, endEvent, success ? "End" : "Cancel");
26
+ }, { useGlobalTarget: this.node.props.globalTapTarget });
127
27
  }
28
+ unmount() { }
128
29
  }
129
30
 
130
31
  export { PressGesture };
@@ -1,18 +1,18 @@
1
1
  "use client";
2
2
  import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import { warning, invariant } from '../../../../motion-utils/dist/es/errors.mjs';
3
4
  import { forwardRef, useContext } from 'react';
5
+ import { LayoutGroupContext } from '../context/LayoutGroupContext.mjs';
6
+ import { LazyContext } from '../context/LazyContext.mjs';
4
7
  import { MotionConfigContext } from '../context/MotionConfigContext.mjs';
5
8
  import { MotionContext } from '../context/MotionContext/index.mjs';
6
- import { useVisualElement } from './utils/use-visual-element.mjs';
7
- import { useMotionRef } from './utils/use-motion-ref.mjs';
8
9
  import { useCreateMotionContext } from '../context/MotionContext/create.mjs';
9
- import { loadFeatures } from './features/load-features.mjs';
10
10
  import { isBrowser } from '../utils/is-browser.mjs';
11
- import { LayoutGroupContext } from '../context/LayoutGroupContext.mjs';
12
- import { LazyContext } from '../context/LazyContext.mjs';
13
- import { motionComponentSymbol } from './utils/symbol.mjs';
14
- import { warning, invariant } from '../utils/errors.mjs';
15
11
  import { featureDefinitions } from './features/definitions.mjs';
12
+ import { loadFeatures } from './features/load-features.mjs';
13
+ import { motionComponentSymbol } from './utils/symbol.mjs';
14
+ import { useMotionRef } from './utils/use-motion-ref.mjs';
15
+ import { useVisualElement } from './utils/use-visual-element.mjs';
16
16
 
17
17
  /**
18
18
  * Create a `motion` component.
@@ -24,6 +24,7 @@ import { featureDefinitions } from './features/definitions.mjs';
24
24
  * component "offline", or outside the React render cycle.
25
25
  */
26
26
  function createRendererMotionComponent({ preloadedFeatures, createVisualElement, useRender, useVisualState, Component, }) {
27
+ var _a, _b;
27
28
  preloadedFeatures && loadFeatures(preloadedFeatures);
28
29
  function MotionComponent(props, externalRef) {
29
30
  /**
@@ -57,6 +58,9 @@ function createRendererMotionComponent({ preloadedFeatures, createVisualElement,
57
58
  */
58
59
  return (jsxs(MotionContext.Provider, { value: context, children: [MeasureLayout && context.visualElement ? (jsx(MeasureLayout, { visualElement: context.visualElement, ...configAndProps })) : null, useRender(Component, props, useMotionRef(visualState, context.visualElement, externalRef), visualState, isStatic, context.visualElement)] }));
59
60
  }
61
+ MotionComponent.displayName = `motion.${typeof Component === "string"
62
+ ? Component
63
+ : `create(${(_b = (_a = Component.displayName) !== null && _a !== void 0 ? _a : Component.name) !== null && _b !== void 0 ? _b : ""})`}`;
60
64
  const ForwardRefMotionComponent = forwardRef(MotionComponent);
61
65
  ForwardRefMotionComponent[motionComponentSymbol] = Component;
62
66
  return ForwardRefMotionComponent;
@@ -1,5 +1,5 @@
1
1
  import { scaleCorrectors } from '../../projection/styles/scale-correction.mjs';
2
- import { transformProps } from '../../render/html/utils/transform.mjs';
2
+ import { transformProps } from '../../render/html/utils/keys-transform.mjs';
3
3
 
4
4
  function isForcedMotionValue(key, { layout, layoutId }) {
5
5
  return (transformProps.has(key) ||
@@ -7,7 +7,9 @@ import { isRefObject } from '../../utils/is-ref-object.mjs';
7
7
  */
8
8
  function useMotionRef(visualState, visualElement, externalRef) {
9
9
  return useCallback((instance) => {
10
- instance && visualState.mount && visualState.mount(instance);
10
+ if (instance) {
11
+ visualState.onMount && visualState.onMount(instance);
12
+ }
11
13
  if (visualElement) {
12
14
  if (instance) {
13
15
  visualElement.mount(instance);
@@ -15,7 +15,7 @@ function useVisualElement(Component, visualState, props, createVisualElement, Pr
15
15
  const lazyContext = useContext(LazyContext);
16
16
  const presenceContext = useContext(PresenceContext);
17
17
  const reducedMotionConfig = useContext(MotionConfigContext).reducedMotion;
18
- const visualElementRef = useRef(undefined);
18
+ const visualElementRef = useRef(null);
19
19
  /**
20
20
  * If we haven't preloaded a renderer, check to see if we have one lazy-loaded
21
21
  */
@@ -1,19 +1,25 @@
1
1
  import { useContext } from 'react';
2
2
  import { isAnimationControls } from '../../animation/utils/is-animation-controls.mjs';
3
+ import { MotionContext } from '../../context/MotionContext/index.mjs';
3
4
  import { PresenceContext } from '../../context/PresenceContext.mjs';
5
+ import { isControllingVariants, isVariantNode } from '../../render/utils/is-controlling-variants.mjs';
4
6
  import { resolveVariantFromProps } from '../../render/utils/resolve-variants.mjs';
5
7
  import { useConstant } from '../../utils/use-constant.mjs';
6
8
  import { resolveMotionValue } from '../../value/utils/resolve-motion-value.mjs';
7
- import { MotionContext } from '../../context/MotionContext/index.mjs';
8
- import { isControllingVariants, isVariantNode } from '../../render/utils/is-controlling-variants.mjs';
9
9
 
10
- function makeState({ scrapeMotionValuesFromProps, createRenderState, onMount, }, props, context, presenceContext) {
10
+ function makeState({ scrapeMotionValuesFromProps, createRenderState, onUpdate, }, props, context, presenceContext) {
11
11
  const state = {
12
12
  latestValues: makeLatestValues(props, context, presenceContext, scrapeMotionValuesFromProps),
13
13
  renderState: createRenderState(),
14
14
  };
15
- if (onMount) {
16
- state.mount = (instance) => onMount(props, instance, state);
15
+ if (onUpdate) {
16
+ /**
17
+ * onMount works without the VisualElement because it could be
18
+ * called before the VisualElement payload has been hydrated.
19
+ * (e.g. if someone is using m components <m.circle />)
20
+ */
21
+ state.onMount = (instance) => onUpdate({ props, current: instance, ...state });
22
+ state.onUpdate = (visualElement) => onUpdate(visualElement);
17
23
  }
18
24
  return state;
19
25
  }
@@ -1,7 +1,8 @@
1
+ import '../../../../../motion-utils/dist/es/errors.mjs';
2
+ import { noop } from '../../../../../motion-utils/dist/es/noop.mjs';
3
+ import { progress } from '../../../../../motion-utils/dist/es/progress.mjs';
1
4
  import { circOut } from '../../easing/circ.mjs';
2
- import { progress } from '../../utils/progress.mjs';
3
5
  import { mixNumber } from '../../utils/mix/number.mjs';
4
- import { noop } from '../../utils/noop.mjs';
5
6
  import { percent, px } from '../../value/types/numbers/units.mjs';
6
7
 
7
8
  const borders = ["TopLeft", "TopRight", "BottomLeft", "BottomRight"];