fabric 6.4.1 → 6.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/index.js +123 -95
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.min.js +1 -1
  5. package/dist/index.min.js.map +1 -1
  6. package/dist/index.min.mjs +1 -1
  7. package/dist/index.min.mjs.map +1 -1
  8. package/dist/index.mjs +123 -95
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/index.node.cjs +123 -95
  11. package/dist/index.node.cjs.map +1 -1
  12. package/dist/index.node.mjs +123 -95
  13. package/dist/index.node.mjs.map +1 -1
  14. package/dist/package.json.min.mjs +1 -1
  15. package/dist/package.json.mjs +1 -1
  16. package/dist/src/canvas/DOMManagers/CanvasDOMManager.min.mjs +1 -1
  17. package/dist/src/canvas/DOMManagers/CanvasDOMManager.min.mjs.map +1 -1
  18. package/dist/src/canvas/DOMManagers/CanvasDOMManager.mjs +0 -1
  19. package/dist/src/canvas/DOMManagers/CanvasDOMManager.mjs.map +1 -1
  20. package/dist/src/canvas/SelectableCanvas.min.mjs +1 -1
  21. package/dist/src/canvas/SelectableCanvas.min.mjs.map +1 -1
  22. package/dist/src/canvas/SelectableCanvas.mjs +0 -1
  23. package/dist/src/canvas/SelectableCanvas.mjs.map +1 -1
  24. package/dist/src/config.d.ts +5 -1
  25. package/dist/src/config.d.ts.map +1 -1
  26. package/dist/src/config.min.mjs +1 -1
  27. package/dist/src/config.min.mjs.map +1 -1
  28. package/dist/src/config.mjs +6 -2
  29. package/dist/src/config.mjs.map +1 -1
  30. package/dist/src/parser/constants.d.ts +0 -1
  31. package/dist/src/parser/constants.d.ts.map +1 -1
  32. package/dist/src/parser/constants.min.mjs +1 -1
  33. package/dist/src/parser/constants.min.mjs.map +1 -1
  34. package/dist/src/parser/constants.mjs +1 -2
  35. package/dist/src/parser/constants.mjs.map +1 -1
  36. package/dist/src/shapes/Line.min.mjs +1 -1
  37. package/dist/src/shapes/Line.min.mjs.map +1 -1
  38. package/dist/src/shapes/Line.mjs +0 -1
  39. package/dist/src/shapes/Line.mjs.map +1 -1
  40. package/dist/src/shapes/Path.min.mjs +1 -1
  41. package/dist/src/shapes/Path.min.mjs.map +1 -1
  42. package/dist/src/shapes/Path.mjs +7 -1
  43. package/dist/src/shapes/Path.mjs.map +1 -1
  44. package/dist/src/shapes/Text/StyledText.min.mjs +1 -1
  45. package/dist/src/shapes/Text/StyledText.min.mjs.map +1 -1
  46. package/dist/src/shapes/Text/StyledText.mjs +0 -1
  47. package/dist/src/shapes/Text/StyledText.mjs.map +1 -1
  48. package/dist/src/util/misc/boundingBoxFromPoints.d.ts.map +1 -1
  49. package/dist/src/util/misc/boundingBoxFromPoints.min.mjs +1 -1
  50. package/dist/src/util/misc/boundingBoxFromPoints.min.mjs.map +1 -1
  51. package/dist/src/util/misc/boundingBoxFromPoints.mjs +17 -30
  52. package/dist/src/util/misc/boundingBoxFromPoints.mjs.map +1 -1
  53. package/dist/src/util/path/index.d.ts.map +1 -1
  54. package/dist/src/util/path/index.min.mjs +1 -1
  55. package/dist/src/util/path/index.min.mjs.map +1 -1
  56. package/dist/src/util/path/index.mjs +51 -47
  57. package/dist/src/util/path/index.mjs.map +1 -1
  58. package/dist/src/util/path/regex.d.ts +2 -1
  59. package/dist/src/util/path/regex.d.ts.map +1 -1
  60. package/dist/src/util/path/regex.min.mjs +1 -1
  61. package/dist/src/util/path/regex.min.mjs.map +1 -1
  62. package/dist/src/util/path/regex.mjs +41 -16
  63. package/dist/src/util/path/regex.mjs.map +1 -1
  64. package/dist/src/util/path/typedefs.d.ts +1 -0
  65. package/dist/src/util/path/typedefs.d.ts.map +1 -1
  66. package/dist-extensions/src/config.d.ts +5 -1
  67. package/dist-extensions/src/config.d.ts.map +1 -1
  68. package/dist-extensions/src/parser/constants.d.ts +0 -1
  69. package/dist-extensions/src/parser/constants.d.ts.map +1 -1
  70. package/dist-extensions/src/util/misc/boundingBoxFromPoints.d.ts.map +1 -1
  71. package/dist-extensions/src/util/path/index.d.ts.map +1 -1
  72. package/dist-extensions/src/util/path/regex.d.ts +2 -1
  73. package/dist-extensions/src/util/path/regex.d.ts.map +1 -1
  74. package/dist-extensions/src/util/path/typedefs.d.ts +1 -0
  75. package/dist-extensions/src/util/path/typedefs.d.ts.map +1 -1
  76. package/package.json +1 -1
  77. package/src/config.ts +6 -2
  78. package/src/parser/constants.ts +0 -2
  79. package/src/shapes/Path.ts +1 -1
  80. package/src/util/misc/boundingBoxFromPoints.ts +15 -24
  81. package/src/util/path/__snapshots__/index.spec.ts.snap +462 -0
  82. package/src/util/path/index.spec.ts +107 -1
  83. package/src/util/path/index.ts +56 -51
  84. package/src/util/path/regex.ts +29 -22
  85. package/src/util/path/typedefs.ts +22 -0
@@ -1 +1 @@
1
- {"version":3,"file":"StyledText.mjs","sources":["../../../../src/shapes/Text/StyledText.ts"],"sourcesContent":["import type { ObjectEvents } from '../../EventTypeDefs';\nimport type { FabricObjectProps, SerializedObjectProps } from '../Object/types';\nimport type { TOptions } from '../../typedefs';\nimport { FabricObject } from '../Object/FabricObject';\nimport { styleProperties } from './constants';\nimport type { StylePropertiesType } from './constants';\nimport type { FabricText } from './Text';\nimport { pick } from '../../util';\nimport { pickBy } from '../../util/misc/pick';\n\nexport type CompleteTextStyleDeclaration = Pick<\n FabricText,\n StylePropertiesType\n>;\n\nexport type TextStyleDeclaration = Partial<CompleteTextStyleDeclaration>;\n\nexport type TextStyle = {\n [line: number | string]: { [char: number | string]: TextStyleDeclaration };\n};\n\nexport abstract class StyledText<\n Props extends TOptions<FabricObjectProps> = Partial<FabricObjectProps>,\n SProps extends SerializedObjectProps = SerializedObjectProps,\n EventSpec extends ObjectEvents = ObjectEvents,\n> extends FabricObject<Props, SProps, EventSpec> {\n declare abstract styles: TextStyle;\n protected declare abstract _textLines: string[][];\n protected declare _forceClearCache: boolean;\n static _styleProperties: Readonly<StylePropertiesType[]> = styleProperties;\n abstract get2DCursorLocation(\n selectionStart: number,\n skipWrapping?: boolean,\n ): { charIndex: number; lineIndex: number };\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 if (typeof lineIndex !== 'undefined' && !this.styles[lineIndex]) {\n return true;\n }\n const obj =\n typeof lineIndex === 'undefined'\n ? this.styles\n : { line: this.styles[lineIndex] };\n for (const p1 in obj) {\n for (const p2 in obj[p1]) {\n // eslint-disable-next-line no-unused-vars\n for (const p3 in obj[p1][p2]) {\n return false;\n }\n }\n }\n return true;\n }\n\n /**\n * Returns true if object has a style property or has it ina specified line\n * This function is used to detect if a text will use a particular property or not.\n * @param {String} property to check for\n * @param {Number} lineIndex to check the style on\n * @return {Boolean}\n */\n styleHas(property: keyof TextStyleDeclaration, lineIndex?: number): boolean {\n if (!this.styles) {\n return false;\n }\n if (typeof lineIndex !== 'undefined' && !this.styles[lineIndex]) {\n return false;\n }\n const obj =\n typeof lineIndex === 'undefined'\n ? this.styles\n : { 0: this.styles[lineIndex] };\n // eslint-disable-next-line\n for (const p1 in obj) {\n // eslint-disable-next-line\n for (const p2 in obj[p1]) {\n if (typeof obj[p1][p2][property] !== 'undefined') {\n return true;\n }\n }\n }\n return false;\n }\n\n /**\n * Check if characters in a text have a value for a property\n * whose value matches the textbox's value for that property. If so,\n * the character-level property is deleted. If the character\n * has no other properties, then it is also deleted. Finally,\n * if the line containing that character has no other characters\n * then it also is deleted.\n *\n * @param {string} property The property to compare between characters and text.\n */\n cleanStyle(property: keyof TextStyleDeclaration) {\n if (!this.styles) {\n return false;\n }\n const obj = this.styles;\n let stylesCount = 0,\n letterCount,\n stylePropertyValue,\n allStyleObjectPropertiesMatch = true,\n graphemeCount = 0;\n for (const p1 in obj) {\n letterCount = 0;\n for (const p2 in obj[p1]) {\n const styleObject = obj[p1][p2] || {},\n stylePropertyHasBeenSet = styleObject[property] !== undefined;\n\n stylesCount++;\n\n if (stylePropertyHasBeenSet) {\n if (!stylePropertyValue) {\n stylePropertyValue = styleObject[property];\n } else if (styleObject[property] !== stylePropertyValue) {\n allStyleObjectPropertiesMatch = false;\n }\n\n if (styleObject[property] === this[property as keyof this]) {\n delete styleObject[property];\n }\n } else {\n allStyleObjectPropertiesMatch = false;\n }\n\n if (Object.keys(styleObject).length !== 0) {\n letterCount++;\n } else {\n delete obj[p1][p2];\n }\n }\n\n if (letterCount === 0) {\n delete obj[p1];\n }\n }\n // if every grapheme has the same style set then\n // delete those styles and set it on the parent\n for (let i = 0; i < this._textLines.length; i++) {\n graphemeCount += this._textLines[i].length;\n }\n if (allStyleObjectPropertiesMatch && stylesCount === graphemeCount) {\n // @ts-expect-error conspiracy theory of TS\n this[property as keyof this] = stylePropertyValue;\n this.removeStyle(property);\n }\n }\n\n /**\n * Remove a style property or properties from all individual character styles\n * in a text object. Deletes the character style object if it contains no other style\n * props. Deletes a line style object if it contains no other character styles.\n *\n * @param {String} props The property to remove from character styles.\n */\n removeStyle(property: keyof TextStyleDeclaration) {\n if (!this.styles) {\n return;\n }\n const obj = this.styles;\n let line, lineNum, charNum;\n for (lineNum in obj) {\n line = obj[lineNum];\n for (charNum in line) {\n delete line[charNum][property];\n if (Object.keys(line[charNum]).length === 0) {\n delete line[charNum];\n }\n }\n if (Object.keys(line).length === 0) {\n delete obj[lineNum];\n }\n }\n }\n\n private _extendStyles(index: number, style: TextStyleDeclaration): void {\n const { lineIndex, charIndex } = this.get2DCursorLocation(index);\n\n if (!this._getLineStyle(lineIndex)) {\n this._setLineStyle(lineIndex);\n }\n\n const newStyle = pickBy(\n {\n // first create a new object that is a merge of existing and new\n ...this._getStyleDeclaration(lineIndex, charIndex),\n ...style,\n // use the predicate to discard undefined values\n },\n (value) => value !== undefined,\n );\n\n // finally assign to the old position the new style\n this._setStyleDeclaration(lineIndex, charIndex, newStyle);\n }\n\n /**\n * Gets style of a current selection/cursor (at the start position)\n * @param {Number} startIndex Start index to get styles at\n * @param {Number} endIndex End index to get styles at, if not specified startIndex + 1\n * @param {Boolean} [complete] get full style or not\n * @return {Array} styles an array with one, zero or more Style objects\n */\n getSelectionStyles(\n startIndex: number,\n endIndex?: number,\n complete?: boolean,\n ): TextStyleDeclaration[] {\n const styles: TextStyleDeclaration[] = [];\n for (let i = startIndex; i < (endIndex || startIndex); i++) {\n styles.push(this.getStyleAtPosition(i, complete));\n }\n return styles;\n }\n\n /**\n * Gets style of a current selection/cursor position\n * @param {Number} position to get styles at\n * @param {Boolean} [complete] full style if true\n * @return {Object} style Style object at a specified index\n * @private\n */\n getStyleAtPosition(position: number, complete?: boolean) {\n const { lineIndex, charIndex } = this.get2DCursorLocation(position);\n return complete\n ? this.getCompleteStyleDeclaration(lineIndex, charIndex)\n : this._getStyleDeclaration(lineIndex, charIndex);\n }\n\n /**\n * Sets style of a current selection, if no selection exist, do not set anything.\n * @param {Object} styles Styles object\n * @param {Number} startIndex Start index to get styles at\n * @param {Number} [endIndex] End index to get styles at, if not specified startIndex + 1\n */\n setSelectionStyles(styles: object, startIndex: number, endIndex?: number) {\n for (let i = startIndex; i < (endIndex || startIndex); i++) {\n this._extendStyles(i, styles);\n }\n /* not included in _extendStyles to avoid clearing cache more than once */\n this._forceClearCache = true;\n }\n\n /**\n * Get a reference, not a clone, to the style object for a given character,\n * if no style is set for a line or char, return a new empty object.\n * This is tricky and confusing because when you get an empty object you can't\n * determine if it is a reference or a new one.\n * @TODO this should always return a reference or always a clone or undefined when necessary.\n * @protected\n * @param {Number} lineIndex\n * @param {Number} charIndex\n * @return {TextStyleDeclaration} a style object reference to the existing one or a new empty object when undefined\n */\n _getStyleDeclaration(\n lineIndex: number,\n charIndex: number,\n ): TextStyleDeclaration {\n const lineStyle = this.styles && this.styles[lineIndex];\n return lineStyle ? lineStyle[charIndex] ?? {} : {};\n }\n\n /**\n * return a new object that contains all the style property for a character\n * the object returned is newly created\n * @param {Number} lineIndex of the line where the character is\n * @param {Number} charIndex position of the character on the line\n * @return {Object} style object\n */\n getCompleteStyleDeclaration(\n lineIndex: number,\n charIndex: number,\n ): CompleteTextStyleDeclaration {\n return {\n // @ts-expect-error readonly\n ...pick(this, (this.constructor as typeof StyledText)._styleProperties),\n ...this._getStyleDeclaration(lineIndex, charIndex),\n } as CompleteTextStyleDeclaration;\n }\n\n /**\n * @param {Number} lineIndex\n * @param {Number} charIndex\n * @param {Object} style\n * @private\n */\n protected _setStyleDeclaration(\n lineIndex: number,\n charIndex: number,\n style: object,\n ) {\n this.styles[lineIndex][charIndex] = style;\n }\n\n /**\n *\n * @param {Number} lineIndex\n * @param {Number} charIndex\n * @private\n */\n protected _deleteStyleDeclaration(lineIndex: number, charIndex: number) {\n delete this.styles[lineIndex][charIndex];\n }\n\n /**\n * @param {Number} lineIndex\n * @return {Boolean} if the line exists or not\n * @private\n */\n protected _getLineStyle(lineIndex: number): boolean {\n return !!this.styles[lineIndex];\n }\n\n /**\n * Set the line style to an empty object so that is initialized\n * @param {Number} lineIndex\n * @private\n */\n protected _setLineStyle(lineIndex: number) {\n this.styles[lineIndex] = {};\n }\n\n protected _deleteLineStyle(lineIndex: number) {\n delete this.styles[lineIndex];\n }\n}\n"],"names":["StyledText","FabricObject","isEmptyStyles","lineIndex","styles","obj","line","p1","p2","p3","styleHas","property","cleanStyle","stylesCount","letterCount","stylePropertyValue","allStyleObjectPropertiesMatch","graphemeCount","styleObject","stylePropertyHasBeenSet","undefined","Object","keys","length","i","_textLines","removeStyle","lineNum","charNum","_extendStyles","index","style","charIndex","get2DCursorLocation","_getLineStyle","_setLineStyle","newStyle","pickBy","_objectSpread","_getStyleDeclaration","value","_setStyleDeclaration","getSelectionStyles","startIndex","endIndex","complete","push","getStyleAtPosition","position","getCompleteStyleDeclaration","setSelectionStyles","_forceClearCache","_lineStyle$charIndex","lineStyle","pick","constructor","_styleProperties","_deleteStyleDeclaration","_deleteLineStyle","_defineProperty","styleProperties"],"mappings":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iB,EAAE;AACzC,IAAA,IAAI,CAACC,MAAM,CAACD,SAAS,CAAC,GAAG,EAAE,CAAA;AAC7B,GAAA;EAEUuD,gBAAgBA,CAACvD,SAAiB,EAAE;AAC5C,IAAA,OAAO,IAAI,CAACC,MAAM,CAACD,SAAS,CAAC,CAAA;AAC/B,GAAA;AACF,CAAA;AAACwD,eAAA,CAzTqB3D,UAAU,EAAA,kBAAA,EAQ6B4D,eAAe,CAAA;;;;"}
1
+ {"version":3,"file":"StyledText.mjs","sources":["../../../../src/shapes/Text/StyledText.ts"],"sourcesContent":["import type { ObjectEvents } from '../../EventTypeDefs';\nimport type { FabricObjectProps, SerializedObjectProps } from '../Object/types';\nimport type { TOptions } from '../../typedefs';\nimport { FabricObject } from '../Object/FabricObject';\nimport { styleProperties } from './constants';\nimport type { StylePropertiesType } from './constants';\nimport type { FabricText } from './Text';\nimport { pick } from '../../util';\nimport { pickBy } from '../../util/misc/pick';\n\nexport type CompleteTextStyleDeclaration = Pick<\n FabricText,\n StylePropertiesType\n>;\n\nexport type TextStyleDeclaration = Partial<CompleteTextStyleDeclaration>;\n\nexport type TextStyle = {\n [line: number | string]: { [char: number | string]: TextStyleDeclaration };\n};\n\nexport abstract class StyledText<\n Props extends TOptions<FabricObjectProps> = Partial<FabricObjectProps>,\n SProps extends SerializedObjectProps = SerializedObjectProps,\n EventSpec extends ObjectEvents = ObjectEvents,\n> extends FabricObject<Props, SProps, EventSpec> {\n declare abstract styles: TextStyle;\n protected declare abstract _textLines: string[][];\n protected declare _forceClearCache: boolean;\n static _styleProperties: Readonly<StylePropertiesType[]> = styleProperties;\n abstract get2DCursorLocation(\n selectionStart: number,\n skipWrapping?: boolean,\n ): { charIndex: number; lineIndex: number };\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 if (typeof lineIndex !== 'undefined' && !this.styles[lineIndex]) {\n return true;\n }\n const obj =\n typeof lineIndex === 'undefined'\n ? this.styles\n : { line: this.styles[lineIndex] };\n for (const p1 in obj) {\n for (const p2 in obj[p1]) {\n // eslint-disable-next-line no-unused-vars\n for (const p3 in obj[p1][p2]) {\n return false;\n }\n }\n }\n return true;\n }\n\n /**\n * Returns true if object has a style property or has it ina specified line\n * This function is used to detect if a text will use a particular property or not.\n * @param {String} property to check for\n * @param {Number} lineIndex to check the style on\n * @return {Boolean}\n */\n styleHas(property: keyof TextStyleDeclaration, lineIndex?: number): boolean {\n if (!this.styles) {\n return false;\n }\n if (typeof lineIndex !== 'undefined' && !this.styles[lineIndex]) {\n return false;\n }\n const obj =\n typeof lineIndex === 'undefined'\n ? this.styles\n : { 0: this.styles[lineIndex] };\n // eslint-disable-next-line\n for (const p1 in obj) {\n // eslint-disable-next-line\n for (const p2 in obj[p1]) {\n if (typeof obj[p1][p2][property] !== 'undefined') {\n return true;\n }\n }\n }\n return false;\n }\n\n /**\n * Check if characters in a text have a value for a property\n * whose value matches the textbox's value for that property. If so,\n * the character-level property is deleted. If the character\n * has no other properties, then it is also deleted. Finally,\n * if the line containing that character has no other characters\n * then it also is deleted.\n *\n * @param {string} property The property to compare between characters and text.\n */\n cleanStyle(property: keyof TextStyleDeclaration) {\n if (!this.styles) {\n return false;\n }\n const obj = this.styles;\n let stylesCount = 0,\n letterCount,\n stylePropertyValue,\n allStyleObjectPropertiesMatch = true,\n graphemeCount = 0;\n for (const p1 in obj) {\n letterCount = 0;\n for (const p2 in obj[p1]) {\n const styleObject = obj[p1][p2] || {},\n stylePropertyHasBeenSet = styleObject[property] !== undefined;\n\n stylesCount++;\n\n if (stylePropertyHasBeenSet) {\n if (!stylePropertyValue) {\n stylePropertyValue = styleObject[property];\n } else if (styleObject[property] !== stylePropertyValue) {\n allStyleObjectPropertiesMatch = false;\n }\n\n if (styleObject[property] === this[property as keyof this]) {\n delete styleObject[property];\n }\n } else {\n allStyleObjectPropertiesMatch = false;\n }\n\n if (Object.keys(styleObject).length !== 0) {\n letterCount++;\n } else {\n delete obj[p1][p2];\n }\n }\n\n if (letterCount === 0) {\n delete obj[p1];\n }\n }\n // if every grapheme has the same style set then\n // delete those styles and set it on the parent\n for (let i = 0; i < this._textLines.length; i++) {\n graphemeCount += this._textLines[i].length;\n }\n if (allStyleObjectPropertiesMatch && stylesCount === graphemeCount) {\n // @ts-expect-error conspiracy theory of TS\n this[property as keyof this] = stylePropertyValue;\n this.removeStyle(property);\n }\n }\n\n /**\n * Remove a style property or properties from all individual character styles\n * in a text object. Deletes the character style object if it contains no other style\n * props. Deletes a line style object if it contains no other character styles.\n *\n * @param {String} props The property to remove from character styles.\n */\n removeStyle(property: keyof TextStyleDeclaration) {\n if (!this.styles) {\n return;\n }\n const obj = this.styles;\n let line, lineNum, charNum;\n for (lineNum in obj) {\n line = obj[lineNum];\n for (charNum in line) {\n delete line[charNum][property];\n if (Object.keys(line[charNum]).length === 0) {\n delete line[charNum];\n }\n }\n if (Object.keys(line).length === 0) {\n delete obj[lineNum];\n }\n }\n }\n\n private _extendStyles(index: number, style: TextStyleDeclaration): void {\n const { lineIndex, charIndex } = this.get2DCursorLocation(index);\n\n if (!this._getLineStyle(lineIndex)) {\n this._setLineStyle(lineIndex);\n }\n\n const newStyle = pickBy(\n {\n // first create a new object that is a merge of existing and new\n ...this._getStyleDeclaration(lineIndex, charIndex),\n ...style,\n // use the predicate to discard undefined values\n },\n (value) => value !== undefined,\n );\n\n // finally assign to the old position the new style\n this._setStyleDeclaration(lineIndex, charIndex, newStyle);\n }\n\n /**\n * Gets style of a current selection/cursor (at the start position)\n * @param {Number} startIndex Start index to get styles at\n * @param {Number} endIndex End index to get styles at, if not specified startIndex + 1\n * @param {Boolean} [complete] get full style or not\n * @return {Array} styles an array with one, zero or more Style objects\n */\n getSelectionStyles(\n startIndex: number,\n endIndex?: number,\n complete?: boolean,\n ): TextStyleDeclaration[] {\n const styles: TextStyleDeclaration[] = [];\n for (let i = startIndex; i < (endIndex || startIndex); i++) {\n styles.push(this.getStyleAtPosition(i, complete));\n }\n return styles;\n }\n\n /**\n * Gets style of a current selection/cursor position\n * @param {Number} position to get styles at\n * @param {Boolean} [complete] full style if true\n * @return {Object} style Style object at a specified index\n * @private\n */\n getStyleAtPosition(position: number, complete?: boolean) {\n const { lineIndex, charIndex } = this.get2DCursorLocation(position);\n return complete\n ? this.getCompleteStyleDeclaration(lineIndex, charIndex)\n : this._getStyleDeclaration(lineIndex, charIndex);\n }\n\n /**\n * Sets style of a current selection, if no selection exist, do not set anything.\n * @param {Object} styles Styles object\n * @param {Number} startIndex Start index to get styles at\n * @param {Number} [endIndex] End index to get styles at, if not specified startIndex + 1\n */\n setSelectionStyles(styles: object, startIndex: number, endIndex?: number) {\n for (let i = startIndex; i < (endIndex || startIndex); i++) {\n this._extendStyles(i, styles);\n }\n /* not included in _extendStyles to avoid clearing cache more than once */\n this._forceClearCache = true;\n }\n\n /**\n * Get a reference, not a clone, to the style object for a given character,\n * if no style is set for a line or char, return a new empty object.\n * This is tricky and confusing because when you get an empty object you can't\n * determine if it is a reference or a new one.\n * @TODO this should always return a reference or always a clone or undefined when necessary.\n * @protected\n * @param {Number} lineIndex\n * @param {Number} charIndex\n * @return {TextStyleDeclaration} a style object reference to the existing one or a new empty object when undefined\n */\n _getStyleDeclaration(\n lineIndex: number,\n charIndex: number,\n ): TextStyleDeclaration {\n const lineStyle = this.styles && this.styles[lineIndex];\n return lineStyle ? lineStyle[charIndex] ?? {} : {};\n }\n\n /**\n * return a new object that contains all the style property for a character\n * the object returned is newly created\n * @param {Number} lineIndex of the line where the character is\n * @param {Number} charIndex position of the character on the line\n * @return {Object} style object\n */\n getCompleteStyleDeclaration(\n lineIndex: number,\n charIndex: number,\n ): CompleteTextStyleDeclaration {\n return {\n // @ts-expect-error readonly\n ...pick(this, (this.constructor as typeof StyledText)._styleProperties),\n ...this._getStyleDeclaration(lineIndex, charIndex),\n } as CompleteTextStyleDeclaration;\n }\n\n /**\n * @param {Number} lineIndex\n * @param {Number} charIndex\n * @param {Object} style\n * @private\n */\n protected _setStyleDeclaration(\n lineIndex: number,\n charIndex: number,\n style: object,\n ) {\n this.styles[lineIndex][charIndex] = style;\n }\n\n /**\n *\n * @param {Number} lineIndex\n * @param {Number} charIndex\n * @private\n */\n protected _deleteStyleDeclaration(lineIndex: number, charIndex: number) {\n delete this.styles[lineIndex][charIndex];\n }\n\n /**\n * @param {Number} lineIndex\n * @return {Boolean} if the line exists or not\n * @private\n */\n protected _getLineStyle(lineIndex: number): boolean {\n return !!this.styles[lineIndex];\n }\n\n /**\n * Set the line style to an empty object so that is initialized\n * @param {Number} lineIndex\n * @private\n */\n protected _setLineStyle(lineIndex: number) {\n this.styles[lineIndex] = {};\n }\n\n protected _deleteLineStyle(lineIndex: number) {\n delete this.styles[lineIndex];\n }\n}\n"],"names":["StyledText","FabricObject","isEmptyStyles","lineIndex","styles","obj","line","p1","p2","p3","styleHas","property","cleanStyle","stylesCount","letterCount","stylePropertyValue","allStyleObjectPropertiesMatch","graphemeCount","styleObject","stylePropertyHasBeenSet","undefined","Object","keys","length","i","_textLines","removeStyle","lineNum","charNum","_extendStyles","index","style","charIndex","get2DCursorLocation","_getLineStyle","_setLineStyle","newStyle","pickBy","_objectSpread","_getStyleDeclaration","value","_setStyleDeclaration","getSelectionStyles","startIndex","endIndex","complete","push","getStyleAtPosition","position","getCompleteStyleDeclaration","setSelectionStyles","_forceClearCache","_lineStyle$charIndex","lineStyle","pick","constructor","_styleProperties","_deleteStyleDeclaration","_deleteLineStyle","_defineProperty","styleProperties"],"mappings":";;;;;;;;;;;;;AAqBO,MAAeA,UAAU,SAItBC,YAAY,CAA2B;AAU/C;AACF;AACA;AACA;AACA;EACEC,aAAaA,CAACC,SAAkB,EAAW;AACzC,IAAA,IAAI,CAAC,IAAI,CAACC,MAAM,EAAE;AAChB,MAAA,OAAO,IAAI,CAAA;AACb,KAAA;AACA,IAAA,IAAI,OAAOD,SAAS,KAAK,WAAW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A,kBAAA,EAQ6B4D,eAAe,CAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"boundingBoxFromPoints.d.ts","sourceRoot":"","sources":["../../../../src/util/misc/boundingBoxFromPoints.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEtC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,WAAY,EAAE,EAAE,KAAG,KA4BxD,CAAC"}
1
+ {"version":3,"file":"boundingBoxFromPoints.d.ts","sourceRoot":"","sources":["../../../../src/util/misc/boundingBoxFromPoints.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,WAAY,EAAE,EAAE,KAAG,KAoBxD,CAAC"}
@@ -1,2 +1,2 @@
1
- import{Point as t}from"../../Point.min.mjs";const n=n=>{if(0===n.length)return{left:0,top:0,width:0,height:0};const{min:e,max:m}=n.reduce(((t,n)=>{let{min:e,max:m}=t;return{min:e.min(n),max:m.max(n)}}),{min:new t(n[0]),max:new t(n[0])}),i=m.subtract(e);return{left:e.x,top:e.y,width:i.x,height:i.y}};export{n as makeBoundingBoxFromPoints};
1
+ const t=t=>{let e=0,o=0,h=0,l=0;for(let n=0,r=t.length;n<r;n++){const{x:r,y:c}=t[n];(r>h||!n)&&(h=r),(r<e||!n)&&(e=r),(c>l||!n)&&(l=c),(c<o||!n)&&(o=c)}return{left:e,top:o,width:h-e,height:l-o}};export{t as makeBoundingBoxFromPoints};
2
2
  //# sourceMappingURL=boundingBoxFromPoints.min.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"boundingBoxFromPoints.min.mjs","sources":["../../../../src/util/misc/boundingBoxFromPoints.ts"],"sourcesContent":["import type { XY } from '../../Point';\nimport { Point } from '../../Point';\nimport type { TBBox } from '../../typedefs';\n\n/**\n * Calculates bounding box (left, top, width, height) from given `points`\n * @param {XY[]} points\n * @return {Object} Object with left, top, width, height properties\n */\nexport const makeBoundingBoxFromPoints = (points: XY[]): TBBox => {\n if (points.length === 0) {\n return {\n left: 0,\n top: 0,\n width: 0,\n height: 0,\n };\n }\n\n const { min, max } = points.reduce(\n ({ min, max }, curr) => {\n return {\n min: min.min(curr),\n max: max.max(curr),\n };\n },\n { min: new Point(points[0]), max: new Point(points[0]) },\n );\n\n const size = max.subtract(min);\n\n return {\n left: min.x,\n top: min.y,\n width: size.x,\n height: size.y,\n };\n};\n"],"names":["makeBoundingBoxFromPoints","points","length","left","top","width","height","min","max","reduce","_ref","curr","Point","size","subtract","x","y"],"mappings":"4CASaA,MAAAA,EAA6BC,IACxC,GAAsB,IAAlBA,EAAOC,OACT,MAAO,CACLC,KAAM,EACNC,IAAK,EACLC,MAAO,EACPC,OAAQ,GAIZ,MAAMC,IAAEA,EAAGC,IAAEA,GAAQP,EAAOQ,QAC1B,CAAAC,EAAeC,KAAS,IAAvBJ,IAAEA,EAAGC,IAAEA,GAAKE,EACX,MAAO,CACLH,IAAKA,EAAIA,IAAII,GACbH,IAAKA,EAAIA,IAAIG,GACd,GAEH,CAAEJ,IAAK,IAAIK,EAAMX,EAAO,IAAKO,IAAK,IAAII,EAAMX,EAAO,MAG/CY,EAAOL,EAAIM,SAASP,GAE1B,MAAO,CACLJ,KAAMI,EAAIQ,EACVX,IAAKG,EAAIS,EACTX,MAAOQ,EAAKE,EACZT,OAAQO,EAAKG,EACd"}
1
+ {"version":3,"file":"boundingBoxFromPoints.min.mjs","sources":["../../../../src/util/misc/boundingBoxFromPoints.ts"],"sourcesContent":["import type { XY } from '../../Point';\nimport type { TBBox } from '../../typedefs';\n\n/**\n * Calculates bounding box (left, top, width, height) from given `points`\n * @param {XY[]} points\n * @return {Object} Object with left, top, width, height properties\n */\nexport const makeBoundingBoxFromPoints = (points: XY[]): TBBox => {\n let left = 0,\n top = 0,\n width = 0,\n height = 0;\n\n for (let i = 0, len = points.length; i < len; i++) {\n const { x, y } = points[i];\n if (x > width || !i) width = x;\n if (x < left || !i) left = x;\n if (y > height || !i) height = y;\n if (y < top || !i) top = y;\n }\n\n return {\n left,\n top,\n width: width - left,\n height: height - top,\n };\n};\n"],"names":["makeBoundingBoxFromPoints","points","left","top","width","height","i","len","length","x","y"],"mappings":"AAQaA,MAAAA,EAA6BC,IACxC,IAAIC,EAAO,EACTC,EAAM,EACNC,EAAQ,EACRC,EAAS,EAEX,IAAK,IAAIC,EAAI,EAAGC,EAAMN,EAAOO,OAAQF,EAAIC,EAAKD,IAAK,CACjD,MAAMG,EAAEA,EAACC,EAAEA,GAAMT,EAAOK,IACpBG,EAAIL,IAAUE,KAAGF,EAAQK,IACzBA,EAAIP,IAASI,KAAGJ,EAAOO,IACvBC,EAAIL,IAAWC,KAAGD,EAASK,IAC3BA,EAAIP,IAAQG,KAAGH,EAAMO,EAC3B,CAEA,MAAO,CACLR,OACAC,MACAC,MAAOA,EAAQF,EACfG,OAAQA,EAASF,EAClB"}
@@ -1,41 +1,28 @@
1
- import { Point } from '../../Point.mjs';
2
-
3
1
  /**
4
2
  * Calculates bounding box (left, top, width, height) from given `points`
5
3
  * @param {XY[]} points
6
4
  * @return {Object} Object with left, top, width, height properties
7
5
  */
8
6
  const makeBoundingBoxFromPoints = points => {
9
- if (points.length === 0) {
10
- return {
11
- left: 0,
12
- top: 0,
13
- width: 0,
14
- height: 0
15
- };
7
+ let left = 0,
8
+ top = 0,
9
+ width = 0,
10
+ height = 0;
11
+ for (let i = 0, len = points.length; i < len; i++) {
12
+ const {
13
+ x,
14
+ y
15
+ } = points[i];
16
+ if (x > width || !i) width = x;
17
+ if (x < left || !i) left = x;
18
+ if (y > height || !i) height = y;
19
+ if (y < top || !i) top = y;
16
20
  }
17
- const {
18
- min,
19
- max
20
- } = points.reduce((_ref, curr) => {
21
- let {
22
- min,
23
- max
24
- } = _ref;
25
- return {
26
- min: min.min(curr),
27
- max: max.max(curr)
28
- };
29
- }, {
30
- min: new Point(points[0]),
31
- max: new Point(points[0])
32
- });
33
- const size = max.subtract(min);
34
21
  return {
35
- left: min.x,
36
- top: min.y,
37
- width: size.x,
38
- height: size.y
22
+ left,
23
+ top,
24
+ width: width - left,
25
+ height: height - top
39
26
  };
40
27
  };
41
28
 
@@ -1 +1 @@
1
- {"version":3,"file":"boundingBoxFromPoints.mjs","sources":["../../../../src/util/misc/boundingBoxFromPoints.ts"],"sourcesContent":["import type { XY } from '../../Point';\nimport { Point } from '../../Point';\nimport type { TBBox } from '../../typedefs';\n\n/**\n * Calculates bounding box (left, top, width, height) from given `points`\n * @param {XY[]} points\n * @return {Object} Object with left, top, width, height properties\n */\nexport const makeBoundingBoxFromPoints = (points: XY[]): TBBox => {\n if (points.length === 0) {\n return {\n left: 0,\n top: 0,\n width: 0,\n height: 0,\n };\n }\n\n const { min, max } = points.reduce(\n ({ min, max }, curr) => {\n return {\n min: min.min(curr),\n max: max.max(curr),\n };\n },\n { min: new Point(points[0]), max: new Point(points[0]) },\n );\n\n const size = max.subtract(min);\n\n return {\n left: min.x,\n top: min.y,\n width: size.x,\n height: size.y,\n };\n};\n"],"names":["makeBoundingBoxFromPoints","points","length","left","top","width","height","min","max","reduce","_ref","curr","Point","size","subtract","x","y"],"mappings":";;AAIA;AACA;AACA;AACA;AACA;AACaA,MAAAA,yBAAyB,GAAIC,MAAY,IAAY;AAChE,EAAA,IAAIA,MAAM,CAACC,MAAM,KAAK,CAAC,EAAE;IACvB,OAAO;AACLC,MAAAA,IAAI,EAAE,CAAC;AACPC,MAAAA,GAAG,EAAE,CAAC;AACNC,MAAAA,KAAK,EAAE,CAAC;AACRC,MAAAA,MAAM,EAAE,CAAA;KACT,CAAA;AACH,GAAA;EAEA,MAAM;IAAEC,GAAG;AAAEC,IAAAA,GAAAA;GAAK,GAAGP,MAAM,CAACQ,MAAM,CAChC,CAAAC,IAAA,EAAeC,IAAI,KAAK;IAAA,IAAvB;MAAEJ,GAAG;AAAEC,MAAAA,GAAAA;AAAI,KAAC,GAAAE,IAAA,CAAA;IACX,OAAO;AACLH,MAAAA,GAAG,EAAEA,GAAG,CAACA,GAAG,CAACI,IAAI,CAAC;AAClBH,MAAAA,GAAG,EAAEA,GAAG,CAACA,GAAG,CAACG,IAAI,CAAA;KAClB,CAAA;AACH,GAAC,EACD;IAAEJ,GAAG,EAAE,IAAIK,KAAK,CAACX,MAAM,CAAC,CAAC,CAAC,CAAC;AAAEO,IAAAA,GAAG,EAAE,IAAII,KAAK,CAACX,MAAM,CAAC,CAAC,CAAC,CAAA;AAAE,GACzD,CAAC,CAAA;AAED,EAAA,MAAMY,IAAI,GAAGL,GAAG,CAACM,QAAQ,CAACP,GAAG,CAAC,CAAA;EAE9B,OAAO;IACLJ,IAAI,EAAEI,GAAG,CAACQ,CAAC;IACXX,GAAG,EAAEG,GAAG,CAACS,CAAC;IACVX,KAAK,EAAEQ,IAAI,CAACE,CAAC;IACbT,MAAM,EAAEO,IAAI,CAACG,CAAAA;GACd,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"boundingBoxFromPoints.mjs","sources":["../../../../src/util/misc/boundingBoxFromPoints.ts"],"sourcesContent":["import type { XY } from '../../Point';\nimport type { TBBox } from '../../typedefs';\n\n/**\n * Calculates bounding box (left, top, width, height) from given `points`\n * @param {XY[]} points\n * @return {Object} Object with left, top, width, height properties\n */\nexport const makeBoundingBoxFromPoints = (points: XY[]): TBBox => {\n let left = 0,\n top = 0,\n width = 0,\n height = 0;\n\n for (let i = 0, len = points.length; i < len; i++) {\n const { x, y } = points[i];\n if (x > width || !i) width = x;\n if (x < left || !i) left = x;\n if (y > height || !i) height = y;\n if (y < top || !i) top = y;\n }\n\n return {\n left,\n top,\n width: width - left,\n height: height - top,\n };\n};\n"],"names":["makeBoundingBoxFromPoints","points","left","top","width","height","i","len","length","x","y"],"mappings":"AAGA;A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CAAC"}
@@ -1,2 +1,2 @@
1
- import{objectSpread2 as t}from"../../../_virtual/_rollupPluginBabelHelpers.min.mjs";import{cache as e}from"../../cache.min.mjs";import{config as n}from"../../config.min.mjs";import{halfPI as s,PiBy180 as r}from"../../constants.min.mjs";import{cos as a}from"../misc/cos.min.mjs";import{multiplyTransformMatrices as o,transformPoint as c}from"../misc/matrix.min.mjs";import{sin as i}from"../misc/sin.min.mjs";import{toFixed as l}from"../misc/toFixed.min.mjs";import{Point as h}from"../../Point.min.mjs";import{rePathCommand as m}from"./regex.min.mjs";import{cleanupSvgAttribute as u}from"../internals/cleanupSvgAttribute.min.mjs";const f={m:"l",M:"L"},x=(t,e,n,s,r,o,c,l,h,m,u)=>{const f=a(t),x=i(t),p=a(e),g=i(e),y=n*r*p-s*o*g+c,M=s*r*p+n*o*g+l;return["C",m+h*(-n*r*x-s*o*f),u+h*(-s*r*x+n*o*f),y+h*(n*r*g+s*o*p),M+h*(s*r*g-n*o*p),y,M]},p=(t,e,n,s)=>{const r=Math.atan2(e,t),a=Math.atan2(s,n);return a>=r?a-r:2*Math.PI-(r-a)};function g(t,s,r,a,o,c,i,l){let m;if(n.cachesBoundsOfCurve&&(m=[...arguments].join(),e.boundsOfCurveCache[m]))return e.boundsOfCurveCache[m];const u=Math.sqrt,f=Math.abs,x=[],p=[[0,0],[0,0]];let g=6*t-12*r+6*o,y=-3*t+9*r-9*o+3*i,M=3*r-3*t;for(let t=0;t<2;++t){if(t>0&&(g=6*s-12*a+6*c,y=-3*s+9*a-9*c+3*l,M=3*a-3*s),f(y)<1e-12){if(f(g)<1e-12)continue;const t=-M/g;0<t&&t<1&&x.push(t);continue}const e=g*g-4*M*y;if(e<0)continue;const n=u(e),r=(-g+n)/(2*y);0<r&&r<1&&x.push(r);const o=(-g-n)/(2*y);0<o&&o<1&&x.push(o)}let b=x.length;const w=b,j=d(t,s,r,a,o,c,i,l);for(;b--;){const{x:t,y:e}=j(x[b]);p[0][b]=t,p[1][b]=e}p[0][w]=t,p[1][w]=s,p[0][w+1]=i,p[1][w+1]=l;const k=[new h(Math.min(...p[0]),Math.min(...p[1])),new h(Math.max(...p[0]),Math.max(...p[1]))];return n.cachesBoundsOfCurve&&(e.boundsOfCurveCache[m]=k),k}const y=(t,e,n)=>{let[s,o,c,l,h,m,u,f]=n;const g=((t,e,n,s,o,c,l)=>{if(0===n||0===s)return[];let h=0,m=0,u=0;const f=Math.PI,g=l*r,y=i(g),M=a(g),b=.5*(-M*t-y*e),d=.5*(-M*e+y*t),w=n**2,j=s**2,k=d**2,C=b**2,v=w*j-w*k-j*C;let L=Math.abs(n),Q=Math.abs(s);if(v<0){const t=Math.sqrt(1-v/(w*j));L*=t,Q*=t}else u=(o===c?-1:1)*Math.sqrt(v/(w*k+j*C));const q=u*L*d/Q,F=-u*Q*b/L,P=M*q-y*F+.5*t,E=y*q+M*F+.5*e;let O=p(1,0,(b-q)/L,(d-F)/Q),Z=p((b-q)/L,(d-F)/Q,(-b-q)/L,(-d-F)/Q);0===c&&Z>0?Z-=2*f:1===c&&Z<0&&(Z+=2*f);const A=Math.ceil(Math.abs(Z/f*2)),N=[],B=Z/A,I=8/3*Math.sin(B/4)*Math.sin(B/4)/Math.sin(B/2);let R=O+B;for(let t=0;t<A;t++)N[t]=x(O,R,M,y,L,Q,P,E,I,h,m),h=N[t][5],m=N[t][6],O=R,R+=B;return N})(u-t,f-e,o,c,h,m,l);for(let n=0,s=g.length;n<s;n++)g[n][1]+=t,g[n][2]+=e,g[n][3]+=t,g[n][4]+=e,g[n][5]+=t,g[n][6]+=e;return g},M=t=>{let e=0,n=0,s=0,r=0;const a=[];let o,c=0,i=0;for(const l of t){const t=[...l];let h;switch(t[0]){case"l":t[1]+=e,t[2]+=n;case"L":e=t[1],n=t[2],h=["L",e,n];break;case"h":t[1]+=e;case"H":e=t[1],h=["L",e,n];break;case"v":t[1]+=n;case"V":n=t[1],h=["L",e,n];break;case"m":t[1]+=e,t[2]+=n;case"M":e=t[1],n=t[2],s=t[1],r=t[2],h=["M",e,n];break;case"c":t[1]+=e,t[2]+=n,t[3]+=e,t[4]+=n,t[5]+=e,t[6]+=n;case"C":c=t[3],i=t[4],e=t[5],n=t[6],h=["C",t[1],t[2],c,i,e,n];break;case"s":t[1]+=e,t[2]+=n,t[3]+=e,t[4]+=n;case"S":"C"===o?(c=2*e-c,i=2*n-i):(c=e,i=n),e=t[3],n=t[4],h=["C",c,i,t[1],t[2],e,n],c=h[3],i=h[4];break;case"q":t[1]+=e,t[2]+=n,t[3]+=e,t[4]+=n;case"Q":c=t[1],i=t[2],e=t[3],n=t[4],h=["Q",c,i,e,n];break;case"t":t[1]+=e,t[2]+=n;case"T":"Q"===o?(c=2*e-c,i=2*n-i):(c=e,i=n),e=t[1],n=t[2],h=["Q",c,i,e,n];break;case"a":t[6]+=e,t[7]+=n;case"A":y(e,n,t).forEach((t=>a.push(t))),e=t[6],n=t[7];break;case"z":case"Z":e=s,n=r,h=["Z"]}h?(a.push(h),o=h[0]):o=""}return a},b=(t,e,n,s)=>Math.sqrt((n-t)**2+(s-e)**2),d=(t,e,n,s,r,a,o,c)=>i=>{const l=i**3,m=(t=>3*t**2*(1-t))(i),u=(t=>3*t*(1-t)**2)(i),f=(t=>(1-t)**3)(i);return new h(o*l+r*m+n*u+t*f,c*l+a*m+s*u+e*f)},w=t=>t**2,j=t=>2*t*(1-t),k=t=>(1-t)**2,C=(t,e,n,s,r,a,o,c)=>i=>{const l=w(i),h=j(i),m=k(i),u=3*(m*(n-t)+h*(r-n)+l*(o-r)),f=3*(m*(s-e)+h*(a-s)+l*(c-a));return Math.atan2(f,u)},v=(t,e,n,s,r,a)=>o=>{const c=w(o),i=j(o),l=k(o);return new h(r*c+n*i+t*l,a*c+s*i+e*l)},L=(t,e,n,s,r,a)=>o=>{const c=1-o,i=2*(c*(n-t)+o*(r-n)),l=2*(c*(s-e)+o*(a-s));return Math.atan2(l,i)},Q=(t,e,n)=>{let s=new h(e,n),r=0;for(let e=1;e<=100;e+=1){const n=t(e/100);r+=b(s.x,s.y,n.x,n.y),s=n}return r},q=(e,n)=>{let s,r=0,a=0,o={x:e.x,y:e.y},c=t({},o),i=.01,l=0;const h=e.iterator,m=e.angleFinder;for(;a<n&&i>1e-4;)c=h(r),l=r,s=b(o.x,o.y,c.x,c.y),s+a>n?(r-=i,i/=2):(o=c,r+=i,a+=s);return t(t({},c),{},{angle:m(l)})},F=t=>{let e,n,s=0,r=0,a=0,o=0,c=0;const i=[];for(const l of t){const t={x:r,y:a,command:l[0],length:0};switch(l[0]){case"M":n=t,n.x=o=r=l[1],n.y=c=a=l[2];break;case"L":n=t,n.length=b(r,a,l[1],l[2]),r=l[1],a=l[2];break;case"C":e=d(r,a,l[1],l[2],l[3],l[4],l[5],l[6]),n=t,n.iterator=e,n.angleFinder=C(r,a,l[1],l[2],l[3],l[4],l[5],l[6]),n.length=Q(e,r,a),r=l[5],a=l[6];break;case"Q":e=v(r,a,l[1],l[2],l[3],l[4]),n=t,n.iterator=e,n.angleFinder=L(r,a,l[1],l[2],l[3],l[4]),n.length=Q(e,r,a),r=l[3],a=l[4];break;case"Z":n=t,n.destX=o,n.destY=c,n.length=b(r,a,o,c),r=o,a=c}s+=n.length,i.push(n)}return i.push({length:s,x:r,y:a}),i},P=function(e,n){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:F(e),r=0;for(;n-s[r].length>0&&r<s.length-2;)n-=s[r].length,r++;const a=s[r],o=n/a.length,c=e[r];switch(a.command){case"M":return{x:a.x,y:a.y,angle:0};case"Z":return t(t({},new h(a.x,a.y).lerp(new h(a.destX,a.destY),o)),{},{angle:Math.atan2(a.destY-a.y,a.destX-a.x)});case"L":return t(t({},new h(a.x,a.y).lerp(new h(c[1],c[2]),o)),{},{angle:Math.atan2(c[2]-a.y,c[1]-a.x)});case"C":case"Q":return q(a,n)}},E=new RegExp(m,"gi"),O=new RegExp(m,"i"),Z=t=>{t=u(t);const e=[];for(let[n]of t.matchAll(E)){const t=[];let s;do{if(s=O.exec(n),!s)break;const e=s.filter((t=>t));e.shift();const r=e.map((t=>{const e=Number.parseFloat(t);return Number.isNaN(e)?t:e}));if(t.push(r),e.length<=1)break;e.shift(),n=n.replace(new RegExp("".concat(e.join(" ?")," ?$")),"")}while(s);t.reverse().forEach(((t,n)=>{const s=f[t[0]];n>0&&("l"==s||"L"==s)&&(t[0]=s),e.push(t)}))}return e},A=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=new h(t[0]),s=new h(t[1]),r=1,a=0;const o=[],c=t.length,i=c>2;let l;for(i&&(r=t[2].x<s.x?-1:t[2].x===s.x?0:1,a=t[2].y<s.y?-1:t[2].y===s.y?0:1),o.push(["M",n.x-r*e,n.y-a*e]),l=1;l<c;l++){if(!n.eq(s)){const t=n.midPointFrom(s);o.push(["Q",n.x,n.y,t.x,t.y])}n=t[l],l+1<t.length&&(s=t[l+1])}return i&&(r=n.x>t[l-2].x?1:n.x===t[l-2].x?0:-1,a=n.y>t[l-2].y?1:n.y===t[l-2].y?0:-1),o.push(["L",n.x+r*e,n.y+a*e]),o},N=(t,e,n)=>(n&&(e=o(e,[1,0,0,1,-n.x,-n.y])),t.map((t=>{const n=[...t];for(let s=1;s<t.length-1;s+=2){const{x:r,y:a}=c({x:t[s],y:t[s+1]},e);n[s]=r,n[s+1]=a}return n}))),B=(t,e)=>{const n=2*Math.PI/t;let r=-s;t%2==0&&(r+=n/2);const o=new Array(t+1);for(let s=0;s<t;s++){const t=s*n+r,{x:c,y:l}=new h(a(t),i(t)).scalarMultiply(e);o[s]=[0===s?"M":"L",c,l]}return o[t]=["Z"],o},I=(t,e)=>t.map((t=>t.map(((t,n)=>0===n||void 0===e?t:l(t,e))).join(" "))).join(" ");export{y as fromArcToBeziers,g as getBoundsOfCurve,F as getPathSegmentsInfo,P as getPointOnPath,B as getRegularPolygonPath,A as getSmoothPathFromPoints,I as joinPath,M as makePathSimpler,Z as parsePath,N as transformPath};
1
+ import{objectSpread2 as t}from"../../../_virtual/_rollupPluginBabelHelpers.min.mjs";import{cache as e}from"../../cache.min.mjs";import{config as n}from"../../config.min.mjs";import{halfPI as s,PiBy180 as r}from"../../constants.min.mjs";import{cos as a}from"../misc/cos.min.mjs";import{multiplyTransformMatrices as o,transformPoint as c}from"../misc/matrix.min.mjs";import{sin as l}from"../misc/sin.min.mjs";import{toFixed as i}from"../misc/toFixed.min.mjs";import{Point as h}from"../../Point.min.mjs";import{rePathCommand as m,reArcCommandPoints as u}from"./regex.min.mjs";import{reNum as f}from"../../parser/constants.min.mjs";const x={m:"l",M:"L"},p=(t,e,n,s,r,o,c,i,h,m,u)=>{const f=a(t),x=l(t),p=a(e),g=l(e),y=n*r*p-s*o*g+c,M=s*r*p+n*o*g+i;return["C",m+h*(-n*r*x-s*o*f),u+h*(-s*r*x+n*o*f),y+h*(n*r*g+s*o*p),M+h*(s*r*g-n*o*p),y,M]},g=(t,e,n,s)=>{const r=Math.atan2(e,t),a=Math.atan2(s,n);return a>=r?a-r:2*Math.PI-(r-a)};function y(t,s,r,a,o,c,l,i){let m;if(n.cachesBoundsOfCurve&&(m=[...arguments].join(),e.boundsOfCurveCache[m]))return e.boundsOfCurveCache[m];const u=Math.sqrt,f=Math.abs,x=[],p=[[0,0],[0,0]];let g=6*t-12*r+6*o,y=-3*t+9*r-9*o+3*l,M=3*r-3*t;for(let t=0;t<2;++t){if(t>0&&(g=6*s-12*a+6*c,y=-3*s+9*a-9*c+3*i,M=3*a-3*s),f(y)<1e-12){if(f(g)<1e-12)continue;const t=-M/g;0<t&&t<1&&x.push(t);continue}const e=g*g-4*M*y;if(e<0)continue;const n=u(e),r=(-g+n)/(2*y);0<r&&r<1&&x.push(r);const o=(-g-n)/(2*y);0<o&&o<1&&x.push(o)}let d=x.length;const b=d,C=w(t,s,r,a,o,c,l,i);for(;d--;){const{x:t,y:e}=C(x[d]);p[0][d]=t,p[1][d]=e}p[0][b]=t,p[1][b]=s,p[0][b+1]=l,p[1][b+1]=i;const j=[new h(Math.min(...p[0]),Math.min(...p[1])),new h(Math.max(...p[0]),Math.max(...p[1]))];return n.cachesBoundsOfCurve&&(e.boundsOfCurveCache[m]=j),j}const M=(t,e,n)=>{let[s,o,c,i,h,m,u,f]=n;const x=((t,e,n,s,o,c,i)=>{if(0===n||0===s)return[];let h=0,m=0,u=0;const f=Math.PI,x=i*r,y=l(x),M=a(x),d=.5*(-M*t-y*e),b=.5*(-M*e+y*t),w=n**2,C=s**2,j=b**2,k=d**2,v=w*C-w*j-C*k;let L=Math.abs(n),q=Math.abs(s);if(v<0){const t=Math.sqrt(1-v/(w*C));L*=t,q*=t}else u=(o===c?-1:1)*Math.sqrt(v/(w*j+C*k));const Q=u*L*b/q,F=-u*q*d/L,P=M*Q-y*F+.5*t,Z=y*Q+M*F+.5*e;let O=g(1,0,(d-Q)/L,(b-F)/q),A=g((d-Q)/L,(b-F)/q,(-d-Q)/L,(-b-F)/q);0===c&&A>0?A-=2*f:1===c&&A<0&&(A+=2*f);const E=Math.ceil(Math.abs(A/f*2)),I=[],B=A/E,R=8/3*Math.sin(B/4)*Math.sin(B/4)/Math.sin(B/2);let X=O+B;for(let t=0;t<E;t++)I[t]=p(O,X,M,y,L,q,P,Z,R,h,m),h=I[t][5],m=I[t][6],O=X,X+=B;return I})(u-t,f-e,o,c,h,m,i);for(let n=0,s=x.length;n<s;n++)x[n][1]+=t,x[n][2]+=e,x[n][3]+=t,x[n][4]+=e,x[n][5]+=t,x[n][6]+=e;return x},d=t=>{let e=0,n=0,s=0,r=0;const a=[];let o,c=0,l=0;for(const i of t){const t=[...i];let h;switch(t[0]){case"l":t[1]+=e,t[2]+=n;case"L":e=t[1],n=t[2],h=["L",e,n];break;case"h":t[1]+=e;case"H":e=t[1],h=["L",e,n];break;case"v":t[1]+=n;case"V":n=t[1],h=["L",e,n];break;case"m":t[1]+=e,t[2]+=n;case"M":e=t[1],n=t[2],s=t[1],r=t[2],h=["M",e,n];break;case"c":t[1]+=e,t[2]+=n,t[3]+=e,t[4]+=n,t[5]+=e,t[6]+=n;case"C":c=t[3],l=t[4],e=t[5],n=t[6],h=["C",t[1],t[2],c,l,e,n];break;case"s":t[1]+=e,t[2]+=n,t[3]+=e,t[4]+=n;case"S":"C"===o?(c=2*e-c,l=2*n-l):(c=e,l=n),e=t[3],n=t[4],h=["C",c,l,t[1],t[2],e,n],c=h[3],l=h[4];break;case"q":t[1]+=e,t[2]+=n,t[3]+=e,t[4]+=n;case"Q":c=t[1],l=t[2],e=t[3],n=t[4],h=["Q",c,l,e,n];break;case"t":t[1]+=e,t[2]+=n;case"T":"Q"===o?(c=2*e-c,l=2*n-l):(c=e,l=n),e=t[1],n=t[2],h=["Q",c,l,e,n];break;case"a":t[6]+=e,t[7]+=n;case"A":M(e,n,t).forEach((t=>a.push(t))),e=t[6],n=t[7];break;case"z":case"Z":e=s,n=r,h=["Z"]}h?(a.push(h),o=h[0]):o=""}return a},b=(t,e,n,s)=>Math.sqrt((n-t)**2+(s-e)**2),w=(t,e,n,s,r,a,o,c)=>l=>{const i=l**3,m=(t=>3*t**2*(1-t))(l),u=(t=>3*t*(1-t)**2)(l),f=(t=>(1-t)**3)(l);return new h(o*i+r*m+n*u+t*f,c*i+a*m+s*u+e*f)},C=t=>t**2,j=t=>2*t*(1-t),k=t=>(1-t)**2,v=(t,e,n,s,r,a,o,c)=>l=>{const i=C(l),h=j(l),m=k(l),u=3*(m*(n-t)+h*(r-n)+i*(o-r)),f=3*(m*(s-e)+h*(a-s)+i*(c-a));return Math.atan2(f,u)},L=(t,e,n,s,r,a)=>o=>{const c=C(o),l=j(o),i=k(o);return new h(r*c+n*l+t*i,a*c+s*l+e*i)},q=(t,e,n,s,r,a)=>o=>{const c=1-o,l=2*(c*(n-t)+o*(r-n)),i=2*(c*(s-e)+o*(a-s));return Math.atan2(i,l)},Q=(t,e,n)=>{let s=new h(e,n),r=0;for(let e=1;e<=100;e+=1){const n=t(e/100);r+=b(s.x,s.y,n.x,n.y),s=n}return r},F=(e,n)=>{let s,r=0,a=0,o={x:e.x,y:e.y},c=t({},o),l=.01,i=0;const h=e.iterator,m=e.angleFinder;for(;a<n&&l>1e-4;)c=h(r),i=r,s=b(o.x,o.y,c.x,c.y),s+a>n?(r-=l,l/=2):(o=c,r+=l,a+=s);return t(t({},c),{},{angle:m(i)})},P=t=>{let e,n,s=0,r=0,a=0,o=0,c=0;const l=[];for(const i of t){const t={x:r,y:a,command:i[0],length:0};switch(i[0]){case"M":n=t,n.x=o=r=i[1],n.y=c=a=i[2];break;case"L":n=t,n.length=b(r,a,i[1],i[2]),r=i[1],a=i[2];break;case"C":e=w(r,a,i[1],i[2],i[3],i[4],i[5],i[6]),n=t,n.iterator=e,n.angleFinder=v(r,a,i[1],i[2],i[3],i[4],i[5],i[6]),n.length=Q(e,r,a),r=i[5],a=i[6];break;case"Q":e=L(r,a,i[1],i[2],i[3],i[4]),n=t,n.iterator=e,n.angleFinder=q(r,a,i[1],i[2],i[3],i[4]),n.length=Q(e,r,a),r=i[3],a=i[4];break;case"Z":n=t,n.destX=o,n.destY=c,n.length=b(r,a,o,c),r=o,a=c}s+=n.length,l.push(n)}return l.push({length:s,x:r,y:a}),l},Z=function(e,n){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:P(e),r=0;for(;n-s[r].length>0&&r<s.length-2;)n-=s[r].length,r++;const a=s[r],o=n/a.length,c=e[r];switch(a.command){case"M":return{x:a.x,y:a.y,angle:0};case"Z":return t(t({},new h(a.x,a.y).lerp(new h(a.destX,a.destY),o)),{},{angle:Math.atan2(a.destY-a.y,a.destX-a.x)});case"L":return t(t({},new h(a.x,a.y).lerp(new h(c[1],c[2]),o)),{},{angle:Math.atan2(c[2]-a.y,c[1]-a.x)});case"C":case"Q":return F(a,n)}},O=new RegExp(m,"gi"),A=new RegExp(u,"g"),E=new RegExp(f,"gi"),I={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},B=t=>{var e;const n=[],s=null!==(e=t.match(O))&&void 0!==e?e:[];for(const t of s){const e=t[0];if("z"===e||"Z"===e){n.push([e]);continue}const s=I[e.toLowerCase()];let r=[];if("a"===e||"A"===e){A.lastIndex=0;for(let e=null;e=A.exec(t);)r.push(...e.slice(1))}else r=t.match(E)||[];for(let t=0;t<r.length;t+=s){const a=new Array(s),o=x[e];a[0]=t>0&&o?o:e;for(let e=0;e<s;e++)a[e+1]=parseFloat(r[t+e]);n.push(a)}}return n},R=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=new h(t[0]),s=new h(t[1]),r=1,a=0;const o=[],c=t.length,l=c>2;let i;for(l&&(r=t[2].x<s.x?-1:t[2].x===s.x?0:1,a=t[2].y<s.y?-1:t[2].y===s.y?0:1),o.push(["M",n.x-r*e,n.y-a*e]),i=1;i<c;i++){if(!n.eq(s)){const t=n.midPointFrom(s);o.push(["Q",n.x,n.y,t.x,t.y])}n=t[i],i+1<t.length&&(s=t[i+1])}return l&&(r=n.x>t[i-2].x?1:n.x===t[i-2].x?0:-1,a=n.y>t[i-2].y?1:n.y===t[i-2].y?0:-1),o.push(["L",n.x+r*e,n.y+a*e]),o},X=(t,e,n)=>(n&&(e=o(e,[1,0,0,1,-n.x,-n.y])),t.map((t=>{const n=[...t];for(let s=1;s<t.length-1;s+=2){const{x:r,y:a}=c({x:t[s],y:t[s+1]},e);n[s]=r,n[s+1]=a}return n}))),Y=(t,e)=>{const n=2*Math.PI/t;let r=-s;t%2==0&&(r+=n/2);const o=new Array(t+1);for(let s=0;s<t;s++){const t=s*n+r,{x:c,y:i}=new h(a(t),l(t)).scalarMultiply(e);o[s]=[0===s?"M":"L",c,i]}return o[t]=["Z"],o},z=(t,e)=>t.map((t=>t.map(((t,n)=>0===n||void 0===e?t:i(t,e))).join(" "))).join(" ");export{M as fromArcToBeziers,y as getBoundsOfCurve,P as getPathSegmentsInfo,Z as getPointOnPath,Y as getRegularPolygonPath,R as getSmoothPathFromPoints,z as joinPath,d as makePathSimpler,B as parsePath,X as transformPath};
2
2
  //# sourceMappingURL=index.min.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.min.mjs","sources":["../../../../src/util/path/index.ts"],"sourcesContent":["import { cache } from '../../cache';\nimport { config } from '../../config';\nimport { halfPI, PiBy180 } from '../../constants';\nimport type { TMat2D, TRadian, TRectBounds } from '../../typedefs';\nimport { cos } from '../misc/cos';\nimport { multiplyTransformMatrices, transformPoint } from '../misc/matrix';\nimport { sin } from '../misc/sin';\nimport { toFixed } from '../misc/toFixed';\nimport type {\n TCurveInfo,\n TComplexPathData,\n TParsedAbsoluteCubicCurveCommand,\n TPathSegmentInfo,\n TPointAngle,\n TSimpleParsedCommand,\n TSimplePathData,\n TPathSegmentCommandInfo,\n TComplexParsedCommand,\n TPathSegmentInfoCommon,\n TEndPathInfo,\n TParsedArcCommand,\n} from './typedefs';\nimport type { XY } from '../../Point';\nimport { Point } from '../../Point';\nimport { rePathCommand } from './regex';\nimport { cleanupSvgAttribute } from '../internals/cleanupSvgAttribute';\n\n/**\n * Commands that may be repeated\n */\nconst repeatedCommands: Record<string, string | undefined> = {\n m: 'l',\n M: 'L',\n};\n\n/**\n * Convert an arc of a rotated ellipse to a Bezier Curve\n * @param {TRadian} theta1 start of the arc\n * @param {TRadian} theta2 end of the arc\n * @param cosTh cosine of the angle of rotation\n * @param sinTh sine of the angle of rotation\n * @param rx x-axis radius (before rotation)\n * @param ry y-axis radius (before rotation)\n * @param cx1 center x of the ellipse\n * @param cy1 center y of the ellipse\n * @param mT\n * @param fromX starting point of arc x\n * @param fromY starting point of arc y\n */\nconst segmentToBezier = (\n theta1: TRadian,\n theta2: TRadian,\n cosTh: number,\n sinTh: number,\n rx: number,\n ry: number,\n cx1: number,\n cy1: number,\n mT: number,\n fromX: number,\n fromY: number,\n): TParsedAbsoluteCubicCurveCommand => {\n const costh1 = cos(theta1),\n sinth1 = sin(theta1),\n costh2 = cos(theta2),\n sinth2 = sin(theta2),\n toX = cosTh * rx * costh2 - sinTh * ry * sinth2 + cx1,\n toY = sinTh * rx * costh2 + cosTh * ry * sinth2 + cy1,\n cp1X = fromX + mT * (-cosTh * rx * sinth1 - sinTh * ry * costh1),\n cp1Y = fromY + mT * (-sinTh * rx * sinth1 + cosTh * ry * costh1),\n cp2X = toX + mT * (cosTh * rx * sinth2 + sinTh * ry * costh2),\n cp2Y = toY + mT * (sinTh * rx * sinth2 - cosTh * ry * costh2);\n\n return ['C', cp1X, cp1Y, cp2X, cp2Y, toX, toY];\n};\n\n/**\n * Adapted from {@link http://dxr.mozilla.org/mozilla-central/source/dom/svg/SVGPathDataParser.cpp}\n * by Andrea Bogazzi code is under MPL. if you don't have a copy of the license you can take it here\n * http://mozilla.org/MPL/2.0/\n * @param toX\n * @param toY\n * @param rx\n * @param ry\n * @param {number} large 0 or 1 flag\n * @param {number} sweep 0 or 1 flag\n * @param rotateX\n */\nconst arcToSegments = (\n toX: number,\n toY: number,\n rx: number,\n ry: number,\n large: number,\n sweep: number,\n rotateX: TRadian,\n): TParsedAbsoluteCubicCurveCommand[] => {\n if (rx === 0 || ry === 0) {\n return [];\n }\n let fromX = 0,\n fromY = 0,\n root = 0;\n const PI = Math.PI,\n theta = rotateX * PiBy180,\n sinTheta = sin(theta),\n cosTh = cos(theta),\n px = 0.5 * (-cosTh * toX - sinTheta * toY),\n py = 0.5 * (-cosTh * toY + sinTheta * toX),\n rx2 = rx ** 2,\n ry2 = ry ** 2,\n py2 = py ** 2,\n px2 = px ** 2,\n pl = rx2 * ry2 - rx2 * py2 - ry2 * px2;\n let _rx = Math.abs(rx);\n let _ry = Math.abs(ry);\n\n if (pl < 0) {\n const s = Math.sqrt(1 - pl / (rx2 * ry2));\n _rx *= s;\n _ry *= s;\n } else {\n root =\n (large === sweep ? -1.0 : 1.0) * Math.sqrt(pl / (rx2 * py2 + ry2 * px2));\n }\n\n const cx = (root * _rx * py) / _ry,\n cy = (-root * _ry * px) / _rx,\n cx1 = cosTh * cx - sinTheta * cy + toX * 0.5,\n cy1 = sinTheta * cx + cosTh * cy + toY * 0.5;\n let mTheta = calcVectorAngle(1, 0, (px - cx) / _rx, (py - cy) / _ry);\n let dtheta = calcVectorAngle(\n (px - cx) / _rx,\n (py - cy) / _ry,\n (-px - cx) / _rx,\n (-py - cy) / _ry,\n );\n\n if (sweep === 0 && dtheta > 0) {\n dtheta -= 2 * PI;\n } else if (sweep === 1 && dtheta < 0) {\n dtheta += 2 * PI;\n }\n\n // Convert into cubic bezier segments <= 90deg\n const segments = Math.ceil(Math.abs((dtheta / PI) * 2)),\n result = [],\n mDelta = dtheta / segments,\n mT =\n ((8 / 3) * Math.sin(mDelta / 4) * Math.sin(mDelta / 4)) /\n Math.sin(mDelta / 2);\n let th3 = mTheta + mDelta;\n\n for (let i = 0; i < segments; i++) {\n result[i] = segmentToBezier(\n mTheta,\n th3,\n cosTh,\n sinTheta,\n _rx,\n _ry,\n cx1,\n cy1,\n mT,\n fromX,\n fromY,\n );\n fromX = result[i][5];\n fromY = result[i][6];\n mTheta = th3;\n th3 += mDelta;\n }\n return result;\n};\n\n/**\n * @private\n * Calculate the angle between two vectors\n * @param ux u endpoint x\n * @param uy u endpoint y\n * @param vx v endpoint x\n * @param vy v endpoint y\n */\nconst calcVectorAngle = (\n ux: number,\n uy: number,\n vx: number,\n vy: number,\n): TRadian => {\n const ta = Math.atan2(uy, ux),\n tb = Math.atan2(vy, vx);\n if (tb >= ta) {\n return tb - ta;\n } else {\n return 2 * Math.PI - (ta - tb);\n }\n};\n\n// functions for the Cubic beizer\n// taken from: https://github.com/konvajs/konva/blob/7.0.5/src/shapes/Path.ts#L350\nconst CB1 = (t: number) => t ** 3;\nconst CB2 = (t: number) => 3 * t ** 2 * (1 - t);\nconst CB3 = (t: number) => 3 * t * (1 - t) ** 2;\nconst CB4 = (t: number) => (1 - t) ** 3;\n\n/**\n * Calculate bounding box of a cubic Bezier curve\n * Taken from http://jsbin.com/ivomiq/56/edit (no credits available)\n * TODO: can we normalize this with the starting points set at 0 and then translated the bbox?\n * @param {number} begx starting point\n * @param {number} begy\n * @param {number} cp1x first control point\n * @param {number} cp1y\n * @param {number} cp2x second control point\n * @param {number} cp2y\n * @param {number} endx end of bezier\n * @param {number} endy\n * @return {TRectBounds} the rectangular bounds\n */\nexport function getBoundsOfCurve(\n begx: number,\n begy: number,\n cp1x: number,\n cp1y: number,\n cp2x: number,\n cp2y: number,\n endx: number,\n endy: number,\n): TRectBounds {\n let argsString: string;\n if (config.cachesBoundsOfCurve) {\n // eslint-disable-next-line\n argsString = [...arguments].join();\n if (cache.boundsOfCurveCache[argsString]) {\n return cache.boundsOfCurveCache[argsString];\n }\n }\n\n const sqrt = Math.sqrt,\n abs = Math.abs,\n tvalues = [],\n bounds: [[x: number, y: number], [x: number, y: number]] = [\n [0, 0],\n [0, 0],\n ];\n\n let b = 6 * begx - 12 * cp1x + 6 * cp2x;\n let a = -3 * begx + 9 * cp1x - 9 * cp2x + 3 * endx;\n let c = 3 * cp1x - 3 * begx;\n\n for (let i = 0; i < 2; ++i) {\n if (i > 0) {\n b = 6 * begy - 12 * cp1y + 6 * cp2y;\n a = -3 * begy + 9 * cp1y - 9 * cp2y + 3 * endy;\n c = 3 * cp1y - 3 * begy;\n }\n\n if (abs(a) < 1e-12) {\n if (abs(b) < 1e-12) {\n continue;\n }\n const t = -c / b;\n if (0 < t && t < 1) {\n tvalues.push(t);\n }\n continue;\n }\n const b2ac = b * b - 4 * c * a;\n if (b2ac < 0) {\n continue;\n }\n const sqrtb2ac = sqrt(b2ac);\n const t1 = (-b + sqrtb2ac) / (2 * a);\n if (0 < t1 && t1 < 1) {\n tvalues.push(t1);\n }\n const t2 = (-b - sqrtb2ac) / (2 * a);\n if (0 < t2 && t2 < 1) {\n tvalues.push(t2);\n }\n }\n\n let j = tvalues.length;\n const jlen = j;\n const iterator = getPointOnCubicBezierIterator(\n begx,\n begy,\n cp1x,\n cp1y,\n cp2x,\n cp2y,\n endx,\n endy,\n );\n while (j--) {\n const { x, y } = iterator(tvalues[j]);\n bounds[0][j] = x;\n bounds[1][j] = y;\n }\n\n bounds[0][jlen] = begx;\n bounds[1][jlen] = begy;\n bounds[0][jlen + 1] = endx;\n bounds[1][jlen + 1] = endy;\n const result: TRectBounds = [\n new Point(Math.min(...bounds[0]), Math.min(...bounds[1])),\n new Point(Math.max(...bounds[0]), Math.max(...bounds[1])),\n ];\n if (config.cachesBoundsOfCurve) {\n cache.boundsOfCurveCache[argsString!] = result;\n }\n return result;\n}\n\n/**\n * Converts arc to a bunch of cubic Bezier curves\n * @param {number} fx starting point x\n * @param {number} fy starting point y\n * @param {TParsedArcCommand} coords Arc command\n */\nexport const fromArcToBeziers = (\n fx: number,\n fy: number,\n [_, rx, ry, rot, large, sweep, tx, ty]: TParsedArcCommand,\n): TParsedAbsoluteCubicCurveCommand[] => {\n const segsNorm = arcToSegments(tx - fx, ty - fy, rx, ry, large, sweep, rot);\n\n for (let i = 0, len = segsNorm.length; i < len; i++) {\n segsNorm[i][1] += fx;\n segsNorm[i][2] += fy;\n segsNorm[i][3] += fx;\n segsNorm[i][4] += fy;\n segsNorm[i][5] += fx;\n segsNorm[i][6] += fy;\n }\n return segsNorm;\n};\n\n/**\n * This function takes a parsed SVG path and makes it simpler for fabricJS logic.\n * Simplification consist of:\n * - All commands converted to absolute (lowercase to uppercase)\n * - S converted to C\n * - T converted to Q\n * - A converted to C\n * @param {TComplexPathData} path the array of commands of a parsed SVG path for `Path`\n * @return {TSimplePathData} the simplified array of commands of a parsed SVG path for `Path`\n * TODO: figure out how to remove the type assertions in a nice way\n */\nexport const makePathSimpler = (path: TComplexPathData): TSimplePathData => {\n // x and y represent the last point of the path, AKA the previous command point.\n // we add them to each relative command to make it an absolute comment.\n // we also swap the v V h H with L, because are easier to transform.\n let x = 0,\n y = 0;\n // x1 and y1 represent the last point of the subpath. the subpath is started with\n // m or M command. When a z or Z command is drawn, x and y need to be resetted to\n // the last x1 and y1.\n let x1 = 0,\n y1 = 0;\n // previous will host the letter of the previous command, to handle S and T.\n // controlX and controlY will host the previous reflected control point\n const destinationPath: TSimplePathData = [];\n let previous,\n // placeholders\n controlX = 0,\n controlY = 0;\n for (const parsedCommand of path) {\n const current: TComplexParsedCommand = [...parsedCommand];\n let converted: TSimpleParsedCommand | undefined;\n switch (\n current[0] // first letter\n ) {\n case 'l': // lineto, relative\n current[1] += x;\n current[2] += y;\n // falls through\n case 'L':\n x = current[1];\n y = current[2];\n converted = ['L', x, y];\n break;\n case 'h': // horizontal lineto, relative\n current[1] += x;\n // falls through\n case 'H':\n x = current[1];\n converted = ['L', x, y];\n break;\n case 'v': // vertical lineto, relative\n current[1] += y;\n // falls through\n case 'V':\n y = current[1];\n converted = ['L', x, y];\n break;\n case 'm': // moveTo, relative\n current[1] += x;\n current[2] += y;\n // falls through\n case 'M':\n x = current[1];\n y = current[2];\n x1 = current[1];\n y1 = current[2];\n converted = ['M', x, y];\n break;\n case 'c': // bezierCurveTo, relative\n current[1] += x;\n current[2] += y;\n current[3] += x;\n current[4] += y;\n current[5] += x;\n current[6] += y;\n // falls through\n case 'C':\n controlX = current[3];\n controlY = current[4];\n x = current[5];\n y = current[6];\n converted = ['C', current[1], current[2], controlX, controlY, x, y];\n break;\n case 's': // shorthand cubic bezierCurveTo, relative\n current[1] += x;\n current[2] += y;\n current[3] += x;\n current[4] += y;\n // falls through\n case 'S':\n // would be sScC but since we are swapping sSc for C, we check just that.\n if (previous === 'C') {\n // calculate reflection of previous control points\n controlX = 2 * x - controlX;\n controlY = 2 * y - controlY;\n } else {\n // If there is no previous command or if the previous command was not a C, c, S, or s,\n // the control point is coincident with the current point\n controlX = x;\n controlY = y;\n }\n x = current[3];\n y = current[4];\n converted = ['C', controlX, controlY, current[1], current[2], x, y];\n // converted[3] and converted[4] are NOW the second control point.\n // we keep it for the next reflection.\n controlX = converted[3];\n controlY = converted[4];\n break;\n case 'q': // quadraticCurveTo, relative\n current[1] += x;\n current[2] += y;\n current[3] += x;\n current[4] += y;\n // falls through\n case 'Q':\n controlX = current[1];\n controlY = current[2];\n x = current[3];\n y = current[4];\n converted = ['Q', controlX, controlY, x, y];\n break;\n case 't': // shorthand quadraticCurveTo, relative\n current[1] += x;\n current[2] += y;\n // falls through\n case 'T':\n if (previous === 'Q') {\n // calculate reflection of previous control point\n controlX = 2 * x - controlX;\n controlY = 2 * y - controlY;\n } else {\n // If there is no previous command or if the previous command was not a Q, q, T or t,\n // assume the control point is coincident with the current point\n controlX = x;\n controlY = y;\n }\n x = current[1];\n y = current[2];\n converted = ['Q', controlX, controlY, x, y];\n break;\n case 'a':\n current[6] += x;\n current[7] += y;\n // falls through\n case 'A':\n fromArcToBeziers(x, y, current).forEach((b) => destinationPath.push(b));\n x = current[6];\n y = current[7];\n break;\n case 'z':\n case 'Z':\n x = x1;\n y = y1;\n converted = ['Z'];\n break;\n default:\n }\n if (converted) {\n destinationPath.push(converted);\n previous = converted[0];\n } else {\n previous = '';\n }\n }\n return destinationPath;\n};\n\n// todo verify if we can just use the point class here\n/**\n * Calc length from point x1,y1 to x2,y2\n * @param {number} x1 starting point x\n * @param {number} y1 starting point y\n * @param {number} x2 starting point x\n * @param {number} y2 starting point y\n * @return {number} length of segment\n */\nconst calcLineLength = (\n x1: number,\n y1: number,\n x2: number,\n y2: number,\n): number => Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2);\n\n/**\n * Get an iterator that takes a percentage and returns a point\n * @param {number} begx\n * @param {number} begy\n * @param {number} cp1x\n * @param {number} cp1y\n * @param {number} cp2x\n * @param {number} cp2y\n * @param {number} endx\n * @param {number} endy\n */\nconst getPointOnCubicBezierIterator =\n (\n begx: number,\n begy: number,\n cp1x: number,\n cp1y: number,\n cp2x: number,\n cp2y: number,\n endx: number,\n endy: number,\n ) =>\n (pct: number) => {\n const c1 = CB1(pct),\n c2 = CB2(pct),\n c3 = CB3(pct),\n c4 = CB4(pct);\n return new Point(\n endx * c1 + cp2x * c2 + cp1x * c3 + begx * c4,\n endy * c1 + cp2y * c2 + cp1y * c3 + begy * c4,\n );\n };\n\nconst QB1 = (t: number) => t ** 2;\nconst QB2 = (t: number) => 2 * t * (1 - t);\nconst QB3 = (t: number) => (1 - t) ** 2;\n\nconst getTangentCubicIterator =\n (\n p1x: number,\n p1y: number,\n p2x: number,\n p2y: number,\n p3x: number,\n p3y: number,\n p4x: number,\n p4y: number,\n ) =>\n (pct: number) => {\n const qb1 = QB1(pct),\n qb2 = QB2(pct),\n qb3 = QB3(pct),\n tangentX =\n 3 * (qb3 * (p2x - p1x) + qb2 * (p3x - p2x) + qb1 * (p4x - p3x)),\n tangentY =\n 3 * (qb3 * (p2y - p1y) + qb2 * (p3y - p2y) + qb1 * (p4y - p3y));\n return Math.atan2(tangentY, tangentX);\n };\n\nconst getPointOnQuadraticBezierIterator =\n (\n p1x: number,\n p1y: number,\n p2x: number,\n p2y: number,\n p3x: number,\n p3y: number,\n ) =>\n (pct: number) => {\n const c1 = QB1(pct),\n c2 = QB2(pct),\n c3 = QB3(pct);\n return new Point(\n p3x * c1 + p2x * c2 + p1x * c3,\n p3y * c1 + p2y * c2 + p1y * c3,\n );\n };\n\nconst getTangentQuadraticIterator =\n (\n p1x: number,\n p1y: number,\n p2x: number,\n p2y: number,\n p3x: number,\n p3y: number,\n ) =>\n (pct: number) => {\n const invT = 1 - pct,\n tangentX = 2 * (invT * (p2x - p1x) + pct * (p3x - p2x)),\n tangentY = 2 * (invT * (p2y - p1y) + pct * (p3y - p2y));\n return Math.atan2(tangentY, tangentX);\n };\n\n// this will run over a path segment (a cubic or quadratic segment) and approximate it\n// with 100 segments. This will good enough to calculate the length of the curve\nconst pathIterator = (\n iterator: (pct: number) => Point,\n x1: number,\n y1: number,\n) => {\n let tempP = new Point(x1, y1),\n tmpLen = 0;\n for (let perc = 1; perc <= 100; perc += 1) {\n const p = iterator(perc / 100);\n tmpLen += calcLineLength(tempP.x, tempP.y, p.x, p.y);\n tempP = p;\n }\n return tmpLen;\n};\n\n/**\n * Given a pathInfo, and a distance in pixels, find the percentage from 0 to 1\n * that correspond to that pixels run over the path.\n * The percentage will be then used to find the correct point on the canvas for the path.\n * @param {Array} segInfo fabricJS collection of information on a parsed path\n * @param {number} distance from starting point, in pixels.\n * @return {TPointAngle} info object with x and y ( the point on canvas ) and angle, the tangent on that point;\n */\nconst findPercentageForDistance = (\n segInfo: TCurveInfo<'Q' | 'C'>,\n distance: number,\n): TPointAngle => {\n let perc = 0,\n tmpLen = 0,\n tempP: XY = { x: segInfo.x, y: segInfo.y },\n p: XY = { ...tempP },\n nextLen: number,\n nextStep = 0.01,\n lastPerc = 0;\n // nextStep > 0.0001 covers 0.00015625 that 1/64th of 1/100\n // the path\n const iterator = segInfo.iterator,\n angleFinder = segInfo.angleFinder;\n while (tmpLen < distance && nextStep > 0.0001) {\n p = iterator(perc);\n lastPerc = perc;\n nextLen = calcLineLength(tempP.x, tempP.y, p.x, p.y);\n // compare tmpLen each cycle with distance, decide next perc to test.\n if (nextLen + tmpLen > distance) {\n // we discard this step and we make smaller steps.\n perc -= nextStep;\n nextStep /= 2;\n } else {\n tempP = p;\n perc += nextStep;\n tmpLen += nextLen;\n }\n }\n return { ...p, angle: angleFinder(lastPerc) };\n};\n\n/**\n * Run over a parsed and simplified path and extract some information (length of each command and starting point)\n * @param {TSimplePathData} path parsed path commands\n * @return {TPathSegmentInfo[]} path commands information\n */\nexport const getPathSegmentsInfo = (\n path: TSimplePathData,\n): TPathSegmentInfo[] => {\n let totalLength = 0,\n //x2 and y2 are the coords of segment start\n //x1 and y1 are the coords of the current point\n x1 = 0,\n y1 = 0,\n x2 = 0,\n y2 = 0,\n iterator,\n tempInfo: TPathSegmentInfo;\n const info: TPathSegmentInfo[] = [];\n for (const current of path) {\n const basicInfo: TPathSegmentInfoCommon<keyof TPathSegmentCommandInfo> = {\n x: x1,\n y: y1,\n command: current[0],\n length: 0,\n };\n switch (\n current[0] //first letter\n ) {\n case 'M':\n tempInfo = <TPathSegmentInfoCommon<'M'>>basicInfo;\n tempInfo.x = x2 = x1 = current[1];\n tempInfo.y = y2 = y1 = current[2];\n break;\n case 'L':\n tempInfo = <TPathSegmentInfoCommon<'L'>>basicInfo;\n tempInfo.length = calcLineLength(x1, y1, current[1], current[2]);\n x1 = current[1];\n y1 = current[2];\n break;\n case 'C':\n iterator = getPointOnCubicBezierIterator(\n x1,\n y1,\n current[1],\n current[2],\n current[3],\n current[4],\n current[5],\n current[6],\n );\n tempInfo = <TCurveInfo<'C'>>basicInfo;\n tempInfo.iterator = iterator;\n tempInfo.angleFinder = getTangentCubicIterator(\n x1,\n y1,\n current[1],\n current[2],\n current[3],\n current[4],\n current[5],\n current[6],\n );\n tempInfo.length = pathIterator(iterator, x1, y1);\n\n x1 = current[5];\n y1 = current[6];\n break;\n case 'Q':\n iterator = getPointOnQuadraticBezierIterator(\n x1,\n y1,\n current[1],\n current[2],\n current[3],\n current[4],\n );\n tempInfo = <TCurveInfo<'Q'>>basicInfo;\n tempInfo.iterator = iterator;\n tempInfo.angleFinder = getTangentQuadraticIterator(\n x1,\n y1,\n current[1],\n current[2],\n current[3],\n current[4],\n );\n tempInfo.length = pathIterator(iterator, x1, y1);\n x1 = current[3];\n y1 = current[4];\n break;\n case 'Z':\n // we add those in order to ease calculations later\n tempInfo = <TEndPathInfo>basicInfo;\n tempInfo.destX = x2;\n tempInfo.destY = y2;\n tempInfo.length = calcLineLength(x1, y1, x2, y2);\n x1 = x2;\n y1 = y2;\n break;\n }\n totalLength += tempInfo.length;\n info.push(tempInfo);\n }\n info.push({ length: totalLength, x: x1, y: y1 });\n return info;\n};\n\n/**\n * Get the point on the path that is distance along the path\n * @param path\n * @param distance\n * @param infos\n */\nexport const getPointOnPath = (\n path: TSimplePathData,\n distance: number,\n infos: TPathSegmentInfo[] = getPathSegmentsInfo(path),\n): TPointAngle | undefined => {\n let i = 0;\n while (distance - infos[i].length > 0 && i < infos.length - 2) {\n distance -= infos[i].length;\n i++;\n }\n const segInfo = infos[i],\n segPercent = distance / segInfo.length,\n segment = path[i];\n\n switch (segInfo.command) {\n case 'M':\n return { x: segInfo.x, y: segInfo.y, angle: 0 };\n case 'Z':\n return {\n ...new Point(segInfo.x, segInfo.y).lerp(\n new Point(segInfo.destX, segInfo.destY),\n segPercent,\n ),\n angle: Math.atan2(segInfo.destY - segInfo.y, segInfo.destX - segInfo.x),\n };\n case 'L':\n return {\n ...new Point(segInfo.x, segInfo.y).lerp(\n new Point(segment[1]!, segment[2]!),\n segPercent,\n ),\n angle: Math.atan2(segment[2]! - segInfo.y, segment[1]! - segInfo.x),\n };\n case 'C':\n return findPercentageForDistance(segInfo, distance);\n case 'Q':\n return findPercentageForDistance(segInfo, distance);\n default:\n // throw Error('Invalid command');\n }\n};\n\nconst rePathCmdAll = new RegExp(rePathCommand, 'gi');\nconst rePathCmd = new RegExp(rePathCommand, 'i');\n\n/**\n *\n * @param {string} pathString\n * @return {TComplexPathData} An array of SVG path commands\n * @example <caption>Usage</caption>\n * parsePath('M 3 4 Q 3 5 2 1 4 0 Q 9 12 2 1 4 0') === [\n * ['M', 3, 4],\n * ['Q', 3, 5, 2, 1, 4, 0],\n * ['Q', 9, 12, 2, 1, 4, 0],\n * ];\n */\nexport const parsePath = (pathString: string): TComplexPathData => {\n // clean the string\n // add spaces around the numbers\n pathString = cleanupSvgAttribute(pathString);\n\n const res: TComplexPathData = [];\n for (let [matchStr] of pathString.matchAll(rePathCmdAll)) {\n const chain: TComplexPathData = [];\n let paramArr: RegExpExecArray | null;\n do {\n paramArr = rePathCmd.exec(matchStr);\n if (!paramArr) {\n break;\n }\n // ignore undefined match groups\n const filteredGroups = paramArr.filter((g) => g);\n // remove the first element from the match array since it's just the whole command\n filteredGroups.shift();\n // if we can't parse the number, just interpret it as a string\n // (since it's probably the path command)\n const command = filteredGroups.map((g) => {\n const numParse = Number.parseFloat(g);\n if (Number.isNaN(numParse)) {\n return g;\n } else {\n return numParse;\n }\n });\n chain.push(command as any);\n // stop now if it's a z command\n if (filteredGroups.length <= 1) {\n break;\n }\n // remove the last part of the chained command\n filteredGroups.shift();\n // ` ?` is to support commands with optional spaces between flags\n matchStr = matchStr.replace(\n new RegExp(`${filteredGroups.join(' ?')} ?$`),\n '',\n );\n } while (paramArr);\n // add the chain, convert multiple m's to l's in the process\n chain.reverse().forEach((c, idx) => {\n const transformed = repeatedCommands[c[0]];\n if (idx > 0 && (transformed == 'l' || transformed == 'L')) {\n c[0] = transformed;\n }\n res.push(c);\n });\n }\n return res;\n};\n\n/**\n *\n * Converts points to a smooth SVG path\n * @param {XY[]} points Array of points\n * @param {number} [correction] Apply a correction to the path (usually we use `width / 1000`). If value is undefined 0 is used as the correction value.\n * @return {(string|number)[][]} An array of SVG path commands\n */\nexport const getSmoothPathFromPoints = (\n points: Point[],\n correction = 0,\n): TSimplePathData => {\n let p1 = new Point(points[0]),\n p2 = new Point(points[1]),\n multSignX = 1,\n multSignY = 0;\n const path: TSimplePathData = [],\n len = points.length,\n manyPoints = len > 2;\n\n if (manyPoints) {\n multSignX = points[2].x < p2.x ? -1 : points[2].x === p2.x ? 0 : 1;\n multSignY = points[2].y < p2.y ? -1 : points[2].y === p2.y ? 0 : 1;\n }\n path.push([\n 'M',\n p1.x - multSignX * correction,\n p1.y - multSignY * correction,\n ]);\n let i;\n for (i = 1; i < len; i++) {\n if (!p1.eq(p2)) {\n const midPoint = p1.midPointFrom(p2);\n // p1 is our bezier control point\n // midpoint is our endpoint\n // start point is p(i-1) value.\n path.push(['Q', p1.x, p1.y, midPoint.x, midPoint.y]);\n }\n p1 = points[i];\n if (i + 1 < points.length) {\n p2 = points[i + 1];\n }\n }\n if (manyPoints) {\n multSignX = p1.x > points[i - 2].x ? 1 : p1.x === points[i - 2].x ? 0 : -1;\n multSignY = p1.y > points[i - 2].y ? 1 : p1.y === points[i - 2].y ? 0 : -1;\n }\n path.push([\n 'L',\n p1.x + multSignX * correction,\n p1.y + multSignY * correction,\n ]);\n return path;\n};\n\n/**\n * Transform a path by transforming each segment.\n * it has to be a simplified path or it won't work.\n * WARNING: this depends from pathOffset for correct operation\n * @param {TSimplePathData} path fabricJS parsed and simplified path commands\n * @param {TMat2D} transform matrix that represent the transformation\n * @param {Point} [pathOffset] `Path.pathOffset`\n * @returns {TSimplePathData} the transformed path\n */\nexport const transformPath = (\n path: TSimplePathData,\n transform: TMat2D,\n pathOffset: Point,\n): TSimplePathData => {\n if (pathOffset) {\n transform = multiplyTransformMatrices(transform, [\n 1,\n 0,\n 0,\n 1,\n -pathOffset.x,\n -pathOffset.y,\n ]);\n }\n return path.map((pathSegment) => {\n const newSegment: TSimpleParsedCommand = [...pathSegment];\n for (let i = 1; i < pathSegment.length - 1; i += 2) {\n // TODO: is there a way to get around casting to any?\n const { x, y } = transformPoint(\n {\n x: pathSegment[i] as number,\n y: pathSegment[i + 1] as number,\n },\n transform,\n );\n newSegment[i] = x;\n newSegment[i + 1] = y;\n }\n return newSegment;\n });\n};\n\n/**\n * Returns an array of path commands to create a regular polygon\n * @param {number} numVertexes\n * @param {number} radius\n * @returns {TSimplePathData} An array of SVG path commands\n */\nexport const getRegularPolygonPath = (\n numVertexes: number,\n radius: number,\n): TSimplePathData => {\n const interiorAngle = (Math.PI * 2) / numVertexes;\n // rotationAdjustment rotates the path by 1/2 the interior angle so that the polygon always has a flat side on the bottom\n // This isn't strictly necessary, but it's how we tend to think of and expect polygons to be drawn\n let rotationAdjustment = -halfPI;\n if (numVertexes % 2 === 0) {\n rotationAdjustment += interiorAngle / 2;\n }\n const d = new Array(numVertexes + 1);\n for (let i = 0; i < numVertexes; i++) {\n const rad = i * interiorAngle + rotationAdjustment;\n const { x, y } = new Point(cos(rad), sin(rad)).scalarMultiply(radius);\n d[i] = [i === 0 ? 'M' : 'L', x, y];\n }\n d[numVertexes] = ['Z'];\n return d;\n};\n\n/**\n * Join path commands to go back to svg format\n * @param {TSimplePathData} pathData fabricJS parsed path commands\n * @param {number} fractionDigits number of fraction digits to \"leave\"\n * @return {String} joined path 'M 0 0 L 20 30'\n */\nexport const joinPath = (pathData: TSimplePathData, fractionDigits?: number) =>\n pathData\n .map((segment) => {\n return segment\n .map((arg, i) => {\n if (i === 0) return arg;\n return fractionDigits === undefined\n ? arg\n : toFixed(arg, fractionDigits);\n })\n .join(' ');\n })\n .join(' ');\n"],"names":["repeatedCommands","m","M","segmentToBezier","theta1","theta2","cosTh","sinTh","rx","ry","cx1","cy1","mT","fromX","fromY","costh1","cos","sinth1","sin","costh2","sinth2","toX","toY","calcVectorAngle","ux","uy","vx","vy","ta","Math","atan2","tb","PI","getBoundsOfCurve","begx","begy","cp1x","cp1y","cp2x","cp2y","endx","endy","argsString","config","cachesBoundsOfCurve","arguments","join","cache","boundsOfCurveCache","sqrt","abs","tvalues","bounds","b","a","c","i","t","push","b2ac","sqrtb2ac","t1","t2","j","length","jlen","iterator","getPointOnCubicBezierIterator","x","y","result","Point","min","max","fromArcToBeziers","fx","fy","_ref","_","rot","large","sweep","tx","ty","segsNorm","arcToSegments","rotateX","root","theta","PiBy180","sinTheta","px","py","rx2","ry2","py2","px2","pl","_rx","_ry","s","cx","cy","mTheta","dtheta","segments","ceil","mDelta","th3","len","makePathSimpler","path","x1","y1","destinationPath","previous","controlX","controlY","parsedCommand","current","converted","forEach","calcLineLength","x2","y2","pct","c1","c2","CB2","c3","CB3","c4","CB4","QB1","QB2","QB3","getTangentCubicIterator","p1x","p1y","p2x","p2y","p3x","p3y","p4x","p4y","qb1","qb2","qb3","tangentX","tangentY","getPointOnQuadraticBezierIterator","getTangentQuadraticIterator","invT","pathIterator","tempP","tmpLen","perc","p","findPercentageForDistance","segInfo","distance","nextLen","_objectSpread","nextStep","lastPerc","angleFinder","angle","getPathSegmentsInfo","tempInfo","totalLength","info","basicInfo","command","destX","destY","getPointOnPath","infos","undefined","segPercent","segment","lerp","rePathCmdAll","RegExp","rePathCommand","rePathCmd","parsePath","pathString","cleanupSvgAttribute","res","matchStr","matchAll","chain","paramArr","exec","filteredGroups","filter","g","shift","map","numParse","Number","parseFloat","isNaN","replace","concat","reverse","idx","transformed","getSmoothPathFromPoints","points","correction","p1","p2","multSignX","multSignY","manyPoints","eq","midPoint","midPointFrom","transformPath","transform","pathOffset","multiplyTransformMatrices","pathSegment","newSegment","transformPoint","getRegularPolygonPath","numVertexes","radius","interiorAngle","rotationAdjustment","halfPI","d","Array","rad","scalarMultiply","joinPath","pathData","fractionDigits","arg","toFixed"],"mappings":"onBA8BA,MAAMA,EAAuD,CAC3DC,EAAG,IACHC,EAAG,KAiBCC,EAAkBA,CACtBC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,KAEA,MAAMC,EAASC,EAAIZ,GACjBa,EAASC,EAAId,GACbe,EAASH,EAAIX,GACbe,EAASF,EAAIb,GACbgB,EAAMf,EAAQE,EAAKW,EAASZ,EAAQE,EAAKW,EAASV,EAClDY,EAAMf,EAAQC,EAAKW,EAASb,EAAQG,EAAKW,EAAST,EAMpD,MAAO,CAAC,IALCE,EAAQD,IAAON,EAAQE,EAAKS,EAASV,EAAQE,EAAKM,GAClDD,EAAQF,IAAOL,EAAQC,EAAKS,EAASX,EAAQG,EAAKM,GAClDM,EAAMT,GAAMN,EAAQE,EAAKY,EAASb,EAAQE,EAAKU,GAC/CG,EAAMV,GAAML,EAAQC,EAAKY,EAASd,EAAQG,EAAKU,GAEnBE,EAAKC,EAAI,EA8G1CC,EAAkBA,CACtBC,EACAC,EACAC,EACAC,KAEA,MAAMC,EAAKC,KAAKC,MAAML,EAAID,GACxBO,EAAKF,KAAKC,MAAMH,EAAID,GACtB,OAAIK,GAAMH,EACDG,EAAKH,EAEL,EAAIC,KAAKG,IAAMJ,EAAKG,EAC7B,EAwBK,SAASE,EACdC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,GAEA,IAAIC,EACJ,GAAIC,EAAOC,sBAETF,EAAa,IAAIG,WAAWC,OACxBC,EAAMC,mBAAmBN,IAC3B,OAAOK,EAAMC,mBAAmBN,GAIpC,MAAMO,EAAOpB,KAAKoB,KAChBC,EAAMrB,KAAKqB,IACXC,EAAU,GACVC,EAA2D,CACzD,CAAC,EAAG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AKG,GAAUmM,EAGtC,IAAIG,GAAsBC,EACtBJ,EAAc,GAAM,IACtBG,GAAsBD,EAAgB,GAExC,MAAMG,EAAI,IAAIC,MAAMN,EAAc,GAClC,IAAK,IAAI3K,EAAI,EAAGA,EAAI2K,EAAa3K,IAAK,CACpC,MAAMkL,EAAMlL,EAAI6K,EAAgBC,GAC1BlK,EAAEA,EAACC,EAAEA,GAAM,IAAIE,EAAMvD,EAAI0N,GAAMxN,EAAIwN,IAAMC,eAAeP,GAC9DI,EAAEhL,GAAK,CAAO,IAANA,EAAU,IAAM,IAAKY,EAAGC,EAClC,CAEA,OADAmK,EAAEL,GAAe,CAAC,KACXK,CAAC,EASGI,EAAWA,CAACC,EAA2BC,IAClDD,EACGvC,KAAKnB,GACGA,EACJmB,KAAI,CAACyC,EAAKvL,IACC,IAANA,QACsByH,IAAnB6D,EADaC,EAGhBC,EAAQD,EAAKD,KAElBhM,KAAK,OAETA,KAAK"}
1
+ {"version":3,"file":"index.min.mjs","sources":["../../../../src/util/path/index.ts"],"sourcesContent":["import { cache } from '../../cache';\nimport { config } from '../../config';\nimport { halfPI, PiBy180 } from '../../constants';\nimport type { TMat2D, TRadian, TRectBounds } from '../../typedefs';\nimport { cos } from '../misc/cos';\nimport { multiplyTransformMatrices, transformPoint } from '../misc/matrix';\nimport { sin } from '../misc/sin';\nimport { toFixed } from '../misc/toFixed';\nimport type {\n TCurveInfo,\n TComplexPathData,\n TParsedAbsoluteCubicCurveCommand,\n TPathSegmentInfo,\n TPointAngle,\n TSimpleParsedCommand,\n TSimplePathData,\n TPathSegmentCommandInfo,\n TComplexParsedCommand,\n TPathSegmentInfoCommon,\n TEndPathInfo,\n TParsedArcCommand,\n TComplexParsedCommandType,\n} from './typedefs';\nimport type { XY } from '../../Point';\nimport { Point } from '../../Point';\nimport { reArcCommandPoints, rePathCommand } from './regex';\nimport { reNum } from '../../parser/constants';\n\n/**\n * Commands that may be repeated\n */\nconst repeatedCommands: Record<string, 'l' | 'L'> = {\n m: 'l',\n M: 'L',\n};\n\n/**\n * Convert an arc of a rotated ellipse to a Bezier Curve\n * @param {TRadian} theta1 start of the arc\n * @param {TRadian} theta2 end of the arc\n * @param cosTh cosine of the angle of rotation\n * @param sinTh sine of the angle of rotation\n * @param rx x-axis radius (before rotation)\n * @param ry y-axis radius (before rotation)\n * @param cx1 center x of the ellipse\n * @param cy1 center y of the ellipse\n * @param mT\n * @param fromX starting point of arc x\n * @param fromY starting point of arc y\n */\nconst segmentToBezier = (\n theta1: TRadian,\n theta2: TRadian,\n cosTh: number,\n sinTh: number,\n rx: number,\n ry: number,\n cx1: number,\n cy1: number,\n mT: number,\n fromX: number,\n fromY: number,\n): TParsedAbsoluteCubicCurveCommand => {\n const costh1 = cos(theta1),\n sinth1 = sin(theta1),\n costh2 = cos(theta2),\n sinth2 = sin(theta2),\n toX = cosTh * rx * costh2 - sinTh * ry * sinth2 + cx1,\n toY = sinTh * rx * costh2 + cosTh * ry * sinth2 + cy1,\n cp1X = fromX + mT * (-cosTh * rx * sinth1 - sinTh * ry * costh1),\n cp1Y = fromY + mT * (-sinTh * rx * sinth1 + cosTh * ry * costh1),\n cp2X = toX + mT * (cosTh * rx * sinth2 + sinTh * ry * costh2),\n cp2Y = toY + mT * (sinTh * rx * sinth2 - cosTh * ry * costh2);\n\n return ['C', cp1X, cp1Y, cp2X, cp2Y, toX, toY];\n};\n\n/**\n * Adapted from {@link http://dxr.mozilla.org/mozilla-central/source/dom/svg/SVGPathDataParser.cpp}\n * by Andrea Bogazzi code is under MPL. if you don't have a copy of the license you can take it here\n * http://mozilla.org/MPL/2.0/\n * @param toX\n * @param toY\n * @param rx\n * @param ry\n * @param {number} large 0 or 1 flag\n * @param {number} sweep 0 or 1 flag\n * @param rotateX\n */\nconst arcToSegments = (\n toX: number,\n toY: number,\n rx: number,\n ry: number,\n large: number,\n sweep: number,\n rotateX: TRadian,\n): TParsedAbsoluteCubicCurveCommand[] => {\n if (rx === 0 || ry === 0) {\n return [];\n }\n let fromX = 0,\n fromY = 0,\n root = 0;\n const PI = Math.PI,\n theta = rotateX * PiBy180,\n sinTheta = sin(theta),\n cosTh = cos(theta),\n px = 0.5 * (-cosTh * toX - sinTheta * toY),\n py = 0.5 * (-cosTh * toY + sinTheta * toX),\n rx2 = rx ** 2,\n ry2 = ry ** 2,\n py2 = py ** 2,\n px2 = px ** 2,\n pl = rx2 * ry2 - rx2 * py2 - ry2 * px2;\n let _rx = Math.abs(rx);\n let _ry = Math.abs(ry);\n\n if (pl < 0) {\n const s = Math.sqrt(1 - pl / (rx2 * ry2));\n _rx *= s;\n _ry *= s;\n } else {\n root =\n (large === sweep ? -1.0 : 1.0) * Math.sqrt(pl / (rx2 * py2 + ry2 * px2));\n }\n\n const cx = (root * _rx * py) / _ry,\n cy = (-root * _ry * px) / _rx,\n cx1 = cosTh * cx - sinTheta * cy + toX * 0.5,\n cy1 = sinTheta * cx + cosTh * cy + toY * 0.5;\n let mTheta = calcVectorAngle(1, 0, (px - cx) / _rx, (py - cy) / _ry);\n let dtheta = calcVectorAngle(\n (px - cx) / _rx,\n (py - cy) / _ry,\n (-px - cx) / _rx,\n (-py - cy) / _ry,\n );\n\n if (sweep === 0 && dtheta > 0) {\n dtheta -= 2 * PI;\n } else if (sweep === 1 && dtheta < 0) {\n dtheta += 2 * PI;\n }\n\n // Convert into cubic bezier segments <= 90deg\n const segments = Math.ceil(Math.abs((dtheta / PI) * 2)),\n result = [],\n mDelta = dtheta / segments,\n mT =\n ((8 / 3) * Math.sin(mDelta / 4) * Math.sin(mDelta / 4)) /\n Math.sin(mDelta / 2);\n let th3 = mTheta + mDelta;\n\n for (let i = 0; i < segments; i++) {\n result[i] = segmentToBezier(\n mTheta,\n th3,\n cosTh,\n sinTheta,\n _rx,\n _ry,\n cx1,\n cy1,\n mT,\n fromX,\n fromY,\n );\n fromX = result[i][5];\n fromY = result[i][6];\n mTheta = th3;\n th3 += mDelta;\n }\n return result;\n};\n\n/**\n * @private\n * Calculate the angle between two vectors\n * @param ux u endpoint x\n * @param uy u endpoint y\n * @param vx v endpoint x\n * @param vy v endpoint y\n */\nconst calcVectorAngle = (\n ux: number,\n uy: number,\n vx: number,\n vy: number,\n): TRadian => {\n const ta = Math.atan2(uy, ux),\n tb = Math.atan2(vy, vx);\n if (tb >= ta) {\n return tb - ta;\n } else {\n return 2 * Math.PI - (ta - tb);\n }\n};\n\n// functions for the Cubic beizer\n// taken from: https://github.com/konvajs/konva/blob/7.0.5/src/shapes/Path.ts#L350\nconst CB1 = (t: number) => t ** 3;\nconst CB2 = (t: number) => 3 * t ** 2 * (1 - t);\nconst CB3 = (t: number) => 3 * t * (1 - t) ** 2;\nconst CB4 = (t: number) => (1 - t) ** 3;\n\n/**\n * Calculate bounding box of a cubic Bezier curve\n * Taken from http://jsbin.com/ivomiq/56/edit (no credits available)\n * TODO: can we normalize this with the starting points set at 0 and then translated the bbox?\n * @param {number} begx starting point\n * @param {number} begy\n * @param {number} cp1x first control point\n * @param {number} cp1y\n * @param {number} cp2x second control point\n * @param {number} cp2y\n * @param {number} endx end of bezier\n * @param {number} endy\n * @return {TRectBounds} the rectangular bounds\n */\nexport function getBoundsOfCurve(\n begx: number,\n begy: number,\n cp1x: number,\n cp1y: number,\n cp2x: number,\n cp2y: number,\n endx: number,\n endy: number,\n): TRectBounds {\n let argsString: string;\n if (config.cachesBoundsOfCurve) {\n // eslint-disable-next-line\n argsString = [...arguments].join();\n if (cache.boundsOfCurveCache[argsString]) {\n return cache.boundsOfCurveCache[argsString];\n }\n }\n\n const sqrt = Math.sqrt,\n abs = Math.abs,\n tvalues = [],\n bounds: [[x: number, y: number], [x: number, y: number]] = [\n [0, 0],\n [0, 0],\n ];\n\n let b = 6 * begx - 12 * cp1x + 6 * cp2x;\n let a = -3 * begx + 9 * cp1x - 9 * cp2x + 3 * endx;\n let c = 3 * cp1x - 3 * begx;\n\n for (let i = 0; i < 2; ++i) {\n if (i > 0) {\n b = 6 * begy - 12 * cp1y + 6 * cp2y;\n a = -3 * begy + 9 * cp1y - 9 * cp2y + 3 * endy;\n c = 3 * cp1y - 3 * begy;\n }\n\n if (abs(a) < 1e-12) {\n if (abs(b) < 1e-12) {\n continue;\n }\n const t = -c / b;\n if (0 < t && t < 1) {\n tvalues.push(t);\n }\n continue;\n }\n const b2ac = b * b - 4 * c * a;\n if (b2ac < 0) {\n continue;\n }\n const sqrtb2ac = sqrt(b2ac);\n const t1 = (-b + sqrtb2ac) / (2 * a);\n if (0 < t1 && t1 < 1) {\n tvalues.push(t1);\n }\n const t2 = (-b - sqrtb2ac) / (2 * a);\n if (0 < t2 && t2 < 1) {\n tvalues.push(t2);\n }\n }\n\n let j = tvalues.length;\n const jlen = j;\n const iterator = getPointOnCubicBezierIterator(\n begx,\n begy,\n cp1x,\n cp1y,\n cp2x,\n cp2y,\n endx,\n endy,\n );\n while (j--) {\n const { x, y } = iterator(tvalues[j]);\n bounds[0][j] = x;\n bounds[1][j] = y;\n }\n\n bounds[0][jlen] = begx;\n bounds[1][jlen] = begy;\n bounds[0][jlen + 1] = endx;\n bounds[1][jlen + 1] = endy;\n const result: TRectBounds = [\n new Point(Math.min(...bounds[0]), Math.min(...bounds[1])),\n new Point(Math.max(...bounds[0]), Math.max(...bounds[1])),\n ];\n if (config.cachesBoundsOfCurve) {\n cache.boundsOfCurveCache[argsString!] = result;\n }\n return result;\n}\n\n/**\n * Converts arc to a bunch of cubic Bezier curves\n * @param {number} fx starting point x\n * @param {number} fy starting point y\n * @param {TParsedArcCommand} coords Arc command\n */\nexport const fromArcToBeziers = (\n fx: number,\n fy: number,\n [_, rx, ry, rot, large, sweep, tx, ty]: TParsedArcCommand,\n): TParsedAbsoluteCubicCurveCommand[] => {\n const segsNorm = arcToSegments(tx - fx, ty - fy, rx, ry, large, sweep, rot);\n\n for (let i = 0, len = segsNorm.length; i < len; i++) {\n segsNorm[i][1] += fx;\n segsNorm[i][2] += fy;\n segsNorm[i][3] += fx;\n segsNorm[i][4] += fy;\n segsNorm[i][5] += fx;\n segsNorm[i][6] += fy;\n }\n return segsNorm;\n};\n\n/**\n * This function takes a parsed SVG path and makes it simpler for fabricJS logic.\n * Simplification consist of:\n * - All commands converted to absolute (lowercase to uppercase)\n * - S converted to C\n * - T converted to Q\n * - A converted to C\n * @param {TComplexPathData} path the array of commands of a parsed SVG path for `Path`\n * @return {TSimplePathData} the simplified array of commands of a parsed SVG path for `Path`\n * TODO: figure out how to remove the type assertions in a nice way\n */\nexport const makePathSimpler = (path: TComplexPathData): TSimplePathData => {\n // x and y represent the last point of the path, AKA the previous command point.\n // we add them to each relative command to make it an absolute comment.\n // we also swap the v V h H with L, because are easier to transform.\n let x = 0,\n y = 0;\n // x1 and y1 represent the last point of the subpath. the subpath is started with\n // m or M command. When a z or Z command is drawn, x and y need to be resetted to\n // the last x1 and y1.\n let x1 = 0,\n y1 = 0;\n // previous will host the letter of the previous command, to handle S and T.\n // controlX and controlY will host the previous reflected control point\n const destinationPath: TSimplePathData = [];\n let previous,\n // placeholders\n controlX = 0,\n controlY = 0;\n for (const parsedCommand of path) {\n const current: TComplexParsedCommand = [...parsedCommand];\n let converted: TSimpleParsedCommand | undefined;\n switch (\n current[0] // first letter\n ) {\n case 'l': // lineto, relative\n current[1] += x;\n current[2] += y;\n // falls through\n case 'L':\n x = current[1];\n y = current[2];\n converted = ['L', x, y];\n break;\n case 'h': // horizontal lineto, relative\n current[1] += x;\n // falls through\n case 'H':\n x = current[1];\n converted = ['L', x, y];\n break;\n case 'v': // vertical lineto, relative\n current[1] += y;\n // falls through\n case 'V':\n y = current[1];\n converted = ['L', x, y];\n break;\n case 'm': // moveTo, relative\n current[1] += x;\n current[2] += y;\n // falls through\n case 'M':\n x = current[1];\n y = current[2];\n x1 = current[1];\n y1 = current[2];\n converted = ['M', x, y];\n break;\n case 'c': // bezierCurveTo, relative\n current[1] += x;\n current[2] += y;\n current[3] += x;\n current[4] += y;\n current[5] += x;\n current[6] += y;\n // falls through\n case 'C':\n controlX = current[3];\n controlY = current[4];\n x = current[5];\n y = current[6];\n converted = ['C', current[1], current[2], controlX, controlY, x, y];\n break;\n case 's': // shorthand cubic bezierCurveTo, relative\n current[1] += x;\n current[2] += y;\n current[3] += x;\n current[4] += y;\n // falls through\n case 'S':\n // would be sScC but since we are swapping sSc for C, we check just that.\n if (previous === 'C') {\n // calculate reflection of previous control points\n controlX = 2 * x - controlX;\n controlY = 2 * y - controlY;\n } else {\n // If there is no previous command or if the previous command was not a C, c, S, or s,\n // the control point is coincident with the current point\n controlX = x;\n controlY = y;\n }\n x = current[3];\n y = current[4];\n converted = ['C', controlX, controlY, current[1], current[2], x, y];\n // converted[3] and converted[4] are NOW the second control point.\n // we keep it for the next reflection.\n controlX = converted[3];\n controlY = converted[4];\n break;\n case 'q': // quadraticCurveTo, relative\n current[1] += x;\n current[2] += y;\n current[3] += x;\n current[4] += y;\n // falls through\n case 'Q':\n controlX = current[1];\n controlY = current[2];\n x = current[3];\n y = current[4];\n converted = ['Q', controlX, controlY, x, y];\n break;\n case 't': // shorthand quadraticCurveTo, relative\n current[1] += x;\n current[2] += y;\n // falls through\n case 'T':\n if (previous === 'Q') {\n // calculate reflection of previous control point\n controlX = 2 * x - controlX;\n controlY = 2 * y - controlY;\n } else {\n // If there is no previous command or if the previous command was not a Q, q, T or t,\n // assume the control point is coincident with the current point\n controlX = x;\n controlY = y;\n }\n x = current[1];\n y = current[2];\n converted = ['Q', controlX, controlY, x, y];\n break;\n case 'a':\n current[6] += x;\n current[7] += y;\n // falls through\n case 'A':\n fromArcToBeziers(x, y, current).forEach((b) => destinationPath.push(b));\n x = current[6];\n y = current[7];\n break;\n case 'z':\n case 'Z':\n x = x1;\n y = y1;\n converted = ['Z'];\n break;\n default:\n }\n if (converted) {\n destinationPath.push(converted);\n previous = converted[0];\n } else {\n previous = '';\n }\n }\n return destinationPath;\n};\n\n// todo verify if we can just use the point class here\n/**\n * Calc length from point x1,y1 to x2,y2\n * @param {number} x1 starting point x\n * @param {number} y1 starting point y\n * @param {number} x2 starting point x\n * @param {number} y2 starting point y\n * @return {number} length of segment\n */\nconst calcLineLength = (\n x1: number,\n y1: number,\n x2: number,\n y2: number,\n): number => Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2);\n\n/**\n * Get an iterator that takes a percentage and returns a point\n * @param {number} begx\n * @param {number} begy\n * @param {number} cp1x\n * @param {number} cp1y\n * @param {number} cp2x\n * @param {number} cp2y\n * @param {number} endx\n * @param {number} endy\n */\nconst getPointOnCubicBezierIterator =\n (\n begx: number,\n begy: number,\n cp1x: number,\n cp1y: number,\n cp2x: number,\n cp2y: number,\n endx: number,\n endy: number,\n ) =>\n (pct: number) => {\n const c1 = CB1(pct),\n c2 = CB2(pct),\n c3 = CB3(pct),\n c4 = CB4(pct);\n return new Point(\n endx * c1 + cp2x * c2 + cp1x * c3 + begx * c4,\n endy * c1 + cp2y * c2 + cp1y * c3 + begy * c4,\n );\n };\n\nconst QB1 = (t: number) => t ** 2;\nconst QB2 = (t: number) => 2 * t * (1 - t);\nconst QB3 = (t: number) => (1 - t) ** 2;\n\nconst getTangentCubicIterator =\n (\n p1x: number,\n p1y: number,\n p2x: number,\n p2y: number,\n p3x: number,\n p3y: number,\n p4x: number,\n p4y: number,\n ) =>\n (pct: number) => {\n const qb1 = QB1(pct),\n qb2 = QB2(pct),\n qb3 = QB3(pct),\n tangentX =\n 3 * (qb3 * (p2x - p1x) + qb2 * (p3x - p2x) + qb1 * (p4x - p3x)),\n tangentY =\n 3 * (qb3 * (p2y - p1y) + qb2 * (p3y - p2y) + qb1 * (p4y - p3y));\n return Math.atan2(tangentY, tangentX);\n };\n\nconst getPointOnQuadraticBezierIterator =\n (\n p1x: number,\n p1y: number,\n p2x: number,\n p2y: number,\n p3x: number,\n p3y: number,\n ) =>\n (pct: number) => {\n const c1 = QB1(pct),\n c2 = QB2(pct),\n c3 = QB3(pct);\n return new Point(\n p3x * c1 + p2x * c2 + p1x * c3,\n p3y * c1 + p2y * c2 + p1y * c3,\n );\n };\n\nconst getTangentQuadraticIterator =\n (\n p1x: number,\n p1y: number,\n p2x: number,\n p2y: number,\n p3x: number,\n p3y: number,\n ) =>\n (pct: number) => {\n const invT = 1 - pct,\n tangentX = 2 * (invT * (p2x - p1x) + pct * (p3x - p2x)),\n tangentY = 2 * (invT * (p2y - p1y) + pct * (p3y - p2y));\n return Math.atan2(tangentY, tangentX);\n };\n\n// this will run over a path segment (a cubic or quadratic segment) and approximate it\n// with 100 segments. This will good enough to calculate the length of the curve\nconst pathIterator = (\n iterator: (pct: number) => Point,\n x1: number,\n y1: number,\n) => {\n let tempP = new Point(x1, y1),\n tmpLen = 0;\n for (let perc = 1; perc <= 100; perc += 1) {\n const p = iterator(perc / 100);\n tmpLen += calcLineLength(tempP.x, tempP.y, p.x, p.y);\n tempP = p;\n }\n return tmpLen;\n};\n\n/**\n * Given a pathInfo, and a distance in pixels, find the percentage from 0 to 1\n * that correspond to that pixels run over the path.\n * The percentage will be then used to find the correct point on the canvas for the path.\n * @param {Array} segInfo fabricJS collection of information on a parsed path\n * @param {number} distance from starting point, in pixels.\n * @return {TPointAngle} info object with x and y ( the point on canvas ) and angle, the tangent on that point;\n */\nconst findPercentageForDistance = (\n segInfo: TCurveInfo<'Q' | 'C'>,\n distance: number,\n): TPointAngle => {\n let perc = 0,\n tmpLen = 0,\n tempP: XY = { x: segInfo.x, y: segInfo.y },\n p: XY = { ...tempP },\n nextLen: number,\n nextStep = 0.01,\n lastPerc = 0;\n // nextStep > 0.0001 covers 0.00015625 that 1/64th of 1/100\n // the path\n const iterator = segInfo.iterator,\n angleFinder = segInfo.angleFinder;\n while (tmpLen < distance && nextStep > 0.0001) {\n p = iterator(perc);\n lastPerc = perc;\n nextLen = calcLineLength(tempP.x, tempP.y, p.x, p.y);\n // compare tmpLen each cycle with distance, decide next perc to test.\n if (nextLen + tmpLen > distance) {\n // we discard this step and we make smaller steps.\n perc -= nextStep;\n nextStep /= 2;\n } else {\n tempP = p;\n perc += nextStep;\n tmpLen += nextLen;\n }\n }\n return { ...p, angle: angleFinder(lastPerc) };\n};\n\n/**\n * Run over a parsed and simplified path and extract some information (length of each command and starting point)\n * @param {TSimplePathData} path parsed path commands\n * @return {TPathSegmentInfo[]} path commands information\n */\nexport const getPathSegmentsInfo = (\n path: TSimplePathData,\n): TPathSegmentInfo[] => {\n let totalLength = 0,\n //x2 and y2 are the coords of segment start\n //x1 and y1 are the coords of the current point\n x1 = 0,\n y1 = 0,\n x2 = 0,\n y2 = 0,\n iterator,\n tempInfo: TPathSegmentInfo;\n const info: TPathSegmentInfo[] = [];\n for (const current of path) {\n const basicInfo: TPathSegmentInfoCommon<keyof TPathSegmentCommandInfo> = {\n x: x1,\n y: y1,\n command: current[0],\n length: 0,\n };\n switch (\n current[0] //first letter\n ) {\n case 'M':\n tempInfo = <TPathSegmentInfoCommon<'M'>>basicInfo;\n tempInfo.x = x2 = x1 = current[1];\n tempInfo.y = y2 = y1 = current[2];\n break;\n case 'L':\n tempInfo = <TPathSegmentInfoCommon<'L'>>basicInfo;\n tempInfo.length = calcLineLength(x1, y1, current[1], current[2]);\n x1 = current[1];\n y1 = current[2];\n break;\n case 'C':\n iterator = getPointOnCubicBezierIterator(\n x1,\n y1,\n current[1],\n current[2],\n current[3],\n current[4],\n current[5],\n current[6],\n );\n tempInfo = <TCurveInfo<'C'>>basicInfo;\n tempInfo.iterator = iterator;\n tempInfo.angleFinder = getTangentCubicIterator(\n x1,\n y1,\n current[1],\n current[2],\n current[3],\n current[4],\n current[5],\n current[6],\n );\n tempInfo.length = pathIterator(iterator, x1, y1);\n\n x1 = current[5];\n y1 = current[6];\n break;\n case 'Q':\n iterator = getPointOnQuadraticBezierIterator(\n x1,\n y1,\n current[1],\n current[2],\n current[3],\n current[4],\n );\n tempInfo = <TCurveInfo<'Q'>>basicInfo;\n tempInfo.iterator = iterator;\n tempInfo.angleFinder = getTangentQuadraticIterator(\n x1,\n y1,\n current[1],\n current[2],\n current[3],\n current[4],\n );\n tempInfo.length = pathIterator(iterator, x1, y1);\n x1 = current[3];\n y1 = current[4];\n break;\n case 'Z':\n // we add those in order to ease calculations later\n tempInfo = <TEndPathInfo>basicInfo;\n tempInfo.destX = x2;\n tempInfo.destY = y2;\n tempInfo.length = calcLineLength(x1, y1, x2, y2);\n x1 = x2;\n y1 = y2;\n break;\n }\n totalLength += tempInfo.length;\n info.push(tempInfo);\n }\n info.push({ length: totalLength, x: x1, y: y1 });\n return info;\n};\n\n/**\n * Get the point on the path that is distance along the path\n * @param path\n * @param distance\n * @param infos\n */\nexport const getPointOnPath = (\n path: TSimplePathData,\n distance: number,\n infos: TPathSegmentInfo[] = getPathSegmentsInfo(path),\n): TPointAngle | undefined => {\n let i = 0;\n while (distance - infos[i].length > 0 && i < infos.length - 2) {\n distance -= infos[i].length;\n i++;\n }\n const segInfo = infos[i],\n segPercent = distance / segInfo.length,\n segment = path[i];\n\n switch (segInfo.command) {\n case 'M':\n return { x: segInfo.x, y: segInfo.y, angle: 0 };\n case 'Z':\n return {\n ...new Point(segInfo.x, segInfo.y).lerp(\n new Point(segInfo.destX, segInfo.destY),\n segPercent,\n ),\n angle: Math.atan2(segInfo.destY - segInfo.y, segInfo.destX - segInfo.x),\n };\n case 'L':\n return {\n ...new Point(segInfo.x, segInfo.y).lerp(\n new Point(segment[1]!, segment[2]!),\n segPercent,\n ),\n angle: Math.atan2(segment[2]! - segInfo.y, segment[1]! - segInfo.x),\n };\n case 'C':\n return findPercentageForDistance(segInfo, distance);\n case 'Q':\n return findPercentageForDistance(segInfo, distance);\n default:\n // throw Error('Invalid command');\n }\n};\n\nconst rePathCmdAll = new RegExp(rePathCommand, 'gi');\nconst regExpArcCommandPoints = new RegExp(reArcCommandPoints, 'g');\nconst reMyNum = new RegExp(reNum, 'gi');\nconst commandLengths = {\n m: 2,\n l: 2,\n h: 1,\n v: 1,\n c: 6,\n s: 4,\n q: 4,\n t: 2,\n a: 7,\n} as const;\n/**\n *\n * @param {string} pathString\n * @return {TComplexPathData} An array of SVG path commands\n * @example <caption>Usage</caption>\n * parsePath('M 3 4 Q 3 5 2 1 4 0 Q 9 12 2 1 4 0') === [\n * ['M', 3, 4],\n * ['Q', 3, 5, 2, 1, 4, 0],\n * ['Q', 9, 12, 2, 1, 4, 0],\n * ];\n */\nexport const parsePath = (pathString: string): TComplexPathData => {\n const chain: TComplexPathData = [];\n const all = pathString.match(rePathCmdAll) ?? [];\n for (const matchStr of all) {\n // take match string and save the first letter as the command\n const commandLetter = matchStr[0] as TComplexParsedCommandType;\n // in case of Z we have very little to do\n if (commandLetter === 'z' || commandLetter === 'Z') {\n chain.push([commandLetter]);\n continue;\n }\n const commandLength =\n commandLengths[\n commandLetter.toLowerCase() as keyof typeof commandLengths\n ];\n\n let paramArr = [];\n if (commandLetter === 'a' || commandLetter === 'A') {\n // the arc command ha some peculariaties that requires a special regex other than numbers\n // it is possible to avoid using a space between the sweep and large arc flags, making them either\n // 00, 01, 10 or 11, making them identical to a plain number for the regex reMyNum\n // reset the regexp\n regExpArcCommandPoints.lastIndex = 0;\n for (let out = null; (out = regExpArcCommandPoints.exec(matchStr)); ) {\n paramArr.push(...out.slice(1));\n }\n } else {\n paramArr = matchStr.match(reMyNum) || [];\n }\n\n // inspect the length of paramArr, if is longer than commandLength\n // we are dealing with repeated commands\n for (let i = 0; i < paramArr.length; i += commandLength) {\n const newCommand = new Array(commandLength) as TComplexParsedCommand;\n const transformedCommand = repeatedCommands[commandLetter];\n newCommand[0] =\n i > 0 && transformedCommand ? transformedCommand : commandLetter;\n for (let j = 0; j < commandLength; j++) {\n newCommand[j + 1] = parseFloat(paramArr[i + j]);\n }\n chain.push(newCommand);\n }\n }\n return chain;\n};\n\n/**\n *\n * Converts points to a smooth SVG path\n * @param {XY[]} points Array of points\n * @param {number} [correction] Apply a correction to the path (usually we use `width / 1000`). If value is undefined 0 is used as the correction value.\n * @return {(string|number)[][]} An array of SVG path commands\n */\nexport const getSmoothPathFromPoints = (\n points: Point[],\n correction = 0,\n): TSimplePathData => {\n let p1 = new Point(points[0]),\n p2 = new Point(points[1]),\n multSignX = 1,\n multSignY = 0;\n const path: TSimplePathData = [],\n len = points.length,\n manyPoints = len > 2;\n\n if (manyPoints) {\n multSignX = points[2].x < p2.x ? -1 : points[2].x === p2.x ? 0 : 1;\n multSignY = points[2].y < p2.y ? -1 : points[2].y === p2.y ? 0 : 1;\n }\n path.push([\n 'M',\n p1.x - multSignX * correction,\n p1.y - multSignY * correction,\n ]);\n let i;\n for (i = 1; i < len; i++) {\n if (!p1.eq(p2)) {\n const midPoint = p1.midPointFrom(p2);\n // p1 is our bezier control point\n // midpoint is our endpoint\n // start point is p(i-1) value.\n path.push(['Q', p1.x, p1.y, midPoint.x, midPoint.y]);\n }\n p1 = points[i];\n if (i + 1 < points.length) {\n p2 = points[i + 1];\n }\n }\n if (manyPoints) {\n multSignX = p1.x > points[i - 2].x ? 1 : p1.x === points[i - 2].x ? 0 : -1;\n multSignY = p1.y > points[i - 2].y ? 1 : p1.y === points[i - 2].y ? 0 : -1;\n }\n path.push([\n 'L',\n p1.x + multSignX * correction,\n p1.y + multSignY * correction,\n ]);\n return path;\n};\n\n/**\n * Transform a path by transforming each segment.\n * it has to be a simplified path or it won't work.\n * WARNING: this depends from pathOffset for correct operation\n * @param {TSimplePathData} path fabricJS parsed and simplified path commands\n * @param {TMat2D} transform matrix that represent the transformation\n * @param {Point} [pathOffset] `Path.pathOffset`\n * @returns {TSimplePathData} the transformed path\n */\nexport const transformPath = (\n path: TSimplePathData,\n transform: TMat2D,\n pathOffset: Point,\n): TSimplePathData => {\n if (pathOffset) {\n transform = multiplyTransformMatrices(transform, [\n 1,\n 0,\n 0,\n 1,\n -pathOffset.x,\n -pathOffset.y,\n ]);\n }\n return path.map((pathSegment) => {\n const newSegment: TSimpleParsedCommand = [...pathSegment];\n for (let i = 1; i < pathSegment.length - 1; i += 2) {\n // TODO: is there a way to get around casting to any?\n const { x, y } = transformPoint(\n {\n x: pathSegment[i] as number,\n y: pathSegment[i + 1] as number,\n },\n transform,\n );\n newSegment[i] = x;\n newSegment[i + 1] = y;\n }\n return newSegment;\n });\n};\n\n/**\n * Returns an array of path commands to create a regular polygon\n * @param {number} numVertexes\n * @param {number} radius\n * @returns {TSimplePathData} An array of SVG path commands\n */\nexport const getRegularPolygonPath = (\n numVertexes: number,\n radius: number,\n): TSimplePathData => {\n const interiorAngle = (Math.PI * 2) / numVertexes;\n // rotationAdjustment rotates the path by 1/2 the interior angle so that the polygon always has a flat side on the bottom\n // This isn't strictly necessary, but it's how we tend to think of and expect polygons to be drawn\n let rotationAdjustment = -halfPI;\n if (numVertexes % 2 === 0) {\n rotationAdjustment += interiorAngle / 2;\n }\n const d = new Array(numVertexes + 1);\n for (let i = 0; i < numVertexes; i++) {\n const rad = i * interiorAngle + rotationAdjustment;\n const { x, y } = new Point(cos(rad), sin(rad)).scalarMultiply(radius);\n d[i] = [i === 0 ? 'M' : 'L', x, y];\n }\n d[numVertexes] = ['Z'];\n return d;\n};\n\n/**\n * Join path commands to go back to svg format\n * @param {TSimplePathData} pathData fabricJS parsed path commands\n * @param {number} fractionDigits number of fraction digits to \"leave\"\n * @return {String} joined path 'M 0 0 L 20 30'\n */\nexport const joinPath = (pathData: TSimplePathData, fractionDigits?: number) =>\n pathData\n .map((segment) => {\n return segment\n .map((arg, i) => {\n if (i === 0) return arg;\n return fractionDigits === undefined\n ? arg\n : toFixed(arg, fractionDigits);\n })\n .join(' ');\n })\n .join(' ');\n"],"names":["repeatedCommands","m","M","segmentToBezier","theta1","theta2","cosTh","sinTh","rx","ry","cx1","cy1","mT","fromX","fromY","costh1","cos","sinth1","sin","costh2","sinth2","toX","toY","calcVectorAngle","ux","uy","vx","vy","ta","Math","atan2","tb","PI","getBoundsOfCurve","begx","begy","cp1x","cp1y","cp2x","cp2y","endx","endy","argsString","config","cachesBoundsOfCurve","arguments","join","cache","boundsOfCurveCache","sqrt","abs","tvalues","bounds","b","a","c","i","t","push","b2ac","sqrtb2ac","t1","t2","j","length","jlen","iterator","getPointOnCubicBezierIterator","x","y","result","Point","min","max","fromArcToBeziers","fx","fy","_ref","_","rot","large","sweep","tx","ty","segsNorm","arcToSegments","rotateX","root","theta","PiBy180","sinTheta","px","py","rx2","ry2","py2","px2","pl","_rx","_ry","s","cx","cy","mTheta","dtheta","segments","ceil","mDelta","th3","len","makePathSimpler","path","x1","y1","destinationPath","previous","controlX","controlY","parsedCommand","current","converted","forEach","calcLineLength","x2","y2","pct","c1","c2","CB2","c3","CB3","c4","CB4","QB1","QB2","QB3","getTangentCubicIterator","p1x","p1y","p2x","p2y","p3x","p3y","p4x","p4y","qb1","qb2","qb3","tangentX","tangentY","getPointOnQuadraticBezierIterator","getTangentQuadraticIterator","invT","pathIterator","tempP","tmpLen","perc","p","findPercentageForDistance","segInfo","distance","nextLen","_objectSpread","nextStep","lastPerc","angleFinder","angle","getPathSegmentsInfo","tempInfo","totalLength","info","basicInfo","command","destX","destY","getPointOnPath","infos","undefined","segPercent","segment","lerp","rePathCmdAll","RegExp","rePathCommand","regExpArcCommandPoints","reArcCommandPoints","reMyNum","reNum","commandLengths","l","h","v","q","parsePath","pathString","_pathString$match","chain","all","match","matchStr","commandLetter","commandLength","toLowerCase","paramArr","lastIndex","out","exec","slice","newCommand","Array","transformedCommand","parseFloat","getSmoothPathFromPoints","points","correction","p1","p2","multSignX","multSignY","manyPoints","eq","midPoint","midPointFrom","transformPath","transform","pathOffset","multiplyTransformMatrices","map","pathSegment","newSegment","transformPoint","getRegularPolygonPath","numVertexes","radius","interiorAngle","rotationAdjustment","halfPI","d","rad","scalarMultiply","joinPath","pathData","fractionDigits","arg","toFixed"],"mappings":"onBA+BA,MAAMA,EAA8C,CAClDC,EAAG,IACHC,EAAG,KAiBCC,EAAkBA,CACtBC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,KAEA,MAAMC,EAASC,EAAIZ,GACjBa,EAASC,EAAId,GACbe,EAASH,EAAIX,GACbe,EAASF,EAAIb,GACbgB,EAAMf,EAAQE,EA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