{"version":3,"file":"changeWidth.mjs","sources":["../../../src/controls/changeWidth.ts"],"sourcesContent":["import type { TransformActionHandler } from '../EventTypeDefs';\nimport { CENTER, LEFT, RIGHT } from '../constants';\nimport { getLocalPoint, isTransformCentered } from './util';\nimport { wrapWithFireEvent } from './wrapWithFireEvent';\nimport { wrapWithFixedAnchor } from './wrapWithFixedAnchor';\n\n/**\n * Action handler to change object's width\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 changeObjectWidth: TransformActionHandler = (\n  eventData,\n  transform,\n  x,\n  y\n) => {\n  const localPoint = getLocalPoint(\n    transform,\n    transform.originX,\n    transform.originY,\n    x,\n    y\n  );\n  //  make sure the control changes width ONLY from it's side of target\n  if (\n    transform.originX === CENTER ||\n    (transform.originX === RIGHT && localPoint.x < 0) ||\n    (transform.originX === LEFT && localPoint.x > 0)\n  ) {\n    const { target } = transform,\n      strokePadding =\n        target.strokeWidth / (target.strokeUniform ? target.scaleX : 1),\n      multiplier = isTransformCentered(transform) ? 2 : 1,\n      oldWidth = target.width,\n      newWidth = Math.ceil(\n        Math.abs((localPoint.x * multiplier) / target.scaleX) - strokePadding\n      );\n    target.set('width', Math.max(newWidth, 0));\n    //  check against actual target width in case `newWidth` was rejected\n    return oldWidth !== target.width;\n  }\n  return false;\n};\n\nexport const changeWidth = wrapWithFireEvent(\n  'resizing',\n  wrapWithFixedAnchor(changeObjectWidth)\n);\n"],"names":["changeObjectWidth","eventData","transform","x","y","localPoint","getLocalPoint","originX","originY","CENTER","RIGHT","LEFT","target","strokePadding","strokeWidth","strokeUniform","scaleX","multiplier","isTransformCentered","oldWidth","width","newWidth","Math","ceil","abs","set","max","changeWidth","wrapWithFireEvent","wrapWithFixedAnchor"],"mappings":";;;;;AAMA;AACA;AACA;A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