fabric 7.0.0 → 7.2.0

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 (323) hide show
  1. package/.husky/pre-commit +1 -0
  2. package/CHANGELOG.md +21 -0
  3. package/dist/extensions/cropping_controls/croppingControls.d.ts +16 -0
  4. package/dist/extensions/cropping_controls/croppingControls.d.ts.map +1 -0
  5. package/dist/extensions/cropping_controls/croppingHandlers.d.ts +39 -0
  6. package/dist/extensions/cropping_controls/croppingHandlers.d.ts.map +1 -0
  7. package/dist/extensions/cropping_controls/enterCropMode.d.ts +7 -0
  8. package/dist/extensions/cropping_controls/enterCropMode.d.ts.map +1 -0
  9. package/dist/extensions/cropping_controls/renderCornerControl.d.ts +14 -0
  10. package/dist/extensions/cropping_controls/renderCornerControl.d.ts.map +1 -0
  11. package/dist/extensions/index.d.ts +3 -0
  12. package/dist/extensions/index.d.ts.map +1 -1
  13. package/dist/fabric.d.ts +1 -0
  14. package/dist/fabric.d.ts.map +1 -1
  15. package/dist/index.js +628 -537
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.min.js +1 -1
  18. package/dist/index.min.js.map +1 -1
  19. package/dist/index.min.mjs +1 -1
  20. package/dist/index.min.mjs.map +1 -1
  21. package/dist/index.mjs +628 -537
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/index.node.cjs +628 -537
  24. package/dist/index.node.cjs.map +1 -1
  25. package/dist/index.node.mjs +628 -537
  26. package/dist/index.node.mjs.map +1 -1
  27. package/dist/package.json.min.mjs +1 -1
  28. package/dist/package.json.mjs +1 -1
  29. package/dist/src/EventTypeDefs.d.ts +5 -0
  30. package/dist/src/EventTypeDefs.d.ts.map +1 -1
  31. package/dist/src/Pattern/Pattern.d.ts.map +1 -1
  32. package/dist/src/Pattern/Pattern.min.mjs +1 -1
  33. package/dist/src/Pattern/Pattern.min.mjs.map +1 -1
  34. package/dist/src/Pattern/Pattern.mjs +2 -1
  35. package/dist/src/Pattern/Pattern.mjs.map +1 -1
  36. package/dist/src/Shadow.d.ts +1 -1
  37. package/dist/src/Shadow.d.ts.map +1 -1
  38. package/dist/src/Shadow.min.mjs +1 -1
  39. package/dist/src/Shadow.min.mjs.map +1 -1
  40. package/dist/src/Shadow.mjs +5 -4
  41. package/dist/src/Shadow.mjs.map +1 -1
  42. package/dist/src/canvas/CanvasOptions.d.ts.map +1 -1
  43. package/dist/src/canvas/CanvasOptions.min.mjs.map +1 -1
  44. package/dist/src/canvas/CanvasOptions.mjs.map +1 -1
  45. package/dist/src/canvas/SelectableCanvas.d.ts +2 -0
  46. package/dist/src/canvas/SelectableCanvas.d.ts.map +1 -1
  47. package/dist/src/canvas/SelectableCanvas.min.mjs +1 -1
  48. package/dist/src/canvas/SelectableCanvas.min.mjs.map +1 -1
  49. package/dist/src/canvas/SelectableCanvas.mjs +33 -13
  50. package/dist/src/canvas/SelectableCanvas.mjs.map +1 -1
  51. package/dist/src/canvas/StaticCanvas.d.ts.map +1 -1
  52. package/dist/src/canvas/StaticCanvas.min.mjs +1 -1
  53. package/dist/src/canvas/StaticCanvas.min.mjs.map +1 -1
  54. package/dist/src/canvas/StaticCanvas.mjs +3 -1
  55. package/dist/src/canvas/StaticCanvas.mjs.map +1 -1
  56. package/dist/src/canvas/StaticCanvasOptions.d.ts.map +1 -1
  57. package/dist/src/canvas/StaticCanvasOptions.min.mjs.map +1 -1
  58. package/dist/src/canvas/StaticCanvasOptions.mjs.map +1 -1
  59. package/dist/src/constants.d.ts +1 -0
  60. package/dist/src/constants.d.ts.map +1 -1
  61. package/dist/src/constants.min.mjs.map +1 -1
  62. package/dist/src/constants.mjs.map +1 -1
  63. package/dist/src/controls/Control.d.ts +22 -1
  64. package/dist/src/controls/Control.d.ts.map +1 -1
  65. package/dist/src/controls/Control.min.mjs +1 -1
  66. package/dist/src/controls/Control.min.mjs.map +1 -1
  67. package/dist/src/controls/Control.mjs +45 -1
  68. package/dist/src/controls/Control.mjs.map +1 -1
  69. package/dist/src/controls/changeWidth.d.ts +22 -0
  70. package/dist/src/controls/changeWidth.d.ts.map +1 -1
  71. package/dist/src/controls/changeWidth.min.mjs +1 -1
  72. package/dist/src/controls/changeWidth.min.mjs.map +1 -1
  73. package/dist/src/controls/changeWidth.mjs +46 -18
  74. package/dist/src/controls/changeWidth.mjs.map +1 -1
  75. package/dist/src/controls/controlRendering.d.ts.map +1 -1
  76. package/dist/src/controls/controlRendering.min.mjs +1 -1
  77. package/dist/src/controls/controlRendering.min.mjs.map +1 -1
  78. package/dist/src/controls/controlRendering.mjs +18 -34
  79. package/dist/src/controls/controlRendering.mjs.map +1 -1
  80. package/dist/src/controls/index.d.ts +2 -1
  81. package/dist/src/controls/index.d.ts.map +1 -1
  82. package/dist/src/controls/index.min.mjs +1 -1
  83. package/dist/src/controls/index.mjs +1 -1
  84. package/dist/src/gradient/Gradient.d.ts.map +1 -1
  85. package/dist/src/gradient/Gradient.min.mjs +1 -1
  86. package/dist/src/gradient/Gradient.min.mjs.map +1 -1
  87. package/dist/src/gradient/Gradient.mjs +19 -6
  88. package/dist/src/gradient/Gradient.mjs.map +1 -1
  89. package/dist/src/shapes/Circle.d.ts.map +1 -1
  90. package/dist/src/shapes/Circle.min.mjs +1 -1
  91. package/dist/src/shapes/Circle.min.mjs.map +1 -1
  92. package/dist/src/shapes/Circle.mjs +10 -7
  93. package/dist/src/shapes/Circle.mjs.map +1 -1
  94. package/dist/src/shapes/Ellipse.d.ts.map +1 -1
  95. package/dist/src/shapes/Ellipse.min.mjs +1 -1
  96. package/dist/src/shapes/Ellipse.min.mjs.map +1 -1
  97. package/dist/src/shapes/Ellipse.mjs +2 -1
  98. package/dist/src/shapes/Ellipse.mjs.map +1 -1
  99. package/dist/src/shapes/Group.d.ts.map +1 -1
  100. package/dist/src/shapes/Group.min.mjs +1 -1
  101. package/dist/src/shapes/Group.min.mjs.map +1 -1
  102. package/dist/src/shapes/Group.mjs +2 -1
  103. package/dist/src/shapes/Group.mjs.map +1 -1
  104. package/dist/src/shapes/IText/IText.d.ts.map +1 -1
  105. package/dist/src/shapes/IText/IText.min.mjs.map +1 -1
  106. package/dist/src/shapes/IText/IText.mjs.map +1 -1
  107. package/dist/src/shapes/Image.d.ts +1 -1
  108. package/dist/src/shapes/Image.d.ts.map +1 -1
  109. package/dist/src/shapes/Image.min.mjs +1 -1
  110. package/dist/src/shapes/Image.min.mjs.map +1 -1
  111. package/dist/src/shapes/Image.mjs +4 -3
  112. package/dist/src/shapes/Image.mjs.map +1 -1
  113. package/dist/src/shapes/Line.d.ts.map +1 -1
  114. package/dist/src/shapes/Line.min.mjs +1 -1
  115. package/dist/src/shapes/Line.min.mjs.map +1 -1
  116. package/dist/src/shapes/Line.mjs +6 -10
  117. package/dist/src/shapes/Line.mjs.map +1 -1
  118. package/dist/src/shapes/Object/FabricObjectSVGExportMixin.d.ts.map +1 -1
  119. package/dist/src/shapes/Object/FabricObjectSVGExportMixin.min.mjs +1 -1
  120. package/dist/src/shapes/Object/FabricObjectSVGExportMixin.min.mjs.map +1 -1
  121. package/dist/src/shapes/Object/FabricObjectSVGExportMixin.mjs +5 -4
  122. package/dist/src/shapes/Object/FabricObjectSVGExportMixin.mjs.map +1 -1
  123. package/dist/src/shapes/Object/InteractiveObject.d.ts.map +1 -1
  124. package/dist/src/shapes/Object/InteractiveObject.min.mjs.map +1 -1
  125. package/dist/src/shapes/Object/InteractiveObject.mjs.map +1 -1
  126. package/dist/src/shapes/Object/Object.d.ts.map +1 -1
  127. package/dist/src/shapes/Object/Object.min.mjs +1 -1
  128. package/dist/src/shapes/Object/Object.min.mjs.map +1 -1
  129. package/dist/src/shapes/Object/Object.mjs +3 -0
  130. package/dist/src/shapes/Object/Object.mjs.map +1 -1
  131. package/dist/src/shapes/Object/ObjectGeometry.min.mjs +1 -1
  132. package/dist/src/shapes/Object/ObjectGeometry.min.mjs.map +1 -1
  133. package/dist/src/shapes/Object/ObjectGeometry.mjs +1 -1
  134. package/dist/src/shapes/Object/ObjectGeometry.mjs.map +1 -1
  135. package/dist/src/shapes/Object/types/FabricObjectProps.d.ts.map +1 -1
  136. package/dist/src/shapes/Object/types/ObjectProps.d.ts.map +1 -1
  137. package/dist/src/shapes/Path.d.ts.map +1 -1
  138. package/dist/src/shapes/Path.min.mjs.map +1 -1
  139. package/dist/src/shapes/Path.mjs +1 -2
  140. package/dist/src/shapes/Path.mjs.map +1 -1
  141. package/dist/src/shapes/Polyline.d.ts.map +1 -1
  142. package/dist/src/shapes/Polyline.min.mjs +1 -1
  143. package/dist/src/shapes/Polyline.min.mjs.map +1 -1
  144. package/dist/src/shapes/Polyline.mjs +10 -6
  145. package/dist/src/shapes/Polyline.mjs.map +1 -1
  146. package/dist/src/shapes/Rect.d.ts.map +1 -1
  147. package/dist/src/shapes/Rect.min.mjs +1 -1
  148. package/dist/src/shapes/Rect.min.mjs.map +1 -1
  149. package/dist/src/shapes/Rect.mjs +2 -1
  150. package/dist/src/shapes/Rect.mjs.map +1 -1
  151. package/dist/src/shapes/Text/StyledText.d.ts.map +1 -1
  152. package/dist/src/shapes/Text/StyledText.min.mjs.map +1 -1
  153. package/dist/src/shapes/Text/StyledText.mjs +0 -3
  154. package/dist/src/shapes/Text/StyledText.mjs.map +1 -1
  155. package/dist/src/shapes/Text/Text.d.ts.map +1 -1
  156. package/dist/src/shapes/Text/Text.min.mjs.map +1 -1
  157. package/dist/src/shapes/Text/Text.mjs.map +1 -1
  158. package/dist/src/shapes/Text/TextSVGExportMixin.d.ts.map +1 -1
  159. package/dist/src/shapes/Text/TextSVGExportMixin.min.mjs +1 -1
  160. package/dist/src/shapes/Text/TextSVGExportMixin.min.mjs.map +1 -1
  161. package/dist/src/shapes/Text/TextSVGExportMixin.mjs +5 -6
  162. package/dist/src/shapes/Text/TextSVGExportMixin.mjs.map +1 -1
  163. package/dist/src/shapes/Textbox.d.ts.map +1 -1
  164. package/dist/src/shapes/Textbox.min.mjs.map +1 -1
  165. package/dist/src/shapes/Textbox.mjs.map +1 -1
  166. package/dist/src/shapes/Triangle.d.ts.map +1 -1
  167. package/dist/src/shapes/Triangle.min.mjs.map +1 -1
  168. package/dist/src/shapes/Triangle.mjs.map +1 -1
  169. package/dist/src/util/lang_string.d.ts +1 -1
  170. package/dist/src/util/lang_string.d.ts.map +1 -1
  171. package/dist/src/util/lang_string.min.mjs +1 -1
  172. package/dist/src/util/lang_string.min.mjs.map +1 -1
  173. package/dist/src/util/lang_string.mjs +1 -1
  174. package/dist/src/util/lang_string.mjs.map +1 -1
  175. package/dist/src/util/misc/svgParsing.d.ts.map +1 -1
  176. package/dist/src/util/misc/svgParsing.min.mjs +1 -1
  177. package/dist/src/util/misc/svgParsing.min.mjs.map +1 -1
  178. package/dist/src/util/misc/svgParsing.mjs +2 -1
  179. package/dist/src/util/misc/svgParsing.mjs.map +1 -1
  180. package/dist-extensions/cropping_controls/croppingControls.mjs +140 -0
  181. package/dist-extensions/cropping_controls/croppingControls.mjs.map +1 -0
  182. package/dist-extensions/cropping_controls/croppingHandlers.mjs +228 -0
  183. package/dist-extensions/cropping_controls/croppingHandlers.mjs.map +1 -0
  184. package/dist-extensions/cropping_controls/enterCropMode.mjs +38 -0
  185. package/dist-extensions/cropping_controls/enterCropMode.mjs.map +1 -0
  186. package/dist-extensions/cropping_controls/renderCornerControl.mjs +45 -0
  187. package/dist-extensions/cropping_controls/renderCornerControl.mjs.map +1 -0
  188. package/dist-extensions/extensions/cropping_controls/croppingControls.d.ts +16 -0
  189. package/dist-extensions/extensions/cropping_controls/croppingControls.d.ts.map +1 -0
  190. package/dist-extensions/extensions/cropping_controls/croppingHandlers.d.ts +39 -0
  191. package/dist-extensions/extensions/cropping_controls/croppingHandlers.d.ts.map +1 -0
  192. package/dist-extensions/extensions/cropping_controls/enterCropMode.d.ts +7 -0
  193. package/dist-extensions/extensions/cropping_controls/enterCropMode.d.ts.map +1 -0
  194. package/dist-extensions/extensions/cropping_controls/renderCornerControl.d.ts +14 -0
  195. package/dist-extensions/extensions/cropping_controls/renderCornerControl.d.ts.map +1 -0
  196. package/dist-extensions/extensions/index.d.ts +3 -0
  197. package/dist-extensions/extensions/index.d.ts.map +1 -1
  198. package/dist-extensions/fabric-extensions.min.js +1 -1
  199. package/dist-extensions/fabric-extensions.min.js.map +1 -1
  200. package/dist-extensions/fabric.d.ts +1 -0
  201. package/dist-extensions/fabric.d.ts.map +1 -1
  202. package/dist-extensions/index.mjs +3 -0
  203. package/dist-extensions/index.mjs.map +1 -1
  204. package/dist-extensions/src/EventTypeDefs.d.ts +5 -0
  205. package/dist-extensions/src/EventTypeDefs.d.ts.map +1 -1
  206. package/dist-extensions/src/Pattern/Pattern.d.ts.map +1 -1
  207. package/dist-extensions/src/Shadow.d.ts +1 -1
  208. package/dist-extensions/src/Shadow.d.ts.map +1 -1
  209. package/dist-extensions/src/canvas/CanvasOptions.d.ts.map +1 -1
  210. package/dist-extensions/src/canvas/SelectableCanvas.d.ts +2 -0
  211. package/dist-extensions/src/canvas/SelectableCanvas.d.ts.map +1 -1
  212. package/dist-extensions/src/canvas/StaticCanvas.d.ts.map +1 -1
  213. package/dist-extensions/src/canvas/StaticCanvasOptions.d.ts.map +1 -1
  214. package/dist-extensions/src/constants.d.ts +1 -0
  215. package/dist-extensions/src/constants.d.ts.map +1 -1
  216. package/dist-extensions/src/controls/Control.d.ts +22 -1
  217. package/dist-extensions/src/controls/Control.d.ts.map +1 -1
  218. package/dist-extensions/src/controls/changeWidth.d.ts +22 -0
  219. package/dist-extensions/src/controls/changeWidth.d.ts.map +1 -1
  220. package/dist-extensions/src/controls/controlRendering.d.ts.map +1 -1
  221. package/dist-extensions/src/controls/index.d.ts +2 -1
  222. package/dist-extensions/src/controls/index.d.ts.map +1 -1
  223. package/dist-extensions/src/gradient/Gradient.d.ts.map +1 -1
  224. package/dist-extensions/src/shapes/Circle.d.ts.map +1 -1
  225. package/dist-extensions/src/shapes/Ellipse.d.ts.map +1 -1
  226. package/dist-extensions/src/shapes/Group.d.ts.map +1 -1
  227. package/dist-extensions/src/shapes/IText/IText.d.ts.map +1 -1
  228. package/dist-extensions/src/shapes/Image.d.ts.map +1 -1
  229. package/dist-extensions/src/shapes/Line.d.ts.map +1 -1
  230. package/dist-extensions/src/shapes/Object/FabricObjectSVGExportMixin.d.ts.map +1 -1
  231. package/dist-extensions/src/shapes/Object/InteractiveObject.d.ts.map +1 -1
  232. package/dist-extensions/src/shapes/Object/Object.d.ts.map +1 -1
  233. package/dist-extensions/src/shapes/Object/types/FabricObjectProps.d.ts.map +1 -1
  234. package/dist-extensions/src/shapes/Object/types/ObjectProps.d.ts.map +1 -1
  235. package/dist-extensions/src/shapes/Path.d.ts +1 -1
  236. package/dist-extensions/src/shapes/Path.d.ts.map +1 -1
  237. package/dist-extensions/src/shapes/Polyline.d.ts.map +1 -1
  238. package/dist-extensions/src/shapes/Rect.d.ts.map +1 -1
  239. package/dist-extensions/src/shapes/Text/StyledText.d.ts.map +1 -1
  240. package/dist-extensions/src/shapes/Text/Text.d.ts.map +1 -1
  241. package/dist-extensions/src/shapes/Text/TextSVGExportMixin.d.ts.map +1 -1
  242. package/dist-extensions/src/shapes/Textbox.d.ts.map +1 -1
  243. package/dist-extensions/src/shapes/Triangle.d.ts.map +1 -1
  244. package/dist-extensions/src/util/lang_string.d.ts +1 -1
  245. package/dist-extensions/src/util/lang_string.d.ts.map +1 -1
  246. package/dist-extensions/src/util/misc/svgParsing.d.ts.map +1 -1
  247. package/eslint.config.mjs +2 -0
  248. package/extensions/cropping_controls/croppingControls.spec.ts +115 -0
  249. package/extensions/cropping_controls/croppingControls.ts +150 -0
  250. package/extensions/cropping_controls/croppingHandlers.spec.ts +579 -0
  251. package/extensions/cropping_controls/croppingHandlers.ts +285 -0
  252. package/extensions/cropping_controls/enterCropMode.ts +30 -0
  253. package/extensions/cropping_controls/renderCornerControl.ts +53 -0
  254. package/extensions/index.ts +9 -0
  255. package/fabric.ts +1 -0
  256. package/package.json +17 -8
  257. package/src/ClassRegistry.spec.ts +18 -19
  258. package/src/EventTypeDefs.ts +15 -11
  259. package/src/Pattern/Pattern.spec.ts +12 -0
  260. package/src/Pattern/Pattern.ts +3 -2
  261. package/src/Shadow.ts +9 -8
  262. package/src/brushes/PencilBrush.spec.ts +11 -11
  263. package/src/canvas/Canvas-dispose.spec.ts +8 -7
  264. package/src/canvas/Canvas.spec.ts +27 -29
  265. package/src/canvas/CanvasOptions.ts +2 -1
  266. package/src/canvas/SelectableCanvas.ts +38 -15
  267. package/src/canvas/StaticCanvas.spec.ts +20 -0
  268. package/src/canvas/StaticCanvas.ts +7 -4
  269. package/src/canvas/StaticCanvasOptions.ts +1 -3
  270. package/src/constants.ts +1 -0
  271. package/src/controls/Control.spec.ts +102 -0
  272. package/src/controls/Control.ts +71 -2
  273. package/src/controls/changeHeight.spec.ts +147 -0
  274. package/src/controls/changeWidth.ts +68 -35
  275. package/src/controls/controlRendering.ts +20 -48
  276. package/src/controls/index.ts +7 -1
  277. package/src/gradient/Gradient.spec.ts +101 -46
  278. package/src/gradient/Gradient.ts +27 -14
  279. package/src/shapes/Circle.spec.ts +10 -39
  280. package/src/shapes/Circle.ts +11 -11
  281. package/src/shapes/Ellipse.spec.ts +8 -37
  282. package/src/shapes/Ellipse.ts +7 -7
  283. package/src/shapes/Group.ts +3 -3
  284. package/src/shapes/IText/IText-click-behavior.spec.ts +36 -49
  285. package/src/shapes/IText/IText.ts +5 -6
  286. package/src/shapes/IText/ITextKeyBehavior.test.ts +0 -1
  287. package/src/shapes/IText/__snapshots__/ITextBehavior.test.ts.snap +6 -6
  288. package/src/shapes/Image.spec.ts +17 -33
  289. package/src/shapes/Image.ts +15 -11
  290. package/src/shapes/Line.spec.ts +4 -30
  291. package/src/shapes/Line.ts +11 -16
  292. package/src/shapes/Object/FabricObjectSVGExportMixin.ts +11 -4
  293. package/src/shapes/Object/InteractiveObject.ts +4 -4
  294. package/src/shapes/Object/Object.ts +6 -5
  295. package/src/shapes/Object/ObjectGeometry.spec.ts +15 -0
  296. package/src/shapes/Object/ObjectGeometry.ts +1 -1
  297. package/src/shapes/Object/objectSvgExport.spec.ts +112 -0
  298. package/src/shapes/Object/types/FabricObjectProps.ts +1 -4
  299. package/src/shapes/Object/types/ObjectProps.ts +1 -3
  300. package/src/shapes/Path.spec.ts +4 -27
  301. package/src/shapes/Path.ts +2 -4
  302. package/src/shapes/Polygon.spec.ts +4 -31
  303. package/src/shapes/Polyline.spec.ts +4 -31
  304. package/src/shapes/Polyline.ts +11 -12
  305. package/src/shapes/Rect.spec.ts +25 -33
  306. package/src/shapes/Rect.ts +7 -7
  307. package/src/shapes/Text/StyledText.ts +0 -3
  308. package/src/shapes/Text/Text.spec.ts +3 -32
  309. package/src/shapes/Text/Text.ts +5 -6
  310. package/src/shapes/Text/TextSVGExportMixin.spec.ts +9 -0
  311. package/src/shapes/Text/TextSVGExportMixin.ts +14 -16
  312. package/src/shapes/Text/__snapshots__/Text.spec.ts.snap +1 -1
  313. package/src/shapes/Text/__snapshots__/TextSVGExportMixin.spec.ts.snap +1 -1
  314. package/src/shapes/Textbox.spec.ts +5 -5
  315. package/src/shapes/Textbox.ts +6 -5
  316. package/src/shapes/Triangle.ts +4 -4
  317. package/src/shapes/__snapshots__/Image.spec.ts.snap +4 -4
  318. package/src/shapes/__snapshots__/Textbox.spec.ts.snap +5 -5
  319. package/src/util/lang_string.ts +3 -2
  320. package/src/util/misc/svgParsing.ts +2 -1
  321. package/tsconfig.spec.json +1 -0
  322. package/vitest.config.ts +12 -2
  323. package/vitest.extend.ts +6 -2
@@ -1,5 +1,4 @@
1
- import { STROKE, FILL, twoMathPi } from '../constants.mjs';
2
- import { degreesToRadians } from '../util/misc/radiansDegreesConversion.mjs';
1
+ import { twoMathPi } from '../constants.mjs';
3
2
 
4
3
  /**
5
4
  * Render a round control, as per fabric features.
@@ -13,33 +12,24 @@ import { degreesToRadians } from '../util/misc/radiansDegreesConversion.mjs';
13
12
  * @param {FabricObject} fabricObject the fabric object for which we are rendering controls
14
13
  */
15
14
  function renderCircleControl(ctx, left, top, styleOverride, fabricObject) {
16
- styleOverride = styleOverride || {};
17
- const xSize = this.sizeX || styleOverride.cornerSize || fabricObject.cornerSize,
18
- ySize = this.sizeY || styleOverride.cornerSize || fabricObject.cornerSize,
19
- transparentCorners = typeof styleOverride.transparentCorners !== 'undefined' ? styleOverride.transparentCorners : fabricObject.transparentCorners,
20
- methodName = transparentCorners ? STROKE : FILL,
21
- stroke = !transparentCorners && (styleOverride.cornerStrokeColor || fabricObject.cornerStrokeColor);
22
- let myLeft = left,
23
- myTop = top,
24
- size;
25
15
  ctx.save();
26
- ctx.fillStyle = styleOverride.cornerColor || fabricObject.cornerColor || '';
27
- ctx.strokeStyle = styleOverride.cornerStrokeColor || fabricObject.cornerStrokeColor || '';
16
+ const {
17
+ stroke,
18
+ xSize,
19
+ ySize,
20
+ opName
21
+ } = this.commonRenderProps(ctx, left, top, fabricObject, styleOverride);
22
+ let size = xSize;
28
23
  // TODO: use proper ellipse code.
29
24
  if (xSize > ySize) {
30
- size = xSize;
31
25
  ctx.scale(1.0, ySize / xSize);
32
- myTop = top * xSize / ySize;
33
26
  } else if (ySize > xSize) {
34
27
  size = ySize;
35
28
  ctx.scale(xSize / ySize, 1.0);
36
- myLeft = left * ySize / xSize;
37
- } else {
38
- size = xSize;
39
29
  }
40
30
  ctx.beginPath();
41
- ctx.arc(myLeft, myTop, size / 2, 0, twoMathPi, false);
42
- ctx[methodName]();
31
+ ctx.arc(0, 0, size / 2, 0, twoMathPi, false);
32
+ ctx[opName]();
43
33
  if (stroke) {
44
34
  ctx.stroke();
45
35
  }
@@ -58,25 +48,19 @@ function renderCircleControl(ctx, left, top, styleOverride, fabricObject) {
58
48
  * @param {FabricObject} fabricObject the fabric object for which we are rendering controls
59
49
  */
60
50
  function renderSquareControl(ctx, left, top, styleOverride, fabricObject) {
61
- styleOverride = styleOverride || {};
62
- const xSize = this.sizeX || styleOverride.cornerSize || fabricObject.cornerSize,
63
- ySize = this.sizeY || styleOverride.cornerSize || fabricObject.cornerSize,
64
- transparentCorners = typeof styleOverride.transparentCorners !== 'undefined' ? styleOverride.transparentCorners : fabricObject.transparentCorners,
65
- methodName = transparentCorners ? STROKE : FILL,
66
- stroke = !transparentCorners && (styleOverride.cornerStrokeColor || fabricObject.cornerStrokeColor),
51
+ ctx.save();
52
+ const {
53
+ stroke,
54
+ xSize,
55
+ ySize,
56
+ opName
57
+ } = this.commonRenderProps(ctx, left, top, fabricObject, styleOverride),
67
58
  xSizeBy2 = xSize / 2,
68
59
  ySizeBy2 = ySize / 2;
69
- ctx.save();
70
- ctx.fillStyle = styleOverride.cornerColor || fabricObject.cornerColor || '';
71
- ctx.strokeStyle = styleOverride.cornerStrokeColor || fabricObject.cornerStrokeColor || '';
72
- ctx.translate(left, top);
73
- // angle is relative to canvas plane
74
- const angle = fabricObject.getTotalAngle();
75
- ctx.rotate(degreesToRadians(angle));
76
60
  // this does not work, and fixed with ( && ) does not make sense.
77
61
  // to have real transparent corners we need the controls on upperCanvas
78
62
  // transparentCorners || ctx.clearRect(-xSizeBy2, -ySizeBy2, xSize, ySize);
79
- ctx[`${methodName}Rect`](-xSizeBy2, -ySizeBy2, xSize, ySize);
63
+ ctx[`${opName}Rect`](-xSizeBy2, -ySizeBy2, xSize, ySize);
80
64
  if (stroke) {
81
65
  ctx.strokeRect(-xSizeBy2, -ySizeBy2, xSize, ySize);
82
66
  }
@@ -1 +1 @@
1
- {"version":3,"file":"controlRendering.mjs","sources":["../../../src/controls/controlRendering.ts"],"sourcesContent":["import { FILL, STROKE, twoMathPi } from '../constants';\nimport type { InteractiveFabricObject } from '../shapes/Object/InteractiveObject';\nimport { degreesToRadians } from '../util/misc/radiansDegreesConversion';\nimport type { Control } from './Control';\n\nexport type ControlRenderingStyleOverride = Partial<\n Pick<\n InteractiveFabricObject,\n | 'cornerStyle'\n | 'cornerSize'\n | 'cornerColor'\n | 'cornerStrokeColor'\n | 'cornerDashArray'\n | 'transparentCorners'\n >\n>;\n\nexport type ControlRenderer<\n O extends InteractiveFabricObject = InteractiveFabricObject,\n> = (\n ctx: CanvasRenderingContext2D,\n left: number,\n top: number,\n styleOverride: ControlRenderingStyleOverride,\n fabricObject: O,\n) => void;\n\n/**\n * Render a round control, as per fabric features.\n * This function is written to respect object properties like transparentCorners, cornerSize\n * cornerColor, cornerStrokeColor\n * plus the addition of offsetY and offsetX.\n * @param {CanvasRenderingContext2D} ctx context to render on\n * @param {Number} left x coordinate where the control center should be\n * @param {Number} top y coordinate where the control center should be\n * @param {Object} styleOverride override for FabricObject controls style\n * @param {FabricObject} fabricObject the fabric object for which we are rendering controls\n */\nexport function renderCircleControl(\n this: Control,\n ctx: CanvasRenderingContext2D,\n left: number,\n top: number,\n styleOverride: ControlRenderingStyleOverride,\n fabricObject: InteractiveFabricObject,\n) {\n styleOverride = styleOverride || {};\n const xSize =\n this.sizeX || styleOverride.cornerSize || fabricObject.cornerSize,\n ySize = this.sizeY || styleOverride.cornerSize || fabricObject.cornerSize,\n transparentCorners =\n typeof styleOverride.transparentCorners !== 'undefined'\n ? styleOverride.transparentCorners\n : fabricObject.transparentCorners,\n methodName = transparentCorners ? STROKE : FILL,\n stroke =\n !transparentCorners &&\n (styleOverride.cornerStrokeColor || fabricObject.cornerStrokeColor);\n let myLeft = left,\n myTop = top,\n size;\n ctx.save();\n ctx.fillStyle = styleOverride.cornerColor || fabricObject.cornerColor || '';\n ctx.strokeStyle =\n styleOverride.cornerStrokeColor || fabricObject.cornerStrokeColor || '';\n // TODO: use proper ellipse code.\n if (xSize > ySize) {\n size = xSize;\n ctx.scale(1.0, ySize / xSize);\n myTop = (top * xSize) / ySize;\n } else if (ySize > xSize) {\n size = ySize;\n ctx.scale(xSize / ySize, 1.0);\n myLeft = (left * ySize) / xSize;\n } else {\n size = xSize;\n }\n ctx.beginPath();\n ctx.arc(myLeft, myTop, size / 2, 0, twoMathPi, false);\n ctx[methodName]();\n if (stroke) {\n ctx.stroke();\n }\n ctx.restore();\n}\n\n/**\n * Render a square control, as per fabric features.\n * This function is written to respect object properties like transparentCorners, cornerSize\n * cornerColor, cornerStrokeColor\n * plus the addition of offsetY and offsetX.\n * @param {CanvasRenderingContext2D} ctx context to render on\n * @param {Number} left x coordinate where the control center should be\n * @param {Number} top y coordinate where the control center should be\n * @param {Object} styleOverride override for FabricObject controls style\n * @param {FabricObject} fabricObject the fabric object for which we are rendering controls\n */\nexport function renderSquareControl(\n this: Control,\n ctx: CanvasRenderingContext2D,\n left: number,\n top: number,\n styleOverride: ControlRenderingStyleOverride,\n fabricObject: InteractiveFabricObject,\n) {\n styleOverride = styleOverride || {};\n const xSize =\n this.sizeX || styleOverride.cornerSize || fabricObject.cornerSize,\n ySize = this.sizeY || styleOverride.cornerSize || fabricObject.cornerSize,\n transparentCorners =\n typeof styleOverride.transparentCorners !== 'undefined'\n ? styleOverride.transparentCorners\n : fabricObject.transparentCorners,\n methodName = transparentCorners ? STROKE : FILL,\n stroke =\n !transparentCorners &&\n (styleOverride.cornerStrokeColor || fabricObject.cornerStrokeColor),\n xSizeBy2 = xSize / 2,\n ySizeBy2 = ySize / 2;\n ctx.save();\n ctx.fillStyle = styleOverride.cornerColor || fabricObject.cornerColor || '';\n ctx.strokeStyle =\n styleOverride.cornerStrokeColor || fabricObject.cornerStrokeColor || '';\n ctx.translate(left, top);\n // angle is relative to canvas plane\n const angle = fabricObject.getTotalAngle();\n ctx.rotate(degreesToRadians(angle));\n // this does not work, and fixed with ( && ) does not make sense.\n // to have real transparent corners we need the controls on upperCanvas\n // transparentCorners || ctx.clearRect(-xSizeBy2, -ySizeBy2, xSize, ySize);\n ctx[`${methodName}Rect`](-xSizeBy2, -ySizeBy2, xSize, ySize);\n if (stroke) {\n ctx.strokeRect(-xSizeBy2, -ySizeBy2, xSize, ySize);\n }\n ctx.restore();\n}\n"],"names":["renderCircleControl","ctx","left","top","styleOverride","fabricObject","xSize","sizeX","cornerSize","ySize","sizeY","transparentCorners","methodName","STROKE","FILL","stroke","cornerStrokeColor","myLeft","myTop","size","save","fillStyle","cornerColor","strokeStyle","scale","beginPath","arc","twoMathPi","restore","renderSquareControl","xSizeBy2","ySizeBy2","translate","angle","getTotalAngle","rotate","degreesToRadians","strokeRect"],"mappings":";;;AA2BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,mBAAmBA,CAEjCC,GAA6B,EAC7BC,IAAY,EACZC,GAAW,EACXC,aAA4C,EAC5CC,YAAqC,EACrC;AACAD,EAAAA,aAAa,GAAGA,aAAa,IAAI,EAAE;AACnC,EAAA,MAAME,KAAK,GACP,IAAI,CAACC,KAAK,IAAIH,aAAa,CAACI,UAAU,IAAIH,YAAY,CAACG,UAAU;IACnEC,KAAK,GAAG,IAAI,CAACC,KAAK,IAAIN,aAAa,CAACI,UAAU,IAAIH,YAAY,CAACG,UAAU;AACzEG,IAAAA,kBAAkB,GAChB,OAAOP,aAAa,CAACO,kBAAkB,KAAK,WAAW,GACnDP,aAAa,CAACO,kBAAkB,GAChCN,YAAY,CAACM,kBAAkB;AACrCC,IAAAA,UAAU,GAAGD,kBAAkB,GAAGE,MAAM,GAAGC,IAAI;IAC/CC,MAAM,GACJ,CAACJ,kBAAkB,KAClBP,aAAa,CAACY,iBAAiB,IAAIX,YAAY,CAACW,iBAAiB,CAAC;EACvE,IAAIC,MAAM,GAAGf,IAAI;AACfgB,IAAAA,KAAK,GAAGf,GAAG;IACXgB,IAAI;EACNlB,GAAG,CAACmB,IAAI,EAAE;EACVnB,GAAG,CAACoB,SAAS,GAAGjB,aAAa,CAACkB,WAAW,IAAIjB,YAAY,CAACiB,WAAW,IAAI,EAAE;EAC3ErB,GAAG,CAACsB,WAAW,GACbnB,aAAa,CAACY,iBAAiB,IAAIX,YAAY,CAACW,iBAAiB,IAAI,EAAE;AACzE;EACA,IAAIV,KAAK,GAAGG,KAAK,EAAE;AACjBU,IAAAA,IAAI,GAAGb,KAAK;IACZL,GAAG,CAACuB,KAAK,CAAC,GAAG,EAAEf,KAAK,GAAGH,KAAK,CAAC;AAC7BY,IAAA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,MAAM,GACJ,CAACJ,kBAAkB,KAClBP,aAAa,CAACY,iBAAiB,IAAIX,YAAY,CAACW,iBAAiB,CAAC;IACrEc,QAAQ,GAAGxB,KAAK,GAAG,CAAC;IACpByB,QAAQ,GAAGtB,KAAK,GAAG,CAAC;EACtBR,GAAG,CAACmB,IAAI,EAAE;EACVnB,GAAG,CAACoB,SAAS,GAAGjB,aAAa,CAACkB,WAAW,IAAIjB,YAAY,CAACiB,WAAW,IAAI,EAAE;EAC3ErB,GAAG,CAACsB,WAAW,GACbnB,aAAa,CAACY,iBAAiB,IAAIX,YAAY,CAACW,iBAAiB,IAAI,EAAE;AACzEf,EAAAA,GAAG,CAAC+B,SAAS,CAAC9B,IAAI,EAAEC,GAAG,CAAC;AACxB;AACA,EAAA,MAAM8B,KAAK,GAAG5B,YAAY,CAAC6B,aAAa,EAAE;AAC1CjC,EAAAA,GAAG,CAACkC,MAAM,CAACC,gBAAgB,CAACH,KAAK,CAAC,CAAC;AACnC;AACA;AACA;AACAhC,EAAAA,GAAG,CAAC,CAAA,EAAGW,UAAU,CAAA,IAAA,CAAM,CAAC,CAAC,CAACkB,QAAQ,EAAE,CAACC,QAAQ,EAAEzB,KAAK,EAAEG,KAAK,CAAC;AAC5D,EAAA,IAAIM,MAAM,EAAE;AACVd,IAAAA,GAAG,CAACoC,UAAU,CAAC,CAACP,QAAQ,EAAE,CAACC,QAAQ,EAAEzB,KAAK,EAAEG,KAAK,CAAC;AACpD,EAAA;EACAR,GAAG,CAAC2B,OAAO,EAAE;AACf;;;;"}
1
+ {"version":3,"file":"controlRendering.mjs","sources":["../../../src/controls/controlRendering.ts"],"sourcesContent":["import { twoMathPi } from '../constants';\nimport type { InteractiveFabricObject } from '../shapes/Object/InteractiveObject';\nimport type { Control } from './Control';\n\nexport type ControlRenderingStyleOverride = Partial<\n Pick<\n InteractiveFabricObject,\n | 'cornerStyle'\n | 'cornerSize'\n | 'cornerColor'\n | 'cornerStrokeColor'\n | 'cornerDashArray'\n | 'transparentCorners'\n >\n>;\n\nexport type ControlRenderer<\n O extends InteractiveFabricObject = InteractiveFabricObject,\n> = (\n ctx: CanvasRenderingContext2D,\n left: number,\n top: number,\n styleOverride: ControlRenderingStyleOverride,\n fabricObject: O,\n) => void;\n\n/**\n * Render a round control, as per fabric features.\n * This function is written to respect object properties like transparentCorners, cornerSize\n * cornerColor, cornerStrokeColor\n * plus the addition of offsetY and offsetX.\n * @param {CanvasRenderingContext2D} ctx context to render on\n * @param {Number} left x coordinate where the control center should be\n * @param {Number} top y coordinate where the control center should be\n * @param {Object} styleOverride override for FabricObject controls style\n * @param {FabricObject} fabricObject the fabric object for which we are rendering controls\n */\nexport function renderCircleControl(\n this: Control,\n ctx: CanvasRenderingContext2D,\n left: number,\n top: number,\n styleOverride: ControlRenderingStyleOverride,\n fabricObject: InteractiveFabricObject,\n) {\n ctx.save();\n const { stroke, xSize, ySize, opName } = this.commonRenderProps(\n ctx,\n left,\n top,\n fabricObject,\n styleOverride,\n );\n let size = xSize;\n // TODO: use proper ellipse code.\n if (xSize > ySize) {\n ctx.scale(1.0, ySize / xSize);\n } else if (ySize > xSize) {\n size = ySize;\n ctx.scale(xSize / ySize, 1.0);\n }\n ctx.beginPath();\n ctx.arc(0, 0, size / 2, 0, twoMathPi, false);\n ctx[opName]();\n if (stroke) {\n ctx.stroke();\n }\n ctx.restore();\n}\n\n/**\n * Render a square control, as per fabric features.\n * This function is written to respect object properties like transparentCorners, cornerSize\n * cornerColor, cornerStrokeColor\n * plus the addition of offsetY and offsetX.\n * @param {CanvasRenderingContext2D} ctx context to render on\n * @param {Number} left x coordinate where the control center should be\n * @param {Number} top y coordinate where the control center should be\n * @param {Object} styleOverride override for FabricObject controls style\n * @param {FabricObject} fabricObject the fabric object for which we are rendering controls\n */\nexport function renderSquareControl(\n this: Control,\n ctx: CanvasRenderingContext2D,\n left: number,\n top: number,\n styleOverride: ControlRenderingStyleOverride,\n fabricObject: InteractiveFabricObject,\n) {\n ctx.save();\n const { stroke, xSize, ySize, opName } = this.commonRenderProps(\n ctx,\n left,\n top,\n fabricObject,\n styleOverride,\n ),\n xSizeBy2 = xSize / 2,\n ySizeBy2 = ySize / 2;\n // this does not work, and fixed with ( && ) does not make sense.\n // to have real transparent corners we need the controls on upperCanvas\n // transparentCorners || ctx.clearRect(-xSizeBy2, -ySizeBy2, xSize, ySize);\n ctx[`${opName}Rect`](-xSizeBy2, -ySizeBy2, xSize, ySize);\n if (stroke) {\n ctx.strokeRect(-xSizeBy2, -ySizeBy2, xSize, ySize);\n }\n ctx.restore();\n}\n"],"names":["renderCircleControl","ctx","left","top","styleOverride","fabricObject","save","stroke","xSize","ySize","opName","commonRenderProps","size","scale","beginPath","arc","twoMathPi","restore","renderSquareControl","xSizeBy2","ySizeBy2","strokeRect"],"mappings":";;AA0BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,mBAAmBA,CAEjCC,GAA6B,EAC7BC,IAAY,EACZC,GAAW,EACXC,aAA4C,EAC5CC,YAAqC,EACrC;EACAJ,GAAG,CAACK,IAAI,EAAE;EACV,MAAM;IAAEC,MAAM;IAAEC,KAAK;IAAEC,KAAK;AAAEC,IAAAA;AAAO,GAAC,GAAG,IAAI,CAACC,iBAAiB,CAC7DV,GAAG,EACHC,IAAI,EACJC,GAAG,EACHE,YAAY,EACZD,aACF,CAAC;EACD,IAAIQ,IAAI,GAAGJ,KAAK;AAChB;EACA,IAAIA,KAAK,GAAGC,KAAK,EAAE;IACjBR,GAAG,CAACY,KAAK,CAAC,GAAG,EAAEJ,KAAK,GAAGD,KAAK,CAAC;AAC/B,EAAA,CAAC,MAAM,IAAIC,KAAK,GAAGD,KAAK,EAAE;AACxBI,IAAAA,IAAI,GAAGH,KAAK;IACZR,GAAG,CAACY,KAAK,CAACL,KAAK,GAAGC,KAAK,EAAE,GAAG,CAAC;AAC/B,EAAA;EACAR,GAAG,CAACa,SAAS,EAAE;AACfb,EAAAA,GAAG,CAACc,GAAG,CAAC,CAAC,EAAE,CAAC,EAAEH,IAAI,GAAG,CAAC,EAAE,CAAC,EAAEI,SAAS,EAAE,KAAK,CAAC;AAC5Cf,EAAAA,GAAG,CAACS,MAAM,CAAC,EAAE;AACb,EAAA,IAAIH,MAAM,EAAE;IACVN,GAAG,CAACM,MAAM,EAAE;AACd,EAAA;EACAN,GAAG,CAACgB,OAAO,EAAE;AACf;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,mBAAmBA,CAEjCjB,GAA6B,EAC7BC,IAAY,EACZC,GAAW,EACXC,aAA4C,EAC5CC,YAAqC,EACrC;EACAJ,GAAG,CAACK,IAAI,EAAE;EACV,MAAM;MAAEC,MAAM;MAAEC,KAAK;MAAEC,KAAK;AAAEC,MAAAA;AAAO,KAAC,GAAG,IAAI,CAACC,iBAAiB,CAC3DV,GAAG,EACHC,IAAI,EACJC,GAAG,EACHE,YAAY,EACZD,aACF,CAAC;IACDe,QAAQ,GAAGX,KAAK,GAAG,CAAC;IACpBY,QAAQ,GAAGX,KAAK,GAAG,CAAC;AACtB;AACA;AACA;AACAR,EAAAA,GAAG,CAAC,CAAA,EAAGS,MAAM,CAAA,IAAA,CAAM,CAAC,CAAC,CAACS,QAAQ,EAAE,CAACC,QAAQ,EAAEZ,KAAK,EAAEC,KAAK,CAAC;AACxD,EAAA,IAAIF,MAAM,EAAE;AACVN,IAAAA,GAAG,CAACoB,UAAU,CAAC,CAACF,QAAQ,EAAE,CAACC,QAAQ,EAAEZ,KAAK,EAAEC,KAAK,CAAC;AACpD,EAAA;EACAR,GAAG,CAACgB,OAAO,EAAE;AACf;;;;"}
@@ -1,5 +1,6 @@
1
- export { changeWidth } from './changeWidth';
1
+ export { changeWidth, changeObjectWidth, changeHeight, changeObjectHeight, } from './changeWidth';
2
2
  export { renderCircleControl, renderSquareControl } from './controlRendering';
3
+ export type { ControlRenderingStyleOverride } from './controlRendering';
3
4
  export * from './commonControls';
4
5
  export { dragHandler } from './drag';
5
6
  export * from './polyControl';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/controls/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9E,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACtE,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,QAAQ,EACR,QAAQ,GACT,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,qBAAqB,EACrB,2BAA2B,EAC3B,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/controls/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9E,YAAY,EAAE,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AACxE,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACtE,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,QAAQ,EACR,QAAQ,GACT,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,qBAAqB,EACrB,2BAA2B,EAC3B,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,cAAc,eAAe,CAAC"}
@@ -1,2 +1,2 @@
1
- export{changeWidth}from"./changeWidth.min.mjs";export{renderCircleControl,renderSquareControl}from"./controlRendering.min.mjs";export{createObjectDefaultControls,createResizeControls,createTextboxDefaultControls}from"./commonControls.min.mjs";export{dragHandler}from"./drag.min.mjs";export{createPolyActionHandler,createPolyControls,createPolyPositionHandler,factoryPolyActionHandler,polyActionHandler}from"./polyControl.min.mjs";export{rotationStyleHandler,rotationWithSnapping}from"./rotate.min.mjs";export{scaleCursorStyleHandler,scalingEqually,scalingX,scalingY}from"./scale.min.mjs";export{scaleOrSkewActionName,scaleSkewCursorStyleHandler,scalingXOrSkewingY,scalingYOrSkewingX}from"./scaleSkew.min.mjs";export{skewCursorStyleHandler,skewHandlerX,skewHandlerY}from"./skew.min.mjs";export{getLocalPoint}from"./util.min.mjs";export{wrapWithFireEvent}from"./wrapWithFireEvent.min.mjs";export{wrapWithFixedAnchor}from"./wrapWithFixedAnchor.min.mjs";export{createPathControls}from"./pathControl.min.mjs";
1
+ export{changeHeight,changeObjectHeight,changeObjectWidth,changeWidth}from"./changeWidth.min.mjs";export{renderCircleControl,renderSquareControl}from"./controlRendering.min.mjs";export{createObjectDefaultControls,createResizeControls,createTextboxDefaultControls}from"./commonControls.min.mjs";export{dragHandler}from"./drag.min.mjs";export{createPolyActionHandler,createPolyControls,createPolyPositionHandler,factoryPolyActionHandler,polyActionHandler}from"./polyControl.min.mjs";export{rotationStyleHandler,rotationWithSnapping}from"./rotate.min.mjs";export{scaleCursorStyleHandler,scalingEqually,scalingX,scalingY}from"./scale.min.mjs";export{scaleOrSkewActionName,scaleSkewCursorStyleHandler,scalingXOrSkewingY,scalingYOrSkewingX}from"./scaleSkew.min.mjs";export{skewCursorStyleHandler,skewHandlerX,skewHandlerY}from"./skew.min.mjs";export{getLocalPoint}from"./util.min.mjs";export{wrapWithFireEvent}from"./wrapWithFireEvent.min.mjs";export{wrapWithFixedAnchor}from"./wrapWithFixedAnchor.min.mjs";export{createPathControls}from"./pathControl.min.mjs";
2
2
  //# sourceMappingURL=index.min.mjs.map
@@ -1,4 +1,4 @@
1
- export { changeWidth } from './changeWidth.mjs';
1
+ export { changeHeight, changeObjectHeight, changeObjectWidth, changeWidth } from './changeWidth.mjs';
2
2
  export { renderCircleControl, renderSquareControl } from './controlRendering.mjs';
3
3
  export { createObjectDefaultControls, createResizeControls, createTextboxDefaultControls } from './commonControls.mjs';
4
4
  export { dragHandler } from './drag.mjs';
@@ -1 +1 @@
1
- {"version":3,"file":"Gradient.d.ts","sourceRoot":"","sources":["../../../src/gradient/Gradient.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAQ1C,OAAO,KAAK,EACV,SAAS,EACT,cAAc,EACd,eAAe,EACf,YAAY,EACZ,aAAa,EACb,UAAU,EACV,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAIpB;;;;GAIG;AACH,qBAAa,QAAQ,CACnB,CAAC,EACD,CAAC,SAAS,YAAY,GAAG,CAAC,SAAS,YAAY,GAAG,CAAC,GAAG,QAAQ;IAE9D;;;;OAIG;IACK,OAA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C,EAAE,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,EAAE,GAC5C,uBAAuB,CAAC,CAAC,CAAC;IAgB7B;;;;OAIG;IACH,KAAK,CACH,MAAM,EAAE,YAAY,EACpB,EACE,mBAAmB,EAAE,YAAY,GAClC,GAAE;QAAE,mBAAmB,CAAC,EAAE,MAAM,CAAA;KAAO;IA6H1C;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,wBAAwB,GAAG,cAAc;WAcxC,UAAU,CACrB,OAAO,EAAE,eAAe,CAAC,QAAQ,CAAC,GACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;WACjB,UAAU,CACrB,OAAO,EAAE,eAAe,CAAC,QAAQ,CAAC,GACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAe9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAyCG;IACH,MAAM,CAAC,WAAW,CAChB,EAAE,EAAE,kBAAkB,EACtB,QAAQ,EAAE,YAAY,EACtB,UAAU,EAAE,UAAU,GACrB,QAAQ,CAAC,YAAY,CAAC;CA2B1B"}
@@ -1,2 +1,2 @@
1
- import{defineProperty as t}from"../../_virtual/_rollupPluginBabelHelpers.min.mjs";import{iMatrix as o}from"../constants.min.mjs";import{parseTransformAttribute as r}from"../parser/parseTransformAttribute.min.mjs";import{uid as s}from"../util/internals/uid.min.mjs";import{pick as i}from"../util/misc/pick.min.mjs";import{matrixToSVG as e}from"../util/misc/svgExport.min.mjs";import{radialDefaultCoords as n,linearDefaultCoords as a}from"./constants.min.mjs";import{parseColorStops as f}from"./parser/parseColorStops.min.mjs";import{parseCoords as m}from"./parser/parseCoords.min.mjs";import{parseGradientUnits as d,parseType as p}from"./parser/misc.min.mjs";import{classRegistry as c}from"../ClassRegistry.min.mjs";import{isPath as h}from"../util/typeAssertions.min.mjs";class l{constructor(t){const{type:o="linear",gradientUnits:r="pixels",coords:i={},colorStops:e=[],offsetX:f=0,offsetY:m=0,gradientTransform:d,id:p}=t||{};Object.assign(this,{type:o,gradientUnits:r,coords:{..."radial"===o?n:a,...i},colorStops:e,offsetX:f,offsetY:m,gradientTransform:d,id:p?`${p}_${s()}`:s()})}addColorStop(t){for(const o in t)this.colorStops.push({offset:parseFloat(o),color:t[o]});return this}toObject(t){return{...i(this,t),type:this.type,coords:{...this.coords},colorStops:this.colorStops.map(t=>({...t})),offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?[...this.gradientTransform]:void 0}}toSVG(t){let{additionalTransform:r}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s=[],i=this.gradientTransform?this.gradientTransform.concat():o.concat(),n="pixels"===this.gradientUnits?"userSpaceOnUse":"objectBoundingBox",a=this.colorStops.map(t=>({...t})).sort((t,o)=>t.offset-o.offset);let f=-this.offsetX,m=-this.offsetY;"objectBoundingBox"===n?(f/=t.width,m/=t.height):(f+=t.width/2,m+=t.height/2),h(t)&&"percentage"!==this.gradientUnits&&(f-=t.pathOffset.x,m-=t.pathOffset.y),i[4]-=f,i[5]-=m;const d=[`id="SVGID_${this.id}"`,`gradientUnits="${n}"`,`gradientTransform="${r?r+" ":""}${e(i)}"`,""].join(" ");if("linear"===this.type){const{x1:t,y1:o,x2:r,y2:i}=this.coords;s.push("<linearGradient ",d,' x1="',t,'" y1="',o,'" x2="',r,'" y2="',i,'">\n')}else if("radial"===this.type){const{x1:t,y1:o,x2:r,y2:i,r1:e,r2:n}=this.coords,f=e>n;s.push("<radialGradient ",d,' cx="',f?t:r,'" cy="',f?o:i,'" r="',f?e:n,'" fx="',f?r:t,'" fy="',f?i:o,'">\n'),f&&(a.reverse(),a.forEach(t=>{t.offset=1-t.offset}));const m=Math.min(e,n);if(m>0){const t=m/Math.max(e,n);a.forEach(o=>{o.offset+=t*(1-o.offset)})}}return a.forEach(t=>{let{color:o,offset:r}=t;s.push(`<stop offset="${100*r}%" style="stop-color:${o};"/>\n`)}),s.push("linear"===this.type?"</linearGradient>":"</radialGradient>","\n"),s.join("")}toLive(t){const{x1:o,y1:r,x2:s,y2:i,r1:e,r2:n}=this.coords,a="linear"===this.type?t.createLinearGradient(o,r,s,i):t.createRadialGradient(o,r,e,s,i,n);return this.colorStops.forEach(t=>{let{color:o,offset:r}=t;a.addColorStop(r,o)}),a}static async fromObject(t){const{colorStops:o,gradientTransform:r}=t;return new this({...t,colorStops:o?o.map(t=>({...t})):void 0,gradientTransform:r?[...r]:void 0})}static fromElement(t,o,s){const i=d(t),e=o._findCenterFromElement();return new this({id:t.getAttribute("id")||void 0,type:p(t),coords:m(t,{width:s.viewBoxWidth||s.width,height:s.viewBoxHeight||s.height}),colorStops:f(t,s.opacity),gradientUnits:i,gradientTransform:r(t.getAttribute("gradientTransform")||""),..."pixels"===i?{offsetX:o.width/2-e.x,offsetY:o.height/2-e.y}:{offsetX:0,offsetY:0}})}}t(l,"type","Gradient"),c.setClass(l,"gradient"),c.setClass(l,"linear"),c.setClass(l,"radial");export{l as Gradient};
1
+ import{defineProperty as t}from"../../_virtual/_rollupPluginBabelHelpers.min.mjs";import{iMatrix as r}from"../constants.min.mjs";import{parseTransformAttribute as o}from"../parser/parseTransformAttribute.min.mjs";import{uid as s}from"../util/internals/uid.min.mjs";import{pick as i}from"../util/misc/pick.min.mjs";import{matrixToSVG as e}from"../util/misc/svgExport.min.mjs";import{radialDefaultCoords as n,linearDefaultCoords as a}from"./constants.min.mjs";import{parseColorStops as f}from"./parser/parseColorStops.min.mjs";import{parseCoords as m}from"./parser/parseCoords.min.mjs";import{parseGradientUnits as d,parseType as p}from"./parser/misc.min.mjs";import{classRegistry as c}from"../ClassRegistry.min.mjs";import{isPath as l}from"../util/typeAssertions.min.mjs";import{escapeXml as h}from"../util/lang_string.min.mjs";class g{constructor(t){const{type:r="linear",gradientUnits:o="pixels",coords:i={},colorStops:e=[],offsetX:f=0,offsetY:m=0,gradientTransform:d,id:p}=t||{};Object.assign(this,{type:r,gradientUnits:o,coords:{..."radial"===r?n:a,...i},colorStops:e,offsetX:f,offsetY:m,gradientTransform:d,id:p?`${p}_${s()}`:s()})}addColorStop(t){for(const r in t)this.colorStops.push({offset:parseFloat(r),color:t[r]});return this}toObject(t){return{...i(this,t),type:this.type,coords:{...this.coords},colorStops:this.colorStops.map(t=>({...t})),offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?[...this.gradientTransform]:void 0}}toSVG(t){let{additionalTransform:o}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s=[],i=this.gradientTransform?this.gradientTransform.concat():r.concat(),n="pixels"===this.gradientUnits?"userSpaceOnUse":"objectBoundingBox",a=this.colorStops.map(t=>({...t})).sort((t,r)=>t.offset-r.offset);let f=-this.offsetX,m=-this.offsetY;"objectBoundingBox"===n?(f/=t.width,m/=t.height):(f+=t.width/2,m+=t.height/2),l(t)&&"percentage"!==this.gradientUnits&&(f-=t.pathOffset.x,m-=t.pathOffset.y),i[4]-=f,i[5]-=m;const d=[`id="SVGID_${h(String(this.id))}"`,`gradientUnits="${n}"`,`gradientTransform="${o?o+" ":""}${e(i)}"`,""].join(" "),p=t=>parseFloat(String(t));if("linear"===this.type){const{x1:t,y1:r,x2:o,y2:i}=this.coords,e=p(t),n=p(r),a=p(o),f=p(i);s.push("<linearGradient ",d,' x1="',e,'" y1="',n,'" x2="',a,'" y2="',f,'">\n')}else if("radial"===this.type){const{x1:t,y1:r,x2:o,y2:i,r1:e,r2:n}=this.coords,f=p(t),m=p(r),c=p(o),l=p(i),h=p(e),g=p(n),y=h>g;s.push("<radialGradient ",d,' cx="',y?f:c,'" cy="',y?m:l,'" r="',y?h:g,'" fx="',y?c:f,'" fy="',y?l:m,'">\n'),y&&(a.reverse(),a.forEach(t=>{t.offset=1-t.offset}));const u=Math.min(h,g);if(u>0){const t=u/Math.max(h,g);a.forEach(r=>{r.offset+=t*(1-r.offset)})}}return a.forEach(t=>{let{color:r,offset:o}=t;s.push(`<stop offset="${100*o}%" style="stop-color:${r};"/>\n`)}),s.push("linear"===this.type?"</linearGradient>":"</radialGradient>","\n"),s.join("")}toLive(t){const{x1:r,y1:o,x2:s,y2:i,r1:e,r2:n}=this.coords,a="linear"===this.type?t.createLinearGradient(r,o,s,i):t.createRadialGradient(r,o,e,s,i,n);return this.colorStops.forEach(t=>{let{color:r,offset:o}=t;a.addColorStop(o,r)}),a}static async fromObject(t){const{colorStops:r,gradientTransform:o}=t;return new this({...t,colorStops:r?r.map(t=>({...t})):void 0,gradientTransform:o?[...o]:void 0})}static fromElement(t,r,s){const i=d(t),e=r._findCenterFromElement();return new this({id:t.getAttribute("id")||void 0,type:p(t),coords:m(t,{width:s.viewBoxWidth||s.width,height:s.viewBoxHeight||s.height}),colorStops:f(t,s.opacity),gradientUnits:i,gradientTransform:o(t.getAttribute("gradientTransform")||""),..."pixels"===i?{offsetX:r.width/2-e.x,offsetY:r.height/2-e.y}:{offsetX:0,offsetY:0}})}}t(g,"type","Gradient"),c.setClass(g,"gradient"),c.setClass(g,"linear"),c.setClass(g,"radial");export{g as Gradient};
2
2
  //# sourceMappingURL=Gradient.min.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Gradient.min.mjs","sources":["../../../src/gradient/Gradient.ts"],"sourcesContent":["import { iMatrix } from '../constants';\nimport { parseTransformAttribute } from '../parser/parseTransformAttribute';\nimport type { FabricObject } from '../shapes/Object/FabricObject';\nimport type { TMat2D } from '../typedefs';\nimport { uid } from '../util/internals/uid';\nimport { pick } from '../util/misc/pick';\nimport { matrixToSVG } from '../util/misc/svgExport';\nimport { linearDefaultCoords, radialDefaultCoords } from './constants';\nimport { parseColorStops } from './parser/parseColorStops';\nimport { parseCoords } from './parser/parseCoords';\nimport { parseType, parseGradientUnits } from './parser/misc';\nimport type {\n ColorStop,\n GradientCoords,\n GradientOptions,\n GradientType,\n GradientUnits,\n SVGOptions,\n SerializedGradientProps,\n} from './typedefs';\nimport { classRegistry } from '../ClassRegistry';\nimport { isPath } from '../util/typeAssertions';\n\n/**\n * Gradient class\n * @class Gradient\n * @see {@link http://fabric5.fabricjs.com/fabric-intro-part-2#gradients}\n */\nexport class Gradient<\n S,\n T extends GradientType = S extends GradientType ? S : 'linear',\n> {\n /**\n * Horizontal offset for aligning gradients coming from SVG when outside pathgroups\n * @type Number\n * @default 0\n */\n declare offsetX: number;\n\n /**\n * Vertical offset for aligning gradients coming from SVG when outside pathgroups\n * @type Number\n * @default 0\n */\n declare offsetY: number;\n\n /**\n * A transform matrix to apply to the gradient before painting.\n * Imported from svg gradients, is not applied with the current transform in the center.\n * Before this transform is applied, the origin point is at the top left corner of the object\n * plus the addition of offsetY and offsetX.\n * @type Number[]\n * @default null\n */\n declare gradientTransform?: TMat2D;\n\n /**\n * coordinates units for coords.\n * If `pixels`, the number of coords are in the same unit of width / height.\n * If set as `percentage` the coords are still a number, but 1 means 100% of width\n * for the X and 100% of the height for the y. It can be bigger than 1 and negative.\n * allowed values pixels or percentage.\n * @type GradientUnits\n * @default 'pixels'\n */\n declare gradientUnits: GradientUnits;\n\n /**\n * Gradient type linear or radial\n * @type GradientType\n * @default 'linear'\n */\n declare type: T;\n\n /**\n * Defines how the gradient is located in space and spread\n * @type GradientCoords\n */\n declare coords: GradientCoords<T>;\n\n /**\n * Defines how many colors a gradient has and how they are located on the axis\n * defined by coords\n * @type GradientCoords\n */\n declare colorStops: ColorStop[];\n\n /**\n * If true, this object will not be exported during the serialization of a canvas\n * @type boolean\n */\n declare excludeFromExport?: boolean;\n\n /**\n * ID used for SVG export functionalities\n * @type number | string\n */\n declare readonly id: string | number;\n\n static type = 'Gradient';\n\n constructor(options: GradientOptions<T>) {\n const {\n type = 'linear' as T,\n gradientUnits = 'pixels',\n coords = {},\n colorStops = [],\n offsetX = 0,\n offsetY = 0,\n gradientTransform,\n id,\n } = options || {};\n Object.assign(this, {\n type,\n gradientUnits,\n coords: {\n ...(type === 'radial' ? radialDefaultCoords : linearDefaultCoords),\n ...coords,\n },\n colorStops,\n offsetX,\n offsetY,\n gradientTransform,\n id: id ? `${id}_${uid()}` : uid(),\n });\n }\n\n /**\n * Adds another colorStop\n * @param {Record<string, string>} colorStop Object with offset and color\n * @return {Gradient} thisArg\n */\n addColorStop(colorStops: Record<string, string>) {\n for (const position in colorStops) {\n this.colorStops.push({\n offset: parseFloat(position),\n color: colorStops[position],\n });\n }\n return this;\n }\n\n /**\n * Returns object representation of a gradient\n * @param {string[]} [propertiesToInclude] Any properties that you might want to additionally include in the output\n * @return {object}\n */\n toObject(\n propertiesToInclude?: (keyof this | string)[],\n ): SerializedGradientProps<T> {\n return {\n ...pick(this, propertiesToInclude as (keyof this)[]),\n type: this.type,\n coords: { ...this.coords },\n colorStops: this.colorStops.map((colorStop) => ({ ...colorStop })),\n offsetX: this.offsetX,\n offsetY: this.offsetY,\n gradientUnits: this.gradientUnits,\n gradientTransform: this.gradientTransform\n ? [...this.gradientTransform]\n : undefined,\n };\n }\n\n /* _TO_SVG_START_ */\n /**\n * Returns SVG representation of an gradient\n * @param {FabricObject} object Object to create a gradient for\n * @return {String} SVG representation of an gradient (linear/radial)\n */\n toSVG(\n object: FabricObject,\n {\n additionalTransform: preTransform,\n }: { additionalTransform?: string } = {},\n ) {\n const markup = [],\n transform = (\n this.gradientTransform\n ? this.gradientTransform.concat()\n : iMatrix.concat()\n ) as TMat2D,\n gradientUnits =\n this.gradientUnits === 'pixels'\n ? 'userSpaceOnUse'\n : 'objectBoundingBox';\n // colorStops must be sorted ascending, and guarded against deep mutations\n const colorStops = this.colorStops\n .map((colorStop) => ({ ...colorStop }))\n .sort((a, b) => {\n return a.offset - b.offset;\n });\n\n let offsetX = -this.offsetX,\n offsetY = -this.offsetY;\n if (gradientUnits === 'objectBoundingBox') {\n offsetX /= object.width;\n offsetY /= object.height;\n } else {\n offsetX += object.width / 2;\n offsetY += object.height / 2;\n }\n // todo what about polygon/polyline?\n if (isPath(object) && this.gradientUnits !== 'percentage') {\n offsetX -= object.pathOffset.x;\n offsetY -= object.pathOffset.y;\n }\n transform[4] -= offsetX;\n transform[5] -= offsetY;\n\n const commonAttributes = [\n `id=\"SVGID_${this.id}\"`,\n `gradientUnits=\"${gradientUnits}\"`,\n `gradientTransform=\"${\n preTransform ? preTransform + ' ' : ''\n }${matrixToSVG(transform)}\"`,\n '',\n ].join(' ');\n\n if (this.type === 'linear') {\n const { x1, y1, x2, y2 } = this.coords;\n markup.push(\n '<linearGradient ',\n commonAttributes,\n ' x1=\"',\n x1,\n '\" y1=\"',\n y1,\n '\" x2=\"',\n x2,\n '\" y2=\"',\n y2,\n '\">\\n',\n );\n } else if (this.type === 'radial') {\n const { x1, y1, x2, y2, r1, r2 } = this\n .coords as GradientCoords<'radial'>;\n const needsSwap = r1 > r2;\n // svg radial gradient has just 1 radius. the biggest.\n markup.push(\n '<radialGradient ',\n commonAttributes,\n ' cx=\"',\n needsSwap ? x1 : x2,\n '\" cy=\"',\n needsSwap ? y1 : y2,\n '\" r=\"',\n needsSwap ? r1 : r2,\n '\" fx=\"',\n needsSwap ? x2 : x1,\n '\" fy=\"',\n needsSwap ? y2 : y1,\n '\">\\n',\n );\n if (needsSwap) {\n // svg goes from internal to external radius. if radius are inverted, swap color stops.\n colorStops.reverse(); // mutates array\n colorStops.forEach((colorStop) => {\n colorStop.offset = 1 - colorStop.offset;\n });\n }\n const minRadius = Math.min(r1, r2);\n if (minRadius > 0) {\n // i have to shift all colorStops and add new one in 0.\n const maxRadius = Math.max(r1, r2),\n percentageShift = minRadius / maxRadius;\n colorStops.forEach((colorStop) => {\n colorStop.offset += percentageShift * (1 - colorStop.offset);\n });\n }\n }\n\n colorStops.forEach(({ color, offset }) => {\n markup.push(\n `<stop offset=\"${offset * 100}%\" style=\"stop-color:${color};\"/>\\n`,\n );\n });\n\n markup.push(\n this.type === 'linear' ? '</linearGradient>' : '</radialGradient>',\n '\\n',\n );\n\n return markup.join('');\n }\n /* _TO_SVG_END_ */\n\n /**\n * Returns an instance of CanvasGradient\n * @param {CanvasRenderingContext2D} ctx Context to render on\n * @return {CanvasGradient}\n */\n toLive(ctx: CanvasRenderingContext2D): CanvasGradient {\n const { x1, y1, x2, y2, r1, r2 } = this.coords as GradientCoords<'radial'>;\n const gradient =\n this.type === 'linear'\n ? ctx.createLinearGradient(x1, y1, x2, y2)\n : ctx.createRadialGradient(x1, y1, r1, x2, y2, r2);\n\n this.colorStops.forEach(({ color, offset }) => {\n gradient.addColorStop(offset, color);\n });\n\n return gradient;\n }\n\n static async fromObject(\n options: GradientOptions<'linear'>,\n ): Promise<Gradient<'linear'>>;\n static async fromObject(\n options: GradientOptions<'radial'>,\n ): Promise<Gradient<'radial'>>;\n static async fromObject(\n options: GradientOptions<'linear'> | GradientOptions<'radial'>,\n ) {\n const { colorStops, gradientTransform } = options;\n return new this({\n ...options,\n colorStops: colorStops\n ? colorStops.map((colorStop) => ({ ...colorStop }))\n : undefined,\n gradientTransform: gradientTransform ? [...gradientTransform] : undefined,\n });\n }\n\n /* _FROM_SVG_START_ */\n /**\n * Returns {@link Gradient} instance from an SVG element\n * @param {SVGGradientElement} el SVG gradient element\n * @param {FabricObject} instance\n * @param {String} opacity A fill-opacity or stroke-opacity attribute to multiply to each stop's opacity.\n * @param {SVGOptions} svgOptions an object containing the size of the SVG in order to parse correctly gradients\n * that uses gradientUnits as 'userSpaceOnUse' and percentages.\n * @return {Gradient} Gradient instance\n * @see http://www.w3.org/TR/SVG/pservers.html#LinearGradientElement\n * @see http://www.w3.org/TR/SVG/pservers.html#RadialGradientElement\n *\n * @example\n *\n * <linearGradient id=\"linearGrad1\">\n * <stop offset=\"0%\" stop-color=\"white\"/>\n * <stop offset=\"100%\" stop-color=\"black\"/>\n * </linearGradient>\n *\n * OR\n *\n * <linearGradient id=\"linearGrad2\">\n * <stop offset=\"0\" style=\"stop-color:rgb(255,255,255)\"/>\n * <stop offset=\"1\" style=\"stop-color:rgb(0,0,0)\"/>\n * </linearGradient>\n *\n * OR\n *\n * <radialGradient id=\"radialGrad1\">\n * <stop offset=\"0%\" stop-color=\"white\" stop-opacity=\"1\" />\n * <stop offset=\"50%\" stop-color=\"black\" stop-opacity=\"0.5\" />\n * <stop offset=\"100%\" stop-color=\"white\" stop-opacity=\"1\" />\n * </radialGradient>\n *\n * OR\n *\n * <radialGradient id=\"radialGrad2\">\n * <stop offset=\"0\" stop-color=\"rgb(255,255,255)\" />\n * <stop offset=\"0.5\" stop-color=\"rgb(0,0,0)\" />\n * <stop offset=\"1\" stop-color=\"rgb(255,255,255)\" />\n * </radialGradient>\n *\n */\n static fromElement(\n el: SVGGradientElement,\n instance: FabricObject,\n svgOptions: SVGOptions,\n ): Gradient<GradientType> {\n const gradientUnits = parseGradientUnits(el);\n const center = instance._findCenterFromElement();\n return new this({\n id: el.getAttribute('id') || undefined,\n type: parseType(el),\n coords: parseCoords(el, {\n width: svgOptions.viewBoxWidth || svgOptions.width,\n height: svgOptions.viewBoxHeight || svgOptions.height,\n }),\n colorStops: parseColorStops(el, svgOptions.opacity),\n gradientUnits,\n gradientTransform: parseTransformAttribute(\n el.getAttribute('gradientTransform') || '',\n ),\n ...(gradientUnits === 'pixels'\n ? {\n offsetX: instance.width / 2 - center.x,\n offsetY: instance.height / 2 - center.y,\n }\n : {\n offsetX: 0,\n offsetY: 0,\n }),\n });\n }\n /* _FROM_SVG_END_ */\n}\n\nclassRegistry.setClass(Gradient, 'gradient');\nclassRegistry.setClass(Gradient, 'linear');\nclassRegistry.setClass(Gradient, 'radial');\n"],"names":["Gradient","constructor","options","type","gradientUnits","coords","colorStops","offsetX","offsetY","gradientTransform","id","Object","assign","this","radialDefaultCoords","linearDefaultCoords","uid","addColorStop","position","push","offset","parseFloat","color","toObject","propertiesToInclude","pick","map","colorStop","undefined","toSVG","object","additionalTransform","preTransform","arguments","length","markup","transform","concat","iMatrix","sort","a","b","width","height","isPath","pathOffset","x","y","commonAttributes","matrixToSVG","join","x1","y1","x2","y2","r1","r2","needsSwap","reverse","forEach","minRadius","Math","min","percentageShift","max","_ref","toLive","ctx","gradient","createLinearGradient","createRadialGradient","_ref2","fromObject","fromElement","el","instance","svgOptions","parseGradientUnits","center","_findCenterFromElement","getAttribute","parseType","parseCoords","viewBoxWidth","viewBoxHeight","parseColorStops","opacity","parseTransformAttribute","_defineProperty","classRegistry","setClass"],"mappings":"mwBA4BO,MAAMA,EAyEXC,WAAAA,CAAYC,GACV,MAAMC,KACJA,EAAO,SAAaC,cACpBA,EAAgB,SAAQC,OACxBA,EAAS,CAAA,EAAEC,WACXA,EAAa,GAAEC,QACfA,EAAU,EAACC,QACXA,EAAU,EAACC,kBACXA,EAAiBC,GACjBA,GACER,GAAW,CAAA,EACfS,OAAOC,OAAOC,KAAM,CAClBV,OACAC,gBACAC,OAAQ,IACO,WAATF,EAAoBW,EAAsBC,KAC3CV,GAELC,aACAC,UACAC,UACAC,oBACAC,GAAIA,EAAK,GAAGA,KAAMM,MAAUA,KAEhC,CAOAC,YAAAA,CAAaX,GACX,IAAK,MAAMY,KAAYZ,EACrBO,KAAKP,WAAWa,KAAK,CACnBC,OAAQC,WAAWH,GACnBI,MAAOhB,EAAWY,KAGtB,OAAOL,IACT,CAOAU,QAAAA,CACEC,GAEA,MAAO,IACFC,EAAKZ,KAAMW,GACdrB,KAAMU,KAAKV,KACXE,OAAQ,IAAKQ,KAAKR,QAClBC,WAAYO,KAAKP,WAAWoB,IAAKC,IAAS,IAAWA,KACrDpB,QAASM,KAAKN,QACdC,QAASK,KAAKL,QACdJ,cAAeS,KAAKT,cACpBK,kBAAmBI,KAAKJ,kBACpB,IAAII,KAAKJ,wBACTmB,EAER,CAQAC,KAAAA,CACEC,GAIA,IAFEC,oBAAqBC,GACYC,UAAAC,OAAA,QAAAN,IAAAK,UAAA,GAAAA,UAAA,GAAG,CAAA,EAEtC,MAAME,EAAS,GACbC,EACEvB,KAAKJ,kBACDI,KAAKJ,kBAAkB4B,SACvBC,EAAQD,SAEdjC,EACyB,WAAvBS,KAAKT,cACD,iBACA,oBAEFE,EAAaO,KAAK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C,WAAY+E,EAAgBX,EAAIE,EAAWU,SAC3ClF,gBACAK,kBAAmB8E,EACjBb,EAAGM,aAAa,sBAAwB,OAEpB,WAAlB5E,EACA,CACEG,QAASoE,EAASjC,MAAQ,EAAIoC,EAAOhC,EACrCtC,QAASmE,EAAShC,OAAS,EAAImC,EAAO/B,GAExC,CACExC,QAAS,EACTC,QAAS,IAGnB,EAhTAgF,EAjEWxF,EAAQ,OAuEL,YA8ShByF,EAAcC,SAAS1F,EAAU,YACjCyF,EAAcC,SAAS1F,EAAU,UACjCyF,EAAcC,SAAS1F,EAAU"}
1
+ {"version":3,"file":"Gradient.min.mjs","sources":["../../../src/gradient/Gradient.ts"],"sourcesContent":["import { iMatrix } from '../constants';\nimport { parseTransformAttribute } from '../parser/parseTransformAttribute';\nimport type { FabricObject } from '../shapes/Object/FabricObject';\nimport type { TMat2D } from '../typedefs';\nimport { uid } from '../util/internals/uid';\nimport { pick } from '../util/misc/pick';\nimport { matrixToSVG } from '../util/misc/svgExport';\nimport { linearDefaultCoords, radialDefaultCoords } from './constants';\nimport { parseColorStops } from './parser/parseColorStops';\nimport { parseCoords } from './parser/parseCoords';\nimport { parseType, parseGradientUnits } from './parser/misc';\nimport type {\n ColorStop,\n GradientCoords,\n GradientOptions,\n GradientType,\n GradientUnits,\n SVGOptions,\n SerializedGradientProps,\n} from './typedefs';\nimport { classRegistry } from '../ClassRegistry';\nimport { isPath } from '../util/typeAssertions';\nimport { escapeXml } from '../util/lang_string';\n\n/**\n * Gradient class\n * @class Gradient\n * @see {@link http://fabric5.fabricjs.com/fabric-intro-part-2#gradients}\n */\nexport class Gradient<\n S,\n T extends GradientType = S extends GradientType ? S : 'linear',\n> {\n /**\n * Horizontal offset for aligning gradients coming from SVG when outside pathgroups\n * @type Number\n * @default 0\n */\n declare offsetX: number;\n\n /**\n * Vertical offset for aligning gradients coming from SVG when outside pathgroups\n * @type Number\n * @default 0\n */\n declare offsetY: number;\n\n /**\n * A transform matrix to apply to the gradient before painting.\n * Imported from svg gradients, is not applied with the current transform in the center.\n * Before this transform is applied, the origin point is at the top left corner of the object\n * plus the addition of offsetY and offsetX.\n * @type Number[]\n * @default null\n */\n declare gradientTransform?: TMat2D;\n\n /**\n * coordinates units for coords.\n * If `pixels`, the number of coords are in the same unit of width / height.\n * If set as `percentage` the coords are still a number, but 1 means 100% of width\n * for the X and 100% of the height for the y. It can be bigger than 1 and negative.\n * allowed values pixels or percentage.\n * @type GradientUnits\n * @default 'pixels'\n */\n declare gradientUnits: GradientUnits;\n\n /**\n * Gradient type linear or radial\n * @type GradientType\n * @default 'linear'\n */\n declare type: T;\n\n /**\n * Defines how the gradient is located in space and spread\n * @type GradientCoords\n */\n declare coords: GradientCoords<T>;\n\n /**\n * Defines how many colors a gradient has and how they are located on the axis\n * defined by coords\n * @type GradientCoords\n */\n declare colorStops: ColorStop[];\n\n /**\n * If true, this object will not be exported during the serialization of a canvas\n * @type boolean\n */\n declare excludeFromExport?: boolean;\n\n /**\n * ID used for SVG export functionalities\n * @type number | string\n */\n declare readonly id: string | number;\n\n static type = 'Gradient';\n\n constructor(options: GradientOptions<T>) {\n const {\n type = 'linear' as T,\n gradientUnits = 'pixels',\n coords = {},\n colorStops = [],\n offsetX = 0,\n offsetY = 0,\n gradientTransform,\n id,\n } = options || {};\n Object.assign(this, {\n type,\n gradientUnits,\n coords: {\n ...(type === 'radial' ? radialDefaultCoords : linearDefaultCoords),\n ...coords,\n },\n colorStops,\n offsetX,\n offsetY,\n gradientTransform,\n id: id ? `${id}_${uid()}` : uid(),\n });\n }\n\n /**\n * Adds another colorStop\n * @param {Record<string, string>} colorStop Object with offset and color\n * @return {Gradient} thisArg\n */\n addColorStop(colorStops: Record<string, string>) {\n for (const position in colorStops) {\n this.colorStops.push({\n offset: parseFloat(position),\n color: colorStops[position],\n });\n }\n return this;\n }\n\n /**\n * Returns object representation of a gradient\n * @param {string[]} [propertiesToInclude] Any properties that you might want to additionally include in the output\n * @return {object}\n */\n toObject(\n propertiesToInclude?: (keyof this | string)[],\n ): SerializedGradientProps<T> {\n return {\n ...pick(this, propertiesToInclude as (keyof this)[]),\n type: this.type,\n coords: { ...this.coords },\n colorStops: this.colorStops.map((colorStop) => ({ ...colorStop })),\n offsetX: this.offsetX,\n offsetY: this.offsetY,\n gradientUnits: this.gradientUnits,\n gradientTransform: this.gradientTransform\n ? [...this.gradientTransform]\n : undefined,\n };\n }\n\n /* _TO_SVG_START_ */\n /**\n * Returns SVG representation of an gradient\n * @param {FabricObject} object Object to create a gradient for\n * @return {String} SVG representation of an gradient (linear/radial)\n */\n toSVG(\n object: FabricObject,\n {\n additionalTransform: preTransform,\n }: { additionalTransform?: string } = {},\n ) {\n const markup = [],\n transform = (\n this.gradientTransform\n ? this.gradientTransform.concat()\n : iMatrix.concat()\n ) as TMat2D,\n gradientUnits =\n this.gradientUnits === 'pixels'\n ? 'userSpaceOnUse'\n : 'objectBoundingBox';\n // colorStops must be sorted ascending, and guarded against deep mutations\n const colorStops = this.colorStops\n .map((colorStop) => ({ ...colorStop }))\n .sort((a, b) => {\n return a.offset - b.offset;\n });\n\n let offsetX = -this.offsetX,\n offsetY = -this.offsetY;\n if (gradientUnits === 'objectBoundingBox') {\n offsetX /= object.width;\n offsetY /= object.height;\n } else {\n offsetX += object.width / 2;\n offsetY += object.height / 2;\n }\n // todo what about polygon/polyline?\n if (isPath(object) && this.gradientUnits !== 'percentage') {\n offsetX -= object.pathOffset.x;\n offsetY -= object.pathOffset.y;\n }\n transform[4] -= offsetX;\n transform[5] -= offsetY;\n\n const commonAttributes = [\n `id=\"SVGID_${escapeXml(String(this.id))}\"`,\n `gradientUnits=\"${gradientUnits}\"`,\n `gradientTransform=\"${\n preTransform ? preTransform + ' ' : ''\n }${matrixToSVG(transform)}\"`,\n '',\n ].join(' ');\n\n const sanitizeCoord = (value: unknown) => parseFloat(String(value));\n\n if (this.type === 'linear') {\n const { x1, y1, x2, y2 } = this.coords;\n const sx1 = sanitizeCoord(x1);\n const sy1 = sanitizeCoord(y1);\n const sx2 = sanitizeCoord(x2);\n const sy2 = sanitizeCoord(y2);\n markup.push(\n '<linearGradient ',\n commonAttributes,\n ' x1=\"',\n sx1,\n '\" y1=\"',\n sy1,\n '\" x2=\"',\n sx2,\n '\" y2=\"',\n sy2,\n '\">\\n',\n );\n } else if (this.type === 'radial') {\n const { x1, y1, x2, y2, r1, r2 } = this\n .coords as GradientCoords<'radial'>;\n const sx1 = sanitizeCoord(x1);\n const sy1 = sanitizeCoord(y1);\n const sx2 = sanitizeCoord(x2);\n const sy2 = sanitizeCoord(y2);\n const sr1 = sanitizeCoord(r1);\n const sr2 = sanitizeCoord(r2);\n const needsSwap = sr1 > sr2;\n // svg radial gradient has just 1 radius. the biggest.\n markup.push(\n '<radialGradient ',\n commonAttributes,\n ' cx=\"',\n needsSwap ? sx1 : sx2,\n '\" cy=\"',\n needsSwap ? sy1 : sy2,\n '\" r=\"',\n needsSwap ? sr1 : sr2,\n '\" fx=\"',\n needsSwap ? sx2 : sx1,\n '\" fy=\"',\n needsSwap ? sy2 : sy1,\n '\">\\n',\n );\n if (needsSwap) {\n // svg goes from internal to external radius. if radius are inverted, swap color stops.\n colorStops.reverse(); // mutates array\n colorStops.forEach((colorStop) => {\n colorStop.offset = 1 - colorStop.offset;\n });\n }\n const minRadius = Math.min(sr1, sr2);\n if (minRadius > 0) {\n // i have to shift all colorStops and add new one in 0.\n const maxRadius = Math.max(sr1, sr2),\n percentageShift = minRadius / maxRadius;\n colorStops.forEach((colorStop) => {\n colorStop.offset += percentageShift * (1 - colorStop.offset);\n });\n }\n }\n // todo make a malicious script tag injection test with color and also apply a fix with escapeXml\n colorStops.forEach(({ color, offset }) => {\n markup.push(\n `<stop offset=\"${offset * 100}%\" style=\"stop-color:${color};\"/>\\n`,\n );\n });\n\n markup.push(\n this.type === 'linear' ? '</linearGradient>' : '</radialGradient>',\n '\\n',\n );\n\n return markup.join('');\n }\n /* _TO_SVG_END_ */\n\n /**\n * Returns an instance of CanvasGradient\n * @param {CanvasRenderingContext2D} ctx Context to render on\n * @return {CanvasGradient}\n */\n toLive(ctx: CanvasRenderingContext2D): CanvasGradient {\n const { x1, y1, x2, y2, r1, r2 } = this.coords as GradientCoords<'radial'>;\n const gradient =\n this.type === 'linear'\n ? ctx.createLinearGradient(x1, y1, x2, y2)\n : ctx.createRadialGradient(x1, y1, r1, x2, y2, r2);\n\n this.colorStops.forEach(({ color, offset }) => {\n gradient.addColorStop(offset, color);\n });\n\n return gradient;\n }\n\n static async fromObject(\n options: GradientOptions<'linear'>,\n ): Promise<Gradient<'linear'>>;\n static async fromObject(\n options: GradientOptions<'radial'>,\n ): Promise<Gradient<'radial'>>;\n static async fromObject(\n options: GradientOptions<'linear'> | GradientOptions<'radial'>,\n ) {\n const { colorStops, gradientTransform } = options;\n return new this({\n ...options,\n colorStops: colorStops\n ? colorStops.map((colorStop) => ({ ...colorStop }))\n : undefined,\n gradientTransform: gradientTransform ? [...gradientTransform] : undefined,\n });\n }\n\n /* _FROM_SVG_START_ */\n /**\n * Returns {@link Gradient} instance from an SVG element\n * @param {SVGGradientElement} el SVG gradient element\n * @param {FabricObject} instance\n * @param {String} opacity A fill-opacity or stroke-opacity attribute to multiply to each stop's opacity.\n * @param {SVGOptions} svgOptions an object containing the size of the SVG in order to parse correctly gradients\n * that uses gradientUnits as 'userSpaceOnUse' and percentages.\n * @return {Gradient} Gradient instance\n * @see http://www.w3.org/TR/SVG/pservers.html#LinearGradientElement\n * @see http://www.w3.org/TR/SVG/pservers.html#RadialGradientElement\n *\n * @example\n *\n * <linearGradient id=\"linearGrad1\">\n * <stop offset=\"0%\" stop-color=\"white\"/>\n * <stop offset=\"100%\" stop-color=\"black\"/>\n * </linearGradient>\n *\n * OR\n *\n * <linearGradient id=\"linearGrad2\">\n * <stop offset=\"0\" style=\"stop-color:rgb(255,255,255)\"/>\n * <stop offset=\"1\" style=\"stop-color:rgb(0,0,0)\"/>\n * </linearGradient>\n *\n * OR\n *\n * <radialGradient id=\"radialGrad1\">\n * <stop offset=\"0%\" stop-color=\"white\" stop-opacity=\"1\" />\n * <stop offset=\"50%\" stop-color=\"black\" stop-opacity=\"0.5\" />\n * <stop offset=\"100%\" stop-color=\"white\" stop-opacity=\"1\" />\n * </radialGradient>\n *\n * OR\n *\n * <radialGradient id=\"radialGrad2\">\n * <stop offset=\"0\" stop-color=\"rgb(255,255,255)\" />\n * <stop offset=\"0.5\" stop-color=\"rgb(0,0,0)\" />\n * <stop offset=\"1\" stop-color=\"rgb(255,255,255)\" />\n * </radialGradient>\n *\n */\n static fromElement(\n el: SVGGradientElement,\n instance: FabricObject,\n svgOptions: SVGOptions,\n ): Gradient<GradientType> {\n const gradientUnits = parseGradientUnits(el);\n const center = instance._findCenterFromElement();\n return new this({\n id: el.getAttribute('id') || undefined,\n type: parseType(el),\n coords: parseCoords(el, {\n width: svgOptions.viewBoxWidth || svgOptions.width,\n height: svgOptions.viewBoxHeight || svgOptions.height,\n }),\n colorStops: parseColorStops(el, svgOptions.opacity),\n gradientUnits,\n gradientTransform: parseTransformAttribute(\n el.getAttribute('gradientTransform') || '',\n ),\n ...(gradientUnits === 'pixels'\n ? {\n offsetX: instance.width / 2 - center.x,\n offsetY: instance.height / 2 - center.y,\n }\n : {\n offsetX: 0,\n offsetY: 0,\n }),\n });\n }\n /* _FROM_SVG_END_ */\n}\n\nclassRegistry.setClass(Gradient, 'gradient');\nclassRegistry.setClass(Gradient, 'linear');\nclassRegistry.setClass(Gradient, 'radial');\n"],"names":["Gradient","constructor","options","type","gradientUnits","coords","colorStops","offsetX","offsetY","gradientTransform","id","Object","assign","this","radialDefaultCoords","linearDefaultCoords","uid","addColorStop","position","push","offset","parseFloat","color","toObject","propertiesToInclude","pick","map","colorStop","undefined","toSVG","object","additionalTransform","preTransform","arguments","length","markup","transform","concat","iMatrix","sort","a","b","width","height","isPath","pathOffset","x","y","commonAttributes","escapeXml","String","matrixToSVG","join","sanitizeCoord","value","x1","y1","x2","y2","sx1","sy1","sx2","sy2","r1","r2","sr1","sr2","needsSwap","reverse","forEach","minRadius","Math","min","percentageShift","max","_ref","toLive","ctx","gradient","createLinearGradient","createRadialGradient","_ref2","fromObject","fromElement","el","instance","svgOptions","parseGradientUnits","center","_findCenterFromElement","getAttribute","parseType","parseCoords","viewBoxWidth","viewBoxHeight","parseColorStops","opacity","parseTransformAttribute","_defineProperty","classRegistry","setClass"],"mappings":"2zBA6BO,MAAMA,EAyEXC,WAAAA,CAAYC,GACV,MAAMC,KACJA,EAAO,SAAaC,cACpBA,EAAgB,SAAQC,OACxBA,EAAS,CAAA,EAAEC,WACXA,EAAa,GAAEC,QACfA,EAAU,EAACC,QACXA,EAAU,EAACC,kBACXA,EAAiBC,GACjBA,GACER,GAAW,CAAA,EACfS,OAAOC,OAAOC,KAAM,CAClBV,OACAC,gBACAC,OAAQ,IACO,WAATF,EAAoBW,EAAsBC,KAC3CV,GAELC,aACAC,UACAC,UACAC,oBACAC,GAAIA,EAAK,GAAGA,KAAMM,MAAUA,KAEhC,CAOAC,YAAAA,CAAaX,GACX,IAAK,MAAMY,KAAYZ,EACrBO,KAAKP,WAAWa,KAAK,CACnBC,OAAQC,WAAWH,GACnBI,MAAOhB,EAAWY,KAGtB,OAAOL,IACT,CAOAU,QAAAA,CACEC,GAEA,MAAO,IACFC,EAAKZ,KAAMW,GACdrB,KAAMU,KAAKV,KACXE,OAAQ,IAAKQ,KAAKR,QAClBC,WAAYO,KAAKP,WAAWoB,IAAKC,IAAS,IAAWA,KACrDpB,QAASM,KAAKN,QACdC,QAASK,KAAKL,QACdJ,cAAeS,KAAKT,cACpBK,kBAAmBI,KAAKJ,kBACpB,IAAII,KAAKJ,wBACTmB,EAER,CAQAC,KAAAA,CACEC,GAIA,IAFEC,oBAAqBC,GACYC,UAAAC,OAAA,QAAAN,IAAAK,UAAA,GAAAA,UAAA,GAAG,CAAA,EAEtC,MAAME,EAAS,GACbC,EACEvB,KAAKJ,kBACDI,KAAKJ,kBAAkB4B,SACvBC,EAAQD,SAEd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nB,kBAAmBA,EAAoB,IAAIA,QAAqBmB,GAEpE,CA6CA,kBAAOuD,CACLC,EACAC,EACAC,GAEA,MAAMlF,EAAgBmF,EAAmBH,GACnCI,EAASH,EAASI,yBACxB,OAAO,IAAI5E,KAAK,CACdH,GAAI0E,EAAGM,aAAa,YAAS9D,EAC7BzB,KAAMwF,EAAUP,GAChB/E,OAAQuF,EAAYR,EAAI,CACtB1C,MAAO4C,EAAWO,cAAgBP,EAAW5C,MAC7CC,OAAQ2C,EAAWQ,eAAiBR,EAAW3C,SAEjDrC,WAAYyF,EAAgBX,EAAIE,EAAWU,SAC3C5F,gBACAK,kBAAmBwF,EACjBb,EAAGM,aAAa,sBAAwB,OAEpB,WAAlBtF,EACA,CACEG,QAAS8E,EAAS3C,MAAQ,EAAI8C,EAAO1C,EACrCtC,QAAS6E,EAAS1C,OAAS,EAAI6C,EAAOzC,GAExC,CACExC,QAAS,EACTC,QAAS,IAGnB,EA5TA0F,EAjEWlG,EAAQ,OAuEL,YA0ThBmG,EAAcC,SAASpG,EAAU,YACjCmG,EAAcC,SAASpG,EAAU,UACjCmG,EAAcC,SAASpG,EAAU"}
@@ -10,6 +10,7 @@ import { parseCoords } from './parser/parseCoords.mjs';
10
10
  import { parseGradientUnits, parseType } from './parser/misc.mjs';
11
11
  import { classRegistry } from '../ClassRegistry.mjs';
12
12
  import { isPath } from '../util/typeAssertions.mjs';
13
+ import { escapeXml } from '../util/lang_string.mjs';
13
14
 
14
15
  /**
15
16
  * Gradient class
@@ -115,7 +116,8 @@ class Gradient {
115
116
  }
116
117
  transform[4] -= offsetX;
117
118
  transform[5] -= offsetY;
118
- const commonAttributes = [`id="SVGID_${this.id}"`, `gradientUnits="${gradientUnits}"`, `gradientTransform="${preTransform ? preTransform + ' ' : ''}${matrixToSVG(transform)}"`, ''].join(' ');
119
+ const commonAttributes = [`id="SVGID_${escapeXml(String(this.id))}"`, `gradientUnits="${gradientUnits}"`, `gradientTransform="${preTransform ? preTransform + ' ' : ''}${matrixToSVG(transform)}"`, ''].join(' ');
120
+ const sanitizeCoord = value => parseFloat(String(value));
119
121
  if (this.type === 'linear') {
120
122
  const {
121
123
  x1,
@@ -123,7 +125,11 @@ class Gradient {
123
125
  x2,
124
126
  y2
125
127
  } = this.coords;
126
- markup.push('<linearGradient ', commonAttributes, ' x1="', x1, '" y1="', y1, '" x2="', x2, '" y2="', y2, '">\n');
128
+ const sx1 = sanitizeCoord(x1);
129
+ const sy1 = sanitizeCoord(y1);
130
+ const sx2 = sanitizeCoord(x2);
131
+ const sy2 = sanitizeCoord(y2);
132
+ markup.push('<linearGradient ', commonAttributes, ' x1="', sx1, '" y1="', sy1, '" x2="', sx2, '" y2="', sy2, '">\n');
127
133
  } else if (this.type === 'radial') {
128
134
  const {
129
135
  x1,
@@ -133,9 +139,15 @@ class Gradient {
133
139
  r1,
134
140
  r2
135
141
  } = this.coords;
136
- const needsSwap = r1 > r2;
142
+ const sx1 = sanitizeCoord(x1);
143
+ const sy1 = sanitizeCoord(y1);
144
+ const sx2 = sanitizeCoord(x2);
145
+ const sy2 = sanitizeCoord(y2);
146
+ const sr1 = sanitizeCoord(r1);
147
+ const sr2 = sanitizeCoord(r2);
148
+ const needsSwap = sr1 > sr2;
137
149
  // svg radial gradient has just 1 radius. the biggest.
138
- markup.push('<radialGradient ', commonAttributes, ' cx="', needsSwap ? x1 : x2, '" cy="', needsSwap ? y1 : y2, '" r="', needsSwap ? r1 : r2, '" fx="', needsSwap ? x2 : x1, '" fy="', needsSwap ? y2 : y1, '">\n');
150
+ markup.push('<radialGradient ', commonAttributes, ' cx="', needsSwap ? sx1 : sx2, '" cy="', needsSwap ? sy1 : sy2, '" r="', needsSwap ? sr1 : sr2, '" fx="', needsSwap ? sx2 : sx1, '" fy="', needsSwap ? sy2 : sy1, '">\n');
139
151
  if (needsSwap) {
140
152
  // svg goes from internal to external radius. if radius are inverted, swap color stops.
141
153
  colorStops.reverse(); // mutates array
@@ -143,16 +155,17 @@ class Gradient {
143
155
  colorStop.offset = 1 - colorStop.offset;
144
156
  });
145
157
  }
146
- const minRadius = Math.min(r1, r2);
158
+ const minRadius = Math.min(sr1, sr2);
147
159
  if (minRadius > 0) {
148
160
  // i have to shift all colorStops and add new one in 0.
149
- const maxRadius = Math.max(r1, r2),
161
+ const maxRadius = Math.max(sr1, sr2),
150
162
  percentageShift = minRadius / maxRadius;
151
163
  colorStops.forEach(colorStop => {
152
164
  colorStop.offset += percentageShift * (1 - colorStop.offset);
153
165
  });
154
166
  }
155
167
  }
168
+ // todo make a malicious script tag injection test with color and also apply a fix with escapeXml
156
169
  colorStops.forEach(_ref => {
157
170
  let {
158
171
  color,
@@ -1 +1 @@
1
- {"version":3,"file":"Gradient.mjs","sources":["../../../src/gradient/Gradient.ts"],"sourcesContent":["import { iMatrix } from '../constants';\nimport { parseTransformAttribute } from '../parser/parseTransformAttribute';\nimport type { FabricObject } from '../shapes/Object/FabricObject';\nimport type { TMat2D } from '../typedefs';\nimport { uid } from '../util/internals/uid';\nimport { pick } from '../util/misc/pick';\nimport { matrixToSVG } from '../util/misc/svgExport';\nimport { linearDefaultCoords, radialDefaultCoords } from './constants';\nimport { parseColorStops } from './parser/parseColorStops';\nimport { parseCoords } from './parser/parseCoords';\nimport { parseType, parseGradientUnits } from './parser/misc';\nimport type {\n ColorStop,\n GradientCoords,\n GradientOptions,\n GradientType,\n GradientUnits,\n SVGOptions,\n SerializedGradientProps,\n} from './typedefs';\nimport { classRegistry } from '../ClassRegistry';\nimport { isPath } from '../util/typeAssertions';\n\n/**\n * Gradient class\n * @class Gradient\n * @see {@link http://fabric5.fabricjs.com/fabric-intro-part-2#gradients}\n */\nexport class Gradient<\n S,\n T extends GradientType = S extends GradientType ? S : 'linear',\n> {\n /**\n * Horizontal offset for aligning gradients coming from SVG when outside pathgroups\n * @type Number\n * @default 0\n */\n declare offsetX: number;\n\n /**\n * Vertical offset for aligning gradients coming from SVG when outside pathgroups\n * @type Number\n * @default 0\n */\n declare offsetY: number;\n\n /**\n * A transform matrix to apply to the gradient before painting.\n * Imported from svg gradients, is not applied with the current transform in the center.\n * Before this transform is applied, the origin point is at the top left corner of the object\n * plus the addition of offsetY and offsetX.\n * @type Number[]\n * @default null\n */\n declare gradientTransform?: TMat2D;\n\n /**\n * coordinates units for coords.\n * If `pixels`, the number of coords are in the same unit of width / height.\n * If set as `percentage` the coords are still a number, but 1 means 100% of width\n * for the X and 100% of the height for the y. It can be bigger than 1 and negative.\n * allowed values pixels or percentage.\n * @type GradientUnits\n * @default 'pixels'\n */\n declare gradientUnits: GradientUnits;\n\n /**\n * Gradient type linear or radial\n * @type GradientType\n * @default 'linear'\n */\n declare type: T;\n\n /**\n * Defines how the gradient is located in space and spread\n * @type GradientCoords\n */\n declare coords: GradientCoords<T>;\n\n /**\n * Defines how many colors a gradient has and how they are located on the axis\n * defined by coords\n * @type GradientCoords\n */\n declare colorStops: ColorStop[];\n\n /**\n * If true, this object will not be exported during the serialization of a canvas\n * @type boolean\n */\n declare excludeFromExport?: boolean;\n\n /**\n * ID used for SVG export functionalities\n * @type number | string\n */\n declare readonly id: string | number;\n\n static type = 'Gradient';\n\n constructor(options: GradientOptions<T>) {\n const {\n type = 'linear' as T,\n gradientUnits = 'pixels',\n coords = {},\n colorStops = [],\n offsetX = 0,\n offsetY = 0,\n gradientTransform,\n id,\n } = options || {};\n Object.assign(this, {\n type,\n gradientUnits,\n coords: {\n ...(type === 'radial' ? radialDefaultCoords : linearDefaultCoords),\n ...coords,\n },\n colorStops,\n offsetX,\n offsetY,\n gradientTransform,\n id: id ? `${id}_${uid()}` : uid(),\n });\n }\n\n /**\n * Adds another colorStop\n * @param {Record<string, string>} colorStop Object with offset and color\n * @return {Gradient} thisArg\n */\n addColorStop(colorStops: Record<string, string>) {\n for (const position in colorStops) {\n this.colorStops.push({\n offset: parseFloat(position),\n color: colorStops[position],\n });\n }\n return this;\n }\n\n /**\n * Returns object representation of a gradient\n * @param {string[]} [propertiesToInclude] Any properties that you might want to additionally include in the output\n * @return {object}\n */\n toObject(\n propertiesToInclude?: (keyof this | string)[],\n ): SerializedGradientProps<T> {\n return {\n ...pick(this, propertiesToInclude as (keyof this)[]),\n type: this.type,\n coords: { ...this.coords },\n colorStops: this.colorStops.map((colorStop) => ({ ...colorStop })),\n offsetX: this.offsetX,\n offsetY: this.offsetY,\n gradientUnits: this.gradientUnits,\n gradientTransform: this.gradientTransform\n ? [...this.gradientTransform]\n : undefined,\n };\n }\n\n /* _TO_SVG_START_ */\n /**\n * Returns SVG representation of an gradient\n * @param {FabricObject} object Object to create a gradient for\n * @return {String} SVG representation of an gradient (linear/radial)\n */\n toSVG(\n object: FabricObject,\n {\n additionalTransform: preTransform,\n }: { additionalTransform?: string } = {},\n ) {\n const markup = [],\n transform = (\n this.gradientTransform\n ? this.gradientTransform.concat()\n : iMatrix.concat()\n ) as TMat2D,\n gradientUnits =\n this.gradientUnits === 'pixels'\n ? 'userSpaceOnUse'\n : 'objectBoundingBox';\n // colorStops must be sorted ascending, and guarded against deep mutations\n const colorStops = this.colorStops\n .map((colorStop) => ({ ...colorStop }))\n .sort((a, b) => {\n return a.offset - b.offset;\n });\n\n let offsetX = -this.offsetX,\n offsetY = -this.offsetY;\n if (gradientUnits === 'objectBoundingBox') {\n offsetX /= object.width;\n offsetY /= object.height;\n } else {\n offsetX += object.width / 2;\n offsetY += object.height / 2;\n }\n // todo what about polygon/polyline?\n if (isPath(object) && this.gradientUnits !== 'percentage') {\n offsetX -= object.pathOffset.x;\n offsetY -= object.pathOffset.y;\n }\n transform[4] -= offsetX;\n transform[5] -= offsetY;\n\n const commonAttributes = [\n `id=\"SVGID_${this.id}\"`,\n `gradientUnits=\"${gradientUnits}\"`,\n `gradientTransform=\"${\n preTransform ? preTransform + ' ' : ''\n }${matrixToSVG(transform)}\"`,\n '',\n ].join(' ');\n\n if (this.type === 'linear') {\n const { x1, y1, x2, y2 } = this.coords;\n markup.push(\n '<linearGradient ',\n commonAttributes,\n ' x1=\"',\n x1,\n '\" y1=\"',\n y1,\n '\" x2=\"',\n x2,\n '\" y2=\"',\n y2,\n '\">\\n',\n );\n } else if (this.type === 'radial') {\n const { x1, y1, x2, y2, r1, r2 } = this\n .coords as GradientCoords<'radial'>;\n const needsSwap = r1 > r2;\n // svg radial gradient has just 1 radius. the biggest.\n markup.push(\n '<radialGradient ',\n commonAttributes,\n ' cx=\"',\n needsSwap ? x1 : x2,\n '\" cy=\"',\n needsSwap ? y1 : y2,\n '\" r=\"',\n needsSwap ? r1 : r2,\n '\" fx=\"',\n needsSwap ? x2 : x1,\n '\" fy=\"',\n needsSwap ? y2 : y1,\n '\">\\n',\n );\n if (needsSwap) {\n // svg goes from internal to external radius. if radius are inverted, swap color stops.\n colorStops.reverse(); // mutates array\n colorStops.forEach((colorStop) => {\n colorStop.offset = 1 - colorStop.offset;\n });\n }\n const minRadius = Math.min(r1, r2);\n if (minRadius > 0) {\n // i have to shift all colorStops and add new one in 0.\n const maxRadius = Math.max(r1, r2),\n percentageShift = minRadius / maxRadius;\n colorStops.forEach((colorStop) => {\n colorStop.offset += percentageShift * (1 - colorStop.offset);\n });\n }\n }\n\n colorStops.forEach(({ color, offset }) => {\n markup.push(\n `<stop offset=\"${offset * 100}%\" style=\"stop-color:${color};\"/>\\n`,\n );\n });\n\n markup.push(\n this.type === 'linear' ? '</linearGradient>' : '</radialGradient>',\n '\\n',\n );\n\n return markup.join('');\n }\n /* _TO_SVG_END_ */\n\n /**\n * Returns an instance of CanvasGradient\n * @param {CanvasRenderingContext2D} ctx Context to render on\n * @return {CanvasGradient}\n */\n toLive(ctx: CanvasRenderingContext2D): CanvasGradient {\n const { x1, y1, x2, y2, r1, r2 } = this.coords as GradientCoords<'radial'>;\n const gradient =\n this.type === 'linear'\n ? ctx.createLinearGradient(x1, y1, x2, y2)\n : ctx.createRadialGradient(x1, y1, r1, x2, y2, r2);\n\n this.colorStops.forEach(({ color, offset }) => {\n gradient.addColorStop(offset, color);\n });\n\n return gradient;\n }\n\n static async fromObject(\n options: GradientOptions<'linear'>,\n ): Promise<Gradient<'linear'>>;\n static async fromObject(\n options: GradientOptions<'radial'>,\n ): Promise<Gradient<'radial'>>;\n static async fromObject(\n options: GradientOptions<'linear'> | GradientOptions<'radial'>,\n ) {\n const { colorStops, gradientTransform } = options;\n return new this({\n ...options,\n colorStops: colorStops\n ? colorStops.map((colorStop) => ({ ...colorStop }))\n : undefined,\n gradientTransform: gradientTransform ? [...gradientTransform] : undefined,\n });\n }\n\n /* _FROM_SVG_START_ */\n /**\n * Returns {@link Gradient} instance from an SVG element\n * @param {SVGGradientElement} el SVG gradient element\n * @param {FabricObject} instance\n * @param {String} opacity A fill-opacity or stroke-opacity attribute to multiply to each stop's opacity.\n * @param {SVGOptions} svgOptions an object containing the size of the SVG in order to parse correctly gradients\n * that uses gradientUnits as 'userSpaceOnUse' and percentages.\n * @return {Gradient} Gradient instance\n * @see http://www.w3.org/TR/SVG/pservers.html#LinearGradientElement\n * @see http://www.w3.org/TR/SVG/pservers.html#RadialGradientElement\n *\n * @example\n *\n * <linearGradient id=\"linearGrad1\">\n * <stop offset=\"0%\" stop-color=\"white\"/>\n * <stop offset=\"100%\" stop-color=\"black\"/>\n * </linearGradient>\n *\n * OR\n *\n * <linearGradient id=\"linearGrad2\">\n * <stop offset=\"0\" style=\"stop-color:rgb(255,255,255)\"/>\n * <stop offset=\"1\" style=\"stop-color:rgb(0,0,0)\"/>\n * </linearGradient>\n *\n * OR\n *\n * <radialGradient id=\"radialGrad1\">\n * <stop offset=\"0%\" stop-color=\"white\" stop-opacity=\"1\" />\n * <stop offset=\"50%\" stop-color=\"black\" stop-opacity=\"0.5\" />\n * <stop offset=\"100%\" stop-color=\"white\" stop-opacity=\"1\" />\n * </radialGradient>\n *\n * OR\n *\n * <radialGradient id=\"radialGrad2\">\n * <stop offset=\"0\" stop-color=\"rgb(255,255,255)\" />\n * <stop offset=\"0.5\" stop-color=\"rgb(0,0,0)\" />\n * <stop offset=\"1\" stop-color=\"rgb(255,255,255)\" />\n * </radialGradient>\n *\n */\n static fromElement(\n el: SVGGradientElement,\n instance: FabricObject,\n svgOptions: SVGOptions,\n ): Gradient<GradientType> {\n const gradientUnits = parseGradientUnits(el);\n const center = instance._findCenterFromElement();\n return new this({\n id: el.getAttribute('id') || undefined,\n type: parseType(el),\n coords: parseCoords(el, {\n width: svgOptions.viewBoxWidth || svgOptions.width,\n height: svgOptions.viewBoxHeight || svgOptions.height,\n }),\n colorStops: parseColorStops(el, svgOptions.opacity),\n gradientUnits,\n gradientTransform: parseTransformAttribute(\n el.getAttribute('gradientTransform') || '',\n ),\n ...(gradientUnits === 'pixels'\n ? {\n offsetX: instance.width / 2 - center.x,\n offsetY: instance.height / 2 - center.y,\n }\n : {\n offsetX: 0,\n offsetY: 0,\n }),\n });\n }\n /* _FROM_SVG_END_ */\n}\n\nclassRegistry.setClass(Gradient, 'gradient');\nclassRegistry.setClass(Gradient, 'linear');\nclassRegistry.setClass(Gradient, 'radial');\n"],"names":["Gradient","constructor","options","type","gradientUnits","coords","colorStops","offsetX","offsetY","gradientTransform","id","Object","assign","radialDefaultCoords","linearDefaultCoords","uid","addColorStop","position","push","offset","parseFloat","color","toObject","propertiesToInclude","pick","map","colorStop","undefined","toSVG","object","additionalTransform","preTransform","arguments","length","markup","transform","concat","iMatrix","sort","a","b","width","height","isPath","pathOffset","x","y","commonAttributes","matrixToSVG","join","x1","y1","x2","y2","r1","r2","needsSwap","reverse","forEach","minRadius","Math","min","maxRadius","max","percentageShift","_ref","toLive","ctx","gradient","createLinearGradient","createRadialGradient","_ref2","fromObject","fromElement","el","instance","svgOptions","parseGradientUnits","center","_findCenterFromElement","getAttribute","parseType","parseCoords","viewBoxWidth","viewBoxHeight","parseColorStops","opacity","parseTransformAttribute","_defineProperty","classRegistry","setClass"],"mappings":";;;;;;;;;;;;;AAuBA;AACA;AACA;AACA;AACA;AACO,MAAMA,QAAQ,CAGnB;EAsEAC,WAAWA,CAACC,OAA2B,EAAE;IACvC,MAAM;AACJC,MAAAA,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GAC1B;QACEG,OAAO,EAAEoE,QAAQ,CAAClC,KAAK,GAAG,CAAC,GAAGqC,MAAM,CAACjC,CAAC;QACtCrC,OAAO,EAAEmE,QAAQ,CAACjC,MAAM,GAAG,CAAC,GAAGoC,MAAM,CAAChC;AACxC,OAAC,GACD;AACEvC,QAAAA,OAAO,EAAE,CAAC;AACVC,QAAAA,OAAO,EAAE;OACV;AACP,KAAC,CAAC;AACJ,EAAA;AACA;AACF;AA/WE;AACF;AACA;AACA;AACA;AAGE;AACF;AACA;AACA;AACA;AAGE;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AAGE;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAGE;AACF;AACA;AACA;AACA;AAGE;AACF;AACA;AACA;AAGE;AACF;AACA;AACA;AACA;AAGE;AACF;AACA;AACA;AAGE;AACF;AACA;AACA;AAHEgF,eAAA,CAjEWxF,QAAQ,EAAA,MAAA,EAuEL,UAAU,CAAA;AA8S1ByF,aAAa,CAACC,QAAQ,CAAC1F,QAAQ,EAAE,UAAU,CAAC;AAC5CyF,aAAa,CAACC,QAAQ,CAAC1F,QAAQ,EAAE,QAAQ,CAAC;AAC1CyF,aAAa,CAACC,QAAQ,CAAC1F,QAAQ,EAAE,QAAQ,CAAC;;;;"}
1
+ {"version":3,"file":"Gradient.mjs","sources":["../../../src/gradient/Gradient.ts"],"sourcesContent":["import { iMatrix } from '../constants';\nimport { parseTransformAttribute } from '../parser/parseTransformAttribute';\nimport type { FabricObject } from '../shapes/Object/FabricObject';\nimport type { TMat2D } from '../typedefs';\nimport { uid } from '../util/internals/uid';\nimport { pick } from '../util/misc/pick';\nimport { matrixToSVG } from '../util/misc/svgExport';\nimport { linearDefaultCoords, radialDefaultCoords } from './constants';\nimport { parseColorStops } from './parser/parseColorStops';\nimport { parseCoords } from './parser/parseCoords';\nimport { parseType, parseGradientUnits } from './parser/misc';\nimport type {\n ColorStop,\n GradientCoords,\n GradientOptions,\n GradientType,\n GradientUnits,\n SVGOptions,\n SerializedGradientProps,\n} from './typedefs';\nimport { classRegistry } from '../ClassRegistry';\nimport { isPath } from '../util/typeAssertions';\nimport { escapeXml } from '../util/lang_string';\n\n/**\n * Gradient class\n * @class Gradient\n * @see {@link http://fabric5.fabricjs.com/fabric-intro-part-2#gradients}\n */\nexport class Gradient<\n S,\n T extends GradientType = S extends GradientType ? S : 'linear',\n> {\n /**\n * Horizontal offset for aligning gradients coming from SVG when outside pathgroups\n * @type Number\n * @default 0\n */\n declare offsetX: number;\n\n /**\n * Vertical offset for aligning gradients coming from SVG when outside pathgroups\n * @type Number\n * @default 0\n */\n declare offsetY: number;\n\n /**\n * A transform matrix to apply to the gradient before painting.\n * Imported from svg gradients, is not applied with the current transform in the center.\n * Before this transform is applied, the origin point is at the top left corner of the object\n * plus the addition of offsetY and offsetX.\n * @type Number[]\n * @default null\n */\n declare gradientTransform?: TMat2D;\n\n /**\n * coordinates units for coords.\n * If `pixels`, the number of coords are in the same unit of width / height.\n * If set as `percentage` the coords are still a number, but 1 means 100% of width\n * for the X and 100% of the height for the y. It can be bigger than 1 and negative.\n * allowed values pixels or percentage.\n * @type GradientUnits\n * @default 'pixels'\n */\n declare gradientUnits: GradientUnits;\n\n /**\n * Gradient type linear or radial\n * @type GradientType\n * @default 'linear'\n */\n declare type: T;\n\n /**\n * Defines how the gradient is located in space and spread\n * @type GradientCoords\n */\n declare coords: GradientCoords<T>;\n\n /**\n * Defines how many colors a gradient has and how they are located on the axis\n * defined by coords\n * @type GradientCoords\n */\n declare colorStops: ColorStop[];\n\n /**\n * If true, this object will not be exported during the serialization of a canvas\n * @type boolean\n */\n declare excludeFromExport?: boolean;\n\n /**\n * ID used for SVG export functionalities\n * @type number | string\n */\n declare readonly id: string | number;\n\n static type = 'Gradient';\n\n constructor(options: GradientOptions<T>) {\n const {\n type = 'linear' as T,\n gradientUnits = 'pixels',\n coords = {},\n colorStops = [],\n offsetX = 0,\n offsetY = 0,\n gradientTransform,\n id,\n } = options || {};\n Object.assign(this, {\n type,\n gradientUnits,\n coords: {\n ...(type === 'radial' ? radialDefaultCoords : linearDefaultCoords),\n ...coords,\n },\n colorStops,\n offsetX,\n offsetY,\n gradientTransform,\n id: id ? `${id}_${uid()}` : uid(),\n });\n }\n\n /**\n * Adds another colorStop\n * @param {Record<string, string>} colorStop Object with offset and color\n * @return {Gradient} thisArg\n */\n addColorStop(colorStops: Record<string, string>) {\n for (const position in colorStops) {\n this.colorStops.push({\n offset: parseFloat(position),\n color: colorStops[position],\n });\n }\n return this;\n }\n\n /**\n * Returns object representation of a gradient\n * @param {string[]} [propertiesToInclude] Any properties that you might want to additionally include in the output\n * @return {object}\n */\n toObject(\n propertiesToInclude?: (keyof this | string)[],\n ): SerializedGradientProps<T> {\n return {\n ...pick(this, propertiesToInclude as (keyof this)[]),\n type: this.type,\n coords: { ...this.coords },\n colorStops: this.colorStops.map((colorStop) => ({ ...colorStop })),\n offsetX: this.offsetX,\n offsetY: this.offsetY,\n gradientUnits: this.gradientUnits,\n gradientTransform: this.gradientTransform\n ? [...this.gradientTransform]\n : undefined,\n };\n }\n\n /* _TO_SVG_START_ */\n /**\n * Returns SVG representation of an gradient\n * @param {FabricObject} object Object to create a gradient for\n * @return {String} SVG representation of an gradient (linear/radial)\n */\n toSVG(\n object: FabricObject,\n {\n additionalTransform: preTransform,\n }: { additionalTransform?: string } = {},\n ) {\n const markup = [],\n transform = (\n this.gradientTransform\n ? this.gradientTransform.concat()\n : iMatrix.concat()\n ) as TMat2D,\n gradientUnits =\n this.gradientUnits === 'pixels'\n ? 'userSpaceOnUse'\n : 'objectBoundingBox';\n // colorStops must be sorted ascending, and guarded against deep mutations\n const colorStops = this.colorStops\n .map((colorStop) => ({ ...colorStop }))\n .sort((a, b) => {\n return a.offset - b.offset;\n });\n\n let offsetX = -this.offsetX,\n offsetY = -this.offsetY;\n if (gradientUnits === 'objectBoundingBox') {\n offsetX /= object.width;\n offsetY /= object.height;\n } else {\n offsetX += object.width / 2;\n offsetY += object.height / 2;\n }\n // todo what about polygon/polyline?\n if (isPath(object) && this.gradientUnits !== 'percentage') {\n offsetX -= object.pathOffset.x;\n offsetY -= object.pathOffset.y;\n }\n transform[4] -= offsetX;\n transform[5] -= offsetY;\n\n const commonAttributes = [\n `id=\"SVGID_${escapeXml(String(this.id))}\"`,\n `gradientUnits=\"${gradientUnits}\"`,\n `gradientTransform=\"${\n preTransform ? preTransform + ' ' : ''\n }${matrixToSVG(transform)}\"`,\n '',\n ].join(' ');\n\n const sanitizeCoord = (value: unknown) => parseFloat(String(value));\n\n if (this.type === 'linear') {\n const { x1, y1, x2, y2 } = this.coords;\n const sx1 = sanitizeCoord(x1);\n const sy1 = sanitizeCoord(y1);\n const sx2 = sanitizeCoord(x2);\n const sy2 = sanitizeCoord(y2);\n markup.push(\n '<linearGradient ',\n commonAttributes,\n ' x1=\"',\n sx1,\n '\" y1=\"',\n sy1,\n '\" x2=\"',\n sx2,\n '\" y2=\"',\n sy2,\n '\">\\n',\n );\n } else if (this.type === 'radial') {\n const { x1, y1, x2, y2, r1, r2 } = this\n .coords as GradientCoords<'radial'>;\n const sx1 = sanitizeCoord(x1);\n const sy1 = sanitizeCoord(y1);\n const sx2 = sanitizeCoord(x2);\n const sy2 = sanitizeCoord(y2);\n const sr1 = sanitizeCoord(r1);\n const sr2 = sanitizeCoord(r2);\n const needsSwap = sr1 > sr2;\n // svg radial gradient has just 1 radius. the biggest.\n markup.push(\n '<radialGradient ',\n commonAttributes,\n ' cx=\"',\n needsSwap ? sx1 : sx2,\n '\" cy=\"',\n needsSwap ? sy1 : sy2,\n '\" r=\"',\n needsSwap ? sr1 : sr2,\n '\" fx=\"',\n needsSwap ? sx2 : sx1,\n '\" fy=\"',\n needsSwap ? sy2 : sy1,\n '\">\\n',\n );\n if (needsSwap) {\n // svg goes from internal to external radius. if radius are inverted, swap color stops.\n colorStops.reverse(); // mutates array\n colorStops.forEach((colorStop) => {\n colorStop.offset = 1 - colorStop.offset;\n });\n }\n const minRadius = Math.min(sr1, sr2);\n if (minRadius > 0) {\n // i have to shift all colorStops and add new one in 0.\n const maxRadius = Math.max(sr1, sr2),\n percentageShift = minRadius / maxRadius;\n colorStops.forEach((colorStop) => {\n colorStop.offset += percentageShift * (1 - colorStop.offset);\n });\n }\n }\n // todo make a malicious script tag injection test with color and also apply a fix with escapeXml\n colorStops.forEach(({ color, offset }) => {\n markup.push(\n `<stop offset=\"${offset * 100}%\" style=\"stop-color:${color};\"/>\\n`,\n );\n });\n\n markup.push(\n this.type === 'linear' ? '</linearGradient>' : '</radialGradient>',\n '\\n',\n );\n\n return markup.join('');\n }\n /* _TO_SVG_END_ */\n\n /**\n * Returns an instance of CanvasGradient\n * @param {CanvasRenderingContext2D} ctx Context to render on\n * @return {CanvasGradient}\n */\n toLive(ctx: CanvasRenderingContext2D): CanvasGradient {\n const { x1, y1, x2, y2, r1, r2 } = this.coords as GradientCoords<'radial'>;\n const gradient =\n this.type === 'linear'\n ? ctx.createLinearGradient(x1, y1, x2, y2)\n : ctx.createRadialGradient(x1, y1, r1, x2, y2, r2);\n\n this.colorStops.forEach(({ color, offset }) => {\n gradient.addColorStop(offset, color);\n });\n\n return gradient;\n }\n\n static async fromObject(\n options: GradientOptions<'linear'>,\n ): Promise<Gradient<'linear'>>;\n static async fromObject(\n options: GradientOptions<'radial'>,\n ): Promise<Gradient<'radial'>>;\n static async fromObject(\n options: GradientOptions<'linear'> | GradientOptions<'radial'>,\n ) {\n const { colorStops, gradientTransform } = options;\n return new this({\n ...options,\n colorStops: colorStops\n ? colorStops.map((colorStop) => ({ ...colorStop }))\n : undefined,\n gradientTransform: gradientTransform ? [...gradientTransform] : undefined,\n });\n }\n\n /* _FROM_SVG_START_ */\n /**\n * Returns {@link Gradient} instance from an SVG element\n * @param {SVGGradientElement} el SVG gradient element\n * @param {FabricObject} instance\n * @param {String} opacity A fill-opacity or stroke-opacity attribute to multiply to each stop's opacity.\n * @param {SVGOptions} svgOptions an object containing the size of the SVG in order to parse correctly gradients\n * that uses gradientUnits as 'userSpaceOnUse' and percentages.\n * @return {Gradient} Gradient instance\n * @see http://www.w3.org/TR/SVG/pservers.html#LinearGradientElement\n * @see http://www.w3.org/TR/SVG/pservers.html#RadialGradientElement\n *\n * @example\n *\n * <linearGradient id=\"linearGrad1\">\n * <stop offset=\"0%\" stop-color=\"white\"/>\n * <stop offset=\"100%\" stop-color=\"black\"/>\n * </linearGradient>\n *\n * OR\n *\n * <linearGradient id=\"linearGrad2\">\n * <stop offset=\"0\" style=\"stop-color:rgb(255,255,255)\"/>\n * <stop offset=\"1\" style=\"stop-color:rgb(0,0,0)\"/>\n * </linearGradient>\n *\n * OR\n *\n * <radialGradient id=\"radialGrad1\">\n * <stop offset=\"0%\" stop-color=\"white\" stop-opacity=\"1\" />\n * <stop offset=\"50%\" stop-color=\"black\" stop-opacity=\"0.5\" />\n * <stop offset=\"100%\" stop-color=\"white\" stop-opacity=\"1\" />\n * </radialGradient>\n *\n * OR\n *\n * <radialGradient id=\"radialGrad2\">\n * <stop offset=\"0\" stop-color=\"rgb(255,255,255)\" />\n * <stop offset=\"0.5\" stop-color=\"rgb(0,0,0)\" />\n * <stop offset=\"1\" stop-color=\"rgb(255,255,255)\" />\n * </radialGradient>\n *\n */\n static fromElement(\n el: SVGGradientElement,\n instance: FabricObject,\n svgOptions: SVGOptions,\n ): Gradient<GradientType> {\n const gradientUnits = parseGradientUnits(el);\n const center = instance._findCenterFromElement();\n return new this({\n id: el.getAttribute('id') || undefined,\n type: parseType(el),\n coords: parseCoords(el, {\n width: svgOptions.viewBoxWidth || svgOptions.width,\n height: svgOptions.viewBoxHeight || svgOptions.height,\n }),\n colorStops: parseColorStops(el, svgOptions.opacity),\n gradientUnits,\n gradientTransform: parseTransformAttribute(\n el.getAttribute('gradientTransform') || '',\n ),\n ...(gradientUnits === 'pixels'\n ? {\n offsetX: instance.width / 2 - center.x,\n offsetY: instance.height / 2 - center.y,\n }\n : {\n offsetX: 0,\n offsetY: 0,\n }),\n });\n }\n /* _FROM_SVG_END_ */\n}\n\nclassRegistry.setClass(Gradient, 'gradient');\nclassRegistry.setClass(Gradient, 'linear');\nclassRegistry.setClass(Gradient, 'radial');\n"],"names":["Gradient","constructor","options","type","gradientUnits","coords","colorStops","offsetX","offsetY","gradientTransform","id","Object","assign","radialDefaultCoords","linearDefaultCoords","uid","addColorStop","position","push","offset","parseFloat","color","toObject","propertiesToInclude","pick","map","colorStop","undefined","toSVG","object","additionalTransform","preTransform","arguments","length","markup","transform","concat","iMatrix","sort","a","b","width","height","isPath","pathOffset","x","y","commonAttributes","escapeXml","String","matrixToSVG","join","sanitizeCoord","value","x1","y1","x2","y2","sx1","sy1","sx2","sy2","r1","r2","sr1","sr2","needsSwap","reverse","forEach","minRadius","Math","min","maxRadius","max","percentageShift","_ref","toLive","ctx","gradient","createLinearGradient","createRadialGradient","_ref2","fromObject","fromElement","el","instance","svgOptions","parseGradientUnits","center","_findCenterFromElement","getAttribute","parseType","parseCoords","viewBoxWidth","viewBoxHeight","parseColorStops","opacity","parseTransformAttribute","_defineProperty","classRegistry","setClass"],"mappings":";;;;;;;;;;;;;;AAwBA;AACA;AACA;AACA;AACA;AACO,MAAMA,QAAQ,CAGnB;EAsEAC,WAAWA,CAACC,OAA2B,EAAE;IACvC,MAAM;AACJC,MAAAA,IAAI,GAAG,QAAa;AACpBC,MAAAA,aAAa,GAAG,QAAQ;MACxBC,MAAM,GAAG,EAAE;AACXC,MAAAA,UAAU,GAAG,EAAE;AACfC,MAAAA,OAAO,GAAG,CAAC;AACXC,MAAAA,OAAO,GAAG,CAAC;MACXC,iBAAiB;AACjBC,MAAAA;AACF,KAAC,GAAGR,OAAO,IAAI,EAAE;AACjBS,IAAAA,MAAM,CAACC,MAAM,CAAC,IAAI,EAAE;MAClBT,IAAI;MACJC,aAAa;AACbC,MAAAA,MAAM,EAAE;AACN,QAAA,IAAIF,IAAI,KAAK,QAAQ,GAAGU,mBAAmB,GAAGC,mBAAmB,CAAC;QAClE,GAAGT;OACJ;MAC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M,EAAE4C,UAAU,CAACQ,aAAa,IAAIR,UAAU,CAAC5C;AACjD,OAAC,CAAC;MACFpC,UAAU,EAAEyF,eAAe,CAACX,EAAE,EAAEE,UAAU,CAACU,OAAO,CAAC;MACnD5F,aAAa;MACbK,iBAAiB,EAAEwF,uBAAuB,CACxCb,EAAE,CAACM,YAAY,CAAC,mBAAmB,CAAC,IAAI,EAC1C,CAAC;MACD,IAAItF,aAAa,KAAK,QAAQ,GAC1B;QACEG,OAAO,EAAE8E,QAAQ,CAAC5C,KAAK,GAAG,CAAC,GAAG+C,MAAM,CAAC3C,CAAC;QACtCrC,OAAO,EAAE6E,QAAQ,CAAC3C,MAAM,GAAG,CAAC,GAAG8C,MAAM,CAAC1C;AACxC,OAAC,GACD;AACEvC,QAAAA,OAAO,EAAE,CAAC;AACVC,QAAAA,OAAO,EAAE;OACV;AACP,KAAC,CAAC;AACJ,EAAA;AACA;AACF;AA3XE;AACF;AACA;AACA;AACA;AAGE;AACF;AACA;AACA;AACA;AAGE;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AAGE;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAGE;AACF;AACA;AACA;AACA;AAGE;AACF;AACA;AACA;AAGE;AACF;AACA;AACA;AACA;AAGE;AACF;AACA;AACA;AAGE;AACF;AACA;AACA;AAHE0F,eAAA,CAjEWlG,QAAQ,EAAA,MAAA,EAuEL,UAAU,CAAA;AA0T1BmG,aAAa,CAACC,QAAQ,CAACpG,QAAQ,EAAE,UAAU,CAAC;AAC5CmG,aAAa,CAACC,QAAQ,CAACpG,QAAQ,EAAE,QAAQ,CAAC;AAC1CmG,aAAa,CAACC,QAAQ,CAACpG,QAAQ,EAAE,QAAQ,CAAC;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"Circle.d.ts","sourceRoot":"","sources":["../../../src/shapes/Circle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAOrD,OA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IACH,UAAU,IAAI,MAAM;IAIpB;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM;IAKvB;;;;OAIG;IACH,QAAQ,CACN,CAAC,SAAS,IAAI,CAAC,KAAK,GAAG,gBAAgB,CAAC,IAAI,CAAC,EAAE,MAAM,MAAM,CAAC,EAC5D,CAAC,SAAS,MAAM,CAAC,GAAG,KAAK,EACzB,mBAAmB,GAAE,CAAC,EAAO,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM;IAMrD;;;;OAIG;IACH,MAAM,IAAI,MAAM,EAAE;IAgClB;;;OAGG;IACH,MAAM,CAAC,eAAe,WAA2C;IAEjE;;;;;OAKG;WACU,WAAW,CACtB,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,SAAS,EAClB,QAAQ,CAAC,EAAE,QAAQ,GAClB,OAAO,CAAC,MAAM,CAAC;IAwBlB;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;CAGvE"}
@@ -1,2 +1,2 @@
1
- import{defineProperty as t}from"../../_virtual/_rollupPluginBabelHelpers.min.mjs";import{SHARED_ATTRIBUTES as s}from"../parser/attributes.min.mjs";import{parseAttributes as e}from"../parser/parseAttributes.min.mjs";import{cos as r}from"../util/misc/cos.min.mjs";import{degreesToRadians as i}from"../util/misc/radiansDegreesConversion.min.mjs";import{sin as n}from"../util/misc/sin.min.mjs";import{classRegistry as o}from"../ClassRegistry.min.mjs";import{FabricObject as a}from"./Object/FabricObject.min.mjs";import{SCALE_X as u,SCALE_Y as m}from"../constants.min.mjs";import{cacheProperties as c}from"./Object/defaultValues.min.mjs";const l=["radius","startAngle","endAngle","counterClockwise"],h={radius:0,startAngle:0,endAngle:360,counterClockwise:!1};class d extends a{static getDefaults(){return{...super.getDefaults(),...d.ownDefaults}}constructor(t){super(),Object.assign(this,d.ownDefaults),this.setOptions(t)}_set(t,s){return super._set(t,s),"radius"===t&&this.setRadius(s),this}_render(t){t.beginPath(),t.arc(0,0,this.radius,i(this.startAngle),i(this.endAngle),this.counterClockwise),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get(u)}getRadiusY(){return this.get("radius")*this.get(m)}setRadius(t){this.radius=t,this.set({width:2*t,height:2*t})}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return super.toObject([...l,...t])}_toSVG(){const t=(this.endAngle-this.startAngle)%360;if(0===t)return["<circle ","COMMON_PARTS",'cx="0" cy="0" ','r="',`${this.radius}`,'" />\n'];{const{radius:s}=this,e=i(this.startAngle),o=i(this.endAngle),a=r(e)*s,u=n(e)*s,m=r(o)*s,c=n(o)*s;return[`<path d="M ${a} ${u} A ${s} ${s} 0 ${t>180?1:0} ${this.counterClockwise?0:1} ${m} ${c}" `,"COMMON_PARTS"," />\n"]}}static async fromElement(t,s,r){const{left:i=0,top:n=0,radius:o=0,...a}=e(t,this.ATTRIBUTE_NAMES,r);return new this({...a,radius:o,left:i-o,top:n-o})}static fromObject(t){return super._fromObject(t)}}t(d,"type","Circle"),t(d,"cacheProperties",[...c,...l]),t(d,"ownDefaults",h),t(d,"ATTRIBUTE_NAMES",["cx","cy","r",...s]),o.setClass(d),o.setSVGClass(d);export{d as Circle,h as circleDefaultValues};
1
+ import{defineProperty as t}from"../../_virtual/_rollupPluginBabelHelpers.min.mjs";import{SHARED_ATTRIBUTES as s}from"../parser/attributes.min.mjs";import{parseAttributes as e}from"../parser/parseAttributes.min.mjs";import{cos as r}from"../util/misc/cos.min.mjs";import{degreesToRadians as i}from"../util/misc/radiansDegreesConversion.min.mjs";import{sin as n}from"../util/misc/sin.min.mjs";import{classRegistry as o}from"../ClassRegistry.min.mjs";import{FabricObject as a}from"./Object/FabricObject.min.mjs";import{SCALE_X as m,SCALE_Y as u}from"../constants.min.mjs";import{escapeXml as c}from"../util/lang_string.min.mjs";import{cacheProperties as l}from"./Object/defaultValues.min.mjs";const p=["radius","startAngle","endAngle","counterClockwise"],d={radius:0,startAngle:0,endAngle:360,counterClockwise:!1};class h extends a{static getDefaults(){return{...super.getDefaults(),...h.ownDefaults}}constructor(t){super(),Object.assign(this,h.ownDefaults),this.setOptions(t)}_set(t,s){return super._set(t,s),"radius"===t&&this.setRadius(s),this}_render(t){t.beginPath(),t.arc(0,0,this.radius,i(this.startAngle),i(this.endAngle),this.counterClockwise),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get(m)}getRadiusY(){return this.get("radius")*this.get(u)}setRadius(t){this.radius=t,this.set({width:2*t,height:2*t})}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return super.toObject([...p,...t])}_toSVG(){const{radius:t,startAngle:s,endAngle:e}=this,o=(e-s)%360;if(0===o)return["<circle ","COMMON_PARTS",'cx="0" cy="0" ','r="',`${c(t)}`,'" />\n'];{const a=i(s),m=i(e),u=r(a)*t,c=n(a)*t,l=r(m)*t,p=n(m)*t;return[`<path d="M ${u} ${c} A ${t} ${t} 0 ${o>180?1:0} ${this.counterClockwise?0:1} ${l} ${p}" `,"COMMON_PARTS"," />\n"]}}static async fromElement(t,s,r){const{left:i=0,top:n=0,radius:o=0,...a}=e(t,this.ATTRIBUTE_NAMES,r);return new this({...a,radius:o,left:i-o,top:n-o})}static fromObject(t){return super._fromObject(t)}}t(h,"type","Circle"),t(h,"cacheProperties",[...l,...p]),t(h,"ownDefaults",d),t(h,"ATTRIBUTE_NAMES",["cx","cy","r",...s]),o.setClass(h),o.setSVGClass(h);export{h as Circle,d as circleDefaultValues};
2
2
  //# sourceMappingURL=Circle.min.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Circle.min.mjs","sources":["../../../src/shapes/Circle.ts"],"sourcesContent":["import type { ObjectEvents } from '../EventTypeDefs';\nimport { SHARED_ATTRIBUTES } from '../parser/attributes';\nimport { parseAttributes } from '../parser/parseAttributes';\nimport { cos } from '../util/misc/cos';\nimport { degreesToRadians } from '../util/misc/radiansDegreesConversion';\nimport { sin } from '../util/misc/sin';\nimport { classRegistry } from '../ClassRegistry';\nimport { FabricObject, cacheProperties } from './Object/FabricObject';\nimport type { Abortable, TClassProperties, TOptions } from '../typedefs';\nimport type { FabricObjectProps, SerializedObjectProps } from './Object/types';\nimport type { CSSRules } from '../parser/typedefs';\nimport { SCALE_X, SCALE_Y } from '../constants';\n\ninterface UniqueCircleProps {\n /**\n * Radius of this circle\n * @type Number\n * @default 0\n */\n radius: number;\n\n /**\n * Angle for the start of the circle, in degrees.\n * @type TDegree 0 - 359\n * @default 0\n */\n startAngle: number;\n\n /**\n * Angle for the end of the circle, in degrees\n * @type TDegree 1 - 360\n * @default 360\n */\n endAngle: number;\n\n /**\n * Orientation for the direction of the circle.\n * Setting to true will switch the arc of the circle to traverse from startAngle to endAngle in a counter-clockwise direction.\n * Note: this will only change how the circle is drawn, and does not affect rotational transformation.\n * @default false\n */\n counterClockwise: boolean;\n}\n\nexport interface SerializedCircleProps\n extends SerializedObjectProps,\n UniqueCircleProps {}\n\nexport interface CircleProps extends FabricObjectProps, UniqueCircleProps {}\n\nconst CIRCLE_PROPS = [\n 'radius',\n 'startAngle',\n 'endAngle',\n 'counterClockwise',\n] as const;\n\nexport const circleDefaultValues: Partial<TClassProperties<Circle>> = {\n radius: 0,\n startAngle: 0,\n endAngle: 360,\n counterClockwise: false,\n};\n\nexport class Circle<\n Props extends TOptions<CircleProps> = Partial<CircleProps>,\n SProps extends SerializedCircleProps = SerializedCircleProps,\n EventSpec extends ObjectEvents = ObjectEvents,\n >\n extends FabricObject<Props, SProps, EventSpec>\n implements UniqueCircleProps\n{\n declare radius: number;\n declare startAngle: number;\n declare endAngle: number;\n declare counterClockwise: boolean;\n\n static type = 'Circle';\n\n static cacheProperties = [...cacheProperties, ...CIRCLE_PROPS];\n\n static ownDefaults = circleDefaultValues;\n\n static getDefaults(): Record<string, any> {\n return {\n ...super.getDefaults(),\n ...Circle.ownDefaults,\n };\n }\n\n /**\n * Constructor\n * @param {Object} [options] Options object\n */\n constructor(options?: Props) {\n super();\n Object.assign(this, Circle.ownDefaults);\n this.setOptions(options);\n }\n\n /**\n * @private\n * @param {String} key\n * @param {*} value\n */\n _set(key: string, value: any) {\n super._set(key, value);\n\n if (key === 'radius') {\n this.setRadius(value);\n }\n\n return this;\n }\n\n /**\n * @private\n * @param {CanvasRenderingContext2D} ctx context to render on\n */\n _render(ctx: CanvasRenderingContext2D) {\n ctx.beginPath();\n ctx.arc(\n 0,\n 0,\n this.radius,\n degreesToRadians(this.startAngle),\n degreesToRadians(this.endAngle),\n this.counterClockwise,\n );\n this._renderPaintInOrder(ctx);\n }\n\n /**\n * Returns horizontal radius of an object (according to how an object is scaled)\n * @return {Number}\n */\n getRadiusX(): number {\n return this.get('radius') * this.get(SCALE_X);\n }\n\n /**\n * Returns vertical radius of an object (according to how an object is scaled)\n * @return {Number}\n */\n getRadiusY(): number {\n return this.get('radius') * this.get(SCALE_Y);\n }\n\n /**\n * Sets radius of an object (and updates width accordingly)\n */\n setRadius(value: number) {\n this.radius = value;\n this.set({ width: value * 2, height: value * 2 });\n }\n\n /**\n * Returns object representation of an instance\n * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output\n * @return {Object} object representation of an instance\n */\n toObject<\n T extends Omit<Props & TClassProperties<this>, keyof SProps>,\n K extends keyof T = never,\n >(propertiesToInclude: K[] = []): Pick<T, K> & SProps {\n return super.toObject([...CIRCLE_PROPS, ...propertiesToInclude]);\n }\n\n /* _TO_SVG_START_ */\n\n /**\n * Returns svg representation of an instance\n * @return {Array} an array of strings with the specific svg representation\n * of the instance\n */\n _toSVG(): string[] {\n const angle = (this.endAngle - this.startAngle) % 360;\n\n if (angle === 0) {\n return [\n '<circle ',\n 'COMMON_PARTS',\n 'cx=\"0\" cy=\"0\" ',\n 'r=\"',\n `${this.radius}`,\n '\" />\\n',\n ];\n } else {\n const { radius } = this;\n const start = degreesToRadians(this.startAngle),\n end = degreesToRadians(this.endAngle),\n startX = cos(start) * radius,\n startY = sin(start) * radius,\n endX = cos(end) * radius,\n endY = sin(end) * radius,\n largeFlag = angle > 180 ? 1 : 0,\n sweepFlag = this.counterClockwise ? 0 : 1;\n return [\n `<path d=\"M ${startX} ${startY} A ${radius} ${radius} 0 ${largeFlag} ${sweepFlag} ${endX} ${endY}\" `,\n 'COMMON_PARTS',\n ' />\\n',\n ];\n }\n }\n /* _TO_SVG_END_ */\n\n /* _FROM_SVG_START_ */\n /**\n * List of attribute names to account for when parsing SVG element (used by {@link Circle.fromElement})\n * @see: http://www.w3.org/TR/SVG/shapes.html#CircleElement\n */\n static ATTRIBUTE_NAMES = ['cx', 'cy', 'r', ...SHARED_ATTRIBUTES];\n\n /**\n * Returns {@link Circle} instance from an SVG element\n * @param {HTMLElement} element Element to parse\n * @param {Object} [options] Partial Circle object to default missing properties on the element.\n * @throws {Error} If value of `r` attribute is missing or invalid\n */\n static async fromElement(\n element: HTMLElement,\n options: Abortable,\n cssRules?: CSSRules,\n ): Promise<Circle> {\n const {\n left = 0,\n top = 0,\n radius = 0,\n ...otherParsedAttributes\n } = parseAttributes(\n element,\n this.ATTRIBUTE_NAMES,\n cssRules,\n ) as Partial<CircleProps>;\n\n // this probably requires to be fixed for default origins not being top/left.\n\n return new this({\n ...otherParsedAttributes,\n radius,\n left: left - radius,\n top: top - radius,\n });\n }\n\n /* _FROM_SVG_END_ */\n\n /**\n * @todo how do we declare this??\n */\n static fromObject<T extends TOptions<SerializedCircleProps>>(object: T) {\n return super._fromObject<Circle>(object);\n }\n}\n\nclassRegistry.setClass(Circle);\nclassRegistry.setSVGClass(Circle);\n"],"names":["CIRCLE_PROPS","circleDefaultValues","radius","startAngle","endAngle","counterClockwise","Circle","FabricObject","getDefaults","super","ownDefaults","constructor","options","Object","assign","this","setOptions","_set","key","value","setRadius","_render","ctx","beginPath","arc","degreesToRadians","_renderPaintInOrder","getRadiusX","get","SCALE_X","getRadiusY","SCALE_Y","set","width","height","toObject","propertiesToInclude","arguments","length","undefined","_toSVG","angle","start","end","startX","cos","startY","sin","endX","endY","fromElement","element","cssRules","left","top","otherParsedAttributes","parseAttributes","ATTRIBUTE_NAMES","fromObject","object","_fromObject","_defineProperty","cacheProperties","SHARED_ATTRIBUTES","classRegistry","setClass","setSVGClass"],"mappings":"ynBAkDA,MAAMA,EAAe,CACnB,SACA,aACA,WACA,oBAGWC,EAAyD,CACpEC,OAAQ,EACRC,WAAY,EACZC,SAAU,IACVC,kBAAkB,GAGb,MAAMC,UAKHC,EAcR,kBAAOC,GACL,MAAO,IACFC,MAAMD,iBACNF,EAAOI,YAEd,CAMAC,WAAAA,CAAYC,GACVH,QACAI,OAAOC,OAAOC,KAAMT,EAAOI,aAC3BK,KAAKC,WAAWJ,EAClB,CAOAK,IAAAA,CAAKC,EAAaC,GAOhB,OANAV,MAAMQ,KAAKC,EAAKC,GAEJ,WAARD,GACFH,KAAKK,UAAUD,GAGVJ,IACT,CAMAM,OAAAA,CAAQC,GACNA,EAAIC,YACJD,EAAIE,IACF,EACA,EACAT,KAAKb,OACLuB,EAAiBV,KAAKZ,YACtBsB,EAAiBV,KAAKX,UACtBW,KAAKV,kBAEPU,KAAKW,oBAAoBJ,EAC3B,CAMAK,UAAAA,GACE,OAAOZ,KAAKa,IAAI,UAAYb,KAAKa,IAAIC,EACvC,CAMAC,UAAAA,GACE,OAAOf,KAAKa,IAAI,UAAYb,KAAKa,IAAIG,EACvC,CAKAX,SAAAA,CAAUD,GACRJ,KAAKb,OAASiB,EACdJ,KAAKiB,IAAI,CAAEC,MAAe,EAARd,EAAWe,OAAgB,EAARf,GACvC,CAOAgB,QAAAA,GAGsD,IAApDC,EAAwBC,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,GAAG,GAC3B,OAAO5B,MAAM0B,SAAS,IAAInC,KAAiBoC,GAC7C,CASAI,MAAAA,GACE,MAAMC,GAAS1B,KAAKX,SAAWW,KAAKZ,YAAc,IAElD,GAAc,IAAVsC,EACF,MAAO,CACL,WACA,eACA,iBACA,MACA,GAAG1B,KAAKb,SACR,UAEG,CACL,MAAMA,OAAEA,GAAWa,KACb2B,EAAQjB,EAAiBV,KAAKZ,YAClCwC,EAAMlB,EAAiBV,KAAKX,UAC5BwC,EAASC,EAAIH,GAASxC,EACtB4C,EAASC,EAAIL,GAASxC,EACtB8C,EAAOH,EAAIF,GAAOzC,EAClB+C,EAAOF,EAAIJ,GAAOzC,EAGpB,MAAO,CACL,cAAc0C,KAAUE,OAAY5C,KAAUA,OAHlCuC,EAAQ,IAAM,EAAI,KAClB1B,KAAKV,iBAAmB,EAAI,KAE4C2C,KAAQC,MAC5F,eACA,QAEJ,CACF,CAgBA,wBAAaC,CACXC,EACAvC,EACAwC,GAEA,MAAMC,KACJA,EAAO,EAACC,IACRA,EAAM,EAACpD,OACPA,EAAS,KACNqD,GACDC,EACFL,EACApC,KAAK0C,gBACLL,GAKF,OAAO,IAAIrC,KAAK,IACXwC,EACHrD,SACAmD,KAAMA,EAAOnD,EACboD,IAAKA,EAAMpD,GAEf,CAOA,iBAAOwD,CAAsDC,GAC3D,OAAOlD,MAAMmD,YAAoBD,EACnC,EACDE,EA7LYvD,EAAM,OAaH,UAAQuD,EAbXvD,EAAM,kBAeQ,IAAIwD,KAAoB9D,IAAa6D,EAfnDvD,EAAM,cAiBIL,GAAmB4D,EAjB7BvD,EAAM,kBAmJQ,CAAC,KAAM,KAAM,OAAQyD,IA4ChDC,EAAcC,SAAS3D,GACvB0D,EAAcE,YAAY5D"}
1
+ {"version":3,"file":"Circle.min.mjs","sources":["../../../src/shapes/Circle.ts"],"sourcesContent":["import type { ObjectEvents } from '../EventTypeDefs';\nimport { SHARED_ATTRIBUTES } from '../parser/attributes';\nimport { parseAttributes } from '../parser/parseAttributes';\nimport { cos } from '../util/misc/cos';\nimport { degreesToRadians } from '../util/misc/radiansDegreesConversion';\nimport { sin } from '../util/misc/sin';\nimport { classRegistry } from '../ClassRegistry';\nimport { FabricObject, cacheProperties } from './Object/FabricObject';\nimport type { Abortable, TClassProperties, TOptions } from '../typedefs';\nimport type { FabricObjectProps, SerializedObjectProps } from './Object/types';\nimport type { CSSRules } from '../parser/typedefs';\nimport { SCALE_X, SCALE_Y } from '../constants';\nimport { escapeXml } from '../util/lang_string';\n\ninterface UniqueCircleProps {\n /**\n * Radius of this circle\n * @type Number\n * @default 0\n */\n radius: number;\n\n /**\n * Angle for the start of the circle, in degrees.\n * @type TDegree 0 - 359\n * @default 0\n */\n startAngle: number;\n\n /**\n * Angle for the end of the circle, in degrees\n * @type TDegree 1 - 360\n * @default 360\n */\n endAngle: number;\n\n /**\n * Orientation for the direction of the circle.\n * Setting to true will switch the arc of the circle to traverse from startAngle to endAngle in a counter-clockwise direction.\n * Note: this will only change how the circle is drawn, and does not affect rotational transformation.\n * @default false\n */\n counterClockwise: boolean;\n}\n\nexport interface SerializedCircleProps\n extends SerializedObjectProps, UniqueCircleProps {}\n\nexport interface CircleProps extends FabricObjectProps, UniqueCircleProps {}\n\nconst CIRCLE_PROPS = [\n 'radius',\n 'startAngle',\n 'endAngle',\n 'counterClockwise',\n] as const;\n\nexport const circleDefaultValues: Partial<TClassProperties<Circle>> = {\n radius: 0,\n startAngle: 0,\n endAngle: 360,\n counterClockwise: false,\n};\n\nexport class Circle<\n Props extends TOptions<CircleProps> = Partial<CircleProps>,\n SProps extends SerializedCircleProps = SerializedCircleProps,\n EventSpec extends ObjectEvents = ObjectEvents,\n>\n extends FabricObject<Props, SProps, EventSpec>\n implements UniqueCircleProps\n{\n declare radius: number;\n declare startAngle: number;\n declare endAngle: number;\n declare counterClockwise: boolean;\n\n static type = 'Circle';\n\n static cacheProperties = [...cacheProperties, ...CIRCLE_PROPS];\n\n static ownDefaults = circleDefaultValues;\n\n static getDefaults(): Record<string, any> {\n return {\n ...super.getDefaults(),\n ...Circle.ownDefaults,\n };\n }\n\n /**\n * Constructor\n * @param {Object} [options] Options object\n */\n constructor(options?: Props) {\n super();\n Object.assign(this, Circle.ownDefaults);\n this.setOptions(options);\n }\n\n /**\n * @private\n * @param {String} key\n * @param {*} value\n */\n _set(key: string, value: any) {\n super._set(key, value);\n\n if (key === 'radius') {\n this.setRadius(value);\n }\n\n return this;\n }\n\n /**\n * @private\n * @param {CanvasRenderingContext2D} ctx context to render on\n */\n _render(ctx: CanvasRenderingContext2D) {\n ctx.beginPath();\n ctx.arc(\n 0,\n 0,\n this.radius,\n degreesToRadians(this.startAngle),\n degreesToRadians(this.endAngle),\n this.counterClockwise,\n );\n this._renderPaintInOrder(ctx);\n }\n\n /**\n * Returns horizontal radius of an object (according to how an object is scaled)\n * @return {Number}\n */\n getRadiusX(): number {\n return this.get('radius') * this.get(SCALE_X);\n }\n\n /**\n * Returns vertical radius of an object (according to how an object is scaled)\n * @return {Number}\n */\n getRadiusY(): number {\n return this.get('radius') * this.get(SCALE_Y);\n }\n\n /**\n * Sets radius of an object (and updates width accordingly)\n */\n setRadius(value: number) {\n this.radius = value;\n this.set({ width: value * 2, height: value * 2 });\n }\n\n /**\n * Returns object representation of an instance\n * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output\n * @return {Object} object representation of an instance\n */\n toObject<\n T extends Omit<Props & TClassProperties<this>, keyof SProps>,\n K extends keyof T = never,\n >(propertiesToInclude: K[] = []): Pick<T, K> & SProps {\n return super.toObject([...CIRCLE_PROPS, ...propertiesToInclude]);\n }\n\n /* _TO_SVG_START_ */\n\n /**\n * Returns svg representation of an instance\n * @return {Array} an array of strings with the specific svg representation\n * of the instance\n */\n _toSVG(): string[] {\n const { radius, startAngle, endAngle } = this;\n const angle = (endAngle - startAngle) % 360;\n\n if (angle === 0) {\n return [\n '<circle ',\n 'COMMON_PARTS',\n 'cx=\"0\" cy=\"0\" ',\n 'r=\"',\n `${escapeXml(radius)}`,\n '\" />\\n',\n ];\n } else {\n const start = degreesToRadians(startAngle),\n end = degreesToRadians(endAngle),\n startX = cos(start) * radius,\n startY = sin(start) * radius,\n endX = cos(end) * radius,\n endY = sin(end) * radius,\n largeFlag = angle > 180 ? 1 : 0,\n sweepFlag = this.counterClockwise ? 0 : 1;\n return [\n `<path d=\"M ${startX} ${startY} A ${radius} ${radius} 0 ${largeFlag} ${sweepFlag} ${endX} ${endY}\" `,\n 'COMMON_PARTS',\n ' />\\n',\n ];\n }\n }\n /* _TO_SVG_END_ */\n\n /* _FROM_SVG_START_ */\n /**\n * List of attribute names to account for when parsing SVG element (used by {@link Circle.fromElement})\n * @see: http://www.w3.org/TR/SVG/shapes.html#CircleElement\n */\n static ATTRIBUTE_NAMES = ['cx', 'cy', 'r', ...SHARED_ATTRIBUTES];\n\n /**\n * Returns {@link Circle} instance from an SVG element\n * @param {HTMLElement} element Element to parse\n * @param {Object} [options] Partial Circle object to default missing properties on the element.\n * @throws {Error} If value of `r` attribute is missing or invalid\n */\n static async fromElement(\n element: HTMLElement,\n options: Abortable,\n cssRules?: CSSRules,\n ): Promise<Circle> {\n const {\n left = 0,\n top = 0,\n radius = 0,\n ...otherParsedAttributes\n } = parseAttributes(\n element,\n this.ATTRIBUTE_NAMES,\n cssRules,\n ) as Partial<CircleProps>;\n\n // this probably requires to be fixed for default origins not being top/left.\n\n return new this({\n ...otherParsedAttributes,\n radius,\n left: left - radius,\n top: top - radius,\n });\n }\n\n /* _FROM_SVG_END_ */\n\n /**\n * @todo how do we declare this??\n */\n static fromObject<T extends TOptions<SerializedCircleProps>>(object: T) {\n return super._fromObject<Circle>(object);\n }\n}\n\nclassRegistry.setClass(Circle);\nclassRegistry.setSVGClass(Circle);\n"],"names":["CIRCLE_PROPS","circleDefaultValues","radius","startAngle","endAngle","counterClockwise","Circle","FabricObject","getDefaults","super","ownDefaults","constructor","options","Object","assign","this","setOptions","_set","key","value","setRadius","_render","ctx","beginPath","arc","degreesToRadians","_renderPaintInOrder","getRadiusX","get","SCALE_X","getRadiusY","SCALE_Y","set","width","height","toObject","propertiesToInclude","arguments","length","undefined","_toSVG","angle","escapeXml","start","end","startX","cos","startY","sin","endX","endY","fromElement","element","cssRules","left","top","otherParsedAttributes","parseAttributes","ATTRIBUTE_NAMES","fromObject","object","_fromObject","_defineProperty","cacheProperties","SHARED_ATTRIBUTES","classRegistry","setClass","setSVGClass"],"mappings":"irBAkDA,MAAMA,EAAe,CACnB,SACA,aACA,WACA,oBAGWC,EAAyD,CACpEC,OAAQ,EACRC,WAAY,EACZC,SAAU,IACVC,kBAAkB,GAGb,MAAMC,UAKHC,EAcR,kBAAOC,GACL,MAAO,IACFC,MAAMD,iBACNF,EAAOI,YAEd,CAMAC,WAAAA,CAAYC,GACVH,QACAI,OAAOC,OAAOC,KAAMT,EAAOI,aAC3BK,KAAKC,WAAWJ,EAClB,CAOAK,IAAAA,CAAKC,EAAaC,GAOhB,OANAV,MAAMQ,KAAKC,EAAKC,GAEJ,WAARD,GACFH,KAAKK,UAAUD,GAGVJ,IACT,CAMAM,OAAAA,CAAQC,GACNA,EAAIC,YACJD,EAAIE,IACF,EACA,EACAT,KAAKb,OACLuB,EAAiBV,KAAKZ,YACtBsB,EAAiBV,KAAKX,UACtBW,KAAKV,kBAEPU,KAAKW,oBAAoBJ,EAC3B,CAMAK,UAAAA,GACE,OAAOZ,KAAKa,IAAI,UAAYb,KAAKa,IAAIC,EACvC,CAMAC,UAAAA,GACE,OAAOf,KAAKa,IAAI,UAAYb,KAAKa,IAAIG,EACvC,CAKAX,SAAAA,CAAUD,GACRJ,KAAKb,OAASiB,EACdJ,KAAKiB,IAAI,CAAEC,MAAe,EAARd,EAAWe,OAAgB,EAARf,GACvC,CAOAgB,QAAAA,GAGsD,IAApDC,EAAwBC,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,GAAG,GAC3B,OAAO5B,MAAM0B,SAAS,IAAInC,KAAiBoC,GAC7C,CASAI,MAAAA,GACE,MAAMtC,OAAEA,EAAMC,WAAEA,EAAUC,SAAEA,GAAaW,KACnC0B,GAASrC,EAAWD,GAAc,IAExC,GAAc,IAAVsC,EACF,MAAO,CACL,WACA,eACA,iBACA,MACA,GAAGC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