fabric-vectr 6.7.15 → 6.7.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (608) hide show
  1. package/dist/dist/index.d.mts +13871 -0
  2. package/dist/dist/index.d.mts.map +1 -0
  3. package/dist/dist/index.mjs +26926 -0
  4. package/dist/dist/index.mjs.map +1 -0
  5. package/dist/dist/src/util/internals/cloneStyles.d.mts +2 -0
  6. package/dist/dist/src/util/internals/cloneStyles.d.mts.map +1 -0
  7. package/dist/dist/src/util/internals/cloneStyles.mjs +15 -0
  8. package/dist/dist/src/util/internals/cloneStyles.mjs.map +1 -0
  9. package/dist/extensions/aligning_guidelines/constant.js +9 -0
  10. package/dist/extensions/aligning_guidelines/constant.js.map +1 -0
  11. package/dist/extensions/aligning_guidelines/index.js +132 -0
  12. package/dist/extensions/aligning_guidelines/index.js.map +1 -0
  13. package/dist/extensions/aligning_guidelines/typedefs.js +2 -0
  14. package/dist/extensions/aligning_guidelines/typedefs.js.map +1 -0
  15. package/dist/extensions/aligning_guidelines/util/basic.js +12 -0
  16. package/dist/extensions/aligning_guidelines/util/basic.js.map +1 -0
  17. package/dist/extensions/aligning_guidelines/util/basic.spec.d.ts +2 -0
  18. package/dist/extensions/aligning_guidelines/util/basic.spec.d.ts.map +1 -0
  19. package/dist/extensions/aligning_guidelines/util/basic.spec.js +30 -0
  20. package/dist/extensions/aligning_guidelines/util/basic.spec.js.map +1 -0
  21. package/dist/extensions/aligning_guidelines/util/collect-line.js +129 -0
  22. package/dist/extensions/aligning_guidelines/util/collect-line.js.map +1 -0
  23. package/dist/extensions/aligning_guidelines/util/collect-point.js +78 -0
  24. package/dist/extensions/aligning_guidelines/util/collect-point.js.map +1 -0
  25. package/dist/extensions/aligning_guidelines/util/draw.js +67 -0
  26. package/dist/extensions/aligning_guidelines/util/draw.js.map +1 -0
  27. package/dist/extensions/aligning_guidelines/util/get-objects-by-target.js +44 -0
  28. package/dist/extensions/aligning_guidelines/util/get-objects-by-target.js.map +1 -0
  29. package/dist/extensions/data_updaters/origins/index.js +36 -0
  30. package/dist/extensions/data_updaters/origins/index.js.map +1 -0
  31. package/dist/extensions/data_updaters/origins/index.spec.d.ts +2 -0
  32. package/dist/extensions/data_updaters/origins/index.spec.d.ts.map +1 -0
  33. package/dist/extensions/data_updaters/origins/index.spec.js +94 -0
  34. package/dist/extensions/data_updaters/origins/index.spec.js.map +1 -0
  35. package/dist/extensions/index.js +3 -0
  36. package/dist/extensions/index.js.map +1 -0
  37. package/dist/fabric.js +101 -0
  38. package/dist/fabric.js.map +1 -0
  39. package/dist/index.js +6 -3
  40. package/dist/index.js.map +1 -1
  41. package/dist/index.min.js +1 -1
  42. package/dist/index.min.js.map +1 -1
  43. package/dist/index.min.mjs +1 -1
  44. package/dist/index.min.mjs.map +1 -1
  45. package/dist/index.mjs +6 -3
  46. package/dist/index.mjs.map +1 -1
  47. package/dist/index.node.cjs +6 -3
  48. package/dist/index.node.cjs.map +1 -1
  49. package/dist/index.node.js +37 -0
  50. package/dist/index.node.js.map +1 -0
  51. package/dist/index.node.mjs +6 -3
  52. package/dist/index.node.mjs.map +1 -1
  53. package/dist/package.json +178 -0
  54. package/dist/package.json.min.mjs +1 -1
  55. package/dist/package.json.mjs +1 -1
  56. package/dist/src/ClassRegistry.js +49 -0
  57. package/dist/src/ClassRegistry.js.map +1 -0
  58. package/dist/src/Collection.js +295 -0
  59. package/dist/src/Collection.js.map +1 -0
  60. package/dist/src/CommonMethods.js +58 -0
  61. package/dist/src/CommonMethods.js.map +1 -0
  62. package/dist/src/EventTypeDefs.js +2 -0
  63. package/dist/src/EventTypeDefs.js.map +1 -0
  64. package/dist/src/Intersection.js +250 -0
  65. package/dist/src/Intersection.js.map +1 -0
  66. package/dist/src/LayoutManager/ActiveSelectionLayoutManager.js +47 -0
  67. package/dist/src/LayoutManager/ActiveSelectionLayoutManager.js.map +1 -0
  68. package/dist/src/LayoutManager/LayoutManager.js +238 -0
  69. package/dist/src/LayoutManager/LayoutManager.js.map +1 -0
  70. package/dist/src/LayoutManager/LayoutStrategies/ClipPathLayout.js +60 -0
  71. package/dist/src/LayoutManager/LayoutStrategies/ClipPathLayout.js.map +1 -0
  72. package/dist/src/LayoutManager/LayoutStrategies/FitContentLayout.js +18 -0
  73. package/dist/src/LayoutManager/LayoutStrategies/FitContentLayout.js.map +1 -0
  74. package/dist/src/LayoutManager/LayoutStrategies/FixedLayout.js +17 -0
  75. package/dist/src/LayoutManager/LayoutStrategies/FixedLayout.js.map +1 -0
  76. package/dist/src/LayoutManager/LayoutStrategies/LayoutStrategy.js +80 -0
  77. package/dist/src/LayoutManager/LayoutStrategies/LayoutStrategy.js.map +1 -0
  78. package/dist/src/LayoutManager/LayoutStrategies/utils.js +28 -0
  79. package/dist/src/LayoutManager/LayoutStrategies/utils.js.map +1 -0
  80. package/dist/src/LayoutManager/constants.js +7 -0
  81. package/dist/src/LayoutManager/constants.js.map +1 -0
  82. package/dist/src/LayoutManager/index.js +7 -0
  83. package/dist/src/LayoutManager/index.js.map +1 -0
  84. package/dist/src/LayoutManager/types.js +2 -0
  85. package/dist/src/LayoutManager/types.js.map +1 -0
  86. package/dist/src/Observable.js +107 -0
  87. package/dist/src/Observable.js.map +1 -0
  88. package/dist/src/Pattern/Pattern.js +152 -0
  89. package/dist/src/Pattern/Pattern.js.map +1 -0
  90. package/dist/src/Pattern/index.js +3 -0
  91. package/dist/src/Pattern/index.js.map +1 -0
  92. package/dist/src/Pattern/types.js +2 -0
  93. package/dist/src/Pattern/types.js.map +1 -0
  94. package/dist/src/Point.js +330 -0
  95. package/dist/src/Point.js.map +1 -0
  96. package/dist/src/Shadow.js +125 -0
  97. package/dist/src/Shadow.js.map +1 -0
  98. package/dist/src/benchmarks/boundingBoxFromPoint.d.mts +2 -0
  99. package/dist/src/benchmarks/boundingBoxFromPoint.d.mts.map +1 -0
  100. package/dist/src/benchmarks/boundingBoxFromPoint.mjs +54 -0
  101. package/dist/src/benchmarks/boundingBoxFromPoint.mjs.map +1 -0
  102. package/dist/src/benchmarks/calcCornerCoords.d.mts +2 -0
  103. package/dist/src/benchmarks/calcCornerCoords.d.mts.map +1 -0
  104. package/dist/src/benchmarks/calcCornerCoords.mjs +78 -0
  105. package/dist/src/benchmarks/calcCornerCoords.mjs.map +1 -0
  106. package/dist/src/benchmarks/calcTransformMatrix.d.mts +2 -0
  107. package/dist/src/benchmarks/calcTransformMatrix.d.mts.map +1 -0
  108. package/dist/src/benchmarks/calcTransformMatrix.mjs +71 -0
  109. package/dist/src/benchmarks/calcTransformMatrix.mjs.map +1 -0
  110. package/dist/src/benchmarks/cloneStyles.d.mts +2 -0
  111. package/dist/src/benchmarks/cloneStyles.d.mts.map +1 -0
  112. package/dist/src/benchmarks/cloneStyles.mjs +56 -0
  113. package/dist/src/benchmarks/cloneStyles.mjs.map +1 -0
  114. package/dist/src/benchmarks/pathCloning.d.mts +2 -0
  115. package/dist/src/benchmarks/pathCloning.d.mts.map +1 -0
  116. package/dist/src/benchmarks/pathCloning.mjs +94 -0
  117. package/dist/src/benchmarks/pathCloning.mjs.map +1 -0
  118. package/dist/src/benchmarks/pathData.d.mts +3 -0
  119. package/dist/src/benchmarks/pathData.d.mts.map +1 -0
  120. package/dist/src/benchmarks/pathData.mjs +3 -0
  121. package/dist/src/benchmarks/pathData.mjs.map +1 -0
  122. package/dist/src/benchmarks/raycasting.d.mts +2 -0
  123. package/dist/src/benchmarks/raycasting.d.mts.map +1 -0
  124. package/dist/src/benchmarks/raycasting.mjs +134 -0
  125. package/dist/src/benchmarks/raycasting.mjs.map +1 -0
  126. package/dist/src/benchmarks/transformMatrixKey.d.mts +2 -0
  127. package/dist/src/benchmarks/transformMatrixKey.d.mts.map +1 -0
  128. package/dist/src/benchmarks/transformMatrixKey.mjs +81 -0
  129. package/dist/src/benchmarks/transformMatrixKey.mjs.map +1 -0
  130. package/dist/src/brushes/BaseBrush.js +121 -0
  131. package/dist/src/brushes/BaseBrush.js.map +1 -0
  132. package/dist/src/brushes/CircleBrush.js +117 -0
  133. package/dist/src/brushes/CircleBrush.js.map +1 -0
  134. package/dist/src/brushes/PatternBrush.js +49 -0
  135. package/dist/src/brushes/PatternBrush.js.map +1 -0
  136. package/dist/src/brushes/PencilBrush.js +259 -0
  137. package/dist/src/brushes/PencilBrush.js.map +1 -0
  138. package/dist/src/brushes/SprayBrush.js +174 -0
  139. package/dist/src/brushes/SprayBrush.js.map +1 -0
  140. package/dist/src/brushes/typedefs.js +2 -0
  141. package/dist/src/brushes/typedefs.js.map +1 -0
  142. package/dist/src/cache.js +69 -0
  143. package/dist/src/cache.js.map +1 -0
  144. package/dist/src/canvas/Canvas.js +1366 -0
  145. package/dist/src/canvas/Canvas.js.map +1 -0
  146. package/dist/src/canvas/CanvasOptions.js +31 -0
  147. package/dist/src/canvas/CanvasOptions.js.map +1 -0
  148. package/dist/src/canvas/DOMManagers/CanvasDOMManager.js +97 -0
  149. package/dist/src/canvas/DOMManagers/CanvasDOMManager.js.map +1 -0
  150. package/dist/src/canvas/DOMManagers/StaticCanvasDOMManager.js +63 -0
  151. package/dist/src/canvas/DOMManagers/StaticCanvasDOMManager.js.map +1 -0
  152. package/dist/src/canvas/DOMManagers/util.js +56 -0
  153. package/dist/src/canvas/DOMManagers/util.js.map +1 -0
  154. package/dist/src/canvas/SelectableCanvas.js +1141 -0
  155. package/dist/src/canvas/SelectableCanvas.js.map +1 -0
  156. package/dist/src/canvas/StaticCanvas.js +1085 -0
  157. package/dist/src/canvas/StaticCanvas.js.map +1 -0
  158. package/dist/src/canvas/StaticCanvasOptions.js +23 -0
  159. package/dist/src/canvas/StaticCanvasOptions.js.map +1 -0
  160. package/dist/src/canvas/TextEditingManager.js +54 -0
  161. package/dist/src/canvas/TextEditingManager.js.map +1 -0
  162. package/dist/src/canvas/canvas_gestures.mixin.js +181 -0
  163. package/dist/src/canvas/canvas_gestures.mixin.js.map +1 -0
  164. package/dist/src/color/Color.js +301 -0
  165. package/dist/src/color/Color.js.map +1 -0
  166. package/dist/src/color/color_map.js +155 -0
  167. package/dist/src/color/color_map.js.map +1 -0
  168. package/dist/src/color/constants.js +111 -0
  169. package/dist/src/color/constants.js.map +1 -0
  170. package/dist/src/color/typedefs.js +2 -0
  171. package/dist/src/color/typedefs.js.map +1 -0
  172. package/dist/src/color/util.js +73 -0
  173. package/dist/src/color/util.js.map +1 -0
  174. package/dist/src/config.js +140 -0
  175. package/dist/src/config.js.map +1 -0
  176. package/dist/src/constants.js +38 -0
  177. package/dist/src/constants.js.map +1 -0
  178. package/dist/src/controls/Control.js +241 -0
  179. package/dist/src/controls/Control.js.map +1 -0
  180. package/dist/src/controls/changeWidth.js +31 -0
  181. package/dist/src/controls/changeWidth.js.map +1 -0
  182. package/dist/src/controls/commonControls.js +91 -0
  183. package/dist/src/controls/commonControls.js.map +1 -0
  184. package/dist/src/controls/controlRendering.js +81 -0
  185. package/dist/src/controls/controlRendering.js.map +1 -0
  186. package/dist/src/controls/drag.js +22 -0
  187. package/dist/src/controls/drag.js.map +1 -0
  188. package/dist/src/controls/fireEvent.js +9 -0
  189. package/dist/src/controls/fireEvent.js.map +1 -0
  190. package/dist/src/controls/index.js +14 -0
  191. package/dist/src/controls/index.js.map +1 -0
  192. package/dist/src/controls/pathControl.js +137 -0
  193. package/dist/src/controls/pathControl.js.map +1 -0
  194. package/dist/src/controls/polyControl.js +66 -0
  195. package/dist/src/controls/polyControl.js.map +1 -0
  196. package/dist/src/controls/rotate.js +57 -0
  197. package/dist/src/controls/rotate.js.map +1 -0
  198. package/dist/src/controls/scale.js +190 -0
  199. package/dist/src/controls/scale.js.map +1 -0
  200. package/dist/src/controls/scaleSkew.js +66 -0
  201. package/dist/src/controls/scaleSkew.js.map +1 -0
  202. package/dist/src/controls/skew.js +147 -0
  203. package/dist/src/controls/skew.js.map +1 -0
  204. package/dist/src/controls/util.js +89 -0
  205. package/dist/src/controls/util.js.map +1 -0
  206. package/dist/src/controls/wrapWithFireEvent.js +22 -0
  207. package/dist/src/controls/wrapWithFireEvent.js.map +1 -0
  208. package/dist/src/controls/wrapWithFixedAnchor.js +16 -0
  209. package/dist/src/controls/wrapWithFixedAnchor.js.map +1 -0
  210. package/dist/src/env/browser.js +18 -0
  211. package/dist/src/env/browser.js.map +1 -0
  212. package/dist/src/env/index.js +37 -0
  213. package/dist/src/env/index.js.map +1 -0
  214. package/dist/src/env/node.js +37 -0
  215. package/dist/src/env/node.js.map +1 -0
  216. package/dist/src/env/types.js +2 -0
  217. package/dist/src/env/types.js.map +1 -0
  218. package/dist/src/filters/BaseFilter.js +304 -0
  219. package/dist/src/filters/BaseFilter.js.map +1 -0
  220. package/dist/src/filters/BlendColor.js +147 -0
  221. package/dist/src/filters/BlendColor.js.map +1 -0
  222. package/dist/src/filters/BlendImage.js +149 -0
  223. package/dist/src/filters/BlendImage.js.map +1 -0
  224. package/dist/src/filters/Blur.js +167 -0
  225. package/dist/src/filters/Blur.js.map +1 -0
  226. package/dist/src/filters/Boilerplate.js +61 -0
  227. package/dist/src/filters/Boilerplate.js.map +1 -0
  228. package/dist/src/filters/Brightness.js +51 -0
  229. package/dist/src/filters/Brightness.js.map +1 -0
  230. package/dist/src/filters/Canvas2dFilterBackend.js +51 -0
  231. package/dist/src/filters/Canvas2dFilterBackend.js.map +1 -0
  232. package/dist/src/filters/ColorMatrix.js +92 -0
  233. package/dist/src/filters/ColorMatrix.js.map +1 -0
  234. package/dist/src/filters/ColorMatrixFilters.js +45 -0
  235. package/dist/src/filters/ColorMatrixFilters.js.map +1 -0
  236. package/dist/src/filters/Composed.js +55 -0
  237. package/dist/src/filters/Composed.js.map +1 -0
  238. package/dist/src/filters/Contrast.js +51 -0
  239. package/dist/src/filters/Contrast.js.map +1 -0
  240. package/dist/src/filters/Convolute.js +132 -0
  241. package/dist/src/filters/Convolute.js.map +1 -0
  242. package/dist/src/filters/FilterBackend.js +34 -0
  243. package/dist/src/filters/FilterBackend.js.map +1 -0
  244. package/dist/src/filters/GLProbes/GLProbe.js +3 -0
  245. package/dist/src/filters/GLProbes/GLProbe.js.map +1 -0
  246. package/dist/src/filters/GLProbes/NodeGLProbe.js +15 -0
  247. package/dist/src/filters/GLProbes/NodeGLProbe.js.map +1 -0
  248. package/dist/src/filters/GLProbes/WebGLProbe.js +39 -0
  249. package/dist/src/filters/GLProbes/WebGLProbe.js.map +1 -0
  250. package/dist/src/filters/Gamma.js +80 -0
  251. package/dist/src/filters/Gamma.js.map +1 -0
  252. package/dist/src/filters/Grayscale.js +69 -0
  253. package/dist/src/filters/Grayscale.js.map +1 -0
  254. package/dist/src/filters/HueRotation.js +61 -0
  255. package/dist/src/filters/HueRotation.js.map +1 -0
  256. package/dist/src/filters/Invert.js +58 -0
  257. package/dist/src/filters/Invert.js.map +1 -0
  258. package/dist/src/filters/Noise.js +54 -0
  259. package/dist/src/filters/Noise.js.map +1 -0
  260. package/dist/src/filters/Pixelate.js +66 -0
  261. package/dist/src/filters/Pixelate.js.map +1 -0
  262. package/dist/src/filters/RemoveColor.js +74 -0
  263. package/dist/src/filters/RemoveColor.js.map +1 -0
  264. package/dist/src/filters/Resize.js +399 -0
  265. package/dist/src/filters/Resize.js.map +1 -0
  266. package/dist/src/filters/Saturation.js +55 -0
  267. package/dist/src/filters/Saturation.js.map +1 -0
  268. package/dist/src/filters/Vibrance.js +57 -0
  269. package/dist/src/filters/Vibrance.js.map +1 -0
  270. package/dist/src/filters/WebGLFilterBackend.js +269 -0
  271. package/dist/src/filters/WebGLFilterBackend.js.map +1 -0
  272. package/dist/src/filters/filters.js +21 -0
  273. package/dist/src/filters/filters.js.map +1 -0
  274. package/dist/src/filters/index.js +7 -0
  275. package/dist/src/filters/index.js.map +1 -0
  276. package/dist/src/filters/shaders/baseFilter.js +16 -0
  277. package/dist/src/filters/shaders/baseFilter.js.map +1 -0
  278. package/dist/src/filters/shaders/blendColor.js +32 -0
  279. package/dist/src/filters/shaders/blendColor.js.map +1 -0
  280. package/dist/src/filters/shaders/blendImage.js +42 -0
  281. package/dist/src/filters/shaders/blendImage.js.map +1 -0
  282. package/dist/src/filters/shaders/blur.js +31 -0
  283. package/dist/src/filters/shaders/blur.js.map +1 -0
  284. package/dist/src/filters/shaders/brightness.js +12 -0
  285. package/dist/src/filters/shaders/brightness.js.map +1 -0
  286. package/dist/src/filters/shaders/colorMatrix.js +13 -0
  287. package/dist/src/filters/shaders/colorMatrix.js.map +1 -0
  288. package/dist/src/filters/shaders/constrast.js +12 -0
  289. package/dist/src/filters/shaders/constrast.js.map +1 -0
  290. package/dist/src/filters/shaders/convolute.js +155 -0
  291. package/dist/src/filters/shaders/convolute.js.map +1 -0
  292. package/dist/src/filters/shaders/gamma.js +16 -0
  293. package/dist/src/filters/shaders/gamma.js.map +1 -0
  294. package/dist/src/filters/shaders/grayscale.js +35 -0
  295. package/dist/src/filters/shaders/grayscale.js.map +1 -0
  296. package/dist/src/filters/shaders/invert.js +20 -0
  297. package/dist/src/filters/shaders/invert.js.map +1 -0
  298. package/dist/src/filters/shaders/noise.js +17 -0
  299. package/dist/src/filters/shaders/noise.js.map +1 -0
  300. package/dist/src/filters/shaders/pixelate.js +20 -0
  301. package/dist/src/filters/shaders/pixelate.js.map +1 -0
  302. package/dist/src/filters/shaders/removeColor.js +14 -0
  303. package/dist/src/filters/shaders/removeColor.js.map +1 -0
  304. package/dist/src/filters/shaders/saturation.js +16 -0
  305. package/dist/src/filters/shaders/saturation.js.map +1 -0
  306. package/dist/src/filters/shaders/vibrance.js +17 -0
  307. package/dist/src/filters/shaders/vibrance.js.map +1 -0
  308. package/dist/src/filters/typedefs.js +2 -0
  309. package/dist/src/filters/typedefs.js.map +1 -0
  310. package/dist/src/filters/utils.js +36 -0
  311. package/dist/src/filters/utils.js.map +1 -0
  312. package/dist/src/gradient/Gradient.d.ts.map +1 -1
  313. package/dist/src/gradient/Gradient.js +244 -0
  314. package/dist/src/gradient/Gradient.js.map +1 -0
  315. package/dist/src/gradient/Gradient.min.mjs +1 -1
  316. package/dist/src/gradient/Gradient.min.mjs.map +1 -1
  317. package/dist/src/gradient/Gradient.mjs +2 -1
  318. package/dist/src/gradient/Gradient.mjs.map +1 -1
  319. package/dist/src/gradient/constants.js +12 -0
  320. package/dist/src/gradient/constants.js.map +1 -0
  321. package/dist/src/gradient/index.js +3 -0
  322. package/dist/src/gradient/index.js.map +1 -0
  323. package/dist/src/gradient/parser/misc.js +11 -0
  324. package/dist/src/gradient/parser/misc.js.map +1 -0
  325. package/dist/src/gradient/parser/parseColorStops.js +42 -0
  326. package/dist/src/gradient/parser/parseColorStops.js.map +1 -0
  327. package/dist/src/gradient/parser/parseCoords.js +60 -0
  328. package/dist/src/gradient/parser/parseCoords.js.map +1 -0
  329. package/dist/src/gradient/typedefs.js +2 -0
  330. package/dist/src/gradient/typedefs.js.map +1 -0
  331. package/dist/src/mixins/eraser_brush.mixin.js +732 -0
  332. package/dist/src/mixins/eraser_brush.mixin.js.map +1 -0
  333. package/dist/src/parkinglot/canvas_animation.mixin.js +102 -0
  334. package/dist/src/parkinglot/canvas_animation.mixin.js.map +1 -0
  335. package/dist/src/parkinglot/straighten.js +53 -0
  336. package/dist/src/parkinglot/straighten.js.map +1 -0
  337. package/dist/src/parser/applyViewboxTransform.js +146 -0
  338. package/dist/src/parser/applyViewboxTransform.js.map +1 -0
  339. package/dist/src/parser/attributes.js +27 -0
  340. package/dist/src/parser/attributes.js.map +1 -0
  341. package/dist/src/parser/constants.js +70 -0
  342. package/dist/src/parser/constants.js.map +1 -0
  343. package/dist/src/parser/doesSomeParentMatch.js +15 -0
  344. package/dist/src/parser/doesSomeParentMatch.js.map +1 -0
  345. package/dist/src/parser/elementMatchesRule.js +15 -0
  346. package/dist/src/parser/elementMatchesRule.js.map +1 -0
  347. package/dist/src/parser/elements_parser.js +164 -0
  348. package/dist/src/parser/elements_parser.js.map +1 -0
  349. package/dist/src/parser/getCSSRules.js +62 -0
  350. package/dist/src/parser/getCSSRules.js.map +1 -0
  351. package/dist/src/parser/getGlobalStylesForElement.js +17 -0
  352. package/dist/src/parser/getGlobalStylesForElement.js.map +1 -0
  353. package/dist/src/parser/getGradientDefs.js +30 -0
  354. package/dist/src/parser/getGradientDefs.js.map +1 -0
  355. package/dist/src/parser/getMultipleNodes.js +10 -0
  356. package/dist/src/parser/getMultipleNodes.js.map +1 -0
  357. package/dist/src/parser/getPatternDefs.js +70 -0
  358. package/dist/src/parser/getPatternDefs.js.map +1 -0
  359. package/dist/src/parser/getSvgRegex.js +4 -0
  360. package/dist/src/parser/getSvgRegex.js.map +1 -0
  361. package/dist/src/parser/getTagName.js +2 -0
  362. package/dist/src/parser/getTagName.js.map +1 -0
  363. package/dist/src/parser/hasInvalidAncestor.js +17 -0
  364. package/dist/src/parser/hasInvalidAncestor.js.map +1 -0
  365. package/dist/src/parser/loadSVGFromString.js +23 -0
  366. package/dist/src/parser/loadSVGFromString.js.map +1 -0
  367. package/dist/src/parser/loadSVGFromURL.js +39 -0
  368. package/dist/src/parser/loadSVGFromURL.js.map +1 -0
  369. package/dist/src/parser/normalizeAttr.js +3 -0
  370. package/dist/src/parser/normalizeAttr.js.map +1 -0
  371. package/dist/src/parser/normalizeValue.js +79 -0
  372. package/dist/src/parser/normalizeValue.js.map +1 -0
  373. package/dist/src/parser/parseAttributes.js +66 -0
  374. package/dist/src/parser/parseAttributes.js.map +1 -0
  375. package/dist/src/parser/parseFontDeclaration.js +38 -0
  376. package/dist/src/parser/parseFontDeclaration.js.map +1 -0
  377. package/dist/src/parser/parsePointsAttribute.js +28 -0
  378. package/dist/src/parser/parsePointsAttribute.js.map +1 -0
  379. package/dist/src/parser/parseSVGDocument.js +74 -0
  380. package/dist/src/parser/parseSVGDocument.js.map +1 -0
  381. package/dist/src/parser/parseStyleAttribute.js +23 -0
  382. package/dist/src/parser/parseStyleAttribute.js.map +1 -0
  383. package/dist/src/parser/parseStyleObject.js +15 -0
  384. package/dist/src/parser/parseStyleObject.js.map +1 -0
  385. package/dist/src/parser/parseStyleString.js +18 -0
  386. package/dist/src/parser/parseStyleString.js.map +1 -0
  387. package/dist/src/parser/parseTransformAttribute.js +76 -0
  388. package/dist/src/parser/parseTransformAttribute.js.map +1 -0
  389. package/dist/src/parser/parseUseDirectives.js +76 -0
  390. package/dist/src/parser/parseUseDirectives.js.map +1 -0
  391. package/dist/src/parser/percent.js +21 -0
  392. package/dist/src/parser/percent.js.map +1 -0
  393. package/dist/src/parser/recursivelyParseGradientsXlink.js +36 -0
  394. package/dist/src/parser/recursivelyParseGradientsXlink.js.map +1 -0
  395. package/dist/src/parser/selectorMatches.js +24 -0
  396. package/dist/src/parser/selectorMatches.js.map +1 -0
  397. package/dist/src/parser/setStrokeFillOpacity.js +35 -0
  398. package/dist/src/parser/setStrokeFillOpacity.js.map +1 -0
  399. package/dist/src/parser/typedefs.js +2 -0
  400. package/dist/src/parser/typedefs.js.map +1 -0
  401. package/dist/src/shapes/ActiveSelection.js +195 -0
  402. package/dist/src/shapes/ActiveSelection.js.map +1 -0
  403. package/dist/src/shapes/Circle.js +155 -0
  404. package/dist/src/shapes/Circle.js.map +1 -0
  405. package/dist/src/shapes/Ellipse.js +120 -0
  406. package/dist/src/shapes/Ellipse.js.map +1 -0
  407. package/dist/src/shapes/Group.js +549 -0
  408. package/dist/src/shapes/Group.js.map +1 -0
  409. package/dist/src/shapes/IText/DraggableTextDelegate.js +326 -0
  410. package/dist/src/shapes/IText/DraggableTextDelegate.js.map +1 -0
  411. package/dist/src/shapes/IText/IText.js +545 -0
  412. package/dist/src/shapes/IText/IText.js.map +1 -0
  413. package/dist/src/shapes/IText/ITextBehavior.js +848 -0
  414. package/dist/src/shapes/IText/ITextBehavior.js.map +1 -0
  415. package/dist/src/shapes/IText/ITextClickBehavior.js +196 -0
  416. package/dist/src/shapes/IText/ITextClickBehavior.js.map +1 -0
  417. package/dist/src/shapes/IText/ITextKeyBehavior.js +522 -0
  418. package/dist/src/shapes/IText/ITextKeyBehavior.js.map +1 -0
  419. package/dist/src/shapes/IText/constants.js +47 -0
  420. package/dist/src/shapes/IText/constants.js.map +1 -0
  421. package/dist/src/shapes/Image.js +589 -0
  422. package/dist/src/shapes/Image.js.map +1 -0
  423. package/dist/src/shapes/Line.js +195 -0
  424. package/dist/src/shapes/Line.js.map +1 -0
  425. package/dist/src/shapes/Object/FabricObject.js +12 -0
  426. package/dist/src/shapes/Object/FabricObject.js.map +1 -0
  427. package/dist/src/shapes/Object/FabricObjectSVGExportMixin.js +255 -0
  428. package/dist/src/shapes/Object/FabricObjectSVGExportMixin.js.map +1 -0
  429. package/dist/src/shapes/Object/InteractiveObject.js +478 -0
  430. package/dist/src/shapes/Object/InteractiveObject.js.map +1 -0
  431. package/dist/src/shapes/Object/Object.js +1392 -0
  432. package/dist/src/shapes/Object/Object.js.map +1 -0
  433. package/dist/src/shapes/Object/ObjectGeometry.js +537 -0
  434. package/dist/src/shapes/Object/ObjectGeometry.js.map +1 -0
  435. package/dist/src/shapes/Object/defaultValues.js +109 -0
  436. package/dist/src/shapes/Object/defaultValues.js.map +1 -0
  437. package/dist/src/shapes/Object/types/BaseProps.js +2 -0
  438. package/dist/src/shapes/Object/types/BaseProps.js.map +1 -0
  439. package/dist/src/shapes/Object/types/BorderProps.js +2 -0
  440. package/dist/src/shapes/Object/types/BorderProps.js.map +1 -0
  441. package/dist/src/shapes/Object/types/ControlProps.js +2 -0
  442. package/dist/src/shapes/Object/types/ControlProps.js.map +1 -0
  443. package/dist/src/shapes/Object/types/FabricObjectProps.js +2 -0
  444. package/dist/src/shapes/Object/types/FabricObjectProps.js.map +1 -0
  445. package/dist/src/shapes/Object/types/FillStrokeProps.js +2 -0
  446. package/dist/src/shapes/Object/types/FillStrokeProps.js.map +1 -0
  447. package/dist/src/shapes/Object/types/LockInteractionProps.js +2 -0
  448. package/dist/src/shapes/Object/types/LockInteractionProps.js.map +1 -0
  449. package/dist/src/shapes/Object/types/ObjectProps.js +2 -0
  450. package/dist/src/shapes/Object/types/ObjectProps.js.map +1 -0
  451. package/dist/src/shapes/Object/types/ObjectTransformProps.js +2 -0
  452. package/dist/src/shapes/Object/types/ObjectTransformProps.js.map +1 -0
  453. package/dist/src/shapes/Object/types/SerializedObjectProps.js +2 -0
  454. package/dist/src/shapes/Object/types/SerializedObjectProps.js.map +1 -0
  455. package/dist/src/shapes/Object/types/index.js +2 -0
  456. package/dist/src/shapes/Object/types/index.js.map +1 -0
  457. package/dist/src/shapes/Path.js +267 -0
  458. package/dist/src/shapes/Path.js.map +1 -0
  459. package/dist/src/shapes/Polygon.js +12 -0
  460. package/dist/src/shapes/Polygon.js.map +1 -0
  461. package/dist/src/shapes/Polyline.js +307 -0
  462. package/dist/src/shapes/Polyline.js.map +1 -0
  463. package/dist/src/shapes/Rect.js +131 -0
  464. package/dist/src/shapes/Rect.js.map +1 -0
  465. package/dist/src/shapes/Text/StyledText.js +261 -0
  466. package/dist/src/shapes/Text/StyledText.js.map +1 -0
  467. package/dist/src/shapes/Text/Text.js +1258 -0
  468. package/dist/src/shapes/Text/Text.js.map +1 -0
  469. package/dist/src/shapes/Text/TextSVGExportMixin.js +339 -0
  470. package/dist/src/shapes/Text/TextSVGExportMixin.js.map +1 -0
  471. package/dist/src/shapes/Text/constants.js +94 -0
  472. package/dist/src/shapes/Text/constants.js.map +1 -0
  473. package/dist/src/shapes/Textbox.d.ts.map +1 -1
  474. package/dist/src/shapes/Textbox.js +910 -0
  475. package/dist/src/shapes/Textbox.js.map +1 -0
  476. package/dist/src/shapes/Textbox.min.mjs +1 -1
  477. package/dist/src/shapes/Textbox.min.mjs.map +1 -1
  478. package/dist/src/shapes/Textbox.mjs +4 -1
  479. package/dist/src/shapes/Textbox.mjs.map +1 -1
  480. package/dist/src/shapes/Triangle.js +47 -0
  481. package/dist/src/shapes/Triangle.js.map +1 -0
  482. package/dist/src/typedefs.js +2 -0
  483. package/dist/src/typedefs.js.map +1 -0
  484. package/dist/src/util/animation/AnimationBase.js +94 -0
  485. package/dist/src/util/animation/AnimationBase.js.map +1 -0
  486. package/dist/src/util/animation/AnimationFrameProvider.js +8 -0
  487. package/dist/src/util/animation/AnimationFrameProvider.js.map +1 -0
  488. package/dist/src/util/animation/AnimationRegistry.js +49 -0
  489. package/dist/src/util/animation/AnimationRegistry.js.map +1 -0
  490. package/dist/src/util/animation/ArrayAnimation.js +18 -0
  491. package/dist/src/util/animation/ArrayAnimation.js.map +1 -0
  492. package/dist/src/util/animation/ColorAnimation.js +43 -0
  493. package/dist/src/util/animation/ColorAnimation.js.map +1 -0
  494. package/dist/src/util/animation/ValueAnimation.js +18 -0
  495. package/dist/src/util/animation/ValueAnimation.js.map +1 -0
  496. package/dist/src/util/animation/animate.js +19 -0
  497. package/dist/src/util/animation/animate.js.map +1 -0
  498. package/dist/src/util/animation/easing.js +265 -0
  499. package/dist/src/util/animation/easing.js.map +1 -0
  500. package/dist/src/util/animation/index.js +3 -0
  501. package/dist/src/util/animation/index.js.map +1 -0
  502. package/dist/src/util/animation/types.js +2 -0
  503. package/dist/src/util/animation/types.js.map +1 -0
  504. package/dist/src/util/applyMixins.js +14 -0
  505. package/dist/src/util/applyMixins.js.map +1 -0
  506. package/dist/src/util/dom_event.js +21 -0
  507. package/dist/src/util/dom_event.js.map +1 -0
  508. package/dist/src/util/dom_misc.js +42 -0
  509. package/dist/src/util/dom_misc.js.map +1 -0
  510. package/dist/src/util/dom_style.js +19 -0
  511. package/dist/src/util/dom_style.js.map +1 -0
  512. package/dist/src/util/index.js +36 -0
  513. package/dist/src/util/index.js.map +1 -0
  514. package/dist/src/util/internals/applyCanvasTransform.js +15 -0
  515. package/dist/src/util/internals/applyCanvasTransform.js.map +1 -0
  516. package/dist/src/util/internals/cleanupSvgAttribute.js +8 -0
  517. package/dist/src/util/internals/cleanupSvgAttribute.js.map +1 -0
  518. package/dist/src/util/internals/cloneDeep.js +8 -0
  519. package/dist/src/util/internals/cloneDeep.js.map +1 -0
  520. package/dist/src/util/internals/cloneStyles.js +11 -0
  521. package/dist/src/util/internals/cloneStyles.js.map +1 -0
  522. package/dist/src/util/internals/console.js +14 -0
  523. package/dist/src/util/internals/console.js.map +1 -0
  524. package/dist/src/util/internals/dom_request.js +39 -0
  525. package/dist/src/util/internals/dom_request.js.map +1 -0
  526. package/dist/src/util/internals/findRight.js +9 -0
  527. package/dist/src/util/internals/findRight.js.map +1 -0
  528. package/dist/src/util/internals/getRandomInt.js +8 -0
  529. package/dist/src/util/internals/getRandomInt.js.map +1 -0
  530. package/dist/src/util/internals/ifNaN.js +10 -0
  531. package/dist/src/util/internals/ifNaN.js.map +1 -0
  532. package/dist/src/util/internals/removeFromArray.js +15 -0
  533. package/dist/src/util/internals/removeFromArray.js.map +1 -0
  534. package/dist/src/util/internals/uid.js +3 -0
  535. package/dist/src/util/internals/uid.js.map +1 -0
  536. package/dist/src/util/lang_string.js +93 -0
  537. package/dist/src/util/lang_string.js.map +1 -0
  538. package/dist/src/util/misc/boundingBoxFromPoints.js +26 -0
  539. package/dist/src/util/misc/boundingBoxFromPoints.js.map +1 -0
  540. package/dist/src/util/misc/capValue.js +2 -0
  541. package/dist/src/util/misc/capValue.js.map +1 -0
  542. package/dist/src/util/misc/cos.js +23 -0
  543. package/dist/src/util/misc/cos.js.map +1 -0
  544. package/dist/src/util/misc/dom.js +55 -0
  545. package/dist/src/util/misc/dom.js.map +1 -0
  546. package/dist/src/util/misc/findScaleTo.js +19 -0
  547. package/dist/src/util/misc/findScaleTo.js.map +1 -0
  548. package/dist/src/util/misc/groupSVGElements.js +15 -0
  549. package/dist/src/util/misc/groupSVGElements.js.map +1 -0
  550. package/dist/src/util/misc/isTransparent.js +23 -0
  551. package/dist/src/util/misc/isTransparent.js.map +1 -0
  552. package/dist/src/util/misc/matrix.js +238 -0
  553. package/dist/src/util/misc/matrix.js.map +1 -0
  554. package/dist/src/util/misc/mergeClipPaths.js +39 -0
  555. package/dist/src/util/misc/mergeClipPaths.js.map +1 -0
  556. package/dist/src/util/misc/objectEnlive.js +136 -0
  557. package/dist/src/util/misc/objectEnlive.js.map +1 -0
  558. package/dist/src/util/misc/objectTransforms.js +89 -0
  559. package/dist/src/util/misc/objectTransforms.js.map +1 -0
  560. package/dist/src/util/misc/pick.js +23 -0
  561. package/dist/src/util/misc/pick.js.map +1 -0
  562. package/dist/src/util/misc/planeChange.js +68 -0
  563. package/dist/src/util/misc/planeChange.js.map +1 -0
  564. package/dist/src/util/misc/projectStroke/StrokeLineCapProjections.js +105 -0
  565. package/dist/src/util/misc/projectStroke/StrokeLineCapProjections.js.map +1 -0
  566. package/dist/src/util/misc/projectStroke/StrokeLineJoinProjections.js +219 -0
  567. package/dist/src/util/misc/projectStroke/StrokeLineJoinProjections.js.map +1 -0
  568. package/dist/src/util/misc/projectStroke/StrokeProjectionsBase.js +42 -0
  569. package/dist/src/util/misc/projectStroke/StrokeProjectionsBase.js.map +1 -0
  570. package/dist/src/util/misc/projectStroke/index.js +61 -0
  571. package/dist/src/util/misc/projectStroke/index.js.map +1 -0
  572. package/dist/src/util/misc/projectStroke/types.js +2 -0
  573. package/dist/src/util/misc/projectStroke/types.js.map +1 -0
  574. package/dist/src/util/misc/radiansDegreesConversion.js +14 -0
  575. package/dist/src/util/misc/radiansDegreesConversion.js.map +1 -0
  576. package/dist/src/util/misc/resolveOrigin.js +17 -0
  577. package/dist/src/util/misc/resolveOrigin.js.map +1 -0
  578. package/dist/src/util/misc/rotatePoint.js +10 -0
  579. package/dist/src/util/misc/rotatePoint.js.map +1 -0
  580. package/dist/src/util/misc/sin.js +25 -0
  581. package/dist/src/util/misc/sin.js.map +1 -0
  582. package/dist/src/util/misc/svgExport.js +13 -0
  583. package/dist/src/util/misc/svgExport.js.map +1 -0
  584. package/dist/src/util/misc/svgParsing.js +129 -0
  585. package/dist/src/util/misc/svgParsing.js.map +1 -0
  586. package/dist/src/util/misc/textStyles.js +107 -0
  587. package/dist/src/util/misc/textStyles.js.map +1 -0
  588. package/dist/src/util/misc/toFixed.js +8 -0
  589. package/dist/src/util/misc/toFixed.js.map +1 -0
  590. package/dist/src/util/misc/vectors.js +77 -0
  591. package/dist/src/util/misc/vectors.js.map +1 -0
  592. package/dist/src/util/path/index.js +743 -0
  593. package/dist/src/util/path/index.js.map +1 -0
  594. package/dist/src/util/path/regex.js +33 -0
  595. package/dist/src/util/path/regex.js.map +1 -0
  596. package/dist/src/util/path/typechecks.js +67 -0
  597. package/dist/src/util/path/typechecks.js.map +1 -0
  598. package/dist/src/util/path/typedefs.js +2 -0
  599. package/dist/src/util/path/typedefs.js.map +1 -0
  600. package/dist/src/util/transform_matrix_removal.js +46 -0
  601. package/dist/src/util/transform_matrix_removal.js.map +1 -0
  602. package/dist/src/util/typeAssertions.js +21 -0
  603. package/dist/src/util/typeAssertions.js.map +1 -0
  604. package/dist-extensions/src/gradient/Gradient.d.ts.map +1 -1
  605. package/dist-extensions/src/shapes/Textbox.d.ts.map +1 -1
  606. package/package.json +1 -1
  607. package/src/gradient/Gradient.ts +5 -2
  608. package/src/shapes/Textbox.ts +4 -1
@@ -0,0 +1,1141 @@
1
+ import { dragHandler } from '../controls/drag';
2
+ import { getActionFromCorner } from '../controls/util';
3
+ import { Point } from '../Point';
4
+ import { FabricObject } from '../shapes/Object/FabricObject';
5
+ import { addTransformToObject, saveObjectTransform, } from '../util/misc/objectTransforms';
6
+ import { StaticCanvas } from './StaticCanvas';
7
+ import { isCollection } from '../Collection';
8
+ import { isTransparent } from '../util/misc/isTransparent';
9
+ import { degreesToRadians } from '../util/misc/radiansDegreesConversion';
10
+ import { getPointer, isTouchEvent } from '../util/dom_event';
11
+ import { pick } from '../util/misc/pick';
12
+ import { sendPointToPlane } from '../util/misc/planeChange';
13
+ import { cos, createCanvasElement, sin } from '../util';
14
+ import { CanvasDOMManager } from './DOMManagers/CanvasDOMManager';
15
+ import { BOTTOM, CENTER, LEFT, MODIFIED, RESIZING, RIGHT, ROTATE, SCALE, SCALE_X, SCALE_Y, SKEW_X, SKEW_Y, TOP, } from '../constants';
16
+ import { canvasDefaults } from './CanvasOptions';
17
+ import { Intersection } from '../Intersection';
18
+ import { isActiveSelection } from '../util/typeAssertions';
19
+ import { Group } from '../shapes/Group';
20
+ /**
21
+ * Canvas class
22
+ * @class Canvas
23
+ * @extends StaticCanvas
24
+ * @tutorial {@link http://fabricjs.com/fabric-intro-part-1#canvas}
25
+ *
26
+ * @fires object:modified at the end of a transform
27
+ * @fires object:rotating while an object is being rotated from the control
28
+ * @fires object:scaling while an object is being scaled by controls
29
+ * @fires object:moving while an object is being dragged
30
+ * @fires object:skewing while an object is being skewed from the controls
31
+ *
32
+ * @fires before:transform before a transform is is started
33
+ * @fires before:selection:cleared
34
+ * @fires selection:cleared
35
+ * @fires selection:updated
36
+ * @fires selection:created
37
+ *
38
+ * @fires path:created after a drawing operation ends and the path is added
39
+ * @fires mouse:down
40
+ * @fires mouse:move
41
+ * @fires mouse:up
42
+ * @fires mouse:down:before on mouse down, before the inner fabric logic runs
43
+ * @fires mouse:move:before on mouse move, before the inner fabric logic runs
44
+ * @fires mouse:up:before on mouse up, before the inner fabric logic runs
45
+ * @fires mouse:over
46
+ * @fires mouse:out
47
+ * @fires mouse:dblclick whenever a native dbl click event fires on the canvas.
48
+ *
49
+ * @fires dragover
50
+ * @fires dragenter
51
+ * @fires dragleave
52
+ * @fires drag:enter object drag enter
53
+ * @fires drag:leave object drag leave
54
+ * @fires drop:before before drop event. Prepare for the drop event (same native event).
55
+ * @fires drop
56
+ * @fires drop:after after drop event. Run logic on canvas after event has been accepted/declined (same native event).
57
+ * @example
58
+ * let a: fabric.Object, b: fabric.Object;
59
+ * let flag = false;
60
+ * canvas.add(a, b);
61
+ * a.on('drop:before', opt => {
62
+ * // we want a to accept the drop even though it's below b in the stack
63
+ * flag = this.canDrop(opt.e);
64
+ * });
65
+ * b.canDrop = function(e) {
66
+ * !flag && this.draggableTextDelegate.canDrop(e);
67
+ * }
68
+ * b.on('dragover', opt => b.set('fill', opt.dropTarget === b ? 'pink' : 'black'));
69
+ * a.on('drop', opt => {
70
+ * opt.e.defaultPrevented // drop occurred
71
+ * opt.didDrop // drop occurred on canvas
72
+ * opt.target // drop target
73
+ * opt.target !== a && a.set('text', 'I lost');
74
+ * });
75
+ * canvas.on('drop:after', opt => {
76
+ * // inform user who won
77
+ * if(!opt.e.defaultPrevented) {
78
+ * // no winners
79
+ * }
80
+ * else if(!opt.didDrop) {
81
+ * // my objects didn't win, some other lucky object
82
+ * }
83
+ * else {
84
+ * // we have a winner it's opt.target!!
85
+ * }
86
+ * })
87
+ *
88
+ * @fires after:render at the end of the render process, receives the context in the callback
89
+ * @fires before:render at start the render process, receives the context in the callback
90
+ *
91
+ * @fires contextmenu:before
92
+ * @fires contextmenu
93
+ * @example
94
+ * let handler;
95
+ * targets.forEach(target => {
96
+ * target.on('contextmenu:before', opt => {
97
+ * // decide which target should handle the event before canvas hijacks it
98
+ * if (someCaseHappens && opt.targets.includes(target)) {
99
+ * handler = target;
100
+ * }
101
+ * });
102
+ * target.on('contextmenu', opt => {
103
+ * // do something fantastic
104
+ * });
105
+ * });
106
+ * canvas.on('contextmenu', opt => {
107
+ * if (!handler) {
108
+ * // no one takes responsibility, it's always left to me
109
+ * // let's show them how it's done!
110
+ * }
111
+ * });
112
+ *
113
+ */
114
+ export class SelectableCanvas extends StaticCanvas {
115
+ /**
116
+ * Double-click the locked node. Currently only group nodes are supported.
117
+ * @type Group | null
118
+ * @default
119
+ */
120
+ isolatedObject;
121
+ /**
122
+ * Fixed search objects
123
+ * @type Boolean
124
+ * @default null
125
+ */
126
+ _fixedSearchTargets;
127
+ /**
128
+ * Keep track of the subTargets for Mouse Events, ordered bottom up from innermost nested subTarget
129
+ * @type FabricObject[]
130
+ */
131
+ targets = [];
132
+ /**
133
+ * hold the list of nested targets hovered
134
+ * @type FabricObject[]
135
+ * @private
136
+ */
137
+ _hoveredTargets = [];
138
+ /**
139
+ * hold the list of objects to render
140
+ * @type FabricObject[]
141
+ * @private
142
+ */
143
+ _objectsToRender;
144
+ /**
145
+ * hold a reference to a data structure that contains information
146
+ * on the current on going transform
147
+ * @type
148
+ * @private
149
+ */
150
+ _currentTransform = null;
151
+ /**
152
+ * hold a reference to a data structure used to track the selection
153
+ * box on canvas drag
154
+ * on the current on going transform
155
+ * x, y, deltaX and deltaY are in scene plane
156
+ * @type
157
+ * @private
158
+ */
159
+ _groupSelector = null;
160
+ /**
161
+ * internal flag used to understand if the context top requires a cleanup
162
+ * in case this is true, the contextTop will be cleared at the next render
163
+ * @type boolean
164
+ * @private
165
+ */
166
+ contextTopDirty = false;
167
+ static ownDefaults = canvasDefaults;
168
+ static getDefaults() {
169
+ return { ...super.getDefaults(), ...SelectableCanvas.ownDefaults };
170
+ }
171
+ get upperCanvasEl() {
172
+ return this.elements.upper?.el;
173
+ }
174
+ get contextTop() {
175
+ return this.elements.upper?.ctx;
176
+ }
177
+ get wrapperEl() {
178
+ return this.elements.container;
179
+ }
180
+ initElements(el) {
181
+ this.elements = new CanvasDOMManager(el, {
182
+ allowTouchScrolling: this.allowTouchScrolling,
183
+ containerClass: this.containerClass,
184
+ });
185
+ this._createCacheCanvas();
186
+ }
187
+ /**
188
+ * @private
189
+ * @param {FabricObject} obj Object that was added
190
+ */
191
+ _onObjectAdded(obj) {
192
+ this._objectsToRender = undefined;
193
+ super._onObjectAdded(obj);
194
+ }
195
+ /**
196
+ * @private
197
+ * @param {FabricObject} obj Object that was removed
198
+ */
199
+ _onObjectRemoved(obj) {
200
+ this._objectsToRender = undefined;
201
+ // removing active object should fire "selection:cleared" events
202
+ if (obj === this._activeObject) {
203
+ this.fire('before:selection:cleared', { deselected: [obj] });
204
+ this._discardActiveObject();
205
+ this.fire('selection:cleared', { deselected: [obj] });
206
+ obj.fire('deselected', {
207
+ target: obj,
208
+ });
209
+ }
210
+ if (obj === this._hoveredTarget) {
211
+ this._hoveredTarget = undefined;
212
+ this._hoveredTargets = [];
213
+ }
214
+ super._onObjectRemoved(obj);
215
+ }
216
+ _onStackOrderChanged() {
217
+ this._objectsToRender = undefined;
218
+ super._onStackOrderChanged();
219
+ }
220
+ /**
221
+ * Divides objects in two groups, one to render immediately
222
+ * and one to render as activeGroup.
223
+ * @return {Array} objects to render immediately and pushes the other in the activeGroup.
224
+ */
225
+ _chooseObjectsToRender() {
226
+ const activeObject = this._activeObject;
227
+ return !this.preserveObjectStacking && activeObject
228
+ ? this._objects
229
+ .filter((object) => !object.group && object !== activeObject)
230
+ .concat(activeObject)
231
+ : this._objects;
232
+ }
233
+ /**
234
+ * Renders both the top canvas and the secondary container canvas.
235
+ */
236
+ renderAll() {
237
+ this.cancelRequestedRender();
238
+ if (this.destroyed) {
239
+ return;
240
+ }
241
+ if (this.contextTopDirty && !this._groupSelector && !this.isDrawingMode) {
242
+ this.clearContext(this.contextTop);
243
+ this.contextTopDirty = false;
244
+ }
245
+ if (this.hasLostContext) {
246
+ this.renderTopLayer(this.contextTop);
247
+ this.hasLostContext = false;
248
+ }
249
+ !this._objectsToRender &&
250
+ (this._objectsToRender = this._chooseObjectsToRender());
251
+ this.renderCanvas(this.getContext(), this._objectsToRender);
252
+ }
253
+ /**
254
+ * text selection is rendered by the active text instance during the rendering cycle
255
+ */
256
+ renderTopLayer(ctx) {
257
+ ctx.save();
258
+ if (this.isDrawingMode && this._isCurrentlyDrawing) {
259
+ this.freeDrawingBrush && this.freeDrawingBrush._render();
260
+ this.contextTopDirty = true;
261
+ }
262
+ // we render the top context - last object
263
+ if (this.selection && this._groupSelector) {
264
+ this._drawSelection(ctx);
265
+ this.contextTopDirty = true;
266
+ }
267
+ ctx.restore();
268
+ }
269
+ /**
270
+ * Method to render only the top canvas.
271
+ * Also used to render the group selection box.
272
+ * Does not render text selection.
273
+ */
274
+ renderTop() {
275
+ const ctx = this.contextTop;
276
+ this.clearContext(ctx);
277
+ this.renderTopLayer(ctx);
278
+ // todo: how do i know if the after:render is for the top or normal contex?
279
+ this.fire('after:render', { ctx });
280
+ }
281
+ /**
282
+ * Set the canvas tolerance value for pixel taret find.
283
+ * Use only integer numbers.
284
+ * @private
285
+ */
286
+ setTargetFindTolerance(value) {
287
+ value = Math.round(value);
288
+ this.targetFindTolerance = value;
289
+ const retina = this.getRetinaScaling();
290
+ const size = Math.ceil((value * 2 + 1) * retina);
291
+ this.pixelFindCanvasEl.width = this.pixelFindCanvasEl.height = size;
292
+ this.pixelFindContext.scale(retina, retina);
293
+ }
294
+ /**
295
+ * Returns true if object is transparent at a certain location
296
+ * Clarification: this is `is target transparent at location X or are controls there`
297
+ * @TODO this seems dumb that we treat controls with transparency. we can find controls
298
+ * programmatically without painting them, the cache canvas optimization is always valid
299
+ * @param {FabricObject} target Object to check
300
+ * @param {Number} x Left coordinate in viewport space
301
+ * @param {Number} y Top coordinate in viewport space
302
+ * @return {Boolean}
303
+ */
304
+ isTargetTransparent(target, x, y) {
305
+ const tolerance = this.targetFindTolerance;
306
+ const ctx = this.pixelFindContext;
307
+ this.clearContext(ctx);
308
+ ctx.save();
309
+ ctx.translate(-x + tolerance, -y + tolerance);
310
+ ctx.transform(...this.viewportTransform);
311
+ const selectionBgc = target.selectionBackgroundColor;
312
+ target.selectionBackgroundColor = '';
313
+ target.render(ctx);
314
+ target.selectionBackgroundColor = selectionBgc;
315
+ ctx.restore();
316
+ // our canvas is square, and made around tolerance.
317
+ // so tolerance in this case also represent the center of the canvas.
318
+ const enhancedTolerance = Math.round(tolerance * this.getRetinaScaling());
319
+ return isTransparent(ctx, enhancedTolerance, enhancedTolerance, enhancedTolerance);
320
+ }
321
+ /**
322
+ * takes an event and determines if selection key has been pressed
323
+ * @private
324
+ * @param {TPointerEvent} e Event object
325
+ */
326
+ _isSelectionKeyPressed(e) {
327
+ const sKey = this.selectionKey;
328
+ if (!sKey) {
329
+ return false;
330
+ }
331
+ if (Array.isArray(sKey)) {
332
+ return !!sKey.find((key) => !!key && e[key] === true);
333
+ }
334
+ else {
335
+ return e[sKey];
336
+ }
337
+ }
338
+ /**
339
+ * @private
340
+ * @param {TPointerEvent} e Event object
341
+ * @param {FabricObject} target
342
+ */
343
+ _shouldClearSelection(e, target) {
344
+ const activeObjects = this.getActiveObjects(), activeObject = this._activeObject;
345
+ return !!(!target ||
346
+ (target &&
347
+ activeObject &&
348
+ activeObjects.length > 1 &&
349
+ activeObjects.indexOf(target) === -1 &&
350
+ activeObject !== target &&
351
+ !this._isSelectionKeyPressed(e)) ||
352
+ (target && !target.evented) ||
353
+ (target && !target.selectable && activeObject && activeObject !== target));
354
+ }
355
+ /**
356
+ * This method will take in consideration a modifier key pressed and the control we are
357
+ * about to drag, and try to guess the anchor point ( origin ) of the transormation.
358
+ * This should be really in the realm of controls, and we should remove specific code for legacy
359
+ * embedded actions.
360
+ * @TODO this probably deserve discussion/rediscovery and change/refactor
361
+ * @private
362
+ * @deprecated
363
+ * @param {FabricObject} target
364
+ * @param {string} action
365
+ * @param {boolean} altKey
366
+ * @returns {boolean} true if the transformation should be centered
367
+ */
368
+ _shouldCenterTransform(target, action, modifierKeyPressed) {
369
+ if (!target) {
370
+ return;
371
+ }
372
+ let centerTransform;
373
+ if (action === SCALE ||
374
+ action === SCALE_X ||
375
+ action === SCALE_Y ||
376
+ action === RESIZING) {
377
+ centerTransform = this.centeredScaling || target.centeredScaling;
378
+ }
379
+ else if (action === ROTATE) {
380
+ centerTransform = this.centeredRotation || target.centeredRotation;
381
+ }
382
+ return centerTransform ? !modifierKeyPressed : modifierKeyPressed;
383
+ }
384
+ /**
385
+ * Given the control clicked, determine the origin of the transform.
386
+ * This is bad because controls can totally have custom names
387
+ * should disappear before release 4.0
388
+ * @private
389
+ * @deprecated
390
+ */
391
+ _getOriginFromCorner(target, controlName) {
392
+ const origin = {
393
+ x: target.originX,
394
+ y: target.originY,
395
+ };
396
+ if (!controlName) {
397
+ return origin;
398
+ }
399
+ // is a left control ?
400
+ if (['ml', 'tl', 'bl'].includes(controlName)) {
401
+ origin.x = RIGHT;
402
+ // is a right control ?
403
+ }
404
+ else if (['mr', 'tr', 'br'].includes(controlName)) {
405
+ origin.x = LEFT;
406
+ }
407
+ // is a top control ?
408
+ if (['tl', 'mt', 'tr'].includes(controlName)) {
409
+ origin.y = BOTTOM;
410
+ // is a bottom control ?
411
+ }
412
+ else if (['bl', 'mb', 'br'].includes(controlName)) {
413
+ origin.y = TOP;
414
+ }
415
+ return origin;
416
+ }
417
+ /**
418
+ * @private
419
+ * @param {Event} e Event object
420
+ * @param {FabricObject} target
421
+ * @param {boolean} [alreadySelected] pass true to setup the active control
422
+ */
423
+ _setupCurrentTransform(e, target, alreadySelected) {
424
+ const pointer = target.group
425
+ ? // transform pointer to target's containing coordinate plane
426
+ sendPointToPlane(this.getScenePoint(e), undefined, target.group.calcTransformMatrix())
427
+ : this.getScenePoint(e);
428
+ const { key: corner = '', control } = target.getActiveControl() || {}, actionHandler = alreadySelected && control
429
+ ? control.getActionHandler(e, target, control)?.bind(control)
430
+ : dragHandler, action = getActionFromCorner(alreadySelected, corner, e, target), altKey = e[this.centeredKey], origin = this._shouldCenterTransform(target, action, altKey)
431
+ ? { x: CENTER, y: CENTER }
432
+ : this._getOriginFromCorner(target, corner),
433
+ /**
434
+ * relative to target's containing coordinate plane
435
+ * both agree on every point
436
+ **/
437
+ transform = {
438
+ target: target,
439
+ action,
440
+ actionHandler,
441
+ actionPerformed: false,
442
+ corner,
443
+ scaleX: target.scaleX,
444
+ scaleY: target.scaleY,
445
+ skewX: target.skewX,
446
+ skewY: target.skewY,
447
+ offsetX: pointer.x - target.left,
448
+ offsetY: pointer.y - target.top,
449
+ originX: origin.x,
450
+ originY: origin.y,
451
+ ex: pointer.x,
452
+ ey: pointer.y,
453
+ lastX: pointer.x,
454
+ lastY: pointer.y,
455
+ theta: degreesToRadians(target.angle),
456
+ width: target.width,
457
+ height: target.height,
458
+ shiftKey: e.shiftKey,
459
+ altKey,
460
+ original: {
461
+ ...saveObjectTransform(target),
462
+ originX: origin.x,
463
+ originY: origin.y,
464
+ },
465
+ };
466
+ this._currentTransform = transform;
467
+ this.fire('before:transform', {
468
+ e,
469
+ transform,
470
+ });
471
+ }
472
+ /**
473
+ * Set the cursor type of the canvas element
474
+ * @param {String} value Cursor type of the canvas element.
475
+ * @see http://www.w3.org/TR/css3-ui/#cursor
476
+ */
477
+ setCursor(value) {
478
+ this.upperCanvasEl.style.cursor = value;
479
+ }
480
+ /**
481
+ * @private
482
+ * @param {CanvasRenderingContext2D} ctx to draw the selection on
483
+ */
484
+ _drawSelection(ctx) {
485
+ const { x, y, deltaX, deltaY } = this._groupSelector, start = new Point(x, y).transform(this.viewportTransform), extent = new Point(x + deltaX, y + deltaY).transform(this.viewportTransform), strokeOffset = this.selectionLineWidth / 2;
486
+ let minX = Math.min(start.x, extent.x), minY = Math.min(start.y, extent.y), maxX = Math.max(start.x, extent.x), maxY = Math.max(start.y, extent.y);
487
+ if (this.selectionColor) {
488
+ ctx.fillStyle = this.selectionColor;
489
+ ctx.fillRect(minX, minY, maxX - minX, maxY - minY);
490
+ }
491
+ if (!this.selectionLineWidth || !this.selectionBorderColor) {
492
+ return;
493
+ }
494
+ ctx.lineWidth = this.selectionLineWidth;
495
+ ctx.strokeStyle = this.selectionBorderColor;
496
+ minX += strokeOffset;
497
+ minY += strokeOffset;
498
+ maxX -= strokeOffset;
499
+ maxY -= strokeOffset;
500
+ // selection border
501
+ // @TODO: is _setLineDash still necessary on modern canvas?
502
+ FabricObject.prototype._setLineDash.call(this, ctx, this.selectionDashArray);
503
+ ctx.strokeRect(minX, minY, maxX - minX, maxY - minY);
504
+ }
505
+ /**
506
+ * Double-click to lock the group
507
+ * @param e
508
+ * @returns
509
+ */
510
+ dblClickLock(e) {
511
+ if (this.dblClickIsolateObject) {
512
+ const pointer = this.getViewportPoint(e);
513
+ const objects = this.isolatedObject
514
+ ? this.isolatedObject.getObjects()
515
+ : this.getObjects();
516
+ const obj = this.searchPossibleTargets(objects, pointer);
517
+ if (obj) {
518
+ if (obj instanceof Group) {
519
+ // Let text in group can be edited after isolation
520
+ obj.interactive = true;
521
+ this.isolatedObject = obj;
522
+ this.discardActiveObject();
523
+ // The newly created group object has its child node coords initialized, otherwise it cannot be selected.
524
+ obj._objects.forEach((o) => {
525
+ o.setCoords();
526
+ });
527
+ }
528
+ else {
529
+ // Non-group objects do not handle locking, return false to continue the object's own double-click event
530
+ return false;
531
+ }
532
+ }
533
+ else {
534
+ // cancel isolation
535
+ this.isolatedObject = null;
536
+ this.discardActiveObject();
537
+ }
538
+ return true;
539
+ }
540
+ return false;
541
+ }
542
+ /**
543
+ * Manually set the search object
544
+ * @param objects
545
+ */
546
+ setFixedSearchTargets(objects) {
547
+ this._fixedSearchTargets = objects;
548
+ }
549
+ /**
550
+ * Returns the search object
551
+ * @returns
552
+ */
553
+ getSearchTargets() {
554
+ return (this._fixedSearchTargets ||
555
+ (this.isolatedObject ? this.isolatedObject._objects : this._objects));
556
+ }
557
+ /**
558
+ * Method that determines what object we are clicking on
559
+ * 11/09/2018 TODO: would be cool if findTarget could discern between being a full target
560
+ * or the outside part of the corner.
561
+ * @param {Event} e mouse event
562
+ * @return {FabricObject | null} the target found
563
+ */
564
+ findTarget(e) {
565
+ if (this.skipTargetFind) {
566
+ return undefined;
567
+ }
568
+ const pointer = this.getViewportPoint(e), activeObject = this._activeObject, aObjects = this.getActiveObjects();
569
+ this.targets = [];
570
+ // valid _fixedSearchTargets is null or _fixedSearchTargets includes activeObject
571
+ if (activeObject &&
572
+ aObjects.length >= 1 &&
573
+ (!this._fixedSearchTargets ||
574
+ this._fixedSearchTargets.includes(activeObject))) {
575
+ if (activeObject.findControl(pointer, isTouchEvent(e))) {
576
+ // if we hit the corner of the active object, let's return that.
577
+ return activeObject;
578
+ }
579
+ else if (aObjects.length > 1 &&
580
+ // check pointer is over active selection and possibly perform `subTargetCheck`
581
+ this.searchPossibleTargets([activeObject], pointer)) {
582
+ // active selection does not select sub targets like normal groups
583
+ return activeObject;
584
+ }
585
+ else if (activeObject === this.searchPossibleTargets([activeObject], pointer)) {
586
+ // active object is not an active selection
587
+ if (!this.preserveObjectStacking) {
588
+ return activeObject;
589
+ }
590
+ else {
591
+ const subTargets = this.targets;
592
+ this.targets = [];
593
+ const target = this.searchPossibleTargets(this.getSearchTargets(), pointer);
594
+ if (e[this.altSelectionKey] &&
595
+ target &&
596
+ target !== activeObject) {
597
+ // alt selection: select active object even though it is not the top most target
598
+ // restore targets
599
+ this.targets = subTargets;
600
+ return activeObject;
601
+ }
602
+ return target;
603
+ }
604
+ }
605
+ }
606
+ return this.searchPossibleTargets(this.getSearchTargets(), pointer);
607
+ }
608
+ /**
609
+ * Checks if the point is inside the object selection area including padding
610
+ * @param {FabricObject} obj Object to test against
611
+ * @param {Object} [pointer] point in scene coordinates
612
+ * @return {Boolean} true if point is contained within an area of given object
613
+ * @private
614
+ */
615
+ _pointIsInObjectSelectionArea(obj, point) {
616
+ // getCoords will already take care of group de-nesting
617
+ let coords = obj.getCoords();
618
+ const viewportZoom = this.getZoom();
619
+ const padding = obj.padding / viewportZoom;
620
+ if (padding) {
621
+ const [tl, tr, br, bl] = coords;
622
+ // what is the angle of the object?
623
+ // we could use getTotalAngle, but is way easier to look at it
624
+ // from how coords are oriented, since if something went wrong
625
+ // at least we are consistent.
626
+ const angleRadians = Math.atan2(tr.y - tl.y, tr.x - tl.x), cosP = cos(angleRadians) * padding, sinP = sin(angleRadians) * padding, cosPSinP = cosP + sinP, cosPMinusSinP = cosP - sinP;
627
+ coords = [
628
+ new Point(tl.x - cosPMinusSinP, tl.y - cosPSinP),
629
+ new Point(tr.x + cosPSinP, tr.y - cosPMinusSinP),
630
+ new Point(br.x + cosPMinusSinP, br.y + cosPSinP),
631
+ new Point(bl.x - cosPSinP, bl.y + cosPMinusSinP),
632
+ ];
633
+ // in case of padding we calculate the new coords on the fly.
634
+ // otherwise we have to maintain 2 sets of coordinates for everything.
635
+ // we can reiterate on storing them.
636
+ // if this is slow, for now the semplification is large and doesn't impact
637
+ // rendering.
638
+ // the idea behind this is that outside target check we don't need ot know
639
+ // where those coords are
640
+ }
641
+ return Intersection.isPointInPolygon(point, coords);
642
+ }
643
+ /**
644
+ * Checks point is inside the object selection condition. Either area with padding
645
+ * or over pixels if perPixelTargetFind is enabled
646
+ * @param {FabricObject} obj Object to test against
647
+ * @param {Object} [pointer] point from viewport.
648
+ * @return {Boolean} true if point is contained within an area of given object
649
+ * @private
650
+ */
651
+ _checkTarget(obj, pointer) {
652
+ if (obj &&
653
+ obj.visible &&
654
+ obj.evented &&
655
+ this._pointIsInObjectSelectionArea(obj, sendPointToPlane(pointer, undefined, this.viewportTransform))) {
656
+ if ((this.perPixelTargetFind || obj.perPixelTargetFind) &&
657
+ !obj.isEditing) {
658
+ if (!this.isTargetTransparent(obj, pointer.x, pointer.y)) {
659
+ return true;
660
+ }
661
+ }
662
+ else {
663
+ return true;
664
+ }
665
+ }
666
+ return false;
667
+ }
668
+ /**
669
+ * Internal Function used to search inside objects an object that contains pointer in bounding box or that contains pointerOnCanvas when painted
670
+ * @param {Array} [objects] objects array to look into
671
+ * @param {Object} [pointer] x,y object of point coordinates we want to check.
672
+ * @return {FabricObject} **top most object from given `objects`** that contains pointer
673
+ * @private
674
+ */
675
+ _searchPossibleTargets(objects, pointer) {
676
+ // Cache all targets where their bounding box contains point.
677
+ let i = objects.length;
678
+ // Do not check for currently grouped objects, since we check the parent group itself.
679
+ // until we call this function specifically to search inside the activeGroup
680
+ while (i--) {
681
+ const target = objects[i];
682
+ if (this._checkTarget(target, pointer)) {
683
+ // Double-clicking to lock a node before searching for its child nodes is not enabled
684
+ if (!this.dblClickIsolateObject &&
685
+ isCollection(target) &&
686
+ target.subTargetCheck) {
687
+ const subTarget = this._searchPossibleTargets(target._objects, pointer);
688
+ subTarget && this.targets.push(subTarget);
689
+ }
690
+ return target;
691
+ }
692
+ }
693
+ }
694
+ /**
695
+ * Function used to search inside objects an object that contains pointer in bounding box or that contains pointerOnCanvas when painted
696
+ * @see {@link _searchPossibleTargets}
697
+ * @param {FabricObject[]} [objects] objects array to look into
698
+ * @param {Point} [pointer] coordinates from viewport to check.
699
+ * @return {FabricObject} **top most object on screen** that contains pointer
700
+ */
701
+ searchPossibleTargets(objects, pointer) {
702
+ const target = this._searchPossibleTargets(objects, pointer);
703
+ // if we found something in this.targets, and the group is interactive, return the innermost subTarget
704
+ // that is still interactive
705
+ // TODO: reverify why interactive. the target should be returned always, but selected only
706
+ // if interactive.
707
+ if (target &&
708
+ isCollection(target) &&
709
+ target.interactive &&
710
+ this.targets[0]) {
711
+ /** targets[0] is the innermost nested target, but it could be inside non interactive groups and so not a selection target */
712
+ const targets = this.targets;
713
+ for (let i = targets.length - 1; i > 0; i--) {
714
+ const t = targets[i];
715
+ if (!(isCollection(t) && t.interactive)) {
716
+ // one of the subtargets was not interactive. that is the last subtarget we can return.
717
+ // we can't dig more deep;
718
+ return t;
719
+ }
720
+ }
721
+ return targets[0];
722
+ }
723
+ return target;
724
+ }
725
+ /**
726
+ * @returns point existing in the same plane as the {@link HTMLCanvasElement},
727
+ * `(0, 0)` being the top left corner of the {@link HTMLCanvasElement}.
728
+ * This means that changes to the {@link viewportTransform} do not change the values of the point
729
+ * and it remains unchanged from the viewer's perspective.
730
+ *
731
+ * @example
732
+ * const scenePoint = sendPointToPlane(
733
+ * this.getViewportPoint(e),
734
+ * undefined,
735
+ * canvas.viewportTransform
736
+ * );
737
+ *
738
+ */
739
+ getViewportPoint(e) {
740
+ if (this._pointer) {
741
+ return this._pointer;
742
+ }
743
+ return this.getPointer(e, true);
744
+ }
745
+ /**
746
+ * @returns point existing in the scene (the same plane as the plane {@link FabricObject#getCenterPoint} exists in).
747
+ * This means that changes to the {@link viewportTransform} do not change the values of the point,
748
+ * however, from the viewer's perspective, the point is changed.
749
+ *
750
+ * @example
751
+ * const viewportPoint = sendPointToPlane(
752
+ * this.getScenePoint(e),
753
+ * canvas.viewportTransform
754
+ * );
755
+ *
756
+ */
757
+ getScenePoint(e) {
758
+ if (this._absolutePointer) {
759
+ return this._absolutePointer;
760
+ }
761
+ return this.getPointer(e);
762
+ }
763
+ /**
764
+ * Returns pointer relative to canvas.
765
+ *
766
+ * @deprecated This method is deprecated since v6 to protect you from misuse.
767
+ * Use {@link getViewportPoint} or {@link getScenePoint} instead.
768
+ *
769
+ * @param {Event} e
770
+ * @param {Boolean} [fromViewport] whether to return the point from the viewport or in the scene
771
+ * @return {Point}
772
+ */
773
+ getPointer(e, fromViewport = false) {
774
+ const upperCanvasEl = this.upperCanvasEl, bounds = upperCanvasEl.getBoundingClientRect();
775
+ let pointer = getPointer(e), boundsWidth = bounds.width || 0, boundsHeight = bounds.height || 0;
776
+ if (!boundsWidth || !boundsHeight) {
777
+ if (TOP in bounds && BOTTOM in bounds) {
778
+ boundsHeight = Math.abs(bounds.top - bounds.bottom);
779
+ }
780
+ if (RIGHT in bounds && LEFT in bounds) {
781
+ boundsWidth = Math.abs(bounds.right - bounds.left);
782
+ }
783
+ }
784
+ this.calcOffset();
785
+ pointer.x = pointer.x - this._offset.left;
786
+ pointer.y = pointer.y - this._offset.top;
787
+ if (!fromViewport) {
788
+ pointer = sendPointToPlane(pointer, undefined, this.viewportTransform);
789
+ }
790
+ const retinaScaling = this.getRetinaScaling();
791
+ if (retinaScaling !== 1) {
792
+ pointer.x /= retinaScaling;
793
+ pointer.y /= retinaScaling;
794
+ }
795
+ // If bounds are not available (i.e. not visible), do not apply scale.
796
+ const cssScale = boundsWidth === 0 || boundsHeight === 0
797
+ ? new Point(1, 1)
798
+ : new Point(upperCanvasEl.width / boundsWidth, upperCanvasEl.height / boundsHeight);
799
+ return pointer.multiply(cssScale);
800
+ }
801
+ /**
802
+ * Internal use only
803
+ * @protected
804
+ */
805
+ _setDimensionsImpl(dimensions, options) {
806
+ // @ts-expect-error this method exists in the subclass - should be moved or declared as abstract
807
+ this._resetTransformEventData();
808
+ super._setDimensionsImpl(dimensions, options);
809
+ if (this._isCurrentlyDrawing) {
810
+ this.freeDrawingBrush &&
811
+ this.freeDrawingBrush._setBrushStyles(this.contextTop);
812
+ }
813
+ }
814
+ _createCacheCanvas() {
815
+ this.pixelFindCanvasEl = createCanvasElement();
816
+ this.pixelFindContext = this.pixelFindCanvasEl.getContext('2d', {
817
+ willReadFrequently: true,
818
+ });
819
+ this.setTargetFindTolerance(this.targetFindTolerance);
820
+ }
821
+ /**
822
+ * Returns context of top canvas where interactions are drawn
823
+ * @returns {CanvasRenderingContext2D}
824
+ */
825
+ getTopContext() {
826
+ return this.elements.upper.ctx;
827
+ }
828
+ /**
829
+ * Returns context of canvas where object selection is drawn
830
+ * @alias
831
+ * @return {CanvasRenderingContext2D}
832
+ */
833
+ getSelectionContext() {
834
+ return this.elements.upper.ctx;
835
+ }
836
+ /**
837
+ * Returns <canvas> element on which object selection is drawn
838
+ * @return {HTMLCanvasElement}
839
+ */
840
+ getSelectionElement() {
841
+ return this.elements.upper.el;
842
+ }
843
+ /**
844
+ * Returns currently active object
845
+ * @return {FabricObject | null} active object
846
+ */
847
+ getActiveObject() {
848
+ return this._activeObject;
849
+ }
850
+ /**
851
+ * Returns an array with the current selected objects
852
+ * @return {FabricObject[]} active objects array
853
+ */
854
+ getActiveObjects() {
855
+ const active = this._activeObject;
856
+ return isActiveSelection(active)
857
+ ? active.getObjects()
858
+ : active
859
+ ? [active]
860
+ : [];
861
+ }
862
+ /**
863
+ * @private
864
+ * Compares the old activeObject with the current one and fires correct events
865
+ * @param {FabricObject[]} oldObjects old activeObject
866
+ * @param {TPointerEvent} e mouse event triggering the selection events
867
+ */
868
+ _fireSelectionEvents(oldObjects, e) {
869
+ let somethingChanged = false, invalidate = false;
870
+ const objects = this.getActiveObjects(), added = [], removed = [];
871
+ oldObjects.forEach((target) => {
872
+ if (!objects.includes(target)) {
873
+ somethingChanged = true;
874
+ target.fire('deselected', {
875
+ e,
876
+ target,
877
+ });
878
+ removed.push(target);
879
+ }
880
+ });
881
+ objects.forEach((target) => {
882
+ if (!oldObjects.includes(target)) {
883
+ somethingChanged = true;
884
+ target.fire('selected', {
885
+ e,
886
+ target,
887
+ });
888
+ added.push(target);
889
+ }
890
+ });
891
+ if (oldObjects.length > 0 && objects.length > 0) {
892
+ invalidate = true;
893
+ somethingChanged &&
894
+ this.fire('selection:updated', {
895
+ e,
896
+ selected: added,
897
+ deselected: removed,
898
+ });
899
+ }
900
+ else if (objects.length > 0) {
901
+ invalidate = true;
902
+ this.fire('selection:created', {
903
+ e,
904
+ selected: added,
905
+ });
906
+ }
907
+ else if (oldObjects.length > 0) {
908
+ invalidate = true;
909
+ this.fire('selection:cleared', {
910
+ e,
911
+ deselected: removed,
912
+ });
913
+ }
914
+ invalidate && (this._objectsToRender = undefined);
915
+ }
916
+ /**
917
+ * Sets given object as the only active object on canvas
918
+ * @param {FabricObject} object Object to set as an active one
919
+ * @param {TPointerEvent} [e] Event (passed along when firing "object:selected")
920
+ * @return {Boolean} true if the object has been selected
921
+ */
922
+ setActiveObject(object, e) {
923
+ // we can't inline this, since _setActiveObject will change what getActiveObjects returns
924
+ const currentActives = this.getActiveObjects();
925
+ const selected = this._setActiveObject(object, e);
926
+ this._fireSelectionEvents(currentActives, e);
927
+ return selected;
928
+ }
929
+ /**
930
+ * This is supposed to be equivalent to setActiveObject but without firing
931
+ * any event. There is commitment to have this stay this way.
932
+ * This is the functional part of setActiveObject.
933
+ * @param {Object} object to set as active
934
+ * @param {Event} [e] Event (passed along when firing "object:selected")
935
+ * @return {Boolean} true if the object has been selected
936
+ */
937
+ _setActiveObject(object, e) {
938
+ const prevActiveObject = this._activeObject;
939
+ if (prevActiveObject === object) {
940
+ return false;
941
+ }
942
+ // after calling this._discardActiveObject, this,_activeObject could be undefined
943
+ if (!this._discardActiveObject(e, object) && this._activeObject) {
944
+ // refused to deselect
945
+ return false;
946
+ }
947
+ if (object.onSelect({ e })) {
948
+ return false;
949
+ }
950
+ this._activeObject = object;
951
+ if (isActiveSelection(object) && prevActiveObject !== object) {
952
+ object.set('canvas', this);
953
+ }
954
+ object.setCoords();
955
+ return true;
956
+ }
957
+ /**
958
+ * This is supposed to be equivalent to discardActiveObject but without firing
959
+ * any selection events ( can still fire object transformation events ). There is commitment to have this stay this way.
960
+ * This is the functional part of discardActiveObject.
961
+ * @param {Event} [e] Event (passed along when firing "object:deselected")
962
+ * @param {Object} object the next object to set as active, reason why we are discarding this
963
+ * @return {Boolean} true if the active object has been discarded
964
+ */
965
+ _discardActiveObject(e, object) {
966
+ const obj = this._activeObject;
967
+ if (obj) {
968
+ // onDeselect return TRUE to cancel selection;
969
+ if (obj.onDeselect({ e, object })) {
970
+ return false;
971
+ }
972
+ if (this._currentTransform && this._currentTransform.target === obj) {
973
+ this.endCurrentTransform(e);
974
+ }
975
+ if (isActiveSelection(obj) && obj === this._hoveredTarget) {
976
+ this._hoveredTarget = undefined;
977
+ }
978
+ this._activeObject = undefined;
979
+ return true;
980
+ }
981
+ return false;
982
+ }
983
+ /**
984
+ * Discards currently active object and fire events. If the function is called by fabric
985
+ * as a consequence of a mouse event, the event is passed as a parameter and
986
+ * sent to the fire function for the custom events. When used as a method the
987
+ * e param does not have any application.
988
+ * @param {event} e
989
+ * @return {Boolean} true if the active object has been discarded
990
+ */
991
+ discardActiveObject(e) {
992
+ const currentActives = this.getActiveObjects(), activeObject = this.getActiveObject();
993
+ if (currentActives.length) {
994
+ this.fire('before:selection:cleared', {
995
+ e,
996
+ deselected: [activeObject],
997
+ });
998
+ }
999
+ const discarded = this._discardActiveObject(e);
1000
+ this._fireSelectionEvents(currentActives, e);
1001
+ return discarded;
1002
+ }
1003
+ /**
1004
+ * End the current transform.
1005
+ * You don't usually need to call this method unless you are interrupting a user initiated transform
1006
+ * because of some other event ( a press of key combination, or something that block the user UX )
1007
+ * @param {Event} [e] send the mouse event that generate the finalize down, so it can be used in the event
1008
+ */
1009
+ endCurrentTransform(e) {
1010
+ const transform = this._currentTransform;
1011
+ this._finalizeCurrentTransform(e);
1012
+ if (transform && transform.target) {
1013
+ // this could probably go inside _finalizeCurrentTransform
1014
+ transform.target.isMoving = false;
1015
+ }
1016
+ this._currentTransform = null;
1017
+ }
1018
+ /**
1019
+ * @private
1020
+ * @param {Event} e send the mouse event that generate the finalize down, so it can be used in the event
1021
+ */
1022
+ _finalizeCurrentTransform(e) {
1023
+ const transform = this._currentTransform, target = transform.target, options = {
1024
+ e,
1025
+ target,
1026
+ transform,
1027
+ action: transform.action,
1028
+ };
1029
+ if (target._scaling) {
1030
+ target._scaling = false;
1031
+ }
1032
+ target.setCoords();
1033
+ if (transform.actionPerformed) {
1034
+ this.fire('object:modified', options);
1035
+ target.fire(MODIFIED, options);
1036
+ }
1037
+ }
1038
+ /**
1039
+ * Sets viewport transformation of this canvas instance
1040
+ * @param {Array} vpt a Canvas 2D API transform matrix
1041
+ */
1042
+ setViewportTransform(vpt) {
1043
+ super.setViewportTransform(vpt);
1044
+ const activeObject = this._activeObject;
1045
+ if (activeObject) {
1046
+ activeObject.setCoords();
1047
+ }
1048
+ }
1049
+ /**
1050
+ * @override clears active selection ref and interactive canvas elements and contexts
1051
+ */
1052
+ destroy() {
1053
+ // dispose of active selection
1054
+ const activeObject = this._activeObject;
1055
+ if (isActiveSelection(activeObject)) {
1056
+ activeObject.removeAll();
1057
+ activeObject.dispose();
1058
+ }
1059
+ delete this._activeObject;
1060
+ super.destroy();
1061
+ // free resources
1062
+ // pixel find canvas
1063
+ // @ts-expect-error disposing
1064
+ this.pixelFindContext = null;
1065
+ // @ts-expect-error disposing
1066
+ this.pixelFindCanvasEl = undefined;
1067
+ }
1068
+ /**
1069
+ * Clears all contexts (background, main, top) of an instance
1070
+ */
1071
+ clear() {
1072
+ // discard active object and fire events
1073
+ this.discardActiveObject();
1074
+ // make sure we clear the active object in case it refused to be discarded
1075
+ this._activeObject = undefined;
1076
+ this.clearContext(this.contextTop);
1077
+ super.clear();
1078
+ }
1079
+ /**
1080
+ * Draws objects' controls (borders/controls)
1081
+ * @param {CanvasRenderingContext2D} ctx Context to render controls on
1082
+ */
1083
+ drawControls(ctx) {
1084
+ const activeObject = this._activeObject;
1085
+ if (activeObject) {
1086
+ activeObject._renderControls(ctx);
1087
+ }
1088
+ }
1089
+ /**
1090
+ * @private
1091
+ */
1092
+ _toObject(instance, methodName, propertiesToInclude) {
1093
+ // If the object is part of the current selection group, it should
1094
+ // be transformed appropriately
1095
+ // i.e. it should be serialised as it would appear if the selection group
1096
+ // were to be destroyed.
1097
+ const originalProperties = this._realizeGroupTransformOnObject(instance), object = super._toObject(instance, methodName, propertiesToInclude);
1098
+ //Undo the damage we did by changing all of its properties
1099
+ instance.set(originalProperties);
1100
+ return object;
1101
+ }
1102
+ /**
1103
+ * Realizes an object's group transformation on it
1104
+ * @private
1105
+ * @param {FabricObject} [instance] the object to transform (gets mutated)
1106
+ * @returns the original values of instance which were changed
1107
+ */
1108
+ _realizeGroupTransformOnObject(instance) {
1109
+ const { group } = instance;
1110
+ if (group && isActiveSelection(group) && this._activeObject === group) {
1111
+ const layoutProps = [
1112
+ 'angle',
1113
+ 'flipX',
1114
+ 'flipY',
1115
+ LEFT,
1116
+ SCALE_X,
1117
+ SCALE_Y,
1118
+ SKEW_X,
1119
+ SKEW_Y,
1120
+ TOP,
1121
+ ];
1122
+ const originalValues = pick(instance, layoutProps);
1123
+ addTransformToObject(instance, group.calcOwnMatrix());
1124
+ return originalValues;
1125
+ }
1126
+ else {
1127
+ return {};
1128
+ }
1129
+ }
1130
+ /**
1131
+ * @private
1132
+ */
1133
+ _setSVGObject(markup, instance, reviver) {
1134
+ // If the object is in a selection group, simulate what would happen to that
1135
+ // object when the group is deselected
1136
+ const originalProperties = this._realizeGroupTransformOnObject(instance);
1137
+ super._setSVGObject(markup, instance, reviver);
1138
+ instance.set(originalProperties);
1139
+ }
1140
+ }
1141
+ //# sourceMappingURL=SelectableCanvas.js.map