UNPKG

fabric

Version:

Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.

24 lines (23 loc) 1.12 kB
import { MOVING } from "../constants.mjs"; import { commonEventInfo, isLocked } from "./util.mjs"; import { fireEvent } from "./fireEvent.mjs"; //#region src/controls/drag.ts /** * Action handler * @private * @param {Event} eventData javascript event that is doing the transform * @param {Object} transform javascript object containing a series of information around the current transform * @param {number} x current mouse x position, canvas normalized * @param {number} y current mouse y position, canvas normalized * @return {Boolean} true if the translation occurred */ const dragHandler = (eventData, transform, x, y) => { const { target, offsetX, offsetY } = transform, newLeft = x - offsetX, newTop = y - offsetY, moveX = !isLocked(target, "lockMovementX") && target.left !== newLeft, moveY = !isLocked(target, "lockMovementY") && target.top !== newTop; moveX && target.set("left", newLeft); moveY && target.set("top", newTop); if (moveX || moveY) fireEvent(MOVING, commonEventInfo(eventData, transform, x, y)); return moveX || moveY; }; //#endregion export { dragHandler }; //# sourceMappingURL=drag.mjs.map