motion-dom 13.4.4 → 13.4.5
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 +60 -73
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/generators/spring.mjs +39 -64
- package/dist/es/animation/generators/spring.mjs.map +1 -1
- package/dist/es/projection/node/create-projection-node.mjs +21 -9
- package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
- package/dist/index.d.ts +1 -8
- package/dist/motion-dom.dev.js +60 -73
- package/dist/motion-dom.js +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -4685,8 +4685,6 @@ interface ScrollMeasurements {
|
|
|
4685
4685
|
}
|
|
4686
4686
|
type LayoutEvents = "willUpdate" | "didUpdate" | "beforeMeasure" | "measure" | "projectionUpdate" | "animationStart" | "animationComplete";
|
|
4687
4687
|
interface IProjectionNode<I = unknown> {
|
|
4688
|
-
linkedParentVersion: number;
|
|
4689
|
-
layoutVersion: number;
|
|
4690
4688
|
id: number;
|
|
4691
4689
|
animationId: number;
|
|
4692
4690
|
animationCommitId: number;
|
|
@@ -4753,6 +4751,7 @@ interface IProjectionNode<I = unknown> {
|
|
|
4753
4751
|
resetSkewAndRotation(): void;
|
|
4754
4752
|
applyTransform(box: Box, transformOnly?: boolean, output?: Box): Box;
|
|
4755
4753
|
resolveTargetDelta(force?: boolean): void;
|
|
4754
|
+
removeRelativeTarget(): void;
|
|
4756
4755
|
calcProjection(): void;
|
|
4757
4756
|
applyProjectionStyles(targetStyle: CSSStyleDeclaration, styleProp?: MotionStyle): void;
|
|
4758
4757
|
clearMeasurements(): void;
|
|
@@ -5054,7 +5053,6 @@ declare function createProjectionNode<I>({ attachResizeListener, defaultParent,
|
|
|
5054
5053
|
prevTransformTemplateValue: string | undefined;
|
|
5055
5054
|
preserveOpacity?: boolean | undefined;
|
|
5056
5055
|
hasTreeAnimated: boolean;
|
|
5057
|
-
layoutVersion: number;
|
|
5058
5056
|
addEventListener(name: LayoutEvents, handler: any): VoidFunction;
|
|
5059
5057
|
notifyListeners(name: LayoutEvents, ...args: any): void;
|
|
5060
5058
|
hasListeners(name: LayoutEvents): boolean;
|
|
@@ -5114,7 +5112,6 @@ declare function createProjectionNode<I>({ attachResizeListener, defaultParent,
|
|
|
5114
5112
|
resolveTargetDelta(forceRecalculation?: boolean): void;
|
|
5115
5113
|
getClosestProjectingParent(): IProjectionNode<unknown> | undefined;
|
|
5116
5114
|
isProjecting(): boolean;
|
|
5117
|
-
linkedParentVersion: number;
|
|
5118
5115
|
createRelativeTarget(relativeParent: IProjectionNode, layout: Box, parentLayout: Box): void;
|
|
5119
5116
|
removeRelativeTarget(): void;
|
|
5120
5117
|
hasProjected: boolean;
|
|
@@ -5211,7 +5208,6 @@ declare const DocumentProjectionNode: {
|
|
|
5211
5208
|
prevTransformTemplateValue: string | undefined;
|
|
5212
5209
|
preserveOpacity?: boolean | undefined;
|
|
5213
5210
|
hasTreeAnimated: boolean;
|
|
5214
|
-
layoutVersion: number;
|
|
5215
5211
|
addEventListener(name: LayoutEvents, handler: any): VoidFunction;
|
|
5216
5212
|
notifyListeners(name: LayoutEvents, ...args: any): void;
|
|
5217
5213
|
hasListeners(name: LayoutEvents): boolean;
|
|
@@ -5257,7 +5253,6 @@ declare const DocumentProjectionNode: {
|
|
|
5257
5253
|
resolveTargetDelta(forceRecalculation?: boolean): void;
|
|
5258
5254
|
getClosestProjectingParent(): IProjectionNode<unknown> | undefined;
|
|
5259
5255
|
isProjecting(): boolean;
|
|
5260
|
-
linkedParentVersion: number;
|
|
5261
5256
|
createRelativeTarget(relativeParent: IProjectionNode<unknown>, layout: motion_utils.Box, parentLayout: motion_utils.Box): void;
|
|
5262
5257
|
removeRelativeTarget(): void;
|
|
5263
5258
|
hasProjected: boolean;
|
|
@@ -5356,7 +5351,6 @@ declare const HTMLProjectionNode: {
|
|
|
5356
5351
|
prevTransformTemplateValue: string | undefined;
|
|
5357
5352
|
preserveOpacity?: boolean | undefined;
|
|
5358
5353
|
hasTreeAnimated: boolean;
|
|
5359
|
-
layoutVersion: number;
|
|
5360
5354
|
addEventListener(name: LayoutEvents, handler: any): VoidFunction;
|
|
5361
5355
|
notifyListeners(name: LayoutEvents, ...args: any): void;
|
|
5362
5356
|
hasListeners(name: LayoutEvents): boolean;
|
|
@@ -5402,7 +5396,6 @@ declare const HTMLProjectionNode: {
|
|
|
5402
5396
|
resolveTargetDelta(forceRecalculation?: boolean): void;
|
|
5403
5397
|
getClosestProjectingParent(): IProjectionNode<unknown> | undefined;
|
|
5404
5398
|
isProjecting(): boolean;
|
|
5405
|
-
linkedParentVersion: number;
|
|
5406
5399
|
createRelativeTarget(relativeParent: IProjectionNode<unknown>, layout: motion_utils.Box, parentLayout: motion_utils.Box): void;
|
|
5407
5400
|
removeRelativeTarget(): void;
|
|
5408
5401
|
hasProjected: boolean;
|
package/dist/motion-dom.dev.js
CHANGED
|
@@ -812,7 +812,6 @@
|
|
|
812
812
|
stiffness: 100,
|
|
813
813
|
damping: 10,
|
|
814
814
|
mass: 1.0,
|
|
815
|
-
velocity: 0.0,
|
|
816
815
|
// Default duration/bounce-based options
|
|
817
816
|
duration: 800, // in ms
|
|
818
817
|
bounce: 0.3,
|
|
@@ -847,7 +846,12 @@
|
|
|
847
846
|
* This is ported from the Framer implementation of duration-based spring resolution.
|
|
848
847
|
*/
|
|
849
848
|
const safeMin = 0.001;
|
|
850
|
-
|
|
849
|
+
/**
|
|
850
|
+
* Assumes zero initial velocity and the default mass: time-defined springs
|
|
851
|
+
* ignore inherited velocity and only resolve without valid physics. Returns
|
|
852
|
+
* NaN physics when the root search doesn't converge.
|
|
853
|
+
*/
|
|
854
|
+
function findSpring({ duration = springDefaults.duration, bounce = springDefaults.bounce, }) {
|
|
851
855
|
let envelope;
|
|
852
856
|
let derivative;
|
|
853
857
|
motionUtils.warning(duration <= motionUtils.secondsToMilliseconds(springDefaults.maxDuration), "Spring duration must be 10 seconds or less", "spring-duration-limit");
|
|
@@ -864,15 +868,13 @@
|
|
|
864
868
|
envelope = (undampedFreq) => {
|
|
865
869
|
const exponentialDecay = undampedFreq * dampingRatio;
|
|
866
870
|
const delta = exponentialDecay * duration;
|
|
867
|
-
const a = exponentialDecay - velocity;
|
|
868
871
|
const b = calcAngularFreq(undampedFreq, dampingRatio);
|
|
869
872
|
const c = Math.exp(-delta);
|
|
870
|
-
return safeMin - (
|
|
873
|
+
return safeMin - (exponentialDecay / b) * c;
|
|
871
874
|
};
|
|
872
875
|
derivative = (undampedFreq) => {
|
|
873
876
|
const exponentialDecay = undampedFreq * dampingRatio;
|
|
874
877
|
const delta = exponentialDecay * duration;
|
|
875
|
-
const d = delta * velocity + velocity;
|
|
876
878
|
const e = dampingRatio *
|
|
877
879
|
dampingRatio *
|
|
878
880
|
undampedFreq *
|
|
@@ -881,7 +883,7 @@
|
|
|
881
883
|
const f = Math.exp(-delta);
|
|
882
884
|
const g = calcAngularFreq(undampedFreq * undampedFreq, dampingRatio);
|
|
883
885
|
const factor = -envelope(undampedFreq) + safeMin > 0 ? -1 : 1;
|
|
884
|
-
return (factor *
|
|
886
|
+
return (factor * -e * f) / g;
|
|
885
887
|
};
|
|
886
888
|
}
|
|
887
889
|
else {
|
|
@@ -890,37 +892,23 @@
|
|
|
890
892
|
*/
|
|
891
893
|
envelope = (undampedFreq) => {
|
|
892
894
|
const a = Math.exp(-undampedFreq * duration);
|
|
893
|
-
const b =
|
|
895
|
+
const b = undampedFreq * duration + 1;
|
|
894
896
|
return -safeMin + a * b;
|
|
895
897
|
};
|
|
896
898
|
derivative = (undampedFreq) => {
|
|
897
899
|
const a = Math.exp(-undampedFreq * duration);
|
|
898
|
-
const b =
|
|
900
|
+
const b = -undampedFreq * (duration * duration);
|
|
899
901
|
return a * b;
|
|
900
902
|
};
|
|
901
903
|
}
|
|
902
904
|
const initialGuess = 5 / duration;
|
|
903
905
|
const undampedFreq = approximateRoot(envelope, derivative, initialGuess);
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
};
|
|
911
|
-
}
|
|
912
|
-
else {
|
|
913
|
-
const stiffness = undampedFreq * undampedFreq * mass;
|
|
914
|
-
return {
|
|
915
|
-
stiffness,
|
|
916
|
-
damping: dampingRatio * 2 * Math.sqrt(mass * stiffness),
|
|
917
|
-
duration,
|
|
918
|
-
};
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
const durationKeys = ["duration", "bounce"];
|
|
922
|
-
function isSpringType(options, keys) {
|
|
923
|
-
return keys.some((key) => options[key] !== undefined);
|
|
906
|
+
const stiffness = undampedFreq * undampedFreq;
|
|
907
|
+
return {
|
|
908
|
+
stiffness,
|
|
909
|
+
damping: dampingRatio * 2 * Math.sqrt(stiffness),
|
|
910
|
+
duration: motionUtils.secondsToMilliseconds(duration),
|
|
911
|
+
};
|
|
924
912
|
}
|
|
925
913
|
/**
|
|
926
914
|
* Spring physics must be finite. stiffness and mass are also divisors so must
|
|
@@ -952,7 +940,7 @@
|
|
|
952
940
|
const validStiffness = resolvePhysics(options.stiffness);
|
|
953
941
|
const validDamping = resolvePhysics(options.damping, true);
|
|
954
942
|
const validMass = resolvePhysics(options.mass);
|
|
955
|
-
|
|
943
|
+
const springOptions = {
|
|
956
944
|
...options,
|
|
957
945
|
stiffness: validStiffness ?? springDefaults.stiffness,
|
|
958
946
|
damping: validDamping ?? springDefaults.damping,
|
|
@@ -960,42 +948,27 @@
|
|
|
960
948
|
isResolvedFromDuration: false,
|
|
961
949
|
// stiffness/damping/mass overrides duration/bounce
|
|
962
950
|
isTimeDefined: (validStiffness ?? validDamping ?? validMass) === undefined &&
|
|
963
|
-
|
|
951
|
+
(options.duration !== undefined || options.bounce !== undefined),
|
|
964
952
|
};
|
|
965
953
|
if (springOptions.isTimeDefined) {
|
|
966
|
-
// Time-defined springs should ignore inherited velocity.
|
|
967
|
-
// Velocity from interrupted animations can cause findSpring()
|
|
968
|
-
// to compute wildly different spring parameters, leading to
|
|
969
|
-
// massive oscillation on small-range animations.
|
|
970
|
-
springOptions.velocity = 0;
|
|
971
954
|
if (options.visualDuration) {
|
|
972
|
-
const
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
springOptions = {
|
|
979
|
-
...springOptions,
|
|
980
|
-
mass: springDefaults.mass,
|
|
981
|
-
stiffness,
|
|
982
|
-
damping,
|
|
983
|
-
};
|
|
955
|
+
const root = (2 * Math.PI) / (options.visualDuration * 1.2);
|
|
956
|
+
springOptions.stiffness = root * root;
|
|
957
|
+
springOptions.damping =
|
|
958
|
+
2 *
|
|
959
|
+
motionUtils.clamp(0.05, 1, 1 - (options.bounce || 0)) *
|
|
960
|
+
Math.sqrt(springOptions.stiffness);
|
|
984
961
|
}
|
|
985
962
|
else {
|
|
986
|
-
|
|
987
|
-
springOptions = {
|
|
988
|
-
...springOptions,
|
|
989
|
-
...derived,
|
|
990
|
-
mass: springDefaults.mass,
|
|
991
|
-
};
|
|
963
|
+
Object.assign(springOptions, findSpring(springOptions));
|
|
992
964
|
springOptions.isResolvedFromDuration = true;
|
|
993
965
|
}
|
|
994
966
|
/**
|
|
995
|
-
*
|
|
996
|
-
*
|
|
997
|
-
*
|
|
998
|
-
* between them is never
|
|
967
|
+
* Time options can degenerate: a NaN bounce gives a NaN damping, an
|
|
968
|
+
* infinite visualDuration a 0 stiffness, and findSpring NaN for both
|
|
969
|
+
* when it doesn't converge. Replace the two together, so the
|
|
970
|
+
* relationship duration resolution establishes between them is never
|
|
971
|
+
* left half-overwritten.
|
|
999
972
|
*/
|
|
1000
973
|
if (!isValidPhysics(springOptions.stiffness) ||
|
|
1001
974
|
!isValidPhysics(springOptions.damping, true)) {
|
|
@@ -1020,10 +993,13 @@
|
|
|
1020
993
|
* to reduce GC during animation.
|
|
1021
994
|
*/
|
|
1022
995
|
const state = { done: false, value: origin };
|
|
1023
|
-
const { stiffness, damping, mass, duration,
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
996
|
+
const { stiffness, damping, mass, duration, isResolvedFromDuration, isTimeDefined, } = getSpringOptions({ ...options });
|
|
997
|
+
/**
|
|
998
|
+
* Time-defined springs ignore inherited velocity. Velocity from
|
|
999
|
+
* interrupted animations causes massive oscillation on small-range
|
|
1000
|
+
* animations.
|
|
1001
|
+
*/
|
|
1002
|
+
const inheritVelocity = (velocity) => isTimeDefined ? 0 : -motionUtils.millisecondsToSeconds(velocity);
|
|
1027
1003
|
const dampingRatio = damping / (2 * Math.sqrt(stiffness * mass));
|
|
1028
1004
|
const undampedAngularFreq = motionUtils.millisecondsToSeconds(Math.sqrt(stiffness / mass));
|
|
1029
1005
|
const decay = dampingRatio * undampedAngularFreq;
|
|
@@ -1037,7 +1013,7 @@
|
|
|
1037
1013
|
const s = {
|
|
1038
1014
|
target,
|
|
1039
1015
|
delta: target - origin,
|
|
1040
|
-
velocity: velocity || 0
|
|
1016
|
+
velocity: inheritVelocity(options.velocity || 0) || 0,
|
|
1041
1017
|
restSpeed: 0,
|
|
1042
1018
|
restDelta: 0,
|
|
1043
1019
|
};
|
|
@@ -1153,8 +1129,7 @@
|
|
|
1153
1129
|
retarget: (keyframes, newVelocity) => {
|
|
1154
1130
|
s.target = keyframes[keyframes.length - 1];
|
|
1155
1131
|
s.delta = s.target - keyframes[0];
|
|
1156
|
-
|
|
1157
|
-
s.velocity = isTimeDefined ? 0 : -motionUtils.millisecondsToSeconds(newVelocity);
|
|
1132
|
+
s.velocity = inheritVelocity(newVelocity);
|
|
1158
1133
|
// Default thresholds depend on the scale of the new delta
|
|
1159
1134
|
if (!(options.restSpeed && options.restDelta))
|
|
1160
1135
|
setRestThresholds();
|
|
@@ -9657,7 +9632,6 @@
|
|
|
9657
9632
|
*/
|
|
9658
9633
|
this.eventHandlers = new Map();
|
|
9659
9634
|
this.hasTreeAnimated = false;
|
|
9660
|
-
this.layoutVersion = 0;
|
|
9661
9635
|
// Note: Currently only running on root node
|
|
9662
9636
|
this.updateScheduled = false;
|
|
9663
9637
|
this.scheduleUpdate = () => this.update();
|
|
@@ -9697,7 +9671,6 @@
|
|
|
9697
9671
|
* Frame calculations
|
|
9698
9672
|
*/
|
|
9699
9673
|
this.resolvedRelativeTargetAt = 0.0;
|
|
9700
|
-
this.linkedParentVersion = 0;
|
|
9701
9674
|
this.hasProjected = false;
|
|
9702
9675
|
this.isVisible = true;
|
|
9703
9676
|
this.animationProgress = 0;
|
|
@@ -9978,6 +9951,7 @@
|
|
|
9978
9951
|
* get measured even when memoized (willUpdate skipped).
|
|
9979
9952
|
*/
|
|
9980
9953
|
this.nodes.forEach(ensureDraggedNodesSnapshotted);
|
|
9954
|
+
this.nodes.forEach(syncRelativeLayout);
|
|
9981
9955
|
/**
|
|
9982
9956
|
* Write
|
|
9983
9957
|
*/
|
|
@@ -10075,7 +10049,6 @@
|
|
|
10075
10049
|
}
|
|
10076
10050
|
const prevLayout = this.layout;
|
|
10077
10051
|
this.layout = this.measure(false);
|
|
10078
|
-
this.layoutVersion++;
|
|
10079
10052
|
if (!this.layoutCorrected)
|
|
10080
10053
|
this.layoutCorrected = createBox();
|
|
10081
10054
|
this.isLayoutDirty = false;
|
|
@@ -10295,11 +10268,6 @@
|
|
|
10295
10268
|
return;
|
|
10296
10269
|
this.resolvedRelativeTargetAt = frameData.timestamp;
|
|
10297
10270
|
const relativeParent = this.getClosestProjectingParent();
|
|
10298
|
-
if (relativeParent &&
|
|
10299
|
-
this.linkedParentVersion !== relativeParent.layoutVersion &&
|
|
10300
|
-
!relativeParent.options.layoutRoot) {
|
|
10301
|
-
this.removeRelativeTarget();
|
|
10302
|
-
}
|
|
10303
10271
|
/**
|
|
10304
10272
|
* If we don't have a targetDelta but do have a layout, we can attempt to resolve
|
|
10305
10273
|
* a relativeParent. This will allow a component to perform scale correction
|
|
@@ -10402,7 +10370,6 @@
|
|
|
10402
10370
|
}
|
|
10403
10371
|
createRelativeTarget(relativeParent, layout, parentLayout) {
|
|
10404
10372
|
this.relativeParent = relativeParent;
|
|
10405
|
-
this.linkedParentVersion = relativeParent.layoutVersion;
|
|
10406
10373
|
this.forceRelativeParentToResolveTarget();
|
|
10407
10374
|
this.relativeTarget = createBox();
|
|
10408
10375
|
this.relativeTargetOrigin = createBox();
|
|
@@ -11112,6 +11079,26 @@
|
|
|
11112
11079
|
node.isLayoutDirty = true;
|
|
11113
11080
|
}
|
|
11114
11081
|
}
|
|
11082
|
+
/**
|
|
11083
|
+
* If a node's relative parent is about to be re-measured but the node isn't
|
|
11084
|
+
* (e.g. it's in another LayoutGroup), its relative target is out of date.
|
|
11085
|
+
* If it's layout animating, re-measure it too, so its relative target keeps
|
|
11086
|
+
* resolving against current layouts. Otherwise its layout is still valid
|
|
11087
|
+
* relative to its parent, so drop the relative target, and any targetDelta
|
|
11088
|
+
* left over from a finished animation while an ancestor still animates, to be
|
|
11089
|
+
* rebuilt from its layout.
|
|
11090
|
+
*/
|
|
11091
|
+
function syncRelativeLayout(node) {
|
|
11092
|
+
if (node.relativeTarget && node.relativeParent?.isLayoutDirty) {
|
|
11093
|
+
if (node.currentAnimation) {
|
|
11094
|
+
node.isLayoutDirty = true;
|
|
11095
|
+
}
|
|
11096
|
+
else {
|
|
11097
|
+
node.targetDelta = undefined;
|
|
11098
|
+
node.removeRelativeTarget();
|
|
11099
|
+
}
|
|
11100
|
+
}
|
|
11101
|
+
}
|
|
11115
11102
|
function resetTransformStyle(node) {
|
|
11116
11103
|
const { visualElement } = node.options;
|
|
11117
11104
|
if (visualElement && visualElement.getProps().onBeforeLayoutMeasure) {
|