{"version":3,"file":"wrapWithFixedAnchor.min.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,EACd,EAAA,CAEA,OAAS,EAAW,EAAW,EAAG,IAAA,CAChC,GAAA,CAAM,OAAE,EAAA,QAAQ,EAAA,QAAS,GAAY,EACnC,EAAa,EAAO,oBAAoB,EAAS,EAAA,CACjD,EAAkB,EAAc,EAAW,EAAW,EAAG,EAAA,CAQ3D,OALA,EAAO,oBACL,EACA,EAAU,QACV,EAAU,QAAA,CAEL,GAAA,OAAA,KAAA"}