motion-dom 13.4.2 → 13.4.4
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 +61 -28
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/GroupAnimation.mjs +1 -1
- package/dist/es/animation/GroupAnimation.mjs.map +1 -1
- package/dist/es/animation/generators/spring.mjs +53 -20
- package/dist/es/animation/generators/spring.mjs.map +1 -1
- package/dist/es/gestures/hover.mjs +1 -1
- package/dist/es/gestures/hover.mjs.map +1 -1
- package/dist/es/projection/geometry/delta-apply.mjs +1 -1
- package/dist/es/projection/geometry/delta-apply.mjs.map +1 -1
- package/dist/es/projection/node/create-projection-node.mjs +2 -2
- package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
- package/dist/es/render/VisualElement.mjs.map +1 -1
- package/dist/es/render/dom/DOMVisualElement.mjs +1 -1
- package/dist/es/render/dom/DOMVisualElement.mjs.map +1 -1
- package/dist/es/render/utils/animation-state.mjs +1 -1
- package/dist/es/render/utils/animation-state.mjs.map +1 -1
- package/dist/es/view/queue.mjs +1 -1
- package/dist/es/view/queue.mjs.map +1 -1
- package/dist/index.d.ts +9 -9
- package/dist/motion-dom.dev.js +61 -28
- package/dist/motion-dom.js +1 -1
- package/package.json +2 -2
package/dist/motion-dom.dev.js
CHANGED
|
@@ -919,22 +919,50 @@
|
|
|
919
919
|
}
|
|
920
920
|
}
|
|
921
921
|
const durationKeys = ["duration", "bounce"];
|
|
922
|
-
const physicsKeys = ["stiffness", "damping", "mass"];
|
|
923
922
|
function isSpringType(options, keys) {
|
|
924
923
|
return keys.some((key) => options[key] !== undefined);
|
|
925
924
|
}
|
|
925
|
+
/**
|
|
926
|
+
* Spring physics must be finite. stiffness and mass are also divisors so must
|
|
927
|
+
* be positive, whereas a damping of 0 is a valid, perpetually oscillating
|
|
928
|
+
* spring. Relational rather than Number.isFinite so numeric strings still
|
|
929
|
+
* coerce.
|
|
930
|
+
*/
|
|
931
|
+
const isValidPhysics = (value, canBeZero) => (canBeZero ? value >= 0 : value > 0) && value < Infinity;
|
|
932
|
+
/**
|
|
933
|
+
* Returns value if it's usable spring physics, otherwise undefined so callers
|
|
934
|
+
* fall back to the default. An explicit `undefined`, e.g. from a forwarded
|
|
935
|
+
* optional prop, must fall back too. Invalid physics would otherwise resolve
|
|
936
|
+
* to NaN spring values that never report done.
|
|
937
|
+
*/
|
|
938
|
+
function resolvePhysics(value, canBeZero) {
|
|
939
|
+
if (isValidPhysics(value, canBeZero))
|
|
940
|
+
return value;
|
|
941
|
+
{
|
|
942
|
+
motionUtils.warning(value === undefined, "Spring stiffness and mass must be positive, damping 0 or greater", "spring-invalid-physics");
|
|
943
|
+
}
|
|
944
|
+
return undefined;
|
|
945
|
+
}
|
|
926
946
|
function getSpringOptions(options) {
|
|
947
|
+
/**
|
|
948
|
+
* Resolve physics before choosing between physics- and duration-based
|
|
949
|
+
* resolution, so an invalid stiffness doesn't also silently discard a
|
|
950
|
+
* valid duration/bounce.
|
|
951
|
+
*/
|
|
952
|
+
const validStiffness = resolvePhysics(options.stiffness);
|
|
953
|
+
const validDamping = resolvePhysics(options.damping, true);
|
|
954
|
+
const validMass = resolvePhysics(options.mass);
|
|
927
955
|
let springOptions = {
|
|
928
|
-
velocity: springDefaults.velocity,
|
|
929
|
-
stiffness: springDefaults.stiffness,
|
|
930
|
-
damping: springDefaults.damping,
|
|
931
|
-
mass: springDefaults.mass,
|
|
932
|
-
isResolvedFromDuration: false,
|
|
933
956
|
...options,
|
|
957
|
+
stiffness: validStiffness ?? springDefaults.stiffness,
|
|
958
|
+
damping: validDamping ?? springDefaults.damping,
|
|
959
|
+
mass: validMass ?? springDefaults.mass,
|
|
960
|
+
isResolvedFromDuration: false,
|
|
961
|
+
// stiffness/damping/mass overrides duration/bounce
|
|
962
|
+
isTimeDefined: (validStiffness ?? validDamping ?? validMass) === undefined &&
|
|
963
|
+
isSpringType(options, durationKeys),
|
|
934
964
|
};
|
|
935
|
-
|
|
936
|
-
if (!isSpringType(options, physicsKeys) &&
|
|
937
|
-
isSpringType(options, durationKeys)) {
|
|
965
|
+
if (springOptions.isTimeDefined) {
|
|
938
966
|
// Time-defined springs should ignore inherited velocity.
|
|
939
967
|
// Velocity from interrupted animations can cause findSpring()
|
|
940
968
|
// to compute wildly different spring parameters, leading to
|
|
@@ -955,7 +983,7 @@
|
|
|
955
983
|
};
|
|
956
984
|
}
|
|
957
985
|
else {
|
|
958
|
-
const derived = findSpring(
|
|
986
|
+
const derived = findSpring(springOptions);
|
|
959
987
|
springOptions = {
|
|
960
988
|
...springOptions,
|
|
961
989
|
...derived,
|
|
@@ -963,6 +991,17 @@
|
|
|
963
991
|
};
|
|
964
992
|
springOptions.isResolvedFromDuration = true;
|
|
965
993
|
}
|
|
994
|
+
/**
|
|
995
|
+
* Non-finite time options degenerate: a NaN bounce gives a NaN
|
|
996
|
+
* damping, an infinite visualDuration a 0 stiffness. Replace the two
|
|
997
|
+
* together, so the relationship duration resolution establishes
|
|
998
|
+
* between them is never left half-overwritten.
|
|
999
|
+
*/
|
|
1000
|
+
if (!isValidPhysics(springOptions.stiffness) ||
|
|
1001
|
+
!isValidPhysics(springOptions.damping, true)) {
|
|
1002
|
+
springOptions.stiffness = springDefaults.stiffness;
|
|
1003
|
+
springOptions.damping = springDefaults.damping;
|
|
1004
|
+
}
|
|
966
1005
|
}
|
|
967
1006
|
return springOptions;
|
|
968
1007
|
}
|
|
@@ -981,7 +1020,7 @@
|
|
|
981
1020
|
* to reduce GC during animation.
|
|
982
1021
|
*/
|
|
983
1022
|
const state = { done: false, value: origin };
|
|
984
|
-
const { stiffness, damping, mass, duration, velocity, isResolvedFromDuration, } = getSpringOptions({
|
|
1023
|
+
const { stiffness, damping, mass, duration, velocity, isResolvedFromDuration, isTimeDefined, } = getSpringOptions({
|
|
985
1024
|
...options,
|
|
986
1025
|
velocity: -motionUtils.millisecondsToSeconds(options.velocity || 0),
|
|
987
1026
|
});
|
|
@@ -1006,7 +1045,7 @@
|
|
|
1006
1045
|
* If we're working on a granular scale, use smaller defaults for determining
|
|
1007
1046
|
* when the spring is finished.
|
|
1008
1047
|
*
|
|
1009
|
-
* These defaults have been selected
|
|
1048
|
+
* These defaults have been selected empirically based on what strikes a good
|
|
1010
1049
|
* ratio between feeling good and finishing as soon as changes are imperceptible.
|
|
1011
1050
|
*/
|
|
1012
1051
|
const setRestThresholds = () => {
|
|
@@ -1104,11 +1143,6 @@
|
|
|
1104
1143
|
};
|
|
1105
1144
|
}
|
|
1106
1145
|
update();
|
|
1107
|
-
/**
|
|
1108
|
-
* Time-defined springs ignore inherited velocity, see getSpringOptions.
|
|
1109
|
-
*/
|
|
1110
|
-
const ignoreVelocity = !isSpringType(options, physicsKeys) &&
|
|
1111
|
-
isSpringType(options, durationKeys);
|
|
1112
1146
|
const calculatedDuration = isResolvedFromDuration ? duration || null : null;
|
|
1113
1147
|
const generator = {
|
|
1114
1148
|
calculatedDuration,
|
|
@@ -1119,9 +1153,8 @@
|
|
|
1119
1153
|
retarget: (keyframes, newVelocity) => {
|
|
1120
1154
|
s.target = keyframes[keyframes.length - 1];
|
|
1121
1155
|
s.delta = s.target - keyframes[0];
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
: -motionUtils.millisecondsToSeconds(newVelocity);
|
|
1156
|
+
// Time-defined springs ignore inherited velocity, see getSpringOptions
|
|
1157
|
+
s.velocity = isTimeDefined ? 0 : -motionUtils.millisecondsToSeconds(newVelocity);
|
|
1125
1158
|
// Default thresholds depend on the scale of the new delta
|
|
1126
1159
|
if (!(options.restSpeed && options.restDelta))
|
|
1127
1160
|
setRestThresholds();
|
|
@@ -3139,7 +3172,7 @@
|
|
|
3139
3172
|
|
|
3140
3173
|
class GroupAnimation {
|
|
3141
3174
|
constructor(animations) {
|
|
3142
|
-
// Bound to
|
|
3175
|
+
// Bound to accommodate common `return animation.stop` pattern
|
|
3143
3176
|
this.stop = () => this.runAll("stop");
|
|
3144
3177
|
this.animations = animations.filter(Boolean);
|
|
3145
3178
|
}
|
|
@@ -5471,7 +5504,7 @@
|
|
|
5471
5504
|
translateAxis(box.y, -node.scroll.offset.y);
|
|
5472
5505
|
}
|
|
5473
5506
|
if (delta) {
|
|
5474
|
-
//
|
|
5507
|
+
// Incorporate each ancestor's scale into a cumulative treeScale for this component
|
|
5475
5508
|
treeScale.x *= delta.x.scale;
|
|
5476
5509
|
treeScale.y *= delta.y.scale;
|
|
5477
5510
|
// Apply each ancestor's calculated delta into this component's recorded layout box
|
|
@@ -5679,7 +5712,7 @@
|
|
|
5679
5712
|
/**
|
|
5680
5713
|
* Create a hover gesture. hover() is different to .addEventListener("pointerenter")
|
|
5681
5714
|
* in that it has an easier syntax, filters out polyfilled touch events, interoperates
|
|
5682
|
-
* with drag gestures, and automatically removes the "
|
|
5715
|
+
* with drag gestures, and automatically removes the "pointerleave" event listener when the hover ends.
|
|
5683
5716
|
*
|
|
5684
5717
|
* @public
|
|
5685
5718
|
*/
|
|
@@ -7415,7 +7448,7 @@
|
|
|
7415
7448
|
/**
|
|
7416
7449
|
* Iterate backwards over the builders array. We can ignore the
|
|
7417
7450
|
* "wait" animations. If we have an interrupting animation in the
|
|
7418
|
-
* queue then we need to batch all
|
|
7451
|
+
* queue then we need to batch all preceding animations into it.
|
|
7419
7452
|
* Currently this only batches the update functions but will also
|
|
7420
7453
|
* need to batch the targets.
|
|
7421
7454
|
*/
|
|
@@ -8295,7 +8328,7 @@
|
|
|
8295
8328
|
/**
|
|
8296
8329
|
* compareDocumentPosition returns a bitmask, by using the bitwise &
|
|
8297
8330
|
* we're returning true if 2 in that bitmask is set to true. 2 is set
|
|
8298
|
-
* to true if b
|
|
8331
|
+
* to true if b precedes a.
|
|
8299
8332
|
*/
|
|
8300
8333
|
return a.compareDocumentPosition(b) & 2 ? 1 : -1;
|
|
8301
8334
|
}
|
|
@@ -8787,7 +8820,7 @@
|
|
|
8787
8820
|
}
|
|
8788
8821
|
/**
|
|
8789
8822
|
* Set all encountered keys so far as the protected keys for this type. This will
|
|
8790
|
-
* be any key that has been animated or otherwise handled by active, higher-
|
|
8823
|
+
* be any key that has been animated or otherwise handled by active, higher-priority types.
|
|
8791
8824
|
*/
|
|
8792
8825
|
typeState.protectedKeys = { ...encounteredKeys };
|
|
8793
8826
|
// Check if we can skip analysing this prop early
|
|
@@ -9612,8 +9645,8 @@
|
|
|
9612
9645
|
this.hasCheckedOptimisedAppear = false;
|
|
9613
9646
|
/**
|
|
9614
9647
|
* An object representing the calculated contextual/accumulated/tree scale.
|
|
9615
|
-
* This will be used to scale
|
|
9616
|
-
* calculated in screen-space but need to be scaled for elements to
|
|
9648
|
+
* This will be used to scale calculated projection transforms, as these are
|
|
9649
|
+
* calculated in screen-space but need to be scaled for elements to visually
|
|
9617
9650
|
* make it to their calculated destinations.
|
|
9618
9651
|
*
|
|
9619
9652
|
* TODO: Lazy-init
|