motion-dom 12.37.0 → 12.38.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/index.d.ts CHANGED
@@ -945,6 +945,19 @@ interface MotionNodeLayoutOptions {
945
945
  * Currently used for `position: sticky` elements in Framer.
946
946
  */
947
947
  layoutRoot?: boolean;
948
+ /**
949
+ * The anchor point for relative layout projection. This defines which
950
+ * point on the parent is used as the reference for the child's position.
951
+ *
952
+ * `{ x: 0, y: 0 }` (default) anchors to the top-left corner.
953
+ * `{ x: 0.5, y: 0.5 }` anchors to the center, useful for centered layouts
954
+ * (e.g., flexbox) to prevent drift during parent layout animations.
955
+ * `false` disables relative projection entirely.
956
+ */
957
+ layoutAnchor?: {
958
+ x: number;
959
+ y: number;
960
+ } | false;
948
961
  /**
949
962
  * Attached to a portal root to ensure we attach the child to the document root and don't
950
963
  * perform scale correction on it.
@@ -4128,10 +4141,10 @@ declare function calcLength(axis: Axis): number;
4128
4141
  declare function isNear(value: number, target: number, maxDistance: number): boolean;
4129
4142
  declare function calcAxisDelta(delta: AxisDelta, source: Axis, target: Axis, origin?: number): void;
4130
4143
  declare function calcBoxDelta(delta: Delta, source: Box, target: Box, origin?: ResolvedValues$1): void;
4131
- declare function calcRelativeAxis(target: Axis, relative: Axis, parent: Axis): void;
4132
- declare function calcRelativeBox(target: Box, relative: Box, parent: Box): void;
4133
- declare function calcRelativeAxisPosition(target: Axis, layout: Axis, parent: Axis): void;
4134
- declare function calcRelativePosition(target: Box, layout: Box, parent: Box): void;
4144
+ declare function calcRelativeAxis(target: Axis, relative: Axis, parent: Axis, anchor?: number): void;
4145
+ declare function calcRelativeBox(target: Box, relative: Box, parent: Box, anchor?: Point): void;
4146
+ declare function calcRelativeAxisPosition(target: Axis, layout: Axis, parent: Axis, anchor?: number): void;
4147
+ declare function calcRelativePosition(target: Box, layout: Box, parent: Box, anchor?: Point): void;
4135
4148
 
4136
4149
  /**
4137
4150
  * Remove a delta from a point. This is essentially the steps of applyPointDelta in reverse
@@ -4381,6 +4394,7 @@ interface ProjectionNodeOptions {
4381
4394
  transition?: Transition;
4382
4395
  initialPromotionConfig?: InitialPromotionConfig;
4383
4396
  layoutDependency?: unknown;
4397
+ layoutAnchor?: Point | false;
4384
4398
  }
4385
4399
  type ProjectionEventName = "layoutUpdate" | "projectionUpdate";
4386
4400
 
@@ -3555,13 +3555,16 @@
3555
3555
  };
3556
3556
  /**
3557
3557
  * If the value is already at the defined target, skip the animation.
3558
+ * We still re-assert the value via frame.update to take precedence
3559
+ * over any stale transitionEnd callbacks from previous animations.
3558
3560
  */
3559
3561
  const currentValue = value.get();
3560
3562
  if (currentValue !== undefined &&
3561
- !value.isAnimating &&
3563
+ !value.isAnimating() &&
3562
3564
  !Array.isArray(valueTarget) &&
3563
3565
  valueTarget === currentValue &&
3564
3566
  !valueTransition.velocity) {
3567
+ frame.update(() => value.set(valueTarget));
3565
3568
  continue;
3566
3569
  }
3567
3570
  /**
@@ -7392,21 +7395,27 @@
7392
7395
  calcAxisDelta(delta.x, source.x, target.x, origin ? origin.originX : undefined);
7393
7396
  calcAxisDelta(delta.y, source.y, target.y, origin ? origin.originY : undefined);
7394
7397
  }
7395
- function calcRelativeAxis(target, relative, parent) {
7396
- target.min = parent.min + relative.min;
7398
+ function calcRelativeAxis(target, relative, parent, anchor = 0) {
7399
+ const anchorPoint = anchor
7400
+ ? mixNumber$1(parent.min, parent.max, anchor)
7401
+ : parent.min;
7402
+ target.min = anchorPoint + relative.min;
7397
7403
  target.max = target.min + calcLength(relative);
7398
7404
  }
7399
- function calcRelativeBox(target, relative, parent) {
7400
- calcRelativeAxis(target.x, relative.x, parent.x);
7401
- calcRelativeAxis(target.y, relative.y, parent.y);
7405
+ function calcRelativeBox(target, relative, parent, anchor) {
7406
+ calcRelativeAxis(target.x, relative.x, parent.x, anchor?.x);
7407
+ calcRelativeAxis(target.y, relative.y, parent.y, anchor?.y);
7402
7408
  }
7403
- function calcRelativeAxisPosition(target, layout, parent) {
7404
- target.min = layout.min - parent.min;
7409
+ function calcRelativeAxisPosition(target, layout, parent, anchor = 0) {
7410
+ const anchorPoint = anchor
7411
+ ? mixNumber$1(parent.min, parent.max, anchor)
7412
+ : parent.min;
7413
+ target.min = layout.min - anchorPoint;
7405
7414
  target.max = target.min + calcLength(layout);
7406
7415
  }
7407
- function calcRelativePosition(target, layout, parent) {
7408
- calcRelativeAxisPosition(target.x, layout.x, parent.x);
7409
- calcRelativeAxisPosition(target.y, layout.y, parent.y);
7416
+ function calcRelativePosition(target, layout, parent, anchor) {
7417
+ calcRelativeAxisPosition(target.x, layout.x, parent.x, anchor?.x);
7418
+ calcRelativeAxisPosition(target.y, layout.y, parent.y, anchor?.y);
7410
7419
  }
7411
7420
 
7412
7421
  /**
@@ -8186,8 +8195,18 @@
8186
8195
  // but should still clean up the measurements so that the next
8187
8196
  // snapshot could be taken correctly.
8188
8197
  if (updateWasBlocked) {
8198
+ const wasBlockedByResize = this.updateBlockedByResize;
8189
8199
  this.unblockUpdate();
8200
+ this.updateBlockedByResize = false;
8190
8201
  this.clearAllSnapshots();
8202
+ /**
8203
+ * When blocked by resize, still measure layouts so
8204
+ * callbacks like onLayoutMeasure fire (e.g. Reorder).
8205
+ * Skip notifyLayoutUpdate to prevent animations.
8206
+ */
8207
+ if (wasBlockedByResize) {
8208
+ this.nodes.forEach(forceLayoutMeasure);
8209
+ }
8191
8210
  this.nodes.forEach(clearMeasurements);
8192
8211
  return;
8193
8212
  }
@@ -8537,7 +8556,9 @@
8537
8556
  * even if no animation has started.
8538
8557
  */
8539
8558
  if (!this.targetDelta && !this.relativeTarget) {
8540
- if (relativeParent && relativeParent.layout) {
8559
+ if (this.options.layoutAnchor !== false &&
8560
+ relativeParent &&
8561
+ relativeParent.layout) {
8541
8562
  this.createRelativeTarget(relativeParent, this.layout.layoutBox, relativeParent.layout.layoutBox);
8542
8563
  }
8543
8564
  else {
@@ -8565,7 +8586,7 @@
8565
8586
  this.relativeParent &&
8566
8587
  this.relativeParent.target) {
8567
8588
  this.forceRelativeParentToResolveTarget();
8568
- calcRelativeBox(this.target, this.relativeTarget, this.relativeParent.target);
8589
+ calcRelativeBox(this.target, this.relativeTarget, this.relativeParent.target, this.options.layoutAnchor || undefined);
8569
8590
  /**
8570
8591
  * If we've only got a targetDelta, resolve it into a target
8571
8592
  */
@@ -8590,7 +8611,8 @@
8590
8611
  */
8591
8612
  if (this.attemptToResolveRelativeTarget) {
8592
8613
  this.attemptToResolveRelativeTarget = false;
8593
- if (relativeParent &&
8614
+ if (this.options.layoutAnchor !== false &&
8615
+ relativeParent &&
8594
8616
  Boolean(relativeParent.resumingFrom) ===
8595
8617
  Boolean(this.resumingFrom) &&
8596
8618
  !relativeParent.options.layoutScroll &&
@@ -8634,7 +8656,7 @@
8634
8656
  this.forceRelativeParentToResolveTarget();
8635
8657
  this.relativeTarget = createBox();
8636
8658
  this.relativeTargetOrigin = createBox();
8637
- calcRelativePosition(this.relativeTargetOrigin, layout, parentLayout);
8659
+ calcRelativePosition(this.relativeTargetOrigin, layout, parentLayout, this.options.layoutAnchor || undefined);
8638
8660
  copyBoxInto(this.relativeTarget, this.relativeTargetOrigin);
8639
8661
  }
8640
8662
  removeRelativeTarget() {
@@ -8806,7 +8828,7 @@
8806
8828
  this.layout &&
8807
8829
  this.relativeParent &&
8808
8830
  this.relativeParent.layout) {
8809
- calcRelativePosition(relativeLayout, this.layout.layoutBox, this.relativeParent.layout.layoutBox);
8831
+ calcRelativePosition(relativeLayout, this.layout.layoutBox, this.relativeParent.layout.layoutBox, this.options.layoutAnchor || undefined);
8810
8832
  mixBox(this.relativeTarget, this.relativeTargetOrigin, relativeLayout, progress);
8811
8833
  /**
8812
8834
  * If this is an unchanged relative target we can consider the
@@ -9225,10 +9247,11 @@
9225
9247
  if (relativeParent && !relativeParent.resumeFrom) {
9226
9248
  const { snapshot: parentSnapshot, layout: parentLayout } = relativeParent;
9227
9249
  if (parentSnapshot && parentLayout) {
9250
+ const anchor = node.options.layoutAnchor || undefined;
9228
9251
  const relativeSnapshot = createBox();
9229
- calcRelativePosition(relativeSnapshot, snapshot.layoutBox, parentSnapshot.layoutBox);
9252
+ calcRelativePosition(relativeSnapshot, snapshot.layoutBox, parentSnapshot.layoutBox, anchor);
9230
9253
  const relativeLayout = createBox();
9231
- calcRelativePosition(relativeLayout, layout, parentLayout.layoutBox);
9254
+ calcRelativePosition(relativeLayout, layout, parentLayout.layoutBox, anchor);
9232
9255
  if (!boxEqualsRounded(relativeSnapshot, relativeLayout)) {
9233
9256
  hasRelativeLayoutChanged = true;
9234
9257
  }
@@ -9300,6 +9323,10 @@
9300
9323
  function clearMeasurements(node) {
9301
9324
  node.clearMeasurements();
9302
9325
  }
9326
+ function forceLayoutMeasure(node) {
9327
+ node.isLayoutDirty = true;
9328
+ node.updateLayout();
9329
+ }
9303
9330
  function clearIsLayoutDirty(node) {
9304
9331
  node.isLayoutDirty = false;
9305
9332
  }