{"version":3,"file":"changeWidth.min.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":"+QAeO,MAAMA,EAA4CA,CACvDC,EACAC,EACAC,EACAC,KAEA,MAAMC,EAAaC,EACjBJ,EACAA,EAAUK,QACVL,EAAUM,QACVL,EACAC,GAGF,GACEF,EAAUK,UAAYE,GACrBP,EAAUK,UAAYG,GAASL,EAAWF,EAAI,GAC9CD,EAAUK,UAAYI,GAAQN,EAAWF,EAAI,EAC9C,CACA,MAAMS,OAAEA,GAAWV,EACjBW,EACED,EAAOE,aAAeF,EAAOG,cAAgBH,EAAOI,OAAS,GAC/DC,EAAaC,EAAoBhB,GAAa,EAAI,EAClDiB,EAAWP,EAAOQ,MAClBC,EAAWC,KAAKC,KACdD,KAAKE,IAAKnB,EAAWF,EAAIc,EAAcL,EAAOI,QAAUH,GAI5D,OAFAD,EAAOa,IAAI,QAASH,KAAKI,IAAIL,EAAU,IAEhCF,IAAaP,EAAOQ,KAC7B,CACA,OAAO,CAAK,EAGDO,EAAcC,EACzB,WACAC,EAAoB7B"}