Calculate anchor-relative position for an overlay element. Handles automatic flipping when the overlay would overflow the viewport.
Position calculation options
Computed position result
const result = calculateAnchorPosition({ anchor: { x: 10, y: 5, w: 20, h: 1 }, overlaySize: { w: 30, h: 10 }, position: "below-start", viewport: { x: 0, y: 0, width: 80, height: 24 },});// result.rect = { x: 10, y: 6, w: 30, h: 10 } Copy
const result = calculateAnchorPosition({ anchor: { x: 10, y: 5, w: 20, h: 1 }, overlaySize: { w: 30, h: 10 }, position: "below-start", viewport: { x: 0, y: 0, width: 80, height: 24 },});// result.rect = { x: 10, y: 6, w: 30, h: 10 }
Calculate anchor-relative position for an overlay element. Handles automatic flipping when the overlay would overflow the viewport.