motion-dom 14.6.0 → 14.7.1
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 +574 -580
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/AsyncMotionValueAnimation.mjs +3 -6
- package/dist/es/animation/AsyncMotionValueAnimation.mjs.map +1 -1
- package/dist/es/animation/JSAnimation.mjs +18 -30
- package/dist/es/animation/JSAnimation.mjs.map +1 -1
- package/dist/es/animation/NativeAnimation.mjs +4 -4
- package/dist/es/animation/NativeAnimation.mjs.map +1 -1
- package/dist/es/animation/animate/effects.mjs +5 -2
- package/dist/es/animation/animate/effects.mjs.map +1 -1
- package/dist/es/animation/generators/inertia.mjs +3 -2
- package/dist/es/animation/generators/inertia.mjs.map +1 -1
- package/dist/es/animation/generators/spring.mjs +40 -44
- package/dist/es/animation/generators/spring.mjs.map +1 -1
- package/dist/es/animation/interfaces/visual-element-target.mjs +1 -1
- package/dist/es/animation/interfaces/visual-element-target.mjs.map +1 -1
- package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs +7 -15
- package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs.map +1 -1
- package/dist/es/animation/keyframes/KeyframesResolver.mjs.map +1 -1
- package/dist/es/animation/utils/can-animate.mjs +1 -0
- package/dist/es/animation/utils/can-animate.mjs.map +1 -1
- package/dist/es/animation/utils/css-variables-conversion.mjs +2 -1
- package/dist/es/animation/utils/css-variables-conversion.mjs.map +1 -1
- package/dist/es/animation/utils/is-transition-defined.mjs +1 -0
- package/dist/es/animation/utils/is-transition-defined.mjs.map +1 -1
- package/dist/es/animation/waapi/transforms/TransformAnimation.mjs +45 -21
- package/dist/es/animation/waapi/transforms/TransformAnimation.mjs.map +1 -1
- package/dist/es/animation/waapi/transforms/groups.mjs.map +1 -1
- package/dist/es/animation/waapi/utils/accelerated-values.mjs +4 -1
- package/dist/es/animation/waapi/utils/accelerated-values.mjs.map +1 -1
- package/dist/es/effects/style/transform.mjs +4 -20
- package/dist/es/effects/style/transform.mjs.map +1 -1
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +78 -61
- package/dist/es/gestures/drag/VisualElementDragControls.mjs.map +1 -1
- package/dist/es/gestures/pan/PanSession.mjs +28 -39
- package/dist/es/gestures/pan/PanSession.mjs.map +1 -1
- package/dist/es/index.mjs +1 -1
- package/dist/es/layout/LayoutAnimationBuilder.mjs +2 -2
- package/dist/es/layout/LayoutAnimationBuilder.mjs.map +1 -1
- package/dist/es/projection/animation/mix-values.mjs +3 -11
- package/dist/es/projection/animation/mix-values.mjs.map +1 -1
- package/dist/es/projection/geometry/delta-apply.mjs +10 -6
- package/dist/es/projection/geometry/delta-apply.mjs.map +1 -1
- package/dist/es/projection/geometry/delta-calc.mjs +2 -2
- package/dist/es/projection/geometry/delta-calc.mjs.map +1 -1
- package/dist/es/projection/geometry/delta-remove.mjs +2 -2
- package/dist/es/projection/geometry/delta-remove.mjs.map +1 -1
- package/dist/es/projection/node/HTMLProjectionNode.mjs +1 -1
- package/dist/es/projection/node/HTMLProjectionNode.mjs.map +1 -1
- package/dist/es/projection/node/create-projection-node.mjs +147 -138
- package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
- package/dist/es/projection/styles/transform.mjs +12 -16
- package/dist/es/projection/styles/transform.mjs.map +1 -1
- package/dist/es/projection/utils/has-transform.mjs +16 -2
- package/dist/es/projection/utils/has-transform.mjs.map +1 -1
- package/dist/es/render/VisualElement.mjs +20 -37
- package/dist/es/render/VisualElement.mjs.map +1 -1
- package/dist/es/render/dom/parse-transform.mjs +6 -17
- package/dist/es/render/dom/parse-transform.mjs.map +1 -1
- package/dist/es/render/html/HTMLVisualElement.mjs +2 -1
- package/dist/es/render/html/HTMLVisualElement.mjs.map +1 -1
- package/dist/es/render/html/utils/build-transform.mjs +25 -29
- package/dist/es/render/html/utils/build-transform.mjs.map +1 -1
- package/dist/es/render/utils/animation-state.mjs +57 -13
- package/dist/es/render/utils/animation-state.mjs.map +1 -1
- package/dist/es/utils/interpolate.mjs +2 -1
- package/dist/es/utils/interpolate.mjs.map +1 -1
- package/dist/es/utils/mix/color.mjs +2 -1
- package/dist/es/utils/mix/color.mjs.map +1 -1
- package/dist/es/utils/mix/complex.mjs +4 -4
- package/dist/es/utils/mix/complex.mjs.map +1 -1
- package/dist/es/utils/resolve-elements.mjs.map +1 -1
- package/dist/es/value/index.mjs +13 -34
- package/dist/es/value/index.mjs.map +1 -1
- package/dist/es/value/types/color/hex.mjs +13 -26
- package/dist/es/value/types/color/hex.mjs.map +1 -1
- package/dist/es/value/types/complex/index.mjs +1 -1
- package/dist/es/value/types/complex/index.mjs.map +1 -1
- package/dist/index.d.ts +72 -21
- package/dist/motion-dom.dev.js +558 -573
- 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 +4 -3
package/dist/cjs/index.js
CHANGED
|
@@ -135,34 +135,21 @@ const rgba = {
|
|
|
135
135
|
")",
|
|
136
136
|
};
|
|
137
137
|
|
|
138
|
+
/**
|
|
139
|
+
* #FF0000 has two characters per channel, #F00 one, which is doubled.
|
|
140
|
+
*/
|
|
141
|
+
const channel = (v, i, size) => {
|
|
142
|
+
const c = v.substring(1 + i * size, 1 + (i + 1) * size);
|
|
143
|
+
return size > 1 ? c : c + c;
|
|
144
|
+
};
|
|
138
145
|
function parseHex(v) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
let b = "";
|
|
142
|
-
let a = "";
|
|
143
|
-
// If we have 6 characters, ie #FF0000
|
|
144
|
-
if (v.length > 5) {
|
|
145
|
-
r = v.substring(1, 3);
|
|
146
|
-
g = v.substring(3, 5);
|
|
147
|
-
b = v.substring(5, 7);
|
|
148
|
-
a = v.substring(7, 9);
|
|
149
|
-
// Or we have 3 characters, ie #F00
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
r = v.substring(1, 2);
|
|
153
|
-
g = v.substring(2, 3);
|
|
154
|
-
b = v.substring(3, 4);
|
|
155
|
-
a = v.substring(4, 5);
|
|
156
|
-
r += r;
|
|
157
|
-
g += g;
|
|
158
|
-
b += b;
|
|
159
|
-
a += a;
|
|
160
|
-
}
|
|
146
|
+
const size = v.length > 5 ? 2 : 1;
|
|
147
|
+
const alpha = channel(v, 3, size);
|
|
161
148
|
return {
|
|
162
|
-
red: parseInt(
|
|
163
|
-
green: parseInt(
|
|
164
|
-
blue: parseInt(
|
|
165
|
-
alpha:
|
|
149
|
+
red: parseInt(channel(v, 0, size), 16),
|
|
150
|
+
green: parseInt(channel(v, 1, size), 16),
|
|
151
|
+
blue: parseInt(channel(v, 2, size), 16),
|
|
152
|
+
alpha: alpha ? parseInt(alpha, 16) / 255 : 1,
|
|
166
153
|
};
|
|
167
154
|
}
|
|
168
155
|
const hex = {
|
|
@@ -437,7 +424,8 @@ const getColorType = (v) => colorTypes.find((type) => type.test(v));
|
|
|
437
424
|
function asRGBA(color) {
|
|
438
425
|
const type = getColorType(color);
|
|
439
426
|
if (!type) {
|
|
440
|
-
|
|
427
|
+
process.env.NODE_ENV !== "production" &&
|
|
428
|
+
motionUtils.warning(false, `'${color}' is not an animatable color. Use the equivalent color code instead.`, "color-not-animatable");
|
|
441
429
|
return false;
|
|
442
430
|
}
|
|
443
431
|
let model = type.parse(color);
|
|
@@ -539,7 +527,6 @@ function matchOrder(origin, target) {
|
|
|
539
527
|
return orderedOrigin;
|
|
540
528
|
}
|
|
541
529
|
const mixComplex = (origin, target) => {
|
|
542
|
-
const template = complex.createTransformer(target);
|
|
543
530
|
const originStats = analyseComplexValue(origin);
|
|
544
531
|
const targetStats = analyseComplexValue(target);
|
|
545
532
|
const canInterpolate = originStats.indexes.var.length === targetStats.indexes.var.length &&
|
|
@@ -552,10 +539,11 @@ const mixComplex = (origin, target) => {
|
|
|
552
539
|
!originStats.values.length)) {
|
|
553
540
|
return mixVisibility(origin, target);
|
|
554
541
|
}
|
|
555
|
-
return motionUtils.pipe(mixArray(matchOrder(originStats, targetStats), targetStats.values),
|
|
542
|
+
return motionUtils.pipe(mixArray(matchOrder(originStats, targetStats), targetStats.values), buildTransformer(targetStats));
|
|
556
543
|
}
|
|
557
544
|
else {
|
|
558
|
-
|
|
545
|
+
process.env.NODE_ENV !== "production" &&
|
|
546
|
+
motionUtils.warning(true, `Complex values '${origin}' and '${target}' too different to mix. Ensure all colors are of the same type, and that each contains the same quantity of number and color values. Falling back to instant transition.`, "complex-values-different");
|
|
559
547
|
return mixImmediate(origin, target);
|
|
560
548
|
}
|
|
561
549
|
};
|
|
@@ -844,37 +832,31 @@ function createGeneratorEasing(options, scale = 100, createGenerator) {
|
|
|
844
832
|
};
|
|
845
833
|
}
|
|
846
834
|
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
},
|
|
865
|
-
// Limits
|
|
866
|
-
minDuration: 0.01, // in seconds
|
|
867
|
-
maxDuration: 10.0, // in seconds
|
|
868
|
-
minDamping: 0.05,
|
|
869
|
-
};
|
|
835
|
+
// Default spring physics
|
|
836
|
+
const defaultStiffness = 100;
|
|
837
|
+
const defaultDamping = 10;
|
|
838
|
+
const defaultMass = 1.0;
|
|
839
|
+
// Default duration/bounce-based options
|
|
840
|
+
const defaultDuration = 800; // in ms
|
|
841
|
+
const defaultBounce = 0.3;
|
|
842
|
+
const defaultVisualDuration = 0.3; // in seconds
|
|
843
|
+
// Rest thresholds
|
|
844
|
+
const restSpeedGranular = 0.01;
|
|
845
|
+
const restSpeedDefault = 2;
|
|
846
|
+
const restDeltaGranular = 0.005;
|
|
847
|
+
const restDeltaDefault = 0.5;
|
|
848
|
+
// Limits
|
|
849
|
+
const minDuration = 0.01; // in seconds
|
|
850
|
+
const maxDuration = 10.0; // in seconds
|
|
851
|
+
const minDamping = 0.05;
|
|
870
852
|
/**
|
|
871
853
|
* Maps bounce to a damping ratio as SwiftUI does: 0 is critically damped, and
|
|
872
854
|
* it approaches undamped towards 1 and infinitely overdamped towards -1. Both
|
|
873
855
|
* ends are limited so the spring still moves and settles.
|
|
874
856
|
*/
|
|
875
857
|
const bounceToDampingRatio = (bounce) => bounce < 0
|
|
876
|
-
? 1 / Math.max(1 + bounce,
|
|
877
|
-
: Math.max(1 - bounce,
|
|
858
|
+
? 1 / Math.max(1 + bounce, minDamping)
|
|
859
|
+
: Math.max(1 - bounce, minDamping);
|
|
878
860
|
/**
|
|
879
861
|
* Scales an overdamped spring's undamped frequency so that, at its defining
|
|
880
862
|
* time, it has as far left to go as the critically damped spring that's
|
|
@@ -917,12 +899,13 @@ const safeMin = 0.001;
|
|
|
917
899
|
* ignore inherited velocity and only resolve without valid physics. Returns
|
|
918
900
|
* NaN physics when the root search doesn't converge.
|
|
919
901
|
*/
|
|
920
|
-
function findSpring({ duration =
|
|
902
|
+
function findSpring({ duration = defaultDuration, bounce = defaultBounce, }) {
|
|
921
903
|
let envelope;
|
|
922
904
|
let derivative;
|
|
923
|
-
|
|
905
|
+
process.env.NODE_ENV !== "production" &&
|
|
906
|
+
motionUtils.warning(duration <= motionUtils.secondsToMilliseconds(maxDuration), "Spring duration must be 10 seconds or less", "spring-duration-limit");
|
|
924
907
|
const dampingRatio = bounceToDampingRatio(bounce);
|
|
925
|
-
duration = motionUtils.clamp(
|
|
908
|
+
duration = motionUtils.clamp(minDuration, maxDuration, motionUtils.millisecondsToSeconds(duration));
|
|
926
909
|
if (dampingRatio < 1) {
|
|
927
910
|
/**
|
|
928
911
|
* Underdamped spring
|
|
@@ -1007,9 +990,9 @@ function getSpringOptions(options) {
|
|
|
1007
990
|
const validMass = resolvePhysics(options.mass);
|
|
1008
991
|
const springOptions = {
|
|
1009
992
|
...options,
|
|
1010
|
-
stiffness: validStiffness ??
|
|
1011
|
-
damping: validDamping ??
|
|
1012
|
-
mass: validMass ??
|
|
993
|
+
stiffness: validStiffness ?? defaultStiffness,
|
|
994
|
+
damping: validDamping ?? defaultDamping,
|
|
995
|
+
mass: validMass ?? defaultMass,
|
|
1013
996
|
isResolvedFromDuration: false,
|
|
1014
997
|
// stiffness/damping/mass overrides duration/bounce
|
|
1015
998
|
isTimeDefined: (validStiffness ?? validDamping ?? validMass) === undefined &&
|
|
@@ -1037,13 +1020,13 @@ function getSpringOptions(options) {
|
|
|
1037
1020
|
*/
|
|
1038
1021
|
if (!isValidPhysics(springOptions.stiffness) ||
|
|
1039
1022
|
!isValidPhysics(springOptions.damping, true)) {
|
|
1040
|
-
springOptions.stiffness =
|
|
1041
|
-
springOptions.damping =
|
|
1023
|
+
springOptions.stiffness = defaultStiffness;
|
|
1024
|
+
springOptions.damping = defaultDamping;
|
|
1042
1025
|
}
|
|
1043
1026
|
}
|
|
1044
1027
|
return springOptions;
|
|
1045
1028
|
}
|
|
1046
|
-
function springGenerator(optionsOrVisualDuration =
|
|
1029
|
+
function springGenerator(optionsOrVisualDuration = defaultVisualDuration, bounce = defaultBounce) {
|
|
1047
1030
|
const options = typeof optionsOrVisualDuration !== "object"
|
|
1048
1031
|
? {
|
|
1049
1032
|
visualDuration: optionsOrVisualDuration,
|
|
@@ -1093,14 +1076,10 @@ function springGenerator(optionsOrVisualDuration = springDefaults.visualDuration
|
|
|
1093
1076
|
const isGranularScale = Math.abs(s.delta) < 5;
|
|
1094
1077
|
s.restSpeed =
|
|
1095
1078
|
options.restSpeed ||
|
|
1096
|
-
(isGranularScale
|
|
1097
|
-
? springDefaults.restSpeed.granular
|
|
1098
|
-
: springDefaults.restSpeed.default);
|
|
1079
|
+
(isGranularScale ? restSpeedGranular : restSpeedDefault);
|
|
1099
1080
|
s.restDelta =
|
|
1100
1081
|
options.restDelta ||
|
|
1101
|
-
(isGranularScale
|
|
1102
|
-
? springDefaults.restDelta.granular
|
|
1103
|
-
: springDefaults.restDelta.default);
|
|
1082
|
+
(isGranularScale ? restDeltaGranular : restDeltaDefault);
|
|
1104
1083
|
};
|
|
1105
1084
|
setRestThresholds();
|
|
1106
1085
|
let resolveSpring;
|
|
@@ -1169,11 +1148,16 @@ function springGenerator(optionsOrVisualDuration = springDefaults.visualDuration
|
|
|
1169
1148
|
* dampedAngularFreq * t passes 300, both terms decay at the damping
|
|
1170
1149
|
* rate. Heavily overdamped drag springs (dragElastic: 0,
|
|
1171
1150
|
* dragTransition) rely on this to settle almost at once rather than
|
|
1172
|
-
* creep at stiffness / damping.
|
|
1173
|
-
*
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1151
|
+
* creep at stiffness / damping. It only applies when reached within
|
|
1152
|
+
* 300ms (a dampedAngularFreq of 1 rad/ms), so it reads as a stiff
|
|
1153
|
+
* spring snapping into place: any later and it cuts off a slow spring
|
|
1154
|
+
* that's visibly still moving (#1207). Negative bounce needs the
|
|
1155
|
+
* exact curve, so time-defined springs are exempt.
|
|
1156
|
+
*/
|
|
1157
|
+
const limit = dampedAngularFreq < 1 || isTimeDefined
|
|
1158
|
+
? Infinity
|
|
1159
|
+
: 300 / dampedAngularFreq;
|
|
1160
|
+
const decayAt = (rate, t) => Math.exp(t > limit ? (decay - rate) * limit - decay * t : -rate * t);
|
|
1177
1161
|
const c = { S: 0, F: 0 };
|
|
1178
1162
|
update = () => {
|
|
1179
1163
|
const P = (s.velocity + decay * s.delta) / dampedAngularFreq;
|
|
@@ -1254,7 +1238,7 @@ function inertia({ keyframes, velocity = 0.0, power = 0.8, timeConstant = 325, b
|
|
|
1254
1238
|
};
|
|
1255
1239
|
let amplitude = power * velocity;
|
|
1256
1240
|
const ideal = origin + amplitude;
|
|
1257
|
-
const target = modifyTarget
|
|
1241
|
+
const target = modifyTarget ? modifyTarget(ideal) : ideal;
|
|
1258
1242
|
/**
|
|
1259
1243
|
* If the target has changed we need to re-calculate the amplitude, otherwise
|
|
1260
1244
|
* the animation will start from the wrong position.
|
|
@@ -1265,7 +1249,8 @@ function inertia({ keyframes, velocity = 0.0, power = 0.8, timeConstant = 325, b
|
|
|
1265
1249
|
const applyFriction = (t) => {
|
|
1266
1250
|
const delta = calcDelta(t);
|
|
1267
1251
|
state.done = Math.abs(delta) <= restDelta;
|
|
1268
|
-
|
|
1252
|
+
// target + delta can be off from origin by a float error at t = 0
|
|
1253
|
+
state.value = state.done ? target : t ? target + delta : origin;
|
|
1269
1254
|
};
|
|
1270
1255
|
/**
|
|
1271
1256
|
* Ideally this would resolve for t in a stateless way, we could
|
|
@@ -1359,7 +1344,8 @@ function createMixers(output, ease, customMixer) {
|
|
|
1359
1344
|
*/
|
|
1360
1345
|
function interpolate(input, output, { clamp: isClamp = true, ease, mixer } = {}) {
|
|
1361
1346
|
const inputLength = input.length;
|
|
1362
|
-
|
|
1347
|
+
process.env.NODE_ENV !== "production" &&
|
|
1348
|
+
motionUtils.invariant(inputLength === output.length, "Both input and output ranges must be the same length", "range-length");
|
|
1363
1349
|
/**
|
|
1364
1350
|
* If we're only provided a single input, we can just make a function
|
|
1365
1351
|
* that returns the output.
|
|
@@ -1712,17 +1698,12 @@ class JSAnimation extends WithPromise {
|
|
|
1712
1698
|
this.generator = generator;
|
|
1713
1699
|
}
|
|
1714
1700
|
updateTime(timestamp) {
|
|
1715
|
-
|
|
1716
|
-
//
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
// Rounding the time because floating point arithmetic is not always accurate, e.g. 3000.367 - 1000.367 =
|
|
1722
|
-
// 2000.0000000000002. This is a problem when we are comparing the currentTime with the duration, for
|
|
1723
|
-
// example.
|
|
1724
|
-
this.currentTime = animationTime;
|
|
1725
|
-
}
|
|
1701
|
+
// Rounding the time because floating point arithmetic is not always accurate, e.g. 3000.367 - 1000.367 =
|
|
1702
|
+
// 2000.0000000000002. This is a problem when we are comparing the currentTime with the duration, for
|
|
1703
|
+
// example.
|
|
1704
|
+
this.currentTime =
|
|
1705
|
+
this.holdTime ??
|
|
1706
|
+
Math.round(timestamp - this.startTime) * this.playbackSpeed;
|
|
1726
1707
|
}
|
|
1727
1708
|
tick(timestamp, sample = false) {
|
|
1728
1709
|
const { generator, totalDuration, calculatedDuration } = this;
|
|
@@ -1763,10 +1744,17 @@ class JSAnimation extends WithPromise {
|
|
|
1763
1744
|
}
|
|
1764
1745
|
const state = this.generate(this.currentTime, isInDelayPhase);
|
|
1765
1746
|
let { done } = state;
|
|
1766
|
-
|
|
1747
|
+
/**
|
|
1748
|
+
* A generator that takes longer than maxGeneratorDuration to finish
|
|
1749
|
+
* has an Infinity duration, so played forwards it finishes when it
|
|
1750
|
+
* says it's done.
|
|
1751
|
+
*/
|
|
1752
|
+
if (!isInDelayPhase) {
|
|
1767
1753
|
done =
|
|
1768
1754
|
this.playbackSpeed >= 0
|
|
1769
|
-
?
|
|
1755
|
+
? calculatedDuration < Infinity
|
|
1756
|
+
? this.currentTime >= totalDuration
|
|
1757
|
+
: done
|
|
1770
1758
|
: this.currentTime <= 0;
|
|
1771
1759
|
}
|
|
1772
1760
|
const isAnimationFinished = this.holdTime === null &&
|
|
@@ -1872,20 +1860,11 @@ class JSAnimation extends WithPromise {
|
|
|
1872
1860
|
}
|
|
1873
1861
|
return state;
|
|
1874
1862
|
}
|
|
1875
|
-
/**
|
|
1876
|
-
* Allows the returned animation to be awaited or promise-chained. Currently
|
|
1877
|
-
* resolves when the animation finishes at all but in a future update could/should
|
|
1878
|
-
* reject if its cancels.
|
|
1879
|
-
*/
|
|
1880
|
-
then(resolve, reject) {
|
|
1881
|
-
return this.finished.then(resolve, reject);
|
|
1882
|
-
}
|
|
1883
1863
|
get duration() {
|
|
1884
1864
|
return motionUtils.millisecondsToSeconds(this.calculatedDuration);
|
|
1885
1865
|
}
|
|
1886
1866
|
get iterationDuration() {
|
|
1887
|
-
|
|
1888
|
-
return this.duration + motionUtils.millisecondsToSeconds(delay);
|
|
1867
|
+
return this.duration + motionUtils.millisecondsToSeconds(this.options.delay ?? 0);
|
|
1889
1868
|
}
|
|
1890
1869
|
get time() {
|
|
1891
1870
|
return motionUtils.millisecondsToSeconds(this.currentTime);
|
|
@@ -1989,14 +1968,9 @@ class JSAnimation extends WithPromise {
|
|
|
1989
1968
|
}
|
|
1990
1969
|
teardown() {
|
|
1991
1970
|
this.state = "idle";
|
|
1992
|
-
this.
|
|
1993
|
-
this.startTime = this.holdTime = null;
|
|
1994
|
-
}
|
|
1995
|
-
stopDriver() {
|
|
1996
|
-
if (!this.driver)
|
|
1997
|
-
return;
|
|
1998
|
-
this.driver.stop();
|
|
1971
|
+
this.driver?.stop();
|
|
1999
1972
|
this.driver = undefined;
|
|
1973
|
+
this.startTime = this.holdTime = null;
|
|
2000
1974
|
}
|
|
2001
1975
|
sample(sampleTime) {
|
|
2002
1976
|
this.startTime = 0;
|
|
@@ -2253,23 +2227,15 @@ function parseValueFromTransform(transform, name) {
|
|
|
2253
2227
|
if (!transform || transform === "none") {
|
|
2254
2228
|
return defaultTransformValue(name);
|
|
2255
2229
|
}
|
|
2256
|
-
const
|
|
2257
|
-
let parsers;
|
|
2258
|
-
let match;
|
|
2259
|
-
if (matrix3dMatch) {
|
|
2260
|
-
parsers = matrix3dParsers;
|
|
2261
|
-
match = matrix3dMatch;
|
|
2262
|
-
}
|
|
2263
|
-
else {
|
|
2264
|
-
const matrix2dMatch = transform.match(/^matrix\(([-\d.e\s,]+)\)$/u);
|
|
2265
|
-
parsers = matrix2dParsers;
|
|
2266
|
-
match = matrix2dMatch;
|
|
2267
|
-
}
|
|
2230
|
+
const match = transform.match(/^matrix(3d)?\(([-\d.e\s,]+)\)$/u);
|
|
2268
2231
|
if (!match) {
|
|
2269
2232
|
return defaultTransformValue(name);
|
|
2270
2233
|
}
|
|
2271
|
-
const valueParser =
|
|
2272
|
-
|
|
2234
|
+
const valueParser = (match[1] ? matrix3dParsers : matrix2dParsers)[name];
|
|
2235
|
+
/**
|
|
2236
|
+
* parseFloat skips leading whitespace and stops at trailing whitespace.
|
|
2237
|
+
*/
|
|
2238
|
+
const values = match[2].split(",").map((v) => parseFloat(v));
|
|
2273
2239
|
return typeof valueParser === "function"
|
|
2274
2240
|
? valueParser(values)
|
|
2275
2241
|
: values[valueParser];
|
|
@@ -2278,9 +2244,6 @@ const readTransformValue = (instance, name) => {
|
|
|
2278
2244
|
const { transform = "none" } = getComputedStyle(instance);
|
|
2279
2245
|
return parseValueFromTransform(transform, name);
|
|
2280
2246
|
};
|
|
2281
|
-
function convertTransformToNumber(value) {
|
|
2282
|
-
return parseFloat(value.trim());
|
|
2283
|
-
}
|
|
2284
2247
|
|
|
2285
2248
|
/**
|
|
2286
2249
|
* Generate a list of every possible transform key.
|
|
@@ -2683,7 +2646,9 @@ class NativeAnimation extends WithPromise {
|
|
|
2683
2646
|
this.isPseudoElement = Boolean(pseudoElement);
|
|
2684
2647
|
this.allowFlatten = allowFlatten;
|
|
2685
2648
|
this.options = options;
|
|
2686
|
-
|
|
2649
|
+
typeof process !== "undefined" &&
|
|
2650
|
+
process.env.NODE_ENV !== "production" &&
|
|
2651
|
+
motionUtils.invariant(typeof options.type !== "string", `Mini animate() doesn't support "type" as a string.`, "mini-spring");
|
|
2687
2652
|
const transition = applyGeneratorOptions(options);
|
|
2688
2653
|
this.animation = startWaapiAnimation(element, name, keyframes, transition, pseudoElement);
|
|
2689
2654
|
if (transition.autoplay === false) {
|
|
@@ -2693,9 +2658,7 @@ class NativeAnimation extends WithPromise {
|
|
|
2693
2658
|
this.finishedTime = this.time;
|
|
2694
2659
|
if (!pseudoElement) {
|
|
2695
2660
|
const keyframe = getFinalKeyframe(keyframes, this.options, finalKeyframe, this.speed);
|
|
2696
|
-
|
|
2697
|
-
this.updateMotionValue(keyframe);
|
|
2698
|
-
}
|
|
2661
|
+
this.updateMotionValue?.(keyframe);
|
|
2699
2662
|
/**
|
|
2700
2663
|
* If we can, we want to commit the final style as set by the user,
|
|
2701
2664
|
* rather than the computed keyframe value supplied by the animation.
|
|
@@ -3016,6 +2979,7 @@ function canAnimate(keyframes, name, type, velocity) {
|
|
|
3016
2979
|
if (!isOriginAnimatable || !isTargetAnimatable) {
|
|
3017
2980
|
// Only build the message when we're going to warn
|
|
3018
2981
|
isOriginAnimatable !== isTargetAnimatable &&
|
|
2982
|
+
process.env.NODE_ENV !== "production" &&
|
|
3019
2983
|
motionUtils.warning(false, `You are trying to animate ${name} from "${originKeyframe}" to "${targetKeyframe}". "${isOriginAnimatable ? targetKeyframe : originKeyframe}" is not an animatable value.`, "value-not-animatable");
|
|
3020
2984
|
return false;
|
|
3021
2985
|
}
|
|
@@ -3030,13 +2994,16 @@ function makeAnimationInstant(options) {
|
|
|
3030
2994
|
|
|
3031
2995
|
/**
|
|
3032
2996
|
* A list of values that can be hardware-accelerated.
|
|
2997
|
+
*
|
|
2998
|
+
* Colors aren't included: WAAPI mixes them in sRGB, but JS animations
|
|
2999
|
+
* (and the sampler that estimates a WAAPI value on interrupt) mix them
|
|
3000
|
+
* in linear color space, so interrupting one would visibly jump.
|
|
3033
3001
|
*/
|
|
3034
3002
|
const acceleratedValues = new Set([
|
|
3035
3003
|
"opacity",
|
|
3036
3004
|
"clipPath",
|
|
3037
3005
|
"filter",
|
|
3038
3006
|
"transform",
|
|
3039
|
-
"backgroundColor",
|
|
3040
3007
|
]);
|
|
3041
3008
|
|
|
3042
3009
|
const browserColorFunctions = /^(?:oklch|oklab|lab|lch|color|color-mix|light-dark)\(/;
|
|
@@ -3128,6 +3095,20 @@ const translateAlias = {
|
|
|
3128
3095
|
transformPerspective: "perspective",
|
|
3129
3096
|
};
|
|
3130
3097
|
const numTransforms = transformPropOrder.length;
|
|
3098
|
+
/**
|
|
3099
|
+
* Cache of `translateX(`-style openers so each transform function is a few
|
|
3100
|
+
* string concatenations rather than a template.
|
|
3101
|
+
*/
|
|
3102
|
+
const openers = {};
|
|
3103
|
+
/**
|
|
3104
|
+
* A transform function, e.g. `translateX(10px)` for `x: 10`.
|
|
3105
|
+
*/
|
|
3106
|
+
const transformFunction = (key, value, valueAsType = getValueAsType(value, transformValueTypes[key])) => (openers[key] || (openers[key] = (translateAlias[key] || key) + "(")) + valueAsType + ")";
|
|
3107
|
+
/**
|
|
3108
|
+
* Whether a transform value is at its default, so can be left out.
|
|
3109
|
+
*/
|
|
3110
|
+
const isDefaultTransform = (key, value) => (typeof value === "number" ? value : parseFloat(value)) ===
|
|
3111
|
+
(key.startsWith("scale") ? 1 : 0);
|
|
3131
3112
|
/**
|
|
3132
3113
|
* Build a CSS transform style from individual x/y/scale etc properties.
|
|
3133
3114
|
*
|
|
@@ -3137,7 +3118,6 @@ const numTransforms = transformPropOrder.length;
|
|
|
3137
3118
|
function buildTransform$1(latestValues, transform, transformTemplate) {
|
|
3138
3119
|
// The transform string we're going to build into.
|
|
3139
3120
|
let transformString = "";
|
|
3140
|
-
let transformIsDefault = true;
|
|
3141
3121
|
/**
|
|
3142
3122
|
* Loop over all possible transforms in order, adding the ones that
|
|
3143
3123
|
* are present to the transform string.
|
|
@@ -3147,24 +3127,11 @@ function buildTransform$1(latestValues, transform, transformTemplate) {
|
|
|
3147
3127
|
const value = latestValues[key];
|
|
3148
3128
|
if (value === undefined)
|
|
3149
3129
|
continue;
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
const parsed = parseFloat(value);
|
|
3156
|
-
valueIsDefault = key.startsWith("scale") ? parsed === 1 : parsed === 0;
|
|
3157
|
-
}
|
|
3158
|
-
if (!valueIsDefault || transformTemplate) {
|
|
3159
|
-
const valueAsType = getValueAsType(value, numberValueTypes[key]);
|
|
3160
|
-
if (!valueIsDefault) {
|
|
3161
|
-
transformIsDefault = false;
|
|
3162
|
-
const transformName = translateAlias[key] || key;
|
|
3163
|
-
transformString += `${transformName}(${valueAsType}) `;
|
|
3164
|
-
}
|
|
3165
|
-
if (transformTemplate) {
|
|
3166
|
-
transform[key] = valueAsType;
|
|
3167
|
-
}
|
|
3130
|
+
const valueAsType = transformTemplate &&
|
|
3131
|
+
(transform[key] = getValueAsType(value, numberValueTypes[key]));
|
|
3132
|
+
if (!isDefaultTransform(key, value)) {
|
|
3133
|
+
transformString +=
|
|
3134
|
+
transformFunction(key, value, valueAsType || undefined) + " ";
|
|
3168
3135
|
}
|
|
3169
3136
|
}
|
|
3170
3137
|
// `pathRotation` composes onto `rotate` as a separate additive term so
|
|
@@ -3172,19 +3139,14 @@ function buildTransform$1(latestValues, transform, transformTemplate) {
|
|
|
3172
3139
|
// `transformPropOrder`.
|
|
3173
3140
|
const pathRotation = latestValues.pathRotation;
|
|
3174
3141
|
if (pathRotation) {
|
|
3175
|
-
|
|
3176
|
-
transformString += `rotate(${getValueAsType(pathRotation, numberValueTypes.pathRotation)}) `;
|
|
3142
|
+
transformString += transformFunction("rotate", pathRotation);
|
|
3177
3143
|
}
|
|
3178
3144
|
transformString = transformString.trim();
|
|
3179
3145
|
// If we have a custom `transform` template, pass our transform values and
|
|
3180
3146
|
// generated transformString to that before returning
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
else if (transformIsDefault) {
|
|
3185
|
-
transformString = "none";
|
|
3186
|
-
}
|
|
3187
|
-
return transformString;
|
|
3147
|
+
return transformTemplate
|
|
3148
|
+
? transformTemplate(transform, transformString)
|
|
3149
|
+
: transformString || "none";
|
|
3188
3150
|
}
|
|
3189
3151
|
|
|
3190
3152
|
const transformGroups = new WeakMap();
|
|
@@ -3526,27 +3488,30 @@ function createGroup(owner) {
|
|
|
3526
3488
|
return values;
|
|
3527
3489
|
};
|
|
3528
3490
|
/**
|
|
3529
|
-
* Build
|
|
3530
|
-
* is written, even at its default, so each keyframe has the
|
|
3531
|
-
* of functions and the browser interpolates them one by one.
|
|
3491
|
+
* Build a transform from values in transformPropOrder. For a keyframe,
|
|
3492
|
+
* every key is written, even at its default, so each keyframe has the
|
|
3493
|
+
* same list of functions and the browser interpolates them one by one.
|
|
3494
|
+
* As an inline style, defaults are left out, as buildTransform does.
|
|
3532
3495
|
*/
|
|
3533
|
-
const
|
|
3496
|
+
const toTransform = (values, isStyle) => {
|
|
3534
3497
|
let transform = "";
|
|
3535
|
-
const values = valuesAt(timestamp, settled);
|
|
3536
3498
|
for (const key in values) {
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
") ";
|
|
3499
|
+
const value = values[key];
|
|
3500
|
+
if (!isStyle || !isDefaultTransform(key, value)) {
|
|
3501
|
+
transform += transformFunction(key, value) + " ";
|
|
3502
|
+
}
|
|
3542
3503
|
}
|
|
3543
|
-
return transform || "none";
|
|
3504
|
+
return (isStyle ? transform.trim() : transform) || "none";
|
|
3544
3505
|
};
|
|
3506
|
+
/**
|
|
3507
|
+
* Build the transform at a timestamp.
|
|
3508
|
+
*/
|
|
3509
|
+
const compose = (timestamp, settled) => toTransform(valuesAt(timestamp, settled));
|
|
3545
3510
|
/**
|
|
3546
3511
|
* Write the transform as an inline style, as the renderer would.
|
|
3547
3512
|
*/
|
|
3548
3513
|
const commit = (values = valuesAt()) => {
|
|
3549
|
-
element.style.transform =
|
|
3514
|
+
element.style.transform = toTransform(values, true);
|
|
3550
3515
|
};
|
|
3551
3516
|
/**
|
|
3552
3517
|
* Cancel the WAAPI animations, by default first committing the
|
|
@@ -3557,6 +3522,13 @@ function createGroup(owner) {
|
|
|
3557
3522
|
segments.forEach(({ animation }) => animation.cancel());
|
|
3558
3523
|
segments = [];
|
|
3559
3524
|
};
|
|
3525
|
+
/**
|
|
3526
|
+
* A WAAPI animation that add() starts by setting its startTime. Playing
|
|
3527
|
+
* it first, as element.animate() does, would leave WebKit holding that
|
|
3528
|
+
* play's ready time once startTime ends the play, and it uses that for
|
|
3529
|
+
* the next updatePlaybackRate(), so the animation would jump.
|
|
3530
|
+
*/
|
|
3531
|
+
const create = (keyframes, options) => new Animation(new KeyframeEffect(element, keyframes, options));
|
|
3560
3532
|
const add = (animation, offset, end = Infinity) => {
|
|
3561
3533
|
const segment = { animation, offset, end };
|
|
3562
3534
|
animation.startTime = time.now() + offset;
|
|
@@ -3749,7 +3721,7 @@ function createGroup(owner) {
|
|
|
3749
3721
|
commit(valuesAt(from, settled));
|
|
3750
3722
|
keyframes = null;
|
|
3751
3723
|
}
|
|
3752
|
-
return
|
|
3724
|
+
return create(keyframes, {
|
|
3753
3725
|
...options,
|
|
3754
3726
|
duration: to - from,
|
|
3755
3727
|
easing: easing || "linear",
|
|
@@ -3839,9 +3811,7 @@ function createGroup(owner) {
|
|
|
3839
3811
|
* empty animations that end with them.
|
|
3840
3812
|
*/
|
|
3841
3813
|
ends.forEach((trackEnd) => trackEnd < end - 1 &&
|
|
3842
|
-
add(
|
|
3843
|
-
duration: trackEnd - now,
|
|
3844
|
-
}), 0, trackEnd - now));
|
|
3814
|
+
add(create(null, { duration: trackEnd - now }), 0, trackEnd - now));
|
|
3845
3815
|
}
|
|
3846
3816
|
if (cycle) {
|
|
3847
3817
|
/**
|
|
@@ -3915,12 +3885,29 @@ function createGroup(owner) {
|
|
|
3915
3885
|
if (isDone)
|
|
3916
3886
|
continue;
|
|
3917
3887
|
const local = elapsed - offset;
|
|
3918
|
-
if (rate
|
|
3888
|
+
if (rate &&
|
|
3889
|
+
animation.updatePlaybackRate &&
|
|
3890
|
+
animation.playState === "running" &&
|
|
3891
|
+
Math.abs(Number(animation.currentTime) - local) < 20) {
|
|
3892
|
+
/**
|
|
3893
|
+
* Only the speed changed. Setting playbackRate and
|
|
3894
|
+
* startTime restarts a running compositor animation, which
|
|
3895
|
+
* can render the underlying value for a frame.
|
|
3896
|
+
*/
|
|
3897
|
+
animation.playbackRate !== rate &&
|
|
3898
|
+
animation.updatePlaybackRate(rate);
|
|
3899
|
+
}
|
|
3900
|
+
else if (rate) {
|
|
3919
3901
|
animation.playbackRate = rate;
|
|
3920
3902
|
animation.startTime = now - local / rate;
|
|
3921
3903
|
}
|
|
3922
3904
|
else {
|
|
3923
|
-
|
|
3905
|
+
/**
|
|
3906
|
+
* Hold it without pause(), whose pending pause setting
|
|
3907
|
+
* currentTime would end at once, leaving WebKit holding its
|
|
3908
|
+
* ready time (see create()).
|
|
3909
|
+
*/
|
|
3910
|
+
animation.startTime = null;
|
|
3924
3911
|
animation.currentTime = local;
|
|
3925
3912
|
}
|
|
3926
3913
|
}
|
|
@@ -4067,6 +4054,7 @@ function createGroup(owner) {
|
|
|
4067
4054
|
built = new Map();
|
|
4068
4055
|
stop();
|
|
4069
4056
|
tracks.forEach((track) => track.state === "running" && track.js?.start());
|
|
4057
|
+
return true;
|
|
4070
4058
|
},
|
|
4071
4059
|
};
|
|
4072
4060
|
transformGroups.set(element, group);
|
|
@@ -4111,9 +4099,8 @@ class AsyncMotionValueAnimation extends WithPromise {
|
|
|
4111
4099
|
* If we can't animate this value with the resolved keyframes
|
|
4112
4100
|
* then we should complete it immediately.
|
|
4113
4101
|
*/
|
|
4114
|
-
|
|
4115
|
-
if (!
|
|
4116
|
-
canAnimateValue = false;
|
|
4102
|
+
const canAnimateValue = canAnimate(keyframes, name, type, velocity);
|
|
4103
|
+
if (!canAnimateValue) {
|
|
4117
4104
|
if (motionUtils.MotionGlobalConfig.instantAnimations || !delay) {
|
|
4118
4105
|
onUpdate?.(getFinalKeyframe(keyframes, options, finalKeyframe));
|
|
4119
4106
|
}
|
|
@@ -4257,9 +4244,7 @@ class AsyncMotionValueAnimation extends WithPromise {
|
|
|
4257
4244
|
this.animation.complete();
|
|
4258
4245
|
}
|
|
4259
4246
|
cancel() {
|
|
4260
|
-
|
|
4261
|
-
this.animation.cancel();
|
|
4262
|
-
}
|
|
4247
|
+
this._animation?.cancel();
|
|
4263
4248
|
this.keyframeResolver?.cancel();
|
|
4264
4249
|
}
|
|
4265
4250
|
}
|
|
@@ -4442,7 +4427,7 @@ class MotionValue {
|
|
|
4442
4427
|
this.setCurrent(v);
|
|
4443
4428
|
// Update update subscribers
|
|
4444
4429
|
if (this.current !== this.prev) {
|
|
4445
|
-
this.
|
|
4430
|
+
this.dirty();
|
|
4446
4431
|
if (this.dependents) {
|
|
4447
4432
|
for (const dependent of this.dependents) {
|
|
4448
4433
|
dependent.dirty();
|
|
@@ -4580,12 +4565,9 @@ class MotionValue {
|
|
|
4580
4565
|
* @public
|
|
4581
4566
|
*/
|
|
4582
4567
|
set(v) {
|
|
4583
|
-
|
|
4584
|
-
this.
|
|
4585
|
-
|
|
4586
|
-
else {
|
|
4587
|
-
this.passiveEffect(v, this.updateAndNotify);
|
|
4588
|
-
}
|
|
4568
|
+
this.passiveEffect
|
|
4569
|
+
? this.passiveEffect(v, this.updateAndNotify)
|
|
4570
|
+
: this.updateAndNotify(v);
|
|
4589
4571
|
}
|
|
4590
4572
|
setWithVelocity(prev, current, delta) {
|
|
4591
4573
|
this.set(current);
|
|
@@ -4602,13 +4584,9 @@ class MotionValue {
|
|
|
4602
4584
|
this.prev = v;
|
|
4603
4585
|
this.prevUpdatedAt = this.prevFrameValue = undefined;
|
|
4604
4586
|
endAnimation && this.stop();
|
|
4605
|
-
|
|
4606
|
-
this.stopPassiveEffect();
|
|
4587
|
+
this.stopPassiveEffect?.();
|
|
4607
4588
|
}
|
|
4608
4589
|
dirty() {
|
|
4609
|
-
this.notifyChange();
|
|
4610
|
-
}
|
|
4611
|
-
notifyChange() {
|
|
4612
4590
|
const { current, changeSubscriber } = this;
|
|
4613
4591
|
/**
|
|
4614
4592
|
* One or the other exists. Subscribing during the direct
|
|
@@ -4623,15 +4601,10 @@ class MotionValue {
|
|
|
4623
4601
|
}
|
|
4624
4602
|
}
|
|
4625
4603
|
addDependent(dependent) {
|
|
4626
|
-
|
|
4627
|
-
this.dependents = new Set();
|
|
4628
|
-
}
|
|
4629
|
-
this.dependents.add(dependent);
|
|
4604
|
+
(this.dependents || (this.dependents = new Set())).add(dependent);
|
|
4630
4605
|
}
|
|
4631
4606
|
removeDependent(dependent) {
|
|
4632
|
-
|
|
4633
|
-
this.dependents.delete(dependent);
|
|
4634
|
-
}
|
|
4607
|
+
this.dependents?.delete(dependent);
|
|
4635
4608
|
}
|
|
4636
4609
|
/**
|
|
4637
4610
|
* Returns the latest state of `MotionValue`
|
|
@@ -4641,9 +4614,7 @@ class MotionValue {
|
|
|
4641
4614
|
* @public
|
|
4642
4615
|
*/
|
|
4643
4616
|
get() {
|
|
4644
|
-
|
|
4645
|
-
collectMotionValues.current.push(this);
|
|
4646
|
-
}
|
|
4617
|
+
collectMotionValues.current?.push(this);
|
|
4647
4618
|
/**
|
|
4648
4619
|
* A value animating on the compositor isn't updated every frame,
|
|
4649
4620
|
* so read it from its animation.
|
|
@@ -4709,7 +4680,7 @@ class MotionValue {
|
|
|
4709
4680
|
isComplete = true;
|
|
4710
4681
|
this.events.animationComplete?.notify();
|
|
4711
4682
|
if (this.animation === animation)
|
|
4712
|
-
this.
|
|
4683
|
+
this.animation = undefined;
|
|
4713
4684
|
resolve();
|
|
4714
4685
|
});
|
|
4715
4686
|
if (!isComplete)
|
|
@@ -4725,11 +4696,10 @@ class MotionValue {
|
|
|
4725
4696
|
stop() {
|
|
4726
4697
|
if (this.animation) {
|
|
4727
4698
|
this.animation.stop();
|
|
4728
|
-
|
|
4729
|
-
this.events.animationCancel.notify();
|
|
4730
|
-
}
|
|
4699
|
+
this.events.animationCancel?.notify();
|
|
4731
4700
|
}
|
|
4732
|
-
|
|
4701
|
+
// Assign rather than delete to keep the object's shape stable
|
|
4702
|
+
this.animation = undefined;
|
|
4733
4703
|
}
|
|
4734
4704
|
/**
|
|
4735
4705
|
* Returns `true` if this value is currently animating.
|
|
@@ -4739,10 +4709,6 @@ class MotionValue {
|
|
|
4739
4709
|
isAnimating() {
|
|
4740
4710
|
return !!this.animation;
|
|
4741
4711
|
}
|
|
4742
|
-
clearAnimation() {
|
|
4743
|
-
// Assign rather than delete to keep the object's shape stable
|
|
4744
|
-
this.animation = undefined;
|
|
4745
|
-
}
|
|
4746
4712
|
/**
|
|
4747
4713
|
* Destroy and clean up subscribers to this `MotionValue`.
|
|
4748
4714
|
*
|
|
@@ -4757,9 +4723,7 @@ class MotionValue {
|
|
|
4757
4723
|
this.events.destroy?.notify();
|
|
4758
4724
|
this.clearListeners();
|
|
4759
4725
|
this.stop();
|
|
4760
|
-
|
|
4761
|
-
this.stopPassiveEffect();
|
|
4762
|
-
}
|
|
4726
|
+
this.stopPassiveEffect?.();
|
|
4763
4727
|
}
|
|
4764
4728
|
}
|
|
4765
4729
|
function motionValue(init, options) {
|
|
@@ -4837,6 +4801,7 @@ const orchestrationKeys = new Set([
|
|
|
4837
4801
|
"repeatDelay",
|
|
4838
4802
|
"from",
|
|
4839
4803
|
"elapsed",
|
|
4804
|
+
"out",
|
|
4840
4805
|
]);
|
|
4841
4806
|
/**
|
|
4842
4807
|
* Decide whether a transition is defined on a given Transition.
|
|
@@ -5148,7 +5113,8 @@ function parseCSSVariable(current) {
|
|
|
5148
5113
|
}
|
|
5149
5114
|
const maxDepth = 4;
|
|
5150
5115
|
function getVariableValue(current, element, depth = 1) {
|
|
5151
|
-
|
|
5116
|
+
process.env.NODE_ENV !== "production" &&
|
|
5117
|
+
motionUtils.invariant(depth <= maxDepth, `Max CSS variable fallback depth detected in property "${current}". This may indicate a circular fallback dependency.`, "max-css-var-depth");
|
|
5152
5118
|
const [token, fallback] = parseCSSVariable(current);
|
|
5153
5119
|
// No CSS variable detected
|
|
5154
5120
|
if (!token)
|
|
@@ -5307,7 +5273,7 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
|
|
|
5307
5273
|
}
|
|
5308
5274
|
const valueTransition = {
|
|
5309
5275
|
delay,
|
|
5310
|
-
...getValueTransition(transition || {}, key),
|
|
5276
|
+
...getValueTransition(animationTypeState?.out[key] || transition || {}, key),
|
|
5311
5277
|
};
|
|
5312
5278
|
if (skipAnimations)
|
|
5313
5279
|
valueTransition.skipAnimations = true;
|
|
@@ -5477,8 +5443,9 @@ function makeNoneKeyframesAnimatable(unresolvedKeyframes, noneKeyframeIndexes, n
|
|
|
5477
5443
|
}
|
|
5478
5444
|
|
|
5479
5445
|
class DOMKeyframesResolver extends KeyframeResolver {
|
|
5480
|
-
constructor(
|
|
5481
|
-
super(
|
|
5446
|
+
constructor() {
|
|
5447
|
+
super(...arguments);
|
|
5448
|
+
this.isAsync = true;
|
|
5482
5449
|
}
|
|
5483
5450
|
/**
|
|
5484
5451
|
* Keyframes that don't need reading from the DOM, or measuring,
|
|
@@ -5506,7 +5473,7 @@ class DOMKeyframesResolver extends KeyframeResolver {
|
|
|
5506
5473
|
}
|
|
5507
5474
|
readKeyframes() {
|
|
5508
5475
|
const { unresolvedKeyframes, element, name } = this;
|
|
5509
|
-
if (!element
|
|
5476
|
+
if (!element?.current)
|
|
5510
5477
|
return;
|
|
5511
5478
|
super.readKeyframes();
|
|
5512
5479
|
/**
|
|
@@ -5601,11 +5568,10 @@ class DOMKeyframesResolver extends KeyframeResolver {
|
|
|
5601
5568
|
}
|
|
5602
5569
|
measureInitialState() {
|
|
5603
5570
|
const { element, unresolvedKeyframes, name } = this;
|
|
5604
|
-
if (!element
|
|
5571
|
+
if (!element?.current)
|
|
5605
5572
|
return;
|
|
5606
|
-
if (name === "height")
|
|
5573
|
+
if (name === "height")
|
|
5607
5574
|
this.suspendedScrollY = window.pageYOffset;
|
|
5608
|
-
}
|
|
5609
5575
|
this.measuredOrigin = this.measure();
|
|
5610
5576
|
unresolvedKeyframes[0] = this.measuredOrigin;
|
|
5611
5577
|
// Set final key frame to measure after next render
|
|
@@ -5616,7 +5582,7 @@ class DOMKeyframesResolver extends KeyframeResolver {
|
|
|
5616
5582
|
}
|
|
5617
5583
|
measureEndState() {
|
|
5618
5584
|
const { element, unresolvedKeyframes } = this;
|
|
5619
|
-
if (!element
|
|
5585
|
+
if (!element?.current)
|
|
5620
5586
|
return;
|
|
5621
5587
|
this.motionValue?.jump(this.measuredOrigin, false);
|
|
5622
5588
|
const finalKeyframeIndex = unresolvedKeyframes.length - 1;
|
|
@@ -5625,14 +5591,6 @@ class DOMKeyframesResolver extends KeyframeResolver {
|
|
|
5625
5591
|
if (finalKeyframe !== null && this.finalKeyframe === undefined) {
|
|
5626
5592
|
this.finalKeyframe = finalKeyframe;
|
|
5627
5593
|
}
|
|
5628
|
-
// If we removed transform values, reapply them before the next render
|
|
5629
|
-
if (this.removedTransforms?.length) {
|
|
5630
|
-
this.removedTransforms.forEach(([unsetTransformName, unsetTransformValue]) => {
|
|
5631
|
-
element
|
|
5632
|
-
.getValue(unsetTransformName)
|
|
5633
|
-
.set(unsetTransformValue);
|
|
5634
|
-
});
|
|
5635
|
-
}
|
|
5636
5594
|
this.resolveNoneKeyframes();
|
|
5637
5595
|
}
|
|
5638
5596
|
}
|
|
@@ -5737,7 +5695,9 @@ const supportsPartialKeyframes = /*@__PURE__*/ motionUtils.memo(() => {
|
|
|
5737
5695
|
*/
|
|
5738
5696
|
const effects = [];
|
|
5739
5697
|
function addEffect(effect) {
|
|
5740
|
-
|
|
5698
|
+
process.env.NODE_ENV !== "production" &&
|
|
5699
|
+
motionUtils.invariant(typeof effect.test === "function" &&
|
|
5700
|
+
typeof effect.read === "function", "Effects passed to animate.addEffect() need test() and read().", "effect-missing-test");
|
|
5741
5701
|
removeEffect(effect);
|
|
5742
5702
|
effects.unshift(effect);
|
|
5743
5703
|
}
|
|
@@ -5824,7 +5784,8 @@ function animateEffectSubject(effect, subject, keyframes, transition, element) {
|
|
|
5824
5784
|
initial =
|
|
5825
5785
|
firstKeyframe(target) ??
|
|
5826
5786
|
effect.read(subject, key, target);
|
|
5827
|
-
|
|
5787
|
+
process.env.NODE_ENV !== "production" &&
|
|
5788
|
+
motionUtils.invariant(initial !== undefined, `"${key}" can't be read from the animated subject. Provide [from, to] keyframes.`, "effect-unreadable-value");
|
|
5828
5789
|
}
|
|
5829
5790
|
value = motionValue(initial, { owner: element });
|
|
5830
5791
|
effect(subject, { [key]: value });
|
|
@@ -6064,11 +6025,6 @@ function createEffect(addValue, { step, ...options } = {}) {
|
|
|
6064
6025
|
});
|
|
6065
6026
|
}
|
|
6066
6027
|
|
|
6067
|
-
/**
|
|
6068
|
-
* Cache of `translateX(`-style openers so each render is a few string
|
|
6069
|
-
* concatenations rather than a template per transform.
|
|
6070
|
-
*/
|
|
6071
|
-
const openers = {};
|
|
6072
6028
|
function buildTransform(state) {
|
|
6073
6029
|
let transform = "";
|
|
6074
6030
|
const { transformKeys: keys = [], transformValues: values = {} } = state;
|
|
@@ -6081,14 +6037,8 @@ function buildTransform(state) {
|
|
|
6081
6037
|
const value = values[key].getCurrent();
|
|
6082
6038
|
if (value === undefined)
|
|
6083
6039
|
continue;
|
|
6084
|
-
|
|
6085
|
-
|
|
6086
|
-
transform +=
|
|
6087
|
-
(transform && " ") +
|
|
6088
|
-
(openers[key] ||
|
|
6089
|
-
(openers[key] = (translateAlias[key] || key) + "(")) +
|
|
6090
|
-
getValueAsType(value, transformValueTypes[key]) +
|
|
6091
|
-
")";
|
|
6040
|
+
if (!isDefaultTransform(key, value)) {
|
|
6041
|
+
transform += (transform && " ") + transformFunction(key, value);
|
|
6092
6042
|
}
|
|
6093
6043
|
}
|
|
6094
6044
|
// See build-transform.ts: additive `rotate()` so user `rotate` isn't
|
|
@@ -6096,10 +6046,7 @@ function buildTransform(state) {
|
|
|
6096
6046
|
const pathRotation = state.get("pathRotation")?.get();
|
|
6097
6047
|
if (pathRotation) {
|
|
6098
6048
|
transform +=
|
|
6099
|
-
(transform && " ") +
|
|
6100
|
-
"rotate(" +
|
|
6101
|
-
getValueAsType(pathRotation, transformValueTypes.pathRotation) +
|
|
6102
|
-
")";
|
|
6049
|
+
(transform && " ") + transformFunction("rotate", pathRotation);
|
|
6103
6050
|
}
|
|
6104
6051
|
return transform || "none";
|
|
6105
6052
|
}
|
|
@@ -6502,10 +6449,24 @@ function hasScale({ scale, scaleX, scaleY }) {
|
|
|
6502
6449
|
!isIdentityScale(scaleX) ||
|
|
6503
6450
|
!isIdentityScale(scaleY));
|
|
6504
6451
|
}
|
|
6452
|
+
/**
|
|
6453
|
+
* Rotations and skews, which projection can't correct for.
|
|
6454
|
+
*/
|
|
6455
|
+
const angleTransforms = [
|
|
6456
|
+
"rotate",
|
|
6457
|
+
"rotateX",
|
|
6458
|
+
"rotateY",
|
|
6459
|
+
"rotateZ",
|
|
6460
|
+
"skewX",
|
|
6461
|
+
"skewY",
|
|
6462
|
+
];
|
|
6505
6463
|
function hasTransform(values) {
|
|
6506
6464
|
return (hasScale(values) ||
|
|
6507
6465
|
has2DTranslate(values) ||
|
|
6508
|
-
values
|
|
6466
|
+
hasDistortingTransform(values));
|
|
6467
|
+
}
|
|
6468
|
+
function hasDistortingTransform(values) {
|
|
6469
|
+
return (values.z ||
|
|
6509
6470
|
values.rotate ||
|
|
6510
6471
|
values.rotateX ||
|
|
6511
6472
|
values.rotateY ||
|
|
@@ -6558,6 +6519,11 @@ const TREE_SCALE_SNAP_MAX = 1.0000000000001;
|
|
|
6558
6519
|
* in a tree upon our box before then calculating how to project it into our desired viewport-relative box
|
|
6559
6520
|
*
|
|
6560
6521
|
* This is the final nested loop within updateLayoutDelta for future refactoring
|
|
6522
|
+
*
|
|
6523
|
+
* isSharedTransition is true for a shared layout animation in page space, which
|
|
6524
|
+
* also applies ancestor scroll and transforms. Or it's the layoutRoot a shared
|
|
6525
|
+
* animation is relative to, so only transforms of ancestors not shared with it
|
|
6526
|
+
* (or above it) are applied.
|
|
6561
6527
|
*/
|
|
6562
6528
|
function applyTreeDeltas(box, treeScale, treePath, isSharedTransition = false) {
|
|
6563
6529
|
const treeLength = treePath.length;
|
|
@@ -6574,13 +6540,10 @@ function applyTreeDeltas(box, treeScale, treePath, isSharedTransition = false) {
|
|
|
6574
6540
|
* TODO: Prefer to remove this, but currently we have motion components with
|
|
6575
6541
|
* display: contents in Framer.
|
|
6576
6542
|
*/
|
|
6577
|
-
|
|
6578
|
-
if (visualElement &&
|
|
6579
|
-
visualElement.props.style &&
|
|
6580
|
-
visualElement.props.style.display === "contents") {
|
|
6543
|
+
if (node.options.visualElement?.props.style?.display === "contents") {
|
|
6581
6544
|
continue;
|
|
6582
6545
|
}
|
|
6583
|
-
if (isSharedTransition &&
|
|
6546
|
+
if (isSharedTransition === true &&
|
|
6584
6547
|
node.options.layoutScroll &&
|
|
6585
6548
|
node.scroll &&
|
|
6586
6549
|
node !== node.root) {
|
|
@@ -6594,7 +6557,9 @@ function applyTreeDeltas(box, treeScale, treePath, isSharedTransition = false) {
|
|
|
6594
6557
|
// Apply each ancestor's calculated delta into this component's recorded layout box
|
|
6595
6558
|
applyBoxDelta(box, delta);
|
|
6596
6559
|
}
|
|
6597
|
-
if (isSharedTransition &&
|
|
6560
|
+
if (isSharedTransition &&
|
|
6561
|
+
(isSharedTransition.path?.[i] || isSharedTransition) !== node &&
|
|
6562
|
+
hasTransform(node.latestValues)) {
|
|
6598
6563
|
transformBox(box, node.latestValues, node.layout?.layoutBox);
|
|
6599
6564
|
}
|
|
6600
6565
|
}
|
|
@@ -6868,15 +6833,6 @@ function resolveMotionValue(value) {
|
|
|
6868
6833
|
const asNumber = (v) => typeof v === "number" ? v : parseFloat(v);
|
|
6869
6834
|
|
|
6870
6835
|
const numBorders = cornerRadiusProps.length;
|
|
6871
|
-
const mixedTransforms = [
|
|
6872
|
-
"rotate",
|
|
6873
|
-
"rotateX",
|
|
6874
|
-
"rotateY",
|
|
6875
|
-
"rotateZ",
|
|
6876
|
-
"skewX",
|
|
6877
|
-
"skewY",
|
|
6878
|
-
];
|
|
6879
|
-
const numMixedTransforms = mixedTransforms.length;
|
|
6880
6836
|
const isPx = (value) => typeof value === "number" || px.test(value);
|
|
6881
6837
|
function mixValues(target, follow, lead, progress, shouldCrossfadeOpacity, isOnlyMember) {
|
|
6882
6838
|
if (shouldCrossfadeOpacity) {
|
|
@@ -6914,8 +6870,8 @@ function mixValues(target, follow, lead, progress, shouldCrossfadeOpacity, isOnl
|
|
|
6914
6870
|
* Mix rotation and skew. These can't be projected, so mix them every
|
|
6915
6871
|
* frame rather than leaving them frozen at the animation-start snapshot.
|
|
6916
6872
|
*/
|
|
6917
|
-
for (let i = 0; i <
|
|
6918
|
-
const key =
|
|
6873
|
+
for (let i = 0; i < angleTransforms.length; i++) {
|
|
6874
|
+
const key = angleTransforms[i];
|
|
6919
6875
|
if (follow[key] || lead[key]) {
|
|
6920
6876
|
target[key] = mixNumber$1(follow[key] || 0, lead[key] || 0, progress);
|
|
6921
6877
|
}
|
|
@@ -6998,8 +6954,8 @@ function calcAxisDelta(delta, source, target, origin = 0.5) {
|
|
|
6998
6954
|
}
|
|
6999
6955
|
}
|
|
7000
6956
|
function calcBoxDelta(delta, source, target, origin) {
|
|
7001
|
-
calcAxisDelta(delta.x, source.x, target.x, origin
|
|
7002
|
-
calcAxisDelta(delta.y, source.y, target.y, origin
|
|
6957
|
+
calcAxisDelta(delta.x, source.x, target.x, origin?.originX);
|
|
6958
|
+
calcAxisDelta(delta.y, source.y, target.y, origin?.originY);
|
|
7003
6959
|
}
|
|
7004
6960
|
function calcRelativeAxis(target, relative, parent, anchor = 0) {
|
|
7005
6961
|
const anchorPoint = anchor
|
|
@@ -7069,8 +7025,8 @@ const yKeys = ["y", "scaleY", "originY"];
|
|
|
7069
7025
|
* and acts as a bridge between motion values and removeAxisDelta
|
|
7070
7026
|
*/
|
|
7071
7027
|
function removeBoxTransforms(box, transforms, originBox, sourceBox) {
|
|
7072
|
-
removeAxisTransforms(box.x, transforms, xKeys, originBox
|
|
7073
|
-
removeAxisTransforms(box.y, transforms, yKeys, originBox
|
|
7028
|
+
removeAxisTransforms(box.x, transforms, xKeys, originBox?.x, sourceBox?.x);
|
|
7029
|
+
removeAxisTransforms(box.y, transforms, yKeys, originBox?.y, sourceBox?.y);
|
|
7074
7030
|
}
|
|
7075
7031
|
|
|
7076
7032
|
const createAxisDelta = () => ({
|
|
@@ -7300,24 +7256,18 @@ function buildProjectionTransform(delta, treeScale, latestTransform) {
|
|
|
7300
7256
|
transform += `scale(${1 / treeScale.x}, ${1 / treeScale.y}) `;
|
|
7301
7257
|
}
|
|
7302
7258
|
if (latestTransform) {
|
|
7303
|
-
const { transformPerspective
|
|
7259
|
+
const { transformPerspective } = latestTransform;
|
|
7304
7260
|
if (transformPerspective)
|
|
7305
7261
|
transform = `perspective(${transformPerspective}px) ${transform}`;
|
|
7306
|
-
|
|
7307
|
-
|
|
7308
|
-
|
|
7309
|
-
|
|
7310
|
-
|
|
7311
|
-
|
|
7312
|
-
|
|
7313
|
-
|
|
7314
|
-
|
|
7315
|
-
if (rotateZ)
|
|
7316
|
-
transform += `rotateZ(${rotateZ}deg) `;
|
|
7317
|
-
if (skewX)
|
|
7318
|
-
transform += `skewX(${skewX}deg) `;
|
|
7319
|
-
if (skewY)
|
|
7320
|
-
transform += `skewY(${skewY}deg) `;
|
|
7262
|
+
for (let i = 0; i < angleTransforms.length; i++) {
|
|
7263
|
+
const key = angleTransforms[i];
|
|
7264
|
+
const value = latestTransform[key];
|
|
7265
|
+
if (value)
|
|
7266
|
+
transform += `${key}(${value}deg) `;
|
|
7267
|
+
// Additive `rotate()` so user `rotate` isn't clobbered.
|
|
7268
|
+
if (!i && latestTransform.pathRotation)
|
|
7269
|
+
transform += `rotate(${latestTransform.pathRotation}deg) `;
|
|
7270
|
+
}
|
|
7321
7271
|
}
|
|
7322
7272
|
/**
|
|
7323
7273
|
* Apply scale to match the size of the element to the size we want it.
|
|
@@ -7380,7 +7330,10 @@ const metrics = {
|
|
|
7380
7330
|
calculatedTargetDeltas: 0,
|
|
7381
7331
|
calculatedProjections: 0,
|
|
7382
7332
|
};
|
|
7383
|
-
|
|
7333
|
+
/**
|
|
7334
|
+
* Transforms that distort an element's layout, so must be reset before measuring.
|
|
7335
|
+
*/
|
|
7336
|
+
const distortingTransforms = ["z", "skew", "skewZ"];
|
|
7384
7337
|
/**
|
|
7385
7338
|
* We use 1000 as the animation target as 0-1000 maps better to pixels than 0-1
|
|
7386
7339
|
* which has a noticeable difference in spring animations
|
|
@@ -7398,7 +7351,15 @@ function resetDistortingTransform(key, visualElement, values, sharedAnimationVal
|
|
|
7398
7351
|
}
|
|
7399
7352
|
}
|
|
7400
7353
|
}
|
|
7401
|
-
|
|
7354
|
+
/**
|
|
7355
|
+
* Move accelerated transforms back to the main thread. The WAAPI animation
|
|
7356
|
+
* hid startUpdate()'s reset of rotations, skews and z, and moving off it
|
|
7357
|
+
* writes the whole transform back, so reset them again before this node
|
|
7358
|
+
* is measured.
|
|
7359
|
+
*/
|
|
7360
|
+
const demoteTransforms = (node) => node.instance &&
|
|
7361
|
+
transformGroups.get(node.instance)?.demote() &&
|
|
7362
|
+
node.resetSkewAndRotation();
|
|
7402
7363
|
function cancelTreeOptimisedTransformAnimations(projectionNode) {
|
|
7403
7364
|
projectionNode.hasCheckedOptimisedAppear = true;
|
|
7404
7365
|
if (projectionNode.root === projectionNode)
|
|
@@ -7588,8 +7549,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
7588
7549
|
return this.eventHandlers.get(name).add(handler);
|
|
7589
7550
|
}
|
|
7590
7551
|
notifyListeners(name, ...args) {
|
|
7591
|
-
|
|
7592
|
-
subscriptionManager && subscriptionManager.notify(...args);
|
|
7552
|
+
this.eventHandlers.get(name)?.notify(...args);
|
|
7593
7553
|
}
|
|
7594
7554
|
hasListeners(name) {
|
|
7595
7555
|
return this.eventHandlers.has(name);
|
|
@@ -7607,7 +7567,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
7607
7567
|
visualElement.mount(instance);
|
|
7608
7568
|
}
|
|
7609
7569
|
this.root.nodes.add(this);
|
|
7610
|
-
this.parent
|
|
7570
|
+
this.parent?.children.add(this);
|
|
7611
7571
|
if (this.root.hasTreeAnimated && (layout || layoutId)) {
|
|
7612
7572
|
this.isLayoutDirty = true;
|
|
7613
7573
|
}
|
|
@@ -7625,7 +7585,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
7625
7585
|
return;
|
|
7626
7586
|
innerWidth = newInnerWidth;
|
|
7627
7587
|
this.root.updateBlockedByResize = true;
|
|
7628
|
-
cancelDelay
|
|
7588
|
+
cancelDelay?.();
|
|
7629
7589
|
cancelDelay = delay(resizeUnblockUpdate, 250);
|
|
7630
7590
|
if (globalProjectionState.hasAnimatedSinceResize) {
|
|
7631
7591
|
globalProjectionState.hasAnimatedSinceResize = false;
|
|
@@ -7716,9 +7676,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
7716
7676
|
if (!hasLayoutChanged) {
|
|
7717
7677
|
finishAnimation(this);
|
|
7718
7678
|
}
|
|
7719
|
-
|
|
7720
|
-
this.options.onExitComplete();
|
|
7721
|
-
}
|
|
7679
|
+
this.isLead() && this.options.onExitComplete?.();
|
|
7722
7680
|
}
|
|
7723
7681
|
this.targetLayout = newLayout;
|
|
7724
7682
|
});
|
|
@@ -7726,9 +7684,8 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
7726
7684
|
unmount() {
|
|
7727
7685
|
this.options.layoutId && this.willUpdate();
|
|
7728
7686
|
this.root.nodes.remove(this);
|
|
7729
|
-
|
|
7730
|
-
|
|
7731
|
-
this.parent && this.parent.children.delete(this);
|
|
7687
|
+
this.getStack()?.remove(this);
|
|
7688
|
+
this.parent?.children.delete(this);
|
|
7732
7689
|
this.instance = undefined;
|
|
7733
7690
|
this.eventHandlers.clear();
|
|
7734
7691
|
this.hasLayoutListener = false;
|
|
@@ -7749,7 +7706,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
7749
7706
|
if (this.isUpdateBlocked())
|
|
7750
7707
|
return;
|
|
7751
7708
|
this.isUpdating = true;
|
|
7752
|
-
this.nodes
|
|
7709
|
+
this.nodes?.forEach(resetSkewAndRotation);
|
|
7753
7710
|
this.animationId++;
|
|
7754
7711
|
}
|
|
7755
7712
|
getTransformTemplate() {
|
|
@@ -7759,7 +7716,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
7759
7716
|
willUpdate(shouldNotifyListeners = true) {
|
|
7760
7717
|
this.root.hasTreeAnimated = true;
|
|
7761
7718
|
if (this.root.isUpdateBlocked()) {
|
|
7762
|
-
this.options.onExitComplete
|
|
7719
|
+
this.options.onExitComplete?.();
|
|
7763
7720
|
return;
|
|
7764
7721
|
}
|
|
7765
7722
|
/**
|
|
@@ -7976,24 +7933,23 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
7976
7933
|
this.projectionDelta = undefined;
|
|
7977
7934
|
this.notifyListeners("measure", this.layout.layoutBox);
|
|
7978
7935
|
const { visualElement } = this.options;
|
|
7979
|
-
visualElement
|
|
7980
|
-
visualElement.notify("LayoutMeasure", this.layout.layoutBox, prevLayout ? prevLayout.layoutBox : undefined);
|
|
7936
|
+
visualElement?.notify("LayoutMeasure", this.layout.layoutBox, prevLayout?.layoutBox);
|
|
7981
7937
|
}
|
|
7982
7938
|
updateScroll(phase = "measure") {
|
|
7983
|
-
|
|
7984
|
-
|
|
7985
|
-
|
|
7986
|
-
|
|
7987
|
-
|
|
7988
|
-
|
|
7989
|
-
|
|
7990
|
-
const isRoot = checkIsScrollRoot(
|
|
7939
|
+
const { scroll, instance } = this;
|
|
7940
|
+
const { animationId } = this.root;
|
|
7941
|
+
if (this.options.layoutScroll &&
|
|
7942
|
+
instance &&
|
|
7943
|
+
!(scroll &&
|
|
7944
|
+
scroll.animationId === animationId &&
|
|
7945
|
+
scroll.phase === phase)) {
|
|
7946
|
+
const isRoot = checkIsScrollRoot(instance);
|
|
7991
7947
|
this.scroll = {
|
|
7992
|
-
animationId
|
|
7948
|
+
animationId,
|
|
7993
7949
|
phase,
|
|
7994
7950
|
isRoot,
|
|
7995
|
-
offset: measureScroll(
|
|
7996
|
-
wasRoot:
|
|
7951
|
+
offset: measureScroll(instance),
|
|
7952
|
+
wasRoot: scroll ? scroll.isRoot : isRoot,
|
|
7997
7953
|
};
|
|
7998
7954
|
}
|
|
7999
7955
|
}
|
|
@@ -8083,10 +8039,10 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8083
8039
|
}
|
|
8084
8040
|
return boxWithoutScroll;
|
|
8085
8041
|
}
|
|
8086
|
-
applyTransform(box, transformOnly = false, output, skipOwnTransform) {
|
|
8042
|
+
applyTransform(box, transformOnly = false, output, skipOwnTransform, start = 0) {
|
|
8087
8043
|
const withTransforms = output || createBox();
|
|
8088
8044
|
copyBoxInto(withTransforms, box);
|
|
8089
|
-
for (let i =
|
|
8045
|
+
for (let i = start; i < this.path.length; i++) {
|
|
8090
8046
|
const node = this.path[i];
|
|
8091
8047
|
if (!transformOnly &&
|
|
8092
8048
|
node.options.layoutScroll &&
|
|
@@ -8258,8 +8214,13 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8258
8214
|
this.attemptToResolveRelativeTarget = false;
|
|
8259
8215
|
if (this.options.layoutAnchor !== false &&
|
|
8260
8216
|
relativeParent &&
|
|
8261
|
-
|
|
8262
|
-
|
|
8217
|
+
(!relativeParent.resumingFrom === !this.resumingFrom ||
|
|
8218
|
+
/**
|
|
8219
|
+
* Shared layout animations within a layoutRoot
|
|
8220
|
+
* animate relative to it.
|
|
8221
|
+
*/
|
|
8222
|
+
(relativeParent.options.layoutRoot &&
|
|
8223
|
+
!relativeParent.resumingFrom)) &&
|
|
8263
8224
|
!relativeParent.options.layoutScroll &&
|
|
8264
8225
|
relativeParent.target &&
|
|
8265
8226
|
this.animationProgress !== 1) {
|
|
@@ -8339,7 +8300,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8339
8300
|
* If this section of the tree isn't animating we can
|
|
8340
8301
|
* delete our target sources for the following frame.
|
|
8341
8302
|
*/
|
|
8342
|
-
this.isTreeAnimating = Boolean(
|
|
8303
|
+
this.isTreeAnimating = Boolean(this.parent?.isTreeAnimating ||
|
|
8343
8304
|
this.currentAnimation ||
|
|
8344
8305
|
this.pendingAnimation);
|
|
8345
8306
|
if (!this.isTreeAnimating) {
|
|
@@ -8360,8 +8321,17 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8360
8321
|
/**
|
|
8361
8322
|
* Apply all the parent deltas to this box to produce the corrected box. This
|
|
8362
8323
|
* is the layout box, as it will appear on screen as a result of the transforms of its parents.
|
|
8324
|
+
*
|
|
8325
|
+
* A shared target is usually in page space, so ancestor transforms are applied
|
|
8326
|
+
* too. But a target relative to a parent that isn't itself shared (like a
|
|
8327
|
+
* layoutRoot) is in that parent's layout space. So the transforms of the
|
|
8328
|
+
* parent and its ancestors, which move both elements alike, are skipped,
|
|
8329
|
+
* but those of other ancestors (between it and either element) apply.
|
|
8363
8330
|
*/
|
|
8364
|
-
applyTreeDeltas(this.layoutCorrected, this.treeScale, this.path, isShared
|
|
8331
|
+
applyTreeDeltas(this.layoutCorrected, this.treeScale, this.path, isShared &&
|
|
8332
|
+
(lead.relativeTarget && !lead.relativeParent.resumingFrom
|
|
8333
|
+
? lead.relativeParent
|
|
8334
|
+
: true));
|
|
8365
8335
|
/**
|
|
8366
8336
|
* If this layer needs to perform scale correction but doesn't have a target,
|
|
8367
8337
|
* use the layout as the target.
|
|
@@ -8428,8 +8398,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8428
8398
|
scheduleRender(notifyAll = true) {
|
|
8429
8399
|
this.options.visualElement?.scheduleRender();
|
|
8430
8400
|
if (notifyAll) {
|
|
8431
|
-
|
|
8432
|
-
stack && stack.scheduleRender();
|
|
8401
|
+
this.getStack()?.scheduleRender();
|
|
8433
8402
|
}
|
|
8434
8403
|
if (this.resumingFrom && !this.resumingFrom.instance) {
|
|
8435
8404
|
this.resumingFrom = undefined;
|
|
@@ -8451,9 +8420,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8451
8420
|
}
|
|
8452
8421
|
this.attemptToResolveRelativeTarget = !hasOnlyRelativeTargetChanged;
|
|
8453
8422
|
const relativeLayout = createBox();
|
|
8454
|
-
const
|
|
8455
|
-
const layoutSource = this.layout ? this.layout.source : undefined;
|
|
8456
|
-
const isSharedLayoutAnimation = snapshotSource !== layoutSource;
|
|
8423
|
+
const isSharedLayoutAnimation = snapshot?.source !== this.layout?.source;
|
|
8457
8424
|
const stack = this.getStack();
|
|
8458
8425
|
const isOnlyMember = !stack || stack.members.length <= 1;
|
|
8459
8426
|
const shouldCrossfadeOpacity = Boolean(isSharedLayoutAnimation &&
|
|
@@ -8468,19 +8435,11 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8468
8435
|
this.mixTargetDelta = (latest) => {
|
|
8469
8436
|
const progress = latest / 1000;
|
|
8470
8437
|
const point = interpolate?.(progress);
|
|
8438
|
+
mixAxisDeltaLinear(targetDelta.x, delta.x, progress);
|
|
8439
|
+
mixAxisDeltaLinear(targetDelta.y, delta.y, progress);
|
|
8471
8440
|
if (point) {
|
|
8472
8441
|
targetDelta.x.translate = point.x;
|
|
8473
|
-
targetDelta.x.scale = mixNumber$1(delta.x.scale, 1, progress);
|
|
8474
|
-
targetDelta.x.origin = delta.x.origin;
|
|
8475
|
-
targetDelta.x.originPoint = delta.x.originPoint;
|
|
8476
8442
|
targetDelta.y.translate = point.y;
|
|
8477
|
-
targetDelta.y.scale = mixNumber$1(delta.y.scale, 1, progress);
|
|
8478
|
-
targetDelta.y.origin = delta.y.origin;
|
|
8479
|
-
targetDelta.y.originPoint = delta.y.originPoint;
|
|
8480
|
-
}
|
|
8481
|
-
else {
|
|
8482
|
-
mixAxisDeltaLinear(targetDelta.x, delta.x, progress);
|
|
8483
|
-
mixAxisDeltaLinear(targetDelta.y, delta.y, progress);
|
|
8484
8443
|
}
|
|
8485
8444
|
this.setTargetDelta(targetDelta);
|
|
8486
8445
|
if (this.relativeTarget &&
|
|
@@ -8506,7 +8465,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8506
8465
|
this.animationValues = mixedValues;
|
|
8507
8466
|
mixValues(mixedValues, snapshotLatestValues, this.latestValues, progress, shouldCrossfadeOpacity, isOnlyMember);
|
|
8508
8467
|
}
|
|
8509
|
-
if (point
|
|
8468
|
+
if (point?.rotate !== undefined) {
|
|
8510
8469
|
// Dedicated `pathRotation` channel, not `rotate`, so an
|
|
8511
8470
|
// animating `rotate` is composed with, never clobbered.
|
|
8512
8471
|
if (!this.animationValues)
|
|
@@ -8571,7 +8530,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8571
8530
|
}
|
|
8572
8531
|
finishAnimation() {
|
|
8573
8532
|
if (this.currentAnimation) {
|
|
8574
|
-
this.mixTargetDelta
|
|
8533
|
+
this.mixTargetDelta?.(animationTarget);
|
|
8575
8534
|
this.currentAnimation.stop();
|
|
8576
8535
|
}
|
|
8577
8536
|
this.completeAnimation();
|
|
@@ -8591,13 +8550,11 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8591
8550
|
this.layout &&
|
|
8592
8551
|
layout &&
|
|
8593
8552
|
shouldAnimatePositionOnly(this.options.animationType, this.layout.layoutBox, layout.layoutBox)) {
|
|
8553
|
+
const { layoutBox } = this.layout;
|
|
8554
|
+
const leadTarget = target;
|
|
8594
8555
|
target = this.target || createBox();
|
|
8595
|
-
|
|
8596
|
-
target.
|
|
8597
|
-
target.x.max = target.x.min + xLength;
|
|
8598
|
-
const yLength = calcLength(this.layout.layoutBox.y);
|
|
8599
|
-
target.y.min = lead.target.y.min;
|
|
8600
|
-
target.y.max = target.y.min + yLength;
|
|
8556
|
+
alignAxis(target.x, leadTarget.x, layoutBox.x);
|
|
8557
|
+
alignAxis(target.y, leadTarget.y, layoutBox.y);
|
|
8601
8558
|
}
|
|
8602
8559
|
copyBoxInto(targetWithTransforms, target);
|
|
8603
8560
|
/**
|
|
@@ -8622,8 +8579,8 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8622
8579
|
stack.add(node);
|
|
8623
8580
|
const config = node.options.initialPromotionConfig;
|
|
8624
8581
|
node.promote({
|
|
8625
|
-
transition: config
|
|
8626
|
-
preserveFollowOpacity: config
|
|
8582
|
+
transition: config?.transition,
|
|
8583
|
+
preserveFollowOpacity: config?.shouldPreserveFollowOpacity
|
|
8627
8584
|
? config.shouldPreserveFollowOpacity(node)
|
|
8628
8585
|
: undefined,
|
|
8629
8586
|
});
|
|
@@ -8646,9 +8603,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8646
8603
|
return this.root.sharedNodes.get(layoutId);
|
|
8647
8604
|
}
|
|
8648
8605
|
promote({ needsReset, transition, preserveFollowOpacity, } = {}) {
|
|
8649
|
-
|
|
8650
|
-
if (stack)
|
|
8651
|
-
stack.promote(this, preserveFollowOpacity);
|
|
8606
|
+
this.getStack()?.promote(this, preserveFollowOpacity);
|
|
8652
8607
|
if (needsReset) {
|
|
8653
8608
|
this.projectionDelta = undefined;
|
|
8654
8609
|
this.needsReset = true;
|
|
@@ -8657,45 +8612,27 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8657
8612
|
this.setOptions({ transition });
|
|
8658
8613
|
}
|
|
8659
8614
|
relegate() {
|
|
8660
|
-
|
|
8661
|
-
if (stack) {
|
|
8662
|
-
return stack.relegate(this);
|
|
8663
|
-
}
|
|
8664
|
-
else {
|
|
8665
|
-
return false;
|
|
8666
|
-
}
|
|
8615
|
+
return this.getStack()?.relegate(this) || false;
|
|
8667
8616
|
}
|
|
8668
8617
|
resetSkewAndRotation() {
|
|
8669
8618
|
const { visualElement } = this.options;
|
|
8670
8619
|
if (!visualElement)
|
|
8671
8620
|
return;
|
|
8672
|
-
// If there's no detected skew or rotation values, we can early return without a forced render.
|
|
8673
|
-
let hasDistortingTransform = false;
|
|
8674
8621
|
/**
|
|
8675
8622
|
* An unrolled check for rotation values. Most elements don't have any rotation and
|
|
8676
|
-
* skipping the
|
|
8623
|
+
* skipping the loop and new object creation is 50% faster.
|
|
8624
|
+
* If there's no distorting values, we don't need to do any more.
|
|
8677
8625
|
*/
|
|
8678
8626
|
const { latestValues } = visualElement;
|
|
8679
|
-
if (latestValues
|
|
8680
|
-
latestValues.rotate ||
|
|
8681
|
-
latestValues.rotateX ||
|
|
8682
|
-
latestValues.rotateY ||
|
|
8683
|
-
latestValues.rotateZ ||
|
|
8684
|
-
latestValues.skewX ||
|
|
8685
|
-
latestValues.skewY) {
|
|
8686
|
-
hasDistortingTransform = true;
|
|
8687
|
-
}
|
|
8688
|
-
// If there's no distorting values, we don't need to do any more.
|
|
8689
|
-
if (!hasDistortingTransform)
|
|
8627
|
+
if (!hasDistortingTransform(latestValues))
|
|
8690
8628
|
return;
|
|
8691
8629
|
const resetValues = {};
|
|
8692
|
-
if (latestValues.z) {
|
|
8693
|
-
resetDistortingTransform("z", visualElement, resetValues, this.animationValues);
|
|
8694
|
-
}
|
|
8695
8630
|
// Check the skew and rotate value of all axes and reset to 0
|
|
8696
|
-
for (let i = 0; i <
|
|
8697
|
-
resetDistortingTransform(
|
|
8698
|
-
|
|
8631
|
+
for (let i = 0; i < distortingTransforms.length; i++) {
|
|
8632
|
+
resetDistortingTransform(distortingTransforms[i], visualElement, resetValues, this.animationValues);
|
|
8633
|
+
}
|
|
8634
|
+
for (let i = 0; i < angleTransforms.length; i++) {
|
|
8635
|
+
resetDistortingTransform(angleTransforms[i], visualElement, resetValues, this.animationValues);
|
|
8699
8636
|
}
|
|
8700
8637
|
// Force a render of this element to apply the transform with all skews and rotations
|
|
8701
8638
|
// set to 0.
|
|
@@ -8715,7 +8652,13 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8715
8652
|
styleProp) {
|
|
8716
8653
|
if (!this.instance || this.isSVG)
|
|
8717
8654
|
return;
|
|
8718
|
-
|
|
8655
|
+
const lead = this.getLead();
|
|
8656
|
+
/**
|
|
8657
|
+
* Without crossfade, a new lead hides the previous one, as it's
|
|
8658
|
+
* usually unmounting. One that gave its layoutId away keeps
|
|
8659
|
+
* rendering, so only hide nodes that follow another.
|
|
8660
|
+
*/
|
|
8661
|
+
if (!this.isVisible && lead !== this) {
|
|
8719
8662
|
targetStyle.visibility = "hidden";
|
|
8720
8663
|
return;
|
|
8721
8664
|
}
|
|
@@ -8731,9 +8674,10 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8731
8674
|
: "none";
|
|
8732
8675
|
return;
|
|
8733
8676
|
}
|
|
8734
|
-
const lead = this.getLead();
|
|
8735
8677
|
if (!this.projectionDelta || !this.layout || !lead.target) {
|
|
8736
|
-
if (this.options.layoutId) {
|
|
8678
|
+
if (this.options.layoutId || this.needsShow) {
|
|
8679
|
+
this.needsShow = false;
|
|
8680
|
+
targetStyle.visibility = "";
|
|
8737
8681
|
targetStyle.opacity =
|
|
8738
8682
|
this.latestValues.opacity !== undefined
|
|
8739
8683
|
? this.latestValues.opacity
|
|
@@ -8867,52 +8811,49 @@ function notifyLayoutUpdate(node) {
|
|
|
8867
8811
|
const isShared = snapshot.source !== node.layout.source;
|
|
8868
8812
|
// TODO Maybe we want to also resize the layout snapshot so we don't trigger
|
|
8869
8813
|
// animations for instance if layout="size" and an element has only changed position
|
|
8870
|
-
|
|
8871
|
-
|
|
8872
|
-
|
|
8873
|
-
|
|
8874
|
-
|
|
8875
|
-
|
|
8876
|
-
|
|
8877
|
-
|
|
8878
|
-
|
|
8879
|
-
|
|
8880
|
-
|
|
8881
|
-
|
|
8882
|
-
|
|
8883
|
-
|
|
8884
|
-
|
|
8885
|
-
|
|
8886
|
-
|
|
8887
|
-
|
|
8888
|
-
|
|
8889
|
-
|
|
8890
|
-
|
|
8891
|
-
|
|
8892
|
-
|
|
8893
|
-
|
|
8894
|
-
|
|
8895
|
-
|
|
8896
|
-
|
|
8897
|
-
|
|
8898
|
-
|
|
8899
|
-
node.relativeTarget[axis].min + length;
|
|
8900
|
-
}
|
|
8901
|
-
});
|
|
8902
|
-
}
|
|
8814
|
+
const resizeSnapshot = (box, to) => {
|
|
8815
|
+
if (animationType === "size") {
|
|
8816
|
+
eachAxis((axis) => {
|
|
8817
|
+
const length = calcLength(box[axis]);
|
|
8818
|
+
box[axis].min = to[axis].min;
|
|
8819
|
+
box[axis].max = box[axis].min + length;
|
|
8820
|
+
});
|
|
8821
|
+
}
|
|
8822
|
+
else if (animationType === "x" || animationType === "y") {
|
|
8823
|
+
const snapAxis = animationType === "x" ? "y" : "x";
|
|
8824
|
+
copyAxisInto(box[snapAxis], to[snapAxis]);
|
|
8825
|
+
}
|
|
8826
|
+
else if (shouldAnimatePositionOnly(animationType, snapshot.layoutBox, layout)) {
|
|
8827
|
+
eachAxis((axis) => {
|
|
8828
|
+
const length = calcLength(to[axis]);
|
|
8829
|
+
box[axis].max = box[axis].min + length;
|
|
8830
|
+
/**
|
|
8831
|
+
* Ensure relative target gets resized and rerendererd
|
|
8832
|
+
*/
|
|
8833
|
+
if (node.relativeTarget && !node.currentAnimation) {
|
|
8834
|
+
node.isProjectionDirty = true;
|
|
8835
|
+
node.relativeTarget[axis].max =
|
|
8836
|
+
node.relativeTarget[axis].min + length;
|
|
8837
|
+
}
|
|
8838
|
+
});
|
|
8839
|
+
}
|
|
8840
|
+
};
|
|
8841
|
+
const snapshotBox = isShared ? snapshot.measuredBox : snapshot.layoutBox;
|
|
8842
|
+
resizeSnapshot(snapshotBox, layout);
|
|
8903
8843
|
const layoutDelta = createDelta();
|
|
8904
8844
|
calcBoxDelta(layoutDelta, layout, snapshot.layoutBox);
|
|
8905
8845
|
const visualDelta = createDelta();
|
|
8906
|
-
|
|
8907
|
-
calcBoxDelta(visualDelta, node.applyTransform(measuredLayout, true), snapshot.measuredBox);
|
|
8908
|
-
}
|
|
8909
|
-
else {
|
|
8910
|
-
calcBoxDelta(visualDelta, layout, snapshot.layoutBox);
|
|
8911
|
-
}
|
|
8846
|
+
calcBoxDelta(visualDelta, isShared ? node.applyTransform(measuredLayout, true) : layout, snapshotBox);
|
|
8912
8847
|
const hasLayoutChanged = !isDeltaZero(layoutDelta);
|
|
8913
8848
|
let hasRelativeLayoutChanged = false;
|
|
8914
|
-
|
|
8915
|
-
|
|
8849
|
+
const relativeParent = node.getClosestProjectingParent();
|
|
8850
|
+
/**
|
|
8851
|
+
* A snapshot resumed from another element is only relative to this
|
|
8852
|
+
* node's relativeParent if it's a layoutRoot that contains both.
|
|
8853
|
+
*/
|
|
8854
|
+
if (!node.resumeFrom ||
|
|
8855
|
+
(relativeParent?.options.layoutRoot &&
|
|
8856
|
+
node.resumeFrom.path.includes(relativeParent))) {
|
|
8916
8857
|
/**
|
|
8917
8858
|
* If the relativeParent is itself resuming from a different element then
|
|
8918
8859
|
* the relative snapshot is not relavent
|
|
@@ -8921,10 +8862,22 @@ function notifyLayoutUpdate(node) {
|
|
|
8921
8862
|
const { snapshot: parentSnapshot, layout: parentLayout } = relativeParent;
|
|
8922
8863
|
if (parentSnapshot && parentLayout) {
|
|
8923
8864
|
const anchor = node.options.layoutAnchor || undefined;
|
|
8865
|
+
/**
|
|
8866
|
+
* A shared snapshot includes the transforms of the old
|
|
8867
|
+
* element's ancestors below the layoutRoot, as they
|
|
8868
|
+
* aren't shared with the new element.
|
|
8869
|
+
*/
|
|
8924
8870
|
const relativeSnapshot = createBox();
|
|
8925
|
-
calcRelativePosition(relativeSnapshot,
|
|
8871
|
+
calcRelativePosition(relativeSnapshot, isShared
|
|
8872
|
+
? node.resumeFrom.applyTransform(snapshot.layoutBox, true, undefined, true, relativeParent.depth + 1)
|
|
8873
|
+
: snapshot.layoutBox, parentSnapshot.layoutBox, anchor);
|
|
8926
8874
|
const relativeLayout = createBox();
|
|
8927
8875
|
calcRelativePosition(relativeLayout, layout, parentLayout.layoutBox, anchor);
|
|
8876
|
+
/**
|
|
8877
|
+
* A shared snapshot is resized in page space, above, so
|
|
8878
|
+
* resize it relative to the layoutRoot too.
|
|
8879
|
+
*/
|
|
8880
|
+
isShared && resizeSnapshot(relativeSnapshot, relativeLayout);
|
|
8928
8881
|
if (!boxEqualsRounded(relativeSnapshot, relativeLayout)) {
|
|
8929
8882
|
hasRelativeLayoutChanged = true;
|
|
8930
8883
|
}
|
|
@@ -8946,8 +8899,7 @@ function notifyLayoutUpdate(node) {
|
|
|
8946
8899
|
});
|
|
8947
8900
|
}
|
|
8948
8901
|
else if (node.isLead()) {
|
|
8949
|
-
|
|
8950
|
-
onExitComplete && onExitComplete();
|
|
8902
|
+
node.options.onExitComplete?.();
|
|
8951
8903
|
}
|
|
8952
8904
|
/**
|
|
8953
8905
|
* Clearing transition
|
|
@@ -9053,7 +9005,7 @@ function syncRelativeLayout(node) {
|
|
|
9053
9005
|
}
|
|
9054
9006
|
function resetTransformStyle(node) {
|
|
9055
9007
|
const { visualElement } = node.options;
|
|
9056
|
-
if (visualElement
|
|
9008
|
+
if (visualElement?.getProps().onBeforeLayoutMeasure) {
|
|
9057
9009
|
visualElement.notify("BeforeLayoutMeasure");
|
|
9058
9010
|
}
|
|
9059
9011
|
node.resetTransform();
|
|
@@ -9087,7 +9039,7 @@ function mixBox(output, from, to, p) {
|
|
|
9087
9039
|
mixAxis(output.y, from.y, to.y, p);
|
|
9088
9040
|
}
|
|
9089
9041
|
function hasOpacityCrossfade(node) {
|
|
9090
|
-
return
|
|
9042
|
+
return node.animationValues?.opacityExit !== undefined;
|
|
9091
9043
|
}
|
|
9092
9044
|
const defaultLayoutTransition = {
|
|
9093
9045
|
duration: 0.45,
|
|
@@ -9113,6 +9065,13 @@ function roundBox(box) {
|
|
|
9113
9065
|
roundAxis(box.x);
|
|
9114
9066
|
roundAxis(box.y);
|
|
9115
9067
|
}
|
|
9068
|
+
/**
|
|
9069
|
+
* Align an axis to the start of another, keeping the length of a layout axis.
|
|
9070
|
+
* The length is read first, as output can be the layout axis itself.
|
|
9071
|
+
*/
|
|
9072
|
+
function alignAxis(output, from, layout) {
|
|
9073
|
+
output.max = calcLength(layout) + (output.min = from.min);
|
|
9074
|
+
}
|
|
9116
9075
|
function shouldAnimatePositionOnly(animationType, snapshot, layout) {
|
|
9117
9076
|
return (animationType === "position" ||
|
|
9118
9077
|
(animationType === "preserve-aspect" &&
|
|
@@ -9163,7 +9122,7 @@ const HTMLProjectionNode =
|
|
|
9163
9122
|
resetTransform: (instance, value) => {
|
|
9164
9123
|
instance.style.transform = value !== undefined ? value : "none";
|
|
9165
9124
|
},
|
|
9166
|
-
checkIsScrollRoot: (instance) =>
|
|
9125
|
+
checkIsScrollRoot: (instance) => window.getComputedStyle(instance).position === "fixed",
|
|
9167
9126
|
});
|
|
9168
9127
|
|
|
9169
9128
|
const visualElementStore = new WeakMap();
|
|
@@ -9449,9 +9408,7 @@ class VisualElement {
|
|
|
9449
9408
|
}
|
|
9450
9409
|
this.current = instance;
|
|
9451
9410
|
visualElementStore.set(instance, this);
|
|
9452
|
-
|
|
9453
|
-
this.projection.mount(instance);
|
|
9454
|
-
}
|
|
9411
|
+
this.projection?.instance || this.projection?.mount(instance);
|
|
9455
9412
|
/**
|
|
9456
9413
|
* Join the closest variant node above, so its variant changes
|
|
9457
9414
|
* propagate here, unless inherit={false} cuts the chain.
|
|
@@ -9497,12 +9454,12 @@ class VisualElement {
|
|
|
9497
9454
|
this.hasBeenMounted = true;
|
|
9498
9455
|
}
|
|
9499
9456
|
unmount() {
|
|
9500
|
-
this.projection
|
|
9457
|
+
this.projection?.unmount();
|
|
9501
9458
|
cancelFrame(this.notifyUpdate);
|
|
9502
9459
|
cancelFrame(this.render);
|
|
9503
9460
|
this.valueSubscriptions.forEach((remove) => remove());
|
|
9504
9461
|
this.valueSubscriptions.clear();
|
|
9505
|
-
this.removeFromVariantTree
|
|
9462
|
+
this.removeFromVariantTree?.();
|
|
9506
9463
|
this.parent?.removeChild(this);
|
|
9507
9464
|
for (const key in this.events) {
|
|
9508
9465
|
this.events[key].clear();
|
|
@@ -9518,17 +9475,14 @@ class VisualElement {
|
|
|
9518
9475
|
}
|
|
9519
9476
|
addChild(child) {
|
|
9520
9477
|
this.children.add(child);
|
|
9521
|
-
this.enteringChildren
|
|
9522
|
-
this.enteringChildren.add(child);
|
|
9478
|
+
(this.enteringChildren || (this.enteringChildren = new Set())).add(child);
|
|
9523
9479
|
}
|
|
9524
9480
|
removeChild(child) {
|
|
9525
9481
|
this.children.delete(child);
|
|
9526
|
-
this.enteringChildren
|
|
9482
|
+
this.enteringChildren?.delete(child);
|
|
9527
9483
|
}
|
|
9528
9484
|
bindToMotionValue(key, value) {
|
|
9529
|
-
|
|
9530
|
-
this.valueSubscriptions.get(key)();
|
|
9531
|
-
}
|
|
9485
|
+
this.valueSubscriptions.get(key)?.();
|
|
9532
9486
|
if (value.accelerate &&
|
|
9533
9487
|
acceleratedValues.has(key) &&
|
|
9534
9488
|
this.current instanceof HTMLElement) {
|
|
@@ -9570,8 +9524,7 @@ class VisualElement {
|
|
|
9570
9524
|
}
|
|
9571
9525
|
this.valueSubscriptions.set(key, () => {
|
|
9572
9526
|
removeOnChange();
|
|
9573
|
-
|
|
9574
|
-
removeSyncCheck();
|
|
9527
|
+
removeSyncCheck?.();
|
|
9575
9528
|
// Defer to MotionValue.on("change") auto-stop so React 19 remounts
|
|
9576
9529
|
// can resubscribe before the animation is cancelled (#3315).
|
|
9577
9530
|
});
|
|
@@ -9664,10 +9617,8 @@ class VisualElement {
|
|
|
9664
9617
|
*/
|
|
9665
9618
|
for (let i = 0; i < propEventHandlers.length; i++) {
|
|
9666
9619
|
const key = propEventHandlers[i];
|
|
9667
|
-
|
|
9668
|
-
|
|
9669
|
-
delete this.propEventSubscriptions[key];
|
|
9670
|
-
}
|
|
9620
|
+
this.propEventSubscriptions[key]?.();
|
|
9621
|
+
delete this.propEventSubscriptions[key];
|
|
9671
9622
|
const listenerName = ("on" + key);
|
|
9672
9623
|
const listener = props[listenerName];
|
|
9673
9624
|
if (listener) {
|
|
@@ -9675,9 +9626,7 @@ class VisualElement {
|
|
|
9675
9626
|
}
|
|
9676
9627
|
}
|
|
9677
9628
|
this.prevMotionValues = updateMotionValuesFromProps(this, this.scrapeMotionValuesFromProps(props, this.prevProps || {}, this), this.prevMotionValues);
|
|
9678
|
-
|
|
9679
|
-
this.handleChildMotionValue();
|
|
9680
|
-
}
|
|
9629
|
+
this.handleChildMotionValue?.();
|
|
9681
9630
|
}
|
|
9682
9631
|
getProps() {
|
|
9683
9632
|
return this.props;
|
|
@@ -9686,7 +9635,7 @@ class VisualElement {
|
|
|
9686
9635
|
* Returns the variant definition with a given name.
|
|
9687
9636
|
*/
|
|
9688
9637
|
getVariant(name) {
|
|
9689
|
-
return this.props.variants
|
|
9638
|
+
return this.props.variants?.[name];
|
|
9690
9639
|
}
|
|
9691
9640
|
/**
|
|
9692
9641
|
* Returns the defined default transition on this component.
|
|
@@ -9724,11 +9673,8 @@ class VisualElement {
|
|
|
9724
9673
|
*/
|
|
9725
9674
|
removeValue(key) {
|
|
9726
9675
|
this.values.delete(key);
|
|
9727
|
-
|
|
9728
|
-
|
|
9729
|
-
unsubscribe();
|
|
9730
|
-
this.valueSubscriptions.delete(key);
|
|
9731
|
-
}
|
|
9676
|
+
this.valueSubscriptions.get(key)?.();
|
|
9677
|
+
this.valueSubscriptions.delete(key);
|
|
9732
9678
|
delete this.latestValues[key];
|
|
9733
9679
|
this.removeValueFromRenderState(key, this.renderState);
|
|
9734
9680
|
}
|
|
@@ -9739,10 +9685,10 @@ class VisualElement {
|
|
|
9739
9685
|
return this.values.has(key);
|
|
9740
9686
|
}
|
|
9741
9687
|
getValue(key, defaultValue) {
|
|
9742
|
-
|
|
9743
|
-
|
|
9744
|
-
|
|
9745
|
-
|
|
9688
|
+
let value = this.props.values?.[key];
|
|
9689
|
+
if (value)
|
|
9690
|
+
return value;
|
|
9691
|
+
value = this.values.get(key);
|
|
9746
9692
|
if (value === undefined && defaultValue !== undefined) {
|
|
9747
9693
|
value = motionValue(defaultValue ?? this.getDefaultValue?.(key), {
|
|
9748
9694
|
owner: this,
|
|
@@ -9792,15 +9738,11 @@ class VisualElement {
|
|
|
9792
9738
|
this.baseTarget[key] = value;
|
|
9793
9739
|
}
|
|
9794
9740
|
on(eventName, callback) {
|
|
9795
|
-
|
|
9796
|
-
this.events[eventName] = new motionUtils.SubscriptionManager();
|
|
9797
|
-
}
|
|
9798
|
-
return this.events[eventName].add(callback);
|
|
9741
|
+
return (this.events[eventName] ||
|
|
9742
|
+
(this.events[eventName] = new motionUtils.SubscriptionManager())).add(callback);
|
|
9799
9743
|
}
|
|
9800
9744
|
notify(eventName, ...args) {
|
|
9801
|
-
|
|
9802
|
-
this.events[eventName].notify(...args);
|
|
9803
|
-
}
|
|
9745
|
+
this.events[eventName]?.notify(...args);
|
|
9804
9746
|
}
|
|
9805
9747
|
scheduleRenderMicrotask() {
|
|
9806
9748
|
microtask.render(this.render);
|
|
@@ -9892,7 +9834,8 @@ class HTMLVisualElement extends DOMVisualElement {
|
|
|
9892
9834
|
* HTML/SVG element (a class instance, an imperative handle) there's
|
|
9893
9835
|
* nothing for Motion to style, measure or attach gestures to. #2777
|
|
9894
9836
|
*/
|
|
9895
|
-
|
|
9837
|
+
process.env.NODE_ENV !== "production" &&
|
|
9838
|
+
motionUtils.invariant(Boolean(instance.style), "motion.create() components must forward their ref to a HTML or SVG element", "custom-component-ref");
|
|
9896
9839
|
super.mount(instance);
|
|
9897
9840
|
}
|
|
9898
9841
|
readValueFromInstance(instance, key) {
|
|
@@ -9966,7 +9909,7 @@ function getProjectionParent(element) {
|
|
|
9966
9909
|
let ancestor = element.parentElement;
|
|
9967
9910
|
while (ancestor) {
|
|
9968
9911
|
const node = layoutNodes.get(ancestor);
|
|
9969
|
-
if (node
|
|
9912
|
+
if (node?.instance)
|
|
9970
9913
|
return node;
|
|
9971
9914
|
ancestor = ancestor.parentElement;
|
|
9972
9915
|
}
|
|
@@ -10232,7 +10175,7 @@ class LayoutAnimationBuilder {
|
|
|
10232
10175
|
hasSurvivor &&
|
|
10233
10176
|
!newMemberIds.has(layoutId)) {
|
|
10234
10177
|
if (restore && restore.parent.isConnected) {
|
|
10235
|
-
restore.parent.insertBefore(element, restore.next
|
|
10178
|
+
restore.parent.insertBefore(element, restore.next?.parentNode === restore.parent
|
|
10236
10179
|
? restore.next
|
|
10237
10180
|
: null);
|
|
10238
10181
|
node.isPresent = false;
|
|
@@ -10437,10 +10380,6 @@ class PanSession {
|
|
|
10437
10380
|
* Scroll positions of scrollable ancestors and window.
|
|
10438
10381
|
*/
|
|
10439
10382
|
this.scrollPositions = new Map();
|
|
10440
|
-
/**
|
|
10441
|
-
* Cleanup function for scroll listeners.
|
|
10442
|
-
*/
|
|
10443
|
-
this.removeScrollListeners = null;
|
|
10444
10383
|
this.onElementScroll = (event) => {
|
|
10445
10384
|
this.handleScroll(event.target);
|
|
10446
10385
|
};
|
|
@@ -10468,10 +10407,10 @@ class PanSession {
|
|
|
10468
10407
|
this.history.push({ ...point, timestamp: time.now() });
|
|
10469
10408
|
const { onStart, onMove } = this.handlers;
|
|
10470
10409
|
if (!isPanStarted) {
|
|
10471
|
-
onStart
|
|
10410
|
+
onStart?.(this.lastMoveEvent, info);
|
|
10472
10411
|
this.startEvent = this.lastMoveEvent;
|
|
10473
10412
|
}
|
|
10474
|
-
onMove
|
|
10413
|
+
onMove?.(this.lastMoveEvent, info);
|
|
10475
10414
|
};
|
|
10476
10415
|
this.handlePointerMove = (event, info) => {
|
|
10477
10416
|
/**
|
|
@@ -10496,17 +10435,15 @@ class PanSession {
|
|
|
10496
10435
|
// Resume animation if dragSnapToOrigin is set OR if no drag started (user just clicked)
|
|
10497
10436
|
// This ensures constraint animations continue when interrupted by a click
|
|
10498
10437
|
if (this.dragSnapToOrigin || !this.startEvent) {
|
|
10499
|
-
resumeAnimation
|
|
10438
|
+
resumeAnimation?.();
|
|
10500
10439
|
}
|
|
10501
10440
|
if (!(this.lastMoveEvent && this.lastMoveEventInfo))
|
|
10502
10441
|
return;
|
|
10503
10442
|
const panInfo = getPanInfo(event.type === "pointercancel"
|
|
10504
10443
|
? this.lastMoveEventInfo
|
|
10505
10444
|
: transformPoint(info, this.transformPagePoint), this.history);
|
|
10506
|
-
|
|
10507
|
-
|
|
10508
|
-
}
|
|
10509
|
-
onSessionEnd && onSessionEnd(event, panInfo);
|
|
10445
|
+
this.startEvent && onEnd?.(event, panInfo);
|
|
10446
|
+
onSessionEnd?.(event, panInfo);
|
|
10510
10447
|
};
|
|
10511
10448
|
// If we have more than one touch, don't start detecting this gesture
|
|
10512
10449
|
if (!isPrimaryPointer(event))
|
|
@@ -10519,8 +10456,13 @@ class PanSession {
|
|
|
10519
10456
|
const info = extractEventInfo(event);
|
|
10520
10457
|
const initialInfo = transformPoint(info, this.transformPagePoint);
|
|
10521
10458
|
const { point } = initialInfo;
|
|
10522
|
-
|
|
10523
|
-
|
|
10459
|
+
/**
|
|
10460
|
+
* Stamp the origin with time.now(), not frameData.timestamp: when
|
|
10461
|
+
* the frameloop is idle, frameData.timestamp is from the last frame
|
|
10462
|
+
* that ran, which can be seconds old, and a fast flick from a
|
|
10463
|
+
* standstill would then report near-zero velocity. See #1747.
|
|
10464
|
+
*/
|
|
10465
|
+
this.history = [{ ...point, timestamp: time.now() }];
|
|
10524
10466
|
const { onSessionStart } = handlers;
|
|
10525
10467
|
onSessionStart &&
|
|
10526
10468
|
onSessionStart(event, getPanInfo(initialInfo, this.history));
|
|
@@ -10544,30 +10486,19 @@ class PanSession {
|
|
|
10544
10486
|
const style = getComputedStyle(current);
|
|
10545
10487
|
if (overflowStyles.has(style.overflowX) ||
|
|
10546
10488
|
overflowStyles.has(style.overflowY)) {
|
|
10547
|
-
this.scrollPositions.set(current,
|
|
10548
|
-
x: current.scrollLeft,
|
|
10549
|
-
y: current.scrollTop,
|
|
10550
|
-
});
|
|
10489
|
+
this.scrollPositions.set(current, getScroll(current));
|
|
10551
10490
|
}
|
|
10552
10491
|
current = current.parentElement;
|
|
10553
10492
|
}
|
|
10554
10493
|
// Track window scroll
|
|
10555
|
-
this.scrollPositions.set(window,
|
|
10556
|
-
|
|
10557
|
-
y: window.scrollY,
|
|
10558
|
-
});
|
|
10494
|
+
this.scrollPositions.set(window, getScroll(window));
|
|
10495
|
+
this.removeScrollListeners = motionUtils.pipe(
|
|
10559
10496
|
// Capture listener catches element scroll events as they bubble
|
|
10560
|
-
window
|
|
10497
|
+
addDomEvent(window, "scroll", this.onElementScroll, {
|
|
10561
10498
|
capture: true,
|
|
10562
|
-
})
|
|
10499
|
+
}),
|
|
10563
10500
|
// Direct window scroll listener (window scroll doesn't bubble)
|
|
10564
|
-
window
|
|
10565
|
-
this.removeScrollListeners = () => {
|
|
10566
|
-
window.removeEventListener("scroll", this.onElementScroll, {
|
|
10567
|
-
capture: true,
|
|
10568
|
-
});
|
|
10569
|
-
window.removeEventListener("scroll", this.onWindowScroll);
|
|
10570
|
-
};
|
|
10501
|
+
addDomEvent(window, "scroll", this.onWindowScroll, {}));
|
|
10571
10502
|
}
|
|
10572
10503
|
/**
|
|
10573
10504
|
* Handle scroll compensation during drag.
|
|
@@ -10580,12 +10511,7 @@ class PanSession {
|
|
|
10580
10511
|
if (!initial)
|
|
10581
10512
|
return;
|
|
10582
10513
|
const isWindow = target === window;
|
|
10583
|
-
const current =
|
|
10584
|
-
? { x: window.scrollX, y: window.scrollY }
|
|
10585
|
-
: {
|
|
10586
|
-
x: target.scrollLeft,
|
|
10587
|
-
y: target.scrollTop,
|
|
10588
|
-
};
|
|
10514
|
+
const current = getScroll(target);
|
|
10589
10515
|
const delta = { x: current.x - initial.x, y: current.y - initial.y };
|
|
10590
10516
|
if (delta.x === 0 && delta.y === 0)
|
|
10591
10517
|
return;
|
|
@@ -10610,12 +10536,18 @@ class PanSession {
|
|
|
10610
10536
|
this.handlers = handlers;
|
|
10611
10537
|
}
|
|
10612
10538
|
end() {
|
|
10613
|
-
this.removeListeners
|
|
10614
|
-
this.removeScrollListeners
|
|
10539
|
+
this.removeListeners?.();
|
|
10540
|
+
this.removeScrollListeners?.();
|
|
10615
10541
|
this.scrollPositions.clear();
|
|
10616
10542
|
cancelFrame(this.updatePoint);
|
|
10617
10543
|
}
|
|
10618
10544
|
}
|
|
10545
|
+
const getScroll = (target) => target === window
|
|
10546
|
+
? { x: window.scrollX, y: window.scrollY }
|
|
10547
|
+
: {
|
|
10548
|
+
x: target.scrollLeft,
|
|
10549
|
+
y: target.scrollTop,
|
|
10550
|
+
};
|
|
10619
10551
|
function transformPoint(info, transformPagePoint) {
|
|
10620
10552
|
return transformPagePoint ? { point: transformPagePoint(info.point) } : info;
|
|
10621
10553
|
}
|
|
@@ -10872,6 +10804,25 @@ function resolvePointElastic(dragElastic, label) {
|
|
|
10872
10804
|
: dragElastic[label] || 0;
|
|
10873
10805
|
}
|
|
10874
10806
|
|
|
10807
|
+
/**
|
|
10808
|
+
* Re-read the scroll of the projection's ancestors, and return that of the
|
|
10809
|
+
* `layoutScroll` ones as a key that changes when any of them scroll.
|
|
10810
|
+
*
|
|
10811
|
+
* Clear the cached scroll first so `updateScroll` bypasses its
|
|
10812
|
+
* per-animationId cache and re-reads the live value.
|
|
10813
|
+
*/
|
|
10814
|
+
function measureScroll(projection) {
|
|
10815
|
+
let key = "";
|
|
10816
|
+
for (const node of projection.path) {
|
|
10817
|
+
node.scroll = undefined;
|
|
10818
|
+
node.updateScroll();
|
|
10819
|
+
const { scroll } = node;
|
|
10820
|
+
if (node !== projection.root && scroll) {
|
|
10821
|
+
key += scroll.offset.x + "," + scroll.offset.y + ",";
|
|
10822
|
+
}
|
|
10823
|
+
}
|
|
10824
|
+
return key;
|
|
10825
|
+
}
|
|
10875
10826
|
const elementDragControls = new WeakMap();
|
|
10876
10827
|
class VisualElementDragControls {
|
|
10877
10828
|
constructor(visualElement, readProps = () => visualElement.getProps()) {
|
|
@@ -10903,8 +10854,7 @@ class VisualElementDragControls {
|
|
|
10903
10854
|
/**
|
|
10904
10855
|
* Don't start dragging if this component is exiting
|
|
10905
10856
|
*/
|
|
10906
|
-
|
|
10907
|
-
if (presenceContext && presenceContext.isPresent === false)
|
|
10857
|
+
if (this.visualElement.presenceContext?.isPresent === false)
|
|
10908
10858
|
return;
|
|
10909
10859
|
const onSessionStart = (event) => {
|
|
10910
10860
|
if (snapToCursor)
|
|
@@ -10915,8 +10865,7 @@ class VisualElementDragControls {
|
|
|
10915
10865
|
// Attempt to grab the global drag gesture lock - maybe make this part of PanSession
|
|
10916
10866
|
const { drag, dragPropagation, onDragStart } = this.getProps();
|
|
10917
10867
|
if (drag && !dragPropagation) {
|
|
10918
|
-
|
|
10919
|
-
this.openDragLock();
|
|
10868
|
+
this.openDragLock?.();
|
|
10920
10869
|
this.openDragLock = setDragLock(drag);
|
|
10921
10870
|
// If we don 't have the lock, don't start dragging
|
|
10922
10871
|
if (!this.openDragLock)
|
|
@@ -10927,9 +10876,10 @@ class VisualElementDragControls {
|
|
|
10927
10876
|
this.isDragging = true;
|
|
10928
10877
|
this.currentDirection = null;
|
|
10929
10878
|
this.resolveConstraints();
|
|
10930
|
-
|
|
10931
|
-
|
|
10932
|
-
|
|
10879
|
+
const { projection } = this.visualElement;
|
|
10880
|
+
if (projection) {
|
|
10881
|
+
projection.isAnimationBlocked = true;
|
|
10882
|
+
projection.target = undefined;
|
|
10933
10883
|
}
|
|
10934
10884
|
/**
|
|
10935
10885
|
* Record gesture origin and pointer offset
|
|
@@ -10951,13 +10901,11 @@ class VisualElementDragControls {
|
|
|
10951
10901
|
current = parseFloat(current);
|
|
10952
10902
|
}
|
|
10953
10903
|
else if (percent.test(current)) {
|
|
10954
|
-
const
|
|
10955
|
-
if (
|
|
10956
|
-
|
|
10957
|
-
|
|
10958
|
-
|
|
10959
|
-
current = length * (parseFloat(current) / 100);
|
|
10960
|
-
}
|
|
10904
|
+
const measuredAxis = projection?.layout?.layoutBox[axis];
|
|
10905
|
+
if (measuredAxis) {
|
|
10906
|
+
current =
|
|
10907
|
+
calcLength(measuredAxis) *
|
|
10908
|
+
(parseFloat(current) / 100);
|
|
10961
10909
|
}
|
|
10962
10910
|
}
|
|
10963
10911
|
this.originPoint[axis] = current;
|
|
@@ -10967,8 +10915,7 @@ class VisualElementDragControls {
|
|
|
10967
10915
|
frame.update(() => onDragStart(event, info), false, true);
|
|
10968
10916
|
}
|
|
10969
10917
|
addValueToWillChange(this.visualElement, "transform");
|
|
10970
|
-
|
|
10971
|
-
animationState && animationState.setActive("whileDrag", true);
|
|
10918
|
+
this.visualElement.animationState?.setActive("whileDrag", true);
|
|
10972
10919
|
};
|
|
10973
10920
|
const onMove = (event, info) => {
|
|
10974
10921
|
this.latestPointerEvent = event;
|
|
@@ -10991,8 +10938,8 @@ class VisualElementDragControls {
|
|
|
10991
10938
|
onDirectionLock && onDirectionLock(this.currentDirection);
|
|
10992
10939
|
}
|
|
10993
10940
|
// Update each point with the latest position
|
|
10994
|
-
this.updateAxis("x",
|
|
10995
|
-
this.updateAxis("y",
|
|
10941
|
+
this.updateAxis("x", offset);
|
|
10942
|
+
this.updateAxis("y", offset);
|
|
10996
10943
|
/**
|
|
10997
10944
|
* Ideally we would leave the renderer to fire naturally at the end of
|
|
10998
10945
|
* this frame but if the element is about to change layout as the result
|
|
@@ -11061,12 +11008,11 @@ class VisualElementDragControls {
|
|
|
11061
11008
|
projection.isAnimationBlocked = false;
|
|
11062
11009
|
}
|
|
11063
11010
|
this.endPanSession();
|
|
11064
|
-
|
|
11065
|
-
if (!dragPropagation && this.openDragLock) {
|
|
11011
|
+
if (!this.getProps().dragPropagation && this.openDragLock) {
|
|
11066
11012
|
this.openDragLock();
|
|
11067
11013
|
this.openDragLock = null;
|
|
11068
11014
|
}
|
|
11069
|
-
animationState
|
|
11015
|
+
animationState?.setActive("whileDrag", false);
|
|
11070
11016
|
}
|
|
11071
11017
|
/**
|
|
11072
11018
|
* Clean up the pan session without modifying other drag state.
|
|
@@ -11074,31 +11020,42 @@ class VisualElementDragControls {
|
|
|
11074
11020
|
* without affecting projection animations or drag locks.
|
|
11075
11021
|
*/
|
|
11076
11022
|
endPanSession() {
|
|
11077
|
-
this.panSession
|
|
11023
|
+
this.panSession?.end();
|
|
11078
11024
|
this.panSession = undefined;
|
|
11079
11025
|
}
|
|
11080
|
-
updateAxis(axis,
|
|
11081
|
-
|
|
11026
|
+
updateAxis(axis, offset) {
|
|
11027
|
+
/**
|
|
11028
|
+
* Read drag per axis: a callback fired while updating the x axis
|
|
11029
|
+
* can synchronously re-render with new props.
|
|
11030
|
+
*/
|
|
11031
|
+
const { drag } = this.readProps();
|
|
11082
11032
|
// If we're not dragging this axis, do an early return.
|
|
11083
11033
|
if (!offset || !shouldDrag(axis, drag, this.currentDirection))
|
|
11084
11034
|
return;
|
|
11085
11035
|
const axisValue = this.getAxisMotionValue(axis);
|
|
11086
11036
|
let next = this.originPoint[axis] + offset[axis];
|
|
11087
11037
|
// Apply constraints
|
|
11088
|
-
|
|
11089
|
-
|
|
11038
|
+
const constraints = this.constraints && this.constraints[axis];
|
|
11039
|
+
if (constraints) {
|
|
11040
|
+
next = applyConstraints(next, constraints, this.elastic[axis]);
|
|
11090
11041
|
}
|
|
11091
11042
|
axisValue.set(next);
|
|
11092
11043
|
}
|
|
11093
11044
|
resolveConstraints() {
|
|
11094
11045
|
const { dragConstraints, dragElastic } = this.getProps();
|
|
11095
|
-
const
|
|
11096
|
-
|
|
11097
|
-
? this.visualElement.projection.measure(false)
|
|
11098
|
-
: this.visualElement.projection?.layout;
|
|
11046
|
+
const { projection } = this.visualElement;
|
|
11047
|
+
const layout = projection && (projection.layout || projection.measure(false));
|
|
11099
11048
|
const prevConstraints = this.constraints;
|
|
11100
11049
|
if (isElementConstraints(dragConstraints)) {
|
|
11101
|
-
|
|
11050
|
+
/**
|
|
11051
|
+
* Ref constraints are measured with the layout. Scrolling a
|
|
11052
|
+
* `layoutScroll` ancestor since can move the element relative
|
|
11053
|
+
* to them without a layout measurement, so measure them again
|
|
11054
|
+
* (#2024). Otherwise keep them: they and the layout can both
|
|
11055
|
+
* have moved on the page since, e.g. when content above grows.
|
|
11056
|
+
*/
|
|
11057
|
+
if (!this.constraints ||
|
|
11058
|
+
this.scroll !== measureScroll(projection)) {
|
|
11102
11059
|
this.constraints = this.resolveRefConstraints();
|
|
11103
11060
|
}
|
|
11104
11061
|
}
|
|
@@ -11135,27 +11092,27 @@ class VisualElementDragControls {
|
|
|
11135
11092
|
if (!isElementConstraints(constraints))
|
|
11136
11093
|
return false;
|
|
11137
11094
|
const constraintsElement = resolveConstraintsElement(constraints);
|
|
11138
|
-
|
|
11095
|
+
process.env.NODE_ENV !== "production" &&
|
|
11096
|
+
motionUtils.invariant(!!constraintsElement, "If `dragConstraints` is set as a React ref, that ref must be passed to another component's `ref` prop.", "drag-constraints-ref");
|
|
11139
11097
|
const { projection } = this.visualElement;
|
|
11140
11098
|
// TODO
|
|
11141
11099
|
if (!projection || !projection.layout)
|
|
11142
11100
|
return false;
|
|
11143
11101
|
/**
|
|
11144
|
-
* Refresh the
|
|
11145
|
-
*
|
|
11146
|
-
*
|
|
11147
|
-
*
|
|
11148
|
-
*
|
|
11149
|
-
*
|
|
11150
|
-
* Clear the cached scroll first so `updateScroll` bypasses its
|
|
11151
|
-
* per-animationId cache and re-reads the live value.
|
|
11102
|
+
* Refresh the scroll offsets of the root and `layoutScroll`
|
|
11103
|
+
* ancestors so the constraint's viewport box translates to the
|
|
11104
|
+
* layout's coordinates. The scroll captured when the layout was
|
|
11105
|
+
* measured can be stale if they've scrolled since — e.g. via the
|
|
11106
|
+
* browser restoring scroll on refresh, or an ancestor layout effect
|
|
11107
|
+
* running after this element's mount (#2829).
|
|
11152
11108
|
*/
|
|
11153
|
-
|
|
11154
|
-
projection.root.scroll = undefined;
|
|
11155
|
-
projection.root.updateScroll();
|
|
11156
|
-
}
|
|
11109
|
+
this.scroll = measureScroll(projection);
|
|
11157
11110
|
const constraintsBox = measurePageBox(constraintsElement, projection.root, this.visualElement.getTransformPagePoint());
|
|
11158
|
-
|
|
11111
|
+
/**
|
|
11112
|
+
* layoutBox removes the scroll of `layoutScroll` ancestors, so
|
|
11113
|
+
* remove it from the constraints box too.
|
|
11114
|
+
*/
|
|
11115
|
+
let measuredConstraints = calcViewportConstraints(projection.layout.layoutBox, projection.removeElementScroll(constraintsBox));
|
|
11159
11116
|
/**
|
|
11160
11117
|
* If there's an onMeasureDragConstraints listener we call it and
|
|
11161
11118
|
* if different constraints are returned, set constraints to that
|
|
@@ -11176,7 +11133,7 @@ class VisualElementDragControls {
|
|
|
11176
11133
|
if (!shouldDrag(axis, dragAxes || drag, this.currentDirection)) {
|
|
11177
11134
|
return;
|
|
11178
11135
|
}
|
|
11179
|
-
let transition =
|
|
11136
|
+
let transition = constraints[axis] || {};
|
|
11180
11137
|
if (dragSnapToOrigin === true ||
|
|
11181
11138
|
dragSnapToOrigin === axis)
|
|
11182
11139
|
transition = { min: 0, max: 0 };
|
|
@@ -11282,7 +11239,7 @@ class VisualElementDragControls {
|
|
|
11282
11239
|
this.visualElement.current.style.transform = transformTemplate
|
|
11283
11240
|
? transformTemplate({}, "")
|
|
11284
11241
|
: "none";
|
|
11285
|
-
projection.root
|
|
11242
|
+
projection.root?.updateScroll();
|
|
11286
11243
|
projection.updateLayout();
|
|
11287
11244
|
/**
|
|
11288
11245
|
* Reset constraints so resolveConstraints() will recalculate them
|
|
@@ -11359,8 +11316,8 @@ class VisualElementDragControls {
|
|
|
11359
11316
|
};
|
|
11360
11317
|
const { projection } = this.visualElement;
|
|
11361
11318
|
const stopMeasureLayoutListener = projection.addEventListener("measure", measureDragConstraints);
|
|
11362
|
-
if (
|
|
11363
|
-
projection.root
|
|
11319
|
+
if (!projection.layout) {
|
|
11320
|
+
projection.root?.updateScroll();
|
|
11364
11321
|
projection.updateLayout();
|
|
11365
11322
|
}
|
|
11366
11323
|
frame.read(measureDragConstraints);
|
|
@@ -11395,22 +11352,14 @@ class VisualElementDragControls {
|
|
|
11395
11352
|
stopResizeListener();
|
|
11396
11353
|
stopPointerListener();
|
|
11397
11354
|
stopMeasureLayoutListener();
|
|
11398
|
-
stopLayoutUpdateListener
|
|
11399
|
-
stopResizeObservers
|
|
11355
|
+
stopLayoutUpdateListener();
|
|
11356
|
+
stopResizeObservers?.();
|
|
11400
11357
|
};
|
|
11401
11358
|
}
|
|
11402
11359
|
getProps() {
|
|
11403
11360
|
const props = this.readProps();
|
|
11404
|
-
const {
|
|
11405
|
-
return {
|
|
11406
|
-
...props,
|
|
11407
|
-
drag,
|
|
11408
|
-
dragDirectionLock,
|
|
11409
|
-
dragPropagation,
|
|
11410
|
-
dragConstraints,
|
|
11411
|
-
dragElastic,
|
|
11412
|
-
dragMomentum,
|
|
11413
|
-
};
|
|
11361
|
+
const { dragElastic = defaultElastic, dragMomentum = true } = props;
|
|
11362
|
+
return { ...props, dragElastic, dragMomentum };
|
|
11414
11363
|
}
|
|
11415
11364
|
}
|
|
11416
11365
|
/**
|
|
@@ -13745,6 +13694,12 @@ function shallowCompare(next, prev) {
|
|
|
13745
13694
|
}
|
|
13746
13695
|
|
|
13747
13696
|
const reversePriorityOrder = [...variantPriorityOrder].reverse();
|
|
13697
|
+
/**
|
|
13698
|
+
* The transition a value uses when it leaves a state (#1725): the state's
|
|
13699
|
+
* own transition when `out: true`, or the `out` transition itself.
|
|
13700
|
+
* Value-specific keys are resolved by animateTarget.
|
|
13701
|
+
*/
|
|
13702
|
+
const getOutTransition = (transition) => transition?.out === true ? transition : transition?.out;
|
|
13748
13703
|
/**
|
|
13749
13704
|
* Diffs the element's animation props (one layer per AnimationType, highest
|
|
13750
13705
|
* priority wins each value) against the previous call and starts animations
|
|
@@ -13766,13 +13721,18 @@ function createAnimationState(visualElement) {
|
|
|
13766
13721
|
let wasReset = false;
|
|
13767
13722
|
function animateChanges(changedActiveType) {
|
|
13768
13723
|
const { props, parent, manuallyAnimateOnMount } = visualElement;
|
|
13724
|
+
const { initial } = props;
|
|
13769
13725
|
const isMounting = isInitialRender || wasReset;
|
|
13770
13726
|
const animations = [];
|
|
13727
|
+
const resolveInitial = (definition = initial) => (typeof definition !== "boolean" &&
|
|
13728
|
+
resolveVariant(visualElement, Array.isArray(definition) ? definition[0] : definition, visualElement.presenceContext?.custom)) ||
|
|
13729
|
+
undefined;
|
|
13771
13730
|
/**
|
|
13772
|
-
* Values removed from a type
|
|
13773
|
-
*
|
|
13731
|
+
* Values removed from a type, mapped to the out transition of the
|
|
13732
|
+
* state they're leaving. A lower-priority type that defines them
|
|
13733
|
+
* animates them back, otherwise they fall back to a base target.
|
|
13774
13734
|
*/
|
|
13775
|
-
const removedKeys = new
|
|
13735
|
+
const removedKeys = new Map();
|
|
13776
13736
|
/**
|
|
13777
13737
|
* Values claimed by active, higher-priority types.
|
|
13778
13738
|
*/
|
|
@@ -13790,6 +13750,13 @@ function createAnimationState(visualElement) {
|
|
|
13790
13750
|
do
|
|
13791
13751
|
source = source.props.inherit !== false && source.parent;
|
|
13792
13752
|
while (source && !source.isControllingVariants);
|
|
13753
|
+
/**
|
|
13754
|
+
* Mounting leaves initial, so values use its out transition. Like the
|
|
13755
|
+
* other types, variant children inherit initial's label.
|
|
13756
|
+
*/
|
|
13757
|
+
const initialOut = isMounting &&
|
|
13758
|
+
getOutTransition(resolveInitial(initial ?? (source && source.props.initial))
|
|
13759
|
+
?.transition);
|
|
13793
13760
|
reversePriorityOrder.forEach((type, i) => {
|
|
13794
13761
|
const typeState = state[type];
|
|
13795
13762
|
const ownProp = props[type];
|
|
@@ -13801,8 +13768,6 @@ function createAnimationState(visualElement) {
|
|
|
13801
13768
|
: undefined;
|
|
13802
13769
|
const propIsVariant = isVariantLabel(prop);
|
|
13803
13770
|
const activeDelta = type === changedActiveType ? typeState.isActive : null;
|
|
13804
|
-
if (activeDelta === false)
|
|
13805
|
-
removedVariantIndex = i;
|
|
13806
13771
|
/**
|
|
13807
13772
|
* Inherited labels are animated by the parent through
|
|
13808
13773
|
* variantChildren, unless this element mounted after its parent.
|
|
@@ -13817,6 +13782,13 @@ function createAnimationState(visualElement) {
|
|
|
13817
13782
|
typeof prop === "boolean") {
|
|
13818
13783
|
return;
|
|
13819
13784
|
}
|
|
13785
|
+
/**
|
|
13786
|
+
* Set after the skip above, so deactivating a type that has nothing
|
|
13787
|
+
* to animate (e.g. whileTap with no prop) doesn't re-run the variants
|
|
13788
|
+
* below it.
|
|
13789
|
+
*/
|
|
13790
|
+
if (activeDelta === false)
|
|
13791
|
+
removedVariantIndex = i;
|
|
13820
13792
|
/**
|
|
13821
13793
|
* Don't re-resolve a running exit: a changed custom would start
|
|
13822
13794
|
* new value animations that stop the originals, leaving the exit
|
|
@@ -13836,6 +13808,7 @@ function createAnimationState(visualElement) {
|
|
|
13836
13808
|
let handledRemovedValues = false;
|
|
13837
13809
|
const definitionList = Array.isArray(prop) ? prop : [prop];
|
|
13838
13810
|
let resolvedValues = {};
|
|
13811
|
+
let out;
|
|
13839
13812
|
if (activeDelta !== false) {
|
|
13840
13813
|
for (const definition of definitionList) {
|
|
13841
13814
|
const { transition, transitionEnd, ...target } = resolveVariant(visualElement, definition, getTypeCustom(visualElement, type)) || {};
|
|
@@ -13844,6 +13817,11 @@ function createAnimationState(visualElement) {
|
|
|
13844
13817
|
...target,
|
|
13845
13818
|
...transitionEnd,
|
|
13846
13819
|
};
|
|
13820
|
+
/**
|
|
13821
|
+
* One out transition per type. With a list of labels,
|
|
13822
|
+
* the last one that sets out applies to all its values.
|
|
13823
|
+
*/
|
|
13824
|
+
out = getOutTransition(transition) || out;
|
|
13847
13825
|
}
|
|
13848
13826
|
}
|
|
13849
13827
|
const { prevResolvedValues } = typeState;
|
|
@@ -13859,12 +13837,18 @@ function createAnimationState(visualElement) {
|
|
|
13859
13837
|
const valueHasChanged = Array.isArray(next) && Array.isArray(prev)
|
|
13860
13838
|
? !shallowCompare(next, prev) || variantDidChange
|
|
13861
13839
|
: next !== prev;
|
|
13840
|
+
let outTransition;
|
|
13862
13841
|
if (valueHasChanged && (next === undefined || next === null)) {
|
|
13863
|
-
|
|
13842
|
+
/**
|
|
13843
|
+
* The highest-priority state a value leaves wins.
|
|
13844
|
+
*/
|
|
13845
|
+
removedKeys.has(key) ||
|
|
13846
|
+
removedKeys.set(key, typeState.prevOut);
|
|
13864
13847
|
}
|
|
13865
13848
|
else if (valueHasChanged ||
|
|
13866
13849
|
(next !== undefined && removedKeys.has(key))) {
|
|
13867
13850
|
shouldAnimateType = true;
|
|
13851
|
+
outTransition = removedKeys.get(key) || initialOut;
|
|
13868
13852
|
if (removedKeys.delete(key))
|
|
13869
13853
|
handledRemovedValues = true;
|
|
13870
13854
|
typeState.needsAnimating[key] = true;
|
|
@@ -13875,9 +13859,11 @@ function createAnimationState(visualElement) {
|
|
|
13875
13859
|
else {
|
|
13876
13860
|
typeState.protectedKeys[key] = true;
|
|
13877
13861
|
}
|
|
13862
|
+
typeState.out[key] = outTransition;
|
|
13878
13863
|
}
|
|
13879
13864
|
typeState.prevProp = prop;
|
|
13880
13865
|
typeState.prevResolvedValues = resolvedValues;
|
|
13866
|
+
typeState.prevOut = out;
|
|
13881
13867
|
if (typeState.isActive) {
|
|
13882
13868
|
encounteredKeys = { ...encounteredKeys, ...resolvedValues };
|
|
13883
13869
|
}
|
|
@@ -13908,14 +13894,17 @@ function createAnimationState(visualElement) {
|
|
|
13908
13894
|
* longer defines a value it once did, it stays where it is.
|
|
13909
13895
|
*/
|
|
13910
13896
|
if (removedKeys.size) {
|
|
13911
|
-
const { initial } = props;
|
|
13912
13897
|
const fallbackAnimation = {};
|
|
13913
|
-
const resolvedInitial =
|
|
13914
|
-
|
|
13915
|
-
|
|
13916
|
-
|
|
13917
|
-
|
|
13918
|
-
|
|
13898
|
+
const resolvedInitial = resolveInitial();
|
|
13899
|
+
let fallbackTransition = resolvedInitial?.transition;
|
|
13900
|
+
removedKeys.forEach((outTransition, key) => {
|
|
13901
|
+
if (outTransition) {
|
|
13902
|
+
fallbackTransition = {
|
|
13903
|
+
...(fallbackTransition ||
|
|
13904
|
+
visualElement.getDefaultTransition()),
|
|
13905
|
+
[key]: outTransition,
|
|
13906
|
+
};
|
|
13907
|
+
}
|
|
13919
13908
|
const motionValue = visualElement.getValue(key);
|
|
13920
13909
|
if (motionValue)
|
|
13921
13910
|
motionValue.liveStyle = true;
|
|
@@ -13947,6 +13936,9 @@ function createAnimationState(visualElement) {
|
|
|
13947
13936
|
visualElement.baseTarget[key] = motionValue?.get();
|
|
13948
13937
|
}
|
|
13949
13938
|
});
|
|
13939
|
+
if (fallbackTransition) {
|
|
13940
|
+
fallbackAnimation.transition = fallbackTransition;
|
|
13941
|
+
}
|
|
13950
13942
|
animations.push({ animation: fallbackAnimation });
|
|
13951
13943
|
}
|
|
13952
13944
|
const blockAnimation = (isMounting && visualElement.blockInitialAnimation) ||
|
|
@@ -14006,6 +13998,7 @@ function createState() {
|
|
|
14006
13998
|
protectedKeys: {},
|
|
14007
13999
|
needsAnimating: {},
|
|
14008
14000
|
prevResolvedValues: {},
|
|
14001
|
+
out: {},
|
|
14009
14002
|
};
|
|
14010
14003
|
}
|
|
14011
14004
|
return state;
|
|
@@ -14172,6 +14165,7 @@ exports.buildProjectionTransform = buildProjectionTransform;
|
|
|
14172
14165
|
exports.buildSVGAttrs = buildSVGAttrs;
|
|
14173
14166
|
exports.buildSVGPath = buildSVGPath;
|
|
14174
14167
|
exports.buildTransform = buildTransform$1;
|
|
14168
|
+
exports.buildTransformer = buildTransformer;
|
|
14175
14169
|
exports.calcAxisDelta = calcAxisDelta;
|
|
14176
14170
|
exports.calcBoxDelta = calcBoxDelta;
|
|
14177
14171
|
exports.calcChildStagger = calcChildStagger;
|