@mocanvas/mocanvas · function
declare function placeNear(anchor: DOMRect, box: {
width: number;
height: number;
}, prefer: "above" | "below" | "side", width: number, height: number,Place box next to anchor, on the preferred side if it fits there and on
the other side if it does not, then clamp the result inside the viewport.
"above" and "below" centre the box on the anchor — what a menu hanging
off a button wants. "side" puts it beside the anchor and aligns their top
edges, which is what a *submenu* wants: opening downwards in the parent's
own column pushes the rest of the menu out of the way and grows towards the
bottom of the screen, where a long submenu runs out of room.
mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.