UNPKG

fabric

Version:

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

1 lines 1.42 kB
{"version":3,"file":"wrapWithFixedAnchor.mjs","names":[],"sources":["../../../src/controls/wrapWithFixedAnchor.ts"],"sourcesContent":["import type { Transform, TransformActionHandler } from '../EventTypeDefs';\n\n/**\n * Wrap an action handler with saving/restoring object position on the transform.\n * this is the code that permits to objects to keep their position while transforming.\n * @param {Function} actionHandler the function to wrap\n * @return {Function} a function with an action handler signature\n */\nexport function wrapWithFixedAnchor<T extends Transform>(\n actionHandler: TransformActionHandler<T>,\n) {\n return ((eventData, transform, x, y) => {\n const { target, originX, originY } = transform,\n constraint = target.getPositionByOrigin(originX, originY),\n actionPerformed = actionHandler(eventData, transform, x, y);\n // flipping requires to change the transform origin, so we read from the mutated transform\n // instead of leveraging the one destructured before\n target.setPositionByOrigin(\n constraint,\n transform.originX,\n transform.originY,\n );\n return actionPerformed;\n }) as TransformActionHandler<T>;\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,oBACd,eACA;AACA,UAAS,WAAW,WAAW,GAAG,MAAM;EACtC,MAAM,EAAE,QAAQ,SAAS,YAAY,WACnC,aAAa,OAAO,oBAAoB,SAAS,QAAQ,EACzD,kBAAkB,cAAc,WAAW,WAAW,GAAG,EAAE;AAG7D,SAAO,oBACL,YACA,UAAU,SACV,UAAU,QACX;AACD,SAAO"}