motion 14.7.1 → 14.9.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/remix.js +14 -0
- package/dist/es/remix.mjs +1 -0
- package/dist/motion.dev.js +444 -175
- package/dist/motion.js +1 -1
- package/dist/remix.d.ts +1 -0
- package/package.json +15 -4
- package/remix/package.json +6 -0
package/dist/motion.dev.js
CHANGED
|
@@ -1619,10 +1619,11 @@
|
|
|
1619
1619
|
|
|
1620
1620
|
function createMixers(output, ease, customMixer) {
|
|
1621
1621
|
const mixers = [];
|
|
1622
|
-
const mixerFactory =
|
|
1622
|
+
const mixerFactory = MotionGlobalConfig.mix || mix;
|
|
1623
1623
|
const numMixers = output.length - 1;
|
|
1624
1624
|
for (let i = 0; i < numMixers; i++) {
|
|
1625
|
-
let mixer =
|
|
1625
|
+
let mixer = customMixer?.(output[i], output[i + 1]) ||
|
|
1626
|
+
mixerFactory(output[i], output[i + 1]);
|
|
1626
1627
|
if (ease) {
|
|
1627
1628
|
const easingFunction = Array.isArray(ease) ? ease[i] || noop : ease;
|
|
1628
1629
|
mixer = pipe(easingFunction, mixer);
|
|
@@ -1708,7 +1709,13 @@
|
|
|
1708
1709
|
function defaultEasing(values, easing) {
|
|
1709
1710
|
return values.map(() => easing || easeInOut).splice(0, values.length - 1);
|
|
1710
1711
|
}
|
|
1711
|
-
function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "easeInOut", }) {
|
|
1712
|
+
function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "easeInOut", mixer: transitionMixer, }) {
|
|
1713
|
+
/**
|
|
1714
|
+
* A mixer only blends values that aren't numbers. Numbers blend as
|
|
1715
|
+
* usual, as they do in springs, and so do the progress animations
|
|
1716
|
+
* behind layout and path animations, which take the same transition.
|
|
1717
|
+
*/
|
|
1718
|
+
const customMixer = typeof keyframeValues[0] === "number" ? undefined : transitionMixer;
|
|
1712
1719
|
/**
|
|
1713
1720
|
* Easing functions can be externally defined as strings. Here we convert them
|
|
1714
1721
|
* into actual functions.
|
|
@@ -1725,9 +1732,11 @@
|
|
|
1725
1732
|
value: keyframeValues[0],
|
|
1726
1733
|
};
|
|
1727
1734
|
/**
|
|
1728
|
-
* Fast setup path for two keyframes one easing.
|
|
1735
|
+
* Fast setup path for two keyframes one easing. interpolate() handles
|
|
1736
|
+
* a custom mixer, and falls back to the usual one where it declines.
|
|
1729
1737
|
*/
|
|
1730
|
-
if (
|
|
1738
|
+
if (!customMixer &&
|
|
1739
|
+
keyframeValues.length === 2 &&
|
|
1731
1740
|
!Array.isArray(easingFunctions) &&
|
|
1732
1741
|
(!times ||
|
|
1733
1742
|
times.length !== 2 ||
|
|
@@ -1760,6 +1769,7 @@
|
|
|
1760
1769
|
ease: Array.isArray(easingFunctions)
|
|
1761
1770
|
? easingFunctions
|
|
1762
1771
|
: defaultEasing(keyframeValues, easingFunctions),
|
|
1772
|
+
mixer: customMixer,
|
|
1763
1773
|
});
|
|
1764
1774
|
return {
|
|
1765
1775
|
calculatedDuration: duration,
|
|
@@ -1967,9 +1977,15 @@
|
|
|
1967
1977
|
if (generatorFactory !== keyframes) {
|
|
1968
1978
|
exports.invariant(keyframes$1.length <= 2, `Only two keyframes currently supported with spring and inertia animations. Trying to animate ${keyframes$1}`, "spring-two-frames");
|
|
1969
1979
|
}
|
|
1980
|
+
/**
|
|
1981
|
+
* This runs again when a spring is flattened to attach it to a
|
|
1982
|
+
* timeline, and the keyframes generator blends values itself.
|
|
1983
|
+
*/
|
|
1984
|
+
this.mixKeyframes = undefined;
|
|
1970
1985
|
if (generatorFactory !== keyframes &&
|
|
1971
1986
|
typeof keyframes$1[0] !== "number") {
|
|
1972
|
-
this.mixKeyframes = pipe(percentToProgress,
|
|
1987
|
+
this.mixKeyframes = pipe(percentToProgress, options.mixer?.(keyframes$1[0], keyframes$1[1]) ||
|
|
1988
|
+
mix(keyframes$1[0], keyframes$1[1]));
|
|
1973
1989
|
keyframes$1 = [0, 100];
|
|
1974
1990
|
}
|
|
1975
1991
|
const generator = generatorFactory(keyframes$1 === options.keyframes
|
|
@@ -3323,6 +3339,15 @@
|
|
|
3323
3339
|
return false;
|
|
3324
3340
|
}
|
|
3325
3341
|
|
|
3342
|
+
/**
|
|
3343
|
+
* Whether an animation needs its mixer, which WAAPI can't call. Numbers
|
|
3344
|
+
* blend as usual, and an animation whose mixer declines every pair runs
|
|
3345
|
+
* as it would without one.
|
|
3346
|
+
*/
|
|
3347
|
+
const needsMixer = ({ mixer, keyframes }) => mixer &&
|
|
3348
|
+
typeof keyframes[0] !== "number" &&
|
|
3349
|
+
keyframes.some((keyframe, i) => i && mixer(keyframes[i - 1], keyframe));
|
|
3350
|
+
|
|
3326
3351
|
const colorProperties = new Set([
|
|
3327
3352
|
"color",
|
|
3328
3353
|
"backgroundColor",
|
|
@@ -3382,7 +3407,8 @@
|
|
|
3382
3407
|
!repeatDelay &&
|
|
3383
3408
|
repeatType !== "mirror" &&
|
|
3384
3409
|
damping !== 0 &&
|
|
3385
|
-
type !== "inertia"
|
|
3410
|
+
type !== "inertia" &&
|
|
3411
|
+
!needsMixer(options));
|
|
3386
3412
|
}
|
|
3387
3413
|
|
|
3388
3414
|
/**
|
|
@@ -3481,18 +3507,21 @@
|
|
|
3481
3507
|
* Named easings that are the same cubic-bezier in JS and CSS.
|
|
3482
3508
|
*/
|
|
3483
3509
|
const isNativeEasing = (ease) => /^(linear|ease(In|Out|InOut))$/.test(ease);
|
|
3510
|
+
/**
|
|
3511
|
+
* Whether two eased progresses match. False if either is NaN.
|
|
3512
|
+
*/
|
|
3513
|
+
const isNear$1 = (a, b) => Math.abs(a - b) <= easingTolerance;
|
|
3484
3514
|
const byTime = (a, b) => a - b;
|
|
3485
3515
|
/**
|
|
3486
3516
|
* n + 1 evenly spaced timestamps, from one timestamp to another.
|
|
3487
3517
|
*/
|
|
3488
|
-
const spread = (from, to, n) =>
|
|
3489
|
-
const result = [];
|
|
3490
|
-
for (let i = 0; i <= n; i++)
|
|
3491
|
-
result.push(mixNumber$1(from, to, i / n));
|
|
3492
|
-
return result;
|
|
3493
|
-
};
|
|
3518
|
+
const spread = (from, to, n) => defaultOffset$1(Array(n + 1)).map((p) => mixNumber$1(from, to, p));
|
|
3494
3519
|
const getOwner = (options) => options.motionValue.owner;
|
|
3495
3520
|
const getGroup = (element) => transformGroups.get(element);
|
|
3521
|
+
/**
|
|
3522
|
+
* Whether an animation has ended, so can leave its group.
|
|
3523
|
+
*/
|
|
3524
|
+
const hasEnded = ({ state }) => state === "idle" || state === "finished";
|
|
3496
3525
|
const read = (owner, key) => owner.latestValues ? owner.latestValues[key] : owner.getValue(key)?.get();
|
|
3497
3526
|
/**
|
|
3498
3527
|
* Whether this animation should join its element's transform group.
|
|
@@ -3531,7 +3560,12 @@
|
|
|
3531
3560
|
/**
|
|
3532
3561
|
* Layout animations write transform every frame.
|
|
3533
3562
|
*/
|
|
3534
|
-
!owner.projection?.isProjecting()
|
|
3563
|
+
!owner.projection?.isProjecting() &&
|
|
3564
|
+
/**
|
|
3565
|
+
* A mixer that blends these values makes them every frame. It's
|
|
3566
|
+
* asked last, as it's user code.
|
|
3567
|
+
*/
|
|
3568
|
+
!needsMixer(options));
|
|
3535
3569
|
}
|
|
3536
3570
|
class TransformAnimation extends JSAnimation {
|
|
3537
3571
|
constructor(options) {
|
|
@@ -3888,9 +3922,8 @@
|
|
|
3888
3922
|
let shared;
|
|
3889
3923
|
let progressAt;
|
|
3890
3924
|
for (const track of moving) {
|
|
3891
|
-
const
|
|
3892
|
-
const
|
|
3893
|
-
const changes = values.map((value) => value - first);
|
|
3925
|
+
const first = track.numberAt(from);
|
|
3926
|
+
const changes = at.map((t) => track.numberAt(t) - first);
|
|
3894
3927
|
const end = changes[changes.length - 1];
|
|
3895
3928
|
/**
|
|
3896
3929
|
* A value that ends only a tiny way from where it started, as
|
|
@@ -3904,25 +3937,20 @@
|
|
|
3904
3937
|
: end;
|
|
3905
3938
|
const progress = changes.map((change) => range ? change / range : change);
|
|
3906
3939
|
/**
|
|
3907
|
-
*
|
|
3908
|
-
*
|
|
3909
|
-
* fits
|
|
3940
|
+
* The first value that moves sets the easing, and every other
|
|
3941
|
+
* one must follow it. A value that doesn't change, like one
|
|
3942
|
+
* still in its delay, fits any easing. One that changes but
|
|
3943
|
+
* ends where it started fits none.
|
|
3910
3944
|
*/
|
|
3911
|
-
if (!
|
|
3912
|
-
if (progress.some((p) => !(Math.abs(p) <= easingTolerance))) {
|
|
3913
|
-
return;
|
|
3914
|
-
}
|
|
3915
|
-
}
|
|
3916
|
-
else if (!shared) {
|
|
3945
|
+
if (range && !shared) {
|
|
3917
3946
|
shared = progress;
|
|
3918
3947
|
progressAt = (t) => (track.numberAt(t) - first) / range;
|
|
3919
3948
|
}
|
|
3920
|
-
else if (progress.some((p, i) => !(
|
|
3949
|
+
else if (progress.some((p, i) => !isNear$1(p, range && shared[i]))) {
|
|
3921
3950
|
return;
|
|
3922
3951
|
}
|
|
3923
3952
|
}
|
|
3924
|
-
if (!shared ||
|
|
3925
|
-
shared.every((p, i) => Math.abs(p - position(at[i])) <= easingTolerance)) {
|
|
3953
|
+
if (!shared || shared.every((p, i) => isNear$1(p, position(at[i])))) {
|
|
3926
3954
|
return "linear";
|
|
3927
3955
|
}
|
|
3928
3956
|
/**
|
|
@@ -4009,7 +4037,7 @@
|
|
|
4009
4037
|
/**
|
|
4010
4038
|
* A WAAPI animation of the composed transform between two timestamps.
|
|
4011
4039
|
*/
|
|
4012
|
-
const run = (moving, from, to, options = { fill: "both" }, settled
|
|
4040
|
+
const run = (moving, from, to, nativeEasing, options = { fill: "both" }, settled) => {
|
|
4013
4041
|
const bounds = moving.flatMap((track) => track.boundaries(from, to));
|
|
4014
4042
|
const easing = nativeEasing || getEasing(moving, from, to, bounds);
|
|
4015
4043
|
const times = easing ? [from, to] : sample(moving, from, to, bounds);
|
|
@@ -4095,9 +4123,7 @@
|
|
|
4095
4123
|
if (byKey.has(key))
|
|
4096
4124
|
return true;
|
|
4097
4125
|
const value = (statics[key] = read(owner, key));
|
|
4098
|
-
return
|
|
4099
|
-
parseFloat(value) !==
|
|
4100
|
-
(key.startsWith("scale") ? 1 : 0));
|
|
4126
|
+
return value !== undefined && !isDefaultTransform(key, value);
|
|
4101
4127
|
});
|
|
4102
4128
|
stop(false);
|
|
4103
4129
|
/**
|
|
@@ -4108,7 +4134,7 @@
|
|
|
4108
4134
|
try {
|
|
4109
4135
|
if (tween && tween[1] > now) {
|
|
4110
4136
|
const [from, to, easing] = tween;
|
|
4111
|
-
add(run(moving, from, to,
|
|
4137
|
+
add(run(moving, from, to, easing), from - now, to - from);
|
|
4112
4138
|
}
|
|
4113
4139
|
else if (end > now) {
|
|
4114
4140
|
add(run(moving, now, end), 0, end - now);
|
|
@@ -4125,7 +4151,7 @@
|
|
|
4125
4151
|
* seamlessly, and start it part way through.
|
|
4126
4152
|
*/
|
|
4127
4153
|
const from = cycleStart + Math.floor((end - cycleStart) / cycle) * cycle;
|
|
4128
|
-
add(run(looping, from, from + cycle, {
|
|
4154
|
+
add(run(looping, from, from + cycle, undefined, {
|
|
4129
4155
|
iterations: Infinity,
|
|
4130
4156
|
iterationStart: (end - from) / cycle,
|
|
4131
4157
|
/**
|
|
@@ -4264,10 +4290,7 @@
|
|
|
4264
4290
|
isScheduled = false;
|
|
4265
4291
|
if (isEnded)
|
|
4266
4292
|
return;
|
|
4267
|
-
tracks.forEach((
|
|
4268
|
-
if (state === "idle" || state === "finished")
|
|
4269
|
-
tracks.delete(track);
|
|
4270
|
-
});
|
|
4293
|
+
tracks.forEach((track) => hasEnded(track) && tracks.delete(track));
|
|
4271
4294
|
if (end())
|
|
4272
4295
|
return;
|
|
4273
4296
|
for (const track of tracks) {
|
|
@@ -4327,9 +4350,7 @@
|
|
|
4327
4350
|
* Only drop the stopped animation. Others can be idle because
|
|
4328
4351
|
* they're part way through play(), and are about to run.
|
|
4329
4352
|
*/
|
|
4330
|
-
|
|
4331
|
-
if (state === "idle" || state === "finished")
|
|
4332
|
-
tracks.delete(track);
|
|
4353
|
+
hasEnded(track) && tracks.delete(track);
|
|
4333
4354
|
end() || group.schedule(true);
|
|
4334
4355
|
},
|
|
4335
4356
|
/**
|
|
@@ -4886,10 +4907,19 @@
|
|
|
4886
4907
|
* effects, and resets velocity to `0`.
|
|
4887
4908
|
*/
|
|
4888
4909
|
jump(v, endAnimation = true) {
|
|
4910
|
+
if (endAnimation) {
|
|
4911
|
+
/**
|
|
4912
|
+
* Stop first, as stopping a running animation can set the
|
|
4913
|
+
* value it's showing, which would replace v. Marking the value
|
|
4914
|
+
* as updated now skips a JS animation's catch-up tick on stop,
|
|
4915
|
+
* which could otherwise complete it.
|
|
4916
|
+
*/
|
|
4917
|
+
this.updatedAt = time.now();
|
|
4918
|
+
this.stop();
|
|
4919
|
+
}
|
|
4889
4920
|
this.updateAndNotify(v);
|
|
4890
4921
|
this.prev = v;
|
|
4891
4922
|
this.prevUpdatedAt = this.prevFrameValue = undefined;
|
|
4892
|
-
endAnimation && this.stop();
|
|
4893
4923
|
this.stopPassiveEffect?.();
|
|
4894
4924
|
}
|
|
4895
4925
|
dirty() {
|
|
@@ -5108,6 +5138,7 @@
|
|
|
5108
5138
|
"from",
|
|
5109
5139
|
"elapsed",
|
|
5110
5140
|
"out",
|
|
5141
|
+
"mixer",
|
|
5111
5142
|
]);
|
|
5112
5143
|
/**
|
|
5113
5144
|
* Decide whether a transition is defined on a given Transition.
|
|
@@ -6664,6 +6695,20 @@
|
|
|
6664
6695
|
else if (key.startsWith("attr")) {
|
|
6665
6696
|
return addAttrValue(element, state, key, value, convertAttrKey(key));
|
|
6666
6697
|
}
|
|
6698
|
+
else if (key === "d") {
|
|
6699
|
+
/**
|
|
6700
|
+
* `d` is a CSS property in Chrome and Firefox, but only as
|
|
6701
|
+
* `path(...)`, so path data goes to the attribute, taken out of
|
|
6702
|
+
* `path(...)` if it's written that way. Path data itself has no
|
|
6703
|
+
* quotes or brackets.
|
|
6704
|
+
*/
|
|
6705
|
+
return state.set(key, value, () => {
|
|
6706
|
+
const d = value.get()?.replace(/path\(|["')]/g, "");
|
|
6707
|
+
d === undefined
|
|
6708
|
+
? element.removeAttribute(key)
|
|
6709
|
+
: element.setAttribute(key, d);
|
|
6710
|
+
});
|
|
6711
|
+
}
|
|
6667
6712
|
/**
|
|
6668
6713
|
* Transforms and origins aren't CSS properties (bar `x`/`y` in some
|
|
6669
6714
|
* browsers), so check them by name rather than `key in element.style`.
|
|
@@ -6920,6 +6965,10 @@
|
|
|
6920
6965
|
}
|
|
6921
6966
|
return viewportBox;
|
|
6922
6967
|
}
|
|
6968
|
+
const measureDocumentScroll = () => ({
|
|
6969
|
+
x: document.documentElement.scrollLeft || document.body?.scrollLeft || 0,
|
|
6970
|
+
y: document.documentElement.scrollTop || document.body?.scrollTop || 0,
|
|
6971
|
+
});
|
|
6923
6972
|
|
|
6924
6973
|
const noProps = {};
|
|
6925
6974
|
const getElementEffect = (element) => (isSVGElement(element)
|
|
@@ -7089,6 +7138,7 @@
|
|
|
7089
7138
|
const statsBuffer = {
|
|
7090
7139
|
value: null,
|
|
7091
7140
|
addProjectionMetrics: null,
|
|
7141
|
+
countProjection: undefined,
|
|
7092
7142
|
};
|
|
7093
7143
|
|
|
7094
7144
|
/**
|
|
@@ -7111,6 +7161,12 @@
|
|
|
7111
7161
|
return delay(callback, secondsToMilliseconds(timeout));
|
|
7112
7162
|
}
|
|
7113
7163
|
|
|
7164
|
+
function isRefObject(ref) {
|
|
7165
|
+
return (ref &&
|
|
7166
|
+
typeof ref === "object" &&
|
|
7167
|
+
Object.prototype.hasOwnProperty.call(ref, "current"));
|
|
7168
|
+
}
|
|
7169
|
+
|
|
7114
7170
|
/**
|
|
7115
7171
|
* Checks if an element is specifically an SVGSVGElement (the root SVG element)
|
|
7116
7172
|
* in a way that works across iframes
|
|
@@ -7325,6 +7381,27 @@
|
|
|
7325
7381
|
removeAxisTransforms(box.y, transforms, yKeys, originBox?.y, sourceBox?.y);
|
|
7326
7382
|
}
|
|
7327
7383
|
|
|
7384
|
+
const userAgentContains = (string) => typeof navigator !== "undefined" &&
|
|
7385
|
+
navigator.userAgent &&
|
|
7386
|
+
navigator.userAgent.toLowerCase().includes(string);
|
|
7387
|
+
/**
|
|
7388
|
+
* Measured bounding boxes must be rounded in Safari and
|
|
7389
|
+
* left untouched in Chrome, otherwise non-integer layouts within scaled-up elements
|
|
7390
|
+
* can appear to jump.
|
|
7391
|
+
*/
|
|
7392
|
+
const roundPoint = userAgentContains("applewebkit/") && !userAgentContains("chrome/")
|
|
7393
|
+
? Math.round
|
|
7394
|
+
: noop;
|
|
7395
|
+
function roundAxis(axis) {
|
|
7396
|
+
// Round to the nearest .5 pixels to support subpixel layouts
|
|
7397
|
+
axis.min = roundPoint(axis.min);
|
|
7398
|
+
axis.max = roundPoint(axis.max);
|
|
7399
|
+
}
|
|
7400
|
+
function roundBox(box) {
|
|
7401
|
+
roundAxis(box.x);
|
|
7402
|
+
roundAxis(box.y);
|
|
7403
|
+
}
|
|
7404
|
+
|
|
7328
7405
|
const createAxisDelta = () => ({
|
|
7329
7406
|
translate: 0,
|
|
7330
7407
|
scale: 1,
|
|
@@ -7621,11 +7698,6 @@
|
|
|
7621
7698
|
hasEverUpdated: false,
|
|
7622
7699
|
};
|
|
7623
7700
|
|
|
7624
|
-
const metrics = {
|
|
7625
|
-
nodes: 0,
|
|
7626
|
-
calculatedTargetDeltas: 0,
|
|
7627
|
-
calculatedProjections: 0,
|
|
7628
|
-
};
|
|
7629
7701
|
/**
|
|
7630
7702
|
* Transforms that distort an element's layout, so must be reset before measuring.
|
|
7631
7703
|
*/
|
|
@@ -7673,6 +7745,13 @@
|
|
|
7673
7745
|
cancelTreeOptimisedTransformAnimations(parent);
|
|
7674
7746
|
}
|
|
7675
7747
|
}
|
|
7748
|
+
function getClosestProjectingNode(visualElement) {
|
|
7749
|
+
if (!visualElement)
|
|
7750
|
+
return undefined;
|
|
7751
|
+
return visualElement.options.allowProjection !== false
|
|
7752
|
+
? visualElement.projection
|
|
7753
|
+
: getClosestProjectingNode(visualElement.parent);
|
|
7754
|
+
}
|
|
7676
7755
|
function createProjectionNode({ attachResizeListener, defaultParent, measureScroll, checkIsScrollRoot, resetTransform, }) {
|
|
7677
7756
|
/**
|
|
7678
7757
|
* Correctors registered via addScaleCorrector before projection loaded
|
|
@@ -7685,6 +7764,57 @@
|
|
|
7685
7764
|
...scaleCorrectors,
|
|
7686
7765
|
});
|
|
7687
7766
|
return class ProjectionNode {
|
|
7767
|
+
/**
|
|
7768
|
+
* Create the projection node of a `motion` component's VisualElement,
|
|
7769
|
+
* from its props. This runs while the component renders, before its
|
|
7770
|
+
* children. It's here rather than in the component so React
|
|
7771
|
+
* bundles only include it with the features that supply a
|
|
7772
|
+
* ProjectionNode. Vanilla bundles that use the projection node
|
|
7773
|
+
* (drag(), animateLayout()) include it too, as a class static
|
|
7774
|
+
* can't be tree-shaken.
|
|
7775
|
+
*/
|
|
7776
|
+
static create(visualElement, props, initialPromotionConfig) {
|
|
7777
|
+
const { layoutId, layout, drag, dragConstraints, layoutScroll, layoutRoot, layoutAnchor, layoutCrossfade, } = props;
|
|
7778
|
+
const projection = (visualElement.projection = new this(visualElement.latestValues, props["data-framer-portal-id"]
|
|
7779
|
+
? undefined
|
|
7780
|
+
: getClosestProjectingNode(visualElement.parent)));
|
|
7781
|
+
projection.setOptions({
|
|
7782
|
+
layoutId,
|
|
7783
|
+
layout,
|
|
7784
|
+
alwaysMeasureLayout: Boolean(drag) ||
|
|
7785
|
+
(dragConstraints && isRefObject(dragConstraints)),
|
|
7786
|
+
visualElement,
|
|
7787
|
+
/**
|
|
7788
|
+
* TODO: Update options in an effect. This could be tricky as it'll be too late
|
|
7789
|
+
* to update by the time layout animations run.
|
|
7790
|
+
* We also need to fix this safeToRemove by linking it up to the one returned by usePresence,
|
|
7791
|
+
* ensuring it gets called if there's no potential layout animations.
|
|
7792
|
+
*
|
|
7793
|
+
*/
|
|
7794
|
+
animationType: typeof layout === "string" ? layout : "both",
|
|
7795
|
+
initialPromotionConfig,
|
|
7796
|
+
crossfade: layoutCrossfade,
|
|
7797
|
+
layoutScroll,
|
|
7798
|
+
layoutRoot,
|
|
7799
|
+
layoutAnchor,
|
|
7800
|
+
});
|
|
7801
|
+
/**
|
|
7802
|
+
* This node will take over from its layoutId's current lead, so snapshot
|
|
7803
|
+
* the lead now, while rendering. By the time the lead unmounts (or this
|
|
7804
|
+
* node mounts) React may already have committed DOM changes that come
|
|
7805
|
+
* before it in the tree, like a sibling changing height, and a snapshot
|
|
7806
|
+
* taken then starts the animation from a position never seen on screen.
|
|
7807
|
+
*
|
|
7808
|
+
* If React discards this render (e.g. it suspends), nothing else
|
|
7809
|
+
* completes the update, so check it after the next frame as an
|
|
7810
|
+
* unmounting node does.
|
|
7811
|
+
*/
|
|
7812
|
+
const lead = projection.getStack()?.lead;
|
|
7813
|
+
if (lead && !projection.root.isUpdateBlocked()) {
|
|
7814
|
+
lead.willUpdate();
|
|
7815
|
+
lead.scheduleCheckAfterUnmount();
|
|
7816
|
+
}
|
|
7817
|
+
}
|
|
7688
7818
|
constructor(latestValues = {}, parent = defaultParent?.()) {
|
|
7689
7819
|
/**
|
|
7690
7820
|
* A unique ID generated for every projection node.
|
|
@@ -7797,23 +7927,14 @@
|
|
|
7797
7927
|
*/
|
|
7798
7928
|
this.updateProjection = () => {
|
|
7799
7929
|
this.projectionUpdateScheduled = false;
|
|
7800
|
-
/**
|
|
7801
|
-
* Reset debug counts. Manually resetting rather than creating a new
|
|
7802
|
-
* object each frame.
|
|
7803
|
-
*/
|
|
7804
|
-
if (statsBuffer.value) {
|
|
7805
|
-
metrics.nodes =
|
|
7806
|
-
metrics.calculatedTargetDeltas =
|
|
7807
|
-
metrics.calculatedProjections =
|
|
7808
|
-
0;
|
|
7809
|
-
}
|
|
7810
7930
|
this.nodes.forEach(propagateDirtyNodes);
|
|
7811
7931
|
this.nodes.forEach(resolveTargetDelta);
|
|
7812
7932
|
this.nodes.forEach(calcProjection);
|
|
7813
7933
|
this.nodes.forEach(cleanDirtyNodes);
|
|
7814
|
-
|
|
7815
|
-
|
|
7816
|
-
|
|
7934
|
+
/**
|
|
7935
|
+
* Record this frame's debug counts, if recordStats() is running.
|
|
7936
|
+
*/
|
|
7937
|
+
statsBuffer.countProjection?.();
|
|
7817
7938
|
};
|
|
7818
7939
|
/**
|
|
7819
7940
|
* Frame calculations
|
|
@@ -8529,9 +8650,7 @@
|
|
|
8529
8650
|
/**
|
|
8530
8651
|
* Increase debug counter for resolved target deltas
|
|
8531
8652
|
*/
|
|
8532
|
-
|
|
8533
|
-
metrics.calculatedTargetDeltas++;
|
|
8534
|
-
}
|
|
8653
|
+
statsBuffer.countProjection?.(1); // calculatedTargetDeltas
|
|
8535
8654
|
}
|
|
8536
8655
|
getClosestProjectingParent() {
|
|
8537
8656
|
if (!this.parent ||
|
|
@@ -8679,9 +8798,7 @@
|
|
|
8679
8798
|
/**
|
|
8680
8799
|
* Increase debug counter for recalculated projections
|
|
8681
8800
|
*/
|
|
8682
|
-
|
|
8683
|
-
metrics.calculatedProjections++;
|
|
8684
|
-
}
|
|
8801
|
+
statsBuffer.countProjection?.(2); // calculatedProjections
|
|
8685
8802
|
}
|
|
8686
8803
|
hide() {
|
|
8687
8804
|
this.isVisible = false;
|
|
@@ -9208,9 +9325,7 @@
|
|
|
9208
9325
|
/**
|
|
9209
9326
|
* Increase debug counter for nodes encountered this frame
|
|
9210
9327
|
*/
|
|
9211
|
-
|
|
9212
|
-
metrics.nodes++;
|
|
9213
|
-
}
|
|
9328
|
+
statsBuffer.countProjection?.(0); // nodes
|
|
9214
9329
|
if (!node.parent)
|
|
9215
9330
|
return;
|
|
9216
9331
|
/**
|
|
@@ -9341,26 +9456,6 @@
|
|
|
9341
9456
|
duration: 0.45,
|
|
9342
9457
|
ease: [0.4, 0, 0.1, 1],
|
|
9343
9458
|
};
|
|
9344
|
-
const userAgentContains = (string) => typeof navigator !== "undefined" &&
|
|
9345
|
-
navigator.userAgent &&
|
|
9346
|
-
navigator.userAgent.toLowerCase().includes(string);
|
|
9347
|
-
/**
|
|
9348
|
-
* Measured bounding boxes must be rounded in Safari and
|
|
9349
|
-
* left untouched in Chrome, otherwise non-integer layouts within scaled-up elements
|
|
9350
|
-
* can appear to jump.
|
|
9351
|
-
*/
|
|
9352
|
-
const roundPoint = userAgentContains("applewebkit/") && !userAgentContains("chrome/")
|
|
9353
|
-
? Math.round
|
|
9354
|
-
: noop;
|
|
9355
|
-
function roundAxis(axis) {
|
|
9356
|
-
// Round to the nearest .5 pixels to support subpixel layouts
|
|
9357
|
-
axis.min = roundPoint(axis.min);
|
|
9358
|
-
axis.max = roundPoint(axis.max);
|
|
9359
|
-
}
|
|
9360
|
-
function roundBox(box) {
|
|
9361
|
-
roundAxis(box.x);
|
|
9362
|
-
roundAxis(box.y);
|
|
9363
|
-
}
|
|
9364
9459
|
/**
|
|
9365
9460
|
* Align an axis to the start of another, keeping the length of a layout axis.
|
|
9366
9461
|
* The length is read first, as output can be the layout axis itself.
|
|
@@ -9385,14 +9480,7 @@
|
|
|
9385
9480
|
const DocumentProjectionNode =
|
|
9386
9481
|
/* @__PURE__ */ createProjectionNode({
|
|
9387
9482
|
attachResizeListener: (ref, notify) => addDomEvent(ref, "resize", notify),
|
|
9388
|
-
measureScroll:
|
|
9389
|
-
x: document.documentElement.scrollLeft ||
|
|
9390
|
-
document.body?.scrollLeft ||
|
|
9391
|
-
0,
|
|
9392
|
-
y: document.documentElement.scrollTop ||
|
|
9393
|
-
document.body?.scrollTop ||
|
|
9394
|
-
0,
|
|
9395
|
-
}),
|
|
9483
|
+
measureScroll: measureDocumentScroll,
|
|
9396
9484
|
checkIsScrollRoot: () => true,
|
|
9397
9485
|
});
|
|
9398
9486
|
|
|
@@ -9694,9 +9782,10 @@
|
|
|
9694
9782
|
/**
|
|
9695
9783
|
* If this element has been mounted before (e.g. after a Suspense
|
|
9696
9784
|
* unmount/remount), reset motion values to their initial state
|
|
9697
|
-
* so animations replay correctly from initial → animate
|
|
9785
|
+
* so animations replay correctly from initial → animate, unless
|
|
9786
|
+
* the presence asks to keep them.
|
|
9698
9787
|
*/
|
|
9699
|
-
if (this.hasBeenMounted) {
|
|
9788
|
+
if (this.hasBeenMounted && !this.presenceContext?.keepValuesOnRemount) {
|
|
9700
9789
|
for (const key in this.initialValues) {
|
|
9701
9790
|
this.values.get(key)?.jump(this.initialValues[key]);
|
|
9702
9791
|
this.latestValues[key] = this.initialValues[key];
|
|
@@ -10165,6 +10254,124 @@
|
|
|
10165
10254
|
}
|
|
10166
10255
|
}
|
|
10167
10256
|
|
|
10257
|
+
/**
|
|
10258
|
+
* Get the VisualElement that imperative APIs like animateLayout() and
|
|
10259
|
+
* drag() render an element with, creating one if it has none, ready for
|
|
10260
|
+
* a projection node to be attached.
|
|
10261
|
+
*/
|
|
10262
|
+
function resolveVisualElement(element) {
|
|
10263
|
+
let visualElement = visualElementStore.get(element);
|
|
10264
|
+
if (!visualElement) {
|
|
10265
|
+
visualElement = new HTMLVisualElement({
|
|
10266
|
+
props: {},
|
|
10267
|
+
presenceContext: null,
|
|
10268
|
+
visualState: {
|
|
10269
|
+
latestValues: {},
|
|
10270
|
+
renderState: {
|
|
10271
|
+
transform: {},
|
|
10272
|
+
transformOrigin: {},
|
|
10273
|
+
style: {},
|
|
10274
|
+
vars: {},
|
|
10275
|
+
},
|
|
10276
|
+
},
|
|
10277
|
+
}, { allowProjection: true });
|
|
10278
|
+
/**
|
|
10279
|
+
* Values animate() has been rendering on this element move to
|
|
10280
|
+
* the VisualElement, so the layout animation composes with
|
|
10281
|
+
* them instead of overwriting them.
|
|
10282
|
+
*/
|
|
10283
|
+
handOffElementState(element, visualElement);
|
|
10284
|
+
}
|
|
10285
|
+
/**
|
|
10286
|
+
* A first-time element may carry a projection transform in its
|
|
10287
|
+
* inline style (e.g. it was cloned from an element mid-animation).
|
|
10288
|
+
* That transform isn't tracked in latestValues so the engine can't
|
|
10289
|
+
* reset it before measuring - clear it now so the first layout
|
|
10290
|
+
* measurement isn't inflated.
|
|
10291
|
+
*/
|
|
10292
|
+
if (element.style.transform && !hasTransform(visualElement.latestValues)) {
|
|
10293
|
+
element.style.transform = "";
|
|
10294
|
+
}
|
|
10295
|
+
return visualElement;
|
|
10296
|
+
}
|
|
10297
|
+
|
|
10298
|
+
/**
|
|
10299
|
+
* animateLayout() registers a function here that creates nodes in the
|
|
10300
|
+
* layout projection tree. When it's in the bundle, drag() uses those, so
|
|
10301
|
+
* the two work together (e.g. a drag follows a layout change mid-gesture).
|
|
10302
|
+
* Otherwise drag() makes do with a node that only measures. Bundles that
|
|
10303
|
+
* don't tree-shake (dev pre-bundling, CDN builds) always register it, and
|
|
10304
|
+
* a drag() started before animateLayout() is lazy loaded keeps its node.
|
|
10305
|
+
*/
|
|
10306
|
+
const layoutProjection = {};
|
|
10307
|
+
/**
|
|
10308
|
+
* The document root of measurement-only nodes. Like the projection tree's
|
|
10309
|
+
* root, it keeps its scroll until drag controls clear it to re-measure.
|
|
10310
|
+
*/
|
|
10311
|
+
const root = {
|
|
10312
|
+
updateScroll: () => {
|
|
10313
|
+
root.scroll || (root.scroll = { offset: measureDocumentScroll() });
|
|
10314
|
+
},
|
|
10315
|
+
};
|
|
10316
|
+
/**
|
|
10317
|
+
* The part of a projection node that drag controls use: measuring the
|
|
10318
|
+
* element's page box, for its layout and constraints. It never projects
|
|
10319
|
+
* or joins a layout update.
|
|
10320
|
+
*/
|
|
10321
|
+
const createMeasureNode = (element) => {
|
|
10322
|
+
const visualElement = resolveVisualElement(element);
|
|
10323
|
+
const measureListeners = new SubscriptionManager();
|
|
10324
|
+
const node = {
|
|
10325
|
+
instance: element,
|
|
10326
|
+
root,
|
|
10327
|
+
path: [root],
|
|
10328
|
+
setOptions: noop,
|
|
10329
|
+
/**
|
|
10330
|
+
* Truthy like the full node's method, which HTMLVisualElement reads
|
|
10331
|
+
* (rather than calls) to default transform values.
|
|
10332
|
+
*/
|
|
10333
|
+
isProjecting: noop,
|
|
10334
|
+
applyProjectionStyles: noop,
|
|
10335
|
+
removeElementScroll: (box) => box,
|
|
10336
|
+
updateLayout: () => {
|
|
10337
|
+
const layoutBox = measurePageBox(element, root, visualElement.getTransformPagePoint());
|
|
10338
|
+
roundBox(layoutBox);
|
|
10339
|
+
node.layout = { layoutBox };
|
|
10340
|
+
measureListeners.notify();
|
|
10341
|
+
},
|
|
10342
|
+
addEventListener: (name, handler) => name === "measure" ? measureListeners.add(handler) : noop,
|
|
10343
|
+
/**
|
|
10344
|
+
* Detach from the VisualElement too, so it doesn't later remount
|
|
10345
|
+
* (or a `motion` component's layout feature adopt) a node that
|
|
10346
|
+
* can't do either.
|
|
10347
|
+
*/
|
|
10348
|
+
unmount: () => {
|
|
10349
|
+
node.instance = undefined;
|
|
10350
|
+
if (visualElement.projection === node) {
|
|
10351
|
+
visualElement.projection = undefined;
|
|
10352
|
+
}
|
|
10353
|
+
},
|
|
10354
|
+
};
|
|
10355
|
+
visualElement.projection = node;
|
|
10356
|
+
visualElement.current || visualElement.mount(element);
|
|
10357
|
+
return [node, node.unmount];
|
|
10358
|
+
};
|
|
10359
|
+
/**
|
|
10360
|
+
* Get a projection node for drag() to measure an element with, and a
|
|
10361
|
+
* function that releases it. Reuses a node a `motion` component or
|
|
10362
|
+
* animateLayout() owns.
|
|
10363
|
+
*/
|
|
10364
|
+
const acquireDragNode = (element) => {
|
|
10365
|
+
const owned = visualElementStore.get(element)?.projection;
|
|
10366
|
+
/**
|
|
10367
|
+
* A VisualElement can outlive its node (e.g. an unmounted `motion`
|
|
10368
|
+
* component's), so only reuse a node that's still mounted.
|
|
10369
|
+
*/
|
|
10370
|
+
return owned?.instance
|
|
10371
|
+
? [owned, noop]
|
|
10372
|
+
: (layoutProjection.create || createMeasureNode)(element);
|
|
10373
|
+
};
|
|
10374
|
+
|
|
10168
10375
|
const layoutSelector = "[data-layout],[data-layout-id]";
|
|
10169
10376
|
/**
|
|
10170
10377
|
* All imperatively-created projection nodes live in one persistent tree,
|
|
@@ -10217,21 +10424,6 @@
|
|
|
10217
10424
|
}
|
|
10218
10425
|
return undefined;
|
|
10219
10426
|
}
|
|
10220
|
-
function createVisualElement() {
|
|
10221
|
-
return new HTMLVisualElement({
|
|
10222
|
-
props: {},
|
|
10223
|
-
presenceContext: null,
|
|
10224
|
-
visualState: {
|
|
10225
|
-
latestValues: {},
|
|
10226
|
-
renderState: {
|
|
10227
|
-
transform: {},
|
|
10228
|
-
transformOrigin: {},
|
|
10229
|
-
style: {},
|
|
10230
|
-
vars: {},
|
|
10231
|
-
},
|
|
10232
|
-
},
|
|
10233
|
-
}, { allowProjection: true });
|
|
10234
|
-
}
|
|
10235
10427
|
function readNodeOptions(element, transition) {
|
|
10236
10428
|
const layoutAttr = element.getAttribute("data-layout");
|
|
10237
10429
|
const layoutId = element.getAttribute("data-layout-id") ?? undefined;
|
|
@@ -10247,27 +10439,7 @@
|
|
|
10247
10439
|
function prepareNode(element, transition) {
|
|
10248
10440
|
let node = layoutNodes.get(element);
|
|
10249
10441
|
if (!node) {
|
|
10250
|
-
|
|
10251
|
-
if (!visualElement) {
|
|
10252
|
-
visualElement = createVisualElement();
|
|
10253
|
-
/**
|
|
10254
|
-
* Values animate() has been rendering on this element move to
|
|
10255
|
-
* the VisualElement, so the layout animation composes with
|
|
10256
|
-
* them instead of overwriting them.
|
|
10257
|
-
*/
|
|
10258
|
-
handOffElementState(element, visualElement);
|
|
10259
|
-
}
|
|
10260
|
-
/**
|
|
10261
|
-
* A first-time element may carry a projection transform in its
|
|
10262
|
-
* inline style (e.g. it was cloned from an element mid-animation).
|
|
10263
|
-
* That transform isn't tracked in latestValues so the engine can't
|
|
10264
|
-
* reset it before measuring - clear it now so the first layout
|
|
10265
|
-
* measurement isn't inflated.
|
|
10266
|
-
*/
|
|
10267
|
-
if (element.style.transform &&
|
|
10268
|
-
!hasTransform(visualElement.latestValues)) {
|
|
10269
|
-
element.style.transform = "";
|
|
10270
|
-
}
|
|
10442
|
+
const visualElement = resolveVisualElement(element);
|
|
10271
10443
|
node = new HTMLProjectionNode(visualElement.latestValues, getProjectionParent(element));
|
|
10272
10444
|
visualElement.projection = node;
|
|
10273
10445
|
node.setOptions({
|
|
@@ -10287,10 +10459,26 @@
|
|
|
10287
10459
|
return node;
|
|
10288
10460
|
}
|
|
10289
10461
|
/**
|
|
10290
|
-
*
|
|
10291
|
-
*
|
|
10292
|
-
|
|
10293
|
-
|
|
10462
|
+
* Create a node for an element in the shared imperative tree. Returns the
|
|
10463
|
+
* node and a function that releases it.
|
|
10464
|
+
*/
|
|
10465
|
+
function createLayoutNode(element) {
|
|
10466
|
+
const node = prepareNode(element);
|
|
10467
|
+
return [
|
|
10468
|
+
node,
|
|
10469
|
+
() => layoutNodes.get(element) === node && dropNode(element, node),
|
|
10470
|
+
];
|
|
10471
|
+
}
|
|
10472
|
+
/**
|
|
10473
|
+
* Let drag() create its nodes in the shared imperative tree, so drag
|
|
10474
|
+
* gestures and layout animations work together.
|
|
10475
|
+
*/
|
|
10476
|
+
layoutProjection.create = createLayoutNode;
|
|
10477
|
+
/**
|
|
10478
|
+
* Get a projection node for an element, so motion/remix can measure and
|
|
10479
|
+
* animate its layout. Reuses a node owned by a `motion` component or
|
|
10480
|
+
* animateLayout(), otherwise creates one in the shared imperative tree.
|
|
10481
|
+
* Returns the node and a function that releases it.
|
|
10294
10482
|
*/
|
|
10295
10483
|
function acquireProjectionNode(element) {
|
|
10296
10484
|
const owned = layoutNodes.get(element) || visualElementStore.get(element)?.projection;
|
|
@@ -10298,13 +10486,7 @@
|
|
|
10298
10486
|
* A VisualElement can outlive a node we released (e.g. a stopped
|
|
10299
10487
|
* drag()), so only reuse a node that's still mounted.
|
|
10300
10488
|
*/
|
|
10301
|
-
|
|
10302
|
-
return [owned, () => { }];
|
|
10303
|
-
const node = prepareNode(element);
|
|
10304
|
-
return [
|
|
10305
|
-
node,
|
|
10306
|
-
() => layoutNodes.get(element) === node && dropNode(element, node),
|
|
10307
|
-
];
|
|
10489
|
+
return owned?.instance ? [owned, () => { }] : createLayoutNode(element);
|
|
10308
10490
|
}
|
|
10309
10491
|
function sortDocumentOrder(elements) {
|
|
10310
10492
|
return [...elements].sort((a, b) => a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1);
|
|
@@ -10324,6 +10506,8 @@
|
|
|
10324
10506
|
}
|
|
10325
10507
|
function flushPendingBuilders() {
|
|
10326
10508
|
const builders = pendingBuilders;
|
|
10509
|
+
if (!builders)
|
|
10510
|
+
return;
|
|
10327
10511
|
pendingBuilders = undefined;
|
|
10328
10512
|
flushPendingFrame();
|
|
10329
10513
|
/**
|
|
@@ -10388,6 +10572,13 @@
|
|
|
10388
10572
|
};
|
|
10389
10573
|
updatePromises.length ? Promise.all(updatePromises).then(commit) : commit();
|
|
10390
10574
|
}
|
|
10575
|
+
/**
|
|
10576
|
+
* Snapshot every pending animateLayout() now, rather than on the next
|
|
10577
|
+
* microtask. For renderers that tell us a DOM update is about to happen
|
|
10578
|
+
* and then make it synchronously (e.g. a beforeUpdate/commit pair), with
|
|
10579
|
+
* updateDom returning a promise that resolves on commit.
|
|
10580
|
+
*/
|
|
10581
|
+
const flushLayoutSnapshots = flushPendingBuilders;
|
|
10391
10582
|
class LayoutAnimationBuilder {
|
|
10392
10583
|
constructor(scope, updateDom, defaultOptions) {
|
|
10393
10584
|
this.scope = scope;
|
|
@@ -11165,7 +11356,7 @@
|
|
|
11165
11356
|
};
|
|
11166
11357
|
const onStart = (event, info) => {
|
|
11167
11358
|
// Attempt to grab the global drag gesture lock - maybe make this part of PanSession
|
|
11168
|
-
const { drag, dragPropagation, onDragStart } = this.getProps();
|
|
11359
|
+
const { drag, dragConstraints, dragPropagation, onDragStart } = this.getProps();
|
|
11169
11360
|
if (drag && !dragPropagation) {
|
|
11170
11361
|
this.openDragLock?.();
|
|
11171
11362
|
this.openDragLock = setDragLock(drag);
|
|
@@ -11212,6 +11403,8 @@
|
|
|
11212
11403
|
}
|
|
11213
11404
|
this.originPoint[axis] = current;
|
|
11214
11405
|
});
|
|
11406
|
+
this.point =
|
|
11407
|
+
typeof dragConstraints === "function" && dragConstraints(this);
|
|
11215
11408
|
// Fire onDragStart event
|
|
11216
11409
|
if (onDragStart) {
|
|
11217
11410
|
frame.update(() => onDragStart(event, info), false, true);
|
|
@@ -11242,6 +11435,7 @@
|
|
|
11242
11435
|
// Update each point with the latest position
|
|
11243
11436
|
this.updateAxis("x", offset);
|
|
11244
11437
|
this.updateAxis("y", offset);
|
|
11438
|
+
this.point && this.point.move();
|
|
11245
11439
|
/**
|
|
11246
11440
|
* Ideally we would leave the renderer to fire naturally at the end of
|
|
11247
11441
|
* this frame but if the element is about to change layout as the result
|
|
@@ -11266,7 +11460,7 @@
|
|
|
11266
11460
|
};
|
|
11267
11461
|
const resumeAnimation = () => {
|
|
11268
11462
|
const { dragSnapToOrigin: snap } = this.getProps();
|
|
11269
|
-
if (snap || this.constraints) {
|
|
11463
|
+
if (snap || this.constraints || this.point) {
|
|
11270
11464
|
this.startAnimation({ x: 0, y: 0 });
|
|
11271
11465
|
}
|
|
11272
11466
|
};
|
|
@@ -11341,7 +11535,7 @@
|
|
|
11341
11535
|
if (constraints) {
|
|
11342
11536
|
next = applyConstraints(next, constraints, this.elastic[axis]);
|
|
11343
11537
|
}
|
|
11344
|
-
axisValue.set(next);
|
|
11538
|
+
this.point ? (this.point[axis] = next) : axisValue.set(next);
|
|
11345
11539
|
}
|
|
11346
11540
|
resolveConstraints() {
|
|
11347
11541
|
const { dragConstraints, dragElastic } = this.getProps();
|
|
@@ -11362,7 +11556,9 @@
|
|
|
11362
11556
|
}
|
|
11363
11557
|
}
|
|
11364
11558
|
else {
|
|
11365
|
-
if (dragConstraints &&
|
|
11559
|
+
if (dragConstraints &&
|
|
11560
|
+
layout &&
|
|
11561
|
+
typeof dragConstraints === "object") {
|
|
11366
11562
|
this.constraints = calcRelativeConstraints(layout.layoutBox, dragConstraints);
|
|
11367
11563
|
}
|
|
11368
11564
|
else {
|
|
@@ -11429,6 +11625,30 @@
|
|
|
11429
11625
|
}
|
|
11430
11626
|
startAnimation(velocity, dragAxes) {
|
|
11431
11627
|
const { drag, dragMomentum, dragElastic, dragTransition, dragSnapToOrigin, onDragTransitionEnd, } = this.getProps();
|
|
11628
|
+
/**
|
|
11629
|
+
* Overdamp the boundary spring if `dragElastic` is disabled. There's still a frame
|
|
11630
|
+
* of spring animations so we should look into adding a disable spring option to `inertia`.
|
|
11631
|
+
* We could do something here where we affect the `bounceStiffness` and `bounceDamping`
|
|
11632
|
+
* using the value of `dragElastic`.
|
|
11633
|
+
*/
|
|
11634
|
+
const options = {
|
|
11635
|
+
bounceStiffness: dragElastic ? 200 : 1000000,
|
|
11636
|
+
bounceDamping: dragElastic ? 40 : 10000000,
|
|
11637
|
+
timeConstant: 750,
|
|
11638
|
+
restDelta: 1,
|
|
11639
|
+
restSpeed: 10,
|
|
11640
|
+
...dragTransition,
|
|
11641
|
+
};
|
|
11642
|
+
const axisVelocity = (axis) => dragMomentum &&
|
|
11643
|
+
!(this.point && dragSnapToOrigin) &&
|
|
11644
|
+
shouldDrag(axis, dragAxes || drag, this.currentDirection)
|
|
11645
|
+
? velocity[axis]
|
|
11646
|
+
: 0;
|
|
11647
|
+
if (this.point && !dragSnapToOrigin) {
|
|
11648
|
+
return this.point
|
|
11649
|
+
.release({ x: axisVelocity("x"), y: axisVelocity("y") }, options)
|
|
11650
|
+
.then(onDragTransitionEnd);
|
|
11651
|
+
}
|
|
11432
11652
|
const constraints = this.constraints || {};
|
|
11433
11653
|
const momentumAnimations = eachAxis((axis) => {
|
|
11434
11654
|
if (!shouldDrag(axis, dragAxes || drag, this.currentDirection)) {
|
|
@@ -11438,23 +11658,10 @@
|
|
|
11438
11658
|
if (dragSnapToOrigin === true ||
|
|
11439
11659
|
dragSnapToOrigin === axis)
|
|
11440
11660
|
transition = { min: 0, max: 0 };
|
|
11441
|
-
/**
|
|
11442
|
-
* Overdamp the boundary spring if `dragElastic` is disabled. There's still a frame
|
|
11443
|
-
* of spring animations so we should look into adding a disable spring option to `inertia`.
|
|
11444
|
-
* We could do something here where we affect the `bounceStiffness` and `bounceDamping`
|
|
11445
|
-
* using the value of `dragElastic`.
|
|
11446
|
-
*/
|
|
11447
|
-
const bounceStiffness = dragElastic ? 200 : 1000000;
|
|
11448
|
-
const bounceDamping = dragElastic ? 40 : 10000000;
|
|
11449
11661
|
const inertia = {
|
|
11450
11662
|
type: "inertia",
|
|
11451
|
-
velocity:
|
|
11452
|
-
|
|
11453
|
-
bounceDamping,
|
|
11454
|
-
timeConstant: 750,
|
|
11455
|
-
restDelta: 1,
|
|
11456
|
-
restSpeed: 10,
|
|
11457
|
-
...dragTransition,
|
|
11663
|
+
velocity: axisVelocity(axis),
|
|
11664
|
+
...options,
|
|
11458
11665
|
...transition,
|
|
11459
11666
|
};
|
|
11460
11667
|
// If we're not animating on an externally-provided `MotionValue` we can use the
|
|
@@ -11785,13 +11992,13 @@
|
|
|
11785
11992
|
}
|
|
11786
11993
|
const cleanups = resolveElements(elementOrSelector).map((element) => {
|
|
11787
11994
|
scope?.track(element);
|
|
11788
|
-
const [node, release] =
|
|
11995
|
+
const [node, release] = acquireDragNode(element);
|
|
11789
11996
|
/**
|
|
11790
11997
|
* Measure layout even when not animating it, as constraints and
|
|
11791
11998
|
* layout-shift correction are computed from it.
|
|
11792
11999
|
*/
|
|
11793
12000
|
node.setOptions({ alwaysMeasureLayout: true });
|
|
11794
|
-
const controls = new VisualElementDragControls(
|
|
12001
|
+
const controls = new VisualElementDragControls(visualElementStore.get(element), () => props);
|
|
11795
12002
|
const removeListeners = controls.addListeners();
|
|
11796
12003
|
const removeStyles = applyDragStyles(element, options.axis);
|
|
11797
12004
|
return () => {
|
|
@@ -12197,9 +12404,19 @@
|
|
|
12197
12404
|
return scope;
|
|
12198
12405
|
}
|
|
12199
12406
|
|
|
12407
|
+
/**
|
|
12408
|
+
* The metrics projection counts, in the order of the index it passes to
|
|
12409
|
+
* statsBuffer.countProjection.
|
|
12410
|
+
*/
|
|
12411
|
+
const projectionMetrics = [
|
|
12412
|
+
"nodes",
|
|
12413
|
+
"calculatedTargetDeltas",
|
|
12414
|
+
"calculatedProjections",
|
|
12415
|
+
];
|
|
12200
12416
|
function clearStatsBuffer() {
|
|
12201
12417
|
statsBuffer.value = null;
|
|
12202
12418
|
statsBuffer.addProjectionMetrics = null;
|
|
12419
|
+
statsBuffer.countProjection = undefined;
|
|
12203
12420
|
}
|
|
12204
12421
|
function recordStats() {
|
|
12205
12422
|
if (statsBuffer.value) {
|
|
@@ -12220,6 +12437,27 @@
|
|
|
12220
12437
|
layoutProjection.calculatedTargetDeltas.push(metrics.calculatedTargetDeltas);
|
|
12221
12438
|
layoutProjection.calculatedProjections.push(metrics.calculatedProjections);
|
|
12222
12439
|
};
|
|
12440
|
+
/**
|
|
12441
|
+
* Counting lives here rather than in projection, so bundles that never
|
|
12442
|
+
* call recordStats() don't ship it.
|
|
12443
|
+
*/
|
|
12444
|
+
const metrics = {
|
|
12445
|
+
nodes: 0,
|
|
12446
|
+
calculatedTargetDeltas: 0,
|
|
12447
|
+
calculatedProjections: 0,
|
|
12448
|
+
};
|
|
12449
|
+
buffer.countProjection = (metric) => {
|
|
12450
|
+
if (metric !== undefined) {
|
|
12451
|
+
metrics[projectionMetrics[metric]]++;
|
|
12452
|
+
}
|
|
12453
|
+
else {
|
|
12454
|
+
buffer.addProjectionMetrics(metrics);
|
|
12455
|
+
metrics.nodes =
|
|
12456
|
+
metrics.calculatedTargetDeltas =
|
|
12457
|
+
metrics.calculatedProjections =
|
|
12458
|
+
0;
|
|
12459
|
+
}
|
|
12460
|
+
};
|
|
12223
12461
|
}
|
|
12224
12462
|
|
|
12225
12463
|
function getOriginIndex(from, total) {
|
|
@@ -14578,6 +14816,11 @@
|
|
|
14578
14816
|
const valueKeyframesAsList = keyframesAsList(valueKeyframes);
|
|
14579
14817
|
const { delay = 0, times = defaultOffset$1(valueKeyframesAsList), type = defaultTransition.type || "keyframes", repeat, repeatType, repeatDelay = 0, ...remainingTransition } = valueTransition;
|
|
14580
14818
|
let { ease = defaultTransition.ease || "easeOut", duration } = valueTransition;
|
|
14819
|
+
/**
|
|
14820
|
+
* The value animates as one, so it takes the first mixer
|
|
14821
|
+
* given for it, or else the default transition's.
|
|
14822
|
+
*/
|
|
14823
|
+
valueSequence.mixer || (valueSequence.mixer = valueTransition.mixer);
|
|
14581
14824
|
/**
|
|
14582
14825
|
* Resolve stagger() if defined.
|
|
14583
14826
|
*/
|
|
@@ -14811,6 +15054,7 @@
|
|
|
14811
15054
|
duration: totalDuration,
|
|
14812
15055
|
ease: valueEasing,
|
|
14813
15056
|
times: valueOffset,
|
|
15057
|
+
mixer: valueSequence.mixer || defaultTransition.mixer,
|
|
14814
15058
|
...sequenceTransition,
|
|
14815
15059
|
};
|
|
14816
15060
|
}
|
|
@@ -14977,6 +15221,16 @@
|
|
|
14977
15221
|
this.isDone = false;
|
|
14978
15222
|
this.isRebuilding = false;
|
|
14979
15223
|
this.playbackSpeed = 1;
|
|
15224
|
+
/**
|
|
15225
|
+
* The scopeMotion() scope this was created in. Rebuilds run in it, so
|
|
15226
|
+
* selectors resolve in its root and cancel() restores what they
|
|
15227
|
+
* animate.
|
|
15228
|
+
*/
|
|
15229
|
+
this.motionScope = activeScope.current;
|
|
15230
|
+
/**
|
|
15231
|
+
* Set when the scope stops, so later changes don't restart it.
|
|
15232
|
+
*/
|
|
15233
|
+
this.isKilled = false;
|
|
14980
15234
|
/**
|
|
14981
15235
|
* True while this plays the animations it was created with, before
|
|
14982
15236
|
* any change compiles it as a sequence.
|
|
@@ -15206,7 +15460,7 @@
|
|
|
15206
15460
|
* reflect it.
|
|
15207
15461
|
*/
|
|
15208
15462
|
flush() {
|
|
15209
|
-
this.isDirty && !this.parent && this.build();
|
|
15463
|
+
this.isDirty && !this.parent && !this.isKilled && this.build();
|
|
15210
15464
|
}
|
|
15211
15465
|
adopt(parent) {
|
|
15212
15466
|
if (this.group) {
|
|
@@ -15252,7 +15506,15 @@
|
|
|
15252
15506
|
Object.assign(playback, options);
|
|
15253
15507
|
const markers = new Map();
|
|
15254
15508
|
const info = {};
|
|
15255
|
-
const
|
|
15509
|
+
const prevScope = activeScope.current;
|
|
15510
|
+
activeScope.current = this.motionScope;
|
|
15511
|
+
let animations;
|
|
15512
|
+
try {
|
|
15513
|
+
animations = animateSequence(this.toSequence(markers), { defaultTransition, ...playback }, scope, info);
|
|
15514
|
+
}
|
|
15515
|
+
finally {
|
|
15516
|
+
activeScope.current = prevScope;
|
|
15517
|
+
}
|
|
15256
15518
|
const labels = info.labels;
|
|
15257
15519
|
let duration = playback.duration ?? info.duration;
|
|
15258
15520
|
/**
|
|
@@ -15424,6 +15686,15 @@
|
|
|
15424
15686
|
this.finished = new Promise((resolve) => {
|
|
15425
15687
|
this.resolveFinished = resolve;
|
|
15426
15688
|
});
|
|
15689
|
+
/**
|
|
15690
|
+
* Stay in the scope while playing, including after a change
|
|
15691
|
+
* restarts a finished timeline.
|
|
15692
|
+
*/
|
|
15693
|
+
const remove = this.motionScope?.add(() => {
|
|
15694
|
+
this.isKilled = true;
|
|
15695
|
+
this.stop();
|
|
15696
|
+
});
|
|
15697
|
+
remove && this.finished.then(remove);
|
|
15427
15698
|
}
|
|
15428
15699
|
}
|
|
15429
15700
|
|
|
@@ -15440,8 +15711,7 @@
|
|
|
15440
15711
|
* Implementation
|
|
15441
15712
|
*/
|
|
15442
15713
|
function scopedAnimate(subjectOrSequence, optionsOrKeyframes, options) {
|
|
15443
|
-
const
|
|
15444
|
-
const scopeTransition = motionScope?.transition;
|
|
15714
|
+
const scopeTransition = activeScope.current?.transition;
|
|
15445
15715
|
const inherited = {};
|
|
15446
15716
|
if (reduceMotion !== undefined)
|
|
15447
15717
|
inherited.reduceMotion = reduceMotion;
|
|
@@ -15490,9 +15760,6 @@
|
|
|
15490
15760
|
: [subjectOrSequence, optionsOrKeyframes, transition]);
|
|
15491
15761
|
timeline = new Timeline([segment], { ...inherited, onComplete, scope }, animateSubject(subjectOrSequence, optionsOrKeyframes, transition, scope));
|
|
15492
15762
|
}
|
|
15493
|
-
if (motionScope) {
|
|
15494
|
-
timeline.finished.then(motionScope.add(() => timeline.stop()));
|
|
15495
|
-
}
|
|
15496
15763
|
return timeline;
|
|
15497
15764
|
}
|
|
15498
15765
|
return scopedAnimate;
|
|
@@ -16297,6 +16564,7 @@
|
|
|
16297
16564
|
exports.VisualElement = VisualElement;
|
|
16298
16565
|
exports.VisualElementDragControls = VisualElementDragControls;
|
|
16299
16566
|
exports.acceleratedValues = acceleratedValues;
|
|
16567
|
+
exports.acquireProjectionNode = acquireProjectionNode;
|
|
16300
16568
|
exports.activeScope = activeScope;
|
|
16301
16569
|
exports.addAttrValue = addAttrValue;
|
|
16302
16570
|
exports.addBuilderToScope = addBuilderToScope;
|
|
@@ -16423,6 +16691,7 @@
|
|
|
16423
16691
|
exports.findEffect = findEffect;
|
|
16424
16692
|
exports.findValueType = findValueType;
|
|
16425
16693
|
exports.flushKeyframeResolvers = flushKeyframeResolvers;
|
|
16694
|
+
exports.flushLayoutSnapshots = flushLayoutSnapshots;
|
|
16426
16695
|
exports.followValue = followValue;
|
|
16427
16696
|
exports.frame = frame;
|
|
16428
16697
|
exports.frameData = frameData;
|