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.
- package/dist/cjs/index.js +38 -21
- package/dist/cjs/index.js.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/render/VisualElement.mjs +3 -2
- package/dist/es/render/VisualElement.mjs.map +1 -1
- package/dist/index.d.ts +1660 -1609
- package/dist/motion-dom.dev.js +38 -21
- package/dist/motion-dom.js +1 -1
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -9486,9 +9486,10 @@ class VisualElement {
|
|
|
9486
9486
|
/**
|
|
9487
9487
|
* If this element has been mounted before (e.g. after a Suspense
|
|
9488
9488
|
* unmount/remount), reset motion values to their initial state
|
|
9489
|
-
* so animations replay correctly from initial → animate
|
|
9489
|
+
* so animations replay correctly from initial → animate, unless
|
|
9490
|
+
* the presence asks to keep them.
|
|
9490
9491
|
*/
|
|
9491
|
-
if (this.hasBeenMounted) {
|
|
9492
|
+
if (this.hasBeenMounted && !this.presenceContext?.keepValuesOnRemount) {
|
|
9492
9493
|
for (const key in this.initialValues) {
|
|
9493
9494
|
this.values.get(key)?.jump(this.initialValues[key]);
|
|
9494
9495
|
this.latestValues[key] = this.initialValues[key];
|
|
@@ -11053,7 +11054,7 @@ class VisualElementDragControls {
|
|
|
11053
11054
|
};
|
|
11054
11055
|
const onStart = (event, info) => {
|
|
11055
11056
|
// Attempt to grab the global drag gesture lock - maybe make this part of PanSession
|
|
11056
|
-
const { drag, dragPropagation, onDragStart } = this.getProps();
|
|
11057
|
+
const { drag, dragConstraints, dragPropagation, onDragStart } = this.getProps();
|
|
11057
11058
|
if (drag && !dragPropagation) {
|
|
11058
11059
|
this.openDragLock?.();
|
|
11059
11060
|
this.openDragLock = setDragLock(drag);
|
|
@@ -11100,6 +11101,8 @@ class VisualElementDragControls {
|
|
|
11100
11101
|
}
|
|
11101
11102
|
this.originPoint[axis] = current;
|
|
11102
11103
|
});
|
|
11104
|
+
this.point =
|
|
11105
|
+
typeof dragConstraints === "function" && dragConstraints(this);
|
|
11103
11106
|
// Fire onDragStart event
|
|
11104
11107
|
if (onDragStart) {
|
|
11105
11108
|
frame.update(() => onDragStart(event, info), false, true);
|
|
@@ -11130,6 +11133,7 @@ class VisualElementDragControls {
|
|
|
11130
11133
|
// Update each point with the latest position
|
|
11131
11134
|
this.updateAxis("x", offset);
|
|
11132
11135
|
this.updateAxis("y", offset);
|
|
11136
|
+
this.point && this.point.move();
|
|
11133
11137
|
/**
|
|
11134
11138
|
* Ideally we would leave the renderer to fire naturally at the end of
|
|
11135
11139
|
* this frame but if the element is about to change layout as the result
|
|
@@ -11154,7 +11158,7 @@ class VisualElementDragControls {
|
|
|
11154
11158
|
};
|
|
11155
11159
|
const resumeAnimation = () => {
|
|
11156
11160
|
const { dragSnapToOrigin: snap } = this.getProps();
|
|
11157
|
-
if (snap || this.constraints) {
|
|
11161
|
+
if (snap || this.constraints || this.point) {
|
|
11158
11162
|
this.startAnimation({ x: 0, y: 0 });
|
|
11159
11163
|
}
|
|
11160
11164
|
};
|
|
@@ -11229,7 +11233,7 @@ class VisualElementDragControls {
|
|
|
11229
11233
|
if (constraints) {
|
|
11230
11234
|
next = applyConstraints(next, constraints, this.elastic[axis]);
|
|
11231
11235
|
}
|
|
11232
|
-
axisValue.set(next);
|
|
11236
|
+
this.point ? (this.point[axis] = next) : axisValue.set(next);
|
|
11233
11237
|
}
|
|
11234
11238
|
resolveConstraints() {
|
|
11235
11239
|
const { dragConstraints, dragElastic } = this.getProps();
|
|
@@ -11250,7 +11254,9 @@ class VisualElementDragControls {
|
|
|
11250
11254
|
}
|
|
11251
11255
|
}
|
|
11252
11256
|
else {
|
|
11253
|
-
if (dragConstraints &&
|
|
11257
|
+
if (dragConstraints &&
|
|
11258
|
+
layout &&
|
|
11259
|
+
typeof dragConstraints === "object") {
|
|
11254
11260
|
this.constraints = calcRelativeConstraints(layout.layoutBox, dragConstraints);
|
|
11255
11261
|
}
|
|
11256
11262
|
else {
|
|
@@ -11318,6 +11324,30 @@ class VisualElementDragControls {
|
|
|
11318
11324
|
}
|
|
11319
11325
|
startAnimation(velocity, dragAxes) {
|
|
11320
11326
|
const { drag, dragMomentum, dragElastic, dragTransition, dragSnapToOrigin, onDragTransitionEnd, } = this.getProps();
|
|
11327
|
+
/**
|
|
11328
|
+
* Overdamp the boundary spring if `dragElastic` is disabled. There's still a frame
|
|
11329
|
+
* of spring animations so we should look into adding a disable spring option to `inertia`.
|
|
11330
|
+
* We could do something here where we affect the `bounceStiffness` and `bounceDamping`
|
|
11331
|
+
* using the value of `dragElastic`.
|
|
11332
|
+
*/
|
|
11333
|
+
const options = {
|
|
11334
|
+
bounceStiffness: dragElastic ? 200 : 1000000,
|
|
11335
|
+
bounceDamping: dragElastic ? 40 : 10000000,
|
|
11336
|
+
timeConstant: 750,
|
|
11337
|
+
restDelta: 1,
|
|
11338
|
+
restSpeed: 10,
|
|
11339
|
+
...dragTransition,
|
|
11340
|
+
};
|
|
11341
|
+
const axisVelocity = (axis) => dragMomentum &&
|
|
11342
|
+
!(this.point && dragSnapToOrigin) &&
|
|
11343
|
+
shouldDrag(axis, dragAxes || drag, this.currentDirection)
|
|
11344
|
+
? velocity[axis]
|
|
11345
|
+
: 0;
|
|
11346
|
+
if (this.point && !dragSnapToOrigin) {
|
|
11347
|
+
return this.point
|
|
11348
|
+
.release({ x: axisVelocity("x"), y: axisVelocity("y") }, options)
|
|
11349
|
+
.then(onDragTransitionEnd);
|
|
11350
|
+
}
|
|
11321
11351
|
const constraints = this.constraints || {};
|
|
11322
11352
|
const momentumAnimations = eachAxis((axis) => {
|
|
11323
11353
|
if (!shouldDrag(axis, dragAxes || drag, this.currentDirection)) {
|
|
@@ -11327,23 +11357,10 @@ class VisualElementDragControls {
|
|
|
11327
11357
|
if (dragSnapToOrigin === true ||
|
|
11328
11358
|
dragSnapToOrigin === axis)
|
|
11329
11359
|
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
11360
|
const inertia = {
|
|
11339
11361
|
type: "inertia",
|
|
11340
|
-
velocity:
|
|
11341
|
-
|
|
11342
|
-
bounceDamping,
|
|
11343
|
-
timeConstant: 750,
|
|
11344
|
-
restDelta: 1,
|
|
11345
|
-
restSpeed: 10,
|
|
11346
|
-
...dragTransition,
|
|
11362
|
+
velocity: axisVelocity(axis),
|
|
11363
|
+
...options,
|
|
11347
11364
|
...transition,
|
|
11348
11365
|
};
|
|
11349
11366
|
// If we're not animating on an externally-provided `MotionValue` we can use the
|