kritzel-stencil 0.0.126 → 0.0.128

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 (451) hide show
  1. package/dist/cjs/app-globals-V2Kpy_OQ.js +8 -0
  2. package/dist/cjs/app-globals-V2Kpy_OQ.js.map +1 -0
  3. package/dist/cjs/index-C7Read21.js +2638 -0
  4. package/dist/cjs/index-C7Read21.js.map +1 -0
  5. package/dist/cjs/index-CUSIflVf.js +1597 -0
  6. package/dist/cjs/index-CUSIflVf.js.map +1 -0
  7. package/dist/cjs/index.cjs.js +17 -0
  8. package/dist/cjs/index.cjs.js.map +1 -0
  9. package/dist/cjs/kritzel-brush-style_22.cjs.entry.js +3133 -0
  10. package/dist/cjs/loader.cjs.js +14 -0
  11. package/dist/cjs/loader.cjs.js.map +1 -0
  12. package/dist/cjs/stencil.cjs.js +26 -0
  13. package/dist/cjs/stencil.cjs.js.map +1 -0
  14. package/dist/collection/classes/commands/add-object.command.js +17 -0
  15. package/dist/collection/classes/commands/add-object.command.js.map +1 -0
  16. package/dist/collection/classes/commands/add-selection-group.command.js +20 -0
  17. package/dist/collection/classes/commands/add-selection-group.command.js.map +1 -0
  18. package/dist/collection/classes/commands/base.command.js +15 -0
  19. package/dist/collection/classes/commands/base.command.js.map +1 -0
  20. package/dist/collection/classes/commands/batch.command.js +14 -0
  21. package/dist/collection/classes/commands/batch.command.js.map +1 -0
  22. package/dist/collection/classes/commands/move-selection-group.command.js +25 -0
  23. package/dist/collection/classes/commands/move-selection-group.command.js.map +1 -0
  24. package/dist/collection/classes/commands/remove-object.command.js +20 -0
  25. package/dist/collection/classes/commands/remove-object.command.js.map +1 -0
  26. package/dist/collection/classes/commands/remove-selection-group.command.js +18 -0
  27. package/dist/collection/classes/commands/remove-selection-group.command.js.map +1 -0
  28. package/dist/collection/classes/commands/resize-selection-group.command.js +18 -0
  29. package/dist/collection/classes/commands/resize-selection-group.command.js.map +1 -0
  30. package/dist/collection/classes/commands/rotate-selection-group.command.js +24 -0
  31. package/dist/collection/classes/commands/rotate-selection-group.command.js.map +1 -0
  32. package/dist/collection/classes/commands/update-object.command.js +32 -0
  33. package/dist/collection/classes/commands/update-object.command.js.map +1 -0
  34. package/dist/collection/classes/commands/update-viewport.command.js +23 -0
  35. package/dist/collection/classes/commands/update-viewport.command.js.map +1 -0
  36. package/dist/collection/classes/database.class.js +227 -0
  37. package/dist/collection/classes/database.class.js.map +1 -0
  38. package/dist/collection/classes/handlers/base.handler.js +7 -0
  39. package/dist/collection/classes/handlers/base.handler.js.map +1 -0
  40. package/dist/collection/classes/handlers/context-menu.handler.js +47 -0
  41. package/dist/collection/classes/handlers/context-menu.handler.js.map +1 -0
  42. package/dist/collection/classes/handlers/hover.handler.js +19 -0
  43. package/dist/collection/classes/handlers/hover.handler.js.map +1 -0
  44. package/dist/collection/classes/handlers/key.handler.js +80 -0
  45. package/dist/collection/classes/handlers/key.handler.js.map +1 -0
  46. package/dist/collection/classes/handlers/move.handler.js +100 -0
  47. package/dist/collection/classes/handlers/move.handler.js.map +1 -0
  48. package/dist/collection/classes/handlers/resize.handler.js +158 -0
  49. package/dist/collection/classes/handlers/resize.handler.js.map +1 -0
  50. package/dist/collection/classes/handlers/rotation.handler.js +118 -0
  51. package/dist/collection/classes/handlers/rotation.handler.js.map +1 -0
  52. package/dist/collection/classes/handlers/selection.handler.js +200 -0
  53. package/dist/collection/classes/handlers/selection.handler.js.map +1 -0
  54. package/dist/collection/classes/history.class.js +84 -0
  55. package/dist/collection/classes/history.class.js.map +1 -0
  56. package/dist/collection/classes/objects/base-object.class.js +205 -0
  57. package/dist/collection/classes/objects/base-object.class.js.map +1 -0
  58. package/dist/collection/classes/objects/custom-element.class.js +53 -0
  59. package/dist/collection/classes/objects/custom-element.class.js.map +1 -0
  60. package/dist/collection/classes/objects/image.class.js +54 -0
  61. package/dist/collection/classes/objects/image.class.js.map +1 -0
  62. package/dist/collection/classes/objects/path.class.js +269 -0
  63. package/dist/collection/classes/objects/path.class.js.map +1 -0
  64. package/dist/collection/classes/objects/selection-box.class.js +23 -0
  65. package/dist/collection/classes/objects/selection-box.class.js.map +1 -0
  66. package/dist/collection/classes/objects/selection-group.class.js +158 -0
  67. package/dist/collection/classes/objects/selection-group.class.js.map +1 -0
  68. package/dist/collection/classes/objects/text.class.js +144 -0
  69. package/dist/collection/classes/objects/text.class.js.map +1 -0
  70. package/dist/{stencil/icon-registry.class-Bw5YkOTi.js → collection/classes/registries/icon-registry.class.js} +7 -7
  71. package/dist/collection/classes/registries/icon-registry.class.js.map +1 -0
  72. package/dist/collection/classes/registries/tool.registry.js +18 -0
  73. package/dist/collection/classes/registries/tool.registry.js.map +1 -0
  74. package/dist/collection/classes/reviver.class.js +66 -0
  75. package/dist/collection/classes/reviver.class.js.map +1 -0
  76. package/dist/collection/classes/store.class.js +410 -0
  77. package/dist/collection/classes/store.class.js.map +1 -0
  78. package/dist/collection/classes/structures/circular-buffer.structure.js +46 -0
  79. package/dist/collection/classes/structures/circular-buffer.structure.js.map +1 -0
  80. package/dist/collection/classes/structures/octree.structure.js +115 -0
  81. package/dist/collection/classes/structures/octree.structure.js.map +1 -0
  82. package/dist/collection/classes/tools/base-tool.class.js +31 -0
  83. package/dist/collection/classes/tools/base-tool.class.js.map +1 -0
  84. package/dist/collection/classes/tools/brush-tool.class.js +116 -0
  85. package/dist/collection/classes/tools/brush-tool.class.js.map +1 -0
  86. package/dist/collection/classes/tools/eraser-tool.class.js +86 -0
  87. package/dist/collection/classes/tools/eraser-tool.class.js.map +1 -0
  88. package/dist/collection/classes/tools/image-tool.class.js +91 -0
  89. package/dist/collection/classes/tools/image-tool.class.js.map +1 -0
  90. package/dist/collection/classes/tools/selection-tool.class.js +156 -0
  91. package/dist/collection/classes/tools/selection-tool.class.js.map +1 -0
  92. package/dist/collection/classes/tools/text-tool.class.js +116 -0
  93. package/dist/collection/classes/tools/text-tool.class.js.map +1 -0
  94. package/dist/collection/classes/viewport.class.js +152 -0
  95. package/dist/collection/classes/viewport.class.js.map +1 -0
  96. package/dist/collection/classes/workspace.class.js +10 -0
  97. package/dist/collection/classes/workspace.class.js.map +1 -0
  98. package/dist/collection/collection-manifest.json +33 -0
  99. package/dist/collection/components/core/kritzel-cursor-trail/kritzel-cursor-trail.css +10 -0
  100. package/dist/collection/components/core/kritzel-cursor-trail/kritzel-cursor-trail.js +154 -0
  101. package/dist/collection/components/core/kritzel-cursor-trail/kritzel-cursor-trail.js.map +1 -0
  102. package/dist/collection/components/core/kritzel-editor/kritzel-editor.css +29 -0
  103. package/dist/collection/components/core/kritzel-editor/kritzel-editor.js +670 -0
  104. package/dist/collection/components/core/kritzel-editor/kritzel-editor.js.map +1 -0
  105. package/dist/collection/components/core/kritzel-engine/kritzel-engine.css +60 -0
  106. package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +1483 -0
  107. package/dist/collection/components/core/kritzel-engine/kritzel-engine.js.map +1 -0
  108. package/dist/collection/components/shared/kritzel-brush-style/kritzel-brush-style.css +44 -0
  109. package/dist/collection/components/shared/kritzel-brush-style/kritzel-brush-style.js +100 -0
  110. package/dist/collection/components/shared/kritzel-brush-style/kritzel-brush-style.js.map +1 -0
  111. package/dist/collection/components/shared/kritzel-color/kritzel-color.css +21 -0
  112. package/dist/collection/components/shared/kritzel-color/kritzel-color.js +108 -0
  113. package/dist/collection/components/shared/kritzel-color/kritzel-color.js.map +1 -0
  114. package/dist/collection/components/shared/kritzel-color-palette/kritzel-color-palette.css +46 -0
  115. package/dist/collection/components/shared/kritzel-color-palette/kritzel-color-palette.js +147 -0
  116. package/dist/collection/components/shared/kritzel-color-palette/kritzel-color-palette.js.map +1 -0
  117. package/dist/collection/components/shared/kritzel-dropdown/kritzel-dropdown.css +53 -0
  118. package/dist/collection/components/shared/kritzel-dropdown/kritzel-dropdown.js +215 -0
  119. package/dist/collection/components/shared/kritzel-dropdown/kritzel-dropdown.js.map +1 -0
  120. package/dist/collection/components/shared/kritzel-font/kritzel-font.css +10 -0
  121. package/dist/collection/components/shared/kritzel-font/kritzel-font.js +92 -0
  122. package/dist/collection/components/shared/kritzel-font/kritzel-font.js.map +1 -0
  123. package/dist/collection/components/shared/kritzel-font-family/kritzel-font-family.css +48 -0
  124. package/dist/collection/components/shared/kritzel-font-family/kritzel-font-family.js +115 -0
  125. package/dist/collection/components/shared/kritzel-font-family/kritzel-font-family.js.map +1 -0
  126. package/dist/collection/components/shared/kritzel-font-size/kritzel-font-size.css +30 -0
  127. package/dist/collection/components/shared/kritzel-font-size/kritzel-font-size.js +112 -0
  128. package/dist/collection/components/shared/kritzel-font-size/kritzel-font-size.js.map +1 -0
  129. package/dist/collection/components/shared/kritzel-icon/kritzel-icon.css +17 -0
  130. package/dist/collection/components/shared/kritzel-icon/kritzel-icon.js +94 -0
  131. package/dist/collection/components/shared/kritzel-icon/kritzel-icon.js.map +1 -0
  132. package/dist/collection/components/shared/kritzel-menu/kritzel-menu.css +166 -0
  133. package/dist/collection/components/shared/kritzel-menu/kritzel-menu.js +272 -0
  134. package/dist/collection/components/shared/kritzel-menu/kritzel-menu.js.map +1 -0
  135. package/dist/collection/components/shared/kritzel-portal/kritzel-portal.js +218 -0
  136. package/dist/collection/components/shared/kritzel-portal/kritzel-portal.js.map +1 -0
  137. package/dist/collection/components/shared/kritzel-split-button/kritzel-split-button.css +74 -0
  138. package/dist/collection/components/shared/kritzel-split-button/kritzel-split-button.js +324 -0
  139. package/dist/collection/components/shared/kritzel-split-button/kritzel-split-button.js.map +1 -0
  140. package/dist/collection/components/shared/kritzel-stroke-size/kritzel-stroke-size.css +28 -0
  141. package/dist/collection/components/shared/kritzel-stroke-size/kritzel-stroke-size.js +91 -0
  142. package/dist/collection/components/shared/kritzel-stroke-size/kritzel-stroke-size.js.map +1 -0
  143. package/dist/collection/components/shared/kritzel-tooltip/kritzel-tooltip.css +17 -0
  144. package/dist/collection/components/shared/kritzel-tooltip/kritzel-tooltip.js +181 -0
  145. package/dist/collection/components/shared/kritzel-tooltip/kritzel-tooltip.js.map +1 -0
  146. package/dist/collection/components/ui/kritzel-context-menu/kritzel-context-menu.css +55 -0
  147. package/dist/collection/components/ui/kritzel-context-menu/kritzel-context-menu.js +141 -0
  148. package/dist/collection/components/ui/kritzel-context-menu/kritzel-context-menu.js.map +1 -0
  149. package/dist/collection/components/ui/kritzel-control-brush-config/kritzel-control-brush-config.css +19 -0
  150. package/dist/collection/components/ui/kritzel-control-brush-config/kritzel-control-brush-config.js +136 -0
  151. package/dist/collection/components/ui/kritzel-control-brush-config/kritzel-control-brush-config.js.map +1 -0
  152. package/dist/collection/components/ui/kritzel-control-text-config/kritzel-control-text-config.css +19 -0
  153. package/dist/collection/components/ui/kritzel-control-text-config/kritzel-control-text-config.js +116 -0
  154. package/dist/collection/components/ui/kritzel-control-text-config/kritzel-control-text-config.js.map +1 -0
  155. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.css +124 -0
  156. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js +280 -0
  157. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js.map +1 -0
  158. package/dist/collection/components/ui/kritzel-utility-panel/kritzel-utility-panel.css +33 -0
  159. package/dist/collection/components/ui/kritzel-utility-panel/kritzel-utility-panel.js +79 -0
  160. package/dist/collection/components/ui/kritzel-utility-panel/kritzel-utility-panel.js.map +1 -0
  161. package/dist/collection/components/ui/kritzel-workspace-manager/kritzel-workspace-manager.css +5 -0
  162. package/dist/collection/components/ui/kritzel-workspace-manager/kritzel-workspace-manager.js +209 -0
  163. package/dist/collection/components/ui/kritzel-workspace-manager/kritzel-workspace-manager.js.map +1 -0
  164. package/dist/{stencil/default-text-tool.config-DvOZmpuR.js → collection/configs/default-brush-tool.config.js} +2 -38
  165. package/dist/collection/configs/default-brush-tool.config.js.map +1 -0
  166. package/dist/collection/configs/default-engine-state.js +61 -0
  167. package/dist/collection/configs/default-engine-state.js.map +1 -0
  168. package/dist/collection/configs/default-text-tool.config.js +32 -0
  169. package/dist/collection/configs/default-text-tool.config.js.map +1 -0
  170. package/dist/collection/constants/engine.constants.js +3 -0
  171. package/dist/collection/constants/engine.constants.js.map +1 -0
  172. package/dist/collection/enums/event-button.enum.js +7 -0
  173. package/dist/collection/enums/event-button.enum.js.map +1 -0
  174. package/dist/collection/enums/handle-type.enum.js +8 -0
  175. package/dist/collection/enums/handle-type.enum.js.map +1 -0
  176. package/dist/collection/helpers/class.helper.js +6 -0
  177. package/dist/collection/helpers/class.helper.js.map +1 -0
  178. package/dist/collection/helpers/devices.helper.js +6 -0
  179. package/dist/collection/helpers/devices.helper.js.map +1 -0
  180. package/dist/collection/helpers/event.helper.js +58 -0
  181. package/dist/collection/helpers/event.helper.js.map +1 -0
  182. package/dist/collection/helpers/geometry.helper.js +53 -0
  183. package/dist/collection/helpers/geometry.helper.js.map +1 -0
  184. package/dist/collection/helpers/html.helper.js +36 -0
  185. package/dist/collection/helpers/html.helper.js.map +1 -0
  186. package/dist/collection/helpers/keyboard.helper.js +31 -0
  187. package/dist/collection/helpers/keyboard.helper.js.map +1 -0
  188. package/dist/collection/helpers/math.helper.js +6 -0
  189. package/dist/collection/helpers/math.helper.js.map +1 -0
  190. package/dist/collection/helpers/object.helper.js +38 -0
  191. package/dist/collection/helpers/object.helper.js.map +1 -0
  192. package/dist/collection/index.js +21 -0
  193. package/dist/collection/index.js.map +1 -0
  194. package/dist/collection/interfaces/bounding-box.interface.js +2 -0
  195. package/dist/collection/interfaces/bounding-box.interface.js.map +1 -0
  196. package/dist/collection/interfaces/command.interface.js +2 -0
  197. package/dist/collection/interfaces/command.interface.js.map +1 -0
  198. package/dist/collection/interfaces/context-menu-item.interface.js +2 -0
  199. package/dist/collection/interfaces/context-menu-item.interface.js.map +1 -0
  200. package/dist/collection/interfaces/debug-info.interface.js +2 -0
  201. package/dist/collection/interfaces/debug-info.interface.js.map +1 -0
  202. package/dist/collection/interfaces/engine-state.interface.js +2 -0
  203. package/dist/collection/interfaces/engine-state.interface.js.map +1 -0
  204. package/dist/collection/interfaces/menu-item.interface.js +2 -0
  205. package/dist/collection/interfaces/menu-item.interface.js.map +1 -0
  206. package/dist/collection/interfaces/object.interface.js +2 -0
  207. package/dist/collection/interfaces/object.interface.js.map +1 -0
  208. package/dist/collection/interfaces/path-options.interface.js +2 -0
  209. package/dist/collection/interfaces/path-options.interface.js.map +1 -0
  210. package/dist/collection/interfaces/point.interface.js +2 -0
  211. package/dist/collection/interfaces/point.interface.js.map +1 -0
  212. package/dist/collection/interfaces/polygon.interface.js +2 -0
  213. package/dist/collection/interfaces/polygon.interface.js.map +1 -0
  214. package/dist/collection/interfaces/selection-state.interface.js +2 -0
  215. package/dist/collection/interfaces/selection-state.interface.js.map +1 -0
  216. package/dist/collection/interfaces/serializable.interface.js +2 -0
  217. package/dist/collection/interfaces/serializable.interface.js.map +1 -0
  218. package/dist/collection/interfaces/tool.interface.js +2 -0
  219. package/dist/collection/interfaces/tool.interface.js.map +1 -0
  220. package/dist/collection/interfaces/toolbar-control.interface.js +2 -0
  221. package/dist/collection/interfaces/toolbar-control.interface.js.map +1 -0
  222. package/dist/collection/types/state.types.js +2 -0
  223. package/dist/collection/types/state.types.js.map +1 -0
  224. package/dist/components/index.d.ts +8 -0
  225. package/dist/components/index.js +28 -0
  226. package/dist/components/index.js.map +1 -0
  227. package/dist/components/kritzel-brush-style.js +9 -0
  228. package/dist/components/kritzel-brush-style.js.map +1 -0
  229. package/dist/components/kritzel-color-palette.js +9 -0
  230. package/dist/components/kritzel-color-palette.js.map +1 -0
  231. package/dist/components/kritzel-color.js +9 -0
  232. package/dist/components/kritzel-color.js.map +1 -0
  233. package/dist/components/kritzel-context-menu.js +9 -0
  234. package/dist/components/kritzel-context-menu.js.map +1 -0
  235. package/dist/components/kritzel-control-brush-config.js +9 -0
  236. package/dist/components/kritzel-control-brush-config.js.map +1 -0
  237. package/dist/components/kritzel-control-text-config.js +9 -0
  238. package/dist/components/kritzel-control-text-config.js.map +1 -0
  239. package/dist/components/kritzel-controls.js +9 -0
  240. package/dist/components/kritzel-controls.js.map +1 -0
  241. package/dist/components/kritzel-cursor-trail.js +9 -0
  242. package/dist/components/kritzel-cursor-trail.js.map +1 -0
  243. package/dist/components/kritzel-dropdown.js +9 -0
  244. package/dist/components/kritzel-dropdown.js.map +1 -0
  245. package/dist/components/kritzel-editor.js +439 -0
  246. package/dist/components/kritzel-editor.js.map +1 -0
  247. package/dist/components/kritzel-engine.js +9 -0
  248. package/dist/components/kritzel-engine.js.map +1 -0
  249. package/dist/components/kritzel-font-family.js +9 -0
  250. package/dist/components/kritzel-font-family.js.map +1 -0
  251. package/dist/components/kritzel-font-size.js +9 -0
  252. package/dist/components/kritzel-font-size.js.map +1 -0
  253. package/dist/components/kritzel-font.js +9 -0
  254. package/dist/components/kritzel-font.js.map +1 -0
  255. package/dist/components/kritzel-icon.js +9 -0
  256. package/dist/components/kritzel-icon.js.map +1 -0
  257. package/dist/components/kritzel-menu.d.ts +11 -0
  258. package/dist/components/kritzel-menu.js +9 -0
  259. package/dist/components/kritzel-menu.js.map +1 -0
  260. package/dist/components/kritzel-portal.d.ts +11 -0
  261. package/dist/components/kritzel-portal.js +9 -0
  262. package/dist/components/kritzel-portal.js.map +1 -0
  263. package/dist/components/kritzel-split-button.d.ts +11 -0
  264. package/dist/components/kritzel-split-button.js +9 -0
  265. package/dist/components/kritzel-split-button.js.map +1 -0
  266. package/dist/components/kritzel-stroke-size.js +9 -0
  267. package/dist/components/kritzel-stroke-size.js.map +1 -0
  268. package/dist/components/kritzel-tooltip.js +9 -0
  269. package/dist/components/kritzel-tooltip.js.map +1 -0
  270. package/dist/components/kritzel-utility-panel.js +9 -0
  271. package/dist/components/kritzel-utility-panel.js.map +1 -0
  272. package/dist/components/kritzel-workspace-manager.d.ts +11 -0
  273. package/dist/components/kritzel-workspace-manager.js +9 -0
  274. package/dist/components/kritzel-workspace-manager.js.map +1 -0
  275. package/dist/{stencil/kritzel-color.entry.js → components/p-5CJxFNEE.js} +31 -11
  276. package/dist/components/p-5CJxFNEE.js.map +1 -0
  277. package/dist/{stencil/brush-tool.class-D1U3x9_Y.js → components/p-B7VrEdgP.js} +77 -110
  278. package/dist/components/p-B7VrEdgP.js.map +1 -0
  279. package/dist/{stencil/kritzel-color-palette.entry.js → components/p-BAPUTr3K.js} +40 -12
  280. package/dist/components/p-BAPUTr3K.js.map +1 -0
  281. package/dist/{stencil/kritzel-controls.entry.js → components/p-BB22cVkU.js} +135 -27
  282. package/dist/components/p-BB22cVkU.js.map +1 -0
  283. package/dist/components/p-BLmFBe2a.js +96 -0
  284. package/dist/components/p-BLmFBe2a.js.map +1 -0
  285. package/dist/components/p-BU2q3PRS.js +84 -0
  286. package/dist/components/p-BU2q3PRS.js.map +1 -0
  287. package/dist/components/p-BZ-j_4CK.js +46 -0
  288. package/dist/components/p-BZ-j_4CK.js.map +1 -0
  289. package/dist/components/p-BaKb8ZLg.js +104 -0
  290. package/dist/components/p-BaKb8ZLg.js.map +1 -0
  291. package/dist/components/p-Bb6od8He.js +42 -0
  292. package/dist/components/p-Bb6od8He.js.map +1 -0
  293. package/dist/components/p-BcQTDgzV.js +56 -0
  294. package/dist/components/p-BcQTDgzV.js.map +1 -0
  295. package/dist/components/p-BeVv4o5c.js +14 -0
  296. package/dist/components/p-BeVv4o5c.js.map +1 -0
  297. package/dist/components/p-BmJbJwkH.js +167 -0
  298. package/dist/components/p-BmJbJwkH.js.map +1 -0
  299. package/dist/components/p-BqrTPNyu.js +1330 -0
  300. package/dist/components/p-BqrTPNyu.js.map +1 -0
  301. package/dist/{stencil/kritzel-dropdown.entry.js → components/p-BvlGgLAQ.js} +39 -11
  302. package/dist/components/p-BvlGgLAQ.js.map +1 -0
  303. package/dist/components/p-BzSz74Ci.js +56 -0
  304. package/dist/components/p-BzSz74Ci.js.map +1 -0
  305. package/dist/components/p-D-zg05gA.js +3148 -0
  306. package/dist/components/p-D-zg05gA.js.map +1 -0
  307. package/dist/{stencil/event-button.enum-D8W6LE-c.js → components/p-D8W6LE-c.js} +2 -2
  308. package/dist/components/p-D8W6LE-c.js.map +1 -0
  309. package/dist/components/p-DV4ERZv5.js +112 -0
  310. package/dist/components/p-DV4ERZv5.js.map +1 -0
  311. package/dist/{stencil/kritzel-cursor-trail.entry.js → components/p-DtmZW6eP.js} +32 -11
  312. package/dist/components/p-DtmZW6eP.js.map +1 -0
  313. package/dist/components/p-V4ui5aWj.js +63 -0
  314. package/dist/components/p-V4ui5aWj.js.map +1 -0
  315. package/dist/{stencil/kritzel-font-family.entry.js → components/p-_ntxNi8v.js} +37 -11
  316. package/dist/components/p-_ntxNi8v.js.map +1 -0
  317. package/dist/components/p-a7KmQzo4.js +113 -0
  318. package/dist/components/p-a7KmQzo4.js.map +1 -0
  319. package/dist/components/p-hSuNJiIq.js +152 -0
  320. package/dist/components/p-hSuNJiIq.js.map +1 -0
  321. package/dist/{stencil/kritzel-tooltip.entry.js → components/p-jG1e48OE.js} +39 -14
  322. package/dist/components/p-jG1e48OE.js.map +1 -0
  323. package/dist/components/p-rQeWFfPG.js +54 -0
  324. package/dist/components/p-rQeWFfPG.js.map +1 -0
  325. package/dist/components/p-sQmW5NRu.js +156 -0
  326. package/dist/components/p-sQmW5NRu.js.map +1 -0
  327. package/dist/esm/app-globals-DQuL1Twl.js +6 -0
  328. package/dist/esm/app-globals-DQuL1Twl.js.map +1 -0
  329. package/dist/esm/index-J4NpPimy.js +2611 -0
  330. package/dist/esm/index-J4NpPimy.js.map +1 -0
  331. package/dist/esm/index-NiIEUDzj.js +1570 -0
  332. package/dist/esm/index-NiIEUDzj.js.map +1 -0
  333. package/dist/esm/index.js +2 -0
  334. package/dist/esm/index.js.map +1 -0
  335. package/dist/esm/kritzel-brush-style_22.entry.js +3110 -0
  336. package/dist/esm/loader.js +12 -0
  337. package/dist/esm/loader.js.map +1 -0
  338. package/dist/esm/stencil.js +22 -0
  339. package/dist/esm/stencil.js.map +1 -0
  340. package/dist/index.cjs.js +1 -0
  341. package/dist/index.js +1 -0
  342. package/dist/stencil/index.esm.js +1 -16
  343. package/dist/stencil/index.esm.js.map +1 -1
  344. package/dist/stencil/loader.esm.js.map +1 -1
  345. package/dist/stencil/p-4a0009e7.entry.js +2 -0
  346. package/dist/stencil/p-4a0009e7.entry.js.map +1 -0
  347. package/dist/stencil/p-DQuL1Twl.js +2 -0
  348. package/dist/stencil/p-DQuL1Twl.js.map +1 -0
  349. package/dist/stencil/p-J4NpPimy.js +2 -0
  350. package/dist/stencil/p-J4NpPimy.js.map +1 -0
  351. package/dist/stencil/p-NiIEUDzj.js +3 -0
  352. package/dist/stencil/p-NiIEUDzj.js.map +1 -0
  353. package/dist/stencil/stencil.esm.js +1 -49
  354. package/dist/stencil/stencil.esm.js.map +1 -1
  355. package/dist/types/classes/commands/add-object.command.d.ts +1 -1
  356. package/dist/types/classes/commands/add-selection-group.command.d.ts +1 -1
  357. package/dist/types/classes/commands/base.command.d.ts +2 -2
  358. package/dist/types/classes/commands/batch.command.d.ts +1 -1
  359. package/dist/types/classes/commands/move-selection-group.command.d.ts +1 -1
  360. package/dist/types/classes/commands/remove-object.command.d.ts +1 -1
  361. package/dist/types/classes/commands/remove-selection-group.command.d.ts +1 -1
  362. package/dist/types/classes/commands/resize-selection-group.command.d.ts +1 -1
  363. package/dist/types/classes/commands/rotate-selection-group.command.d.ts +1 -1
  364. package/dist/types/classes/commands/update-object.command.d.ts +1 -1
  365. package/dist/types/classes/commands/update-viewport.command.d.ts +1 -1
  366. package/dist/types/classes/database.class.d.ts +28 -0
  367. package/dist/types/classes/history.class.d.ts +1 -0
  368. package/dist/types/classes/objects/base-object.class.d.ts +2 -0
  369. package/dist/types/classes/objects/path.class.d.ts +1 -0
  370. package/dist/types/classes/objects/text.class.d.ts +1 -1
  371. package/dist/types/classes/store.class.d.ts +19 -2
  372. package/dist/types/classes/structures/octree.structure.d.ts +1 -0
  373. package/dist/types/classes/workspace.class.d.ts +16 -0
  374. package/dist/types/components/core/kritzel-editor/kritzel-editor.d.ts +6 -1
  375. package/dist/types/components/core/kritzel-engine/kritzel-engine.d.ts +12 -2
  376. package/dist/types/components/shared/kritzel-menu/kritzel-menu.d.ts +24 -0
  377. package/dist/types/components/shared/kritzel-portal/kritzel-portal.d.ts +24 -0
  378. package/dist/types/components/shared/kritzel-split-button/kritzel-split-button.d.ts +24 -0
  379. package/dist/types/components/ui/kritzel-context-menu/kritzel-context-menu.d.ts +3 -4
  380. package/dist/types/components/ui/kritzel-controls/kritzel-controls.d.ts +2 -1
  381. package/dist/types/components/ui/kritzel-workspace-manager/kritzel-workspace-manager.d.ts +25 -0
  382. package/dist/types/components.d.ts +250 -2
  383. package/dist/types/helpers/html.helper.d.ts +3 -1
  384. package/dist/types/interfaces/command.interface.d.ts +1 -1
  385. package/dist/types/interfaces/debug-info.interface.d.ts +1 -0
  386. package/dist/types/interfaces/engine-state.interface.d.ts +3 -0
  387. package/dist/types/interfaces/menu-item.interface.d.ts +9 -0
  388. package/dist/types/interfaces/object.interface.d.ts +2 -0
  389. package/dist/types/stencil-public-runtime.d.ts +21 -0
  390. package/package.json +63 -62
  391. package/dist/stencil/brush-tool.class-D1U3x9_Y.js.map +0 -1
  392. package/dist/stencil/default-text-tool.config-DvOZmpuR.js.map +0 -1
  393. package/dist/stencil/engine.constants-DsjjAmnl.js +0 -7
  394. package/dist/stencil/engine.constants-DsjjAmnl.js.map +0 -1
  395. package/dist/stencil/event-button.enum-D8W6LE-c.js.map +0 -1
  396. package/dist/stencil/icon-registry.class-Bw5YkOTi.js.map +0 -1
  397. package/dist/stencil/image-tool.class-uKAmXFSl.js +0 -1341
  398. package/dist/stencil/image-tool.class-uKAmXFSl.js.map +0 -1
  399. package/dist/stencil/index-Df69oUcb.js +0 -4334
  400. package/dist/stencil/index-Df69oUcb.js.map +0 -1
  401. package/dist/stencil/kritzel-brush-style.entry.esm.js.map +0 -1
  402. package/dist/stencil/kritzel-brush-style.entry.js +0 -31
  403. package/dist/stencil/kritzel-brush-style.entry.js.map +0 -1
  404. package/dist/stencil/kritzel-color-palette.entry.esm.js.map +0 -1
  405. package/dist/stencil/kritzel-color-palette.entry.js.map +0 -1
  406. package/dist/stencil/kritzel-color.entry.esm.js.map +0 -1
  407. package/dist/stencil/kritzel-color.entry.js.map +0 -1
  408. package/dist/stencil/kritzel-context-menu-B2p1_Ffh.js +0 -91
  409. package/dist/stencil/kritzel-context-menu-B2p1_Ffh.js.map +0 -1
  410. package/dist/stencil/kritzel-context-menu-DPHV6MRm.js +0 -91
  411. package/dist/stencil/kritzel-context-menu-DPHV6MRm.js.map +0 -1
  412. package/dist/stencil/kritzel-context-menu.entry.esm.js.map +0 -1
  413. package/dist/stencil/kritzel-context-menu.entry.js +0 -5
  414. package/dist/stencil/kritzel-context-menu.entry.js.map +0 -1
  415. package/dist/stencil/kritzel-control-brush-config.entry.esm.js.map +0 -1
  416. package/dist/stencil/kritzel-control-brush-config.entry.js +0 -54
  417. package/dist/stencil/kritzel-control-brush-config.entry.js.map +0 -1
  418. package/dist/stencil/kritzel-control-text-config.entry.esm.js.map +0 -1
  419. package/dist/stencil/kritzel-control-text-config.entry.js +0 -42
  420. package/dist/stencil/kritzel-control-text-config.entry.js.map +0 -1
  421. package/dist/stencil/kritzel-controls.entry.esm.js.map +0 -1
  422. package/dist/stencil/kritzel-controls.entry.js.map +0 -1
  423. package/dist/stencil/kritzel-cursor-trail.entry.esm.js.map +0 -1
  424. package/dist/stencil/kritzel-cursor-trail.entry.js.map +0 -1
  425. package/dist/stencil/kritzel-dropdown.entry.esm.js.map +0 -1
  426. package/dist/stencil/kritzel-dropdown.entry.js.map +0 -1
  427. package/dist/stencil/kritzel-editor.entry.esm.js.map +0 -1
  428. package/dist/stencil/kritzel-editor.entry.js +0 -180
  429. package/dist/stencil/kritzel-editor.entry.js.map +0 -1
  430. package/dist/stencil/kritzel-engine.entry.esm.js.map +0 -1
  431. package/dist/stencil/kritzel-engine.entry.js +0 -1318
  432. package/dist/stencil/kritzel-engine.entry.js.map +0 -1
  433. package/dist/stencil/kritzel-font-family.entry.esm.js.map +0 -1
  434. package/dist/stencil/kritzel-font-family.entry.js.map +0 -1
  435. package/dist/stencil/kritzel-font-size.entry.esm.js.map +0 -1
  436. package/dist/stencil/kritzel-font-size.entry.js +0 -29
  437. package/dist/stencil/kritzel-font-size.entry.js.map +0 -1
  438. package/dist/stencil/kritzel-font.entry.esm.js.map +0 -1
  439. package/dist/stencil/kritzel-font.entry.js +0 -25
  440. package/dist/stencil/kritzel-font.entry.js.map +0 -1
  441. package/dist/stencil/kritzel-icon.entry.esm.js.map +0 -1
  442. package/dist/stencil/kritzel-icon.entry.js +0 -29
  443. package/dist/stencil/kritzel-icon.entry.js.map +0 -1
  444. package/dist/stencil/kritzel-stroke-size.entry.esm.js.map +0 -1
  445. package/dist/stencil/kritzel-stroke-size.entry.js +0 -28
  446. package/dist/stencil/kritzel-stroke-size.entry.js.map +0 -1
  447. package/dist/stencil/kritzel-tooltip.entry.esm.js.map +0 -1
  448. package/dist/stencil/kritzel-tooltip.entry.js.map +0 -1
  449. package/dist/stencil/kritzel-utility-panel.entry.esm.js.map +0 -1
  450. package/dist/stencil/kritzel-utility-panel.entry.js +0 -33
  451. package/dist/stencil/kritzel-utility-panel.entry.js.map +0 -1
@@ -0,0 +1,3148 @@
1
+ import { p as proxyCustomElement, H, c as createEvent, h, d as Host } from './p-BqrTPNyu.js';
2
+ import { K as KritzelMouseButton } from './p-D8W6LE-c.js';
3
+ import { d as KritzelBaseObject, e as KritzelBaseCommand, f as KritzelBaseTool, g as KritzelEventHelper, U as UpdateObjectCommand, c as KritzelTextTool, b as KritzelBrushTool, K as KritzelText, a as KritzelPath, A as AddObjectCommand, h as KritzelToolRegistry, i as KritzelKeyboardHelper } from './p-B7VrEdgP.js';
4
+ import { O as ObjectHelper } from './p-Bb6od8He.js';
5
+ import { K as KritzelContextMenu, d as defineCustomElement$3 } from './p-BU2q3PRS.js';
6
+ import { K as KritzelWorkspace } from './p-BeVv4o5c.js';
7
+ import { d as defineCustomElement$2 } from './p-DtmZW6eP.js';
8
+ import { d as defineCustomElement$1 } from './p-BLmFBe2a.js';
9
+
10
+ class KritzelImage extends KritzelBaseObject {
11
+ constructor(config) {
12
+ super();
13
+ this.__class__ = 'KritzelImage';
14
+ this.src = '';
15
+ this.maxWidth = 300;
16
+ this.maxHeight = 300;
17
+ this.maxCompressionSize = 300;
18
+ this.isDebugInfoVisible = true;
19
+ this.src = (config === null || config === void 0 ? void 0 : config.src) || '';
20
+ this.x = (config === null || config === void 0 ? void 0 : config.x) || 0;
21
+ this.y = (config === null || config === void 0 ? void 0 : config.y) || 0;
22
+ this.translateX = (config === null || config === void 0 ? void 0 : config.translateX) || 0;
23
+ this.translateY = (config === null || config === void 0 ? void 0 : config.translateY) || 0;
24
+ this.scale = (config === null || config === void 0 ? void 0 : config.scale) || 1;
25
+ }
26
+ static create(store) {
27
+ const object = new KritzelImage();
28
+ object._store = store;
29
+ object.id = object.generateId();
30
+ object.workspaceId = store.state.activeWorkspace.id;
31
+ object.x = 0;
32
+ object.y = 0;
33
+ object.translateX = 0;
34
+ object.translateY = 0;
35
+ object.scale = object._store.state.scale;
36
+ object.zIndex = store.currentZIndex;
37
+ return object;
38
+ }
39
+ resize(x, y, width, height) {
40
+ if (width <= 1 || height <= 1) {
41
+ return;
42
+ }
43
+ const scaleFactor = height / this.height;
44
+ this.width = this.width * scaleFactor;
45
+ this.height = this.height * scaleFactor;
46
+ this.translateX = x;
47
+ this.translateY = y;
48
+ }
49
+ calculateScaledDimensions(img) {
50
+ let scaledWidth = img.width;
51
+ let scaledHeight = img.height;
52
+ if (img.width > this.maxWidth || img.height > this.maxHeight) {
53
+ const widthRatio = this.maxWidth / img.width;
54
+ const heightRatio = this.maxHeight / img.height;
55
+ const scaleRatio = Math.min(widthRatio, heightRatio);
56
+ scaledWidth = img.width * scaleRatio;
57
+ scaledHeight = img.height * scaleRatio;
58
+ }
59
+ return { scaledWidth, scaledHeight };
60
+ }
61
+ }
62
+
63
+ class BatchCommand extends KritzelBaseCommand {
64
+ constructor(store, initiator, commands, skipHistory = false) {
65
+ super(store, initiator, skipHistory);
66
+ this.commands = commands;
67
+ }
68
+ execute() {
69
+ this.commands.forEach(command => command.execute());
70
+ }
71
+ undo() {
72
+ this.commands.forEach(command => command.undo());
73
+ }
74
+ }
75
+
76
+ class KritzelCustomElement extends KritzelBaseObject {
77
+ constructor(config) {
78
+ super();
79
+ this.__class__ = 'KritzelCustomElement';
80
+ this.isInteractive = true;
81
+ if (config) {
82
+ this.translateX = config.translateX || 0;
83
+ this.translateY = config.translateY || 0;
84
+ this.scale = config.scale || 1;
85
+ this.element = config.element;
86
+ this.height = config.height || 0;
87
+ this.width = config.width || 0;
88
+ }
89
+ }
90
+ static create(store, config) {
91
+ const object = new KritzelCustomElement(config);
92
+ object._store = store;
93
+ object.id = object.generateId();
94
+ object.workspaceId = store.state.activeWorkspace.id;
95
+ return object;
96
+ }
97
+ mount(element) {
98
+ if (this.isMounted) {
99
+ return;
100
+ }
101
+ this.elementRef = element;
102
+ this.isMounted = true;
103
+ this.elementRef.appendChild(this.element);
104
+ }
105
+ resize(x, y, width, height) {
106
+ if (width <= 1 || height <= 1) {
107
+ return;
108
+ }
109
+ this.width = width;
110
+ this.height = height;
111
+ this.translateX = x;
112
+ this.translateY = y;
113
+ if (this.element) {
114
+ this.element.style.width = `${width}px`;
115
+ this.element.style.height = `${height}px`;
116
+ }
117
+ }
118
+ copy() {
119
+ const copiedObject = Object.create(Object.getPrototypeOf(this));
120
+ Object.assign(copiedObject, this);
121
+ copiedObject.id = this.generateId();
122
+ copiedObject.isMounted = false;
123
+ copiedObject.element = this.element.cloneNode(true);
124
+ return copiedObject;
125
+ }
126
+ }
127
+
128
+ class RemoveObjectCommand extends KritzelBaseCommand {
129
+ constructor(store, initiator, object, skipHistory = false) {
130
+ super(store, initiator, skipHistory);
131
+ this.object = object;
132
+ }
133
+ execute() {
134
+ this._store.state.objectsOctree.remove(object => object.id === this.object.id);
135
+ this._store.state.objectsOctree.filter(object => object instanceof KritzelCustomElement).forEach(object => object.remount());
136
+ this._store.deleteObjectFromDatabase(this.object.id);
137
+ }
138
+ undo() {
139
+ this._store.state.objectsOctree.insert(this.object);
140
+ this._store.state.objectsOctree.filter(object => object instanceof KritzelCustomElement).forEach(object => object.remount());
141
+ this._store.addObjectToDatabase(ObjectHelper.clone(this.object));
142
+ }
143
+ }
144
+
145
+ class KritzelEraserTool extends KritzelBaseTool {
146
+ constructor(store) {
147
+ super(store);
148
+ this.touchStartTimeout = null;
149
+ }
150
+ handlePointerDown(event) {
151
+ if (event.pointerType === 'mouse') {
152
+ if (KritzelEventHelper.isLeftClick(event)) {
153
+ this._store.state.isErasing = true;
154
+ }
155
+ }
156
+ if (event.pointerType === 'touch') {
157
+ this.touchStartTimeout = setTimeout(() => {
158
+ if (this._store.state.pointers.size === 1 && !this._store.state.isScaling) {
159
+ this._store.state.isErasing = true;
160
+ }
161
+ }, 80);
162
+ }
163
+ }
164
+ handlePointerMove(event) {
165
+ var _a;
166
+ if (event.pointerType === 'mouse') {
167
+ if (this._store.state.isErasing) {
168
+ const selectedObjects = this._store.getObjectsFromPointerEvent(event, '.object');
169
+ if (selectedObjects.length === 0)
170
+ return;
171
+ const x = this._store.state.pointerX;
172
+ const y = this._store.state.pointerY;
173
+ selectedObjects.forEach(selectedObject => {
174
+ selectedObject.markedForRemoval = selectedObject.hitTest(x, y);
175
+ });
176
+ this._store.rerender();
177
+ }
178
+ }
179
+ if (event.pointerType === 'touch') {
180
+ if (this._store.state.pointers.size === 1 && this._store.state.isErasing) {
181
+ const shadowRoot = (_a = this._store.state.host) === null || _a === void 0 ? void 0 : _a.shadowRoot;
182
+ if (!shadowRoot)
183
+ return;
184
+ const selectedObjects = this._store.getObjectsFromPointerEvent(event, '.object');
185
+ if (selectedObjects.length === 0)
186
+ return;
187
+ const x = this._store.state.pointerX;
188
+ const y = this._store.state.pointerY;
189
+ selectedObjects.forEach(selectedObject => {
190
+ selectedObject.markedForRemoval = selectedObject.hitTest(x, y);
191
+ });
192
+ this._store.rerender();
193
+ }
194
+ }
195
+ }
196
+ handlePointerUp(event) {
197
+ if (event.pointerType === 'mouse') {
198
+ if (this._store.state.isErasing) {
199
+ const removeCommands = this._store.allObjects.filter(object => object.markedForRemoval).map(object => {
200
+ object.markedForRemoval = false;
201
+ return new RemoveObjectCommand(this._store, this, object);
202
+ });
203
+ if (removeCommands.length > 0) {
204
+ this._store.history.executeCommand(new BatchCommand(this._store, this, removeCommands));
205
+ }
206
+ this._store.state.isErasing = false;
207
+ }
208
+ }
209
+ if (event.pointerType === 'touch') {
210
+ clearTimeout(this.touchStartTimeout);
211
+ if (this._store.state.isErasing) {
212
+ const removeCommands = this._store.allObjects
213
+ .filter(object => object.markedForRemoval)
214
+ .map(object => {
215
+ object.markedForRemoval = false;
216
+ return new RemoveObjectCommand(this._store, this, object);
217
+ });
218
+ if (removeCommands.length > 0) {
219
+ this._store.history.executeCommand(new BatchCommand(this._store, this, removeCommands));
220
+ }
221
+ this._store.state.isErasing = false;
222
+ }
223
+ }
224
+ }
225
+ }
226
+
227
+ class RemoveSelectionGroupCommand extends KritzelBaseCommand {
228
+ constructor(store, initiator, skipHistory = false) {
229
+ super(store, initiator, skipHistory);
230
+ this.previousSelectionGroup = this._store.state.selectionGroup;
231
+ }
232
+ execute() {
233
+ this._store.state.objectsOctree.remove(object => { var _a; return object.id === ((_a = this.previousSelectionGroup) === null || _a === void 0 ? void 0 : _a.id); });
234
+ this._store.state.selectionGroup = null;
235
+ }
236
+ undo() {
237
+ if (this.previousSelectionGroup) {
238
+ this._store.state.objectsOctree.insert(this.previousSelectionGroup);
239
+ this._store.state.selectionGroup = this.previousSelectionGroup;
240
+ }
241
+ }
242
+ }
243
+
244
+ class MoveSelectionGroupCommand extends KritzelBaseCommand {
245
+ constructor(store, initiator, startX, startY, endX, endY, skipFirstExecution = false, skipHistory = false) {
246
+ super(store, initiator, skipHistory);
247
+ this.startX = startX;
248
+ this.startY = startY;
249
+ this.endX = endX;
250
+ this.endY = endY;
251
+ this.skipExecution = skipFirstExecution;
252
+ this.selectionGroup = this._store.state.selectionGroup;
253
+ }
254
+ execute() {
255
+ if (this.skipExecution) {
256
+ this.skipExecution = false;
257
+ return;
258
+ }
259
+ this._store.state.selectionGroup = this.selectionGroup;
260
+ this._store.state.selectionGroup.move(this.startX, this.startY, this.endX, this.endY);
261
+ }
262
+ undo() {
263
+ this._store.state.selectionGroup = this.selectionGroup;
264
+ this._store.state.selectionGroup.move(this.endX, this.endY, this.startX, this.startY);
265
+ }
266
+ }
267
+
268
+ class KritzelBaseHandler {
269
+ constructor(store) {
270
+ this._store = store;
271
+ }
272
+ }
273
+
274
+ class KritzelMoveHandler extends KritzelBaseHandler {
275
+ constructor(store) {
276
+ super(store);
277
+ }
278
+ handlePointerDown(event) {
279
+ var _a, _b;
280
+ if (event.pointerType === 'mouse') {
281
+ if (KritzelEventHelper.isLeftClick(event)) {
282
+ if (((_a = this._store.state.selectionGroup) === null || _a === void 0 ? void 0 : _a.isSelected) && !this._store.state.isResizeHandleSelected && !this._store.state.isRotationHandleSelected) {
283
+ const clientX = event.clientX - this._store.offsetX;
284
+ const clientY = event.clientY - this._store.offsetY;
285
+ this._store.state.isDragging = true;
286
+ this.dragStartX = clientX;
287
+ this.dragStartY = clientY;
288
+ this.startX = this.dragStartX;
289
+ this.startY = this.dragStartY;
290
+ }
291
+ }
292
+ }
293
+ if (event.pointerType === 'touch') {
294
+ const activePointers = Array.from(this._store.state.pointers.values());
295
+ if (this._store.state.pointers.size === 1) {
296
+ if (((_b = this._store.state.selectionGroup) === null || _b === void 0 ? void 0 : _b.isSelected) && !this._store.state.isResizeHandleSelected && !this._store.state.isRotationHandleSelected) {
297
+ const x = Math.round(activePointers[0].clientX - this._store.offsetX);
298
+ const y = Math.round(activePointers[0].clientY - this._store.offsetY);
299
+ this.dragStartX = x;
300
+ this.dragStartY = y;
301
+ this.startX = x;
302
+ this.startY = y;
303
+ }
304
+ }
305
+ }
306
+ }
307
+ handlePointerMove(event) {
308
+ if (event.pointerType === 'mouse') {
309
+ if (this._store.state.isDragging && this._store.state.selectionGroup) {
310
+ const clientX = event.clientX - this._store.offsetX;
311
+ const clientY = event.clientY - this._store.offsetY;
312
+ this.endX = clientX;
313
+ this.endY = clientY;
314
+ this._store.state.selectionGroup.move(clientX, clientY, this.dragStartX, this.dragStartY);
315
+ this.dragStartX = clientX;
316
+ this.dragStartY = clientY;
317
+ }
318
+ }
319
+ if (event.pointerType === 'touch') {
320
+ const activePointers = Array.from(this._store.state.pointers.values());
321
+ if (this._store.state.pointers.size === 1 && this._store.state.selectionGroup && !this._store.state.isResizeHandleSelected && !this._store.state.isRotationHandleSelected) {
322
+ const x = Math.round(activePointers[0].clientX - this._store.offsetX);
323
+ const y = Math.round(activePointers[0].clientY - this._store.offsetY);
324
+ this._store.state.isDragging = true;
325
+ this.endX = x;
326
+ this.endY = y;
327
+ const moveDeltaX = Math.abs(x - this.startX);
328
+ const moveDeltaY = Math.abs(y - this.startY);
329
+ const moveThreshold = 5;
330
+ if (moveDeltaX > moveThreshold || moveDeltaY > moveThreshold) {
331
+ clearTimeout(this._store.state.longTouchTimeout);
332
+ this._store.state.selectionGroup.move(x, y, this.dragStartX, this.dragStartY);
333
+ this.dragStartX = x;
334
+ this.dragStartY = y;
335
+ }
336
+ }
337
+ }
338
+ }
339
+ handlePointerUp(event) {
340
+ if (event.pointerType === 'mouse') {
341
+ if (this._store.state.isDragging) {
342
+ this._store.state.isDragging = false;
343
+ const moveSelectionGroupCommand = new MoveSelectionGroupCommand(this._store, this, this.endX, this.endY, this.startX, this.startY, true);
344
+ const updateObjectsCommand = this._store.state.selectionGroup.objects.map(object => {
345
+ return new UpdateObjectCommand(this._store, this, object, {
346
+ translateX: object.translateX,
347
+ translateY: object.translateY
348
+ });
349
+ });
350
+ this._store.history.executeCommand(new BatchCommand(this._store, this, [moveSelectionGroupCommand, ...updateObjectsCommand]));
351
+ }
352
+ }
353
+ if (event.pointerType === 'touch') {
354
+ if (this._store.state.isDragging) {
355
+ this._store.state.isDragging = false;
356
+ const moveSelectionGroupCommand = new MoveSelectionGroupCommand(this._store, this, this.endX, this.endY, this.startX, this.startY, true);
357
+ const updateObjectsCommand = this._store.state.selectionGroup.objects.map(object => {
358
+ return new UpdateObjectCommand(this._store, this, object, {
359
+ translateX: object.translateX,
360
+ translateY: object.translateY
361
+ });
362
+ });
363
+ this._store.history.executeCommand(new BatchCommand(this._store, this, [moveSelectionGroupCommand, ...updateObjectsCommand]));
364
+ }
365
+ }
366
+ }
367
+ }
368
+
369
+ var KritzelHandleType;
370
+ (function (KritzelHandleType) {
371
+ KritzelHandleType["TopLeft"] = "top-left";
372
+ KritzelHandleType["TopRight"] = "top-right";
373
+ KritzelHandleType["BottomLeft"] = "bottom-left";
374
+ KritzelHandleType["BottomRight"] = "bottom-right";
375
+ })(KritzelHandleType || (KritzelHandleType = {}));
376
+
377
+ class ResizeSelectionGroupCommand extends KritzelBaseCommand {
378
+ constructor(store, initiator, previousSize, newSize, skipHistory = false) {
379
+ super(store, initiator, skipHistory);
380
+ this.previousSize = previousSize;
381
+ this.newSize = newSize;
382
+ this.selectionGroup = this._store.state.selectionGroup;
383
+ }
384
+ execute() {
385
+ this._store.state.selectionGroup = this.selectionGroup;
386
+ this._store.state.selectionGroup.resize(this.newSize.x, this.newSize.y, this.newSize.width, this.newSize.height);
387
+ }
388
+ undo() {
389
+ this._store.state.selectionGroup = this.selectionGroup;
390
+ this._store.state.selectionGroup.resize(this.previousSize.x, this.previousSize.y, this.previousSize.width, this.previousSize.height);
391
+ }
392
+ }
393
+
394
+ class KritzelResizeHandler extends KritzelBaseHandler {
395
+ constructor(store) {
396
+ super(store);
397
+ this.initialMouseX = 0;
398
+ this.initialMouseY = 0;
399
+ this.initialSize = { x: 0, y: 0, width: 0, height: 0 };
400
+ this.newSize = { x: 0, y: 0, width: 0, height: 0 };
401
+ }
402
+ handlePointerDown(event) {
403
+ if (event.pointerType === 'mouse') {
404
+ if (KritzelEventHelper.isLeftClick(event)) {
405
+ if (this._store.state.selectionGroup && this._store.state.isResizeHandleSelected) {
406
+ const clientX = event.clientX - this._store.offsetX;
407
+ const clientY = event.clientY - this._store.offsetY;
408
+ this._store.state.isResizing = true;
409
+ this.initialMouseX = clientX;
410
+ this.initialMouseY = clientY;
411
+ this.initialSize.width = this._store.state.selectionGroup.width;
412
+ this.initialSize.height = this._store.state.selectionGroup.height;
413
+ this.initialSize.x = this._store.state.selectionGroup.translateX;
414
+ this.initialSize.y = this._store.state.selectionGroup.translateY;
415
+ }
416
+ }
417
+ }
418
+ if (event.pointerType === 'touch') {
419
+ const activePointers = Array.from(this._store.state.pointers.values());
420
+ const firstTouch = activePointers[0];
421
+ if (!firstTouch) {
422
+ return;
423
+ }
424
+ if (activePointers.length === 1) {
425
+ if (this._store.state.selectionGroup && this._store.state.isResizeHandleSelected) {
426
+ const clientX = Math.round(firstTouch.clientX - this._store.offsetX);
427
+ const clientY = Math.round(firstTouch.clientY - this._store.offsetY);
428
+ this._store.state.isResizing = true;
429
+ this.initialMouseX = clientX;
430
+ this.initialMouseY = clientY;
431
+ this.initialSize.width = this._store.state.selectionGroup.width;
432
+ this.initialSize.height = this._store.state.selectionGroup.height;
433
+ this.initialSize.x = this._store.state.selectionGroup.translateX;
434
+ this.initialSize.y = this._store.state.selectionGroup.translateY;
435
+ clearTimeout(this._store.state.longTouchTimeout);
436
+ }
437
+ }
438
+ }
439
+ }
440
+ handlePointerMove(event) {
441
+ if (event.pointerType === 'mouse') {
442
+ if (this._store.state.isResizing && this._store.state.selectionGroup) {
443
+ const clientX = event.clientX - this._store.offsetX;
444
+ const clientY = event.clientY - this._store.offsetY;
445
+ const dx = clientX - this.initialMouseX;
446
+ const dy = clientY - this.initialMouseY;
447
+ switch (this._store.state.resizeHandleType) {
448
+ case KritzelHandleType.TopLeft:
449
+ this.newSize.width = this.initialSize.width - dx;
450
+ this.newSize.height = this.initialSize.height - dy;
451
+ this.newSize.x = dx / this._store.state.scale + this.initialSize.x;
452
+ this.newSize.y = dy / this._store.state.scale + this.initialSize.y;
453
+ break;
454
+ case KritzelHandleType.TopRight:
455
+ this.newSize.width = this.initialSize.width + dx;
456
+ this.newSize.height = this.initialSize.height - dy;
457
+ this.newSize.x = this.initialSize.x;
458
+ this.newSize.y = dy / this._store.state.scale + this.initialSize.y;
459
+ break;
460
+ case KritzelHandleType.BottomLeft:
461
+ this.newSize.width = this.initialSize.width - dx;
462
+ this.newSize.height = this.initialSize.height + dy;
463
+ this.newSize.x = dx / this._store.state.scale + this.initialSize.x;
464
+ this.newSize.y = this.initialSize.y;
465
+ break;
466
+ case KritzelHandleType.BottomRight:
467
+ this.newSize.width = this.initialSize.width + dx;
468
+ this.newSize.height = this.initialSize.height + dy;
469
+ this.newSize.x = this.initialSize.x;
470
+ this.newSize.y = this.initialSize.y;
471
+ break;
472
+ }
473
+ this._store.state.selectionGroup.resize(this.newSize.x, this.newSize.y, this.newSize.width, this.newSize.height);
474
+ this._store.rerender();
475
+ }
476
+ }
477
+ if (event.pointerType === 'touch') {
478
+ const activePointers = Array.from(this._store.state.pointers.values());
479
+ const oneFingerTouch = activePointers[0];
480
+ if (!oneFingerTouch) {
481
+ return;
482
+ }
483
+ if (this._store.state.isResizing && this._store.state.selectionGroup) {
484
+ const clientX = Math.round(oneFingerTouch.clientX - this._store.offsetX);
485
+ const clientY = Math.round(oneFingerTouch.clientY - this._store.offsetY);
486
+ const dx = clientX - this.initialMouseX;
487
+ const dy = clientY - this.initialMouseY;
488
+ switch (this._store.state.resizeHandleType) {
489
+ case KritzelHandleType.TopLeft:
490
+ this.newSize.width = this.initialSize.width - dx;
491
+ this.newSize.height = this.initialSize.height - dy;
492
+ this.newSize.x = dx / this._store.state.scale + this.initialSize.x;
493
+ this.newSize.y = dy / this._store.state.scale + this.initialSize.y;
494
+ break;
495
+ case KritzelHandleType.TopRight:
496
+ this.newSize.width = this.initialSize.width + dx;
497
+ this.newSize.height = this.initialSize.height - dy;
498
+ this.newSize.x = this.initialSize.x;
499
+ this.newSize.y = dy / this._store.state.scale + this.initialSize.y;
500
+ break;
501
+ case KritzelHandleType.BottomLeft:
502
+ this.newSize.width = this.initialSize.width - dx;
503
+ this.newSize.height = this.initialSize.height + dy;
504
+ this.newSize.x = dx / this._store.state.scale + this.initialSize.x;
505
+ this.newSize.y = this.initialSize.y;
506
+ break;
507
+ case KritzelHandleType.BottomRight:
508
+ this.newSize.width = this.initialSize.width + dx;
509
+ this.newSize.height = this.initialSize.height + dy;
510
+ this.newSize.x = this.initialSize.x;
511
+ this.newSize.y = this.initialSize.y;
512
+ break;
513
+ }
514
+ this._store.state.selectionGroup.resize(this.newSize.x, this.newSize.y, this.newSize.width, this.newSize.height);
515
+ clearTimeout(this._store.state.longTouchTimeout);
516
+ }
517
+ }
518
+ }
519
+ handlePointerUp(event) {
520
+ if (event.pointerType === 'mouse') {
521
+ if (this._store.state.isResizing) {
522
+ const resizeSelectionGroupCommand = new ResizeSelectionGroupCommand(this._store, this, structuredClone(this.initialSize), structuredClone(this.newSize));
523
+ const updateObjectsCommand = this._store.state.selectionGroup.objects.map(object => {
524
+ return new UpdateObjectCommand(this._store, this, object, Object.assign({}, object));
525
+ });
526
+ this._store.history.executeCommand(new BatchCommand(this._store, this, [resizeSelectionGroupCommand, ...updateObjectsCommand]));
527
+ this._store.state.isResizing = false;
528
+ this._store.rerender();
529
+ }
530
+ }
531
+ if (event.pointerType === 'touch') {
532
+ if (this._store.state.isResizing) {
533
+ const resizeSelectionGroupCommand = new ResizeSelectionGroupCommand(this._store, this, structuredClone(this.initialSize), structuredClone(this.newSize));
534
+ const updateObjectsCommand = this._store.state.selectionGroup.objects.map(object => {
535
+ return new UpdateObjectCommand(this._store, this, object, Object.assign({}, object));
536
+ });
537
+ this._store.history.executeCommand(new BatchCommand(this._store, this, [resizeSelectionGroupCommand, ...updateObjectsCommand]));
538
+ this._store.state.isResizing = false;
539
+ this._store.rerender();
540
+ clearTimeout(this._store.state.longTouchTimeout);
541
+ }
542
+ }
543
+ }
544
+ }
545
+
546
+ class RotateSelectionGroupCommand extends KritzelBaseCommand {
547
+ constructor(store, initiator, rotation, skipHistory = false) {
548
+ super(store, initiator, skipHistory);
549
+ this.rotation = rotation;
550
+ this.initialRotation = this._store.state.selectionGroup.rotation;
551
+ this.selectionGroup = this._store.state.selectionGroup;
552
+ }
553
+ execute() {
554
+ this._store.state.selectionGroup = this.selectionGroup;
555
+ this._store.state.selectionGroup.rotate(this.rotation);
556
+ this._store.state.selectionGroup.objects.forEach(object => {
557
+ this._store.state.objectsOctree.update(object);
558
+ });
559
+ }
560
+ undo() {
561
+ this._store.state.selectionGroup = this.selectionGroup;
562
+ this._store.state.selectionGroup.rotate(this.rotation - this.initialRotation);
563
+ this._store.state.selectionGroup.objects.forEach(object => {
564
+ this._store.state.objectsOctree.update(object);
565
+ });
566
+ }
567
+ }
568
+
569
+ class KritzelRotationHandler extends KritzelBaseHandler {
570
+ constructor(store) {
571
+ super(store);
572
+ this.initialRotation = 0;
573
+ this.rotation = 0;
574
+ }
575
+ handlePointerDown(event) {
576
+ if (event.pointerType === 'mouse') {
577
+ if (KritzelEventHelper.isLeftClick(event)) {
578
+ if (this._store.state.selectionGroup && this._store.state.isRotationHandleSelected) {
579
+ const clientX = event.clientX - this._store.offsetX;
580
+ const clientY = event.clientY - this._store.offsetY;
581
+ this._store.state.isRotating = true;
582
+ const centerX = this._store.state.selectionGroup.translateX + this._store.state.selectionGroup.width / 2 / this._store.state.scale;
583
+ const centerY = this._store.state.selectionGroup.translateY + this._store.state.selectionGroup.height / 2 / this._store.state.scale;
584
+ const cursorX = (clientX - this._store.state.translateX) / this._store.state.scale;
585
+ const cursorY = (clientY - this._store.state.translateY) / this._store.state.scale;
586
+ this.initialRotation = Math.atan2(centerY - cursorY, centerX - cursorX) - this._store.state.selectionGroup.rotation;
587
+ }
588
+ }
589
+ }
590
+ if (event.pointerType === 'touch') {
591
+ const activePointers = Array.from(this._store.state.pointers.values());
592
+ const firstTouch = activePointers[0];
593
+ if (!firstTouch) {
594
+ return;
595
+ }
596
+ if (activePointers.length === 1) {
597
+ if (this._store.state.selectionGroup && this._store.state.isRotationHandleSelected) {
598
+ const clientX = Math.round(firstTouch.clientX - this._store.offsetX);
599
+ const clientY = Math.round(firstTouch.clientY - this._store.offsetY);
600
+ this._store.state.isRotating = true;
601
+ const centerX = this._store.state.selectionGroup.translateX + this._store.state.selectionGroup.width / 2 / this._store.state.scale;
602
+ const centerY = this._store.state.selectionGroup.translateY + this._store.state.selectionGroup.height / 2 / this._store.state.scale;
603
+ const cursorX = (clientX - this._store.state.translateX) / this._store.state.scale;
604
+ const cursorY = (clientY - this._store.state.translateY) / this._store.state.scale;
605
+ this.initialRotation = Math.atan2(centerY - cursorY, centerX - cursorX) - this._store.state.selectionGroup.rotation;
606
+ clearTimeout(this._store.state.longTouchTimeout);
607
+ }
608
+ }
609
+ }
610
+ }
611
+ handlePointerMove(event) {
612
+ if (event.pointerType === 'mouse') {
613
+ if (this._store.state.isRotating && this._store.state.selectionGroup) {
614
+ const clientX = event.clientX - this._store.offsetX;
615
+ const clientY = event.clientY - this._store.offsetY;
616
+ const groupCenterX = this._store.state.selectionGroup.translateX + this._store.state.selectionGroup.width / 2 / this._store.state.scale;
617
+ const groupCenterY = this._store.state.selectionGroup.translateY + this._store.state.selectionGroup.height / 2 / this._store.state.scale;
618
+ const cursorX = (clientX - this._store.state.translateX) / this._store.state.scale;
619
+ const cursorY = (clientY - this._store.state.translateY) / this._store.state.scale;
620
+ const currentRotation = Math.atan2(groupCenterY - cursorY, groupCenterX - cursorX);
621
+ this.rotation = currentRotation - this.initialRotation;
622
+ this._store.state.selectionGroup.rotate(this.rotation);
623
+ this._store.rerender();
624
+ }
625
+ }
626
+ if (event.pointerType === 'touch') {
627
+ const activePointers = Array.from(this._store.state.pointers.values());
628
+ const firstTouch = activePointers[0];
629
+ if (!firstTouch) {
630
+ return;
631
+ }
632
+ if (this._store.state.isRotating && this._store.state.selectionGroup) {
633
+ const clientX = Math.round(firstTouch.clientX - this._store.offsetX);
634
+ const clientY = Math.round(firstTouch.clientY - this._store.offsetY);
635
+ const groupCenterX = this._store.state.selectionGroup.translateX + this._store.state.selectionGroup.width / 2 / this._store.state.scale;
636
+ const groupCenterY = this._store.state.selectionGroup.translateY + this._store.state.selectionGroup.height / 2 / this._store.state.scale;
637
+ const cursorX = (clientX - this._store.state.translateX) / this._store.state.scale;
638
+ const cursorY = (clientY - this._store.state.translateY) / this._store.state.scale;
639
+ const currentRotation = Math.atan2(groupCenterY - cursorY, groupCenterX - cursorX);
640
+ this.rotation = currentRotation - this.initialRotation;
641
+ this._store.state.selectionGroup.rotate(this.rotation);
642
+ this._store.rerender();
643
+ clearTimeout(this._store.state.longTouchTimeout);
644
+ }
645
+ }
646
+ }
647
+ handlePointerUp(event) {
648
+ if (event.pointerType === 'mouse') {
649
+ if (this._store.state.isRotating) {
650
+ const rotateSelectionGroupCommand = new RotateSelectionGroupCommand(this._store, this, this.rotation);
651
+ const updateObjectsCommand = this._store.state.selectionGroup.objects.map(object => {
652
+ return new UpdateObjectCommand(this._store, this, object, {
653
+ rotation: object.rotation,
654
+ translateX: object.translateX,
655
+ translateY: object.translateY,
656
+ });
657
+ });
658
+ this._store.history.executeCommand(new BatchCommand(this._store, this, [rotateSelectionGroupCommand, ...updateObjectsCommand]));
659
+ this._store.state.isRotating = false;
660
+ this.initialRotation = 0;
661
+ this.rotation = 0;
662
+ }
663
+ }
664
+ if (event.pointerType === 'touch') {
665
+ if (this._store.state.isRotating) {
666
+ const rotateSelectionGroupCommand = new RotateSelectionGroupCommand(this._store, this, this.rotation);
667
+ const updateObjectsCommand = this._store.state.selectionGroup.objects.map(object => {
668
+ return new UpdateObjectCommand(this._store, this, object, {
669
+ rotation: object.rotation,
670
+ });
671
+ });
672
+ this._store.history.executeCommand(new BatchCommand(this._store, this, [rotateSelectionGroupCommand, ...updateObjectsCommand]));
673
+ this._store.state.isRotating = false;
674
+ this.initialRotation = 0;
675
+ this.rotation = 0;
676
+ clearTimeout(this._store.state.longTouchTimeout);
677
+ }
678
+ }
679
+ }
680
+ }
681
+
682
+ class KrtizelSelectionBox extends KritzelBaseObject {
683
+ constructor() {
684
+ super(...arguments);
685
+ this.__class__ = 'KrtizelSelectionBox';
686
+ this.objects = [];
687
+ }
688
+ static create(store) {
689
+ const object = new KrtizelSelectionBox();
690
+ object._store = store;
691
+ object.id = object.generateId();
692
+ object.workspaceId = store.state.activeWorkspace.id;
693
+ object.scale = store.state.scale;
694
+ object.zIndex = 99999;
695
+ object.backgroundColor = 'var(--kritzel-selection-box-background-color, rgba(0, 122, 255, 0.2))';
696
+ object.borderColor = 'var(--kritzel-selection-box-border-color, rgba(0, 122, 255, 0.5))';
697
+ object.borderWidth = 2;
698
+ object.height = 0;
699
+ object.width = 0;
700
+ return object;
701
+ }
702
+ }
703
+
704
+ class AddSelectionGroupCommand extends KritzelBaseCommand {
705
+ constructor(store, initiator, selectionGroup, skipHistory = false) {
706
+ super(store, initiator, skipHistory);
707
+ this.selectionGroup = selectionGroup;
708
+ }
709
+ execute() {
710
+ this._store.state.objectsOctree.remove(object => object instanceof KrtizelSelectionBox);
711
+ this._store.state.objectsOctree.insert(this.selectionGroup);
712
+ this._store.state.selectionGroup = this.selectionGroup;
713
+ this._store.state.selectionBox = null;
714
+ }
715
+ undo() {
716
+ this._store.state.objectsOctree.remove(object => object.id === this.selectionGroup.id);
717
+ this._store.state.selectionGroup = null;
718
+ this._store.state.selectionBox = null;
719
+ }
720
+ }
721
+
722
+ class KritzelSelectionHandler extends KritzelBaseHandler {
723
+ get isSelectionClick() {
724
+ return this._store.state.selectionBox && this._store.state.selectionBox.width === 0 && this._store.state.selectionBox.height === 0;
725
+ }
726
+ get isSelectionDrag() {
727
+ return this._store.state.selectionBox && (this._store.state.selectionBox.width > 0 || this._store.state.selectionBox.height > 0);
728
+ }
729
+ constructor(store) {
730
+ super(store);
731
+ this.touchStartX = 0;
732
+ this.touchStartY = 0;
733
+ this.touchStartTimeout = null;
734
+ }
735
+ handlePointerDown(event) {
736
+ if (event.pointerType === 'mouse') {
737
+ if (KritzelEventHelper.isLeftClick(event) && !this._store.state.selectionGroup) {
738
+ this.startMouseSelection(event);
739
+ }
740
+ }
741
+ if (event.pointerType === 'touch') {
742
+ this.touchStartTimeout = setTimeout(() => {
743
+ if (this._store.state.pointers.size === 1 && !this._store.state.isScaling && !this._store.state.selectionGroup) {
744
+ this.startTouchSelection();
745
+ this.updateTouchSelection();
746
+ }
747
+ }, 80);
748
+ }
749
+ }
750
+ handlePointerMove(event) {
751
+ if (event.pointerType === 'mouse') {
752
+ if (this._store.state.isSelecting) {
753
+ this.updateMouseSelection(event);
754
+ }
755
+ }
756
+ if (event.pointerType === 'touch') {
757
+ const activePointers = Array.from(this._store.state.pointers.values());
758
+ const x = Math.round(activePointers[0].clientX - this._store.offsetX);
759
+ const y = Math.round(activePointers[0].clientY - this._store.offsetY);
760
+ const moveDeltaX = Math.abs(x - this.touchStartX);
761
+ const moveDeltaY = Math.abs(y - this.touchStartY);
762
+ const moveThreshold = 5;
763
+ if ((moveDeltaX > moveThreshold || moveDeltaY > moveThreshold) && this._store.state.isSelecting) {
764
+ this.updateTouchSelection();
765
+ clearTimeout(this._store.state.longTouchTimeout);
766
+ }
767
+ }
768
+ }
769
+ handlePointerUp(event) {
770
+ if (event.pointerType === 'mouse') {
771
+ if (KritzelEventHelper.isLeftClick(event) && this._store.state.isSelecting) {
772
+ if (this.isSelectionClick) {
773
+ const x = this._store.state.pointerX;
774
+ const y = this._store.state.pointerY;
775
+ const selectedObject = this._store.getObjectsFromPointerEvent(event, '.object').find(obj => obj.hitTest(x, y));
776
+ this.addObjectToSelectionGroup(selectedObject);
777
+ this.removeSelectionBox();
778
+ }
779
+ if (this.isSelectionDrag) {
780
+ this.updateMouseSelection(event);
781
+ this.addSelectedObjectsToSelectionGroup();
782
+ this.removeSelectionBox();
783
+ }
784
+ }
785
+ }
786
+ if (event.pointerType === 'touch') {
787
+ clearTimeout(this.touchStartTimeout);
788
+ if (this._store.state.isSelecting) {
789
+ if (this.isSelectionClick) {
790
+ const x = this._store.state.pointerX;
791
+ const y = this._store.state.pointerY;
792
+ const selectedObject = this._store.getObjectsFromPointerEvent(event, '.object').find(obj => obj.hitTest(x, y));
793
+ this.addObjectToSelectionGroup(selectedObject);
794
+ this.removeSelectionBox();
795
+ }
796
+ if (this.isSelectionDrag) {
797
+ this.updateTouchSelection();
798
+ this.addSelectedObjectsToSelectionGroup();
799
+ this.removeSelectionBox();
800
+ }
801
+ this._store.state.skipContextMenu = false;
802
+ }
803
+ }
804
+ }
805
+ removeSelectionBox() {
806
+ this._store.state.selectionBox = null;
807
+ this._store.state.isSelecting = false;
808
+ this._store.state.objectsOctree.remove(o => o instanceof KrtizelSelectionBox);
809
+ this._store.rerender();
810
+ }
811
+ startMouseSelection(event) {
812
+ let clientX, clientY;
813
+ clientX = event.clientX - this._store.offsetX;
814
+ clientY = event.clientY - this._store.offsetY;
815
+ const selectionBox = KrtizelSelectionBox.create(this._store);
816
+ this.startX = (clientX - this._store.state.translateX) / this._store.state.scale;
817
+ this.startY = (clientY - this._store.state.translateY) / this._store.state.scale;
818
+ selectionBox.translateX = this.startX;
819
+ selectionBox.translateY = this.startY;
820
+ this._store.state.selectionGroup = null;
821
+ this._store.state.selectionBox = selectionBox;
822
+ this._store.state.isSelecting = true;
823
+ this._store.state.objectsOctree.remove(o => o instanceof KrtizelSelectionBox || o instanceof KritzelSelectionGroup);
824
+ this._store.state.objectsOctree.insert(selectionBox);
825
+ }
826
+ startTouchSelection() {
827
+ const activePointers = Array.from(this._store.state.pointers.values());
828
+ const firstTouch = activePointers[0];
829
+ if (!firstTouch) {
830
+ return;
831
+ }
832
+ let clientX, clientY;
833
+ clientX = Math.round(firstTouch.clientX - this._store.offsetX);
834
+ clientY = Math.round(firstTouch.clientY - this._store.offsetY);
835
+ this.touchStartX = clientX;
836
+ this.touchStartY = clientY;
837
+ const selectionBox = KrtizelSelectionBox.create(this._store);
838
+ this.startX = (clientX - this._store.state.translateX) / this._store.state.scale;
839
+ this.startY = (clientY - this._store.state.translateY) / this._store.state.scale;
840
+ selectionBox.translateX = this.startX;
841
+ selectionBox.translateY = this.startY;
842
+ this._store.state.selectionGroup = null;
843
+ this._store.state.selectionBox = selectionBox;
844
+ this._store.state.isSelecting = true;
845
+ this._store.state.objectsOctree.remove(o => o instanceof KrtizelSelectionBox || o instanceof KritzelSelectionGroup);
846
+ this._store.state.objectsOctree.insert(selectionBox);
847
+ }
848
+ updateMouseSelection(event) {
849
+ let clientX, clientY;
850
+ clientX = event.clientX - this._store.offsetX;
851
+ clientY = event.clientY - this._store.offsetY;
852
+ const selectionBox = this._store.state.selectionBox;
853
+ if (selectionBox) {
854
+ const currentX = (clientX - this._store.state.translateX) / selectionBox.scale;
855
+ const currentY = (clientY - this._store.state.translateY) / selectionBox.scale;
856
+ selectionBox.width = Math.abs(currentX - this.startX) * selectionBox.scale;
857
+ selectionBox.height = Math.abs(currentY - this.startY) * selectionBox.scale;
858
+ selectionBox.translateX = Math.min(currentX, this.startX);
859
+ selectionBox.translateY = Math.min(currentY, this.startY);
860
+ this.updateSelectedObjects();
861
+ this._store.rerender();
862
+ }
863
+ }
864
+ updateTouchSelection() {
865
+ const activePointers = Array.from(this._store.state.pointers.values());
866
+ const firstTouch = activePointers[0];
867
+ if (!firstTouch) {
868
+ return;
869
+ }
870
+ let clientX, clientY;
871
+ clientX = Math.round(firstTouch.clientX - this._store.offsetX);
872
+ clientY = Math.round(firstTouch.clientY - this._store.offsetY);
873
+ const selectionBox = this._store.state.selectionBox;
874
+ if (selectionBox) {
875
+ const currentX = (clientX - this._store.state.translateX) / selectionBox.scale;
876
+ const currentY = (clientY - this._store.state.translateY) / selectionBox.scale;
877
+ selectionBox.width = Math.abs(currentX - this.startX) * selectionBox.scale;
878
+ selectionBox.height = Math.abs(currentY - this.startY) * selectionBox.scale;
879
+ selectionBox.translateX = Math.min(currentX, this.startX);
880
+ selectionBox.translateY = Math.min(currentY, this.startY);
881
+ this.updateSelectedObjects();
882
+ }
883
+ }
884
+ updateSelectedObjects() {
885
+ this._store.allObjects
886
+ .filter(o => !(o instanceof KrtizelSelectionBox))
887
+ .forEach(object => (object.isSelected = object.hitTestPolygon(this._store.state.selectionBox.rotatedPolygon)));
888
+ }
889
+ addObjectToSelectionGroup(object) {
890
+ if (!object) {
891
+ return;
892
+ }
893
+ this._store.state.selectionGroup = KritzelSelectionGroup.create(this._store);
894
+ this._store.state.selectionGroup.addOrRemove(object);
895
+ this._store.state.selectionGroup.isSelected = true;
896
+ this._store.state.selectionGroup.rotation = object.rotation;
897
+ this._store.history.executeCommand(new AddSelectionGroupCommand(this._store, this, this._store.state.selectionGroup));
898
+ }
899
+ addSelectedObjectsToSelectionGroup() {
900
+ const selectedObjects = this._store.selectedObjects;
901
+ if (selectedObjects.length === 0) {
902
+ return;
903
+ }
904
+ this._store.state.selectionGroup = KritzelSelectionGroup.create(this._store);
905
+ selectedObjects.forEach(o => {
906
+ o.isSelected = false;
907
+ this._store.state.selectionGroup.addOrRemove(o);
908
+ });
909
+ this._store.state.selectionGroup.isSelected = true;
910
+ if (this._store.state.selectionGroup.length === 1) {
911
+ this._store.state.selectionGroup.rotation = this._store.state.selectionGroup.objects[0].rotation;
912
+ }
913
+ this._store.history.executeCommand(new AddSelectionGroupCommand(this._store, this, this._store.state.selectionGroup));
914
+ }
915
+ }
916
+
917
+ class KritzelHoverHandler extends KritzelBaseHandler {
918
+ constructor(store) {
919
+ super(store);
920
+ }
921
+ handlePointerMove(event) {
922
+ if (event.pointerType === 'mouse') {
923
+ const hoveredObject = this._store.getObjectFromPointerEvent(event, '.object');
924
+ if (!hoveredObject)
925
+ return;
926
+ const x = this._store.state.pointerX;
927
+ const y = this._store.state.pointerY;
928
+ hoveredObject.isHovered = hoveredObject.hitTest(x, y);
929
+ }
930
+ }
931
+ }
932
+
933
+ class KritzelSelectionTool extends KritzelBaseTool {
934
+ constructor(store) {
935
+ super(store);
936
+ this.selectionHandler = new KritzelSelectionHandler(this._store);
937
+ this.moveHandler = new KritzelMoveHandler(this._store);
938
+ this.hoverHandler = new KritzelHoverHandler(this._store);
939
+ this.resizeHandler = new KritzelResizeHandler(this._store);
940
+ this.rotationHandler = new KritzelRotationHandler(this._store);
941
+ }
942
+ handlePointerDown(event) {
943
+ if (event.cancelable) {
944
+ event.preventDefault();
945
+ }
946
+ if (event.pointerType === 'mouse') {
947
+ if (KritzelEventHelper.isLeftClick(event)) {
948
+ this._store.state.isResizeHandleSelected = this.isHandleSelected(event);
949
+ this._store.state.isRotationHandleSelected = this.isRotationHandleSelected(event);
950
+ this._store.state.resizeHandleType = this.getHandleType(event);
951
+ const selectedObject = this.getSelectedObject(event);
952
+ const isDifferentObject = selectedObject && this._store.state.selectionGroup && selectedObject.id !== this._store.state.selectionGroup.id;
953
+ if ((selectedObject === null || isDifferentObject) &&
954
+ this._store.state.selectionGroup &&
955
+ !this._store.state.isResizeHandleSelected &&
956
+ !this._store.state.isRotationHandleSelected) {
957
+ this._store.history.executeCommand(new RemoveSelectionGroupCommand(this._store, this._store.state.selectionGroup));
958
+ }
959
+ if (selectedObject && selectedObject.isSelected === false && (selectedObject === null || selectedObject === void 0 ? void 0 : selectedObject.objects.length) === 1 && selectedObject.objects[0].isInteractive) {
960
+ return;
961
+ }
962
+ }
963
+ this.moveHandler.handlePointerDown(event);
964
+ this.selectionHandler.handlePointerDown(event);
965
+ this.resizeHandler.handlePointerDown(event);
966
+ this.rotationHandler.handlePointerDown(event);
967
+ this._store.rerender();
968
+ }
969
+ if (event.pointerType === 'touch') {
970
+ if (this._store.state.isScaling === true) {
971
+ return;
972
+ }
973
+ if (this._store.state.pointers.size === 1) {
974
+ this._store.state.isResizeHandleSelected = this.isHandleSelected(event);
975
+ this._store.state.isRotationHandleSelected = this.isRotationHandleSelected(event);
976
+ this._store.state.resizeHandleType = this.getHandleType(event);
977
+ const selectedObject = this.getSelectedObject(event);
978
+ const isDifferentObject = selectedObject && this._store.state.selectionGroup && selectedObject.id !== this._store.state.selectionGroup.id;
979
+ if (!this._store.state.selectionGroup && selectedObject) {
980
+ this._store.state.skipContextMenu = true;
981
+ }
982
+ if ((selectedObject === null || isDifferentObject) &&
983
+ this._store.state.selectionGroup &&
984
+ !this._store.state.isResizeHandleSelected &&
985
+ !this._store.state.isRotationHandleSelected) {
986
+ this._store.history.executeCommand(new RemoveSelectionGroupCommand(this._store, this._store.state.selectionGroup));
987
+ }
988
+ }
989
+ this.rotationHandler.handlePointerDown(event);
990
+ this.resizeHandler.handlePointerDown(event);
991
+ this.moveHandler.handlePointerDown(event);
992
+ this.selectionHandler.handlePointerDown(event);
993
+ }
994
+ }
995
+ handlePointerMove(event) {
996
+ if (event.cancelable) {
997
+ event.preventDefault();
998
+ }
999
+ if (event.pointerType === 'mouse') {
1000
+ this.moveHandler.handlePointerMove(event);
1001
+ this.hoverHandler.handlePointerMove(event);
1002
+ this.selectionHandler.handlePointerMove(event);
1003
+ this.resizeHandler.handlePointerMove(event);
1004
+ this.rotationHandler.handlePointerMove(event);
1005
+ this._store.rerender();
1006
+ }
1007
+ if (event.pointerType === 'touch') {
1008
+ if (this._store.state.isScaling === true) {
1009
+ return;
1010
+ }
1011
+ this.rotationHandler.handlePointerMove(event);
1012
+ this.resizeHandler.handlePointerMove(event);
1013
+ this.moveHandler.handlePointerMove(event);
1014
+ this.selectionHandler.handlePointerMove(event);
1015
+ this._store.rerender();
1016
+ }
1017
+ }
1018
+ handlePointerUp(event) {
1019
+ if (event.cancelable) {
1020
+ event.preventDefault();
1021
+ }
1022
+ if (event.pointerType === 'mouse') {
1023
+ this.moveHandler.handlePointerUp(event);
1024
+ this.selectionHandler.handlePointerUp(event);
1025
+ this.resizeHandler.handlePointerUp(event);
1026
+ this.rotationHandler.handlePointerUp(event);
1027
+ this._store.rerender();
1028
+ }
1029
+ if (event.pointerType === 'touch') {
1030
+ if (this._store.state.isScaling === true) {
1031
+ return;
1032
+ }
1033
+ this.rotationHandler.handlePointerUp(event);
1034
+ this.resizeHandler.handlePointerUp(event);
1035
+ this.moveHandler.handlePointerUp(event);
1036
+ this.selectionHandler.handlePointerUp(event);
1037
+ }
1038
+ }
1039
+ getSelectedObject(event) {
1040
+ const path = event.composedPath().slice(1);
1041
+ const objectElement = path.find(element => element.classList && element.classList.contains('object'));
1042
+ const object = this._store.findObjectById(objectElement === null || objectElement === void 0 ? void 0 : objectElement.id);
1043
+ if (!object) {
1044
+ return null;
1045
+ }
1046
+ if (object instanceof KritzelSelectionGroup) {
1047
+ return object;
1048
+ }
1049
+ else {
1050
+ const group = KritzelSelectionGroup.create(this._store);
1051
+ group.translateX = 0;
1052
+ group.translateY = 0;
1053
+ group.addOrRemove(object);
1054
+ return group;
1055
+ }
1056
+ }
1057
+ getHandleType(event) {
1058
+ var _a;
1059
+ const shadowRoot = (_a = this._store.state.host) === null || _a === void 0 ? void 0 : _a.shadowRoot;
1060
+ if (!shadowRoot)
1061
+ return;
1062
+ const elementAtPoint = shadowRoot.elementFromPoint(event.clientX, event.clientY);
1063
+ const handle = elementAtPoint === null || elementAtPoint === void 0 ? void 0 : elementAtPoint.closest('.resize-handle-overlay');
1064
+ return handle === null || handle === void 0 ? void 0 : handle.classList[1];
1065
+ }
1066
+ isHandleSelected(event) {
1067
+ var _a;
1068
+ const shadowRoot = (_a = this._store.state.host) === null || _a === void 0 ? void 0 : _a.shadowRoot;
1069
+ if (!shadowRoot)
1070
+ return false;
1071
+ const elementAtPoint = shadowRoot.elementFromPoint(event.clientX, event.clientY);
1072
+ return !!(elementAtPoint === null || elementAtPoint === void 0 ? void 0 : elementAtPoint.classList.contains('resize-handle-overlay'));
1073
+ }
1074
+ isRotationHandleSelected(event) {
1075
+ const path = event.composedPath();
1076
+ return !!path.find(element => element.classList && element.classList.contains('rotation-handle-overlay'));
1077
+ }
1078
+ }
1079
+
1080
+ class KritzelReviver {
1081
+ constructor(store) {
1082
+ this._store = store;
1083
+ }
1084
+ revive(obj) {
1085
+ if (obj && typeof obj === 'object') {
1086
+ if (obj.__class__) {
1087
+ let revivedObj;
1088
+ switch (obj.__class__) {
1089
+ case 'KritzelPath':
1090
+ revivedObj = KritzelPath.create(this._store).revive(obj);
1091
+ break;
1092
+ case 'KritzelText':
1093
+ revivedObj = KritzelText.create(this._store, obj.fontSize, obj.fontFamily).revive(obj);
1094
+ break;
1095
+ case 'KritzelImage':
1096
+ revivedObj = KritzelImage.create(this._store).revive(obj);
1097
+ break;
1098
+ case 'KritzelCustomElement':
1099
+ revivedObj = KritzelCustomElement.create(this._store).revive(obj);
1100
+ break;
1101
+ case 'KritzelSelectionGroup':
1102
+ revivedObj = KritzelSelectionGroup.create(this._store).revive(obj);
1103
+ break;
1104
+ case 'KritzelBrushTool':
1105
+ revivedObj = new KritzelBrushTool(this._store);
1106
+ break;
1107
+ case 'KritzelEraserTool':
1108
+ revivedObj = new KritzelEraserTool(this._store);
1109
+ break;
1110
+ case 'KritzelImageTool':
1111
+ revivedObj = new KritzelImageTool(this._store);
1112
+ break;
1113
+ case 'KritzelSelectionTool':
1114
+ revivedObj = new KritzelSelectionTool(this._store);
1115
+ break;
1116
+ case 'KritzelTextTool':
1117
+ revivedObj = new KritzelTextTool(this._store);
1118
+ break;
1119
+ default:
1120
+ revivedObj = obj;
1121
+ }
1122
+ return revivedObj;
1123
+ }
1124
+ const newObj = Array.isArray(obj) ? [] : {};
1125
+ for (const key in obj) {
1126
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
1127
+ newObj[key] = this.revive(obj[key]);
1128
+ }
1129
+ }
1130
+ return newObj;
1131
+ }
1132
+ return obj;
1133
+ }
1134
+ }
1135
+
1136
+ class KritzelSelectionGroup extends KritzelBaseObject {
1137
+ constructor() {
1138
+ super(...arguments);
1139
+ this.__class__ = 'KritzelSelectionGroup';
1140
+ this.objects = [];
1141
+ this.unchangedObjects = [];
1142
+ }
1143
+ get length() {
1144
+ return this.objects.length;
1145
+ }
1146
+ static create(store) {
1147
+ const object = new KritzelSelectionGroup();
1148
+ object._store = store;
1149
+ object.id = object.generateId();
1150
+ object.workspaceId = store.state.activeWorkspace.id;
1151
+ object.scale = store.state.scale;
1152
+ object.zIndex = 99999;
1153
+ return object;
1154
+ }
1155
+ addOrRemove(object) {
1156
+ const index = this.objects.findIndex(obj => obj.id === object.id);
1157
+ if (index === -1) {
1158
+ this.objects.push(object);
1159
+ }
1160
+ else {
1161
+ this.objects.splice(index, 1);
1162
+ }
1163
+ this.unchangedObjects = ObjectHelper.clone(this.objects);
1164
+ this.refreshObjectDimensions();
1165
+ }
1166
+ deselectAllChildren() {
1167
+ this.objects.forEach(obj => (obj.isSelected = false));
1168
+ }
1169
+ updatePosition(x, y) {
1170
+ this.objects.forEach(obj => {
1171
+ const deltaX = obj.translateX - this.translateX;
1172
+ const deltaY = obj.translateY - this.translateY;
1173
+ obj.updatePosition(x + deltaX, y + deltaY);
1174
+ });
1175
+ this.unchangedObjects.forEach(obj => {
1176
+ const deltaX = obj.translateX - this.translateX;
1177
+ const deltaY = obj.translateY - this.translateY;
1178
+ obj.translateX = x + deltaX;
1179
+ obj.translateY = y + deltaY;
1180
+ });
1181
+ this.translateX = x;
1182
+ this.translateY = y;
1183
+ this._store.state.objectsOctree.update(this);
1184
+ }
1185
+ move(startX, startY, endX, endY) {
1186
+ const deltaX = (startX - endX) / this._store.state.scale;
1187
+ const deltaY = (startY - endY) / this._store.state.scale;
1188
+ this.translateX += deltaX;
1189
+ this.translateY += deltaY;
1190
+ this._store.state.objectsOctree.update(this);
1191
+ this.objects.forEach(obj => {
1192
+ obj.move(startX, startY, endX, endY);
1193
+ this._store.state.objectsOctree.update(obj);
1194
+ });
1195
+ this.unchangedObjects.forEach(obj => {
1196
+ obj.translateX += deltaX;
1197
+ obj.translateY += deltaY;
1198
+ });
1199
+ }
1200
+ resize(x, y, width, height) {
1201
+ const widthScaleFactor = width / this.width;
1202
+ const heightScaleFactor = height / this.height;
1203
+ const deltaX = x - this.translateX;
1204
+ const deltaY = y - this.translateY;
1205
+ this.objects.forEach(child => {
1206
+ const updatedWidth = child.width * widthScaleFactor;
1207
+ const updatedHeight = child.height * heightScaleFactor;
1208
+ const updatedX = child.translateX + deltaX + (child.translateX - this.translateX) * (widthScaleFactor - 1);
1209
+ const updatedY = child.translateY + deltaY + (child.translateY - this.translateY) * (heightScaleFactor - 1);
1210
+ child.resize(updatedX, updatedY, updatedWidth, updatedHeight);
1211
+ this._store.state.objectsOctree.update(child);
1212
+ });
1213
+ this.refreshObjectDimensions();
1214
+ this.unchangedObjects = ObjectHelper.clone(this.objects);
1215
+ }
1216
+ rotate(value) {
1217
+ this.rotation = value;
1218
+ const centerX = this.translateX + this.totalWidth / 2 / this.scale;
1219
+ const centerY = this.translateY + this.totalHeight / 2 / this.scale;
1220
+ const angle = value;
1221
+ const cos = Math.cos(angle);
1222
+ const sin = Math.sin(angle);
1223
+ this.objects.forEach(child => {
1224
+ const unchangedChild = this.getUnchangedObject(child.id);
1225
+ const offsetX = this.getOffsetXToCenter(unchangedChild);
1226
+ const offsetY = this.getOffsetYToCenter(unchangedChild);
1227
+ const rotatedX = cos * offsetX - sin * offsetY;
1228
+ const rotatedY = sin * offsetX + cos * offsetY;
1229
+ child.translateX = centerX + rotatedX - child.totalWidth / 2 / child.scale;
1230
+ child.translateY = centerY + rotatedY - child.totalHeight / 2 / child.scale;
1231
+ child.rotate(this.objects.length === 1 ? value : value + unchangedChild.rotation);
1232
+ this._store.state.objectsOctree.update(child);
1233
+ });
1234
+ }
1235
+ copy() {
1236
+ const selectionGroup = KritzelSelectionGroup.create(this._store);
1237
+ let currentZIndex = this._store.currentZIndex;
1238
+ this.objects.sort((a, b) => a.zIndex - b.zIndex).forEach(obj => {
1239
+ const copiedObject = obj.copy();
1240
+ copiedObject.zIndex = currentZIndex;
1241
+ selectionGroup.addOrRemove(copiedObject);
1242
+ currentZIndex++;
1243
+ });
1244
+ selectionGroup.unchangedObjects = ObjectHelper.clone(selectionGroup.objects);
1245
+ if (this.objects.length === 1) {
1246
+ selectionGroup.rotation = this.objects[0].rotation;
1247
+ }
1248
+ return selectionGroup;
1249
+ }
1250
+ refreshObjectDimensions() {
1251
+ if (this.objects.length === 1) {
1252
+ const obj = this.objects[0];
1253
+ this.minX = obj.boundingBox.x / this.scale;
1254
+ this.maxX = obj.boundingBox.x / this.scale + obj.boundingBox.width;
1255
+ this.minY = obj.boundingBox.y / this.scale;
1256
+ this.maxY = obj.boundingBox.y / this.scale + obj.boundingBox.height;
1257
+ this.translateX = (this.minX - this.padding) * this.scale;
1258
+ this.translateY = (this.minY - this.padding) * this.scale;
1259
+ this.width = (this.maxX - this.minX - this.padding) * this.scale;
1260
+ this.height = (this.maxY - this.minY - this.padding) * this.scale;
1261
+ }
1262
+ else {
1263
+ this.minX = Math.min(...this.objects.map(obj => obj.minXRotated));
1264
+ this.maxX = Math.max(...this.objects.map(obj => obj.maxXRotated));
1265
+ this.minY = Math.min(...this.objects.map(obj => obj.minYRotated));
1266
+ this.maxY = Math.max(...this.objects.map(obj => obj.maxYRotated));
1267
+ this.translateX = this.minX - this.padding;
1268
+ this.translateY = this.minY - this.padding;
1269
+ this.width = (this.maxX - this.minX - this.padding) * this.scale;
1270
+ this.height = (this.maxY - this.minY - this.padding) * this.scale;
1271
+ }
1272
+ this._store.state.objectsOctree.update(this);
1273
+ }
1274
+ getOffsetXToCenter(obj) {
1275
+ const objCenterX = obj.translateX + obj.totalWidth / obj.scale / 2;
1276
+ const groupCenterX = this.translateX + this.totalWidth / this.scale / 2;
1277
+ return objCenterX - groupCenterX;
1278
+ }
1279
+ getOffsetYToCenter(obj) {
1280
+ const objCenterY = obj.translateY + obj.totalHeight / obj.scale / 2;
1281
+ const groupCenterY = this.translateY + this.totalHeight / this.scale / 2;
1282
+ return objCenterY - groupCenterY;
1283
+ }
1284
+ getUnchangedObject(objectId) {
1285
+ const obj = this.unchangedObjects.find(obj => obj.id === objectId);
1286
+ const reviver = new KritzelReviver(this._store);
1287
+ return reviver.revive(obj);
1288
+ }
1289
+ }
1290
+
1291
+ /**
1292
+ * Browser Image Compression
1293
+ * v2.0.2
1294
+ * by Donald <donaldcwl@gmail.com>
1295
+ * https://github.com/Donaldcwl/browser-image-compression
1296
+ */
1297
+
1298
+ function _mergeNamespaces(e,t){return t.forEach((function(t){t&&"string"!=typeof t&&!Array.isArray(t)&&Object.keys(t).forEach((function(r){if("default"!==r&&!(r in e)){var i=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,i.get?i:{enumerable:true,get:function(){return t[r]}});}}));})),Object.freeze(e)}function copyExifWithoutOrientation(e,t){return new Promise((function(r,i){let o;return getApp1Segment(e).then((function(e){try{return o=e,r(new Blob([t.slice(0,2),o,t.slice(2)],{type:"image/jpeg"}))}catch(e){return i(e)}}),i)}))}const getApp1Segment=e=>new Promise(((t,r)=>{const i=new FileReader;i.addEventListener("load",(({target:{result:e}})=>{const i=new DataView(e);let o=0;if(65496!==i.getUint16(o))return r("not a valid JPEG");for(o+=2;;){const a=i.getUint16(o);if(65498===a)break;const s=i.getUint16(o+2);if(65505===a&&1165519206===i.getUint32(o+4)){const a=o+10;let f;switch(i.getUint16(a)){case 18761:f=true;break;case 19789:f=false;break;default:return r("TIFF header contains invalid endian")}if(42!==i.getUint16(a+2,f))return r("TIFF header contains invalid version");const l=i.getUint32(a+4,f),c=a+l+2+12*i.getUint16(a+l,f);for(let e=a+l+2;e<c;e+=12){if(274==i.getUint16(e,f)){if(3!==i.getUint16(e+2,f))return r("Orientation data type is invalid");if(1!==i.getUint32(e+4,f))return r("Orientation data count is invalid");i.setUint16(e+8,1,f);break}}return t(e.slice(o,o+2+s))}o+=2+s;}return t(new Blob)})),i.readAsArrayBuffer(e);}));var e={},t={get exports(){return e},set exports(t){e=t;}};!function(e){var r,i,UZIP={};t.exports=UZIP,UZIP.parse=function(e,t){for(var r=UZIP.bin.readUshort,i=UZIP.bin.readUint,o=0,a={},s=new Uint8Array(e),f=s.length-4;101010256!=i(s,f);)f--;o=f;o+=4;var l=r(s,o+=4);r(s,o+=2);var c=i(s,o+=2),u=i(s,o+=4);o+=4,o=u;for(var h=0;h<l;h++){i(s,o),o+=4,o+=4,o+=4,i(s,o+=4);c=i(s,o+=4);var d=i(s,o+=4),A=r(s,o+=4),g=r(s,o+2),p=r(s,o+4);o+=6;var m=i(s,o+=8);o+=4,o+=A+g+p,UZIP._readLocal(s,m,a,c,d,t);}return a},UZIP._readLocal=function(e,t,r,i,o,a){var s=UZIP.bin.readUshort,f=UZIP.bin.readUint;f(e,t),s(e,t+=4),s(e,t+=2);var l=s(e,t+=2);f(e,t+=2),f(e,t+=4),t+=4;var c=s(e,t+=8),u=s(e,t+=2);t+=2;var h=UZIP.bin.readUTF8(e,t,c);if(t+=c,t+=u,a)r[h]={size:o,csize:i};else {var d=new Uint8Array(e.buffer,t);if(0==l)r[h]=new Uint8Array(d.buffer.slice(t,t+i));else {if(8!=l)throw "unknown compression method: "+l;var A=new Uint8Array(o);UZIP.inflateRaw(d,A),r[h]=A;}}},UZIP.inflateRaw=function(e,t){return UZIP.F.inflate(e,t)},UZIP.inflate=function(e,t){return UZIP.inflateRaw(new Uint8Array(e.buffer,e.byteOffset+2,e.length-6),t)},UZIP.deflate=function(e,t){null==t&&(t={level:6});var r=0,i=new Uint8Array(50+Math.floor(1.1*e.length));i[r]=120,i[r+1]=156,r+=2,r=UZIP.F.deflateRaw(e,i,r,t.level);var o=UZIP.adler(e,0,e.length);return i[r+0]=o>>>24&255,i[r+1]=o>>>16&255,i[r+2]=o>>>8&255,i[r+3]=o>>>0&255,new Uint8Array(i.buffer,0,r+4)},UZIP.deflateRaw=function(e,t){null==t&&(t={level:6});var r=new Uint8Array(50+Math.floor(1.1*e.length)),i=UZIP.F.deflateRaw(e,r,i,t.level);return new Uint8Array(r.buffer,0,i)},UZIP.encode=function(e,t){null==t&&(t=false);var r=0,i=UZIP.bin.writeUint,o=UZIP.bin.writeUshort,a={};for(var s in e){var f=!UZIP._noNeed(s)&&!t,l=e[s],c=UZIP.crc.crc(l,0,l.length);a[s]={cpr:f,usize:l.length,crc:c,file:f?UZIP.deflateRaw(l):l};}for(var s in a)r+=a[s].file.length+30+46+2*UZIP.bin.sizeUTF8(s);r+=22;var u=new Uint8Array(r),h=0,d=[];for(var s in a){var A=a[s];d.push(h),h=UZIP._writeHeader(u,h,s,A,0);}var g=0,p=h;for(var s in a){A=a[s];d.push(h),h=UZIP._writeHeader(u,h,s,A,1,d[g++]);}var m=h-p;return i(u,h,101010256),h+=4,o(u,h+=4,g),o(u,h+=2,g),i(u,h+=2,m),i(u,h+=4,p),h+=4,h+=2,u.buffer},UZIP._noNeed=function(e){var t=e.split(".").pop().toLowerCase();return -1!="png,jpg,jpeg,zip".indexOf(t)},UZIP._writeHeader=function(e,t,r,i,o,a){var s=UZIP.bin.writeUint,f=UZIP.bin.writeUshort,l=i.file;return s(e,t,0==o?67324752:33639248),t+=4,1==o&&(t+=2),f(e,t,20),f(e,t+=2,0),f(e,t+=2,i.cpr?8:0),s(e,t+=2,0),s(e,t+=4,i.crc),s(e,t+=4,l.length),s(e,t+=4,i.usize),f(e,t+=4,UZIP.bin.sizeUTF8(r)),f(e,t+=2,0),t+=2,1==o&&(t+=2,t+=2,s(e,t+=6,a),t+=4),t+=UZIP.bin.writeUTF8(e,t,r),0==o&&(e.set(l,t),t+=l.length),t},UZIP.crc={table:function(){for(var e=new Uint32Array(256),t=0;t<256;t++){for(var r=t,i=0;i<8;i++)1&r?r=3988292384^r>>>1:r>>>=1;e[t]=r;}return e}(),update:function(e,t,r,i){for(var o=0;o<i;o++)e=UZIP.crc.table[255&(e^t[r+o])]^e>>>8;return e},crc:function(e,t,r){return 4294967295^UZIP.crc.update(4294967295,e,t,r)}},UZIP.adler=function(e,t,r){for(var i=1,o=0,a=t,s=t+r;a<s;){for(var f=Math.min(a+5552,s);a<f;)o+=i+=e[a++];i%=65521,o%=65521;}return o<<16|i},UZIP.bin={readUshort:function(e,t){return e[t]|e[t+1]<<8},writeUshort:function(e,t,r){e[t]=255&r,e[t+1]=r>>8&255;},readUint:function(e,t){return 16777216*e[t+3]+(e[t+2]<<16|e[t+1]<<8|e[t])},writeUint:function(e,t,r){e[t]=255&r,e[t+1]=r>>8&255,e[t+2]=r>>16&255,e[t+3]=r>>24&255;},readASCII:function(e,t,r){for(var i="",o=0;o<r;o++)i+=String.fromCharCode(e[t+o]);return i},writeASCII:function(e,t,r){for(var i=0;i<r.length;i++)e[t+i]=r.charCodeAt(i);},pad:function(e){return e.length<2?"0"+e:e},readUTF8:function(e,t,r){for(var i,o="",a=0;a<r;a++)o+="%"+UZIP.bin.pad(e[t+a].toString(16));try{i=decodeURIComponent(o);}catch(i){return UZIP.bin.readASCII(e,t,r)}return i},writeUTF8:function(e,t,r){for(var i=r.length,o=0,a=0;a<i;a++){var s=r.charCodeAt(a);if(0==(4294967168&s))e[t+o]=s,o++;else if(0==(4294965248&s))e[t+o]=192|s>>6,e[t+o+1]=128|s>>0&63,o+=2;else if(0==(4294901760&s))e[t+o]=224|s>>12,e[t+o+1]=128|s>>6&63,e[t+o+2]=128|s>>0&63,o+=3;else {if(0!=(4292870144&s))throw "e";e[t+o]=240|s>>18,e[t+o+1]=128|s>>12&63,e[t+o+2]=128|s>>6&63,e[t+o+3]=128|s>>0&63,o+=4;}}return o},sizeUTF8:function(e){for(var t=e.length,r=0,i=0;i<t;i++){var o=e.charCodeAt(i);if(0==(4294967168&o))r++;else if(0==(4294965248&o))r+=2;else if(0==(4294901760&o))r+=3;else {if(0!=(4292870144&o))throw "e";r+=4;}}return r}},UZIP.F={},UZIP.F.deflateRaw=function(e,t,r,i){var o=[[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]][i],a=UZIP.F.U,s=UZIP.F._goodIndex;var f=UZIP.F._putsE,l=0,c=r<<3,u=0,h=e.length;if(0==i){for(;l<h;){f(t,c,l+(_=Math.min(65535,h-l))==h?1:0),c=UZIP.F._copyExact(e,l,_,t,c+8),l+=_;}return c>>>3}var d=a.lits,A=a.strt,g=a.prev,p=0,m=0,w=0,v=0,b=0,y=0;for(h>2&&(A[y=UZIP.F._hash(e,0)]=0),l=0;l<h;l++){if(b=y,l+1<h-2){y=UZIP.F._hash(e,l+1);var E=l+1&32767;g[E]=A[y],A[y]=E;}if(u<=l){(p>14e3||m>26697)&&h-l>100&&(u<l&&(d[p]=l-u,p+=2,u=l),c=UZIP.F._writeBlock(l==h-1||u==h?1:0,d,p,v,e,w,l-w,t,c),p=m=v=0,w=l);var F=0;l<h-2&&(F=UZIP.F._bestMatch(e,l,g,b,Math.min(o[2],h-l),o[3]));var _=F>>>16,B=65535&F;if(0!=F){B=65535&F;var U=s(_=F>>>16,a.of0);a.lhst[257+U]++;var C=s(B,a.df0);a.dhst[C]++,v+=a.exb[U]+a.dxb[C],d[p]=_<<23|l-u,d[p+1]=B<<16|U<<8|C,p+=2,u=l+_;}else a.lhst[e[l]]++;m++;}}for(w==l&&0!=e.length||(u<l&&(d[p]=l-u,p+=2,u=l),c=UZIP.F._writeBlock(1,d,p,v,e,w,l-w,t,c),p=0,m=0,p=m=v=0,w=l);0!=(7&c);)c++;return c>>>3},UZIP.F._bestMatch=function(e,t,r,i,o,a){var s=32767&t,f=r[s],l=s-f+32768&32767;if(f==s||i!=UZIP.F._hash(e,t-l))return 0;for(var c=0,u=0,h=Math.min(32767,t);l<=h&&0!=--a&&f!=s;){if(0==c||e[t+c]==e[t+c-l]){var d=UZIP.F._howLong(e,t,l);if(d>c){if(u=l,(c=d)>=o)break;l+2<d&&(d=l+2);for(var A=0,g=0;g<d-2;g++){var p=t-l+g+32768&32767,m=p-r[p]+32768&32767;m>A&&(A=m,f=p);}}}l+=(s=f)-(f=r[s])+32768&32767;}return c<<16|u},UZIP.F._howLong=function(e,t,r){if(e[t]!=e[t-r]||e[t+1]!=e[t+1-r]||e[t+2]!=e[t+2-r])return 0;var i=t,o=Math.min(e.length,t+258);for(t+=3;t<o&&e[t]==e[t-r];)t++;return t-i},UZIP.F._hash=function(e,t){return (e[t]<<8|e[t+1])+(e[t+2]<<4)&65535},UZIP.saved=0,UZIP.F._writeBlock=function(e,t,r,i,o,a,s,f,l){var c,u,h,d,A,g,p,m,w,v=UZIP.F.U,b=UZIP.F._putsF,y=UZIP.F._putsE;v.lhst[256]++,u=(c=UZIP.F.getTrees())[0],h=c[1],d=c[2],A=c[3],g=c[4],p=c[5],m=c[6],w=c[7];var E=32+(0==(l+3&7)?0:8-(l+3&7))+(s<<3),F=i+UZIP.F.contSize(v.fltree,v.lhst)+UZIP.F.contSize(v.fdtree,v.dhst),_=i+UZIP.F.contSize(v.ltree,v.lhst)+UZIP.F.contSize(v.dtree,v.dhst);_+=14+3*p+UZIP.F.contSize(v.itree,v.ihst)+(2*v.ihst[16]+3*v.ihst[17]+7*v.ihst[18]);for(var B=0;B<286;B++)v.lhst[B]=0;for(B=0;B<30;B++)v.dhst[B]=0;for(B=0;B<19;B++)v.ihst[B]=0;var U=E<F&&E<_?0:F<_?1:2;if(b(f,l,e),b(f,l+1,U),l+=3,0==U){for(;0!=(7&l);)l++;l=UZIP.F._copyExact(o,a,s,f,l);}else {var C,I;if(1==U&&(C=v.fltree,I=v.fdtree),2==U){UZIP.F.makeCodes(v.ltree,u),UZIP.F.revCodes(v.ltree,u),UZIP.F.makeCodes(v.dtree,h),UZIP.F.revCodes(v.dtree,h),UZIP.F.makeCodes(v.itree,d),UZIP.F.revCodes(v.itree,d),C=v.ltree,I=v.dtree,y(f,l,A-257),y(f,l+=5,g-1),y(f,l+=5,p-4),l+=4;for(var Q=0;Q<p;Q++)y(f,l+3*Q,v.itree[1+(v.ordr[Q]<<1)]);l+=3*p,l=UZIP.F._codeTiny(m,v.itree,f,l),l=UZIP.F._codeTiny(w,v.itree,f,l);}for(var M=a,x=0;x<r;x+=2){for(var S=t[x],R=S>>>23,T=M+(8388607&S);M<T;)l=UZIP.F._writeLit(o[M++],C,f,l);if(0!=R){var O=t[x+1],P=O>>16,H=O>>8&255,L=255&O;y(f,l=UZIP.F._writeLit(257+H,C,f,l),R-v.of0[H]),l+=v.exb[H],b(f,l=UZIP.F._writeLit(L,I,f,l),P-v.df0[L]),l+=v.dxb[L],M+=R;}}l=UZIP.F._writeLit(256,C,f,l);}return l},UZIP.F._copyExact=function(e,t,r,i,o){var a=o>>>3;return i[a]=r,i[a+1]=r>>>8,i[a+2]=255-i[a],i[a+3]=255-i[a+1],a+=4,i.set(new Uint8Array(e.buffer,t,r),a),o+(r+4<<3)},UZIP.F.getTrees=function(){for(var e=UZIP.F.U,t=UZIP.F._hufTree(e.lhst,e.ltree,15),r=UZIP.F._hufTree(e.dhst,e.dtree,15),i=[],o=UZIP.F._lenCodes(e.ltree,i),a=[],s=UZIP.F._lenCodes(e.dtree,a),f=0;f<i.length;f+=2)e.ihst[i[f]]++;for(f=0;f<a.length;f+=2)e.ihst[a[f]]++;for(var l=UZIP.F._hufTree(e.ihst,e.itree,7),c=19;c>4&&0==e.itree[1+(e.ordr[c-1]<<1)];)c--;return [t,r,l,o,s,c,i,a]},UZIP.F.getSecond=function(e){for(var t=[],r=0;r<e.length;r+=2)t.push(e[r+1]);return t},UZIP.F.nonZero=function(e){for(var t="",r=0;r<e.length;r+=2)0!=e[r+1]&&(t+=(r>>1)+",");return t},UZIP.F.contSize=function(e,t){for(var r=0,i=0;i<t.length;i++)r+=t[i]*e[1+(i<<1)];return r},UZIP.F._codeTiny=function(e,t,r,i){for(var o=0;o<e.length;o+=2){var a=e[o],s=e[o+1];i=UZIP.F._writeLit(a,t,r,i);var f=16==a?2:17==a?3:7;a>15&&(UZIP.F._putsE(r,i,s,f),i+=f);}return i},UZIP.F._lenCodes=function(e,t){for(var r=e.length;2!=r&&0==e[r-1];)r-=2;for(var i=0;i<r;i+=2){var o=e[i+1],a=i+3<r?e[i+3]:-1,s=i+5<r?e[i+5]:-1,f=0==i?-1:e[i-1];if(0==o&&a==o&&s==o){for(var l=i+5;l+2<r&&e[l+2]==o;)l+=2;(c=Math.min(l+1-i>>>1,138))<11?t.push(17,c-3):t.push(18,c-11),i+=2*c-2;}else if(o==f&&a==o&&s==o){for(l=i+5;l+2<r&&e[l+2]==o;)l+=2;var c=Math.min(l+1-i>>>1,6);t.push(16,c-3),i+=2*c-2;}else t.push(o,0);}return r>>>1},UZIP.F._hufTree=function(e,t,r){var i=[],o=e.length,a=t.length,s=0;for(s=0;s<a;s+=2)t[s]=0,t[s+1]=0;for(s=0;s<o;s++)0!=e[s]&&i.push({lit:s,f:e[s]});var f=i.length,l=i.slice(0);if(0==f)return 0;if(1==f){var c=i[0].lit;l=0==c?1:0;return t[1+(c<<1)]=1,t[1+(l<<1)]=1,1}i.sort((function(e,t){return e.f-t.f}));var u=i[0],h=i[1],d=0,A=1,g=2;for(i[0]={lit:-1,f:u.f+h.f,l:u,r:h,d:0};A!=f-1;)u=d!=A&&(g==f||i[d].f<i[g].f)?i[d++]:i[g++],h=d!=A&&(g==f||i[d].f<i[g].f)?i[d++]:i[g++],i[A++]={lit:-1,f:u.f+h.f,l:u,r:h};var p=UZIP.F.setDepth(i[A-1],0);for(p>r&&(UZIP.F.restrictDepth(l,r,p),p=r),s=0;s<f;s++)t[1+(l[s].lit<<1)]=l[s].d;return p},UZIP.F.setDepth=function(e,t){return -1!=e.lit?(e.d=t,t):Math.max(UZIP.F.setDepth(e.l,t+1),UZIP.F.setDepth(e.r,t+1))},UZIP.F.restrictDepth=function(e,t,r){var i=0,o=1<<r-t,a=0;for(e.sort((function(e,t){return t.d==e.d?e.f-t.f:t.d-e.d})),i=0;i<e.length&&e[i].d>t;i++){var s=e[i].d;e[i].d=t,a+=o-(1<<r-s);}for(a>>>=r-t;a>0;){(s=e[i].d)<t?(e[i].d++,a-=1<<t-s-1):i++;}for(;i>=0;i--)e[i].d==t&&a<0&&(e[i].d--,a++);0!=a&&console.log("debt left");},UZIP.F._goodIndex=function(e,t){var r=0;return t[16|r]<=e&&(r|=16),t[8|r]<=e&&(r|=8),t[4|r]<=e&&(r|=4),t[2|r]<=e&&(r|=2),t[1|r]<=e&&(r|=1),r},UZIP.F._writeLit=function(e,t,r,i){return UZIP.F._putsF(r,i,t[e<<1]),i+t[1+(e<<1)]},UZIP.F.inflate=function(e,t){var r=Uint8Array;if(3==e[0]&&0==e[1])return t||new r(0);var i=UZIP.F,o=i._bitsF,a=i._bitsE,s=i._decodeTiny,f=i.makeCodes,l=i.codes2map,c=i._get17,u=i.U,h=null==t;h&&(t=new r(e.length>>>2<<3));for(var d,A,g=0,p=0,m=0,w=0,v=0,b=0,y=0,E=0,F=0;0==g;)if(g=o(e,F,1),p=o(e,F+1,2),F+=3,0!=p){if(h&&(t=UZIP.F._check(t,E+(1<<17))),1==p&&(d=u.flmap,A=u.fdmap,b=511,y=31),2==p){m=a(e,F,5)+257,w=a(e,F+5,5)+1,v=a(e,F+10,4)+4,F+=14;for(var _=0;_<38;_+=2)u.itree[_]=0,u.itree[_+1]=0;var B=1;for(_=0;_<v;_++){var U=a(e,F+3*_,3);u.itree[1+(u.ordr[_]<<1)]=U,U>B&&(B=U);}F+=3*v,f(u.itree,B),l(u.itree,B,u.imap),d=u.lmap,A=u.dmap,F=s(u.imap,(1<<B)-1,m+w,e,F,u.ttree);var C=i._copyOut(u.ttree,0,m,u.ltree);b=(1<<C)-1;var I=i._copyOut(u.ttree,m,w,u.dtree);y=(1<<I)-1,f(u.ltree,C),l(u.ltree,C,d),f(u.dtree,I),l(u.dtree,I,A);}for(;;){var Q=d[c(e,F)&b];F+=15&Q;var M=Q>>>4;if(M>>>8==0)t[E++]=M;else {if(256==M)break;var x=E+M-254;if(M>264){var S=u.ldef[M-257];x=E+(S>>>3)+a(e,F,7&S),F+=7&S;}var R=A[c(e,F)&y];F+=15&R;var T=R>>>4,O=u.ddef[T],P=(O>>>4)+o(e,F,15&O);for(F+=15&O,h&&(t=UZIP.F._check(t,E+(1<<17)));E<x;)t[E]=t[E++-P],t[E]=t[E++-P],t[E]=t[E++-P],t[E]=t[E++-P];E=x;}}}else {0!=(7&F)&&(F+=8-(7&F));var H=4+(F>>>3),L=e[H-4]|e[H-3]<<8;h&&(t=UZIP.F._check(t,E+L)),t.set(new r(e.buffer,e.byteOffset+H,L),E),F=H+L<<3,E+=L;}return t.length==E?t:t.slice(0,E)},UZIP.F._check=function(e,t){var r=e.length;if(t<=r)return e;var i=new Uint8Array(Math.max(r<<1,t));return i.set(e,0),i},UZIP.F._decodeTiny=function(e,t,r,i,o,a){for(var s=UZIP.F._bitsE,f=UZIP.F._get17,l=0;l<r;){var c=e[f(i,o)&t];o+=15&c;var u=c>>>4;if(u<=15)a[l]=u,l++;else {var h=0,d=0;16==u?(d=3+s(i,o,2),o+=2,h=a[l-1]):17==u?(d=3+s(i,o,3),o+=3):18==u&&(d=11+s(i,o,7),o+=7);for(var A=l+d;l<A;)a[l]=h,l++;}}return o},UZIP.F._copyOut=function(e,t,r,i){for(var o=0,a=0,s=i.length>>>1;a<r;){var f=e[a+t];i[a<<1]=0,i[1+(a<<1)]=f,f>o&&(o=f),a++;}for(;a<s;)i[a<<1]=0,i[1+(a<<1)]=0,a++;return o},UZIP.F.makeCodes=function(e,t){for(var r,i,o,a,s=UZIP.F.U,f=e.length,l=s.bl_count,c=0;c<=t;c++)l[c]=0;for(c=1;c<f;c+=2)l[e[c]]++;var u=s.next_code;for(r=0,l[0]=0,i=1;i<=t;i++)r=r+l[i-1]<<1,u[i]=r;for(o=0;o<f;o+=2)0!=(a=e[o+1])&&(e[o]=u[a],u[a]++);},UZIP.F.codes2map=function(e,t,r){for(var i=e.length,o=UZIP.F.U.rev15,a=0;a<i;a+=2)if(0!=e[a+1])for(var s=a>>1,f=e[a+1],l=s<<4|f,c=t-f,u=e[a]<<c,h=u+(1<<c);u!=h;){r[o[u]>>>15-t]=l,u++;}},UZIP.F.revCodes=function(e,t){for(var r=UZIP.F.U.rev15,i=15-t,o=0;o<e.length;o+=2){var a=e[o]<<t-e[o+1];e[o]=r[a]>>>i;}},UZIP.F._putsE=function(e,t,r){r<<=7&t;var i=t>>>3;e[i]|=r,e[i+1]|=r>>>8;},UZIP.F._putsF=function(e,t,r){r<<=7&t;var i=t>>>3;e[i]|=r,e[i+1]|=r>>>8,e[i+2]|=r>>>16;},UZIP.F._bitsE=function(e,t,r){return (e[t>>>3]|e[1+(t>>>3)]<<8)>>>(7&t)&(1<<r)-1},UZIP.F._bitsF=function(e,t,r){return (e[t>>>3]|e[1+(t>>>3)]<<8|e[2+(t>>>3)]<<16)>>>(7&t)&(1<<r)-1},UZIP.F._get17=function(e,t){return (e[t>>>3]|e[1+(t>>>3)]<<8|e[2+(t>>>3)]<<16)>>>(7&t)},UZIP.F._get25=function(e,t){return (e[t>>>3]|e[1+(t>>>3)]<<8|e[2+(t>>>3)]<<16|e[3+(t>>>3)]<<24)>>>(7&t)},UZIP.F.U=(r=Uint16Array,i=Uint32Array,{next_code:new r(16),bl_count:new r(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 r(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 r(512),fltree:[],fdmap:new r(32),fdtree:[],lmap:new r(32768),ltree:[],ttree:[],dmap:new r(32768),dtree:[],imap:new r(512),itree:[],rev15:new r(32768),lhst:new i(286),dhst:new i(30),ihst:new i(19),lits:new i(15e3),strt:new r(65536),prev:new r(32768)}),function(){for(var e=UZIP.F.U,t=0;t<32768;t++){var r=t;r=(4278255360&(r=(4042322160&(r=(3435973836&(r=(2863311530&r)>>>1|(1431655765&r)<<1))>>>2|(858993459&r)<<2))>>>4|(252645135&r)<<4))>>>8|(16711935&r)<<8,e.rev15[t]=(r>>>16|r<<16)>>>17;}function pushV(e,t,r){for(;0!=t--;)e.push(0,r);}for(t=0;t<32;t++)e.ldef[t]=e.of0[t]<<3|e.exb[t],e.ddef[t]=e.df0[t]<<4|e.dxb[t];pushV(e.fltree,144,8),pushV(e.fltree,112,9),pushV(e.fltree,24,7),pushV(e.fltree,8,8),UZIP.F.makeCodes(e.fltree,9),UZIP.F.codes2map(e.fltree,9,e.flmap),UZIP.F.revCodes(e.fltree,9),pushV(e.fdtree,32,5),UZIP.F.makeCodes(e.fdtree,5),UZIP.F.codes2map(e.fdtree,5,e.fdmap),UZIP.F.revCodes(e.fdtree,5),pushV(e.itree,19,0),pushV(e.ltree,286,0),pushV(e.dtree,30,0),pushV(e.ttree,320,0);}();}();var UZIP=_mergeNamespaces({__proto__:null,default:e},[e]);const UPNG=function(){var e={nextZero(e,t){for(;0!=e[t];)t++;return t},readUshort:(e,t)=>e[t]<<8|e[t+1],writeUshort(e,t,r){e[t]=r>>8&255,e[t+1]=255&r;},readUint:(e,t)=>16777216*e[t]+(e[t+1]<<16|e[t+2]<<8|e[t+3]),writeUint(e,t,r){e[t]=r>>24&255,e[t+1]=r>>16&255,e[t+2]=r>>8&255,e[t+3]=255&r;},readASCII(e,t,r){let i="";for(let o=0;o<r;o++)i+=String.fromCharCode(e[t+o]);return i},writeASCII(e,t,r){for(let i=0;i<r.length;i++)e[t+i]=r.charCodeAt(i);},readBytes(e,t,r){const i=[];for(let o=0;o<r;o++)i.push(e[t+o]);return i},pad:e=>e.length<2?`0${e}`:e,readUTF8(t,r,i){let o,a="";for(let o=0;o<i;o++)a+=`%${e.pad(t[r+o].toString(16))}`;try{o=decodeURIComponent(a);}catch(o){return e.readASCII(t,r,i)}return o}};function decodeImage(t,r,i,o){const a=r*i,s=_getBPP(o),f=Math.ceil(r*s/8),l=new Uint8Array(4*a),c=new Uint32Array(l.buffer),{ctype:u}=o,{depth:h}=o,d=e.readUshort;if(6==u){const e=a<<2;if(8==h)for(var A=0;A<e;A+=4)l[A]=t[A],l[A+1]=t[A+1],l[A+2]=t[A+2],l[A+3]=t[A+3];if(16==h)for(A=0;A<e;A++)l[A]=t[A<<1];}else if(2==u){const e=o.tabs.tRNS;if(null==e){if(8==h)for(A=0;A<a;A++){var g=3*A;c[A]=255<<24|t[g+2]<<16|t[g+1]<<8|t[g];}if(16==h)for(A=0;A<a;A++){g=6*A;c[A]=255<<24|t[g+4]<<16|t[g+2]<<8|t[g];}}else {var p=e[0];const r=e[1],i=e[2];if(8==h)for(A=0;A<a;A++){var m=A<<2;g=3*A;c[A]=255<<24|t[g+2]<<16|t[g+1]<<8|t[g],t[g]==p&&t[g+1]==r&&t[g+2]==i&&(l[m+3]=0);}if(16==h)for(A=0;A<a;A++){m=A<<2,g=6*A;c[A]=255<<24|t[g+4]<<16|t[g+2]<<8|t[g],d(t,g)==p&&d(t,g+2)==r&&d(t,g+4)==i&&(l[m+3]=0);}}}else if(3==u){const e=o.tabs.PLTE,s=o.tabs.tRNS,c=s?s.length:0;if(1==h)for(var w=0;w<i;w++){var v=w*f,b=w*r;for(A=0;A<r;A++){m=b+A<<2;var y=3*(E=t[v+(A>>3)]>>7-((7&A)<<0)&1);l[m]=e[y],l[m+1]=e[y+1],l[m+2]=e[y+2],l[m+3]=E<c?s[E]:255;}}if(2==h)for(w=0;w<i;w++)for(v=w*f,b=w*r,A=0;A<r;A++){m=b+A<<2,y=3*(E=t[v+(A>>2)]>>6-((3&A)<<1)&3);l[m]=e[y],l[m+1]=e[y+1],l[m+2]=e[y+2],l[m+3]=E<c?s[E]:255;}if(4==h)for(w=0;w<i;w++)for(v=w*f,b=w*r,A=0;A<r;A++){m=b+A<<2,y=3*(E=t[v+(A>>1)]>>4-((1&A)<<2)&15);l[m]=e[y],l[m+1]=e[y+1],l[m+2]=e[y+2],l[m+3]=E<c?s[E]:255;}if(8==h)for(A=0;A<a;A++){var E;m=A<<2,y=3*(E=t[A]);l[m]=e[y],l[m+1]=e[y+1],l[m+2]=e[y+2],l[m+3]=E<c?s[E]:255;}}else if(4==u){if(8==h)for(A=0;A<a;A++){m=A<<2;var F=t[_=A<<1];l[m]=F,l[m+1]=F,l[m+2]=F,l[m+3]=t[_+1];}if(16==h)for(A=0;A<a;A++){var _;m=A<<2,F=t[_=A<<2];l[m]=F,l[m+1]=F,l[m+2]=F,l[m+3]=t[_+2];}}else if(0==u)for(p=o.tabs.tRNS?o.tabs.tRNS:-1,w=0;w<i;w++){const e=w*f,i=w*r;if(1==h)for(var B=0;B<r;B++){var U=(F=255*(t[e+(B>>>3)]>>>7-(7&B)&1))==255*p?0:255;c[i+B]=U<<24|F<<16|F<<8|F;}else if(2==h)for(B=0;B<r;B++){U=(F=85*(t[e+(B>>>2)]>>>6-((3&B)<<1)&3))==85*p?0:255;c[i+B]=U<<24|F<<16|F<<8|F;}else if(4==h)for(B=0;B<r;B++){U=(F=17*(t[e+(B>>>1)]>>>4-((1&B)<<2)&15))==17*p?0:255;c[i+B]=U<<24|F<<16|F<<8|F;}else if(8==h)for(B=0;B<r;B++){U=(F=t[e+B])==p?0:255;c[i+B]=U<<24|F<<16|F<<8|F;}else if(16==h)for(B=0;B<r;B++){F=t[e+(B<<1)],U=d(t,e+(B<<1))==p?0:255;c[i+B]=U<<24|F<<16|F<<8|F;}}return l}function _decompress(e,r,i,o){const a=_getBPP(e),s=Math.ceil(i*a/8),f=new Uint8Array((s+1+e.interlace)*o);return r=e.tabs.CgBI?t(r,f):_inflate(r,f),0==e.interlace?r=_filterZero(r,e,0,i,o):1==e.interlace&&(r=function _readInterlace(e,t){const r=t.width,i=t.height,o=_getBPP(t),a=o>>3,s=Math.ceil(r*o/8),f=new Uint8Array(i*s);let l=0;const c=[0,0,4,0,2,0,1],u=[0,4,0,2,0,1,0],h=[8,8,8,4,4,2,2],d=[8,8,4,4,2,2,1];let A=0;for(;A<7;){const p=h[A],m=d[A];let w=0,v=0,b=c[A];for(;b<i;)b+=p,v++;let y=u[A];for(;y<r;)y+=m,w++;const E=Math.ceil(w*o/8);_filterZero(e,t,l,w,v);let F=0,_=c[A];for(;_<i;){let t=u[A],i=l+F*E<<3;for(;t<r;){var g;if(1==o)g=(g=e[i>>3])>>7-(7&i)&1,f[_*s+(t>>3)]|=g<<7-((7&t)<<0);if(2==o)g=(g=e[i>>3])>>6-(7&i)&3,f[_*s+(t>>2)]|=g<<6-((3&t)<<1);if(4==o)g=(g=e[i>>3])>>4-(7&i)&15,f[_*s+(t>>1)]|=g<<4-((1&t)<<2);if(o>=8){const r=_*s+t*a;for(let t=0;t<a;t++)f[r+t]=e[(i>>3)+t];}i+=o,t+=m;}F++,_+=p;}w*v!=0&&(l+=v*(1+E)),A+=1;}return f}(r,e)),r}function _inflate(e,r){return t(new Uint8Array(e.buffer,2,e.length-6),r)}var t=function(){const e={H:{}};return e.H.N=function(t,r){const i=Uint8Array;let o,a,s=0,f=0,l=0,c=0,u=0,h=0,d=0,A=0,g=0;if(3==t[0]&&0==t[1])return r||new i(0);const p=e.H,m=p.b,w=p.e,v=p.R,b=p.n,y=p.A,E=p.Z,F=p.m,_=null==r;for(_&&(r=new i(t.length>>>2<<5));0==s;)if(s=m(t,g,1),f=m(t,g+1,2),g+=3,0!=f){if(_&&(r=e.H.W(r,A+(1<<17))),1==f&&(o=F.J,a=F.h,h=511,d=31),2==f){l=w(t,g,5)+257,c=w(t,g+5,5)+1,u=w(t,g+10,4)+4,g+=14;let e=1;for(var B=0;B<38;B+=2)F.Q[B]=0,F.Q[B+1]=0;for(B=0;B<u;B++){const r=w(t,g+3*B,3);F.Q[1+(F.X[B]<<1)]=r,r>e&&(e=r);}g+=3*u,b(F.Q,e),y(F.Q,e,F.u),o=F.w,a=F.d,g=v(F.u,(1<<e)-1,l+c,t,g,F.v);const r=p.V(F.v,0,l,F.C);h=(1<<r)-1;const i=p.V(F.v,l,c,F.D);d=(1<<i)-1,b(F.C,r),y(F.C,r,o),b(F.D,i),y(F.D,i,a);}for(;;){const e=o[E(t,g)&h];g+=15&e;const i=e>>>4;if(i>>>8==0)r[A++]=i;else {if(256==i)break;{let e=A+i-254;if(i>264){const r=F.q[i-257];e=A+(r>>>3)+w(t,g,7&r),g+=7&r;}const o=a[E(t,g)&d];g+=15&o;const s=o>>>4,f=F.c[s],l=(f>>>4)+m(t,g,15&f);for(g+=15&f;A<e;)r[A]=r[A++-l],r[A]=r[A++-l],r[A]=r[A++-l],r[A]=r[A++-l];A=e;}}}}else {0!=(7&g)&&(g+=8-(7&g));const o=4+(g>>>3),a=t[o-4]|t[o-3]<<8;_&&(r=e.H.W(r,A+a)),r.set(new i(t.buffer,t.byteOffset+o,a),A),g=o+a<<3,A+=a;}return r.length==A?r:r.slice(0,A)},e.H.W=function(e,t){const r=e.length;if(t<=r)return e;const i=new Uint8Array(r<<1);return i.set(e,0),i},e.H.R=function(t,r,i,o,a,s){const f=e.H.e,l=e.H.Z;let c=0;for(;c<i;){const e=t[l(o,a)&r];a+=15&e;const i=e>>>4;if(i<=15)s[c]=i,c++;else {let e=0,t=0;16==i?(t=3+f(o,a,2),a+=2,e=s[c-1]):17==i?(t=3+f(o,a,3),a+=3):18==i&&(t=11+f(o,a,7),a+=7);const r=c+t;for(;c<r;)s[c]=e,c++;}}return a},e.H.V=function(e,t,r,i){let o=0,a=0;const s=i.length>>>1;for(;a<r;){const r=e[a+t];i[a<<1]=0,i[1+(a<<1)]=r,r>o&&(o=r),a++;}for(;a<s;)i[a<<1]=0,i[1+(a<<1)]=0,a++;return o},e.H.n=function(t,r){const i=e.H.m,o=t.length;let a,s,f;let l;const c=i.j;for(var u=0;u<=r;u++)c[u]=0;for(u=1;u<o;u+=2)c[t[u]]++;const h=i.K;for(a=0,c[0]=0,s=1;s<=r;s++)a=a+c[s-1]<<1,h[s]=a;for(f=0;f<o;f+=2)l=t[f+1],0!=l&&(t[f]=h[l],h[l]++);},e.H.A=function(t,r,i){const o=t.length,a=e.H.m.r;for(let e=0;e<o;e+=2)if(0!=t[e+1]){const o=e>>1,s=t[e+1],f=o<<4|s,l=r-s;let c=t[e]<<l;const u=c+(1<<l);for(;c!=u;){i[a[c]>>>15-r]=f,c++;}}},e.H.l=function(t,r){const i=e.H.m.r,o=15-r;for(let e=0;e<t.length;e+=2){const a=t[e]<<r-t[e+1];t[e]=i[a]>>>o;}},e.H.M=function(e,t,r){r<<=7&t;const i=t>>>3;e[i]|=r,e[i+1]|=r>>>8;},e.H.I=function(e,t,r){r<<=7&t;const i=t>>>3;e[i]|=r,e[i+1]|=r>>>8,e[i+2]|=r>>>16;},e.H.e=function(e,t,r){return (e[t>>>3]|e[1+(t>>>3)]<<8)>>>(7&t)&(1<<r)-1},e.H.b=function(e,t,r){return (e[t>>>3]|e[1+(t>>>3)]<<8|e[2+(t>>>3)]<<16)>>>(7&t)&(1<<r)-1},e.H.Z=function(e,t){return (e[t>>>3]|e[1+(t>>>3)]<<8|e[2+(t>>>3)]<<16)>>>(7&t)},e.H.i=function(e,t){return (e[t>>>3]|e[1+(t>>>3)]<<8|e[2+(t>>>3)]<<16|e[3+(t>>>3)]<<24)>>>(7&t)},e.H.m=function(){const e=Uint16Array,t=Uint32Array;return {K:new e(16),j:new e(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 e(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 t(32),J:new e(512),_:[],h:new e(32),$:[],w:new e(32768),C:[],v:[],d:new e(32768),D:[],u:new e(512),Q:[],r:new e(32768),s:new t(286),Y:new t(30),a:new t(19),t:new t(15e3),k:new e(65536),g:new e(32768)}}(),function(){const t=e.H.m;for(var r=0;r<32768;r++){let e=r;e=(2863311530&e)>>>1|(1431655765&e)<<1,e=(3435973836&e)>>>2|(858993459&e)<<2,e=(4042322160&e)>>>4|(252645135&e)<<4,e=(4278255360&e)>>>8|(16711935&e)<<8,t.r[r]=(e>>>16|e<<16)>>>17;}function n(e,t,r){for(;0!=t--;)e.push(0,r);}for(r=0;r<32;r++)t.q[r]=t.S[r]<<3|t.T[r],t.c[r]=t.p[r]<<4|t.z[r];n(t._,144,8),n(t._,112,9),n(t._,24,7),n(t._,8,8),e.H.n(t._,9),e.H.A(t._,9,t.J),e.H.l(t._,9),n(t.$,32,5),e.H.n(t.$,5),e.H.A(t.$,5,t.h),e.H.l(t.$,5),n(t.Q,19,0),n(t.C,286,0),n(t.D,30,0),n(t.v,320,0);}(),e.H.N}();function _getBPP(e){return [1,null,3,1,2,null,4][e.ctype]*e.depth}function _filterZero(e,t,r,i,o){let a=_getBPP(t);const s=Math.ceil(i*a/8);let f,l;a=Math.ceil(a/8);let c=e[r],u=0;if(c>1&&(e[r]=[0,0,1][c-2]),3==c)for(u=a;u<s;u++)e[u+1]=e[u+1]+(e[u+1-a]>>>1)&255;for(let t=0;t<o;t++)if(f=r+t*s,l=f+t+1,c=e[l-1],u=0,0==c)for(;u<s;u++)e[f+u]=e[l+u];else if(1==c){for(;u<a;u++)e[f+u]=e[l+u];for(;u<s;u++)e[f+u]=e[l+u]+e[f+u-a];}else if(2==c)for(;u<s;u++)e[f+u]=e[l+u]+e[f+u-s];else if(3==c){for(;u<a;u++)e[f+u]=e[l+u]+(e[f+u-s]>>>1);for(;u<s;u++)e[f+u]=e[l+u]+(e[f+u-s]+e[f+u-a]>>>1);}else {for(;u<a;u++)e[f+u]=e[l+u]+_paeth(0,e[f+u-s],0);for(;u<s;u++)e[f+u]=e[l+u]+_paeth(e[f+u-a],e[f+u-s],e[f+u-a-s]);}return e}function _paeth(e,t,r){const i=e+t-r,o=i-e,a=i-t,s=i-r;return o*o<=a*a&&o*o<=s*s?e:a*a<=s*s?t:r}function _IHDR(t,r,i){i.width=e.readUint(t,r),r+=4,i.height=e.readUint(t,r),r+=4,i.depth=t[r],r++,i.ctype=t[r],r++,i.compress=t[r],r++,i.filter=t[r],r++,i.interlace=t[r],r++;}function _copyTile(e,t,r,i,o,a,s,f,l){const c=Math.min(t,o),u=Math.min(r,a);let h=0,d=0;for(let r=0;r<u;r++)for(let a=0;a<c;a++)if(s>=0&&f>=0?(h=r*t+a<<2,d=(f+r)*o+s+a<<2):(h=(-f+r)*t-s+a<<2,d=r*o+a<<2),0==l)i[d]=e[h],i[d+1]=e[h+1],i[d+2]=e[h+2],i[d+3]=e[h+3];else if(1==l){var A=e[h+3]*(1/255),g=e[h]*A,p=e[h+1]*A,m=e[h+2]*A,w=i[d+3]*(1/255),v=i[d]*w,b=i[d+1]*w,y=i[d+2]*w;const t=1-A,r=A+w*t,o=0==r?0:1/r;i[d+3]=255*r,i[d+0]=(g+v*t)*o,i[d+1]=(p+b*t)*o,i[d+2]=(m+y*t)*o;}else if(2==l){A=e[h+3],g=e[h],p=e[h+1],m=e[h+2],w=i[d+3],v=i[d],b=i[d+1],y=i[d+2];A==w&&g==v&&p==b&&m==y?(i[d]=0,i[d+1]=0,i[d+2]=0,i[d+3]=0):(i[d]=g,i[d+1]=p,i[d+2]=m,i[d+3]=A);}else if(3==l){A=e[h+3],g=e[h],p=e[h+1],m=e[h+2],w=i[d+3],v=i[d],b=i[d+1],y=i[d+2];if(A==w&&g==v&&p==b&&m==y)continue;if(A<220&&w>20)return false}return true}return {decode:function decode(r){const i=new Uint8Array(r);let o=8;const a=e,s=a.readUshort,f=a.readUint,l={tabs:{},frames:[]},c=new Uint8Array(i.length);let u,h=0,d=0;const A=[137,80,78,71,13,10,26,10];for(var g=0;g<8;g++)if(i[g]!=A[g])throw "The input is not a PNG file!";for(;o<i.length;){const e=a.readUint(i,o);o+=4;const r=a.readASCII(i,o,4);if(o+=4,"IHDR"==r)_IHDR(i,o,l);else if("iCCP"==r){for(var p=o;0!=i[p];)p++;a.readASCII(i,o,p-o);const s=i.slice(p+2,o+e);let f=null;try{f=_inflate(s);}catch(e){f=t(s);}l.tabs[r]=f;}else if("CgBI"==r)l.tabs[r]=i.slice(o,o+4);else if("IDAT"==r){for(g=0;g<e;g++)c[h+g]=i[o+g];h+=e;}else if("acTL"==r)l.tabs[r]={num_frames:f(i,o),num_plays:f(i,o+4)},u=new Uint8Array(i.length);else if("fcTL"==r){if(0!=d)(E=l.frames[l.frames.length-1]).data=_decompress(l,u.slice(0,d),E.rect.width,E.rect.height),d=0;const e={x:f(i,o+12),y:f(i,o+16),width:f(i,o+4),height:f(i,o+8)};let t=s(i,o+22);t=s(i,o+20)/(0==t?100:t);const r={rect:e,delay:Math.round(1e3*t),dispose:i[o+24],blend:i[o+25]};l.frames.push(r);}else if("fdAT"==r){for(g=0;g<e-4;g++)u[d+g]=i[o+g+4];d+=e-4;}else if("pHYs"==r)l.tabs[r]=[a.readUint(i,o),a.readUint(i,o+4),i[o+8]];else if("cHRM"==r){l.tabs[r]=[];for(g=0;g<8;g++)l.tabs[r].push(a.readUint(i,o+4*g));}else if("tEXt"==r||"zTXt"==r){null==l.tabs[r]&&(l.tabs[r]={});var m=a.nextZero(i,o),w=a.readASCII(i,o,m-o),v=o+e-m-1;if("tEXt"==r)y=a.readASCII(i,m+1,v);else {var b=_inflate(i.slice(m+2,m+2+v));y=a.readUTF8(b,0,b.length);}l.tabs[r][w]=y;}else if("iTXt"==r){null==l.tabs[r]&&(l.tabs[r]={});m=0,p=o;m=a.nextZero(i,p);w=a.readASCII(i,p,m-p);const t=i[p=m+1];var y;p+=2,m=a.nextZero(i,p),a.readASCII(i,p,m-p),p=m+1,m=a.nextZero(i,p),a.readUTF8(i,p,m-p);v=e-((p=m+1)-o);if(0==t)y=a.readUTF8(i,p,v);else {b=_inflate(i.slice(p,p+v));y=a.readUTF8(b,0,b.length);}l.tabs[r][w]=y;}else if("PLTE"==r)l.tabs[r]=a.readBytes(i,o,e);else if("hIST"==r){const e=l.tabs.PLTE.length/3;l.tabs[r]=[];for(g=0;g<e;g++)l.tabs[r].push(s(i,o+2*g));}else if("tRNS"==r)3==l.ctype?l.tabs[r]=a.readBytes(i,o,e):0==l.ctype?l.tabs[r]=s(i,o):2==l.ctype&&(l.tabs[r]=[s(i,o),s(i,o+2),s(i,o+4)]);else if("gAMA"==r)l.tabs[r]=a.readUint(i,o)/1e5;else if("sRGB"==r)l.tabs[r]=i[o];else if("bKGD"==r)0==l.ctype||4==l.ctype?l.tabs[r]=[s(i,o)]:2==l.ctype||6==l.ctype?l.tabs[r]=[s(i,o),s(i,o+2),s(i,o+4)]:3==l.ctype&&(l.tabs[r]=i[o]);else if("IEND"==r)break;o+=e,a.readUint(i,o),o+=4;}var E;return 0!=d&&((E=l.frames[l.frames.length-1]).data=_decompress(l,u.slice(0,d),E.rect.width,E.rect.height)),l.data=_decompress(l,c,l.width,l.height),delete l.compress,delete l.interlace,delete l.filter,l},toRGBA8:function toRGBA8(e){const t=e.width,r=e.height;if(null==e.tabs.acTL)return [decodeImage(e.data,t,r,e).buffer];const i=[];null==e.frames[0].data&&(e.frames[0].data=e.data);const o=t*r*4,a=new Uint8Array(o),s=new Uint8Array(o),f=new Uint8Array(o);for(let c=0;c<e.frames.length;c++){const u=e.frames[c],h=u.rect.x,d=u.rect.y,A=u.rect.width,g=u.rect.height,p=decodeImage(u.data,A,g,e);if(0!=c)for(var l=0;l<o;l++)f[l]=a[l];if(0==u.blend?_copyTile(p,A,g,a,t,r,h,d,0):1==u.blend&&_copyTile(p,A,g,a,t,r,h,d,1),i.push(a.buffer.slice(0)),0==u.dispose);else if(1==u.dispose)_copyTile(s,A,g,a,t,r,h,d,0);else if(2==u.dispose)for(l=0;l<o;l++)a[l]=f[l];}return i},_paeth:_paeth,_copyTile:_copyTile,_bin:e}}();!function(){const{_copyTile:e}=UPNG,{_bin:t}=UPNG,r=UPNG._paeth;var i={table:function(){const e=new Uint32Array(256);for(let t=0;t<256;t++){let r=t;for(let e=0;e<8;e++)1&r?r=3988292384^r>>>1:r>>>=1;e[t]=r;}return e}(),update(e,t,r,o){for(let a=0;a<o;a++)e=i.table[255&(e^t[r+a])]^e>>>8;return e},crc:(e,t,r)=>4294967295^i.update(4294967295,e,t,r)};function addErr(e,t,r,i){t[r]+=e[0]*i>>4,t[r+1]+=e[1]*i>>4,t[r+2]+=e[2]*i>>4,t[r+3]+=e[3]*i>>4;}function N(e){return Math.max(0,Math.min(255,e))}function D(e,t){const r=e[0]-t[0],i=e[1]-t[1],o=e[2]-t[2],a=e[3]-t[3];return r*r+i*i+o*o+a*a}function dither(e,t,r,i,o,a,s){null==s&&(s=1);const f=i.length,l=[];for(var c=0;c<f;c++){const e=i[c];l.push([e>>>0&255,e>>>8&255,e>>>16&255,e>>>24&255]);}for(c=0;c<f;c++){let e=4294967295;for(var u=0,h=0;h<f;h++){var d=D(l[c],l[h]);h!=c&&d<e&&(e=d,u=h);}}const A=new Uint32Array(o.buffer),g=new Int16Array(t*r*4),p=[0,8,2,10,12,4,14,6,3,11,1,9,15,7,13,5];for(c=0;c<p.length;c++)p[c]=255*((p[c]+.5)/16-.5);for(let o=0;o<r;o++)for(let w=0;w<t;w++){var m;c=4*(o*t+w);if(2!=s)m=[N(e[c]+g[c]),N(e[c+1]+g[c+1]),N(e[c+2]+g[c+2]),N(e[c+3]+g[c+3])];else {d=p[4*(3&o)+(3&w)];m=[N(e[c]+d),N(e[c+1]+d),N(e[c+2]+d),N(e[c+3]+d)];}u=0;let v=16777215;for(h=0;h<f;h++){const e=D(m,l[h]);e<v&&(v=e,u=h);}const b=l[u],y=[m[0]-b[0],m[1]-b[1],m[2]-b[2],m[3]-b[3]];1==s&&(w!=t-1&&addErr(y,g,c+4,7),o!=r-1&&(0!=w&&addErr(y,g,c+4*t-4,3),addErr(y,g,c+4*t,5),w!=t-1&&addErr(y,g,c+4*t+4,1))),a[c>>2]=u,A[c>>2]=i[u];}}function _main(e,r,o,a,s){null==s&&(s={});const{crc:f}=i,l=t.writeUint,c=t.writeUshort,u=t.writeASCII;let h=8;const d=e.frames.length>1;let A,g=false,p=33+(d?20:0);if(null!=s.sRGB&&(p+=13),null!=s.pHYs&&(p+=21),null!=s.iCCP&&(A=pako.deflate(s.iCCP),p+=21+A.length+4),3==e.ctype){for(var m=e.plte.length,w=0;w<m;w++)e.plte[w]>>>24!=255&&(g=true);p+=8+3*m+4+(g?8+1*m+4:0);}for(var v=0;v<e.frames.length;v++){d&&(p+=38),p+=(F=e.frames[v]).cimg.length+12,0!=v&&(p+=4);}p+=12;const b=new Uint8Array(p),y=[137,80,78,71,13,10,26,10];for(w=0;w<8;w++)b[w]=y[w];if(l(b,h,13),h+=4,u(b,h,"IHDR"),h+=4,l(b,h,r),h+=4,l(b,h,o),h+=4,b[h]=e.depth,h++,b[h]=e.ctype,h++,b[h]=0,h++,b[h]=0,h++,b[h]=0,h++,l(b,h,f(b,h-17,17)),h+=4,null!=s.sRGB&&(l(b,h,1),h+=4,u(b,h,"sRGB"),h+=4,b[h]=s.sRGB,h++,l(b,h,f(b,h-5,5)),h+=4),null!=s.iCCP){const e=13+A.length;l(b,h,e),h+=4,u(b,h,"iCCP"),h+=4,u(b,h,"ICC profile"),h+=11,h+=2,b.set(A,h),h+=A.length,l(b,h,f(b,h-(e+4),e+4)),h+=4;}if(null!=s.pHYs&&(l(b,h,9),h+=4,u(b,h,"pHYs"),h+=4,l(b,h,s.pHYs[0]),h+=4,l(b,h,s.pHYs[1]),h+=4,b[h]=s.pHYs[2],h++,l(b,h,f(b,h-13,13)),h+=4),d&&(l(b,h,8),h+=4,u(b,h,"acTL"),h+=4,l(b,h,e.frames.length),h+=4,l(b,h,null!=s.loop?s.loop:0),h+=4,l(b,h,f(b,h-12,12)),h+=4),3==e.ctype){l(b,h,3*(m=e.plte.length)),h+=4,u(b,h,"PLTE"),h+=4;for(w=0;w<m;w++){const t=3*w,r=e.plte[w],i=255&r,o=r>>>8&255,a=r>>>16&255;b[h+t+0]=i,b[h+t+1]=o,b[h+t+2]=a;}if(h+=3*m,l(b,h,f(b,h-3*m-4,3*m+4)),h+=4,g){l(b,h,m),h+=4,u(b,h,"tRNS"),h+=4;for(w=0;w<m;w++)b[h+w]=e.plte[w]>>>24&255;h+=m,l(b,h,f(b,h-m-4,m+4)),h+=4;}}let E=0;for(v=0;v<e.frames.length;v++){var F=e.frames[v];d&&(l(b,h,26),h+=4,u(b,h,"fcTL"),h+=4,l(b,h,E++),h+=4,l(b,h,F.rect.width),h+=4,l(b,h,F.rect.height),h+=4,l(b,h,F.rect.x),h+=4,l(b,h,F.rect.y),h+=4,c(b,h,a[v]),h+=2,c(b,h,1e3),h+=2,b[h]=F.dispose,h++,b[h]=F.blend,h++,l(b,h,f(b,h-30,30)),h+=4);const t=F.cimg;l(b,h,(m=t.length)+(0==v?0:4)),h+=4;const r=h;u(b,h,0==v?"IDAT":"fdAT"),h+=4,0!=v&&(l(b,h,E++),h+=4),b.set(t,h),h+=m,l(b,h,f(b,r,h-r)),h+=4;}return l(b,h,0),h+=4,u(b,h,"IEND"),h+=4,l(b,h,f(b,h-4,4)),h+=4,b.buffer}function compressPNG(e,t,r){for(let i=0;i<e.frames.length;i++){const o=e.frames[i];const a=o.rect.height,s=new Uint8Array(a*o.bpl+a);o.cimg=_filterZero(o.img,a,o.bpp,o.bpl,s,t,r);}}function compress(t,r,i,o,a){const s=a[0],f=a[1],l=a[2],c=a[3],u=a[4],h=a[5];let d=6,A=8,g=255;for(var p=0;p<t.length;p++){const e=new Uint8Array(t[p]);for(var m=e.length,w=0;w<m;w+=4)g&=e[w+3];}const v=255!=g,b=function framize(t,r,i,o,a,s){const f=[];for(var l=0;l<t.length;l++){const h=new Uint8Array(t[l]),A=new Uint32Array(h.buffer);var c;let g=0,p=0,m=r,w=i,v=o?1:0;if(0!=l){const b=s||o||1==l||0!=f[l-2].dispose?1:2;let y=0,E=1e9;for(let e=0;e<b;e++){var u=new Uint8Array(t[l-1-e]);const o=new Uint32Array(t[l-1-e]);let s=r,f=i,c=-1,h=-1;for(let e=0;e<i;e++)for(let t=0;t<r;t++){A[d=e*r+t]!=o[d]&&(t<s&&(s=t),t>c&&(c=t),e<f&&(f=e),e>h&&(h=e));} -1==c&&(s=f=c=h=0),a&&(1==(1&s)&&s--,1==(1&f)&&f--);const v=(c-s+1)*(h-f+1);v<E&&(E=v,y=e,g=s,p=f,m=c-s+1,w=h-f+1);}u=new Uint8Array(t[l-1-y]);1==y&&(f[l-1].dispose=2),c=new Uint8Array(m*w*4),e(u,r,i,c,m,w,-g,-p,0),v=e(h,r,i,c,m,w,-g,-p,3)?1:0,1==v?_prepareDiff(h,r,i,c,{x:g,y:p,width:m,height:w}):e(h,r,i,c,m,w,-g,-p,0);}else c=h.slice(0);f.push({rect:{x:g,y:p,width:m,height:w},img:c,blend:v,dispose:0});}if(o)for(l=0;l<f.length;l++){if(1==(A=f[l]).blend)continue;const e=A.rect,o=f[l-1].rect,s=Math.min(e.x,o.x),c=Math.min(e.y,o.y),u={x:s,y:c,width:Math.max(e.x+e.width,o.x+o.width)-s,height:Math.max(e.y+e.height,o.y+o.height)-c};f[l-1].dispose=1,l-1!=0&&_updateFrame(t,r,i,f,l-1,u,a),_updateFrame(t,r,i,f,l,u,a);}let h=0;if(1!=t.length)for(var d=0;d<f.length;d++){var A;h+=(A=f[d]).rect.width*A.rect.height;}return f}(t,r,i,s,f,l),y={},E=[],F=[];if(0!=o){const e=[];for(w=0;w<b.length;w++)e.push(b[w].img.buffer);const t=function concatRGBA(e){let t=0;for(var r=0;r<e.length;r++)t+=e[r].byteLength;const i=new Uint8Array(t);let o=0;for(r=0;r<e.length;r++){const t=new Uint8Array(e[r]),a=t.length;for(let e=0;e<a;e+=4){let r=t[e],a=t[e+1],s=t[e+2];const f=t[e+3];0==f&&(r=a=s=0),i[o+e]=r,i[o+e+1]=a,i[o+e+2]=s,i[o+e+3]=f;}o+=a;}return i.buffer}(e),r=quantize(t,o);for(w=0;w<r.plte.length;w++)E.push(r.plte[w].est.rgba);let i=0;for(w=0;w<b.length;w++){const e=(B=b[w]).img.length;var _=new Uint8Array(r.inds.buffer,i>>2,e>>2);F.push(_);const t=new Uint8Array(r.abuf,i,e);h&&dither(B.img,B.rect.width,B.rect.height,E,t,_),B.img.set(t),i+=e;}}else for(p=0;p<b.length;p++){var B=b[p];const e=new Uint32Array(B.img.buffer);var U=B.rect.width;m=e.length,_=new Uint8Array(m);F.push(_);for(w=0;w<m;w++){const t=e[w];if(0!=w&&t==e[w-1])_[w]=_[w-1];else if(w>U&&t==e[w-U])_[w]=_[w-U];else {let e=y[t];if(null==e&&(y[t]=e=E.length,E.push(t),E.length>=300))break;_[w]=e;}}}const C=E.length;C<=256&&0==u&&(A=C<=2?1:C<=4?2:C<=16?4:8,A=Math.max(A,c));for(p=0;p<b.length;p++){(B=b[p]).rect.x;U=B.rect.width;const e=B.rect.height;let t=B.img;let r=4*U,i=4;if(C<=256&&0==u){r=Math.ceil(A*U/8);var I=new Uint8Array(r*e);const o=F[p];for(let t=0;t<e;t++){w=t*r;const e=t*U;if(8==A)for(var Q=0;Q<U;Q++)I[w+Q]=o[e+Q];else if(4==A)for(Q=0;Q<U;Q++)I[w+(Q>>1)]|=o[e+Q]<<4-4*(1&Q);else if(2==A)for(Q=0;Q<U;Q++)I[w+(Q>>2)]|=o[e+Q]<<6-2*(3&Q);else if(1==A)for(Q=0;Q<U;Q++)I[w+(Q>>3)]|=o[e+Q]<<7-1*(7&Q);}t=I,d=3,i=1;}else if(0==v&&1==b.length){I=new Uint8Array(U*e*3);const o=U*e;for(w=0;w<o;w++){const e=3*w,r=4*w;I[e]=t[r],I[e+1]=t[r+1],I[e+2]=t[r+2];}t=I,d=2,i=3,r=3*U;}B.img=t,B.bpl=r,B.bpp=i;}return {ctype:d,depth:A,plte:E,frames:b}}function _updateFrame(t,r,i,o,a,s,f){const l=Uint8Array,c=Uint32Array,u=new l(t[a-1]),h=new c(t[a-1]),d=a+1<t.length?new l(t[a+1]):null,A=new l(t[a]),g=new c(A.buffer);let p=r,m=i,w=-1,v=-1;for(let e=0;e<s.height;e++)for(let t=0;t<s.width;t++){const i=s.x+t,f=s.y+e,l=f*r+i,c=g[l];0==c||0==o[a-1].dispose&&h[l]==c&&(null==d||0!=d[4*l+3])||(i<p&&(p=i),i>w&&(w=i),f<m&&(m=f),f>v&&(v=f));} -1==w&&(p=m=w=v=0),f&&(1==(1&p)&&p--,1==(1&m)&&m--),s={x:p,y:m,width:w-p+1,height:v-m+1};const b=o[a];b.rect=s,b.blend=1,b.img=new Uint8Array(s.width*s.height*4),0==o[a-1].dispose?(e(u,r,i,b.img,s.width,s.height,-s.x,-s.y,0),_prepareDiff(A,r,i,b.img,s)):e(A,r,i,b.img,s.width,s.height,-s.x,-s.y,0);}function _prepareDiff(t,r,i,o,a){e(t,r,i,o,a.width,a.height,-a.x,-a.y,2);}function _filterZero(e,t,r,i,o,a,s){const f=[];let l,c=[0,1,2,3,4];-1!=a?c=[a]:(t*i>5e5||1==r)&&(c=[0]),s&&(l={level:0});const u=UZIP;for(var h=0;h<c.length;h++){for(let a=0;a<t;a++)_filterLine(o,e,a,i,r,c[h]);f.push(u.deflate(o,l));}let d,A=1e9;for(h=0;h<f.length;h++)f[h].length<A&&(d=h,A=f[h].length);return f[d]}function _filterLine(e,t,i,o,a,s){const f=i*o;let l=f+i;if(e[l]=s,l++,0==s)if(o<500)for(var c=0;c<o;c++)e[l+c]=t[f+c];else e.set(new Uint8Array(t.buffer,f,o),l);else if(1==s){for(c=0;c<a;c++)e[l+c]=t[f+c];for(c=a;c<o;c++)e[l+c]=t[f+c]-t[f+c-a]+256&255;}else if(0==i){for(c=0;c<a;c++)e[l+c]=t[f+c];if(2==s)for(c=a;c<o;c++)e[l+c]=t[f+c];if(3==s)for(c=a;c<o;c++)e[l+c]=t[f+c]-(t[f+c-a]>>1)+256&255;if(4==s)for(c=a;c<o;c++)e[l+c]=t[f+c]-r(t[f+c-a],0,0)+256&255;}else {if(2==s)for(c=0;c<o;c++)e[l+c]=t[f+c]+256-t[f+c-o]&255;if(3==s){for(c=0;c<a;c++)e[l+c]=t[f+c]+256-(t[f+c-o]>>1)&255;for(c=a;c<o;c++)e[l+c]=t[f+c]+256-(t[f+c-o]+t[f+c-a]>>1)&255;}if(4==s){for(c=0;c<a;c++)e[l+c]=t[f+c]+256-r(0,t[f+c-o],0)&255;for(c=a;c<o;c++)e[l+c]=t[f+c]+256-r(t[f+c-a],t[f+c-o],t[f+c-a-o])&255;}}}function quantize(e,t){const r=new Uint8Array(e),i=r.slice(0),o=new Uint32Array(i.buffer),a=getKDtree(i,t),s=a[0],f=a[1],l=r.length,c=new Uint8Array(l>>2);let u;if(r.length<2e7)for(var h=0;h<l;h+=4){u=getNearest(s,d=r[h]*(1/255),A=r[h+1]*(1/255),g=r[h+2]*(1/255),p=r[h+3]*(1/255)),c[h>>2]=u.ind,o[h>>2]=u.est.rgba;}else for(h=0;h<l;h+=4){var d=r[h]*(1/255),A=r[h+1]*(1/255),g=r[h+2]*(1/255),p=r[h+3]*(1/255);for(u=s;u.left;)u=planeDst(u.est,d,A,g,p)<=0?u.left:u.right;c[h>>2]=u.ind,o[h>>2]=u.est.rgba;}return {abuf:i.buffer,inds:c,plte:f}}function getKDtree(e,t,r){null==r&&(r=1e-4);const i=new Uint32Array(e.buffer),o={i0:0,i1:e.length,bst:null,est:null,tdst:0,left:null,right:null};o.bst=stats(e,o.i0,o.i1),o.est=estats(o.bst);const a=[o];for(;a.length<t;){let t=0,o=0;for(var s=0;s<a.length;s++)a[s].est.L>t&&(t=a[s].est.L,o=s);if(t<r)break;const f=a[o],l=splitPixels(e,i,f.i0,f.i1,f.est.e,f.est.eMq255);if(f.i0>=l||f.i1<=l){f.est.L=0;continue}const c={i0:f.i0,i1:l,bst:null,est:null,tdst:0,left:null,right:null};c.bst=stats(e,c.i0,c.i1),c.est=estats(c.bst);const u={i0:l,i1:f.i1,bst:null,est:null,tdst:0,left:null,right:null};u.bst={R:[],m:[],N:f.bst.N-c.bst.N};for(s=0;s<16;s++)u.bst.R[s]=f.bst.R[s]-c.bst.R[s];for(s=0;s<4;s++)u.bst.m[s]=f.bst.m[s]-c.bst.m[s];u.est=estats(u.bst),f.left=c,f.right=u,a[o]=c,a.push(u);}a.sort(((e,t)=>t.bst.N-e.bst.N));for(s=0;s<a.length;s++)a[s].ind=s;return [o,a]}function getNearest(e,t,r,i,o){if(null==e.left)return e.tdst=function dist(e,t,r,i,o){const a=t-e[0],s=r-e[1],f=i-e[2],l=o-e[3];return a*a+s*s+f*f+l*l}(e.est.q,t,r,i,o),e;const a=planeDst(e.est,t,r,i,o);let s=e.left,f=e.right;a>0&&(s=e.right,f=e.left);const l=getNearest(s,t,r,i,o);if(l.tdst<=a*a)return l;const c=getNearest(f,t,r,i,o);return c.tdst<l.tdst?c:l}function planeDst(e,t,r,i,o){const{e:a}=e;return a[0]*t+a[1]*r+a[2]*i+a[3]*o-e.eMq}function splitPixels(e,t,r,i,o,a){for(i-=4;r<i;){for(;vecDot(e,r,o)<=a;)r+=4;for(;vecDot(e,i,o)>a;)i-=4;if(r>=i)break;const s=t[r>>2];t[r>>2]=t[i>>2],t[i>>2]=s,r+=4,i-=4;}for(;vecDot(e,r,o)>a;)r-=4;return r+4}function vecDot(e,t,r){return e[t]*r[0]+e[t+1]*r[1]+e[t+2]*r[2]+e[t+3]*r[3]}function stats(e,t,r){const i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],o=[0,0,0,0],a=r-t>>2;for(let a=t;a<r;a+=4){const t=e[a]*(1/255),r=e[a+1]*(1/255),s=e[a+2]*(1/255),f=e[a+3]*(1/255);o[0]+=t,o[1]+=r,o[2]+=s,o[3]+=f,i[0]+=t*t,i[1]+=t*r,i[2]+=t*s,i[3]+=t*f,i[5]+=r*r,i[6]+=r*s,i[7]+=r*f,i[10]+=s*s,i[11]+=s*f,i[15]+=f*f;}return i[4]=i[1],i[8]=i[2],i[9]=i[6],i[12]=i[3],i[13]=i[7],i[14]=i[11],{R:i,m:o,N:a}}function estats(e){const{R:t}=e,{m:r}=e,{N:i}=e,a=r[0],s=r[1],f=r[2],l=r[3],c=0==i?0:1/i,u=[t[0]-a*a*c,t[1]-a*s*c,t[2]-a*f*c,t[3]-a*l*c,t[4]-s*a*c,t[5]-s*s*c,t[6]-s*f*c,t[7]-s*l*c,t[8]-f*a*c,t[9]-f*s*c,t[10]-f*f*c,t[11]-f*l*c,t[12]-l*a*c,t[13]-l*s*c,t[14]-l*f*c,t[15]-l*l*c],h=u,d=o;let A=[Math.random(),Math.random(),Math.random(),Math.random()],g=0,p=0;if(0!=i)for(let e=0;e<16&&(A=d.multVec(h,A),p=Math.sqrt(d.dot(A,A)),A=d.sml(1/p,A),!(0!=e&&Math.abs(p-g)<1e-9));e++)g=p;const m=[a*c,s*c,f*c,l*c];return {Cov:u,q:m,e:A,L:g,eMq255:d.dot(d.sml(255,m),A),eMq:d.dot(A,m),rgba:(Math.round(255*m[3])<<24|Math.round(255*m[2])<<16|Math.round(255*m[1])<<8|Math.round(255*m[0])<<0)>>>0}}var o={multVec:(e,t)=>[e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3],e[4]*t[0]+e[5]*t[1]+e[6]*t[2]+e[7]*t[3],e[8]*t[0]+e[9]*t[1]+e[10]*t[2]+e[11]*t[3],e[12]*t[0]+e[13]*t[1]+e[14]*t[2]+e[15]*t[3]],dot:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3],sml:(e,t)=>[e*t[0],e*t[1],e*t[2],e*t[3]]};UPNG.encode=function encode(e,t,r,i,o,a,s){null==i&&(i=0),null==s&&(s=false);const f=compress(e,t,r,i,[false,false,false,0,s,false]);return compressPNG(f,-1),_main(f,t,r,o,a)},UPNG.encodeLL=function encodeLL(e,t,r,i,o,a,s,f){const l={ctype:0+(1==i?0:2)+(0==o?0:4),depth:a,frames:[]},c=(i+o)*a,u=c*t;for(let i=0;i<e.length;i++)l.frames.push({rect:{x:0,y:0,width:t,height:r},img:new Uint8Array(e[i]),blend:0,dispose:1,bpp:Math.ceil(c/8),bpl:Math.ceil(u/8)});return compressPNG(l,0,true),_main(l,t,r,s,f)},UPNG.encode.compress=compress,UPNG.encode.dither=dither,UPNG.quantize=quantize,UPNG.quantize.getKDtree=getKDtree,UPNG.quantize.getNearest=getNearest;}();const r={toArrayBuffer(e,t){const i=e.width,o=e.height,a=i<<2,s=e.getContext("2d").getImageData(0,0,i,o),f=new Uint32Array(s.data.buffer),l=(32*i+31)/32<<2,c=l*o,u=122+c,h=new ArrayBuffer(u),d=new DataView(h),A=1<<20;let g,p,m,w,v=A,b=0,y=0,E=0;function set16(e){d.setUint16(y,e,true),y+=2;}function set32(e){d.setUint32(y,e,true),y+=4;}function seek(e){y+=e;}set16(19778),set32(u),seek(4),set32(122),set32(108),set32(i),set32(-o>>>0),set16(1),set16(32),set32(3),set32(c),set32(2835),set32(2835),seek(8),set32(16711680),set32(65280),set32(255),set32(4278190080),set32(1466527264),function convert(){for(;b<o&&v>0;){for(w=122+b*l,g=0;g<a;)v--,p=f[E++],m=p>>>24,d.setUint32(w+g,p<<8|m),g+=4;b++;}E<f.length?(v=A,setTimeout(convert,r._dly)):t(h);}();},toBlob(e,t){this.toArrayBuffer(e,(e=>{t(new Blob([e],{type:"image/bmp"}));}));},_dly:9};var i={CHROME:"CHROME",FIREFOX:"FIREFOX",DESKTOP_SAFARI:"DESKTOP_SAFARI",IE:"IE",IOS:"IOS",ETC:"ETC"},o={[i.CHROME]:16384,[i.FIREFOX]:11180,[i.DESKTOP_SAFARI]:16384,[i.IE]:8192,[i.IOS]:4096,[i.ETC]:8192};const a="undefined"!=typeof window,s="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,f=a&&window.cordova&&window.cordova.require&&window.cordova.require("cordova/modulemapper"),CustomFile=(a||s)&&(f&&f.getOriginalSymbol(window,"File")||"undefined"!=typeof File&&File),CustomFileReader=(a||s)&&(f&&f.getOriginalSymbol(window,"FileReader")||"undefined"!=typeof FileReader&&FileReader);function getFilefromDataUrl(e,t,r=Date.now()){return new Promise((i=>{const o=e.split(","),a=o[0].match(/:(.*?);/)[1],s=globalThis.atob(o[1]);let f=s.length;const l=new Uint8Array(f);for(;f--;)l[f]=s.charCodeAt(f);const c=new Blob([l],{type:a});c.name=t,c.lastModified=r,i(c);}))}function getDataUrlFromFile(e){return new Promise(((t,r)=>{const i=new CustomFileReader;i.onload=()=>t(i.result),i.onerror=e=>r(e),i.readAsDataURL(e);}))}function loadImage(e){return new Promise(((t,r)=>{const i=new Image;i.onload=()=>t(i),i.onerror=e=>r(e),i.src=e;}))}function getBrowserName(){if(void 0!==getBrowserName.cachedResult)return getBrowserName.cachedResult;let e=i.ETC;const{userAgent:t}=navigator;return /Chrom(e|ium)/i.test(t)?e=i.CHROME:/iP(ad|od|hone)/i.test(t)&&/WebKit/i.test(t)?e=i.IOS:/Safari/i.test(t)?e=i.DESKTOP_SAFARI:/Firefox/i.test(t)?e=i.FIREFOX:(/MSIE/i.test(t)||true==!!document.documentMode)&&(e=i.IE),getBrowserName.cachedResult=e,getBrowserName.cachedResult}function approximateBelowMaximumCanvasSizeOfBrowser(e,t){const r=getBrowserName(),i=o[r];let a=e,s=t,f=a*s;const l=a>s?s/a:a/s;for(;f>i*i;){const e=(i+a)/2,t=(i+s)/2;e<t?(s=t,a=t*l):(s=e*l,a=e),f=a*s;}return {width:a,height:s}}function getNewCanvasAndCtx(e,t){let r,i;try{if(r=new OffscreenCanvas(e,t),i=r.getContext("2d"),null===i)throw new Error("getContext of OffscreenCanvas returns null")}catch(e){r=document.createElement("canvas"),i=r.getContext("2d");}return r.width=e,r.height=t,[r,i]}function drawImageInCanvas(e,t){const{width:r,height:i}=approximateBelowMaximumCanvasSizeOfBrowser(e.width,e.height),[o,a]=getNewCanvasAndCtx(r,i);return t&&/jpe?g/.test(t)&&(a.fillStyle="white",a.fillRect(0,0,o.width,o.height)),a.drawImage(e,0,0,o.width,o.height),o}function isIOS(){return void 0!==isIOS.cachedResult||(isIOS.cachedResult=["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"undefined"!=typeof document&&"ontouchend"in document),isIOS.cachedResult}function drawFileInCanvas(e,t={}){return new Promise((function(r,o){let a,s;var $Try_2_Post=function(){try{return s=drawImageInCanvas(a,t.fileType||e.type),r([a,s])}catch(e){return o(e)}},$Try_2_Catch=function(t){try{var $Try_3_Catch=function(e){try{throw e}catch(e){return o(e)}};try{let t;return getDataUrlFromFile(e).then((function(e){try{return t=e,loadImage(t).then((function(e){try{return a=e,function(){try{return $Try_2_Post()}catch(e){return o(e)}}()}catch(e){return $Try_3_Catch(e)}}),$Try_3_Catch)}catch(e){return $Try_3_Catch(e)}}),$Try_3_Catch)}catch(e){$Try_3_Catch(e);}}catch(e){return o(e)}};try{if(isIOS()||[i.DESKTOP_SAFARI,i.MOBILE_SAFARI].includes(getBrowserName()))throw new Error("Skip createImageBitmap on IOS and Safari");return createImageBitmap(e).then((function(e){try{return a=e,$Try_2_Post()}catch(e){return $Try_2_Catch()}}),$Try_2_Catch)}catch(e){$Try_2_Catch();}}))}function canvasToFile(e,t,i,o,a=1){return new Promise((function(s,f){let l;if("image/png"===t){let c,u,h;return c=e.getContext("2d"),({data:u}=c.getImageData(0,0,e.width,e.height)),h=UPNG.encode([u.buffer],e.width,e.height,4096*a),l=new Blob([h],{type:t}),l.name=i,l.lastModified=o,$If_4.call(this)}{if("image/bmp"===t)return new Promise((t=>r.toBlob(e,t))).then(function(e){try{return l=e,l.name=i,l.lastModified=o,$If_5.call(this)}catch(e){return f(e)}}.bind(this),f);{if("function"==typeof OffscreenCanvas&&e instanceof OffscreenCanvas)return e.convertToBlob({type:t,quality:a}).then(function(e){try{return l=e,l.name=i,l.lastModified=o,$If_6.call(this)}catch(e){return f(e)}}.bind(this),f);{let d;return d=e.toDataURL(t,a),getFilefromDataUrl(d,i,o).then(function(e){try{return l=e,$If_6.call(this)}catch(e){return f(e)}}.bind(this),f)}function $If_6(){return $If_5.call(this)}}function $If_5(){return $If_4.call(this)}}function $If_4(){return s(l)}}))}function cleanupCanvasMemory(e){e.width=0,e.height=0;}function isAutoOrientationInBrowser(){return new Promise((function(e,t){let i,o,a,s;return void 0!==isAutoOrientationInBrowser.cachedResult?e(isAutoOrientationInBrowser.cachedResult):(getFilefromDataUrl("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/xABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAAAAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==","test.jpg",Date.now()).then((function(r){try{return i=r,drawFileInCanvas(i).then((function(r){try{return o=r[1],canvasToFile(o,i.type,i.name,i.lastModified).then((function(r){try{return a=r,cleanupCanvasMemory(o),drawFileInCanvas(a).then((function(r){try{return s=r[0],isAutoOrientationInBrowser.cachedResult=1===s.width&&2===s.height,e(isAutoOrientationInBrowser.cachedResult)}catch(e){return t(e)}}),t)}catch(e){return t(e)}}),t)}catch(e){return t(e)}}),t)}catch(e){return t(e)}}),t))}))}function getExifOrientation(e){return new Promise(((t,r)=>{const i=new CustomFileReader;i.onload=e=>{const r=new DataView(e.target.result);if(65496!=r.getUint16(0,false))return t(-2);const i=r.byteLength;let o=2;for(;o<i;){if(r.getUint16(o+2,false)<=8)return t(-1);const e=r.getUint16(o,false);if(o+=2,65505==e){if(1165519206!=r.getUint32(o+=2,false))return t(-1);const e=18761==r.getUint16(o+=6,false);o+=r.getUint32(o+4,e);const i=r.getUint16(o,e);o+=2;for(let a=0;a<i;a++)if(274==r.getUint16(o+12*a,e))return t(r.getUint16(o+12*a+8,e))}else {if(65280!=(65280&e))break;o+=r.getUint16(o,false);}}return t(-1)},i.onerror=e=>r(e),i.readAsArrayBuffer(e);}))}function handleMaxWidthOrHeight(e,t){const{width:r}=e,{height:i}=e,{maxWidthOrHeight:o}=t;let a,s=e;return isFinite(o)&&(r>o||i>o)&&([s,a]=getNewCanvasAndCtx(r,i),r>i?(s.width=o,s.height=i/r*o):(s.width=r/i*o,s.height=o),a.drawImage(e,0,0,s.width,s.height),cleanupCanvasMemory(e)),s}function followExifOrientation(e,t){const{width:r}=e,{height:i}=e,[o,a]=getNewCanvasAndCtx(r,i);switch(t>4&&t<9?(o.width=i,o.height=r):(o.width=r,o.height=i),t){case 2:a.transform(-1,0,0,1,r,0);break;case 3:a.transform(-1,0,0,-1,r,i);break;case 4:a.transform(1,0,0,-1,0,i);break;case 5:a.transform(0,1,1,0,0,0);break;case 6:a.transform(0,1,-1,0,i,0);break;case 7:a.transform(0,-1,-1,0,i,r);break;case 8:a.transform(0,-1,1,0,0,r);}return a.drawImage(e,0,0,r,i),cleanupCanvasMemory(e),o}function compress(e,t,r=0){return new Promise((function(i,o){let a,s,f,l,c,u,h,d,A,g,p,m,w,v,b,y,E,F,_,B;function incProgress(e=5){if(t.signal&&t.signal.aborted)throw t.signal.reason;a+=e,t.onProgress(Math.min(a,100));}function setProgress(e){if(t.signal&&t.signal.aborted)throw t.signal.reason;a=Math.min(Math.max(e,a),100),t.onProgress(a);}return a=r,s=t.maxIteration||10,f=1024*t.maxSizeMB*1024,incProgress(),drawFileInCanvas(e,t).then(function(r){try{return [,l]=r,incProgress(),c=handleMaxWidthOrHeight(l,t),incProgress(),new Promise((function(r,i){var o;if(!(o=t.exifOrientation))return getExifOrientation(e).then(function(e){try{return o=e,$If_2.call(this)}catch(e){return i(e)}}.bind(this),i);function $If_2(){return r(o)}return $If_2.call(this)})).then(function(r){try{return u=r,incProgress(),isAutoOrientationInBrowser().then(function(r){try{return h=r?c:followExifOrientation(c,u),incProgress(),d=t.initialQuality||1,A=t.fileType||e.type,canvasToFile(h,A,e.name,e.lastModified,d).then(function(r){try{{if(g=r,incProgress(),p=g.size>f,m=g.size>e.size,!p&&!m)return setProgress(100),i(g);var a;function $Loop_3(){if(s--&&(b>f||b>w)){let t,r;return t=B?.95*_.width:_.width,r=B?.95*_.height:_.height,[E,F]=getNewCanvasAndCtx(t,r),F.drawImage(_,0,0,t,r),d*="image/png"===A?.85:.95,canvasToFile(E,A,e.name,e.lastModified,d).then((function(e){try{return y=e,cleanupCanvasMemory(_),_=E,b=y.size,setProgress(Math.min(99,Math.floor((v-b)/(v-f)*100))),$Loop_3}catch(e){return o(e)}}),o)}return [1]}return w=e.size,v=g.size,b=v,_=h,B=!t.alwaysKeepResolution&&p,(a=function(e){for(;e;){if(e.then)return void e.then(a,o);try{if(e.pop){if(e.length)return e.pop()?$Loop_3_exit.call(this):e;e=$Loop_3;}else e=e.call(this);}catch(e){return o(e)}}}.bind(this))($Loop_3);function $Loop_3_exit(){return cleanupCanvasMemory(_),cleanupCanvasMemory(E),cleanupCanvasMemory(c),cleanupCanvasMemory(h),cleanupCanvasMemory(l),setProgress(100),i(y)}}}catch(u){return o(u)}}.bind(this),o)}catch(e){return o(e)}}.bind(this),o)}catch(e){return o(e)}}.bind(this),o)}catch(e){return o(e)}}.bind(this),o)}))}const l="\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 c;function compressOnWebWorker(e,t){return new Promise(((r,i)=>{c||(c=function createWorkerScriptURL(e){const t=[];return t.push(e),URL.createObjectURL(new Blob(t))}(l));const o=new Worker(c);o.addEventListener("message",(function handler(e){if(t.signal&&t.signal.aborted)o.terminate();else if(void 0===e.data.progress){if(e.data.error)return i(new Error(e.data.error)),void o.terminate();r(e.data.file),o.terminate();}else t.onProgress(e.data.progress);})),o.addEventListener("error",i),t.signal&&t.signal.addEventListener("abort",(()=>{i(t.signal.reason),o.terminate();})),o.postMessage({file:e,imageCompressionLibUrl:t.libURL,options:{...t,onProgress:void 0,signal:void 0}});}))}function imageCompression(e,t){return new Promise((function(r,i){let o,a,s,f,l,c;if(o={...t},s=0,({onProgress:f}=o),o.maxSizeMB=o.maxSizeMB||Number.POSITIVE_INFINITY,l="boolean"!=typeof o.useWebWorker||o.useWebWorker,delete o.useWebWorker,o.onProgress=e=>{s=e,"function"==typeof f&&f(s);},!(e instanceof Blob||e instanceof CustomFile))return i(new Error("The file given is not an instance of Blob or File"));if(!/^image/.test(e.type))return i(new Error("The file given is not an image"));if(c="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,!l||"function"!=typeof Worker||c)return compress(e,o).then(function(e){try{return a=e,$If_4.call(this)}catch(e){return i(e)}}.bind(this),i);var u=function(){try{return $If_4.call(this)}catch(e){return i(e)}}.bind(this),$Try_1_Catch=function(t){try{return compress(e,o).then((function(e){try{return a=e,u()}catch(e){return i(e)}}),i)}catch(e){return i(e)}};try{return o.libURL=o.libURL||"https://cdn.jsdelivr.net/npm/browser-image-compression@2.0.2/dist/browser-image-compression.js",compressOnWebWorker(e,o).then((function(e){try{return a=e,u()}catch(e){return $Try_1_Catch()}}),$Try_1_Catch)}catch(e){$Try_1_Catch();}function $If_4(){try{a.name=e.name,a.lastModified=e.lastModified;}catch(e){}try{o.preserveExif&&"image/jpeg"===e.type&&(!o.fileType||o.fileType&&o.fileType===e.type)&&(a=copyExifWithoutOrientation(e,a));}catch(e){}return r(a)}}))}imageCompression.getDataUrlFromFile=getDataUrlFromFile,imageCompression.getFilefromDataUrl=getFilefromDataUrl,imageCompression.loadImage=loadImage,imageCompression.drawImageInCanvas=drawImageInCanvas,imageCompression.drawFileInCanvas=drawFileInCanvas,imageCompression.canvasToFile=canvasToFile,imageCompression.getExifOrientation=getExifOrientation,imageCompression.handleMaxWidthOrHeight=handleMaxWidthOrHeight,imageCompression.followExifOrientation=followExifOrientation,imageCompression.cleanupCanvasMemory=cleanupCanvasMemory,imageCompression.isAutoOrientationInBrowser=isAutoOrientationInBrowser,imageCompression.approximateBelowMaximumCanvasSizeOfBrowser=approximateBelowMaximumCanvasSizeOfBrowser,imageCompression.copyExifWithoutOrientation=copyExifWithoutOrientation,imageCompression.getBrowserName=getBrowserName,imageCompression.version="2.0.2";
1299
+
1300
+ class KritzelImageTool extends KritzelBaseTool {
1301
+ constructor(store) {
1302
+ super(store);
1303
+ this.fileInput = null;
1304
+ this.maxCompressionSize = 300;
1305
+ this.setupFileInput();
1306
+ }
1307
+ onActivate() {
1308
+ this.openFilePicker();
1309
+ }
1310
+ openFilePicker() {
1311
+ if (this._store.isDisabled) {
1312
+ return;
1313
+ }
1314
+ this.fileInput.click();
1315
+ }
1316
+ setupFileInput() {
1317
+ this.fileInput = document.createElement('input');
1318
+ this.fileInput.type = 'file';
1319
+ this.fileInput.accept = 'image/*';
1320
+ this.fileInput.style.display = 'none';
1321
+ this.fileInput.addEventListener('change', this.handleFileSelect.bind(this));
1322
+ this.fileInput.addEventListener('cancel', this.handleCancel.bind(this));
1323
+ document.body.appendChild(this.fileInput);
1324
+ }
1325
+ handleFileSelect(event) {
1326
+ const input = event.target;
1327
+ if (input.files && input.files[0]) {
1328
+ const file = input.files[0];
1329
+ imageCompression(file, {
1330
+ maxWidthOrHeight: this.maxCompressionSize,
1331
+ })
1332
+ .then(compressedFile => {
1333
+ this.readFile(compressedFile);
1334
+ })
1335
+ .catch(error => {
1336
+ console.error('Error during image compression or processing:', error);
1337
+ this.handleCancel();
1338
+ });
1339
+ }
1340
+ else {
1341
+ console.info('File selection cancelled by user.');
1342
+ this.handleCancel();
1343
+ }
1344
+ if (input) {
1345
+ input.value = '';
1346
+ }
1347
+ }
1348
+ readFile(file) {
1349
+ const reader = new FileReader();
1350
+ reader.onload = e => {
1351
+ var _a;
1352
+ const img = new Image();
1353
+ img.src = (_a = e.target) === null || _a === void 0 ? void 0 : _a.result;
1354
+ img.onload = () => this.createKritzelImage(img);
1355
+ };
1356
+ reader.readAsDataURL(file);
1357
+ }
1358
+ createKritzelImage(img) {
1359
+ const image = KritzelImage.create(this._store);
1360
+ const { scaledWidth, scaledHeight } = image.calculateScaledDimensions(img);
1361
+ image.src = img.src;
1362
+ image.width = scaledWidth;
1363
+ image.height = scaledHeight;
1364
+ image.zIndex = this._store.currentZIndex;
1365
+ image.centerInViewport();
1366
+ this.addImageToStore(image);
1367
+ return image;
1368
+ }
1369
+ addImageToStore(image) {
1370
+ const selectionGroup = KritzelSelectionGroup.create(this._store);
1371
+ selectionGroup.addOrRemove(image);
1372
+ selectionGroup.isSelected = true;
1373
+ const addImageCommand = new AddObjectCommand(this._store, this, image);
1374
+ const addSelectionGroupCommand = new AddSelectionGroupCommand(this._store, this, selectionGroup);
1375
+ this._store.history.executeCommand(new BatchCommand(this._store, this, [addImageCommand, addSelectionGroupCommand]));
1376
+ this._store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
1377
+ }
1378
+ handleCancel() {
1379
+ this._store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
1380
+ }
1381
+ }
1382
+
1383
+ const ABSOLUTE_SCALE_MAX = 1000;
1384
+ const ABSOLUTE_SCALE_MIN = 0.0001;
1385
+
1386
+ class KritzelViewport {
1387
+ constructor(store, host) {
1388
+ this.initialTouchDistance = 0;
1389
+ this.startX = 0;
1390
+ this.startY = 0;
1391
+ this._store = store;
1392
+ this._store.state.host = host;
1393
+ this._store.state.viewportWidth = host.clientWidth;
1394
+ this._store.state.viewportHeight = host.clientHeight;
1395
+ this._store.state.startX = 0;
1396
+ this._store.state.startY = 0;
1397
+ this._store.state.translateX = 0;
1398
+ this._store.state.translateY = 0;
1399
+ }
1400
+ handleResize() {
1401
+ this._store.state.viewportWidth = this._store.state.host.clientWidth;
1402
+ this._store.state.viewportHeight = this._store.state.host.clientHeight;
1403
+ this._store.state.hasViewportChanged = true;
1404
+ this._store.rerender();
1405
+ }
1406
+ handlePointerDown(event) {
1407
+ if (event.pointerType === 'mouse') {
1408
+ const adjustedClientX = event.clientX - this._store.offsetX;
1409
+ const adjustedClientY = event.clientY - this._store.offsetY;
1410
+ if (event.button === KritzelMouseButton.Right) {
1411
+ this._store.state.isPanning = true;
1412
+ this._store.state.startX = adjustedClientX;
1413
+ this._store.state.startY = adjustedClientY;
1414
+ }
1415
+ }
1416
+ if (event.pointerType === 'touch') {
1417
+ const activePointers = Array.from(this._store.state.pointers.values());
1418
+ if (activePointers.length === 2) {
1419
+ this._store.state.currentPath = null;
1420
+ this._store.state.isScaling = true;
1421
+ const firstTouchX = activePointers[0].clientX - this._store.offsetX;
1422
+ const firstTouchY = activePointers[0].clientY - this._store.offsetY;
1423
+ const secondTouchX = activePointers[1].clientX - this._store.offsetX;
1424
+ const secondTouchY = activePointers[1].clientY - this._store.offsetY;
1425
+ this.initialTouchDistance = Math.sqrt(Math.pow(firstTouchX - secondTouchX, 2) + Math.pow(firstTouchY - secondTouchY, 2));
1426
+ this.startX = (firstTouchX + secondTouchX) / 2;
1427
+ this.startY = (firstTouchY + secondTouchY) / 2;
1428
+ this._store.rerender();
1429
+ }
1430
+ }
1431
+ }
1432
+ handlePointerMove(event) {
1433
+ if (event.pointerType === 'mouse') {
1434
+ const hostRect = this._store.state.host.getBoundingClientRect();
1435
+ const xRelativeToHost = event.clientX - hostRect.left;
1436
+ const yRelativeToHost = event.clientY - hostRect.top;
1437
+ this._store.state.pointerX = (xRelativeToHost - this._store.state.translateX) / this._store.state.scale;
1438
+ this._store.state.pointerY = (yRelativeToHost - this._store.state.translateY) / this._store.state.scale;
1439
+ if (this._store.state.isPanning) {
1440
+ this._store.state.translateX -= this._store.state.startX - xRelativeToHost;
1441
+ this._store.state.translateY -= this._store.state.startY - yRelativeToHost;
1442
+ this._store.state.startX = xRelativeToHost;
1443
+ this._store.state.startY = yRelativeToHost;
1444
+ this._store.state.hasViewportChanged = true;
1445
+ this._store.state.skipContextMenu = true;
1446
+ this._store.rerender();
1447
+ this._store.updateWorkspaceViewport(this._store.state.translateX, this._store.state.translateY, this._store.state.scale);
1448
+ }
1449
+ }
1450
+ if (event.pointerType === 'touch') {
1451
+ const hostRect = this._store.state.host.getBoundingClientRect();
1452
+ const xRelativeToHost = event.clientX - hostRect.left;
1453
+ const yRelativeToHost = event.clientY - hostRect.top;
1454
+ this._store.state.pointerX = (xRelativeToHost - this._store.state.translateX) / this._store.state.scale;
1455
+ this._store.state.pointerY = (yRelativeToHost - this._store.state.translateY) / this._store.state.scale;
1456
+ const activePointers = Array.from(this._store.state.pointers.values());
1457
+ if (activePointers.length === 2) {
1458
+ const firstTouchX = activePointers[0].clientX - this._store.offsetX;
1459
+ const firstTouchY = activePointers[0].clientY - this._store.offsetY;
1460
+ const secondTouchX = activePointers[1].clientX - this._store.offsetX;
1461
+ const secondTouchY = activePointers[1].clientY - this._store.offsetY;
1462
+ const currentTouchDistance = Math.sqrt(Math.pow(firstTouchX - secondTouchX, 2) + Math.pow(firstTouchY - secondTouchY, 2));
1463
+ const midpointX = (firstTouchX + secondTouchX) / 2;
1464
+ const midpointY = (firstTouchY + secondTouchY) / 2;
1465
+ const scaleRatio = currentTouchDistance / this.initialTouchDistance;
1466
+ const newScale = this._store.state.scale * scaleRatio;
1467
+ if (newScale > this._store.state.scaleMax || newScale < this._store.state.scaleMin) {
1468
+ this._store.state.translateX += midpointX - this.startX;
1469
+ this._store.state.translateY += midpointY - this.startY;
1470
+ }
1471
+ else {
1472
+ const translateXAdjustment = (midpointX - this._store.state.translateX) * (scaleRatio - 1);
1473
+ const translateYAdjustment = (midpointY - this._store.state.translateY) * (scaleRatio - 1);
1474
+ this._store.state.translateX += midpointX - this.startX - translateXAdjustment;
1475
+ this._store.state.translateY += midpointY - this.startY - translateYAdjustment;
1476
+ this._store.state.scale = newScale;
1477
+ this.initialTouchDistance = currentTouchDistance;
1478
+ }
1479
+ this.startX = midpointX;
1480
+ this.startY = midpointY;
1481
+ this._store.state.hasViewportChanged = true;
1482
+ this._store.rerender();
1483
+ this._store.updateWorkspaceViewport(this._store.state.translateX, this._store.state.translateY, this._store.state.scale);
1484
+ }
1485
+ }
1486
+ }
1487
+ handlePointerUp(event) {
1488
+ if (event.pointerType === 'mouse') {
1489
+ if (this._store.state.isPanning) {
1490
+ this._store.state.isPanning = false;
1491
+ this._store.rerender();
1492
+ }
1493
+ }
1494
+ if (event.pointerType === 'touch') {
1495
+ this._store.state.isScaling = false;
1496
+ this._store.rerender();
1497
+ }
1498
+ }
1499
+ handleWheel(event) {
1500
+ event.preventDefault();
1501
+ if (event.ctrlKey === true && KritzelEventHelper.isMainMouseWheel(event)) {
1502
+ this.handleZoom(event);
1503
+ }
1504
+ if (!event.ctrlKey) {
1505
+ this.handlePan(event);
1506
+ }
1507
+ }
1508
+ handleZoom(event) {
1509
+ const rect = this._store.state.host.getBoundingClientRect();
1510
+ const xRelativeToHost = event.clientX - rect.left;
1511
+ const yRelativeToHost = event.clientY - rect.top;
1512
+ this._store.state.pointerX = (xRelativeToHost - this._store.state.translateX) / this._store.state.scale;
1513
+ this._store.state.pointerY = (yRelativeToHost - this._store.state.translateY) / this._store.state.scale;
1514
+ const delta = event.deltaY > 0 ? -this._store.state.scaleStep * this._store.state.scale : this._store.state.scaleStep * this._store.state.scale;
1515
+ const newScale = Math.min(this._store.state.scaleMax, Math.max(this._store.state.scaleMin, this._store.state.scale + delta));
1516
+ const scaleRatio = newScale / this._store.state.scale;
1517
+ const translateXAdjustment = (xRelativeToHost - this._store.state.translateX) * (scaleRatio - 1);
1518
+ const translateYAdjustment = (yRelativeToHost - this._store.state.translateY) * (scaleRatio - 1);
1519
+ this._store.state.scale = newScale;
1520
+ this._store.state.translateX -= translateXAdjustment;
1521
+ this._store.state.translateY -= translateYAdjustment;
1522
+ this._store.state.hasViewportChanged = true;
1523
+ this._store.rerender();
1524
+ this._store.updateWorkspaceViewport(this._store.state.translateX, this._store.state.translateY, this._store.state.scale);
1525
+ }
1526
+ handlePan(event) {
1527
+ const panSpeed = 0.8;
1528
+ this._store.state.translateX -= event.deltaX * panSpeed;
1529
+ this._store.state.translateY -= event.deltaY * panSpeed;
1530
+ this._store.state.hasViewportChanged = true;
1531
+ this._store.rerender();
1532
+ this._store.updateWorkspaceViewport(this._store.state.translateX, this._store.state.translateY, this._store.state.scale);
1533
+ }
1534
+ }
1535
+
1536
+ class UpdateViewportCommand extends KritzelBaseCommand {
1537
+ constructor(store, initiator, previousViewport, skipHistory = false) {
1538
+ super(store, initiator, skipHistory);
1539
+ this.previousViewport = previousViewport;
1540
+ this.currentViewport = {
1541
+ scale: this._store.state.scale,
1542
+ translateX: this._store.state.translateX,
1543
+ translateY: this._store.state.translateY,
1544
+ };
1545
+ }
1546
+ execute() {
1547
+ this._store.state.scale = this.currentViewport.scale;
1548
+ this._store.state.translateX = this.currentViewport.translateX;
1549
+ this._store.state.translateY = this.currentViewport.translateY;
1550
+ }
1551
+ undo() {
1552
+ this._store.state.scale = this.previousViewport.scale;
1553
+ this._store.state.translateX = this.previousViewport.translateX;
1554
+ this._store.state.translateY = this.previousViewport.translateY;
1555
+ }
1556
+ }
1557
+
1558
+ class KritzelCircularBuffer {
1559
+ constructor(capacity) {
1560
+ this.head = 0;
1561
+ this.tail = 0;
1562
+ this.size = 0;
1563
+ this.capacity = capacity;
1564
+ this.buffer = new Array(capacity).fill(null);
1565
+ }
1566
+ add(item) {
1567
+ this.buffer[this.head] = item;
1568
+ this.head = (this.head + 1) % this.capacity;
1569
+ if (this.size < this.capacity) {
1570
+ this.size++;
1571
+ }
1572
+ else {
1573
+ this.tail = (this.tail + 1) % this.capacity;
1574
+ }
1575
+ }
1576
+ pop() {
1577
+ if (this.size === 0) {
1578
+ return null;
1579
+ }
1580
+ this.head = (this.head - 1 + this.capacity) % this.capacity;
1581
+ const item = this.buffer[this.head];
1582
+ this.buffer[this.head] = null;
1583
+ this.size--;
1584
+ return item;
1585
+ }
1586
+ peek() {
1587
+ if (this.size === 0) {
1588
+ return null;
1589
+ }
1590
+ const lastIndex = (this.head - 1 + this.capacity) % this.capacity;
1591
+ return this.buffer[lastIndex];
1592
+ }
1593
+ isEmpty() {
1594
+ return this.size === 0;
1595
+ }
1596
+ clear() {
1597
+ this.buffer.fill(null);
1598
+ this.head = 0;
1599
+ this.tail = 0;
1600
+ this.size = 0;
1601
+ }
1602
+ }
1603
+
1604
+ class KritzelHistory {
1605
+ constructor(store) {
1606
+ this._store = store;
1607
+ this.undoStack = new KritzelCircularBuffer(this._store.state.historyBufferSize);
1608
+ this.redoStack = new KritzelCircularBuffer(this._store.state.historyBufferSize);
1609
+ this.previousViewport = {
1610
+ scale: this._store.state.scale,
1611
+ scaleStep: this._store.state.scaleStep,
1612
+ translateX: this._store.state.translateX,
1613
+ translateY: this._store.state.translateY,
1614
+ };
1615
+ }
1616
+ reset() {
1617
+ this.undoStack.clear();
1618
+ this.redoStack.clear();
1619
+ this.previousViewport = {
1620
+ scale: this._store.state.scale,
1621
+ scaleStep: this._store.state.scaleStep,
1622
+ translateX: this._store.state.translateX,
1623
+ translateY: this._store.state.translateY
1624
+ };
1625
+ }
1626
+ executeCommand(command) {
1627
+ if (this._store.state.hasViewportChanged) {
1628
+ this.addUpdateViewportCommand();
1629
+ }
1630
+ command.execute();
1631
+ if (command.skipHistory === false) {
1632
+ if (this._store.state.debugInfo.logCommands) {
1633
+ console.info('add', command);
1634
+ }
1635
+ this.undoStack.add(command);
1636
+ if (this.redoStack.isEmpty() === false) {
1637
+ this.redoStack.clear();
1638
+ }
1639
+ }
1640
+ this._store.rerender();
1641
+ }
1642
+ undo() {
1643
+ if (this._store.state.hasViewportChanged) {
1644
+ const command = new UpdateViewportCommand(this._store, this, this.previousViewport);
1645
+ command.undo();
1646
+ this._store.state.hasViewportChanged = false;
1647
+ this._store.rerender();
1648
+ return;
1649
+ }
1650
+ const command = this.undoStack.pop();
1651
+ if (command) {
1652
+ command.undo();
1653
+ if (this._store.state.debugInfo.logCommands)
1654
+ console.info('undo', command);
1655
+ this.redoStack.add(command);
1656
+ }
1657
+ this._store.rerender();
1658
+ }
1659
+ redo() {
1660
+ const command = this.redoStack.pop();
1661
+ if (command) {
1662
+ command.execute();
1663
+ if (this._store.state.debugInfo.logCommands)
1664
+ console.info('redo', command);
1665
+ this.undoStack.add(command);
1666
+ }
1667
+ this._store.rerender();
1668
+ }
1669
+ addUpdateViewportCommand() {
1670
+ const command = new UpdateViewportCommand(this._store, this, this.previousViewport);
1671
+ command.execute();
1672
+ this.undoStack.add(command);
1673
+ if (this.redoStack.isEmpty() === false) {
1674
+ this.redoStack.clear();
1675
+ }
1676
+ this._store.state.hasViewportChanged = false;
1677
+ this.previousViewport = {
1678
+ scale: this._store.state.scale,
1679
+ scaleStep: this._store.state.scaleStep,
1680
+ translateX: this._store.state.translateX,
1681
+ translateY: this._store.state.translateY,
1682
+ };
1683
+ }
1684
+ }
1685
+
1686
+ class KritzelOctree {
1687
+ constructor(bounds, capacity = 8) {
1688
+ this.objects = [];
1689
+ this.children = null;
1690
+ this.bounds = bounds;
1691
+ this.capacity = capacity;
1692
+ }
1693
+ reset() {
1694
+ this.objects = [];
1695
+ this.children = null;
1696
+ }
1697
+ insert(object) {
1698
+ if (!this.intersects(object.rotatedBoundingBox, this.bounds)) {
1699
+ return false;
1700
+ }
1701
+ if (this.objects.length < this.capacity && this.children === null) {
1702
+ this.objects.push(object);
1703
+ return true;
1704
+ }
1705
+ if (this.children === null) {
1706
+ this.subdivide();
1707
+ }
1708
+ for (const child of this.children) {
1709
+ if (child.insert(object)) {
1710
+ return true;
1711
+ }
1712
+ }
1713
+ return false;
1714
+ }
1715
+ update(object) {
1716
+ const index = this.objects.findIndex(o => o.id === object.id);
1717
+ if (index !== -1) {
1718
+ this.objects[index] = object;
1719
+ return true;
1720
+ }
1721
+ if (this.children !== null) {
1722
+ for (const child of this.children) {
1723
+ if (child.update(object)) {
1724
+ return true;
1725
+ }
1726
+ }
1727
+ }
1728
+ return false;
1729
+ }
1730
+ remove(predicate) {
1731
+ const index = this.objects.findIndex(o => predicate(o));
1732
+ if (index !== -1) {
1733
+ this.objects.splice(index, 1);
1734
+ }
1735
+ if (this.children !== null) {
1736
+ for (const child of this.children) {
1737
+ child.remove(predicate);
1738
+ }
1739
+ }
1740
+ }
1741
+ query(range) {
1742
+ const results = [];
1743
+ if (!this.intersects(range, this.bounds)) {
1744
+ return results;
1745
+ }
1746
+ for (const object of this.objects) {
1747
+ if (this.intersects(object.rotatedBoundingBox, range)) {
1748
+ results.push(object);
1749
+ }
1750
+ }
1751
+ if (this.children !== null) {
1752
+ for (const child of this.children) {
1753
+ results.push(...child.query(range));
1754
+ }
1755
+ }
1756
+ return results;
1757
+ }
1758
+ filter(predicate) {
1759
+ const results = this.objects.filter(o => predicate(o));
1760
+ if (this.children !== null) {
1761
+ for (const child of this.children) {
1762
+ results.push(...child.filter(predicate));
1763
+ }
1764
+ }
1765
+ return results;
1766
+ }
1767
+ allObjects() {
1768
+ const results = [...this.objects];
1769
+ if (this.children !== null) {
1770
+ for (const child of this.children) {
1771
+ results.push(...child.allObjects());
1772
+ }
1773
+ }
1774
+ return results;
1775
+ }
1776
+ subdivide() {
1777
+ const { x, y, z, width, height, depth } = this.bounds;
1778
+ const halfWidth = width / 2;
1779
+ const halfHeight = height / 2;
1780
+ const halfDepth = depth / 2;
1781
+ this.children = [
1782
+ new KritzelOctree({ x, y, z, width: halfWidth, height: halfHeight, depth: halfDepth }, this.capacity),
1783
+ new KritzelOctree({ x: x + halfWidth, y, z, width: halfWidth, height: halfHeight, depth: halfDepth }, this.capacity),
1784
+ new KritzelOctree({ x, y: y + halfHeight, z, width: halfWidth, height: halfHeight, depth: halfDepth }, this.capacity),
1785
+ new KritzelOctree({ x: x + halfWidth, y: y + halfHeight, z, width: halfWidth, height: halfHeight, depth: halfDepth }, this.capacity),
1786
+ new KritzelOctree({ x, y, z: z + halfDepth, width: halfWidth, height: halfHeight, depth: halfDepth }, this.capacity),
1787
+ new KritzelOctree({ x: x + halfWidth, y, z: z + halfDepth, width: halfWidth, height: halfHeight, depth: halfDepth }, this.capacity),
1788
+ new KritzelOctree({ x, y: y + halfHeight, z: z + halfDepth, width: halfWidth, height: halfHeight, depth: halfDepth }, this.capacity),
1789
+ new KritzelOctree({ x: x + halfWidth, y: y + halfHeight, z: z + halfDepth, width: halfWidth, height: halfHeight, depth: halfDepth }, this.capacity),
1790
+ ];
1791
+ }
1792
+ intersects(a, b) {
1793
+ return !(a.x >= b.x + b.width || // a is completely to the right of b
1794
+ a.x + a.width <= b.x || // a is completely to the left of b
1795
+ a.y >= b.y + b.height || // a is completely below b
1796
+ a.y + a.height <= b.y // a is completely above b
1797
+ );
1798
+ }
1799
+ }
1800
+
1801
+ const DEFAULT_ENGINE_STATE = {
1802
+ activeWorkspace: null,
1803
+ activeTool: null,
1804
+ activeText: null,
1805
+ currentPath: null,
1806
+ copiedObjects: null,
1807
+ objectsOctree: null,
1808
+ selectionBox: null,
1809
+ selectionGroup: null,
1810
+ resizeHandleType: null,
1811
+ hasViewportChanged: false,
1812
+ isReady: false,
1813
+ isEnabled: true,
1814
+ isScaling: false,
1815
+ isPanning: false,
1816
+ isFocused: false,
1817
+ isSelecting: false,
1818
+ isResizing: false,
1819
+ isResizeHandleSelected: false,
1820
+ isRotating: false,
1821
+ isRotationHandleSelected: false,
1822
+ isDragging: false,
1823
+ isDrawing: false,
1824
+ isErasing: false,
1825
+ isWriting: false,
1826
+ isCtrlKeyPressed: false,
1827
+ isContextMenuVisible: false,
1828
+ contextMenuItems: [],
1829
+ contextMenuX: 0,
1830
+ contextMenuY: 0,
1831
+ skipContextMenu: false,
1832
+ debugInfo: {
1833
+ showObjectInfo: false,
1834
+ showViewportInfo: false,
1835
+ logCommands: false,
1836
+ logDatabase: false,
1837
+ },
1838
+ host: null,
1839
+ pointerX: 0,
1840
+ pointerY: 0,
1841
+ scale: 1,
1842
+ scaleMax: 1,
1843
+ scaleMin: 1,
1844
+ scaleStep: 0.075,
1845
+ startX: 0,
1846
+ startY: 0,
1847
+ translateX: 0,
1848
+ translateXMax: 400,
1849
+ translateXMin: 0,
1850
+ translateY: 0,
1851
+ translateYMax: 400,
1852
+ translateYMin: 0,
1853
+ viewportWidth: 0,
1854
+ viewportHeight: 0,
1855
+ historyBufferSize: 1000,
1856
+ longTouchTimeout: null,
1857
+ longTouchDelay: 300,
1858
+ pointers: new Map(),
1859
+ workspaces: [],
1860
+ };
1861
+
1862
+ class KritzelDatabase {
1863
+ constructor(dbName, dbVersion, isLoggingEnabled = false) {
1864
+ this.db = null;
1865
+ this.dbName = dbName;
1866
+ this.dbVersion = dbVersion;
1867
+ this.isLoggingEnabled = isLoggingEnabled;
1868
+ }
1869
+ async open(stores) {
1870
+ return new Promise((resolve, reject) => {
1871
+ if (this.db) {
1872
+ resolve();
1873
+ return;
1874
+ }
1875
+ if (this.isLoggingEnabled) {
1876
+ console.log(`[IndexedDB] Opening database: ${this.dbName}, version: ${this.dbVersion}`);
1877
+ }
1878
+ const request = indexedDB.open(this.dbName, this.dbVersion);
1879
+ request.onerror = () => {
1880
+ console.error('IndexedDB error:', request.error);
1881
+ reject(request.error);
1882
+ };
1883
+ request.onsuccess = () => {
1884
+ this.db = request.result;
1885
+ if (this.isLoggingEnabled) {
1886
+ console.log(`[IndexedDB] Database opened successfully.`);
1887
+ }
1888
+ resolve();
1889
+ };
1890
+ request.onupgradeneeded = event => {
1891
+ if (this.isLoggingEnabled) {
1892
+ console.log(`[IndexedDB] Upgrade needed for database: ${this.dbName}`);
1893
+ }
1894
+ const db = event.target.result;
1895
+ stores.forEach(storeConfig => {
1896
+ if (!db.objectStoreNames.contains(storeConfig.name)) {
1897
+ if (this.isLoggingEnabled) {
1898
+ console.log(`[IndexedDB] Creating store: ${storeConfig.name}`);
1899
+ }
1900
+ const store = db.createObjectStore(storeConfig.name, storeConfig.options);
1901
+ if (storeConfig.indices) {
1902
+ storeConfig.indices.forEach(index => {
1903
+ if (this.isLoggingEnabled) {
1904
+ console.log(`[IndexedDB] Creating index: ${index.name} on store: ${storeConfig.name}`);
1905
+ }
1906
+ store.createIndex(index.name, index.keyPath, index.options);
1907
+ });
1908
+ }
1909
+ }
1910
+ });
1911
+ };
1912
+ });
1913
+ }
1914
+ close() {
1915
+ if (this.db) {
1916
+ if (this.isLoggingEnabled) {
1917
+ console.log(`[IndexedDB] Closing database: ${this.dbName}`);
1918
+ }
1919
+ this.db.close();
1920
+ this.db = null;
1921
+ }
1922
+ }
1923
+ async add(storeName, item) {
1924
+ if (this.isLoggingEnabled) {
1925
+ console.log('[IndexedDB] Add:', { storeName, item });
1926
+ }
1927
+ return this.executeTransaction(storeName, 'readwrite', store => store.add(item));
1928
+ }
1929
+ async get(storeName, key) {
1930
+ if (this.isLoggingEnabled) {
1931
+ console.log('[IndexedDB] Get:', { storeName, key });
1932
+ }
1933
+ return this.executeTransaction(storeName, 'readonly', store => store.get(key));
1934
+ }
1935
+ async getAll(storeName) {
1936
+ if (this.isLoggingEnabled) {
1937
+ console.log('[IndexedDB] GetAll:', { storeName });
1938
+ }
1939
+ return this.executeTransaction(storeName, 'readonly', store => store.getAll());
1940
+ }
1941
+ async update(storeName, item) {
1942
+ if (this.isLoggingEnabled) {
1943
+ console.log('[IndexedDB] Update:', { storeName, item });
1944
+ }
1945
+ return this.executeTransaction(storeName, 'readwrite', store => store.put(item));
1946
+ }
1947
+ async delete(storeName, key) {
1948
+ if (this.isLoggingEnabled) {
1949
+ console.log('[IndexedDB] Delete:', { storeName, key });
1950
+ }
1951
+ return this.executeTransaction(storeName, 'readwrite', store => store.delete(key));
1952
+ }
1953
+ async deleteByRange(storeName, range) {
1954
+ if (this.isLoggingEnabled) {
1955
+ console.log('[IndexedDB] DeleteByRange:', { storeName, range });
1956
+ }
1957
+ return this.executeTransaction(storeName, 'readwrite', store => store.delete(range));
1958
+ }
1959
+ async getAllByRange(storeName, range) {
1960
+ if (this.isLoggingEnabled) {
1961
+ console.log('[IndexedDB] GetAllByRange:', { storeName, range });
1962
+ }
1963
+ return this.executeTransaction(storeName, 'readonly', store => {
1964
+ return store.getAll(range);
1965
+ });
1966
+ }
1967
+ async getAllByIndex(storeName, indexName, query) {
1968
+ if (this.isLoggingEnabled) {
1969
+ console.log('[IndexedDB] GetAllByIndex:', { storeName, indexName, query });
1970
+ }
1971
+ return this.executeTransaction(storeName, 'readonly', store => {
1972
+ const index = store.index(indexName);
1973
+ return index.getAll(query);
1974
+ });
1975
+ }
1976
+ async executeTransaction(storeName, mode, action) {
1977
+ if (!this.db) {
1978
+ throw new Error('Database is not open.');
1979
+ }
1980
+ return new Promise((resolve, reject) => {
1981
+ const transaction = this.db.transaction(storeName, mode);
1982
+ const store = transaction.objectStore(storeName);
1983
+ const request = action(store);
1984
+ let requestResult;
1985
+ transaction.oncomplete = () => {
1986
+ resolve(requestResult);
1987
+ };
1988
+ transaction.onabort = () => {
1989
+ var _a;
1990
+ reject((_a = transaction.error) !== null && _a !== void 0 ? _a : new Error('Transaction aborted'));
1991
+ };
1992
+ transaction.onerror = () => {
1993
+ reject(transaction.error);
1994
+ };
1995
+ request.onsuccess = () => {
1996
+ requestResult = request.result;
1997
+ };
1998
+ });
1999
+ }
2000
+ async batch(actions) {
2001
+ if (!this.db) {
2002
+ throw new Error('Database is not open.');
2003
+ }
2004
+ const storeNames = await this.extractStoreNamesFromActions(actions);
2005
+ if (this.isLoggingEnabled) {
2006
+ console.log('[IndexedDB] Starting batch transaction:', { storeNames });
2007
+ }
2008
+ return new Promise((resolve, reject) => {
2009
+ const transaction = this.db.transaction(storeNames, 'readwrite');
2010
+ const results = [];
2011
+ const promises = [];
2012
+ const tempDbInstance = {
2013
+ add: (storeName, item) => this.add(storeName, item),
2014
+ get: (storeName, key) => this.get(storeName, key),
2015
+ getAll: (storeName) => this.getAll(storeName),
2016
+ update: (storeName, item) => this.update(storeName, item),
2017
+ delete: (storeName, key) => this.delete(storeName, key),
2018
+ deleteByRange: (storeName, range) => this.deleteByRange(storeName, range),
2019
+ getAllByRange: (storeName, range) => this.getAllByRange(storeName, range),
2020
+ getAllByIndex: (storeName, indexName, query) => this.getAllByIndex(storeName, indexName, query),
2021
+ executeTransaction: (storeName, mode, action) => {
2022
+ return new Promise((resolveRequest, rejectRequest) => {
2023
+ if (this.isLoggingEnabled) {
2024
+ console.log('[IndexedDB] Executing batch action:', { storeName, mode });
2025
+ }
2026
+ const store = transaction.objectStore(storeName);
2027
+ const request = action(store);
2028
+ request.onsuccess = () => {
2029
+ if (this.isLoggingEnabled) {
2030
+ console.log('[IndexedDB] Batch action request successful:', { result: request.result });
2031
+ }
2032
+ resolveRequest(request.result);
2033
+ };
2034
+ request.onerror = () => {
2035
+ console.error('[IndexedDB] Batch action request error:', request.error);
2036
+ rejectRequest(request.error);
2037
+ };
2038
+ });
2039
+ },
2040
+ };
2041
+ transaction.oncomplete = () => {
2042
+ if (this.isLoggingEnabled) {
2043
+ console.log('[IndexedDB] Batch transaction complete.');
2044
+ }
2045
+ Promise.all(promises).then(() => resolve(results));
2046
+ };
2047
+ transaction.onabort = () => {
2048
+ var _a;
2049
+ console.error('[IndexedDB] Batch transaction aborted:', transaction.error);
2050
+ reject((_a = transaction.error) !== null && _a !== void 0 ? _a : new Error('Transaction aborted'));
2051
+ };
2052
+ transaction.onerror = () => {
2053
+ console.error('[IndexedDB] Batch transaction error:', transaction.error);
2054
+ reject(transaction.error);
2055
+ };
2056
+ actions.forEach((action, index) => {
2057
+ const promise = action(tempDbInstance)
2058
+ .then(result => {
2059
+ results[index] = result;
2060
+ })
2061
+ .catch(err => {
2062
+ if (!transaction.error) {
2063
+ transaction.abort();
2064
+ }
2065
+ reject(err);
2066
+ });
2067
+ promises.push(promise);
2068
+ });
2069
+ });
2070
+ }
2071
+ async extractStoreNamesFromActions(actions) {
2072
+ const storeNamesSet = new Set();
2073
+ const storeNameCollector = new Proxy(this, {
2074
+ get: (target, prop) => {
2075
+ if (['add', 'get', 'getAll', 'update', 'delete', 'deleteByRange', 'getAllByRange', 'getAllByIndex'].includes(prop)) {
2076
+ return (storeName) => {
2077
+ storeNamesSet.add(storeName);
2078
+ return Promise.resolve();
2079
+ };
2080
+ }
2081
+ return target[prop];
2082
+ },
2083
+ });
2084
+ await Promise.all(actions.map(action => action(storeNameCollector)));
2085
+ return Array.from(storeNamesSet);
2086
+ }
2087
+ }
2088
+
2089
+ class KritzelStore {
2090
+ get history() {
2091
+ return this._history;
2092
+ }
2093
+ get database() {
2094
+ return this._database;
2095
+ }
2096
+ get state() {
2097
+ return this._state;
2098
+ }
2099
+ get currentZIndex() {
2100
+ return this._state.objectsOctree.filter(o => !(o instanceof KritzelSelectionGroup) && !(o instanceof KrtizelSelectionBox)).length;
2101
+ }
2102
+ get allObjects() {
2103
+ return this._state.objectsOctree.allObjects();
2104
+ }
2105
+ get selectedObjects() {
2106
+ return this.allObjects.filter(o => !(o instanceof KritzelSelectionGroup)).filter(o => o.isSelected);
2107
+ }
2108
+ get offsetX() {
2109
+ return this._state.host.getBoundingClientRect().left;
2110
+ }
2111
+ get offsetY() {
2112
+ return this._state.host.getBoundingClientRect().top;
2113
+ }
2114
+ get isDisabled() {
2115
+ return this._state.isEnabled === false || this._state.isReady === false || this._state.activeWorkspace === null;
2116
+ }
2117
+ constructor(kritzelEngine) {
2118
+ this._listeners = new Map();
2119
+ this.objects = [];
2120
+ this._state = DEFAULT_ENGINE_STATE;
2121
+ this._kritzelEngine = kritzelEngine;
2122
+ this._history = new KritzelHistory(this);
2123
+ this._database = new KritzelDatabase('kritzelDB', 1, this._state.debugInfo.logDatabase);
2124
+ this._state.objectsOctree = new KritzelOctree({
2125
+ x: -Infinity,
2126
+ y: -Infinity,
2127
+ z: -Infinity,
2128
+ width: Infinity,
2129
+ height: Infinity,
2130
+ depth: Infinity,
2131
+ });
2132
+ }
2133
+ async initializeDatabase() {
2134
+ await this._database.open([
2135
+ {
2136
+ name: 'objects',
2137
+ options: { keyPath: ['workspaceId', 'id'] },
2138
+ },
2139
+ { name: 'workspaces', options: { keyPath: 'id' } },
2140
+ ]);
2141
+ this.rerender();
2142
+ }
2143
+ async initializeWorkspace(workspace) {
2144
+ var _a;
2145
+ const workspaces = await this.getWorkspaces();
2146
+ const mostRecentWorkspace = [...workspaces].sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime())[0];
2147
+ const fallbackWorkspace = new KritzelWorkspace(ObjectHelper.generateUUID(), 'New Workspace');
2148
+ this._state.activeWorkspace = (_a = workspace !== null && workspace !== void 0 ? workspace : mostRecentWorkspace) !== null && _a !== void 0 ? _a : fallbackWorkspace;
2149
+ const isExistingWorkspace = await this.getWorkspace(this._state.activeWorkspace.id);
2150
+ if (isExistingWorkspace) {
2151
+ await this.updateWorkspace(this._state.activeWorkspace);
2152
+ }
2153
+ else {
2154
+ await this.createWorkspace(this._state.activeWorkspace);
2155
+ }
2156
+ this._state.workspaces = await this.getWorkspaces();
2157
+ this.state.translateX = this._state.activeWorkspace.viewport.translateX;
2158
+ this.state.translateY = this._state.activeWorkspace.viewport.translateY;
2159
+ this.state.scale = this._state.activeWorkspace.viewport.scale;
2160
+ await this.initializeWorkspaceObjects(this._state.activeWorkspace.id);
2161
+ }
2162
+ async initializeWorkspaceObjects(workspaceId) {
2163
+ this._state.objectsOctree.reset();
2164
+ this._history.reset();
2165
+ const objectsFromDb = await this._database.getAllByRange('objects', IDBKeyRange.bound([workspaceId], [workspaceId, '\uffff']));
2166
+ const reviver = new KritzelReviver(this);
2167
+ objectsFromDb.forEach(element => {
2168
+ const revivedObject = reviver.revive(element);
2169
+ this._state.objectsOctree.insert(revivedObject);
2170
+ });
2171
+ this.rerender();
2172
+ }
2173
+ async updateWorkspaceViewport(translateX, translateY, scale) {
2174
+ if (!this.state.activeWorkspace) {
2175
+ throw new Error('Workspace not initialized');
2176
+ }
2177
+ this.state.activeWorkspace.viewport = {
2178
+ translateX,
2179
+ translateY,
2180
+ scale,
2181
+ };
2182
+ this.state.activeWorkspace.updatedAt = new Date();
2183
+ await this._database.update('workspaces', this.state.activeWorkspace);
2184
+ }
2185
+ async addObjectToDatabase(object) {
2186
+ if (!this._database) {
2187
+ throw new Error('Database not initialized');
2188
+ }
2189
+ if (!this.state.activeWorkspace) {
2190
+ throw new Error('Workspace not initialized');
2191
+ }
2192
+ this.state.activeWorkspace.updatedAt = new Date();
2193
+ await this._database.batch([db => db.add('objects', object), db => db.update('workspaces', this.state.activeWorkspace)]).catch(err => {
2194
+ console.error('Error adding object to database:', err);
2195
+ });
2196
+ }
2197
+ async updateObjectInDatabase(object) {
2198
+ if (!this._database) {
2199
+ throw new Error('Database not initialized');
2200
+ }
2201
+ if (!this.state.activeWorkspace) {
2202
+ throw new Error('Workspace not initialized');
2203
+ }
2204
+ this.state.activeWorkspace.updatedAt = new Date();
2205
+ await this._database.batch([db => db.update('objects', object), db => db.update('workspaces', this.state.activeWorkspace)]).catch(err => {
2206
+ console.error('Error updating object in database:', err);
2207
+ });
2208
+ }
2209
+ async deleteObjectFromDatabase(objectId) {
2210
+ if (!this._database) {
2211
+ throw new Error('Database not initialized');
2212
+ }
2213
+ if (!this.state.activeWorkspace) {
2214
+ throw new Error('Workspace not initialized');
2215
+ }
2216
+ this.state.activeWorkspace.updatedAt = new Date();
2217
+ await this._database.batch([db => db.delete('objects', [this.state.activeWorkspace.id, objectId]), db => db.update('workspaces', this.state.activeWorkspace)]).catch(err => {
2218
+ console.error('Error deleting object from database:', err);
2219
+ });
2220
+ }
2221
+ getWorkspace(id) {
2222
+ if (!this._database) {
2223
+ throw new Error('Database not initialized');
2224
+ }
2225
+ return this._database.get('workspaces', id);
2226
+ }
2227
+ getWorkspaces() {
2228
+ if (!this._database) {
2229
+ throw new Error('Database not initialized');
2230
+ }
2231
+ return this._database.getAll('workspaces');
2232
+ }
2233
+ async createWorkspace(workspace) {
2234
+ if (!this._database) {
2235
+ throw new Error('Database not initialized');
2236
+ }
2237
+ workspace.createdAt = new Date();
2238
+ workspace.updatedAt = new Date();
2239
+ await this._database.add('workspaces', workspace);
2240
+ this.state.workspaces.push(workspace);
2241
+ }
2242
+ async updateWorkspace(workspace) {
2243
+ if (!this._database) {
2244
+ throw new Error('Database not initialized');
2245
+ }
2246
+ workspace.updatedAt = new Date();
2247
+ await this._database.update('workspaces', workspace);
2248
+ const index = this.state.workspaces.findIndex(w => w.id === workspace.id);
2249
+ if (index !== -1) {
2250
+ this.state.workspaces[index] = workspace;
2251
+ }
2252
+ }
2253
+ async deleteWorkspace(workspace) {
2254
+ if (!this._database) {
2255
+ throw new Error('Database not initialized');
2256
+ }
2257
+ const objectRange = IDBKeyRange.bound([workspace.id], [workspace.id, '\uffff']);
2258
+ await this._database.deleteByRange('objects', objectRange);
2259
+ await this._database.delete('workspaces', workspace.id);
2260
+ }
2261
+ rerender() {
2262
+ if (this._kritzelEngine) {
2263
+ this._kritzelEngine.forceUpdate++;
2264
+ }
2265
+ }
2266
+ findObjectById(id) {
2267
+ for (const object of this.allObjects) {
2268
+ if (object.id === id) {
2269
+ return object;
2270
+ }
2271
+ }
2272
+ return null;
2273
+ }
2274
+ deselectAllObjects() {
2275
+ if (this._state.selectionGroup) {
2276
+ this._history.executeCommand(new RemoveSelectionGroupCommand(this, this));
2277
+ }
2278
+ }
2279
+ onStateChange(property, listener) {
2280
+ if (!this._listeners.has(property)) {
2281
+ this._listeners.set(property, new Set());
2282
+ }
2283
+ this._listeners.get(property).add(listener);
2284
+ }
2285
+ setState(property, value) {
2286
+ const oldValue = this._state[property];
2287
+ if (oldValue !== value) {
2288
+ this._state[property] = value;
2289
+ if (this._listeners.has(property)) {
2290
+ this._listeners.get(property).forEach(listener => listener(value, oldValue, String(property)));
2291
+ }
2292
+ }
2293
+ }
2294
+ delete() {
2295
+ if (!this.state.selectionGroup) {
2296
+ return;
2297
+ }
2298
+ const deleteSelectedObjectsCommand = this.state.selectionGroup.objects.map(obj => new RemoveObjectCommand(this, this.state.selectionGroup, obj));
2299
+ const removeSelectionGroupCommand = new RemoveSelectionGroupCommand(this, this.state.selectionGroup);
2300
+ const commands = [...deleteSelectedObjectsCommand, removeSelectionGroupCommand];
2301
+ this.history.executeCommand(new BatchCommand(this, this.state.selectionGroup, commands));
2302
+ }
2303
+ deleteObject(id, skipHistory = false) {
2304
+ const object = this.findObjectById(id);
2305
+ if (object) {
2306
+ const removeObjectCommand = new RemoveObjectCommand(this, this, object, skipHistory);
2307
+ this.history.executeCommand(removeObjectCommand);
2308
+ }
2309
+ }
2310
+ copy() {
2311
+ this.state.copiedObjects = this.state.selectionGroup.copy();
2312
+ }
2313
+ paste(x, y) {
2314
+ this.state.copiedObjects.isSelected = true;
2315
+ const adjustedX = x !== undefined ? x : this.state.copiedObjects.translateX + 25;
2316
+ const adjustedY = y !== undefined ? y : this.state.copiedObjects.translateY + 25;
2317
+ this.state.copiedObjects.updatePosition(adjustedX, adjustedY);
2318
+ const commands = [];
2319
+ if (this.state.selectionGroup !== null) {
2320
+ commands.push(new RemoveSelectionGroupCommand(this, this.state.selectionGroup));
2321
+ }
2322
+ const addCopiedObjectsCommands = this.state.copiedObjects.objects.map(obj => new AddObjectCommand(this, this, obj));
2323
+ const addCopiedObjectsAsSelectionGroupCommand = new AddSelectionGroupCommand(this, this, this.state.copiedObjects);
2324
+ commands.push(...addCopiedObjectsCommands, addCopiedObjectsAsSelectionGroupCommand);
2325
+ this.history.executeCommand(new BatchCommand(this, this, commands));
2326
+ this.state.isSelecting = false;
2327
+ this.state.copiedObjects = this.state.selectionGroup.copy();
2328
+ this.setState('activeTool', KritzelToolRegistry.getTool('selection'));
2329
+ }
2330
+ bringForward(object) {
2331
+ const max = this.allObjects.length + 1;
2332
+ const objects = object ? [object] : this.state.selectionGroup.objects;
2333
+ const increaseZIndexCommands = objects.map(obj => {
2334
+ if (obj.zIndex === max) {
2335
+ return;
2336
+ }
2337
+ return new UpdateObjectCommand(this, this, obj, { zIndex: obj.zIndex + 1 });
2338
+ });
2339
+ this.history.executeCommand(new BatchCommand(this, this, increaseZIndexCommands));
2340
+ }
2341
+ sendBackward(object) {
2342
+ const min = 0;
2343
+ const objects = object ? [object] : this.state.selectionGroup.objects;
2344
+ const decreaseZIndexCommands = objects.map(obj => {
2345
+ if (obj.zIndex === min) {
2346
+ return;
2347
+ }
2348
+ return new UpdateObjectCommand(this, this, obj, { zIndex: obj.zIndex - 1 });
2349
+ });
2350
+ this.history.executeCommand(new BatchCommand(this, this, decreaseZIndexCommands));
2351
+ }
2352
+ bringToFront(object) {
2353
+ const max = Math.max(...this.allObjects.map(obj => obj.zIndex)) + 1;
2354
+ const objects = object ? [object] : this.state.selectionGroup.objects;
2355
+ const increaseZIndexCommands = objects.map(obj => {
2356
+ return new UpdateObjectCommand(this, this, obj, { zIndex: max });
2357
+ });
2358
+ this.history.executeCommand(new BatchCommand(this, this, increaseZIndexCommands));
2359
+ }
2360
+ sendToBack(object) {
2361
+ const min = Math.min(...this.allObjects.map(obj => obj.zIndex)) - 1;
2362
+ const objects = object ? [object] : this.state.selectionGroup.objects;
2363
+ const decreaseZIndexCommands = objects.map(obj => {
2364
+ return new UpdateObjectCommand(this, this, obj, { zIndex: min });
2365
+ });
2366
+ this.history.executeCommand(new BatchCommand(this, this, decreaseZIndexCommands));
2367
+ }
2368
+ selectObjects(objects) {
2369
+ if (objects.length === 0) {
2370
+ return;
2371
+ }
2372
+ const selectionGroup = KritzelSelectionGroup.create(this);
2373
+ objects.forEach(obj => {
2374
+ obj.isSelected = false;
2375
+ selectionGroup.addOrRemove(obj);
2376
+ });
2377
+ selectionGroup.isSelected = true;
2378
+ this.state.selectionGroup = selectionGroup;
2379
+ if (objects.length === 1) {
2380
+ selectionGroup.rotation = selectionGroup.objects[0].rotation;
2381
+ }
2382
+ this.history.executeCommand(new AddSelectionGroupCommand(this, this, selectionGroup));
2383
+ }
2384
+ selectAllObjectsInViewport() {
2385
+ const objectsInViewport = this._state.objectsOctree
2386
+ .query({
2387
+ x: -this._state.translateX / this._state.scale,
2388
+ y: -this._state.translateY / this._state.scale,
2389
+ z: this._state.scale,
2390
+ width: this._state.viewportWidth / this._state.scale,
2391
+ height: this._state.viewportHeight / this._state.scale,
2392
+ depth: 100,
2393
+ })
2394
+ .filter(o => !(o instanceof KritzelSelectionGroup) && !(o instanceof KrtizelSelectionBox) && !(o instanceof KritzelContextMenu));
2395
+ if (objectsInViewport.length > 0) {
2396
+ const selectionGroup = KritzelSelectionGroup.create(this);
2397
+ objectsInViewport.forEach(obj => {
2398
+ obj.isSelected = false;
2399
+ selectionGroup.addOrRemove(obj);
2400
+ });
2401
+ selectionGroup.isSelected = true;
2402
+ this.state.isSelecting = false;
2403
+ if (objectsInViewport.length === 1) {
2404
+ selectionGroup.rotation = selectionGroup.objects[0].rotation;
2405
+ }
2406
+ this.history.executeCommand(new AddSelectionGroupCommand(this, this, selectionGroup));
2407
+ this.setState('activeTool', KritzelToolRegistry.getTool('selection'));
2408
+ }
2409
+ }
2410
+ clearSelection() {
2411
+ const command = new RemoveSelectionGroupCommand(this, this.state.selectionGroup);
2412
+ this.history.executeCommand(command);
2413
+ this.state.selectionGroup = null;
2414
+ this.state.selectionBox = null;
2415
+ this.state.isSelecting = false;
2416
+ this.state.isResizeHandleSelected = false;
2417
+ this.state.isRotationHandleSelected = false;
2418
+ }
2419
+ resetActiveText() {
2420
+ if (this.state.activeText && this.state.activeText.value === ' ') {
2421
+ this.deleteObject(this.state.activeText.id, true);
2422
+ }
2423
+ this.state.activeText = null;
2424
+ }
2425
+ getObjectFromPointerEvent(event, selector = '.object') {
2426
+ var _a;
2427
+ const shadowRoot = (_a = this.state.host) === null || _a === void 0 ? void 0 : _a.shadowRoot;
2428
+ if (!shadowRoot)
2429
+ return null;
2430
+ const clientX = event.clientX;
2431
+ const clientY = event.clientY;
2432
+ const elementAtPoint = shadowRoot.elementFromPoint(clientX, clientY);
2433
+ if (!elementAtPoint)
2434
+ return null;
2435
+ const selectedObject = elementAtPoint.closest(selector);
2436
+ if (selectedObject) {
2437
+ return this.allObjects.find(object => selectedObject.id === object.id);
2438
+ }
2439
+ return null;
2440
+ }
2441
+ getObjectsFromPointerEvent(event, selector = '.object') {
2442
+ var _a;
2443
+ const shadowRoot = (_a = this.state.host) === null || _a === void 0 ? void 0 : _a.shadowRoot;
2444
+ if (!shadowRoot)
2445
+ return [];
2446
+ const clientX = event.clientX;
2447
+ const clientY = event.clientY;
2448
+ const elementsAtPoint = shadowRoot.elementsFromPoint(clientX, clientY);
2449
+ if (!elementsAtPoint || elementsAtPoint.length === 0)
2450
+ return [];
2451
+ const objectIds = new Set();
2452
+ elementsAtPoint.forEach(element => {
2453
+ const selectedObject = element.closest(selector);
2454
+ if (selectedObject && selectedObject.id) {
2455
+ objectIds.add(selectedObject.id);
2456
+ }
2457
+ });
2458
+ if (objectIds.size > 0) {
2459
+ return this.allObjects.filter(object => objectIds.has(object.id)).sort((a, b) => b.zIndex - a.zIndex);
2460
+ }
2461
+ return [];
2462
+ }
2463
+ getCanvasPoint(event) {
2464
+ if (!this.state.host) {
2465
+ return { x: 0, y: 0 };
2466
+ }
2467
+ // Get the position of the kritzel-engine host element relative to the viewport
2468
+ const hostRect = this.state.host.getBoundingClientRect();
2469
+ // 1. Make the pointer coordinates relative to the host element
2470
+ const xRelativeToHost = event.clientX - hostRect.left;
2471
+ const yRelativeToHost = event.clientY - hostRect.top;
2472
+ // 2. Reverse the translation applied to the #origin div
2473
+ const xWithoutTranslate = xRelativeToHost - this.state.translateX;
2474
+ const yWithoutTranslate = yRelativeToHost - this.state.translateY;
2475
+ // 3. Reverse the scaling to get the final world coordinates
2476
+ const worldX = xWithoutTranslate / this.state.scale;
2477
+ const worldY = yWithoutTranslate / this.state.scale;
2478
+ return { x: worldX, y: worldY };
2479
+ }
2480
+ }
2481
+
2482
+ class KritzelKeyHandler extends KritzelBaseHandler {
2483
+ constructor(store) {
2484
+ super(store);
2485
+ }
2486
+ handleKeyDown(event) {
2487
+ if (this._store.state.isFocused === false) {
2488
+ return;
2489
+ }
2490
+ this._store.state.isCtrlKeyPressed = event.ctrlKey;
2491
+ if (this._store.state.isCtrlKeyPressed) {
2492
+ event.preventDefault();
2493
+ }
2494
+ if (event.key === 'Escape' && this._store.state.selectionGroup) {
2495
+ this._store.clearSelection();
2496
+ }
2497
+ if (event.key === 'Delete' && this._store.state.selectionGroup) {
2498
+ this._store.delete();
2499
+ }
2500
+ if (event.key === 'z' && event.ctrlKey) {
2501
+ this._store.history.undo();
2502
+ }
2503
+ if (event.key === 'y' && event.ctrlKey) {
2504
+ this._store.history.redo();
2505
+ }
2506
+ if (event.key === 's' && event.ctrlKey) {
2507
+ this._store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
2508
+ this._store.deselectAllObjects();
2509
+ }
2510
+ if (event.key === 'b' && event.ctrlKey) {
2511
+ this._store.setState('activeTool', KritzelToolRegistry.getTool('brush'));
2512
+ this._store.deselectAllObjects();
2513
+ }
2514
+ if (event.key === 'e' && event.ctrlKey) {
2515
+ this._store.setState('activeTool', KritzelToolRegistry.getTool('eraser'));
2516
+ this._store.deselectAllObjects();
2517
+ }
2518
+ if (event.key === 'i' && event.ctrlKey) {
2519
+ this._store.setState('activeTool', KritzelToolRegistry.getTool('image'));
2520
+ this._store.deselectAllObjects();
2521
+ }
2522
+ if (event.key === 'x' && event.ctrlKey) {
2523
+ this._store.setState('activeTool', KritzelToolRegistry.getTool('text'));
2524
+ this._store.deselectAllObjects();
2525
+ }
2526
+ if (event.key === 'c' && event.ctrlKey && this._store.state.selectionGroup) {
2527
+ this._store.copy();
2528
+ this._store.rerender();
2529
+ }
2530
+ if (event.key === 'v' && event.ctrlKey && this._store.state.copiedObjects) {
2531
+ this._store.paste();
2532
+ }
2533
+ if (event.key === '+' && event.ctrlKey && this._store.state.selectionGroup) {
2534
+ this._store.bringForward();
2535
+ }
2536
+ if (event.key === '-' && event.ctrlKey && this._store.state.selectionGroup) {
2537
+ this._store.sendBackward();
2538
+ }
2539
+ if (event.key === '*' && event.shiftKey && this._store.state.selectionGroup) {
2540
+ this._store.bringToFront();
2541
+ }
2542
+ if (event.key === '_' && event.shiftKey && this._store.state.selectionGroup) {
2543
+ this._store.sendToBack();
2544
+ }
2545
+ if (event.key === 'a' && event.ctrlKey && this._store.state.activeText) {
2546
+ this._store.state.activeText.selectAll();
2547
+ }
2548
+ if (event.key === 'v' && event.ctrlKey && this._store.state.activeText) {
2549
+ this._store.state.activeText.insertFromClipboard();
2550
+ }
2551
+ }
2552
+ handleKeyUp(event) {
2553
+ if (this._store.state.isFocused === false) {
2554
+ return;
2555
+ }
2556
+ this._store.state.isCtrlKeyPressed = event.ctrlKey;
2557
+ }
2558
+ }
2559
+
2560
+ class KritzelContextMenuHandler extends KritzelBaseHandler {
2561
+ constructor(store, globalContextMenuItems, objectContextMenuItems) {
2562
+ super(store);
2563
+ this.globalContextMenuItems = [];
2564
+ this.objectContextMenuItems = [];
2565
+ this.globalContextMenuItems = globalContextMenuItems;
2566
+ this.objectContextMenuItems = objectContextMenuItems;
2567
+ }
2568
+ handleContextMenu(event) {
2569
+ if (this._store.state.skipContextMenu) {
2570
+ this._store.state.skipContextMenu = false;
2571
+ return;
2572
+ }
2573
+ const selectedObject = this._store.getObjectFromPointerEvent(event, '.object');
2574
+ if (selectedObject && !(selectedObject instanceof KritzelSelectionGroup)) {
2575
+ this._store.state.selectionGroup = KritzelSelectionGroup.create(this._store);
2576
+ this._store.state.selectionGroup.addOrRemove(selectedObject);
2577
+ this._store.state.selectionGroup.isSelected = true;
2578
+ this._store.state.selectionGroup.rotation = selectedObject.rotation;
2579
+ this._store.state.isSelecting = false;
2580
+ this._store.history.executeCommand(new AddSelectionGroupCommand(this._store, this, this._store.state.selectionGroup));
2581
+ }
2582
+ this._store.state.contextMenuItems = this._store.state.selectionGroup ? this.objectContextMenuItems : this.globalContextMenuItems;
2583
+ let x = event.clientX - this._store.offsetX;
2584
+ let y = event.clientY - this._store.offsetY;
2585
+ const menuWidthEstimate = 150;
2586
+ const menuHeightEstimate = 200;
2587
+ const margin = 10;
2588
+ if (x + menuWidthEstimate > window.innerWidth - margin) {
2589
+ x = window.innerWidth - menuWidthEstimate - margin;
2590
+ }
2591
+ if (y + menuHeightEstimate > window.innerHeight - margin) {
2592
+ y = window.innerHeight - menuHeightEstimate - margin;
2593
+ }
2594
+ x = Math.max(margin, x);
2595
+ y = Math.max(margin, y);
2596
+ this._store.state.contextMenuX = x;
2597
+ this._store.state.contextMenuY = y;
2598
+ this._store.state.isContextMenuVisible = true;
2599
+ this._store.state.isEnabled = false;
2600
+ this._store.rerender();
2601
+ }
2602
+ }
2603
+
2604
+ class KritzelClassHelper {
2605
+ static isInstanceOf(object, className) {
2606
+ return !!object && object.__class__ === className;
2607
+ }
2608
+ }
2609
+
2610
+ const kritzelEngineCss = ":host{display:block;position:relative;height:100%;width:100%;overflow:hidden;background-color:var(--kritzel-engine-background-color, #ffffff)}:host,:host *{touch-action:none;user-select:none}.debug-panel{position:absolute;pointer-events:none;top:0;right:0}.origin{position:relative;top:0;left:0;height:0;width:0;pointer-events:none;-webkit-transform-origin:top left;-moz-transform-origin:top left;transform-origin:top left;overflow:visible}.object{overflow:visible}textarea{all:unset;box-sizing:border-box;outline:none !important;border:none !important;overflow:visible}.resize-handle-overlay.top-left,.resize-handle-overlay.bottom-right{cursor:nwse-resize}.resize-handle-overlay.top-right,.resize-handle-overlay.bottom-left{cursor:nesw-resize}.rotation-handle-overlay{cursor:grab}";
2611
+
2612
+ const KritzelEngine = /*@__PURE__*/ proxyCustomElement(class KritzelEngine extends H {
2613
+ onWorkspaceChange(newWorkspace) {
2614
+ if (newWorkspace) {
2615
+ this.store.initializeWorkspace(newWorkspace);
2616
+ }
2617
+ }
2618
+ validateScaleMax(newValue) {
2619
+ if (newValue > ABSOLUTE_SCALE_MAX) {
2620
+ console.warn(`scaleMax cannot be greater than ${ABSOLUTE_SCALE_MAX}.`);
2621
+ this.scaleMax = ABSOLUTE_SCALE_MAX;
2622
+ this.store.state.scaleMax = this.scaleMax;
2623
+ }
2624
+ else {
2625
+ this.store.state.scaleMax = newValue;
2626
+ }
2627
+ }
2628
+ validateScaleMin(newValue) {
2629
+ if (newValue < ABSOLUTE_SCALE_MIN) {
2630
+ console.warn(`scaleMin cannot be less than ${ABSOLUTE_SCALE_MIN}.`);
2631
+ this.scaleMin = ABSOLUTE_SCALE_MIN;
2632
+ this.store.state.scaleMin = this.scaleMin;
2633
+ }
2634
+ else {
2635
+ this.store.state.scaleMin = newValue;
2636
+ }
2637
+ }
2638
+ get isSelecting() {
2639
+ return this.store.state.activeTool instanceof KritzelSelectionTool && this.store.state.isSelecting;
2640
+ }
2641
+ get isSelectionActive() {
2642
+ return this.store.state.activeTool instanceof KritzelSelectionTool && this.store.state.selectionGroup !== null;
2643
+ }
2644
+ constructor(registerHost) {
2645
+ super();
2646
+ if (registerHost !== false) {
2647
+ this.__registerHost();
2648
+ }
2649
+ this.__attachShadow();
2650
+ this.isEngineReady = createEvent(this, "isEngineReady");
2651
+ this.activeToolChange = createEvent(this, "activeToolChange");
2652
+ this.workspacesChange = createEvent(this, "workspacesChange");
2653
+ this.scaleMax = ABSOLUTE_SCALE_MAX;
2654
+ this.scaleMin = ABSOLUTE_SCALE_MIN;
2655
+ this.forceUpdate = 0;
2656
+ this.contextMenuElement = null;
2657
+ this.store = new KritzelStore(this);
2658
+ }
2659
+ componentWillLoad() {
2660
+ this.validateScaleMax(this.scaleMax);
2661
+ this.validateScaleMin(this.scaleMin);
2662
+ }
2663
+ async componentDidLoad() {
2664
+ this.contextMenuHandler = new KritzelContextMenuHandler(this.store, this.globalContextMenuItems, this.objectContextMenuItems);
2665
+ this.keyHandler = new KritzelKeyHandler(this.store);
2666
+ this.viewport = new KritzelViewport(this.store, this.host);
2667
+ this._registerStateChangeListeners();
2668
+ await this.store.initializeDatabase();
2669
+ await this.store.initializeWorkspace(this.workspace);
2670
+ if (this.store.state.isReady === false) {
2671
+ this.store.state.isReady = true;
2672
+ this.isEngineReady.emit(this.store.state);
2673
+ }
2674
+ }
2675
+ handleWheel(ev) {
2676
+ var _a, _b;
2677
+ if (this.store.isDisabled) {
2678
+ return;
2679
+ }
2680
+ if (this.store.state.isContextMenuVisible) {
2681
+ this.hideContextMenu();
2682
+ }
2683
+ this.viewport.handleWheel(ev);
2684
+ (_b = (_a = this.store.state) === null || _a === void 0 ? void 0 : _a.activeTool) === null || _b === void 0 ? void 0 : _b.handleWheel(ev);
2685
+ }
2686
+ handlePointerDown(ev) {
2687
+ var _a, _b;
2688
+ if (this.store.isDisabled) {
2689
+ return;
2690
+ }
2691
+ if (KritzelEventHelper.isPointerEventOnContextMenu(ev) === false && this.store.state.isContextMenuVisible) {
2692
+ this.hideContextMenu();
2693
+ return;
2694
+ }
2695
+ KritzelEventHelper.onLongTouchPress(ev, (event) => {
2696
+ if (!(this.store.state.activeTool instanceof KritzelSelectionTool)) {
2697
+ return;
2698
+ }
2699
+ this.contextMenuHandler.handleContextMenu(event);
2700
+ });
2701
+ this.host.setPointerCapture(ev.pointerId);
2702
+ this.store.state.pointers.set(ev.pointerId, ev);
2703
+ this.viewport.handlePointerDown(ev);
2704
+ (_b = (_a = this.store.state) === null || _a === void 0 ? void 0 : _a.activeTool) === null || _b === void 0 ? void 0 : _b.handlePointerDown(ev);
2705
+ }
2706
+ handlePointerMove(ev) {
2707
+ var _a, _b;
2708
+ if (this.store.isDisabled) {
2709
+ return;
2710
+ }
2711
+ this.store.state.pointers.set(ev.pointerId, ev);
2712
+ this.viewport.handlePointerMove(ev);
2713
+ (_b = (_a = this.store.state) === null || _a === void 0 ? void 0 : _a.activeTool) === null || _b === void 0 ? void 0 : _b.handlePointerMove(ev);
2714
+ }
2715
+ handlePointerUp(ev) {
2716
+ var _a, _b;
2717
+ if (this.store.isDisabled) {
2718
+ return;
2719
+ }
2720
+ this.store.state.pointers.delete(ev.pointerId);
2721
+ this.host.releasePointerCapture(ev.pointerId);
2722
+ this.viewport.handlePointerUp(ev);
2723
+ (_b = (_a = this.store.state) === null || _a === void 0 ? void 0 : _a.activeTool) === null || _b === void 0 ? void 0 : _b.handlePointerUp(ev);
2724
+ }
2725
+ handlePointerCancel(ev) {
2726
+ var _a, _b;
2727
+ if (this.store.isDisabled) {
2728
+ return;
2729
+ }
2730
+ this.host.releasePointerCapture(ev.pointerId);
2731
+ this.store.state.pointers.delete(ev.pointerId);
2732
+ this.viewport.handlePointerUp(ev);
2733
+ (_b = (_a = this.store.state) === null || _a === void 0 ? void 0 : _a.activeTool) === null || _b === void 0 ? void 0 : _b.handlePointerUp(ev);
2734
+ }
2735
+ handleContextMenu(ev) {
2736
+ ev.preventDefault();
2737
+ if (this.store.isDisabled) {
2738
+ return;
2739
+ }
2740
+ if (ev.pointerType === 'touch') {
2741
+ return;
2742
+ }
2743
+ this.contextMenuHandler.handleContextMenu(ev);
2744
+ }
2745
+ handleResize() {
2746
+ this.viewport.handleResize();
2747
+ }
2748
+ handleKeyDown(ev) {
2749
+ this.keyHandler.handleKeyDown(ev);
2750
+ }
2751
+ handleKeyUp(ev) {
2752
+ this.keyHandler.handleKeyUp(ev);
2753
+ }
2754
+ updateFocus(ev) {
2755
+ if (this.store.isDisabled) {
2756
+ return;
2757
+ }
2758
+ const rect = this.store.state.host.getBoundingClientRect();
2759
+ const isInside = ev.clientX >= rect.left && ev.clientX <= rect.right && ev.clientY >= rect.top && ev.clientY <= rect.bottom;
2760
+ const path = ev.composedPath();
2761
+ const kritzelEngineElement = this.host.closest('kritzel-engine');
2762
+ const isInKritzelEngine = path.includes(kritzelEngineElement || this.host);
2763
+ this.store.setState('isFocused', isInside && isInKritzelEngine);
2764
+ }
2765
+ handleClick() {
2766
+ this.enable();
2767
+ }
2768
+ async registerTool(toolName, toolClass, toolConfig) {
2769
+ if (typeof toolClass !== 'function' || !(toolClass.prototype instanceof KritzelBaseTool)) {
2770
+ console.error(`Failed to register tool "${toolName}": Tool class must be a constructor function`);
2771
+ return null;
2772
+ }
2773
+ const registeredTool = KritzelToolRegistry.registerTool(toolName, toolClass, this.store);
2774
+ if (toolConfig) {
2775
+ Object.entries(toolConfig).forEach(([key, value]) => {
2776
+ registeredTool[key] = value;
2777
+ });
2778
+ }
2779
+ return Promise.resolve(registeredTool);
2780
+ }
2781
+ async changeActiveTool(tool) {
2782
+ var _a;
2783
+ (_a = this.store.state.activeTool) === null || _a === void 0 ? void 0 : _a.onDeactivate();
2784
+ this.store.setState('activeTool', tool);
2785
+ this.store.deselectAllObjects();
2786
+ tool === null || tool === void 0 ? void 0 : tool.onActivate();
2787
+ }
2788
+ async setFocus() {
2789
+ this.host.focus();
2790
+ this.store.state.isFocused = true;
2791
+ }
2792
+ async disable() {
2793
+ this.store.state.isEnabled = false;
2794
+ this.forceUpdate++;
2795
+ }
2796
+ async enable() {
2797
+ this.store.state.isEnabled = true;
2798
+ this.forceUpdate++;
2799
+ }
2800
+ async delete() {
2801
+ this.store.delete();
2802
+ }
2803
+ async copy() {
2804
+ this.store.copy();
2805
+ }
2806
+ async paste(x, y) {
2807
+ this.store.paste(x, y);
2808
+ }
2809
+ async bringForward(object) {
2810
+ this.store.bringForward(object);
2811
+ }
2812
+ async sendBackward(object) {
2813
+ this.store.sendBackward(object);
2814
+ }
2815
+ async bringToFront(object) {
2816
+ this.store.bringToFront(object);
2817
+ }
2818
+ async sendToBack(object) {
2819
+ this.store.sendToBack(object);
2820
+ }
2821
+ async undo() {
2822
+ this.store.history.undo();
2823
+ }
2824
+ async redo() {
2825
+ this.store.history.redo();
2826
+ }
2827
+ async hideContextMenu() {
2828
+ this.store.state.pointers.clear();
2829
+ this.store.state.isContextMenuVisible = false;
2830
+ this.store.state.selectionBox = null;
2831
+ this.store.state.isSelecting = false;
2832
+ }
2833
+ async getObjectById(id) {
2834
+ const object = this.store.objects.find(obj => obj.id === id);
2835
+ return object || null;
2836
+ }
2837
+ async addObject(object) {
2838
+ this.store.deselectAllObjects();
2839
+ object.id = object.generateId();
2840
+ object._store = this.store;
2841
+ object.scale = object.scale ? object.scale : this.store.state.scale;
2842
+ object.zIndex = this.store.currentZIndex;
2843
+ const command = new AddObjectCommand(this.store, this, object);
2844
+ this.store.history.executeCommand(command);
2845
+ return object;
2846
+ }
2847
+ async updateObject(object, updatedProperties) {
2848
+ this.store.deselectAllObjects();
2849
+ const command = new UpdateObjectCommand(this.store, this, object, updatedProperties);
2850
+ this.store.history.executeCommand(command);
2851
+ return object;
2852
+ }
2853
+ async removeObject(object) {
2854
+ this.store.deselectAllObjects();
2855
+ const command = new RemoveObjectCommand(this.store, this, object);
2856
+ this.store.history.executeCommand(command);
2857
+ return object;
2858
+ }
2859
+ async getSelectedObjects() {
2860
+ return this.store.state.selectionGroup ? this.store.state.selectionGroup.objects : [];
2861
+ }
2862
+ async selectObjects(objects) {
2863
+ var _a;
2864
+ (_a = this.store.state.activeTool) === null || _a === void 0 ? void 0 : _a.onDeactivate();
2865
+ this.store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
2866
+ this.store.deselectAllObjects();
2867
+ this.store.selectObjects(objects);
2868
+ }
2869
+ async selectAllObjectsInViewport() {
2870
+ var _a;
2871
+ (_a = this.store.state.activeTool) === null || _a === void 0 ? void 0 : _a.onDeactivate();
2872
+ this.store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
2873
+ this.store.deselectAllObjects();
2874
+ this.store.selectAllObjectsInViewport();
2875
+ }
2876
+ async clearSelection() {
2877
+ this.store.clearSelection();
2878
+ }
2879
+ async centerObjectInViewport(object) {
2880
+ object.centerInViewport();
2881
+ const command = new UpdateObjectCommand(this.store, this, object, object);
2882
+ this.store.history.executeCommand(command);
2883
+ return object;
2884
+ }
2885
+ async getCopiedObjects() {
2886
+ var _a;
2887
+ return ((_a = this.store.state.copiedObjects) === null || _a === void 0 ? void 0 : _a.objects) || [];
2888
+ }
2889
+ async createWorkspace(workspace) {
2890
+ return this.store.createWorkspace(workspace).then(() => {
2891
+ this.workspacesChange.emit(this.store.state.workspaces);
2892
+ });
2893
+ }
2894
+ async updateWorkspace(workspace) {
2895
+ return this.store.updateWorkspace(workspace).then(() => {
2896
+ this.workspacesChange.emit(this.store.state.workspaces);
2897
+ });
2898
+ }
2899
+ async deleteWorkspace(workspace) {
2900
+ return this.store.deleteWorkspace(workspace).then(() => {
2901
+ this.workspacesChange.emit(this.store.state.workspaces.filter(ws => ws.id !== workspace.id));
2902
+ });
2903
+ }
2904
+ async getWorkspaces() {
2905
+ return this.store.getWorkspaces();
2906
+ }
2907
+ _registerStateChangeListeners() {
2908
+ this.store.onStateChange('activeTool', this._handleActiveToolChange.bind(this));
2909
+ this.store.onStateChange('isFocused', this._handleIsFocusedChange.bind(this));
2910
+ }
2911
+ _handleActiveToolChange(activeTool) {
2912
+ if (!(activeTool instanceof KritzelSelectionTool)) {
2913
+ this.store.clearSelection();
2914
+ }
2915
+ this.store.state.skipContextMenu = false;
2916
+ this.activeToolChange.emit(activeTool);
2917
+ KritzelKeyboardHelper.forceHideKeyboard();
2918
+ }
2919
+ _handleIsFocusedChange(isFocused) {
2920
+ if (!isFocused) {
2921
+ this.store.resetActiveText();
2922
+ }
2923
+ }
2924
+ render() {
2925
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8;
2926
+ const computedStyle = window.getComputedStyle(this.host);
2927
+ const baseHandleSizePx = computedStyle.getPropertyValue('--kritzel-selection-handle-size').trim() || '6px';
2928
+ const baseHandleSize = parseFloat(baseHandleSizePx);
2929
+ const baseHandleTouchSize = baseHandleSize * 2 < 14 ? 14 : baseHandleSize;
2930
+ return (h(Host, { key: 'c7e747aa6106e7904cf9f44db37fa285a6fb4434' }, h("div", { key: 'b75652ab9f9531dce765cbe448ad3131c172d06a', class: "debug-panel", style: { display: this.store.state.debugInfo.showViewportInfo ? 'block' : 'none' } }, h("div", { key: 'fd1355bd640b9296949f6bbcf084589578654db6' }, "ActiveWorkspaceId: ", (_b = (_a = this.store.state) === null || _a === void 0 ? void 0 : _a.activeWorkspace) === null || _b === void 0 ? void 0 :
2931
+ _b.id), h("div", { key: '8520e3e774e97ebc42ee86401fbfbafbe41c88e8' }, "ActiveWorkspaceName: ", (_d = (_c = this.store.state) === null || _c === void 0 ? void 0 : _c.activeWorkspace) === null || _d === void 0 ? void 0 :
2932
+ _d.name), h("div", { key: 'f247b4d76cd018e787a9b59829deedeb6c5c5272' }, "TranslateX: ", (_e = this.store.state) === null || _e === void 0 ? void 0 :
2933
+ _e.translateX), h("div", { key: 'e0438479bc9e950ef2cbe88ed0aa0b8ec1888890' }, "TranslateY: ", (_f = this.store.state) === null || _f === void 0 ? void 0 :
2934
+ _f.translateY), h("div", { key: '1735fde66588e285039bcc090dee71630608d666' }, "ViewportWidth: ", (_g = this.store.state) === null || _g === void 0 ? void 0 :
2935
+ _g.viewportWidth), h("div", { key: '15f8b3305c27a395b8aa6463c5acec42bb3e3ddd' }, "ViewportHeight: ", (_h = this.store.state) === null || _h === void 0 ? void 0 :
2936
+ _h.viewportHeight), h("div", { key: 'd2e39bae191c7256967d0140f38e75dccf95f24c' }, "ObjectsInViewport. ", this.store.objects.length), h("div", { key: 'cd3f53ff4a8f119a2ef975133f69fc3798fe0f71' }, "Scale: ", (_j = this.store.state) === null || _j === void 0 ? void 0 :
2937
+ _j.scale), h("div", { key: 'b1f8c77589a80fe49d0947602bda46438921f7a8' }, "ActiveTool: ", (_l = (_k = this.store.state) === null || _k === void 0 ? void 0 : _k.activeTool) === null || _l === void 0 ? void 0 :
2938
+ _l.name), h("div", { key: '41cd94f58f71cd5c1cffc679ada5fc51f6ceeea7' }, "HasViewportChanged: ", ((_m = this.store.state) === null || _m === void 0 ? void 0 : _m.hasViewportChanged) ? 'true' : 'false'), h("div", { key: 'bf8495bb924673aad3a9ca57ed0bf9ac23874dfb' }, "IsEnabled: ", ((_o = this.store.state) === null || _o === void 0 ? void 0 : _o.isEnabled) ? 'true' : 'false'), h("div", { key: '3823936f5b46b100742f94fac8d7e87ed93ddb58' }, "IsScaling: ", ((_p = this.store.state) === null || _p === void 0 ? void 0 : _p.isScaling) ? 'true' : 'false'), h("div", { key: '62eb836fff78b050cdab8cbef54f88f9d5b644ba' }, "IsPanning: ", ((_q = this.store.state) === null || _q === void 0 ? void 0 : _q.isPanning) ? 'true' : 'false'), h("div", { key: 'dac6b8d18ae8f6317bdd318ad48a9612f9942613' }, "IsFocused: ", this.store.state.isFocused ? 'true' : 'false'), h("div", { key: 'af232e2cd738e255029f5611531c246ac63a28ce' }, "IsSelecting: ", this.isSelecting ? 'true' : 'false'), h("div", { key: '95a44fef4b6befe95bfadfc62957103b48bf76b6' }, "IsSelectionActive: ", this.isSelectionActive ? 'true' : 'false'), h("div", { key: 'e8162d4de449a0d6756c2f540fca28353c193438' }, "IsResizeHandleSelected: ", this.store.state.isResizeHandleSelected ? 'true' : 'false'), h("div", { key: '4440d023cd4982c834736e06863698c3baf72353' }, "IsRotationHandleSelected: ", this.store.state.isRotationHandleSelected ? 'true' : 'false'), h("div", { key: 'd3e467dd18e53850df4d5bedf2b69f54b1fbe5c6' }, "IsDrawing: ", this.store.state.isDrawing ? 'true' : 'false'), h("div", { key: 'df6e4bca16cbe4346786a544d6f6c53d87bdb699' }, "IsWriting: ", this.store.state.isWriting ? 'true' : 'false'), h("div", { key: '532aebf1ff35cc578f12e36cdaf00713ffc76b97' }, "PointerX: ", (_r = this.store.state) === null || _r === void 0 ? void 0 :
2939
+ _r.pointerX), h("div", { key: 'f710f8c8d27979da4a40e50452e2cdd63cdefa98' }, "PointerY: ", (_s = this.store.state) === null || _s === void 0 ? void 0 :
2940
+ _s.pointerY), h("div", { key: '0175010e1d5a22be81ca0b2d88dd1aff217eacfd' }, "SelectedObjects: ", ((_t = this.store.state.selectionGroup) === null || _t === void 0 ? void 0 : _t.objects.length) || 0)), h("div", { key: 'dc2964c479405ed147bd5f090e24262595a474e2', id: "origin", class: "origin", style: {
2941
+ transform: `matrix(${(_u = this.store.state) === null || _u === void 0 ? void 0 : _u.scale}, 0, 0, ${(_v = this.store.state) === null || _v === void 0 ? void 0 : _v.scale}, ${(_w = this.store.state) === null || _w === void 0 ? void 0 : _w.translateX}, ${(_x = this.store.state) === null || _x === void 0 ? void 0 : _x.translateY})`,
2942
+ } }, (_y = this.store.state.objectsOctree.allObjects()) === null || _y === void 0 ? void 0 :
2943
+ _y.map(object => {
2944
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
2945
+ return (h("div", { key: object.id, style: { display: object.isInViewport() ? 'block' : 'none', transform: object === null || object === void 0 ? void 0 : object.transformationMatrix, transformOrigin: 'top left', zIndex: object.zIndex.toString(), position: 'absolute' } }, h("svg", { xmlns: "http://www.w3.org/2000/svg", id: object.id, class: "object", style: {
2946
+ height: object === null || object === void 0 ? void 0 : object.totalHeight.toString(),
2947
+ width: object === null || object === void 0 ? void 0 : object.totalWidth.toString(),
2948
+ left: '0',
2949
+ top: '0',
2950
+ position: 'absolute',
2951
+ transform: `rotate(${object.rotationDegrees}deg)`,
2952
+ transformOrigin: 'center',
2953
+ opacity: object.markedForRemoval ? '0.5' : object.opacity.toString(),
2954
+ pointerEvents: object.markedForRemoval ? 'none' : 'auto',
2955
+ } }, h("foreignObject", { x: "0", y: "0", width: object.totalWidth.toString(), height: object.totalHeight.toString(), style: {
2956
+ minHeight: '0',
2957
+ minWidth: '0',
2958
+ backgroundColor: object.backgroundColor,
2959
+ borderColor: object.borderColor,
2960
+ borderWidth: object.borderWidth + 'px',
2961
+ borderStyle: 'solid',
2962
+ padding: object.padding + 'px',
2963
+ overflow: 'visible',
2964
+ } }, KritzelClassHelper.isInstanceOf(object, 'KritzelPath') && (h("svg", { ref: el => (el ? object.mount(el) : object.unmount()), xmlns: "http://www.w3.org/2000/svg", style: {
2965
+ height: object === null || object === void 0 ? void 0 : object.height.toString(),
2966
+ width: object === null || object === void 0 ? void 0 : object.width.toString(),
2967
+ position: 'absolute',
2968
+ overflow: 'visible',
2969
+ }, viewBox: object === null || object === void 0 ? void 0 : object.viewBox }, h("path", { d: object === null || object === void 0 ? void 0 : object.d, fill: object.fill, stroke: object === null || object === void 0 ? void 0 : object.stroke }))), KritzelClassHelper.isInstanceOf(object, 'KritzelImage') && (h("img", { ref: el => (el ? object.mount(el) : object.unmount()), src: object.src, style: {
2970
+ width: '100%',
2971
+ height: '100%',
2972
+ userSelect: 'none',
2973
+ pointerEvents: 'none',
2974
+ }, draggable: false, onDragStart: e => e.preventDefault() })), KritzelClassHelper.isInstanceOf(object, 'KritzelText') && (h("textarea", { ref: el => (el ? object.mount(el) : object.unmount()), value: object.value, onKeyDown: event => object.handleKeyDown(event), onInput: event => object.handleInput(event), rows: object.rows, style: {
2975
+ width: '100%',
2976
+ height: '100%',
2977
+ color: object.fontColor,
2978
+ fontSize: ((_a = object.fontSize) === null || _a === void 0 ? void 0 : _a.toString()) + 'px',
2979
+ fontFamily: object.fontFamily,
2980
+ border: 'none',
2981
+ outline: 'none',
2982
+ resize: 'none',
2983
+ overflow: 'hidden',
2984
+ display: 'block',
2985
+ padding: '1px',
2986
+ whiteSpace: 'nowrap',
2987
+ pointerEvents: object.isReadonly ? 'none' : 'auto',
2988
+ cursor: object.isReadonly ? 'default' : 'text',
2989
+ caretColor: object.isReadonly ? 'transparent' : 'auto',
2990
+ } })), KritzelClassHelper.isInstanceOf(object, 'KritzelCustomElement') && (h("div", { ref: el => (el ? object.mount(el) : object.unmount()), style: {
2991
+ width: '100%',
2992
+ height: '100%',
2993
+ pointerEvents: 'auto',
2994
+ overflow: 'hidden',
2995
+ display: 'block',
2996
+ } })), KritzelClassHelper.isInstanceOf(object, 'KritzelSelectionGroup') && (h("div", { ref: el => (el ? object.mount(el) : object.unmount()), style: {
2997
+ width: '100%',
2998
+ height: '100%',
2999
+ } })), KritzelClassHelper.isInstanceOf(object, 'KrtizelSelectionBox') && (h("div", { ref: el => (el ? object.mount(el) : object.unmount()), style: {
3000
+ width: '100%',
3001
+ height: '100%',
3002
+ } }))), h("line", { x1: "0", y1: "0", x2: object.totalWidth, y2: "0", style: {
3003
+ stroke: 'var(--kritzel-selection-border-color, #007AFF)',
3004
+ strokeWidth: `calc(var(--kritzel-selection-border-width, 2px) * ${object.scale} / ${(_b = this.store.state) === null || _b === void 0 ? void 0 : _b.scale})`,
3005
+ strokeLinecap: 'square',
3006
+ }, visibility: object.isSelected ? 'visible' : 'hidden' }), h("line", { x1: "0", y1: "0", x2: "0", y2: object.totalHeight, style: {
3007
+ stroke: 'var(--kritzel-selection-border-color, #007AFF)',
3008
+ strokeWidth: `calc(var(--kritzel-selection-border-width, 2px) * ${object.scale} / ${(_c = this.store.state) === null || _c === void 0 ? void 0 : _c.scale})`,
3009
+ strokeLinecap: 'square',
3010
+ }, visibility: object.isSelected ? 'visible' : 'hidden' }), h("line", { x1: "0", y1: object.totalHeight, x2: object.totalWidth, y2: object.totalHeight, style: {
3011
+ stroke: 'var(--kritzel-selection-border-color, #007AFF)',
3012
+ strokeWidth: `calc(var(--kritzel-selection-border-width, 2px) * ${object.scale} / ${(_d = this.store.state) === null || _d === void 0 ? void 0 : _d.scale})`,
3013
+ strokeLinecap: 'square',
3014
+ }, visibility: object.isSelected ? 'visible' : 'hidden' }), h("line", { x1: object.totalWidth, y1: "0", x2: object.totalWidth, y2: object.totalHeight, style: {
3015
+ stroke: 'var(--kritzel-selection-border-color, #007AFF)',
3016
+ strokeWidth: `calc(var(--kritzel-selection-border-width, 2px) * ${object.scale} / ${(_e = this.store.state) === null || _e === void 0 ? void 0 : _e.scale})`,
3017
+ strokeLinecap: 'square',
3018
+ }, visibility: object.isSelected ? 'visible' : 'hidden' }), h("circle", { class: "resize-handle top-left", cx: "0", cy: "0", r: `${(baseHandleSize * object.scale) / ((_f = this.store.state) === null || _f === void 0 ? void 0 : _f.scale)}`, style: {
3019
+ fill: 'var(--kritzel-selection-handle-color, #000000)',
3020
+ }, visibility: object.isSelected && !this.isSelecting ? 'visible' : 'hidden' }), h("circle", { class: "resize-handle-overlay top-left", cx: "0", cy: "0", r: `${(baseHandleTouchSize * object.scale) / ((_g = this.store.state) === null || _g === void 0 ? void 0 : _g.scale)}`, style: {
3021
+ fill: 'transparent',
3022
+ }, visibility: object.isSelected && !this.isSelecting ? 'visible' : 'hidden' }), h("circle", { class: "resize-handle top-right", cx: object.totalWidth, cy: "0", r: `${(baseHandleSize * object.scale) / ((_h = this.store.state) === null || _h === void 0 ? void 0 : _h.scale)}`, style: {
3023
+ fill: 'var(--kritzel-selection-handle-color, #000000)',
3024
+ }, visibility: object.isSelected && !this.isSelecting ? 'visible' : 'hidden' }), h("circle", { class: "resize-handle-overlay top-right", cx: object.totalWidth, cy: "0", r: `${(baseHandleTouchSize * object.scale) / ((_j = this.store.state) === null || _j === void 0 ? void 0 : _j.scale)}`, style: {
3025
+ fill: 'transparent',
3026
+ }, visibility: object.isSelected && !this.isSelecting ? 'visible' : 'hidden' }), h("circle", { class: "resize-handle bottom-left", cx: "0", cy: object.totalHeight, r: `${(baseHandleSize * object.scale) / ((_k = this.store.state) === null || _k === void 0 ? void 0 : _k.scale)}`, style: {
3027
+ fill: 'var(--kritzel-selection-handle-color, #000000)',
3028
+ }, visibility: object.isSelected && !this.isSelecting ? 'visible' : 'hidden' }), h("circle", { class: "resize-handle-overlay bottom-left", cx: "0", cy: object.totalHeight, r: `${(baseHandleTouchSize * object.scale) / ((_l = this.store.state) === null || _l === void 0 ? void 0 : _l.scale)}`, style: {
3029
+ fill: 'transparent',
3030
+ }, visibility: object.isSelected && !this.isSelecting ? 'visible' : 'hidden' }), h("circle", { class: "resize-handle bottom-right", cx: object.totalWidth, cy: object.totalHeight, r: `${(baseHandleSize * object.scale) / ((_m = this.store.state) === null || _m === void 0 ? void 0 : _m.scale)}`, style: {
3031
+ fill: 'var(--kritzel-selection-handle-color, #000000)',
3032
+ }, visibility: object.isSelected && !this.isSelecting ? 'visible' : 'hidden' }), h("circle", { class: "resize-handle-overlay bottom-right", cx: object.totalWidth, cy: object.totalHeight, r: `${(baseHandleTouchSize * object.scale) / ((_o = this.store.state) === null || _o === void 0 ? void 0 : _o.scale)}`, style: {
3033
+ fill: 'transparent',
3034
+ }, visibility: object.isSelected && !this.isSelecting ? 'visible' : 'hidden' }), h("line", { x1: object.totalWidth / 2, y1: "0", x2: object.totalWidth / 2, y2: -((15 * object.scale) / ((_p = this.store.state) === null || _p === void 0 ? void 0 : _p.scale)), style: {
3035
+ stroke: 'var(--kritzel-selection-border-color, #007AFF)',
3036
+ strokeWidth: `calc(var(--kritzel-selection-border-width, 2px) * ${object.scale} / ${(_q = this.store.state) === null || _q === void 0 ? void 0 : _q.scale})`,
3037
+ }, visibility: object.isSelected && !this.isSelecting ? 'visible' : 'hidden' }), h("circle", { class: "rotation-handle", cx: object.totalWidth / 2, cy: -((15 * object.scale) / ((_r = this.store.state) === null || _r === void 0 ? void 0 : _r.scale)), r: `${(baseHandleSize * object.scale) / ((_s = this.store.state) === null || _s === void 0 ? void 0 : _s.scale)}`, style: {
3038
+ fill: 'var(--kritzel-selection-handle-color, #000000)',
3039
+ }, visibility: object.isSelected && !this.isSelecting ? 'visible' : 'hidden' }), h("circle", { class: "rotation-handle-overlay", cx: object.totalWidth / 2, cy: -((15 * object.scale) / ((_t = this.store.state) === null || _t === void 0 ? void 0 : _t.scale)), r: `${(baseHandleTouchSize * object.scale) / ((_u = this.store.state) === null || _u === void 0 ? void 0 : _u.scale)}`, style: {
3040
+ fill: 'transparent',
3041
+ cursor: 'grab',
3042
+ }, visibility: object.isSelected && !this.isSelecting ? 'visible' : 'hidden' }), h("g", { style: { display: this.store.state.debugInfo.showObjectInfo ? 'block' : 'none', pointerEvents: 'none' } }, h("foreignObject", { x: object.totalWidth.toString(), y: "0", width: "400px", height: "160px", style: { minHeight: '0', minWidth: '0', display: object.isDebugInfoVisible ? 'block' : 'none' } }, h("div", { style: { width: '100%', height: '100%' } }, h("div", { style: { whiteSpace: 'nowrap' } }, "zIndex: ", object.zIndex), h("div", { style: { whiteSpace: 'nowrap' } }, "translateX: ", object.translateX), h("div", { style: { whiteSpace: 'nowrap' } }, "translateY: ", object.translateY), h("div", { style: { whiteSpace: 'nowrap' } }, "width: ", object.width), h("div", { style: { whiteSpace: 'nowrap' } }, "height: ", object.height), h("div", { style: { whiteSpace: 'nowrap' } }, "scale: ", object.scale), h("div", { style: { whiteSpace: 'nowrap' } }, "rotation: ", object.rotation), h("div", { style: { whiteSpace: 'nowrap' } }, "x: ", object.x), h("div", { style: { whiteSpace: 'nowrap' } }, "y: ", object.y)))))));
3043
+ }), h("svg", { key: '86f9a08bea3ac2d261b14b2eec471fafd20ca11f', class: "object", xmlns: "http://www.w3.org/2000/svg", style: {
3044
+ height: (_z = this.store.state.currentPath) === null || _z === void 0 ? void 0 : _z.height.toString(),
3045
+ width: (_0 = this.store.state.currentPath) === null || _0 === void 0 ? void 0 : _0.width.toString(),
3046
+ left: '0',
3047
+ top: '0',
3048
+ zIndex: (_1 = this.store.state.currentPath) === null || _1 === void 0 ? void 0 : _1.zIndex.toString(),
3049
+ position: 'absolute',
3050
+ transform: (_2 = this.store.state.currentPath) === null || _2 === void 0 ? void 0 : _2.transformationMatrix,
3051
+ transformOrigin: 'top left',
3052
+ overflow: 'visible',
3053
+ }, viewBox: (_3 = this.store.state.currentPath) === null || _3 === void 0 ? void 0 : _3.viewBox }, h("path", { key: '66ebcf1791c993d62b34a2e4da1d4279428a17dd', d: (_4 = this.store.state.currentPath) === null || _4 === void 0 ? void 0 : _4.d, fill: (_5 = this.store.state.currentPath) === null || _5 === void 0 ? void 0 : _5.fill, stroke: (_6 = this.store.state.currentPath) === null || _6 === void 0 ? void 0 : _6.stroke }))), this.store.state.isContextMenuVisible && (h("kritzel-context-menu", { key: 'af91784e3afc84b71d5186237d287c31d472d80a', class: "context-menu", ref: el => (this.contextMenuElement = el), items: this.store.state.contextMenuItems, objects: ((_7 = this.store.state.selectionGroup) === null || _7 === void 0 ? void 0 : _7.objects) || [], style: {
3054
+ position: 'fixed',
3055
+ left: `${this.store.state.contextMenuX}px`,
3056
+ top: `${this.store.state.contextMenuY}px`,
3057
+ zIndex: '10000',
3058
+ }, onActionSelected: event => {
3059
+ var _a;
3060
+ event.detail.action({
3061
+ x: (-this.store.state.translateX + this.store.state.contextMenuX) / this.store.state.scale,
3062
+ y: (-this.store.state.translateY + this.store.state.contextMenuY) / this.store.state.scale,
3063
+ }, (_a = this.store.state.selectionGroup) === null || _a === void 0 ? void 0 : _a.objects);
3064
+ this.hideContextMenu();
3065
+ } })), ((_8 = this.store.state) === null || _8 === void 0 ? void 0 : _8.activeTool) instanceof KritzelEraserTool && !this.store.state.isScaling && h("kritzel-cursor-trail", { key: '573a4422b742044df5f240b260bc66e83d004520', store: this.store })));
3066
+ }
3067
+ get host() { return this; }
3068
+ static get watchers() { return {
3069
+ "workspace": ["onWorkspaceChange"],
3070
+ "scaleMax": ["validateScaleMax"],
3071
+ "scaleMin": ["validateScaleMin"]
3072
+ }; }
3073
+ static get style() { return kritzelEngineCss; }
3074
+ }, [257, "kritzel-engine", {
3075
+ "workspace": [16],
3076
+ "activeTool": [16, "active-tool"],
3077
+ "globalContextMenuItems": [16, "global-context-menu-items"],
3078
+ "objectContextMenuItems": [16, "object-context-menu-items"],
3079
+ "scaleMax": [1026, "scale-max"],
3080
+ "scaleMin": [1026, "scale-min"],
3081
+ "forceUpdate": [32],
3082
+ "registerTool": [64],
3083
+ "changeActiveTool": [64],
3084
+ "setFocus": [64],
3085
+ "disable": [64],
3086
+ "enable": [64],
3087
+ "delete": [64],
3088
+ "copy": [64],
3089
+ "paste": [64],
3090
+ "bringForward": [64],
3091
+ "sendBackward": [64],
3092
+ "bringToFront": [64],
3093
+ "sendToBack": [64],
3094
+ "undo": [64],
3095
+ "redo": [64],
3096
+ "hideContextMenu": [64],
3097
+ "getObjectById": [64],
3098
+ "addObject": [64],
3099
+ "updateObject": [64],
3100
+ "removeObject": [64],
3101
+ "getSelectedObjects": [64],
3102
+ "selectObjects": [64],
3103
+ "selectAllObjectsInViewport": [64],
3104
+ "clearSelection": [64],
3105
+ "centerObjectInViewport": [64],
3106
+ "getCopiedObjects": [64],
3107
+ "createWorkspace": [64],
3108
+ "updateWorkspace": [64],
3109
+ "deleteWorkspace": [64],
3110
+ "getWorkspaces": [64]
3111
+ }, [[0, "wheel", "handleWheel"], [0, "pointerdown", "handlePointerDown"], [0, "pointermove", "handlePointerMove"], [0, "pointerup", "handlePointerUp"], [0, "pointercancel", "handlePointerCancel"], [0, "contextmenu", "handleContextMenu"], [9, "resize", "handleResize"], [8, "keydown", "handleKeyDown"], [8, "keyup", "handleKeyUp"], [9, "mousedown", "updateFocus"], [0, "click", "handleClick"]], {
3112
+ "workspace": ["onWorkspaceChange"],
3113
+ "scaleMax": ["validateScaleMax"],
3114
+ "scaleMin": ["validateScaleMin"]
3115
+ }]);
3116
+ function defineCustomElement() {
3117
+ if (typeof customElements === "undefined") {
3118
+ return;
3119
+ }
3120
+ const components = ["kritzel-engine", "kritzel-context-menu", "kritzel-cursor-trail", "kritzel-icon"];
3121
+ components.forEach(tagName => { switch (tagName) {
3122
+ case "kritzel-engine":
3123
+ if (!customElements.get(tagName)) {
3124
+ customElements.define(tagName, KritzelEngine);
3125
+ }
3126
+ break;
3127
+ case "kritzel-context-menu":
3128
+ if (!customElements.get(tagName)) {
3129
+ defineCustomElement$3();
3130
+ }
3131
+ break;
3132
+ case "kritzel-cursor-trail":
3133
+ if (!customElements.get(tagName)) {
3134
+ defineCustomElement$2();
3135
+ }
3136
+ break;
3137
+ case "kritzel-icon":
3138
+ if (!customElements.get(tagName)) {
3139
+ defineCustomElement$1();
3140
+ }
3141
+ break;
3142
+ } });
3143
+ }
3144
+
3145
+ export { ABSOLUTE_SCALE_MAX as A, KritzelImage as K, KritzelEraserTool as a, KritzelImageTool as b, KritzelSelectionTool as c, KritzelEngine as d, defineCustomElement as e, ABSOLUTE_SCALE_MIN as f };
3146
+ //# sourceMappingURL=p-D-zg05gA.js.map
3147
+
3148
+ //# sourceMappingURL=p-D-zg05gA.js.map