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 CHANGED
@@ -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
- "borderTopLeftRadius",
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
- * Each layer's box size per snapshot, so `finalizeCrop` can tell whether a
5706
- * morph's aspect ratio changed (the only case worth cropping).
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 cropBox = new Map();
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 rect = element.getBoundingClientRect?.();
5752
+ const el = element;
5753
+ const rect = el.getBoundingClientRect?.();
5711
5754
  if (rect && rect.height) {
5712
- const entry = cropBox.get(name) ?? {};
5713
- entry[phase] = { width: rect.width, height: rect.height };
5714
- cropBox.set(name, entry);
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 = cropBox.get(name);
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
  }
@@ -5985,6 +6033,31 @@ function startViewAnimation(builder) {
5985
6033
  }
5986
6034
  continue;
5987
6035
  }
6036
+ /**
6037
+ * Drop the orphaned half of the default crossfade. The UA
6038
+ * fades old out and new in as a *pair*; if the opposing half
6039
+ * was explicitly overridden with something other than an
6040
+ * opacity fade (a clip or transform reveal), this side's
6041
+ * default opacity fade has no partner - left to run it would
6042
+ * dissolve what should be a static backdrop (e.g.
6043
+ * `.new({ clipPath })` should reveal over a still old view,
6044
+ * not fade the old out around the growing clip). Cancel it -
6045
+ * and its `plus-lighter` sibling on the same pseudo, which
6046
+ * would otherwise flash bright where the two opaque layers
6047
+ * overlap. A genuine crossfade (the opposing side also fading
6048
+ * opacity) keeps both halves and is handled above.
6049
+ */
6050
+ const opposite = name.type === "old"
6051
+ ? "new"
6052
+ : name.type === "new"
6053
+ ? "old"
6054
+ : undefined;
6055
+ if (opposite &&
6056
+ explicitlyAnimated.has(`${name.layer}:${opposite}`) &&
6057
+ !opacityAnimated.has(`${name.layer}:${opposite}`)) {
6058
+ animation.cancel();
6059
+ continue;
6060
+ }
5988
6061
  /**
5989
6062
  * Otherwise retime the browser-generated animation to
5990
6063
  * Motion's timing. This auto-enables the layout (group)
@@ -6009,36 +6082,85 @@ function startViewAnimation(builder) {
6009
6082
  const isMorphCrossfade = (name.type === "old" || name.type === "new") &&
6010
6083
  !!stagger?.old &&
6011
6084
  !!stagger?.new;
6012
- const timingType = name.type.startsWith("group") || isMorphCrossfade
6013
- ? "group"
6014
- : name.type;
6015
- const [index, total] = staggerPosition(name.layer, timingType);
6016
- const transitionName = timingType === "group" ? "layout" : "";
6017
- let animationTransition = resolveLayerTransition(targetDefinition, timingType, transitionName, index === -1 ? 0 : index, total);
6018
- /**
6019
- * The crossfade should resolve at the spring's *perceptual*
6020
- * (visual) duration - the geometry can keep bouncing, but the
6021
- * opacity shouldn't drag through the settle. So capture
6022
- * `visualDuration` before `applyGeneratorOptions` replaces it
6023
- * with the full overshoot duration, and use it for the fade.
6024
- */
6025
- const visualDuration = animationTransition.visualDuration;
6026
- animationTransition.duration && (animationTransition.duration = motionUtils.secondsToMilliseconds(animationTransition.duration));
6027
- animationTransition =
6028
- applyGeneratorOptions(animationTransition);
6029
- const duration = isMorphCrossfade && visualDuration !== undefined
6030
- ? motionUtils.secondsToMilliseconds(visualDuration)
6031
- : animationTransition.duration;
6032
- const easing = isMorphCrossfade
6033
- ? "linear"
6034
- : mapEasingToNativeEasing(animationTransition.ease, animationTransition.duration);
6035
- effect.updateTiming({
6036
- delay: motionUtils.secondsToMilliseconds(animationTransition.delay ?? 0),
6037
- duration,
6038
- easing,
6039
- });
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);
6040
6125
  animations.push(new NativeAnimationWrapper(animation));
6041
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
+ });
6042
6164
  resolve(new GroupAnimation(animations));
6043
6165
  })
6044
6166
  .catch(() =>
@@ -7418,12 +7540,7 @@ const correctBoxShadow = {
7418
7540
  const scaleCorrectors = {
7419
7541
  borderRadius: {
7420
7542
  ...correctBorderRadius,
7421
- applyTo: [
7422
- "borderTopLeftRadius",
7423
- "borderTopRightRadius",
7424
- "borderBottomLeftRadius",
7425
- "borderBottomRightRadius",
7426
- ],
7543
+ applyTo: [...cornerRadiusProps],
7427
7544
  },
7428
7545
  borderTopLeftRadius: correctBorderRadius,
7429
7546
  borderTopRightRadius: correctBorderRadius,
@@ -8351,13 +8468,7 @@ function buildProjectionTransform(delta, treeScale, latestTransform) {
8351
8468
  return transform || "none";
8352
8469
  }
8353
8470
 
8354
- const borderLabels = [
8355
- "borderTopLeftRadius",
8356
- "borderTopRightRadius",
8357
- "borderBottomLeftRadius",
8358
- "borderBottomRightRadius",
8359
- ];
8360
- const numBorders = borderLabels.length;
8471
+ const numBorders = cornerRadiusProps.length;
8361
8472
  const asNumber = (value) => typeof value === "string" ? parseFloat(value) : value;
8362
8473
  const isPx = (value) => typeof value === "number" || px.test(value);
8363
8474
  function mixValues(target, follow, lead, progress, shouldCrossfadeOpacity, isOnlyMember) {
@@ -8372,7 +8483,7 @@ function mixValues(target, follow, lead, progress, shouldCrossfadeOpacity, isOnl
8372
8483
  * Mix border radius
8373
8484
  */
8374
8485
  for (let i = 0; i < numBorders; i++) {
8375
- const borderLabel = borderLabels[i];
8486
+ const borderLabel = cornerRadiusProps[i];
8376
8487
  let followRadius = getRadius(follow, borderLabel);
8377
8488
  let leadRadius = getRadius(lead, borderLabel);
8378
8489
  if (followRadius === undefined && leadRadius === undefined)