motion-dom 12.42.1 → 12.43.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 +157 -62
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/waapi/supports/waapi.mjs +7 -5
- package/dist/es/animation/waapi/supports/waapi.mjs.map +1 -1
- package/dist/es/animation/waapi/utils/accelerated-values.mjs +1 -3
- package/dist/es/animation/waapi/utils/accelerated-values.mjs.map +1 -1
- package/dist/es/animation/waapi/utils/px-values.mjs +3 -4
- package/dist/es/animation/waapi/utils/px-values.mjs.map +1 -1
- package/dist/es/projection/animation/mix-values.mjs +3 -8
- package/dist/es/projection/animation/mix-values.mjs.map +1 -1
- package/dist/es/projection/styles/scale-correction.mjs +2 -6
- package/dist/es/projection/styles/scale-correction.mjs.map +1 -1
- package/dist/es/render/html/HTMLVisualElement.mjs +10 -0
- package/dist/es/render/html/HTMLVisualElement.mjs.map +1 -1
- package/dist/es/utils/border-radius.mjs +15 -0
- package/dist/es/utils/border-radius.mjs.map +1 -0
- package/dist/es/view/start.mjs +124 -36
- package/dist/es/view/start.mjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/motion-dom.dev.js +157 -62
- package/dist/motion-dom.js +1 -1
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -2478,9 +2478,7 @@ const acceleratedValues = new Set([
|
|
|
2478
2478
|
"clipPath",
|
|
2479
2479
|
"filter",
|
|
2480
2480
|
"transform",
|
|
2481
|
-
|
|
2482
|
-
// or until we implement support for linear() easing.
|
|
2483
|
-
// "background-color"
|
|
2481
|
+
"backgroundColor",
|
|
2484
2482
|
]);
|
|
2485
2483
|
|
|
2486
2484
|
const browserColorFunctions = /^(?:oklch|oklab|lab|lch|color|color-mix|light-dark)\(/;
|
|
@@ -2511,12 +2509,14 @@ function supportsBrowserAnimation(options) {
|
|
|
2511
2509
|
const { motionValue, name, repeatDelay, repeatType, damping, type, keyframes, } = options;
|
|
2512
2510
|
const subject = motionValue?.owner?.current;
|
|
2513
2511
|
/**
|
|
2514
|
-
* We use
|
|
2515
|
-
* **don't** want elements in different timing
|
|
2516
|
-
* to be accelerated, as it's not possible to sync
|
|
2517
|
-
* properly with those driven from the main window
|
|
2512
|
+
* We use instanceof checks instead of isHTMLElement()/isSVGElement()
|
|
2513
|
+
* because we explicitly **don't** want elements in different timing
|
|
2514
|
+
* contexts (i.e. popups) to be accelerated, as it's not possible to sync
|
|
2515
|
+
* these animations properly with those driven from the main window
|
|
2516
|
+
* frameloop.
|
|
2518
2517
|
*/
|
|
2519
|
-
if (!(subject instanceof HTMLElement)
|
|
2518
|
+
if (!(subject instanceof HTMLElement) &&
|
|
2519
|
+
!(subject instanceof SVGElement)) {
|
|
2520
2520
|
return false;
|
|
2521
2521
|
}
|
|
2522
2522
|
const { onUpdate, transformTemplate } = motionValue.owner.getProps();
|
|
@@ -4214,6 +4214,19 @@ class DOMKeyframesResolver extends KeyframeResolver {
|
|
|
4214
4214
|
}
|
|
4215
4215
|
}
|
|
4216
4216
|
|
|
4217
|
+
/**
|
|
4218
|
+
* The four corner-radius longhands. Shared so the projection mixer, scale
|
|
4219
|
+
* corrector, WAAPI px-value set and view-transition crop pass don't each carry
|
|
4220
|
+
* their own copy. Order is irrelevant - every consumer mixes/corrects/animates
|
|
4221
|
+
* each corner independently.
|
|
4222
|
+
*/
|
|
4223
|
+
const cornerRadiusProps = [
|
|
4224
|
+
"borderTopLeftRadius",
|
|
4225
|
+
"borderTopRightRadius",
|
|
4226
|
+
"borderBottomRightRadius",
|
|
4227
|
+
"borderBottomLeftRadius",
|
|
4228
|
+
];
|
|
4229
|
+
|
|
4217
4230
|
const pxValues = new Set([
|
|
4218
4231
|
// Border props
|
|
4219
4232
|
"borderWidth",
|
|
@@ -4222,10 +4235,7 @@ const pxValues = new Set([
|
|
|
4222
4235
|
"borderBottomWidth",
|
|
4223
4236
|
"borderLeftWidth",
|
|
4224
4237
|
"borderRadius",
|
|
4225
|
-
|
|
4226
|
-
"borderTopRightRadius",
|
|
4227
|
-
"borderBottomRightRadius",
|
|
4228
|
-
"borderBottomLeftRadius",
|
|
4238
|
+
...cornerRadiusProps,
|
|
4229
4239
|
// Positioning props
|
|
4230
4240
|
"width",
|
|
4231
4241
|
"maxWidth",
|
|
@@ -5516,6 +5526,12 @@ function hasTarget(target, targets) {
|
|
|
5516
5526
|
}
|
|
5517
5527
|
|
|
5518
5528
|
const definitionNames = ["layout", "enter", "exit", "new", "old"];
|
|
5529
|
+
/**
|
|
5530
|
+
* Whether a computed border-radius is square (every component zero). Splitting
|
|
5531
|
+
* on whitespace handles two-value/elliptical radii like "0px 20px" - a leading
|
|
5532
|
+
* `parseFloat` alone would misread the non-zero vertical radius as square.
|
|
5533
|
+
*/
|
|
5534
|
+
const isSquareRadius = (radius) => radius.split(" ").every((value) => parseFloat(value) === 0);
|
|
5519
5535
|
/**
|
|
5520
5536
|
* The `ViewTransitionTarget` buckets driving each generated layer type, in
|
|
5521
5537
|
* priority order - the inverse of `chooseLayerType`. The new view is driven by
|
|
@@ -5702,16 +5718,48 @@ function startViewAnimation(builder) {
|
|
|
5702
5718
|
return transition;
|
|
5703
5719
|
};
|
|
5704
5720
|
/**
|
|
5705
|
-
*
|
|
5706
|
-
*
|
|
5721
|
+
* Resolve a layer's group (`layout`) timing to plain WAAPI values: native
|
|
5722
|
+
* ms `delay`/`duration` and a baked `ease`. The single source of group
|
|
5723
|
+
* timing, shared by the generated-group retiming and the crop corner-radius
|
|
5724
|
+
* pass so the rounded clip animates on exactly the box's timing. It returns
|
|
5725
|
+
* no generator `type` (the WAAPI-only `NativeAnimation` rejects a string
|
|
5726
|
+
* type) nor `repeat`/`times` (which the group's `updateTiming` ignores), so
|
|
5727
|
+
* none of them can leak into the radius animation and desync it.
|
|
5707
5728
|
*/
|
|
5708
|
-
const
|
|
5729
|
+
const resolveGroupTiming = (name) => {
|
|
5730
|
+
const [index, total] = staggerPosition(name, "group");
|
|
5731
|
+
const transition = resolveLayerTransition(layerTargets.get(name), "group", "layout", index === -1 ? 0 : index, total);
|
|
5732
|
+
transition.duration && (transition.duration = motionUtils.secondsToMilliseconds(transition.duration));
|
|
5733
|
+
const { delay = 0, duration, ease } = applyGeneratorOptions(transition);
|
|
5734
|
+
return { delay: motionUtils.secondsToMilliseconds(delay), duration, ease };
|
|
5735
|
+
};
|
|
5736
|
+
/**
|
|
5737
|
+
* Each layer's measured box + corner radii per snapshot. The box lets
|
|
5738
|
+
* `finalizeCrop` tell whether a morph's aspect ratio changed (the only case
|
|
5739
|
+
* worth cropping); the radii let a cropped morph's group clip animate each
|
|
5740
|
+
* corner from the old element's radius to the new element's, keeping it
|
|
5741
|
+
* rounded where `overflow: clip` would otherwise square the corners.
|
|
5742
|
+
*
|
|
5743
|
+
* We never flatten the source for capture (a snapshot is a paint of the live
|
|
5744
|
+
* DOM, so squaring an element just for its capture would flash one real
|
|
5745
|
+
* square frame). For an aspect-changing morph `object-fit: cover` crops each
|
|
5746
|
+
* snapshot's own baked corners off-screen mid-morph, so the animated clip is
|
|
5747
|
+
* the only visible corner; a near-same-aspect forced crop (`.crop(true)`)
|
|
5748
|
+
* can't hide the outgoing snapshot's silhouette, but the endpoints coincide.
|
|
5749
|
+
*/
|
|
5750
|
+
const cropMeasurements = new Map();
|
|
5709
5751
|
const measureLayers = (phase) => nameRegistry.forEach((name, element) => {
|
|
5710
|
-
const
|
|
5752
|
+
const el = element;
|
|
5753
|
+
const rect = el.getBoundingClientRect?.();
|
|
5711
5754
|
if (rect && rect.height) {
|
|
5712
|
-
const
|
|
5713
|
-
|
|
5714
|
-
|
|
5755
|
+
const style = getComputedStyle(el);
|
|
5756
|
+
const radii = {};
|
|
5757
|
+
for (const corner of cornerRadiusProps) {
|
|
5758
|
+
radii[corner] = style[corner];
|
|
5759
|
+
}
|
|
5760
|
+
const entry = cropMeasurements.get(name) ?? {};
|
|
5761
|
+
entry[phase] = { width: rect.width, height: rect.height, radii };
|
|
5762
|
+
cropMeasurements.set(name, entry);
|
|
5715
5763
|
}
|
|
5716
5764
|
});
|
|
5717
5765
|
/**
|
|
@@ -5741,7 +5789,7 @@ function startViewAnimation(builder) {
|
|
|
5741
5789
|
* never "changed".
|
|
5742
5790
|
*/
|
|
5743
5791
|
const aspectChanged = (name) => {
|
|
5744
|
-
const box =
|
|
5792
|
+
const box = cropMeasurements.get(name);
|
|
5745
5793
|
if (!box?.old || !box?.new || !box.old.height || !box.new.height) {
|
|
5746
5794
|
return false;
|
|
5747
5795
|
}
|
|
@@ -6034,36 +6082,85 @@ function startViewAnimation(builder) {
|
|
|
6034
6082
|
const isMorphCrossfade = (name.type === "old" || name.type === "new") &&
|
|
6035
6083
|
!!stagger?.old &&
|
|
6036
6084
|
!!stagger?.new;
|
|
6037
|
-
|
|
6038
|
-
|
|
6039
|
-
|
|
6040
|
-
|
|
6041
|
-
|
|
6042
|
-
|
|
6043
|
-
|
|
6044
|
-
|
|
6045
|
-
|
|
6046
|
-
|
|
6047
|
-
|
|
6048
|
-
|
|
6049
|
-
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6085
|
+
let timing;
|
|
6086
|
+
if (name.type.startsWith("group")) {
|
|
6087
|
+
// group + group-children follow the resolved group
|
|
6088
|
+
// timing - the single source shared with the crop
|
|
6089
|
+
// corner-radius pass below.
|
|
6090
|
+
const { delay, duration, ease } = resolveGroupTiming(name.layer);
|
|
6091
|
+
timing = {
|
|
6092
|
+
delay,
|
|
6093
|
+
duration,
|
|
6094
|
+
easing: mapEasingToNativeEasing(ease, duration),
|
|
6095
|
+
};
|
|
6096
|
+
}
|
|
6097
|
+
else {
|
|
6098
|
+
const timingType = isMorphCrossfade ? "group" : name.type;
|
|
6099
|
+
const [index, total] = staggerPosition(name.layer, timingType);
|
|
6100
|
+
const transitionName = timingType === "group" ? "layout" : "";
|
|
6101
|
+
let animationTransition = resolveLayerTransition(targetDefinition, timingType, transitionName, index === -1 ? 0 : index, total);
|
|
6102
|
+
/**
|
|
6103
|
+
* The crossfade should resolve at the spring's
|
|
6104
|
+
* *perceptual* (visual) duration - the geometry can keep
|
|
6105
|
+
* bouncing, but the opacity shouldn't drag through the
|
|
6106
|
+
* settle. So capture `visualDuration` before
|
|
6107
|
+
* `applyGeneratorOptions` replaces it with the full
|
|
6108
|
+
* overshoot duration, and use it for the fade.
|
|
6109
|
+
*/
|
|
6110
|
+
const visualDuration = animationTransition.visualDuration;
|
|
6111
|
+
animationTransition.duration && (animationTransition.duration = motionUtils.secondsToMilliseconds(animationTransition.duration));
|
|
6112
|
+
animationTransition =
|
|
6113
|
+
applyGeneratorOptions(animationTransition);
|
|
6114
|
+
timing = {
|
|
6115
|
+
delay: motionUtils.secondsToMilliseconds(animationTransition.delay ?? 0),
|
|
6116
|
+
duration: isMorphCrossfade && visualDuration !== undefined
|
|
6117
|
+
? motionUtils.secondsToMilliseconds(visualDuration)
|
|
6118
|
+
: animationTransition.duration,
|
|
6119
|
+
easing: isMorphCrossfade
|
|
6120
|
+
? "linear"
|
|
6121
|
+
: mapEasingToNativeEasing(animationTransition.ease, animationTransition.duration),
|
|
6122
|
+
};
|
|
6123
|
+
}
|
|
6124
|
+
effect.updateTiming(timing);
|
|
6065
6125
|
animations.push(new NativeAnimationWrapper(animation));
|
|
6066
6126
|
}
|
|
6127
|
+
/**
|
|
6128
|
+
* Round each cropped layer's clip. Its `::view-transition-group`
|
|
6129
|
+
* has `overflow: clip`, which would otherwise square the corners
|
|
6130
|
+
* mid-morph; animate each corner from the old element's radius to
|
|
6131
|
+
* the new element's so the crop stays rounded. Timed as the group
|
|
6132
|
+
* (`layout`) so the radius tracks the morphing box.
|
|
6133
|
+
*/
|
|
6134
|
+
cropMeasurements.forEach((entry, name) => {
|
|
6135
|
+
if (!croppedNames.has(name))
|
|
6136
|
+
return;
|
|
6137
|
+
// Reuse the group's resolved timing - native ms delay/
|
|
6138
|
+
// duration + a baked ease, with no generator `type` or
|
|
6139
|
+
// repeat/times to leak into (or throw inside) NativeAnimation.
|
|
6140
|
+
const { delay, duration, ease } = resolveGroupTiming(name);
|
|
6141
|
+
for (const corner of cornerRadiusProps) {
|
|
6142
|
+
// `||` (not `??`) so an empty measurement falls back to
|
|
6143
|
+
// the other snapshot rather than an invalid keyframe.
|
|
6144
|
+
const from = entry.old?.radii[corner] ||
|
|
6145
|
+
entry.new?.radii[corner] ||
|
|
6146
|
+
"0px";
|
|
6147
|
+
const to = entry.new?.radii[corner] ||
|
|
6148
|
+
entry.old?.radii[corner] ||
|
|
6149
|
+
"0px";
|
|
6150
|
+
// Nothing to round if the corner is square at both ends.
|
|
6151
|
+
if (isSquareRadius(from) && isSquareRadius(to))
|
|
6152
|
+
continue;
|
|
6153
|
+
animations.push(new NativeAnimation({
|
|
6154
|
+
element: document.documentElement,
|
|
6155
|
+
name: corner,
|
|
6156
|
+
pseudoElement: `::view-transition-group(${name})`,
|
|
6157
|
+
keyframes: [from, to],
|
|
6158
|
+
delay,
|
|
6159
|
+
duration,
|
|
6160
|
+
ease,
|
|
6161
|
+
}));
|
|
6162
|
+
}
|
|
6163
|
+
});
|
|
6067
6164
|
resolve(new GroupAnimation(animations));
|
|
6068
6165
|
})
|
|
6069
6166
|
.catch(() =>
|
|
@@ -7443,12 +7540,7 @@ const correctBoxShadow = {
|
|
|
7443
7540
|
const scaleCorrectors = {
|
|
7444
7541
|
borderRadius: {
|
|
7445
7542
|
...correctBorderRadius,
|
|
7446
|
-
applyTo: [
|
|
7447
|
-
"borderTopLeftRadius",
|
|
7448
|
-
"borderTopRightRadius",
|
|
7449
|
-
"borderBottomLeftRadius",
|
|
7450
|
-
"borderBottomRightRadius",
|
|
7451
|
-
],
|
|
7543
|
+
applyTo: [...cornerRadiusProps],
|
|
7452
7544
|
},
|
|
7453
7545
|
borderTopLeftRadius: correctBorderRadius,
|
|
7454
7546
|
borderTopRightRadius: correctBorderRadius,
|
|
@@ -7498,6 +7590,15 @@ class HTMLVisualElement extends DOMVisualElement {
|
|
|
7498
7590
|
this.type = "html";
|
|
7499
7591
|
this.renderInstance = renderHTML;
|
|
7500
7592
|
}
|
|
7593
|
+
mount(instance) {
|
|
7594
|
+
/**
|
|
7595
|
+
* If a custom component forwards its ref to something other than a
|
|
7596
|
+
* HTML/SVG element (a class instance, an imperative handle) there's
|
|
7597
|
+
* nothing for Motion to style, measure or attach gestures to. #2777
|
|
7598
|
+
*/
|
|
7599
|
+
motionUtils.invariant(Boolean(instance.style), "motion.create() components must forward their ref to a HTML or SVG element", "custom-component-ref");
|
|
7600
|
+
super.mount(instance);
|
|
7601
|
+
}
|
|
7501
7602
|
readValueFromInstance(instance, key) {
|
|
7502
7603
|
if (transformProps.has(key)) {
|
|
7503
7604
|
return this.projection?.isProjecting
|
|
@@ -8376,13 +8477,7 @@ function buildProjectionTransform(delta, treeScale, latestTransform) {
|
|
|
8376
8477
|
return transform || "none";
|
|
8377
8478
|
}
|
|
8378
8479
|
|
|
8379
|
-
const
|
|
8380
|
-
"borderTopLeftRadius",
|
|
8381
|
-
"borderTopRightRadius",
|
|
8382
|
-
"borderBottomLeftRadius",
|
|
8383
|
-
"borderBottomRightRadius",
|
|
8384
|
-
];
|
|
8385
|
-
const numBorders = borderLabels.length;
|
|
8480
|
+
const numBorders = cornerRadiusProps.length;
|
|
8386
8481
|
const asNumber = (value) => typeof value === "string" ? parseFloat(value) : value;
|
|
8387
8482
|
const isPx = (value) => typeof value === "number" || px.test(value);
|
|
8388
8483
|
function mixValues(target, follow, lead, progress, shouldCrossfadeOpacity, isOnlyMember) {
|
|
@@ -8397,7 +8492,7 @@ function mixValues(target, follow, lead, progress, shouldCrossfadeOpacity, isOnl
|
|
|
8397
8492
|
* Mix border radius
|
|
8398
8493
|
*/
|
|
8399
8494
|
for (let i = 0; i < numBorders; i++) {
|
|
8400
|
-
const borderLabel =
|
|
8495
|
+
const borderLabel = cornerRadiusProps[i];
|
|
8401
8496
|
let followRadius = getRadius(follow, borderLabel);
|
|
8402
8497
|
let leadRadius = getRadius(lead, borderLabel);
|
|
8403
8498
|
if (followRadius === undefined && leadRadius === undefined)
|