fabric 6.0.0-beta1 → 6.0.0-beta10

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 (455) hide show
  1. package/.eslintignore +3 -0
  2. package/.eslintrc.js +8 -0
  3. package/.gitpod.yml +17 -1
  4. package/.prettierignore +3 -0
  5. package/CHANGELOG.md +124 -0
  6. package/CONTRIBUTING.md +84 -78
  7. package/README.md +31 -15
  8. package/babel-jest.config.js +6 -0
  9. package/dist/fabric.d.ts +53 -1020
  10. package/dist/{index.cjs → index.js} +21998 -21573
  11. package/dist/index.js.map +1 -0
  12. package/dist/index.min.js +1 -1
  13. package/dist/index.mjs +21988 -21567
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/index.node.cjs +22836 -22390
  16. package/dist/index.node.cjs.map +1 -1
  17. package/dist/index.node.d.ts +9 -4
  18. package/dist/index.node.mjs +22827 -22385
  19. package/dist/index.node.mjs.map +1 -1
  20. package/dist/src/{util/class_registry.d.ts → ClassRegistry.d.ts} +2 -3
  21. package/dist/src/Collection.d.ts +11 -1
  22. package/dist/src/EventTypeDefs.d.ts +17 -16
  23. package/dist/src/Intersection.d.ts +12 -0
  24. package/dist/src/Observable.d.ts +11 -5
  25. package/dist/src/{Pattern.d.ts → Pattern/Pattern.d.ts} +23 -28
  26. package/dist/src/Pattern/index.d.ts +3 -0
  27. package/dist/src/Pattern/types.d.ts +9 -0
  28. package/dist/src/Point.d.ts +42 -42
  29. package/dist/src/Shadow.d.ts +12 -3
  30. package/dist/src/brushes/BaseBrush.d.ts +1 -5
  31. package/dist/src/brushes/CircleBrush.d.ts +2 -7
  32. package/dist/src/brushes/CircleBrush.test.d.ts +2 -0
  33. package/dist/src/brushes/PatternBrush.d.ts +2 -2
  34. package/dist/src/brushes/PencilBrush.d.ts +8 -8
  35. package/dist/src/brushes/SprayBrush.d.ts +2 -7
  36. package/dist/src/brushes/typedefs.d.ts +18 -0
  37. package/dist/src/cache.d.ts +2 -1
  38. package/dist/src/canvas/Canvas.d.ts +19 -222
  39. package/dist/src/canvas/DOMManagers/CanvasDOMManager.d.ts +29 -0
  40. package/dist/src/canvas/DOMManagers/StaticCanvasDOMManager.d.ts +29 -0
  41. package/dist/src/canvas/DOMManagers/util.d.ts +24 -0
  42. package/dist/src/canvas/DOMManagers/util.spec.d.ts +2 -0
  43. package/dist/src/canvas/SelectableCanvas.d.ts +80 -80
  44. package/dist/src/canvas/StaticCanvas.d.ts +42 -46
  45. package/dist/src/canvas/TextEditingManager.d.ts +5 -1
  46. package/dist/src/color/Color.d.ts +1 -23
  47. package/dist/src/color/constants.d.ts +96 -14
  48. package/dist/src/color/typedefs.d.ts +16 -0
  49. package/dist/src/color/util.d.ts +18 -3
  50. package/dist/src/constants.d.ts +8 -1
  51. package/dist/src/controls/Control.d.ts +14 -13
  52. package/dist/src/controls/changeWidth.d.ts +1 -1
  53. package/dist/src/controls/{default_controls.d.ts → commonControls.d.ts} +1 -23
  54. package/dist/src/controls/{controls.render.d.ts → controlRendering.d.ts} +6 -6
  55. package/dist/src/controls/drag.d.ts +1 -1
  56. package/dist/src/controls/fireEvent.d.ts +3 -0
  57. package/dist/src/controls/index.d.ts +13 -0
  58. package/dist/src/controls/rotate.d.ts +1 -1
  59. package/dist/src/controls/scale.d.ts +2 -2
  60. package/dist/src/controls/scaleSkew.d.ts +2 -2
  61. package/dist/src/controls/skew.d.ts +1 -1
  62. package/dist/src/controls/util.d.ts +2 -2
  63. package/dist/src/controls/wrapWithFireEvent.d.ts +1 -1
  64. package/dist/src/controls/wrapWithFixedAnchor.d.ts +1 -1
  65. package/dist/src/env/browser.d.ts +1 -1
  66. package/dist/src/env/index.d.ts +25 -4
  67. package/dist/src/env/node.d.ts +4 -1
  68. package/dist/src/env/types.d.ts +5 -5
  69. package/dist/src/filters/BaseFilter.d.ts +24 -20
  70. package/dist/src/filters/BlendColor.d.ts +18 -17
  71. package/dist/src/filters/BlendImage.d.ts +13 -10
  72. package/dist/src/filters/Blur.d.ts +4 -2
  73. package/dist/src/filters/Boilerplate.d.ts +6 -4
  74. package/dist/src/filters/Brightness.d.ts +4 -2
  75. package/dist/src/filters/Canvas2dFilterBackend.d.ts +1 -1
  76. package/dist/src/filters/ColorMatrix.d.ts +4 -2
  77. package/dist/src/filters/ColorMatrixFilters.d.ts +128 -760
  78. package/dist/src/filters/Composed.d.ts +7 -8
  79. package/dist/src/filters/Contrast.d.ts +4 -2
  80. package/dist/src/filters/Convolute.d.ts +6 -5
  81. package/dist/src/filters/FilterBackend.d.ts +2 -1
  82. package/dist/src/filters/GLProbes/GLProbe.d.ts +7 -0
  83. package/dist/src/filters/GLProbes/NodeGLProbe.d.ts +11 -0
  84. package/dist/src/filters/GLProbes/WebGLProbe.d.ts +20 -0
  85. package/dist/src/filters/Gamma.d.ts +6 -4
  86. package/dist/src/filters/Grayscale.d.ts +7 -5
  87. package/dist/src/filters/HueRotation.d.ts +3 -2
  88. package/dist/src/filters/Invert.d.ts +4 -2
  89. package/dist/src/filters/Noise.d.ts +4 -2
  90. package/dist/src/filters/Pixelate.d.ts +4 -2
  91. package/dist/src/filters/RemoveColor.d.ts +4 -2
  92. package/dist/src/filters/Resize.d.ts +7 -4
  93. package/dist/src/filters/Saturation.d.ts +4 -2
  94. package/dist/src/filters/Vibrance.d.ts +4 -2
  95. package/dist/src/filters/WebGLFilterBackend.d.ts +8 -6
  96. package/dist/src/filters/filters.d.ts +21 -0
  97. package/dist/src/filters/index.d.ts +7 -0
  98. package/dist/src/filters/shaders/baseFilter.d.ts +4 -0
  99. package/dist/src/filters/shaders/blendColor.d.ts +13 -0
  100. package/dist/src/filters/shaders/blendImage.d.ts +3 -0
  101. package/dist/src/filters/shaders/blur.d.ts +2 -0
  102. package/dist/src/filters/shaders/brightness.d.ts +2 -0
  103. package/dist/src/filters/shaders/colorMatrix.d.ts +2 -0
  104. package/dist/src/filters/shaders/constrast.d.ts +2 -0
  105. package/dist/src/filters/shaders/convolute.d.ts +11 -0
  106. package/dist/src/filters/shaders/gamma.d.ts +2 -0
  107. package/dist/src/filters/shaders/grayscale.d.ts +3 -0
  108. package/dist/src/filters/shaders/invert.d.ts +2 -0
  109. package/dist/src/filters/shaders/noise.d.ts +2 -0
  110. package/dist/src/filters/shaders/pixelate.d.ts +2 -0
  111. package/dist/src/filters/shaders/removeColor.d.ts +2 -0
  112. package/dist/src/filters/shaders/saturation.d.ts +2 -0
  113. package/dist/src/filters/shaders/vibrance.d.ts +2 -0
  114. package/dist/src/filters/typedefs.d.ts +1 -2
  115. package/dist/src/filters/utils.d.ts +3 -0
  116. package/dist/src/gradient/Gradient.d.ts +3 -2
  117. package/dist/src/gradient/index.d.ts +3 -0
  118. package/dist/src/gradient/parser/misc.d.ts +1 -1
  119. package/dist/src/gradient/parser/parseColorStops.d.ts +2 -5
  120. package/dist/src/gradient/parser/parseCoords.d.ts +1 -1
  121. package/dist/src/gradient/typedefs.d.ts +2 -2
  122. package/dist/src/parser/applyViewboxTransform.d.ts +1 -1
  123. package/dist/src/parser/constants.d.ts +2 -3
  124. package/dist/src/parser/doesSomeParentMatch.d.ts +1 -1
  125. package/dist/src/parser/elementById.d.ts +1 -1
  126. package/dist/src/parser/elementMatchesRule.d.ts +1 -1
  127. package/dist/src/parser/elements_parser.d.ts +1 -1
  128. package/dist/src/parser/getCSSRules.d.ts +1 -1
  129. package/dist/src/parser/getSvgRegex.d.ts +1 -1
  130. package/dist/src/parser/index.d.ts +9 -0
  131. package/dist/src/parser/loadSVGFromString.d.ts +11 -5
  132. package/dist/src/parser/loadSVGFromURL.d.ts +11 -5
  133. package/dist/src/parser/parseSVGDocument.d.ts +16 -8
  134. package/dist/src/parser/parseTransformAttribute.d.ts +3 -2
  135. package/dist/src/parser/selectorMatches.d.ts +1 -1
  136. package/dist/src/parser/typedefs.d.ts +9 -0
  137. package/dist/src/shapes/ActiveSelection.d.ts +20 -3
  138. package/dist/src/shapes/Circle.d.ts +25 -6
  139. package/dist/src/shapes/Ellipse.d.ts +22 -12
  140. package/dist/src/shapes/Group.d.ts +55 -29
  141. package/dist/src/shapes/IText/DraggableTextDelegate.d.ts +1 -1
  142. package/dist/src/shapes/IText/IText.d.ts +42 -28
  143. package/dist/src/shapes/IText/ITextBehavior.d.ts +8 -6
  144. package/dist/src/shapes/IText/ITextClickBehavior.d.ts +6 -14
  145. package/dist/src/shapes/IText/ITextKeyBehavior.d.ts +6 -4
  146. package/dist/src/shapes/Image.d.ts +43 -17
  147. package/dist/src/shapes/Line.d.ts +31 -27
  148. package/dist/src/shapes/Object/AnimatableObject.d.ts +3 -3
  149. package/dist/src/shapes/Object/FabricObject.d.ts +6 -4
  150. package/dist/src/shapes/Object/FabricObjectSVGExportMixin.d.ts +1 -1
  151. package/dist/src/shapes/Object/InteractiveObject.d.ts +52 -38
  152. package/dist/src/shapes/Object/Object.d.ts +57 -364
  153. package/dist/src/shapes/Object/ObjectGeometry.d.ts +3 -19
  154. package/dist/src/shapes/Object/ObjectOrigin.d.ts +6 -75
  155. package/dist/src/shapes/Object/StackedObject.d.ts +14 -4
  156. package/dist/src/shapes/Object/defaultValues.d.ts +71 -72
  157. package/dist/src/shapes/Object/types/BaseProps.d.ts +84 -0
  158. package/dist/src/shapes/Object/types/BorderProps.d.ts +37 -0
  159. package/dist/src/shapes/Object/types/ControlProps.d.ts +62 -0
  160. package/dist/src/shapes/Object/types/FabricObjectProps.d.ts +96 -0
  161. package/dist/src/shapes/Object/types/FillStrokeProps.d.ts +80 -0
  162. package/dist/src/shapes/Object/types/LockInteractionProps.d.ts +51 -0
  163. package/dist/src/shapes/Object/types/ObjectProps.d.ts +42 -0
  164. package/dist/src/shapes/Object/types/SerializedObjectProps.d.ts +66 -0
  165. package/dist/src/shapes/Object/types/index.d.ts +6 -0
  166. package/dist/src/shapes/Path.d.ts +129 -38
  167. package/dist/src/shapes/Polygon.d.ts +5 -2
  168. package/dist/src/shapes/Polyline.d.ts +29 -12
  169. package/dist/src/shapes/Rect.d.ts +27 -7
  170. package/dist/src/shapes/Text/StyledText.d.ts +19 -14
  171. package/dist/src/shapes/Text/Text.d.ts +74 -42
  172. package/dist/src/shapes/Text/TextSVGExportMixin.d.ts +1 -1
  173. package/dist/src/shapes/Text/constants.d.ts +13 -0
  174. package/dist/src/shapes/Textbox.d.ts +44 -10
  175. package/dist/src/shapes/Triangle.d.ts +12 -3
  176. package/dist/src/typedefs.d.ts +27 -24
  177. package/dist/src/util/animation/AnimationBase.d.ts +1 -1
  178. package/dist/src/util/animation/AnimationFrameProvider.d.ts +0 -5
  179. package/dist/src/util/animation/ArrayAnimation.d.ts +1 -1
  180. package/dist/src/util/animation/ColorAnimation.d.ts +1 -1
  181. package/dist/src/util/animation/ValueAnimation.d.ts +1 -1
  182. package/dist/src/util/animation/animate.d.ts +2 -2
  183. package/dist/src/util/animation/easing.d.ts +1 -1
  184. package/dist/src/util/animation/index.d.ts +3 -0
  185. package/dist/src/util/animation/types.d.ts +1 -1
  186. package/dist/src/util/applyMixins.d.ts +1 -1
  187. package/dist/src/util/dom_misc.d.ts +3 -31
  188. package/dist/src/util/dom_request.d.ts +1 -1
  189. package/dist/src/util/index.d.ts +36 -0
  190. package/dist/src/util/internals/cleanupSvgAttribute.d.ts +2 -0
  191. package/dist/src/util/internals/cleanupSvgAttribute.test.d.ts +2 -0
  192. package/dist/src/util/internals/cloneDeep.test.d.ts +2 -0
  193. package/dist/src/util/internals/getRandomInt.test.d.ts +2 -0
  194. package/dist/src/util/misc/boundingBoxFromPoints.d.ts +4 -4
  195. package/dist/src/util/misc/dom.d.ts +1 -1
  196. package/dist/src/util/misc/findScaleTo.d.ts +7 -16
  197. package/dist/src/util/misc/groupSVGElements.d.ts +1 -1
  198. package/dist/src/util/misc/isTransparent.d.ts +3 -3
  199. package/dist/src/util/misc/matrix.d.ts +87 -11
  200. package/dist/src/util/misc/objectEnlive.d.ts +5 -20
  201. package/dist/src/util/misc/objectTransforms.d.ts +1 -1
  202. package/dist/src/util/misc/pick.d.ts +1 -0
  203. package/dist/src/util/misc/planeChange.d.ts +2 -5
  204. package/dist/src/util/misc/projectStroke/StrokeLineCapProjections.d.ts +4 -3
  205. package/dist/src/util/misc/projectStroke/StrokeLineJoinProjections.d.ts +4 -3
  206. package/dist/src/util/misc/projectStroke/StrokeProjectionsBase.d.ts +4 -3
  207. package/dist/src/util/misc/projectStroke/index.d.ts +4 -3
  208. package/dist/src/util/misc/projectStroke/types.d.ts +3 -3
  209. package/dist/src/util/misc/resolveOrigin.d.ts +1 -1
  210. package/dist/src/util/misc/svgParsing.d.ts +4 -12
  211. package/dist/src/util/misc/vectors.d.ts +4 -3
  212. package/dist/src/util/path/index.d.ts +96 -0
  213. package/dist/src/util/path/regex.d.ts +2 -0
  214. package/dist/src/util/path/typechecks.d.ts +24 -0
  215. package/dist/src/util/path/typedefs.d.ts +220 -0
  216. package/dist/src/util/transform_matrix_removal.d.ts +1 -1
  217. package/dist/src/util/{types.d.ts → typeAssertions.d.ts} +3 -3
  218. package/e2e/site/index.html +25 -0
  219. package/e2e/utils/objects.ts +36 -0
  220. package/fabric.ts +61 -416
  221. package/index.node.ts +12 -12
  222. package/jest.config.js +194 -0
  223. package/lib/aligning_guidelines.js +2 -2
  224. package/package.json +36 -17
  225. package/playwright.config.ts +64 -0
  226. package/rollup.config.mjs +27 -7
  227. package/scripts/git.mjs +36 -0
  228. package/scripts/index.mjs +9 -124
  229. package/scripts/sandbox.mjs +149 -0
  230. package/src/{util/class_registry.ts → ClassRegistry.ts} +11 -9
  231. package/src/Collection.ts +37 -2
  232. package/src/EventTypeDefs.ts +65 -61
  233. package/src/Intersection.ts +54 -25
  234. package/src/Observable.ts +11 -5
  235. package/src/{Pattern.ts → Pattern/Pattern.ts} +39 -43
  236. package/src/Pattern/index.ts +2 -0
  237. package/src/Pattern/types.ts +17 -0
  238. package/src/Point.ts +43 -43
  239. package/src/Shadow.ts +28 -29
  240. package/src/brushes/BaseBrush.ts +1 -3
  241. package/src/brushes/CircleBrush.test.ts +11 -0
  242. package/src/brushes/CircleBrush.ts +6 -11
  243. package/src/brushes/PatternBrush.ts +2 -2
  244. package/src/brushes/PencilBrush.ts +10 -10
  245. package/src/brushes/SprayBrush.ts +6 -11
  246. package/src/brushes/typedefs.ts +18 -0
  247. package/src/cache.ts +2 -1
  248. package/src/canvas/Canvas.ts +170 -244
  249. package/src/canvas/DOMManagers/CanvasDOMManager.ts +124 -0
  250. package/src/canvas/DOMManagers/StaticCanvasDOMManager.ts +80 -0
  251. package/src/canvas/DOMManagers/util.spec.ts +26 -0
  252. package/src/canvas/DOMManagers/util.ts +98 -0
  253. package/src/canvas/SelectableCanvas.ts +232 -362
  254. package/src/canvas/StaticCanvas.ts +92 -167
  255. package/src/canvas/TextEditingManager.ts +24 -2
  256. package/src/canvas/canvas_gestures.mixin.ts +10 -10
  257. package/src/color/Color.ts +51 -135
  258. package/src/color/color_map.ts +13 -13
  259. package/src/color/constants.ts +98 -17
  260. package/src/color/typedefs.ts +18 -0
  261. package/src/color/util.ts +68 -7
  262. package/src/constants.ts +11 -1
  263. package/src/controls/Control.ts +26 -18
  264. package/src/controls/changeWidth.ts +5 -4
  265. package/src/controls/{default_controls.ts → commonControls.ts} +2 -29
  266. package/src/controls/{controls.render.ts → controlRendering.ts} +5 -5
  267. package/src/controls/drag.ts +5 -4
  268. package/src/{util → controls}/fireEvent.ts +4 -1
  269. package/src/controls/index.ts +22 -0
  270. package/src/controls/polyControl.ts +4 -4
  271. package/src/controls/rotate.ts +1 -1
  272. package/src/controls/scale.ts +2 -2
  273. package/src/controls/scaleSkew.ts +2 -2
  274. package/src/controls/skew.ts +4 -3
  275. package/src/controls/util.ts +6 -5
  276. package/src/controls/wrapWithFireEvent.ts +2 -2
  277. package/src/controls/wrapWithFixedAnchor.ts +1 -1
  278. package/src/env/browser.ts +6 -2
  279. package/src/env/index.ts +27 -8
  280. package/src/env/node.ts +32 -26
  281. package/src/env/types.ts +5 -5
  282. package/src/filters/BaseFilter.ts +69 -69
  283. package/src/filters/BlendColor.ts +41 -80
  284. package/src/filters/BlendImage.ts +34 -58
  285. package/src/filters/Blur.ts +16 -37
  286. package/src/filters/Boilerplate.ts +25 -22
  287. package/src/filters/Brightness.ts +15 -23
  288. package/src/filters/Canvas2dFilterBackend.ts +1 -1
  289. package/src/filters/ColorMatrix.ts +17 -26
  290. package/src/filters/ColorMatrixFilters.ts +17 -44
  291. package/src/filters/Composed.ts +11 -18
  292. package/src/filters/Contrast.ts +13 -23
  293. package/src/filters/Convolute.ts +15 -170
  294. package/src/filters/FilterBackend.ts +10 -4
  295. package/src/filters/GLProbes/GLProbe.ts +7 -0
  296. package/src/filters/GLProbes/NodeGLProbe.ts +15 -0
  297. package/src/filters/{WebGLProbe.ts → GLProbes/WebGLProbe.ts} +9 -24
  298. package/src/filters/Gamma.ts +25 -40
  299. package/src/filters/Grayscale.ts +17 -50
  300. package/src/filters/HueRotation.ts +12 -14
  301. package/src/filters/Invert.ts +16 -32
  302. package/src/filters/Noise.ts +15 -28
  303. package/src/filters/Pixelate.ts +15 -31
  304. package/src/filters/RemoveColor.ts +16 -27
  305. package/src/filters/Resize.ts +72 -72
  306. package/src/filters/Saturation.ts +16 -27
  307. package/src/filters/Vibrance.ts +15 -28
  308. package/src/filters/WebGLFilterBackend.ts +55 -29
  309. package/src/filters/filters.ts +28 -0
  310. package/src/filters/index.ts +12 -0
  311. package/src/filters/shaders/baseFilter.ts +17 -0
  312. package/src/filters/shaders/blendColor.ts +33 -0
  313. package/src/filters/shaders/blendImage.ts +32 -0
  314. package/src/filters/shaders/blur.ts +24 -0
  315. package/src/filters/shaders/brightness.ts +11 -0
  316. package/src/filters/shaders/colorMatrix.ts +12 -0
  317. package/src/filters/shaders/constrast.ts +11 -0
  318. package/src/filters/shaders/convolute.ts +154 -0
  319. package/src/filters/shaders/gamma.ts +15 -0
  320. package/src/filters/shaders/grayscale.ts +36 -0
  321. package/src/filters/shaders/invert.ts +19 -0
  322. package/src/filters/shaders/noise.ts +16 -0
  323. package/src/filters/shaders/pixelate.ts +19 -0
  324. package/src/filters/shaders/removeColor.ts +13 -0
  325. package/src/filters/shaders/saturation.ts +15 -0
  326. package/src/filters/shaders/vibrance.ts +16 -0
  327. package/src/filters/typedefs.ts +1 -7
  328. package/src/filters/utils.ts +7 -0
  329. package/src/gradient/Gradient.ts +14 -6
  330. package/src/gradient/index.ts +2 -0
  331. package/src/gradient/parser/misc.ts +1 -1
  332. package/src/gradient/parser/parseColorStops.ts +2 -1
  333. package/src/gradient/parser/parseCoords.ts +2 -2
  334. package/src/gradient/typedefs.ts +2 -2
  335. package/src/parser/applyViewboxTransform.ts +29 -33
  336. package/src/parser/constants.ts +7 -9
  337. package/src/parser/doesSomeParentMatch.ts +7 -8
  338. package/src/parser/elementById.ts +5 -7
  339. package/src/parser/elementMatchesRule.ts +4 -7
  340. package/src/parser/elements_parser.ts +64 -97
  341. package/src/parser/getCSSRules.ts +17 -18
  342. package/src/parser/getGradientDefs.ts +4 -5
  343. package/src/parser/getSvgRegex.ts +1 -3
  344. package/src/parser/index.ts +8 -0
  345. package/src/parser/loadSVGFromString.ts +19 -16
  346. package/src/parser/loadSVGFromURL.ts +36 -29
  347. package/src/parser/normalizeValue.ts +8 -7
  348. package/src/parser/parsePointsAttribute.ts +2 -4
  349. package/src/parser/parseSVGDocument.ts +71 -59
  350. package/src/parser/parseTransformAttribute.ts +54 -115
  351. package/src/parser/parseUseDirectives.ts +20 -21
  352. package/src/parser/selectorMatches.ts +11 -11
  353. package/src/parser/setStrokeFillOpacity.ts +3 -3
  354. package/src/parser/typedefs.ts +13 -0
  355. package/src/shapes/ActiveSelection.ts +47 -12
  356. package/src/shapes/Circle.ts +74 -43
  357. package/src/shapes/Ellipse.ts +52 -29
  358. package/src/shapes/Group.ts +134 -84
  359. package/src/shapes/IText/DraggableTextDelegate.ts +23 -32
  360. package/src/shapes/IText/IText.ts +83 -53
  361. package/src/shapes/IText/ITextBehavior.ts +72 -54
  362. package/src/shapes/IText/ITextClickBehavior.ts +43 -72
  363. package/src/shapes/IText/ITextKeyBehavior.ts +68 -76
  364. package/src/shapes/IText/constants.ts +26 -20
  365. package/src/shapes/Image.ts +112 -53
  366. package/src/shapes/Line.ts +106 -150
  367. package/src/shapes/Object/AnimatableObject.ts +4 -7
  368. package/src/shapes/Object/FabricObject.ts +17 -7
  369. package/src/shapes/Object/FabricObjectSVGExportMixin.ts +3 -2
  370. package/src/shapes/Object/InteractiveObject.ts +94 -70
  371. package/src/shapes/Object/Object.ts +163 -470
  372. package/src/shapes/Object/ObjectGeometry.ts +12 -28
  373. package/src/shapes/Object/ObjectOrigin.ts +19 -96
  374. package/src/shapes/Object/StackedObject.ts +36 -21
  375. package/src/shapes/Object/defaultValues.ts +7 -9
  376. package/src/shapes/Object/types/BaseProps.ts +96 -0
  377. package/src/shapes/Object/types/BorderProps.ts +40 -0
  378. package/src/shapes/Object/types/ControlProps.ts +69 -0
  379. package/src/shapes/Object/types/FabricObjectProps.ts +111 -0
  380. package/src/shapes/Object/types/FillStrokeProps.ts +90 -0
  381. package/src/shapes/Object/types/LockInteractionProps.ts +57 -0
  382. package/src/shapes/Object/types/ObjectProps.ts +49 -0
  383. package/src/shapes/Object/types/SerializedObjectProps.ts +73 -0
  384. package/src/shapes/Object/types/index.ts +8 -0
  385. package/src/shapes/Path.ts +164 -125
  386. package/src/shapes/Polygon.ts +12 -9
  387. package/src/shapes/Polyline.ts +91 -60
  388. package/src/shapes/Rect.ts +55 -24
  389. package/src/shapes/Text/StyledText.ts +51 -47
  390. package/src/shapes/Text/Text.ts +228 -285
  391. package/src/shapes/Text/TextSVGExportMixin.ts +4 -3
  392. package/src/shapes/Text/constants.ts +111 -0
  393. package/src/shapes/Textbox.ts +108 -53
  394. package/src/shapes/Triangle.ts +28 -11
  395. package/src/typedefs.ts +29 -27
  396. package/src/util/animation/AnimationBase.ts +1 -1
  397. package/src/util/animation/AnimationFrameProvider.ts +3 -22
  398. package/src/util/animation/ArrayAnimation.ts +1 -1
  399. package/src/util/animation/ColorAnimation.ts +1 -1
  400. package/src/util/animation/ValueAnimation.ts +1 -1
  401. package/src/util/animation/animate.ts +2 -2
  402. package/src/util/animation/easing.ts +1 -1
  403. package/src/util/animation/index.ts +2 -0
  404. package/src/util/animation/types.ts +1 -1
  405. package/src/util/applyMixins.ts +1 -1
  406. package/src/util/dom_misc.ts +12 -106
  407. package/src/util/dom_request.ts +2 -2
  408. package/src/util/index.ts +106 -0
  409. package/src/util/internals/cleanupSvgAttribute.test.ts +16 -0
  410. package/src/util/internals/cleanupSvgAttribute.ts +8 -0
  411. package/src/util/internals/cloneDeep.test.ts +16 -0
  412. package/src/util/internals/getRandomInt.test.ts +33 -0
  413. package/src/util/misc/boundingBoxFromPoints.ts +5 -4
  414. package/src/util/misc/dom.ts +10 -5
  415. package/src/util/misc/findScaleTo.ts +7 -22
  416. package/src/util/misc/isTransparent.ts +9 -32
  417. package/src/util/misc/matrix.ts +161 -55
  418. package/src/util/misc/objectEnlive.ts +5 -20
  419. package/src/util/misc/objectTransforms.ts +3 -2
  420. package/src/util/misc/pick.ts +12 -0
  421. package/src/util/misc/planeChange.ts +4 -13
  422. package/src/util/misc/projectStroke/StrokeLineCapProjections.ts +4 -3
  423. package/src/util/misc/projectStroke/StrokeLineJoinProjections.ts +4 -8
  424. package/src/util/misc/projectStroke/StrokeProjectionsBase.ts +4 -3
  425. package/src/util/misc/projectStroke/index.ts +6 -4
  426. package/src/util/misc/projectStroke/types.ts +3 -3
  427. package/src/util/misc/resolveOrigin.ts +1 -1
  428. package/src/util/misc/svgParsing.ts +20 -30
  429. package/src/util/misc/textStyles.ts +5 -6
  430. package/src/util/misc/vectors.ts +4 -3
  431. package/src/util/{path.ts → path/index.ts} +417 -319
  432. package/src/util/path/regex.ts +39 -0
  433. package/src/util/path/typechecks.ts +145 -0
  434. package/src/util/path/typedefs.ts +305 -0
  435. package/src/util/transform_matrix_removal.ts +4 -3
  436. package/src/util/{types.ts → typeAssertions.ts} +3 -3
  437. package/dist/index.cjs.map +0 -1
  438. package/dist/src/filters/WebGLProbe.d.ts +0 -28
  439. package/dist/src/mixins/stateful.mixin.d.ts +0 -18
  440. package/dist/src/parser/parseElements.d.ts +0 -11
  441. package/dist/src/parser/rotateMatrix.d.ts +0 -2
  442. package/dist/src/parser/scaleMatrix.d.ts +0 -2
  443. package/dist/src/parser/skewMatrix.d.ts +0 -2
  444. package/dist/src/parser/translateMatrix.d.ts +0 -2
  445. package/dist/src/util/fireEvent.d.ts +0 -3
  446. package/dist/src/util/lang_class.d.ts +0 -12
  447. package/dist/src/util/path.d.ts +0 -108
  448. package/scripts/transform_files.mjs +0 -504
  449. package/src/mixins/stateful.mixin.ts +0 -104
  450. package/src/parser/parseElements.ts +0 -28
  451. package/src/parser/rotateMatrix.ts +0 -21
  452. package/src/parser/scaleMatrix.ts +0 -9
  453. package/src/parser/skewMatrix.ts +0 -6
  454. package/src/parser/translateMatrix.ts +0 -8
  455. package/src/util/lang_class.ts +0 -90
package/.eslintignore ADDED
@@ -0,0 +1,3 @@
1
+ src/mixins/eraser_brush.mixin.ts
2
+ src/util/lang_class.ts
3
+ src/parkinglot
package/.eslintrc.js CHANGED
@@ -1,10 +1,16 @@
1
1
  module.exports = {
2
2
  root: true,
3
3
  parser: '@typescript-eslint/parser',
4
+ parserOptions: {
5
+ project: true,
6
+ tsconfigRootDir: './',
7
+ },
4
8
  plugins: ['@typescript-eslint'],
5
9
  extends: [
6
10
  'eslint:recommended',
7
11
  'plugin:@typescript-eslint/recommended',
12
+ // this is too noisy for now
13
+ // 'plugin:@typescript-eslint/recommended-requiring-type-checking',
8
14
  'prettier',
9
15
  ],
10
16
  overrides: [
@@ -13,6 +19,8 @@ module.exports = {
13
19
  },
14
20
  ],
15
21
  rules: {
22
+ '@typescript-eslint/consistent-type-exports': 'error',
23
+ '@typescript-eslint/consistent-type-imports': 'error',
16
24
  '@typescript-eslint/ban-types': 1,
17
25
  '@typescript-eslint/ban-ts-comment': 1,
18
26
  'no-restricted-globals': [
package/.gitpod.yml CHANGED
@@ -1,2 +1,18 @@
1
+ # https://www.gitpod.io/docs/config-gitpod-file
2
+
1
3
  tasks:
2
- - init: npm install
4
+ - name: Build & Watch
5
+ init: npm install
6
+ command: npm run build -- -w -f
7
+
8
+ - name: Node
9
+ init: npm install
10
+ command: npm start node -- --no-watch
11
+
12
+ - name: Next.js
13
+ init: npm install
14
+ command: npm start next -- --no-watch
15
+
16
+ - name: Vanilla
17
+ init: npm install
18
+ command: npm start vanilla -- --no-watch
package/.prettierignore CHANGED
@@ -14,3 +14,6 @@ before_commit
14
14
  /dist/
15
15
  /lib/
16
16
  /test/
17
+ .next/
18
+ .parcel-cache/
19
+ /docs/
package/CHANGELOG.md CHANGED
@@ -2,6 +2,130 @@
2
2
 
3
3
  ## [next]
4
4
 
5
+ ## [6.0.0-beta10]
6
+
7
+ - chore(TS): Remove @ts-nocheck from Text class. [#9018](https://github.com/fabricjs/fabric.js/pull/9018)
8
+ - Fix(Textbox) minimum word width calculation across all lines [#9004](https://github.com/fabricjs/fabric.js/pull/9004)
9
+ - ci(): add Jest for the unit tests [#8919](https://github.com/fabricjs/fabric.js/pull/8919)
10
+ - ci(): Revert "invoke tests after changelog action (#8974)" [#9013](https://github.com/fabricjs/fabric.js/pull/9013)
11
+ - fix(IText): empty line selection [#9019](https://github.com/fabricjs/fabric.js/pull/9019)
12
+ - ci(): Added playwright testing [#8616](https://github.com/fabricjs/fabric.js/pull/8616)
13
+ - fix(IText): `exitEditing` should clear contextTop [#9020](https://github.com/fabricjs/fabric.js/pull/9020)
14
+ - ci(): prettier after changelog action [#9021](https://github.com/fabricjs/fabric.js/pull/9021)
15
+
16
+ ## [6.0.0-beta9]
17
+
18
+ - fix(fabric): Fix the serialization and registry dependency from minification [#9009](https://github.com/fabricjs/fabric.js/pull/9009)
19
+ - chore(TS): remove troublesome `AssertKeys` TS construct [#9012](https://github.com/fabricjs/fabric.js/pull/9012)
20
+ - fix(lib): fix aligning_guideline zoom [#8998](https://github.com/fabricjs/fabric.js/pull/8998)
21
+ - fix(IText): support control interaction in text editing mode [#8995](https://github.com/fabricjs/fabric.js/pull/8995)
22
+ - fix(Textbox): `splitByGrapheme` measurements infix length bug [#8990](https://github.com/fabricjs/fabric.js/pull/8990)
23
+ - patch(Text): styles es6 minor patch [#8988](https://github.com/fabricjs/fabric.js/pull/8988)
24
+
25
+ ## [6.0.0-beta8]
26
+
27
+ - BREAKING fix(IText): detect cursor from proper offsets, remove getLocalPointer from IText class [#8972](https://github.com/fabricjs/fabric.js/pull/8972)
28
+ - fix(Text): styles line break [#8973](https://github.com/fabricjs/fabric.js/pull/8973)
29
+ - fix(): regression to itext focusing from #8939 [#8970](https://github.com/fabricjs/fabric.js/pull/8970)
30
+ - ci(): warn build errors in dev mode [#8971](https://github.com/fabricjs/fabric.js/pull/8971)
31
+ - ci(): invoke tests after changelog action [#8974](https://github.com/fabricjs/fabric.js/pull/8974)
32
+ - chore(TS): Export more types [#8965](https://github.com/fabricjs/fabric.js/pull/8965)
33
+ - BREAKING: fabric.util.makeElementSelectable / fabric.util.makeElementUnselectable are removed [#8930](https://github.com/fabricjs/fabric.js/pull/8930)
34
+ - refactor(): Canvas DOM delegation to utility class [#8930](https://github.com/fabricjs/fabric.js/pull/8930)
35
+
36
+ ## [6.0.0-beta7]
37
+
38
+ - feat(): Export setFilterBackend and port the texture filtering option from fabric 5, exports some extra types [#8954](https://github.com/fabricjs/fabric.js/pull/8954)
39
+ - chore(): swap commonly used string with constants [#8933](https://github.com/fabricjs/fabric.js/pull/8933)
40
+ - chore(TS): Add more text types [#8941](https://github.com/fabricjs/fabric.js/pull/8941)
41
+ - ci(): fix changelog action race condition [#8949](https://github.com/fabricjs/fabric.js/pull/8949)
42
+ - ci(): automate PR changelog [#8938](https://github.com/fabricjs/fabric.js/pull/8938)
43
+ - chore(): move canvas click handler to TextManager [#8939](https://github.com/fabricjs/fabric.js/pull/8939)
44
+ - refactor(): write less bulky code [#8943](https://github.com/fabricjs/fabric.js/pull/8943)
45
+
46
+ ## [6.0.0-beta6]
47
+
48
+ - patch(): expose `Control#shouldActivate` [#8934](https://github.com/fabricjs/fabric.js/pull/8934)
49
+ - feat(Color) Improve regex for new standards, more documentation and code cleanup [#8916](https://github.com/fabricjs/fabric.js/pull/8916)
50
+ - fix(TS): extending canvas and object event types (`type` => `interface`) [#8926](https://github.com/fabricjs/fabric.js/pull/8926)
51
+ - chore(build) simple deps update [#8929](https://github.com/fabricjs/fabric.js/pull/8929)
52
+ - fix(Canvas): sync cleanup of dom elements in dispose [#8903](https://github.com/fabricjs/fabric.js/pull/8903)
53
+ - chore(TS): export util types [#8915](https://github.com/fabricjs/fabric.js/pull/8915)
54
+ - chore(TS): change enums with types [#8918](https://github.com/fabricjs/fabric.js/pull/8918)
55
+ - chore(TS): export gradient types
56
+ - chore(lint) export filter colors and brushes types [#8913](https://github.com/fabricjs/fabric.js/pull/8913)
57
+ - chore(lint) Add a rule for import type [#8907](https://github.com/fabricjs/fabric.js/pull/8907)
58
+ - fix(Object): dirty unflagging inconsistency [#8910](https://github.com/fabricjs/fabric.js/pull/8910)
59
+ - chore(TS): minor type/import fixes [#8904](https://github.com/fabricjs/fabric.js/pull/8904)
60
+ - chore(): Matrix util cleanup [#8894](https://github.com/fabricjs/fabric.js/pull/8894)
61
+ - chore(TS): pattern cleanup + export types [#8875](https://github.com/fabricjs/fabric.js/pull/8875)
62
+ - fix(): Disable offscreen check for bg and overlay when not needed [#8898](https://github.com/fabricjs/fabric.js/pull/8898)
63
+ - chore(): cleanup #8888 [#8892](https://github.com/fabricjs/fabric.js/pull/8892)
64
+ - feat(env): relative window/document, support iframe [#8897](https://github.com/fabricjs/fabric.js/pull/8897)
65
+ - docs(): add repo repro link to `bug_report.yml` [#8900](https://github.com/fabricjs/fabric.js/pull/8900)
66
+ - refactor(fabric.Line): Line position is calculated from the center between the 2 points now [#8877](https://github.com/fabricjs/fabric.js/pull/8877)
67
+ - chore(Path, Polyline): Clean up old SVG import code [#8857](https://github.com/fabricjs/fabric.js/pull/8857)
68
+
69
+ ## [6.0.0-beta5]
70
+
71
+ - refactor(): SVG loading and parsing functionality are now promises or async. Callback have been removed [#8884](https://github.com/fabricjs/fabric.js/pull/8884)
72
+ - refactor(fabric.Line): Line position is calculated from the center between the 2 points now [#8877](https://github.com/fabricjs/fabric.js/pull/8877)
73
+ - bundle(): export `setEnv` for test interoperability [#8888](https://github.com/fabricjs/fabric.js/pull/8888)
74
+
75
+ ## [6.0.0-beta4]
76
+
77
+ - chore(): Code cleanup and reuse of code in svg-parsing code [#8881](https://github.com/fabricjs/fabric.js/pull/8881)
78
+ - chore(TS): Parse transform attribute typing [#8878](https://github.com/fabricjs/fabric.js/pull/8878)
79
+ - chore(TS): Fix typing for DOMParser [#8871](https://github.com/fabricjs/fabric.js/pull/8871)
80
+ - fix(Path, Polyline): fix for SVG import [#8879](https://github.com/fabricjs/fabric.js/pull/8879)
81
+ - chore(TS) add types for loadSVGFromURl, parseSVGDocument, loadSVGFromString [#8869](https://github.com/fabricjs/fabric.js/pull/8869)
82
+ - chore(TS): finalize Path migration [#8438](https://github.com/fabricjs/fabric.js/pull/8438)
83
+ - fix(Path, Obect) Fix path parsing edge case for zeroed arc command and for too small canvas patterns [#8853](https://github.com/fabricjs/fabric.js/pull/8853)
84
+
85
+ ## [6.0.0-beta3]
86
+
87
+ - chore(TS): Path type fixes [#8842](https://github.com/fabricjs/fabric.js/pull/8842)
88
+ - fix(TS): add types to some untyped empty arrays [#8830](https://github.com/fabricjs/fabric.js/pull/8830)
89
+ - chore(TS): Complete typings for toObject/fromObject [#8756](https://github.com/fabricjs/fabric.js/pull/8756)
90
+ - fix(): text styles edge case [#8820](https://github.com/fabricjs/fabric.js/pull/8820)
91
+ - chore(TS): Group types [#8807](https://github.com/fabricjs/fabric.js/pull/8807)
92
+ - chore(TS): Path util typings and refactoring [#8787](https://github.com/fabricjs/fabric.js/pull/8787)
93
+ - rename(): `IPoint` => `XY` [#8806](https://github.com/fabricjs/fabric.js/pull/8806)
94
+ - ci(): use sandbox apps in issue template, use the current branch when deploying an app, minors [#8803](https://github.com/fabricjs/fabric.js/pull/8803)
95
+ - perf(): optimize `perPixelTargetFind` [#8770](https://github.com/fabricjs/fabric.js/pull/8770)
96
+ - BREAKING fix(): reflect NUM_FRACTION_DIGITS to SVG path data [#8782] (https://github.com/fabricjs/fabric.js/pull/8782)
97
+ - fix(IText): layout change regression caused by #8663 (`text` was changed but layout was skipped) [#8711](https://github.com/fabricjs/fabric.js/pull/8711)
98
+ - fix(IText, Textbox): fix broken text input [#8775](https://github.com/fabricjs/fabric.js/pull/8775)
99
+ - ci(): `.codesandbox` [#8135](https://github.com/fabricjs/fabric.js/pull/8135)
100
+ - ci(): disallow circular deps [#8759](https://github.com/fabricjs/fabric.js/pull/8759)
101
+ - fix(): env WebGL import cycle [#8758](https://github.com/fabricjs/fabric.js/pull/8758)
102
+ - chore(TS): remove controls from prototype. BREAKING: controls aren't shared anymore [#8753](https://github.com/fabricjs/fabric.js/pull/8753)
103
+ - chore(TS): remove object `type` from prototype [#8714](https://github.com/fabricjs/fabric.js/pull/8714)
104
+ - chore(TS): type Object props [#8677](https://github.com/fabricjs/fabric.js/issues/8677)
105
+ - chore(TS): remove default values from filter prototypes [#8742](https://github.com/fabricjs/fabric.js/issues/8742)
106
+ - chore(TS): remove default values from Objects prototypes, ( filters in a followup ) [#8719](https://github.com/fabricjs/fabric.js/issues/8719)
107
+ - fix(Intersection): bug causing selection edge case [#8735](https://github.com/fabricjs/fabric.js/pull/8735)
108
+ - chore(TS): class interface for options/brevity [#8674](https://github.com/fabricjs/fabric.js/issues/8674)
109
+ - ci(): fix import autocomplete in dev mode #8725
110
+ - chore(): remove deprecated class util [#8731](https://github.com/fabricjs/fabric.js/pull/8731)
111
+ - lint(): fix eslint errors [#8729](https://github.com/fabricjs/fabric.js/pull/8729)
112
+ - fix(TS): `this.constructor` types [#8675](https://github.com/fabricjs/fabric.js/issues/8675)
113
+ - fix(DraggableText): drag image blur [#8712](https://github.com/fabricjs/fabric.js/pull/8712)
114
+ - ci(): Fix tests for firefox 110 update [#8710](https://github.com/fabricjs/fabric.js/pull/8710)
115
+ - chore(): index files for exports and tree shaking [#8661](https://github.com/fabricjs/fabric.js/pull/8661)
116
+ - ci(test): cleanup node config (#8694 followup) [#8707](https://github.com/fabricjs/fabric.js/issues/8707)
117
+ - fix(): BREAKING set/discard active object return value, discard active object now return false if no discard happened [#8672](https://github.com/fabricjs/fabric.js/issues/8672)
118
+ - fix(): selection logic to support nested multiselection [#8665](https://github.com/fabricjs/fabric.js/issues/8665)
119
+ - fix(test): remove bad node config [#8694](https://github.com/fabricjs/fabric.js/issues/8694)
120
+ - fix(): keep browser files as .js [#8690](https://github.com/fabricjs/fabric.js/issues/8690)
121
+ - fix(): object dispose removes canvas/event refs [#8673](https://github.com/fabricjs/fabric.js/issues/8673)
122
+ - fix(test): Textbox `fromObject` test is incorrectly trying to restore an instance [#8686](https://github.com/fabricjs/fabric.js/pull/8686)
123
+ - TS(): Moved cache properties to static properties on classes [#xxxx](https://github.com/fabricjs/fabric.js/pull/xxxx)
124
+ - refactor(): Moved cache properties to static properties on classes [#8662](https://github.com/fabricjs/fabric.js/pull/8662)
125
+ - docs(): v6 announcements [#8664](https://github.com/fabricjs/fabric.js/issues/8664)
126
+ - ci(): remove TS transformer [#8660](https://github.com/fabricjs/fabric.js/pull/8660)
127
+ - refactor(): BREAKING remove stateful mixin and functionality [#8663](https://github.com/fabricjs/fabric.js/pull/8663)
128
+ - patch(): Added WebGLProbe to env, removed isLikelyNode, added specific env dispose ( instead of cleanup JSDOM ) [#8652](https://github.com/fabricjs/fabric.js/pull/8652)
5
129
  - ci(): Removed the browser publish script [#8656](https://github.com/fabricjs/fabric.js/pull/8656)
6
130
  - feat(): Node entry point [#8632](https://github.com/fabricjs/fabric.js/pull/8632)
7
131
  - chore(): Change import and export strategy [#8622](https://github.com/fabricjs/fabric.js/pull/8622)
package/CONTRIBUTING.md CHANGED
@@ -62,12 +62,12 @@ Answering questions and addressing issues, as well as fixing and adding types (s
62
62
  - [Issues][issues]
63
63
  - [Discussions][discussions]
64
64
 
65
- ### 🎮 Adding a DEMO
65
+ ### 🎮 Adding a DEMO (currently not possible)
66
66
 
67
67
  Take a look at an existing [demo file][demo_file].\
68
68
  Create a new file in the same directory (`posts/demos/_posts`) and follow [**developing the website**](#fabricjscom-deprecated).
69
69
 
70
- ### ~~`fabricjs.com`~~ (_deprecated_)
70
+ ### ~~`fabricjs.com`~~ (currently not possible)
71
71
 
72
72
  To develop fabric's site you need to clone [`fabricjs.com`][website_repo] in the same parent folder of [`fabric.js`][repo], so that `fabric.js` and `fabricjs.com` are siblings.
73
73
 
@@ -91,17 +91,19 @@ Fabric is an open source project 🦄 and as such depends on the **genuine effor
91
91
 
92
92
  - Read this section through.
93
93
  - Take a look at [**GOTCHAS**][gotchas]
94
- - Follow [Developing](#-developing-) and read [Testing](#-testing).
94
+ - Follow [Developing](#-developing-) and [Testing](#-testing).
95
95
 
96
96
  ### ✅ Guidelines
97
97
 
98
+ - **Be patient** \
99
+ Sometimes it takes time to get back to you. Someone eventually will. Having a small, concise and super clear change will make maintainers more prone to handle it quickly.
98
100
  - **Code Style** \
99
101
  Fabric uses [`prettier`][prettier] to format files and [`eslint`][eslint] for linting (`npm run lint -- --fix`).\
100
102
  To enjoy a seamless dev experience add the [`Prettier - Code formatter`][prettier_extension] extension via the extensions toolbar in VSCode.
101
- - **⛔ `dist`** \
102
- Commit changes to [source files](src). Don't commit the generated [distribution files](dist).
103
+ If that doesn't work, once the PR is ready run `npm run prettier:write` and commit the changes.
104
+ Do not reorder imports. Irrelevant changes in a PR that are not created by prettier aren't needed nor welcome.
103
105
  - **Tests** \
104
- PRs must be backed with relevant tests, follow [TESTING](#-testing).
106
+ PRs must be backed with relevant tests, follow [TESTING](#-testing). If you never wrote a test or you find our tests unclear to extend, just ask for help.
105
107
  - **Docs** \
106
108
  Add relevant comments to your code if necessary using [JSDoc 3][jsdoc] and update relevant guides.\
107
109
  The generated documentation can be found at [fabricjs.com][docs], see [DOCS](#-improving-docs).
@@ -110,6 +112,7 @@ Fabric is an open source project 🦄 and as such depends on the **genuine effor
110
112
  - **1️⃣ PR per feature/bug** \
111
113
  Create a new branch for every pull request.\
112
114
  If you want to do more than one thing, create multiple pull requests 💪.
115
+ If your bug fix or feature requires a refactor, don't refactor. Commit the bugfix or the feature with the current code structure, let it sink, give some time to surface issues with the change, then when the bug or the feature seem solid, a refactor or code improvement can be tried
113
116
  - **And there you go!** \
114
117
  If you still have questions we're always happy to help.
115
118
 
@@ -122,108 +125,106 @@ It is more than likely you will be requested to change stuff and refine your wor
122
125
  [![🧪](../../actions/workflows/tests.yml/badge.svg)](../../actions/workflows/tests.yml)
123
126
  [![CodeQL](../../actions/workflows/codeql-analysis.yml/badge.svg)](../../actions/workflows/codeql-analysis.yml)
124
127
 
125
- Test suites use [`QUnit`][qunit] for assertions and [`testem`][testem] for serving
128
+ Test suites use [`QUnit`][qunit] for assertions and [`testem`][testem] for serving the browser tests
126
129
 
127
130
  - `unit` tests: test logic and state
128
- - `visual` tests: test visual outcome against image refs located at `/test/visual/golden`
131
+ - `visual` tests: test visual outcome against image refs located at `test/visual/golden`
132
+ - `UI` tests: testing with playwright
129
133
 
130
134
  ### Getting Started
131
135
 
132
- - build and watch for changes:
136
+ - Build and watch for changes
137
+ ```bash
138
+ npm run build -- -f -w
139
+ ```
140
+ - Run the entire test suite on `chrome` (many tests are skipped on `node`)
141
+ ```bash
142
+ npm test -- -a -c chrome
143
+ ```
144
+ - Handle failing tests
145
+ - Fix logic
146
+ - If needed, alter tests with **caution**
147
+ - Rerun failing tests
148
+ - Save time by rerunning failing tests only
149
+ - Select failing test files
150
+ ```bash
151
+ npm test -- -c chrome
152
+ ```
153
+ - **OR** launch the browser test suite in _dev mode_ to watch for test changes
154
+ ```bash
155
+ npm test -- -c chrome --dev -l
156
+ ```
157
+ - In case of failing visual tests, there are 2 options to view visual diffs (in order to understand what is wrong)
158
+ - Testing in _visual debug mode_ is comfortable when using with `Github Desktop` to view the diffs since refs will be overwritten (rerunning tests will use the overwritten refs so be cautious)
159
+ ```bash
160
+ npm test -- -d -c chrome
161
+ ```
162
+ - Launching the browser test suite
163
+ ```bash
164
+ npm test -- -c chrome --dev -l
165
+ ```
166
+ - Take into account that different environments produce different outputs so it is advised to run both in `chrome` and `node`.
167
+ - Committing refs is done **ONLY** with `chrome` output.
168
+ - When you are done, rerun the entire test suit to verify all tests pass.
169
+ - If you are submitting a PR, visit the PR page on github to see all checks have passed (different platforms and config are covered by the checks).
170
+ - Refer to the command docs
171
+ ```bash
172
+ npm test -- -h
173
+ ```
174
+
175
+ ## UI tests
176
+
177
+ Run UI tests with Playwright in parallel in Chrome (headed mode).
133
178
 
134
179
  ```bash
135
-
136
- npm run build -- -f -w
137
-
180
+ $ npm run test:e2e
138
181
  ```
139
182
 
140
- - run tests:
141
-
142
- ```bash
143
-
144
- npm test -- -a -d
145
- > Running all tests in debug mode (read more in the help section)
146
-
147
- npm test -- -s visual --dev -l -c chrome
148
- > Running live visual tests on chrome (navigate to see)
183
+ ### Adding Tests
149
184
 
150
- npm test -- --help
185
+ Backing a PR with tests that cover the changes that were made is a **MUST**. Aim to cover 100% of the cases.
151
186
 
152
- > Usage: fabric.js test [options]
187
+ Add tests to relevant files or add new files when necessary under `test/unit` or `test/visual`.
153
188
 
154
- > run test suite
189
+ - [`unit` test example][unit_test]
190
+ - [`visual` test example][visual_test]
155
191
 
156
- Options:
157
- -s, --suite <suite...> test suite to run (choices: "unit", "visual")
158
- -f, --file <file> run a specific test file
159
- --filter <filter> filter tests by name
160
- -a, --all run all tests (default: false)
161
- -d, --debug debug visual tests by overriding refs (golden images) in case of visual changes (default:
162
- false)
163
- -r, --recreate recreate visual refs (golden images) (default: false)
164
- -v, --verbose log passing tests (default: false)
165
- -l, --launch launch tests in the browser (default: false)
166
- --dev runs testem in `dev` mode, without a `ci` flag (default: false)
167
- -c, --context <context...> context to test in (choices: "chrome", "firefox", "node", default: "node")
168
- -p, --port
169
- -o, --out <out> path to report test results to
170
- --clear-cache clear CLI test cache (default: false)
171
- -h, --help display help for command
172
-
173
- ```
192
+ If you need to change test config ask for guidance.
174
193
 
175
194
  ---
176
195
 
177
196
  ## 🚧🎢 Developing 💡✨
178
197
 
179
- ### Setting Up Locally
198
+ ### Getting Started
180
199
 
181
- 1. 🍴 Fork the repository
182
- 1. 💾 Clone your 🍴 to your 💻
200
+ 1. 🍴 Fork and clone 💾 the repository
183
201
  1. Install dependencies 🕹️ `npm i --include=dev`
184
- 1. Next Up [Prototyping](#-prototyping) & [Testing](#-testing)
185
-
186
- #### Online
187
-
188
- [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/from-referrer/)
189
202
 
190
- Gitpod will start the [prototyping](#-prototyping) apps and expose them as endpoints.
191
- `A service is available on port ...` popups will show up.
192
-
193
- ### 🧭 Prototyping
194
-
195
- [`.codesandbox/templates`](.codesandbox/templates) contains templates for **INSTANT** out-of-the-box prototyping **👍 Try it out**
203
+ ### Starting an App
196
204
 
197
205
  ```bash
206
+ npm start <template>
207
+ npm start -- --help
208
+ ```
198
209
 
199
- npm run sandbox build next [/path/to/sandbox]
200
- > building next app at /path/to/sandbox
201
-
202
- npm run sandbox start </path/to/sandbox>
203
- > starting dev server
204
-
205
- npm run sandbox deploy </path/to/sandbox>
206
- > created codesandbox https://codesandbox.io/s/fgh476
207
-
208
- npm run sandbox deploy -- --template node
209
- > created codesandbox https://codesandbox.io/s/fgh476
210
+ You can deploy an app to codesandbox via the cli or build an app at a path of your choosing:
210
211
 
212
+ ```bash
213
+ npm run sandbox deploy <path/to/app>
214
+ npm run sandbox build <template> <path/to/app>
211
215
  npm run sandbox -- --help
216
+ ```
212
217
 
213
- > Usage: fabric.js sandbox [options] [command]
214
-
215
- > sandbox commands
218
+ Refer to [`.codesandbox/README.md`](.codesandbox/README.md) for more information.
216
219
 
217
- Options:
218
- -h, --help display help for command
220
+ ### Online
219
221
 
220
- Commands:
221
- deploy [options] [path] deploy a sandbox to codesandbox
222
- build <template> [destination] build and start a sandbox
223
- start <path> start a sandbox
224
- help [command] display help for command
222
+ You can actively develop fabric online using [Github Codespaces][github_codespaces], [Gitpod][gitpod] or CodeSandbox:
225
223
 
226
- ```
224
+ - After the Github Codespace has started run `npm start <template>` to start a prototyping app.
225
+ - Gitpod will start the prototyping apps and expose them as endpoints available on forwarded ports.
226
+ `A service is available on port ...` popups will show up.
227
+ - Codesandbox: _available soon_.
227
228
 
228
229
  ### 🔮 Symlinking
229
230
 
@@ -231,6 +232,7 @@ Establish symlinking to work with a local version on separate projects.
231
232
 
232
233
  1. From `fabric.js` folder run `npm link` **OR** `yarn link`.
233
234
  1. From the project's folder run `npm link fabric` **OR** `yarn link fabric`.
235
+ 1. Consider flagging `--save` to avoid confusion regarding what version of fabric is being used by the project.
234
236
 
235
237
  See [npm link][npm_link] **OR** [yarn link][yarn_link].\
236
238
  Don't forget to unlink the package once you're done.
@@ -256,5 +258,9 @@ Don't forget to unlink the package once you're done.
256
258
  [jsdoc]: https://jsdoc.app/
257
259
  [qunit]: https://qunitjs.com/
258
260
  [testem]: https://github.com/testem/testem
261
+ [unit_test]: https://github.com/fabricjs/fabric.js/blob/93dd2dcca705a4b481fbc9982da4952ef5b4ed1d/test/unit/point.js#L227-L237
262
+ [visual_test]: https://github.com/fabricjs/fabric.js/blob/93dd2dcca705a4b481fbc9982da4952ef5b4ed1d/test/visual/generic_rendering.js#L44-L67
263
+ [github_codespaces]: https://github.com/codespaces/new?hide_repo_select=true&ref=master&repo=712530
264
+ [gitpod]: https://gitpod.io/from-referrer/
259
265
  [npm_link]: https://docs.npmjs.com/cli/v8/commands/npm-link
260
266
  [yarn_link]: https://yarnpkg.com/cli/link
package/README.md CHANGED
@@ -42,7 +42,7 @@ A **simple and powerful Javascript HTML5 canvas library**.
42
42
  - Out of the box interactions such as scale, move, rotate, skew, group...
43
43
  - Built in shapes, controls, animations, image filters, gradients, patterns, brushes...
44
44
  - `JPG`, `PNG`, `JSON` and `SVG` i/o
45
- - Typed and modular
45
+ - [Typed and modular](#migrating-to-v6)
46
46
  - [Unit tested](CONTRIBUTING.md#%F0%9F%A7%AA%20testing)
47
47
 
48
48
  #### Supported Browsers/Environments
@@ -60,20 +60,23 @@ A **simple and powerful Javascript HTML5 canvas library**.
60
60
 
61
61
  Fabric.js Does not use transpilation by default, the browser version we support is determined by the level of canvas api we want to use and some js syntax. While JS can be easily transpiled, canvas API can't.
62
62
 
63
- ## Installation
63
+ ## Migrating to v6
64
+
65
+ v6 is a **MAJOR** effort including migrating to TS and es6, countless fixes, rewrites and features.\
66
+ Currently in beta, refer to [#8299](../../issues/8299) for guidance.
64
67
 
65
68
  ```bash
66
- $ npm install fabric --save
69
+ $ npm install fabric@beta --save
67
70
  // or
68
- $ yarn add fabric
71
+ $ yarn add fabric@beta
69
72
  ```
70
73
 
71
- ```js
72
- // es6 imports
73
- import { fabric } from 'fabric';
74
+ ## Installation
74
75
 
75
- // or cjs
76
- const fabric = require('fabric').fabric;
76
+ ```bash
77
+ $ npm install fabric --save
78
+ // or
79
+ $ yarn add fabric
77
80
  ```
78
81
 
79
82
  #### Browser
@@ -92,6 +95,15 @@ Follow these [instructions][node_canvas_install] to get `node-canvas` up and run
92
95
 
93
96
  ## Quick Start
94
97
 
98
+ ```js
99
+ // v6
100
+ import { Canvas, Rect } from 'fabric'; // browser
101
+ import { StaticCanvas, Rect } from 'fabric/node'; // node
102
+
103
+ // v5
104
+ import { fabric } from 'fabric';
105
+ ```
106
+
95
107
  <details><summary><b>Plain HTML</b></summary>
96
108
 
97
109
  ```html
@@ -117,10 +129,11 @@ Follow these [instructions][node_canvas_install] to get `node-canvas` up and run
117
129
 
118
130
  ```tsx
119
131
  import React, { useEffect, useRef } from 'react';
120
- import { fabric } from 'fabric';
132
+ import * as fabric from 'fabric'; // v6
133
+ import { fabric } from 'fabric'; // v5
121
134
 
122
135
  export const FabricJSCanvas = () => {
123
- const canvasEl = useRef(null);
136
+ const canvasEl = useRef<HTMLCanvasElement>(null);
124
137
  useEffect(() => {
125
138
  const options = { ... };
126
139
  const canvas = new fabric.Canvas(canvasEl.current, options);
@@ -132,8 +145,8 @@ export const FabricJSCanvas = () => {
132
145
  }
133
146
  }, []);
134
147
 
135
- return (<canvas width="300" height="300" ref={canvasEl}/>)
136
- });
148
+ return <canvas width="300" height="300" ref={canvasEl}/>;
149
+ };
137
150
 
138
151
  ```
139
152
 
@@ -142,8 +155,9 @@ export const FabricJSCanvas = () => {
142
155
  <details><summary><b>Node.js</b></summary>
143
156
 
144
157
  ```js
145
- const http = require('http');
146
- const { fabric } = require('fabric');
158
+ import http from 'http';
159
+ import * as fabric from 'fabric/node'; // v6
160
+ import { fabric } from 'fabric'; // v5
147
161
 
148
162
  const port = 8080;
149
163
 
@@ -177,6 +191,8 @@ http
177
191
 
178
192
  </details>
179
193
 
194
+ See our ready to use [templates](./.codesandbox/templates/).
195
+
180
196
  ---
181
197
 
182
198
  ## Other Solutions
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ presets: [
3
+ ['@babel/preset-env', { targets: { node: 'current' } }],
4
+ '@babel/preset-typescript',
5
+ ],
6
+ };