moderator-toolbox-nxg-for-reddit / util/ui/drawPosition

util/ui/drawPosition

Functions

clampIntoViewport()

clampIntoViewport(left, top, width, height, margin?): object

Defined in: extension/data/util/ui/drawPosition.ts:18

Clamps a page-coordinate top-left position so a popup of the given size stays fully on-screen against every edge, leaving a small margin. When the popup is larger than the viewport along an axis, it is pinned to the top/left edge rather than producing a negative (off-screen) clamp.

Works in page coordinates (i.e. includes window.scrollX/Y), matching the values written to a popup’s style.left/style.top.

Parameters

left

number

top

number

width

number

height

number

margin?

number = 5

Returns

object

left

left: number

top

top: number


drawPosition()

drawPosition(event, __namedParameters?): DrawPosition

Defined in: extension/data/util/ui/drawPosition.ts:46

Picks a viewport coordinate at which to anchor a popup for a given pointer event. Aims to sit near the cursor while clamping the result so the popup stays fully on-screen against every edge.

Supply popupWidth/popupHeight when known for exact clamping; otherwise conservative fallback dimensions are assumed.

Parameters

event

MouseEvent | PointerEvent

__namedParameters?
popupHeight?

number = 500

popupWidth?

number = 700

Returns

DrawPosition

Interfaces

DrawPosition

Defined in: extension/data/util/ui/drawPosition.ts:4

Pixel coordinates for positioning a popup relative to the viewport.

Properties

leftPosition

leftPosition: number

Defined in: extension/data/util/ui/drawPosition.ts:5

topPosition

topPosition: number

Defined in: extension/data/util/ui/drawPosition.ts:6