{"version":3,"file":"changeWidth.min.mjs","sources":["../../../src/controls/changeWidth.ts"],"sourcesContent":["import type { TransformActionHandler } from '../EventTypeDefs';\nimport { CENTER, LEFT, RESIZING, RIGHT } from '../constants';\nimport { resolveOrigin } from '../util/misc/resolveOrigin';\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    resolveOrigin(transform.originX) === resolveOrigin(CENTER) ||\n    (resolveOrigin(transform.originX) === resolveOrigin(RIGHT) &&\n      localPoint.x < 0) ||\n    (resolveOrigin(transform.originX) === resolveOrigin(LEFT) &&\n      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","resolveOrigin","CENTER","RIGHT","LEFT","target","strokePadding","strokeWidth","strokeUniform","scaleX","multiplier","isTransformCentered","oldWidth","width","newWidth","Math","ceil","abs","set","max","changeWidth","wrapWithFireEvent","RESIZING","wrapWithFixedAnchor"],"mappings":"gWAgBO,MAAMA,EAA4CA,CACvDC,EACAC,EACAC,EACAC,KAEA,MAAMC,EAAaC,EACjBJ,EACAA,EAAUK,QACVL,EAAUM,QACVL,EACAC,GAGF,GACEK,EAAcP,EAAUK,WAAaE,EAAcC,IAClDD,EAAcP,EAAUK,WAAaE,EAAcE,IAClDN,EAAWF,EAAI,GAChBM,EAAcP,EAAUK,WAAaE,EAAcG,IAClDP,EAAWF,EAAI,EACjB,CACA,MAAMU,OAAEA,GAAWX,EACjBY,EACED,EAAOE,aAAeF,EAAOG,cAAgBH,EAAOI,OAAS,GAC/DC,EAAaC,EAAoBjB,GAAa,EAAI,EAClDkB,EAAWP,EAAOQ,MAClBC,EAAWC,KAAKC,KACdD,KAAKE,IAAKpB,EAAWF,EAAIe,EAAcL,EAAOI,QAAUH,GAI5D,OAFAD,EAAOa,IAAI,QAASH,KAAKI,IAAIL,EAAU,IAEhCF,IAAaP,EAAOQ,KAC7B,CACA,OAAO,CAAK,EAGDO,EAAcC,EACzBC,EACAC,EAAoB/B"}