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,910 @@
1
+ import { IText } from './IText/IText';
2
+ import { classRegistry } from '../ClassRegistry';
3
+ import { createTextboxDefaultControls } from '../controls/commonControls';
4
+ import { JUSTIFY } from './Text/constants';
5
+ import { parseAttributes } from '../parser/parseAttributes';
6
+ import { Path } from './Path';
7
+ import { DEFAULT_SVG_FONT_SIZE } from '../constants';
8
+ import { graphemeSplit } from '../util/lang_string';
9
+ import { stylesFromArray } from '../util/misc/textStyles';
10
+ // @TODO: Many things here are configuration related and shouldn't be on the class nor prototype
11
+ // regexes, list of properties that are not suppose to change by instances, magic consts.
12
+ // this will be a separated effort
13
+ export const textboxDefaultValues = {
14
+ minWidth: 20,
15
+ dynamicMinWidth: 2,
16
+ lockScalingFlip: true,
17
+ noScaleCache: false,
18
+ _wordJoiners: /[ \t\r]/,
19
+ splitByGrapheme: false,
20
+ };
21
+ /**
22
+ * Textbox class, based on IText, allows the user to resize the text rectangle
23
+ * and wraps lines automatically. Textboxes have their Y scaling locked, the
24
+ * user can only change width. Height is adjusted automatically based on the
25
+ * wrapping of lines.
26
+ */
27
+ export class Textbox extends IText {
28
+ static type = 'Textbox';
29
+ static textLayoutProperties = [...IText.textLayoutProperties, 'width'];
30
+ static ownDefaults = textboxDefaultValues;
31
+ // James modified 自动计算文字高度
32
+ static enableCalcTextHeight = false;
33
+ /**
34
+ * James modified 自动计算文字高度
35
+ * 增加wrap宽度,设置为page的宽度
36
+ * 增加textbox wrap的默认宽度
37
+ * @type Number
38
+ * @default
39
+ */
40
+ static defaultWrapWidth = 1920;
41
+ static getDefaults() {
42
+ return {
43
+ ...super.getDefaults(),
44
+ ...Textbox.ownDefaults,
45
+ };
46
+ }
47
+ /**
48
+ * Constructor
49
+ * @param {String} text Text string
50
+ * @param {Object} [options] Options object
51
+ */
52
+ constructor(text, options) {
53
+ super(text, { ...Textbox.ownDefaults, ...options });
54
+ }
55
+ /**
56
+ * Creates the default control object.
57
+ * If you prefer to have on instance of controls shared among all objects
58
+ * make this function return an empty object and add controls to the ownDefaults object
59
+ */
60
+ static createControls() {
61
+ return { controls: createTextboxDefaultControls() };
62
+ }
63
+ /**
64
+ * Unlike superclass's version of this function, Textbox does not update
65
+ * its width.
66
+ * @private
67
+ * @override
68
+ */
69
+ initDimensions() {
70
+ if (!this.initialized) {
71
+ return;
72
+ }
73
+ this.isEditing && this.initDelayedCursor();
74
+ this._clearCache();
75
+ // clear dynamicMinWidth as it will be different after we re-wrap line
76
+ this.dynamicMinWidth = 0;
77
+ // wrap lines
78
+ this._styleMap = this._generateStyleMap(this._splitText());
79
+ // James modified
80
+ // if after wrapping, the width is smaller than dynamicMinWidth, change the width and re-wrap
81
+ if (!this.path && this.dynamicMinWidth > this.width) {
82
+ this._set('width', this.dynamicMinWidth);
83
+ }
84
+ if (this.textAlign.includes(JUSTIFY)) {
85
+ // once text is measured we need to make space fatter to make justified text.
86
+ this.enlargeSpaces();
87
+ }
88
+ // James modified 取消 textbox 自动计算高度
89
+ if (!this.path && Textbox.enableCalcTextHeight) {
90
+ // clear cache and re-calculate height
91
+ this.height = this.calcTextHeight();
92
+ }
93
+ this.preventGroupCache = this.path ? true : false;
94
+ }
95
+ /**
96
+ * Generate an object that translates the style object so that it is
97
+ * broken up by visual lines (new lines and automatic wrapping).
98
+ * The original text styles object is broken up by actual lines (new lines only),
99
+ * which is only sufficient for Text / IText
100
+ * @private
101
+ */
102
+ _generateStyleMap(textInfo) {
103
+ let realLineCount = 0, realLineCharCount = 0, charCount = 0;
104
+ const map = {};
105
+ for (let i = 0; i < textInfo.graphemeLines.length; i++) {
106
+ if (textInfo.graphemeText[charCount] === '\n' && i > 0) {
107
+ realLineCharCount = 0;
108
+ charCount++;
109
+ realLineCount++;
110
+ }
111
+ else if (!this.splitByGrapheme &&
112
+ this._reSpaceAndTab.test(textInfo.graphemeText[charCount]) &&
113
+ i > 0) {
114
+ // this case deals with space's that are removed from end of lines when wrapping
115
+ realLineCharCount++;
116
+ charCount++;
117
+ }
118
+ map[i] = { line: realLineCount, offset: realLineCharCount };
119
+ charCount += textInfo.graphemeLines[i].length;
120
+ realLineCharCount += textInfo.graphemeLines[i].length;
121
+ }
122
+ return map;
123
+ }
124
+ /**
125
+ * Returns true if object has a style property or has it on a specified line
126
+ * @param {Number} lineIndex
127
+ * @return {Boolean}
128
+ */
129
+ styleHas(property, lineIndex) {
130
+ if (this._styleMap && !this.isWrapping) {
131
+ const map = this._styleMap[lineIndex];
132
+ if (map) {
133
+ lineIndex = map.line;
134
+ }
135
+ }
136
+ return super.styleHas(property, lineIndex);
137
+ }
138
+ /**
139
+ * Returns true if object has no styling or no styling in a line
140
+ * @param {Number} lineIndex , lineIndex is on wrapped lines.
141
+ * @return {Boolean}
142
+ */
143
+ isEmptyStyles(lineIndex) {
144
+ if (!this.styles) {
145
+ return true;
146
+ }
147
+ let offset = 0, nextLineIndex = lineIndex + 1, nextOffset, shouldLimit = false;
148
+ const map = this._styleMap[lineIndex], mapNextLine = this._styleMap[lineIndex + 1];
149
+ if (map) {
150
+ lineIndex = map.line;
151
+ offset = map.offset;
152
+ }
153
+ if (mapNextLine) {
154
+ nextLineIndex = mapNextLine.line;
155
+ shouldLimit = nextLineIndex === lineIndex;
156
+ nextOffset = mapNextLine.offset;
157
+ }
158
+ const obj = typeof lineIndex === 'undefined'
159
+ ? this.styles
160
+ : { line: this.styles[lineIndex] };
161
+ for (const p1 in obj) {
162
+ for (const p2 in obj[p1]) {
163
+ const p2Number = parseInt(p2, 10);
164
+ if (p2Number >= offset && (!shouldLimit || p2Number < nextOffset)) {
165
+ // eslint-disable-next-line no-unused-vars
166
+ for (const p3 in obj[p1][p2]) {
167
+ return false;
168
+ }
169
+ }
170
+ }
171
+ }
172
+ return true;
173
+ }
174
+ /**
175
+ * @protected
176
+ * @param {Number} lineIndex
177
+ * @param {Number} charIndex
178
+ * @return {TextStyleDeclaration} a style object reference to the existing one or a new empty object when undefined
179
+ */
180
+ _getStyleDeclaration(lineIndex, charIndex) {
181
+ if (this._styleMap && !this.isWrapping) {
182
+ const map = this._styleMap[lineIndex];
183
+ if (!map) {
184
+ return {};
185
+ }
186
+ lineIndex = map.line;
187
+ charIndex = map.offset + charIndex;
188
+ }
189
+ return super._getStyleDeclaration(lineIndex, charIndex);
190
+ }
191
+ /**
192
+ * @param {Number} lineIndex
193
+ * @param {Number} charIndex
194
+ * @param {Object} style
195
+ * @private
196
+ */
197
+ _setStyleDeclaration(lineIndex, charIndex, style) {
198
+ const map = this._styleMap[lineIndex];
199
+ super._setStyleDeclaration(map.line, map.offset + charIndex, style);
200
+ }
201
+ /**
202
+ * @param {Number} lineIndex
203
+ * @param {Number} charIndex
204
+ * @private
205
+ */
206
+ _deleteStyleDeclaration(lineIndex, charIndex) {
207
+ const map = this._styleMap[lineIndex];
208
+ super._deleteStyleDeclaration(map.line, map.offset + charIndex);
209
+ }
210
+ /**
211
+ * probably broken need a fix
212
+ * Returns the real style line that correspond to the wrapped lineIndex line
213
+ * Used just to verify if the line does exist or not.
214
+ * @param {Number} lineIndex
215
+ * @returns {Boolean} if the line exists or not
216
+ * @private
217
+ */
218
+ _getLineStyle(lineIndex) {
219
+ const map = this._styleMap[lineIndex];
220
+ return !!this.styles[map.line];
221
+ }
222
+ /**
223
+ * Set the line style to an empty object so that is initialized
224
+ * @param {Number} lineIndex
225
+ * @param {Object} style
226
+ * @private
227
+ */
228
+ _setLineStyle(lineIndex) {
229
+ const map = this._styleMap[lineIndex];
230
+ super._setLineStyle(map.line);
231
+ }
232
+ /**
233
+ * Wraps text using the 'width' property of Textbox. First this function
234
+ * splits text on newlines, so we preserve newlines entered by the user.
235
+ * Then it wraps each line using the width of the Textbox by calling
236
+ * _wrapLine().
237
+ * @param {Array} lines The string array of text that is split into lines
238
+ * @param {Number} desiredWidth width you want to wrap to
239
+ * @returns {Array} Array of lines
240
+ */
241
+ _wrapText(lines, desiredWidth) {
242
+ this.isWrapping = true;
243
+ // extract all thewords and the widths to optimally wrap lines.
244
+ const data = this.getGraphemeDataForRender(lines);
245
+ const wrapped = [];
246
+ for (let i = 0; i < data.wordsData.length; i++) {
247
+ wrapped.push(...this._wrapLine(i, desiredWidth, data));
248
+ }
249
+ this.isWrapping = false;
250
+ return wrapped;
251
+ }
252
+ /**
253
+ * For each line of text terminated by an hard line stop,
254
+ * measure each word width and extract the largest word from all.
255
+ * The returned words here are the one that at the end will be rendered.
256
+ * @param {string[]} lines the lines we need to measure
257
+ *
258
+ */
259
+ getGraphemeDataForRender(lines) {
260
+ const splitByGrapheme = this.splitByGrapheme, infix = splitByGrapheme ? '' : ' ';
261
+ let largestWordWidth = 0;
262
+ const data = lines.map((line, lineIndex) => {
263
+ let offset = 0;
264
+ const wordsOrGraphemes = splitByGrapheme
265
+ ? this.graphemeSplit(line)
266
+ : this.wordSplit(line);
267
+ if (wordsOrGraphemes.length === 0) {
268
+ return [{ word: [], width: 0 }];
269
+ }
270
+ return wordsOrGraphemes.map((word) => {
271
+ // if using splitByGrapheme words are already in graphemes.
272
+ const graphemeArray = splitByGrapheme
273
+ ? [word]
274
+ : this.graphemeSplit(word);
275
+ const width = this._measureWord(graphemeArray, lineIndex, offset);
276
+ largestWordWidth = Math.max(width, largestWordWidth);
277
+ offset += graphemeArray.length + infix.length;
278
+ return { word: graphemeArray, width };
279
+ });
280
+ });
281
+ return {
282
+ wordsData: data,
283
+ largestWordWidth,
284
+ };
285
+ }
286
+ /**
287
+ * Helper function to measure a string of text, given its lineIndex and charIndex offset
288
+ * It gets called when charBounds are not available yet.
289
+ * Override if necessary
290
+ * Use with {@link Textbox#wordSplit}
291
+ *
292
+ * @param {CanvasRenderingContext2D} ctx
293
+ * @param {String} text
294
+ * @param {number} lineIndex
295
+ * @param {number} charOffset
296
+ * @returns {number}
297
+ */
298
+ _measureWord(word, lineIndex, charOffset = 0) {
299
+ let width = 0, prevGrapheme;
300
+ const skipLeft = true;
301
+ for (let i = 0, len = word.length; i < len; i++) {
302
+ const box = this._getGraphemeBox(word[i], lineIndex, i + charOffset, prevGrapheme, skipLeft);
303
+ width += box.kernedWidth;
304
+ prevGrapheme = word[i];
305
+ }
306
+ return width;
307
+ }
308
+ /**
309
+ * Override this method to customize word splitting
310
+ * Use with {@link Textbox#_measureWord}
311
+ * @param {string} value
312
+ * @returns {string[]} array of words
313
+ */
314
+ wordSplit(value) {
315
+ return value.split(this._wordJoiners);
316
+ }
317
+ /**
318
+ * Wraps a line of text using the width of the Textbox as desiredWidth
319
+ * and leveraging the known width o words from GraphemeData
320
+ * @private
321
+ * @param {Number} lineIndex
322
+ * @param {Number} desiredWidth width you want to wrap the line to
323
+ * @param {GraphemeData} graphemeData an object containing all the lines' words width.
324
+ * @param {Number} reservedSpace space to remove from wrapping for custom functionalities
325
+ * @returns {Array} Array of line(s) into which the given text is wrapped
326
+ * to.
327
+ */
328
+ _wrapLine(lineIndex, desiredWidth, { largestWordWidth, wordsData }, reservedSpace = 0) {
329
+ const additionalSpace = this._getWidthOfCharSpacing(), splitByGrapheme = this.splitByGrapheme, graphemeLines = [], infix = splitByGrapheme ? '' : ' ';
330
+ let lineWidth = 0, line = [],
331
+ // spaces in different languages?
332
+ offset = 0, infixWidth = 0, lineJustStarted = true;
333
+ desiredWidth -= reservedSpace;
334
+ const maxWidth = Math.max(desiredWidth, largestWordWidth, this.dynamicMinWidth);
335
+ // layout words
336
+ const data = wordsData[lineIndex];
337
+ offset = 0;
338
+ let i;
339
+ for (i = 0; i < data.length; i++) {
340
+ const { word, width: wordWidth } = data[i];
341
+ offset += word.length;
342
+ lineWidth += infixWidth + wordWidth - additionalSpace;
343
+ if (lineWidth > maxWidth && !lineJustStarted) {
344
+ graphemeLines.push(line);
345
+ line = [];
346
+ lineWidth = wordWidth;
347
+ lineJustStarted = true;
348
+ }
349
+ else {
350
+ lineWidth += additionalSpace;
351
+ }
352
+ if (!lineJustStarted && !splitByGrapheme) {
353
+ line.push(infix);
354
+ }
355
+ line = line.concat(word);
356
+ infixWidth = splitByGrapheme
357
+ ? 0
358
+ : this._measureWord([infix], lineIndex, offset);
359
+ offset++;
360
+ lineJustStarted = false;
361
+ }
362
+ i && graphemeLines.push(line);
363
+ // TODO: this code is probably not necessary anymore.
364
+ // it can be moved out of this function since largestWordWidth is now
365
+ // known in advance
366
+ if (largestWordWidth + reservedSpace > this.dynamicMinWidth) {
367
+ this.dynamicMinWidth = largestWordWidth - additionalSpace + reservedSpace;
368
+ }
369
+ return graphemeLines;
370
+ }
371
+ /**
372
+ * Detect if the text line is ended with an hard break
373
+ * text and itext do not have wrapping, return false
374
+ * @param {Number} lineIndex text to split
375
+ * @return {Boolean}
376
+ */
377
+ isEndOfWrapping(lineIndex) {
378
+ if (!this._styleMap[lineIndex + 1]) {
379
+ // is last line, return true;
380
+ return true;
381
+ }
382
+ if (this._styleMap[lineIndex + 1].line !== this._styleMap[lineIndex].line) {
383
+ // this is last line before a line break, return true;
384
+ return true;
385
+ }
386
+ return false;
387
+ }
388
+ /**
389
+ * Detect if a line has a linebreak and so we need to account for it when moving
390
+ * and counting style.
391
+ * This is important only for splitByGrapheme at the end of wrapping.
392
+ * If we are not wrapping the offset is always 1
393
+ * @return Number
394
+ */
395
+ missingNewlineOffset(lineIndex, skipWrapping) {
396
+ if (this.splitByGrapheme && !skipWrapping) {
397
+ return this.isEndOfWrapping(lineIndex) ? 1 : 0;
398
+ }
399
+ return 1;
400
+ }
401
+ /**
402
+ * Gets lines of text to render in the Textbox. This function calculates
403
+ * text wrapping on the fly every time it is called.
404
+ * @param {String} text text to split
405
+ * @returns {Array} Array of lines in the Textbox.
406
+ * @override
407
+ */
408
+ _splitTextIntoLines(text) {
409
+ // James modified 存在path时候不按照宽度换行
410
+ var wrapWidth = this.path ? 10000000 : this.width;
411
+ // 如果width 不存在, 使用page width
412
+ wrapWidth = wrapWidth || Textbox.defaultWrapWidth;
413
+ const newText = super._splitTextIntoLines(text), graphemeLines = this._wrapText(newText.lines, wrapWidth), lines = new Array(graphemeLines.length);
414
+ for (let i = 0; i < graphemeLines.length; i++) {
415
+ lines[i] = graphemeLines[i].join('');
416
+ }
417
+ newText.lines = lines;
418
+ newText.graphemeLines = graphemeLines;
419
+ return newText;
420
+ }
421
+ getMinWidth() {
422
+ return Math.max(this.minWidth, this.dynamicMinWidth);
423
+ }
424
+ _removeExtraneousStyles() {
425
+ const linesToKeep = new Map();
426
+ for (const prop in this._styleMap) {
427
+ const propNumber = parseInt(prop, 10);
428
+ if (this._textLines[propNumber]) {
429
+ const lineIndex = this._styleMap[prop].line;
430
+ linesToKeep.set(`${lineIndex}`, true);
431
+ }
432
+ }
433
+ for (const prop in this.styles) {
434
+ if (!linesToKeep.has(prop)) {
435
+ delete this.styles[prop];
436
+ }
437
+ }
438
+ }
439
+ /**
440
+ * Returns object representation of an instance
441
+ * @method toObject
442
+ * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
443
+ * @return {Object} object representation of an instance
444
+ */
445
+ toObject(propertiesToInclude = []) {
446
+ return super.toObject([
447
+ 'minWidth',
448
+ 'splitByGrapheme',
449
+ ...propertiesToInclude,
450
+ ]);
451
+ }
452
+ /**
453
+ * Returns FabricText instance from an SVG element (<b>not yet implemented</b>)
454
+ * @static
455
+ * @memberOf Text
456
+ * @param {HTMLElement} element Element to parse
457
+ * @param {Object} [options] Options object
458
+ */
459
+ static async fromElement(element, options, cssRules) {
460
+ if (!element) {
461
+ return null;
462
+ }
463
+ var parsedAttributes = parseAttributes(element, Textbox.ATTRIBUTE_NAMES, cssRules);
464
+ const textOptions = {
465
+ ...(cssRules ? JSON.parse(JSON.stringify(cssRules)) : {}),
466
+ ...parsedAttributes,
467
+ };
468
+ // 处理style中字体样式带单引号问题
469
+ let reg = /^'(.*)'$/;
470
+ if (reg.test(textOptions.fontFamily)) {
471
+ textOptions.fontFamily = textOptions.fontFamily.slice(1, -1);
472
+ }
473
+ textOptions.top = textOptions.top || 0;
474
+ textOptions.left = textOptions.left || 0;
475
+ if (parsedAttributes.textDecoration) {
476
+ var textDecoration = parsedAttributes.textDecoration;
477
+ if (textDecoration.indexOf('underline') !== -1) {
478
+ textOptions.underline = true;
479
+ }
480
+ if (textDecoration.indexOf('overline') !== -1) {
481
+ textOptions.overline = true;
482
+ }
483
+ if (textDecoration.indexOf('line-through') !== -1) {
484
+ textOptions.linethrough = true;
485
+ }
486
+ delete textOptions.textDecoration;
487
+ }
488
+ if ('dx' in parsedAttributes) {
489
+ textOptions.left += parsedAttributes.dx;
490
+ }
491
+ if ('dy' in parsedAttributes) {
492
+ textOptions.top += parsedAttributes.dy;
493
+ }
494
+ if (!('fontSize' in textOptions)) {
495
+ textOptions.fontSize = DEFAULT_SVG_FONT_SIZE;
496
+ }
497
+ let text;
498
+ const paths = element.getElementsByTagName('textPath');
499
+ if (paths.length) {
500
+ text = this._fromTextPath(paths[0], textOptions, parsedAttributes);
501
+ }
502
+ else {
503
+ text = this._fromTextSpan(element, textOptions, parsedAttributes);
504
+ }
505
+ return text;
506
+ }
507
+ static _findSvgTextPath(element, id) {
508
+ const svg = element.closest('svg');
509
+ return svg.querySelector(id);
510
+ }
511
+ static _fromTextPath = (textPath, options, parsedAttributes) => {
512
+ var parsedAnchor = parsedAttributes.textAnchor || 'left';
513
+ var textPathParsedAttributes = parseAttributes(textPath, [
514
+ 'href',
515
+ 'text-anchor',
516
+ 'startOffset',
517
+ ]);
518
+ if (textPathParsedAttributes.textAnchor) {
519
+ parsedAnchor = textPathParsedAttributes.textAnchor;
520
+ }
521
+ if (parsedAnchor === 'middle') {
522
+ parsedAnchor = 'center';
523
+ }
524
+ else if (parsedAnchor === 'end') {
525
+ parsedAnchor = 'right';
526
+ }
527
+ options.textAlign = parsedAnchor;
528
+ var textContent = textPath.textContent;
529
+ var text = new Textbox(textContent, options);
530
+ // 逐字符样式(text-on-path 也支持选中字符单独改色/字号/字体)。
531
+ // 导出时 _getTextPath 会按样式切分 tspan,导入时这里收集每个 tspan 的样式,
532
+ // 用 stylesFromArray 恢复成 fabric 的 styles 结构,否则导入后丢失。
533
+ // text-on-path 是单行,grapheme 索引从 0 顺序累计即可(无换行偏移)。
534
+ // 只收集与对象级值有差异的样式键:tspan 常带完整 style(font-family 等与对象级
535
+ // 相同),若全量收集会在无逐字符覆盖时也凭空多出 styles,破坏兼容性。
536
+ const pathSpans = textPath.getElementsByTagName('tspan');
537
+ if (pathSpans.length > 0) {
538
+ const stylesArray = [];
539
+ // 对象级字体名可能带引号(tspan style 里 getSvgSpanStyles 会加引号),
540
+ // 对比前先规范化,避免误判为「有差异」。
541
+ const normFontFamily = (v) => typeof v === 'string'
542
+ ? v.replace(/^['"]|['"]$/g, '')
543
+ : v;
544
+ let globalOffset = 0;
545
+ for (let i = 0; i < pathSpans.length; i++) {
546
+ const spanAttrs = parseAttributes(pathSpans[i], Textbox.ATTRIBUTE_NAMES);
547
+ const spanStyle = {};
548
+ [
549
+ 'fontFamily',
550
+ 'fontWeight',
551
+ 'fontStyle',
552
+ 'fontSize',
553
+ 'fill',
554
+ 'stroke',
555
+ 'strokeWidth',
556
+ ].forEach((key) => {
557
+ const value = spanAttrs[key];
558
+ if (value === undefined || value === null || value === '')
559
+ return;
560
+ // 与对象级一致时跳过(无逐字符覆盖,避免凭空多出 styles)
561
+ const objValue = options[key];
562
+ if (key === 'fontFamily') {
563
+ if (normFontFamily(value) === normFontFamily(objValue))
564
+ return;
565
+ spanStyle[key] = normFontFamily(value);
566
+ }
567
+ else if (value !== objValue) {
568
+ spanStyle[key] = value;
569
+ }
570
+ });
571
+ const spanGraphemes = graphemeSplit(pathSpans[i].textContent || '');
572
+ if (Object.keys(spanStyle).length && spanGraphemes.length) {
573
+ stylesArray.push({
574
+ start: globalOffset,
575
+ end: globalOffset + spanGraphemes.length,
576
+ style: spanStyle,
577
+ });
578
+ }
579
+ globalOffset += spanGraphemes.length;
580
+ }
581
+ if (stylesArray.length) {
582
+ text.set({ styles: stylesFromArray(stylesArray, text.text || textContent) });
583
+ }
584
+ }
585
+ const href = textPathParsedAttributes.href;
586
+ if (href && href.startsWith('#')) {
587
+ const pathElement = Textbox._findSvgTextPath(textPath, href);
588
+ if (pathElement) {
589
+ var pathParsedAttributes = parseAttributes(pathElement, Path.ATTRIBUTE_NAMES);
590
+ const path = new Path(pathParsedAttributes.d, {
591
+ ...pathParsedAttributes,
592
+ ...{
593
+ strokeWidth: 1,
594
+ stroke: '#ff0000',
595
+ fill: null,
596
+ visible: false,
597
+ },
598
+ });
599
+ // 需要计算实际字体大小
600
+ Textbox.enableCalcTextHeight = true;
601
+ const textHeight = new Textbox('i', {
602
+ fontFamily: options.fontFamily,
603
+ fontSize: options.fontSize,
604
+ fontStyle: options.fontStyle,
605
+ fontWeight: options.fontWeight,
606
+ width: undefined,
607
+ height: undefined,
608
+ }).height || 20;
609
+ text.set({
610
+ width: (path.width || 0) + textHeight * 2,
611
+ height: (path.height || 0) + textHeight * 2,
612
+ path,
613
+ pathType: 'custom',
614
+ });
615
+ // 取消自动计算文字高度
616
+ Textbox.enableCalcTextHeight = false;
617
+ }
618
+ }
619
+ // 设置位置中心点为左上角
620
+ text.set({
621
+ left: options.left - (text.width || 0) / 2,
622
+ top: options.top - (text.height || 0) / 2,
623
+ });
624
+ return text;
625
+ };
626
+ static _fromTextSpan(element, options, parsedAttributes) {
627
+ var textContent = '';
628
+ var parsedAnchor = parsedAttributes.textAnchor || 'left';
629
+ // 是否需要根据tspan位置计算对齐
630
+ let calcHorAlign = !parsedAttributes.textAnchor;
631
+ let calcAdjustHorAlign = '';
632
+ // The XML is not properly parsed in IE9 so a workaround to get
633
+ // textContent is through firstChild.data. Another workaround would be
634
+ // to convert XML loaded from a file to be converted using DOMParser (same way loadSVGFromString() does)
635
+ let lineCnt = 1;
636
+ let alignmentBaseline = 'auto';
637
+ let spanOffX = 0, minSpanX = null, spanOffY = 0;
638
+ // 逐字符样式(不同字符不同字体/字号/颜色),在 tspan 遍历中收集,
639
+ // 最后用 stylesFromArray 恢复成 fabric 的 styles 结构。
640
+ let stylesArray = [];
641
+ if (element.hasAttribute('line-height')) {
642
+ options.lineHeight = parseFloat(element.getAttribute('line-height'));
643
+ }
644
+ else if (options['line-height']) {
645
+ // 从style 转换过来
646
+ options.lineHeight = parseFloat(options['line-height']) / 100;
647
+ }
648
+ else {
649
+ options.lineHeight = 1;
650
+ }
651
+ if (!('textContent' in element)) {
652
+ if ('firstChild' in element && element.firstChild !== null) {
653
+ if ('data' in element.firstChild && element.firstChild.data !== null) {
654
+ textContent = element.firstChild.data;
655
+ }
656
+ }
657
+ }
658
+ else {
659
+ textContent = element.textContent;
660
+ let spans = element.getElementsByTagName('tspan');
661
+ if (spans.length > 0) {
662
+ // 多行文字
663
+ let lines = [], lineText = '', curLineLeft = 0, // 本行的 水平方向位置
664
+ preSpanTop = 0, // 前一个tspan的 垂直方向位置
665
+ sumDx = 0, sumDy = 0;
666
+ // 逐字符样式(不同字符不同字体/字号/颜色):遍历 tspan 时收集每个区间的样式,
667
+ // 最后用 stylesFromArray 恢复成 fabric 的 styles 结构,否则导入后丢失。
668
+ stylesArray = [];
669
+ let globalOffset = 0;
670
+ for (let i = 0; i < spans.length; i++) {
671
+ var parsedSpanAttributes = parseAttributes(spans[i], Textbox.ATTRIBUTE_NAMES);
672
+ sumDx += Number(parsedSpanAttributes.dx) || 0;
673
+ sumDy += Number(parsedSpanAttributes.dy) || 0;
674
+ // 在使用tspan判断对齐时spanX取最小的值
675
+ if ('left' in parsedSpanAttributes) {
676
+ let spanX = parseFloat(parsedSpanAttributes.left);
677
+ minSpanX = minSpanX != null ? Math.min(minSpanX, spanX) : spanX;
678
+ }
679
+ // 现在多个tspan用多行文字, 所以对齐和位置只处理第一个 tspan
680
+ if (i === 0) {
681
+ if (spans[i].hasAttribute('text-anchor')) {
682
+ // 水平方向
683
+ let anchor = spans[i].getAttribute('text-anchor');
684
+ // left | center | right
685
+ // start | middle | end
686
+ if (anchor === 'middle') {
687
+ parsedAnchor = 'center';
688
+ }
689
+ else if (anchor === 'end') {
690
+ parsedAnchor = 'right';
691
+ }
692
+ calcHorAlign = false;
693
+ }
694
+ if (spans[i].hasAttribute('alignment-baseline')) {
695
+ // 垂直方向
696
+ alignmentBaseline = spans[i].getAttribute('alignment-baseline');
697
+ }
698
+ // 处理tspan设置的位置和偏移
699
+ // top只处理第一行
700
+ if ('top' in parsedSpanAttributes) {
701
+ let spanY = parseFloat(parsedSpanAttributes.top);
702
+ spanY += sumDy;
703
+ spanOffY = options.top - spanY;
704
+ }
705
+ }
706
+ // 多个tspan可能在一行 根据 y position判断是否换行
707
+ // 另外没有对齐方式的,计算判断对齐方式,根据left的值判断对齐方式
708
+ parsedSpanAttributes.left =
709
+ Number(parsedSpanAttributes.left || 0) + sumDx;
710
+ parsedSpanAttributes.top =
711
+ Number(parsedSpanAttributes.top || 0) + sumDy;
712
+ if (i === 0 || preSpanTop === parsedSpanAttributes.top) {
713
+ lineText += spans[i].textContent;
714
+ if (i === 0) {
715
+ curLineLeft = Number(parsedSpanAttributes.left || 0);
716
+ }
717
+ }
718
+ else {
719
+ lines.push({ text: lineText, left: curLineLeft });
720
+ lineText = spans[i].textContent;
721
+ curLineLeft = Number(parsedSpanAttributes.left || 0);
722
+ }
723
+ // 记住上一个span的Y位置
724
+ preSpanTop = parsedSpanAttributes.top;
725
+ // 收集该 tspan 的逐字符样式(只保留非空的样式键)。
726
+ // globalOffset 按 grapheme 跨行累计,换行的 '\n' 不占索引,
727
+ // 与 stylesFromArray / stylesToArray 的语义保持一致。
728
+ const spanStyle = {};
729
+ [
730
+ 'fontFamily',
731
+ 'fontWeight',
732
+ 'fontStyle',
733
+ 'fontSize',
734
+ 'fill',
735
+ 'stroke',
736
+ 'strokeWidth',
737
+ ].forEach((key) => {
738
+ const value = parsedSpanAttributes[key];
739
+ if (value !== undefined && value !== null && value !== '') {
740
+ spanStyle[key] = value;
741
+ }
742
+ });
743
+ // 记录该 tspan 覆盖的字符区间(grapheme 计数,与 stylesFromArray 一致)
744
+ const spanGraphemes = graphemeSplit(spans[i].textContent || '');
745
+ if (Object.keys(spanStyle).length && spanGraphemes.length) {
746
+ stylesArray.push({
747
+ start: globalOffset,
748
+ end: globalOffset + spanGraphemes.length,
749
+ style: spanStyle,
750
+ });
751
+ }
752
+ globalOffset += spanGraphemes.length;
753
+ }
754
+ // 加上最后一行
755
+ if (lineText.length) {
756
+ lines.push({ text: lineText, left: curLineLeft });
757
+ }
758
+ // 加上换行符号
759
+ textContent = lines.map((v) => v.text).join('\n');
760
+ lineCnt = lines.length;
761
+ if (calcHorAlign) {
762
+ if (lines.some((v) => v.left !== curLineLeft)) {
763
+ // 取最left的最小值,和right最大值
764
+ let minLeft = lines[0].left, maxRight = lines[0].left, maxWidth = 0, minCenter = null, maxCenter = null, maxChar = 0, maxCharIdx = 0;
765
+ lines.forEach((v, idx) => {
766
+ minLeft = Math.min(minLeft, v.left);
767
+ v.width = new Textbox(v.text, options).calcTextWidth();
768
+ v.right = v.left + (v.width || 0);
769
+ maxRight = Math.max(maxRight, v.right);
770
+ maxWidth = Math.max(maxWidth, v.width || 0);
771
+ if (v.width) {
772
+ const center = v.left + (v.width || 0) / 2;
773
+ minCenter = minCenter ? Math.min(minCenter, center) : center;
774
+ maxCenter = maxCenter ? Math.max(maxCenter, center) : center;
775
+ if (v.text.length > maxChar) {
776
+ maxChar = v.text.length;
777
+ maxCharIdx = idx;
778
+ }
779
+ }
780
+ });
781
+ let leftGap = 0, rightGap = 0;
782
+ lines.forEach((v) => {
783
+ leftGap = Math.max(leftGap, (v.left || 0) - minLeft);
784
+ rightGap = Math.max(rightGap, maxRight - (v.right || 0));
785
+ });
786
+ // 计算中心点位置
787
+ if (maxCenter !== null && minCenter !== null) {
788
+ const centerOff = maxCenter - minCenter;
789
+ const onCharWidth = (lines[maxCharIdx].width || 0) / lines[maxCharIdx].text.length;
790
+ // 左边间距大于右边两倍 或者 中心点偏移超过1/2字符且右边间距小于1/3字符
791
+ if (leftGap / (rightGap || 1) > 2 &&
792
+ centerOff > onCharWidth / 2 &&
793
+ rightGap < onCharWidth / 3) {
794
+ calcAdjustHorAlign = 'right';
795
+ }
796
+ else if (centerOff < onCharWidth / 2) {
797
+ calcAdjustHorAlign = 'center';
798
+ }
799
+ }
800
+ }
801
+ }
802
+ }
803
+ }
804
+ // 处理文字的水平偏移
805
+ // 只有当 tspan 显式携带 x/dx 位置(minSpanX 非空)时,tspan 的 x 才是相对
806
+ // <text> 原点的偏移量,需要换算成绝对坐标;否则 <text> 上的 x 本身就是绝对坐标,
807
+ // 直接使用,避免把整个 left 减掉导致 X 轴整体偏移(GPT 等标准 SVG 常见)。
808
+ spanOffX = minSpanX != null ? options.left - minSpanX : 0;
809
+ // textAlign保持和parsedAnchor一致
810
+ options.textAlign = parsedAnchor;
811
+ // 注释掉原来删除换行等符号的代码
812
+ //textContent = textContent.replace(/^\s+|\s+$|\n+/g, '').replace(/\s+/g, ' ');
813
+ var originalStrokeWidth = options.strokeWidth;
814
+ options.strokeWidth = 0;
815
+ // 导入时打开自动计算文字高度,否则文字高度和 Y 轴位置错误
816
+ Textbox.enableCalcTextHeight = true;
817
+ var text = new Textbox(textContent, options);
818
+ // 恢复逐字符样式(tspan 的不同字体/字号/颜色)。stylesFromArray 会把
819
+ // [{start,end,style}] 转成 fabric 的 { line: { char: style } } 结构。
820
+ // 必须放在下面 text.height 等计算之前:tspan 可能单独指定 fontSize
821
+ // (对象 fontSize 很大但字符实际用 14px),先应用样式才能让 text.height
822
+ // 反映真实字形高度,否则 offY 用对象级大字号算出巨大垂直偏移。
823
+ if (stylesArray.length) {
824
+ text.set({ styles: stylesFromArray(stylesArray, text.text || textContent) });
825
+ }
826
+ // offY 定位的是「第一行」的 baseline。当存在逐字符样式时,不同行的字号可能不同
827
+ // (例如第一行 62px、第二行 74px),此时 text.height / lineCnt 是「平均行高」,
828
+ // 会让 textHeight 被第二行的更大字号带偏,导致第一行整体偏移。此时应改用第一行的
829
+ // 实际高度 getHeightOfLine(0),与「统一字号」时 text.height / lineCnt 完全一致。
830
+ // 无逐字符样式时保持原逻辑不变(text.height / lineCnt)。
831
+ var firstLineHeight = stylesArray.length && lineCnt > 0
832
+ ? text.getHeightOfLine(0)
833
+ : text.height / lineCnt, textHeightScaleFactor = text.getScaledHeight() / text.height, lineHeightDiff = (firstLineHeight + text.strokeWidth) * text.lineHeight -
834
+ firstLineHeight, scaledDiff = lineHeightDiff * textHeightScaleFactor, textHeight = (stylesArray.length && lineCnt > 0
835
+ ? firstLineHeight * textHeightScaleFactor
836
+ : text.getScaledHeight() / lineCnt) + scaledDiff, offX = 0, offY = 0;
837
+ // 默认 alignment-baseline="before-edge" offY = 0
838
+ let offScale = 0;
839
+ if (alignmentBaseline === 'before-edge') {
840
+ // 这个是1.0 导出的偏移值,多行且间距设置大于1也会有变化
841
+ // 暂时这么处理, 以后再解决
842
+ offScale = 1.1;
843
+ }
844
+ else if (alignmentBaseline === 'auto') {
845
+ // alignment-baseline="auto" 或者 没有设置
846
+ offScale = 0.02913333333;
847
+ }
848
+ if (offScale !== 0) {
849
+ // 仅当存在逐字符样式(不同字符不同 fontSize/字体)时,对象级 fontSize 才可能
850
+ // 被覆盖,需要反推「实际渲染用到的字号」;否则直接用对象级 fontSize,
851
+ // 保持原有导入行为完全不变(兼容 lineHeight ≠ 1 等所有正常场景)。
852
+ let effectiveFontSize = text.fontSize;
853
+ if (stylesArray.length) {
854
+ // offY 定位的是「第一行」的 baseline(text.top 是文本框顶部,对应第一行),
855
+ // 因此这里应取第一行的真实字号,而不是所有行的最大字号。若取最大字号
856
+ // (例如第二行用了更大的逐字符 fontSize),会把第一行整体向下/向上带偏。
857
+ // getHeightOfLine(0) = 第一行字符 fontSize 的最大值 × lineHeight × fontSizeMult,
858
+ // 反推即第一行的有效字号。
859
+ const firstLineHeight = text.getHeightOfLine(0);
860
+ effectiveFontSize = firstLineHeight / (text.lineHeight * text._fontSizeMult);
861
+ }
862
+ offY =
863
+ (textHeight -
864
+ effectiveFontSize * (offScale + text._fontSizeFraction)) /
865
+ text.lineHeight;
866
+ }
867
+ // 取消自动计算文字高度
868
+ Textbox.enableCalcTextHeight = false;
869
+ /*
870
+ Adjust positioning:
871
+ x/y attributes in SVG correspond to the bottom-left corner of text bounding box
872
+ fabric output by default at top, left.
873
+ */
874
+ const adjustOption = {};
875
+ // 源码中options.width总是等于svg的宽度, 之前是new Text不能编辑文字,宽度设置为svg宽度也无效
876
+ // 修改为 new fabric.Textbox,并且设置为计算的正确宽度
877
+ const originWidth = options.width;
878
+ let width = text.calcTextWidth();
879
+ // 有时候计算出来的大小是不对的, 可能是字体的原因, 导致TextBox自动换行了, 所以加i字符的宽度
880
+ const oneIWidth = new Textbox('i', options).calcTextWidth();
881
+ width += oneIWidth;
882
+ if (originWidth !== width) {
883
+ adjustOption.width = width;
884
+ }
885
+ if (calcAdjustHorAlign) {
886
+ // tspan 按字符分开计算的对齐
887
+ adjustOption.textAlign = calcAdjustHorAlign;
888
+ }
889
+ // 2021.1.29修改
890
+ // Vectr1.0导出的svg,需要处理水平居中或右对齐偏移
891
+ // Vectr2.0导出的是按照span位置判断的对齐不需要处理整个width的位置偏移, 但是需要处理 oneIWidth的位置偏移
892
+ const textAlign = calcAdjustHorAlign || parsedAnchor;
893
+ if (textAlign === 'center') {
894
+ offX = (parsedAnchor === 'center' ? width : oneIWidth) / 2;
895
+ }
896
+ else if (textAlign === 'right') {
897
+ offX = parsedAnchor === 'right' ? width : oneIWidth;
898
+ }
899
+ text.set({
900
+ ...adjustOption,
901
+ left: text.left - offX - spanOffX,
902
+ top: text.top - offY - spanOffY,
903
+ strokeWidth: typeof originalStrokeWidth !== 'undefined' ? originalStrokeWidth : 1,
904
+ });
905
+ return text;
906
+ }
907
+ }
908
+ classRegistry.setClass(Textbox);
909
+ classRegistry.setSVGClass(Textbox);
910
+ //# sourceMappingURL=Textbox.js.map