motion-dom 12.35.1 → 12.36.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 +224 -86
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/AsyncMotionValueAnimation.mjs +8 -1
- package/dist/es/animation/AsyncMotionValueAnimation.mjs.map +1 -1
- package/dist/es/animation/JSAnimation.mjs +17 -0
- package/dist/es/animation/JSAnimation.mjs.map +1 -1
- package/dist/es/animation/NativeAnimationExtended.mjs +6 -1
- package/dist/es/animation/NativeAnimationExtended.mjs.map +1 -1
- package/dist/es/animation/generators/inertia.mjs +3 -3
- package/dist/es/animation/generators/inertia.mjs.map +1 -1
- package/dist/es/animation/generators/spring.mjs +329 -0
- package/dist/es/animation/generators/spring.mjs.map +1 -0
- package/dist/es/animation/generators/utils/velocity.mjs +2 -2
- package/dist/es/animation/generators/utils/velocity.mjs.map +1 -1
- package/dist/es/animation/keyframes/utils/unit-conversion.mjs +12 -2
- package/dist/es/animation/keyframes/utils/unit-conversion.mjs.map +1 -1
- package/dist/es/animation/utils/replace-transition-type.mjs +1 -1
- package/dist/es/effects/MotionValueState.mjs +0 -5
- package/dist/es/effects/MotionValueState.mjs.map +1 -1
- package/dist/es/effects/style/transform.mjs +1 -2
- package/dist/es/effects/style/transform.mjs.map +1 -1
- package/dist/es/effects/utils/create-effect.mjs +1 -1
- package/dist/es/effects/utils/create-effect.mjs.map +1 -1
- package/dist/es/frameloop/batcher.mjs +3 -2
- package/dist/es/frameloop/batcher.mjs.map +1 -1
- package/dist/es/frameloop/render-step.mjs +5 -3
- package/dist/es/frameloop/render-step.mjs.map +1 -1
- package/dist/es/index.mjs +1 -1
- package/dist/es/layout/LayoutAnimationBuilder.mjs.map +1 -1
- package/dist/es/projection/geometry/delta-apply.mjs +5 -4
- package/dist/es/projection/geometry/delta-apply.mjs.map +1 -1
- package/dist/es/projection/node/create-projection-node.mjs +24 -10
- package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
- package/dist/es/utils/is-html-element.mjs +3 -1
- package/dist/es/utils/is-html-element.mjs.map +1 -1
- package/dist/es/value/follow-value.mjs +29 -10
- package/dist/es/value/follow-value.mjs.map +1 -1
- package/dist/es/value/types/complex/index.mjs +27 -5
- package/dist/es/value/types/complex/index.mjs.map +1 -1
- package/dist/index.d.ts +25 -8
- package/dist/motion-dom.dev.js +224 -86
- package/dist/motion-dom.js +1 -1
- package/dist/size-rollup-motion-value.js +1 -1
- package/dist/size-rollup-motion-value.js.map +1 -1
- package/dist/size-rollup-style-effect.js +1 -1
- package/dist/size-rollup-style-effect.js.map +1 -1
- package/package.json +3 -3
- package/dist/es/animation/generators/spring/defaults.mjs +0 -28
- package/dist/es/animation/generators/spring/defaults.mjs.map +0 -1
- package/dist/es/animation/generators/spring/find.mjs +0 -85
- package/dist/es/animation/generators/spring/find.mjs.map +0 -1
- package/dist/es/animation/generators/spring/index.mjs +0 -181
- package/dist/es/animation/generators/spring/index.mjs.map +0 -1
package/dist/motion-dom.dev.js
CHANGED
|
@@ -60,8 +60,7 @@
|
|
|
60
60
|
const queue = addToCurrentFrame ? thisFrame : nextFrame;
|
|
61
61
|
if (keepAlive)
|
|
62
62
|
toKeepAlive.add(callback);
|
|
63
|
-
|
|
64
|
-
queue.add(callback);
|
|
63
|
+
queue.add(callback);
|
|
65
64
|
return callback;
|
|
66
65
|
},
|
|
67
66
|
/**
|
|
@@ -86,7 +85,10 @@
|
|
|
86
85
|
return;
|
|
87
86
|
}
|
|
88
87
|
isProcessing = true;
|
|
89
|
-
|
|
88
|
+
// Swap this frame and the next to avoid GC
|
|
89
|
+
const prevFrame = thisFrame;
|
|
90
|
+
thisFrame = nextFrame;
|
|
91
|
+
nextFrame = prevFrame;
|
|
90
92
|
// Execute this frame
|
|
91
93
|
thisFrame.forEach(triggerCallback);
|
|
92
94
|
/**
|
|
@@ -125,11 +127,12 @@
|
|
|
125
127
|
}, {});
|
|
126
128
|
const { setup, read, resolveKeyframes, preUpdate, update, preRender, render, postRender, } = steps;
|
|
127
129
|
const processBatch = () => {
|
|
128
|
-
const
|
|
130
|
+
const useManualTiming = motionUtils.MotionGlobalConfig.useManualTiming;
|
|
131
|
+
const timestamp = useManualTiming
|
|
129
132
|
? state.timestamp
|
|
130
133
|
: performance.now();
|
|
131
134
|
runNextFrame = false;
|
|
132
|
-
if (!
|
|
135
|
+
if (!useManualTiming) {
|
|
133
136
|
state.delta = useDefaultElapsed
|
|
134
137
|
? 1000 / 60
|
|
135
138
|
: Math.max(Math.min(timestamp - state.timestamp, maxElapsed), 1);
|
|
@@ -451,8 +454,7 @@
|
|
|
451
454
|
function parseComplexValue(v) {
|
|
452
455
|
return analyseComplexValue(v).values;
|
|
453
456
|
}
|
|
454
|
-
function
|
|
455
|
-
const { split, types } = analyseComplexValue(source);
|
|
457
|
+
function buildTransformer({ split, types }) {
|
|
456
458
|
const numSections = split.length;
|
|
457
459
|
return (v) => {
|
|
458
460
|
let output = "";
|
|
@@ -474,11 +476,34 @@
|
|
|
474
476
|
return output;
|
|
475
477
|
};
|
|
476
478
|
}
|
|
479
|
+
function createTransformer(source) {
|
|
480
|
+
return buildTransformer(analyseComplexValue(source));
|
|
481
|
+
}
|
|
477
482
|
const convertNumbersToZero = (v) => typeof v === "number" ? 0 : color.test(v) ? color.getAnimatableNone(v) : v;
|
|
483
|
+
/**
|
|
484
|
+
* Convert a parsed value to its zero equivalent, but preserve numbers
|
|
485
|
+
* that act as divisors in CSS calc() expressions.
|
|
486
|
+
*
|
|
487
|
+
* analyseComplexValue extracts numbers from CSS strings and puts the
|
|
488
|
+
* surrounding text into a `split` template array. For example:
|
|
489
|
+
* "calc(var(--gap) / 5)" → values: [var(--gap), 5]
|
|
490
|
+
* split: ["calc(", " / ", ")"]
|
|
491
|
+
*
|
|
492
|
+
* When building a zero-equivalent for animation, naively zeroing all
|
|
493
|
+
* numbers turns the divisor into 0 → "calc(var(--gap) / 0)" → NaN.
|
|
494
|
+
* We detect this by checking whether the text preceding a number
|
|
495
|
+
* (split[i]) ends with "/" — the CSS calc division operator.
|
|
496
|
+
*/
|
|
497
|
+
const convertToZero = (value, splitBefore) => {
|
|
498
|
+
if (typeof value === "number") {
|
|
499
|
+
return splitBefore?.trim().endsWith("/") ? value : 0;
|
|
500
|
+
}
|
|
501
|
+
return convertNumbersToZero(value);
|
|
502
|
+
};
|
|
478
503
|
function getAnimatableNone$1(v) {
|
|
479
|
-
const
|
|
480
|
-
const transformer =
|
|
481
|
-
return transformer(
|
|
504
|
+
const info = analyseComplexValue(v);
|
|
505
|
+
const transformer = buildTransformer(info);
|
|
506
|
+
return transformer(info.values.map((value, i) => convertToZero(value, info.split[i])));
|
|
482
507
|
}
|
|
483
508
|
const complex = {
|
|
484
509
|
test,
|
|
@@ -757,12 +782,6 @@
|
|
|
757
782
|
};
|
|
758
783
|
}
|
|
759
784
|
|
|
760
|
-
const velocitySampleDuration = 5; // ms
|
|
761
|
-
function calcGeneratorVelocity(resolveValue, t, current) {
|
|
762
|
-
const prevT = Math.max(t - velocitySampleDuration, 0);
|
|
763
|
-
return motionUtils.velocityPerSecond(current - resolveValue(prevT), t - prevT);
|
|
764
|
-
}
|
|
765
|
-
|
|
766
785
|
const springDefaults = {
|
|
767
786
|
// Default spring physics
|
|
768
787
|
stiffness: 100,
|
|
@@ -788,7 +807,20 @@
|
|
|
788
807
|
minDamping: 0.05,
|
|
789
808
|
maxDamping: 1,
|
|
790
809
|
};
|
|
791
|
-
|
|
810
|
+
function calcAngularFreq(undampedFreq, dampingRatio) {
|
|
811
|
+
return undampedFreq * Math.sqrt(1 - dampingRatio * dampingRatio);
|
|
812
|
+
}
|
|
813
|
+
const rootIterations = 12;
|
|
814
|
+
function approximateRoot(envelope, derivative, initialGuess) {
|
|
815
|
+
let result = initialGuess;
|
|
816
|
+
for (let i = 1; i < rootIterations; i++) {
|
|
817
|
+
result = result - envelope(result) / derivative(result);
|
|
818
|
+
}
|
|
819
|
+
return result;
|
|
820
|
+
}
|
|
821
|
+
/**
|
|
822
|
+
* This is ported from the Framer implementation of duration-based spring resolution.
|
|
823
|
+
*/
|
|
792
824
|
const safeMin = 0.001;
|
|
793
825
|
function findSpring({ duration = springDefaults.duration, bounce = springDefaults.bounce, velocity = springDefaults.velocity, mass = springDefaults.mass, }) {
|
|
794
826
|
let envelope;
|
|
@@ -857,18 +889,6 @@
|
|
|
857
889
|
};
|
|
858
890
|
}
|
|
859
891
|
}
|
|
860
|
-
const rootIterations = 12;
|
|
861
|
-
function approximateRoot(envelope, derivative, initialGuess) {
|
|
862
|
-
let result = initialGuess;
|
|
863
|
-
for (let i = 1; i < rootIterations; i++) {
|
|
864
|
-
result = result - envelope(result) / derivative(result);
|
|
865
|
-
}
|
|
866
|
-
return result;
|
|
867
|
-
}
|
|
868
|
-
function calcAngularFreq(undampedFreq, dampingRatio) {
|
|
869
|
-
return undampedFreq * Math.sqrt(1 - dampingRatio * dampingRatio);
|
|
870
|
-
}
|
|
871
|
-
|
|
872
892
|
const durationKeys = ["duration", "bounce"];
|
|
873
893
|
const physicsKeys = ["stiffness", "damping", "mass"];
|
|
874
894
|
function isSpringType(options, keys) {
|
|
@@ -956,19 +976,37 @@
|
|
|
956
976
|
? springDefaults.restDelta.granular
|
|
957
977
|
: springDefaults.restDelta.default);
|
|
958
978
|
let resolveSpring;
|
|
979
|
+
let resolveVelocity;
|
|
980
|
+
// Underdamped coefficients, hoisted for use in the inlined next() hot path
|
|
981
|
+
let angularFreq;
|
|
982
|
+
let A;
|
|
983
|
+
let sinCoeff;
|
|
984
|
+
let cosCoeff;
|
|
959
985
|
if (dampingRatio < 1) {
|
|
960
|
-
|
|
986
|
+
angularFreq = calcAngularFreq(undampedAngularFreq, dampingRatio);
|
|
987
|
+
A =
|
|
988
|
+
(initialVelocity +
|
|
989
|
+
dampingRatio * undampedAngularFreq * initialDelta) /
|
|
990
|
+
angularFreq;
|
|
961
991
|
// Underdamped spring
|
|
962
992
|
resolveSpring = (t) => {
|
|
963
993
|
const envelope = Math.exp(-dampingRatio * undampedAngularFreq * t);
|
|
964
994
|
return (target -
|
|
965
995
|
envelope *
|
|
966
|
-
((
|
|
967
|
-
dampingRatio * undampedAngularFreq * initialDelta) /
|
|
968
|
-
angularFreq) *
|
|
969
|
-
Math.sin(angularFreq * t) +
|
|
996
|
+
(A * Math.sin(angularFreq * t) +
|
|
970
997
|
initialDelta * Math.cos(angularFreq * t)));
|
|
971
998
|
};
|
|
999
|
+
// Analytical derivative of underdamped spring (px/ms)
|
|
1000
|
+
sinCoeff =
|
|
1001
|
+
dampingRatio * undampedAngularFreq * A + initialDelta * angularFreq;
|
|
1002
|
+
cosCoeff =
|
|
1003
|
+
dampingRatio * undampedAngularFreq * initialDelta - A * angularFreq;
|
|
1004
|
+
resolveVelocity = (t) => {
|
|
1005
|
+
const envelope = Math.exp(-dampingRatio * undampedAngularFreq * t);
|
|
1006
|
+
return envelope *
|
|
1007
|
+
(sinCoeff * Math.sin(angularFreq * t) +
|
|
1008
|
+
cosCoeff * Math.cos(angularFreq * t));
|
|
1009
|
+
};
|
|
972
1010
|
}
|
|
973
1011
|
else if (dampingRatio === 1) {
|
|
974
1012
|
// Critically damped spring
|
|
@@ -976,6 +1014,10 @@
|
|
|
976
1014
|
Math.exp(-undampedAngularFreq * t) *
|
|
977
1015
|
(initialDelta +
|
|
978
1016
|
(initialVelocity + undampedAngularFreq * initialDelta) * t);
|
|
1017
|
+
// Analytical derivative of critically damped spring (px/ms)
|
|
1018
|
+
const C = initialVelocity + undampedAngularFreq * initialDelta;
|
|
1019
|
+
resolveVelocity = (t) => Math.exp(-undampedAngularFreq * t) *
|
|
1020
|
+
(undampedAngularFreq * C * t - initialVelocity);
|
|
979
1021
|
}
|
|
980
1022
|
else {
|
|
981
1023
|
// Overdamped spring
|
|
@@ -994,28 +1036,50 @@
|
|
|
994
1036
|
Math.cosh(freqForT))) /
|
|
995
1037
|
dampedAngularFreq);
|
|
996
1038
|
};
|
|
1039
|
+
// Analytical derivative of overdamped spring (px/ms)
|
|
1040
|
+
const P = (initialVelocity +
|
|
1041
|
+
dampingRatio * undampedAngularFreq * initialDelta) /
|
|
1042
|
+
dampedAngularFreq;
|
|
1043
|
+
const sinhCoeff = dampingRatio * undampedAngularFreq * P - initialDelta * dampedAngularFreq;
|
|
1044
|
+
const coshCoeff = dampingRatio * undampedAngularFreq * initialDelta - P * dampedAngularFreq;
|
|
1045
|
+
resolveVelocity = (t) => {
|
|
1046
|
+
const envelope = Math.exp(-dampingRatio * undampedAngularFreq * t);
|
|
1047
|
+
const freqForT = Math.min(dampedAngularFreq * t, 300);
|
|
1048
|
+
return envelope *
|
|
1049
|
+
(sinhCoeff * Math.sinh(freqForT) +
|
|
1050
|
+
coshCoeff * Math.cosh(freqForT));
|
|
1051
|
+
};
|
|
997
1052
|
}
|
|
998
1053
|
const generator = {
|
|
999
1054
|
calculatedDuration: isResolvedFromDuration ? duration || null : null,
|
|
1055
|
+
velocity: (t) => motionUtils.secondsToMilliseconds(resolveVelocity(t)),
|
|
1000
1056
|
next: (t) => {
|
|
1057
|
+
/**
|
|
1058
|
+
* For underdamped physics springs we need both position and
|
|
1059
|
+
* velocity each tick. Compute shared trig values once to avoid
|
|
1060
|
+
* duplicate Math.exp/sin/cos calls on the hot path.
|
|
1061
|
+
*/
|
|
1062
|
+
if (!isResolvedFromDuration && dampingRatio < 1) {
|
|
1063
|
+
const envelope = Math.exp(-dampingRatio * undampedAngularFreq * t);
|
|
1064
|
+
const sin = Math.sin(angularFreq * t);
|
|
1065
|
+
const cos = Math.cos(angularFreq * t);
|
|
1066
|
+
const current = target -
|
|
1067
|
+
envelope *
|
|
1068
|
+
(A * sin + initialDelta * cos);
|
|
1069
|
+
const currentVelocity = motionUtils.secondsToMilliseconds(envelope *
|
|
1070
|
+
(sinCoeff * sin + cosCoeff * cos));
|
|
1071
|
+
state.done =
|
|
1072
|
+
Math.abs(currentVelocity) <= restSpeed &&
|
|
1073
|
+
Math.abs(target - current) <= restDelta;
|
|
1074
|
+
state.value = state.done ? target : current;
|
|
1075
|
+
return state;
|
|
1076
|
+
}
|
|
1001
1077
|
const current = resolveSpring(t);
|
|
1002
1078
|
if (!isResolvedFromDuration) {
|
|
1003
|
-
|
|
1004
|
-
/**
|
|
1005
|
-
* We only need to calculate velocity for under-damped springs
|
|
1006
|
-
* as over- and critically-damped springs can't overshoot, so
|
|
1007
|
-
* checking only for displacement is enough.
|
|
1008
|
-
*/
|
|
1009
|
-
if (dampingRatio < 1) {
|
|
1010
|
-
currentVelocity =
|
|
1011
|
-
t === 0
|
|
1012
|
-
? motionUtils.secondsToMilliseconds(initialVelocity)
|
|
1013
|
-
: calcGeneratorVelocity(resolveSpring, t, current);
|
|
1014
|
-
}
|
|
1015
|
-
const isBelowVelocityThreshold = Math.abs(currentVelocity) <= restSpeed;
|
|
1016
|
-
const isBelowDisplacementThreshold = Math.abs(target - current) <= restDelta;
|
|
1079
|
+
const currentVelocity = motionUtils.secondsToMilliseconds(resolveVelocity(t));
|
|
1017
1080
|
state.done =
|
|
1018
|
-
|
|
1081
|
+
Math.abs(currentVelocity) <= restSpeed &&
|
|
1082
|
+
Math.abs(target - current) <= restDelta;
|
|
1019
1083
|
}
|
|
1020
1084
|
else {
|
|
1021
1085
|
state.done = t >= duration;
|
|
@@ -1040,6 +1104,12 @@
|
|
|
1040
1104
|
return options;
|
|
1041
1105
|
};
|
|
1042
1106
|
|
|
1107
|
+
const velocitySampleDuration = 5; // ms
|
|
1108
|
+
function getGeneratorVelocity(resolveValue, t, current) {
|
|
1109
|
+
const prevT = Math.max(t - velocitySampleDuration, 0);
|
|
1110
|
+
return motionUtils.velocityPerSecond(current - resolveValue(prevT), t - prevT);
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1043
1113
|
function inertia({ keyframes, velocity = 0.0, power = 0.8, timeConstant = 325, bounceDamping = 10, bounceStiffness = 500, modifyTarget, min, max, restDelta = 0.5, restSpeed, }) {
|
|
1044
1114
|
const origin = keyframes[0];
|
|
1045
1115
|
const state = {
|
|
@@ -1085,7 +1155,7 @@
|
|
|
1085
1155
|
timeReachedBoundary = t;
|
|
1086
1156
|
spring$1 = spring({
|
|
1087
1157
|
keyframes: [state.value, nearestBoundary(state.value)],
|
|
1088
|
-
velocity:
|
|
1158
|
+
velocity: getGeneratorVelocity(calcLatest, t, state.value), // TODO: This should be passing * 1000
|
|
1089
1159
|
damping: bounceDamping,
|
|
1090
1160
|
stiffness: bounceStiffness,
|
|
1091
1161
|
restDelta,
|
|
@@ -1548,6 +1618,22 @@
|
|
|
1548
1618
|
this.tick(newTime);
|
|
1549
1619
|
}
|
|
1550
1620
|
}
|
|
1621
|
+
/**
|
|
1622
|
+
* Returns the generator's velocity at the current time in units/second.
|
|
1623
|
+
* Uses the analytical derivative when available (springs), avoiding
|
|
1624
|
+
* the MotionValue's frame-dependent velocity estimation.
|
|
1625
|
+
*/
|
|
1626
|
+
getGeneratorVelocity() {
|
|
1627
|
+
const t = this.currentTime;
|
|
1628
|
+
if (t <= 0)
|
|
1629
|
+
return this.options.velocity || 0;
|
|
1630
|
+
if (this.generator.velocity) {
|
|
1631
|
+
return this.generator.velocity(t);
|
|
1632
|
+
}
|
|
1633
|
+
// Fallback: finite difference
|
|
1634
|
+
const current = this.generator.next(t).value;
|
|
1635
|
+
return getGeneratorVelocity((s) => this.generator.next(s).value, t, current);
|
|
1636
|
+
}
|
|
1551
1637
|
get speed() {
|
|
1552
1638
|
return this.playbackSpeed;
|
|
1553
1639
|
}
|
|
@@ -1778,8 +1864,18 @@
|
|
|
1778
1864
|
}
|
|
1779
1865
|
const positionalValues = {
|
|
1780
1866
|
// Dimensions
|
|
1781
|
-
width: ({ x }, { paddingLeft = "0", paddingRight = "0" }) =>
|
|
1782
|
-
|
|
1867
|
+
width: ({ x }, { paddingLeft = "0", paddingRight = "0", boxSizing }) => {
|
|
1868
|
+
const width = x.max - x.min;
|
|
1869
|
+
return boxSizing === "border-box"
|
|
1870
|
+
? width
|
|
1871
|
+
: width - parseFloat(paddingLeft) - parseFloat(paddingRight);
|
|
1872
|
+
},
|
|
1873
|
+
height: ({ y }, { paddingTop = "0", paddingBottom = "0", boxSizing }) => {
|
|
1874
|
+
const height = y.max - y.min;
|
|
1875
|
+
return boxSizing === "border-box"
|
|
1876
|
+
? height
|
|
1877
|
+
: height - parseFloat(paddingTop) - parseFloat(paddingBottom);
|
|
1878
|
+
},
|
|
1783
1879
|
top: (_bbox, { top }) => parseFloat(top),
|
|
1784
1880
|
left: (_bbox, { left }) => parseFloat(left),
|
|
1785
1881
|
bottom: ({ y }, { top }) => parseFloat(top) + (y.max - y.min),
|
|
@@ -2263,7 +2359,12 @@
|
|
|
2263
2359
|
*/
|
|
2264
2360
|
replaceTransitionType(options);
|
|
2265
2361
|
super(options);
|
|
2266
|
-
|
|
2362
|
+
/**
|
|
2363
|
+
* Only set startTime when the animation should autoplay.
|
|
2364
|
+
* Setting startTime on a paused WAAPI animation unpauses it
|
|
2365
|
+
* (per the WAAPI spec), which breaks autoplay: false.
|
|
2366
|
+
*/
|
|
2367
|
+
if (options.startTime !== undefined && options.autoplay !== false) {
|
|
2267
2368
|
this.startTime = options.startTime;
|
|
2268
2369
|
}
|
|
2269
2370
|
this.options = options;
|
|
@@ -2466,7 +2567,9 @@
|
|
|
2466
2567
|
* If we can't animate this value with the resolved keyframes
|
|
2467
2568
|
* then we should complete it immediately.
|
|
2468
2569
|
*/
|
|
2570
|
+
let canAnimateValue = true;
|
|
2469
2571
|
if (!canAnimate(keyframes, name, type, velocity)) {
|
|
2572
|
+
canAnimateValue = false;
|
|
2470
2573
|
if (motionUtils.MotionGlobalConfig.instantAnimations || !delay) {
|
|
2471
2574
|
onUpdate?.(getFinalKeyframe$1(keyframes, options, finalKeyframe));
|
|
2472
2575
|
}
|
|
@@ -2503,8 +2606,13 @@
|
|
|
2503
2606
|
* Animate via WAAPI if possible. If this is a handoff animation, the optimised animation will be running via
|
|
2504
2607
|
* WAAPI. Therefore, this animation must be JS to ensure it runs "under" the
|
|
2505
2608
|
* optimised animation.
|
|
2609
|
+
*
|
|
2610
|
+
* Also skip WAAPI when keyframes aren't animatable, as the resolved
|
|
2611
|
+
* values may not be valid CSS and would trigger browser warnings.
|
|
2506
2612
|
*/
|
|
2507
|
-
const useWaapi =
|
|
2613
|
+
const useWaapi = canAnimateValue &&
|
|
2614
|
+
!isHandoff &&
|
|
2615
|
+
supportsBrowserAnimation(resolvedOptions);
|
|
2508
2616
|
const element = resolvedOptions.motionValue?.owner?.current;
|
|
2509
2617
|
const animation = useWaapi
|
|
2510
2618
|
? new NativeAnimationExtended({
|
|
@@ -4045,19 +4153,14 @@
|
|
|
4045
4153
|
get(name) {
|
|
4046
4154
|
return this.values.get(name)?.value;
|
|
4047
4155
|
}
|
|
4048
|
-
destroy() {
|
|
4049
|
-
for (const value of this.values.values()) {
|
|
4050
|
-
value.onRemove();
|
|
4051
|
-
}
|
|
4052
|
-
}
|
|
4053
4156
|
}
|
|
4054
4157
|
|
|
4055
4158
|
function createEffect(addValue) {
|
|
4056
4159
|
const stateCache = new WeakMap();
|
|
4057
|
-
const subscriptions = [];
|
|
4058
4160
|
return (subject, values) => {
|
|
4059
4161
|
const state = stateCache.get(subject) ?? new MotionValueState();
|
|
4060
4162
|
stateCache.set(subject, state);
|
|
4163
|
+
const subscriptions = [];
|
|
4061
4164
|
for (const key in values) {
|
|
4062
4165
|
const value = values[key];
|
|
4063
4166
|
const remove = addValue(subject, state, key, value);
|
|
@@ -4117,7 +4220,9 @@
|
|
|
4117
4220
|
* that works across iframes
|
|
4118
4221
|
*/
|
|
4119
4222
|
function isHTMLElement(element) {
|
|
4120
|
-
return motionUtils.isObject(element) &&
|
|
4223
|
+
return (motionUtils.isObject(element) &&
|
|
4224
|
+
"offsetHeight" in element &&
|
|
4225
|
+
!("ownerSVGElement" in element));
|
|
4121
4226
|
}
|
|
4122
4227
|
|
|
4123
4228
|
const translateAlias$1 = {
|
|
@@ -4149,8 +4254,7 @@
|
|
|
4149
4254
|
if (!valueIsDefault) {
|
|
4150
4255
|
transformIsDefault = false;
|
|
4151
4256
|
const transformName = translateAlias$1[key] || key;
|
|
4152
|
-
|
|
4153
|
-
transform += `${transformName}(${valueToRender}) `;
|
|
4257
|
+
transform += `${transformName}(${value}) `;
|
|
4154
4258
|
}
|
|
4155
4259
|
}
|
|
4156
4260
|
return transformIsDefault ? "none" : transform.trim();
|
|
@@ -4858,16 +4962,23 @@
|
|
|
4858
4962
|
}
|
|
4859
4963
|
};
|
|
4860
4964
|
const startAnimation = () => {
|
|
4861
|
-
stopAnimation();
|
|
4862
4965
|
const currentValue = asNumber$1(value.get());
|
|
4863
4966
|
const targetValue = asNumber$1(latestValue);
|
|
4864
4967
|
// Don't animate if we're already at the target
|
|
4865
4968
|
if (currentValue === targetValue) {
|
|
4969
|
+
stopAnimation();
|
|
4866
4970
|
return;
|
|
4867
4971
|
}
|
|
4972
|
+
// Use the running animation's analytical velocity for accuracy,
|
|
4973
|
+
// falling back to the MotionValue's velocity for the initial animation.
|
|
4974
|
+
// This prevents systematic velocity loss at high frame rates (240hz+).
|
|
4975
|
+
const velocity = activeAnimation
|
|
4976
|
+
? activeAnimation.getGeneratorVelocity()
|
|
4977
|
+
: value.getVelocity();
|
|
4978
|
+
stopAnimation();
|
|
4868
4979
|
activeAnimation = new JSAnimation({
|
|
4869
4980
|
keyframes: [currentValue, targetValue],
|
|
4870
|
-
velocity
|
|
4981
|
+
velocity,
|
|
4871
4982
|
// Default to spring if no type specified (matches useSpring behavior)
|
|
4872
4983
|
type: "spring",
|
|
4873
4984
|
restDelta: 0.001,
|
|
@@ -4876,19 +4987,31 @@
|
|
|
4876
4987
|
onUpdate: latestSetter,
|
|
4877
4988
|
});
|
|
4878
4989
|
};
|
|
4990
|
+
// Use a stable function reference so the frame loop Set deduplicates
|
|
4991
|
+
// multiple calls within the same frame (e.g. rapid mouse events)
|
|
4992
|
+
const scheduleAnimation = () => {
|
|
4993
|
+
startAnimation();
|
|
4994
|
+
value["events"].animationStart?.notify();
|
|
4995
|
+
activeAnimation?.then(() => {
|
|
4996
|
+
value["events"].animationComplete?.notify();
|
|
4997
|
+
});
|
|
4998
|
+
};
|
|
4879
4999
|
value.attach((v, set) => {
|
|
4880
5000
|
latestValue = v;
|
|
4881
5001
|
latestSetter = (latest) => set(parseValue(latest, unit));
|
|
4882
|
-
frame.postRender(
|
|
4883
|
-
startAnimation();
|
|
4884
|
-
value["events"].animationStart?.notify();
|
|
4885
|
-
activeAnimation?.then(() => {
|
|
4886
|
-
value["events"].animationComplete?.notify();
|
|
4887
|
-
});
|
|
4888
|
-
});
|
|
5002
|
+
frame.postRender(scheduleAnimation);
|
|
4889
5003
|
}, stopAnimation);
|
|
4890
5004
|
if (isMotionValue(source)) {
|
|
4891
|
-
|
|
5005
|
+
let skipNextAnimation = options.skipInitialAnimation === true;
|
|
5006
|
+
const removeSourceOnChange = source.on("change", (v) => {
|
|
5007
|
+
if (skipNextAnimation) {
|
|
5008
|
+
skipNextAnimation = false;
|
|
5009
|
+
value.jump(parseValue(v, unit), false);
|
|
5010
|
+
}
|
|
5011
|
+
else {
|
|
5012
|
+
value.set(parseValue(v, unit));
|
|
5013
|
+
}
|
|
5014
|
+
});
|
|
4892
5015
|
const removeValueOnDestroy = value.on("destroy", removeSourceOnChange);
|
|
4893
5016
|
return () => {
|
|
4894
5017
|
removeSourceOnChange();
|
|
@@ -6181,7 +6304,7 @@
|
|
|
6181
6304
|
applyBoxDelta(box, delta);
|
|
6182
6305
|
}
|
|
6183
6306
|
if (isSharedTransition && hasTransform(node.latestValues)) {
|
|
6184
|
-
transformBox(box, node.latestValues);
|
|
6307
|
+
transformBox(box, node.latestValues, node.layout?.layoutBox);
|
|
6185
6308
|
}
|
|
6186
6309
|
}
|
|
6187
6310
|
/**
|
|
@@ -6220,9 +6343,10 @@
|
|
|
6220
6343
|
/**
|
|
6221
6344
|
* Apply a transform to a box from the latest resolved motion values.
|
|
6222
6345
|
*/
|
|
6223
|
-
function transformBox(box, transform) {
|
|
6224
|
-
|
|
6225
|
-
transformAxis(box.
|
|
6346
|
+
function transformBox(box, transform, sourceBox) {
|
|
6347
|
+
const resolveBox = sourceBox ?? box;
|
|
6348
|
+
transformAxis(box.x, resolveAxisTranslate(transform.x, resolveBox.x), transform.scaleX, transform.scale, transform.originX);
|
|
6349
|
+
transformAxis(box.y, resolveAxisTranslate(transform.y, resolveBox.y), transform.scaleY, transform.scale, transform.originY);
|
|
6226
6350
|
}
|
|
6227
6351
|
|
|
6228
6352
|
function measureViewportBox(instance, transformPoint) {
|
|
@@ -7978,6 +8102,14 @@
|
|
|
7978
8102
|
for (let i = 0; i < this.path.length; i++) {
|
|
7979
8103
|
const node = this.path[i];
|
|
7980
8104
|
node.shouldResetTransform = true;
|
|
8105
|
+
/**
|
|
8106
|
+
* Percentage translates resolve against layoutBox dimensions,
|
|
8107
|
+
* so ancestors with them must be re-measured after transform reset.
|
|
8108
|
+
*/
|
|
8109
|
+
if (typeof node.latestValues.x === "string" ||
|
|
8110
|
+
typeof node.latestValues.y === "string") {
|
|
8111
|
+
node.isLayoutDirty = true;
|
|
8112
|
+
}
|
|
7981
8113
|
node.updateScroll("snapshot");
|
|
7982
8114
|
if (node.options.layoutRoot) {
|
|
7983
8115
|
node.willUpdate(false);
|
|
@@ -8243,10 +8375,10 @@
|
|
|
8243
8375
|
}
|
|
8244
8376
|
if (!hasTransform(node.latestValues))
|
|
8245
8377
|
continue;
|
|
8246
|
-
transformBox(withTransforms, node.latestValues);
|
|
8378
|
+
transformBox(withTransforms, node.latestValues, node.layout?.layoutBox);
|
|
8247
8379
|
}
|
|
8248
8380
|
if (hasTransform(this.latestValues)) {
|
|
8249
|
-
transformBox(withTransforms, this.latestValues);
|
|
8381
|
+
transformBox(withTransforms, this.latestValues, this.layout?.layoutBox);
|
|
8250
8382
|
}
|
|
8251
8383
|
return withTransforms;
|
|
8252
8384
|
}
|
|
@@ -8255,15 +8387,15 @@
|
|
|
8255
8387
|
copyBoxInto(boxWithoutTransform, box);
|
|
8256
8388
|
for (let i = 0; i < this.path.length; i++) {
|
|
8257
8389
|
const node = this.path[i];
|
|
8258
|
-
if (!node.instance)
|
|
8259
|
-
continue;
|
|
8260
8390
|
if (!hasTransform(node.latestValues))
|
|
8261
8391
|
continue;
|
|
8262
|
-
|
|
8263
|
-
|
|
8264
|
-
|
|
8265
|
-
|
|
8266
|
-
|
|
8392
|
+
let sourceBox;
|
|
8393
|
+
if (node.instance) {
|
|
8394
|
+
hasScale(node.latestValues) && node.updateSnapshot();
|
|
8395
|
+
sourceBox = createBox();
|
|
8396
|
+
copyBoxInto(sourceBox, node.measurePageBox());
|
|
8397
|
+
}
|
|
8398
|
+
removeBoxTransforms(boxWithoutTransform, node.latestValues, node.snapshot?.layoutBox, sourceBox);
|
|
8267
8399
|
}
|
|
8268
8400
|
if (hasTransform(this.latestValues)) {
|
|
8269
8401
|
removeBoxTransforms(boxWithoutTransform, this.latestValues);
|
|
@@ -8993,6 +9125,12 @@
|
|
|
8993
9125
|
axisSnapshot.max = axisSnapshot.min + length;
|
|
8994
9126
|
});
|
|
8995
9127
|
}
|
|
9128
|
+
else if (animationType === "x" || animationType === "y") {
|
|
9129
|
+
const snapAxis = animationType === "x" ? "y" : "x";
|
|
9130
|
+
copyAxisInto(isShared
|
|
9131
|
+
? snapshot.measuredBox[snapAxis]
|
|
9132
|
+
: snapshot.layoutBox[snapAxis], layout[snapAxis]);
|
|
9133
|
+
}
|
|
8996
9134
|
else if (shouldAnimatePositionOnly(animationType, snapshot.layoutBox, layout)) {
|
|
8997
9135
|
eachAxis((axis) => {
|
|
8998
9136
|
const axisSnapshot = isShared
|