fabric 5.3.0 → 6.0.0-beta3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (604) hide show
  1. package/.babelrc +11 -0
  2. package/.babelrcAlt +19 -0
  3. package/.browserslistrc +5 -0
  4. package/.eslintignore +3 -0
  5. package/.eslintrc.js +43 -0
  6. package/.eslintrc.json +38 -46
  7. package/.eslintrc_tests +12 -0
  8. package/.gitattributes +2 -0
  9. package/.gitpod.yml +17 -1
  10. package/.prettierignore +19 -0
  11. package/.prettierrc +4 -0
  12. package/CHANGELOG.md +532 -189
  13. package/CONTRIBUTING.md +224 -59
  14. package/README.md +200 -235
  15. package/bower.json +1 -3
  16. package/dist/fabric.d.ts +42 -0
  17. package/dist/index.d.ts +2 -0
  18. package/dist/index.js +27582 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/index.min.js +1 -0
  21. package/dist/index.mjs +27519 -0
  22. package/dist/index.mjs.map +1 -0
  23. package/dist/index.node.cjs +27663 -0
  24. package/dist/index.node.cjs.map +1 -0
  25. package/dist/index.node.d.ts +14 -0
  26. package/dist/index.node.mjs +27606 -0
  27. package/dist/index.node.mjs.map +1 -0
  28. package/dist/src/ClassRegistry.d.ts +13 -0
  29. package/dist/src/Collection.d.ts +136 -0
  30. package/dist/src/CommonMethods.d.ts +32 -0
  31. package/dist/src/EventTypeDefs.d.ts +227 -0
  32. package/dist/src/Intersection.d.ts +112 -0
  33. package/dist/src/Observable.d.ts +60 -0
  34. package/dist/src/Pattern.d.ts +113 -0
  35. package/dist/src/Point.d.ts +232 -0
  36. package/dist/src/Shadow.d.ts +97 -0
  37. package/dist/src/brushes/BaseBrush.d.ts +105 -0
  38. package/dist/src/brushes/CircleBrush.d.ts +49 -0
  39. package/dist/src/brushes/PatternBrush.d.ts +23 -0
  40. package/dist/src/brushes/PencilBrush.d.ts +92 -0
  41. package/dist/src/brushes/SprayBrush.d.ts +79 -0
  42. package/dist/src/cache.d.ts +47 -0
  43. package/dist/src/canvas/Canvas.d.ts +548 -0
  44. package/dist/src/canvas/SelectableCanvas.d.ts +754 -0
  45. package/dist/src/canvas/StaticCanvas.d.ts +778 -0
  46. package/dist/src/canvas/TextEditingManager.d.ts +17 -0
  47. package/dist/src/canvas/canvas_gestures.mixin.d.ts +2 -0
  48. package/dist/src/color/Color.d.ts +174 -0
  49. package/dist/src/color/color_map.d.ts +155 -0
  50. package/dist/src/color/constants.d.ts +22 -0
  51. package/dist/src/color/util.d.ts +12 -0
  52. package/dist/src/config.d.ts +115 -0
  53. package/dist/src/constants.d.ts +14 -0
  54. package/dist/src/controls/Control.d.ts +228 -0
  55. package/dist/src/controls/changeWidth.d.ts +13 -0
  56. package/dist/src/controls/commonControls.d.ts +28 -0
  57. package/dist/src/controls/controlRendering.d.ts +29 -0
  58. package/dist/src/controls/drag.d.ts +12 -0
  59. package/dist/src/controls/index.d.ts +13 -0
  60. package/dist/src/controls/polyControl.d.ts +5 -0
  61. package/dist/src/controls/rotate.d.ts +12 -0
  62. package/dist/src/controls/scale.d.ts +47 -0
  63. package/dist/src/controls/scaleSkew.d.ts +39 -0
  64. package/dist/src/controls/skew.d.ts +33 -0
  65. package/dist/src/controls/util.d.ts +41 -0
  66. package/dist/src/controls/wrapWithFireEvent.d.ts +8 -0
  67. package/dist/src/controls/wrapWithFixedAnchor.d.ts +9 -0
  68. package/dist/src/env/browser.d.ts +3 -0
  69. package/dist/src/env/index.d.ts +15 -0
  70. package/dist/src/env/node.d.ts +5 -0
  71. package/dist/src/env/types.d.ts +15 -0
  72. package/dist/src/filters/BaseFilter.d.ts +153 -0
  73. package/dist/src/filters/BlendColor.d.ts +80 -0
  74. package/dist/src/filters/BlendImage.d.ts +92 -0
  75. package/dist/src/filters/Blur.d.ts +51 -0
  76. package/dist/src/filters/Boilerplate.d.ts +48 -0
  77. package/dist/src/filters/Brightness.d.ts +47 -0
  78. package/dist/src/filters/Canvas2dFilterBackend.d.ts +27 -0
  79. package/dist/src/filters/ColorMatrix.d.ts +63 -0
  80. package/dist/src/filters/ColorMatrixFilters.d.ts +545 -0
  81. package/dist/src/filters/Composed.d.ts +45 -0
  82. package/dist/src/filters/Contrast.d.ts +45 -0
  83. package/dist/src/filters/Convolute.d.ts +82 -0
  84. package/dist/src/filters/FilterBackend.d.ts +14 -0
  85. package/dist/src/filters/GLProbes/GLProbe.d.ts +11 -0
  86. package/dist/src/filters/GLProbes/NodeGLProbe.d.ts +11 -0
  87. package/dist/src/filters/GLProbes/WebGLProbe.d.ts +20 -0
  88. package/dist/src/filters/Gamma.d.ts +54 -0
  89. package/dist/src/filters/Grayscale.d.ts +46 -0
  90. package/dist/src/filters/HueRotation.d.ts +24 -0
  91. package/dist/src/filters/Invert.d.ts +55 -0
  92. package/dist/src/filters/Noise.d.ts +54 -0
  93. package/dist/src/filters/Pixelate.d.ts +44 -0
  94. package/dist/src/filters/RemoveColor.d.ts +63 -0
  95. package/dist/src/filters/Resize.d.ts +136 -0
  96. package/dist/src/filters/Saturation.d.ts +48 -0
  97. package/dist/src/filters/Vibrance.d.ts +48 -0
  98. package/dist/src/filters/WebGLFilterBackend.d.ts +126 -0
  99. package/dist/src/filters/filters.d.ts +21 -0
  100. package/dist/src/filters/index.d.ts +5 -0
  101. package/dist/src/filters/shaders/baseFilter.d.ts +4 -0
  102. package/dist/src/filters/shaders/blendColor.d.ts +13 -0
  103. package/dist/src/filters/shaders/blendImage.d.ts +3 -0
  104. package/dist/src/filters/shaders/blur.d.ts +2 -0
  105. package/dist/src/filters/shaders/brightness.d.ts +2 -0
  106. package/dist/src/filters/shaders/colorMatrix.d.ts +2 -0
  107. package/dist/src/filters/shaders/constrast.d.ts +2 -0
  108. package/dist/src/filters/shaders/convolute.d.ts +11 -0
  109. package/dist/src/filters/shaders/gamma.d.ts +2 -0
  110. package/dist/src/filters/shaders/grayscale.d.ts +3 -0
  111. package/dist/src/filters/shaders/invert.d.ts +2 -0
  112. package/dist/src/filters/shaders/noise.d.ts +2 -0
  113. package/dist/src/filters/shaders/pixelate.d.ts +2 -0
  114. package/dist/src/filters/shaders/removeColor.d.ts +2 -0
  115. package/dist/src/filters/shaders/saturation.d.ts +2 -0
  116. package/dist/src/filters/shaders/vibrance.d.ts +2 -0
  117. package/dist/src/filters/typedefs.d.ts +49 -0
  118. package/dist/src/gradient/Gradient.d.ts +149 -0
  119. package/dist/src/gradient/constants.d.ts +15 -0
  120. package/dist/src/gradient/parser/index.d.ts +4 -0
  121. package/dist/src/gradient/parser/misc.d.ts +4 -0
  122. package/dist/src/gradient/parser/parseColorStops.d.ts +3 -0
  123. package/dist/src/gradient/parser/parseCoords.d.ts +17 -0
  124. package/dist/src/gradient/typedefs.d.ts +93 -0
  125. package/dist/src/mixins/eraser_brush.mixin.d.ts +2 -0
  126. package/dist/src/parkinglot/canvas_animation.mixin.d.ts +2 -0
  127. package/dist/src/parkinglot/straighten.d.ts +2 -0
  128. package/dist/src/parser/applyViewboxTransform.d.ts +5 -0
  129. package/dist/src/parser/attributes.d.ts +6 -0
  130. package/dist/src/parser/constants.d.ts +53 -0
  131. package/dist/src/parser/doesSomeParentMatch.d.ts +2 -0
  132. package/dist/src/parser/elementById.d.ts +6 -0
  133. package/dist/src/parser/elementMatchesRule.d.ts +5 -0
  134. package/dist/src/parser/elements_parser.d.ts +3 -0
  135. package/dist/src/parser/getCSSRules.d.ts +7 -0
  136. package/dist/src/parser/getGlobalStylesForElement.d.ts +5 -0
  137. package/dist/src/parser/getGradientDefs.d.ts +7 -0
  138. package/dist/src/parser/getMultipleNodes.d.ts +2 -0
  139. package/dist/src/parser/getSvgRegex.d.ts +2 -0
  140. package/dist/src/parser/hasAncestorWithNodeName.d.ts +2 -0
  141. package/dist/src/parser/index.d.ts +10 -0
  142. package/dist/src/parser/loadSVGFromString.d.ts +12 -0
  143. package/dist/src/parser/loadSVGFromURL.d.ts +13 -0
  144. package/dist/src/parser/normalizeAttr.d.ts +2 -0
  145. package/dist/src/parser/normalizeValue.d.ts +2 -0
  146. package/dist/src/parser/parseAttributes.d.ts +9 -0
  147. package/dist/src/parser/parseElements.d.ts +11 -0
  148. package/dist/src/parser/parseFontDeclaration.d.ts +10 -0
  149. package/dist/src/parser/parsePointsAttribute.d.ts +12 -0
  150. package/dist/src/parser/parseSVGDocument.d.ts +15 -0
  151. package/dist/src/parser/parseStyleAttribute.d.ts +9 -0
  152. package/dist/src/parser/parseStyleObject.d.ts +2 -0
  153. package/dist/src/parser/parseStyleString.d.ts +2 -0
  154. package/dist/src/parser/parseTransformAttribute.d.ts +10 -0
  155. package/dist/src/parser/parseUseDirectives.d.ts +2 -0
  156. package/dist/src/parser/percent.d.ts +9 -0
  157. package/dist/src/parser/recursivelyParseGradientsXlink.d.ts +2 -0
  158. package/dist/src/parser/rotateMatrix.d.ts +2 -0
  159. package/dist/src/parser/scaleMatrix.d.ts +2 -0
  160. package/dist/src/parser/selectorMatches.d.ts +2 -0
  161. package/dist/src/parser/setStrokeFillOpacity.d.ts +6 -0
  162. package/dist/src/parser/skewMatrix.d.ts +2 -0
  163. package/dist/src/parser/translateMatrix.d.ts +2 -0
  164. package/dist/src/shapes/ActiveSelection.d.ts +82 -0
  165. package/dist/src/shapes/Circle.d.ts +99 -0
  166. package/dist/src/shapes/Ellipse.d.ts +84 -0
  167. package/dist/src/shapes/Group.d.ts +408 -0
  168. package/dist/src/shapes/IText/DraggableTextDelegate.d.ts +78 -0
  169. package/dist/src/shapes/IText/IText.d.ts +335 -0
  170. package/dist/src/shapes/IText/ITextBehavior.d.ts +287 -0
  171. package/dist/src/shapes/IText/ITextClickBehavior.d.ts +83 -0
  172. package/dist/src/shapes/IText/ITextKeyBehavior.d.ts +195 -0
  173. package/dist/src/shapes/IText/constants.d.ts +13 -0
  174. package/dist/src/shapes/Image.d.ts +311 -0
  175. package/dist/src/shapes/Line.d.ts +126 -0
  176. package/dist/src/shapes/Object/AnimatableObject.d.ts +33 -0
  177. package/dist/src/shapes/Object/FabricObject.d.ts +11 -0
  178. package/dist/src/shapes/Object/FabricObjectSVGExportMixin.d.ts +74 -0
  179. package/dist/src/shapes/Object/InteractiveObject.d.ts +296 -0
  180. package/dist/src/shapes/Object/Object.d.ts +594 -0
  181. package/dist/src/shapes/Object/ObjectGeometry.d.ts +327 -0
  182. package/dist/src/shapes/Object/ObjectOrigin.d.ts +109 -0
  183. package/dist/src/shapes/Object/StackedObject.d.ts +72 -0
  184. package/dist/src/shapes/Object/defaultValues.d.ts +76 -0
  185. package/dist/src/shapes/Object/types/BaseProps.d.ts +84 -0
  186. package/dist/src/shapes/Object/types/BorderProps.d.ts +37 -0
  187. package/dist/src/shapes/Object/types/ControlProps.d.ts +62 -0
  188. package/dist/src/shapes/Object/types/FabricObjectProps.d.ts +96 -0
  189. package/dist/src/shapes/Object/types/FillStrokeProps.d.ts +80 -0
  190. package/dist/src/shapes/Object/types/LockInteractionProps.d.ts +51 -0
  191. package/dist/src/shapes/Object/types/ObjectProps.d.ts +42 -0
  192. package/dist/src/shapes/Object/types/SerializedObjectProps.d.ts +66 -0
  193. package/dist/src/shapes/Object/types/index.d.ts +6 -0
  194. package/dist/src/shapes/Path.d.ts +130 -0
  195. package/dist/src/shapes/Polygon.d.ts +9 -0
  196. package/dist/src/shapes/Polyline.d.ts +140 -0
  197. package/dist/src/shapes/Rect.d.ts +76 -0
  198. package/dist/src/shapes/Text/StyledText.d.ts +119 -0
  199. package/dist/src/shapes/Text/Text.d.ts +673 -0
  200. package/dist/src/shapes/Text/TextSVGExportMixin.d.ts +32 -0
  201. package/dist/src/shapes/Text/constants.d.ts +7 -0
  202. package/dist/src/shapes/Textbox.d.ts +185 -0
  203. package/dist/src/shapes/Triangle.d.ts +25 -0
  204. package/dist/src/typedefs.d.ts +90 -0
  205. package/dist/src/util/animation/AnimationBase.d.ts +54 -0
  206. package/dist/src/util/animation/AnimationFrameProvider.d.ts +3 -0
  207. package/dist/src/util/animation/AnimationRegistry.d.ts +29 -0
  208. package/dist/src/util/animation/ArrayAnimation.d.ts +10 -0
  209. package/dist/src/util/animation/ColorAnimation.d.ts +11 -0
  210. package/dist/src/util/animation/ValueAnimation.d.ts +10 -0
  211. package/dist/src/util/animation/animate.d.ts +37 -0
  212. package/dist/src/util/animation/easing.d.ts +130 -0
  213. package/dist/src/util/animation/types.d.ts +87 -0
  214. package/dist/src/util/applyMixins.d.ts +8 -0
  215. package/dist/src/util/dom_event.d.ts +5 -0
  216. package/dist/src/util/dom_misc.d.ts +39 -0
  217. package/dist/src/util/dom_request.d.ts +14 -0
  218. package/dist/src/util/dom_style.d.ts +7 -0
  219. package/dist/src/util/fireEvent.d.ts +3 -0
  220. package/dist/src/util/index.d.ts +35 -0
  221. package/dist/src/util/internals/cloneDeep.d.ts +2 -0
  222. package/dist/src/util/internals/getRandomInt.d.ts +8 -0
  223. package/dist/src/util/internals/ifNaN.d.ts +8 -0
  224. package/dist/src/util/internals/index.d.ts +4 -0
  225. package/dist/src/util/internals/removeFromArray.d.ts +9 -0
  226. package/dist/src/util/internals/uid.d.ts +2 -0
  227. package/dist/src/util/lang_string.d.ts +22 -0
  228. package/dist/src/util/misc/boundingBoxFromPoints.d.ts +9 -0
  229. package/dist/src/util/misc/capValue.d.ts +2 -0
  230. package/dist/src/util/misc/cos.d.ts +10 -0
  231. package/dist/src/util/misc/dom.d.ts +28 -0
  232. package/dist/src/util/misc/findScaleTo.d.ts +29 -0
  233. package/dist/src/util/misc/groupSVGElements.d.ts +9 -0
  234. package/dist/src/util/misc/isTransparent.d.ts +11 -0
  235. package/dist/src/util/misc/matrix.d.ts +92 -0
  236. package/dist/src/util/misc/mergeClipPaths.d.ts +23 -0
  237. package/dist/src/util/misc/objectEnlive.d.ts +56 -0
  238. package/dist/src/util/misc/objectTransforms.d.ts +68 -0
  239. package/dist/src/util/misc/pick.d.ts +9 -0
  240. package/dist/src/util/misc/planeChange.d.ts +84 -0
  241. package/dist/src/util/misc/projectStroke/StrokeLineCapProjections.d.ts +51 -0
  242. package/dist/src/util/misc/projectStroke/StrokeLineJoinProjections.d.ts +81 -0
  243. package/dist/src/util/misc/projectStroke/StrokeProjectionsBase.d.ts +25 -0
  244. package/dist/src/util/misc/projectStroke/index.d.ts +11 -0
  245. package/dist/src/util/misc/projectStroke/types.d.ts +23 -0
  246. package/dist/src/util/misc/radiansDegreesConversion.d.ts +14 -0
  247. package/dist/src/util/misc/resolveOrigin.d.ts +9 -0
  248. package/dist/src/util/misc/rotatePoint.d.ts +12 -0
  249. package/dist/src/util/misc/sin.d.ts +10 -0
  250. package/dist/src/util/misc/svgParsing.d.ts +53 -0
  251. package/dist/src/util/misc/textStyles.d.ts +32 -0
  252. package/dist/src/util/misc/toFixed.d.ts +8 -0
  253. package/dist/src/util/misc/vectors.d.ts +57 -0
  254. package/dist/src/util/path/index.d.ts +96 -0
  255. package/dist/src/util/path/regex.d.ts +3 -0
  256. package/dist/src/util/path/typechecks.d.ts +24 -0
  257. package/dist/src/util/path/typedefs.d.ts +220 -0
  258. package/dist/src/util/transform_matrix_removal.d.ts +14 -0
  259. package/dist/src/util/types.d.ts +19 -0
  260. package/fabric.ts +51 -0
  261. package/index.node.ts +37 -0
  262. package/index.ts +1 -0
  263. package/package.json +100 -40
  264. package/publish.js +0 -26
  265. package/rollup.config.mjs +91 -0
  266. package/rollup.test.config.js +24 -0
  267. package/scripts/build.mjs +50 -0
  268. package/scripts/buildLock.mjs +115 -0
  269. package/scripts/buildReporter.mjs +15 -0
  270. package/scripts/buildStats.mjs +139 -0
  271. package/scripts/dirname.mjs +14 -0
  272. package/scripts/git.mjs +36 -0
  273. package/scripts/index.mjs +564 -0
  274. package/scripts/sandbox.mjs +149 -0
  275. package/src/ClassRegistry.ts +56 -0
  276. package/src/Collection.ts +346 -0
  277. package/src/CommonMethods.ts +63 -0
  278. package/src/EventTypeDefs.ts +296 -0
  279. package/src/Intersection.ts +302 -0
  280. package/src/Observable.ts +181 -0
  281. package/src/Pattern.ts +227 -0
  282. package/src/Point.ts +388 -0
  283. package/src/Shadow.ts +214 -0
  284. package/src/brushes/{base_brush.class.js → BaseBrush.ts} +65 -42
  285. package/src/brushes/CircleBrush.ts +145 -0
  286. package/src/brushes/PatternBrush.ts +70 -0
  287. package/src/brushes/PencilBrush.ts +300 -0
  288. package/src/brushes/SprayBrush.ts +219 -0
  289. package/src/cache.ts +90 -0
  290. package/src/canvas/Canvas.ts +1607 -0
  291. package/src/canvas/SelectableCanvas.ts +1608 -0
  292. package/src/canvas/StaticCanvas.ts +1734 -0
  293. package/src/canvas/TextEditingManager.ts +48 -0
  294. package/src/canvas/canvas_gestures.mixin.ts +207 -0
  295. package/src/color/Color.ts +404 -0
  296. package/src/color/color_map.ts +154 -0
  297. package/src/color/constants.ts +26 -0
  298. package/src/color/util.ts +32 -0
  299. package/src/config.ts +159 -0
  300. package/src/constants.ts +20 -0
  301. package/src/controls/Control.ts +380 -0
  302. package/src/controls/changeWidth.ts +52 -0
  303. package/src/controls/commonControls.ts +105 -0
  304. package/src/controls/controlRendering.ts +138 -0
  305. package/src/controls/drag.ts +31 -0
  306. package/src/controls/index.ts +22 -0
  307. package/src/controls/polyControl.ts +135 -0
  308. package/src/controls/rotate.ts +87 -0
  309. package/src/controls/scale.ts +277 -0
  310. package/src/controls/scaleSkew.ts +92 -0
  311. package/src/controls/skew.ts +242 -0
  312. package/src/controls/util.ts +154 -0
  313. package/src/controls/wrapWithFireEvent.ts +25 -0
  314. package/src/controls/wrapWithFixedAnchor.ts +20 -0
  315. package/src/env/browser.ts +32 -0
  316. package/src/env/index.ts +24 -0
  317. package/src/env/node.ts +56 -0
  318. package/src/env/types.ts +15 -0
  319. package/src/filters/{base_filter.class.js → BaseFilter.ts} +192 -151
  320. package/src/filters/BlendColor.ts +217 -0
  321. package/src/filters/BlendImage.ts +228 -0
  322. package/src/filters/Blur.ts +179 -0
  323. package/src/filters/Boilerplate.ts +94 -0
  324. package/src/filters/Brightness.ts +83 -0
  325. package/src/filters/Canvas2dFilterBackend.ts +65 -0
  326. package/src/filters/ColorMatrix.ts +145 -0
  327. package/src/filters/ColorMatrixFilters.ts +77 -0
  328. package/src/filters/Composed.ts +76 -0
  329. package/src/filters/Contrast.ts +82 -0
  330. package/src/filters/Convolute.ts +184 -0
  331. package/src/filters/FilterBackend.ts +34 -0
  332. package/src/filters/GLProbes/GLProbe.ts +11 -0
  333. package/src/filters/GLProbes/NodeGLProbe.ts +15 -0
  334. package/src/filters/GLProbes/WebGLProbe.ts +46 -0
  335. package/src/filters/Gamma.ts +110 -0
  336. package/src/filters/Grayscale.ts +102 -0
  337. package/src/filters/HueRotation.ts +62 -0
  338. package/src/filters/Invert.ts +99 -0
  339. package/src/filters/Noise.ts +94 -0
  340. package/src/filters/Pixelate.ts +96 -0
  341. package/src/filters/RemoveColor.ts +135 -0
  342. package/src/filters/Resize.ts +538 -0
  343. package/src/filters/Saturation.ts +87 -0
  344. package/src/filters/Vibrance.ts +88 -0
  345. package/src/filters/WebGLFilterBackend.ts +430 -0
  346. package/src/filters/filters.ts +28 -0
  347. package/src/filters/index.ts +5 -0
  348. package/src/filters/shaders/baseFilter.ts +19 -0
  349. package/src/filters/shaders/blendColor.ts +33 -0
  350. package/src/filters/shaders/blendImage.ts +32 -0
  351. package/src/filters/shaders/blur.ts +24 -0
  352. package/src/filters/shaders/brightness.ts +11 -0
  353. package/src/filters/shaders/colorMatrix.ts +12 -0
  354. package/src/filters/shaders/constrast.ts +11 -0
  355. package/src/filters/shaders/convolute.ts +154 -0
  356. package/src/filters/shaders/gamma.ts +15 -0
  357. package/src/filters/shaders/grayscale.ts +36 -0
  358. package/src/filters/shaders/invert.ts +19 -0
  359. package/src/filters/shaders/noise.ts +16 -0
  360. package/src/filters/shaders/pixelate.ts +19 -0
  361. package/src/filters/shaders/removeColor.ts +13 -0
  362. package/src/filters/shaders/saturation.ts +15 -0
  363. package/src/filters/shaders/vibrance.ts +16 -0
  364. package/src/filters/typedefs.ts +65 -0
  365. package/src/gradient/Gradient.ts +406 -0
  366. package/src/gradient/constants.ts +12 -0
  367. package/src/gradient/parser/index.ts +3 -0
  368. package/src/gradient/parser/misc.ts +13 -0
  369. package/src/gradient/parser/parseColorStops.ts +56 -0
  370. package/src/gradient/parser/parseCoords.ts +73 -0
  371. package/src/gradient/typedefs.ts +104 -0
  372. package/src/mixins/{eraser_brush.mixin.js → eraser_brush.mixin.ts} +350 -239
  373. package/src/parkinglot/canvas_animation.mixin.ts +121 -0
  374. package/src/parkinglot/straighten.ts +58 -0
  375. package/src/parser/applyViewboxTransform.ts +157 -0
  376. package/src/parser/attributes.ts +25 -0
  377. package/src/parser/constants.ts +115 -0
  378. package/src/parser/doesSomeParentMatch.ts +19 -0
  379. package/src/parser/elementById.ts +21 -0
  380. package/src/parser/elementMatchesRule.ts +16 -0
  381. package/src/parser/elements_parser.ts +191 -0
  382. package/src/parser/getCSSRules.ts +62 -0
  383. package/src/parser/getGlobalStylesForElement.ts +19 -0
  384. package/src/parser/getGradientDefs.ts +31 -0
  385. package/src/parser/getMultipleNodes.ts +15 -0
  386. package/src/parser/getSvgRegex.ts +5 -0
  387. package/src/parser/hasAncestorWithNodeName.ts +14 -0
  388. package/src/parser/index.ts +9 -0
  389. package/src/parser/loadSVGFromString.ts +26 -0
  390. package/src/parser/loadSVGFromURL.ts +40 -0
  391. package/src/parser/normalizeAttr.ts +10 -0
  392. package/src/parser/normalizeValue.ts +63 -0
  393. package/src/parser/parseAttributes.ts +90 -0
  394. package/src/parser/parseElements.ts +28 -0
  395. package/src/parser/parseFontDeclaration.ts +44 -0
  396. package/src/parser/parsePointsAttribute.ts +34 -0
  397. package/src/parser/parseSVGDocument.ts +93 -0
  398. package/src/parser/parseStyleAttribute.ts +27 -0
  399. package/src/parser/parseStyleObject.ts +15 -0
  400. package/src/parser/parseStyleString.ts +16 -0
  401. package/src/parser/parseTransformAttribute.ts +155 -0
  402. package/src/parser/parseUseDirectives.ts +78 -0
  403. package/src/parser/percent.ts +27 -0
  404. package/src/parser/recursivelyParseGradientsXlink.ts +42 -0
  405. package/src/parser/rotateMatrix.ts +21 -0
  406. package/src/parser/scaleMatrix.ts +9 -0
  407. package/src/parser/selectorMatches.ts +25 -0
  408. package/src/parser/setStrokeFillOpacity.ts +40 -0
  409. package/src/parser/skewMatrix.ts +6 -0
  410. package/src/parser/translateMatrix.ts +8 -0
  411. package/src/shapes/ActiveSelection.ts +189 -0
  412. package/src/shapes/Circle.ts +242 -0
  413. package/src/shapes/Ellipse.ts +179 -0
  414. package/src/shapes/Group.ts +1100 -0
  415. package/src/shapes/IText/DraggableTextDelegate.ts +382 -0
  416. package/src/shapes/IText/IText.ts +693 -0
  417. package/src/shapes/IText/ITextBehavior.ts +1064 -0
  418. package/src/shapes/IText/ITextClickBehavior.ts +325 -0
  419. package/src/shapes/IText/ITextKeyBehavior.ts +685 -0
  420. package/src/shapes/IText/constants.ts +47 -0
  421. package/src/shapes/Image.ts +841 -0
  422. package/src/shapes/Line.ts +346 -0
  423. package/src/shapes/Object/AnimatableObject.ts +106 -0
  424. package/src/shapes/Object/FabricObject.ts +29 -0
  425. package/src/shapes/Object/FabricObjectSVGExportMixin.ts +277 -0
  426. package/src/shapes/Object/InteractiveObject.ts +672 -0
  427. package/src/shapes/Object/Object.ts +1561 -0
  428. package/src/shapes/Object/ObjectGeometry.ts +813 -0
  429. package/src/shapes/Object/ObjectOrigin.ts +276 -0
  430. package/src/shapes/Object/StackedObject.ts +206 -0
  431. package/src/shapes/Object/defaultValues.ts +108 -0
  432. package/src/shapes/Object/types/BaseProps.ts +96 -0
  433. package/src/shapes/Object/types/BorderProps.ts +40 -0
  434. package/src/shapes/Object/types/ControlProps.ts +69 -0
  435. package/src/shapes/Object/types/FabricObjectProps.ts +111 -0
  436. package/src/shapes/Object/types/FillStrokeProps.ts +90 -0
  437. package/src/shapes/Object/types/LockInteractionProps.ts +57 -0
  438. package/src/shapes/Object/types/ObjectProps.ts +46 -0
  439. package/src/shapes/Object/types/SerializedObjectProps.ts +73 -0
  440. package/src/shapes/Object/types/index.ts +8 -0
  441. package/src/shapes/Path.ts +416 -0
  442. package/src/shapes/Polygon.ts +20 -0
  443. package/src/shapes/Polyline.ts +359 -0
  444. package/src/shapes/Rect.ts +233 -0
  445. package/src/shapes/Text/StyledText.ts +329 -0
  446. package/src/shapes/Text/Text.ts +1884 -0
  447. package/src/shapes/Text/TextSVGExportMixin.ts +288 -0
  448. package/src/shapes/Text/constants.ts +91 -0
  449. package/src/shapes/Textbox.ts +477 -0
  450. package/src/shapes/Triangle.ts +60 -0
  451. package/src/typedefs.ts +115 -0
  452. package/src/util/animation/AnimationBase.ts +166 -0
  453. package/src/util/animation/AnimationFrameProvider.ts +9 -0
  454. package/src/util/animation/AnimationRegistry.ts +58 -0
  455. package/src/util/animation/ArrayAnimation.ts +27 -0
  456. package/src/util/animation/ColorAnimation.ts +74 -0
  457. package/src/util/animation/ValueAnimation.ts +29 -0
  458. package/src/util/animation/animate.ts +74 -0
  459. package/src/util/animation/easing.ts +327 -0
  460. package/src/util/animation/types.ts +136 -0
  461. package/src/util/applyMixins.ts +22 -0
  462. package/src/util/dom_event.ts +28 -0
  463. package/src/util/dom_misc.ts +121 -0
  464. package/src/util/dom_request.ts +64 -0
  465. package/src/util/dom_style.ts +20 -0
  466. package/src/util/fireEvent.ts +15 -0
  467. package/src/util/index.ts +102 -0
  468. package/src/util/internals/cloneDeep.ts +2 -0
  469. package/src/util/internals/getRandomInt.ts +8 -0
  470. package/src/util/internals/ifNaN.ts +9 -0
  471. package/src/util/internals/index.ts +3 -0
  472. package/src/util/internals/removeFromArray.ts +14 -0
  473. package/src/util/internals/uid.ts +3 -0
  474. package/src/util/lang_string.ts +79 -0
  475. package/src/util/misc/boundingBoxFromPoints.ts +37 -0
  476. package/src/util/misc/capValue.ts +2 -0
  477. package/src/util/misc/cos.ts +24 -0
  478. package/src/util/misc/dom.ts +50 -0
  479. package/src/util/misc/findScaleTo.ts +44 -0
  480. package/src/util/misc/groupSVGElements.ts +15 -0
  481. package/src/util/misc/isTransparent.ts +28 -0
  482. package/src/util/misc/matrix.ts +207 -0
  483. package/src/util/misc/mergeClipPaths.ts +40 -0
  484. package/src/util/misc/objectEnlive.ts +189 -0
  485. package/src/util/misc/objectTransforms.ts +129 -0
  486. package/src/util/misc/pick.ts +29 -0
  487. package/src/util/misc/planeChange.ts +136 -0
  488. package/src/util/misc/projectStroke/StrokeLineCapProjections.ts +112 -0
  489. package/src/util/misc/projectStroke/StrokeLineJoinProjections.ts +226 -0
  490. package/src/util/misc/projectStroke/StrokeProjectionsBase.ts +75 -0
  491. package/src/util/misc/projectStroke/index.ts +53 -0
  492. package/src/util/misc/projectStroke/types.ts +24 -0
  493. package/src/util/misc/radiansDegreesConversion.ts +18 -0
  494. package/src/util/misc/resolveOrigin.ts +22 -0
  495. package/src/util/misc/rotatePoint.ts +15 -0
  496. package/src/util/misc/sin.ts +26 -0
  497. package/src/util/misc/svgParsing.ts +181 -0
  498. package/src/util/misc/textStyles.ts +134 -0
  499. package/src/util/misc/toFixed.ts +8 -0
  500. package/src/util/misc/vectors.ts +82 -0
  501. package/src/util/path/index.ts +1038 -0
  502. package/src/util/path/regex.ts +41 -0
  503. package/src/util/path/typechecks.ts +145 -0
  504. package/src/util/path/typedefs.ts +305 -0
  505. package/src/util/transform_matrix_removal.ts +60 -0
  506. package/src/util/types.ts +78 -0
  507. package/tsconfig.json +106 -0
  508. package/HEADER.js +0 -203
  509. package/build.js +0 -287
  510. package/dist/fabric.js +0 -31187
  511. package/dist/fabric.min.js +0 -1
  512. package/old-travis-reference.yml +0 -97
  513. package/src/brushes/circle_brush.class.js +0 -144
  514. package/src/brushes/pattern_brush.class.js +0 -61
  515. package/src/brushes/pencil_brush.class.js +0 -310
  516. package/src/brushes/spray_brush.class.js +0 -219
  517. package/src/canvas.class.js +0 -1312
  518. package/src/color.class.js +0 -636
  519. package/src/control.class.js +0 -339
  520. package/src/controls.actions.js +0 -740
  521. package/src/controls.render.js +0 -99
  522. package/src/elements_parser.js +0 -152
  523. package/src/filters/2d_backend.class.js +0 -65
  524. package/src/filters/blendcolor_filter.class.js +0 -251
  525. package/src/filters/blendimage_filter.class.js +0 -247
  526. package/src/filters/blur_filter.class.js +0 -217
  527. package/src/filters/brightness_filter.class.js +0 -113
  528. package/src/filters/colormatrix_filter.class.js +0 -159
  529. package/src/filters/composed_filter.class.js +0 -72
  530. package/src/filters/contrast_filter.class.js +0 -113
  531. package/src/filters/convolute_filter.class.js +0 -352
  532. package/src/filters/filter_boilerplate.js +0 -111
  533. package/src/filters/filter_generator.js +0 -85
  534. package/src/filters/gamma_filter.class.js +0 -136
  535. package/src/filters/grayscale_filter.class.js +0 -154
  536. package/src/filters/hue_rotation.class.js +0 -107
  537. package/src/filters/invert_filter.class.js +0 -111
  538. package/src/filters/noise_filter.class.js +0 -134
  539. package/src/filters/pixelate_filter.class.js +0 -137
  540. package/src/filters/removecolor_filter.class.js +0 -173
  541. package/src/filters/resize_filter.class.js +0 -490
  542. package/src/filters/saturate_filter.class.js +0 -119
  543. package/src/filters/vibrance_filter.class.js +0 -122
  544. package/src/filters/webgl_backend.class.js +0 -396
  545. package/src/globalFabric.js +0 -4
  546. package/src/gradient.class.js +0 -490
  547. package/src/intersection.class.js +0 -172
  548. package/src/log.js +0 -11
  549. package/src/mixins/animation.mixin.js +0 -231
  550. package/src/mixins/canvas_dataurl_exporter.mixin.js +0 -97
  551. package/src/mixins/canvas_events.mixin.js +0 -974
  552. package/src/mixins/canvas_gestures.mixin.js +0 -149
  553. package/src/mixins/canvas_grouping.mixin.js +0 -177
  554. package/src/mixins/canvas_serialization.mixin.js +0 -228
  555. package/src/mixins/collection.mixin.js +0 -170
  556. package/src/mixins/default_controls.js +0 -114
  557. package/src/mixins/itext.svg_export.js +0 -241
  558. package/src/mixins/itext_behavior.mixin.js +0 -940
  559. package/src/mixins/itext_click_behavior.mixin.js +0 -278
  560. package/src/mixins/itext_key_behavior.mixin.js +0 -694
  561. package/src/mixins/object.svg_export.js +0 -258
  562. package/src/mixins/object_geometry.mixin.js +0 -683
  563. package/src/mixins/object_interactivity.mixin.js +0 -314
  564. package/src/mixins/object_origin.mixin.js +0 -255
  565. package/src/mixins/object_stacking.mixin.js +0 -80
  566. package/src/mixins/object_straightening.mixin.js +0 -80
  567. package/src/mixins/observable.mixin.js +0 -141
  568. package/src/mixins/shared_methods.mixin.js +0 -94
  569. package/src/mixins/stateful.mixin.js +0 -107
  570. package/src/mixins/text_style.mixin.js +0 -324
  571. package/src/parser.js +0 -1090
  572. package/src/pattern.class.js +0 -189
  573. package/src/point.class.js +0 -337
  574. package/src/shadow.class.js +0 -195
  575. package/src/shapes/active_selection.class.js +0 -155
  576. package/src/shapes/circle.class.js +0 -210
  577. package/src/shapes/ellipse.class.js +0 -181
  578. package/src/shapes/group.class.js +0 -593
  579. package/src/shapes/image.class.js +0 -764
  580. package/src/shapes/itext.class.js +0 -526
  581. package/src/shapes/line.class.js +0 -324
  582. package/src/shapes/object.class.js +0 -2008
  583. package/src/shapes/path.class.js +0 -384
  584. package/src/shapes/polygon.class.js +0 -81
  585. package/src/shapes/polyline.class.js +0 -268
  586. package/src/shapes/rect.class.js +0 -187
  587. package/src/shapes/text.class.js +0 -1696
  588. package/src/shapes/textbox.class.js +0 -461
  589. package/src/shapes/triangle.class.js +0 -93
  590. package/src/static_canvas.class.js +0 -1881
  591. package/src/util/anim_ease.js +0 -398
  592. package/src/util/animate.js +0 -254
  593. package/src/util/animate_color.js +0 -74
  594. package/src/util/dom_event.js +0 -50
  595. package/src/util/dom_misc.js +0 -300
  596. package/src/util/dom_request.js +0 -54
  597. package/src/util/dom_style.js +0 -70
  598. package/src/util/lang_array.js +0 -94
  599. package/src/util/lang_class.js +0 -115
  600. package/src/util/lang_object.js +0 -75
  601. package/src/util/lang_string.js +0 -110
  602. package/src/util/misc.js +0 -1330
  603. package/src/util/named_accessors.mixin.js +0 -428
  604. package/src/util/path.js +0 -829
@@ -0,0 +1 @@
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).fabric={})}(this,(function(t){"use strict";function e(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);e&&(s=s.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,s)}return i}function i(t){for(var i=1;i<arguments.length;i++){var r=null!=arguments[i]?arguments[i]:{};i%2?e(Object(r),!0).forEach((function(e){s(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):e(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function s(t,e,i){return(e=a(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function r(){return r=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(t[s]=i[s])}return t},r.apply(this,arguments)}function n(t,e){if(null==t)return{};var i,s,r=function(t,e){if(null==t)return{};var i,s,r={},n=Object.keys(t);for(s=0;s<n.length;s++)i=n[s],e.indexOf(i)>=0||(r[i]=t[i]);return r}(t,e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);for(s=0;s<n.length;s++)i=n[s],e.indexOf(i)>=0||Object.prototype.propertyIsEnumerable.call(t,i)&&(r[i]=t[i])}return r}function o(t,e){return e||(e=t.slice(0)),Object.freeze(Object.defineProperties(t,{raw:{value:Object.freeze(e)}}))}function a(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var s=i.call(t,e||"default");if("object"!=typeof s)return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}class h{constructor(){s(this,"browserShadowBlurConstant",1),s(this,"DPI",96),s(this,"devicePixelRatio",1),s(this,"perfLimitSizeTotal",2097152),s(this,"maxCacheSideLimit",4096),s(this,"minCacheSideLimit",256),s(this,"disableStyleCopyPaste",!1),s(this,"enableGLFiltering",!0),s(this,"textureSize",4096),s(this,"forceGLPutImageData",!1),s(this,"cachesBoundsOfCurve",!0),s(this,"fontPaths",{}),s(this,"NUM_FRACTION_DIGITS",4)}}const c=new class extends h{constructor(t){super(),this.configure(t)}configure(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};Object.assign(this,t)}addFonts(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.fontPaths=i(i({},this.fontPaths),t)}removeFonts(){(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).forEach((t=>{delete this.fontPaths[t]}))}clearFonts(){this.fontPaths={}}restoreDefaults(t){const e=new h,i=(null==t?void 0:t.reduce(((t,i)=>(t[i]=e[i],t)),{}))||e;this.configure(i)}};let l;!function(t){t.low="lowp",t.medium="mediump",t.high="highp"}(l||(l={}));class d{}class u extends d{testPrecision(t,e){const i="precision ".concat(e," float;\nvoid main(){}"),s=t.createShader(t.FRAGMENT_SHADER);return!!s&&(t.shaderSource(s,i),t.compileShader(s),!!t.getShaderParameter(s,t.COMPILE_STATUS))}queryWebGL(t){const e=t.getContext("webgl");e&&(this.maxTextureSize=e.getParameter(e.MAX_TEXTURE_SIZE),this.GLPrecision=Object.values(l).find((t=>this.testPrecision(e,t))),console.log("fabric: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const g={};let f,p=!1;const m=()=>(p||(c.configure({devicePixelRatio:window.devicePixelRatio||1}),f="ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,p=!0),{document:document,window:window,isTouchSupported:f,WebGLProbe:new u,dispose(){},copyPasteData:g}),v=()=>m().document,_=()=>m().window;const x=new class{constructor(){s(this,"charWidthsCache",{}),s(this,"boundsOfCurveCache",{})}getFontCache(t){let{fontFamily:e,fontStyle:i,fontWeight:s}=t;e=e.toLowerCase(),this.charWidthsCache[e]||(this.charWidthsCache[e]={});const r=this.charWidthsCache[e],n="".concat(i.toLowerCase(),"_").concat((s+"").toLowerCase());return r[n]||(r[n]={}),r[n]}clearFontCache(t){(t=(t||"").toLowerCase())?this.charWidthsCache[t]&&delete this.charWidthsCache[t]:this.charWidthsCache={}}limitDimsByArea(t){const{perfLimitSizeTotal:e}=c,i=Math.sqrt(e*t);return[Math.floor(i),Math.floor(e/i)]}};const y="6.0.0-beta3";function C(){}const b=Math.PI/2,S=2*Math.PI,w=Math.PI/180,T=Object.freeze([1,0,0,1,0,0]),O=16,k=.4477152502,D="json",E="svg";const M=new class{constructor(){this[D]=new Map,this[E]=new Map}getClass(t){const e=this[D].get(t);if(!e)throw new Error("No class registered for ".concat(t));return e}setClass(t,e){e?this[D].set(e,t):(this[D].set(t.name,t),this[D].set(t.name.toLowerCase(),t))}getSVGClass(t){return this[E].get(t)}setSVGClass(t,e){this[E].set(null!=e?e:t.name.toLowerCase(),t)}};const P=new class extends Array{remove(t){const e=this.indexOf(t);e>-1&&this.splice(e,1)}cancelAll(){const t=this.splice(0);return t.forEach((t=>t.abort())),t}cancelByCanvas(t){if(!t)return[];const e=this.filter((e=>{var i;return"object"==typeof e.target&&(null===(i=e.target)||void 0===i?void 0:i.canvas)===t}));return e.forEach((t=>t.abort())),e}cancelByTarget(t){if(!t)return[];const e=this.filter((e=>e.target===t));return e.forEach((t=>t.abort())),e}};class A{constructor(){s(this,"__eventListeners",{})}on(t,e){if(this.__eventListeners||(this.__eventListeners={}),"object"==typeof t){for(const e in t)this.on(e,t[e]);return()=>this.off(t)}if(e){const i=t;return this.__eventListeners[i]||(this.__eventListeners[i]=[]),this.__eventListeners[i].push(e),()=>this.off(i,e)}return()=>!1}once(t,e){if("object"==typeof t){const e=[];for(const i in t)e.push(this.once(i,t[i]));return()=>e.forEach((t=>t()))}if(e){const i=this.on(t,(function(){e(...arguments),i()}));return i}return()=>!1}_removeEventListener(t,e){if(this.__eventListeners[t])if(e){const i=this.__eventListeners[t],s=i.indexOf(e);s>-1&&i.splice(s,1)}else this.__eventListeners[t]=[]}off(t,e){if(this.__eventListeners)if(void 0===t)for(const t in this.__eventListeners)this._removeEventListener(t);else if("object"==typeof t)for(const e in t)this._removeEventListener(e,t[e]);else this._removeEventListener(t,e)}fire(t,e){var i;if(!this.__eventListeners)return;const s=null===(i=this.__eventListeners[t])||void 0===i?void 0:i.concat();if(s)for(let t=0;t<s.length;t++)s[t].call(this,e||{})}}const F=(t,e)=>Math.floor(Math.random()*(e-t+1))+t,L=(t,e)=>isNaN(t)&&"number"==typeof e?e:t,R=(t,e)=>{const i=t.indexOf(e);return-1!==i&&t.splice(i,1),t},B=t=>{if(0===t)return 1;switch(Math.abs(t)/b){case 1:case 3:return 0;case 2:return-1}return Math.cos(t)},I=t=>{if(0===t)return 0;const e=t/b,i=Math.sign(t);switch(e){case 1:return i;case 2:return 0;case 3:return-i}return Math.sin(t)};class X{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;"object"==typeof t?(this.x=t.x,this.y=t.y):(this.x=t,this.y=e)}add(t){return new X(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new X(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new X(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new X(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new X(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new X(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new X(this.x/t.x,this.y/t.y)}scalarDivide(t){return new X(this.x/t,this.y/t)}scalarDivideEquals(t){return this.x/=t,this.y/=t,this}eq(t){return this.x===t.x&&this.y===t.y}lt(t){return this.x<t.x&&this.y<t.y}lte(t){return this.x<=t.x&&this.y<=t.y}gt(t){return this.x>t.x&&this.y>t.y}gte(t){return this.x>=t.x&&this.y>=t.y}lerp(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.5;return e=Math.max(Math.min(1,e),0),new X(this.x+(t.x-this.x)*e,this.y+(t.y-this.y)*e)}distanceFrom(t){const e=this.x-t.x,i=this.y-t.y;return Math.sqrt(e*e+i*i)}midPointFrom(t){return this.lerp(t)}min(t){return new X(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new X(Math.max(this.x,t.x),Math.max(this.y,t.y))}toString(){return"".concat(this.x,",").concat(this.y)}setXY(t,e){return this.x=t,this.y=e,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setFromPoint(t){return this.x=t.x,this.y=t.y,this}swap(t){const e=this.x,i=this.y;this.x=t.x,this.y=t.y,t.x=e,t.y=i}clone(){return new X(this.x,this.y)}rotate(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Y;const i=I(t),s=B(t),r=this.subtract(e);return new X(r.x*s-r.y*i,r.x*i+r.y*s).add(e)}transform(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return new X(t[0]*this.x+t[2]*this.y+(e?0:t[4]),t[1]*this.x+t[3]*this.y+(e?0:t[5]))}}const Y=new X(0,0);function W(t){class e extends t{constructor(){super(...arguments),s(this,"_objects",[])}_onObjectAdded(t){}_onObjectRemoved(t){}_onStackOrderChanged(t){}add(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];const s=this._objects.push(...e);return e.forEach((t=>this._onObjectAdded(t))),s}insertAt(t){for(var e=arguments.length,i=new Array(e>1?e-1:0),s=1;s<e;s++)i[s-1]=arguments[s];return this._objects.splice(t,0,...i),i.forEach((t=>this._onObjectAdded(t))),this._objects.length}remove(){const t=this._objects,e=[];for(var i=arguments.length,s=new Array(i),r=0;r<i;r++)s[r]=arguments[r];return s.forEach((i=>{const s=t.indexOf(i);-1!==s&&(t.splice(s,1),e.push(i),this._onObjectRemoved(i))})),e}forEachObject(t){this.getObjects().forEach(((e,i,s)=>t(e,i,s)))}getObjects(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];return 0===e.length?[...this._objects]:this._objects.filter((t=>t.isType(...e)))}item(t){return this._objects[t]}isEmpty(){return 0===this._objects.length}size(){return this._objects.length}contains(t,i){return!!this._objects.includes(t)||!!i&&this._objects.some((i=>i instanceof e&&i.contains(t,!0)))}complexity(){return this._objects.reduce(((t,e)=>t+=e.complexity?e.complexity():0),0)}sendObjectToBack(t){return!(!t||t===this._objects[0])&&(R(this._objects,t),this._objects.unshift(t),this._onStackOrderChanged(t),!0)}bringObjectToFront(t){return!(!t||t===this._objects[this._objects.length-1])&&(R(this._objects,t),this._objects.push(t),this._onStackOrderChanged(t),!0)}sendObjectBackwards(t,e){if(!t)return!1;const i=this._objects.indexOf(t);if(0!==i){const s=this.findNewLowerIndex(t,i,e);return R(this._objects,t),this._objects.splice(s,0,t),this._onStackOrderChanged(t),!0}return!1}bringObjectForward(t,e){if(!t)return!1;const i=this._objects.indexOf(t);if(i!==this._objects.length-1){const s=this.findNewUpperIndex(t,i,e);return R(this._objects,t),this._objects.splice(s,0,t),this._onStackOrderChanged(t),!0}return!1}moveObjectTo(t,e){return t!==this._objects[e]&&(R(this._objects,t),this._objects.splice(e,0,t),this._onStackOrderChanged(t),!0)}findNewLowerIndex(t,e,i){let s;if(i){s=e;for(let i=e-1;i>=0;--i)if(t.isOverlapping(this._objects[i])){s=i;break}}else s=e-1;return s}findNewUpperIndex(t,e,i){let s;if(i){s=e;for(let i=e+1;i<this._objects.length;++i)if(t.isOverlapping(this._objects[i])){s=i;break}}else s=e+1;return s}collectObjects(t){let{left:e,top:i,width:s,height:r}=t,{includeIntersecting:n=!0}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const o=[],a=new X(e,i),h=a.add(new X(s,r));for(let t=this._objects.length-1;t>=0;t--){const e=this._objects[t];e.selectable&&e.visible&&(n&&e.intersectsWithRect(a,h,!0)||e.isContainedWithinRect(a,h,!0)||n&&e.containsPoint(a,void 0,!0)||n&&e.containsPoint(h,void 0,!0))&&o.push(e)}return o}}return e}class V extends A{_setOptions(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};for(const e in t)this.set(e,t[e])}_setObject(t){for(const e in t)this._set(e,t[e])}set(t,e){return"object"==typeof t?this._setObject(t):this._set(t,e),this}_set(t,e){this[t]=e}toggle(t){const e=this.get(t);return"boolean"==typeof e&&this.set(t,!e),this}get(t){return this[t]}}let G,z,H;function U(t){return _().requestAnimationFrame(t)}function N(t){return _().cancelAnimationFrame(t)}function q(t,e){return t.parentNode&&t.parentNode.replaceChild(e,t),e.appendChild(t),e}function K(t){let e=0,i=0;const s=v().documentElement,r=v().body||{scrollLeft:0,scrollTop:0};for(;t&&(t.parentNode||t.host)&&((t=t.parentNode||t.host)===v()?(e=r.scrollLeft||s.scrollLeft||0,i=r.scrollTop||s.scrollTop||0):(e+=t.scrollLeft||0,i+=t.scrollTop||0),1!==t.nodeType||"fixed"!==t.style.position););return{left:e,top:i}}function J(t){let e={left:0,top:0};const i=t&&t.ownerDocument,s={left:0,top:0},r={borderLeftWidth:"left",borderTopWidth:"top",paddingLeft:"left",paddingTop:"top"};if(!i)return s;const n=v().defaultView.getComputedStyle(t,null);for(const t in r)s[r[t]]+=parseInt(n[t],10)||0;const o=i.documentElement;void 0!==t.getBoundingClientRect&&(e=t.getBoundingClientRect());const a=K(t);return{left:e.left+a.left-(o.clientLeft||0)+s.left,top:e.top+a.top-(o.clientTop||0)+s.top}}function $(t){return void 0!==t.onselectstart&&(t.onselectstart=()=>!1),t.style.userSelect="none",t}!function(t){t.jpeg="jpeg",t.jpg="jpeg",t.png="png"}(G||(G={})),function(t){t.linearGradient="linearGradient",t.radialGradient="radialGradient",t.stop="stop"}(z||(z={})),function(t){t.mm="mm",t.cm="cm",t.in="in",t.pt="pt",t.pc="pc",t.em="em"}(H||(H={}));let Z=0;const Q=()=>Z++,tt=()=>v().createElement("canvas"),et=()=>v().createElement("img"),it=(t,e,i)=>t.toDataURL("image/".concat(e),i),st=t=>t*w,rt=t=>t/w,nt=["translateX","translateY","angle"],ot=(t,e,i)=>new X(t).transform(e,i),at=t=>{const e=1/(t[0]*t[3]-t[1]*t[2]),i=[e*t[3],-e*t[1],-e*t[2],e*t[0],0,0],{x:s,y:r}=ot(new X(t[4],t[5]),i,!0);return i[4]=-s,i[5]=-r,i},ht=(t,e,i)=>[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],i?0:t[0]*e[4]+t[2]*e[5]+t[4],i?0:t[1]*e[4]+t[3]*e[5]+t[5]],ct=t=>{const e=Math.atan2(t[1],t[0]),i=Math.pow(t[0],2)+Math.pow(t[1],2),s=Math.sqrt(i),r=(t[0]*t[3]-t[2]*t[1])/s,n=Math.atan2(t[0]*t[2]+t[1]*t[3],i);return{angle:rt(e),scaleX:s,scaleY:r,skewX:rt(n),skewY:0,translateX:t[4]||0,translateY:t[5]||0}},lt=t=>{let{angle:e}=t;if(!e)return T;const i=st(e),s=B(i),r=I(i);return[s,r,-r,s,0,0]},dt=t=>{let{scaleX:e=1,scaleY:i=1,flipX:s=!1,flipY:r=!1,skewX:n=0,skewY:o=0}=t,a=T;return(1!==e||1!==i||s||r)&&(a=[s?-e:e,0,0,r?-i:i,0,0]),n&&(a=ht(a,[1,0,Math.tan(st(n)),1],!0)),o&&(a=ht(a,[1,Math.tan(st(o)),0,1],!0)),a},ut=t=>{let{translateX:e=0,translateY:i=0,angle:s=0}=t,r=n(t,nt),o=[1,0,0,1,e,i];s&&(o=ht(o,lt({angle:s})));const a=dt(r);return a!==T&&(o=ht(o,a)),o},gt=function(t){let{signal:e,crossOrigin:i=null}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise((function(s,r){if(e&&e.aborted)return r(new Error("`options.signal` is in `aborted` state"));const n=et();let o;e&&(o=function(t){n.src="",r(t)},e.addEventListener("abort",o,{once:!0}));const a=function(){n.onload=n.onerror=null,o&&(null==e||e.removeEventListener("abort",o)),s(n)};t?(n.onload=a,n.onerror=function(){o&&(null==e||e.removeEventListener("abort",o)),r(new Error("Error loading "+n.src))},i&&(n.crossOrigin=i),n.src=t):a()}))},ft=function(t){let{signal:e,reviver:i=C}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise(((s,r)=>{const n=[];e&&e.addEventListener("abort",r,{once:!0}),Promise.all(t.map((t=>M.getClass(t.type).fromObject(t,{signal:e,reviver:i}).then((e=>(i(t,e),n.push(e),e)))))).then(s).catch((t=>{n.forEach((function(t){t.dispose&&t.dispose()})),r(t)})).finally((()=>{e&&e.removeEventListener("abort",r)}))}))},pt=function(t){let{signal:e}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise(((i,s)=>{const r=[];e&&e.addEventListener("abort",s,{once:!0});const n=Object.values(t).map((t=>t?t.colorStops?new(M.getClass("gradient"))(t):t.type?ft([t],{signal:e}).then((t=>{let[e]=t;return r.push(e),e})):t.source?M.getClass("pattern").fromObject(t,{signal:e}).then((t=>(r.push(t),t))):t:t)),o=Object.keys(t);Promise.all(n).then((t=>t.reduce(((t,e,i)=>(t[o[i]]=e,t)),{}))).then(i).catch((t=>{r.forEach((t=>{t.dispose&&t.dispose()})),s(t)})).finally((()=>{e&&e.removeEventListener("abort",s)}))}))},mt=function(t){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:[]).reduce(((e,i)=>(i in t&&(e[i]=t[i]),e)),{})},vt=(t,e)=>Object.keys(t).reduce(((i,s)=>(e(t[s],s,t)&&(i[s]=t[s]),i)),{}),_t={aliceblue:"#F0F8FF",antiquewhite:"#FAEBD7",aqua:"#00FFFF",aquamarine:"#7FFFD4",azure:"#F0FFFF",beige:"#F5F5DC",bisque:"#FFE4C4",black:"#000000",blanchedalmond:"#FFEBCD",blue:"#0000FF",blueviolet:"#8A2BE2",brown:"#A52A2A",burlywood:"#DEB887",cadetblue:"#5F9EA0",chartreuse:"#7FFF00",chocolate:"#D2691E",coral:"#FF7F50",cornflowerblue:"#6495ED",cornsilk:"#FFF8DC",crimson:"#DC143C",cyan:"#00FFFF",darkblue:"#00008B",darkcyan:"#008B8B",darkgoldenrod:"#B8860B",darkgray:"#A9A9A9",darkgrey:"#A9A9A9",darkgreen:"#006400",darkkhaki:"#BDB76B",darkmagenta:"#8B008B",darkolivegreen:"#556B2F",darkorange:"#FF8C00",darkorchid:"#9932CC",darkred:"#8B0000",darksalmon:"#E9967A",darkseagreen:"#8FBC8F",darkslateblue:"#483D8B",darkslategray:"#2F4F4F",darkslategrey:"#2F4F4F",darkturquoise:"#00CED1",darkviolet:"#9400D3",deeppink:"#FF1493",deepskyblue:"#00BFFF",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1E90FF",firebrick:"#B22222",floralwhite:"#FFFAF0",forestgreen:"#228B22",fuchsia:"#FF00FF",gainsboro:"#DCDCDC",ghostwhite:"#F8F8FF",gold:"#FFD700",goldenrod:"#DAA520",gray:"#808080",grey:"#808080",green:"#008000",greenyellow:"#ADFF2F",honeydew:"#F0FFF0",hotpink:"#FF69B4",indianred:"#CD5C5C",indigo:"#4B0082",ivory:"#FFFFF0",khaki:"#F0E68C",lavender:"#E6E6FA",lavenderblush:"#FFF0F5",lawngreen:"#7CFC00",lemonchiffon:"#FFFACD",lightblue:"#ADD8E6",lightcoral:"#F08080",lightcyan:"#E0FFFF",lightgoldenrodyellow:"#FAFAD2",lightgray:"#D3D3D3",lightgrey:"#D3D3D3",lightgreen:"#90EE90",lightpink:"#FFB6C1",lightsalmon:"#FFA07A",lightseagreen:"#20B2AA",lightskyblue:"#87CEFA",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#B0C4DE",lightyellow:"#FFFFE0",lime:"#00FF00",limegreen:"#32CD32",linen:"#FAF0E6",magenta:"#FF00FF",maroon:"#800000",mediumaquamarine:"#66CDAA",mediumblue:"#0000CD",mediumorchid:"#BA55D3",mediumpurple:"#9370DB",mediumseagreen:"#3CB371",mediumslateblue:"#7B68EE",mediumspringgreen:"#00FA9A",mediumturquoise:"#48D1CC",mediumvioletred:"#C71585",midnightblue:"#191970",mintcream:"#F5FFFA",mistyrose:"#FFE4E1",moccasin:"#FFE4B5",navajowhite:"#FFDEAD",navy:"#000080",oldlace:"#FDF5E6",olive:"#808000",olivedrab:"#6B8E23",orange:"#FFA500",orangered:"#FF4500",orchid:"#DA70D6",palegoldenrod:"#EEE8AA",palegreen:"#98FB98",paleturquoise:"#AFEEEE",palevioletred:"#DB7093",papayawhip:"#FFEFD5",peachpuff:"#FFDAB9",peru:"#CD853F",pink:"#FFC0CB",plum:"#DDA0DD",powderblue:"#B0E0E6",purple:"#800080",rebeccapurple:"#663399",red:"#FF0000",rosybrown:"#BC8F8F",royalblue:"#4169E1",saddlebrown:"#8B4513",salmon:"#FA8072",sandybrown:"#F4A460",seagreen:"#2E8B57",seashell:"#FFF5EE",sienna:"#A0522D",silver:"#C0C0C0",skyblue:"#87CEEB",slateblue:"#6A5ACD",slategray:"#708090",slategrey:"#708090",snow:"#FFFAFA",springgreen:"#00FF7F",steelblue:"#4682B4",tan:"#D2B48C",teal:"#008080",thistle:"#D8BFD8",tomato:"#FF6347",turquoise:"#40E0D0",violet:"#EE82EE",wheat:"#F5DEB3",white:"#FFFFFF",whitesmoke:"#F5F5F5",yellow:"#FFFF00",yellowgreen:"#9ACD32"},xt=/^rgba?\(\s*(\d{1,3}(?:\.\d+)?%?)\s*,\s*(\d{1,3}(?:\.\d+)?%?)\s*,\s*(\d{1,3}(?:\.\d+)?%?)\s*(?:\s*,\s*((?:\d*\.?\d+)?)\s*)?\)$/i,yt=/^hsla?\(\s*(\d{1,3})\s*,\s*(\d{1,3}%)\s*,\s*(\d{1,3}%)\s*(?:\s*,\s*(\d+(?:\.\d+)?)\s*)?\)$/i,Ct=/^#?([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})$/i;function bt(t,e,i){return i<0&&(i+=1),i>1&&(i-=1),i<1/6?t+6*(e-t)*i:i<.5?e:i<2/3?t+(e-t)*(2/3-i)*6:t}function St(t){const e=t.toString(16).toUpperCase();return 1===e.length?"0".concat(e):e}class wt{constructor(t){if(t)if(t instanceof wt)this.setSource([...t._source]);else if(Array.isArray(t)){const[e,i,s,r=1]=t;this.setSource([e,i,s,r])}else this.setSource(this._tryParsingColor(t));else this.setSource([0,0,0,1])}_tryParsingColor(t){return t in _t&&(t=_t[t]),"transparent"===t?[255,255,255,0]:wt.sourceFromHex(t)||wt.sourceFromRgb(t)||wt.sourceFromHsl(t)||[0,0,0,1]}_rgbToHsl(t,e,i){t/=255,e/=255,i/=255;const s=Math.max(t,e,i),r=Math.min(t,e,i);let n,o;const a=(s+r)/2;if(s===r)n=o=0;else{const h=s-r;switch(o=a>.5?h/(2-s-r):h/(s+r),s){case t:n=(e-i)/h+(e<i?6:0);break;case e:n=(i-t)/h+2;break;case i:n=(t-e)/h+4}n/=6}return[Math.round(360*n),Math.round(100*o),Math.round(100*a)]}getSource(){return this._source}setSource(t){this._source=t}toRgb(){const t=this.getSource();return"rgb(".concat(t[0],",").concat(t[1],",").concat(t[2],")")}toRgba(){const t=this.getSource();return"rgba(".concat(t[0],",").concat(t[1],",").concat(t[2],",").concat(t[3],")")}toHsl(){const t=this.getSource(),e=this._rgbToHsl(t[0],t[1],t[2]);return"hsl(".concat(e[0],",").concat(e[1],"%,").concat(e[2],"%)")}toHsla(){const t=this.getSource(),e=this._rgbToHsl(t[0],t[1],t[2]);return"hsla(".concat(e[0],",").concat(e[1],"%,").concat(e[2],"%,").concat(t[3],")")}toHex(){const[t,e,i]=this.getSource();return"".concat(St(t)).concat(St(e)).concat(St(i))}toHexa(){const t=this.getSource();return"".concat(this.toHex()).concat(St(Math.round(255*t[3])))}getAlpha(){return this.getSource()[3]}setAlpha(t){const e=this.getSource();return e[3]=t,this.setSource(e),this}toGrayscale(){const t=this.getSource(),e=parseInt((.3*t[0]+.59*t[1]+.11*t[2]).toFixed(0),10),i=t[3];return this.setSource([e,e,e,i]),this}toBlackWhite(t){const e=this.getSource(),i=e[3];let s=Math.round(.3*e[0]+.59*e[1]+.11*e[2]);return s=s<(t||127)?0:255,this.setSource([s,s,s,i]),this}overlayWith(t){t instanceof wt||(t=new wt(t));const[e,i,s,r]=this.getSource(),n=t.getSource(),[o,a,h]=[e,i,s].map(((t,e)=>Math.round(.5*t+.5*n[e])));return this.setSource([o,a,h,r]),this}static fromRgb(t){return wt.fromRgba(t)}static fromRgba(t){return new wt(wt.sourceFromRgb(t))}static sourceFromRgb(t){const e=t.match(xt);if(e){return[parseInt(e[1],10)/(/%$/.test(e[1])?100:1)*(/%$/.test(e[1])?255:1),parseInt(e[2],10)/(/%$/.test(e[2])?100:1)*(/%$/.test(e[2])?255:1),parseInt(e[3],10)/(/%$/.test(e[3])?100:1)*(/%$/.test(e[3])?255:1),e[4]?parseFloat(e[4]):1]}}static fromHsl(t){return wt.fromHsla(t)}static fromHsla(t){return new wt(wt.sourceFromHsl(t))}static sourceFromHsl(t){const e=t.match(yt);if(!e)return;const i=(parseFloat(e[1])%360+360)%360/360,s=parseFloat(e[2])/(/%$/.test(e[2])?100:1),r=parseFloat(e[3])/(/%$/.test(e[3])?100:1);let n,o,a;if(0===s)n=o=a=r;else{const t=r<=.5?r*(s+1):r+s-r*s,e=2*r-t;n=bt(e,t,i+1/3),o=bt(e,t,i),a=bt(e,t,i-1/3)}return[Math.round(255*n),Math.round(255*o),Math.round(255*a),e[4]?parseFloat(e[4]):1]}static fromHex(t){return new wt(wt.sourceFromHex(t))}static sourceFromHex(t){if(t.match(Ct)){const e=t.slice(t.indexOf("#")+1),i=3===e.length||4===e.length,s=8===e.length||4===e.length,r=i?e.charAt(0)+e.charAt(0):e.substring(0,2),n=i?e.charAt(1)+e.charAt(1):e.substring(2,4),o=i?e.charAt(2)+e.charAt(2):e.substring(4,6),a=s?i?e.charAt(3)+e.charAt(3):e.substring(6,8):"FF";return[parseInt(r,16),parseInt(n,16),parseInt(o,16),parseFloat((parseInt(a,16)/255).toFixed(2))]}}}const Tt=(t,e)=>parseFloat(Number(t).toFixed(e)),Ot=(t,e)=>{const i=/\D{0,2}$/.exec(t),s=parseFloat(t);e||(e=O);const r=c.DPI;switch(null==i?void 0:i[0]){case H.mm:return s*r/25.4;case H.cm:return s*r/2.54;case H.in:return s*r;case H.pt:return s*r/72;case H.pc:return s*r/72*12;case H.em:return s*e;default:return s}};let kt,Dt;!function(t){t.meet="meet",t.slice="slice"}(kt||(kt={})),function(t){t.min="Min",t.mid="Mid",t.max="Max",t.none="none"}(Dt||(Dt={}));const Et=t=>{const[e,i]=t.trim().split(" "),[s,r]=(n=e)&&n!==Dt.none?[n.slice(1,4),n.slice(5,8)]:n===Dt.none?[n,n]:[Dt.mid,Dt.mid];var n;return{meetOrSlice:i||kt.meet,alignX:s,alignY:r}},Mt=t=>"matrix("+t.map((t=>Tt(t,c.NUM_FRACTION_DIGITS))).join(" ")+")",Pt=(t,e)=>{if(e){if(e.toLive)return"".concat(t,": url(#SVGID_").concat(e.id,"); ");{const i=new wt(e),s=i.getAlpha();let r="".concat(t,": ").concat(i.toRgb(),"; ");return 1!==s&&(r+="".concat(t,"-opacity: ").concat(s.toString(),"; ")),r}}return"".concat(t,": none; ")},At=function(t,e){let{left:i,top:s,width:r,height:n}=e,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:c.NUM_FRACTION_DIGITS;const a=Pt("fill",t),[h,l,d,u]=[i,s,r,n].map((t=>Tt(t,o)));return"<rect ".concat(a,' x="').concat(h,'" y="').concat(l,'" width="').concat(d,'" height="').concat(u,'"></rect>')},jt=t=>!!t&&void 0!==t.toLive,Ft=t=>!!t&&"function"==typeof t.toObject,Lt=t=>!!t&&void 0!==t.offsetX&&void 0!==t.source,Rt=t=>!!t&&Array.isArray(t._objects),Bt=t=>!!t&&t.isType("Text","IText","Textbox"),It=t=>!!t&&t.isType("IText","Textbox"),Xt=t=>!!t&&"function"==typeof t.onDragStart&&"function"==typeof t.shouldStartDragging,Yt="Could not initialize `canvas` element",Wt={backgroundColor:"",backgroundImage:null,overlayColor:"",overlayImage:null,includeDefaultValues:!0,renderOnAddRemove:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,imageSmoothingEnabled:!0,viewportTransform:T.concat(),backgroundVpt:!0,overlayVpt:!0,enableRetinaScaling:!0,svgViewportTransformation:!0,skipOffscreen:!0,clipPath:void 0};class Vt extends(W(V)){static getDefaults(){return Vt.ownDefaults}constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),Object.assign(this,this.constructor.getDefaults()),this.set(e),this.initElements(t),this._setDimensionsImpl({width:this.width||this.lowerCanvasEl.width||0,height:this.height||this.lowerCanvasEl.height||0}),this.viewportTransform=[...this.viewportTransform],this.calcViewportBoundaries()}initElements(t){this._createLowerCanvas(t),this._originalCanvasStyle=this.lowerCanvasEl.style.cssText}add(){const t=super.add(...arguments);return arguments.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}insertAt(t){for(var e=arguments.length,i=new Array(e>1?e-1:0),s=1;s<e;s++)i[s-1]=arguments[s];const r=super.insertAt(t,...i);return i.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),r}remove(){const t=super.remove(...arguments);return t.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}_onObjectAdded(t){t.canvas&&t.canvas!==this&&(console.warn("fabric.Canvas: trying to add an object that belongs to a different canvas.\nResulting to default behavior: removing object from previous canvas and adding to new canvas"),t.canvas.remove(t)),t._set("canvas",this),t.setCoords(),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onObjectRemoved(t){t._set("canvas",void 0),this.fire("object:removed",{target:t}),t.fire("removed",{target:this})}_onStackOrderChanged(){this.renderOnAddRemove&&this.requestRenderAll()}_isRetinaScaling(){return c.devicePixelRatio>1&&this.enableRetinaScaling}getRetinaScaling(){return this._isRetinaScaling()?Math.max(1,c.devicePixelRatio):1}_initRetinaScaling(){this.__initRetinaScaling(this.lowerCanvasEl,this.contextContainer)}__initRetinaScaling(t,e){const i=c.devicePixelRatio;t.setAttribute("width",(this.width*i).toString()),t.setAttribute("height",(this.height*i).toString()),e.scale(i,i)}calcOffset(){return this._offset=J(this.lowerCanvasEl)}_createCanvasElement(){const t=tt();if(!t)throw new Error(Yt);if(void 0===t.getContext)throw new Error(Yt);return t}_createLowerCanvas(t){var e;if((e=t)&&void 0!==e.getContext?this.lowerCanvasEl=t:this.lowerCanvasEl=v().getElementById(t)||this._createCanvasElement(),this.lowerCanvasEl.hasAttribute("data-fabric"))throw new Error("fabric.js: trying to initialize a canvas that has already been initialized");this.lowerCanvasEl.classList.add("lower-canvas"),this.lowerCanvasEl.setAttribute("data-fabric","main"),this.contextContainer=this.lowerCanvasEl.getContext("2d")}getWidth(){return this.width}getHeight(){return this.height}setWidth(t,e){return this.setDimensions({width:t},e)}setHeight(t,e){return this.setDimensions({height:t},e)}_setDimensionsImpl(t){let{cssOnly:e=!1,backstoreOnly:i=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};Object.entries(t).forEach((t=>{let[s,r]=t,n="".concat(r);e||(this._setBackstoreDimension(s,r),n+="px",this.hasLostContext=!0),i||this._setCssDimension(s,n)})),this._isRetinaScaling()&&this._initRetinaScaling(),this.calcOffset()}setDimensions(t){let{cssOnly:e=!1,backstoreOnly:i=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this._setDimensionsImpl(t,{cssOnly:e,backstoreOnly:i}),e||this.requestRenderAll()}_setBackstoreDimension(t,e){this.lowerCanvasEl[t]=e,this[t]=e}_setCssDimension(t,e){this.lowerCanvasEl.style[t]=e}getZoom(){return this.viewportTransform[0]}setViewportTransform(t){const e=this.backgroundImage,i=this.overlayImage,s=this._objects.length;this.viewportTransform=t;for(let t=0;t<s;t++){const e=this._objects[t];e.group||e.setCoords()}e&&e.setCoords(),i&&i.setCoords(),this.calcViewportBoundaries(),this.renderOnAddRemove&&this.requestRenderAll()}zoomToPoint(t,e){const i=t,s=[...this.viewportTransform],r=ot(t,at(s));s[0]=e,s[3]=e;const n=ot(r,s);s[4]+=i.x-n.x,s[5]+=i.y-n.y,this.setViewportTransform(s)}setZoom(t){this.zoomToPoint(new X(0,0),t)}absolutePan(t){const e=[...this.viewportTransform];return e[4]=-t.x,e[5]=-t.y,this.setViewportTransform(e)}relativePan(t){return this.absolutePan(new X(-t.x-this.viewportTransform[4],-t.y-this.viewportTransform[5]))}getElement(){return this.lowerCanvasEl}clearContext(t){t.clearRect(0,0,this.width,this.height)}getContext(){return this.contextContainer}clear(){this.remove(...this.getObjects()),this.backgroundImage=null,this.overlayImage=null,this.backgroundColor="",this.overlayColor="",this.clearContext(this.contextContainer),this.fire("canvas:cleared"),this.renderOnAddRemove&&this.requestRenderAll()}renderAll(){this.cancelRequestedRender(),this.destroyed||this.renderCanvas(this.contextContainer,this._objects)}renderAndReset(){this.nextRenderHandle=0,this.renderAll()}requestRenderAll(){this.nextRenderHandle||this.disposed||this.destroyed||(this.nextRenderHandle=U((()=>this.renderAndReset())))}calcViewportBoundaries(){const t=this.width,e=this.height,i=at(this.viewportTransform),s=ot({x:0,y:0},i),r=ot({x:t,y:e},i),n=s.min(r),o=s.max(r);return this.vptCoords={tl:n,tr:new X(o.x,n.y),bl:new X(n.x,o.y),br:o}}cancelRequestedRender(){this.nextRenderHandle&&(N(this.nextRenderHandle),this.nextRenderHandle=0)}drawControls(t){}renderCanvas(t,e){if(this.destroyed)return;const i=this.viewportTransform,s=this.clipPath;this.calcViewportBoundaries(),this.clearContext(t),t.imageSmoothingEnabled=this.imageSmoothingEnabled,t.patternQuality="best",this.fire("before:render",{ctx:t}),this._renderBackground(t),t.save(),t.transform(i[0],i[1],i[2],i[3],i[4],i[5]),this._renderObjects(t,e),t.restore(),this.controlsAboveOverlay||this.drawControls(t),s&&(s._set("canvas",this),s.shouldCache(),s._transformDone=!0,s.renderCache({forClipping:!0}),this.drawClipPathOnCanvas(t,s)),this._renderOverlay(t),this.controlsAboveOverlay&&this.drawControls(t),this.fire("after:render",{ctx:t}),this.__cleanupTask&&(this.__cleanupTask(),this.__cleanupTask=void 0)}drawClipPathOnCanvas(t,e){const i=this.viewportTransform;t.save(),t.transform(...i),t.globalCompositeOperation="destination-in",e.transform(t),t.scale(1/e.zoomX,1/e.zoomY),t.drawImage(e._cacheCanvas,-e.cacheTranslationX,-e.cacheTranslationY),t.restore()}_renderObjects(t,e){for(let i=0,s=e.length;i<s;++i)e[i]&&e[i].render(t)}_renderBackgroundOrOverlay(t,e){const i=this["".concat(e,"Color")],s=this["".concat(e,"Image")],r=this.viewportTransform,n=this["".concat(e,"Vpt")];if(!i&&!s)return;const o=jt(i);if(i){if(t.save(),t.beginPath(),t.moveTo(0,0),t.lineTo(this.width,0),t.lineTo(this.width,this.height),t.lineTo(0,this.height),t.closePath(),t.fillStyle=o?i.toLive(t):i,n&&t.transform(...r),o){t.transform(1,0,0,1,i.offsetX||0,i.offsetY||0);const e=i.gradientTransform||i.patternTransform;e&&t.transform(...e)}t.fill(),t.restore()}s&&(t.save(),n&&t.transform(...r),s.render(t),t.restore())}_renderBackground(t){this._renderBackgroundOrOverlay(t,"background")}_renderOverlay(t){this._renderBackgroundOrOverlay(t,"overlay")}getCenter(){return{top:this.height/2,left:this.width/2}}getCenterPoint(){return new X(this.width/2,this.height/2)}centerObjectH(t){return this._centerObject(t,new X(this.getCenterPoint().x,t.getCenterPoint().y))}centerObjectV(t){return this._centerObject(t,new X(t.getCenterPoint().x,this.getCenterPoint().y))}centerObject(t){return this._centerObject(t,this.getCenterPoint())}viewportCenterObject(t){return this._centerObject(t,this.getVpCenter())}viewportCenterObjectH(t){return this._centerObject(t,new X(this.getVpCenter().x,t.getCenterPoint().y))}viewportCenterObjectV(t){return this._centerObject(t,new X(t.getCenterPoint().x,this.getVpCenter().y))}getVpCenter(){return ot(this.getCenterPoint(),at(this.viewportTransform))}_centerObject(t,e){t.setXY(e,"center","center"),t.setCoords(),this.renderOnAddRemove&&this.requestRenderAll()}toDatalessJSON(t){return this.toDatalessObject(t)}toObject(t){return this._toObjectMethod("toObject",t)}toJSON(){return this.toObject()}toDatalessObject(t){return this._toObjectMethod("toDatalessObject",t)}_toObjectMethod(t,e){const s=this.clipPath,r=s&&!s.excludeFromExport?this._toObject(s,t,e):null;return i(i(i({version:y},mt(this,e)),{},{objects:this._objects.filter((t=>!t.excludeFromExport)).map((i=>this._toObject(i,t,e)))},this.__serializeBgOverlay(t,e)),r?{clipPath:r}:null)}_toObject(t,e,i){let s;this.includeDefaultValues||(s=t.includeDefaultValues,t.includeDefaultValues=!1);const r=t[e](i);return this.includeDefaultValues||(t.includeDefaultValues=!!s),r}__serializeBgOverlay(t,e){const i={},s=this.backgroundImage,r=this.overlayImage,n=this.backgroundColor,o=this.overlayColor;return jt(n)?n.excludeFromExport||(i.background=n.toObject(e)):n&&(i.background=n),jt(o)?o.excludeFromExport||(i.overlay=o.toObject(e)):o&&(i.overlay=o),s&&!s.excludeFromExport&&(i.backgroundImage=this._toObject(s,t,e)),r&&!r.excludeFromExport&&(i.overlayImage=this._toObject(r,t,e)),i}toSVG(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;t.reviver=e;const i=[];return this._setSVGPreamble(i,t),this._setSVGHeader(i,t),this.clipPath&&i.push('<g clip-path="url(#'.concat(this.clipPath.clipPathId,')" >\n')),this._setSVGBgOverlayColor(i,"background"),this._setSVGBgOverlayImage(i,"backgroundImage",e),this._setSVGObjects(i,e),this.clipPath&&i.push("</g>\n"),this._setSVGBgOverlayColor(i,"overlay"),this._setSVGBgOverlayImage(i,"overlayImage",e),i.push("</svg>"),i.join("")}_setSVGPreamble(t,e){e.suppressPreamble||t.push('<?xml version="1.0" encoding="',e.encoding||"UTF-8",'" standalone="no" ?>\n','<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" ','"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n')}_setSVGHeader(t,e){const i=e.width||"".concat(this.width),s=e.height||"".concat(this.height),r=c.NUM_FRACTION_DIGITS,n=e.viewBox;let o;if(n)o='viewBox="'.concat(n.x," ").concat(n.y," ").concat(n.width," ").concat(n.height,'" ');else if(this.svgViewportTransformation){const t=this.viewportTransform;o='viewBox="'.concat(Tt(-t[4]/t[0],r)," ").concat(Tt(-t[5]/t[3],r)," ").concat(Tt(this.width/t[0],r)," ").concat(Tt(this.height/t[3],r),'" ')}else o='viewBox="0 0 '.concat(this.width," ").concat(this.height,'" ');t.push("<svg ",'xmlns="http://www.w3.org/2000/svg" ','xmlns:xlink="http://www.w3.org/1999/xlink" ','version="1.1" ','width="',i,'" ','height="',s,'" ',o,'xml:space="preserve">\n',"<desc>Created with Fabric.js ",y,"</desc>\n","<defs>\n",this.createSVGFontFacesMarkup(),this.createSVGRefElementsMarkup(),this.createSVGClipPathMarkup(e),"</defs>\n")}createSVGClipPathMarkup(t){const e=this.clipPath;return e?(e.clipPathId="CLIPPATH_".concat(Q()),'<clipPath id="'+e.clipPathId+'" >\n'+this.clipPath.toClipPathSVG(t.reviver)+"</clipPath>\n"):""}createSVGRefElementsMarkup(){return["background","overlay"].map((t=>{const e=this["".concat(t,"Color")];if(jt(e)){const i=this["".concat(t,"Vpt")],s=this.viewportTransform,r={width:this.width/(i?s[0]:1),height:this.height/(i?s[3]:1)};return e.toSVG(r,{additionalTransform:i?Mt(s):""})}})).join("")}createSVGFontFacesMarkup(){const t=[],e={},i=c.fontPaths;this._objects.forEach((function e(i){t.push(i),Rt(i)&&i._objects.forEach(e)})),t.forEach((t=>{if(!Bt(t))return;let s=t.fontFamily;!e[s]&&i[s]&&(e[s]=!0,t.styles&&Object.values(t.styles).forEach((t=>{Object.values(t).forEach((t=>{s=t.fontFamily,!e[s]&&i[s]&&(e[s]=!0)}))})))}));const s=Object.keys(e).map((t=>"\t\t@font-face {\n\t\t\tfont-family: '".concat(t,"';\n\t\t\tsrc: url('").concat(i[t],"');\n\t\t}\n"))).join("");return s?'\t<style type="text/css"><![CDATA[\n'.concat(s,"]]></style>\n"):""}_setSVGObjects(t,e){this.forEachObject((i=>{i.excludeFromExport||this._setSVGObject(t,i,e)}))}_setSVGObject(t,e,i){t.push(e.toSVG(i))}_setSVGBgOverlayImage(t,e,i){const s=this[e];s&&!s.excludeFromExport&&s.toSVG&&t.push(s.toSVG(i))}_setSVGBgOverlayColor(t,e){const i=this["".concat(e,"Color")];if(i)if(jt(i)){const s=i.repeat||"",r=this.width,n=this.height,o=this["".concat(e,"Vpt")]?Mt(at(this.viewportTransform)):"";t.push('<rect transform="'.concat(o," translate(").concat(r/2,",").concat(n/2,')" x="').concat(i.offsetX-r/2,'" y="').concat(i.offsetY-n/2,'" width="').concat("repeat-y"!==s&&"no-repeat"!==s||!Lt(i)?r:i.source.width,'" height="').concat("repeat-x"!==s&&"no-repeat"!==s||!Lt(i)?n:i.source.height,'" fill="url(#SVGID_').concat(i.id,')"></rect>\n'))}else t.push('<rect x="0" y="0" width="100%" height="100%" ','fill="',i,'"',"></rect>\n")}loadFromJSON(t,e){let{signal:i}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!t)return Promise.reject(new Error("fabric.js: `json` is undefined"));const s="string"==typeof t?JSON.parse(t):t,{objects:r=[],backgroundImage:n,background:o,overlayImage:a,overlay:h,clipPath:c}=s,l=this.renderOnAddRemove;return this.renderOnAddRemove=!1,Promise.all([ft(r,{reviver:e,signal:i}),pt({backgroundImage:n,backgroundColor:o,overlayImage:a,overlayColor:h,clipPath:c},{signal:i})]).then((t=>{let[e,i]=t;return this.clear(),this.add(...e),this.set(s),this.set(i),this.renderOnAddRemove=l,this}))}clone(t){const e=this.toObject(t);return this.cloneWithoutData().loadFromJSON(e)}cloneWithoutData(){const t=tt();return t.width=this.width,t.height=this.height,new this.constructor(t)}toDataURL(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const{format:e=G.png,quality:i=1,multiplier:s=1,enableRetinaScaling:r=!1}=t,n=s*(r?this.getRetinaScaling():1);return it(this.toCanvasElement(n,t),e,i)}toCanvasElement(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,{width:e,height:i,left:s,top:r,filter:n}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const o=(e||this.width)*t,a=(i||this.height)*t,h=this.getZoom(),c=this.width,l=this.height,d=h*t,u=this.viewportTransform,g=[d,0,0,d,(u[4]-(s||0))*t,(u[5]-(r||0))*t],f=this.enableRetinaScaling,p=tt(),m=n?this._objects.filter((t=>n(t))):this._objects;return p.width=o,p.height=a,this.enableRetinaScaling=!1,this.viewportTransform=g,this.width=o,this.height=a,this.calcViewportBoundaries(),this.renderCanvas(p.getContext("2d"),m),this.viewportTransform=u,this.width=c,this.height=l,this.calcViewportBoundaries(),this.enableRetinaScaling=f,p}dispose(){return this.disposed=!0,new Promise(((t,e)=>{const i=()=>{this.destroy(),t(!0)};i.kill=e,this.__cleanupTask&&this.__cleanupTask.kill("aborted"),this.destroyed?t(!1):this.nextRenderHandle?this.__cleanupTask=i:i()}))}destroy(){this.destroyed=!0,this.cancelRequestedRender(),this.forEachObject((t=>t.dispose())),this._objects=[],this.backgroundImage&&this.backgroundImage.dispose(),this.backgroundImage=null,this.overlayImage&&this.overlayImage.dispose(),this.overlayImage=null,this.contextContainer=null;const t=this.lowerCanvasEl;this.lowerCanvasEl=void 0,t.classList.remove("lower-canvas"),t.removeAttribute("data-fabric"),t.setAttribute("width","".concat(this.width)),t.setAttribute("height","".concat(this.height)),t.style.cssText=this._originalCanvasStyle||"",this._originalCanvasStyle=void 0,m().dispose(t)}toString(){return"#<Canvas (".concat(this.complexity(),"): { objects: ").concat(this._objects.length," }>")}}s(Vt,"ownDefaults",Wt);const Gt=["touchstart","touchmove","touchend"];const zt=t=>{const e=K(t.target),i=function(t){const e=t.changedTouches;return e&&e[0]?e[0]:t}(t);return new X(i.clientX+e.left,i.clientY+e.top)},Ht=t=>Gt.indexOf(t.type)>-1||"touch"===t.pointerType,Ut=t=>{t.preventDefault(),t.stopPropagation()},Nt=t=>{if(0===t.length)return{left:0,top:0,width:0,height:0};const{min:e,max:i}=t.reduce(((t,e)=>{let{min:i,max:s}=t;return{min:i.min(e),max:s.max(e)}}),{min:new X(t[0]),max:new X(t[0])}),s=i.subtract(e);return{left:e.x,top:e.y,width:s.x,height:s.y}},qt=["translateX","translateY","scaleX","scaleY"],Kt=(t,e)=>Jt(t,ht(e,t.calcOwnMatrix())),Jt=(t,e)=>{const i=ct(e),{translateX:s,translateY:r,scaleX:o,scaleY:a}=i,h=n(i,qt),c=new X(s,r);t.flipX=!1,t.flipY=!1,Object.assign(t,h),t.set({scaleX:o,scaleY:a}),t.setPositionByOrigin(c,"center","center")},$t=t=>{t.scaleX=1,t.scaleY=1,t.skewX=0,t.skewY=0,t.flipX=!1,t.flipY=!1,t.rotate(0)},Zt=t=>({scaleX:t.scaleX,scaleY:t.scaleY,skewX:t.skewX,skewY:t.skewY,angle:t.angle,left:t.left,flipX:t.flipX,flipY:t.flipY,top:t.top}),Qt=(t,e,i)=>{const s=t/2,r=e/2,n=dt(i),o=[new X(-s,-r),new X(s,-r),new X(-s,r),new X(s,r)].map((t=>t.transform(n))),a=Nt(o);return new X(a.width,a.height)};let te;!function(t){t.sibling="sibling",t.child="child"}(te||(te={}));const ee=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:T;return ht(at(arguments.length>1&&void 0!==arguments[1]?arguments[1]:T),t)},ie=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:T,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:T;return t.transform(ee(e,i))},se=(t,e,i)=>{const s=ee(e,i);return Jt(t,ht(s,t.calcOwnMatrix())),s},re=(t,e)=>{var s;const{transform:{target:r}}=e;null===(s=r.canvas)||void 0===s||s.fire("object:".concat(t),i(i({},e),{},{target:r})),r.fire(t,e)},ne={left:-.5,top:-.5,center:0,bottom:.5,right:.5},oe=t=>"string"==typeof t?ne[t]:t-.5,ae="not-allowed";function he(t){return"center"===t.originX&&"center"===t.originY}function ce(t){return.5-oe(t)}const le=(t,e)=>t[e],de=(t,e,i,s)=>({e:t,transform:e,pointer:new X(i,s)});function ue(t,e){const i=t.getTotalAngle()+rt(Math.atan2(e.y,e.x))+360;return Math.round(i%360/45)}function ge(t,e,i,s,r){var n;let{target:o,corner:a}=t;const h=o.controls[a],c=(null===(n=o.canvas)||void 0===n?void 0:n.getZoom())||1,l=o.padding/c,d=function(t,e,i,s){const r=t.getRelativeCenterPoint(),n=void 0!==i&&void 0!==s?t.translateToGivenOrigin(r,"center","center",i,s):new X(t.left,t.top);return(t.angle?e.rotate(-st(t.angle),r):e).subtract(n)}(o,new X(s,r),e,i);return d.x>=l&&(d.x-=l),d.x<=-l&&(d.x+=l),d.y>=l&&(d.y-=l),d.y<=l&&(d.y+=l),d.x-=h.offsetX,d.y-=h.offsetY,d}const fe=(t,e,i,s)=>{const{target:r,offsetX:n,offsetY:o}=e,a=i-n,h=s-o,c=!le(r,"lockMovementX")&&r.left!==a,l=!le(r,"lockMovementY")&&r.top!==h;return c&&r.set("left",a),l&&r.set("top",h),(c||l)&&re("moving",de(t,e,i,s)),c||l};class pe{getSvgStyles(t){const e=this.fillRule?this.fillRule:"nonzero",i=this.strokeWidth?this.strokeWidth:"0",s=this.strokeDashArray?this.strokeDashArray.join(" "):"none",r=this.strokeDashOffset?this.strokeDashOffset:"0",n=this.strokeLineCap?this.strokeLineCap:"butt",o=this.strokeLineJoin?this.strokeLineJoin:"miter",a=this.strokeMiterLimit?this.strokeMiterLimit:"4",h=void 0!==this.opacity?this.opacity:"1",c=this.visible?"":" visibility: hidden;",l=t?"":this.getSvgFilter(),d=Pt("fill",this.fill);return[Pt("stroke",this.stroke),"stroke-width: ",i,"; ","stroke-dasharray: ",s,"; ","stroke-linecap: ",n,"; ","stroke-dashoffset: ",r,"; ","stroke-linejoin: ",o,"; ","stroke-miterlimit: ",a,"; ",d,"fill-rule: ",e,"; ","opacity: ",h,";",l,c].join("")}getSvgSpanStyles(t,e){const i="; ",s=t.fontFamily?"font-family: ".concat(-1===t.fontFamily.indexOf("'")&&-1===t.fontFamily.indexOf('"')?"'".concat(t.fontFamily,"'"):t.fontFamily).concat(i):"",r=t.strokeWidth?"stroke-width: ".concat(t.strokeWidth).concat(i):"",n=t.fontSize?"font-size: ".concat(t.fontSize,"px").concat(i):"",o=t.fontStyle?"font-style: ".concat(t.fontStyle).concat(i):"",a=t.fontWeight?"font-weight: ".concat(t.fontWeight).concat(i):"",h=t.fill?Pt("fill",t.fill):"",c=t.stroke?Pt("stroke",t.stroke):"",l=this.getSvgTextDecoration(t),d=t.deltaY?"baseline-shift: ".concat(-t.deltaY,"; "):"";return[c,r,s,n,o,a,l?"text-decoration: ".concat(l).concat(i):l,h,d,e?"white-space: pre; ":""].join("")}getSvgTextDecoration(t){return["overline","underline","line-through"].filter((e=>t[e.replace("-","")])).join(" ")}getSvgFilter(){return this.shadow?"filter: url(#SVGID_".concat(this.shadow.id,");"):""}getSvgCommons(){return[this.id?'id="'.concat(this.id,'" '):"",this.clipPath?'clip-path="url(#'.concat(this.clipPath.clipPathId,')" '):""].join("")}getSvgTransform(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const i=t?this.calcTransformMatrix():this.calcOwnMatrix(),s='transform="'.concat(Mt(i));return"".concat(s).concat(e,'" ')}toSVG(t){return this._createBaseSVGMarkup(this._toSVG(t),{reviver:t})}toClipPathSVG(t){return"\t"+this._createBaseClipPathSVGMarkup(this._toSVG(t),{reviver:t})}_createBaseClipPathSVGMarkup(t){let{reviver:e,additionalTransform:i=""}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s=[this.getSvgTransform(!0,i),this.getSvgCommons()].join(""),r=t.indexOf("COMMON_PARTS");return t[r]=s,e?e(t.join("")):t.join("")}_createBaseSVGMarkup(t){let{noStyle:e,reviver:i,withShadow:s,additionalTransform:r}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n=e?"":'style="'.concat(this.getSvgStyles(),'" '),o=s?'style="'.concat(this.getSvgFilter(),'" '):"",a=this.clipPath,h=this.strokeUniform?'vector-effect="non-scaling-stroke" ':"",c=a&&a.absolutePositioned,l=this.stroke,d=this.fill,u=this.shadow,g=[],f=t.indexOf("COMMON_PARTS");let p;a&&(a.clipPathId="CLIPPATH_".concat(Q()),p='<clipPath id="'.concat(a.clipPathId,'" >\n').concat(a.toClipPathSVG(i),"</clipPath>\n")),c&&g.push("<g ",o,this.getSvgCommons()," >\n"),g.push("<g ",this.getSvgTransform(!1),c?"":o+this.getSvgCommons()," >\n");const m=[n,h,e?"":this.addPaintOrder()," ",r?'transform="'.concat(r,'" '):""].join("");return t[f]=m,d&&d.toLive&&g.push(d.toSVG(this)),l&&l.toLive&&g.push(l.toSVG(this)),u&&g.push(u.toSVG(this)),a&&g.push(p),g.push(t.join("")),g.push("</g>\n"),c&&g.push("</g>\n"),i?i(g.join("")):g.join("")}addPaintOrder(){return"fill"!==this.paintFirst?' paint-order="'.concat(this.paintFirst,'" '):""}}const me=(t,e,i,s)=>(t<Math.abs(e)?(t=e,s=i/4):s=0===e&&0===t?i/S*Math.asin(1):i/S*Math.asin(e/t),{a:t,c:e,p:i,s:s}),ve=(t,e,i,s,r)=>t*Math.pow(2,10*(s-=1))*Math.sin((s*r-e)*S/i),_e=(t,e,i,s)=>-i*Math.cos(t/s*b)+i+e,xe=(t,e,i,s)=>(t/=s)<1/2.75?i*(7.5625*t*t)+e:t<2/2.75?i*(7.5625*(t-=1.5/2.75)*t+.75)+e:t<2.5/2.75?i*(7.5625*(t-=2.25/2.75)*t+.9375)+e:i*(7.5625*(t-=2.625/2.75)*t+.984375)+e,ye=(t,e,i,s)=>i-xe(s-t,0,i,s)+e;var Ce=Object.freeze({__proto__:null,defaultEasing:_e,easeInBack:function(t,e,i,s){let r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1.70158;return i*(t/=s)*t*((r+1)*t-r)+e},easeInBounce:ye,easeInCirc:(t,e,i,s)=>-i*(Math.sqrt(1-(t/=s)*t)-1)+e,easeInCubic:(t,e,i,s)=>i*(t/s)**3+e,easeInElastic:(t,e,i,s)=>{const r=i;let n=0;if(0===t)return e;if(1===(t/=s))return e+i;n||(n=.3*s);const{a:o,s:a,p:h}=me(r,i,n,1.70158);return-ve(o,a,h,t,s)+e},easeInExpo:(t,e,i,s)=>0===t?e:i*2**(10*(t/s-1))+e,easeInOutBack:function(t,e,i,s){let r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1.70158;return(t/=s/2)<1?i/2*(t*t*((1+(r*=1.525))*t-r))+e:i/2*((t-=2)*t*((1+(r*=1.525))*t+r)+2)+e},easeInOutBounce:(t,e,i,s)=>t<s/2?.5*ye(2*t,0,i,s)+e:.5*xe(2*t-s,0,i,s)+.5*i+e,easeInOutCirc:(t,e,i,s)=>(t/=s/2)<1?-i/2*(Math.sqrt(1-t**2)-1)+e:i/2*(Math.sqrt(1-(t-=2)*t)+1)+e,easeInOutCubic:(t,e,i,s)=>(t/=s/2)<1?i/2*t**3+e:i/2*((t-2)**3+2)+e,easeInOutElastic:(t,e,i,s)=>{const r=i;let n=0;if(0===t)return e;if(2===(t/=s/2))return e+i;n||(n=s*(.3*1.5));const{a:o,s:a,p:h,c:c}=me(r,i,n,1.70158);return t<1?-.5*ve(o,a,h,t,s)+e:o*Math.pow(2,-10*(t-=1))*Math.sin((t*s-a)*S/h)*.5+c+e},easeInOutExpo:(t,e,i,s)=>0===t?e:t===s?e+i:(t/=s/2)<1?i/2*2**(10*(t-1))+e:i/2*-(2**(-10*--t)+2)+e,easeInOutQuad:(t,e,i,s)=>(t/=s/2)<1?i/2*t**2+e:-i/2*(--t*(t-2)-1)+e,easeInOutQuart:(t,e,i,s)=>(t/=s/2)<1?i/2*t**4+e:-i/2*((t-=2)*t**3-2)+e,easeInOutQuint:(t,e,i,s)=>(t/=s/2)<1?i/2*t**5+e:i/2*((t-2)**5+2)+e,easeInOutSine:(t,e,i,s)=>-i/2*(Math.cos(Math.PI*t/s)-1)+e,easeInQuad:(t,e,i,s)=>i*(t/=s)*t+e,easeInQuart:(t,e,i,s)=>i*(t/=s)*t**3+e,easeInQuint:(t,e,i,s)=>i*(t/s)**5+e,easeInSine:(t,e,i,s)=>-i*Math.cos(t/s*b)+i+e,easeOutBack:function(t,e,i,s){let r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1.70158;return i*((t=t/s-1)*t*((r+1)*t+r)+1)+e},easeOutBounce:xe,easeOutCirc:(t,e,i,s)=>i*Math.sqrt(1-(t=t/s-1)*t)+e,easeOutCubic:(t,e,i,s)=>i*((t/s-1)**3+1)+e,easeOutElastic:(t,e,i,s)=>{const r=i;let n=0;if(0===t)return e;if(1===(t/=s))return e+i;n||(n=.3*s);const{a:o,s:a,p:h,c:c}=me(r,i,n,1.70158);return o*2**(-10*t)*Math.sin((t*s-a)*S/h)+c+e},easeOutExpo:(t,e,i,s)=>t===s?e+i:i*-(2**(-10*t/s)+1)+e,easeOutQuad:(t,e,i,s)=>-i*(t/=s)*(t-2)+e,easeOutQuart:(t,e,i,s)=>-i*((t=t/s-1)*t**3-1)+e,easeOutQuint:(t,e,i,s)=>i*((t/s-1)**5+1)+e,easeOutSine:(t,e,i,s)=>i*Math.sin(t/s*b)+e});const be=()=>!1;class Se{constructor(t){let{startValue:e,byValue:i,duration:r=500,delay:n=0,easing:o=_e,onStart:a=C,onChange:h=C,onComplete:c=C,abort:l=be,target:d}=t;s(this,"_state","pending"),s(this,"durationProgress",0),s(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=r,this.delay=n,this.easing=o,this._onStart=a,this._onChange=h,this._onComplete=c,this._abort=l,this.target=d,this.startValue=e,this.byValue=i,this.value=this.startValue,this.endValue=Object.freeze(this.calculate(this.duration).value)}get state(){return this._state}isDone(){return"aborted"===this._state||"completed"===this._state}start(){const t=t=>{"pending"===this._state&&(this.startTime=t||+new Date,this._state="running",this._onStart(),this.tick(this.startTime))};this.register(),this.delay>0?setTimeout((()=>U(t)),this.delay):U(t)}tick(t){const e=(t||+new Date)-this.startTime,i=Math.min(e,this.duration);this.durationProgress=i/this.duration;const{value:s,valueProgress:r}=this.calculate(i);this.value=Object.freeze(s),this.valueProgress=r,"aborted"!==this._state&&(this._abort(this.value,this.valueProgress,this.durationProgress)?(this._state="aborted",this.unregister()):e>=this.duration?(this.durationProgress=this.valueProgress=1,this._onChange(this.endValue,this.valueProgress,this.durationProgress),this._state="completed",this._onComplete(this.endValue,this.valueProgress,this.durationProgress),this.unregister()):(this._onChange(this.value,this.valueProgress,this.durationProgress),U(this.tick)))}register(){P.push(this)}unregister(){P.remove(this)}abort(){this._state="aborted",this.unregister()}}const we=["startValue","endValue"];class Te extends Se{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(i(i({},n(t,we)),{},{startValue:e,byValue:s-e}))}calculate(t){const e=this.easing(t,this.startValue,this.byValue,this.duration);return{value:e,valueProgress:Math.abs((e-this.startValue)/this.byValue)}}}const Oe=["startValue","endValue"];class ke extends Se{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(i(i({},n(t,Oe)),{},{startValue:e,byValue:s.map(((t,i)=>t-e[i]))}))}calculate(t){const e=this.startValue.map(((e,i)=>this.easing(t,e,this.byValue[i],this.duration,i)));return{value:e,valueProgress:Math.abs((e[0]-this.startValue[0])/this.byValue[0])}}}const De=(t,e,i)=>Math.max(t,Math.min(e,i)),Ee=["startValue","endValue","easing","onChange","onComplete","abort"],Me=(t,e,i,s)=>e+i*(1-Math.cos(t/s*b)),Pe=t=>t&&((e,i,s)=>t(new wt(e).toRgba(),i,s));class Ae extends Se{constructor(t){let{startValue:e,endValue:s,easing:r=Me,onChange:o,onComplete:a,abort:h}=t,c=n(t,Ee);const l=new wt(e).getSource(),d=new wt(s).getSource();super(i(i({},c),{},{startValue:l,byValue:d.map(((t,e)=>t-l[e])),easing:r,onChange:Pe(o),onComplete:Pe(a),abort:Pe(h)}))}calculate(t){const[e,i,s,r]=this.startValue.map(((e,i)=>this.easing(t,e,this.byValue[i],this.duration,i))),n=[...[e,i,s].map(Math.round),De(0,r,1)];return{value:n,valueProgress:n.map(((t,e)=>0!==this.byValue[e]?Math.abs((t-this.startValue[e])/this.byValue[e]):0)).find((t=>0!==t))||0}}}const je=t=>Array.isArray(t.startValue)||Array.isArray(t.endValue);function Fe(t){const e=je(t)?new ke(t):new Te(t);return e.start(),e}function Le(t){const e=new Ae(t);return e.start(),e}const Re=new X(1,0),Be=(t,e)=>t.rotate(e),Ie=(t,e)=>new X(e).subtract(t),Xe=t=>t.distanceFrom(new X),Ye=(t,e)=>{const i=t.x*e.x+t.y*e.y,s=t.x*e.y-t.y*e.x;return Math.atan2(s,i)},We=t=>t.scalarDivide(Xe(t)),Ve=(t,e,i)=>{const s=Ie(t,e),r=Ie(t,i),n=Ye(s,r);return{vector:We(Be(s,n/2)),angle:n}},Ge=function(t){let e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return We(new X(-t.y,t.x).scalarMultiply(e?1:-1))};class ze{constructor(t){this.status=t,this.points=[]}includes(t){return this.points.some((e=>e.eq(t)))}append(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];return this.points=this.points.concat(e.filter((t=>!this.includes(t)))),this}static isPointContained(t,e,i){let s=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(e.eq(i))return t.eq(e);if(e.x===i.x)return t.x===e.x&&(s||t.y>=Math.min(e.y,i.y)&&t.y<=Math.max(e.y,i.y));if(e.y===i.y)return t.y===e.y&&(s||t.x>=Math.min(e.x,i.x)&&t.x<=Math.max(e.x,i.x));{const r=Ie(e,i),n=Ie(e,t).divide(r);return s?Math.abs(n.x)===Math.abs(n.y):n.x===n.y&&n.x>=0&&n.x<=1}}static intersectLineLine(t,e,i,s){let r=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],n=!(arguments.length>5&&void 0!==arguments[5])||arguments[5];const o=e.x-t.x,a=e.y-t.y,h=s.x-i.x,c=s.y-i.y,l=t.x-i.x,d=t.y-i.y,u=h*d-c*l,g=o*d-a*l,f=c*o-h*a;if(0!==f){const e=u/f,i=g/f;return(r||0<=e&&e<=1)&&(n||0<=i&&i<=1)?new ze("Intersection").append(new X(t.x+e*o,t.y+e*a)):new ze}if(0===u||0===g){const o=r||n||ze.isPointContained(t,i,s)||ze.isPointContained(e,i,s)||ze.isPointContained(i,t,e)||ze.isPointContained(s,t,e);return new ze(o?"Coincident":void 0)}return new ze("Parallel")}static intersectSegmentLine(t,e,i,s){return ze.intersectLineLine(t,e,i,s,!1,!0)}static intersectSegmentSegment(t,e,i,s){return ze.intersectLineLine(t,e,i,s,!1,!1)}static intersectLinePolygon(t,e,i){let s=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];const r=new ze,n=i.length;for(let o,a,h,c=0;c<n;c++){if(o=i[c],a=i[(c+1)%n],h=ze.intersectLineLine(t,e,o,a,s,!1),"Coincident"===h.status)return h;r.append(...h.points)}return r.points.length>0&&(r.status="Intersection"),r}static intersectSegmentPolygon(t,e,i){return ze.intersectLinePolygon(t,e,i,!1)}static intersectPolygonPolygon(t,e){const i=new ze,s=t.length,r=[];for(let n=0;n<s;n++){const o=t[n],a=t[(n+1)%s],h=ze.intersectSegmentPolygon(o,a,e);"Coincident"===h.status?(r.push(h),i.append(o,a)):i.append(...h.points)}return r.length>0&&r.length===t.length?new ze("Coincident"):(i.points.length>0&&(i.status="Intersection"),i)}static intersectPolygonRectangle(t,e,i){const s=e.min(i),r=e.max(i),n=new X(r.x,s.y),o=new X(s.x,r.y);return ze.intersectPolygonPolygon(t,[s,n,r,o])}}class He extends V{_getTransformedDimensions(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const e=i({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,width:this.width,height:this.height,strokeWidth:this.strokeWidth},t),s=e.strokeWidth;let r=s,n=0;this.strokeUniform&&(r=0,n=s);const o=e.width+r,a=e.height+r;let h;return h=0===e.skewX&&0===e.skewY?new X(o*e.scaleX,a*e.scaleY):Qt(o,a,e),h.scalarAdd(n)}translateToGivenOrigin(t,e,i,s,r){let n=t.x,o=t.y;const a=oe(s)-oe(e),h=oe(r)-oe(i);if(a||h){const t=this._getTransformedDimensions();n+=a*t.x,o+=h*t.y}return new X(n,o)}translateToCenterPoint(t,e,i){const s=this.translateToGivenOrigin(t,e,i,"center","center");return this.angle?s.rotate(st(this.angle),t):s}translateToOriginPoint(t,e,i){const s=this.translateToGivenOrigin(t,"center","center",e,i);return this.angle?s.rotate(st(this.angle),t):s}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?ot(t,this.group.calcTransformMatrix()):t}getRelativeCenterPoint(){return this.translateToCenterPoint(new X(this.left,this.top),this.originX,this.originY)}getPointByOrigin(t,e){return this.translateToOriginPoint(this.getRelativeCenterPoint(),t,e)}setPositionByOrigin(t,e,i){const s=this.translateToCenterPoint(t,e,i),r=this.translateToOriginPoint(s,this.originX,this.originY);this.set({left:r.x,top:r.y})}_setOriginToCenter(){this._originalOriginX=this.originX,this._originalOriginY=this.originY;const t=this.getRelativeCenterPoint();this.originX="center",this.originY="center",this.left=t.x,this.top=t.y}_resetOrigin(){if(void 0!==this._originalOriginX&&void 0!==this._originalOriginY){const t=this.translateToOriginPoint(this.getRelativeCenterPoint(),this._originalOriginX,this._originalOriginY);this.left=t.x,this.top=t.y,this.originX=this._originalOriginX,this.originY=this._originalOriginY,this._originalOriginX=void 0,this._originalOriginY=void 0}}_getLeftTopCoords(){return this.translateToOriginPoint(this.getRelativeCenterPoint(),"left","top")}}class Ue extends He{getX(){return this.getXY().x}setX(t){this.setXY(this.getXY().setX(t))}getY(){return this.getXY().y}setY(t){this.setXY(this.getXY().setY(t))}getRelativeX(){return this.left}setRelativeX(t){this.left=t}getRelativeY(){return this.top}setRelativeY(t){this.top=t}getXY(){const t=this.getRelativeXY();return this.group?ot(t,this.group.calcTransformMatrix()):t}setXY(t,e,i){this.group&&(t=ot(t,at(this.group.calcTransformMatrix()))),this.setRelativeXY(t,e,i)}getRelativeXY(){return new X(this.left,this.top)}setRelativeXY(t,e,i){this.setPositionByOrigin(t,e||this.originX,i||this.originY)}_getCoords(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return arguments.length>1&&void 0!==arguments[1]&&arguments[1]?t?this.calcACoords():this.calcLineCoords():(this.aCoords||(this.aCoords=this.calcACoords()),this.lineCoords||(this.lineCoords=this.calcLineCoords()),t?this.aCoords:this.lineCoords)}getCoords(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const{tl:i,tr:s,br:r,bl:n}=this._getCoords(t,e),o=[i,s,r,n];if(this.group){const t=this.group.calcTransformMatrix();return o.map((e=>ot(e,t)))}return o}intersectsWithRect(t,e,i,s){const r=this.getCoords(i,s);return"Intersection"===ze.intersectPolygonRectangle(r,t,e).status}intersectsWithObject(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const s=ze.intersectPolygonPolygon(this.getCoords(e,i),t.getCoords(e,i));return"Intersection"===s.status||"Coincident"===s.status||t.isContainedWithinObject(this,e,i)||this.isContainedWithinObject(t,e,i)}isContainedWithinObject(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const s=this.getCoords(e,i),r=e?t.aCoords:t.lineCoords,n=t._getImageLines(r);for(let e=0;e<4;e++)if(!t.containsPoint(s[e],n))return!1;return!0}isContainedWithinRect(t,e,i,s){const r=this.getBoundingRect(i,s);return r.left>=t.x&&r.left+r.width<=e.x&&r.top>=t.y&&r.top+r.height<=e.y}isOverlapping(t){return this.intersectsWithObject(t)||this.isContainedWithinObject(t)||t.isContainedWithinObject(this)}containsPoint(t,e){let i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],s=arguments.length>3&&void 0!==arguments[3]&&arguments[3];const r=this._getCoords(i,s),n=e||this._getImageLines(r),o=this._findCrossPoints(t,n);return 0!==o&&o%2==1}isOnScreen(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(!this.canvas)return!1;const{tl:e,br:i}=this.canvas.vptCoords;return!!this.getCoords(!0,t).some((t=>t.x<=i.x&&t.x>=e.x&&t.y<=i.y&&t.y>=e.y))||(!!this.intersectsWithRect(e,i,!0,t)||this._containsCenterOfCanvas(e,i,t))}_containsCenterOfCanvas(t,e,i){const s=t.midPointFrom(e);return this.containsPoint(s,void 0,!0,i)}isPartiallyOnScreen(t){if(!this.canvas)return!1;const{tl:e,br:i}=this.canvas.vptCoords;if(this.intersectsWithRect(e,i,!0,t))return!0;return this.getCoords(!0,t).every((t=>(t.x>=i.x||t.x<=e.x)&&(t.y>=i.y||t.y<=e.y)))&&this._containsCenterOfCanvas(e,i,t)}_getImageLines(t){let{tl:e,tr:i,bl:s,br:r}=t;return{topline:{o:e,d:i},rightline:{o:i,d:r},bottomline:{o:r,d:s},leftline:{o:s,d:e}}}_findCrossPoints(t,e){let i=0;for(const s in e){let r;const n=e[s];if(!(n.o.y<t.y&&n.d.y<t.y)&&!(n.o.y>=t.y&&n.d.y>=t.y)){if(n.o.x===n.d.x&&n.o.x>=t.x)r=n.o.x;else{const e=0,i=(n.d.y-n.o.y)/(n.d.x-n.o.x);r=-(t.y-e*t.x-(n.o.y-i*n.o.x))/(e-i)}if(r>=t.x&&(i+=1),2===i)break}}return i}getBoundingRect(t,e){return Nt(this.getCoords(t,e))}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set("scaleX",t),this._set("scaleY",t),this.setCoords()}scaleToWidth(t,e){const i=this.getBoundingRect(e).width/this.getScaledWidth();return this.scale(t/this.width/i)}scaleToHeight(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const i=this.getBoundingRect(e).height/this.getScaledHeight();return this.scale(t/this.height/i)}getCanvasRetinaScaling(){var t;return(null===(t=this.canvas)||void 0===t?void 0:t.getRetinaScaling())||1}getTotalAngle(){return this.group?ct(this.calcTransformMatrix()).angle:this.angle}calcLineCoords(){const t=this.getViewportTransform(),e=this.padding,i=st(this.getTotalAngle()),s=B(i)*e,r=I(i)*e,n=s+r,o=s-r,{tl:a,tr:h,bl:c,br:l}=this.calcACoords(),d={tl:ot(a,t),tr:ot(h,t),bl:ot(c,t),br:ot(l,t)};return e&&(d.tl.x-=o,d.tl.y-=n,d.tr.x+=n,d.tr.y-=o,d.bl.x-=n,d.bl.y+=o,d.br.x+=o,d.br.y+=n),d}getViewportTransform(){var t;return(null===(t=this.canvas)||void 0===t?void 0:t.viewportTransform)||T.concat()}calcACoords(){const t=lt({angle:this.angle}),e=this.getRelativeCenterPoint(),i=[1,0,0,1,e.x,e.y],s=ht(i,t),r=this._getTransformedDimensions(),n=r.x/2,o=r.y/2;return{tl:ot({x:-n,y:-o},s),tr:ot({x:n,y:-o},s),bl:ot({x:-n,y:o},s),br:ot({x:n,y:o},s)}}setCoords(){this.aCoords=this.calcACoords(),this.lineCoords=this.group?this.aCoords:this.calcLineCoords()}transformMatrixKey(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];const e="_";let i="";return!t&&this.group&&(i=this.group.transformMatrixKey(t)+e),i+this.top+e+this.left+e+this.scaleX+e+this.scaleY+e+this.skewX+e+this.skewY+e+this.angle+e+this.originX+e+this.originY+e+this.width+e+this.height+e+this.strokeWidth+this.flipX+this.flipY}calcTransformMatrix(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=this.calcOwnMatrix();if(t||!this.group)return e;const i=this.transformMatrixKey(t),s=this.matrixCache;return s&&s.key===i?s.value:(this.group&&(e=ht(this.group.calcTransformMatrix(!1),e)),this.matrixCache={key:i,value:e},e)}calcOwnMatrix(){const t=this.transformMatrixKey(!0),e=this.ownMatrixCache;if(e&&e.key===t)return e.value;const i=this.getRelativeCenterPoint(),s={angle:this.angle,translateX:i.x,translateY:i.y,scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,flipX:this.flipX,flipY:this.flipY},r=ut(s);return this.ownMatrixCache={key:t,value:r},r}_getNonTransformedDimensions(){return new X(this.width,this.height).scalarAdd(this.strokeWidth)}_calculateCurrentDimensions(t){return this._getTransformedDimensions(t).transform(this.getViewportTransform(),!0).scalarAdd(2*this.padding)}}class Ne extends Ue{getParent(t){return((e=this.group)&&e.isType("ActiveSelection")?this.__owningGroup:this.group)||(t?void 0:this.canvas);var e}isDescendantOf(t){return this.__owningGroup===t||this.group===t||this.canvas===t||!!this.__owningGroup&&this.__owningGroup.isDescendantOf(t)||!!this.group&&this.group.isDescendantOf(t)}getAncestors(t){const e=[];let i=this;do{i=i instanceof Ne?i.getParent(t):void 0,i&&e.push(i)}while(i);return e}findCommonAncestors(t,e){if(this===t)return{fork:[],otherFork:[],common:[this,...this.getAncestors(e)]};const i=this.getAncestors(e),s=t.getAncestors(e);if(0===i.length&&s.length>0&&this===s[s.length-1])return{fork:[],otherFork:[t,...s.slice(0,s.length-1)],common:[this]};for(let e,r=0;r<i.length;r++){if(e=i[r],e===t)return{fork:[this,...i.slice(0,r)],otherFork:[],common:i.slice(r)};for(let n=0;n<s.length;n++){if(this===s[n])return{fork:[],otherFork:[t,...s.slice(0,n)],common:[this,...i]};if(e===s[n])return{fork:[this,...i.slice(0,r)],otherFork:[t,...s.slice(0,n)],common:i.slice(r)}}}return{fork:[this,...i],otherFork:[t,...s],common:[]}}hasCommonAncestors(t,e){const i=this.findCommonAncestors(t,e);return i&&!!i.common.length}isInFrontOf(t){if(this===t)return;const e=this.findCommonAncestors(t);if(!e)return;if(e.fork.includes(t))return!0;if(e.otherFork.includes(this))return!1;const i=e.common[0];if(!i)return;const s=e.fork.pop(),r=e.otherFork.pop(),n=i._objects.indexOf(s),o=i._objects.indexOf(r);return n>-1&&n>o}}class qe extends Ne{animate(t,e){return Object.entries(t).reduce(((t,i)=>{let[s,r]=i;return t[s]=this._animate(s,r,e),t}),{})}_animate(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const s=t.split("."),r=this.colorProperties.includes(s[s.length-1]),{easing:n,duration:o,abort:a,startValue:h,onChange:c,onComplete:l}=i,d={target:this,startValue:null!=h?h:s.reduce(((t,e)=>t[e]),this),endValue:e,easing:n,duration:o,abort:null==a?void 0:a.bind(this),onChange:(t,e,i)=>{s.reduce(((e,i,r)=>(r===s.length-1&&(e[i]=t),e[i])),this),c&&c(t,e,i)},onComplete:(t,e,i)=>{this.setCoords(),l&&l(t,e,i)}};return r?Le(d):Fe(d)}}class Ke{constructor(t){const e="string"==typeof t?Ke.parseShadow(t):t;Object.assign(this,this.constructor.ownDefaults);for(const t in e)this[t]=e[t];this.id=Q()}static parseShadow(t){const e=t.trim(),[i,s=0,r=0,n=0]=(Ke.reOffsetsAndBlur.exec(e)||[]).map((t=>parseFloat(t)||0));return{color:(e.replace(Ke.reOffsetsAndBlur,"")||"rgb(0,0,0)").trim(),offsetX:s,offsetY:r,blur:n}}toString(){return[this.offsetX,this.offsetY,this.blur,this.color].join("px ")}toSVG(t){const e=Be(new X(this.offsetX,this.offsetY),st(-t.angle)),i=new wt(this.color);let s=40,r=40;return t.width&&t.height&&(s=100*Tt((Math.abs(e.x)+this.blur)/t.width,c.NUM_FRACTION_DIGITS)+20,r=100*Tt((Math.abs(e.y)+this.blur)/t.height,c.NUM_FRACTION_DIGITS)+20),t.flipX&&(e.x*=-1),t.flipY&&(e.y*=-1),'<filter id="SVGID_'.concat(this.id,'" y="-').concat(r,'%" height="').concat(100+2*r,'%" x="-').concat(s,'%" width="').concat(100+2*s,'%" >\n\t<feGaussianBlur in="SourceAlpha" stdDeviation="').concat(Tt(this.blur?this.blur/2:0,c.NUM_FRACTION_DIGITS),'"></feGaussianBlur>\n\t<feOffset dx="').concat(Tt(e.x,c.NUM_FRACTION_DIGITS),'" dy="').concat(Tt(e.y,c.NUM_FRACTION_DIGITS),'" result="oBlur" ></feOffset>\n\t<feFlood flood-color="').concat(i.toRgb(),'" flood-opacity="').concat(i.getAlpha(),'"/>\n\t<feComposite in2="oBlur" operator="in" />\n\t<feMerge>\n\t\t<feMergeNode></feMergeNode>\n\t\t<feMergeNode in="SourceGraphic"></feMergeNode>\n\t</feMerge>\n</filter>\n')}toObject(){const t={color:this.color,blur:this.blur,offsetX:this.offsetX,offsetY:this.offsetY,affectStroke:this.affectStroke,nonScaling:this.nonScaling},e=Ke.ownDefaults;return this.includeDefaultValues?t:vt(t,((t,i)=>t!==e[i]))}}s(Ke,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),s(Ke,"reOffsetsAndBlur",/(?:\s|^)(-?\d+(?:\.\d*)?(?:px)?(?:\s?|$))?(-?\d+(?:\.\d*)?(?:px)?(?:\s?|$))?(\d+(?:\.\d*)?(?:px)?)?(?:\s?|$)(?:$|\s)/);const Je=t=>JSON.parse(JSON.stringify(t)),$e=["fill","stroke","strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],Ze={originX:"left",originY:"top",top:0,left:0,width:0,height:0,scaleX:1,scaleY:1,flipX:!1,flipY:!1,opacity:1,angle:0,skewX:0,skewY:0,cornerSize:13,touchCornerSize:24,transparentCorners:!0,hoverCursor:null,moveCursor:null,padding:0,borderColor:"rgb(178,204,255)",borderDashArray:null,cornerColor:"rgb(178,204,255)",cornerStrokeColor:"",cornerStyle:"rect",cornerDashArray:null,centeredScaling:!1,centeredRotation:!0,fill:"rgb(0,0,0)",fillRule:"nonzero",globalCompositeOperation:"source-over",backgroundColor:"",selectionBackgroundColor:"",stroke:null,strokeWidth:1,strokeDashArray:null,strokeDashOffset:0,strokeLineCap:"butt",strokeLineJoin:"miter",strokeMiterLimit:4,shadow:null,borderOpacityWhenMoving:.4,borderScaleFactor:1,minScaleLimit:0,selectable:!0,evented:!0,visible:!0,hasControls:!0,hasBorders:!0,perPixelTargetFind:!1,includeDefaultValues:!0,lockMovementX:!1,lockMovementY:!1,lockRotation:!1,lockScalingX:!1,lockScalingY:!1,lockSkewingX:!1,lockSkewingY:!1,lockScalingFlip:!1,excludeFromExport:!1,objectCaching:!0,noScaleCache:!0,strokeUniform:!1,dirty:!0,paintFirst:"fill",activeOn:"down",colorProperties:["fill","stroke","backgroundColor"],clipPath:void 0,inverted:!1,absolutePositioned:!1,FX_DURATION:500},Qe=["extraParam"];let ti=class extends qe{static getDefaults(){return i({},ti.ownDefaults)}get type(){const t=this.constructor.name;return"FabricObject"===t?"object":t.toLowerCase()}set type(t){console.warn("Setting type has no effect",t)}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(),s(this,"_cacheContext",null),Object.assign(this,this.constructor.getDefaults()),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=tt(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,i=t.height,s=c.maxCacheSideLimit,r=c.minCacheSideLimit;if(e<=s&&i<=s&&e*i<=c.perfLimitSizeTotal)return e<r&&(t.width=r),i<r&&(t.height=r),t;const n=e/i,[o,a]=x.limitDimsByArea(n),h=De(r,o,s),l=De(r,a,s);return e>h&&(t.zoomX/=e/h,t.width=h,t.capped=!0),i>l&&(t.zoomY/=i/l,t.height=l,t.capped=!0),t}_getCacheCanvasDimensions(){const t=this.getTotalObjectScaling(),e=this._getTransformedDimensions({skewX:0,skewY:0}),i=e.x*t.x/this.scaleX,s=e.y*t.y/this.scaleY;return{width:i+2,height:s+2,zoomX:t.x,zoomY:t.y,x:i,y:s}}_updateCacheCanvas(){const t=this._cacheCanvas,e=this._cacheContext,i=this._limitCacheSize(this._getCacheCanvasDimensions()),s=c.minCacheSideLimit,r=i.width,n=i.height,o=i.zoomX,a=i.zoomY,h=r!==this.cacheWidth||n!==this.cacheHeight,l=this.zoomX!==o||this.zoomY!==a;if(!t||!e)return!1;let d,u,g=h||l,f=0,p=0,m=!1;if(h){const t=this._cacheCanvas.width,e=this._cacheCanvas.height,o=r>t||n>e;m=o||(r<.9*t||n<.9*e)&&t>s&&e>s,o&&!i.capped&&(r>s||n>s)&&(f=.1*r,p=.1*n)}return Bt(this)&&this.path&&(g=!0,m=!0,f+=this.getHeightOfLine(0)*this.zoomX,p+=this.getHeightOfLine(0)*this.zoomY),!!g&&(m?(t.width=Math.ceil(r+f),t.height=Math.ceil(n+p)):(e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,t.width,t.height)),d=i.x/2,u=i.y/2,this.cacheTranslationX=Math.round(t.width/2-d)+d,this.cacheTranslationY=Math.round(t.height/2-u)+u,this.cacheWidth=r,this.cacheHeight=n,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(o,a),this.zoomX=o,this.zoomY=a,!0)}setOptions(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this._setOptions(t)}transform(t){const e=this.group&&!this.group._transformDone||this.group&&this.canvas&&t===this.canvas.contextTop,i=this.calcTransformMatrix(!e);t.transform(i[0],i[1],i[2],i[3],i[4],i[5])}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const e=c.NUM_FRACTION_DIGITS,s=this.clipPath&&!this.clipPath.excludeFromExport?i(i({},this.clipPath.toObject(t)),{},{inverted:this.clipPath.inverted,absolutePositioned:this.clipPath.absolutePositioned}):null,r=i(i({},mt(this,t)),{},{type:this.constructor.name,version:y,originX:this.originX,originY:this.originY,left:Tt(this.left,e),top:Tt(this.top,e),width:Tt(this.width,e),height:Tt(this.height,e),fill:Ft(this.fill)?this.fill.toObject():this.fill,stroke:Ft(this.stroke)?this.stroke.toObject():this.stroke,strokeWidth:Tt(this.strokeWidth,e),strokeDashArray:this.strokeDashArray?this.strokeDashArray.concat():this.strokeDashArray,strokeLineCap:this.strokeLineCap,strokeDashOffset:this.strokeDashOffset,strokeLineJoin:this.strokeLineJoin,strokeUniform:this.strokeUniform,strokeMiterLimit:Tt(this.strokeMiterLimit,e),scaleX:Tt(this.scaleX,e),scaleY:Tt(this.scaleY,e),angle:Tt(this.angle,e),flipX:this.flipX,flipY:this.flipY,opacity:Tt(this.opacity,e),shadow:this.shadow&&this.shadow.toObject?this.shadow.toObject():this.shadow,visible:this.visible,backgroundColor:this.backgroundColor,fillRule:this.fillRule,paintFirst:this.paintFirst,globalCompositeOperation:this.globalCompositeOperation,skewX:Tt(this.skewX,e),skewY:Tt(this.skewY,e)},s?{clipPath:s}:null);return this.includeDefaultValues?r:this._removeDefaultValues(r)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),i=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return vt(t,((t,e)=>{if("left"===e||"top"===e||"type"===e)return!0;const s=i[e];return t!==s&&!(Array.isArray(t)&&Array.isArray(s)&&0===t.length&&0===s.length)}))}toString(){return"#<".concat(this.constructor.name,">")}getObjectScaling(){if(!this.group)return new X(Math.abs(this.scaleX),Math.abs(this.scaleY));const t=ct(this.calcTransformMatrix());return new X(Math.abs(t.scaleX),Math.abs(t.scaleY))}getTotalObjectScaling(){const t=this.getObjectScaling();if(this.canvas){const e=this.canvas.getZoom(),i=this.getCanvasRetinaScaling();return t.scalarMultiply(e*i)}return t}getObjectOpacity(){let t=this.opacity;return this.group&&(t*=this.group.getObjectOpacity()),t}_constrainScale(t){return Math.abs(t)<this.minScaleLimit?t<0?-this.minScaleLimit:this.minScaleLimit:0===t?1e-4:t}_set(t,e){const i=this[t]!==e;if("scaleX"!==t&&"scaleY"!==t||(e=this._constrainScale(e)),"scaleX"===t&&e<0?(this.flipX=!this.flipX,e*=-1):"scaleY"===t&&e<0?(this.flipY=!this.flipY,e*=-1):"shadow"!==t||!e||e instanceof Ke?"dirty"===t&&this.group&&this.group.set("dirty",e):e=new Ke(e),this[t]=e,i){const e=this.group&&this.group.isOnACache();this.constructor.cacheProperties.includes(t)?(this.dirty=!0,e&&this.group.set("dirty",!0)):e&&this.constructor.stateProperties.includes(t)&&this.group.set("dirty",!0)}return this}isNotVisible(){return 0===this.opacity||!this.width&&!this.height&&0===this.strokeWidth||!this.visible}render(t){this.isNotVisible()||this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(t.save(),this._setupCompositeOperation(t),this.drawSelectionBackground(t),this.transform(t),this._setOpacity(t),this._setShadow(t),this.shouldCache()?(this.renderCache(),this.drawCacheOnCanvas(t)):(this._removeCacheCanvas(),this.dirty=!1,this.drawObject(t)),t.restore())}drawSelectionBackground(t){}renderCache(t){t=t||{},this._cacheCanvas&&this._cacheContext||this._createCacheCanvas(),this.isCacheDirty()&&this._cacheContext&&(this.drawObject(this._cacheContext,t.forClipping),this.dirty=!1)}_removeCacheCanvas(){this._cacheCanvas=void 0,this._cacheContext=null,this.cacheWidth=0,this.cacheHeight=0}hasStroke(){return this.stroke&&"transparent"!==this.stroke&&0!==this.strokeWidth}hasFill(){return this.fill&&"transparent"!==this.fill}needsItsOwnCache(){return!("stroke"!==this.paintFirst||!this.hasFill()||!this.hasStroke()||"object"!=typeof this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.needsItsOwnCache()||this.objectCaching&&(!this.group||!this.group.isOnACache()),this.ownCaching}willDrawShadow(){return!!this.shadow&&(0!==this.shadow.offsetX||0!==this.shadow.offsetY)}drawClipPathOnCache(t,e){if(t.save(),e.inverted?t.globalCompositeOperation="destination-out":t.globalCompositeOperation="destination-in",e.absolutePositioned){const e=at(this.calcTransformMatrix());t.transform(e[0],e[1],e[2],e[3],e[4],e[5])}e.transform(t),t.scale(1/e.zoomX,1/e.zoomY),t.drawImage(e._cacheCanvas,-e.cacheTranslationX,-e.cacheTranslationY),t.restore()}drawObject(t,e){const i=this.fill,s=this.stroke;e?(this.fill="black",this.stroke="",this._setClippingProperties(t)):this._renderBackground(t),this._render(t),this._drawClipPath(t,this.clipPath),this.fill=i,this.stroke=s}_drawClipPath(t,e){e&&(e._set("canvas",this.canvas),e.shouldCache(),e._transformDone=!0,e.renderCache({forClipping:!0}),this.drawClipPathOnCache(t,e))}drawCacheOnCanvas(t){t.scale(1/this.zoomX,1/this.zoomY),t.drawImage(this._cacheCanvas,-this.cacheTranslationX,-this.cacheTranslationY)}isCacheDirty(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(this.isNotVisible())return!1;if(this._cacheCanvas&&this._cacheContext&&!t&&this._updateCacheCanvas())return!0;if(this.dirty||this.clipPath&&this.clipPath.absolutePositioned){if(this._cacheCanvas&&this._cacheContext&&!t){const t=this.cacheWidth/this.zoomX,e=this.cacheHeight/this.zoomY;this._cacheContext.clearRect(-t/2,-e/2,t,e)}return!0}return!1}_renderBackground(t){if(!this.backgroundColor)return;const e=this._getNonTransformedDimensions();t.fillStyle=this.backgroundColor,t.fillRect(-e.x/2,-e.y/2,e.x,e.y),this._removeShadow(t)}_setOpacity(t){this.group&&!this.group._transformDone?t.globalAlpha=this.getObjectOpacity():t.globalAlpha*=this.opacity}_setStrokeStyles(t,e){const i=e.stroke;i&&(t.lineWidth=e.strokeWidth,t.lineCap=e.strokeLineCap,t.lineDashOffset=e.strokeDashOffset,t.lineJoin=e.strokeLineJoin,t.miterLimit=e.strokeMiterLimit,jt(i)?"percentage"===i.gradientUnits||i.gradientTransform||i.patternTransform?this._applyPatternForTransformedGradient(t,i):(t.strokeStyle=i.toLive(t),this._applyPatternGradientTransform(t,i)):t.strokeStyle=e.stroke)}_setFillStyles(t,e){let{fill:i}=e;i&&(jt(i)?(t.fillStyle=i.toLive(t),this._applyPatternGradientTransform(t,i)):t.fillStyle=i)}_setClippingProperties(t){t.globalAlpha=1,t.strokeStyle="transparent",t.fillStyle="#000000"}_setLineDash(t,e){e&&0!==e.length&&(1&e.length&&e.push(...e),t.setLineDash(e))}_setShadow(t){if(!this.shadow)return;const e=this.shadow,i=this.canvas,s=this.getCanvasRetinaScaling(),[r,,,n]=(null==i?void 0:i.viewportTransform)||T,o=r*s,a=n*s,h=e.nonScaling?new X(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*c.browserShadowBlurConstant*(o+a)*(h.x+h.y)/4,t.shadowOffsetX=e.offsetX*o*h.x,t.shadowOffsetY=e.offsetY*a*h.y}_removeShadow(t){this.shadow&&(t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0)}_applyPatternGradientTransform(t,e){if(!jt(e))return{offsetX:0,offsetY:0};const i=e.gradientTransform||e.patternTransform,s=-this.width/2+e.offsetX||0,r=-this.height/2+e.offsetY||0;return"percentage"===e.gradientUnits?t.transform(this.width,0,0,this.height,s,r):t.transform(1,0,0,1,s,r),i&&t.transform(i[0],i[1],i[2],i[3],i[4],i[5]),{offsetX:s,offsetY:r}}_renderPaintInOrder(t){"stroke"===this.paintFirst?(this._renderStroke(t),this._renderFill(t)):(this._renderFill(t),this._renderStroke(t))}_render(t){}_renderFill(t){this.fill&&(t.save(),this._setFillStyles(t,this),"evenodd"===this.fillRule?t.fill("evenodd"):t.fill(),t.restore())}_renderStroke(t){if(this.stroke&&0!==this.strokeWidth){if(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this.strokeUniform){const e=this.getObjectScaling();t.scale(1/e.x,1/e.y)}this._setLineDash(t,this.strokeDashArray),this._setStrokeStyles(t,this),t.stroke(),t.restore()}}_applyPatternForTransformedGradient(t,e){var i;const s=this._limitCacheSize(this._getCacheCanvasDimensions()),r=tt(),n=this.getCanvasRetinaScaling(),o=s.x/this.scaleX/n,a=s.y/this.scaleY/n;r.width=o,r.height=a;const h=r.getContext("2d");h&&(h.beginPath(),h.moveTo(0,0),h.lineTo(o,0),h.lineTo(o,a),h.lineTo(0,a),h.closePath(),h.translate(o/2,a/2),h.scale(s.zoomX/this.scaleX/n,s.zoomY/this.scaleY/n),this._applyPatternGradientTransform(h,e),h.fillStyle=e.toLive(t),h.fill(),t.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),t.scale(n*this.scaleX/s.zoomX,n*this.scaleY/s.zoomY),t.strokeStyle=null!==(i=h.createPattern(r,"no-repeat"))&&void 0!==i?i:"")}_findCenterFromElement(){return new X(this.left+this.width/2,this.top+this.height/2)}clone(t){const e=this.toObject(t);return this.constructor.fromObject(e)}cloneAsImage(t){const e=this.toCanvasElement(t);return new(M.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const e=Zt(this),i=this.group,s=this.shadow,r=Math.abs,n=t.enableRetinaScaling?Math.max(c.devicePixelRatio,1):1,o=(t.multiplier||1)*n;delete this.group,t.withoutTransform&&$t(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&se(this,this.getViewportTransform());const a=tt(),h=this.getBoundingRect(!0,!0),l=this.shadow,d=new X;if(l){const t=l.blur,e=l.nonScaling?new X(1,1):this.getObjectScaling();d.x=2*Math.round(r(l.offsetX)+t)*r(e.x),d.y=2*Math.round(r(l.offsetY)+t)*r(e.y)}const u=h.width+d.x,g=h.height+d.y;a.width=Math.ceil(u),a.height=Math.ceil(g);const f=new Vt(a,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1});"jpeg"===t.format&&(f.backgroundColor="#fff"),this.setPositionByOrigin(new X(f.width/2,f.height/2),"center","center");const p=this.canvas;f._objects=[this],this.set("canvas",f),this.setCoords();const m=f.toCanvasElement(o||1,t);return this.set("canvas",p),this.shadow=s,i&&(this.group=i),this.set(e),this.setCoords(),f._objects=[],f.destroy(),m}toDataURL(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return it(this.toCanvasElement(t),t.format||"png",t.quality||1)}isType(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];return e.includes(this.constructor.name)||e.includes(this.type)}complexity(){return 1}toJSON(){return this.toObject()}rotate(t){const e=("center"!==this.originX||"center"!==this.originY)&&this.centeredRotation;e&&this._setOriginToCenter(),this.set("angle",t),e&&this._resetOrigin()}setOnGroup(){}_setupCompositeOperation(t){this.globalCompositeOperation&&(t.globalCompositeOperation=this.globalCompositeOperation)}dispose(){P.cancelByTarget(this),this.off(),this._set("canvas",void 0)}static _fromObject(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{extraParam:s}=e,r=n(e,Qe);return pt(Je(t),r).then((t=>{const e=i(i({},r),t);if(s){const{[s]:t,type:i}=e;return new this(t,n(e,[s,"type"].map(a)))}return new this(e)}))}static fromObject(t,e){return this._fromObject(t,e)}};s(ti,"stateProperties",["top","left","scaleX","scaleY","flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible","skewX","skewY"]),s(ti,"cacheProperties",$e),s(ti,"ownDefaults",Ze),M.setClass(ti),M.setClass(ti,"object");const ei=(t,e)=>(i,s,r,n)=>{const o=e(i,s,r,n);return o&&re(t,de(i,s,r,n)),o};function ii(t){return(e,i,s,r)=>{const{target:n,originX:o,originY:a}=i,h=n.getRelativeCenterPoint(),c=n.translateToOriginPoint(h,o,a),l=t(e,i,s,r);return n.setPositionByOrigin(c,o,a),l}}const si=ei("resizing",ii(((t,e,i,s)=>{const r=ge(e,e.originX,e.originY,i,s);if("center"===e.originX||"right"===e.originX&&r.x<0||"left"===e.originX&&r.x>0){const{target:t}=e,i=t.strokeWidth/(t.strokeUniform?t.scaleX:1),s=he(e)?2:1,n=t.width,o=Math.ceil(Math.abs(r.x*s/t.scaleX)-i);return t.set("width",Math.max(o,0)),n!==t.width}return!1})));function ri(t,e,i,s,r){s=s||{};const n=this.sizeX||s.cornerSize||r.cornerSize,o=this.sizeY||s.cornerSize||r.cornerSize,a=void 0!==s.transparentCorners?s.transparentCorners:r.transparentCorners,h=a?"stroke":"fill",c=!a&&(s.cornerStrokeColor||r.cornerStrokeColor);let l,d=e,u=i;t.save(),t.fillStyle=s.cornerColor||r.cornerColor||"",t.strokeStyle=s.cornerStrokeColor||r.cornerStrokeColor||"",n>o?(l=n,t.scale(1,o/n),u=i*n/o):o>n?(l=o,t.scale(n/o,1),d=e*o/n):l=n,t.lineWidth=1,t.beginPath(),t.arc(d,u,l/2,0,S,!1),t[h](),c&&t.stroke(),t.restore()}function ni(t,e,i,s,r){s=s||{};const n=this.sizeX||s.cornerSize||r.cornerSize,o=this.sizeY||s.cornerSize||r.cornerSize,a=void 0!==s.transparentCorners?s.transparentCorners:r.transparentCorners,h=a?"stroke":"fill",c=!a&&(s.cornerStrokeColor||r.cornerStrokeColor),l=n/2,d=o/2;t.save(),t.fillStyle=s.cornerColor||r.cornerColor||"",t.strokeStyle=s.cornerStrokeColor||r.cornerStrokeColor||"",t.lineWidth=1,t.translate(e,i);const u=r.getTotalAngle();t.rotate(st(u)),t["".concat(h,"Rect")](-l,-d,n,o),c&&t.strokeRect(-l,-d,n,o),t.restore()}class oi{constructor(t){s(this,"visible",!0),s(this,"actionName","scale"),s(this,"angle",0),s(this,"x",0),s(this,"y",0),s(this,"offsetX",0),s(this,"offsetY",0),s(this,"sizeX",null),s(this,"sizeY",null),s(this,"touchSizeX",null),s(this,"touchSizeY",null),s(this,"cursorStyle","crosshair"),s(this,"withConnection",!1),Object.assign(this,t)}getActionHandler(t,e,i){return this.actionHandler}getMouseDownHandler(t,e,i){return this.mouseDownHandler}getMouseUpHandler(t,e,i){return this.mouseUpHandler}cursorStyleHandler(t,e,i){return e.cursorStyle}getActionName(t,e,i){return e.actionName}getVisibility(t,e){var i,s;return null!==(i=null===(s=t._controlsVisibility)||void 0===s?void 0:s[e])&&void 0!==i?i:this.visible}setVisibility(t,e,i){this.visible=t}positionHandler(t,e,i,s){return new X(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,i,s,r){let n,o,a,h;const c=r?this.touchSizeX:this.sizeX,l=r?this.touchSizeY:this.sizeY;if(c&&l&&c!==l){const e=Math.atan2(l,c),i=Math.sqrt(c*c+l*l)/2,s=e-st(t),r=b-e-st(t);n=i*B(s),o=i*I(s),a=i*B(r),h=i*I(r)}else{const i=(c&&l?c:e)*Math.SQRT1_2,s=st(45-t);n=a=i*B(s),o=h=i*I(s)}return{tl:new X(i-h,s-a),tr:new X(i+n,s-o),bl:new X(i-n,s+o),br:new X(i+h,s+a)}}render(t,e,i,s,r){if("circle"===((s=s||{}).cornerStyle||r.cornerStyle))ri.call(this,t,e,i,s,r);else ni.call(this,t,e,i,s,r)}}const ai=(t,e,i)=>i.lockRotation?ae:e.cursorStyle,hi=ei("rotating",ii(((t,e,i,s)=>{let{target:r,ex:n,ey:o,theta:a,originX:h,originY:c}=e;const l=r.translateToOriginPoint(r.getRelativeCenterPoint(),h,c);if(le(r,"lockRotation"))return!1;const d=Math.atan2(o-l.y,n-l.x),u=Math.atan2(s-l.y,i-l.x);let g=rt(u-d+a);if(r.snapAngle&&r.snapAngle>0){const t=r.snapAngle,e=r.snapThreshold||t,i=Math.ceil(g/t)*t,s=Math.floor(g/t)*t;Math.abs(g-s)<e?g=s:Math.abs(g-i)<e&&(g=i)}g<0&&(g=360+g),g%=360;const f=r.angle!==g;return r.angle=g,f})));function ci(t,e){const i=e.canvas,s=t[i.uniScaleKey];return i.uniformScaling&&!s||!i.uniformScaling&&s}function li(t,e,i){const s=le(t,"lockScalingX"),r=le(t,"lockScalingY");return!(!s||!r)||(!(e||!s&&!r||!i)||(!(!s||"x"!==e)||!(!r||"y"!==e)))}const di=["e","se","s","sw","w","nw","n","ne","e"],ui=(t,e,i)=>{const s=ci(t,i);if(li(i,0!==e.x&&0===e.y?"x":0===e.x&&0!==e.y?"y":"",s))return ae;const r=ue(i,e);return"".concat(di[r],"-resize")};function gi(t,e,i,s){let r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};const n=e.target,o=r.by,a=ci(t,n);let h,c,l,d,u,g;if(li(n,o,a))return!1;if(e.gestureScale)c=e.scaleX*e.gestureScale,l=e.scaleY*e.gestureScale;else{if(h=ge(e,e.originX,e.originY,i,s),u="y"!==o?Math.sign(h.x||e.signX||1):1,g="x"!==o?Math.sign(h.y||e.signY||1):1,e.signX||(e.signX=u),e.signY||(e.signY=g),le(n,"lockScalingFlip")&&(e.signX!==u||e.signY!==g))return!1;if(d=n._getTransformedDimensions(),a&&!o){const t=Math.abs(h.x)+Math.abs(h.y),{original:i}=e,s=t/(Math.abs(d.x*i.scaleX/n.scaleX)+Math.abs(d.y*i.scaleY/n.scaleY));c=i.scaleX*s,l=i.scaleY*s}else c=Math.abs(h.x*n.scaleX/d.x),l=Math.abs(h.y*n.scaleY/d.y);he(e)&&(c*=2,l*=2),e.signX!==u&&"y"!==o&&(e.originX=ce(e.originX),c*=-1,e.signX=u),e.signY!==g&&"x"!==o&&(e.originY=ce(e.originY),l*=-1,e.signY=g)}const f=n.scaleX,p=n.scaleY;return o?("x"===o&&n.set("scaleX",c),"y"===o&&n.set("scaleY",l)):(!le(n,"lockScalingX")&&n.set("scaleX",c),!le(n,"lockScalingY")&&n.set("scaleY",l)),f!==n.scaleX||p!==n.scaleY}const fi=ei("scaling",ii(((t,e,i,s)=>gi(t,e,i,s)))),pi=ei("scaling",ii(((t,e,i,s)=>gi(t,e,i,s,{by:"x"})))),mi=ei("scaling",ii(((t,e,i,s)=>gi(t,e,i,s,{by:"y"})))),vi=["target","ex","ey","skewingSide"],_i={x:{counterAxis:"y",scale:"scaleX",skew:"skewX",lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:"scaleY",skew:"skewY",lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},xi=["ns","nesw","ew","nwse"],yi=(t,e,i)=>{if(0!==e.x&&le(i,"lockSkewingY"))return ae;if(0!==e.y&&le(i,"lockSkewingX"))return ae;const s=ue(i,e)%4;return"".concat(xi[s],"-resize")};function Ci(t,e,s,r,o){const{target:a}=s,{counterAxis:h,origin:c,lockSkewing:l,skew:d,flip:u}=_i[t];if(le(a,l))return!1;const{origin:g,flip:f}=_i[h],p=oe(s[g])*(a[f]?-1:1),m=-Math.sign(p)*(a[u]?-1:1),v=.5*-((0===a[d]&&ge(s,"center","center",r,o)[t]>0||a[d]>0?1:-1)*m)+.5,_=ei("skewing",ii(((e,i,s,r)=>function(t,e,i){let{target:s,ex:r,ey:o,skewingSide:a}=e,h=n(e,vi);const{skew:c}=_i[t],l=i.subtract(new X(r,o)).divide(new X(s.scaleX,s.scaleY))[t],d=s[c],u=h[c],g=Math.tan(st(u)),f="y"===t?s._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:s._getTransformedDimensions({scaleX:1,scaleY:1}).y,p=2*l*a/Math.max(f,1)+g,m=rt(Math.atan(p));s.set(c,m);const v=d!==s[c];if(v&&"y"===t){const{skewX:t,scaleX:e}=s,i=s._getTransformedDimensions({skewY:d}),r=s._getTransformedDimensions(),n=0!==t?i.x/r.x:1;1!==n&&s.set("scaleX",n*e)}return v}(t,i,new X(s,r)))));return _(e,i(i({},s),{},{[c]:v,skewingSide:m}),r,o)}const bi=(t,e,i,s)=>Ci("x",t,e,i,s),Si=(t,e,i,s)=>Ci("y",t,e,i,s);function wi(t,e){return t[e.canvas.altActionKey]}const Ti=(t,e,i)=>{const s=wi(t,i);return 0===e.x?s?"skewX":"scaleY":0===e.y?s?"skewY":"scaleX":""},Oi=(t,e,i)=>wi(t,i)?yi(0,e,i):ui(t,e,i),ki=(t,e,i,s)=>wi(t,e.target)?Si(t,e,i,s):pi(t,e,i,s),Di=(t,e,i,s)=>wi(t,e.target)?bi(t,e,i,s):mi(t,e,i,s),Ei=()=>({ml:new oi({x:-.5,y:0,cursorStyleHandler:Oi,actionHandler:ki,getActionName:Ti}),mr:new oi({x:.5,y:0,cursorStyleHandler:Oi,actionHandler:ki,getActionName:Ti}),mb:new oi({x:0,y:.5,cursorStyleHandler:Oi,actionHandler:Di,getActionName:Ti}),mt:new oi({x:0,y:-.5,cursorStyleHandler:Oi,actionHandler:Di,getActionName:Ti}),tl:new oi({x:-.5,y:-.5,cursorStyleHandler:ui,actionHandler:fi}),tr:new oi({x:.5,y:-.5,cursorStyleHandler:ui,actionHandler:fi}),bl:new oi({x:-.5,y:.5,cursorStyleHandler:ui,actionHandler:fi}),br:new oi({x:.5,y:.5,cursorStyleHandler:ui,actionHandler:fi}),mtr:new oi({x:0,y:-.5,actionHandler:hi,cursorStyleHandler:ai,offsetY:-40,withConnection:!0,actionName:"rotate"})}),Mi=()=>({mr:new oi({x:.5,y:0,actionHandler:si,cursorStyleHandler:Oi,actionName:"resizing"}),ml:new oi({x:-.5,y:0,actionHandler:si,cursorStyleHandler:Oi,actionName:"resizing"})}),Pi=()=>i(i({},Ei()),Mi());class Ai extends ti{static getDefaults(){return i(i({},super.getDefaults()),{},{controls:Ei()},Ai.ownDefaults)}_updateCacheCanvas(){const t=this.canvas;if(this.noScaleCache&&t&&t._currentTransform){const e=t._currentTransform.target,i=t._currentTransform.action;if(this===e&&i.startsWith("scale"))return!1}return super._updateCacheCanvas()}_findTargetCorner(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!this.hasControls||!this.canvas||this.canvas._activeObject!==this)return 0;this.__corner=void 0;const i=Object.entries(this.oCoords);for(let s=i.length-1;s>=0;s--){const[r,n]=i[s];if(!this.isControlVisible(r))continue;const o=this._getImageLines(e?n.touchCorner:n.corner),a=this._findCrossPoints(t,o);if(0!==a&&a%2==1)return this.__corner=r,r}return 0}calcOCoords(){const t=this.getViewportTransform(),e=this.getCenterPoint(),i=[1,0,0,1,e.x,e.y],s=lt({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),r=ht(i,s),n=ht(t,r),o=ht(n,[1/t[0],0,0,1/t[3],0,0]),a=this.group?ct(this.calcTransformMatrix()):void 0,h=this._calculateCurrentDimensions(a),c={};return this.forEachControl(((t,e)=>{const i=t.positionHandler(h,o,this,t);c[e]=Object.assign(i,this._calcCornerCoords(t,i))})),c}_calcCornerCoords(t,e){return{corner:t.calcCornerCoords(this.angle,this.cornerSize,e.x,e.y,!1),touchCorner:t.calcCornerCoords(this.angle,this.touchCornerSize,e.x,e.y,!0)}}setCoords(){super.setCoords(),this.oCoords=this.calcOCoords()}forEachControl(t){for(const e in this.controls)t(this.controls[e],e,this)}drawSelectionBackground(t){if(!this.selectionBackgroundColor||this.canvas&&!this.canvas.interactive||this.canvas&&this.canvas._activeObject!==this)return;t.save();const e=this.getRelativeCenterPoint(),i=this._calculateCurrentDimensions(),s=this.getViewportTransform();t.translate(e.x,e.y),t.scale(1/s[0],1/s[3]),t.rotate(st(this.angle)),t.fillStyle=this.selectionBackgroundColor,t.fillRect(-i.x/2,-i.y/2,i.x,i.y),t.restore()}strokeBorders(t,e){t.strokeRect(-e.x/2,-e.y/2,e.x,e.y)}_drawBorders(t,e){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const r=i({hasControls:this.hasControls,borderColor:this.borderColor,borderDashArray:this.borderDashArray},s);t.save(),t.strokeStyle=r.borderColor,this._setLineDash(t,r.borderDashArray),this.strokeBorders(t,e),r.hasControls&&this.drawControlsConnectingLines(t,e),t.restore()}_renderControls(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{hasBorders:s,hasControls:r}=this,n=i({hasBorders:s,hasControls:r},e),o=this.getViewportTransform(),a=n.hasBorders,h=n.hasControls,c=ht(o,this.calcTransformMatrix()),l=ct(c);t.save(),t.translate(l.translateX,l.translateY),t.lineWidth=1*this.borderScaleFactor,this.group||(t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1),this.flipX&&(l.angle-=180),t.rotate(st(this.group?l.angle:this.angle)),a&&this.drawBorders(t,l,e),h&&this.drawControls(t,e),t.restore()}drawBorders(t,e,i){let s;if(i&&i.forActiveSelection||this.group){const t=Qt(this.width,this.height,e),i=(this.strokeUniform?(new X).scalarAdd(this.canvas?this.canvas.getZoom():1):new X(e.scaleX,e.scaleY)).scalarMultiply(this.strokeWidth);s=t.add(i).scalarAdd(this.borderScaleFactor)}else s=this._calculateCurrentDimensions().scalarAdd(this.borderScaleFactor);this._drawBorders(t,s,i)}drawControlsConnectingLines(t,e){let i=!1;t.beginPath(),this.forEachControl(((s,r)=>{s.withConnection&&s.getVisibility(this,r)&&(i=!0,t.moveTo(s.x*e.x,s.y*e.y),t.lineTo(s.x*e.x+s.offsetX,s.y*e.y+s.offsetY))})),i&&t.stroke()}drawControls(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t.save();const s=this.getCanvasRetinaScaling(),{cornerStrokeColor:r,cornerDashArray:n,cornerColor:o}=this,a=i({cornerStrokeColor:r,cornerDashArray:n,cornerColor:o},e);t.setTransform(s,0,0,s,0,0),t.strokeStyle=t.fillStyle=a.cornerColor,this.transparentCorners||(t.strokeStyle=a.cornerStrokeColor),this._setLineDash(t,a.cornerDashArray),this.setCoords(),this.forEachControl(((e,i)=>{if(e.getVisibility(this,i)){const s=this.oCoords[i];e.render(t,s.x,s.y,a,this)}})),t.restore()}isControlVisible(t){return this.controls[t]&&this.controls[t].getVisibility(this,t)}setControlVisible(t,e){this._controlsVisibility||(this._controlsVisibility={}),this._controlsVisibility[t]=e}setControlsVisibility(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};Object.entries(t).forEach((t=>{let[e,i]=t;return this.setControlVisible(e,i)}))}clearContextTop(t){if(!this.canvas)return;const e=this.canvas.contextTop;if(!e)return;const i=this.canvas.viewportTransform;e.save(),e.transform(i[0],i[1],i[2],i[3],i[4],i[5]),this.transform(e);const s=this.width+4,r=this.height+4;return e.clearRect(-s/2,-r/2,s,r),t||e.restore(),e}onDeselect(t){return!1}onSelect(t){return!1}canDrop(t){return!1}renderDragSourceEffect(t){}renderDropTargetEffect(t){}}function ji(t,e){return e.forEach((e=>{Object.getOwnPropertyNames(e.prototype).forEach((i=>{"constructor"!==i&&Object.defineProperty(t.prototype,i,Object.getOwnPropertyDescriptor(e.prototype,i)||Object.create(null))}))})),t}s(Ai,"ownDefaults",{});class Fi extends Ai{}ji(Fi,[pe]),M.setClass(Fi),M.setClass(Fi,"object");const Li=(t,e,i,s)=>{const r=2*(s=Math.round(s))+1,{data:n}=t.getImageData(e-s,i-s,r,r);for(let t=3;t<n.length;t+=4){if(n[t]>0)return!1}return!0};function Ri(t,e){const i=t.style;i&&("string"==typeof e?t.style.cssText+=";"+e:Object.entries(e).forEach((t=>{let[e,s]=t;return i.setProperty(e,s)})))}const Bi=["display","transform","fill","fill-opacity","fill-rule","opacity","stroke","stroke-dasharray","stroke-linecap","stroke-dashoffset","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","id","paint-order","vector-effect","instantiated_by_use","clip-path"];function Ii(t){return new RegExp("^("+t.join("|")+")\\b","i")}var Xi;const Yi={},Wi={},Vi={},Gi={cssRules:Yi,gradientDefs:Wi,clipPaths:Vi},zi="(?:[-+]?(?:\\d+|\\d*\\.\\d+)(?:[eE][-+]?\\d+)?)",Hi="http://www.w3.org/2000/svg",Ui=String.raw(Xi||(Xi=o(["(?:s+,?s*|,s*|$)"],["(?:\\s+,?\\s*|,\\s*|$)"]))),Ni=new RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+zi+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+zi+"))?\\s+(.*)"),qi={cx:"left",x:"left",r:"radius",cy:"top",y:"top",display:"visible",visibility:"visible",transform:"transformMatrix","fill-opacity":"fillOpacity","fill-rule":"fillRule","font-family":"fontFamily","font-size":"fontSize","font-style":"fontStyle","font-weight":"fontWeight","letter-spacing":"charSpacing","paint-order":"paintFirst","stroke-dasharray":"strokeDashArray","stroke-dashoffset":"strokeDashOffset","stroke-linecap":"strokeLineCap","stroke-linejoin":"strokeLineJoin","stroke-miterlimit":"strokeMiterLimit","stroke-opacity":"strokeOpacity","stroke-width":"strokeWidth","text-decoration":"textDecoration","text-anchor":"textAnchor",opacity:"opacity","clip-path":"clipPath","clip-rule":"clipRule","vector-effect":"strokeUniform","image-rendering":"imageSmoothing"},Ki={stroke:"strokeOpacity",fill:"fillOpacity"},Ji="font-size",$i="clip-path",Zi=Ii(["path","circle","polygon","polyline","ellipse","rect","line","image","text"]),Qi=Ii(["symbol","image","marker","pattern","view","svg"]),ts=Ii(["pattern","defs","symbol","metadata","clipPath","mask","desc"]),es=Ii(["symbol","g","a","svg","clipPath","defs"]),is=new RegExp("^\\s*("+zi+"+)\\s*,?\\s*("+zi+"+)\\s*,?\\s*("+zi+"+)\\s*,?\\s*("+zi+"+)\\s*$");function ss(t,e){const i=t.nodeName,s=t.getAttribute("class"),r=t.getAttribute("id");let n;if(n=new RegExp("^"+i,"i"),e=e.replace(n,""),r&&e.length&&(n=new RegExp("#"+r+"(?![a-zA-Z\\-]+)","i"),e=e.replace(n,"")),s&&e.length){const t=s.split(" ");for(let i=t.length;i--;)n=new RegExp("\\."+t[i]+"(?![a-zA-Z\\-]+)","i"),e=e.replace(n,"")}return 0===e.length}function rs(t,e){let i=!0;const s=ss(t,e.pop());return s&&e.length&&(i=function(t,e){let i,s=!0;for(;t.parentNode&&1===t.parentNode.nodeType&&e.length;)s&&(i=e.pop()),s=ss(t=t.parentNode,i);return 0===e.length}(t,e)),s&&i&&0===e.length}function ns(t){return t in qi?qi[t]:t}function os(t,e,i){t[i]=Math.tan(st(e[0]))}const as="(?:"+("(?:(matrix)\\s*\\(\\s*("+zi+")"+Ui+"("+zi+")"+Ui+"("+zi+")"+Ui+"("+zi+")"+Ui+"("+zi+")"+Ui+"("+zi+")\\s*\\))")+"|"+("(?:(translate)\\s*\\(\\s*("+zi+")(?:"+Ui+"("+zi+"))?\\s*\\))")+"|"+("(?:(scale)\\s*\\(\\s*("+zi+")(?:"+Ui+"("+zi+"))?\\s*\\))")+"|"+("(?:(rotate)\\s*\\(\\s*("+zi+")(?:"+Ui+"("+zi+")"+Ui+"("+zi+"))?\\s*\\))")+"|"+("(?:(skewX)\\s*\\(\\s*("+zi+")\\s*\\))")+"|"+("(?:(skewY)\\s*\\(\\s*("+zi+")\\s*\\))")+")",hs=new RegExp("^\\s*(?:"+("(?:"+as+"(?:"+Ui+"*"+as+")*)")+"?)\\s*$"),cs=new RegExp(as,"g");function ls(t){let e=T.concat();const i=[];if(!t||t&&!hs.test(t))return e;t.replace(cs,(function(t){const s=new RegExp(as).exec(t).filter((function(t){return!!t})),r=s[1],n=s.slice(2).map(parseFloat);switch(r){case"translate":!function(t,e){t[4]=e[0],2===e.length&&(t[5]=e[1])}(e,n);break;case"rotate":n[0]=st(n[0]),function(t,e){const i=B(e[0]),s=I(e[0]);let r=0,n=0;3===e.length&&(r=e[1],n=e[2]),t[0]=i,t[1]=s,t[2]=-s,t[3]=i,t[4]=r-(i*r-s*n),t[5]=n-(s*r+i*n)}(e,n);break;case"scale":!function(t,e){const i=e[0],s=2===e.length?e[1]:e[0];t[0]=i,t[3]=s}(e,n);break;case"skewX":os(e,n,2);break;case"skewY":os(e,n,1);break;case"matrix":e=n}i.push(e.concat()),e=T.concat()}));let s=i[0];for(;i.length>1;)i.shift(),s=ht(s,i[0]);return s}function ds(t,e,i,s){const r=Array.isArray(e);let n;if("fill"!==t&&"stroke"!==t||"none"!==e){if("strokeUniform"===t)return"non-scaling-stroke"===e;if("strokeDashArray"===t)e="none"===e?null:e.replace(/,/g," ").split(/\s+/).map(parseFloat);else if("transformMatrix"===t)e=i&&i.transformMatrix?ht(i.transformMatrix,ls(e)):ls(e);else if("visible"===t)e="none"!==e&&"hidden"!==e,i&&!1===i.visible&&(e=!1);else if("opacity"===t)e=parseFloat(e),i&&void 0!==i.opacity&&(e*=i.opacity);else if("textAnchor"===t)e="start"===e?"left":"end"===e?"right":"center";else if("charSpacing"===t)n=Ot(e,s)/s*1e3;else if("paintFirst"===t){const t=e.indexOf("fill"),i=e.indexOf("stroke");e="fill",(t>-1&&i>-1&&i<t||-1===t&&i>-1)&&(e="stroke")}else{if("href"===t||"xlink:href"===t||"font"===t)return e;if("imageSmoothing"===t)return"optimizeQuality"===e;n=r?e.map(Ot):Ot(e,s)}}else e="";return!r&&isNaN(n)?e:n}function us(t,e){const i=t.match(Ni);if(!i)return;const s=i[1],r=i[3],n=i[4],o=i[5],a=i[6];s&&(e.fontStyle=s),r&&(e.fontWeight=isNaN(parseFloat(r))?r:parseFloat(r)),n&&(e.fontSize=Ot(n)),a&&(e.fontFamily=a),o&&(e.lineHeight="normal"===o?1:o)}function gs(t){const e={},i=t.getAttribute("style");return i?("string"==typeof i?function(t,e){let i,s;t.replace(/;\s*$/,"").split(";").forEach((function(t){const r=t.split(":");i=r[0].trim().toLowerCase(),s=r[1].trim(),e[i]=s}))}(i,e):function(t,e){let i,s;for(const r in t)void 0!==t[r]&&(i=r.toLowerCase(),s=t[r],e[i]=s)}(i,e),e):e}function fs(t,e,s){if(!t)return{};let r,n,o,a={};void 0===s&&(s=t.getAttribute("svgUid")),t.parentNode&&es.test(t.parentNode.nodeName)&&(a=fs(t.parentNode,e,s));let h=e.reduce((function(e,i){return r=t.getAttribute(i),r&&(e[i]=r),e}),{});const c=Object.assign(function(t,e){const i={};for(const s in Yi[e])if(rs(t,s.split(" ")))for(const t in Yi[e][s])i[t]=Yi[e][s][t];return i}(t,s),gs(t));h=Object.assign(h,c),c[$i]&&t.setAttribute($i,c[$i]),n=o=a.fontSize||O,h[Ji]&&(h[Ji]=n=Ot(h[Ji],o));const l={};for(const t in h){const e=ns(t),i=ds(e,h[t],a,n);l[e]=i}l&&l.font&&us(l.font,l);const d=i(i({},a),l);return es.test(t.nodeName)?d:function(t){for(const e in Ki){if(void 0===t[Ki[e]]||""===t[e])continue;const i=Fi.getDefaults();if(void 0===t[e]){if(!i[e])continue;t[e]=i[e]}if(0===t[e].indexOf("url("))continue;const s=new wt(t[e]);t[e]=s.setAlpha(Tt(s.getAlpha()*t[Ki[e]],2)).toRgba()}return t}(d)}const ps=["left","top","width","height","visible"],ms=["rx","ry"];class vs extends Fi{static getDefaults(){return i(i({},super.getDefaults()),vs.ownDefaults)}constructor(t){super(t),this._initRxRy()}_initRxRy(){const{rx:t,ry:e}=this;t&&!e?this.ry=t:e&&!t&&(this.rx=e)}_render(t){const{width:e,height:i}=this,s=-e/2,r=-i/2,n=this.rx?Math.min(this.rx,e/2):0,o=this.ry?Math.min(this.ry,i/2):0,a=0!==n||0!==o;t.beginPath(),t.moveTo(s+n,r),t.lineTo(s+e-n,r),a&&t.bezierCurveTo(s+e-k*n,r,s+e,r+k*o,s+e,r+o),t.lineTo(s+e,r+i-o),a&&t.bezierCurveTo(s+e,r+i-k*o,s+e-k*n,r+i,s+e-n,r+i),t.lineTo(s+n,r+i),a&&t.bezierCurveTo(s+k*n,r+i,s,r+i-k*o,s,r+i-o),t.lineTo(s,r+o),a&&t.bezierCurveTo(s,r+k*o,s+k*n,r,s+n,r),t.closePath(),this._renderPaintInOrder(t)}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return super.toObject([...ms,...t])}_toSVG(){const{width:t,height:e,rx:i,ry:s}=this;return["<rect ","COMMON_PARTS",'x="'.concat(-t/2,'" y="').concat(-e/2,'" rx="').concat(i,'" ry="').concat(s,'" width="').concat(t,'" height="').concat(e,'" />\n')]}static fromElement(t,e){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!t)return e(null);const r=fs(t,this.ATTRIBUTE_NAMES),{left:o=0,top:a=0,width:h=0,height:c=0,visible:l=!0}=r,d=n(r,ps);e(new this(i(i(i({},s),d),{},{left:o,top:a,width:h,height:c,visible:Boolean(l&&h&&c)})))}}s(vs,"cacheProperties",[...$e,...ms]),s(vs,"ownDefaults",{rx:0,ry:0}),s(vs,"ATTRIBUTE_NAMES",[...Bi,"x","y","rx","ry","width","height"]),M.setClass(vs),M.setSVGClass(vs);const _s=["objects"];class xs extends(W(Fi)){static getDefaults(){return i(i({},super.getDefaults()),xs.ownDefaults)}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0;super(),s(this,"_activeObjects",[]),s(this,"__objectSelectionTracker",void 0),s(this,"__objectSelectionDisposer",void 0),s(this,"_firstLayoutDone",!1),this._objects=t,this.__objectMonitor=this.__objectMonitor.bind(this),this.__objectSelectionTracker=this.__objectSelectionMonitor.bind(this,!0),this.__objectSelectionDisposer=this.__objectSelectionMonitor.bind(this,!1),this.set(i(i({},e),{},{angle:0,skewX:0,skewY:0})),this.forEachObject((t=>{this.enterGroup(t,!1)})),this._applyLayoutStrategy({type:"initialization",options:e,objectsRelativeToGroup:r})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(console.error("fabric.Group: circular object trees are not supported, this call has no effect"),!1):-1===this._objects.indexOf(t)||(console.error("fabric.Group: duplicate objects are not supported inside group, this call has no effect"),!1)}_filterObjectsBeforeEnteringGroup(t){return t.filter(((t,e,i)=>this.canEnterGroup(t)&&i.indexOf(t)===e))}add(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];const s=this._filterObjectsBeforeEnteringGroup(e),r=super.add(...s);return this._onAfterObjectsChange("added",s),r}insertAt(t){for(var e=arguments.length,i=new Array(e>1?e-1:0),s=1;s<e;s++)i[s-1]=arguments[s];const r=this._filterObjectsBeforeEnteringGroup(i),n=super.insertAt(t,...r);return this._onAfterObjectsChange("added",r),n}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange("removed",t),t}_onObjectAdded(t){this.enterGroup(t,!0),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onRelativeObjectAdded(t){this.enterGroup(t,!1),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onObjectRemoved(t,e){this.exitGroup(t,e),this.fire("object:removed",{target:t}),t.fire("removed",{target:this})}_onAfterObjectsChange(t,e){this._applyLayoutStrategy({type:t,targets:e}),this._set("dirty",!0)}_onStackOrderChanged(){this._set("dirty",!0)}_set(t,e){const i=this[t];return super._set(t,e),"canvas"===t&&i!==e&&this.forEachObject((i=>{i._set(t,e)})),"layout"===t&&i!==e&&this._applyLayoutStrategy({type:"layout_change",layout:e,prevLayout:i}),"interactive"===t&&this.forEachObject((t=>this._watchObject(e,t))),this}_shouldSetNestedCoords(){return this.subTargetCheck}removeAll(){return this._activeObjects=[],this.remove(...this._objects)}__objectMonitor(t){this._applyLayoutStrategy(i(i({},t),{},{type:"object_modified"})),this._set("dirty",!0)}__objectSelectionMonitor(t,e){let{target:i}=e;if(t)this._activeObjects.push(i),this._set("dirty",!0);else if(this._activeObjects.length>0){const t=this._activeObjects.indexOf(i);t>-1&&(this._activeObjects.splice(t,1),this._set("dirty",!0))}}_watchObject(t,e){const i=t?"on":"off";t&&this._watchObject(!1,e),e[i]("changed",this.__objectMonitor),e[i]("modified",this.__objectMonitor),e[i]("selected",this.__objectSelectionTracker),e[i]("deselected",this.__objectSelectionDisposer)}enterGroup(t,e){return t.group&&t.group.remove(t),this._enterGroup(t,e),!0}_enterGroup(t,e){e&&Jt(t,ht(at(this.calcTransformMatrix()),t.calcTransformMatrix())),this._shouldSetNestedCoords()&&t.setCoords(),t._set("group",this),t._set("canvas",this.canvas),this.interactive&&this._watchObject(!0,t);const i=this.canvas&&this.canvas.getActiveObject&&this.canvas.getActiveObject();i&&(i===t||t.isDescendantOf(i))&&this._activeObjects.push(t)}exitGroup(t,e){this._exitGroup(t,e),t._set("canvas",void 0)}_exitGroup(t,e){t._set("group",void 0),e||(Jt(t,ht(this.calcTransformMatrix(),t.calcTransformMatrix())),t.setCoords()),this._watchObject(!1,t);const i=this._activeObjects.length>0?this._activeObjects.indexOf(t):-1;i>-1&&this._activeObjects.splice(i,1)}shouldCache(){const t=Fi.prototype.shouldCache.call(this);if(t)for(let t=0;t<this._objects.length;t++)if(this._objects[t].willDrawShadow())return this.ownCaching=!1,!1;return t}willDrawShadow(){if(Fi.prototype.willDrawShadow.call(this))return!0;for(let t=0;t<this._objects.length;t++)if(this._objects[t].willDrawShadow())return!0;return!1}isOnACache(){return this.ownCaching||!!this.group&&this.group.isOnACache()}drawObject(t){this._renderBackground(t);for(let i=0;i<this._objects.length;i++){var e;null!==(e=this.canvas)&&void 0!==e&&e.preserveObjectStacking&&this._objects[i].group!==this?(t.save(),t.transform(...at(this.calcTransformMatrix())),this._objects[i].render(t),t.restore()):this._objects[i].group===this&&this._objects[i].render(t)}this._drawClipPath(t,this.clipPath)}setCoords(){super.setCoords(),this._shouldSetNestedCoords()&&this.forEachObject((t=>t.setCoords()))}render(t){this._transformDone=!0,super.render(t),this._transformDone=!1}triggerLayout(t){t&&t.layout&&(t.prevLayout=this.layout,this.layout=t.layout),this._applyLayoutStrategy({type:"imperative",context:t})}_adjustObjectPosition(t,e){t.set({left:t.left+e.x,top:t.top+e.y})}_applyLayoutStrategy(t){const e="initialization"===t.type;if(!e&&!this._firstLayoutDone)return;const i=e&&t.options,s=i&&{angle:i.angle||0,skewX:i.skewX||0,skewY:i.skewY||0},r=this.getRelativeCenterPoint();let n,o=this.getLayoutStrategyResult(this.layout,[...this._objects],t);if(o){const i=new X(o.centerX,o.centerY),a=r.subtract(i).add(new X(o.correctionX||0,o.correctionY||0));n=a.transform(at(this.calcOwnMatrix()),!0),this.set({width:o.width,height:o.height}),!t.objectsRelativeToGroup&&this.forEachObject((t=>{t.group===this&&this._adjustObjectPosition(t,n)})),!e&&"clip-path"!==this.layout&&this.clipPath&&!this.clipPath.absolutePositioned&&this._adjustObjectPosition(this.clipPath,n),i.eq(r)&&!s||(this.setPositionByOrigin(i,"center","center"),s&&this.set(s),this.setCoords())}else{if(!e)return;o={centerX:r.x,centerY:r.y,width:this.width,height:this.height},s&&this.set(s),n=new X}this._firstLayoutDone=!0,this.onLayout(t,o),this.fire("layout",{context:t,result:o,diff:n}),this.group&&this.group._applyLayoutStrategy&&(t.path||(t.path=[]),t.path.push(this),this.group._applyLayoutStrategy(t))}getLayoutStrategyResult(t,e,i){if("fit-content-lazy"===t&&"added"===i.type&&e.length>i.targets.length){const e=i.targets.concat(this);return this.prepareBoundingBox(t,e,i)}if("fit-content"===t||"fit-content-lazy"===t||"fixed"===t&&("initialization"===i.type||"imperative"===i.type))return this.prepareBoundingBox(t,e,i);if("clip-path"===t&&this.clipPath){const s=this.clipPath,r=s._getTransformedDimensions();if(s.absolutePositioned&&("initialization"===i.type||"layout_change"===i.type)){let t=s.getCenterPoint();if(this.group){const e=at(this.group.calcTransformMatrix());t=ot(t,e)}return{centerX:t.x,centerY:t.y,width:r.x,height:r.y}}if(!s.absolutePositioned){let n;const o=s.getRelativeCenterPoint(),a=ot(o,this.calcOwnMatrix(),!0);if("initialization"===i.type||"layout_change"===i.type){const r=this.prepareBoundingBox(t,e,i)||{};return n=new X(r.centerX||0,r.centerY||0),{centerX:n.x+a.x,centerY:n.y+a.y,correctionX:r.correctionX-a.x,correctionY:r.correctionY-a.y,width:s.width,height:s.height}}return n=this.getRelativeCenterPoint(),{centerX:n.x+a.x,centerY:n.y+a.y,width:r.x,height:r.y}}}}prepareBoundingBox(t,e,s){return"initialization"===s.type?this.prepareInitialBoundingBox(t,e,s):"imperative"===s.type&&s.context?i(i({},this.getObjectsBoundingBox(e)||{}),s.context):this.getObjectsBoundingBox(e)}prepareInitialBoundingBox(t,e,i){const s=i.options||{},r="number"==typeof s.left,n="number"==typeof s.top,o="number"==typeof s.width,a="number"==typeof s.height;if(r&&n&&o&&a&&i.objectsRelativeToGroup||0===e.length)return;const h=this.getObjectsBoundingBox(e)||{},{centerX:c=0,centerY:l=0,width:d=0,height:u=0}=h,g=o?this.width:d,f=a?this.height:u,p=new X(c,l),m=new X(oe(this.originX),oe(this.originY)),v=new X(g,f),_=this._getTransformedDimensions({width:0,height:0}),x=this._getTransformedDimensions({width:g,height:f,strokeWidth:0}),y=this._getTransformedDimensions({width:h.width,height:h.height,strokeWidth:0}),C=new X(0,0),b=m.scalarAdd(.5),S=x.multiply(b),w=new X(o?y.x/2:S.x,a?y.y/2:S.y),T=new X(r?this.left-(x.x+_.x)*m.x:p.x-w.x,n?this.top-(x.y+_.y)*m.y:p.y-w.y),O=new X(r?T.x-p.x+y.x*(o?.5:0):-(o?.5*(x.x-_.x):x.x*b.x),n?T.y-p.y+y.y*(a?.5:0):-(a?.5*(x.y-_.y):x.y*b.y)).add(C),k=new X(o?-x.x/2:0,a?-x.y/2:0).add(O);return{centerX:T.x,centerY:T.y,correctionX:k.x,correctionY:k.y,width:v.x,height:v.y}}getObjectsBoundingBox(t,e){if(0===t.length)return null;const i=[];t.forEach((t=>{const e=t.getRelativeCenterPoint();let s=t._getTransformedDimensions().scalarDivide(2);if(t.angle){const e=st(t.angle),i=Math.abs(I(e)),r=Math.abs(B(e)),n=s.x*r+s.y*i,o=s.x*i+s.y*r;s=new X(n,o)}i.push(e.subtract(s),e.add(s))}));const{left:s,top:r,width:n,height:o}=Nt(i),a=new X(n,o),h=(e?new X:new X(s,r)).add(a.scalarDivide(2)).transform(this.calcOwnMatrix());return{centerX:h.x,centerY:h.y,width:a.x,height:a.y}}onLayout(t,e){}__serializeObjects(t,e){const i=this.includeDefaultValues;return this._objects.filter((function(t){return!t.excludeFromExport})).map((function(s){const r=s.includeDefaultValues;s.includeDefaultValues=i;const n=s[t||"toObject"](e);return s.includeDefaultValues=r,n}))}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return i(i({},super.toObject(["layout","subTargetCheck","interactive",...t])),{},{objects:this.__serializeObjects("toObject",t)})}toString(){return"#<Group: (".concat(this.complexity(),")>")}dispose(){this._activeObjects=[],this.forEachObject((t=>{this._watchObject(!1,t),t.dispose()})),super.dispose()}_createSVGBgRect(t){if(!this.backgroundColor)return"";const e=vs.prototype._toSVG.call(this),i=e.indexOf("COMMON_PARTS");e[i]='for="group" ';const s=e.join("");return t?t(s):s}_toSVG(t){const e=["<g ","COMMON_PARTS"," >\n"],i=this._createSVGBgRect(t);i&&e.push("\t\t",i);for(let i=0;i<this._objects.length;i++)e.push("\t\t",this._objects[i].toSVG(t));return e.push("</g>\n"),e}getSvgStyles(){const t=void 0!==this.opacity&&1!==this.opacity?"opacity: ".concat(this.opacity,";"):"",e=this.visible?"":" visibility: hidden;";return[t,this.getSvgFilter(),e].join("")}toClipPathSVG(t){const e=[],i=this._createSVGBgRect(t);i&&e.push("\t",i);for(let i=0;i<this._objects.length;i++)e.push("\t",this._objects[i].toClipPathSVG(t));return this._createBaseClipPathSVGMarkup(e,{reviver:t})}static fromObject(t){let{objects:e=[]}=t,s=n(t,_s);return Promise.all([ft(e),pt(s)]).then((t=>{let[e,r]=t;return new this(e,i(i({},s),r),!0)}))}}s(xs,"stateProperties",[...Fi.stateProperties,"layout"]),s(xs,"ownDefaults",{layout:"fit-content",strokeWidth:0,subTargetCheck:!1,interactive:!1}),M.setClass(xs);class ys extends xs{constructor(t,e,i){super(t,e,i),s(this,"multiSelectionStacking","canvas-stacking"),this.setCoords()}_shouldSetNestedCoords(){return!0}__objectSelectionMonitor(){}multiSelectAdd(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];"selection-order"===this.multiSelectionStacking?this.add(...e):e.forEach((t=>{const e=this._objects.findIndex((e=>e.isInFrontOf(t))),i=-1===e?this.size():e;this.insertAt(i,t)}))}enterGroup(t,e){if(t.group){const e=t.group;e._exitGroup(t),t.__owningGroup=e}return this._enterGroup(t,e),!0}exitGroup(t,e){this._exitGroup(t,e);const i=t.__owningGroup;i&&(i._enterGroup(t,!0),delete t.__owningGroup)}_onAfterObjectsChange(t,e){super._onAfterObjectsChange(t,e);const i=[];e.forEach((t=>{t.group&&!i.includes(t.group)&&i.push(t.group)})),"removed"===t?i.forEach((t=>{t._onAfterObjectsChange("added",e)})):i.forEach((t=>{t._set("dirty",!0)}))}onDeselect(){return this.removeAll(),!1}toString(){return"#<ActiveSelection: (".concat(this.complexity(),")>")}shouldCache(){return!1}isOnACache(){return!1}_renderControls(t,e,s){t.save(),t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1,super._renderControls(t,e);const r=i(i({hasControls:!1},s),{},{forActiveSelection:!0});for(let e=0;e<this._objects.length;e++)this._objects[e]._renderControls(t,r);t.restore()}}M.setClass(ys),M.setClass(ys,"activeSelection");class Cs extends Vt{static getDefaults(){return i(i({},super.getDefaults()),Cs.ownDefaults)}constructor(t){super(t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}),s(this,"interactive",!0),s(this,"targets",[]),s(this,"_hoveredTargets",[]),s(this,"_objectsToRender",[]),s(this,"_currentTransform",null),s(this,"_groupSelector",null),s(this,"contextTopDirty",!1),s(this,"_activeSelection",void 0),this._activeSelection=new ys([],{canvas:this})}initElements(t){super.initElements(t),this._applyCanvasStyle(this.lowerCanvasEl),this._initWrapperElement(),this._createUpperCanvas(),this._createCacheCanvas()}_initRetinaScaling(){super._initRetinaScaling(),this.__initRetinaScaling(this.upperCanvasEl,this.contextTop)}_onObjectAdded(t){this._objectsToRender=void 0,super._onObjectAdded(t)}_onObjectRemoved(t){this._objectsToRender=void 0,t===this._activeObject&&(this.fire("before:selection:cleared",{deselected:[t]}),this._discardActiveObject(),this.fire("selection:cleared",{deselected:[t]}),t.fire("deselected",{target:t})),t===this._hoveredTarget&&(this._hoveredTarget=void 0,this._hoveredTargets=[]),super._onObjectRemoved(t)}_chooseObjectsToRender(){const t=this._activeObject;return!this.preserveObjectStacking&&t?this._objects.filter((e=>!e.group&&e!==t)).concat(t):this._objects}renderAll(){this.cancelRequestedRender(),this.destroyed||(!this.contextTopDirty||this._groupSelector||this.isDrawingMode||(this.clearContext(this.contextTop),this.contextTopDirty=!1),this.hasLostContext&&(this.renderTopLayer(this.contextTop),this.hasLostContext=!1),!this._objectsToRender&&(this._objectsToRender=this._chooseObjectsToRender()),this.renderCanvas(this.contextContainer,this._objectsToRender))}renderTopLayer(t){t.save(),this.isDrawingMode&&this._isCurrentlyDrawing&&(this.freeDrawingBrush&&this.freeDrawingBrush._render(),this.contextTopDirty=!0),this.selection&&this._groupSelector&&(this._drawSelection(t),this.contextTopDirty=!0),t.restore()}renderTop(){const t=this.contextTop;this.clearContext(t),this.renderTopLayer(t),this.fire("after:render",{ctx:t})}_normalizePointer(t,e){return ot(this.restorePointerVpt(e),at(t.calcTransformMatrix()))}setTargetFindTolerance(t){t=Math.round(t),this.targetFindTolerance=t;const e=this.getRetinaScaling(),i=Math.ceil((2*t+1)*e);this.pixelFindCanvasEl.width=this.pixelFindCanvasEl.height=i,this.pixelFindContext.scale(e,e)}isTargetTransparent(t,e,i){const s=this.targetFindTolerance,r=this.pixelFindContext;this.clearContext(r),r.save(),r.translate(-e+s,-i+s),r.transform(...this.viewportTransform);const n=t.selectionBackgroundColor;t.selectionBackgroundColor="",t.render(r),t.selectionBackgroundColor=n,r.restore();const o=Math.round(s*this.getRetinaScaling());return Li(r,o,o,o)}_isSelectionKeyPressed(t){const e=this.selectionKey;return!!e&&(Array.isArray(e)?!!e.find((e=>!!e&&!0===t[e])):t[e])}_shouldClearSelection(t,e){const i=this.getActiveObjects(),s=this._activeObject;return!!(!e||e&&s&&i.length>1&&-1===i.indexOf(e)&&s!==e&&!this._isSelectionKeyPressed(t)||e&&!e.evented||e&&!e.selectable&&s&&s!==e)}_shouldCenterTransform(t,e,i){if(!t)return;let s;return"scale"===e||"scaleX"===e||"scaleY"===e||"resizing"===e?s=this.centeredScaling||t.centeredScaling:"rotate"===e&&(s=this.centeredRotation||t.centeredRotation),s?!i:i}_getOriginFromCorner(t,e){const i={x:t.originX,y:t.originY};return["ml","tl","bl"].includes(e)?i.x="right":["mr","tr","br"].includes(e)&&(i.x="left"),["tl","mt","tr"].includes(e)?i.y="bottom":["bl","mb","br"].includes(e)&&(i.y="top"),i}_setupCurrentTransform(t,e,s){if(!e)return;const r=e.group?ie(this.getPointer(t),void 0,e.group.calcTransformMatrix()):this.getPointer(t),n=e.__corner||"",o=!!n&&e.controls[n],a=s&&o?o.getActionHandler(t,e,o):fe,h=((t,e,i,s)=>{if(!e||!t)return"drag";const r=s.controls[e];return r.getActionName(i,r,s)})(s,n,t,e),c=this._getOriginFromCorner(e,n),l=t[this.centeredKey],d={target:e,action:h,actionHandler:a,actionPerformed:!1,corner:n,scaleX:e.scaleX,scaleY:e.scaleY,skewX:e.skewX,skewY:e.skewY,offsetX:r.x-e.left,offsetY:r.y-e.top,originX:c.x,originY:c.y,ex:r.x,ey:r.y,lastX:r.x,lastY:r.y,theta:st(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:l,original:i(i({},Zt(e)),{},{originX:c.x,originY:c.y})};this._shouldCenterTransform(e,h,l)&&(d.originX="center",d.originY="center"),this._currentTransform=d,this._beforeTransform(t)}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:i,deltaX:s,deltaY:r}=this._groupSelector,n=new X(e,i).transform(this.viewportTransform),o=new X(e+s,i+r).transform(this.viewportTransform),a=this.selectionLineWidth/2;let h=Math.min(n.x,o.x),c=Math.min(n.y,o.y),l=Math.max(n.x,o.x),d=Math.max(n.y,o.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(h,c,l-h,d-c)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,h+=a,c+=a,l-=a,d-=a,Fi.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(h,c,l-h,d-c))}findTarget(t){if(this.skipTargetFind)return;const e=this.getPointer(t,!0),i=this._activeObject,s=this.getActiveObjects();if(this.targets=[],i&&s.length>=1){if(i._findTargetCorner(e,Ht(t)))return i;if(s.length>1&&this.searchPossibleTargets([i],e))return i;if(i===this.searchPossibleTargets([i],e)){if(this.preserveObjectStacking){const s=this.targets;this.targets=[];const r=this.searchPossibleTargets(this._objects,e);return t[this.altSelectionKey]&&r&&r!==i?(this.targets=s,i):r}return i}}return this.searchPossibleTargets(this._objects,e)}_checkTarget(t,e,i){if(e&&e.visible&&e.evented&&e.containsPoint(t)){if(!this.perPixelTargetFind&&!e.perPixelTargetFind||e.isEditing)return!0;if(!this.isTargetTransparent(e,i.x,i.y))return!0}return!1}_searchPossibleTargets(t,e){let i,s=t.length;for(;s--;){const r=t[s],n=r.group?this._normalizePointer(r.group,e):e;if(this._checkTarget(n,r,e)){if(i=t[s],Rt(i)&&i.subTargetCheck){const t=this._searchPossibleTargets(i._objects,e);t&&this.targets.push(t)}break}}return i}searchPossibleTargets(t,e){const i=this._searchPossibleTargets(t,e);return i&&Rt(i)&&i.interactive&&this.targets[0]?this.targets[0]:i}restorePointerVpt(t){return t.transform(at(this.viewportTransform))}getPointer(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this._absolutePointer&&!e)return this._absolutePointer;if(this._pointer&&e)return this._pointer;const i=this.upperCanvasEl,s=i.getBoundingClientRect();let r=zt(t),n=s.width||0,o=s.height||0;n&&o||("top"in s&&"bottom"in s&&(o=Math.abs(s.top-s.bottom)),"right"in s&&"left"in s&&(n=Math.abs(s.right-s.left))),this.calcOffset(),r.x=r.x-this._offset.left,r.y=r.y-this._offset.top,e||(r=this.restorePointerVpt(r));const a=this.getRetinaScaling();1!==a&&(r.x/=a,r.y/=a);const h=0===n||0===o?new X(1,1):new X(i.width/n,i.height/o);return r.multiply(h)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_setBackstoreDimension(t,e){super._setBackstoreDimension(t,e),this.upperCanvasEl[t]=e}_setCssDimension(t,e){super._setCssDimension(t,e),this.upperCanvasEl.style[t]=e,this.wrapperEl.style[t]=e}_createUpperCanvas(){const t=this.lowerCanvasEl;this.upperCanvasEl||(this.upperCanvasEl=this._createCanvasElement());const e=this.upperCanvasEl;e.className=t.className,e.classList.remove("lower-canvas"),e.classList.add("upper-canvas"),e.setAttribute("data-fabric","top"),this.wrapperEl.appendChild(e),e.style.cssText=t.style.cssText,this._applyCanvasStyle(e),e.setAttribute("draggable","true"),this.contextTop=e.getContext("2d")}_createCacheCanvas(){this.pixelFindCanvasEl=this._createCanvasElement(),this.pixelFindContext=this.pixelFindCanvasEl.getContext("2d",{willReadFrequently:!0}),this.setTargetFindTolerance(this.targetFindTolerance)}_initWrapperElement(){const t=v().createElement("div");t.classList.add(this.containerClass),this.wrapperEl=q(this.lowerCanvasEl,t),this.wrapperEl.setAttribute("data-fabric","wrapper"),Ri(this.wrapperEl,{width:"".concat(this.width,"px"),height:"".concat(this.height,"px"),position:"relative"}),$(this.wrapperEl)}_applyCanvasStyle(t){const e=this.width||t.width,i=this.height||t.height;Ri(t,{position:"absolute",width:e+"px",height:i+"px",left:0,top:0,"touch-action":this.allowTouchScrolling?"manipulation":"none","-ms-touch-action":this.allowTouchScrolling?"manipulation":"none"}),t.width=e,t.height=i,$(t)}getTopContext(){return this.contextTop}getSelectionContext(){return this.contextTop}getSelectionElement(){return this.upperCanvasEl}getActiveObject(){return this._activeObject}getActiveSelection(){return this._activeSelection}getActiveObjects(){const t=this._activeObject;return t?t===this._activeSelection?[...t._objects]:[t]:[]}_fireSelectionEvents(t,e){let i=!1,s=!1;const r=this.getActiveObjects(),n=[],o=[];t.forEach((t=>{r.includes(t)||(i=!0,t.fire("deselected",{e:e,target:t}),o.push(t))})),r.forEach((s=>{t.includes(s)||(i=!0,s.fire("selected",{e:e,target:s}),n.push(s))})),t.length>0&&r.length>0?(s=!0,i&&this.fire("selection:updated",{e:e,selected:n,deselected:o})):r.length>0?(s=!0,this.fire("selection:created",{e:e,selected:n})):t.length>0&&(s=!0,this.fire("selection:cleared",{e:e,deselected:o})),s&&(this._objectsToRender=void 0)}setActiveObject(t,e){const i=this.getActiveObjects(),s=this._setActiveObject(t,e);return this._fireSelectionEvents(i,e),s}_setActiveObject(t,e){return this._activeObject!==t&&(!(!this._discardActiveObject(e,t)&&this._activeObject)&&(!t.onSelect({e:e})&&(this._activeObject=t,!0)))}_discardActiveObject(t,e){const i=this._activeObject;return!!i&&(!i.onDeselect({e:t,object:e})&&(i===this._activeSelection&&(this._activeSelection.removeAll(),$t(this._activeSelection)),this._currentTransform&&this._currentTransform.target===i&&this.endCurrentTransform(t),this._activeObject=void 0,!0))}discardActiveObject(t){const e=this.getActiveObjects(),i=this.getActiveObject();e.length&&this.fire("before:selection:cleared",{e:t,deselected:[i]});const s=this._discardActiveObject(t);return this._fireSelectionEvents(e,t),s}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this.wrapperEl,e=this.lowerCanvasEl,i=this.upperCanvasEl,s=this._activeSelection;s.removeAll(),this._activeSelection=void 0,s.dispose(),super.destroy(),t.removeChild(i),t.removeChild(e),this.pixelFindContext=null,this.contextTop=null,m().dispose(i),this.upperCanvasEl=void 0,m().dispose(this.pixelFindCanvasEl),this.pixelFindCanvasEl=void 0,t.parentNode&&t.parentNode.replaceChild(e,t),this.wrapperEl=void 0}clear(){this.discardActiveObject(),this._activeObject=void 0,this.clearContext(this.contextTop),super.clear()}drawControls(t){const e=this._activeObject;e&&e._renderControls(t)}_toObject(t,e,i){const s=this._realizeGroupTransformOnObject(t),r=super._toObject(t,e,i);return t.set(s),r}_realizeGroupTransformOnObject(t){if(t.group&&t.group===this._activeSelection&&this._activeObject===t.group){const e=mt(t,["angle","flipX","flipY","left","scaleX","scaleY","skewX","skewY","top"]);return Kt(t,this._activeObject.calcOwnMatrix()),e}return{}}_setSVGObject(t,e,i){const s=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,i),e.set(s)}}s(Cs,"ownDefaults",{uniformScaling:!0,uniScaleKey:"shiftKey",centeredScaling:!1,centeredRotation:!1,centeredKey:"altKey",altActionKey:"shiftKey",selection:!0,selectionKey:"shiftKey",selectionColor:"rgba(100, 100, 255, 0.3)",selectionDashArray:[],selectionBorderColor:"rgba(255, 255, 255, 0.3)",selectionLineWidth:1,selectionFullyContained:!1,hoverCursor:"move",moveCursor:"move",defaultCursor:"default",freeDrawingCursor:"crosshair",notAllowedCursor:"not-allowed",containerClass:"canvas-container",perPixelTargetFind:!1,targetFindTolerance:0,skipTargetFind:!1,preserveObjectStacking:!1,stopContextMenu:!1,fireRightClick:!1,fireMiddleClick:!1,enablePointerEvents:!1});class bs{constructor(){s(this,"targets",[])}exitTextEditing(){this.target=void 0,this.targets.forEach((t=>{t.isEditing&&t.exitEditing()}))}add(t){this.targets.push(t)}remove(t){this.unregister(t),R(this.targets,t)}register(t){this.target=t}unregister(t){t===this.target&&(this.target=void 0)}onMouseMove(t){var e;(null===(e=this.target)||void 0===e?void 0:e.isEditing)&&this.target.updateSelectionOnMouseMove(t)}dispose(){this.targets=[],this.target=void 0}}const Ss=["target","oldTarget","fireCanvas","e"],ws={passive:!1};function Ts(t,e){return!!t.button&&t.button===e-1}const Os=function(t){for(var e=arguments.length,i=new Array(e>1?e-1:0),s=1;s<e;s++)i[s-1]=arguments[s];return t.addEventListener(...i)},ks=function(t){for(var e=arguments.length,i=new Array(e>1?e-1:0),s=1;s<e;s++)i[s-1]=arguments[s];return t.removeEventListener(...i)},Ds={mouse:{in:"over",out:"out",targetIn:"mouseover",targetOut:"mouseout",canvasIn:"mouse:over",canvasOut:"mouse:out"},drag:{in:"enter",out:"leave",targetIn:"dragenter",targetOut:"dragleave",canvasIn:"drag:enter",canvasOut:"drag:leave"}};class Es extends Cs{constructor(t){super(t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}),s(this,"_isClick",void 0),s(this,"textEditingManager",new bs),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onDoubleClick","_onDragStart","_onDragEnd","_onDragProgress","_onDragOver","_onDragEnter","_onDragLeave","_onDrop"].forEach((t=>{this[t]=this[t].bind(this)})),this.addOrRemove(Os,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const i=this.upperCanvasEl,s=this._getEventPrefix();t(_(),"resize",this._onResize),t(i,s+"down",this._onMouseDown),t(i,"".concat(s,"move"),this._onMouseMove,ws),t(i,"".concat(s,"out"),this._onMouseOut),t(i,"".concat(s,"enter"),this._onMouseEnter),t(i,"wheel",this._onMouseWheel),t(i,"contextmenu",this._onContextMenu),t(i,"dblclick",this._onDoubleClick),t(i,"dragstart",this._onDragStart),t(i,"dragend",this._onDragEnd),t(i,"dragover",this._onDragOver),t(i,"dragenter",this._onDragEnter),t(i,"dragleave",this._onDragLeave),t(i,"drop",this._onDrop),this.enablePointerEvents||t(i,"touchstart",this._onTouchStart,ws)}removeListeners(){this.addOrRemove(ks,"remove");const t=this._getEventPrefix();ks(v(),"".concat(t,"up"),this._onMouseUp),ks(v(),"touchend",this._onTouchEnd,ws),ks(v(),"".concat(t,"move"),this._onMouseMove,ws),ks(v(),"touchmove",this._onMouseMove,ws)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s={e:t,isClick:!1,pointer:this.getPointer(t),absolutePointer:this.getPointer(t,!0)};this.fire("mouse:out",i(i({},s),{},{target:e})),this._hoveredTarget=void 0,e&&e.fire("mouseout",i({},s)),this._hoveredTargets.forEach((t=>{this.fire("mouse:out",i(i({},s),{},{target:t})),t&&t.fire("mouseout",i({},s))})),this._hoveredTargets=[]}_onMouseEnter(t){this._currentTransform||this.findTarget(t)||(this.fire("mouse:over",{e:t,isClick:!1,pointer:this.getPointer(t),absolutePointer:this.getPointer(t,!0)}),this._hoveredTarget=void 0,this._hoveredTargets=[])}_onDragStart(t){this._isClick=!1;const e=this.getActiveObject();if(Xt(e)&&e.onDragStart(t)){this._dragSource=e;const i={e:t,target:e};return this.fire("dragstart",i),e.fire("dragstart",i),void Os(this.upperCanvasEl,"drag",this._onDragProgress)}Ut(t)}_renderDragEffects(t,e,i){let s=!1;const r=this._dropTarget;r&&r!==e&&r!==i&&(r.clearContextTop(),s=!0),null==e||e.clearContextTop(),i!==e&&(null==i||i.clearContextTop());const n=this.contextTop;n.save(),n.transform(...this.viewportTransform),e&&(n.save(),e.transform(n),e.renderDragSourceEffect(t),n.restore(),s=!0),i&&(n.save(),i.transform(n),i.renderDropTargetEffect(t),n.restore(),s=!0),n.restore(),s&&(this.contextTopDirty=!0)}_onDragEnd(t){const e=!!t.dataTransfer&&"none"!==t.dataTransfer.dropEffect,i=e?this._activeObject:void 0,s={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:i};ks(this.upperCanvasEl,"drag",this._onDragProgress),this.fire("dragend",s),this._dragSource&&this._dragSource.fire("dragend",s),delete this._dragSource,this._onMouseUp(t)}_onDragProgress(t){const e={e:t,target:this._dragSource,dragSource:this._dragSource,dropTarget:this._draggedoverTarget};this.fire("drag",e),this._dragSource&&this._dragSource.fire("drag",e)}findDragTargets(t){this.targets=[];return{target:this._searchPossibleTargets(this._objects,this.getPointer(t,!0)),targets:[...this.targets]}}_onDragOver(t){const e="dragover",{target:i,targets:s}=this.findDragTargets(t),r=this._dragSource,n={e:t,target:i,subTargets:s,dragSource:r,canDrop:!1,dropTarget:void 0};let o;this.fire(e,n),this._fireEnterLeaveEvents(i,n),i&&(i.canDrop(t)&&(o=i),i.fire(e,n));for(let i=0;i<s.length;i++){const r=s[i];r.canDrop(t)&&(o=r),r.fire(e,n)}this._renderDragEffects(t,r,o),this._dropTarget=o}_onDragEnter(t){const{target:e,targets:i}=this.findDragTargets(t),s={e:t,target:e,subTargets:i,dragSource:this._dragSource};this.fire("dragenter",s),this._fireEnterLeaveEvents(e,s)}_onDragLeave(t){const e={e:t,target:this._draggedoverTarget,subTargets:this.targets,dragSource:this._dragSource};this.fire("dragleave",e),this._fireEnterLeaveEvents(void 0,e),this._renderDragEffects(t,this._dragSource),this._dropTarget=void 0,this.targets=[],this._hoveredTargets=[]}_onDrop(t){const{target:e,targets:i}=this.findDragTargets(t),s=this._basicEventHandler("drop:before",{e:t,target:e,subTargets:i,dragSource:this._dragSource,pointer:this.getPointer(t)});s.didDrop=!1,s.dropTarget=void 0,this._basicEventHandler("drop",s),this.fire("drop:after",s)}_onContextMenu(t){const e=this.findTarget(t),i=this.targets||[],s=this._basicEventHandler("contextmenu:before",{e:t,target:e,subTargets:i});return this.stopContextMenu&&Ut(t),this._basicEventHandler("contextmenu",s),!1}_onDoubleClick(t){this._cacheTransformEventData(t),this._handleEvent(t,"dblclick"),this._resetTransformEventData()}getPointerId(t){const e=t.changedTouches;return e?e[0]&&e[0].identifier:this.enablePointerEvents?t.pointerId:-1}_isMainEvent(t){return!0===t.isPrimary||!1!==t.isPrimary&&("touchend"===t.type&&0===t.touches.length||(!t.changedTouches||t.changedTouches[0].identifier===this.mainTouchId))}_onTouchStart(t){t.preventDefault(),null===this.mainTouchId&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,i=this._getEventPrefix();Os(v(),"touchend",this._onTouchEnd,ws),Os(v(),"touchmove",this._onMouseMove,ws),ks(e,i+"down",this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,i=this._getEventPrefix();ks(e,"".concat(i,"move"),this._onMouseMove,ws),Os(v(),"".concat(i,"up"),this._onMouseUp),Os(v(),"".concat(i,"move"),this._onMouseMove,ws)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),this.mainTouchId=null;const e=this._getEventPrefix();ks(v(),"touchend",this._onTouchEnd,ws),ks(v(),"touchmove",this._onMouseMove,ws),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout((()=>{Os(this.upperCanvasEl,e+"down",this._onMouseDown),this._willAddMouseDown=0}),400)}_onMouseUp(t){this.__onMouseUp(t),this._resetTransformEventData();const e=this.upperCanvasEl,i=this._getEventPrefix();this._isMainEvent(t)&&(ks(v(),"".concat(i,"up"),this._onMouseUp),ks(v(),"".concat(i,"move"),this._onMouseMove,ws),Os(e,"".concat(i,"move"),this._onMouseMove,ws))}_onMouseMove(t){const e=this.getActiveObject();!this.allowTouchScrolling&&(!e||Xt(e)&&!e.shouldStartDragging())&&t.preventDefault&&t.preventDefault(),this.__onMouseMove(t)}_onResize(){this.calcOffset(),this._resetTransformEventData()}_shouldRender(t){const e=this.getActiveObject();return!!(!!e!=!!t||e&&t&&e!==t)||(It(e),!1)}__onMouseUp(t){const e=this._currentTransform;this._cacheTransformEventData(t);const i=this._target,s=this._isClick;if(this._handleEvent(t,"up:before"),Ts(t,3))return void(this.fireRightClick&&this._handleEvent(t,"up",3,s));if(Ts(t,2))return this.fireMiddleClick&&this._handleEvent(t,"up",2,s),void this._resetTransformEventData();if(this.isDrawingMode&&this._isCurrentlyDrawing)return void this._onMouseUpInDrawingMode(t);if(!this._isMainEvent(t))return;let r,n,o=!1;if(e&&(this._finalizeCurrentTransform(t),o=e.actionPerformed),!s){const e=i===this._activeObject;this.handleSelection(t),o||(o=this._shouldRender(i)||!e&&i===this._activeObject)}if(i){if(n=i._findTargetCorner(this.getPointer(t,!0),Ht(t)),i.selectable&&i!==this._activeObject&&"up"===i.activeOn)this.setActiveObject(i,t),o=!0;else{const s=i.controls[n],o=s&&s.getMouseUpHandler(t,i,s);o&&(r=this.getPointer(t),o(t,e,r.x,r.y))}i.isMoving=!1}if(e&&(e.target!==i||e.corner!==n)){const i=e.target&&e.target.controls[e.corner],s=i&&i.getMouseUpHandler(t,e.target,i);r=r||this.getPointer(t),s&&s(t,e,r.x,r.y)}this._setCursorFromEvent(t,i),this._handleEvent(t,"up",1,s),this._groupSelector=null,this._currentTransform=null,i&&(i.__corner=void 0),o?this.requestRenderAll():s||It(this._activeObject)&&this._activeObject.isEditing||this.renderTop()}_basicEventHandler(t,e){const{target:i,subTargets:s=[]}=e;this.fire(t,e),i&&i.fire(t,e);for(let i=0;i<s.length;i++)s[i].fire(t,e);return e}_handleEvent(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,s=arguments.length>3&&void 0!==arguments[3]&&arguments[3];const r=this._target,n=this.targets||[],o={e:t,target:r,subTargets:n,button:i,isClick:s,pointer:this.getPointer(t),absolutePointer:this.getPointer(t,!0),transform:this._currentTransform};"up"===e&&(o.currentTarget=this.findTarget(t),o.currentSubTargets=this.targets),this.fire("mouse:".concat(e),o),r&&r.fire("mouse".concat(e),o);for(let t=0;t<n.length;t++)n[t].fire("mouse".concat(e),o)}endCurrentTransform(t){const e=this._currentTransform;this._finalizeCurrentTransform(t),e&&e.target&&(e.target.isMoving=!1),this._currentTransform=null}_finalizeCurrentTransform(t){const e=this._currentTransform,i=e.target,s={e:t,target:i,transform:e,action:e.action};i._scaling&&(i._scaling=!1),i.setCoords(),e.actionPerformed&&(this.fire("object:modified",s),i.fire("modified",s))}_onMouseDownInDrawingMode(t){this._isCurrentlyDrawing=!0,this.getActiveObject()&&(this.discardActiveObject(t),this.requestRenderAll());const e=this.getPointer(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseDown(e,{e:t,pointer:e}),this._handleEvent(t,"down")}_onMouseMoveInDrawingMode(t){if(this._isCurrentlyDrawing){const e=this.getPointer(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseMove(e,{e:t,pointer:e})}this.setCursor(this.freeDrawingCursor),this._handleEvent(t,"move")}_onMouseUpInDrawingMode(t){const e=this.getPointer(t);this.freeDrawingBrush?this._isCurrentlyDrawing=!!this.freeDrawingBrush.onMouseUp({e:t,pointer:e}):this._isCurrentlyDrawing=!1,this._handleEvent(t,"up")}__onMouseDown(t){this._isClick=!0,this._cacheTransformEventData(t),this._handleEvent(t,"down:before");let e=this._target;if(Ts(t,3))return void(this.fireRightClick&&this._handleEvent(t,"down",3));if(Ts(t,2))return void(this.fireMiddleClick&&this._handleEvent(t,"down",2));if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t))return;if(this._currentTransform)return;let i=this._shouldRender(e),s=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,s=!0,i=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){const e=this.getPointer(t);this._groupSelector={x:e.x,y:e.y,deltaY:0,deltaX:0}}if(e){const i=e===this._activeObject;e.selectable&&"down"===e.activeOn&&this.setActiveObject(e,t);const r=e._findTargetCorner(this.getPointer(t,!0),Ht(t));if(e===this._activeObject&&(r||!s)){this._setupCurrentTransform(t,e,i);const s=e.controls[r],n=this.getPointer(t),o=s&&s.getMouseDownHandler(t,e,s);o&&o(t,this._currentTransform,n.x,n.y)}}i&&(this._objectsToRender=void 0),this._handleEvent(t,"down"),i&&this.requestRenderAll()}_resetTransformEventData(){this._target=void 0,this._pointer=void 0,this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getPointer(t,!0),this._absolutePointer=this.restorePointerVpt(this._pointer),this._target=this._currentTransform?this._currentTransform.target:this.findTarget(t)}_beforeTransform(t){const e=this._currentTransform;this.fire("before:transform",{e:t,transform:e})}__onMouseMove(t){if(this._isClick=!1,this._handleEvent(t,"move:before"),this._cacheTransformEventData(t),this.isDrawingMode)return void this._onMouseMoveInDrawingMode(t);if(!this._isMainEvent(t))return;const e=this._groupSelector;if(e){const i=this.getPointer(t);e.deltaX=i.x-e.x,e.deltaY=i.y-e.y,this.renderTop()}else if(this._currentTransform)this._transformObject(t);else{const e=this.findTarget(t);this._setCursorFromEvent(t,e),this._fireOverOutEvents(t,e)}this.textEditingManager.onMouseMove(t),this._handleEvent(t,"move"),this._resetTransformEventData()}_fireOverOutEvents(t,e){const i=this._hoveredTarget,s=this._hoveredTargets,r=this.targets,n=Math.max(s.length,r.length);this.fireSyntheticInOutEvents("mouse",{e:t,target:e,oldTarget:i,fireCanvas:!0});for(let e=0;e<n;e++)this.fireSyntheticInOutEvents("mouse",{e:t,target:r[e],oldTarget:s[e]});this._hoveredTarget=e,this._hoveredTargets=this.targets.concat()}_fireEnterLeaveEvents(t,e){const s=this._draggedoverTarget,r=this._hoveredTargets,n=this.targets,o=Math.max(r.length,n.length);this.fireSyntheticInOutEvents("drag",i(i({},e),{},{target:t,oldTarget:s,fireCanvas:!0}));for(let t=0;t<o;t++)this.fireSyntheticInOutEvents("drag",i(i({},e),{},{target:n[t],oldTarget:r[t]}));this._draggedoverTarget=t}fireSyntheticInOutEvents(t,e){let{target:s,oldTarget:r,fireCanvas:o,e:a}=e,h=n(e,Ss);const{targetIn:c,targetOut:l,canvasIn:d,canvasOut:u}=Ds[t],g=r!==s;if(r&&g){const t=i(i({},h),{},{e:a,target:r,nextTarget:s,isClick:!1,pointer:this.getPointer(a),absolutePointer:this.getPointer(a,!0)});o&&this.fire(d,t),r.fire(l,t)}if(s&&g){const t=i(i({},h),{},{e:a,target:s,previousTarget:r,isClick:!1,pointer:this.getPointer(a),absolutePointer:this.getPointer(a,!0)});o&&this.fire(u,t),s.fire(c,t)}}__onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_transformObject(t){const e=this.getPointer(t),i=this._currentTransform,s=i.target,r=s.group?ie(e,void 0,s.group.calcTransformMatrix()):e;i.reset=!1,i.shiftKey=t.shiftKey,i.altKey=!!this.centeredKey&&t[this.centeredKey],this._performTransformAction(t,i,r),i.actionPerformed&&this.requestRenderAll()}_performTransformAction(t,e,i){const s=i.x,r=i.y,n=e.action,o=e.actionHandler;let a=!1;o&&(a=o(t,e,s,r)),"drag"===n&&a&&(e.target.isMoving=!0,this.setCursor(e.target.moveCursor||this.moveCursor)),e.actionPerformed=e.actionPerformed||a}_setCursorFromEvent(t,e){if(!e)return void this.setCursor(this.defaultCursor);let i=e.hoverCursor||this.hoverCursor;const s=this._activeObject===this._activeSelection?this._activeObject:null,r=(!s||e.group!==s)&&e._findTargetCorner(this.getPointer(t,!0));if(r){const i=e.controls[r];this.setCursor(i.cursorStyleHandler(t,i,e))}else e.subTargetCheck&&this.targets.concat().reverse().map((t=>{i=t.hoverCursor||i})),this.setCursor(i)}handleMultiSelection(t,e){const i=this._activeObject,s=this._activeSelection,r=i===s;if(i&&this._isSelectionKeyPressed(t)&&this.selection&&e&&e.selectable&&(i!==e||r)&&(r||!e.isDescendantOf(i)&&!i.isDescendantOf(e))&&!e.onSelect({e:t})&&!i.__corner){if(r){const i=s.getObjects();if(!(e!==s||(e=this.searchPossibleTargets(i,this.getPointer(t,!0)))&&e.selectable))return!1;e.group===s?(s.remove(e),this._hoveredTarget=e,this._hoveredTargets=[...this.targets],1===s.size()&&this._setActiveObject(s.item(0),t)):(s.multiSelectAdd(e),this._hoveredTarget=s,this._hoveredTargets=[...this.targets]),this._fireSelectionEvents(i,t)}else It(i)&&i.exitEditing(),s.multiSelectAdd(i,e),this._hoveredTarget=s,this._setActiveObject(s,t),this._fireSelectionEvents([i],t);return!0}return!1}handleSelection(t){if(!this.selection||!this._groupSelector)return!1;const{x:e,y:i,deltaX:s,deltaY:r}=this._groupSelector,n=new X(e,i),o=n.add(new X(s,r)),a=n.min(o),h=n.max(o).subtract(a),c=n.eq(o),l=this.collectObjects({left:a.x,top:a.y,width:h.x,height:h.y},{includeIntersecting:!this.selectionFullyContained}),d=c?l[0]?[l[0]]:[]:l.length>1?l.filter((e=>!e.onSelect({e:t}))).reverse():l;return 1===d.length?this.setActiveObject(d[0],t):d.length>1&&(this._activeSelection.add(...d),this.setActiveObject(this._activeSelection,t)),this._groupSelector=null,!0}exitTextEditing(){this.textEditingManager.exitTextEditing()}clear(){this.textEditingManager.dispose(),super.clear()}destroy(){this.removeListeners(),super.destroy(),this.textEditingManager.dispose()}}const Ms={x1:0,y1:0,x2:0,y2:0},Ps=i(i({},Ms),{},{r1:0,r2:0});function As(t){return"linearGradient"===t.nodeName||"LINEARGRADIENT"===t.nodeName?"linear":"radial"}function js(t){return"userSpaceOnUse"===t.getAttribute("gradientUnits")?"pixels":"percentage"}const Fs=/^(\d+\.\d+)%|(\d+)%$/;function Ls(t){return t&&Fs.test(t)}function Rs(t,e){const i="number"==typeof t?t:"string"==typeof t?parseFloat(t)/(Ls(t)?100:1):NaN;return De(0,L(i,e),1)}const Bs=/\s*;\s*/,Is=/\s*:\s*/;function Xs(t,e){let i,s;const r=t.getAttribute("style");if(r){const t=r.split(Bs);""===t[t.length-1]&&t.pop();for(let e=t.length;e--;){const[r,n]=t[e].split(Is).map((t=>t.trim()));"stop-color"===r?i=n:"stop-opacity"===r&&(s=n)}}const n=new wt(i||t.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:Rs(t.getAttribute("offset"),0),color:n.toRgb(),opacity:L(parseFloat(s||t.getAttribute("stop-opacity")||""),1)*n.getAlpha()*e}}function Ys(t,e){const i=[],s=t.getElementsByTagName("stop"),r=Rs(e,1);for(let t=s.length;t--;)i.push(Xs(s[t],r));return i}function Ws(t,e){return t.getAttribute(e)}function Vs(t,e){return function(t,e){let i,{width:s,height:r,gradientUnits:n}=e;return Object.keys(t).reduce(((e,o)=>{const a=t[o];return"Infinity"===a?i=1:"-Infinity"===a?i=0:(i="string"==typeof a?parseFloat(a):a,"string"==typeof a&&Ls(a)&&(i*=.01,"pixels"===n&&("x1"!==o&&"x2"!==o&&"r2"!==o||(i*=s),"y1"!==o&&"y2"!==o||(i*=r)))),e[o]=i,e}),{})}("linear"===As(t)?function(t){return{x1:Ws(t,"x1")||0,y1:Ws(t,"y1")||0,x2:Ws(t,"x2")||"100%",y2:Ws(t,"y2")||0}}(t):function(t){return{x1:Ws(t,"fx")||Ws(t,"cx")||"50%",y1:Ws(t,"fy")||Ws(t,"cy")||"50%",r1:0,x2:Ws(t,"cx")||"50%",y2:Ws(t,"cy")||"50%",r2:Ws(t,"r")||"50%"}}(t),i(i({},e),{},{gradientUnits:js(t)}))}class Gs{constructor(t){let{type:e="linear",gradientUnits:s="pixels",coords:r,colorStops:n=[],offsetX:o=0,offsetY:a=0,gradientTransform:h=null,id:c}=t;this.id=c?"".concat(c,"_").concat(Q()):Q(),this.type=e,this.gradientUnits=s,this.gradientTransform=h,this.offsetX=o,this.offsetY=a,this.coords=i(i({},"radial"===this.type?Ps:Ms),r),this.colorStops=n.slice()}addColorStop(t){for(const e in t){const i=new wt(t[e]);this.colorStops.push({offset:parseFloat(e),color:i.toRgb(),opacity:i.getAlpha()})}return this}toObject(t){return i(i({},mt(this,t)),{},{type:this.type,coords:this.coords,colorStops:this.colorStops,offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?this.gradientTransform.concat():this.gradientTransform})}toSVG(t){let{additionalTransform:e}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s=[],r=this.gradientTransform?this.gradientTransform.concat():T.concat(),n="pixels"===this.gradientUnits?"userSpaceOnUse":"objectBoundingBox",o=this.colorStops.map((t=>i({},t))).sort(((t,e)=>t.offset-e.offset));let a=-this.offsetX,h=-this.offsetY;"objectBoundingBox"===n?(a/=t.width,h/=t.height):(a+=t.width/2,h+=t.height/2),t instanceof ti&&t.isType("Path")&&"percentage"!==this.gradientUnits&&(a-=t.pathOffset.x,h-=t.pathOffset.y),r[4]-=a,r[5]-=h;const c=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(n,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(Mt(r),'"'),""].join(" ");if("linear"===this.type){const{x1:t,y1:e,x2:i,y2:r}=this.coords;s.push("<linearGradient ",c,' x1="',t,'" y1="',e,'" x2="',i,'" y2="',r,'">\n')}else if("radial"===this.type){const{x1:t,y1:e,x2:i,y2:r,r1:n,r2:a}=this.coords,h=n>a;s.push("<radialGradient ",c,' cx="',h?t:i,'" cy="',h?e:r,'" r="',h?n:a,'" fx="',h?i:t,'" fy="',h?r:e,'">\n'),h&&(o.reverse(),o.forEach((t=>{t.offset=1-t.offset})));const l=Math.min(n,a);if(l>0){const t=l/Math.max(n,a);o.forEach((e=>{e.offset+=t*(1-e.offset)}))}}return o.forEach((t=>{let{color:e,offset:i,opacity:r}=t;s.push("<stop ",'offset="',100*i+"%",'" style="stop-color:',e,void 0!==r?";stop-opacity: "+r:";",'"/>\n')})),s.push("linear"===this.type?"</linearGradient>":"</radialGradient>","\n"),s.join("")}toLive(t){const e=this.coords,i="linear"===this.type?t.createLinearGradient(e.x1,e.y1,e.x2,e.y2):t.createRadialGradient(e.x1,e.y1,e.r1,e.x2,e.y2,e.r2);return this.colorStops.forEach((t=>{let{color:e,opacity:s,offset:r}=t;i.addColorStop(r,void 0!==s?new wt(e).setAlpha(s).toRgba():e)})),i}static fromElement(t,e,s){const r=js(t);return new this(i({id:t.getAttribute("id")||void 0,type:As(t),coords:Vs(t,{width:s.viewBoxWidth||s.width,height:s.viewBoxHeight||s.height}),colorStops:Ys(t,s.opacity),gradientUnits:r,gradientTransform:ls(t.getAttribute("gradientTransform")||"")},"pixels"===r?{offsetX:-e.left,offsetY:-e.top}:{offsetX:0,offsetY:0}))}}M.setClass(Gs,"gradient");const zs=["source"];class Hs{get type(){return"pattern"}set type(t){console.warn("Setting type has no effect",t)}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};s(this,"repeat","repeat"),s(this,"offsetX",0),s(this,"offsetY",0),s(this,"crossOrigin",""),s(this,"patternTransform",null),this.id=Q(),Object.assign(this,t)}isImageSource(){return!!this.source&&"string"==typeof this.source.src}isCanvasSource(){return!!this.source&&!!this.source.toDataURL}sourceToString(){return this.isImageSource()?this.source.src:this.isCanvasSource()?this.source.toDataURL():""}toLive(t){return this.source&&(!this.isImageSource()||this.source.complete&&0!==this.source.naturalWidth&&0!==this.source.naturalHeight)?t.createPattern(this.source,this.repeat):null}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const{repeat:e,crossOrigin:s}=this;return i(i({},mt(this,t)),{},{type:"pattern",source:this.sourceToString(),repeat:e,crossOrigin:s,offsetX:Tt(this.offsetX,c.NUM_FRACTION_DIGITS),offsetY:Tt(this.offsetY,c.NUM_FRACTION_DIGITS),patternTransform:this.patternTransform?[...this.patternTransform]:null})}toSVG(t){let{width:e,height:i}=t;const{source:s,repeat:r,id:n}=this,o=L(this.offsetX/e,0),a=L(this.offsetY/i,0),h="repeat-y"===r||"no-repeat"===r?1+Math.abs(o||0):L(s.width/e,0),c="repeat-x"===r||"no-repeat"===r?1+Math.abs(a||0):L(s.height/i,0);return['<pattern id="SVGID_'.concat(n,'" x="').concat(o,'" y="').concat(a,'" width="').concat(h,'" height="').concat(c,'">'),'<image x="0" y="0" width="'.concat(s.width,'" height="').concat(s.height,'" xlink:href="').concat(this.sourceToString(),'"></image>'),"</pattern>",""].join("\n")}static async fromObject(t,e){let{source:s}=t,r=n(t,zs);const o=await gt(s,i(i({},e),{},{crossOrigin:r.crossOrigin}));return new this(i(i({},r),{},{source:o}))}}M.setClass(Hs),M.setClass(Hs,"pattern");class Us{constructor(t){s(this,"color","rgb(0, 0, 0)"),s(this,"width",1),s(this,"shadow",null),s(this,"strokeLineCap","round"),s(this,"strokeLineJoin","round"),s(this,"strokeMiterLimit",10),s(this,"strokeDashArray",null),s(this,"limitedToCanvasSize",!1),this.canvas=t}_setBrushStyles(t){t.strokeStyle=this.color,t.lineWidth=this.width,t.lineCap=this.strokeLineCap,t.miterLimit=this.strokeMiterLimit,t.lineJoin=this.strokeLineJoin,t.setLineDash(this.strokeDashArray||[])}_saveAndTransform(t){const e=this.canvas.viewportTransform;t.save(),t.transform(e[0],e[1],e[2],e[3],e[4],e[5])}needsFullRender(){return new wt(this.color).getAlpha()<1||!!this.shadow}_setShadow(){if(!this.shadow||!this.canvas)return;const t=this.canvas,e=this.shadow,i=t.contextTop,s=t.getZoom()*t.getRetinaScaling();i.shadowColor=e.color,i.shadowBlur=e.blur*s,i.shadowOffsetX=e.offsetX*s,i.shadowOffsetY=e.offsetY*s}_resetShadow(){const t=this.canvas.contextTop;t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0}_isOutSideCanvas(t){return t.x<0||t.x>this.canvas.getWidth()||t.y<0||t.y>this.canvas.getHeight()}}var Ns,qs;const Ks=String.raw(Ns||(Ns=o(["(?:d*.d+|d+.?)(?:[eE][-+]?d+)?"],["(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?"]))),Js="[-+]?".concat(Ks),$s="(".concat(Js,")"),Zs="(M) (?:".concat($s," ").concat($s," ?)+"),Qs="(L) (?:".concat($s," ").concat($s," ?)+"),tr="(H) (?:".concat($s," ?)+"),er="(V) (?:".concat($s," ?)+"),ir=String.raw(qs||(qs=o(["(Z)s*"],["(Z)\\s*"]))),sr="(C) (?:".concat($s," ").concat($s," ").concat($s," ").concat($s," ").concat($s," ").concat($s," ?)+"),rr="(S) (?:".concat($s," ").concat($s," ").concat($s," ").concat($s," ?)+"),nr="(Q) (?:".concat($s," ").concat($s," ").concat($s," ").concat($s," ?)+"),or="(T) (?:".concat($s," ").concat($s," ?)+"),ar="(A) (?:".concat($s," ").concat($s," ").concat($s," ([01]) ?([01]) ").concat($s," ").concat($s," ?)+"),hr="(?:(?:".concat(Zs,")")+"|(?:".concat(Qs,")")+"|(?:".concat(tr,")")+"|(?:".concat(er,")")+"|(?:".concat(ir,")")+"|(?:".concat(sr,")")+"|(?:".concat(rr,")")+"|(?:".concat(nr,")")+"|(?:".concat(or,")")+"|(?:".concat(ar,"))"),cr={m:"l",M:"L"},lr=(t,e,i,s,r,n,o,a,h,c,l)=>{const d=B(t),u=I(t),g=B(e),f=I(e),p=i*r*g-s*n*f+o,m=s*r*g+i*n*f+a;return["C",c+h*(-i*r*u-s*n*d),l+h*(-s*r*u+i*n*d),p+h*(i*r*f+s*n*g),m+h*(s*r*f-i*n*g),p,m]},dr=(t,e,i,s)=>{const r=Math.atan2(e,t),n=Math.atan2(s,i);return n>=r?n-r:2*Math.PI-(r-n)};function ur(t,e,i,s,r,n,o,a){let h;if(c.cachesBoundsOfCurve&&(h=[...arguments].join(),x.boundsOfCurveCache[h]))return x.boundsOfCurveCache[h];const l=Math.sqrt,d=Math.abs,u=[],g=[[0,0],[0,0]];let f=6*t-12*i+6*r,p=-3*t+9*i-9*r+3*o,m=3*i-3*t;for(let t=0;t<2;++t){if(t>0&&(f=6*e-12*s+6*n,p=-3*e+9*s-9*n+3*a,m=3*s-3*e),d(p)<1e-12){if(d(f)<1e-12)continue;const t=-m/f;0<t&&t<1&&u.push(t);continue}const i=f*f-4*m*p;if(i<0)continue;const r=l(i),o=(-f+r)/(2*p);0<o&&o<1&&u.push(o);const h=(-f-r)/(2*p);0<h&&h<1&&u.push(h)}let v=u.length;const _=v,y=mr(t,e,i,s,r,n,o,a);for(;v--;){const{x:t,y:e}=y(u[v]);g[0][v]=t,g[1][v]=e}g[0][_]=t,g[1][_]=e,g[0][_+1]=o,g[1][_+1]=a;const C=[new X(Math.min(...g[0]),Math.min(...g[1])),new X(Math.max(...g[0]),Math.max(...g[1]))];return c.cachesBoundsOfCurve&&(x.boundsOfCurveCache[h]=C),C}const gr=(t,e,i)=>{let[s,r,n,o,a,h,c,l]=i;const d=((t,e,i,s,r,n,o)=>{let a=0,h=0,c=0;const l=Math.PI,d=o*w,u=I(d),g=B(d),f=.5*(-g*t-u*e),p=.5*(-g*e+u*t),m=i**2,v=s**2,_=p**2,x=f**2,y=m*v-m*_-v*x;let C=Math.abs(i),b=Math.abs(s);if(y<0){const t=Math.sqrt(1-y/(m*v));C*=t,b*=t}else c=(r===n?-1:1)*Math.sqrt(y/(m*_+v*x));const S=c*C*p/b,T=-c*b*f/C,O=g*S-u*T+.5*t,k=u*S+g*T+.5*e;let D=dr(1,0,(f-S)/C,(p-T)/b),E=dr((f-S)/C,(p-T)/b,(-f-S)/C,(-p-T)/b);0===n&&E>0?E-=2*l:1===n&&E<0&&(E+=2*l);const M=Math.ceil(Math.abs(E/l*2)),P=new Array(M),A=E/M,j=8/3*Math.sin(A/4)*Math.sin(A/4)/Math.sin(A/2);let F=D+A;for(let t=0;t<M;t++)P[t]=lr(D,F,g,u,C,b,O,k,j,a,h),a=P[t][5],h=P[t][6],D=F,F+=A;return P})(c-t,l-e,r,n,a,h,o);for(let i=0,s=d.length;i<s;i++)d[i][1]+=t,d[i][2]+=e,d[i][3]+=t,d[i][4]+=e,d[i][5]+=t,d[i][6]+=e;return d},fr=t=>{let e=0,i=0,s=0,r=0;const n=[];let o,a=0,h=0;for(const c of t){const t=[...c];let l;switch(t[0]){case"l":t[1]+=e,t[2]+=i;case"L":e=t[1],i=t[2],l=["L",e,i];break;case"h":t[1]+=e;case"H":e=t[1],l=["L",e,i];break;case"v":t[1]+=i;case"V":i=t[1],l=["L",e,i];break;case"m":t[1]+=e,t[2]+=i;case"M":e=t[1],i=t[2],s=t[1],r=t[2],l=["M",e,i];break;case"c":t[1]+=e,t[2]+=i,t[3]+=e,t[4]+=i,t[5]+=e,t[6]+=i;case"C":a=t[3],h=t[4],e=t[5],i=t[6],l=["C",t[1],t[2],a,h,e,i];break;case"s":t[1]+=e,t[2]+=i,t[3]+=e,t[4]+=i;case"S":"C"===o?(a=2*e-a,h=2*i-h):(a=e,h=i),e=t[3],i=t[4],l=["C",a,h,t[1],t[2],e,i],a=l[3],h=l[4];break;case"q":t[1]+=e,t[2]+=i,t[3]+=e,t[4]+=i;case"Q":a=t[1],h=t[2],e=t[3],i=t[4],l=["Q",a,h,e,i];break;case"t":t[1]+=e,t[2]+=i;case"T":"Q"===o?(a=2*e-a,h=2*i-h):(a=e,h=i),e=t[1],i=t[2],l=["Q",a,h,e,i];break;case"a":t[6]+=e,t[7]+=i;case"A":gr(e,i,t).forEach((t=>n.push(t))),e=t[6],i=t[7];break;case"z":case"Z":e=s,i=r,l=["Z"]}l?(n.push(l),o=l[0]):o=""}return n},pr=(t,e,i,s)=>Math.sqrt((i-t)**2+(s-e)**2),mr=(t,e,i,s,r,n,o,a)=>h=>{const c=h**3,l=(t=>3*t**2*(1-t))(h),d=(t=>3*t*(1-t)**2)(h),u=(t=>(1-t)**3)(h);return new X(o*c+r*l+i*d+t*u,a*c+n*l+s*d+e*u)},vr=t=>t**2,_r=t=>2*t*(1-t),xr=t=>(1-t)**2,yr=(t,e,i,s,r,n,o,a)=>h=>{const c=vr(h),l=_r(h),d=xr(h),u=3*(d*(i-t)+l*(r-i)+c*(o-r)),g=3*(d*(s-e)+l*(n-s)+c*(a-n));return Math.atan2(g,u)},Cr=(t,e,i,s,r,n)=>o=>{const a=vr(o),h=_r(o),c=xr(o);return new X(r*a+i*h+t*c,n*a+s*h+e*c)},br=(t,e,i,s,r,n)=>o=>{const a=1-o,h=2*(a*(i-t)+o*(r-i)),c=2*(a*(s-e)+o*(n-s));return Math.atan2(c,h)},Sr=(t,e,i)=>{let s=new X(e,i),r=0;for(let e=1;e<=100;e+=1){const i=t(e/100);r+=pr(s.x,s.y,i.x,i.y),s=i}return r},wr=(t,e)=>{let s,r=0,n=0,o={x:t.x,y:t.y},a=i({},o),h=.01,c=0;const l=t.iterator,d=t.angleFinder;for(;n<e&&h>1e-4;)a=l(r),c=r,s=pr(o.x,o.y,a.x,a.y),s+n>e?(r-=h,h/=2):(o=a,r+=h,n+=s);return i(i({},a),{},{angle:d(c)})},Tr=t=>{let e,i,s=0,r=0,n=0,o=0,a=0;const h=[];for(const c of t){const t={x:r,y:n,command:c[0],length:0};switch(c[0]){case"M":i=t,o=r=c[1],a=n=c[2];break;case"L":i=t,i.length=pr(r,n,c[1],c[2]),r=c[1],n=c[2];break;case"C":e=mr(r,n,c[1],c[2],c[3],c[4],c[5],c[6]),i=t,i.iterator=e,i.angleFinder=yr(r,n,c[1],c[2],c[3],c[4],c[5],c[6]),i.length=Sr(e,r,n),r=c[5],n=c[6];break;case"Q":e=Cr(r,n,c[1],c[2],c[3],c[4]),i=t,i.iterator=e,i.angleFinder=br(r,n,c[1],c[2],c[3],c[4]),i.length=Sr(e,r,n),r=c[3],n=c[4];break;case"Z":i=t,i.destX=o,i.destY=a,i.length=pr(r,n,o,a),r=o,n=a}s+=i.length,h.push(i)}return h.push({length:s,x:r,y:n}),h},Or=function(t,e){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Tr(t),r=0;for(;e-s[r].length>0&&r<s.length-2;)e-=s[r].length,r++;const n=s[r],o=e/n.length,a=t[r];switch(n.command){case"M":return{x:n.x,y:n.y,angle:0};case"Z":return i(i({},new X(n.x,n.y).lerp(new X(n.destX,n.destY),o)),{},{angle:Math.atan2(n.destY-n.y,n.destX-n.x)});case"L":return i(i({},new X(n.x,n.y).lerp(new X(a[1],a[2]),o)),{},{angle:Math.atan2(a[2]-n.y,a[1]-n.x)});case"C":case"Q":return wr(n,e)}},kr=t=>{t=t.replace(new RegExp("(".concat(Js,")"),"gi")," $1 ").replace(/,/gi," ").replace(/\s+/gi," ");const e=[];for(const i of t.matchAll(new RegExp(hr,"gi"))){let t=i[0];const s=[];let r;do{if(r=new RegExp(hr,"i").exec(t),!r)break;const e=r.filter((t=>t));e.shift();const i=e.map((t=>{const e=Number.parseFloat(t);return Number.isNaN(e)?t:e}));if(s.push(i),e.length<=1)break;e.shift(),t=t.replace(new RegExp("".concat(e.join(" ?")," ?$")),"")}while(r);s.reverse().forEach(((t,i)=>{const s=cr[t[0]];i>0&&("l"==s||"L"==s)&&(t[0]=s),e.push(t)}))}return e},Dr=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=new X(t[0]),s=new X(t[1]),r=1,n=0;const o=[],a=t.length,h=a>2;let c;for(h&&(r=t[2].x<s.x?-1:t[2].x===s.x?0:1,n=t[2].y<s.y?-1:t[2].y===s.y?0:1),o.push(["M",i.x-r*e,i.y-n*e]),c=1;c<a;c++){if(!i.eq(s)){const t=i.midPointFrom(s);o.push(["Q",i.x,i.y,t.x,t.y])}i=t[c],c+1<t.length&&(s=t[c+1])}return h&&(r=i.x>t[c-2].x?1:i.x===t[c-2].x?0:-1,n=i.y>t[c-2].y?1:i.y===t[c-2].y?0:-1),o.push(["L",i.x+r*e,i.y+n*e]),o},Er=(t,e)=>t.map((t=>t.map(((t,i)=>0===i||void 0===e?t:Tt(t,e))).join(" "))).join(" "),Mr=["path","left","top"];class Pr extends Fi{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{path:i,left:s,top:r}=e;super(n(e,Mr));const o=this._setPath(t||[]),a=this.translateToGivenOrigin(new X(null!=s?s:o.x,null!=r?r:o.y),"number"==typeof s?this.originX:"left","number"==typeof r?this.originY:"top",this.originX,this.originY);this.setPositionByOrigin(a,this.originX,this.originY)}_setPath(t,e){return this.path=fr(Array.isArray(t)?t:kr(t)),this.setDimensions()}_renderPathCommands(t){let e,i=0,s=0,r=0,n=0,o=0,a=0;const h=-this.pathOffset.x,c=-this.pathOffset.y;t.beginPath();for(let l=0,d=this.path.length;l<d;++l)switch(e=this.path[l],e[0]){case"L":r=e[1],n=e[2],t.lineTo(r+h,n+c);break;case"M":r=e[1],n=e[2],i=r,s=n,t.moveTo(r+h,n+c);break;case"C":r=e[5],n=e[6],o=e[3],a=e[4],t.bezierCurveTo(e[1]+h,e[2]+c,o+h,a+c,r+h,n+c);break;case"Q":t.quadraticCurveTo(e[1]+h,e[2]+c,e[3]+h,e[4]+c),r=e[3],n=e[4],o=e[1],a=e[2];break;case"Z":r=i,n=s,t.closePath()}}_render(t){this._renderPathCommands(t),this._renderPaintInOrder(t)}toString(){return"#<Path (".concat(this.complexity(),'): { "top": ').concat(this.top,', "left": ').concat(this.left," }>")}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return i(i({},super.toObject(t)),{},{path:Je(this.path)})}toDatalessObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const e=this.toObject(t);return this.sourcePath&&(delete e.path,e.sourcePath=this.sourcePath),e}_toSVG(){const t=Er(this.path,c.NUM_FRACTION_DIGITS);return["<path ","COMMON_PARTS",'d="'.concat(t,'" stroke-linecap="round" />\n')]}_getOffsetTransform(){const t=c.NUM_FRACTION_DIGITS;return" translate(".concat(Tt(-this.pathOffset.x,t),", ").concat(Tt(-this.pathOffset.y,t),")")}toClipPathSVG(t){const e=this._getOffsetTransform();return"\t"+this._createBaseClipPathSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}toSVG(t){const e=this._getOffsetTransform();return this._createBaseSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}complexity(){return this.path.length}setDimensions(){const{left:t,top:e,width:i,height:s,pathOffset:r}=this._calcDimensions();return this.set({width:i,height:s,pathOffset:r}),new X(t,e)}_calcDimensions(){const t=[];let e=0,s=0,r=0,n=0;for(let i=0;i<this.path.length;++i){const o=this.path[i];switch(o[0]){case"L":r=o[1],n=o[2],t.push(new X(e,s),new X(r,n));break;case"M":r=o[1],n=o[2],e=r,s=n;break;case"C":t.push(...ur(r,n,o[1],o[2],o[3],o[4],o[5],o[6])),r=o[5],n=o[6];break;case"Q":t.push(...ur(r,n,o[1],o[2],o[1],o[2],o[3],o[4])),r=o[3],n=o[4];break;case"Z":r=e,n=s}}const o=Nt(t),a=this.fromSVG?0:this.strokeWidth/2;return i(i({},o),{},{left:o.left-a,top:o.top-a,pathOffset:new X(o.left+o.width/2,o.top+o.height/2)})}static fromObject(t){return this._fromObject(t,{extraParam:"path"})}static fromElement(t,e,s){const r=fs(t,this.ATTRIBUTE_NAMES);e(new this(r.d,i(i(i({},r),s),{},{left:void 0,top:void 0,fromSVG:!0})))}}s(Pr,"cacheProperties",[...$e,"path","fillRule"]),s(Pr,"ATTRIBUTE_NAMES",[...Bi,"d"]),M.setClass(Pr),M.setSVGClass(Pr);class Ar extends Us{constructor(t){super(t),s(this,"decimate",.4),s(this,"drawStraightLine",!1),s(this,"straightLineKey","shiftKey"),this._points=[],this._hasStraightLine=!1}needsFullRender(){return super.needsFullRender()||this._hasStraightLine}static drawSegment(t,e,i){const s=e.midPointFrom(i);return t.quadraticCurveTo(e.x,e.y,s.x,s.y),s}onMouseDown(t,e){let{e:i}=e;this.canvas._isMainEvent(i)&&(this.drawStraightLine=!!this.straightLineKey&&i[this.straightLineKey],this._prepareForDrawing(t),this._addPoint(t),this._render())}onMouseMove(t,e){let{e:i}=e;if(this.canvas._isMainEvent(i)&&(this.drawStraightLine=!!this.straightLineKey&&i[this.straightLineKey],(!0!==this.limitedToCanvasSize||!this._isOutSideCanvas(t))&&this._addPoint(t)&&this._points.length>1))if(this.needsFullRender())this.canvas.clearContext(this.canvas.contextTop),this._render();else{const t=this._points,e=t.length,i=this.canvas.contextTop;this._saveAndTransform(i),this.oldEnd&&(i.beginPath(),i.moveTo(this.oldEnd.x,this.oldEnd.y)),this.oldEnd=Ar.drawSegment(i,t[e-2],t[e-1]),i.stroke(),i.restore()}}onMouseUp(t){let{e:e}=t;return!this.canvas._isMainEvent(e)||(this.drawStraightLine=!1,this.oldEnd=void 0,this._finalizeAndAddPath(),!1)}_prepareForDrawing(t){this._reset(),this._addPoint(t),this.canvas.contextTop.moveTo(t.x,t.y)}_addPoint(t){return!(this._points.length>1&&t.eq(this._points[this._points.length-1]))&&(this.drawStraightLine&&this._points.length>1&&(this._hasStraightLine=!0,this._points.pop()),this._points.push(t),!0)}_reset(){this._points=[],this._setBrushStyles(this.canvas.contextTop),this._setShadow(),this._hasStraightLine=!1}_render(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.canvas.contextTop,e=this._points[0],i=this._points[1];if(this._saveAndTransform(t),t.beginPath(),2===this._points.length&&e.x===i.x&&e.y===i.y){const t=this.width/1e3;e.x-=t,i.x+=t}t.moveTo(e.x,e.y);for(let s=1;s<this._points.length;s++)Ar.drawSegment(t,e,i),e=this._points[s],i=this._points[s+1];t.lineTo(e.x,e.y),t.stroke(),t.restore()}convertPointsToSVGPath(t){const e=this.width/1e3;return Dr(t,e)}createPath(t){const e=new Pr(t,{fill:null,stroke:this.color,strokeWidth:this.width,strokeLineCap:this.strokeLineCap,strokeMiterLimit:this.strokeMiterLimit,strokeLineJoin:this.strokeLineJoin,strokeDashArray:this.strokeDashArray});return this.shadow&&(this.shadow.affectStroke=!0,e.shadow=new Ke(this.shadow)),e}decimatePoints(t,e){if(t.length<=2)return t;let i,s=t[0];const r=this.canvas.getZoom(),n=Math.pow(e/r,2),o=t.length-1,a=[s];for(let e=1;e<o-1;e++)i=Math.pow(s.x-t[e].x,2)+Math.pow(s.y-t[e].y,2),i>=n&&(s=t[e],a.push(s));return a.push(t[o]),a}_finalizeAndAddPath(){this.canvas.contextTop.closePath(),this.decimate&&(this._points=this.decimatePoints(this._points,this.decimate));const t=this.convertPointsToSVGPath(this._points);if(function(t){return"M 0 0 Q 0 0 0 0 L 0 0"===Er(t)}(t))return void this.canvas.requestRenderAll();const e=this.createPath(t);this.canvas.clearContext(this.canvas.contextTop),this.canvas.fire("before:path:created",{path:e}),this.canvas.add(e),this.canvas.requestRenderAll(),e.setCoords(),this._resetShadow(),this.canvas.fire("path:created",{path:e})}}const jr=["left","top","radius"],Fr=["radius","startAngle","endAngle"];class Lr extends Fi{static getDefaults(){return i(i({},super.getDefaults()),Lr.ownDefaults)}_set(t,e){return super._set(t,e),"radius"===t&&this.setRadius(e),this}_render(t){t.beginPath(),t.arc(0,0,this.radius,st(this.startAngle),st(this.endAngle),!1),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get("scaleX")}getRadiusY(){return this.get("radius")*this.get("scaleY")}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([...Fr,...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:e}=this,i=st(this.startAngle),s=st(this.endAngle),r=B(i)*e,n=I(i)*e,o=B(s)*e,a=I(s)*e,h=t>180?"1":"0";return['<path d="M '.concat(r," ").concat(n)," A ".concat(e," ").concat(e)," 0 ","".concat(h," 1")," ".concat(o," ").concat(a),'" ',"COMMON_PARTS"," />\n"]}}static fromElement(t,e){const s=fs(t,this.ATTRIBUTE_NAMES),{left:r=0,top:o=0,radius:a}=s,h=n(s,jr);if(!a||a<0)throw new Error("value of `r` attribute is required and can not be negative");e(new this(i(i({},h),{},{radius:a,left:r-a,top:o-a})))}static fromObject(t){return super._fromObject(t)}}s(Lr,"cacheProperties",[...$e,...Fr]),s(Lr,"ownDefaults",{radius:0,startAngle:0,endAngle:360}),s(Lr,"ATTRIBUTE_NAMES",["cx","cy","r",...Bi]),M.setClass(Lr),M.setSVGClass(Lr);const Rr=["x1","y1","x2","y2"],Br=["x1","x2","y1","y2"];class Ir extends Fi{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[0,0,0,0],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(e),this.x1=t[0],this.y1=t[1],this.x2=t[2],this.y2=t[3],this._setWidthHeight(e)}_setWidthHeight(){let{left:t,top:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.width=Math.abs(this.x2-this.x1),this.height=Math.abs(this.y2-this.y1),this.left=null!=t?t:this._getLeftToOriginX(),this.top=null!=e?e:this._getTopToOriginY()}_set(t,e){return super._set(t,e),Br.includes(t)&&this._setWidthHeight(),this}_render(t){t.beginPath();const e=this.calcLinePoints();t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2),t.lineWidth=this.strokeWidth;const i=t.strokeStyle;var s;jt(this.stroke)?t.strokeStyle=this.stroke.toLive(t):t.strokeStyle=null!==(s=this.stroke)&&void 0!==s?s:t.fillStyle;this.stroke&&this._renderStroke(t),t.strokeStyle=i}_findCenterFromElement(){return new X((this.x1+this.x2)/2,(this.y1+this.y2)/2)}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return i(i({},super.toObject(t)),this.calcLinePoints())}_getNonTransformedDimensions(){const t=super._getNonTransformedDimensions();return"butt"===this.strokeLineCap&&(0===this.width&&(t.y-=this.strokeWidth),0===this.height&&(t.x-=this.strokeWidth)),t}calcLinePoints(){const t=this.x1<=this.x2?-1:1,e=this.y1<=this.y2?-1:1,i=t*this.width*.5,s=e*this.height*.5;return{x1:i,x2:t*this.width*-.5,y1:s,y2:e*this.height*-.5}}makeEdgeToOriginGetter(t,e){const i=t.origin,s=t.axis1,r=t.axis2,n=t.dimension,o=e.nearest,a=e.center,h=e.farthest;switch(this.get(i)){case o:return Math.min(this.get(s),this.get(r));case a:return Math.min(this.get(s),this.get(r))+.5*this.get(n);case h:return Math.max(this.get(s),this.get(r));default:return 0}}_getLeftToOriginX(){return this.makeEdgeToOriginGetter({origin:"originX",axis1:"x1",axis2:"x2",dimension:"width"},{nearest:"left",center:"center",farthest:"right"})}_getTopToOriginY(){return this.makeEdgeToOriginGetter({origin:"originY",axis1:"y1",axis2:"y2",dimension:"height"},{nearest:"top",center:"center",farthest:"bottom"})}_toSVG(){const t=this.calcLinePoints();return["<line ","COMMON_PARTS",'x1="',t.x1,'" y1="',t.y1,'" x2="',t.x2,'" y2="',t.y2,'" />\n']}static fromElement(t,e){const i=fs(t,this.ATTRIBUTE_NAMES);e(new this([i.x1||0,i.y1||0,i.x2||0,i.y2||0],i))}static fromObject(t){let{x1:e,y1:s,x2:r,y2:o}=t,a=n(t,Rr);return this._fromObject(i(i({},a),{},{points:[e,s,r,o]}),{extraParam:"points"})}}s(Ir,"cacheProperties",[...$e,...Br]),s(Ir,"ATTRIBUTE_NAMES",Bi.concat(Br)),M.setClass(Ir),M.setSVGClass(Ir);class Xr extends Fi{static getDefaults(){return i(i({},super.getDefaults()),Xr.ownDefaults)}_render(t){const e=this.width/2,i=this.height/2;t.beginPath(),t.moveTo(-e,i),t.lineTo(0,-i),t.lineTo(e,i),t.closePath(),this._renderPaintInOrder(t)}_toSVG(){const t=this.width/2,e=this.height/2;return["<polygon ","COMMON_PARTS",'points="',"".concat(-t," ").concat(e,",0 ").concat(-e,",").concat(t," ").concat(e),'" />']}}s(Xr,"ownDefaults",{width:100,height:100}),M.setClass(Xr),M.setSVGClass(Xr);const Yr=["rx","ry"];class Wr extends Fi{static getDefaults(){return i(i({},super.getDefaults()),Wr.ownDefaults)}_set(t,e){switch(super._set(t,e),t){case"rx":this.rx=e,this.set("width",2*e);break;case"ry":this.ry=e,this.set("height",2*e)}return this}getRx(){return this.get("rx")*this.get("scaleX")}getRy(){return this.get("ry")*this.get("scaleY")}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return super.toObject([...Yr,...t])}_toSVG(){return["<ellipse ","COMMON_PARTS",'cx="0" cy="0" ','rx="',this.rx,'" ry="',this.ry,'" />\n']}_render(t){t.beginPath(),t.save(),t.transform(1,0,0,this.ry/this.rx,0,0),t.arc(0,0,this.rx,0,S,!1),t.restore(),this._renderPaintInOrder(t)}static fromElement(t,e){const i=fs(t,this.ATTRIBUTE_NAMES);i.left=(i.left||0)-i.rx,i.top=(i.top||0)-i.ry,e(new this(i))}}function Vr(t){if(!t)return null;t=(t=t.replace(/,/g," ").trim()).split(/\s+/);const e=[];for(let i=0;i<t.length;i+=2)e.push({x:parseFloat(t[i]),y:parseFloat(t[i+1])});return e}s(Wr,"cacheProperties",[...$e,...Yr]),s(Wr,"ownDefaults",{rx:0,ry:0}),s(Wr,"ATTRIBUTE_NAMES",[...Bi,"cx","cy","rx","ry"]),M.setClass(Wr),M.setSVGClass(Wr);class Gr{static getAcuteAngleFactor(t,e){const i=e?Ye(t,e):Ye(Re,t);return Math.abs(i)<b?-1:1}constructor(t){this.options=t,this.strokeProjectionMagnitude=this.options.strokeWidth/2,this.scale=new X(this.options.scaleX,this.options.scaleY),this.strokeUniformScalar=this.options.strokeUniform?new X(1/this.options.scaleX,1/this.options.scaleY):new X(1,1)}createSideVector(t,e){const i=Ie(t,e);return this.options.strokeUniform?i.multiply(this.scale):i}projectOrthogonally(t,e,i){return this.applySkew(t.add(this.calcOrthogonalProjection(t,e,i)))}isSkewed(){return 0!==this.options.skewX||0!==this.options.skewY}applySkew(t){const e=new X(t);return e.y+=e.x*Math.tan(st(this.options.skewY)),e.x+=e.y*Math.tan(st(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}class zr extends Gr{constructor(t,e,i,s){super(s),this.A=new X(t),this.B=new X(e),this.C=new X(i),this.bisector=this.options.strokeUniform?Ve(this.A.multiply(this.scale),this.B.multiply(this.scale),this.C.multiply(this.scale)):Ve(this.A,this.B,this.C)}get bisectorVector(){return this.bisector.vector}get bisectorAngle(){return this.bisector.angle}calcOrthogonalProjection(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.strokeProjectionMagnitude;const s=this.createSideVector(t,e),r=Ge(s),n=Gr.getAcuteAngleFactor(r,this.bisectorVector);return this.scaleUnitVector(r,i*n)}projectBevel(){return[this.B,this.C].map((t=>this.projectOrthogonally(this.A,t)))}projectMiter(){const t=Math.abs(this.bisectorAngle),e=1/Math.sin(t/2),i=this.scaleUnitVector(this.bisectorVector,-this.strokeProjectionMagnitude*e),s=this.options.strokeUniform?e:this.options.strokeMiterLimit;return Xe(i)/this.strokeProjectionMagnitude<=s?[this.applySkew(this.A.add(i))]:this.projectBevel()}projectRoundNoSkew(){const t=new X(Gr.getAcuteAngleFactor(this.bisectorVector),Gr.getAcuteAngleFactor(new X(this.bisectorVector.y,this.bisectorVector.x))),e=new X(1,0).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(t),i=new X(0,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(t);return[this.A.add(e),this.A.add(i)]}projectRoundWithSkew(){const t=[];[this.B,this.C].forEach((e=>t.push(this.projectOrthogonally(this.A,e))));const{skewX:e,skewY:i}=this.options,s=(new X).scalarAdd(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar),r=s.y/Math.sqrt(1+Math.tan(st(i))**2),n=new X(Math.sqrt(s.x**2-(r*s.x/s.y)**2),r),o=s.x/Math.sqrt(1+Math.tan(st(e))**2);return[new X(o,Math.sqrt(r**2-(o*r/s.x)**2)),n].forEach((e=>{t.push(this.applySkew(this.A.add(e)),this.applySkew(this.A.subtract(e)))})),t}projectRound(){return this.isSkewed()?this.projectRoundWithSkew():this.projectRoundNoSkew()}projectPoints(){switch(this.options.strokeLineJoin){case"miter":return this.projectMiter();case"round":return this.projectRound();default:return this.projectBevel()}}project(){return this.projectPoints().map((t=>({originPoint:this.A,projectedPoint:t,bisector:this.bisector})))}}class Hr extends Gr{constructor(t,e,i){super(i),this.A=new X(t),this.T=new X(e)}calcOrthogonalProjection(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.strokeProjectionMagnitude;const s=this.createSideVector(t,e);return this.scaleUnitVector(Ge(s),i)}projectButt(){return[this.projectOrthogonally(this.A,this.T,this.strokeProjectionMagnitude),this.projectOrthogonally(this.A,this.T,-this.strokeProjectionMagnitude)]}projectRound(){return new zr(this.A,this.T,this.T,this.options).projectRound()}projectSquare(){const t=this.calcOrthogonalProjection(this.A,this.T,this.strokeProjectionMagnitude),e=this.scaleUnitVector(We(Ie(this.A,this.T)),-this.strokeProjectionMagnitude),i=this.A.add(e);return[i.add(t),i.subtract(t)].map((t=>this.applySkew(t)))}projectPoints(){switch(this.options.strokeLineCap){case"round":return this.projectRound();case"square":return this.projectSquare();default:return this.projectButt()}}project(){return this.projectPoints().map((t=>({originPoint:this.A,projectedPoint:t})))}}const Ur=function(t,e){let i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const s=[];return t.length<=1||t.forEach(((r,n)=>{let o,a;0===n?(a=t[1],o=i?r:t[t.length-1]):n===t.length-1?(o=t[n-1],a=i?r:t[0]):(o=t[n-1],a=t[n+1]),!i||0!==n&&n!==t.length-1?s.push(...new zr(r,o,a,e).project()):s.push(...new Hr(r,0===n?a:o,e).project())})),s},Nr=["left","top"],qr={exactBoundingBox:!1};class Kr extends Fi{static getDefaults(){return i(i({},super.getDefaults()),Kr.ownDefaults)}constructor(){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(i({points:arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]},t));const{left:e,top:s}=t;this.initialized=!0,this.setBoundingBox(!0),"number"==typeof e&&this.set("left",e),"number"==typeof s&&this.set("top",s)}isOpen(){return!0}_projectStrokeOnPoints(){return Ur(this.points,this,this.isOpen())}_calcDimensions(){const t=this.exactBoundingBox?this._projectStrokeOnPoints().map((t=>t.projectedPoint)):this.points;if(0===t.length)return{left:0,top:0,width:0,height:0,pathOffset:new X,strokeOffset:new X};const e=Nt(t),s=Nt(this.points),r=e.left+e.width/2,n=e.top+e.height/2,o=r-n*Math.tan(st(this.skewX)),a=n-o*Math.tan(st(this.skewY)),h=this.fromSVG||this.exactBoundingBox?0:this.strokeWidth/2;return i(i({},e),{},{left:e.left-h,top:e.top-h,pathOffset:new X(o,a),strokeOffset:new X(s.left,s.top).subtract(new X(e.left,e.top))})}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{left:e,top:i,width:s,height:r,pathOffset:n,strokeOffset:o}=this._calcDimensions();this.set({width:s,height:r,pathOffset:n,strokeOffset:o}),t&&this.setPositionByOrigin(new X(e,i),"left","top")}_getNonTransformedDimensions(){return this.exactBoundingBox?new X(this.width,this.height):super._getNonTransformedDimensions()}_getTransformedDimensions(t){return this.exactBoundingBox?super._getTransformedDimensions(i(i({},t||{}),{},{strokeWidth:0,skewX:0,skewY:0})):super._getTransformedDimensions(t)}_set(t,e){const i=this.initialized&&this[t]!==e,s=super._set(t,e);return i&&(("scaleX"===t||"scaleY"===t)&&this.strokeUniform&&this.constructor.layoutProperties.includes("strokeUniform")&&"round"!==this.strokeLineJoin||this.constructor.layoutProperties.includes(t))&&this.setDimensions(),s}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return i(i({},super.toObject(t)),{},{points:Je(this.points)})}_toSVG(){const t=[],e=this.pathOffset.x,i=this.pathOffset.y,s=c.NUM_FRACTION_DIGITS;for(let r=0,n=this.points.length;r<n;r++)t.push(Tt(this.points[r].x-e,s),",",Tt(this.points[r].y-i,s)," ");return["<".concat(this.constructor.name.toLowerCase()," "),"COMMON_PARTS",'points="'.concat(t.join(""),'" />\n')]}_render(t){const e=this.points.length,i=this.pathOffset.x,s=this.pathOffset.y;if(e&&!isNaN(this.points[e-1].y)){t.beginPath(),t.moveTo(this.points[0].x-i,this.points[0].y-s);for(let r=0;r<e;r++){const e=this.points[r];t.lineTo(e.x-i,e.y-s)}!this.isOpen()&&t.closePath(),this._renderPaintInOrder(t)}}complexity(){return this.points.length}static fromElement(t,e,s){if(!t)return e(null);e(new this(Vr(t.getAttribute("points"))||[],i(i(i({},n(fs(t,this.ATTRIBUTE_NAMES),Nr)),s),{},{fromSVG:!0})))}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}}s(Kr,"ownDefaults",qr),s(Kr,"layoutProperties",["skewX","skewY","strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),s(Kr,"cacheProperties",[...$e,"points"]),s(Kr,"ATTRIBUTE_NAMES",[...Bi]),M.setClass(Kr),M.setSVGClass(Kr);class Jr extends Kr{static getDefaults(){return i(i({},super.getDefaults()),Kr.ownDefaults)}isOpen(){return!1}}s(Jr,"ownDefaults",qr),M.setClass(Jr),M.setSVGClass(Jr);const $r=["fontSize","fontWeight","fontFamily","fontStyle"],Zr=["underline","overline","linethrough"],Qr=[...$r,"lineHeight","text","charSpacing","textAlign","styles","path","pathStartOffset","pathSide","pathAlign"],tn=[...Qr,...Zr,"textBackgroundColor","direction"],en=[...$r,...Zr,"stroke","strokeWidth","fill","deltaY","textBackgroundColor"];class sn extends Fi{isEmptyStyles(t){if(!this.styles)return!0;if(void 0!==t&&!this.styles[t])return!0;const e=void 0===t?this.styles:{line:this.styles[t]};for(const t in e)for(const i in e[t])for(const s in e[t][i])return!1;return!0}styleHas(t,e){if(!this.styles||!t||""===t)return!1;if(void 0!==e&&!this.styles[e])return!1;const i=void 0===e?this.styles:{0:this.styles[e]};for(const e in i)for(const s in i[e])if(void 0!==i[e][s][t])return!0;return!1}cleanStyle(t){if(!this.styles||!t||""===t)return!1;const e=this.styles;let i,s,r=0,n=!0,o=0;for(const o in e){i=0;for(const a in e[o]){const h=e[o][a];r++,Object.prototype.hasOwnProperty.call(h,t)?(s?h[t]!==s&&(n=!1):s=h[t],h[t]===this[t]&&delete h[t]):n=!1,0!==Object.keys(h).length?i++:delete e[o][a]}0===i&&delete e[o]}for(let t=0;t<this._textLines.length;t++)o+=this._textLines[t].length;n&&r===o&&(this[t]=s,this.removeStyle(t))}removeStyle(t){if(!this.styles||!t||""===t)return;const e=this.styles;let i,s,r;for(s in e){for(r in i=e[s],i)delete i[r][t],0===Object.keys(i[r]).length&&delete i[r];0===Object.keys(i).length&&delete e[s]}}_extendStyles(t,e){const{lineIndex:i,charIndex:s}=this.get2DCursorLocation(t);return this._getLineStyle(i)||this._setLineStyle(i),this._getStyleDeclaration(i,s)||this._setStyleDeclaration(i,s,{}),Object.assign(this._getStyleDeclaration(i,s)||{},e)}getSelectionStyles(t,e,i){const s=[];for(let r=t;r<(e||t);r++)s.push(this.getStyleAtPosition(r,i));return s}getStyleAtPosition(t,e){const{lineIndex:i,charIndex:s}=this.get2DCursorLocation(t);return(e?this.getCompleteStyleDeclaration(i,s):this._getStyleDeclaration(i,s))||{}}setSelectionStyles(t,e,i){for(let s=e;s<(i||e);s++)this._extendStyles(s,t);this._forceClearCache=!0}_getStyleDeclaration(t,e){const i=this.styles&&this.styles[t];return i?i[e]:null}getCompleteStyleDeclaration(t,e){const i=this._getStyleDeclaration(t,e)||{},s={},r=this.constructor._styleProperties;for(let t=0;t<r.length;t++){const e=r[t];s[e]=void 0===i[e]?this[e]:i[e]}return s}_setStyleDeclaration(t,e,i){this.styles[t][e]=i}_deleteStyleDeclaration(t,e){delete this.styles[t][e]}_getLineStyle(t){return!!this.styles[t]}_setLineStyle(t){this.styles[t]={}}_deleteLineStyle(t){delete this.styles[t]}}s(sn,"_styleProperties",en);const rn=t=>t.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&apos;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),nn=t=>{const e=[];for(let i,s=0;s<t.length;s++)!1!==(i=on(t,s))&&e.push(i);return e},on=(t,e)=>{const i=t.charCodeAt(e);if(isNaN(i))return"";if(i<55296||i>57343)return t.charAt(e);if(55296<=i&&i<=56319){if(t.length<=e+1)throw"High surrogate without following low surrogate";const i=t.charCodeAt(e+1);if(56320>i||i>57343)throw"High surrogate without following low surrogate";return t.charAt(e)+t.charAt(e+1)}if(0===e)throw"Low surrogate without preceding high surrogate";const s=t.charCodeAt(e-1);if(55296>s||s>56319)throw"Low surrogate without preceding high surrogate";return!1};var an=Object.freeze({__proto__:null,capitalize:function(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return"".concat(t.charAt(0).toUpperCase()).concat(e?t.slice(1):t.slice(1).toLowerCase())},escapeXml:rn,graphemeSplit:nn});const hn=function(t,e){let i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return t.fill!==e.fill||t.stroke!==e.stroke||t.strokeWidth!==e.strokeWidth||t.fontSize!==e.fontSize||t.fontFamily!==e.fontFamily||t.fontWeight!==e.fontWeight||t.fontStyle!==e.fontStyle||t.textBackgroundColor!==e.textBackgroundColor||t.deltaY!==e.deltaY||i&&(t.overline!==e.overline||t.underline!==e.underline||t.linethrough!==e.linethrough)},cn=(t,e)=>{const i=e.split("\n"),s=[];let r=-1,n={};t=Je(t);for(let e=0;e<i.length;e++)if(t[e])for(let o=0;o<i[e].length;o++){r++;const i=t[e][o];i&&Object.keys(i).length>0&&(hn(n,i,!0)?s.push({start:r,end:r+1,style:i}):s[s.length-1].end++),n=i||{}}else r+=i[e].length,n={};return s},ln=(t,e)=>{if(!Array.isArray(t))return Je(t);const s=e.split("\n"),r={};let n=-1,o=0;for(let e=0;e<s.length;e++)for(let a=0;a<s[e].length;a++)n++,t[o]&&t[o].start<=n&&n<t[o].end&&(r[e]=r[e]||{},r[e][a]=i({},t[o].style),n===t[o].end-1&&o++);return r},dn=/ +/g,un=/"/g;function gn(t,e,i,s,r){return"\t\t".concat(At(t,{left:e,top:i,width:s,height:r}),"\n")}let fn;class pn extends sn{static getDefaults(){return i(i({},super.getDefaults()),pn.ownDefaults)}constructor(t,e){super(i(i({},e),{},{text:t,styles:(null==e?void 0:e.styles)||{}})),s(this,"__charBounds",[]),this.initialized=!0,this.path&&this.setPathInfo(),this.initDimensions(),this.setCoords()}setPathInfo(){const t=this.path;t&&(t.segmentsInfo=Tr(t.path))}_splitText(){const t=this._splitTextIntoLines(this.text);return this.textLines=t.lines,this._textLines=t.graphemeLines,this._unwrappedTextLines=t._unwrappedLines,this._text=t.graphemeText,t}initDimensions(){this._splitText(),this._clearCache(),this.dirty=!0,this.path?(this.width=this.path.width,this.height=this.path.height):(this.width=this.calcTextWidth()||this.cursorWidth||this.MIN_TEXT_WIDTH,this.height=this.calcTextHeight()),-1!==this.textAlign.indexOf("justify")&&this.enlargeSpaces()}enlargeSpaces(){let t,e,i,s,r,n,o;for(let a=0,h=this._textLines.length;a<h;a++)if(("justify"===this.textAlign||a!==h-1&&!this.isEndOfWrapping(a))&&(s=0,r=this._textLines[a],e=this.getLineWidth(a),e<this.width&&(o=this.textLines[a].match(this._reSpacesAndTabs)))){i=o.length,t=(this.width-e)/i;for(let e=0;e<=r.length;e++)n=this.__charBounds[a][e],this._reSpaceAndTab.test(r[e])?(n.width+=t,n.kernedWidth+=t,n.left+=s,s+=t):n.left+=s}}isEndOfWrapping(t){return t===this._textLines.length-1}missingNewlineOffset(t){return 1}get2DCursorLocation(t,e){const i=e?this._unwrappedTextLines:this._textLines;let s;for(s=0;s<i.length;s++){if(t<=i[s].length)return{lineIndex:s,charIndex:t};t-=i[s].length+this.missingNewlineOffset(s)}return{lineIndex:s-1,charIndex:i[s-1].length<t?i[s-1].length:t}}toString(){return"#<Text (".concat(this.complexity(),'): { "text": "').concat(this.text,'", "fontFamily": "').concat(this.fontFamily,'" }>')}_getCacheCanvasDimensions(){const t=super._getCacheCanvasDimensions(),e=this.fontSize;return t.width+=e*t.zoomX,t.height+=e*t.zoomY,t}_render(t){const e=this.path;e&&!e.isNotVisible()&&e._render(t),this._setTextStyles(t),this._renderTextLinesBackground(t),this._renderTextDecoration(t,"underline"),this._renderText(t),this._renderTextDecoration(t,"overline"),this._renderTextDecoration(t,"linethrough")}_renderText(t){"stroke"===this.paintFirst?(this._renderTextStroke(t),this._renderTextFill(t)):(this._renderTextFill(t),this._renderTextStroke(t))}_setTextStyles(t,e,i){if(t.textBaseline="alphabetic",this.path)switch(this.pathAlign){case"center":t.textBaseline="middle";break;case"ascender":t.textBaseline="top";break;case"descender":t.textBaseline="bottom"}t.font=this._getFontDeclaration(e,i)}calcTextWidth(){let t=this.getLineWidth(0);for(let e=1,i=this._textLines.length;e<i;e++){const i=this.getLineWidth(e);i>t&&(t=i)}return t}_renderTextLine(t,e,i,s,r,n){this._renderChars(t,e,i,s,r,n)}_renderTextLinesBackground(t){if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor"))return;const e=t.fillStyle,i=this._getLeftOffset();let s=this._getTopOffset();for(let e=0,r=this._textLines.length;e<r;e++){const r=this.getHeightOfLine(e);if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor",e)){s+=r;continue}const n=this._textLines[e].length,o=this._getLineLeftOffset(e);let a,h,c=0,l=0,d=this.getValueOfPropertyAt(e,0,"textBackgroundColor");for(let u=0;u<n;u++){const n=this.__charBounds[e][u];h=this.getValueOfPropertyAt(e,u,"textBackgroundColor"),this.path?(t.save(),t.translate(n.renderLeft,n.renderTop),t.rotate(n.angle),t.fillStyle=h,h&&t.fillRect(-n.width/2,-r/this.lineHeight*(1-this._fontSizeFraction),n.width,r/this.lineHeight),t.restore()):h!==d?(a=i+o+l,"rtl"===this.direction&&(a=this.width-a-c),t.fillStyle=d,d&&t.fillRect(a,s,c,r/this.lineHeight),l=n.left,c=n.width,d=h):c+=n.kernedWidth}h&&!this.path&&(a=i+o+l,"rtl"===this.direction&&(a=this.width-a-c),t.fillStyle=h,t.fillRect(a,s,c,r/this.lineHeight)),s+=r}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,i,s){const r=x.getFontCache(e),n=i+t,o=this._getFontDeclaration(e)===this._getFontDeclaration(s),a=e.fontSize/this.CACHE_FONT_SIZE;let h,c,l,d;if(i&&void 0!==r[i]&&(l=r[i]),void 0!==r[t]&&(d=h=r[t]),o&&void 0!==r[n]&&(c=r[n],d=c-l),void 0===h||void 0===l||void 0===c){const s=(fn||(fn=tt().getContext("2d")),fn);this._setTextStyles(s,e,!0),void 0===h&&(d=h=s.measureText(t).width,r[t]=h),void 0===l&&o&&i&&(l=s.measureText(i).width,r[i]=l),o&&void 0===c&&(c=s.measureText(n).width,r[n]=c,d=c-l)}return{width:h*a,kernedWidth:d*a}}getHeightOfChar(t,e){return this.getValueOfPropertyAt(t,e,"fontSize")}measureLine(t){const e=this._measureLine(t);return 0!==this.charSpacing&&(e.width-=this._getWidthOfCharSpacing()),e.width<0&&(e.width=0),e}_measureLine(t){let e,i,s=0;const r="right"===this.pathSide,n=this.path,o=this._textLines[t],a=o.length,h=new Array(a);this.__charBounds[t]=h;for(let r=0;r<a;r++){const n=o[r];i=this._getGraphemeBox(n,t,r,e),h[r]=i,s+=i.kernedWidth,e=n}if(h[a]={left:i?i.left+i.width:0,width:0,kernedWidth:0,height:this.fontSize},n&&n.segmentsInfo){let t=0;const e=n.segmentsInfo[n.segmentsInfo.length-1].length,o=Or(n.path,0,n.segmentsInfo);switch(o.x+=n.pathOffset.x,o.y+=n.pathOffset.y,this.textAlign){case"left":t=r?e-s:0;break;case"center":t=(e-s)/2;break;case"right":t=r?0:e-s}t+=this.pathStartOffset*(r?-1:1);for(let s=r?a-1:0;r?s>=0:s<a;r?s--:s++)i=h[s],t>e?t%=e:t<0&&(t+=e),this._setGraphemeOnPath(t,i,o),t+=i.kernedWidth}return{width:s,numOfSpaces:0}}_setGraphemeOnPath(t,e,i){const s=t+e.kernedWidth/2,r=this.path,n=Or(r.path,s,r.segmentsInfo);e.renderLeft=n.x-i.x,e.renderTop=n.y-i.y,e.angle=n.angle+("right"===this.pathSide?Math.PI:0)}_getGraphemeBox(t,e,i,s,r){const n=this.getCompleteStyleDeclaration(e,i),o=s?this.getCompleteStyleDeclaration(e,i-1):{},a=this._measureChar(t,n,s,o);let h,c=a.kernedWidth,l=a.width;0!==this.charSpacing&&(h=this._getWidthOfCharSpacing(),l+=h,c+=h);const d={width:l,left:0,height:n.fontSize,kernedWidth:c,deltaY:n.deltaY};if(i>0&&!r){const t=this.__charBounds[e][i-1];d.left=t.left+t.width+a.kernedWidth-a.width}return d}getHeightOfLine(t){if(this.__lineHeights[t])return this.__lineHeights[t];let e=this.getHeightOfChar(t,0);for(let i=1,s=this._textLines[t].length;i<s;i++)e=Math.max(this.getHeightOfChar(t,i),e);return this.__lineHeights[t]=e*this.lineHeight*this._fontSizeMult}calcTextHeight(){let t,e=0;for(let i=0,s=this._textLines.length;i<s;i++)t=this.getHeightOfLine(i),e+=i===s-1?t/this.lineHeight:t;return e}_getLeftOffset(){return"ltr"===this.direction?-this.width/2:this.width/2}_getTopOffset(){return-this.height/2}_renderTextCommon(t,e){t.save();let i=0;const s=this._getLeftOffset(),r=this._getTopOffset();for(let n=0,o=this._textLines.length;n<o;n++){const o=this.getHeightOfLine(n),a=o/this.lineHeight,h=this._getLineLeftOffset(n);this._renderTextLine(e,t,this._textLines[n],s+h,r+i+a,n),i+=o}t.restore()}_renderTextFill(t){(this.fill||this.styleHas("fill"))&&this._renderTextCommon(t,"fillText")}_renderTextStroke(t){(this.stroke&&0!==this.strokeWidth||!this.isEmptyStyles())&&(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this._setLineDash(t,this.strokeDashArray),t.beginPath(),this._renderTextCommon(t,"strokeText"),t.closePath(),t.restore())}_renderChars(t,e,i,s,r,n){const o=this.getHeightOfLine(n),a=-1!==this.textAlign.indexOf("justify"),h=this.path,c=!a&&0===this.charSpacing&&this.isEmptyStyles(n)&&!h,l="ltr"===this.direction,d="ltr"===this.direction?1:-1,u=e.direction;let g,f,p,m,v,_="",x=0;if(e.save(),u!==this.direction&&(e.canvas.setAttribute("dir",l?"ltr":"rtl"),e.direction=l?"ltr":"rtl",e.textAlign=l?"left":"right"),r-=o*this._fontSizeFraction/this.lineHeight,c)return this._renderChar(t,e,n,0,i.join(""),s,r),void e.restore();for(let o=0,c=i.length-1;o<=c;o++)m=o===c||this.charSpacing||h,_+=i[o],p=this.__charBounds[n][o],0===x?(s+=d*(p.kernedWidth-p.width),x+=p.width):x+=p.kernedWidth,a&&!m&&this._reSpaceAndTab.test(i[o])&&(m=!0),m||(g=g||this.getCompleteStyleDeclaration(n,o),f=this.getCompleteStyleDeclaration(n,o+1),m=hn(g,f,!1)),m&&(h?(e.save(),e.translate(p.renderLeft,p.renderTop),e.rotate(p.angle),this._renderChar(t,e,n,o,_,-x/2,0),e.restore()):(v=s,this._renderChar(t,e,n,o,_,v,r)),_="",g=f,s+=d*x,x=0);e.restore()}_applyPatternGradientTransformText(t){const e=tt(),i=this.width+this.strokeWidth,s=this.height+this.strokeWidth,r=e.getContext("2d");return e.width=i,e.height=s,r.beginPath(),r.moveTo(0,0),r.lineTo(i,0),r.lineTo(i,s),r.lineTo(0,s),r.closePath(),r.translate(i/2,s/2),r.fillStyle=t.toLive(r),this._applyPatternGradientTransform(r,t),r.fill(),r.createPattern(e,"no-repeat")}handleFiller(t,e,i){let s,r;return i.toLive?"percentage"===i.gradientUnits||i.gradientTransform||i.patternTransform?(s=-this.width/2,r=-this.height/2,t.translate(s,r),t[e]=this._applyPatternGradientTransformText(i),{offsetX:s,offsetY:r}):(t[e]=i.toLive(t,this),this._applyPatternGradientTransform(t,i)):(t[e]=i,{offsetX:0,offsetY:0})}_setStrokeStyles(t,e){let{stroke:i,strokeWidth:s}=e;return t.lineWidth=s,t.lineCap=this.strokeLineCap,t.lineDashOffset=this.strokeDashOffset,t.lineJoin=this.strokeLineJoin,t.miterLimit=this.strokeMiterLimit,this.handleFiller(t,"strokeStyle",i)}_setFillStyles(t,e){let{fill:i}=e;return this.handleFiller(t,"fillStyle",i)}_renderChar(t,e,i,s,r,n,o){const a=this._getStyleDeclaration(i,s),h=this.getCompleteStyleDeclaration(i,s),c="fillText"===t&&h.fill,l="strokeText"===t&&h.stroke&&h.strokeWidth;let d,u;(l||c)&&(e.save(),c&&(d=this._setFillStyles(e,h)),l&&(u=this._setStrokeStyles(e,h)),e.font=this._getFontDeclaration(h),a&&a.textBackgroundColor&&this._removeShadow(e),a&&a.deltaY&&(o+=a.deltaY),c&&e.fillText(r,n-d.offsetX,o-d.offsetY),l&&e.strokeText(r,n-u.offsetX,o-u.offsetY),e.restore())}setSuperscript(t,e){this._setScript(t,e,this.superscript)}setSubscript(t,e){this._setScript(t,e,this.subscript)}_setScript(t,e,i){const s=this.get2DCursorLocation(t,!0),r=this.getValueOfPropertyAt(s.lineIndex,s.charIndex,"fontSize"),n=this.getValueOfPropertyAt(s.lineIndex,s.charIndex,"deltaY"),o={fontSize:r*i.size,deltaY:n+r*i.baseline};this.setSelectionStyles(o,t,e)}_getLineLeftOffset(t){const e=this.getLineWidth(t),i=this.width-e,s=this.textAlign,r=this.direction,n=this.isEndOfWrapping(t);let o=0;return"justify"===s||"justify-center"===s&&!n||"justify-right"===s&&!n||"justify-left"===s&&!n?0:("center"===s&&(o=i/2),"right"===s&&(o=i),"justify-center"===s&&(o=i/2),"justify-right"===s&&(o=i),"rtl"===r&&("right"===s||"justify"===s||"justify-right"===s?o=0:"left"===s||"justify-left"===s?o=-i:"center"!==s&&"justify-center"!==s||(o=-i/2)),o)}_clearCache(){this._forceClearCache=!1,this.__lineWidths=[],this.__lineHeights=[],this.__charBounds=[]}getLineWidth(t){if(void 0!==this.__lineWidths[t])return this.__lineWidths[t];const{width:e}=this.measureLine(t);return this.__lineWidths[t]=e,e}_getWidthOfCharSpacing(){return 0!==this.charSpacing?this.fontSize*this.charSpacing/1e3:0}getValueOfPropertyAt(t,e,i){const s=this._getStyleDeclaration(t,e);return s&&void 0!==s[i]?s[i]:this[i]}_renderTextDecoration(t,e){if(!this[e]&&!this.styleHas(e))return;let i=this._getTopOffset();const s=this._getLeftOffset(),r=this.path,n=this._getWidthOfCharSpacing(),o=this.offsets[e];for(let a=0,h=this._textLines.length;a<h;a++){const h=this.getHeightOfLine(a);if(!this[e]&&!this.styleHas(e,a)){i+=h;continue}const c=this._textLines[a],l=h/this.lineHeight,d=this._getLineLeftOffset(a);let u,g,f=0,p=0,m=this.getValueOfPropertyAt(a,0,e),v=this.getValueOfPropertyAt(a,0,"fill");const _=i+l*(1-this._fontSizeFraction);let x=this.getHeightOfChar(a,0),y=this.getValueOfPropertyAt(a,0,"deltaY");for(let i=0,n=c.length;i<n;i++){const n=this.__charBounds[a][i];u=this.getValueOfPropertyAt(a,i,e),g=this.getValueOfPropertyAt(a,i,"fill");const h=this.getHeightOfChar(a,i),c=this.getValueOfPropertyAt(a,i,"deltaY");if(r&&u&&g)t.save(),t.fillStyle=v,t.translate(n.renderLeft,n.renderTop),t.rotate(n.angle),t.fillRect(-n.kernedWidth/2,o*h+c,n.kernedWidth,this.fontSize/15),t.restore();else if((u!==m||g!==v||h!==x||c!==y)&&p>0){let e=s+d+f;"rtl"===this.direction&&(e=this.width-e-p),m&&v&&(t.fillStyle=v,t.fillRect(e,_+o*x+y,p,this.fontSize/15)),f=n.left,p=n.width,m=u,v=g,x=h,y=c}else p+=n.kernedWidth}let C=s+d+f;"rtl"===this.direction&&(C=this.width-C-p),t.fillStyle=g,u&&g&&t.fillRect(C,_+o*x+y,p-n,this.fontSize/15),i+=h}this._removeShadow(t)}_getFontDeclaration(t,e){const i=t||this,s=this.fontFamily,r=pn.genericFonts.indexOf(s.toLowerCase())>-1,n=void 0===s||s.indexOf("'")>-1||s.indexOf(",")>-1||s.indexOf('"')>-1||r?i.fontFamily:'"'.concat(i.fontFamily,'"');return[i.fontStyle,i.fontWeight,e?this.CACHE_FONT_SIZE+"px":i.fontSize+"px",n].join(" ")}render(t){this.visible&&(this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(this._forceClearCache&&this.initDimensions(),super.render(t)))}graphemeSplit(t){return nn(t)}_splitTextIntoLines(t){const e=t.split(this._reNewline),i=new Array(e.length),s=["\n"];let r=[];for(let t=0;t<e.length;t++)i[t]=this.graphemeSplit(e[t]),r=r.concat(i[t],s);return r.pop(),{_unwrappedLines:i,lines:e,graphemeText:r,graphemeLines:i}}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return i(i({},super.toObject([...tn,...t])),{},{styles:cn(this.styles,this.text)},this.path?{path:this.path.toObject()}:{})}set(t,e){const{textLayoutProperties:i}=this.constructor;super.set(t,e);let s=!1,r=!1;if("object"==typeof t)for(const e in t)"path"===e&&this.setPathInfo(),s=s||i.includes(e),r=r||"path"===e;else s=i.includes(t),r="path"===t;return r&&this.setPathInfo(),s&&this.initialized&&(this.initDimensions(),this.setCoords()),this}complexity(){return 1}static fromElement(t,e,i){if(!t)return e(null);const s=fs(t,pn.ATTRIBUTE_NAMES),r=s.textAnchor||"left";if((i=Object.assign({},i,s)).top=i.top||0,i.left=i.left||0,s.textDecoration){const t=s.textDecoration;-1!==t.indexOf("underline")&&(i.underline=!0),-1!==t.indexOf("overline")&&(i.overline=!0),-1!==t.indexOf("line-through")&&(i.linethrough=!0),delete i.textDecoration}"dx"in s&&(i.left+=s.dx),"dy"in s&&(i.top+=s.dy),"fontSize"in i||(i.fontSize=O);let n="";"textContent"in t?n=t.textContent:"firstChild"in t&&null!==t.firstChild&&"data"in t.firstChild&&null!==t.firstChild.data&&(n=t.firstChild.data),n=n.replace(/^\s+|\s+$|\n+/g,"").replace(/\s+/g," ");const o=i.strokeWidth;i.strokeWidth=0;const a=new this(n,i),h=a.getScaledHeight()/a.height,c=((a.height+a.strokeWidth)*a.lineHeight-a.height)*h,l=a.getScaledHeight()+c;let d=0;"center"===r&&(d=a.getScaledWidth()/2),"right"===r&&(d=a.getScaledWidth()),a.set({left:a.left-d,top:a.top-(l-a.fontSize*(.07+a._fontSizeFraction))/a.lineHeight,strokeWidth:void 0!==o?o:1}),e(a)}static fromObject(t){return this._fromObject(i(i({},t),{},{styles:ln(t.styles||{},t.text)}),{extraParam:"text"})}}s(pn,"textLayoutProperties",Qr),s(pn,"cacheProperties",[...$e,...tn]),s(pn,"ownDefaults",{_reNewline:/\r?\n/,_reSpacesAndTabs:/[ \t\r]/g,_reSpaceAndTab:/[ \t\r]/,_reWords:/\S+/g,fontSize:40,fontWeight:"normal",fontFamily:"Times New Roman",underline:!1,overline:!1,linethrough:!1,textAlign:"left",fontStyle:"normal",lineHeight:1.16,superscript:{size:.6,baseline:-.35},subscript:{size:.6,baseline:.11},textBackgroundColor:"",stroke:null,shadow:null,path:null,pathStartOffset:0,pathSide:"left",pathAlign:"baseline",_fontSizeFraction:.222,offsets:{underline:.1,linethrough:-.315,overline:-.88},_fontSizeMult:1.13,charSpacing:0,deltaY:0,direction:"ltr",CACHE_FONT_SIZE:400,MIN_TEXT_WIDTH:2}),s(pn,"genericFonts",["sans-serif","serif","cursive","fantasy","monospace"]),s(pn,"ATTRIBUTE_NAMES",Bi.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-anchor")),ji(pn,[class extends pe{_toSVG(){const t=this._getSVGLeftTopOffsets(),e=this._getSVGTextAndBg(t.textTop,t.textLeft);return this._wrapSVGTextAndBg(e)}toSVG(t){return this._createBaseSVGMarkup(this._toSVG(),{reviver:t,noStyle:!0,withShadow:!0})}_getSVGLeftTopOffsets(){return{textLeft:-this.width/2,textTop:-this.height/2,lineTop:this.getHeightOfLine(0)}}_wrapSVGTextAndBg(t){let{textBgRects:e,textSpans:i}=t;const s=this.getSvgTextDecoration(this);return[e.join(""),'\t\t<text xml:space="preserve" ',this.fontFamily?'font-family="'.concat(this.fontFamily.replace(un,"'"),'" '):"",this.fontSize?'font-size="'.concat(this.fontSize,'" '):"",this.fontStyle?'font-style="'.concat(this.fontStyle,'" '):"",this.fontWeight?'font-weight="'.concat(this.fontWeight,'" '):"",s?'text-decoration="'.concat(s,'" '):"","rtl"===this.direction?'direction="'.concat(this.direction,'" '):"",'style="',this.getSvgStyles(!0),'"',this.addPaintOrder()," >",i.join(""),"</text>\n"]}_getSVGTextAndBg(t,e){const i=[],s=[];let r,n=t;this.backgroundColor&&s.push(...gn(this.backgroundColor,-this.width/2,-this.height/2,this.width,this.height));for(let t=0,o=this._textLines.length;t<o;t++)r=this._getLineLeftOffset(t),"rtl"===this.direction&&(r+=this.width),(this.textBackgroundColor||this.styleHas("textBackgroundColor",t))&&this._setSVGTextLineBg(s,t,e+r,n),this._setSVGTextLineText(i,t,e+r,n),n+=this.getHeightOfLine(t);return{textSpans:i,textBgRects:s}}_createTextCharSpan(t,e,i,s){const r=this.getSvgSpanStyles(e,t!==t.trim()||!!t.match(dn)),n=r?'style="'.concat(r,'"'):"",o=e.deltaY,a=o?' dy="'.concat(Tt(o,c.NUM_FRACTION_DIGITS),'" '):"";return'<tspan x="'.concat(Tt(i,c.NUM_FRACTION_DIGITS),'" y="').concat(Tt(s,c.NUM_FRACTION_DIGITS),'" ').concat(a).concat(n,">").concat(rn(t),"</tspan>")}_setSVGTextLineText(t,e,i,s){const r=this.getHeightOfLine(e),n=-1!==this.textAlign.indexOf("justify"),o=this._textLines[e];let a,h,c,l,d,u="",g=0;s+=r*(1-this._fontSizeFraction)/this.lineHeight;for(let r=0,f=o.length-1;r<=f;r++)d=r===f||this.charSpacing,u+=o[r],c=this.__charBounds[e][r],0===g?(i+=c.kernedWidth-c.width,g+=c.width):g+=c.kernedWidth,n&&!d&&this._reSpaceAndTab.test(o[r])&&(d=!0),d||(a=a||this.getCompleteStyleDeclaration(e,r),h=this.getCompleteStyleDeclaration(e,r+1),d=hn(a,h,!0)),d&&(l=this._getStyleDeclaration(e,r)||{},t.push(this._createTextCharSpan(u,l,i,s)),u="",a=h,"rtl"===this.direction?i-=g:i+=g,g=0)}_setSVGTextLineBg(t,e,i,s){const r=this._textLines[e],n=this.getHeightOfLine(e)/this.lineHeight;let o,a,h=0,c=0,l=this.getValueOfPropertyAt(e,0,"textBackgroundColor");for(let d=0;d<r.length;d++)o=this.__charBounds[e][d],a=this.getValueOfPropertyAt(e,d,"textBackgroundColor"),a!==l?(l&&t.push(...gn(l,i+c,s,h,n)),c=o.left,h=o.width,l=a):h+=o.kernedWidth;a&&t.push(...gn(l,i+c,s,h,n))}_getSVGLineTopOffset(t){let e=0,i=0;for(let i=0;i<t;i++)e+=this.getHeightOfLine(i);return i=this.getHeightOfLine(j),{lineTop:e,offset:(this._fontSizeMult-this._fontSizeFraction)*i/(this.lineHeight*this._fontSizeMult)}}getSvgStyles(t){return"".concat(super.getSvgStyles(t)," white-space: pre;")}}]),M.setClass(pn),M.setSVGClass(pn);class mn{constructor(t){s(this,"target",void 0),s(this,"__mouseDownInPlace",!1),s(this,"__dragStartFired",!1),s(this,"__isDraggingOver",!1),s(this,"__dragStartSelection",void 0),s(this,"__dragImageDisposer",void 0),s(this,"_dispose",void 0),this.target=t;const e=[this.target.on("dragenter",this.dragEnterHandler.bind(this)),this.target.on("dragover",this.dragOverHandler.bind(this)),this.target.on("dragleave",this.dragLeaveHandler.bind(this)),this.target.on("dragend",this.dragEndHandler.bind(this)),this.target.on("drop",this.dropHandler.bind(this))];this._dispose=()=>{e.forEach((t=>t())),this._dispose=void 0}}isPointerOverSelection(t){const e=this.target,i=e.getSelectionStartFromPointer(t);return e.isEditing&&i>=e.selectionStart&&i<=e.selectionEnd&&e.selectionStart<e.selectionEnd}start(t){return this.__mouseDownInPlace=this.isPointerOverSelection(t)}isActive(){return this.__mouseDownInPlace}end(t){const e=this.isActive();return e&&!this.__dragStartFired&&(this.target.setCursorByClick(t),this.target.initDelayedCursor(!0)),this.__mouseDownInPlace=!1,this.__dragStartFired=!1,this.__isDraggingOver=!1,e}getDragStartSelection(){return this.__dragStartSelection}setDragImage(t,e){var i;let{selectionStart:s,selectionEnd:r}=e;const n=this.target,o=n.canvas,a=new X(n.flipX?-1:1,n.flipY?-1:1),h=n._getCursorBoundaries(s),c=new X(h.left+h.leftOffset,h.top+h.topOffset).multiply(a).transform(n.calcTransformMatrix()),l=o.getPointer(t).subtract(c),d=o._isRetinaScaling(),u=n.getCanvasRetinaScaling(),g=n.getBoundingRect(!0),f=c.subtract(new X(g.left,g.top)),p=o.viewportTransform,m=f.add(l).transform(p,!0),_=n.backgroundColor,x=Je(n.styles);n.backgroundColor="";const y={stroke:"transparent",fill:"transparent",textBackgroundColor:"transparent"};n.setSelectionStyles(y,0,s),n.setSelectionStyles(y,r,n.text.length),n.dirty=!0;const C=n.toCanvasElement({enableRetinaScaling:d,viewportTransform:!0});n.backgroundColor=_,n.styles=x,n.dirty=!0,Ri(C,{position:"fixed",left:"".concat(-C.width,"px"),border:"none",width:"".concat(C.width/u,"px"),height:"".concat(C.height/u,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{C.remove()},v().body.appendChild(C),null===(i=t.dataTransfer)||void 0===i||i.setDragImage(C,m.x,m.y)}onDragStart(t){this.__dragStartFired=!0;const e=this.target,s=this.isActive();if(s&&t.dataTransfer){const s=this.__dragStartSelection={selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},r=e._text.slice(s.selectionStart,s.selectionEnd).join(""),n=i({text:e.text,value:r},s);t.dataTransfer.setData("text/plain",r),t.dataTransfer.setData("application/fabric",JSON.stringify({value:r,styles:e.getSelectionStyles(s.selectionStart,s.selectionEnd,!0)})),t.dataTransfer.effectAllowed="copyMove",this.setDragImage(t,n)}return e.abortCursorAnimation(),s}canDrop(t){if(this.target.editable&&!this.target.__corner&&!t.defaultPrevented){if(this.isActive()&&this.__dragStartSelection){const e=this.target.getSelectionStartFromPointer(t),i=this.__dragStartSelection;return e<i.selectionStart||e>i.selectionEnd}return!0}return!1}targetCanDrop(t){return this.target.canDrop(t)}dragEnterHandler(t){let{e:e}=t;const i=this.targetCanDrop(e);!this.__isDraggingOver&&i&&(this.__isDraggingOver=!0)}dragOverHandler(t){const{e:e}=t,i=this.targetCanDrop(e);!this.__isDraggingOver&&i?this.__isDraggingOver=!0:this.__isDraggingOver&&!i&&(this.__isDraggingOver=!1),this.__isDraggingOver&&(e.preventDefault(),t.canDrop=!0,t.dropTarget=this.target)}dragLeaveHandler(){(this.__isDraggingOver||this.isActive())&&(this.__isDraggingOver=!1)}dropHandler(t){var e;const{e:i}=t,s=i.defaultPrevented;this.__isDraggingOver=!1,i.preventDefault();let r=null===(e=i.dataTransfer)||void 0===e?void 0:e.getData("text/plain");if(r&&!s){const e=this.target,s=e.canvas;let n=e.getSelectionStartFromPointer(i);const{styles:o}=i.dataTransfer.types.includes("application/fabric")?JSON.parse(i.dataTransfer.getData("application/fabric")):{},a=r[Math.max(0,r.length-1)],h=0;if(this.__dragStartSelection){const t=this.__dragStartSelection.selectionStart,i=this.__dragStartSelection.selectionEnd;n>t&&n<=i?n=t:n>i&&(n-=i-t),e.removeChars(t,i),delete this.__dragStartSelection}e._reNewline.test(a)&&(e._reNewline.test(e._text[n])||n===e._text.length)&&(r=r.trimEnd()),t.didDrop=!0,t.dropTarget=e,e.insertChars(r,o,n),s.setActiveObject(e),e.enterEditing(i),e.selectionStart=Math.min(n+h,e._text.length),e.selectionEnd=Math.min(e.selectionStart+r.length,e._text.length),e.hiddenTextarea.value=e.text,e._updateTextarea(),e.hiddenTextarea.focus(),e.fire("changed",{index:n+h,action:"drop"}),s.fire("text:changed",{target:e}),s.contextTopDirty=!0,s.requestRenderAll()}}dragEndHandler(t){let{e:e}=t;if(this.isActive()&&this.__dragStartFired&&this.__dragStartSelection){var i;const t=this.target,s=this.target.canvas,{selectionStart:r,selectionEnd:n}=this.__dragStartSelection,o=(null===(i=e.dataTransfer)||void 0===i?void 0:i.dropEffect)||"none";"none"===o?(t.selectionStart=r,t.selectionEnd=n,t._updateTextarea(),t.hiddenTextarea.focus()):(t.clearContextTop(),"move"===o&&(t.removeChars(r,n),t.selectionStart=t.selectionEnd=r,t.hiddenTextarea&&(t.hiddenTextarea.value=t.text),t._updateTextarea(),t.fire("changed",{index:r,action:"dragend"}),s.fire("text:changed",{target:t}),s.requestRenderAll()),t.exitEditing())}this.__dragImageDisposer&&this.__dragImageDisposer(),delete this.__dragImageDisposer,delete this.__dragStartSelection,this.__isDraggingOver=!1}dispose(){this._dispose&&this._dispose()}}const vn=/[ \n\.,;!\?\-]/;class _n extends pn{constructor(){super(...arguments),s(this,"_currentCursorOpacity",1)}initBehavior(){this._tick=this._tick.bind(this),this._onTickComplete=this._onTickComplete.bind(this),this.updateSelectionOnMouseMove=this.updateSelectionOnMouseMove.bind(this)}onDeselect(t){return this.isEditing&&this.exitEditing(),this.selected=!1,super.onDeselect(t)}_animateCursor(t){let{toValue:e,duration:i,delay:s,onComplete:r}=t;return Fe({startValue:this._currentCursorOpacity,endValue:e,duration:i,delay:s,onComplete:r,abort:()=>!this.canvas||this.selectionStart!==this.selectionEnd,onChange:t=>{this._currentCursorOpacity=t,this.renderCursorOrSelection()}})}_tick(t){this._currentTickState=this._animateCursor({toValue:1,duration:this.cursorDuration,delay:t,onComplete:this._onTickComplete})}_onTickComplete(){var t;null===(t=this._currentTickCompleteState)||void 0===t||t.abort(),this._currentTickCompleteState=this._animateCursor({toValue:0,duration:this.cursorDuration/2,delay:100,onComplete:this._tick})}initDelayedCursor(t){this.abortCursorAnimation(),this._tick(t?0:this.cursorDelay)}abortCursorAnimation(){let t=!1;[this._currentTickState,this._currentTickCompleteState].forEach((e=>{e&&!e.isDone()&&(t=!0,e.abort())})),this._currentCursorOpacity=1,t&&this.clearContextTop()}restartCursorIfNeeded(){[this._currentTickState,this._currentTickCompleteState].some((t=>!t||t.isDone()))&&this.initDelayedCursor()}selectAll(){return this.selectionStart=0,this.selectionEnd=this._text.length,this._fireSelectionChanged(),this._updateTextarea(),this}getSelectedText(){return this._text.slice(this.selectionStart,this.selectionEnd).join("")}findWordBoundaryLeft(t){let e=0,i=t-1;if(this._reSpace.test(this._text[i]))for(;this._reSpace.test(this._text[i]);)e++,i--;for(;/\S/.test(this._text[i])&&i>-1;)e++,i--;return t-e}findWordBoundaryRight(t){let e=0,i=t;if(this._reSpace.test(this._text[i]))for(;this._reSpace.test(this._text[i]);)e++,i++;for(;/\S/.test(this._text[i])&&i<this._text.length;)e++,i++;return t+e}findLineBoundaryLeft(t){let e=0,i=t-1;for(;!/\n/.test(this._text[i])&&i>-1;)e++,i--;return t-e}findLineBoundaryRight(t){let e=0,i=t;for(;!/\n/.test(this._text[i])&&i<this._text.length;)e++,i++;return t+e}searchWordBoundary(t,e){const i=this._text;let s=this._reSpace.test(i[t])?t-1:t,r=i[s];for(;!vn.test(r)&&s>0&&s<i.length;)s+=e,r=i[s];return vn.test(r)&&(s+=1===e?0:1),s}selectWord(t){t=t||this.selectionStart;const e=this.searchWordBoundary(t,-1),i=this.searchWordBoundary(t,1);this.selectionStart=e,this.selectionEnd=i,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){t=t||this.selectionStart;const e=this.findLineBoundaryLeft(t),i=this.findLineBoundaryRight(t);return this.selectionStart=e,this.selectionEnd=i,this._fireSelectionChanged(),this._updateTextarea(),this}enterEditing(t){!this.isEditing&&this.editable&&(this.canvas&&(this.canvas.calcOffset(),this.canvas.textEditingManager.exitTextEditing()),this.isEditing=!0,this.initHiddenTextarea(),this.hiddenTextarea.focus(),this.hiddenTextarea.value=this.text,this._updateTextarea(),this._saveEditingProps(),this._setEditingProps(),this._textBeforeEdit=this.text,this._tick(),this.fire("editing:entered",{e:t}),this._fireSelectionChanged(),this.canvas&&(this.canvas.fire("text:editing:entered",{target:this,e:t}),this.canvas.requestRenderAll()))}updateSelectionOnMouseMove(t){v().activeElement!==this.hiddenTextarea&&this.hiddenTextarea.focus();const e=this.getSelectionStartFromPointer(t),i=this.selectionStart,s=this.selectionEnd;(e===this.__selectionStartOnMouseDown&&i!==s||i!==e&&s!==e)&&(e>this.__selectionStartOnMouseDown?(this.selectionStart=this.__selectionStartOnMouseDown,this.selectionEnd=e):(this.selectionStart=e,this.selectionEnd=this.__selectionStartOnMouseDown),this.selectionStart===i&&this.selectionEnd===s||(this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()))}_setEditingProps(){this.hoverCursor="text",this.canvas&&(this.canvas.defaultCursor=this.canvas.moveCursor="text"),this.borderColor=this.editingBorderColor,this.hasControls=this.selectable=!1,this.lockMovementX=this.lockMovementY=!0}fromStringToGraphemeSelection(t,e,i){const s=i.slice(0,t),r=this.graphemeSplit(s).length;if(t===e)return{selectionStart:r,selectionEnd:r};const n=i.slice(t,e);return{selectionStart:r,selectionEnd:r+this.graphemeSplit(n).length}}fromGraphemeToStringSelection(t,e,i){const s=i.slice(0,t).join("").length;if(t===e)return{selectionStart:s,selectionEnd:s};return{selectionStart:s,selectionEnd:s+i.slice(t,e).join("").length}}_updateTextarea(){if(this.cursorOffsetCache={},this.hiddenTextarea){if(!this.inCompositionMode){const t=this.fromGraphemeToStringSelection(this.selectionStart,this.selectionEnd,this._text);this.hiddenTextarea.selectionStart=t.selectionStart,this.hiddenTextarea.selectionEnd=t.selectionEnd}this.updateTextareaPosition()}}updateFromTextArea(){if(!this.hiddenTextarea)return;this.cursorOffsetCache={};const t=this.hiddenTextarea;this.text=t.value,this.set("dirty",!0),this.initDimensions(),this.setCoords();const e=this.fromStringToGraphemeSelection(t.selectionStart,t.selectionEnd,t.value);this.selectionEnd=this.selectionStart=e.selectionEnd,this.inCompositionMode||(this.selectionStart=e.selectionStart),this.updateTextareaPosition()}updateTextareaPosition(){if(this.selectionStart===this.selectionEnd){const t=this._calcTextareaPosition();this.hiddenTextarea.style.left=t.left,this.hiddenTextarea.style.top=t.top}}_calcTextareaPosition(){if(!this.canvas)return{left:"1px",top:"1px"};const t=this.inCompositionMode?this.compositionStart:this.selectionStart,e=this._getCursorBoundaries(t),i=this.get2DCursorLocation(t),s=i.lineIndex,r=i.charIndex,n=this.getValueOfPropertyAt(s,r,"fontSize")*this.lineHeight,o=e.leftOffset,a=this.getCanvasRetinaScaling(),h=this.canvas.upperCanvasEl,c=h.width/a,l=h.height/a,d=c-n,u=l-n,g=new X(e.left+o,e.top+e.topOffset+n).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new X(h.clientWidth/c,h.clientHeight/l));return g.x<0&&(g.x=0),g.x>d&&(g.x=d),g.y<0&&(g.y=0),g.y>u&&(g.y=u),g.x+=this.canvas._offset.left,g.y+=this.canvas._offset.top,{left:"".concat(g.x,"px"),top:"".concat(g.y,"px"),fontSize:"".concat(n,"px"),charHeight:n}}_saveEditingProps(){this._savedProps={hasControls:this.hasControls,borderColor:this.borderColor,lockMovementX:this.lockMovementX,lockMovementY:this.lockMovementY,hoverCursor:this.hoverCursor,selectable:this.selectable,defaultCursor:this.canvas&&this.canvas.defaultCursor,moveCursor:this.canvas&&this.canvas.moveCursor}}_restoreEditingProps(){this._savedProps&&(this.hoverCursor=this._savedProps.hoverCursor,this.hasControls=this._savedProps.hasControls,this.borderColor=this._savedProps.borderColor,this.selectable=this._savedProps.selectable,this.lockMovementX=this._savedProps.lockMovementX,this.lockMovementY=this._savedProps.lockMovementY,this.canvas&&(this.canvas.defaultCursor=this._savedProps.defaultCursor||this.canvas.defaultCursor,this.canvas.moveCursor=this._savedProps.moveCursor||this.canvas.moveCursor),delete this._savedProps)}_exitEditing(){const t=this.hiddenTextarea;this.selected=!1,this.isEditing=!1,t&&(t.blur&&t.blur(),t.parentNode&&t.parentNode.removeChild(t)),this.hiddenTextarea=null,this.abortCursorAnimation()}exitEditing(){const t=this._textBeforeEdit!==this.text;return this.selectionEnd=this.selectionStart,this._exitEditing(),this._restoreEditingProps(),this._forceClearCache&&(this.initDimensions(),this.setCoords()),this.fire("editing:exited"),t&&this.fire("modified"),this.canvas&&(this.canvas.fire("text:editing:exited",{target:this}),t&&this.canvas.fire("object:modified",{target:this})),this}_removeExtraneousStyles(){for(const t in this.styles)this._textLines[t]||delete this.styles[t]}removeStyleFromTo(t,e){const{lineIndex:i,charIndex:s}=this.get2DCursorLocation(t,!0),{lineIndex:r,charIndex:n}=this.get2DCursorLocation(e,!0);if(i!==r){if(this.styles[i])for(let t=s;t<this._unwrappedTextLines[i].length;t++)delete this.styles[i][t];if(this.styles[r])for(let t=n;t<this._unwrappedTextLines[r].length;t++){const e=this.styles[r][t];e&&(this.styles[i]||(this.styles[i]={}),this.styles[i][s+t-n]=e)}for(let t=i+1;t<=r;t++)delete this.styles[t];this.shiftLineStyles(r,i-r)}else if(this.styles[i]){const t=this.styles[i],e=n-s;for(let e=s;e<n;e++)delete t[e];for(const s in this.styles[i]){const i=parseInt(s,10);i>=n&&(t[i-e]=t[s],delete t[s])}}}shiftLineStyles(t,e){const i=Object.assign({},this.styles);for(const s in this.styles){const r=parseInt(s,10);r>t&&(this.styles[r+e]=i[r],i[r-e]||delete this.styles[r])}}insertNewlineStyleObject(t,e,s,r){const n={},o=this._unwrappedTextLines[t].length===e;let a=!1;s||(s=1),this.shiftLineStyles(t,s);const h=this.styles[t]?this.styles[t][0===e?e:e-1]:void 0;for(const i in this.styles[t]){const s=parseInt(i,10);s>=e&&(a=!0,n[s-e]=this.styles[t][i],o&&0===e||delete this.styles[t][i])}let c=!1;for(a&&!o&&(this.styles[t+s]=n,c=!0),c&&s--;s>0;)r&&r[s-1]?this.styles[t+s]={0:i({},r[s-1])}:h?this.styles[t+s]={0:i({},h)}:delete this.styles[t+s],s--;this._forceClearCache=!0}insertCharStyleObject(t,e,s,r){this.styles||(this.styles={});const n=this.styles[t],o=n?i({},n):{};s||(s=1);for(const t in o){const i=parseInt(t,10);i>=e&&(n[i+s]=o[i],o[i-s]||delete n[i])}if(this._forceClearCache=!0,r){for(;s--;)Object.keys(r[s]).length&&(this.styles[t]||(this.styles[t]={}),this.styles[t][e+s]=i({},r[s]));return}if(!n)return;const a=n[e?e-1:1];for(;a&&s--;)this.styles[t][e+s]=i({},a)}insertNewStyleBlock(t,e,i){const s=this.get2DCursorLocation(e,!0),r=[0];let n,o=0;for(let e=0;e<t.length;e++)"\n"===t[e]?(o++,r[o]=0):r[o]++;for(r[0]>0&&(this.insertCharStyleObject(s.lineIndex,s.charIndex,r[0],i),i=i&&i.slice(r[0]+1)),o&&this.insertNewlineStyleObject(s.lineIndex,s.charIndex+r[0],o),n=1;n<o;n++)r[n]>0?this.insertCharStyleObject(s.lineIndex+n,0,r[n],i):i&&this.styles[s.lineIndex+n]&&i[0]&&(this.styles[s.lineIndex+n][0]=i[0]),i=i&&i.slice(r[n]+1);r[n]>0&&this.insertCharStyleObject(s.lineIndex+n,0,r[n],i)}removeChars(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t+1;this.removeStyleFromTo(t,e),this._text.splice(t,e-t),this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}insertChars(t,e,i){let s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:i;s>i&&this.removeStyleFromTo(i,s);const r=this.graphemeSplit(t);this.insertNewStyleBlock(r,i,e),this._text=[...this._text.slice(0,i),...r,...this._text.slice(s)],this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}setSelectionStartEndWithShift(t,e,i){i<=t?(e===t?this._selectionDirection="left":"right"===this._selectionDirection&&(this._selectionDirection="left",this.selectionEnd=t),this.selectionStart=i):i>t&&i<e?"right"===this._selectionDirection?this.selectionEnd=i:this.selectionStart=i:(e===t?this._selectionDirection="right":"left"===this._selectionDirection&&(this._selectionDirection="right",this.selectionStart=e),this.selectionEnd=i)}}class xn extends _n{initHiddenTextarea(){this.hiddenTextarea=v().createElement("textarea"),this.hiddenTextarea.setAttribute("autocapitalize","off"),this.hiddenTextarea.setAttribute("autocorrect","off"),this.hiddenTextarea.setAttribute("autocomplete","off"),this.hiddenTextarea.setAttribute("spellcheck","false"),this.hiddenTextarea.setAttribute("data-fabric","textarea"),this.hiddenTextarea.setAttribute("wrap","off");const t=this._calcTextareaPosition();this.hiddenTextarea.style.cssText="position: absolute; top: ".concat(t.top,"; left: ").concat(t.left,"; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; padding-top: ").concat(t.fontSize,";"),this.hiddenTextareaContainer?this.hiddenTextareaContainer.appendChild(this.hiddenTextarea):v().body.appendChild(this.hiddenTextarea),this.hiddenTextarea.addEventListener("blur",this.blur.bind(this)),this.hiddenTextarea.addEventListener("keydown",this.onKeyDown.bind(this)),this.hiddenTextarea.addEventListener("keyup",this.onKeyUp.bind(this)),this.hiddenTextarea.addEventListener("input",this.onInput.bind(this)),this.hiddenTextarea.addEventListener("copy",this.copy.bind(this)),this.hiddenTextarea.addEventListener("cut",this.copy.bind(this)),this.hiddenTextarea.addEventListener("paste",this.paste.bind(this)),this.hiddenTextarea.addEventListener("compositionstart",this.onCompositionStart.bind(this)),this.hiddenTextarea.addEventListener("compositionupdate",this.onCompositionUpdate.bind(this)),this.hiddenTextarea.addEventListener("compositionend",this.onCompositionEnd.bind(this)),!this._clickHandlerInitialized&&this.canvas&&(this.canvas.upperCanvasEl.addEventListener("click",this.onClick.bind(this)),this._clickHandlerInitialized=!0)}onClick(){this.hiddenTextarea&&this.hiddenTextarea.focus()}blur(){this.abortCursorAnimation()}onKeyDown(t){if(!this.isEditing)return;const e="rtl"===this.direction?this.keysMapRtl:this.keysMap;if(t.keyCode in e)this[e[t.keyCode]](t);else{if(!(t.keyCode in this.ctrlKeysMapDown)||!t.ctrlKey&&!t.metaKey)return;this[this.ctrlKeysMapDown[t.keyCode]](t)}t.stopImmediatePropagation(),t.preventDefault(),t.keyCode>=33&&t.keyCode<=40?(this.inCompositionMode=!1,this.clearContextTop(),this.renderCursorOrSelection()):this.canvas&&this.canvas.requestRenderAll()}onKeyUp(t){!this.isEditing||this._copyDone||this.inCompositionMode?this._copyDone=!1:t.keyCode in this.ctrlKeysMapUp&&(t.ctrlKey||t.metaKey)&&(this[this.ctrlKeysMapUp[t.keyCode]](t),t.stopImmediatePropagation(),t.preventDefault(),this.canvas&&this.canvas.requestRenderAll())}onInput(t){const e=this.fromPaste;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const i=()=>{this.updateFromTextArea(),this.fire("changed"),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(""===this.hiddenTextarea.value)return this.styles={},void i();const s=this._splitTextIntoLines(this.hiddenTextarea.value).graphemeText,r=this._text.length,n=s.length,o=this.selectionStart,a=this.selectionEnd,h=o!==a;let l,d,u,g,f=n-r;const p=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value),v=o>p.selectionStart;h?(d=this._text.slice(o,a),f+=a-o):n<r&&(d=v?this._text.slice(a+f,a):this._text.slice(o,o-f));const _=s.slice(p.selectionEnd-f,p.selectionEnd);if(d&&d.length&&(_.length&&(l=this.getSelectionStyles(o,o+1,!1),l=_.map((()=>l[0]))),h?(u=o,g=a):v?(u=a-d.length,g=a):(u=a,g=a+d.length),this.removeStyleFromTo(u,g)),_.length){const{copyPasteData:t}=m();e&&_.join("")===t.copiedText&&!c.disableStyleCopyPaste&&(l=t.copiedTextStyle),this.insertNewStyleBlock(_,o,l)}i()}onCompositionStart(){this.inCompositionMode=!0}onCompositionEnd(){this.inCompositionMode=!1}onCompositionUpdate(t){this.compositionStart=t.target.selectionStart,this.compositionEnd=t.target.selectionEnd,this.updateTextareaPosition()}copy(){if(this.selectionStart===this.selectionEnd)return;const{copyPasteData:t}=m();t.copiedText=this.getSelectedText(),c.disableStyleCopyPaste?t.copiedTextStyle=null:t.copiedTextStyle=this.getSelectionStyles(this.selectionStart,this.selectionEnd,!0),this._copyDone=!0}paste(){this.fromPaste=!0}_getWidthBeforeCursor(t,e){let i,s=this._getLineLeftOffset(t);return e>0&&(i=this.__charBounds[t][e-1],s+=i.left+i.width),s}getDownCursorOffset(t,e){const i=this._getSelectionForOffset(t,e),s=this.get2DCursorLocation(i),r=s.lineIndex;if(r===this._textLines.length-1||t.metaKey||34===t.keyCode)return this._text.length-i;const n=s.charIndex,o=this._getWidthBeforeCursor(r,n),a=this._getIndexOnLine(r+1,o);return this._textLines[r].slice(n).length+a+1+this.missingNewlineOffset(r)}_getSelectionForOffset(t,e){return t.shiftKey&&this.selectionStart!==this.selectionEnd&&e?this.selectionEnd:this.selectionStart}getUpCursorOffset(t,e){const i=this._getSelectionForOffset(t,e),s=this.get2DCursorLocation(i),r=s.lineIndex;if(0===r||t.metaKey||33===t.keyCode)return-i;const n=s.charIndex,o=this._getWidthBeforeCursor(r,n),a=this._getIndexOnLine(r-1,o),h=this._textLines[r].slice(0,n),c=this.missingNewlineOffset(r-1);return-this._textLines[r-1].length+a-h.length+(1-c)}_getIndexOnLine(t,e){const i=this._textLines[t];let s,r,n=this._getLineLeftOffset(t),o=0;for(let a=0,h=i.length;a<h;a++)if(s=this.__charBounds[t][a].width,n+=s,n>e){r=!0;const t=n-s,i=n,h=Math.abs(t-e);o=Math.abs(i-e)<h?a:a-1;break}return r||(o=i.length-1),o}moveCursorDown(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorUpOrDown("Down",t)}moveCursorUp(t){0===this.selectionStart&&0===this.selectionEnd||this._moveCursorUpOrDown("Up",t)}_moveCursorUpOrDown(t,e){const i=this["get".concat(t,"CursorOffset")](e,"right"===this._selectionDirection);if(e.shiftKey?this.moveCursorWithShift(i):this.moveCursorWithoutShift(i),0!==i){const t=this.text.length;this.selectionStart=De(0,this.selectionStart,t),this.selectionEnd=De(0,this.selectionEnd,t),this.abortCursorAnimation(),this._currentCursorOpacity=1,this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(t){const e="left"===this._selectionDirection?this.selectionStart+t:this.selectionEnd+t;return this.setSelectionStartEndWithShift(this.selectionStart,this.selectionEnd,e),0!==t}moveCursorWithoutShift(t){return t<0?(this.selectionStart+=t,this.selectionEnd=this.selectionStart):(this.selectionEnd+=t,this.selectionStart=this.selectionEnd),0!==t}moveCursorLeft(t){0===this.selectionStart&&0===this.selectionEnd||this._moveCursorLeftOrRight("Left",t)}_move(t,e,i){let s;if(t.altKey)s=this["findWordBoundary"+i](this[e]);else{if(!t.metaKey&&35!==t.keyCode&&36!==t.keyCode)return this[e]+="Left"===i?-1:1,!0;s=this["findLineBoundary"+i](this[e])}if(void 0!==s&&this[e]!==s)return this[e]=s,!0}_moveLeft(t,e){return this._move(t,e,"Left")}_moveRight(t,e){return this._move(t,e,"Right")}moveCursorLeftWithoutShift(t){let e=!0;return this._selectionDirection="left",this.selectionEnd===this.selectionStart&&0!==this.selectionStart&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return"right"===this._selectionDirection&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):0!==this.selectionStart?(this._selectionDirection="left",this._moveLeft(t,"selectionStart")):void 0}moveCursorRight(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorLeftOrRight("Right",t)}_moveCursorLeftOrRight(t,e){let i="moveCursor"+t+"With";this._currentCursorOpacity=1,e.shiftKey?i+="Shift":i+="outShift",this[i](e)&&(this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())}moveCursorRightWithShift(t){return"left"===this._selectionDirection&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection="right",this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection="right",this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}function yn(t){return t.button&&1!==t.button}class Cn extends xn{constructor(){super(...arguments),s(this,"draggableTextDelegate",void 0)}initBehavior(){this.on("mousedown",this._mouseDownHandler),this.on("mousedown:before",this._mouseDownHandlerBefore),this.on("mouseup",this.mouseUpHandler),this.on("mousedblclick",this.doubleClickHandler),this.on("tripleclick",this.tripleClickHandler),this.__lastClickTime=+new Date,this.__lastLastClickTime=+new Date,this.__lastPointer={},this.on("mousedown",this.onMouseDown),this.draggableTextDelegate=new mn(this),super.initBehavior()}shouldStartDragging(){return this.draggableTextDelegate.isActive()}onDragStart(t){return this.draggableTextDelegate.onDragStart(t)}canDrop(t){return this.draggableTextDelegate.canDrop(t)}onMouseDown(t){if(!this.canvas)return;this.__newClickTime=+new Date;const e=t.pointer;this.isTripleClick(e)&&(this.fire("tripleclick",t),Ut(t.e)),this.__lastLastClickTime=this.__lastClickTime,this.__lastClickTime=this.__newClickTime,this.__lastPointer=e,this.__lastSelected=this.selected}isTripleClick(t){return this.__newClickTime-this.__lastClickTime<500&&this.__lastClickTime-this.__lastLastClickTime<500&&this.__lastPointer.x===t.x&&this.__lastPointer.y===t.y}doubleClickHandler(t){this.isEditing&&this.selectWord(this.getSelectionStartFromPointer(t.e))}tripleClickHandler(t){this.isEditing&&this.selectLine(this.getSelectionStartFromPointer(t.e))}_mouseDownHandler(t){let{e:e}=t;this.canvas&&this.editable&&!yn(e)&&(this.draggableTextDelegate.start(e)||(this.canvas.textEditingManager.register(this),this.selected&&(this.inCompositionMode=!1,this.setCursorByClick(e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection())))}_mouseDownHandlerBefore(t){let{e:e}=t;this.canvas&&this.editable&&!yn(e)&&(this.selected=this===this.canvas._activeObject)}mouseUpHandler(t){let{e:e,transform:i,button:s}=t;const r=this.draggableTextDelegate.end(e);if(this.canvas){this.canvas.textEditingManager.unregister(this);const t=this.canvas._activeObject;if(t&&t!==this)return}!this.editable||this.group&&!this.group.interactive||i&&i.actionPerformed||yn(e)||r||(this.__lastSelected&&!this.__corner?(this.selected=!1,this.__lastSelected=!1,this.enterEditing(e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection()):this.selected=!0)}setCursorByClick(t){const e=this.getSelectionStartFromPointer(t),i=this.selectionStart,s=this.selectionEnd;t.shiftKey?this.setSelectionStartEndWithShift(i,s,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())}getLocalPointer(t){return ot(t,at(this.calcTransformMatrix())).add(new X(this.width/2,this.height/2))}getSelectionStartFromPointer(t){const e=this.getLocalPointer(this.canvas.getPointer(t));let i=0,s=0,r=0;for(let t=0,n=this._textLines.length;t<n&&i<=e.y;t++)i+=this.getHeightOfLine(t),r=t,t>0&&(s+=this._textLines[t-1].length+this.missingNewlineOffset(t-1));let n=Math.abs(this._getLineLeftOffset(r));const o=this._textLines[r].length;"rtl"===this.direction&&(e.x=this.width-e.x);let a=0;for(let t=0;t<o&&(a=n,n+=this.__charBounds[r][t].kernedWidth,n<=e.x);t++)s++;return this._getNewSelectionStartFromOffset(e,a,n,s,o)}_getNewSelectionStartFromOffset(t,e,i,s,r){const n=t.x-e,o=i-t.x;let a=s+(o>n||o<0?0:1);return this.flipX&&(a=r-a),a>this._text.length&&(a=this._text.length),a}}const bn={selectionStart:0,selectionEnd:0,selectionColor:"rgba(17,119,255,0.3)",isEditing:!1,editable:!0,editingBorderColor:"rgba(102,153,255,0.25)",cursorWidth:2,cursorColor:"",cursorDelay:1e3,cursorDuration:600,caching:!0,hiddenTextareaContainer:null,_selectionDirection:null,_reSpace:/\s|\n/,inCompositionMode:!1,keysMap:{9:"exitEditing",27:"exitEditing",33:"moveCursorUp",34:"moveCursorDown",35:"moveCursorRight",36:"moveCursorLeft",37:"moveCursorLeft",38:"moveCursorUp",39:"moveCursorRight",40:"moveCursorDown"},keysMapRtl:{9:"exitEditing",27:"exitEditing",33:"moveCursorUp",34:"moveCursorDown",35:"moveCursorLeft",36:"moveCursorRight",37:"moveCursorRight",38:"moveCursorUp",39:"moveCursorLeft",40:"moveCursorDown"},ctrlKeysMapDown:{65:"selectAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}};class Sn extends Cn{static getDefaults(){return i(i({},super.getDefaults()),Sn.ownDefaults)}get type(){return"i-text"}constructor(t,e){super(t,e),this.initBehavior()}_set(t,e){return this.isEditing&&this._savedProps&&t in this._savedProps?(this._savedProps[t]=e,this):("canvas"===t&&(this.canvas instanceof Es&&this.canvas.textEditingManager.remove(this),e instanceof Es&&e.textEditingManager.add(this)),super._set(t,e))}setSelectionStart(t){t=Math.max(t,0),this._updateAndFire("selectionStart",t)}setSelectionEnd(t){t=Math.min(t,this.text.length),this._updateAndFire("selectionEnd",t)}_updateAndFire(t,e){this[t]!==e&&(this._fireSelectionChanged(),this[t]=e),this._updateTextarea()}_fireSelectionChanged(){this.fire("selection:changed"),this.canvas&&this.canvas.fire("text:selection:changed",{target:this})}initDimensions(){this.isEditing&&this.initDelayedCursor(),super.initDimensions()}getSelectionStyles(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.selectionStart||0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.selectionEnd,i=arguments.length>2?arguments[2]:void 0;return super.getSelectionStyles(t,e,i)}setSelectionStyles(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.selectionStart||0,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.selectionEnd;return super.setSelectionStyles(t,e,i)}get2DCursorLocation(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;return super.get2DCursorLocation(t,e)}render(t){super.render(t),this.cursorOffsetCache={},this.renderCursorOrSelection()}toCanvasElement(t){const e=this.isEditing;this.isEditing=!1;const i=super.toCanvasElement(t);return this.isEditing=e,i}renderCursorOrSelection(){if(!this.isEditing)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries();this.selectionStart===this.selectionEnd?this.renderCursor(t,e):this.renderSelection(t,e),this.canvas.contextTopDirty=!0,t.restore()}_getCursorBoundaries(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;const i=this._getLeftOffset(),s=this._getTopOffset(),r=this._getCursorBoundariesOffsets(t,e);return{left:i,top:s,leftOffset:r.left,topOffset:r.top}}_getCursorBoundariesOffsets(t,e){return e?this.__getCursorBoundariesOffsets(t):this.cursorOffsetCache&&"top"in this.cursorOffsetCache?this.cursorOffsetCache:this.cursorOffsetCache=this.__getCursorBoundariesOffsets(t)}__getCursorBoundariesOffsets(t){let e=0,i=0;const{charIndex:s,lineIndex:r}=this.get2DCursorLocation(t);for(let t=0;t<r;t++)e+=this.getHeightOfLine(t);const n=this._getLineLeftOffset(r),o=this.__charBounds[r][s];o&&(i=o.left),0!==this.charSpacing&&s===this._textLines[r].length&&(i-=this._getWidthOfCharSpacing());const a={top:e,left:n+(i>0?i:0)};return"rtl"===this.direction&&("right"===this.textAlign||"justify"===this.textAlign||"justify-right"===this.textAlign?a.left*=-1:"left"===this.textAlign||"justify-left"===this.textAlign?a.left=n-(i>0?i:0):"center"!==this.textAlign&&"justify-center"!==this.textAlign||(a.left=n-(i>0?i:0))),a}renderCursorAt(t){const e=this._getCursorBoundaries(t,!0);this._renderCursor(this.canvas.contextTop,e,t)}renderCursor(t,e){this._renderCursor(t,e,this.selectionStart)}_renderCursor(t,e,i){const s=this.get2DCursorLocation(i),r=s.lineIndex,n=s.charIndex>0?s.charIndex-1:0,o=this.getValueOfPropertyAt(r,n,"fontSize"),a=this.scaleX*this.canvas.getZoom(),h=this.cursorWidth/a,c=this.getValueOfPropertyAt(r,n,"deltaY"),l=e.topOffset+(1-this._fontSizeFraction)*this.getHeightOfLine(r)/this.lineHeight-o*(1-this._fontSizeFraction);this.inCompositionMode&&this.renderSelection(t,e),t.fillStyle=this.cursorColor||this.getValueOfPropertyAt(r,n,"fill"),t.globalAlpha=this._currentCursorOpacity,t.fillRect(e.left+e.leftOffset-h/2,l+e.top+c,h,o)}renderSelection(t,e){const i={selectionStart:this.inCompositionMode?this.hiddenTextarea.selectionStart:this.selectionStart,selectionEnd:this.inCompositionMode?this.hiddenTextarea.selectionEnd:this.selectionEnd};this._renderSelection(t,i,e)}renderDragSourceEffect(){const t=this.draggableTextDelegate.getDragStartSelection();this._renderSelection(this.canvas.contextTop,t,this._getCursorBoundaries(t.selectionStart,!0))}renderDropTargetEffect(t){const e=this.getSelectionStartFromPointer(t);this.renderCursorAt(e)}_renderSelection(t,e,i){const s=e.selectionStart,r=e.selectionEnd,n=-1!==this.textAlign.indexOf("justify"),o=this.get2DCursorLocation(s),a=this.get2DCursorLocation(r),h=o.lineIndex,c=a.lineIndex,l=o.charIndex<0?0:o.charIndex,d=a.charIndex<0?0:a.charIndex;for(let e=h;e<=c;e++){const s=this._getLineLeftOffset(e)||0;let r=this.getHeightOfLine(e),o=0,a=0,u=0;if(e===h&&(a=this.__charBounds[h][l].left),e>=h&&e<c)u=n&&!this.isEndOfWrapping(e)?this.width:this.getLineWidth(e)||5;else if(e===c)if(0===d)u=this.__charBounds[c][d].left;else{const t=this._getWidthOfCharSpacing();u=this.__charBounds[c][d-1].left+this.__charBounds[c][d-1].width-t}o=r,(this.lineHeight<1||e===c&&this.lineHeight>1)&&(r/=this.lineHeight);let g=i.left+s+a,f=r,p=0;const m=u-a;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",f=1,p=r):t.fillStyle=this.selectionColor,"rtl"===this.direction&&("right"===this.textAlign||"justify"===this.textAlign||"justify-right"===this.textAlign?g=this.width-g-m:"left"===this.textAlign||"justify-left"===this.textAlign?g=i.left+s-u:"center"!==this.textAlign&&"justify-center"!==this.textAlign||(g=i.left+s-u)),t.fillRect(g,i.top+i.topOffset+p,m,f),i.topOffset+=o}}getCurrentCharFontSize(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,"fontSize")}getCurrentCharColor(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,"fill")}_getCurrentCharIndex(){const t=this.get2DCursorLocation(this.selectionStart,!0),e=t.charIndex>0?t.charIndex-1:0;return{l:t.lineIndex,c:e}}dispose(){this._exitEditing(),this.draggableTextDelegate.dispose(),super.dispose()}}s(Sn,"ownDefaults",bn),M.setClass(Sn),M.setClass(Sn,"i-text");class wn extends Sn{static getDefaults(){return i(i({},super.getDefaults()),{},{controls:Pi()},wn.ownDefaults)}initDimensions(){this.initialized&&(this.isEditing&&this.initDelayedCursor(),this._clearCache(),this.dynamicMinWidth=0,this._styleMap=this._generateStyleMap(this._splitText()),this.dynamicMinWidth>this.width&&this._set("width",this.dynamicMinWidth),-1!==this.textAlign.indexOf("justify")&&this.enlargeSpaces(),this.height=this.calcTextHeight())}_generateStyleMap(t){let e=0,i=0,s=0;const r={};for(let n=0;n<t.graphemeLines.length;n++)"\n"===t.graphemeText[s]&&n>0?(i=0,s++,e++):!this.splitByGrapheme&&this._reSpaceAndTab.test(t.graphemeText[s])&&n>0&&(i++,s++),r[n]={line:e,offset:i},s+=t.graphemeLines[n].length,i+=t.graphemeLines[n].length;return r}styleHas(t,e){if(this._styleMap&&!this.isWrapping){const t=this._styleMap[e];t&&(e=t.line)}return super.styleHas(t,e)}isEmptyStyles(t){if(!this.styles)return!0;let e,i=0,s=t+1,r=!1;const n=this._styleMap[t],o=this._styleMap[t+1];n&&(t=n.line,i=n.offset),o&&(s=o.line,r=s===t,e=o.offset);const a=void 0===t?this.styles:{line:this.styles[t]};for(const t in a)for(const s in a[t])if(s>=i&&(!r||s<e))for(const e in a[t][s])return!1;return!0}_getStyleDeclaration(t,e){if(this._styleMap&&!this.isWrapping){const i=this._styleMap[t];if(!i)return null;t=i.line,e=i.offset+e}return super._getStyleDeclaration(t,e)}_setStyleDeclaration(t,e,i){const s=this._styleMap[t];t=s.line,e=s.offset+e,this.styles[t][e]=i}_deleteStyleDeclaration(t,e){const i=this._styleMap[t];t=i.line,e=i.offset+e,delete this.styles[t][e]}_getLineStyle(t){const e=this._styleMap[t];return!!this.styles[e.line]}_setLineStyle(t){const e=this._styleMap[t];this.styles[e.line]={}}_wrapText(t,e){const i=[];this.isWrapping=!0;for(let s=0;s<t.length;s++)i.push(...this._wrapLine(t[s],s,e));return this.isWrapping=!1,i}_measureWord(t,e){let i,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=0;for(let n=0,o=t.length;n<o;n++){r+=this._getGraphemeBox(t[n],e,n+s,i,true).kernedWidth,i=t[n]}return r}wordSplit(t){return t.split(this._wordJoiners)}_wrapLine(t,e,i){let s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;const r=this._getWidthOfCharSpacing(),n=this.splitByGrapheme,o=[],a=n?this.graphemeSplit(t):this.wordSplit(t),h=n?"":" ";let c=0,l=[],d=0,u=0,g=0,f=!0;0===a.length&&a.push([]),i-=s;const p=a.map((t=>{t=n?t:this.graphemeSplit(t);const i=this._measureWord(t,e,d);return g=Math.max(i,g),d+=t.length+1,{word:t,width:i}})),m=Math.max(i,g,this.dynamicMinWidth);let v;for(d=0,v=0;v<a.length;v++){const t=p[v].word,i=p[v].width;d+=t.length,c+=u+i-r,c>m&&!f?(o.push(l),l=[],c=i,f=!0):c+=r,f||n||l.push(h),l=l.concat(t),u=n?0:this._measureWord([h],e,d),d++,f=!1}return v&&o.push(l),g+s>this.dynamicMinWidth&&(this.dynamicMinWidth=g-r+s),o}isEndOfWrapping(t){return!this._styleMap[t+1]||this._styleMap[t+1].line!==this._styleMap[t].line}missingNewlineOffset(t){return this.splitByGrapheme?this.isEndOfWrapping(t)?1:0:1}_splitTextIntoLines(t){const e=super._splitTextIntoLines(t),i=this._wrapText(e.lines,this.width),s=new Array(i.length);for(let t=0;t<i.length;t++)s[t]=i[t].join("");return e.lines=s,e.graphemeLines=i,e}getMinWidth(){return Math.max(this.minWidth,this.dynamicMinWidth)}_removeExtraneousStyles(){const t={};for(const e in this._styleMap)this._textLines[e]&&(t[this._styleMap[e].line]=1);for(const e in this.styles)t[e]||delete this.styles[e]}toObject(t){return super.toObject(["minWidth","splitByGrapheme"].concat(t))}}s(wn,"textLayoutProperties",[...Sn.textLayoutProperties,"width"]),s(wn,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),M.setClass(wn);class Tn{constructor(){s(this,"resources",{})}applyFilters(t,e,i,s,r){const n=r.getContext("2d");if(!n)return;n.drawImage(e,0,0,i,s);const o={sourceWidth:i,sourceHeight:s,imageData:n.getImageData(0,0,i,s),originalEl:e,originalImageData:n.getImageData(0,0,i,s),canvasEl:r,ctx:n,filterBackend:this};t.forEach((t=>{t.applyTo(o)}));const{imageData:a}=o;return a.width===i&&a.height===s||(r.width=a.width,r.height=a.height),n.putImageData(a,0,0),o}}class On{constructor(){let{tileSize:t=c.textureSize}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};s(this,"aPosition",new Float32Array([0,0,0,1,1,0,1,1])),s(this,"resources",{}),this.tileSize=t,this.setupGLContext(t,t),this.captureGPUInfo()}setupGLContext(t,e){this.dispose(),this.createWebGLCanvas(t,e),this.chooseFastestCopyGLTo2DMethod(t,e)}chooseFastestCopyGLTo2DMethod(t,e){const i=tt(),s=new ArrayBuffer(t*e*4);if(c.forceGLPutImageData)return this.imageBuffer=s,void(this.copyGLTo2D=kn);const r={imageBuffer:s},n={destinationWidth:t,destinationHeight:e,targetCanvas:i};let o;i.width=t,i.height=e,o=_().performance.now(),this.copyGLTo2D.call(r,this.gl,n);const a=_().performance.now()-o;o=_().performance.now(),kn.call(r,this.gl,n);a>_().performance.now()-o&&(this.imageBuffer=s,this.copyGLTo2D=kn)}createWebGLCanvas(t,e){const i=tt();i.width=t,i.height=e;const s=i.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,depth:!1,stencil:!1,antialias:!1});s&&(s.clearColor(0,0,0,0),this.canvas=i,this.gl=s)}applyFilters(t,e,i,s,r,n){const o=this.gl,a=r.getContext("2d");if(!o||!a)return;let h;n&&(h=this.getCachedTexture(n,e));const c={originalWidth:e.width||e.originalWidth||0,originalHeight:e.height||e.originalHeight||0,sourceWidth:i,sourceHeight:s,destinationWidth:i,destinationHeight:s,context:o,sourceTexture:this.createTexture(o,i,s,h?void 0:e),targetTexture:this.createTexture(o,i,s),originalTexture:h||this.createTexture(o,i,s,h?void 0:e),passes:t.length,webgl:!0,aPosition:this.aPosition,programCache:this.programCache,pass:0,filterBackend:this,targetCanvas:r},l=o.createFramebuffer();return o.bindFramebuffer(o.FRAMEBUFFER,l),t.forEach((t=>{t&&t.applyTo(c)})),function(t){const e=t.targetCanvas,i=e.width,s=e.height,r=t.destinationWidth,n=t.destinationHeight;i===r&&s===n||(e.width=r,e.height=n)}(c),this.copyGLTo2D(o,c),o.bindTexture(o.TEXTURE_2D,null),o.deleteTexture(c.sourceTexture),o.deleteTexture(c.targetTexture),o.deleteFramebuffer(l),a.setTransform(1,0,0,1,0,0),c}dispose(){this.canvas&&(this.canvas=null,this.gl=null),this.clearWebGLCaches()}clearWebGLCaches(){this.programCache={},this.textureCache={}}createTexture(t,e,i,s){const r=t.createTexture();return t.bindTexture(t.TEXTURE_2D,r),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),s?t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,s):t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e,i,0,t.RGBA,t.UNSIGNED_BYTE,null),r}getCachedTexture(t,e){if(this.textureCache[t])return this.textureCache[t];{const i=this.createTexture(this.gl,e.width,e.height,e);return this.textureCache[t]=i,i}}evictCachesForKey(t){this.textureCache[t]&&(this.gl.deleteTexture(this.textureCache[t]),delete this.textureCache[t])}copyGLTo2D(t,e){const i=t.canvas,s=e.targetCanvas,r=s.getContext("2d");if(!r)return;r.translate(0,s.height),r.scale(1,-1);const n=i.height-s.height;r.drawImage(i,0,n,s.width,s.height,0,0,s.width,s.height)}captureGPUInfo(){if(this.gpuInfo)return this.gpuInfo;const t=this.gl,e={renderer:"",vendor:""};if(!t)return e;const i=t.getExtension("WEBGL_debug_renderer_info");if(i){const s=t.getParameter(i.UNMASKED_RENDERER_WEBGL),r=t.getParameter(i.UNMASKED_VENDOR_WEBGL);s&&(e.renderer=s.toLowerCase()),r&&(e.vendor=r.toLowerCase())}return this.gpuInfo=e,e}}function kn(t,e){const i=e.targetCanvas.getContext("2d"),s=e.destinationWidth,r=e.destinationHeight,n=s*r*4;if(!i)return;const o=new Uint8Array(this.imageBuffer,0,n),a=new Uint8ClampedArray(this.imageBuffer,0,n);t.readPixels(0,0,s,r,t.RGBA,t.UNSIGNED_BYTE,o);const h=new ImageData(a,s,r);i.putImageData(h,0,0)}let Dn;function En(){const{WebGLProbe:t}=m();return t.queryWebGL(tt()),c.enableGLFiltering&&t.isSupported(c.textureSize)?new On({tileSize:c.textureSize}):new Tn}function Mn(){return!Dn&&(!(arguments.length>0&&void 0!==arguments[0])||arguments[0])&&(Dn=En()),Dn}const Pn=(t,e)=>Math.min(e.width/t.width,e.height/t.height),An=(t,e)=>Math.max(e.width/t.width,e.height/t.height),jn=["filters","resizeFilter","src","crossOrigin"],Fn=["cropX","cropY"];class Ln extends Fi{static getDefaults(){return i(i({},super.getDefaults()),Ln.ownDefaults)}constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(i({filters:[]},e)),s(this,"_lastScaleX",1),s(this,"_lastScaleY",1),s(this,"_filterScalingX",1),s(this,"_filterScalingY",1),this.cacheKey="texture".concat(Q()),this.setElement("string"==typeof t?v().getElementById(t):t,e)}getElement(){return this._element}setElement(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._element=t,this._originalElement=t,this._setWidthHeight(e),t.classList.add(Ln.CSS_CANVAS),0!==this.filters.length&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=Mn(!1);e instanceof On&&e.evictCachesForKey(t)}dispose(){super.dispose(),this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._cacheContext=null,["_originalElement","_element","_filteredEl","_cacheCanvas"].forEach((t=>{m().dispose(this[t]),this[t]=void 0}))}getCrossOrigin(){return this._originalElement&&(this._originalElement.crossOrigin||null)}getOriginalSize(){const t=this.getElement();return t?{width:t.naturalWidth||t.width,height:t.naturalHeight||t.height}:{width:0,height:0}}_stroke(t){if(!this.stroke||0===this.strokeWidth)return;const e=this.width/2,i=this.height/2;t.beginPath(),t.moveTo(-e,-i),t.lineTo(e,-i),t.lineTo(e,i),t.lineTo(-e,i),t.lineTo(-e,-i),t.closePath()}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const e=[];return this.filters.forEach((t=>{t&&e.push(t.toObject())})),i(i({},super.toObject([...Fn,...t])),{},{src:this.getSrc(),crossOrigin:this.getCrossOrigin(),filters:e},this.resizeFilter?{resizeFilter:this.resizeFilter.toObject()}:{})}hasCrop(){return!!this.cropX||!!this.cropY||this.width<this._element.width||this.height<this._element.height}_toSVG(){const t=[],e=this._element,i=-this.width/2,s=-this.height/2;let r,n=[],o="",a="";if(!e)return[];if(this.hasCrop()){const t=Q();n.push('<clipPath id="imageCrop_'+t+'">\n','\t<rect x="'+i+'" y="'+s+'" width="'+this.width+'" height="'+this.height+'" />\n',"</clipPath>\n"),o=' clip-path="url(#imageCrop_'+t+')" '}if(this.imageSmoothing||(a='" image-rendering="optimizeSpeed'),t.push("\t<image ","COMMON_PARTS",'xlink:href="',this.getSvgSrc(!0),'" x="',i-this.cropX,'" y="',s-this.cropY,'" width="',e.width||e.naturalWidth,'" height="',e.height||e.naturalHeight,a,'"',o,"></image>\n"),this.stroke||this.strokeDashArray){const t=this.fill;this.fill=null,r=["\t<rect ",'x="',i,'" y="',s,'" width="',this.width,'" height="',this.height,'" style="',this.getSvgStyles(),'"/>\n'],this.fill=t}return n="fill"!==this.paintFirst?n.concat(r,t):n.concat(t,r),n}getSrc(t){const e=t?this._element:this._originalElement;return e?e.toDataURL?e.toDataURL():this.srcFromAttribute?e.getAttribute("src"):e.src:this.src||""}getSvgSrc(t){return this.getSrc(t)}setSrc(t){let{crossOrigin:e,signal:i}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return gt(t,{crossOrigin:e,signal:i}).then((t=>{void 0!==e&&this.set({crossOrigin:e}),this.setElement(t)}))}toString(){return'#<Image: { src: "'.concat(this.getSrc(),'" }>')}applyResizeFilters(){const t=this.resizeFilter,e=this.minimumScaleTrigger,i=this.getTotalObjectScaling(),s=i.x,r=i.y,n=this._filteredEl||this._originalElement;if(this.group&&this.set("dirty",!0),!t||s>e&&r>e)return this._element=n,this._filterScalingX=1,this._filterScalingY=1,this._lastScaleX=s,void(this._lastScaleY=r);const o=tt(),a=n.width,h=n.height;o.width=a,o.height=h,this._element=o,this._lastScaleX=t.scaleX=s,this._lastScaleY=t.scaleY=r,Mn().applyFilters([t],n,a,h,this._element),this._filterScalingX=o.width/this._originalElement.width,this._filterScalingY=o.height/this._originalElement.height}applyFilters(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.filters||[];if(t=t.filter((t=>t&&!t.isNeutralState())),this.set("dirty",!0),this.removeTexture("".concat(this.cacheKey,"_filtered")),0===t.length)return this._element=this._originalElement,this._filteredEl=null,this._filterScalingX=1,void(this._filterScalingY=1);const e=this._originalElement,i=e.naturalWidth||e.width,s=e.naturalHeight||e.height;if(this._element===this._originalElement){const t=tt();t.width=i,t.height=s,this._element=t,this._filteredEl=t}else this._element=this._filteredEl,this._filteredEl.getContext("2d").clearRect(0,0,i,s),this._lastScaleX=1,this._lastScaleY=1;Mn().applyFilters(t,this._originalElement,i,s,this._element),this._originalElement.width===this._element.width&&this._originalElement.height===this._element.height||(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height)}_render(t){t.imageSmoothingEnabled=this.imageSmoothing,!0!==this.isMoving&&this.resizeFilter&&this._needsResize()&&this.applyResizeFilters(),this._stroke(t),this._renderPaintInOrder(t)}drawCacheOnCanvas(t){t.imageSmoothingEnabled=this.imageSmoothing,super.drawCacheOnCanvas(t)}shouldCache(){return this.needsItsOwnCache()}_renderFill(t){const e=this._element;if(!e)return;const i=this._filterScalingX,s=this._filterScalingY,r=this.width,n=this.height,o=Math.max(this.cropX,0),a=Math.max(this.cropY,0),h=e.naturalWidth||e.width,c=e.naturalHeight||e.height,l=o*i,d=a*s,u=Math.min(r*i,h-l),g=Math.min(n*s,c-d),f=-r/2,p=-n/2,m=Math.min(r,h/i-o),v=Math.min(n,c/s-a);e&&t.drawImage(e,l,d,u,g,f,p,m,v)}_needsResize(){const t=this.getTotalObjectScaling();return t.x!==this._lastScaleX||t.y!==this._lastScaleY}_resetWidthHeight(){this.set(this.getOriginalSize())}_setWidthHeight(){let{width:t,height:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const i=this.getOriginalSize();this.width=t||i.width,this.height=e||i.height}parsePreserveAspectRatioAttribute(){const t=Et(this.preserveAspectRatio||""),e=this.width,i=this.height,s={width:e,height:i};let r,n=this._element.width,o=this._element.height,a=1,h=1,c=0,l=0,d=0,u=0;return!t||"none"===t.alignX&&"none"===t.alignY?(a=e/n,h=i/o):("meet"===t.meetOrSlice&&(a=h=Pn(this._element,s),r=(e-n*a)/2,"Min"===t.alignX&&(c=-r),"Max"===t.alignX&&(c=r),r=(i-o*h)/2,"Min"===t.alignY&&(l=-r),"Max"===t.alignY&&(l=r)),"slice"===t.meetOrSlice&&(a=h=An(this._element,s),r=n-e/a,"Mid"===t.alignX&&(d=r/2),"Max"===t.alignX&&(d=r),r=o-i/h,"Mid"===t.alignY&&(u=r/2),"Max"===t.alignY&&(u=r),n=e/a,o=i/h)),{width:n,height:o,scaleX:a,scaleY:h,offsetLeft:c,offsetTop:l,cropX:d,cropY:u}}static fromObject(t,e){let{filters:s,resizeFilter:r,src:o,crossOrigin:a}=t,h=n(t,jn);return Promise.all([gt(o,i(i({},e),{},{crossOrigin:a})),s&&ft(s,e),r&&ft([r],e),pt(h,e)]).then((t=>{let[e,s=[],[r]=[],n={}]=t;return new this(e,i(i({},h),{},{src:o,crossOrigin:a,filters:s,resizeFilter:r},n))}))}static fromURL(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return gt(t,e).then((t=>new this(t,e)))}static fromElement(t,e){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const r=fs(t,this.ATTRIBUTE_NAMES);this.fromURL(r["xlink:href"],i(i({},s),r)).then(e)}}s(Ln,"cacheProperties",[...$e,...Fn]),s(Ln,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),s(Ln,"CSS_CANVAS","canvas-img"),s(Ln,"ATTRIBUTE_NAMES",[...Bi,"x","y","width","height","preserveAspectRatio","xlink:href","crossOrigin","image-rendering"]),M.setClass(Ln),M.setSVGClass(Ln);function Rn(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=e.method?e.method.toUpperCase():"GET",s=e.onComplete||C,r=new(_().XMLHttpRequest),n=e.body||e.parameters,o=e.signal,a=function(){r.abort()},h=function(){o&&o.removeEventListener("abort",a),r.onerror=r.ontimeout=C};if(o&&o.aborted)throw new Error("`options.signal` is in `aborted` state");if(o&&o.addEventListener("abort",a,{once:!0}),r.onreadystatechange=function(){4===r.readyState&&(h(),s(r),r.onreadystatechange=C)},r.onerror=r.ontimeout=h,"GET"===i&&e.parameters){const{origin:i,pathname:s,searchParams:r}=new URL(t);t="".concat(i).concat(s,"?").concat(new URLSearchParams([...Array.from(r.entries()),...Object.entries(e.parameters)]))}return r.open(i,t,!0),"POST"!==i&&"PUT"!==i||r.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),r.send("GET"===i?null:n),r}const Bn=(t,e)=>{let i=t._findCenterFromElement();t.transformMatrix&&((t=>{if(t.transformMatrix){const{scaleX:e,scaleY:i,angle:s,skewX:r}=ct(t.transformMatrix);t.flipX=!1,t.flipY=!1,t.set("scaleX",e),t.set("scaleY",i),t.angle=s,t.skewX=r,t.skewY=0}})(t),i=i.transform(t.transformMatrix)),delete t.transformMatrix,e&&(t.scaleX*=e.scaleX,t.scaleY*=e.scaleY,t.cropX=e.cropX,t.cropY=e.cropY,i.x+=e.offsetLeft,i.y+=e.offsetTop,t.width=e.width,t.height=e.height),t.setPositionByOrigin(i,"center","center")};var In=Object.freeze({__proto__:null,addTransformToObject:Kt,animate:Fe,animateColor:Le,applyTransformToObject:Jt,calcAngleBetweenVectors:Ye,calcDimensionsMatrix:dt,calcPlaneChangeMatrix:ee,calcRotateMatrix:lt,cancelAnimFrame:N,capValue:De,composeMatrix:ut,copyCanvasElement:t=>{var e;const i=tt();return i.width=t.width,i.height=t.height,null===(e=i.getContext("2d"))||void 0===e||e.drawImage(t,0,0),i},cos:B,createCanvasElement:tt,createImage:et,createVector:Ie,degreesToRadians:st,ease:Ce,enlivenObjectEnlivables:pt,enlivenObjects:ft,findScaleToCover:An,findScaleToFit:Pn,getBisector:Ve,getBoundsOfCurve:ur,getElementOffset:J,getPathSegmentsInfo:Tr,getPointOnPath:Or,getPointer:zt,getRandomInt:F,getRegularPolygonPath:(t,e)=>{const i=2*Math.PI/t;let s=-b;t%2==0&&(s+=i/2);const r=new Array(t+1);for(let n=0;n<t;n++){const t=n*i+s,{x:o,y:a}=new X(B(t),I(t)).scalarMultiply(e);r[n]=[0===n?"M":"L",o,a]}return r[t]=["Z"],r},getSmoothPathFromPoints:Dr,getSvgAttributes:t=>{const e=["instantiated_by_use","style","id","class"];switch(t){case z.linearGradient:return e.concat(["x1","y1","x2","y2","gradientUnits","gradientTransform"]);case"radialGradient":return e.concat(["gradientUnits","gradientTransform","cx","cy","r","fx","fy","fr"]);case"stop":return e.concat(["offset","stop-color","stop-opacity"])}return e},getUnitVector:We,groupSVGElements:t=>t&&1===t.length?t[0]:new xs(t),hasStyleChanged:hn,invertTransform:at,isIdentityMatrix:t=>t.every(((t,e)=>t===T[e])),isTouchEvent:Ht,isTransparent:Li,joinPath:Er,loadImage:gt,makeBoundingBoxFromPoints:Nt,makeElementSelectable:function(t){return void 0!==t.onselectstart&&(t.onselectstart=null),t.style.userSelect="",t},makeElementUnselectable:$,makePathSimpler:fr,matrixToSVG:Mt,mergeClipPaths:(t,e)=>{var i;let s=t,r=e;s.inverted&&!r.inverted&&(s=e,r=t),se(r,null===(i=r.group)||void 0===i?void 0:i.calcTransformMatrix(),s.calcTransformMatrix());const n=s.inverted&&r.inverted;return n&&(s.inverted=r.inverted=!1),new xs([s],{clipPath:r,inverted:n})},multiplyTransformMatrices:ht,parsePath:kr,parsePreserveAspectRatioAttribute:Et,parseUnit:Ot,pick:mt,projectStrokeOnPoints:Ur,qrDecompose:ct,radiansToDegrees:rt,removeFromArray:R,removeTransformFromObject:(t,e)=>{const i=at(e),s=ht(i,t.calcOwnMatrix());Jt(t,s)},removeTransformMatrixForSvgParsing:Bn,request:Rn,requestAnimFrame:U,resetObjectTransform:$t,rotatePoint:(t,e,i)=>t.rotate(i,e),rotateVector:Be,saveObjectTransform:Zt,sendObjectToPlane:se,sendPointToPlane:ie,setStyle:Ri,sin:I,sizeAfterTransform:Qt,string:an,stylesFromArray:ln,stylesToArray:cn,toDataURL:it,toFixed:Tt,transformPath:(t,e,i)=>(i&&(e=ht(e,[1,0,0,1,-i.x,-i.y])),t.map((t=>{const i=[...t];for(let s=1;s<t.length-1;s+=2){const{x:r,y:n}=ot({x:t[s],y:t[s+1]},e);i[s]=r,i[s+1]=n}return i}))),transformPoint:ot,transformPointRelativeToCanvas:(t,e,i,s)=>{if(i!==te.child&&i!==te.sibling)throw new Error("fabric.js: received bad argument ".concat(i));if(s!==te.child&&s!==te.sibling)throw new Error("fabric.js: received bad argument ".concat(s));if(i===s)return t;const r=e.viewportTransform;return t.transform("child"===s?at(r):r)},wrapElement:q});function Xn(t){if(!Qi.test(t.nodeName))return{};let e,i,s=t.getAttribute("viewBox"),r=1,n=1,o=0,a=0;const h=t.getAttribute("width"),c=t.getAttribute("height"),l=t.getAttribute("x")||0,d=t.getAttribute("y")||0;let u=t.getAttribute("preserveAspectRatio")||"";const g=!s||!(s=s.match(is)),f=!h||!c||"100%"===h||"100%"===c,p=g&&f,m={};let v="",_=0,x=0;if(m.width=0,m.height=0,m.toBeParsed=p,g&&(l||d)&&t.parentNode&&"#document"!==t.parentNode.nodeName&&(v=" translate("+Ot(l)+" "+Ot(d)+") ",e=(t.getAttribute("transform")||"")+v,t.setAttribute("transform",e),t.removeAttribute("x"),t.removeAttribute("y")),p)return m;if(g)return m.width=Ot(h),m.height=Ot(c),m;o=-parseFloat(s[1]),a=-parseFloat(s[2]);const y=parseFloat(s[3]),C=parseFloat(s[4]);if(m.minX=o,m.minY=a,m.viewBoxWidth=y,m.viewBoxHeight=C,f?(m.width=y,m.height=C):(m.width=Ot(h),m.height=Ot(c),r=m.width/y,n=m.height/C),u=Et(u),"none"!==u.alignX&&("meet"===u.meetOrSlice&&(n=r=r>n?n:r),"slice"===u.meetOrSlice&&(n=r=r>n?r:n),_=m.width-y*r,x=m.height-C*r,"Mid"===u.alignX&&(_/=2),"Mid"===u.alignY&&(x/=2),"Min"===u.alignX&&(_=0),"Min"===u.alignY&&(x=0)),1===r&&1===n&&0===o&&0===a&&0===l&&0===d)return m;if((l||d)&&"#document"!==t.parentNode.nodeName&&(v=" translate("+Ot(l)+" "+Ot(d)+") "),e=v+" matrix("+r+" 0 0 "+n+" "+(o*r+_)+" "+(a*n+x)+") ","svg"===t.nodeName){for(i=t.ownerDocument.createElementNS(Hi,"g");t.firstChild;)i.appendChild(t.firstChild);t.appendChild(i)}else i=t,i.removeAttribute("x"),i.removeAttribute("y"),e=i.getAttribute("transform")+e;return i.setAttribute("transform",e),m}function Yn(t){const e=t.getElementsByTagName("style");let i,s;const r={};let n;for(i=0,s=e.length;i<s;i++){let t=e[i].textContent;t=t.replace(/\/\*[\s\S]*?\*\//g,""),""!==t.trim()&&(n=t.split("}"),n=n.filter((function(t){return t.trim()})),n.forEach((function(t){const e=t.split("{"),n={},o=e[1].trim().split(";").filter((function(t){return t.trim()}));for(i=0,s=o.length;i<s;i++){const t=o[i].split(":"),e=t[0].trim(),s=t[1].trim();n[e]=s}(t=e[0].trim()).split(",").forEach((function(t){""!==(t=t.replace(/^svg/i,"").trim())&&(r[t]?Object.assign(r[t],n):r[t]=Object.assign({},n))}))})))}return r}function Wn(t,e){let i,s,r,n,o=[];for(r=0,n=e.length;r<n;r++)i=e[r],s=t.getElementsByTagName(i),o=o.concat(Array.prototype.slice.call(s));return o}function Vn(t,e){let i,s,r,n;if(t.getElementById&&(i=t.getElementById(e)),i)return i;const o=t.getElementsByTagName("*");for(r=0,n=o.length;r<n;r++)if(s=o[r],e===s.getAttribute("id"))return s}const Gn=["gradientTransform","x1","x2","y1","y2","gradientUnits","cx","cy","r","fx","fy"],zn="xlink:href";function Hn(t,e){const i=Vn(t,e.getAttribute(zn).slice(1));if(i&&i.getAttribute(zn)&&Hn(t,i),Gn.forEach((function(t){i&&!e.hasAttribute(t)&&i.hasAttribute(t)&&e.setAttribute(t,i.getAttribute(t))})),!e.children.length){const t=i.cloneNode(!0);for(;t.firstChild;)e.appendChild(t.firstChild)}e.removeAttribute(zn)}const Un=["linearGradient","radialGradient","svg:linearGradient","svg:radialGradient"];const Nn=function(t,e,i,s,r,n){this.elements=t,this.callback=e,this.options=i,this.reviver=s,this.svgUid=i&&i.svgUid||0,this.parsingOptions=r,this.regexUrl=/^url\(['"]?#([^'"]+)['"]?\)/g,this.doc=n};var qn;function Kn(t,e,i,s,r){new Nn(t,e,i,s,r).parse()}function Jn(t,e,i,s){if(!t)return;if(s&&s.signal&&s.signal.aborted)throw new Error("`options.signal` is in `aborted` state");!function(t){const e=Wn(t,["use","svg:use"]);let i=0;for(;e.length&&i<e.length;){const s=e[i],r=s.getAttribute("xlink:href")||s.getAttribute("href");if(null===r)return;const n=r.slice(1),o=s.getAttribute("x")||0,a=s.getAttribute("y")||0;let h=Vn(t,n).cloneNode(!0),c=(h.getAttribute("transform")||"")+" translate("+o+", "+a+")";const l=e.length;let d,u,g,f;const p=Hi;if(Xn(h),/^svg$/i.test(h.nodeName)){const t=h.ownerDocument.createElementNS(p,"g");for(u=0,g=h.attributes,f=g.length;u<f;u++)d=g.item(u),t.setAttributeNS(p,d.nodeName,d.nodeValue);for(;h.firstChild;)t.appendChild(h.firstChild);h=t}for(u=0,g=s.attributes,f=g.length;u<f;u++)d=g.item(u),"x"!==d.nodeName&&"y"!==d.nodeName&&"xlink:href"!==d.nodeName&&"href"!==d.nodeName&&("transform"===d.nodeName?c=d.nodeValue+" "+c:h.setAttribute(d.nodeName,d.nodeValue));h.setAttribute("transform",c),h.setAttribute("instantiated_by_use","1"),h.removeAttribute("id"),s.parentNode.replaceChild(h,s),e.length===l&&i++}}(t);const r=Q(),n=Xn(t),o=Array.from(t.getElementsByTagName("*"));n.crossOrigin=s&&s.crossOrigin,n.svgUid=r,n.signal=s&&s.signal;const a=o.filter((function(t){return Xn(t),Zi.test(t.nodeName.replace("svg:",""))&&!function(t,e){for(;t&&(t=t.parentNode);)if(t.nodeName&&e.test(t.nodeName.replace("svg:",""))&&!t.getAttribute("instantiated_by_use"))return!0;return!1}(t,ts)}));if(!a||a&&!a.length)return void(e&&e([],{}));const h={};o.filter((function(t){return"clipPath"===t.nodeName.replace("svg:","")})).forEach((function(t){const e=t.getAttribute("id");h[e]=Array.from(t.getElementsByTagName("*")).filter((function(t){return Zi.test(t.nodeName.replace("svg:",""))}))})),Wi[r]=function(t){const e=Wn(t,Un);let i;const s={};let r=e.length;for(;r--;)i=e[r],i.getAttribute("xlink:href")&&Hn(t,i),s[i.getAttribute("id")]=i;return s}(t),Yi[r]=Yn(t),Vi[r]=h,Kn(a,(function(t,i){e&&(e(t,n,i,o),delete Wi[r],delete Yi[r],delete Vi[r])}),Object.assign({},n),i,s)}(qn=Nn.prototype).parse=function(){this.instances=new Array(this.elements.length),this.numElements=this.elements.length,this.createObjects()},qn.createObjects=function(){this.elements.forEach(((t,e)=>{t.setAttribute("svgUid",this.svgUid),this.createObject(t,e)}))},qn.findTag=function(t){return M.getSVGClass(t.tagName.toLowerCase().replace("svg:",""))},qn.createObject=function(t,e){const i=this.findTag(t);if(i&&i.fromElement)try{i.fromElement(t,this.createCallback(e,t),this.options)}catch(t){console.log(t)}else this.checkIfDone()},qn.createCallback=function(t,e){return i=>{let s;this.resolveGradient(i,e,"fill"),this.resolveGradient(i,e,"stroke"),i instanceof Ln&&i._originalElement&&(s=i.parsePreserveAspectRatioAttribute(e)),Bn(i,s),this.resolveClipPath(i,e),this.reviver&&this.reviver(e,i),this.instances[t]=i,this.checkIfDone()}},qn.extractPropertyDefinition=function(t,e,i){const s=t[e],r=this.regexUrl;if(!r.test(s))return;r.lastIndex=0;const n=r.exec(s)[1];return r.lastIndex=0,Gi[i][this.svgUid][n]},qn.resolveGradient=function(t,e,s){const r=this.extractPropertyDefinition(t,s,"gradientDefs");if(r){const n=e.getAttribute(s+"-opacity"),o=Gs.fromElement(r,t,i(i({},this.options),{},{opacity:n}));t.set(s,o)}},qn.createClipPathCallback=function(t,e){return function(t){Bn(t),t.fillRule=t.clipRule,e.push(t)}},qn.resolveClipPath=function(t,e){let i,s,r,n,o,a=this.extractPropertyDefinition(t,"clipPath","clipPaths");if(a){n=[],r=at(t.calcTransformMatrix());const h=a[0].parentNode;let c=e;for(;c.parentNode&&c.getAttribute("clip-path")!==t.clipPath;)c=c.parentNode;c.parentNode.appendChild(h);for(let e=0;e<a.length;e++)i=a[e],s=this.findTag(i),s.fromElement(i,this.createClipPathCallback(t,n),this.options);a=1===n.length?n[0]:new xs(n),o=ht(r,a.calcTransformMatrix()),a.clipPath&&this.resolveClipPath(a,c);const l=ct(o);a.flipX=!1,a.flipY=!1,a.set("scaleX",l.scaleX),a.set("scaleY",l.scaleY),a.angle=l.angle,a.skewX=l.skewX,a.skewY=0,a.setPositionByOrigin({x:l.translateX,y:l.translateY},"center","center"),t.clipPath=a}else delete t.clipPath},qn.checkIfDone=function(){0==--this.numElements&&(this.instances=this.instances.filter((function(t){return null!=t})),this.callback(this.instances,this.elements))};const $n=t=>new X(t.width,t.height),Zn=t=>function(e,i,s){var r,n;const o=s.points[t].x-s.pathOffset.x,a=s.points[t].y-s.pathOffset.y;return new X(o,a).transform(ht(null!==(r=null===(n=s.canvas)||void 0===n?void 0:n.viewportTransform)&&void 0!==r?r:T,s.calcTransformMatrix()))},Qn=(t,e,i,s)=>{const r=e.target,n=e.pointIndex,o=ge(e,"center","center",i,s),a=$n(r),h=r._getTransformedDimensions(),c=a.divide(h),l=new X(r.flipX?-1:1,r.flipY?-1:1),d=o.multiply(l).multiply(c).add(r.pathOffset);return r.points[n]=d,r.setDimensions(),!0},to=(t,e)=>function(s,r,n,o){const a=r.target,h=(t>0?t:a.points.length)-1,c=new X(a.points[h].x-a.pathOffset.x,a.points[h].y-a.pathOffset.y).transform(a.calcOwnMatrix()),l=e(s,i(i({},r),{},{pointIndex:t}),n,o),d=$n(a),u=new X(a.flipX?-1:1,a.flipY?-1:1),g=new X(a.points[h].x,a.points[h].y).subtract(a.pathOffset).divide(d).multiply(u);return a.setPositionByOrigin(c,g.x+.5,g.y+.5),l};var eo=Object.freeze({__proto__:null,changeWidth:si,createObjectDefaultControls:Ei,createPolyControls:function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s={};for(let r=0;r<("number"==typeof t?t:t.points.length);r++)s["p".concat(r)]=new oi(i({actionName:"modifyPoly",positionHandler:Zn(r),actionHandler:to(r,Qn)},e));return s},createResizeControls:Mi,createTextboxDefaultControls:Pi,dragHandler:fe,getLocalPoint:ge,renderCircleControl:ri,renderSquareControl:ni,rotationStyleHandler:ai,rotationWithSnapping:hi,scaleCursorStyleHandler:ui,scaleOrSkewActionName:Ti,scaleSkewCursorStyleHandler:Oi,scalingEqually:fi,scalingX:pi,scalingXOrSkewingY:ki,scalingY:mi,scalingYOrSkewingX:Di,skewCursorStyleHandler:yi,skewHandlerX:bi,skewHandlerY:Si,wrapWithFireEvent:ei,wrapWithFixedAnchor:ii});const io=t=>void 0!==t.webgl,so="precision ".concat(l.high," float"),ro="\n ".concat(so,";\n varying vec2 vTexCoord;\n uniform sampler2D uTexture;\n void main() {\n gl_FragColor = texture2D(uTexture, vTexCoord);\n }"),no=["type"];class oo{get type(){return this.constructor.name}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=r({},(function(t){if(null==t)throw new TypeError("Cannot destructure "+t)}(t),t));s(this,"vertexSource","\n attribute vec2 aPosition;\n varying vec2 vTexCoord;\n void main() {\n vTexCoord = aPosition;\n gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);\n }"),Object.assign(this,this.constructor.defaults,e)}getFragmentSource(){return ro}createProgram(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.getFragmentSource(),i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.vertexSource;const{WebGLProbe:s}=m();s.GLPrecision&&s.GLPrecision!==l.high&&(e=e.replace(new RegExp(so,"g"),so.replace(l.high,s.GLPrecision)));const r=t.createShader(t.VERTEX_SHADER),n=t.createShader(t.FRAGMENT_SHADER),o=t.createProgram();if(!r||!n||!o)throw new Error("Vertex, fragment shader or program creation error");if(t.shaderSource(r,i),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS))throw new Error("Vertex shader compile error for ".concat(this.type,": ").concat(t.getShaderInfoLog(r)));if(t.shaderSource(n,e),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new Error("Fragment shader compile error for ".concat(this.type,": ").concat(t.getShaderInfoLog(n)));if(t.attachShader(o,r),t.attachShader(o,n),t.linkProgram(o),!t.getProgramParameter(o,t.LINK_STATUS))throw new Error('Shader link error for "${this.type}" '+t.getProgramInfoLog(o));const a=this.getUniformLocations(t,o)||{};return a.uStepW=t.getUniformLocation(o,"uStepW"),a.uStepH=t.getUniformLocation(o,"uStepH"),{program:o,attributeLocations:this.getAttributeLocations(t,o),uniformLocations:a}}getAttributeLocations(t,e){return{aPosition:t.getAttribLocation(e,"aPosition")}}getUniformLocations(t,e){return{}}sendAttributeData(t,e,i){const s=e.aPosition,r=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,r),t.enableVertexAttribArray(s),t.vertexAttribPointer(s,2,t.FLOAT,!1,0,0),t.bufferData(t.ARRAY_BUFFER,i,t.STATIC_DRAW)}_setupFrameBuffer(t){const e=t.context;if(t.passes>1){const i=t.destinationWidth,s=t.destinationHeight;t.sourceWidth===i&&t.sourceHeight===s||(e.deleteTexture(t.targetTexture),t.targetTexture=t.filterBackend.createTexture(e,i,s)),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t.targetTexture,0)}else e.bindFramebuffer(e.FRAMEBUFFER,null),e.finish()}_swapTextures(t){t.passes--,t.pass++;const e=t.targetTexture;t.targetTexture=t.sourceTexture,t.sourceTexture=e}isNeutralState(t){const e=this.mainParameter,i=this.constructor.defaults[e];if(e){const t=this[e];return Array.isArray(i)&&Array.isArray(t)?i.every(((e,i)=>e===t[i])):i===t}return!1}applyTo(t){io(t)?(this._setupFrameBuffer(t),this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){}getCacheKey(){return this.type}retrieveShader(t){const e=this.getCacheKey();return t.programCache[e]||(t.programCache[e]=this.createProgram(t.context)),t.programCache[e]}applyToWebGL(t){const e=t.context,i=this.retrieveShader(t);0===t.pass&&t.originalTexture?e.bindTexture(e.TEXTURE_2D,t.originalTexture):e.bindTexture(e.TEXTURE_2D,t.sourceTexture),e.useProgram(i.program),this.sendAttributeData(e,i.attributeLocations,t.aPosition),e.uniform1f(i.uniformLocations.uStepW,1/t.sourceWidth),e.uniform1f(i.uniformLocations.uStepH,1/t.sourceHeight),this.sendUniformData(e,i.uniformLocations),e.viewport(0,0,t.destinationWidth,t.destinationHeight),e.drawArrays(e.TRIANGLE_STRIP,0,4)}bindAdditionalTexture(t,e,i){t.activeTexture(i),t.bindTexture(t.TEXTURE_2D,e),t.activeTexture(t.TEXTURE0)}unbindAdditionalTexture(t,e){t.activeTexture(e),t.bindTexture(t.TEXTURE_2D,null),t.activeTexture(t.TEXTURE0)}getMainParameter(){return this.mainParameter?this[this.mainParameter]:void 0}setMainParameter(t){this.mainParameter&&(this[this.mainParameter]=t)}sendUniformData(t,e){}createHelpLayer(t){if(!t.helpLayer){const e=tt();e.width=t.sourceWidth,e.height=t.sourceHeight,t.helpLayer=e}}toObject(){const t=this.mainParameter;return i({type:this.type},t?{[t]:this[t]}:{})}toJSON(){return this.toObject()}static async fromObject(t,e){return new this(n(t,no))}}const ao={multiply:"gl_FragColor.rgb *= uColor.rgb;\n",screen:"gl_FragColor.rgb = 1.0 - (1.0 - gl_FragColor.rgb) * (1.0 - uColor.rgb);\n",add:"gl_FragColor.rgb += uColor.rgb;\n",difference:"gl_FragColor.rgb = abs(gl_FragColor.rgb - uColor.rgb);\n",subtract:"gl_FragColor.rgb -= uColor.rgb;\n",lighten:"gl_FragColor.rgb = max(gl_FragColor.rgb, uColor.rgb);\n",darken:"gl_FragColor.rgb = min(gl_FragColor.rgb, uColor.rgb);\n",exclusion:"gl_FragColor.rgb += uColor.rgb - 2.0 * (uColor.rgb * gl_FragColor.rgb);\n",overlay:"\n if (uColor.r < 0.5) {\n gl_FragColor.r *= 2.0 * uColor.r;\n } else {\n gl_FragColor.r = 1.0 - 2.0 * (1.0 - gl_FragColor.r) * (1.0 - uColor.r);\n }\n if (uColor.g < 0.5) {\n gl_FragColor.g *= 2.0 * uColor.g;\n } else {\n gl_FragColor.g = 1.0 - 2.0 * (1.0 - gl_FragColor.g) * (1.0 - uColor.g);\n }\n if (uColor.b < 0.5) {\n gl_FragColor.b *= 2.0 * uColor.b;\n } else {\n gl_FragColor.b = 1.0 - 2.0 * (1.0 - gl_FragColor.b) * (1.0 - uColor.b);\n }\n ",tint:"\n gl_FragColor.rgb *= (1.0 - uColor.a);\n gl_FragColor.rgb += uColor.rgb;\n "};class ho extends oo{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec4 uColor;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n gl_FragColor = color;\n if (color.a > 0.0) {\n ".concat(ao[this.mode],"\n }\n }\n ")}applyTo2d(t){let{imageData:{data:e}}=t;const i=new wt(this.color).getSource(),s=i[0]*this.alpha,r=i[1]*this.alpha,n=i[2]*this.alpha,o=1-this.alpha;for(let t=0;t<e.length;t+=4){const i=e[t],a=e[t+1],h=e[t+2];switch(this.mode){case"multiply":e[t]=i*s/255,e[t+1]=a*r/255,e[t+2]=h*n/255;break;case"screen":e[t]=255-(255-i)*(255-s)/255,e[t+1]=255-(255-a)*(255-r)/255,e[t+2]=255-(255-h)*(255-n)/255;break;case"add":e[t]=i+s,e[t+1]=a+r,e[t+2]=h+n;break;case"difference":e[t]=Math.abs(i-s),e[t+1]=Math.abs(a-r),e[t+2]=Math.abs(h-n);break;case"subtract":e[t]=i-s,e[t+1]=a-r,e[t+2]=h-n;break;case"darken":e[t]=Math.min(i,s),e[t+1]=Math.min(a,r),e[t+2]=Math.min(h,n);break;case"lighten":e[t]=Math.max(i,s),e[t+1]=Math.max(a,r),e[t+2]=Math.max(h,n);break;case"overlay":e[t]=s<128?2*i*s/255:255-2*(255-i)*(255-s)/255,e[t+1]=r<128?2*a*r/255:255-2*(255-a)*(255-r)/255,e[t+2]=n<128?2*h*n/255:255-2*(255-h)*(255-n)/255;break;case"exclusion":e[t]=s+i-2*s*i/255,e[t+1]=r+a-2*r*a/255,e[t+2]=n+h-2*n*h/255;break;case"tint":e[t]=s+i*o,e[t+1]=r+a*o,e[t+2]=n+h*o}}}getUniformLocations(t,e){return{uColor:t.getUniformLocation(e,"uColor")}}sendUniformData(t,e){const i=new wt(this.color).getSource();i[0]=this.alpha*i[0]/255,i[1]=this.alpha*i[1]/255,i[2]=this.alpha*i[2]/255,i[3]=this.alpha,t.uniform4fv(e.uColor,i)}toObject(){return{type:this.type,color:this.color,mode:this.mode,alpha:this.alpha}}}s(ho,"defaults",{color:"#F95C63",mode:"multiply",alpha:1}),M.setClass(ho);const co={multiply:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform sampler2D uImage;\n uniform vec4 uColor;\n varying vec2 vTexCoord;\n varying vec2 vTexCoord2;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n vec4 color2 = texture2D(uImage, vTexCoord2);\n color.rgba *= color2.rgba;\n gl_FragColor = color;\n }\n ",mask:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform sampler2D uImage;\n uniform vec4 uColor;\n varying vec2 vTexCoord;\n varying vec2 vTexCoord2;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n vec4 color2 = texture2D(uImage, vTexCoord2);\n color.a = color2.a;\n gl_FragColor = color;\n }\n "},lo=["type","image"];class uo extends oo{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return co[this.mode]}applyToWebGL(t){const e=t.context,i=this.createTexture(t.filterBackend,this.image);this.bindAdditionalTexture(e,i,e.TEXTURE1),super.applyToWebGL(t),this.unbindAdditionalTexture(e,e.TEXTURE1)}createTexture(t,e){return t.getCachedTexture(e.cacheKey,e.getElement())}calculateMatrix(){const t=this.image,{width:e,height:i}=t.getElement();return[1/t.scaleX,0,0,0,1/t.scaleY,0,-t.left/e,-t.top/i,1]}applyTo2d(t){let{imageData:{data:e,width:i,height:s},filterBackend:{resources:r}}=t;const n=this.image;r.blendImage||(r.blendImage=tt());const o=r.blendImage,a=o.getContext("2d");o.width!==i||o.height!==s?(o.width=i,o.height=s):a.clearRect(0,0,i,s),a.setTransform(n.scaleX,0,0,n.scaleY,n.left,n.top),a.drawImage(n.getElement(),0,0,i,s);const h=a.getImageData(0,0,i,s).data;for(let t=0;t<e.length;t+=4){const i=e[t],s=e[t+1],r=e[t+2],n=e[t+3],o=h[t],a=h[t+1],c=h[t+2],l=h[t+3];switch(this.mode){case"multiply":e[t]=i*o/255,e[t+1]=s*a/255,e[t+2]=r*c/255,e[t+3]=n*l/255;break;case"mask":e[t+3]=l}}}getUniformLocations(t,e){return{uTransformMatrix:t.getUniformLocation(e,"uTransformMatrix"),uImage:t.getUniformLocation(e,"uImage")}}sendUniformData(t,e){const i=this.calculateMatrix();t.uniform1i(e.uImage,1),t.uniformMatrix3fv(e.uTransformMatrix,!1,i)}toObject(){return{type:this.type,image:this.image&&this.image.toObject(),mode:this.mode,alpha:this.alpha}}static fromObject(t,e){let{type:s,image:r}=t,o=n(t,lo);return Ln.fromObject(r,e).then((t=>new this(i(i({},o),{},{image:t}))))}}s(uo,"defaults",{mode:"multiply",alpha:1,vertexSource:"\n attribute vec2 aPosition;\n varying vec2 vTexCoord;\n varying vec2 vTexCoord2;\n uniform mat3 uTransformMatrix;\n void main() {\n vTexCoord = aPosition;\n vTexCoord2 = (uTransformMatrix * vec3(aPosition, 1.0)).xy;\n gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);\n }\n "}),M.setClass(uo);class go extends oo{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n const float nSamples = 15.0;\n vec3 v3offset = vec3(12.9898, 78.233, 151.7182);\n float random(vec3 scale) {\n /* use the fragment position for a different seed per-pixel */\n return fract(sin(dot(gl_FragCoord.xyz, scale)) * 43758.5453);\n }\n void main() {\n vec4 color = vec4(0.0);\n float total = 0.0;\n float offset = random(v3offset);\n for (float t = -nSamples; t <= nSamples; t++) {\n float percent = (t + offset - 0.5) / nSamples;\n float weight = 1.0 - abs(percent);\n color += texture2D(uTexture, vTexCoord + uDelta * percent) * weight;\n total += weight;\n }\n gl_FragColor = color / total;\n }\n "}applyTo(t){io(t)?(this.aspectRatio=t.sourceWidth/t.sourceHeight,t.passes++,this._setupFrameBuffer(t),this.horizontal=!0,this.applyToWebGL(t),this._swapTextures(t),this._setupFrameBuffer(t),this.horizontal=!1,this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){t.imageData=this.simpleBlur(t)}simpleBlur(t){let{ctx:e,imageData:i,filterBackend:{resources:s}}=t;const{width:r,height:n}=i;s.blurLayer1||(s.blurLayer1=tt(),s.blurLayer2=tt());const o=s.blurLayer1,a=s.blurLayer2;o.width===r&&o.height===n||(a.width=o.width=r,a.height=o.height=n);const h=o.getContext("2d"),c=a.getContext("2d"),l=15,d=.06*this.blur*.5;let u,g,f,p;for(h.putImageData(i,0,0),c.clearRect(0,0,r,n),p=-15;p<=l;p++)u=(Math.random()-.5)/4,g=p/l,f=d*g*r+u,c.globalAlpha=1-Math.abs(g),c.drawImage(o,f,u),h.drawImage(a,0,0),c.globalAlpha=1,c.clearRect(0,0,a.width,a.height);for(p=-15;p<=l;p++)u=(Math.random()-.5)/4,g=p/l,f=d*g*n+u,c.globalAlpha=1-Math.abs(g),c.drawImage(o,u,f),h.drawImage(a,0,0),c.globalAlpha=1,c.clearRect(0,0,a.width,a.height);e.drawImage(o,0,0);const m=e.getImageData(0,0,o.width,o.height);return h.globalAlpha=1,h.clearRect(0,0,o.width,o.height),m}getUniformLocations(t,e){return{delta:t.getUniformLocation(e,"uDelta")}}sendUniformData(t,e){const i=this.chooseRightDelta();t.uniform2fv(e.delta,i)}chooseRightDelta(){let t=1;const e=[0,0];this.horizontal?this.aspectRatio>1&&(t=1/this.aspectRatio):this.aspectRatio<1&&(t=this.aspectRatio);const i=t*this.blur*.12;return this.horizontal?e[0]=i:e[1]=i,e}}s(go,"defaults",{blur:0,mainParameter:"blur"}),M.setClass(go);class fo extends oo{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uBrightness;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n color.rgb += uBrightness;\n gl_FragColor = color;\n }\n"}applyTo2d(t){let{imageData:{data:e}}=t;if(0===this.brightness)return;const i=Math.round(255*this.brightness);for(let t=0;t<e.length;t+=4)e[t]=e[t]+i,e[t+1]=e[t+1]+i,e[t+2]=e[t+2]+i}getUniformLocations(t,e){return{uBrightness:t.getUniformLocation(e,"uBrightness")}}sendUniformData(t,e){t.uniform1f(e.uBrightness,this.brightness)}}s(fo,"defaults",{brightness:0,mainParameter:"brightness"}),M.setClass(fo);const po=["matrix"],mo={matrix:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],mainParameter:"matrix",colorsOnly:!0};class vo extends oo{setOptions(t){let{matrix:e}=t,i=n(t,po);e&&(this.matrix=[...e]),Object.assign(this,i)}getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n varying vec2 vTexCoord;\n uniform mat4 uColorMatrix;\n uniform vec4 uConstants;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n color *= uColorMatrix;\n color += uConstants;\n gl_FragColor = color;\n }"}applyTo2d(t){const e=t.imageData.data,i=this.matrix,s=this.colorsOnly;for(let t=0;t<e.length;t+=4){const r=e[t],n=e[t+1],o=e[t+2];if(s)e[t]=r*i[0]+n*i[1]+o*i[2]+255*i[4],e[t+1]=r*i[5]+n*i[6]+o*i[7]+255*i[9],e[t+2]=r*i[10]+n*i[11]+o*i[12]+255*i[14];else{const s=e[t+3];e[t]=r*i[0]+n*i[1]+o*i[2]+s*i[3]+255*i[4],e[t+1]=r*i[5]+n*i[6]+o*i[7]+s*i[8]+255*i[9],e[t+2]=r*i[10]+n*i[11]+o*i[12]+s*i[13]+255*i[14],e[t+3]=r*i[15]+n*i[16]+o*i[17]+s*i[18]+255*i[19]}}}getUniformLocations(t,e){return{uColorMatrix:t.getUniformLocation(e,"uColorMatrix"),uConstants:t.getUniformLocation(e,"uConstants")}}sendUniformData(t,e){const i=this.matrix,s=[i[0],i[1],i[2],i[3],i[5],i[6],i[7],i[8],i[10],i[11],i[12],i[13],i[15],i[16],i[17],i[18]],r=[i[4],i[9],i[14],i[19]];t.uniformMatrix4fv(e.uColorMatrix,!1,s),t.uniform4fv(e.uConstants,r)}}function _o(t,e){var r;const n=(s(r=class extends vo{get type(){return t}},"defaults",i(i({},mo),{},{mainParameter:void 0,matrix:e})),r);return M.setClass(n,t),n}s(vo,"defaults",mo),M.setClass(vo);const xo=_o("Brownie",[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0]),yo=_o("Vintage",[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0]),Co=_o("Kodachrome",[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0]),bo=_o("Technicolor",[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0]),So=_o("Polaroid",[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0]),wo=_o("Sepia",[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0]),To=_o("BlackWhite",[1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,0,0,0,1,0]),Oo=["subFilters"];class ko extends oo{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{subFilters:e=[]}=t;super(n(t,Oo)),this.subFilters=e}applyTo(t){io(t)&&(t.passes+=this.subFilters.length-1),this.subFilters.forEach((e=>{e.applyTo(t)}))}toObject(){return i(i({},super.toObject()),{},{subFilters:this.subFilters.map((t=>t.toObject()))})}isNeutralState(){return!this.subFilters.some((t=>!t.isNeutralState()))}static fromObject(t,e){return Promise.all((t.subFilters||[]).map((t=>M.getClass(t.type).fromObject(t,e)))).then((t=>new this({subFilters:t})))}}M.setClass(ko);class Do extends oo{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uContrast;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float contrastF = 1.015 * (uContrast + 1.0) / (1.0 * (1.015 - uContrast));\n color.rgb = contrastF * (color.rgb - 0.5) + 0.5;\n gl_FragColor = color;\n }"}applyTo2d(t){let{imageData:{data:e}}=t;if(0===this.contrast)return;const i=Math.floor(255*this.contrast),s=259*(i+255)/(255*(259-i));for(let t=0;t<e.length;t+=4)e[t]=s*(e[t]-128)+128,e[t+1]=s*(e[t+1]-128)+128,e[t+2]=s*(e[t+2]-128)+128}getUniformLocations(t,e){return{uContrast:t.getUniformLocation(e,"uContrast")}}sendUniformData(t,e){t.uniform1f(e.uContrast,this.contrast)}}s(Do,"defaults",{contrast:0,mainParameter:"contrast"}),M.setClass(Do);const Eo={Convolute_3_1:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[9];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 0);\n for (float h = 0.0; h < 3.0; h+=1.0) {\n for (float w = 0.0; w < 3.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 1), uStepH * (h - 1));\n color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 3.0 + w)];\n }\n }\n gl_FragColor = color;\n }\n ",Convolute_3_0:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[9];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 1);\n for (float h = 0.0; h < 3.0; h+=1.0) {\n for (float w = 0.0; w < 3.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 1.0), uStepH * (h - 1.0));\n color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 3.0 + w)];\n }\n }\n float alpha = texture2D(uTexture, vTexCoord).a;\n gl_FragColor = color;\n gl_FragColor.a = alpha;\n }\n ",Convolute_5_1:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[25];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 0);\n for (float h = 0.0; h < 5.0; h+=1.0) {\n for (float w = 0.0; w < 5.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 2.0), uStepH * (h - 2.0));\n color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 5.0 + w)];\n }\n }\n gl_FragColor = color;\n }\n ",Convolute_5_0:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[25];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 1);\n for (float h = 0.0; h < 5.0; h+=1.0) {\n for (float w = 0.0; w < 5.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 2.0), uStepH * (h - 2.0));\n color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 5.0 + w)];\n }\n }\n float alpha = texture2D(uTexture, vTexCoord).a;\n gl_FragColor = color;\n gl_FragColor.a = alpha;\n }\n ",Convolute_7_1:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[49];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 0);\n for (float h = 0.0; h < 7.0; h+=1.0) {\n for (float w = 0.0; w < 7.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 3.0), uStepH * (h - 3.0));\n color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 7.0 + w)];\n }\n }\n gl_FragColor = color;\n }\n ",Convolute_7_0:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[49];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 1);\n for (float h = 0.0; h < 7.0; h+=1.0) {\n for (float w = 0.0; w < 7.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 3.0), uStepH * (h - 3.0));\n color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 7.0 + w)];\n }\n }\n float alpha = texture2D(uTexture, vTexCoord).a;\n gl_FragColor = color;\n gl_FragColor.a = alpha;\n }\n ",Convolute_9_1:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[81];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 0);\n for (float h = 0.0; h < 9.0; h+=1.0) {\n for (float w = 0.0; w < 9.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 4.0), uStepH * (h - 4.0));\n color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 9.0 + w)];\n }\n }\n gl_FragColor = color;\n }\n ",Convolute_9_0:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[81];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 1);\n for (float h = 0.0; h < 9.0; h+=1.0) {\n for (float w = 0.0; w < 9.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 4.0), uStepH * (h - 4.0));\n color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 9.0 + w)];\n }\n }\n float alpha = texture2D(uTexture, vTexCoord).a;\n gl_FragColor = color;\n gl_FragColor.a = alpha;\n }\n "};class Mo extends oo{getCacheKey(){return"".concat(this.type,"_").concat(Math.sqrt(this.matrix.length),"_").concat(this.opaque?1:0)}getFragmentSource(){return Eo[this.getCacheKey()]}applyTo2d(t){const e=t.imageData,i=e.data,s=this.matrix,r=Math.round(Math.sqrt(s.length)),n=Math.floor(r/2),o=e.width,a=e.height,h=t.ctx.createImageData(o,a),c=h.data,l=this.opaque?1:0;let d,u,g,f,p,m,v,_,x,y,C,b,S;for(C=0;C<a;C++)for(y=0;y<o;y++){for(p=4*(C*o+y),d=0,u=0,g=0,f=0,S=0;S<r;S++)for(b=0;b<r;b++)v=C+S-n,m=y+b-n,v<0||v>=a||m<0||m>=o||(_=4*(v*o+m),x=s[S*r+b],d+=i[_]*x,u+=i[_+1]*x,g+=i[_+2]*x,l||(f+=i[_+3]*x));c[p]=d,c[p+1]=u,c[p+2]=g,c[p+3]=l?i[p+3]:f}t.imageData=h}getUniformLocations(t,e){return{uMatrix:t.getUniformLocation(e,"uMatrix"),uOpaque:t.getUniformLocation(e,"uOpaque"),uHalfSize:t.getUniformLocation(e,"uHalfSize"),uSize:t.getUniformLocation(e,"uSize")}}sendUniformData(t,e){t.uniform1fv(e.uMatrix,this.matrix)}toObject(){return i(i({},super.toObject()),{},{opaque:this.opaque,matrix:[...this.matrix]})}}s(Mo,"defaults",{opaque:!1,matrix:[0,0,0,0,1,0,0,0,0]}),M.setClass(Mo);const Po=["gamma"];class Ao extends oo{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec3 uGamma;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n vec3 correction = (1.0 / uGamma);\n color.r = pow(color.r, correction.r);\n color.g = pow(color.g, correction.g);\n color.b = pow(color.b, correction.b);\n gl_FragColor = color;\n gl_FragColor.rgb *= color.a;\n }\n"}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{gamma:e=[1,1,1]}=t;super(n(t,Po)),this.gamma=e}applyTo2d(t){let{imageData:{data:e}}=t;const i=this.gamma,s=1/i[0],r=1/i[1],n=1/i[2];this.rgbValues||(this.rgbValues={r:new Uint8Array(256),g:new Uint8Array(256),b:new Uint8Array(256)});const o=this.rgbValues;for(let t=0;t<256;t++)o.r[t]=255*Math.pow(t/255,s),o.g[t]=255*Math.pow(t/255,r),o.b[t]=255*Math.pow(t/255,n);for(let t=0;t<e.length;t+=4)e[t]=o.r[e[t]],e[t+1]=o.g[e[t+1]],e[t+2]=o.b[e[t+2]]}getUniformLocations(t,e){return{uGamma:t.getUniformLocation(e,"uGamma")}}sendUniformData(t,e){t.uniform3fv(e.uGamma,this.gamma)}}s(Ao,"defaults",{mainParameter:"gamma",gamma:[1,1,1]}),M.setClass(Ao);const jo={average:"\n precision highp float;\n uniform sampler2D uTexture;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float average = (color.r + color.b + color.g) / 3.0;\n gl_FragColor = vec4(average, average, average, color.a);\n }\n ",lightness:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform int uMode;\n varying vec2 vTexCoord;\n void main() {\n vec4 col = texture2D(uTexture, vTexCoord);\n float average = (max(max(col.r, col.g),col.b) + min(min(col.r, col.g),col.b)) / 2.0;\n gl_FragColor = vec4(average, average, average, col.a);\n }\n ",luminosity:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform int uMode;\n varying vec2 vTexCoord;\n void main() {\n vec4 col = texture2D(uTexture, vTexCoord);\n float average = 0.21 * col.r + 0.72 * col.g + 0.07 * col.b;\n gl_FragColor = vec4(average, average, average, col.a);\n }\n "};class Fo extends oo{applyTo2d(t){let{imageData:{data:e}}=t;for(let t,i=0;i<e.length;i+=4){switch(this.mode){case"average":t=(e[i]+e[i+1]+e[i+2])/3;break;case"lightness":t=(Math.min(e[i],e[i+1],e[i+2])+Math.max(e[i],e[i+1],e[i+2]))/2;break;case"luminosity":t=.21*e[i]+.72*e[i+1]+.07*e[i+2]}e[i]=t,e[i+1]=t,e[i+2]=t}}getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return jo[this.mode]}getUniformLocations(t,e){return{uMode:t.getUniformLocation(e,"uMode")}}sendUniformData(t,e){t.uniform1i(e.uMode,1)}isNeutralState(){return!1}}s(Fo,"defaults",{mode:"average",mainParameter:"mode"}),M.setClass(Fo);class Lo extends vo{calculateMatrix(){const t=this.rotation*Math.PI,e=B(t),i=I(t),s=1/3,r=Math.sqrt(s)*i,n=1-e;this.matrix=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],this.matrix[0]=e+n/3,this.matrix[1]=s*n-r,this.matrix[2]=s*n+r,this.matrix[5]=s*n+r,this.matrix[6]=e+s*n,this.matrix[7]=s*n-r,this.matrix[10]=s*n-r,this.matrix[11]=s*n+r,this.matrix[12]=e+s*n}isNeutralState(){return this.calculateMatrix(),super.isNeutralState()}applyTo(t){this.calculateMatrix(),super.applyTo(t)}}s(Lo,"defaults",{rotation:0,mainParameter:"rotation"}),M.setClass(Lo);class Ro extends oo{applyTo2d(t){let{imageData:{data:e}}=t;for(let t=0;t<e.length;t+=4)e[t]=255-e[t],e[t+1]=255-e[t+1],e[t+2]=255-e[t+2],this.alpha&&(e[t+3]=255-e[t+3])}getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform int uInvert;\n uniform int uAlpha;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n if (uInvert == 1) {\n if (uAlpha == 1) {\n gl_FragColor = vec4(1.0 - color.r,1.0 -color.g,1.0 -color.b,1.0 -color.a);\n } else {\n gl_FragColor = vec4(1.0 - color.r,1.0 -color.g,1.0 -color.b,color.a);\n }\n } else {\n gl_FragColor = color;\n }\n }\n"}isNeutralState(){return!this.invert}getUniformLocations(t,e){return{uInvert:t.getUniformLocation(e,"uInvert"),uAlpha:t.getUniformLocation(e,"uAlpha")}}sendUniformData(t,e){t.uniform1i(e.uInvert,Number(this.invert)),t.uniform1i(e.uAlpha,Number(this.alpha))}}s(Ro,"defaults",{alpha:!1,invert:!0,mainParameter:"invert"}),M.setClass(Ro);class Bo extends oo{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uStepH;\n uniform float uNoise;\n uniform float uSeed;\n varying vec2 vTexCoord;\n float rand(vec2 co, float seed, float vScale) {\n return fract(sin(dot(co.xy * vScale ,vec2(12.9898 , 78.233))) * 43758.5453 * (seed + 0.01) / 2.0);\n }\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n color.rgb += (0.5 - rand(vTexCoord, uSeed, 0.1 / uStepH)) * uNoise;\n gl_FragColor = color;\n }\n"}applyTo2d(t){let{imageData:{data:e}}=t;if(0===this.noise)return;const i=this.noise;for(let t=0;t<e.length;t+=4){const s=(.5-Math.random())*i;e[t]+=s,e[t+1]+=s,e[t+2]+=s}}getUniformLocations(t,e){return{uNoise:t.getUniformLocation(e,"uNoise"),uSeed:t.getUniformLocation(e,"uSeed")}}sendUniformData(t,e){t.uniform1f(e.uNoise,this.noise/255),t.uniform1f(e.uSeed,Math.random())}toObject(){return i(i({},super.toObject()),{},{noise:this.noise})}}s(Bo,"defaults",{mainParameter:"noise",noise:0}),M.setClass(Bo);class Io extends oo{applyTo2d(t){let{imageData:{data:e,width:i,height:s}}=t;for(let t=0;t<s;t+=this.blocksize)for(let r=0;r<i;r+=this.blocksize){const n=4*t*i+4*r,o=e[n],a=e[n+1],h=e[n+2],c=e[n+3];for(let n=t;n<Math.min(t+this.blocksize,s);n++)for(let t=r;t<Math.min(r+this.blocksize,i);t++){const s=4*n*i+4*t;e[s]=o,e[s+1]=a,e[s+2]=h,e[s+3]=c}}}isNeutralState(){return 1===this.blocksize}getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uBlocksize;\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n float blockW = uBlocksize * uStepW;\n float blockH = uBlocksize * uStepW;\n int posX = int(vTexCoord.x / blockW);\n int posY = int(vTexCoord.y / blockH);\n float fposX = float(posX);\n float fposY = float(posY);\n vec2 squareCoords = vec2(fposX * blockW, fposY * blockH);\n vec4 color = texture2D(uTexture, squareCoords);\n gl_FragColor = color;\n }\n"}getUniformLocations(t,e){return{uBlocksize:t.getUniformLocation(e,"uBlocksize"),uStepW:t.getUniformLocation(e,"uStepW"),uStepH:t.getUniformLocation(e,"uStepH")}}sendUniformData(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}s(Io,"defaults",{blocksize:4,mainParameter:"blocksize"}),M.setClass(Io);class Xo extends oo{getFragmentShader(){return"\nprecision highp float;\nuniform sampler2D uTexture;\nuniform vec4 uLow;\nuniform vec4 uHigh;\nvarying vec2 vTexCoord;\nvoid main() {\n gl_FragColor = texture2D(uTexture, vTexCoord);\n if(all(greaterThan(gl_FragColor.rgb,uLow.rgb)) && all(greaterThan(uHigh.rgb,gl_FragColor.rgb))) {\n gl_FragColor.a = 0.0;\n }\n}\n"}applyTo2d(t){let{imageData:{data:e}}=t;const i=255*this.distance,s=new wt(this.color).getSource(),r=[s[0]-i,s[1]-i,s[2]-i],n=[s[0]+i,s[1]+i,s[2]+i];for(let t=0;t<e.length;t+=4){const i=e[t],s=e[t+1],o=e[t+2];i>r[0]&&s>r[1]&&o>r[2]&&i<n[0]&&s<n[1]&&o<n[2]&&(e[t+3]=0)}}getUniformLocations(t,e){return{uLow:t.getUniformLocation(e,"uLow"),uHigh:t.getUniformLocation(e,"uHigh")}}sendUniformData(t,e){const i=new wt(this.color).getSource(),s=this.distance,r=[0+i[0]/255-s,0+i[1]/255-s,0+i[2]/255-s,1],n=[i[0]/255+s,i[1]/255+s,i[2]/255+s,1];t.uniform4fv(e.uLow,r),t.uniform4fv(e.uHigh,n)}toObject(){return i(i({},super.toObject()),{},{color:this.color,distance:this.distance})}}s(Xo,"defaults",{color:"#FFFFFF",distance:.02,useAlpha:!1}),M.setClass(Xo);class Yo extends oo{getUniformLocations(t,e){return{uDelta:t.getUniformLocation(e,"uDelta"),uTaps:t.getUniformLocation(e,"uTaps")}}sendUniformData(t,e){t.uniform2fv(e.uDelta,this.horizontal?[1/this.width,0]:[0,1/this.height]),t.uniform1fv(e.uTaps,this.taps)}getFilterWindow(){const t=this.tempScale;return Math.ceil(this.lanczosLobes/t)}getCacheKey(){const t=this.getFilterWindow();return"".concat(this.type,"_").concat(t)}getFragmentSource(){const t=this.getFilterWindow();return this.generateShader(t)}getTaps(){const t=this.lanczosCreate(this.lanczosLobes),e=this.tempScale,i=this.getFilterWindow(),s=new Array(i);for(let r=1;r<=i;r++)s[r-1]=t(r*e);return s}generateShader(t){const e=new Array(t);for(let i=1;i<=t;i++)e[i-1]="".concat(i,".0 * uDelta");return"\n ".concat(this.fragmentSourceTOP,"\n uniform float uTaps[").concat(t,"];\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float sum = 1.0;\n ").concat(e.map(((t,e)=>"\n color += texture2D(uTexture, vTexCoord + ".concat(t,") * uTaps[").concat(e,"] + texture2D(uTexture, vTexCoord - ").concat(t,") * uTaps[").concat(e,"];\n sum += 2.0 * uTaps[").concat(e,"];\n "))).join("\n"),"\n gl_FragColor = color / sum;\n }\n ")}applyTo(t){io(t)?(t.passes++,this.width=t.sourceWidth,this.horizontal=!0,this.dW=Math.round(this.width*this.scaleX),this.dH=t.sourceHeight,this.tempScale=this.dW/this.width,this.taps=this.getTaps(),t.destinationWidth=this.dW,this._setupFrameBuffer(t),this.applyToWebGL(t),this._swapTextures(t),t.sourceWidth=t.destinationWidth,this.height=t.sourceHeight,this.horizontal=!1,this.dH=Math.round(this.height*this.scaleY),this.tempScale=this.dH/this.height,this.taps=this.getTaps(),t.destinationHeight=this.dH,this._setupFrameBuffer(t),this.applyToWebGL(t),this._swapTextures(t),t.sourceHeight=t.destinationHeight):this.applyTo2d(t)}isNeutralState(){return 1===this.scaleX&&1===this.scaleY}lanczosCreate(t){return e=>{if(e>=t||e<=-t)return 0;if(e<1.1920929e-7&&e>-1.1920929e-7)return 1;const i=(e*=Math.PI)/t;return Math.sin(e)/e*Math.sin(i)/i}}applyTo2d(t){const e=t.imageData,i=this.scaleX,s=this.scaleY;this.rcpScaleX=1/i,this.rcpScaleY=1/s;const r=e.width,n=e.height,o=Math.round(r*i),a=Math.round(n*s);let h;"sliceHack"===this.resizeType?h=this.sliceByTwo(t,r,n,o,a):"hermite"===this.resizeType?h=this.hermiteFastResize(t,r,n,o,a):"bilinear"===this.resizeType?h=this.bilinearFiltering(t,r,n,o,a):"lanczos"===this.resizeType&&(h=this.lanczosResize(t,r,n,o,a)),t.imageData=h}sliceByTwo(t,e,i,s,r){const n=t.imageData,o=.5;let a=!1,h=!1,c=e*o,l=i*o;const d=t.filterBackend.resources;let u=0,g=0;const f=e;let p=0;d.sliceByTwo||(d.sliceByTwo=tt());const m=d.sliceByTwo;(m.width<1.5*e||m.height<i)&&(m.width=1.5*e,m.height=i);const v=m.getContext("2d");for(v.clearRect(0,0,1.5*e,i),v.putImageData(n,0,0),s=Math.floor(s),r=Math.floor(r);!a||!h;)e=c,i=l,s<Math.floor(c*o)?c=Math.floor(c*o):(c=s,a=!0),r<Math.floor(l*o)?l=Math.floor(l*o):(l=r,h=!0),v.drawImage(m,u,g,e,i,f,p,c,l),u=f,g=p,p+=l;return v.getImageData(u,g,s,r)}lanczosResize(t,e,i,s,r){const n=t.imageData.data,o=t.ctx.createImageData(s,r),a=o.data,h=this.lanczosCreate(this.lanczosLobes),c=this.rcpScaleX,l=this.rcpScaleY,d=2/this.rcpScaleX,u=2/this.rcpScaleY,g=Math.ceil(c*this.lanczosLobes/2),f=Math.ceil(l*this.lanczosLobes/2),p={},m={},v={};return function t(_){let x,y,C,b,S,w,T,O,k,D,E;for(m.x=(_+.5)*c,v.x=Math.floor(m.x),x=0;x<r;x++){for(m.y=(x+.5)*l,v.y=Math.floor(m.y),S=0,w=0,T=0,O=0,k=0,y=v.x-g;y<=v.x+g;y++)if(!(y<0||y>=e)){D=Math.floor(1e3*Math.abs(y-m.x)),p[D]||(p[D]={});for(let t=v.y-f;t<=v.y+f;t++)t<0||t>=i||(E=Math.floor(1e3*Math.abs(t-m.y)),p[D][E]||(p[D][E]=h(Math.sqrt(Math.pow(D*d,2)+Math.pow(E*u,2))/1e3)),C=p[D][E],C>0&&(b=4*(t*e+y),S+=C,w+=C*n[b],T+=C*n[b+1],O+=C*n[b+2],k+=C*n[b+3]))}b=4*(x*s+_),a[b]=w/S,a[b+1]=T/S,a[b+2]=O/S,a[b+3]=k/S}return++_<s?t(_):o}(0)}bilinearFiltering(t,e,i,s,r){let n,o,a,h,c,l,d,u,g,f,p,m,v,_=0;const x=this.rcpScaleX,y=this.rcpScaleY,C=4*(e-1),b=t.imageData.data,S=t.ctx.createImageData(s,r),w=S.data;for(d=0;d<r;d++)for(u=0;u<s;u++)for(c=Math.floor(x*u),l=Math.floor(y*d),g=x*u-c,f=y*d-l,v=4*(l*e+c),p=0;p<4;p++)n=b[v+p],o=b[v+4+p],a=b[v+C+p],h=b[v+C+4+p],m=n*(1-g)*(1-f)+o*g*(1-f)+a*f*(1-g)+h*g*f,w[_++]=m;return S}hermiteFastResize(t,e,i,s,r){const n=this.rcpScaleX,o=this.rcpScaleY,a=Math.ceil(n/2),h=Math.ceil(o/2),c=t.imageData.data,l=t.ctx.createImageData(s,r),d=l.data;for(let t=0;t<r;t++)for(let i=0;i<s;i++){const r=4*(i+t*s);let l=0,u=0,g=0,f=0,p=0,m=0,v=0;const _=(t+.5)*o;for(let s=Math.floor(t*o);s<(t+1)*o;s++){const t=Math.abs(_-(s+.5))/h,r=(i+.5)*n,o=t*t;for(let t=Math.floor(i*n);t<(i+1)*n;t++){let i=Math.abs(r-(t+.5))/a;const n=Math.sqrt(o+i*i);n>1&&n<-1||(l=2*n*n*n-3*n*n+1,l>0&&(i=4*(t+s*e),v+=l*c[i+3],g+=l,c[i+3]<255&&(l=l*c[i+3]/250),f+=l*c[i],p+=l*c[i+1],m+=l*c[i+2],u+=l))}}d[r]=f/u,d[r+1]=p/u,d[r+2]=m/u,d[r+3]=v/g}return l}toObject(){return{type:this.type,scaleX:this.scaleX,scaleY:this.scaleY,resizeType:this.resizeType,lanczosLobes:this.lanczosLobes}}}s(Yo,"defaults",{resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3,fragmentSourceTOP:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n "}),M.setClass(Yo);class Wo extends oo{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uSaturation;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float rgMax = max(color.r, color.g);\n float rgbMax = max(rgMax, color.b);\n color.r += rgbMax != color.r ? (rgbMax - color.r) * uSaturation : 0.00;\n color.g += rgbMax != color.g ? (rgbMax - color.g) * uSaturation : 0.00;\n color.b += rgbMax != color.b ? (rgbMax - color.b) * uSaturation : 0.00;\n gl_FragColor = color;\n }\n"}applyTo2d(t){let{imageData:{data:e}}=t;if(0===this.saturation)return;const i=-this.saturation;for(let t=0;t<e.length;t+=4){const s=Math.max(e[t],e[t+1],e[t+2]);e[t]+=s!==e[t]?(s-e[t])*i:0,e[t+1]+=s!==e[t+1]?(s-e[t+1])*i:0,e[t+2]+=s!==e[t+2]?(s-e[t+2])*i:0}}getUniformLocations(t,e){return{uSaturation:t.getUniformLocation(e,"uSaturation")}}sendUniformData(t,e){t.uniform1f(e.uSaturation,-this.saturation)}}s(Wo,"defaults",{saturation:0,mainParameter:"saturation"}),M.setClass(Wo);class Vo extends oo{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uVibrance;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float max = max(color.r, max(color.g, color.b));\n float avg = (color.r + color.g + color.b) / 3.0;\n float amt = (abs(max - avg) * 2.0) * uVibrance;\n color.r += max != color.r ? (max - color.r) * amt : 0.00;\n color.g += max != color.g ? (max - color.g) * amt : 0.00;\n color.b += max != color.b ? (max - color.b) * amt : 0.00;\n gl_FragColor = color;\n }\n"}applyTo2d(t){let{imageData:{data:e}}=t;if(0===this.vibrance)return;const i=-this.vibrance;for(let t=0;t<e.length;t+=4){const s=Math.max(e[t],e[t+1],e[t+2]),r=(e[t]+e[t+1]+e[t+2])/3,n=2*Math.abs(s-r)/255*i;e[t]+=s!==e[t]?(s-e[t])*n:0,e[t+1]+=s!==e[t+1]?(s-e[t+1])*n:0,e[t+2]+=s!==e[t+2]?(s-e[t+2])*n:0}}getUniformLocations(t,e){return{uVibrance:t.getUniformLocation(e,"uVibrance")}}sendUniformData(t,e){t.uniform1f(e.uVibrance,-this.vibrance)}}s(Vo,"defaults",{vibrance:0,mainParameter:"vibrance"}),M.setClass(Vo);var Go=Object.freeze({__proto__:null,BaseFilter:oo,BlackWhite:To,BlendColor:ho,BlendImage:uo,Blur:go,Brightness:fo,Brownie:xo,ColorMatrix:vo,Composed:ko,Contrast:Do,Convolute:Mo,Gamma:Ao,Grayscale:Fo,HueRotation:Lo,Invert:Ro,Kodachrome:Co,Noise:Bo,Pixelate:Io,Polaroid:So,RemoveColor:Xo,Resize:Yo,Saturation:Wo,Sepia:wo,Technicolor:bo,Vibrance:Vo,Vintage:yo});t.ActiveSelection=ys,t.BaseBrush=Us,t.Canvas=Es,t.Canvas2dFilterBackend=Tn,t.Circle=Lr,t.CircleBrush=class extends Us{constructor(t){super(t),s(this,"width",10),this.points=[]}drawDot(t){const e=this.addPoint(t),i=this.canvas.contextTop;this._saveAndTransform(i),this.dot(i,e),i.restore()}dot(t,e){t.fillStyle=e.fill,t.beginPath(),t.arc(e.x,e.y,e.radius,0,2*Math.PI,!1),t.closePath(),t.fill()}onMouseDown(t){this.points=[],this.canvas.clearContext(this.canvas.contextTop),this._setShadow(),this.drawDot(t)}_render(){const t=this.canvas.contextTop,e=this.points;this._saveAndTransform(t);for(let i=0;i<e.length;i++)this.dot(t,e[i]);t.restore()}onMouseMove(t){!0===this.limitedToCanvasSize&&this._isOutSideCanvas(t)||(this.needsFullRender()?(this.canvas.clearContext(this.canvas.contextTop),this.addPoint(t),this._render()):this.drawDot(t))}onMouseUp(){const t=this.canvas.renderOnAddRemove;this.canvas.renderOnAddRemove=!1;const e=[];for(let t=0;t<this.points.length;t++){const i=this.points[t],s=new Lr({radius:i.radius,left:i.x,top:i.y,originX:"center",originY:"center",fill:i.fill});this.shadow&&(s.shadow=new Ke(this.shadow)),e.push(s)}const i=new xs(e,{canvas:this.canvas});this.canvas.fire("before:path:created",{path:i}),this.canvas.add(i),this.canvas.fire("path:created",{path:i}),this.canvas.clearContext(this.canvas.contextTop),this._resetShadow(),this.canvas.renderOnAddRemove=t,this.canvas.requestRenderAll()}addPoint(t){let{x:e,y:i}=t;const s={x:e,y:i,radius:F(Math.max(0,this.width-20),this.width+20)/2,fill:new wt(this.color).setAlpha(F(0,100)/100).toRgba()};return this.points.push(s),s}},t.Color=wt,t.Control=oi,t.Ellipse=Wr,t.Gradient=Gs,t.Group=xs,t.IText=Sn,t.Image=Ln,t.Intersection=ze,t.Line=Ir,t.Object=Fi,t.Observable=A,t.Path=Pr,t.Pattern=Hs,t.PatternBrush=class extends Ar{constructor(t){super(t)}getPatternSrc(){const t=tt(),e=t.getContext("2d");return t.width=t.height=25,e&&(e.fillStyle=this.color,e.beginPath(),e.arc(10,10,10,0,2*Math.PI,!1),e.closePath(),e.fill()),t}getPattern(t){return t.createPattern(this.source||this.getPatternSrc(),"repeat")}_setBrushStyles(t){super._setBrushStyles(t);const e=this.getPattern(t);e&&(t.strokeStyle=e)}createPath(t){const e=super.createPath(t),i=e._getLeftTopCoords().scalarAdd(e.strokeWidth/2);return e.stroke=new Hs({source:this.source||this.getPatternSrc(),offsetX:-i.x,offsetY:-i.y}),e}},t.PencilBrush=Ar,t.Point=X,t.Polygon=Jr,t.Polyline=Kr,t.Rect=vs,t.Shadow=Ke,t.SprayBrush=class extends Us{constructor(t){super(t),s(this,"width",10),s(this,"density",20),s(this,"dotWidth",1),s(this,"dotWidthVariance",1),s(this,"randomOpacity",!1),s(this,"optimizeOverlapping",!0),this.sprayChunks=[],this.sprayChunk=[]}onMouseDown(t){this.sprayChunks=[],this.canvas.clearContext(this.canvas.contextTop),this._setShadow(),this.addSprayChunk(t),this.renderChunck(this.sprayChunk)}onMouseMove(t){!0===this.limitedToCanvasSize&&this._isOutSideCanvas(t)||(this.addSprayChunk(t),this.renderChunck(this.sprayChunk))}onMouseUp(){const t=this.canvas.renderOnAddRemove;this.canvas.renderOnAddRemove=!1;const e=[];for(let t=0;t<this.sprayChunks.length;t++){const i=this.sprayChunks[t];for(let t=0;t<i.length;t++){const s=i[t],r=new vs({width:s.width,height:s.width,left:s.x+1,top:s.y+1,originX:"center",originY:"center",fill:this.color});e.push(r)}}const i=new xs(this.optimizeOverlapping?function(t){const e={},i=[];for(let s,r=0;r<t.length;r++)s="".concat(t[r].left).concat(t[r].top),e[s]||(e[s]=!0,i.push(t[r]));return i}(e):e,{objectCaching:!0,layout:"fixed",subTargetCheck:!1,interactive:!1});this.shadow&&i.set("shadow",new Ke(this.shadow)),this.canvas.fire("before:path:created",{path:i}),this.canvas.add(i),this.canvas.fire("path:created",{path:i}),this.canvas.clearContext(this.canvas.contextTop),this._resetShadow(),this.canvas.renderOnAddRemove=t,this.canvas.requestRenderAll()}renderChunck(t){const e=this.canvas.contextTop;e.fillStyle=this.color,this._saveAndTransform(e);for(let i=0;i<t.length;i++){const s=t[i];e.globalAlpha=s.opacity,e.fillRect(s.x,s.y,s.width,s.width)}e.restore()}_render(){const t=this.canvas.contextTop;t.fillStyle=this.color,this._saveAndTransform(t);for(let t=0;t<this.sprayChunks.length;t++)this.renderChunck(this.sprayChunks[t]);t.restore()}addSprayChunk(t){this.sprayChunk=[];const e=this.width/2;for(let i=0;i<this.density;i++)this.sprayChunk.push({x:F(t.x-e,t.x+e),y:F(t.y-e,t.y+e),width:this.dotWidthVariance?F(Math.max(1,this.dotWidth-this.dotWidthVariance),this.dotWidth+this.dotWidthVariance):this.dotWidth,opacity:this.randomOpacity?F(0,100)/100:1});this.sprayChunks.push(this.sprayChunk)}},t.StaticCanvas=Vt,t.Text=pn,t.Textbox=wn,t.Triangle=Xr,t.WebGLFilterBackend=On,t.cache=x,t.classRegistry=M,t.config=c,t.controlsUtils=eo,t.createCollectionMixin=W,t.filters=Go,t.getCSSRules=Yn,t.getDocument=v,t.getEnv=m,t.getFilterBackend=Mn,t.getWindow=_,t.iMatrix=T,t.initFilterBackend=En,t.loadSVGFromString=function(t,e,i,s){Jn((new(_().DOMParser)).parseFromString(t.trim(),"text/xml").documentElement,(function(t,i,s,r){e(t,i,s,r)}),i,s)},t.loadSVGFromURL=function(t,e,i,s){new Rn(t.replace(/^\n\s*/,"").trim(),{method:"get",onComplete:function(t){const r=t.responseXML;if(!r||!r.documentElement)return e&&e(null),!1;Jn(r.documentElement,(function(t,i,s,r){e&&e(t,i,s,r)}),i,s)},signal:s&&s.signal})},t.parseAttributes=fs,t.parseElements=Kn,t.parseFontDeclaration=us,t.parsePointsAttribute=Vr,t.parseStyleAttribute=gs,t.parseTransformAttribute=ls,t.runningAnimations=P,t.util=In,t.version=y}));