Skip to content

Commit 97dcc3e

Browse files
committed
fix: apply offset when pre-registered fallback has no paragraph context
1 parent 7b77d0d commit 97dcc3e

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

packages/layout-engine/contracts/src/graphic-placement.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ describe('resolveAnchoredGraphicY', () => {
5252
).toBe(92);
5353
});
5454

55+
it('ignores paragraph alignV when pre-registered fallback has no paragraph context', () => {
56+
expect(
57+
resolveAnchoredGraphicY({
58+
...base,
59+
anchor: { vRelativeFrom: 'paragraph', alignV: 'center', offsetV: 0 },
60+
preRegisteredFallbackToContentTop: true,
61+
}),
62+
).toBe(72);
63+
expect(
64+
resolveAnchoredGraphicY({
65+
...base,
66+
objectHeight: 50,
67+
anchor: { vRelativeFrom: 'paragraph', alignV: 'bottom', offsetV: 10 },
68+
preRegisteredFallbackToContentTop: true,
69+
}),
70+
).toBe(82);
71+
});
72+
5573
it('legacy undefined vRelativeFrom uses anchor paragraph Y', () => {
5674
expect(
5775
resolveAnchoredGraphicY({

packages/layout-engine/contracts/src/graphic-placement.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ export type ResolveAnchoredGraphicYInput = {
3333
/** First line height of the anchor paragraph (paragraph-relative alignV). */
3434
firstLineHeight?: number;
3535
/**
36-
* When true and vRelativeFrom is not margin/page, fall back to contentTop + offsetV
37-
* (page/margin pre-registered anchors that lack paragraph context).
36+
* When true, anchor has no host paragraph (pre-registered / paragraphless layout).
37+
* For `vRelativeFrom: 'paragraph'`, use `contentTop + offsetV` instead of alignV on a
38+
* synthetic paragraph (defaults would wrongly center/bottom against contentTop).
3839
*/
3940
preRegisteredFallbackToContentTop?: boolean;
4041
};
@@ -81,6 +82,9 @@ export function resolveAnchoredGraphicY(input: ResolveAnchoredGraphicYInput): nu
8182
}
8283

8384
if (vRelativeFrom === 'paragraph') {
85+
if (preRegisteredFallbackToContentTop) {
86+
return contentTop + offsetV;
87+
}
8488
const baseAnchorY = anchorParagraphY;
8589
if (alignV === 'bottom') {
8690
return baseAnchorY + firstLineHeight - objectHeight + offsetV;

0 commit comments

Comments
 (0)