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,1085 @@
1
+ import { config } from '../config';
2
+ import { CENTER, VERSION } from '../constants';
3
+ import { createCollectionMixin, isCollection } from '../Collection';
4
+ import { CommonMethods } from '../CommonMethods';
5
+ import { Point } from '../Point';
6
+ import { cancelAnimFrame, requestAnimFrame, } from '../util/animation/AnimationFrameProvider';
7
+ import { runningAnimations } from '../util/animation/AnimationRegistry';
8
+ import { uid } from '../util/internals/uid';
9
+ import { createCanvasElementFor, toBlob, toDataURL } from '../util/misc/dom';
10
+ import { invertTransform, transformPoint } from '../util/misc/matrix';
11
+ import { enlivenObjectEnlivables, enlivenObjects, } from '../util/misc/objectEnlive';
12
+ import { pick } from '../util/misc/pick';
13
+ import { matrixToSVG } from '../util/misc/svgExport';
14
+ import { toFixed } from '../util/misc/toFixed';
15
+ import { isFiller, isPattern, isTextObject } from '../util/typeAssertions';
16
+ import { StaticCanvasDOMManager } from './DOMManagers/StaticCanvasDOMManager';
17
+ import { staticCanvasDefaults } from './StaticCanvasOptions';
18
+ import { log, FabricError } from '../util/internals/console';
19
+ import { getDevicePixelRatio } from '../env';
20
+ /**
21
+ * Static canvas class
22
+ * @see {@link http://fabricjs.com/static_canvas|StaticCanvas demo}
23
+ * @fires before:render
24
+ * @fires after:render
25
+ * @fires canvas:cleared
26
+ * @fires object:added
27
+ * @fires object:removed
28
+ */
29
+ // TODO: fix `EventSpec` inheritance https://github.com/microsoft/TypeScript/issues/26154#issuecomment-1366616260
30
+ export class StaticCanvas extends createCollectionMixin((CommonMethods)) {
31
+ /**
32
+ * A reference to the canvas actual HTMLCanvasElement.
33
+ * Can be use to read the raw pixels, but never write or manipulate
34
+ * @type HTMLCanvasElement
35
+ */
36
+ get lowerCanvasEl() {
37
+ return this.elements.lower?.el;
38
+ }
39
+ get contextContainer() {
40
+ return this.elements.lower?.ctx;
41
+ }
42
+ static ownDefaults = staticCanvasDefaults;
43
+ static getDefaults() {
44
+ return StaticCanvas.ownDefaults;
45
+ }
46
+ constructor(el, options = {}) {
47
+ super();
48
+ Object.assign(this, this.constructor.getDefaults());
49
+ this.set(options);
50
+ this.initElements(el);
51
+ this._setDimensionsImpl({
52
+ width: this.width || this.elements.lower.el.width || 0,
53
+ height: this.height || this.elements.lower.el.height || 0,
54
+ });
55
+ this.skipControlsDrawing = false;
56
+ this.viewportTransform = [...this.viewportTransform];
57
+ this.calcViewportBoundaries();
58
+ }
59
+ initElements(el) {
60
+ this.elements = new StaticCanvasDOMManager(el);
61
+ }
62
+ add(...objects) {
63
+ const size = super.add(...objects);
64
+ objects.length > 0 && this.renderOnAddRemove && this.requestRenderAll();
65
+ return size;
66
+ }
67
+ insertAt(index, ...objects) {
68
+ const size = super.insertAt(index, ...objects);
69
+ objects.length > 0 && this.renderOnAddRemove && this.requestRenderAll();
70
+ return size;
71
+ }
72
+ remove(...objects) {
73
+ const removed = super.remove(...objects);
74
+ removed.length > 0 && this.renderOnAddRemove && this.requestRenderAll();
75
+ return removed;
76
+ }
77
+ _onObjectAdded(obj) {
78
+ if (obj.canvas && obj.canvas !== this) {
79
+ log('warn', 'Canvas is trying to add an object that belongs to a different canvas.\n' +
80
+ 'Resulting to default behavior: removing object from previous canvas and adding to new canvas');
81
+ obj.canvas.remove(obj);
82
+ }
83
+ obj._set('canvas', this);
84
+ obj.setCoords();
85
+ this.fire('object:added', { target: obj });
86
+ obj.fire('added', { target: this });
87
+ }
88
+ _onObjectRemoved(obj) {
89
+ obj._set('canvas', undefined);
90
+ this.fire('object:removed', { target: obj });
91
+ obj.fire('removed', { target: this });
92
+ }
93
+ _onStackOrderChanged() {
94
+ this.renderOnAddRemove && this.requestRenderAll();
95
+ }
96
+ /**
97
+ * @private
98
+ * @see https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/HTML-canvas-guide/SettingUptheCanvas/SettingUptheCanvas.html
99
+ * @return {Number} retinaScaling if applied, otherwise 1;
100
+ */
101
+ getRetinaScaling() {
102
+ return this.enableRetinaScaling ? getDevicePixelRatio() : 1;
103
+ }
104
+ /**
105
+ * Calculates canvas element offset relative to the document
106
+ * This method is also attached as "resize" event handler of window
107
+ */
108
+ calcOffset() {
109
+ return (this._offset = this.elements.calcOffset());
110
+ }
111
+ /**
112
+ * Returns canvas width (in px)
113
+ * @return {Number}
114
+ */
115
+ getWidth() {
116
+ return this.width;
117
+ }
118
+ /**
119
+ * Returns canvas height (in px)
120
+ * @return {Number}
121
+ */
122
+ getHeight() {
123
+ return this.height;
124
+ }
125
+ setWidth(value, options) {
126
+ return this.setDimensions({ width: value }, options);
127
+ }
128
+ setHeight(value, options) {
129
+ return this.setDimensions({ height: value }, options);
130
+ }
131
+ /**
132
+ * Internal use only
133
+ * @protected
134
+ */
135
+ _setDimensionsImpl(dimensions, { cssOnly = false, backstoreOnly = false } = {}) {
136
+ if (!cssOnly) {
137
+ const size = {
138
+ width: this.width,
139
+ height: this.height,
140
+ ...dimensions,
141
+ };
142
+ this.elements.setDimensions(size, this.getRetinaScaling());
143
+ this.hasLostContext = true;
144
+ this.width = size.width;
145
+ this.height = size.height;
146
+ }
147
+ if (!backstoreOnly) {
148
+ this.elements.setCSSDimensions(dimensions);
149
+ }
150
+ this.calcOffset();
151
+ }
152
+ setDimensions(dimensions, options) {
153
+ this._setDimensionsImpl(dimensions, options);
154
+ if (!options || !options.cssOnly) {
155
+ this.requestRenderAll();
156
+ }
157
+ }
158
+ /**
159
+ * Returns canvas zoom level
160
+ * @return {Number}
161
+ */
162
+ getZoom() {
163
+ return this.viewportTransform[0];
164
+ }
165
+ /**
166
+ * Sets viewport transformation of this canvas instance
167
+ * @param {Array} vpt a Canvas 2D API transform matrix
168
+ */
169
+ setViewportTransform(vpt) {
170
+ this.viewportTransform = vpt;
171
+ this.calcViewportBoundaries();
172
+ this.renderOnAddRemove && this.requestRenderAll();
173
+ }
174
+ /**
175
+ * Sets zoom level of this canvas instance, the zoom centered around point
176
+ * meaning that following zoom to point with the same point will have the visual
177
+ * effect of the zoom originating from that point. The point won't move.
178
+ * It has nothing to do with canvas center or visual center of the viewport.
179
+ * @param {Point} point to zoom with respect to
180
+ * @param {Number} value to set zoom to, less than 1 zooms out
181
+ */
182
+ zoomToPoint(point, value) {
183
+ // TODO: just change the scale, preserve other transformations
184
+ const before = point, vpt = [...this.viewportTransform];
185
+ const newPoint = transformPoint(point, invertTransform(vpt));
186
+ vpt[0] = value;
187
+ vpt[3] = value;
188
+ const after = transformPoint(newPoint, vpt);
189
+ vpt[4] += before.x - after.x;
190
+ vpt[5] += before.y - after.y;
191
+ this.setViewportTransform(vpt);
192
+ }
193
+ /**
194
+ * Sets zoom level of this canvas instance
195
+ * @param {Number} value to set zoom to, less than 1 zooms out
196
+ */
197
+ setZoom(value) {
198
+ this.zoomToPoint(new Point(0, 0), value);
199
+ }
200
+ /**
201
+ * Pan viewport so as to place point at top left corner of canvas
202
+ * @param {Point} point to move to
203
+ */
204
+ absolutePan(point) {
205
+ const vpt = [...this.viewportTransform];
206
+ vpt[4] = -point.x;
207
+ vpt[5] = -point.y;
208
+ return this.setViewportTransform(vpt);
209
+ }
210
+ /**
211
+ * Pans viewpoint relatively
212
+ * @param {Point} point (position vector) to move by
213
+ */
214
+ relativePan(point) {
215
+ return this.absolutePan(new Point(-point.x - this.viewportTransform[4], -point.y - this.viewportTransform[5]));
216
+ }
217
+ /**
218
+ * Returns <canvas> element corresponding to this instance
219
+ * @return {HTMLCanvasElement}
220
+ */
221
+ getElement() {
222
+ return this.elements.lower.el;
223
+ }
224
+ /**
225
+ * Clears specified context of canvas element
226
+ * @param {CanvasRenderingContext2D} ctx Context to clear
227
+ */
228
+ clearContext(ctx) {
229
+ ctx.clearRect(0, 0, this.width, this.height);
230
+ }
231
+ /**
232
+ * Returns context of canvas where objects are drawn
233
+ * @return {CanvasRenderingContext2D}
234
+ */
235
+ getContext() {
236
+ return this.elements.lower.ctx;
237
+ }
238
+ /**
239
+ * Clears all contexts (background, main, top) of an instance
240
+ */
241
+ clear() {
242
+ this.remove(...this.getObjects());
243
+ this.backgroundImage = undefined;
244
+ this.overlayImage = undefined;
245
+ this.backgroundColor = '';
246
+ this.overlayColor = '';
247
+ this.clearContext(this.getContext());
248
+ this.fire('canvas:cleared');
249
+ this.renderOnAddRemove && this.requestRenderAll();
250
+ }
251
+ /**
252
+ * Renders the canvas
253
+ */
254
+ renderAll() {
255
+ this.cancelRequestedRender();
256
+ if (this.destroyed) {
257
+ return;
258
+ }
259
+ this.renderCanvas(this.getContext(), this._objects);
260
+ }
261
+ /**
262
+ * Function created to be instance bound at initialization
263
+ * used in requestAnimationFrame rendering
264
+ * Let the fabricJS call it. If you call it manually you could have more
265
+ * animationFrame stacking on to of each other
266
+ * for an imperative rendering, use canvas.renderAll
267
+ * @private
268
+ */
269
+ renderAndReset() {
270
+ this.nextRenderHandle = 0;
271
+ this.renderAll();
272
+ }
273
+ /**
274
+ * Append a renderAll request to next animation frame.
275
+ * unless one is already in progress, in that case nothing is done
276
+ * a boolean flag will avoid appending more.
277
+ */
278
+ requestRenderAll() {
279
+ if (!this.nextRenderHandle && !this.disposed && !this.destroyed) {
280
+ this.nextRenderHandle = requestAnimFrame(() => this.renderAndReset());
281
+ }
282
+ }
283
+ /**
284
+ * Calculate the position of the 4 corner of canvas with current viewportTransform.
285
+ * helps to determinate when an object is in the current rendering viewport
286
+ */
287
+ calcViewportBoundaries() {
288
+ const width = this.width, height = this.height, iVpt = invertTransform(this.viewportTransform), a = transformPoint({ x: 0, y: 0 }, iVpt), b = transformPoint({ x: width, y: height }, iVpt),
289
+ // we don't support vpt flipping
290
+ // but the code is robust enough to mostly work with flipping
291
+ min = a.min(b), max = a.max(b);
292
+ return (this.vptCoords = {
293
+ tl: min,
294
+ tr: new Point(max.x, min.y),
295
+ bl: new Point(min.x, max.y),
296
+ br: max,
297
+ });
298
+ }
299
+ cancelRequestedRender() {
300
+ if (this.nextRenderHandle) {
301
+ cancelAnimFrame(this.nextRenderHandle);
302
+ this.nextRenderHandle = 0;
303
+ }
304
+ }
305
+ drawControls(_ctx) {
306
+ // Static canvas has no controls
307
+ }
308
+ /**
309
+ * Renders background, objects, overlay and controls.
310
+ * @param {CanvasRenderingContext2D} ctx
311
+ * @param {Array} objects to render
312
+ */
313
+ renderCanvas(ctx, objects) {
314
+ if (this.destroyed) {
315
+ return;
316
+ }
317
+ const v = this.viewportTransform, path = this.clipPath;
318
+ this.calcViewportBoundaries();
319
+ this.clearContext(ctx);
320
+ ctx.imageSmoothingEnabled = this.imageSmoothingEnabled;
321
+ // @ts-expect-error node-canvas stuff
322
+ ctx.patternQuality = 'best';
323
+ this.fire('before:render', { ctx });
324
+ this._renderBackground(ctx);
325
+ ctx.save();
326
+ //apply viewport transform once for all rendering process
327
+ ctx.transform(v[0], v[1], v[2], v[3], v[4], v[5]);
328
+ this._renderObjects(ctx, objects);
329
+ ctx.restore();
330
+ if (!this.controlsAboveOverlay && !this.skipControlsDrawing) {
331
+ this.drawControls(ctx);
332
+ }
333
+ if (path) {
334
+ path._set('canvas', this);
335
+ // needed to setup a couple of variables
336
+ // todo migrate to the newer one
337
+ path.shouldCache();
338
+ path._transformDone = true;
339
+ path.renderCache({ forClipping: true });
340
+ this.drawClipPathOnCanvas(ctx, path);
341
+ }
342
+ this._renderOverlay(ctx);
343
+ if (this.controlsAboveOverlay && !this.skipControlsDrawing) {
344
+ this.drawControls(ctx);
345
+ }
346
+ this.fire('after:render', { ctx });
347
+ if (this.__cleanupTask) {
348
+ this.__cleanupTask();
349
+ this.__cleanupTask = undefined;
350
+ }
351
+ }
352
+ /**
353
+ * Paint the cached clipPath on the lowerCanvasEl
354
+ * @param {CanvasRenderingContext2D} ctx Context to render on
355
+ */
356
+ drawClipPathOnCanvas(ctx, clipPath) {
357
+ const v = this.viewportTransform;
358
+ ctx.save();
359
+ ctx.transform(...v);
360
+ // DEBUG: uncomment this line, comment the following
361
+ // ctx.globalAlpha = 0.4;
362
+ ctx.globalCompositeOperation = 'destination-in';
363
+ clipPath.transform(ctx);
364
+ ctx.scale(1 / clipPath.zoomX, 1 / clipPath.zoomY);
365
+ ctx.drawImage(clipPath._cacheCanvas, -clipPath.cacheTranslationX, -clipPath.cacheTranslationY);
366
+ ctx.restore();
367
+ }
368
+ /**
369
+ * @private
370
+ * @param {CanvasRenderingContext2D} ctx Context to render on
371
+ * @param {Array} objects to render
372
+ */
373
+ _renderObjects(ctx, objects) {
374
+ for (let i = 0, len = objects.length; i < len; ++i) {
375
+ objects[i] && objects[i].render(ctx);
376
+ }
377
+ }
378
+ /**
379
+ * @private
380
+ * @param {CanvasRenderingContext2D} ctx Context to render on
381
+ * @param {string} property 'background' or 'overlay'
382
+ */
383
+ _renderBackgroundOrOverlay(ctx, property) {
384
+ const fill = this[`${property}Color`], object = this[`${property}Image`], v = this.viewportTransform, needsVpt = this[`${property}Vpt`];
385
+ if (!fill && !object) {
386
+ return;
387
+ }
388
+ const isAFiller = isFiller(fill);
389
+ if (fill) {
390
+ ctx.save();
391
+ ctx.beginPath();
392
+ ctx.moveTo(0, 0);
393
+ ctx.lineTo(this.width, 0);
394
+ ctx.lineTo(this.width, this.height);
395
+ ctx.lineTo(0, this.height);
396
+ ctx.closePath();
397
+ ctx.fillStyle = isAFiller ? fill.toLive(ctx /* this */) : fill;
398
+ if (needsVpt) {
399
+ ctx.transform(...v);
400
+ }
401
+ if (isAFiller) {
402
+ ctx.transform(1, 0, 0, 1, fill.offsetX || 0, fill.offsetY || 0);
403
+ const m = (fill.gradientTransform ||
404
+ fill.patternTransform);
405
+ m && ctx.transform(...m);
406
+ }
407
+ ctx.fill();
408
+ ctx.restore();
409
+ }
410
+ if (object) {
411
+ ctx.save();
412
+ const { skipOffscreen } = this;
413
+ // if the object doesn't move with the viewport,
414
+ // the offscreen concept does not apply;
415
+ this.skipOffscreen = needsVpt;
416
+ if (needsVpt) {
417
+ ctx.transform(...v);
418
+ }
419
+ object.render(ctx);
420
+ this.skipOffscreen = skipOffscreen;
421
+ ctx.restore();
422
+ }
423
+ }
424
+ /**
425
+ * @private
426
+ * @param {CanvasRenderingContext2D} ctx Context to render on
427
+ */
428
+ _renderBackground(ctx) {
429
+ this._renderBackgroundOrOverlay(ctx, 'background');
430
+ }
431
+ /**
432
+ * @private
433
+ * @param {CanvasRenderingContext2D} ctx Context to render on
434
+ */
435
+ _renderOverlay(ctx) {
436
+ this._renderBackgroundOrOverlay(ctx, 'overlay');
437
+ }
438
+ /**
439
+ * Returns coordinates of a center of canvas.
440
+ * Returned value is an object with top and left properties
441
+ * @return {Object} object with "top" and "left" number values
442
+ * @deprecated migrate to `getCenterPoint`
443
+ */
444
+ getCenter() {
445
+ return {
446
+ top: this.height / 2,
447
+ left: this.width / 2,
448
+ };
449
+ }
450
+ /**
451
+ * Returns coordinates of a center of canvas.
452
+ * @return {Point}
453
+ */
454
+ getCenterPoint() {
455
+ return new Point(this.width / 2, this.height / 2);
456
+ }
457
+ /**
458
+ * Centers object horizontally in the canvas
459
+ */
460
+ centerObjectH(object) {
461
+ return this._centerObject(object, new Point(this.getCenterPoint().x, object.getCenterPoint().y));
462
+ }
463
+ /**
464
+ * Centers object vertically in the canvas
465
+ * @param {FabricObject} object Object to center vertically
466
+ */
467
+ centerObjectV(object) {
468
+ return this._centerObject(object, new Point(object.getCenterPoint().x, this.getCenterPoint().y));
469
+ }
470
+ /**
471
+ * Centers object vertically and horizontally in the canvas
472
+ * @param {FabricObject} object Object to center vertically and horizontally
473
+ */
474
+ centerObject(object) {
475
+ return this._centerObject(object, this.getCenterPoint());
476
+ }
477
+ /**
478
+ * Centers object vertically and horizontally in the viewport
479
+ * @param {FabricObject} object Object to center vertically and horizontally
480
+ */
481
+ viewportCenterObject(object) {
482
+ return this._centerObject(object, this.getVpCenter());
483
+ }
484
+ /**
485
+ * Centers object horizontally in the viewport, object.top is unchanged
486
+ * @param {FabricObject} object Object to center vertically and horizontally
487
+ */
488
+ viewportCenterObjectH(object) {
489
+ return this._centerObject(object, new Point(this.getVpCenter().x, object.getCenterPoint().y));
490
+ }
491
+ /**
492
+ * Centers object Vertically in the viewport, object.top is unchanged
493
+ * @param {FabricObject} object Object to center vertically and horizontally
494
+ */
495
+ viewportCenterObjectV(object) {
496
+ return this._centerObject(object, new Point(object.getCenterPoint().x, this.getVpCenter().y));
497
+ }
498
+ /**
499
+ * Calculate the point in canvas that correspond to the center of actual viewport.
500
+ * @return {Point} vpCenter, viewport center
501
+ */
502
+ getVpCenter() {
503
+ return transformPoint(this.getCenterPoint(), invertTransform(this.viewportTransform));
504
+ }
505
+ /**
506
+ * @private
507
+ * @param {FabricObject} object Object to center
508
+ * @param {Point} center Center point
509
+ */
510
+ _centerObject(object, center) {
511
+ object.setXY(center, CENTER, CENTER);
512
+ object.setCoords();
513
+ this.renderOnAddRemove && this.requestRenderAll();
514
+ }
515
+ /**
516
+ * Returns dataless JSON representation of canvas
517
+ * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
518
+ * @return {String} json string
519
+ */
520
+ toDatalessJSON(propertiesToInclude) {
521
+ return this.toDatalessObject(propertiesToInclude);
522
+ }
523
+ /**
524
+ * Returns object representation of canvas
525
+ * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
526
+ * @return {Object} object representation of an instance
527
+ */
528
+ toObject(propertiesToInclude) {
529
+ return this._toObjectMethod('toObject', propertiesToInclude);
530
+ }
531
+ /**
532
+ * Returns Object representation of canvas
533
+ * this alias is provided because if you call JSON.stringify on an instance,
534
+ * the toJSON object will be invoked if it exists.
535
+ * Having a toJSON method means you can do JSON.stringify(myCanvas)
536
+ * JSON does not support additional properties because toJSON has its own signature
537
+ * @return {Object} JSON compatible object
538
+ * @tutorial {@link http://fabricjs.com/fabric-intro-part-3#serialization}
539
+ * @see {@link http://jsfiddle.net/fabricjs/pec86/|jsFiddle demo}
540
+ * @example <caption>JSON representation of canvas </caption>
541
+ * const json = canvas.toJSON();
542
+ * @example <caption>JSON representation of canvas </caption>
543
+ * const json = JSON.stringify(canvas);
544
+ */
545
+ toJSON() {
546
+ return this.toObject();
547
+ }
548
+ /**
549
+ * Returns dataless object representation of canvas
550
+ * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
551
+ * @return {Object} object representation of an instance
552
+ */
553
+ toDatalessObject(propertiesToInclude) {
554
+ return this._toObjectMethod('toDatalessObject', propertiesToInclude);
555
+ }
556
+ /**
557
+ * @private
558
+ */
559
+ _toObjectMethod(methodName, propertiesToInclude) {
560
+ const clipPath = this.clipPath;
561
+ const clipPathData = clipPath && !clipPath.excludeFromExport
562
+ ? this._toObject(clipPath, methodName, propertiesToInclude)
563
+ : null;
564
+ return {
565
+ version: VERSION,
566
+ ...pick(this, propertiesToInclude),
567
+ objects: this._objects
568
+ .filter((object) => !object.excludeFromExport)
569
+ .map((instance) => this._toObject(instance, methodName, propertiesToInclude)),
570
+ ...this.__serializeBgOverlay(methodName, propertiesToInclude),
571
+ ...(clipPathData ? { clipPath: clipPathData } : null),
572
+ };
573
+ }
574
+ /**
575
+ * @private
576
+ */
577
+ _toObject(instance, methodName, propertiesToInclude) {
578
+ let originalValue;
579
+ if (!this.includeDefaultValues) {
580
+ originalValue = instance.includeDefaultValues;
581
+ instance.includeDefaultValues = false;
582
+ }
583
+ const object = instance[methodName](propertiesToInclude);
584
+ if (!this.includeDefaultValues) {
585
+ instance.includeDefaultValues = !!originalValue;
586
+ }
587
+ return object;
588
+ }
589
+ /**
590
+ * @private
591
+ */
592
+ __serializeBgOverlay(methodName, propertiesToInclude) {
593
+ const data = {}, bgImage = this.backgroundImage, overlayImage = this.overlayImage, bgColor = this.backgroundColor, overlayColor = this.overlayColor;
594
+ if (isFiller(bgColor)) {
595
+ if (!bgColor.excludeFromExport) {
596
+ data.background = bgColor.toObject(propertiesToInclude);
597
+ }
598
+ }
599
+ else if (bgColor) {
600
+ data.background = bgColor;
601
+ }
602
+ if (isFiller(overlayColor)) {
603
+ if (!overlayColor.excludeFromExport) {
604
+ data.overlay = overlayColor.toObject(propertiesToInclude);
605
+ }
606
+ }
607
+ else if (overlayColor) {
608
+ data.overlay = overlayColor;
609
+ }
610
+ if (bgImage && !bgImage.excludeFromExport) {
611
+ data.backgroundImage = this._toObject(bgImage, methodName, propertiesToInclude);
612
+ }
613
+ if (overlayImage && !overlayImage.excludeFromExport) {
614
+ data.overlayImage = this._toObject(overlayImage, methodName, propertiesToInclude);
615
+ }
616
+ return data;
617
+ }
618
+ /**
619
+ * Returns SVG representation of canvas
620
+ * @function
621
+ * @param {Object} [options] Options object for SVG output
622
+ * @param {Boolean} [options.suppressPreamble=false] If true xml tag is not included
623
+ * @param {Object} [options.viewBox] SVG viewbox object
624
+ * @param {Number} [options.viewBox.x] x-coordinate of viewbox
625
+ * @param {Number} [options.viewBox.y] y-coordinate of viewbox
626
+ * @param {Number} [options.viewBox.width] Width of viewbox
627
+ * @param {Number} [options.viewBox.height] Height of viewbox
628
+ * @param {String} [options.encoding=UTF-8] Encoding of SVG output
629
+ * @param {String} [options.width] desired width of svg with or without units
630
+ * @param {String} [options.height] desired height of svg with or without units
631
+ * @param {Function} [reviver] Method for further parsing of svg elements, called after each fabric object converted into svg representation.
632
+ * @return {String} SVG string
633
+ * @tutorial {@link http://fabricjs.com/fabric-intro-part-3#serialization}
634
+ * @see {@link http://jsfiddle.net/fabricjs/jQ3ZZ/|jsFiddle demo}
635
+ * @example <caption>Normal SVG output</caption>
636
+ * var svg = canvas.toSVG();
637
+ * @example <caption>SVG output without preamble (without &lt;?xml ../>)</caption>
638
+ * var svg = canvas.toSVG({suppressPreamble: true});
639
+ * @example <caption>SVG output with viewBox attribute</caption>
640
+ * var svg = canvas.toSVG({
641
+ * viewBox: {
642
+ * x: 100,
643
+ * y: 100,
644
+ * width: 200,
645
+ * height: 300
646
+ * }
647
+ * });
648
+ * @example <caption>SVG output with different encoding (default: UTF-8)</caption>
649
+ * var svg = canvas.toSVG({encoding: 'ISO-8859-1'});
650
+ * @example <caption>Modify SVG output with reviver function</caption>
651
+ * var svg = canvas.toSVG(null, function(svg) {
652
+ * return svg.replace('stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; ', '');
653
+ * });
654
+ */
655
+ toSVG(options = {}, reviver) {
656
+ options.reviver = reviver;
657
+ const markup = [];
658
+ this._setSVGPreamble(markup, options);
659
+ this._setSVGHeader(markup, options);
660
+ if (this.clipPath) {
661
+ markup.push(`<g clip-path="url(#${this.clipPath.clipPathId})" >\n`);
662
+ }
663
+ this._setSVGBgOverlayColor(markup, 'background');
664
+ this._setSVGBgOverlayImage(markup, 'backgroundImage', reviver);
665
+ this._setSVGObjects(markup, reviver);
666
+ if (this.clipPath) {
667
+ markup.push('</g>\n');
668
+ }
669
+ this._setSVGBgOverlayColor(markup, 'overlay');
670
+ this._setSVGBgOverlayImage(markup, 'overlayImage', reviver);
671
+ markup.push('</svg>');
672
+ return markup.join('');
673
+ }
674
+ /**
675
+ * @private
676
+ */
677
+ _setSVGPreamble(markup, options) {
678
+ if (options.suppressPreamble) {
679
+ return;
680
+ }
681
+ markup.push('<?xml version="1.0" encoding="', options.encoding || 'UTF-8', '" standalone="no" ?>\n', '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" ', '"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n');
682
+ }
683
+ /**
684
+ * @private
685
+ */
686
+ _setSVGHeader(markup, options) {
687
+ const width = options.width || `${this.width}`, height = options.height || `${this.height}`, NUM_FRACTION_DIGITS = config.NUM_FRACTION_DIGITS, optViewBox = options.viewBox;
688
+ let viewBox;
689
+ if (optViewBox) {
690
+ viewBox = `viewBox="${optViewBox.x} ${optViewBox.y} ${optViewBox.width} ${optViewBox.height}" `;
691
+ }
692
+ else if (this.svgViewportTransformation) {
693
+ const vpt = this.viewportTransform;
694
+ viewBox = `viewBox="${toFixed(-vpt[4] / vpt[0], NUM_FRACTION_DIGITS)} ${toFixed(-vpt[5] / vpt[3], NUM_FRACTION_DIGITS)} ${toFixed(this.width / vpt[0], NUM_FRACTION_DIGITS)} ${toFixed(this.height / vpt[3], NUM_FRACTION_DIGITS)}" `;
695
+ }
696
+ else {
697
+ viewBox = `viewBox="0 0 ${this.width} ${this.height}" `;
698
+ }
699
+ markup.push('<svg ', 'xmlns="http://www.w3.org/2000/svg" ', 'xmlns:xlink="http://www.w3.org/1999/xlink" ', 'version="1.1" ', 'width="', width, '" ', 'height="', height, '" ', viewBox, 'xml:space="preserve">\n', '<desc>Created with Fabric.js ', VERSION, '</desc>\n', '<defs>\n', this.createSVGFontFacesMarkup(), this.createSVGRefElementsMarkup(), this.createSVGClipPathMarkup(options),
700
+ // James add
701
+ this._createPathForText(), '</defs>\n');
702
+ }
703
+ /**
704
+ * James added this method for exporting text path
705
+ */
706
+ _createPathForText() {
707
+ const pathMarkups = [];
708
+ const objects = [];
709
+ this._objects.forEach(function add(object) {
710
+ objects.push(object);
711
+ if (isCollection(object)) {
712
+ object._objects.forEach(add);
713
+ }
714
+ });
715
+ objects.forEach((instance) => {
716
+ if (instance.excludeFromExport) {
717
+ return;
718
+ }
719
+ if (!isTextObject(instance) || !instance.path) {
720
+ return;
721
+ }
722
+ const pathId = `TEXTPATH_${instance.id}`;
723
+ const pathMarkup = instance.path._toSVG();
724
+ const index = pathMarkup.indexOf('COMMON_PARTS');
725
+ // 加上id, 和路径偏移
726
+ pathMarkup[index] = [
727
+ 'id="' + pathId + '" ',
728
+ 'transform="translate(' +
729
+ -instance.path.pathOffset.x +
730
+ ',' +
731
+ -instance.path.pathOffset.y +
732
+ ')" ',
733
+ ].join('');
734
+ pathMarkups.push(pathMarkup.join(''));
735
+ });
736
+ return pathMarkups.join('\n');
737
+ }
738
+ createSVGClipPathMarkup(options) {
739
+ const clipPath = this.clipPath;
740
+ if (clipPath) {
741
+ clipPath.clipPathId = `CLIPPATH_${uid()}`;
742
+ return `<clipPath id="${clipPath.clipPathId}" >\n${clipPath.toClipPathSVG(options.reviver)}</clipPath>\n`;
743
+ }
744
+ return '';
745
+ }
746
+ /**
747
+ * Creates markup containing SVG referenced elements like patterns, gradients etc.
748
+ * @return {String}
749
+ */
750
+ createSVGRefElementsMarkup() {
751
+ return ['background', 'overlay']
752
+ .map((prop) => {
753
+ const fill = this[`${prop}Color`];
754
+ if (isFiller(fill)) {
755
+ const shouldTransform = this[`${prop}Vpt`], vpt = this.viewportTransform, object = {
756
+ // otherwise circular dependency
757
+ isType: () => false,
758
+ width: this.width / (shouldTransform ? vpt[0] : 1),
759
+ height: this.height / (shouldTransform ? vpt[3] : 1),
760
+ };
761
+ return fill.toSVG(object, {
762
+ additionalTransform: shouldTransform ? matrixToSVG(vpt) : '',
763
+ });
764
+ }
765
+ })
766
+ .join('');
767
+ }
768
+ /**
769
+ * Creates markup containing SVG font faces,
770
+ * font URLs for font faces must be collected by developers
771
+ * and are not extracted from the DOM by fabricjs
772
+ * @param {Array} objects Array of fabric objects
773
+ * @return {String}
774
+ */
775
+ createSVGFontFacesMarkup() {
776
+ const objects = [], fontList = {}, fontPaths = config.fontPaths;
777
+ this._objects.forEach(function add(object) {
778
+ objects.push(object);
779
+ if (isCollection(object)) {
780
+ object._objects.forEach(add);
781
+ }
782
+ });
783
+ objects.forEach((obj) => {
784
+ if (!isTextObject(obj)) {
785
+ return;
786
+ }
787
+ const { styles, fontFamily } = obj;
788
+ if (fontList[fontFamily] || !fontPaths[fontFamily]) {
789
+ return;
790
+ }
791
+ fontList[fontFamily] = true;
792
+ if (!styles) {
793
+ return;
794
+ }
795
+ Object.values(styles).forEach((styleRow) => {
796
+ Object.values(styleRow).forEach(({ fontFamily = '' }) => {
797
+ if (!fontList[fontFamily] && fontPaths[fontFamily]) {
798
+ fontList[fontFamily] = true;
799
+ }
800
+ });
801
+ });
802
+ });
803
+ const fontListMarkup = Object.keys(fontList)
804
+ .map((fontFamily) => `\t\t@font-face {\n\t\t\tfont-family: '${fontFamily}';\n\t\t\tsrc: url('${fontPaths[fontFamily]}');\n\t\t}\n`)
805
+ .join('');
806
+ if (fontListMarkup) {
807
+ return `\t<style type="text/css"><![CDATA[\n${fontListMarkup}]]></style>\n`;
808
+ }
809
+ return '';
810
+ }
811
+ /**
812
+ * @private
813
+ */
814
+ _setSVGObjects(markup, reviver) {
815
+ this.forEachObject((fabricObject) => {
816
+ if (fabricObject.excludeFromExport) {
817
+ return;
818
+ }
819
+ this._setSVGObject(markup, fabricObject, reviver);
820
+ });
821
+ }
822
+ /**
823
+ * This is its own function because the Canvas ( non static ) requires extra code here
824
+ * @private
825
+ */
826
+ _setSVGObject(markup, instance, reviver) {
827
+ markup.push(instance.toSVG(reviver));
828
+ }
829
+ /**
830
+ * @private
831
+ */
832
+ _setSVGBgOverlayImage(markup, property, reviver) {
833
+ const bgOrOverlay = this[property];
834
+ if (bgOrOverlay && !bgOrOverlay.excludeFromExport && bgOrOverlay.toSVG) {
835
+ markup.push(bgOrOverlay.toSVG(reviver));
836
+ }
837
+ }
838
+ /**
839
+ * @TODO this seems to handle patterns but fail at gradients.
840
+ * @private
841
+ */
842
+ _setSVGBgOverlayColor(markup, property) {
843
+ const filler = this[`${property}Color`];
844
+ if (!filler) {
845
+ return;
846
+ }
847
+ if (isFiller(filler)) {
848
+ const repeat = filler.repeat || '', finalWidth = this.width, finalHeight = this.height, shouldInvert = this[`${property}Vpt`], additionalTransform = shouldInvert
849
+ ? matrixToSVG(invertTransform(this.viewportTransform))
850
+ : '';
851
+ markup.push(`<rect transform="${additionalTransform} translate(${finalWidth / 2},${finalHeight / 2})" x="${filler.offsetX - finalWidth / 2}" y="${filler.offsetY - finalHeight / 2}" width="${(repeat === 'repeat-y' || repeat === 'no-repeat') && isPattern(filler)
852
+ ? filler.source.width
853
+ : finalWidth}" height="${(repeat === 'repeat-x' || repeat === 'no-repeat') && isPattern(filler)
854
+ ? filler.source.height
855
+ : finalHeight}" fill="url(#SVGID_${filler.id})"></rect>\n`);
856
+ }
857
+ else {
858
+ markup.push('<rect x="0" y="0" width="100%" height="100%" ', 'fill="', filler, '"', '></rect>\n');
859
+ }
860
+ }
861
+ /* _TO_SVG_END_ */
862
+ /**
863
+ * Populates canvas with data from the specified JSON.
864
+ * JSON format must conform to the one of {@link fabric.Canvas#toJSON}
865
+ *
866
+ * **IMPORTANT**: It is recommended to abort loading tasks before calling this method to prevent race conditions and unnecessary networking
867
+ *
868
+ * @param {String|Object} json JSON string or object
869
+ * @param {Function} [reviver] Method for further parsing of JSON elements, called after each fabric object created.
870
+ * @param {Object} [options] options
871
+ * @param {AbortSignal} [options.signal] see https://developer.mozilla.org/en-US/docs/Web/API/AbortController/signal
872
+ * @return {Promise<Canvas | StaticCanvas>} instance
873
+ * @tutorial {@link http://fabricjs.com/fabric-intro-part-3#deserialization}
874
+ * @see {@link http://jsfiddle.net/fabricjs/fmgXt/|jsFiddle demo}
875
+ * @example <caption>loadFromJSON</caption>
876
+ * canvas.loadFromJSON(json).then((canvas) => canvas.requestRenderAll());
877
+ * @example <caption>loadFromJSON with reviver</caption>
878
+ * canvas.loadFromJSON(json, function(o, object) {
879
+ * // `o` = json object
880
+ * // `object` = fabric.Object instance
881
+ * // ... do some stuff ...
882
+ * }).then((canvas) => {
883
+ * ... canvas is restored, add your code.
884
+ * });
885
+ *
886
+ */
887
+ loadFromJSON(json, reviver, { signal } = {}) {
888
+ if (!json) {
889
+ return Promise.reject(new FabricError('`json` is undefined'));
890
+ }
891
+ // parse json if it wasn't already
892
+ const serialized = typeof json === 'string' ? JSON.parse(json) : json;
893
+ const { objects = [], backgroundImage, background, overlayImage, overlay, clipPath, } = serialized;
894
+ const renderOnAddRemove = this.renderOnAddRemove;
895
+ this.renderOnAddRemove = false;
896
+ return Promise.all([
897
+ enlivenObjects(objects, {
898
+ reviver,
899
+ signal,
900
+ }),
901
+ enlivenObjectEnlivables({
902
+ backgroundImage,
903
+ backgroundColor: background,
904
+ overlayImage,
905
+ overlayColor: overlay,
906
+ clipPath,
907
+ }, { signal }),
908
+ ]).then(([enlived, enlivedMap]) => {
909
+ this.clear();
910
+ this.add(...enlived);
911
+ this.set(serialized);
912
+ this.set(enlivedMap);
913
+ this.renderOnAddRemove = renderOnAddRemove;
914
+ return this;
915
+ });
916
+ }
917
+ /**
918
+ * Clones canvas instance
919
+ * @param {string[]} [properties] Array of properties to include in the cloned canvas and children
920
+ */
921
+ clone(properties) {
922
+ const data = this.toObject(properties);
923
+ const canvas = this.cloneWithoutData();
924
+ return canvas.loadFromJSON(data);
925
+ }
926
+ /**
927
+ * Clones canvas instance without cloning existing data.
928
+ * This essentially copies canvas dimensions since loadFromJSON does not affect canvas size.
929
+ */
930
+ cloneWithoutData() {
931
+ const el = createCanvasElementFor(this);
932
+ return new this.constructor(el);
933
+ }
934
+ /**
935
+ * Exports canvas element to a dataurl image. Note that when multiplier is used, cropping is scaled appropriately
936
+ * @param {Object} [options] Options object
937
+ * @param {String} [options.format=png] The format of the output image. Either "jpeg" or "png"
938
+ * @param {Number} [options.quality=1] Quality level (0..1). Only used for jpeg.
939
+ * @param {Number} [options.multiplier=1] Multiplier to scale by, to have consistent
940
+ * @param {Number} [options.left] Cropping left offset. Introduced in v1.2.14
941
+ * @param {Number} [options.top] Cropping top offset. Introduced in v1.2.14
942
+ * @param {Number} [options.width] Cropping width. Introduced in v1.2.14
943
+ * @param {Number} [options.height] Cropping height. Introduced in v1.2.14
944
+ * @param {Boolean} [options.enableRetinaScaling] Enable retina scaling for clone image. Introduce in 2.0.0
945
+ * @param {(object: fabric.Object) => boolean} [options.filter] Function to filter objects.
946
+ * @return {String} Returns a data: URL containing a representation of the object in the format specified by options.format
947
+ * @see {@link https://jsfiddle.net/xsjua1rd/ demo}
948
+ * @example <caption>Generate jpeg dataURL with lower quality</caption>
949
+ * var dataURL = canvas.toDataURL({
950
+ * format: 'jpeg',
951
+ * quality: 0.8
952
+ * });
953
+ * @example <caption>Generate cropped png dataURL (clipping of canvas)</caption>
954
+ * var dataURL = canvas.toDataURL({
955
+ * format: 'png',
956
+ * left: 100,
957
+ * top: 100,
958
+ * width: 200,
959
+ * height: 200
960
+ * });
961
+ * @example <caption>Generate double scaled png dataURL</caption>
962
+ * var dataURL = canvas.toDataURL({
963
+ * format: 'png',
964
+ * multiplier: 2
965
+ * });
966
+ * @example <caption>Generate dataURL with objects that overlap a specified object</caption>
967
+ * var myObject;
968
+ * var dataURL = canvas.toDataURL({
969
+ * filter: (object) => object.isContainedWithinObject(myObject) || object.intersectsWithObject(myObject)
970
+ * });
971
+ */
972
+ toDataURL(options = {}) {
973
+ const { format = 'png', quality = 1, multiplier = 1, enableRetinaScaling = false, } = options;
974
+ const finalMultiplier = multiplier * (enableRetinaScaling ? this.getRetinaScaling() : 1);
975
+ return toDataURL(this.toCanvasElement(finalMultiplier, options), format, quality);
976
+ }
977
+ toBlob(options = {}) {
978
+ const { format = 'png', quality = 1, multiplier = 1, enableRetinaScaling = false, } = options;
979
+ const finalMultiplier = multiplier * (enableRetinaScaling ? this.getRetinaScaling() : 1);
980
+ return toBlob(this.toCanvasElement(finalMultiplier, options), format, quality);
981
+ }
982
+ /**
983
+ * Create a new HTMLCanvas element painted with the current canvas content.
984
+ * No need to resize the actual one or repaint it.
985
+ * Will transfer object ownership to a new canvas, paint it, and set everything back.
986
+ * This is an intermediary step used to get to a dataUrl but also it is useful to
987
+ * create quick image copies of a canvas without passing for the dataUrl string
988
+ * @param {Number} [multiplier] a zoom factor.
989
+ * @param {Object} [options] Cropping informations
990
+ * @param {Number} [options.left] Cropping left offset.
991
+ * @param {Number} [options.top] Cropping top offset.
992
+ * @param {Number} [options.width] Cropping width.
993
+ * @param {Number} [options.height] Cropping height.
994
+ * @param {(object: fabric.Object) => boolean} [options.filter] Function to filter objects.
995
+ */
996
+ toCanvasElement(multiplier = 1, { width, height, left, top, filter } = {}) {
997
+ const scaledWidth = (width || this.width) * multiplier, scaledHeight = (height || this.height) * multiplier, zoom = this.getZoom(), originalWidth = this.width, originalHeight = this.height, originalSkipControlsDrawing = this.skipControlsDrawing, newZoom = zoom * multiplier, vp = this.viewportTransform, translateX = (vp[4] - (left || 0)) * multiplier, translateY = (vp[5] - (top || 0)) * multiplier, newVp = [newZoom, 0, 0, newZoom, translateX, translateY], originalRetina = this.enableRetinaScaling, canvasEl = createCanvasElementFor({
998
+ width: scaledWidth,
999
+ height: scaledHeight,
1000
+ }), objectsToRender = filter
1001
+ ? this._objects.filter((obj) => filter(obj))
1002
+ : this._objects;
1003
+ this.enableRetinaScaling = false;
1004
+ this.viewportTransform = newVp;
1005
+ this.width = scaledWidth;
1006
+ this.height = scaledHeight;
1007
+ this.skipControlsDrawing = true;
1008
+ this.calcViewportBoundaries();
1009
+ this.renderCanvas(canvasEl.getContext('2d'), objectsToRender);
1010
+ this.viewportTransform = vp;
1011
+ this.width = originalWidth;
1012
+ this.height = originalHeight;
1013
+ this.calcViewportBoundaries();
1014
+ this.enableRetinaScaling = originalRetina;
1015
+ this.skipControlsDrawing = originalSkipControlsDrawing;
1016
+ return canvasEl;
1017
+ }
1018
+ /**
1019
+ * Waits until rendering has settled to destroy the canvas
1020
+ * @returns {Promise<boolean>} a promise resolving to `true` once the canvas has been destroyed or to `false` if the canvas has was already destroyed
1021
+ * @throws if aborted by a consequent call
1022
+ */
1023
+ dispose() {
1024
+ !this.disposed &&
1025
+ this.elements.cleanupDOM({ width: this.width, height: this.height });
1026
+ runningAnimations.cancelByCanvas(this);
1027
+ this.disposed = true;
1028
+ return new Promise((resolve, reject) => {
1029
+ const task = () => {
1030
+ this.destroy();
1031
+ resolve(true);
1032
+ };
1033
+ task.kill = reject;
1034
+ if (this.__cleanupTask) {
1035
+ this.__cleanupTask.kill('aborted');
1036
+ }
1037
+ if (this.destroyed) {
1038
+ resolve(false);
1039
+ }
1040
+ else if (this.nextRenderHandle) {
1041
+ this.__cleanupTask = task;
1042
+ }
1043
+ else {
1044
+ task();
1045
+ }
1046
+ });
1047
+ }
1048
+ /**
1049
+ * Clears the canvas element, disposes objects and frees resources.
1050
+ *
1051
+ * Invoked as part of the **async** operation of {@link dispose}.
1052
+ *
1053
+ * **CAUTION**:
1054
+ *
1055
+ * This method is **UNSAFE**.
1056
+ * You may encounter a race condition using it if there's a requested render.
1057
+ * Call this method only if you are sure rendering has settled.
1058
+ * Consider using {@link dispose} as it is **SAFE**
1059
+ *
1060
+ * @private
1061
+ */
1062
+ destroy() {
1063
+ this.destroyed = true;
1064
+ this.cancelRequestedRender();
1065
+ this.forEachObject((object) => object.dispose());
1066
+ this._objects = [];
1067
+ if (this.backgroundImage) {
1068
+ this.backgroundImage.dispose();
1069
+ }
1070
+ this.backgroundImage = undefined;
1071
+ if (this.overlayImage) {
1072
+ this.overlayImage.dispose();
1073
+ }
1074
+ this.overlayImage = undefined;
1075
+ this.elements.dispose();
1076
+ }
1077
+ /**
1078
+ * Returns a string representation of an instance
1079
+ * @return {String} string representation of an instance
1080
+ */
1081
+ toString() {
1082
+ return `#<Canvas (${this.complexity()}): { objects: ${this._objects.length} }>`;
1083
+ }
1084
+ }
1085
+ //# sourceMappingURL=StaticCanvas.js.map