UNPKG

fabric

Version:

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

1 lines 1.86 kB
{"version":3,"file":"drag.min.mjs","sources":["../../../src/controls/drag.ts"],"sourcesContent":["import type { TransformActionHandler } from '../EventTypeDefs';\nimport { LEFT, TOP, MOVING } from '../constants';\nimport { fireEvent } from './fireEvent';\nimport { commonEventInfo, isLocked } from './util';\n\n/**\n * Action handler\n * @private\n * @param {Event} eventData javascript event that is doing the transform\n * @param {Object} transform javascript object containing a series of information around the current transform\n * @param {number} x current mouse x position, canvas normalized\n * @param {number} y current mouse y position, canvas normalized\n * @return {Boolean} true if the translation occurred\n */\nexport const dragHandler: TransformActionHandler = (\n eventData,\n transform,\n x,\n y,\n) => {\n const { target, offsetX, offsetY } = transform,\n newLeft = x - offsetX,\n newTop = y - offsetY,\n moveX = !isLocked(target, 'lockMovementX') && target.left !== newLeft,\n moveY = !isLocked(target, 'lockMovementY') && target.top !== newTop;\n moveX && target.set(LEFT, newLeft);\n moveY && target.set(TOP, newTop);\n if (moveX || moveY) {\n fireEvent(MOVING, commonEventInfo(eventData, transform, x, y));\n }\n return moveX || moveY;\n};\n"],"names":["dragHandler","eventData","transform","x","y","target","offsetX","offsetY","newLeft","newTop","moveX","isLocked","left","moveY","top","set","LEFT","TOP","fireEvent","MOVING","commonEventInfo"],"mappings":"gLAcO,MAAMA,EAAsCA,CACjDC,EACAC,EACAC,EACAC,KAEA,MAAMC,OAAEA,EAAMC,QAAEA,EAAOC,QAAEA,GAAYL,EACnCM,EAAUL,EAAIG,EACdG,EAASL,EAAIG,EACbG,GAASC,EAASN,EAAQ,kBAAoBA,EAAOO,OAASJ,EAC9DK,GAASF,EAASN,EAAQ,kBAAoBA,EAAOS,MAAQL,EAM/D,OALAC,GAASL,EAAOU,IAAIC,EAAMR,GAC1BK,GAASR,EAAOU,IAAIE,EAAKR,IACrBC,GAASG,IACXK,EAAUC,EAAQC,EAAgBnB,EAAWC,EAAWC,EAAGC,IAEtDM,GAASG"}