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/cjs/index.js
CHANGED
|
@@ -60,8 +60,7 @@ function createRenderStep(runNextFrame, stepName) {
|
|
|
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 @@ function createRenderStep(runNextFrame, stepName) {
|
|
|
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 @@ function createRenderBatcher(scheduleNextBatch, allowKeepAlive) {
|
|
|
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 @@ function analyseComplexValue(value) {
|
|
|
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 @@ function createTransformer(source) {
|
|
|
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 @@ function createGeneratorEasing(options, scale = 100, createGenerator) {
|
|
|
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 @@ const springDefaults = {
|
|
|
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 @@ function findSpring({ duration = springDefaults.duration, bounce = springDefault
|
|
|
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 @@ function spring(optionsOrVisualDuration = springDefaults.visualDuration, bounce
|
|
|
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 @@ function spring(optionsOrVisualDuration = springDefaults.visualDuration, bounce
|
|
|
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 @@ function spring(optionsOrVisualDuration = springDefaults.visualDuration, bounce
|
|
|
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 @@ spring.applyToOptions = (options) => {
|
|
|
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 @@ function inertia({ keyframes, velocity = 0.0, power = 0.8, timeConstant = 325, b
|
|
|
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,
|
|
@@ -1549,6 +1619,22 @@ class JSAnimation extends WithPromise {
|
|
|
1549
1619
|
this.tick(newTime);
|
|
1550
1620
|
}
|
|
1551
1621
|
}
|
|
1622
|
+
/**
|
|
1623
|
+
* Returns the generator's velocity at the current time in units/second.
|
|
1624
|
+
* Uses the analytical derivative when available (springs), avoiding
|
|
1625
|
+
* the MotionValue's frame-dependent velocity estimation.
|
|
1626
|
+
*/
|
|
1627
|
+
getGeneratorVelocity() {
|
|
1628
|
+
const t = this.currentTime;
|
|
1629
|
+
if (t <= 0)
|
|
1630
|
+
return this.options.velocity || 0;
|
|
1631
|
+
if (this.generator.velocity) {
|
|
1632
|
+
return this.generator.velocity(t);
|
|
1633
|
+
}
|
|
1634
|
+
// Fallback: finite difference
|
|
1635
|
+
const current = this.generator.next(t).value;
|
|
1636
|
+
return getGeneratorVelocity((s) => this.generator.next(s).value, t, current);
|
|
1637
|
+
}
|
|
1552
1638
|
get speed() {
|
|
1553
1639
|
return this.playbackSpeed;
|
|
1554
1640
|
}
|
|
@@ -1779,8 +1865,18 @@ function removeNonTranslationalTransform(visualElement) {
|
|
|
1779
1865
|
}
|
|
1780
1866
|
const positionalValues = {
|
|
1781
1867
|
// Dimensions
|
|
1782
|
-
width: ({ x }, { paddingLeft = "0", paddingRight = "0" }) =>
|
|
1783
|
-
|
|
1868
|
+
width: ({ x }, { paddingLeft = "0", paddingRight = "0", boxSizing }) => {
|
|
1869
|
+
const width = x.max - x.min;
|
|
1870
|
+
return boxSizing === "border-box"
|
|
1871
|
+
? width
|
|
1872
|
+
: width - parseFloat(paddingLeft) - parseFloat(paddingRight);
|
|
1873
|
+
},
|
|
1874
|
+
height: ({ y }, { paddingTop = "0", paddingBottom = "0", boxSizing }) => {
|
|
1875
|
+
const height = y.max - y.min;
|
|
1876
|
+
return boxSizing === "border-box"
|
|
1877
|
+
? height
|
|
1878
|
+
: height - parseFloat(paddingTop) - parseFloat(paddingBottom);
|
|
1879
|
+
},
|
|
1784
1880
|
top: (_bbox, { top }) => parseFloat(top),
|
|
1785
1881
|
left: (_bbox, { left }) => parseFloat(left),
|
|
1786
1882
|
bottom: ({ y }, { top }) => parseFloat(top) + (y.max - y.min),
|
|
@@ -2264,7 +2360,12 @@ class NativeAnimationExtended extends NativeAnimation {
|
|
|
2264
2360
|
*/
|
|
2265
2361
|
replaceTransitionType(options);
|
|
2266
2362
|
super(options);
|
|
2267
|
-
|
|
2363
|
+
/**
|
|
2364
|
+
* Only set startTime when the animation should autoplay.
|
|
2365
|
+
* Setting startTime on a paused WAAPI animation unpauses it
|
|
2366
|
+
* (per the WAAPI spec), which breaks autoplay: false.
|
|
2367
|
+
*/
|
|
2368
|
+
if (options.startTime !== undefined && options.autoplay !== false) {
|
|
2268
2369
|
this.startTime = options.startTime;
|
|
2269
2370
|
}
|
|
2270
2371
|
this.options = options;
|
|
@@ -2467,7 +2568,9 @@ class AsyncMotionValueAnimation extends WithPromise {
|
|
|
2467
2568
|
* If we can't animate this value with the resolved keyframes
|
|
2468
2569
|
* then we should complete it immediately.
|
|
2469
2570
|
*/
|
|
2571
|
+
let canAnimateValue = true;
|
|
2470
2572
|
if (!canAnimate(keyframes, name, type, velocity)) {
|
|
2573
|
+
canAnimateValue = false;
|
|
2471
2574
|
if (motionUtils.MotionGlobalConfig.instantAnimations || !delay) {
|
|
2472
2575
|
onUpdate?.(getFinalKeyframe$1(keyframes, options, finalKeyframe));
|
|
2473
2576
|
}
|
|
@@ -2504,8 +2607,13 @@ class AsyncMotionValueAnimation extends WithPromise {
|
|
|
2504
2607
|
* Animate via WAAPI if possible. If this is a handoff animation, the optimised animation will be running via
|
|
2505
2608
|
* WAAPI. Therefore, this animation must be JS to ensure it runs "under" the
|
|
2506
2609
|
* optimised animation.
|
|
2610
|
+
*
|
|
2611
|
+
* Also skip WAAPI when keyframes aren't animatable, as the resolved
|
|
2612
|
+
* values may not be valid CSS and would trigger browser warnings.
|
|
2507
2613
|
*/
|
|
2508
|
-
const useWaapi =
|
|
2614
|
+
const useWaapi = canAnimateValue &&
|
|
2615
|
+
!isHandoff &&
|
|
2616
|
+
supportsBrowserAnimation(resolvedOptions);
|
|
2509
2617
|
const element = resolvedOptions.motionValue?.owner?.current;
|
|
2510
2618
|
const animation = useWaapi
|
|
2511
2619
|
? new NativeAnimationExtended({
|
|
@@ -4046,19 +4154,14 @@ class MotionValueState {
|
|
|
4046
4154
|
get(name) {
|
|
4047
4155
|
return this.values.get(name)?.value;
|
|
4048
4156
|
}
|
|
4049
|
-
destroy() {
|
|
4050
|
-
for (const value of this.values.values()) {
|
|
4051
|
-
value.onRemove();
|
|
4052
|
-
}
|
|
4053
|
-
}
|
|
4054
4157
|
}
|
|
4055
4158
|
|
|
4056
4159
|
function createEffect(addValue) {
|
|
4057
4160
|
const stateCache = new WeakMap();
|
|
4058
|
-
const subscriptions = [];
|
|
4059
4161
|
return (subject, values) => {
|
|
4060
4162
|
const state = stateCache.get(subject) ?? new MotionValueState();
|
|
4061
4163
|
stateCache.set(subject, state);
|
|
4164
|
+
const subscriptions = [];
|
|
4062
4165
|
for (const key in values) {
|
|
4063
4166
|
const value = values[key];
|
|
4064
4167
|
const remove = addValue(subject, state, key, value);
|
|
@@ -4118,7 +4221,9 @@ const propEffect = /*@__PURE__*/ createEffect((subject, state, key, value) => {
|
|
|
4118
4221
|
* that works across iframes
|
|
4119
4222
|
*/
|
|
4120
4223
|
function isHTMLElement(element) {
|
|
4121
|
-
return motionUtils.isObject(element) &&
|
|
4224
|
+
return (motionUtils.isObject(element) &&
|
|
4225
|
+
"offsetHeight" in element &&
|
|
4226
|
+
!("ownerSVGElement" in element));
|
|
4122
4227
|
}
|
|
4123
4228
|
|
|
4124
4229
|
const translateAlias$1 = {
|
|
@@ -4150,8 +4255,7 @@ function buildTransform$1(state) {
|
|
|
4150
4255
|
if (!valueIsDefault) {
|
|
4151
4256
|
transformIsDefault = false;
|
|
4152
4257
|
const transformName = translateAlias$1[key] || key;
|
|
4153
|
-
|
|
4154
|
-
transform += `${transformName}(${valueToRender}) `;
|
|
4258
|
+
transform += `${transformName}(${value}) `;
|
|
4155
4259
|
}
|
|
4156
4260
|
}
|
|
4157
4261
|
return transformIsDefault ? "none" : transform.trim();
|
|
@@ -4859,16 +4963,23 @@ function attachFollow(value, source, options = {}) {
|
|
|
4859
4963
|
}
|
|
4860
4964
|
};
|
|
4861
4965
|
const startAnimation = () => {
|
|
4862
|
-
stopAnimation();
|
|
4863
4966
|
const currentValue = asNumber$1(value.get());
|
|
4864
4967
|
const targetValue = asNumber$1(latestValue);
|
|
4865
4968
|
// Don't animate if we're already at the target
|
|
4866
4969
|
if (currentValue === targetValue) {
|
|
4970
|
+
stopAnimation();
|
|
4867
4971
|
return;
|
|
4868
4972
|
}
|
|
4973
|
+
// Use the running animation's analytical velocity for accuracy,
|
|
4974
|
+
// falling back to the MotionValue's velocity for the initial animation.
|
|
4975
|
+
// This prevents systematic velocity loss at high frame rates (240hz+).
|
|
4976
|
+
const velocity = activeAnimation
|
|
4977
|
+
? activeAnimation.getGeneratorVelocity()
|
|
4978
|
+
: value.getVelocity();
|
|
4979
|
+
stopAnimation();
|
|
4869
4980
|
activeAnimation = new JSAnimation({
|
|
4870
4981
|
keyframes: [currentValue, targetValue],
|
|
4871
|
-
velocity
|
|
4982
|
+
velocity,
|
|
4872
4983
|
// Default to spring if no type specified (matches useSpring behavior)
|
|
4873
4984
|
type: "spring",
|
|
4874
4985
|
restDelta: 0.001,
|
|
@@ -4877,19 +4988,31 @@ function attachFollow(value, source, options = {}) {
|
|
|
4877
4988
|
onUpdate: latestSetter,
|
|
4878
4989
|
});
|
|
4879
4990
|
};
|
|
4991
|
+
// Use a stable function reference so the frame loop Set deduplicates
|
|
4992
|
+
// multiple calls within the same frame (e.g. rapid mouse events)
|
|
4993
|
+
const scheduleAnimation = () => {
|
|
4994
|
+
startAnimation();
|
|
4995
|
+
value["events"].animationStart?.notify();
|
|
4996
|
+
activeAnimation?.then(() => {
|
|
4997
|
+
value["events"].animationComplete?.notify();
|
|
4998
|
+
});
|
|
4999
|
+
};
|
|
4880
5000
|
value.attach((v, set) => {
|
|
4881
5001
|
latestValue = v;
|
|
4882
5002
|
latestSetter = (latest) => set(parseValue(latest, unit));
|
|
4883
|
-
frame.postRender(
|
|
4884
|
-
startAnimation();
|
|
4885
|
-
value["events"].animationStart?.notify();
|
|
4886
|
-
activeAnimation?.then(() => {
|
|
4887
|
-
value["events"].animationComplete?.notify();
|
|
4888
|
-
});
|
|
4889
|
-
});
|
|
5003
|
+
frame.postRender(scheduleAnimation);
|
|
4890
5004
|
}, stopAnimation);
|
|
4891
5005
|
if (isMotionValue(source)) {
|
|
4892
|
-
|
|
5006
|
+
let skipNextAnimation = options.skipInitialAnimation === true;
|
|
5007
|
+
const removeSourceOnChange = source.on("change", (v) => {
|
|
5008
|
+
if (skipNextAnimation) {
|
|
5009
|
+
skipNextAnimation = false;
|
|
5010
|
+
value.jump(parseValue(v, unit), false);
|
|
5011
|
+
}
|
|
5012
|
+
else {
|
|
5013
|
+
value.set(parseValue(v, unit));
|
|
5014
|
+
}
|
|
5015
|
+
});
|
|
4893
5016
|
const removeValueOnDestroy = value.on("destroy", removeSourceOnChange);
|
|
4894
5017
|
return () => {
|
|
4895
5018
|
removeSourceOnChange();
|
|
@@ -6182,7 +6305,7 @@ function applyTreeDeltas(box, treeScale, treePath, isSharedTransition = false) {
|
|
|
6182
6305
|
applyBoxDelta(box, delta);
|
|
6183
6306
|
}
|
|
6184
6307
|
if (isSharedTransition && hasTransform(node.latestValues)) {
|
|
6185
|
-
transformBox(box, node.latestValues);
|
|
6308
|
+
transformBox(box, node.latestValues, node.layout?.layoutBox);
|
|
6186
6309
|
}
|
|
6187
6310
|
}
|
|
6188
6311
|
/**
|
|
@@ -6221,9 +6344,10 @@ function resolveAxisTranslate(value, axis) {
|
|
|
6221
6344
|
/**
|
|
6222
6345
|
* Apply a transform to a box from the latest resolved motion values.
|
|
6223
6346
|
*/
|
|
6224
|
-
function transformBox(box, transform) {
|
|
6225
|
-
|
|
6226
|
-
transformAxis(box.
|
|
6347
|
+
function transformBox(box, transform, sourceBox) {
|
|
6348
|
+
const resolveBox = sourceBox ?? box;
|
|
6349
|
+
transformAxis(box.x, resolveAxisTranslate(transform.x, resolveBox.x), transform.scaleX, transform.scale, transform.originX);
|
|
6350
|
+
transformAxis(box.y, resolveAxisTranslate(transform.y, resolveBox.y), transform.scaleY, transform.scale, transform.originY);
|
|
6227
6351
|
}
|
|
6228
6352
|
|
|
6229
6353
|
function measureViewportBox(instance, transformPoint) {
|
|
@@ -7979,6 +8103,14 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
7979
8103
|
for (let i = 0; i < this.path.length; i++) {
|
|
7980
8104
|
const node = this.path[i];
|
|
7981
8105
|
node.shouldResetTransform = true;
|
|
8106
|
+
/**
|
|
8107
|
+
* Percentage translates resolve against layoutBox dimensions,
|
|
8108
|
+
* so ancestors with them must be re-measured after transform reset.
|
|
8109
|
+
*/
|
|
8110
|
+
if (typeof node.latestValues.x === "string" ||
|
|
8111
|
+
typeof node.latestValues.y === "string") {
|
|
8112
|
+
node.isLayoutDirty = true;
|
|
8113
|
+
}
|
|
7982
8114
|
node.updateScroll("snapshot");
|
|
7983
8115
|
if (node.options.layoutRoot) {
|
|
7984
8116
|
node.willUpdate(false);
|
|
@@ -8244,10 +8376,10 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8244
8376
|
}
|
|
8245
8377
|
if (!hasTransform(node.latestValues))
|
|
8246
8378
|
continue;
|
|
8247
|
-
transformBox(withTransforms, node.latestValues);
|
|
8379
|
+
transformBox(withTransforms, node.latestValues, node.layout?.layoutBox);
|
|
8248
8380
|
}
|
|
8249
8381
|
if (hasTransform(this.latestValues)) {
|
|
8250
|
-
transformBox(withTransforms, this.latestValues);
|
|
8382
|
+
transformBox(withTransforms, this.latestValues, this.layout?.layoutBox);
|
|
8251
8383
|
}
|
|
8252
8384
|
return withTransforms;
|
|
8253
8385
|
}
|
|
@@ -8256,15 +8388,15 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8256
8388
|
copyBoxInto(boxWithoutTransform, box);
|
|
8257
8389
|
for (let i = 0; i < this.path.length; i++) {
|
|
8258
8390
|
const node = this.path[i];
|
|
8259
|
-
if (!node.instance)
|
|
8260
|
-
continue;
|
|
8261
8391
|
if (!hasTransform(node.latestValues))
|
|
8262
8392
|
continue;
|
|
8263
|
-
|
|
8264
|
-
|
|
8265
|
-
|
|
8266
|
-
|
|
8267
|
-
|
|
8393
|
+
let sourceBox;
|
|
8394
|
+
if (node.instance) {
|
|
8395
|
+
hasScale(node.latestValues) && node.updateSnapshot();
|
|
8396
|
+
sourceBox = createBox();
|
|
8397
|
+
copyBoxInto(sourceBox, node.measurePageBox());
|
|
8398
|
+
}
|
|
8399
|
+
removeBoxTransforms(boxWithoutTransform, node.latestValues, node.snapshot?.layoutBox, sourceBox);
|
|
8268
8400
|
}
|
|
8269
8401
|
if (hasTransform(this.latestValues)) {
|
|
8270
8402
|
removeBoxTransforms(boxWithoutTransform, this.latestValues);
|
|
@@ -8994,6 +9126,12 @@ function notifyLayoutUpdate(node) {
|
|
|
8994
9126
|
axisSnapshot.max = axisSnapshot.min + length;
|
|
8995
9127
|
});
|
|
8996
9128
|
}
|
|
9129
|
+
else if (animationType === "x" || animationType === "y") {
|
|
9130
|
+
const snapAxis = animationType === "x" ? "y" : "x";
|
|
9131
|
+
copyAxisInto(isShared
|
|
9132
|
+
? snapshot.measuredBox[snapAxis]
|
|
9133
|
+
: snapshot.layoutBox[snapAxis], layout[snapAxis]);
|
|
9134
|
+
}
|
|
8997
9135
|
else if (shouldAnimatePositionOnly(animationType, snapshot.layoutBox, layout)) {
|
|
8998
9136
|
eachAxis((axis) => {
|
|
8999
9137
|
const axisSnapshot = isShared
|