motion-dom 14.8.0 → 14.9.1

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.
@@ -2665,7 +2665,8 @@
2665
2665
  if (transition.autoplay === false) {
2666
2666
  this.animation.pause();
2667
2667
  }
2668
- this.animation.onfinish = () => {
2668
+ this.animation.onfinish = this.onFinish = () => {
2669
+ this.animation.onfinish = null;
2669
2670
  this.finishedTime = this.time;
2670
2671
  if (!pseudoElement) {
2671
2672
  const keyframe = getFinalKeyframe(keyframes, this.options, finalKeyframe, this.speed);
@@ -2689,6 +2690,7 @@
2689
2690
  if (this.isStopped)
2690
2691
  return;
2691
2692
  this.manualStartTime = null;
2693
+ this.animation.onfinish = this.onFinish;
2692
2694
  this.animation.play();
2693
2695
  if (this.state === "finished") {
2694
2696
  this.updateFinished();
@@ -2698,9 +2700,12 @@
2698
2700
  this.animation.pause();
2699
2701
  }
2700
2702
  complete() {
2703
+ if (!this.isStopped)
2704
+ this.animation.onfinish = this.onFinish;
2701
2705
  this.animation.finish?.();
2702
2706
  }
2703
2707
  cancel() {
2708
+ this.animation.onfinish = null;
2704
2709
  try {
2705
2710
  this.animation.cancel();
2706
2711
  }
@@ -2724,10 +2729,8 @@
2724
2729
  else {
2725
2730
  this.commitStyles();
2726
2731
  }
2727
- if (!this.isPseudoElement) {
2728
- this.animation.onfinish = null;
2732
+ if (!this.isPseudoElement)
2729
2733
  this.cancel();
2730
- }
2731
2734
  }
2732
2735
  /**
2733
2736
  * WAAPI doesn't natively have any interruption capabilities.
@@ -2798,7 +2801,7 @@
2798
2801
  if (this.allowFlatten) {
2799
2802
  this.animation.effect?.updateTiming({ easing: "linear" });
2800
2803
  }
2801
- this.animation.onfinish = null;
2804
+ this.animation.onfinish = this.onFinish = null;
2802
2805
  if (timeline && supportsScrollTimeline()) {
2803
2806
  this.animation.timeline = timeline;
2804
2807
  onAttach?.(this.animation);
@@ -3433,13 +3436,15 @@
3433
3436
  }
3434
3437
  }
3435
3438
  /**
3436
- * JSAnimation finishes on its next tick, which only happens on the
3437
- * main thread, so finish now.
3439
+ * JSAnimation finishes on its next tick, which only happens once the
3440
+ * group is on the main thread, so finish now. That includes an
3441
+ * animation that can't be accelerated but reached its end before the
3442
+ * group could move there.
3438
3443
  */
3439
3444
  complete() {
3440
3445
  super.complete();
3441
3446
  const { group } = this;
3442
- group && !group.isJS && this.canAccelerate && this.tick(time.now());
3447
+ group && !group.isJS && this.tick(time.now());
3443
3448
  }
3444
3449
  /**
3445
3450
  * Without a tick to rebase it, a held time still includes the delay,
@@ -3542,13 +3547,22 @@
3542
3547
  const commit = (values = valuesAt()) => {
3543
3548
  element.style.transform = toTransform(values, true);
3544
3549
  };
3550
+ /**
3551
+ * Cancel a WAAPI animation and remove its handlers, as WebKit never
3552
+ * collects an animation once it has run, nor anything its handlers
3553
+ * reference (#4034).
3554
+ */
3555
+ const cancel = (animation) => {
3556
+ animation.onfinish = animation.oncancel = null;
3557
+ animation.cancel();
3558
+ };
3545
3559
  /**
3546
3560
  * Cancel the WAAPI animations, by default first committing the
3547
3561
  * transform. The renderer writes its own version on its next render.
3548
3562
  */
3549
3563
  const stop = (shouldCommit = true) => {
3550
3564
  shouldCommit && commit();
3551
- segments.forEach(({ animation }) => animation.cancel());
3565
+ segments.forEach(({ animation }) => cancel(animation));
3552
3566
  segments = [];
3553
3567
  };
3554
3568
  /**
@@ -3569,7 +3583,7 @@
3569
3583
  animation.onfinish = () => {
3570
3584
  segment.isDone = true;
3571
3585
  if (segments.some((s) => s.end === Infinity)) {
3572
- animation.cancel();
3586
+ cancel(animation);
3573
3587
  segments = segments.filter((s) => s !== segment);
3574
3588
  }
3575
3589
  group.schedule(false);
@@ -4355,7 +4369,8 @@
4355
4369
  constructor(animation) {
4356
4370
  super();
4357
4371
  this.animation = animation;
4358
- animation.onfinish = () => {
4372
+ animation.onfinish = this.onFinish = () => {
4373
+ animation.onfinish = null;
4359
4374
  this.finishedTime = this.time;
4360
4375
  this.notifyFinished();
4361
4376
  };
@@ -8957,12 +8972,15 @@
8957
8972
  let hasRelativeLayoutChanged = false;
8958
8973
  const relativeParent = node.getClosestProjectingParent();
8959
8974
  /**
8960
- * A snapshot resumed from another element is only relative to this
8961
- * node's relativeParent if it's a layoutRoot that contains both.
8975
+ * A snapshot from another element is only relative to this node's
8976
+ * relativeParent if it's a layoutRoot that contains both. A node can
8977
+ * hold one without resumeFrom, when the element it came from changed
8978
+ * layoutId but stayed mounted (see switchLayoutId), or a remix
8979
+ * layout exit cleared it (see markLayoutExit).
8962
8980
  */
8963
- if (!node.resumeFrom ||
8981
+ if (!isShared ||
8964
8982
  (relativeParent?.options.layoutRoot &&
8965
- node.resumeFrom.path.includes(relativeParent))) {
8983
+ node.resumeFrom?.path.includes(relativeParent))) {
8966
8984
  /**
8967
8985
  * If the relativeParent is itself resuming from a different element then
8968
8986
  * the relative snapshot is not relavent
@@ -9478,9 +9496,14 @@
9478
9496
  /**
9479
9497
  * If this element has been mounted before (e.g. after a Suspense
9480
9498
  * unmount/remount), reset motion values to their initial state
9481
- * so animations replay correctly from initial → animate.
9482
- */
9483
- if (this.hasBeenMounted) {
9499
+ * so animations replay correctly from initial → animate, unless
9500
+ * the presence asks to keep them or the element is only shown
9501
+ * again to exit (#4049).
9502
+ */
9503
+ const presence = this.presenceContext;
9504
+ if (this.hasBeenMounted &&
9505
+ presence?.isPresent !== false &&
9506
+ !presence?.keepValuesOnRemount) {
9484
9507
  for (const key in this.initialValues) {
9485
9508
  this.values.get(key)?.jump(this.initialValues[key]);
9486
9509
  this.latestValues[key] = this.initialValues[key];
@@ -11044,7 +11067,7 @@
11044
11067
  };
11045
11068
  const onStart = (event, info) => {
11046
11069
  // Attempt to grab the global drag gesture lock - maybe make this part of PanSession
11047
- const { drag, dragPropagation, onDragStart } = this.getProps();
11070
+ const { drag, dragConstraints, dragPropagation, onDragStart } = this.getProps();
11048
11071
  if (drag && !dragPropagation) {
11049
11072
  this.openDragLock?.();
11050
11073
  this.openDragLock = setDragLock(drag);
@@ -11091,6 +11114,8 @@
11091
11114
  }
11092
11115
  this.originPoint[axis] = current;
11093
11116
  });
11117
+ this.point =
11118
+ typeof dragConstraints === "function" && dragConstraints(this);
11094
11119
  // Fire onDragStart event
11095
11120
  if (onDragStart) {
11096
11121
  frame.update(() => onDragStart(event, info), false, true);
@@ -11121,6 +11146,7 @@
11121
11146
  // Update each point with the latest position
11122
11147
  this.updateAxis("x", offset);
11123
11148
  this.updateAxis("y", offset);
11149
+ this.point && this.point.move();
11124
11150
  /**
11125
11151
  * Ideally we would leave the renderer to fire naturally at the end of
11126
11152
  * this frame but if the element is about to change layout as the result
@@ -11145,7 +11171,7 @@
11145
11171
  };
11146
11172
  const resumeAnimation = () => {
11147
11173
  const { dragSnapToOrigin: snap } = this.getProps();
11148
- if (snap || this.constraints) {
11174
+ if (snap || this.constraints || this.point) {
11149
11175
  this.startAnimation({ x: 0, y: 0 });
11150
11176
  }
11151
11177
  };
@@ -11220,7 +11246,7 @@
11220
11246
  if (constraints) {
11221
11247
  next = applyConstraints(next, constraints, this.elastic[axis]);
11222
11248
  }
11223
- axisValue.set(next);
11249
+ this.point ? (this.point[axis] = next) : axisValue.set(next);
11224
11250
  }
11225
11251
  resolveConstraints() {
11226
11252
  const { dragConstraints, dragElastic } = this.getProps();
@@ -11241,7 +11267,9 @@
11241
11267
  }
11242
11268
  }
11243
11269
  else {
11244
- if (dragConstraints && layout) {
11270
+ if (dragConstraints &&
11271
+ layout &&
11272
+ typeof dragConstraints === "object") {
11245
11273
  this.constraints = calcRelativeConstraints(layout.layoutBox, dragConstraints);
11246
11274
  }
11247
11275
  else {
@@ -11308,6 +11336,30 @@
11308
11336
  }
11309
11337
  startAnimation(velocity, dragAxes) {
11310
11338
  const { drag, dragMomentum, dragElastic, dragTransition, dragSnapToOrigin, onDragTransitionEnd, } = this.getProps();
11339
+ /**
11340
+ * Overdamp the boundary spring if `dragElastic` is disabled. There's still a frame
11341
+ * of spring animations so we should look into adding a disable spring option to `inertia`.
11342
+ * We could do something here where we affect the `bounceStiffness` and `bounceDamping`
11343
+ * using the value of `dragElastic`.
11344
+ */
11345
+ const options = {
11346
+ bounceStiffness: dragElastic ? 200 : 1000000,
11347
+ bounceDamping: dragElastic ? 40 : 10000000,
11348
+ timeConstant: 750,
11349
+ restDelta: 1,
11350
+ restSpeed: 10,
11351
+ ...dragTransition,
11352
+ };
11353
+ const axisVelocity = (axis) => dragMomentum &&
11354
+ !(this.point && dragSnapToOrigin) &&
11355
+ shouldDrag(axis, dragAxes || drag, this.currentDirection)
11356
+ ? velocity[axis]
11357
+ : 0;
11358
+ if (this.point && !dragSnapToOrigin) {
11359
+ return this.point
11360
+ .release({ x: axisVelocity("x"), y: axisVelocity("y") }, options)
11361
+ .then(onDragTransitionEnd);
11362
+ }
11311
11363
  const constraints = this.constraints || {};
11312
11364
  const momentumAnimations = eachAxis((axis) => {
11313
11365
  if (!shouldDrag(axis, dragAxes || drag, this.currentDirection)) {
@@ -11317,23 +11369,10 @@
11317
11369
  if (dragSnapToOrigin === true ||
11318
11370
  dragSnapToOrigin === axis)
11319
11371
  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
11372
  const inertia = {
11329
11373
  type: "inertia",
11330
- velocity: dragMomentum ? velocity[axis] : 0,
11331
- bounceStiffness,
11332
- bounceDamping,
11333
- timeConstant: 750,
11334
- restDelta: 1,
11335
- restSpeed: 10,
11336
- ...dragTransition,
11374
+ velocity: axisVelocity(axis),
11375
+ ...options,
11337
11376
  ...transition,
11338
11377
  };
11339
11378
  // If we're not animating on an externally-provided `MotionValue` we can use the