motion-dom 14.8.0 → 14.9.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.
@@ -9478,9 +9478,10 @@
9478
9478
  /**
9479
9479
  * If this element has been mounted before (e.g. after a Suspense
9480
9480
  * unmount/remount), reset motion values to their initial state
9481
- * so animations replay correctly from initial → animate.
9481
+ * so animations replay correctly from initial → animate, unless
9482
+ * the presence asks to keep them.
9482
9483
  */
9483
- if (this.hasBeenMounted) {
9484
+ if (this.hasBeenMounted && !this.presenceContext?.keepValuesOnRemount) {
9484
9485
  for (const key in this.initialValues) {
9485
9486
  this.values.get(key)?.jump(this.initialValues[key]);
9486
9487
  this.latestValues[key] = this.initialValues[key];
@@ -11044,7 +11045,7 @@
11044
11045
  };
11045
11046
  const onStart = (event, info) => {
11046
11047
  // Attempt to grab the global drag gesture lock - maybe make this part of PanSession
11047
- const { drag, dragPropagation, onDragStart } = this.getProps();
11048
+ const { drag, dragConstraints, dragPropagation, onDragStart } = this.getProps();
11048
11049
  if (drag && !dragPropagation) {
11049
11050
  this.openDragLock?.();
11050
11051
  this.openDragLock = setDragLock(drag);
@@ -11091,6 +11092,8 @@
11091
11092
  }
11092
11093
  this.originPoint[axis] = current;
11093
11094
  });
11095
+ this.point =
11096
+ typeof dragConstraints === "function" && dragConstraints(this);
11094
11097
  // Fire onDragStart event
11095
11098
  if (onDragStart) {
11096
11099
  frame.update(() => onDragStart(event, info), false, true);
@@ -11121,6 +11124,7 @@
11121
11124
  // Update each point with the latest position
11122
11125
  this.updateAxis("x", offset);
11123
11126
  this.updateAxis("y", offset);
11127
+ this.point && this.point.move();
11124
11128
  /**
11125
11129
  * Ideally we would leave the renderer to fire naturally at the end of
11126
11130
  * this frame but if the element is about to change layout as the result
@@ -11145,7 +11149,7 @@
11145
11149
  };
11146
11150
  const resumeAnimation = () => {
11147
11151
  const { dragSnapToOrigin: snap } = this.getProps();
11148
- if (snap || this.constraints) {
11152
+ if (snap || this.constraints || this.point) {
11149
11153
  this.startAnimation({ x: 0, y: 0 });
11150
11154
  }
11151
11155
  };
@@ -11220,7 +11224,7 @@
11220
11224
  if (constraints) {
11221
11225
  next = applyConstraints(next, constraints, this.elastic[axis]);
11222
11226
  }
11223
- axisValue.set(next);
11227
+ this.point ? (this.point[axis] = next) : axisValue.set(next);
11224
11228
  }
11225
11229
  resolveConstraints() {
11226
11230
  const { dragConstraints, dragElastic } = this.getProps();
@@ -11241,7 +11245,9 @@
11241
11245
  }
11242
11246
  }
11243
11247
  else {
11244
- if (dragConstraints && layout) {
11248
+ if (dragConstraints &&
11249
+ layout &&
11250
+ typeof dragConstraints === "object") {
11245
11251
  this.constraints = calcRelativeConstraints(layout.layoutBox, dragConstraints);
11246
11252
  }
11247
11253
  else {
@@ -11308,6 +11314,30 @@
11308
11314
  }
11309
11315
  startAnimation(velocity, dragAxes) {
11310
11316
  const { drag, dragMomentum, dragElastic, dragTransition, dragSnapToOrigin, onDragTransitionEnd, } = this.getProps();
11317
+ /**
11318
+ * Overdamp the boundary spring if `dragElastic` is disabled. There's still a frame
11319
+ * of spring animations so we should look into adding a disable spring option to `inertia`.
11320
+ * We could do something here where we affect the `bounceStiffness` and `bounceDamping`
11321
+ * using the value of `dragElastic`.
11322
+ */
11323
+ const options = {
11324
+ bounceStiffness: dragElastic ? 200 : 1000000,
11325
+ bounceDamping: dragElastic ? 40 : 10000000,
11326
+ timeConstant: 750,
11327
+ restDelta: 1,
11328
+ restSpeed: 10,
11329
+ ...dragTransition,
11330
+ };
11331
+ const axisVelocity = (axis) => dragMomentum &&
11332
+ !(this.point && dragSnapToOrigin) &&
11333
+ shouldDrag(axis, dragAxes || drag, this.currentDirection)
11334
+ ? velocity[axis]
11335
+ : 0;
11336
+ if (this.point && !dragSnapToOrigin) {
11337
+ return this.point
11338
+ .release({ x: axisVelocity("x"), y: axisVelocity("y") }, options)
11339
+ .then(onDragTransitionEnd);
11340
+ }
11311
11341
  const constraints = this.constraints || {};
11312
11342
  const momentumAnimations = eachAxis((axis) => {
11313
11343
  if (!shouldDrag(axis, dragAxes || drag, this.currentDirection)) {
@@ -11317,23 +11347,10 @@
11317
11347
  if (dragSnapToOrigin === true ||
11318
11348
  dragSnapToOrigin === axis)
11319
11349
  transition = { min: 0, max: 0 };
11320
- /**
11321
- * Overdamp the boundary spring if `dragElastic` is disabled. There's still a frame
11322
- * of spring animations so we should look into adding a disable spring option to `inertia`.
11323
- * We could do something here where we affect the `bounceStiffness` and `bounceDamping`
11324
- * using the value of `dragElastic`.
11325
- */
11326
- const bounceStiffness = dragElastic ? 200 : 1000000;
11327
- const bounceDamping = dragElastic ? 40 : 10000000;
11328
11350
  const inertia = {
11329
11351
  type: "inertia",
11330
- velocity: dragMomentum ? velocity[axis] : 0,
11331
- bounceStiffness,
11332
- bounceDamping,
11333
- timeConstant: 750,
11334
- restDelta: 1,
11335
- restSpeed: 10,
11336
- ...dragTransition,
11352
+ velocity: axisVelocity(axis),
11353
+ ...options,
11337
11354
  ...transition,
11338
11355
  };
11339
11356
  // If we're not animating on an externally-provided `MotionValue` we can use the