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.
- package/dist/cjs/index.js +76 -37
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/NativeAnimation.mjs +8 -5
- package/dist/es/animation/NativeAnimation.mjs.map +1 -1
- package/dist/es/animation/NativeAnimationWrapper.mjs +2 -1
- package/dist/es/animation/NativeAnimationWrapper.mjs.map +1 -1
- package/dist/es/animation/waapi/transforms/TransformAnimation.mjs +16 -5
- package/dist/es/animation/waapi/transforms/TransformAnimation.mjs.map +1 -1
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +35 -19
- package/dist/es/gestures/drag/VisualElementDragControls.mjs.map +1 -1
- package/dist/es/gestures/drag/index.mjs.map +1 -1
- package/dist/es/projection/node/create-projection-node.mjs +7 -4
- package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
- package/dist/es/render/VisualElement.mjs +7 -2
- package/dist/es/render/VisualElement.mjs.map +1 -1
- package/dist/index.d.ts +1667 -1610
- package/dist/motion-dom.dev.js +76 -37
- package/dist/motion-dom.js +1 -1
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -2670,7 +2670,8 @@ class NativeAnimation extends WithPromise {
|
|
|
2670
2670
|
if (transition.autoplay === false) {
|
|
2671
2671
|
this.animation.pause();
|
|
2672
2672
|
}
|
|
2673
|
-
this.animation.onfinish = () => {
|
|
2673
|
+
this.animation.onfinish = this.onFinish = () => {
|
|
2674
|
+
this.animation.onfinish = null;
|
|
2674
2675
|
this.finishedTime = this.time;
|
|
2675
2676
|
if (!pseudoElement) {
|
|
2676
2677
|
const keyframe = getFinalKeyframe(keyframes, this.options, finalKeyframe, this.speed);
|
|
@@ -2694,6 +2695,7 @@ class NativeAnimation extends WithPromise {
|
|
|
2694
2695
|
if (this.isStopped)
|
|
2695
2696
|
return;
|
|
2696
2697
|
this.manualStartTime = null;
|
|
2698
|
+
this.animation.onfinish = this.onFinish;
|
|
2697
2699
|
this.animation.play();
|
|
2698
2700
|
if (this.state === "finished") {
|
|
2699
2701
|
this.updateFinished();
|
|
@@ -2703,9 +2705,12 @@ class NativeAnimation extends WithPromise {
|
|
|
2703
2705
|
this.animation.pause();
|
|
2704
2706
|
}
|
|
2705
2707
|
complete() {
|
|
2708
|
+
if (!this.isStopped)
|
|
2709
|
+
this.animation.onfinish = this.onFinish;
|
|
2706
2710
|
this.animation.finish?.();
|
|
2707
2711
|
}
|
|
2708
2712
|
cancel() {
|
|
2713
|
+
this.animation.onfinish = null;
|
|
2709
2714
|
try {
|
|
2710
2715
|
this.animation.cancel();
|
|
2711
2716
|
}
|
|
@@ -2729,10 +2734,8 @@ class NativeAnimation extends WithPromise {
|
|
|
2729
2734
|
else {
|
|
2730
2735
|
this.commitStyles();
|
|
2731
2736
|
}
|
|
2732
|
-
if (!this.isPseudoElement)
|
|
2733
|
-
this.animation.onfinish = null;
|
|
2737
|
+
if (!this.isPseudoElement)
|
|
2734
2738
|
this.cancel();
|
|
2735
|
-
}
|
|
2736
2739
|
}
|
|
2737
2740
|
/**
|
|
2738
2741
|
* WAAPI doesn't natively have any interruption capabilities.
|
|
@@ -2803,7 +2806,7 @@ class NativeAnimation extends WithPromise {
|
|
|
2803
2806
|
if (this.allowFlatten) {
|
|
2804
2807
|
this.animation.effect?.updateTiming({ easing: "linear" });
|
|
2805
2808
|
}
|
|
2806
|
-
this.animation.onfinish = null;
|
|
2809
|
+
this.animation.onfinish = this.onFinish = null;
|
|
2807
2810
|
if (timeline && supportsScrollTimeline()) {
|
|
2808
2811
|
this.animation.timeline = timeline;
|
|
2809
2812
|
onAttach?.(this.animation);
|
|
@@ -3438,13 +3441,15 @@ class TransformAnimation extends JSAnimation {
|
|
|
3438
3441
|
}
|
|
3439
3442
|
}
|
|
3440
3443
|
/**
|
|
3441
|
-
* JSAnimation finishes on its next tick, which only happens
|
|
3442
|
-
* main thread, so finish now.
|
|
3444
|
+
* JSAnimation finishes on its next tick, which only happens once the
|
|
3445
|
+
* group is on the main thread, so finish now. That includes an
|
|
3446
|
+
* animation that can't be accelerated but reached its end before the
|
|
3447
|
+
* group could move there.
|
|
3443
3448
|
*/
|
|
3444
3449
|
complete() {
|
|
3445
3450
|
super.complete();
|
|
3446
3451
|
const { group } = this;
|
|
3447
|
-
group && !group.isJS && this.
|
|
3452
|
+
group && !group.isJS && this.tick(time.now());
|
|
3448
3453
|
}
|
|
3449
3454
|
/**
|
|
3450
3455
|
* Without a tick to rebase it, a held time still includes the delay,
|
|
@@ -3547,13 +3552,22 @@ function createGroup(owner) {
|
|
|
3547
3552
|
const commit = (values = valuesAt()) => {
|
|
3548
3553
|
element.style.transform = toTransform(values, true);
|
|
3549
3554
|
};
|
|
3555
|
+
/**
|
|
3556
|
+
* Cancel a WAAPI animation and remove its handlers, as WebKit never
|
|
3557
|
+
* collects an animation once it has run, nor anything its handlers
|
|
3558
|
+
* reference (#4034).
|
|
3559
|
+
*/
|
|
3560
|
+
const cancel = (animation) => {
|
|
3561
|
+
animation.onfinish = animation.oncancel = null;
|
|
3562
|
+
animation.cancel();
|
|
3563
|
+
};
|
|
3550
3564
|
/**
|
|
3551
3565
|
* Cancel the WAAPI animations, by default first committing the
|
|
3552
3566
|
* transform. The renderer writes its own version on its next render.
|
|
3553
3567
|
*/
|
|
3554
3568
|
const stop = (shouldCommit = true) => {
|
|
3555
3569
|
shouldCommit && commit();
|
|
3556
|
-
segments.forEach(({ animation }) =>
|
|
3570
|
+
segments.forEach(({ animation }) => cancel(animation));
|
|
3557
3571
|
segments = [];
|
|
3558
3572
|
};
|
|
3559
3573
|
/**
|
|
@@ -3574,7 +3588,7 @@ function createGroup(owner) {
|
|
|
3574
3588
|
animation.onfinish = () => {
|
|
3575
3589
|
segment.isDone = true;
|
|
3576
3590
|
if (segments.some((s) => s.end === Infinity)) {
|
|
3577
|
-
|
|
3591
|
+
cancel(animation);
|
|
3578
3592
|
segments = segments.filter((s) => s !== segment);
|
|
3579
3593
|
}
|
|
3580
3594
|
group.schedule(false);
|
|
@@ -4360,7 +4374,8 @@ class NativeAnimationWrapper extends NativeAnimation {
|
|
|
4360
4374
|
constructor(animation) {
|
|
4361
4375
|
super();
|
|
4362
4376
|
this.animation = animation;
|
|
4363
|
-
animation.onfinish = () => {
|
|
4377
|
+
animation.onfinish = this.onFinish = () => {
|
|
4378
|
+
animation.onfinish = null;
|
|
4364
4379
|
this.finishedTime = this.time;
|
|
4365
4380
|
this.notifyFinished();
|
|
4366
4381
|
};
|
|
@@ -8965,12 +8980,15 @@ function notifyLayoutUpdate(node) {
|
|
|
8965
8980
|
let hasRelativeLayoutChanged = false;
|
|
8966
8981
|
const relativeParent = node.getClosestProjectingParent();
|
|
8967
8982
|
/**
|
|
8968
|
-
* A snapshot
|
|
8969
|
-
*
|
|
8983
|
+
* A snapshot from another element is only relative to this node's
|
|
8984
|
+
* relativeParent if it's a layoutRoot that contains both. A node can
|
|
8985
|
+
* hold one without resumeFrom, when the element it came from changed
|
|
8986
|
+
* layoutId but stayed mounted (see switchLayoutId), or a remix
|
|
8987
|
+
* layout exit cleared it (see markLayoutExit).
|
|
8970
8988
|
*/
|
|
8971
|
-
if (!
|
|
8989
|
+
if (!isShared ||
|
|
8972
8990
|
(relativeParent?.options.layoutRoot &&
|
|
8973
|
-
node.resumeFrom
|
|
8991
|
+
node.resumeFrom?.path.includes(relativeParent))) {
|
|
8974
8992
|
/**
|
|
8975
8993
|
* If the relativeParent is itself resuming from a different element then
|
|
8976
8994
|
* the relative snapshot is not relavent
|
|
@@ -9486,9 +9504,14 @@ class VisualElement {
|
|
|
9486
9504
|
/**
|
|
9487
9505
|
* If this element has been mounted before (e.g. after a Suspense
|
|
9488
9506
|
* unmount/remount), reset motion values to their initial state
|
|
9489
|
-
* so animations replay correctly from initial → animate
|
|
9490
|
-
|
|
9491
|
-
|
|
9507
|
+
* so animations replay correctly from initial → animate, unless
|
|
9508
|
+
* the presence asks to keep them or the element is only shown
|
|
9509
|
+
* again to exit (#4049).
|
|
9510
|
+
*/
|
|
9511
|
+
const presence = this.presenceContext;
|
|
9512
|
+
if (this.hasBeenMounted &&
|
|
9513
|
+
presence?.isPresent !== false &&
|
|
9514
|
+
!presence?.keepValuesOnRemount) {
|
|
9492
9515
|
for (const key in this.initialValues) {
|
|
9493
9516
|
this.values.get(key)?.jump(this.initialValues[key]);
|
|
9494
9517
|
this.latestValues[key] = this.initialValues[key];
|
|
@@ -11053,7 +11076,7 @@ class VisualElementDragControls {
|
|
|
11053
11076
|
};
|
|
11054
11077
|
const onStart = (event, info) => {
|
|
11055
11078
|
// Attempt to grab the global drag gesture lock - maybe make this part of PanSession
|
|
11056
|
-
const { drag, dragPropagation, onDragStart } = this.getProps();
|
|
11079
|
+
const { drag, dragConstraints, dragPropagation, onDragStart } = this.getProps();
|
|
11057
11080
|
if (drag && !dragPropagation) {
|
|
11058
11081
|
this.openDragLock?.();
|
|
11059
11082
|
this.openDragLock = setDragLock(drag);
|
|
@@ -11100,6 +11123,8 @@ class VisualElementDragControls {
|
|
|
11100
11123
|
}
|
|
11101
11124
|
this.originPoint[axis] = current;
|
|
11102
11125
|
});
|
|
11126
|
+
this.point =
|
|
11127
|
+
typeof dragConstraints === "function" && dragConstraints(this);
|
|
11103
11128
|
// Fire onDragStart event
|
|
11104
11129
|
if (onDragStart) {
|
|
11105
11130
|
frame.update(() => onDragStart(event, info), false, true);
|
|
@@ -11130,6 +11155,7 @@ class VisualElementDragControls {
|
|
|
11130
11155
|
// Update each point with the latest position
|
|
11131
11156
|
this.updateAxis("x", offset);
|
|
11132
11157
|
this.updateAxis("y", offset);
|
|
11158
|
+
this.point && this.point.move();
|
|
11133
11159
|
/**
|
|
11134
11160
|
* Ideally we would leave the renderer to fire naturally at the end of
|
|
11135
11161
|
* this frame but if the element is about to change layout as the result
|
|
@@ -11154,7 +11180,7 @@ class VisualElementDragControls {
|
|
|
11154
11180
|
};
|
|
11155
11181
|
const resumeAnimation = () => {
|
|
11156
11182
|
const { dragSnapToOrigin: snap } = this.getProps();
|
|
11157
|
-
if (snap || this.constraints) {
|
|
11183
|
+
if (snap || this.constraints || this.point) {
|
|
11158
11184
|
this.startAnimation({ x: 0, y: 0 });
|
|
11159
11185
|
}
|
|
11160
11186
|
};
|
|
@@ -11229,7 +11255,7 @@ class VisualElementDragControls {
|
|
|
11229
11255
|
if (constraints) {
|
|
11230
11256
|
next = applyConstraints(next, constraints, this.elastic[axis]);
|
|
11231
11257
|
}
|
|
11232
|
-
axisValue.set(next);
|
|
11258
|
+
this.point ? (this.point[axis] = next) : axisValue.set(next);
|
|
11233
11259
|
}
|
|
11234
11260
|
resolveConstraints() {
|
|
11235
11261
|
const { dragConstraints, dragElastic } = this.getProps();
|
|
@@ -11250,7 +11276,9 @@ class VisualElementDragControls {
|
|
|
11250
11276
|
}
|
|
11251
11277
|
}
|
|
11252
11278
|
else {
|
|
11253
|
-
if (dragConstraints &&
|
|
11279
|
+
if (dragConstraints &&
|
|
11280
|
+
layout &&
|
|
11281
|
+
typeof dragConstraints === "object") {
|
|
11254
11282
|
this.constraints = calcRelativeConstraints(layout.layoutBox, dragConstraints);
|
|
11255
11283
|
}
|
|
11256
11284
|
else {
|
|
@@ -11318,6 +11346,30 @@ class VisualElementDragControls {
|
|
|
11318
11346
|
}
|
|
11319
11347
|
startAnimation(velocity, dragAxes) {
|
|
11320
11348
|
const { drag, dragMomentum, dragElastic, dragTransition, dragSnapToOrigin, onDragTransitionEnd, } = this.getProps();
|
|
11349
|
+
/**
|
|
11350
|
+
* Overdamp the boundary spring if `dragElastic` is disabled. There's still a frame
|
|
11351
|
+
* of spring animations so we should look into adding a disable spring option to `inertia`.
|
|
11352
|
+
* We could do something here where we affect the `bounceStiffness` and `bounceDamping`
|
|
11353
|
+
* using the value of `dragElastic`.
|
|
11354
|
+
*/
|
|
11355
|
+
const options = {
|
|
11356
|
+
bounceStiffness: dragElastic ? 200 : 1000000,
|
|
11357
|
+
bounceDamping: dragElastic ? 40 : 10000000,
|
|
11358
|
+
timeConstant: 750,
|
|
11359
|
+
restDelta: 1,
|
|
11360
|
+
restSpeed: 10,
|
|
11361
|
+
...dragTransition,
|
|
11362
|
+
};
|
|
11363
|
+
const axisVelocity = (axis) => dragMomentum &&
|
|
11364
|
+
!(this.point && dragSnapToOrigin) &&
|
|
11365
|
+
shouldDrag(axis, dragAxes || drag, this.currentDirection)
|
|
11366
|
+
? velocity[axis]
|
|
11367
|
+
: 0;
|
|
11368
|
+
if (this.point && !dragSnapToOrigin) {
|
|
11369
|
+
return this.point
|
|
11370
|
+
.release({ x: axisVelocity("x"), y: axisVelocity("y") }, options)
|
|
11371
|
+
.then(onDragTransitionEnd);
|
|
11372
|
+
}
|
|
11321
11373
|
const constraints = this.constraints || {};
|
|
11322
11374
|
const momentumAnimations = eachAxis((axis) => {
|
|
11323
11375
|
if (!shouldDrag(axis, dragAxes || drag, this.currentDirection)) {
|
|
@@ -11327,23 +11379,10 @@ class VisualElementDragControls {
|
|
|
11327
11379
|
if (dragSnapToOrigin === true ||
|
|
11328
11380
|
dragSnapToOrigin === axis)
|
|
11329
11381
|
transition = { min: 0, max: 0 };
|
|
11330
|
-
/**
|
|
11331
|
-
* Overdamp the boundary spring if `dragElastic` is disabled. There's still a frame
|
|
11332
|
-
* of spring animations so we should look into adding a disable spring option to `inertia`.
|
|
11333
|
-
* We could do something here where we affect the `bounceStiffness` and `bounceDamping`
|
|
11334
|
-
* using the value of `dragElastic`.
|
|
11335
|
-
*/
|
|
11336
|
-
const bounceStiffness = dragElastic ? 200 : 1000000;
|
|
11337
|
-
const bounceDamping = dragElastic ? 40 : 10000000;
|
|
11338
11382
|
const inertia = {
|
|
11339
11383
|
type: "inertia",
|
|
11340
|
-
velocity:
|
|
11341
|
-
|
|
11342
|
-
bounceDamping,
|
|
11343
|
-
timeConstant: 750,
|
|
11344
|
-
restDelta: 1,
|
|
11345
|
-
restSpeed: 10,
|
|
11346
|
-
...dragTransition,
|
|
11384
|
+
velocity: axisVelocity(axis),
|
|
11385
|
+
...options,
|
|
11347
11386
|
...transition,
|
|
11348
11387
|
};
|
|
11349
11388
|
// If we're not animating on an externally-provided `MotionValue` we can use the
|