motion-dom 13.4.1 → 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 +62 -29
- 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/keyframes.mjs +1 -1
- package/dist/es/animation/generators/keyframes.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 +62 -29
- package/dist/motion-dom.js +1 -1
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -919,22 +919,50 @@ function findSpring({ duration = springDefaults.duration, bounce = springDefault
|
|
|
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
|
+
if (process.env.NODE_ENV !== "production") {
|
|
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 @@ function getSpringOptions(options) {
|
|
|
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 @@ function getSpringOptions(options) {
|
|
|
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 @@ function spring(optionsOrVisualDuration = springDefaults.visualDuration, bounce
|
|
|
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 @@ function spring(optionsOrVisualDuration = springDefaults.visualDuration, bounce
|
|
|
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 @@ function spring(optionsOrVisualDuration = springDefaults.visualDuration, bounce
|
|
|
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 @@ function spring(optionsOrVisualDuration = springDefaults.visualDuration, bounce
|
|
|
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();
|
|
@@ -1346,7 +1379,7 @@ function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "e
|
|
|
1346
1379
|
*/
|
|
1347
1380
|
const easingFunctions = motionUtils.isEasingArray(ease)
|
|
1348
1381
|
? ease.map(motionUtils.easingDefinitionToFunction)
|
|
1349
|
-
: motionUtils.easingDefinitionToFunction(ease);
|
|
1382
|
+
: motionUtils.easingDefinitionToFunction(ease) || motionUtils.easeInOut;
|
|
1350
1383
|
/**
|
|
1351
1384
|
* This is the Iterator-spec return value. We ensure it's mutable rather than using a generator
|
|
1352
1385
|
* to reduce GC during animation.
|
|
@@ -3140,7 +3173,7 @@ class AsyncMotionValueAnimation extends WithPromise {
|
|
|
3140
3173
|
|
|
3141
3174
|
class GroupAnimation {
|
|
3142
3175
|
constructor(animations) {
|
|
3143
|
-
// Bound to
|
|
3176
|
+
// Bound to accommodate common `return animation.stop` pattern
|
|
3144
3177
|
this.stop = () => this.runAll("stop");
|
|
3145
3178
|
this.animations = animations.filter(Boolean);
|
|
3146
3179
|
}
|
|
@@ -5472,7 +5505,7 @@ function applyTreeDeltas(box, treeScale, treePath, isSharedTransition = false) {
|
|
|
5472
5505
|
translateAxis(box.y, -node.scroll.offset.y);
|
|
5473
5506
|
}
|
|
5474
5507
|
if (delta) {
|
|
5475
|
-
//
|
|
5508
|
+
// Incorporate each ancestor's scale into a cumulative treeScale for this component
|
|
5476
5509
|
treeScale.x *= delta.x.scale;
|
|
5477
5510
|
treeScale.y *= delta.y.scale;
|
|
5478
5511
|
// Apply each ancestor's calculated delta into this component's recorded layout box
|
|
@@ -5680,7 +5713,7 @@ function isValidHover(event) {
|
|
|
5680
5713
|
/**
|
|
5681
5714
|
* Create a hover gesture. hover() is different to .addEventListener("pointerenter")
|
|
5682
5715
|
* in that it has an easier syntax, filters out polyfilled touch events, interoperates
|
|
5683
|
-
* with drag gestures, and automatically removes the "
|
|
5716
|
+
* with drag gestures, and automatically removes the "pointerleave" event listener when the hover ends.
|
|
5684
5717
|
*
|
|
5685
5718
|
* @public
|
|
5686
5719
|
*/
|
|
@@ -7416,7 +7449,7 @@ function processQueue() {
|
|
|
7416
7449
|
/**
|
|
7417
7450
|
* Iterate backwards over the builders array. We can ignore the
|
|
7418
7451
|
* "wait" animations. If we have an interrupting animation in the
|
|
7419
|
-
* queue then we need to batch all
|
|
7452
|
+
* queue then we need to batch all preceding animations into it.
|
|
7420
7453
|
* Currently this only batches the update functions but will also
|
|
7421
7454
|
* need to batch the targets.
|
|
7422
7455
|
*/
|
|
@@ -8296,7 +8329,7 @@ class DOMVisualElement extends VisualElement {
|
|
|
8296
8329
|
/**
|
|
8297
8330
|
* compareDocumentPosition returns a bitmask, by using the bitwise &
|
|
8298
8331
|
* we're returning true if 2 in that bitmask is set to true. 2 is set
|
|
8299
|
-
* to true if b
|
|
8332
|
+
* to true if b precedes a.
|
|
8300
8333
|
*/
|
|
8301
8334
|
return a.compareDocumentPosition(b) & 2 ? 1 : -1;
|
|
8302
8335
|
}
|
|
@@ -8788,7 +8821,7 @@ function createAnimationState(visualElement) {
|
|
|
8788
8821
|
}
|
|
8789
8822
|
/**
|
|
8790
8823
|
* Set all encountered keys so far as the protected keys for this type. This will
|
|
8791
|
-
* be any key that has been animated or otherwise handled by active, higher-
|
|
8824
|
+
* be any key that has been animated or otherwise handled by active, higher-priority types.
|
|
8792
8825
|
*/
|
|
8793
8826
|
typeState.protectedKeys = { ...encounteredKeys };
|
|
8794
8827
|
// Check if we can skip analysing this prop early
|
|
@@ -9613,8 +9646,8 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
9613
9646
|
this.hasCheckedOptimisedAppear = false;
|
|
9614
9647
|
/**
|
|
9615
9648
|
* An object representing the calculated contextual/accumulated/tree scale.
|
|
9616
|
-
* This will be used to scale
|
|
9617
|
-
* calculated in screen-space but need to be scaled for elements to
|
|
9649
|
+
* This will be used to scale calculated projection transforms, as these are
|
|
9650
|
+
* calculated in screen-space but need to be scaled for elements to visually
|
|
9618
9651
|
* make it to their calculated destinations.
|
|
9619
9652
|
*
|
|
9620
9653
|
* TODO: Lazy-init
|