fabric
Version:
Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.
1 lines • 1.85 kB
Source Map (JSON)
{"version":3,"file":"wrapWithFixedAnchor.mjs","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"],"names":["wrapWithFixedAnchor","actionHandler","eventData","transform","x","y","target","originX","originY","constraint","getPositionByOrigin","actionPerformed","setPositionByOrigin"],"mappings":"AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,mBAAmBA,CACjCC,aAAwC,EACxC;EACA,OAAQ,CAACC,SAAS,EAAEC,SAAS,EAAEC,CAAC,EAAEC,CAAC,KAAK;IACtC,MAAM;QAAEC,MAAM;QAAEC,OAAO;AAAEC,QAAAA;AAAQ,OAAC,GAAGL,SAAS;MAC5CM,UAAU,GAAGH,MAAM,CAACI,mBAAmB,CAACH,OAAO,EAAEC,OAAO,CAAC;MACzDG,eAAe,GAAGV,aAAa,CAACC,SAAS,EAAEC,SAAS,EAAEC,CAAC,EAAEC,CAAC,CAAC;AAC7D;AACA;AACAC,IAAAA,MAAM,CAACM,mBAAmB,CACxBH,UAAU,EACVN,SAAS,CAACI,OAAO,EACjBJ,SAAS,CAACK,OACZ,CAAC;AACD,IAAA,OAAOG,eAAe;EACxB,CAAC;AACH;;;;"}