fabric-vectr 6.7.16 → 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 (601) 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 +2 -2
  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 +2 -2
  46. package/dist/index.mjs.map +1 -1
  47. package/dist/index.node.cjs +2 -2
  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 +2 -2
  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.js +910 -0
  474. package/dist/src/shapes/Textbox.js.map +1 -0
  475. package/dist/src/shapes/Triangle.js +47 -0
  476. package/dist/src/shapes/Triangle.js.map +1 -0
  477. package/dist/src/typedefs.js +2 -0
  478. package/dist/src/typedefs.js.map +1 -0
  479. package/dist/src/util/animation/AnimationBase.js +94 -0
  480. package/dist/src/util/animation/AnimationBase.js.map +1 -0
  481. package/dist/src/util/animation/AnimationFrameProvider.js +8 -0
  482. package/dist/src/util/animation/AnimationFrameProvider.js.map +1 -0
  483. package/dist/src/util/animation/AnimationRegistry.js +49 -0
  484. package/dist/src/util/animation/AnimationRegistry.js.map +1 -0
  485. package/dist/src/util/animation/ArrayAnimation.js +18 -0
  486. package/dist/src/util/animation/ArrayAnimation.js.map +1 -0
  487. package/dist/src/util/animation/ColorAnimation.js +43 -0
  488. package/dist/src/util/animation/ColorAnimation.js.map +1 -0
  489. package/dist/src/util/animation/ValueAnimation.js +18 -0
  490. package/dist/src/util/animation/ValueAnimation.js.map +1 -0
  491. package/dist/src/util/animation/animate.js +19 -0
  492. package/dist/src/util/animation/animate.js.map +1 -0
  493. package/dist/src/util/animation/easing.js +265 -0
  494. package/dist/src/util/animation/easing.js.map +1 -0
  495. package/dist/src/util/animation/index.js +3 -0
  496. package/dist/src/util/animation/index.js.map +1 -0
  497. package/dist/src/util/animation/types.js +2 -0
  498. package/dist/src/util/animation/types.js.map +1 -0
  499. package/dist/src/util/applyMixins.js +14 -0
  500. package/dist/src/util/applyMixins.js.map +1 -0
  501. package/dist/src/util/dom_event.js +21 -0
  502. package/dist/src/util/dom_event.js.map +1 -0
  503. package/dist/src/util/dom_misc.js +42 -0
  504. package/dist/src/util/dom_misc.js.map +1 -0
  505. package/dist/src/util/dom_style.js +19 -0
  506. package/dist/src/util/dom_style.js.map +1 -0
  507. package/dist/src/util/index.js +36 -0
  508. package/dist/src/util/index.js.map +1 -0
  509. package/dist/src/util/internals/applyCanvasTransform.js +15 -0
  510. package/dist/src/util/internals/applyCanvasTransform.js.map +1 -0
  511. package/dist/src/util/internals/cleanupSvgAttribute.js +8 -0
  512. package/dist/src/util/internals/cleanupSvgAttribute.js.map +1 -0
  513. package/dist/src/util/internals/cloneDeep.js +8 -0
  514. package/dist/src/util/internals/cloneDeep.js.map +1 -0
  515. package/dist/src/util/internals/cloneStyles.js +11 -0
  516. package/dist/src/util/internals/cloneStyles.js.map +1 -0
  517. package/dist/src/util/internals/console.js +14 -0
  518. package/dist/src/util/internals/console.js.map +1 -0
  519. package/dist/src/util/internals/dom_request.js +39 -0
  520. package/dist/src/util/internals/dom_request.js.map +1 -0
  521. package/dist/src/util/internals/findRight.js +9 -0
  522. package/dist/src/util/internals/findRight.js.map +1 -0
  523. package/dist/src/util/internals/getRandomInt.js +8 -0
  524. package/dist/src/util/internals/getRandomInt.js.map +1 -0
  525. package/dist/src/util/internals/ifNaN.js +10 -0
  526. package/dist/src/util/internals/ifNaN.js.map +1 -0
  527. package/dist/src/util/internals/removeFromArray.js +15 -0
  528. package/dist/src/util/internals/removeFromArray.js.map +1 -0
  529. package/dist/src/util/internals/uid.js +3 -0
  530. package/dist/src/util/internals/uid.js.map +1 -0
  531. package/dist/src/util/lang_string.js +93 -0
  532. package/dist/src/util/lang_string.js.map +1 -0
  533. package/dist/src/util/misc/boundingBoxFromPoints.js +26 -0
  534. package/dist/src/util/misc/boundingBoxFromPoints.js.map +1 -0
  535. package/dist/src/util/misc/capValue.js +2 -0
  536. package/dist/src/util/misc/capValue.js.map +1 -0
  537. package/dist/src/util/misc/cos.js +23 -0
  538. package/dist/src/util/misc/cos.js.map +1 -0
  539. package/dist/src/util/misc/dom.js +55 -0
  540. package/dist/src/util/misc/dom.js.map +1 -0
  541. package/dist/src/util/misc/findScaleTo.js +19 -0
  542. package/dist/src/util/misc/findScaleTo.js.map +1 -0
  543. package/dist/src/util/misc/groupSVGElements.js +15 -0
  544. package/dist/src/util/misc/groupSVGElements.js.map +1 -0
  545. package/dist/src/util/misc/isTransparent.js +23 -0
  546. package/dist/src/util/misc/isTransparent.js.map +1 -0
  547. package/dist/src/util/misc/matrix.js +238 -0
  548. package/dist/src/util/misc/matrix.js.map +1 -0
  549. package/dist/src/util/misc/mergeClipPaths.js +39 -0
  550. package/dist/src/util/misc/mergeClipPaths.js.map +1 -0
  551. package/dist/src/util/misc/objectEnlive.js +136 -0
  552. package/dist/src/util/misc/objectEnlive.js.map +1 -0
  553. package/dist/src/util/misc/objectTransforms.js +89 -0
  554. package/dist/src/util/misc/objectTransforms.js.map +1 -0
  555. package/dist/src/util/misc/pick.js +23 -0
  556. package/dist/src/util/misc/pick.js.map +1 -0
  557. package/dist/src/util/misc/planeChange.js +68 -0
  558. package/dist/src/util/misc/planeChange.js.map +1 -0
  559. package/dist/src/util/misc/projectStroke/StrokeLineCapProjections.js +105 -0
  560. package/dist/src/util/misc/projectStroke/StrokeLineCapProjections.js.map +1 -0
  561. package/dist/src/util/misc/projectStroke/StrokeLineJoinProjections.js +219 -0
  562. package/dist/src/util/misc/projectStroke/StrokeLineJoinProjections.js.map +1 -0
  563. package/dist/src/util/misc/projectStroke/StrokeProjectionsBase.js +42 -0
  564. package/dist/src/util/misc/projectStroke/StrokeProjectionsBase.js.map +1 -0
  565. package/dist/src/util/misc/projectStroke/index.js +61 -0
  566. package/dist/src/util/misc/projectStroke/index.js.map +1 -0
  567. package/dist/src/util/misc/projectStroke/types.js +2 -0
  568. package/dist/src/util/misc/projectStroke/types.js.map +1 -0
  569. package/dist/src/util/misc/radiansDegreesConversion.js +14 -0
  570. package/dist/src/util/misc/radiansDegreesConversion.js.map +1 -0
  571. package/dist/src/util/misc/resolveOrigin.js +17 -0
  572. package/dist/src/util/misc/resolveOrigin.js.map +1 -0
  573. package/dist/src/util/misc/rotatePoint.js +10 -0
  574. package/dist/src/util/misc/rotatePoint.js.map +1 -0
  575. package/dist/src/util/misc/sin.js +25 -0
  576. package/dist/src/util/misc/sin.js.map +1 -0
  577. package/dist/src/util/misc/svgExport.js +13 -0
  578. package/dist/src/util/misc/svgExport.js.map +1 -0
  579. package/dist/src/util/misc/svgParsing.js +129 -0
  580. package/dist/src/util/misc/svgParsing.js.map +1 -0
  581. package/dist/src/util/misc/textStyles.js +107 -0
  582. package/dist/src/util/misc/textStyles.js.map +1 -0
  583. package/dist/src/util/misc/toFixed.js +8 -0
  584. package/dist/src/util/misc/toFixed.js.map +1 -0
  585. package/dist/src/util/misc/vectors.js +77 -0
  586. package/dist/src/util/misc/vectors.js.map +1 -0
  587. package/dist/src/util/path/index.js +743 -0
  588. package/dist/src/util/path/index.js.map +1 -0
  589. package/dist/src/util/path/regex.js +33 -0
  590. package/dist/src/util/path/regex.js.map +1 -0
  591. package/dist/src/util/path/typechecks.js +67 -0
  592. package/dist/src/util/path/typechecks.js.map +1 -0
  593. package/dist/src/util/path/typedefs.js +2 -0
  594. package/dist/src/util/path/typedefs.js.map +1 -0
  595. package/dist/src/util/transform_matrix_removal.js +46 -0
  596. package/dist/src/util/transform_matrix_removal.js.map +1 -0
  597. package/dist/src/util/typeAssertions.js +21 -0
  598. package/dist/src/util/typeAssertions.js.map +1 -0
  599. package/dist-extensions/src/gradient/Gradient.d.ts.map +1 -1
  600. package/package.json +1 -1
  601. package/src/gradient/Gradient.ts +5 -2
@@ -0,0 +1,1258 @@
1
+ import { cache } from '../../cache';
2
+ import { FILL, STROKE } from '../../constants';
3
+ import { StyledText } from './StyledText';
4
+ import { SHARED_ATTRIBUTES } from '../../parser/attributes';
5
+ import { classRegistry } from '../../ClassRegistry';
6
+ import { graphemeSplit } from '../../util/lang_string';
7
+ import { createCanvasElementFor } from '../../util/misc/dom';
8
+ import { hasStyleChanged, stylesFromArray, stylesToArray, } from '../../util/misc/textStyles';
9
+ import { getPathSegmentsInfo, getPointOnPath } from '../../util/path';
10
+ import { cacheProperties } from '../Object/FabricObject';
11
+ import { TextSVGExportMixin } from './TextSVGExportMixin';
12
+ import { applyMixins } from '../../util/applyMixins';
13
+ import { additionalProps, textDefaultValues, textLayoutProperties, JUSTIFY, JUSTIFY_CENTER, JUSTIFY_LEFT, JUSTIFY_RIGHT, TEXT_DECORATION_THICKNESS, } from './constants';
14
+ import { CENTER, LEFT, RIGHT, TOP, BOTTOM } from '../../constants';
15
+ import { isFiller } from '../../util/typeAssertions';
16
+ import { renderCircleControl, renderSquareControl } from '../../controls';
17
+ let measuringContext;
18
+ /**
19
+ * Return a context for measurement of text string.
20
+ * if created it gets stored for reuse
21
+ */
22
+ function getMeasuringContext() {
23
+ if (!measuringContext) {
24
+ const canvas = createCanvasElementFor({
25
+ width: 0,
26
+ height: 0,
27
+ });
28
+ measuringContext = canvas.getContext('2d');
29
+ }
30
+ return measuringContext;
31
+ }
32
+ /**
33
+ * Text class
34
+ * @tutorial {@link http://fabricjs.com/fabric-intro-part-2#text}
35
+ */
36
+ export class FabricText extends StyledText {
37
+ /**
38
+ * Properties that requires a text layout recalculation when changed
39
+ * @type string[]
40
+ * @protected
41
+ */
42
+ static textLayoutProperties = textLayoutProperties;
43
+ /**
44
+ * contains characters bounding boxes
45
+ * This variable is considered to be protected.
46
+ * But for how mixins are implemented right now, we can't leave it private
47
+ * @protected
48
+ */
49
+ __charBounds = [];
50
+ static cacheProperties = [...cacheProperties, ...additionalProps];
51
+ static ownDefaults = textDefaultValues;
52
+ /**
53
+ * James add
54
+ * 是否启用计算文字高度
55
+ */
56
+ static enableCalcTextHeight;
57
+ static type = 'Text';
58
+ static getDefaults() {
59
+ return { ...super.getDefaults(), ...FabricText.ownDefaults };
60
+ }
61
+ constructor(text, options) {
62
+ super();
63
+ Object.assign(this, FabricText.ownDefaults);
64
+ this.setOptions(options);
65
+ if (!this.styles) {
66
+ this.styles = {};
67
+ }
68
+ this.text = text;
69
+ this.initialized = true;
70
+ if (this.path) {
71
+ this.setPathInfo();
72
+ }
73
+ this.initDimensions();
74
+ this.setCoords();
75
+ }
76
+ /**
77
+ * If text has a path, it will add the extra information needed
78
+ * for path and text calculations
79
+ */
80
+ setPathInfo() {
81
+ const path = this.path;
82
+ if (path) {
83
+ path.segmentsInfo = getPathSegmentsInfo(path.path);
84
+ // James modified 检查空路径的话,设置path为空
85
+ if (!path.width && !path.height) {
86
+ console.log(this, 'text path empty');
87
+ this.path = undefined;
88
+ }
89
+ }
90
+ }
91
+ /**
92
+ * @private
93
+ * Divides text into lines of text and lines of graphemes.
94
+ */
95
+ _splitText() {
96
+ const newLines = this._splitTextIntoLines(this.text);
97
+ this.textLines = newLines.lines;
98
+ this._textLines = newLines.graphemeLines;
99
+ this._unwrappedTextLines = newLines._unwrappedLines;
100
+ this._text = newLines.graphemeText;
101
+ return newLines;
102
+ }
103
+ /**
104
+ * Initialize or update text dimensions.
105
+ * Updates this.width and this.height with the proper values.
106
+ * Does not return dimensions.
107
+ */
108
+ initDimensions() {
109
+ this._splitText();
110
+ this._clearCache();
111
+ this.dirty = true;
112
+ if (this.path) {
113
+ this.width = this.path.width;
114
+ this.height = this.path.height;
115
+ }
116
+ else {
117
+ this.width =
118
+ this.calcTextWidth() || this.cursorWidth || this.MIN_TEXT_WIDTH;
119
+ this.height = this.calcTextHeight();
120
+ }
121
+ if (this.textAlign.includes(JUSTIFY)) {
122
+ // once text is measured we need to make space fatter to make justified text.
123
+ this.enlargeSpaces();
124
+ }
125
+ }
126
+ /**
127
+ * Enlarge space boxes and shift the others
128
+ */
129
+ enlargeSpaces() {
130
+ let diffSpace, currentLineWidth, numberOfSpaces, accumulatedSpace, line, charBound, spaces;
131
+ for (let i = 0, len = this._textLines.length; i < len; i++) {
132
+ if (this.textAlign !== JUSTIFY &&
133
+ (i === len - 1 || this.isEndOfWrapping(i))) {
134
+ continue;
135
+ }
136
+ accumulatedSpace = 0;
137
+ line = this._textLines[i];
138
+ currentLineWidth = this.getLineWidth(i);
139
+ if (currentLineWidth < this.width &&
140
+ (spaces = this.textLines[i].match(this._reSpacesAndTabs))) {
141
+ numberOfSpaces = spaces.length;
142
+ diffSpace = (this.width - currentLineWidth) / numberOfSpaces;
143
+ for (let j = 0; j <= line.length; j++) {
144
+ charBound = this.__charBounds[i][j];
145
+ if (this._reSpaceAndTab.test(line[j])) {
146
+ charBound.width += diffSpace;
147
+ charBound.kernedWidth += diffSpace;
148
+ charBound.left += accumulatedSpace;
149
+ accumulatedSpace += diffSpace;
150
+ }
151
+ else {
152
+ charBound.left += accumulatedSpace;
153
+ }
154
+ }
155
+ }
156
+ }
157
+ }
158
+ /**
159
+ * Detect if the text line is ended with an hard break
160
+ * text and itext do not have wrapping, return false
161
+ * @return {Boolean}
162
+ */
163
+ isEndOfWrapping(lineIndex) {
164
+ return lineIndex === this._textLines.length - 1;
165
+ }
166
+ missingNewlineOffset(_lineIndex) {
167
+ return 1;
168
+ }
169
+ /**
170
+ * Returns 2d representation (lineIndex and charIndex) of cursor
171
+ * @param {Number} selectionStart
172
+ * @param {Boolean} [skipWrapping] consider the location for unwrapped lines. useful to manage styles.
173
+ */
174
+ get2DCursorLocation(selectionStart, skipWrapping) {
175
+ const lines = skipWrapping ? this._unwrappedTextLines : this._textLines;
176
+ let i;
177
+ for (i = 0; i < lines.length; i++) {
178
+ if (selectionStart <= lines[i].length) {
179
+ return {
180
+ lineIndex: i,
181
+ charIndex: selectionStart,
182
+ };
183
+ }
184
+ selectionStart -=
185
+ lines[i].length + this.missingNewlineOffset(i, skipWrapping);
186
+ }
187
+ return {
188
+ lineIndex: i - 1,
189
+ charIndex: lines[i - 1].length < selectionStart
190
+ ? lines[i - 1].length
191
+ : selectionStart,
192
+ };
193
+ }
194
+ /**
195
+ * Returns string representation of an instance
196
+ * @return {String} String representation of text object
197
+ */
198
+ toString() {
199
+ return `#<Text (${this.complexity()}): { "text": "${this.text}", "fontFamily": "${this.fontFamily}" }>`;
200
+ }
201
+ /**
202
+ * Return the dimension and the zoom level needed to create a cache canvas
203
+ * big enough to host the object to be cached.
204
+ * @private
205
+ * @param {Object} dim.x width of object to be cached
206
+ * @param {Object} dim.y height of object to be cached
207
+ * @return {Object}.width width of canvas
208
+ * @return {Object}.height height of canvas
209
+ * @return {Object}.zoomX zoomX zoom value to unscale the canvas before drawing cache
210
+ * @return {Object}.zoomY zoomY zoom value to unscale the canvas before drawing cache
211
+ */
212
+ _getCacheCanvasDimensions() {
213
+ const dims = super._getCacheCanvasDimensions();
214
+ const fontSize = this.fontSize;
215
+ dims.width += fontSize * dims.zoomX * 2;
216
+ dims.height += fontSize * dims.zoomY * 2;
217
+ return dims;
218
+ }
219
+ /**
220
+ * @private
221
+ * @param {CanvasRenderingContext2D} ctx Context to render on
222
+ */
223
+ _render(ctx) {
224
+ const path = this.path;
225
+ path && !path.isNotVisible() && path._render(ctx);
226
+ this._setTextStyles(ctx);
227
+ this._renderTextLinesBackground(ctx);
228
+ this._renderTextDecoration(ctx, 'underline');
229
+ this._renderText(ctx);
230
+ this._renderTextDecoration(ctx, 'overline');
231
+ this._renderTextDecoration(ctx, 'linethrough');
232
+ }
233
+ /**
234
+ * @private
235
+ * @param {CanvasRenderingContext2D} ctx Context to render on
236
+ */
237
+ _renderText(ctx) {
238
+ if (this.paintFirst === STROKE) {
239
+ this._renderTextStroke(ctx);
240
+ this._renderTextFill(ctx);
241
+ }
242
+ else {
243
+ this._renderTextFill(ctx);
244
+ this._renderTextStroke(ctx);
245
+ }
246
+ }
247
+ /**
248
+ * Set the font parameter of the context with the object properties or with charStyle
249
+ * @private
250
+ * @param {CanvasRenderingContext2D} ctx Context to render on
251
+ * @param {Object} [charStyle] object with font style properties
252
+ * @param {String} [charStyle.fontFamily] Font Family
253
+ * @param {Number} [charStyle.fontSize] Font size in pixels. ( without px suffix )
254
+ * @param {String} [charStyle.fontWeight] Font weight
255
+ * @param {String} [charStyle.fontStyle] Font style (italic|normal)
256
+ */
257
+ _setTextStyles(ctx, charStyle, forMeasuring) {
258
+ ctx.textBaseline = 'alphabetic';
259
+ if (this.path) {
260
+ switch (this.pathAlign) {
261
+ case CENTER:
262
+ ctx.textBaseline = 'middle';
263
+ break;
264
+ case 'ascender':
265
+ ctx.textBaseline = TOP;
266
+ break;
267
+ case 'descender':
268
+ ctx.textBaseline = BOTTOM;
269
+ break;
270
+ }
271
+ }
272
+ ctx.font = this._getFontDeclaration(charStyle, forMeasuring);
273
+ }
274
+ /**
275
+ * calculate and return the text Width measuring each line.
276
+ * @private
277
+ * @param {CanvasRenderingContext2D} ctx Context to render on
278
+ * @return {Number} Maximum width of Text object
279
+ */
280
+ calcTextWidth() {
281
+ let maxWidth = this.getLineWidth(0);
282
+ for (let i = 1, len = this._textLines.length; i < len; i++) {
283
+ const currentLineWidth = this.getLineWidth(i);
284
+ if (currentLineWidth > maxWidth) {
285
+ maxWidth = currentLineWidth;
286
+ }
287
+ }
288
+ return maxWidth;
289
+ }
290
+ /**
291
+ * @private
292
+ * @param {String} method Method name ("fillText" or "strokeText")
293
+ * @param {CanvasRenderingContext2D} ctx Context to render on
294
+ * @param {String} line Text to render
295
+ * @param {Number} left Left position of text
296
+ * @param {Number} top Top position of text
297
+ * @param {Number} lineIndex Index of a line in a text
298
+ */
299
+ _renderTextLine(method, ctx, line, left, top, lineIndex) {
300
+ this._renderChars(method, ctx, line, left, top, lineIndex);
301
+ }
302
+ /**
303
+ * Renders the text background for lines, taking care of style
304
+ * @private
305
+ * @param {CanvasRenderingContext2D} ctx Context to render on
306
+ */
307
+ _renderTextLinesBackground(ctx) {
308
+ if (!this.textBackgroundColor && !this.styleHas('textBackgroundColor')) {
309
+ return;
310
+ }
311
+ const originalFill = ctx.fillStyle, leftOffset = this._getLeftOffset();
312
+ let lineTopOffset = this._getTopOffset();
313
+ for (let i = 0, len = this._textLines.length; i < len; i++) {
314
+ const heightOfLine = this.getHeightOfLine(i);
315
+ if (!this.textBackgroundColor &&
316
+ !this.styleHas('textBackgroundColor', i)) {
317
+ lineTopOffset += heightOfLine;
318
+ continue;
319
+ }
320
+ const jlen = this._textLines[i].length;
321
+ const lineLeftOffset = this._getLineLeftOffset(i);
322
+ let boxWidth = 0;
323
+ let boxStart = 0;
324
+ let drawStart;
325
+ let currentColor;
326
+ let lastColor = this.getValueOfPropertyAt(i, 0, 'textBackgroundColor');
327
+ for (let j = 0; j < jlen; j++) {
328
+ // at this point charbox are either standard or full with pathInfo if there is a path.
329
+ const charBox = this.__charBounds[i][j];
330
+ currentColor = this.getValueOfPropertyAt(i, j, 'textBackgroundColor');
331
+ // James modified
332
+ if (this.path && !this.isEditing) {
333
+ ctx.save();
334
+ ctx.translate(charBox.renderLeft, charBox.renderTop);
335
+ ctx.rotate(charBox.angle);
336
+ ctx.fillStyle = currentColor;
337
+ currentColor &&
338
+ ctx.fillRect(-charBox.width / 2, (-heightOfLine / this.lineHeight) * (1 - this._fontSizeFraction), charBox.width, heightOfLine / this.lineHeight);
339
+ ctx.restore();
340
+ }
341
+ else if (currentColor !== lastColor) {
342
+ drawStart = leftOffset + lineLeftOffset + boxStart;
343
+ if (this.direction === 'rtl') {
344
+ drawStart = this.width - drawStart - boxWidth;
345
+ }
346
+ ctx.fillStyle = lastColor;
347
+ lastColor &&
348
+ ctx.fillRect(drawStart, lineTopOffset, boxWidth, heightOfLine / this.lineHeight);
349
+ boxStart = charBox.left;
350
+ boxWidth = charBox.width;
351
+ lastColor = currentColor;
352
+ }
353
+ else {
354
+ boxWidth += charBox.kernedWidth;
355
+ }
356
+ }
357
+ if (currentColor && !this.path) {
358
+ drawStart = leftOffset + lineLeftOffset + boxStart;
359
+ if (this.direction === 'rtl') {
360
+ drawStart = this.width - drawStart - boxWidth;
361
+ }
362
+ ctx.fillStyle = currentColor;
363
+ ctx.fillRect(drawStart, lineTopOffset, boxWidth, heightOfLine / this.lineHeight);
364
+ }
365
+ lineTopOffset += heightOfLine;
366
+ }
367
+ ctx.fillStyle = originalFill;
368
+ // if there is text background color no
369
+ // other shadows should be casted
370
+ this._removeShadow(ctx);
371
+ }
372
+ /**
373
+ * measure and return the width of a single character.
374
+ * possibly overridden to accommodate different measure logic or
375
+ * to hook some external lib for character measurement
376
+ * @private
377
+ * @param {String} _char, char to be measured
378
+ * @param {Object} charStyle style of char to be measured
379
+ * @param {String} [previousChar] previous char
380
+ * @param {Object} [prevCharStyle] style of previous char
381
+ */
382
+ _measureChar(_char, charStyle, previousChar, prevCharStyle) {
383
+ const fontCache = cache.getFontCache(charStyle), fontDeclaration = this._getFontDeclaration(charStyle), couple = previousChar + _char, stylesAreEqual = previousChar &&
384
+ fontDeclaration === this._getFontDeclaration(prevCharStyle), fontMultiplier = charStyle.fontSize / this.CACHE_FONT_SIZE;
385
+ let width, coupleWidth, previousWidth, kernedWidth;
386
+ if (previousChar && fontCache[previousChar] !== undefined) {
387
+ previousWidth = fontCache[previousChar];
388
+ }
389
+ if (fontCache[_char] !== undefined) {
390
+ kernedWidth = width = fontCache[_char];
391
+ }
392
+ if (stylesAreEqual && fontCache[couple] !== undefined) {
393
+ coupleWidth = fontCache[couple];
394
+ kernedWidth = coupleWidth - previousWidth;
395
+ }
396
+ if (width === undefined ||
397
+ previousWidth === undefined ||
398
+ coupleWidth === undefined) {
399
+ const ctx = getMeasuringContext();
400
+ // send a TRUE to specify measuring font size CACHE_FONT_SIZE
401
+ this._setTextStyles(ctx, charStyle, true);
402
+ if (width === undefined) {
403
+ kernedWidth = width = ctx.measureText(_char).width;
404
+ fontCache[_char] = width;
405
+ }
406
+ if (previousWidth === undefined && stylesAreEqual && previousChar) {
407
+ previousWidth = ctx.measureText(previousChar).width;
408
+ fontCache[previousChar] = previousWidth;
409
+ }
410
+ if (stylesAreEqual && coupleWidth === undefined) {
411
+ // we can measure the kerning couple and subtract the width of the previous character
412
+ coupleWidth = ctx.measureText(couple).width;
413
+ fontCache[couple] = coupleWidth;
414
+ // safe to use the non-null since if undefined we defined it before.
415
+ kernedWidth = coupleWidth - previousWidth;
416
+ }
417
+ }
418
+ return {
419
+ width: width * fontMultiplier,
420
+ kernedWidth: kernedWidth * fontMultiplier,
421
+ };
422
+ }
423
+ /**
424
+ * Computes height of character at given position
425
+ * @param {Number} line the line index number
426
+ * @param {Number} _char the character index number
427
+ * @return {Number} fontSize of the character
428
+ */
429
+ getHeightOfChar(line, _char) {
430
+ return this.getValueOfPropertyAt(line, _char, 'fontSize');
431
+ }
432
+ /**
433
+ * measure a text line measuring all characters.
434
+ * @param {Number} lineIndex line number
435
+ */
436
+ measureLine(lineIndex) {
437
+ const lineInfo = this._measureLine(lineIndex);
438
+ if (this.charSpacing !== 0) {
439
+ lineInfo.width -= this._getWidthOfCharSpacing();
440
+ }
441
+ if (lineInfo.width < 0) {
442
+ lineInfo.width = 0;
443
+ }
444
+ return lineInfo;
445
+ }
446
+ /**
447
+ * measure every grapheme of a line, populating __charBounds
448
+ * @param {Number} lineIndex
449
+ * @return {Object} object.width total width of characters
450
+ * @return {Object} object.numOfSpaces length of chars that match this._reSpacesAndTabs
451
+ */
452
+ _measureLine(lineIndex) {
453
+ let width = 0, prevGrapheme, graphemeInfo;
454
+ const reverse = this.pathSide === RIGHT, path = this.path, line = this._textLines[lineIndex], llength = line.length, lineBounds = new Array(llength);
455
+ this.__charBounds[lineIndex] = lineBounds;
456
+ for (let i = 0; i < llength; i++) {
457
+ const grapheme = line[i];
458
+ graphemeInfo = this._getGraphemeBox(grapheme, lineIndex, i, prevGrapheme);
459
+ lineBounds[i] = graphemeInfo;
460
+ width += graphemeInfo.kernedWidth;
461
+ prevGrapheme = grapheme;
462
+ }
463
+ // this latest bound box represent the last character of the line
464
+ // to simplify cursor handling in interactive mode.
465
+ lineBounds[llength] = {
466
+ left: graphemeInfo ? graphemeInfo.left + graphemeInfo.width : 0,
467
+ width: 0,
468
+ kernedWidth: 0,
469
+ height: this.fontSize,
470
+ deltaY: 0,
471
+ };
472
+ if (path && path.segmentsInfo) {
473
+ let positionInPath = 0;
474
+ const totalPathLength = path.segmentsInfo[path.segmentsInfo.length - 1].length;
475
+ switch (this.textAlign) {
476
+ case LEFT:
477
+ positionInPath = reverse ? totalPathLength - width : 0;
478
+ break;
479
+ case CENTER:
480
+ positionInPath = (totalPathLength - width) / 2;
481
+ break;
482
+ case RIGHT:
483
+ positionInPath = reverse ? 0 : totalPathLength - width;
484
+ break;
485
+ //todo - add support for justify
486
+ }
487
+ positionInPath += this.pathStartOffset * (reverse ? -1 : 1);
488
+ for (let i = reverse ? llength - 1 : 0; reverse ? i >= 0 : i < llength; reverse ? i-- : i++) {
489
+ graphemeInfo = lineBounds[i];
490
+ // James modified
491
+ /* if (positionInPath > totalPathLength) {
492
+ positionInPath %= totalPathLength;
493
+ } else if (positionInPath < 0) {
494
+ positionInPath += totalPathLength;
495
+ } */
496
+ // 超过路径范围外不显示
497
+ var visible = false;
498
+ var tolerance = 2;
499
+ if (positionInPath >= 0 - tolerance &&
500
+ positionInPath + graphemeInfo.kernedWidth <=
501
+ totalPathLength + tolerance) {
502
+ visible = true;
503
+ }
504
+ if (visible) {
505
+ // it would probably much faster to send all the grapheme position for a line
506
+ // and calculate path position/angle at once.
507
+ this._setGraphemeOnPath(positionInPath, graphemeInfo);
508
+ }
509
+ positionInPath += graphemeInfo.kernedWidth;
510
+ graphemeInfo.visible = visible;
511
+ }
512
+ }
513
+ return { width: width, numOfSpaces: 0 };
514
+ }
515
+ /**
516
+ * Calculate the angle and the left,top position of the char that follow a path.
517
+ * It appends it to graphemeInfo to be reused later at rendering
518
+ * @private
519
+ * @param {Number} positionInPath to be measured
520
+ * @param {GraphemeBBox} graphemeInfo current grapheme box information
521
+ * @param {Object} startingPoint position of the point
522
+ */
523
+ _setGraphemeOnPath(positionInPath, graphemeInfo) {
524
+ const centerPosition = positionInPath + graphemeInfo.kernedWidth / 2, path = this.path;
525
+ // we are at currentPositionOnPath. we want to know what point on the path is.
526
+ const info = getPointOnPath(path.path, centerPosition, path.segmentsInfo);
527
+ graphemeInfo.renderLeft = info.x - path.pathOffset.x;
528
+ graphemeInfo.renderTop = info.y - path.pathOffset.y;
529
+ graphemeInfo.angle = info.angle + (this.pathSide === RIGHT ? Math.PI : 0);
530
+ }
531
+ /**
532
+ *
533
+ * @param {String} grapheme to be measured
534
+ * @param {Number} lineIndex index of the line where the char is
535
+ * @param {Number} charIndex position in the line
536
+ * @param {String} [prevGrapheme] character preceding the one to be measured
537
+ * @returns {GraphemeBBox} grapheme bbox
538
+ */
539
+ _getGraphemeBox(grapheme, lineIndex, charIndex, prevGrapheme, skipLeft) {
540
+ const style = this.getCompleteStyleDeclaration(lineIndex, charIndex), prevStyle = prevGrapheme
541
+ ? this.getCompleteStyleDeclaration(lineIndex, charIndex - 1)
542
+ : {}, info = this._measureChar(grapheme, style, prevGrapheme, prevStyle);
543
+ let kernedWidth = info.kernedWidth, width = info.width, charSpacing;
544
+ if (this.charSpacing !== 0) {
545
+ charSpacing = this._getWidthOfCharSpacing();
546
+ width += charSpacing;
547
+ kernedWidth += charSpacing;
548
+ }
549
+ const box = {
550
+ width,
551
+ left: 0,
552
+ height: style.fontSize,
553
+ kernedWidth,
554
+ deltaY: style.deltaY,
555
+ };
556
+ if (charIndex > 0 && !skipLeft) {
557
+ const previousBox = this.__charBounds[lineIndex][charIndex - 1];
558
+ box.left =
559
+ previousBox.left + previousBox.width + info.kernedWidth - info.width;
560
+ }
561
+ return box;
562
+ }
563
+ /**
564
+ * Calculate height of line at 'lineIndex'
565
+ * @param {Number} lineIndex index of line to calculate
566
+ * @return {Number}
567
+ */
568
+ getHeightOfLine(lineIndex) {
569
+ if (this.__lineHeights[lineIndex]) {
570
+ return this.__lineHeights[lineIndex];
571
+ }
572
+ // char 0 is measured before the line cycle because it needs to char
573
+ // emptylines
574
+ let maxHeight = this.getHeightOfChar(lineIndex, 0);
575
+ for (let i = 1, len = this._textLines[lineIndex].length; i < len; i++) {
576
+ maxHeight = Math.max(this.getHeightOfChar(lineIndex, i), maxHeight);
577
+ }
578
+ return (this.__lineHeights[lineIndex] =
579
+ maxHeight * this.lineHeight * this._fontSizeMult);
580
+ }
581
+ /**
582
+ * Calculate text box height
583
+ */
584
+ calcTextHeight() {
585
+ let lineHeight, height = 0;
586
+ for (let i = 0, len = this._textLines.length; i < len; i++) {
587
+ lineHeight = this.getHeightOfLine(i);
588
+ height += i === len - 1 ? lineHeight / this.lineHeight : lineHeight;
589
+ }
590
+ return height;
591
+ }
592
+ /**
593
+ * @private
594
+ * @return {Number} Left offset
595
+ */
596
+ _getLeftOffset() {
597
+ return this.direction === 'ltr' ? -this.width / 2 : this.width / 2;
598
+ }
599
+ /**
600
+ * @private
601
+ * @return {Number} Top offset
602
+ */
603
+ _getTopOffset() {
604
+ return -this.height / 2;
605
+ }
606
+ /**
607
+ * James add
608
+ * 是否应该按行隐藏文字
609
+ * @returns
610
+ */
611
+ _shouldHideTextLine() {
612
+ return !this.isEditing && !this.path;
613
+ }
614
+ /**
615
+ * James modified
616
+ * 框子外的文字不绘制
617
+ * @private
618
+ * @param {CanvasRenderingContext2D} ctx Context to render on
619
+ * @param {String} method Method name ("fillText" or "strokeText")
620
+ */
621
+ _renderTextCommon(ctx, method) {
622
+ ctx.save();
623
+ let lineHeights = 0;
624
+ const left = this._getLeftOffset(), top = this._getTopOffset();
625
+ // 存在隐藏文字
626
+ this.hasHideText = false;
627
+ for (let i = 0, len = this._textLines.length; i < len; i++) {
628
+ const heightOfLine = this.getHeightOfLine(i), maxHeight = heightOfLine / this.lineHeight, leftOffset = this._getLineLeftOffset(i);
629
+ // 非编辑状态超过box 不显示
630
+ if (this._shouldHideTextLine() &&
631
+ lineHeights + maxHeight * 0.8 > this.height) {
632
+ this.hasHideText = true;
633
+ break;
634
+ }
635
+ this._renderTextLine(method, ctx, this._textLines[i], left + leftOffset, top + lineHeights + maxHeight, i);
636
+ lineHeights += heightOfLine;
637
+ }
638
+ ctx.restore();
639
+ }
640
+ /**
641
+ * James add
642
+ * 增加隐藏文字图标
643
+ */
644
+ showHideTextIcon() {
645
+ const control = this.controls?.['mb'];
646
+ if (control) {
647
+ control.render = (ctx, left, top, styleOverride, fabricObject) => {
648
+ styleOverride = styleOverride || {};
649
+ if (this.hasHideText) {
650
+ styleOverride = {
651
+ ...styleOverride,
652
+ cornerStrokeColor: '#FF0000',
653
+ cornerSize: 10,
654
+ };
655
+ }
656
+ switch (styleOverride.cornerStyle || fabricObject.cornerStyle) {
657
+ case 'circle':
658
+ renderCircleControl.call(control, ctx, left, top, styleOverride, fabricObject);
659
+ break;
660
+ default:
661
+ renderSquareControl.call(control, ctx, left, top, styleOverride, fabricObject);
662
+ }
663
+ };
664
+ }
665
+ }
666
+ /**
667
+ * @private
668
+ * @param {CanvasRenderingContext2D} ctx Context to render on
669
+ */
670
+ _renderTextFill(ctx) {
671
+ if (!this.fill && !this.styleHas(FILL)) {
672
+ return;
673
+ }
674
+ this._renderTextCommon(ctx, 'fillText');
675
+ }
676
+ /**
677
+ * @private
678
+ * @param {CanvasRenderingContext2D} ctx Context to render on
679
+ */
680
+ _renderTextStroke(ctx) {
681
+ if ((!this.stroke || this.strokeWidth === 0) && this.isEmptyStyles()) {
682
+ return;
683
+ }
684
+ if (this.shadow && !this.shadow.affectStroke) {
685
+ this._removeShadow(ctx);
686
+ }
687
+ ctx.save();
688
+ this._setLineDash(ctx, this.strokeDashArray);
689
+ ctx.beginPath();
690
+ this._renderTextCommon(ctx, 'strokeText');
691
+ ctx.closePath();
692
+ ctx.restore();
693
+ }
694
+ /**
695
+ * @private
696
+ * @param {String} method fillText or strokeText.
697
+ * @param {CanvasRenderingContext2D} ctx Context to render on
698
+ * @param {Array} line Content of the line, splitted in an array by grapheme
699
+ * @param {Number} left
700
+ * @param {Number} top
701
+ * @param {Number} lineIndex
702
+ */
703
+ _renderChars(method, ctx, line, left, top, lineIndex) {
704
+ const lineHeight = this.getHeightOfLine(lineIndex), isJustify = this.textAlign.includes(JUSTIFY), path = this.path, shortCut = !isJustify &&
705
+ this.charSpacing === 0 &&
706
+ this.isEmptyStyles(lineIndex) &&
707
+ !path, isLtr = this.direction === 'ltr', sign = this.direction === 'ltr' ? 1 : -1,
708
+ // James modified
709
+ // 修改为之前绘制 direction rtl的方式,5.3.0版本的绘制方式显示有问题
710
+ // this was changed in the PR #7674
711
+ // currentDirection = ctx.canvas.getAttribute('dir');
712
+ currentDirection = ctx.direction;
713
+ let actualStyle, nextStyle, charsToRender = '', charBox, boxWidth = 0, timeToRender, drawingLeft;
714
+ ctx.save();
715
+ if (currentDirection !== this.direction) {
716
+ ctx.canvas.setAttribute('dir', isLtr ? 'ltr' : 'rtl');
717
+ // James modified
718
+ ctx.direction = isLtr ? 'ltr' : 'rtl';
719
+ ctx.textAlign = isLtr ? LEFT : RIGHT;
720
+ }
721
+ top -= (lineHeight * this._fontSizeFraction) / this.lineHeight;
722
+ if (shortCut) {
723
+ // render all the line in one pass without checking
724
+ // drawingLeft = isLtr ? left : left - this.getLineWidth(lineIndex);
725
+ // James modified
726
+ this._renderChar(method, ctx, lineIndex, 0, line.join(''), left, top);
727
+ ctx.restore();
728
+ return;
729
+ }
730
+ for (let i = 0, len = line.length - 1; i <= len; i++) {
731
+ timeToRender = i === len || this.charSpacing || path;
732
+ charsToRender += line[i];
733
+ charBox = this.__charBounds[lineIndex][i];
734
+ if (boxWidth === 0) {
735
+ left += sign * (charBox.kernedWidth - charBox.width);
736
+ boxWidth += charBox.width;
737
+ }
738
+ else {
739
+ boxWidth += charBox.kernedWidth;
740
+ }
741
+ if (isJustify && !timeToRender) {
742
+ if (this._reSpaceAndTab.test(line[i])) {
743
+ timeToRender = true;
744
+ }
745
+ }
746
+ if (!timeToRender) {
747
+ // if we have charSpacing, we render char by char
748
+ actualStyle =
749
+ actualStyle || this.getCompleteStyleDeclaration(lineIndex, i);
750
+ nextStyle = this.getCompleteStyleDeclaration(lineIndex, i + 1);
751
+ timeToRender = hasStyleChanged(actualStyle, nextStyle, false);
752
+ }
753
+ if (timeToRender) {
754
+ // James modified
755
+ if (path && !this.isEditing) {
756
+ if (charBox.visible) {
757
+ ctx.save();
758
+ ctx.translate(charBox.renderLeft, charBox.renderTop);
759
+ ctx.rotate(charBox.angle);
760
+ this._renderChar(method, ctx, lineIndex, i, charsToRender, -boxWidth / 2, 0);
761
+ ctx.restore();
762
+ }
763
+ }
764
+ else {
765
+ drawingLeft = left;
766
+ this._renderChar(method, ctx, lineIndex, i, charsToRender, drawingLeft, top);
767
+ }
768
+ charsToRender = '';
769
+ actualStyle = nextStyle;
770
+ left += sign * boxWidth;
771
+ boxWidth = 0;
772
+ }
773
+ }
774
+ ctx.restore();
775
+ }
776
+ /**
777
+ * This function try to patch the missing gradientTransform on canvas gradients.
778
+ * transforming a context to transform the gradient, is going to transform the stroke too.
779
+ * we want to transform the gradient but not the stroke operation, so we create
780
+ * a transformed gradient on a pattern and then we use the pattern instead of the gradient.
781
+ * this method has drawbacks: is slow, is in low resolution, needs a patch for when the size
782
+ * is limited.
783
+ * @private
784
+ * @param {TFiller} filler a fabric gradient instance
785
+ * @return {CanvasPattern} a pattern to use as fill/stroke style
786
+ */
787
+ _applyPatternGradientTransformText(filler) {
788
+ // TODO: verify compatibility with strokeUniform
789
+ const width = this.width + this.strokeWidth, height = this.height + this.strokeWidth, pCanvas = createCanvasElementFor({
790
+ width,
791
+ height,
792
+ }), pCtx = pCanvas.getContext('2d');
793
+ pCanvas.width = width;
794
+ pCanvas.height = height;
795
+ pCtx.beginPath();
796
+ pCtx.moveTo(0, 0);
797
+ pCtx.lineTo(width, 0);
798
+ pCtx.lineTo(width, height);
799
+ pCtx.lineTo(0, height);
800
+ pCtx.closePath();
801
+ pCtx.translate(width / 2, height / 2);
802
+ pCtx.fillStyle = filler.toLive(pCtx);
803
+ this._applyPatternGradientTransform(pCtx, filler);
804
+ pCtx.fill();
805
+ return pCtx.createPattern(pCanvas, 'no-repeat');
806
+ }
807
+ handleFiller(ctx, property, filler) {
808
+ let offsetX, offsetY;
809
+ if (isFiller(filler)) {
810
+ if (filler.gradientUnits === 'percentage' ||
811
+ filler.gradientTransform ||
812
+ filler.patternTransform) {
813
+ // need to transform gradient in a pattern.
814
+ // this is a slow process. If you are hitting this codepath, and the object
815
+ // is not using caching, you should consider switching it on.
816
+ // we need a canvas as big as the current object caching canvas.
817
+ offsetX = -this.width / 2;
818
+ offsetY = -this.height / 2;
819
+ ctx.translate(offsetX, offsetY);
820
+ ctx[property] = this._applyPatternGradientTransformText(filler);
821
+ return { offsetX, offsetY };
822
+ }
823
+ else {
824
+ // is a simple gradient or pattern
825
+ ctx[property] = filler.toLive(ctx);
826
+ return this._applyPatternGradientTransform(ctx, filler);
827
+ }
828
+ }
829
+ else {
830
+ // is a color
831
+ ctx[property] = filler;
832
+ }
833
+ return { offsetX: 0, offsetY: 0 };
834
+ }
835
+ /**
836
+ * This function prepare the canvas for a stroke style, and stroke and strokeWidth
837
+ * need to be sent in as defined
838
+ * @param {CanvasRenderingContext2D} ctx
839
+ * @param {CompleteTextStyleDeclaration} style with stroke and strokeWidth defined
840
+ * @returns
841
+ */
842
+ _setStrokeStyles(ctx, { stroke, strokeWidth, }) {
843
+ ctx.lineWidth = strokeWidth;
844
+ ctx.lineCap = this.strokeLineCap;
845
+ ctx.lineDashOffset = this.strokeDashOffset;
846
+ ctx.lineJoin = this.strokeLineJoin;
847
+ ctx.miterLimit = this.strokeMiterLimit;
848
+ return this.handleFiller(ctx, 'strokeStyle', stroke);
849
+ }
850
+ /**
851
+ * This function prepare the canvas for a ill style, and fill
852
+ * need to be sent in as defined
853
+ * @param {CanvasRenderingContext2D} ctx
854
+ * @param {CompleteTextStyleDeclaration} style with ill defined
855
+ * @returns
856
+ */
857
+ _setFillStyles(ctx, { fill }) {
858
+ return this.handleFiller(ctx, 'fillStyle', fill);
859
+ }
860
+ /**
861
+ * @private
862
+ * @param {String} method
863
+ * @param {CanvasRenderingContext2D} ctx Context to render on
864
+ * @param {Number} lineIndex
865
+ * @param {Number} charIndex
866
+ * @param {String} _char
867
+ * @param {Number} left Left coordinate
868
+ * @param {Number} top Top coordinate
869
+ * @param {Number} lineHeight Height of the line
870
+ */
871
+ _renderChar(method, ctx, lineIndex, charIndex, _char, left, top) {
872
+ const decl = this._getStyleDeclaration(lineIndex, charIndex), fullDecl = this.getCompleteStyleDeclaration(lineIndex, charIndex), shouldFill = method === 'fillText' && fullDecl.fill, shouldStroke = method === 'strokeText' && fullDecl.stroke && fullDecl.strokeWidth;
873
+ if (!shouldStroke && !shouldFill) {
874
+ return;
875
+ }
876
+ ctx.save();
877
+ ctx.font = this._getFontDeclaration(fullDecl);
878
+ if (decl.textBackgroundColor) {
879
+ this._removeShadow(ctx);
880
+ }
881
+ if (decl.deltaY) {
882
+ top += decl.deltaY;
883
+ }
884
+ if (shouldFill) {
885
+ const fillOffsets = this._setFillStyles(ctx, fullDecl);
886
+ ctx.fillText(_char, left - fillOffsets.offsetX, top - fillOffsets.offsetY);
887
+ }
888
+ if (shouldStroke) {
889
+ const strokeOffsets = this._setStrokeStyles(ctx, fullDecl);
890
+ ctx.strokeText(_char, left - strokeOffsets.offsetX, top - strokeOffsets.offsetY);
891
+ }
892
+ ctx.restore();
893
+ }
894
+ /**
895
+ * Turns the character into a 'superior figure' (i.e. 'superscript')
896
+ * @param {Number} start selection start
897
+ * @param {Number} end selection end
898
+ */
899
+ setSuperscript(start, end) {
900
+ this._setScript(start, end, this.superscript);
901
+ }
902
+ /**
903
+ * Turns the character into an 'inferior figure' (i.e. 'subscript')
904
+ * @param {Number} start selection start
905
+ * @param {Number} end selection end
906
+ */
907
+ setSubscript(start, end) {
908
+ this._setScript(start, end, this.subscript);
909
+ }
910
+ /**
911
+ * Applies 'schema' at given position
912
+ * @private
913
+ * @param {Number} start selection start
914
+ * @param {Number} end selection end
915
+ * @param {Number} schema
916
+ */
917
+ _setScript(start, end, schema) {
918
+ const loc = this.get2DCursorLocation(start, true), fontSize = this.getValueOfPropertyAt(loc.lineIndex, loc.charIndex, 'fontSize'), dy = this.getValueOfPropertyAt(loc.lineIndex, loc.charIndex, 'deltaY'), style = {
919
+ fontSize: fontSize * schema.size,
920
+ deltaY: dy + fontSize * schema.baseline,
921
+ };
922
+ this.setSelectionStyles(style, start, end);
923
+ }
924
+ /**
925
+ * @private
926
+ * @param {Number} lineIndex index text line
927
+ * @return {Number} Line left offset
928
+ */
929
+ _getLineLeftOffset(lineIndex) {
930
+ const lineWidth = this.getLineWidth(lineIndex), lineDiff = this.width - lineWidth, textAlign = this.textAlign, direction = this.direction, isEndOfWrapping = this.isEndOfWrapping(lineIndex);
931
+ let leftOffset = 0;
932
+ if (textAlign === JUSTIFY ||
933
+ (textAlign === JUSTIFY_CENTER && !isEndOfWrapping) ||
934
+ (textAlign === JUSTIFY_RIGHT && !isEndOfWrapping) ||
935
+ (textAlign === JUSTIFY_LEFT && !isEndOfWrapping)) {
936
+ return 0;
937
+ }
938
+ if (textAlign === CENTER) {
939
+ leftOffset = lineDiff / 2;
940
+ }
941
+ if (textAlign === RIGHT) {
942
+ leftOffset = lineDiff;
943
+ }
944
+ if (textAlign === JUSTIFY_CENTER) {
945
+ leftOffset = lineDiff / 2;
946
+ }
947
+ if (textAlign === JUSTIFY_RIGHT) {
948
+ leftOffset = lineDiff;
949
+ }
950
+ if (direction === 'rtl') {
951
+ if (textAlign === RIGHT ||
952
+ textAlign === JUSTIFY ||
953
+ textAlign === JUSTIFY_RIGHT) {
954
+ leftOffset = 0;
955
+ }
956
+ else if (textAlign === LEFT || textAlign === JUSTIFY_LEFT) {
957
+ leftOffset = -lineDiff;
958
+ }
959
+ else if (textAlign === CENTER || textAlign === JUSTIFY_CENTER) {
960
+ leftOffset = -lineDiff / 2;
961
+ }
962
+ }
963
+ return leftOffset;
964
+ }
965
+ /**
966
+ * @private
967
+ */
968
+ _clearCache() {
969
+ this._forceClearCache = false;
970
+ this.__lineWidths = [];
971
+ this.__lineHeights = [];
972
+ this.__charBounds = [];
973
+ }
974
+ /**
975
+ * Measure a single line given its index. Used to calculate the initial
976
+ * text bounding box. The values are calculated and stored in __lineWidths cache.
977
+ * @private
978
+ * @param {Number} lineIndex line number
979
+ * @return {Number} Line width
980
+ */
981
+ getLineWidth(lineIndex) {
982
+ if (this.__lineWidths[lineIndex] !== undefined) {
983
+ return this.__lineWidths[lineIndex];
984
+ }
985
+ const { width } = this.measureLine(lineIndex);
986
+ this.__lineWidths[lineIndex] = width;
987
+ return width;
988
+ }
989
+ _getWidthOfCharSpacing() {
990
+ if (this.charSpacing !== 0) {
991
+ return (this.fontSize * this.charSpacing) / 1000;
992
+ }
993
+ return 0;
994
+ }
995
+ /**
996
+ * Retrieves the value of property at given character position
997
+ * @param {Number} lineIndex the line number
998
+ * @param {Number} charIndex the character number
999
+ * @param {String} property the property name
1000
+ * @returns the value of 'property'
1001
+ */
1002
+ getValueOfPropertyAt(lineIndex, charIndex, property) {
1003
+ const charStyle = this._getStyleDeclaration(lineIndex, charIndex);
1004
+ return (charStyle[property] ?? this[property]);
1005
+ }
1006
+ /**
1007
+ * @private
1008
+ * @param {CanvasRenderingContext2D} ctx Context to render on
1009
+ */
1010
+ _renderTextDecoration(ctx, type) {
1011
+ if (!this[type] && !this.styleHas(type)) {
1012
+ return;
1013
+ }
1014
+ let topOffset = this._getTopOffset();
1015
+ const leftOffset = this._getLeftOffset(), path = this.path, charSpacing = this._getWidthOfCharSpacing(), offsetAligner = type === 'linethrough' ? 0.5 : type === 'overline' ? 1 : 0, offsetY = this.offsets[type];
1016
+ for (let i = 0, len = this._textLines.length; i < len; i++) {
1017
+ const heightOfLine = this.getHeightOfLine(i);
1018
+ if (!this[type] && !this.styleHas(type, i)) {
1019
+ topOffset += heightOfLine;
1020
+ continue;
1021
+ }
1022
+ const line = this._textLines[i];
1023
+ const maxHeight = heightOfLine / this.lineHeight;
1024
+ const lineLeftOffset = this._getLineLeftOffset(i);
1025
+ let boxStart = 0;
1026
+ let boxWidth = 0;
1027
+ let lastDecoration = this.getValueOfPropertyAt(i, 0, type);
1028
+ let lastFill = this.getValueOfPropertyAt(i, 0, FILL);
1029
+ let lastTickness = this.getValueOfPropertyAt(i, 0, TEXT_DECORATION_THICKNESS);
1030
+ let currentDecoration = lastDecoration;
1031
+ let currentFill = lastFill;
1032
+ let currentTickness = lastTickness;
1033
+ const top = topOffset + maxHeight * (1 - this._fontSizeFraction);
1034
+ let size = this.getHeightOfChar(i, 0);
1035
+ let dy = this.getValueOfPropertyAt(i, 0, 'deltaY');
1036
+ for (let j = 0, jlen = line.length; j < jlen; j++) {
1037
+ const charBox = this.__charBounds[i][j];
1038
+ currentDecoration = this.getValueOfPropertyAt(i, j, type);
1039
+ currentFill = this.getValueOfPropertyAt(i, j, FILL);
1040
+ currentTickness = this.getValueOfPropertyAt(i, j, TEXT_DECORATION_THICKNESS);
1041
+ const currentSize = this.getHeightOfChar(i, j);
1042
+ const currentDy = this.getValueOfPropertyAt(i, j, 'deltaY');
1043
+ if (path && currentDecoration && currentFill) {
1044
+ const finalTickness = (this.fontSize * currentTickness) / 1000;
1045
+ ctx.save();
1046
+ // bug? verify lastFill is a valid fill here.
1047
+ ctx.fillStyle = lastFill;
1048
+ ctx.translate(charBox.renderLeft, charBox.renderTop);
1049
+ ctx.rotate(charBox.angle);
1050
+ ctx.fillRect(-charBox.kernedWidth / 2, offsetY * currentSize + currentDy - offsetAligner * finalTickness, charBox.kernedWidth, finalTickness);
1051
+ ctx.restore();
1052
+ }
1053
+ else if ((currentDecoration !== lastDecoration ||
1054
+ currentFill !== lastFill ||
1055
+ currentSize !== size ||
1056
+ currentTickness !== lastTickness ||
1057
+ currentDy !== dy) &&
1058
+ boxWidth > 0) {
1059
+ const finalTickness = (this.fontSize * lastTickness) / 1000;
1060
+ let drawStart = leftOffset + lineLeftOffset + boxStart;
1061
+ if (this.direction === 'rtl') {
1062
+ drawStart = this.width - drawStart - boxWidth;
1063
+ }
1064
+ if (lastDecoration && lastFill && lastTickness) {
1065
+ // bug? verify lastFill is a valid fill here.
1066
+ ctx.fillStyle = lastFill;
1067
+ ctx.fillRect(drawStart, top + offsetY * size + dy - offsetAligner * finalTickness, boxWidth, finalTickness);
1068
+ }
1069
+ boxStart = charBox.left;
1070
+ boxWidth = charBox.width;
1071
+ lastDecoration = currentDecoration;
1072
+ lastTickness = currentTickness;
1073
+ lastFill = currentFill;
1074
+ size = currentSize;
1075
+ dy = currentDy;
1076
+ }
1077
+ else {
1078
+ boxWidth += charBox.kernedWidth;
1079
+ }
1080
+ }
1081
+ let drawStart = leftOffset + lineLeftOffset + boxStart;
1082
+ if (this.direction === 'rtl') {
1083
+ drawStart = this.width - drawStart - boxWidth;
1084
+ }
1085
+ ctx.fillStyle = currentFill;
1086
+ const finalTickness = (this.fontSize * currentTickness) / 1000;
1087
+ currentDecoration &&
1088
+ currentFill &&
1089
+ currentTickness &&
1090
+ ctx.fillRect(drawStart, top + offsetY * size + dy - offsetAligner * finalTickness, boxWidth - charSpacing, finalTickness);
1091
+ topOffset += heightOfLine;
1092
+ }
1093
+ // if there is text background color no
1094
+ // other shadows should be casted
1095
+ this._removeShadow(ctx);
1096
+ }
1097
+ /**
1098
+ * return font declaration string for canvas context
1099
+ * @param {Object} [styleObject] object
1100
+ * @returns {String} font declaration formatted for canvas context.
1101
+ */
1102
+ _getFontDeclaration({ fontFamily = this.fontFamily, fontStyle = this.fontStyle, fontWeight = this.fontWeight, fontSize = this.fontSize, } = {}, forMeasuring) {
1103
+ const parsedFontFamily = fontFamily.includes("'") ||
1104
+ fontFamily.includes('"') ||
1105
+ fontFamily.includes(',') ||
1106
+ FabricText.genericFonts.includes(fontFamily.toLowerCase())
1107
+ ? fontFamily
1108
+ : `"${fontFamily}"`;
1109
+ return [
1110
+ fontStyle,
1111
+ fontWeight,
1112
+ `${forMeasuring ? this.CACHE_FONT_SIZE : fontSize}px`,
1113
+ parsedFontFamily,
1114
+ ].join(' ');
1115
+ }
1116
+ /**
1117
+ * Renders text instance on a specified context
1118
+ * @param {CanvasRenderingContext2D} ctx Context to render on
1119
+ */
1120
+ render(ctx) {
1121
+ if (!this.visible) {
1122
+ return;
1123
+ }
1124
+ if (this.canvas &&
1125
+ this.canvas.skipOffscreen &&
1126
+ !this.group &&
1127
+ !this.isOnScreen()) {
1128
+ return;
1129
+ }
1130
+ if (this._forceClearCache) {
1131
+ this.initDimensions();
1132
+ }
1133
+ super.render(ctx);
1134
+ }
1135
+ /**
1136
+ * Override this method to customize grapheme splitting
1137
+ * @todo the util `graphemeSplit` needs to be injectable in some way.
1138
+ * is more comfortable to inject the correct util rather than having to override text
1139
+ * in the middle of the prototype chain
1140
+ * @param {string} value
1141
+ * @returns {string[]} array of graphemes
1142
+ */
1143
+ graphemeSplit(value) {
1144
+ return graphemeSplit(value);
1145
+ }
1146
+ /**
1147
+ * Returns the text as an array of lines.
1148
+ * @param {String} text text to split
1149
+ * @returns Lines in the text
1150
+ */
1151
+ _splitTextIntoLines(text) {
1152
+ // James modified 生成换行数据, 如果是path则不进行换行(删除换行字符)
1153
+ text = this.path ? text.replaceAll(/\r?\n/g, '') : text;
1154
+ const lines = text.split(this._reNewline), newLines = new Array(lines.length), newLine = ['\n'];
1155
+ let newText = [];
1156
+ for (let i = 0; i < lines.length; i++) {
1157
+ newLines[i] = this.graphemeSplit(lines[i]);
1158
+ newText = newText.concat(newLines[i], newLine);
1159
+ }
1160
+ newText.pop();
1161
+ return {
1162
+ _unwrappedLines: newLines,
1163
+ lines: lines,
1164
+ graphemeText: newText,
1165
+ graphemeLines: newLines,
1166
+ };
1167
+ }
1168
+ /**
1169
+ * Returns object representation of an instance
1170
+ * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
1171
+ * @return {Object} Object representation of an instance
1172
+ */
1173
+ toObject(propertiesToInclude = []) {
1174
+ return {
1175
+ ...super.toObject([...additionalProps, ...propertiesToInclude]),
1176
+ styles: stylesToArray(this.styles, this.text),
1177
+ ...(this.path ? { path: this.path.toObject() } : {}),
1178
+ };
1179
+ }
1180
+ set(key, value) {
1181
+ const { textLayoutProperties } = this.constructor;
1182
+ super.set(key, value);
1183
+ let needsDims = false;
1184
+ let isAddingPath = false;
1185
+ if (typeof key === 'object') {
1186
+ for (const _key in key) {
1187
+ if (_key === 'path') {
1188
+ this.setPathInfo();
1189
+ }
1190
+ needsDims = needsDims || textLayoutProperties.includes(_key);
1191
+ isAddingPath = isAddingPath || _key === 'path';
1192
+ }
1193
+ }
1194
+ else {
1195
+ needsDims = textLayoutProperties.includes(key);
1196
+ isAddingPath = key === 'path';
1197
+ }
1198
+ if (isAddingPath) {
1199
+ this.setPathInfo();
1200
+ }
1201
+ if (needsDims && this.initialized) {
1202
+ this.initDimensions();
1203
+ this.setCoords();
1204
+ }
1205
+ return this;
1206
+ }
1207
+ /**
1208
+ * Returns complexity of an instance
1209
+ * @return {Number} complexity
1210
+ */
1211
+ complexity() {
1212
+ return 1;
1213
+ }
1214
+ /**
1215
+ * List of generic font families
1216
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/font-family#generic-name
1217
+ */
1218
+ static genericFonts = [
1219
+ 'serif',
1220
+ 'sans-serif',
1221
+ 'monospace',
1222
+ 'cursive',
1223
+ 'fantasy',
1224
+ 'system-ui',
1225
+ 'ui-serif',
1226
+ 'ui-sans-serif',
1227
+ 'ui-monospace',
1228
+ 'ui-rounded',
1229
+ 'math',
1230
+ 'emoji',
1231
+ 'fangsong',
1232
+ ];
1233
+ /* _FROM_SVG_START_ */
1234
+ /**
1235
+ * List of attribute names to account for when parsing SVG element (used by {@link FabricText.fromElement})
1236
+ * @static
1237
+ * @memberOf Text
1238
+ * @see: http://www.w3.org/TR/SVG/text.html#TextElement
1239
+ */
1240
+ static ATTRIBUTE_NAMES = SHARED_ATTRIBUTES.concat('x', 'y', 'dx', 'dy', 'font-family', 'font-style', 'font-weight', 'font-size', 'letter-spacing', 'text-decoration', 'text-anchor');
1241
+ /* _FROM_SVG_END_ */
1242
+ /**
1243
+ * Returns FabricText instance from an object representation
1244
+ * @param {Object} object plain js Object to create an instance from
1245
+ * @returns {Promise<FabricText>}
1246
+ */
1247
+ static fromObject(object) {
1248
+ return this._fromObject({
1249
+ ...object,
1250
+ styles: stylesFromArray(object.styles || {}, object.text),
1251
+ }, {
1252
+ extraParam: 'text',
1253
+ });
1254
+ }
1255
+ }
1256
+ applyMixins(FabricText, [TextSVGExportMixin]);
1257
+ classRegistry.setClass(FabricText);
1258
+ //# sourceMappingURL=Text.js.map