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 | 5x 5x 5x | /**
* Calculate normalized mouse coordinates relative to the screen canvas.
*
* Uses clientX/clientY against the canvas bounding rect so that coordinates
* are correct even when the canvas is inset within a monitor image (e.g.
* display filters with non-zero canvasLeft/canvasTop).
*
* @param {MouseEvent} evt - The mouse event
* @param {DOMRect} screenRect - Bounding client rect of the screen canvas
* @returns {{x: number, y: number}} Normalized coordinates in [0, 1]
*/
export function calculateMouseCoordinates(evt, screenRect) {
const x = (evt.clientX - screenRect.left) / screenRect.width;
const y = (evt.clientY - screenRect.top) / screenRect.height;
return { x, y };
}
|