fabric 5.3.0 → 6.0.0-beta3

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 (604) hide show
  1. package/.babelrc +11 -0
  2. package/.babelrcAlt +19 -0
  3. package/.browserslistrc +5 -0
  4. package/.eslintignore +3 -0
  5. package/.eslintrc.js +43 -0
  6. package/.eslintrc.json +38 -46
  7. package/.eslintrc_tests +12 -0
  8. package/.gitattributes +2 -0
  9. package/.gitpod.yml +17 -1
  10. package/.prettierignore +19 -0
  11. package/.prettierrc +4 -0
  12. package/CHANGELOG.md +532 -189
  13. package/CONTRIBUTING.md +224 -59
  14. package/README.md +200 -235
  15. package/bower.json +1 -3
  16. package/dist/fabric.d.ts +42 -0
  17. package/dist/index.d.ts +2 -0
  18. package/dist/index.js +27582 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/index.min.js +1 -0
  21. package/dist/index.mjs +27519 -0
  22. package/dist/index.mjs.map +1 -0
  23. package/dist/index.node.cjs +27663 -0
  24. package/dist/index.node.cjs.map +1 -0
  25. package/dist/index.node.d.ts +14 -0
  26. package/dist/index.node.mjs +27606 -0
  27. package/dist/index.node.mjs.map +1 -0
  28. package/dist/src/ClassRegistry.d.ts +13 -0
  29. package/dist/src/Collection.d.ts +136 -0
  30. package/dist/src/CommonMethods.d.ts +32 -0
  31. package/dist/src/EventTypeDefs.d.ts +227 -0
  32. package/dist/src/Intersection.d.ts +112 -0
  33. package/dist/src/Observable.d.ts +60 -0
  34. package/dist/src/Pattern.d.ts +113 -0
  35. package/dist/src/Point.d.ts +232 -0
  36. package/dist/src/Shadow.d.ts +97 -0
  37. package/dist/src/brushes/BaseBrush.d.ts +105 -0
  38. package/dist/src/brushes/CircleBrush.d.ts +49 -0
  39. package/dist/src/brushes/PatternBrush.d.ts +23 -0
  40. package/dist/src/brushes/PencilBrush.d.ts +92 -0
  41. package/dist/src/brushes/SprayBrush.d.ts +79 -0
  42. package/dist/src/cache.d.ts +47 -0
  43. package/dist/src/canvas/Canvas.d.ts +548 -0
  44. package/dist/src/canvas/SelectableCanvas.d.ts +754 -0
  45. package/dist/src/canvas/StaticCanvas.d.ts +778 -0
  46. package/dist/src/canvas/TextEditingManager.d.ts +17 -0
  47. package/dist/src/canvas/canvas_gestures.mixin.d.ts +2 -0
  48. package/dist/src/color/Color.d.ts +174 -0
  49. package/dist/src/color/color_map.d.ts +155 -0
  50. package/dist/src/color/constants.d.ts +22 -0
  51. package/dist/src/color/util.d.ts +12 -0
  52. package/dist/src/config.d.ts +115 -0
  53. package/dist/src/constants.d.ts +14 -0
  54. package/dist/src/controls/Control.d.ts +228 -0
  55. package/dist/src/controls/changeWidth.d.ts +13 -0
  56. package/dist/src/controls/commonControls.d.ts +28 -0
  57. package/dist/src/controls/controlRendering.d.ts +29 -0
  58. package/dist/src/controls/drag.d.ts +12 -0
  59. package/dist/src/controls/index.d.ts +13 -0
  60. package/dist/src/controls/polyControl.d.ts +5 -0
  61. package/dist/src/controls/rotate.d.ts +12 -0
  62. package/dist/src/controls/scale.d.ts +47 -0
  63. package/dist/src/controls/scaleSkew.d.ts +39 -0
  64. package/dist/src/controls/skew.d.ts +33 -0
  65. package/dist/src/controls/util.d.ts +41 -0
  66. package/dist/src/controls/wrapWithFireEvent.d.ts +8 -0
  67. package/dist/src/controls/wrapWithFixedAnchor.d.ts +9 -0
  68. package/dist/src/env/browser.d.ts +3 -0
  69. package/dist/src/env/index.d.ts +15 -0
  70. package/dist/src/env/node.d.ts +5 -0
  71. package/dist/src/env/types.d.ts +15 -0
  72. package/dist/src/filters/BaseFilter.d.ts +153 -0
  73. package/dist/src/filters/BlendColor.d.ts +80 -0
  74. package/dist/src/filters/BlendImage.d.ts +92 -0
  75. package/dist/src/filters/Blur.d.ts +51 -0
  76. package/dist/src/filters/Boilerplate.d.ts +48 -0
  77. package/dist/src/filters/Brightness.d.ts +47 -0
  78. package/dist/src/filters/Canvas2dFilterBackend.d.ts +27 -0
  79. package/dist/src/filters/ColorMatrix.d.ts +63 -0
  80. package/dist/src/filters/ColorMatrixFilters.d.ts +545 -0
  81. package/dist/src/filters/Composed.d.ts +45 -0
  82. package/dist/src/filters/Contrast.d.ts +45 -0
  83. package/dist/src/filters/Convolute.d.ts +82 -0
  84. package/dist/src/filters/FilterBackend.d.ts +14 -0
  85. package/dist/src/filters/GLProbes/GLProbe.d.ts +11 -0
  86. package/dist/src/filters/GLProbes/NodeGLProbe.d.ts +11 -0
  87. package/dist/src/filters/GLProbes/WebGLProbe.d.ts +20 -0
  88. package/dist/src/filters/Gamma.d.ts +54 -0
  89. package/dist/src/filters/Grayscale.d.ts +46 -0
  90. package/dist/src/filters/HueRotation.d.ts +24 -0
  91. package/dist/src/filters/Invert.d.ts +55 -0
  92. package/dist/src/filters/Noise.d.ts +54 -0
  93. package/dist/src/filters/Pixelate.d.ts +44 -0
  94. package/dist/src/filters/RemoveColor.d.ts +63 -0
  95. package/dist/src/filters/Resize.d.ts +136 -0
  96. package/dist/src/filters/Saturation.d.ts +48 -0
  97. package/dist/src/filters/Vibrance.d.ts +48 -0
  98. package/dist/src/filters/WebGLFilterBackend.d.ts +126 -0
  99. package/dist/src/filters/filters.d.ts +21 -0
  100. package/dist/src/filters/index.d.ts +5 -0
  101. package/dist/src/filters/shaders/baseFilter.d.ts +4 -0
  102. package/dist/src/filters/shaders/blendColor.d.ts +13 -0
  103. package/dist/src/filters/shaders/blendImage.d.ts +3 -0
  104. package/dist/src/filters/shaders/blur.d.ts +2 -0
  105. package/dist/src/filters/shaders/brightness.d.ts +2 -0
  106. package/dist/src/filters/shaders/colorMatrix.d.ts +2 -0
  107. package/dist/src/filters/shaders/constrast.d.ts +2 -0
  108. package/dist/src/filters/shaders/convolute.d.ts +11 -0
  109. package/dist/src/filters/shaders/gamma.d.ts +2 -0
  110. package/dist/src/filters/shaders/grayscale.d.ts +3 -0
  111. package/dist/src/filters/shaders/invert.d.ts +2 -0
  112. package/dist/src/filters/shaders/noise.d.ts +2 -0
  113. package/dist/src/filters/shaders/pixelate.d.ts +2 -0
  114. package/dist/src/filters/shaders/removeColor.d.ts +2 -0
  115. package/dist/src/filters/shaders/saturation.d.ts +2 -0
  116. package/dist/src/filters/shaders/vibrance.d.ts +2 -0
  117. package/dist/src/filters/typedefs.d.ts +49 -0
  118. package/dist/src/gradient/Gradient.d.ts +149 -0
  119. package/dist/src/gradient/constants.d.ts +15 -0
  120. package/dist/src/gradient/parser/index.d.ts +4 -0
  121. package/dist/src/gradient/parser/misc.d.ts +4 -0
  122. package/dist/src/gradient/parser/parseColorStops.d.ts +3 -0
  123. package/dist/src/gradient/parser/parseCoords.d.ts +17 -0
  124. package/dist/src/gradient/typedefs.d.ts +93 -0
  125. package/dist/src/mixins/eraser_brush.mixin.d.ts +2 -0
  126. package/dist/src/parkinglot/canvas_animation.mixin.d.ts +2 -0
  127. package/dist/src/parkinglot/straighten.d.ts +2 -0
  128. package/dist/src/parser/applyViewboxTransform.d.ts +5 -0
  129. package/dist/src/parser/attributes.d.ts +6 -0
  130. package/dist/src/parser/constants.d.ts +53 -0
  131. package/dist/src/parser/doesSomeParentMatch.d.ts +2 -0
  132. package/dist/src/parser/elementById.d.ts +6 -0
  133. package/dist/src/parser/elementMatchesRule.d.ts +5 -0
  134. package/dist/src/parser/elements_parser.d.ts +3 -0
  135. package/dist/src/parser/getCSSRules.d.ts +7 -0
  136. package/dist/src/parser/getGlobalStylesForElement.d.ts +5 -0
  137. package/dist/src/parser/getGradientDefs.d.ts +7 -0
  138. package/dist/src/parser/getMultipleNodes.d.ts +2 -0
  139. package/dist/src/parser/getSvgRegex.d.ts +2 -0
  140. package/dist/src/parser/hasAncestorWithNodeName.d.ts +2 -0
  141. package/dist/src/parser/index.d.ts +10 -0
  142. package/dist/src/parser/loadSVGFromString.d.ts +12 -0
  143. package/dist/src/parser/loadSVGFromURL.d.ts +13 -0
  144. package/dist/src/parser/normalizeAttr.d.ts +2 -0
  145. package/dist/src/parser/normalizeValue.d.ts +2 -0
  146. package/dist/src/parser/parseAttributes.d.ts +9 -0
  147. package/dist/src/parser/parseElements.d.ts +11 -0
  148. package/dist/src/parser/parseFontDeclaration.d.ts +10 -0
  149. package/dist/src/parser/parsePointsAttribute.d.ts +12 -0
  150. package/dist/src/parser/parseSVGDocument.d.ts +15 -0
  151. package/dist/src/parser/parseStyleAttribute.d.ts +9 -0
  152. package/dist/src/parser/parseStyleObject.d.ts +2 -0
  153. package/dist/src/parser/parseStyleString.d.ts +2 -0
  154. package/dist/src/parser/parseTransformAttribute.d.ts +10 -0
  155. package/dist/src/parser/parseUseDirectives.d.ts +2 -0
  156. package/dist/src/parser/percent.d.ts +9 -0
  157. package/dist/src/parser/recursivelyParseGradientsXlink.d.ts +2 -0
  158. package/dist/src/parser/rotateMatrix.d.ts +2 -0
  159. package/dist/src/parser/scaleMatrix.d.ts +2 -0
  160. package/dist/src/parser/selectorMatches.d.ts +2 -0
  161. package/dist/src/parser/setStrokeFillOpacity.d.ts +6 -0
  162. package/dist/src/parser/skewMatrix.d.ts +2 -0
  163. package/dist/src/parser/translateMatrix.d.ts +2 -0
  164. package/dist/src/shapes/ActiveSelection.d.ts +82 -0
  165. package/dist/src/shapes/Circle.d.ts +99 -0
  166. package/dist/src/shapes/Ellipse.d.ts +84 -0
  167. package/dist/src/shapes/Group.d.ts +408 -0
  168. package/dist/src/shapes/IText/DraggableTextDelegate.d.ts +78 -0
  169. package/dist/src/shapes/IText/IText.d.ts +335 -0
  170. package/dist/src/shapes/IText/ITextBehavior.d.ts +287 -0
  171. package/dist/src/shapes/IText/ITextClickBehavior.d.ts +83 -0
  172. package/dist/src/shapes/IText/ITextKeyBehavior.d.ts +195 -0
  173. package/dist/src/shapes/IText/constants.d.ts +13 -0
  174. package/dist/src/shapes/Image.d.ts +311 -0
  175. package/dist/src/shapes/Line.d.ts +126 -0
  176. package/dist/src/shapes/Object/AnimatableObject.d.ts +33 -0
  177. package/dist/src/shapes/Object/FabricObject.d.ts +11 -0
  178. package/dist/src/shapes/Object/FabricObjectSVGExportMixin.d.ts +74 -0
  179. package/dist/src/shapes/Object/InteractiveObject.d.ts +296 -0
  180. package/dist/src/shapes/Object/Object.d.ts +594 -0
  181. package/dist/src/shapes/Object/ObjectGeometry.d.ts +327 -0
  182. package/dist/src/shapes/Object/ObjectOrigin.d.ts +109 -0
  183. package/dist/src/shapes/Object/StackedObject.d.ts +72 -0
  184. package/dist/src/shapes/Object/defaultValues.d.ts +76 -0
  185. package/dist/src/shapes/Object/types/BaseProps.d.ts +84 -0
  186. package/dist/src/shapes/Object/types/BorderProps.d.ts +37 -0
  187. package/dist/src/shapes/Object/types/ControlProps.d.ts +62 -0
  188. package/dist/src/shapes/Object/types/FabricObjectProps.d.ts +96 -0
  189. package/dist/src/shapes/Object/types/FillStrokeProps.d.ts +80 -0
  190. package/dist/src/shapes/Object/types/LockInteractionProps.d.ts +51 -0
  191. package/dist/src/shapes/Object/types/ObjectProps.d.ts +42 -0
  192. package/dist/src/shapes/Object/types/SerializedObjectProps.d.ts +66 -0
  193. package/dist/src/shapes/Object/types/index.d.ts +6 -0
  194. package/dist/src/shapes/Path.d.ts +130 -0
  195. package/dist/src/shapes/Polygon.d.ts +9 -0
  196. package/dist/src/shapes/Polyline.d.ts +140 -0
  197. package/dist/src/shapes/Rect.d.ts +76 -0
  198. package/dist/src/shapes/Text/StyledText.d.ts +119 -0
  199. package/dist/src/shapes/Text/Text.d.ts +673 -0
  200. package/dist/src/shapes/Text/TextSVGExportMixin.d.ts +32 -0
  201. package/dist/src/shapes/Text/constants.d.ts +7 -0
  202. package/dist/src/shapes/Textbox.d.ts +185 -0
  203. package/dist/src/shapes/Triangle.d.ts +25 -0
  204. package/dist/src/typedefs.d.ts +90 -0
  205. package/dist/src/util/animation/AnimationBase.d.ts +54 -0
  206. package/dist/src/util/animation/AnimationFrameProvider.d.ts +3 -0
  207. package/dist/src/util/animation/AnimationRegistry.d.ts +29 -0
  208. package/dist/src/util/animation/ArrayAnimation.d.ts +10 -0
  209. package/dist/src/util/animation/ColorAnimation.d.ts +11 -0
  210. package/dist/src/util/animation/ValueAnimation.d.ts +10 -0
  211. package/dist/src/util/animation/animate.d.ts +37 -0
  212. package/dist/src/util/animation/easing.d.ts +130 -0
  213. package/dist/src/util/animation/types.d.ts +87 -0
  214. package/dist/src/util/applyMixins.d.ts +8 -0
  215. package/dist/src/util/dom_event.d.ts +5 -0
  216. package/dist/src/util/dom_misc.d.ts +39 -0
  217. package/dist/src/util/dom_request.d.ts +14 -0
  218. package/dist/src/util/dom_style.d.ts +7 -0
  219. package/dist/src/util/fireEvent.d.ts +3 -0
  220. package/dist/src/util/index.d.ts +35 -0
  221. package/dist/src/util/internals/cloneDeep.d.ts +2 -0
  222. package/dist/src/util/internals/getRandomInt.d.ts +8 -0
  223. package/dist/src/util/internals/ifNaN.d.ts +8 -0
  224. package/dist/src/util/internals/index.d.ts +4 -0
  225. package/dist/src/util/internals/removeFromArray.d.ts +9 -0
  226. package/dist/src/util/internals/uid.d.ts +2 -0
  227. package/dist/src/util/lang_string.d.ts +22 -0
  228. package/dist/src/util/misc/boundingBoxFromPoints.d.ts +9 -0
  229. package/dist/src/util/misc/capValue.d.ts +2 -0
  230. package/dist/src/util/misc/cos.d.ts +10 -0
  231. package/dist/src/util/misc/dom.d.ts +28 -0
  232. package/dist/src/util/misc/findScaleTo.d.ts +29 -0
  233. package/dist/src/util/misc/groupSVGElements.d.ts +9 -0
  234. package/dist/src/util/misc/isTransparent.d.ts +11 -0
  235. package/dist/src/util/misc/matrix.d.ts +92 -0
  236. package/dist/src/util/misc/mergeClipPaths.d.ts +23 -0
  237. package/dist/src/util/misc/objectEnlive.d.ts +56 -0
  238. package/dist/src/util/misc/objectTransforms.d.ts +68 -0
  239. package/dist/src/util/misc/pick.d.ts +9 -0
  240. package/dist/src/util/misc/planeChange.d.ts +84 -0
  241. package/dist/src/util/misc/projectStroke/StrokeLineCapProjections.d.ts +51 -0
  242. package/dist/src/util/misc/projectStroke/StrokeLineJoinProjections.d.ts +81 -0
  243. package/dist/src/util/misc/projectStroke/StrokeProjectionsBase.d.ts +25 -0
  244. package/dist/src/util/misc/projectStroke/index.d.ts +11 -0
  245. package/dist/src/util/misc/projectStroke/types.d.ts +23 -0
  246. package/dist/src/util/misc/radiansDegreesConversion.d.ts +14 -0
  247. package/dist/src/util/misc/resolveOrigin.d.ts +9 -0
  248. package/dist/src/util/misc/rotatePoint.d.ts +12 -0
  249. package/dist/src/util/misc/sin.d.ts +10 -0
  250. package/dist/src/util/misc/svgParsing.d.ts +53 -0
  251. package/dist/src/util/misc/textStyles.d.ts +32 -0
  252. package/dist/src/util/misc/toFixed.d.ts +8 -0
  253. package/dist/src/util/misc/vectors.d.ts +57 -0
  254. package/dist/src/util/path/index.d.ts +96 -0
  255. package/dist/src/util/path/regex.d.ts +3 -0
  256. package/dist/src/util/path/typechecks.d.ts +24 -0
  257. package/dist/src/util/path/typedefs.d.ts +220 -0
  258. package/dist/src/util/transform_matrix_removal.d.ts +14 -0
  259. package/dist/src/util/types.d.ts +19 -0
  260. package/fabric.ts +51 -0
  261. package/index.node.ts +37 -0
  262. package/index.ts +1 -0
  263. package/package.json +100 -40
  264. package/publish.js +0 -26
  265. package/rollup.config.mjs +91 -0
  266. package/rollup.test.config.js +24 -0
  267. package/scripts/build.mjs +50 -0
  268. package/scripts/buildLock.mjs +115 -0
  269. package/scripts/buildReporter.mjs +15 -0
  270. package/scripts/buildStats.mjs +139 -0
  271. package/scripts/dirname.mjs +14 -0
  272. package/scripts/git.mjs +36 -0
  273. package/scripts/index.mjs +564 -0
  274. package/scripts/sandbox.mjs +149 -0
  275. package/src/ClassRegistry.ts +56 -0
  276. package/src/Collection.ts +346 -0
  277. package/src/CommonMethods.ts +63 -0
  278. package/src/EventTypeDefs.ts +296 -0
  279. package/src/Intersection.ts +302 -0
  280. package/src/Observable.ts +181 -0
  281. package/src/Pattern.ts +227 -0
  282. package/src/Point.ts +388 -0
  283. package/src/Shadow.ts +214 -0
  284. package/src/brushes/{base_brush.class.js → BaseBrush.ts} +65 -42
  285. package/src/brushes/CircleBrush.ts +145 -0
  286. package/src/brushes/PatternBrush.ts +70 -0
  287. package/src/brushes/PencilBrush.ts +300 -0
  288. package/src/brushes/SprayBrush.ts +219 -0
  289. package/src/cache.ts +90 -0
  290. package/src/canvas/Canvas.ts +1607 -0
  291. package/src/canvas/SelectableCanvas.ts +1608 -0
  292. package/src/canvas/StaticCanvas.ts +1734 -0
  293. package/src/canvas/TextEditingManager.ts +48 -0
  294. package/src/canvas/canvas_gestures.mixin.ts +207 -0
  295. package/src/color/Color.ts +404 -0
  296. package/src/color/color_map.ts +154 -0
  297. package/src/color/constants.ts +26 -0
  298. package/src/color/util.ts +32 -0
  299. package/src/config.ts +159 -0
  300. package/src/constants.ts +20 -0
  301. package/src/controls/Control.ts +380 -0
  302. package/src/controls/changeWidth.ts +52 -0
  303. package/src/controls/commonControls.ts +105 -0
  304. package/src/controls/controlRendering.ts +138 -0
  305. package/src/controls/drag.ts +31 -0
  306. package/src/controls/index.ts +22 -0
  307. package/src/controls/polyControl.ts +135 -0
  308. package/src/controls/rotate.ts +87 -0
  309. package/src/controls/scale.ts +277 -0
  310. package/src/controls/scaleSkew.ts +92 -0
  311. package/src/controls/skew.ts +242 -0
  312. package/src/controls/util.ts +154 -0
  313. package/src/controls/wrapWithFireEvent.ts +25 -0
  314. package/src/controls/wrapWithFixedAnchor.ts +20 -0
  315. package/src/env/browser.ts +32 -0
  316. package/src/env/index.ts +24 -0
  317. package/src/env/node.ts +56 -0
  318. package/src/env/types.ts +15 -0
  319. package/src/filters/{base_filter.class.js → BaseFilter.ts} +192 -151
  320. package/src/filters/BlendColor.ts +217 -0
  321. package/src/filters/BlendImage.ts +228 -0
  322. package/src/filters/Blur.ts +179 -0
  323. package/src/filters/Boilerplate.ts +94 -0
  324. package/src/filters/Brightness.ts +83 -0
  325. package/src/filters/Canvas2dFilterBackend.ts +65 -0
  326. package/src/filters/ColorMatrix.ts +145 -0
  327. package/src/filters/ColorMatrixFilters.ts +77 -0
  328. package/src/filters/Composed.ts +76 -0
  329. package/src/filters/Contrast.ts +82 -0
  330. package/src/filters/Convolute.ts +184 -0
  331. package/src/filters/FilterBackend.ts +34 -0
  332. package/src/filters/GLProbes/GLProbe.ts +11 -0
  333. package/src/filters/GLProbes/NodeGLProbe.ts +15 -0
  334. package/src/filters/GLProbes/WebGLProbe.ts +46 -0
  335. package/src/filters/Gamma.ts +110 -0
  336. package/src/filters/Grayscale.ts +102 -0
  337. package/src/filters/HueRotation.ts +62 -0
  338. package/src/filters/Invert.ts +99 -0
  339. package/src/filters/Noise.ts +94 -0
  340. package/src/filters/Pixelate.ts +96 -0
  341. package/src/filters/RemoveColor.ts +135 -0
  342. package/src/filters/Resize.ts +538 -0
  343. package/src/filters/Saturation.ts +87 -0
  344. package/src/filters/Vibrance.ts +88 -0
  345. package/src/filters/WebGLFilterBackend.ts +430 -0
  346. package/src/filters/filters.ts +28 -0
  347. package/src/filters/index.ts +5 -0
  348. package/src/filters/shaders/baseFilter.ts +19 -0
  349. package/src/filters/shaders/blendColor.ts +33 -0
  350. package/src/filters/shaders/blendImage.ts +32 -0
  351. package/src/filters/shaders/blur.ts +24 -0
  352. package/src/filters/shaders/brightness.ts +11 -0
  353. package/src/filters/shaders/colorMatrix.ts +12 -0
  354. package/src/filters/shaders/constrast.ts +11 -0
  355. package/src/filters/shaders/convolute.ts +154 -0
  356. package/src/filters/shaders/gamma.ts +15 -0
  357. package/src/filters/shaders/grayscale.ts +36 -0
  358. package/src/filters/shaders/invert.ts +19 -0
  359. package/src/filters/shaders/noise.ts +16 -0
  360. package/src/filters/shaders/pixelate.ts +19 -0
  361. package/src/filters/shaders/removeColor.ts +13 -0
  362. package/src/filters/shaders/saturation.ts +15 -0
  363. package/src/filters/shaders/vibrance.ts +16 -0
  364. package/src/filters/typedefs.ts +65 -0
  365. package/src/gradient/Gradient.ts +406 -0
  366. package/src/gradient/constants.ts +12 -0
  367. package/src/gradient/parser/index.ts +3 -0
  368. package/src/gradient/parser/misc.ts +13 -0
  369. package/src/gradient/parser/parseColorStops.ts +56 -0
  370. package/src/gradient/parser/parseCoords.ts +73 -0
  371. package/src/gradient/typedefs.ts +104 -0
  372. package/src/mixins/{eraser_brush.mixin.js → eraser_brush.mixin.ts} +350 -239
  373. package/src/parkinglot/canvas_animation.mixin.ts +121 -0
  374. package/src/parkinglot/straighten.ts +58 -0
  375. package/src/parser/applyViewboxTransform.ts +157 -0
  376. package/src/parser/attributes.ts +25 -0
  377. package/src/parser/constants.ts +115 -0
  378. package/src/parser/doesSomeParentMatch.ts +19 -0
  379. package/src/parser/elementById.ts +21 -0
  380. package/src/parser/elementMatchesRule.ts +16 -0
  381. package/src/parser/elements_parser.ts +191 -0
  382. package/src/parser/getCSSRules.ts +62 -0
  383. package/src/parser/getGlobalStylesForElement.ts +19 -0
  384. package/src/parser/getGradientDefs.ts +31 -0
  385. package/src/parser/getMultipleNodes.ts +15 -0
  386. package/src/parser/getSvgRegex.ts +5 -0
  387. package/src/parser/hasAncestorWithNodeName.ts +14 -0
  388. package/src/parser/index.ts +9 -0
  389. package/src/parser/loadSVGFromString.ts +26 -0
  390. package/src/parser/loadSVGFromURL.ts +40 -0
  391. package/src/parser/normalizeAttr.ts +10 -0
  392. package/src/parser/normalizeValue.ts +63 -0
  393. package/src/parser/parseAttributes.ts +90 -0
  394. package/src/parser/parseElements.ts +28 -0
  395. package/src/parser/parseFontDeclaration.ts +44 -0
  396. package/src/parser/parsePointsAttribute.ts +34 -0
  397. package/src/parser/parseSVGDocument.ts +93 -0
  398. package/src/parser/parseStyleAttribute.ts +27 -0
  399. package/src/parser/parseStyleObject.ts +15 -0
  400. package/src/parser/parseStyleString.ts +16 -0
  401. package/src/parser/parseTransformAttribute.ts +155 -0
  402. package/src/parser/parseUseDirectives.ts +78 -0
  403. package/src/parser/percent.ts +27 -0
  404. package/src/parser/recursivelyParseGradientsXlink.ts +42 -0
  405. package/src/parser/rotateMatrix.ts +21 -0
  406. package/src/parser/scaleMatrix.ts +9 -0
  407. package/src/parser/selectorMatches.ts +25 -0
  408. package/src/parser/setStrokeFillOpacity.ts +40 -0
  409. package/src/parser/skewMatrix.ts +6 -0
  410. package/src/parser/translateMatrix.ts +8 -0
  411. package/src/shapes/ActiveSelection.ts +189 -0
  412. package/src/shapes/Circle.ts +242 -0
  413. package/src/shapes/Ellipse.ts +179 -0
  414. package/src/shapes/Group.ts +1100 -0
  415. package/src/shapes/IText/DraggableTextDelegate.ts +382 -0
  416. package/src/shapes/IText/IText.ts +693 -0
  417. package/src/shapes/IText/ITextBehavior.ts +1064 -0
  418. package/src/shapes/IText/ITextClickBehavior.ts +325 -0
  419. package/src/shapes/IText/ITextKeyBehavior.ts +685 -0
  420. package/src/shapes/IText/constants.ts +47 -0
  421. package/src/shapes/Image.ts +841 -0
  422. package/src/shapes/Line.ts +346 -0
  423. package/src/shapes/Object/AnimatableObject.ts +106 -0
  424. package/src/shapes/Object/FabricObject.ts +29 -0
  425. package/src/shapes/Object/FabricObjectSVGExportMixin.ts +277 -0
  426. package/src/shapes/Object/InteractiveObject.ts +672 -0
  427. package/src/shapes/Object/Object.ts +1561 -0
  428. package/src/shapes/Object/ObjectGeometry.ts +813 -0
  429. package/src/shapes/Object/ObjectOrigin.ts +276 -0
  430. package/src/shapes/Object/StackedObject.ts +206 -0
  431. package/src/shapes/Object/defaultValues.ts +108 -0
  432. package/src/shapes/Object/types/BaseProps.ts +96 -0
  433. package/src/shapes/Object/types/BorderProps.ts +40 -0
  434. package/src/shapes/Object/types/ControlProps.ts +69 -0
  435. package/src/shapes/Object/types/FabricObjectProps.ts +111 -0
  436. package/src/shapes/Object/types/FillStrokeProps.ts +90 -0
  437. package/src/shapes/Object/types/LockInteractionProps.ts +57 -0
  438. package/src/shapes/Object/types/ObjectProps.ts +46 -0
  439. package/src/shapes/Object/types/SerializedObjectProps.ts +73 -0
  440. package/src/shapes/Object/types/index.ts +8 -0
  441. package/src/shapes/Path.ts +416 -0
  442. package/src/shapes/Polygon.ts +20 -0
  443. package/src/shapes/Polyline.ts +359 -0
  444. package/src/shapes/Rect.ts +233 -0
  445. package/src/shapes/Text/StyledText.ts +329 -0
  446. package/src/shapes/Text/Text.ts +1884 -0
  447. package/src/shapes/Text/TextSVGExportMixin.ts +288 -0
  448. package/src/shapes/Text/constants.ts +91 -0
  449. package/src/shapes/Textbox.ts +477 -0
  450. package/src/shapes/Triangle.ts +60 -0
  451. package/src/typedefs.ts +115 -0
  452. package/src/util/animation/AnimationBase.ts +166 -0
  453. package/src/util/animation/AnimationFrameProvider.ts +9 -0
  454. package/src/util/animation/AnimationRegistry.ts +58 -0
  455. package/src/util/animation/ArrayAnimation.ts +27 -0
  456. package/src/util/animation/ColorAnimation.ts +74 -0
  457. package/src/util/animation/ValueAnimation.ts +29 -0
  458. package/src/util/animation/animate.ts +74 -0
  459. package/src/util/animation/easing.ts +327 -0
  460. package/src/util/animation/types.ts +136 -0
  461. package/src/util/applyMixins.ts +22 -0
  462. package/src/util/dom_event.ts +28 -0
  463. package/src/util/dom_misc.ts +121 -0
  464. package/src/util/dom_request.ts +64 -0
  465. package/src/util/dom_style.ts +20 -0
  466. package/src/util/fireEvent.ts +15 -0
  467. package/src/util/index.ts +102 -0
  468. package/src/util/internals/cloneDeep.ts +2 -0
  469. package/src/util/internals/getRandomInt.ts +8 -0
  470. package/src/util/internals/ifNaN.ts +9 -0
  471. package/src/util/internals/index.ts +3 -0
  472. package/src/util/internals/removeFromArray.ts +14 -0
  473. package/src/util/internals/uid.ts +3 -0
  474. package/src/util/lang_string.ts +79 -0
  475. package/src/util/misc/boundingBoxFromPoints.ts +37 -0
  476. package/src/util/misc/capValue.ts +2 -0
  477. package/src/util/misc/cos.ts +24 -0
  478. package/src/util/misc/dom.ts +50 -0
  479. package/src/util/misc/findScaleTo.ts +44 -0
  480. package/src/util/misc/groupSVGElements.ts +15 -0
  481. package/src/util/misc/isTransparent.ts +28 -0
  482. package/src/util/misc/matrix.ts +207 -0
  483. package/src/util/misc/mergeClipPaths.ts +40 -0
  484. package/src/util/misc/objectEnlive.ts +189 -0
  485. package/src/util/misc/objectTransforms.ts +129 -0
  486. package/src/util/misc/pick.ts +29 -0
  487. package/src/util/misc/planeChange.ts +136 -0
  488. package/src/util/misc/projectStroke/StrokeLineCapProjections.ts +112 -0
  489. package/src/util/misc/projectStroke/StrokeLineJoinProjections.ts +226 -0
  490. package/src/util/misc/projectStroke/StrokeProjectionsBase.ts +75 -0
  491. package/src/util/misc/projectStroke/index.ts +53 -0
  492. package/src/util/misc/projectStroke/types.ts +24 -0
  493. package/src/util/misc/radiansDegreesConversion.ts +18 -0
  494. package/src/util/misc/resolveOrigin.ts +22 -0
  495. package/src/util/misc/rotatePoint.ts +15 -0
  496. package/src/util/misc/sin.ts +26 -0
  497. package/src/util/misc/svgParsing.ts +181 -0
  498. package/src/util/misc/textStyles.ts +134 -0
  499. package/src/util/misc/toFixed.ts +8 -0
  500. package/src/util/misc/vectors.ts +82 -0
  501. package/src/util/path/index.ts +1038 -0
  502. package/src/util/path/regex.ts +41 -0
  503. package/src/util/path/typechecks.ts +145 -0
  504. package/src/util/path/typedefs.ts +305 -0
  505. package/src/util/transform_matrix_removal.ts +60 -0
  506. package/src/util/types.ts +78 -0
  507. package/tsconfig.json +106 -0
  508. package/HEADER.js +0 -203
  509. package/build.js +0 -287
  510. package/dist/fabric.js +0 -31187
  511. package/dist/fabric.min.js +0 -1
  512. package/old-travis-reference.yml +0 -97
  513. package/src/brushes/circle_brush.class.js +0 -144
  514. package/src/brushes/pattern_brush.class.js +0 -61
  515. package/src/brushes/pencil_brush.class.js +0 -310
  516. package/src/brushes/spray_brush.class.js +0 -219
  517. package/src/canvas.class.js +0 -1312
  518. package/src/color.class.js +0 -636
  519. package/src/control.class.js +0 -339
  520. package/src/controls.actions.js +0 -740
  521. package/src/controls.render.js +0 -99
  522. package/src/elements_parser.js +0 -152
  523. package/src/filters/2d_backend.class.js +0 -65
  524. package/src/filters/blendcolor_filter.class.js +0 -251
  525. package/src/filters/blendimage_filter.class.js +0 -247
  526. package/src/filters/blur_filter.class.js +0 -217
  527. package/src/filters/brightness_filter.class.js +0 -113
  528. package/src/filters/colormatrix_filter.class.js +0 -159
  529. package/src/filters/composed_filter.class.js +0 -72
  530. package/src/filters/contrast_filter.class.js +0 -113
  531. package/src/filters/convolute_filter.class.js +0 -352
  532. package/src/filters/filter_boilerplate.js +0 -111
  533. package/src/filters/filter_generator.js +0 -85
  534. package/src/filters/gamma_filter.class.js +0 -136
  535. package/src/filters/grayscale_filter.class.js +0 -154
  536. package/src/filters/hue_rotation.class.js +0 -107
  537. package/src/filters/invert_filter.class.js +0 -111
  538. package/src/filters/noise_filter.class.js +0 -134
  539. package/src/filters/pixelate_filter.class.js +0 -137
  540. package/src/filters/removecolor_filter.class.js +0 -173
  541. package/src/filters/resize_filter.class.js +0 -490
  542. package/src/filters/saturate_filter.class.js +0 -119
  543. package/src/filters/vibrance_filter.class.js +0 -122
  544. package/src/filters/webgl_backend.class.js +0 -396
  545. package/src/globalFabric.js +0 -4
  546. package/src/gradient.class.js +0 -490
  547. package/src/intersection.class.js +0 -172
  548. package/src/log.js +0 -11
  549. package/src/mixins/animation.mixin.js +0 -231
  550. package/src/mixins/canvas_dataurl_exporter.mixin.js +0 -97
  551. package/src/mixins/canvas_events.mixin.js +0 -974
  552. package/src/mixins/canvas_gestures.mixin.js +0 -149
  553. package/src/mixins/canvas_grouping.mixin.js +0 -177
  554. package/src/mixins/canvas_serialization.mixin.js +0 -228
  555. package/src/mixins/collection.mixin.js +0 -170
  556. package/src/mixins/default_controls.js +0 -114
  557. package/src/mixins/itext.svg_export.js +0 -241
  558. package/src/mixins/itext_behavior.mixin.js +0 -940
  559. package/src/mixins/itext_click_behavior.mixin.js +0 -278
  560. package/src/mixins/itext_key_behavior.mixin.js +0 -694
  561. package/src/mixins/object.svg_export.js +0 -258
  562. package/src/mixins/object_geometry.mixin.js +0 -683
  563. package/src/mixins/object_interactivity.mixin.js +0 -314
  564. package/src/mixins/object_origin.mixin.js +0 -255
  565. package/src/mixins/object_stacking.mixin.js +0 -80
  566. package/src/mixins/object_straightening.mixin.js +0 -80
  567. package/src/mixins/observable.mixin.js +0 -141
  568. package/src/mixins/shared_methods.mixin.js +0 -94
  569. package/src/mixins/stateful.mixin.js +0 -107
  570. package/src/mixins/text_style.mixin.js +0 -324
  571. package/src/parser.js +0 -1090
  572. package/src/pattern.class.js +0 -189
  573. package/src/point.class.js +0 -337
  574. package/src/shadow.class.js +0 -195
  575. package/src/shapes/active_selection.class.js +0 -155
  576. package/src/shapes/circle.class.js +0 -210
  577. package/src/shapes/ellipse.class.js +0 -181
  578. package/src/shapes/group.class.js +0 -593
  579. package/src/shapes/image.class.js +0 -764
  580. package/src/shapes/itext.class.js +0 -526
  581. package/src/shapes/line.class.js +0 -324
  582. package/src/shapes/object.class.js +0 -2008
  583. package/src/shapes/path.class.js +0 -384
  584. package/src/shapes/polygon.class.js +0 -81
  585. package/src/shapes/polyline.class.js +0 -268
  586. package/src/shapes/rect.class.js +0 -187
  587. package/src/shapes/text.class.js +0 -1696
  588. package/src/shapes/textbox.class.js +0 -461
  589. package/src/shapes/triangle.class.js +0 -93
  590. package/src/static_canvas.class.js +0 -1881
  591. package/src/util/anim_ease.js +0 -398
  592. package/src/util/animate.js +0 -254
  593. package/src/util/animate_color.js +0 -74
  594. package/src/util/dom_event.js +0 -50
  595. package/src/util/dom_misc.js +0 -300
  596. package/src/util/dom_request.js +0 -54
  597. package/src/util/dom_style.js +0 -70
  598. package/src/util/lang_array.js +0 -94
  599. package/src/util/lang_class.js +0 -115
  600. package/src/util/lang_object.js +0 -75
  601. package/src/util/lang_string.js +0 -110
  602. package/src/util/misc.js +0 -1330
  603. package/src/util/named_accessors.mixin.js +0 -428
  604. package/src/util/path.js +0 -829
@@ -1,2008 +0,0 @@
1
- (function(global) {
2
-
3
- 'use strict';
4
-
5
- var fabric = global.fabric || (global.fabric = { }),
6
- extend = fabric.util.object.extend,
7
- clone = fabric.util.object.clone,
8
- toFixed = fabric.util.toFixed,
9
- capitalize = fabric.util.string.capitalize,
10
- degreesToRadians = fabric.util.degreesToRadians,
11
- objectCaching = !fabric.isLikelyNode,
12
- ALIASING_LIMIT = 2;
13
-
14
- if (fabric.Object) {
15
- return;
16
- }
17
-
18
- /**
19
- * Root object class from which all 2d shape classes inherit from
20
- * @class fabric.Object
21
- * @tutorial {@link http://fabricjs.com/fabric-intro-part-1#objects}
22
- * @see {@link fabric.Object#initialize} for constructor definition
23
- *
24
- * @fires added
25
- * @fires removed
26
- *
27
- * @fires selected
28
- * @fires deselected
29
- * @fires modified
30
- * @fires modified
31
- * @fires moved
32
- * @fires scaled
33
- * @fires rotated
34
- * @fires skewed
35
- *
36
- * @fires rotating
37
- * @fires scaling
38
- * @fires moving
39
- * @fires skewing
40
- *
41
- * @fires mousedown
42
- * @fires mouseup
43
- * @fires mouseover
44
- * @fires mouseout
45
- * @fires mousewheel
46
- * @fires mousedblclick
47
- *
48
- * @fires dragover
49
- * @fires dragenter
50
- * @fires dragleave
51
- * @fires drop
52
- */
53
- fabric.Object = fabric.util.createClass(fabric.CommonMethods, /** @lends fabric.Object.prototype */ {
54
-
55
- /**
56
- * Type of an object (rect, circle, path, etc.).
57
- * Note that this property is meant to be read-only and not meant to be modified.
58
- * If you modify, certain parts of Fabric (such as JSON loading) won't work correctly.
59
- * @type String
60
- * @default
61
- */
62
- type: 'object',
63
-
64
- /**
65
- * Horizontal origin of transformation of an object (one of "left", "right", "center")
66
- * See http://jsfiddle.net/1ow02gea/244/ on how originX/originY affect objects in groups
67
- * @type String
68
- * @default
69
- */
70
- originX: 'left',
71
-
72
- /**
73
- * Vertical origin of transformation of an object (one of "top", "bottom", "center")
74
- * See http://jsfiddle.net/1ow02gea/244/ on how originX/originY affect objects in groups
75
- * @type String
76
- * @default
77
- */
78
- originY: 'top',
79
-
80
- /**
81
- * Top position of an object. Note that by default it's relative to object top. You can change this by setting originY={top/center/bottom}
82
- * @type Number
83
- * @default
84
- */
85
- top: 0,
86
-
87
- /**
88
- * Left position of an object. Note that by default it's relative to object left. You can change this by setting originX={left/center/right}
89
- * @type Number
90
- * @default
91
- */
92
- left: 0,
93
-
94
- /**
95
- * Object width
96
- * @type Number
97
- * @default
98
- */
99
- width: 0,
100
-
101
- /**
102
- * Object height
103
- * @type Number
104
- * @default
105
- */
106
- height: 0,
107
-
108
- /**
109
- * Object scale factor (horizontal)
110
- * @type Number
111
- * @default
112
- */
113
- scaleX: 1,
114
-
115
- /**
116
- * Object scale factor (vertical)
117
- * @type Number
118
- * @default
119
- */
120
- scaleY: 1,
121
-
122
- /**
123
- * When true, an object is rendered as flipped horizontally
124
- * @type Boolean
125
- * @default
126
- */
127
- flipX: false,
128
-
129
- /**
130
- * When true, an object is rendered as flipped vertically
131
- * @type Boolean
132
- * @default
133
- */
134
- flipY: false,
135
-
136
- /**
137
- * Opacity of an object
138
- * @type Number
139
- * @default
140
- */
141
- opacity: 1,
142
-
143
- /**
144
- * Angle of rotation of an object (in degrees)
145
- * @type Number
146
- * @default
147
- */
148
- angle: 0,
149
-
150
- /**
151
- * Angle of skew on x axes of an object (in degrees)
152
- * @type Number
153
- * @default
154
- */
155
- skewX: 0,
156
-
157
- /**
158
- * Angle of skew on y axes of an object (in degrees)
159
- * @type Number
160
- * @default
161
- */
162
- skewY: 0,
163
-
164
- /**
165
- * Size of object's controlling corners (in pixels)
166
- * @type Number
167
- * @default
168
- */
169
- cornerSize: 13,
170
-
171
- /**
172
- * Size of object's controlling corners when touch interaction is detected
173
- * @type Number
174
- * @default
175
- */
176
- touchCornerSize: 24,
177
-
178
- /**
179
- * When true, object's controlling corners are rendered as transparent inside (i.e. stroke instead of fill)
180
- * @type Boolean
181
- * @default
182
- */
183
- transparentCorners: true,
184
-
185
- /**
186
- * Default cursor value used when hovering over this object on canvas
187
- * @type String
188
- * @default
189
- */
190
- hoverCursor: null,
191
-
192
- /**
193
- * Default cursor value used when moving this object on canvas
194
- * @type String
195
- * @default
196
- */
197
- moveCursor: null,
198
-
199
- /**
200
- * Padding between object and its controlling borders (in pixels)
201
- * @type Number
202
- * @default
203
- */
204
- padding: 0,
205
-
206
- /**
207
- * Color of controlling borders of an object (when it's active)
208
- * @type String
209
- * @default
210
- */
211
- borderColor: 'rgb(178,204,255)',
212
-
213
- /**
214
- * Array specifying dash pattern of an object's borders (hasBorder must be true)
215
- * @since 1.6.2
216
- * @type Array
217
- */
218
- borderDashArray: null,
219
-
220
- /**
221
- * Color of controlling corners of an object (when it's active)
222
- * @type String
223
- * @default
224
- */
225
- cornerColor: 'rgb(178,204,255)',
226
-
227
- /**
228
- * Color of controlling corners of an object (when it's active and transparentCorners false)
229
- * @since 1.6.2
230
- * @type String
231
- * @default
232
- */
233
- cornerStrokeColor: null,
234
-
235
- /**
236
- * Specify style of control, 'rect' or 'circle'
237
- * @since 1.6.2
238
- * @type String
239
- */
240
- cornerStyle: 'rect',
241
-
242
- /**
243
- * Array specifying dash pattern of an object's control (hasBorder must be true)
244
- * @since 1.6.2
245
- * @type Array
246
- */
247
- cornerDashArray: null,
248
-
249
- /**
250
- * When true, this object will use center point as the origin of transformation
251
- * when being scaled via the controls.
252
- * <b>Backwards incompatibility note:</b> This property replaces "centerTransform" (Boolean).
253
- * @since 1.3.4
254
- * @type Boolean
255
- * @default
256
- */
257
- centeredScaling: false,
258
-
259
- /**
260
- * When true, this object will use center point as the origin of transformation
261
- * when being rotated via the controls.
262
- * <b>Backwards incompatibility note:</b> This property replaces "centerTransform" (Boolean).
263
- * @since 1.3.4
264
- * @type Boolean
265
- * @default
266
- */
267
- centeredRotation: true,
268
-
269
- /**
270
- * Color of object's fill
271
- * takes css colors https://www.w3.org/TR/css-color-3/
272
- * @type String
273
- * @default
274
- */
275
- fill: 'rgb(0,0,0)',
276
-
277
- /**
278
- * Fill rule used to fill an object
279
- * accepted values are nonzero, evenodd
280
- * <b>Backwards incompatibility note:</b> This property was used for setting globalCompositeOperation until v1.4.12 (use `fabric.Object#globalCompositeOperation` instead)
281
- * @type String
282
- * @default
283
- */
284
- fillRule: 'nonzero',
285
-
286
- /**
287
- * Composite rule used for canvas globalCompositeOperation
288
- * @type String
289
- * @default
290
- */
291
- globalCompositeOperation: 'source-over',
292
-
293
- /**
294
- * Background color of an object.
295
- * takes css colors https://www.w3.org/TR/css-color-3/
296
- * @type String
297
- * @default
298
- */
299
- backgroundColor: '',
300
-
301
- /**
302
- * Selection Background color of an object. colored layer behind the object when it is active.
303
- * does not mix good with globalCompositeOperation methods.
304
- * @type String
305
- * @default
306
- */
307
- selectionBackgroundColor: '',
308
-
309
- /**
310
- * When defined, an object is rendered via stroke and this property specifies its color
311
- * takes css colors https://www.w3.org/TR/css-color-3/
312
- * @type String
313
- * @default
314
- */
315
- stroke: null,
316
-
317
- /**
318
- * Width of a stroke used to render this object
319
- * @type Number
320
- * @default
321
- */
322
- strokeWidth: 1,
323
-
324
- /**
325
- * Array specifying dash pattern of an object's stroke (stroke must be defined)
326
- * @type Array
327
- */
328
- strokeDashArray: null,
329
-
330
- /**
331
- * Line offset of an object's stroke
332
- * @type Number
333
- * @default
334
- */
335
- strokeDashOffset: 0,
336
-
337
- /**
338
- * Line endings style of an object's stroke (one of "butt", "round", "square")
339
- * @type String
340
- * @default
341
- */
342
- strokeLineCap: 'butt',
343
-
344
- /**
345
- * Corner style of an object's stroke (one of "bevel", "round", "miter")
346
- * @type String
347
- * @default
348
- */
349
- strokeLineJoin: 'miter',
350
-
351
- /**
352
- * Maximum miter length (used for strokeLineJoin = "miter") of an object's stroke
353
- * @type Number
354
- * @default
355
- */
356
- strokeMiterLimit: 4,
357
-
358
- /**
359
- * Shadow object representing shadow of this shape
360
- * @type fabric.Shadow
361
- * @default
362
- */
363
- shadow: null,
364
-
365
- /**
366
- * Opacity of object's controlling borders when object is active and moving
367
- * @type Number
368
- * @default
369
- */
370
- borderOpacityWhenMoving: 0.4,
371
-
372
- /**
373
- * Scale factor of object's controlling borders
374
- * bigger number will make a thicker border
375
- * border is 1, so this is basically a border thickness
376
- * since there is no way to change the border itself.
377
- * @type Number
378
- * @default
379
- */
380
- borderScaleFactor: 1,
381
-
382
- /**
383
- * Minimum allowed scale value of an object
384
- * @type Number
385
- * @default
386
- */
387
- minScaleLimit: 0,
388
-
389
- /**
390
- * When set to `false`, an object can not be selected for modification (using either point-click-based or group-based selection).
391
- * But events still fire on it.
392
- * @type Boolean
393
- * @default
394
- */
395
- selectable: true,
396
-
397
- /**
398
- * When set to `false`, an object can not be a target of events. All events propagate through it. Introduced in v1.3.4
399
- * @type Boolean
400
- * @default
401
- */
402
- evented: true,
403
-
404
- /**
405
- * When set to `false`, an object is not rendered on canvas
406
- * @type Boolean
407
- * @default
408
- */
409
- visible: true,
410
-
411
- /**
412
- * When set to `false`, object's controls are not displayed and can not be used to manipulate object
413
- * @type Boolean
414
- * @default
415
- */
416
- hasControls: true,
417
-
418
- /**
419
- * When set to `false`, object's controlling borders are not rendered
420
- * @type Boolean
421
- * @default
422
- */
423
- hasBorders: true,
424
-
425
- /**
426
- * When set to `true`, objects are "found" on canvas on per-pixel basis rather than according to bounding box
427
- * @type Boolean
428
- * @default
429
- */
430
- perPixelTargetFind: false,
431
-
432
- /**
433
- * When `false`, default object's values are not included in its serialization
434
- * @type Boolean
435
- * @default
436
- */
437
- includeDefaultValues: true,
438
-
439
- /**
440
- * When `true`, object horizontal movement is locked
441
- * @type Boolean
442
- * @default
443
- */
444
- lockMovementX: false,
445
-
446
- /**
447
- * When `true`, object vertical movement is locked
448
- * @type Boolean
449
- * @default
450
- */
451
- lockMovementY: false,
452
-
453
- /**
454
- * When `true`, object rotation is locked
455
- * @type Boolean
456
- * @default
457
- */
458
- lockRotation: false,
459
-
460
- /**
461
- * When `true`, object horizontal scaling is locked
462
- * @type Boolean
463
- * @default
464
- */
465
- lockScalingX: false,
466
-
467
- /**
468
- * When `true`, object vertical scaling is locked
469
- * @type Boolean
470
- * @default
471
- */
472
- lockScalingY: false,
473
-
474
- /**
475
- * When `true`, object horizontal skewing is locked
476
- * @type Boolean
477
- * @default
478
- */
479
- lockSkewingX: false,
480
-
481
- /**
482
- * When `true`, object vertical skewing is locked
483
- * @type Boolean
484
- * @default
485
- */
486
- lockSkewingY: false,
487
-
488
- /**
489
- * When `true`, object cannot be flipped by scaling into negative values
490
- * @type Boolean
491
- * @default
492
- */
493
- lockScalingFlip: false,
494
-
495
- /**
496
- * When `true`, object is not exported in OBJECT/JSON
497
- * @since 1.6.3
498
- * @type Boolean
499
- * @default
500
- */
501
- excludeFromExport: false,
502
-
503
- /**
504
- * When `true`, object is cached on an additional canvas.
505
- * When `false`, object is not cached unless necessary ( clipPath )
506
- * default to true
507
- * @since 1.7.0
508
- * @type Boolean
509
- * @default true
510
- */
511
- objectCaching: objectCaching,
512
-
513
- /**
514
- * When `true`, object properties are checked for cache invalidation. In some particular
515
- * situation you may want this to be disabled ( spray brush, very big, groups)
516
- * or if your application does not allow you to modify properties for groups child you want
517
- * to disable it for groups.
518
- * default to false
519
- * since 1.7.0
520
- * @type Boolean
521
- * @default false
522
- */
523
- statefullCache: false,
524
-
525
- /**
526
- * When `true`, cache does not get updated during scaling. The picture will get blocky if scaled
527
- * too much and will be redrawn with correct details at the end of scaling.
528
- * this setting is performance and application dependant.
529
- * default to true
530
- * since 1.7.0
531
- * @type Boolean
532
- * @default true
533
- */
534
- noScaleCache: true,
535
-
536
- /**
537
- * When `false`, the stoke width will scale with the object.
538
- * When `true`, the stroke will always match the exact pixel size entered for stroke width.
539
- * this Property does not work on Text classes or drawing call that uses strokeText,fillText methods
540
- * default to false
541
- * @since 2.6.0
542
- * @type Boolean
543
- * @default false
544
- * @type Boolean
545
- * @default false
546
- */
547
- strokeUniform: false,
548
-
549
- /**
550
- * When set to `true`, object's cache will be rerendered next render call.
551
- * since 1.7.0
552
- * @type Boolean
553
- * @default true
554
- */
555
- dirty: true,
556
-
557
- /**
558
- * keeps the value of the last hovered corner during mouse move.
559
- * 0 is no corner, or 'mt', 'ml', 'mtr' etc..
560
- * It should be private, but there is no harm in using it as
561
- * a read-only property.
562
- * @type number|string|any
563
- * @default 0
564
- */
565
- __corner: 0,
566
-
567
- /**
568
- * Determines if the fill or the stroke is drawn first (one of "fill" or "stroke")
569
- * @type String
570
- * @default
571
- */
572
- paintFirst: 'fill',
573
-
574
- /**
575
- * When 'down', object is set to active on mousedown/touchstart
576
- * When 'up', object is set to active on mouseup/touchend
577
- * Experimental. Let's see if this breaks anything before supporting officially
578
- * @private
579
- * since 4.4.0
580
- * @type String
581
- * @default 'down'
582
- */
583
- activeOn: 'down',
584
-
585
- /**
586
- * List of properties to consider when checking if state
587
- * of an object is changed (fabric.Object#hasStateChanged)
588
- * as well as for history (undo/redo) purposes
589
- * @type Array
590
- */
591
- stateProperties: (
592
- 'top left width height scaleX scaleY flipX flipY originX originY transformMatrix ' +
593
- 'stroke strokeWidth strokeDashArray strokeLineCap strokeDashOffset strokeLineJoin strokeMiterLimit ' +
594
- 'angle opacity fill globalCompositeOperation shadow visible backgroundColor ' +
595
- 'skewX skewY fillRule paintFirst clipPath strokeUniform'
596
- ).split(' '),
597
-
598
- /**
599
- * List of properties to consider when checking if cache needs refresh
600
- * Those properties are checked by statefullCache ON ( or lazy mode if we want ) or from single
601
- * calls to Object.set(key, value). If the key is in this list, the object is marked as dirty
602
- * and refreshed at the next render
603
- * @type Array
604
- */
605
- cacheProperties: (
606
- 'fill stroke strokeWidth strokeDashArray width height paintFirst strokeUniform' +
607
- ' strokeLineCap strokeDashOffset strokeLineJoin strokeMiterLimit backgroundColor clipPath'
608
- ).split(' '),
609
-
610
- /**
611
- * List of properties to consider for animating colors.
612
- * @type Array
613
- */
614
- colorProperties: (
615
- 'fill stroke backgroundColor'
616
- ).split(' '),
617
-
618
- /**
619
- * a fabricObject that, without stroke define a clipping area with their shape. filled in black
620
- * the clipPath object gets used when the object has rendered, and the context is placed in the center
621
- * of the object cacheCanvas.
622
- * If you want 0,0 of a clipPath to align with an object center, use clipPath.originX/Y to 'center'
623
- * @type fabric.Object
624
- */
625
- clipPath: undefined,
626
-
627
- /**
628
- * Meaningful ONLY when the object is used as clipPath.
629
- * if true, the clipPath will make the object clip to the outside of the clipPath
630
- * since 2.4.0
631
- * @type boolean
632
- * @default false
633
- */
634
- inverted: false,
635
-
636
- /**
637
- * Meaningful ONLY when the object is used as clipPath.
638
- * if true, the clipPath will have its top and left relative to canvas, and will
639
- * not be influenced by the object transform. This will make the clipPath relative
640
- * to the canvas, but clipping just a particular object.
641
- * WARNING this is beta, this feature may change or be renamed.
642
- * since 2.4.0
643
- * @type boolean
644
- * @default false
645
- */
646
- absolutePositioned: false,
647
-
648
- /**
649
- * Constructor
650
- * @param {Object} [options] Options object
651
- */
652
- initialize: function(options) {
653
- if (options) {
654
- this.setOptions(options);
655
- }
656
- },
657
-
658
- /**
659
- * Create a the canvas used to keep the cached copy of the object
660
- * @private
661
- */
662
- _createCacheCanvas: function() {
663
- this._cacheProperties = {};
664
- this._cacheCanvas = fabric.util.createCanvasElement();
665
- this._cacheContext = this._cacheCanvas.getContext('2d');
666
- this._updateCacheCanvas();
667
- // if canvas gets created, is empty, so dirty.
668
- this.dirty = true;
669
- },
670
-
671
- /**
672
- * Limit the cache dimensions so that X * Y do not cross fabric.perfLimitSizeTotal
673
- * and each side do not cross fabric.cacheSideLimit
674
- * those numbers are configurable so that you can get as much detail as you want
675
- * making bargain with performances.
676
- * @param {Object} dims
677
- * @param {Object} dims.width width of canvas
678
- * @param {Object} dims.height height of canvas
679
- * @param {Object} dims.zoomX zoomX zoom value to unscale the canvas before drawing cache
680
- * @param {Object} dims.zoomY zoomY zoom value to unscale the canvas before drawing cache
681
- * @return {Object}.width width of canvas
682
- * @return {Object}.height height of canvas
683
- * @return {Object}.zoomX zoomX zoom value to unscale the canvas before drawing cache
684
- * @return {Object}.zoomY zoomY zoom value to unscale the canvas before drawing cache
685
- */
686
- _limitCacheSize: function(dims) {
687
- var perfLimitSizeTotal = fabric.perfLimitSizeTotal,
688
- width = dims.width, height = dims.height,
689
- max = fabric.maxCacheSideLimit, min = fabric.minCacheSideLimit;
690
- if (width <= max && height <= max && width * height <= perfLimitSizeTotal) {
691
- if (width < min) {
692
- dims.width = min;
693
- }
694
- if (height < min) {
695
- dims.height = min;
696
- }
697
- return dims;
698
- }
699
- var ar = width / height, limitedDims = fabric.util.limitDimsByArea(ar, perfLimitSizeTotal),
700
- capValue = fabric.util.capValue,
701
- x = capValue(min, limitedDims.x, max),
702
- y = capValue(min, limitedDims.y, max);
703
- if (width > x) {
704
- dims.zoomX /= width / x;
705
- dims.width = x;
706
- dims.capped = true;
707
- }
708
- if (height > y) {
709
- dims.zoomY /= height / y;
710
- dims.height = y;
711
- dims.capped = true;
712
- }
713
- return dims;
714
- },
715
-
716
- /**
717
- * Return the dimension and the zoom level needed to create a cache canvas
718
- * big enough to host the object to be cached.
719
- * @private
720
- * @return {Object}.x width of object to be cached
721
- * @return {Object}.y height of object to be cached
722
- * @return {Object}.width width of canvas
723
- * @return {Object}.height height of canvas
724
- * @return {Object}.zoomX zoomX zoom value to unscale the canvas before drawing cache
725
- * @return {Object}.zoomY zoomY zoom value to unscale the canvas before drawing cache
726
- */
727
- _getCacheCanvasDimensions: function() {
728
- var objectScale = this.getTotalObjectScaling(),
729
- // caculate dimensions without skewing
730
- dim = this._getTransformedDimensions(0, 0),
731
- neededX = dim.x * objectScale.scaleX / this.scaleX,
732
- neededY = dim.y * objectScale.scaleY / this.scaleY;
733
- return {
734
- // for sure this ALIASING_LIMIT is slightly creating problem
735
- // in situation in which the cache canvas gets an upper limit
736
- // also objectScale contains already scaleX and scaleY
737
- width: neededX + ALIASING_LIMIT,
738
- height: neededY + ALIASING_LIMIT,
739
- zoomX: objectScale.scaleX,
740
- zoomY: objectScale.scaleY,
741
- x: neededX,
742
- y: neededY
743
- };
744
- },
745
-
746
- /**
747
- * Update width and height of the canvas for cache
748
- * returns true or false if canvas needed resize.
749
- * @private
750
- * @return {Boolean} true if the canvas has been resized
751
- */
752
- _updateCacheCanvas: function() {
753
- var targetCanvas = this.canvas;
754
- if (this.noScaleCache && targetCanvas && targetCanvas._currentTransform) {
755
- var target = targetCanvas._currentTransform.target,
756
- action = targetCanvas._currentTransform.action;
757
- if (this === target && action.slice && action.slice(0, 5) === 'scale') {
758
- return false;
759
- }
760
- }
761
- var canvas = this._cacheCanvas,
762
- dims = this._limitCacheSize(this._getCacheCanvasDimensions()),
763
- minCacheSize = fabric.minCacheSideLimit,
764
- width = dims.width, height = dims.height, drawingWidth, drawingHeight,
765
- zoomX = dims.zoomX, zoomY = dims.zoomY,
766
- dimensionsChanged = width !== this.cacheWidth || height !== this.cacheHeight,
767
- zoomChanged = this.zoomX !== zoomX || this.zoomY !== zoomY,
768
- shouldRedraw = dimensionsChanged || zoomChanged,
769
- additionalWidth = 0, additionalHeight = 0, shouldResizeCanvas = false;
770
- if (dimensionsChanged) {
771
- var canvasWidth = this._cacheCanvas.width,
772
- canvasHeight = this._cacheCanvas.height,
773
- sizeGrowing = width > canvasWidth || height > canvasHeight,
774
- sizeShrinking = (width < canvasWidth * 0.9 || height < canvasHeight * 0.9) &&
775
- canvasWidth > minCacheSize && canvasHeight > minCacheSize;
776
- shouldResizeCanvas = sizeGrowing || sizeShrinking;
777
- if (sizeGrowing && !dims.capped && (width > minCacheSize || height > minCacheSize)) {
778
- additionalWidth = width * 0.1;
779
- additionalHeight = height * 0.1;
780
- }
781
- }
782
- if (this instanceof fabric.Text && this.path) {
783
- shouldRedraw = true;
784
- shouldResizeCanvas = true;
785
- additionalWidth += this.getHeightOfLine(0) * this.zoomX;
786
- additionalHeight += this.getHeightOfLine(0) * this.zoomY;
787
- }
788
- if (shouldRedraw) {
789
- if (shouldResizeCanvas) {
790
- canvas.width = Math.ceil(width + additionalWidth);
791
- canvas.height = Math.ceil(height + additionalHeight);
792
- }
793
- else {
794
- this._cacheContext.setTransform(1, 0, 0, 1, 0, 0);
795
- this._cacheContext.clearRect(0, 0, canvas.width, canvas.height);
796
- }
797
- drawingWidth = dims.x / 2;
798
- drawingHeight = dims.y / 2;
799
- this.cacheTranslationX = Math.round(canvas.width / 2 - drawingWidth) + drawingWidth;
800
- this.cacheTranslationY = Math.round(canvas.height / 2 - drawingHeight) + drawingHeight;
801
- this.cacheWidth = width;
802
- this.cacheHeight = height;
803
- this._cacheContext.translate(this.cacheTranslationX, this.cacheTranslationY);
804
- this._cacheContext.scale(zoomX, zoomY);
805
- this.zoomX = zoomX;
806
- this.zoomY = zoomY;
807
- return true;
808
- }
809
- return false;
810
- },
811
-
812
- /**
813
- * Sets object's properties from options
814
- * @param {Object} [options] Options object
815
- */
816
- setOptions: function(options) {
817
- this._setOptions(options);
818
- this._initGradient(options.fill, 'fill');
819
- this._initGradient(options.stroke, 'stroke');
820
- this._initPattern(options.fill, 'fill');
821
- this._initPattern(options.stroke, 'stroke');
822
- },
823
-
824
- /**
825
- * Transforms context when rendering an object
826
- * @param {CanvasRenderingContext2D} ctx Context
827
- */
828
- transform: function(ctx) {
829
- var needFullTransform = (this.group && !this.group._transformDone) ||
830
- (this.group && this.canvas && ctx === this.canvas.contextTop);
831
- var m = this.calcTransformMatrix(!needFullTransform);
832
- ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
833
- },
834
-
835
- /**
836
- * Returns an object representation of an instance
837
- * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
838
- * @return {Object} Object representation of an instance
839
- */
840
- toObject: function(propertiesToInclude) {
841
- var NUM_FRACTION_DIGITS = fabric.Object.NUM_FRACTION_DIGITS,
842
-
843
- object = {
844
- type: this.type,
845
- version: fabric.version,
846
- originX: this.originX,
847
- originY: this.originY,
848
- left: toFixed(this.left, NUM_FRACTION_DIGITS),
849
- top: toFixed(this.top, NUM_FRACTION_DIGITS),
850
- width: toFixed(this.width, NUM_FRACTION_DIGITS),
851
- height: toFixed(this.height, NUM_FRACTION_DIGITS),
852
- fill: (this.fill && this.fill.toObject) ? this.fill.toObject() : this.fill,
853
- stroke: (this.stroke && this.stroke.toObject) ? this.stroke.toObject() : this.stroke,
854
- strokeWidth: toFixed(this.strokeWidth, NUM_FRACTION_DIGITS),
855
- strokeDashArray: this.strokeDashArray ? this.strokeDashArray.concat() : this.strokeDashArray,
856
- strokeLineCap: this.strokeLineCap,
857
- strokeDashOffset: this.strokeDashOffset,
858
- strokeLineJoin: this.strokeLineJoin,
859
- strokeUniform: this.strokeUniform,
860
- strokeMiterLimit: toFixed(this.strokeMiterLimit, NUM_FRACTION_DIGITS),
861
- scaleX: toFixed(this.scaleX, NUM_FRACTION_DIGITS),
862
- scaleY: toFixed(this.scaleY, NUM_FRACTION_DIGITS),
863
- angle: toFixed(this.angle, NUM_FRACTION_DIGITS),
864
- flipX: this.flipX,
865
- flipY: this.flipY,
866
- opacity: toFixed(this.opacity, NUM_FRACTION_DIGITS),
867
- shadow: (this.shadow && this.shadow.toObject) ? this.shadow.toObject() : this.shadow,
868
- visible: this.visible,
869
- backgroundColor: this.backgroundColor,
870
- fillRule: this.fillRule,
871
- paintFirst: this.paintFirst,
872
- globalCompositeOperation: this.globalCompositeOperation,
873
- skewX: toFixed(this.skewX, NUM_FRACTION_DIGITS),
874
- skewY: toFixed(this.skewY, NUM_FRACTION_DIGITS),
875
- };
876
-
877
- if (this.clipPath && !this.clipPath.excludeFromExport) {
878
- object.clipPath = this.clipPath.toObject(propertiesToInclude);
879
- object.clipPath.inverted = this.clipPath.inverted;
880
- object.clipPath.absolutePositioned = this.clipPath.absolutePositioned;
881
- }
882
-
883
- fabric.util.populateWithProperties(this, object, propertiesToInclude);
884
- if (!this.includeDefaultValues) {
885
- object = this._removeDefaultValues(object);
886
- }
887
-
888
- return object;
889
- },
890
-
891
- /**
892
- * Returns (dataless) object representation of an instance
893
- * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
894
- * @return {Object} Object representation of an instance
895
- */
896
- toDatalessObject: function(propertiesToInclude) {
897
- // will be overwritten by subclasses
898
- return this.toObject(propertiesToInclude);
899
- },
900
-
901
- /**
902
- * @private
903
- * @param {Object} object
904
- */
905
- _removeDefaultValues: function(object) {
906
- var prototype = fabric.util.getKlass(object.type).prototype,
907
- stateProperties = prototype.stateProperties;
908
- stateProperties.forEach(function(prop) {
909
- if (prop === 'left' || prop === 'top') {
910
- return;
911
- }
912
- if (object[prop] === prototype[prop]) {
913
- delete object[prop];
914
- }
915
- // basically a check for [] === []
916
- if (Array.isArray(object[prop]) && Array.isArray(prototype[prop])
917
- && object[prop].length === 0 && prototype[prop].length === 0) {
918
- delete object[prop];
919
- }
920
- });
921
-
922
- return object;
923
- },
924
-
925
- /**
926
- * Returns a string representation of an instance
927
- * @return {String}
928
- */
929
- toString: function() {
930
- return '#<fabric.' + capitalize(this.type) + '>';
931
- },
932
-
933
- /**
934
- * Return the object scale factor counting also the group scaling
935
- * @return {Object} object with scaleX and scaleY properties
936
- */
937
- getObjectScaling: function() {
938
- // if the object is a top level one, on the canvas, we go for simple aritmetic
939
- // otherwise the complex method with angles will return approximations and decimals
940
- // and will likely kill the cache when not needed
941
- // https://github.com/fabricjs/fabric.js/issues/7157
942
- if (!this.group) {
943
- return {
944
- scaleX: this.scaleX,
945
- scaleY: this.scaleY,
946
- };
947
- }
948
- // if we are inside a group total zoom calculation is complex, we defer to generic matrices
949
- var options = fabric.util.qrDecompose(this.calcTransformMatrix());
950
- return { scaleX: Math.abs(options.scaleX), scaleY: Math.abs(options.scaleY) };
951
- },
952
-
953
- /**
954
- * Return the object scale factor counting also the group scaling, zoom and retina
955
- * @return {Object} object with scaleX and scaleY properties
956
- */
957
- getTotalObjectScaling: function() {
958
- var scale = this.getObjectScaling(), scaleX = scale.scaleX, scaleY = scale.scaleY;
959
- if (this.canvas) {
960
- var zoom = this.canvas.getZoom();
961
- var retina = this.canvas.getRetinaScaling();
962
- scaleX *= zoom * retina;
963
- scaleY *= zoom * retina;
964
- }
965
- return { scaleX: scaleX, scaleY: scaleY };
966
- },
967
-
968
- /**
969
- * Return the object opacity counting also the group property
970
- * @return {Number}
971
- */
972
- getObjectOpacity: function() {
973
- var opacity = this.opacity;
974
- if (this.group) {
975
- opacity *= this.group.getObjectOpacity();
976
- }
977
- return opacity;
978
- },
979
-
980
- /**
981
- * @private
982
- * @param {String} key
983
- * @param {*} value
984
- * @return {fabric.Object} thisArg
985
- */
986
- _set: function(key, value) {
987
- var shouldConstrainValue = (key === 'scaleX' || key === 'scaleY'),
988
- isChanged = this[key] !== value, groupNeedsUpdate = false;
989
-
990
- if (shouldConstrainValue) {
991
- value = this._constrainScale(value);
992
- }
993
- if (key === 'scaleX' && value < 0) {
994
- this.flipX = !this.flipX;
995
- value *= -1;
996
- }
997
- else if (key === 'scaleY' && value < 0) {
998
- this.flipY = !this.flipY;
999
- value *= -1;
1000
- }
1001
- else if (key === 'shadow' && value && !(value instanceof fabric.Shadow)) {
1002
- value = new fabric.Shadow(value);
1003
- }
1004
- else if (key === 'dirty' && this.group) {
1005
- this.group.set('dirty', value);
1006
- }
1007
-
1008
- this[key] = value;
1009
-
1010
- if (isChanged) {
1011
- groupNeedsUpdate = this.group && this.group.isOnACache();
1012
- if (this.cacheProperties.indexOf(key) > -1) {
1013
- this.dirty = true;
1014
- groupNeedsUpdate && this.group.set('dirty', true);
1015
- }
1016
- else if (groupNeedsUpdate && this.stateProperties.indexOf(key) > -1) {
1017
- this.group.set('dirty', true);
1018
- }
1019
- }
1020
- return this;
1021
- },
1022
-
1023
- /**
1024
- * This callback function is called by the parent group of an object every
1025
- * time a non-delegated property changes on the group. It is passed the key
1026
- * and value as parameters. Not adding in this function's signature to avoid
1027
- * Travis build error about unused variables.
1028
- */
1029
- setOnGroup: function() {
1030
- // implemented by sub-classes, as needed.
1031
- },
1032
-
1033
- /**
1034
- * Retrieves viewportTransform from Object's canvas if possible
1035
- * @method getViewportTransform
1036
- * @memberOf fabric.Object.prototype
1037
- * @return {Array}
1038
- */
1039
- getViewportTransform: function() {
1040
- if (this.canvas && this.canvas.viewportTransform) {
1041
- return this.canvas.viewportTransform;
1042
- }
1043
- return fabric.iMatrix.concat();
1044
- },
1045
-
1046
- /*
1047
- * @private
1048
- * return if the object would be visible in rendering
1049
- * @memberOf fabric.Object.prototype
1050
- * @return {Boolean}
1051
- */
1052
- isNotVisible: function() {
1053
- return this.opacity === 0 ||
1054
- (!this.width && !this.height && this.strokeWidth === 0) ||
1055
- !this.visible;
1056
- },
1057
-
1058
- /**
1059
- * Renders an object on a specified context
1060
- * @param {CanvasRenderingContext2D} ctx Context to render on
1061
- */
1062
- render: function(ctx) {
1063
- // do not render if width/height are zeros or object is not visible
1064
- if (this.isNotVisible()) {
1065
- return;
1066
- }
1067
- if (this.canvas && this.canvas.skipOffscreen && !this.group && !this.isOnScreen()) {
1068
- return;
1069
- }
1070
- ctx.save();
1071
- this._setupCompositeOperation(ctx);
1072
- this.drawSelectionBackground(ctx);
1073
- this.transform(ctx);
1074
- this._setOpacity(ctx);
1075
- this._setShadow(ctx, this);
1076
- if (this.shouldCache()) {
1077
- this.renderCache();
1078
- this.drawCacheOnCanvas(ctx);
1079
- }
1080
- else {
1081
- this._removeCacheCanvas();
1082
- this.dirty = false;
1083
- this.drawObject(ctx);
1084
- if (this.objectCaching && this.statefullCache) {
1085
- this.saveState({ propertySet: 'cacheProperties' });
1086
- }
1087
- }
1088
- ctx.restore();
1089
- },
1090
-
1091
- renderCache: function(options) {
1092
- options = options || {};
1093
- if (!this._cacheCanvas || !this._cacheContext) {
1094
- this._createCacheCanvas();
1095
- }
1096
- if (this.isCacheDirty()) {
1097
- this.statefullCache && this.saveState({ propertySet: 'cacheProperties' });
1098
- this.drawObject(this._cacheContext, options.forClipping);
1099
- this.dirty = false;
1100
- }
1101
- },
1102
-
1103
- /**
1104
- * Remove cacheCanvas and its dimensions from the objects
1105
- */
1106
- _removeCacheCanvas: function() {
1107
- this._cacheCanvas = null;
1108
- this._cacheContext = null;
1109
- this.cacheWidth = 0;
1110
- this.cacheHeight = 0;
1111
- },
1112
-
1113
- /**
1114
- * return true if the object will draw a stroke
1115
- * Does not consider text styles. This is just a shortcut used at rendering time
1116
- * We want it to be an approximation and be fast.
1117
- * wrote to avoid extra caching, it has to return true when stroke happens,
1118
- * can guess when it will not happen at 100% chance, does not matter if it misses
1119
- * some use case where the stroke is invisible.
1120
- * @since 3.0.0
1121
- * @returns Boolean
1122
- */
1123
- hasStroke: function() {
1124
- return this.stroke && this.stroke !== 'transparent' && this.strokeWidth !== 0;
1125
- },
1126
-
1127
- /**
1128
- * return true if the object will draw a fill
1129
- * Does not consider text styles. This is just a shortcut used at rendering time
1130
- * We want it to be an approximation and be fast.
1131
- * wrote to avoid extra caching, it has to return true when fill happens,
1132
- * can guess when it will not happen at 100% chance, does not matter if it misses
1133
- * some use case where the fill is invisible.
1134
- * @since 3.0.0
1135
- * @returns Boolean
1136
- */
1137
- hasFill: function() {
1138
- return this.fill && this.fill !== 'transparent';
1139
- },
1140
-
1141
- /**
1142
- * When set to `true`, force the object to have its own cache, even if it is inside a group
1143
- * it may be needed when your object behave in a particular way on the cache and always needs
1144
- * its own isolated canvas to render correctly.
1145
- * Created to be overridden
1146
- * since 1.7.12
1147
- * @returns Boolean
1148
- */
1149
- needsItsOwnCache: function() {
1150
- if (this.paintFirst === 'stroke' &&
1151
- this.hasFill() && this.hasStroke() && typeof this.shadow === 'object') {
1152
- return true;
1153
- }
1154
- if (this.clipPath) {
1155
- return true;
1156
- }
1157
- return false;
1158
- },
1159
-
1160
- /**
1161
- * Decide if the object should cache or not. Create its own cache level
1162
- * objectCaching is a global flag, wins over everything
1163
- * needsItsOwnCache should be used when the object drawing method requires
1164
- * a cache step. None of the fabric classes requires it.
1165
- * Generally you do not cache objects in groups because the group outside is cached.
1166
- * Read as: cache if is needed, or if the feature is enabled but we are not already caching.
1167
- * @return {Boolean}
1168
- */
1169
- shouldCache: function() {
1170
- this.ownCaching = this.needsItsOwnCache() || (
1171
- this.objectCaching &&
1172
- (!this.group || !this.group.isOnACache())
1173
- );
1174
- return this.ownCaching;
1175
- },
1176
-
1177
- /**
1178
- * Check if this object or a child object will cast a shadow
1179
- * used by Group.shouldCache to know if child has a shadow recursively
1180
- * @return {Boolean}
1181
- */
1182
- willDrawShadow: function() {
1183
- return !!this.shadow && (this.shadow.offsetX !== 0 || this.shadow.offsetY !== 0);
1184
- },
1185
-
1186
- /**
1187
- * Execute the drawing operation for an object clipPath
1188
- * @param {CanvasRenderingContext2D} ctx Context to render on
1189
- * @param {fabric.Object} clipPath
1190
- */
1191
- drawClipPathOnCache: function(ctx, clipPath) {
1192
- ctx.save();
1193
- // DEBUG: uncomment this line, comment the following
1194
- // ctx.globalAlpha = 0.4
1195
- if (clipPath.inverted) {
1196
- ctx.globalCompositeOperation = 'destination-out';
1197
- }
1198
- else {
1199
- ctx.globalCompositeOperation = 'destination-in';
1200
- }
1201
- //ctx.scale(1 / 2, 1 / 2);
1202
- if (clipPath.absolutePositioned) {
1203
- var m = fabric.util.invertTransform(this.calcTransformMatrix());
1204
- ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
1205
- }
1206
- clipPath.transform(ctx);
1207
- ctx.scale(1 / clipPath.zoomX, 1 / clipPath.zoomY);
1208
- ctx.drawImage(clipPath._cacheCanvas, -clipPath.cacheTranslationX, -clipPath.cacheTranslationY);
1209
- ctx.restore();
1210
- },
1211
-
1212
- /**
1213
- * Execute the drawing operation for an object on a specified context
1214
- * @param {CanvasRenderingContext2D} ctx Context to render on
1215
- */
1216
- drawObject: function(ctx, forClipping) {
1217
- var originalFill = this.fill, originalStroke = this.stroke;
1218
- if (forClipping) {
1219
- this.fill = 'black';
1220
- this.stroke = '';
1221
- this._setClippingProperties(ctx);
1222
- }
1223
- else {
1224
- this._renderBackground(ctx);
1225
- }
1226
- this._render(ctx);
1227
- this._drawClipPath(ctx, this.clipPath);
1228
- this.fill = originalFill;
1229
- this.stroke = originalStroke;
1230
- },
1231
-
1232
- /**
1233
- * Prepare clipPath state and cache and draw it on instance's cache
1234
- * @param {CanvasRenderingContext2D} ctx
1235
- * @param {fabric.Object} clipPath
1236
- */
1237
- _drawClipPath: function (ctx, clipPath) {
1238
- if (!clipPath) { return; }
1239
- // needed to setup a couple of variables
1240
- // path canvas gets overridden with this one.
1241
- // TODO find a better solution?
1242
- clipPath.canvas = this.canvas;
1243
- clipPath.shouldCache();
1244
- clipPath._transformDone = true;
1245
- clipPath.renderCache({ forClipping: true });
1246
- this.drawClipPathOnCache(ctx, clipPath);
1247
- },
1248
-
1249
- /**
1250
- * Paint the cached copy of the object on the target context.
1251
- * @param {CanvasRenderingContext2D} ctx Context to render on
1252
- */
1253
- drawCacheOnCanvas: function(ctx) {
1254
- ctx.scale(1 / this.zoomX, 1 / this.zoomY);
1255
- ctx.drawImage(this._cacheCanvas, -this.cacheTranslationX, -this.cacheTranslationY);
1256
- },
1257
-
1258
- /**
1259
- * Check if cache is dirty
1260
- * @param {Boolean} skipCanvas skip canvas checks because this object is painted
1261
- * on parent canvas.
1262
- */
1263
- isCacheDirty: function(skipCanvas) {
1264
- if (this.isNotVisible()) {
1265
- return false;
1266
- }
1267
- if (this._cacheCanvas && this._cacheContext && !skipCanvas && this._updateCacheCanvas()) {
1268
- // in this case the context is already cleared.
1269
- return true;
1270
- }
1271
- else {
1272
- if (this.dirty ||
1273
- (this.clipPath && this.clipPath.absolutePositioned) ||
1274
- (this.statefullCache && this.hasStateChanged('cacheProperties'))
1275
- ) {
1276
- if (this._cacheCanvas && this._cacheContext && !skipCanvas) {
1277
- var width = this.cacheWidth / this.zoomX;
1278
- var height = this.cacheHeight / this.zoomY;
1279
- this._cacheContext.clearRect(-width / 2, -height / 2, width, height);
1280
- }
1281
- return true;
1282
- }
1283
- }
1284
- return false;
1285
- },
1286
-
1287
- /**
1288
- * Draws a background for the object big as its untransformed dimensions
1289
- * @private
1290
- * @param {CanvasRenderingContext2D} ctx Context to render on
1291
- */
1292
- _renderBackground: function(ctx) {
1293
- if (!this.backgroundColor) {
1294
- return;
1295
- }
1296
- var dim = this._getNonTransformedDimensions();
1297
- ctx.fillStyle = this.backgroundColor;
1298
-
1299
- ctx.fillRect(
1300
- -dim.x / 2,
1301
- -dim.y / 2,
1302
- dim.x,
1303
- dim.y
1304
- );
1305
- // if there is background color no other shadows
1306
- // should be casted
1307
- this._removeShadow(ctx);
1308
- },
1309
-
1310
- /**
1311
- * @private
1312
- * @param {CanvasRenderingContext2D} ctx Context to render on
1313
- */
1314
- _setOpacity: function(ctx) {
1315
- if (this.group && !this.group._transformDone) {
1316
- ctx.globalAlpha = this.getObjectOpacity();
1317
- }
1318
- else {
1319
- ctx.globalAlpha *= this.opacity;
1320
- }
1321
- },
1322
-
1323
- _setStrokeStyles: function(ctx, decl) {
1324
- var stroke = decl.stroke;
1325
- if (stroke) {
1326
- ctx.lineWidth = decl.strokeWidth;
1327
- ctx.lineCap = decl.strokeLineCap;
1328
- ctx.lineDashOffset = decl.strokeDashOffset;
1329
- ctx.lineJoin = decl.strokeLineJoin;
1330
- ctx.miterLimit = decl.strokeMiterLimit;
1331
- if (stroke.toLive) {
1332
- if (stroke.gradientUnits === 'percentage' || stroke.gradientTransform || stroke.patternTransform) {
1333
- // need to transform gradient in a pattern.
1334
- // this is a slow process. If you are hitting this codepath, and the object
1335
- // is not using caching, you should consider switching it on.
1336
- // we need a canvas as big as the current object caching canvas.
1337
- this._applyPatternForTransformedGradient(ctx, stroke);
1338
- }
1339
- else {
1340
- // is a simple gradient or pattern
1341
- ctx.strokeStyle = stroke.toLive(ctx, this);
1342
- this._applyPatternGradientTransform(ctx, stroke);
1343
- }
1344
- }
1345
- else {
1346
- // is a color
1347
- ctx.strokeStyle = decl.stroke;
1348
- }
1349
- }
1350
- },
1351
-
1352
- _setFillStyles: function(ctx, decl) {
1353
- var fill = decl.fill;
1354
- if (fill) {
1355
- if (fill.toLive) {
1356
- ctx.fillStyle = fill.toLive(ctx, this);
1357
- this._applyPatternGradientTransform(ctx, decl.fill);
1358
- }
1359
- else {
1360
- ctx.fillStyle = fill;
1361
- }
1362
- }
1363
- },
1364
-
1365
- _setClippingProperties: function(ctx) {
1366
- ctx.globalAlpha = 1;
1367
- ctx.strokeStyle = 'transparent';
1368
- ctx.fillStyle = '#000000';
1369
- },
1370
-
1371
- /**
1372
- * @private
1373
- * Sets line dash
1374
- * @param {CanvasRenderingContext2D} ctx Context to set the dash line on
1375
- * @param {Array} dashArray array representing dashes
1376
- */
1377
- _setLineDash: function(ctx, dashArray) {
1378
- if (!dashArray || dashArray.length === 0) {
1379
- return;
1380
- }
1381
- // Spec requires the concatenation of two copies the dash list when the number of elements is odd
1382
- if (1 & dashArray.length) {
1383
- dashArray.push.apply(dashArray, dashArray);
1384
- }
1385
- ctx.setLineDash(dashArray);
1386
- },
1387
-
1388
- /**
1389
- * Renders controls and borders for the object
1390
- * the context here is not transformed
1391
- * @param {CanvasRenderingContext2D} ctx Context to render on
1392
- * @param {Object} [styleOverride] properties to override the object style
1393
- */
1394
- _renderControls: function(ctx, styleOverride) {
1395
- var vpt = this.getViewportTransform(),
1396
- matrix = this.calcTransformMatrix(),
1397
- options, drawBorders, drawControls;
1398
- styleOverride = styleOverride || { };
1399
- drawBorders = typeof styleOverride.hasBorders !== 'undefined' ? styleOverride.hasBorders : this.hasBorders;
1400
- drawControls = typeof styleOverride.hasControls !== 'undefined' ? styleOverride.hasControls : this.hasControls;
1401
- matrix = fabric.util.multiplyTransformMatrices(vpt, matrix);
1402
- options = fabric.util.qrDecompose(matrix);
1403
- ctx.save();
1404
- ctx.translate(options.translateX, options.translateY);
1405
- ctx.lineWidth = 1 * this.borderScaleFactor;
1406
- if (!this.group) {
1407
- ctx.globalAlpha = this.isMoving ? this.borderOpacityWhenMoving : 1;
1408
- }
1409
- if (this.flipX) {
1410
- options.angle -= 180;
1411
- }
1412
- ctx.rotate(degreesToRadians(this.group ? options.angle : this.angle));
1413
- if (styleOverride.forActiveSelection || this.group) {
1414
- drawBorders && this.drawBordersInGroup(ctx, options, styleOverride);
1415
- }
1416
- else {
1417
- drawBorders && this.drawBorders(ctx, styleOverride);
1418
- }
1419
- drawControls && this.drawControls(ctx, styleOverride);
1420
- ctx.restore();
1421
- },
1422
-
1423
- /**
1424
- * @private
1425
- * @param {CanvasRenderingContext2D} ctx Context to render on
1426
- */
1427
- _setShadow: function(ctx) {
1428
- if (!this.shadow) {
1429
- return;
1430
- }
1431
-
1432
- var shadow = this.shadow, canvas = this.canvas, scaling,
1433
- multX = (canvas && canvas.viewportTransform[0]) || 1,
1434
- multY = (canvas && canvas.viewportTransform[3]) || 1;
1435
- if (shadow.nonScaling) {
1436
- scaling = { scaleX: 1, scaleY: 1 };
1437
- }
1438
- else {
1439
- scaling = this.getObjectScaling();
1440
- }
1441
- if (canvas && canvas._isRetinaScaling()) {
1442
- multX *= fabric.devicePixelRatio;
1443
- multY *= fabric.devicePixelRatio;
1444
- }
1445
- ctx.shadowColor = shadow.color;
1446
- ctx.shadowBlur = shadow.blur * fabric.browserShadowBlurConstant *
1447
- (multX + multY) * (scaling.scaleX + scaling.scaleY) / 4;
1448
- ctx.shadowOffsetX = shadow.offsetX * multX * scaling.scaleX;
1449
- ctx.shadowOffsetY = shadow.offsetY * multY * scaling.scaleY;
1450
- },
1451
-
1452
- /**
1453
- * @private
1454
- * @param {CanvasRenderingContext2D} ctx Context to render on
1455
- */
1456
- _removeShadow: function(ctx) {
1457
- if (!this.shadow) {
1458
- return;
1459
- }
1460
-
1461
- ctx.shadowColor = '';
1462
- ctx.shadowBlur = ctx.shadowOffsetX = ctx.shadowOffsetY = 0;
1463
- },
1464
-
1465
- /**
1466
- * @private
1467
- * @param {CanvasRenderingContext2D} ctx Context to render on
1468
- * @param {Object} filler fabric.Pattern or fabric.Gradient
1469
- * @return {Object} offset.offsetX offset for text rendering
1470
- * @return {Object} offset.offsetY offset for text rendering
1471
- */
1472
- _applyPatternGradientTransform: function(ctx, filler) {
1473
- if (!filler || !filler.toLive) {
1474
- return { offsetX: 0, offsetY: 0 };
1475
- }
1476
- var t = filler.gradientTransform || filler.patternTransform;
1477
- var offsetX = -this.width / 2 + filler.offsetX || 0,
1478
- offsetY = -this.height / 2 + filler.offsetY || 0;
1479
-
1480
- if (filler.gradientUnits === 'percentage') {
1481
- ctx.transform(this.width, 0, 0, this.height, offsetX, offsetY);
1482
- }
1483
- else {
1484
- ctx.transform(1, 0, 0, 1, offsetX, offsetY);
1485
- }
1486
- if (t) {
1487
- ctx.transform(t[0], t[1], t[2], t[3], t[4], t[5]);
1488
- }
1489
- return { offsetX: offsetX, offsetY: offsetY };
1490
- },
1491
-
1492
- /**
1493
- * @private
1494
- * @param {CanvasRenderingContext2D} ctx Context to render on
1495
- */
1496
- _renderPaintInOrder: function(ctx) {
1497
- if (this.paintFirst === 'stroke') {
1498
- this._renderStroke(ctx);
1499
- this._renderFill(ctx);
1500
- }
1501
- else {
1502
- this._renderFill(ctx);
1503
- this._renderStroke(ctx);
1504
- }
1505
- },
1506
-
1507
- /**
1508
- * @private
1509
- * function that actually render something on the context.
1510
- * empty here to allow Obects to work on tests to benchmark fabric functionalites
1511
- * not related to rendering
1512
- * @param {CanvasRenderingContext2D} ctx Context to render on
1513
- */
1514
- _render: function(/* ctx */) {
1515
-
1516
- },
1517
-
1518
- /**
1519
- * @private
1520
- * @param {CanvasRenderingContext2D} ctx Context to render on
1521
- */
1522
- _renderFill: function(ctx) {
1523
- if (!this.fill) {
1524
- return;
1525
- }
1526
-
1527
- ctx.save();
1528
- this._setFillStyles(ctx, this);
1529
- if (this.fillRule === 'evenodd') {
1530
- ctx.fill('evenodd');
1531
- }
1532
- else {
1533
- ctx.fill();
1534
- }
1535
- ctx.restore();
1536
- },
1537
-
1538
- /**
1539
- * @private
1540
- * @param {CanvasRenderingContext2D} ctx Context to render on
1541
- */
1542
- _renderStroke: function(ctx) {
1543
- if (!this.stroke || this.strokeWidth === 0) {
1544
- return;
1545
- }
1546
-
1547
- if (this.shadow && !this.shadow.affectStroke) {
1548
- this._removeShadow(ctx);
1549
- }
1550
-
1551
- ctx.save();
1552
- if (this.strokeUniform && this.group) {
1553
- var scaling = this.getObjectScaling();
1554
- ctx.scale(1 / scaling.scaleX, 1 / scaling.scaleY);
1555
- }
1556
- else if (this.strokeUniform) {
1557
- ctx.scale(1 / this.scaleX, 1 / this.scaleY);
1558
- }
1559
- this._setLineDash(ctx, this.strokeDashArray);
1560
- this._setStrokeStyles(ctx, this);
1561
- ctx.stroke();
1562
- ctx.restore();
1563
- },
1564
-
1565
- /**
1566
- * This function try to patch the missing gradientTransform on canvas gradients.
1567
- * transforming a context to transform the gradient, is going to transform the stroke too.
1568
- * we want to transform the gradient but not the stroke operation, so we create
1569
- * a transformed gradient on a pattern and then we use the pattern instead of the gradient.
1570
- * this method has drwabacks: is slow, is in low resolution, needs a patch for when the size
1571
- * is limited.
1572
- * @private
1573
- * @param {CanvasRenderingContext2D} ctx Context to render on
1574
- * @param {fabric.Gradient} filler a fabric gradient instance
1575
- */
1576
- _applyPatternForTransformedGradient: function(ctx, filler) {
1577
- var dims = this._limitCacheSize(this._getCacheCanvasDimensions()),
1578
- pCanvas = fabric.util.createCanvasElement(), pCtx, retinaScaling = this.canvas.getRetinaScaling(),
1579
- width = dims.x / this.scaleX / retinaScaling, height = dims.y / this.scaleY / retinaScaling;
1580
- pCanvas.width = width;
1581
- pCanvas.height = height;
1582
- pCtx = pCanvas.getContext('2d');
1583
- pCtx.beginPath(); pCtx.moveTo(0, 0); pCtx.lineTo(width, 0); pCtx.lineTo(width, height);
1584
- pCtx.lineTo(0, height); pCtx.closePath();
1585
- pCtx.translate(width / 2, height / 2);
1586
- pCtx.scale(
1587
- dims.zoomX / this.scaleX / retinaScaling,
1588
- dims.zoomY / this.scaleY / retinaScaling
1589
- );
1590
- this._applyPatternGradientTransform(pCtx, filler);
1591
- pCtx.fillStyle = filler.toLive(ctx);
1592
- pCtx.fill();
1593
- ctx.translate(-this.width / 2 - this.strokeWidth / 2, -this.height / 2 - this.strokeWidth / 2);
1594
- ctx.scale(
1595
- retinaScaling * this.scaleX / dims.zoomX,
1596
- retinaScaling * this.scaleY / dims.zoomY
1597
- );
1598
- ctx.strokeStyle = pCtx.createPattern(pCanvas, 'no-repeat');
1599
- },
1600
-
1601
- /**
1602
- * This function is an helper for svg import. it returns the center of the object in the svg
1603
- * untransformed coordinates
1604
- * @private
1605
- * @return {Object} center point from element coordinates
1606
- */
1607
- _findCenterFromElement: function() {
1608
- return { x: this.left + this.width / 2, y: this.top + this.height / 2 };
1609
- },
1610
-
1611
- /**
1612
- * This function is an helper for svg import. it decompose the transformMatrix
1613
- * and assign properties to object.
1614
- * untransformed coordinates
1615
- * @private
1616
- * @chainable
1617
- */
1618
- _assignTransformMatrixProps: function() {
1619
- if (this.transformMatrix) {
1620
- var options = fabric.util.qrDecompose(this.transformMatrix);
1621
- this.flipX = false;
1622
- this.flipY = false;
1623
- this.set('scaleX', options.scaleX);
1624
- this.set('scaleY', options.scaleY);
1625
- this.angle = options.angle;
1626
- this.skewX = options.skewX;
1627
- this.skewY = 0;
1628
- }
1629
- },
1630
-
1631
- /**
1632
- * This function is an helper for svg import. it removes the transform matrix
1633
- * and set to object properties that fabricjs can handle
1634
- * @private
1635
- * @param {Object} preserveAspectRatioOptions
1636
- * @return {thisArg}
1637
- */
1638
- _removeTransformMatrix: function(preserveAspectRatioOptions) {
1639
- var center = this._findCenterFromElement();
1640
- if (this.transformMatrix) {
1641
- this._assignTransformMatrixProps();
1642
- center = fabric.util.transformPoint(center, this.transformMatrix);
1643
- }
1644
- this.transformMatrix = null;
1645
- if (preserveAspectRatioOptions) {
1646
- this.scaleX *= preserveAspectRatioOptions.scaleX;
1647
- this.scaleY *= preserveAspectRatioOptions.scaleY;
1648
- this.cropX = preserveAspectRatioOptions.cropX;
1649
- this.cropY = preserveAspectRatioOptions.cropY;
1650
- center.x += preserveAspectRatioOptions.offsetLeft;
1651
- center.y += preserveAspectRatioOptions.offsetTop;
1652
- this.width = preserveAspectRatioOptions.width;
1653
- this.height = preserveAspectRatioOptions.height;
1654
- }
1655
- this.setPositionByOrigin(center, 'center', 'center');
1656
- },
1657
-
1658
- /**
1659
- * Clones an instance, using a callback method will work for every object.
1660
- * @param {Function} callback Callback is invoked with a clone as a first argument
1661
- * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
1662
- */
1663
- clone: function(callback, propertiesToInclude) {
1664
- var objectForm = this.toObject(propertiesToInclude);
1665
- if (this.constructor.fromObject) {
1666
- this.constructor.fromObject(objectForm, callback);
1667
- }
1668
- else {
1669
- fabric.Object._fromObject('Object', objectForm, callback);
1670
- }
1671
- },
1672
-
1673
- /**
1674
- * Creates an instance of fabric.Image out of an object
1675
- * makes use of toCanvasElement.
1676
- * Once this method was based on toDataUrl and loadImage, so it also had a quality
1677
- * and format option. toCanvasElement is faster and produce no loss of quality.
1678
- * If you need to get a real Jpeg or Png from an object, using toDataURL is the right way to do it.
1679
- * toCanvasElement and then toBlob from the obtained canvas is also a good option.
1680
- * This method is sync now, but still support the callback because we did not want to break.
1681
- * When fabricJS 5.0 will be planned, this will probably be changed to not have a callback.
1682
- * @param {Function} callback callback, invoked with an instance as a first argument
1683
- * @param {Object} [options] for clone as image, passed to toDataURL
1684
- * @param {Number} [options.multiplier=1] Multiplier to scale by
1685
- * @param {Number} [options.left] Cropping left offset. Introduced in v1.2.14
1686
- * @param {Number} [options.top] Cropping top offset. Introduced in v1.2.14
1687
- * @param {Number} [options.width] Cropping width. Introduced in v1.2.14
1688
- * @param {Number} [options.height] Cropping height. Introduced in v1.2.14
1689
- * @param {Boolean} [options.enableRetinaScaling] Enable retina scaling for clone image. Introduce in 1.6.4
1690
- * @param {Boolean} [options.withoutTransform] Remove current object transform ( no scale , no angle, no flip, no skew ). Introduced in 2.3.4
1691
- * @param {Boolean} [options.withoutShadow] Remove current object shadow. Introduced in 2.4.2
1692
- * @return {fabric.Object} thisArg
1693
- */
1694
- cloneAsImage: function(callback, options) {
1695
- var canvasEl = this.toCanvasElement(options);
1696
- if (callback) {
1697
- callback(new fabric.Image(canvasEl));
1698
- }
1699
- return this;
1700
- },
1701
-
1702
- /**
1703
- * Converts an object into a HTMLCanvas element
1704
- * @param {Object} options Options object
1705
- * @param {Number} [options.multiplier=1] Multiplier to scale by
1706
- * @param {Number} [options.left] Cropping left offset. Introduced in v1.2.14
1707
- * @param {Number} [options.top] Cropping top offset. Introduced in v1.2.14
1708
- * @param {Number} [options.width] Cropping width. Introduced in v1.2.14
1709
- * @param {Number} [options.height] Cropping height. Introduced in v1.2.14
1710
- * @param {Boolean} [options.enableRetinaScaling] Enable retina scaling for clone image. Introduce in 1.6.4
1711
- * @param {Boolean} [options.withoutTransform] Remove current object transform ( no scale , no angle, no flip, no skew ). Introduced in 2.3.4
1712
- * @param {Boolean} [options.withoutShadow] Remove current object shadow. Introduced in 2.4.2
1713
- * @return {HTMLCanvasElement} Returns DOM element <canvas> with the fabric.Object
1714
- */
1715
- toCanvasElement: function(options) {
1716
- options || (options = { });
1717
-
1718
- var utils = fabric.util, origParams = utils.saveObjectTransform(this),
1719
- originalGroup = this.group,
1720
- originalShadow = this.shadow, abs = Math.abs,
1721
- multiplier = (options.multiplier || 1) * (options.enableRetinaScaling ? fabric.devicePixelRatio : 1);
1722
- delete this.group;
1723
- if (options.withoutTransform) {
1724
- utils.resetObjectTransform(this);
1725
- }
1726
- if (options.withoutShadow) {
1727
- this.shadow = null;
1728
- }
1729
-
1730
- var el = fabric.util.createCanvasElement(),
1731
- // skip canvas zoom and calculate with setCoords now.
1732
- boundingRect = this.getBoundingRect(true, true),
1733
- shadow = this.shadow, scaling,
1734
- shadowOffset = { x: 0, y: 0 }, shadowBlur,
1735
- width, height;
1736
-
1737
- if (shadow) {
1738
- shadowBlur = shadow.blur;
1739
- if (shadow.nonScaling) {
1740
- scaling = { scaleX: 1, scaleY: 1 };
1741
- }
1742
- else {
1743
- scaling = this.getObjectScaling();
1744
- }
1745
- // consider non scaling shadow.
1746
- shadowOffset.x = 2 * Math.round(abs(shadow.offsetX) + shadowBlur) * (abs(scaling.scaleX));
1747
- shadowOffset.y = 2 * Math.round(abs(shadow.offsetY) + shadowBlur) * (abs(scaling.scaleY));
1748
- }
1749
- width = boundingRect.width + shadowOffset.x;
1750
- height = boundingRect.height + shadowOffset.y;
1751
- // if the current width/height is not an integer
1752
- // we need to make it so.
1753
- el.width = Math.ceil(width);
1754
- el.height = Math.ceil(height);
1755
- var canvas = new fabric.StaticCanvas(el, {
1756
- enableRetinaScaling: false,
1757
- renderOnAddRemove: false,
1758
- skipOffscreen: false,
1759
- });
1760
- if (options.format === 'jpeg') {
1761
- canvas.backgroundColor = '#fff';
1762
- }
1763
- this.setPositionByOrigin(new fabric.Point(canvas.width / 2, canvas.height / 2), 'center', 'center');
1764
-
1765
- var originalCanvas = this.canvas;
1766
- canvas.add(this);
1767
- var canvasEl = canvas.toCanvasElement(multiplier || 1, options);
1768
- this.shadow = originalShadow;
1769
- this.set('canvas', originalCanvas);
1770
- if (originalGroup) {
1771
- this.group = originalGroup;
1772
- }
1773
- this.set(origParams).setCoords();
1774
- // canvas.dispose will call image.dispose that will nullify the elements
1775
- // since this canvas is a simple element for the process, we remove references
1776
- // to objects in this way in order to avoid object trashing.
1777
- canvas._objects = [];
1778
- canvas.dispose();
1779
- canvas = null;
1780
-
1781
- return canvasEl;
1782
- },
1783
-
1784
- /**
1785
- * Converts an object into a data-url-like string
1786
- * @param {Object} options Options object
1787
- * @param {String} [options.format=png] The format of the output image. Either "jpeg" or "png"
1788
- * @param {Number} [options.quality=1] Quality level (0..1). Only used for jpeg.
1789
- * @param {Number} [options.multiplier=1] Multiplier to scale by
1790
- * @param {Number} [options.left] Cropping left offset. Introduced in v1.2.14
1791
- * @param {Number} [options.top] Cropping top offset. Introduced in v1.2.14
1792
- * @param {Number} [options.width] Cropping width. Introduced in v1.2.14
1793
- * @param {Number} [options.height] Cropping height. Introduced in v1.2.14
1794
- * @param {Boolean} [options.enableRetinaScaling] Enable retina scaling for clone image. Introduce in 1.6.4
1795
- * @param {Boolean} [options.withoutTransform] Remove current object transform ( no scale , no angle, no flip, no skew ). Introduced in 2.3.4
1796
- * @param {Boolean} [options.withoutShadow] Remove current object shadow. Introduced in 2.4.2
1797
- * @return {String} Returns a data: URL containing a representation of the object in the format specified by options.format
1798
- */
1799
- toDataURL: function(options) {
1800
- options || (options = { });
1801
- return fabric.util.toDataURL(this.toCanvasElement(options), options.format || 'png', options.quality || 1);
1802
- },
1803
-
1804
- /**
1805
- * Returns true if specified type is identical to the type of an instance
1806
- * @param {String} type Type to check against
1807
- * @return {Boolean}
1808
- */
1809
- isType: function(type) {
1810
- return arguments.length > 1 ? Array.from(arguments).includes(this.type) : this.type === type;
1811
- },
1812
-
1813
- /**
1814
- * Returns complexity of an instance
1815
- * @return {Number} complexity of this instance (is 1 unless subclassed)
1816
- */
1817
- complexity: function() {
1818
- return 1;
1819
- },
1820
-
1821
- /**
1822
- * Returns a JSON representation of an instance
1823
- * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
1824
- * @return {Object} JSON
1825
- */
1826
- toJSON: function(propertiesToInclude) {
1827
- // delegate, not alias
1828
- return this.toObject(propertiesToInclude);
1829
- },
1830
-
1831
- /**
1832
- * Sets "angle" of an instance with centered rotation
1833
- * @param {Number} angle Angle value (in degrees)
1834
- * @return {fabric.Object} thisArg
1835
- * @chainable
1836
- */
1837
- rotate: function(angle) {
1838
- var shouldCenterOrigin = (this.originX !== 'center' || this.originY !== 'center') && this.centeredRotation;
1839
-
1840
- if (shouldCenterOrigin) {
1841
- this._setOriginToCenter();
1842
- }
1843
-
1844
- this.set('angle', angle);
1845
-
1846
- if (shouldCenterOrigin) {
1847
- this._resetOrigin();
1848
- }
1849
-
1850
- return this;
1851
- },
1852
-
1853
- /**
1854
- * Centers object horizontally on canvas to which it was added last.
1855
- * You might need to call `setCoords` on an object after centering, to update controls area.
1856
- * @return {fabric.Object} thisArg
1857
- * @chainable
1858
- */
1859
- centerH: function () {
1860
- this.canvas && this.canvas.centerObjectH(this);
1861
- return this;
1862
- },
1863
-
1864
- /**
1865
- * Centers object horizontally on current viewport of canvas to which it was added last.
1866
- * You might need to call `setCoords` on an object after centering, to update controls area.
1867
- * @return {fabric.Object} thisArg
1868
- * @chainable
1869
- */
1870
- viewportCenterH: function () {
1871
- this.canvas && this.canvas.viewportCenterObjectH(this);
1872
- return this;
1873
- },
1874
-
1875
- /**
1876
- * Centers object vertically on canvas to which it was added last.
1877
- * You might need to call `setCoords` on an object after centering, to update controls area.
1878
- * @return {fabric.Object} thisArg
1879
- * @chainable
1880
- */
1881
- centerV: function () {
1882
- this.canvas && this.canvas.centerObjectV(this);
1883
- return this;
1884
- },
1885
-
1886
- /**
1887
- * Centers object vertically on current viewport of canvas to which it was added last.
1888
- * You might need to call `setCoords` on an object after centering, to update controls area.
1889
- * @return {fabric.Object} thisArg
1890
- * @chainable
1891
- */
1892
- viewportCenterV: function () {
1893
- this.canvas && this.canvas.viewportCenterObjectV(this);
1894
- return this;
1895
- },
1896
-
1897
- /**
1898
- * Centers object vertically and horizontally on canvas to which is was added last
1899
- * You might need to call `setCoords` on an object after centering, to update controls area.
1900
- * @return {fabric.Object} thisArg
1901
- * @chainable
1902
- */
1903
- center: function () {
1904
- this.canvas && this.canvas.centerObject(this);
1905
- return this;
1906
- },
1907
-
1908
- /**
1909
- * Centers object on current viewport of canvas to which it was added last.
1910
- * You might need to call `setCoords` on an object after centering, to update controls area.
1911
- * @return {fabric.Object} thisArg
1912
- * @chainable
1913
- */
1914
- viewportCenter: function () {
1915
- this.canvas && this.canvas.viewportCenterObject(this);
1916
- return this;
1917
- },
1918
-
1919
- /**
1920
- * Returns coordinates of a pointer relative to an object
1921
- * @param {Event} e Event to operate upon
1922
- * @param {Object} [pointer] Pointer to operate upon (instead of event)
1923
- * @return {Object} Coordinates of a pointer (x, y)
1924
- */
1925
- getLocalPointer: function(e, pointer) {
1926
- pointer = pointer || this.canvas.getPointer(e);
1927
- var pClicked = new fabric.Point(pointer.x, pointer.y),
1928
- objectLeftTop = this._getLeftTopCoords();
1929
- if (this.angle) {
1930
- pClicked = fabric.util.rotatePoint(
1931
- pClicked, objectLeftTop, degreesToRadians(-this.angle));
1932
- }
1933
- return {
1934
- x: pClicked.x - objectLeftTop.x,
1935
- y: pClicked.y - objectLeftTop.y
1936
- };
1937
- },
1938
-
1939
- /**
1940
- * Sets canvas globalCompositeOperation for specific object
1941
- * custom composition operation for the particular object can be specified using globalCompositeOperation property
1942
- * @param {CanvasRenderingContext2D} ctx Rendering canvas context
1943
- */
1944
- _setupCompositeOperation: function (ctx) {
1945
- if (this.globalCompositeOperation) {
1946
- ctx.globalCompositeOperation = this.globalCompositeOperation;
1947
- }
1948
- },
1949
-
1950
- /**
1951
- * cancel instance's running animations
1952
- * override if necessary to dispose artifacts such as `clipPath`
1953
- */
1954
- dispose: function () {
1955
- if (fabric.runningAnimations) {
1956
- fabric.runningAnimations.cancelByTarget(this);
1957
- }
1958
- }
1959
- });
1960
-
1961
- fabric.util.createAccessors && fabric.util.createAccessors(fabric.Object);
1962
-
1963
- extend(fabric.Object.prototype, fabric.Observable);
1964
-
1965
- /**
1966
- * Defines the number of fraction digits to use when serializing object values.
1967
- * You can use it to increase/decrease precision of such values like left, top, scaleX, scaleY, etc.
1968
- * @static
1969
- * @memberOf fabric.Object
1970
- * @constant
1971
- * @type Number
1972
- */
1973
- fabric.Object.NUM_FRACTION_DIGITS = 2;
1974
-
1975
- /**
1976
- * Defines which properties should be enlivened from the object passed to {@link fabric.Object._fromObject}
1977
- * @static
1978
- * @memberOf fabric.Object
1979
- * @constant
1980
- * @type string[]
1981
- */
1982
- fabric.Object.ENLIVEN_PROPS = ['clipPath'];
1983
-
1984
- fabric.Object._fromObject = function(className, object, callback, extraParam) {
1985
- var klass = fabric[className];
1986
- object = clone(object, true);
1987
- fabric.util.enlivenPatterns([object.fill, object.stroke], function(patterns) {
1988
- if (typeof patterns[0] !== 'undefined') {
1989
- object.fill = patterns[0];
1990
- }
1991
- if (typeof patterns[1] !== 'undefined') {
1992
- object.stroke = patterns[1];
1993
- }
1994
- fabric.util.enlivenObjectEnlivables(object, object, function () {
1995
- var instance = extraParam ? new klass(object[extraParam], object) : new klass(object);
1996
- callback && callback(instance);
1997
- });
1998
- });
1999
- };
2000
-
2001
- /**
2002
- * Unique id used internally when creating SVG elements
2003
- * @static
2004
- * @memberOf fabric.Object
2005
- * @type Number
2006
- */
2007
- fabric.Object.__uid = 0;
2008
- })(typeof exports !== 'undefined' ? exports : this);