UNPKG

fabric

Version:

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

1 lines 1.67 kB
{"version":3,"file":"drag.min.mjs","names":[],"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"],"mappings":"6JAcA,MAAa,GACX,EACA,EACA,EACA,IAAA,CAEA,GAAA,CAAM,OAAE,EAAA,QAAQ,EAAA,QAAS,GAAY,EACnC,EAAU,EAAI,EACd,EAAS,EAAI,EACb,EAAA,CAAS,EAAS,EAAQ,gBAAA,EAAoB,EAAO,OAAS,EAC9D,EAAA,CAAS,EAAS,EAAQ,gBAAA,EAAoB,EAAO,MAAQ,EAM/D,OALA,GAAS,EAAO,IAAA,OAAU,EAAA,CAC1B,GAAS,EAAO,IAAA,MAAS,EAAA,EACrB,GAAS,IACX,EAAU,EAAQ,EAAgB,EAAW,EAAW,EAAG,EAAA,CAAA,CAEtD,GAAS,GAAA,OAAA,KAAA"}