{"version":3,"file":"X_Textbox.min.mjs","sources":["../../../../src/shapes/canvasx/X_Textbox.ts"],"sourcesContent":["import { TClassProperties } from '../../typedefs';\nimport { IText } from '../IText/IText';\nimport { classRegistry } from '../../ClassRegistry';\nimport { createTextboxDefaultControls } from '../../controls/X_commonControls';\nimport { EventName, TextAlign, WidgetType, Origin } from './types';\nimport { Textbox } from '../Textbox';\n\nimport { isTransformCentered, getLocalPoint } from '../../controls/util';\n// @TODO: Many things here are configuration related and shouldn't be on the class nor prototype\n// regexes, list of properties that are not suppose to change by instances, magic consts.\n// this will be a separated effort\nexport const textboxDefaultValues: Partial<TClassProperties<X_Textbox>> = {\n  minWidth: 20,\n  dynamicMinWidth: 2,\n  // _wordJoiners: /[ \\t\\r]/,\n  splitByGrapheme: true,\n  objType: 'X_Textbox',\n};\n\n/**\n * Textbox class, based on IText, allows the user to resize the text rectangle\n * and wraps lines automatically. Textboxes have their Y scaling locked, the\n * user can only change width. Height is adjusted automatically based on the\n * wrapping of lines.\n */\nexport class X_Textbox extends Textbox {\n  /**\n   * Minimum width of textbox, in pixels.\n   * @type Number\n   * @default\n   */\n  declare minWidth: number;\n\n  /* boardx cusotm function */\n  declare objType: string;\n\n  declare hasNoText: boolean;\n  /**\n   * Minimum calculated width of a textbox, in pixels.\n   * fixed to 2 so that an empty textbox cannot go to 0\n   * and is still selectable without text.\n   * @type Number\n   * @default\n   */\n  declare dynamicMinWidth: number;\n\n  declare oneLine: boolean;\n\n  declare fromCopy: boolean;\n  /**\n   * Use this boolean property in order to split strings that have no white space concept.\n   * this is a cheap way to help with chinese/japanese\n   * @type Boolean\n   * @since 2.6.0\n   */\n  declare splitByGrapheme: boolean;\n\n  static textLayoutProperties = [...IText.textLayoutProperties, 'width'];\n\n  static ownDefaults: Record<string, any> = textboxDefaultValues;\n\n  static getDefaults() {\n    return {\n      ...super.getDefaults(),\n      controls: createTextboxDefaultControls(),\n      ...X_Textbox.ownDefaults,\n    };\n  }\n  constructor(text: string, options: any) {\n    super(text, options);\n    // if (this.objType !== 'WBText' && this.objType !== 'WBTextbox') {\n    // this.addControls();\n    // }\n    this.InitializeEvent();\n    this.resetResizeControls();\n  }\n\n  // /**\n  //  * Unlike superclass's version of this function, Textbox does not update\n  //  * its width.\n  //  * @private\n  //  * @override\n  //  */\n  // initDimensions() {\n  //   if (!this.initialized) {\n  //     return;\n  //   }\n  //   this.isEditing && this.initDelayedCursor();\n  //   this._clearCache();\n  //   // clear dynamicMinWidth as it will be different after we re-wrap line\n  //   this.dynamicMinWidth = 0;\n  //   // wrap lines\n  //   this._styleMap = this._generateStyleMap(this._splitText());\n  //   // if after wrapping, the width is smaller than dynamicMinWidth, change the width and re-wrap\n  //   if (this.dynamicMinWidth > this.width) {\n  //     this._set('width', this.dynamicMinWidth);\n  //   }\n  //   if (this.textAlign.indexOf('justify') !== -1) {\n  //     // once text is measured we need to make space fatter to make justified text.\n  //     this.enlargeSpaces();\n  //   }\n  //   // clear cache and re-calculate height\n  //   this.height = this.calcTextHeight();\n  // }\n\n  /**\n   * Generate an object that translates the style object so that it is\n   * broken up by visual lines (new lines and automatic wrapping).\n   * The original text styles object is broken up by actual lines (new lines only),\n   * which is only sufficient for Text / IText\n   * @private\n   */\n  _generateStyleMap(textInfo: any) {\n    let realLineCount = 0,\n      realLineCharCount = 0,\n      charCount = 0;\n    const map: any = {};\n\n    for (let i = 0; i < textInfo.graphemeLines.length; i++) {\n      if (textInfo.graphemeText[charCount] === '\\n' && i > 0) {\n        realLineCharCount = 0;\n        charCount++;\n        realLineCount++;\n      } else if (\n        !this.splitByGrapheme &&\n        this._reSpaceAndTab.test(textInfo.graphemeText[charCount]) &&\n        i > 0\n      ) {\n        // this case deals with space's that are removed from end of lines when wrapping\n        realLineCharCount++;\n        charCount++;\n      }\n\n      map[i] = { line: realLineCount, offset: realLineCharCount };\n\n      charCount += textInfo.graphemeLines[i].length;\n      realLineCharCount += textInfo.graphemeLines[i].length;\n    }\n\n    return map;\n  }\n\n  /**\n   * Returns true if object has a style property or has it on a specified line\n   * @param {Number} lineIndex\n   * @return {Boolean}\n   */\n  styleHas(property: any, lineIndex: number): boolean {\n    if (this._styleMap && !this.isWrapping) {\n      const map = this._styleMap[lineIndex];\n      if (map) {\n        lineIndex = map.line;\n      }\n    }\n    return super.styleHas(property, lineIndex);\n  }\n\n  /**\n   * Returns true if object has no styling or no styling in a line\n   * @param {Number} lineIndex , lineIndex is on wrapped lines.\n   * @return {Boolean}\n   */\n  isEmptyStyles(lineIndex: number): boolean {\n    if (!this.styles) {\n      return true;\n    }\n    let offset: number = 0,\n      nextLineIndex = lineIndex + 1,\n      nextOffset: any,\n      shouldLimit = false;\n    const map = this._styleMap[lineIndex],\n      mapNextLine = this._styleMap[lineIndex + 1];\n    if (map) {\n      lineIndex = map.line;\n      offset = map.offset;\n    }\n    if (mapNextLine) {\n      nextLineIndex = mapNextLine.line;\n      shouldLimit = nextLineIndex === lineIndex;\n      nextOffset = mapNextLine.offset;\n    }\n    const obj =\n      typeof lineIndex === 'undefined'\n        ? this.styles\n        : { line: this.styles[lineIndex] };\n    for (const p1 in obj as any) {\n      for (const p2 in obj[p1] as any) {\n        if (Number(p2) >= offset && (!shouldLimit || Number(p2) < nextOffset)) {\n          // eslint-disable-next-line no-unused-vars\n          for (const p3 in obj[p1][p2]) {\n            return false;\n          }\n        }\n      }\n    }\n    return true;\n  }\n\n  // /**\n  //  * @param {Number} lineIndex\n  //  * @param {Number} charIndex\n  //  * @private\n  //  */\n  // _getStyleDeclaration(lineIndex: number, charIndex: number) {\n  //   if (this._styleMap && !this.isWrapping) {\n  //     const map = this._styleMap[lineIndex];\n  //     if (!map) {\n  //       return null;\n  //     }\n  //     lineIndex = map.line;\n  //     charIndex = map.offset + charIndex;\n  //   }\n  //   return super._getStyleDeclaration(lineIndex, charIndex);\n  // }\n\n  /**\n   * @param {Number} lineIndex\n   * @param {Number} charIndex\n   * @param {Object} style\n   * @private\n   */\n  _setStyleDeclaration(lineIndex: number, charIndex: number, style: object) {\n    const map = this._styleMap[lineIndex];\n    lineIndex = map.line;\n    charIndex = map.offset + charIndex;\n\n    this.styles[lineIndex][charIndex] = style;\n  }\n\n  /**\n   * @param {Number} lineIndex\n   * @param {Number} charIndex\n   * @private\n   */\n  _deleteStyleDeclaration(lineIndex: number, charIndex: number) {\n    const map = this._styleMap[lineIndex];\n    lineIndex = map.line;\n    charIndex = map.offset + charIndex;\n    delete this.styles[lineIndex][charIndex];\n  }\n\n  /**\n   * probably broken need a fix\n   * Returns the real style line that correspond to the wrapped lineIndex line\n   * Used just to verify if the line does exist or not.\n   * @param {Number} lineIndex\n   * @returns {Boolean} if the line exists or not\n   * @private\n   */\n  _getLineStyle(lineIndex: number): boolean {\n    const map = this._styleMap[lineIndex];\n    return !!this.styles[map.line];\n  }\n\n  /**\n   * Set the line style to an empty object so that is initialized\n   * @param {Number} lineIndex\n   * @param {Object} style\n   * @private\n   */\n  _setLineStyle(lineIndex: number) {\n    const map = this._styleMap[lineIndex];\n    this.styles[map.line] = {};\n  }\n\n  // /**\n  //  * Wraps text using the 'width' property of Textbox. First this function\n  //  * splits text on newlines, so we preserve newlines entered by the user.\n  //  * Then it wraps each line using the width of the Textbox by calling\n  //  * _wrapLine().\n  //  * @param {Array} lines The string array of text that is split into lines\n  //  * @param {Number} desiredWidth width you want to wrap to\n  //  * @returns {Array} Array of lines\n  //  */\n  // _wrapText(lines: Array<any>, desiredWidth: number): Array<any> {\n  //   const wrapped = [];\n  //   this.isWrapping = true;\n  //   for (let i = 0; i < lines.length; i++) {\n  //     wrapped.push(...this._wrapLine(lines[i], i, desiredWidth));\n  //   }\n  //   this.isWrapping = false;\n  //   return wrapped;\n  // }\n\n  /**\n   * Helper function to measure a string of text, given its lineIndex and charIndex offset\n   * It gets called when charBounds are not available yet.\n   * Override if necessary\n   * Use with {@link Textbox#wordSplit}\n   *\n   * @param {CanvasRenderingContext2D} ctx\n   * @param {String} text\n   * @param {number} lineIndex\n   * @param {number} charOffset\n   * @returns {number}\n   */\n  _measureWord(word: any, lineIndex: number, charOffset = 0): number {\n    let width = 0,\n      prevGrapheme;\n    const skipLeft = true;\n    for (let i = 0, len = word.length; i < len; i++) {\n      const box = this._getGraphemeBox(\n        word[i],\n        lineIndex,\n        i + charOffset,\n        prevGrapheme,\n        skipLeft\n      );\n      width += box.kernedWidth;\n      prevGrapheme = word[i];\n    }\n    return width;\n  }\n\n  /**\n   * Override this method to customize word splitting\n   * Use with {@link Textbox#_measureWord}\n   * @param {string} value\n   * @returns {string[]} array of words\n   */\n  wordSplit(value: string): string[] {\n    return value.split(this._wordJoiners);\n  }\n\n  /**\n   * Wraps a line of text using the width of the Textbox and a context.\n   * @param {Array} line The grapheme array that represent the line\n   * @param {Number} lineIndex\n   * @param {Number} desiredWidth width you want to wrap the line to\n   * @param {Number} reservedSpace space to remove from wrapping for custom functionalities\n   * @returns {Array} Array of line(s) into which the given text is wrapped\n   * to.\n   */\n  graphemeSplitForRectNotes(textstring: string): string[] {\n    const graphemes = [];\n    const words = textstring.split(/\\b/);\n    for (let i = 0; i < words.length; i++) {\n      // 检查单词是否全为拉丁字母，长度不大于16\n      if (/^[a-zA-Z]{1,16}$/.test(words[i])) {\n        graphemes.push(words[i]);\n      } else {\n        for (let j = 0; j < words[i].length; j++) {\n          graphemes.push(words[i][j]);\n        }\n      }\n    }\n    return graphemes;\n  }\n\n  // _wrapLine(\n  //   _line: any,\n  //   lineIndex: number,\n  //   desiredWidth: number,\n  //   reservedSpace = 0\n  // ): Array<any> {\n  //   const additionalSpace = this._getWidthOfCharSpacing(),\n  //     splitByGrapheme = this.splitByGrapheme,\n  //     graphemeLines = [],\n  //     words: any = splitByGrapheme\n  //       ? this.graphemeSplitForRectNotes(_line)\n  //       : this.wordSplit(_line),\n  //     infix = splitByGrapheme ? '' : ' ';\n\n  //   let lineWidth = 0,\n  //     line: any[] = [],\n  //     // spaces in different languages?\n  //     offset = 0,\n  //     infixWidth = 0,\n  //     largestWordWidth = 0,\n  //     lineJustStarted = true;\n  //   // fix a difference between split and graphemeSplit\n  //   if (words.length === 0) {\n  //     words.push([]);\n  //   }\n  //   desiredWidth -= reservedSpace;\n  //   // measure words\n  //   const data = words.map((word: any) => {\n  //     // if using splitByGrapheme words are already in graphemes.\n  //     word = splitByGrapheme ? word : this.graphemeSplitForRectNotes(word);\n  //     const width = this._measureWord(word, lineIndex, offset);\n  //     largestWordWidth = Math.max(width, largestWordWidth);\n  //     offset += word.length + 1;\n  //     return { word: word, width: width };\n  //   });\n  //   const maxWidth = Math.max(\n  //     desiredWidth,\n  //     largestWordWidth,\n  //     this.dynamicMinWidth\n  //   );\n  //   // layout words\n  //   offset = 0;\n  //   let i;\n  //   for (i = 0; i < words.length; i++) {\n  //     const word = data[i].word;\n  //     const wordWidth = data[i].width;\n  //     offset += word.length;\n\n  //     lineWidth += infixWidth + wordWidth - additionalSpace;\n  //     if (lineWidth > maxWidth && !lineJustStarted) {\n  //       graphemeLines.push(line);\n  //       line = [];\n  //       lineWidth = wordWidth;\n  //       lineJustStarted = true;\n  //     } else {\n  //       lineWidth += additionalSpace;\n  //     }\n\n  //     if (!lineJustStarted && !splitByGrapheme) {\n  //       line.push(infix);\n  //     }\n  //     if (word.length > 1) {\n  //       line = line.concat(word.split(''));\n  //     } else {\n  //       line = line.concat(word);\n  //     }\n\n  //     infixWidth = splitByGrapheme\n  //       ? 0\n  //       : this._measureWord([infix], lineIndex, offset);\n  //     offset++;\n  //     lineJustStarted = false;\n  //   }\n\n  //   i && graphemeLines.push(line);\n\n  //   if (largestWordWidth + reservedSpace > this.dynamicMinWidth) {\n  //     this.dynamicMinWidth = largestWordWidth - additionalSpace + reservedSpace;\n  //   }\n  //   return graphemeLines;\n  // }\n\n  /**\n   * Detect if the text line is ended with an hard break\n   * text and itext do not have wrapping, return false\n   * @param {Number} lineIndex text to split\n   * @return {Boolean}\n   */\n  isEndOfWrapping(lineIndex: number): boolean {\n    if (!this._styleMap[lineIndex + 1]) {\n      // is last line, return true;\n      return true;\n    }\n    if (this._styleMap[lineIndex + 1].line !== this._styleMap[lineIndex].line) {\n      // this is last line before a line break, return true;\n      return true;\n    }\n    return false;\n  }\n\n  /**\n   * Detect if a line has a linebreak and so we need to account for it when moving\n   * and counting style.\n   * @return Number\n   */\n  missingNewlineOffset(lineIndex: number) {\n    if (this.splitByGrapheme) {\n      return this.isEndOfWrapping(lineIndex) ? 1 : 0;\n    }\n    return 1;\n  }\n\n  /**\n   * Gets lines of text to render in the Textbox. This function calculates\n   * text wrapping on the fly every time it is called.\n   * @param {String} text text to split\n   * @returns {Array} Array of lines in the Textbox.\n   * @override\n   */\n  _splitTextIntoLines(text: string) {\n    const newText = super._splitTextIntoLines(text);\n    if (!this.fromCopy) {\n      if (\n        (this.objType === 'WBText' || this.objType === 'WBTextbox') &&\n        this.textLines &&\n        this.textLines.length > 1 &&\n        this.isEditing\n      ) {\n        this.oneLine = false;\n      } else {\n        this.oneLine = true;\n      }\n    } else {\n      this.oneLine = false;\n    }\n    if (\n      (this.objType === 'WBText' || this.objType === 'WBTextbox') &&\n      newText &&\n      newText.lines &&\n      this.oneLine &&\n      this.isEditing\n    ) {\n      if (newText.lines[0].length > 1) {\n        this.width =\n          this._measureWord(newText.lines[0], 0, 0) > this.width\n            ? this._measureWord(newText.lines[0], 0, 0) + 10\n            : this.width;\n      }\n    }\n    const graphemeLines = this._wrapText(newText.lines, this.width);\n    const lines = new Array(graphemeLines.length);\n    for (let i = 0; i < graphemeLines.length; i++) {\n      lines[i] = graphemeLines[i].join('');\n    }\n    newText.lines = lines;\n    newText.graphemeLines = graphemeLines;\n    return newText;\n  }\n\n  getMinWidth() {\n    return Math.max(this.minWidth, this.dynamicMinWidth);\n  }\n\n  // _removeExtraneousStyles() {\n  //   const linesToKeep = {};\n  //   for (const prop in this._styleMap) {\n  //     if (this._textLines[prop]) {\n  //       linesToKeep[this._styleMap[prop].line] = 1;\n  //     }\n  //   }\n  //   for (const prop in this.styles) {\n  //     if (!linesToKeep[prop]) {\n  //       delete this.styles[prop];\n  //     }\n  //   }\n  // }\n  // addControls() {\n  //   function renderCustomControl(ctx, left, top, fabricObject) {\n  //     const styleOverride1 = {\n  //       cornerSize: 10,\n  //       cornerStrokeColor: this.isHovering ? '#31A4F5' : '#b3cdfd',\n  //       cornerColor: this.isHovering ? '#31A4F5' : '#b3cdfd',\n  //       lineWidth: 2,\n  //     };\n  //     renderCircleControl.call(\n  //       fabricObject,\n  //       ctx,\n  //       left,\n  //       top,\n  //       styleOverride1,\n  //       fabricObject\n  //     );\n  //   }\n\n  //   this.controls.mtaStart = new Control({\n  //     x: 0,\n  //     y: -0.5,\n  //     offsetX: 0,\n  //     offsetY: -20,\n  //     render: renderCustomControl,\n  //     mouseDownHandler: (eventData, transformData) => {\n  //       this.controlMousedownProcess(transformData, 0.0, -0.5);\n  //       return true;\n  //     },\n  //     name: 'mtaStart',\n  //   });\n\n  //   this.controls.mbaStart = new Control({\n  //     x: 0,\n  //     y: 0.5,\n  //     offsetX: 0,\n  //     offsetY: 20,\n  //     render: renderCustomControl,\n  //     mouseDownHandler: (eventData, transformData) => {\n  //       this.controlMousedownProcess(transformData, 0.0, 0.5);\n  //       return true;\n  //     },\n  //     name: 'mbaStart',\n  //   });\n\n  //   this.controls.mlaStart = new Control({\n  //     x: -0.5,\n  //     y: 0,\n  //     offsetX: -20,\n  //     offsetY: 0,\n  //     render: renderCustomControl,\n  //     mouseDownHandler: (eventData, transformData) => {\n  //       this.controlMousedownProcess(transformData, -0.5, 0.0);\n  //       return true;\n  //     },\n  //     name: 'mlaStart',\n  //   });\n\n  //   this.controls.mraStart = new Control({\n  //     x: 0.5,\n  //     y: 0,\n  //     offsetX: 20,\n  //     offsetY: 0,\n  //     render: renderCustomControl,\n  //     mouseDownHandler: (eventData, transformData) => {\n  //       this.controlMousedownProcess(transformData, 0.5, 0.0);\n  //       return true;\n  //     },\n  //     name: 'mraStart',\n  //   });\n  // }\n\n  controlMousedownProcess(transformData: any, rx: any, ry: any) {\n    return;\n  }\n  /**\n   * Returns object representation of an instance\n   * @method toObject\n   * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output\n   * @return {Object} object representation of an instance\n   */\n\n  getObject() {\n    const object = {};\n\n    const keys = [\n      'id', // string, the id of the object\n      'angle', //  integer, angle for recording rotating\n      'backgroundColor', // string,  background color, works when the image is transparent\n      'fill', // the font color\n      'width', // integer, width of the object\n      'height', // integer, height of the object\n      'left', // integer left for position\n      'lines', // array, the arrows array [{…}]\n      'locked', // boolean, lock status for the widget， this is connected to lock\n      'lockMovementX', // boolean, lock the verticle movement\n      'lockMovementY', // boolean, lock the horizontal movement\n      'lockScalingFlip', // boolean,  make it can not be inverted by pulling the width to the negative side\n      'objType', // object type\n      'originX', // string, Horizontal origin of transformation of an object (one of \"left\", \"right\", \"center\") See http://jsfiddle.net/1ow02gea/244/ on how originX/originY affect objects in groups\n      'originY', // string, Vertical origin of transformation of an object (one of \"top\", \"bottom\", \"center\") See http://jsfiddle.net/1ow02gea/244/ on how originX/originY affect objects in groups\n      'scaleX', // nunber, Object scale factor (horizontal)\n      'scaleY', // number, Object scale factor (vertical)\n      'selectable', // boolean, When set to `false`, an object can not be selected for modification (using either point-click-based or group-based selection). But events still fire on it.\n      'top', // integer, Top position of an object. Note that by default it's relative to object top. You can change this by setting originY={top/center/bottom}\n      'userId', // string, user identity\n      'whiteboardId', // whiteboard id, string\n      'zIndex', // the index for the object on whiteboard, integer\n      'version', // version of the app, string\n      'isPanel', // is this a panel, boolean\n      'panelObj', // if this is a panel, the id of the panel, string\n      'relationship', // array, viewporttransform\n      'subObjList', // [\"5H9qYfNGt4vizhcuS\"] array list id for sub objects\n      'fontFamily', // string, font family\n      'fontSize', // integer, font size\n      'fontWeight', // integer, font weight\n      'lineHeight', // integer, font height\n      'text', // string, text\n      'textAlign', // string, alignment\n      'editable',\n      'shapeScaleX',\n      'shapeScaleY',\n      'maxHeight',\n      'tempTop',\n      'fixedScaleChange',\n      'preTop',\n    ];\n    keys.forEach((key) => {\n      //@ts-ignore\n      object[key] = this[key];\n    });\n    return object;\n  }\n\n  // toObject(propertiesToInclude: Array<any>): object {\n  //   return super.toObject(\n  //     ['minWidth', 'splitByGrapheme'].concat(propertiesToInclude)\n  //   );\n  // }\n  /**extend function for fronted */\n  checkTextboxChange() {}\n  InitializeEvent() {\n    const self = this;\n    const canvas = this.canvas;\n\n    self.on(EventName.EDITINGENTERED, () => {\n      // if it is in draw widget mode, then skip update\n      // if (canvas.drawTempWidget) return;\n\n      self.originX = self.textAlign;\n\n      if (self.textAlign === TextAlign.LEFT) {\n        self.left -= (self.width * self.scaleX) / 2;\n      }\n\n      if (self.textAlign === TextAlign.RIGHT) {\n        self.left += (self.width * self.scaleX) / 2;\n      }\n\n      if (self.objType === WidgetType.WBText) {\n        self.originY = 'top';\n\n        self.top -= (self.height * self.scaleY) / 2;\n\n        self.tempTop = self.top;\n\n        if (self.text === 'Type here...') {\n          self.selectAll();\n\n          self.text = '';\n\n          // self.hiddenTextarea.value = '';\n\n          self.dirty = true;\n\n          self.fill = 'rgb(0, 0, 0)';\n\n          canvas?.requestRenderAll();\n        }\n      }\n    });\n\n    self.on(EventName.EDITINGEXITED, () => {\n      // if it is in draw widget mode, then skip update\n      // if (canvas.drawTempWidget) return;\n\n      // if (self.text === '' && self.objType === WidgetType.WBText) {\n      //   canvas.removeWidget(self);\n\n      //   return;\n      // }\n\n      self.originX = Origin.Center;\n\n      self.originY = Origin.Center;\n\n      if (self.textAlign === Origin.Left) {\n        self.left += (self.width * self.scaleX) / 2;\n      }\n\n      if (self.textAlign === Origin.Right) {\n        self.left -= (self.width * self.scaleX) / 2;\n      }\n\n      if (self.objType === WidgetType.WBText) {\n        self.top = self.tempTop + (self.height * self.scaleY) / 2;\n        self.tempTop = self.top;\n      }\n    });\n\n    self.on(EventName.MODIFIED, () => {\n      self.checkTextboxChange();\n\n      // canvas.requestRenderAll();\n    });\n    self.on(EventName.CHANGED, () => {\n      if (self.styles[0]) {\n        self.styles = {};\n\n        // self.canvas.requestRenderAll();\n      }\n    });\n  }\n\n  changeWidth(eventData: any, transform: any, x: any, y: any) {\n    var target = transform.target,\n      localPoint = getLocalPoint(\n        transform,\n        transform.originX,\n        transform.originY,\n        x,\n        y\n      ),\n      strokePadding =\n        target.strokeWidth / (target.strokeUniform ? target.scaleX : 1),\n      multiplier = isTransformCentered(transform) ? 2 : 1,\n      oldWidth = target.width,\n      newWidth =\n        Math.abs((localPoint.x * multiplier) / target.scaleX) - strokePadding,\n      shapeScaleX =\n        Math.abs(target.aCoords['tl'].x - target.aCoords['tr'].x) / 138;\n    target.set('shapeScaleX', shapeScaleX);\n    target.set('width', Math.max(newWidth, 0));\n\n    target.initDimensions();\n\n    target.set('dirty', true);\n\n    if (target.objType === 'WBTextbox' || target.objType === 'WBText') {\n      target.set('fixedScaleChange', false);\n    }\n\n    if (target.objType !== 'WBText') {\n      target.saveData('MODIFIED', ['width']);\n    }\n\n    return oldWidth !== newWidth;\n  }\n\n  resetResizeControls() {\n    const self = this;\n    const textAlign = self.textAlign;\n\n    if (\n      self.objType === 'WBText' &&\n      (textAlign === 'left' || textAlign === 'center')\n    ) {\n      self.setControlVisible('ml', false);\n      self.setControlVisible('mr', true);\n    }\n\n    if (self.objType === 'WBText' && textAlign === 'right') {\n      self.setControlVisible('ml', true);\n      self.setControlVisible('mr', false);\n    }\n    if (self.canvas) self.canvas.requestRenderAll();\n  }\n}\n\nclassRegistry.setClass(Textbox);\n// classRegistry.getSVGClass(Textbox);\n"],"names":["textboxDefaultValues","minWidth","dynamicMinWidth","splitByGrapheme","objType","X_Textbox","Textbox","getDefaults","_objectSpread","super","controls","createTextboxDefaultControls","ownDefaults","constructor","text","options","this","InitializeEvent","resetResizeControls","_generateStyleMap","textInfo","realLineCount","realLineCharCount","charCount","map","i","graphemeLines","length","graphemeText","_reSpaceAndTab","test","line","offset","styleHas","property","lineIndex","_styleMap","isWrapping","isEmptyStyles","styles","nextOffset","nextLineIndex","shouldLimit","mapNextLine","obj","p1","p2","Number","p3","_setStyleDeclaration","charIndex","style","_deleteStyleDeclaration","_getLineStyle","_setLineStyle","_measureWord","word","prevGrapheme","charOffset","arguments","undefined","width","len","_getGraphemeBox","kernedWidth","wordSplit","value","split","_wordJoiners","graphemeSplitForRectNotes","textstring","graphemes","words","push","j","isEndOfWrapping","missingNewlineOffset","_splitTextIntoLines","newText","fromCopy","textLines","isEditing","oneLine","lines","_wrapText","Array","join","getMinWidth","Math","max","controlMousedownProcess","transformData","rx","ry","getObject","object","forEach","key","checkTextboxChange","self","canvas","on","EventName","EDITINGENTERED","originX","textAlign","TextAlign","LEFT","left","scaleX","RIGHT","WidgetType","WBText","originY","top","height","scaleY","tempTop","selectAll","dirty","fill","requestRenderAll","EDITINGEXITED","Origin","Center","Left","Right","MODIFIED","CHANGED","changeWidth","eventData","transform","x","y","target","localPoint","getLocalPoint","strokePadding","strokeWidth","strokeUniform","multiplier","isTransformCentered","oldWidth","newWidth","abs","shapeScaleX","aCoords","set","initDimensions","saveData","setControlVisible","_defineProperty","IText","textLayoutProperties","classRegistry","setClass"],"mappings":"mgBAWO,MAAMA,EAA6D,CACxEC,SAAU,GACVC,gBAAiB,EAEjBC,iBAAiB,EACjBC,QAAS,aASJ,MAAMC,UAAkBC,EAoC7B,kBAAOC,GACL,OAAAC,EAAAA,EAAA,CAAA,EACKC,MAAMF,eAAa,GAAA,CACtBG,SAAUC,KACPN,EAAUO,YAEjB,CACAC,WAAAA,CAAYC,EAAcC,GACxBN,MAAMK,EAAMC,GAIZC,KAAKC,kBACLD,KAAKE,qBACP,CAqCAC,iBAAAA,CAAkBC,GAChB,IAAIC,EAAgB,EAClBC,EAAoB,EACpBC,EAAY,EACd,MAAMC,EAAW,CAAA,EAEjB,IAAK,IAAIC,EAAI,EAAGA,EAAIL,EAASM,cAAcC,OAAQF,IACR,OAArCL,EAASQ,aAAaL,IAAuBE,EAAI,GACnDH,EAAoB,EACpBC,IACAF,MAECL,KAAKb,iBACNa,KAAKa,eAAeC,KAAKV,EAASQ,aAA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