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,1392 @@
1
+ import { cache } from '../../cache';
2
+ import { config } from '../../config';
3
+ import { ALIASING_LIMIT, CENTER, iMatrix, LEFT, SCALE_X, SCALE_Y, STROKE, FILL, TOP, VERSION, } from '../../constants';
4
+ import { Point } from '../../Point';
5
+ import { Shadow } from '../../Shadow';
6
+ import { classRegistry } from '../../ClassRegistry';
7
+ import { runningAnimations } from '../../util/animation/AnimationRegistry';
8
+ import { capValue } from '../../util/misc/capValue';
9
+ import { createCanvasElement, createCanvasElementFor, toDataURL, toBlob, } from '../../util/misc/dom';
10
+ import { invertTransform, qrDecompose } from '../../util/misc/matrix';
11
+ import { enlivenObjectEnlivables } from '../../util/misc/objectEnlive';
12
+ import { resetObjectTransform, saveObjectTransform, } from '../../util/misc/objectTransforms';
13
+ import { sendObjectToPlane } from '../../util/misc/planeChange';
14
+ import { pick, pickBy } from '../../util/misc/pick';
15
+ import { toFixed } from '../../util/misc/toFixed';
16
+ import { StaticCanvas } from '../../canvas/StaticCanvas';
17
+ import { isFiller, isSerializableFiller } from '../../util/typeAssertions';
18
+ import { cacheProperties, fabricObjectDefaultValues, stateProperties, } from './defaultValues';
19
+ import { getDevicePixelRatio, getEnv } from '../../env';
20
+ import { log } from '../../util/internals/console';
21
+ import { animate, animateColor } from '../../util/animation/animate';
22
+ import { ObjectGeometry } from './ObjectGeometry';
23
+ /**
24
+ * Root object class from which all 2d shape classes inherit from
25
+ * @tutorial {@link http://fabricjs.com/fabric-intro-part-1#objects}
26
+ *
27
+ * @fires added
28
+ * @fires removed
29
+ *
30
+ * @fires selected
31
+ * @fires deselected
32
+ *
33
+ * @fires rotating
34
+ * @fires scaling
35
+ * @fires moving
36
+ * @fires skewing
37
+ * @fires modified
38
+ *
39
+ * @fires mousedown
40
+ * @fires mouseup
41
+ * @fires mouseover
42
+ * @fires mouseout
43
+ * @fires mousewheel
44
+ * @fires mousedblclick
45
+ *
46
+ * @fires dragover
47
+ * @fires dragenter
48
+ * @fires dragleave
49
+ * @fires drop
50
+ */
51
+ export class FabricObject extends ObjectGeometry {
52
+ /**
53
+ * This list of properties is used to check if the state of an object is changed.
54
+ * This state change now is only used for children of groups to understand if a group
55
+ * needs its cache regenerated during a .set call
56
+ * @type Array
57
+ */
58
+ static stateProperties = stateProperties;
59
+ /**
60
+ * List of properties to consider when checking if cache needs refresh
61
+ * Those properties are checked by
62
+ * calls to Object.set(key, value). If the key is in this list, the object is marked as dirty
63
+ * and refreshed at the next render
64
+ * @type Array
65
+ */
66
+ static cacheProperties = cacheProperties;
67
+ /**
68
+ * Quick access for the _cacheCanvas rendering context
69
+ * This is part of the objectCaching feature
70
+ * since 1.7.0
71
+ * @type boolean
72
+ * @default undefined
73
+ * @private
74
+ */
75
+ _cacheContext = null;
76
+ static ownDefaults = fabricObjectDefaultValues;
77
+ static getDefaults() {
78
+ return FabricObject.ownDefaults;
79
+ }
80
+ /**
81
+ * The class type.
82
+ * This is used for serialization and deserialization purposes and internally it can be used
83
+ * to identify classes.
84
+ * When we transform a class in a plain JS object we need a way to recognize which class it was,
85
+ * and the type is the way we do that. It has no other purposes and you should not give one.
86
+ * Hard to reach on instances and please do not use to drive instance's logic (this.constructor.type).
87
+ * To idenfity a class use instanceof class ( instanceof Rect ).
88
+ * We do not do that in fabricJS code because we want to try to have code splitting possible.
89
+ */
90
+ static type = 'FabricObject';
91
+ /**
92
+ * Legacy identifier of the class. Prefer using utils like isType or instanceOf
93
+ * Will be removed in fabric 7 or 8.
94
+ * The setter exists to avoid type errors in old code and possibly current deserialization code.
95
+ * DO NOT build new code around this type value
96
+ * @TODO add sustainable warning message
97
+ * @type string
98
+ * @deprecated
99
+ */
100
+ get type() {
101
+ const name = this.constructor.type;
102
+ if (name === 'FabricObject') {
103
+ return 'object';
104
+ }
105
+ return name.toLowerCase();
106
+ }
107
+ set type(value) {
108
+ log('warn', 'Setting type has no effect', value);
109
+ }
110
+ /**
111
+ * Constructor
112
+ * @param {Object} [options] Options object
113
+ */
114
+ constructor(options) {
115
+ super();
116
+ Object.assign(this, FabricObject.ownDefaults);
117
+ this.setOptions(options);
118
+ }
119
+ /**
120
+ * Create a the canvas used to keep the cached copy of the object
121
+ * @private
122
+ */
123
+ _createCacheCanvas() {
124
+ this._cacheCanvas = createCanvasElement();
125
+ this._cacheContext = this._cacheCanvas.getContext('2d');
126
+ this._updateCacheCanvas();
127
+ // if canvas gets created, is empty, so dirty.
128
+ this.dirty = true;
129
+ }
130
+ /**
131
+ * Limit the cache dimensions so that X * Y do not cross config.perfLimitSizeTotal
132
+ * and each side do not cross fabric.cacheSideLimit
133
+ * those numbers are configurable so that you can get as much detail as you want
134
+ * making bargain with performances.
135
+ * @param {Object} dims
136
+ * @param {Object} dims.width width of canvas
137
+ * @param {Object} dims.height height of canvas
138
+ * @param {Object} dims.zoomX zoomX zoom value to unscale the canvas before drawing cache
139
+ * @param {Object} dims.zoomY zoomY zoom value to unscale the canvas before drawing cache
140
+ * @return {Object}.width width of canvas
141
+ * @return {Object}.height height of canvas
142
+ * @return {Object}.zoomX zoomX zoom value to unscale the canvas before drawing cache
143
+ * @return {Object}.zoomY zoomY zoom value to unscale the canvas before drawing cache
144
+ */
145
+ _limitCacheSize(dims) {
146
+ const width = dims.width, height = dims.height, max = config.maxCacheSideLimit, min = config.minCacheSideLimit;
147
+ if (width <= max &&
148
+ height <= max &&
149
+ width * height <= config.perfLimitSizeTotal) {
150
+ if (width < min) {
151
+ dims.width = min;
152
+ }
153
+ if (height < min) {
154
+ dims.height = min;
155
+ }
156
+ return dims;
157
+ }
158
+ const ar = width / height, [limX, limY] = cache.limitDimsByArea(ar), x = capValue(min, limX, max), y = capValue(min, limY, max);
159
+ if (width > x) {
160
+ dims.zoomX /= width / x;
161
+ dims.width = x;
162
+ dims.capped = true;
163
+ }
164
+ if (height > y) {
165
+ dims.zoomY /= height / y;
166
+ dims.height = y;
167
+ dims.capped = true;
168
+ }
169
+ return dims;
170
+ }
171
+ /**
172
+ * Return the dimension and the zoom level needed to create a cache canvas
173
+ * big enough to host the object to be cached.
174
+ * @private
175
+ * @return {Object}.x width of object to be cached
176
+ * @return {Object}.y height of object to be cached
177
+ * @return {Object}.width width of canvas
178
+ * @return {Object}.height height of canvas
179
+ * @return {Object}.zoomX zoomX zoom value to unscale the canvas before drawing cache
180
+ * @return {Object}.zoomY zoomY zoom value to unscale the canvas before drawing cache
181
+ */
182
+ _getCacheCanvasDimensions() {
183
+ const objectScale = this.getTotalObjectScaling(),
184
+ // calculate dimensions without skewing
185
+ dim = this._getTransformedDimensions({ skewX: 0, skewY: 0 }), neededX = (dim.x * objectScale.x) / this.scaleX, neededY = (dim.y * objectScale.y) / this.scaleY;
186
+ return {
187
+ // for sure this ALIASING_LIMIT is slightly creating problem
188
+ // in situation in which the cache canvas gets an upper limit
189
+ // also objectScale contains already scaleX and scaleY
190
+ width: Math.ceil(neededX + ALIASING_LIMIT),
191
+ height: Math.ceil(neededY + ALIASING_LIMIT),
192
+ zoomX: objectScale.x,
193
+ zoomY: objectScale.y,
194
+ x: neededX,
195
+ y: neededY,
196
+ };
197
+ }
198
+ /**
199
+ * Update width and height of the canvas for cache
200
+ * returns true or false if canvas needed resize.
201
+ * @private
202
+ * @return {Boolean} true if the canvas has been resized
203
+ */
204
+ _updateCacheCanvas() {
205
+ const canvas = this._cacheCanvas, context = this._cacheContext, { width, height, zoomX, zoomY, x, y } = this._limitCacheSize(this._getCacheCanvasDimensions()), dimensionsChanged = width !== canvas.width || height !== canvas.height, zoomChanged = this.zoomX !== zoomX || this.zoomY !== zoomY;
206
+ if (!canvas || !context) {
207
+ return false;
208
+ }
209
+ const shouldRedraw = dimensionsChanged || zoomChanged;
210
+ if (shouldRedraw) {
211
+ if (width !== canvas.width || height !== canvas.height) {
212
+ canvas.width = width;
213
+ canvas.height = height;
214
+ }
215
+ else {
216
+ context.setTransform(1, 0, 0, 1, 0, 0);
217
+ context.clearRect(0, 0, canvas.width, canvas.height);
218
+ }
219
+ const drawingWidth = x / 2;
220
+ const drawingHeight = y / 2;
221
+ this.cacheTranslationX =
222
+ Math.round(canvas.width / 2 - drawingWidth) + drawingWidth;
223
+ this.cacheTranslationY =
224
+ Math.round(canvas.height / 2 - drawingHeight) + drawingHeight;
225
+ context.translate(this.cacheTranslationX, this.cacheTranslationY);
226
+ context.scale(zoomX, zoomY);
227
+ this.zoomX = zoomX;
228
+ this.zoomY = zoomY;
229
+ return true;
230
+ }
231
+ return false;
232
+ }
233
+ /**
234
+ * Sets object's properties from options, for class constructor only.
235
+ * Needs to be overridden for different defaults.
236
+ * @protected
237
+ * @param {Object} [options] Options object
238
+ */
239
+ setOptions(options = {}) {
240
+ this._setOptions(options);
241
+ }
242
+ /**
243
+ * Transforms context when rendering an object
244
+ * @param {CanvasRenderingContext2D} ctx Context
245
+ */
246
+ transform(ctx) {
247
+ const needFullTransform = (this.group && !this.group._transformDone) ||
248
+ (this.group && this.canvas && ctx === this.canvas.contextTop);
249
+ const m = this.calcTransformMatrix(!needFullTransform);
250
+ ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
251
+ }
252
+ /**
253
+ * Return the object scale factor counting also the group scaling
254
+ * @return {Point}
255
+ */
256
+ getObjectScaling() {
257
+ // if the object is a top level one, on the canvas, we go for simple aritmetic
258
+ // otherwise the complex method with angles will return approximations and decimals
259
+ // and will likely kill the cache when not needed
260
+ // https://github.com/fabricjs/fabric.js/issues/7157
261
+ if (!this.group) {
262
+ return new Point(Math.abs(this.scaleX), Math.abs(this.scaleY));
263
+ }
264
+ // if we are inside a group total zoom calculation is complex, we defer to generic matrices
265
+ const options = qrDecompose(this.calcTransformMatrix());
266
+ return new Point(Math.abs(options.scaleX), Math.abs(options.scaleY));
267
+ }
268
+ /**
269
+ * Return the object scale factor counting also the group scaling, zoom and retina
270
+ * @return {Object} object with scaleX and scaleY properties
271
+ */
272
+ getTotalObjectScaling() {
273
+ const scale = this.getObjectScaling();
274
+ if (this.canvas) {
275
+ const zoom = this.canvas.getZoom();
276
+ const retina = this.getCanvasRetinaScaling();
277
+ return scale.scalarMultiply(zoom * retina);
278
+ }
279
+ return scale;
280
+ }
281
+ /**
282
+ * Return the object opacity counting also the group property
283
+ * @return {Number}
284
+ */
285
+ getObjectOpacity() {
286
+ let opacity = this.opacity;
287
+ if (this.group) {
288
+ opacity *= this.group.getObjectOpacity();
289
+ }
290
+ return opacity;
291
+ }
292
+ /**
293
+ * Makes sure the scale is valid and modifies it if necessary
294
+ * @todo: this is a control action issue, not a geometry one
295
+ * @private
296
+ * @param {Number} value, unconstrained
297
+ * @return {Number} constrained value;
298
+ */
299
+ _constrainScale(value) {
300
+ if (Math.abs(value) < this.minScaleLimit) {
301
+ if (value < 0) {
302
+ return -this.minScaleLimit;
303
+ }
304
+ else {
305
+ return this.minScaleLimit;
306
+ }
307
+ }
308
+ else if (value === 0) {
309
+ return 0.0001;
310
+ }
311
+ return value;
312
+ }
313
+ /**
314
+ * Handles setting values on the instance and handling internal side effects
315
+ * @protected
316
+ * @param {String} key
317
+ * @param {*} value
318
+ */
319
+ _set(key, value) {
320
+ if (key === SCALE_X || key === SCALE_Y) {
321
+ value = this._constrainScale(value);
322
+ }
323
+ if (key === SCALE_X && value < 0) {
324
+ this.flipX = !this.flipX;
325
+ value *= -1;
326
+ }
327
+ else if (key === 'scaleY' && value < 0) {
328
+ this.flipY = !this.flipY;
329
+ value *= -1;
330
+ // i don't like this automatic initialization here
331
+ }
332
+ else if (key === 'shadow' && value && !(value instanceof Shadow)) {
333
+ value = new Shadow(value);
334
+ }
335
+ const isChanged = this[key] !== value;
336
+ this[key] = value;
337
+ // invalidate caches
338
+ if (isChanged &&
339
+ this.constructor.cacheProperties.includes(key)) {
340
+ this.dirty = true;
341
+ }
342
+ // a dirty child makes the parent dirty.
343
+ // but a non dirty child does not make the parent not dirty.
344
+ // the parent could be dirty for some other reason.
345
+ this.parent &&
346
+ (this.dirty ||
347
+ (isChanged &&
348
+ this.constructor.stateProperties.includes(key))) &&
349
+ this.parent._set('dirty', true);
350
+ return this;
351
+ }
352
+ /*
353
+ * @private
354
+ * return if the object would be visible in rendering
355
+ * @memberOf FabricObject.prototype
356
+ * @return {Boolean}
357
+ */
358
+ isNotVisible() {
359
+ return (this.opacity === 0 ||
360
+ (!this.width && !this.height && this.strokeWidth === 0) ||
361
+ !this.visible);
362
+ }
363
+ /**
364
+ * Renders an object on a specified context
365
+ * @param {CanvasRenderingContext2D} ctx Context to render on
366
+ */
367
+ render(ctx) {
368
+ // do not render if width/height are zeros or object is not visible
369
+ if (this.isNotVisible()) {
370
+ return;
371
+ }
372
+ if (this.canvas &&
373
+ this.canvas.skipOffscreen &&
374
+ !this.group &&
375
+ !this.isOnScreen()) {
376
+ return;
377
+ }
378
+ ctx.save();
379
+ this._setupCompositeOperation(ctx);
380
+ this.drawSelectionBackground(ctx);
381
+ this.transform(ctx);
382
+ this._setOpacity(ctx);
383
+ this._setShadow(ctx);
384
+ if (this.shouldCache()) {
385
+ this.renderCache();
386
+ this.drawCacheOnCanvas(ctx);
387
+ }
388
+ else {
389
+ this._removeCacheCanvas();
390
+ this.drawObject(ctx, false, {});
391
+ this.dirty = false;
392
+ }
393
+ ctx.restore();
394
+ }
395
+ drawSelectionBackground(_ctx) {
396
+ /* no op */
397
+ }
398
+ renderCache(options) {
399
+ options = options || {};
400
+ if (!this._cacheCanvas || !this._cacheContext) {
401
+ this._createCacheCanvas();
402
+ }
403
+ if (this.isCacheDirty() && this._cacheContext) {
404
+ const { zoomX, zoomY, cacheTranslationX, cacheTranslationY } = this;
405
+ const { width, height } = this._cacheCanvas;
406
+ this.drawObject(this._cacheContext, options.forClipping, {
407
+ zoomX,
408
+ zoomY,
409
+ cacheTranslationX,
410
+ cacheTranslationY,
411
+ width,
412
+ height,
413
+ parentClipPaths: [],
414
+ });
415
+ this.dirty = false;
416
+ }
417
+ }
418
+ /**
419
+ * Remove cacheCanvas and its dimensions from the objects
420
+ */
421
+ _removeCacheCanvas() {
422
+ this._cacheCanvas = undefined;
423
+ this._cacheContext = null;
424
+ }
425
+ /**
426
+ * return true if the object will draw a stroke
427
+ * Does not consider text styles. This is just a shortcut used at rendering time
428
+ * We want it to be an approximation and be fast.
429
+ * wrote to avoid extra caching, it has to return true when stroke happens,
430
+ * can guess when it will not happen at 100% chance, does not matter if it misses
431
+ * some use case where the stroke is invisible.
432
+ * @since 3.0.0
433
+ * @returns Boolean
434
+ */
435
+ hasStroke() {
436
+ return (this.stroke && this.stroke !== 'transparent' && this.strokeWidth !== 0);
437
+ }
438
+ /**
439
+ * return true if the object will draw a fill
440
+ * Does not consider text styles. This is just a shortcut used at rendering time
441
+ * We want it to be an approximation and be fast.
442
+ * wrote to avoid extra caching, it has to return true when fill happens,
443
+ * can guess when it will not happen at 100% chance, does not matter if it misses
444
+ * some use case where the fill is invisible.
445
+ * @since 3.0.0
446
+ * @returns Boolean
447
+ */
448
+ hasFill() {
449
+ return this.fill && this.fill !== 'transparent';
450
+ }
451
+ /**
452
+ * When returns `true`, force the object to have its own cache, even if it is inside a group
453
+ * it may be needed when your object behave in a particular way on the cache and always needs
454
+ * its own isolated canvas to render correctly.
455
+ * Created to be overridden
456
+ * since 1.7.12
457
+ * @returns Boolean
458
+ */
459
+ needsItsOwnCache() {
460
+ // TODO re-evaluate this shadow condition
461
+ if (this.paintFirst === STROKE &&
462
+ this.hasFill() &&
463
+ this.hasStroke() &&
464
+ !!this.shadow) {
465
+ return true;
466
+ }
467
+ if (this.clipPath) {
468
+ return true;
469
+ }
470
+ return false;
471
+ }
472
+ /**
473
+ * Decide if the object should cache or not. Create its own cache level
474
+ * objectCaching is a global flag, wins over everything
475
+ * needsItsOwnCache should be used when the object drawing method requires
476
+ * a cache step.
477
+ * Generally you do not cache objects in groups because the group outside is cached.
478
+ * Read as: cache if is needed, or if the feature is enabled but we are not already caching.
479
+ * @return {Boolean}
480
+ */
481
+ shouldCache() {
482
+ this.ownCaching =
483
+ (this.objectCaching && (!this.parent || !this.parent.isOnACache())) ||
484
+ this.needsItsOwnCache();
485
+ return this.ownCaching;
486
+ }
487
+ /**
488
+ * Check if this object will cast a shadow with an offset.
489
+ * used by Group.shouldCache to know if child has a shadow recursively
490
+ * @return {Boolean}
491
+ * @deprecated
492
+ */
493
+ willDrawShadow() {
494
+ return (!!this.shadow && (this.shadow.offsetX !== 0 || this.shadow.offsetY !== 0));
495
+ }
496
+ /**
497
+ * Execute the drawing operation for an object clipPath
498
+ * @param {CanvasRenderingContext2D} ctx Context to render on
499
+ * @param {FabricObject} clipPath
500
+ */
501
+ drawClipPathOnCache(ctx, clipPath, canvasWithClipPath) {
502
+ ctx.save();
503
+ // DEBUG: uncomment this line, comment the following
504
+ // ctx.globalAlpha = 0.4
505
+ if (clipPath.inverted) {
506
+ ctx.globalCompositeOperation = 'destination-out';
507
+ }
508
+ else {
509
+ ctx.globalCompositeOperation = 'destination-in';
510
+ }
511
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
512
+ ctx.drawImage(canvasWithClipPath, 0, 0);
513
+ ctx.restore();
514
+ }
515
+ /**
516
+ * Execute the drawing operation for an object on a specified context
517
+ * @param {CanvasRenderingContext2D} ctx Context to render on
518
+ * @param {boolean} forClipping apply clipping styles
519
+ * @param {DrawContext} context additional context for rendering
520
+ */
521
+ drawObject(ctx, forClipping, context) {
522
+ const originalFill = this.fill, originalStroke = this.stroke;
523
+ if (forClipping) {
524
+ this.fill = 'black';
525
+ this.stroke = '';
526
+ this._setClippingProperties(ctx);
527
+ }
528
+ else {
529
+ this._renderBackground(ctx);
530
+ }
531
+ this._render(ctx);
532
+ this._drawClipPath(ctx, this.clipPath, context);
533
+ this.fill = originalFill;
534
+ this.stroke = originalStroke;
535
+ }
536
+ createClipPathLayer(clipPath, context) {
537
+ const canvas = createCanvasElementFor(context);
538
+ const ctx = canvas.getContext('2d');
539
+ ctx.translate(context.cacheTranslationX, context.cacheTranslationY);
540
+ ctx.scale(context.zoomX, context.zoomY);
541
+ clipPath._cacheCanvas = canvas;
542
+ context.parentClipPaths.forEach((prevClipPath) => {
543
+ prevClipPath.transform(ctx);
544
+ });
545
+ context.parentClipPaths.push(clipPath);
546
+ if (clipPath.absolutePositioned) {
547
+ const m = invertTransform(this.calcTransformMatrix());
548
+ ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
549
+ }
550
+ clipPath.transform(ctx);
551
+ clipPath.drawObject(ctx, true, context);
552
+ return canvas;
553
+ }
554
+ /**
555
+ * Prepare clipPath state and cache and draw it on instance's cache
556
+ * @param {CanvasRenderingContext2D} ctx
557
+ * @param {FabricObject} clipPath
558
+ */
559
+ _drawClipPath(ctx, clipPath, context) {
560
+ if (!clipPath) {
561
+ return;
562
+ }
563
+ // needed to setup _transformDone
564
+ // TODO find a better solution?
565
+ clipPath._transformDone = true;
566
+ const canvas = this.createClipPathLayer(clipPath, context);
567
+ this.drawClipPathOnCache(ctx, clipPath, canvas);
568
+ }
569
+ /**
570
+ * Paint the cached copy of the object on the target context.
571
+ * @param {CanvasRenderingContext2D} ctx Context to render on
572
+ */
573
+ drawCacheOnCanvas(ctx) {
574
+ ctx.scale(1 / this.zoomX, 1 / this.zoomY);
575
+ ctx.drawImage(this._cacheCanvas, -this.cacheTranslationX, -this.cacheTranslationY);
576
+ }
577
+ /**
578
+ * Check if cache is dirty and if is dirty clear the context.
579
+ * This check has a big side effect, it changes the underlying cache canvas if necessary.
580
+ * Do not call this method on your own to check if the cache is dirty, because if it is,
581
+ * it is also going to wipe the cache. This is badly designed and needs to be fixed.
582
+ * @param {Boolean} skipCanvas skip canvas checks because this object is painted
583
+ * on parent canvas.
584
+ */
585
+ isCacheDirty(skipCanvas = false) {
586
+ if (this.isNotVisible()) {
587
+ return false;
588
+ }
589
+ const canvas = this._cacheCanvas;
590
+ const ctx = this._cacheContext;
591
+ if (canvas && ctx && !skipCanvas && this._updateCacheCanvas()) {
592
+ // in this case the context is already cleared.
593
+ return true;
594
+ }
595
+ else {
596
+ if (this.dirty || (this.clipPath && this.clipPath.absolutePositioned)) {
597
+ if (canvas && ctx && !skipCanvas) {
598
+ ctx.save();
599
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
600
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
601
+ ctx.restore();
602
+ }
603
+ return true;
604
+ }
605
+ }
606
+ return false;
607
+ }
608
+ /**
609
+ * Draws a background for the object big as its untransformed dimensions
610
+ * @private
611
+ * @param {CanvasRenderingContext2D} ctx Context to render on
612
+ */
613
+ _renderBackground(ctx) {
614
+ if (!this.backgroundColor) {
615
+ return;
616
+ }
617
+ const dim = this._getNonTransformedDimensions();
618
+ ctx.fillStyle = this.backgroundColor;
619
+ ctx.fillRect(-dim.x / 2, -dim.y / 2, dim.x, dim.y);
620
+ // if there is background color no other shadows
621
+ // should be casted
622
+ this._removeShadow(ctx);
623
+ }
624
+ /**
625
+ * @private
626
+ * @param {CanvasRenderingContext2D} ctx Context to render on
627
+ */
628
+ _setOpacity(ctx) {
629
+ if (this.group && !this.group._transformDone) {
630
+ ctx.globalAlpha = this.getObjectOpacity();
631
+ }
632
+ else {
633
+ ctx.globalAlpha *= this.opacity;
634
+ }
635
+ }
636
+ _setStrokeStyles(ctx, decl) {
637
+ const stroke = decl.stroke;
638
+ if (stroke) {
639
+ ctx.lineWidth = decl.strokeWidth;
640
+ ctx.lineCap = decl.strokeLineCap;
641
+ ctx.lineDashOffset = decl.strokeDashOffset;
642
+ ctx.lineJoin = decl.strokeLineJoin;
643
+ ctx.miterLimit = decl.strokeMiterLimit;
644
+ if (isFiller(stroke)) {
645
+ if (stroke.gradientUnits === 'percentage' ||
646
+ stroke.gradientTransform ||
647
+ stroke.patternTransform) {
648
+ // need to transform gradient in a pattern.
649
+ // this is a slow process. If you are hitting this codepath, and the object
650
+ // is not using caching, you should consider switching it on.
651
+ // we need a canvas as big as the current object caching canvas.
652
+ this._applyPatternForTransformedGradient(ctx, stroke);
653
+ }
654
+ else {
655
+ // is a simple gradient or pattern
656
+ ctx.strokeStyle = stroke.toLive(ctx);
657
+ this._applyPatternGradientTransform(ctx, stroke);
658
+ }
659
+ }
660
+ else {
661
+ // is a color
662
+ ctx.strokeStyle = decl.stroke;
663
+ }
664
+ }
665
+ }
666
+ _setFillStyles(ctx, { fill }) {
667
+ if (fill) {
668
+ if (isFiller(fill)) {
669
+ ctx.fillStyle = fill.toLive(ctx);
670
+ this._applyPatternGradientTransform(ctx, fill);
671
+ }
672
+ else {
673
+ ctx.fillStyle = fill;
674
+ }
675
+ }
676
+ }
677
+ _setClippingProperties(ctx) {
678
+ ctx.globalAlpha = 1;
679
+ ctx.strokeStyle = 'transparent';
680
+ ctx.fillStyle = '#000000';
681
+ }
682
+ /**
683
+ * @private
684
+ * Sets line dash
685
+ * @param {CanvasRenderingContext2D} ctx Context to set the dash line on
686
+ * @param {Array} dashArray array representing dashes
687
+ */
688
+ _setLineDash(ctx, dashArray) {
689
+ if (!dashArray || dashArray.length === 0) {
690
+ return;
691
+ }
692
+ ctx.setLineDash(dashArray);
693
+ }
694
+ /**
695
+ * @private
696
+ * @param {CanvasRenderingContext2D} ctx Context to render on
697
+ */
698
+ _setShadow(ctx) {
699
+ if (!this.shadow) {
700
+ return;
701
+ }
702
+ const shadow = this.shadow, canvas = this.canvas, retinaScaling = this.getCanvasRetinaScaling(), [sx, , , sy] = canvas?.viewportTransform || iMatrix, multX = sx * retinaScaling, multY = sy * retinaScaling, scaling = shadow.nonScaling ? new Point(1, 1) : this.getObjectScaling();
703
+ ctx.shadowColor = shadow.color;
704
+ ctx.shadowBlur =
705
+ (shadow.blur *
706
+ config.browserShadowBlurConstant *
707
+ (multX + multY) *
708
+ (scaling.x + scaling.y)) /
709
+ 4;
710
+ ctx.shadowOffsetX = shadow.offsetX * multX * scaling.x;
711
+ ctx.shadowOffsetY = shadow.offsetY * multY * scaling.y;
712
+ }
713
+ /**
714
+ * @private
715
+ * @param {CanvasRenderingContext2D} ctx Context to render on
716
+ */
717
+ _removeShadow(ctx) {
718
+ if (!this.shadow) {
719
+ return;
720
+ }
721
+ ctx.shadowColor = '';
722
+ ctx.shadowBlur = ctx.shadowOffsetX = ctx.shadowOffsetY = 0;
723
+ }
724
+ /**
725
+ * @private
726
+ * @param {CanvasRenderingContext2D} ctx Context to render on
727
+ * @param {TFiller} filler {@link Pattern} or {@link Gradient}
728
+ */
729
+ _applyPatternGradientTransform(ctx, filler) {
730
+ if (!isFiller(filler)) {
731
+ return { offsetX: 0, offsetY: 0 };
732
+ }
733
+ const t = filler.gradientTransform ||
734
+ filler.patternTransform;
735
+ const offsetX = -this.width / 2 + filler.offsetX || 0, offsetY = -this.height / 2 + filler.offsetY || 0;
736
+ if (filler.gradientUnits === 'percentage') {
737
+ ctx.transform(this.width, 0, 0, this.height, offsetX, offsetY);
738
+ }
739
+ else {
740
+ ctx.transform(1, 0, 0, 1, offsetX, offsetY);
741
+ }
742
+ if (t) {
743
+ ctx.transform(t[0], t[1], t[2], t[3], t[4], t[5]);
744
+ }
745
+ return { offsetX: offsetX, offsetY: offsetY };
746
+ }
747
+ /**
748
+ * @private
749
+ * @param {CanvasRenderingContext2D} ctx Context to render on
750
+ */
751
+ _renderPaintInOrder(ctx) {
752
+ if (this.paintFirst === STROKE) {
753
+ this._renderStroke(ctx);
754
+ this._renderFill(ctx);
755
+ }
756
+ else {
757
+ this._renderFill(ctx);
758
+ this._renderStroke(ctx);
759
+ }
760
+ }
761
+ /**
762
+ * @private
763
+ * function that actually render something on the context.
764
+ * empty here to allow Obects to work on tests to benchmark fabric functionalites
765
+ * not related to rendering
766
+ * @param {CanvasRenderingContext2D} _ctx Context to render on
767
+ */
768
+ _render(_ctx) {
769
+ // placeholder to be overridden
770
+ }
771
+ /**
772
+ * @private
773
+ * @param {CanvasRenderingContext2D} ctx Context to render on
774
+ */
775
+ _renderFill(ctx) {
776
+ if (!this.fill) {
777
+ return;
778
+ }
779
+ ctx.save();
780
+ this._setFillStyles(ctx, this);
781
+ if (this.fillRule === 'evenodd') {
782
+ ctx.fill('evenodd');
783
+ }
784
+ else {
785
+ ctx.fill();
786
+ }
787
+ ctx.restore();
788
+ }
789
+ /**
790
+ * @private
791
+ * @param {CanvasRenderingContext2D} ctx Context to render on
792
+ */
793
+ _renderStroke(ctx) {
794
+ if (!this.stroke || this.strokeWidth === 0) {
795
+ return;
796
+ }
797
+ if (this.shadow && !this.shadow.affectStroke) {
798
+ this._removeShadow(ctx);
799
+ }
800
+ ctx.save();
801
+ if (this.strokeUniform) {
802
+ const scaling = this.getObjectScaling();
803
+ ctx.scale(1 / scaling.x, 1 / scaling.y);
804
+ }
805
+ this._setLineDash(ctx, this.strokeDashArray);
806
+ this._setStrokeStyles(ctx, this);
807
+ ctx.stroke();
808
+ ctx.restore();
809
+ }
810
+ /**
811
+ * This function try to patch the missing gradientTransform on canvas gradients.
812
+ * transforming a context to transform the gradient, is going to transform the stroke too.
813
+ * we want to transform the gradient but not the stroke operation, so we create
814
+ * a transformed gradient on a pattern and then we use the pattern instead of the gradient.
815
+ * this method has drawbacks: is slow, is in low resolution, needs a patch for when the size
816
+ * is limited.
817
+ * @private
818
+ * @param {CanvasRenderingContext2D} ctx Context to render on
819
+ * @param {Gradient} filler
820
+ */
821
+ _applyPatternForTransformedGradient(ctx, filler) {
822
+ const dims = this._limitCacheSize(this._getCacheCanvasDimensions()), retinaScaling = this.getCanvasRetinaScaling(), width = dims.x / this.scaleX / retinaScaling, height = dims.y / this.scaleY / retinaScaling, pCanvas = createCanvasElementFor({
823
+ // in case width and height are less than 1px, we have to round up.
824
+ // since the pattern is no-repeat, this is fine
825
+ width: Math.ceil(width),
826
+ height: Math.ceil(height),
827
+ });
828
+ const pCtx = pCanvas.getContext('2d');
829
+ if (!pCtx) {
830
+ return;
831
+ }
832
+ pCtx.beginPath();
833
+ pCtx.moveTo(0, 0);
834
+ pCtx.lineTo(width, 0);
835
+ pCtx.lineTo(width, height);
836
+ pCtx.lineTo(0, height);
837
+ pCtx.closePath();
838
+ pCtx.translate(width / 2, height / 2);
839
+ pCtx.scale(dims.zoomX / this.scaleX / retinaScaling, dims.zoomY / this.scaleY / retinaScaling);
840
+ this._applyPatternGradientTransform(pCtx, filler);
841
+ pCtx.fillStyle = filler.toLive(ctx);
842
+ pCtx.fill();
843
+ ctx.translate(-this.width / 2 - this.strokeWidth / 2, -this.height / 2 - this.strokeWidth / 2);
844
+ ctx.scale((retinaScaling * this.scaleX) / dims.zoomX, (retinaScaling * this.scaleY) / dims.zoomY);
845
+ ctx.strokeStyle = pCtx.createPattern(pCanvas, 'no-repeat') ?? '';
846
+ }
847
+ /**
848
+ * This function is an helper for svg import. it returns the center of the object in the svg
849
+ * untransformed coordinates
850
+ * @private
851
+ * @return {Point} center point from element coordinates
852
+ */
853
+ _findCenterFromElement() {
854
+ return new Point(this.left + this.width / 2, this.top + this.height / 2);
855
+ }
856
+ /**
857
+ * Clones an instance.
858
+ * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
859
+ * @returns {Promise<FabricObject>}
860
+ */
861
+ clone(propertiesToInclude) {
862
+ const objectForm = this.toObject(propertiesToInclude);
863
+ return this.constructor.fromObject(objectForm);
864
+ }
865
+ /**
866
+ * Creates an instance of Image out of an object
867
+ * makes use of toCanvasElement.
868
+ * Once this method was based on toDataUrl and loadImage, so it also had a quality
869
+ * and format option. toCanvasElement is faster and produce no loss of quality.
870
+ * If you need to get a real Jpeg or Png from an object, using toDataURL is the right way to do it.
871
+ * toCanvasElement and then toBlob from the obtained canvas is also a good option.
872
+ * @todo fix the export type, it could not be Image but the type that getClass return for 'image'.
873
+ * @param {ObjectToCanvasElementOptions} [options] for clone as image, passed to toDataURL
874
+ * @param {Number} [options.multiplier=1] Multiplier to scale by
875
+ * @param {Number} [options.left] Cropping left offset. Introduced in v1.2.14
876
+ * @param {Number} [options.top] Cropping top offset. Introduced in v1.2.14
877
+ * @param {Number} [options.width] Cropping width. Introduced in v1.2.14
878
+ * @param {Number} [options.height] Cropping height. Introduced in v1.2.14
879
+ * @param {Boolean} [options.enableRetinaScaling] Enable retina scaling for clone image. Introduce in 1.6.4
880
+ * @param {Boolean} [options.withoutTransform] Remove current object transform ( no scale , no angle, no flip, no skew ). Introduced in 2.3.4
881
+ * @param {Boolean} [options.withoutShadow] Remove current object shadow. Introduced in 2.4.2
882
+ * @return {FabricImage} Object cloned as image.
883
+ */
884
+ cloneAsImage(options) {
885
+ const canvasEl = this.toCanvasElement(options);
886
+ // TODO: how to import Image w/o an import cycle?
887
+ const ImageClass = classRegistry.getClass('image');
888
+ return new ImageClass(canvasEl);
889
+ }
890
+ /**
891
+ * Converts an object into a HTMLCanvas element
892
+ * @param {ObjectToCanvasElementOptions} options Options object
893
+ * @param {Number} [options.multiplier=1] Multiplier to scale by
894
+ * @param {Number} [options.left] Cropping left offset. Introduced in v1.2.14
895
+ * @param {Number} [options.top] Cropping top offset. Introduced in v1.2.14
896
+ * @param {Number} [options.width] Cropping width. Introduced in v1.2.14
897
+ * @param {Number} [options.height] Cropping height. Introduced in v1.2.14
898
+ * @param {Boolean} [options.enableRetinaScaling] Enable retina scaling for clone image. Introduce in 1.6.4
899
+ * @param {Boolean} [options.withoutTransform] Remove current object transform ( no scale , no angle, no flip, no skew ). Introduced in 2.3.4
900
+ * @param {Boolean} [options.withoutShadow] Remove current object shadow. Introduced in 2.4.2
901
+ * @param {Boolean} [options.viewportTransform] Account for canvas viewport transform
902
+ * @param {(el?: HTMLCanvasElement) => StaticCanvas} [options.canvasProvider] Create the output canvas
903
+ * @return {HTMLCanvasElement} Returns DOM element <canvas> with the FabricObject
904
+ */
905
+ toCanvasElement(options = {}) {
906
+ const origParams = saveObjectTransform(this), originalGroup = this.group, originalShadow = this.shadow, abs = Math.abs, retinaScaling = options.enableRetinaScaling ? getDevicePixelRatio() : 1, multiplier = (options.multiplier || 1) * retinaScaling, canvasProvider = options.canvasProvider ||
907
+ ((el) => new StaticCanvas(el, {
908
+ enableRetinaScaling: false,
909
+ renderOnAddRemove: false,
910
+ skipOffscreen: false,
911
+ }));
912
+ delete this.group;
913
+ if (options.withoutTransform) {
914
+ resetObjectTransform(this);
915
+ }
916
+ if (options.withoutShadow) {
917
+ this.shadow = null;
918
+ }
919
+ if (options.viewportTransform) {
920
+ sendObjectToPlane(this, this.getViewportTransform());
921
+ }
922
+ this.setCoords();
923
+ const el = createCanvasElement(), boundingRect = this.getBoundingRect(), shadow = this.shadow, shadowOffset = new Point();
924
+ if (shadow) {
925
+ const shadowBlur = shadow.blur;
926
+ const scaling = shadow.nonScaling
927
+ ? new Point(1, 1)
928
+ : this.getObjectScaling();
929
+ // consider non scaling shadow.
930
+ shadowOffset.x =
931
+ 2 * Math.round(abs(shadow.offsetX) + shadowBlur) * abs(scaling.x);
932
+ shadowOffset.y =
933
+ 2 * Math.round(abs(shadow.offsetY) + shadowBlur) * abs(scaling.y);
934
+ }
935
+ const width = boundingRect.width + shadowOffset.x, height = boundingRect.height + shadowOffset.y;
936
+ // if the current width/height is not an integer
937
+ // we need to make it so.
938
+ el.width = Math.ceil(width);
939
+ el.height = Math.ceil(height);
940
+ const canvas = canvasProvider(el);
941
+ if (options.format === 'jpeg') {
942
+ canvas.backgroundColor = '#fff';
943
+ }
944
+ this.setPositionByOrigin(new Point(canvas.width / 2, canvas.height / 2), CENTER, CENTER);
945
+ const originalCanvas = this.canvas;
946
+ // static canvas and canvas have both an array of InteractiveObjects
947
+ // @ts-expect-error this needs to be fixed somehow, or ignored globally
948
+ canvas._objects = [this];
949
+ this.set('canvas', canvas);
950
+ this.setCoords();
951
+ const canvasEl = canvas.toCanvasElement(multiplier || 1, options);
952
+ this.set('canvas', originalCanvas);
953
+ this.shadow = originalShadow;
954
+ if (originalGroup) {
955
+ this.group = originalGroup;
956
+ }
957
+ this.set(origParams);
958
+ this.setCoords();
959
+ // canvas.dispose will call image.dispose that will nullify the elements
960
+ // since this canvas is a simple element for the process, we remove references
961
+ // to objects in this way in order to avoid object trashing.
962
+ canvas._objects = [];
963
+ // since render has settled it is safe to destroy canvas
964
+ canvas.destroy();
965
+ return canvasEl;
966
+ }
967
+ /**
968
+ * Converts an object into a data-url-like string
969
+ * @param {Object} options Options object
970
+ * @param {String} [options.format=png] The format of the output image. Either "jpeg" or "png"
971
+ * @param {Number} [options.quality=1] Quality level (0..1). Only used for jpeg.
972
+ * @param {Number} [options.multiplier=1] Multiplier to scale by
973
+ * @param {Number} [options.left] Cropping left offset. Introduced in v1.2.14
974
+ * @param {Number} [options.top] Cropping top offset. Introduced in v1.2.14
975
+ * @param {Number} [options.width] Cropping width. Introduced in v1.2.14
976
+ * @param {Number} [options.height] Cropping height. Introduced in v1.2.14
977
+ * @param {Boolean} [options.enableRetinaScaling] Enable retina scaling for clone image. Introduce in 1.6.4
978
+ * @param {Boolean} [options.withoutTransform] Remove current object transform ( no scale , no angle, no flip, no skew ). Introduced in 2.3.4
979
+ * @param {Boolean} [options.withoutShadow] Remove current object shadow. Introduced in 2.4.2
980
+ * @return {String} Returns a data: URL containing a representation of the object in the format specified by options.format
981
+ */
982
+ toDataURL(options = {}) {
983
+ return toDataURL(this.toCanvasElement(options), options.format || 'png', options.quality || 1);
984
+ }
985
+ toBlob(options = {}) {
986
+ return toBlob(this.toCanvasElement(options), options.format || 'png', options.quality || 1);
987
+ }
988
+ /**
989
+ * Returns true if any of the specified types is identical to the type of an instance
990
+ * @param {String} type Type to check against
991
+ * @return {Boolean}
992
+ */
993
+ isType(...types) {
994
+ return (types.includes(this.constructor.type) ||
995
+ types.includes(this.type));
996
+ }
997
+ /**
998
+ * Returns complexity of an instance
999
+ * @return {Number} complexity of this instance (is 1 unless subclassed)
1000
+ */
1001
+ complexity() {
1002
+ return 1;
1003
+ }
1004
+ /**
1005
+ * Returns a JSON representation of an instance
1006
+ * @return {Object} JSON
1007
+ */
1008
+ toJSON() {
1009
+ // delegate, not alias
1010
+ return this.toObject();
1011
+ }
1012
+ /**
1013
+ * Sets "angle" of an instance with centered rotation
1014
+ * @param {TDegree} angle Angle value (in degrees)
1015
+ */
1016
+ rotate(angle) {
1017
+ const { centeredRotation, originX, originY } = this;
1018
+ if (centeredRotation) {
1019
+ const { x, y } = this.getRelativeCenterPoint();
1020
+ this.originX = CENTER;
1021
+ this.originY = CENTER;
1022
+ this.left = x;
1023
+ this.top = y;
1024
+ }
1025
+ this.set('angle', angle);
1026
+ if (centeredRotation) {
1027
+ const { x, y } = this.translateToOriginPoint(this.getRelativeCenterPoint(), originX, originY);
1028
+ this.left = x;
1029
+ this.top = y;
1030
+ this.originX = originX;
1031
+ this.originY = originY;
1032
+ }
1033
+ }
1034
+ /**
1035
+ * This callback function is called by the parent group of an object every
1036
+ * time a non-delegated property changes on the group. It is passed the key
1037
+ * and value as parameters. Not adding in this function's signature to avoid
1038
+ * Travis build error about unused variables.
1039
+ */
1040
+ setOnGroup() {
1041
+ // implemented by sub-classes, as needed.
1042
+ }
1043
+ /**
1044
+ * Sets canvas globalCompositeOperation for specific object
1045
+ * custom composition operation for the particular object can be specified using globalCompositeOperation property
1046
+ * @param {CanvasRenderingContext2D} ctx Rendering canvas context
1047
+ */
1048
+ _setupCompositeOperation(ctx) {
1049
+ if (this.globalCompositeOperation) {
1050
+ ctx.globalCompositeOperation = this.globalCompositeOperation;
1051
+ }
1052
+ }
1053
+ /**
1054
+ * cancel instance's running animations
1055
+ * override if necessary to dispose artifacts such as `clipPath`
1056
+ */
1057
+ dispose() {
1058
+ runningAnimations.cancelByTarget(this);
1059
+ this.off();
1060
+ this._set('canvas', undefined);
1061
+ // clear caches
1062
+ this._cacheCanvas && getEnv().dispose(this._cacheCanvas);
1063
+ this._cacheCanvas = undefined;
1064
+ this._cacheContext = null;
1065
+ }
1066
+ // #region Animation methods
1067
+ /**
1068
+ * List of properties to consider for animating colors.
1069
+ * @type String[]
1070
+ */
1071
+ static colorProperties = [FILL, STROKE, 'backgroundColor'];
1072
+ /**
1073
+ * Animates object's properties
1074
+ * @param {Record<string, number | number[] | TColorArg>} animatable map of keys and end values
1075
+ * @param {Partial<AnimationOptions<T>>} options
1076
+ * @tutorial {@link http://fabricjs.com/fabric-intro-part-2#animation}
1077
+ * @return {Record<string, TAnimation<T>>} map of animation contexts
1078
+ *
1079
+ * As object — multiple properties
1080
+ *
1081
+ * object.animate({ left: ..., top: ... });
1082
+ * object.animate({ left: ..., top: ... }, { duration: ... });
1083
+ */
1084
+ animate(animatable, options) {
1085
+ return Object.entries(animatable).reduce((acc, [key, endValue]) => {
1086
+ acc[key] = this._animate(key, endValue, options);
1087
+ return acc;
1088
+ }, {});
1089
+ }
1090
+ /**
1091
+ * @private
1092
+ * @param {String} key Property to animate
1093
+ * @param {String} to Value to animate to
1094
+ * @param {Object} [options] Options object
1095
+ */
1096
+ _animate(key, endValue, options = {}) {
1097
+ const path = key.split('.');
1098
+ const propIsColor = this.constructor.colorProperties.includes(path[path.length - 1]);
1099
+ const { abort, startValue, onChange, onComplete } = options;
1100
+ const animationOptions = {
1101
+ ...options,
1102
+ target: this,
1103
+ // path.reduce... is the current value in case start value isn't provided
1104
+ startValue: startValue ?? path.reduce((deep, key) => deep[key], this),
1105
+ endValue,
1106
+ abort: abort?.bind(this),
1107
+ onChange: (value, valueProgress, durationProgress) => {
1108
+ path.reduce((deep, key, index) => {
1109
+ if (index === path.length - 1) {
1110
+ deep[key] = value;
1111
+ }
1112
+ return deep[key];
1113
+ }, this);
1114
+ onChange &&
1115
+ // @ts-expect-error generic callback arg0 is wrong
1116
+ onChange(value, valueProgress, durationProgress);
1117
+ },
1118
+ onComplete: (value, valueProgress, durationProgress) => {
1119
+ this.setCoords();
1120
+ onComplete &&
1121
+ // @ts-expect-error generic callback arg0 is wrong
1122
+ onComplete(value, valueProgress, durationProgress);
1123
+ },
1124
+ };
1125
+ return (propIsColor
1126
+ ? animateColor(animationOptions)
1127
+ : animate(animationOptions));
1128
+ }
1129
+ /**
1130
+ * Checks if object is descendant of target
1131
+ * Should be used instead of {@link Group.contains} or {@link StaticCanvas.contains} for performance reasons
1132
+ * @param {TAncestor} target
1133
+ * @returns {boolean}
1134
+ */
1135
+ isDescendantOf(target) {
1136
+ const { parent, group } = this;
1137
+ return (parent === target ||
1138
+ group === target ||
1139
+ // walk up
1140
+ (!!parent && parent.isDescendantOf(target)) ||
1141
+ (!!group && group !== parent && group.isDescendantOf(target)));
1142
+ }
1143
+ /**
1144
+ * @returns {Ancestors} ancestors (excluding `ActiveSelection`) from bottom to top
1145
+ */
1146
+ getAncestors() {
1147
+ const ancestors = [];
1148
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
1149
+ let parent = this;
1150
+ do {
1151
+ parent = parent.parent;
1152
+ parent && ancestors.push(parent);
1153
+ } while (parent);
1154
+ return ancestors;
1155
+ }
1156
+ /**
1157
+ * Compare ancestors
1158
+ *
1159
+ * @param {StackedObject} other
1160
+ * @returns {AncestryComparison} an object that represent the ancestry situation.
1161
+ */
1162
+ findCommonAncestors(other) {
1163
+ if (this === other) {
1164
+ return {
1165
+ fork: [],
1166
+ otherFork: [],
1167
+ common: [this, ...this.getAncestors()],
1168
+ };
1169
+ }
1170
+ const ancestors = this.getAncestors();
1171
+ const otherAncestors = other.getAncestors();
1172
+ // if `this` has no ancestors and `this` is top ancestor of `other` we must handle the following case
1173
+ if (ancestors.length === 0 &&
1174
+ otherAncestors.length > 0 &&
1175
+ this === otherAncestors[otherAncestors.length - 1]) {
1176
+ return {
1177
+ fork: [],
1178
+ otherFork: [
1179
+ other,
1180
+ ...otherAncestors.slice(0, otherAncestors.length - 1),
1181
+ ],
1182
+ common: [this],
1183
+ };
1184
+ }
1185
+ // compare ancestors
1186
+ for (let i = 0, ancestor; i < ancestors.length; i++) {
1187
+ ancestor = ancestors[i];
1188
+ if (ancestor === other) {
1189
+ return {
1190
+ fork: [this, ...ancestors.slice(0, i)],
1191
+ otherFork: [],
1192
+ common: ancestors.slice(i),
1193
+ };
1194
+ }
1195
+ for (let j = 0; j < otherAncestors.length; j++) {
1196
+ if (this === otherAncestors[j]) {
1197
+ return {
1198
+ fork: [],
1199
+ otherFork: [other, ...otherAncestors.slice(0, j)],
1200
+ common: [this, ...ancestors],
1201
+ };
1202
+ }
1203
+ if (ancestor === otherAncestors[j]) {
1204
+ return {
1205
+ fork: [this, ...ancestors.slice(0, i)],
1206
+ otherFork: [other, ...otherAncestors.slice(0, j)],
1207
+ common: ancestors.slice(i),
1208
+ };
1209
+ }
1210
+ }
1211
+ }
1212
+ // nothing shared
1213
+ return {
1214
+ fork: [this, ...ancestors],
1215
+ otherFork: [other, ...otherAncestors],
1216
+ common: [],
1217
+ };
1218
+ }
1219
+ /**
1220
+ *
1221
+ * @param {StackedObject} other
1222
+ * @returns {boolean}
1223
+ */
1224
+ hasCommonAncestors(other) {
1225
+ const commonAncestors = this.findCommonAncestors(other);
1226
+ return commonAncestors && !!commonAncestors.common.length;
1227
+ }
1228
+ /**
1229
+ *
1230
+ * @param {FabricObject} other object to compare against
1231
+ * @returns {boolean | undefined} if objects do not share a common ancestor or they are strictly equal it is impossible to determine which is in front of the other; in such cases the function returns `undefined`
1232
+ */
1233
+ isInFrontOf(other) {
1234
+ if (this === other) {
1235
+ return undefined;
1236
+ }
1237
+ const ancestorData = this.findCommonAncestors(other);
1238
+ if (ancestorData.fork.includes(other)) {
1239
+ return true;
1240
+ }
1241
+ if (ancestorData.otherFork.includes(this)) {
1242
+ return false;
1243
+ }
1244
+ // if there isn't a common ancestor, we take the canvas.
1245
+ // if there is no canvas, there is nothing to compare
1246
+ const firstCommonAncestor = ancestorData.common[0] || this.canvas;
1247
+ if (!firstCommonAncestor) {
1248
+ return undefined;
1249
+ }
1250
+ const headOfFork = ancestorData.fork.pop(), headOfOtherFork = ancestorData.otherFork.pop(), thisIndex = firstCommonAncestor._objects.indexOf(headOfFork), otherIndex = firstCommonAncestor._objects.indexOf(headOfOtherFork);
1251
+ return thisIndex > -1 && thisIndex > otherIndex;
1252
+ }
1253
+ // #region Serialization
1254
+ /**
1255
+ * Define a list of custom properties that will be serialized when
1256
+ * instance.toObject() gets called
1257
+ */
1258
+ static customProperties = [];
1259
+ /**
1260
+ * Returns an object representation of an instance
1261
+ * @param {string[]} [propertiesToInclude] Any properties that you might want to additionally include in the output
1262
+ * @return {Object} Object representation of an instance
1263
+ */
1264
+ toObject(propertiesToInclude = []) {
1265
+ const propertiesToSerialize = propertiesToInclude.concat(FabricObject.customProperties, this.constructor.customProperties || []);
1266
+ let clipPathData;
1267
+ const NUM_FRACTION_DIGITS = config.NUM_FRACTION_DIGITS;
1268
+ const { clipPath, fill, stroke, shadow, strokeDashArray, left, top, originX, originY, width, height, strokeWidth, strokeLineCap, strokeDashOffset, strokeLineJoin, strokeUniform, strokeMiterLimit, scaleX, scaleY, angle, flipX, flipY, opacity, visible, backgroundColor, fillRule, paintFirst, globalCompositeOperation, skewX, skewY, } = this;
1269
+ if (clipPath && !clipPath.excludeFromExport) {
1270
+ clipPathData = clipPath.toObject(propertiesToSerialize.concat('inverted', 'absolutePositioned'));
1271
+ }
1272
+ const toFixedBound = (val) => toFixed(val, NUM_FRACTION_DIGITS);
1273
+ const object = {
1274
+ ...pick(this, propertiesToSerialize),
1275
+ type: this.constructor.type,
1276
+ version: VERSION,
1277
+ originX,
1278
+ originY,
1279
+ left: toFixedBound(left),
1280
+ top: toFixedBound(top),
1281
+ width: toFixedBound(width),
1282
+ height: toFixedBound(height),
1283
+ fill: isSerializableFiller(fill) ? fill.toObject() : fill,
1284
+ stroke: isSerializableFiller(stroke) ? stroke.toObject() : stroke,
1285
+ strokeWidth: toFixedBound(strokeWidth),
1286
+ strokeDashArray: strokeDashArray
1287
+ ? strokeDashArray.concat()
1288
+ : strokeDashArray,
1289
+ strokeLineCap,
1290
+ strokeDashOffset,
1291
+ strokeLineJoin,
1292
+ strokeUniform,
1293
+ strokeMiterLimit: toFixedBound(strokeMiterLimit),
1294
+ scaleX: toFixedBound(scaleX),
1295
+ scaleY: toFixedBound(scaleY),
1296
+ angle: toFixedBound(angle),
1297
+ flipX,
1298
+ flipY,
1299
+ opacity: toFixedBound(opacity),
1300
+ shadow: shadow ? shadow.toObject() : shadow,
1301
+ visible,
1302
+ backgroundColor,
1303
+ fillRule,
1304
+ paintFirst,
1305
+ globalCompositeOperation,
1306
+ skewX: toFixedBound(skewX),
1307
+ skewY: toFixedBound(skewY),
1308
+ ...(clipPathData ? { clipPath: clipPathData } : null),
1309
+ };
1310
+ return !this.includeDefaultValues
1311
+ ? this._removeDefaultValues(object)
1312
+ : object;
1313
+ }
1314
+ /**
1315
+ * Returns (dataless) object representation of an instance
1316
+ * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
1317
+ * @return {Object} Object representation of an instance
1318
+ */
1319
+ toDatalessObject(propertiesToInclude) {
1320
+ // will be overwritten by subclasses
1321
+ return this.toObject(propertiesToInclude);
1322
+ }
1323
+ /**
1324
+ * @private
1325
+ * @param {Object} object
1326
+ */
1327
+ _removeDefaultValues(object) {
1328
+ // getDefaults() ( get from static ownDefaults ) should win over prototype since anyway they get assigned to instance
1329
+ // ownDefault vs prototype is swappable only if you change all the fabric objects consistently.
1330
+ const defaults = this.constructor.getDefaults();
1331
+ const hasStaticDefaultValues = Object.keys(defaults).length > 0;
1332
+ const baseValues = hasStaticDefaultValues
1333
+ ? defaults
1334
+ : Object.getPrototypeOf(this);
1335
+ return pickBy(object, (value, key) => {
1336
+ if (key === LEFT || key === TOP || key === 'type') {
1337
+ return true;
1338
+ }
1339
+ const baseValue = baseValues[key];
1340
+ return (value !== baseValue &&
1341
+ // basically a check for [] === []
1342
+ !(Array.isArray(value) &&
1343
+ Array.isArray(baseValue) &&
1344
+ value.length === 0 &&
1345
+ baseValue.length === 0));
1346
+ });
1347
+ }
1348
+ /**
1349
+ * Returns a string representation of an instance
1350
+ * @return {String}
1351
+ */
1352
+ toString() {
1353
+ return `#<${this.constructor.type}>`;
1354
+ }
1355
+ /**
1356
+ *
1357
+ * @param {Function} klass
1358
+ * @param {object} object
1359
+ * @param {object} [options]
1360
+ * @param {string} [options.extraParam] property to pass as first argument to the constructor
1361
+ * @param {AbortSignal} [options.signal] handle aborting, see https://developer.mozilla.org/en-US/docs/Web/API/AbortController/signal
1362
+ * @returns {Promise<FabricObject>}
1363
+ */
1364
+ static _fromObject({ type, ...serializedObjectOptions }, { extraParam, ...options } = {}) {
1365
+ return enlivenObjectEnlivables(serializedObjectOptions, options).then((enlivedObjectOptions) => {
1366
+ // from the resulting enlived options, extract options.extraParam to arg0
1367
+ // to avoid accidental overrides later
1368
+ if (extraParam) {
1369
+ delete enlivedObjectOptions[extraParam];
1370
+ return new this(serializedObjectOptions[extraParam],
1371
+ // @ts-expect-error different signature
1372
+ enlivedObjectOptions);
1373
+ }
1374
+ else {
1375
+ return new this(enlivedObjectOptions);
1376
+ }
1377
+ });
1378
+ }
1379
+ /**
1380
+ *
1381
+ * @param {object} object
1382
+ * @param {object} [options]
1383
+ * @param {AbortSignal} [options.signal] handle aborting, see https://developer.mozilla.org/en-US/docs/Web/API/AbortController/signal
1384
+ * @returns {Promise<FabricObject>}
1385
+ */
1386
+ static fromObject(object, options) {
1387
+ return this._fromObject(object, options);
1388
+ }
1389
+ }
1390
+ classRegistry.setClass(FabricObject);
1391
+ classRegistry.setClass(FabricObject, 'object');
1392
+ //# sourceMappingURL=Object.js.map