kritzel-stencil 0.0.144 → 0.0.146

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 (290) hide show
  1. package/dist/cjs/{index-C9GjuVAx.js → default-text-tool.config-C0W0noF9.js} +15960 -1098
  2. package/dist/cjs/default-text-tool.config-C0W0noF9.js.map +1 -0
  3. package/dist/cjs/{index-DcTwXs_q.js → index-Cj__YTlG.js} +9 -11
  4. package/dist/cjs/index-Cj__YTlG.js.map +1 -0
  5. package/dist/cjs/index.cjs.js +1369 -12
  6. package/dist/cjs/index.cjs.js.map +1 -1
  7. package/dist/cjs/kritzel-brush-style.cjs.entry.js +1 -1
  8. package/dist/cjs/kritzel-color_22.cjs.entry.js +777 -754
  9. package/dist/cjs/loader.cjs.js +2 -2
  10. package/dist/cjs/stencil.cjs.js +3 -3
  11. package/dist/cjs/stencil.cjs.js.map +1 -1
  12. package/dist/collection/classes/core/core.class.js +263 -211
  13. package/dist/collection/classes/core/core.class.js.map +1 -1
  14. package/dist/collection/classes/core/store.class.js +21 -3
  15. package/dist/collection/classes/core/store.class.js.map +1 -1
  16. package/dist/collection/classes/core/viewport.class.js +4 -1
  17. package/dist/collection/classes/core/viewport.class.js.map +1 -1
  18. package/dist/collection/classes/core/workspace.class.js +2 -3
  19. package/dist/collection/classes/core/workspace.class.js.map +1 -1
  20. package/dist/collection/classes/handlers/context-menu.handler.js +11 -14
  21. package/dist/collection/classes/handlers/context-menu.handler.js.map +1 -1
  22. package/dist/collection/classes/handlers/key.handler.js +13 -13
  23. package/dist/collection/classes/handlers/key.handler.js.map +1 -1
  24. package/dist/collection/classes/handlers/move.handler.js +12 -9
  25. package/dist/collection/classes/handlers/move.handler.js.map +1 -1
  26. package/dist/collection/classes/handlers/resize.handler.js +20 -17
  27. package/dist/collection/classes/handlers/resize.handler.js.map +1 -1
  28. package/dist/collection/classes/handlers/rotation.handler.js +26 -23
  29. package/dist/collection/classes/handlers/rotation.handler.js.map +1 -1
  30. package/dist/collection/classes/handlers/selection.handler.js +32 -30
  31. package/dist/collection/classes/handlers/selection.handler.js.map +1 -1
  32. package/dist/collection/classes/objects/base-object.class.js +6 -15
  33. package/dist/collection/classes/objects/base-object.class.js.map +1 -1
  34. package/dist/collection/classes/objects/custom-element.class.js +2 -0
  35. package/dist/collection/classes/objects/custom-element.class.js.map +1 -1
  36. package/dist/collection/classes/objects/image.class.js +2 -0
  37. package/dist/collection/classes/objects/image.class.js.map +1 -1
  38. package/dist/collection/classes/objects/path.class.js +4 -0
  39. package/dist/collection/classes/objects/path.class.js.map +1 -1
  40. package/dist/collection/classes/objects/selection-box.class.js +3 -4
  41. package/dist/collection/classes/objects/selection-box.class.js.map +1 -1
  42. package/dist/collection/classes/objects/selection-group.class.js +109 -49
  43. package/dist/collection/classes/objects/selection-group.class.js.map +1 -1
  44. package/dist/collection/classes/objects/text.class.js +37 -43
  45. package/dist/collection/classes/objects/text.class.js.map +1 -1
  46. package/dist/collection/classes/providers/broadcast-sync-provider.class.js +93 -0
  47. package/dist/collection/classes/providers/broadcast-sync-provider.class.js.map +1 -0
  48. package/dist/collection/classes/providers/hocuspocus-sync-provider.class.js +232 -0
  49. package/dist/collection/classes/providers/hocuspocus-sync-provider.class.js.map +1 -0
  50. package/dist/collection/classes/providers/indexeddb-sync-provider.class.js +35 -0
  51. package/dist/collection/classes/providers/indexeddb-sync-provider.class.js.map +1 -0
  52. package/dist/collection/classes/providers/websocket-sync-provider.class.js +89 -0
  53. package/dist/collection/classes/providers/websocket-sync-provider.class.js.map +1 -0
  54. package/dist/collection/classes/structures/app-state-map.structure.js +189 -0
  55. package/dist/collection/classes/structures/app-state-map.structure.js.map +1 -0
  56. package/dist/collection/classes/structures/object-map.structure.js +260 -1
  57. package/dist/collection/classes/structures/object-map.structure.js.map +1 -1
  58. package/dist/collection/classes/tools/brush-tool.class.js +48 -37
  59. package/dist/collection/classes/tools/brush-tool.class.js.map +1 -1
  60. package/dist/collection/classes/tools/eraser-tool.class.js +10 -12
  61. package/dist/collection/classes/tools/eraser-tool.class.js.map +1 -1
  62. package/dist/collection/classes/tools/image-tool.class.js +2 -10
  63. package/dist/collection/classes/tools/image-tool.class.js.map +1 -1
  64. package/dist/collection/classes/tools/selection-tool.class.js +11 -8
  65. package/dist/collection/classes/tools/selection-tool.class.js.map +1 -1
  66. package/dist/collection/classes/tools/text-tool.class.js +13 -26
  67. package/dist/collection/classes/tools/text-tool.class.js.map +1 -1
  68. package/dist/collection/collection-manifest.json +1 -1
  69. package/dist/collection/components/core/kritzel-cursor-trail/kritzel-cursor-trail.js +1 -1
  70. package/dist/collection/components/core/kritzel-editor/kritzel-editor.js +36 -1
  71. package/dist/collection/components/core/kritzel-editor/kritzel-editor.js.map +1 -1
  72. package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +61 -35
  73. package/dist/collection/components/core/kritzel-engine/kritzel-engine.js.map +1 -1
  74. package/dist/collection/components/shared/kritzel-color/kritzel-color.js +2 -2
  75. package/dist/collection/components/shared/kritzel-color-palette/kritzel-color-palette.js +1 -1
  76. package/dist/collection/components/shared/kritzel-font/kritzel-font.js +1 -1
  77. package/dist/collection/components/shared/kritzel-font-family/kritzel-font-family.js +1 -1
  78. package/dist/collection/components/shared/kritzel-font-size/kritzel-font-size.js +1 -1
  79. package/dist/collection/components/shared/kritzel-menu/kritzel-menu.js +1 -1
  80. package/dist/collection/components/shared/kritzel-menu-item/kritzel-menu-item.js +2 -2
  81. package/dist/collection/components/shared/kritzel-portal/kritzel-portal.js +1 -1
  82. package/dist/collection/components/shared/kritzel-split-button/kritzel-split-button.js +1 -1
  83. package/dist/collection/components/shared/kritzel-stroke-size/kritzel-stroke-size.js +1 -1
  84. package/dist/collection/components/shared/kritzel-tooltip/kritzel-tooltip.js +4 -4
  85. package/dist/collection/components/ui/kritzel-context-menu/kritzel-context-menu.js +1 -1
  86. package/dist/collection/components/ui/kritzel-control-brush-config/kritzel-control-brush-config.js +2 -2
  87. package/dist/collection/components/ui/kritzel-control-text-config/kritzel-control-text-config.js +2 -2
  88. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js +3 -3
  89. package/dist/collection/components/ui/kritzel-utility-panel/kritzel-utility-panel.js +1 -1
  90. package/dist/collection/configs/{default-engine-state.js → default-engine-config.js} +2 -8
  91. package/dist/collection/configs/default-engine-config.js.map +1 -0
  92. package/dist/collection/configs/default-sync.config.js +12 -0
  93. package/dist/collection/configs/default-sync.config.js.map +1 -0
  94. package/dist/collection/constants/core.constants.js +2 -0
  95. package/dist/collection/constants/core.constants.js.map +1 -0
  96. package/dist/collection/index.js +8 -1
  97. package/dist/collection/index.js.map +1 -1
  98. package/dist/collection/interfaces/debug-info.interface.js.map +1 -1
  99. package/dist/collection/interfaces/engine-state.interface.js.map +1 -1
  100. package/dist/collection/interfaces/object.interface.js.map +1 -1
  101. package/dist/collection/interfaces/selection-state.interface.js.map +1 -1
  102. package/dist/collection/interfaces/sync-config.interface.js +2 -0
  103. package/dist/collection/interfaces/sync-config.interface.js.map +1 -0
  104. package/dist/collection/interfaces/sync-provider.interface.js +2 -0
  105. package/dist/collection/interfaces/sync-provider.interface.js.map +1 -0
  106. package/dist/components/index.js +1361 -4
  107. package/dist/components/index.js.map +1 -1
  108. package/dist/components/kritzel-brush-style.js +4 -4
  109. package/dist/components/kritzel-color-palette.js +1 -1
  110. package/dist/components/kritzel-color.js +1 -1
  111. package/dist/components/kritzel-context-menu.js +1 -1
  112. package/dist/components/kritzel-control-brush-config.js +1 -1
  113. package/dist/components/kritzel-control-text-config.js +1 -1
  114. package/dist/components/kritzel-controls.js +1 -1
  115. package/dist/components/kritzel-cursor-trail.js +1 -1
  116. package/dist/components/kritzel-dropdown.js +1 -1
  117. package/dist/components/kritzel-editor.js +39 -27
  118. package/dist/components/kritzel-editor.js.map +1 -1
  119. package/dist/components/kritzel-engine.js +1 -1
  120. package/dist/components/kritzel-font-family.js +1 -1
  121. package/dist/components/kritzel-font-size.js +1 -1
  122. package/dist/components/kritzel-font.js +1 -1
  123. package/dist/components/kritzel-icon.js +1 -1
  124. package/dist/components/kritzel-menu-item.js +1 -1
  125. package/dist/components/kritzel-menu.js +1 -1
  126. package/dist/components/kritzel-portal.js +1 -1
  127. package/dist/components/kritzel-split-button.js +1 -1
  128. package/dist/components/kritzel-stroke-size.js +1 -1
  129. package/dist/components/kritzel-tooltip.js +1 -1
  130. package/dist/components/kritzel-utility-panel.js +1 -1
  131. package/dist/components/kritzel-workspace-manager.js +1 -1
  132. package/dist/components/{p-C_hSH2nN.js → p-8iFF5GHL.js} +6 -6
  133. package/dist/components/{p-C_hSH2nN.js.map → p-8iFF5GHL.js.map} +1 -1
  134. package/dist/components/{p-BycHaC-9.js → p-BCrMfH5n.js} +6 -6
  135. package/dist/components/{p-BycHaC-9.js.map → p-BCrMfH5n.js.map} +1 -1
  136. package/dist/components/{p-D_RcVGj0.js → p-BHDOht0m.js} +6 -6
  137. package/dist/components/{p-D_RcVGj0.js.map → p-BHDOht0m.js.map} +1 -1
  138. package/dist/components/{p-DqsgZIHC.js → p-BHT7_POQ.js} +6 -6
  139. package/dist/components/{p-DqsgZIHC.js.map → p-BHT7_POQ.js.map} +1 -1
  140. package/dist/components/{p-DzyZA2GT.js → p-BQ5cdSqE.js} +11 -11
  141. package/dist/components/{p-DzyZA2GT.js.map → p-BQ5cdSqE.js.map} +1 -1
  142. package/dist/components/{p-Co5lU_7h.js → p-BaHZYvfq.js} +13 -13
  143. package/dist/components/{p-Co5lU_7h.js.map → p-BaHZYvfq.js.map} +1 -1
  144. package/dist/components/{p-BJbN3vca.js → p-BctNMdxr.js} +8 -8
  145. package/dist/components/{p-BJbN3vca.js.map → p-BctNMdxr.js.map} +1 -1
  146. package/dist/components/{p-D27d2rKT.js → p-Bhtn9qay.js} +5 -5
  147. package/dist/components/{p-D27d2rKT.js.map → p-Bhtn9qay.js.map} +1 -1
  148. package/dist/components/{p-CEn1WeG3.js → p-Bit0z7Yg.js} +9 -9
  149. package/dist/components/{p-CEn1WeG3.js.map → p-Bit0z7Yg.js.map} +1 -1
  150. package/dist/components/{p-CGb-8cK4.js → p-BlI4vzRZ.js} +5 -5
  151. package/dist/components/{p-CGb-8cK4.js.map → p-BlI4vzRZ.js.map} +1 -1
  152. package/dist/components/{p-fiFoOjv0.js → p-C3_LIgzd.js} +10 -10
  153. package/dist/components/{p-fiFoOjv0.js.map → p-C3_LIgzd.js.map} +1 -1
  154. package/dist/components/{p-DPxzgBs0.js → p-CIXPLjCu.js} +4 -4
  155. package/dist/components/{p-DPxzgBs0.js.map → p-CIXPLjCu.js.map} +1 -1
  156. package/dist/components/{p-dcR2uxM3.js → p-CURq0twf.js} +6 -6
  157. package/dist/components/{p-dcR2uxM3.js.map → p-CURq0twf.js.map} +1 -1
  158. package/dist/components/p-CwHz5s2a.js +18262 -0
  159. package/dist/components/p-CwHz5s2a.js.map +1 -0
  160. package/dist/components/{p-C9hrbrUN.js → p-CwkUrTy1.js} +5 -7
  161. package/dist/{cjs/index-DcTwXs_q.js.map → components/p-CwkUrTy1.js.map} +1 -1
  162. package/dist/components/{p-ByAzDzS5.js → p-D13ydJjo.js} +5 -5
  163. package/dist/components/{p-ByAzDzS5.js.map → p-D13ydJjo.js.map} +1 -1
  164. package/dist/components/{p-1bVCRi-d.js → p-DPN0PZvw.js} +20 -20
  165. package/dist/components/{p-1bVCRi-d.js.map → p-DPN0PZvw.js.map} +1 -1
  166. package/dist/components/{p-BFNwskCY.js → p-Dbp5YJIa.js} +5 -5
  167. package/dist/components/{p-BFNwskCY.js.map → p-Dbp5YJIa.js.map} +1 -1
  168. package/dist/components/{p-BEKicPnH.js → p-Dcf7tVJW.js} +5 -5
  169. package/dist/components/{p-BEKicPnH.js.map → p-Dcf7tVJW.js.map} +1 -1
  170. package/dist/components/{p-CieOx1XL.js → p-EBtkRix7.js} +8 -8
  171. package/dist/components/{p-CieOx1XL.js.map → p-EBtkRix7.js.map} +1 -1
  172. package/dist/components/{p-UsToUu6G.js → p-G2HGJcNm.js} +118 -196
  173. package/dist/components/p-G2HGJcNm.js.map +1 -0
  174. package/dist/components/{p-gCHmJzc2.js → p-NXPGXBZ2.js} +6 -6
  175. package/dist/components/{p-gCHmJzc2.js.map → p-NXPGXBZ2.js.map} +1 -1
  176. package/dist/components/{p-YqK8ch2R.js → p-n789Y3S-.js} +4 -5
  177. package/dist/components/p-n789Y3S-.js.map +1 -0
  178. package/dist/esm/{index-YVlgItFD.js → default-text-tool.config-nXXHSTK9.js} +15920 -1090
  179. package/dist/esm/default-text-tool.config-nXXHSTK9.js.map +1 -0
  180. package/dist/esm/{index-Cw77zP6g.js → index-SGde3HXB.js} +9 -11
  181. package/dist/esm/index-SGde3HXB.js.map +1 -0
  182. package/dist/esm/index.js +1358 -1
  183. package/dist/esm/index.js.map +1 -1
  184. package/dist/esm/kritzel-brush-style.entry.js +1 -1
  185. package/dist/esm/kritzel-color_22.entry.js +732 -709
  186. package/dist/esm/loader.js +3 -3
  187. package/dist/esm/stencil.js +4 -4
  188. package/dist/esm/stencil.js.map +1 -1
  189. package/dist/stencil/index.esm.js +1 -1
  190. package/dist/stencil/index.esm.js.map +1 -1
  191. package/dist/stencil/{p-Cw77zP6g.js → p-SGde3HXB.js} +2 -2
  192. package/dist/stencil/p-SGde3HXB.js.map +1 -0
  193. package/dist/stencil/{p-8b831c94.entry.js → p-d702c5af.entry.js} +2 -2
  194. package/dist/stencil/p-f8a8a8d7.entry.js +2 -0
  195. package/dist/stencil/p-f8a8a8d7.entry.js.map +1 -0
  196. package/dist/stencil/p-nXXHSTK9.js +2 -0
  197. package/dist/stencil/p-nXXHSTK9.js.map +1 -0
  198. package/dist/stencil/stencil.esm.js +1 -1
  199. package/dist/stencil/stencil.esm.js.map +1 -1
  200. package/dist/types/classes/core/core.class.d.ts +34 -21
  201. package/dist/types/classes/core/store.class.d.ts +8 -0
  202. package/dist/types/classes/objects/base-object.class.d.ts +1 -5
  203. package/dist/types/classes/objects/path.class.d.ts +1 -0
  204. package/dist/types/classes/objects/selection-box.class.d.ts +2 -3
  205. package/dist/types/classes/objects/selection-group.class.d.ts +24 -5
  206. package/dist/types/classes/objects/text.class.d.ts +1 -3
  207. package/dist/types/classes/providers/broadcast-sync-provider.class.d.ts +18 -0
  208. package/dist/types/classes/providers/hocuspocus-sync-provider.class.d.ts +120 -0
  209. package/dist/types/classes/providers/indexeddb-sync-provider.class.d.ts +22 -0
  210. package/dist/types/classes/providers/websocket-sync-provider.class.d.ts +52 -0
  211. package/dist/types/classes/structures/app-state-map.structure.d.ts +30 -0
  212. package/dist/types/classes/structures/object-map.structure.d.ts +39 -1
  213. package/dist/types/components/core/kritzel-editor/kritzel-editor.d.ts +3 -0
  214. package/dist/types/components/core/kritzel-engine/kritzel-engine.d.ts +2 -0
  215. package/dist/types/components.d.ts +6 -0
  216. package/dist/types/configs/{default-engine-state.d.ts → default-engine-config.d.ts} +1 -1
  217. package/dist/types/configs/default-sync.config.d.ts +5 -0
  218. package/dist/types/constants/core.constants.d.ts +0 -0
  219. package/dist/types/index.d.ts +8 -1
  220. package/dist/types/interfaces/debug-info.interface.d.ts +0 -1
  221. package/dist/types/interfaces/engine-state.interface.d.ts +1 -10
  222. package/dist/types/interfaces/object.interface.d.ts +1 -1
  223. package/dist/types/interfaces/selection-state.interface.d.ts +0 -4
  224. package/dist/types/interfaces/sync-config.interface.d.ts +22 -0
  225. package/dist/types/interfaces/sync-provider.interface.d.ts +29 -0
  226. package/dist/types/stencil-public-runtime.d.ts +1 -1
  227. package/package.json +16 -11
  228. package/dist/cjs/index-C9GjuVAx.js.map +0 -1
  229. package/dist/collection/classes/commands/add-object.command.js +0 -18
  230. package/dist/collection/classes/commands/add-object.command.js.map +0 -1
  231. package/dist/collection/classes/commands/add-selection-group.command.js +0 -24
  232. package/dist/collection/classes/commands/add-selection-group.command.js.map +0 -1
  233. package/dist/collection/classes/commands/base.command.js +0 -19
  234. package/dist/collection/classes/commands/base.command.js.map +0 -1
  235. package/dist/collection/classes/commands/batch.command.js +0 -15
  236. package/dist/collection/classes/commands/batch.command.js.map +0 -1
  237. package/dist/collection/classes/commands/move-selection-group.command.js +0 -44
  238. package/dist/collection/classes/commands/move-selection-group.command.js.map +0 -1
  239. package/dist/collection/classes/commands/remove-object.command.js +0 -18
  240. package/dist/collection/classes/commands/remove-object.command.js.map +0 -1
  241. package/dist/collection/classes/commands/remove-selection-group.command.js +0 -19
  242. package/dist/collection/classes/commands/remove-selection-group.command.js.map +0 -1
  243. package/dist/collection/classes/commands/resize-selection-group.command.js +0 -29
  244. package/dist/collection/classes/commands/resize-selection-group.command.js.map +0 -1
  245. package/dist/collection/classes/commands/rotate-selection-group.command.js +0 -29
  246. package/dist/collection/classes/commands/rotate-selection-group.command.js.map +0 -1
  247. package/dist/collection/classes/commands/update-object.command.js +0 -38
  248. package/dist/collection/classes/commands/update-object.command.js.map +0 -1
  249. package/dist/collection/classes/commands/update-viewport.command.js +0 -25
  250. package/dist/collection/classes/commands/update-viewport.command.js.map +0 -1
  251. package/dist/collection/classes/core/command-manager.class.js +0 -51
  252. package/dist/collection/classes/core/command-manager.class.js.map +0 -1
  253. package/dist/collection/classes/core/database.class.js +0 -236
  254. package/dist/collection/classes/core/database.class.js.map +0 -1
  255. package/dist/collection/classes/core/history.class.js +0 -51
  256. package/dist/collection/classes/core/history.class.js.map +0 -1
  257. package/dist/collection/classes/structures/circular-buffer.structure.js +0 -48
  258. package/dist/collection/classes/structures/circular-buffer.structure.js.map +0 -1
  259. package/dist/collection/configs/default-engine-state.js.map +0 -1
  260. package/dist/collection/interfaces/command.interface.js +0 -2
  261. package/dist/collection/interfaces/command.interface.js.map +0 -1
  262. package/dist/components/p-C9hrbrUN.js.map +0 -1
  263. package/dist/components/p-UsToUu6G.js.map +0 -1
  264. package/dist/components/p-YqK8ch2R.js.map +0 -1
  265. package/dist/components/p-kn4eunyR.js +0 -3338
  266. package/dist/components/p-kn4eunyR.js.map +0 -1
  267. package/dist/esm/index-Cw77zP6g.js.map +0 -1
  268. package/dist/esm/index-YVlgItFD.js.map +0 -1
  269. package/dist/stencil/p-Cw77zP6g.js.map +0 -1
  270. package/dist/stencil/p-YVlgItFD.js +0 -2
  271. package/dist/stencil/p-YVlgItFD.js.map +0 -1
  272. package/dist/stencil/p-fe738990.entry.js +0 -2
  273. package/dist/stencil/p-fe738990.entry.js.map +0 -1
  274. package/dist/types/classes/commands/add-object.command.d.ts +0 -9
  275. package/dist/types/classes/commands/add-selection-group.command.d.ts +0 -10
  276. package/dist/types/classes/commands/base.command.d.ts +0 -11
  277. package/dist/types/classes/commands/batch.command.d.ts +0 -8
  278. package/dist/types/classes/commands/move-selection-group.command.d.ts +0 -13
  279. package/dist/types/classes/commands/remove-object.command.d.ts +0 -9
  280. package/dist/types/classes/commands/remove-selection-group.command.d.ts +0 -8
  281. package/dist/types/classes/commands/resize-selection-group.command.d.ts +0 -20
  282. package/dist/types/classes/commands/rotate-selection-group.command.d.ts +0 -10
  283. package/dist/types/classes/commands/update-object.command.d.ts +0 -11
  284. package/dist/types/classes/commands/update-viewport.command.d.ts +0 -21
  285. package/dist/types/classes/core/command-manager.class.d.ts +0 -16
  286. package/dist/types/classes/core/database.class.d.ts +0 -29
  287. package/dist/types/classes/core/history.class.d.ts +0 -12
  288. package/dist/types/classes/structures/circular-buffer.structure.d.ts +0 -13
  289. package/dist/types/interfaces/command.interface.d.ts +0 -6
  290. /package/dist/stencil/{p-8b831c94.entry.js.map → p-d702c5af.entry.js.map} +0 -0
@@ -1,2 +0,0 @@
1
- class t{static registry={};static registerTool(t,e,i){const r=new e(i);r.name=t;this.registry[t]=r;return r}static getTool(t){const e=this.registry[t];if(!e){console.warn(`Unknown tool: ${t}`);return null}return e}}class e{static generateUUID(){return Math.random().toString(36).substr(2,9)}static isEmpty(t){if(t===null||t===undefined){return true}return Object?.keys(t).length===0&&t?.constructor===Object}}class i{static doPolygonsIntersect(t,e){const i=[t.bottomLeft,t.bottomRight,t.topRight,t.topLeft];const r=[e.bottomLeft,e.bottomRight,e.topRight,e.topLeft];for(const t of i){if(this.isPointInPolygon(t,r)){return true}}for(const t of r){if(this.isPointInPolygon(t,i)){return true}}for(let t=0;t<i.length;t++){const e=i[t];const s=i[(t+1)%i.length];for(let t=0;t<r.length;t++){const i=r[t];const n=r[(t+1)%r.length];if(this.intersectLines(e,s,i,n)){return true}}}return false}static isPointInPolygon(t,e){let i=false;for(let r=0,s=e.length-1;r<e.length;s=r++){const n=e[r].x,h=e[r].y;const l=e[s].x,o=e[s].y;const f=h>t.y!==o>t.y&&t.x<(l-n)*(t.y-h)/(o-h)+n;if(f)i=!i}return i}static intersectLines(t,e,i,r){const s=(e.x-t.x)*(r.y-i.y)-(e.y-t.y)*(r.x-i.x);if(s===0){return false}const n=((i.x-t.x)*(r.y-i.y)-(i.y-t.y)*(r.x-i.x))/s;const h=-((t.x-i.x)*(e.y-t.y)-(t.y-i.y)*(e.x-t.x))/s;return n>=0&&n<=1&&h>=0&&h<=1}}class r{__class__="KritzelBaseObject";_core;_elementRef;id;workspaceId;x;y;translateX;translateY;height;width;backgroundColor;borderColor;borderWidth=0;opacity=1;padding=0;scale;resizing=false;rotation=0;markedForRemoval=false;zIndex=0;isVisible=true;isSelected=false;isHovered=false;isMounted=false;isEditable=false;isInteractive=false;isDebugInfoVisible=false;get totalWidth(){return this.width+this.padding*2}get totalHeight(){return this.height+this.padding*2}set elementRef(t){this._elementRef=t}get elementRef(){return this._elementRef}get boundingBox(){return{x:this.translateX,y:this.translateY,z:this.scale,width:this.totalWidth/this.scale,height:this.totalHeight/this.scale}}get rotatedBoundingBox(){return{x:this.minXRotated,y:this.minYRotated,z:this.scale,width:this.maxXRotated-this.minXRotated,height:this.maxYRotated-this.minYRotated}}get rotatedPolygon(){const t=this.translateX+this.totalWidth/2/this.scale;const e=this.translateY+this.totalHeight/2/this.scale;const i=this.rotation;const r=this.totalWidth/this.scale;const s=this.totalHeight/this.scale;const n={topLeft:{x:this.translateX,y:this.translateY},topRight:{x:this.translateX+r,y:this.translateY},bottomRight:{x:this.translateX+r,y:this.translateY+s},bottomLeft:{x:this.translateX,y:this.translateY+s}};const h=Object.keys(n).reduce(((r,s)=>{const h=n[s];const l=Math.cos(i)*(h.x-t)-Math.sin(i)*(h.y-e)+t;const o=Math.sin(i)*(h.x-t)+Math.cos(i)*(h.y-e)+e;r[s]={x:l,y:o};return r}),{});return h}get minXRotated(){const t=[this.rotatedPolygon.topLeft.x,this.rotatedPolygon.topRight.x,this.rotatedPolygon.bottomRight.x,this.rotatedPolygon.bottomLeft.x];return Math.min(...t)}get minYRotated(){const t=[this.rotatedPolygon.topLeft.y,this.rotatedPolygon.topRight.y,this.rotatedPolygon.bottomRight.y,this.rotatedPolygon.bottomLeft.y];return Math.min(...t)}get maxXRotated(){const t=[this.rotatedPolygon.topLeft.x,this.rotatedPolygon.topRight.x,this.rotatedPolygon.bottomRight.x,this.rotatedPolygon.bottomLeft.x];return Math.max(...t)}get maxYRotated(){const t=[this.rotatedPolygon.topLeft.y,this.rotatedPolygon.topRight.y,this.rotatedPolygon.bottomRight.y,this.rotatedPolygon.bottomLeft.y];return Math.max(...t)}get transformationMatrix(){const t=1/this.scale;const e=this.translateX;const i=this.translateY;return`matrix(${t}, 0, 0, ${t}, ${e}, ${i})`}get rotationDegrees(){return this.rotation*(180/Math.PI)}get centerX(){return this.translateX+this.totalWidth/2}get centerY(){return this.translateY+this.totalHeight/2}constructor(){this.id=this.generateId()}static create(t){const e=new r;e._core=t;e.zIndex=t.store.currentZIndex;e.workspaceId=t.store.state.activeWorkspace.id;return e}mount(t){if(this.isMounted){return}this.elementRef=t;this.isMounted=true}generateId(){return e.generateUUID()}isInViewport(){const t={x:-this._core.store.state.translateX/this._core.store.state.scale,y:-this._core.store.state.translateY/this._core.store.state.scale,width:this._core.store.state.viewportWidth/this._core.store.state.scale,height:this._core.store.state.viewportHeight/this._core.store.state.scale};return this.rotatedBoundingBox.x<t.x+t.width&&this.rotatedBoundingBox.x+this.rotatedBoundingBox.width>t.x&&this.rotatedBoundingBox.y<t.y+t.height&&this.rotatedBoundingBox.y+this.rotatedBoundingBox.height>t.y}centerInViewport(){const{viewportWidth:t,viewportHeight:e,translateX:i,translateY:r,scale:s}=this._core.store.state;const{x:n,y:h,width:l,height:o}=this.rotatedBoundingBox;const f=n+l/2;const u=h+o/2;const a=(t/2-i)/s;const c=(e/2-r)/s;const d=a-f;const p=c-u;this.updatePosition(this.translateX+d,this.translateY+p)}move(t,e,i,r){const s=(t-i)/this._core.store.state.scale;const n=(e-r)/this._core.store.state.scale;this.translateX+=s;this.translateY+=n}resize(t,e,i,r){if(i<=1||r<=1){return}this.width=i;this.height=r;this.translateX=t;this.translateY=e}rotate(t){this.rotation=t}clone(){const t=Object.create(Object.getPrototypeOf(this));Object.assign(t,this);t.id=this.id;return t}copy(){const t=Object.create(Object.getPrototypeOf(this));Object.assign(t,this);t.id=this.generateId();t.isMounted=false;return t}onSelectedClick(){}serialize(){const{_core:t,_elementRef:e,element:i,totalWidth:r,totalHeight:s,...n}=this;const h=structuredClone(n);if(i&&typeof i==="object"&&"nodeType"in i&&i.nodeType===1){h.element=i.cloneNode(true)}return h}deserialize(t){Object.assign(this,t);return this}isClass(t){return this.__class__===t}edit(t){}hitTest(t,e){return true}hitTestPolygon(t){const e=this.rotatedPolygon;return i.doPolygonsIntersect(e,t)}updatePosition(t,e){this.translateX=t;this.translateY=e;this._core.store.state.objectsMap.update(this)}onExecuteAddCommand(t){}onUndoAddCommand(t){}onExecuteUpdateCommand(t){}onUndoUpdateCommand(t){}}class s{static forceHideKeyboard(){if(document.activeElement instanceof HTMLElement){document.activeElement.blur()}}static enableInteractiveWidget(){const t=document.querySelector('meta[name="viewport"][content*="interactive-widget=resizes-content"]');if(t){let e=t.getAttribute("content");if(!e.includes("interactive-widget=resizes-content")){e+=", interactive-widget=resizes-content"}t.setAttribute("content",e)}}static disableInteractiveWidget(){const t=document.querySelector('meta[name="viewport"][content*="interactive-widget=resizes-content"]');if(t){let e=t.getAttribute("content");let i=e.replace(/\s*interactive-widget=resizes-content\s*[,;]?/g,"");i=i.replace(/,(\s*,)+/g,",").replace(/^,/,"").replace(/,$/,"").trim();t.setAttribute("content",i)}}static onKeyboardVisibleChanged(t){if("visualViewport"in window){const e=.75;const i=i=>{const r=i.target;const s=r.height*r.scale/window.screen.height<e;t(s)};window.visualViewport.addEventListener("resize",i);return()=>window.visualViewport.removeEventListener("resize",i)}else{console.warn("Listening for keyboard visibility changes is not reliably supported in this browser.");return()=>{}}}}class n{_core;initiator;skipHistory;timestamp;constructor(t,e,i=false){this._core=t;this.initiator=e?.constructor?.name??"Unknown";this.skipHistory=i;this.timestamp=new Date}execute(){throw new Error("Method not implemented.")}undo(){throw new Error("Method not implemented.")}}class h extends n{object;updatedProperties;previousProperties;constructor(t,e,i,r,s=false){super(t,e,s);this.object=i;this.updatedProperties=r;this.previousProperties={};for(const t in r){if(r.hasOwnProperty(t)){this.previousProperties[t]=this.object[t]}}}execute(){for(const t in this.updatedProperties){if(this.updatedProperties.hasOwnProperty(t)){this.object[t]=this.updatedProperties[t]}}this.object.onExecuteUpdateCommand(this.updatedProperties);this._core.store.state.objectsMap.update(this.object);this._core.updateObjectInDatabase(this.object)}undo(){for(const t in this.previousProperties){if(this.previousProperties.hasOwnProperty(t)){this.object[t]=this.previousProperties[t]}}this.object.onUndoUpdateCommand(this.previousProperties);this._core.store.state.objectsMap.update(this.object);this._core.updateObjectInDatabase(this.object)}}function l(t){this.content=t}l.prototype={constructor:l,find:function(t){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===t)return e;return-1},get:function(t){var e=this.find(t);return e==-1?undefined:this.content[e+1]},update:function(t,e,i){var r=i&&i!=t?this.remove(i):this;var s=r.find(t),n=r.content.slice();if(s==-1){n.push(i||t,e)}else{n[s+1]=e;if(i)n[s]=i}return new l(n)},remove:function(t){var e=this.find(t);if(e==-1)return this;var i=this.content.slice();i.splice(e,2);return new l(i)},addToStart:function(t,e){return new l([t,e].concat(this.remove(t).content))},addToEnd:function(t,e){var i=this.remove(t).content.slice();i.push(t,e);return new l(i)},addBefore:function(t,e,i){var r=this.remove(e),s=r.content.slice();var n=r.find(t);s.splice(n==-1?s.length:n,0,e,i);return new l(s)},forEach:function(t){for(var e=0;e<this.content.length;e+=2)t(this.content[e],this.content[e+1])},prepend:function(t){t=l.from(t);if(!t.size)return this;return new l(t.content.concat(this.subtract(t).content))},append:function(t){t=l.from(t);if(!t.size)return this;return new l(this.subtract(t).content.concat(t.content))},subtract:function(t){var e=this;t=l.from(t);for(var i=0;i<t.content.length;i+=2)e=e.remove(t.content[i]);return e},toObject:function(){var t={};this.forEach((function(e,i){t[e]=i}));return t},get size(){return this.content.length>>1}};l.from=function(t){if(t instanceof l)return t;var e=[];if(t)for(var i in t)e.push(i,t[i]);return new l(e)};function o(t,e,i){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:i;let s=t.child(r),n=e.child(r);if(s==n){i+=s.nodeSize;continue}if(!s.sameMarkup(n))return i;if(s.isText&&s.text!=n.text){for(let t=0;s.text[t]==n.text[t];t++)i++;return i}if(s.content.size||n.content.size){let t=o(s.content,n.content,i+1);if(t!=null)return t}i+=s.nodeSize}}function f(t,e,i,r){for(let s=t.childCount,n=e.childCount;;){if(s==0||n==0)return s==n?null:{a:i,b:r};let h=t.child(--s),l=e.child(--n),o=h.nodeSize;if(h==l){i-=o;r-=o;continue}if(!h.sameMarkup(l))return{a:i,b:r};if(h.isText&&h.text!=l.text){let t=0,e=Math.min(h.text.length,l.text.length);while(t<e&&h.text[h.text.length-t-1]==l.text[l.text.length-t-1]){t++;i--;r--}return{a:i,b:r}}if(h.content.size||l.content.size){let t=f(h.content,l.content,i-1,r-1);if(t)return t}i-=o;r-=o}}class u{constructor(t,e){this.content=t;this.size=e||0;if(e==null)for(let e=0;e<t.length;e++)this.size+=t[e].nodeSize}nodesBetween(t,e,i,r=0,s){for(let n=0,h=0;h<e;n++){let l=this.content[n],o=h+l.nodeSize;if(o>t&&i(l,r+h,s||null,n)!==false&&l.content.size){let s=h+1;l.nodesBetween(Math.max(0,t-s),Math.min(l.content.size,e-s),i,r+s)}h=o}}descendants(t){this.nodesBetween(0,this.size,t)}textBetween(t,e,i,r){let s="",n=true;this.nodesBetween(t,e,((h,l)=>{let o=h.isText?h.text.slice(Math.max(t,l)-l,e-l):!h.isLeaf?"":r?typeof r==="function"?r(h):r:h.type.spec.leafText?h.type.spec.leafText(h):"";if(h.isBlock&&(h.isLeaf&&o||h.isTextblock)&&i){if(n)n=false;else s+=i}s+=o}),0);return s}append(t){if(!t.size)return this;if(!this.size)return t;let e=this.lastChild,i=t.firstChild,r=this.content.slice(),s=0;if(e.isText&&e.sameMarkup(i)){r[r.length-1]=e.withText(e.text+i.text);s=1}for(;s<t.content.length;s++)r.push(t.content[s]);return new u(r,this.size+t.size)}cut(t,e=this.size){if(t==0&&e==this.size)return this;let i=[],r=0;if(e>t)for(let s=0,n=0;n<e;s++){let h=this.content[s],l=n+h.nodeSize;if(l>t){if(n<t||l>e){if(h.isText)h=h.cut(Math.max(0,t-n),Math.min(h.text.length,e-n));else h=h.cut(Math.max(0,t-n-1),Math.min(h.content.size,e-n-1))}i.push(h);r+=h.nodeSize}n=l}return new u(i,r)}cutByIndex(t,e){if(t==e)return u.empty;if(t==0&&e==this.content.length)return this;return new u(this.content.slice(t,e))}replaceChild(t,e){let i=this.content[t];if(i==e)return this;let r=this.content.slice();let s=this.size+e.nodeSize-i.nodeSize;r[t]=e;return new u(r,s)}addToStart(t){return new u([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new u(this.content.concat(t),this.size+t.nodeSize)}eq(t){if(this.content.length!=t.content.length)return false;for(let e=0;e<this.content.length;e++)if(!this.content[e].eq(t.content[e]))return false;return true}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(t){let e=this.content[t];if(!e)throw new RangeError("Index "+t+" out of range for "+this);return e}maybeChild(t){return this.content[t]||null}forEach(t){for(let e=0,i=0;e<this.content.length;e++){let r=this.content[e];t(r,i,e);i+=r.nodeSize}}findDiffStart(t,e=0){return o(this,t,e)}findDiffEnd(t,e=this.size,i=t.size){return f(this,t,e,i)}findIndex(t){if(t==0)return c(0,t);if(t==this.size)return c(this.content.length,t);if(t>this.size||t<0)throw new RangeError(`Position ${t} outside of fragment (${this})`);for(let e=0,i=0;;e++){let r=this.child(e),s=i+r.nodeSize;if(s>=t){if(s==t)return c(e+1,s);return c(e,i)}i=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map((t=>t.toJSON())):null}static fromJSON(t,e){if(!e)return u.empty;if(!Array.isArray(e))throw new RangeError("Invalid input for Fragment.fromJSON");return new u(e.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return u.empty;let e,i=0;for(let r=0;r<t.length;r++){let s=t[r];i+=s.nodeSize;if(r&&s.isText&&t[r-1].sameMarkup(s)){if(!e)e=t.slice(0,r);e[e.length-1]=s.withText(e[e.length-1].text+s.text)}else if(e){e.push(s)}}return new u(e||t,i)}static from(t){if(!t)return u.empty;if(t instanceof u)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new u([t],t.nodeSize);throw new RangeError("Can not convert "+t+" to a Fragment"+(t.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}u.empty=new u([],0);const a={index:0,offset:0};function c(t,e){a.index=t;a.offset=e;return a}function d(t,e){if(t===e)return true;if(!(t&&typeof t=="object")||!(e&&typeof e=="object"))return false;let i=Array.isArray(t);if(Array.isArray(e)!=i)return false;if(i){if(t.length!=e.length)return false;for(let i=0;i<t.length;i++)if(!d(t[i],e[i]))return false}else{for(let i in t)if(!(i in e)||!d(t[i],e[i]))return false;for(let i in e)if(!(i in t))return false}return true}class p{constructor(t,e){this.type=t;this.attrs=e}addToSet(t){let e,i=false;for(let r=0;r<t.length;r++){let s=t[r];if(this.eq(s))return t;if(this.type.excludes(s.type)){if(!e)e=t.slice(0,r)}else if(s.type.excludes(this.type)){return t}else{if(!i&&s.type.rank>this.type.rank){if(!e)e=t.slice(0,r);e.push(this);i=true}if(e)e.push(s)}}if(!e)e=t.slice();if(!i)e.push(this);return e}removeFromSet(t){for(let e=0;e<t.length;e++)if(this.eq(t[e]))return t.slice(0,e).concat(t.slice(e+1));return t}isInSet(t){for(let e=0;e<t.length;e++)if(this.eq(t[e]))return true;return false}eq(t){return this==t||this.type==t.type&&d(this.attrs,t.attrs)}toJSON(){let t={type:this.type.name};for(let e in this.attrs){t.attrs=this.attrs;break}return t}static fromJSON(t,e){if(!e)throw new RangeError("Invalid input for Mark.fromJSON");let i=t.marks[e.type];if(!i)throw new RangeError(`There is no mark type ${e.type} in this schema`);let r=i.create(e.attrs);i.checkAttrs(r.attrs);return r}static sameSet(t,e){if(t==e)return true;if(t.length!=e.length)return false;for(let i=0;i<t.length;i++)if(!t[i].eq(e[i]))return false;return true}static setFrom(t){if(!t||Array.isArray(t)&&t.length==0)return p.none;if(t instanceof p)return[t];let e=t.slice();e.sort(((t,e)=>t.type.rank-e.type.rank));return e}}p.none=[];class w extends Error{}class m{constructor(t,e,i){this.content=t;this.openStart=e;this.openEnd=i}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,e){let i=b(this.content,t+this.openStart,e);return i&&new m(i,this.openStart,this.openEnd)}removeBetween(t,e){return new m(g(this.content,t+this.openStart,e+this.openStart),this.openStart,this.openEnd)}eq(t){return this.content.eq(t.content)&&this.openStart==t.openStart&&this.openEnd==t.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let t={content:this.content.toJSON()};if(this.openStart>0)t.openStart=this.openStart;if(this.openEnd>0)t.openEnd=this.openEnd;return t}static fromJSON(t,e){if(!e)return m.empty;let i=e.openStart||0,r=e.openEnd||0;if(typeof i!="number"||typeof r!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new m(u.fromJSON(t,e.content),i,r)}static maxOpen(t,e=true){let i=0,r=0;for(let r=t.firstChild;r&&!r.isLeaf&&(e||!r.type.spec.isolating);r=r.firstChild)i++;for(let i=t.lastChild;i&&!i.isLeaf&&(e||!i.type.spec.isolating);i=i.lastChild)r++;return new m(t,i,r)}}m.empty=new m(u.empty,0,0);function g(t,e,i){let{index:r,offset:s}=t.findIndex(e),n=t.maybeChild(r);let{index:h,offset:l}=t.findIndex(i);if(s==e||n.isText){if(l!=i&&!t.child(h).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(i))}if(r!=h)throw new RangeError("Removing non-flat range");return t.replaceChild(r,n.copy(g(n.content,e-s-1,i-s-1)))}function b(t,e,i,r){let{index:s,offset:n}=t.findIndex(e),h=t.maybeChild(s);if(n==e||h.isText){if(r&&!r.canReplace(s,s,i))return null;return t.cut(0,e).append(i).append(t.cut(e))}let l=b(h.content,e-n-1,i,h);return l&&t.replaceChild(s,h.copy(l))}function v(t,e,i){if(i.openStart>t.depth)throw new w("Inserted content deeper than insertion position");if(t.depth-i.openStart!=e.depth-i.openEnd)throw new w("Inconsistent open depths");return y(t,e,i,0)}function y(t,e,i,r){let s=t.index(r),n=t.node(r);if(s==e.index(r)&&r<t.depth-i.openStart){let h=y(t,e,i,r+1);return n.copy(n.content.replaceChild(s,h))}else if(!i.content.size){return x(n,O(t,e,r))}else if(!i.openStart&&!i.openEnd&&t.depth==r&&e.depth==r){let r=t.parent,s=r.content;return x(r,s.cut(0,t.parentOffset).append(i.content).append(s.cut(e.parentOffset)))}else{let{start:s,end:h}=D(i,t);return x(n,E(t,s,h,e,r))}}function M(t,e){if(!e.type.compatibleContent(t.type))throw new w("Cannot join "+e.type.name+" onto "+t.type.name)}function A(t,e,i){let r=t.node(i);M(r,e.node(i));return r}function k(t,e){let i=e.length-1;if(i>=0&&t.isText&&t.sameMarkup(e[i]))e[i]=t.withText(e[i].text+t.text);else e.push(t)}function S(t,e,i,r){let s=(e||t).node(i);let n=0,h=e?e.index(i):s.childCount;if(t){n=t.index(i);if(t.depth>i){n++}else if(t.textOffset){k(t.nodeAfter,r);n++}}for(let t=n;t<h;t++)k(s.child(t),r);if(e&&e.depth==i&&e.textOffset)k(e.nodeBefore,r)}function x(t,e){t.type.checkContent(e);return t.copy(e)}function E(t,e,i,r,s){let n=t.depth>s&&A(t,e,s+1);let h=r.depth>s&&A(i,r,s+1);let l=[];S(null,t,s,l);if(n&&h&&e.index(s)==i.index(s)){M(n,h);k(x(n,E(t,e,i,r,s+1)),l)}else{if(n)k(x(n,O(t,e,s+1)),l);S(e,i,s,l);if(h)k(x(h,O(i,r,s+1)),l)}S(r,null,s,l);return new u(l)}function O(t,e,i){let r=[];S(null,t,i,r);if(t.depth>i){let s=A(t,e,i+1);k(x(s,O(t,e,i+1)),r)}S(e,null,i,r);return new u(r)}function D(t,e){let i=e.depth-t.openStart,r=e.node(i);let s=r.copy(t.content);for(let t=i-1;t>=0;t--)s=e.node(t).copy(u.from(s));return{start:s.resolveNoCache(t.openStart+i),end:s.resolveNoCache(s.content.size-t.openEnd-i)}}class T{constructor(t,e,i){this.pos=t;this.path=e;this.parentOffset=i;this.depth=e.length/3-1}resolveDepth(t){if(t==null)return this.depth;if(t<0)return this.depth+t;return t}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(t){return this.path[this.resolveDepth(t)*3]}index(t){return this.path[this.resolveDepth(t)*3+1]}indexAfter(t){t=this.resolveDepth(t);return this.index(t)+(t==this.depth&&!this.textOffset?0:1)}start(t){t=this.resolveDepth(t);return t==0?0:this.path[t*3-1]+1}end(t){t=this.resolveDepth(t);return this.start(t)+this.node(t).content.size}before(t){t=this.resolveDepth(t);if(!t)throw new RangeError("There is no position before the top-level node");return t==this.depth+1?this.pos:this.path[t*3-1]}after(t){t=this.resolveDepth(t);if(!t)throw new RangeError("There is no position after the top-level node");return t==this.depth+1?this.pos:this.path[t*3-1]+this.path[t*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let t=this.parent,e=this.index(this.depth);if(e==t.childCount)return null;let i=this.pos-this.path[this.path.length-1],r=t.child(e);return i?t.child(e).cut(i):r}get nodeBefore(){let t=this.index(this.depth);let e=this.pos-this.path[this.path.length-1];if(e)return this.parent.child(t).cut(0,e);return t==0?null:this.parent.child(t-1)}posAtIndex(t,e){e=this.resolveDepth(e);let i=this.path[e*3],r=e==0?0:this.path[e*3-1]+1;for(let e=0;e<t;e++)r+=i.child(e).nodeSize;return r}marks(){let t=this.parent,e=this.index();if(t.content.size==0)return p.none;if(this.textOffset)return t.child(e).marks;let i=t.maybeChild(e-1),r=t.maybeChild(e);if(!i){let t=i;i=r;r=t}let s=i.marks;for(var n=0;n<s.length;n++)if(s[n].type.spec.inclusive===false&&(!r||!s[n].isInSet(r.marks)))s=s[n--].removeFromSet(s);return s}marksAcross(t){let e=this.parent.maybeChild(this.index());if(!e||!e.isInline)return null;let i=e.marks,r=t.parent.maybeChild(t.index());for(var s=0;s<i.length;s++)if(i[s].type.spec.inclusive===false&&(!r||!i[s].isInSet(r.marks)))i=i[s--].removeFromSet(i);return i}sharedDepth(t){for(let e=this.depth;e>0;e--)if(this.start(e)<=t&&this.end(e)>=t)return e;return 0}blockRange(t=this,e){if(t.pos<this.pos)return t.blockRange(this);for(let i=this.depth-(this.parent.inlineContent||this.pos==t.pos?1:0);i>=0;i--)if(t.pos<=this.end(i)&&(!e||e(this.node(i))))return new I(this,t,i);return null}sameParent(t){return this.pos-this.parentOffset==t.pos-t.parentOffset}max(t){return t.pos>this.pos?t:this}min(t){return t.pos<this.pos?t:this}toString(){let t="";for(let e=1;e<=this.depth;e++)t+=(t?"/":"")+this.node(e).type.name+"_"+this.index(e-1);return t+":"+this.parentOffset}static resolve(t,e){if(!(e>=0&&e<=t.content.size))throw new RangeError("Position "+e+" out of range");let i=[];let r=0,s=e;for(let e=t;;){let{index:t,offset:n}=e.content.findIndex(s);let h=s-n;i.push(e,t,r+n);if(!h)break;e=e.child(t);if(e.isText)break;s=h-1;r+=n+1}return new T(e,i,s)}static resolveCached(t,e){let i=P.get(t);if(i){for(let t=0;t<i.elts.length;t++){let r=i.elts[t];if(r.pos==e)return r}}else{P.set(t,i=new R)}let r=i.elts[i.i]=T.resolve(t,e);i.i=(i.i+1)%C;return r}}class R{constructor(){this.elts=[];this.i=0}}const C=12,P=new WeakMap;class I{constructor(t,e,i){this.$from=t;this.$to=e;this.depth=i}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}const N=Object.create(null);class F{constructor(t,e,i,r=p.none){this.type=t;this.attrs=e;this.marks=r;this.content=i||u.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(t){return this.content.child(t)}maybeChild(t){return this.content.maybeChild(t)}forEach(t){this.content.forEach(t)}nodesBetween(t,e,i,r=0){this.content.nodesBetween(t,e,i,r,this)}descendants(t){this.nodesBetween(0,this.content.size,t)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(t,e,i,r){return this.content.textBetween(t,e,i,r)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(t){return this==t||this.sameMarkup(t)&&this.content.eq(t.content)}sameMarkup(t){return this.hasMarkup(t.type,t.attrs,t.marks)}hasMarkup(t,e,i){return this.type==t&&d(this.attrs,e||t.defaultAttrs||N)&&p.sameSet(this.marks,i||p.none)}copy(t=null){if(t==this.content)return this;return new F(this.type,this.attrs,t,this.marks)}mark(t){return t==this.marks?this:new F(this.type,this.attrs,this.content,t)}cut(t,e=this.content.size){if(t==0&&e==this.content.size)return this;return this.copy(this.content.cut(t,e))}slice(t,e=this.content.size,i=false){if(t==e)return m.empty;let r=this.resolve(t),s=this.resolve(e);let n=i?0:r.sharedDepth(e);let h=r.start(n),l=r.node(n);let o=l.content.cut(r.pos-h,s.pos-h);return new m(o,r.depth-n,s.depth-n)}replace(t,e,i){return v(this.resolve(t),this.resolve(e),i)}nodeAt(t){for(let e=this;;){let{index:i,offset:r}=e.content.findIndex(t);e=e.maybeChild(i);if(!e)return null;if(r==t||e.isText)return e;t-=r+1}}childAfter(t){let{index:e,offset:i}=this.content.findIndex(t);return{node:this.content.maybeChild(e),index:e,offset:i}}childBefore(t){if(t==0)return{node:null,index:0,offset:0};let{index:e,offset:i}=this.content.findIndex(t);if(i<t)return{node:this.content.child(e),index:e,offset:i};let r=this.content.child(e-1);return{node:r,index:e-1,offset:i-r.nodeSize}}resolve(t){return T.resolveCached(this,t)}resolveNoCache(t){return T.resolve(this,t)}rangeHasMark(t,e,i){let r=false;if(e>t)this.nodesBetween(t,e,(t=>{if(i.isInSet(t.marks))r=true;return!r}));return r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let t=this.type.name;if(this.content.size)t+="("+this.content.toStringInner()+")";return U(this.marks,t)}contentMatchAt(t){let e=this.type.contentMatch.matchFragment(this.content,0,t);if(!e)throw new Error("Called contentMatchAt on a node with invalid content");return e}canReplace(t,e,i=u.empty,r=0,s=i.childCount){let n=this.contentMatchAt(t).matchFragment(i,r,s);let h=n&&n.matchFragment(this.content,e);if(!h||!h.validEnd)return false;for(let t=r;t<s;t++)if(!this.type.allowsMarks(i.child(t).marks))return false;return true}canReplaceWith(t,e,i,r){if(r&&!this.type.allowsMarks(r))return false;let s=this.contentMatchAt(t).matchType(i);let n=s&&s.matchFragment(this.content,e);return n?n.validEnd:false}canAppend(t){if(t.content.size)return this.canReplace(this.childCount,this.childCount,t.content);else return this.type.compatibleContent(t.type)}check(){this.type.checkContent(this.content);this.type.checkAttrs(this.attrs);let t=p.none;for(let e=0;e<this.marks.length;e++){let i=this.marks[e];i.type.checkAttrs(i.attrs);t=i.addToSet(t)}if(!p.sameSet(t,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map((t=>t.type.name))}`);this.content.forEach((t=>t.check()))}toJSON(){let t={type:this.type.name};for(let e in this.attrs){t.attrs=this.attrs;break}if(this.content.size)t.content=this.content.toJSON();if(this.marks.length)t.marks=this.marks.map((t=>t.toJSON()));return t}static fromJSON(t,e){if(!e)throw new RangeError("Invalid input for Node.fromJSON");let i=undefined;if(e.marks){if(!Array.isArray(e.marks))throw new RangeError("Invalid mark data for Node.fromJSON");i=e.marks.map(t.markFromJSON)}if(e.type=="text"){if(typeof e.text!="string")throw new RangeError("Invalid text node in JSON");return t.text(e.text,i)}let r=u.fromJSON(t,e.content);let s=t.nodeType(e.type).create(e.attrs,r,i);s.type.checkAttrs(s.attrs);return s}}F.prototype.text=undefined;class B extends F{constructor(t,e,i,r){super(t,e,null,r);if(!i)throw new RangeError("Empty text nodes are not allowed");this.text=i}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);return U(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(t,e){return this.text.slice(t,e)}get nodeSize(){return this.text.length}mark(t){return t==this.marks?this:new B(this.type,this.attrs,this.text,t)}withText(t){if(t==this.text)return this;return new B(this.type,this.attrs,t,this.marks)}cut(t=0,e=this.text.length){if(t==0&&e==this.text.length)return this;return this.withText(this.text.slice(t,e))}eq(t){return this.sameMarkup(t)&&this.text==t.text}toJSON(){let t=super.toJSON();t.text=this.text;return t}}function U(t,e){for(let i=t.length-1;i>=0;i--)e=t[i].type.name+"("+e+")";return e}class j{constructor(t){this.validEnd=t;this.next=[];this.wrapCache=[]}static parse(t,e){let i=new $(t,e);if(i.next==null)return j.empty;let r=_(i);if(i.next)i.err("Unexpected trailing text");let s=X(H(r));Y(s,i);return s}matchType(t){for(let e=0;e<this.next.length;e++)if(this.next[e].type==t)return this.next[e].next;return null}matchFragment(t,e=0,i=t.childCount){let r=this;for(let s=e;r&&s<i;s++)r=r.matchType(t.child(s).type);return r}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let t=0;t<this.next.length;t++){let{type:e}=this.next[t];if(!(e.isText||e.hasRequiredAttrs()))return e}return null}compatible(t){for(let e=0;e<this.next.length;e++)for(let i=0;i<t.next.length;i++)if(this.next[e].type==t.next[i].type)return true;return false}fillBefore(t,e=false,i=0){let r=[this];function s(n,h){let l=n.matchFragment(t,i);if(l&&(!e||l.validEnd))return u.from(h.map((t=>t.createAndFill())));for(let t=0;t<n.next.length;t++){let{type:e,next:i}=n.next[t];if(!(e.isText||e.hasRequiredAttrs())&&r.indexOf(i)==-1){r.push(i);let t=s(i,h.concat(e));if(t)return t}}return null}return s(this,[])}findWrapping(t){for(let e=0;e<this.wrapCache.length;e+=2)if(this.wrapCache[e]==t)return this.wrapCache[e+1];let e=this.computeWrapping(t);this.wrapCache.push(t,e);return e}computeWrapping(t){let e=Object.create(null),i=[{match:this,type:null,via:null}];while(i.length){let r=i.shift(),s=r.match;if(s.matchType(t)){let t=[];for(let e=r;e.type;e=e.via)t.push(e.type);return t.reverse()}for(let t=0;t<s.next.length;t++){let{type:n,next:h}=s.next[t];if(!n.isLeaf&&!n.hasRequiredAttrs()&&!(n.name in e)&&(!r.type||h.validEnd)){i.push({match:n.contentMatch,type:n,via:r});e[n.name]=true}}}return null}get edgeCount(){return this.next.length}edge(t){if(t>=this.next.length)throw new RangeError(`There's no ${t}th edge in this content match`);return this.next[t]}toString(){let t=[];function e(i){t.push(i);for(let r=0;r<i.next.length;r++)if(t.indexOf(i.next[r].next)==-1)e(i.next[r].next)}e(this);return t.map(((e,i)=>{let r=i+(e.validEnd?"*":" ")+" ";for(let i=0;i<e.next.length;i++)r+=(i?", ":"")+e.next[i].type.name+"->"+t.indexOf(e.next[i].next);return r})).join("\n")}}j.empty=new j(true);class ${constructor(t,e){this.string=t;this.nodeTypes=e;this.inline=null;this.pos=0;this.tokens=t.split(/\s*(?=\b|\W|$)/);if(this.tokens[this.tokens.length-1]=="")this.tokens.pop();if(this.tokens[0]=="")this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(t){return this.next==t&&(this.pos++||true)}err(t){throw new SyntaxError(t+" (in content expression '"+this.string+"')")}}function _(t){let e=[];do{e.push(z(t))}while(t.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function z(t){let e=[];do{e.push(J(t))}while(t.next&&t.next!=")"&&t.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function J(t){let e=K(t);for(;;){if(t.eat("+"))e={type:"plus",expr:e};else if(t.eat("*"))e={type:"star",expr:e};else if(t.eat("?"))e={type:"opt",expr:e};else if(t.eat("{"))e=Q(t,e);else break}return e}function W(t){if(/\D/.test(t.next))t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);t.pos++;return e}function Q(t,e){let i=W(t),r=i;if(t.eat(",")){if(t.next!="}")r=W(t);else r=-1}if(!t.eat("}"))t.err("Unclosed braced range");return{type:"range",min:i,max:r,expr:e}}function L(t,e){let i=t.nodeTypes,r=i[e];if(r)return[r];let s=[];for(let t in i){let r=i[t];if(r.isInGroup(e))s.push(r)}if(s.length==0)t.err("No node type or group '"+e+"' found");return s}function K(t){if(t.eat("(")){let e=_(t);if(!t.eat(")"))t.err("Missing closing paren");return e}else if(!/\W/.test(t.next)){let e=L(t,t.next).map((e=>{if(t.inline==null)t.inline=e.isInline;else if(t.inline!=e.isInline)t.err("Mixing inline and block content");return{type:"name",value:e}}));t.pos++;return e.length==1?e[0]:{type:"choice",exprs:e}}else{t.err("Unexpected token '"+t.next+"'")}}function H(t){let e=[[]];s(n(t,0),i());return e;function i(){return e.push([])-1}function r(t,i,r){let s={term:r,to:i};e[t].push(s);return s}function s(t,e){t.forEach((t=>t.to=e))}function n(t,e){if(t.type=="choice"){return t.exprs.reduce(((t,i)=>t.concat(n(i,e))),[])}else if(t.type=="seq"){for(let r=0;;r++){let h=n(t.exprs[r],e);if(r==t.exprs.length-1)return h;s(h,e=i())}}else if(t.type=="star"){let h=i();r(e,h);s(n(t.expr,h),h);return[r(h)]}else if(t.type=="plus"){let h=i();s(n(t.expr,e),h);s(n(t.expr,h),h);return[r(h)]}else if(t.type=="opt"){return[r(e)].concat(n(t.expr,e))}else if(t.type=="range"){let h=e;for(let e=0;e<t.min;e++){let e=i();s(n(t.expr,h),e);h=e}if(t.max==-1){s(n(t.expr,h),h)}else{for(let e=t.min;e<t.max;e++){let e=i();r(h,e);s(n(t.expr,h),e);h=e}}return[r(h)]}else if(t.type=="name"){return[r(e,undefined,t.value)]}else{throw new Error("Unknown expr type")}}}function q(t,e){return e-t}function G(t,e){let i=[];r(e);return i.sort(q);function r(e){let s=t[e];if(s.length==1&&!s[0].term)return r(s[0].to);i.push(e);for(let t=0;t<s.length;t++){let{term:e,to:n}=s[t];if(!e&&i.indexOf(n)==-1)r(n)}}}function X(t){let e=Object.create(null);return i(G(t,0));function i(r){let s=[];r.forEach((e=>{t[e].forEach((({term:e,to:i})=>{if(!e)return;let r;for(let t=0;t<s.length;t++)if(s[t][0]==e)r=s[t][1];G(t,i).forEach((t=>{if(!r)s.push([e,r=[]]);if(r.indexOf(t)==-1)r.push(t)}))}))}));let n=e[r.join(",")]=new j(r.indexOf(t.length-1)>-1);for(let t=0;t<s.length;t++){let r=s[t][1].sort(q);n.next.push({type:s[t][0],next:e[r.join(",")]||i(r)})}return n}}function Y(t,e){for(let i=0,r=[t];i<r.length;i++){let t=r[i],s=!t.validEnd,n=[];for(let e=0;e<t.next.length;e++){let{type:i,next:h}=t.next[e];n.push(i.name);if(s&&!(i.isText||i.hasRequiredAttrs()))s=false;if(r.indexOf(h)==-1)r.push(h)}if(s)e.err("Only non-generatable nodes ("+n.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function V(t){let e=Object.create(null);for(let i in t){let r=t[i];if(!r.hasDefault)return null;e[i]=r.default}return e}function Z(t,e){let i=Object.create(null);for(let r in t){let s=e&&e[r];if(s===undefined){let e=t[r];if(e.hasDefault)s=e.default;else throw new RangeError("No value supplied for attribute "+r)}i[r]=s}return i}function tt(t,e,i,r){for(let r in e)if(!(r in t))throw new RangeError(`Unsupported attribute ${r} for ${i} of type ${r}`);for(let i in t){let r=t[i];if(r.validate)r.validate(e[i])}}function et(t,e){let i=Object.create(null);if(e)for(let r in e)i[r]=new st(t,r,e[r]);return i}let it=class t{constructor(t,e,i){this.name=t;this.schema=e;this.spec=i;this.markSet=null;this.groups=i.group?i.group.split(" "):[];this.attrs=et(t,i.attrs);this.defaultAttrs=V(this.attrs);this.contentMatch=null;this.inlineContent=null;this.isBlock=!(i.inline||t=="text");this.isText=t=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==j.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(t){return this.groups.indexOf(t)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let t in this.attrs)if(this.attrs[t].isRequired)return true;return false}compatibleContent(t){return this==t||this.contentMatch.compatible(t.contentMatch)}computeAttrs(t){if(!t&&this.defaultAttrs)return this.defaultAttrs;else return Z(this.attrs,t)}create(t=null,e,i){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new F(this,this.computeAttrs(t),u.from(e),p.setFrom(i))}createChecked(t=null,e,i){e=u.from(e);this.checkContent(e);return new F(this,this.computeAttrs(t),e,p.setFrom(i))}createAndFill(t=null,e,i){t=this.computeAttrs(t);e=u.from(e);if(e.size){let t=this.contentMatch.fillBefore(e);if(!t)return null;e=t.append(e)}let r=this.contentMatch.matchFragment(e);let s=r&&r.fillBefore(u.empty,true);if(!s)return null;return new F(this,t,e.append(s),p.setFrom(i))}validContent(t){let e=this.contentMatch.matchFragment(t);if(!e||!e.validEnd)return false;for(let e=0;e<t.childCount;e++)if(!this.allowsMarks(t.child(e).marks))return false;return true}checkContent(t){if(!this.validContent(t))throw new RangeError(`Invalid content for node ${this.name}: ${t.toString().slice(0,50)}`)}checkAttrs(t){tt(this.attrs,t,"node")}allowsMarkType(t){return this.markSet==null||this.markSet.indexOf(t)>-1}allowsMarks(t){if(this.markSet==null)return true;for(let e=0;e<t.length;e++)if(!this.allowsMarkType(t[e].type))return false;return true}allowedMarks(t){if(this.markSet==null)return t;let e;for(let i=0;i<t.length;i++){if(!this.allowsMarkType(t[i].type)){if(!e)e=t.slice(0,i)}else if(e){e.push(t[i])}}return!e?t:e.length?e:p.none}static compile(e,i){let r=Object.create(null);e.forEach(((e,s)=>r[e]=new t(e,i,s)));let s=i.spec.topNode||"doc";if(!r[s])throw new RangeError("Schema is missing its top node type ('"+s+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let t in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function rt(t,e,i){let r=i.split("|");return i=>{let s=i===null?"null":typeof i;if(r.indexOf(s)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${t}, got ${s}`)}}class st{constructor(t,e,i){this.hasDefault=Object.prototype.hasOwnProperty.call(i,"default");this.default=i.default;this.validate=typeof i.validate=="string"?rt(t,e,i.validate):i.validate}get isRequired(){return!this.hasDefault}}class nt{constructor(t,e,i,r){this.name=t;this.rank=e;this.schema=i;this.spec=r;this.attrs=et(t,r.attrs);this.excluded=null;let s=V(this.attrs);this.instance=s?new p(this,s):null}create(t=null){if(!t&&this.instance)return this.instance;return new p(this,Z(this.attrs,t))}static compile(t,e){let i=Object.create(null),r=0;t.forEach(((t,s)=>i[t]=new nt(t,r++,e,s)));return i}removeFromSet(t){for(var e=0;e<t.length;e++)if(t[e].type==this){t=t.slice(0,e).concat(t.slice(e+1));e--}return t}isInSet(t){for(let e=0;e<t.length;e++)if(t[e].type==this)return t[e]}checkAttrs(t){tt(this.attrs,t,"mark")}excludes(t){return this.excluded.indexOf(t)>-1}}class ht{constructor(t){this.linebreakReplacement=null;this.cached=Object.create(null);let e=this.spec={};for(let i in t)e[i]=t[i];e.nodes=l.from(t.nodes),e.marks=l.from(t.marks||{}),this.nodes=it.compile(this.spec.nodes,this);this.marks=nt.compile(this.spec.marks,this);let i=Object.create(null);for(let t in this.nodes){if(t in this.marks)throw new RangeError(t+" can not be both a node and a mark");let e=this.nodes[t],r=e.spec.content||"",s=e.spec.marks;e.contentMatch=i[r]||(i[r]=j.parse(r,this.nodes));e.inlineContent=e.contentMatch.inlineContent;if(e.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!e.isInline||!e.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=e}e.markSet=s=="_"?null:s?lt(this,s.split(" ")):s==""||!e.inlineContent?[]:null}for(let t in this.marks){let e=this.marks[t],i=e.spec.excludes;e.excluded=i==null?[e]:i==""?[]:lt(this,i.split(" "))}this.nodeFromJSON=t=>F.fromJSON(this,t);this.markFromJSON=t=>p.fromJSON(this,t);this.topNodeType=this.nodes[this.spec.topNode||"doc"];this.cached.wrappings=Object.create(null)}node(t,e=null,i,r){if(typeof t=="string")t=this.nodeType(t);else if(!(t instanceof it))throw new RangeError("Invalid node type: "+t);else if(t.schema!=this)throw new RangeError("Node type from different schema used ("+t.name+")");return t.createChecked(e,i,r)}text(t,e){let i=this.nodes.text;return new B(i,i.defaultAttrs,t,p.setFrom(e))}mark(t,e){if(typeof t=="string")t=this.marks[t];return t.create(e)}nodeType(t){let e=this.nodes[t];if(!e)throw new RangeError("Unknown node type: "+t);return e}}function lt(t,e){let i=[];for(let r=0;r<e.length;r++){let s=e[r],n=t.marks[s],h=n;if(n){i.push(n)}else{for(let e in t.marks){let r=t.marks[e];if(s=="_"||r.spec.group&&r.spec.group.split(" ").indexOf(s)>-1)i.push(h=r)}}if(!h)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return i}function ot(t){return t.tag!=null}function ft(t){return t.style!=null}class ut{constructor(t,e){this.schema=t;this.rules=e;this.tags=[];this.styles=[];let i=this.matchedStyles=[];e.forEach((t=>{if(ot(t)){this.tags.push(t)}else if(ft(t)){let e=/[^=]*/.exec(t.style)[0];if(i.indexOf(e)<0)i.push(e);this.styles.push(t)}}));this.normalizeLists=!this.tags.some((e=>{if(!/^(ul|ol)\b/.test(e.tag)||!e.node)return false;let i=t.nodes[e.node];return i.contentMatch.matchType(i)}))}parse(t,e={}){let i=new vt(this,e,false);i.addAll(t,p.none,e.from,e.to);return i.finish()}parseSlice(t,e={}){let i=new vt(this,e,true);i.addAll(t,p.none,e.from,e.to);return m.maxOpen(i.finish())}matchTag(t,e,i){for(let r=i?this.tags.indexOf(i)+1:0;r<this.tags.length;r++){let i=this.tags[r];if(Mt(t,i.tag)&&(i.namespace===undefined||t.namespaceURI==i.namespace)&&(!i.context||e.matchesContext(i.context))){if(i.getAttrs){let e=i.getAttrs(t);if(e===false)continue;i.attrs=e||undefined}return i}}}matchStyle(t,e,i,r){for(let s=r?this.styles.indexOf(r)+1:0;s<this.styles.length;s++){let r=this.styles[s],n=r.style;if(n.indexOf(t)!=0||r.context&&!i.matchesContext(r.context)||n.length>t.length&&(n.charCodeAt(t.length)!=61||n.slice(t.length+1)!=e))continue;if(r.getAttrs){let t=r.getAttrs(e);if(t===false)continue;r.attrs=t||undefined}return r}}static schemaRules(t){let e=[];function i(t){let i=t.priority==null?50:t.priority,r=0;for(;r<e.length;r++){let t=e[r],s=t.priority==null?50:t.priority;if(s<i)break}e.splice(r,0,t)}for(let e in t.marks){let r=t.marks[e].spec.parseDOM;if(r)r.forEach((t=>{i(t=At(t));if(!(t.mark||t.ignore||t.clearMark))t.mark=e}))}for(let e in t.nodes){let r=t.nodes[e].spec.parseDOM;if(r)r.forEach((t=>{i(t=At(t));if(!(t.node||t.ignore||t.mark))t.node=e}))}return e}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new ut(t,ut.schemaRules(t)))}}const at={address:true,article:true,aside:true,blockquote:true,canvas:true,dd:true,div:true,dl:true,fieldset:true,figcaption:true,figure:true,footer:true,form:true,h1:true,h2:true,h3:true,h4:true,h5:true,h6:true,header:true,hgroup:true,hr:true,li:true,noscript:true,ol:true,output:true,p:true,pre:true,section:true,table:true,tfoot:true,ul:true};const ct={head:true,noscript:true,object:true,script:true,style:true,title:true};const dt={ol:true,ul:true};const pt=1,wt=2,mt=4;function gt(t,e,i){if(e!=null)return(e?pt:0)|(e==="full"?wt:0);return t&&t.whitespace=="pre"?pt|wt:i&-5}class bt{constructor(t,e,i,r,s,n){this.type=t;this.attrs=e;this.marks=i;this.solid=r;this.options=n;this.content=[];this.activeMarks=p.none;this.match=s||(n&mt?null:t.contentMatch)}findWrapping(t){if(!this.match){if(!this.type)return[];let e=this.type.contentMatch.fillBefore(u.from(t));if(e){this.match=this.type.contentMatch.matchFragment(e)}else{let e=this.type.contentMatch,i;if(i=e.findWrapping(t.type)){this.match=e;return i}else{return null}}}return this.match.findWrapping(t.type)}finish(t){if(!(this.options&pt)){let t=this.content[this.content.length-1],e;if(t&&t.isText&&(e=/[ \t\r\n\u000c]+$/.exec(t.text))){let i=t;if(t.text.length==e[0].length)this.content.pop();else this.content[this.content.length-1]=i.withText(i.text.slice(0,i.text.length-e[0].length))}}let e=u.from(this.content);if(!t&&this.match)e=e.append(this.match.fillBefore(u.empty,true));return this.type?this.type.create(this.attrs,e,this.marks):e}inlineContext(t){if(this.type)return this.type.inlineContent;if(this.content.length)return this.content[0].isInline;return t.parentNode&&!at.hasOwnProperty(t.parentNode.nodeName.toLowerCase())}}class vt{constructor(t,e,i){this.parser=t;this.options=e;this.isOpen=i;this.open=0;this.localPreserveWS=false;let r=e.topNode,s;let n=gt(null,e.preserveWhitespace,0)|(i?mt:0);if(r)s=new bt(r.type,r.attrs,p.none,true,e.topMatch||r.type.contentMatch,n);else if(i)s=new bt(null,null,p.none,true,null,n);else s=new bt(t.schema.topNodeType,null,p.none,true,null,n);this.nodes=[s];this.find=e.findPositions;this.needsBlock=false}get top(){return this.nodes[this.open]}addDOM(t,e){if(t.nodeType==3)this.addTextNode(t,e);else if(t.nodeType==1)this.addElement(t,e)}addTextNode(t,e){let i=t.nodeValue;let r=this.top,s=r.options&wt?"full":this.localPreserveWS||(r.options&pt)>0;let{schema:n}=this.parser;if(s==="full"||r.inlineContext(t)||/[^ \t\r\n\u000c]/.test(i)){if(!s){i=i.replace(/[ \t\r\n\u000c]+/g," ");if(/^[ \t\r\n\u000c]/.test(i)&&this.open==this.nodes.length-1){let e=r.content[r.content.length-1];let s=t.previousSibling;if(!e||s&&s.nodeName=="BR"||e.isText&&/[ \t\r\n\u000c]$/.test(e.text))i=i.slice(1)}}else if(s==="full"){i=i.replace(/\r\n?/g,"\n")}else if(n.linebreakReplacement&&/[\r\n]/.test(i)&&this.top.findWrapping(n.linebreakReplacement.create())){let t=i.split(/\r?\n|\r/);for(let i=0;i<t.length;i++){if(i)this.insertNode(n.linebreakReplacement.create(),e,true);if(t[i])this.insertNode(n.text(t[i]),e,!/\S/.test(t[i]))}i=""}else{i=i.replace(/\r?\n|\r/g," ")}if(i)this.insertNode(n.text(i),e,!/\S/.test(i));this.findInText(t)}else{this.findInside(t)}}addElement(t,e,i){let r=this.localPreserveWS,s=this.top;if(t.tagName=="PRE"||/pre/.test(t.style&&t.style.whiteSpace))this.localPreserveWS=true;let n=t.nodeName.toLowerCase(),h;if(dt.hasOwnProperty(n)&&this.parser.normalizeLists)yt(t);let l=this.options.ruleFromNode&&this.options.ruleFromNode(t)||(h=this.parser.matchTag(t,this,i));t:if(l?l.ignore:ct.hasOwnProperty(n)){this.findInside(t);this.ignoreFallback(t,e)}else if(!l||l.skip||l.closeParent){if(l&&l.closeParent)this.open=Math.max(0,this.open-1);else if(l&&l.skip.nodeType)t=l.skip;let i,r=this.needsBlock;if(at.hasOwnProperty(n)){if(s.content.length&&s.content[0].isInline&&this.open){this.open--;s=this.top}i=true;if(!s.type)this.needsBlock=true}else if(!t.firstChild){this.leafFallback(t,e);break t}let h=l&&l.skip?e:this.readStyles(t,e);if(h)this.addAll(t,h);if(i)this.sync(s);this.needsBlock=r}else{let i=this.readStyles(t,e);if(i)this.addElementByRule(t,l,i,l.consuming===false?h:undefined)}this.localPreserveWS=r}leafFallback(t,e){if(t.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent)this.addTextNode(t.ownerDocument.createTextNode("\n"),e)}ignoreFallback(t,e){if(t.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent))this.findPlace(this.parser.schema.text("-"),e,true)}readStyles(t,e){let i=t.style;if(i&&i.length)for(let t=0;t<this.parser.matchedStyles.length;t++){let r=this.parser.matchedStyles[t],s=i.getPropertyValue(r);if(s)for(let t=undefined;;){let i=this.parser.matchStyle(r,s,this,t);if(!i)break;if(i.ignore)return null;if(i.clearMark)e=e.filter((t=>!i.clearMark(t)));else e=e.concat(this.parser.schema.marks[i.mark].create(i.attrs));if(i.consuming===false)t=i;else break}}return e}addElementByRule(t,e,i,r){let s,n;if(e.node){n=this.parser.schema.nodes[e.node];if(!n.isLeaf){let t=this.enter(n,e.attrs||null,i,e.preserveWhitespace);if(t){s=true;i=t}}else if(!this.insertNode(n.create(e.attrs),i,t.nodeName=="BR")){this.leafFallback(t,i)}}else{let t=this.parser.schema.marks[e.mark];i=i.concat(t.create(e.attrs))}let h=this.top;if(n&&n.isLeaf){this.findInside(t)}else if(r){this.addElement(t,i,r)}else if(e.getContent){this.findInside(t);e.getContent(t,this.parser.schema).forEach((t=>this.insertNode(t,i,false)))}else{let r=t;if(typeof e.contentElement=="string")r=t.querySelector(e.contentElement);else if(typeof e.contentElement=="function")r=e.contentElement(t);else if(e.contentElement)r=e.contentElement;this.findAround(t,r,true);this.addAll(r,i);this.findAround(t,r,false)}if(s&&this.sync(h))this.open--}addAll(t,e,i,r){let s=i||0;for(let n=i?t.childNodes[i]:t.firstChild,h=r==null?null:t.childNodes[r];n!=h;n=n.nextSibling,++s){this.findAtPoint(t,s);this.addDOM(n,e)}this.findAtPoint(t,s)}findPlace(t,e,i){let r,s;for(let e=this.open,n=0;e>=0;e--){let h=this.nodes[e];let l=h.findWrapping(t);if(l&&(!r||r.length>l.length+n)){r=l;s=h;if(!l.length)break}if(h.solid){if(i)break;n+=2}}if(!r)return null;this.sync(s);for(let t=0;t<r.length;t++)e=this.enterInner(r[t],null,e,false);return e}insertNode(t,e,i){if(t.isInline&&this.needsBlock&&!this.top.type){let t=this.textblockFromContext();if(t)e=this.enterInner(t,null,e)}let r=this.findPlace(t,e,i);if(r){this.closeExtra();let e=this.top;if(e.match)e.match=e.match.matchType(t.type);let i=p.none;for(let s of r.concat(t.marks))if(e.type?e.type.allowsMarkType(s.type):kt(s.type,t.type))i=s.addToSet(i);e.content.push(t.mark(i));return true}return false}enter(t,e,i,r){let s=this.findPlace(t.create(e),i,false);if(s)s=this.enterInner(t,e,i,true,r);return s}enterInner(t,e,i,r=false,s){this.closeExtra();let n=this.top;n.match=n.match&&n.match.matchType(t);let h=gt(t,s,n.options);if(n.options&mt&&n.content.length==0)h|=mt;let l=p.none;i=i.filter((e=>{if(n.type?n.type.allowsMarkType(e.type):kt(e.type,t)){l=e.addToSet(l);return false}return true}));this.nodes.push(new bt(t,e,l,r,null,h));this.open++;return i}closeExtra(t=false){let e=this.nodes.length-1;if(e>this.open){for(;e>this.open;e--)this.nodes[e-1].content.push(this.nodes[e].finish(t));this.nodes.length=this.open+1}}finish(){this.open=0;this.closeExtra(this.isOpen);return this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(t){for(let e=this.open;e>=0;e--){if(this.nodes[e]==t){this.open=e;return true}else if(this.localPreserveWS){this.nodes[e].options|=pt}}return false}get currentPos(){this.closeExtra();let t=0;for(let e=this.open;e>=0;e--){let i=this.nodes[e].content;for(let e=i.length-1;e>=0;e--)t+=i[e].nodeSize;if(e)t++}return t}findAtPoint(t,e){if(this.find)for(let i=0;i<this.find.length;i++){if(this.find[i].node==t&&this.find[i].offset==e)this.find[i].pos=this.currentPos}}findInside(t){if(this.find)for(let e=0;e<this.find.length;e++){if(this.find[e].pos==null&&t.nodeType==1&&t.contains(this.find[e].node))this.find[e].pos=this.currentPos}}findAround(t,e,i){if(t!=e&&this.find)for(let r=0;r<this.find.length;r++){if(this.find[r].pos==null&&t.nodeType==1&&t.contains(this.find[r].node)){let t=e.compareDocumentPosition(this.find[r].node);if(t&(i?2:4))this.find[r].pos=this.currentPos}}}findInText(t){if(this.find)for(let e=0;e<this.find.length;e++){if(this.find[e].node==t)this.find[e].pos=this.currentPos-(t.nodeValue.length-this.find[e].offset)}}matchesContext(t){if(t.indexOf("|")>-1)return t.split(/\s*\|\s*/).some(this.matchesContext,this);let e=t.split("/");let i=this.options.context;let r=!this.isOpen&&(!i||i.parent.type==this.nodes[0].type);let s=-(i?i.depth+1:0)+(r?0:1);let n=(t,h)=>{for(;t>=0;t--){let l=e[t];if(l==""){if(t==e.length-1||t==0)continue;for(;h>=s;h--)if(n(t-1,h))return true;return false}else{let t=h>0||h==0&&r?this.nodes[h].type:i&&h>=s?i.node(h-s).type:null;if(!t||t.name!=l&&!t.isInGroup(l))return false;h--}}return true};return n(e.length-1,this.open)}textblockFromContext(){let t=this.options.context;if(t)for(let e=t.depth;e>=0;e--){let i=t.node(e).contentMatchAt(t.indexAfter(e)).defaultType;if(i&&i.isTextblock&&i.defaultAttrs)return i}for(let t in this.parser.schema.nodes){let e=this.parser.schema.nodes[t];if(e.isTextblock&&e.defaultAttrs)return e}}}function yt(t){for(let e=t.firstChild,i=null;e;e=e.nextSibling){let t=e.nodeType==1?e.nodeName.toLowerCase():null;if(t&&dt.hasOwnProperty(t)&&i){i.appendChild(e);e=i}else if(t=="li"){i=e}else if(t){i=null}}}function Mt(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function At(t){let e={};for(let i in t)e[i]=t[i];return e}function kt(t,e){let i=e.schema.nodes;for(let r in i){let s=i[r];if(!s.allowsMarkType(t))continue;let n=[],h=t=>{n.push(t);for(let i=0;i<t.edgeCount;i++){let{type:r,next:s}=t.edge(i);if(r==e)return true;if(n.indexOf(s)<0&&h(s))return true}};if(h(s.contentMatch))return true}}class St{constructor(t,e){this.nodes=t;this.marks=e}serializeFragment(t,e={},i){if(!i)i=Et(e).createDocumentFragment();let r=i,s=[];t.forEach((t=>{if(s.length||t.marks.length){let i=0,n=0;while(i<s.length&&n<t.marks.length){let e=t.marks[n];if(!this.marks[e.type.name]){n++;continue}if(!e.eq(s[i][0])||e.type.spec.spanning===false)break;i++;n++}while(i<s.length)r=s.pop()[1];while(n<t.marks.length){let i=t.marks[n++];let h=this.serializeMark(i,t.isInline,e);if(h){s.push([i,r]);r.appendChild(h.dom);r=h.contentDOM||h.dom}}}r.appendChild(this.serializeNodeInner(t,e))}));return i}serializeNodeInner(t,e){let{dom:i,contentDOM:r}=Rt(Et(e),this.nodes[t.type.name](t),null,t.attrs);if(r){if(t.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(t.content,e,r)}return i}serializeNode(t,e={}){let i=this.serializeNodeInner(t,e);for(let r=t.marks.length-1;r>=0;r--){let s=this.serializeMark(t.marks[r],t.isInline,e);if(s){(s.contentDOM||s.dom).appendChild(i);i=s.dom}}return i}serializeMark(t,e,i={}){let r=this.marks[t.type.name];return r&&Rt(Et(i),r(t,e),null,t.attrs)}static renderSpec(t,e,i=null,r){return Rt(t,e,i,r)}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new St(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(t){let e=xt(t.nodes);if(!e.text)e.text=t=>t.text;return e}static marksFromSchema(t){return xt(t.marks)}}function xt(t){let e={};for(let i in t){let r=t[i].spec.toDOM;if(r)e[i]=r}return e}function Et(t){return t.document||window.document}const Ot=new WeakMap;function Dt(t){let e=Ot.get(t);if(e===undefined)Ot.set(t,e=Tt(t));return e}function Tt(t){let e=null;function i(t){if(t&&typeof t=="object"){if(Array.isArray(t)){if(typeof t[0]=="string"){if(!e)e=[];e.push(t)}else{for(let e=0;e<t.length;e++)i(t[e])}}else{for(let e in t)i(t[e])}}}i(t);return e}function Rt(t,e,i,r){if(typeof e=="string")return{dom:t.createTextNode(e)};if(e.nodeType!=null)return{dom:e};if(e.dom&&e.dom.nodeType!=null)return e;let s=e[0],n;if(typeof s!="string")throw new RangeError("Invalid array passed to renderSpec");if(r&&(n=Dt(r))&&n.indexOf(e)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let h=s.indexOf(" ");if(h>0){i=s.slice(0,h);s=s.slice(h+1)}let l;let o=i?t.createElementNS(i,s):t.createElement(s);let f=e[1],u=1;if(f&&typeof f=="object"&&f.nodeType==null&&!Array.isArray(f)){u=2;for(let t in f)if(f[t]!=null){let e=t.indexOf(" ");if(e>0)o.setAttributeNS(t.slice(0,e),t.slice(e+1),f[t]);else if(t=="style"&&o.style)o.style.cssText=f[t];else o.setAttribute(t,f[t])}}for(let s=u;s<e.length;s++){let n=e[s];if(n===0){if(s<e.length-1||s>u)throw new RangeError("Content hole must be the only child of its parent node");return{dom:o,contentDOM:o}}else{let{dom:e,contentDOM:s}=Rt(t,n,i,r);o.appendChild(e);if(s){if(l)throw new RangeError("Multiple content holes");l=s}}}return{dom:o,contentDOM:l}}const Ct=65535;const Pt=Math.pow(2,16);function It(t,e){return t+e*Pt}function Nt(t){return t&Ct}function Ft(t){return(t-(t&Ct))/Pt}const Bt=1,Ut=2,jt=4,$t=8;class _t{constructor(t,e,i){this.pos=t;this.delInfo=e;this.recover=i}get deleted(){return(this.delInfo&$t)>0}get deletedBefore(){return(this.delInfo&(Bt|jt))>0}get deletedAfter(){return(this.delInfo&(Ut|jt))>0}get deletedAcross(){return(this.delInfo&jt)>0}}class zt{constructor(t,e=false){this.ranges=t;this.inverted=e;if(!t.length&&zt.empty)return zt.empty}recover(t){let e=0,i=Nt(t);if(!this.inverted)for(let t=0;t<i;t++)e+=this.ranges[t*3+2]-this.ranges[t*3+1];return this.ranges[i*3]+e+Ft(t)}mapResult(t,e=1){return this._map(t,e,false)}map(t,e=1){return this._map(t,e,true)}_map(t,e,i){let r=0,s=this.inverted?2:1,n=this.inverted?1:2;for(let h=0;h<this.ranges.length;h+=3){let l=this.ranges[h]-(this.inverted?r:0);if(l>t)break;let o=this.ranges[h+s],f=this.ranges[h+n],u=l+o;if(t<=u){let s=!o?e:t==l?-1:t==u?1:e;let n=l+r+(s<0?0:f);if(i)return n;let a=t==(e<0?l:u)?null:It(h/3,t-l);let c=t==l?Ut:t==u?Bt:jt;if(e<0?t!=l:t!=u)c|=$t;return new _t(n,c,a)}r+=f-o}return i?t+r:new _t(t+r,0,null)}touches(t,e){let i=0,r=Nt(e);let s=this.inverted?2:1,n=this.inverted?1:2;for(let e=0;e<this.ranges.length;e+=3){let h=this.ranges[e]-(this.inverted?i:0);if(h>t)break;let l=this.ranges[e+s],o=h+l;if(t<=o&&e==r*3)return true;i+=this.ranges[e+n]-l}return false}forEach(t){let e=this.inverted?2:1,i=this.inverted?1:2;for(let r=0,s=0;r<this.ranges.length;r+=3){let n=this.ranges[r],h=n-(this.inverted?s:0),l=n+(this.inverted?0:s);let o=this.ranges[r+e],f=this.ranges[r+i];t(h,h+o,l,l+f);s+=f-o}}invert(){return new zt(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(t){return t==0?zt.empty:new zt(t<0?[0,-t,0]:[0,0,t])}}zt.empty=new zt([]);class Jt{constructor(t,e,i=0,r=(t?t.length:0)){this.mirror=e;this.from=i;this.to=r;this._maps=t||[];this.ownData=!(t||e)}get maps(){return this._maps}slice(t=0,e=this.maps.length){return new Jt(this._maps,this.mirror,t,e)}appendMap(t,e){if(!this.ownData){this._maps=this._maps.slice();this.mirror=this.mirror&&this.mirror.slice();this.ownData=true}this.to=this._maps.push(t);if(e!=null)this.setMirror(this._maps.length-1,e)}appendMapping(t){for(let e=0,i=this._maps.length;e<t._maps.length;e++){let r=t.getMirror(e);this.appendMap(t._maps[e],r!=null&&r<e?i+r:undefined)}}getMirror(t){if(this.mirror)for(let e=0;e<this.mirror.length;e++)if(this.mirror[e]==t)return this.mirror[e+(e%2?-1:1)]}setMirror(t,e){if(!this.mirror)this.mirror=[];this.mirror.push(t,e)}appendMappingInverted(t){for(let e=t.maps.length-1,i=this._maps.length+t._maps.length;e>=0;e--){let r=t.getMirror(e);this.appendMap(t._maps[e].invert(),r!=null&&r>e?i-r-1:undefined)}}invert(){let t=new Jt;t.appendMappingInverted(this);return t}map(t,e=1){if(this.mirror)return this._map(t,e,true);for(let i=this.from;i<this.to;i++)t=this._maps[i].map(t,e);return t}mapResult(t,e=1){return this._map(t,e,false)}_map(t,e,i){let r=0;for(let i=this.from;i<this.to;i++){let s=this._maps[i],n=s.mapResult(t,e);if(n.recover!=null){let e=this.getMirror(i);if(e!=null&&e>i&&e<this.to){i=e;t=this._maps[e].recover(n.recover);continue}}r|=n.delInfo;t=n.pos}return i?t:new _t(t,r,null)}}const Wt=Object.create(null);class Qt{getMap(){return zt.empty}merge(t){return null}static fromJSON(t,e){if(!e||!e.stepType)throw new RangeError("Invalid input for Step.fromJSON");let i=Wt[e.stepType];if(!i)throw new RangeError(`No step type ${e.stepType} defined`);return i.fromJSON(t,e)}static jsonID(t,e){if(t in Wt)throw new RangeError("Duplicate use of step JSON ID "+t);Wt[t]=e;e.prototype.jsonID=t;return e}}class Lt{constructor(t,e){this.doc=t;this.failed=e}static ok(t){return new Lt(t,null)}static fail(t){return new Lt(null,t)}static fromReplace(t,e,i,r){try{return Lt.ok(t.replace(e,i,r))}catch(t){if(t instanceof w)return Lt.fail(t.message);throw t}}}function Kt(t,e,i){let r=[];for(let s=0;s<t.childCount;s++){let n=t.child(s);if(n.content.size)n=n.copy(Kt(n.content,e,n));if(n.isInline)n=e(n,i,s);r.push(n)}return u.fromArray(r)}class Ht extends Qt{constructor(t,e,i){super();this.from=t;this.to=e;this.mark=i}apply(t){let e=t.slice(this.from,this.to),i=t.resolve(this.from);let r=i.node(i.sharedDepth(this.to));let s=new m(Kt(e.content,((t,e)=>{if(!t.isAtom||!e.type.allowsMarkType(this.mark.type))return t;return t.mark(this.mark.addToSet(t.marks))}),r),e.openStart,e.openEnd);return Lt.fromReplace(t,this.from,this.to,s)}invert(){return new qt(this.from,this.to,this.mark)}map(t){let e=t.mapResult(this.from,1),i=t.mapResult(this.to,-1);if(e.deleted&&i.deleted||e.pos>=i.pos)return null;return new Ht(e.pos,i.pos,this.mark)}merge(t){if(t instanceof Ht&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from)return new Ht(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark);return null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,e){if(typeof e.from!="number"||typeof e.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Ht(e.from,e.to,t.markFromJSON(e.mark))}}Qt.jsonID("addMark",Ht);class qt extends Qt{constructor(t,e,i){super();this.from=t;this.to=e;this.mark=i}apply(t){let e=t.slice(this.from,this.to);let i=new m(Kt(e.content,(t=>t.mark(this.mark.removeFromSet(t.marks))),t),e.openStart,e.openEnd);return Lt.fromReplace(t,this.from,this.to,i)}invert(){return new Ht(this.from,this.to,this.mark)}map(t){let e=t.mapResult(this.from,1),i=t.mapResult(this.to,-1);if(e.deleted&&i.deleted||e.pos>=i.pos)return null;return new qt(e.pos,i.pos,this.mark)}merge(t){if(t instanceof qt&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from)return new qt(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark);return null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,e){if(typeof e.from!="number"||typeof e.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new qt(e.from,e.to,t.markFromJSON(e.mark))}}Qt.jsonID("removeMark",qt);class Gt extends Qt{constructor(t,e){super();this.pos=t;this.mark=e}apply(t){let e=t.nodeAt(this.pos);if(!e)return Lt.fail("No node at mark step's position");let i=e.type.create(e.attrs,null,this.mark.addToSet(e.marks));return Lt.fromReplace(t,this.pos,this.pos+1,new m(u.from(i),0,e.isLeaf?0:1))}invert(t){let e=t.nodeAt(this.pos);if(e){let t=this.mark.addToSet(e.marks);if(t.length==e.marks.length){for(let i=0;i<e.marks.length;i++)if(!e.marks[i].isInSet(t))return new Gt(this.pos,e.marks[i]);return new Gt(this.pos,this.mark)}}return new Xt(this.pos,this.mark)}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new Gt(e.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,e){if(typeof e.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Gt(e.pos,t.markFromJSON(e.mark))}}Qt.jsonID("addNodeMark",Gt);class Xt extends Qt{constructor(t,e){super();this.pos=t;this.mark=e}apply(t){let e=t.nodeAt(this.pos);if(!e)return Lt.fail("No node at mark step's position");let i=e.type.create(e.attrs,null,this.mark.removeFromSet(e.marks));return Lt.fromReplace(t,this.pos,this.pos+1,new m(u.from(i),0,e.isLeaf?0:1))}invert(t){let e=t.nodeAt(this.pos);if(!e||!this.mark.isInSet(e.marks))return this;return new Gt(this.pos,this.mark)}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new Xt(e.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,e){if(typeof e.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new Xt(e.pos,t.markFromJSON(e.mark))}}Qt.jsonID("removeNodeMark",Xt);class Yt extends Qt{constructor(t,e,i,r=false){super();this.from=t;this.to=e;this.slice=i;this.structure=r}apply(t){if(this.structure&&Zt(t,this.from,this.to))return Lt.fail("Structure replace would overwrite content");return Lt.fromReplace(t,this.from,this.to,this.slice)}getMap(){return new zt([this.from,this.to-this.from,this.slice.size])}invert(t){return new Yt(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let e=t.mapResult(this.from,1),i=t.mapResult(this.to,-1);if(e.deletedAcross&&i.deletedAcross)return null;return new Yt(e.pos,Math.max(e.pos,i.pos),this.slice,this.structure)}merge(t){if(!(t instanceof Yt)||t.structure||this.structure)return null;if(this.from+this.slice.size==t.from&&!this.slice.openEnd&&!t.slice.openStart){let e=this.slice.size+t.slice.size==0?m.empty:new m(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new Yt(this.from,this.to+(t.to-t.from),e,this.structure)}else if(t.to==this.from&&!this.slice.openStart&&!t.slice.openEnd){let e=this.slice.size+t.slice.size==0?m.empty:new m(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new Yt(t.from,this.to,e,this.structure)}else{return null}}toJSON(){let t={stepType:"replace",from:this.from,to:this.to};if(this.slice.size)t.slice=this.slice.toJSON();if(this.structure)t.structure=true;return t}static fromJSON(t,e){if(typeof e.from!="number"||typeof e.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new Yt(e.from,e.to,m.fromJSON(t,e.slice),!!e.structure)}}Qt.jsonID("replace",Yt);class Vt extends Qt{constructor(t,e,i,r,s,n,h=false){super();this.from=t;this.to=e;this.gapFrom=i;this.gapTo=r;this.slice=s;this.insert=n;this.structure=h}apply(t){if(this.structure&&(Zt(t,this.from,this.gapFrom)||Zt(t,this.gapTo,this.to)))return Lt.fail("Structure gap-replace would overwrite content");let e=t.slice(this.gapFrom,this.gapTo);if(e.openStart||e.openEnd)return Lt.fail("Gap is not a flat range");let i=this.slice.insertAt(this.insert,e.content);if(!i)return Lt.fail("Content does not fit in gap");return Lt.fromReplace(t,this.from,this.to,i)}getMap(){return new zt([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let e=this.gapTo-this.gapFrom;return new Vt(this.from,this.from+this.slice.size+e,this.from+this.insert,this.from+this.insert+e,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let e=t.mapResult(this.from,1),i=t.mapResult(this.to,-1);let r=this.from==this.gapFrom?e.pos:t.map(this.gapFrom,-1);let s=this.to==this.gapTo?i.pos:t.map(this.gapTo,1);if(e.deletedAcross&&i.deletedAcross||r<e.pos||s>i.pos)return null;return new Vt(e.pos,i.pos,r,s,this.slice,this.insert,this.structure)}toJSON(){let t={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};if(this.slice.size)t.slice=this.slice.toJSON();if(this.structure)t.structure=true;return t}static fromJSON(t,e){if(typeof e.from!="number"||typeof e.to!="number"||typeof e.gapFrom!="number"||typeof e.gapTo!="number"||typeof e.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Vt(e.from,e.to,e.gapFrom,e.gapTo,m.fromJSON(t,e.slice),e.insert,!!e.structure)}}Qt.jsonID("replaceAround",Vt);function Zt(t,e,i){let r=t.resolve(e),s=i-e,n=r.depth;while(s>0&&n>0&&r.indexAfter(n)==r.node(n).childCount){n--;s--}if(s>0){let t=r.node(n).maybeChild(r.indexAfter(n));while(s>0){if(!t||t.isLeaf)return true;t=t.firstChild;s--}}return false}function te(t,e,i,r){let s=[],n=[];let h,l;t.doc.nodesBetween(e,i,((t,o,f)=>{if(!t.isInline)return;let u=t.marks;if(!r.isInSet(u)&&f.type.allowsMarkType(r.type)){let f=Math.max(o,e),a=Math.min(o+t.nodeSize,i);let c=r.addToSet(u);for(let t=0;t<u.length;t++){if(!u[t].isInSet(c)){if(h&&h.to==f&&h.mark.eq(u[t]))h.to=a;else s.push(h=new qt(f,a,u[t]))}}if(l&&l.to==f)l.to=a;else n.push(l=new Ht(f,a,r))}}));s.forEach((e=>t.step(e)));n.forEach((e=>t.step(e)))}function ee(t,e,i,r){let s=[],n=0;t.doc.nodesBetween(e,i,((t,h)=>{if(!t.isInline)return;n++;let l=null;if(r instanceof nt){let e=t.marks,i;while(i=r.isInSet(e)){(l||(l=[])).push(i);e=i.removeFromSet(e)}}else if(r){if(r.isInSet(t.marks))l=[r]}else{l=t.marks}if(l&&l.length){let r=Math.min(h+t.nodeSize,i);for(let t=0;t<l.length;t++){let i=l[t],o;for(let t=0;t<s.length;t++){let e=s[t];if(e.step==n-1&&i.eq(s[t].style))o=e}if(o){o.to=r;o.step=n}else{s.push({style:i,from:Math.max(h,e),to:r,step:n})}}}}));s.forEach((e=>t.step(new qt(e.from,e.to,e.style))))}function ie(t,e,i,r=i.contentMatch,s=true){let n=t.doc.nodeAt(e);let h=[],l=e+1;for(let e=0;e<n.childCount;e++){let o=n.child(e),f=l+o.nodeSize;let a=r.matchType(o.type);if(!a){h.push(new Yt(l,f,m.empty))}else{r=a;for(let e=0;e<o.marks.length;e++)if(!i.allowsMarkType(o.marks[e].type))t.step(new qt(l,f,o.marks[e]));if(s&&o.isText&&i.whitespace!="pre"){let t,e=/\r?\n|\r/g,r;while(t=e.exec(o.text)){if(!r)r=new m(u.from(i.schema.text(" ",i.allowedMarks(o.marks))),0,0);h.push(new Yt(l+t.index,l+t.index+t[0].length,r))}}}l=f}if(!r.validEnd){let e=r.fillBefore(u.empty,true);t.replace(l,l,new m(e,0,0))}for(let e=h.length-1;e>=0;e--)t.step(h[e])}function re(t,e,i){return(e==0||t.canReplace(e,t.childCount))&&(i==t.childCount||t.canReplace(0,i))}function se(t){let e=t.parent;let i=e.content.cutByIndex(t.startIndex,t.endIndex);for(let e=t.depth;;--e){let r=t.$from.node(e);let s=t.$from.index(e),n=t.$to.indexAfter(e);if(e<t.depth&&r.canReplace(s,n,i))return e;if(e==0||r.type.spec.isolating||!re(r,s,n))break}return null}function ne(t,e,i){let{$from:r,$to:s,depth:n}=e;let h=r.before(n+1),l=s.after(n+1);let o=h,f=l;let a=u.empty,c=0;for(let t=n,e=false;t>i;t--)if(e||r.index(t)>0){e=true;a=u.from(r.node(t).copy(a));c++}else{o--}let d=u.empty,p=0;for(let t=n,e=false;t>i;t--)if(e||s.after(t+1)<s.end(t)){e=true;d=u.from(s.node(t).copy(d));p++}else{f++}t.step(new Vt(o,f,h,l,new m(a.append(d),c,p),a.size-c,true))}function he(t,e,i){let r=u.empty;for(let t=i.length-1;t>=0;t--){if(r.size){let e=i[t].type.contentMatch.matchFragment(r);if(!e||!e.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=u.from(i[t].type.create(i[t].attrs,r))}let s=e.start,n=e.end;t.step(new Vt(s,n,s,n,new m(r,0,0),i.length,true))}function le(t,e,i,r,s){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let n=t.steps.length;t.doc.nodesBetween(e,i,((e,i)=>{let h=typeof s=="function"?s(e):s;if(e.isTextblock&&!e.hasMarkup(r,h)&&ue(t.doc,t.mapping.slice(n).map(i),r)){let s=null;if(r.schema.linebreakReplacement){let t=r.whitespace=="pre",e=!!r.contentMatch.matchType(r.schema.linebreakReplacement);if(t&&!e)s=false;else if(!t&&e)s=true}if(s===false)fe(t,e,i,n);ie(t,t.mapping.slice(n).map(i,1),r,undefined,s===null);let l=t.mapping.slice(n);let o=l.map(i,1),f=l.map(i+e.nodeSize,1);t.step(new Vt(o,f,o+1,f-1,new m(u.from(r.create(h,null,e.marks)),0,0),1,true));if(s===true)oe(t,e,i,n);return false}}))}function oe(t,e,i,r){e.forEach(((s,n)=>{if(s.isText){let h,l=/\r?\n|\r/g;while(h=l.exec(s.text)){let s=t.mapping.slice(r).map(i+1+n+h.index);t.replaceWith(s,s+1,e.type.schema.linebreakReplacement.create())}}}))}function fe(t,e,i,r){e.forEach(((s,n)=>{if(s.type==s.type.schema.linebreakReplacement){let s=t.mapping.slice(r).map(i+1+n);t.replaceWith(s,s+1,e.type.schema.text("\n"))}}))}function ue(t,e,i){let r=t.resolve(e),s=r.index();return r.parent.canReplaceWith(s,s+1,i)}function ae(t,e,i,r,s){let n=t.doc.nodeAt(e);if(!n)throw new RangeError("No node at given position");if(!i)i=n.type;let h=i.create(r,null,s||n.marks);if(n.isLeaf)return t.replaceWith(e,e+n.nodeSize,h);if(!i.validContent(n.content))throw new RangeError("Invalid content for node type "+i.name);t.step(new Vt(e,e+n.nodeSize,e+1,e+n.nodeSize-1,new m(u.from(h),0,0),1,true))}function ce(t,e,i=1,r){let s=t.resolve(e),n=s.depth-i;let h=r&&r[r.length-1]||s.parent;if(n<0||s.parent.type.spec.isolating||!s.parent.canReplace(s.index(),s.parent.childCount)||!h.type.validContent(s.parent.content.cutByIndex(s.index(),s.parent.childCount)))return false;for(let t=s.depth-1,e=i-2;t>n;t--,e--){let i=s.node(t),n=s.index(t);if(i.type.spec.isolating)return false;let h=i.content.cutByIndex(n,i.childCount);let l=r&&r[e+1];if(l)h=h.replaceChild(0,l.type.create(l.attrs));let o=r&&r[e]||i;if(!i.canReplace(n+1,i.childCount)||!o.type.validContent(h))return false}let l=s.indexAfter(n);let o=r&&r[0];return s.node(n).canReplaceWith(l,l,o?o.type:s.node(n+1).type)}function de(t,e,i=1,r){let s=t.doc.resolve(e),n=u.empty,h=u.empty;for(let t=s.depth,e=s.depth-i,l=i-1;t>e;t--,l--){n=u.from(s.node(t).copy(n));let e=r&&r[l];h=u.from(e?e.type.create(e.attrs,h):s.node(t).copy(h))}t.step(new Yt(e,e,new m(n.append(h),i,i),true))}function pe(t,e){let i=t.resolve(e),r=i.index();return me(i.nodeBefore,i.nodeAfter)&&i.parent.canReplace(r,r+1)}function we(t,e){if(!e.content.size)t.type.compatibleContent(e.type);let i=t.contentMatchAt(t.childCount);let{linebreakReplacement:r}=t.type.schema;for(let s=0;s<e.childCount;s++){let n=e.child(s);let h=n.type==r?t.type.schema.nodes.text:n.type;i=i.matchType(h);if(!i)return false;if(!t.type.allowsMarks(n.marks))return false}return i.validEnd}function me(t,e){return!!(t&&e&&!t.isLeaf&&we(t,e))}function ge(t,e,i){let r=null;let{linebreakReplacement:s}=t.doc.type.schema;let n=t.doc.resolve(e-i),h=n.node().type;if(s&&h.inlineContent){let t=h.whitespace=="pre";let e=!!h.contentMatch.matchType(s);if(t&&!e)r=false;else if(!t&&e)r=true}let l=t.steps.length;if(r===false){let r=t.doc.resolve(e+i);fe(t,r.node(),r.before(),l)}if(h.inlineContent)ie(t,e+i-1,h,n.node().contentMatchAt(n.index()),r==null);let o=t.mapping.slice(l),f=o.map(e-i);t.step(new Yt(f,o.map(e+i,-1),m.empty,true));if(r===true){let e=t.doc.resolve(f);oe(t,e.node(),e.before(),t.steps.length)}return t}function be(t,e,i){let r=t.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),i))return e;if(r.parentOffset==0)for(let t=r.depth-1;t>=0;t--){let e=r.index(t);if(r.node(t).canReplaceWith(e,e,i))return r.before(t+1);if(e>0)return null}if(r.parentOffset==r.parent.content.size)for(let t=r.depth-1;t>=0;t--){let e=r.indexAfter(t);if(r.node(t).canReplaceWith(e,e,i))return r.after(t+1);if(e<r.node(t).childCount)return null}return null}function ve(t,e,i){let r=t.resolve(e);if(!i.content.size)return e;let s=i.content;for(let t=0;t<i.openStart;t++)s=s.firstChild.content;for(let t=1;t<=(i.openStart==0&&i.size?2:1);t++){for(let e=r.depth;e>=0;e--){let i=e==r.depth?0:r.pos<=(r.start(e+1)+r.end(e+1))/2?-1:1;let n=r.index(e)+(i>0?1:0);let h=r.node(e),l=false;if(t==1){l=h.canReplace(n,n,s)}else{let t=h.contentMatchAt(n).findWrapping(s.firstChild.type);l=t&&h.canReplaceWith(n,n,t[0])}if(l)return i==0?r.pos:i<0?r.before(e+1):r.after(e+1)}}return null}function ye(t,e,i=e,r=m.empty){if(e==i&&!r.size)return null;let s=t.resolve(e),n=t.resolve(i);if(Me(s,n,r))return new Yt(e,i,r);return new Ae(s,n,r).fit()}function Me(t,e,i){return!i.openStart&&!i.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),i.content)}class Ae{constructor(t,e,i){this.$from=t;this.$to=e;this.unplaced=i;this.frontier=[];this.placed=u.empty;for(let e=0;e<=t.depth;e++){let i=t.node(e);this.frontier.push({type:i.type,match:i.contentMatchAt(t.indexAfter(e))})}for(let e=t.depth;e>0;e--)this.placed=u.from(t.node(e).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){while(this.unplaced.size){let t=this.findFittable();if(t)this.placeNodes(t);else this.openMore()||this.dropNode()}let t=this.mustMoveInline(),e=this.placed.size-this.depth-this.$from.depth;let i=this.$from,r=this.close(t<0?this.$to:i.doc.resolve(t));if(!r)return null;let s=this.placed,n=i.depth,h=r.depth;while(n&&h&&s.childCount==1){s=s.firstChild.content;n--;h--}let l=new m(s,n,h);if(t>-1)return new Vt(i.pos,t,this.$to.pos,this.$to.end(),l,e);if(l.size||i.pos!=this.$to.pos)return new Yt(i.pos,r.pos,l);return null}findFittable(){let t=this.unplaced.openStart;for(let e=this.unplaced.content,i=0,r=this.unplaced.openEnd;i<t;i++){let s=e.firstChild;if(e.childCount>1)r=0;if(s.type.spec.isolating&&r<=i){t=i;break}e=s.content}for(let e=1;e<=2;e++){for(let i=e==1?t:this.unplaced.openStart;i>=0;i--){let t,r=null;if(i){r=xe(this.unplaced.content,i-1).firstChild;t=r.content}else{t=this.unplaced.content}let s=t.firstChild;for(let t=this.depth;t>=0;t--){let{type:n,match:h}=this.frontier[t],l,o=null;if(e==1&&(s?h.matchType(s.type)||(o=h.fillBefore(u.from(s),false)):r&&n.compatibleContent(r.type)))return{sliceDepth:i,frontierDepth:t,parent:r,inject:o};else if(e==2&&s&&(l=h.findWrapping(s.type)))return{sliceDepth:i,frontierDepth:t,parent:r,wrap:l};if(r&&h.matchType(r.type))break}}}}openMore(){let{content:t,openStart:e,openEnd:i}=this.unplaced;let r=xe(t,e);if(!r.childCount||r.firstChild.isLeaf)return false;this.unplaced=new m(t,e+1,Math.max(i,r.size+e>=t.size-i?e+1:0));return true}dropNode(){let{content:t,openStart:e,openEnd:i}=this.unplaced;let r=xe(t,e);if(r.childCount<=1&&e>0){let s=t.size-e<=e+r.size;this.unplaced=new m(ke(t,e-1,1),e-1,s?e-1:i)}else{this.unplaced=new m(ke(t,e,1),e,i)}}placeNodes({sliceDepth:t,frontierDepth:e,parent:i,inject:r,wrap:s}){while(this.depth>e)this.closeFrontierNode();if(s)for(let t=0;t<s.length;t++)this.openFrontierNode(s[t]);let n=this.unplaced,h=i?i.content:n.content;let l=n.openStart-t;let o=0,f=[];let{match:a,type:c}=this.frontier[e];if(r){for(let t=0;t<r.childCount;t++)f.push(r.child(t));a=a.matchFragment(r)}let d=h.size+t-(n.content.size-n.openEnd);while(o<h.childCount){let t=h.child(o),e=a.matchType(t.type);if(!e)break;o++;if(o>1||l==0||t.content.size){a=e;f.push(Ee(t.mark(c.allowedMarks(t.marks)),o==1?l:0,o==h.childCount?d:-1))}}let p=o==h.childCount;if(!p)d=-1;this.placed=Se(this.placed,e,u.from(f));this.frontier[e].match=a;if(p&&d<0&&i&&i.type==this.frontier[this.depth].type&&this.frontier.length>1)this.closeFrontierNode();for(let t=0,e=h;t<d;t++){let t=e.lastChild;this.frontier.push({type:t.type,match:t.contentMatchAt(t.childCount)});e=t.content}this.unplaced=!p?new m(ke(n.content,t,o),n.openStart,n.openEnd):t==0?m.empty:new m(ke(n.content,t-1,1),t-1,d<0?n.openEnd:t-1)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let t=this.frontier[this.depth],e;if(!t.type.isTextblock||!Oe(this.$to,this.$to.depth,t.type,t.match,false)||this.$to.depth==this.depth&&(e=this.findCloseLevel(this.$to))&&e.depth==this.depth)return-1;let{depth:i}=this.$to,r=this.$to.after(i);while(i>1&&r==this.$to.end(--i))++r;return r}findCloseLevel(t){t:for(let e=Math.min(this.depth,t.depth);e>=0;e--){let{match:i,type:r}=this.frontier[e];let s=e<t.depth&&t.end(e+1)==t.pos+(t.depth-(e+1));let n=Oe(t,e,r,i,s);if(!n)continue;for(let i=e-1;i>=0;i--){let{match:e,type:r}=this.frontier[i];let s=Oe(t,i,r,e,true);if(!s||s.childCount)continue t}return{depth:e,fit:n,move:s?t.doc.resolve(t.after(e+1)):t}}}close(t){let e=this.findCloseLevel(t);if(!e)return null;while(this.depth>e.depth)this.closeFrontierNode();if(e.fit.childCount)this.placed=Se(this.placed,e.depth,e.fit);t=e.move;for(let i=e.depth+1;i<=t.depth;i++){let e=t.node(i),r=e.type.contentMatch.fillBefore(e.content,true,t.index(i));this.openFrontierNode(e.type,e.attrs,r)}return t}openFrontierNode(t,e=null,i){let r=this.frontier[this.depth];r.match=r.match.matchType(t);this.placed=Se(this.placed,this.depth,u.from(t.create(e,i)));this.frontier.push({type:t,match:t.contentMatch})}closeFrontierNode(){let t=this.frontier.pop();let e=t.match.fillBefore(u.empty,true);if(e.childCount)this.placed=Se(this.placed,this.frontier.length,e)}}function ke(t,e,i){if(e==0)return t.cutByIndex(i,t.childCount);return t.replaceChild(0,t.firstChild.copy(ke(t.firstChild.content,e-1,i)))}function Se(t,e,i){if(e==0)return t.append(i);return t.replaceChild(t.childCount-1,t.lastChild.copy(Se(t.lastChild.content,e-1,i)))}function xe(t,e){for(let i=0;i<e;i++)t=t.firstChild.content;return t}function Ee(t,e,i){if(e<=0)return t;let r=t.content;if(e>1)r=r.replaceChild(0,Ee(r.firstChild,e-1,r.childCount==1?i-1:0));if(e>0){r=t.type.contentMatch.fillBefore(r).append(r);if(i<=0)r=r.append(t.type.contentMatch.matchFragment(r).fillBefore(u.empty,true))}return t.copy(r)}function Oe(t,e,i,r,s){let n=t.node(e),h=s?t.indexAfter(e):t.index(e);if(h==n.childCount&&!i.compatibleContent(n.type))return null;let l=r.fillBefore(n.content,true,h);return l&&!De(i,n.content,h)?l:null}function De(t,e,i){for(let r=i;r<e.childCount;r++)if(!t.allowsMarks(e.child(r).marks))return true;return false}function Te(t){return t.spec.defining||t.spec.definingForContent}function Re(t,e,i,r){if(!r.size)return t.deleteRange(e,i);let s=t.doc.resolve(e),n=t.doc.resolve(i);if(Me(s,n,r))return t.step(new Yt(e,i,r));let h=Ne(s,t.doc.resolve(i));if(h[h.length-1]==0)h.pop();let l=-(s.depth+1);h.unshift(l);for(let t=s.depth,e=s.pos-1;t>0;t--,e--){let i=s.node(t).type.spec;if(i.defining||i.definingAsContext||i.isolating)break;if(h.indexOf(t)>-1)l=t;else if(s.before(t)==e)h.splice(1,0,-t)}let o=h.indexOf(l);let f=[],u=r.openStart;for(let t=r.content,e=0;;e++){let i=t.firstChild;f.push(i);if(e==r.openStart)break;t=i.content}for(let t=u-1;t>=0;t--){let e=f[t],i=Te(e.type);if(i&&!e.sameMarkup(s.node(Math.abs(l)-1)))u=t;else if(i||!e.type.isTextblock)break}for(let e=r.openStart;e>=0;e--){let l=(e+u+1)%(r.openStart+1);let a=f[l];if(!a)continue;for(let e=0;e<h.length;e++){let f=h[(e+o)%h.length],u=true;if(f<0){u=false;f=-f}let c=s.node(f-1),d=s.index(f-1);if(c.canReplaceWith(d,d,a.type,a.marks))return t.replace(s.before(f),u?n.after(f):i,new m(Ce(r.content,0,r.openStart,l),l,r.openEnd))}}let a=t.steps.length;for(let l=h.length-1;l>=0;l--){t.replace(e,i,r);if(t.steps.length>a)break;let o=h[l];if(o<0)continue;e=s.before(o);i=n.after(o)}}function Ce(t,e,i,r,s){if(e<i){let s=t.firstChild;t=t.replaceChild(0,s.copy(Ce(s.content,e+1,i,r,s)))}if(e>r){let e=s.contentMatchAt(0);let i=e.fillBefore(t).append(t);t=i.append(e.matchFragment(i).fillBefore(u.empty,true))}return t}function Pe(t,e,i,r){if(!r.isInline&&e==i&&t.doc.resolve(e).parent.content.size){let s=be(t.doc,e,r.type);if(s!=null)e=i=s}t.replaceRange(e,i,new m(u.from(r),0,0))}function Ie(t,e,i){let r=t.doc.resolve(e),s=t.doc.resolve(i);let n=Ne(r,s);for(let e=0;e<n.length;e++){let i=n[e],h=e==n.length-1;if(h&&i==0||r.node(i).type.contentMatch.validEnd)return t.delete(r.start(i),s.end(i));if(i>0&&(h||r.node(i-1).canReplace(r.index(i-1),s.indexAfter(i-1))))return t.delete(r.before(i),s.after(i))}for(let n=1;n<=r.depth&&n<=s.depth;n++){if(e-r.start(n)==r.depth-n&&i>r.end(n)&&s.end(n)-i!=s.depth-n&&r.start(n-1)==s.start(n-1)&&r.node(n-1).canReplace(r.index(n-1),s.index(n-1)))return t.delete(r.before(n),i)}t.delete(e,i)}function Ne(t,e){let i=[],r=Math.min(t.depth,e.depth);for(let s=r;s>=0;s--){let r=t.start(s);if(r<t.pos-(t.depth-s)||e.end(s)>e.pos+(e.depth-s)||t.node(s).type.spec.isolating||e.node(s).type.spec.isolating)break;if(r==e.start(s)||s==t.depth&&s==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&s&&e.start(s-1)==r-1)i.push(s)}return i}class Fe extends Qt{constructor(t,e,i){super();this.pos=t;this.attr=e;this.value=i}apply(t){let e=t.nodeAt(this.pos);if(!e)return Lt.fail("No node at attribute step's position");let i=Object.create(null);for(let t in e.attrs)i[t]=e.attrs[t];i[this.attr]=this.value;let r=e.type.create(i,null,e.marks);return Lt.fromReplace(t,this.pos,this.pos+1,new m(u.from(r),0,e.isLeaf?0:1))}getMap(){return zt.empty}invert(t){return new Fe(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new Fe(e.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,e){if(typeof e.pos!="number"||typeof e.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Fe(e.pos,e.attr,e.value)}}Qt.jsonID("attr",Fe);class Be extends Qt{constructor(t,e){super();this.attr=t;this.value=e}apply(t){let e=Object.create(null);for(let i in t.attrs)e[i]=t.attrs[i];e[this.attr]=this.value;let i=t.type.create(e,t.content,t.marks);return Lt.ok(i)}getMap(){return zt.empty}invert(t){return new Be(this.attr,t.attrs[this.attr])}map(t){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(t,e){if(typeof e.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new Be(e.attr,e.value)}}Qt.jsonID("docAttr",Be);let Ue=class extends Error{};Ue=function t(e){let i=Error.call(this,e);i.__proto__=t.prototype;return i};Ue.prototype=Object.create(Error.prototype);Ue.prototype.constructor=Ue;Ue.prototype.name="TransformError";class je{constructor(t){this.doc=t;this.steps=[];this.docs=[];this.mapping=new Jt}get before(){return this.docs.length?this.docs[0]:this.doc}step(t){let e=this.maybeStep(t);if(e.failed)throw new Ue(e.failed);return this}maybeStep(t){let e=t.apply(this.doc);if(!e.failed)this.addStep(t,e.doc);return e}get docChanged(){return this.steps.length>0}addStep(t,e){this.docs.push(this.doc);this.steps.push(t);this.mapping.appendMap(t.getMap());this.doc=e}replace(t,e=t,i=m.empty){let r=ye(this.doc,t,e,i);if(r)this.step(r);return this}replaceWith(t,e,i){return this.replace(t,e,new m(u.from(i),0,0))}delete(t,e){return this.replace(t,e,m.empty)}insert(t,e){return this.replaceWith(t,t,e)}replaceRange(t,e,i){Re(this,t,e,i);return this}replaceRangeWith(t,e,i){Pe(this,t,e,i);return this}deleteRange(t,e){Ie(this,t,e);return this}lift(t,e){ne(this,t,e);return this}join(t,e=1){ge(this,t,e);return this}wrap(t,e){he(this,t,e);return this}setBlockType(t,e=t,i,r=null){le(this,t,e,i,r);return this}setNodeMarkup(t,e,i=null,r){ae(this,t,e,i,r);return this}setNodeAttribute(t,e,i){this.step(new Fe(t,e,i));return this}setDocAttribute(t,e){this.step(new Be(t,e));return this}addNodeMark(t,e){this.step(new Gt(t,e));return this}removeNodeMark(t,e){let i=this.doc.nodeAt(t);if(!i)throw new RangeError("No node at position "+t);if(e instanceof p){if(e.isInSet(i.marks))this.step(new Xt(t,e))}else{let r=i.marks,s,n=[];while(s=e.isInSet(r)){n.push(new Xt(t,s));r=s.removeFromSet(r)}for(let t=n.length-1;t>=0;t--)this.step(n[t])}return this}split(t,e=1,i){de(this,t,e,i);return this}addMark(t,e,i){te(this,t,e,i);return this}removeMark(t,e,i){ee(this,t,e,i);return this}clearIncompatible(t,e,i){ie(this,t,e,i);return this}}const $e=Object.create(null);class _e{constructor(t,e,i){this.$anchor=t;this.$head=e;this.ranges=i||[new ze(t.min(e),t.max(e))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let t=this.ranges;for(let e=0;e<t.length;e++)if(t[e].$from.pos!=t[e].$to.pos)return false;return true}content(){return this.$from.doc.slice(this.from,this.to,true)}replace(t,e=m.empty){let i=e.content.lastChild,r=null;for(let t=0;t<e.openEnd;t++){r=i;i=i.lastChild}let s=t.steps.length,n=this.ranges;for(let h=0;h<n.length;h++){let{$from:l,$to:o}=n[h],f=t.mapping.slice(s);t.replaceRange(f.map(l.pos),f.map(o.pos),h?m.empty:e);if(h==0)Ye(t,s,(i?i.isInline:r&&r.isTextblock)?-1:1)}}replaceWith(t,e){let i=t.steps.length,r=this.ranges;for(let s=0;s<r.length;s++){let{$from:n,$to:h}=r[s],l=t.mapping.slice(i);let o=l.map(n.pos),f=l.map(h.pos);if(s){t.deleteRange(o,f)}else{t.replaceRangeWith(o,f,e);Ye(t,i,e.isInline?-1:1)}}}static findFrom(t,e,i=false){let r=t.parent.inlineContent?new Qe(t):Xe(t.node(0),t.parent,t.pos,t.index(),e,i);if(r)return r;for(let r=t.depth-1;r>=0;r--){let s=e<0?Xe(t.node(0),t.node(r),t.before(r+1),t.index(r),e,i):Xe(t.node(0),t.node(r),t.after(r+1),t.index(r)+1,e,i);if(s)return s}return null}static near(t,e=1){return this.findFrom(t,e)||this.findFrom(t,-e)||new qe(t.node(0))}static atStart(t){return Xe(t,t,0,0,1)||new qe(t)}static atEnd(t){return Xe(t,t,t.content.size,t.childCount,-1)||new qe(t)}static fromJSON(t,e){if(!e||!e.type)throw new RangeError("Invalid input for Selection.fromJSON");let i=$e[e.type];if(!i)throw new RangeError(`No selection type ${e.type} defined`);return i.fromJSON(t,e)}static jsonID(t,e){if(t in $e)throw new RangeError("Duplicate use of selection JSON ID "+t);$e[t]=e;e.prototype.jsonID=t;return e}getBookmark(){return Qe.between(this.$anchor,this.$head).getBookmark()}}_e.prototype.visible=true;class ze{constructor(t,e){this.$from=t;this.$to=e}}let Je=false;function We(t){if(!Je&&!t.parent.inlineContent){Je=true;console["warn"]("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")")}}class Qe extends _e{constructor(t,e=t){We(t);We(e);super(t,e)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,e){let i=t.resolve(e.map(this.head));if(!i.parent.inlineContent)return _e.near(i);let r=t.resolve(e.map(this.anchor));return new Qe(r.parent.inlineContent?r:i,i)}replace(t,e=m.empty){super.replace(t,e);if(e==m.empty){let e=this.$from.marksAcross(this.$to);if(e)t.ensureMarks(e)}}eq(t){return t instanceof Qe&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new Le(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(t,e){if(typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new Qe(t.resolve(e.anchor),t.resolve(e.head))}static create(t,e,i=e){let r=t.resolve(e);return new this(r,i==e?r:t.resolve(i))}static between(t,e,i){let r=t.pos-e.pos;if(!i||r)i=r>=0?1:-1;if(!e.parent.inlineContent){let t=_e.findFrom(e,i,true)||_e.findFrom(e,-i,true);if(t)e=t.$head;else return _e.near(e,i)}if(!t.parent.inlineContent){if(r==0){t=e}else{t=(_e.findFrom(t,-i,true)||_e.findFrom(t,i,true)).$anchor;if(t.pos<e.pos!=r<0)t=e}}return new Qe(t,e)}}_e.jsonID("text",Qe);class Le{constructor(t,e){this.anchor=t;this.head=e}map(t){return new Le(t.map(this.anchor),t.map(this.head))}resolve(t){return Qe.between(t.resolve(this.anchor),t.resolve(this.head))}}class Ke extends _e{constructor(t){let e=t.nodeAfter;let i=t.node(0).resolve(t.pos+e.nodeSize);super(t,i);this.node=e}map(t,e){let{deleted:i,pos:r}=e.mapResult(this.anchor);let s=t.resolve(r);if(i)return _e.near(s);return new Ke(s)}content(){return new m(u.from(this.node),0,0)}eq(t){return t instanceof Ke&&t.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new He(this.anchor)}static fromJSON(t,e){if(typeof e.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new Ke(t.resolve(e.anchor))}static create(t,e){return new Ke(t.resolve(e))}static isSelectable(t){return!t.isText&&t.type.spec.selectable!==false}}Ke.prototype.visible=false;_e.jsonID("node",Ke);class He{constructor(t){this.anchor=t}map(t){let{deleted:e,pos:i}=t.mapResult(this.anchor);return e?new Le(i,i):new He(i)}resolve(t){let e=t.resolve(this.anchor),i=e.nodeAfter;if(i&&Ke.isSelectable(i))return new Ke(e);return _e.near(e)}}class qe extends _e{constructor(t){super(t.resolve(0),t.resolve(t.content.size))}replace(t,e=m.empty){if(e==m.empty){t.delete(0,t.doc.content.size);let e=_e.atStart(t.doc);if(!e.eq(t.selection))t.setSelection(e)}else{super.replace(t,e)}}toJSON(){return{type:"all"}}static fromJSON(t){return new qe(t)}map(t){return new qe(t)}eq(t){return t instanceof qe}getBookmark(){return Ge}}_e.jsonID("all",qe);const Ge={map(){return this},resolve(t){return new qe(t)}};function Xe(t,e,i,r,s,n=false){if(e.inlineContent)return Qe.create(t,i);for(let h=r-(s>0?0:1);s>0?h<e.childCount:h>=0;h+=s){let r=e.child(h);if(!r.isAtom){let e=Xe(t,r,i+s,s<0?r.childCount:0,s,n);if(e)return e}else if(!n&&Ke.isSelectable(r)){return Ke.create(t,i-(s<0?r.nodeSize:0))}i+=r.nodeSize*s}return null}function Ye(t,e,i){let r=t.steps.length-1;if(r<e)return;let s=t.steps[r];if(!(s instanceof Yt||s instanceof Vt))return;let n=t.mapping.maps[r],h;n.forEach(((t,e,i,r)=>{if(h==null)h=r}));t.setSelection(_e.near(t.doc.resolve(h),i))}const Ve=1,Ze=2,ti=4;class ei extends je{constructor(t){super(t.doc);this.curSelectionFor=0;this.updated=0;this.meta=Object.create(null);this.time=Date.now();this.curSelection=t.selection;this.storedMarks=t.storedMarks}get selection(){if(this.curSelectionFor<this.steps.length){this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor));this.curSelectionFor=this.steps.length}return this.curSelection}setSelection(t){if(t.$from.doc!=this.doc)throw new RangeError("Selection passed to setSelection must point at the current document");this.curSelection=t;this.curSelectionFor=this.steps.length;this.updated=(this.updated|Ve)&-3;this.storedMarks=null;return this}get selectionSet(){return(this.updated&Ve)>0}setStoredMarks(t){this.storedMarks=t;this.updated|=Ze;return this}ensureMarks(t){if(!p.sameSet(this.storedMarks||this.selection.$from.marks(),t))this.setStoredMarks(t);return this}addStoredMark(t){return this.ensureMarks(t.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(t){return this.ensureMarks(t.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Ze)>0}addStep(t,e){super.addStep(t,e);this.updated=this.updated&-3;this.storedMarks=null}setTime(t){this.time=t;return this}replaceSelection(t){this.selection.replace(this,t);return this}replaceSelectionWith(t,e=true){let i=this.selection;if(e)t=t.mark(this.storedMarks||(i.empty?i.$from.marks():i.$from.marksAcross(i.$to)||p.none));i.replaceWith(this,t);return this}deleteSelection(){this.selection.replace(this);return this}insertText(t,e,i){let r=this.doc.type.schema;if(e==null){if(!t)return this.deleteSelection();return this.replaceSelectionWith(r.text(t),true)}else{if(i==null)i=e;if(!t)return this.deleteRange(e,i);let s=this.storedMarks;if(!s){let t=this.doc.resolve(e);s=i==e?t.marks():t.marksAcross(this.doc.resolve(i))}this.replaceRangeWith(e,i,r.text(t,s));if(!this.selection.empty&&this.selection.to==e+t.length)this.setSelection(_e.near(this.selection.$to));return this}}setMeta(t,e){this.meta[typeof t=="string"?t:t.key]=e;return this}getMeta(t){return this.meta[typeof t=="string"?t:t.key]}get isGeneric(){for(let t in this.meta)return false;return true}scrollIntoView(){this.updated|=ti;return this}get scrolledIntoView(){return(this.updated&ti)>0}}function ii(t,e){return!e||!t?t:t.bind(e)}class ri{constructor(t,e,i){this.name=t;this.init=ii(e.init,i);this.apply=ii(e.apply,i)}}const si=[new ri("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new ri("selection",{init(t,e){return t.selection||_e.atStart(e.doc)},apply(t){return t.selection}}),new ri("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,i,r){return r.selection.$cursor?t.storedMarks:null}}),new ri("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}})];class ni{constructor(t,e){this.schema=t;this.plugins=[];this.pluginsByKey=Object.create(null);this.fields=si.slice();if(e)e.forEach((t=>{if(this.pluginsByKey[t.key])throw new RangeError("Adding different instances of a keyed plugin ("+t.key+")");this.plugins.push(t);this.pluginsByKey[t.key]=t;if(t.spec.state)this.fields.push(new ri(t.key,t.spec.state,t))}))}}class hi{constructor(t){this.config=t}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(t){return this.applyTransaction(t).state}filterTransaction(t,e=-1){for(let i=0;i<this.config.plugins.length;i++)if(i!=e){let e=this.config.plugins[i];if(e.spec.filterTransaction&&!e.spec.filterTransaction.call(e,t,this))return false}return true}applyTransaction(t){if(!this.filterTransaction(t))return{state:this,transactions:[]};let e=[t],i=this.applyInner(t),r=null;for(;;){let s=false;for(let n=0;n<this.config.plugins.length;n++){let h=this.config.plugins[n];if(h.spec.appendTransaction){let l=r?r[n].n:0,o=r?r[n].state:this;let f=l<e.length&&h.spec.appendTransaction.call(h,l?e.slice(l):e,o,i);if(f&&i.filterTransaction(f,n)){f.setMeta("appendedTransaction",t);if(!r){r=[];for(let t=0;t<this.config.plugins.length;t++)r.push(t<n?{state:i,n:e.length}:{state:this,n:0})}e.push(f);i=i.applyInner(f);s=true}if(r)r[n]={state:i,n:e.length}}}if(!s)return{state:i,transactions:e}}}applyInner(t){if(!t.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let e=new hi(this.config),i=this.config.fields;for(let r=0;r<i.length;r++){let s=i[r];e[s.name]=s.apply(t,this[s.name],this,e)}return e}get tr(){return new ei(this)}static create(t){let e=new ni(t.doc?t.doc.type.schema:t.schema,t.plugins);let i=new hi(e);for(let r=0;r<e.fields.length;r++)i[e.fields[r].name]=e.fields[r].init(t,i);return i}reconfigure(t){let e=new ni(this.schema,t.plugins);let i=e.fields,r=new hi(e);for(let e=0;e<i.length;e++){let s=i[e].name;r[s]=this.hasOwnProperty(s)?this[s]:i[e].init(t,r)}return r}toJSON(t){let e={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks)e.storedMarks=this.storedMarks.map((t=>t.toJSON()));if(t&&typeof t=="object")for(let i in t){if(i=="doc"||i=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let r=t[i],s=r.spec.state;if(s&&s.toJSON)e[i]=s.toJSON.call(r,this[r.key])}return e}static fromJSON(t,e,i){if(!e)throw new RangeError("Invalid input for EditorState.fromJSON");if(!t.schema)throw new RangeError("Required config field 'schema' missing");let r=new ni(t.schema,t.plugins);let s=new hi(r);r.fields.forEach((r=>{if(r.name=="doc"){s.doc=F.fromJSON(t.schema,e.doc)}else if(r.name=="selection"){s.selection=_e.fromJSON(s.doc,e.selection)}else if(r.name=="storedMarks"){if(e.storedMarks)s.storedMarks=e.storedMarks.map(t.schema.markFromJSON)}else{if(i)for(let n in i){let h=i[n],l=h.spec.state;if(h.key==r.name&&l&&l.fromJSON&&Object.prototype.hasOwnProperty.call(e,n)){s[r.name]=l.fromJSON.call(h,t,e[n],s);return}}s[r.name]=r.init(t,s)}}));return s}}function li(t,e,i){for(let r in t){let s=t[r];if(s instanceof Function)s=s.bind(e);else if(r=="handleDOMEvents")s=li(s,e,{});i[r]=s}return i}class oi{constructor(t){this.spec=t;this.props={};if(t.props)li(t.props,this,this.props);this.key=t.key?t.key.key:ui("plugin")}getState(t){return t[this.key]}}const fi=Object.create(null);function ui(t){if(t in fi)return t+"$"+ ++fi[t];fi[t]=0;return t+"$"}const ai=function(t){for(var e=0;;e++){t=t.previousSibling;if(!t)return e}};const ci=function(t){let e=t.assignedSlot||t.parentNode;return e&&e.nodeType==11?e.host:e};let di=null;const pi=function(t,e,i){let r=di||(di=document.createRange());r.setEnd(t,i==null?t.nodeValue.length:i);r.setStart(t,e||0);return r};const wi=function(){di=null};const mi=function(t,e,i,r){return i&&(bi(t,e,i,r,-1)||bi(t,e,i,r,1))};const gi=/^(img|br|input|textarea|hr)$/i;function bi(t,e,i,r,s){var n;for(;;){if(t==i&&e==r)return true;if(e==(s<0?0:vi(t))){let i=t.parentNode;if(!i||i.nodeType!=1||ki(t)||gi.test(t.nodeName)||t.contentEditable=="false")return false;e=ai(t)+(s<0?0:1);t=i}else if(t.nodeType==1){let i=t.childNodes[e+(s<0?-1:0)];if(i.nodeType==1&&i.contentEditable=="false"){if((n=i.pmViewDesc)===null||n===void 0?void 0:n.ignoreForSelection)e+=s;else return false}else{t=i;e=s<0?vi(t):0}}else{return false}}}function vi(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function yi(t,e){for(;;){if(t.nodeType==3&&e)return t;if(t.nodeType==1&&e>0){if(t.contentEditable=="false")return null;t=t.childNodes[e-1];e=vi(t)}else if(t.parentNode&&!ki(t)){e=ai(t);t=t.parentNode}else{return null}}}function Mi(t,e){for(;;){if(t.nodeType==3&&e<t.nodeValue.length)return t;if(t.nodeType==1&&e<t.childNodes.length){if(t.contentEditable=="false")return null;t=t.childNodes[e];e=0}else if(t.parentNode&&!ki(t)){e=ai(t)+1;t=t.parentNode}else{return null}}}function Ai(t,e,i){for(let r=e==0,s=e==vi(t);r||s;){if(t==i)return true;let e=ai(t);t=t.parentNode;if(!t)return false;r=r&&e==0;s=s&&e==vi(t)}}function ki(t){let e;for(let i=t;i;i=i.parentNode)if(e=i.pmViewDesc)break;return e&&e.node&&e.node.isBlock&&(e.dom==t||e.contentDOM==t)}const Si=function(t){return t.focusNode&&mi(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)};function xi(t,e){let i=document.createEvent("Event");i.initEvent("keydown",true,true);i.keyCode=t;i.key=i.code=e;return i}function Ei(t){let e=t.activeElement;while(e&&e.shadowRoot)e=e.shadowRoot.activeElement;return e}function Oi(t,e,i){if(t.caretPositionFromPoint){try{let r=t.caretPositionFromPoint(e,i);if(r)return{node:r.offsetNode,offset:Math.min(vi(r.offsetNode),r.offset)}}catch(t){}}if(t.caretRangeFromPoint){let r=t.caretRangeFromPoint(e,i);if(r)return{node:r.startContainer,offset:Math.min(vi(r.startContainer),r.startOffset)}}}const Di=typeof navigator!="undefined"?navigator:null;const Ti=typeof document!="undefined"?document:null;const Ri=Di&&Di.userAgent||"";const Ci=/Edge\/(\d+)/.exec(Ri);const Pi=/MSIE \d/.exec(Ri);const Ii=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Ri);const Ni=!!(Pi||Ii||Ci);const Fi=Pi?document.documentMode:Ii?+Ii[1]:Ci?+Ci[1]:0;const Bi=!Ni&&/gecko\/(\d+)/i.test(Ri);const Ui=!Ni&&/Chrome\/(\d+)/.exec(Ri);const ji=!!Ui;const $i=Ui?+Ui[1]:0;const _i=!Ni&&!!Di&&/Apple Computer/.test(Di.vendor);const zi=_i&&(/Mobile\/\w+/.test(Ri)||!!Di&&Di.maxTouchPoints>2);const Ji=zi||(Di?/Mac/.test(Di.platform):false);const Wi=Di?/Win/.test(Di.platform):false;const Qi=/Android \d/.test(Ri);const Li=!!Ti&&"webkitFontSmoothing"in Ti.documentElement.style;const Ki=Li?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Hi(t){let e=t.defaultView&&t.defaultView.visualViewport;if(e)return{left:0,right:e.width,top:0,bottom:e.height};return{left:0,right:t.documentElement.clientWidth,top:0,bottom:t.documentElement.clientHeight}}function qi(t,e){return typeof t=="number"?t:t[e]}function Gi(t){let e=t.getBoundingClientRect();let i=e.width/t.offsetWidth||1;let r=e.height/t.offsetHeight||1;return{left:e.left,right:e.left+t.clientWidth*i,top:e.top,bottom:e.top+t.clientHeight*r}}function Xi(t,e,i){let r=t.someProp("scrollThreshold")||0,s=t.someProp("scrollMargin")||5;let n=t.dom.ownerDocument;for(let h=i||t.dom;;){if(!h)break;if(h.nodeType!=1){h=ci(h);continue}let t=h;let i=t==n.body;let l=i?Hi(n):Gi(t);let o=0,f=0;if(e.top<l.top+qi(r,"top"))f=-(l.top-e.top+qi(s,"top"));else if(e.bottom>l.bottom-qi(r,"bottom"))f=e.bottom-e.top>l.bottom-l.top?e.top+qi(s,"top")-l.top:e.bottom-l.bottom+qi(s,"bottom");if(e.left<l.left+qi(r,"left"))o=-(l.left-e.left+qi(s,"left"));else if(e.right>l.right-qi(r,"right"))o=e.right-l.right+qi(s,"right");if(o||f){if(i){n.defaultView.scrollBy(o,f)}else{let i=t.scrollLeft,r=t.scrollTop;if(f)t.scrollTop+=f;if(o)t.scrollLeft+=o;let s=t.scrollLeft-i,n=t.scrollTop-r;e={left:e.left-s,top:e.top-n,right:e.right-s,bottom:e.bottom-n}}}let u=i?"fixed":getComputedStyle(h).position;if(/^(fixed|sticky)$/.test(u))break;h=u=="absolute"?h.offsetParent:ci(h)}}function Yi(t){let e=t.dom.getBoundingClientRect(),i=Math.max(0,e.top);let r,s;for(let n=(e.left+e.right)/2,h=i+1;h<Math.min(innerHeight,e.bottom);h+=5){let e=t.root.elementFromPoint(n,h);if(!e||e==t.dom||!t.dom.contains(e))continue;let l=e.getBoundingClientRect();if(l.top>=i-20){r=e;s=l.top;break}}return{refDOM:r,refTop:s,stack:Vi(t.dom)}}function Vi(t){let e=[],i=t.ownerDocument;for(let r=t;r;r=ci(r)){e.push({dom:r,top:r.scrollTop,left:r.scrollLeft});if(t==i)break}return e}function Zi({refDOM:t,refTop:e,stack:i}){let r=t?t.getBoundingClientRect().top:0;tr(i,r==0?0:r-e)}function tr(t,e){for(let i=0;i<t.length;i++){let{dom:r,top:s,left:n}=t[i];if(r.scrollTop!=s+e)r.scrollTop=s+e;if(r.scrollLeft!=n)r.scrollLeft=n}}let er=null;function ir(t){if(t.setActive)return t.setActive();if(er)return t.focus(er);let e=Vi(t);t.focus(er==null?{get preventScroll(){er={preventScroll:true};return true}}:undefined);if(!er){er=false;tr(e,0)}}function rr(t,e){let i,r=2e8,s,n=0;let h=e.top,l=e.top;let o,f;for(let u=t.firstChild,a=0;u;u=u.nextSibling,a++){let t;if(u.nodeType==1)t=u.getClientRects();else if(u.nodeType==3)t=pi(u).getClientRects();else continue;for(let c=0;c<t.length;c++){let d=t[c];if(d.top<=h&&d.bottom>=l){h=Math.max(d.bottom,h);l=Math.min(d.top,l);let t=d.left>e.left?d.left-e.left:d.right<e.left?e.left-d.right:0;if(t<r){i=u;r=t;s=t&&i.nodeType==3?{left:d.right<e.left?d.right:d.left,top:e.top}:e;if(u.nodeType==1&&t)n=a+(e.left>=(d.left+d.right)/2?1:0);continue}}else if(d.top>e.top&&!o&&d.left<=e.left&&d.right>=e.left){o=u;f={left:Math.max(d.left,Math.min(d.right,e.left)),top:d.top}}if(!i&&(e.left>=d.right&&e.top>=d.top||e.left>=d.left&&e.top>=d.bottom))n=a+1}}if(!i&&o){i=o;s=f;r=0}if(i&&i.nodeType==3)return sr(i,s);if(!i||r&&i.nodeType==1)return{node:t,offset:n};return rr(i,s)}function sr(t,e){let i=t.nodeValue.length;let r=document.createRange();for(let s=0;s<i;s++){r.setEnd(t,s+1);r.setStart(t,s);let i=cr(r,1);if(i.top==i.bottom)continue;if(nr(e,i))return{node:t,offset:s+(e.left>=(i.left+i.right)/2?1:0)}}return{node:t,offset:0}}function nr(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function hr(t,e){let i=t.parentNode;if(i&&/^li$/i.test(i.nodeName)&&e.left<t.getBoundingClientRect().left)return i;return t}function lr(t,e,i){let{node:r,offset:s}=rr(e,i),n=-1;if(r.nodeType==1&&!r.firstChild){let t=r.getBoundingClientRect();n=t.left!=t.right&&i.left>(t.left+t.right)/2?1:-1}return t.docView.posFromDOM(r,s,n)}function or(t,e,i,r){let s=-1;for(let i=e,n=false;;){if(i==t.dom)break;let e=t.docView.nearestDesc(i,true),h;if(!e)return null;if(e.dom.nodeType==1&&(e.node.isBlock&&e.parent||!e.contentDOM)&&((h=e.dom.getBoundingClientRect()).width||h.height)){if(e.node.isBlock&&e.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(e.dom.nodeName)){if(!n&&h.left>r.left||h.top>r.top)s=e.posBefore;else if(!n&&h.right<r.left||h.bottom<r.top)s=e.posAfter;n=true}if(!e.contentDOM&&s<0&&!e.node.isText){let t=e.node.isBlock?r.top<(h.top+h.bottom)/2:r.left<(h.left+h.right)/2;return t?e.posBefore:e.posAfter}}i=e.dom.parentNode}return s>-1?s:t.docView.posFromDOM(e,i,-1)}function fr(t,e,i){let r=t.childNodes.length;if(r&&i.top<i.bottom){for(let s=Math.max(0,Math.min(r-1,Math.floor(r*(e.top-i.top)/(i.bottom-i.top))-2)),n=s;;){let i=t.childNodes[n];if(i.nodeType==1){let t=i.getClientRects();for(let r=0;r<t.length;r++){let s=t[r];if(nr(e,s))return fr(i,e,s)}}if((n=(n+1)%r)==s)break}}return t}function ur(t,e){let i=t.dom.ownerDocument,r,s=0;let n=Oi(i,e.left,e.top);if(n)({node:r,offset:s}=n);let h=(t.root.elementFromPoint?t.root:i).elementFromPoint(e.left,e.top);let l;if(!h||!t.dom.contains(h.nodeType!=1?h.parentNode:h)){let i=t.dom.getBoundingClientRect();if(!nr(e,i))return null;h=fr(t.dom,e,i);if(!h)return null}if(_i){for(let t=h;r&&t;t=ci(t))if(t.draggable)r=undefined}h=hr(h,e);if(r){if(Bi&&r.nodeType==1){s=Math.min(s,r.childNodes.length);if(s<r.childNodes.length){let t=r.childNodes[s],i;if(t.nodeName=="IMG"&&(i=t.getBoundingClientRect()).right<=e.left&&i.bottom>e.top)s++}}let i;if(Li&&s&&r.nodeType==1&&(i=r.childNodes[s-1]).nodeType==1&&i.contentEditable=="false"&&i.getBoundingClientRect().top>=e.top)s--;if(r==t.dom&&s==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom)l=t.state.doc.content.size;else if(s==0||r.nodeType!=1||r.childNodes[s-1].nodeName!="BR")l=or(t,r,s,e)}if(l==null)l=lr(t,h,e);let o=t.docView.nearestDesc(h,true);return{pos:l,inside:o?o.posAtStart-o.border:-1}}function ar(t){return t.top<t.bottom||t.left<t.right}function cr(t,e){let i=t.getClientRects();if(i.length){let t=i[e<0?0:i.length-1];if(ar(t))return t}return Array.prototype.find.call(i,ar)||t.getBoundingClientRect()}const dr=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function pr(t,e,i){let{node:r,offset:s,atom:n}=t.docView.domFromPos(e,i<0?-1:1);let h=Li||Bi;if(r.nodeType==3){if(h&&(dr.test(r.nodeValue)||(i<0?!s:s==r.nodeValue.length))){let t=cr(pi(r,s,s),i);if(Bi&&s&&/\s/.test(r.nodeValue[s-1])&&s<r.nodeValue.length){let e=cr(pi(r,s-1,s-1),-1);if(e.top==t.top){let i=cr(pi(r,s,s+1),-1);if(i.top!=t.top)return wr(i,i.left<e.left)}}return t}else{let t=s,e=s,n=i<0?1:-1;if(i<0&&!s){e++;n=-1}else if(i>=0&&s==r.nodeValue.length){t--;n=1}else if(i<0){t--}else{e++}return wr(cr(pi(r,t,e),n),n<0)}}let l=t.state.doc.resolve(e-(n||0));if(!l.parent.inlineContent){if(n==null&&s&&(i<0||s==vi(r))){let t=r.childNodes[s-1];if(t.nodeType==1)return mr(t.getBoundingClientRect(),false)}if(n==null&&s<vi(r)){let t=r.childNodes[s];if(t.nodeType==1)return mr(t.getBoundingClientRect(),true)}return mr(r.getBoundingClientRect(),i>=0)}if(n==null&&s&&(i<0||s==vi(r))){let t=r.childNodes[s-1];let e=t.nodeType==3?pi(t,vi(t)-(h?0:1)):t.nodeType==1&&(t.nodeName!="BR"||!t.nextSibling)?t:null;if(e)return wr(cr(e,1),false)}if(n==null&&s<vi(r)){let t=r.childNodes[s];while(t.pmViewDesc&&t.pmViewDesc.ignoreForCoords)t=t.nextSibling;let e=!t?null:t.nodeType==3?pi(t,0,h?0:1):t.nodeType==1?t:null;if(e)return wr(cr(e,-1),true)}return wr(cr(r.nodeType==3?pi(r):r,-i),i>=0)}function wr(t,e){if(t.width==0)return t;let i=e?t.left:t.right;return{top:t.top,bottom:t.bottom,left:i,right:i}}function mr(t,e){if(t.height==0)return t;let i=e?t.top:t.bottom;return{top:i,bottom:i,left:t.left,right:t.right}}function gr(t,e,i){let r=t.state,s=t.root.activeElement;if(r!=e)t.updateState(e);if(s!=t.dom)t.focus();try{return i()}finally{if(r!=e)t.updateState(r);if(s!=t.dom&&s)s.focus()}}function br(t,e,i){let r=e.selection;let s=i=="up"?r.$from:r.$to;return gr(t,e,(()=>{let{node:e}=t.docView.domFromPos(s.pos,i=="up"?-1:1);for(;;){let i=t.docView.nearestDesc(e,true);if(!i)break;if(i.node.isBlock){e=i.contentDOM||i.dom;break}e=i.dom.parentNode}let r=pr(t,s.pos,1);for(let t=e.firstChild;t;t=t.nextSibling){let e;if(t.nodeType==1)e=t.getClientRects();else if(t.nodeType==3)e=pi(t,0,t.nodeValue.length).getClientRects();else continue;for(let t=0;t<e.length;t++){let s=e[t];if(s.bottom>s.top+1&&(i=="up"?r.top-s.top>(s.bottom-r.top)*2:s.bottom-r.bottom>(r.bottom-s.top)*2))return false}}return true}))}const vr=/[\u0590-\u08ac]/;function yr(t,e,i){let{$head:r}=e.selection;if(!r.parent.isTextblock)return false;let s=r.parentOffset,n=!s,h=s==r.parent.content.size;let l=t.domSelection();if(!l)return r.pos==r.start()||r.pos==r.end();if(!vr.test(r.parent.textContent)||!l.modify)return i=="left"||i=="backward"?n:h;return gr(t,e,(()=>{let{focusNode:e,focusOffset:s,anchorNode:n,anchorOffset:h}=t.domSelectionRange();let o=l.caretBidiLevel;l.modify("move",i,"character");let f=r.depth?t.docView.domAfterPos(r.before()):t.dom;let{focusNode:u,focusOffset:a}=t.domSelectionRange();let c=u&&!f.contains(u.nodeType==1?u:u.parentNode)||e==u&&s==a;try{l.collapse(n,h);if(e&&(e!=n||s!=h)&&l.extend)l.extend(e,s)}catch(t){}if(o!=null)l.caretBidiLevel=o;return c}))}let Mr=null;let Ar=null;let kr=false;function Sr(t,e,i){if(Mr==e&&Ar==i)return kr;Mr=e;Ar=i;return kr=i=="up"||i=="down"?br(t,e,i):yr(t,e,i)}const xr=0,Er=1,Or=2,Dr=3;class Tr{constructor(t,e,i,r){this.parent=t;this.children=e;this.dom=i;this.contentDOM=r;this.dirty=xr;i.pmViewDesc=this}matchesWidget(t){return false}matchesMark(t){return false}matchesNode(t,e,i){return false}matchesHack(t){return false}parseRule(){return null}stopEvent(t){return false}get size(){let t=0;for(let e=0;e<this.children.length;e++)t+=this.children[e].size;return t}get border(){return 0}destroy(){this.parent=undefined;if(this.dom.pmViewDesc==this)this.dom.pmViewDesc=undefined;for(let t=0;t<this.children.length;t++)this.children[t].destroy()}posBeforeChild(t){for(let e=0,i=this.posAtStart;;e++){let r=this.children[e];if(r==t)return i;i+=r.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(t,e,i){if(this.contentDOM&&this.contentDOM.contains(t.nodeType==1?t:t.parentNode)){if(i<0){let i,r;if(t==this.contentDOM){i=t.childNodes[e-1]}else{while(t.parentNode!=this.contentDOM)t=t.parentNode;i=t.previousSibling}while(i&&!((r=i.pmViewDesc)&&r.parent==this))i=i.previousSibling;return i?this.posBeforeChild(r)+r.size:this.posAtStart}else{let i,r;if(t==this.contentDOM){i=t.childNodes[e]}else{while(t.parentNode!=this.contentDOM)t=t.parentNode;i=t.nextSibling}while(i&&!((r=i.pmViewDesc)&&r.parent==this))i=i.nextSibling;return i?this.posBeforeChild(r):this.posAtEnd}}let r;if(t==this.dom&&this.contentDOM){r=e>ai(this.contentDOM)}else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM)){r=t.compareDocumentPosition(this.contentDOM)&2}else if(this.dom.firstChild){if(e==0)for(let e=t;;e=e.parentNode){if(e==this.dom){r=false;break}if(e.previousSibling)break}if(r==null&&e==t.childNodes.length)for(let e=t;;e=e.parentNode){if(e==this.dom){r=true;break}if(e.nextSibling)break}}return(r==null?i>0:r)?this.posAtEnd:this.posAtStart}nearestDesc(t,e=false){for(let i=true,r=t;r;r=r.parentNode){let s=this.getDesc(r),n;if(s&&(!e||s.node)){if(i&&(n=s.nodeDOM)&&!(n.nodeType==1?n.contains(t.nodeType==1?t:t.parentNode):n==t))i=false;else return s}}}getDesc(t){let e=t.pmViewDesc;for(let t=e;t;t=t.parent)if(t==this)return e}posFromDOM(t,e,i){for(let r=t;r;r=r.parentNode){let s=this.getDesc(r);if(s)return s.localPosFromDOM(t,e,i)}return-1}descAt(t){for(let e=0,i=0;e<this.children.length;e++){let r=this.children[e],s=i+r.size;if(i==t&&s!=i){while(!r.border&&r.children.length){for(let t=0;t<r.children.length;t++){let e=r.children[t];if(e.size){r=e;break}}}return r}if(t<s)return r.descAt(t-i-r.border);i=s}}domFromPos(t,e){if(!this.contentDOM)return{node:this.dom,offset:0,atom:t+1};let i=0,r=0;for(let e=0;i<this.children.length;i++){let s=this.children[i],n=e+s.size;if(n>t||s instanceof Br){r=t-e;break}e=n}if(r)return this.children[i].domFromPos(r-this.children[i].border,e);for(let t;i&&!(t=this.children[i-1]).size&&t instanceof Rr&&t.side>=0;i--){}if(e<=0){let t,r=true;for(;;i--,r=false){t=i?this.children[i-1]:null;if(!t||t.dom.parentNode==this.contentDOM)break}if(t&&e&&r&&!t.border&&!t.domAtom)return t.domFromPos(t.size,e);return{node:this.contentDOM,offset:t?ai(t.dom)+1:0}}else{let t,r=true;for(;;i++,r=false){t=i<this.children.length?this.children[i]:null;if(!t||t.dom.parentNode==this.contentDOM)break}if(t&&r&&!t.border&&!t.domAtom)return t.domFromPos(0,e);return{node:this.contentDOM,offset:t?ai(t.dom):this.contentDOM.childNodes.length}}}parseRange(t,e,i=0){if(this.children.length==0)return{node:this.contentDOM,from:t,to:e,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let r=-1,s=-1;for(let n=i,h=0;;h++){let i=this.children[h],l=n+i.size;if(r==-1&&t<=l){let s=n+i.border;if(t>=s&&e<=l-i.border&&i.node&&i.contentDOM&&this.contentDOM.contains(i.contentDOM))return i.parseRange(t,e,s);t=n;for(let e=h;e>0;e--){let i=this.children[e-1];if(i.size&&i.dom.parentNode==this.contentDOM&&!i.emptyChildAt(1)){r=ai(i.dom)+1;break}t-=i.size}if(r==-1)r=0}if(r>-1&&(l>e||h==this.children.length-1)){e=l;for(let t=h+1;t<this.children.length;t++){let i=this.children[t];if(i.size&&i.dom.parentNode==this.contentDOM&&!i.emptyChildAt(-1)){s=ai(i.dom);break}e+=i.size}if(s==-1)s=this.contentDOM.childNodes.length;break}n=l}return{node:this.contentDOM,from:t,to:e,fromOffset:r,toOffset:s}}emptyChildAt(t){if(this.border||!this.contentDOM||!this.children.length)return false;let e=this.children[t<0?0:this.children.length-1];return e.size==0||e.emptyChildAt(t)}domAfterPos(t){let{node:e,offset:i}=this.domFromPos(t,0);if(e.nodeType!=1||i==e.childNodes.length)throw new RangeError("No node after pos "+t);return e.childNodes[i]}setSelection(t,e,i,r=false){let s=Math.min(t,e),n=Math.max(t,e);for(let h=0,l=0;h<this.children.length;h++){let o=this.children[h],f=l+o.size;if(s>l&&n<f)return o.setSelection(t-l-o.border,e-l-o.border,i,r);l=f}let h=this.domFromPos(t,t?-1:1);let l=e==t?h:this.domFromPos(e,e?-1:1);let o=i.root.getSelection();let f=i.domSelectionRange();let u=false;if((Bi||_i)&&t==e){let{node:t,offset:e}=h;if(t.nodeType==3){u=!!(e&&t.nodeValue[e-1]=="\n");if(u&&e==t.nodeValue.length){for(let e=t,i;e;e=e.parentNode){if(i=e.nextSibling){if(i.nodeName=="BR")h=l={node:i.parentNode,offset:ai(i)+1};break}let t=e.pmViewDesc;if(t&&t.node&&t.node.isBlock)break}}}else{let i=t.childNodes[e-1];u=i&&(i.nodeName=="BR"||i.contentEditable=="false")}}if(Bi&&f.focusNode&&f.focusNode!=l.node&&f.focusNode.nodeType==1){let t=f.focusNode.childNodes[f.focusOffset];if(t&&t.contentEditable=="false")r=true}if(!(r||u&&_i)&&mi(h.node,h.offset,f.anchorNode,f.anchorOffset)&&mi(l.node,l.offset,f.focusNode,f.focusOffset))return;let a=false;if((o.extend||t==e)&&!(u&&Bi)){o.collapse(h.node,h.offset);try{if(t!=e)o.extend(l.node,l.offset);a=true}catch(t){}}if(!a){if(t>e){let t=h;h=l;l=t}let i=document.createRange();i.setEnd(l.node,l.offset);i.setStart(h.node,h.offset);o.removeAllRanges();o.addRange(i)}}ignoreMutation(t){return!this.contentDOM&&t.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(t,e){for(let i=0,r=0;r<this.children.length;r++){let s=this.children[r],n=i+s.size;if(i==n?t<=n&&e>=i:t<n&&e>i){let r=i+s.border,h=n-s.border;if(t>=r&&e<=h){this.dirty=t==i||e==n?Or:Er;if(t==r&&e==h&&(s.contentLost||s.dom.parentNode!=this.contentDOM))s.dirty=Dr;else s.markDirty(t-r,e-r);return}else{s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?Or:Dr}}i=n}this.dirty=Or}markParentsDirty(){let t=1;for(let e=this.parent;e;e=e.parent,t++){let i=t==1?Or:Er;if(e.dirty<i)e.dirty=i}}get domAtom(){return false}get ignoreForCoords(){return false}get ignoreForSelection(){return false}isText(t){return false}}class Rr extends Tr{constructor(t,e,i,r){let s,n=e.type.toDOM;if(typeof n=="function")n=n(i,(()=>{if(!s)return r;if(s.parent)return s.parent.posBeforeChild(s)}));if(!e.type.spec.raw){if(n.nodeType!=1){let t=document.createElement("span");t.appendChild(n);n=t}n.contentEditable="false";n.classList.add("ProseMirror-widget")}super(t,[],n,null);this.widget=e;this.widget=e;s=this}matchesWidget(t){return this.dirty==xr&&t.type.eq(this.widget.type)}parseRule(){return{ignore:true}}stopEvent(t){let e=this.widget.spec.stopEvent;return e?e(t):false}ignoreMutation(t){return t.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom);super.destroy()}get domAtom(){return true}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}}class Cr extends Tr{constructor(t,e,i,r){super(t,[],e,null);this.textDOM=i;this.text=r}get size(){return this.text.length}localPosFromDOM(t,e){if(t!=this.textDOM)return this.posAtStart+(e?this.size:0);return this.posAtStart+e}domFromPos(t){return{node:this.textDOM,offset:t}}ignoreMutation(t){return t.type==="characterData"&&t.target.nodeValue==t.oldValue}}class Pr extends Tr{constructor(t,e,i,r,s){super(t,[],i,r);this.mark=e;this.spec=s}static create(t,e,i,r){let s=r.nodeViews[e.type.name];let n=s&&s(e,r,i);if(!n||!n.dom)n=St.renderSpec(document,e.type.spec.toDOM(e,i),null,e.attrs);return new Pr(t,e,n.dom,n.contentDOM||n.dom,n)}parseRule(){if(this.dirty&Dr||this.mark.type.spec.reparseInView)return null;return{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(t){return this.dirty!=Dr&&this.mark.eq(t)}markDirty(t,e){super.markDirty(t,e);if(this.dirty!=xr){let t=this.parent;while(!t.node)t=t.parent;if(t.dirty<this.dirty)t.dirty=this.dirty;this.dirty=xr}}slice(t,e,i){let r=Pr.create(this.parent,this.mark,true,i);let s=this.children,n=this.size;if(e<n)s=Zr(s,e,n,i);if(t>0)s=Zr(s,0,t,i);for(let t=0;t<s.length;t++)s[t].parent=r;r.children=s;return r}ignoreMutation(t){return this.spec.ignoreMutation?this.spec.ignoreMutation(t):super.ignoreMutation(t)}destroy(){if(this.spec.destroy)this.spec.destroy();super.destroy()}}class Ir extends Tr{constructor(t,e,i,r,s,n,h,l,o){super(t,[],s,n);this.node=e;this.outerDeco=i;this.innerDeco=r;this.nodeDOM=h}static create(t,e,i,r,s,n){let h=s.nodeViews[e.type.name],l;let o=h&&h(e,s,(()=>{if(!l)return n;if(l.parent)return l.parent.posBeforeChild(l)}),i,r);let f=o&&o.dom,u=o&&o.contentDOM;if(e.isText){if(!f)f=document.createTextNode(e.text);else if(f.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else if(!f){let t=St.renderSpec(document,e.type.spec.toDOM(e),null,e.attrs);({dom:f,contentDOM:u}=t)}if(!u&&!e.isText&&f.nodeName!="BR"){if(!f.hasAttribute("contenteditable"))f.contentEditable="false";if(e.type.spec.draggable)f.draggable=true}let a=f;f=Qr(f,i,e);if(o)return l=new Ur(t,e,i,r,f,u||null,a,o,s,n+1);else if(e.isText)return new Fr(t,e,i,r,f,a,s);else return new Ir(t,e,i,r,f,u||null,a,s,n+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let t={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre")t.preserveWhitespace="full";if(!this.contentDOM){t.getContent=()=>this.node.content}else if(!this.contentLost){t.contentElement=this.contentDOM}else{for(let e=this.children.length-1;e>=0;e--){let i=this.children[e];if(this.dom.contains(i.dom.parentNode)){t.contentElement=i.dom.parentNode;break}}if(!t.contentElement)t.getContent=()=>u.empty}return t}matchesNode(t,e,i){return this.dirty==xr&&t.eq(this.node)&&Lr(e,this.outerDeco)&&i.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(t,e){let i=this.node.inlineContent,r=e;let s=t.composing?this.localCompositionInfo(t,e):null;let n=s&&s.pos>-1?s:null;let h=s&&s.pos<0;let l=new Hr(this,n&&n.node,t);Xr(this.node,this.innerDeco,((e,s,n)=>{if(e.spec.marks)l.syncToMarks(e.spec.marks,i,t);else if(e.type.side>=0&&!n)l.syncToMarks(s==this.node.childCount?p.none:this.node.child(s).marks,i,t);l.placeWidget(e,t,r)}),((e,n,o,f)=>{l.syncToMarks(e.marks,i,t);let u;if(l.findNodeMatch(e,n,o,f));else if(h&&t.state.selection.from>r&&t.state.selection.to<r+e.nodeSize&&(u=l.findIndexWithChild(s.node))>-1&&l.updateNodeAt(e,n,o,u,t));else if(l.updateNextNode(e,n,o,t,f,r));else{l.addNode(e,n,o,t,r)}r+=e.nodeSize}));l.syncToMarks([],i,t);if(this.node.isTextblock)l.addTextblockHacks();l.destroyRest();if(l.changed||this.dirty==Or){if(n)this.protectLocalComposition(t,n);jr(this.contentDOM,this.children,t);if(zi)Yr(this.dom)}}localCompositionInfo(t,e){let{from:i,to:r}=t.state.selection;if(!(t.state.selection instanceof Qe)||i<e||r>e+this.node.content.size)return null;let s=t.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let t=s.nodeValue;let n=Vr(this.node.content,t,i-e,r-e);return n<0?null:{node:s,pos:n,text:t}}else{return{node:s,pos:-1,text:""}}}protectLocalComposition(t,{node:e,pos:i,text:r}){if(this.getDesc(e))return;let s=e;for(;;s=s.parentNode){if(s.parentNode==this.contentDOM)break;while(s.previousSibling)s.parentNode.removeChild(s.previousSibling);while(s.nextSibling)s.parentNode.removeChild(s.nextSibling);if(s.pmViewDesc)s.pmViewDesc=undefined}let n=new Cr(this,s,e,r);t.input.compositionNodes.push(n);this.children=Zr(this.children,i,i+r.length,t,n)}update(t,e,i,r){if(this.dirty==Dr||!t.sameMarkup(this.node))return false;this.updateInner(t,e,i,r);return true}updateInner(t,e,i,r){this.updateOuterDeco(e);this.node=t;this.innerDeco=i;if(this.contentDOM)this.updateChildren(r,this.posAtStart);this.dirty=xr}updateOuterDeco(t){if(Lr(t,this.outerDeco))return;let e=this.nodeDOM.nodeType!=1;let i=this.dom;this.dom=Jr(this.dom,this.nodeDOM,zr(this.outerDeco,this.node,e),zr(t,this.node,e));if(this.dom!=i){i.pmViewDesc=undefined;this.dom.pmViewDesc=this}this.outerDeco=t}selectNode(){if(this.nodeDOM.nodeType==1){this.nodeDOM.classList.add("ProseMirror-selectednode");if(this.contentDOM||!this.node.type.spec.draggable)this.nodeDOM.draggable=true}}deselectNode(){if(this.nodeDOM.nodeType==1){this.nodeDOM.classList.remove("ProseMirror-selectednode");if(this.contentDOM||!this.node.type.spec.draggable)this.nodeDOM.removeAttribute("draggable")}}get domAtom(){return this.node.isAtom}}function Nr(t,e,i,r,s){Qr(r,e,t);let n=new Ir(undefined,t,e,i,r,r,r,s,0);if(n.contentDOM)n.updateChildren(s,0);return n}class Fr extends Ir{constructor(t,e,i,r,s,n,h){super(t,e,i,r,s,null,n,h,0)}parseRule(){let t=this.nodeDOM.parentNode;while(t&&t!=this.dom&&!t.pmIsDeco)t=t.parentNode;return{skip:t||true}}update(t,e,i,r){if(this.dirty==Dr||this.dirty!=xr&&!this.inParent()||!t.sameMarkup(this.node))return false;this.updateOuterDeco(e);if((this.dirty!=xr||t.text!=this.node.text)&&t.text!=this.nodeDOM.nodeValue){this.nodeDOM.nodeValue=t.text;if(r.trackWrites==this.nodeDOM)r.trackWrites=null}this.node=t;this.dirty=xr;return true}inParent(){let t=this.parent.contentDOM;for(let e=this.nodeDOM;e;e=e.parentNode)if(e==t)return true;return false}domFromPos(t){return{node:this.nodeDOM,offset:t}}localPosFromDOM(t,e,i){if(t==this.nodeDOM)return this.posAtStart+Math.min(e,this.node.text.length);return super.localPosFromDOM(t,e,i)}ignoreMutation(t){return t.type!="characterData"&&t.type!="selection"}slice(t,e,i){let r=this.node.cut(t,e),s=document.createTextNode(r.text);return new Fr(this.parent,r,this.outerDeco,this.innerDeco,s,s,i)}markDirty(t,e){super.markDirty(t,e);if(this.dom!=this.nodeDOM&&(t==0||e==this.nodeDOM.nodeValue.length))this.dirty=Dr}get domAtom(){return false}isText(t){return this.node.text==t}}class Br extends Tr{parseRule(){return{ignore:true}}matchesHack(t){return this.dirty==xr&&this.dom.nodeName==t}get domAtom(){return true}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class Ur extends Ir{constructor(t,e,i,r,s,n,h,l,o,f){super(t,e,i,r,s,n,h,o,f);this.spec=l}update(t,e,i,r){if(this.dirty==Dr)return false;if(this.spec.update&&(this.node.type==t.type||this.spec.multiType)){let s=this.spec.update(t,e,i);if(s)this.updateInner(t,e,i,r);return s}else if(!this.contentDOM&&!t.isLeaf){return false}else{return super.update(t,e,i,r)}}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(t,e,i,r){this.spec.setSelection?this.spec.setSelection(t,e,i.root):super.setSelection(t,e,i,r)}destroy(){if(this.spec.destroy)this.spec.destroy();super.destroy()}stopEvent(t){return this.spec.stopEvent?this.spec.stopEvent(t):false}ignoreMutation(t){return this.spec.ignoreMutation?this.spec.ignoreMutation(t):super.ignoreMutation(t)}}function jr(t,e,i){let r=t.firstChild,s=false;for(let n=0;n<e.length;n++){let h=e[n],l=h.dom;if(l.parentNode==t){while(l!=r){r=Kr(r);s=true}r=r.nextSibling}else{s=true;t.insertBefore(l,r)}if(h instanceof Pr){let e=r?r.previousSibling:t.lastChild;jr(h.contentDOM,h.children,i);r=e?e.nextSibling:t.firstChild}}while(r){r=Kr(r);s=true}if(s&&i.trackWrites==t)i.trackWrites=null}const $r=function(t){if(t)this.nodeName=t};$r.prototype=Object.create(null);const _r=[new $r];function zr(t,e,i){if(t.length==0)return _r;let r=i?_r[0]:new $r,s=[r];for(let n=0;n<t.length;n++){let h=t[n].type.attrs;if(!h)continue;if(h.nodeName)s.push(r=new $r(h.nodeName));for(let t in h){let n=h[t];if(n==null)continue;if(i&&s.length==1)s.push(r=new $r(e.isInline?"span":"div"));if(t=="class")r.class=(r.class?r.class+" ":"")+n;else if(t=="style")r.style=(r.style?r.style+";":"")+n;else if(t!="nodeName")r[t]=n}}return s}function Jr(t,e,i,r){if(i==_r&&r==_r)return e;let s=e;for(let e=0;e<r.length;e++){let n=r[e],h=i[e];if(e){let e;if(h&&h.nodeName==n.nodeName&&s!=t&&(e=s.parentNode)&&e.nodeName.toLowerCase()==n.nodeName){s=e}else{e=document.createElement(n.nodeName);e.pmIsDeco=true;e.appendChild(s);h=_r[0];s=e}}Wr(s,h||_r[0],n)}return s}function Wr(t,e,i){for(let r in e)if(r!="class"&&r!="style"&&r!="nodeName"&&!(r in i))t.removeAttribute(r);for(let r in i)if(r!="class"&&r!="style"&&r!="nodeName"&&i[r]!=e[r])t.setAttribute(r,i[r]);if(e.class!=i.class){let r=e.class?e.class.split(" ").filter(Boolean):[];let s=i.class?i.class.split(" ").filter(Boolean):[];for(let e=0;e<r.length;e++)if(s.indexOf(r[e])==-1)t.classList.remove(r[e]);for(let e=0;e<s.length;e++)if(r.indexOf(s[e])==-1)t.classList.add(s[e]);if(t.classList.length==0)t.removeAttribute("class")}if(e.style!=i.style){if(e.style){let i=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,r;while(r=i.exec(e.style))t.style.removeProperty(r[1])}if(i.style)t.style.cssText+=i.style}}function Qr(t,e,i){return Jr(t,t,_r,zr(e,i,t.nodeType!=1))}function Lr(t,e){if(t.length!=e.length)return false;for(let i=0;i<t.length;i++)if(!t[i].type.eq(e[i].type))return false;return true}function Kr(t){let e=t.nextSibling;t.parentNode.removeChild(t);return e}class Hr{constructor(t,e,i){this.lock=e;this.view=i;this.index=0;this.stack=[];this.changed=false;this.top=t;this.preMatch=qr(t.node.content,t)}destroyBetween(t,e){if(t==e)return;for(let i=t;i<e;i++)this.top.children[i].destroy();this.top.children.splice(t,e-t);this.changed=true}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(t,e,i){let r=0,s=this.stack.length>>1;let n=Math.min(s,t.length);while(r<n&&(r==s-1?this.top:this.stack[r+1<<1]).matchesMark(t[r])&&t[r].type.spec.spanning!==false)r++;while(r<s){this.destroyRest();this.top.dirty=xr;this.index=this.stack.pop();this.top=this.stack.pop();s--}while(s<t.length){this.stack.push(this.top,this.index+1);let r=-1;for(let e=this.index;e<Math.min(this.index+3,this.top.children.length);e++){let i=this.top.children[e];if(i.matchesMark(t[s])&&!this.isLocked(i.dom)){r=e;break}}if(r>-1){if(r>this.index){this.changed=true;this.destroyBetween(this.index,r)}this.top=this.top.children[this.index]}else{let r=Pr.create(this.top,t[s],e,i);this.top.children.splice(this.index,0,r);this.top=r;this.changed=true}this.index=0;s++}}findNodeMatch(t,e,i,r){let s=-1,n;if(r>=this.preMatch.index&&(n=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&n.matchesNode(t,e,i)){s=this.top.children.indexOf(n,this.index)}else{for(let r=this.index,n=Math.min(this.top.children.length,r+5);r<n;r++){let n=this.top.children[r];if(n.matchesNode(t,e,i)&&!this.preMatch.matched.has(n)){s=r;break}}}if(s<0)return false;this.destroyBetween(this.index,s);this.index++;return true}updateNodeAt(t,e,i,r,s){let n=this.top.children[r];if(n.dirty==Dr&&n.dom==n.contentDOM)n.dirty=Or;if(!n.update(t,e,i,s))return false;this.destroyBetween(this.index,r);this.index++;return true}findIndexWithChild(t){for(;;){let e=t.parentNode;if(!e)return-1;if(e==this.top.contentDOM){let e=t.pmViewDesc;if(e)for(let t=this.index;t<this.top.children.length;t++){if(this.top.children[t]==e)return t}return-1}t=e}}updateNextNode(t,e,i,r,s,n){for(let h=this.index;h<this.top.children.length;h++){let l=this.top.children[h];if(l instanceof Ir){let o=this.preMatch.matched.get(l);if(o!=null&&o!=s)return false;let f=l.dom,u;let a=this.isLocked(f)&&!(t.isText&&l.node&&l.node.isText&&l.nodeDOM.nodeValue==t.text&&l.dirty!=Dr&&Lr(e,l.outerDeco));if(!a&&l.update(t,e,i,r)){this.destroyBetween(this.index,h);if(l.dom!=f)this.changed=true;this.index++;return true}else if(!a&&(u=this.recreateWrapper(l,t,e,i,r,n))){this.destroyBetween(this.index,h);this.top.children[this.index]=u;if(u.contentDOM){u.dirty=Or;u.updateChildren(r,n+1);u.dirty=xr}this.changed=true;this.index++;return true}break}}return false}recreateWrapper(t,e,i,r,s,n){if(t.dirty||e.isAtom||!t.children.length||!t.node.content.eq(e.content)||!Lr(i,t.outerDeco)||!r.eq(t.innerDeco))return null;let h=Ir.create(this.top,e,i,r,s,n);if(h.contentDOM){h.children=t.children;t.children=[];for(let t of h.children)t.parent=h}t.destroy();return h}addNode(t,e,i,r,s){let n=Ir.create(this.top,t,e,i,r,s);if(n.contentDOM)n.updateChildren(r,s+1);this.top.children.splice(this.index++,0,n);this.changed=true}placeWidget(t,e,i){let r=this.index<this.top.children.length?this.top.children[this.index]:null;if(r&&r.matchesWidget(t)&&(t==r.widget||!r.widget.type.toDOM.parentNode)){this.index++}else{let r=new Rr(this.top,t,e,i);this.top.children.splice(this.index++,0,r);this.changed=true}}addTextblockHacks(){let t=this.top.children[this.index-1],e=this.top;while(t instanceof Pr){e=t;t=e.children[e.children.length-1]}if(!t||!(t instanceof Fr)||/\n$/.test(t.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(t.node.text)){if((_i||ji)&&t&&t.dom.contentEditable=="false")this.addHackNode("IMG",e);this.addHackNode("BR",this.top)}}addHackNode(t,e){if(e==this.top&&this.index<e.children.length&&e.children[this.index].matchesHack(t)){this.index++}else{let i=document.createElement(t);if(t=="IMG"){i.className="ProseMirror-separator";i.alt=""}if(t=="BR")i.className="ProseMirror-trailingBreak";let r=new Br(this.top,[],i,null);if(e!=this.top)e.children.push(r);else e.children.splice(this.index++,0,r);this.changed=true}}isLocked(t){return this.lock&&(t==this.lock||t.nodeType==1&&t.contains(this.lock.parentNode))}}function qr(t,e){let i=e,r=i.children.length;let s=t.childCount,n=new Map,h=[];t:while(s>0){let l;for(;;){if(r){let t=i.children[r-1];if(t instanceof Pr){i=t;r=t.children.length}else{l=t;r--;break}}else if(i==e){break t}else{r=i.parent.children.indexOf(i);i=i.parent}}let o=l.node;if(!o)continue;if(o!=t.child(s-1))break;--s;n.set(l,s);h.push(l)}return{index:s,matched:n,matches:h.reverse()}}function Gr(t,e){return t.type.side-e.type.side}function Xr(t,e,i,r){let s=e.locals(t),n=0;if(s.length==0){for(let i=0;i<t.childCount;i++){let h=t.child(i);r(h,s,e.forChild(n,h),i);n+=h.nodeSize}return}let h=0,l=[],o=null;for(let f=0;;){let u,a;while(h<s.length&&s[h].to==n){let t=s[h++];if(t.widget){if(!u)u=t;else(a||(a=[u])).push(t)}}if(u){if(a){a.sort(Gr);for(let t=0;t<a.length;t++)i(a[t],f,!!o)}else{i(u,f,!!o)}}let c,d;if(o){d=-1;c=o;o=null}else if(f<t.childCount){d=f;c=t.child(f++)}else{break}for(let t=0;t<l.length;t++)if(l[t].to<=n)l.splice(t--,1);while(h<s.length&&s[h].from<=n&&s[h].to>n)l.push(s[h++]);let p=n+c.nodeSize;if(c.isText){let t=p;if(h<s.length&&s[h].from<t)t=s[h].from;for(let e=0;e<l.length;e++)if(l[e].to<t)t=l[e].to;if(t<p){o=c.cut(t-n);c=c.cut(0,t-n);p=t;d=-1}}else{while(h<s.length&&s[h].to<p)h++}let w=c.isInline&&!c.isLeaf?l.filter((t=>!t.inline)):l.slice();r(c,w,e.forChild(n,c),d);n=p}}function Yr(t){if(t.nodeName=="UL"||t.nodeName=="OL"){let e=t.style.cssText;t.style.cssText=e+"; list-style: square !important";window.getComputedStyle(t).listStyle;t.style.cssText=e}}function Vr(t,e,i,r){for(let s=0,n=0;s<t.childCount&&n<=r;){let h=t.child(s++),l=n;n+=h.nodeSize;if(!h.isText)continue;let o=h.text;while(s<t.childCount){let e=t.child(s++);n+=e.nodeSize;if(!e.isText)break;o+=e.text}if(n>=i){if(n>=r&&o.slice(r-e.length-l,r-l)==e)return r-e.length;let t=l<r?o.lastIndexOf(e,r-l-1):-1;if(t>=0&&t+e.length+l>=i)return l+t;if(i==r&&o.length>=r+e.length-l&&o.slice(r-l,r-l+e.length)==e)return r}}return-1}function Zr(t,e,i,r,s){let n=[];for(let h=0,l=0;h<t.length;h++){let o=t[h],f=l,u=l+=o.size;if(f>=i||u<=e){n.push(o)}else{if(f<e)n.push(o.slice(0,e-f,r));if(s){n.push(s);s=undefined}if(u>i)n.push(o.slice(i-f,o.size,r))}}return n}function ts(t,e=null){let i=t.domSelectionRange(),r=t.state.doc;if(!i.focusNode)return null;let s=t.docView.nearestDesc(i.focusNode),n=s&&s.size==0;let h=t.docView.posFromDOM(i.focusNode,i.focusOffset,1);if(h<0)return null;let l=r.resolve(h),o,f;if(Si(i)){o=h;while(s&&!s.node)s=s.parent;let t=s.node;if(s&&t.isAtom&&Ke.isSelectable(t)&&s.parent&&!(t.isInline&&Ai(i.focusNode,i.focusOffset,s.dom))){let t=s.posBefore;f=new Ke(h==t?l:r.resolve(t))}}else{if(i instanceof t.dom.ownerDocument.defaultView.Selection&&i.rangeCount>1){let e=h,s=h;for(let r=0;r<i.rangeCount;r++){let n=i.getRangeAt(r);e=Math.min(e,t.docView.posFromDOM(n.startContainer,n.startOffset,1));s=Math.max(s,t.docView.posFromDOM(n.endContainer,n.endOffset,-1))}if(e<0)return null;[o,h]=s==t.state.selection.anchor?[s,e]:[e,s];l=r.resolve(h)}else{o=t.docView.posFromDOM(i.anchorNode,i.anchorOffset,1)}if(o<0)return null}let u=r.resolve(o);if(!f){let i=e=="pointer"||t.state.selection.head<l.pos&&!n?1:-1;f=cs(t,u,l,i)}return f}function es(t){return t.editable?t.hasFocus():ps(t)&&document.activeElement&&document.activeElement.contains(t.dom)}function is(t,e=false){let i=t.state.selection;us(t,i);if(!es(t))return;if(!e&&t.input.mouseDown&&t.input.mouseDown.allowDefault&&ji){let e=t.domSelectionRange(),i=t.domObserver.currentSelection;if(e.anchorNode&&i.anchorNode&&mi(e.anchorNode,e.anchorOffset,i.anchorNode,i.anchorOffset)){t.input.mouseDown.delayedSelectionSync=true;t.domObserver.setCurSelection();return}}t.domObserver.disconnectSelection();if(t.cursorWrapper){fs(t)}else{let{anchor:r,head:s}=i,n,h;if(rs&&!(i instanceof Qe)){if(!i.$from.parent.inlineContent)n=ss(t,i.from);if(!i.empty&&!i.$from.parent.inlineContent)h=ss(t,i.to)}t.docView.setSelection(r,s,t,e);if(rs){if(n)hs(n);if(h)hs(h)}if(i.visible){t.dom.classList.remove("ProseMirror-hideselection")}else{t.dom.classList.add("ProseMirror-hideselection");if("onselectionchange"in document)ls(t)}}t.domObserver.setCurSelection();t.domObserver.connectSelection()}const rs=_i||ji&&$i<63;function ss(t,e){let{node:i,offset:r}=t.docView.domFromPos(e,0);let s=r<i.childNodes.length?i.childNodes[r]:null;let n=r?i.childNodes[r-1]:null;if(_i&&s&&s.contentEditable=="false")return ns(s);if((!s||s.contentEditable=="false")&&(!n||n.contentEditable=="false")){if(s)return ns(s);else if(n)return ns(n)}}function ns(t){t.contentEditable="true";if(_i&&t.draggable){t.draggable=false;t.wasDraggable=true}return t}function hs(t){t.contentEditable="false";if(t.wasDraggable){t.draggable=true;t.wasDraggable=null}}function ls(t){let e=t.dom.ownerDocument;e.removeEventListener("selectionchange",t.input.hideSelectionGuard);let i=t.domSelectionRange();let r=i.anchorNode,s=i.anchorOffset;e.addEventListener("selectionchange",t.input.hideSelectionGuard=()=>{if(i.anchorNode!=r||i.anchorOffset!=s){e.removeEventListener("selectionchange",t.input.hideSelectionGuard);setTimeout((()=>{if(!es(t)||t.state.selection.visible)t.dom.classList.remove("ProseMirror-hideselection")}),20)}})}function fs(t){let e=t.domSelection();if(!e)return;let i=t.cursorWrapper.dom,r=i.nodeName=="IMG";if(r)e.collapse(i.parentNode,ai(i)+1);else e.collapse(i,0);if(!r&&!t.state.selection.visible&&Ni&&Fi<=11){i.disabled=true;i.disabled=false}}function us(t,e){if(e instanceof Ke){let i=t.docView.descAt(e.from);if(i!=t.lastSelectedViewDesc){as(t);if(i)i.selectNode();t.lastSelectedViewDesc=i}}else{as(t)}}function as(t){if(t.lastSelectedViewDesc){if(t.lastSelectedViewDesc.parent)t.lastSelectedViewDesc.deselectNode();t.lastSelectedViewDesc=undefined}}function cs(t,e,i,r){return t.someProp("createSelectionBetween",(r=>r(t,e,i)))||Qe.between(e,i,r)}function ds(t){if(t.editable&&!t.hasFocus())return false;return ps(t)}function ps(t){let e=t.domSelectionRange();if(!e.anchorNode)return false;try{return t.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(t.editable||t.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch(t){return false}}function ws(t){let e=t.docView.domFromPos(t.state.selection.anchor,0);let i=t.domSelectionRange();return mi(e.node,e.offset,i.anchorNode,i.anchorOffset)}function ms(t,e){let{$anchor:i,$head:r}=t.selection;let s=e>0?i.max(r):i.min(r);let n=!s.parent.inlineContent?s:s.depth?t.doc.resolve(e>0?s.after():s.before()):null;return n&&_e.findFrom(n,e)}function gs(t,e){t.dispatch(t.state.tr.setSelection(e).scrollIntoView());return true}function bs(t,e,i){let r=t.state.selection;if(r instanceof Qe){if(i.indexOf("s")>-1){let{$head:i}=r,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return false;let n=t.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return gs(t,new Qe(r.$anchor,n))}else if(!r.empty){return false}else if(t.endOfTextblock(e>0?"forward":"backward")){let i=ms(t.state,e);if(i&&i instanceof Ke)return gs(t,i);return false}else if(!(Ji&&i.indexOf("m")>-1)){let i=r.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,n;if(!s||s.isText)return false;let h=e<0?i.pos-s.nodeSize:i.pos;if(!(s.isAtom||(n=t.docView.descAt(h))&&!n.contentDOM))return false;if(Ke.isSelectable(s)){return gs(t,new Ke(e<0?t.state.doc.resolve(i.pos-s.nodeSize):i))}else if(Li){return gs(t,new Qe(t.state.doc.resolve(e<0?h:h+s.nodeSize)))}else{return false}}}else if(r instanceof Ke&&r.node.isInline){return gs(t,new Qe(e>0?r.$to:r.$from))}else{let i=ms(t.state,e);if(i)return gs(t,i);return false}}function vs(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function ys(t,e){let i=t.pmViewDesc;return i&&i.size==0&&(e<0||t.nextSibling||t.nodeName!="BR")}function Ms(t,e){return e<0?As(t):ks(t)}function As(t){let e=t.domSelectionRange();let i=e.focusNode,r=e.focusOffset;if(!i)return;let s,n,h=false;if(Bi&&i.nodeType==1&&r<vs(i)&&ys(i.childNodes[r],-1))h=true;for(;;){if(r>0){if(i.nodeType!=1){break}else{let t=i.childNodes[r-1];if(ys(t,-1)){s=i;n=--r}else if(t.nodeType==3){i=t;r=i.nodeValue.length}else break}}else if(Ss(i)){break}else{let e=i.previousSibling;while(e&&ys(e,-1)){s=i.parentNode;n=ai(e);e=e.previousSibling}if(!e){i=i.parentNode;if(i==t.dom)break;r=0}else{i=e;r=vs(i)}}}if(h)Os(t,i,r);else if(s)Os(t,s,n)}function ks(t){let e=t.domSelectionRange();let i=e.focusNode,r=e.focusOffset;if(!i)return;let s=vs(i);let n,h;for(;;){if(r<s){if(i.nodeType!=1)break;let t=i.childNodes[r];if(ys(t,1)){n=i;h=++r}else break}else if(Ss(i)){break}else{let e=i.nextSibling;while(e&&ys(e,1)){n=e.parentNode;h=ai(e)+1;e=e.nextSibling}if(!e){i=i.parentNode;if(i==t.dom)break;r=s=0}else{i=e;r=0;s=vs(i)}}}if(n)Os(t,n,h)}function Ss(t){let e=t.pmViewDesc;return e&&e.node&&e.node.isBlock}function xs(t,e){while(t&&e==t.childNodes.length&&!ki(t)){e=ai(t)+1;t=t.parentNode}while(t&&e<t.childNodes.length){let i=t.childNodes[e];if(i.nodeType==3)return i;if(i.nodeType==1&&i.contentEditable=="false")break;t=i;e=0}}function Es(t,e){while(t&&!e&&!ki(t)){e=ai(t);t=t.parentNode}while(t&&e){let i=t.childNodes[e-1];if(i.nodeType==3)return i;if(i.nodeType==1&&i.contentEditable=="false")break;t=i;e=t.childNodes.length}}function Os(t,e,i){if(e.nodeType!=3){let t,r;if(r=xs(e,i)){e=r;i=0}else if(t=Es(e,i)){e=t;i=t.nodeValue.length}}let r=t.domSelection();if(!r)return;if(Si(r)){let t=document.createRange();t.setEnd(e,i);t.setStart(e,i);r.removeAllRanges();r.addRange(t)}else if(r.extend){r.extend(e,i)}t.domObserver.setCurSelection();let{state:s}=t;setTimeout((()=>{if(t.state==s)is(t)}),50)}function Ds(t,e){let i=t.state.doc.resolve(e);if(!(ji||Wi)&&i.parent.inlineContent){let r=t.coordsAtPos(e);if(e>i.start()){let i=t.coordsAtPos(e-1);let s=(i.top+i.bottom)/2;if(s>r.top&&s<r.bottom&&Math.abs(i.left-r.left)>1)return i.left<r.left?"ltr":"rtl"}if(e<i.end()){let i=t.coordsAtPos(e+1);let s=(i.top+i.bottom)/2;if(s>r.top&&s<r.bottom&&Math.abs(i.left-r.left)>1)return i.left>r.left?"ltr":"rtl"}}let r=getComputedStyle(t.dom).direction;return r=="rtl"?"rtl":"ltr"}function Ts(t,e,i){let r=t.state.selection;if(r instanceof Qe&&!r.empty||i.indexOf("s")>-1)return false;if(Ji&&i.indexOf("m")>-1)return false;let{$from:s,$to:n}=r;if(!s.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let i=ms(t.state,e);if(i&&i instanceof Ke)return gs(t,i)}if(!s.parent.inlineContent){let i=e<0?s:n;let h=r instanceof qe?_e.near(i,e):_e.findFrom(i,e);return h?gs(t,h):false}return false}function Rs(t,e){if(!(t.state.selection instanceof Qe))return true;let{$head:i,$anchor:r,empty:s}=t.state.selection;if(!i.sameParent(r))return true;if(!s)return false;if(t.endOfTextblock(e>0?"forward":"backward"))return true;let n=!i.textOffset&&(e<0?i.nodeBefore:i.nodeAfter);if(n&&!n.isText){let r=t.state.tr;if(e<0)r.delete(i.pos-n.nodeSize,i.pos);else r.delete(i.pos,i.pos+n.nodeSize);t.dispatch(r);return true}return false}function Cs(t,e,i){t.domObserver.stop();e.contentEditable=i;t.domObserver.start()}function Ps(t){if(!_i||t.state.selection.$head.parentOffset>0)return false;let{focusNode:e,focusOffset:i}=t.domSelectionRange();if(e&&e.nodeType==1&&i==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let i=e.firstChild;Cs(t,i,"true");setTimeout((()=>Cs(t,i,"false")),20)}return false}function Is(t){let e="";if(t.ctrlKey)e+="c";if(t.metaKey)e+="m";if(t.altKey)e+="a";if(t.shiftKey)e+="s";return e}function Ns(t,e){let i=e.keyCode,r=Is(e);if(i==8||Ji&&i==72&&r=="c"){return Rs(t,-1)||Ms(t,-1)}else if(i==46&&!e.shiftKey||Ji&&i==68&&r=="c"){return Rs(t,1)||Ms(t,1)}else if(i==13||i==27){return true}else if(i==37||Ji&&i==66&&r=="c"){let e=i==37?Ds(t,t.state.selection.from)=="ltr"?-1:1:-1;return bs(t,e,r)||Ms(t,e)}else if(i==39||Ji&&i==70&&r=="c"){let e=i==39?Ds(t,t.state.selection.from)=="ltr"?1:-1:1;return bs(t,e,r)||Ms(t,e)}else if(i==38||Ji&&i==80&&r=="c"){return Ts(t,-1,r)||Ms(t,-1)}else if(i==40||Ji&&i==78&&r=="c"){return Ps(t)||Ts(t,1,r)||Ms(t,1)}else if(r==(Ji?"m":"c")&&(i==66||i==73||i==89||i==90)){return true}return false}function Fs(t,e){t.someProp("transformCopied",(i=>{e=i(e,t)}));let i=[],{content:r,openStart:s,openEnd:n}=e;while(s>1&&n>1&&r.childCount==1&&r.firstChild.childCount==1){s--;n--;let t=r.firstChild;i.push(t.type.name,t.attrs!=t.type.defaultAttrs?t.attrs:null);r=t.content}let h=t.someProp("clipboardSerializer")||St.fromSchema(t.state.schema);let l=Ks(),o=l.createElement("div");o.appendChild(h.serializeFragment(r,{document:l}));let f=o.firstChild,u,a=0;while(f&&f.nodeType==1&&(u=Qs[f.nodeName.toLowerCase()])){for(let t=u.length-1;t>=0;t--){let e=l.createElement(u[t]);while(o.firstChild)e.appendChild(o.firstChild);o.appendChild(e);a++}f=o.firstChild}if(f&&f.nodeType==1)f.setAttribute("data-pm-slice",`${s} ${n}${a?` -${a}`:""} ${JSON.stringify(i)}`);let c=t.someProp("clipboardTextSerializer",(i=>i(e,t)))||e.content.textBetween(0,e.content.size,"\n\n");return{dom:o,text:c,slice:e}}function Bs(t,e,i,r,s){let n=s.parent.type.spec.code;let h,l;if(!i&&!e)return null;let o=!!e&&(r||n||!i);if(o){t.someProp("transformPastedText",(i=>{e=i(e,n||r,t)}));if(n){l=new m(u.from(t.state.schema.text(e.replace(/\r\n?/g,"\n"))),0,0);t.someProp("transformPasted",(e=>{l=e(l,t,true)}));return l}let i=t.someProp("clipboardTextParser",(i=>i(e,s,r,t)));if(i){l=i}else{let i=s.marks();let{schema:r}=t.state,n=St.fromSchema(r);h=document.createElement("div");e.split(/(?:\r\n?|\n)+/).forEach((t=>{let e=h.appendChild(document.createElement("p"));if(t)e.appendChild(n.serializeNode(r.text(t,i)))}))}}else{t.someProp("transformPastedHTML",(e=>{i=e(i,t)}));h=Gs(i);if(Li)Xs(h)}let f=h&&h.querySelector("[data-pm-slice]");let a=f&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(f.getAttribute("data-pm-slice")||"");if(a&&a[3])for(let t=+a[3];t>0;t--){let t=h.firstChild;while(t&&t.nodeType!=1)t=t.nextSibling;if(!t)break;h=t}if(!l){let e=t.someProp("clipboardParser")||t.someProp("domParser")||ut.fromSchema(t.state.schema);l=e.parseSlice(h,{preserveWhitespace:!!(o||a),context:s,ruleFromNode(t){if(t.nodeName=="BR"&&!t.nextSibling&&t.parentNode&&!Us.test(t.parentNode.nodeName))return{ignore:true};return null}})}if(a){l=Ys(Ws(l,+a[1],+a[2]),a[4])}else{l=m.maxOpen(js(l.content,s),true);if(l.openStart||l.openEnd){let t=0,e=0;for(let e=l.content.firstChild;t<l.openStart&&!e.type.spec.isolating;t++,e=e.firstChild){}for(let t=l.content.lastChild;e<l.openEnd&&!t.type.spec.isolating;e++,t=t.lastChild){}l=Ws(l,t,e)}}t.someProp("transformPasted",(e=>{l=e(l,t,o)}));return l}const Us=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function js(t,e){if(t.childCount<2)return t;for(let i=e.depth;i>=0;i--){let r=e.node(i);let s=r.contentMatchAt(e.index(i));let n,h=[];t.forEach((t=>{if(!h)return;let e=s.findWrapping(t.type),i;if(!e)return h=null;if(i=h.length&&n.length&&_s(e,n,t,h[h.length-1],0)){h[h.length-1]=i}else{if(h.length)h[h.length-1]=zs(h[h.length-1],n.length);let i=$s(t,e);h.push(i);s=s.matchType(i.type);n=e}}));if(h)return u.from(h)}return t}function $s(t,e,i=0){for(let r=e.length-1;r>=i;r--)t=e[r].create(null,u.from(t));return t}function _s(t,e,i,r,s){if(s<t.length&&s<e.length&&t[s]==e[s]){let n=_s(t,e,i,r.lastChild,s+1);if(n)return r.copy(r.content.replaceChild(r.childCount-1,n));let h=r.contentMatchAt(r.childCount);if(h.matchType(s==t.length-1?i.type:t[s+1]))return r.copy(r.content.append(u.from($s(i,t,s+1))))}}function zs(t,e){if(e==0)return t;let i=t.content.replaceChild(t.childCount-1,zs(t.lastChild,e-1));let r=t.contentMatchAt(t.childCount).fillBefore(u.empty,true);return t.copy(i.append(r))}function Js(t,e,i,r,s,n){let h=e<0?t.firstChild:t.lastChild,l=h.content;if(t.childCount>1)n=0;if(s<r-1)l=Js(l,e,i,r,s+1,n);if(s>=i)l=e<0?h.contentMatchAt(0).fillBefore(l,n<=s).append(l):l.append(h.contentMatchAt(h.childCount).fillBefore(u.empty,true));return t.replaceChild(e<0?0:t.childCount-1,h.copy(l))}function Ws(t,e,i){if(e<t.openStart)t=new m(Js(t.content,-1,e,t.openStart,0,t.openEnd),e,t.openEnd);if(i<t.openEnd)t=new m(Js(t.content,1,i,t.openEnd,0,0),t.openStart,i);return t}const Qs={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};let Ls=null;function Ks(){return Ls||(Ls=document.implementation.createHTMLDocument("title"))}let Hs=null;function qs(t){let e=window.trustedTypes;if(!e)return t;if(!Hs)Hs=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t});return Hs.createHTML(t)}function Gs(t){let e=/^(\s*<meta [^>]*>)*/.exec(t);if(e)t=t.slice(e[0].length);let i=Ks().createElement("div");let r=/<([a-z][^>\s]+)/i.exec(t),s;if(s=r&&Qs[r[1].toLowerCase()])t=s.map((t=>"<"+t+">")).join("")+t+s.map((t=>"</"+t+">")).reverse().join("");i.innerHTML=qs(t);if(s)for(let t=0;t<s.length;t++)i=i.querySelector(s[t])||i;return i}function Xs(t){let e=t.querySelectorAll(ji?"span:not([class]):not([style])":"span.Apple-converted-space");for(let i=0;i<e.length;i++){let r=e[i];if(r.childNodes.length==1&&r.textContent==" "&&r.parentNode)r.parentNode.replaceChild(t.ownerDocument.createTextNode(" "),r)}}function Ys(t,e){if(!t.size)return t;let i=t.content.firstChild.type.schema,r;try{r=JSON.parse(e)}catch(e){return t}let{content:s,openStart:n,openEnd:h}=t;for(let t=r.length-2;t>=0;t-=2){let e=i.nodes[r[t]];if(!e||e.hasRequiredAttrs())break;s=u.from(e.create(r[t+1],s));n++;h++}return new m(s,n,h)}const Vs={};const Zs={};const tn={touchstart:true,touchmove:true};class en{constructor(){this.shiftKey=false;this.mouseDown=null;this.lastKeyCode=null;this.lastKeyCodeTime=0;this.lastClick={time:0,x:0,y:0,type:"",button:0};this.lastSelectionOrigin=null;this.lastSelectionTime=0;this.lastIOSEnter=0;this.lastIOSEnterFallbackTimeout=-1;this.lastFocus=0;this.lastTouch=0;this.lastChromeDelete=0;this.composing=false;this.compositionNode=null;this.composingTimeout=-1;this.compositionNodes=[];this.compositionEndedAt=-2e8;this.compositionID=1;this.compositionPendingChanges=0;this.domChangeCount=0;this.eventHandlers=Object.create(null);this.hideSelectionGuard=null}}function rn(t){for(let e in Vs){let i=Vs[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=e=>{if(on(t,e)&&!ln(t,e)&&(t.editable||!(e.type in Zs)))i(t,e)},tn[e]?{passive:true}:undefined)}if(_i)t.dom.addEventListener("input",(()=>null));hn(t)}function sn(t,e){t.input.lastSelectionOrigin=e;t.input.lastSelectionTime=Date.now()}function nn(t){t.domObserver.stop();for(let e in t.input.eventHandlers)t.dom.removeEventListener(e,t.input.eventHandlers[e]);clearTimeout(t.input.composingTimeout);clearTimeout(t.input.lastIOSEnterFallbackTimeout)}function hn(t){t.someProp("handleDOMEvents",(e=>{for(let i in e)if(!t.input.eventHandlers[i])t.dom.addEventListener(i,t.input.eventHandlers[i]=e=>ln(t,e))}))}function ln(t,e){return t.someProp("handleDOMEvents",(i=>{let r=i[e.type];return r?r(t,e)||e.defaultPrevented:false}))}function on(t,e){if(!e.bubbles)return true;if(e.defaultPrevented)return false;for(let i=e.target;i!=t.dom;i=i.parentNode)if(!i||i.nodeType==11||i.pmViewDesc&&i.pmViewDesc.stopEvent(e))return false;return true}function fn(t,e){if(!ln(t,e)&&Vs[e.type]&&(t.editable||!(e.type in Zs)))Vs[e.type](t,e)}Zs.keydown=(t,e)=>{let i=e;t.input.shiftKey=i.keyCode==16||i.shiftKey;if(kn(t,i))return;t.input.lastKeyCode=i.keyCode;t.input.lastKeyCodeTime=Date.now();if(Qi&&ji&&i.keyCode==13)return;if(i.keyCode!=229)t.domObserver.forceFlush();if(zi&&i.keyCode==13&&!i.ctrlKey&&!i.altKey&&!i.metaKey){let e=Date.now();t.input.lastIOSEnter=e;t.input.lastIOSEnterFallbackTimeout=setTimeout((()=>{if(t.input.lastIOSEnter==e){t.someProp("handleKeyDown",(e=>e(t,xi(13,"Enter"))));t.input.lastIOSEnter=0}}),200)}else if(t.someProp("handleKeyDown",(e=>e(t,i)))||Ns(t,i)){i.preventDefault()}else{sn(t,"key")}};Zs.keyup=(t,e)=>{if(e.keyCode==16)t.input.shiftKey=false};Zs.keypress=(t,e)=>{let i=e;if(kn(t,i)||!i.charCode||i.ctrlKey&&!i.altKey||Ji&&i.metaKey)return;if(t.someProp("handleKeyPress",(e=>e(t,i)))){i.preventDefault();return}let r=t.state.selection;if(!(r instanceof Qe)||!r.$from.sameParent(r.$to)){let e=String.fromCharCode(i.charCode);let s=()=>t.state.tr.insertText(e).scrollIntoView();if(!/[\r\n]/.test(e)&&!t.someProp("handleTextInput",(i=>i(t,r.$from.pos,r.$to.pos,e,s))))t.dispatch(s());i.preventDefault()}};function un(t){return{left:t.clientX,top:t.clientY}}function an(t,e){let i=e.x-t.clientX,r=e.y-t.clientY;return i*i+r*r<100}function cn(t,e,i,r,s){if(r==-1)return false;let n=t.state.doc.resolve(r);for(let r=n.depth+1;r>0;r--){if(t.someProp(e,(e=>r>n.depth?e(t,i,n.nodeAfter,n.before(r),s,true):e(t,i,n.node(r),n.before(r),s,false))))return true}return false}function dn(t,e,i){if(!t.focused)t.focus();if(t.state.selection.eq(e))return;let r=t.state.tr.setSelection(e);r.setMeta("pointer",true);t.dispatch(r)}function pn(t,e){if(e==-1)return false;let i=t.state.doc.resolve(e),r=i.nodeAfter;if(r&&r.isAtom&&Ke.isSelectable(r)){dn(t,new Ke(i));return true}return false}function wn(t,e){if(e==-1)return false;let i=t.state.selection,r,s;if(i instanceof Ke)r=i.node;let n=t.state.doc.resolve(e);for(let t=n.depth+1;t>0;t--){let e=t>n.depth?n.nodeAfter:n.node(t);if(Ke.isSelectable(e)){if(r&&i.$from.depth>0&&t>=i.$from.depth&&n.before(i.$from.depth+1)==i.$from.pos)s=n.before(i.$from.depth);else s=n.before(t);break}}if(s!=null){dn(t,Ke.create(t.state.doc,s));return true}else{return false}}function mn(t,e,i,r,s){return cn(t,"handleClickOn",e,i,r)||t.someProp("handleClick",(i=>i(t,e,r)))||(s?wn(t,i):pn(t,i))}function gn(t,e,i,r){return cn(t,"handleDoubleClickOn",e,i,r)||t.someProp("handleDoubleClick",(i=>i(t,e,r)))}function bn(t,e,i,r){return cn(t,"handleTripleClickOn",e,i,r)||t.someProp("handleTripleClick",(i=>i(t,e,r)))||vn(t,i,r)}function vn(t,e,i){if(i.button!=0)return false;let r=t.state.doc;if(e==-1){if(r.inlineContent){dn(t,Qe.create(r,0,r.content.size));return true}return false}let s=r.resolve(e);for(let e=s.depth+1;e>0;e--){let i=e>s.depth?s.nodeAfter:s.node(e);let n=s.before(e);if(i.inlineContent)dn(t,Qe.create(r,n+1,n+1+i.content.size));else if(Ke.isSelectable(i))dn(t,Ke.create(r,n));else continue;return true}}function yn(t){return Tn(t)}const Mn=Ji?"metaKey":"ctrlKey";Vs.mousedown=(t,e)=>{let i=e;t.input.shiftKey=i.shiftKey;let r=yn(t);let s=Date.now(),n="singleClick";if(s-t.input.lastClick.time<500&&an(i,t.input.lastClick)&&!i[Mn]&&t.input.lastClick.button==i.button){if(t.input.lastClick.type=="singleClick")n="doubleClick";else if(t.input.lastClick.type=="doubleClick")n="tripleClick"}t.input.lastClick={time:s,x:i.clientX,y:i.clientY,type:n,button:i.button};let h=t.posAtCoords(un(i));if(!h)return;if(n=="singleClick"){if(t.input.mouseDown)t.input.mouseDown.done();t.input.mouseDown=new An(t,h,i,!!r)}else if((n=="doubleClick"?gn:bn)(t,h.pos,h.inside,i)){i.preventDefault()}else{sn(t,"pointer")}};class An{constructor(t,e,i,r){this.view=t;this.pos=e;this.event=i;this.flushed=r;this.delayedSelectionSync=false;this.mightDrag=null;this.startDoc=t.state.doc;this.selectNode=!!i[Mn];this.allowDefault=i.shiftKey;let s,n;if(e.inside>-1){s=t.state.doc.nodeAt(e.inside);n=e.inside}else{let i=t.state.doc.resolve(e.pos);s=i.parent;n=i.depth?i.before():0}const h=r?null:i.target;const l=h?t.docView.nearestDesc(h,true):null;this.target=l&&l.nodeDOM.nodeType==1?l.nodeDOM:null;let{selection:o}=t.state;if(i.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==false||o instanceof Ke&&o.from<=n&&o.to>n)this.mightDrag={node:s,pos:n,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Bi&&!this.target.hasAttribute("contentEditable"))};if(this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)){this.view.domObserver.stop();if(this.mightDrag.addAttr)this.target.draggable=true;if(this.mightDrag.setUneditable)setTimeout((()=>{if(this.view.input.mouseDown==this)this.target.setAttribute("contentEditable","false")}),20);this.view.domObserver.start()}t.root.addEventListener("mouseup",this.up=this.up.bind(this));t.root.addEventListener("mousemove",this.move=this.move.bind(this));sn(t,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up);this.view.root.removeEventListener("mousemove",this.move);if(this.mightDrag&&this.target){this.view.domObserver.stop();if(this.mightDrag.addAttr)this.target.removeAttribute("draggable");if(this.mightDrag.setUneditable)this.target.removeAttribute("contentEditable");this.view.domObserver.start()}if(this.delayedSelectionSync)setTimeout((()=>is(this.view)));this.view.input.mouseDown=null}up(t){this.done();if(!this.view.dom.contains(t.target))return;let e=this.pos;if(this.view.state.doc!=this.startDoc)e=this.view.posAtCoords(un(t));this.updateAllowDefault(t);if(this.allowDefault||!e){sn(this.view,"pointer")}else if(mn(this.view,e.pos,e.inside,t,this.selectNode)){t.preventDefault()}else if(t.button==0&&(this.flushed||_i&&this.mightDrag&&!this.mightDrag.node.isAtom||ji&&!this.view.state.selection.visible&&Math.min(Math.abs(e.pos-this.view.state.selection.from),Math.abs(e.pos-this.view.state.selection.to))<=2)){dn(this.view,_e.near(this.view.state.doc.resolve(e.pos)));t.preventDefault()}else{sn(this.view,"pointer")}}move(t){this.updateAllowDefault(t);sn(this.view,"pointer");if(t.buttons==0)this.done()}updateAllowDefault(t){if(!this.allowDefault&&(Math.abs(this.event.x-t.clientX)>4||Math.abs(this.event.y-t.clientY)>4))this.allowDefault=true}}Vs.touchstart=t=>{t.input.lastTouch=Date.now();yn(t);sn(t,"pointer")};Vs.touchmove=t=>{t.input.lastTouch=Date.now();sn(t,"pointer")};Vs.contextmenu=t=>yn(t);function kn(t,e){if(t.composing)return true;if(_i&&Math.abs(e.timeStamp-t.input.compositionEndedAt)<500){t.input.compositionEndedAt=-2e8;return true}return false}const Sn=Qi?5e3:-1;Zs.compositionstart=Zs.compositionupdate=t=>{if(!t.composing){t.domObserver.flush();let{state:e}=t,i=e.selection.$to;if(e.selection instanceof Qe&&(e.storedMarks||!i.textOffset&&i.parentOffset&&i.nodeBefore.marks.some((t=>t.type.spec.inclusive===false)))){t.markCursor=t.state.storedMarks||i.marks();Tn(t,true);t.markCursor=null}else{Tn(t,!e.selection.empty);if(Bi&&e.selection.empty&&i.parentOffset&&!i.textOffset&&i.nodeBefore.marks.length){let e=t.domSelectionRange();for(let i=e.focusNode,r=e.focusOffset;i&&i.nodeType==1&&r!=0;){let e=r<0?i.lastChild:i.childNodes[r-1];if(!e)break;if(e.nodeType==3){let i=t.domSelection();if(i)i.collapse(e,e.nodeValue.length);break}else{i=e;r=-1}}}}t.input.composing=true}xn(t,Sn)};Zs.compositionend=(t,e)=>{if(t.composing){t.input.composing=false;t.input.compositionEndedAt=e.timeStamp;t.input.compositionPendingChanges=t.domObserver.pendingRecords().length?t.input.compositionID:0;t.input.compositionNode=null;if(t.input.compositionPendingChanges)Promise.resolve().then((()=>t.domObserver.flush()));t.input.compositionID++;xn(t,20)}};function xn(t,e){clearTimeout(t.input.composingTimeout);if(e>-1)t.input.composingTimeout=setTimeout((()=>Tn(t)),e)}function En(t){if(t.composing){t.input.composing=false;t.input.compositionEndedAt=Dn()}while(t.input.compositionNodes.length>0)t.input.compositionNodes.pop().markParentsDirty()}function On(t){let e=t.domSelectionRange();if(!e.focusNode)return null;let i=yi(e.focusNode,e.focusOffset);let r=Mi(e.focusNode,e.focusOffset);if(i&&r&&i!=r){let e=r.pmViewDesc,s=t.domObserver.lastChangedTextNode;if(i==s||r==s)return s;if(!e||!e.isText(r.nodeValue)){return r}else if(t.input.compositionNode==r){let t=i.pmViewDesc;if(!(!t||!t.isText(i.nodeValue)))return r}}return i||r}function Dn(){let t=document.createEvent("Event");t.initEvent("event",true,true);return t.timeStamp}function Tn(t,e=false){if(Qi&&t.domObserver.flushingSoon>=0)return;t.domObserver.forceFlush();En(t);if(e||t.docView&&t.docView.dirty){let i=ts(t),r=t.state.selection;if(i&&!i.eq(r))t.dispatch(t.state.tr.setSelection(i));else if((t.markCursor||e)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent)t.dispatch(t.state.tr.deleteSelection());else t.updateState(t.state);return true}return false}function Rn(t,e){if(!t.dom.parentNode)return;let i=t.dom.parentNode.appendChild(document.createElement("div"));i.appendChild(e);i.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),s=document.createRange();s.selectNodeContents(e);t.dom.blur();r.removeAllRanges();r.addRange(s);setTimeout((()=>{if(i.parentNode)i.parentNode.removeChild(i);t.focus()}),50)}const Cn=Ni&&Fi<15||zi&&Ki<604;Vs.copy=Zs.cut=(t,e)=>{let i=e;let r=t.state.selection,s=i.type=="cut";if(r.empty)return;let n=Cn?null:i.clipboardData;let h=r.content(),{dom:l,text:o}=Fs(t,h);if(n){i.preventDefault();n.clearData();n.setData("text/html",l.innerHTML);n.setData("text/plain",o)}else{Rn(t,l)}if(s)t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function Pn(t){return t.openStart==0&&t.openEnd==0&&t.content.childCount==1?t.content.firstChild:null}function In(t,e){if(!t.dom.parentNode)return;let i=t.input.shiftKey||t.state.selection.$from.parent.type.spec.code;let r=t.dom.parentNode.appendChild(document.createElement(i?"textarea":"div"));if(!i)r.contentEditable="true";r.style.cssText="position: fixed; left: -10000px; top: 10px";r.focus();let s=t.input.shiftKey&&t.input.lastKeyCode!=45;setTimeout((()=>{t.focus();if(r.parentNode)r.parentNode.removeChild(r);if(i)Nn(t,r.value,null,s,e);else Nn(t,r.textContent,r.innerHTML,s,e)}),50)}function Nn(t,e,i,r,s){let n=Bs(t,e,i,r,t.state.selection.$from);if(t.someProp("handlePaste",(e=>e(t,s,n||m.empty))))return true;if(!n)return false;let h=Pn(n);let l=h?t.state.tr.replaceSelectionWith(h,r):t.state.tr.replaceSelection(n);t.dispatch(l.scrollIntoView().setMeta("paste",true).setMeta("uiEvent","paste"));return true}function Fn(t){let e=t.getData("text/plain")||t.getData("Text");if(e)return e;let i=t.getData("text/uri-list");return i?i.replace(/\r?\n/g," "):""}Zs.paste=(t,e)=>{let i=e;if(t.composing&&!Qi)return;let r=Cn?null:i.clipboardData;let s=t.input.shiftKey&&t.input.lastKeyCode!=45;if(r&&Nn(t,Fn(r),r.getData("text/html"),s,i))i.preventDefault();else In(t,i)};class Bn{constructor(t,e,i){this.slice=t;this.move=e;this.node=i}}const Un=Ji?"altKey":"ctrlKey";function jn(t,e){let i=t.someProp("dragCopies",(t=>!t(e)));return i!=null?i:!e[Un]}Vs.dragstart=(t,e)=>{let i=e;let r=t.input.mouseDown;if(r)r.done();if(!i.dataTransfer)return;let s=t.state.selection;let n=s.empty?null:t.posAtCoords(un(i));let h;if(n&&n.pos>=s.from&&n.pos<=(s instanceof Ke?s.to-1:s.to));else if(r&&r.mightDrag){h=Ke.create(t.state.doc,r.mightDrag.pos)}else if(i.target&&i.target.nodeType==1){let e=t.docView.nearestDesc(i.target,true);if(e&&e.node.type.spec.draggable&&e!=t.docView)h=Ke.create(t.state.doc,e.posBefore)}let l=(h||t.state.selection).content();let{dom:o,text:f,slice:u}=Fs(t,l);if(!i.dataTransfer.files.length||!ji||$i>120)i.dataTransfer.clearData();i.dataTransfer.setData(Cn?"Text":"text/html",o.innerHTML);i.dataTransfer.effectAllowed="copyMove";if(!Cn)i.dataTransfer.setData("text/plain",f);t.dragging=new Bn(u,jn(t,i),h)};Vs.dragend=t=>{let e=t.dragging;window.setTimeout((()=>{if(t.dragging==e)t.dragging=null}),50)};Zs.dragover=Zs.dragenter=(t,e)=>e.preventDefault();Zs.drop=(t,e)=>{let i=e;let r=t.dragging;t.dragging=null;if(!i.dataTransfer)return;let s=t.posAtCoords(un(i));if(!s)return;let n=t.state.doc.resolve(s.pos);let h=r&&r.slice;if(h){t.someProp("transformPasted",(e=>{h=e(h,t,false)}))}else{h=Bs(t,Fn(i.dataTransfer),Cn?null:i.dataTransfer.getData("text/html"),false,n)}let l=!!(r&&jn(t,i));if(t.someProp("handleDrop",(e=>e(t,i,h||m.empty,l)))){i.preventDefault();return}if(!h)return;i.preventDefault();let o=h?ve(t.state.doc,n.pos,h):n.pos;if(o==null)o=n.pos;let f=t.state.tr;if(l){let{node:t}=r;if(t)t.replace(f);else f.deleteSelection()}let u=f.mapping.map(o);let a=h.openStart==0&&h.openEnd==0&&h.content.childCount==1;let c=f.doc;if(a)f.replaceRangeWith(u,u,h.content.firstChild);else f.replaceRange(u,u,h);if(f.doc.eq(c))return;let d=f.doc.resolve(u);if(a&&Ke.isSelectable(h.content.firstChild)&&d.nodeAfter&&d.nodeAfter.sameMarkup(h.content.firstChild)){f.setSelection(new Ke(d))}else{let e=f.mapping.map(o);f.mapping.maps[f.mapping.maps.length-1].forEach(((t,i,r,s)=>e=s));f.setSelection(cs(t,d,f.doc.resolve(e)))}t.focus();t.dispatch(f.setMeta("uiEvent","drop"))};Vs.focus=t=>{t.input.lastFocus=Date.now();if(!t.focused){t.domObserver.stop();t.dom.classList.add("ProseMirror-focused");t.domObserver.start();t.focused=true;setTimeout((()=>{if(t.docView&&t.hasFocus()&&!t.domObserver.currentSelection.eq(t.domSelectionRange()))is(t)}),20)}};Vs.blur=(t,e)=>{let i=e;if(t.focused){t.domObserver.stop();t.dom.classList.remove("ProseMirror-focused");t.domObserver.start();if(i.relatedTarget&&t.dom.contains(i.relatedTarget))t.domObserver.currentSelection.clear();t.focused=false}};Vs.beforeinput=(t,e)=>{let i=e;if(ji&&Qi&&i.inputType=="deleteContentBackward"){t.domObserver.flushSoon();let{domChangeCount:e}=t.input;setTimeout((()=>{if(t.input.domChangeCount!=e)return;t.dom.blur();t.focus();if(t.someProp("handleKeyDown",(e=>e(t,xi(8,"Backspace")))))return;let{$cursor:i}=t.state.selection;if(i&&i.pos>0)t.dispatch(t.state.tr.delete(i.pos-1,i.pos).scrollIntoView())}),50)}};for(let t in Zs)Vs[t]=Zs[t];function $n(t,e){if(t==e)return true;for(let i in t)if(t[i]!==e[i])return false;for(let i in e)if(!(i in t))return false;return true}class _n{constructor(t,e){this.toDOM=t;this.spec=e||Ln;this.side=this.spec.side||0}map(t,e,i,r){let{pos:s,deleted:n}=t.mapResult(e.from+r,this.side<0?-1:1);return n?null:new Wn(s-i,s-i,this)}valid(){return true}eq(t){return this==t||t instanceof _n&&(this.spec.key&&this.spec.key==t.spec.key||this.toDOM==t.toDOM&&$n(this.spec,t.spec))}destroy(t){if(this.spec.destroy)this.spec.destroy(t)}}class zn{constructor(t,e){this.attrs=t;this.spec=e||Ln}map(t,e,i,r){let s=t.map(e.from+r,this.spec.inclusiveStart?-1:1)-i;let n=t.map(e.to+r,this.spec.inclusiveEnd?1:-1)-i;return s>=n?null:new Wn(s,n,this)}valid(t,e){return e.from<e.to}eq(t){return this==t||t instanceof zn&&$n(this.attrs,t.attrs)&&$n(this.spec,t.spec)}static is(t){return t.type instanceof zn}destroy(){}}class Jn{constructor(t,e){this.attrs=t;this.spec=e||Ln}map(t,e,i,r){let s=t.mapResult(e.from+r,1);if(s.deleted)return null;let n=t.mapResult(e.to+r,-1);if(n.deleted||n.pos<=s.pos)return null;return new Wn(s.pos-i,n.pos-i,this)}valid(t,e){let{index:i,offset:r}=t.content.findIndex(e.from),s;return r==e.from&&!(s=t.child(i)).isText&&r+s.nodeSize==e.to}eq(t){return this==t||t instanceof Jn&&$n(this.attrs,t.attrs)&&$n(this.spec,t.spec)}destroy(){}}class Wn{constructor(t,e,i){this.from=t;this.to=e;this.type=i}copy(t,e){return new Wn(t,e,this.type)}eq(t,e=0){return this.type.eq(t.type)&&this.from+e==t.from&&this.to+e==t.to}map(t,e,i){return this.type.map(t,this,e,i)}static widget(t,e,i){return new Wn(t,t,new _n(e,i))}static inline(t,e,i,r){return new Wn(t,e,new zn(i,r))}static node(t,e,i,r){return new Wn(t,e,new Jn(i,r))}get spec(){return this.type.spec}get inline(){return this.type instanceof zn}get widget(){return this.type instanceof _n}}const Qn=[],Ln={};class Kn{constructor(t,e){this.local=t.length?t:Qn;this.children=e.length?e:Qn}static create(t,e){return e.length?th(e,t,0,Ln):Hn}find(t,e,i){let r=[];this.findInner(t==null?0:t,e==null?1e9:e,r,0,i);return r}findInner(t,e,i,r,s){for(let n=0;n<this.local.length;n++){let h=this.local[n];if(h.from<=e&&h.to>=t&&(!s||s(h.spec)))i.push(h.copy(h.from+r,h.to+r))}for(let n=0;n<this.children.length;n+=3){if(this.children[n]<e&&this.children[n+1]>t){let h=this.children[n]+1;this.children[n+2].findInner(t-h,e-h,i,r+h,s)}}}map(t,e,i){if(this==Hn||t.maps.length==0)return this;return this.mapInner(t,e,0,0,i||Ln)}mapInner(t,e,i,r,s){let n;for(let h=0;h<this.local.length;h++){let l=this.local[h].map(t,i,r);if(l&&l.type.valid(e,l))(n||(n=[])).push(l);else if(s.onRemove)s.onRemove(this.local[h].spec)}if(this.children.length)return Gn(this.children,n||[],t,e,i,r,s);else return n?new Kn(n.sort(eh),Qn):Hn}add(t,e){if(!e.length)return this;if(this==Hn)return Kn.create(t,e);return this.addInner(t,e,0)}addInner(t,e,i){let r,s=0;t.forEach(((t,n)=>{let h=n+i,l;if(!(l=Vn(e,t,h)))return;if(!r)r=this.children.slice();while(s<r.length&&r[s]<n)s+=3;if(r[s]==n)r[s+2]=r[s+2].addInner(t,l,h+1);else r.splice(s,0,n,n+t.nodeSize,th(l,t,h+1,Ln));s+=3}));let n=Xn(s?Zn(e):e,-i);for(let e=0;e<n.length;e++)if(!n[e].type.valid(t,n[e]))n.splice(e--,1);return new Kn(n.length?this.local.concat(n).sort(eh):this.local,r||this.children)}remove(t){if(t.length==0||this==Hn)return this;return this.removeInner(t,0)}removeInner(t,e){let i=this.children,r=this.local;for(let r=0;r<i.length;r+=3){let s;let n=i[r]+e,h=i[r+1]+e;for(let e=0,i;e<t.length;e++)if(i=t[e]){if(i.from>n&&i.to<h){t[e]=null;(s||(s=[])).push(i)}}if(!s)continue;if(i==this.children)i=this.children.slice();let l=i[r+2].removeInner(s,n+1);if(l!=Hn){i[r+2]=l}else{i.splice(r,3);r-=3}}if(r.length)for(let i=0,s;i<t.length;i++)if(s=t[i]){for(let t=0;t<r.length;t++)if(r[t].eq(s,e)){if(r==this.local)r=this.local.slice();r.splice(t--,1)}}if(i==this.children&&r==this.local)return this;return r.length||i.length?new Kn(r,i):Hn}forChild(t,e){if(this==Hn)return this;if(e.isLeaf)return Kn.empty;let i,r;for(let e=0;e<this.children.length;e+=3)if(this.children[e]>=t){if(this.children[e]==t)i=this.children[e+2];break}let s=t+1,n=s+e.content.size;for(let t=0;t<this.local.length;t++){let e=this.local[t];if(e.from<n&&e.to>s&&e.type instanceof zn){let t=Math.max(s,e.from)-s,i=Math.min(n,e.to)-s;if(t<i)(r||(r=[])).push(e.copy(t,i))}}if(r){let t=new Kn(r.sort(eh),Qn);return i?new qn([t,i]):t}return i||Hn}eq(t){if(this==t)return true;if(!(t instanceof Kn)||this.local.length!=t.local.length||this.children.length!=t.children.length)return false;for(let e=0;e<this.local.length;e++)if(!this.local[e].eq(t.local[e]))return false;for(let e=0;e<this.children.length;e+=3)if(this.children[e]!=t.children[e]||this.children[e+1]!=t.children[e+1]||!this.children[e+2].eq(t.children[e+2]))return false;return true}locals(t){return ih(this.localsInner(t))}localsInner(t){if(this==Hn)return Qn;if(t.inlineContent||!this.local.some(zn.is))return this.local;let e=[];for(let t=0;t<this.local.length;t++){if(!(this.local[t].type instanceof zn))e.push(this.local[t])}return e}forEachSet(t){t(this)}}Kn.empty=new Kn([],[]);Kn.removeOverlap=ih;const Hn=Kn.empty;class qn{constructor(t){this.members=t}map(t,e){const i=this.members.map((i=>i.map(t,e,Ln)));return qn.from(i)}forChild(t,e){if(e.isLeaf)return Kn.empty;let i=[];for(let r=0;r<this.members.length;r++){let s=this.members[r].forChild(t,e);if(s==Hn)continue;if(s instanceof qn)i=i.concat(s.members);else i.push(s)}return qn.from(i)}eq(t){if(!(t instanceof qn)||t.members.length!=this.members.length)return false;for(let e=0;e<this.members.length;e++)if(!this.members[e].eq(t.members[e]))return false;return true}locals(t){let e,i=true;for(let r=0;r<this.members.length;r++){let s=this.members[r].localsInner(t);if(!s.length)continue;if(!e){e=s}else{if(i){e=e.slice();i=false}for(let t=0;t<s.length;t++)e.push(s[t])}}return e?ih(i?e:e.sort(eh)):Qn}static from(t){switch(t.length){case 0:return Hn;case 1:return t[0];default:return new qn(t.every((t=>t instanceof Kn))?t:t.reduce(((t,e)=>t.concat(e instanceof Kn?e:e.members)),[]))}}forEachSet(t){for(let e=0;e<this.members.length;e++)this.members[e].forEachSet(t)}}function Gn(t,e,i,r,s,n,h){let l=t.slice();for(let t=0,e=n;t<i.maps.length;t++){let r=0;i.maps[t].forEach(((t,i,s,n)=>{let h=n-s-(i-t);for(let s=0;s<l.length;s+=3){let n=l[s+1];if(n<0||t>n+e-r)continue;let o=l[s]+e-r;if(i>=o){l[s+1]=t<=o?-2:-1}else if(t>=e&&h){l[s]+=h;l[s+1]+=h}}r+=h}));e=i.maps[t].map(e,-1)}let o=false;for(let e=0;e<l.length;e+=3)if(l[e+1]<0){if(l[e+1]==-2){o=true;l[e+1]=-1;continue}let f=i.map(t[e]+n),u=f-s;if(u<0||u>=r.content.size){o=true;continue}let a=i.map(t[e+1]+n,-1),c=a-s;let{index:d,offset:p}=r.content.findIndex(u);let w=r.maybeChild(d);if(w&&p==u&&p+w.nodeSize==c){let r=l[e+2].mapInner(i,w,f+1,t[e]+n+1,h);if(r!=Hn){l[e]=u;l[e+1]=c;l[e+2]=r}else{l[e+1]=-2;o=true}}else{o=true}}if(o){let o=Yn(l,t,e,i,s,n,h);let f=th(o,r,0,h);e=f.local;for(let t=0;t<l.length;t+=3)if(l[t+1]<0){l.splice(t,3);t-=3}for(let t=0,e=0;t<f.children.length;t+=3){let i=f.children[t];while(e<l.length&&l[e]<i)e+=3;l.splice(e,0,f.children[t],f.children[t+1],f.children[t+2])}}return new Kn(e.sort(eh),l)}function Xn(t,e){if(!e||!t.length)return t;let i=[];for(let r=0;r<t.length;r++){let s=t[r];i.push(new Wn(s.from+e,s.to+e,s.type))}return i}function Yn(t,e,i,r,s,n,h){function l(t,e){for(let n=0;n<t.local.length;n++){let l=t.local[n].map(r,s,e);if(l)i.push(l);else if(h.onRemove)h.onRemove(t.local[n].spec)}for(let i=0;i<t.children.length;i+=3)l(t.children[i+2],t.children[i]+e+1)}for(let i=0;i<t.length;i+=3)if(t[i+1]==-1)l(t[i+2],e[i]+n+1);return i}function Vn(t,e,i){if(e.isLeaf)return null;let r=i+e.nodeSize,s=null;for(let e=0,n;e<t.length;e++){if((n=t[e])&&n.from>i&&n.to<r){(s||(s=[])).push(n);t[e]=null}}return s}function Zn(t){let e=[];for(let i=0;i<t.length;i++)if(t[i]!=null)e.push(t[i]);return e}function th(t,e,i,r){let s=[],n=false;e.forEach(((e,h)=>{let l=Vn(t,e,h+i);if(l){n=true;let t=th(l,e,i+h+1,r);if(t!=Hn)s.push(h,h+e.nodeSize,t)}}));let h=Xn(n?Zn(t):t,-i).sort(eh);for(let t=0;t<h.length;t++)if(!h[t].type.valid(e,h[t])){if(r.onRemove)r.onRemove(h[t].spec);h.splice(t--,1)}return h.length||s.length?new Kn(h,s):Hn}function eh(t,e){return t.from-e.from||t.to-e.to}function ih(t){let e=t;for(let i=0;i<e.length-1;i++){let r=e[i];if(r.from!=r.to)for(let s=i+1;s<e.length;s++){let n=e[s];if(n.from==r.from){if(n.to!=r.to){if(e==t)e=t.slice();e[s]=n.copy(n.from,r.to);rh(e,s+1,n.copy(r.to,n.to))}continue}else{if(n.from<r.to){if(e==t)e=t.slice();e[i]=r.copy(r.from,n.from);rh(e,s,r.copy(n.from,r.to))}break}}}return e}function rh(t,e,i){while(e<t.length&&eh(i,t[e])>0)e++;t.splice(e,0,i)}function sh(t){let e=[];t.someProp("decorations",(i=>{let r=i(t.state);if(r&&r!=Hn)e.push(r)}));if(t.cursorWrapper)e.push(Kn.create(t.state.doc,[t.cursorWrapper.deco]));return qn.from(e)}const nh={childList:true,characterData:true,characterDataOldValue:true,attributes:true,attributeOldValue:true,subtree:true};const hh=Ni&&Fi<=11;class lh{constructor(){this.anchorNode=null;this.anchorOffset=0;this.focusNode=null;this.focusOffset=0}set(t){this.anchorNode=t.anchorNode;this.anchorOffset=t.anchorOffset;this.focusNode=t.focusNode;this.focusOffset=t.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(t){return t.anchorNode==this.anchorNode&&t.anchorOffset==this.anchorOffset&&t.focusNode==this.focusNode&&t.focusOffset==this.focusOffset}}class oh{constructor(t,e){this.view=t;this.handleDOMChange=e;this.queue=[];this.flushingSoon=-1;this.observer=null;this.currentSelection=new lh;this.onCharData=null;this.suppressingSelectionUpdates=false;this.lastChangedTextNode=null;this.observer=window.MutationObserver&&new window.MutationObserver((t=>{for(let e=0;e<t.length;e++)this.queue.push(t[e]);if(Ni&&Fi<=11&&t.some((t=>t.type=="childList"&&t.removedNodes.length||t.type=="characterData"&&t.oldValue.length>t.target.nodeValue.length)))this.flushSoon();else this.flush()}));if(hh){this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue});this.flushSoon()}}this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){if(this.flushingSoon<0)this.flushingSoon=window.setTimeout((()=>{this.flushingSoon=-1;this.flush()}),20)}forceFlush(){if(this.flushingSoon>-1){window.clearTimeout(this.flushingSoon);this.flushingSoon=-1;this.flush()}}start(){if(this.observer){this.observer.takeRecords();this.observer.observe(this.view.dom,nh)}if(this.onCharData)this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData);this.connectSelection()}stop(){if(this.observer){let t=this.observer.takeRecords();if(t.length){for(let e=0;e<t.length;e++)this.queue.push(t[e]);window.setTimeout((()=>this.flush()),20)}this.observer.disconnect()}if(this.onCharData)this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData);this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=true;setTimeout((()=>this.suppressingSelectionUpdates=false),50)}onSelectionChange(){if(!ds(this.view))return;if(this.suppressingSelectionUpdates)return is(this.view);if(Ni&&Fi<=11&&!this.view.state.selection.empty){let t=this.view.domSelectionRange();if(t.focusNode&&mi(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset))return this.flushSoon()}this.flush()}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(t){if(!t.focusNode)return true;let e=new Set,i;for(let i=t.focusNode;i;i=ci(i))e.add(i);for(let r=t.anchorNode;r;r=ci(r))if(e.has(r)){i=r;break}let r=i&&this.view.docView.nearestDesc(i);if(r&&r.ignoreMutation({type:"selection",target:i.nodeType==3?i.parentNode:i})){this.setCurSelection();return true}}pendingRecords(){if(this.observer)for(let t of this.observer.takeRecords())this.queue.push(t);return this.queue}flush(){let{view:t}=this;if(!t.docView||this.flushingSoon>-1)return;let e=this.pendingRecords();if(e.length)this.queue=[];let i=t.domSelectionRange();let r=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(i)&&ds(t)&&!this.ignoreSelectionChange(i);let s=-1,n=-1,h=false,l=[];if(t.editable){for(let t=0;t<e.length;t++){let i=this.registerMutation(e[t],l);if(i){s=s<0?i.from:Math.min(i.from,s);n=n<0?i.to:Math.max(i.to,n);if(i.typeOver)h=true}}}if(Bi&&l.length){let e=l.filter((t=>t.nodeName=="BR"));if(e.length==2){let[t,i]=e;if(t.parentNode&&t.parentNode.parentNode==i.parentNode)i.remove();else t.remove()}else{let{focusNode:i}=this.currentSelection;for(let r of e){let e=r.parentNode;if(e&&e.nodeName=="LI"&&(!i||ph(t,i)!=e))r.remove()}}}let o=null;if(s<0&&r&&t.input.lastFocus>Date.now()-200&&Math.max(t.input.lastTouch,t.input.lastClick.time)<Date.now()-300&&Si(i)&&(o=ts(t))&&o.eq(_e.near(t.state.doc.resolve(0),1))){t.input.lastFocus=0;is(t);this.currentSelection.set(i);t.scrollToSelection()}else if(s>-1||r){if(s>-1){t.docView.markDirty(s,n);ah(t)}this.handleDOMChange(s,n,h,l);if(t.docView&&t.docView.dirty)t.updateState(t.state);else if(!this.currentSelection.eq(i))is(t);this.currentSelection.set(i)}}registerMutation(t,e){if(e.indexOf(t.target)>-1)return null;let i=this.view.docView.nearestDesc(t.target);if(t.type=="attributes"&&(i==this.view.docView||t.attributeName=="contenteditable"||t.attributeName=="style"&&!t.oldValue&&!t.target.getAttribute("style")))return null;if(!i||i.ignoreMutation(t))return null;if(t.type=="childList"){for(let i=0;i<t.addedNodes.length;i++){let r=t.addedNodes[i];e.push(r);if(r.nodeType==3)this.lastChangedTextNode=r}if(i.contentDOM&&i.contentDOM!=i.dom&&!i.contentDOM.contains(t.target))return{from:i.posBefore,to:i.posAfter};let r=t.previousSibling,s=t.nextSibling;if(Ni&&Fi<=11&&t.addedNodes.length){for(let e=0;e<t.addedNodes.length;e++){let{previousSibling:i,nextSibling:n}=t.addedNodes[e];if(!i||Array.prototype.indexOf.call(t.addedNodes,i)<0)r=i;if(!n||Array.prototype.indexOf.call(t.addedNodes,n)<0)s=n}}let n=r&&r.parentNode==t.target?ai(r)+1:0;let h=i.localPosFromDOM(t.target,n,-1);let l=s&&s.parentNode==t.target?ai(s):t.target.childNodes.length;let o=i.localPosFromDOM(t.target,l,1);return{from:h,to:o}}else if(t.type=="attributes"){return{from:i.posAtStart-i.border,to:i.posAtEnd+i.border}}else{this.lastChangedTextNode=t.target;return{from:i.posAtStart,to:i.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}}}}let fh=new WeakMap;let uh=false;function ah(t){if(fh.has(t))return;fh.set(t,null);if(["normal","nowrap","pre-line"].indexOf(getComputedStyle(t.dom).whiteSpace)!==-1){t.requiresGeckoHackNode=Bi;if(uh)return;console["warn"]("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package.");uh=true}}function ch(t,e){let i=e.startContainer,r=e.startOffset;let s=e.endContainer,n=e.endOffset;let h=t.domAtPos(t.state.selection.anchor);if(mi(h.node,h.offset,s,n))[i,r,s,n]=[s,n,i,r];return{anchorNode:i,anchorOffset:r,focusNode:s,focusOffset:n}}function dh(t,e){if(e.getComposedRanges){let i=e.getComposedRanges(t.root)[0];if(i)return ch(t,i)}let i;function r(t){t.preventDefault();t.stopImmediatePropagation();i=t.getTargetRanges()[0]}t.dom.addEventListener("beforeinput",r,true);document.execCommand("indent");t.dom.removeEventListener("beforeinput",r,true);return i?ch(t,i):null}function ph(t,e){for(let i=e.parentNode;i&&i!=t.dom;i=i.parentNode){let e=t.docView.nearestDesc(i,true);if(e&&e.node.isBlock)return i}return null}function wh(t,e,i){let{node:r,fromOffset:s,toOffset:n,from:h,to:l}=t.docView.parseRange(e,i);let o=t.domSelectionRange();let f;let u=o.anchorNode;if(u&&t.dom.contains(u.nodeType==1?u:u.parentNode)){f=[{node:u,offset:o.anchorOffset}];if(!Si(o))f.push({node:o.focusNode,offset:o.focusOffset})}if(ji&&t.input.lastKeyCode===8){for(let t=n;t>s;t--){let e=r.childNodes[t-1],i=e.pmViewDesc;if(e.nodeName=="BR"&&!i){n=t;break}if(!i||i.size)break}}let a=t.state.doc;let c=t.someProp("domParser")||ut.fromSchema(t.state.schema);let d=a.resolve(h);let p=null,w=c.parse(r,{topNode:d.parent,topMatch:d.parent.contentMatchAt(d.index()),topOpen:true,from:s,to:n,preserveWhitespace:d.parent.type.whitespace=="pre"?"full":true,findPositions:f,ruleFromNode:mh,context:d});if(f&&f[0].pos!=null){let t=f[0].pos,e=f[1]&&f[1].pos;if(e==null)e=t;p={anchor:t+h,head:e+h}}return{doc:w,sel:p,from:h,to:l}}function mh(t){let e=t.pmViewDesc;if(e){return e.parseRule()}else if(t.nodeName=="BR"&&t.parentNode){if(_i&&/^(ul|ol)$/i.test(t.parentNode.nodeName)){let t=document.createElement("div");t.appendChild(document.createElement("li"));return{skip:t}}else if(t.parentNode.lastChild==t||_i&&/^(tr|table)$/i.test(t.parentNode.nodeName)){return{ignore:true}}}else if(t.nodeName=="IMG"&&t.getAttribute("mark-placeholder")){return{ignore:true}}return null}const gh=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function bh(t,e,i,r,s){let n=t.input.compositionPendingChanges||(t.composing?t.input.compositionID:0);t.input.compositionPendingChanges=0;if(e<0){let e=t.input.lastSelectionTime>Date.now()-50?t.input.lastSelectionOrigin:null;let i=ts(t,e);if(i&&!t.state.selection.eq(i)){if(ji&&Qi&&t.input.lastKeyCode===13&&Date.now()-100<t.input.lastKeyCodeTime&&t.someProp("handleKeyDown",(e=>e(t,xi(13,"Enter")))))return;let r=t.state.tr.setSelection(i);if(e=="pointer")r.setMeta("pointer",true);else if(e=="key")r.scrollIntoView();if(n)r.setMeta("composition",n);t.dispatch(r)}return}let h=t.state.doc.resolve(e);let l=h.sharedDepth(i);e=h.before(l+1);i=t.state.doc.resolve(i).after(l+1);let o=t.state.selection;let f=wh(t,e,i);let u=t.state.doc,a=u.slice(f.from,f.to);let c,d;if(t.input.lastKeyCode===8&&Date.now()-100<t.input.lastKeyCodeTime){c=t.state.selection.to;d="end"}else{c=t.state.selection.from;d="start"}t.input.lastKeyCode=null;let p=kh(a.content,f.doc.content,f.from,c,d);if(p)t.input.domChangeCount++;if((zi&&t.input.lastIOSEnter>Date.now()-225||Qi)&&s.some((t=>t.nodeType==1&&!gh.test(t.nodeName)))&&(!p||p.endA>=p.endB)&&t.someProp("handleKeyDown",(e=>e(t,xi(13,"Enter"))))){t.input.lastIOSEnter=0;return}if(!p){if(r&&o instanceof Qe&&!o.empty&&o.$head.sameParent(o.$anchor)&&!t.composing&&!(f.sel&&f.sel.anchor!=f.sel.head)){p={start:o.from,endA:o.to,endB:o.to}}else{if(f.sel){let e=vh(t,t.state.doc,f.sel);if(e&&!e.eq(t.state.selection)){let i=t.state.tr.setSelection(e);if(n)i.setMeta("composition",n);t.dispatch(i)}}return}}if(t.state.selection.from<t.state.selection.to&&p.start==p.endB&&t.state.selection instanceof Qe){if(p.start>t.state.selection.from&&p.start<=t.state.selection.from+2&&t.state.selection.from>=f.from){p.start=t.state.selection.from}else if(p.endA<t.state.selection.to&&p.endA>=t.state.selection.to-2&&t.state.selection.to<=f.to){p.endB+=t.state.selection.to-p.endA;p.endA=t.state.selection.to}}if(Ni&&Fi<=11&&p.endB==p.start+1&&p.endA==p.start&&p.start>f.from&&f.doc.textBetween(p.start-f.from-1,p.start-f.from+1)=="  "){p.start--;p.endA--;p.endB--}let w=f.doc.resolveNoCache(p.start-f.from);let m=f.doc.resolveNoCache(p.endB-f.from);let g=u.resolve(p.start);let b=w.sameParent(m)&&w.parent.inlineContent&&g.end()>=p.endA;if((zi&&t.input.lastIOSEnter>Date.now()-225&&(!b||s.some((t=>t.nodeName=="DIV"||t.nodeName=="P")))||!b&&w.pos<f.doc.content.size&&(!w.sameParent(m)||!w.parent.inlineContent)&&w.pos<m.pos&&!/\S/.test(f.doc.textBetween(w.pos,m.pos,"","")))&&t.someProp("handleKeyDown",(e=>e(t,xi(13,"Enter"))))){t.input.lastIOSEnter=0;return}if(t.state.selection.anchor>p.start&&Mh(u,p.start,p.endA,w,m)&&t.someProp("handleKeyDown",(e=>e(t,xi(8,"Backspace"))))){if(Qi&&ji)t.domObserver.suppressSelectionUpdates();return}if(ji&&p.endB==p.start)t.input.lastChromeDelete=Date.now();if(Qi&&!b&&w.start()!=m.start()&&m.parentOffset==0&&w.depth==m.depth&&f.sel&&f.sel.anchor==f.sel.head&&f.sel.head==p.endA){p.endB-=2;m=f.doc.resolveNoCache(p.endB-f.from);setTimeout((()=>{t.someProp("handleKeyDown",(function(e){return e(t,xi(13,"Enter"))}))}),20)}let v=p.start,y=p.endA;let M=e=>{let i=e||t.state.tr.replace(v,y,f.doc.slice(p.start-f.from,p.endB-f.from));if(f.sel){let e=vh(t,i.doc,f.sel);if(e&&!(ji&&t.composing&&e.empty&&(p.start!=p.endB||t.input.lastChromeDelete<Date.now()-100)&&(e.head==v||e.head==i.mapping.map(y)-1)||Ni&&e.empty&&e.head==v))i.setSelection(e)}if(n)i.setMeta("composition",n);return i.scrollIntoView()};let A;if(b){if(w.pos==m.pos){if(Ni&&Fi<=11&&w.parentOffset==0){t.domObserver.suppressSelectionUpdates();setTimeout((()=>is(t)),20)}let e=M(t.state.tr.delete(v,y));let i=u.resolve(p.start).marksAcross(u.resolve(p.endA));if(i)e.ensureMarks(i);t.dispatch(e)}else if(p.endA==p.endB&&(A=yh(w.parent.content.cut(w.parentOffset,m.parentOffset),g.parent.content.cut(g.parentOffset,p.endA-g.start())))){let e=M(t.state.tr);if(A.type=="add")e.addMark(v,y,A.mark);else e.removeMark(v,y,A.mark);t.dispatch(e)}else if(w.parent.child(w.index()).isText&&w.index()==m.index()-(m.textOffset?0:1)){let e=w.parent.textBetween(w.parentOffset,m.parentOffset);let i=()=>M(t.state.tr.insertText(e,v,y));if(!t.someProp("handleTextInput",(r=>r(t,v,y,e,i))))t.dispatch(i())}else{t.dispatch(M())}}else{t.dispatch(M())}}function vh(t,e,i){if(Math.max(i.anchor,i.head)>e.content.size)return null;return cs(t,e.resolve(i.anchor),e.resolve(i.head))}function yh(t,e){let i=t.firstChild.marks,r=e.firstChild.marks;let s=i,n=r,h,l,o;for(let t=0;t<r.length;t++)s=r[t].removeFromSet(s);for(let t=0;t<i.length;t++)n=i[t].removeFromSet(n);if(s.length==1&&n.length==0){l=s[0];h="add";o=t=>t.mark(l.addToSet(t.marks))}else if(s.length==0&&n.length==1){l=n[0];h="remove";o=t=>t.mark(l.removeFromSet(t.marks))}else{return null}let f=[];for(let t=0;t<e.childCount;t++)f.push(o(e.child(t)));if(u.from(f).eq(t))return{mark:l,type:h}}function Mh(t,e,i,r,s){if(i-e<=s.pos-r.pos||Ah(r,true,false)<s.pos)return false;let n=t.resolve(e);if(!r.parent.isTextblock){let t=n.nodeAfter;return t!=null&&i==e+t.nodeSize}if(n.parentOffset<n.parent.content.size||!n.parent.isTextblock)return false;let h=t.resolve(Ah(n,true,true));if(!h.parent.isTextblock||h.pos>i||Ah(h,true,false)<i)return false;return r.parent.content.cut(r.parentOffset).eq(h.parent.content)}function Ah(t,e,i){let r=t.depth,s=e?t.end():t.pos;while(r>0&&(e||t.indexAfter(r)==t.node(r).childCount)){r--;s++;e=false}if(i){let e=t.node(r).maybeChild(t.indexAfter(r));while(e&&!e.isLeaf){e=e.firstChild;s++}}return s}function kh(t,e,i,r,s){let n=t.findDiffStart(e,i);if(n==null)return null;let{a:h,b:l}=t.findDiffEnd(e,i+t.size,i+e.size);if(s=="end"){let t=Math.max(0,n-Math.min(h,l));r-=h+t-n}if(h<n&&t.size<e.size){let t=r<=n&&r>=h?n-r:0;n-=t;if(n&&n<e.size&&Sh(e.textBetween(n-1,n+1)))n+=t?1:-1;l=n+(l-h);h=n}else if(l<n){let e=r<=n&&r>=l?n-r:0;n-=e;if(n&&n<t.size&&Sh(t.textBetween(n-1,n+1)))n+=e?1:-1;h=n+(h-l);l=n}return{start:n,endA:h,endB:l}}function Sh(t){if(t.length!=2)return false;let e=t.charCodeAt(0),i=t.charCodeAt(1);return e>=56320&&e<=57343&&i>=55296&&i<=56319}class xh{constructor(t,e){this._root=null;this.focused=false;this.trackWrites=null;this.mounted=false;this.markCursor=null;this.cursorWrapper=null;this.lastSelectedViewDesc=undefined;this.input=new en;this.prevDirectPlugins=[];this.pluginViews=[];this.requiresGeckoHackNode=false;this.dragging=null;this._props=e;this.state=e.state;this.directPlugins=e.plugins||[];this.directPlugins.forEach(Ph);this.dispatch=this.dispatch.bind(this);this.dom=t&&t.mount||document.createElement("div");if(t){if(t.appendChild)t.appendChild(this.dom);else if(typeof t=="function")t(this.dom);else if(t.mount)this.mounted=true}this.editable=Dh(this);Oh(this);this.nodeViews=Rh(this);this.docView=Nr(this.state.doc,Eh(this),sh(this),this.dom,this);this.domObserver=new oh(this,((t,e,i,r)=>bh(this,t,e,i,r)));this.domObserver.start();rn(this);this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let t=this._props;this._props={};for(let e in t)this._props[e]=t[e];this._props.state=this.state}return this._props}update(t){if(t.handleDOMEvents!=this._props.handleDOMEvents)hn(this);let e=this._props;this._props=t;if(t.plugins){t.plugins.forEach(Ph);this.directPlugins=t.plugins}this.updateStateInner(t.state,e)}setProps(t){let e={};for(let t in this._props)e[t]=this._props[t];e.state=this.state;for(let i in t)e[i]=t[i];this.update(e)}updateState(t){this.updateStateInner(t,this._props)}updateStateInner(t,e){var i;let r=this.state,s=false,n=false;if(t.storedMarks&&this.composing){En(this);n=true}this.state=t;let h=r.plugins!=t.plugins||this._props.plugins!=e.plugins;if(h||this._props.plugins!=e.plugins||this._props.nodeViews!=e.nodeViews){let t=Rh(this);if(Ch(t,this.nodeViews)){this.nodeViews=t;s=true}}if(h||e.handleDOMEvents!=this._props.handleDOMEvents){hn(this)}this.editable=Dh(this);Oh(this);let l=sh(this),o=Eh(this);let f=r.plugins!=t.plugins&&!r.doc.eq(t.doc)?"reset":t.scrollToSelection>r.scrollToSelection?"to selection":"preserve";let u=s||!this.docView.matchesNode(t.doc,o,l);if(u||!t.selection.eq(r.selection))n=true;let a=f=="preserve"&&n&&this.dom.style.overflowAnchor==null&&Yi(this);if(n){this.domObserver.stop();let e=u&&(Ni||ji)&&!this.composing&&!r.selection.empty&&!t.selection.empty&&Th(r.selection,t.selection);if(u){let i=ji?this.trackWrites=this.domSelectionRange().focusNode:null;if(this.composing)this.input.compositionNode=On(this);if(s||!this.docView.update(t.doc,o,l,this)){this.docView.updateOuterDeco(o);this.docView.destroy();this.docView=Nr(t.doc,o,l,this.dom,this)}if(i&&!this.trackWrites)e=true}if(e||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&ws(this))){is(this,e)}else{us(this,t.selection);this.domObserver.setCurSelection()}this.domObserver.start()}this.updatePluginViews(r);if(((i=this.dragging)===null||i===void 0?void 0:i.node)&&!r.doc.eq(t.doc))this.updateDraggedNode(this.dragging,r);if(f=="reset"){this.dom.scrollTop=0}else if(f=="to selection"){this.scrollToSelection()}else if(a){Zi(a)}}scrollToSelection(){let t=this.domSelectionRange().focusNode;if(!t||!this.dom.contains(t.nodeType==1?t:t.parentNode));else if(this.someProp("handleScrollToSelection",(t=>t(this))));else if(this.state.selection instanceof Ke){let e=this.docView.domAfterPos(this.state.selection.from);if(e.nodeType==1)Xi(this,e.getBoundingClientRect(),t)}else{Xi(this,this.coordsAtPos(this.state.selection.head,1),t)}}destroyPluginViews(){let t;while(t=this.pluginViews.pop())if(t.destroy)t.destroy()}updatePluginViews(t){if(!t||t.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins;this.destroyPluginViews();for(let t=0;t<this.directPlugins.length;t++){let e=this.directPlugins[t];if(e.spec.view)this.pluginViews.push(e.spec.view(this))}for(let t=0;t<this.state.plugins.length;t++){let e=this.state.plugins[t];if(e.spec.view)this.pluginViews.push(e.spec.view(this))}}else{for(let e=0;e<this.pluginViews.length;e++){let i=this.pluginViews[e];if(i.update)i.update(this,t)}}}updateDraggedNode(t,e){let i=t.node,r=-1;if(this.state.doc.nodeAt(i.from)==i.node){r=i.from}else{let t=i.from+(this.state.doc.content.size-e.doc.content.size);let s=t>0&&this.state.doc.nodeAt(t);if(s==i.node)r=t}this.dragging=new Bn(t.slice,t.move,r<0?undefined:Ke.create(this.state.doc,r))}someProp(t,e){let i=this._props&&this._props[t],r;if(i!=null&&(r=e?e(i):i))return r;for(let i=0;i<this.directPlugins.length;i++){let s=this.directPlugins[i].props[t];if(s!=null&&(r=e?e(s):s))return r}let s=this.state.plugins;if(s)for(let i=0;i<s.length;i++){let n=s[i].props[t];if(n!=null&&(r=e?e(n):n))return r}}hasFocus(){if(Ni){let t=this.root.activeElement;if(t==this.dom)return true;if(!t||!this.dom.contains(t))return false;while(t&&this.dom!=t&&this.dom.contains(t)){if(t.contentEditable=="false")return false;t=t.parentElement}return true}return this.root.activeElement==this.dom}focus(){this.domObserver.stop();if(this.editable)ir(this.dom);is(this);this.domObserver.start()}get root(){let t=this._root;if(t==null)for(let t=this.dom.parentNode;t;t=t.parentNode){if(t.nodeType==9||t.nodeType==11&&t.host){if(!t.getSelection)Object.getPrototypeOf(t).getSelection=()=>t.ownerDocument.getSelection();return this._root=t}}return t||document}updateRoot(){this._root=null}posAtCoords(t){return ur(this,t)}coordsAtPos(t,e=1){return pr(this,t,e)}domAtPos(t,e=0){return this.docView.domFromPos(t,e)}nodeDOM(t){let e=this.docView.descAt(t);return e?e.nodeDOM:null}posAtDOM(t,e,i=-1){let r=this.docView.posFromDOM(t,e,i);if(r==null)throw new RangeError("DOM position not inside the editor");return r}endOfTextblock(t,e){return Sr(this,e||this.state,t)}pasteHTML(t,e){return Nn(this,"",t,false,e||new ClipboardEvent("paste"))}pasteText(t,e){return Nn(this,t,null,true,e||new ClipboardEvent("paste"))}serializeForClipboard(t){return Fs(this,t)}destroy(){if(!this.docView)return;nn(this);this.destroyPluginViews();if(this.mounted){this.docView.update(this.state.doc,[],sh(this),this);this.dom.textContent=""}else if(this.dom.parentNode){this.dom.parentNode.removeChild(this.dom)}this.docView.destroy();this.docView=null;wi()}get isDestroyed(){return this.docView==null}dispatchEvent(t){return fn(this,t)}domSelectionRange(){let t=this.domSelection();if(!t)return{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0};return _i&&this.root.nodeType===11&&Ei(this.dom.ownerDocument)==this.dom&&dh(this,t)||t}domSelection(){return this.root.getSelection()}}xh.prototype.dispatch=function(t){let e=this._props.dispatchTransaction;if(e)e.call(this,t);else this.updateState(this.state.apply(t))};function Eh(t){let e=Object.create(null);e.class="ProseMirror";e.contenteditable=String(t.editable);t.someProp("attributes",(i=>{if(typeof i=="function")i=i(t.state);if(i)for(let t in i){if(t=="class")e.class+=" "+i[t];else if(t=="style")e.style=(e.style?e.style+";":"")+i[t];else if(!e[t]&&t!="contenteditable"&&t!="nodeName")e[t]=String(i[t])}}));if(!e.translate)e.translate="no";return[Wn.node(0,t.state.doc.content.size,e)]}function Oh(t){if(t.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator";e.setAttribute("mark-placeholder","true");e.setAttribute("alt","");t.cursorWrapper={dom:e,deco:Wn.widget(t.state.selection.from,e,{raw:true,marks:t.markCursor})}}else{t.cursorWrapper=null}}function Dh(t){return!t.someProp("editable",(e=>e(t.state)===false))}function Th(t,e){let i=Math.min(t.$anchor.sharedDepth(t.head),e.$anchor.sharedDepth(e.head));return t.$anchor.start(i)!=e.$anchor.start(i)}function Rh(t){let e=Object.create(null);function i(t){for(let i in t)if(!Object.prototype.hasOwnProperty.call(e,i))e[i]=t[i]}t.someProp("nodeViews",i);t.someProp("markViews",i);return e}function Ch(t,e){let i=0,r=0;for(let r in t){if(t[r]!=e[r])return true;i++}for(let t in e)r++;return i!=r}function Ph(t){if(t.spec.state||t.spec.filterTransaction||t.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}const Ih=["p",0],Nh=["blockquote",0],Fh=["hr"],Bh=["pre",["code",0]],Uh=["br"];const jh={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return Ih}},blockquote:{content:"block+",group:"block",defining:true,parseDOM:[{tag:"blockquote"}],toDOM(){return Nh}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return Fh}},heading:{attrs:{level:{default:1,validate:"number"}},content:"inline*",group:"block",defining:true,parseDOM:[{tag:"h1",attrs:{level:1}},{tag:"h2",attrs:{level:2}},{tag:"h3",attrs:{level:3}},{tag:"h4",attrs:{level:4}},{tag:"h5",attrs:{level:5}},{tag:"h6",attrs:{level:6}}],toDOM(t){return["h"+t.attrs.level,0]}},code_block:{content:"text*",marks:"",group:"block",code:true,defining:true,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM(){return Bh}},text:{group:"inline"},image:{inline:true,attrs:{src:{validate:"string"},alt:{default:null,validate:"string|null"},title:{default:null,validate:"string|null"}},group:"inline",draggable:true,parseDOM:[{tag:"img[src]",getAttrs(t){return{src:t.getAttribute("src"),title:t.getAttribute("title"),alt:t.getAttribute("alt")}}}],toDOM(t){let{src:e,alt:i,title:r}=t.attrs;return["img",{src:e,alt:i,title:r}]}},hard_break:{inline:true,group:"inline",selectable:false,parseDOM:[{tag:"br"}],toDOM(){return Uh}}};const $h=["em",0],_h=["strong",0],zh=["code",0];const Jh={link:{attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},inclusive:false,parseDOM:[{tag:"a[href]",getAttrs(t){return{href:t.getAttribute("href"),title:t.getAttribute("title")}}}],toDOM(t){let{href:e,title:i}=t.attrs;return["a",{href:e,title:i},0]}},em:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"},{style:"font-style=normal",clearMark:t=>t.type.name=="em"}],toDOM(){return $h}},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:t=>t.style.fontWeight!="normal"&&null},{style:"font-weight=400",clearMark:t=>t.type.name=="strong"},{style:"font-weight",getAttrs:t=>/^(bold(er)?|[5-9]\d{2,})$/.test(t)&&null}],toDOM(){return _h}},code:{code:true,parseDOM:[{tag:"code"}],toDOM(){return zh}}};const Wh=new ht({nodes:jh,marks:Jh});const Qh=["ol",0],Lh=["ul",0],Kh=["li",0];const Hh={attrs:{order:{default:1,validate:"number"}},parseDOM:[{tag:"ol",getAttrs(t){return{order:t.hasAttribute("start")?+t.getAttribute("start"):1}}}],toDOM(t){return t.attrs.order==1?Qh:["ol",{start:t.attrs.order},0]}};const qh={parseDOM:[{tag:"ul"}],toDOM(){return Lh}};const Gh={parseDOM:[{tag:"li"}],toDOM(){return Kh},defining:true};function Xh(t,e){let i={};for(let e in t)i[e]=t[e];for(let t in e)i[t]=e[t];return i}function Yh(t,e,i){return t.append({ordered_list:Xh(Hh,{content:"list_item+",group:i}),bullet_list:Xh(qh,{content:"list_item+",group:i}),list_item:Xh(Gh,{content:e})})}var Vh={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"};var Zh={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'};var tl=typeof navigator!="undefined"&&/Mac/.test(navigator.platform);var el=typeof navigator!="undefined"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var il=0;il<10;il++)Vh[48+il]=Vh[96+il]=String(il);for(var il=1;il<=24;il++)Vh[il+111]="F"+il;for(var il=65;il<=90;il++){Vh[il]=String.fromCharCode(il+32);Zh[il]=String.fromCharCode(il)}for(var rl in Vh)if(!Zh.hasOwnProperty(rl))Zh[rl]=Vh[rl];function sl(t){var e=tl&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||el&&t.shiftKey&&t.key&&t.key.length==1||t.key=="Unidentified";var i=!e&&t.key||(t.shiftKey?Zh:Vh)[t.keyCode]||t.key||"Unidentified";if(i=="Esc")i="Escape";if(i=="Del")i="Delete";if(i=="Left")i="ArrowLeft";if(i=="Up")i="ArrowUp";if(i=="Right")i="ArrowRight";if(i=="Down")i="ArrowDown";return i}const nl=typeof navigator!="undefined"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform);const hl=typeof navigator!="undefined"&&/Win/.test(navigator.platform);function ll(t){let e=t.split(/-(?!$)/),i=e[e.length-1];if(i=="Space")i=" ";let r,s,n,h;for(let t=0;t<e.length-1;t++){let i=e[t];if(/^(cmd|meta|m)$/i.test(i))h=true;else if(/^a(lt)?$/i.test(i))r=true;else if(/^(c|ctrl|control)$/i.test(i))s=true;else if(/^s(hift)?$/i.test(i))n=true;else if(/^mod$/i.test(i)){if(nl)h=true;else s=true}else throw new Error("Unrecognized modifier name: "+i)}if(r)i="Alt-"+i;if(s)i="Ctrl-"+i;if(h)i="Meta-"+i;if(n)i="Shift-"+i;return i}function ol(t){let e=Object.create(null);for(let i in t)e[ll(i)]=t[i];return e}function fl(t,e,i=true){if(e.altKey)t="Alt-"+t;if(e.ctrlKey)t="Ctrl-"+t;if(e.metaKey)t="Meta-"+t;if(i&&e.shiftKey)t="Shift-"+t;return t}function ul(t){return new oi({props:{handleKeyDown:al(t)}})}function al(t){let e=ol(t);return function(t,i){let r=sl(i),s,n=e[fl(r,i)];if(n&&n(t.state,t.dispatch,t))return true;if(r.length==1&&r!=" "){if(i.shiftKey){let s=e[fl(r,i,false)];if(s&&s(t.state,t.dispatch,t))return true}if((i.altKey||i.metaKey||i.ctrlKey)&&!(hl&&i.ctrlKey&&i.altKey)&&(s=Vh[i.keyCode])&&s!=r){let r=e[fl(s,i)];if(r&&r(t.state,t.dispatch,t))return true}}return false}}const cl=(t,e)=>{if(t.selection.empty)return false;if(e)e(t.tr.deleteSelection().scrollIntoView());return true};function dl(t,e){let{$cursor:i}=t.selection;if(!i||(e?!e.endOfTextblock("backward",t):i.parentOffset>0))return null;return i}const pl=(t,e,i)=>{let r=dl(t,i);if(!r)return false;let s=gl(r);if(!s){let i=r.blockRange(),s=i&&se(i);if(s==null)return false;if(e)e(t.tr.lift(i,s).scrollIntoView());return true}let n=s.nodeBefore;if(Cl(t,s,e,-1))return true;if(r.parent.content.size==0&&(wl(n,"end")||Ke.isSelectable(n))){for(let i=r.depth;;i--){let h=ye(t.doc,r.before(i),r.after(i),m.empty);if(h&&h.slice.size<h.to-h.from){if(e){let i=t.tr.step(h);i.setSelection(wl(n,"end")?_e.findFrom(i.doc.resolve(i.mapping.map(s.pos,-1)),-1):Ke.create(i.doc,s.pos-n.nodeSize));e(i.scrollIntoView())}return true}if(i==1||r.node(i-1).childCount>1)break}}if(n.isAtom&&s.depth==r.depth-1){if(e)e(t.tr.delete(s.pos-n.nodeSize,s.pos).scrollIntoView());return true}return false};function wl(t,e,i=false){for(let r=t;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return true;if(i&&r.childCount!=1)return false}return false}const ml=(t,e,i)=>{let{$head:r,empty:s}=t.selection,n=r;if(!s)return false;if(r.parent.isTextblock){if(i?!i.endOfTextblock("backward",t):r.parentOffset>0)return false;n=gl(r)}let h=n&&n.nodeBefore;if(!h||!Ke.isSelectable(h))return false;if(e)e(t.tr.setSelection(Ke.create(t.doc,n.pos-h.nodeSize)).scrollIntoView());return true};function gl(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){if(t.index(e)>0)return t.doc.resolve(t.before(e+1));if(t.node(e).type.spec.isolating)break}return null}function bl(t,e){let{$cursor:i}=t.selection;if(!i||(e?!e.endOfTextblock("forward",t):i.parentOffset<i.parent.content.size))return null;return i}const vl=(t,e,i)=>{let r=bl(t,i);if(!r)return false;let s=Ml(r);if(!s)return false;let n=s.nodeAfter;if(Cl(t,s,e,1))return true;if(r.parent.content.size==0&&(wl(n,"start")||Ke.isSelectable(n))){let i=ye(t.doc,r.before(),r.after(),m.empty);if(i&&i.slice.size<i.to-i.from){if(e){let r=t.tr.step(i);r.setSelection(wl(n,"start")?_e.findFrom(r.doc.resolve(r.mapping.map(s.pos)),1):Ke.create(r.doc,r.mapping.map(s.pos)));e(r.scrollIntoView())}return true}}if(n.isAtom&&s.depth==r.depth-1){if(e)e(t.tr.delete(s.pos,s.pos+n.nodeSize).scrollIntoView());return true}return false};const yl=(t,e,i)=>{let{$head:r,empty:s}=t.selection,n=r;if(!s)return false;if(r.parent.isTextblock){if(i?!i.endOfTextblock("forward",t):r.parentOffset<r.parent.content.size)return false;n=Ml(r)}let h=n&&n.nodeAfter;if(!h||!Ke.isSelectable(h))return false;if(e)e(t.tr.setSelection(Ke.create(t.doc,n.pos)).scrollIntoView());return true};function Ml(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){let i=t.node(e);if(t.index(e)+1<i.childCount)return t.doc.resolve(t.after(e+1));if(i.type.spec.isolating)break}return null}const Al=(t,e)=>{let{$head:i,$anchor:r}=t.selection;if(!i.parent.type.spec.code||!i.sameParent(r))return false;if(e)e(t.tr.insertText("\n").scrollIntoView());return true};function kl(t){for(let e=0;e<t.edgeCount;e++){let{type:i}=t.edge(e);if(i.isTextblock&&!i.hasRequiredAttrs())return i}return null}const Sl=(t,e)=>{let{$head:i,$anchor:r}=t.selection;if(!i.parent.type.spec.code||!i.sameParent(r))return false;let s=i.node(-1),n=i.indexAfter(-1),h=kl(s.contentMatchAt(n));if(!h||!s.canReplaceWith(n,n,h))return false;if(e){let r=i.after(),s=t.tr.replaceWith(r,r,h.createAndFill());s.setSelection(_e.near(s.doc.resolve(r),1));e(s.scrollIntoView())}return true};const xl=(t,e)=>{let i=t.selection,{$from:r,$to:s}=i;if(i instanceof qe||r.parent.inlineContent||s.parent.inlineContent)return false;let n=kl(s.parent.contentMatchAt(s.indexAfter()));if(!n||!n.isTextblock)return false;if(e){let i=(!r.parentOffset&&s.index()<s.parent.childCount?r:s).pos;let h=t.tr.insert(i,n.createAndFill());h.setSelection(Qe.create(h.doc,i+1));e(h.scrollIntoView())}return true};const El=(t,e)=>{let{$cursor:i}=t.selection;if(!i||i.parent.content.size)return false;if(i.depth>1&&i.after()!=i.end(-1)){let r=i.before();if(ce(t.doc,r)){if(e)e(t.tr.split(r).scrollIntoView());return true}}let r=i.blockRange(),s=r&&se(r);if(s==null)return false;if(e)e(t.tr.lift(r,s).scrollIntoView());return true};function Ol(t){return(t,e)=>{let{$from:i}=t.selection;if(t.selection instanceof Ke&&t.selection.node.isBlock){if(!i.parentOffset||!ce(t.doc,i.pos))return false;if(e)e(t.tr.split(i.pos).scrollIntoView());return true}if(!i.depth)return false;let r=[];let s,n,h=false,l=false;for(let t=i.depth;;t--){let e=i.node(t);if(e.isBlock){h=i.end(t)==i.pos+(i.depth-t);l=i.start(t)==i.pos-(i.depth-t);n=kl(i.node(t-1).contentMatchAt(i.indexAfter(t-1)));r.unshift(h&&n?{type:n}:null);s=t;break}else{if(t==1)return false;r.unshift(null)}}let o=t.tr;if(t.selection instanceof Qe||t.selection instanceof qe)o.deleteSelection();let f=o.mapping.map(i.pos);let u=ce(o.doc,f,r.length,r);if(!u){r[0]=n?{type:n}:null;u=ce(o.doc,f,r.length,r)}if(!u)return false;o.split(f,r.length,r);if(!h&&l&&i.node(s).type!=n){let t=o.mapping.map(i.before(s)),e=o.doc.resolve(t);if(n&&i.node(s-1).canReplaceWith(e.index(),e.index()+1,n))o.setNodeMarkup(o.mapping.map(i.before(s)),n)}if(e)e(o.scrollIntoView());return true}}const Dl=Ol();const Tl=(t,e)=>{if(e)e(t.tr.setSelection(new qe(t.doc)));return true};function Rl(t,e,i){let r=e.nodeBefore,s=e.nodeAfter,n=e.index();if(!r||!s||!r.type.compatibleContent(s.type))return false;if(!r.content.size&&e.parent.canReplace(n-1,n)){if(i)i(t.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView());return true}if(!e.parent.canReplace(n,n+1)||!(s.isTextblock||pe(t.doc,e.pos)))return false;if(i)i(t.tr.join(e.pos).scrollIntoView());return true}function Cl(t,e,i,r){let s=e.nodeBefore,n=e.nodeAfter,h,l;let o=s.type.spec.isolating||n.type.spec.isolating;if(!o&&Rl(t,e,i))return true;let f=!o&&e.parent.canReplace(e.index(),e.index()+1);if(f&&(h=(l=s.contentMatchAt(s.childCount)).findWrapping(n.type))&&l.matchType(h[0]||n.type).validEnd){if(i){let r=e.pos+n.nodeSize,l=u.empty;for(let t=h.length-1;t>=0;t--)l=u.from(h[t].create(null,l));l=u.from(s.copy(l));let o=t.tr.step(new Vt(e.pos-1,r,e.pos,r,new m(l,1,0),h.length,true));let f=o.doc.resolve(r+2*h.length);if(f.nodeAfter&&f.nodeAfter.type==s.type&&pe(o.doc,f.pos))o.join(f.pos);i(o.scrollIntoView())}return true}let a=n.type.spec.isolating||r>0&&o?null:_e.findFrom(e,1);let c=a&&a.$from.blockRange(a.$to),d=c&&se(c);if(d!=null&&d>=e.depth){if(i)i(t.tr.lift(c,d).scrollIntoView());return true}if(f&&wl(n,"start",true)&&wl(s,"end")){let r=s,h=[];for(;;){h.push(r);if(r.isTextblock)break;r=r.lastChild}let l=n,o=1;for(;!l.isTextblock;l=l.firstChild)o++;if(r.canReplace(r.childCount,r.childCount,l.content)){if(i){let r=u.empty;for(let t=h.length-1;t>=0;t--)r=u.from(h[t].copy(r));let s=t.tr.step(new Vt(e.pos-h.length,e.pos+n.nodeSize,e.pos+o,e.pos+n.nodeSize-o,new m(r,h.length,0),0,true));i(s.scrollIntoView())}return true}}return false}function Pl(t){return function(e,i){let r=e.selection,s=t<0?r.$from:r.$to;let n=s.depth;while(s.node(n).isInline){if(!n)return false;n--}if(!s.node(n).isTextblock)return false;if(i)i(e.tr.setSelection(Qe.create(e.doc,t<0?s.start(n):s.end(n))));return true}}const Il=Pl(-1);const Nl=Pl(1);function Fl(...t){return function(e,i,r){for(let s=0;s<t.length;s++)if(t[s](e,i,r))return true;return false}}let Bl=Fl(cl,pl,ml);let Ul=Fl(cl,vl,yl);const jl={Enter:Fl(Al,xl,El,Dl),"Mod-Enter":Sl,Backspace:Bl,"Mod-Backspace":Bl,"Shift-Backspace":Bl,Delete:Ul,"Mod-Delete":Ul,"Mod-a":Tl};const $l={"Ctrl-h":jl["Backspace"],"Alt-Backspace":jl["Mod-Backspace"],"Ctrl-d":jl["Delete"],"Ctrl-Alt-Backspace":jl["Mod-Delete"],"Alt-Delete":jl["Mod-Delete"],"Alt-d":jl["Mod-Delete"],"Ctrl-a":Il,"Ctrl-e":Nl};for(let t in jl)$l[t]=jl[t];const _l=typeof navigator!="undefined"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os!="undefined"&&os.platform?os.platform()=="darwin":false;const zl=_l?$l:jl;class Jl extends n{object;constructor(t,e,i,r=false){super(t,e,r);this.object=i}execute(){this._core.store.state.objectsMap.insert(this.object);this._core.addObjectToDatabase(this.object)}undo(){this.object.isMounted=false;this._core.store.state.objectsMap.remove((t=>t.id===this.object.id));this._core.deleteObjectFromDatabase(this.object.id)}}class Wl extends r{__class__="KritzelText";fontFamily="Arial";fontSize=8;fontColor="#000000";initialWidth=1;initialHeight=1;scale=1;scaleFactor=1;isNew=true;isDebugInfoVisible=true;isEditable=true;isEditing=false;editor=null;content=null;_schema=new ht({nodes:Yh(Wh.spec.nodes,"paragraph block*","block"),marks:Wh.spec.marks});uneditedObject=null;rows=1;get isEmpty(){if(!this.editor){return true}const t=this.editor.state.doc;if(t.content.size===0){return true}const e=t.textContent.trim();return e.length===0}constructor(t){super();if(t){this.translateX=t.translateX||0;this.translateY=t.translateY||0;this.fontSize=t.fontSize||8;this.fontFamily=t.fontFamily||"Arial";this.fontColor=t.fontColor||"#000000";this.width=this.initialWidth/(this._core.store.state.scale<0?this._core.store.state.scale:1);this.height=this.fontSize*1.2/(this._core.store.state.scale<0?this._core.store.state.scale:1);this.scale=t.scale||1;this.scaleFactor=t.scaleX??1}}static create(t,e,i){const r=new Wl;r._core=t;r.id=r.generateId();r.workspaceId=t.store.state.activeWorkspace.id;r.fontSize=e;r.fontFamily=i;r.translateX=0;r.translateY=0;r.width=r.initialWidth/(r._core.store.state.scale<0?r._core.store.state.scale:1);r.height=r.fontSize*1.2/(r._core.store.state.scale<0?r._core.store.state.scale:1);r.backgroundColor="transparent";r.initialWidth=r.width;r.initialHeight=r.height;r.scaleFactor=1;r.scale=r._core.store.state.scale;r.zIndex=t.store.currentZIndex;r.editor=r.createEditor();return r}mount(t){if(t===null||this.isInViewport()===false){return}if(this.isMounted&&this.elementRef===t&&this.editor.dom.parentElement===t){return}this.elementRef=t;this.elementRef.style.fontFamily=this.fontFamily;this.elementRef.style.fontSize=`${this.fontSize}pt`;this.elementRef.style.color=this.fontColor;this.elementRef.style.whiteSpace="pre-wrap";this.elementRef.style.wordWrap="break-word";this.elementRef.innerHTML="";this.elementRef.appendChild(this.editor.dom);this.isMounted=true;requestAnimationFrame((()=>this.adjustSizeOnInput()))}createEditor(){const t=this._schema.node("doc",null,[this._schema.node("paragraph")]);return new xh(null,{state:hi.create({doc:t,plugins:[ul(zl)]}),editable:()=>false,dispatchTransaction:t=>{const e=this.editor.state.apply(t);this.editor.updateState(e);this.adjustSizeOnInput();this._core.store.state.objectsMap.update(this);this._core.rerender()}})}setContent(t){this.content=t;if(this.editor){const e=this.editor.state.schema.nodeFromJSON(t);const i=this.editor.state.tr.replaceWith(0,this.editor.state.doc.content.size,e.content);this.editor.dispatch(i)}}adjustSizeOnInput(){const t=this.elementRef;if(t&&this.isMounted&&t.scrollWidth>0){const e=this.totalWidth;const i=this.totalHeight;const r=t.scrollWidth;const s=t.scrollHeight;this.width=r*this.scaleFactor;this.height=s*this.scaleFactor;if(this.rotation!==0){const t=this.totalWidth;const r=this.totalHeight;const s=(t-e)/2/this.scale;const n=(r-i)/2/this.scale;if(s!==0||n!==0){const t=Math.cos(this.rotation);const e=Math.sin(this.rotation);const i=t*s-e*n;const r=e*s+t*n;this.translateX+=i-s;this.translateY+=r-n}}}if(this._core){this._core.store.state.objectsMap.update(this);this._core.rerender()}}resize(t,e,i,r){if(i<=1||r<=1){return}const s=this.width/this.scaleFactor;const n=this.height/this.scaleFactor;const h=i/s;const l=r/n;this.scaleFactor=Math.min(h,l);this.width=s*this.scaleFactor;this.height=n*this.scaleFactor;this.translateX=t;this.translateY=e}focus(t){if(this.editor){const e=this.editor.state.doc;if(t){const i=this.editor.posAtCoords({left:t.x,top:t.y});if(i){this.editor.dispatch(this.editor.state.tr.setSelection(Qe.create(e,i.pos)));this.editor.focus();return}}const i=Math.max(1,e.content.size-1);this.editor.dispatch(this.editor.state.tr.setSelection(Qe.create(e,i)));this.editor.focus()}}edit(e){s.disableInteractiveWidget();this.uneditedObject=this.clone();this._core.store.setState("activeTool",t.getTool("text"));this._core.store.state.activeText=this;if(this.editor){this.editor.setProps({editable:()=>true})}this.isEditing=true;if(e){this.focus({x:e.clientX,y:e.clientY})}else{this.focus()}this._core.rerender();requestAnimationFrame((()=>this.adjustSizeOnInput()));s.enableInteractiveWidget()}save(){requestAnimationFrame((()=>this.adjustSizeOnInput()));this.content=this.editor.state.doc.toJSON();this.editor.setProps({editable:()=>false});this.editor.dom.blur();this.isEditing=false;let t;if(this.isNew){this.isNew=false;t=new Jl(this._core,this,this)}else{t=new h(this._core,this,this.uneditedObject,{...this})}this._core.commandManager.executeCommand(t)}handlePointerDown(t){if(!this.isEditing){return}t.stopPropagation()}handlePointerMove(t){if(!this.isEditing){return}t.stopPropagation()}handlePointerUp(t){if(!this.isEditing){return}t.stopPropagation()}copy(){const t=super.copy();t.editor=t.createEditor();if(this.content){t.setContent(this.content)}return t}serialize(){const{_core:t,_elementRef:e,_schema:i,element:r,totalWidth:s,totalHeight:n,editor:h,uneditedObject:l,...o}=this;const f=structuredClone(o);if(r&&typeof r==="object"&&"nodeType"in r&&r.nodeType===1){f.element=r.cloneNode(true)}return f}deserialize(t){super.deserialize(t);this.setContent(t.content);return this}onExecuteUpdateCommand(t){if("content"in t){this.setContent(t.content)}}onUndoUpdateCommand(t){if("content"in t&&this.editor){this.setContent(t.content)}}}var Ql={};var Ll;function Kl(){if(Ll)return Ql;Ll=1;(function(t){var e=Object.defineProperty;var i=t=>e(t,"__esModule",{value:true});var r=(t,r)=>{i(t);for(var s in r)e(t,s,{get:r[s],enumerable:true})};r(t,{default:()=>D,getStroke:()=>O,getStrokeOutlinePoints:()=>x,getStrokePoints:()=>E});function s(t,e,i,r=t=>t){return t*r(.5-e*(.5-i))}function n(t){return[-t[0],-t[1]]}function h(t,e){return[t[0]+e[0],t[1]+e[1]]}function l(t,e){return[t[0]-e[0],t[1]-e[1]]}function o(t,e){return[t[0]*e,t[1]*e]}function f(t,e){return[t[0]/e,t[1]/e]}function u(t){return[t[1],-t[0]]}function a(t,e){return t[0]*e[0]+t[1]*e[1]}function c(t,e){return t[0]===e[0]&&t[1]===e[1]}function d(t){return Math.hypot(t[0],t[1])}function p(t){return t[0]*t[0]+t[1]*t[1]}function w(t,e){return p(l(t,e))}function m(t){return f(t,d(t))}function g(t,e){return Math.hypot(t[1]-e[1],t[0]-e[0])}function b(t,e,i){let r=Math.sin(i),s=Math.cos(i),n=t[0]-e[0],h=t[1]-e[1],l=n*s-h*r,o=n*r+h*s;return[l+e[0],o+e[1]]}function v(t,e,i){return h(t,o(l(e,t),i))}function y(t,e,i){return h(t,o(e,i))}var{min:M,PI:A}=Math,k=.275,S=A+1e-4;function x(t,e={}){let{size:i=16,smoothing:r=.5,thinning:f=.5,simulatePressure:c=true,easing:d=t=>t,start:p={},end:g={},last:A=false}=e,{cap:x=true,easing:E=t=>t*(2-t)}=p,{cap:O=true,easing:D=t=>--t*t*t+1}=g;if(t.length===0||i<=0)return[];let T=t[t.length-1].runningLength,R=p.taper===false?0:p.taper===true?Math.max(i,T):p.taper,C=g.taper===false?0:g.taper===true?Math.max(i,T):g.taper,P=Math.pow(i*r,2),I=[],N=[],F=t.slice(0,10).reduce(((t,e)=>{let r=e.pressure;if(c){let s=M(1,e.distance/i),n=M(1,1-s);r=M(1,t+(n-t)*(s*k))}return(t+r)/2}),t[0].pressure),B=s(i,f,t[t.length-1].pressure,d),U,j=t[0].vector,$=t[0].point,_=$,z=$,J=_,W=false;for(let e=0;e<t.length;e++){let{pressure:r}=t[e],{point:n,vector:p,distance:m,runningLength:g}=t[e];if(e<t.length-1&&T-g<3)continue;if(f){if(c){let t=M(1,m/i),e=M(1,1-t);r=M(1,F+(e-F)*(t*k))}B=s(i,f,r,d)}else B=i/2;U===void 0&&(U=B);let y=g<R?E(g/R):1,A=T-g<C?D((T-g)/C):1;B=Math.max(.01,B*Math.min(y,A));let x=(e<t.length-1?t[e+1]:t[e]).vector,O=e<t.length-1?a(p,x):1,Q=a(p,j)<0&&!W,L=O!==null&&O<0;if(Q||L){let t=o(u(j),B);for(let e=1/13,i=0;i<=1;i+=e)z=b(l(n,t),n,S*i),I.push(z),J=b(h(n,t),n,S*-i),N.push(J);$=z,_=J,L&&(W=true);continue}if(W=false,e===t.length-1){let t=o(u(p),B);I.push(l(n,t)),N.push(h(n,t));continue}let K=o(u(v(x,p,O)),B);z=l(n,K),(e<=1||w($,z)>P)&&(I.push(z),$=z),J=h(n,K),(e<=1||w(_,J)>P)&&(N.push(J),_=J),F=r,j=p}let Q=t[0].point.slice(0,2),L=t.length>1?t[t.length-1].point.slice(0,2):h(t[0].point,[1,1]),K=[],H=[];if(t.length===1){if(!(R||C)||A){let t=y(Q,m(u(l(Q,L))),-(U||B)),e=[];for(let i=1/13,r=i;r<=1;r+=i)e.push(b(t,Q,S*2*r));return e}}else{if(!(R||C&&t.length===1))if(x)for(let t=1/13,e=t;e<=1;e+=t){let t=b(N[0],Q,S*e);K.push(t)}else{let t=l(I[0],N[0]),e=o(t,.5),i=o(t,.51);K.push(l(Q,e),l(Q,i),h(Q,i),h(Q,e))}let e=u(n(t[t.length-1].vector));if(C||R&&t.length===1)H.push(L);else if(O){let t=y(L,e,B);for(let e=1/29,i=e;i<1;i+=e)H.push(b(t,L,S*3*i))}else H.push(h(L,o(e,B)),h(L,o(e,B*.99)),l(L,o(e,B*.99)),l(L,o(e,B)))}return I.concat(H,N.reverse(),K)}function E(t,e={}){var i;let{streamline:r=.5,size:s=16,last:n=false}=e;if(t.length===0)return[];let o=.15+(1-r)*.85,f=Array.isArray(t[0])?t:t.map((({x:t,y:e,pressure:i=.5})=>[t,e,i]));if(f.length===2){let t=f[1];f=f.slice(0,-1);for(let e=1;e<5;e++)f.push(v(f[0],t,e/4))}f.length===1&&(f=[...f,[...h(f[0],[1,1]),...f[0].slice(2)]]);let u=[{point:[f[0][0],f[0][1]],pressure:f[0][2]>=0?f[0][2]:.25,vector:[1,1],distance:0,runningLength:0}],a=false,d=0,p=u[0],w=f.length-1;for(let t=1;t<f.length;t++){let e=n&&t===w?f[t].slice(0,2):v(p.point,f[t],o);if(c(p.point,e))continue;let i=g(e,p.point);if(d+=i,t<w&&!a){if(d<s)continue;a=true}p={point:e,pressure:f[t][2]>=0?f[t][2]:.5,vector:m(l(p.point,e)),distance:i,runningLength:d},u.push(p)}return u[0].vector=((i=u[1])==null?void 0:i.vector)||[0,0],u}function O(t,e={}){return x(E(t,e),e)}var D=O})(Ql);return Ql}var Hl=Kl();class ql{static average(t,e){return(t+e)/2}}class Gl extends r{__class__="KritzelPath";points;d;stroke="none";strokeWidth;lineSlack=.5;fill;x=0;y=0;height=0;width=0;scale=1;options;isVisible=true;isDebugInfoVisible=true;_adjustedPoints=null;get viewBox(){return`${this.x} ${this.y} ${this.width} ${this.height}`}constructor(t){super();this.options=t;this.points=t?.points??[];this.translateX=t?.translateX??0;this.translateY=t?.translateY??0;this.scale=t?.scale??1;this.strokeWidth=t?.strokeWidth??8;this.fill=t?.fill??"#000000";this.d=this.generateSvgPath();this.updateDimensions()}static create(t,e){const i=new Gl;i._core=t;i.id=i.generateId();i.workspaceId=t.store.state.activeWorkspace.id;i.options=e;i.points=e?.points??[];i.translateX=e?.translateX??0;i.translateY=e?.translateY??0;i.scale=e?.scale??1;i.strokeWidth=e?.strokeWidth??8;i.fill=e?.fill??"#000000";i.zIndex=t.store.currentZIndex;i.d=i.generateSvgPath();i.updateDimensions();return i}resize(t,e,i,r){if(i<=1||r<=1){return}const s=i/this.width;const n=r/this.height;this.width=i;this.height=r;this.points=this.points.map((([t,e])=>[t*s,e*n]));this.d=this.generateSvgPath();this.width=Math.max(...this.points.map((t=>t[0])))-Math.min(...this.points.map((t=>t[0])))+this.strokeWidth;this.height=Math.max(...this.points.map((t=>t[1])))-Math.min(...this.points.map((t=>t[1])))+this.strokeWidth;this.x=Math.min(...this.points.map((t=>t[0])))-this.strokeWidth/2;this.y=Math.min(...this.points.map((t=>t[1])))-this.strokeWidth/2;this.translateX=t;this.translateY=e;this._adjustedPoints=null}rotate(t){this.rotation=t;this._adjustedPoints=null}move(t,e,i,r){const s=(t-i)/this._core.store.state.scale;const n=(e-r)/this._core.store.state.scale;this.translateX+=s;this.translateY+=n;this._adjustedPoints=null}hitTest(t,e){const i=this.strokeWidth/this.scale/2;if(this._adjustedPoints===null){this._adjustedPoints=this.computeAdjustedPoints()}if(this._adjustedPoints.length===1){const r=this._adjustedPoints[0];const s=this.pointToLineSegmentDistance(t,e,r[0],r[1],r[0],r[1]);return s<=i}for(let r=0;r<this._adjustedPoints.length-1;r++){const s=this._adjustedPoints[r];const n=this._adjustedPoints[r+1];const h=this.pointToLineSegmentDistance(t,e,s[0],s[1],n[0],n[1]);if(h<=i){return true}}return false}hitTestPolygon(t){const e=this.strokeWidth/this.scale/2;if(this._adjustedPoints===null){this._adjustedPoints=this.computeAdjustedPoints()}const r=[{x:t.bottomLeft.x,y:t.bottomLeft.y},{x:t.bottomRight.x,y:t.bottomRight.y},{x:t.topRight.x,y:t.topRight.y},{x:t.topLeft.x,y:t.topLeft.y}];for(const[t,e]of this._adjustedPoints){if(i.isPointInPolygon({x:t,y:e},r)){return true}}for(const t of r){if(this.hitTest(t.x,t.y)){return true}}for(let t=0;t<this._adjustedPoints.length-1;t++){const e={x:this._adjustedPoints[t][0],y:this._adjustedPoints[t][1]};const s={x:this._adjustedPoints[t+1][0],y:this._adjustedPoints[t+1][1]};for(let t=0;t<r.length;t++){const n=r[t];const h=r[(t+1)%r.length];if(i.intersectLines(e,s,n,h)){return true}}}for(let t=0;t<this._adjustedPoints.length-1;t++){const i=this._adjustedPoints[t];const s=this._adjustedPoints[t+1];for(let t=0;t<r.length;t++){const n=r[t];const h=r[(t+1)%r.length];const l=this.pointToLineSegmentDistance(n.x,n.y,i[0],i[1],s[0],s[1]);const o=this.pointToLineSegmentDistance(h.x,h.y,i[0],i[1],s[0],s[1]);const f=this.pointToLineSegmentDistance(i[0],i[1],n.x,n.y,h.x,h.y);const u=this.pointToLineSegmentDistance(s[0],s[1],n.x,n.y,h.x,h.y);const a=Math.min(l,o,f,u);if(a<=e){return true}}}return false}updatePosition(t,e){this.translateX=t;this.translateY=e;this._adjustedPoints=null;this._core.store.state.objectsMap.update(this)}computeAdjustedPoints(){if(!this.points?.length){return[]}const t=this.rotation;const e=Math.cos(t);const i=Math.sin(t);const r=this.points.map((t=>t[0]));const s=this.points.map((t=>t[1]));const n={x:(Math.min(...r)+Math.max(...r))/2,y:(Math.min(...s)+Math.max(...s))/2};const{x:h,y:l}=n;const o=this.points.map((([t,r])=>{const s=t-h;const n=r-l;return[h+s*e-n*i,l+s*i+n*e]}));return o.map((([t,e])=>[Math.abs(t-this.x)/this.scale+this.translateX,Math.abs(e-this.y)/this.scale+this.translateY]))}pointToLineSegmentDistance(t,e,i,r,s,n){const h=t-i;const l=e-r;const o=s-i;const f=n-r;const u=h*o+l*f;const a=o*o+f*f;let c=-1;if(a!==0){c=u/a}let d,p;if(c<0){d=i;p=r}else if(c>1){d=s;p=n}else{d=i+c*o;p=r+c*f}const w=t-d;const m=e-p;return Math.sqrt(w*w+m*m)}updateDimensions(){const t=this.points.map((([t,e])=>{const i=t*Math.cos(this.rotation)-e*Math.sin(this.rotation);const r=t*Math.sin(this.rotation)+e*Math.cos(this.rotation);return[i,r]}));const e=Math.min(...t.map((t=>t[0]-this.strokeWidth/2)));const i=Math.min(...t.map((t=>t[1]-this.strokeWidth/2)));const r=Math.max(...t.map((t=>t[0]+this.strokeWidth/2)));const s=Math.max(...t.map((t=>t[1]+this.strokeWidth/2)));this.width=r-e+this.lineSlack;this.height=s-i+this.lineSlack;this.x=e;this.y=i;this.translateX=(this.x+this.translateX)/this.scale;this.translateY=(this.y+this.translateY)/this.scale}generateSvgPath(){const t=this.getStrokeFromPoints(this.points,this.strokeWidth);return this.getSvgPathFromStroke(t)}getStrokeFromPoints(t,e){return Hl.getStroke(t,{size:e,thinning:.5,smoothing:.5,streamline:.5,easing:t=>t,simulatePressure:true,last:true,start:{cap:true,taper:0,easing:t=>t},end:{cap:true,taper:0,easing:t=>t}})}getSvgPathFromStroke(t,e=true){const i=t.length;if(i<4){return``}let r=t[0];let s=t[1];const n=t[2];let h=`M${r[0].toFixed(2)},${r[1].toFixed(2)} Q${s[0].toFixed(2)},${s[1].toFixed(2)} ${ql.average(s[0],n[0]).toFixed(2)},${ql.average(s[1],n[1]).toFixed(2)} T`;for(let e=2,n=i-1;e<n;e++){r=t[e];s=t[e+1];h+=`${ql.average(r[0],s[0]).toFixed(2)},${ql.average(r[1],s[1]).toFixed(2)} `}if(e){h+="Z"}return h}}class Xl extends r{__class__="KritzelImage";src="";maxWidth=300;maxHeight=300;maxCompressionSize=300;isDebugInfoVisible=true;constructor(t){super();this.src=t?.src||"";this.x=t?.x||0;this.y=t?.y||0;this.translateX=t?.translateX||0;this.translateY=t?.translateY||0;this.scale=t?.scale||1}static create(t){const e=new Xl;e._core=t;e.id=e.generateId();e.workspaceId=t.store.state.activeWorkspace.id;e.x=0;e.y=0;e.translateX=0;e.translateY=0;e.scale=e._core.store.state.scale;e.zIndex=t.store.currentZIndex;return e}resize(t,e,i,r){if(i<=1||r<=1){return}const s=r/this.height;this.width=this.width*s;this.height=this.height*s;this.translateX=t;this.translateY=e}calculateScaledDimensions(t){let e=t.width;let i=t.height;if(t.width>this.maxWidth||t.height>this.maxHeight){const r=this.maxWidth/t.width;const s=this.maxHeight/t.height;const n=Math.min(r,s);e=t.width*n;i=t.height*n}return{scaledWidth:e,scaledHeight:i}}}var Yl;(function(t){t[t["Left"]=0]="Left";t[t["Middle"]=1]="Middle";t[t["Right"]=2]="Right"})(Yl||(Yl={}));class Vl{static isRightClick(t){return t.button===Yl.Right}static isLeftClick(t){return t.button===Yl.Left}static isPointerEventOnContextMenu(t){const e=t.composedPath();const i=e.find((t=>t.classList&&t.classList.contains("context-menu")));return!!i}static onLongPress(t,e,i){const r=400;const s=10;const n=t.clientX;const h=t.clientY;const l=t.target;const o=setTimeout((()=>{d();e(t)}),r);const f=()=>{clearTimeout(o);d();i?.()};const u=t=>{if(Math.abs(t.clientX-n)>s||Math.abs(t.clientY-h)>s){f()}};const a=()=>{f()};const c=()=>{f()};const d=()=>{l.removeEventListener("pointermove",u);l.removeEventListener("pointerup",a);l.removeEventListener("pointercancel",c)};l.addEventListener("pointermove",u,{passive:true});l.addEventListener("pointerup",a,{once:true});l.addEventListener("pointercancel",c,{once:true});return f}}class Zl{__class__=this.constructor.name;name="base-tool";_core;constructor(t){this._core=t}onActivate(){}onDeactivate(){}handlePointerDown(t){}handlePointerMove(t){}handlePointerUp(t){}handleWheel(t){}serialize(){return{__class__:this.__class__,name:this.name}}deserialize(t){Object.assign(this,t);return this}}class to extends Zl{type="pen";color="#000000";size=6;palettes={pen:["#000000","#FFFFFF","#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF","#00FFFF","#808080","#C0C0C0","#800000","#008000","#000080","#808000","#800080"],highlighter:["#ffff00","#ffb347","#b4ffb4"]};constructor(t){super(t)}handlePointerDown(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){if(Vl.isLeftClick(t)){this._core.store.state.isDrawing=true;const e=t.clientX-this._core.store.offsetX;const i=t.clientY-this._core.store.offsetY;this._core.store.state.currentPath=Gl.create(this._core,{points:[[e,i]],translateX:-this._core.store.state.translateX,translateY:-this._core.store.state.translateY,scale:this._core.store.state.scale,fill:this.color,strokeWidth:this.size})}}if(t.pointerType==="touch"){const t=Array.from(this._core.store.state.pointers.values());if(t.length===1){const e=Math.round(t[0].clientX-this._core.store.offsetX);const i=Math.round(t[0].clientY-this._core.store.offsetY);this._core.store.state.isDrawing=true;this._core.store.state.currentPath=Gl.create(this._core,{points:[[e,i]],translateX:-this._core.store.state.translateX,translateY:-this._core.store.state.translateY,scale:this._core.store.state.scale,fill:this.color,strokeWidth:this.size});this._core.rerender()}}}handlePointerMove(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){if(this._core.store.state.isDrawing){const e=t.clientX-this._core.store.offsetX;const i=t.clientY-this._core.store.offsetY;this._core.store.state.currentPath=Gl.create(this._core,{points:[...this._core.store.state.currentPath.points,[e,i]],translateX:-this._core.store.state.translateX,translateY:-this._core.store.state.translateY,scale:this._core.store.state.scale,fill:this.color,strokeWidth:this.size});this._core.rerender()}}if(t.pointerType==="touch"){const t=Array.from(this._core.store.state.pointers.values());if(t.length===1){const e=Math.round(t[0].clientX-this._core.store.offsetX);const i=Math.round(t[0].clientY-this._core.store.offsetY);this._core.store.state.currentPath=Gl.create(this._core,{points:[...this._core.store.state.currentPath.points,[e,i]],translateX:-this._core.store.state.translateX,translateY:-this._core.store.state.translateY,scale:this._core.store.state.scale,fill:this.color,strokeWidth:this.size});this._core.rerender()}}}handlePointerUp(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){if(this._core.store.state.isDrawing){this._core.store.state.isDrawing=false;if(this._core.store.state.currentPath){const t=this._core.store.state.currentPath;t.zIndex=this._core.store.currentZIndex;this._core.store.state.currentPath=t;this._core.commandManager.executeCommand(new Jl(this._core,this,this._core.store.state.currentPath))}this._core.store.state.currentPath=undefined}}if(t.pointerType==="touch"){if(this._core.store.state.isDrawing){this._core.store.state.isDrawing=false;if(this._core.store.state.currentPath){const t=this._core.store.state.currentPath;t.zIndex=this._core.store.currentZIndex;this._core.store.state.currentPath=t;this._core.commandManager.executeCommand(new Jl(this._core,this,t))}this._core.store.state.currentPath=undefined;this._core.rerender()}}}}class eo extends n{commands;constructor(t,e,i,r=false){super(t,e,r);this.commands=i}execute(){this.commands.forEach((t=>t.execute()))}undo(){this.commands.forEach((t=>t.undo()))}}class io extends n{object;constructor(t,e,i,r=false){super(t,e,r);this.object=i}execute(){this.object.isMounted=false;this._core.store.state.objectsMap.remove((t=>t.id===this.object.id));this._core.deleteObjectFromDatabase(this.object.id)}undo(){this._core.store.state.objectsMap.insert(this.object);this._core.addObjectToDatabase(this.object)}}class ro extends Zl{touchStartTimeout=null;constructor(t){super(t)}handlePointerDown(t){if(t.pointerType==="mouse"){if(Vl.isLeftClick(t)){this._core.store.state.isErasing=true}}if(t.pointerType==="touch"){this.touchStartTimeout=setTimeout((()=>{if(this._core.store.state.pointers.size===1&&!this._core.store.state.isScaling){this._core.store.state.isErasing=true}}),80)}}handlePointerMove(t){if(t.pointerType==="mouse"){if(this._core.store.state.isErasing){const e=this._core.getObjectsFromPointerEvent(t,".object");if(e.length===0)return;const i=this._core.store.state.pointerX;const r=this._core.store.state.pointerY;e.forEach((t=>{t.markedForRemoval=t.hitTest(i,r)}));this._core.rerender()}}if(t.pointerType==="touch"){if(this._core.store.state.pointers.size===1&&this._core.store.state.isErasing){const e=this._core.store.state.host?.shadowRoot;if(!e)return;const i=this._core.getObjectsFromPointerEvent(t,".object");if(i.length===0)return;const r=this._core.store.state.pointerX;const s=this._core.store.state.pointerY;i.forEach((t=>{t.markedForRemoval=t.hitTest(r,s)}));this._core.rerender()}}}handlePointerUp(t){if(t.pointerType==="mouse"){if(this._core.store.state.isErasing){const t=this._core.store.allObjects.filter((t=>t.markedForRemoval)).map((t=>{t.markedForRemoval=false;return new io(this._core,this,t)}));if(t.length>0){this._core.commandManager.executeCommand(new eo(this._core,this,t))}this._core.store.state.isErasing=false}}if(t.pointerType==="touch"){clearTimeout(this.touchStartTimeout);if(this._core.store.state.isErasing){const t=this._core.store.allObjects.filter((t=>t.markedForRemoval)).map((t=>{t.markedForRemoval=false;return new io(this._core,this,t)}));if(t.length>0){this._core.commandManager.executeCommand(new eo(this._core,this,t))}this._core.store.state.isErasing=false}}}}class so extends n{previousSelectionGroup;constructor(t,e,i=false){super(t,e,i);this.previousSelectionGroup=this._core.store.state.selectionGroup}execute(){this._core.store.state.objectsMap.remove((t=>t.id===this.previousSelectionGroup?.id));this._core.store.state.selectionGroup=null}undo(){if(this.previousSelectionGroup){this._core.store.state.objectsMap.insert(this.previousSelectionGroup);this._core.store.state.selectionGroup=this.previousSelectionGroup}}}class no extends n{selectionGroup;startX;startY;endX;endY;skipExecution;constructor(t,e,i,r,s,n,h=false,l=false){super(t,e,l);this.startX=i;this.startY=r;this.endX=s;this.endY=n;this.skipExecution=h;this.selectionGroup=this._core.store.state.selectionGroup}execute(){if(this.skipExecution){this.skipExecution=false;this._core.store.state.selectionGroup.objects.forEach((t=>{this._core.store.state.objectsMap.update(t);this._core.updateObjectInDatabase(t)}));return}this._core.store.state.selectionGroup=this.selectionGroup;this._core.store.state.selectionGroup.move(this.startX,this.startY,this.endX,this.endY);this._core.store.state.selectionGroup.objects.forEach((t=>{this._core.store.state.objectsMap.update(t);this._core.updateObjectInDatabase(t)}))}undo(){this._core.store.state.selectionGroup=this.selectionGroup;this._core.store.state.selectionGroup.move(this.endX,this.endY,this.startX,this.startY);this._core.store.state.selectionGroup.objects.forEach((t=>{this._core.store.state.objectsMap.update(t);this._core.updateObjectInDatabase(t)}))}}class ho{_core;constructor(t){this._core=t}}class lo extends ho{dragStartX;dragStartY;startX;startY;endX;endY;hasMoved=false;trackedPointerId=null;constructor(t){super(t)}reset(){this.dragStartX=0;this.dragStartY=0;this.startX=0;this.startY=0;this.endX=0;this.endY=0;this.hasMoved=false;this.trackedPointerId=null}cancelPendingDrag(){this._core.store.state.isDragging=false;this.reset()}handlePointerDown(t){if(t.pointerType==="mouse"){if(Vl.isLeftClick(t)){if(this._core.store.state.selectionGroup?.isSelected&&!this._core.store.state.isResizeHandleSelected&&!this._core.store.state.isRotationHandleSelected){const e=t.clientX-this._core.store.offsetX;const i=t.clientY-this._core.store.offsetY;this._core.store.state.isDragging=true;this.dragStartX=e;this.dragStartY=i;this.startX=this.dragStartX;this.startY=this.dragStartY;this.trackedPointerId=t.pointerId}else{this.trackedPointerId=null}}else{this.trackedPointerId=null}}if(t.pointerType==="touch"){const e=Array.from(this._core.store.state.pointers.values());if(this._core.store.state.pointers.size===1){if(this._core.store.state.isScaling){this.trackedPointerId=null;return}if(this._core.store.state.selectionGroup?.isSelected&&!this._core.store.state.isResizeHandleSelected&&!this._core.store.state.isRotationHandleSelected){const i=Math.round(e[0].clientX-this._core.store.offsetX);const r=Math.round(e[0].clientY-this._core.store.offsetY);this.dragStartX=i;this.dragStartY=r;this.startX=i;this.startY=r;this.trackedPointerId=t.pointerId}else{this.trackedPointerId=null}}}}handlePointerMove(t){if(this.trackedPointerId===null||this.trackedPointerId!==t.pointerId){return}if(t.pointerType==="mouse"){if(this._core.store.state.isDragging&&this._core.store.state.selectionGroup){const e=t.clientX-this._core.store.offsetX;const i=t.clientY-this._core.store.offsetY;this.endX=e;this.endY=i;const r=Math.abs(e-this.startX);const s=Math.abs(i-this.startY);const n=5;if(r>n||s>n){this._core.store.state.selectionGroup.move(e,i,this.dragStartX,this.dragStartY);this.dragStartX=e;this.dragStartY=i;this.hasMoved=true}}}if(t.pointerType==="touch"){const t=Array.from(this._core.store.state.pointers.values());if(this._core.store.state.pointers.size===1&&this._core.store.state.selectionGroup&&!this._core.store.state.isResizeHandleSelected&&!this._core.store.state.isRotationHandleSelected&&!this._core.store.state.isScaling){const e=Math.round(t[0].clientX-this._core.store.offsetX);const i=Math.round(t[0].clientY-this._core.store.offsetY);this._core.store.state.isDragging=true;this.endX=e;this.endY=i;const r=Math.abs(e-this.startX);const s=Math.abs(i-this.startY);const n=5;if(r>n||s>n){clearTimeout(this._core.store.state.longTouchTimeout);this._core.store.state.selectionGroup.move(e,i,this.dragStartX,this.dragStartY);this.dragStartX=e;this.dragStartY=i;this.hasMoved=true}}}}handlePointerUp(t){if(this.trackedPointerId===null||this.trackedPointerId!==t.pointerId){return}if(t.pointerType==="mouse"){if(this._core.store.state.isDragging){this._core.store.state.isDragging=false;if(this.hasMoved){this._core.commandManager.executeCommand(new no(this._core,this,this.endX,this.endY,this.startX,this.startY,true));this._core.store.state.hasObjectsChanged=true}}}if(t.pointerType==="touch"){if(this._core.store.state.isDragging){this._core.store.state.isDragging=false;if(this.hasMoved){this._core.commandManager.executeCommand(new no(this._core,this,this.endX,this.endY,this.startX,this.startY,true));this._core.store.state.hasObjectsChanged=true}}}this.reset()}}var oo;(function(t){t["TopLeft"]="top-left";t["TopRight"]="top-right";t["BottomLeft"]="bottom-left";t["BottomRight"]="bottom-right"})(oo||(oo={}));class fo extends n{newSize;previousSize;selectionGroup;constructor(t,e,i,r,s=false){super(t,e,s);this.previousSize=i;this.newSize=r;this.selectionGroup=this._core.store.state.selectionGroup}execute(){this._core.store.state.selectionGroup=this.selectionGroup;this._core.store.state.selectionGroup.resize(this.newSize.x,this.newSize.y,this.newSize.width,this.newSize.height);this._core.store.state.selectionGroup.objects.forEach((t=>{this._core.store.state.objectsMap.update(t);this._core.updateObjectInDatabase(t)}))}undo(){this._core.store.state.selectionGroup=this.selectionGroup;this._core.store.state.selectionGroup.resize(this.previousSize.x,this.previousSize.y,this.previousSize.width,this.previousSize.height);this._core.store.state.selectionGroup.objects.forEach((t=>{this._core.store.state.objectsMap.update(t);this._core.updateObjectInDatabase(t)}))}}class uo extends ho{initialMouseX=0;initialMouseY=0;initialSize={x:0,y:0,width:0,height:0};newSize={x:0,y:0,width:0,height:0};hasResized=false;constructor(t){super(t)}reset(){this.initialMouseX=0;this.initialMouseY=0;this.initialSize={x:0,y:0,width:0,height:0};this.newSize={x:0,y:0,width:0,height:0};this.hasResized=false}handlePointerDown(t){if(t.pointerType==="mouse"){if(Vl.isLeftClick(t)){if(this._core.store.state.selectionGroup&&this._core.store.state.isResizeHandleSelected){const e=t.clientX-this._core.store.offsetX;const i=t.clientY-this._core.store.offsetY;this._core.store.state.isResizing=true;this.initialMouseX=e;this.initialMouseY=i;this.initialSize.width=this._core.store.state.selectionGroup.width;this.initialSize.height=this._core.store.state.selectionGroup.height;this.initialSize.x=this._core.store.state.selectionGroup.translateX;this.initialSize.y=this._core.store.state.selectionGroup.translateY}}}if(t.pointerType==="touch"){const t=Array.from(this._core.store.state.pointers.values());const e=t[0];if(!e){return}if(t.length===1){if(this._core.store.state.selectionGroup&&this._core.store.state.isResizeHandleSelected){const t=Math.round(e.clientX-this._core.store.offsetX);const i=Math.round(e.clientY-this._core.store.offsetY);this._core.store.state.isResizing=true;this.initialMouseX=t;this.initialMouseY=i;this.initialSize.width=this._core.store.state.selectionGroup.width;this.initialSize.height=this._core.store.state.selectionGroup.height;this.initialSize.x=this._core.store.state.selectionGroup.translateX;this.initialSize.y=this._core.store.state.selectionGroup.translateY;clearTimeout(this._core.store.state.longTouchTimeout)}}}}handlePointerMove(t){if(t.pointerType==="mouse"){if(this._core.store.state.isResizing&&this._core.store.state.selectionGroup){const e=t.clientX-this._core.store.offsetX;const i=t.clientY-this._core.store.offsetY;const r=e-this.initialMouseX;const s=i-this.initialMouseY;const n=Math.abs(r);const h=Math.abs(s);const l=5;if(n>l||h>l){this.hasResized=true}if(!this.hasResized){return}switch(this._core.store.state.resizeHandleType){case oo.TopLeft:this.newSize.width=this.initialSize.width-r;this.newSize.height=this.initialSize.height-s;this.newSize.x=r/this._core.store.state.scale+this.initialSize.x;this.newSize.y=s/this._core.store.state.scale+this.initialSize.y;break;case oo.TopRight:this.newSize.width=this.initialSize.width+r;this.newSize.height=this.initialSize.height-s;this.newSize.x=this.initialSize.x;this.newSize.y=s/this._core.store.state.scale+this.initialSize.y;break;case oo.BottomLeft:this.newSize.width=this.initialSize.width-r;this.newSize.height=this.initialSize.height+s;this.newSize.x=r/this._core.store.state.scale+this.initialSize.x;this.newSize.y=this.initialSize.y;break;case oo.BottomRight:this.newSize.width=this.initialSize.width+r;this.newSize.height=this.initialSize.height+s;this.newSize.x=this.initialSize.x;this.newSize.y=this.initialSize.y;break}this._core.store.state.selectionGroup.resize(this.newSize.x,this.newSize.y,this.newSize.width,this.newSize.height)}}if(t.pointerType==="touch"){const t=Array.from(this._core.store.state.pointers.values());const e=t[0];if(!e){return}if(this._core.store.state.isResizing&&this._core.store.state.selectionGroup){const t=Math.round(e.clientX-this._core.store.offsetX);const i=Math.round(e.clientY-this._core.store.offsetY);const r=t-this.initialMouseX;const s=i-this.initialMouseY;const n=Math.abs(r);const h=Math.abs(s);const l=5;if(n>l||h>l){clearTimeout(this._core.store.state.longTouchTimeout);this.hasResized=true}if(!this.hasResized){return}switch(this._core.store.state.resizeHandleType){case oo.TopLeft:this.newSize.width=this.initialSize.width-r;this.newSize.height=this.initialSize.height-s;this.newSize.x=r/this._core.store.state.scale+this.initialSize.x;this.newSize.y=s/this._core.store.state.scale+this.initialSize.y;break;case oo.TopRight:this.newSize.width=this.initialSize.width+r;this.newSize.height=this.initialSize.height-s;this.newSize.x=this.initialSize.x;this.newSize.y=s/this._core.store.state.scale+this.initialSize.y;break;case oo.BottomLeft:this.newSize.width=this.initialSize.width-r;this.newSize.height=this.initialSize.height+s;this.newSize.x=r/this._core.store.state.scale+this.initialSize.x;this.newSize.y=this.initialSize.y;break;case oo.BottomRight:this.newSize.width=this.initialSize.width+r;this.newSize.height=this.initialSize.height+s;this.newSize.x=this.initialSize.x;this.newSize.y=this.initialSize.y;break}this._core.store.state.selectionGroup.resize(this.newSize.x,this.newSize.y,this.newSize.width,this.newSize.height)}}}handlePointerUp(t){if(t.pointerType==="mouse"){if(this._core.store.state.isResizing){this._core.store.state.isResizing=false;if(this.hasResized){this._core.commandManager.executeCommand(new fo(this._core,this,structuredClone(this.initialSize),structuredClone(this.newSize)));this._core.store.state.hasObjectsChanged=true}this.reset()}}if(t.pointerType==="touch"){if(this._core.store.state.isResizing){this._core.store.state.isResizing=false;if(this.hasResized){this._core.commandManager.executeCommand(new fo(this._core,this,structuredClone(this.initialSize),structuredClone(this.newSize)));this._core.store.state.hasObjectsChanged=true}this.reset();clearTimeout(this._core.store.state.longTouchTimeout)}}}}class ao extends n{rotation;initialRotation;selectionGroup;constructor(t,e,i,r,s=false){super(t,e,s);this.rotation=i;this.initialRotation=r;this.selectionGroup=this._core.store.state.selectionGroup}execute(){this._core.store.state.selectionGroup=this.selectionGroup;this._core.store.state.selectionGroup.rotate(this.rotation);this._core.store.state.selectionGroup.objects.forEach((t=>{this._core.store.state.objectsMap.update(t);this._core.updateObjectInDatabase(t)}))}undo(){this._core.store.state.selectionGroup=this.selectionGroup;this._core.store.state.selectionGroup.rotate(this.initialRotation);this._core.store.state.selectionGroup.objects.forEach((t=>{this._core.store.state.objectsMap.update(t);this._core.updateObjectInDatabase(t)}))}}class co extends ho{initialRotation=0;rotation=0;unchangedObjects=[];initialSelectionGroupRotation=0;constructor(t){super(t)}reset(){this.initialRotation=0;this.rotation=0;this.unchangedObjects=[]}handlePointerDown(t){if(t.pointerType==="mouse"){if(Vl.isLeftClick(t)){if(this._core.store.state.selectionGroup&&this._core.store.state.isRotationHandleSelected){const e=t.clientX-this._core.store.offsetX;const i=t.clientY-this._core.store.offsetY;this._core.store.state.isRotating=true;const r=this._core.store.state.selectionGroup.translateX+this._core.store.state.selectionGroup.width/2/this._core.store.state.scale;const s=this._core.store.state.selectionGroup.translateY+this._core.store.state.selectionGroup.height/2/this._core.store.state.scale;const n=(e-this._core.store.state.translateX)/this._core.store.state.scale;const h=(i-this._core.store.state.translateY)/this._core.store.state.scale;this.initialSelectionGroupRotation=this._core.store.state.selectionGroup.rotation;this.initialRotation=Math.atan2(s-h,r-n)-this._core.store.state.selectionGroup.rotation;this.unchangedObjects=this._core.store.state.selectionGroup.objects.map((t=>t.clone()))}}}if(t.pointerType==="touch"){const t=Array.from(this._core.store.state.pointers.values());const e=t[0];if(!e){return}if(t.length===1){if(this._core.store.state.selectionGroup&&this._core.store.state.isRotationHandleSelected){const t=Math.round(e.clientX-this._core.store.offsetX);const i=Math.round(e.clientY-this._core.store.offsetY);this._core.store.state.isRotating=true;const r=this._core.store.state.selectionGroup.translateX+this._core.store.state.selectionGroup.width/2/this._core.store.state.scale;const s=this._core.store.state.selectionGroup.translateY+this._core.store.state.selectionGroup.height/2/this._core.store.state.scale;const n=(t-this._core.store.state.translateX)/this._core.store.state.scale;const h=(i-this._core.store.state.translateY)/this._core.store.state.scale;this.initialSelectionGroupRotation=this._core.store.state.selectionGroup.rotation;this.initialRotation=Math.atan2(s-h,r-n)-this._core.store.state.selectionGroup.rotation;this.unchangedObjects=this._core.store.state.selectionGroup.objects.map((t=>t.clone()));clearTimeout(this._core.store.state.longTouchTimeout)}}}}handlePointerMove(t){if(t.pointerType==="mouse"){if(this._core.store.state.isRotating&&this._core.store.state.selectionGroup){const e=t.clientX-this._core.store.offsetX;const i=t.clientY-this._core.store.offsetY;const r=this._core.store.state.selectionGroup.translateX+this._core.store.state.selectionGroup.width/2/this._core.store.state.scale;const s=this._core.store.state.selectionGroup.translateY+this._core.store.state.selectionGroup.height/2/this._core.store.state.scale;const n=(e-this._core.store.state.translateX)/this._core.store.state.scale;const h=(i-this._core.store.state.translateY)/this._core.store.state.scale;const l=Math.atan2(s-h,r-n);this.rotation=l-this.initialRotation;this._core.store.state.selectionGroup.rotate(this.rotation)}}if(t.pointerType==="touch"){const t=Array.from(this._core.store.state.pointers.values());const e=t[0];if(!e){return}if(this._core.store.state.isRotating&&this._core.store.state.selectionGroup){const t=Math.round(e.clientX-this._core.store.offsetX);const i=Math.round(e.clientY-this._core.store.offsetY);const r=this._core.store.state.selectionGroup.translateX+this._core.store.state.selectionGroup.width/2/this._core.store.state.scale;const s=this._core.store.state.selectionGroup.translateY+this._core.store.state.selectionGroup.height/2/this._core.store.state.scale;const n=(t-this._core.store.state.translateX)/this._core.store.state.scale;const h=(i-this._core.store.state.translateY)/this._core.store.state.scale;const l=Math.atan2(s-h,r-n);this.rotation=l-this.initialRotation;this._core.store.state.selectionGroup.rotate(this.rotation);clearTimeout(this._core.store.state.longTouchTimeout)}}}handlePointerUp(t){if(t.pointerType==="mouse"){if(this._core.store.state.isRotating){this._core.commandManager.executeCommand(new ao(this._core,this,this.rotation,this.initialSelectionGroupRotation));this._core.store.state.isRotating=false;this._core.store.state.hasObjectsChanged=true;this.reset()}}if(t.pointerType==="touch"){if(this._core.store.state.isRotating){this._core.commandManager.executeCommand(new ao(this._core,this,this.rotation,this.initialSelectionGroupRotation));this._core.store.state.isRotating=false;this._core.store.state.hasObjectsChanged=true;this.reset();clearTimeout(this._core.store.state.longTouchTimeout)}}}}class po extends r{__class__="KrtizelSelectionBox";objects=[];static create(t){const e=new po;e._core=t;e.id=e.generateId();e.workspaceId=t.store.state.activeWorkspace.id;e.scale=t.store.state.scale;e.zIndex=99999;e.backgroundColor="var(--kritzel-selection-box-background-color, rgba(0, 122, 255, 0.2))";e.borderColor="var(--kritzel-selection-box-border-color, rgba(0, 122, 255, 0.5))";e.borderWidth=2;e.height=0;e.width=0;return e}}class wo extends n{selectionGroup;previousSelectionGroup;constructor(t,e,i,r,s=false){super(t,e,s);this.selectionGroup=i;this.previousSelectionGroup=r||null}execute(){this._core.store.state.objectsMap.remove((t=>t instanceof po||t instanceof xo));this._core.store.state.objectsMap.insert(this.selectionGroup);this._core.store.state.selectionGroup=this.selectionGroup;this._core.store.state.selectionBox=null}undo(){this._core.store.state.objectsMap.remove((t=>t.id===this.selectionGroup.id));this._core.store.state.selectionGroup=this.previousSelectionGroup;this._core.store.state.selectionBox=null}}class mo extends ho{startX;startY;touchStartX=0;touchStartY=0;touchStartTimeout=null;get isSelectionClick(){return this._core.store.state.selectionBox&&this._core.store.state.selectionBox.width===0&&this._core.store.state.selectionBox.height===0}get isSelectionDrag(){return this._core.store.state.selectionBox&&(this._core.store.state.selectionBox.width>0||this._core.store.state.selectionBox.height>0)}constructor(t){super(t)}handlePointerDown(t){if(t.pointerType==="mouse"){if(Vl.isLeftClick(t)&&!this._core.store.state.selectionGroup){this.startMouseSelection(t)}}if(t.pointerType==="touch"){this.touchStartTimeout=setTimeout((()=>{if(this._core.store.state.pointers.size===1&&!this._core.store.state.isScaling&&!this._core.store.state.selectionGroup){this.startTouchSelection();this.updateTouchSelection()}}),80)}}handlePointerMove(t){if(t.pointerType==="mouse"){if(this._core.store.state.isSelecting){this.updateMouseSelection(t)}}if(t.pointerType==="touch"){const t=Array.from(this._core.store.state.pointers.values());const e=Math.round(t[0].clientX-this._core.store.offsetX);const i=Math.round(t[0].clientY-this._core.store.offsetY);const r=Math.abs(e-this.touchStartX);const s=Math.abs(i-this.touchStartY);const n=5;if((r>n||s>n)&&this._core.store.state.isSelecting){this.updateTouchSelection();clearTimeout(this._core.store.state.longTouchTimeout)}}}handlePointerUp(t){if(t.pointerType==="mouse"){if(Vl.isLeftClick(t)){const e=this._core.store.state.hasObjectsChanged;if(this._core.store.state.selectionGroup?.objects.length===1&&e===false){this._core.store.state.selectionGroup.objects[0].edit(t)}this._core.store.state.hasObjectsChanged=false;if(this._core.store.state.isSelecting){if(this.isSelectionClick){this.handleSelectionClick(t)}if(this.isSelectionDrag){this.updateMouseSelection(t);this.addSelectedObjectsToSelectionGroup();this.removeSelectionBox()}}}}if(t.pointerType==="touch"){clearTimeout(this.touchStartTimeout);const e=this._core.store.state.hasObjectsChanged;if(this._core.store.state.selectionGroup?.objects.length===1&&e===false){this._core.store.state.selectionGroup.objects[0].edit(t)}this._core.store.state.hasObjectsChanged=false;if(this._core.store.state.isSelecting){if(this.isSelectionClick){this.handleSelectionClick(t)}if(this.isSelectionDrag){this.updateTouchSelection();this.addSelectedObjectsToSelectionGroup();this.removeSelectionBox()}this._core.store.state.skipContextMenu=false}}}removeSelectionBox(){this._core.store.state.selectionBox=null;this._core.store.state.isSelecting=false;this._core.store.state.objectsMap.remove((t=>t instanceof po))}startMouseSelection(t){let e,i;e=t.clientX-this._core.store.offsetX;i=t.clientY-this._core.store.offsetY;const r=po.create(this._core);this.startX=(e-this._core.store.state.translateX)/this._core.store.state.scale;this.startY=(i-this._core.store.state.translateY)/this._core.store.state.scale;r.translateX=this.startX;r.translateY=this.startY;this._core.store.state.selectionGroup=null;this._core.store.state.selectionBox=r;this._core.store.state.isSelecting=true;this._core.store.state.objectsMap.remove((t=>t instanceof po||t instanceof xo));this._core.store.state.objectsMap.insert(r)}startTouchSelection(){const t=Array.from(this._core.store.state.pointers.values());const e=t[0];if(!e){return}let i,r;i=Math.round(e.clientX-this._core.store.offsetX);r=Math.round(e.clientY-this._core.store.offsetY);this.touchStartX=i;this.touchStartY=r;const s=po.create(this._core);this.startX=(i-this._core.store.state.translateX)/this._core.store.state.scale;this.startY=(r-this._core.store.state.translateY)/this._core.store.state.scale;s.translateX=this.startX;s.translateY=this.startY;this._core.store.state.selectionGroup=null;this._core.store.state.selectionBox=s;this._core.store.state.isSelecting=true;this._core.store.state.objectsMap.remove((t=>t instanceof po||t instanceof xo));this._core.store.state.objectsMap.insert(s)}updateMouseSelection(t){let e,i;e=t.clientX-this._core.store.offsetX;i=t.clientY-this._core.store.offsetY;const r=this._core.store.state.selectionBox;if(r){const t=(e-this._core.store.state.translateX)/r.scale;const s=(i-this._core.store.state.translateY)/r.scale;const n=Math.abs(t-this.startX)*r.scale;const h=Math.abs(s-this.startY)*r.scale;r.width=n;r.height=h;r.translateX=Math.min(t,this.startX);r.translateY=Math.min(s,this.startY);if(n>0||h>0){this.updateSelectedObjects()}else{this.clearSelectionPreview()}}}updateTouchSelection(){const t=Array.from(this._core.store.state.pointers.values());const e=t[0];if(!e){return}let i,r;i=Math.round(e.clientX-this._core.store.offsetX);r=Math.round(e.clientY-this._core.store.offsetY);const s=this._core.store.state.selectionBox;if(s){const t=(i-this._core.store.state.translateX)/s.scale;const e=(r-this._core.store.state.translateY)/s.scale;const n=Math.abs(t-this.startX)*s.scale;const h=Math.abs(e-this.startY)*s.scale;s.width=n;s.height=h;s.translateX=Math.min(t,this.startX);s.translateY=Math.min(e,this.startY);if(n>0||h>0){this.updateSelectedObjects()}else{this.clearSelectionPreview()}}}updateSelectedObjects(){this._core.store.allObjects.filter((t=>!(t instanceof po))).forEach((t=>t.isSelected=t.hitTestPolygon(this._core.store.state.selectionBox.rotatedPolygon)))}handleSelectionClick(t){const e=this.getTopmostHitObject(t);this.clearSelectionPreview();this.addObjectToSelectionGroup(e);this.removeSelectionBox()}getTopmostHitObject(t){const e=this._core.store.state.pointerX;const i=this._core.store.state.pointerY;const r=this._core.getObjectsFromPointerEvent(t,".object");for(const t of r){if(t.hitTest(e,i)){return t}}return null}clearSelectionPreview(){this._core.store.allNonSelectionObjects.forEach((t=>{t.isSelected=false}))}addObjectToSelectionGroup(t){if(!t){return}t.isSelected=false;const e=xo.create(this._core);e.addOrRemove(t);e.isSelected=true;e.rotation=t.rotation;this._core.commandManager.executeCommand(new wo(this._core,this,e))}addSelectedObjectsToSelectionGroup(){const t=this._core.store.selectedObjects;if(t.length===0){return}this._core.store.state.selectionGroup=xo.create(this._core);t.forEach((t=>{this._core.store.state.selectionGroup.addOrRemove(t);t.isSelected=false}));const e=this._core.store.state.selectionGroup;e.isSelected=true;if(e.length===1){e.rotation=e.objects[0].rotation}this._core.commandManager.executeCommand(new wo(this._core,this,e))}}class go extends ho{constructor(t){super(t)}handlePointerMove(t){if(t.pointerType==="mouse"){const e=this._core.getObjectFromPointerEvent(t,".object");if(!e)return;const i=this._core.store.state.pointerX;const r=this._core.store.state.pointerY;e.isHovered=e.hitTest(i,r)}}}class bo extends Zl{selectionHandler;moveHandler;hoverHandler;resizeHandler;rotationHandler;constructor(t){super(t);this.selectionHandler=new mo(this._core);this.moveHandler=new lo(this._core);this.hoverHandler=new go(this._core);this.resizeHandler=new uo(this._core);this.rotationHandler=new co(this._core)}handlePointerDown(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){if(Vl.isLeftClick(t)){this._core.store.state.isResizeHandleSelected=this.isHandleSelected(t);this._core.store.state.isRotationHandleSelected=this.isRotationHandleSelected(t);this._core.store.state.resizeHandleType=this.getHandleType(t);const e=this.getSelectedObject(t);const i=e&&this._core.store.state.selectionGroup&&e.id!==this._core.store.state.selectionGroup.id;if((e===null||i)&&this._core.store.state.selectionGroup&&!this._core.store.state.isResizeHandleSelected&&!this._core.store.state.isRotationHandleSelected){this._core.commandManager.executeCommand(new so(this._core,this._core.store.state.selectionGroup))}if(e&&e.isSelected===false&&e?.objects.length===1&&e.objects[0].isInteractive){return}}this.moveHandler.handlePointerDown(t);this.selectionHandler.handlePointerDown(t);this.resizeHandler.handlePointerDown(t);this.rotationHandler.handlePointerDown(t);this._core.rerender()}if(t.pointerType==="touch"){if(this._core.store.state.isScaling===true){return}if(this._core.store.state.pointers.size===1){this._core.store.state.isResizeHandleSelected=this.isHandleSelected(t);this._core.store.state.isRotationHandleSelected=this.isRotationHandleSelected(t);this._core.store.state.resizeHandleType=this.getHandleType(t);const e=this.getSelectedObject(t);const i=e&&this._core.store.state.selectionGroup&&e.id!==this._core.store.state.selectionGroup.id;if(!this._core.store.state.selectionGroup&&e){this._core.store.state.skipContextMenu=true}if((e===null||i)&&this._core.store.state.selectionGroup&&!this._core.store.state.isResizeHandleSelected&&!this._core.store.state.isRotationHandleSelected){this._core.commandManager.executeCommand(new so(this._core,this._core.store.state.selectionGroup))}}this.rotationHandler.handlePointerDown(t);this.resizeHandler.handlePointerDown(t);this.moveHandler.handlePointerDown(t);this.selectionHandler.handlePointerDown(t);this._core.rerender()}}handlePointerMove(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){this.moveHandler.handlePointerMove(t);this.hoverHandler.handlePointerMove(t);this.selectionHandler.handlePointerMove(t);this.resizeHandler.handlePointerMove(t);this.rotationHandler.handlePointerMove(t);this._core.rerender()}if(t.pointerType==="touch"){if(this._core.store.state.isScaling===true){return}this.rotationHandler.handlePointerMove(t);this.resizeHandler.handlePointerMove(t);this.moveHandler.handlePointerMove(t);this.selectionHandler.handlePointerMove(t);this._core.rerender()}}handlePointerUp(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){this.moveHandler.handlePointerUp(t);this.resizeHandler.handlePointerUp(t);this.rotationHandler.handlePointerUp(t);this.selectionHandler.handlePointerUp(t);this._core.rerender()}if(t.pointerType==="touch"){if(this._core.store.state.isScaling===true){return}this.rotationHandler.handlePointerUp(t);this.resizeHandler.handlePointerUp(t);this.moveHandler.handlePointerUp(t);this.selectionHandler.handlePointerUp(t);this._core.rerender()}}getSelectedObject(t){const e=t.composedPath().slice(1);const i=e.find((t=>t.classList&&t.classList.contains("object")));const r=this._core.findObjectById(i?.id);if(!r){return null}if(r instanceof xo){return r}else{const t=xo.create(this._core);t.translateX=0;t.translateY=0;t.addOrRemove(r);return t}}getHandleType(t){const e=this._core.store.state.host?.shadowRoot;if(!e)return;const i=e.elementFromPoint(t.clientX,t.clientY);const r=i?.closest(".resize-handle-overlay");return r?.classList[1]}isHandleSelected(t){const e=this._core.store.state.host?.shadowRoot;if(!e)return false;const i=e.elementFromPoint(t.clientX,t.clientY);return!!i?.classList.contains("resize-handle-overlay")}isRotationHandleSelected(t){const e=t.composedPath();return!!e.find((t=>t.classList&&t.classList.contains("rotation-handle-overlay")))}}class vo extends Zl{fontFamily="Arial";fontSize=16;fontColor="#000000";palette=["#000000","#FFFFFF","#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF","#00FFFF","#808080","#C0C0C0","#800000","#008000","#000080","#808000","#800080"];constructor(t){super(t)}handlePointerDown(e){if(e.cancelable){e.preventDefault()}if(e.pointerType==="mouse"){const i=e.composedPath().slice(1);const r=i.find((t=>t.classList&&t.classList.contains("object")));const s=this._core.findObjectById(r?.id);if(this._core.store.state.activeText===null&&s instanceof Wl){this._core.store.state.activeText=s;s.edit(e);return}if(this._core.store.state.activeText!==null&&s instanceof Wl){this._core.store.state.activeText.save();this._core.store.state.activeText=s;s.edit(e);return}if(this._core.store.state.activeText!==null&&s instanceof Wl===false){this._core.resetActiveText();this._core.store.setState("activeTool",t.getTool("selection"));return}if(Vl.isLeftClick(e)===false){return}const n=e.clientX-this._core.store.offsetX;const h=e.clientY-this._core.store.offsetY;const l=Wl.create(this._core,this.fontSize,this.fontFamily);l.isNew=true;l.fontColor=this.fontColor;l.translateX=(n-this._core.store.state.translateX)/this._core.store.state.scale;l.translateY=(h-this._core.store.state.translateY)/this._core.store.state.scale;l.zIndex=this._core.store.currentZIndex;this._core.store.state.activeText=l;this._core.store.state.objectsMap.insert(l);this._core.rerender();requestAnimationFrame((()=>l.edit(e)))}if(e.pointerType==="touch"){const i=Array.from(this._core.store.state.pointers.values());const r=e.composedPath().slice(1);const n=r.find((t=>t.classList&&t.classList.contains("object")));const h=this._core.findObjectById(n?.id);if(this._core.store.state.activeText===null&&h instanceof Wl){this._core.store.state.activeText=h;h.edit(e);return}if(this._core.store.state.activeText!==null&&h instanceof Wl){this._core.store.state.activeText.save();this._core.store.state.activeText=h;h.edit(e);return}if(this._core.store.state.activeText!==null&&h instanceof Wl===false){this._core.resetActiveText();this._core.store.setState("activeTool",t.getTool("selection"));return}if(i.length>1){return}s.disableInteractiveWidget();const l=Math.round(i[0].clientX-this._core.store.offsetX);const o=Math.round(i[0].clientY-this._core.store.offsetY);const f=Wl.create(this._core,this.fontSize,this.fontFamily);f.isNew=true;f.fontColor=this.fontColor;f.translateX=(l-this._core.store.state.translateX)/this._core.store.state.scale;f.translateY=(o-this._core.store.state.translateY)/this._core.store.state.scale;f.zIndex=this._core.store.currentZIndex;this._core.store.state.activeText=f;this._core.store.state.objectsMap.insert(f);this._core.rerender()}}handlePointerUp(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){this._core.store.state.activeText?.edit(t)}if(t.pointerType==="touch"){this._core.store.state.activeText?.edit(t);s.enableInteractiveWidget()}}}class yo extends r{__class__="KritzelCustomElement";element;isInteractive=true;constructor(t){super();if(t){this.translateX=t.translateX||0;this.translateY=t.translateY||0;this.scale=t.scale||1;this.element=t.element;this.height=t.height||0;this.width=t.width||0}}static create(t,e){const i=new yo(e);i._core=t;i.id=i.generateId();i.workspaceId=t.store.state.activeWorkspace.id;return i}mount(t){if(t===null){return}if(this.isMounted&&this.elementRef===t&&this.element.parentElement===t){return}this.elementRef=t;this.isMounted=true;this.elementRef.innerHTML="";this.elementRef.appendChild(this.element)}resize(t,e,i,r){if(i<=1||r<=1){return}this.width=i;this.height=r;this.translateX=t;this.translateY=e;if(this.element){this.element.style.width=`${i}px`;this.element.style.height=`${r}px`}}copy(){const t=Object.create(Object.getPrototypeOf(this));Object.assign(t,this);t.id=this.generateId();t.isMounted=false;t.element=this.element.cloneNode(true);return t}}const Mo={type:"pen",color:"#000000",size:16,palettes:{pen:["#000000","#ff5252","#ffbc00","#00c853","#0000FF","#d500f9","#fafafa","#a52714","#ee8100","#558b2f","#01579b","#8e24aa","#90a4ae","#ff4081","#ff6e40","#aeea00","#304ffe","#7c4dff","#cfd8dc","#f8bbd0","#ffccbc","#f0f4c3","#9fa8da","#d1c4e9"],highlighter:["#0000006e","#ff52526e","#ffbb006e","#00c8536e","#0000FF6e","#d500f96e","#fafafa6e","#a527146e","#ee81006e","#558b2f6e","#01579b6e","#8e24aa6e","#90a4ae6e","#ff40816e","#ff6e406e","#aeea006e","#304ffe6e","#7c4dff6e","#cfd8dc6e","#f8bbd06e","#ffccbc6e","#f0f4c36e","#9fa8da6e","#d1c4e96e"]}};const Ao={color:"#000000",size:8,fontFamily:"Arial",palette:["#000000","#ff5252","#ffbc00","#00c853","#0000FF","#d500f9","#fafafa","#a52714","#ee8100","#558b2f","#01579b","#8e24aa","#90a4ae","#ff4081","#ff6e40","#aeea00","#304ffe","#7c4dff","#cfd8dc","#f8bbd0","#ffccbc","#f0f4c3","#9fa8da","#d1c4e9"]};class ko{__class__="KritzelWorkspace";id;name;createdAt;updatedAt;viewport;_core;constructor(t,e,i={translateX:0,translateY:0,scale:1}){this.id=t;this.name=e;this.createdAt=new Date;this.updatedAt=new Date;this.viewport=i}static create(t,e){const i=new ko(e.id,e.name,e.viewport);i._core=t;Object.assign(i,e);return i}addObject(t){this._core.engine.addObject(t)}serialize(){return{__class__:this.__class__,id:this.id,name:this.name,createdAt:this.createdAt,updatedAt:this.updatedAt,viewport:this.viewport}}deserialize(t){Object.assign(this,t);this.createdAt=new Date(t.createdAt);this.updatedAt=new Date(t.updatedAt);return this}}class So{_core;constructor(t){this._core=t}revive(t){if(t&&typeof t==="object"){if(t.__class__){let e;switch(t.__class__){case"KritzelPath":e=Gl.create(this._core).deserialize(t);break;case"KritzelText":e=Wl.create(this._core,t.fontSize,t.fontFamily).deserialize(t);break;case"KritzelImage":e=Xl.create(this._core).deserialize(t);break;case"KritzelCustomElement":e=yo.create(this._core).deserialize(t);break;case"KritzelSelectionGroup":e=xo.create(this._core).deserialize(t);break;case"KritzelWorkspace":e=ko.create(this._core,t).deserialize(t);break;case"KritzelBrushTool":e=new to(this._core);break;case"KritzelEraserTool":e=new ro(this._core);break;case"KritzelImageTool":e=new of(this._core);break;case"KritzelSelectionTool":e=new bo(this._core);break;case"KritzelTextTool":e=new vo(this._core);break;default:e=t}return e}const e=Array.isArray(t)?[]:{};for(const i in t){if(Object.prototype.hasOwnProperty.call(t,i)){e[i]=this.revive(t[i])}}return e}return t}}class xo extends r{__class__="KritzelSelectionGroup";objects=[];unchangedObjects=[];minX;maxX;minY;maxY;get length(){return this.objects.length}static create(t){const e=new xo;e._core=t;e.id=e.generateId();e.workspaceId=t.store.state.activeWorkspace.id;e.scale=t.store.state.scale;e.zIndex=99999;return e}addOrRemove(t){const e=this.objects.findIndex((e=>e.id===t.id));if(e===-1){this.objects.push(t)}else{this.objects.splice(e,1)}this.unchangedObjects=this.objects.map((t=>t.clone()));this.refreshObjectDimensions()}deselectAllChildren(){this.objects.forEach((t=>t.isSelected=false))}updateWorkspaceId(t){this.workspaceId=t;this.objects.forEach((e=>e.workspaceId=t))}updateZIndices(t){this.objects.forEach(((e,i)=>{e.zIndex=t+i}))}updatePosition(t,e){this.objects.forEach((i=>{const r=i.translateX-this.translateX;const s=i.translateY-this.translateY;i.updatePosition(t+r,e+s)}));this.unchangedObjects.forEach((i=>{const r=i.translateX-this.translateX;const s=i.translateY-this.translateY;i.translateX=t+r;i.translateY=e+s}));this.translateX=t;this.translateY=e;this._core.store.state.objectsMap.update(this)}move(t,e,i,r){const s=(t-i)/this._core.store.state.scale;const n=(e-r)/this._core.store.state.scale;this.translateX+=s;this.translateY+=n;this._core.store.state.objectsMap.update(this);this.objects.forEach((s=>{s.move(t,e,i,r);this._core.store.state.objectsMap.update(s)}));this.unchangedObjects.forEach((t=>{t.translateX+=s;t.translateY+=n}))}resize(t,e,i,r){const s=i/this.width;const n=r/this.height;const h=t-this.translateX;const l=e-this.translateY;this.objects.forEach((t=>{const e=t.width*s;const i=t.height*n;const r=t.translateX+h+(t.translateX-this.translateX)*(s-1);const o=t.translateY+l+(t.translateY-this.translateY)*(n-1);t.resize(r,o,e,i);this._core.store.state.objectsMap.update(t)}));this.refreshObjectDimensions();this.unchangedObjects=this.objects.map((t=>t.clone()))}rotate(t){this.rotation=t;const e=this.translateX+this.totalWidth/2/this.scale;const i=this.translateY+this.totalHeight/2/this.scale;const r=t;const s=Math.cos(r);const n=Math.sin(r);this.objects.forEach((r=>{const h=this.getUnchangedObject(r.id);const l=this.getOffsetXToCenter(h);const o=this.getOffsetYToCenter(h);const f=s*l-n*o;const u=n*l+s*o;r.translateX=e+f-r.totalWidth/2/r.scale;r.translateY=i+u-r.totalHeight/2/r.scale;r.rotate(this.objects.length===1?t:t+h.rotation);this._core.store.state.objectsMap.update(r)}))}copy(){const t=xo.create(this._core);this.objects.sort(((t,e)=>t.zIndex-e.zIndex)).forEach((e=>{const i=e.copy();t.addOrRemove(i)}));t.unchangedObjects=t.objects.map((t=>t.clone()));if(this.objects.length===1){t.rotation=this.objects[0].rotation}return t}refreshObjectDimensions(){if(this.objects.length===1){const t=this.objects[0];this.minX=t.boundingBox.x/this.scale;this.maxX=t.boundingBox.x/this.scale+t.boundingBox.width;this.minY=t.boundingBox.y/this.scale;this.maxY=t.boundingBox.y/this.scale+t.boundingBox.height;this.translateX=(this.minX-this.padding)*this.scale;this.translateY=(this.minY-this.padding)*this.scale;this.width=(this.maxX-this.minX-this.padding)*this.scale;this.height=(this.maxY-this.minY-this.padding)*this.scale}else{this.minX=Math.min(...this.objects.map((t=>t.minXRotated)));this.maxX=Math.max(...this.objects.map((t=>t.maxXRotated)));this.minY=Math.min(...this.objects.map((t=>t.minYRotated)));this.maxY=Math.max(...this.objects.map((t=>t.maxYRotated)));this.translateX=this.minX-this.padding;this.translateY=this.minY-this.padding;this.width=(this.maxX-this.minX-this.padding)*this.scale;this.height=(this.maxY-this.minY-this.padding)*this.scale}this._core.store.state.objectsMap.update(this)}getOffsetXToCenter(t){const e=t.translateX+t.totalWidth/t.scale/2;const i=this.translateX+this.totalWidth/this.scale/2;return e-i}getOffsetYToCenter(t){const e=t.translateY+t.totalHeight/t.scale/2;const i=this.translateY+this.totalHeight/this.scale/2;return e-i}getUnchangedObject(t){const e=this.unchangedObjects.find((e=>e.id===t));const i=new So(this._core);return i.revive(e)}}function Eo(t,e){return e.forEach((function(e){e&&"string"!=typeof e&&!Array.isArray(e)&&Object.keys(e).forEach((function(i){if("default"!==i&&!(i in t)){var r=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,r.get?r:{enumerable:true,get:function(){return e[i]}})}}))})),Object.freeze(t)}function Oo(t,e){return new Promise((function(i,r){let s;return Do(t).then((function(t){try{return s=t,i(new Blob([e.slice(0,2),s,e.slice(2)],{type:"image/jpeg"}))}catch(t){return r(t)}}),r)}))}const Do=t=>new Promise(((e,i)=>{const r=new FileReader;r.addEventListener("load",(({target:{result:t}})=>{const r=new DataView(t);let s=0;if(65496!==r.getUint16(s))return i("not a valid JPEG");for(s+=2;;){const n=r.getUint16(s);if(65498===n)break;const h=r.getUint16(s+2);if(65505===n&&1165519206===r.getUint32(s+4)){const n=s+10;let l;switch(r.getUint16(n)){case 18761:l=true;break;case 19789:l=false;break;default:return i("TIFF header contains invalid endian")}if(42!==r.getUint16(n+2,l))return i("TIFF header contains invalid version");const o=r.getUint32(n+4,l),f=n+o+2+12*r.getUint16(n+o,l);for(let t=n+o+2;t<f;t+=12){if(274==r.getUint16(t,l)){if(3!==r.getUint16(t+2,l))return i("Orientation data type is invalid");if(1!==r.getUint32(t+4,l))return i("Orientation data count is invalid");r.setUint16(t+8,1,l);break}}return e(t.slice(s,s+2+h))}s+=2+h}return e(new Blob)})),r.readAsArrayBuffer(t)}));var To={},Ro={get exports(){return To},set exports(t){To=t}};!function(t){var e,i,r={};Ro.exports=r,r.parse=function(t,e){for(var i=r.bin.readUshort,s=r.bin.readUint,n=0,h={},l=new Uint8Array(t),o=l.length-4;101010256!=s(l,o);)o--;n=o;n+=4;var f=i(l,n+=4);i(l,n+=2);var u=s(l,n+=2),a=s(l,n+=4);n+=4,n=a;for(var c=0;c<f;c++){s(l,n),n+=4,n+=4,n+=4,s(l,n+=4);u=s(l,n+=4);var d=s(l,n+=4),p=i(l,n+=4),w=i(l,n+2),m=i(l,n+4);n+=6;var g=s(l,n+=8);n+=4,n+=p+w+m,r._readLocal(l,g,h,u,d,e)}return h},r._readLocal=function(t,e,i,s,n,h){var l=r.bin.readUshort,o=r.bin.readUint;o(t,e),l(t,e+=4),l(t,e+=2);var f=l(t,e+=2);o(t,e+=2),o(t,e+=4),e+=4;var u=l(t,e+=8),a=l(t,e+=2);e+=2;var c=r.bin.readUTF8(t,e,u);if(e+=u,e+=a,h)i[c]={size:n,csize:s};else{var d=new Uint8Array(t.buffer,e);if(0==f)i[c]=new Uint8Array(d.buffer.slice(e,e+s));else{if(8!=f)throw"unknown compression method: "+f;var p=new Uint8Array(n);r.inflateRaw(d,p),i[c]=p}}},r.inflateRaw=function(t,e){return r.F.inflate(t,e)},r.inflate=function(t,e){return r.inflateRaw(new Uint8Array(t.buffer,t.byteOffset+2,t.length-6),e)},r.deflate=function(t,e){null==e&&(e={level:6});var i=0,s=new Uint8Array(50+Math.floor(1.1*t.length));s[i]=120,s[i+1]=156,i+=2,i=r.F.deflateRaw(t,s,i,e.level);var n=r.adler(t,0,t.length);return s[i+0]=n>>>24&255,s[i+1]=n>>>16&255,s[i+2]=n>>>8&255,s[i+3]=n>>>0&255,new Uint8Array(s.buffer,0,i+4)},r.deflateRaw=function(t,e){null==e&&(e={level:6});var i=new Uint8Array(50+Math.floor(1.1*t.length)),s=r.F.deflateRaw(t,i,s,e.level);return new Uint8Array(i.buffer,0,s)},r.encode=function(t,e){null==e&&(e=false);var i=0,s=r.bin.writeUint,n=r.bin.writeUshort,h={};for(var l in t){var o=!r._noNeed(l)&&!e,f=t[l],u=r.crc.crc(f,0,f.length);h[l]={cpr:o,usize:f.length,crc:u,file:o?r.deflateRaw(f):f}}for(var l in h)i+=h[l].file.length+30+46+2*r.bin.sizeUTF8(l);i+=22;var a=new Uint8Array(i),c=0,d=[];for(var l in h){var p=h[l];d.push(c),c=r._writeHeader(a,c,l,p,0)}var w=0,m=c;for(var l in h){p=h[l];d.push(c),c=r._writeHeader(a,c,l,p,1,d[w++])}var g=c-m;return s(a,c,101010256),c+=4,n(a,c+=4,w),n(a,c+=2,w),s(a,c+=2,g),s(a,c+=4,m),c+=4,c+=2,a.buffer},r._noNeed=function(t){var e=t.split(".").pop().toLowerCase();return-1!="png,jpg,jpeg,zip".indexOf(e)},r._writeHeader=function(t,e,i,s,n,h){var l=r.bin.writeUint,o=r.bin.writeUshort,f=s.file;return l(t,e,0==n?67324752:33639248),e+=4,1==n&&(e+=2),o(t,e,20),o(t,e+=2,0),o(t,e+=2,s.cpr?8:0),l(t,e+=2,0),l(t,e+=4,s.crc),l(t,e+=4,f.length),l(t,e+=4,s.usize),o(t,e+=4,r.bin.sizeUTF8(i)),o(t,e+=2,0),e+=2,1==n&&(e+=2,e+=2,l(t,e+=6,h),e+=4),e+=r.bin.writeUTF8(t,e,i),0==n&&(t.set(f,e),e+=f.length),e},r.crc={table:function(){for(var t=new Uint32Array(256),e=0;e<256;e++){for(var i=e,r=0;r<8;r++)1&i?i=3988292384^i>>>1:i>>>=1;t[e]=i}return t}(),update:function(t,e,i,s){for(var n=0;n<s;n++)t=r.crc.table[255&(t^e[i+n])]^t>>>8;return t},crc:function(t,e,i){return 4294967295^r.crc.update(4294967295,t,e,i)}},r.adler=function(t,e,i){for(var r=1,s=0,n=e,h=e+i;n<h;){for(var l=Math.min(n+5552,h);n<l;)s+=r+=t[n++];r%=65521,s%=65521}return s<<16|r},r.bin={readUshort:function(t,e){return t[e]|t[e+1]<<8},writeUshort:function(t,e,i){t[e]=255&i,t[e+1]=i>>8&255},readUint:function(t,e){return 16777216*t[e+3]+(t[e+2]<<16|t[e+1]<<8|t[e])},writeUint:function(t,e,i){t[e]=255&i,t[e+1]=i>>8&255,t[e+2]=i>>16&255,t[e+3]=i>>24&255},readASCII:function(t,e,i){for(var r="",s=0;s<i;s++)r+=String.fromCharCode(t[e+s]);return r},writeASCII:function(t,e,i){for(var r=0;r<i.length;r++)t[e+r]=i.charCodeAt(r)},pad:function(t){return t.length<2?"0"+t:t},readUTF8:function(t,e,i){for(var s,n="",h=0;h<i;h++)n+="%"+r.bin.pad(t[e+h].toString(16));try{s=decodeURIComponent(n)}catch(s){return r.bin.readASCII(t,e,i)}return s},writeUTF8:function(t,e,i){for(var r=i.length,s=0,n=0;n<r;n++){var h=i.charCodeAt(n);if(0==(4294967168&h))t[e+s]=h,s++;else if(0==(4294965248&h))t[e+s]=192|h>>6,t[e+s+1]=128|h>>0&63,s+=2;else if(0==(4294901760&h))t[e+s]=224|h>>12,t[e+s+1]=128|h>>6&63,t[e+s+2]=128|h>>0&63,s+=3;else{if(0!=(4292870144&h))throw"e";t[e+s]=240|h>>18,t[e+s+1]=128|h>>12&63,t[e+s+2]=128|h>>6&63,t[e+s+3]=128|h>>0&63,s+=4}}return s},sizeUTF8:function(t){for(var e=t.length,i=0,r=0;r<e;r++){var s=t.charCodeAt(r);if(0==(4294967168&s))i++;else if(0==(4294965248&s))i+=2;else if(0==(4294901760&s))i+=3;else{if(0!=(4292870144&s))throw"e";i+=4}}return i}},r.F={},r.F.deflateRaw=function(t,e,i,s){var n=[[0,0,0,0,0],[4,4,8,4,0],[4,5,16,8,0],[4,6,16,16,0],[4,10,16,32,0],[8,16,32,32,0],[8,16,128,128,0],[8,32,128,256,0],[32,128,258,1024,1],[32,258,258,4096,1]][s],h=r.F.U,l=r.F._goodIndex;var o=r.F._putsE,f=0,u=i<<3,a=0,c=t.length;if(0==s){for(;f<c;){o(e,u,f+(S=Math.min(65535,c-f))==c?1:0),u=r.F._copyExact(t,f,S,e,u+8),f+=S}return u>>>3}var d=h.lits,p=h.strt,w=h.prev,m=0,g=0,b=0,v=0,y=0,M=0;for(c>2&&(p[M=r.F._hash(t,0)]=0),f=0;f<c;f++){if(y=M,f+1<c-2){M=r.F._hash(t,f+1);var A=f+1&32767;w[A]=p[M],p[M]=A}if(a<=f){(m>14e3||g>26697)&&c-f>100&&(a<f&&(d[m]=f-a,m+=2,a=f),u=r.F._writeBlock(f==c-1||a==c?1:0,d,m,v,t,b,f-b,e,u),m=g=v=0,b=f);var k=0;f<c-2&&(k=r.F._bestMatch(t,f,w,y,Math.min(n[2],c-f),n[3]));var S=k>>>16,x=65535&k;if(0!=k){x=65535&k;var E=l(S=k>>>16,h.of0);h.lhst[257+E]++;var O=l(x,h.df0);h.dhst[O]++,v+=h.exb[E]+h.dxb[O],d[m]=S<<23|f-a,d[m+1]=x<<16|E<<8|O,m+=2,a=f+S}else h.lhst[t[f]]++;g++}}for(b==f&&0!=t.length||(a<f&&(d[m]=f-a,m+=2,a=f),u=r.F._writeBlock(1,d,m,v,t,b,f-b,e,u),m=0,g=0,m=g=v=0,b=f);0!=(7&u);)u++;return u>>>3},r.F._bestMatch=function(t,e,i,s,n,h){var l=32767&e,o=i[l],f=l-o+32768&32767;if(o==l||s!=r.F._hash(t,e-f))return 0;for(var u=0,a=0,c=Math.min(32767,e);f<=c&&0!=--h&&o!=l;){if(0==u||t[e+u]==t[e+u-f]){var d=r.F._howLong(t,e,f);if(d>u){if(a=f,(u=d)>=n)break;f+2<d&&(d=f+2);for(var p=0,w=0;w<d-2;w++){var m=e-f+w+32768&32767,g=m-i[m]+32768&32767;g>p&&(p=g,o=m)}}}f+=(l=o)-(o=i[l])+32768&32767}return u<<16|a},r.F._howLong=function(t,e,i){if(t[e]!=t[e-i]||t[e+1]!=t[e+1-i]||t[e+2]!=t[e+2-i])return 0;var r=e,s=Math.min(t.length,e+258);for(e+=3;e<s&&t[e]==t[e-i];)e++;return e-r},r.F._hash=function(t,e){return(t[e]<<8|t[e+1])+(t[e+2]<<4)&65535},r.saved=0,r.F._writeBlock=function(t,e,i,s,n,h,l,o,f){var u,a,c,d,p,w,m,g,b,v=r.F.U,y=r.F._putsF,M=r.F._putsE;v.lhst[256]++,a=(u=r.F.getTrees())[0],c=u[1],d=u[2],p=u[3],w=u[4],m=u[5],g=u[6],b=u[7];var A=32+(0==(f+3&7)?0:8-(f+3&7))+(l<<3),k=s+r.F.contSize(v.fltree,v.lhst)+r.F.contSize(v.fdtree,v.dhst),S=s+r.F.contSize(v.ltree,v.lhst)+r.F.contSize(v.dtree,v.dhst);S+=14+3*m+r.F.contSize(v.itree,v.ihst)+(2*v.ihst[16]+3*v.ihst[17]+7*v.ihst[18]);for(var x=0;x<286;x++)v.lhst[x]=0;for(x=0;x<30;x++)v.dhst[x]=0;for(x=0;x<19;x++)v.ihst[x]=0;var E=A<k&&A<S?0:k<S?1:2;if(y(o,f,t),y(o,f+1,E),f+=3,0==E){for(;0!=(7&f);)f++;f=r.F._copyExact(n,h,l,o,f)}else{var O,D;if(1==E&&(O=v.fltree,D=v.fdtree),2==E){r.F.makeCodes(v.ltree,a),r.F.revCodes(v.ltree,a),r.F.makeCodes(v.dtree,c),r.F.revCodes(v.dtree,c),r.F.makeCodes(v.itree,d),r.F.revCodes(v.itree,d),O=v.ltree,D=v.dtree,M(o,f,p-257),M(o,f+=5,w-1),M(o,f+=5,m-4),f+=4;for(var T=0;T<m;T++)M(o,f+3*T,v.itree[1+(v.ordr[T]<<1)]);f+=3*m,f=r.F._codeTiny(g,v.itree,o,f),f=r.F._codeTiny(b,v.itree,o,f)}for(var R=h,C=0;C<i;C+=2){for(var P=e[C],I=P>>>23,N=R+(8388607&P);R<N;)f=r.F._writeLit(n[R++],O,o,f);if(0!=I){var F=e[C+1],B=F>>16,U=F>>8&255,j=255&F;M(o,f=r.F._writeLit(257+U,O,o,f),I-v.of0[U]),f+=v.exb[U],y(o,f=r.F._writeLit(j,D,o,f),B-v.df0[j]),f+=v.dxb[j],R+=I}}f=r.F._writeLit(256,O,o,f)}return f},r.F._copyExact=function(t,e,i,r,s){var n=s>>>3;return r[n]=i,r[n+1]=i>>>8,r[n+2]=255-r[n],r[n+3]=255-r[n+1],n+=4,r.set(new Uint8Array(t.buffer,e,i),n),s+(i+4<<3)},r.F.getTrees=function(){for(var t=r.F.U,e=r.F._hufTree(t.lhst,t.ltree,15),i=r.F._hufTree(t.dhst,t.dtree,15),s=[],n=r.F._lenCodes(t.ltree,s),h=[],l=r.F._lenCodes(t.dtree,h),o=0;o<s.length;o+=2)t.ihst[s[o]]++;for(o=0;o<h.length;o+=2)t.ihst[h[o]]++;for(var f=r.F._hufTree(t.ihst,t.itree,7),u=19;u>4&&0==t.itree[1+(t.ordr[u-1]<<1)];)u--;return[e,i,f,n,l,u,s,h]},r.F.getSecond=function(t){for(var e=[],i=0;i<t.length;i+=2)e.push(t[i+1]);return e},r.F.nonZero=function(t){for(var e="",i=0;i<t.length;i+=2)0!=t[i+1]&&(e+=(i>>1)+",");return e},r.F.contSize=function(t,e){for(var i=0,r=0;r<e.length;r++)i+=e[r]*t[1+(r<<1)];return i},r.F._codeTiny=function(t,e,i,s){for(var n=0;n<t.length;n+=2){var h=t[n],l=t[n+1];s=r.F._writeLit(h,e,i,s);var o=16==h?2:17==h?3:7;h>15&&(r.F._putsE(i,s,l,o),s+=o)}return s},r.F._lenCodes=function(t,e){for(var i=t.length;2!=i&&0==t[i-1];)i-=2;for(var r=0;r<i;r+=2){var s=t[r+1],n=r+3<i?t[r+3]:-1,h=r+5<i?t[r+5]:-1,l=0==r?-1:t[r-1];if(0==s&&n==s&&h==s){for(var o=r+5;o+2<i&&t[o+2]==s;)o+=2;(f=Math.min(o+1-r>>>1,138))<11?e.push(17,f-3):e.push(18,f-11),r+=2*f-2}else if(s==l&&n==s&&h==s){for(o=r+5;o+2<i&&t[o+2]==s;)o+=2;var f=Math.min(o+1-r>>>1,6);e.push(16,f-3),r+=2*f-2}else e.push(s,0)}return i>>>1},r.F._hufTree=function(t,e,i){var s=[],n=t.length,h=e.length,l=0;for(l=0;l<h;l+=2)e[l]=0,e[l+1]=0;for(l=0;l<n;l++)0!=t[l]&&s.push({lit:l,f:t[l]});var o=s.length,f=s.slice(0);if(0==o)return 0;if(1==o){var u=s[0].lit;f=0==u?1:0;return e[1+(u<<1)]=1,e[1+(f<<1)]=1,1}s.sort((function(t,e){return t.f-e.f}));var a=s[0],c=s[1],d=0,p=1,w=2;for(s[0]={lit:-1,f:a.f+c.f,l:a,r:c,d:0};p!=o-1;)a=d!=p&&(w==o||s[d].f<s[w].f)?s[d++]:s[w++],c=d!=p&&(w==o||s[d].f<s[w].f)?s[d++]:s[w++],s[p++]={lit:-1,f:a.f+c.f,l:a,r:c};var m=r.F.setDepth(s[p-1],0);for(m>i&&(r.F.restrictDepth(f,i,m),m=i),l=0;l<o;l++)e[1+(f[l].lit<<1)]=f[l].d;return m},r.F.setDepth=function(t,e){return-1!=t.lit?(t.d=e,e):Math.max(r.F.setDepth(t.l,e+1),r.F.setDepth(t.r,e+1))},r.F.restrictDepth=function(t,e,i){var r=0,s=1<<i-e,n=0;for(t.sort((function(t,e){return e.d==t.d?t.f-e.f:e.d-t.d})),r=0;r<t.length&&t[r].d>e;r++){var h=t[r].d;t[r].d=e,n+=s-(1<<i-h)}for(n>>>=i-e;n>0;){(h=t[r].d)<e?(t[r].d++,n-=1<<e-h-1):r++}for(;r>=0;r--)t[r].d==e&&n<0&&(t[r].d--,n++);0!=n&&console.log("debt left")},r.F._goodIndex=function(t,e){var i=0;return e[16|i]<=t&&(i|=16),e[8|i]<=t&&(i|=8),e[4|i]<=t&&(i|=4),e[2|i]<=t&&(i|=2),e[1|i]<=t&&(i|=1),i},r.F._writeLit=function(t,e,i,s){return r.F._putsF(i,s,e[t<<1]),s+e[1+(t<<1)]},r.F.inflate=function(t,e){var i=Uint8Array;if(3==t[0]&&0==t[1])return e||new i(0);var s=r.F,n=s._bitsF,h=s._bitsE,l=s._decodeTiny,o=s.makeCodes,f=s.codes2map,u=s._get17,a=s.U,c=null==e;c&&(e=new i(t.length>>>2<<3));for(var d,p,w=0,m=0,g=0,b=0,v=0,y=0,M=0,A=0,k=0;0==w;)if(w=n(t,k,1),m=n(t,k+1,2),k+=3,0!=m){if(c&&(e=r.F._check(e,A+(1<<17))),1==m&&(d=a.flmap,p=a.fdmap,y=511,M=31),2==m){g=h(t,k,5)+257,b=h(t,k+5,5)+1,v=h(t,k+10,4)+4,k+=14;for(var S=0;S<38;S+=2)a.itree[S]=0,a.itree[S+1]=0;var x=1;for(S=0;S<v;S++){var E=h(t,k+3*S,3);a.itree[1+(a.ordr[S]<<1)]=E,E>x&&(x=E)}k+=3*v,o(a.itree,x),f(a.itree,x,a.imap),d=a.lmap,p=a.dmap,k=l(a.imap,(1<<x)-1,g+b,t,k,a.ttree);var O=s._copyOut(a.ttree,0,g,a.ltree);y=(1<<O)-1;var D=s._copyOut(a.ttree,g,b,a.dtree);M=(1<<D)-1,o(a.ltree,O),f(a.ltree,O,d),o(a.dtree,D),f(a.dtree,D,p)}for(;;){var T=d[u(t,k)&y];k+=15&T;var R=T>>>4;if(R>>>8==0)e[A++]=R;else{if(256==R)break;var C=A+R-254;if(R>264){var P=a.ldef[R-257];C=A+(P>>>3)+h(t,k,7&P),k+=7&P}var I=p[u(t,k)&M];k+=15&I;var N=I>>>4,F=a.ddef[N],B=(F>>>4)+n(t,k,15&F);for(k+=15&F,c&&(e=r.F._check(e,A+(1<<17)));A<C;)e[A]=e[A++-B],e[A]=e[A++-B],e[A]=e[A++-B],e[A]=e[A++-B];A=C}}}else{0!=(7&k)&&(k+=8-(7&k));var U=4+(k>>>3),j=t[U-4]|t[U-3]<<8;c&&(e=r.F._check(e,A+j)),e.set(new i(t.buffer,t.byteOffset+U,j),A),k=U+j<<3,A+=j}return e.length==A?e:e.slice(0,A)},r.F._check=function(t,e){var i=t.length;if(e<=i)return t;var r=new Uint8Array(Math.max(i<<1,e));return r.set(t,0),r},r.F._decodeTiny=function(t,e,i,s,n,h){for(var l=r.F._bitsE,o=r.F._get17,f=0;f<i;){var u=t[o(s,n)&e];n+=15&u;var a=u>>>4;if(a<=15)h[f]=a,f++;else{var c=0,d=0;16==a?(d=3+l(s,n,2),n+=2,c=h[f-1]):17==a?(d=3+l(s,n,3),n+=3):18==a&&(d=11+l(s,n,7),n+=7);for(var p=f+d;f<p;)h[f]=c,f++}}return n},r.F._copyOut=function(t,e,i,r){for(var s=0,n=0,h=r.length>>>1;n<i;){var l=t[n+e];r[n<<1]=0,r[1+(n<<1)]=l,l>s&&(s=l),n++}for(;n<h;)r[n<<1]=0,r[1+(n<<1)]=0,n++;return s},r.F.makeCodes=function(t,e){for(var i,s,n,h,l=r.F.U,o=t.length,f=l.bl_count,u=0;u<=e;u++)f[u]=0;for(u=1;u<o;u+=2)f[t[u]]++;var a=l.next_code;for(i=0,f[0]=0,s=1;s<=e;s++)i=i+f[s-1]<<1,a[s]=i;for(n=0;n<o;n+=2)0!=(h=t[n+1])&&(t[n]=a[h],a[h]++)},r.F.codes2map=function(t,e,i){for(var s=t.length,n=r.F.U.rev15,h=0;h<s;h+=2)if(0!=t[h+1])for(var l=h>>1,o=t[h+1],f=l<<4|o,u=e-o,a=t[h]<<u,c=a+(1<<u);a!=c;){i[n[a]>>>15-e]=f,a++}},r.F.revCodes=function(t,e){for(var i=r.F.U.rev15,s=15-e,n=0;n<t.length;n+=2){var h=t[n]<<e-t[n+1];t[n]=i[h]>>>s}},r.F._putsE=function(t,e,i){i<<=7&e;var r=e>>>3;t[r]|=i,t[r+1]|=i>>>8},r.F._putsF=function(t,e,i){i<<=7&e;var r=e>>>3;t[r]|=i,t[r+1]|=i>>>8,t[r+2]|=i>>>16},r.F._bitsE=function(t,e,i){return(t[e>>>3]|t[1+(e>>>3)]<<8)>>>(7&e)&(1<<i)-1},r.F._bitsF=function(t,e,i){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)&(1<<i)-1},r.F._get17=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)},r.F._get25=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16|t[3+(e>>>3)]<<24)>>>(7&e)},r.F.U=(e=Uint16Array,i=Uint32Array,{next_code:new e(16),bl_count:new e(16),ordr:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],of0:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],exb:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],ldef:new e(32),df0:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],dxb:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],ddef:new i(32),flmap:new e(512),fltree:[],fdmap:new e(32),fdtree:[],lmap:new e(32768),ltree:[],ttree:[],dmap:new e(32768),dtree:[],imap:new e(512),itree:[],rev15:new e(32768),lhst:new i(286),dhst:new i(30),ihst:new i(19),lits:new i(15e3),strt:new e(65536),prev:new e(32768)}),function(){for(var t=r.F.U,e=0;e<32768;e++){var i=e;i=(4278255360&(i=(4042322160&(i=(3435973836&(i=(2863311530&i)>>>1|(1431655765&i)<<1))>>>2|(858993459&i)<<2))>>>4|(252645135&i)<<4))>>>8|(16711935&i)<<8,t.rev15[e]=(i>>>16|i<<16)>>>17}function s(t,e,i){for(;0!=e--;)t.push(0,i)}for(e=0;e<32;e++)t.ldef[e]=t.of0[e]<<3|t.exb[e],t.ddef[e]=t.df0[e]<<4|t.dxb[e];s(t.fltree,144,8),s(t.fltree,112,9),s(t.fltree,24,7),s(t.fltree,8,8),r.F.makeCodes(t.fltree,9),r.F.codes2map(t.fltree,9,t.flmap),r.F.revCodes(t.fltree,9),s(t.fdtree,32,5),r.F.makeCodes(t.fdtree,5),r.F.codes2map(t.fdtree,5,t.fdmap),r.F.revCodes(t.fdtree,5),s(t.itree,19,0),s(t.ltree,286,0),s(t.dtree,30,0),s(t.ttree,320,0)}()}();var Co=Eo({__proto__:null,default:To},[To]);const Po=function(){var t={nextZero(t,e){for(;0!=t[e];)e++;return e},readUshort:(t,e)=>t[e]<<8|t[e+1],writeUshort(t,e,i){t[e]=i>>8&255,t[e+1]=255&i},readUint:(t,e)=>16777216*t[e]+(t[e+1]<<16|t[e+2]<<8|t[e+3]),writeUint(t,e,i){t[e]=i>>24&255,t[e+1]=i>>16&255,t[e+2]=i>>8&255,t[e+3]=255&i},readASCII(t,e,i){let r="";for(let s=0;s<i;s++)r+=String.fromCharCode(t[e+s]);return r},writeASCII(t,e,i){for(let r=0;r<i.length;r++)t[e+r]=i.charCodeAt(r)},readBytes(t,e,i){const r=[];for(let s=0;s<i;s++)r.push(t[e+s]);return r},pad:t=>t.length<2?`0${t}`:t,readUTF8(e,i,r){let s,n="";for(let s=0;s<r;s++)n+=`%${t.pad(e[i+s].toString(16))}`;try{s=decodeURIComponent(n)}catch(s){return t.readASCII(e,i,r)}return s}};function e(e,i,r,s){const h=i*r,l=n(s),o=Math.ceil(i*l/8),f=new Uint8Array(4*h),u=new Uint32Array(f.buffer),{ctype:a}=s,{depth:c}=s,d=t.readUshort;if(6==a){const t=h<<2;if(8==c)for(var p=0;p<t;p+=4)f[p]=e[p],f[p+1]=e[p+1],f[p+2]=e[p+2],f[p+3]=e[p+3];if(16==c)for(p=0;p<t;p++)f[p]=e[p<<1]}else if(2==a){const t=s.tabs.tRNS;if(null==t){if(8==c)for(p=0;p<h;p++){var w=3*p;u[p]=255<<24|e[w+2]<<16|e[w+1]<<8|e[w]}if(16==c)for(p=0;p<h;p++){w=6*p;u[p]=255<<24|e[w+4]<<16|e[w+2]<<8|e[w]}}else{var m=t[0];const i=t[1],r=t[2];if(8==c)for(p=0;p<h;p++){var g=p<<2;w=3*p;u[p]=255<<24|e[w+2]<<16|e[w+1]<<8|e[w],e[w]==m&&e[w+1]==i&&e[w+2]==r&&(f[g+3]=0)}if(16==c)for(p=0;p<h;p++){g=p<<2,w=6*p;u[p]=255<<24|e[w+4]<<16|e[w+2]<<8|e[w],d(e,w)==m&&d(e,w+2)==i&&d(e,w+4)==r&&(f[g+3]=0)}}}else if(3==a){const t=s.tabs.PLTE,n=s.tabs.tRNS,l=n?n.length:0;if(1==c)for(var b=0;b<r;b++){var v=b*o,y=b*i;for(p=0;p<i;p++){g=y+p<<2;var M=3*(A=e[v+(p>>3)]>>7-((7&p)<<0)&1);f[g]=t[M],f[g+1]=t[M+1],f[g+2]=t[M+2],f[g+3]=A<l?n[A]:255}}if(2==c)for(b=0;b<r;b++)for(v=b*o,y=b*i,p=0;p<i;p++){g=y+p<<2,M=3*(A=e[v+(p>>2)]>>6-((3&p)<<1)&3);f[g]=t[M],f[g+1]=t[M+1],f[g+2]=t[M+2],f[g+3]=A<l?n[A]:255}if(4==c)for(b=0;b<r;b++)for(v=b*o,y=b*i,p=0;p<i;p++){g=y+p<<2,M=3*(A=e[v+(p>>1)]>>4-((1&p)<<2)&15);f[g]=t[M],f[g+1]=t[M+1],f[g+2]=t[M+2],f[g+3]=A<l?n[A]:255}if(8==c)for(p=0;p<h;p++){var A;g=p<<2,M=3*(A=e[p]);f[g]=t[M],f[g+1]=t[M+1],f[g+2]=t[M+2],f[g+3]=A<l?n[A]:255}}else if(4==a){if(8==c)for(p=0;p<h;p++){g=p<<2;var k=e[S=p<<1];f[g]=k,f[g+1]=k,f[g+2]=k,f[g+3]=e[S+1]}if(16==c)for(p=0;p<h;p++){var S;g=p<<2,k=e[S=p<<2];f[g]=k,f[g+1]=k,f[g+2]=k,f[g+3]=e[S+2]}}else if(0==a)for(m=s.tabs.tRNS?s.tabs.tRNS:-1,b=0;b<r;b++){const t=b*o,r=b*i;if(1==c)for(var x=0;x<i;x++){var E=(k=255*(e[t+(x>>>3)]>>>7-(7&x)&1))==255*m?0:255;u[r+x]=E<<24|k<<16|k<<8|k}else if(2==c)for(x=0;x<i;x++){E=(k=85*(e[t+(x>>>2)]>>>6-((3&x)<<1)&3))==85*m?0:255;u[r+x]=E<<24|k<<16|k<<8|k}else if(4==c)for(x=0;x<i;x++){E=(k=17*(e[t+(x>>>1)]>>>4-((1&x)<<2)&15))==17*m?0:255;u[r+x]=E<<24|k<<16|k<<8|k}else if(8==c)for(x=0;x<i;x++){E=(k=e[t+x])==m?0:255;u[r+x]=E<<24|k<<16|k<<8|k}else if(16==c)for(x=0;x<i;x++){k=e[t+(x<<1)],E=d(e,t+(x<<1))==m?0:255;u[r+x]=E<<24|k<<16|k<<8|k}}return f}function i(t,e,i,l){const o=n(t),f=Math.ceil(i*o/8),u=new Uint8Array((f+1+t.interlace)*l);return e=t.tabs.CgBI?s(e,u):r(e,u),0==t.interlace?e=h(e,t,0,i,l):1==t.interlace&&(e=function t(e,i){const r=i.width,s=i.height,l=n(i),o=l>>3,f=Math.ceil(r*l/8),u=new Uint8Array(s*f);let a=0;const c=[0,0,4,0,2,0,1],d=[0,4,0,2,0,1,0],p=[8,8,8,4,4,2,2],w=[8,8,4,4,2,2,1];let m=0;for(;m<7;){const t=p[m],n=w[m];let b=0,v=0,y=c[m];for(;y<s;)y+=t,v++;let M=d[m];for(;M<r;)M+=n,b++;const A=Math.ceil(b*l/8);h(e,i,a,b,v);let k=0,S=c[m];for(;S<s;){let i=d[m],s=a+k*A<<3;for(;i<r;){var g;if(1==l)g=(g=e[s>>3])>>7-(7&s)&1,u[S*f+(i>>3)]|=g<<7-((7&i)<<0);if(2==l)g=(g=e[s>>3])>>6-(7&s)&3,u[S*f+(i>>2)]|=g<<6-((3&i)<<1);if(4==l)g=(g=e[s>>3])>>4-(7&s)&15,u[S*f+(i>>1)]|=g<<4-((1&i)<<2);if(l>=8){const t=S*f+i*o;for(let i=0;i<o;i++)u[t+i]=e[(s>>3)+i]}s+=l,i+=n}k++,S+=t}b*v!=0&&(a+=v*(1+A)),m+=1}return u}(e,t)),e}function r(t,e){return s(new Uint8Array(t.buffer,2,t.length-6),e)}var s=function(){const t={H:{}};return t.H.N=function(e,i){const r=Uint8Array;let s,n,h=0,l=0,o=0,f=0,u=0,a=0,c=0,d=0,p=0;if(3==e[0]&&0==e[1])return i||new r(0);const w=t.H,m=w.b,g=w.e,b=w.R,v=w.n,y=w.A,M=w.Z,A=w.m,k=null==i;for(k&&(i=new r(e.length>>>2<<5));0==h;)if(h=m(e,p,1),l=m(e,p+1,2),p+=3,0!=l){if(k&&(i=t.H.W(i,d+(1<<17))),1==l&&(s=A.J,n=A.h,a=511,c=31),2==l){o=g(e,p,5)+257,f=g(e,p+5,5)+1,u=g(e,p+10,4)+4,p+=14;let t=1;for(var S=0;S<38;S+=2)A.Q[S]=0,A.Q[S+1]=0;for(S=0;S<u;S++){const i=g(e,p+3*S,3);A.Q[1+(A.X[S]<<1)]=i,i>t&&(t=i)}p+=3*u,v(A.Q,t),y(A.Q,t,A.u),s=A.w,n=A.d,p=b(A.u,(1<<t)-1,o+f,e,p,A.v);const i=w.V(A.v,0,o,A.C);a=(1<<i)-1;const r=w.V(A.v,o,f,A.D);c=(1<<r)-1,v(A.C,i),y(A.C,i,s),v(A.D,r),y(A.D,r,n)}for(;;){const t=s[M(e,p)&a];p+=15&t;const r=t>>>4;if(r>>>8==0)i[d++]=r;else{if(256==r)break;{let t=d+r-254;if(r>264){const i=A.q[r-257];t=d+(i>>>3)+g(e,p,7&i),p+=7&i}const s=n[M(e,p)&c];p+=15&s;const h=s>>>4,l=A.c[h],o=(l>>>4)+m(e,p,15&l);for(p+=15&l;d<t;)i[d]=i[d++-o],i[d]=i[d++-o],i[d]=i[d++-o],i[d]=i[d++-o];d=t}}}}else{0!=(7&p)&&(p+=8-(7&p));const s=4+(p>>>3),n=e[s-4]|e[s-3]<<8;k&&(i=t.H.W(i,d+n)),i.set(new r(e.buffer,e.byteOffset+s,n),d),p=s+n<<3,d+=n}return i.length==d?i:i.slice(0,d)},t.H.W=function(t,e){const i=t.length;if(e<=i)return t;const r=new Uint8Array(i<<1);return r.set(t,0),r},t.H.R=function(e,i,r,s,n,h){const l=t.H.e,o=t.H.Z;let f=0;for(;f<r;){const t=e[o(s,n)&i];n+=15&t;const r=t>>>4;if(r<=15)h[f]=r,f++;else{let t=0,e=0;16==r?(e=3+l(s,n,2),n+=2,t=h[f-1]):17==r?(e=3+l(s,n,3),n+=3):18==r&&(e=11+l(s,n,7),n+=7);const i=f+e;for(;f<i;)h[f]=t,f++}}return n},t.H.V=function(t,e,i,r){let s=0,n=0;const h=r.length>>>1;for(;n<i;){const i=t[n+e];r[n<<1]=0,r[1+(n<<1)]=i,i>s&&(s=i),n++}for(;n<h;)r[n<<1]=0,r[1+(n<<1)]=0,n++;return s},t.H.n=function(e,i){const r=t.H.m,s=e.length;let n,h,l;let o;const f=r.j;for(var u=0;u<=i;u++)f[u]=0;for(u=1;u<s;u+=2)f[e[u]]++;const a=r.K;for(n=0,f[0]=0,h=1;h<=i;h++)n=n+f[h-1]<<1,a[h]=n;for(l=0;l<s;l+=2)o=e[l+1],0!=o&&(e[l]=a[o],a[o]++)},t.H.A=function(e,i,r){const s=e.length,n=t.H.m.r;for(let t=0;t<s;t+=2)if(0!=e[t+1]){const s=t>>1,h=e[t+1],l=s<<4|h,o=i-h;let f=e[t]<<o;const u=f+(1<<o);for(;f!=u;){r[n[f]>>>15-i]=l,f++}}},t.H.l=function(e,i){const r=t.H.m.r,s=15-i;for(let t=0;t<e.length;t+=2){const n=e[t]<<i-e[t+1];e[t]=r[n]>>>s}},t.H.M=function(t,e,i){i<<=7&e;const r=e>>>3;t[r]|=i,t[r+1]|=i>>>8},t.H.I=function(t,e,i){i<<=7&e;const r=e>>>3;t[r]|=i,t[r+1]|=i>>>8,t[r+2]|=i>>>16},t.H.e=function(t,e,i){return(t[e>>>3]|t[1+(e>>>3)]<<8)>>>(7&e)&(1<<i)-1},t.H.b=function(t,e,i){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)&(1<<i)-1},t.H.Z=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)},t.H.i=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16|t[3+(e>>>3)]<<24)>>>(7&e)},t.H.m=function(){const t=Uint16Array,e=Uint32Array;return{K:new t(16),j:new t(16),X:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],S:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],T:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],q:new t(32),p:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],z:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],c:new e(32),J:new t(512),_:[],h:new t(32),$:[],w:new t(32768),C:[],v:[],d:new t(32768),D:[],u:new t(512),Q:[],r:new t(32768),s:new e(286),Y:new e(30),a:new e(19),t:new e(15e3),k:new t(65536),g:new t(32768)}}(),function(){const e=t.H.m;for(var i=0;i<32768;i++){let t=i;t=(2863311530&t)>>>1|(1431655765&t)<<1,t=(3435973836&t)>>>2|(858993459&t)<<2,t=(4042322160&t)>>>4|(252645135&t)<<4,t=(4278255360&t)>>>8|(16711935&t)<<8,e.r[i]=(t>>>16|t<<16)>>>17}function r(t,e,i){for(;0!=e--;)t.push(0,i)}for(i=0;i<32;i++)e.q[i]=e.S[i]<<3|e.T[i],e.c[i]=e.p[i]<<4|e.z[i];r(e._,144,8),r(e._,112,9),r(e._,24,7),r(e._,8,8),t.H.n(e._,9),t.H.A(e._,9,e.J),t.H.l(e._,9),r(e.$,32,5),t.H.n(e.$,5),t.H.A(e.$,5,e.h),t.H.l(e.$,5),r(e.Q,19,0),r(e.C,286,0),r(e.D,30,0),r(e.v,320,0)}(),t.H.N}();function n(t){return[1,null,3,1,2,null,4][t.ctype]*t.depth}function h(t,e,i,r,s){let h=n(e);const o=Math.ceil(r*h/8);let f,u;h=Math.ceil(h/8);let a=t[i],c=0;if(a>1&&(t[i]=[0,0,1][a-2]),3==a)for(c=h;c<o;c++)t[c+1]=t[c+1]+(t[c+1-h]>>>1)&255;for(let e=0;e<s;e++)if(f=i+e*o,u=f+e+1,a=t[u-1],c=0,0==a)for(;c<o;c++)t[f+c]=t[u+c];else if(1==a){for(;c<h;c++)t[f+c]=t[u+c];for(;c<o;c++)t[f+c]=t[u+c]+t[f+c-h]}else if(2==a)for(;c<o;c++)t[f+c]=t[u+c]+t[f+c-o];else if(3==a){for(;c<h;c++)t[f+c]=t[u+c]+(t[f+c-o]>>>1);for(;c<o;c++)t[f+c]=t[u+c]+(t[f+c-o]+t[f+c-h]>>>1)}else{for(;c<h;c++)t[f+c]=t[u+c]+l(0,t[f+c-o],0);for(;c<o;c++)t[f+c]=t[u+c]+l(t[f+c-h],t[f+c-o],t[f+c-h-o])}return t}function l(t,e,i){const r=t+e-i,s=r-t,n=r-e,h=r-i;return s*s<=n*n&&s*s<=h*h?t:n*n<=h*h?e:i}function o(e,i,r){r.width=t.readUint(e,i),i+=4,r.height=t.readUint(e,i),i+=4,r.depth=e[i],i++,r.ctype=e[i],i++,r.compress=e[i],i++,r.filter=e[i],i++,r.interlace=e[i],i++}function f(t,e,i,r,s,n,h,l,o){const f=Math.min(e,s),u=Math.min(i,n);let a=0,c=0;for(let i=0;i<u;i++)for(let n=0;n<f;n++)if(h>=0&&l>=0?(a=i*e+n<<2,c=(l+i)*s+h+n<<2):(a=(-l+i)*e-h+n<<2,c=i*s+n<<2),0==o)r[c]=t[a],r[c+1]=t[a+1],r[c+2]=t[a+2],r[c+3]=t[a+3];else if(1==o){var d=t[a+3]*(1/255),p=t[a]*d,w=t[a+1]*d,m=t[a+2]*d,g=r[c+3]*(1/255),b=r[c]*g,v=r[c+1]*g,y=r[c+2]*g;const e=1-d,i=d+g*e,s=0==i?0:1/i;r[c+3]=255*i,r[c+0]=(p+b*e)*s,r[c+1]=(w+v*e)*s,r[c+2]=(m+y*e)*s}else if(2==o){d=t[a+3],p=t[a],w=t[a+1],m=t[a+2],g=r[c+3],b=r[c],v=r[c+1],y=r[c+2];d==g&&p==b&&w==v&&m==y?(r[c]=0,r[c+1]=0,r[c+2]=0,r[c+3]=0):(r[c]=p,r[c+1]=w,r[c+2]=m,r[c+3]=d)}else if(3==o){d=t[a+3],p=t[a],w=t[a+1],m=t[a+2],g=r[c+3],b=r[c],v=r[c+1],y=r[c+2];if(d==g&&p==b&&w==v&&m==y)continue;if(d<220&&g>20)return false}return true}return{decode:function e(n){const h=new Uint8Array(n);let l=8;const f=t,u=f.readUshort,a=f.readUint,c={tabs:{},frames:[]},d=new Uint8Array(h.length);let p,w=0,m=0;const g=[137,80,78,71,13,10,26,10];for(var b=0;b<8;b++)if(h[b]!=g[b])throw"The input is not a PNG file!";for(;l<h.length;){const t=f.readUint(h,l);l+=4;const e=f.readASCII(h,l,4);if(l+=4,"IHDR"==e)o(h,l,c);else if("iCCP"==e){for(var v=l;0!=h[v];)v++;f.readASCII(h,l,v-l);const i=h.slice(v+2,l+t);let n=null;try{n=r(i)}catch(t){n=s(i)}c.tabs[e]=n}else if("CgBI"==e)c.tabs[e]=h.slice(l,l+4);else if("IDAT"==e){for(b=0;b<t;b++)d[w+b]=h[l+b];w+=t}else if("acTL"==e)c.tabs[e]={num_frames:a(h,l),num_plays:a(h,l+4)},p=new Uint8Array(h.length);else if("fcTL"==e){if(0!=m)(x=c.frames[c.frames.length-1]).data=i(c,p.slice(0,m),x.rect.width,x.rect.height),m=0;const t={x:a(h,l+12),y:a(h,l+16),width:a(h,l+4),height:a(h,l+8)};let e=u(h,l+22);e=u(h,l+20)/(0==e?100:e);const r={rect:t,delay:Math.round(1e3*e),dispose:h[l+24],blend:h[l+25]};c.frames.push(r)}else if("fdAT"==e){for(b=0;b<t-4;b++)p[m+b]=h[l+b+4];m+=t-4}else if("pHYs"==e)c.tabs[e]=[f.readUint(h,l),f.readUint(h,l+4),h[l+8]];else if("cHRM"==e){c.tabs[e]=[];for(b=0;b<8;b++)c.tabs[e].push(f.readUint(h,l+4*b))}else if("tEXt"==e||"zTXt"==e){null==c.tabs[e]&&(c.tabs[e]={});var y=f.nextZero(h,l),M=f.readASCII(h,l,y-l),A=l+t-y-1;if("tEXt"==e)S=f.readASCII(h,y+1,A);else{var k=r(h.slice(y+2,y+2+A));S=f.readUTF8(k,0,k.length)}c.tabs[e][M]=S}else if("iTXt"==e){null==c.tabs[e]&&(c.tabs[e]={});y=0,v=l;y=f.nextZero(h,v);M=f.readASCII(h,v,y-v);const i=h[v=y+1];var S;v+=2,y=f.nextZero(h,v),f.readASCII(h,v,y-v),v=y+1,y=f.nextZero(h,v),f.readUTF8(h,v,y-v);A=t-((v=y+1)-l);if(0==i)S=f.readUTF8(h,v,A);else{k=r(h.slice(v,v+A));S=f.readUTF8(k,0,k.length)}c.tabs[e][M]=S}else if("PLTE"==e)c.tabs[e]=f.readBytes(h,l,t);else if("hIST"==e){const t=c.tabs.PLTE.length/3;c.tabs[e]=[];for(b=0;b<t;b++)c.tabs[e].push(u(h,l+2*b))}else if("tRNS"==e)3==c.ctype?c.tabs[e]=f.readBytes(h,l,t):0==c.ctype?c.tabs[e]=u(h,l):2==c.ctype&&(c.tabs[e]=[u(h,l),u(h,l+2),u(h,l+4)]);else if("gAMA"==e)c.tabs[e]=f.readUint(h,l)/1e5;else if("sRGB"==e)c.tabs[e]=h[l];else if("bKGD"==e)0==c.ctype||4==c.ctype?c.tabs[e]=[u(h,l)]:2==c.ctype||6==c.ctype?c.tabs[e]=[u(h,l),u(h,l+2),u(h,l+4)]:3==c.ctype&&(c.tabs[e]=h[l]);else if("IEND"==e)break;l+=t,f.readUint(h,l),l+=4}var x;return 0!=m&&((x=c.frames[c.frames.length-1]).data=i(c,p.slice(0,m),x.rect.width,x.rect.height)),c.data=i(c,d,c.width,c.height),delete c.compress,delete c.interlace,delete c.filter,c},toRGBA8:function t(i){const r=i.width,s=i.height;if(null==i.tabs.acTL)return[e(i.data,r,s,i).buffer];const n=[];null==i.frames[0].data&&(i.frames[0].data=i.data);const h=r*s*4,l=new Uint8Array(h),o=new Uint8Array(h),u=new Uint8Array(h);for(let t=0;t<i.frames.length;t++){const c=i.frames[t],d=c.rect.x,p=c.rect.y,w=c.rect.width,m=c.rect.height,g=e(c.data,w,m,i);if(0!=t)for(var a=0;a<h;a++)u[a]=l[a];if(0==c.blend?f(g,w,m,l,r,s,d,p,0):1==c.blend&&f(g,w,m,l,r,s,d,p,1),n.push(l.buffer.slice(0)),0==c.dispose);else if(1==c.dispose)f(o,w,m,l,r,s,d,p,0);else if(2==c.dispose)for(a=0;a<h;a++)l[a]=u[a]}return n},_paeth:l,_copyTile:f,_bin:t}}();!function(){const{_copyTile:t}=Po,{_bin:e}=Po,i=Po._paeth;var r={table:function(){const t=new Uint32Array(256);for(let e=0;e<256;e++){let i=e;for(let t=0;t<8;t++)1&i?i=3988292384^i>>>1:i>>>=1;t[e]=i}return t}(),update(t,e,i,s){for(let n=0;n<s;n++)t=r.table[255&(t^e[i+n])]^t>>>8;return t},crc:(t,e,i)=>4294967295^r.update(4294967295,t,e,i)};function s(t,e,i,r){e[i]+=t[0]*r>>4,e[i+1]+=t[1]*r>>4,e[i+2]+=t[2]*r>>4,e[i+3]+=t[3]*r>>4}function n(t){return Math.max(0,Math.min(255,t))}function h(t,e){const i=t[0]-e[0],r=t[1]-e[1],s=t[2]-e[2],n=t[3]-e[3];return i*i+r*r+s*s+n*n}function l(t,e,i,r,l,o,f){null==f&&(f=1);const u=r.length,a=[];for(var c=0;c<u;c++){const t=r[c];a.push([t>>>0&255,t>>>8&255,t>>>16&255,t>>>24&255])}for(c=0;c<u;c++){let t=4294967295;for(var d=0,p=0;p<u;p++){var w=h(a[c],a[p]);p!=c&&w<t&&(t=w,d=p)}}const m=new Uint32Array(l.buffer),g=new Int16Array(e*i*4),b=[0,8,2,10,12,4,14,6,3,11,1,9,15,7,13,5];for(c=0;c<b.length;c++)b[c]=255*((b[c]+.5)/16-.5);for(let l=0;l<i;l++)for(let y=0;y<e;y++){var v;c=4*(l*e+y);if(2!=f)v=[n(t[c]+g[c]),n(t[c+1]+g[c+1]),n(t[c+2]+g[c+2]),n(t[c+3]+g[c+3])];else{w=b[4*(3&l)+(3&y)];v=[n(t[c]+w),n(t[c+1]+w),n(t[c+2]+w),n(t[c+3]+w)]}d=0;let M=16777215;for(p=0;p<u;p++){const t=h(v,a[p]);t<M&&(M=t,d=p)}const A=a[d],k=[v[0]-A[0],v[1]-A[1],v[2]-A[2],v[3]-A[3]];1==f&&(y!=e-1&&s(k,g,c+4,7),l!=i-1&&(0!=y&&s(k,g,c+4*e-4,3),s(k,g,c+4*e,5),y!=e-1&&s(k,g,c+4*e+4,1))),o[c>>2]=d,m[c>>2]=r[d]}}function o(t,i,s,n,h){null==h&&(h={});const{crc:l}=r,o=e.writeUint,f=e.writeUshort,u=e.writeASCII;let a=8;const c=t.frames.length>1;let d,p=false,w=33+(c?20:0);if(null!=h.sRGB&&(w+=13),null!=h.pHYs&&(w+=21),null!=h.iCCP&&(d=pako.deflate(h.iCCP),w+=21+d.length+4),3==t.ctype){for(var m=t.plte.length,g=0;g<m;g++)t.plte[g]>>>24!=255&&(p=true);w+=8+3*m+4+(p?8+1*m+4:0)}for(var b=0;b<t.frames.length;b++){c&&(w+=38),w+=(A=t.frames[b]).cimg.length+12,0!=b&&(w+=4)}w+=12;const v=new Uint8Array(w),y=[137,80,78,71,13,10,26,10];for(g=0;g<8;g++)v[g]=y[g];if(o(v,a,13),a+=4,u(v,a,"IHDR"),a+=4,o(v,a,i),a+=4,o(v,a,s),a+=4,v[a]=t.depth,a++,v[a]=t.ctype,a++,v[a]=0,a++,v[a]=0,a++,v[a]=0,a++,o(v,a,l(v,a-17,17)),a+=4,null!=h.sRGB&&(o(v,a,1),a+=4,u(v,a,"sRGB"),a+=4,v[a]=h.sRGB,a++,o(v,a,l(v,a-5,5)),a+=4),null!=h.iCCP){const t=13+d.length;o(v,a,t),a+=4,u(v,a,"iCCP"),a+=4,u(v,a,"ICC profile"),a+=11,a+=2,v.set(d,a),a+=d.length,o(v,a,l(v,a-(t+4),t+4)),a+=4}if(null!=h.pHYs&&(o(v,a,9),a+=4,u(v,a,"pHYs"),a+=4,o(v,a,h.pHYs[0]),a+=4,o(v,a,h.pHYs[1]),a+=4,v[a]=h.pHYs[2],a++,o(v,a,l(v,a-13,13)),a+=4),c&&(o(v,a,8),a+=4,u(v,a,"acTL"),a+=4,o(v,a,t.frames.length),a+=4,o(v,a,null!=h.loop?h.loop:0),a+=4,o(v,a,l(v,a-12,12)),a+=4),3==t.ctype){o(v,a,3*(m=t.plte.length)),a+=4,u(v,a,"PLTE"),a+=4;for(g=0;g<m;g++){const e=3*g,i=t.plte[g],r=255&i,s=i>>>8&255,n=i>>>16&255;v[a+e+0]=r,v[a+e+1]=s,v[a+e+2]=n}if(a+=3*m,o(v,a,l(v,a-3*m-4,3*m+4)),a+=4,p){o(v,a,m),a+=4,u(v,a,"tRNS"),a+=4;for(g=0;g<m;g++)v[a+g]=t.plte[g]>>>24&255;a+=m,o(v,a,l(v,a-m-4,m+4)),a+=4}}let M=0;for(b=0;b<t.frames.length;b++){var A=t.frames[b];c&&(o(v,a,26),a+=4,u(v,a,"fcTL"),a+=4,o(v,a,M++),a+=4,o(v,a,A.rect.width),a+=4,o(v,a,A.rect.height),a+=4,o(v,a,A.rect.x),a+=4,o(v,a,A.rect.y),a+=4,f(v,a,n[b]),a+=2,f(v,a,1e3),a+=2,v[a]=A.dispose,a++,v[a]=A.blend,a++,o(v,a,l(v,a-30,30)),a+=4);const e=A.cimg;o(v,a,(m=e.length)+(0==b?0:4)),a+=4;const i=a;u(v,a,0==b?"IDAT":"fdAT"),a+=4,0!=b&&(o(v,a,M++),a+=4),v.set(e,a),a+=m,o(v,a,l(v,i,a-i)),a+=4}return o(v,a,0),a+=4,u(v,a,"IEND"),a+=4,o(v,a,l(v,a-4,4)),a+=4,v.buffer}function f(t,e,i){for(let r=0;r<t.frames.length;r++){const s=t.frames[r];const n=s.rect.height,h=new Uint8Array(n*s.bpl+n);s.cimg=d(s.img,n,s.bpp,s.bpl,h,e,i)}}function u(e,i,r,s,n){const h=n[0],o=n[1],f=n[2],u=n[3],d=n[4],p=n[5];let m=6,g=8,b=255;for(var v=0;v<e.length;v++){const t=new Uint8Array(e[v]);for(var y=t.length,M=0;M<y;M+=4)b&=t[M+3]}const A=255!=b,k=function e(i,r,s,n,h,l){const o=[];for(var f=0;f<i.length;f++){const e=new Uint8Array(i[f]),a=new Uint32Array(e.buffer);var u;let p=0,m=0,g=r,b=s,v=n?1:0;if(0!=f){const y=l||n||1==f||0!=o[f-2].dispose?1:2;let M=0,A=1e9;for(let t=0;t<y;t++){var d=new Uint8Array(i[f-1-t]);const e=new Uint32Array(i[f-1-t]);let n=r,l=s,o=-1,u=-1;for(let t=0;t<s;t++)for(let i=0;i<r;i++){a[w=t*r+i]!=e[w]&&(i<n&&(n=i),i>o&&(o=i),t<l&&(l=t),t>u&&(u=t))}-1==o&&(n=l=o=u=0),h&&(1==(1&n)&&n--,1==(1&l)&&l--);const c=(o-n+1)*(u-l+1);c<A&&(A=c,M=t,p=n,m=l,g=o-n+1,b=u-l+1)}d=new Uint8Array(i[f-1-M]);1==M&&(o[f-1].dispose=2),u=new Uint8Array(g*b*4),t(d,r,s,u,g,b,-p,-m,0),v=t(e,r,s,u,g,b,-p,-m,3)?1:0,1==v?c(e,r,s,u,{x:p,y:m,width:g,height:b}):t(e,r,s,u,g,b,-p,-m,0)}else u=e.slice(0);o.push({rect:{x:p,y:m,width:g,height:b},img:u,blend:v,dispose:0})}if(n)for(f=0;f<o.length;f++){if(1==(m=o[f]).blend)continue;const t=m.rect,e=o[f-1].rect,n=Math.min(t.x,e.x),l=Math.min(t.y,e.y),u={x:n,y:l,width:Math.max(t.x+t.width,e.x+e.width)-n,height:Math.max(t.y+t.height,e.y+e.height)-l};o[f-1].dispose=1,f-1!=0&&a(i,r,s,o,f-1,u,h),a(i,r,s,o,f,u,h)}let p=0;if(1!=i.length)for(var w=0;w<o.length;w++){var m;p+=(m=o[w]).rect.width*m.rect.height}return o}(e,i,r,h,o,f),S={},x=[],E=[];if(0!=s){const t=[];for(M=0;M<k.length;M++)t.push(k[M].img.buffer);const e=function t(e){let i=0;for(var r=0;r<e.length;r++)i+=e[r].byteLength;const s=new Uint8Array(i);let n=0;for(r=0;r<e.length;r++){const t=new Uint8Array(e[r]),i=t.length;for(let e=0;e<i;e+=4){let i=t[e],r=t[e+1],h=t[e+2];const l=t[e+3];0==l&&(i=r=h=0),s[n+e]=i,s[n+e+1]=r,s[n+e+2]=h,s[n+e+3]=l}n+=i}return s.buffer}(t),i=w(e,s);for(M=0;M<i.plte.length;M++)x.push(i.plte[M].est.rgba);let r=0;for(M=0;M<k.length;M++){const t=(D=k[M]).img.length;var O=new Uint8Array(i.inds.buffer,r>>2,t>>2);E.push(O);const e=new Uint8Array(i.abuf,r,t);p&&l(D.img,D.rect.width,D.rect.height,x,e,O),D.img.set(e),r+=t}}else for(v=0;v<k.length;v++){var D=k[v];const t=new Uint32Array(D.img.buffer);var T=D.rect.width;y=t.length,O=new Uint8Array(y);E.push(O);for(M=0;M<y;M++){const e=t[M];if(0!=M&&e==t[M-1])O[M]=O[M-1];else if(M>T&&e==t[M-T])O[M]=O[M-T];else{let t=S[e];if(null==t&&(S[e]=t=x.length,x.push(e),x.length>=300))break;O[M]=t}}}const R=x.length;R<=256&&0==d&&(g=R<=2?1:R<=4?2:R<=16?4:8,g=Math.max(g,u));for(v=0;v<k.length;v++){(D=k[v]).rect.x;T=D.rect.width;const t=D.rect.height;let e=D.img;let i=4*T,r=4;if(R<=256&&0==d){i=Math.ceil(g*T/8);var C=new Uint8Array(i*t);const s=E[v];for(let e=0;e<t;e++){M=e*i;const t=e*T;if(8==g)for(var P=0;P<T;P++)C[M+P]=s[t+P];else if(4==g)for(P=0;P<T;P++)C[M+(P>>1)]|=s[t+P]<<4-4*(1&P);else if(2==g)for(P=0;P<T;P++)C[M+(P>>2)]|=s[t+P]<<6-2*(3&P);else if(1==g)for(P=0;P<T;P++)C[M+(P>>3)]|=s[t+P]<<7-1*(7&P)}e=C,m=3,r=1}else if(0==A&&1==k.length){C=new Uint8Array(T*t*3);const s=T*t;for(M=0;M<s;M++){const t=3*M,i=4*M;C[t]=e[i],C[t+1]=e[i+1],C[t+2]=e[i+2]}e=C,m=2,r=3,i=3*T}D.img=e,D.bpl=i,D.bpp=r}return{ctype:m,depth:g,plte:x,frames:k}}function a(e,i,r,s,n,h,l){const o=Uint8Array,f=Uint32Array,u=new o(e[n-1]),a=new f(e[n-1]),d=n+1<e.length?new o(e[n+1]):null,p=new o(e[n]),w=new f(p.buffer);let m=i,g=r,b=-1,v=-1;for(let t=0;t<h.height;t++)for(let e=0;e<h.width;e++){const r=h.x+e,l=h.y+t,o=l*i+r,f=w[o];0==f||0==s[n-1].dispose&&a[o]==f&&(null==d||0!=d[4*o+3])||(r<m&&(m=r),r>b&&(b=r),l<g&&(g=l),l>v&&(v=l))}-1==b&&(m=g=b=v=0),l&&(1==(1&m)&&m--,1==(1&g)&&g--),h={x:m,y:g,width:b-m+1,height:v-g+1};const y=s[n];y.rect=h,y.blend=1,y.img=new Uint8Array(h.width*h.height*4),0==s[n-1].dispose?(t(u,i,r,y.img,h.width,h.height,-h.x,-h.y,0),c(p,i,r,y.img,h)):t(p,i,r,y.img,h.width,h.height,-h.x,-h.y,0)}function c(e,i,r,s,n){t(e,i,r,s,n.width,n.height,-n.x,-n.y,2)}function d(t,e,i,r,s,n,h){const l=[];let o,f=[0,1,2,3,4];-1!=n?f=[n]:(e*r>5e5||1==i)&&(f=[0]),h&&(o={level:0});const u=Co;for(var a=0;a<f.length;a++){for(let n=0;n<e;n++)p(s,t,n,r,i,f[a]);l.push(u.deflate(s,o))}let c,d=1e9;for(a=0;a<l.length;a++)l[a].length<d&&(c=a,d=l[a].length);return l[c]}function p(t,e,r,s,n,h){const l=r*s;let o=l+r;if(t[o]=h,o++,0==h)if(s<500)for(var f=0;f<s;f++)t[o+f]=e[l+f];else t.set(new Uint8Array(e.buffer,l,s),o);else if(1==h){for(f=0;f<n;f++)t[o+f]=e[l+f];for(f=n;f<s;f++)t[o+f]=e[l+f]-e[l+f-n]+256&255}else if(0==r){for(f=0;f<n;f++)t[o+f]=e[l+f];if(2==h)for(f=n;f<s;f++)t[o+f]=e[l+f];if(3==h)for(f=n;f<s;f++)t[o+f]=e[l+f]-(e[l+f-n]>>1)+256&255;if(4==h)for(f=n;f<s;f++)t[o+f]=e[l+f]-i(e[l+f-n],0,0)+256&255}else{if(2==h)for(f=0;f<s;f++)t[o+f]=e[l+f]+256-e[l+f-s]&255;if(3==h){for(f=0;f<n;f++)t[o+f]=e[l+f]+256-(e[l+f-s]>>1)&255;for(f=n;f<s;f++)t[o+f]=e[l+f]+256-(e[l+f-s]+e[l+f-n]>>1)&255}if(4==h){for(f=0;f<n;f++)t[o+f]=e[l+f]+256-i(0,e[l+f-s],0)&255;for(f=n;f<s;f++)t[o+f]=e[l+f]+256-i(e[l+f-n],e[l+f-s],e[l+f-n-s])&255}}}function w(t,e){const i=new Uint8Array(t),r=i.slice(0),s=new Uint32Array(r.buffer),n=m(r,e),h=n[0],l=n[1],o=i.length,f=new Uint8Array(o>>2);let u;if(i.length<2e7)for(var a=0;a<o;a+=4){u=g(h,c=i[a]*(1/255),d=i[a+1]*(1/255),p=i[a+2]*(1/255),w=i[a+3]*(1/255)),f[a>>2]=u.ind,s[a>>2]=u.est.rgba}else for(a=0;a<o;a+=4){var c=i[a]*(1/255),d=i[a+1]*(1/255),p=i[a+2]*(1/255),w=i[a+3]*(1/255);for(u=h;u.left;)u=b(u.est,c,d,p,w)<=0?u.left:u.right;f[a>>2]=u.ind,s[a>>2]=u.est.rgba}return{abuf:r.buffer,inds:f,plte:l}}function m(t,e,i){null==i&&(i=1e-4);const r=new Uint32Array(t.buffer),s={i0:0,i1:t.length,bst:null,est:null,tdst:0,left:null,right:null};s.bst=M(t,s.i0,s.i1),s.est=A(s.bst);const n=[s];for(;n.length<e;){let e=0,s=0;for(var h=0;h<n.length;h++)n[h].est.L>e&&(e=n[h].est.L,s=h);if(e<i)break;const l=n[s],o=v(t,r,l.i0,l.i1,l.est.e,l.est.eMq255);if(l.i0>=o||l.i1<=o){l.est.L=0;continue}const f={i0:l.i0,i1:o,bst:null,est:null,tdst:0,left:null,right:null};f.bst=M(t,f.i0,f.i1),f.est=A(f.bst);const u={i0:o,i1:l.i1,bst:null,est:null,tdst:0,left:null,right:null};u.bst={R:[],m:[],N:l.bst.N-f.bst.N};for(h=0;h<16;h++)u.bst.R[h]=l.bst.R[h]-f.bst.R[h];for(h=0;h<4;h++)u.bst.m[h]=l.bst.m[h]-f.bst.m[h];u.est=A(u.bst),l.left=f,l.right=u,n[s]=f,n.push(u)}n.sort(((t,e)=>e.bst.N-t.bst.N));for(h=0;h<n.length;h++)n[h].ind=h;return[s,n]}function g(t,e,i,r,s){if(null==t.left)return t.tdst=function t(e,i,r,s,n){const h=i-e[0],l=r-e[1],o=s-e[2],f=n-e[3];return h*h+l*l+o*o+f*f}(t.est.q,e,i,r,s),t;const n=b(t.est,e,i,r,s);let h=t.left,l=t.right;n>0&&(h=t.right,l=t.left);const o=g(h,e,i,r,s);if(o.tdst<=n*n)return o;const f=g(l,e,i,r,s);return f.tdst<o.tdst?f:o}function b(t,e,i,r,s){const{e:n}=t;return n[0]*e+n[1]*i+n[2]*r+n[3]*s-t.eMq}function v(t,e,i,r,s,n){for(r-=4;i<r;){for(;y(t,i,s)<=n;)i+=4;for(;y(t,r,s)>n;)r-=4;if(i>=r)break;const h=e[i>>2];e[i>>2]=e[r>>2],e[r>>2]=h,i+=4,r-=4}for(;y(t,i,s)>n;)i-=4;return i+4}function y(t,e,i){return t[e]*i[0]+t[e+1]*i[1]+t[e+2]*i[2]+t[e+3]*i[3]}function M(t,e,i){const r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],s=[0,0,0,0],n=i-e>>2;for(let n=e;n<i;n+=4){const e=t[n]*(1/255),i=t[n+1]*(1/255),h=t[n+2]*(1/255),l=t[n+3]*(1/255);s[0]+=e,s[1]+=i,s[2]+=h,s[3]+=l,r[0]+=e*e,r[1]+=e*i,r[2]+=e*h,r[3]+=e*l,r[5]+=i*i,r[6]+=i*h,r[7]+=i*l,r[10]+=h*h,r[11]+=h*l,r[15]+=l*l}return r[4]=r[1],r[8]=r[2],r[9]=r[6],r[12]=r[3],r[13]=r[7],r[14]=r[11],{R:r,m:s,N:n}}function A(t){const{R:e}=t,{m:i}=t,{N:r}=t,s=i[0],n=i[1],h=i[2],l=i[3],o=0==r?0:1/r,f=[e[0]-s*s*o,e[1]-s*n*o,e[2]-s*h*o,e[3]-s*l*o,e[4]-n*s*o,e[5]-n*n*o,e[6]-n*h*o,e[7]-n*l*o,e[8]-h*s*o,e[9]-h*n*o,e[10]-h*h*o,e[11]-h*l*o,e[12]-l*s*o,e[13]-l*n*o,e[14]-l*h*o,e[15]-l*l*o],u=f,a=k;let c=[Math.random(),Math.random(),Math.random(),Math.random()],d=0,p=0;if(0!=r)for(let t=0;t<16&&(c=a.multVec(u,c),p=Math.sqrt(a.dot(c,c)),c=a.sml(1/p,c),!(0!=t&&Math.abs(p-d)<1e-9));t++)d=p;const w=[s*o,n*o,h*o,l*o];return{Cov:f,q:w,e:c,L:d,eMq255:a.dot(a.sml(255,w),c),eMq:a.dot(c,w),rgba:(Math.round(255*w[3])<<24|Math.round(255*w[2])<<16|Math.round(255*w[1])<<8|Math.round(255*w[0])<<0)>>>0}}var k={multVec:(t,e)=>[t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3],t[4]*e[0]+t[5]*e[1]+t[6]*e[2]+t[7]*e[3],t[8]*e[0]+t[9]*e[1]+t[10]*e[2]+t[11]*e[3],t[12]*e[0]+t[13]*e[1]+t[14]*e[2]+t[15]*e[3]],dot:(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3],sml:(t,e)=>[t*e[0],t*e[1],t*e[2],t*e[3]]};Po.encode=function t(e,i,r,s,n,h,l){null==s&&(s=0),null==l&&(l=false);const a=u(e,i,r,s,[false,false,false,0,l,false]);return f(a,-1),o(a,i,r,n,h)},Po.encodeLL=function t(e,i,r,s,n,h,l,u){const a={ctype:0+(1==s?0:2)+(0==n?0:4),depth:h,frames:[]},c=(s+n)*h,d=c*i;for(let t=0;t<e.length;t++)a.frames.push({rect:{x:0,y:0,width:i,height:r},img:new Uint8Array(e[t]),blend:0,dispose:1,bpp:Math.ceil(c/8),bpl:Math.ceil(d/8)});return f(a,0,true),o(a,i,r,l,u)},Po.encode.compress=u,Po.encode.dither=l,Po.quantize=w,Po.quantize.getKDtree=m,Po.quantize.getNearest=g}();const Io={toArrayBuffer(t,e){const i=t.width,r=t.height,s=i<<2,n=t.getContext("2d").getImageData(0,0,i,r),h=new Uint32Array(n.data.buffer),l=(32*i+31)/32<<2,o=l*r,f=122+o,u=new ArrayBuffer(f),a=new DataView(u),c=1<<20;let d,p,w,m,g=c,b=0,v=0,y=0;function M(t){a.setUint16(v,t,true),v+=2}function A(t){a.setUint32(v,t,true),v+=4}function k(t){v+=t}M(19778),A(f),k(4),A(122),A(108),A(i),A(-r>>>0),M(1),M(32),A(3),A(o),A(2835),A(2835),k(8),A(16711680),A(65280),A(255),A(4278190080),A(1466527264),function t(){for(;b<r&&g>0;){for(m=122+b*l,d=0;d<s;)g--,p=h[y++],w=p>>>24,a.setUint32(m+d,p<<8|w),d+=4;b++}y<h.length?(g=c,setTimeout(t,Io._dly)):e(u)}()},toBlob(t,e){this.toArrayBuffer(t,(t=>{e(new Blob([t],{type:"image/bmp"}))}))},_dly:9};var No={CHROME:"CHROME",FIREFOX:"FIREFOX",DESKTOP_SAFARI:"DESKTOP_SAFARI",IE:"IE",IOS:"IOS",ETC:"ETC"},Fo={[No.CHROME]:16384,[No.FIREFOX]:11180,[No.DESKTOP_SAFARI]:16384,[No.IE]:8192,[No.IOS]:4096,[No.ETC]:8192};const Bo="undefined"!=typeof window,Uo="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,jo=Bo&&window.cordova&&window.cordova.require&&window.cordova.require("cordova/modulemapper"),$o=(Bo||Uo)&&(jo&&jo.getOriginalSymbol(window,"File")||"undefined"!=typeof File&&File),_o=(Bo||Uo)&&(jo&&jo.getOriginalSymbol(window,"FileReader")||"undefined"!=typeof FileReader&&FileReader);function zo(t,e,i=Date.now()){return new Promise((r=>{const s=t.split(","),n=s[0].match(/:(.*?);/)[1],h=globalThis.atob(s[1]);let l=h.length;const o=new Uint8Array(l);for(;l--;)o[l]=h.charCodeAt(l);const f=new Blob([o],{type:n});f.name=e,f.lastModified=i,r(f)}))}function Jo(t){return new Promise(((e,i)=>{const r=new _o;r.onload=()=>e(r.result),r.onerror=t=>i(t),r.readAsDataURL(t)}))}function Wo(t){return new Promise(((e,i)=>{const r=new Image;r.onload=()=>e(r),r.onerror=t=>i(t),r.src=t}))}function Qo(){if(void 0!==Qo.cachedResult)return Qo.cachedResult;let t=No.ETC;const{userAgent:e}=navigator;return/Chrom(e|ium)/i.test(e)?t=No.CHROME:/iP(ad|od|hone)/i.test(e)&&/WebKit/i.test(e)?t=No.IOS:/Safari/i.test(e)?t=No.DESKTOP_SAFARI:/Firefox/i.test(e)?t=No.FIREFOX:(/MSIE/i.test(e)||true==!!document.documentMode)&&(t=No.IE),Qo.cachedResult=t,Qo.cachedResult}function Lo(t,e){const i=Qo(),r=Fo[i];let s=t,n=e,h=s*n;const l=s>n?n/s:s/n;for(;h>r*r;){const t=(r+s)/2,e=(r+n)/2;t<e?(n=e,s=e*l):(n=t*l,s=t),h=s*n}return{width:s,height:n}}function Ko(t,e){let i,r;try{if(i=new OffscreenCanvas(t,e),r=i.getContext("2d"),null===r)throw new Error("getContext of OffscreenCanvas returns null")}catch(t){i=document.createElement("canvas"),r=i.getContext("2d")}return i.width=t,i.height=e,[i,r]}function Ho(t,e){const{width:i,height:r}=Lo(t.width,t.height),[s,n]=Ko(i,r);return e&&/jpe?g/.test(e)&&(n.fillStyle="white",n.fillRect(0,0,s.width,s.height)),n.drawImage(t,0,0,s.width,s.height),s}function qo(){return void 0!==qo.cachedResult||(qo.cachedResult=["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"undefined"!=typeof document&&"ontouchend"in document),qo.cachedResult}function Go(t,e={}){return new Promise((function(i,r){let s,n;var h=function(){try{return n=Ho(s,e.fileType||t.type),i([s,n])}catch(t){return r(t)}},l=function(e){try{var i=function(t){try{throw t}catch(t){return r(t)}};try{let e;return Jo(t).then((function(t){try{return e=t,Wo(e).then((function(t){try{return s=t,function(){try{return h()}catch(t){return r(t)}}()}catch(t){return i(t)}}),i)}catch(t){return i(t)}}),i)}catch(t){i(t)}}catch(t){return r(t)}};try{if(qo()||[No.DESKTOP_SAFARI,No.MOBILE_SAFARI].includes(Qo()))throw new Error("Skip createImageBitmap on IOS and Safari");return createImageBitmap(t).then((function(t){try{return s=t,h()}catch(t){return l()}}),l)}catch(t){l()}}))}function Xo(t,e,i,r,s=1){return new Promise((function(n,h){let l;if("image/png"===e){let f,u,a;return f=t.getContext("2d"),({data:u}=f.getImageData(0,0,t.width,t.height)),a=Po.encode([u.buffer],t.width,t.height,4096*s),l=new Blob([a],{type:e}),l.name=i,l.lastModified=r,o.call(this)}{if("image/bmp"===e)return new Promise((e=>Io.toBlob(t,e))).then(function(t){try{return l=t,l.name=i,l.lastModified=r,c.call(this)}catch(t){return h(t)}}.bind(this),h);{if("function"==typeof OffscreenCanvas&&t instanceof OffscreenCanvas)return t.convertToBlob({type:e,quality:s}).then(function(t){try{return l=t,l.name=i,l.lastModified=r,d.call(this)}catch(t){return h(t)}}.bind(this),h);{let p;return p=t.toDataURL(e,s),zo(p,i,r).then(function(t){try{return l=t,d.call(this)}catch(t){return h(t)}}.bind(this),h)}function d(){return c.call(this)}}function c(){return o.call(this)}}function o(){return n(l)}}))}function Yo(t){t.width=0,t.height=0}function Vo(){return new Promise((function(t,e){let i,r,s,n;return void 0!==Vo.cachedResult?t(Vo.cachedResult):zo("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/xABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAAAAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==","test.jpg",Date.now()).then((function(h){try{return i=h,Go(i).then((function(h){try{return r=h[1],Xo(r,i.type,i.name,i.lastModified).then((function(i){try{return s=i,Yo(r),Go(s).then((function(i){try{return n=i[0],Vo.cachedResult=1===n.width&&2===n.height,t(Vo.cachedResult)}catch(t){return e(t)}}),e)}catch(t){return e(t)}}),e)}catch(t){return e(t)}}),e)}catch(t){return e(t)}}),e)}))}function Zo(t){return new Promise(((e,i)=>{const r=new _o;r.onload=t=>{const i=new DataView(t.target.result);if(65496!=i.getUint16(0,false))return e(-2);const r=i.byteLength;let s=2;for(;s<r;){if(i.getUint16(s+2,false)<=8)return e(-1);const t=i.getUint16(s,false);if(s+=2,65505==t){if(1165519206!=i.getUint32(s+=2,false))return e(-1);const t=18761==i.getUint16(s+=6,false);s+=i.getUint32(s+4,t);const r=i.getUint16(s,t);s+=2;for(let n=0;n<r;n++)if(274==i.getUint16(s+12*n,t))return e(i.getUint16(s+12*n+8,t))}else{if(65280!=(65280&t))break;s+=i.getUint16(s,false)}}return e(-1)},r.onerror=t=>i(t),r.readAsArrayBuffer(t)}))}function tf(t,e){const{width:i}=t,{height:r}=t,{maxWidthOrHeight:s}=e;let n,h=t;return isFinite(s)&&(i>s||r>s)&&([h,n]=Ko(i,r),i>r?(h.width=s,h.height=r/i*s):(h.width=i/r*s,h.height=s),n.drawImage(t,0,0,h.width,h.height),Yo(t)),h}function ef(t,e){const{width:i}=t,{height:r}=t,[s,n]=Ko(i,r);switch(e>4&&e<9?(s.width=r,s.height=i):(s.width=i,s.height=r),e){case 2:n.transform(-1,0,0,1,i,0);break;case 3:n.transform(-1,0,0,-1,i,r);break;case 4:n.transform(1,0,0,-1,0,r);break;case 5:n.transform(0,1,1,0,0,0);break;case 6:n.transform(0,1,-1,0,r,0);break;case 7:n.transform(0,-1,-1,0,r,i);break;case 8:n.transform(0,-1,1,0,0,i)}return n.drawImage(t,0,0,i,r),Yo(t),s}function rf(t,e,i=0){return new Promise((function(r,s){let n,h,l,o,f,u,a,c,d,p,w,m,g,b,v,y,M,A,k,S;function x(t=5){if(e.signal&&e.signal.aborted)throw e.signal.reason;n+=t,e.onProgress(Math.min(n,100))}function E(t){if(e.signal&&e.signal.aborted)throw e.signal.reason;n=Math.min(Math.max(t,n),100),e.onProgress(n)}return n=i,h=e.maxIteration||10,l=1024*e.maxSizeMB*1024,x(),Go(t,e).then(function(i){try{return[,o]=i,x(),f=tf(o,e),x(),new Promise((function(i,r){var s;if(!(s=e.exifOrientation))return Zo(t).then(function(t){try{return s=t,n.call(this)}catch(t){return r(t)}}.bind(this),r);function n(){return i(s)}return n.call(this)})).then(function(i){try{return u=i,x(),Vo().then(function(i){try{return a=i?f:ef(f,u),x(),c=e.initialQuality||1,d=e.fileType||t.type,Xo(a,d,t.name,t.lastModified,c).then(function(i){try{{if(p=i,x(),w=p.size>l,m=p.size>t.size,!w&&!m)return E(100),r(p);var n;function u(){if(h--&&(v>l||v>g)){let e,i;return e=S?.95*k.width:k.width,i=S?.95*k.height:k.height,[M,A]=Ko(e,i),A.drawImage(k,0,0,e,i),c*="image/png"===d?.85:.95,Xo(M,d,t.name,t.lastModified,c).then((function(t){try{return y=t,Yo(k),k=M,v=y.size,E(Math.min(99,Math.floor((b-v)/(b-l)*100))),u}catch(t){return s(t)}}),s)}return[1]}return g=t.size,b=p.size,v=b,k=a,S=!e.alwaysKeepResolution&&w,(n=function(t){for(;t;){if(t.then)return void t.then(n,s);try{if(t.pop){if(t.length)return t.pop()?O.call(this):t;t=u}else t=t.call(this)}catch(t){return s(t)}}}.bind(this))(u);function O(){return Yo(k),Yo(M),Yo(f),Yo(a),Yo(o),E(100),r(y)}}}catch(D){return s(D)}}.bind(this),s)}catch(t){return s(t)}}.bind(this),s)}catch(t){return s(t)}}.bind(this),s)}catch(t){return s(t)}}.bind(this),s)}))}const sf="\nlet scriptImported = false\nself.addEventListener('message', async (e) => {\n const { file, id, imageCompressionLibUrl, options } = e.data\n options.onProgress = (progress) => self.postMessage({ progress, id })\n try {\n if (!scriptImported) {\n // console.log('[worker] importScripts', imageCompressionLibUrl)\n self.importScripts(imageCompressionLibUrl)\n scriptImported = true\n }\n // console.log('[worker] self', self)\n const compressedFile = await imageCompression(file, options)\n self.postMessage({ file: compressedFile, id })\n } catch (e) {\n // console.error('[worker] error', e)\n self.postMessage({ error: e.message + '\\n' + e.stack, id })\n }\n})\n";let nf;function hf(t,e){return new Promise(((i,r)=>{nf||(nf=function t(e){const i=[];return i.push(e),URL.createObjectURL(new Blob(i))}(sf));const s=new Worker(nf);s.addEventListener("message",(function t(n){if(e.signal&&e.signal.aborted)s.terminate();else if(void 0===n.data.progress){if(n.data.error)return r(new Error(n.data.error)),void s.terminate();i(n.data.file),s.terminate()}else e.onProgress(n.data.progress)})),s.addEventListener("error",r),e.signal&&e.signal.addEventListener("abort",(()=>{r(e.signal.reason),s.terminate()})),s.postMessage({file:t,imageCompressionLibUrl:e.libURL,options:{...e,onProgress:void 0,signal:void 0}})}))}function lf(t,e){return new Promise((function(i,r){let s,n,h,l,o,f;if(s={...e},h=0,({onProgress:l}=s),s.maxSizeMB=s.maxSizeMB||Number.POSITIVE_INFINITY,o="boolean"!=typeof s.useWebWorker||s.useWebWorker,delete s.useWebWorker,s.onProgress=t=>{h=t,"function"==typeof l&&l(h)},!(t instanceof Blob||t instanceof $o))return r(new Error("The file given is not an instance of Blob or File"));if(!/^image/.test(t.type))return r(new Error("The file given is not an image"));if(f="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,!o||"function"!=typeof Worker||f)return rf(t,s).then(function(t){try{return n=t,c.call(this)}catch(t){return r(t)}}.bind(this),r);var u=function(){try{return c.call(this)}catch(t){return r(t)}}.bind(this),a=function(e){try{return rf(t,s).then((function(t){try{return n=t,u()}catch(t){return r(t)}}),r)}catch(t){return r(t)}};try{return s.libURL=s.libURL||"https://cdn.jsdelivr.net/npm/browser-image-compression@2.0.2/dist/browser-image-compression.js",hf(t,s).then((function(t){try{return n=t,u()}catch(t){return a()}}),a)}catch(t){a()}function c(){try{n.name=t.name,n.lastModified=t.lastModified}catch(t){}try{s.preserveExif&&"image/jpeg"===t.type&&(!s.fileType||s.fileType&&s.fileType===t.type)&&(n=Oo(t,n))}catch(t){}return i(n)}}))}lf.getDataUrlFromFile=Jo,lf.getFilefromDataUrl=zo,lf.loadImage=Wo,lf.drawImageInCanvas=Ho,lf.drawFileInCanvas=Go,lf.canvasToFile=Xo,lf.getExifOrientation=Zo,lf.handleMaxWidthOrHeight=tf,lf.followExifOrientation=ef,lf.cleanupCanvasMemory=Yo,lf.isAutoOrientationInBrowser=Vo,lf.approximateBelowMaximumCanvasSizeOfBrowser=Lo,lf.copyExifWithoutOrientation=Oo,lf.getBrowserName=Qo,lf.version="2.0.2";class of extends Zl{fileInput=null;maxCompressionSize=300;constructor(t){super(t);this.setupFileInput()}onActivate(){this.openFilePicker()}openFilePicker(){if(this._core.store.isDisabled){return}this.fileInput.click()}setupFileInput(){this.fileInput=document.createElement("input");this.fileInput.type="file";this.fileInput.accept="image/*";this.fileInput.style.display="none";this.fileInput.addEventListener("change",this.handleFileSelect.bind(this));this.fileInput.addEventListener("cancel",this.handleCancel.bind(this));document.body.appendChild(this.fileInput)}handleFileSelect(t){const e=t.target;if(e.files&&e.files[0]){const t=e.files[0];lf(t,{maxWidthOrHeight:this.maxCompressionSize}).then((t=>{this.readFile(t)})).catch((t=>{console.error("Error during image compression or processing:",t);this.handleCancel()}))}else{console.info("File selection cancelled by user.");this.handleCancel()}if(e){e.value=""}}readFile(t){const e=new FileReader;e.onload=t=>{const e=new Image;e.src=t.target?.result;e.onload=()=>this.createKritzelImage(e)};e.readAsDataURL(t)}createKritzelImage(t){const e=Xl.create(this._core);const{scaledWidth:i,scaledHeight:r}=e.calculateScaledDimensions(t);e.src=t.src;e.width=i;e.height=r;e.zIndex=this._core.store.currentZIndex;e.centerInViewport();this.addImageToStore(e);return e}addImageToStore(e){const i=xo.create(this._core);i.addOrRemove(e);i.isSelected=true;const r=new Jl(this._core,this,e);const s=new wo(this._core,this,i);this._core.commandManager.executeCommand(new eo(this._core,this,[r,s]));this._core.store.setState("activeTool",t.getTool("selection"))}handleCancel(){this._core.store.setState("activeTool",t.getTool("selection"))}}export{wo as A,eo as B,Mo as D,to as K,e as O,so as R,h as U,vo as a,Yl as b,bo as c,ro as d,Ao as e,of as f,ko as g,s as h,ho as i,t as j,po as k,xo as l,n as m,So as n,io as o,Jl as p,Vl as q,Zl as r,Wl as s,Gl as t,Xl as u};
2
- //# sourceMappingURL=p-YVlgItFD.js.map