framer-motion 12.24.8 → 12.24.10

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var featureBundle = require('./feature-bundle-C6mMBZjn.js');
5
+ var featureBundle = require('./feature-bundle-OJqyiRBo.js');
6
6
  require('react');
7
7
  require('motion-dom');
8
8
  require('motion-utils');
@@ -4105,69 +4105,51 @@ const useSVGVisualState = /*@__PURE__*/ makeUseVisualState({
4105
4105
 
4106
4106
  const motionComponentSymbol = Symbol.for("motionComponentSymbol");
4107
4107
 
4108
- function isRefObject(ref) {
4109
- return (ref &&
4110
- typeof ref === "object" &&
4111
- Object.prototype.hasOwnProperty.call(ref, "current"));
4112
- }
4113
-
4114
- /**
4115
- * Set a given ref to a given value
4116
- * This utility takes care of different types of refs: callback refs and RefObject(s)
4117
- * Returns a cleanup function if the ref callback returns one (React 19 feature)
4118
- */
4119
- function setRef(ref, value) {
4120
- if (typeof ref === "function") {
4121
- return ref(value);
4122
- }
4123
- else if (isRefObject(ref)) {
4124
- ref.current = value;
4125
- }
4126
- }
4127
4108
  /**
4128
4109
  * Creates a ref function that, when called, hydrates the provided
4129
4110
  * external ref and VisualElement.
4130
4111
  */
4131
4112
  function useMotionRef(visualState, visualElement, externalRef) {
4132
- // Store the cleanup function from external ref if it returns one
4133
- const externalRefCleanupRef = React.useRef(null);
4113
+ /**
4114
+ * Store externalRef in a ref to avoid including it in the useCallback
4115
+ * dependency array. Including externalRef in dependencies causes issues
4116
+ * with libraries like Radix UI that create new callback refs on each render
4117
+ * when using asChild - this would cause the callback to be recreated,
4118
+ * triggering element remounts and breaking AnimatePresence exit animations.
4119
+ */
4120
+ const externalRefContainer = React.useRef(externalRef);
4121
+ React.useInsertionEffect(() => {
4122
+ externalRefContainer.current = externalRef;
4123
+ });
4124
+ // Store cleanup function returned by callback refs (React 19 feature)
4125
+ const refCleanup = React.useRef(null);
4134
4126
  return React.useCallback((instance) => {
4135
4127
  if (instance) {
4136
- visualState.onMount && visualState.onMount(instance);
4128
+ visualState.onMount?.(instance);
4137
4129
  }
4138
4130
  if (visualElement) {
4139
- if (instance) {
4140
- visualElement.mount(instance);
4141
- }
4142
- else {
4143
- visualElement.unmount();
4144
- }
4131
+ instance ? visualElement.mount(instance) : visualElement.unmount();
4145
4132
  }
4146
- if (externalRef) {
4133
+ const ref = externalRefContainer.current;
4134
+ if (typeof ref === "function") {
4147
4135
  if (instance) {
4148
- // Mount: call the external ref and store any cleanup function
4149
- const cleanup = setRef(externalRef, instance);
4136
+ const cleanup = ref(instance);
4150
4137
  if (typeof cleanup === "function") {
4151
- externalRefCleanupRef.current = cleanup;
4138
+ refCleanup.current = cleanup;
4152
4139
  }
4153
4140
  }
4141
+ else if (refCleanup.current) {
4142
+ refCleanup.current();
4143
+ refCleanup.current = null;
4144
+ }
4154
4145
  else {
4155
- // Unmount: call stored cleanup function if available, otherwise call ref with null
4156
- if (externalRefCleanupRef.current) {
4157
- externalRefCleanupRef.current();
4158
- externalRefCleanupRef.current = null;
4159
- }
4160
- else {
4161
- // Fallback to React <19 behavior for refs that don't return cleanup
4162
- setRef(externalRef, instance);
4163
- }
4146
+ ref(instance);
4164
4147
  }
4165
4148
  }
4166
- },
4167
- /**
4168
- * Include all dependencies to ensure the callback updates correctly
4169
- */
4170
- [visualElement, visualState, externalRef]);
4149
+ else if (ref) {
4150
+ ref.current = instance;
4151
+ }
4152
+ }, [visualElement]);
4171
4153
  }
4172
4154
 
4173
4155
  /**
@@ -4175,6 +4157,12 @@ function useMotionRef(visualState, visualElement, externalRef) {
4175
4157
  */
4176
4158
  const SwitchLayoutGroupContext = React.createContext({});
4177
4159
 
4160
+ function isRefObject(ref) {
4161
+ return (ref &&
4162
+ typeof ref === "object" &&
4163
+ Object.prototype.hasOwnProperty.call(ref, "current"));
4164
+ }
4165
+
4178
4166
  function useVisualElement(Component, visualState, props, createVisualElement, ProjectionNodeConstructor, isSVG) {
4179
4167
  const { visualElement: parent } = React.useContext(MotionContext);
4180
4168
  const lazyContext = React.useContext(LazyContext);
@@ -5172,8 +5160,11 @@ class PanSession {
5172
5160
  this.handlePointerUp = (event, info) => {
5173
5161
  this.end();
5174
5162
  const { onEnd, onSessionEnd, resumeAnimation } = this.handlers;
5175
- if (this.dragSnapToOrigin)
5163
+ // Resume animation if dragSnapToOrigin is set OR if no drag started (user just clicked)
5164
+ // This ensures constraint animations continue when interrupted by a click
5165
+ if (this.dragSnapToOrigin || !this.startEvent) {
5176
5166
  resumeAnimation && resumeAnimation();
5167
+ }
5177
5168
  if (!(this.lastMoveEvent && this.lastMoveEventInfo))
5178
5169
  return;
5179
5170
  const panInfo = getPanInfo(event.type === "pointercancel"
@@ -5422,15 +5413,21 @@ class VisualElementDragControls {
5422
5413
  if (presenceContext && presenceContext.isPresent === false)
5423
5414
  return;
5424
5415
  const onSessionStart = (event) => {
5425
- const { dragSnapToOrigin } = this.getProps();
5426
- // Stop or pause any animations on both axis values immediately. This allows the user to throw and catch
5427
- // the component.
5428
- dragSnapToOrigin ? this.pauseAnimation() : this.stopAnimation();
5416
+ // Stop or pause animations based on context:
5417
+ // - snapToCursor: stop because we'll set new position values
5418
+ // - otherwise: pause to allow resume if no drag starts (for constraint animations)
5429
5419
  if (snapToCursor) {
5420
+ this.stopAnimation();
5430
5421
  this.snapToCursor(extractEventInfo(event).point);
5431
5422
  }
5423
+ else {
5424
+ this.pauseAnimation();
5425
+ }
5432
5426
  };
5433
5427
  const onStart = (event, info) => {
5428
+ // Stop any paused animation so motion values reflect true current position
5429
+ // (pauseAnimation was called in onSessionStart to allow resume if no drag started)
5430
+ this.stopAnimation();
5434
5431
  // Attempt to grab the global drag gesture lock - maybe make this part of PanSession
5435
5432
  const { drag, dragPropagation, onDragStart } = this.getProps();
5436
5433
  if (drag && !dragPropagation) {
@@ -5796,7 +5793,11 @@ class VisualElementDragControls {
5796
5793
  */
5797
5794
  const stopPointerListener = addPointerEvent(element, "pointerdown", (event) => {
5798
5795
  const { drag, dragListener = true } = this.getProps();
5799
- drag && dragListener && this.start(event);
5796
+ if (drag &&
5797
+ dragListener &&
5798
+ !motionDom.isElementKeyboardAccessible(event.target)) {
5799
+ this.start(event);
5800
+ }
5800
5801
  });
5801
5802
  const measureDragConstraints = () => {
5802
5803
  const { dragConstraints } = this.getProps();
@@ -6359,4 +6360,4 @@ exports.useIsPresent = useIsPresent;
6359
6360
  exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
6360
6361
  exports.usePresence = usePresence;
6361
6362
  exports.visualElementStore = visualElementStore;
6362
- //# sourceMappingURL=feature-bundle-C6mMBZjn.js.map
6363
+ //# sourceMappingURL=feature-bundle-OJqyiRBo.js.map