motion-dom 12.42.1 → 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.
@@ -4213,6 +4213,19 @@
4213
4213
  }
4214
4214
  }
4215
4215
 
4216
+ /**
4217
+ * The four corner-radius longhands. Shared so the projection mixer, scale
4218
+ * corrector, WAAPI px-value set and view-transition crop pass don't each carry
4219
+ * their own copy. Order is irrelevant - every consumer mixes/corrects/animates
4220
+ * each corner independently.
4221
+ */
4222
+ const cornerRadiusProps = [
4223
+ "borderTopLeftRadius",
4224
+ "borderTopRightRadius",
4225
+ "borderBottomRightRadius",
4226
+ "borderBottomLeftRadius",
4227
+ ];
4228
+
4216
4229
  const pxValues = new Set([
4217
4230
  // Border props
4218
4231
  "borderWidth",
@@ -4221,10 +4234,7 @@
4221
4234
  "borderBottomWidth",
4222
4235
  "borderLeftWidth",
4223
4236
  "borderRadius",
4224
- "borderTopLeftRadius",
4225
- "borderTopRightRadius",
4226
- "borderBottomRightRadius",
4227
- "borderBottomLeftRadius",
4237
+ ...cornerRadiusProps,
4228
4238
  // Positioning props
4229
4239
  "width",
4230
4240
  "maxWidth",
@@ -5515,6 +5525,12 @@
5515
5525
  }
5516
5526
 
5517
5527
  const definitionNames = ["layout", "enter", "exit", "new", "old"];
5528
+ /**
5529
+ * Whether a computed border-radius is square (every component zero). Splitting
5530
+ * on whitespace handles two-value/elliptical radii like "0px 20px" - a leading
5531
+ * `parseFloat` alone would misread the non-zero vertical radius as square.
5532
+ */
5533
+ const isSquareRadius = (radius) => radius.split(" ").every((value) => parseFloat(value) === 0);
5518
5534
  /**
5519
5535
  * The `ViewTransitionTarget` buckets driving each generated layer type, in
5520
5536
  * priority order - the inverse of `chooseLayerType`. The new view is driven by
@@ -5701,16 +5717,48 @@
5701
5717
  return transition;
5702
5718
  };
5703
5719
  /**
5704
- * Each layer's box size per snapshot, so `finalizeCrop` can tell whether a
5705
- * morph's aspect ratio changed (the only case worth cropping).
5720
+ * Resolve a layer's group (`layout`) timing to plain WAAPI values: native
5721
+ * ms `delay`/`duration` and a baked `ease`. The single source of group
5722
+ * timing, shared by the generated-group retiming and the crop corner-radius
5723
+ * pass so the rounded clip animates on exactly the box's timing. It returns
5724
+ * no generator `type` (the WAAPI-only `NativeAnimation` rejects a string
5725
+ * type) nor `repeat`/`times` (which the group's `updateTiming` ignores), so
5726
+ * none of them can leak into the radius animation and desync it.
5727
+ */
5728
+ const resolveGroupTiming = (name) => {
5729
+ const [index, total] = staggerPosition(name, "group");
5730
+ const transition = resolveLayerTransition(layerTargets.get(name), "group", "layout", index === -1 ? 0 : index, total);
5731
+ transition.duration && (transition.duration = motionUtils.secondsToMilliseconds(transition.duration));
5732
+ const { delay = 0, duration, ease } = applyGeneratorOptions(transition);
5733
+ return { delay: motionUtils.secondsToMilliseconds(delay), duration, ease };
5734
+ };
5735
+ /**
5736
+ * Each layer's measured box + corner radii per snapshot. The box lets
5737
+ * `finalizeCrop` tell whether a morph's aspect ratio changed (the only case
5738
+ * worth cropping); the radii let a cropped morph's group clip animate each
5739
+ * corner from the old element's radius to the new element's, keeping it
5740
+ * rounded where `overflow: clip` would otherwise square the corners.
5741
+ *
5742
+ * We never flatten the source for capture (a snapshot is a paint of the live
5743
+ * DOM, so squaring an element just for its capture would flash one real
5744
+ * square frame). For an aspect-changing morph `object-fit: cover` crops each
5745
+ * snapshot's own baked corners off-screen mid-morph, so the animated clip is
5746
+ * the only visible corner; a near-same-aspect forced crop (`.crop(true)`)
5747
+ * can't hide the outgoing snapshot's silhouette, but the endpoints coincide.
5706
5748
  */
5707
- const cropBox = new Map();
5749
+ const cropMeasurements = new Map();
5708
5750
  const measureLayers = (phase) => nameRegistry.forEach((name, element) => {
5709
- const rect = element.getBoundingClientRect?.();
5751
+ const el = element;
5752
+ const rect = el.getBoundingClientRect?.();
5710
5753
  if (rect && rect.height) {
5711
- const entry = cropBox.get(name) ?? {};
5712
- entry[phase] = { width: rect.width, height: rect.height };
5713
- cropBox.set(name, entry);
5754
+ const style = getComputedStyle(el);
5755
+ const radii = {};
5756
+ for (const corner of cornerRadiusProps) {
5757
+ radii[corner] = style[corner];
5758
+ }
5759
+ const entry = cropMeasurements.get(name) ?? {};
5760
+ entry[phase] = { width: rect.width, height: rect.height, radii };
5761
+ cropMeasurements.set(name, entry);
5714
5762
  }
5715
5763
  });
5716
5764
  /**
@@ -5740,7 +5788,7 @@
5740
5788
  * never "changed".
5741
5789
  */
5742
5790
  const aspectChanged = (name) => {
5743
- const box = cropBox.get(name);
5791
+ const box = cropMeasurements.get(name);
5744
5792
  if (!box?.old || !box?.new || !box.old.height || !box.new.height) {
5745
5793
  return false;
5746
5794
  }
@@ -6033,36 +6081,85 @@
6033
6081
  const isMorphCrossfade = (name.type === "old" || name.type === "new") &&
6034
6082
  !!stagger?.old &&
6035
6083
  !!stagger?.new;
6036
- const timingType = name.type.startsWith("group") || isMorphCrossfade
6037
- ? "group"
6038
- : name.type;
6039
- const [index, total] = staggerPosition(name.layer, timingType);
6040
- const transitionName = timingType === "group" ? "layout" : "";
6041
- let animationTransition = resolveLayerTransition(targetDefinition, timingType, transitionName, index === -1 ? 0 : index, total);
6042
- /**
6043
- * The crossfade should resolve at the spring's *perceptual*
6044
- * (visual) duration - the geometry can keep bouncing, but the
6045
- * opacity shouldn't drag through the settle. So capture
6046
- * `visualDuration` before `applyGeneratorOptions` replaces it
6047
- * with the full overshoot duration, and use it for the fade.
6048
- */
6049
- const visualDuration = animationTransition.visualDuration;
6050
- animationTransition.duration && (animationTransition.duration = motionUtils.secondsToMilliseconds(animationTransition.duration));
6051
- animationTransition =
6052
- applyGeneratorOptions(animationTransition);
6053
- const duration = isMorphCrossfade && visualDuration !== undefined
6054
- ? motionUtils.secondsToMilliseconds(visualDuration)
6055
- : animationTransition.duration;
6056
- const easing = isMorphCrossfade
6057
- ? "linear"
6058
- : mapEasingToNativeEasing(animationTransition.ease, animationTransition.duration);
6059
- effect.updateTiming({
6060
- delay: motionUtils.secondsToMilliseconds(animationTransition.delay ?? 0),
6061
- duration,
6062
- easing,
6063
- });
6084
+ let timing;
6085
+ if (name.type.startsWith("group")) {
6086
+ // group + group-children follow the resolved group
6087
+ // timing - the single source shared with the crop
6088
+ // corner-radius pass below.
6089
+ const { delay, duration, ease } = resolveGroupTiming(name.layer);
6090
+ timing = {
6091
+ delay,
6092
+ duration,
6093
+ easing: mapEasingToNativeEasing(ease, duration),
6094
+ };
6095
+ }
6096
+ else {
6097
+ const timingType = isMorphCrossfade ? "group" : name.type;
6098
+ const [index, total] = staggerPosition(name.layer, timingType);
6099
+ const transitionName = timingType === "group" ? "layout" : "";
6100
+ let animationTransition = resolveLayerTransition(targetDefinition, timingType, transitionName, index === -1 ? 0 : index, total);
6101
+ /**
6102
+ * The crossfade should resolve at the spring's
6103
+ * *perceptual* (visual) duration - the geometry can keep
6104
+ * bouncing, but the opacity shouldn't drag through the
6105
+ * settle. So capture `visualDuration` before
6106
+ * `applyGeneratorOptions` replaces it with the full
6107
+ * overshoot duration, and use it for the fade.
6108
+ */
6109
+ const visualDuration = animationTransition.visualDuration;
6110
+ animationTransition.duration && (animationTransition.duration = motionUtils.secondsToMilliseconds(animationTransition.duration));
6111
+ animationTransition =
6112
+ applyGeneratorOptions(animationTransition);
6113
+ timing = {
6114
+ delay: motionUtils.secondsToMilliseconds(animationTransition.delay ?? 0),
6115
+ duration: isMorphCrossfade && visualDuration !== undefined
6116
+ ? motionUtils.secondsToMilliseconds(visualDuration)
6117
+ : animationTransition.duration,
6118
+ easing: isMorphCrossfade
6119
+ ? "linear"
6120
+ : mapEasingToNativeEasing(animationTransition.ease, animationTransition.duration),
6121
+ };
6122
+ }
6123
+ effect.updateTiming(timing);
6064
6124
  animations.push(new NativeAnimationWrapper(animation));
6065
6125
  }
6126
+ /**
6127
+ * Round each cropped layer's clip. Its `::view-transition-group`
6128
+ * has `overflow: clip`, which would otherwise square the corners
6129
+ * mid-morph; animate each corner from the old element's radius to
6130
+ * the new element's so the crop stays rounded. Timed as the group
6131
+ * (`layout`) so the radius tracks the morphing box.
6132
+ */
6133
+ cropMeasurements.forEach((entry, name) => {
6134
+ if (!croppedNames.has(name))
6135
+ return;
6136
+ // Reuse the group's resolved timing - native ms delay/
6137
+ // duration + a baked ease, with no generator `type` or
6138
+ // repeat/times to leak into (or throw inside) NativeAnimation.
6139
+ const { delay, duration, ease } = resolveGroupTiming(name);
6140
+ for (const corner of cornerRadiusProps) {
6141
+ // `||` (not `??`) so an empty measurement falls back to
6142
+ // the other snapshot rather than an invalid keyframe.
6143
+ const from = entry.old?.radii[corner] ||
6144
+ entry.new?.radii[corner] ||
6145
+ "0px";
6146
+ const to = entry.new?.radii[corner] ||
6147
+ entry.old?.radii[corner] ||
6148
+ "0px";
6149
+ // Nothing to round if the corner is square at both ends.
6150
+ if (isSquareRadius(from) && isSquareRadius(to))
6151
+ continue;
6152
+ animations.push(new NativeAnimation({
6153
+ element: document.documentElement,
6154
+ name: corner,
6155
+ pseudoElement: `::view-transition-group(${name})`,
6156
+ keyframes: [from, to],
6157
+ delay,
6158
+ duration,
6159
+ ease,
6160
+ }));
6161
+ }
6162
+ });
6066
6163
  resolve(new GroupAnimation(animations));
6067
6164
  })
6068
6165
  .catch(() =>
@@ -7442,12 +7539,7 @@
7442
7539
  const scaleCorrectors = {
7443
7540
  borderRadius: {
7444
7541
  ...correctBorderRadius,
7445
- applyTo: [
7446
- "borderTopLeftRadius",
7447
- "borderTopRightRadius",
7448
- "borderBottomLeftRadius",
7449
- "borderBottomRightRadius",
7450
- ],
7542
+ applyTo: [...cornerRadiusProps],
7451
7543
  },
7452
7544
  borderTopLeftRadius: correctBorderRadius,
7453
7545
  borderTopRightRadius: correctBorderRadius,
@@ -8375,13 +8467,7 @@
8375
8467
  return transform || "none";
8376
8468
  }
8377
8469
 
8378
- const borderLabels = [
8379
- "borderTopLeftRadius",
8380
- "borderTopRightRadius",
8381
- "borderBottomLeftRadius",
8382
- "borderBottomRightRadius",
8383
- ];
8384
- const numBorders = borderLabels.length;
8470
+ const numBorders = cornerRadiusProps.length;
8385
8471
  const asNumber = (value) => typeof value === "string" ? parseFloat(value) : value;
8386
8472
  const isPx = (value) => typeof value === "number" || px.test(value);
8387
8473
  function mixValues(target, follow, lead, progress, shouldCrossfadeOpacity, isOnlyMember) {
@@ -8396,7 +8482,7 @@
8396
8482
  * Mix border radius
8397
8483
  */
8398
8484
  for (let i = 0; i < numBorders; i++) {
8399
- const borderLabel = borderLabels[i];
8485
+ const borderLabel = cornerRadiusProps[i];
8400
8486
  let followRadius = getRadius(follow, borderLabel);
8401
8487
  let leadRadius = getRadius(lead, borderLabel);
8402
8488
  if (followRadius === undefined && leadRadius === undefined)