fabric-vectr 6.7.15 → 6.7.17

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 (608) hide show
  1. package/dist/dist/index.d.mts +13871 -0
  2. package/dist/dist/index.d.mts.map +1 -0
  3. package/dist/dist/index.mjs +26926 -0
  4. package/dist/dist/index.mjs.map +1 -0
  5. package/dist/dist/src/util/internals/cloneStyles.d.mts +2 -0
  6. package/dist/dist/src/util/internals/cloneStyles.d.mts.map +1 -0
  7. package/dist/dist/src/util/internals/cloneStyles.mjs +15 -0
  8. package/dist/dist/src/util/internals/cloneStyles.mjs.map +1 -0
  9. package/dist/extensions/aligning_guidelines/constant.js +9 -0
  10. package/dist/extensions/aligning_guidelines/constant.js.map +1 -0
  11. package/dist/extensions/aligning_guidelines/index.js +132 -0
  12. package/dist/extensions/aligning_guidelines/index.js.map +1 -0
  13. package/dist/extensions/aligning_guidelines/typedefs.js +2 -0
  14. package/dist/extensions/aligning_guidelines/typedefs.js.map +1 -0
  15. package/dist/extensions/aligning_guidelines/util/basic.js +12 -0
  16. package/dist/extensions/aligning_guidelines/util/basic.js.map +1 -0
  17. package/dist/extensions/aligning_guidelines/util/basic.spec.d.ts +2 -0
  18. package/dist/extensions/aligning_guidelines/util/basic.spec.d.ts.map +1 -0
  19. package/dist/extensions/aligning_guidelines/util/basic.spec.js +30 -0
  20. package/dist/extensions/aligning_guidelines/util/basic.spec.js.map +1 -0
  21. package/dist/extensions/aligning_guidelines/util/collect-line.js +129 -0
  22. package/dist/extensions/aligning_guidelines/util/collect-line.js.map +1 -0
  23. package/dist/extensions/aligning_guidelines/util/collect-point.js +78 -0
  24. package/dist/extensions/aligning_guidelines/util/collect-point.js.map +1 -0
  25. package/dist/extensions/aligning_guidelines/util/draw.js +67 -0
  26. package/dist/extensions/aligning_guidelines/util/draw.js.map +1 -0
  27. package/dist/extensions/aligning_guidelines/util/get-objects-by-target.js +44 -0
  28. package/dist/extensions/aligning_guidelines/util/get-objects-by-target.js.map +1 -0
  29. package/dist/extensions/data_updaters/origins/index.js +36 -0
  30. package/dist/extensions/data_updaters/origins/index.js.map +1 -0
  31. package/dist/extensions/data_updaters/origins/index.spec.d.ts +2 -0
  32. package/dist/extensions/data_updaters/origins/index.spec.d.ts.map +1 -0
  33. package/dist/extensions/data_updaters/origins/index.spec.js +94 -0
  34. package/dist/extensions/data_updaters/origins/index.spec.js.map +1 -0
  35. package/dist/extensions/index.js +3 -0
  36. package/dist/extensions/index.js.map +1 -0
  37. package/dist/fabric.js +101 -0
  38. package/dist/fabric.js.map +1 -0
  39. package/dist/index.js +6 -3
  40. package/dist/index.js.map +1 -1
  41. package/dist/index.min.js +1 -1
  42. package/dist/index.min.js.map +1 -1
  43. package/dist/index.min.mjs +1 -1
  44. package/dist/index.min.mjs.map +1 -1
  45. package/dist/index.mjs +6 -3
  46. package/dist/index.mjs.map +1 -1
  47. package/dist/index.node.cjs +6 -3
  48. package/dist/index.node.cjs.map +1 -1
  49. package/dist/index.node.js +37 -0
  50. package/dist/index.node.js.map +1 -0
  51. package/dist/index.node.mjs +6 -3
  52. package/dist/index.node.mjs.map +1 -1
  53. package/dist/package.json +178 -0
  54. package/dist/package.json.min.mjs +1 -1
  55. package/dist/package.json.mjs +1 -1
  56. package/dist/src/ClassRegistry.js +49 -0
  57. package/dist/src/ClassRegistry.js.map +1 -0
  58. package/dist/src/Collection.js +295 -0
  59. package/dist/src/Collection.js.map +1 -0
  60. package/dist/src/CommonMethods.js +58 -0
  61. package/dist/src/CommonMethods.js.map +1 -0
  62. package/dist/src/EventTypeDefs.js +2 -0
  63. package/dist/src/EventTypeDefs.js.map +1 -0
  64. package/dist/src/Intersection.js +250 -0
  65. package/dist/src/Intersection.js.map +1 -0
  66. package/dist/src/LayoutManager/ActiveSelectionLayoutManager.js +47 -0
  67. package/dist/src/LayoutManager/ActiveSelectionLayoutManager.js.map +1 -0
  68. package/dist/src/LayoutManager/LayoutManager.js +238 -0
  69. package/dist/src/LayoutManager/LayoutManager.js.map +1 -0
  70. package/dist/src/LayoutManager/LayoutStrategies/ClipPathLayout.js +60 -0
  71. package/dist/src/LayoutManager/LayoutStrategies/ClipPathLayout.js.map +1 -0
  72. package/dist/src/LayoutManager/LayoutStrategies/FitContentLayout.js +18 -0
  73. package/dist/src/LayoutManager/LayoutStrategies/FitContentLayout.js.map +1 -0
  74. package/dist/src/LayoutManager/LayoutStrategies/FixedLayout.js +17 -0
  75. package/dist/src/LayoutManager/LayoutStrategies/FixedLayout.js.map +1 -0
  76. package/dist/src/LayoutManager/LayoutStrategies/LayoutStrategy.js +80 -0
  77. package/dist/src/LayoutManager/LayoutStrategies/LayoutStrategy.js.map +1 -0
  78. package/dist/src/LayoutManager/LayoutStrategies/utils.js +28 -0
  79. package/dist/src/LayoutManager/LayoutStrategies/utils.js.map +1 -0
  80. package/dist/src/LayoutManager/constants.js +7 -0
  81. package/dist/src/LayoutManager/constants.js.map +1 -0
  82. package/dist/src/LayoutManager/index.js +7 -0
  83. package/dist/src/LayoutManager/index.js.map +1 -0
  84. package/dist/src/LayoutManager/types.js +2 -0
  85. package/dist/src/LayoutManager/types.js.map +1 -0
  86. package/dist/src/Observable.js +107 -0
  87. package/dist/src/Observable.js.map +1 -0
  88. package/dist/src/Pattern/Pattern.js +152 -0
  89. package/dist/src/Pattern/Pattern.js.map +1 -0
  90. package/dist/src/Pattern/index.js +3 -0
  91. package/dist/src/Pattern/index.js.map +1 -0
  92. package/dist/src/Pattern/types.js +2 -0
  93. package/dist/src/Pattern/types.js.map +1 -0
  94. package/dist/src/Point.js +330 -0
  95. package/dist/src/Point.js.map +1 -0
  96. package/dist/src/Shadow.js +125 -0
  97. package/dist/src/Shadow.js.map +1 -0
  98. package/dist/src/benchmarks/boundingBoxFromPoint.d.mts +2 -0
  99. package/dist/src/benchmarks/boundingBoxFromPoint.d.mts.map +1 -0
  100. package/dist/src/benchmarks/boundingBoxFromPoint.mjs +54 -0
  101. package/dist/src/benchmarks/boundingBoxFromPoint.mjs.map +1 -0
  102. package/dist/src/benchmarks/calcCornerCoords.d.mts +2 -0
  103. package/dist/src/benchmarks/calcCornerCoords.d.mts.map +1 -0
  104. package/dist/src/benchmarks/calcCornerCoords.mjs +78 -0
  105. package/dist/src/benchmarks/calcCornerCoords.mjs.map +1 -0
  106. package/dist/src/benchmarks/calcTransformMatrix.d.mts +2 -0
  107. package/dist/src/benchmarks/calcTransformMatrix.d.mts.map +1 -0
  108. package/dist/src/benchmarks/calcTransformMatrix.mjs +71 -0
  109. package/dist/src/benchmarks/calcTransformMatrix.mjs.map +1 -0
  110. package/dist/src/benchmarks/cloneStyles.d.mts +2 -0
  111. package/dist/src/benchmarks/cloneStyles.d.mts.map +1 -0
  112. package/dist/src/benchmarks/cloneStyles.mjs +56 -0
  113. package/dist/src/benchmarks/cloneStyles.mjs.map +1 -0
  114. package/dist/src/benchmarks/pathCloning.d.mts +2 -0
  115. package/dist/src/benchmarks/pathCloning.d.mts.map +1 -0
  116. package/dist/src/benchmarks/pathCloning.mjs +94 -0
  117. package/dist/src/benchmarks/pathCloning.mjs.map +1 -0
  118. package/dist/src/benchmarks/pathData.d.mts +3 -0
  119. package/dist/src/benchmarks/pathData.d.mts.map +1 -0
  120. package/dist/src/benchmarks/pathData.mjs +3 -0
  121. package/dist/src/benchmarks/pathData.mjs.map +1 -0
  122. package/dist/src/benchmarks/raycasting.d.mts +2 -0
  123. package/dist/src/benchmarks/raycasting.d.mts.map +1 -0
  124. package/dist/src/benchmarks/raycasting.mjs +134 -0
  125. package/dist/src/benchmarks/raycasting.mjs.map +1 -0
  126. package/dist/src/benchmarks/transformMatrixKey.d.mts +2 -0
  127. package/dist/src/benchmarks/transformMatrixKey.d.mts.map +1 -0
  128. package/dist/src/benchmarks/transformMatrixKey.mjs +81 -0
  129. package/dist/src/benchmarks/transformMatrixKey.mjs.map +1 -0
  130. package/dist/src/brushes/BaseBrush.js +121 -0
  131. package/dist/src/brushes/BaseBrush.js.map +1 -0
  132. package/dist/src/brushes/CircleBrush.js +117 -0
  133. package/dist/src/brushes/CircleBrush.js.map +1 -0
  134. package/dist/src/brushes/PatternBrush.js +49 -0
  135. package/dist/src/brushes/PatternBrush.js.map +1 -0
  136. package/dist/src/brushes/PencilBrush.js +259 -0
  137. package/dist/src/brushes/PencilBrush.js.map +1 -0
  138. package/dist/src/brushes/SprayBrush.js +174 -0
  139. package/dist/src/brushes/SprayBrush.js.map +1 -0
  140. package/dist/src/brushes/typedefs.js +2 -0
  141. package/dist/src/brushes/typedefs.js.map +1 -0
  142. package/dist/src/cache.js +69 -0
  143. package/dist/src/cache.js.map +1 -0
  144. package/dist/src/canvas/Canvas.js +1366 -0
  145. package/dist/src/canvas/Canvas.js.map +1 -0
  146. package/dist/src/canvas/CanvasOptions.js +31 -0
  147. package/dist/src/canvas/CanvasOptions.js.map +1 -0
  148. package/dist/src/canvas/DOMManagers/CanvasDOMManager.js +97 -0
  149. package/dist/src/canvas/DOMManagers/CanvasDOMManager.js.map +1 -0
  150. package/dist/src/canvas/DOMManagers/StaticCanvasDOMManager.js +63 -0
  151. package/dist/src/canvas/DOMManagers/StaticCanvasDOMManager.js.map +1 -0
  152. package/dist/src/canvas/DOMManagers/util.js +56 -0
  153. package/dist/src/canvas/DOMManagers/util.js.map +1 -0
  154. package/dist/src/canvas/SelectableCanvas.js +1141 -0
  155. package/dist/src/canvas/SelectableCanvas.js.map +1 -0
  156. package/dist/src/canvas/StaticCanvas.js +1085 -0
  157. package/dist/src/canvas/StaticCanvas.js.map +1 -0
  158. package/dist/src/canvas/StaticCanvasOptions.js +23 -0
  159. package/dist/src/canvas/StaticCanvasOptions.js.map +1 -0
  160. package/dist/src/canvas/TextEditingManager.js +54 -0
  161. package/dist/src/canvas/TextEditingManager.js.map +1 -0
  162. package/dist/src/canvas/canvas_gestures.mixin.js +181 -0
  163. package/dist/src/canvas/canvas_gestures.mixin.js.map +1 -0
  164. package/dist/src/color/Color.js +301 -0
  165. package/dist/src/color/Color.js.map +1 -0
  166. package/dist/src/color/color_map.js +155 -0
  167. package/dist/src/color/color_map.js.map +1 -0
  168. package/dist/src/color/constants.js +111 -0
  169. package/dist/src/color/constants.js.map +1 -0
  170. package/dist/src/color/typedefs.js +2 -0
  171. package/dist/src/color/typedefs.js.map +1 -0
  172. package/dist/src/color/util.js +73 -0
  173. package/dist/src/color/util.js.map +1 -0
  174. package/dist/src/config.js +140 -0
  175. package/dist/src/config.js.map +1 -0
  176. package/dist/src/constants.js +38 -0
  177. package/dist/src/constants.js.map +1 -0
  178. package/dist/src/controls/Control.js +241 -0
  179. package/dist/src/controls/Control.js.map +1 -0
  180. package/dist/src/controls/changeWidth.js +31 -0
  181. package/dist/src/controls/changeWidth.js.map +1 -0
  182. package/dist/src/controls/commonControls.js +91 -0
  183. package/dist/src/controls/commonControls.js.map +1 -0
  184. package/dist/src/controls/controlRendering.js +81 -0
  185. package/dist/src/controls/controlRendering.js.map +1 -0
  186. package/dist/src/controls/drag.js +22 -0
  187. package/dist/src/controls/drag.js.map +1 -0
  188. package/dist/src/controls/fireEvent.js +9 -0
  189. package/dist/src/controls/fireEvent.js.map +1 -0
  190. package/dist/src/controls/index.js +14 -0
  191. package/dist/src/controls/index.js.map +1 -0
  192. package/dist/src/controls/pathControl.js +137 -0
  193. package/dist/src/controls/pathControl.js.map +1 -0
  194. package/dist/src/controls/polyControl.js +66 -0
  195. package/dist/src/controls/polyControl.js.map +1 -0
  196. package/dist/src/controls/rotate.js +57 -0
  197. package/dist/src/controls/rotate.js.map +1 -0
  198. package/dist/src/controls/scale.js +190 -0
  199. package/dist/src/controls/scale.js.map +1 -0
  200. package/dist/src/controls/scaleSkew.js +66 -0
  201. package/dist/src/controls/scaleSkew.js.map +1 -0
  202. package/dist/src/controls/skew.js +147 -0
  203. package/dist/src/controls/skew.js.map +1 -0
  204. package/dist/src/controls/util.js +89 -0
  205. package/dist/src/controls/util.js.map +1 -0
  206. package/dist/src/controls/wrapWithFireEvent.js +22 -0
  207. package/dist/src/controls/wrapWithFireEvent.js.map +1 -0
  208. package/dist/src/controls/wrapWithFixedAnchor.js +16 -0
  209. package/dist/src/controls/wrapWithFixedAnchor.js.map +1 -0
  210. package/dist/src/env/browser.js +18 -0
  211. package/dist/src/env/browser.js.map +1 -0
  212. package/dist/src/env/index.js +37 -0
  213. package/dist/src/env/index.js.map +1 -0
  214. package/dist/src/env/node.js +37 -0
  215. package/dist/src/env/node.js.map +1 -0
  216. package/dist/src/env/types.js +2 -0
  217. package/dist/src/env/types.js.map +1 -0
  218. package/dist/src/filters/BaseFilter.js +304 -0
  219. package/dist/src/filters/BaseFilter.js.map +1 -0
  220. package/dist/src/filters/BlendColor.js +147 -0
  221. package/dist/src/filters/BlendColor.js.map +1 -0
  222. package/dist/src/filters/BlendImage.js +149 -0
  223. package/dist/src/filters/BlendImage.js.map +1 -0
  224. package/dist/src/filters/Blur.js +167 -0
  225. package/dist/src/filters/Blur.js.map +1 -0
  226. package/dist/src/filters/Boilerplate.js +61 -0
  227. package/dist/src/filters/Boilerplate.js.map +1 -0
  228. package/dist/src/filters/Brightness.js +51 -0
  229. package/dist/src/filters/Brightness.js.map +1 -0
  230. package/dist/src/filters/Canvas2dFilterBackend.js +51 -0
  231. package/dist/src/filters/Canvas2dFilterBackend.js.map +1 -0
  232. package/dist/src/filters/ColorMatrix.js +92 -0
  233. package/dist/src/filters/ColorMatrix.js.map +1 -0
  234. package/dist/src/filters/ColorMatrixFilters.js +45 -0
  235. package/dist/src/filters/ColorMatrixFilters.js.map +1 -0
  236. package/dist/src/filters/Composed.js +55 -0
  237. package/dist/src/filters/Composed.js.map +1 -0
  238. package/dist/src/filters/Contrast.js +51 -0
  239. package/dist/src/filters/Contrast.js.map +1 -0
  240. package/dist/src/filters/Convolute.js +132 -0
  241. package/dist/src/filters/Convolute.js.map +1 -0
  242. package/dist/src/filters/FilterBackend.js +34 -0
  243. package/dist/src/filters/FilterBackend.js.map +1 -0
  244. package/dist/src/filters/GLProbes/GLProbe.js +3 -0
  245. package/dist/src/filters/GLProbes/GLProbe.js.map +1 -0
  246. package/dist/src/filters/GLProbes/NodeGLProbe.js +15 -0
  247. package/dist/src/filters/GLProbes/NodeGLProbe.js.map +1 -0
  248. package/dist/src/filters/GLProbes/WebGLProbe.js +39 -0
  249. package/dist/src/filters/GLProbes/WebGLProbe.js.map +1 -0
  250. package/dist/src/filters/Gamma.js +80 -0
  251. package/dist/src/filters/Gamma.js.map +1 -0
  252. package/dist/src/filters/Grayscale.js +69 -0
  253. package/dist/src/filters/Grayscale.js.map +1 -0
  254. package/dist/src/filters/HueRotation.js +61 -0
  255. package/dist/src/filters/HueRotation.js.map +1 -0
  256. package/dist/src/filters/Invert.js +58 -0
  257. package/dist/src/filters/Invert.js.map +1 -0
  258. package/dist/src/filters/Noise.js +54 -0
  259. package/dist/src/filters/Noise.js.map +1 -0
  260. package/dist/src/filters/Pixelate.js +66 -0
  261. package/dist/src/filters/Pixelate.js.map +1 -0
  262. package/dist/src/filters/RemoveColor.js +74 -0
  263. package/dist/src/filters/RemoveColor.js.map +1 -0
  264. package/dist/src/filters/Resize.js +399 -0
  265. package/dist/src/filters/Resize.js.map +1 -0
  266. package/dist/src/filters/Saturation.js +55 -0
  267. package/dist/src/filters/Saturation.js.map +1 -0
  268. package/dist/src/filters/Vibrance.js +57 -0
  269. package/dist/src/filters/Vibrance.js.map +1 -0
  270. package/dist/src/filters/WebGLFilterBackend.js +269 -0
  271. package/dist/src/filters/WebGLFilterBackend.js.map +1 -0
  272. package/dist/src/filters/filters.js +21 -0
  273. package/dist/src/filters/filters.js.map +1 -0
  274. package/dist/src/filters/index.js +7 -0
  275. package/dist/src/filters/index.js.map +1 -0
  276. package/dist/src/filters/shaders/baseFilter.js +16 -0
  277. package/dist/src/filters/shaders/baseFilter.js.map +1 -0
  278. package/dist/src/filters/shaders/blendColor.js +32 -0
  279. package/dist/src/filters/shaders/blendColor.js.map +1 -0
  280. package/dist/src/filters/shaders/blendImage.js +42 -0
  281. package/dist/src/filters/shaders/blendImage.js.map +1 -0
  282. package/dist/src/filters/shaders/blur.js +31 -0
  283. package/dist/src/filters/shaders/blur.js.map +1 -0
  284. package/dist/src/filters/shaders/brightness.js +12 -0
  285. package/dist/src/filters/shaders/brightness.js.map +1 -0
  286. package/dist/src/filters/shaders/colorMatrix.js +13 -0
  287. package/dist/src/filters/shaders/colorMatrix.js.map +1 -0
  288. package/dist/src/filters/shaders/constrast.js +12 -0
  289. package/dist/src/filters/shaders/constrast.js.map +1 -0
  290. package/dist/src/filters/shaders/convolute.js +155 -0
  291. package/dist/src/filters/shaders/convolute.js.map +1 -0
  292. package/dist/src/filters/shaders/gamma.js +16 -0
  293. package/dist/src/filters/shaders/gamma.js.map +1 -0
  294. package/dist/src/filters/shaders/grayscale.js +35 -0
  295. package/dist/src/filters/shaders/grayscale.js.map +1 -0
  296. package/dist/src/filters/shaders/invert.js +20 -0
  297. package/dist/src/filters/shaders/invert.js.map +1 -0
  298. package/dist/src/filters/shaders/noise.js +17 -0
  299. package/dist/src/filters/shaders/noise.js.map +1 -0
  300. package/dist/src/filters/shaders/pixelate.js +20 -0
  301. package/dist/src/filters/shaders/pixelate.js.map +1 -0
  302. package/dist/src/filters/shaders/removeColor.js +14 -0
  303. package/dist/src/filters/shaders/removeColor.js.map +1 -0
  304. package/dist/src/filters/shaders/saturation.js +16 -0
  305. package/dist/src/filters/shaders/saturation.js.map +1 -0
  306. package/dist/src/filters/shaders/vibrance.js +17 -0
  307. package/dist/src/filters/shaders/vibrance.js.map +1 -0
  308. package/dist/src/filters/typedefs.js +2 -0
  309. package/dist/src/filters/typedefs.js.map +1 -0
  310. package/dist/src/filters/utils.js +36 -0
  311. package/dist/src/filters/utils.js.map +1 -0
  312. package/dist/src/gradient/Gradient.d.ts.map +1 -1
  313. package/dist/src/gradient/Gradient.js +244 -0
  314. package/dist/src/gradient/Gradient.js.map +1 -0
  315. package/dist/src/gradient/Gradient.min.mjs +1 -1
  316. package/dist/src/gradient/Gradient.min.mjs.map +1 -1
  317. package/dist/src/gradient/Gradient.mjs +2 -1
  318. package/dist/src/gradient/Gradient.mjs.map +1 -1
  319. package/dist/src/gradient/constants.js +12 -0
  320. package/dist/src/gradient/constants.js.map +1 -0
  321. package/dist/src/gradient/index.js +3 -0
  322. package/dist/src/gradient/index.js.map +1 -0
  323. package/dist/src/gradient/parser/misc.js +11 -0
  324. package/dist/src/gradient/parser/misc.js.map +1 -0
  325. package/dist/src/gradient/parser/parseColorStops.js +42 -0
  326. package/dist/src/gradient/parser/parseColorStops.js.map +1 -0
  327. package/dist/src/gradient/parser/parseCoords.js +60 -0
  328. package/dist/src/gradient/parser/parseCoords.js.map +1 -0
  329. package/dist/src/gradient/typedefs.js +2 -0
  330. package/dist/src/gradient/typedefs.js.map +1 -0
  331. package/dist/src/mixins/eraser_brush.mixin.js +732 -0
  332. package/dist/src/mixins/eraser_brush.mixin.js.map +1 -0
  333. package/dist/src/parkinglot/canvas_animation.mixin.js +102 -0
  334. package/dist/src/parkinglot/canvas_animation.mixin.js.map +1 -0
  335. package/dist/src/parkinglot/straighten.js +53 -0
  336. package/dist/src/parkinglot/straighten.js.map +1 -0
  337. package/dist/src/parser/applyViewboxTransform.js +146 -0
  338. package/dist/src/parser/applyViewboxTransform.js.map +1 -0
  339. package/dist/src/parser/attributes.js +27 -0
  340. package/dist/src/parser/attributes.js.map +1 -0
  341. package/dist/src/parser/constants.js +70 -0
  342. package/dist/src/parser/constants.js.map +1 -0
  343. package/dist/src/parser/doesSomeParentMatch.js +15 -0
  344. package/dist/src/parser/doesSomeParentMatch.js.map +1 -0
  345. package/dist/src/parser/elementMatchesRule.js +15 -0
  346. package/dist/src/parser/elementMatchesRule.js.map +1 -0
  347. package/dist/src/parser/elements_parser.js +164 -0
  348. package/dist/src/parser/elements_parser.js.map +1 -0
  349. package/dist/src/parser/getCSSRules.js +62 -0
  350. package/dist/src/parser/getCSSRules.js.map +1 -0
  351. package/dist/src/parser/getGlobalStylesForElement.js +17 -0
  352. package/dist/src/parser/getGlobalStylesForElement.js.map +1 -0
  353. package/dist/src/parser/getGradientDefs.js +30 -0
  354. package/dist/src/parser/getGradientDefs.js.map +1 -0
  355. package/dist/src/parser/getMultipleNodes.js +10 -0
  356. package/dist/src/parser/getMultipleNodes.js.map +1 -0
  357. package/dist/src/parser/getPatternDefs.js +70 -0
  358. package/dist/src/parser/getPatternDefs.js.map +1 -0
  359. package/dist/src/parser/getSvgRegex.js +4 -0
  360. package/dist/src/parser/getSvgRegex.js.map +1 -0
  361. package/dist/src/parser/getTagName.js +2 -0
  362. package/dist/src/parser/getTagName.js.map +1 -0
  363. package/dist/src/parser/hasInvalidAncestor.js +17 -0
  364. package/dist/src/parser/hasInvalidAncestor.js.map +1 -0
  365. package/dist/src/parser/loadSVGFromString.js +23 -0
  366. package/dist/src/parser/loadSVGFromString.js.map +1 -0
  367. package/dist/src/parser/loadSVGFromURL.js +39 -0
  368. package/dist/src/parser/loadSVGFromURL.js.map +1 -0
  369. package/dist/src/parser/normalizeAttr.js +3 -0
  370. package/dist/src/parser/normalizeAttr.js.map +1 -0
  371. package/dist/src/parser/normalizeValue.js +79 -0
  372. package/dist/src/parser/normalizeValue.js.map +1 -0
  373. package/dist/src/parser/parseAttributes.js +66 -0
  374. package/dist/src/parser/parseAttributes.js.map +1 -0
  375. package/dist/src/parser/parseFontDeclaration.js +38 -0
  376. package/dist/src/parser/parseFontDeclaration.js.map +1 -0
  377. package/dist/src/parser/parsePointsAttribute.js +28 -0
  378. package/dist/src/parser/parsePointsAttribute.js.map +1 -0
  379. package/dist/src/parser/parseSVGDocument.js +74 -0
  380. package/dist/src/parser/parseSVGDocument.js.map +1 -0
  381. package/dist/src/parser/parseStyleAttribute.js +23 -0
  382. package/dist/src/parser/parseStyleAttribute.js.map +1 -0
  383. package/dist/src/parser/parseStyleObject.js +15 -0
  384. package/dist/src/parser/parseStyleObject.js.map +1 -0
  385. package/dist/src/parser/parseStyleString.js +18 -0
  386. package/dist/src/parser/parseStyleString.js.map +1 -0
  387. package/dist/src/parser/parseTransformAttribute.js +76 -0
  388. package/dist/src/parser/parseTransformAttribute.js.map +1 -0
  389. package/dist/src/parser/parseUseDirectives.js +76 -0
  390. package/dist/src/parser/parseUseDirectives.js.map +1 -0
  391. package/dist/src/parser/percent.js +21 -0
  392. package/dist/src/parser/percent.js.map +1 -0
  393. package/dist/src/parser/recursivelyParseGradientsXlink.js +36 -0
  394. package/dist/src/parser/recursivelyParseGradientsXlink.js.map +1 -0
  395. package/dist/src/parser/selectorMatches.js +24 -0
  396. package/dist/src/parser/selectorMatches.js.map +1 -0
  397. package/dist/src/parser/setStrokeFillOpacity.js +35 -0
  398. package/dist/src/parser/setStrokeFillOpacity.js.map +1 -0
  399. package/dist/src/parser/typedefs.js +2 -0
  400. package/dist/src/parser/typedefs.js.map +1 -0
  401. package/dist/src/shapes/ActiveSelection.js +195 -0
  402. package/dist/src/shapes/ActiveSelection.js.map +1 -0
  403. package/dist/src/shapes/Circle.js +155 -0
  404. package/dist/src/shapes/Circle.js.map +1 -0
  405. package/dist/src/shapes/Ellipse.js +120 -0
  406. package/dist/src/shapes/Ellipse.js.map +1 -0
  407. package/dist/src/shapes/Group.js +549 -0
  408. package/dist/src/shapes/Group.js.map +1 -0
  409. package/dist/src/shapes/IText/DraggableTextDelegate.js +326 -0
  410. package/dist/src/shapes/IText/DraggableTextDelegate.js.map +1 -0
  411. package/dist/src/shapes/IText/IText.js +545 -0
  412. package/dist/src/shapes/IText/IText.js.map +1 -0
  413. package/dist/src/shapes/IText/ITextBehavior.js +848 -0
  414. package/dist/src/shapes/IText/ITextBehavior.js.map +1 -0
  415. package/dist/src/shapes/IText/ITextClickBehavior.js +196 -0
  416. package/dist/src/shapes/IText/ITextClickBehavior.js.map +1 -0
  417. package/dist/src/shapes/IText/ITextKeyBehavior.js +522 -0
  418. package/dist/src/shapes/IText/ITextKeyBehavior.js.map +1 -0
  419. package/dist/src/shapes/IText/constants.js +47 -0
  420. package/dist/src/shapes/IText/constants.js.map +1 -0
  421. package/dist/src/shapes/Image.js +589 -0
  422. package/dist/src/shapes/Image.js.map +1 -0
  423. package/dist/src/shapes/Line.js +195 -0
  424. package/dist/src/shapes/Line.js.map +1 -0
  425. package/dist/src/shapes/Object/FabricObject.js +12 -0
  426. package/dist/src/shapes/Object/FabricObject.js.map +1 -0
  427. package/dist/src/shapes/Object/FabricObjectSVGExportMixin.js +255 -0
  428. package/dist/src/shapes/Object/FabricObjectSVGExportMixin.js.map +1 -0
  429. package/dist/src/shapes/Object/InteractiveObject.js +478 -0
  430. package/dist/src/shapes/Object/InteractiveObject.js.map +1 -0
  431. package/dist/src/shapes/Object/Object.js +1392 -0
  432. package/dist/src/shapes/Object/Object.js.map +1 -0
  433. package/dist/src/shapes/Object/ObjectGeometry.js +537 -0
  434. package/dist/src/shapes/Object/ObjectGeometry.js.map +1 -0
  435. package/dist/src/shapes/Object/defaultValues.js +109 -0
  436. package/dist/src/shapes/Object/defaultValues.js.map +1 -0
  437. package/dist/src/shapes/Object/types/BaseProps.js +2 -0
  438. package/dist/src/shapes/Object/types/BaseProps.js.map +1 -0
  439. package/dist/src/shapes/Object/types/BorderProps.js +2 -0
  440. package/dist/src/shapes/Object/types/BorderProps.js.map +1 -0
  441. package/dist/src/shapes/Object/types/ControlProps.js +2 -0
  442. package/dist/src/shapes/Object/types/ControlProps.js.map +1 -0
  443. package/dist/src/shapes/Object/types/FabricObjectProps.js +2 -0
  444. package/dist/src/shapes/Object/types/FabricObjectProps.js.map +1 -0
  445. package/dist/src/shapes/Object/types/FillStrokeProps.js +2 -0
  446. package/dist/src/shapes/Object/types/FillStrokeProps.js.map +1 -0
  447. package/dist/src/shapes/Object/types/LockInteractionProps.js +2 -0
  448. package/dist/src/shapes/Object/types/LockInteractionProps.js.map +1 -0
  449. package/dist/src/shapes/Object/types/ObjectProps.js +2 -0
  450. package/dist/src/shapes/Object/types/ObjectProps.js.map +1 -0
  451. package/dist/src/shapes/Object/types/ObjectTransformProps.js +2 -0
  452. package/dist/src/shapes/Object/types/ObjectTransformProps.js.map +1 -0
  453. package/dist/src/shapes/Object/types/SerializedObjectProps.js +2 -0
  454. package/dist/src/shapes/Object/types/SerializedObjectProps.js.map +1 -0
  455. package/dist/src/shapes/Object/types/index.js +2 -0
  456. package/dist/src/shapes/Object/types/index.js.map +1 -0
  457. package/dist/src/shapes/Path.js +267 -0
  458. package/dist/src/shapes/Path.js.map +1 -0
  459. package/dist/src/shapes/Polygon.js +12 -0
  460. package/dist/src/shapes/Polygon.js.map +1 -0
  461. package/dist/src/shapes/Polyline.js +307 -0
  462. package/dist/src/shapes/Polyline.js.map +1 -0
  463. package/dist/src/shapes/Rect.js +131 -0
  464. package/dist/src/shapes/Rect.js.map +1 -0
  465. package/dist/src/shapes/Text/StyledText.js +261 -0
  466. package/dist/src/shapes/Text/StyledText.js.map +1 -0
  467. package/dist/src/shapes/Text/Text.js +1258 -0
  468. package/dist/src/shapes/Text/Text.js.map +1 -0
  469. package/dist/src/shapes/Text/TextSVGExportMixin.js +339 -0
  470. package/dist/src/shapes/Text/TextSVGExportMixin.js.map +1 -0
  471. package/dist/src/shapes/Text/constants.js +94 -0
  472. package/dist/src/shapes/Text/constants.js.map +1 -0
  473. package/dist/src/shapes/Textbox.d.ts.map +1 -1
  474. package/dist/src/shapes/Textbox.js +910 -0
  475. package/dist/src/shapes/Textbox.js.map +1 -0
  476. package/dist/src/shapes/Textbox.min.mjs +1 -1
  477. package/dist/src/shapes/Textbox.min.mjs.map +1 -1
  478. package/dist/src/shapes/Textbox.mjs +4 -1
  479. package/dist/src/shapes/Textbox.mjs.map +1 -1
  480. package/dist/src/shapes/Triangle.js +47 -0
  481. package/dist/src/shapes/Triangle.js.map +1 -0
  482. package/dist/src/typedefs.js +2 -0
  483. package/dist/src/typedefs.js.map +1 -0
  484. package/dist/src/util/animation/AnimationBase.js +94 -0
  485. package/dist/src/util/animation/AnimationBase.js.map +1 -0
  486. package/dist/src/util/animation/AnimationFrameProvider.js +8 -0
  487. package/dist/src/util/animation/AnimationFrameProvider.js.map +1 -0
  488. package/dist/src/util/animation/AnimationRegistry.js +49 -0
  489. package/dist/src/util/animation/AnimationRegistry.js.map +1 -0
  490. package/dist/src/util/animation/ArrayAnimation.js +18 -0
  491. package/dist/src/util/animation/ArrayAnimation.js.map +1 -0
  492. package/dist/src/util/animation/ColorAnimation.js +43 -0
  493. package/dist/src/util/animation/ColorAnimation.js.map +1 -0
  494. package/dist/src/util/animation/ValueAnimation.js +18 -0
  495. package/dist/src/util/animation/ValueAnimation.js.map +1 -0
  496. package/dist/src/util/animation/animate.js +19 -0
  497. package/dist/src/util/animation/animate.js.map +1 -0
  498. package/dist/src/util/animation/easing.js +265 -0
  499. package/dist/src/util/animation/easing.js.map +1 -0
  500. package/dist/src/util/animation/index.js +3 -0
  501. package/dist/src/util/animation/index.js.map +1 -0
  502. package/dist/src/util/animation/types.js +2 -0
  503. package/dist/src/util/animation/types.js.map +1 -0
  504. package/dist/src/util/applyMixins.js +14 -0
  505. package/dist/src/util/applyMixins.js.map +1 -0
  506. package/dist/src/util/dom_event.js +21 -0
  507. package/dist/src/util/dom_event.js.map +1 -0
  508. package/dist/src/util/dom_misc.js +42 -0
  509. package/dist/src/util/dom_misc.js.map +1 -0
  510. package/dist/src/util/dom_style.js +19 -0
  511. package/dist/src/util/dom_style.js.map +1 -0
  512. package/dist/src/util/index.js +36 -0
  513. package/dist/src/util/index.js.map +1 -0
  514. package/dist/src/util/internals/applyCanvasTransform.js +15 -0
  515. package/dist/src/util/internals/applyCanvasTransform.js.map +1 -0
  516. package/dist/src/util/internals/cleanupSvgAttribute.js +8 -0
  517. package/dist/src/util/internals/cleanupSvgAttribute.js.map +1 -0
  518. package/dist/src/util/internals/cloneDeep.js +8 -0
  519. package/dist/src/util/internals/cloneDeep.js.map +1 -0
  520. package/dist/src/util/internals/cloneStyles.js +11 -0
  521. package/dist/src/util/internals/cloneStyles.js.map +1 -0
  522. package/dist/src/util/internals/console.js +14 -0
  523. package/dist/src/util/internals/console.js.map +1 -0
  524. package/dist/src/util/internals/dom_request.js +39 -0
  525. package/dist/src/util/internals/dom_request.js.map +1 -0
  526. package/dist/src/util/internals/findRight.js +9 -0
  527. package/dist/src/util/internals/findRight.js.map +1 -0
  528. package/dist/src/util/internals/getRandomInt.js +8 -0
  529. package/dist/src/util/internals/getRandomInt.js.map +1 -0
  530. package/dist/src/util/internals/ifNaN.js +10 -0
  531. package/dist/src/util/internals/ifNaN.js.map +1 -0
  532. package/dist/src/util/internals/removeFromArray.js +15 -0
  533. package/dist/src/util/internals/removeFromArray.js.map +1 -0
  534. package/dist/src/util/internals/uid.js +3 -0
  535. package/dist/src/util/internals/uid.js.map +1 -0
  536. package/dist/src/util/lang_string.js +93 -0
  537. package/dist/src/util/lang_string.js.map +1 -0
  538. package/dist/src/util/misc/boundingBoxFromPoints.js +26 -0
  539. package/dist/src/util/misc/boundingBoxFromPoints.js.map +1 -0
  540. package/dist/src/util/misc/capValue.js +2 -0
  541. package/dist/src/util/misc/capValue.js.map +1 -0
  542. package/dist/src/util/misc/cos.js +23 -0
  543. package/dist/src/util/misc/cos.js.map +1 -0
  544. package/dist/src/util/misc/dom.js +55 -0
  545. package/dist/src/util/misc/dom.js.map +1 -0
  546. package/dist/src/util/misc/findScaleTo.js +19 -0
  547. package/dist/src/util/misc/findScaleTo.js.map +1 -0
  548. package/dist/src/util/misc/groupSVGElements.js +15 -0
  549. package/dist/src/util/misc/groupSVGElements.js.map +1 -0
  550. package/dist/src/util/misc/isTransparent.js +23 -0
  551. package/dist/src/util/misc/isTransparent.js.map +1 -0
  552. package/dist/src/util/misc/matrix.js +238 -0
  553. package/dist/src/util/misc/matrix.js.map +1 -0
  554. package/dist/src/util/misc/mergeClipPaths.js +39 -0
  555. package/dist/src/util/misc/mergeClipPaths.js.map +1 -0
  556. package/dist/src/util/misc/objectEnlive.js +136 -0
  557. package/dist/src/util/misc/objectEnlive.js.map +1 -0
  558. package/dist/src/util/misc/objectTransforms.js +89 -0
  559. package/dist/src/util/misc/objectTransforms.js.map +1 -0
  560. package/dist/src/util/misc/pick.js +23 -0
  561. package/dist/src/util/misc/pick.js.map +1 -0
  562. package/dist/src/util/misc/planeChange.js +68 -0
  563. package/dist/src/util/misc/planeChange.js.map +1 -0
  564. package/dist/src/util/misc/projectStroke/StrokeLineCapProjections.js +105 -0
  565. package/dist/src/util/misc/projectStroke/StrokeLineCapProjections.js.map +1 -0
  566. package/dist/src/util/misc/projectStroke/StrokeLineJoinProjections.js +219 -0
  567. package/dist/src/util/misc/projectStroke/StrokeLineJoinProjections.js.map +1 -0
  568. package/dist/src/util/misc/projectStroke/StrokeProjectionsBase.js +42 -0
  569. package/dist/src/util/misc/projectStroke/StrokeProjectionsBase.js.map +1 -0
  570. package/dist/src/util/misc/projectStroke/index.js +61 -0
  571. package/dist/src/util/misc/projectStroke/index.js.map +1 -0
  572. package/dist/src/util/misc/projectStroke/types.js +2 -0
  573. package/dist/src/util/misc/projectStroke/types.js.map +1 -0
  574. package/dist/src/util/misc/radiansDegreesConversion.js +14 -0
  575. package/dist/src/util/misc/radiansDegreesConversion.js.map +1 -0
  576. package/dist/src/util/misc/resolveOrigin.js +17 -0
  577. package/dist/src/util/misc/resolveOrigin.js.map +1 -0
  578. package/dist/src/util/misc/rotatePoint.js +10 -0
  579. package/dist/src/util/misc/rotatePoint.js.map +1 -0
  580. package/dist/src/util/misc/sin.js +25 -0
  581. package/dist/src/util/misc/sin.js.map +1 -0
  582. package/dist/src/util/misc/svgExport.js +13 -0
  583. package/dist/src/util/misc/svgExport.js.map +1 -0
  584. package/dist/src/util/misc/svgParsing.js +129 -0
  585. package/dist/src/util/misc/svgParsing.js.map +1 -0
  586. package/dist/src/util/misc/textStyles.js +107 -0
  587. package/dist/src/util/misc/textStyles.js.map +1 -0
  588. package/dist/src/util/misc/toFixed.js +8 -0
  589. package/dist/src/util/misc/toFixed.js.map +1 -0
  590. package/dist/src/util/misc/vectors.js +77 -0
  591. package/dist/src/util/misc/vectors.js.map +1 -0
  592. package/dist/src/util/path/index.js +743 -0
  593. package/dist/src/util/path/index.js.map +1 -0
  594. package/dist/src/util/path/regex.js +33 -0
  595. package/dist/src/util/path/regex.js.map +1 -0
  596. package/dist/src/util/path/typechecks.js +67 -0
  597. package/dist/src/util/path/typechecks.js.map +1 -0
  598. package/dist/src/util/path/typedefs.js +2 -0
  599. package/dist/src/util/path/typedefs.js.map +1 -0
  600. package/dist/src/util/transform_matrix_removal.js +46 -0
  601. package/dist/src/util/transform_matrix_removal.js.map +1 -0
  602. package/dist/src/util/typeAssertions.js +21 -0
  603. package/dist/src/util/typeAssertions.js.map +1 -0
  604. package/dist-extensions/src/gradient/Gradient.d.ts.map +1 -1
  605. package/dist-extensions/src/shapes/Textbox.d.ts.map +1 -1
  606. package/package.json +1 -1
  607. package/src/gradient/Gradient.ts +5 -2
  608. package/src/shapes/Textbox.ts +4 -1
@@ -0,0 +1,848 @@
1
+ import { Point } from '../../Point';
2
+ import { FabricText } from '../Text/Text';
3
+ import { animate } from '../../util/animation/animate';
4
+ import { getDocumentFromElement } from '../../util/dom_misc';
5
+ import { LEFT, MODIFIED, RIGHT, reNewline } from '../../constants';
6
+ /**
7
+ * extend this regex to support non english languages
8
+ *
9
+ * - ` ` Matches a SPACE character (char code 32).
10
+ * - `\n` Matches a LINE FEED character (char code 10).
11
+ * - `\.` Matches a "." character (char code 46).
12
+ * - `,` Matches a "," character (char code 44).
13
+ * - `;` Matches a ";" character (char code 59).
14
+ * - `!` Matches a "!" character (char code 33).
15
+ * - `\?` Matches a "?" character (char code 63).
16
+ * - `\-` Matches a "-" character (char code 45).
17
+ */
18
+ // eslint-disable-next-line no-useless-escape
19
+ const reNonWord = /[ \n\.,;!\?\-]/;
20
+ export class ITextBehavior extends FabricText {
21
+ _currentCursorOpacity = 1;
22
+ /**
23
+ * Initializes all the interactive behavior of IText
24
+ */
25
+ initBehavior() {
26
+ this._tick = this._tick.bind(this);
27
+ this._onTickComplete = this._onTickComplete.bind(this);
28
+ this.updateSelectionOnMouseMove =
29
+ this.updateSelectionOnMouseMove.bind(this);
30
+ }
31
+ onDeselect(options) {
32
+ this.isEditing && this.exitEditing();
33
+ this.selected = false;
34
+ return super.onDeselect(options);
35
+ }
36
+ /**
37
+ * @private
38
+ */
39
+ _animateCursor({ toValue, duration, delay, onComplete, }) {
40
+ return animate({
41
+ startValue: this._currentCursorOpacity,
42
+ endValue: toValue,
43
+ duration,
44
+ delay,
45
+ onComplete,
46
+ abort: () => !this.canvas ||
47
+ // we do not want to animate a selection, only cursor
48
+ this.selectionStart !== this.selectionEnd,
49
+ onChange: (value) => {
50
+ this._currentCursorOpacity = value;
51
+ this.renderCursorOrSelection();
52
+ },
53
+ });
54
+ }
55
+ /**
56
+ * changes the cursor from visible to invisible
57
+ */
58
+ _tick(delay) {
59
+ this._currentTickState = this._animateCursor({
60
+ toValue: 0,
61
+ duration: this.cursorDuration / 2,
62
+ delay: Math.max(delay || 0, 100),
63
+ onComplete: this._onTickComplete,
64
+ });
65
+ }
66
+ /**
67
+ * Changes the cursor from invisible to visible
68
+ */
69
+ _onTickComplete() {
70
+ this._currentTickCompleteState?.abort();
71
+ this._currentTickCompleteState = this._animateCursor({
72
+ toValue: 1,
73
+ duration: this.cursorDuration,
74
+ onComplete: this._tick,
75
+ });
76
+ }
77
+ /**
78
+ * Initializes delayed cursor
79
+ */
80
+ initDelayedCursor(restart) {
81
+ this.abortCursorAnimation();
82
+ this._tick(restart ? 0 : this.cursorDelay);
83
+ }
84
+ /**
85
+ * Aborts cursor animation, clears all timeouts and clear textarea context if necessary
86
+ */
87
+ abortCursorAnimation() {
88
+ let shouldClear = false;
89
+ [this._currentTickState, this._currentTickCompleteState].forEach((cursorAnimation) => {
90
+ if (cursorAnimation && !cursorAnimation.isDone()) {
91
+ shouldClear = true;
92
+ cursorAnimation.abort();
93
+ }
94
+ });
95
+ this._currentCursorOpacity = 1;
96
+ // make sure we clear context even if instance is not editing
97
+ if (shouldClear) {
98
+ this.clearContextTop();
99
+ }
100
+ }
101
+ /**
102
+ * Restart tue cursor animation if either is in complete state ( between animations )
103
+ * or if it never started before
104
+ */
105
+ restartCursorIfNeeded() {
106
+ if ([this._currentTickState, this._currentTickCompleteState].some((cursorAnimation) => !cursorAnimation || cursorAnimation.isDone())) {
107
+ this.initDelayedCursor();
108
+ }
109
+ }
110
+ /**
111
+ * Selects entire text
112
+ */
113
+ selectAll() {
114
+ this.selectionStart = 0;
115
+ this.selectionEnd = this._text.length;
116
+ this._fireSelectionChanged();
117
+ this._updateTextarea();
118
+ return this;
119
+ }
120
+ /**
121
+ * Selects entire text and updates the visual state
122
+ */
123
+ cmdAll() {
124
+ this.selectAll();
125
+ this.renderCursorOrSelection();
126
+ }
127
+ /**
128
+ * Returns selected text
129
+ * @return {String}
130
+ */
131
+ getSelectedText() {
132
+ return this._text.slice(this.selectionStart, this.selectionEnd).join('');
133
+ }
134
+ /**
135
+ * Find new selection index representing start of current word according to current selection index
136
+ * @param {Number} startFrom Current selection index
137
+ * @return {Number} New selection index
138
+ */
139
+ findWordBoundaryLeft(startFrom) {
140
+ let offset = 0, index = startFrom - 1;
141
+ // remove space before cursor first
142
+ if (this._reSpace.test(this._text[index])) {
143
+ while (this._reSpace.test(this._text[index])) {
144
+ offset++;
145
+ index--;
146
+ }
147
+ }
148
+ while (/\S/.test(this._text[index]) && index > -1) {
149
+ offset++;
150
+ index--;
151
+ }
152
+ return startFrom - offset;
153
+ }
154
+ /**
155
+ * Find new selection index representing end of current word according to current selection index
156
+ * @param {Number} startFrom Current selection index
157
+ * @return {Number} New selection index
158
+ */
159
+ findWordBoundaryRight(startFrom) {
160
+ let offset = 0, index = startFrom;
161
+ // remove space after cursor first
162
+ if (this._reSpace.test(this._text[index])) {
163
+ while (this._reSpace.test(this._text[index])) {
164
+ offset++;
165
+ index++;
166
+ }
167
+ }
168
+ while (/\S/.test(this._text[index]) && index < this._text.length) {
169
+ offset++;
170
+ index++;
171
+ }
172
+ return startFrom + offset;
173
+ }
174
+ /**
175
+ * Find new selection index representing start of current line according to current selection index
176
+ * @param {Number} startFrom Current selection index
177
+ * @return {Number} New selection index
178
+ */
179
+ findLineBoundaryLeft(startFrom) {
180
+ let offset = 0, index = startFrom - 1;
181
+ while (!/\n/.test(this._text[index]) && index > -1) {
182
+ offset++;
183
+ index--;
184
+ }
185
+ return startFrom - offset;
186
+ }
187
+ /**
188
+ * Find new selection index representing end of current line according to current selection index
189
+ * @param {Number} startFrom Current selection index
190
+ * @return {Number} New selection index
191
+ */
192
+ findLineBoundaryRight(startFrom) {
193
+ let offset = 0, index = startFrom;
194
+ while (!/\n/.test(this._text[index]) && index < this._text.length) {
195
+ offset++;
196
+ index++;
197
+ }
198
+ return startFrom + offset;
199
+ }
200
+ /**
201
+ * Finds index corresponding to beginning or end of a word
202
+ * @param {Number} selectionStart Index of a character
203
+ * @param {Number} direction 1 or -1
204
+ * @return {Number} Index of the beginning or end of a word
205
+ */
206
+ searchWordBoundary(selectionStart, direction) {
207
+ const text = this._text;
208
+ // if we land on a space we move the cursor backwards
209
+ // if we are searching boundary end we move the cursor backwards ONLY if we don't land on a line break
210
+ let index = selectionStart > 0 &&
211
+ this._reSpace.test(text[selectionStart]) &&
212
+ (direction === -1 || !reNewline.test(text[selectionStart - 1]))
213
+ ? selectionStart - 1
214
+ : selectionStart, _char = text[index];
215
+ while (index > 0 && index < text.length && !reNonWord.test(_char)) {
216
+ index += direction;
217
+ _char = text[index];
218
+ }
219
+ if (direction === -1 && reNonWord.test(_char)) {
220
+ index++;
221
+ }
222
+ return index;
223
+ }
224
+ /**
225
+ * Selects the word that contains the char at index selectionStart
226
+ * @param {Number} selectionStart Index of a character
227
+ */
228
+ selectWord(selectionStart) {
229
+ selectionStart = selectionStart ?? this.selectionStart;
230
+ // search backwards
231
+ const newSelectionStart = this.searchWordBoundary(selectionStart, -1),
232
+ // search forward
233
+ newSelectionEnd = Math.max(newSelectionStart, this.searchWordBoundary(selectionStart, 1));
234
+ this.selectionStart = newSelectionStart;
235
+ this.selectionEnd = newSelectionEnd;
236
+ this._fireSelectionChanged();
237
+ this._updateTextarea();
238
+ // remove next major, for now it renders twice :(
239
+ this.renderCursorOrSelection();
240
+ }
241
+ /**
242
+ * Selects the line that contains selectionStart
243
+ * @param {Number} selectionStart Index of a character
244
+ */
245
+ selectLine(selectionStart) {
246
+ selectionStart = selectionStart ?? this.selectionStart;
247
+ const newSelectionStart = this.findLineBoundaryLeft(selectionStart), newSelectionEnd = this.findLineBoundaryRight(selectionStart);
248
+ this.selectionStart = newSelectionStart;
249
+ this.selectionEnd = newSelectionEnd;
250
+ this._fireSelectionChanged();
251
+ this._updateTextarea();
252
+ }
253
+ /**
254
+ * Enters editing state
255
+ */
256
+ enterEditing(e) {
257
+ if (this.isEditing || !this.editable) {
258
+ return;
259
+ }
260
+ this.enterEditingImpl();
261
+ this.fire('editing:entered', e ? { e } : undefined);
262
+ this._fireSelectionChanged();
263
+ if (this.canvas) {
264
+ this.canvas.fire('text:editing:entered', {
265
+ target: this,
266
+ e,
267
+ });
268
+ this.canvas.requestRenderAll();
269
+ }
270
+ }
271
+ /**
272
+ * runs the actual logic that enter from editing state, see {@link enterEditing}
273
+ */
274
+ enterEditingImpl() {
275
+ if (this.canvas) {
276
+ this.canvas.calcOffset();
277
+ this.canvas.textEditingManager.exitTextEditing();
278
+ }
279
+ this.isEditing = true;
280
+ this.initHiddenTextarea();
281
+ this.hiddenTextarea.focus();
282
+ this.hiddenTextarea.value = this.text;
283
+ this._updateTextarea();
284
+ this._saveEditingProps();
285
+ this._setEditingProps();
286
+ this._textBeforeEdit = this.text;
287
+ this._tick();
288
+ }
289
+ /**
290
+ * called by {@link Canvas#textEditingManager}
291
+ */
292
+ updateSelectionOnMouseMove(e) {
293
+ if (this.getActiveControl()) {
294
+ return;
295
+ }
296
+ const el = this.hiddenTextarea;
297
+ // regain focus
298
+ getDocumentFromElement(el).activeElement !== el && el.focus();
299
+ const newSelectionStart = this.getSelectionStartFromPointer(e), currentStart = this.selectionStart, currentEnd = this.selectionEnd;
300
+ if ((newSelectionStart !== this.__selectionStartOnMouseDown ||
301
+ currentStart === currentEnd) &&
302
+ (currentStart === newSelectionStart || currentEnd === newSelectionStart)) {
303
+ return;
304
+ }
305
+ if (newSelectionStart > this.__selectionStartOnMouseDown) {
306
+ this.selectionStart = this.__selectionStartOnMouseDown;
307
+ this.selectionEnd = newSelectionStart;
308
+ }
309
+ else {
310
+ this.selectionStart = newSelectionStart;
311
+ this.selectionEnd = this.__selectionStartOnMouseDown;
312
+ }
313
+ if (this.selectionStart !== currentStart ||
314
+ this.selectionEnd !== currentEnd) {
315
+ this._fireSelectionChanged();
316
+ this._updateTextarea();
317
+ this.renderCursorOrSelection();
318
+ }
319
+ }
320
+ /**
321
+ * @private
322
+ */
323
+ _setEditingProps() {
324
+ this.hoverCursor = 'text';
325
+ if (this.canvas) {
326
+ this.canvas.defaultCursor = this.canvas.moveCursor = 'text';
327
+ }
328
+ this.borderColor = this.editingBorderColor;
329
+ this.hasControls = this.selectable = false;
330
+ this.lockMovementX = this.lockMovementY = true;
331
+ }
332
+ /**
333
+ * convert from textarea to grapheme indexes
334
+ */
335
+ fromStringToGraphemeSelection(start, end, text) {
336
+ const smallerTextStart = text.slice(0, start), graphemeStart = this.graphemeSplit(smallerTextStart).length;
337
+ if (start === end) {
338
+ return { selectionStart: graphemeStart, selectionEnd: graphemeStart };
339
+ }
340
+ const smallerTextEnd = text.slice(start, end), graphemeEnd = this.graphemeSplit(smallerTextEnd).length;
341
+ return {
342
+ selectionStart: graphemeStart,
343
+ selectionEnd: graphemeStart + graphemeEnd,
344
+ };
345
+ }
346
+ /**
347
+ * convert from fabric to textarea values
348
+ */
349
+ fromGraphemeToStringSelection(start, end, graphemes) {
350
+ const smallerTextStart = graphemes.slice(0, start), graphemeStart = smallerTextStart.join('').length;
351
+ if (start === end) {
352
+ return { selectionStart: graphemeStart, selectionEnd: graphemeStart };
353
+ }
354
+ const smallerTextEnd = graphemes.slice(start, end), graphemeEnd = smallerTextEnd.join('').length;
355
+ return {
356
+ selectionStart: graphemeStart,
357
+ selectionEnd: graphemeStart + graphemeEnd,
358
+ };
359
+ }
360
+ /**
361
+ * @private
362
+ */
363
+ _updateTextarea() {
364
+ this.cursorOffsetCache = {};
365
+ if (!this.hiddenTextarea) {
366
+ return;
367
+ }
368
+ if (!this.inCompositionMode) {
369
+ const newSelection = this.fromGraphemeToStringSelection(this.selectionStart, this.selectionEnd, this._text);
370
+ this.hiddenTextarea.selectionStart = newSelection.selectionStart;
371
+ this.hiddenTextarea.selectionEnd = newSelection.selectionEnd;
372
+ }
373
+ this.updateTextareaPosition();
374
+ }
375
+ /**
376
+ * @private
377
+ */
378
+ updateFromTextArea() {
379
+ if (!this.hiddenTextarea) {
380
+ return;
381
+ }
382
+ this.cursorOffsetCache = {};
383
+ const textarea = this.hiddenTextarea;
384
+ this.text = textarea.value;
385
+ this.set('dirty', true);
386
+ this.initDimensions();
387
+ this.setCoords();
388
+ const newSelection = this.fromStringToGraphemeSelection(textarea.selectionStart, textarea.selectionEnd, textarea.value);
389
+ this.selectionEnd = this.selectionStart = newSelection.selectionEnd;
390
+ if (!this.inCompositionMode) {
391
+ this.selectionStart = newSelection.selectionStart;
392
+ }
393
+ this.updateTextareaPosition();
394
+ }
395
+ /**
396
+ * @private
397
+ */
398
+ updateTextareaPosition() {
399
+ if (this.selectionStart === this.selectionEnd) {
400
+ const style = this._calcTextareaPosition();
401
+ this.hiddenTextarea.style.left = style.left;
402
+ this.hiddenTextarea.style.top = style.top;
403
+ }
404
+ }
405
+ /**
406
+ * @private
407
+ * @return {Object} style contains style for hiddenTextarea
408
+ */
409
+ _calcTextareaPosition() {
410
+ if (!this.canvas) {
411
+ return { left: '1px', top: '1px' };
412
+ }
413
+ const desiredPosition = this.inCompositionMode
414
+ ? this.compositionStart
415
+ : this.selectionStart, boundaries = this._getCursorBoundaries(desiredPosition), cursorLocation = this.get2DCursorLocation(desiredPosition), lineIndex = cursorLocation.lineIndex, charIndex = cursorLocation.charIndex, charHeight = this.getValueOfPropertyAt(lineIndex, charIndex, 'fontSize') *
416
+ this.lineHeight, leftOffset = boundaries.leftOffset, retinaScaling = this.getCanvasRetinaScaling(), upperCanvas = this.canvas.upperCanvasEl, upperCanvasWidth = upperCanvas.width / retinaScaling, upperCanvasHeight = upperCanvas.height / retinaScaling, maxWidth = upperCanvasWidth - charHeight, maxHeight = upperCanvasHeight - charHeight;
417
+ const p = new Point(boundaries.left + leftOffset, boundaries.top + boundaries.topOffset + charHeight)
418
+ .transform(this.calcTransformMatrix())
419
+ .transform(this.canvas.viewportTransform)
420
+ .multiply(new Point(upperCanvas.clientWidth / upperCanvasWidth, upperCanvas.clientHeight / upperCanvasHeight));
421
+ if (p.x < 0) {
422
+ p.x = 0;
423
+ }
424
+ if (p.x > maxWidth) {
425
+ p.x = maxWidth;
426
+ }
427
+ if (p.y < 0) {
428
+ p.y = 0;
429
+ }
430
+ if (p.y > maxHeight) {
431
+ p.y = maxHeight;
432
+ }
433
+ // add canvas offset on document
434
+ p.x += this.canvas._offset.left;
435
+ p.y += this.canvas._offset.top;
436
+ return {
437
+ left: `${p.x}px`,
438
+ top: `${p.y}px`,
439
+ fontSize: `${charHeight}px`,
440
+ charHeight: charHeight,
441
+ };
442
+ }
443
+ /**
444
+ * @private
445
+ */
446
+ _saveEditingProps() {
447
+ this._savedProps = {
448
+ hasControls: this.hasControls,
449
+ borderColor: this.borderColor,
450
+ lockMovementX: this.lockMovementX,
451
+ lockMovementY: this.lockMovementY,
452
+ hoverCursor: this.hoverCursor,
453
+ selectable: this.selectable,
454
+ defaultCursor: this.canvas && this.canvas.defaultCursor,
455
+ moveCursor: this.canvas && this.canvas.moveCursor,
456
+ };
457
+ }
458
+ /**
459
+ * @private
460
+ */
461
+ _restoreEditingProps() {
462
+ if (!this._savedProps) {
463
+ return;
464
+ }
465
+ this.hoverCursor = this._savedProps.hoverCursor;
466
+ this.hasControls = this._savedProps.hasControls;
467
+ this.borderColor = this._savedProps.borderColor;
468
+ this.selectable = this._savedProps.selectable;
469
+ this.lockMovementX = this._savedProps.lockMovementX;
470
+ this.lockMovementY = this._savedProps.lockMovementY;
471
+ if (this.canvas) {
472
+ this.canvas.defaultCursor =
473
+ this._savedProps.defaultCursor || this.canvas.defaultCursor;
474
+ this.canvas.moveCursor =
475
+ this._savedProps.moveCursor || this.canvas.moveCursor;
476
+ }
477
+ delete this._savedProps;
478
+ }
479
+ /**
480
+ * runs the actual logic that exits from editing state, see {@link exitEditing}
481
+ * Please use exitEditingImpl, this function was kept to avoid breaking changes.
482
+ * Will be removed in fabric 7.0
483
+ * @deprecated use "exitEditingImpl"
484
+ */
485
+ _exitEditing() {
486
+ const hiddenTextarea = this.hiddenTextarea;
487
+ this.selected = false;
488
+ this.isEditing = false;
489
+ if (hiddenTextarea) {
490
+ hiddenTextarea.blur && hiddenTextarea.blur();
491
+ hiddenTextarea.parentNode &&
492
+ hiddenTextarea.parentNode.removeChild(hiddenTextarea);
493
+ }
494
+ this.hiddenTextarea = null;
495
+ this.abortCursorAnimation();
496
+ this.selectionStart !== this.selectionEnd && this.clearContextTop();
497
+ }
498
+ /**
499
+ * runs the actual logic that exits from editing state, see {@link exitEditing}
500
+ * But it does not fire events
501
+ */
502
+ exitEditingImpl() {
503
+ this._exitEditing();
504
+ this.selectionEnd = this.selectionStart;
505
+ this._restoreEditingProps();
506
+ if (this._forceClearCache) {
507
+ this.initDimensions();
508
+ this.setCoords();
509
+ }
510
+ }
511
+ /**
512
+ * Exits from editing state and fires relevant events
513
+ */
514
+ exitEditing() {
515
+ const isTextChanged = this._textBeforeEdit !== this.text;
516
+ this.exitEditingImpl();
517
+ this.fire('editing:exited');
518
+ isTextChanged && this.fire(MODIFIED);
519
+ if (this.canvas) {
520
+ this.canvas.fire('text:editing:exited', {
521
+ target: this,
522
+ });
523
+ // todo: evaluate add an action to this event
524
+ isTextChanged && this.canvas.fire('object:modified', { target: this });
525
+ }
526
+ return this;
527
+ }
528
+ /**
529
+ * @private
530
+ */
531
+ _removeExtraneousStyles() {
532
+ for (const prop in this.styles) {
533
+ if (!this._textLines[prop]) {
534
+ delete this.styles[prop];
535
+ }
536
+ }
537
+ }
538
+ /**
539
+ * remove and reflow a style block from start to end.
540
+ * @param {Number} start linear start position for removal (included in removal)
541
+ * @param {Number} end linear end position for removal ( excluded from removal )
542
+ */
543
+ removeStyleFromTo(start, end) {
544
+ const { lineIndex: lineStart, charIndex: charStart } = this.get2DCursorLocation(start, true), { lineIndex: lineEnd, charIndex: charEnd } = this.get2DCursorLocation(end, true);
545
+ if (lineStart !== lineEnd) {
546
+ // step1 remove the trailing of lineStart
547
+ if (this.styles[lineStart]) {
548
+ for (let i = charStart; i < this._unwrappedTextLines[lineStart].length; i++) {
549
+ delete this.styles[lineStart][i];
550
+ }
551
+ }
552
+ // step2 move the trailing of lineEnd to lineStart if needed
553
+ if (this.styles[lineEnd]) {
554
+ for (let i = charEnd; i < this._unwrappedTextLines[lineEnd].length; i++) {
555
+ const styleObj = this.styles[lineEnd][i];
556
+ if (styleObj) {
557
+ this.styles[lineStart] || (this.styles[lineStart] = {});
558
+ this.styles[lineStart][charStart + i - charEnd] = styleObj;
559
+ }
560
+ }
561
+ }
562
+ // step3 detects lines will be completely removed.
563
+ for (let i = lineStart + 1; i <= lineEnd; i++) {
564
+ delete this.styles[i];
565
+ }
566
+ // step4 shift remaining lines.
567
+ this.shiftLineStyles(lineEnd, lineStart - lineEnd);
568
+ }
569
+ else {
570
+ // remove and shift left on the same line
571
+ if (this.styles[lineStart]) {
572
+ const styleObj = this.styles[lineStart];
573
+ const diff = charEnd - charStart;
574
+ for (let i = charStart; i < charEnd; i++) {
575
+ delete styleObj[i];
576
+ }
577
+ for (const char in this.styles[lineStart]) {
578
+ const numericChar = parseInt(char, 10);
579
+ if (numericChar >= charEnd) {
580
+ styleObj[numericChar - diff] = styleObj[char];
581
+ delete styleObj[char];
582
+ }
583
+ }
584
+ }
585
+ }
586
+ }
587
+ /**
588
+ * Shifts line styles up or down
589
+ * @param {Number} lineIndex Index of a line
590
+ * @param {Number} offset Can any number?
591
+ */
592
+ shiftLineStyles(lineIndex, offset) {
593
+ const clonedStyles = Object.assign({}, this.styles);
594
+ for (const line in this.styles) {
595
+ const numericLine = parseInt(line, 10);
596
+ if (numericLine > lineIndex) {
597
+ this.styles[numericLine + offset] = clonedStyles[numericLine];
598
+ if (!clonedStyles[numericLine - offset]) {
599
+ delete this.styles[numericLine];
600
+ }
601
+ }
602
+ }
603
+ }
604
+ /**
605
+ * Handle insertion of more consecutive style lines for when one or more
606
+ * newlines gets added to the text. Since current style needs to be shifted
607
+ * first we shift the current style of the number lines needed, then we add
608
+ * new lines from the last to the first.
609
+ * @param {Number} lineIndex Index of a line
610
+ * @param {Number} charIndex Index of a char
611
+ * @param {Number} qty number of lines to add
612
+ * @param {Array} copiedStyle Array of objects styles
613
+ */
614
+ insertNewlineStyleObject(lineIndex, charIndex, qty, copiedStyle) {
615
+ const newLineStyles = {};
616
+ const originalLineLength = this._unwrappedTextLines[lineIndex].length;
617
+ const isEndOfLine = originalLineLength === charIndex;
618
+ let someStyleIsCarryingOver = false;
619
+ qty || (qty = 1);
620
+ this.shiftLineStyles(lineIndex, qty);
621
+ const currentCharStyle = this.styles[lineIndex]
622
+ ? this.styles[lineIndex][charIndex === 0 ? charIndex : charIndex - 1]
623
+ : undefined;
624
+ // we clone styles of all chars
625
+ // after cursor onto the current line
626
+ for (const index in this.styles[lineIndex]) {
627
+ const numIndex = parseInt(index, 10);
628
+ if (numIndex >= charIndex) {
629
+ someStyleIsCarryingOver = true;
630
+ newLineStyles[numIndex - charIndex] = this.styles[lineIndex][index];
631
+ // remove lines from the previous line since they're on a new line now
632
+ if (!(isEndOfLine && charIndex === 0)) {
633
+ delete this.styles[lineIndex][index];
634
+ }
635
+ }
636
+ }
637
+ let styleCarriedOver = false;
638
+ if (someStyleIsCarryingOver && !isEndOfLine) {
639
+ // if is end of line, the extra style we copied
640
+ // is probably not something we want
641
+ this.styles[lineIndex + qty] = newLineStyles;
642
+ styleCarriedOver = true;
643
+ }
644
+ if (styleCarriedOver || originalLineLength > charIndex) {
645
+ // skip the last line of since we already prepared it.
646
+ // or contains text without style that we don't want to style
647
+ // just because it changed lines
648
+ qty--;
649
+ }
650
+ // for the all the lines or all the other lines
651
+ // we clone current char style onto the next (otherwise empty) line
652
+ while (qty > 0) {
653
+ if (copiedStyle && copiedStyle[qty - 1]) {
654
+ this.styles[lineIndex + qty] = {
655
+ 0: { ...copiedStyle[qty - 1] },
656
+ };
657
+ }
658
+ else if (currentCharStyle) {
659
+ this.styles[lineIndex + qty] = {
660
+ 0: { ...currentCharStyle },
661
+ };
662
+ }
663
+ else {
664
+ delete this.styles[lineIndex + qty];
665
+ }
666
+ qty--;
667
+ }
668
+ this._forceClearCache = true;
669
+ }
670
+ /**
671
+ * Inserts style object for a given line/char index
672
+ * @param {Number} lineIndex Index of a line
673
+ * @param {Number} charIndex Index of a char
674
+ * @param {Number} quantity number Style object to insert, if given
675
+ * @param {Array} copiedStyle array of style objects
676
+ */
677
+ insertCharStyleObject(lineIndex, charIndex, quantity, copiedStyle) {
678
+ if (!this.styles) {
679
+ this.styles = {};
680
+ }
681
+ const currentLineStyles = this.styles[lineIndex], currentLineStylesCloned = currentLineStyles
682
+ ? { ...currentLineStyles }
683
+ : {};
684
+ quantity || (quantity = 1);
685
+ // shift all char styles by quantity forward
686
+ // 0,1,2,3 -> (charIndex=2) -> 0,1,3,4 -> (insert 2) -> 0,1,2,3,4
687
+ for (const index in currentLineStylesCloned) {
688
+ const numericIndex = parseInt(index, 10);
689
+ if (numericIndex >= charIndex) {
690
+ currentLineStyles[numericIndex + quantity] =
691
+ currentLineStylesCloned[numericIndex];
692
+ // only delete the style if there was nothing moved there
693
+ if (!currentLineStylesCloned[numericIndex - quantity]) {
694
+ delete currentLineStyles[numericIndex];
695
+ }
696
+ }
697
+ }
698
+ this._forceClearCache = true;
699
+ if (copiedStyle) {
700
+ while (quantity--) {
701
+ if (!Object.keys(copiedStyle[quantity]).length) {
702
+ continue;
703
+ }
704
+ if (!this.styles[lineIndex]) {
705
+ this.styles[lineIndex] = {};
706
+ }
707
+ this.styles[lineIndex][charIndex + quantity] = {
708
+ ...copiedStyle[quantity],
709
+ };
710
+ }
711
+ return;
712
+ }
713
+ if (!currentLineStyles) {
714
+ return;
715
+ }
716
+ const newStyle = currentLineStyles[charIndex ? charIndex - 1 : 1];
717
+ while (newStyle && quantity--) {
718
+ this.styles[lineIndex][charIndex + quantity] = { ...newStyle };
719
+ }
720
+ }
721
+ /**
722
+ * Inserts style object(s)
723
+ * @param {Array} insertedText Characters at the location where style is inserted
724
+ * @param {Number} start cursor index for inserting style
725
+ * @param {Array} [copiedStyle] array of style objects to insert.
726
+ */
727
+ insertNewStyleBlock(insertedText, start, copiedStyle) {
728
+ const cursorLoc = this.get2DCursorLocation(start, true), addedLines = [0];
729
+ let linesLength = 0;
730
+ // get an array of how many char per lines are being added.
731
+ for (let i = 0; i < insertedText.length; i++) {
732
+ if (insertedText[i] === '\n') {
733
+ linesLength++;
734
+ addedLines[linesLength] = 0;
735
+ }
736
+ else {
737
+ addedLines[linesLength]++;
738
+ }
739
+ }
740
+ // for the first line copy the style from the current char position.
741
+ if (addedLines[0] > 0) {
742
+ this.insertCharStyleObject(cursorLoc.lineIndex, cursorLoc.charIndex, addedLines[0], copiedStyle);
743
+ copiedStyle = copiedStyle && copiedStyle.slice(addedLines[0] + 1);
744
+ }
745
+ linesLength &&
746
+ this.insertNewlineStyleObject(cursorLoc.lineIndex, cursorLoc.charIndex + addedLines[0], linesLength);
747
+ let i;
748
+ for (i = 1; i < linesLength; i++) {
749
+ if (addedLines[i] > 0) {
750
+ this.insertCharStyleObject(cursorLoc.lineIndex + i, 0, addedLines[i], copiedStyle);
751
+ }
752
+ else if (copiedStyle) {
753
+ // this test is required in order to close #6841
754
+ // when a pasted buffer begins with a newline then
755
+ // this.styles[cursorLoc.lineIndex + i] and copiedStyle[0]
756
+ // may be undefined for some reason
757
+ if (this.styles[cursorLoc.lineIndex + i] && copiedStyle[0]) {
758
+ this.styles[cursorLoc.lineIndex + i][0] = copiedStyle[0];
759
+ }
760
+ }
761
+ copiedStyle = copiedStyle && copiedStyle.slice(addedLines[i] + 1);
762
+ }
763
+ if (addedLines[i] > 0) {
764
+ this.insertCharStyleObject(cursorLoc.lineIndex + i, 0, addedLines[i], copiedStyle);
765
+ }
766
+ }
767
+ /**
768
+ * Removes characters from start/end
769
+ * start/end ar per grapheme position in _text array.
770
+ *
771
+ * @param {Number} start
772
+ * @param {Number} end default to start + 1
773
+ */
774
+ removeChars(start, end = start + 1) {
775
+ this.removeStyleFromTo(start, end);
776
+ this._text.splice(start, end - start);
777
+ this.text = this._text.join('');
778
+ this.set('dirty', true);
779
+ this.initDimensions();
780
+ this.setCoords();
781
+ this._removeExtraneousStyles();
782
+ }
783
+ /**
784
+ * insert characters at start position, before start position.
785
+ * start equal 1 it means the text get inserted between actual grapheme 0 and 1
786
+ * if style array is provided, it must be as the same length of text in graphemes
787
+ * if end is provided and is bigger than start, old text is replaced.
788
+ * start/end ar per grapheme position in _text array.
789
+ *
790
+ * @param {String} text text to insert
791
+ * @param {Array} style array of style objects
792
+ * @param {Number} start
793
+ * @param {Number} end default to start + 1
794
+ */
795
+ insertChars(text, style, start, end = start) {
796
+ if (end > start) {
797
+ this.removeStyleFromTo(start, end);
798
+ }
799
+ const graphemes = this.graphemeSplit(text);
800
+ this.insertNewStyleBlock(graphemes, start, style);
801
+ this._text = [
802
+ ...this._text.slice(0, start),
803
+ ...graphemes,
804
+ ...this._text.slice(end),
805
+ ];
806
+ this.text = this._text.join('');
807
+ this.set('dirty', true);
808
+ this.initDimensions();
809
+ this.setCoords();
810
+ this._removeExtraneousStyles();
811
+ }
812
+ /**
813
+ * Set the selectionStart and selectionEnd according to the new position of cursor
814
+ * mimic the key - mouse navigation when shift is pressed.
815
+ */
816
+ setSelectionStartEndWithShift(start, end, newSelection) {
817
+ if (newSelection <= start) {
818
+ if (end === start) {
819
+ this._selectionDirection = LEFT;
820
+ }
821
+ else if (this._selectionDirection === RIGHT) {
822
+ this._selectionDirection = LEFT;
823
+ this.selectionEnd = start;
824
+ }
825
+ this.selectionStart = newSelection;
826
+ }
827
+ else if (newSelection > start && newSelection < end) {
828
+ if (this._selectionDirection === RIGHT) {
829
+ this.selectionEnd = newSelection;
830
+ }
831
+ else {
832
+ this.selectionStart = newSelection;
833
+ }
834
+ }
835
+ else {
836
+ // newSelection is > selection start and end
837
+ if (end === start) {
838
+ this._selectionDirection = RIGHT;
839
+ }
840
+ else if (this._selectionDirection === LEFT) {
841
+ this._selectionDirection = RIGHT;
842
+ this.selectionStart = end;
843
+ }
844
+ this.selectionEnd = newSelection;
845
+ }
846
+ }
847
+ }
848
+ //# sourceMappingURL=ITextBehavior.js.map