UNPKG

@avolutions/canvas-painter

Version:

CanvasPainter.js is a simple yet powerful JavaScript library for drawing basic shapes (rectangles, circles, etc.) on HTML5 Canvas with ease. Perfect for creating 2D graphics in your web projects.

43 lines (42 loc) 1.69 kB
import { Point } from "./Point.js"; /** * A utility class for handling mouse-related events. */ export class Mouse { /** * Gets the position of the mouse relative to the element that triggered the event. * * @param event - The MouseEvent object that contains the mouse event data. * @returns A Point object representing the X and Y coordinates relative to the event target. */ static getOffsetPosition(event) { return new Point(event.offsetX, event.offsetY); } /** * Gets the position of the mouse relative to the viewport (visible area of the browser window). * * @param event - The MouseEvent object that contains the mouse event data. * @returns A Point object representing the X and Y coordinates relative to the viewport. */ static getClientPosition(event) { return new Point(event.clientX, event.clientY); } /** * Gets the position of the mouse relative to the entire document, including the scroll position. * * @param event - The MouseEvent object that contains the mouse event data. * @returns A Point object representing the X and Y coordinates relative to the document. */ static getPagePosition(event) { return new Point(event.pageX, event.pageY); } /** * Gets the position of the mouse relative to the entire screen (including monitor setup). * * @param event - The MouseEvent object that contains the mouse event data. * @returns A Point object representing the X and Y coordinates relative to the screen. */ static getScreenPosition(event) { return new Point(event.screenX, event.screenY); } }