motion-dom 12.42.0 → 12.42.2
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 +165 -54
- package/dist/cjs/index.js.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/utils/border-radius.mjs +15 -0
- package/dist/es/utils/border-radius.mjs.map +1 -0
- package/dist/es/view/start.mjs +149 -36
- package/dist/es/view/start.mjs.map +1 -1
- package/dist/motion-dom.dev.js +165 -54
- package/dist/motion-dom.js +1 -1
- package/package.json +2 -2
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { cornerRadiusProps } from '../../../utils/border-radius.mjs';
|
|
2
|
+
|
|
1
3
|
const pxValues = new Set([
|
|
2
4
|
// Border props
|
|
3
5
|
"borderWidth",
|
|
@@ -6,10 +8,7 @@ const pxValues = new Set([
|
|
|
6
8
|
"borderBottomWidth",
|
|
7
9
|
"borderLeftWidth",
|
|
8
10
|
"borderRadius",
|
|
9
|
-
|
|
10
|
-
"borderTopRightRadius",
|
|
11
|
-
"borderBottomRightRadius",
|
|
12
|
-
"borderBottomLeftRadius",
|
|
11
|
+
...cornerRadiusProps,
|
|
13
12
|
// Positioning props
|
|
14
13
|
"width",
|
|
15
14
|
"maxWidth",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"px-values.mjs","sources":["../../../../../src/animation/waapi/utils/px-values.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"px-values.mjs","sources":["../../../../../src/animation/waapi/utils/px-values.ts"],"sourcesContent":["import { cornerRadiusProps } from \"../../../utils/border-radius\"\n\nexport const pxValues = new Set([\n // Border props\n \"borderWidth\",\n \"borderTopWidth\",\n \"borderRightWidth\",\n \"borderBottomWidth\",\n \"borderLeftWidth\",\n \"borderRadius\",\n ...cornerRadiusProps,\n // Positioning props\n \"width\",\n \"maxWidth\",\n \"height\",\n \"maxHeight\",\n \"top\",\n \"right\",\n \"bottom\",\n \"left\",\n \"inset\",\n \"insetBlock\",\n \"insetBlockStart\",\n \"insetBlockEnd\",\n \"insetInline\",\n \"insetInlineStart\",\n \"insetInlineEnd\",\n // Spacing props\n \"padding\",\n \"paddingTop\",\n \"paddingRight\",\n \"paddingBottom\",\n \"paddingLeft\",\n \"paddingBlock\",\n \"paddingBlockStart\",\n \"paddingBlockEnd\",\n \"paddingInline\",\n \"paddingInlineStart\",\n \"paddingInlineEnd\",\n \"margin\",\n \"marginTop\",\n \"marginRight\",\n \"marginBottom\",\n \"marginLeft\",\n \"marginBlock\",\n \"marginBlockStart\",\n \"marginBlockEnd\",\n \"marginInline\",\n \"marginInlineStart\",\n \"marginInlineEnd\",\n // Typography\n \"fontSize\",\n // Misc\n \"backgroundPositionX\",\n \"backgroundPositionY\",\n])\n"],"names":[],"mappings":";;AAEO,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC;;IAE5B,aAAa;IACb,gBAAgB;IAChB,kBAAkB;IAClB,mBAAmB;IACnB,iBAAiB;IACjB,cAAc;AACd,IAAA,GAAG,iBAAiB;;IAEpB,OAAO;IACP,UAAU;IACV,QAAQ;IACR,WAAW;IACX,KAAK;IACL,OAAO;IACP,QAAQ;IACR,MAAM;IACN,OAAO;IACP,YAAY;IACZ,iBAAiB;IACjB,eAAe;IACf,aAAa;IACb,kBAAkB;IAClB,gBAAgB;;IAEhB,SAAS;IACT,YAAY;IACZ,cAAc;IACd,eAAe;IACf,aAAa;IACb,cAAc;IACd,mBAAmB;IACnB,iBAAiB;IACjB,eAAe;IACf,oBAAoB;IACpB,kBAAkB;IAClB,QAAQ;IACR,WAAW;IACX,aAAa;IACb,cAAc;IACd,YAAY;IACZ,aAAa;IACb,kBAAkB;IAClB,gBAAgB;IAChB,cAAc;IACd,mBAAmB;IACnB,iBAAiB;;IAEjB,UAAU;;IAEV,qBAAqB;IACrB,qBAAqB;AACxB,CAAA;;;;"}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import { mixNumber } from '../../utils/mix/number.mjs';
|
|
2
2
|
import { percent, px } from '../../value/types/numbers/units.mjs';
|
|
3
3
|
import { progress, circOut, noop } from 'motion-utils';
|
|
4
|
+
import { cornerRadiusProps } from '../../utils/border-radius.mjs';
|
|
4
5
|
|
|
5
|
-
const
|
|
6
|
-
"borderTopLeftRadius",
|
|
7
|
-
"borderTopRightRadius",
|
|
8
|
-
"borderBottomLeftRadius",
|
|
9
|
-
"borderBottomRightRadius",
|
|
10
|
-
];
|
|
11
|
-
const numBorders = borderLabels.length;
|
|
6
|
+
const numBorders = cornerRadiusProps.length;
|
|
12
7
|
const asNumber = (value) => typeof value === "string" ? parseFloat(value) : value;
|
|
13
8
|
const isPx = (value) => typeof value === "number" || px.test(value);
|
|
14
9
|
function mixValues(target, follow, lead, progress, shouldCrossfadeOpacity, isOnlyMember) {
|
|
@@ -23,7 +18,7 @@ function mixValues(target, follow, lead, progress, shouldCrossfadeOpacity, isOnl
|
|
|
23
18
|
* Mix border radius
|
|
24
19
|
*/
|
|
25
20
|
for (let i = 0; i < numBorders; i++) {
|
|
26
|
-
const borderLabel =
|
|
21
|
+
const borderLabel = cornerRadiusProps[i];
|
|
27
22
|
let followRadius = getRadius(follow, borderLabel);
|
|
28
23
|
let leadRadius = getRadius(lead, borderLabel);
|
|
29
24
|
if (followRadius === undefined && leadRadius === undefined)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mix-values.mjs","sources":["../../../../src/projection/animation/mix-values.ts"],"sourcesContent":["import { mixNumber } from \"../../utils/mix/number\"\nimport { percent, px } from \"../../value/types/numbers/units\"\nimport type { AnyResolvedKeyframe } from \"../../animation/types\"\nimport {\n progress as calcProgress,\n circOut,\n EasingFunction,\n noop,\n} from \"motion-utils\"\nimport type { ResolvedValues } from \"../../node/types\"\
|
|
1
|
+
{"version":3,"file":"mix-values.mjs","sources":["../../../../src/projection/animation/mix-values.ts"],"sourcesContent":["import { mixNumber } from \"../../utils/mix/number\"\nimport { percent, px } from \"../../value/types/numbers/units\"\nimport type { AnyResolvedKeyframe } from \"../../animation/types\"\nimport {\n progress as calcProgress,\n circOut,\n EasingFunction,\n noop,\n} from \"motion-utils\"\nimport type { ResolvedValues } from \"../../node/types\"\nimport { cornerRadiusProps } from \"../../utils/border-radius\"\n\nconst numBorders = cornerRadiusProps.length\n\nconst asNumber = (value: AnyResolvedKeyframe) =>\n typeof value === \"string\" ? parseFloat(value) : value\n\nconst isPx = (value: AnyResolvedKeyframe) =>\n typeof value === \"number\" || px.test(value)\n\nexport function mixValues(\n target: ResolvedValues,\n follow: ResolvedValues,\n lead: ResolvedValues,\n progress: number,\n shouldCrossfadeOpacity: boolean,\n isOnlyMember: boolean\n) {\n if (shouldCrossfadeOpacity) {\n target.opacity = mixNumber(\n 0,\n (lead.opacity as number) ?? 1,\n easeCrossfadeIn(progress)\n )\n target.opacityExit = mixNumber(\n (follow.opacity as number) ?? 1,\n 0,\n easeCrossfadeOut(progress)\n )\n } else if (isOnlyMember) {\n target.opacity = mixNumber(\n (follow.opacity as number) ?? 1,\n (lead.opacity as number) ?? 1,\n progress\n )\n }\n\n /**\n * Mix border radius\n */\n for (let i = 0; i < numBorders; i++) {\n const borderLabel = cornerRadiusProps[i]\n let followRadius = getRadius(follow, borderLabel)\n let leadRadius = getRadius(lead, borderLabel)\n\n if (followRadius === undefined && leadRadius === undefined) continue\n\n followRadius ||= 0\n leadRadius ||= 0\n\n const canMix =\n followRadius === 0 ||\n leadRadius === 0 ||\n isPx(followRadius) === isPx(leadRadius)\n\n if (canMix) {\n target[borderLabel] = Math.max(\n mixNumber(\n asNumber(followRadius),\n asNumber(leadRadius),\n progress\n ),\n 0\n )\n\n if (percent.test(leadRadius) || percent.test(followRadius)) {\n target[borderLabel] += \"%\"\n }\n } else {\n target[borderLabel] = leadRadius\n }\n }\n\n /**\n * Mix rotation\n */\n if (follow.rotate || lead.rotate) {\n target.rotate = mixNumber(\n (follow.rotate as number) || 0,\n (lead.rotate as number) || 0,\n progress\n )\n }\n}\n\nfunction getRadius(values: ResolvedValues, radiusName: string) {\n return values[radiusName] !== undefined\n ? values[radiusName]\n : values.borderRadius\n}\n\nconst easeCrossfadeIn = /*@__PURE__*/ compress(0, 0.5, circOut)\nconst easeCrossfadeOut = /*@__PURE__*/ compress(0.5, 0.95, noop)\n\nfunction compress(\n min: number,\n max: number,\n easing: EasingFunction\n): EasingFunction {\n return (p: number) => {\n // Could replace ifs with clamp\n if (p < min) return 0\n if (p > max) return 1\n return easing(calcProgress(min, max, p))\n }\n}\n"],"names":["calcProgress"],"mappings":"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"}
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import { isCSSVariableName } from '../../animation/utils/is-css-variable.mjs';
|
|
2
|
+
import { cornerRadiusProps } from '../../utils/border-radius.mjs';
|
|
2
3
|
import { correctBorderRadius } from './scale-border-radius.mjs';
|
|
3
4
|
import { correctBoxShadow } from './scale-box-shadow.mjs';
|
|
4
5
|
|
|
5
6
|
const scaleCorrectors = {
|
|
6
7
|
borderRadius: {
|
|
7
8
|
...correctBorderRadius,
|
|
8
|
-
applyTo: [
|
|
9
|
-
"borderTopLeftRadius",
|
|
10
|
-
"borderTopRightRadius",
|
|
11
|
-
"borderBottomLeftRadius",
|
|
12
|
-
"borderBottomRightRadius",
|
|
13
|
-
],
|
|
9
|
+
applyTo: [...cornerRadiusProps],
|
|
14
10
|
},
|
|
15
11
|
borderTopLeftRadius: correctBorderRadius,
|
|
16
12
|
borderTopRightRadius: correctBorderRadius,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scale-correction.mjs","sources":["../../../../src/projection/styles/scale-correction.ts"],"sourcesContent":["import { isCSSVariableName } from \"../../animation/utils/is-css-variable\"\nimport { correctBorderRadius } from \"./scale-border-radius\"\nimport { correctBoxShadow } from \"./scale-box-shadow\"\nimport type { ScaleCorrectorMap } from \"./types\"\n\nexport const scaleCorrectors: ScaleCorrectorMap = {\n borderRadius: {\n ...correctBorderRadius,\n applyTo: [
|
|
1
|
+
{"version":3,"file":"scale-correction.mjs","sources":["../../../../src/projection/styles/scale-correction.ts"],"sourcesContent":["import { isCSSVariableName } from \"../../animation/utils/is-css-variable\"\nimport { cornerRadiusProps } from \"../../utils/border-radius\"\nimport { correctBorderRadius } from \"./scale-border-radius\"\nimport { correctBoxShadow } from \"./scale-box-shadow\"\nimport type { ScaleCorrectorMap } from \"./types\"\n\nexport const scaleCorrectors: ScaleCorrectorMap = {\n borderRadius: {\n ...correctBorderRadius,\n applyTo: [...cornerRadiusProps],\n },\n borderTopLeftRadius: correctBorderRadius,\n borderTopRightRadius: correctBorderRadius,\n borderBottomLeftRadius: correctBorderRadius,\n borderBottomRightRadius: correctBorderRadius,\n boxShadow: correctBoxShadow,\n}\n\nexport function addScaleCorrector(correctors: ScaleCorrectorMap) {\n for (const key in correctors) {\n scaleCorrectors[key] = correctors[key]\n if (isCSSVariableName(key)) {\n scaleCorrectors[key].isCSSVariable = true\n }\n }\n}\n"],"names":[],"mappings":";;;;;AAMO,MAAM,eAAe,GAAsB;AAC9C,IAAA,YAAY,EAAE;AACV,QAAA,GAAG,mBAAmB;AACtB,QAAA,OAAO,EAAE,CAAC,GAAG,iBAAiB,CAAC;AAClC,KAAA;AACD,IAAA,mBAAmB,EAAE,mBAAmB;AACxC,IAAA,oBAAoB,EAAE,mBAAmB;AACzC,IAAA,sBAAsB,EAAE,mBAAmB;AAC3C,IAAA,uBAAuB,EAAE,mBAAmB;AAC5C,IAAA,SAAS,EAAE,gBAAgB;;AAGzB,SAAU,iBAAiB,CAAC,UAA6B,EAAA;AAC3D,IAAA,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE;QAC1B,eAAe,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC;AACtC,QAAA,IAAI,iBAAiB,CAAC,GAAG,CAAC,EAAE;AACxB,YAAA,eAAe,CAAC,GAAG,CAAC,CAAC,aAAa,GAAG,IAAI;QAC7C;IACJ;AACJ;;;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The four corner-radius longhands. Shared so the projection mixer, scale
|
|
3
|
+
* corrector, WAAPI px-value set and view-transition crop pass don't each carry
|
|
4
|
+
* their own copy. Order is irrelevant - every consumer mixes/corrects/animates
|
|
5
|
+
* each corner independently.
|
|
6
|
+
*/
|
|
7
|
+
const cornerRadiusProps = [
|
|
8
|
+
"borderTopLeftRadius",
|
|
9
|
+
"borderTopRightRadius",
|
|
10
|
+
"borderBottomRightRadius",
|
|
11
|
+
"borderBottomLeftRadius",
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
export { cornerRadiusProps };
|
|
15
|
+
//# sourceMappingURL=border-radius.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"border-radius.mjs","sources":["../../../src/utils/border-radius.ts"],"sourcesContent":["/**\n * The four corner-radius longhands. Shared so the projection mixer, scale\n * corrector, WAAPI px-value set and view-transition crop pass don't each carry\n * their own copy. Order is irrelevant - every consumer mixes/corrects/animates\n * each corner independently.\n */\nexport const cornerRadiusProps = [\n \"borderTopLeftRadius\",\n \"borderTopRightRadius\",\n \"borderBottomRightRadius\",\n \"borderBottomLeftRadius\",\n] as const\n"],"names":[],"mappings":"AAAA;;;;;AAKG;AACI,MAAM,iBAAiB,GAAG;IAC7B,qBAAqB;IACrB,sBAAsB;IACtB,yBAAyB;IACzB,wBAAwB;;;;;"}
|
package/dist/es/view/start.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { NativeAnimationWrapper } from '../animation/NativeAnimationWrapper.mjs'
|
|
|
5
5
|
import { getValueTransition } from '../animation/utils/get-value-transition.mjs';
|
|
6
6
|
import { mapEasingToNativeEasing } from '../animation/waapi/easing/map-easing.mjs';
|
|
7
7
|
import { applyGeneratorOptions } from '../animation/waapi/utils/apply-generator.mjs';
|
|
8
|
+
import { cornerRadiusProps } from '../utils/border-radius.mjs';
|
|
8
9
|
import { resolveElements } from '../utils/resolve-elements.mjs';
|
|
9
10
|
import { assignViewTransitionNames, releaseViewTransitionNames } from './utils/assign-names.mjs';
|
|
10
11
|
import { chooseLayerType } from './utils/choose-layer-type.mjs';
|
|
@@ -14,6 +15,12 @@ import { getViewAnimations } from './utils/get-view-animations.mjs';
|
|
|
14
15
|
import { hasTarget } from './utils/has-target.mjs';
|
|
15
16
|
|
|
16
17
|
const definitionNames = ["layout", "enter", "exit", "new", "old"];
|
|
18
|
+
/**
|
|
19
|
+
* Whether a computed border-radius is square (every component zero). Splitting
|
|
20
|
+
* on whitespace handles two-value/elliptical radii like "0px 20px" - a leading
|
|
21
|
+
* `parseFloat` alone would misread the non-zero vertical radius as square.
|
|
22
|
+
*/
|
|
23
|
+
const isSquareRadius = (radius) => radius.split(" ").every((value) => parseFloat(value) === 0);
|
|
17
24
|
/**
|
|
18
25
|
* The `ViewTransitionTarget` buckets driving each generated layer type, in
|
|
19
26
|
* priority order - the inverse of `chooseLayerType`. The new view is driven by
|
|
@@ -200,16 +207,48 @@ function startViewAnimation(builder) {
|
|
|
200
207
|
return transition;
|
|
201
208
|
};
|
|
202
209
|
/**
|
|
203
|
-
*
|
|
204
|
-
*
|
|
210
|
+
* Resolve a layer's group (`layout`) timing to plain WAAPI values: native
|
|
211
|
+
* ms `delay`/`duration` and a baked `ease`. The single source of group
|
|
212
|
+
* timing, shared by the generated-group retiming and the crop corner-radius
|
|
213
|
+
* pass so the rounded clip animates on exactly the box's timing. It returns
|
|
214
|
+
* no generator `type` (the WAAPI-only `NativeAnimation` rejects a string
|
|
215
|
+
* type) nor `repeat`/`times` (which the group's `updateTiming` ignores), so
|
|
216
|
+
* none of them can leak into the radius animation and desync it.
|
|
217
|
+
*/
|
|
218
|
+
const resolveGroupTiming = (name) => {
|
|
219
|
+
const [index, total] = staggerPosition(name, "group");
|
|
220
|
+
const transition = resolveLayerTransition(layerTargets.get(name), "group", "layout", index === -1 ? 0 : index, total);
|
|
221
|
+
transition.duration && (transition.duration = secondsToMilliseconds(transition.duration));
|
|
222
|
+
const { delay = 0, duration, ease } = applyGeneratorOptions(transition);
|
|
223
|
+
return { delay: secondsToMilliseconds(delay), duration, ease };
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* Each layer's measured box + corner radii per snapshot. The box lets
|
|
227
|
+
* `finalizeCrop` tell whether a morph's aspect ratio changed (the only case
|
|
228
|
+
* worth cropping); the radii let a cropped morph's group clip animate each
|
|
229
|
+
* corner from the old element's radius to the new element's, keeping it
|
|
230
|
+
* rounded where `overflow: clip` would otherwise square the corners.
|
|
231
|
+
*
|
|
232
|
+
* We never flatten the source for capture (a snapshot is a paint of the live
|
|
233
|
+
* DOM, so squaring an element just for its capture would flash one real
|
|
234
|
+
* square frame). For an aspect-changing morph `object-fit: cover` crops each
|
|
235
|
+
* snapshot's own baked corners off-screen mid-morph, so the animated clip is
|
|
236
|
+
* the only visible corner; a near-same-aspect forced crop (`.crop(true)`)
|
|
237
|
+
* can't hide the outgoing snapshot's silhouette, but the endpoints coincide.
|
|
205
238
|
*/
|
|
206
|
-
const
|
|
239
|
+
const cropMeasurements = new Map();
|
|
207
240
|
const measureLayers = (phase) => nameRegistry.forEach((name, element) => {
|
|
208
|
-
const
|
|
241
|
+
const el = element;
|
|
242
|
+
const rect = el.getBoundingClientRect?.();
|
|
209
243
|
if (rect && rect.height) {
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
|
|
244
|
+
const style = getComputedStyle(el);
|
|
245
|
+
const radii = {};
|
|
246
|
+
for (const corner of cornerRadiusProps) {
|
|
247
|
+
radii[corner] = style[corner];
|
|
248
|
+
}
|
|
249
|
+
const entry = cropMeasurements.get(name) ?? {};
|
|
250
|
+
entry[phase] = { width: rect.width, height: rect.height, radii };
|
|
251
|
+
cropMeasurements.set(name, entry);
|
|
213
252
|
}
|
|
214
253
|
});
|
|
215
254
|
/**
|
|
@@ -239,7 +278,7 @@ function startViewAnimation(builder) {
|
|
|
239
278
|
* never "changed".
|
|
240
279
|
*/
|
|
241
280
|
const aspectChanged = (name) => {
|
|
242
|
-
const box =
|
|
281
|
+
const box = cropMeasurements.get(name);
|
|
243
282
|
if (!box?.old || !box?.new || !box.old.height || !box.new.height) {
|
|
244
283
|
return false;
|
|
245
284
|
}
|
|
@@ -483,6 +522,31 @@ function startViewAnimation(builder) {
|
|
|
483
522
|
}
|
|
484
523
|
continue;
|
|
485
524
|
}
|
|
525
|
+
/**
|
|
526
|
+
* Drop the orphaned half of the default crossfade. The UA
|
|
527
|
+
* fades old out and new in as a *pair*; if the opposing half
|
|
528
|
+
* was explicitly overridden with something other than an
|
|
529
|
+
* opacity fade (a clip or transform reveal), this side's
|
|
530
|
+
* default opacity fade has no partner - left to run it would
|
|
531
|
+
* dissolve what should be a static backdrop (e.g.
|
|
532
|
+
* `.new({ clipPath })` should reveal over a still old view,
|
|
533
|
+
* not fade the old out around the growing clip). Cancel it -
|
|
534
|
+
* and its `plus-lighter` sibling on the same pseudo, which
|
|
535
|
+
* would otherwise flash bright where the two opaque layers
|
|
536
|
+
* overlap. A genuine crossfade (the opposing side also fading
|
|
537
|
+
* opacity) keeps both halves and is handled above.
|
|
538
|
+
*/
|
|
539
|
+
const opposite = name.type === "old"
|
|
540
|
+
? "new"
|
|
541
|
+
: name.type === "new"
|
|
542
|
+
? "old"
|
|
543
|
+
: undefined;
|
|
544
|
+
if (opposite &&
|
|
545
|
+
explicitlyAnimated.has(`${name.layer}:${opposite}`) &&
|
|
546
|
+
!opacityAnimated.has(`${name.layer}:${opposite}`)) {
|
|
547
|
+
animation.cancel();
|
|
548
|
+
continue;
|
|
549
|
+
}
|
|
486
550
|
/**
|
|
487
551
|
* Otherwise retime the browser-generated animation to
|
|
488
552
|
* Motion's timing. This auto-enables the layout (group)
|
|
@@ -507,36 +571,85 @@ function startViewAnimation(builder) {
|
|
|
507
571
|
const isMorphCrossfade = (name.type === "old" || name.type === "new") &&
|
|
508
572
|
!!stagger?.old &&
|
|
509
573
|
!!stagger?.new;
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
574
|
+
let timing;
|
|
575
|
+
if (name.type.startsWith("group")) {
|
|
576
|
+
// group + group-children follow the resolved group
|
|
577
|
+
// timing - the single source shared with the crop
|
|
578
|
+
// corner-radius pass below.
|
|
579
|
+
const { delay, duration, ease } = resolveGroupTiming(name.layer);
|
|
580
|
+
timing = {
|
|
581
|
+
delay,
|
|
582
|
+
duration,
|
|
583
|
+
easing: mapEasingToNativeEasing(ease, duration),
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
else {
|
|
587
|
+
const timingType = isMorphCrossfade ? "group" : name.type;
|
|
588
|
+
const [index, total] = staggerPosition(name.layer, timingType);
|
|
589
|
+
const transitionName = timingType === "group" ? "layout" : "";
|
|
590
|
+
let animationTransition = resolveLayerTransition(targetDefinition, timingType, transitionName, index === -1 ? 0 : index, total);
|
|
591
|
+
/**
|
|
592
|
+
* The crossfade should resolve at the spring's
|
|
593
|
+
* *perceptual* (visual) duration - the geometry can keep
|
|
594
|
+
* bouncing, but the opacity shouldn't drag through the
|
|
595
|
+
* settle. So capture `visualDuration` before
|
|
596
|
+
* `applyGeneratorOptions` replaces it with the full
|
|
597
|
+
* overshoot duration, and use it for the fade.
|
|
598
|
+
*/
|
|
599
|
+
const visualDuration = animationTransition.visualDuration;
|
|
600
|
+
animationTransition.duration && (animationTransition.duration = secondsToMilliseconds(animationTransition.duration));
|
|
601
|
+
animationTransition =
|
|
602
|
+
applyGeneratorOptions(animationTransition);
|
|
603
|
+
timing = {
|
|
604
|
+
delay: secondsToMilliseconds(animationTransition.delay ?? 0),
|
|
605
|
+
duration: isMorphCrossfade && visualDuration !== undefined
|
|
606
|
+
? secondsToMilliseconds(visualDuration)
|
|
607
|
+
: animationTransition.duration,
|
|
608
|
+
easing: isMorphCrossfade
|
|
609
|
+
? "linear"
|
|
610
|
+
: mapEasingToNativeEasing(animationTransition.ease, animationTransition.duration),
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
effect.updateTiming(timing);
|
|
538
614
|
animations.push(new NativeAnimationWrapper(animation));
|
|
539
615
|
}
|
|
616
|
+
/**
|
|
617
|
+
* Round each cropped layer's clip. Its `::view-transition-group`
|
|
618
|
+
* has `overflow: clip`, which would otherwise square the corners
|
|
619
|
+
* mid-morph; animate each corner from the old element's radius to
|
|
620
|
+
* the new element's so the crop stays rounded. Timed as the group
|
|
621
|
+
* (`layout`) so the radius tracks the morphing box.
|
|
622
|
+
*/
|
|
623
|
+
cropMeasurements.forEach((entry, name) => {
|
|
624
|
+
if (!croppedNames.has(name))
|
|
625
|
+
return;
|
|
626
|
+
// Reuse the group's resolved timing - native ms delay/
|
|
627
|
+
// duration + a baked ease, with no generator `type` or
|
|
628
|
+
// repeat/times to leak into (or throw inside) NativeAnimation.
|
|
629
|
+
const { delay, duration, ease } = resolveGroupTiming(name);
|
|
630
|
+
for (const corner of cornerRadiusProps) {
|
|
631
|
+
// `||` (not `??`) so an empty measurement falls back to
|
|
632
|
+
// the other snapshot rather than an invalid keyframe.
|
|
633
|
+
const from = entry.old?.radii[corner] ||
|
|
634
|
+
entry.new?.radii[corner] ||
|
|
635
|
+
"0px";
|
|
636
|
+
const to = entry.new?.radii[corner] ||
|
|
637
|
+
entry.old?.radii[corner] ||
|
|
638
|
+
"0px";
|
|
639
|
+
// Nothing to round if the corner is square at both ends.
|
|
640
|
+
if (isSquareRadius(from) && isSquareRadius(to))
|
|
641
|
+
continue;
|
|
642
|
+
animations.push(new NativeAnimation({
|
|
643
|
+
element: document.documentElement,
|
|
644
|
+
name: corner,
|
|
645
|
+
pseudoElement: `::view-transition-group(${name})`,
|
|
646
|
+
keyframes: [from, to],
|
|
647
|
+
delay,
|
|
648
|
+
duration,
|
|
649
|
+
ease,
|
|
650
|
+
}));
|
|
651
|
+
}
|
|
652
|
+
});
|
|
540
653
|
resolve(new GroupAnimation(animations));
|
|
541
654
|
})
|
|
542
655
|
.catch(() =>
|