kritzel-stencil 0.0.131 → 0.0.133

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 (362) hide show
  1. package/dist/cjs/{index-BwINBV6L.js → index-DCHCVnOl.js} +755 -701
  2. package/dist/cjs/index-DCHCVnOl.js.map +1 -0
  3. package/dist/cjs/index-nzUNdMPh.js +6 -2
  4. package/dist/cjs/index.cjs.js +1 -1
  5. package/dist/cjs/kritzel-brush-style.cjs.entry.js +32 -0
  6. package/dist/cjs/kritzel-brush-style.entry.cjs.js.map +1 -0
  7. package/dist/cjs/{kritzel-brush-style_23.cjs.entry.js → kritzel-color_22.cjs.entry.js} +1046 -874
  8. package/dist/cjs/loader.cjs.js +1 -1
  9. package/dist/cjs/stencil.cjs.js +1 -1
  10. package/dist/collection/classes/commands/add-object.command.js +6 -7
  11. package/dist/collection/classes/commands/add-object.command.js.map +1 -1
  12. package/dist/collection/classes/commands/add-selection-group.command.js +9 -9
  13. package/dist/collection/classes/commands/add-selection-group.command.js.map +1 -1
  14. package/dist/collection/classes/commands/base.command.js +3 -3
  15. package/dist/collection/classes/commands/base.command.js.map +1 -1
  16. package/dist/collection/classes/commands/batch.command.js +2 -2
  17. package/dist/collection/classes/commands/batch.command.js.map +1 -1
  18. package/dist/collection/classes/commands/move-selection-group.command.js +15 -7
  19. package/dist/collection/classes/commands/move-selection-group.command.js.map +1 -1
  20. package/dist/collection/classes/commands/remove-object.command.js +8 -9
  21. package/dist/collection/classes/commands/remove-object.command.js.map +1 -1
  22. package/dist/collection/classes/commands/remove-selection-group.command.js +7 -7
  23. package/dist/collection/classes/commands/remove-selection-group.command.js.map +1 -1
  24. package/dist/collection/classes/commands/resize-selection-group.command.js +15 -7
  25. package/dist/collection/classes/commands/resize-selection-group.command.js.map +1 -1
  26. package/dist/collection/classes/commands/rotate-selection-group.command.js +14 -12
  27. package/dist/collection/classes/commands/rotate-selection-group.command.js.map +1 -1
  28. package/dist/collection/classes/commands/update-object.command.js +6 -5
  29. package/dist/collection/classes/commands/update-object.command.js.map +1 -1
  30. package/dist/collection/classes/commands/update-viewport.command.js +11 -11
  31. package/dist/collection/classes/commands/update-viewport.command.js.map +1 -1
  32. package/dist/collection/classes/{store.class.js → core/core.class.js} +116 -145
  33. package/dist/collection/classes/core/core.class.js.map +1 -0
  34. package/dist/collection/classes/{database.class.js → core/database.class.js} +28 -20
  35. package/dist/collection/classes/core/database.class.js.map +1 -0
  36. package/dist/collection/classes/core/history.class.js +88 -0
  37. package/dist/collection/classes/core/history.class.js.map +1 -0
  38. package/dist/collection/classes/{reviver.class.js → core/reviver.class.js} +27 -23
  39. package/dist/collection/classes/core/reviver.class.js.map +1 -0
  40. package/dist/collection/classes/core/store.class.js +51 -0
  41. package/dist/collection/classes/core/store.class.js.map +1 -0
  42. package/dist/collection/classes/core/viewport.class.js +165 -0
  43. package/dist/collection/classes/core/viewport.class.js.map +1 -0
  44. package/dist/collection/classes/core/workspace.class.js +42 -0
  45. package/dist/collection/classes/core/workspace.class.js.map +1 -0
  46. package/dist/collection/classes/handlers/base.handler.js +4 -4
  47. package/dist/collection/classes/handlers/base.handler.js.map +1 -1
  48. package/dist/collection/classes/handlers/context-menu.handler.js +29 -19
  49. package/dist/collection/classes/handlers/context-menu.handler.js.map +1 -1
  50. package/dist/collection/classes/handlers/hover.handler.js +5 -5
  51. package/dist/collection/classes/handlers/hover.handler.js.map +1 -1
  52. package/dist/collection/classes/handlers/key.handler.js +38 -44
  53. package/dist/collection/classes/handlers/key.handler.js.map +1 -1
  54. package/dist/collection/classes/handlers/move.handler.js +49 -44
  55. package/dist/collection/classes/handlers/move.handler.js.map +1 -1
  56. package/dist/collection/classes/handlers/resize.handler.js +55 -60
  57. package/dist/collection/classes/handlers/resize.handler.js.map +1 -1
  58. package/dist/collection/classes/handlers/rotation.handler.js +59 -69
  59. package/dist/collection/classes/handlers/rotation.handler.js.map +1 -1
  60. package/dist/collection/classes/handlers/selection.handler.js +73 -72
  61. package/dist/collection/classes/handlers/selection.handler.js.map +1 -1
  62. package/dist/collection/classes/objects/base-object.class.js +30 -17
  63. package/dist/collection/classes/objects/base-object.class.js.map +1 -1
  64. package/dist/collection/classes/objects/custom-element.class.js +3 -3
  65. package/dist/collection/classes/objects/custom-element.class.js.map +1 -1
  66. package/dist/collection/classes/objects/image.class.js +5 -5
  67. package/dist/collection/classes/objects/image.class.js.map +1 -1
  68. package/dist/collection/classes/objects/path.class.js +7 -7
  69. package/dist/collection/classes/objects/path.class.js.map +1 -1
  70. package/dist/collection/classes/objects/selection-box.class.js +4 -4
  71. package/dist/collection/classes/objects/selection-box.class.js.map +1 -1
  72. package/dist/collection/classes/objects/selection-group.class.js +19 -20
  73. package/dist/collection/classes/objects/selection-group.class.js.map +1 -1
  74. package/dist/collection/classes/objects/text.class.js +13 -13
  75. package/dist/collection/classes/objects/text.class.js.map +1 -1
  76. package/dist/collection/classes/registries/tool.registry.js +2 -2
  77. package/dist/collection/classes/registries/tool.registry.js.map +1 -1
  78. package/dist/collection/classes/tools/base-tool.class.js +11 -5
  79. package/dist/collection/classes/tools/base-tool.class.js.map +1 -1
  80. package/dist/collection/classes/tools/brush-tool.class.js +57 -53
  81. package/dist/collection/classes/tools/brush-tool.class.js.map +1 -1
  82. package/dist/collection/classes/tools/eraser-tool.class.js +26 -26
  83. package/dist/collection/classes/tools/eraser-tool.class.js.map +1 -1
  84. package/dist/collection/classes/tools/image-tool.class.js +11 -11
  85. package/dist/collection/classes/tools/image-tool.class.js.map +1 -1
  86. package/dist/collection/classes/tools/selection-tool.class.js +39 -37
  87. package/dist/collection/classes/tools/selection-tool.class.js.map +1 -1
  88. package/dist/collection/classes/tools/text-tool.class.js +37 -37
  89. package/dist/collection/classes/tools/text-tool.class.js.map +1 -1
  90. package/dist/collection/components/core/kritzel-cursor-trail/kritzel-cursor-trail.js +28 -28
  91. package/dist/collection/components/core/kritzel-cursor-trail/kritzel-cursor-trail.js.map +1 -1
  92. package/dist/collection/components/core/kritzel-editor/kritzel-editor.css +7 -9
  93. package/dist/collection/components/core/kritzel-editor/kritzel-editor.js +177 -7
  94. package/dist/collection/components/core/kritzel-editor/kritzel-editor.js.map +1 -1
  95. package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +237 -232
  96. package/dist/collection/components/core/kritzel-engine/kritzel-engine.js.map +1 -1
  97. package/dist/collection/components/shared/kritzel-brush-style/kritzel-brush-style.js +1 -1
  98. package/dist/collection/components/shared/kritzel-brush-style/kritzel-brush-style.js.map +1 -1
  99. package/dist/collection/components/shared/kritzel-color/kritzel-color.js +2 -2
  100. package/dist/collection/components/shared/kritzel-color/kritzel-color.js.map +1 -1
  101. package/dist/collection/components/shared/kritzel-color-palette/kritzel-color-palette.css +5 -0
  102. package/dist/collection/components/shared/kritzel-color-palette/kritzel-color-palette.js +3 -3
  103. package/dist/collection/components/shared/kritzel-color-palette/kritzel-color-palette.js.map +1 -1
  104. package/dist/collection/components/shared/kritzel-dropdown/kritzel-dropdown.js +12 -12
  105. package/dist/collection/components/shared/kritzel-dropdown/kritzel-dropdown.js.map +1 -1
  106. package/dist/collection/components/shared/kritzel-font/kritzel-font.js +1 -1
  107. package/dist/collection/components/shared/kritzel-font/kritzel-font.js.map +1 -1
  108. package/dist/collection/components/shared/kritzel-font-family/kritzel-font-family.js +1 -1
  109. package/dist/collection/components/shared/kritzel-font-family/kritzel-font-family.js.map +1 -1
  110. package/dist/collection/components/shared/kritzel-font-size/kritzel-font-size.js +1 -1
  111. package/dist/collection/components/shared/kritzel-font-size/kritzel-font-size.js.map +1 -1
  112. package/dist/collection/components/shared/kritzel-icon/kritzel-icon.css +1 -0
  113. package/dist/collection/components/shared/kritzel-icon/kritzel-icon.js.map +1 -1
  114. package/dist/collection/components/shared/kritzel-menu/kritzel-menu.css +5 -1
  115. package/dist/collection/components/shared/kritzel-menu/kritzel-menu.js +2 -2
  116. package/dist/collection/components/shared/kritzel-menu/kritzel-menu.js.map +1 -1
  117. package/dist/collection/components/shared/kritzel-menu-item/kritzel-menu-item.css +18 -7
  118. package/dist/collection/components/shared/kritzel-menu-item/kritzel-menu-item.js +24 -9
  119. package/dist/collection/components/shared/kritzel-menu-item/kritzel-menu-item.js.map +1 -1
  120. package/dist/collection/components/shared/kritzel-portal/kritzel-portal.js +4 -42
  121. package/dist/collection/components/shared/kritzel-portal/kritzel-portal.js.map +1 -1
  122. package/dist/collection/components/shared/kritzel-split-button/kritzel-split-button.css +0 -4
  123. package/dist/collection/components/shared/kritzel-split-button/kritzel-split-button.js +52 -10
  124. package/dist/collection/components/shared/kritzel-split-button/kritzel-split-button.js.map +1 -1
  125. package/dist/collection/components/shared/kritzel-stroke-size/kritzel-stroke-size.css +4 -0
  126. package/dist/collection/components/shared/kritzel-stroke-size/kritzel-stroke-size.js +1 -1
  127. package/dist/collection/components/shared/kritzel-stroke-size/kritzel-stroke-size.js.map +1 -1
  128. package/dist/collection/components/shared/kritzel-tooltip/kritzel-tooltip.js +79 -7
  129. package/dist/collection/components/shared/kritzel-tooltip/kritzel-tooltip.js.map +1 -1
  130. package/dist/collection/components/ui/kritzel-context-menu/kritzel-context-menu.js +47 -15
  131. package/dist/collection/components/ui/kritzel-context-menu/kritzel-context-menu.js.map +1 -1
  132. package/dist/collection/components/ui/kritzel-control-brush-config/kritzel-control-brush-config.css +4 -0
  133. package/dist/collection/components/ui/kritzel-control-brush-config/kritzel-control-brush-config.js +6 -6
  134. package/dist/collection/components/ui/kritzel-control-brush-config/kritzel-control-brush-config.js.map +1 -1
  135. package/dist/collection/components/ui/kritzel-control-text-config/kritzel-control-text-config.js +2 -2
  136. package/dist/collection/components/ui/kritzel-control-text-config/kritzel-control-text-config.js.map +1 -1
  137. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.css +12 -1
  138. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js +23 -7
  139. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js.map +1 -1
  140. package/dist/collection/components/ui/kritzel-utility-panel/kritzel-utility-panel.css +5 -0
  141. package/dist/collection/components/ui/kritzel-utility-panel/kritzel-utility-panel.js +1 -1
  142. package/dist/collection/components/ui/kritzel-utility-panel/kritzel-utility-panel.js.map +1 -1
  143. package/dist/collection/components/ui/kritzel-workspace-manager/kritzel-workspace-manager.js +25 -15
  144. package/dist/collection/components/ui/kritzel-workspace-manager/kritzel-workspace-manager.js.map +1 -1
  145. package/dist/collection/configs/default-engine-state.js +0 -1
  146. package/dist/collection/configs/default-engine-state.js.map +1 -1
  147. package/dist/collection/helpers/devices.helper.js +20 -0
  148. package/dist/collection/helpers/devices.helper.js.map +1 -1
  149. package/dist/collection/helpers/event.helper.js +1 -5
  150. package/dist/collection/helpers/event.helper.js.map +1 -1
  151. package/dist/collection/helpers/html.helper.js +29 -0
  152. package/dist/collection/helpers/html.helper.js.map +1 -1
  153. package/dist/collection/helpers/object.helper.js +0 -14
  154. package/dist/collection/helpers/object.helper.js.map +1 -1
  155. package/dist/collection/index.js +1 -1
  156. package/dist/collection/index.js.map +1 -1
  157. package/dist/collection/interfaces/clonable.interface.js +2 -0
  158. package/dist/collection/interfaces/clonable.interface.js.map +1 -0
  159. package/dist/collection/interfaces/engine-state.interface.js.map +1 -1
  160. package/dist/collection/interfaces/serializable.interface.js.map +1 -1
  161. package/dist/collection/types/deep-readonly.type.js +2 -0
  162. package/dist/collection/types/deep-readonly.type.js.map +1 -0
  163. package/dist/components/index.js +3 -3
  164. package/dist/components/kritzel-brush-style.js +59 -1
  165. package/dist/components/kritzel-brush-style.js.map +1 -1
  166. package/dist/components/kritzel-color-palette.js +1 -1
  167. package/dist/components/kritzel-color.js +1 -1
  168. package/dist/components/kritzel-context-menu.js +1 -1
  169. package/dist/components/kritzel-control-brush-config.js +1 -1
  170. package/dist/components/kritzel-control-text-config.js +1 -1
  171. package/dist/components/kritzel-controls.js +1 -1
  172. package/dist/components/kritzel-cursor-trail.js +1 -1
  173. package/dist/components/kritzel-dropdown.js +1 -1
  174. package/dist/components/kritzel-editor.js +80 -37
  175. package/dist/components/kritzel-editor.js.map +1 -1
  176. package/dist/components/kritzel-engine.js +1 -1
  177. package/dist/components/kritzel-font-family.js +1 -1
  178. package/dist/components/kritzel-font-size.js +1 -1
  179. package/dist/components/kritzel-font.js +1 -1
  180. package/dist/components/kritzel-icon.js +1 -1
  181. package/dist/components/kritzel-menu-item.js +1 -1
  182. package/dist/components/kritzel-menu.js +1 -1
  183. package/dist/components/kritzel-portal.js +1 -1
  184. package/dist/components/kritzel-split-button.js +1 -1
  185. package/dist/components/kritzel-stroke-size.js +1 -1
  186. package/dist/components/kritzel-tooltip.js +1 -1
  187. package/dist/components/kritzel-utility-panel.js +1 -1
  188. package/dist/components/kritzel-workspace-manager.js +1 -1
  189. package/dist/components/{p-CMJ3P0Vw.js → p-0iJh9Z6m.js} +5 -5
  190. package/dist/components/p-0iJh9Z6m.js.map +1 -0
  191. package/dist/components/p-B0kd2rUI.js +16 -0
  192. package/dist/components/p-B0kd2rUI.js.map +1 -0
  193. package/dist/components/{p-BB5R2k1o.js → p-B3LGnqFz.js} +41 -31
  194. package/dist/components/p-B3LGnqFz.js.map +1 -0
  195. package/dist/components/{p-BB0_-X42.js → p-B7kZ1_RH.js} +4 -4
  196. package/dist/components/{p-BB0_-X42.js.map → p-B7kZ1_RH.js.map} +1 -1
  197. package/dist/components/{p-t4NIsuX9.js → p-B7w19kIk.js} +15 -27
  198. package/dist/components/p-B7w19kIk.js.map +1 -0
  199. package/dist/components/{p-B1BLgWL1.js → p-BGdsAz54.js} +27 -18
  200. package/dist/components/p-BGdsAz54.js.map +1 -0
  201. package/dist/components/{p-CGmS8wnN.js → p-BKvOO7NT.js} +26 -16
  202. package/dist/components/p-BKvOO7NT.js.map +1 -0
  203. package/dist/components/{p-BhiYvSBc.js → p-BM9IjvnD.js} +3 -3
  204. package/dist/components/p-BM9IjvnD.js.map +1 -0
  205. package/dist/components/{p-BrBQUN0Q.js → p-BPsQrpzN.js} +40 -11
  206. package/dist/components/p-BPsQrpzN.js.map +1 -0
  207. package/dist/components/p-C6qB08BS.js +68 -0
  208. package/dist/components/p-C6qB08BS.js.map +1 -0
  209. package/dist/components/{p-BPz_H-EG.js → p-CM8KdFZI.js} +28 -16
  210. package/dist/components/p-CM8KdFZI.js.map +1 -0
  211. package/dist/components/{p-DHSEK3rF.js → p-CNTK3JOp.js} +174 -153
  212. package/dist/components/p-CNTK3JOp.js.map +1 -0
  213. package/dist/components/{p-DMrtdhBD.js → p-CsyM5q2M.js} +7 -7
  214. package/dist/components/p-CsyM5q2M.js.map +1 -0
  215. package/dist/components/{p-BuewJQNl.js → p-CwH-bwjb.js} +1187 -1141
  216. package/dist/components/p-CwH-bwjb.js.map +1 -0
  217. package/dist/components/{p-BgmKrd5Z.js → p-DCx3703u.js} +5 -5
  218. package/dist/components/p-DCx3703u.js.map +1 -0
  219. package/dist/components/{p-trncBp_6.js → p-DFO-6kuA.js} +15 -15
  220. package/dist/components/p-DFO-6kuA.js.map +1 -0
  221. package/dist/components/{p-BubxwvMA.js → p-Db3kxVe2.js} +24 -24
  222. package/dist/components/p-Db3kxVe2.js.map +1 -0
  223. package/dist/components/{p-BexTdWaX.js → p-Ddlbt3Bj.js} +4 -4
  224. package/dist/components/p-Ddlbt3Bj.js.map +1 -0
  225. package/dist/components/{p-CHxPWeZd.js → p-DjU7p3od.js} +11 -11
  226. package/dist/components/{p-CHxPWeZd.js.map → p-DjU7p3od.js.map} +1 -1
  227. package/dist/components/{p-BeljsQ-8.js → p-Dw4n-4zp.js} +32 -17
  228. package/dist/components/p-Dw4n-4zp.js.map +1 -0
  229. package/dist/components/{p-DxTu1aoJ.js → p-NP1Htol7.js} +7 -45
  230. package/dist/components/p-NP1Htol7.js.map +1 -0
  231. package/dist/components/p-YqK8ch2R.js +46 -0
  232. package/dist/components/p-YqK8ch2R.js.map +1 -0
  233. package/dist/components/p-l10It7Nm.js +30 -0
  234. package/dist/components/p-l10It7Nm.js.map +1 -0
  235. package/dist/components/{p-p1Jkec_q.js → p-sq9jgfX0.js} +3 -3
  236. package/dist/components/p-sq9jgfX0.js.map +1 -0
  237. package/dist/components/{p-yZ48g7-u.js → p-sreNwi0N.js} +4 -4
  238. package/dist/components/{p-yZ48g7-u.js.map → p-sreNwi0N.js.map} +1 -1
  239. package/dist/esm/{index-B-oSk-v8.js → index-DY3KqYWc.js} +756 -702
  240. package/dist/esm/index-DY3KqYWc.js.map +1 -0
  241. package/dist/esm/index-oCOlsFCN.js +6 -2
  242. package/dist/esm/index.js +1 -1
  243. package/dist/esm/kritzel-brush-style.entry.js +30 -0
  244. package/dist/esm/kritzel-brush-style.entry.js.map +1 -0
  245. package/dist/esm/{kritzel-brush-style_23.entry.js → kritzel-color_22.entry.js} +1048 -875
  246. package/dist/esm/loader.js +1 -1
  247. package/dist/esm/stencil.js +1 -1
  248. package/dist/stencil/index.esm.js +1 -1
  249. package/dist/stencil/kritzel-brush-style.entry.esm.js.map +1 -0
  250. package/dist/stencil/p-25d1e040.entry.js +2 -0
  251. package/dist/stencil/p-25d1e040.entry.js.map +1 -0
  252. package/dist/stencil/p-DY3KqYWc.js +2 -0
  253. package/dist/stencil/p-DY3KqYWc.js.map +1 -0
  254. package/dist/stencil/p-dc534b01.entry.js +2 -0
  255. package/dist/stencil/p-dc534b01.entry.js.map +1 -0
  256. package/dist/stencil/stencil.esm.js +1 -1
  257. package/dist/types/classes/commands/add-object.command.d.ts +2 -2
  258. package/dist/types/classes/commands/add-selection-group.command.d.ts +2 -1
  259. package/dist/types/classes/commands/base.command.d.ts +3 -3
  260. package/dist/types/classes/commands/batch.command.d.ts +2 -1
  261. package/dist/types/classes/commands/move-selection-group.command.d.ts +2 -1
  262. package/dist/types/classes/commands/remove-object.command.d.ts +2 -2
  263. package/dist/types/classes/commands/remove-selection-group.command.d.ts +2 -2
  264. package/dist/types/classes/commands/resize-selection-group.command.d.ts +2 -1
  265. package/dist/types/classes/commands/rotate-selection-group.command.d.ts +2 -1
  266. package/dist/types/classes/commands/update-object.command.d.ts +2 -2
  267. package/dist/types/classes/commands/update-viewport.command.d.ts +2 -1
  268. package/dist/types/classes/{store.class.d.ts → core/core.class.d.ts} +9 -19
  269. package/dist/types/classes/{database.class.d.ts → core/database.class.d.ts} +3 -2
  270. package/dist/types/classes/{history.class.d.ts → core/history.class.d.ts} +5 -5
  271. package/dist/types/classes/core/reviver.class.d.ts +6 -0
  272. package/dist/types/classes/core/store.class.d.ts +17 -0
  273. package/dist/types/classes/{viewport.class.d.ts → core/viewport.class.d.ts} +3 -3
  274. package/dist/types/classes/core/workspace.class.d.ts +24 -0
  275. package/dist/types/classes/handlers/base.handler.d.ts +3 -3
  276. package/dist/types/classes/handlers/context-menu.handler.d.ts +2 -2
  277. package/dist/types/classes/handlers/hover.handler.d.ts +2 -2
  278. package/dist/types/classes/handlers/key.handler.d.ts +2 -2
  279. package/dist/types/classes/handlers/move.handler.d.ts +4 -2
  280. package/dist/types/classes/handlers/resize.handler.d.ts +3 -2
  281. package/dist/types/classes/handlers/rotation.handler.d.ts +6 -2
  282. package/dist/types/classes/handlers/selection.handler.d.ts +2 -2
  283. package/dist/types/classes/objects/base-object.class.d.ts +8 -5
  284. package/dist/types/classes/objects/custom-element.class.d.ts +2 -2
  285. package/dist/types/classes/objects/image.class.d.ts +2 -2
  286. package/dist/types/classes/objects/path.class.d.ts +2 -2
  287. package/dist/types/classes/objects/selection-box.class.d.ts +2 -2
  288. package/dist/types/classes/objects/selection-group.class.d.ts +2 -2
  289. package/dist/types/classes/objects/text.class.d.ts +2 -2
  290. package/dist/types/classes/registries/tool.registry.d.ts +2 -2
  291. package/dist/types/classes/tools/base-tool.class.d.ts +8 -4
  292. package/dist/types/classes/tools/brush-tool.class.d.ts +2 -2
  293. package/dist/types/classes/tools/eraser-tool.class.d.ts +2 -2
  294. package/dist/types/classes/tools/image-tool.class.d.ts +2 -2
  295. package/dist/types/classes/tools/selection-tool.class.d.ts +2 -2
  296. package/dist/types/classes/tools/text-tool.class.d.ts +2 -2
  297. package/dist/types/components/core/kritzel-cursor-trail/kritzel-cursor-trail.d.ts +5 -5
  298. package/dist/types/components/core/kritzel-editor/kritzel-editor.d.ts +13 -3
  299. package/dist/types/components/core/kritzel-engine/kritzel-engine.d.ts +21 -22
  300. package/dist/types/components/shared/kritzel-dropdown/kritzel-dropdown.d.ts +2 -2
  301. package/dist/types/components/shared/kritzel-menu-item/kritzel-menu-item.d.ts +2 -0
  302. package/dist/types/components/shared/kritzel-portal/kritzel-portal.d.ts +0 -1
  303. package/dist/types/components/shared/kritzel-split-button/kritzel-split-button.d.ts +4 -2
  304. package/dist/types/components/shared/kritzel-tooltip/kritzel-tooltip.d.ts +8 -2
  305. package/dist/types/components/ui/kritzel-context-menu/kritzel-context-menu.d.ts +5 -3
  306. package/dist/types/components/ui/kritzel-control-brush-config/kritzel-control-brush-config.d.ts +1 -1
  307. package/dist/types/components/ui/kritzel-controls/kritzel-controls.d.ts +3 -1
  308. package/dist/types/components/ui/kritzel-workspace-manager/kritzel-workspace-manager.d.ts +3 -2
  309. package/dist/types/components.d.ts +41 -12
  310. package/dist/types/helpers/devices.helper.d.ts +4 -0
  311. package/dist/types/helpers/event.helper.d.ts +1 -1
  312. package/dist/types/helpers/html.helper.d.ts +1 -0
  313. package/dist/types/helpers/object.helper.d.ts +0 -2
  314. package/dist/types/index.d.ts +1 -1
  315. package/dist/types/interfaces/clonable.interface.d.ts +3 -0
  316. package/dist/types/interfaces/engine-state.interface.d.ts +1 -2
  317. package/dist/types/interfaces/serializable.interface.d.ts +2 -1
  318. package/dist/types/types/deep-readonly.type.d.ts +7 -0
  319. package/package.json +3 -2
  320. package/dist/cjs/index-BwINBV6L.js.map +0 -1
  321. package/dist/collection/classes/database.class.js.map +0 -1
  322. package/dist/collection/classes/history.class.js +0 -88
  323. package/dist/collection/classes/history.class.js.map +0 -1
  324. package/dist/collection/classes/reviver.class.js.map +0 -1
  325. package/dist/collection/classes/store.class.js.map +0 -1
  326. package/dist/collection/classes/viewport.class.js +0 -153
  327. package/dist/collection/classes/viewport.class.js.map +0 -1
  328. package/dist/collection/classes/workspace.class.js +0 -15
  329. package/dist/collection/classes/workspace.class.js.map +0 -1
  330. package/dist/components/p-B1BLgWL1.js.map +0 -1
  331. package/dist/components/p-BB5R2k1o.js.map +0 -1
  332. package/dist/components/p-BPz_H-EG.js.map +0 -1
  333. package/dist/components/p-B_lb1FGi.js +0 -19
  334. package/dist/components/p-B_lb1FGi.js.map +0 -1
  335. package/dist/components/p-BeljsQ-8.js.map +0 -1
  336. package/dist/components/p-BexTdWaX.js.map +0 -1
  337. package/dist/components/p-BgmKrd5Z.js.map +0 -1
  338. package/dist/components/p-BhiYvSBc.js.map +0 -1
  339. package/dist/components/p-BrBQUN0Q.js.map +0 -1
  340. package/dist/components/p-BubxwvMA.js.map +0 -1
  341. package/dist/components/p-BuewJQNl.js.map +0 -1
  342. package/dist/components/p-CGmS8wnN.js.map +0 -1
  343. package/dist/components/p-CJKA5zIE.js +0 -10
  344. package/dist/components/p-CJKA5zIE.js.map +0 -1
  345. package/dist/components/p-CMJ3P0Vw.js.map +0 -1
  346. package/dist/components/p-DHSEK3rF.js.map +0 -1
  347. package/dist/components/p-DMrtdhBD.js.map +0 -1
  348. package/dist/components/p-DnUKql15.js +0 -30
  349. package/dist/components/p-DnUKql15.js.map +0 -1
  350. package/dist/components/p-DxTu1aoJ.js.map +0 -1
  351. package/dist/components/p-p1Jkec_q.js.map +0 -1
  352. package/dist/components/p-rIRXQdie.js +0 -64
  353. package/dist/components/p-rIRXQdie.js.map +0 -1
  354. package/dist/components/p-t4NIsuX9.js.map +0 -1
  355. package/dist/components/p-trncBp_6.js.map +0 -1
  356. package/dist/esm/index-B-oSk-v8.js.map +0 -1
  357. package/dist/stencil/p-3bb80782.entry.js +0 -2
  358. package/dist/stencil/p-3bb80782.entry.js.map +0 -1
  359. package/dist/stencil/p-B-oSk-v8.js +0 -2
  360. package/dist/stencil/p-B-oSk-v8.js.map +0 -1
  361. package/dist/types/classes/reviver.class.d.ts +0 -6
  362. package/dist/types/classes/workspace.class.d.ts +0 -16
@@ -1,9 +1,9 @@
1
1
  class KritzelBaseCommand {
2
- _store;
2
+ _core;
3
3
  initiator;
4
4
  skipHistory;
5
- constructor(store, initiator, skipHistory = false) {
6
- this._store = store;
5
+ constructor(core, initiator, skipHistory = false) {
6
+ this._core = core;
7
7
  this.initiator = initiator?.constructor?.name ?? 'Unknown';
8
8
  this.skipHistory = skipHistory;
9
9
  }
@@ -15,38 +15,12 @@ class KritzelBaseCommand {
15
15
  }
16
16
  }
17
17
 
18
- class ObjectHelper {
19
- static generateUUID() {
20
- return Math.random().toString(36).substr(2, 9);
21
- }
22
- static clone(objOrObjs) {
23
- const cloneObject = (obj) => {
24
- const { _store, _elementRef, totalWidth, totalHeight, element, ...remainingProps } = obj;
25
- const clonedProps = structuredClone(remainingProps);
26
- if (element && typeof element === 'object' && 'nodeType' in element && element.nodeType === 1) {
27
- clonedProps.element = element.cloneNode(true);
28
- }
29
- return clonedProps;
30
- };
31
- if (Array.isArray(objOrObjs)) {
32
- return objOrObjs.map(cloneObject);
33
- }
34
- return cloneObject(objOrObjs);
35
- }
36
- static isEmpty(obj) {
37
- if (obj === null || obj === undefined) {
38
- return true;
39
- }
40
- return Object?.keys(obj).length === 0 && obj?.constructor === Object;
41
- }
42
- }
43
-
44
18
  class UpdateObjectCommand extends KritzelBaseCommand {
45
19
  object;
46
20
  updatedProperties;
47
21
  previousProperties;
48
- constructor(store, initiator, object, updatedProperties, skipHistory = false) {
49
- super(store, initiator, skipHistory);
22
+ constructor(core, initiator, object, updatedProperties, skipHistory = false) {
23
+ super(core, initiator, skipHistory);
50
24
  this.object = object;
51
25
  this.updatedProperties = updatedProperties;
52
26
  this.previousProperties = {};
@@ -62,7 +36,8 @@ class UpdateObjectCommand extends KritzelBaseCommand {
62
36
  this.object[key] = this.updatedProperties[key];
63
37
  }
64
38
  }
65
- this._store.updateObjectInDatabase(ObjectHelper.clone(this.object));
39
+ this._core.store.state.objectsMap.update(this.object);
40
+ this._core.updateObjectInDatabase(this.object);
66
41
  }
67
42
  undo() {
68
43
  for (const key in this.previousProperties) {
@@ -70,14 +45,15 @@ class UpdateObjectCommand extends KritzelBaseCommand {
70
45
  this.object[key] = this.previousProperties[key];
71
46
  }
72
47
  }
73
- this._store.updateObjectInDatabase(ObjectHelper.clone(this.object));
48
+ this._core.store.state.objectsMap.update(this.object);
49
+ this._core.updateObjectInDatabase(this.object);
74
50
  }
75
51
  }
76
52
 
77
53
  class KritzelToolRegistry {
78
54
  static registry = {};
79
- static registerTool(toolName, constructor, store) {
80
- const toolInstance = new constructor(store);
55
+ static registerTool(toolName, constructor, core) {
56
+ const toolInstance = new constructor(core);
81
57
  toolInstance.name = toolName;
82
58
  this.registry[toolName] = toolInstance;
83
59
  return toolInstance;
@@ -95,9 +71,9 @@ class KritzelToolRegistry {
95
71
  class KritzelBaseTool {
96
72
  __class__ = this.constructor.name;
97
73
  name = 'base-tool';
98
- _store;
99
- constructor(store) {
100
- this._store = store;
74
+ _core;
75
+ constructor(core) {
76
+ this._core = core;
101
77
  }
102
78
  onActivate() {
103
79
  // default implementation
@@ -117,7 +93,13 @@ class KritzelBaseTool {
117
93
  handleWheel(_event) {
118
94
  // default implementation
119
95
  }
120
- revive(object) {
96
+ serialize() {
97
+ return {
98
+ __class__: this.__class__,
99
+ name: this.name,
100
+ };
101
+ }
102
+ deserialize(object) {
121
103
  Object.assign(this, object);
122
104
  return this;
123
105
  }
@@ -125,17 +107,17 @@ class KritzelBaseTool {
125
107
 
126
108
  class AddObjectCommand extends KritzelBaseCommand {
127
109
  object;
128
- constructor(store, initiator, object, skipHistory = false) {
129
- super(store, initiator, skipHistory);
110
+ constructor(core, initiator, object, skipHistory = false) {
111
+ super(core, initiator, skipHistory);
130
112
  this.object = object;
131
113
  }
132
114
  execute() {
133
- this._store.state.objectsMap.insert(this.object);
134
- this._store.addObjectToDatabase(ObjectHelper.clone(this.object));
115
+ this._core.store.state.objectsMap.insert(this.object);
116
+ this._core.addObjectToDatabase(this.object);
135
117
  }
136
118
  undo() {
137
- this._store.state.objectsMap.remove(object => object.id === this.object.id);
138
- this._store.deleteObjectFromDatabase(this.object.id);
119
+ this._core.store.state.objectsMap.remove(object => object.id === this.object.id);
120
+ this._core.deleteObjectFromDatabase(this.object.id);
139
121
  }
140
122
  }
141
123
 
@@ -161,11 +143,7 @@ class KritzelEventHelper {
161
143
  const contextMenu = path.find(element => element.classList && element.classList.contains('context-menu'));
162
144
  return !!contextMenu;
163
145
  }
164
- static onLongTouchPress(event, onSuccess, onCancel) {
165
- if (event.pointerType !== 'touch') {
166
- onCancel?.();
167
- return () => { };
168
- }
146
+ static onLongPress(event, onSuccess, onCancel) {
169
147
  const longPressTimeout = 400;
170
148
  const moveThreshold = 10;
171
149
  const startX = event.clientX;
@@ -273,8 +251,8 @@ class KritzelTextTool extends KritzelBaseTool {
273
251
  '#808000',
274
252
  '#800080',
275
253
  ];
276
- constructor(store) {
277
- super(store);
254
+ constructor(core) {
255
+ super(core);
278
256
  }
279
257
  handlePointerDown(event) {
280
258
  if (event.cancelable) {
@@ -283,66 +261,66 @@ class KritzelTextTool extends KritzelBaseTool {
283
261
  if (event.pointerType === 'mouse') {
284
262
  const path = event.composedPath().slice(1);
285
263
  const objectElement = path.find(element => element.classList && element.classList.contains('object'));
286
- const object = this._store.findObjectById(objectElement?.id);
287
- if (this._store.state.activeText === null && object && object instanceof KritzelText) {
288
- this._store.state.activeText = object;
264
+ const object = this._core.findObjectById(objectElement?.id);
265
+ if (this._core.store.state.activeText === null && object && object instanceof KritzelText) {
266
+ this._core.store.setState('activeText', object);
289
267
  object.focus();
290
268
  return;
291
269
  }
292
- if (this._store.state.activeText !== null && object instanceof KritzelText) {
270
+ if (this._core.store.state.activeText !== null && object instanceof KritzelText) {
293
271
  object.focus();
294
272
  return;
295
273
  }
296
- if (this._store.state.activeText !== null) {
297
- this._store.resetActiveText();
298
- this._store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
274
+ if (this._core.store.state.activeText !== null) {
275
+ this._core.resetActiveText();
276
+ this._core.store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
299
277
  return;
300
278
  }
301
279
  if (KritzelEventHelper.isLeftClick(event) === false) {
302
280
  return;
303
281
  }
304
- const clientX = event.clientX - this._store.offsetX;
305
- const clientY = event.clientY - this._store.offsetY;
306
- const text = KritzelText.create(this._store, this.fontSize, this.fontFamily);
282
+ const clientX = event.clientX - this._core.store.offsetX;
283
+ const clientY = event.clientY - this._core.store.offsetY;
284
+ const text = KritzelText.create(this._core, this.fontSize, this.fontFamily);
307
285
  text.fontColor = this.fontColor;
308
- text.translateX = (clientX - this._store.state.translateX) / this._store.state.scale;
309
- text.translateY = (clientY - this._store.state.translateY) / this._store.state.scale;
310
- text.zIndex = this._store.currentZIndex;
311
- this._store.state.activeText = text;
312
- this._store.history.executeCommand(new AddObjectCommand(this._store, this, text));
286
+ text.translateX = (clientX - this._core.store.state.translateX) / this._core.store.state.scale;
287
+ text.translateY = (clientY - this._core.store.state.translateY) / this._core.store.state.scale;
288
+ text.zIndex = this._core.store.currentZIndex;
289
+ this._core.store.setState('activeText', text);
290
+ this._core.history.executeCommand(new AddObjectCommand(this._core, this, text));
313
291
  }
314
292
  if (event.pointerType === 'touch') {
315
- const activePointers = Array.from(this._store.state.pointers.values());
293
+ const activePointers = Array.from(this._core.store.state.pointers.values());
316
294
  const path = event.composedPath().slice(1);
317
295
  const objectElement = path.find(element => element.classList && element.classList.contains('object'));
318
- const object = this._store.findObjectById(objectElement?.id);
319
- if (this._store.state.activeText === null && object && object instanceof KritzelText) {
320
- this._store.state.activeText = object;
296
+ const object = this._core.findObjectById(objectElement?.id);
297
+ if (this._core.store.state.activeText === null && object && object instanceof KritzelText) {
298
+ this._core.store.setState('activeText', object);
321
299
  object.focus();
322
300
  return;
323
301
  }
324
- if (this._store.state.activeText !== null && object instanceof KritzelText) {
302
+ if (this._core.store.state.activeText !== null && object instanceof KritzelText) {
325
303
  object.focus();
326
304
  return;
327
305
  }
328
- if (this._store.state.activeText !== null) {
329
- this._store.resetActiveText();
330
- this._store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
306
+ if (this._core.store.state.activeText !== null) {
307
+ this._core.resetActiveText();
308
+ this._core.store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
331
309
  return;
332
310
  }
333
311
  if (activePointers.length > 1) {
334
312
  return;
335
313
  }
336
314
  KritzelKeyboardHelper.disableInteractiveWidget();
337
- const clientX = Math.round(activePointers[0].clientX - this._store.offsetX);
338
- const clientY = Math.round(activePointers[0].clientY - this._store.offsetY);
339
- const text = KritzelText.create(this._store, this.fontSize, this.fontFamily);
315
+ const clientX = Math.round(activePointers[0].clientX - this._core.store.offsetX);
316
+ const clientY = Math.round(activePointers[0].clientY - this._core.store.offsetY);
317
+ const text = KritzelText.create(this._core, this.fontSize, this.fontFamily);
340
318
  text.fontColor = this.fontColor;
341
- text.translateX = (clientX - this._store.state.translateX) / this._store.state.scale;
342
- text.translateY = (clientY - this._store.state.translateY) / this._store.state.scale;
343
- text.zIndex = this._store.currentZIndex;
344
- this._store.state.activeText = text;
345
- this._store.history.executeCommand(new AddObjectCommand(this._store, this, text));
319
+ text.translateX = (clientX - this._core.store.state.translateX) / this._core.store.state.scale;
320
+ text.translateY = (clientY - this._core.store.state.translateY) / this._core.store.state.scale;
321
+ text.zIndex = this._core.store.currentZIndex;
322
+ this._core.store.setState('activeText', text);
323
+ this._core.history.executeCommand(new AddObjectCommand(this._core, this, text));
346
324
  }
347
325
  }
348
326
  handlePointerUp(event) {
@@ -350,17 +328,29 @@ class KritzelTextTool extends KritzelBaseTool {
350
328
  event.preventDefault();
351
329
  }
352
330
  if (event.pointerType === 'mouse') {
353
- this._store.state.activeText?.updateTextareaDimensions();
354
- this._store.state.activeText?.focus();
331
+ this._core.store.state.activeText?.updateTextareaDimensions();
332
+ this._core.store.state.activeText?.focus();
355
333
  }
356
334
  if (event.pointerType === 'touch') {
357
- this._store.state.activeText?.updateTextareaDimensions();
358
- this._store.state.activeText?.focus();
335
+ this._core.store.state.activeText?.updateTextareaDimensions();
336
+ this._core.store.state.activeText?.focus();
359
337
  KritzelKeyboardHelper.enableInteractiveWidget();
360
338
  }
361
339
  }
362
340
  }
363
341
 
342
+ class ObjectHelper {
343
+ static generateUUID() {
344
+ return Math.random().toString(36).substr(2, 9);
345
+ }
346
+ static isEmpty(obj) {
347
+ if (obj === null || obj === undefined) {
348
+ return true;
349
+ }
350
+ return Object?.keys(obj).length === 0 && obj?.constructor === Object;
351
+ }
352
+ }
353
+
364
354
  class KritzelGeometryHelper {
365
355
  static doPolygonsIntersect(polygon1, polygon2) {
366
356
  // 1. Convert polygons to array of points for easier processing
@@ -416,7 +406,7 @@ class KritzelGeometryHelper {
416
406
 
417
407
  class KritzelBaseObject {
418
408
  __class__ = 'KritzelBaseObject';
419
- _store;
409
+ _core;
420
410
  _elementRef;
421
411
  id;
422
412
  workspaceId;
@@ -530,11 +520,11 @@ class KritzelBaseObject {
530
520
  constructor() {
531
521
  this.id = this.generateId();
532
522
  }
533
- static create(store) {
523
+ static create(core) {
534
524
  const object = new KritzelBaseObject();
535
- object._store = store;
536
- object.zIndex = store.currentZIndex;
537
- object.workspaceId = store.state.activeWorkspace.id;
525
+ object._core = core;
526
+ object.zIndex = core.store.currentZIndex;
527
+ object.workspaceId = core.store.state.activeWorkspace.id;
538
528
  return object;
539
529
  }
540
530
  mount(element) {
@@ -561,23 +551,23 @@ class KritzelBaseObject {
561
551
  }
562
552
  isInViewport() {
563
553
  const viewportBounds = {
564
- x: -this._store.state.translateX / this._store.state.scale,
565
- y: -this._store.state.translateY / this._store.state.scale,
566
- width: this._store.state.viewportWidth / this._store.state.scale,
567
- height: this._store.state.viewportHeight / this._store.state.scale};
554
+ x: -this._core.store.state.translateX / this._core.store.state.scale,
555
+ y: -this._core.store.state.translateY / this._core.store.state.scale,
556
+ width: this._core.store.state.viewportWidth / this._core.store.state.scale,
557
+ height: this._core.store.state.viewportHeight / this._core.store.state.scale};
568
558
  return (this.boundingBox.x < viewportBounds.x + viewportBounds.width &&
569
559
  this.boundingBox.x + this.boundingBox.width > viewportBounds.x &&
570
560
  this.boundingBox.y < viewportBounds.y + viewportBounds.height &&
571
561
  this.boundingBox.y + this.boundingBox.height > viewportBounds.y);
572
562
  }
573
563
  centerInViewport() {
574
- const scale = this._store.state.scale;
575
- this.translateX = (this._store.state.viewportWidth / 2 - this.totalWidth / 2 - this._store.state.translateX) / scale;
576
- this.translateY = (this._store.state.viewportHeight / 2 - this.totalHeight / 2 - this._store.state.translateY) / scale;
564
+ const scale = this._core.store.state.scale;
565
+ this.translateX = (this._core.store.state.viewportWidth / 2 - this.totalWidth / 2 - this._core.store.state.translateX) / scale;
566
+ this.translateY = (this._core.store.state.viewportHeight / 2 - this.totalHeight / 2 - this._core.store.state.translateY) / scale;
577
567
  }
578
568
  move(startX, startY, endX, endY) {
579
- const deltaX = (startX - endX) / this._store.state.scale;
580
- const deltaY = (startY - endY) / this._store.state.scale;
569
+ const deltaX = (startX - endX) / this._core.store.state.scale;
570
+ const deltaY = (startY - endY) / this._core.store.state.scale;
581
571
  this.translateX += deltaX;
582
572
  this.translateY += deltaY;
583
573
  }
@@ -593,6 +583,11 @@ class KritzelBaseObject {
593
583
  rotate(value) {
594
584
  this.rotation = value;
595
585
  }
586
+ clone() {
587
+ const clone = new KritzelBaseObject();
588
+ Object.assign(clone, this);
589
+ return clone;
590
+ }
596
591
  copy() {
597
592
  const copiedObject = Object.create(Object.getPrototypeOf(this));
598
593
  Object.assign(copiedObject, this);
@@ -603,7 +598,15 @@ class KritzelBaseObject {
603
598
  onSelectedClick() {
604
599
  // This method can be overridden by subclasses to handle click events when the object is selected.
605
600
  }
606
- revive(object) {
601
+ serialize() {
602
+ const { _core, _elementRef, element, totalWidth, totalHeight, ...remainingProps } = this;
603
+ const clonedProps = structuredClone(remainingProps);
604
+ if (element && typeof element === 'object' && 'nodeType' in element && element.nodeType === 1) {
605
+ clonedProps.element = element.cloneNode(true);
606
+ }
607
+ return clonedProps;
608
+ }
609
+ deserialize(object) {
607
610
  Object.assign(this, object);
608
611
  return this;
609
612
  }
@@ -623,7 +626,7 @@ class KritzelBaseObject {
623
626
  updatePosition(x, y) {
624
627
  this.translateX = x;
625
628
  this.translateY = y;
626
- this._store.state.objectsMap.update(this);
629
+ this._core.store.state.objectsMap.update(this);
627
630
  }
628
631
  }
629
632
 
@@ -639,7 +642,7 @@ class KritzelText extends KritzelBaseObject {
639
642
  isEditable = true;
640
643
  rows = 1;
641
644
  get isReadonly() {
642
- return !(this._store.state.activeTool instanceof KritzelTextTool);
645
+ return !(this._core.store.state.activeTool instanceof KritzelTextTool);
643
646
  }
644
647
  constructor(config) {
645
648
  super();
@@ -655,22 +658,22 @@ class KritzelText extends KritzelBaseObject {
655
658
  this.scale = config.scale || 1;
656
659
  }
657
660
  }
658
- static create(store, fontSize, fontFamily) {
661
+ static create(core, fontSize, fontFamily) {
659
662
  const object = new KritzelText();
660
- object._store = store;
663
+ object._core = core;
661
664
  object.id = object.generateId();
662
- object.workspaceId = store.state.activeWorkspace.id;
665
+ object.workspaceId = core.store.state.activeWorkspace.id;
663
666
  object.fontSize = fontSize;
664
667
  object.fontFamily = fontFamily;
665
668
  object.translateX = 0;
666
669
  object.translateY = 0;
667
- object.width = object.initialWidth / (object._store.state.scale < 0 ? object._store.state.scale : 1);
668
- object.height = (object.fontSize * 1.2) / (object._store.state.scale < 0 ? object._store.state.scale : 1);
670
+ object.width = object.initialWidth / (object._core.store.state.scale < 0 ? object._core.store.state.scale : 1);
671
+ object.height = (object.fontSize * 1.2) / (object._core.store.state.scale < 0 ? object._core.store.state.scale : 1);
669
672
  object.padding = 5;
670
673
  object.backgroundColor = 'transparent';
671
- object.scale = object._store.state.scale;
674
+ object.scale = object._core.store.state.scale;
672
675
  object.value = ' ';
673
- object.zIndex = store.currentZIndex;
676
+ object.zIndex = core.store.currentZIndex;
674
677
  return object;
675
678
  }
676
679
  mount(element) {
@@ -724,7 +727,7 @@ class KritzelText extends KritzelBaseObject {
724
727
  document.body.removeChild(span);
725
728
  this.width = textWidth;
726
729
  this.height = textHeight;
727
- this._store.history.executeCommand(new UpdateObjectCommand(this._store, this, this, { ...this }));
730
+ this._core.history.executeCommand(new UpdateObjectCommand(this._core, this, this, { ...this }));
728
731
  }
729
732
  }
730
733
  focus() {
@@ -757,10 +760,10 @@ class KritzelText extends KritzelBaseObject {
757
760
  }
758
761
  }
759
762
  edit() {
760
- this._store.setState('activeTool', KritzelToolRegistry.getTool('text'));
761
- this._store.state.selectionGroup = null;
762
- this._store.state.selectionBox = null;
763
- this._store.state.activeText = this;
763
+ this._core.store.setState('activeTool', KritzelToolRegistry.getTool('text'));
764
+ this._core.store.setState('selectionGroup', null);
765
+ this._core.store.setState('selectionBox', null);
766
+ this._core.store.setState('activeText', this);
764
767
  setTimeout(() => {
765
768
  this.focus();
766
769
  }, 300);
@@ -820,11 +823,11 @@ class KritzelPath extends KritzelBaseObject {
820
823
  this.d = this.generateSvgPath();
821
824
  this.updateDimensions();
822
825
  }
823
- static create(store, options) {
826
+ static create(core, options) {
824
827
  const object = new KritzelPath();
825
- object._store = store;
828
+ object._core = core;
826
829
  object.id = object.generateId();
827
- object.workspaceId = store.state.activeWorkspace.id;
830
+ object.workspaceId = core.store.state.activeWorkspace.id;
828
831
  object.options = options;
829
832
  object.points = options?.points ?? [];
830
833
  object.translateX = options?.translateX ?? 0;
@@ -832,7 +835,7 @@ class KritzelPath extends KritzelBaseObject {
832
835
  object.scale = options?.scale ?? 1;
833
836
  object.strokeWidth = options?.strokeWidth ?? 8;
834
837
  object.fill = options?.fill ?? '#000000';
835
- object.zIndex = store.currentZIndex;
838
+ object.zIndex = core.store.currentZIndex;
836
839
  object.d = object.generateSvgPath();
837
840
  object.updateDimensions();
838
841
  return object;
@@ -860,8 +863,8 @@ class KritzelPath extends KritzelBaseObject {
860
863
  this._adjustedPoints = null;
861
864
  }
862
865
  move(startX, startY, endX, endY) {
863
- const deltaX = (startX - endX) / this._store.state.scale;
864
- const deltaY = (startY - endY) / this._store.state.scale;
866
+ const deltaX = (startX - endX) / this._core.store.state.scale;
867
+ const deltaY = (startY - endY) / this._core.store.state.scale;
865
868
  this.translateX += deltaX;
866
869
  this.translateY += deltaY;
867
870
  this._adjustedPoints = null;
@@ -940,7 +943,7 @@ class KritzelPath extends KritzelBaseObject {
940
943
  this.translateX = x;
941
944
  this.translateY = y;
942
945
  this._adjustedPoints = null;
943
- this._store.state.objectsMap.update(this);
946
+ this._core.store.state.objectsMap.update(this);
944
947
  }
945
948
  computeAdjustedPoints() {
946
949
  if (!this.points?.length) {
@@ -1071,17 +1074,17 @@ class KritzelImage extends KritzelBaseObject {
1071
1074
  this.translateY = config?.translateY || 0;
1072
1075
  this.scale = config?.scale || 1;
1073
1076
  }
1074
- static create(store) {
1077
+ static create(core) {
1075
1078
  const object = new KritzelImage();
1076
- object._store = store;
1079
+ object._core = core;
1077
1080
  object.id = object.generateId();
1078
- object.workspaceId = store.state.activeWorkspace.id;
1081
+ object.workspaceId = core.store.state.activeWorkspace.id;
1079
1082
  object.x = 0;
1080
1083
  object.y = 0;
1081
1084
  object.translateX = 0;
1082
1085
  object.translateY = 0;
1083
- object.scale = object._store.state.scale;
1084
- object.zIndex = store.currentZIndex;
1086
+ object.scale = object._core.store.state.scale;
1087
+ object.zIndex = core.store.currentZIndex;
1085
1088
  return object;
1086
1089
  }
1087
1090
  resize(x, y, width, height) {
@@ -1116,8 +1119,8 @@ class KritzelBrushTool extends KritzelBaseTool {
1116
1119
  pen: ['#000000', '#FFFFFF', '#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#FF00FF', '#00FFFF', '#808080', '#C0C0C0', '#800000', '#008000', '#000080', '#808000', '#800080'],
1117
1120
  highlighter: ['#ffff00', '#ffb347', '#b4ffb4'],
1118
1121
  };
1119
- constructor(store) {
1120
- super(store);
1122
+ constructor(core) {
1123
+ super(core);
1121
1124
  }
1122
1125
  handlePointerDown(event) {
1123
1126
  if (event.cancelable) {
@@ -1125,34 +1128,34 @@ class KritzelBrushTool extends KritzelBaseTool {
1125
1128
  }
1126
1129
  if (event.pointerType === 'mouse') {
1127
1130
  if (KritzelEventHelper.isLeftClick(event)) {
1128
- this._store.state.isDrawing = true;
1129
- const x = event.clientX - this._store.offsetX;
1130
- const y = event.clientY - this._store.offsetY;
1131
- this._store.state.currentPath = KritzelPath.create(this._store, {
1131
+ this._core.store.setState('isDrawing', true);
1132
+ const x = event.clientX - this._core.store.offsetX;
1133
+ const y = event.clientY - this._core.store.offsetY;
1134
+ this._core.store.setState('currentPath', KritzelPath.create(this._core, {
1132
1135
  points: [[x, y]],
1133
- translateX: -this._store.state.translateX,
1134
- translateY: -this._store.state.translateY,
1135
- scale: this._store.state.scale,
1136
+ translateX: -this._core.store.state.translateX,
1137
+ translateY: -this._core.store.state.translateY,
1138
+ scale: this._core.store.state.scale,
1136
1139
  fill: this.color,
1137
1140
  strokeWidth: this.size,
1138
- });
1141
+ }));
1139
1142
  }
1140
1143
  }
1141
1144
  if (event.pointerType === 'touch') {
1142
- const activePointers = Array.from(this._store.state.pointers.values());
1145
+ const activePointers = Array.from(this._core.store.state.pointers.values());
1143
1146
  if (activePointers.length === 1) {
1144
- const x = Math.round(activePointers[0].clientX - this._store.offsetX);
1145
- const y = Math.round(activePointers[0].clientY - this._store.offsetY);
1146
- this._store.state.isDrawing = true;
1147
- this._store.state.currentPath = KritzelPath.create(this._store, {
1147
+ const x = Math.round(activePointers[0].clientX - this._core.store.offsetX);
1148
+ const y = Math.round(activePointers[0].clientY - this._core.store.offsetY);
1149
+ this._core.store.setState('isDrawing', true);
1150
+ this._core.store.setState('currentPath', KritzelPath.create(this._core, {
1148
1151
  points: [[x, y]],
1149
- translateX: -this._store.state.translateX,
1150
- translateY: -this._store.state.translateY,
1151
- scale: this._store.state.scale,
1152
+ translateX: -this._core.store.state.translateX,
1153
+ translateY: -this._core.store.state.translateY,
1154
+ scale: this._core.store.state.scale,
1152
1155
  fill: this.color,
1153
1156
  strokeWidth: this.size,
1154
- });
1155
- this._store.rerender();
1157
+ }));
1158
+ this._core.rerender();
1156
1159
  }
1157
1160
  }
1158
1161
  }
@@ -1161,34 +1164,34 @@ class KritzelBrushTool extends KritzelBaseTool {
1161
1164
  event.preventDefault();
1162
1165
  }
1163
1166
  if (event.pointerType === 'mouse') {
1164
- if (this._store.state.isDrawing) {
1165
- const x = event.clientX - this._store.offsetX;
1166
- const y = event.clientY - this._store.offsetY;
1167
- this._store.state.currentPath = KritzelPath.create(this._store, {
1168
- points: [...this._store.state.currentPath.points, [x, y]],
1169
- translateX: -this._store.state.translateX,
1170
- translateY: -this._store.state.translateY,
1171
- scale: this._store.state.scale,
1167
+ if (this._core.store.state.isDrawing) {
1168
+ const x = event.clientX - this._core.store.offsetX;
1169
+ const y = event.clientY - this._core.store.offsetY;
1170
+ this._core.store.setState('currentPath', KritzelPath.create(this._core, {
1171
+ points: [...this._core.store.state.currentPath.points, [x, y]],
1172
+ translateX: -this._core.store.state.translateX,
1173
+ translateY: -this._core.store.state.translateY,
1174
+ scale: this._core.store.state.scale,
1172
1175
  fill: this.color,
1173
1176
  strokeWidth: this.size,
1174
- });
1175
- this._store.rerender();
1177
+ }));
1178
+ this._core.rerender();
1176
1179
  }
1177
1180
  }
1178
1181
  if (event.pointerType === 'touch') {
1179
- const activePointers = Array.from(this._store.state.pointers.values());
1182
+ const activePointers = Array.from(this._core.store.state.pointers.values());
1180
1183
  if (activePointers.length === 1) {
1181
- const x = Math.round(activePointers[0].clientX - this._store.offsetX);
1182
- const y = Math.round(activePointers[0].clientY - this._store.offsetY);
1183
- this._store.state.currentPath = KritzelPath.create(this._store, {
1184
- points: [...this._store.state.currentPath.points, [x, y]],
1185
- translateX: -this._store.state.translateX,
1186
- translateY: -this._store.state.translateY,
1187
- scale: this._store.state.scale,
1184
+ const x = Math.round(activePointers[0].clientX - this._core.store.offsetX);
1185
+ const y = Math.round(activePointers[0].clientY - this._core.store.offsetY);
1186
+ this._core.store.setState('currentPath', KritzelPath.create(this._core, {
1187
+ points: [...this._core.store.state.currentPath.points, [x, y]],
1188
+ translateX: -this._core.store.state.translateX,
1189
+ translateY: -this._core.store.state.translateY,
1190
+ scale: this._core.store.state.scale,
1188
1191
  fill: this.color,
1189
1192
  strokeWidth: this.size,
1190
- });
1191
- this._store.rerender();
1193
+ }));
1194
+ this._core.rerender();
1192
1195
  }
1193
1196
  }
1194
1197
  }
@@ -1197,24 +1200,28 @@ class KritzelBrushTool extends KritzelBaseTool {
1197
1200
  event.preventDefault();
1198
1201
  }
1199
1202
  if (event.pointerType === 'mouse') {
1200
- if (this._store.state.isDrawing) {
1201
- this._store.state.isDrawing = false;
1202
- if (this._store.state.currentPath) {
1203
- this._store.state.currentPath.zIndex = this._store.currentZIndex;
1204
- this._store.history.executeCommand(new AddObjectCommand(this._store, this, this._store.state.currentPath));
1203
+ if (this._core.store.state.isDrawing) {
1204
+ this._core.store.setState('isDrawing', false);
1205
+ if (this._core.store.state.currentPath) {
1206
+ const currentPath = this._core.store.state.currentPath;
1207
+ currentPath.zIndex = this._core.store.currentZIndex;
1208
+ this._core.store.setState('currentPath', currentPath);
1209
+ this._core.history.executeCommand(new AddObjectCommand(this._core, this, this._core.store.state.currentPath));
1205
1210
  }
1206
- this._store.state.currentPath = undefined;
1211
+ this._core.store.setState('currentPath', undefined);
1207
1212
  }
1208
1213
  }
1209
1214
  if (event.pointerType === 'touch') {
1210
- if (this._store.state.isDrawing) {
1211
- this._store.state.isDrawing = false;
1212
- if (this._store.state.currentPath) {
1213
- this._store.state.currentPath.zIndex = this._store.currentZIndex;
1214
- this._store.history.executeCommand(new AddObjectCommand(this._store, this, this._store.state.currentPath));
1215
+ if (this._core.store.state.isDrawing) {
1216
+ this._core.store.setState('isDrawing', false);
1217
+ if (this._core.store.state.currentPath) {
1218
+ const currentPath = this._core.store.state.currentPath;
1219
+ currentPath.zIndex = this._core.store.currentZIndex;
1220
+ this._core.store.setState('currentPath', currentPath);
1221
+ this._core.history.executeCommand(new AddObjectCommand(this._core, this, currentPath));
1215
1222
  }
1216
- this._store.state.currentPath = undefined;
1217
- this._store.rerender();
1223
+ this._core.store.setState('currentPath', undefined);
1224
+ this._core.rerender();
1218
1225
  }
1219
1226
  }
1220
1227
  }
@@ -1222,8 +1229,8 @@ class KritzelBrushTool extends KritzelBaseTool {
1222
1229
 
1223
1230
  class BatchCommand extends KritzelBaseCommand {
1224
1231
  commands;
1225
- constructor(store, initiator, commands, skipHistory = false) {
1226
- super(store, initiator, skipHistory);
1232
+ constructor(core, initiator, commands, skipHistory = false) {
1233
+ super(core, initiator, skipHistory);
1227
1234
  this.commands = commands;
1228
1235
  }
1229
1236
  execute() {
@@ -1249,11 +1256,11 @@ class KritzelCustomElement extends KritzelBaseObject {
1249
1256
  this.width = config.width || 0;
1250
1257
  }
1251
1258
  }
1252
- static create(store, config) {
1259
+ static create(core, config) {
1253
1260
  const object = new KritzelCustomElement(config);
1254
- object._store = store;
1261
+ object._core = core;
1255
1262
  object.id = object.generateId();
1256
- object.workspaceId = store.state.activeWorkspace.id;
1263
+ object.workspaceId = core.store.state.activeWorkspace.id;
1257
1264
  return object;
1258
1265
  }
1259
1266
  mount(element) {
@@ -1289,98 +1296,98 @@ class KritzelCustomElement extends KritzelBaseObject {
1289
1296
 
1290
1297
  class RemoveObjectCommand extends KritzelBaseCommand {
1291
1298
  object;
1292
- constructor(store, initiator, object, skipHistory = false) {
1293
- super(store, initiator, skipHistory);
1299
+ constructor(core, initiator, object, skipHistory = false) {
1300
+ super(core, initiator, skipHistory);
1294
1301
  this.object = object;
1295
1302
  }
1296
1303
  execute() {
1297
- this._store.state.objectsMap.remove(object => object.id === this.object.id);
1298
- this._store.state.objectsMap.filter(object => object instanceof KritzelCustomElement).forEach(object => object.remount());
1299
- this._store.deleteObjectFromDatabase(this.object.id);
1304
+ this._core.store.state.objectsMap.remove(object => object.id === this.object.id);
1305
+ this._core.store.state.objectsMap.filter(object => object instanceof KritzelCustomElement).forEach(object => object.remount());
1306
+ this._core.deleteObjectFromDatabase(this.object.id);
1300
1307
  }
1301
1308
  undo() {
1302
- this._store.state.objectsMap.insert(this.object);
1303
- this._store.state.objectsMap.filter(object => object instanceof KritzelCustomElement).forEach(object => object.remount());
1304
- this._store.addObjectToDatabase(ObjectHelper.clone(this.object));
1309
+ this._core.store.state.objectsMap.insert(this.object);
1310
+ this._core.store.state.objectsMap.filter(object => object instanceof KritzelCustomElement).forEach(object => object.remount());
1311
+ this._core.addObjectToDatabase(this.object);
1305
1312
  }
1306
1313
  }
1307
1314
 
1308
1315
  class KritzelEraserTool extends KritzelBaseTool {
1309
1316
  touchStartTimeout = null;
1310
- constructor(store) {
1311
- super(store);
1317
+ constructor(core) {
1318
+ super(core);
1312
1319
  }
1313
1320
  handlePointerDown(event) {
1314
1321
  if (event.pointerType === 'mouse') {
1315
1322
  if (KritzelEventHelper.isLeftClick(event)) {
1316
- this._store.state.isErasing = true;
1323
+ this._core.store.setState('isErasing', true);
1317
1324
  }
1318
1325
  }
1319
1326
  if (event.pointerType === 'touch') {
1320
1327
  this.touchStartTimeout = setTimeout(() => {
1321
- if (this._store.state.pointers.size === 1 && !this._store.state.isScaling) {
1322
- this._store.state.isErasing = true;
1328
+ if (this._core.store.state.pointers.size === 1 && !this._core.store.state.isScaling) {
1329
+ this._core.store.setState('isErasing', true);
1323
1330
  }
1324
1331
  }, 80);
1325
1332
  }
1326
1333
  }
1327
1334
  handlePointerMove(event) {
1328
1335
  if (event.pointerType === 'mouse') {
1329
- if (this._store.state.isErasing) {
1330
- const selectedObjects = this._store.getObjectsFromPointerEvent(event, '.object');
1336
+ if (this._core.store.state.isErasing) {
1337
+ const selectedObjects = this._core.getObjectsFromPointerEvent(event, '.object');
1331
1338
  if (selectedObjects.length === 0)
1332
1339
  return;
1333
- const x = this._store.state.pointerX;
1334
- const y = this._store.state.pointerY;
1340
+ const x = this._core.store.state.pointerX;
1341
+ const y = this._core.store.state.pointerY;
1335
1342
  selectedObjects.forEach(selectedObject => {
1336
1343
  selectedObject.markedForRemoval = selectedObject.hitTest(x, y);
1337
1344
  });
1338
- this._store.rerender();
1345
+ this._core.rerender();
1339
1346
  }
1340
1347
  }
1341
1348
  if (event.pointerType === 'touch') {
1342
- if (this._store.state.pointers.size === 1 && this._store.state.isErasing) {
1343
- const shadowRoot = this._store.state.host?.shadowRoot;
1349
+ if (this._core.store.state.pointers.size === 1 && this._core.store.state.isErasing) {
1350
+ const shadowRoot = this._core.store.state.host?.shadowRoot;
1344
1351
  if (!shadowRoot)
1345
1352
  return;
1346
- const selectedObjects = this._store.getObjectsFromPointerEvent(event, '.object');
1353
+ const selectedObjects = this._core.getObjectsFromPointerEvent(event, '.object');
1347
1354
  if (selectedObjects.length === 0)
1348
1355
  return;
1349
- const x = this._store.state.pointerX;
1350
- const y = this._store.state.pointerY;
1356
+ const x = this._core.store.state.pointerX;
1357
+ const y = this._core.store.state.pointerY;
1351
1358
  selectedObjects.forEach(selectedObject => {
1352
1359
  selectedObject.markedForRemoval = selectedObject.hitTest(x, y);
1353
1360
  });
1354
- this._store.rerender();
1361
+ this._core.rerender();
1355
1362
  }
1356
1363
  }
1357
1364
  }
1358
1365
  handlePointerUp(event) {
1359
1366
  if (event.pointerType === 'mouse') {
1360
- if (this._store.state.isErasing) {
1361
- const removeCommands = this._store.allObjects.filter(object => object.markedForRemoval).map(object => {
1367
+ if (this._core.store.state.isErasing) {
1368
+ const removeCommands = this._core.store.allObjects.filter(object => object.markedForRemoval).map(object => {
1362
1369
  object.markedForRemoval = false;
1363
- return new RemoveObjectCommand(this._store, this, object);
1370
+ return new RemoveObjectCommand(this._core, this, object);
1364
1371
  });
1365
1372
  if (removeCommands.length > 0) {
1366
- this._store.history.executeCommand(new BatchCommand(this._store, this, removeCommands));
1373
+ this._core.history.executeCommand(new BatchCommand(this._core, this, removeCommands));
1367
1374
  }
1368
- this._store.state.isErasing = false;
1375
+ this._core.store.setState('isErasing', false);
1369
1376
  }
1370
1377
  }
1371
1378
  if (event.pointerType === 'touch') {
1372
1379
  clearTimeout(this.touchStartTimeout);
1373
- if (this._store.state.isErasing) {
1374
- const removeCommands = this._store.allObjects
1380
+ if (this._core.store.state.isErasing) {
1381
+ const removeCommands = this._core.store.allObjects
1375
1382
  .filter(object => object.markedForRemoval)
1376
1383
  .map(object => {
1377
1384
  object.markedForRemoval = false;
1378
- return new RemoveObjectCommand(this._store, this, object);
1385
+ return new RemoveObjectCommand(this._core, this, object);
1379
1386
  });
1380
1387
  if (removeCommands.length > 0) {
1381
- this._store.history.executeCommand(new BatchCommand(this._store, this, removeCommands));
1388
+ this._core.history.executeCommand(new BatchCommand(this._core, this, removeCommands));
1382
1389
  }
1383
- this._store.state.isErasing = false;
1390
+ this._core.store.setState('isErasing', false);
1384
1391
  }
1385
1392
  }
1386
1393
  }
@@ -1388,18 +1395,18 @@ class KritzelEraserTool extends KritzelBaseTool {
1388
1395
 
1389
1396
  class RemoveSelectionGroupCommand extends KritzelBaseCommand {
1390
1397
  previousSelectionGroup;
1391
- constructor(store, initiator, skipHistory = false) {
1392
- super(store, initiator, skipHistory);
1393
- this.previousSelectionGroup = this._store.state.selectionGroup;
1398
+ constructor(core, initiator, skipHistory = false) {
1399
+ super(core, initiator, skipHistory);
1400
+ this.previousSelectionGroup = this._core.store.state.selectionGroup;
1394
1401
  }
1395
1402
  execute() {
1396
- this._store.state.objectsMap.remove(object => object.id === this.previousSelectionGroup?.id);
1397
- this._store.state.selectionGroup = null;
1403
+ this._core.store.state.objectsMap.remove(object => object.id === this.previousSelectionGroup?.id);
1404
+ this._core.store.setState('selectionGroup', null);
1398
1405
  }
1399
1406
  undo() {
1400
1407
  if (this.previousSelectionGroup) {
1401
- this._store.state.objectsMap.insert(this.previousSelectionGroup);
1402
- this._store.state.selectionGroup = this.previousSelectionGroup;
1408
+ this._core.store.state.objectsMap.insert(this.previousSelectionGroup);
1409
+ this._core.store.setState('selectionGroup', this.previousSelectionGroup);
1403
1410
  }
1404
1411
  }
1405
1412
  }
@@ -1411,33 +1418,41 @@ class MoveSelectionGroupCommand extends KritzelBaseCommand {
1411
1418
  endX;
1412
1419
  endY;
1413
1420
  skipExecution;
1414
- constructor(store, initiator, startX, startY, endX, endY, skipFirstExecution = false, skipHistory = false) {
1415
- super(store, initiator, skipHistory);
1421
+ constructor(core, initiator, startX, startY, endX, endY, skipFirstExecution = false, skipHistory = false) {
1422
+ super(core, initiator, skipHistory);
1416
1423
  this.startX = startX;
1417
1424
  this.startY = startY;
1418
1425
  this.endX = endX;
1419
1426
  this.endY = endY;
1420
1427
  this.skipExecution = skipFirstExecution;
1421
- this.selectionGroup = this._store.state.selectionGroup;
1428
+ this.selectionGroup = this._core.store.state.selectionGroup;
1422
1429
  }
1423
1430
  execute() {
1424
1431
  if (this.skipExecution) {
1425
1432
  this.skipExecution = false;
1426
1433
  return;
1427
1434
  }
1428
- this._store.state.selectionGroup = this.selectionGroup;
1429
- this._store.state.selectionGroup.move(this.startX, this.startY, this.endX, this.endY);
1435
+ this._core.store.setState('selectionGroup', this.selectionGroup);
1436
+ this._core.store.state.selectionGroup.move(this.startX, this.startY, this.endX, this.endY);
1437
+ this._core.store.state.selectionGroup.objects.forEach(object => {
1438
+ this._core.store.state.objectsMap.update(object);
1439
+ this._core.updateObjectInDatabase(object);
1440
+ });
1430
1441
  }
1431
1442
  undo() {
1432
- this._store.state.selectionGroup = this.selectionGroup;
1433
- this._store.state.selectionGroup.move(this.endX, this.endY, this.startX, this.startY);
1443
+ this._core.store.setState('selectionGroup', this.selectionGroup);
1444
+ this._core.store.state.selectionGroup.move(this.endX, this.endY, this.startX, this.startY);
1445
+ this._core.store.state.selectionGroup.objects.forEach(object => {
1446
+ this._core.store.state.objectsMap.update(object);
1447
+ this._core.updateObjectInDatabase(object);
1448
+ });
1434
1449
  }
1435
1450
  }
1436
1451
 
1437
1452
  class KritzelBaseHandler {
1438
- _store;
1439
- constructor(store) {
1440
- this._store = store;
1453
+ _core;
1454
+ constructor(core) {
1455
+ this._core = core;
1441
1456
  }
1442
1457
  }
1443
1458
 
@@ -1448,16 +1463,26 @@ class KritzelMoveHandler extends KritzelBaseHandler {
1448
1463
  startY;
1449
1464
  endX;
1450
1465
  endY;
1451
- constructor(store) {
1452
- super(store);
1466
+ hasMoved = false;
1467
+ constructor(core) {
1468
+ super(core);
1469
+ }
1470
+ reset() {
1471
+ this.dragStartX = 0;
1472
+ this.dragStartY = 0;
1473
+ this.startX = 0;
1474
+ this.startY = 0;
1475
+ this.endX = 0;
1476
+ this.endY = 0;
1477
+ this.hasMoved = false;
1453
1478
  }
1454
1479
  handlePointerDown(event) {
1455
1480
  if (event.pointerType === 'mouse') {
1456
1481
  if (KritzelEventHelper.isLeftClick(event)) {
1457
- if (this._store.state.selectionGroup?.isSelected && !this._store.state.isResizeHandleSelected && !this._store.state.isRotationHandleSelected) {
1458
- const clientX = event.clientX - this._store.offsetX;
1459
- const clientY = event.clientY - this._store.offsetY;
1460
- this._store.state.isDragging = true;
1482
+ if (this._core.store.state.selectionGroup?.isSelected && !this._core.store.state.isResizeHandleSelected && !this._core.store.state.isRotationHandleSelected) {
1483
+ const clientX = event.clientX - this._core.store.offsetX;
1484
+ const clientY = event.clientY - this._core.store.offsetY;
1485
+ this._core.store.setState('isDragging', true);
1461
1486
  this.dragStartX = clientX;
1462
1487
  this.dragStartY = clientY;
1463
1488
  this.startX = this.dragStartX;
@@ -1466,11 +1491,11 @@ class KritzelMoveHandler extends KritzelBaseHandler {
1466
1491
  }
1467
1492
  }
1468
1493
  if (event.pointerType === 'touch') {
1469
- const activePointers = Array.from(this._store.state.pointers.values());
1470
- if (this._store.state.pointers.size === 1) {
1471
- if (this._store.state.selectionGroup?.isSelected && !this._store.state.isResizeHandleSelected && !this._store.state.isRotationHandleSelected) {
1472
- const x = Math.round(activePointers[0].clientX - this._store.offsetX);
1473
- const y = Math.round(activePointers[0].clientY - this._store.offsetY);
1494
+ const activePointers = Array.from(this._core.store.state.pointers.values());
1495
+ if (this._core.store.state.pointers.size === 1) {
1496
+ if (this._core.store.state.selectionGroup?.isSelected && !this._core.store.state.isResizeHandleSelected && !this._core.store.state.isRotationHandleSelected) {
1497
+ const x = Math.round(activePointers[0].clientX - this._core.store.offsetX);
1498
+ const y = Math.round(activePointers[0].clientY - this._core.store.offsetY);
1474
1499
  this.dragStartX = x;
1475
1500
  this.dragStartY = y;
1476
1501
  this.startX = x;
@@ -1481,30 +1506,35 @@ class KritzelMoveHandler extends KritzelBaseHandler {
1481
1506
  }
1482
1507
  handlePointerMove(event) {
1483
1508
  if (event.pointerType === 'mouse') {
1484
- if (this._store.state.isDragging && this._store.state.selectionGroup) {
1485
- const clientX = event.clientX - this._store.offsetX;
1486
- const clientY = event.clientY - this._store.offsetY;
1509
+ if (this._core.store.state.isDragging && this._core.store.state.selectionGroup) {
1510
+ const clientX = event.clientX - this._core.store.offsetX;
1511
+ const clientY = event.clientY - this._core.store.offsetY;
1487
1512
  this.endX = clientX;
1488
1513
  this.endY = clientY;
1489
- this._store.state.selectionGroup.move(clientX, clientY, this.dragStartX, this.dragStartY);
1514
+ this._core.store.state.selectionGroup.move(clientX, clientY, this.dragStartX, this.dragStartY);
1490
1515
  this.dragStartX = clientX;
1491
1516
  this.dragStartY = clientY;
1517
+ this.hasMoved = true;
1492
1518
  }
1493
1519
  }
1494
1520
  if (event.pointerType === 'touch') {
1495
- const activePointers = Array.from(this._store.state.pointers.values());
1496
- if (this._store.state.pointers.size === 1 && this._store.state.selectionGroup && !this._store.state.isResizeHandleSelected && !this._store.state.isRotationHandleSelected) {
1497
- const x = Math.round(activePointers[0].clientX - this._store.offsetX);
1498
- const y = Math.round(activePointers[0].clientY - this._store.offsetY);
1499
- this._store.state.isDragging = true;
1521
+ const activePointers = Array.from(this._core.store.state.pointers.values());
1522
+ if (this._core.store.state.pointers.size === 1 &&
1523
+ this._core.store.state.selectionGroup &&
1524
+ !this._core.store.state.isResizeHandleSelected &&
1525
+ !this._core.store.state.isRotationHandleSelected) {
1526
+ const x = Math.round(activePointers[0].clientX - this._core.store.offsetX);
1527
+ const y = Math.round(activePointers[0].clientY - this._core.store.offsetY);
1528
+ this._core.store.setState('isDragging', true);
1500
1529
  this.endX = x;
1501
1530
  this.endY = y;
1531
+ this.hasMoved = true;
1502
1532
  const moveDeltaX = Math.abs(x - this.startX);
1503
1533
  const moveDeltaY = Math.abs(y - this.startY);
1504
1534
  const moveThreshold = 5;
1505
1535
  if (moveDeltaX > moveThreshold || moveDeltaY > moveThreshold) {
1506
- clearTimeout(this._store.state.longTouchTimeout);
1507
- this._store.state.selectionGroup.move(x, y, this.dragStartX, this.dragStartY);
1536
+ clearTimeout(this._core.store.state.longTouchTimeout);
1537
+ this._core.store.state.selectionGroup.move(x, y, this.dragStartX, this.dragStartY);
1508
1538
  this.dragStartX = x;
1509
1539
  this.dragStartY = y;
1510
1540
  }
@@ -1513,29 +1543,21 @@ class KritzelMoveHandler extends KritzelBaseHandler {
1513
1543
  }
1514
1544
  handlePointerUp(event) {
1515
1545
  if (event.pointerType === 'mouse') {
1516
- if (this._store.state.isDragging) {
1517
- this._store.state.isDragging = false;
1518
- const moveSelectionGroupCommand = new MoveSelectionGroupCommand(this._store, this, this.endX, this.endY, this.startX, this.startY, true);
1519
- const updateObjectsCommand = this._store.state.selectionGroup.objects.map(object => {
1520
- return new UpdateObjectCommand(this._store, this, object, {
1521
- translateX: object.translateX,
1522
- translateY: object.translateY
1523
- });
1524
- });
1525
- this._store.history.executeCommand(new BatchCommand(this._store, this, [moveSelectionGroupCommand, ...updateObjectsCommand]));
1546
+ if (this._core.store.state.isDragging) {
1547
+ this._core.store.setState('isDragging', false);
1548
+ if (this.hasMoved) {
1549
+ this._core.history.executeCommand(new MoveSelectionGroupCommand(this._core, this, this.endX, this.endY, this.startX, this.startY, true));
1550
+ }
1551
+ this.reset();
1526
1552
  }
1527
1553
  }
1528
1554
  if (event.pointerType === 'touch') {
1529
- if (this._store.state.isDragging) {
1530
- this._store.state.isDragging = false;
1531
- const moveSelectionGroupCommand = new MoveSelectionGroupCommand(this._store, this, this.endX, this.endY, this.startX, this.startY, true);
1532
- const updateObjectsCommand = this._store.state.selectionGroup.objects.map(object => {
1533
- return new UpdateObjectCommand(this._store, this, object, {
1534
- translateX: object.translateX,
1535
- translateY: object.translateY
1536
- });
1537
- });
1538
- this._store.history.executeCommand(new BatchCommand(this._store, this, [moveSelectionGroupCommand, ...updateObjectsCommand]));
1555
+ if (this._core.store.state.isDragging) {
1556
+ this._core.store.setState('isDragging', false);
1557
+ if (this.hasMoved) {
1558
+ this._core.history.executeCommand(new MoveSelectionGroupCommand(this._core, this, this.endX, this.endY, this.startX, this.startY, true));
1559
+ }
1560
+ this.reset();
1539
1561
  }
1540
1562
  }
1541
1563
  }
@@ -1553,19 +1575,27 @@ class ResizeSelectionGroupCommand extends KritzelBaseCommand {
1553
1575
  newSize;
1554
1576
  previousSize;
1555
1577
  selectionGroup;
1556
- constructor(store, initiator, previousSize, newSize, skipHistory = false) {
1557
- super(store, initiator, skipHistory);
1578
+ constructor(core, initiator, previousSize, newSize, skipHistory = false) {
1579
+ super(core, initiator, skipHistory);
1558
1580
  this.previousSize = previousSize;
1559
1581
  this.newSize = newSize;
1560
- this.selectionGroup = this._store.state.selectionGroup;
1582
+ this.selectionGroup = this._core.store.state.selectionGroup;
1561
1583
  }
1562
1584
  execute() {
1563
- this._store.state.selectionGroup = this.selectionGroup;
1564
- this._store.state.selectionGroup.resize(this.newSize.x, this.newSize.y, this.newSize.width, this.newSize.height);
1585
+ this._core.store.setState('selectionGroup', this.selectionGroup);
1586
+ this._core.store.state.selectionGroup.resize(this.newSize.x, this.newSize.y, this.newSize.width, this.newSize.height);
1587
+ this._core.store.state.selectionGroup.objects.forEach(object => {
1588
+ this._core.store.state.objectsMap.update(object);
1589
+ this._core.updateObjectInDatabase(object);
1590
+ });
1565
1591
  }
1566
1592
  undo() {
1567
- this._store.state.selectionGroup = this.selectionGroup;
1568
- this._store.state.selectionGroup.resize(this.previousSize.x, this.previousSize.y, this.previousSize.width, this.previousSize.height);
1593
+ this._core.store.setState('selectionGroup', this.selectionGroup);
1594
+ this._core.store.state.selectionGroup.resize(this.previousSize.x, this.previousSize.y, this.previousSize.width, this.previousSize.height);
1595
+ this._core.store.state.selectionGroup.objects.forEach(object => {
1596
+ this._core.store.state.objectsMap.update(object);
1597
+ this._core.updateObjectInDatabase(object);
1598
+ });
1569
1599
  }
1570
1600
  }
1571
1601
 
@@ -1574,71 +1604,77 @@ class KritzelResizeHandler extends KritzelBaseHandler {
1574
1604
  initialMouseY = 0;
1575
1605
  initialSize = { x: 0, y: 0, width: 0, height: 0 };
1576
1606
  newSize = { x: 0, y: 0, width: 0, height: 0 };
1577
- constructor(store) {
1578
- super(store);
1607
+ constructor(core) {
1608
+ super(core);
1609
+ }
1610
+ reset() {
1611
+ this.initialMouseX = 0;
1612
+ this.initialMouseY = 0;
1613
+ this.initialSize = { x: 0, y: 0, width: 0, height: 0 };
1614
+ this.newSize = { x: 0, y: 0, width: 0, height: 0 };
1579
1615
  }
1580
1616
  handlePointerDown(event) {
1581
1617
  if (event.pointerType === 'mouse') {
1582
1618
  if (KritzelEventHelper.isLeftClick(event)) {
1583
- if (this._store.state.selectionGroup && this._store.state.isResizeHandleSelected) {
1584
- const clientX = event.clientX - this._store.offsetX;
1585
- const clientY = event.clientY - this._store.offsetY;
1586
- this._store.state.isResizing = true;
1619
+ if (this._core.store.state.selectionGroup && this._core.store.state.isResizeHandleSelected) {
1620
+ const clientX = event.clientX - this._core.store.offsetX;
1621
+ const clientY = event.clientY - this._core.store.offsetY;
1622
+ this._core.store.setState('isResizing', true);
1587
1623
  this.initialMouseX = clientX;
1588
1624
  this.initialMouseY = clientY;
1589
- this.initialSize.width = this._store.state.selectionGroup.width;
1590
- this.initialSize.height = this._store.state.selectionGroup.height;
1591
- this.initialSize.x = this._store.state.selectionGroup.translateX;
1592
- this.initialSize.y = this._store.state.selectionGroup.translateY;
1625
+ this.initialSize.width = this._core.store.state.selectionGroup.width;
1626
+ this.initialSize.height = this._core.store.state.selectionGroup.height;
1627
+ this.initialSize.x = this._core.store.state.selectionGroup.translateX;
1628
+ this.initialSize.y = this._core.store.state.selectionGroup.translateY;
1593
1629
  }
1594
1630
  }
1595
1631
  }
1596
1632
  if (event.pointerType === 'touch') {
1597
- const activePointers = Array.from(this._store.state.pointers.values());
1633
+ const activePointers = Array.from(this._core.store.state.pointers.values());
1598
1634
  const firstTouch = activePointers[0];
1599
1635
  if (!firstTouch) {
1600
1636
  return;
1601
1637
  }
1602
1638
  if (activePointers.length === 1) {
1603
- if (this._store.state.selectionGroup && this._store.state.isResizeHandleSelected) {
1604
- const clientX = Math.round(firstTouch.clientX - this._store.offsetX);
1605
- const clientY = Math.round(firstTouch.clientY - this._store.offsetY);
1606
- this._store.state.isResizing = true;
1639
+ if (this._core.store.state.selectionGroup && this._core.store.state.isResizeHandleSelected) {
1640
+ const clientX = Math.round(firstTouch.clientX - this._core.store.offsetX);
1641
+ const clientY = Math.round(firstTouch.clientY - this._core.store.offsetY);
1642
+ this._core.store.setState('isResizing', true);
1607
1643
  this.initialMouseX = clientX;
1608
1644
  this.initialMouseY = clientY;
1609
- this.initialSize.width = this._store.state.selectionGroup.width;
1610
- this.initialSize.height = this._store.state.selectionGroup.height;
1611
- this.initialSize.x = this._store.state.selectionGroup.translateX;
1612
- this.initialSize.y = this._store.state.selectionGroup.translateY;
1613
- clearTimeout(this._store.state.longTouchTimeout);
1645
+ this.initialSize.width = this._core.store.state.selectionGroup.width;
1646
+ this.initialSize.height = this._core.store.state.selectionGroup.height;
1647
+ this.initialSize.x = this._core.store.state.selectionGroup.translateX;
1648
+ this.initialSize.y = this._core.store.state.selectionGroup.translateY;
1649
+ clearTimeout(this._core.store.state.longTouchTimeout);
1614
1650
  }
1615
1651
  }
1616
1652
  }
1617
1653
  }
1618
1654
  handlePointerMove(event) {
1619
1655
  if (event.pointerType === 'mouse') {
1620
- if (this._store.state.isResizing && this._store.state.selectionGroup) {
1621
- const clientX = event.clientX - this._store.offsetX;
1622
- const clientY = event.clientY - this._store.offsetY;
1656
+ if (this._core.store.state.isResizing && this._core.store.state.selectionGroup) {
1657
+ const clientX = event.clientX - this._core.store.offsetX;
1658
+ const clientY = event.clientY - this._core.store.offsetY;
1623
1659
  const dx = clientX - this.initialMouseX;
1624
1660
  const dy = clientY - this.initialMouseY;
1625
- switch (this._store.state.resizeHandleType) {
1661
+ switch (this._core.store.state.resizeHandleType) {
1626
1662
  case KritzelHandleType.TopLeft:
1627
1663
  this.newSize.width = this.initialSize.width - dx;
1628
1664
  this.newSize.height = this.initialSize.height - dy;
1629
- this.newSize.x = dx / this._store.state.scale + this.initialSize.x;
1630
- this.newSize.y = dy / this._store.state.scale + this.initialSize.y;
1665
+ this.newSize.x = dx / this._core.store.state.scale + this.initialSize.x;
1666
+ this.newSize.y = dy / this._core.store.state.scale + this.initialSize.y;
1631
1667
  break;
1632
1668
  case KritzelHandleType.TopRight:
1633
1669
  this.newSize.width = this.initialSize.width + dx;
1634
1670
  this.newSize.height = this.initialSize.height - dy;
1635
1671
  this.newSize.x = this.initialSize.x;
1636
- this.newSize.y = dy / this._store.state.scale + this.initialSize.y;
1672
+ this.newSize.y = dy / this._core.store.state.scale + this.initialSize.y;
1637
1673
  break;
1638
1674
  case KritzelHandleType.BottomLeft:
1639
1675
  this.newSize.width = this.initialSize.width - dx;
1640
1676
  this.newSize.height = this.initialSize.height + dy;
1641
- this.newSize.x = dx / this._store.state.scale + this.initialSize.x;
1677
+ this.newSize.x = dx / this._core.store.state.scale + this.initialSize.x;
1642
1678
  this.newSize.y = this.initialSize.y;
1643
1679
  break;
1644
1680
  case KritzelHandleType.BottomRight:
@@ -1648,38 +1684,37 @@ class KritzelResizeHandler extends KritzelBaseHandler {
1648
1684
  this.newSize.y = this.initialSize.y;
1649
1685
  break;
1650
1686
  }
1651
- this._store.state.selectionGroup.resize(this.newSize.x, this.newSize.y, this.newSize.width, this.newSize.height);
1652
- this._store.rerender();
1687
+ this._core.store.state.selectionGroup.resize(this.newSize.x, this.newSize.y, this.newSize.width, this.newSize.height);
1653
1688
  }
1654
1689
  }
1655
1690
  if (event.pointerType === 'touch') {
1656
- const activePointers = Array.from(this._store.state.pointers.values());
1691
+ const activePointers = Array.from(this._core.store.state.pointers.values());
1657
1692
  const oneFingerTouch = activePointers[0];
1658
1693
  if (!oneFingerTouch) {
1659
1694
  return;
1660
1695
  }
1661
- if (this._store.state.isResizing && this._store.state.selectionGroup) {
1662
- const clientX = Math.round(oneFingerTouch.clientX - this._store.offsetX);
1663
- const clientY = Math.round(oneFingerTouch.clientY - this._store.offsetY);
1696
+ if (this._core.store.state.isResizing && this._core.store.state.selectionGroup) {
1697
+ const clientX = Math.round(oneFingerTouch.clientX - this._core.store.offsetX);
1698
+ const clientY = Math.round(oneFingerTouch.clientY - this._core.store.offsetY);
1664
1699
  const dx = clientX - this.initialMouseX;
1665
1700
  const dy = clientY - this.initialMouseY;
1666
- switch (this._store.state.resizeHandleType) {
1701
+ switch (this._core.store.state.resizeHandleType) {
1667
1702
  case KritzelHandleType.TopLeft:
1668
1703
  this.newSize.width = this.initialSize.width - dx;
1669
1704
  this.newSize.height = this.initialSize.height - dy;
1670
- this.newSize.x = dx / this._store.state.scale + this.initialSize.x;
1671
- this.newSize.y = dy / this._store.state.scale + this.initialSize.y;
1705
+ this.newSize.x = dx / this._core.store.state.scale + this.initialSize.x;
1706
+ this.newSize.y = dy / this._core.store.state.scale + this.initialSize.y;
1672
1707
  break;
1673
1708
  case KritzelHandleType.TopRight:
1674
1709
  this.newSize.width = this.initialSize.width + dx;
1675
1710
  this.newSize.height = this.initialSize.height - dy;
1676
1711
  this.newSize.x = this.initialSize.x;
1677
- this.newSize.y = dy / this._store.state.scale + this.initialSize.y;
1712
+ this.newSize.y = dy / this._core.store.state.scale + this.initialSize.y;
1678
1713
  break;
1679
1714
  case KritzelHandleType.BottomLeft:
1680
1715
  this.newSize.width = this.initialSize.width - dx;
1681
1716
  this.newSize.height = this.initialSize.height + dy;
1682
- this.newSize.x = dx / this._store.state.scale + this.initialSize.x;
1717
+ this.newSize.x = dx / this._core.store.state.scale + this.initialSize.x;
1683
1718
  this.newSize.y = this.initialSize.y;
1684
1719
  break;
1685
1720
  case KritzelHandleType.BottomRight:
@@ -1689,33 +1724,25 @@ class KritzelResizeHandler extends KritzelBaseHandler {
1689
1724
  this.newSize.y = this.initialSize.y;
1690
1725
  break;
1691
1726
  }
1692
- this._store.state.selectionGroup.resize(this.newSize.x, this.newSize.y, this.newSize.width, this.newSize.height);
1693
- clearTimeout(this._store.state.longTouchTimeout);
1727
+ this._core.store.state.selectionGroup.resize(this.newSize.x, this.newSize.y, this.newSize.width, this.newSize.height);
1728
+ clearTimeout(this._core.store.state.longTouchTimeout);
1694
1729
  }
1695
1730
  }
1696
1731
  }
1697
1732
  handlePointerUp(event) {
1698
1733
  if (event.pointerType === 'mouse') {
1699
- if (this._store.state.isResizing) {
1700
- const resizeSelectionGroupCommand = new ResizeSelectionGroupCommand(this._store, this, structuredClone(this.initialSize), structuredClone(this.newSize));
1701
- const updateObjectsCommand = this._store.state.selectionGroup.objects.map(object => {
1702
- return new UpdateObjectCommand(this._store, this, object, { ...object });
1703
- });
1704
- this._store.history.executeCommand(new BatchCommand(this._store, this, [resizeSelectionGroupCommand, ...updateObjectsCommand]));
1705
- this._store.state.isResizing = false;
1706
- this._store.rerender();
1734
+ if (this._core.store.state.isResizing) {
1735
+ this._core.history.executeCommand(new ResizeSelectionGroupCommand(this._core, this, structuredClone(this.initialSize), structuredClone(this.newSize)));
1736
+ this._core.store.setState('isResizing', false);
1737
+ this.reset();
1707
1738
  }
1708
1739
  }
1709
1740
  if (event.pointerType === 'touch') {
1710
- if (this._store.state.isResizing) {
1711
- const resizeSelectionGroupCommand = new ResizeSelectionGroupCommand(this._store, this, structuredClone(this.initialSize), structuredClone(this.newSize));
1712
- const updateObjectsCommand = this._store.state.selectionGroup.objects.map(object => {
1713
- return new UpdateObjectCommand(this._store, this, object, { ...object });
1714
- });
1715
- this._store.history.executeCommand(new BatchCommand(this._store, this, [resizeSelectionGroupCommand, ...updateObjectsCommand]));
1716
- this._store.state.isResizing = false;
1717
- this._store.rerender();
1718
- clearTimeout(this._store.state.longTouchTimeout);
1741
+ if (this._core.store.state.isResizing) {
1742
+ this._core.history.executeCommand(new ResizeSelectionGroupCommand(this._core, this, structuredClone(this.initialSize), structuredClone(this.newSize)));
1743
+ this._core.store.setState('isResizing', false);
1744
+ this.reset();
1745
+ clearTimeout(this._core.store.state.longTouchTimeout);
1719
1746
  }
1720
1747
  }
1721
1748
  }
@@ -1725,24 +1752,26 @@ class RotateSelectionGroupCommand extends KritzelBaseCommand {
1725
1752
  rotation;
1726
1753
  initialRotation;
1727
1754
  selectionGroup;
1728
- constructor(store, initiator, rotation, skipHistory = false) {
1729
- super(store, initiator, skipHistory);
1755
+ constructor(core, initiator, rotation, initialRotation, skipHistory = false) {
1756
+ super(core, initiator, skipHistory);
1730
1757
  this.rotation = rotation;
1731
- this.initialRotation = this._store.state.selectionGroup.rotation;
1732
- this.selectionGroup = this._store.state.selectionGroup;
1758
+ this.initialRotation = initialRotation;
1759
+ this.selectionGroup = this._core.store.state.selectionGroup;
1733
1760
  }
1734
1761
  execute() {
1735
- this._store.state.selectionGroup = this.selectionGroup;
1736
- this._store.state.selectionGroup.rotate(this.rotation);
1737
- this._store.state.selectionGroup.objects.forEach(object => {
1738
- this._store.state.objectsMap.update(object);
1762
+ this._core.store.setState('selectionGroup', this.selectionGroup);
1763
+ this._core.store.state.selectionGroup.rotate(this.rotation);
1764
+ this._core.store.state.selectionGroup.objects.forEach(object => {
1765
+ this._core.store.state.objectsMap.update(object);
1766
+ this._core.updateObjectInDatabase(object);
1739
1767
  });
1740
1768
  }
1741
1769
  undo() {
1742
- this._store.state.selectionGroup = this.selectionGroup;
1743
- this._store.state.selectionGroup.rotate(this.rotation - this.initialRotation);
1744
- this._store.state.selectionGroup.objects.forEach(object => {
1745
- this._store.state.objectsMap.update(object);
1770
+ this._core.store.setState('selectionGroup', this.selectionGroup);
1771
+ this._core.store.state.selectionGroup.rotate(this.initialRotation);
1772
+ this._core.store.state.selectionGroup.objects.forEach(object => {
1773
+ this._core.store.state.objectsMap.update(object);
1774
+ this._core.updateObjectInDatabase(object);
1746
1775
  });
1747
1776
  }
1748
1777
  }
@@ -1750,111 +1779,103 @@ class RotateSelectionGroupCommand extends KritzelBaseCommand {
1750
1779
  class KritzelRotationHandler extends KritzelBaseHandler {
1751
1780
  initialRotation = 0;
1752
1781
  rotation = 0;
1753
- constructor(store) {
1754
- super(store);
1782
+ unchangedObjects = [];
1783
+ initialSelectionGroupRotation = 0;
1784
+ constructor(core) {
1785
+ super(core);
1786
+ }
1787
+ reset() {
1788
+ this.initialRotation = 0;
1789
+ this.rotation = 0;
1790
+ this.unchangedObjects = [];
1755
1791
  }
1756
1792
  handlePointerDown(event) {
1757
1793
  if (event.pointerType === 'mouse') {
1758
1794
  if (KritzelEventHelper.isLeftClick(event)) {
1759
- if (this._store.state.selectionGroup && this._store.state.isRotationHandleSelected) {
1760
- const clientX = event.clientX - this._store.offsetX;
1761
- const clientY = event.clientY - this._store.offsetY;
1762
- this._store.state.isRotating = true;
1763
- const centerX = this._store.state.selectionGroup.translateX + this._store.state.selectionGroup.width / 2 / this._store.state.scale;
1764
- const centerY = this._store.state.selectionGroup.translateY + this._store.state.selectionGroup.height / 2 / this._store.state.scale;
1765
- const cursorX = (clientX - this._store.state.translateX) / this._store.state.scale;
1766
- const cursorY = (clientY - this._store.state.translateY) / this._store.state.scale;
1767
- this.initialRotation = Math.atan2(centerY - cursorY, centerX - cursorX) - this._store.state.selectionGroup.rotation;
1795
+ if (this._core.store.state.selectionGroup && this._core.store.state.isRotationHandleSelected) {
1796
+ const clientX = event.clientX - this._core.store.offsetX;
1797
+ const clientY = event.clientY - this._core.store.offsetY;
1798
+ this._core.store.setState('isRotating', true);
1799
+ const centerX = this._core.store.state.selectionGroup.translateX + this._core.store.state.selectionGroup.width / 2 / this._core.store.state.scale;
1800
+ const centerY = this._core.store.state.selectionGroup.translateY + this._core.store.state.selectionGroup.height / 2 / this._core.store.state.scale;
1801
+ const cursorX = (clientX - this._core.store.state.translateX) / this._core.store.state.scale;
1802
+ const cursorY = (clientY - this._core.store.state.translateY) / this._core.store.state.scale;
1803
+ this.initialSelectionGroupRotation = this._core.store.state.selectionGroup.rotation;
1804
+ this.initialRotation = Math.atan2(centerY - cursorY, centerX - cursorX) - this._core.store.state.selectionGroup.rotation;
1805
+ this.unchangedObjects = this._core.store.state.selectionGroup.objects.map(obj => obj.clone());
1768
1806
  }
1769
1807
  }
1770
1808
  }
1771
1809
  if (event.pointerType === 'touch') {
1772
- const activePointers = Array.from(this._store.state.pointers.values());
1810
+ const activePointers = Array.from(this._core.store.state.pointers.values());
1773
1811
  const firstTouch = activePointers[0];
1774
1812
  if (!firstTouch) {
1775
1813
  return;
1776
1814
  }
1777
1815
  if (activePointers.length === 1) {
1778
- if (this._store.state.selectionGroup && this._store.state.isRotationHandleSelected) {
1779
- const clientX = Math.round(firstTouch.clientX - this._store.offsetX);
1780
- const clientY = Math.round(firstTouch.clientY - this._store.offsetY);
1781
- this._store.state.isRotating = true;
1782
- const centerX = this._store.state.selectionGroup.translateX + this._store.state.selectionGroup.width / 2 / this._store.state.scale;
1783
- const centerY = this._store.state.selectionGroup.translateY + this._store.state.selectionGroup.height / 2 / this._store.state.scale;
1784
- const cursorX = (clientX - this._store.state.translateX) / this._store.state.scale;
1785
- const cursorY = (clientY - this._store.state.translateY) / this._store.state.scale;
1786
- this.initialRotation = Math.atan2(centerY - cursorY, centerX - cursorX) - this._store.state.selectionGroup.rotation;
1787
- clearTimeout(this._store.state.longTouchTimeout);
1816
+ if (this._core.store.state.selectionGroup && this._core.store.state.isRotationHandleSelected) {
1817
+ const clientX = Math.round(firstTouch.clientX - this._core.store.offsetX);
1818
+ const clientY = Math.round(firstTouch.clientY - this._core.store.offsetY);
1819
+ this._core.store.setState('isRotating', true);
1820
+ const centerX = this._core.store.state.selectionGroup.translateX + this._core.store.state.selectionGroup.width / 2 / this._core.store.state.scale;
1821
+ const centerY = this._core.store.state.selectionGroup.translateY + this._core.store.state.selectionGroup.height / 2 / this._core.store.state.scale;
1822
+ const cursorX = (clientX - this._core.store.state.translateX) / this._core.store.state.scale;
1823
+ const cursorY = (clientY - this._core.store.state.translateY) / this._core.store.state.scale;
1824
+ this.initialRotation = Math.atan2(centerY - cursorY, centerX - cursorX) - this._core.store.state.selectionGroup.rotation;
1825
+ this.unchangedObjects = this._core.store.state.selectionGroup.objects.map(obj => obj.clone());
1826
+ clearTimeout(this._core.store.state.longTouchTimeout);
1788
1827
  }
1789
1828
  }
1790
1829
  }
1791
1830
  }
1792
1831
  handlePointerMove(event) {
1793
1832
  if (event.pointerType === 'mouse') {
1794
- if (this._store.state.isRotating && this._store.state.selectionGroup) {
1795
- const clientX = event.clientX - this._store.offsetX;
1796
- const clientY = event.clientY - this._store.offsetY;
1797
- const groupCenterX = this._store.state.selectionGroup.translateX + this._store.state.selectionGroup.width / 2 / this._store.state.scale;
1798
- const groupCenterY = this._store.state.selectionGroup.translateY + this._store.state.selectionGroup.height / 2 / this._store.state.scale;
1799
- const cursorX = (clientX - this._store.state.translateX) / this._store.state.scale;
1800
- const cursorY = (clientY - this._store.state.translateY) / this._store.state.scale;
1833
+ if (this._core.store.state.isRotating && this._core.store.state.selectionGroup) {
1834
+ const clientX = event.clientX - this._core.store.offsetX;
1835
+ const clientY = event.clientY - this._core.store.offsetY;
1836
+ const groupCenterX = this._core.store.state.selectionGroup.translateX + this._core.store.state.selectionGroup.width / 2 / this._core.store.state.scale;
1837
+ const groupCenterY = this._core.store.state.selectionGroup.translateY + this._core.store.state.selectionGroup.height / 2 / this._core.store.state.scale;
1838
+ const cursorX = (clientX - this._core.store.state.translateX) / this._core.store.state.scale;
1839
+ const cursorY = (clientY - this._core.store.state.translateY) / this._core.store.state.scale;
1801
1840
  const currentRotation = Math.atan2(groupCenterY - cursorY, groupCenterX - cursorX);
1802
1841
  this.rotation = currentRotation - this.initialRotation;
1803
- this._store.state.selectionGroup.rotate(this.rotation);
1804
- this._store.rerender();
1842
+ this._core.store.state.selectionGroup.rotate(this.rotation);
1805
1843
  }
1806
1844
  }
1807
1845
  if (event.pointerType === 'touch') {
1808
- const activePointers = Array.from(this._store.state.pointers.values());
1846
+ const activePointers = Array.from(this._core.store.state.pointers.values());
1809
1847
  const firstTouch = activePointers[0];
1810
1848
  if (!firstTouch) {
1811
1849
  return;
1812
1850
  }
1813
- if (this._store.state.isRotating && this._store.state.selectionGroup) {
1814
- const clientX = Math.round(firstTouch.clientX - this._store.offsetX);
1815
- const clientY = Math.round(firstTouch.clientY - this._store.offsetY);
1816
- const groupCenterX = this._store.state.selectionGroup.translateX + this._store.state.selectionGroup.width / 2 / this._store.state.scale;
1817
- const groupCenterY = this._store.state.selectionGroup.translateY + this._store.state.selectionGroup.height / 2 / this._store.state.scale;
1818
- const cursorX = (clientX - this._store.state.translateX) / this._store.state.scale;
1819
- const cursorY = (clientY - this._store.state.translateY) / this._store.state.scale;
1851
+ if (this._core.store.state.isRotating && this._core.store.state.selectionGroup) {
1852
+ const clientX = Math.round(firstTouch.clientX - this._core.store.offsetX);
1853
+ const clientY = Math.round(firstTouch.clientY - this._core.store.offsetY);
1854
+ const groupCenterX = this._core.store.state.selectionGroup.translateX + this._core.store.state.selectionGroup.width / 2 / this._core.store.state.scale;
1855
+ const groupCenterY = this._core.store.state.selectionGroup.translateY + this._core.store.state.selectionGroup.height / 2 / this._core.store.state.scale;
1856
+ const cursorX = (clientX - this._core.store.state.translateX) / this._core.store.state.scale;
1857
+ const cursorY = (clientY - this._core.store.state.translateY) / this._core.store.state.scale;
1820
1858
  const currentRotation = Math.atan2(groupCenterY - cursorY, groupCenterX - cursorX);
1821
1859
  this.rotation = currentRotation - this.initialRotation;
1822
- this._store.state.selectionGroup.rotate(this.rotation);
1823
- this._store.rerender();
1824
- clearTimeout(this._store.state.longTouchTimeout);
1860
+ this._core.store.state.selectionGroup.rotate(this.rotation);
1861
+ clearTimeout(this._core.store.state.longTouchTimeout);
1825
1862
  }
1826
1863
  }
1827
1864
  }
1828
1865
  handlePointerUp(event) {
1829
1866
  if (event.pointerType === 'mouse') {
1830
- if (this._store.state.isRotating) {
1831
- const rotateSelectionGroupCommand = new RotateSelectionGroupCommand(this._store, this, this.rotation);
1832
- const updateObjectsCommand = this._store.state.selectionGroup.objects.map(object => {
1833
- return new UpdateObjectCommand(this._store, this, object, {
1834
- rotation: object.rotation,
1835
- translateX: object.translateX,
1836
- translateY: object.translateY,
1837
- });
1838
- });
1839
- this._store.history.executeCommand(new BatchCommand(this._store, this, [rotateSelectionGroupCommand, ...updateObjectsCommand]));
1840
- this._store.state.isRotating = false;
1841
- this.initialRotation = 0;
1842
- this.rotation = 0;
1867
+ if (this._core.store.state.isRotating) {
1868
+ this._core.history.executeCommand(new RotateSelectionGroupCommand(this._core, this, this.rotation, this.initialSelectionGroupRotation));
1869
+ this._core.store.setState('isRotating', false);
1870
+ this.reset();
1843
1871
  }
1844
1872
  }
1845
1873
  if (event.pointerType === 'touch') {
1846
- if (this._store.state.isRotating) {
1847
- const rotateSelectionGroupCommand = new RotateSelectionGroupCommand(this._store, this, this.rotation);
1848
- const updateObjectsCommand = this._store.state.selectionGroup.objects.map(object => {
1849
- return new UpdateObjectCommand(this._store, this, object, {
1850
- rotation: object.rotation,
1851
- });
1852
- });
1853
- this._store.history.executeCommand(new BatchCommand(this._store, this, [rotateSelectionGroupCommand, ...updateObjectsCommand]));
1854
- this._store.state.isRotating = false;
1855
- this.initialRotation = 0;
1856
- this.rotation = 0;
1857
- clearTimeout(this._store.state.longTouchTimeout);
1874
+ if (this._core.store.state.isRotating) {
1875
+ this._core.history.executeCommand(new RotateSelectionGroupCommand(this._core, this, this.rotation, this.initialSelectionGroupRotation));
1876
+ this._core.store.setState('isRotating', false);
1877
+ this.reset();
1878
+ clearTimeout(this._core.store.state.longTouchTimeout);
1858
1879
  }
1859
1880
  }
1860
1881
  }
@@ -1863,12 +1884,12 @@ class KritzelRotationHandler extends KritzelBaseHandler {
1863
1884
  class KrtizelSelectionBox extends KritzelBaseObject {
1864
1885
  __class__ = 'KrtizelSelectionBox';
1865
1886
  objects = [];
1866
- static create(store) {
1887
+ static create(core) {
1867
1888
  const object = new KrtizelSelectionBox();
1868
- object._store = store;
1889
+ object._core = core;
1869
1890
  object.id = object.generateId();
1870
- object.workspaceId = store.state.activeWorkspace.id;
1871
- object.scale = store.state.scale;
1891
+ object.workspaceId = core.store.state.activeWorkspace.id;
1892
+ object.scale = core.store.state.scale;
1872
1893
  object.zIndex = 99999;
1873
1894
  object.backgroundColor = 'var(--kritzel-selection-box-background-color, rgba(0, 122, 255, 0.2))';
1874
1895
  object.borderColor = 'var(--kritzel-selection-box-border-color, rgba(0, 122, 255, 0.5))';
@@ -1881,20 +1902,20 @@ class KrtizelSelectionBox extends KritzelBaseObject {
1881
1902
 
1882
1903
  class AddSelectionGroupCommand extends KritzelBaseCommand {
1883
1904
  selectionGroup;
1884
- constructor(store, initiator, selectionGroup, skipHistory = false) {
1885
- super(store, initiator, skipHistory);
1905
+ constructor(core, initiator, selectionGroup, skipHistory = false) {
1906
+ super(core, initiator, skipHistory);
1886
1907
  this.selectionGroup = selectionGroup;
1887
1908
  }
1888
1909
  execute() {
1889
- this._store.state.objectsMap.remove(object => object instanceof KrtizelSelectionBox);
1890
- this._store.state.objectsMap.insert(this.selectionGroup);
1891
- this._store.state.selectionGroup = this.selectionGroup;
1892
- this._store.state.selectionBox = null;
1910
+ this._core.store.state.objectsMap.remove(object => object instanceof KrtizelSelectionBox);
1911
+ this._core.store.state.objectsMap.insert(this.selectionGroup);
1912
+ this._core.store.setState('selectionGroup', this.selectionGroup);
1913
+ this._core.store.setState('selectionBox', null);
1893
1914
  }
1894
1915
  undo() {
1895
- this._store.state.objectsMap.remove(object => object.id === this.selectionGroup.id);
1896
- this._store.state.selectionGroup = null;
1897
- this._store.state.selectionBox = null;
1916
+ this._core.store.state.objectsMap.remove(object => object.id === this.selectionGroup.id);
1917
+ this._core.store.setState('selectionGroup', null);
1918
+ this._core.store.setState('selectionBox', null);
1898
1919
  }
1899
1920
  }
1900
1921
 
@@ -1905,23 +1926,23 @@ class KritzelSelectionHandler extends KritzelBaseHandler {
1905
1926
  touchStartY = 0;
1906
1927
  touchStartTimeout = null;
1907
1928
  get isSelectionClick() {
1908
- return this._store.state.selectionBox && this._store.state.selectionBox.width === 0 && this._store.state.selectionBox.height === 0;
1929
+ return this._core.store.state.selectionBox && this._core.store.state.selectionBox.width === 0 && this._core.store.state.selectionBox.height === 0;
1909
1930
  }
1910
1931
  get isSelectionDrag() {
1911
- return this._store.state.selectionBox && (this._store.state.selectionBox.width > 0 || this._store.state.selectionBox.height > 0);
1932
+ return this._core.store.state.selectionBox && (this._core.store.state.selectionBox.width > 0 || this._core.store.state.selectionBox.height > 0);
1912
1933
  }
1913
- constructor(store) {
1914
- super(store);
1934
+ constructor(core) {
1935
+ super(core);
1915
1936
  }
1916
1937
  handlePointerDown(event) {
1917
1938
  if (event.pointerType === 'mouse') {
1918
- if (KritzelEventHelper.isLeftClick(event) && !this._store.state.selectionGroup) {
1939
+ if (KritzelEventHelper.isLeftClick(event) && !this._core.store.state.selectionGroup) {
1919
1940
  this.startMouseSelection(event);
1920
1941
  }
1921
1942
  }
1922
1943
  if (event.pointerType === 'touch') {
1923
1944
  this.touchStartTimeout = setTimeout(() => {
1924
- if (this._store.state.pointers.size === 1 && !this._store.state.isScaling && !this._store.state.selectionGroup) {
1945
+ if (this._core.store.state.pointers.size === 1 && !this._core.store.state.isScaling && !this._core.store.state.selectionGroup) {
1925
1946
  this.startTouchSelection();
1926
1947
  this.updateTouchSelection();
1927
1948
  }
@@ -1930,30 +1951,30 @@ class KritzelSelectionHandler extends KritzelBaseHandler {
1930
1951
  }
1931
1952
  handlePointerMove(event) {
1932
1953
  if (event.pointerType === 'mouse') {
1933
- if (this._store.state.isSelecting) {
1954
+ if (this._core.store.state.isSelecting) {
1934
1955
  this.updateMouseSelection(event);
1935
1956
  }
1936
1957
  }
1937
1958
  if (event.pointerType === 'touch') {
1938
- const activePointers = Array.from(this._store.state.pointers.values());
1939
- const x = Math.round(activePointers[0].clientX - this._store.offsetX);
1940
- const y = Math.round(activePointers[0].clientY - this._store.offsetY);
1959
+ const activePointers = Array.from(this._core.store.state.pointers.values());
1960
+ const x = Math.round(activePointers[0].clientX - this._core.store.offsetX);
1961
+ const y = Math.round(activePointers[0].clientY - this._core.store.offsetY);
1941
1962
  const moveDeltaX = Math.abs(x - this.touchStartX);
1942
1963
  const moveDeltaY = Math.abs(y - this.touchStartY);
1943
1964
  const moveThreshold = 5;
1944
- if ((moveDeltaX > moveThreshold || moveDeltaY > moveThreshold) && this._store.state.isSelecting) {
1965
+ if ((moveDeltaX > moveThreshold || moveDeltaY > moveThreshold) && this._core.store.state.isSelecting) {
1945
1966
  this.updateTouchSelection();
1946
- clearTimeout(this._store.state.longTouchTimeout);
1967
+ clearTimeout(this._core.store.state.longTouchTimeout);
1947
1968
  }
1948
1969
  }
1949
1970
  }
1950
1971
  handlePointerUp(event) {
1951
1972
  if (event.pointerType === 'mouse') {
1952
- if (KritzelEventHelper.isLeftClick(event) && this._store.state.isSelecting) {
1973
+ if (KritzelEventHelper.isLeftClick(event) && this._core.store.state.isSelecting) {
1953
1974
  if (this.isSelectionClick) {
1954
- const x = this._store.state.pointerX;
1955
- const y = this._store.state.pointerY;
1956
- const selectedObject = this._store.getObjectsFromPointerEvent(event, '.object').find(obj => obj.hitTest(x, y));
1975
+ const x = this._core.store.state.pointerX;
1976
+ const y = this._core.store.state.pointerY;
1977
+ const selectedObject = this._core.getObjectsFromPointerEvent(event, '.object').find(obj => obj.hitTest(x, y));
1957
1978
  this.addObjectToSelectionGroup(selectedObject);
1958
1979
  this.removeSelectionBox();
1959
1980
  }
@@ -1966,11 +1987,11 @@ class KritzelSelectionHandler extends KritzelBaseHandler {
1966
1987
  }
1967
1988
  if (event.pointerType === 'touch') {
1968
1989
  clearTimeout(this.touchStartTimeout);
1969
- if (this._store.state.isSelecting) {
1990
+ if (this._core.store.state.isSelecting) {
1970
1991
  if (this.isSelectionClick) {
1971
- const x = this._store.state.pointerX;
1972
- const y = this._store.state.pointerY;
1973
- const selectedObject = this._store.getObjectsFromPointerEvent(event, '.object').find(obj => obj.hitTest(x, y));
1992
+ const x = this._core.store.state.pointerX;
1993
+ const y = this._core.store.state.pointerY;
1994
+ const selectedObject = this._core.getObjectsFromPointerEvent(event, '.object').find(obj => obj.hitTest(x, y));
1974
1995
  this.addObjectToSelectionGroup(selectedObject);
1975
1996
  this.removeSelectionBox();
1976
1997
  }
@@ -1979,82 +2000,80 @@ class KritzelSelectionHandler extends KritzelBaseHandler {
1979
2000
  this.addSelectedObjectsToSelectionGroup();
1980
2001
  this.removeSelectionBox();
1981
2002
  }
1982
- this._store.state.skipContextMenu = false;
2003
+ this._core.store.setState('skipContextMenu', false);
1983
2004
  }
1984
2005
  }
1985
2006
  }
1986
2007
  removeSelectionBox() {
1987
- this._store.state.selectionBox = null;
1988
- this._store.state.isSelecting = false;
1989
- this._store.state.objectsMap.remove(o => o instanceof KrtizelSelectionBox);
1990
- this._store.rerender();
2008
+ this._core.store.setState('selectionBox', null);
2009
+ this._core.store.setState('isSelecting', false);
2010
+ this._core.store.state.objectsMap.remove(o => o instanceof KrtizelSelectionBox);
1991
2011
  }
1992
2012
  startMouseSelection(event) {
1993
2013
  let clientX, clientY;
1994
- clientX = event.clientX - this._store.offsetX;
1995
- clientY = event.clientY - this._store.offsetY;
1996
- const selectionBox = KrtizelSelectionBox.create(this._store);
1997
- this.startX = (clientX - this._store.state.translateX) / this._store.state.scale;
1998
- this.startY = (clientY - this._store.state.translateY) / this._store.state.scale;
2014
+ clientX = event.clientX - this._core.store.offsetX;
2015
+ clientY = event.clientY - this._core.store.offsetY;
2016
+ const selectionBox = KrtizelSelectionBox.create(this._core);
2017
+ this.startX = (clientX - this._core.store.state.translateX) / this._core.store.state.scale;
2018
+ this.startY = (clientY - this._core.store.state.translateY) / this._core.store.state.scale;
1999
2019
  selectionBox.translateX = this.startX;
2000
2020
  selectionBox.translateY = this.startY;
2001
- this._store.state.selectionGroup = null;
2002
- this._store.state.selectionBox = selectionBox;
2003
- this._store.state.isSelecting = true;
2004
- this._store.state.objectsMap.remove(o => o instanceof KrtizelSelectionBox || o instanceof KritzelSelectionGroup);
2005
- this._store.state.objectsMap.insert(selectionBox);
2021
+ this._core.store.setState('selectionGroup', null);
2022
+ this._core.store.setState('selectionBox', selectionBox);
2023
+ this._core.store.setState('isSelecting', true);
2024
+ this._core.store.state.objectsMap.remove(o => o instanceof KrtizelSelectionBox || o instanceof KritzelSelectionGroup);
2025
+ this._core.store.state.objectsMap.insert(selectionBox);
2006
2026
  }
2007
2027
  startTouchSelection() {
2008
- const activePointers = Array.from(this._store.state.pointers.values());
2028
+ const activePointers = Array.from(this._core.store.state.pointers.values());
2009
2029
  const firstTouch = activePointers[0];
2010
2030
  if (!firstTouch) {
2011
2031
  return;
2012
2032
  }
2013
2033
  let clientX, clientY;
2014
- clientX = Math.round(firstTouch.clientX - this._store.offsetX);
2015
- clientY = Math.round(firstTouch.clientY - this._store.offsetY);
2034
+ clientX = Math.round(firstTouch.clientX - this._core.store.offsetX);
2035
+ clientY = Math.round(firstTouch.clientY - this._core.store.offsetY);
2016
2036
  this.touchStartX = clientX;
2017
2037
  this.touchStartY = clientY;
2018
- const selectionBox = KrtizelSelectionBox.create(this._store);
2019
- this.startX = (clientX - this._store.state.translateX) / this._store.state.scale;
2020
- this.startY = (clientY - this._store.state.translateY) / this._store.state.scale;
2038
+ const selectionBox = KrtizelSelectionBox.create(this._core);
2039
+ this.startX = (clientX - this._core.store.state.translateX) / this._core.store.state.scale;
2040
+ this.startY = (clientY - this._core.store.state.translateY) / this._core.store.state.scale;
2021
2041
  selectionBox.translateX = this.startX;
2022
2042
  selectionBox.translateY = this.startY;
2023
- this._store.state.selectionGroup = null;
2024
- this._store.state.selectionBox = selectionBox;
2025
- this._store.state.isSelecting = true;
2026
- this._store.state.objectsMap.remove(o => o instanceof KrtizelSelectionBox || o instanceof KritzelSelectionGroup);
2027
- this._store.state.objectsMap.insert(selectionBox);
2043
+ this._core.store.setState('selectionGroup', null);
2044
+ this._core.store.setState('selectionBox', selectionBox);
2045
+ this._core.store.setState('isSelecting', true);
2046
+ this._core.store.state.objectsMap.remove(o => o instanceof KrtizelSelectionBox || o instanceof KritzelSelectionGroup);
2047
+ this._core.store.state.objectsMap.insert(selectionBox);
2028
2048
  }
2029
2049
  updateMouseSelection(event) {
2030
2050
  let clientX, clientY;
2031
- clientX = event.clientX - this._store.offsetX;
2032
- clientY = event.clientY - this._store.offsetY;
2033
- const selectionBox = this._store.state.selectionBox;
2051
+ clientX = event.clientX - this._core.store.offsetX;
2052
+ clientY = event.clientY - this._core.store.offsetY;
2053
+ const selectionBox = this._core.store.state.selectionBox;
2034
2054
  if (selectionBox) {
2035
- const currentX = (clientX - this._store.state.translateX) / selectionBox.scale;
2036
- const currentY = (clientY - this._store.state.translateY) / selectionBox.scale;
2055
+ const currentX = (clientX - this._core.store.state.translateX) / selectionBox.scale;
2056
+ const currentY = (clientY - this._core.store.state.translateY) / selectionBox.scale;
2037
2057
  selectionBox.width = Math.abs(currentX - this.startX) * selectionBox.scale;
2038
2058
  selectionBox.height = Math.abs(currentY - this.startY) * selectionBox.scale;
2039
2059
  selectionBox.translateX = Math.min(currentX, this.startX);
2040
2060
  selectionBox.translateY = Math.min(currentY, this.startY);
2041
2061
  this.updateSelectedObjects();
2042
- this._store.rerender();
2043
2062
  }
2044
2063
  }
2045
2064
  updateTouchSelection() {
2046
- const activePointers = Array.from(this._store.state.pointers.values());
2065
+ const activePointers = Array.from(this._core.store.state.pointers.values());
2047
2066
  const firstTouch = activePointers[0];
2048
2067
  if (!firstTouch) {
2049
2068
  return;
2050
2069
  }
2051
2070
  let clientX, clientY;
2052
- clientX = Math.round(firstTouch.clientX - this._store.offsetX);
2053
- clientY = Math.round(firstTouch.clientY - this._store.offsetY);
2054
- const selectionBox = this._store.state.selectionBox;
2071
+ clientX = Math.round(firstTouch.clientX - this._core.store.offsetX);
2072
+ clientY = Math.round(firstTouch.clientY - this._core.store.offsetY);
2073
+ const selectionBox = this._core.store.state.selectionBox;
2055
2074
  if (selectionBox) {
2056
- const currentX = (clientX - this._store.state.translateX) / selectionBox.scale;
2057
- const currentY = (clientY - this._store.state.translateY) / selectionBox.scale;
2075
+ const currentX = (clientX - this._core.store.state.translateX) / selectionBox.scale;
2076
+ const currentY = (clientY - this._core.store.state.translateY) / selectionBox.scale;
2058
2077
  selectionBox.width = Math.abs(currentX - this.startX) * selectionBox.scale;
2059
2078
  selectionBox.height = Math.abs(currentY - this.startY) * selectionBox.scale;
2060
2079
  selectionBox.translateX = Math.min(currentX, this.startX);
@@ -2063,49 +2082,52 @@ class KritzelSelectionHandler extends KritzelBaseHandler {
2063
2082
  }
2064
2083
  }
2065
2084
  updateSelectedObjects() {
2066
- this._store.allObjects
2085
+ this._core.store.allObjects
2067
2086
  .filter(o => !(o instanceof KrtizelSelectionBox))
2068
- .forEach(object => (object.isSelected = object.hitTestPolygon(this._store.state.selectionBox.rotatedPolygon)));
2087
+ .forEach(object => (object.isSelected = object.hitTestPolygon(this._core.store.state.selectionBox.rotatedPolygon)));
2069
2088
  }
2070
2089
  addObjectToSelectionGroup(object) {
2071
2090
  if (!object) {
2072
2091
  return;
2073
2092
  }
2074
- this._store.state.selectionGroup = KritzelSelectionGroup.create(this._store);
2075
- this._store.state.selectionGroup.addOrRemove(object);
2076
- this._store.state.selectionGroup.isSelected = true;
2077
- this._store.state.selectionGroup.rotation = object.rotation;
2078
- this._store.history.executeCommand(new AddSelectionGroupCommand(this._store, this, this._store.state.selectionGroup));
2093
+ const selectionGroup = KritzelSelectionGroup.create(this._core);
2094
+ selectionGroup.addOrRemove(object);
2095
+ selectionGroup.isSelected = true;
2096
+ selectionGroup.rotation = object.rotation;
2097
+ this._core.store.setState('selectionGroup', selectionGroup);
2098
+ this._core.history.executeCommand(new AddSelectionGroupCommand(this._core, this, this._core.store.state.selectionGroup));
2079
2099
  }
2080
2100
  addSelectedObjectsToSelectionGroup() {
2081
- const selectedObjects = this._store.selectedObjects;
2101
+ const selectedObjects = this._core.store.selectedObjects;
2082
2102
  if (selectedObjects.length === 0) {
2083
2103
  return;
2084
2104
  }
2085
- this._store.state.selectionGroup = KritzelSelectionGroup.create(this._store);
2105
+ this._core.store.setState('selectionGroup', KritzelSelectionGroup.create(this._core));
2086
2106
  selectedObjects.forEach(o => {
2087
2107
  o.isSelected = false;
2088
- this._store.state.selectionGroup.addOrRemove(o);
2108
+ this._core.store.state.selectionGroup.addOrRemove(o);
2089
2109
  });
2090
- this._store.state.selectionGroup.isSelected = true;
2091
- if (this._store.state.selectionGroup.length === 1) {
2092
- this._store.state.selectionGroup.rotation = this._store.state.selectionGroup.objects[0].rotation;
2110
+ const selectionGroup = this._core.store.state.selectionGroup;
2111
+ selectionGroup.isSelected = true;
2112
+ if (selectionGroup.length === 1) {
2113
+ selectionGroup.rotation = selectionGroup.objects[0].rotation;
2093
2114
  }
2094
- this._store.history.executeCommand(new AddSelectionGroupCommand(this._store, this, this._store.state.selectionGroup));
2115
+ this._core.store.setState('selectionGroup', selectionGroup);
2116
+ this._core.history.executeCommand(new AddSelectionGroupCommand(this._core, this, this._core.store.state.selectionGroup));
2095
2117
  }
2096
2118
  }
2097
2119
 
2098
2120
  class KritzelHoverHandler extends KritzelBaseHandler {
2099
- constructor(store) {
2100
- super(store);
2121
+ constructor(core) {
2122
+ super(core);
2101
2123
  }
2102
2124
  handlePointerMove(event) {
2103
2125
  if (event.pointerType === 'mouse') {
2104
- const hoveredObject = this._store.getObjectFromPointerEvent(event, '.object');
2126
+ const hoveredObject = this._core.getObjectFromPointerEvent(event, '.object');
2105
2127
  if (!hoveredObject)
2106
2128
  return;
2107
- const x = this._store.state.pointerX;
2108
- const y = this._store.state.pointerY;
2129
+ const x = this._core.store.state.pointerX;
2130
+ const y = this._core.store.state.pointerY;
2109
2131
  hoveredObject.isHovered = hoveredObject.hitTest(x, y);
2110
2132
  }
2111
2133
  }
@@ -2117,13 +2139,13 @@ class KritzelSelectionTool extends KritzelBaseTool {
2117
2139
  hoverHandler;
2118
2140
  resizeHandler;
2119
2141
  rotationHandler;
2120
- constructor(store) {
2121
- super(store);
2122
- this.selectionHandler = new KritzelSelectionHandler(this._store);
2123
- this.moveHandler = new KritzelMoveHandler(this._store);
2124
- this.hoverHandler = new KritzelHoverHandler(this._store);
2125
- this.resizeHandler = new KritzelResizeHandler(this._store);
2126
- this.rotationHandler = new KritzelRotationHandler(this._store);
2142
+ constructor(core) {
2143
+ super(core);
2144
+ this.selectionHandler = new KritzelSelectionHandler(this._core);
2145
+ this.moveHandler = new KritzelMoveHandler(this._core);
2146
+ this.hoverHandler = new KritzelHoverHandler(this._core);
2147
+ this.resizeHandler = new KritzelResizeHandler(this._core);
2148
+ this.rotationHandler = new KritzelRotationHandler(this._core);
2127
2149
  }
2128
2150
  handlePointerDown(event) {
2129
2151
  if (event.cancelable) {
@@ -2131,16 +2153,16 @@ class KritzelSelectionTool extends KritzelBaseTool {
2131
2153
  }
2132
2154
  if (event.pointerType === 'mouse') {
2133
2155
  if (KritzelEventHelper.isLeftClick(event)) {
2134
- this._store.state.isResizeHandleSelected = this.isHandleSelected(event);
2135
- this._store.state.isRotationHandleSelected = this.isRotationHandleSelected(event);
2136
- this._store.state.resizeHandleType = this.getHandleType(event);
2156
+ this._core.store.setState('isResizeHandleSelected', this.isHandleSelected(event));
2157
+ this._core.store.setState('isRotationHandleSelected', this.isRotationHandleSelected(event));
2158
+ this._core.store.setState('resizeHandleType', this.getHandleType(event));
2137
2159
  const selectedObject = this.getSelectedObject(event);
2138
- const isDifferentObject = selectedObject && this._store.state.selectionGroup && selectedObject.id !== this._store.state.selectionGroup.id;
2160
+ const isDifferentObject = selectedObject && this._core.store.state.selectionGroup && selectedObject.id !== this._core.store.state.selectionGroup.id;
2139
2161
  if ((selectedObject === null || isDifferentObject) &&
2140
- this._store.state.selectionGroup &&
2141
- !this._store.state.isResizeHandleSelected &&
2142
- !this._store.state.isRotationHandleSelected) {
2143
- this._store.history.executeCommand(new RemoveSelectionGroupCommand(this._store, this._store.state.selectionGroup));
2162
+ this._core.store.state.selectionGroup &&
2163
+ !this._core.store.state.isResizeHandleSelected &&
2164
+ !this._core.store.state.isRotationHandleSelected) {
2165
+ this._core.history.executeCommand(new RemoveSelectionGroupCommand(this._core, this._core.store.state.selectionGroup));
2144
2166
  }
2145
2167
  if (selectedObject && selectedObject.isSelected === false && selectedObject?.objects.length === 1 && selectedObject.objects[0].isInteractive) {
2146
2168
  return;
@@ -2150,32 +2172,33 @@ class KritzelSelectionTool extends KritzelBaseTool {
2150
2172
  this.selectionHandler.handlePointerDown(event);
2151
2173
  this.resizeHandler.handlePointerDown(event);
2152
2174
  this.rotationHandler.handlePointerDown(event);
2153
- this._store.rerender();
2175
+ this._core.rerender();
2154
2176
  }
2155
2177
  if (event.pointerType === 'touch') {
2156
- if (this._store.state.isScaling === true) {
2178
+ if (this._core.store.state.isScaling === true) {
2157
2179
  return;
2158
2180
  }
2159
- if (this._store.state.pointers.size === 1) {
2160
- this._store.state.isResizeHandleSelected = this.isHandleSelected(event);
2161
- this._store.state.isRotationHandleSelected = this.isRotationHandleSelected(event);
2162
- this._store.state.resizeHandleType = this.getHandleType(event);
2181
+ if (this._core.store.state.pointers.size === 1) {
2182
+ this._core.store.setState('isResizeHandleSelected', this.isHandleSelected(event));
2183
+ this._core.store.setState('isRotationHandleSelected', this.isRotationHandleSelected(event));
2184
+ this._core.store.setState('resizeHandleType', this.getHandleType(event));
2163
2185
  const selectedObject = this.getSelectedObject(event);
2164
- const isDifferentObject = selectedObject && this._store.state.selectionGroup && selectedObject.id !== this._store.state.selectionGroup.id;
2165
- if (!this._store.state.selectionGroup && selectedObject) {
2166
- this._store.state.skipContextMenu = true;
2186
+ const isDifferentObject = selectedObject && this._core.store.state.selectionGroup && selectedObject.id !== this._core.store.state.selectionGroup.id;
2187
+ if (!this._core.store.state.selectionGroup && selectedObject) {
2188
+ this._core.store.setState('skipContextMenu', true);
2167
2189
  }
2168
2190
  if ((selectedObject === null || isDifferentObject) &&
2169
- this._store.state.selectionGroup &&
2170
- !this._store.state.isResizeHandleSelected &&
2171
- !this._store.state.isRotationHandleSelected) {
2172
- this._store.history.executeCommand(new RemoveSelectionGroupCommand(this._store, this._store.state.selectionGroup));
2191
+ this._core.store.state.selectionGroup &&
2192
+ !this._core.store.state.isResizeHandleSelected &&
2193
+ !this._core.store.state.isRotationHandleSelected) {
2194
+ this._core.history.executeCommand(new RemoveSelectionGroupCommand(this._core, this._core.store.state.selectionGroup));
2173
2195
  }
2174
2196
  }
2175
2197
  this.rotationHandler.handlePointerDown(event);
2176
2198
  this.resizeHandler.handlePointerDown(event);
2177
2199
  this.moveHandler.handlePointerDown(event);
2178
2200
  this.selectionHandler.handlePointerDown(event);
2201
+ this._core.rerender();
2179
2202
  }
2180
2203
  }
2181
2204
  handlePointerMove(event) {
@@ -2188,17 +2211,17 @@ class KritzelSelectionTool extends KritzelBaseTool {
2188
2211
  this.selectionHandler.handlePointerMove(event);
2189
2212
  this.resizeHandler.handlePointerMove(event);
2190
2213
  this.rotationHandler.handlePointerMove(event);
2191
- this._store.rerender();
2214
+ this._core.rerender();
2192
2215
  }
2193
2216
  if (event.pointerType === 'touch') {
2194
- if (this._store.state.isScaling === true) {
2217
+ if (this._core.store.state.isScaling === true) {
2195
2218
  return;
2196
2219
  }
2197
2220
  this.rotationHandler.handlePointerMove(event);
2198
2221
  this.resizeHandler.handlePointerMove(event);
2199
2222
  this.moveHandler.handlePointerMove(event);
2200
2223
  this.selectionHandler.handlePointerMove(event);
2201
- this._store.rerender();
2224
+ this._core.rerender();
2202
2225
  }
2203
2226
  }
2204
2227
  handlePointerUp(event) {
@@ -2210,22 +2233,23 @@ class KritzelSelectionTool extends KritzelBaseTool {
2210
2233
  this.selectionHandler.handlePointerUp(event);
2211
2234
  this.resizeHandler.handlePointerUp(event);
2212
2235
  this.rotationHandler.handlePointerUp(event);
2213
- this._store.rerender();
2236
+ this._core.rerender();
2214
2237
  }
2215
2238
  if (event.pointerType === 'touch') {
2216
- if (this._store.state.isScaling === true) {
2239
+ if (this._core.store.state.isScaling === true) {
2217
2240
  return;
2218
2241
  }
2219
2242
  this.rotationHandler.handlePointerUp(event);
2220
2243
  this.resizeHandler.handlePointerUp(event);
2221
2244
  this.moveHandler.handlePointerUp(event);
2222
2245
  this.selectionHandler.handlePointerUp(event);
2246
+ this._core.rerender();
2223
2247
  }
2224
2248
  }
2225
2249
  getSelectedObject(event) {
2226
2250
  const path = event.composedPath().slice(1);
2227
2251
  const objectElement = path.find(element => element.classList && element.classList.contains('object'));
2228
- const object = this._store.findObjectById(objectElement?.id);
2252
+ const object = this._core.findObjectById(objectElement?.id);
2229
2253
  if (!object) {
2230
2254
  return null;
2231
2255
  }
@@ -2233,7 +2257,7 @@ class KritzelSelectionTool extends KritzelBaseTool {
2233
2257
  return object;
2234
2258
  }
2235
2259
  else {
2236
- const group = KritzelSelectionGroup.create(this._store);
2260
+ const group = KritzelSelectionGroup.create(this._core);
2237
2261
  group.translateX = 0;
2238
2262
  group.translateY = 0;
2239
2263
  group.addOrRemove(object);
@@ -2241,7 +2265,7 @@ class KritzelSelectionTool extends KritzelBaseTool {
2241
2265
  }
2242
2266
  }
2243
2267
  getHandleType(event) {
2244
- const shadowRoot = this._store.state.host?.shadowRoot;
2268
+ const shadowRoot = this._core.store.state.host?.shadowRoot;
2245
2269
  if (!shadowRoot)
2246
2270
  return;
2247
2271
  const elementAtPoint = shadowRoot.elementFromPoint(event.clientX, event.clientY);
@@ -2249,7 +2273,7 @@ class KritzelSelectionTool extends KritzelBaseTool {
2249
2273
  return handle?.classList[1];
2250
2274
  }
2251
2275
  isHandleSelected(event) {
2252
- const shadowRoot = this._store.state.host?.shadowRoot;
2276
+ const shadowRoot = this._core.store.state.host?.shadowRoot;
2253
2277
  if (!shadowRoot)
2254
2278
  return false;
2255
2279
  const elementAtPoint = shadowRoot.elementFromPoint(event.clientX, event.clientY);
@@ -2261,10 +2285,144 @@ class KritzelSelectionTool extends KritzelBaseTool {
2261
2285
  }
2262
2286
  }
2263
2287
 
2288
+ const DEFAULT_BRUSH_CONFIG = {
2289
+ type: 'pen',
2290
+ color: '#000000',
2291
+ size: 16,
2292
+ palettes: {
2293
+ pen: [
2294
+ '#000000',
2295
+ '#ff5252',
2296
+ '#ffbc00',
2297
+ '#00c853',
2298
+ '#0000FF',
2299
+ '#d500f9',
2300
+ '#fafafa',
2301
+ '#a52714',
2302
+ '#ee8100',
2303
+ '#558b2f',
2304
+ '#01579b',
2305
+ '#8e24aa',
2306
+ '#90a4ae',
2307
+ '#ff4081',
2308
+ '#ff6e40',
2309
+ '#aeea00',
2310
+ '#304ffe',
2311
+ '#7c4dff',
2312
+ '#cfd8dc',
2313
+ '#f8bbd0',
2314
+ '#ffccbc',
2315
+ '#f0f4c3',
2316
+ '#9fa8da',
2317
+ '#d1c4e9',
2318
+ ],
2319
+ highlighter: [
2320
+ '#0000006e',
2321
+ '#ff52526e',
2322
+ '#ffbb006e',
2323
+ '#00c8536e',
2324
+ '#0000FF6e',
2325
+ '#d500f96e',
2326
+ '#fafafa6e',
2327
+ '#a527146e',
2328
+ '#ee81006e',
2329
+ '#558b2f6e',
2330
+ '#01579b6e',
2331
+ '#8e24aa6e',
2332
+ '#90a4ae6e',
2333
+ '#ff40816e',
2334
+ '#ff6e406e',
2335
+ '#aeea006e',
2336
+ '#304ffe6e',
2337
+ '#7c4dff6e',
2338
+ '#cfd8dc6e',
2339
+ '#f8bbd06e',
2340
+ '#ffccbc6e',
2341
+ '#f0f4c36e',
2342
+ '#9fa8da6e',
2343
+ '#d1c4e96e',
2344
+ ],
2345
+ },
2346
+ };
2347
+
2348
+ const DEFAULT_TEXT_CONFIG = {
2349
+ color: '#000000',
2350
+ size: 8,
2351
+ fontFamily: 'Arial',
2352
+ palette: [
2353
+ '#000000',
2354
+ '#ff5252',
2355
+ '#ffbc00',
2356
+ '#00c853',
2357
+ '#0000FF',
2358
+ '#d500f9',
2359
+ '#fafafa',
2360
+ '#a52714',
2361
+ '#ee8100',
2362
+ '#558b2f',
2363
+ '#01579b',
2364
+ '#8e24aa',
2365
+ '#90a4ae',
2366
+ '#ff4081',
2367
+ '#ff6e40',
2368
+ '#aeea00',
2369
+ '#304ffe',
2370
+ '#7c4dff',
2371
+ '#cfd8dc',
2372
+ '#f8bbd0',
2373
+ '#ffccbc',
2374
+ '#f0f4c3',
2375
+ '#9fa8da',
2376
+ '#d1c4e9',
2377
+ ],
2378
+ };
2379
+
2380
+ class KritzelWorkspace {
2381
+ __class__ = 'KritzelWorkspace';
2382
+ id;
2383
+ name;
2384
+ createdAt;
2385
+ updatedAt;
2386
+ viewport;
2387
+ _core;
2388
+ constructor(id, name, viewport = { translateX: 0, translateY: 0, scale: 1 }) {
2389
+ this.id = id;
2390
+ this.name = name;
2391
+ this.createdAt = new Date();
2392
+ this.updatedAt = new Date();
2393
+ this.viewport = viewport;
2394
+ }
2395
+ static create(core, obj) {
2396
+ const workspace = new KritzelWorkspace(obj.id, obj.name, obj.viewport);
2397
+ workspace._core = core;
2398
+ Object.assign(workspace, obj);
2399
+ return workspace;
2400
+ }
2401
+ addObject(obj) {
2402
+ this._core.engine.addObject(obj);
2403
+ }
2404
+ serialize() {
2405
+ return {
2406
+ __class__: this.__class__,
2407
+ id: this.id,
2408
+ name: this.name,
2409
+ createdAt: this.createdAt,
2410
+ updatedAt: this.updatedAt,
2411
+ viewport: this.viewport,
2412
+ };
2413
+ }
2414
+ deserialize(object) {
2415
+ Object.assign(this, object);
2416
+ this.createdAt = new Date(object.createdAt);
2417
+ this.updatedAt = new Date(object.updatedAt);
2418
+ return this;
2419
+ }
2420
+ }
2421
+
2264
2422
  class KritzelReviver {
2265
- _store;
2266
- constructor(store) {
2267
- this._store = store;
2423
+ _core;
2424
+ constructor(core) {
2425
+ this._core = core;
2268
2426
  }
2269
2427
  revive(obj) {
2270
2428
  if (obj && typeof obj === 'object') {
@@ -2272,34 +2430,37 @@ class KritzelReviver {
2272
2430
  let revivedObj;
2273
2431
  switch (obj.__class__) {
2274
2432
  case 'KritzelPath':
2275
- revivedObj = KritzelPath.create(this._store).revive(obj);
2433
+ revivedObj = KritzelPath.create(this._core).deserialize(obj);
2276
2434
  break;
2277
2435
  case 'KritzelText':
2278
- revivedObj = KritzelText.create(this._store, obj.fontSize, obj.fontFamily).revive(obj);
2436
+ revivedObj = KritzelText.create(this._core, obj.fontSize, obj.fontFamily).deserialize(obj);
2279
2437
  break;
2280
2438
  case 'KritzelImage':
2281
- revivedObj = KritzelImage.create(this._store).revive(obj);
2439
+ revivedObj = KritzelImage.create(this._core).deserialize(obj);
2282
2440
  break;
2283
2441
  case 'KritzelCustomElement':
2284
- revivedObj = KritzelCustomElement.create(this._store).revive(obj);
2442
+ revivedObj = KritzelCustomElement.create(this._core).deserialize(obj);
2285
2443
  break;
2286
2444
  case 'KritzelSelectionGroup':
2287
- revivedObj = KritzelSelectionGroup.create(this._store).revive(obj);
2445
+ revivedObj = KritzelSelectionGroup.create(this._core).deserialize(obj);
2446
+ break;
2447
+ case 'KritzelWorkspace':
2448
+ revivedObj = KritzelWorkspace.create(this._core, obj).deserialize(obj);
2288
2449
  break;
2289
2450
  case 'KritzelBrushTool':
2290
- revivedObj = new KritzelBrushTool(this._store);
2451
+ revivedObj = new KritzelBrushTool(this._core);
2291
2452
  break;
2292
2453
  case 'KritzelEraserTool':
2293
- revivedObj = new KritzelEraserTool(this._store);
2454
+ revivedObj = new KritzelEraserTool(this._core);
2294
2455
  break;
2295
2456
  case 'KritzelImageTool':
2296
- revivedObj = new KritzelImageTool(this._store);
2457
+ revivedObj = new KritzelImageTool(this._core);
2297
2458
  break;
2298
2459
  case 'KritzelSelectionTool':
2299
- revivedObj = new KritzelSelectionTool(this._store);
2460
+ revivedObj = new KritzelSelectionTool(this._core);
2300
2461
  break;
2301
2462
  case 'KritzelTextTool':
2302
- revivedObj = new KritzelTextTool(this._store);
2463
+ revivedObj = new KritzelTextTool(this._core);
2303
2464
  break;
2304
2465
  default:
2305
2466
  revivedObj = obj;
@@ -2329,12 +2490,12 @@ class KritzelSelectionGroup extends KritzelBaseObject {
2329
2490
  get length() {
2330
2491
  return this.objects.length;
2331
2492
  }
2332
- static create(store) {
2493
+ static create(core) {
2333
2494
  const object = new KritzelSelectionGroup();
2334
- object._store = store;
2495
+ object._core = core;
2335
2496
  object.id = object.generateId();
2336
- object.workspaceId = store.state.activeWorkspace.id;
2337
- object.scale = store.state.scale;
2497
+ object.workspaceId = core.store.state.activeWorkspace.id;
2498
+ object.scale = core.store.state.scale;
2338
2499
  object.zIndex = 99999;
2339
2500
  return object;
2340
2501
  }
@@ -2346,7 +2507,7 @@ class KritzelSelectionGroup extends KritzelBaseObject {
2346
2507
  else {
2347
2508
  this.objects.splice(index, 1);
2348
2509
  }
2349
- this.unchangedObjects = ObjectHelper.clone(this.objects);
2510
+ this.unchangedObjects = this.objects.map(obj => obj.clone());
2350
2511
  this.refreshObjectDimensions();
2351
2512
  }
2352
2513
  deselectAllChildren() {
@@ -2366,17 +2527,17 @@ class KritzelSelectionGroup extends KritzelBaseObject {
2366
2527
  });
2367
2528
  this.translateX = x;
2368
2529
  this.translateY = y;
2369
- this._store.state.objectsMap.update(this);
2530
+ this._core.store.state.objectsMap.update(this);
2370
2531
  }
2371
2532
  move(startX, startY, endX, endY) {
2372
- const deltaX = (startX - endX) / this._store.state.scale;
2373
- const deltaY = (startY - endY) / this._store.state.scale;
2533
+ const deltaX = (startX - endX) / this._core.store.state.scale;
2534
+ const deltaY = (startY - endY) / this._core.store.state.scale;
2374
2535
  this.translateX += deltaX;
2375
2536
  this.translateY += deltaY;
2376
- this._store.state.objectsMap.update(this);
2537
+ this._core.store.state.objectsMap.update(this);
2377
2538
  this.objects.forEach(obj => {
2378
2539
  obj.move(startX, startY, endX, endY);
2379
- this._store.state.objectsMap.update(obj);
2540
+ this._core.store.state.objectsMap.update(obj);
2380
2541
  });
2381
2542
  this.unchangedObjects.forEach(obj => {
2382
2543
  obj.translateX += deltaX;
@@ -2394,10 +2555,10 @@ class KritzelSelectionGroup extends KritzelBaseObject {
2394
2555
  const updatedX = child.translateX + deltaX + (child.translateX - this.translateX) * (widthScaleFactor - 1);
2395
2556
  const updatedY = child.translateY + deltaY + (child.translateY - this.translateY) * (heightScaleFactor - 1);
2396
2557
  child.resize(updatedX, updatedY, updatedWidth, updatedHeight);
2397
- this._store.state.objectsMap.update(child);
2558
+ this._core.store.state.objectsMap.update(child);
2398
2559
  });
2399
2560
  this.refreshObjectDimensions();
2400
- this.unchangedObjects = ObjectHelper.clone(this.objects);
2561
+ this.unchangedObjects = this.objects.map(obj => obj.clone());
2401
2562
  }
2402
2563
  rotate(value) {
2403
2564
  this.rotation = value;
@@ -2415,19 +2576,19 @@ class KritzelSelectionGroup extends KritzelBaseObject {
2415
2576
  child.translateX = centerX + rotatedX - child.totalWidth / 2 / child.scale;
2416
2577
  child.translateY = centerY + rotatedY - child.totalHeight / 2 / child.scale;
2417
2578
  child.rotate(this.objects.length === 1 ? value : value + unchangedChild.rotation);
2418
- this._store.state.objectsMap.update(child);
2579
+ this._core.store.state.objectsMap.update(child);
2419
2580
  });
2420
2581
  }
2421
2582
  copy() {
2422
- const selectionGroup = KritzelSelectionGroup.create(this._store);
2423
- let currentZIndex = this._store.currentZIndex;
2583
+ const selectionGroup = KritzelSelectionGroup.create(this._core);
2584
+ let currentZIndex = this._core.store.currentZIndex;
2424
2585
  this.objects.sort((a, b) => a.zIndex - b.zIndex).forEach(obj => {
2425
2586
  const copiedObject = obj.copy();
2426
2587
  copiedObject.zIndex = currentZIndex;
2427
2588
  selectionGroup.addOrRemove(copiedObject);
2428
2589
  currentZIndex++;
2429
2590
  });
2430
- selectionGroup.unchangedObjects = ObjectHelper.clone(selectionGroup.objects);
2591
+ selectionGroup.unchangedObjects = selectionGroup.objects.map(obj => obj.clone());
2431
2592
  if (this.objects.length === 1) {
2432
2593
  selectionGroup.rotation = this.objects[0].rotation;
2433
2594
  }
@@ -2455,7 +2616,7 @@ class KritzelSelectionGroup extends KritzelBaseObject {
2455
2616
  this.width = (this.maxX - this.minX - this.padding) * this.scale;
2456
2617
  this.height = (this.maxY - this.minY - this.padding) * this.scale;
2457
2618
  }
2458
- this._store.state.objectsMap.update(this);
2619
+ this._core.store.state.objectsMap.update(this);
2459
2620
  }
2460
2621
  getOffsetXToCenter(obj) {
2461
2622
  const objCenterX = obj.translateX + obj.totalWidth / obj.scale / 2;
@@ -2469,7 +2630,7 @@ class KritzelSelectionGroup extends KritzelBaseObject {
2469
2630
  }
2470
2631
  getUnchangedObject(objectId) {
2471
2632
  const obj = this.unchangedObjects.find(obj => obj.id === objectId);
2472
- const reviver = new KritzelReviver(this._store);
2633
+ const reviver = new KritzelReviver(this._core);
2473
2634
  return reviver.revive(obj);
2474
2635
  }
2475
2636
  }
@@ -2486,15 +2647,15 @@ function _mergeNamespaces(e,t){return t.forEach((function(t){t&&"string"!=typeof
2486
2647
  class KritzelImageTool extends KritzelBaseTool {
2487
2648
  fileInput = null;
2488
2649
  maxCompressionSize = 300;
2489
- constructor(store) {
2490
- super(store);
2650
+ constructor(core) {
2651
+ super(core);
2491
2652
  this.setupFileInput();
2492
2653
  }
2493
2654
  onActivate() {
2494
2655
  this.openFilePicker();
2495
2656
  }
2496
2657
  openFilePicker() {
2497
- if (this._store.isDisabled) {
2658
+ if (this._core.store.isDisabled) {
2498
2659
  return;
2499
2660
  }
2500
2661
  this.fileInput.click();
@@ -2541,138 +2702,31 @@ class KritzelImageTool extends KritzelBaseTool {
2541
2702
  reader.readAsDataURL(file);
2542
2703
  }
2543
2704
  createKritzelImage(img) {
2544
- const image = KritzelImage.create(this._store);
2705
+ const image = KritzelImage.create(this._core);
2545
2706
  const { scaledWidth, scaledHeight } = image.calculateScaledDimensions(img);
2546
2707
  image.src = img.src;
2547
2708
  image.width = scaledWidth;
2548
2709
  image.height = scaledHeight;
2549
- image.zIndex = this._store.currentZIndex;
2710
+ image.zIndex = this._core.store.currentZIndex;
2550
2711
  image.centerInViewport();
2551
2712
  this.addImageToStore(image);
2552
2713
  return image;
2553
2714
  }
2554
2715
  addImageToStore(image) {
2555
- const selectionGroup = KritzelSelectionGroup.create(this._store);
2716
+ const selectionGroup = KritzelSelectionGroup.create(this._core);
2556
2717
  selectionGroup.addOrRemove(image);
2557
2718
  selectionGroup.isSelected = true;
2558
- const addImageCommand = new AddObjectCommand(this._store, this, image);
2559
- const addSelectionGroupCommand = new AddSelectionGroupCommand(this._store, this, selectionGroup);
2560
- this._store.history.executeCommand(new BatchCommand(this._store, this, [addImageCommand, addSelectionGroupCommand]));
2561
- this._store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
2719
+ const addImageCommand = new AddObjectCommand(this._core, this, image);
2720
+ const addSelectionGroupCommand = new AddSelectionGroupCommand(this._core, this, selectionGroup);
2721
+ this._core.history.executeCommand(new BatchCommand(this._core, this, [addImageCommand, addSelectionGroupCommand]));
2722
+ this._core.store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
2562
2723
  }
2563
2724
  handleCancel() {
2564
- this._store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
2565
- }
2566
- }
2567
-
2568
- const DEFAULT_BRUSH_CONFIG = {
2569
- type: 'pen',
2570
- color: '#000000',
2571
- size: 16,
2572
- palettes: {
2573
- pen: [
2574
- '#000000',
2575
- '#ff5252',
2576
- '#ffbc00',
2577
- '#00c853',
2578
- '#0000FF',
2579
- '#d500f9',
2580
- '#fafafa',
2581
- '#a52714',
2582
- '#ee8100',
2583
- '#558b2f',
2584
- '#01579b',
2585
- '#8e24aa',
2586
- '#90a4ae',
2587
- '#ff4081',
2588
- '#ff6e40',
2589
- '#aeea00',
2590
- '#304ffe',
2591
- '#7c4dff',
2592
- '#cfd8dc',
2593
- '#f8bbd0',
2594
- '#ffccbc',
2595
- '#f0f4c3',
2596
- '#9fa8da',
2597
- '#d1c4e9',
2598
- ],
2599
- highlighter: [
2600
- '#0000006e',
2601
- '#ff52526e',
2602
- '#ffbb006e',
2603
- '#00c8536e',
2604
- '#0000FF6e',
2605
- '#d500f96e',
2606
- '#fafafa6e',
2607
- '#a527146e',
2608
- '#ee81006e',
2609
- '#558b2f6e',
2610
- '#01579b6e',
2611
- '#8e24aa6e',
2612
- '#90a4ae6e',
2613
- '#ff40816e',
2614
- '#ff6e406e',
2615
- '#aeea006e',
2616
- '#304ffe6e',
2617
- '#7c4dff6e',
2618
- '#cfd8dc6e',
2619
- '#f8bbd06e',
2620
- '#ffccbc6e',
2621
- '#f0f4c36e',
2622
- '#9fa8da6e',
2623
- '#d1c4e96e',
2624
- ],
2625
- },
2626
- };
2627
-
2628
- const DEFAULT_TEXT_CONFIG = {
2629
- color: '#000000',
2630
- size: 8,
2631
- fontFamily: 'Arial',
2632
- palette: [
2633
- '#000000',
2634
- '#ff5252',
2635
- '#ffbc00',
2636
- '#00c853',
2637
- '#0000FF',
2638
- '#d500f9',
2639
- '#fafafa',
2640
- '#a52714',
2641
- '#ee8100',
2642
- '#558b2f',
2643
- '#01579b',
2644
- '#8e24aa',
2645
- '#90a4ae',
2646
- '#ff4081',
2647
- '#ff6e40',
2648
- '#aeea00',
2649
- '#304ffe',
2650
- '#7c4dff',
2651
- '#cfd8dc',
2652
- '#f8bbd0',
2653
- '#ffccbc',
2654
- '#f0f4c3',
2655
- '#9fa8da',
2656
- '#d1c4e9',
2657
- ],
2658
- };
2659
-
2660
- class KritzelWorkspace {
2661
- id;
2662
- name;
2663
- createdAt;
2664
- updatedAt;
2665
- viewport;
2666
- constructor(id, name, viewport = { translateX: 0, translateY: 0, scale: 1 }) {
2667
- this.id = id;
2668
- this.name = name;
2669
- this.createdAt = new Date();
2670
- this.updatedAt = new Date();
2671
- this.viewport = viewport;
2725
+ this._core.store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
2672
2726
  }
2673
2727
  }
2674
2728
 
2675
- export { AddObjectCommand as A, BatchCommand as B, DEFAULT_BRUSH_CONFIG as D, KritzelBrushTool as K, ObjectHelper as O, RemoveSelectionGroupCommand as R, UpdateObjectCommand as U, KritzelTextTool as a, KritzelMouseButton as b, KritzelSelectionTool as c, KritzelEraserTool as d, DEFAULT_TEXT_CONFIG as e, KritzelImageTool as f, KritzelKeyboardHelper as g, KritzelEventHelper as h, KritzelBaseCommand as i, KritzelSelectionGroup as j, KrtizelSelectionBox as k, KritzelWorkspace as l, KritzelReviver as m, RemoveObjectCommand as n, AddSelectionGroupCommand as o, KritzelToolRegistry as p, KritzelBaseHandler as q, KritzelBaseTool as r, KritzelText as s, KritzelPath as t, KritzelImage as u };
2676
- //# sourceMappingURL=index-B-oSk-v8.js.map
2729
+ export { AddSelectionGroupCommand as A, BatchCommand as B, DEFAULT_BRUSH_CONFIG as D, KritzelBrushTool as K, ObjectHelper as O, RemoveSelectionGroupCommand as R, UpdateObjectCommand as U, KritzelTextTool as a, KritzelMouseButton as b, KritzelSelectionTool as c, KritzelEraserTool as d, DEFAULT_TEXT_CONFIG as e, KritzelImageTool as f, KritzelWorkspace as g, KritzelKeyboardHelper as h, KritzelEventHelper as i, KritzelBaseHandler as j, KritzelToolRegistry as k, KritzelSelectionGroup as l, KritzelBaseCommand as m, KrtizelSelectionBox as n, KritzelReviver as o, RemoveObjectCommand as p, AddObjectCommand as q, KritzelBaseTool as r, KritzelText as s, KritzelPath as t, KritzelImage as u };
2730
+ //# sourceMappingURL=index-DY3KqYWc.js.map
2677
2731
 
2678
- //# sourceMappingURL=index-B-oSk-v8.js.map
2732
+ //# sourceMappingURL=index-DY3KqYWc.js.map