UNPKG

fabric

Version:

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

1 lines 4.33 kB
{"version":3,"file":"scaleSkew.min.mjs","names":[],"sources":["../../../src/controls/scaleSkew.ts"],"sourcesContent":["import type {\n ControlCallback,\n ControlCursorCallback,\n TPointerEvent,\n TransformActionHandler,\n} from '../EventTypeDefs';\nimport { SCALE_X, SCALE_Y, SKEW_X, SKEW_Y } from '../constants';\nimport type { FabricObject } from '../shapes/Object/FabricObject';\nimport type { TAxisKey } from '../typedefs';\nimport { scaleCursorStyleHandler, scalingX, scalingY } from './scale';\nimport { skewCursorStyleHandler, skewHandlerX, skewHandlerY } from './skew';\n\nfunction isAltAction(eventData: TPointerEvent, target: FabricObject) {\n return eventData[target.canvas!.altActionKey!];\n}\n\n/**\n * Inspect event, control and fabricObject to return the correct action name\n * @param {Event} eventData the javascript event that is causing the scale\n * @param {Control} control the control that is interested in the action\n * @param {FabricObject} fabricObject the fabric object that is interested in the action\n * @return {String} an action name\n */\nexport const scaleOrSkewActionName: ControlCallback<\n TAxisKey<'skew' | 'scale'> | ''\n> = (eventData, control, fabricObject) => {\n const isAlternative = isAltAction(eventData, fabricObject);\n if (control.x === 0) {\n // then is scaleY or skewX\n return isAlternative ? SKEW_X : SCALE_Y;\n }\n if (control.y === 0) {\n // then is scaleY or skewX\n return isAlternative ? SKEW_Y : SCALE_X;\n }\n return '';\n};\n\n/**\n * Combine skew and scale style handlers to cover fabric standard use case\n * @param {Event} eventData the javascript event that is causing the scale\n * @param {Control} control the control that is interested in the action\n * @param {FabricObject} fabricObject the fabric object that is interested in the action\n * @return {String} a valid css string for the cursor\n */\nexport const scaleSkewCursorStyleHandler: ControlCursorCallback = (\n eventData,\n control,\n fabricObject,\n coord,\n) => {\n return isAltAction(eventData, fabricObject)\n ? skewCursorStyleHandler(eventData, control, fabricObject, coord)\n : scaleCursorStyleHandler(eventData, control, fabricObject, coord);\n};\n/**\n * Composed action handler to either scale X or skew Y\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 some change happened\n */\nexport const scalingXOrSkewingY: TransformActionHandler = (\n eventData,\n transform,\n x,\n y,\n) => {\n return isAltAction(eventData, transform.target)\n ? skewHandlerY(eventData, transform, x, y)\n : scalingX(eventData, transform, x, y);\n};\n\n/**\n * Composed action handler to either scale Y or skew X\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 some change happened\n */\nexport const scalingYOrSkewingX: TransformActionHandler = (\n eventData,\n transform,\n x,\n y,\n) => {\n return isAltAction(eventData, transform.target)\n ? skewHandlerX(eventData, transform, x, y)\n : scalingY(eventData, transform, x, y);\n};\n"],"mappings":"sQAYA,SAAS,EAAY,EAA0B,EAAA,CAC7C,OAAO,EAAU,EAAO,OAAQ,cAUlC,MAAa,GAER,EAAW,EAAS,IAAA,CACvB,IAAM,EAAgB,EAAY,EAAW,EAAA,CAC7C,OAAI,EAAQ,IAAM,EAET,EAAgB,EAAS,EAE9B,EAAQ,IAAM,EAET,EAAgB,EAAS,EAE3B,IAUI,GACX,EACA,EACA,EACA,IAEO,EAAY,EAAW,EAAA,CAC1B,EAAuB,EAAW,EAAS,EAAc,EAAA,CACzD,EAAwB,EAAW,EAAS,EAAc,EAAA,CAWnD,GACX,EACA,EACA,EACA,IAEO,EAAY,EAAW,EAAU,OAAA,CACpC,EAAa,EAAW,EAAW,EAAG,EAAA,CACtC,EAAS,EAAW,EAAW,EAAG,EAAA,CAY3B,GACX,EACA,EACA,EACA,IAEO,EAAY,EAAW,EAAU,OAAA,CACpC,EAAa,EAAW,EAAW,EAAG,EAAA,CACtC,EAAS,EAAW,EAAW,EAAG,EAAA,CAAA,OAAA,KAAA,sBAAA,KAAA,4BAAA,KAAA,mBAAA,KAAA"}