The pointer's viewport X in the DOM (event.clientX).
The pointer's viewport Y in the DOM (event.clientY).
The canvas's bounding rect (getBoundingClientRect()).
The canvas's internal pixel width (= frame/viewport width).
The canvas's internal pixel height (= frame/viewport height).
Integer viewport coordinates, or null when mapping isn't possible.
Maps a display-space pointer position on the live canvas to the server browser's VIEWPORT pixel space.
The canvas's internal resolution (
canvasWidth/canvasHeight, set from each pushed frame) IS the viewport pixel space; the canvas is displayed scaled to its bounding rect. So a display point maps asvx = (clientX - rect.left) / rect.width * canvasWidth(and likewise for y), rounded to ints. Returnsnullfor a zero-size rect or un-sized canvas (divide-by-zero / not-ready guard).Pure + framework-free so it's unit-testable without a DOM.