motion-dom 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/index.js +408 -168
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/JSAnimation.mjs +7 -1
- package/dist/es/animation/JSAnimation.mjs.map +1 -1
- package/dist/es/animation/generators/keyframes.mjs +12 -3
- package/dist/es/animation/generators/keyframes.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 +3 -1
- package/dist/es/animation/waapi/supports/waapi.mjs.map +1 -1
- package/dist/es/animation/waapi/transforms/TransformAnimation.mjs +31 -35
- package/dist/es/animation/waapi/transforms/TransformAnimation.mjs.map +1 -1
- package/dist/es/animation/waapi/utils/needs-mixer.mjs +11 -0
- package/dist/es/animation/waapi/utils/needs-mixer.mjs.map +1 -0
- package/dist/es/effects/svg/index.mjs +14 -0
- package/dist/es/effects/svg/index.mjs.map +1 -1
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +35 -19
- package/dist/es/gestures/drag/VisualElementDragControls.mjs.map +1 -1
- package/dist/es/gestures/drag/index.mjs +4 -3
- package/dist/es/gestures/drag/index.mjs.map +1 -1
- package/dist/es/gestures/drag/projection.mjs +85 -0
- package/dist/es/gestures/drag/projection.mjs.map +1 -0
- package/dist/es/index.mjs +1 -1
- package/dist/es/layout/LayoutAnimationBuilder.mjs +34 -51
- package/dist/es/layout/LayoutAnimationBuilder.mjs.map +1 -1
- package/dist/es/layout/visual-element.mjs +48 -0
- package/dist/es/layout/visual-element.mjs.map +1 -0
- package/dist/es/projection/geometry/round.mjs +25 -0
- package/dist/es/projection/geometry/round.mjs.map +1 -0
- package/dist/es/projection/node/DocumentProjectionNode.mjs +2 -8
- package/dist/es/projection/node/DocumentProjectionNode.mjs.map +1 -1
- package/dist/es/projection/node/create-projection-node.mjs +68 -48
- package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
- package/dist/es/projection/utils/measure.mjs +5 -1
- package/dist/es/projection/utils/measure.mjs.map +1 -1
- package/dist/es/render/VisualElement.mjs +3 -2
- package/dist/es/render/VisualElement.mjs.map +1 -1
- package/dist/es/stats/buffer.mjs +1 -0
- package/dist/es/stats/buffer.mjs.map +1 -1
- package/dist/es/stats/index.mjs +31 -0
- package/dist/es/stats/index.mjs.map +1 -1
- package/dist/es/utils/interpolate.mjs +3 -2
- package/dist/es/utils/interpolate.mjs.map +1 -1
- package/dist/es/utils/is-ref-object.mjs +8 -0
- package/dist/es/utils/is-ref-object.mjs.map +1 -0
- package/dist/es/utils/transform.mjs.map +1 -1
- package/dist/es/value/index.mjs +10 -1
- package/dist/es/value/index.mjs.map +1 -1
- package/dist/index.d.ts +2048 -1931
- package/dist/motion-dom.dev.js +408 -168
- 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 +2 -2
package/dist/motion-dom.dev.js
CHANGED
|
@@ -1308,10 +1308,11 @@
|
|
|
1308
1308
|
|
|
1309
1309
|
function createMixers(output, ease, customMixer) {
|
|
1310
1310
|
const mixers = [];
|
|
1311
|
-
const mixerFactory =
|
|
1311
|
+
const mixerFactory = motionUtils.MotionGlobalConfig.mix || mix;
|
|
1312
1312
|
const numMixers = output.length - 1;
|
|
1313
1313
|
for (let i = 0; i < numMixers; i++) {
|
|
1314
|
-
let mixer =
|
|
1314
|
+
let mixer = customMixer?.(output[i], output[i + 1]) ||
|
|
1315
|
+
mixerFactory(output[i], output[i + 1]);
|
|
1315
1316
|
if (ease) {
|
|
1316
1317
|
const easingFunction = Array.isArray(ease) ? ease[i] || motionUtils.noop : ease;
|
|
1317
1318
|
mixer = motionUtils.pipe(easingFunction, mixer);
|
|
@@ -1397,7 +1398,13 @@
|
|
|
1397
1398
|
function defaultEasing(values, easing) {
|
|
1398
1399
|
return values.map(() => easing || motionUtils.easeInOut).splice(0, values.length - 1);
|
|
1399
1400
|
}
|
|
1400
|
-
function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "easeInOut", }) {
|
|
1401
|
+
function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "easeInOut", mixer: transitionMixer, }) {
|
|
1402
|
+
/**
|
|
1403
|
+
* A mixer only blends values that aren't numbers. Numbers blend as
|
|
1404
|
+
* usual, as they do in springs, and so do the progress animations
|
|
1405
|
+
* behind layout and path animations, which take the same transition.
|
|
1406
|
+
*/
|
|
1407
|
+
const customMixer = typeof keyframeValues[0] === "number" ? undefined : transitionMixer;
|
|
1401
1408
|
/**
|
|
1402
1409
|
* Easing functions can be externally defined as strings. Here we convert them
|
|
1403
1410
|
* into actual functions.
|
|
@@ -1414,9 +1421,11 @@
|
|
|
1414
1421
|
value: keyframeValues[0],
|
|
1415
1422
|
};
|
|
1416
1423
|
/**
|
|
1417
|
-
* Fast setup path for two keyframes one easing.
|
|
1424
|
+
* Fast setup path for two keyframes one easing. interpolate() handles
|
|
1425
|
+
* a custom mixer, and falls back to the usual one where it declines.
|
|
1418
1426
|
*/
|
|
1419
|
-
if (
|
|
1427
|
+
if (!customMixer &&
|
|
1428
|
+
keyframeValues.length === 2 &&
|
|
1420
1429
|
!Array.isArray(easingFunctions) &&
|
|
1421
1430
|
(!times ||
|
|
1422
1431
|
times.length !== 2 ||
|
|
@@ -1449,6 +1458,7 @@
|
|
|
1449
1458
|
ease: Array.isArray(easingFunctions)
|
|
1450
1459
|
? easingFunctions
|
|
1451
1460
|
: defaultEasing(keyframeValues, easingFunctions),
|
|
1461
|
+
mixer: customMixer,
|
|
1452
1462
|
});
|
|
1453
1463
|
return {
|
|
1454
1464
|
calculatedDuration: duration,
|
|
@@ -1656,9 +1666,15 @@
|
|
|
1656
1666
|
if (generatorFactory !== keyframes) {
|
|
1657
1667
|
motionUtils.invariant(keyframes$1.length <= 2, `Only two keyframes currently supported with spring and inertia animations. Trying to animate ${keyframes$1}`, "spring-two-frames");
|
|
1658
1668
|
}
|
|
1669
|
+
/**
|
|
1670
|
+
* This runs again when a spring is flattened to attach it to a
|
|
1671
|
+
* timeline, and the keyframes generator blends values itself.
|
|
1672
|
+
*/
|
|
1673
|
+
this.mixKeyframes = undefined;
|
|
1659
1674
|
if (generatorFactory !== keyframes &&
|
|
1660
1675
|
typeof keyframes$1[0] !== "number") {
|
|
1661
|
-
this.mixKeyframes = motionUtils.pipe(percentToProgress,
|
|
1676
|
+
this.mixKeyframes = motionUtils.pipe(percentToProgress, options.mixer?.(keyframes$1[0], keyframes$1[1]) ||
|
|
1677
|
+
mix(keyframes$1[0], keyframes$1[1]));
|
|
1662
1678
|
keyframes$1 = [0, 100];
|
|
1663
1679
|
}
|
|
1664
1680
|
const generator = generatorFactory(keyframes$1 === options.keyframes
|
|
@@ -3012,6 +3028,15 @@
|
|
|
3012
3028
|
return false;
|
|
3013
3029
|
}
|
|
3014
3030
|
|
|
3031
|
+
/**
|
|
3032
|
+
* Whether an animation needs its mixer, which WAAPI can't call. Numbers
|
|
3033
|
+
* blend as usual, and an animation whose mixer declines every pair runs
|
|
3034
|
+
* as it would without one.
|
|
3035
|
+
*/
|
|
3036
|
+
const needsMixer = ({ mixer, keyframes }) => mixer &&
|
|
3037
|
+
typeof keyframes[0] !== "number" &&
|
|
3038
|
+
keyframes.some((keyframe, i) => i && mixer(keyframes[i - 1], keyframe));
|
|
3039
|
+
|
|
3015
3040
|
const colorProperties = new Set([
|
|
3016
3041
|
"color",
|
|
3017
3042
|
"backgroundColor",
|
|
@@ -3071,7 +3096,8 @@
|
|
|
3071
3096
|
!repeatDelay &&
|
|
3072
3097
|
repeatType !== "mirror" &&
|
|
3073
3098
|
damping !== 0 &&
|
|
3074
|
-
type !== "inertia"
|
|
3099
|
+
type !== "inertia" &&
|
|
3100
|
+
!needsMixer(options));
|
|
3075
3101
|
}
|
|
3076
3102
|
|
|
3077
3103
|
/**
|
|
@@ -3170,18 +3196,21 @@
|
|
|
3170
3196
|
* Named easings that are the same cubic-bezier in JS and CSS.
|
|
3171
3197
|
*/
|
|
3172
3198
|
const isNativeEasing = (ease) => /^(linear|ease(In|Out|InOut))$/.test(ease);
|
|
3199
|
+
/**
|
|
3200
|
+
* Whether two eased progresses match. False if either is NaN.
|
|
3201
|
+
*/
|
|
3202
|
+
const isNear$1 = (a, b) => Math.abs(a - b) <= easingTolerance;
|
|
3173
3203
|
const byTime = (a, b) => a - b;
|
|
3174
3204
|
/**
|
|
3175
3205
|
* n + 1 evenly spaced timestamps, from one timestamp to another.
|
|
3176
3206
|
*/
|
|
3177
|
-
const spread = (from, to, n) =>
|
|
3178
|
-
const result = [];
|
|
3179
|
-
for (let i = 0; i <= n; i++)
|
|
3180
|
-
result.push(mixNumber$1(from, to, i / n));
|
|
3181
|
-
return result;
|
|
3182
|
-
};
|
|
3207
|
+
const spread = (from, to, n) => defaultOffset(Array(n + 1)).map((p) => mixNumber$1(from, to, p));
|
|
3183
3208
|
const getOwner = (options) => options.motionValue.owner;
|
|
3184
3209
|
const getGroup = (element) => transformGroups.get(element);
|
|
3210
|
+
/**
|
|
3211
|
+
* Whether an animation has ended, so can leave its group.
|
|
3212
|
+
*/
|
|
3213
|
+
const hasEnded = ({ state }) => state === "idle" || state === "finished";
|
|
3185
3214
|
const read = (owner, key) => owner.latestValues ? owner.latestValues[key] : owner.getValue(key)?.get();
|
|
3186
3215
|
/**
|
|
3187
3216
|
* Whether this animation should join its element's transform group.
|
|
@@ -3220,7 +3249,12 @@
|
|
|
3220
3249
|
/**
|
|
3221
3250
|
* Layout animations write transform every frame.
|
|
3222
3251
|
*/
|
|
3223
|
-
!owner.projection?.isProjecting()
|
|
3252
|
+
!owner.projection?.isProjecting() &&
|
|
3253
|
+
/**
|
|
3254
|
+
* A mixer that blends these values makes them every frame. It's
|
|
3255
|
+
* asked last, as it's user code.
|
|
3256
|
+
*/
|
|
3257
|
+
!needsMixer(options));
|
|
3224
3258
|
}
|
|
3225
3259
|
class TransformAnimation extends JSAnimation {
|
|
3226
3260
|
constructor(options) {
|
|
@@ -3577,9 +3611,8 @@
|
|
|
3577
3611
|
let shared;
|
|
3578
3612
|
let progressAt;
|
|
3579
3613
|
for (const track of moving) {
|
|
3580
|
-
const
|
|
3581
|
-
const
|
|
3582
|
-
const changes = values.map((value) => value - first);
|
|
3614
|
+
const first = track.numberAt(from);
|
|
3615
|
+
const changes = at.map((t) => track.numberAt(t) - first);
|
|
3583
3616
|
const end = changes[changes.length - 1];
|
|
3584
3617
|
/**
|
|
3585
3618
|
* A value that ends only a tiny way from where it started, as
|
|
@@ -3593,25 +3626,20 @@
|
|
|
3593
3626
|
: end;
|
|
3594
3627
|
const progress = changes.map((change) => range ? change / range : change);
|
|
3595
3628
|
/**
|
|
3596
|
-
*
|
|
3597
|
-
*
|
|
3598
|
-
* fits
|
|
3629
|
+
* The first value that moves sets the easing, and every other
|
|
3630
|
+
* one must follow it. A value that doesn't change, like one
|
|
3631
|
+
* still in its delay, fits any easing. One that changes but
|
|
3632
|
+
* ends where it started fits none.
|
|
3599
3633
|
*/
|
|
3600
|
-
if (!
|
|
3601
|
-
if (progress.some((p) => !(Math.abs(p) <= easingTolerance))) {
|
|
3602
|
-
return;
|
|
3603
|
-
}
|
|
3604
|
-
}
|
|
3605
|
-
else if (!shared) {
|
|
3634
|
+
if (range && !shared) {
|
|
3606
3635
|
shared = progress;
|
|
3607
3636
|
progressAt = (t) => (track.numberAt(t) - first) / range;
|
|
3608
3637
|
}
|
|
3609
|
-
else if (progress.some((p, i) => !(
|
|
3638
|
+
else if (progress.some((p, i) => !isNear$1(p, range && shared[i]))) {
|
|
3610
3639
|
return;
|
|
3611
3640
|
}
|
|
3612
3641
|
}
|
|
3613
|
-
if (!shared ||
|
|
3614
|
-
shared.every((p, i) => Math.abs(p - position(at[i])) <= easingTolerance)) {
|
|
3642
|
+
if (!shared || shared.every((p, i) => isNear$1(p, position(at[i])))) {
|
|
3615
3643
|
return "linear";
|
|
3616
3644
|
}
|
|
3617
3645
|
/**
|
|
@@ -3698,7 +3726,7 @@
|
|
|
3698
3726
|
/**
|
|
3699
3727
|
* A WAAPI animation of the composed transform between two timestamps.
|
|
3700
3728
|
*/
|
|
3701
|
-
const run = (moving, from, to, options = { fill: "both" }, settled
|
|
3729
|
+
const run = (moving, from, to, nativeEasing, options = { fill: "both" }, settled) => {
|
|
3702
3730
|
const bounds = moving.flatMap((track) => track.boundaries(from, to));
|
|
3703
3731
|
const easing = nativeEasing || getEasing(moving, from, to, bounds);
|
|
3704
3732
|
const times = easing ? [from, to] : sample(moving, from, to, bounds);
|
|
@@ -3784,9 +3812,7 @@
|
|
|
3784
3812
|
if (byKey.has(key))
|
|
3785
3813
|
return true;
|
|
3786
3814
|
const value = (statics[key] = read(owner, key));
|
|
3787
|
-
return
|
|
3788
|
-
parseFloat(value) !==
|
|
3789
|
-
(key.startsWith("scale") ? 1 : 0));
|
|
3815
|
+
return value !== undefined && !isDefaultTransform(key, value);
|
|
3790
3816
|
});
|
|
3791
3817
|
stop(false);
|
|
3792
3818
|
/**
|
|
@@ -3797,7 +3823,7 @@
|
|
|
3797
3823
|
try {
|
|
3798
3824
|
if (tween && tween[1] > now) {
|
|
3799
3825
|
const [from, to, easing] = tween;
|
|
3800
|
-
add(run(moving, from, to,
|
|
3826
|
+
add(run(moving, from, to, easing), from - now, to - from);
|
|
3801
3827
|
}
|
|
3802
3828
|
else if (end > now) {
|
|
3803
3829
|
add(run(moving, now, end), 0, end - now);
|
|
@@ -3814,7 +3840,7 @@
|
|
|
3814
3840
|
* seamlessly, and start it part way through.
|
|
3815
3841
|
*/
|
|
3816
3842
|
const from = cycleStart + Math.floor((end - cycleStart) / cycle) * cycle;
|
|
3817
|
-
add(run(looping, from, from + cycle, {
|
|
3843
|
+
add(run(looping, from, from + cycle, undefined, {
|
|
3818
3844
|
iterations: Infinity,
|
|
3819
3845
|
iterationStart: (end - from) / cycle,
|
|
3820
3846
|
/**
|
|
@@ -3953,10 +3979,7 @@
|
|
|
3953
3979
|
isScheduled = false;
|
|
3954
3980
|
if (isEnded)
|
|
3955
3981
|
return;
|
|
3956
|
-
tracks.forEach((
|
|
3957
|
-
if (state === "idle" || state === "finished")
|
|
3958
|
-
tracks.delete(track);
|
|
3959
|
-
});
|
|
3982
|
+
tracks.forEach((track) => hasEnded(track) && tracks.delete(track));
|
|
3960
3983
|
if (end())
|
|
3961
3984
|
return;
|
|
3962
3985
|
for (const track of tracks) {
|
|
@@ -4016,9 +4039,7 @@
|
|
|
4016
4039
|
* Only drop the stopped animation. Others can be idle because
|
|
4017
4040
|
* they're part way through play(), and are about to run.
|
|
4018
4041
|
*/
|
|
4019
|
-
|
|
4020
|
-
if (state === "idle" || state === "finished")
|
|
4021
|
-
tracks.delete(track);
|
|
4042
|
+
hasEnded(track) && tracks.delete(track);
|
|
4022
4043
|
end() || group.schedule(true);
|
|
4023
4044
|
},
|
|
4024
4045
|
/**
|
|
@@ -4575,10 +4596,19 @@
|
|
|
4575
4596
|
* effects, and resets velocity to `0`.
|
|
4576
4597
|
*/
|
|
4577
4598
|
jump(v, endAnimation = true) {
|
|
4599
|
+
if (endAnimation) {
|
|
4600
|
+
/**
|
|
4601
|
+
* Stop first, as stopping a running animation can set the
|
|
4602
|
+
* value it's showing, which would replace v. Marking the value
|
|
4603
|
+
* as updated now skips a JS animation's catch-up tick on stop,
|
|
4604
|
+
* which could otherwise complete it.
|
|
4605
|
+
*/
|
|
4606
|
+
this.updatedAt = time.now();
|
|
4607
|
+
this.stop();
|
|
4608
|
+
}
|
|
4578
4609
|
this.updateAndNotify(v);
|
|
4579
4610
|
this.prev = v;
|
|
4580
4611
|
this.prevUpdatedAt = this.prevFrameValue = undefined;
|
|
4581
|
-
endAnimation && this.stop();
|
|
4582
4612
|
this.stopPassiveEffect?.();
|
|
4583
4613
|
}
|
|
4584
4614
|
dirty() {
|
|
@@ -4797,6 +4827,7 @@
|
|
|
4797
4827
|
"from",
|
|
4798
4828
|
"elapsed",
|
|
4799
4829
|
"out",
|
|
4830
|
+
"mixer",
|
|
4800
4831
|
]);
|
|
4801
4832
|
/**
|
|
4802
4833
|
* Decide whether a transition is defined on a given Transition.
|
|
@@ -6353,6 +6384,20 @@
|
|
|
6353
6384
|
else if (key.startsWith("attr")) {
|
|
6354
6385
|
return addAttrValue(element, state, key, value, convertAttrKey(key));
|
|
6355
6386
|
}
|
|
6387
|
+
else if (key === "d") {
|
|
6388
|
+
/**
|
|
6389
|
+
* `d` is a CSS property in Chrome and Firefox, but only as
|
|
6390
|
+
* `path(...)`, so path data goes to the attribute, taken out of
|
|
6391
|
+
* `path(...)` if it's written that way. Path data itself has no
|
|
6392
|
+
* quotes or brackets.
|
|
6393
|
+
*/
|
|
6394
|
+
return state.set(key, value, () => {
|
|
6395
|
+
const d = value.get()?.replace(/path\(|["')]/g, "");
|
|
6396
|
+
d === undefined
|
|
6397
|
+
? element.removeAttribute(key)
|
|
6398
|
+
: element.setAttribute(key, d);
|
|
6399
|
+
});
|
|
6400
|
+
}
|
|
6356
6401
|
/**
|
|
6357
6402
|
* Transforms and origins aren't CSS properties (bar `x`/`y` in some
|
|
6358
6403
|
* browsers), so check them by name rather than `key in element.style`.
|
|
@@ -6609,6 +6654,10 @@
|
|
|
6609
6654
|
}
|
|
6610
6655
|
return viewportBox;
|
|
6611
6656
|
}
|
|
6657
|
+
const measureDocumentScroll = () => ({
|
|
6658
|
+
x: document.documentElement.scrollLeft || document.body?.scrollLeft || 0,
|
|
6659
|
+
y: document.documentElement.scrollTop || document.body?.scrollTop || 0,
|
|
6660
|
+
});
|
|
6612
6661
|
|
|
6613
6662
|
const noProps = {};
|
|
6614
6663
|
const getElementEffect = (element) => (isSVGElement(element)
|
|
@@ -6785,6 +6834,7 @@
|
|
|
6785
6834
|
const statsBuffer = {
|
|
6786
6835
|
value: null,
|
|
6787
6836
|
addProjectionMetrics: null,
|
|
6837
|
+
countProjection: undefined,
|
|
6788
6838
|
};
|
|
6789
6839
|
|
|
6790
6840
|
/**
|
|
@@ -6807,6 +6857,12 @@
|
|
|
6807
6857
|
return delay(callback, motionUtils.secondsToMilliseconds(timeout));
|
|
6808
6858
|
}
|
|
6809
6859
|
|
|
6860
|
+
function isRefObject(ref) {
|
|
6861
|
+
return (ref &&
|
|
6862
|
+
typeof ref === "object" &&
|
|
6863
|
+
Object.prototype.hasOwnProperty.call(ref, "current"));
|
|
6864
|
+
}
|
|
6865
|
+
|
|
6810
6866
|
/**
|
|
6811
6867
|
* Checks if an element is specifically an SVGSVGElement (the root SVG element)
|
|
6812
6868
|
* in a way that works across iframes
|
|
@@ -7021,6 +7077,27 @@
|
|
|
7021
7077
|
removeAxisTransforms(box.y, transforms, yKeys, originBox?.y, sourceBox?.y);
|
|
7022
7078
|
}
|
|
7023
7079
|
|
|
7080
|
+
const userAgentContains = (string) => typeof navigator !== "undefined" &&
|
|
7081
|
+
navigator.userAgent &&
|
|
7082
|
+
navigator.userAgent.toLowerCase().includes(string);
|
|
7083
|
+
/**
|
|
7084
|
+
* Measured bounding boxes must be rounded in Safari and
|
|
7085
|
+
* left untouched in Chrome, otherwise non-integer layouts within scaled-up elements
|
|
7086
|
+
* can appear to jump.
|
|
7087
|
+
*/
|
|
7088
|
+
const roundPoint = userAgentContains("applewebkit/") && !userAgentContains("chrome/")
|
|
7089
|
+
? Math.round
|
|
7090
|
+
: motionUtils.noop;
|
|
7091
|
+
function roundAxis(axis) {
|
|
7092
|
+
// Round to the nearest .5 pixels to support subpixel layouts
|
|
7093
|
+
axis.min = roundPoint(axis.min);
|
|
7094
|
+
axis.max = roundPoint(axis.max);
|
|
7095
|
+
}
|
|
7096
|
+
function roundBox(box) {
|
|
7097
|
+
roundAxis(box.x);
|
|
7098
|
+
roundAxis(box.y);
|
|
7099
|
+
}
|
|
7100
|
+
|
|
7024
7101
|
const createAxisDelta = () => ({
|
|
7025
7102
|
translate: 0,
|
|
7026
7103
|
scale: 1,
|
|
@@ -7317,11 +7394,6 @@
|
|
|
7317
7394
|
hasEverUpdated: false,
|
|
7318
7395
|
};
|
|
7319
7396
|
|
|
7320
|
-
const metrics = {
|
|
7321
|
-
nodes: 0,
|
|
7322
|
-
calculatedTargetDeltas: 0,
|
|
7323
|
-
calculatedProjections: 0,
|
|
7324
|
-
};
|
|
7325
7397
|
/**
|
|
7326
7398
|
* Transforms that distort an element's layout, so must be reset before measuring.
|
|
7327
7399
|
*/
|
|
@@ -7369,6 +7441,13 @@
|
|
|
7369
7441
|
cancelTreeOptimisedTransformAnimations(parent);
|
|
7370
7442
|
}
|
|
7371
7443
|
}
|
|
7444
|
+
function getClosestProjectingNode(visualElement) {
|
|
7445
|
+
if (!visualElement)
|
|
7446
|
+
return undefined;
|
|
7447
|
+
return visualElement.options.allowProjection !== false
|
|
7448
|
+
? visualElement.projection
|
|
7449
|
+
: getClosestProjectingNode(visualElement.parent);
|
|
7450
|
+
}
|
|
7372
7451
|
function createProjectionNode({ attachResizeListener, defaultParent, measureScroll, checkIsScrollRoot, resetTransform, }) {
|
|
7373
7452
|
/**
|
|
7374
7453
|
* Correctors registered via addScaleCorrector before projection loaded
|
|
@@ -7381,6 +7460,57 @@
|
|
|
7381
7460
|
...scaleCorrectors,
|
|
7382
7461
|
});
|
|
7383
7462
|
return class ProjectionNode {
|
|
7463
|
+
/**
|
|
7464
|
+
* Create the projection node of a `motion` component's VisualElement,
|
|
7465
|
+
* from its props. This runs while the component renders, before its
|
|
7466
|
+
* children. It's here rather than in the component so React
|
|
7467
|
+
* bundles only include it with the features that supply a
|
|
7468
|
+
* ProjectionNode. Vanilla bundles that use the projection node
|
|
7469
|
+
* (drag(), animateLayout()) include it too, as a class static
|
|
7470
|
+
* can't be tree-shaken.
|
|
7471
|
+
*/
|
|
7472
|
+
static create(visualElement, props, initialPromotionConfig) {
|
|
7473
|
+
const { layoutId, layout, drag, dragConstraints, layoutScroll, layoutRoot, layoutAnchor, layoutCrossfade, } = props;
|
|
7474
|
+
const projection = (visualElement.projection = new this(visualElement.latestValues, props["data-framer-portal-id"]
|
|
7475
|
+
? undefined
|
|
7476
|
+
: getClosestProjectingNode(visualElement.parent)));
|
|
7477
|
+
projection.setOptions({
|
|
7478
|
+
layoutId,
|
|
7479
|
+
layout,
|
|
7480
|
+
alwaysMeasureLayout: Boolean(drag) ||
|
|
7481
|
+
(dragConstraints && isRefObject(dragConstraints)),
|
|
7482
|
+
visualElement,
|
|
7483
|
+
/**
|
|
7484
|
+
* TODO: Update options in an effect. This could be tricky as it'll be too late
|
|
7485
|
+
* to update by the time layout animations run.
|
|
7486
|
+
* We also need to fix this safeToRemove by linking it up to the one returned by usePresence,
|
|
7487
|
+
* ensuring it gets called if there's no potential layout animations.
|
|
7488
|
+
*
|
|
7489
|
+
*/
|
|
7490
|
+
animationType: typeof layout === "string" ? layout : "both",
|
|
7491
|
+
initialPromotionConfig,
|
|
7492
|
+
crossfade: layoutCrossfade,
|
|
7493
|
+
layoutScroll,
|
|
7494
|
+
layoutRoot,
|
|
7495
|
+
layoutAnchor,
|
|
7496
|
+
});
|
|
7497
|
+
/**
|
|
7498
|
+
* This node will take over from its layoutId's current lead, so snapshot
|
|
7499
|
+
* the lead now, while rendering. By the time the lead unmounts (or this
|
|
7500
|
+
* node mounts) React may already have committed DOM changes that come
|
|
7501
|
+
* before it in the tree, like a sibling changing height, and a snapshot
|
|
7502
|
+
* taken then starts the animation from a position never seen on screen.
|
|
7503
|
+
*
|
|
7504
|
+
* If React discards this render (e.g. it suspends), nothing else
|
|
7505
|
+
* completes the update, so check it after the next frame as an
|
|
7506
|
+
* unmounting node does.
|
|
7507
|
+
*/
|
|
7508
|
+
const lead = projection.getStack()?.lead;
|
|
7509
|
+
if (lead && !projection.root.isUpdateBlocked()) {
|
|
7510
|
+
lead.willUpdate();
|
|
7511
|
+
lead.scheduleCheckAfterUnmount();
|
|
7512
|
+
}
|
|
7513
|
+
}
|
|
7384
7514
|
constructor(latestValues = {}, parent = defaultParent?.()) {
|
|
7385
7515
|
/**
|
|
7386
7516
|
* A unique ID generated for every projection node.
|
|
@@ -7493,23 +7623,14 @@
|
|
|
7493
7623
|
*/
|
|
7494
7624
|
this.updateProjection = () => {
|
|
7495
7625
|
this.projectionUpdateScheduled = false;
|
|
7496
|
-
/**
|
|
7497
|
-
* Reset debug counts. Manually resetting rather than creating a new
|
|
7498
|
-
* object each frame.
|
|
7499
|
-
*/
|
|
7500
|
-
if (statsBuffer.value) {
|
|
7501
|
-
metrics.nodes =
|
|
7502
|
-
metrics.calculatedTargetDeltas =
|
|
7503
|
-
metrics.calculatedProjections =
|
|
7504
|
-
0;
|
|
7505
|
-
}
|
|
7506
7626
|
this.nodes.forEach(propagateDirtyNodes);
|
|
7507
7627
|
this.nodes.forEach(resolveTargetDelta);
|
|
7508
7628
|
this.nodes.forEach(calcProjection);
|
|
7509
7629
|
this.nodes.forEach(cleanDirtyNodes);
|
|
7510
|
-
|
|
7511
|
-
|
|
7512
|
-
|
|
7630
|
+
/**
|
|
7631
|
+
* Record this frame's debug counts, if recordStats() is running.
|
|
7632
|
+
*/
|
|
7633
|
+
statsBuffer.countProjection?.();
|
|
7513
7634
|
};
|
|
7514
7635
|
/**
|
|
7515
7636
|
* Frame calculations
|
|
@@ -8225,9 +8346,7 @@
|
|
|
8225
8346
|
/**
|
|
8226
8347
|
* Increase debug counter for resolved target deltas
|
|
8227
8348
|
*/
|
|
8228
|
-
|
|
8229
|
-
metrics.calculatedTargetDeltas++;
|
|
8230
|
-
}
|
|
8349
|
+
statsBuffer.countProjection?.(1); // calculatedTargetDeltas
|
|
8231
8350
|
}
|
|
8232
8351
|
getClosestProjectingParent() {
|
|
8233
8352
|
if (!this.parent ||
|
|
@@ -8375,9 +8494,7 @@
|
|
|
8375
8494
|
/**
|
|
8376
8495
|
* Increase debug counter for recalculated projections
|
|
8377
8496
|
*/
|
|
8378
|
-
|
|
8379
|
-
metrics.calculatedProjections++;
|
|
8380
|
-
}
|
|
8497
|
+
statsBuffer.countProjection?.(2); // calculatedProjections
|
|
8381
8498
|
}
|
|
8382
8499
|
hide() {
|
|
8383
8500
|
this.isVisible = false;
|
|
@@ -8904,9 +9021,7 @@
|
|
|
8904
9021
|
/**
|
|
8905
9022
|
* Increase debug counter for nodes encountered this frame
|
|
8906
9023
|
*/
|
|
8907
|
-
|
|
8908
|
-
metrics.nodes++;
|
|
8909
|
-
}
|
|
9024
|
+
statsBuffer.countProjection?.(0); // nodes
|
|
8910
9025
|
if (!node.parent)
|
|
8911
9026
|
return;
|
|
8912
9027
|
/**
|
|
@@ -9037,26 +9152,6 @@
|
|
|
9037
9152
|
duration: 0.45,
|
|
9038
9153
|
ease: [0.4, 0, 0.1, 1],
|
|
9039
9154
|
};
|
|
9040
|
-
const userAgentContains = (string) => typeof navigator !== "undefined" &&
|
|
9041
|
-
navigator.userAgent &&
|
|
9042
|
-
navigator.userAgent.toLowerCase().includes(string);
|
|
9043
|
-
/**
|
|
9044
|
-
* Measured bounding boxes must be rounded in Safari and
|
|
9045
|
-
* left untouched in Chrome, otherwise non-integer layouts within scaled-up elements
|
|
9046
|
-
* can appear to jump.
|
|
9047
|
-
*/
|
|
9048
|
-
const roundPoint = userAgentContains("applewebkit/") && !userAgentContains("chrome/")
|
|
9049
|
-
? Math.round
|
|
9050
|
-
: motionUtils.noop;
|
|
9051
|
-
function roundAxis(axis) {
|
|
9052
|
-
// Round to the nearest .5 pixels to support subpixel layouts
|
|
9053
|
-
axis.min = roundPoint(axis.min);
|
|
9054
|
-
axis.max = roundPoint(axis.max);
|
|
9055
|
-
}
|
|
9056
|
-
function roundBox(box) {
|
|
9057
|
-
roundAxis(box.x);
|
|
9058
|
-
roundAxis(box.y);
|
|
9059
|
-
}
|
|
9060
9155
|
/**
|
|
9061
9156
|
* Align an axis to the start of another, keeping the length of a layout axis.
|
|
9062
9157
|
* The length is read first, as output can be the layout axis itself.
|
|
@@ -9081,14 +9176,7 @@
|
|
|
9081
9176
|
const DocumentProjectionNode =
|
|
9082
9177
|
/* @__PURE__ */ createProjectionNode({
|
|
9083
9178
|
attachResizeListener: (ref, notify) => addDomEvent(ref, "resize", notify),
|
|
9084
|
-
measureScroll:
|
|
9085
|
-
x: document.documentElement.scrollLeft ||
|
|
9086
|
-
document.body?.scrollLeft ||
|
|
9087
|
-
0,
|
|
9088
|
-
y: document.documentElement.scrollTop ||
|
|
9089
|
-
document.body?.scrollTop ||
|
|
9090
|
-
0,
|
|
9091
|
-
}),
|
|
9179
|
+
measureScroll: measureDocumentScroll,
|
|
9092
9180
|
checkIsScrollRoot: () => true,
|
|
9093
9181
|
});
|
|
9094
9182
|
|
|
@@ -9390,9 +9478,10 @@
|
|
|
9390
9478
|
/**
|
|
9391
9479
|
* If this element has been mounted before (e.g. after a Suspense
|
|
9392
9480
|
* unmount/remount), reset motion values to their initial state
|
|
9393
|
-
* so animations replay correctly from initial → animate
|
|
9481
|
+
* so animations replay correctly from initial → animate, unless
|
|
9482
|
+
* the presence asks to keep them.
|
|
9394
9483
|
*/
|
|
9395
|
-
if (this.hasBeenMounted) {
|
|
9484
|
+
if (this.hasBeenMounted && !this.presenceContext?.keepValuesOnRemount) {
|
|
9396
9485
|
for (const key in this.initialValues) {
|
|
9397
9486
|
this.values.get(key)?.jump(this.initialValues[key]);
|
|
9398
9487
|
this.latestValues[key] = this.initialValues[key];
|
|
@@ -9854,6 +9943,124 @@
|
|
|
9854
9943
|
}
|
|
9855
9944
|
}
|
|
9856
9945
|
|
|
9946
|
+
/**
|
|
9947
|
+
* Get the VisualElement that imperative APIs like animateLayout() and
|
|
9948
|
+
* drag() render an element with, creating one if it has none, ready for
|
|
9949
|
+
* a projection node to be attached.
|
|
9950
|
+
*/
|
|
9951
|
+
function resolveVisualElement(element) {
|
|
9952
|
+
let visualElement = visualElementStore.get(element);
|
|
9953
|
+
if (!visualElement) {
|
|
9954
|
+
visualElement = new HTMLVisualElement({
|
|
9955
|
+
props: {},
|
|
9956
|
+
presenceContext: null,
|
|
9957
|
+
visualState: {
|
|
9958
|
+
latestValues: {},
|
|
9959
|
+
renderState: {
|
|
9960
|
+
transform: {},
|
|
9961
|
+
transformOrigin: {},
|
|
9962
|
+
style: {},
|
|
9963
|
+
vars: {},
|
|
9964
|
+
},
|
|
9965
|
+
},
|
|
9966
|
+
}, { allowProjection: true });
|
|
9967
|
+
/**
|
|
9968
|
+
* Values animate() has been rendering on this element move to
|
|
9969
|
+
* the VisualElement, so the layout animation composes with
|
|
9970
|
+
* them instead of overwriting them.
|
|
9971
|
+
*/
|
|
9972
|
+
handOffElementState(element, visualElement);
|
|
9973
|
+
}
|
|
9974
|
+
/**
|
|
9975
|
+
* A first-time element may carry a projection transform in its
|
|
9976
|
+
* inline style (e.g. it was cloned from an element mid-animation).
|
|
9977
|
+
* That transform isn't tracked in latestValues so the engine can't
|
|
9978
|
+
* reset it before measuring - clear it now so the first layout
|
|
9979
|
+
* measurement isn't inflated.
|
|
9980
|
+
*/
|
|
9981
|
+
if (element.style.transform && !hasTransform(visualElement.latestValues)) {
|
|
9982
|
+
element.style.transform = "";
|
|
9983
|
+
}
|
|
9984
|
+
return visualElement;
|
|
9985
|
+
}
|
|
9986
|
+
|
|
9987
|
+
/**
|
|
9988
|
+
* animateLayout() registers a function here that creates nodes in the
|
|
9989
|
+
* layout projection tree. When it's in the bundle, drag() uses those, so
|
|
9990
|
+
* the two work together (e.g. a drag follows a layout change mid-gesture).
|
|
9991
|
+
* Otherwise drag() makes do with a node that only measures. Bundles that
|
|
9992
|
+
* don't tree-shake (dev pre-bundling, CDN builds) always register it, and
|
|
9993
|
+
* a drag() started before animateLayout() is lazy loaded keeps its node.
|
|
9994
|
+
*/
|
|
9995
|
+
const layoutProjection = {};
|
|
9996
|
+
/**
|
|
9997
|
+
* The document root of measurement-only nodes. Like the projection tree's
|
|
9998
|
+
* root, it keeps its scroll until drag controls clear it to re-measure.
|
|
9999
|
+
*/
|
|
10000
|
+
const root = {
|
|
10001
|
+
updateScroll: () => {
|
|
10002
|
+
root.scroll || (root.scroll = { offset: measureDocumentScroll() });
|
|
10003
|
+
},
|
|
10004
|
+
};
|
|
10005
|
+
/**
|
|
10006
|
+
* The part of a projection node that drag controls use: measuring the
|
|
10007
|
+
* element's page box, for its layout and constraints. It never projects
|
|
10008
|
+
* or joins a layout update.
|
|
10009
|
+
*/
|
|
10010
|
+
const createMeasureNode = (element) => {
|
|
10011
|
+
const visualElement = resolveVisualElement(element);
|
|
10012
|
+
const measureListeners = new motionUtils.SubscriptionManager();
|
|
10013
|
+
const node = {
|
|
10014
|
+
instance: element,
|
|
10015
|
+
root,
|
|
10016
|
+
path: [root],
|
|
10017
|
+
setOptions: motionUtils.noop,
|
|
10018
|
+
/**
|
|
10019
|
+
* Truthy like the full node's method, which HTMLVisualElement reads
|
|
10020
|
+
* (rather than calls) to default transform values.
|
|
10021
|
+
*/
|
|
10022
|
+
isProjecting: motionUtils.noop,
|
|
10023
|
+
applyProjectionStyles: motionUtils.noop,
|
|
10024
|
+
removeElementScroll: (box) => box,
|
|
10025
|
+
updateLayout: () => {
|
|
10026
|
+
const layoutBox = measurePageBox(element, root, visualElement.getTransformPagePoint());
|
|
10027
|
+
roundBox(layoutBox);
|
|
10028
|
+
node.layout = { layoutBox };
|
|
10029
|
+
measureListeners.notify();
|
|
10030
|
+
},
|
|
10031
|
+
addEventListener: (name, handler) => name === "measure" ? measureListeners.add(handler) : motionUtils.noop,
|
|
10032
|
+
/**
|
|
10033
|
+
* Detach from the VisualElement too, so it doesn't later remount
|
|
10034
|
+
* (or a `motion` component's layout feature adopt) a node that
|
|
10035
|
+
* can't do either.
|
|
10036
|
+
*/
|
|
10037
|
+
unmount: () => {
|
|
10038
|
+
node.instance = undefined;
|
|
10039
|
+
if (visualElement.projection === node) {
|
|
10040
|
+
visualElement.projection = undefined;
|
|
10041
|
+
}
|
|
10042
|
+
},
|
|
10043
|
+
};
|
|
10044
|
+
visualElement.projection = node;
|
|
10045
|
+
visualElement.current || visualElement.mount(element);
|
|
10046
|
+
return [node, node.unmount];
|
|
10047
|
+
};
|
|
10048
|
+
/**
|
|
10049
|
+
* Get a projection node for drag() to measure an element with, and a
|
|
10050
|
+
* function that releases it. Reuses a node a `motion` component or
|
|
10051
|
+
* animateLayout() owns.
|
|
10052
|
+
*/
|
|
10053
|
+
const acquireDragNode = (element) => {
|
|
10054
|
+
const owned = visualElementStore.get(element)?.projection;
|
|
10055
|
+
/**
|
|
10056
|
+
* A VisualElement can outlive its node (e.g. an unmounted `motion`
|
|
10057
|
+
* component's), so only reuse a node that's still mounted.
|
|
10058
|
+
*/
|
|
10059
|
+
return owned?.instance
|
|
10060
|
+
? [owned, motionUtils.noop]
|
|
10061
|
+
: (layoutProjection.create || createMeasureNode)(element);
|
|
10062
|
+
};
|
|
10063
|
+
|
|
9857
10064
|
const layoutSelector = "[data-layout],[data-layout-id]";
|
|
9858
10065
|
/**
|
|
9859
10066
|
* All imperatively-created projection nodes live in one persistent tree,
|
|
@@ -9906,21 +10113,6 @@
|
|
|
9906
10113
|
}
|
|
9907
10114
|
return undefined;
|
|
9908
10115
|
}
|
|
9909
|
-
function createVisualElement() {
|
|
9910
|
-
return new HTMLVisualElement({
|
|
9911
|
-
props: {},
|
|
9912
|
-
presenceContext: null,
|
|
9913
|
-
visualState: {
|
|
9914
|
-
latestValues: {},
|
|
9915
|
-
renderState: {
|
|
9916
|
-
transform: {},
|
|
9917
|
-
transformOrigin: {},
|
|
9918
|
-
style: {},
|
|
9919
|
-
vars: {},
|
|
9920
|
-
},
|
|
9921
|
-
},
|
|
9922
|
-
}, { allowProjection: true });
|
|
9923
|
-
}
|
|
9924
10116
|
function readNodeOptions(element, transition) {
|
|
9925
10117
|
const layoutAttr = element.getAttribute("data-layout");
|
|
9926
10118
|
const layoutId = element.getAttribute("data-layout-id") ?? undefined;
|
|
@@ -9936,27 +10128,7 @@
|
|
|
9936
10128
|
function prepareNode(element, transition) {
|
|
9937
10129
|
let node = layoutNodes.get(element);
|
|
9938
10130
|
if (!node) {
|
|
9939
|
-
|
|
9940
|
-
if (!visualElement) {
|
|
9941
|
-
visualElement = createVisualElement();
|
|
9942
|
-
/**
|
|
9943
|
-
* Values animate() has been rendering on this element move to
|
|
9944
|
-
* the VisualElement, so the layout animation composes with
|
|
9945
|
-
* them instead of overwriting them.
|
|
9946
|
-
*/
|
|
9947
|
-
handOffElementState(element, visualElement);
|
|
9948
|
-
}
|
|
9949
|
-
/**
|
|
9950
|
-
* A first-time element may carry a projection transform in its
|
|
9951
|
-
* inline style (e.g. it was cloned from an element mid-animation).
|
|
9952
|
-
* That transform isn't tracked in latestValues so the engine can't
|
|
9953
|
-
* reset it before measuring - clear it now so the first layout
|
|
9954
|
-
* measurement isn't inflated.
|
|
9955
|
-
*/
|
|
9956
|
-
if (element.style.transform &&
|
|
9957
|
-
!hasTransform(visualElement.latestValues)) {
|
|
9958
|
-
element.style.transform = "";
|
|
9959
|
-
}
|
|
10131
|
+
const visualElement = resolveVisualElement(element);
|
|
9960
10132
|
node = new HTMLProjectionNode(visualElement.latestValues, getProjectionParent(element));
|
|
9961
10133
|
visualElement.projection = node;
|
|
9962
10134
|
node.setOptions({
|
|
@@ -9976,10 +10148,26 @@
|
|
|
9976
10148
|
return node;
|
|
9977
10149
|
}
|
|
9978
10150
|
/**
|
|
9979
|
-
*
|
|
9980
|
-
*
|
|
9981
|
-
|
|
9982
|
-
|
|
10151
|
+
* Create a node for an element in the shared imperative tree. Returns the
|
|
10152
|
+
* node and a function that releases it.
|
|
10153
|
+
*/
|
|
10154
|
+
function createLayoutNode(element) {
|
|
10155
|
+
const node = prepareNode(element);
|
|
10156
|
+
return [
|
|
10157
|
+
node,
|
|
10158
|
+
() => layoutNodes.get(element) === node && dropNode(element, node),
|
|
10159
|
+
];
|
|
10160
|
+
}
|
|
10161
|
+
/**
|
|
10162
|
+
* Let drag() create its nodes in the shared imperative tree, so drag
|
|
10163
|
+
* gestures and layout animations work together.
|
|
10164
|
+
*/
|
|
10165
|
+
layoutProjection.create = createLayoutNode;
|
|
10166
|
+
/**
|
|
10167
|
+
* Get a projection node for an element, so motion/remix can measure and
|
|
10168
|
+
* animate its layout. Reuses a node owned by a `motion` component or
|
|
10169
|
+
* animateLayout(), otherwise creates one in the shared imperative tree.
|
|
10170
|
+
* Returns the node and a function that releases it.
|
|
9983
10171
|
*/
|
|
9984
10172
|
function acquireProjectionNode(element) {
|
|
9985
10173
|
const owned = layoutNodes.get(element) || visualElementStore.get(element)?.projection;
|
|
@@ -9987,13 +10175,7 @@
|
|
|
9987
10175
|
* A VisualElement can outlive a node we released (e.g. a stopped
|
|
9988
10176
|
* drag()), so only reuse a node that's still mounted.
|
|
9989
10177
|
*/
|
|
9990
|
-
|
|
9991
|
-
return [owned, () => { }];
|
|
9992
|
-
const node = prepareNode(element);
|
|
9993
|
-
return [
|
|
9994
|
-
node,
|
|
9995
|
-
() => layoutNodes.get(element) === node && dropNode(element, node),
|
|
9996
|
-
];
|
|
10178
|
+
return owned?.instance ? [owned, () => { }] : createLayoutNode(element);
|
|
9997
10179
|
}
|
|
9998
10180
|
function sortDocumentOrder(elements) {
|
|
9999
10181
|
return [...elements].sort((a, b) => a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1);
|
|
@@ -10013,6 +10195,8 @@
|
|
|
10013
10195
|
}
|
|
10014
10196
|
function flushPendingBuilders() {
|
|
10015
10197
|
const builders = pendingBuilders;
|
|
10198
|
+
if (!builders)
|
|
10199
|
+
return;
|
|
10016
10200
|
pendingBuilders = undefined;
|
|
10017
10201
|
flushPendingFrame();
|
|
10018
10202
|
/**
|
|
@@ -10077,6 +10261,13 @@
|
|
|
10077
10261
|
};
|
|
10078
10262
|
updatePromises.length ? Promise.all(updatePromises).then(commit) : commit();
|
|
10079
10263
|
}
|
|
10264
|
+
/**
|
|
10265
|
+
* Snapshot every pending animateLayout() now, rather than on the next
|
|
10266
|
+
* microtask. For renderers that tell us a DOM update is about to happen
|
|
10267
|
+
* and then make it synchronously (e.g. a beforeUpdate/commit pair), with
|
|
10268
|
+
* updateDom returning a promise that resolves on commit.
|
|
10269
|
+
*/
|
|
10270
|
+
const flushLayoutSnapshots = flushPendingBuilders;
|
|
10080
10271
|
class LayoutAnimationBuilder {
|
|
10081
10272
|
constructor(scope, updateDom, defaultOptions) {
|
|
10082
10273
|
this.scope = scope;
|
|
@@ -10854,7 +11045,7 @@
|
|
|
10854
11045
|
};
|
|
10855
11046
|
const onStart = (event, info) => {
|
|
10856
11047
|
// Attempt to grab the global drag gesture lock - maybe make this part of PanSession
|
|
10857
|
-
const { drag, dragPropagation, onDragStart } = this.getProps();
|
|
11048
|
+
const { drag, dragConstraints, dragPropagation, onDragStart } = this.getProps();
|
|
10858
11049
|
if (drag && !dragPropagation) {
|
|
10859
11050
|
this.openDragLock?.();
|
|
10860
11051
|
this.openDragLock = setDragLock(drag);
|
|
@@ -10901,6 +11092,8 @@
|
|
|
10901
11092
|
}
|
|
10902
11093
|
this.originPoint[axis] = current;
|
|
10903
11094
|
});
|
|
11095
|
+
this.point =
|
|
11096
|
+
typeof dragConstraints === "function" && dragConstraints(this);
|
|
10904
11097
|
// Fire onDragStart event
|
|
10905
11098
|
if (onDragStart) {
|
|
10906
11099
|
frame.update(() => onDragStart(event, info), false, true);
|
|
@@ -10931,6 +11124,7 @@
|
|
|
10931
11124
|
// Update each point with the latest position
|
|
10932
11125
|
this.updateAxis("x", offset);
|
|
10933
11126
|
this.updateAxis("y", offset);
|
|
11127
|
+
this.point && this.point.move();
|
|
10934
11128
|
/**
|
|
10935
11129
|
* Ideally we would leave the renderer to fire naturally at the end of
|
|
10936
11130
|
* this frame but if the element is about to change layout as the result
|
|
@@ -10955,7 +11149,7 @@
|
|
|
10955
11149
|
};
|
|
10956
11150
|
const resumeAnimation = () => {
|
|
10957
11151
|
const { dragSnapToOrigin: snap } = this.getProps();
|
|
10958
|
-
if (snap || this.constraints) {
|
|
11152
|
+
if (snap || this.constraints || this.point) {
|
|
10959
11153
|
this.startAnimation({ x: 0, y: 0 });
|
|
10960
11154
|
}
|
|
10961
11155
|
};
|
|
@@ -11030,7 +11224,7 @@
|
|
|
11030
11224
|
if (constraints) {
|
|
11031
11225
|
next = applyConstraints(next, constraints, this.elastic[axis]);
|
|
11032
11226
|
}
|
|
11033
|
-
axisValue.set(next);
|
|
11227
|
+
this.point ? (this.point[axis] = next) : axisValue.set(next);
|
|
11034
11228
|
}
|
|
11035
11229
|
resolveConstraints() {
|
|
11036
11230
|
const { dragConstraints, dragElastic } = this.getProps();
|
|
@@ -11051,7 +11245,9 @@
|
|
|
11051
11245
|
}
|
|
11052
11246
|
}
|
|
11053
11247
|
else {
|
|
11054
|
-
if (dragConstraints &&
|
|
11248
|
+
if (dragConstraints &&
|
|
11249
|
+
layout &&
|
|
11250
|
+
typeof dragConstraints === "object") {
|
|
11055
11251
|
this.constraints = calcRelativeConstraints(layout.layoutBox, dragConstraints);
|
|
11056
11252
|
}
|
|
11057
11253
|
else {
|
|
@@ -11118,6 +11314,30 @@
|
|
|
11118
11314
|
}
|
|
11119
11315
|
startAnimation(velocity, dragAxes) {
|
|
11120
11316
|
const { drag, dragMomentum, dragElastic, dragTransition, dragSnapToOrigin, onDragTransitionEnd, } = this.getProps();
|
|
11317
|
+
/**
|
|
11318
|
+
* Overdamp the boundary spring if `dragElastic` is disabled. There's still a frame
|
|
11319
|
+
* of spring animations so we should look into adding a disable spring option to `inertia`.
|
|
11320
|
+
* We could do something here where we affect the `bounceStiffness` and `bounceDamping`
|
|
11321
|
+
* using the value of `dragElastic`.
|
|
11322
|
+
*/
|
|
11323
|
+
const options = {
|
|
11324
|
+
bounceStiffness: dragElastic ? 200 : 1000000,
|
|
11325
|
+
bounceDamping: dragElastic ? 40 : 10000000,
|
|
11326
|
+
timeConstant: 750,
|
|
11327
|
+
restDelta: 1,
|
|
11328
|
+
restSpeed: 10,
|
|
11329
|
+
...dragTransition,
|
|
11330
|
+
};
|
|
11331
|
+
const axisVelocity = (axis) => dragMomentum &&
|
|
11332
|
+
!(this.point && dragSnapToOrigin) &&
|
|
11333
|
+
shouldDrag(axis, dragAxes || drag, this.currentDirection)
|
|
11334
|
+
? velocity[axis]
|
|
11335
|
+
: 0;
|
|
11336
|
+
if (this.point && !dragSnapToOrigin) {
|
|
11337
|
+
return this.point
|
|
11338
|
+
.release({ x: axisVelocity("x"), y: axisVelocity("y") }, options)
|
|
11339
|
+
.then(onDragTransitionEnd);
|
|
11340
|
+
}
|
|
11121
11341
|
const constraints = this.constraints || {};
|
|
11122
11342
|
const momentumAnimations = eachAxis((axis) => {
|
|
11123
11343
|
if (!shouldDrag(axis, dragAxes || drag, this.currentDirection)) {
|
|
@@ -11127,23 +11347,10 @@
|
|
|
11127
11347
|
if (dragSnapToOrigin === true ||
|
|
11128
11348
|
dragSnapToOrigin === axis)
|
|
11129
11349
|
transition = { min: 0, max: 0 };
|
|
11130
|
-
/**
|
|
11131
|
-
* Overdamp the boundary spring if `dragElastic` is disabled. There's still a frame
|
|
11132
|
-
* of spring animations so we should look into adding a disable spring option to `inertia`.
|
|
11133
|
-
* We could do something here where we affect the `bounceStiffness` and `bounceDamping`
|
|
11134
|
-
* using the value of `dragElastic`.
|
|
11135
|
-
*/
|
|
11136
|
-
const bounceStiffness = dragElastic ? 200 : 1000000;
|
|
11137
|
-
const bounceDamping = dragElastic ? 40 : 10000000;
|
|
11138
11350
|
const inertia = {
|
|
11139
11351
|
type: "inertia",
|
|
11140
|
-
velocity:
|
|
11141
|
-
|
|
11142
|
-
bounceDamping,
|
|
11143
|
-
timeConstant: 750,
|
|
11144
|
-
restDelta: 1,
|
|
11145
|
-
restSpeed: 10,
|
|
11146
|
-
...dragTransition,
|
|
11352
|
+
velocity: axisVelocity(axis),
|
|
11353
|
+
...options,
|
|
11147
11354
|
...transition,
|
|
11148
11355
|
};
|
|
11149
11356
|
// If we're not animating on an externally-provided `MotionValue` we can use the
|
|
@@ -11474,13 +11681,13 @@
|
|
|
11474
11681
|
}
|
|
11475
11682
|
const cleanups = resolveElements(elementOrSelector).map((element) => {
|
|
11476
11683
|
scope?.track(element);
|
|
11477
|
-
const [node, release] =
|
|
11684
|
+
const [node, release] = acquireDragNode(element);
|
|
11478
11685
|
/**
|
|
11479
11686
|
* Measure layout even when not animating it, as constraints and
|
|
11480
11687
|
* layout-shift correction are computed from it.
|
|
11481
11688
|
*/
|
|
11482
11689
|
node.setOptions({ alwaysMeasureLayout: true });
|
|
11483
|
-
const controls = new VisualElementDragControls(
|
|
11690
|
+
const controls = new VisualElementDragControls(visualElementStore.get(element), () => props);
|
|
11484
11691
|
const removeListeners = controls.addListeners();
|
|
11485
11692
|
const removeStyles = applyDragStyles(element, options.axis);
|
|
11486
11693
|
return () => {
|
|
@@ -11886,9 +12093,19 @@
|
|
|
11886
12093
|
return scope;
|
|
11887
12094
|
}
|
|
11888
12095
|
|
|
12096
|
+
/**
|
|
12097
|
+
* The metrics projection counts, in the order of the index it passes to
|
|
12098
|
+
* statsBuffer.countProjection.
|
|
12099
|
+
*/
|
|
12100
|
+
const projectionMetrics = [
|
|
12101
|
+
"nodes",
|
|
12102
|
+
"calculatedTargetDeltas",
|
|
12103
|
+
"calculatedProjections",
|
|
12104
|
+
];
|
|
11889
12105
|
function clearStatsBuffer() {
|
|
11890
12106
|
statsBuffer.value = null;
|
|
11891
12107
|
statsBuffer.addProjectionMetrics = null;
|
|
12108
|
+
statsBuffer.countProjection = undefined;
|
|
11892
12109
|
}
|
|
11893
12110
|
function recordStats() {
|
|
11894
12111
|
if (statsBuffer.value) {
|
|
@@ -11909,6 +12126,27 @@
|
|
|
11909
12126
|
layoutProjection.calculatedTargetDeltas.push(metrics.calculatedTargetDeltas);
|
|
11910
12127
|
layoutProjection.calculatedProjections.push(metrics.calculatedProjections);
|
|
11911
12128
|
};
|
|
12129
|
+
/**
|
|
12130
|
+
* Counting lives here rather than in projection, so bundles that never
|
|
12131
|
+
* call recordStats() don't ship it.
|
|
12132
|
+
*/
|
|
12133
|
+
const metrics = {
|
|
12134
|
+
nodes: 0,
|
|
12135
|
+
calculatedTargetDeltas: 0,
|
|
12136
|
+
calculatedProjections: 0,
|
|
12137
|
+
};
|
|
12138
|
+
buffer.countProjection = (metric) => {
|
|
12139
|
+
if (metric !== undefined) {
|
|
12140
|
+
metrics[projectionMetrics[metric]]++;
|
|
12141
|
+
}
|
|
12142
|
+
else {
|
|
12143
|
+
buffer.addProjectionMetrics(metrics);
|
|
12144
|
+
metrics.nodes =
|
|
12145
|
+
metrics.calculatedTargetDeltas =
|
|
12146
|
+
metrics.calculatedProjections =
|
|
12147
|
+
0;
|
|
12148
|
+
}
|
|
12149
|
+
};
|
|
11912
12150
|
}
|
|
11913
12151
|
|
|
11914
12152
|
function getOriginIndex(from, total) {
|
|
@@ -14106,6 +14344,7 @@
|
|
|
14106
14344
|
exports.VisualElement = VisualElement;
|
|
14107
14345
|
exports.VisualElementDragControls = VisualElementDragControls;
|
|
14108
14346
|
exports.acceleratedValues = acceleratedValues;
|
|
14347
|
+
exports.acquireProjectionNode = acquireProjectionNode;
|
|
14109
14348
|
exports.activeScope = activeScope;
|
|
14110
14349
|
exports.addAttrValue = addAttrValue;
|
|
14111
14350
|
exports.addBuilderToScope = addBuilderToScope;
|
|
@@ -14215,6 +14454,7 @@
|
|
|
14215
14454
|
exports.findEffect = findEffect;
|
|
14216
14455
|
exports.findValueType = findValueType;
|
|
14217
14456
|
exports.flushKeyframeResolvers = flushKeyframeResolvers;
|
|
14457
|
+
exports.flushLayoutSnapshots = flushLayoutSnapshots;
|
|
14218
14458
|
exports.followValue = followValue;
|
|
14219
14459
|
exports.frame = frame;
|
|
14220
14460
|
exports.frameData = frameData;
|