motion-dom 12.35.0 → 12.35.2
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 +205 -81
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/JSAnimation.mjs +31 -4
- package/dist/es/animation/JSAnimation.mjs.map +1 -1
- package/dist/es/animation/NativeAnimation.mjs +4 -0
- package/dist/es/animation/NativeAnimation.mjs.map +1 -1
- package/dist/es/animation/NativeAnimationExtended.mjs +17 -2
- 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/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/index.mjs +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 +17 -9
- package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
- package/dist/es/value/follow-value.mjs +19 -9
- 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 +9 -3
- package/dist/motion-dom.dev.js +205 -81
- package/dist/motion-dom.js +1 -1
- package/dist/size-rollup-style-effect.js +1 -1
- package/dist/size-rollup-style-effect.js.map +1 -1
- package/package.json +2 -2
- 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
|
@@ -451,8 +451,7 @@
|
|
|
451
451
|
function parseComplexValue(v) {
|
|
452
452
|
return analyseComplexValue(v).values;
|
|
453
453
|
}
|
|
454
|
-
function
|
|
455
|
-
const { split, types } = analyseComplexValue(source);
|
|
454
|
+
function buildTransformer({ split, types }) {
|
|
456
455
|
const numSections = split.length;
|
|
457
456
|
return (v) => {
|
|
458
457
|
let output = "";
|
|
@@ -474,11 +473,34 @@
|
|
|
474
473
|
return output;
|
|
475
474
|
};
|
|
476
475
|
}
|
|
476
|
+
function createTransformer(source) {
|
|
477
|
+
return buildTransformer(analyseComplexValue(source));
|
|
478
|
+
}
|
|
477
479
|
const convertNumbersToZero = (v) => typeof v === "number" ? 0 : color.test(v) ? color.getAnimatableNone(v) : v;
|
|
480
|
+
/**
|
|
481
|
+
* Convert a parsed value to its zero equivalent, but preserve numbers
|
|
482
|
+
* that act as divisors in CSS calc() expressions.
|
|
483
|
+
*
|
|
484
|
+
* analyseComplexValue extracts numbers from CSS strings and puts the
|
|
485
|
+
* surrounding text into a `split` template array. For example:
|
|
486
|
+
* "calc(var(--gap) / 5)" → values: [var(--gap), 5]
|
|
487
|
+
* split: ["calc(", " / ", ")"]
|
|
488
|
+
*
|
|
489
|
+
* When building a zero-equivalent for animation, naively zeroing all
|
|
490
|
+
* numbers turns the divisor into 0 → "calc(var(--gap) / 0)" → NaN.
|
|
491
|
+
* We detect this by checking whether the text preceding a number
|
|
492
|
+
* (split[i]) ends with "/" — the CSS calc division operator.
|
|
493
|
+
*/
|
|
494
|
+
const convertToZero = (value, splitBefore) => {
|
|
495
|
+
if (typeof value === "number") {
|
|
496
|
+
return splitBefore?.trim().endsWith("/") ? value : 0;
|
|
497
|
+
}
|
|
498
|
+
return convertNumbersToZero(value);
|
|
499
|
+
};
|
|
478
500
|
function getAnimatableNone$1(v) {
|
|
479
|
-
const
|
|
480
|
-
const transformer =
|
|
481
|
-
return transformer(
|
|
501
|
+
const info = analyseComplexValue(v);
|
|
502
|
+
const transformer = buildTransformer(info);
|
|
503
|
+
return transformer(info.values.map((value, i) => convertToZero(value, info.split[i])));
|
|
482
504
|
}
|
|
483
505
|
const complex = {
|
|
484
506
|
test,
|
|
@@ -757,12 +779,6 @@
|
|
|
757
779
|
};
|
|
758
780
|
}
|
|
759
781
|
|
|
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
782
|
const springDefaults = {
|
|
767
783
|
// Default spring physics
|
|
768
784
|
stiffness: 100,
|
|
@@ -788,7 +804,20 @@
|
|
|
788
804
|
minDamping: 0.05,
|
|
789
805
|
maxDamping: 1,
|
|
790
806
|
};
|
|
791
|
-
|
|
807
|
+
function calcAngularFreq(undampedFreq, dampingRatio) {
|
|
808
|
+
return undampedFreq * Math.sqrt(1 - dampingRatio * dampingRatio);
|
|
809
|
+
}
|
|
810
|
+
const rootIterations = 12;
|
|
811
|
+
function approximateRoot(envelope, derivative, initialGuess) {
|
|
812
|
+
let result = initialGuess;
|
|
813
|
+
for (let i = 1; i < rootIterations; i++) {
|
|
814
|
+
result = result - envelope(result) / derivative(result);
|
|
815
|
+
}
|
|
816
|
+
return result;
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
* This is ported from the Framer implementation of duration-based spring resolution.
|
|
820
|
+
*/
|
|
792
821
|
const safeMin = 0.001;
|
|
793
822
|
function findSpring({ duration = springDefaults.duration, bounce = springDefaults.bounce, velocity = springDefaults.velocity, mass = springDefaults.mass, }) {
|
|
794
823
|
let envelope;
|
|
@@ -857,18 +886,6 @@
|
|
|
857
886
|
};
|
|
858
887
|
}
|
|
859
888
|
}
|
|
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
889
|
const durationKeys = ["duration", "bounce"];
|
|
873
890
|
const physicsKeys = ["stiffness", "damping", "mass"];
|
|
874
891
|
function isSpringType(options, keys) {
|
|
@@ -956,19 +973,37 @@
|
|
|
956
973
|
? springDefaults.restDelta.granular
|
|
957
974
|
: springDefaults.restDelta.default);
|
|
958
975
|
let resolveSpring;
|
|
976
|
+
let resolveVelocity;
|
|
977
|
+
// Underdamped coefficients, hoisted for use in the inlined next() hot path
|
|
978
|
+
let angularFreq;
|
|
979
|
+
let A;
|
|
980
|
+
let sinCoeff;
|
|
981
|
+
let cosCoeff;
|
|
959
982
|
if (dampingRatio < 1) {
|
|
960
|
-
|
|
983
|
+
angularFreq = calcAngularFreq(undampedAngularFreq, dampingRatio);
|
|
984
|
+
A =
|
|
985
|
+
(initialVelocity +
|
|
986
|
+
dampingRatio * undampedAngularFreq * initialDelta) /
|
|
987
|
+
angularFreq;
|
|
961
988
|
// Underdamped spring
|
|
962
989
|
resolveSpring = (t) => {
|
|
963
990
|
const envelope = Math.exp(-dampingRatio * undampedAngularFreq * t);
|
|
964
991
|
return (target -
|
|
965
992
|
envelope *
|
|
966
|
-
((
|
|
967
|
-
dampingRatio * undampedAngularFreq * initialDelta) /
|
|
968
|
-
angularFreq) *
|
|
969
|
-
Math.sin(angularFreq * t) +
|
|
993
|
+
(A * Math.sin(angularFreq * t) +
|
|
970
994
|
initialDelta * Math.cos(angularFreq * t)));
|
|
971
995
|
};
|
|
996
|
+
// Analytical derivative of underdamped spring (px/ms)
|
|
997
|
+
sinCoeff =
|
|
998
|
+
dampingRatio * undampedAngularFreq * A + initialDelta * angularFreq;
|
|
999
|
+
cosCoeff =
|
|
1000
|
+
dampingRatio * undampedAngularFreq * initialDelta - A * angularFreq;
|
|
1001
|
+
resolveVelocity = (t) => {
|
|
1002
|
+
const envelope = Math.exp(-dampingRatio * undampedAngularFreq * t);
|
|
1003
|
+
return envelope *
|
|
1004
|
+
(sinCoeff * Math.sin(angularFreq * t) +
|
|
1005
|
+
cosCoeff * Math.cos(angularFreq * t));
|
|
1006
|
+
};
|
|
972
1007
|
}
|
|
973
1008
|
else if (dampingRatio === 1) {
|
|
974
1009
|
// Critically damped spring
|
|
@@ -976,6 +1011,10 @@
|
|
|
976
1011
|
Math.exp(-undampedAngularFreq * t) *
|
|
977
1012
|
(initialDelta +
|
|
978
1013
|
(initialVelocity + undampedAngularFreq * initialDelta) * t);
|
|
1014
|
+
// Analytical derivative of critically damped spring (px/ms)
|
|
1015
|
+
const C = initialVelocity + undampedAngularFreq * initialDelta;
|
|
1016
|
+
resolveVelocity = (t) => Math.exp(-undampedAngularFreq * t) *
|
|
1017
|
+
(undampedAngularFreq * C * t - initialVelocity);
|
|
979
1018
|
}
|
|
980
1019
|
else {
|
|
981
1020
|
// Overdamped spring
|
|
@@ -994,28 +1033,50 @@
|
|
|
994
1033
|
Math.cosh(freqForT))) /
|
|
995
1034
|
dampedAngularFreq);
|
|
996
1035
|
};
|
|
1036
|
+
// Analytical derivative of overdamped spring (px/ms)
|
|
1037
|
+
const P = (initialVelocity +
|
|
1038
|
+
dampingRatio * undampedAngularFreq * initialDelta) /
|
|
1039
|
+
dampedAngularFreq;
|
|
1040
|
+
const sinhCoeff = dampingRatio * undampedAngularFreq * P - initialDelta * dampedAngularFreq;
|
|
1041
|
+
const coshCoeff = dampingRatio * undampedAngularFreq * initialDelta - P * dampedAngularFreq;
|
|
1042
|
+
resolveVelocity = (t) => {
|
|
1043
|
+
const envelope = Math.exp(-dampingRatio * undampedAngularFreq * t);
|
|
1044
|
+
const freqForT = Math.min(dampedAngularFreq * t, 300);
|
|
1045
|
+
return envelope *
|
|
1046
|
+
(sinhCoeff * Math.sinh(freqForT) +
|
|
1047
|
+
coshCoeff * Math.cosh(freqForT));
|
|
1048
|
+
};
|
|
997
1049
|
}
|
|
998
1050
|
const generator = {
|
|
999
1051
|
calculatedDuration: isResolvedFromDuration ? duration || null : null,
|
|
1052
|
+
velocity: (t) => motionUtils.secondsToMilliseconds(resolveVelocity(t)),
|
|
1000
1053
|
next: (t) => {
|
|
1054
|
+
/**
|
|
1055
|
+
* For underdamped physics springs we need both position and
|
|
1056
|
+
* velocity each tick. Compute shared trig values once to avoid
|
|
1057
|
+
* duplicate Math.exp/sin/cos calls on the hot path.
|
|
1058
|
+
*/
|
|
1059
|
+
if (!isResolvedFromDuration && dampingRatio < 1) {
|
|
1060
|
+
const envelope = Math.exp(-dampingRatio * undampedAngularFreq * t);
|
|
1061
|
+
const sin = Math.sin(angularFreq * t);
|
|
1062
|
+
const cos = Math.cos(angularFreq * t);
|
|
1063
|
+
const current = target -
|
|
1064
|
+
envelope *
|
|
1065
|
+
(A * sin + initialDelta * cos);
|
|
1066
|
+
const currentVelocity = motionUtils.secondsToMilliseconds(envelope *
|
|
1067
|
+
(sinCoeff * sin + cosCoeff * cos));
|
|
1068
|
+
state.done =
|
|
1069
|
+
Math.abs(currentVelocity) <= restSpeed &&
|
|
1070
|
+
Math.abs(target - current) <= restDelta;
|
|
1071
|
+
state.value = state.done ? target : current;
|
|
1072
|
+
return state;
|
|
1073
|
+
}
|
|
1001
1074
|
const current = resolveSpring(t);
|
|
1002
1075
|
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;
|
|
1076
|
+
const currentVelocity = motionUtils.secondsToMilliseconds(resolveVelocity(t));
|
|
1017
1077
|
state.done =
|
|
1018
|
-
|
|
1078
|
+
Math.abs(currentVelocity) <= restSpeed &&
|
|
1079
|
+
Math.abs(target - current) <= restDelta;
|
|
1019
1080
|
}
|
|
1020
1081
|
else {
|
|
1021
1082
|
state.done = t >= duration;
|
|
@@ -1040,6 +1101,12 @@
|
|
|
1040
1101
|
return options;
|
|
1041
1102
|
};
|
|
1042
1103
|
|
|
1104
|
+
const velocitySampleDuration = 5; // ms
|
|
1105
|
+
function getGeneratorVelocity(resolveValue, t, current) {
|
|
1106
|
+
const prevT = Math.max(t - velocitySampleDuration, 0);
|
|
1107
|
+
return motionUtils.velocityPerSecond(current - resolveValue(prevT), t - prevT);
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1043
1110
|
function inertia({ keyframes, velocity = 0.0, power = 0.8, timeConstant = 325, bounceDamping = 10, bounceStiffness = 500, modifyTarget, min, max, restDelta = 0.5, restSpeed, }) {
|
|
1044
1111
|
const origin = keyframes[0];
|
|
1045
1112
|
const state = {
|
|
@@ -1085,7 +1152,7 @@
|
|
|
1085
1152
|
timeReachedBoundary = t;
|
|
1086
1153
|
spring$1 = spring({
|
|
1087
1154
|
keyframes: [state.value, nearestBoundary(state.value)],
|
|
1088
|
-
velocity:
|
|
1155
|
+
velocity: getGeneratorVelocity(calcLatest, t, state.value), // TODO: This should be passing * 1000
|
|
1089
1156
|
damping: bounceDamping,
|
|
1090
1157
|
stiffness: bounceStiffness,
|
|
1091
1158
|
restDelta,
|
|
@@ -1485,7 +1552,7 @@
|
|
|
1485
1552
|
const state = isInDelayPhase
|
|
1486
1553
|
? { done: false, value: keyframes[0] }
|
|
1487
1554
|
: frameGenerator.next(elapsed);
|
|
1488
|
-
if (mixKeyframes) {
|
|
1555
|
+
if (mixKeyframes && !isInDelayPhase) {
|
|
1489
1556
|
state.value = mixKeyframes(state.value);
|
|
1490
1557
|
}
|
|
1491
1558
|
let { done } = state;
|
|
@@ -1538,16 +1605,42 @@
|
|
|
1538
1605
|
else if (this.driver) {
|
|
1539
1606
|
this.startTime = this.driver.now() - newTime / this.playbackSpeed;
|
|
1540
1607
|
}
|
|
1541
|
-
this.driver
|
|
1608
|
+
if (this.driver) {
|
|
1609
|
+
this.driver.start(false);
|
|
1610
|
+
}
|
|
1611
|
+
else {
|
|
1612
|
+
this.startTime = 0;
|
|
1613
|
+
this.state = "paused";
|
|
1614
|
+
this.holdTime = newTime;
|
|
1615
|
+
this.tick(newTime);
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
/**
|
|
1619
|
+
* Returns the generator's velocity at the current time in units/second.
|
|
1620
|
+
* Uses the analytical derivative when available (springs), avoiding
|
|
1621
|
+
* the MotionValue's frame-dependent velocity estimation.
|
|
1622
|
+
*/
|
|
1623
|
+
getGeneratorVelocity() {
|
|
1624
|
+
const t = this.currentTime;
|
|
1625
|
+
if (t <= 0)
|
|
1626
|
+
return this.options.velocity || 0;
|
|
1627
|
+
if (this.generator.velocity) {
|
|
1628
|
+
return this.generator.velocity(t);
|
|
1629
|
+
}
|
|
1630
|
+
// Fallback: finite difference
|
|
1631
|
+
const current = this.generator.next(t).value;
|
|
1632
|
+
return getGeneratorVelocity((s) => this.generator.next(s).value, t, current);
|
|
1542
1633
|
}
|
|
1543
1634
|
get speed() {
|
|
1544
1635
|
return this.playbackSpeed;
|
|
1545
1636
|
}
|
|
1546
1637
|
set speed(newSpeed) {
|
|
1547
|
-
this.updateTime(time.now());
|
|
1548
1638
|
const hasChanged = this.playbackSpeed !== newSpeed;
|
|
1639
|
+
if (hasChanged && this.driver) {
|
|
1640
|
+
this.updateTime(time.now());
|
|
1641
|
+
}
|
|
1549
1642
|
this.playbackSpeed = newSpeed;
|
|
1550
|
-
if (hasChanged) {
|
|
1643
|
+
if (hasChanged && this.driver) {
|
|
1551
1644
|
this.time = motionUtils.millisecondsToSeconds(this.currentTime);
|
|
1552
1645
|
}
|
|
1553
1646
|
}
|
|
@@ -2157,9 +2250,13 @@
|
|
|
2157
2250
|
return motionUtils.millisecondsToSeconds(Number(this.animation.currentTime) || 0);
|
|
2158
2251
|
}
|
|
2159
2252
|
set time(newTime) {
|
|
2253
|
+
const wasFinished = this.finishedTime !== null;
|
|
2160
2254
|
this.manualStartTime = null;
|
|
2161
2255
|
this.finishedTime = null;
|
|
2162
2256
|
this.animation.currentTime = motionUtils.secondsToMilliseconds(newTime);
|
|
2257
|
+
if (wasFinished) {
|
|
2258
|
+
this.animation.pause();
|
|
2259
|
+
}
|
|
2163
2260
|
}
|
|
2164
2261
|
/**
|
|
2165
2262
|
* The playback speed of the animation.
|
|
@@ -2249,7 +2346,12 @@
|
|
|
2249
2346
|
*/
|
|
2250
2347
|
replaceTransitionType(options);
|
|
2251
2348
|
super(options);
|
|
2252
|
-
|
|
2349
|
+
/**
|
|
2350
|
+
* Only set startTime when the animation should autoplay.
|
|
2351
|
+
* Setting startTime on a paused WAAPI animation unpauses it
|
|
2352
|
+
* (per the WAAPI spec), which breaks autoplay: false.
|
|
2353
|
+
*/
|
|
2354
|
+
if (options.startTime !== undefined && options.autoplay !== false) {
|
|
2253
2355
|
this.startTime = options.startTime;
|
|
2254
2356
|
}
|
|
2255
2357
|
this.options = options;
|
|
@@ -2281,7 +2383,16 @@
|
|
|
2281
2383
|
*/
|
|
2282
2384
|
const sampleTime = Math.max(sampleDelta, time.now() - this.startTime);
|
|
2283
2385
|
const delta = motionUtils.clamp(0, sampleDelta, sampleTime - sampleDelta);
|
|
2284
|
-
|
|
2386
|
+
const current = sampleAnimation.sample(sampleTime).value;
|
|
2387
|
+
/**
|
|
2388
|
+
* Write the estimated value to inline style so it persists
|
|
2389
|
+
* after cancel(), covering the async gap before the next
|
|
2390
|
+
* animation starts.
|
|
2391
|
+
*/
|
|
2392
|
+
const { name } = this.options;
|
|
2393
|
+
if (element && name)
|
|
2394
|
+
setStyle(element, name, current);
|
|
2395
|
+
motionValue.setWithVelocity(sampleAnimation.sample(Math.max(0, sampleTime - delta)).value, current, delta);
|
|
2285
2396
|
sampleAnimation.stop();
|
|
2286
2397
|
}
|
|
2287
2398
|
}
|
|
@@ -4022,19 +4133,14 @@
|
|
|
4022
4133
|
get(name) {
|
|
4023
4134
|
return this.values.get(name)?.value;
|
|
4024
4135
|
}
|
|
4025
|
-
destroy() {
|
|
4026
|
-
for (const value of this.values.values()) {
|
|
4027
|
-
value.onRemove();
|
|
4028
|
-
}
|
|
4029
|
-
}
|
|
4030
4136
|
}
|
|
4031
4137
|
|
|
4032
4138
|
function createEffect(addValue) {
|
|
4033
4139
|
const stateCache = new WeakMap();
|
|
4034
|
-
const subscriptions = [];
|
|
4035
4140
|
return (subject, values) => {
|
|
4036
4141
|
const state = stateCache.get(subject) ?? new MotionValueState();
|
|
4037
4142
|
stateCache.set(subject, state);
|
|
4143
|
+
const subscriptions = [];
|
|
4038
4144
|
for (const key in values) {
|
|
4039
4145
|
const value = values[key];
|
|
4040
4146
|
const remove = addValue(subject, state, key, value);
|
|
@@ -4126,8 +4232,7 @@
|
|
|
4126
4232
|
if (!valueIsDefault) {
|
|
4127
4233
|
transformIsDefault = false;
|
|
4128
4234
|
const transformName = translateAlias$1[key] || key;
|
|
4129
|
-
|
|
4130
|
-
transform += `${transformName}(${valueToRender}) `;
|
|
4235
|
+
transform += `${transformName}(${value}) `;
|
|
4131
4236
|
}
|
|
4132
4237
|
}
|
|
4133
4238
|
return transformIsDefault ? "none" : transform.trim();
|
|
@@ -4835,16 +4940,23 @@
|
|
|
4835
4940
|
}
|
|
4836
4941
|
};
|
|
4837
4942
|
const startAnimation = () => {
|
|
4838
|
-
stopAnimation();
|
|
4839
4943
|
const currentValue = asNumber$1(value.get());
|
|
4840
4944
|
const targetValue = asNumber$1(latestValue);
|
|
4841
4945
|
// Don't animate if we're already at the target
|
|
4842
4946
|
if (currentValue === targetValue) {
|
|
4947
|
+
stopAnimation();
|
|
4843
4948
|
return;
|
|
4844
4949
|
}
|
|
4950
|
+
// Use the running animation's analytical velocity for accuracy,
|
|
4951
|
+
// falling back to the MotionValue's velocity for the initial animation.
|
|
4952
|
+
// This prevents systematic velocity loss at high frame rates (240hz+).
|
|
4953
|
+
const velocity = activeAnimation
|
|
4954
|
+
? activeAnimation.getGeneratorVelocity()
|
|
4955
|
+
: value.getVelocity();
|
|
4956
|
+
stopAnimation();
|
|
4845
4957
|
activeAnimation = new JSAnimation({
|
|
4846
4958
|
keyframes: [currentValue, targetValue],
|
|
4847
|
-
velocity
|
|
4959
|
+
velocity,
|
|
4848
4960
|
// Default to spring if no type specified (matches useSpring behavior)
|
|
4849
4961
|
type: "spring",
|
|
4850
4962
|
restDelta: 0.001,
|
|
@@ -4853,16 +4965,19 @@
|
|
|
4853
4965
|
onUpdate: latestSetter,
|
|
4854
4966
|
});
|
|
4855
4967
|
};
|
|
4968
|
+
// Use a stable function reference so the frame loop Set deduplicates
|
|
4969
|
+
// multiple calls within the same frame (e.g. rapid mouse events)
|
|
4970
|
+
const scheduleAnimation = () => {
|
|
4971
|
+
startAnimation();
|
|
4972
|
+
value["events"].animationStart?.notify();
|
|
4973
|
+
activeAnimation?.then(() => {
|
|
4974
|
+
value["events"].animationComplete?.notify();
|
|
4975
|
+
});
|
|
4976
|
+
};
|
|
4856
4977
|
value.attach((v, set) => {
|
|
4857
4978
|
latestValue = v;
|
|
4858
4979
|
latestSetter = (latest) => set(parseValue(latest, unit));
|
|
4859
|
-
frame.postRender(
|
|
4860
|
-
startAnimation();
|
|
4861
|
-
value["events"].animationStart?.notify();
|
|
4862
|
-
activeAnimation?.then(() => {
|
|
4863
|
-
value["events"].animationComplete?.notify();
|
|
4864
|
-
});
|
|
4865
|
-
});
|
|
4980
|
+
frame.postRender(scheduleAnimation);
|
|
4866
4981
|
}, stopAnimation);
|
|
4867
4982
|
if (isMotionValue(source)) {
|
|
4868
4983
|
const removeSourceOnChange = source.on("change", (v) => value.set(parseValue(v, unit)));
|
|
@@ -6158,7 +6273,7 @@
|
|
|
6158
6273
|
applyBoxDelta(box, delta);
|
|
6159
6274
|
}
|
|
6160
6275
|
if (isSharedTransition && hasTransform(node.latestValues)) {
|
|
6161
|
-
transformBox(box, node.latestValues);
|
|
6276
|
+
transformBox(box, node.latestValues, node.layout?.layoutBox);
|
|
6162
6277
|
}
|
|
6163
6278
|
}
|
|
6164
6279
|
/**
|
|
@@ -6197,9 +6312,10 @@
|
|
|
6197
6312
|
/**
|
|
6198
6313
|
* Apply a transform to a box from the latest resolved motion values.
|
|
6199
6314
|
*/
|
|
6200
|
-
function transformBox(box, transform) {
|
|
6201
|
-
|
|
6202
|
-
transformAxis(box.
|
|
6315
|
+
function transformBox(box, transform, sourceBox) {
|
|
6316
|
+
const resolveBox = sourceBox ?? box;
|
|
6317
|
+
transformAxis(box.x, resolveAxisTranslate(transform.x, resolveBox.x), transform.scaleX, transform.scale, transform.originX);
|
|
6318
|
+
transformAxis(box.y, resolveAxisTranslate(transform.y, resolveBox.y), transform.scaleY, transform.scale, transform.originY);
|
|
6203
6319
|
}
|
|
6204
6320
|
|
|
6205
6321
|
function measureViewportBox(instance, transformPoint) {
|
|
@@ -7955,6 +8071,14 @@
|
|
|
7955
8071
|
for (let i = 0; i < this.path.length; i++) {
|
|
7956
8072
|
const node = this.path[i];
|
|
7957
8073
|
node.shouldResetTransform = true;
|
|
8074
|
+
/**
|
|
8075
|
+
* Percentage translates resolve against layoutBox dimensions,
|
|
8076
|
+
* so ancestors with them must be re-measured after transform reset.
|
|
8077
|
+
*/
|
|
8078
|
+
if (typeof node.latestValues.x === "string" ||
|
|
8079
|
+
typeof node.latestValues.y === "string") {
|
|
8080
|
+
node.isLayoutDirty = true;
|
|
8081
|
+
}
|
|
7958
8082
|
node.updateScroll("snapshot");
|
|
7959
8083
|
if (node.options.layoutRoot) {
|
|
7960
8084
|
node.willUpdate(false);
|
|
@@ -8220,10 +8344,10 @@
|
|
|
8220
8344
|
}
|
|
8221
8345
|
if (!hasTransform(node.latestValues))
|
|
8222
8346
|
continue;
|
|
8223
|
-
transformBox(withTransforms, node.latestValues);
|
|
8347
|
+
transformBox(withTransforms, node.latestValues, node.layout?.layoutBox);
|
|
8224
8348
|
}
|
|
8225
8349
|
if (hasTransform(this.latestValues)) {
|
|
8226
|
-
transformBox(withTransforms, this.latestValues);
|
|
8350
|
+
transformBox(withTransforms, this.latestValues, this.layout?.layoutBox);
|
|
8227
8351
|
}
|
|
8228
8352
|
return withTransforms;
|
|
8229
8353
|
}
|
|
@@ -8232,15 +8356,15 @@
|
|
|
8232
8356
|
copyBoxInto(boxWithoutTransform, box);
|
|
8233
8357
|
for (let i = 0; i < this.path.length; i++) {
|
|
8234
8358
|
const node = this.path[i];
|
|
8235
|
-
if (!node.instance)
|
|
8236
|
-
continue;
|
|
8237
8359
|
if (!hasTransform(node.latestValues))
|
|
8238
8360
|
continue;
|
|
8239
|
-
|
|
8240
|
-
|
|
8241
|
-
|
|
8242
|
-
|
|
8243
|
-
|
|
8361
|
+
let sourceBox;
|
|
8362
|
+
if (node.instance) {
|
|
8363
|
+
hasScale(node.latestValues) && node.updateSnapshot();
|
|
8364
|
+
sourceBox = createBox();
|
|
8365
|
+
copyBoxInto(sourceBox, node.measurePageBox());
|
|
8366
|
+
}
|
|
8367
|
+
removeBoxTransforms(boxWithoutTransform, node.latestValues, node.snapshot?.layoutBox, sourceBox);
|
|
8244
8368
|
}
|
|
8245
8369
|
if (hasTransform(this.latestValues)) {
|
|
8246
8370
|
removeBoxTransforms(boxWithoutTransform, this.latestValues);
|