motion-dom 14.7.0 → 14.8.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 +380 -148
- 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 +32 -35
- package/dist/es/animation/waapi/transforms/TransformAnimation.mjs.map +1 -1
- package/dist/es/animation/waapi/transforms/groups.mjs.map +1 -1
- package/dist/es/animation/waapi/utils/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/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 +77 -49
- 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/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 +298 -232
- package/dist/motion-dom.dev.js +380 -148
- 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/cjs/index.js
CHANGED
|
@@ -1311,10 +1311,11 @@ function inertia({ keyframes, velocity = 0.0, power = 0.8, timeConstant = 325, b
|
|
|
1311
1311
|
|
|
1312
1312
|
function createMixers(output, ease, customMixer) {
|
|
1313
1313
|
const mixers = [];
|
|
1314
|
-
const mixerFactory =
|
|
1314
|
+
const mixerFactory = motionUtils.MotionGlobalConfig.mix || mix;
|
|
1315
1315
|
const numMixers = output.length - 1;
|
|
1316
1316
|
for (let i = 0; i < numMixers; i++) {
|
|
1317
|
-
let mixer =
|
|
1317
|
+
let mixer = customMixer?.(output[i], output[i + 1]) ||
|
|
1318
|
+
mixerFactory(output[i], output[i + 1]);
|
|
1318
1319
|
if (ease) {
|
|
1319
1320
|
const easingFunction = Array.isArray(ease) ? ease[i] || motionUtils.noop : ease;
|
|
1320
1321
|
mixer = motionUtils.pipe(easingFunction, mixer);
|
|
@@ -1401,7 +1402,13 @@ function convertOffsetToTimes(offset, duration) {
|
|
|
1401
1402
|
function defaultEasing(values, easing) {
|
|
1402
1403
|
return values.map(() => easing || motionUtils.easeInOut).splice(0, values.length - 1);
|
|
1403
1404
|
}
|
|
1404
|
-
function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "easeInOut", }) {
|
|
1405
|
+
function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "easeInOut", mixer: transitionMixer, }) {
|
|
1406
|
+
/**
|
|
1407
|
+
* A mixer only blends values that aren't numbers. Numbers blend as
|
|
1408
|
+
* usual, as they do in springs, and so do the progress animations
|
|
1409
|
+
* behind layout and path animations, which take the same transition.
|
|
1410
|
+
*/
|
|
1411
|
+
const customMixer = typeof keyframeValues[0] === "number" ? undefined : transitionMixer;
|
|
1405
1412
|
/**
|
|
1406
1413
|
* Easing functions can be externally defined as strings. Here we convert them
|
|
1407
1414
|
* into actual functions.
|
|
@@ -1418,9 +1425,11 @@ function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "e
|
|
|
1418
1425
|
value: keyframeValues[0],
|
|
1419
1426
|
};
|
|
1420
1427
|
/**
|
|
1421
|
-
* Fast setup path for two keyframes one easing.
|
|
1428
|
+
* Fast setup path for two keyframes one easing. interpolate() handles
|
|
1429
|
+
* a custom mixer, and falls back to the usual one where it declines.
|
|
1422
1430
|
*/
|
|
1423
|
-
if (
|
|
1431
|
+
if (!customMixer &&
|
|
1432
|
+
keyframeValues.length === 2 &&
|
|
1424
1433
|
!Array.isArray(easingFunctions) &&
|
|
1425
1434
|
(!times ||
|
|
1426
1435
|
times.length !== 2 ||
|
|
@@ -1453,6 +1462,7 @@ function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "e
|
|
|
1453
1462
|
ease: Array.isArray(easingFunctions)
|
|
1454
1463
|
? easingFunctions
|
|
1455
1464
|
: defaultEasing(keyframeValues, easingFunctions),
|
|
1465
|
+
mixer: customMixer,
|
|
1456
1466
|
});
|
|
1457
1467
|
return {
|
|
1458
1468
|
calculatedDuration: duration,
|
|
@@ -1661,9 +1671,15 @@ class JSAnimation extends WithPromise {
|
|
|
1661
1671
|
generatorFactory !== keyframes) {
|
|
1662
1672
|
motionUtils.invariant(keyframes$1.length <= 2, `Only two keyframes currently supported with spring and inertia animations. Trying to animate ${keyframes$1}`, "spring-two-frames");
|
|
1663
1673
|
}
|
|
1674
|
+
/**
|
|
1675
|
+
* This runs again when a spring is flattened to attach it to a
|
|
1676
|
+
* timeline, and the keyframes generator blends values itself.
|
|
1677
|
+
*/
|
|
1678
|
+
this.mixKeyframes = undefined;
|
|
1664
1679
|
if (generatorFactory !== keyframes &&
|
|
1665
1680
|
typeof keyframes$1[0] !== "number") {
|
|
1666
|
-
this.mixKeyframes = motionUtils.pipe(percentToProgress,
|
|
1681
|
+
this.mixKeyframes = motionUtils.pipe(percentToProgress, options.mixer?.(keyframes$1[0], keyframes$1[1]) ||
|
|
1682
|
+
mix(keyframes$1[0], keyframes$1[1]));
|
|
1667
1683
|
keyframes$1 = [0, 100];
|
|
1668
1684
|
}
|
|
1669
1685
|
const generator = generatorFactory(keyframes$1 === options.keyframes
|
|
@@ -3017,6 +3033,15 @@ function hasBrowserOnlyColors(keyframes) {
|
|
|
3017
3033
|
return false;
|
|
3018
3034
|
}
|
|
3019
3035
|
|
|
3036
|
+
/**
|
|
3037
|
+
* Whether an animation needs its mixer, which WAAPI can't call. Numbers
|
|
3038
|
+
* blend as usual, and an animation whose mixer declines every pair runs
|
|
3039
|
+
* as it would without one.
|
|
3040
|
+
*/
|
|
3041
|
+
const needsMixer = ({ mixer, keyframes }) => mixer &&
|
|
3042
|
+
typeof keyframes[0] !== "number" &&
|
|
3043
|
+
keyframes.some((keyframe, i) => i && mixer(keyframes[i - 1], keyframe));
|
|
3044
|
+
|
|
3020
3045
|
const colorProperties = new Set([
|
|
3021
3046
|
"color",
|
|
3022
3047
|
"backgroundColor",
|
|
@@ -3076,7 +3101,8 @@ function supportsBrowserAnimation(options) {
|
|
|
3076
3101
|
!repeatDelay &&
|
|
3077
3102
|
repeatType !== "mirror" &&
|
|
3078
3103
|
damping !== 0 &&
|
|
3079
|
-
type !== "inertia"
|
|
3104
|
+
type !== "inertia" &&
|
|
3105
|
+
!needsMixer(options));
|
|
3080
3106
|
}
|
|
3081
3107
|
|
|
3082
3108
|
/**
|
|
@@ -3175,18 +3201,21 @@ const churnWindow = 100;
|
|
|
3175
3201
|
* Named easings that are the same cubic-bezier in JS and CSS.
|
|
3176
3202
|
*/
|
|
3177
3203
|
const isNativeEasing = (ease) => /^(linear|ease(In|Out|InOut))$/.test(ease);
|
|
3204
|
+
/**
|
|
3205
|
+
* Whether two eased progresses match. False if either is NaN.
|
|
3206
|
+
*/
|
|
3207
|
+
const isNear$1 = (a, b) => Math.abs(a - b) <= easingTolerance;
|
|
3178
3208
|
const byTime = (a, b) => a - b;
|
|
3179
3209
|
/**
|
|
3180
3210
|
* n + 1 evenly spaced timestamps, from one timestamp to another.
|
|
3181
3211
|
*/
|
|
3182
|
-
const spread = (from, to, n) =>
|
|
3183
|
-
const result = [];
|
|
3184
|
-
for (let i = 0; i <= n; i++)
|
|
3185
|
-
result.push(mixNumber$1(from, to, i / n));
|
|
3186
|
-
return result;
|
|
3187
|
-
};
|
|
3212
|
+
const spread = (from, to, n) => defaultOffset(Array(n + 1)).map((p) => mixNumber$1(from, to, p));
|
|
3188
3213
|
const getOwner = (options) => options.motionValue.owner;
|
|
3189
3214
|
const getGroup = (element) => transformGroups.get(element);
|
|
3215
|
+
/**
|
|
3216
|
+
* Whether an animation has ended, so can leave its group.
|
|
3217
|
+
*/
|
|
3218
|
+
const hasEnded = ({ state }) => state === "idle" || state === "finished";
|
|
3190
3219
|
const read = (owner, key) => owner.latestValues ? owner.latestValues[key] : owner.getValue(key)?.get();
|
|
3191
3220
|
/**
|
|
3192
3221
|
* Whether this animation should join its element's transform group.
|
|
@@ -3225,7 +3254,12 @@ function canAccelerateTransform(options) {
|
|
|
3225
3254
|
/**
|
|
3226
3255
|
* Layout animations write transform every frame.
|
|
3227
3256
|
*/
|
|
3228
|
-
!owner.projection?.isProjecting()
|
|
3257
|
+
!owner.projection?.isProjecting() &&
|
|
3258
|
+
/**
|
|
3259
|
+
* A mixer that blends these values makes them every frame. It's
|
|
3260
|
+
* asked last, as it's user code.
|
|
3261
|
+
*/
|
|
3262
|
+
!needsMixer(options));
|
|
3229
3263
|
}
|
|
3230
3264
|
class TransformAnimation extends JSAnimation {
|
|
3231
3265
|
constructor(options) {
|
|
@@ -3582,9 +3616,8 @@ function createGroup(owner) {
|
|
|
3582
3616
|
let shared;
|
|
3583
3617
|
let progressAt;
|
|
3584
3618
|
for (const track of moving) {
|
|
3585
|
-
const
|
|
3586
|
-
const
|
|
3587
|
-
const changes = values.map((value) => value - first);
|
|
3619
|
+
const first = track.numberAt(from);
|
|
3620
|
+
const changes = at.map((t) => track.numberAt(t) - first);
|
|
3588
3621
|
const end = changes[changes.length - 1];
|
|
3589
3622
|
/**
|
|
3590
3623
|
* A value that ends only a tiny way from where it started, as
|
|
@@ -3598,25 +3631,20 @@ function createGroup(owner) {
|
|
|
3598
3631
|
: end;
|
|
3599
3632
|
const progress = changes.map((change) => range ? change / range : change);
|
|
3600
3633
|
/**
|
|
3601
|
-
*
|
|
3602
|
-
*
|
|
3603
|
-
* fits
|
|
3634
|
+
* The first value that moves sets the easing, and every other
|
|
3635
|
+
* one must follow it. A value that doesn't change, like one
|
|
3636
|
+
* still in its delay, fits any easing. One that changes but
|
|
3637
|
+
* ends where it started fits none.
|
|
3604
3638
|
*/
|
|
3605
|
-
if (!
|
|
3606
|
-
if (progress.some((p) => !(Math.abs(p) <= easingTolerance))) {
|
|
3607
|
-
return;
|
|
3608
|
-
}
|
|
3609
|
-
}
|
|
3610
|
-
else if (!shared) {
|
|
3639
|
+
if (range && !shared) {
|
|
3611
3640
|
shared = progress;
|
|
3612
3641
|
progressAt = (t) => (track.numberAt(t) - first) / range;
|
|
3613
3642
|
}
|
|
3614
|
-
else if (progress.some((p, i) => !(
|
|
3643
|
+
else if (progress.some((p, i) => !isNear$1(p, range && shared[i]))) {
|
|
3615
3644
|
return;
|
|
3616
3645
|
}
|
|
3617
3646
|
}
|
|
3618
|
-
if (!shared ||
|
|
3619
|
-
shared.every((p, i) => Math.abs(p - position(at[i])) <= easingTolerance)) {
|
|
3647
|
+
if (!shared || shared.every((p, i) => isNear$1(p, position(at[i])))) {
|
|
3620
3648
|
return "linear";
|
|
3621
3649
|
}
|
|
3622
3650
|
/**
|
|
@@ -3703,7 +3731,7 @@ function createGroup(owner) {
|
|
|
3703
3731
|
/**
|
|
3704
3732
|
* A WAAPI animation of the composed transform between two timestamps.
|
|
3705
3733
|
*/
|
|
3706
|
-
const run = (moving, from, to, options = { fill: "both" }, settled
|
|
3734
|
+
const run = (moving, from, to, nativeEasing, options = { fill: "both" }, settled) => {
|
|
3707
3735
|
const bounds = moving.flatMap((track) => track.boundaries(from, to));
|
|
3708
3736
|
const easing = nativeEasing || getEasing(moving, from, to, bounds);
|
|
3709
3737
|
const times = easing ? [from, to] : sample(moving, from, to, bounds);
|
|
@@ -3789,9 +3817,7 @@ function createGroup(owner) {
|
|
|
3789
3817
|
if (byKey.has(key))
|
|
3790
3818
|
return true;
|
|
3791
3819
|
const value = (statics[key] = read(owner, key));
|
|
3792
|
-
return
|
|
3793
|
-
parseFloat(value) !==
|
|
3794
|
-
(key.startsWith("scale") ? 1 : 0));
|
|
3820
|
+
return value !== undefined && !isDefaultTransform(key, value);
|
|
3795
3821
|
});
|
|
3796
3822
|
stop(false);
|
|
3797
3823
|
/**
|
|
@@ -3802,7 +3828,7 @@ function createGroup(owner) {
|
|
|
3802
3828
|
try {
|
|
3803
3829
|
if (tween && tween[1] > now) {
|
|
3804
3830
|
const [from, to, easing] = tween;
|
|
3805
|
-
add(run(moving, from, to,
|
|
3831
|
+
add(run(moving, from, to, easing), from - now, to - from);
|
|
3806
3832
|
}
|
|
3807
3833
|
else if (end > now) {
|
|
3808
3834
|
add(run(moving, now, end), 0, end - now);
|
|
@@ -3819,7 +3845,7 @@ function createGroup(owner) {
|
|
|
3819
3845
|
* seamlessly, and start it part way through.
|
|
3820
3846
|
*/
|
|
3821
3847
|
const from = cycleStart + Math.floor((end - cycleStart) / cycle) * cycle;
|
|
3822
|
-
add(run(looping, from, from + cycle, {
|
|
3848
|
+
add(run(looping, from, from + cycle, undefined, {
|
|
3823
3849
|
iterations: Infinity,
|
|
3824
3850
|
iterationStart: (end - from) / cycle,
|
|
3825
3851
|
/**
|
|
@@ -3958,10 +3984,7 @@ function createGroup(owner) {
|
|
|
3958
3984
|
isScheduled = false;
|
|
3959
3985
|
if (isEnded)
|
|
3960
3986
|
return;
|
|
3961
|
-
tracks.forEach((
|
|
3962
|
-
if (state === "idle" || state === "finished")
|
|
3963
|
-
tracks.delete(track);
|
|
3964
|
-
});
|
|
3987
|
+
tracks.forEach((track) => hasEnded(track) && tracks.delete(track));
|
|
3965
3988
|
if (end())
|
|
3966
3989
|
return;
|
|
3967
3990
|
for (const track of tracks) {
|
|
@@ -4021,9 +4044,7 @@ function createGroup(owner) {
|
|
|
4021
4044
|
* Only drop the stopped animation. Others can be idle because
|
|
4022
4045
|
* they're part way through play(), and are about to run.
|
|
4023
4046
|
*/
|
|
4024
|
-
|
|
4025
|
-
if (state === "idle" || state === "finished")
|
|
4026
|
-
tracks.delete(track);
|
|
4047
|
+
hasEnded(track) && tracks.delete(track);
|
|
4027
4048
|
end() || group.schedule(true);
|
|
4028
4049
|
},
|
|
4029
4050
|
/**
|
|
@@ -4054,6 +4075,7 @@ function createGroup(owner) {
|
|
|
4054
4075
|
built = new Map();
|
|
4055
4076
|
stop();
|
|
4056
4077
|
tracks.forEach((track) => track.state === "running" && track.js?.start());
|
|
4078
|
+
return true;
|
|
4057
4079
|
},
|
|
4058
4080
|
};
|
|
4059
4081
|
transformGroups.set(element, group);
|
|
@@ -4579,10 +4601,19 @@ class MotionValue {
|
|
|
4579
4601
|
* effects, and resets velocity to `0`.
|
|
4580
4602
|
*/
|
|
4581
4603
|
jump(v, endAnimation = true) {
|
|
4604
|
+
if (endAnimation) {
|
|
4605
|
+
/**
|
|
4606
|
+
* Stop first, as stopping a running animation can set the
|
|
4607
|
+
* value it's showing, which would replace v. Marking the value
|
|
4608
|
+
* as updated now skips a JS animation's catch-up tick on stop,
|
|
4609
|
+
* which could otherwise complete it.
|
|
4610
|
+
*/
|
|
4611
|
+
this.updatedAt = time.now();
|
|
4612
|
+
this.stop();
|
|
4613
|
+
}
|
|
4582
4614
|
this.updateAndNotify(v);
|
|
4583
4615
|
this.prev = v;
|
|
4584
4616
|
this.prevUpdatedAt = this.prevFrameValue = undefined;
|
|
4585
|
-
endAnimation && this.stop();
|
|
4586
4617
|
this.stopPassiveEffect?.();
|
|
4587
4618
|
}
|
|
4588
4619
|
dirty() {
|
|
@@ -4801,6 +4832,7 @@ const orchestrationKeys = new Set([
|
|
|
4801
4832
|
"from",
|
|
4802
4833
|
"elapsed",
|
|
4803
4834
|
"out",
|
|
4835
|
+
"mixer",
|
|
4804
4836
|
]);
|
|
4805
4837
|
/**
|
|
4806
4838
|
* Decide whether a transition is defined on a given Transition.
|
|
@@ -6360,6 +6392,20 @@ const addSVGValue = (element, state, key, value) => {
|
|
|
6360
6392
|
else if (key.startsWith("attr")) {
|
|
6361
6393
|
return addAttrValue(element, state, key, value, convertAttrKey(key));
|
|
6362
6394
|
}
|
|
6395
|
+
else if (key === "d") {
|
|
6396
|
+
/**
|
|
6397
|
+
* `d` is a CSS property in Chrome and Firefox, but only as
|
|
6398
|
+
* `path(...)`, so path data goes to the attribute, taken out of
|
|
6399
|
+
* `path(...)` if it's written that way. Path data itself has no
|
|
6400
|
+
* quotes or brackets.
|
|
6401
|
+
*/
|
|
6402
|
+
return state.set(key, value, () => {
|
|
6403
|
+
const d = value.get()?.replace(/path\(|["')]/g, "");
|
|
6404
|
+
d === undefined
|
|
6405
|
+
? element.removeAttribute(key)
|
|
6406
|
+
: element.setAttribute(key, d);
|
|
6407
|
+
});
|
|
6408
|
+
}
|
|
6363
6409
|
/**
|
|
6364
6410
|
* Transforms and origins aren't CSS properties (bar `x`/`y` in some
|
|
6365
6411
|
* browsers), so check them by name rather than `key in element.style`.
|
|
@@ -6616,6 +6662,10 @@ function measurePageBox(element, rootProjectionNode, transformPagePoint) {
|
|
|
6616
6662
|
}
|
|
6617
6663
|
return viewportBox;
|
|
6618
6664
|
}
|
|
6665
|
+
const measureDocumentScroll = () => ({
|
|
6666
|
+
x: document.documentElement.scrollLeft || document.body?.scrollLeft || 0,
|
|
6667
|
+
y: document.documentElement.scrollTop || document.body?.scrollTop || 0,
|
|
6668
|
+
});
|
|
6619
6669
|
|
|
6620
6670
|
const noProps = {};
|
|
6621
6671
|
const getElementEffect = (element) => (isSVGElement(element)
|
|
@@ -6792,6 +6842,7 @@ function isForcedMotionValue(key, { layout, layoutId }) {
|
|
|
6792
6842
|
const statsBuffer = {
|
|
6793
6843
|
value: null,
|
|
6794
6844
|
addProjectionMetrics: null,
|
|
6845
|
+
countProjection: undefined,
|
|
6795
6846
|
};
|
|
6796
6847
|
|
|
6797
6848
|
/**
|
|
@@ -6814,6 +6865,12 @@ function delayInSeconds(callback, timeout) {
|
|
|
6814
6865
|
return delay(callback, motionUtils.secondsToMilliseconds(timeout));
|
|
6815
6866
|
}
|
|
6816
6867
|
|
|
6868
|
+
function isRefObject(ref) {
|
|
6869
|
+
return (ref &&
|
|
6870
|
+
typeof ref === "object" &&
|
|
6871
|
+
Object.prototype.hasOwnProperty.call(ref, "current"));
|
|
6872
|
+
}
|
|
6873
|
+
|
|
6817
6874
|
/**
|
|
6818
6875
|
* Checks if an element is specifically an SVGSVGElement (the root SVG element)
|
|
6819
6876
|
* in a way that works across iframes
|
|
@@ -7028,6 +7085,27 @@ function removeBoxTransforms(box, transforms, originBox, sourceBox) {
|
|
|
7028
7085
|
removeAxisTransforms(box.y, transforms, yKeys, originBox?.y, sourceBox?.y);
|
|
7029
7086
|
}
|
|
7030
7087
|
|
|
7088
|
+
const userAgentContains = (string) => typeof navigator !== "undefined" &&
|
|
7089
|
+
navigator.userAgent &&
|
|
7090
|
+
navigator.userAgent.toLowerCase().includes(string);
|
|
7091
|
+
/**
|
|
7092
|
+
* Measured bounding boxes must be rounded in Safari and
|
|
7093
|
+
* left untouched in Chrome, otherwise non-integer layouts within scaled-up elements
|
|
7094
|
+
* can appear to jump.
|
|
7095
|
+
*/
|
|
7096
|
+
const roundPoint = userAgentContains("applewebkit/") && !userAgentContains("chrome/")
|
|
7097
|
+
? Math.round
|
|
7098
|
+
: motionUtils.noop;
|
|
7099
|
+
function roundAxis(axis) {
|
|
7100
|
+
// Round to the nearest .5 pixels to support subpixel layouts
|
|
7101
|
+
axis.min = roundPoint(axis.min);
|
|
7102
|
+
axis.max = roundPoint(axis.max);
|
|
7103
|
+
}
|
|
7104
|
+
function roundBox(box) {
|
|
7105
|
+
roundAxis(box.x);
|
|
7106
|
+
roundAxis(box.y);
|
|
7107
|
+
}
|
|
7108
|
+
|
|
7031
7109
|
const createAxisDelta = () => ({
|
|
7032
7110
|
translate: 0,
|
|
7033
7111
|
scale: 1,
|
|
@@ -7324,11 +7402,6 @@ const globalProjectionState = {
|
|
|
7324
7402
|
hasEverUpdated: false,
|
|
7325
7403
|
};
|
|
7326
7404
|
|
|
7327
|
-
const metrics = {
|
|
7328
|
-
nodes: 0,
|
|
7329
|
-
calculatedTargetDeltas: 0,
|
|
7330
|
-
calculatedProjections: 0,
|
|
7331
|
-
};
|
|
7332
7405
|
/**
|
|
7333
7406
|
* Transforms that distort an element's layout, so must be reset before measuring.
|
|
7334
7407
|
*/
|
|
@@ -7350,7 +7423,15 @@ function resetDistortingTransform(key, visualElement, values, sharedAnimationVal
|
|
|
7350
7423
|
}
|
|
7351
7424
|
}
|
|
7352
7425
|
}
|
|
7353
|
-
|
|
7426
|
+
/**
|
|
7427
|
+
* Move accelerated transforms back to the main thread. The WAAPI animation
|
|
7428
|
+
* hid startUpdate()'s reset of rotations, skews and z, and moving off it
|
|
7429
|
+
* writes the whole transform back, so reset them again before this node
|
|
7430
|
+
* is measured.
|
|
7431
|
+
*/
|
|
7432
|
+
const demoteTransforms = (node) => node.instance &&
|
|
7433
|
+
transformGroups.get(node.instance)?.demote() &&
|
|
7434
|
+
node.resetSkewAndRotation();
|
|
7354
7435
|
function cancelTreeOptimisedTransformAnimations(projectionNode) {
|
|
7355
7436
|
projectionNode.hasCheckedOptimisedAppear = true;
|
|
7356
7437
|
if (projectionNode.root === projectionNode)
|
|
@@ -7368,6 +7449,13 @@ function cancelTreeOptimisedTransformAnimations(projectionNode) {
|
|
|
7368
7449
|
cancelTreeOptimisedTransformAnimations(parent);
|
|
7369
7450
|
}
|
|
7370
7451
|
}
|
|
7452
|
+
function getClosestProjectingNode(visualElement) {
|
|
7453
|
+
if (!visualElement)
|
|
7454
|
+
return undefined;
|
|
7455
|
+
return visualElement.options.allowProjection !== false
|
|
7456
|
+
? visualElement.projection
|
|
7457
|
+
: getClosestProjectingNode(visualElement.parent);
|
|
7458
|
+
}
|
|
7371
7459
|
function createProjectionNode({ attachResizeListener, defaultParent, measureScroll, checkIsScrollRoot, resetTransform, }) {
|
|
7372
7460
|
/**
|
|
7373
7461
|
* Correctors registered via addScaleCorrector before projection loaded
|
|
@@ -7380,6 +7468,57 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
7380
7468
|
...scaleCorrectors,
|
|
7381
7469
|
});
|
|
7382
7470
|
return class ProjectionNode {
|
|
7471
|
+
/**
|
|
7472
|
+
* Create the projection node of a `motion` component's VisualElement,
|
|
7473
|
+
* from its props. This runs while the component renders, before its
|
|
7474
|
+
* children. It's here rather than in the component so React
|
|
7475
|
+
* bundles only include it with the features that supply a
|
|
7476
|
+
* ProjectionNode. Vanilla bundles that use the projection node
|
|
7477
|
+
* (drag(), animateLayout()) include it too, as a class static
|
|
7478
|
+
* can't be tree-shaken.
|
|
7479
|
+
*/
|
|
7480
|
+
static create(visualElement, props, initialPromotionConfig) {
|
|
7481
|
+
const { layoutId, layout, drag, dragConstraints, layoutScroll, layoutRoot, layoutAnchor, layoutCrossfade, } = props;
|
|
7482
|
+
const projection = (visualElement.projection = new this(visualElement.latestValues, props["data-framer-portal-id"]
|
|
7483
|
+
? undefined
|
|
7484
|
+
: getClosestProjectingNode(visualElement.parent)));
|
|
7485
|
+
projection.setOptions({
|
|
7486
|
+
layoutId,
|
|
7487
|
+
layout,
|
|
7488
|
+
alwaysMeasureLayout: Boolean(drag) ||
|
|
7489
|
+
(dragConstraints && isRefObject(dragConstraints)),
|
|
7490
|
+
visualElement,
|
|
7491
|
+
/**
|
|
7492
|
+
* TODO: Update options in an effect. This could be tricky as it'll be too late
|
|
7493
|
+
* to update by the time layout animations run.
|
|
7494
|
+
* We also need to fix this safeToRemove by linking it up to the one returned by usePresence,
|
|
7495
|
+
* ensuring it gets called if there's no potential layout animations.
|
|
7496
|
+
*
|
|
7497
|
+
*/
|
|
7498
|
+
animationType: typeof layout === "string" ? layout : "both",
|
|
7499
|
+
initialPromotionConfig,
|
|
7500
|
+
crossfade: layoutCrossfade,
|
|
7501
|
+
layoutScroll,
|
|
7502
|
+
layoutRoot,
|
|
7503
|
+
layoutAnchor,
|
|
7504
|
+
});
|
|
7505
|
+
/**
|
|
7506
|
+
* This node will take over from its layoutId's current lead, so snapshot
|
|
7507
|
+
* the lead now, while rendering. By the time the lead unmounts (or this
|
|
7508
|
+
* node mounts) React may already have committed DOM changes that come
|
|
7509
|
+
* before it in the tree, like a sibling changing height, and a snapshot
|
|
7510
|
+
* taken then starts the animation from a position never seen on screen.
|
|
7511
|
+
*
|
|
7512
|
+
* If React discards this render (e.g. it suspends), nothing else
|
|
7513
|
+
* completes the update, so check it after the next frame as an
|
|
7514
|
+
* unmounting node does.
|
|
7515
|
+
*/
|
|
7516
|
+
const lead = projection.getStack()?.lead;
|
|
7517
|
+
if (lead && !projection.root.isUpdateBlocked()) {
|
|
7518
|
+
lead.willUpdate();
|
|
7519
|
+
lead.scheduleCheckAfterUnmount();
|
|
7520
|
+
}
|
|
7521
|
+
}
|
|
7383
7522
|
constructor(latestValues = {}, parent = defaultParent?.()) {
|
|
7384
7523
|
/**
|
|
7385
7524
|
* A unique ID generated for every projection node.
|
|
@@ -7492,23 +7631,14 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
7492
7631
|
*/
|
|
7493
7632
|
this.updateProjection = () => {
|
|
7494
7633
|
this.projectionUpdateScheduled = false;
|
|
7495
|
-
/**
|
|
7496
|
-
* Reset debug counts. Manually resetting rather than creating a new
|
|
7497
|
-
* object each frame.
|
|
7498
|
-
*/
|
|
7499
|
-
if (statsBuffer.value) {
|
|
7500
|
-
metrics.nodes =
|
|
7501
|
-
metrics.calculatedTargetDeltas =
|
|
7502
|
-
metrics.calculatedProjections =
|
|
7503
|
-
0;
|
|
7504
|
-
}
|
|
7505
7634
|
this.nodes.forEach(propagateDirtyNodes);
|
|
7506
7635
|
this.nodes.forEach(resolveTargetDelta);
|
|
7507
7636
|
this.nodes.forEach(calcProjection);
|
|
7508
7637
|
this.nodes.forEach(cleanDirtyNodes);
|
|
7509
|
-
|
|
7510
|
-
|
|
7511
|
-
|
|
7638
|
+
/**
|
|
7639
|
+
* Record this frame's debug counts, if recordStats() is running.
|
|
7640
|
+
*/
|
|
7641
|
+
statsBuffer.countProjection?.();
|
|
7512
7642
|
};
|
|
7513
7643
|
/**
|
|
7514
7644
|
* Frame calculations
|
|
@@ -8224,9 +8354,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8224
8354
|
/**
|
|
8225
8355
|
* Increase debug counter for resolved target deltas
|
|
8226
8356
|
*/
|
|
8227
|
-
|
|
8228
|
-
metrics.calculatedTargetDeltas++;
|
|
8229
|
-
}
|
|
8357
|
+
statsBuffer.countProjection?.(1); // calculatedTargetDeltas
|
|
8230
8358
|
}
|
|
8231
8359
|
getClosestProjectingParent() {
|
|
8232
8360
|
if (!this.parent ||
|
|
@@ -8374,9 +8502,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
8374
8502
|
/**
|
|
8375
8503
|
* Increase debug counter for recalculated projections
|
|
8376
8504
|
*/
|
|
8377
|
-
|
|
8378
|
-
metrics.calculatedProjections++;
|
|
8379
|
-
}
|
|
8505
|
+
statsBuffer.countProjection?.(2); // calculatedProjections
|
|
8380
8506
|
}
|
|
8381
8507
|
hide() {
|
|
8382
8508
|
this.isVisible = false;
|
|
@@ -8903,9 +9029,7 @@ function propagateDirtyNodes(node) {
|
|
|
8903
9029
|
/**
|
|
8904
9030
|
* Increase debug counter for nodes encountered this frame
|
|
8905
9031
|
*/
|
|
8906
|
-
|
|
8907
|
-
metrics.nodes++;
|
|
8908
|
-
}
|
|
9032
|
+
statsBuffer.countProjection?.(0); // nodes
|
|
8909
9033
|
if (!node.parent)
|
|
8910
9034
|
return;
|
|
8911
9035
|
/**
|
|
@@ -9036,26 +9160,6 @@ const defaultLayoutTransition = {
|
|
|
9036
9160
|
duration: 0.45,
|
|
9037
9161
|
ease: [0.4, 0, 0.1, 1],
|
|
9038
9162
|
};
|
|
9039
|
-
const userAgentContains = (string) => typeof navigator !== "undefined" &&
|
|
9040
|
-
navigator.userAgent &&
|
|
9041
|
-
navigator.userAgent.toLowerCase().includes(string);
|
|
9042
|
-
/**
|
|
9043
|
-
* Measured bounding boxes must be rounded in Safari and
|
|
9044
|
-
* left untouched in Chrome, otherwise non-integer layouts within scaled-up elements
|
|
9045
|
-
* can appear to jump.
|
|
9046
|
-
*/
|
|
9047
|
-
const roundPoint = userAgentContains("applewebkit/") && !userAgentContains("chrome/")
|
|
9048
|
-
? Math.round
|
|
9049
|
-
: motionUtils.noop;
|
|
9050
|
-
function roundAxis(axis) {
|
|
9051
|
-
// Round to the nearest .5 pixels to support subpixel layouts
|
|
9052
|
-
axis.min = roundPoint(axis.min);
|
|
9053
|
-
axis.max = roundPoint(axis.max);
|
|
9054
|
-
}
|
|
9055
|
-
function roundBox(box) {
|
|
9056
|
-
roundAxis(box.x);
|
|
9057
|
-
roundAxis(box.y);
|
|
9058
|
-
}
|
|
9059
9163
|
/**
|
|
9060
9164
|
* Align an axis to the start of another, keeping the length of a layout axis.
|
|
9061
9165
|
* The length is read first, as output can be the layout axis itself.
|
|
@@ -9080,14 +9184,7 @@ function addDomEvent(target, eventName, handler, options = { passive: true }) {
|
|
|
9080
9184
|
const DocumentProjectionNode =
|
|
9081
9185
|
/* @__PURE__ */ createProjectionNode({
|
|
9082
9186
|
attachResizeListener: (ref, notify) => addDomEvent(ref, "resize", notify),
|
|
9083
|
-
measureScroll:
|
|
9084
|
-
x: document.documentElement.scrollLeft ||
|
|
9085
|
-
document.body?.scrollLeft ||
|
|
9086
|
-
0,
|
|
9087
|
-
y: document.documentElement.scrollTop ||
|
|
9088
|
-
document.body?.scrollTop ||
|
|
9089
|
-
0,
|
|
9090
|
-
}),
|
|
9187
|
+
measureScroll: measureDocumentScroll,
|
|
9091
9188
|
checkIsScrollRoot: () => true,
|
|
9092
9189
|
});
|
|
9093
9190
|
|
|
@@ -9854,6 +9951,124 @@ class HTMLVisualElement extends DOMVisualElement {
|
|
|
9854
9951
|
}
|
|
9855
9952
|
}
|
|
9856
9953
|
|
|
9954
|
+
/**
|
|
9955
|
+
* Get the VisualElement that imperative APIs like animateLayout() and
|
|
9956
|
+
* drag() render an element with, creating one if it has none, ready for
|
|
9957
|
+
* a projection node to be attached.
|
|
9958
|
+
*/
|
|
9959
|
+
function resolveVisualElement(element) {
|
|
9960
|
+
let visualElement = visualElementStore.get(element);
|
|
9961
|
+
if (!visualElement) {
|
|
9962
|
+
visualElement = new HTMLVisualElement({
|
|
9963
|
+
props: {},
|
|
9964
|
+
presenceContext: null,
|
|
9965
|
+
visualState: {
|
|
9966
|
+
latestValues: {},
|
|
9967
|
+
renderState: {
|
|
9968
|
+
transform: {},
|
|
9969
|
+
transformOrigin: {},
|
|
9970
|
+
style: {},
|
|
9971
|
+
vars: {},
|
|
9972
|
+
},
|
|
9973
|
+
},
|
|
9974
|
+
}, { allowProjection: true });
|
|
9975
|
+
/**
|
|
9976
|
+
* Values animate() has been rendering on this element move to
|
|
9977
|
+
* the VisualElement, so the layout animation composes with
|
|
9978
|
+
* them instead of overwriting them.
|
|
9979
|
+
*/
|
|
9980
|
+
handOffElementState(element, visualElement);
|
|
9981
|
+
}
|
|
9982
|
+
/**
|
|
9983
|
+
* A first-time element may carry a projection transform in its
|
|
9984
|
+
* inline style (e.g. it was cloned from an element mid-animation).
|
|
9985
|
+
* That transform isn't tracked in latestValues so the engine can't
|
|
9986
|
+
* reset it before measuring - clear it now so the first layout
|
|
9987
|
+
* measurement isn't inflated.
|
|
9988
|
+
*/
|
|
9989
|
+
if (element.style.transform && !hasTransform(visualElement.latestValues)) {
|
|
9990
|
+
element.style.transform = "";
|
|
9991
|
+
}
|
|
9992
|
+
return visualElement;
|
|
9993
|
+
}
|
|
9994
|
+
|
|
9995
|
+
/**
|
|
9996
|
+
* animateLayout() registers a function here that creates nodes in the
|
|
9997
|
+
* layout projection tree. When it's in the bundle, drag() uses those, so
|
|
9998
|
+
* the two work together (e.g. a drag follows a layout change mid-gesture).
|
|
9999
|
+
* Otherwise drag() makes do with a node that only measures. Bundles that
|
|
10000
|
+
* don't tree-shake (dev pre-bundling, CDN builds) always register it, and
|
|
10001
|
+
* a drag() started before animateLayout() is lazy loaded keeps its node.
|
|
10002
|
+
*/
|
|
10003
|
+
const layoutProjection = {};
|
|
10004
|
+
/**
|
|
10005
|
+
* The document root of measurement-only nodes. Like the projection tree's
|
|
10006
|
+
* root, it keeps its scroll until drag controls clear it to re-measure.
|
|
10007
|
+
*/
|
|
10008
|
+
const root = {
|
|
10009
|
+
updateScroll: () => {
|
|
10010
|
+
root.scroll || (root.scroll = { offset: measureDocumentScroll() });
|
|
10011
|
+
},
|
|
10012
|
+
};
|
|
10013
|
+
/**
|
|
10014
|
+
* The part of a projection node that drag controls use: measuring the
|
|
10015
|
+
* element's page box, for its layout and constraints. It never projects
|
|
10016
|
+
* or joins a layout update.
|
|
10017
|
+
*/
|
|
10018
|
+
const createMeasureNode = (element) => {
|
|
10019
|
+
const visualElement = resolveVisualElement(element);
|
|
10020
|
+
const measureListeners = new motionUtils.SubscriptionManager();
|
|
10021
|
+
const node = {
|
|
10022
|
+
instance: element,
|
|
10023
|
+
root,
|
|
10024
|
+
path: [root],
|
|
10025
|
+
setOptions: motionUtils.noop,
|
|
10026
|
+
/**
|
|
10027
|
+
* Truthy like the full node's method, which HTMLVisualElement reads
|
|
10028
|
+
* (rather than calls) to default transform values.
|
|
10029
|
+
*/
|
|
10030
|
+
isProjecting: motionUtils.noop,
|
|
10031
|
+
applyProjectionStyles: motionUtils.noop,
|
|
10032
|
+
removeElementScroll: (box) => box,
|
|
10033
|
+
updateLayout: () => {
|
|
10034
|
+
const layoutBox = measurePageBox(element, root, visualElement.getTransformPagePoint());
|
|
10035
|
+
roundBox(layoutBox);
|
|
10036
|
+
node.layout = { layoutBox };
|
|
10037
|
+
measureListeners.notify();
|
|
10038
|
+
},
|
|
10039
|
+
addEventListener: (name, handler) => name === "measure" ? measureListeners.add(handler) : motionUtils.noop,
|
|
10040
|
+
/**
|
|
10041
|
+
* Detach from the VisualElement too, so it doesn't later remount
|
|
10042
|
+
* (or a `motion` component's layout feature adopt) a node that
|
|
10043
|
+
* can't do either.
|
|
10044
|
+
*/
|
|
10045
|
+
unmount: () => {
|
|
10046
|
+
node.instance = undefined;
|
|
10047
|
+
if (visualElement.projection === node) {
|
|
10048
|
+
visualElement.projection = undefined;
|
|
10049
|
+
}
|
|
10050
|
+
},
|
|
10051
|
+
};
|
|
10052
|
+
visualElement.projection = node;
|
|
10053
|
+
visualElement.current || visualElement.mount(element);
|
|
10054
|
+
return [node, node.unmount];
|
|
10055
|
+
};
|
|
10056
|
+
/**
|
|
10057
|
+
* Get a projection node for drag() to measure an element with, and a
|
|
10058
|
+
* function that releases it. Reuses a node a `motion` component or
|
|
10059
|
+
* animateLayout() owns.
|
|
10060
|
+
*/
|
|
10061
|
+
const acquireDragNode = (element) => {
|
|
10062
|
+
const owned = visualElementStore.get(element)?.projection;
|
|
10063
|
+
/**
|
|
10064
|
+
* A VisualElement can outlive its node (e.g. an unmounted `motion`
|
|
10065
|
+
* component's), so only reuse a node that's still mounted.
|
|
10066
|
+
*/
|
|
10067
|
+
return owned?.instance
|
|
10068
|
+
? [owned, motionUtils.noop]
|
|
10069
|
+
: (layoutProjection.create || createMeasureNode)(element);
|
|
10070
|
+
};
|
|
10071
|
+
|
|
9857
10072
|
const layoutSelector = "[data-layout],[data-layout-id]";
|
|
9858
10073
|
/**
|
|
9859
10074
|
* All imperatively-created projection nodes live in one persistent tree,
|
|
@@ -9906,21 +10121,6 @@ function getProjectionParent(element) {
|
|
|
9906
10121
|
}
|
|
9907
10122
|
return undefined;
|
|
9908
10123
|
}
|
|
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
10124
|
function readNodeOptions(element, transition) {
|
|
9925
10125
|
const layoutAttr = element.getAttribute("data-layout");
|
|
9926
10126
|
const layoutId = element.getAttribute("data-layout-id") ?? undefined;
|
|
@@ -9936,27 +10136,7 @@ function readNodeOptions(element, transition) {
|
|
|
9936
10136
|
function prepareNode(element, transition) {
|
|
9937
10137
|
let node = layoutNodes.get(element);
|
|
9938
10138
|
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
|
-
}
|
|
10139
|
+
const visualElement = resolveVisualElement(element);
|
|
9960
10140
|
node = new HTMLProjectionNode(visualElement.latestValues, getProjectionParent(element));
|
|
9961
10141
|
visualElement.projection = node;
|
|
9962
10142
|
node.setOptions({
|
|
@@ -9976,10 +10156,26 @@ function prepareNode(element, transition) {
|
|
|
9976
10156
|
return node;
|
|
9977
10157
|
}
|
|
9978
10158
|
/**
|
|
9979
|
-
*
|
|
9980
|
-
*
|
|
9981
|
-
|
|
9982
|
-
|
|
10159
|
+
* Create a node for an element in the shared imperative tree. Returns the
|
|
10160
|
+
* node and a function that releases it.
|
|
10161
|
+
*/
|
|
10162
|
+
function createLayoutNode(element) {
|
|
10163
|
+
const node = prepareNode(element);
|
|
10164
|
+
return [
|
|
10165
|
+
node,
|
|
10166
|
+
() => layoutNodes.get(element) === node && dropNode(element, node),
|
|
10167
|
+
];
|
|
10168
|
+
}
|
|
10169
|
+
/**
|
|
10170
|
+
* Let drag() create its nodes in the shared imperative tree, so drag
|
|
10171
|
+
* gestures and layout animations work together.
|
|
10172
|
+
*/
|
|
10173
|
+
layoutProjection.create = createLayoutNode;
|
|
10174
|
+
/**
|
|
10175
|
+
* Get a projection node for an element, so motion/remix can measure and
|
|
10176
|
+
* animate its layout. Reuses a node owned by a `motion` component or
|
|
10177
|
+
* animateLayout(), otherwise creates one in the shared imperative tree.
|
|
10178
|
+
* Returns the node and a function that releases it.
|
|
9983
10179
|
*/
|
|
9984
10180
|
function acquireProjectionNode(element) {
|
|
9985
10181
|
const owned = layoutNodes.get(element) || visualElementStore.get(element)?.projection;
|
|
@@ -9987,13 +10183,7 @@ function acquireProjectionNode(element) {
|
|
|
9987
10183
|
* A VisualElement can outlive a node we released (e.g. a stopped
|
|
9988
10184
|
* drag()), so only reuse a node that's still mounted.
|
|
9989
10185
|
*/
|
|
9990
|
-
|
|
9991
|
-
return [owned, () => { }];
|
|
9992
|
-
const node = prepareNode(element);
|
|
9993
|
-
return [
|
|
9994
|
-
node,
|
|
9995
|
-
() => layoutNodes.get(element) === node && dropNode(element, node),
|
|
9996
|
-
];
|
|
10186
|
+
return owned?.instance ? [owned, () => { }] : createLayoutNode(element);
|
|
9997
10187
|
}
|
|
9998
10188
|
function sortDocumentOrder(elements) {
|
|
9999
10189
|
return [...elements].sort((a, b) => a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1);
|
|
@@ -10013,6 +10203,8 @@ function dropNode(element, node) {
|
|
|
10013
10203
|
}
|
|
10014
10204
|
function flushPendingBuilders() {
|
|
10015
10205
|
const builders = pendingBuilders;
|
|
10206
|
+
if (!builders)
|
|
10207
|
+
return;
|
|
10016
10208
|
pendingBuilders = undefined;
|
|
10017
10209
|
flushPendingFrame();
|
|
10018
10210
|
/**
|
|
@@ -10077,6 +10269,13 @@ function flushPendingBuilders() {
|
|
|
10077
10269
|
};
|
|
10078
10270
|
updatePromises.length ? Promise.all(updatePromises).then(commit) : commit();
|
|
10079
10271
|
}
|
|
10272
|
+
/**
|
|
10273
|
+
* Snapshot every pending animateLayout() now, rather than on the next
|
|
10274
|
+
* microtask. For renderers that tell us a DOM update is about to happen
|
|
10275
|
+
* and then make it synchronously (e.g. a beforeUpdate/commit pair), with
|
|
10276
|
+
* updateDom returning a promise that resolves on commit.
|
|
10277
|
+
*/
|
|
10278
|
+
const flushLayoutSnapshots = flushPendingBuilders;
|
|
10080
10279
|
class LayoutAnimationBuilder {
|
|
10081
10280
|
constructor(scope, updateDom, defaultOptions) {
|
|
10082
10281
|
this.scope = scope;
|
|
@@ -11475,13 +11674,13 @@ function drag(elementOrSelector, options = {}) {
|
|
|
11475
11674
|
}
|
|
11476
11675
|
const cleanups = resolveElements(elementOrSelector).map((element) => {
|
|
11477
11676
|
scope?.track(element);
|
|
11478
|
-
const [node, release] =
|
|
11677
|
+
const [node, release] = acquireDragNode(element);
|
|
11479
11678
|
/**
|
|
11480
11679
|
* Measure layout even when not animating it, as constraints and
|
|
11481
11680
|
* layout-shift correction are computed from it.
|
|
11482
11681
|
*/
|
|
11483
11682
|
node.setOptions({ alwaysMeasureLayout: true });
|
|
11484
|
-
const controls = new VisualElementDragControls(
|
|
11683
|
+
const controls = new VisualElementDragControls(visualElementStore.get(element), () => props);
|
|
11485
11684
|
const removeListeners = controls.addListeners();
|
|
11486
11685
|
const removeStyles = applyDragStyles(element, options.axis);
|
|
11487
11686
|
return () => {
|
|
@@ -11887,9 +12086,19 @@ function scopeMotion(...args) {
|
|
|
11887
12086
|
return scope;
|
|
11888
12087
|
}
|
|
11889
12088
|
|
|
12089
|
+
/**
|
|
12090
|
+
* The metrics projection counts, in the order of the index it passes to
|
|
12091
|
+
* statsBuffer.countProjection.
|
|
12092
|
+
*/
|
|
12093
|
+
const projectionMetrics = [
|
|
12094
|
+
"nodes",
|
|
12095
|
+
"calculatedTargetDeltas",
|
|
12096
|
+
"calculatedProjections",
|
|
12097
|
+
];
|
|
11890
12098
|
function clearStatsBuffer() {
|
|
11891
12099
|
statsBuffer.value = null;
|
|
11892
12100
|
statsBuffer.addProjectionMetrics = null;
|
|
12101
|
+
statsBuffer.countProjection = undefined;
|
|
11893
12102
|
}
|
|
11894
12103
|
function recordStats() {
|
|
11895
12104
|
if (statsBuffer.value) {
|
|
@@ -11910,6 +12119,27 @@ function recordStats() {
|
|
|
11910
12119
|
layoutProjection.calculatedTargetDeltas.push(metrics.calculatedTargetDeltas);
|
|
11911
12120
|
layoutProjection.calculatedProjections.push(metrics.calculatedProjections);
|
|
11912
12121
|
};
|
|
12122
|
+
/**
|
|
12123
|
+
* Counting lives here rather than in projection, so bundles that never
|
|
12124
|
+
* call recordStats() don't ship it.
|
|
12125
|
+
*/
|
|
12126
|
+
const metrics = {
|
|
12127
|
+
nodes: 0,
|
|
12128
|
+
calculatedTargetDeltas: 0,
|
|
12129
|
+
calculatedProjections: 0,
|
|
12130
|
+
};
|
|
12131
|
+
buffer.countProjection = (metric) => {
|
|
12132
|
+
if (metric !== undefined) {
|
|
12133
|
+
metrics[projectionMetrics[metric]]++;
|
|
12134
|
+
}
|
|
12135
|
+
else {
|
|
12136
|
+
buffer.addProjectionMetrics(metrics);
|
|
12137
|
+
metrics.nodes =
|
|
12138
|
+
metrics.calculatedTargetDeltas =
|
|
12139
|
+
metrics.calculatedProjections =
|
|
12140
|
+
0;
|
|
12141
|
+
}
|
|
12142
|
+
};
|
|
11913
12143
|
}
|
|
11914
12144
|
|
|
11915
12145
|
function getOriginIndex(from, total) {
|
|
@@ -14108,6 +14338,7 @@ exports.ViewTransitionBuilder = ViewTransitionBuilder;
|
|
|
14108
14338
|
exports.VisualElement = VisualElement;
|
|
14109
14339
|
exports.VisualElementDragControls = VisualElementDragControls;
|
|
14110
14340
|
exports.acceleratedValues = acceleratedValues;
|
|
14341
|
+
exports.acquireProjectionNode = acquireProjectionNode;
|
|
14111
14342
|
exports.activeScope = activeScope;
|
|
14112
14343
|
exports.addAttrValue = addAttrValue;
|
|
14113
14344
|
exports.addBuilderToScope = addBuilderToScope;
|
|
@@ -14217,6 +14448,7 @@ exports.findDimensionValueType = findDimensionValueType;
|
|
|
14217
14448
|
exports.findEffect = findEffect;
|
|
14218
14449
|
exports.findValueType = findValueType;
|
|
14219
14450
|
exports.flushKeyframeResolvers = flushKeyframeResolvers;
|
|
14451
|
+
exports.flushLayoutSnapshots = flushLayoutSnapshots;
|
|
14220
14452
|
exports.followValue = followValue;
|
|
14221
14453
|
exports.frame = frame;
|
|
14222
14454
|
exports.frameData = frameData;
|