@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.
47 lines (46 loc) • 1.86 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Mouse = void 0;
const Point_js_1 = require("./Point.js");
/**
* A utility class for handling mouse-related events.
*/
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_js_1.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_js_1.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_js_1.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_js_1.Point(event.screenX, event.screenY);
}
}
exports.Mouse = Mouse;