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/cjs/index.js
CHANGED
|
@@ -451,8 +451,7 @@ function analyseComplexValue(value) {
|
|
|
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 @@ function createTransformer(source) {
|
|
|
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 @@ function createGeneratorEasing(options, scale = 100, createGenerator) {
|
|
|
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 @@ const springDefaults = {
|
|
|
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 @@ function findSpring({ duration = springDefaults.duration, bounce = springDefault
|
|
|
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 @@ function spring(optionsOrVisualDuration = springDefaults.visualDuration, bounce
|
|
|
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 @@ function spring(optionsOrVisualDuration = springDefaults.visualDuration, bounce
|
|
|
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 @@ function spring(optionsOrVisualDuration = springDefaults.visualDuration, bounce
|
|
|
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 @@ spring.applyToOptions = (options) => {
|
|
|
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 @@ function inertia({ keyframes, velocity = 0.0, power = 0.8, timeConstant = 325, b
|
|
|
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,
|
|
@@ -1486,7 +1553,7 @@ class JSAnimation extends WithPromise {
|
|
|
1486
1553
|
const state = isInDelayPhase
|
|
1487
1554
|
? { done: false, value: keyframes[0] }
|
|
1488
1555
|
: frameGenerator.next(elapsed);
|
|
1489
|
-
if (mixKeyframes) {
|
|
1556
|
+
if (mixKeyframes && !isInDelayPhase) {
|
|
1490
1557
|
state.value = mixKeyframes(state.value);
|
|
1491
1558
|
}
|
|
1492
1559
|
let { done } = state;
|
|
@@ -1539,16 +1606,42 @@ class JSAnimation extends WithPromise {
|
|
|
1539
1606
|
else if (this.driver) {
|
|
1540
1607
|
this.startTime = this.driver.now() - newTime / this.playbackSpeed;
|
|
1541
1608
|
}
|
|
1542
|
-
this.driver
|
|
1609
|
+
if (this.driver) {
|
|
1610
|
+
this.driver.start(false);
|
|
1611
|
+
}
|
|
1612
|
+
else {
|
|
1613
|
+
this.startTime = 0;
|
|
1614
|
+
this.state = "paused";
|
|
1615
|
+
this.holdTime = newTime;
|
|
1616
|
+
this.tick(newTime);
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
/**
|
|
1620
|
+
* Returns the generator's velocity at the current time in units/second.
|
|
1621
|
+
* Uses the analytical derivative when available (springs), avoiding
|
|
1622
|
+
* the MotionValue's frame-dependent velocity estimation.
|
|
1623
|
+
*/
|
|
1624
|
+
getGeneratorVelocity() {
|
|
1625
|
+
const t = this.currentTime;
|
|
1626
|
+
if (t <= 0)
|
|
1627
|
+
return this.options.velocity || 0;
|
|
1628
|
+
if (this.generator.velocity) {
|
|
1629
|
+
return this.generator.velocity(t);
|
|
1630
|
+
}
|
|
1631
|
+
// Fallback: finite difference
|
|
1632
|
+
const current = this.generator.next(t).value;
|
|
1633
|
+
return getGeneratorVelocity((s) => this.generator.next(s).value, t, current);
|
|
1543
1634
|
}
|
|
1544
1635
|
get speed() {
|
|
1545
1636
|
return this.playbackSpeed;
|
|
1546
1637
|
}
|
|
1547
1638
|
set speed(newSpeed) {
|
|
1548
|
-
this.updateTime(time.now());
|
|
1549
1639
|
const hasChanged = this.playbackSpeed !== newSpeed;
|
|
1640
|
+
if (hasChanged && this.driver) {
|
|
1641
|
+
this.updateTime(time.now());
|
|
1642
|
+
}
|
|
1550
1643
|
this.playbackSpeed = newSpeed;
|
|
1551
|
-
if (hasChanged) {
|
|
1644
|
+
if (hasChanged && this.driver) {
|
|
1552
1645
|
this.time = motionUtils.millisecondsToSeconds(this.currentTime);
|
|
1553
1646
|
}
|
|
1554
1647
|
}
|
|
@@ -2158,9 +2251,13 @@ class NativeAnimation extends WithPromise {
|
|
|
2158
2251
|
return motionUtils.millisecondsToSeconds(Number(this.animation.currentTime) || 0);
|
|
2159
2252
|
}
|
|
2160
2253
|
set time(newTime) {
|
|
2254
|
+
const wasFinished = this.finishedTime !== null;
|
|
2161
2255
|
this.manualStartTime = null;
|
|
2162
2256
|
this.finishedTime = null;
|
|
2163
2257
|
this.animation.currentTime = motionUtils.secondsToMilliseconds(newTime);
|
|
2258
|
+
if (wasFinished) {
|
|
2259
|
+
this.animation.pause();
|
|
2260
|
+
}
|
|
2164
2261
|
}
|
|
2165
2262
|
/**
|
|
2166
2263
|
* The playback speed of the animation.
|
|
@@ -2250,7 +2347,12 @@ class NativeAnimationExtended extends NativeAnimation {
|
|
|
2250
2347
|
*/
|
|
2251
2348
|
replaceTransitionType(options);
|
|
2252
2349
|
super(options);
|
|
2253
|
-
|
|
2350
|
+
/**
|
|
2351
|
+
* Only set startTime when the animation should autoplay.
|
|
2352
|
+
* Setting startTime on a paused WAAPI animation unpauses it
|
|
2353
|
+
* (per the WAAPI spec), which breaks autoplay: false.
|
|
2354
|
+
*/
|
|
2355
|
+
if (options.startTime !== undefined && options.autoplay !== false) {
|
|
2254
2356
|
this.startTime = options.startTime;
|
|
2255
2357
|
}
|
|
2256
2358
|
this.options = options;
|
|
@@ -2282,7 +2384,16 @@ class NativeAnimationExtended extends NativeAnimation {
|
|
|
2282
2384
|
*/
|
|
2283
2385
|
const sampleTime = Math.max(sampleDelta, time.now() - this.startTime);
|
|
2284
2386
|
const delta = motionUtils.clamp(0, sampleDelta, sampleTime - sampleDelta);
|
|
2285
|
-
|
|
2387
|
+
const current = sampleAnimation.sample(sampleTime).value;
|
|
2388
|
+
/**
|
|
2389
|
+
* Write the estimated value to inline style so it persists
|
|
2390
|
+
* after cancel(), covering the async gap before the next
|
|
2391
|
+
* animation starts.
|
|
2392
|
+
*/
|
|
2393
|
+
const { name } = this.options;
|
|
2394
|
+
if (element && name)
|
|
2395
|
+
setStyle(element, name, current);
|
|
2396
|
+
motionValue.setWithVelocity(sampleAnimation.sample(Math.max(0, sampleTime - delta)).value, current, delta);
|
|
2286
2397
|
sampleAnimation.stop();
|
|
2287
2398
|
}
|
|
2288
2399
|
}
|
|
@@ -4023,19 +4134,14 @@ class MotionValueState {
|
|
|
4023
4134
|
get(name) {
|
|
4024
4135
|
return this.values.get(name)?.value;
|
|
4025
4136
|
}
|
|
4026
|
-
destroy() {
|
|
4027
|
-
for (const value of this.values.values()) {
|
|
4028
|
-
value.onRemove();
|
|
4029
|
-
}
|
|
4030
|
-
}
|
|
4031
4137
|
}
|
|
4032
4138
|
|
|
4033
4139
|
function createEffect(addValue) {
|
|
4034
4140
|
const stateCache = new WeakMap();
|
|
4035
|
-
const subscriptions = [];
|
|
4036
4141
|
return (subject, values) => {
|
|
4037
4142
|
const state = stateCache.get(subject) ?? new MotionValueState();
|
|
4038
4143
|
stateCache.set(subject, state);
|
|
4144
|
+
const subscriptions = [];
|
|
4039
4145
|
for (const key in values) {
|
|
4040
4146
|
const value = values[key];
|
|
4041
4147
|
const remove = addValue(subject, state, key, value);
|
|
@@ -4127,8 +4233,7 @@ function buildTransform$1(state) {
|
|
|
4127
4233
|
if (!valueIsDefault) {
|
|
4128
4234
|
transformIsDefault = false;
|
|
4129
4235
|
const transformName = translateAlias$1[key] || key;
|
|
4130
|
-
|
|
4131
|
-
transform += `${transformName}(${valueToRender}) `;
|
|
4236
|
+
transform += `${transformName}(${value}) `;
|
|
4132
4237
|
}
|
|
4133
4238
|
}
|
|
4134
4239
|
return transformIsDefault ? "none" : transform.trim();
|
|
@@ -4836,16 +4941,23 @@ function attachFollow(value, source, options = {}) {
|
|
|
4836
4941
|
}
|
|
4837
4942
|
};
|
|
4838
4943
|
const startAnimation = () => {
|
|
4839
|
-
stopAnimation();
|
|
4840
4944
|
const currentValue = asNumber$1(value.get());
|
|
4841
4945
|
const targetValue = asNumber$1(latestValue);
|
|
4842
4946
|
// Don't animate if we're already at the target
|
|
4843
4947
|
if (currentValue === targetValue) {
|
|
4948
|
+
stopAnimation();
|
|
4844
4949
|
return;
|
|
4845
4950
|
}
|
|
4951
|
+
// Use the running animation's analytical velocity for accuracy,
|
|
4952
|
+
// falling back to the MotionValue's velocity for the initial animation.
|
|
4953
|
+
// This prevents systematic velocity loss at high frame rates (240hz+).
|
|
4954
|
+
const velocity = activeAnimation
|
|
4955
|
+
? activeAnimation.getGeneratorVelocity()
|
|
4956
|
+
: value.getVelocity();
|
|
4957
|
+
stopAnimation();
|
|
4846
4958
|
activeAnimation = new JSAnimation({
|
|
4847
4959
|
keyframes: [currentValue, targetValue],
|
|
4848
|
-
velocity
|
|
4960
|
+
velocity,
|
|
4849
4961
|
// Default to spring if no type specified (matches useSpring behavior)
|
|
4850
4962
|
type: "spring",
|
|
4851
4963
|
restDelta: 0.001,
|
|
@@ -4854,16 +4966,19 @@ function attachFollow(value, source, options = {}) {
|
|
|
4854
4966
|
onUpdate: latestSetter,
|
|
4855
4967
|
});
|
|
4856
4968
|
};
|
|
4969
|
+
// Use a stable function reference so the frame loop Set deduplicates
|
|
4970
|
+
// multiple calls within the same frame (e.g. rapid mouse events)
|
|
4971
|
+
const scheduleAnimation = () => {
|
|
4972
|
+
startAnimation();
|
|
4973
|
+
value["events"].animationStart?.notify();
|
|
4974
|
+
activeAnimation?.then(() => {
|
|
4975
|
+
value["events"].animationComplete?.notify();
|
|
4976
|
+
});
|
|
4977
|
+
};
|
|
4857
4978
|
value.attach((v, set) => {
|
|
4858
4979
|
latestValue = v;
|
|
4859
4980
|
latestSetter = (latest) => set(parseValue(latest, unit));
|
|
4860
|
-
frame.postRender(
|
|
4861
|
-
startAnimation();
|
|
4862
|
-
value["events"].animationStart?.notify();
|
|
4863
|
-
activeAnimation?.then(() => {
|
|
4864
|
-
value["events"].animationComplete?.notify();
|
|
4865
|
-
});
|
|
4866
|
-
});
|
|
4981
|
+
frame.postRender(scheduleAnimation);
|
|
4867
4982
|
}, stopAnimation);
|
|
4868
4983
|
if (isMotionValue(source)) {
|
|
4869
4984
|
const removeSourceOnChange = source.on("change", (v) => value.set(parseValue(v, unit)));
|
|
@@ -6159,7 +6274,7 @@ function applyTreeDeltas(box, treeScale, treePath, isSharedTransition = false) {
|
|
|
6159
6274
|
applyBoxDelta(box, delta);
|
|
6160
6275
|
}
|
|
6161
6276
|
if (isSharedTransition && hasTransform(node.latestValues)) {
|
|
6162
|
-
transformBox(box, node.latestValues);
|
|
6277
|
+
transformBox(box, node.latestValues, node.layout?.layoutBox);
|
|
6163
6278
|
}
|
|
6164
6279
|
}
|
|
6165
6280
|
/**
|
|
@@ -6198,9 +6313,10 @@ function resolveAxisTranslate(value, axis) {
|
|
|
6198
6313
|
/**
|
|
6199
6314
|
* Apply a transform to a box from the latest resolved motion values.
|
|
6200
6315
|
*/
|
|
6201
|
-
function transformBox(box, transform) {
|
|
6202
|
-
|
|
6203
|
-
transformAxis(box.
|
|
6316
|
+
function transformBox(box, transform, sourceBox) {
|
|
6317
|
+
const resolveBox = sourceBox ?? box;
|
|
6318
|
+
transformAxis(box.x, resolveAxisTranslate(transform.x, resolveBox.x), transform.scaleX, transform.scale, transform.originX);
|
|
6319
|
+
transformAxis(box.y, resolveAxisTranslate(transform.y, resolveBox.y), transform.scaleY, transform.scale, transform.originY);
|
|
6204
6320
|
}
|
|
6205
6321
|
|
|
6206
6322
|
function measureViewportBox(instance, transformPoint) {
|
|
@@ -7956,6 +8072,14 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
7956
8072
|
for (let i = 0; i < this.path.length; i++) {
|
|
7957
8073
|
const node = this.path[i];
|
|
7958
8074
|
node.shouldResetTransform = true;
|
|
8075
|
+
/**
|
|
8076
|
+
* Percentage translates resolve against layoutBox dimensions,
|
|
8077
|
+
* so ancestors with them must be re-measured after transform reset.
|
|
8078
|
+
*/
|
|
8079
|
+
if (typeof node.latestValues.x === "string" ||
|
|
8080
|
+
typeof node.latestValues.y === "string") {
|
|
8081
|
+
node.isLayoutDirty = true;
|
|
8082
|
+
}
|
|
7959
8083
|
node.updateScroll("snapshot");
|
|
7960
8084
|
if (node.options.layoutRoot) {
|
|
7961
8085
|
node.willUpdate(false);
|
|
@@ -8221,10 +8345,10 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8221
8345
|
}
|
|
8222
8346
|
if (!hasTransform(node.latestValues))
|
|
8223
8347
|
continue;
|
|
8224
|
-
transformBox(withTransforms, node.latestValues);
|
|
8348
|
+
transformBox(withTransforms, node.latestValues, node.layout?.layoutBox);
|
|
8225
8349
|
}
|
|
8226
8350
|
if (hasTransform(this.latestValues)) {
|
|
8227
|
-
transformBox(withTransforms, this.latestValues);
|
|
8351
|
+
transformBox(withTransforms, this.latestValues, this.layout?.layoutBox);
|
|
8228
8352
|
}
|
|
8229
8353
|
return withTransforms;
|
|
8230
8354
|
}
|
|
@@ -8233,15 +8357,15 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8233
8357
|
copyBoxInto(boxWithoutTransform, box);
|
|
8234
8358
|
for (let i = 0; i < this.path.length; i++) {
|
|
8235
8359
|
const node = this.path[i];
|
|
8236
|
-
if (!node.instance)
|
|
8237
|
-
continue;
|
|
8238
8360
|
if (!hasTransform(node.latestValues))
|
|
8239
8361
|
continue;
|
|
8240
|
-
|
|
8241
|
-
|
|
8242
|
-
|
|
8243
|
-
|
|
8244
|
-
|
|
8362
|
+
let sourceBox;
|
|
8363
|
+
if (node.instance) {
|
|
8364
|
+
hasScale(node.latestValues) && node.updateSnapshot();
|
|
8365
|
+
sourceBox = createBox();
|
|
8366
|
+
copyBoxInto(sourceBox, node.measurePageBox());
|
|
8367
|
+
}
|
|
8368
|
+
removeBoxTransforms(boxWithoutTransform, node.latestValues, node.snapshot?.layoutBox, sourceBox);
|
|
8245
8369
|
}
|
|
8246
8370
|
if (hasTransform(this.latestValues)) {
|
|
8247
8371
|
removeBoxTransforms(boxWithoutTransform, this.latestValues);
|