Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 13x 13x 50x 50x | import type { Anchor } from '../anchor';
const MIDDLE = 0.5;
const FACTORS: Readonly<Record<Anchor, readonly [x: number, y: number]>> = {
'top-left': [0, 0],
top: [MIDDLE, 0],
'top-right': [1, 0],
left: [0, MIDDLE],
center: [MIDDLE, MIDDLE],
right: [1, MIDDLE],
'bottom-left': [0, 1],
bottom: [MIDDLE, 1],
'bottom-right': [1, 1],
};
export function getAnchorPoint(box: DOMRectReadOnly, anchor: Anchor): DOMPoint {
const [factorX, factorY] = FACTORS[anchor];
return new DOMPoint(box.x + box.width * factorX, box.y + box.height * factorY);
}
|