motion-dom 14.5.0 → 14.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +706 -632
- 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 +14 -8
- 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 +50 -52
- 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/keyframes/utils/unit-conversion.mjs +8 -7
- package/dist/es/animation/keyframes/utils/unit-conversion.mjs.map +1 -1
- package/dist/es/animation/optimized-appear/data-id.mjs +1 -3
- package/dist/es/animation/optimized-appear/data-id.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/supports/waapi.mjs +8 -2
- package/dist/es/animation/waapi/supports/waapi.mjs.map +1 -1
- package/dist/es/animation/waapi/transforms/TransformAnimation.mjs +44 -21
- package/dist/es/animation/waapi/transforms/TransformAnimation.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/frameloop/process-frame.mjs +42 -0
- package/dist/es/frameloop/process-frame.mjs.map +1 -0
- package/dist/es/frameloop/render-step.mjs +15 -1
- package/dist/es/frameloop/render-step.mjs.map +1 -1
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +94 -67
- 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 +4 -2
- package/dist/es/index.mjs.map +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/DocumentProjectionNode.mjs +8 -3
- package/dist/es/projection/node/DocumentProjectionNode.mjs.map +1 -1
- package/dist/es/projection/node/HTMLProjectionNode.mjs +5 -6
- package/dist/es/projection/node/HTMLProjectionNode.mjs.map +1 -1
- package/dist/es/projection/node/create-projection-node.mjs +158 -148
- package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
- package/dist/es/projection/node/root.mjs +6 -0
- package/dist/es/projection/node/root.mjs.map +1 -0
- package/dist/es/projection/styles/default-scale-correctors.mjs +3 -4
- package/dist/es/projection/styles/default-scale-correctors.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 +58 -15
- package/dist/es/render/utils/animation-state.mjs.map +1 -1
- package/dist/es/render/utils/variant-props.mjs +1 -1
- package/dist/es/render/utils/variant-props.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 +111 -30
- package/dist/motion-dom.dev.js +690 -625
- 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
|
};
|
|
@@ -621,6 +609,11 @@ function createRenderStep(runNextFrame) {
|
|
|
621
609
|
*/
|
|
622
610
|
let isProcessing = false;
|
|
623
611
|
let flushNextFrame = false;
|
|
612
|
+
/**
|
|
613
|
+
* The callback currently running. If it schedules itself with `immediate`
|
|
614
|
+
* it's left in place, so as before it doesn't run again this step.
|
|
615
|
+
*/
|
|
616
|
+
let running;
|
|
624
617
|
/**
|
|
625
618
|
* A set of processes which were marked keepAlive when scheduled.
|
|
626
619
|
* A keepAlive process is always also held by a frame queue until
|
|
@@ -638,7 +631,7 @@ function createRenderStep(runNextFrame) {
|
|
|
638
631
|
nextFrame.add(callback);
|
|
639
632
|
runNextFrame();
|
|
640
633
|
}
|
|
641
|
-
callback(latestFrameData);
|
|
634
|
+
(running = callback)(latestFrameData);
|
|
642
635
|
}
|
|
643
636
|
const step = {
|
|
644
637
|
/**
|
|
@@ -649,6 +642,14 @@ function createRenderStep(runNextFrame) {
|
|
|
649
642
|
const queue = addToCurrentFrame ? thisFrame : nextFrame;
|
|
650
643
|
if (keepAlive)
|
|
651
644
|
toKeepAlive.add(callback);
|
|
645
|
+
/**
|
|
646
|
+
* A callback scheduled with `immediate` during processing may
|
|
647
|
+
* already have run this step (for instance, a value it reads was
|
|
648
|
+
* changed by a later callback). Re-adding moves it to the end of
|
|
649
|
+
* the queue, so it runs again. The running callback is excluded,
|
|
650
|
+
* so one that re-schedules itself can't loop forever.
|
|
651
|
+
*/
|
|
652
|
+
addToCurrentFrame && callback !== running && queue.delete(callback);
|
|
652
653
|
queue.add(callback);
|
|
653
654
|
return callback;
|
|
654
655
|
},
|
|
@@ -683,6 +684,7 @@ function createRenderStep(runNextFrame) {
|
|
|
683
684
|
// Clear the frame so no callbacks remain. This is to avoid
|
|
684
685
|
// memory leaks should this render step not run for a while.
|
|
685
686
|
thisFrame.clear();
|
|
687
|
+
running = undefined;
|
|
686
688
|
isProcessing = false;
|
|
687
689
|
if (flushNextFrame) {
|
|
688
690
|
flushNextFrame = false;
|
|
@@ -830,37 +832,31 @@ function createGeneratorEasing(options, scale = 100, createGenerator) {
|
|
|
830
832
|
};
|
|
831
833
|
}
|
|
832
834
|
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
},
|
|
851
|
-
// Limits
|
|
852
|
-
minDuration: 0.01, // in seconds
|
|
853
|
-
maxDuration: 10.0, // in seconds
|
|
854
|
-
minDamping: 0.05,
|
|
855
|
-
};
|
|
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;
|
|
856
852
|
/**
|
|
857
853
|
* Maps bounce to a damping ratio as SwiftUI does: 0 is critically damped, and
|
|
858
854
|
* it approaches undamped towards 1 and infinitely overdamped towards -1. Both
|
|
859
855
|
* ends are limited so the spring still moves and settles.
|
|
860
856
|
*/
|
|
861
857
|
const bounceToDampingRatio = (bounce) => bounce < 0
|
|
862
|
-
? 1 / Math.max(1 + bounce,
|
|
863
|
-
: Math.max(1 - bounce,
|
|
858
|
+
? 1 / Math.max(1 + bounce, minDamping)
|
|
859
|
+
: Math.max(1 - bounce, minDamping);
|
|
864
860
|
/**
|
|
865
861
|
* Scales an overdamped spring's undamped frequency so that, at its defining
|
|
866
862
|
* time, it has as far left to go as the critically damped spring that's
|
|
@@ -903,12 +899,13 @@ const safeMin = 0.001;
|
|
|
903
899
|
* ignore inherited velocity and only resolve without valid physics. Returns
|
|
904
900
|
* NaN physics when the root search doesn't converge.
|
|
905
901
|
*/
|
|
906
|
-
function findSpring({ duration =
|
|
902
|
+
function findSpring({ duration = defaultDuration, bounce = defaultBounce, }) {
|
|
907
903
|
let envelope;
|
|
908
904
|
let derivative;
|
|
909
|
-
|
|
905
|
+
process.env.NODE_ENV !== "production" &&
|
|
906
|
+
motionUtils.warning(duration <= motionUtils.secondsToMilliseconds(maxDuration), "Spring duration must be 10 seconds or less", "spring-duration-limit");
|
|
910
907
|
const dampingRatio = bounceToDampingRatio(bounce);
|
|
911
|
-
duration = motionUtils.clamp(
|
|
908
|
+
duration = motionUtils.clamp(minDuration, maxDuration, motionUtils.millisecondsToSeconds(duration));
|
|
912
909
|
if (dampingRatio < 1) {
|
|
913
910
|
/**
|
|
914
911
|
* Underdamped spring
|
|
@@ -993,9 +990,9 @@ function getSpringOptions(options) {
|
|
|
993
990
|
const validMass = resolvePhysics(options.mass);
|
|
994
991
|
const springOptions = {
|
|
995
992
|
...options,
|
|
996
|
-
stiffness: validStiffness ??
|
|
997
|
-
damping: validDamping ??
|
|
998
|
-
mass: validMass ??
|
|
993
|
+
stiffness: validStiffness ?? defaultStiffness,
|
|
994
|
+
damping: validDamping ?? defaultDamping,
|
|
995
|
+
mass: validMass ?? defaultMass,
|
|
999
996
|
isResolvedFromDuration: false,
|
|
1000
997
|
// stiffness/damping/mass overrides duration/bounce
|
|
1001
998
|
isTimeDefined: (validStiffness ?? validDamping ?? validMass) === undefined &&
|
|
@@ -1023,13 +1020,13 @@ function getSpringOptions(options) {
|
|
|
1023
1020
|
*/
|
|
1024
1021
|
if (!isValidPhysics(springOptions.stiffness) ||
|
|
1025
1022
|
!isValidPhysics(springOptions.damping, true)) {
|
|
1026
|
-
springOptions.stiffness =
|
|
1027
|
-
springOptions.damping =
|
|
1023
|
+
springOptions.stiffness = defaultStiffness;
|
|
1024
|
+
springOptions.damping = defaultDamping;
|
|
1028
1025
|
}
|
|
1029
1026
|
}
|
|
1030
1027
|
return springOptions;
|
|
1031
1028
|
}
|
|
1032
|
-
function
|
|
1029
|
+
function springGenerator(optionsOrVisualDuration = defaultVisualDuration, bounce = defaultBounce) {
|
|
1033
1030
|
const options = typeof optionsOrVisualDuration !== "object"
|
|
1034
1031
|
? {
|
|
1035
1032
|
visualDuration: optionsOrVisualDuration,
|
|
@@ -1079,14 +1076,10 @@ function spring(optionsOrVisualDuration = springDefaults.visualDuration, bounce
|
|
|
1079
1076
|
const isGranularScale = Math.abs(s.delta) < 5;
|
|
1080
1077
|
s.restSpeed =
|
|
1081
1078
|
options.restSpeed ||
|
|
1082
|
-
(isGranularScale
|
|
1083
|
-
? springDefaults.restSpeed.granular
|
|
1084
|
-
: springDefaults.restSpeed.default);
|
|
1079
|
+
(isGranularScale ? restSpeedGranular : restSpeedDefault);
|
|
1085
1080
|
s.restDelta =
|
|
1086
1081
|
options.restDelta ||
|
|
1087
|
-
(isGranularScale
|
|
1088
|
-
? springDefaults.restDelta.granular
|
|
1089
|
-
: springDefaults.restDelta.default);
|
|
1082
|
+
(isGranularScale ? restDeltaGranular : restDeltaDefault);
|
|
1090
1083
|
};
|
|
1091
1084
|
setRestThresholds();
|
|
1092
1085
|
let resolveSpring;
|
|
@@ -1155,11 +1148,16 @@ function spring(optionsOrVisualDuration = springDefaults.visualDuration, bounce
|
|
|
1155
1148
|
* dampedAngularFreq * t passes 300, both terms decay at the damping
|
|
1156
1149
|
* rate. Heavily overdamped drag springs (dragElastic: 0,
|
|
1157
1150
|
* dragTransition) rely on this to settle almost at once rather than
|
|
1158
|
-
* creep at stiffness / damping.
|
|
1159
|
-
*
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
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);
|
|
1163
1161
|
const c = { S: 0, F: 0 };
|
|
1164
1162
|
update = () => {
|
|
1165
1163
|
const P = (s.velocity + decay * s.delta) / dampedAngularFreq;
|
|
@@ -1214,13 +1212,15 @@ function spring(optionsOrVisualDuration = springDefaults.visualDuration, bounce
|
|
|
1214
1212
|
};
|
|
1215
1213
|
return generator;
|
|
1216
1214
|
}
|
|
1217
|
-
spring
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1215
|
+
const spring = /* @__PURE__ */ Object.assign(springGenerator, {
|
|
1216
|
+
applyToOptions: (options) => {
|
|
1217
|
+
const generatorOptions = createGeneratorEasing(options, 100, springGenerator);
|
|
1218
|
+
options.ease = generatorOptions.ease;
|
|
1219
|
+
options.duration = motionUtils.secondsToMilliseconds(generatorOptions.duration);
|
|
1220
|
+
options.type = "keyframes";
|
|
1221
|
+
return options;
|
|
1222
|
+
},
|
|
1223
|
+
});
|
|
1224
1224
|
|
|
1225
1225
|
function inertia({ keyframes, velocity = 0.0, power = 0.8, timeConstant = 325, bounceDamping = 10, bounceStiffness = 500, modifyTarget, min, max, restDelta = 0.5, restSpeed, }) {
|
|
1226
1226
|
const origin = keyframes[0];
|
|
@@ -1238,7 +1238,7 @@ function inertia({ keyframes, velocity = 0.0, power = 0.8, timeConstant = 325, b
|
|
|
1238
1238
|
};
|
|
1239
1239
|
let amplitude = power * velocity;
|
|
1240
1240
|
const ideal = origin + amplitude;
|
|
1241
|
-
const target = modifyTarget
|
|
1241
|
+
const target = modifyTarget ? modifyTarget(ideal) : ideal;
|
|
1242
1242
|
/**
|
|
1243
1243
|
* If the target has changed we need to re-calculate the amplitude, otherwise
|
|
1244
1244
|
* the animation will start from the wrong position.
|
|
@@ -1249,7 +1249,8 @@ function inertia({ keyframes, velocity = 0.0, power = 0.8, timeConstant = 325, b
|
|
|
1249
1249
|
const applyFriction = (t) => {
|
|
1250
1250
|
const delta = calcDelta(t);
|
|
1251
1251
|
state.done = Math.abs(delta) <= restDelta;
|
|
1252
|
-
|
|
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;
|
|
1253
1254
|
};
|
|
1254
1255
|
/**
|
|
1255
1256
|
* Ideally this would resolve for t in a stateless way, we could
|
|
@@ -1343,7 +1344,8 @@ function createMixers(output, ease, customMixer) {
|
|
|
1343
1344
|
*/
|
|
1344
1345
|
function interpolate(input, output, { clamp: isClamp = true, ease, mixer } = {}) {
|
|
1345
1346
|
const inputLength = input.length;
|
|
1346
|
-
|
|
1347
|
+
process.env.NODE_ENV !== "production" &&
|
|
1348
|
+
motionUtils.invariant(inputLength === output.length, "Both input and output ranges must be the same length", "range-length");
|
|
1347
1349
|
/**
|
|
1348
1350
|
* If we're only provided a single input, we can just make a function
|
|
1349
1351
|
* that returns the output.
|
|
@@ -1696,17 +1698,12 @@ class JSAnimation extends WithPromise {
|
|
|
1696
1698
|
this.generator = generator;
|
|
1697
1699
|
}
|
|
1698
1700
|
updateTime(timestamp) {
|
|
1699
|
-
|
|
1700
|
-
//
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
// Rounding the time because floating point arithmetic is not always accurate, e.g. 3000.367 - 1000.367 =
|
|
1706
|
-
// 2000.0000000000002. This is a problem when we are comparing the currentTime with the duration, for
|
|
1707
|
-
// example.
|
|
1708
|
-
this.currentTime = animationTime;
|
|
1709
|
-
}
|
|
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;
|
|
1710
1707
|
}
|
|
1711
1708
|
tick(timestamp, sample = false) {
|
|
1712
1709
|
const { generator, totalDuration, calculatedDuration } = this;
|
|
@@ -1747,10 +1744,17 @@ class JSAnimation extends WithPromise {
|
|
|
1747
1744
|
}
|
|
1748
1745
|
const state = this.generate(this.currentTime, isInDelayPhase);
|
|
1749
1746
|
let { done } = state;
|
|
1750
|
-
|
|
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) {
|
|
1751
1753
|
done =
|
|
1752
1754
|
this.playbackSpeed >= 0
|
|
1753
|
-
?
|
|
1755
|
+
? calculatedDuration < Infinity
|
|
1756
|
+
? this.currentTime >= totalDuration
|
|
1757
|
+
: done
|
|
1754
1758
|
: this.currentTime <= 0;
|
|
1755
1759
|
}
|
|
1756
1760
|
const isAnimationFinished = this.holdTime === null &&
|
|
@@ -1856,20 +1860,11 @@ class JSAnimation extends WithPromise {
|
|
|
1856
1860
|
}
|
|
1857
1861
|
return state;
|
|
1858
1862
|
}
|
|
1859
|
-
/**
|
|
1860
|
-
* Allows the returned animation to be awaited or promise-chained. Currently
|
|
1861
|
-
* resolves when the animation finishes at all but in a future update could/should
|
|
1862
|
-
* reject if its cancels.
|
|
1863
|
-
*/
|
|
1864
|
-
then(resolve, reject) {
|
|
1865
|
-
return this.finished.then(resolve, reject);
|
|
1866
|
-
}
|
|
1867
1863
|
get duration() {
|
|
1868
1864
|
return motionUtils.millisecondsToSeconds(this.calculatedDuration);
|
|
1869
1865
|
}
|
|
1870
1866
|
get iterationDuration() {
|
|
1871
|
-
|
|
1872
|
-
return this.duration + motionUtils.millisecondsToSeconds(delay);
|
|
1867
|
+
return this.duration + motionUtils.millisecondsToSeconds(this.options.delay ?? 0);
|
|
1873
1868
|
}
|
|
1874
1869
|
get time() {
|
|
1875
1870
|
return motionUtils.millisecondsToSeconds(this.currentTime);
|
|
@@ -1973,14 +1968,9 @@ class JSAnimation extends WithPromise {
|
|
|
1973
1968
|
}
|
|
1974
1969
|
teardown() {
|
|
1975
1970
|
this.state = "idle";
|
|
1976
|
-
this.
|
|
1977
|
-
this.startTime = this.holdTime = null;
|
|
1978
|
-
}
|
|
1979
|
-
stopDriver() {
|
|
1980
|
-
if (!this.driver)
|
|
1981
|
-
return;
|
|
1982
|
-
this.driver.stop();
|
|
1971
|
+
this.driver?.stop();
|
|
1983
1972
|
this.driver = undefined;
|
|
1973
|
+
this.startTime = this.holdTime = null;
|
|
1984
1974
|
}
|
|
1985
1975
|
sample(sampleTime) {
|
|
1986
1976
|
this.startTime = 0;
|
|
@@ -2237,23 +2227,15 @@ function parseValueFromTransform(transform, name) {
|
|
|
2237
2227
|
if (!transform || transform === "none") {
|
|
2238
2228
|
return defaultTransformValue(name);
|
|
2239
2229
|
}
|
|
2240
|
-
const
|
|
2241
|
-
let parsers;
|
|
2242
|
-
let match;
|
|
2243
|
-
if (matrix3dMatch) {
|
|
2244
|
-
parsers = matrix3dParsers;
|
|
2245
|
-
match = matrix3dMatch;
|
|
2246
|
-
}
|
|
2247
|
-
else {
|
|
2248
|
-
const matrix2dMatch = transform.match(/^matrix\(([-\d.e\s,]+)\)$/u);
|
|
2249
|
-
parsers = matrix2dParsers;
|
|
2250
|
-
match = matrix2dMatch;
|
|
2251
|
-
}
|
|
2230
|
+
const match = transform.match(/^matrix(3d)?\(([-\d.e\s,]+)\)$/u);
|
|
2252
2231
|
if (!match) {
|
|
2253
2232
|
return defaultTransformValue(name);
|
|
2254
2233
|
}
|
|
2255
|
-
const valueParser =
|
|
2256
|
-
|
|
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));
|
|
2257
2239
|
return typeof valueParser === "function"
|
|
2258
2240
|
? valueParser(values)
|
|
2259
2241
|
: values[valueParser];
|
|
@@ -2262,9 +2244,6 @@ const readTransformValue = (instance, name) => {
|
|
|
2262
2244
|
const { transform = "none" } = getComputedStyle(instance);
|
|
2263
2245
|
return parseValueFromTransform(transform, name);
|
|
2264
2246
|
};
|
|
2265
|
-
function convertTransformToNumber(value) {
|
|
2266
|
-
return parseFloat(value.trim());
|
|
2267
|
-
}
|
|
2268
2247
|
|
|
2269
2248
|
/**
|
|
2270
2249
|
* Generate a list of every possible transform key.
|
|
@@ -2303,7 +2282,7 @@ const transformProps = /*@__PURE__*/ (() => new Set([...transformPropOrder, "pat
|
|
|
2303
2282
|
|
|
2304
2283
|
const isNumOrPxType = (v) => v === number || v === px;
|
|
2305
2284
|
const transformKeys = new Set(["x", "y", "z"]);
|
|
2306
|
-
const nonTranslationalTransformKeys = transformPropOrder.filter((key) => !transformKeys.has(key));
|
|
2285
|
+
const nonTranslationalTransformKeys = /* @__PURE__ */ transformPropOrder.filter((key) => !transformKeys.has(key));
|
|
2307
2286
|
/**
|
|
2308
2287
|
* Reset any bounding box-changing transforms so the element can be
|
|
2309
2288
|
* measured. Returns the values to restore. Values already at their
|
|
@@ -2345,6 +2324,8 @@ function measureDimension(computed, measureBox, axis, paddingStart, paddingEnd,
|
|
|
2345
2324
|
? size
|
|
2346
2325
|
: size - parseFloat(paddingStart) - parseFloat(paddingEnd);
|
|
2347
2326
|
}
|
|
2327
|
+
const transformX = ({ transform }) => parseValueFromTransform(transform, "x");
|
|
2328
|
+
const transformY = ({ transform }) => parseValueFromTransform(transform, "y");
|
|
2348
2329
|
const positionalValues = {
|
|
2349
2330
|
// Dimensions
|
|
2350
2331
|
width: ({ width, paddingLeft = "0", paddingRight = "0", boxSizing }, measureBox) => measureDimension(width, measureBox, "x", paddingLeft, paddingRight, boxSizing),
|
|
@@ -2359,13 +2340,12 @@ const positionalValues = {
|
|
|
2359
2340
|
const { x } = measureBox();
|
|
2360
2341
|
return parseFloat(left) + (x.max - x.min);
|
|
2361
2342
|
},
|
|
2362
|
-
// Transform
|
|
2363
|
-
x:
|
|
2364
|
-
y:
|
|
2343
|
+
// Transform, including translate longform names
|
|
2344
|
+
x: transformX,
|
|
2345
|
+
y: transformY,
|
|
2346
|
+
translateX: transformX,
|
|
2347
|
+
translateY: transformY,
|
|
2365
2348
|
};
|
|
2366
|
-
// Alias translate longform names
|
|
2367
|
-
positionalValues.translateX = positionalValues.x;
|
|
2368
|
-
positionalValues.translateY = positionalValues.y;
|
|
2369
2349
|
|
|
2370
2350
|
const toResolve = new Set();
|
|
2371
2351
|
let isScheduled = false;
|
|
@@ -2666,7 +2646,9 @@ class NativeAnimation extends WithPromise {
|
|
|
2666
2646
|
this.isPseudoElement = Boolean(pseudoElement);
|
|
2667
2647
|
this.allowFlatten = allowFlatten;
|
|
2668
2648
|
this.options = options;
|
|
2669
|
-
|
|
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");
|
|
2670
2652
|
const transition = applyGeneratorOptions(options);
|
|
2671
2653
|
this.animation = startWaapiAnimation(element, name, keyframes, transition, pseudoElement);
|
|
2672
2654
|
if (transition.autoplay === false) {
|
|
@@ -2676,9 +2658,7 @@ class NativeAnimation extends WithPromise {
|
|
|
2676
2658
|
this.finishedTime = this.time;
|
|
2677
2659
|
if (!pseudoElement) {
|
|
2678
2660
|
const keyframe = getFinalKeyframe(keyframes, this.options, finalKeyframe, this.speed);
|
|
2679
|
-
|
|
2680
|
-
this.updateMotionValue(keyframe);
|
|
2681
|
-
}
|
|
2661
|
+
this.updateMotionValue?.(keyframe);
|
|
2682
2662
|
/**
|
|
2683
2663
|
* If we can, we want to commit the final style as set by the user,
|
|
2684
2664
|
* rather than the computed keyframe value supplied by the animation.
|
|
@@ -2719,18 +2699,24 @@ class NativeAnimation extends WithPromise {
|
|
|
2719
2699
|
if (this.isStopped)
|
|
2720
2700
|
return;
|
|
2721
2701
|
this.isStopped = true;
|
|
2722
|
-
|
|
2723
|
-
|
|
2702
|
+
/**
|
|
2703
|
+
* Before its finish event, a finished animation (an instant one is
|
|
2704
|
+
* as soon as it starts) is still showing its end, so it's stopped
|
|
2705
|
+
* like a running one. Otherwise that event would apply its end
|
|
2706
|
+
* over whatever animates the value next.
|
|
2707
|
+
*/
|
|
2708
|
+
if (this.state === "idle" || this.finishedTime !== null)
|
|
2724
2709
|
return;
|
|
2725
|
-
}
|
|
2726
2710
|
if (this.updateMotionValue) {
|
|
2727
2711
|
this.updateMotionValue();
|
|
2728
2712
|
}
|
|
2729
2713
|
else {
|
|
2730
2714
|
this.commitStyles();
|
|
2731
2715
|
}
|
|
2732
|
-
if (!this.isPseudoElement)
|
|
2716
|
+
if (!this.isPseudoElement) {
|
|
2717
|
+
this.animation.onfinish = null;
|
|
2733
2718
|
this.cancel();
|
|
2719
|
+
}
|
|
2734
2720
|
}
|
|
2735
2721
|
/**
|
|
2736
2722
|
* WAAPI doesn't natively have any interruption capabilities.
|
|
@@ -2993,6 +2979,7 @@ function canAnimate(keyframes, name, type, velocity) {
|
|
|
2993
2979
|
if (!isOriginAnimatable || !isTargetAnimatable) {
|
|
2994
2980
|
// Only build the message when we're going to warn
|
|
2995
2981
|
isOriginAnimatable !== isTargetAnimatable &&
|
|
2982
|
+
process.env.NODE_ENV !== "production" &&
|
|
2996
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");
|
|
2997
2984
|
return false;
|
|
2998
2985
|
}
|
|
@@ -3007,13 +2994,16 @@ function makeAnimationInstant(options) {
|
|
|
3007
2994
|
|
|
3008
2995
|
/**
|
|
3009
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.
|
|
3010
3001
|
*/
|
|
3011
3002
|
const acceleratedValues = new Set([
|
|
3012
3003
|
"opacity",
|
|
3013
3004
|
"clipPath",
|
|
3014
3005
|
"filter",
|
|
3015
3006
|
"transform",
|
|
3016
|
-
"backgroundColor",
|
|
3017
3007
|
]);
|
|
3018
3008
|
|
|
3019
3009
|
const browserColorFunctions = /^(?:oklch|oklab|lab|lch|color|color-mix|light-dark)\(/;
|
|
@@ -3039,7 +3029,13 @@ const colorProperties = new Set([
|
|
|
3039
3029
|
"borderBottomColor",
|
|
3040
3030
|
"borderLeftColor",
|
|
3041
3031
|
]);
|
|
3042
|
-
|
|
3032
|
+
/**
|
|
3033
|
+
* WAAPI runs on the browser's clock, so on a manual clock every animation
|
|
3034
|
+
* runs in JS where processFrame can drive it. Set the flag before starting
|
|
3035
|
+
* animations: running WAAPI animations stay on the browser's clock.
|
|
3036
|
+
*/
|
|
3037
|
+
const supportsWaapi = () => !motionUtils.MotionGlobalConfig.useManualTiming &&
|
|
3038
|
+
Object.hasOwnProperty.call(Element.prototype, "animate");
|
|
3043
3039
|
function supportsBrowserAnimation(options) {
|
|
3044
3040
|
const { motionValue, name, repeatDelay, repeatType, damping, type, keyframes, } = options;
|
|
3045
3041
|
/**
|
|
@@ -3099,6 +3095,20 @@ const translateAlias = {
|
|
|
3099
3095
|
transformPerspective: "perspective",
|
|
3100
3096
|
};
|
|
3101
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);
|
|
3102
3112
|
/**
|
|
3103
3113
|
* Build a CSS transform style from individual x/y/scale etc properties.
|
|
3104
3114
|
*
|
|
@@ -3108,7 +3118,6 @@ const numTransforms = transformPropOrder.length;
|
|
|
3108
3118
|
function buildTransform$1(latestValues, transform, transformTemplate) {
|
|
3109
3119
|
// The transform string we're going to build into.
|
|
3110
3120
|
let transformString = "";
|
|
3111
|
-
let transformIsDefault = true;
|
|
3112
3121
|
/**
|
|
3113
3122
|
* Loop over all possible transforms in order, adding the ones that
|
|
3114
3123
|
* are present to the transform string.
|
|
@@ -3118,24 +3127,11 @@ function buildTransform$1(latestValues, transform, transformTemplate) {
|
|
|
3118
3127
|
const value = latestValues[key];
|
|
3119
3128
|
if (value === undefined)
|
|
3120
3129
|
continue;
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
const parsed = parseFloat(value);
|
|
3127
|
-
valueIsDefault = key.startsWith("scale") ? parsed === 1 : parsed === 0;
|
|
3128
|
-
}
|
|
3129
|
-
if (!valueIsDefault || transformTemplate) {
|
|
3130
|
-
const valueAsType = getValueAsType(value, numberValueTypes[key]);
|
|
3131
|
-
if (!valueIsDefault) {
|
|
3132
|
-
transformIsDefault = false;
|
|
3133
|
-
const transformName = translateAlias[key] || key;
|
|
3134
|
-
transformString += `${transformName}(${valueAsType}) `;
|
|
3135
|
-
}
|
|
3136
|
-
if (transformTemplate) {
|
|
3137
|
-
transform[key] = valueAsType;
|
|
3138
|
-
}
|
|
3130
|
+
const valueAsType = transformTemplate &&
|
|
3131
|
+
(transform[key] = getValueAsType(value, numberValueTypes[key]));
|
|
3132
|
+
if (!isDefaultTransform(key, value)) {
|
|
3133
|
+
transformString +=
|
|
3134
|
+
transformFunction(key, value, valueAsType || undefined) + " ";
|
|
3139
3135
|
}
|
|
3140
3136
|
}
|
|
3141
3137
|
// `pathRotation` composes onto `rotate` as a separate additive term so
|
|
@@ -3143,19 +3139,14 @@ function buildTransform$1(latestValues, transform, transformTemplate) {
|
|
|
3143
3139
|
// `transformPropOrder`.
|
|
3144
3140
|
const pathRotation = latestValues.pathRotation;
|
|
3145
3141
|
if (pathRotation) {
|
|
3146
|
-
|
|
3147
|
-
transformString += `rotate(${getValueAsType(pathRotation, numberValueTypes.pathRotation)}) `;
|
|
3142
|
+
transformString += transformFunction("rotate", pathRotation);
|
|
3148
3143
|
}
|
|
3149
3144
|
transformString = transformString.trim();
|
|
3150
3145
|
// If we have a custom `transform` template, pass our transform values and
|
|
3151
3146
|
// generated transformString to that before returning
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
else if (transformIsDefault) {
|
|
3156
|
-
transformString = "none";
|
|
3157
|
-
}
|
|
3158
|
-
return transformString;
|
|
3147
|
+
return transformTemplate
|
|
3148
|
+
? transformTemplate(transform, transformString)
|
|
3149
|
+
: transformString || "none";
|
|
3159
3150
|
}
|
|
3160
3151
|
|
|
3161
3152
|
const transformGroups = new WeakMap();
|
|
@@ -3497,27 +3488,30 @@ function createGroup(owner) {
|
|
|
3497
3488
|
return values;
|
|
3498
3489
|
};
|
|
3499
3490
|
/**
|
|
3500
|
-
* Build
|
|
3501
|
-
* is written, even at its default, so each keyframe has the
|
|
3502
|
-
* 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.
|
|
3503
3495
|
*/
|
|
3504
|
-
const
|
|
3496
|
+
const toTransform = (values, isStyle) => {
|
|
3505
3497
|
let transform = "";
|
|
3506
|
-
const values = valuesAt(timestamp, settled);
|
|
3507
3498
|
for (const key in values) {
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
") ";
|
|
3499
|
+
const value = values[key];
|
|
3500
|
+
if (!isStyle || !isDefaultTransform(key, value)) {
|
|
3501
|
+
transform += transformFunction(key, value) + " ";
|
|
3502
|
+
}
|
|
3513
3503
|
}
|
|
3514
|
-
return transform || "none";
|
|
3504
|
+
return (isStyle ? transform.trim() : transform) || "none";
|
|
3515
3505
|
};
|
|
3506
|
+
/**
|
|
3507
|
+
* Build the transform at a timestamp.
|
|
3508
|
+
*/
|
|
3509
|
+
const compose = (timestamp, settled) => toTransform(valuesAt(timestamp, settled));
|
|
3516
3510
|
/**
|
|
3517
3511
|
* Write the transform as an inline style, as the renderer would.
|
|
3518
3512
|
*/
|
|
3519
3513
|
const commit = (values = valuesAt()) => {
|
|
3520
|
-
element.style.transform =
|
|
3514
|
+
element.style.transform = toTransform(values, true);
|
|
3521
3515
|
};
|
|
3522
3516
|
/**
|
|
3523
3517
|
* Cancel the WAAPI animations, by default first committing the
|
|
@@ -3528,6 +3522,13 @@ function createGroup(owner) {
|
|
|
3528
3522
|
segments.forEach(({ animation }) => animation.cancel());
|
|
3529
3523
|
segments = [];
|
|
3530
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));
|
|
3531
3532
|
const add = (animation, offset, end = Infinity) => {
|
|
3532
3533
|
const segment = { animation, offset, end };
|
|
3533
3534
|
animation.startTime = time.now() + offset;
|
|
@@ -3720,7 +3721,7 @@ function createGroup(owner) {
|
|
|
3720
3721
|
commit(valuesAt(from, settled));
|
|
3721
3722
|
keyframes = null;
|
|
3722
3723
|
}
|
|
3723
|
-
return
|
|
3724
|
+
return create(keyframes, {
|
|
3724
3725
|
...options,
|
|
3725
3726
|
duration: to - from,
|
|
3726
3727
|
easing: easing || "linear",
|
|
@@ -3810,9 +3811,7 @@ function createGroup(owner) {
|
|
|
3810
3811
|
* empty animations that end with them.
|
|
3811
3812
|
*/
|
|
3812
3813
|
ends.forEach((trackEnd) => trackEnd < end - 1 &&
|
|
3813
|
-
add(
|
|
3814
|
-
duration: trackEnd - now,
|
|
3815
|
-
}), 0, trackEnd - now));
|
|
3814
|
+
add(create(null, { duration: trackEnd - now }), 0, trackEnd - now));
|
|
3816
3815
|
}
|
|
3817
3816
|
if (cycle) {
|
|
3818
3817
|
/**
|
|
@@ -3886,12 +3885,29 @@ function createGroup(owner) {
|
|
|
3886
3885
|
if (isDone)
|
|
3887
3886
|
continue;
|
|
3888
3887
|
const local = elapsed - offset;
|
|
3889
|
-
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) {
|
|
3890
3901
|
animation.playbackRate = rate;
|
|
3891
3902
|
animation.startTime = now - local / rate;
|
|
3892
3903
|
}
|
|
3893
3904
|
else {
|
|
3894
|
-
|
|
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;
|
|
3895
3911
|
animation.currentTime = local;
|
|
3896
3912
|
}
|
|
3897
3913
|
}
|
|
@@ -4082,9 +4098,8 @@ class AsyncMotionValueAnimation extends WithPromise {
|
|
|
4082
4098
|
* If we can't animate this value with the resolved keyframes
|
|
4083
4099
|
* then we should complete it immediately.
|
|
4084
4100
|
*/
|
|
4085
|
-
|
|
4086
|
-
if (!
|
|
4087
|
-
canAnimateValue = false;
|
|
4101
|
+
const canAnimateValue = canAnimate(keyframes, name, type, velocity);
|
|
4102
|
+
if (!canAnimateValue) {
|
|
4088
4103
|
if (motionUtils.MotionGlobalConfig.instantAnimations || !delay) {
|
|
4089
4104
|
onUpdate?.(getFinalKeyframe(keyframes, options, finalKeyframe));
|
|
4090
4105
|
}
|
|
@@ -4228,9 +4243,7 @@ class AsyncMotionValueAnimation extends WithPromise {
|
|
|
4228
4243
|
this.animation.complete();
|
|
4229
4244
|
}
|
|
4230
4245
|
cancel() {
|
|
4231
|
-
|
|
4232
|
-
this.animation.cancel();
|
|
4233
|
-
}
|
|
4246
|
+
this._animation?.cancel();
|
|
4234
4247
|
this.keyframeResolver?.cancel();
|
|
4235
4248
|
}
|
|
4236
4249
|
}
|
|
@@ -4413,7 +4426,7 @@ class MotionValue {
|
|
|
4413
4426
|
this.setCurrent(v);
|
|
4414
4427
|
// Update update subscribers
|
|
4415
4428
|
if (this.current !== this.prev) {
|
|
4416
|
-
this.
|
|
4429
|
+
this.dirty();
|
|
4417
4430
|
if (this.dependents) {
|
|
4418
4431
|
for (const dependent of this.dependents) {
|
|
4419
4432
|
dependent.dirty();
|
|
@@ -4551,12 +4564,9 @@ class MotionValue {
|
|
|
4551
4564
|
* @public
|
|
4552
4565
|
*/
|
|
4553
4566
|
set(v) {
|
|
4554
|
-
|
|
4555
|
-
this.
|
|
4556
|
-
|
|
4557
|
-
else {
|
|
4558
|
-
this.passiveEffect(v, this.updateAndNotify);
|
|
4559
|
-
}
|
|
4567
|
+
this.passiveEffect
|
|
4568
|
+
? this.passiveEffect(v, this.updateAndNotify)
|
|
4569
|
+
: this.updateAndNotify(v);
|
|
4560
4570
|
}
|
|
4561
4571
|
setWithVelocity(prev, current, delta) {
|
|
4562
4572
|
this.set(current);
|
|
@@ -4573,13 +4583,9 @@ class MotionValue {
|
|
|
4573
4583
|
this.prev = v;
|
|
4574
4584
|
this.prevUpdatedAt = this.prevFrameValue = undefined;
|
|
4575
4585
|
endAnimation && this.stop();
|
|
4576
|
-
|
|
4577
|
-
this.stopPassiveEffect();
|
|
4586
|
+
this.stopPassiveEffect?.();
|
|
4578
4587
|
}
|
|
4579
4588
|
dirty() {
|
|
4580
|
-
this.notifyChange();
|
|
4581
|
-
}
|
|
4582
|
-
notifyChange() {
|
|
4583
4589
|
const { current, changeSubscriber } = this;
|
|
4584
4590
|
/**
|
|
4585
4591
|
* One or the other exists. Subscribing during the direct
|
|
@@ -4594,15 +4600,10 @@ class MotionValue {
|
|
|
4594
4600
|
}
|
|
4595
4601
|
}
|
|
4596
4602
|
addDependent(dependent) {
|
|
4597
|
-
|
|
4598
|
-
this.dependents = new Set();
|
|
4599
|
-
}
|
|
4600
|
-
this.dependents.add(dependent);
|
|
4603
|
+
(this.dependents || (this.dependents = new Set())).add(dependent);
|
|
4601
4604
|
}
|
|
4602
4605
|
removeDependent(dependent) {
|
|
4603
|
-
|
|
4604
|
-
this.dependents.delete(dependent);
|
|
4605
|
-
}
|
|
4606
|
+
this.dependents?.delete(dependent);
|
|
4606
4607
|
}
|
|
4607
4608
|
/**
|
|
4608
4609
|
* Returns the latest state of `MotionValue`
|
|
@@ -4612,9 +4613,7 @@ class MotionValue {
|
|
|
4612
4613
|
* @public
|
|
4613
4614
|
*/
|
|
4614
4615
|
get() {
|
|
4615
|
-
|
|
4616
|
-
collectMotionValues.current.push(this);
|
|
4617
|
-
}
|
|
4616
|
+
collectMotionValues.current?.push(this);
|
|
4618
4617
|
/**
|
|
4619
4618
|
* A value animating on the compositor isn't updated every frame,
|
|
4620
4619
|
* so read it from its animation.
|
|
@@ -4680,7 +4679,7 @@ class MotionValue {
|
|
|
4680
4679
|
isComplete = true;
|
|
4681
4680
|
this.events.animationComplete?.notify();
|
|
4682
4681
|
if (this.animation === animation)
|
|
4683
|
-
this.
|
|
4682
|
+
this.animation = undefined;
|
|
4684
4683
|
resolve();
|
|
4685
4684
|
});
|
|
4686
4685
|
if (!isComplete)
|
|
@@ -4696,11 +4695,10 @@ class MotionValue {
|
|
|
4696
4695
|
stop() {
|
|
4697
4696
|
if (this.animation) {
|
|
4698
4697
|
this.animation.stop();
|
|
4699
|
-
|
|
4700
|
-
this.events.animationCancel.notify();
|
|
4701
|
-
}
|
|
4698
|
+
this.events.animationCancel?.notify();
|
|
4702
4699
|
}
|
|
4703
|
-
|
|
4700
|
+
// Assign rather than delete to keep the object's shape stable
|
|
4701
|
+
this.animation = undefined;
|
|
4704
4702
|
}
|
|
4705
4703
|
/**
|
|
4706
4704
|
* Returns `true` if this value is currently animating.
|
|
@@ -4710,10 +4708,6 @@ class MotionValue {
|
|
|
4710
4708
|
isAnimating() {
|
|
4711
4709
|
return !!this.animation;
|
|
4712
4710
|
}
|
|
4713
|
-
clearAnimation() {
|
|
4714
|
-
// Assign rather than delete to keep the object's shape stable
|
|
4715
|
-
this.animation = undefined;
|
|
4716
|
-
}
|
|
4717
4711
|
/**
|
|
4718
4712
|
* Destroy and clean up subscribers to this `MotionValue`.
|
|
4719
4713
|
*
|
|
@@ -4728,9 +4722,7 @@ class MotionValue {
|
|
|
4728
4722
|
this.events.destroy?.notify();
|
|
4729
4723
|
this.clearListeners();
|
|
4730
4724
|
this.stop();
|
|
4731
|
-
|
|
4732
|
-
this.stopPassiveEffect();
|
|
4733
|
-
}
|
|
4725
|
+
this.stopPassiveEffect?.();
|
|
4734
4726
|
}
|
|
4735
4727
|
}
|
|
4736
4728
|
function motionValue(init, options) {
|
|
@@ -4808,6 +4800,7 @@ const orchestrationKeys = new Set([
|
|
|
4808
4800
|
"repeatDelay",
|
|
4809
4801
|
"from",
|
|
4810
4802
|
"elapsed",
|
|
4803
|
+
"out",
|
|
4811
4804
|
]);
|
|
4812
4805
|
/**
|
|
4813
4806
|
* Decide whether a transition is defined on a given Transition.
|
|
@@ -5119,7 +5112,8 @@ function parseCSSVariable(current) {
|
|
|
5119
5112
|
}
|
|
5120
5113
|
const maxDepth = 4;
|
|
5121
5114
|
function getVariableValue(current, element, depth = 1) {
|
|
5122
|
-
|
|
5115
|
+
process.env.NODE_ENV !== "production" &&
|
|
5116
|
+
motionUtils.invariant(depth <= maxDepth, `Max CSS variable fallback depth detected in property "${current}". This may indicate a circular fallback dependency.`, "max-css-var-depth");
|
|
5123
5117
|
const [token, fallback] = parseCSSVariable(current);
|
|
5124
5118
|
// No CSS variable detected
|
|
5125
5119
|
if (!token)
|
|
@@ -5230,12 +5224,8 @@ function addValueToWillChange(visualElement, key) {
|
|
|
5230
5224
|
}
|
|
5231
5225
|
}
|
|
5232
5226
|
|
|
5233
|
-
function camelToDash(str) {
|
|
5234
|
-
return str.replace(/([A-Z])/g, (match) => `-${match.toLowerCase()}`);
|
|
5235
|
-
}
|
|
5236
|
-
|
|
5237
5227
|
const optimizedAppearDataId = "framerAppearId";
|
|
5238
|
-
const optimizedAppearDataAttribute = "data-"
|
|
5228
|
+
const optimizedAppearDataAttribute = "data-framer-appear-id";
|
|
5239
5229
|
|
|
5240
5230
|
function getOptimisedAppearId(visualElement) {
|
|
5241
5231
|
return visualElement.props[optimizedAppearDataAttribute];
|
|
@@ -5282,7 +5272,7 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
|
|
|
5282
5272
|
}
|
|
5283
5273
|
const valueTransition = {
|
|
5284
5274
|
delay,
|
|
5285
|
-
...getValueTransition(transition || {}, key),
|
|
5275
|
+
...getValueTransition(animationTypeState?.out[key] || transition || {}, key),
|
|
5286
5276
|
};
|
|
5287
5277
|
if (skipAnimations)
|
|
5288
5278
|
valueTransition.skipAnimations = true;
|
|
@@ -5452,8 +5442,9 @@ function makeNoneKeyframesAnimatable(unresolvedKeyframes, noneKeyframeIndexes, n
|
|
|
5452
5442
|
}
|
|
5453
5443
|
|
|
5454
5444
|
class DOMKeyframesResolver extends KeyframeResolver {
|
|
5455
|
-
constructor(
|
|
5456
|
-
super(
|
|
5445
|
+
constructor() {
|
|
5446
|
+
super(...arguments);
|
|
5447
|
+
this.isAsync = true;
|
|
5457
5448
|
}
|
|
5458
5449
|
/**
|
|
5459
5450
|
* Keyframes that don't need reading from the DOM, or measuring,
|
|
@@ -5481,7 +5472,7 @@ class DOMKeyframesResolver extends KeyframeResolver {
|
|
|
5481
5472
|
}
|
|
5482
5473
|
readKeyframes() {
|
|
5483
5474
|
const { unresolvedKeyframes, element, name } = this;
|
|
5484
|
-
if (!element
|
|
5475
|
+
if (!element?.current)
|
|
5485
5476
|
return;
|
|
5486
5477
|
super.readKeyframes();
|
|
5487
5478
|
/**
|
|
@@ -5576,11 +5567,10 @@ class DOMKeyframesResolver extends KeyframeResolver {
|
|
|
5576
5567
|
}
|
|
5577
5568
|
measureInitialState() {
|
|
5578
5569
|
const { element, unresolvedKeyframes, name } = this;
|
|
5579
|
-
if (!element
|
|
5570
|
+
if (!element?.current)
|
|
5580
5571
|
return;
|
|
5581
|
-
if (name === "height")
|
|
5572
|
+
if (name === "height")
|
|
5582
5573
|
this.suspendedScrollY = window.pageYOffset;
|
|
5583
|
-
}
|
|
5584
5574
|
this.measuredOrigin = this.measure();
|
|
5585
5575
|
unresolvedKeyframes[0] = this.measuredOrigin;
|
|
5586
5576
|
// Set final key frame to measure after next render
|
|
@@ -5591,7 +5581,7 @@ class DOMKeyframesResolver extends KeyframeResolver {
|
|
|
5591
5581
|
}
|
|
5592
5582
|
measureEndState() {
|
|
5593
5583
|
const { element, unresolvedKeyframes } = this;
|
|
5594
|
-
if (!element
|
|
5584
|
+
if (!element?.current)
|
|
5595
5585
|
return;
|
|
5596
5586
|
this.motionValue?.jump(this.measuredOrigin, false);
|
|
5597
5587
|
const finalKeyframeIndex = unresolvedKeyframes.length - 1;
|
|
@@ -5600,14 +5590,6 @@ class DOMKeyframesResolver extends KeyframeResolver {
|
|
|
5600
5590
|
if (finalKeyframe !== null && this.finalKeyframe === undefined) {
|
|
5601
5591
|
this.finalKeyframe = finalKeyframe;
|
|
5602
5592
|
}
|
|
5603
|
-
// If we removed transform values, reapply them before the next render
|
|
5604
|
-
if (this.removedTransforms?.length) {
|
|
5605
|
-
this.removedTransforms.forEach(([unsetTransformName, unsetTransformValue]) => {
|
|
5606
|
-
element
|
|
5607
|
-
.getValue(unsetTransformName)
|
|
5608
|
-
.set(unsetTransformValue);
|
|
5609
|
-
});
|
|
5610
|
-
}
|
|
5611
5593
|
this.resolveNoneKeyframes();
|
|
5612
5594
|
}
|
|
5613
5595
|
}
|
|
@@ -5712,7 +5694,9 @@ const supportsPartialKeyframes = /*@__PURE__*/ motionUtils.memo(() => {
|
|
|
5712
5694
|
*/
|
|
5713
5695
|
const effects = [];
|
|
5714
5696
|
function addEffect(effect) {
|
|
5715
|
-
|
|
5697
|
+
process.env.NODE_ENV !== "production" &&
|
|
5698
|
+
motionUtils.invariant(typeof effect.test === "function" &&
|
|
5699
|
+
typeof effect.read === "function", "Effects passed to animate.addEffect() need test() and read().", "effect-missing-test");
|
|
5716
5700
|
removeEffect(effect);
|
|
5717
5701
|
effects.unshift(effect);
|
|
5718
5702
|
}
|
|
@@ -5799,7 +5783,8 @@ function animateEffectSubject(effect, subject, keyframes, transition, element) {
|
|
|
5799
5783
|
initial =
|
|
5800
5784
|
firstKeyframe(target) ??
|
|
5801
5785
|
effect.read(subject, key, target);
|
|
5802
|
-
|
|
5786
|
+
process.env.NODE_ENV !== "production" &&
|
|
5787
|
+
motionUtils.invariant(initial !== undefined, `"${key}" can't be read from the animated subject. Provide [from, to] keyframes.`, "effect-unreadable-value");
|
|
5803
5788
|
}
|
|
5804
5789
|
value = motionValue(initial, { owner: element });
|
|
5805
5790
|
effect(subject, { [key]: value });
|
|
@@ -6039,11 +6024,6 @@ function createEffect(addValue, { step, ...options } = {}) {
|
|
|
6039
6024
|
});
|
|
6040
6025
|
}
|
|
6041
6026
|
|
|
6042
|
-
/**
|
|
6043
|
-
* Cache of `translateX(`-style openers so each render is a few string
|
|
6044
|
-
* concatenations rather than a template per transform.
|
|
6045
|
-
*/
|
|
6046
|
-
const openers = {};
|
|
6047
6027
|
function buildTransform(state) {
|
|
6048
6028
|
let transform = "";
|
|
6049
6029
|
const { transformKeys: keys = [], transformValues: values = {} } = state;
|
|
@@ -6056,14 +6036,8 @@ function buildTransform(state) {
|
|
|
6056
6036
|
const value = values[key].getCurrent();
|
|
6057
6037
|
if (value === undefined)
|
|
6058
6038
|
continue;
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
transform +=
|
|
6062
|
-
(transform && " ") +
|
|
6063
|
-
(openers[key] ||
|
|
6064
|
-
(openers[key] = (translateAlias[key] || key) + "(")) +
|
|
6065
|
-
getValueAsType(value, transformValueTypes[key]) +
|
|
6066
|
-
")";
|
|
6039
|
+
if (!isDefaultTransform(key, value)) {
|
|
6040
|
+
transform += (transform && " ") + transformFunction(key, value);
|
|
6067
6041
|
}
|
|
6068
6042
|
}
|
|
6069
6043
|
// See build-transform.ts: additive `rotate()` so user `rotate` isn't
|
|
@@ -6071,10 +6045,7 @@ function buildTransform(state) {
|
|
|
6071
6045
|
const pathRotation = state.get("pathRotation")?.get();
|
|
6072
6046
|
if (pathRotation) {
|
|
6073
6047
|
transform +=
|
|
6074
|
-
(transform && " ") +
|
|
6075
|
-
"rotate(" +
|
|
6076
|
-
getValueAsType(pathRotation, transformValueTypes.pathRotation) +
|
|
6077
|
-
")";
|
|
6048
|
+
(transform && " ") + transformFunction("rotate", pathRotation);
|
|
6078
6049
|
}
|
|
6079
6050
|
return transform || "none";
|
|
6080
6051
|
}
|
|
@@ -6163,6 +6134,10 @@ const styleSubjectEffect = /*@__PURE__*/ createEffect(addStyleValue, {
|
|
|
6163
6134
|
const styleEffect =
|
|
6164
6135
|
/*@__PURE__*/ createSelectorEffect(styleSubjectEffect);
|
|
6165
6136
|
|
|
6137
|
+
function camelToDash(str) {
|
|
6138
|
+
return str.replace(/([A-Z])/g, (match) => `-${match.toLowerCase()}`);
|
|
6139
|
+
}
|
|
6140
|
+
|
|
6166
6141
|
function buildHTMLStyles(state, latestValues, transformTemplate) {
|
|
6167
6142
|
const { style, vars, transformOrigin } = state;
|
|
6168
6143
|
// Track whether we encounter any transform or transformOrigin values.
|
|
@@ -6473,10 +6448,24 @@ function hasScale({ scale, scaleX, scaleY }) {
|
|
|
6473
6448
|
!isIdentityScale(scaleX) ||
|
|
6474
6449
|
!isIdentityScale(scaleY));
|
|
6475
6450
|
}
|
|
6451
|
+
/**
|
|
6452
|
+
* Rotations and skews, which projection can't correct for.
|
|
6453
|
+
*/
|
|
6454
|
+
const angleTransforms = [
|
|
6455
|
+
"rotate",
|
|
6456
|
+
"rotateX",
|
|
6457
|
+
"rotateY",
|
|
6458
|
+
"rotateZ",
|
|
6459
|
+
"skewX",
|
|
6460
|
+
"skewY",
|
|
6461
|
+
];
|
|
6476
6462
|
function hasTransform(values) {
|
|
6477
6463
|
return (hasScale(values) ||
|
|
6478
6464
|
has2DTranslate(values) ||
|
|
6479
|
-
values
|
|
6465
|
+
hasDistortingTransform(values));
|
|
6466
|
+
}
|
|
6467
|
+
function hasDistortingTransform(values) {
|
|
6468
|
+
return (values.z ||
|
|
6480
6469
|
values.rotate ||
|
|
6481
6470
|
values.rotateX ||
|
|
6482
6471
|
values.rotateY ||
|
|
@@ -6529,6 +6518,11 @@ const TREE_SCALE_SNAP_MAX = 1.0000000000001;
|
|
|
6529
6518
|
* in a tree upon our box before then calculating how to project it into our desired viewport-relative box
|
|
6530
6519
|
*
|
|
6531
6520
|
* This is the final nested loop within updateLayoutDelta for future refactoring
|
|
6521
|
+
*
|
|
6522
|
+
* isSharedTransition is true for a shared layout animation in page space, which
|
|
6523
|
+
* also applies ancestor scroll and transforms. Or it's the layoutRoot a shared
|
|
6524
|
+
* animation is relative to, so only transforms of ancestors not shared with it
|
|
6525
|
+
* (or above it) are applied.
|
|
6532
6526
|
*/
|
|
6533
6527
|
function applyTreeDeltas(box, treeScale, treePath, isSharedTransition = false) {
|
|
6534
6528
|
const treeLength = treePath.length;
|
|
@@ -6545,13 +6539,10 @@ function applyTreeDeltas(box, treeScale, treePath, isSharedTransition = false) {
|
|
|
6545
6539
|
* TODO: Prefer to remove this, but currently we have motion components with
|
|
6546
6540
|
* display: contents in Framer.
|
|
6547
6541
|
*/
|
|
6548
|
-
|
|
6549
|
-
if (visualElement &&
|
|
6550
|
-
visualElement.props.style &&
|
|
6551
|
-
visualElement.props.style.display === "contents") {
|
|
6542
|
+
if (node.options.visualElement?.props.style?.display === "contents") {
|
|
6552
6543
|
continue;
|
|
6553
6544
|
}
|
|
6554
|
-
if (isSharedTransition &&
|
|
6545
|
+
if (isSharedTransition === true &&
|
|
6555
6546
|
node.options.layoutScroll &&
|
|
6556
6547
|
node.scroll &&
|
|
6557
6548
|
node !== node.root) {
|
|
@@ -6565,7 +6556,9 @@ function applyTreeDeltas(box, treeScale, treePath, isSharedTransition = false) {
|
|
|
6565
6556
|
// Apply each ancestor's calculated delta into this component's recorded layout box
|
|
6566
6557
|
applyBoxDelta(box, delta);
|
|
6567
6558
|
}
|
|
6568
|
-
if (isSharedTransition &&
|
|
6559
|
+
if (isSharedTransition &&
|
|
6560
|
+
(isSharedTransition.path?.[i] || isSharedTransition) !== node &&
|
|
6561
|
+
hasTransform(node.latestValues)) {
|
|
6569
6562
|
transformBox(box, node.latestValues, node.layout?.layoutBox);
|
|
6570
6563
|
}
|
|
6571
6564
|
}
|
|
@@ -6738,6 +6731,41 @@ const propEffect = /*@__PURE__*/ createEffect((subject, state, key, value) => {
|
|
|
6738
6731
|
const { schedule: microtask, cancel: cancelMicrotask } =
|
|
6739
6732
|
/* @__PURE__ */ createRenderBatcher(queueMicrotask, false);
|
|
6740
6733
|
|
|
6734
|
+
/**
|
|
6735
|
+
* Process a frame now, for driving Motion from a loop other than
|
|
6736
|
+
* window.requestAnimationFrame, like an XRSession's during an immersive
|
|
6737
|
+
* WebXR session. Wherever window.requestAnimationFrame does fire, Motion
|
|
6738
|
+
* keeps processing frames from it too.
|
|
6739
|
+
*
|
|
6740
|
+
* `timestamp` defaults to now. For a timeline you control, set
|
|
6741
|
+
* `MotionGlobalConfig.useManualTiming = true` and pass each frame's time in
|
|
6742
|
+
* milliseconds.
|
|
6743
|
+
*
|
|
6744
|
+
* Animations Motion hands to the browser (WAAPI), like `opacity` or
|
|
6745
|
+
* `transform` on an HTML or SVG element, follow the browser's clock. With
|
|
6746
|
+
* `useManualTiming` on, Motion runs those in JS instead, except for
|
|
6747
|
+
* `motion/mini`, view transitions and optimized appear animations, and
|
|
6748
|
+
* colours only the browser can mix, like `oklch()`, which jump to their end.
|
|
6749
|
+
*
|
|
6750
|
+
* Ignored when called inside a frame.
|
|
6751
|
+
*/
|
|
6752
|
+
const processFrame = (timestamp = time.now()) => {
|
|
6753
|
+
if (frameData.isProcessing)
|
|
6754
|
+
return;
|
|
6755
|
+
const delta = timestamp - frameData.timestamp;
|
|
6756
|
+
// Clamp like the requestAnimationFrame loop, unless the timeline is ours
|
|
6757
|
+
frameData.delta = motionUtils.MotionGlobalConfig.useManualTiming
|
|
6758
|
+
? delta
|
|
6759
|
+
: Math.max(Math.min(delta, 40), 1);
|
|
6760
|
+
time.set((frameData.timestamp = timestamp));
|
|
6761
|
+
frameData.isProcessing = true;
|
|
6762
|
+
// frameSteps' keys are in stepsOrder
|
|
6763
|
+
for (const step in frameSteps) {
|
|
6764
|
+
frameSteps[step].process(frameData);
|
|
6765
|
+
}
|
|
6766
|
+
frameData.isProcessing = false;
|
|
6767
|
+
};
|
|
6768
|
+
|
|
6741
6769
|
function animateSingleValue(value, keyframes, options) {
|
|
6742
6770
|
const motionValue$1 = isMotionValue(value) ? value : motionValue(value);
|
|
6743
6771
|
motionValue$1.start(animateMotionValue("", motionValue$1, keyframes, options));
|
|
@@ -6804,15 +6832,6 @@ function resolveMotionValue(value) {
|
|
|
6804
6832
|
const asNumber = (v) => typeof v === "number" ? v : parseFloat(v);
|
|
6805
6833
|
|
|
6806
6834
|
const numBorders = cornerRadiusProps.length;
|
|
6807
|
-
const mixedTransforms = [
|
|
6808
|
-
"rotate",
|
|
6809
|
-
"rotateX",
|
|
6810
|
-
"rotateY",
|
|
6811
|
-
"rotateZ",
|
|
6812
|
-
"skewX",
|
|
6813
|
-
"skewY",
|
|
6814
|
-
];
|
|
6815
|
-
const numMixedTransforms = mixedTransforms.length;
|
|
6816
6835
|
const isPx = (value) => typeof value === "number" || px.test(value);
|
|
6817
6836
|
function mixValues(target, follow, lead, progress, shouldCrossfadeOpacity, isOnlyMember) {
|
|
6818
6837
|
if (shouldCrossfadeOpacity) {
|
|
@@ -6850,8 +6869,8 @@ function mixValues(target, follow, lead, progress, shouldCrossfadeOpacity, isOnl
|
|
|
6850
6869
|
* Mix rotation and skew. These can't be projected, so mix them every
|
|
6851
6870
|
* frame rather than leaving them frozen at the animation-start snapshot.
|
|
6852
6871
|
*/
|
|
6853
|
-
for (let i = 0; i <
|
|
6854
|
-
const key =
|
|
6872
|
+
for (let i = 0; i < angleTransforms.length; i++) {
|
|
6873
|
+
const key = angleTransforms[i];
|
|
6855
6874
|
if (follow[key] || lead[key]) {
|
|
6856
6875
|
target[key] = mixNumber$1(follow[key] || 0, lead[key] || 0, progress);
|
|
6857
6876
|
}
|
|
@@ -6934,8 +6953,8 @@ function calcAxisDelta(delta, source, target, origin = 0.5) {
|
|
|
6934
6953
|
}
|
|
6935
6954
|
}
|
|
6936
6955
|
function calcBoxDelta(delta, source, target, origin) {
|
|
6937
|
-
calcAxisDelta(delta.x, source.x, target.x, origin
|
|
6938
|
-
calcAxisDelta(delta.y, source.y, target.y, origin
|
|
6956
|
+
calcAxisDelta(delta.x, source.x, target.x, origin?.originX);
|
|
6957
|
+
calcAxisDelta(delta.y, source.y, target.y, origin?.originY);
|
|
6939
6958
|
}
|
|
6940
6959
|
function calcRelativeAxis(target, relative, parent, anchor = 0) {
|
|
6941
6960
|
const anchorPoint = anchor
|
|
@@ -7005,8 +7024,8 @@ const yKeys = ["y", "scaleY", "originY"];
|
|
|
7005
7024
|
* and acts as a bridge between motion values and removeAxisDelta
|
|
7006
7025
|
*/
|
|
7007
7026
|
function removeBoxTransforms(box, transforms, originBox, sourceBox) {
|
|
7008
|
-
removeAxisTransforms(box.x, transforms, xKeys, originBox
|
|
7009
|
-
removeAxisTransforms(box.y, transforms, yKeys, originBox
|
|
7027
|
+
removeAxisTransforms(box.x, transforms, xKeys, originBox?.x, sourceBox?.x);
|
|
7028
|
+
removeAxisTransforms(box.y, transforms, yKeys, originBox?.y, sourceBox?.y);
|
|
7010
7029
|
}
|
|
7011
7030
|
|
|
7012
7031
|
const createAxisDelta = () => ({
|
|
@@ -7204,10 +7223,9 @@ const correctBoxShadow = {
|
|
|
7204
7223
|
};
|
|
7205
7224
|
|
|
7206
7225
|
const defaultScaleCorrectors = {
|
|
7207
|
-
borderRadius: {
|
|
7208
|
-
|
|
7209
|
-
|
|
7210
|
-
},
|
|
7226
|
+
borderRadius: /* @__PURE__ */ Object.assign({}, correctBorderRadius, {
|
|
7227
|
+
applyTo: /* @__PURE__ */ cornerRadiusProps.slice(),
|
|
7228
|
+
}),
|
|
7211
7229
|
borderTopLeftRadius: correctBorderRadius,
|
|
7212
7230
|
borderTopRightRadius: correctBorderRadius,
|
|
7213
7231
|
borderBottomLeftRadius: correctBorderRadius,
|
|
@@ -7237,24 +7255,18 @@ function buildProjectionTransform(delta, treeScale, latestTransform) {
|
|
|
7237
7255
|
transform += `scale(${1 / treeScale.x}, ${1 / treeScale.y}) `;
|
|
7238
7256
|
}
|
|
7239
7257
|
if (latestTransform) {
|
|
7240
|
-
const { transformPerspective
|
|
7258
|
+
const { transformPerspective } = latestTransform;
|
|
7241
7259
|
if (transformPerspective)
|
|
7242
7260
|
transform = `perspective(${transformPerspective}px) ${transform}`;
|
|
7243
|
-
|
|
7244
|
-
|
|
7245
|
-
|
|
7246
|
-
|
|
7247
|
-
|
|
7248
|
-
|
|
7249
|
-
|
|
7250
|
-
|
|
7251
|
-
|
|
7252
|
-
if (rotateZ)
|
|
7253
|
-
transform += `rotateZ(${rotateZ}deg) `;
|
|
7254
|
-
if (skewX)
|
|
7255
|
-
transform += `skewX(${skewX}deg) `;
|
|
7256
|
-
if (skewY)
|
|
7257
|
-
transform += `skewY(${skewY}deg) `;
|
|
7261
|
+
for (let i = 0; i < angleTransforms.length; i++) {
|
|
7262
|
+
const key = angleTransforms[i];
|
|
7263
|
+
const value = latestTransform[key];
|
|
7264
|
+
if (value)
|
|
7265
|
+
transform += `${key}(${value}deg) `;
|
|
7266
|
+
// Additive `rotate()` so user `rotate` isn't clobbered.
|
|
7267
|
+
if (!i && latestTransform.pathRotation)
|
|
7268
|
+
transform += `rotate(${latestTransform.pathRotation}deg) `;
|
|
7269
|
+
}
|
|
7258
7270
|
}
|
|
7259
7271
|
/**
|
|
7260
7272
|
* Apply scale to match the size of the element to the size we want it.
|
|
@@ -7312,20 +7324,15 @@ const globalProjectionState = {
|
|
|
7312
7324
|
hasEverUpdated: false,
|
|
7313
7325
|
};
|
|
7314
7326
|
|
|
7315
|
-
/**
|
|
7316
|
-
* Correctors registered via addScaleCorrector before projection loaded
|
|
7317
|
-
* (e.g. with an async LazyMotion bundle) take precedence over the defaults.
|
|
7318
|
-
*/
|
|
7319
|
-
Object.assign(scaleCorrectors, {
|
|
7320
|
-
...defaultScaleCorrectors,
|
|
7321
|
-
...scaleCorrectors,
|
|
7322
|
-
});
|
|
7323
7327
|
const metrics = {
|
|
7324
7328
|
nodes: 0,
|
|
7325
7329
|
calculatedTargetDeltas: 0,
|
|
7326
7330
|
calculatedProjections: 0,
|
|
7327
7331
|
};
|
|
7328
|
-
|
|
7332
|
+
/**
|
|
7333
|
+
* Transforms that distort an element's layout, so must be reset before measuring.
|
|
7334
|
+
*/
|
|
7335
|
+
const distortingTransforms = ["z", "skew", "skewZ"];
|
|
7329
7336
|
/**
|
|
7330
7337
|
* We use 1000 as the animation target as 0-1000 maps better to pixels than 0-1
|
|
7331
7338
|
* which has a noticeable difference in spring animations
|
|
@@ -7362,6 +7369,16 @@ function cancelTreeOptimisedTransformAnimations(projectionNode) {
|
|
|
7362
7369
|
}
|
|
7363
7370
|
}
|
|
7364
7371
|
function createProjectionNode({ attachResizeListener, defaultParent, measureScroll, checkIsScrollRoot, resetTransform, }) {
|
|
7372
|
+
/**
|
|
7373
|
+
* Correctors registered via addScaleCorrector before projection loaded
|
|
7374
|
+
* (e.g. with an async LazyMotion bundle) take precedence over the defaults.
|
|
7375
|
+
* Applied here rather than at module scope so bundlers can drop projection
|
|
7376
|
+
* when it's unused.
|
|
7377
|
+
*/
|
|
7378
|
+
Object.assign(scaleCorrectors, {
|
|
7379
|
+
...defaultScaleCorrectors,
|
|
7380
|
+
...scaleCorrectors,
|
|
7381
|
+
});
|
|
7365
7382
|
return class ProjectionNode {
|
|
7366
7383
|
constructor(latestValues = {}, parent = defaultParent?.()) {
|
|
7367
7384
|
/**
|
|
@@ -7523,8 +7540,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
7523
7540
|
return this.eventHandlers.get(name).add(handler);
|
|
7524
7541
|
}
|
|
7525
7542
|
notifyListeners(name, ...args) {
|
|
7526
|
-
|
|
7527
|
-
subscriptionManager && subscriptionManager.notify(...args);
|
|
7543
|
+
this.eventHandlers.get(name)?.notify(...args);
|
|
7528
7544
|
}
|
|
7529
7545
|
hasListeners(name) {
|
|
7530
7546
|
return this.eventHandlers.has(name);
|
|
@@ -7542,7 +7558,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
7542
7558
|
visualElement.mount(instance);
|
|
7543
7559
|
}
|
|
7544
7560
|
this.root.nodes.add(this);
|
|
7545
|
-
this.parent
|
|
7561
|
+
this.parent?.children.add(this);
|
|
7546
7562
|
if (this.root.hasTreeAnimated && (layout || layoutId)) {
|
|
7547
7563
|
this.isLayoutDirty = true;
|
|
7548
7564
|
}
|
|
@@ -7560,7 +7576,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
7560
7576
|
return;
|
|
7561
7577
|
innerWidth = newInnerWidth;
|
|
7562
7578
|
this.root.updateBlockedByResize = true;
|
|
7563
|
-
cancelDelay
|
|
7579
|
+
cancelDelay?.();
|
|
7564
7580
|
cancelDelay = delay(resizeUnblockUpdate, 250);
|
|
7565
7581
|
if (globalProjectionState.hasAnimatedSinceResize) {
|
|
7566
7582
|
globalProjectionState.hasAnimatedSinceResize = false;
|
|
@@ -7651,9 +7667,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
7651
7667
|
if (!hasLayoutChanged) {
|
|
7652
7668
|
finishAnimation(this);
|
|
7653
7669
|
}
|
|
7654
|
-
|
|
7655
|
-
this.options.onExitComplete();
|
|
7656
|
-
}
|
|
7670
|
+
this.isLead() && this.options.onExitComplete?.();
|
|
7657
7671
|
}
|
|
7658
7672
|
this.targetLayout = newLayout;
|
|
7659
7673
|
});
|
|
@@ -7661,9 +7675,8 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
7661
7675
|
unmount() {
|
|
7662
7676
|
this.options.layoutId && this.willUpdate();
|
|
7663
7677
|
this.root.nodes.remove(this);
|
|
7664
|
-
|
|
7665
|
-
|
|
7666
|
-
this.parent && this.parent.children.delete(this);
|
|
7678
|
+
this.getStack()?.remove(this);
|
|
7679
|
+
this.parent?.children.delete(this);
|
|
7667
7680
|
this.instance = undefined;
|
|
7668
7681
|
this.eventHandlers.clear();
|
|
7669
7682
|
this.hasLayoutListener = false;
|
|
@@ -7684,7 +7697,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
7684
7697
|
if (this.isUpdateBlocked())
|
|
7685
7698
|
return;
|
|
7686
7699
|
this.isUpdating = true;
|
|
7687
|
-
this.nodes
|
|
7700
|
+
this.nodes?.forEach(resetSkewAndRotation);
|
|
7688
7701
|
this.animationId++;
|
|
7689
7702
|
}
|
|
7690
7703
|
getTransformTemplate() {
|
|
@@ -7694,7 +7707,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
7694
7707
|
willUpdate(shouldNotifyListeners = true) {
|
|
7695
7708
|
this.root.hasTreeAnimated = true;
|
|
7696
7709
|
if (this.root.isUpdateBlocked()) {
|
|
7697
|
-
this.options.onExitComplete
|
|
7710
|
+
this.options.onExitComplete?.();
|
|
7698
7711
|
return;
|
|
7699
7712
|
}
|
|
7700
7713
|
/**
|
|
@@ -7911,24 +7924,23 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
7911
7924
|
this.projectionDelta = undefined;
|
|
7912
7925
|
this.notifyListeners("measure", this.layout.layoutBox);
|
|
7913
7926
|
const { visualElement } = this.options;
|
|
7914
|
-
visualElement
|
|
7915
|
-
visualElement.notify("LayoutMeasure", this.layout.layoutBox, prevLayout ? prevLayout.layoutBox : undefined);
|
|
7927
|
+
visualElement?.notify("LayoutMeasure", this.layout.layoutBox, prevLayout?.layoutBox);
|
|
7916
7928
|
}
|
|
7917
7929
|
updateScroll(phase = "measure") {
|
|
7918
|
-
|
|
7919
|
-
|
|
7920
|
-
|
|
7921
|
-
|
|
7922
|
-
|
|
7923
|
-
|
|
7924
|
-
|
|
7925
|
-
const isRoot = checkIsScrollRoot(
|
|
7930
|
+
const { scroll, instance } = this;
|
|
7931
|
+
const { animationId } = this.root;
|
|
7932
|
+
if (this.options.layoutScroll &&
|
|
7933
|
+
instance &&
|
|
7934
|
+
!(scroll &&
|
|
7935
|
+
scroll.animationId === animationId &&
|
|
7936
|
+
scroll.phase === phase)) {
|
|
7937
|
+
const isRoot = checkIsScrollRoot(instance);
|
|
7926
7938
|
this.scroll = {
|
|
7927
|
-
animationId
|
|
7939
|
+
animationId,
|
|
7928
7940
|
phase,
|
|
7929
7941
|
isRoot,
|
|
7930
|
-
offset: measureScroll(
|
|
7931
|
-
wasRoot:
|
|
7942
|
+
offset: measureScroll(instance),
|
|
7943
|
+
wasRoot: scroll ? scroll.isRoot : isRoot,
|
|
7932
7944
|
};
|
|
7933
7945
|
}
|
|
7934
7946
|
}
|
|
@@ -8018,10 +8030,10 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8018
8030
|
}
|
|
8019
8031
|
return boxWithoutScroll;
|
|
8020
8032
|
}
|
|
8021
|
-
applyTransform(box, transformOnly = false, output) {
|
|
8033
|
+
applyTransform(box, transformOnly = false, output, skipOwnTransform, start = 0) {
|
|
8022
8034
|
const withTransforms = output || createBox();
|
|
8023
8035
|
copyBoxInto(withTransforms, box);
|
|
8024
|
-
for (let i =
|
|
8036
|
+
for (let i = start; i < this.path.length; i++) {
|
|
8025
8037
|
const node = this.path[i];
|
|
8026
8038
|
if (!transformOnly &&
|
|
8027
8039
|
node.options.layoutScroll &&
|
|
@@ -8034,7 +8046,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8034
8046
|
continue;
|
|
8035
8047
|
transformBox(withTransforms, node.latestValues, node.layout?.layoutBox);
|
|
8036
8048
|
}
|
|
8037
|
-
if (hasTransform(this.latestValues)) {
|
|
8049
|
+
if (!skipOwnTransform && hasTransform(this.latestValues)) {
|
|
8038
8050
|
transformBox(withTransforms, this.latestValues, this.layout?.layoutBox);
|
|
8039
8051
|
}
|
|
8040
8052
|
return withTransforms;
|
|
@@ -8169,7 +8181,11 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8169
8181
|
}
|
|
8170
8182
|
else if (this.targetDelta) {
|
|
8171
8183
|
if (Boolean(this.resumingFrom)) {
|
|
8172
|
-
|
|
8184
|
+
/**
|
|
8185
|
+
* Own transforms are applied later, in applyTransformsToTarget,
|
|
8186
|
+
* so only apply ancestor transforms here or they'd be doubled.
|
|
8187
|
+
*/
|
|
8188
|
+
this.applyTransform(this.layout.layoutBox, false, this.target, true);
|
|
8173
8189
|
}
|
|
8174
8190
|
else {
|
|
8175
8191
|
copyBoxInto(this.target, this.layout.layoutBox);
|
|
@@ -8189,8 +8205,13 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8189
8205
|
this.attemptToResolveRelativeTarget = false;
|
|
8190
8206
|
if (this.options.layoutAnchor !== false &&
|
|
8191
8207
|
relativeParent &&
|
|
8192
|
-
|
|
8193
|
-
|
|
8208
|
+
(!relativeParent.resumingFrom === !this.resumingFrom ||
|
|
8209
|
+
/**
|
|
8210
|
+
* Shared layout animations within a layoutRoot
|
|
8211
|
+
* animate relative to it.
|
|
8212
|
+
*/
|
|
8213
|
+
(relativeParent.options.layoutRoot &&
|
|
8214
|
+
!relativeParent.resumingFrom)) &&
|
|
8194
8215
|
!relativeParent.options.layoutScroll &&
|
|
8195
8216
|
relativeParent.target &&
|
|
8196
8217
|
this.animationProgress !== 1) {
|
|
@@ -8270,7 +8291,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8270
8291
|
* If this section of the tree isn't animating we can
|
|
8271
8292
|
* delete our target sources for the following frame.
|
|
8272
8293
|
*/
|
|
8273
|
-
this.isTreeAnimating = Boolean(
|
|
8294
|
+
this.isTreeAnimating = Boolean(this.parent?.isTreeAnimating ||
|
|
8274
8295
|
this.currentAnimation ||
|
|
8275
8296
|
this.pendingAnimation);
|
|
8276
8297
|
if (!this.isTreeAnimating) {
|
|
@@ -8291,8 +8312,17 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8291
8312
|
/**
|
|
8292
8313
|
* Apply all the parent deltas to this box to produce the corrected box. This
|
|
8293
8314
|
* is the layout box, as it will appear on screen as a result of the transforms of its parents.
|
|
8315
|
+
*
|
|
8316
|
+
* A shared target is usually in page space, so ancestor transforms are applied
|
|
8317
|
+
* too. But a target relative to a parent that isn't itself shared (like a
|
|
8318
|
+
* layoutRoot) is in that parent's layout space. So the transforms of the
|
|
8319
|
+
* parent and its ancestors, which move both elements alike, are skipped,
|
|
8320
|
+
* but those of other ancestors (between it and either element) apply.
|
|
8294
8321
|
*/
|
|
8295
|
-
applyTreeDeltas(this.layoutCorrected, this.treeScale, this.path, isShared
|
|
8322
|
+
applyTreeDeltas(this.layoutCorrected, this.treeScale, this.path, isShared &&
|
|
8323
|
+
(lead.relativeTarget && !lead.relativeParent.resumingFrom
|
|
8324
|
+
? lead.relativeParent
|
|
8325
|
+
: true));
|
|
8296
8326
|
/**
|
|
8297
8327
|
* If this layer needs to perform scale correction but doesn't have a target,
|
|
8298
8328
|
* use the layout as the target.
|
|
@@ -8359,8 +8389,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8359
8389
|
scheduleRender(notifyAll = true) {
|
|
8360
8390
|
this.options.visualElement?.scheduleRender();
|
|
8361
8391
|
if (notifyAll) {
|
|
8362
|
-
|
|
8363
|
-
stack && stack.scheduleRender();
|
|
8392
|
+
this.getStack()?.scheduleRender();
|
|
8364
8393
|
}
|
|
8365
8394
|
if (this.resumingFrom && !this.resumingFrom.instance) {
|
|
8366
8395
|
this.resumingFrom = undefined;
|
|
@@ -8382,9 +8411,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8382
8411
|
}
|
|
8383
8412
|
this.attemptToResolveRelativeTarget = !hasOnlyRelativeTargetChanged;
|
|
8384
8413
|
const relativeLayout = createBox();
|
|
8385
|
-
const
|
|
8386
|
-
const layoutSource = this.layout ? this.layout.source : undefined;
|
|
8387
|
-
const isSharedLayoutAnimation = snapshotSource !== layoutSource;
|
|
8414
|
+
const isSharedLayoutAnimation = snapshot?.source !== this.layout?.source;
|
|
8388
8415
|
const stack = this.getStack();
|
|
8389
8416
|
const isOnlyMember = !stack || stack.members.length <= 1;
|
|
8390
8417
|
const shouldCrossfadeOpacity = Boolean(isSharedLayoutAnimation &&
|
|
@@ -8399,19 +8426,11 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8399
8426
|
this.mixTargetDelta = (latest) => {
|
|
8400
8427
|
const progress = latest / 1000;
|
|
8401
8428
|
const point = interpolate?.(progress);
|
|
8429
|
+
mixAxisDeltaLinear(targetDelta.x, delta.x, progress);
|
|
8430
|
+
mixAxisDeltaLinear(targetDelta.y, delta.y, progress);
|
|
8402
8431
|
if (point) {
|
|
8403
8432
|
targetDelta.x.translate = point.x;
|
|
8404
|
-
targetDelta.x.scale = mixNumber$1(delta.x.scale, 1, progress);
|
|
8405
|
-
targetDelta.x.origin = delta.x.origin;
|
|
8406
|
-
targetDelta.x.originPoint = delta.x.originPoint;
|
|
8407
8433
|
targetDelta.y.translate = point.y;
|
|
8408
|
-
targetDelta.y.scale = mixNumber$1(delta.y.scale, 1, progress);
|
|
8409
|
-
targetDelta.y.origin = delta.y.origin;
|
|
8410
|
-
targetDelta.y.originPoint = delta.y.originPoint;
|
|
8411
|
-
}
|
|
8412
|
-
else {
|
|
8413
|
-
mixAxisDeltaLinear(targetDelta.x, delta.x, progress);
|
|
8414
|
-
mixAxisDeltaLinear(targetDelta.y, delta.y, progress);
|
|
8415
8434
|
}
|
|
8416
8435
|
this.setTargetDelta(targetDelta);
|
|
8417
8436
|
if (this.relativeTarget &&
|
|
@@ -8437,7 +8456,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8437
8456
|
this.animationValues = mixedValues;
|
|
8438
8457
|
mixValues(mixedValues, snapshotLatestValues, this.latestValues, progress, shouldCrossfadeOpacity, isOnlyMember);
|
|
8439
8458
|
}
|
|
8440
|
-
if (point
|
|
8459
|
+
if (point?.rotate !== undefined) {
|
|
8441
8460
|
// Dedicated `pathRotation` channel, not `rotate`, so an
|
|
8442
8461
|
// animating `rotate` is composed with, never clobbered.
|
|
8443
8462
|
if (!this.animationValues)
|
|
@@ -8502,7 +8521,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8502
8521
|
}
|
|
8503
8522
|
finishAnimation() {
|
|
8504
8523
|
if (this.currentAnimation) {
|
|
8505
|
-
this.mixTargetDelta
|
|
8524
|
+
this.mixTargetDelta?.(animationTarget);
|
|
8506
8525
|
this.currentAnimation.stop();
|
|
8507
8526
|
}
|
|
8508
8527
|
this.completeAnimation();
|
|
@@ -8522,13 +8541,11 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8522
8541
|
this.layout &&
|
|
8523
8542
|
layout &&
|
|
8524
8543
|
shouldAnimatePositionOnly(this.options.animationType, this.layout.layoutBox, layout.layoutBox)) {
|
|
8544
|
+
const { layoutBox } = this.layout;
|
|
8545
|
+
const leadTarget = target;
|
|
8525
8546
|
target = this.target || createBox();
|
|
8526
|
-
|
|
8527
|
-
target.
|
|
8528
|
-
target.x.max = target.x.min + xLength;
|
|
8529
|
-
const yLength = calcLength(this.layout.layoutBox.y);
|
|
8530
|
-
target.y.min = lead.target.y.min;
|
|
8531
|
-
target.y.max = target.y.min + yLength;
|
|
8547
|
+
alignAxis(target.x, leadTarget.x, layoutBox.x);
|
|
8548
|
+
alignAxis(target.y, leadTarget.y, layoutBox.y);
|
|
8532
8549
|
}
|
|
8533
8550
|
copyBoxInto(targetWithTransforms, target);
|
|
8534
8551
|
/**
|
|
@@ -8553,8 +8570,8 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8553
8570
|
stack.add(node);
|
|
8554
8571
|
const config = node.options.initialPromotionConfig;
|
|
8555
8572
|
node.promote({
|
|
8556
|
-
transition: config
|
|
8557
|
-
preserveFollowOpacity: config
|
|
8573
|
+
transition: config?.transition,
|
|
8574
|
+
preserveFollowOpacity: config?.shouldPreserveFollowOpacity
|
|
8558
8575
|
? config.shouldPreserveFollowOpacity(node)
|
|
8559
8576
|
: undefined,
|
|
8560
8577
|
});
|
|
@@ -8577,9 +8594,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8577
8594
|
return this.root.sharedNodes.get(layoutId);
|
|
8578
8595
|
}
|
|
8579
8596
|
promote({ needsReset, transition, preserveFollowOpacity, } = {}) {
|
|
8580
|
-
|
|
8581
|
-
if (stack)
|
|
8582
|
-
stack.promote(this, preserveFollowOpacity);
|
|
8597
|
+
this.getStack()?.promote(this, preserveFollowOpacity);
|
|
8583
8598
|
if (needsReset) {
|
|
8584
8599
|
this.projectionDelta = undefined;
|
|
8585
8600
|
this.needsReset = true;
|
|
@@ -8588,45 +8603,27 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8588
8603
|
this.setOptions({ transition });
|
|
8589
8604
|
}
|
|
8590
8605
|
relegate() {
|
|
8591
|
-
|
|
8592
|
-
if (stack) {
|
|
8593
|
-
return stack.relegate(this);
|
|
8594
|
-
}
|
|
8595
|
-
else {
|
|
8596
|
-
return false;
|
|
8597
|
-
}
|
|
8606
|
+
return this.getStack()?.relegate(this) || false;
|
|
8598
8607
|
}
|
|
8599
8608
|
resetSkewAndRotation() {
|
|
8600
8609
|
const { visualElement } = this.options;
|
|
8601
8610
|
if (!visualElement)
|
|
8602
8611
|
return;
|
|
8603
|
-
// If there's no detected skew or rotation values, we can early return without a forced render.
|
|
8604
|
-
let hasDistortingTransform = false;
|
|
8605
8612
|
/**
|
|
8606
8613
|
* An unrolled check for rotation values. Most elements don't have any rotation and
|
|
8607
|
-
* skipping the
|
|
8614
|
+
* skipping the loop and new object creation is 50% faster.
|
|
8615
|
+
* If there's no distorting values, we don't need to do any more.
|
|
8608
8616
|
*/
|
|
8609
8617
|
const { latestValues } = visualElement;
|
|
8610
|
-
if (latestValues
|
|
8611
|
-
latestValues.rotate ||
|
|
8612
|
-
latestValues.rotateX ||
|
|
8613
|
-
latestValues.rotateY ||
|
|
8614
|
-
latestValues.rotateZ ||
|
|
8615
|
-
latestValues.skewX ||
|
|
8616
|
-
latestValues.skewY) {
|
|
8617
|
-
hasDistortingTransform = true;
|
|
8618
|
-
}
|
|
8619
|
-
// If there's no distorting values, we don't need to do any more.
|
|
8620
|
-
if (!hasDistortingTransform)
|
|
8618
|
+
if (!hasDistortingTransform(latestValues))
|
|
8621
8619
|
return;
|
|
8622
8620
|
const resetValues = {};
|
|
8623
|
-
if (latestValues.z) {
|
|
8624
|
-
resetDistortingTransform("z", visualElement, resetValues, this.animationValues);
|
|
8625
|
-
}
|
|
8626
8621
|
// Check the skew and rotate value of all axes and reset to 0
|
|
8627
|
-
for (let i = 0; i <
|
|
8628
|
-
resetDistortingTransform(
|
|
8629
|
-
|
|
8622
|
+
for (let i = 0; i < distortingTransforms.length; i++) {
|
|
8623
|
+
resetDistortingTransform(distortingTransforms[i], visualElement, resetValues, this.animationValues);
|
|
8624
|
+
}
|
|
8625
|
+
for (let i = 0; i < angleTransforms.length; i++) {
|
|
8626
|
+
resetDistortingTransform(angleTransforms[i], visualElement, resetValues, this.animationValues);
|
|
8630
8627
|
}
|
|
8631
8628
|
// Force a render of this element to apply the transform with all skews and rotations
|
|
8632
8629
|
// set to 0.
|
|
@@ -8646,7 +8643,13 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8646
8643
|
styleProp) {
|
|
8647
8644
|
if (!this.instance || this.isSVG)
|
|
8648
8645
|
return;
|
|
8649
|
-
|
|
8646
|
+
const lead = this.getLead();
|
|
8647
|
+
/**
|
|
8648
|
+
* Without crossfade, a new lead hides the previous one, as it's
|
|
8649
|
+
* usually unmounting. One that gave its layoutId away keeps
|
|
8650
|
+
* rendering, so only hide nodes that follow another.
|
|
8651
|
+
*/
|
|
8652
|
+
if (!this.isVisible && lead !== this) {
|
|
8650
8653
|
targetStyle.visibility = "hidden";
|
|
8651
8654
|
return;
|
|
8652
8655
|
}
|
|
@@ -8662,9 +8665,10 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8662
8665
|
: "none";
|
|
8663
8666
|
return;
|
|
8664
8667
|
}
|
|
8665
|
-
const lead = this.getLead();
|
|
8666
8668
|
if (!this.projectionDelta || !this.layout || !lead.target) {
|
|
8667
|
-
if (this.options.layoutId) {
|
|
8669
|
+
if (this.options.layoutId || this.needsShow) {
|
|
8670
|
+
this.needsShow = false;
|
|
8671
|
+
targetStyle.visibility = "";
|
|
8668
8672
|
targetStyle.opacity =
|
|
8669
8673
|
this.latestValues.opacity !== undefined
|
|
8670
8674
|
? this.latestValues.opacity
|
|
@@ -8798,52 +8802,49 @@ function notifyLayoutUpdate(node) {
|
|
|
8798
8802
|
const isShared = snapshot.source !== node.layout.source;
|
|
8799
8803
|
// TODO Maybe we want to also resize the layout snapshot so we don't trigger
|
|
8800
8804
|
// animations for instance if layout="size" and an element has only changed position
|
|
8801
|
-
|
|
8802
|
-
|
|
8803
|
-
|
|
8804
|
-
|
|
8805
|
-
|
|
8806
|
-
|
|
8807
|
-
|
|
8808
|
-
|
|
8809
|
-
|
|
8810
|
-
|
|
8811
|
-
|
|
8812
|
-
|
|
8813
|
-
|
|
8814
|
-
|
|
8815
|
-
|
|
8816
|
-
|
|
8817
|
-
|
|
8818
|
-
|
|
8819
|
-
|
|
8820
|
-
|
|
8821
|
-
|
|
8822
|
-
|
|
8823
|
-
|
|
8824
|
-
|
|
8825
|
-
|
|
8826
|
-
|
|
8827
|
-
|
|
8828
|
-
|
|
8829
|
-
|
|
8830
|
-
node.relativeTarget[axis].min + length;
|
|
8831
|
-
}
|
|
8832
|
-
});
|
|
8833
|
-
}
|
|
8805
|
+
const resizeSnapshot = (box, to) => {
|
|
8806
|
+
if (animationType === "size") {
|
|
8807
|
+
eachAxis((axis) => {
|
|
8808
|
+
const length = calcLength(box[axis]);
|
|
8809
|
+
box[axis].min = to[axis].min;
|
|
8810
|
+
box[axis].max = box[axis].min + length;
|
|
8811
|
+
});
|
|
8812
|
+
}
|
|
8813
|
+
else if (animationType === "x" || animationType === "y") {
|
|
8814
|
+
const snapAxis = animationType === "x" ? "y" : "x";
|
|
8815
|
+
copyAxisInto(box[snapAxis], to[snapAxis]);
|
|
8816
|
+
}
|
|
8817
|
+
else if (shouldAnimatePositionOnly(animationType, snapshot.layoutBox, layout)) {
|
|
8818
|
+
eachAxis((axis) => {
|
|
8819
|
+
const length = calcLength(to[axis]);
|
|
8820
|
+
box[axis].max = box[axis].min + length;
|
|
8821
|
+
/**
|
|
8822
|
+
* Ensure relative target gets resized and rerendererd
|
|
8823
|
+
*/
|
|
8824
|
+
if (node.relativeTarget && !node.currentAnimation) {
|
|
8825
|
+
node.isProjectionDirty = true;
|
|
8826
|
+
node.relativeTarget[axis].max =
|
|
8827
|
+
node.relativeTarget[axis].min + length;
|
|
8828
|
+
}
|
|
8829
|
+
});
|
|
8830
|
+
}
|
|
8831
|
+
};
|
|
8832
|
+
const snapshotBox = isShared ? snapshot.measuredBox : snapshot.layoutBox;
|
|
8833
|
+
resizeSnapshot(snapshotBox, layout);
|
|
8834
8834
|
const layoutDelta = createDelta();
|
|
8835
8835
|
calcBoxDelta(layoutDelta, layout, snapshot.layoutBox);
|
|
8836
8836
|
const visualDelta = createDelta();
|
|
8837
|
-
|
|
8838
|
-
calcBoxDelta(visualDelta, node.applyTransform(measuredLayout, true), snapshot.measuredBox);
|
|
8839
|
-
}
|
|
8840
|
-
else {
|
|
8841
|
-
calcBoxDelta(visualDelta, layout, snapshot.layoutBox);
|
|
8842
|
-
}
|
|
8837
|
+
calcBoxDelta(visualDelta, isShared ? node.applyTransform(measuredLayout, true) : layout, snapshotBox);
|
|
8843
8838
|
const hasLayoutChanged = !isDeltaZero(layoutDelta);
|
|
8844
8839
|
let hasRelativeLayoutChanged = false;
|
|
8845
|
-
|
|
8846
|
-
|
|
8840
|
+
const relativeParent = node.getClosestProjectingParent();
|
|
8841
|
+
/**
|
|
8842
|
+
* A snapshot resumed from another element is only relative to this
|
|
8843
|
+
* node's relativeParent if it's a layoutRoot that contains both.
|
|
8844
|
+
*/
|
|
8845
|
+
if (!node.resumeFrom ||
|
|
8846
|
+
(relativeParent?.options.layoutRoot &&
|
|
8847
|
+
node.resumeFrom.path.includes(relativeParent))) {
|
|
8847
8848
|
/**
|
|
8848
8849
|
* If the relativeParent is itself resuming from a different element then
|
|
8849
8850
|
* the relative snapshot is not relavent
|
|
@@ -8852,10 +8853,22 @@ function notifyLayoutUpdate(node) {
|
|
|
8852
8853
|
const { snapshot: parentSnapshot, layout: parentLayout } = relativeParent;
|
|
8853
8854
|
if (parentSnapshot && parentLayout) {
|
|
8854
8855
|
const anchor = node.options.layoutAnchor || undefined;
|
|
8856
|
+
/**
|
|
8857
|
+
* A shared snapshot includes the transforms of the old
|
|
8858
|
+
* element's ancestors below the layoutRoot, as they
|
|
8859
|
+
* aren't shared with the new element.
|
|
8860
|
+
*/
|
|
8855
8861
|
const relativeSnapshot = createBox();
|
|
8856
|
-
calcRelativePosition(relativeSnapshot,
|
|
8862
|
+
calcRelativePosition(relativeSnapshot, isShared
|
|
8863
|
+
? node.resumeFrom.applyTransform(snapshot.layoutBox, true, undefined, true, relativeParent.depth + 1)
|
|
8864
|
+
: snapshot.layoutBox, parentSnapshot.layoutBox, anchor);
|
|
8857
8865
|
const relativeLayout = createBox();
|
|
8858
8866
|
calcRelativePosition(relativeLayout, layout, parentLayout.layoutBox, anchor);
|
|
8867
|
+
/**
|
|
8868
|
+
* A shared snapshot is resized in page space, above, so
|
|
8869
|
+
* resize it relative to the layoutRoot too.
|
|
8870
|
+
*/
|
|
8871
|
+
isShared && resizeSnapshot(relativeSnapshot, relativeLayout);
|
|
8859
8872
|
if (!boxEqualsRounded(relativeSnapshot, relativeLayout)) {
|
|
8860
8873
|
hasRelativeLayoutChanged = true;
|
|
8861
8874
|
}
|
|
@@ -8877,8 +8890,7 @@ function notifyLayoutUpdate(node) {
|
|
|
8877
8890
|
});
|
|
8878
8891
|
}
|
|
8879
8892
|
else if (node.isLead()) {
|
|
8880
|
-
|
|
8881
|
-
onExitComplete && onExitComplete();
|
|
8893
|
+
node.options.onExitComplete?.();
|
|
8882
8894
|
}
|
|
8883
8895
|
/**
|
|
8884
8896
|
* Clearing transition
|
|
@@ -8938,10 +8950,13 @@ function clearIsLayoutDirty(node) {
|
|
|
8938
8950
|
* A dragged node doesn't layout animate, so it jumps to its new layout. Shift
|
|
8939
8951
|
* its descendants' snapshots by the same amount, so they only animate layout
|
|
8940
8952
|
* changes relative to it, rather than lagging behind.
|
|
8953
|
+
*
|
|
8954
|
+
* If its drag ended since the snapshot (e.g. drag disabled from onDrag), it
|
|
8955
|
+
* layout animates again, so its descendants mustn't follow its jump.
|
|
8941
8956
|
*/
|
|
8942
8957
|
function followDraggedAncestor(node) {
|
|
8943
8958
|
const { snapshot, dragAncestor } = node;
|
|
8944
|
-
const to = dragAncestor?.layout;
|
|
8959
|
+
const to = dragAncestor?.isAnimationBlocked && dragAncestor.layout;
|
|
8945
8960
|
if (!snapshot || !to || node.resumeFrom || node.isAnimationBlocked)
|
|
8946
8961
|
return;
|
|
8947
8962
|
const from = dragAncestor.dragSnapshot;
|
|
@@ -8981,7 +8996,7 @@ function syncRelativeLayout(node) {
|
|
|
8981
8996
|
}
|
|
8982
8997
|
function resetTransformStyle(node) {
|
|
8983
8998
|
const { visualElement } = node.options;
|
|
8984
|
-
if (visualElement
|
|
8999
|
+
if (visualElement?.getProps().onBeforeLayoutMeasure) {
|
|
8985
9000
|
visualElement.notify("BeforeLayoutMeasure");
|
|
8986
9001
|
}
|
|
8987
9002
|
node.resetTransform();
|
|
@@ -9015,7 +9030,7 @@ function mixBox(output, from, to, p) {
|
|
|
9015
9030
|
mixAxis(output.y, from.y, to.y, p);
|
|
9016
9031
|
}
|
|
9017
9032
|
function hasOpacityCrossfade(node) {
|
|
9018
|
-
return
|
|
9033
|
+
return node.animationValues?.opacityExit !== undefined;
|
|
9019
9034
|
}
|
|
9020
9035
|
const defaultLayoutTransition = {
|
|
9021
9036
|
duration: 0.45,
|
|
@@ -9041,6 +9056,13 @@ function roundBox(box) {
|
|
|
9041
9056
|
roundAxis(box.x);
|
|
9042
9057
|
roundAxis(box.y);
|
|
9043
9058
|
}
|
|
9059
|
+
/**
|
|
9060
|
+
* Align an axis to the start of another, keeping the length of a layout axis.
|
|
9061
|
+
* The length is read first, as output can be the layout axis itself.
|
|
9062
|
+
*/
|
|
9063
|
+
function alignAxis(output, from, layout) {
|
|
9064
|
+
output.max = calcLength(layout) + (output.min = from.min);
|
|
9065
|
+
}
|
|
9044
9066
|
function shouldAnimatePositionOnly(animationType, snapshot, layout) {
|
|
9045
9067
|
return (animationType === "position" ||
|
|
9046
9068
|
(animationType === "preserve-aspect" &&
|
|
@@ -9055,11 +9077,16 @@ function addDomEvent(target, eventName, handler, options = { passive: true }) {
|
|
|
9055
9077
|
return () => target.removeEventListener(eventName, handler, options);
|
|
9056
9078
|
}
|
|
9057
9079
|
|
|
9058
|
-
const DocumentProjectionNode =
|
|
9080
|
+
const DocumentProjectionNode =
|
|
9081
|
+
/* @__PURE__ */ createProjectionNode({
|
|
9059
9082
|
attachResizeListener: (ref, notify) => addDomEvent(ref, "resize", notify),
|
|
9060
9083
|
measureScroll: () => ({
|
|
9061
|
-
x: document.documentElement.scrollLeft ||
|
|
9062
|
-
|
|
9084
|
+
x: document.documentElement.scrollLeft ||
|
|
9085
|
+
document.body?.scrollLeft ||
|
|
9086
|
+
0,
|
|
9087
|
+
y: document.documentElement.scrollTop ||
|
|
9088
|
+
document.body?.scrollTop ||
|
|
9089
|
+
0,
|
|
9063
9090
|
}),
|
|
9064
9091
|
checkIsScrollRoot: () => true,
|
|
9065
9092
|
});
|
|
@@ -9067,7 +9094,9 @@ const DocumentProjectionNode = createProjectionNode({
|
|
|
9067
9094
|
const rootProjectionNode = {
|
|
9068
9095
|
current: undefined,
|
|
9069
9096
|
};
|
|
9070
|
-
|
|
9097
|
+
|
|
9098
|
+
const HTMLProjectionNode =
|
|
9099
|
+
/* @__PURE__ */ createProjectionNode({
|
|
9071
9100
|
measureScroll: (instance) => ({
|
|
9072
9101
|
x: instance.scrollLeft,
|
|
9073
9102
|
y: instance.scrollTop,
|
|
@@ -9084,7 +9113,7 @@ const HTMLProjectionNode = createProjectionNode({
|
|
|
9084
9113
|
resetTransform: (instance, value) => {
|
|
9085
9114
|
instance.style.transform = value !== undefined ? value : "none";
|
|
9086
9115
|
},
|
|
9087
|
-
checkIsScrollRoot: (instance) =>
|
|
9116
|
+
checkIsScrollRoot: (instance) => window.getComputedStyle(instance).position === "fixed",
|
|
9088
9117
|
});
|
|
9089
9118
|
|
|
9090
9119
|
const visualElementStore = new WeakMap();
|
|
@@ -9111,7 +9140,7 @@ const variantPriorityOrder = [
|
|
|
9111
9140
|
"whileDrag",
|
|
9112
9141
|
"exit",
|
|
9113
9142
|
];
|
|
9114
|
-
const variantProps = ["initial"
|
|
9143
|
+
const variantProps = /* @__PURE__ */ ["initial"].concat(variantPriorityOrder);
|
|
9115
9144
|
|
|
9116
9145
|
function isControllingVariants(props) {
|
|
9117
9146
|
if (isAnimationControls(props.animate))
|
|
@@ -9370,9 +9399,7 @@ class VisualElement {
|
|
|
9370
9399
|
}
|
|
9371
9400
|
this.current = instance;
|
|
9372
9401
|
visualElementStore.set(instance, this);
|
|
9373
|
-
|
|
9374
|
-
this.projection.mount(instance);
|
|
9375
|
-
}
|
|
9402
|
+
this.projection?.instance || this.projection?.mount(instance);
|
|
9376
9403
|
/**
|
|
9377
9404
|
* Join the closest variant node above, so its variant changes
|
|
9378
9405
|
* propagate here, unless inherit={false} cuts the chain.
|
|
@@ -9418,12 +9445,12 @@ class VisualElement {
|
|
|
9418
9445
|
this.hasBeenMounted = true;
|
|
9419
9446
|
}
|
|
9420
9447
|
unmount() {
|
|
9421
|
-
this.projection
|
|
9448
|
+
this.projection?.unmount();
|
|
9422
9449
|
cancelFrame(this.notifyUpdate);
|
|
9423
9450
|
cancelFrame(this.render);
|
|
9424
9451
|
this.valueSubscriptions.forEach((remove) => remove());
|
|
9425
9452
|
this.valueSubscriptions.clear();
|
|
9426
|
-
this.removeFromVariantTree
|
|
9453
|
+
this.removeFromVariantTree?.();
|
|
9427
9454
|
this.parent?.removeChild(this);
|
|
9428
9455
|
for (const key in this.events) {
|
|
9429
9456
|
this.events[key].clear();
|
|
@@ -9439,17 +9466,14 @@ class VisualElement {
|
|
|
9439
9466
|
}
|
|
9440
9467
|
addChild(child) {
|
|
9441
9468
|
this.children.add(child);
|
|
9442
|
-
this.enteringChildren
|
|
9443
|
-
this.enteringChildren.add(child);
|
|
9469
|
+
(this.enteringChildren || (this.enteringChildren = new Set())).add(child);
|
|
9444
9470
|
}
|
|
9445
9471
|
removeChild(child) {
|
|
9446
9472
|
this.children.delete(child);
|
|
9447
|
-
this.enteringChildren
|
|
9473
|
+
this.enteringChildren?.delete(child);
|
|
9448
9474
|
}
|
|
9449
9475
|
bindToMotionValue(key, value) {
|
|
9450
|
-
|
|
9451
|
-
this.valueSubscriptions.get(key)();
|
|
9452
|
-
}
|
|
9476
|
+
this.valueSubscriptions.get(key)?.();
|
|
9453
9477
|
if (value.accelerate &&
|
|
9454
9478
|
acceleratedValues.has(key) &&
|
|
9455
9479
|
this.current instanceof HTMLElement) {
|
|
@@ -9491,8 +9515,7 @@ class VisualElement {
|
|
|
9491
9515
|
}
|
|
9492
9516
|
this.valueSubscriptions.set(key, () => {
|
|
9493
9517
|
removeOnChange();
|
|
9494
|
-
|
|
9495
|
-
removeSyncCheck();
|
|
9518
|
+
removeSyncCheck?.();
|
|
9496
9519
|
// Defer to MotionValue.on("change") auto-stop so React 19 remounts
|
|
9497
9520
|
// can resubscribe before the animation is cancelled (#3315).
|
|
9498
9521
|
});
|
|
@@ -9585,10 +9608,8 @@ class VisualElement {
|
|
|
9585
9608
|
*/
|
|
9586
9609
|
for (let i = 0; i < propEventHandlers.length; i++) {
|
|
9587
9610
|
const key = propEventHandlers[i];
|
|
9588
|
-
|
|
9589
|
-
|
|
9590
|
-
delete this.propEventSubscriptions[key];
|
|
9591
|
-
}
|
|
9611
|
+
this.propEventSubscriptions[key]?.();
|
|
9612
|
+
delete this.propEventSubscriptions[key];
|
|
9592
9613
|
const listenerName = ("on" + key);
|
|
9593
9614
|
const listener = props[listenerName];
|
|
9594
9615
|
if (listener) {
|
|
@@ -9596,9 +9617,7 @@ class VisualElement {
|
|
|
9596
9617
|
}
|
|
9597
9618
|
}
|
|
9598
9619
|
this.prevMotionValues = updateMotionValuesFromProps(this, this.scrapeMotionValuesFromProps(props, this.prevProps || {}, this), this.prevMotionValues);
|
|
9599
|
-
|
|
9600
|
-
this.handleChildMotionValue();
|
|
9601
|
-
}
|
|
9620
|
+
this.handleChildMotionValue?.();
|
|
9602
9621
|
}
|
|
9603
9622
|
getProps() {
|
|
9604
9623
|
return this.props;
|
|
@@ -9607,7 +9626,7 @@ class VisualElement {
|
|
|
9607
9626
|
* Returns the variant definition with a given name.
|
|
9608
9627
|
*/
|
|
9609
9628
|
getVariant(name) {
|
|
9610
|
-
return this.props.variants
|
|
9629
|
+
return this.props.variants?.[name];
|
|
9611
9630
|
}
|
|
9612
9631
|
/**
|
|
9613
9632
|
* Returns the defined default transition on this component.
|
|
@@ -9645,11 +9664,8 @@ class VisualElement {
|
|
|
9645
9664
|
*/
|
|
9646
9665
|
removeValue(key) {
|
|
9647
9666
|
this.values.delete(key);
|
|
9648
|
-
|
|
9649
|
-
|
|
9650
|
-
unsubscribe();
|
|
9651
|
-
this.valueSubscriptions.delete(key);
|
|
9652
|
-
}
|
|
9667
|
+
this.valueSubscriptions.get(key)?.();
|
|
9668
|
+
this.valueSubscriptions.delete(key);
|
|
9653
9669
|
delete this.latestValues[key];
|
|
9654
9670
|
this.removeValueFromRenderState(key, this.renderState);
|
|
9655
9671
|
}
|
|
@@ -9660,10 +9676,10 @@ class VisualElement {
|
|
|
9660
9676
|
return this.values.has(key);
|
|
9661
9677
|
}
|
|
9662
9678
|
getValue(key, defaultValue) {
|
|
9663
|
-
|
|
9664
|
-
|
|
9665
|
-
|
|
9666
|
-
|
|
9679
|
+
let value = this.props.values?.[key];
|
|
9680
|
+
if (value)
|
|
9681
|
+
return value;
|
|
9682
|
+
value = this.values.get(key);
|
|
9667
9683
|
if (value === undefined && defaultValue !== undefined) {
|
|
9668
9684
|
value = motionValue(defaultValue ?? this.getDefaultValue?.(key), {
|
|
9669
9685
|
owner: this,
|
|
@@ -9713,15 +9729,11 @@ class VisualElement {
|
|
|
9713
9729
|
this.baseTarget[key] = value;
|
|
9714
9730
|
}
|
|
9715
9731
|
on(eventName, callback) {
|
|
9716
|
-
|
|
9717
|
-
this.events[eventName] = new motionUtils.SubscriptionManager();
|
|
9718
|
-
}
|
|
9719
|
-
return this.events[eventName].add(callback);
|
|
9732
|
+
return (this.events[eventName] ||
|
|
9733
|
+
(this.events[eventName] = new motionUtils.SubscriptionManager())).add(callback);
|
|
9720
9734
|
}
|
|
9721
9735
|
notify(eventName, ...args) {
|
|
9722
|
-
|
|
9723
|
-
this.events[eventName].notify(...args);
|
|
9724
|
-
}
|
|
9736
|
+
this.events[eventName]?.notify(...args);
|
|
9725
9737
|
}
|
|
9726
9738
|
scheduleRenderMicrotask() {
|
|
9727
9739
|
microtask.render(this.render);
|
|
@@ -9813,7 +9825,8 @@ class HTMLVisualElement extends DOMVisualElement {
|
|
|
9813
9825
|
* HTML/SVG element (a class instance, an imperative handle) there's
|
|
9814
9826
|
* nothing for Motion to style, measure or attach gestures to. #2777
|
|
9815
9827
|
*/
|
|
9816
|
-
|
|
9828
|
+
process.env.NODE_ENV !== "production" &&
|
|
9829
|
+
motionUtils.invariant(Boolean(instance.style), "motion.create() components must forward their ref to a HTML or SVG element", "custom-component-ref");
|
|
9817
9830
|
super.mount(instance);
|
|
9818
9831
|
}
|
|
9819
9832
|
readValueFromInstance(instance, key) {
|
|
@@ -9887,7 +9900,7 @@ function getProjectionParent(element) {
|
|
|
9887
9900
|
let ancestor = element.parentElement;
|
|
9888
9901
|
while (ancestor) {
|
|
9889
9902
|
const node = layoutNodes.get(ancestor);
|
|
9890
|
-
if (node
|
|
9903
|
+
if (node?.instance)
|
|
9891
9904
|
return node;
|
|
9892
9905
|
ancestor = ancestor.parentElement;
|
|
9893
9906
|
}
|
|
@@ -10153,7 +10166,7 @@ class LayoutAnimationBuilder {
|
|
|
10153
10166
|
hasSurvivor &&
|
|
10154
10167
|
!newMemberIds.has(layoutId)) {
|
|
10155
10168
|
if (restore && restore.parent.isConnected) {
|
|
10156
|
-
restore.parent.insertBefore(element, restore.next
|
|
10169
|
+
restore.parent.insertBefore(element, restore.next?.parentNode === restore.parent
|
|
10157
10170
|
? restore.next
|
|
10158
10171
|
: null);
|
|
10159
10172
|
node.isPresent = false;
|
|
@@ -10358,10 +10371,6 @@ class PanSession {
|
|
|
10358
10371
|
* Scroll positions of scrollable ancestors and window.
|
|
10359
10372
|
*/
|
|
10360
10373
|
this.scrollPositions = new Map();
|
|
10361
|
-
/**
|
|
10362
|
-
* Cleanup function for scroll listeners.
|
|
10363
|
-
*/
|
|
10364
|
-
this.removeScrollListeners = null;
|
|
10365
10374
|
this.onElementScroll = (event) => {
|
|
10366
10375
|
this.handleScroll(event.target);
|
|
10367
10376
|
};
|
|
@@ -10389,10 +10398,10 @@ class PanSession {
|
|
|
10389
10398
|
this.history.push({ ...point, timestamp: time.now() });
|
|
10390
10399
|
const { onStart, onMove } = this.handlers;
|
|
10391
10400
|
if (!isPanStarted) {
|
|
10392
|
-
onStart
|
|
10401
|
+
onStart?.(this.lastMoveEvent, info);
|
|
10393
10402
|
this.startEvent = this.lastMoveEvent;
|
|
10394
10403
|
}
|
|
10395
|
-
onMove
|
|
10404
|
+
onMove?.(this.lastMoveEvent, info);
|
|
10396
10405
|
};
|
|
10397
10406
|
this.handlePointerMove = (event, info) => {
|
|
10398
10407
|
/**
|
|
@@ -10417,17 +10426,15 @@ class PanSession {
|
|
|
10417
10426
|
// Resume animation if dragSnapToOrigin is set OR if no drag started (user just clicked)
|
|
10418
10427
|
// This ensures constraint animations continue when interrupted by a click
|
|
10419
10428
|
if (this.dragSnapToOrigin || !this.startEvent) {
|
|
10420
|
-
resumeAnimation
|
|
10429
|
+
resumeAnimation?.();
|
|
10421
10430
|
}
|
|
10422
10431
|
if (!(this.lastMoveEvent && this.lastMoveEventInfo))
|
|
10423
10432
|
return;
|
|
10424
10433
|
const panInfo = getPanInfo(event.type === "pointercancel"
|
|
10425
10434
|
? this.lastMoveEventInfo
|
|
10426
10435
|
: transformPoint(info, this.transformPagePoint), this.history);
|
|
10427
|
-
|
|
10428
|
-
|
|
10429
|
-
}
|
|
10430
|
-
onSessionEnd && onSessionEnd(event, panInfo);
|
|
10436
|
+
this.startEvent && onEnd?.(event, panInfo);
|
|
10437
|
+
onSessionEnd?.(event, panInfo);
|
|
10431
10438
|
};
|
|
10432
10439
|
// If we have more than one touch, don't start detecting this gesture
|
|
10433
10440
|
if (!isPrimaryPointer(event))
|
|
@@ -10440,8 +10447,13 @@ class PanSession {
|
|
|
10440
10447
|
const info = extractEventInfo(event);
|
|
10441
10448
|
const initialInfo = transformPoint(info, this.transformPagePoint);
|
|
10442
10449
|
const { point } = initialInfo;
|
|
10443
|
-
|
|
10444
|
-
|
|
10450
|
+
/**
|
|
10451
|
+
* Stamp the origin with time.now(), not frameData.timestamp: when
|
|
10452
|
+
* the frameloop is idle, frameData.timestamp is from the last frame
|
|
10453
|
+
* that ran, which can be seconds old, and a fast flick from a
|
|
10454
|
+
* standstill would then report near-zero velocity. See #1747.
|
|
10455
|
+
*/
|
|
10456
|
+
this.history = [{ ...point, timestamp: time.now() }];
|
|
10445
10457
|
const { onSessionStart } = handlers;
|
|
10446
10458
|
onSessionStart &&
|
|
10447
10459
|
onSessionStart(event, getPanInfo(initialInfo, this.history));
|
|
@@ -10465,30 +10477,19 @@ class PanSession {
|
|
|
10465
10477
|
const style = getComputedStyle(current);
|
|
10466
10478
|
if (overflowStyles.has(style.overflowX) ||
|
|
10467
10479
|
overflowStyles.has(style.overflowY)) {
|
|
10468
|
-
this.scrollPositions.set(current,
|
|
10469
|
-
x: current.scrollLeft,
|
|
10470
|
-
y: current.scrollTop,
|
|
10471
|
-
});
|
|
10480
|
+
this.scrollPositions.set(current, getScroll(current));
|
|
10472
10481
|
}
|
|
10473
10482
|
current = current.parentElement;
|
|
10474
10483
|
}
|
|
10475
10484
|
// Track window scroll
|
|
10476
|
-
this.scrollPositions.set(window,
|
|
10477
|
-
|
|
10478
|
-
y: window.scrollY,
|
|
10479
|
-
});
|
|
10485
|
+
this.scrollPositions.set(window, getScroll(window));
|
|
10486
|
+
this.removeScrollListeners = motionUtils.pipe(
|
|
10480
10487
|
// Capture listener catches element scroll events as they bubble
|
|
10481
|
-
window
|
|
10488
|
+
addDomEvent(window, "scroll", this.onElementScroll, {
|
|
10482
10489
|
capture: true,
|
|
10483
|
-
})
|
|
10490
|
+
}),
|
|
10484
10491
|
// Direct window scroll listener (window scroll doesn't bubble)
|
|
10485
|
-
window
|
|
10486
|
-
this.removeScrollListeners = () => {
|
|
10487
|
-
window.removeEventListener("scroll", this.onElementScroll, {
|
|
10488
|
-
capture: true,
|
|
10489
|
-
});
|
|
10490
|
-
window.removeEventListener("scroll", this.onWindowScroll);
|
|
10491
|
-
};
|
|
10492
|
+
addDomEvent(window, "scroll", this.onWindowScroll, {}));
|
|
10492
10493
|
}
|
|
10493
10494
|
/**
|
|
10494
10495
|
* Handle scroll compensation during drag.
|
|
@@ -10501,12 +10502,7 @@ class PanSession {
|
|
|
10501
10502
|
if (!initial)
|
|
10502
10503
|
return;
|
|
10503
10504
|
const isWindow = target === window;
|
|
10504
|
-
const current =
|
|
10505
|
-
? { x: window.scrollX, y: window.scrollY }
|
|
10506
|
-
: {
|
|
10507
|
-
x: target.scrollLeft,
|
|
10508
|
-
y: target.scrollTop,
|
|
10509
|
-
};
|
|
10505
|
+
const current = getScroll(target);
|
|
10510
10506
|
const delta = { x: current.x - initial.x, y: current.y - initial.y };
|
|
10511
10507
|
if (delta.x === 0 && delta.y === 0)
|
|
10512
10508
|
return;
|
|
@@ -10531,12 +10527,18 @@ class PanSession {
|
|
|
10531
10527
|
this.handlers = handlers;
|
|
10532
10528
|
}
|
|
10533
10529
|
end() {
|
|
10534
|
-
this.removeListeners
|
|
10535
|
-
this.removeScrollListeners
|
|
10530
|
+
this.removeListeners?.();
|
|
10531
|
+
this.removeScrollListeners?.();
|
|
10536
10532
|
this.scrollPositions.clear();
|
|
10537
10533
|
cancelFrame(this.updatePoint);
|
|
10538
10534
|
}
|
|
10539
10535
|
}
|
|
10536
|
+
const getScroll = (target) => target === window
|
|
10537
|
+
? { x: window.scrollX, y: window.scrollY }
|
|
10538
|
+
: {
|
|
10539
|
+
x: target.scrollLeft,
|
|
10540
|
+
y: target.scrollTop,
|
|
10541
|
+
};
|
|
10540
10542
|
function transformPoint(info, transformPagePoint) {
|
|
10541
10543
|
return transformPagePoint ? { point: transformPagePoint(info.point) } : info;
|
|
10542
10544
|
}
|
|
@@ -10793,6 +10795,25 @@ function resolvePointElastic(dragElastic, label) {
|
|
|
10793
10795
|
: dragElastic[label] || 0;
|
|
10794
10796
|
}
|
|
10795
10797
|
|
|
10798
|
+
/**
|
|
10799
|
+
* Re-read the scroll of the projection's ancestors, and return that of the
|
|
10800
|
+
* `layoutScroll` ones as a key that changes when any of them scroll.
|
|
10801
|
+
*
|
|
10802
|
+
* Clear the cached scroll first so `updateScroll` bypasses its
|
|
10803
|
+
* per-animationId cache and re-reads the live value.
|
|
10804
|
+
*/
|
|
10805
|
+
function measureScroll(projection) {
|
|
10806
|
+
let key = "";
|
|
10807
|
+
for (const node of projection.path) {
|
|
10808
|
+
node.scroll = undefined;
|
|
10809
|
+
node.updateScroll();
|
|
10810
|
+
const { scroll } = node;
|
|
10811
|
+
if (node !== projection.root && scroll) {
|
|
10812
|
+
key += scroll.offset.x + "," + scroll.offset.y + ",";
|
|
10813
|
+
}
|
|
10814
|
+
}
|
|
10815
|
+
return key;
|
|
10816
|
+
}
|
|
10796
10817
|
const elementDragControls = new WeakMap();
|
|
10797
10818
|
class VisualElementDragControls {
|
|
10798
10819
|
constructor(visualElement, readProps = () => visualElement.getProps()) {
|
|
@@ -10824,8 +10845,7 @@ class VisualElementDragControls {
|
|
|
10824
10845
|
/**
|
|
10825
10846
|
* Don't start dragging if this component is exiting
|
|
10826
10847
|
*/
|
|
10827
|
-
|
|
10828
|
-
if (presenceContext && presenceContext.isPresent === false)
|
|
10848
|
+
if (this.visualElement.presenceContext?.isPresent === false)
|
|
10829
10849
|
return;
|
|
10830
10850
|
const onSessionStart = (event) => {
|
|
10831
10851
|
if (snapToCursor)
|
|
@@ -10836,8 +10856,7 @@ class VisualElementDragControls {
|
|
|
10836
10856
|
// Attempt to grab the global drag gesture lock - maybe make this part of PanSession
|
|
10837
10857
|
const { drag, dragPropagation, onDragStart } = this.getProps();
|
|
10838
10858
|
if (drag && !dragPropagation) {
|
|
10839
|
-
|
|
10840
|
-
this.openDragLock();
|
|
10859
|
+
this.openDragLock?.();
|
|
10841
10860
|
this.openDragLock = setDragLock(drag);
|
|
10842
10861
|
// If we don 't have the lock, don't start dragging
|
|
10843
10862
|
if (!this.openDragLock)
|
|
@@ -10848,9 +10867,10 @@ class VisualElementDragControls {
|
|
|
10848
10867
|
this.isDragging = true;
|
|
10849
10868
|
this.currentDirection = null;
|
|
10850
10869
|
this.resolveConstraints();
|
|
10851
|
-
|
|
10852
|
-
|
|
10853
|
-
|
|
10870
|
+
const { projection } = this.visualElement;
|
|
10871
|
+
if (projection) {
|
|
10872
|
+
projection.isAnimationBlocked = true;
|
|
10873
|
+
projection.target = undefined;
|
|
10854
10874
|
}
|
|
10855
10875
|
/**
|
|
10856
10876
|
* Record gesture origin and pointer offset
|
|
@@ -10872,13 +10892,11 @@ class VisualElementDragControls {
|
|
|
10872
10892
|
current = parseFloat(current);
|
|
10873
10893
|
}
|
|
10874
10894
|
else if (percent.test(current)) {
|
|
10875
|
-
const
|
|
10876
|
-
if (
|
|
10877
|
-
|
|
10878
|
-
|
|
10879
|
-
|
|
10880
|
-
current = length * (parseFloat(current) / 100);
|
|
10881
|
-
}
|
|
10895
|
+
const measuredAxis = projection?.layout?.layoutBox[axis];
|
|
10896
|
+
if (measuredAxis) {
|
|
10897
|
+
current =
|
|
10898
|
+
calcLength(measuredAxis) *
|
|
10899
|
+
(parseFloat(current) / 100);
|
|
10882
10900
|
}
|
|
10883
10901
|
}
|
|
10884
10902
|
this.originPoint[axis] = current;
|
|
@@ -10888,8 +10906,7 @@ class VisualElementDragControls {
|
|
|
10888
10906
|
frame.update(() => onDragStart(event, info), false, true);
|
|
10889
10907
|
}
|
|
10890
10908
|
addValueToWillChange(this.visualElement, "transform");
|
|
10891
|
-
|
|
10892
|
-
animationState && animationState.setActive("whileDrag", true);
|
|
10909
|
+
this.visualElement.animationState?.setActive("whileDrag", true);
|
|
10893
10910
|
};
|
|
10894
10911
|
const onMove = (event, info) => {
|
|
10895
10912
|
this.latestPointerEvent = event;
|
|
@@ -10912,8 +10929,8 @@ class VisualElementDragControls {
|
|
|
10912
10929
|
onDirectionLock && onDirectionLock(this.currentDirection);
|
|
10913
10930
|
}
|
|
10914
10931
|
// Update each point with the latest position
|
|
10915
|
-
this.updateAxis("x",
|
|
10916
|
-
this.updateAxis("y",
|
|
10932
|
+
this.updateAxis("x", offset);
|
|
10933
|
+
this.updateAxis("y", offset);
|
|
10917
10934
|
/**
|
|
10918
10935
|
* Ideally we would leave the renderer to fire naturally at the end of
|
|
10919
10936
|
* this frame but if the element is about to change layout as the result
|
|
@@ -10957,7 +10974,11 @@ class VisualElementDragControls {
|
|
|
10957
10974
|
element: this.visualElement.current,
|
|
10958
10975
|
});
|
|
10959
10976
|
}
|
|
10960
|
-
|
|
10977
|
+
/**
|
|
10978
|
+
* @param dragAxes - The axes to animate on release, if not the `drag`
|
|
10979
|
+
* prop's, e.g. when drag was disabled mid-gesture.
|
|
10980
|
+
*/
|
|
10981
|
+
stop(event, panInfo, dragAxes) {
|
|
10961
10982
|
const finalEvent = event || this.latestPointerEvent;
|
|
10962
10983
|
const finalPanInfo = panInfo || this.latestPanInfo;
|
|
10963
10984
|
const isDragging = this.isDragging;
|
|
@@ -10965,7 +10986,7 @@ class VisualElementDragControls {
|
|
|
10965
10986
|
if (!isDragging || !finalPanInfo || !finalEvent)
|
|
10966
10987
|
return;
|
|
10967
10988
|
const { velocity } = finalPanInfo;
|
|
10968
|
-
this.startAnimation(velocity);
|
|
10989
|
+
this.startAnimation(velocity, dragAxes);
|
|
10969
10990
|
const { onDragEnd } = this.getProps();
|
|
10970
10991
|
if (onDragEnd) {
|
|
10971
10992
|
frame.postRender(() => onDragEnd(finalEvent, finalPanInfo));
|
|
@@ -10978,12 +10999,11 @@ class VisualElementDragControls {
|
|
|
10978
10999
|
projection.isAnimationBlocked = false;
|
|
10979
11000
|
}
|
|
10980
11001
|
this.endPanSession();
|
|
10981
|
-
|
|
10982
|
-
if (!dragPropagation && this.openDragLock) {
|
|
11002
|
+
if (!this.getProps().dragPropagation && this.openDragLock) {
|
|
10983
11003
|
this.openDragLock();
|
|
10984
11004
|
this.openDragLock = null;
|
|
10985
11005
|
}
|
|
10986
|
-
animationState
|
|
11006
|
+
animationState?.setActive("whileDrag", false);
|
|
10987
11007
|
}
|
|
10988
11008
|
/**
|
|
10989
11009
|
* Clean up the pan session without modifying other drag state.
|
|
@@ -10991,31 +11011,42 @@ class VisualElementDragControls {
|
|
|
10991
11011
|
* without affecting projection animations or drag locks.
|
|
10992
11012
|
*/
|
|
10993
11013
|
endPanSession() {
|
|
10994
|
-
this.panSession
|
|
11014
|
+
this.panSession?.end();
|
|
10995
11015
|
this.panSession = undefined;
|
|
10996
11016
|
}
|
|
10997
|
-
updateAxis(axis,
|
|
10998
|
-
|
|
11017
|
+
updateAxis(axis, offset) {
|
|
11018
|
+
/**
|
|
11019
|
+
* Read drag per axis: a callback fired while updating the x axis
|
|
11020
|
+
* can synchronously re-render with new props.
|
|
11021
|
+
*/
|
|
11022
|
+
const { drag } = this.readProps();
|
|
10999
11023
|
// If we're not dragging this axis, do an early return.
|
|
11000
11024
|
if (!offset || !shouldDrag(axis, drag, this.currentDirection))
|
|
11001
11025
|
return;
|
|
11002
11026
|
const axisValue = this.getAxisMotionValue(axis);
|
|
11003
11027
|
let next = this.originPoint[axis] + offset[axis];
|
|
11004
11028
|
// Apply constraints
|
|
11005
|
-
|
|
11006
|
-
|
|
11029
|
+
const constraints = this.constraints && this.constraints[axis];
|
|
11030
|
+
if (constraints) {
|
|
11031
|
+
next = applyConstraints(next, constraints, this.elastic[axis]);
|
|
11007
11032
|
}
|
|
11008
11033
|
axisValue.set(next);
|
|
11009
11034
|
}
|
|
11010
11035
|
resolveConstraints() {
|
|
11011
11036
|
const { dragConstraints, dragElastic } = this.getProps();
|
|
11012
|
-
const
|
|
11013
|
-
|
|
11014
|
-
? this.visualElement.projection.measure(false)
|
|
11015
|
-
: this.visualElement.projection?.layout;
|
|
11037
|
+
const { projection } = this.visualElement;
|
|
11038
|
+
const layout = projection && (projection.layout || projection.measure(false));
|
|
11016
11039
|
const prevConstraints = this.constraints;
|
|
11017
11040
|
if (isElementConstraints(dragConstraints)) {
|
|
11018
|
-
|
|
11041
|
+
/**
|
|
11042
|
+
* Ref constraints are measured with the layout. Scrolling a
|
|
11043
|
+
* `layoutScroll` ancestor since can move the element relative
|
|
11044
|
+
* to them without a layout measurement, so measure them again
|
|
11045
|
+
* (#2024). Otherwise keep them: they and the layout can both
|
|
11046
|
+
* have moved on the page since, e.g. when content above grows.
|
|
11047
|
+
*/
|
|
11048
|
+
if (!this.constraints ||
|
|
11049
|
+
this.scroll !== measureScroll(projection)) {
|
|
11019
11050
|
this.constraints = this.resolveRefConstraints();
|
|
11020
11051
|
}
|
|
11021
11052
|
}
|
|
@@ -11052,27 +11083,27 @@ class VisualElementDragControls {
|
|
|
11052
11083
|
if (!isElementConstraints(constraints))
|
|
11053
11084
|
return false;
|
|
11054
11085
|
const constraintsElement = resolveConstraintsElement(constraints);
|
|
11055
|
-
|
|
11086
|
+
process.env.NODE_ENV !== "production" &&
|
|
11087
|
+
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");
|
|
11056
11088
|
const { projection } = this.visualElement;
|
|
11057
11089
|
// TODO
|
|
11058
11090
|
if (!projection || !projection.layout)
|
|
11059
11091
|
return false;
|
|
11060
11092
|
/**
|
|
11061
|
-
* Refresh the
|
|
11062
|
-
*
|
|
11063
|
-
*
|
|
11064
|
-
*
|
|
11065
|
-
*
|
|
11066
|
-
*
|
|
11067
|
-
* Clear the cached scroll first so `updateScroll` bypasses its
|
|
11068
|
-
* per-animationId cache and re-reads the live value.
|
|
11093
|
+
* Refresh the scroll offsets of the root and `layoutScroll`
|
|
11094
|
+
* ancestors so the constraint's viewport box translates to the
|
|
11095
|
+
* layout's coordinates. The scroll captured when the layout was
|
|
11096
|
+
* measured can be stale if they've scrolled since — e.g. via the
|
|
11097
|
+
* browser restoring scroll on refresh, or an ancestor layout effect
|
|
11098
|
+
* running after this element's mount (#2829).
|
|
11069
11099
|
*/
|
|
11070
|
-
|
|
11071
|
-
projection.root.scroll = undefined;
|
|
11072
|
-
projection.root.updateScroll();
|
|
11073
|
-
}
|
|
11100
|
+
this.scroll = measureScroll(projection);
|
|
11074
11101
|
const constraintsBox = measurePageBox(constraintsElement, projection.root, this.visualElement.getTransformPagePoint());
|
|
11075
|
-
|
|
11102
|
+
/**
|
|
11103
|
+
* layoutBox removes the scroll of `layoutScroll` ancestors, so
|
|
11104
|
+
* remove it from the constraints box too.
|
|
11105
|
+
*/
|
|
11106
|
+
let measuredConstraints = calcViewportConstraints(projection.layout.layoutBox, projection.removeElementScroll(constraintsBox));
|
|
11076
11107
|
/**
|
|
11077
11108
|
* If there's an onMeasureDragConstraints listener we call it and
|
|
11078
11109
|
* if different constraints are returned, set constraints to that
|
|
@@ -11086,14 +11117,14 @@ class VisualElementDragControls {
|
|
|
11086
11117
|
}
|
|
11087
11118
|
return measuredConstraints;
|
|
11088
11119
|
}
|
|
11089
|
-
startAnimation(velocity) {
|
|
11120
|
+
startAnimation(velocity, dragAxes) {
|
|
11090
11121
|
const { drag, dragMomentum, dragElastic, dragTransition, dragSnapToOrigin, onDragTransitionEnd, } = this.getProps();
|
|
11091
11122
|
const constraints = this.constraints || {};
|
|
11092
11123
|
const momentumAnimations = eachAxis((axis) => {
|
|
11093
|
-
if (!shouldDrag(axis, drag, this.currentDirection)) {
|
|
11124
|
+
if (!shouldDrag(axis, dragAxes || drag, this.currentDirection)) {
|
|
11094
11125
|
return;
|
|
11095
11126
|
}
|
|
11096
|
-
let transition =
|
|
11127
|
+
let transition = constraints[axis] || {};
|
|
11097
11128
|
if (dragSnapToOrigin === true ||
|
|
11098
11129
|
dragSnapToOrigin === axis)
|
|
11099
11130
|
transition = { min: 0, max: 0 };
|
|
@@ -11199,7 +11230,7 @@ class VisualElementDragControls {
|
|
|
11199
11230
|
this.visualElement.current.style.transform = transformTemplate
|
|
11200
11231
|
? transformTemplate({}, "")
|
|
11201
11232
|
: "none";
|
|
11202
|
-
projection.root
|
|
11233
|
+
projection.root?.updateScroll();
|
|
11203
11234
|
projection.updateLayout();
|
|
11204
11235
|
/**
|
|
11205
11236
|
* Reset constraints so resolveConstraints() will recalculate them
|
|
@@ -11276,8 +11307,8 @@ class VisualElementDragControls {
|
|
|
11276
11307
|
};
|
|
11277
11308
|
const { projection } = this.visualElement;
|
|
11278
11309
|
const stopMeasureLayoutListener = projection.addEventListener("measure", measureDragConstraints);
|
|
11279
|
-
if (
|
|
11280
|
-
projection.root
|
|
11310
|
+
if (!projection.layout) {
|
|
11311
|
+
projection.root?.updateScroll();
|
|
11281
11312
|
projection.updateLayout();
|
|
11282
11313
|
}
|
|
11283
11314
|
frame.read(measureDragConstraints);
|
|
@@ -11293,9 +11324,15 @@ class VisualElementDragControls {
|
|
|
11293
11324
|
const stopLayoutUpdateListener = projection.addEventListener("didUpdate", (({ delta, hasLayoutChanged }) => {
|
|
11294
11325
|
if (this.isDragging && hasLayoutChanged) {
|
|
11295
11326
|
eachAxis((axis) => {
|
|
11296
|
-
|
|
11297
|
-
|
|
11327
|
+
/**
|
|
11328
|
+
* Only compensate axes this gesture drags. A
|
|
11329
|
+
* non-drag axis follows its layout instead, as
|
|
11330
|
+
* nothing would ever move it back (e.g. snapping
|
|
11331
|
+
* to origin only animates drag axes).
|
|
11332
|
+
*/
|
|
11333
|
+
if (!shouldDrag(axis, this.getProps().drag, this.currentDirection))
|
|
11298
11334
|
return;
|
|
11335
|
+
const motionValue = this.getAxisMotionValue(axis);
|
|
11299
11336
|
this.originPoint[axis] += delta[axis].translate;
|
|
11300
11337
|
motionValue.set(motionValue.get() + delta[axis].translate);
|
|
11301
11338
|
});
|
|
@@ -11306,22 +11343,14 @@ class VisualElementDragControls {
|
|
|
11306
11343
|
stopResizeListener();
|
|
11307
11344
|
stopPointerListener();
|
|
11308
11345
|
stopMeasureLayoutListener();
|
|
11309
|
-
stopLayoutUpdateListener
|
|
11310
|
-
stopResizeObservers
|
|
11346
|
+
stopLayoutUpdateListener();
|
|
11347
|
+
stopResizeObservers?.();
|
|
11311
11348
|
};
|
|
11312
11349
|
}
|
|
11313
11350
|
getProps() {
|
|
11314
11351
|
const props = this.readProps();
|
|
11315
|
-
const {
|
|
11316
|
-
return {
|
|
11317
|
-
...props,
|
|
11318
|
-
drag,
|
|
11319
|
-
dragDirectionLock,
|
|
11320
|
-
dragPropagation,
|
|
11321
|
-
dragConstraints,
|
|
11322
|
-
dragElastic,
|
|
11323
|
-
dragMomentum,
|
|
11324
|
-
};
|
|
11352
|
+
const { dragElastic = defaultElastic, dragMomentum = true } = props;
|
|
11353
|
+
return { ...props, dragElastic, dragMomentum };
|
|
11325
11354
|
}
|
|
11326
11355
|
}
|
|
11327
11356
|
/**
|
|
@@ -13656,6 +13685,12 @@ function shallowCompare(next, prev) {
|
|
|
13656
13685
|
}
|
|
13657
13686
|
|
|
13658
13687
|
const reversePriorityOrder = [...variantPriorityOrder].reverse();
|
|
13688
|
+
/**
|
|
13689
|
+
* The transition a value uses when it leaves a state (#1725): the state's
|
|
13690
|
+
* own transition when `out: true`, or the `out` transition itself.
|
|
13691
|
+
* Value-specific keys are resolved by animateTarget.
|
|
13692
|
+
*/
|
|
13693
|
+
const getOutTransition = (transition) => transition?.out === true ? transition : transition?.out;
|
|
13659
13694
|
/**
|
|
13660
13695
|
* Diffs the element's animation props (one layer per AnimationType, highest
|
|
13661
13696
|
* priority wins each value) against the previous call and starts animations
|
|
@@ -13677,13 +13712,18 @@ function createAnimationState(visualElement) {
|
|
|
13677
13712
|
let wasReset = false;
|
|
13678
13713
|
function animateChanges(changedActiveType) {
|
|
13679
13714
|
const { props, parent, manuallyAnimateOnMount } = visualElement;
|
|
13715
|
+
const { initial } = props;
|
|
13680
13716
|
const isMounting = isInitialRender || wasReset;
|
|
13681
13717
|
const animations = [];
|
|
13718
|
+
const resolveInitial = (definition = initial) => (typeof definition !== "boolean" &&
|
|
13719
|
+
resolveVariant(visualElement, Array.isArray(definition) ? definition[0] : definition, visualElement.presenceContext?.custom)) ||
|
|
13720
|
+
undefined;
|
|
13682
13721
|
/**
|
|
13683
|
-
* Values removed from a type
|
|
13684
|
-
*
|
|
13722
|
+
* Values removed from a type, mapped to the out transition of the
|
|
13723
|
+
* state they're leaving. A lower-priority type that defines them
|
|
13724
|
+
* animates them back, otherwise they fall back to a base target.
|
|
13685
13725
|
*/
|
|
13686
|
-
const removedKeys = new
|
|
13726
|
+
const removedKeys = new Map();
|
|
13687
13727
|
/**
|
|
13688
13728
|
* Values claimed by active, higher-priority types.
|
|
13689
13729
|
*/
|
|
@@ -13701,6 +13741,13 @@ function createAnimationState(visualElement) {
|
|
|
13701
13741
|
do
|
|
13702
13742
|
source = source.props.inherit !== false && source.parent;
|
|
13703
13743
|
while (source && !source.isControllingVariants);
|
|
13744
|
+
/**
|
|
13745
|
+
* Mounting leaves initial, so values use its out transition. Like the
|
|
13746
|
+
* other types, variant children inherit initial's label.
|
|
13747
|
+
*/
|
|
13748
|
+
const initialOut = isMounting &&
|
|
13749
|
+
getOutTransition(resolveInitial(initial ?? (source && source.props.initial))
|
|
13750
|
+
?.transition);
|
|
13704
13751
|
reversePriorityOrder.forEach((type, i) => {
|
|
13705
13752
|
const typeState = state[type];
|
|
13706
13753
|
const ownProp = props[type];
|
|
@@ -13712,8 +13759,6 @@ function createAnimationState(visualElement) {
|
|
|
13712
13759
|
: undefined;
|
|
13713
13760
|
const propIsVariant = isVariantLabel(prop);
|
|
13714
13761
|
const activeDelta = type === changedActiveType ? typeState.isActive : null;
|
|
13715
|
-
if (activeDelta === false)
|
|
13716
|
-
removedVariantIndex = i;
|
|
13717
13762
|
/**
|
|
13718
13763
|
* Inherited labels are animated by the parent through
|
|
13719
13764
|
* variantChildren, unless this element mounted after its parent.
|
|
@@ -13728,6 +13773,13 @@ function createAnimationState(visualElement) {
|
|
|
13728
13773
|
typeof prop === "boolean") {
|
|
13729
13774
|
return;
|
|
13730
13775
|
}
|
|
13776
|
+
/**
|
|
13777
|
+
* Set after the skip above, so deactivating a type that has nothing
|
|
13778
|
+
* to animate (e.g. whileTap with no prop) doesn't re-run the variants
|
|
13779
|
+
* below it.
|
|
13780
|
+
*/
|
|
13781
|
+
if (activeDelta === false)
|
|
13782
|
+
removedVariantIndex = i;
|
|
13731
13783
|
/**
|
|
13732
13784
|
* Don't re-resolve a running exit: a changed custom would start
|
|
13733
13785
|
* new value animations that stop the originals, leaving the exit
|
|
@@ -13747,6 +13799,7 @@ function createAnimationState(visualElement) {
|
|
|
13747
13799
|
let handledRemovedValues = false;
|
|
13748
13800
|
const definitionList = Array.isArray(prop) ? prop : [prop];
|
|
13749
13801
|
let resolvedValues = {};
|
|
13802
|
+
let out;
|
|
13750
13803
|
if (activeDelta !== false) {
|
|
13751
13804
|
for (const definition of definitionList) {
|
|
13752
13805
|
const { transition, transitionEnd, ...target } = resolveVariant(visualElement, definition, getTypeCustom(visualElement, type)) || {};
|
|
@@ -13755,6 +13808,11 @@ function createAnimationState(visualElement) {
|
|
|
13755
13808
|
...target,
|
|
13756
13809
|
...transitionEnd,
|
|
13757
13810
|
};
|
|
13811
|
+
/**
|
|
13812
|
+
* One out transition per type. With a list of labels,
|
|
13813
|
+
* the last one that sets out applies to all its values.
|
|
13814
|
+
*/
|
|
13815
|
+
out = getOutTransition(transition) || out;
|
|
13758
13816
|
}
|
|
13759
13817
|
}
|
|
13760
13818
|
const { prevResolvedValues } = typeState;
|
|
@@ -13770,13 +13828,18 @@ function createAnimationState(visualElement) {
|
|
|
13770
13828
|
const valueHasChanged = Array.isArray(next) && Array.isArray(prev)
|
|
13771
13829
|
? !shallowCompare(next, prev) || variantDidChange
|
|
13772
13830
|
: next !== prev;
|
|
13773
|
-
|
|
13774
|
-
|
|
13775
|
-
|
|
13831
|
+
let outTransition;
|
|
13832
|
+
if (valueHasChanged && (next === undefined || next === null)) {
|
|
13833
|
+
/**
|
|
13834
|
+
* The highest-priority state a value leaves wins.
|
|
13835
|
+
*/
|
|
13836
|
+
removedKeys.has(key) ||
|
|
13837
|
+
removedKeys.set(key, typeState.prevOut);
|
|
13776
13838
|
}
|
|
13777
13839
|
else if (valueHasChanged ||
|
|
13778
13840
|
(next !== undefined && removedKeys.has(key))) {
|
|
13779
13841
|
shouldAnimateType = true;
|
|
13842
|
+
outTransition = removedKeys.get(key) || initialOut;
|
|
13780
13843
|
if (removedKeys.delete(key))
|
|
13781
13844
|
handledRemovedValues = true;
|
|
13782
13845
|
typeState.needsAnimating[key] = true;
|
|
@@ -13787,9 +13850,11 @@ function createAnimationState(visualElement) {
|
|
|
13787
13850
|
else {
|
|
13788
13851
|
typeState.protectedKeys[key] = true;
|
|
13789
13852
|
}
|
|
13853
|
+
typeState.out[key] = outTransition;
|
|
13790
13854
|
}
|
|
13791
13855
|
typeState.prevProp = prop;
|
|
13792
13856
|
typeState.prevResolvedValues = resolvedValues;
|
|
13857
|
+
typeState.prevOut = out;
|
|
13793
13858
|
if (typeState.isActive) {
|
|
13794
13859
|
encounteredKeys = { ...encounteredKeys, ...resolvedValues };
|
|
13795
13860
|
}
|
|
@@ -13820,14 +13885,17 @@ function createAnimationState(visualElement) {
|
|
|
13820
13885
|
* longer defines a value it once did, it stays where it is.
|
|
13821
13886
|
*/
|
|
13822
13887
|
if (removedKeys.size) {
|
|
13823
|
-
const { initial } = props;
|
|
13824
13888
|
const fallbackAnimation = {};
|
|
13825
|
-
const resolvedInitial =
|
|
13826
|
-
|
|
13827
|
-
|
|
13828
|
-
|
|
13829
|
-
|
|
13830
|
-
|
|
13889
|
+
const resolvedInitial = resolveInitial();
|
|
13890
|
+
let fallbackTransition = resolvedInitial?.transition;
|
|
13891
|
+
removedKeys.forEach((outTransition, key) => {
|
|
13892
|
+
if (outTransition) {
|
|
13893
|
+
fallbackTransition = {
|
|
13894
|
+
...(fallbackTransition ||
|
|
13895
|
+
visualElement.getDefaultTransition()),
|
|
13896
|
+
[key]: outTransition,
|
|
13897
|
+
};
|
|
13898
|
+
}
|
|
13831
13899
|
const motionValue = visualElement.getValue(key);
|
|
13832
13900
|
if (motionValue)
|
|
13833
13901
|
motionValue.liveStyle = true;
|
|
@@ -13859,6 +13927,9 @@ function createAnimationState(visualElement) {
|
|
|
13859
13927
|
visualElement.baseTarget[key] = motionValue?.get();
|
|
13860
13928
|
}
|
|
13861
13929
|
});
|
|
13930
|
+
if (fallbackTransition) {
|
|
13931
|
+
fallbackAnimation.transition = fallbackTransition;
|
|
13932
|
+
}
|
|
13862
13933
|
animations.push({ animation: fallbackAnimation });
|
|
13863
13934
|
}
|
|
13864
13935
|
const blockAnimation = (isMounting && visualElement.blockInitialAnimation) ||
|
|
@@ -13918,6 +13989,7 @@ function createState() {
|
|
|
13918
13989
|
protectedKeys: {},
|
|
13919
13990
|
needsAnimating: {},
|
|
13920
13991
|
prevResolvedValues: {},
|
|
13992
|
+
out: {},
|
|
13921
13993
|
};
|
|
13922
13994
|
}
|
|
13923
13995
|
return state;
|
|
@@ -14084,6 +14156,7 @@ exports.buildProjectionTransform = buildProjectionTransform;
|
|
|
14084
14156
|
exports.buildSVGAttrs = buildSVGAttrs;
|
|
14085
14157
|
exports.buildSVGPath = buildSVGPath;
|
|
14086
14158
|
exports.buildTransform = buildTransform$1;
|
|
14159
|
+
exports.buildTransformer = buildTransformer;
|
|
14087
14160
|
exports.calcAxisDelta = calcAxisDelta;
|
|
14088
14161
|
exports.calcBoxDelta = calcBoxDelta;
|
|
14089
14162
|
exports.calcChildStagger = calcChildStagger;
|
|
@@ -14238,6 +14311,7 @@ exports.pixelsToPercent = pixelsToPercent;
|
|
|
14238
14311
|
exports.positionalKeys = positionalKeys;
|
|
14239
14312
|
exports.prefersReducedMotion = prefersReducedMotion;
|
|
14240
14313
|
exports.press = press;
|
|
14314
|
+
exports.processFrame = processFrame;
|
|
14241
14315
|
exports.progressPercentage = progressPercentage;
|
|
14242
14316
|
exports.propEffect = propEffect;
|
|
14243
14317
|
exports.propagateDirtyNodes = propagateDirtyNodes;
|