kritzel-react 0.1.32 → 0.1.34

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 (210) hide show
  1. package/dist/types/components/stencil-generated/components.d.ts +1 -1
  2. package/package.json +2 -2
  3. package/dist/kritzel-react/lib/components/stencil-generated/components.js +0 -122
  4. package/dist/kritzel-react/lib/index.js +0 -2
  5. package/dist/kritzel-stencil/src/classes/core/core.class.js +0 -797
  6. package/dist/kritzel-stencil/src/classes/core/reviver.class.js +0 -97
  7. package/dist/kritzel-stencil/src/classes/core/store.class.js +0 -153
  8. package/dist/kritzel-stencil/src/classes/core/viewport.class.js +0 -311
  9. package/dist/kritzel-stencil/src/classes/core/workspace.class.js +0 -34
  10. package/dist/kritzel-stencil/src/classes/handlers/base.handler.js +0 -6
  11. package/dist/kritzel-stencil/src/classes/handlers/context-menu.handler.js +0 -63
  12. package/dist/kritzel-stencil/src/classes/handlers/hover.handler.js +0 -18
  13. package/dist/kritzel-stencil/src/classes/handlers/key.handler.js +0 -76
  14. package/dist/kritzel-stencil/src/classes/handlers/line-handle.handler.js +0 -382
  15. package/dist/kritzel-stencil/src/classes/handlers/move.handler.js +0 -213
  16. package/dist/kritzel-stencil/src/classes/handlers/resize.handler.js +0 -205
  17. package/dist/kritzel-stencil/src/classes/handlers/rotation.handler.js +0 -117
  18. package/dist/kritzel-stencil/src/classes/handlers/selection.handler.js +0 -313
  19. package/dist/kritzel-stencil/src/classes/managers/anchor.manager.js +0 -1056
  20. package/dist/kritzel-stencil/src/classes/managers/cursor.manager.js +0 -117
  21. package/dist/kritzel-stencil/src/classes/managers/theme.manager.js +0 -103
  22. package/dist/kritzel-stencil/src/classes/objects/base-object.class.js +0 -249
  23. package/dist/kritzel-stencil/src/classes/objects/custom-element.class.js +0 -60
  24. package/dist/kritzel-stencil/src/classes/objects/group.class.js +0 -407
  25. package/dist/kritzel-stencil/src/classes/objects/image.class.js +0 -55
  26. package/dist/kritzel-stencil/src/classes/objects/line.class.js +0 -608
  27. package/dist/kritzel-stencil/src/classes/objects/path.class.js +0 -401
  28. package/dist/kritzel-stencil/src/classes/objects/selection-box.class.js +0 -21
  29. package/dist/kritzel-stencil/src/classes/objects/selection-group.class.js +0 -409
  30. package/dist/kritzel-stencil/src/classes/objects/shape.class.js +0 -412
  31. package/dist/kritzel-stencil/src/classes/objects/text.class.js +0 -292
  32. package/dist/kritzel-stencil/src/classes/providers/broadcast-sync-provider.class.js +0 -101
  33. package/dist/kritzel-stencil/src/classes/providers/hocuspocus-sync-provider.class.js +0 -241
  34. package/dist/kritzel-stencil/src/classes/providers/indexeddb-sync-provider.class.js +0 -43
  35. package/dist/kritzel-stencil/src/classes/providers/websocket-sync-provider.class.js +0 -98
  36. package/dist/kritzel-stencil/src/classes/registries/icon-registry.class.js +0 -66
  37. package/dist/kritzel-stencil/src/classes/registries/tool.registry.js +0 -21
  38. package/dist/kritzel-stencil/src/classes/structures/app-state-map.structure.js +0 -212
  39. package/dist/kritzel-stencil/src/classes/structures/object-map.structure.js +0 -414
  40. package/dist/kritzel-stencil/src/classes/structures/quadtree.structure.js +0 -151
  41. package/dist/kritzel-stencil/src/classes/tools/base-tool.class.js +0 -36
  42. package/dist/kritzel-stencil/src/classes/tools/brush-tool.class.js +0 -161
  43. package/dist/kritzel-stencil/src/classes/tools/eraser-tool.class.js +0 -85
  44. package/dist/kritzel-stencil/src/classes/tools/image-tool.class.js +0 -83
  45. package/dist/kritzel-stencil/src/classes/tools/line-tool.class.js +0 -187
  46. package/dist/kritzel-stencil/src/classes/tools/selection-tool.class.js +0 -429
  47. package/dist/kritzel-stencil/src/classes/tools/shape-tool.class.js +0 -196
  48. package/dist/kritzel-stencil/src/classes/tools/text-tool.class.js +0 -100
  49. package/dist/kritzel-stencil/src/components/core/kritzel-engine/kritzel-engine.js +0 -1343
  50. package/dist/kritzel-stencil/src/components/shared/kritzel-brush-style/kritzel-brush-style.js +0 -46
  51. package/dist/kritzel-stencil/src/components/shared/kritzel-dropdown/kritzel-dropdown.js +0 -312
  52. package/dist/kritzel-stencil/src/components/shared/kritzel-font-family/kritzel-font-family.js +0 -60
  53. package/dist/kritzel-stencil/src/components/shared/kritzel-line-endings/kritzel-line-endings.js +0 -105
  54. package/dist/kritzel-stencil/src/components/shared/kritzel-shape-fill/kritzel-shape-fill.js +0 -53
  55. package/dist/kritzel-stencil/src/components/ui/kritzel-context-menu/kritzel-context-menu.js +0 -137
  56. package/dist/kritzel-stencil/src/configs/default-brush-tool.config.js +0 -9
  57. package/dist/kritzel-stencil/src/configs/default-engine-config.js +0 -63
  58. package/dist/kritzel-stencil/src/configs/default-line-tool.config.js +0 -9
  59. package/dist/kritzel-stencil/src/configs/default-sync.config.js +0 -9
  60. package/dist/kritzel-stencil/src/configs/default-text-tool.config.js +0 -7
  61. package/dist/kritzel-stencil/src/constants/color-palette.constants.js +0 -37
  62. package/dist/kritzel-stencil/src/constants/engine.constants.js +0 -2
  63. package/dist/kritzel-stencil/src/enums/event-button.enum.js +0 -6
  64. package/dist/kritzel-stencil/src/enums/handle-type.enum.js +0 -7
  65. package/dist/kritzel-stencil/src/enums/shape-type.enum.js +0 -6
  66. package/dist/kritzel-stencil/src/helpers/class.helper.js +0 -5
  67. package/dist/kritzel-stencil/src/helpers/color.helper.js +0 -106
  68. package/dist/kritzel-stencil/src/helpers/cursor.helper.js +0 -57
  69. package/dist/kritzel-stencil/src/helpers/devices.helper.js +0 -28
  70. package/dist/kritzel-stencil/src/helpers/event.helper.js +0 -58
  71. package/dist/kritzel-stencil/src/helpers/geometry.helper.js +0 -149
  72. package/dist/kritzel-stencil/src/helpers/keyboard.helper.js +0 -51
  73. package/dist/kritzel-stencil/src/helpers/math.helper.js +0 -5
  74. package/dist/kritzel-stencil/src/helpers/object.helper.js +0 -11
  75. package/dist/kritzel-stencil/src/helpers/theme.helper.js +0 -69
  76. package/dist/kritzel-stencil/src/index.js +0 -41
  77. package/dist/kritzel-stencil/src/interfaces/anchor.interface.js +0 -1
  78. package/dist/kritzel-stencil/src/interfaces/arrow-head.interface.js +0 -1
  79. package/dist/kritzel-stencil/src/interfaces/bounding-box.interface.js +0 -1
  80. package/dist/kritzel-stencil/src/interfaces/clonable.interface.js +0 -1
  81. package/dist/kritzel-stencil/src/interfaces/context-menu-item.interface.js +0 -1
  82. package/dist/kritzel-stencil/src/interfaces/debug-info.interface.js +0 -1
  83. package/dist/kritzel-stencil/src/interfaces/dialog.interface.js +0 -1
  84. package/dist/kritzel-stencil/src/interfaces/displayable-shortcut.interface.js +0 -1
  85. package/dist/kritzel-stencil/src/interfaces/engine-state.interface.js +0 -1
  86. package/dist/kritzel-stencil/src/interfaces/line-options.interface.js +0 -1
  87. package/dist/kritzel-stencil/src/interfaces/master-detail.interface.js +0 -1
  88. package/dist/kritzel-stencil/src/interfaces/menu-item.interface.js +0 -1
  89. package/dist/kritzel-stencil/src/interfaces/object.interface.js +0 -1
  90. package/dist/kritzel-stencil/src/interfaces/path-options.interface.js +0 -1
  91. package/dist/kritzel-stencil/src/interfaces/point.interface.js +0 -1
  92. package/dist/kritzel-stencil/src/interfaces/polygon.interface.js +0 -1
  93. package/dist/kritzel-stencil/src/interfaces/serializable.interface.js +0 -1
  94. package/dist/kritzel-stencil/src/interfaces/settings.interface.js +0 -1
  95. package/dist/kritzel-stencil/src/interfaces/shortcut.interface.js +0 -1
  96. package/dist/kritzel-stencil/src/interfaces/sync-config.interface.js +0 -1
  97. package/dist/kritzel-stencil/src/interfaces/sync-provider.interface.js +0 -1
  98. package/dist/kritzel-stencil/src/interfaces/theme.interface.js +0 -1
  99. package/dist/kritzel-stencil/src/interfaces/tool-config.interface.js +0 -1
  100. package/dist/kritzel-stencil/src/interfaces/tool.interface.js +0 -1
  101. package/dist/kritzel-stencil/src/interfaces/toolbar-control.interface.js +0 -1
  102. package/dist/kritzel-stencil/src/interfaces/undo-state.interface.js +0 -1
  103. package/dist/kritzel-stencil/src/themes/dark-theme.js +0 -198
  104. package/dist/kritzel-stencil/src/themes/light-theme.js +0 -199
  105. package/dist/kritzel-stencil/src/types/shortcut.type.js +0 -1
  106. package/dist/kritzel-stencil/src/types/state.types.js +0 -1
  107. package/dist/types/kritzel-react/lib/components/stencil-generated/components.d.ts +0 -74
  108. package/dist/types/kritzel-react/lib/index.d.ts +0 -2
  109. package/dist/types/kritzel-stencil/src/classes/core/core.class.d.ts +0 -101
  110. package/dist/types/kritzel-stencil/src/classes/core/reviver.class.d.ts +0 -6
  111. package/dist/types/kritzel-stencil/src/classes/core/store.class.d.ts +0 -53
  112. package/dist/types/kritzel-stencil/src/classes/core/viewport.class.d.ts +0 -48
  113. package/dist/types/kritzel-stencil/src/classes/core/workspace.class.d.ts +0 -24
  114. package/dist/types/kritzel-stencil/src/classes/handlers/base.handler.d.ts +0 -5
  115. package/dist/types/kritzel-stencil/src/classes/handlers/context-menu.handler.d.ts +0 -8
  116. package/dist/types/kritzel-stencil/src/classes/handlers/hover.handler.d.ts +0 -6
  117. package/dist/types/kritzel-stencil/src/classes/handlers/key.handler.d.ts +0 -11
  118. package/dist/types/kritzel-stencil/src/classes/handlers/line-handle.handler.d.ts +0 -34
  119. package/dist/types/kritzel-stencil/src/classes/handlers/move.handler.d.ts +0 -29
  120. package/dist/types/kritzel-stencil/src/classes/handlers/resize.handler.d.ts +0 -24
  121. package/dist/types/kritzel-stencil/src/classes/handlers/rotation.handler.d.ts +0 -12
  122. package/dist/types/kritzel-stencil/src/classes/handlers/selection.handler.d.ts +0 -27
  123. package/dist/types/kritzel-stencil/src/classes/managers/anchor.manager.d.ts +0 -180
  124. package/dist/types/kritzel-stencil/src/classes/managers/cursor.manager.d.ts +0 -43
  125. package/dist/types/kritzel-stencil/src/classes/managers/theme.manager.d.ts +0 -56
  126. package/dist/types/kritzel-stencil/src/classes/objects/base-object.class.d.ts +0 -76
  127. package/dist/types/kritzel-stencil/src/classes/objects/custom-element.class.d.ts +0 -26
  128. package/dist/types/kritzel-stencil/src/classes/objects/group.class.d.ts +0 -97
  129. package/dist/types/kritzel-stencil/src/classes/objects/image.class.d.ts +0 -17
  130. package/dist/types/kritzel-stencil/src/classes/objects/line.class.d.ts +0 -101
  131. package/dist/types/kritzel-stencil/src/classes/objects/path.class.d.ts +0 -62
  132. package/dist/types/kritzel-stencil/src/classes/objects/selection-box.class.d.ts +0 -6
  133. package/dist/types/kritzel-stencil/src/classes/objects/selection-group.class.d.ts +0 -67
  134. package/dist/types/kritzel-stencil/src/classes/objects/shape.class.d.ts +0 -124
  135. package/dist/types/kritzel-stencil/src/classes/objects/text.class.d.ts +0 -56
  136. package/dist/types/kritzel-stencil/src/classes/providers/broadcast-sync-provider.class.d.ts +0 -18
  137. package/dist/types/kritzel-stencil/src/classes/providers/hocuspocus-sync-provider.class.d.ts +0 -120
  138. package/dist/types/kritzel-stencil/src/classes/providers/indexeddb-sync-provider.class.d.ts +0 -22
  139. package/dist/types/kritzel-stencil/src/classes/providers/websocket-sync-provider.class.d.ts +0 -52
  140. package/dist/types/kritzel-stencil/src/classes/registries/icon-registry.class.d.ts +0 -9
  141. package/dist/types/kritzel-stencil/src/classes/registries/tool.registry.d.ts +0 -8
  142. package/dist/types/kritzel-stencil/src/classes/structures/app-state-map.structure.d.ts +0 -31
  143. package/dist/types/kritzel-stencil/src/classes/structures/object-map.structure.d.ts +0 -63
  144. package/dist/types/kritzel-stencil/src/classes/structures/quadtree.structure.d.ts +0 -36
  145. package/dist/types/kritzel-stencil/src/classes/tools/base-tool.class.d.ts +0 -20
  146. package/dist/types/kritzel-stencil/src/classes/tools/brush-tool.class.d.ts +0 -14
  147. package/dist/types/kritzel-stencil/src/classes/tools/eraser-tool.class.d.ts +0 -9
  148. package/dist/types/kritzel-stencil/src/classes/tools/image-tool.class.d.ts +0 -15
  149. package/dist/types/kritzel-stencil/src/classes/tools/line-tool.class.d.ts +0 -19
  150. package/dist/types/kritzel-stencil/src/classes/tools/selection-tool.class.d.ts +0 -54
  151. package/dist/types/kritzel-stencil/src/classes/tools/shape-tool.class.d.ts +0 -39
  152. package/dist/types/kritzel-stencil/src/classes/tools/text-tool.class.d.ts +0 -13
  153. package/dist/types/kritzel-stencil/src/components/core/kritzel-engine/kritzel-engine.d.ts +0 -111
  154. package/dist/types/kritzel-stencil/src/components/shared/kritzel-brush-style/kritzel-brush-style.d.ts +0 -11
  155. package/dist/types/kritzel-stencil/src/components/shared/kritzel-dropdown/kritzel-dropdown.d.ts +0 -46
  156. package/dist/types/kritzel-stencil/src/components/shared/kritzel-font-family/kritzel-font-family.d.ts +0 -13
  157. package/dist/types/kritzel-stencil/src/components/shared/kritzel-line-endings/kritzel-line-endings.d.ts +0 -21
  158. package/dist/types/kritzel-stencil/src/components/shared/kritzel-shape-fill/kritzel-shape-fill.d.ts +0 -10
  159. package/dist/types/kritzel-stencil/src/components/ui/kritzel-context-menu/kritzel-context-menu.d.ts +0 -21
  160. package/dist/types/kritzel-stencil/src/configs/default-brush-tool.config.d.ts +0 -2
  161. package/dist/types/kritzel-stencil/src/configs/default-engine-config.d.ts +0 -2
  162. package/dist/types/kritzel-stencil/src/configs/default-line-tool.config.d.ts +0 -2
  163. package/dist/types/kritzel-stencil/src/configs/default-sync.config.d.ts +0 -5
  164. package/dist/types/kritzel-stencil/src/configs/default-text-tool.config.d.ts +0 -2
  165. package/dist/types/kritzel-stencil/src/constants/color-palette.constants.d.ts +0 -29
  166. package/dist/types/kritzel-stencil/src/constants/engine.constants.d.ts +0 -2
  167. package/dist/types/kritzel-stencil/src/enums/event-button.enum.d.ts +0 -5
  168. package/dist/types/kritzel-stencil/src/enums/handle-type.enum.d.ts +0 -6
  169. package/dist/types/kritzel-stencil/src/enums/shape-type.enum.d.ts +0 -5
  170. package/dist/types/kritzel-stencil/src/helpers/class.helper.d.ts +0 -3
  171. package/dist/types/kritzel-stencil/src/helpers/color.helper.d.ts +0 -33
  172. package/dist/types/kritzel-stencil/src/helpers/cursor.helper.d.ts +0 -22
  173. package/dist/types/kritzel-stencil/src/helpers/devices.helper.d.ts +0 -8
  174. package/dist/types/kritzel-stencil/src/helpers/event.helper.d.ts +0 -6
  175. package/dist/types/kritzel-stencil/src/helpers/geometry.helper.d.ts +0 -38
  176. package/dist/types/kritzel-stencil/src/helpers/keyboard.helper.d.ts +0 -6
  177. package/dist/types/kritzel-stencil/src/helpers/math.helper.d.ts +0 -3
  178. package/dist/types/kritzel-stencil/src/helpers/object.helper.d.ts +0 -4
  179. package/dist/types/kritzel-stencil/src/helpers/theme.helper.d.ts +0 -41
  180. package/dist/types/kritzel-stencil/src/index.d.ts +0 -42
  181. package/dist/types/kritzel-stencil/src/interfaces/anchor.interface.d.ts +0 -137
  182. package/dist/types/kritzel-stencil/src/interfaces/arrow-head.interface.d.ts +0 -27
  183. package/dist/types/kritzel-stencil/src/interfaces/bounding-box.interface.d.ts +0 -8
  184. package/dist/types/kritzel-stencil/src/interfaces/clonable.interface.d.ts +0 -3
  185. package/dist/types/kritzel-stencil/src/interfaces/context-menu-item.interface.d.ts +0 -17
  186. package/dist/types/kritzel-stencil/src/interfaces/debug-info.interface.d.ts +0 -4
  187. package/dist/types/kritzel-stencil/src/interfaces/dialog.interface.d.ts +0 -4
  188. package/dist/types/kritzel-stencil/src/interfaces/displayable-shortcut.interface.d.ts +0 -5
  189. package/dist/types/kritzel-stencil/src/interfaces/engine-state.interface.d.ts +0 -73
  190. package/dist/types/kritzel-stencil/src/interfaces/line-options.interface.d.ts +0 -23
  191. package/dist/types/kritzel-stencil/src/interfaces/master-detail.interface.d.ts +0 -14
  192. package/dist/types/kritzel-stencil/src/interfaces/menu-item.interface.d.ts +0 -24
  193. package/dist/types/kritzel-stencil/src/interfaces/object.interface.d.ts +0 -53
  194. package/dist/types/kritzel-stencil/src/interfaces/path-options.interface.d.ts +0 -11
  195. package/dist/types/kritzel-stencil/src/interfaces/point.interface.d.ts +0 -4
  196. package/dist/types/kritzel-stencil/src/interfaces/polygon.interface.d.ts +0 -7
  197. package/dist/types/kritzel-stencil/src/interfaces/serializable.interface.d.ts +0 -5
  198. package/dist/types/kritzel-stencil/src/interfaces/settings.interface.d.ts +0 -11
  199. package/dist/types/kritzel-stencil/src/interfaces/shortcut.interface.d.ts +0 -10
  200. package/dist/types/kritzel-stencil/src/interfaces/sync-config.interface.d.ts +0 -22
  201. package/dist/types/kritzel-stencil/src/interfaces/sync-provider.interface.d.ts +0 -29
  202. package/dist/types/kritzel-stencil/src/interfaces/theme.interface.d.ts +0 -330
  203. package/dist/types/kritzel-stencil/src/interfaces/tool-config.interface.d.ts +0 -26
  204. package/dist/types/kritzel-stencil/src/interfaces/tool.interface.d.ts +0 -7
  205. package/dist/types/kritzel-stencil/src/interfaces/toolbar-control.interface.d.ts +0 -58
  206. package/dist/types/kritzel-stencil/src/interfaces/undo-state.interface.d.ts +0 -6
  207. package/dist/types/kritzel-stencil/src/themes/dark-theme.d.ts +0 -5
  208. package/dist/types/kritzel-stencil/src/themes/light-theme.d.ts +0 -5
  209. package/dist/types/kritzel-stencil/src/types/shortcut.type.d.ts +0 -1
  210. package/dist/types/kritzel-stencil/src/types/state.types.d.ts +0 -3
@@ -1,412 +0,0 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
- import { KritzelToolRegistry } from '../registries/tool.registry';
13
- import { KritzelBaseObject } from './base-object.class';
14
- import { KritzelKeyboardHelper } from '../../helpers/keyboard.helper';
15
- import { KritzelDevicesHelper } from '../../helpers/devices.helper';
16
- import { KritzelGeometryHelper } from '../../helpers/geometry.helper';
17
- import { ShapeType } from '../../enums/shape-type.enum';
18
- import { EditorState, TextSelection } from 'prosemirror-state';
19
- import { EditorView } from 'prosemirror-view';
20
- import { Schema } from 'prosemirror-model';
21
- import { schema } from 'prosemirror-schema-basic';
22
- import { addListNodes } from 'prosemirror-schema-list';
23
- import { keymap } from 'prosemirror-keymap';
24
- import { baseKeymap } from 'prosemirror-commands';
25
- import { KritzelColorHelper } from '../../helpers/color.helper';
26
- export class KritzelShape extends KritzelBaseObject {
27
- /**
28
- * Returns the viewBox for the shape's SVG, using screen-space coordinates.
29
- * This follows the same pattern as KritzelPath.viewBox.
30
- */
31
- get viewBox() {
32
- return `${this.x} ${this.y} ${this.width} ${this.height}`;
33
- }
34
- constructor(config) {
35
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
36
- super();
37
- this.__class__ = 'KritzelShape';
38
- this.shapeType = ShapeType.Rectangle;
39
- this.fillColor = { light: 'transparent', dark: 'transparent' };
40
- this.strokeColor = { light: '#000000', dark: '#ffffff' };
41
- this.strokeWidth = 4;
42
- this.fontFamily = 'Arial';
43
- this.fontSize = 16;
44
- this.fontColor = { light: '#000000', dark: '#ffffff' };
45
- /** Screen-space x coordinate of the shape's top-left corner (like Path.x) */
46
- this.x = 0;
47
- /** Screen-space y coordinate of the shape's top-left corner (like Path.y) */
48
- this.y = 0;
49
- this.scale = 1;
50
- this.scaleFactor = 1;
51
- this.isDebugInfoVisible = true;
52
- this.isEditable = true;
53
- this.isEditing = false;
54
- this.editor = null;
55
- this.content = null;
56
- this._schema = new Schema({
57
- nodes: addListNodes(schema.spec.nodes, 'paragraph block*', 'block'),
58
- marks: schema.spec.marks,
59
- });
60
- this.uneditedObject = null;
61
- if (config) {
62
- this.x = (_a = config.x) !== null && _a !== void 0 ? _a : 0;
63
- this.y = (_b = config.y) !== null && _b !== void 0 ? _b : 0;
64
- this.translateX = (_c = config.translateX) !== null && _c !== void 0 ? _c : 0;
65
- this.translateY = (_d = config.translateY) !== null && _d !== void 0 ? _d : 0;
66
- this.width = (_e = config.width) !== null && _e !== void 0 ? _e : 100;
67
- this.height = (_f = config.height) !== null && _f !== void 0 ? _f : 100;
68
- this.shapeType = (_g = config.shapeType) !== null && _g !== void 0 ? _g : ShapeType.Rectangle;
69
- this.fillColor = (_h = config.fillColor) !== null && _h !== void 0 ? _h : { light: 'transparent', dark: 'transparent' };
70
- this.strokeColor = (_j = config.strokeColor) !== null && _j !== void 0 ? _j : { light: '#000000', dark: '#ffffff' };
71
- this.strokeWidth = (_k = config.strokeWidth) !== null && _k !== void 0 ? _k : 4;
72
- this.fontSize = (_l = config.fontSize) !== null && _l !== void 0 ? _l : 16;
73
- this.fontFamily = (_m = config.fontFamily) !== null && _m !== void 0 ? _m : 'Arial';
74
- this.fontColor = (_o = config.fontColor) !== null && _o !== void 0 ? _o : KritzelColorHelper.determineTextColor(this.fillColor);
75
- this.scale = (_p = config.scale) !== null && _p !== void 0 ? _p : 1;
76
- this.scaleFactor = (_q = config.scaleX) !== null && _q !== void 0 ? _q : 1;
77
- }
78
- }
79
- /**
80
- * Creates a new KritzelShape with screen-space coordinates.
81
- * Following the same pattern as KritzelPath.create():
82
- * - x, y are screen-space coordinates of the shape's top-left corner
83
- * - translateX, translateY should be set to -viewportTranslateX, -viewportTranslateY
84
- * - width, height are in screen-space
85
- * - scale is the viewport scale at creation time
86
- */
87
- static create(core, config) {
88
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
89
- const object = new KritzelShape();
90
- object._core = core;
91
- object.id = object.generateId();
92
- object.workspaceId = core.store.state.activeWorkspace.id;
93
- object.x = (_a = config === null || config === void 0 ? void 0 : config.x) !== null && _a !== void 0 ? _a : 0;
94
- object.y = (_b = config === null || config === void 0 ? void 0 : config.y) !== null && _b !== void 0 ? _b : 0;
95
- object.translateX = (_c = config === null || config === void 0 ? void 0 : config.translateX) !== null && _c !== void 0 ? _c : 0;
96
- object.translateY = (_d = config === null || config === void 0 ? void 0 : config.translateY) !== null && _d !== void 0 ? _d : 0;
97
- object.width = (_e = config === null || config === void 0 ? void 0 : config.width) !== null && _e !== void 0 ? _e : 100;
98
- object.height = (_f = config === null || config === void 0 ? void 0 : config.height) !== null && _f !== void 0 ? _f : 100;
99
- object.shapeType = (_g = config === null || config === void 0 ? void 0 : config.shapeType) !== null && _g !== void 0 ? _g : ShapeType.Rectangle;
100
- object.fillColor = (_h = config === null || config === void 0 ? void 0 : config.fillColor) !== null && _h !== void 0 ? _h : { light: 'transparent', dark: 'transparent' };
101
- object.strokeColor = (_j = config === null || config === void 0 ? void 0 : config.strokeColor) !== null && _j !== void 0 ? _j : { light: '#000000', dark: '#ffffff' };
102
- object.strokeWidth = (_k = config === null || config === void 0 ? void 0 : config.strokeWidth) !== null && _k !== void 0 ? _k : 4;
103
- object.opacity = (_l = config === null || config === void 0 ? void 0 : config.opacity) !== null && _l !== void 0 ? _l : 1;
104
- object.fontSize = (_m = config === null || config === void 0 ? void 0 : config.fontSize) !== null && _m !== void 0 ? _m : 16;
105
- object.fontFamily = (_o = config === null || config === void 0 ? void 0 : config.fontFamily) !== null && _o !== void 0 ? _o : 'Arial';
106
- object.fontColor = (_p = config === null || config === void 0 ? void 0 : config.fontColor) !== null && _p !== void 0 ? _p : KritzelColorHelper.determineTextColor(object.fillColor);
107
- object.backgroundColor = { light: 'transparent', dark: 'transparent' };
108
- object.scaleFactor = 1;
109
- object.scale = (_q = config === null || config === void 0 ? void 0 : config.scale) !== null && _q !== void 0 ? _q : core.store.state.scale;
110
- object.zIndex = core.store.currentZIndex;
111
- object.editor = object.createEditor();
112
- // Compute world-space translateX/Y from screen-space coordinates
113
- // This follows the same pattern as KritzelPath.updateDimensions()
114
- object.updateDimensions();
115
- return object;
116
- }
117
- /**
118
- * Updates the translateX/Y to world coordinates based on screen-space x, y.
119
- * This follows the same pattern as KritzelPath.updateDimensions().
120
- *
121
- * The formula: translateX = (x + initialTranslateX) / scale
122
- * where initialTranslateX was -viewportTranslateX
123
- *
124
- * This converts screen-space position to world coordinates.
125
- */
126
- updateDimensions() {
127
- this.translateX = (this.x + this.translateX) / this.scale;
128
- this.translateY = (this.y + this.translateY) / this.scale;
129
- }
130
- mount(element) {
131
- if (element === null || this.isInViewport() === false) {
132
- return;
133
- }
134
- if (this.isMounted && this.elementRef === element && this.editor.dom.parentElement === element) {
135
- return;
136
- }
137
- this.elementRef = element;
138
- this.isMounted = true;
139
- }
140
- mountTextEditor(element) {
141
- if (element === null) {
142
- return;
143
- }
144
- element.style.fontFamily = this.fontFamily;
145
- element.style.fontSize = `${this.fontSize}pt`;
146
- element.style.color = KritzelColorHelper.resolveThemeColor(this.fontColor);
147
- element.style.whiteSpace = 'pre-wrap';
148
- element.style.wordWrap = 'break-word';
149
- if (this.editor.dom.parentElement === element) {
150
- return;
151
- }
152
- element.innerHTML = '';
153
- element.appendChild(this.editor.dom);
154
- }
155
- createEditor() {
156
- const doc = this._schema.node('doc', null, [this._schema.node('paragraph')]);
157
- return new EditorView(null, {
158
- state: EditorState.create({
159
- doc: doc,
160
- plugins: [keymap(baseKeymap)],
161
- }),
162
- editable: () => false,
163
- dispatchTransaction: transaction => {
164
- const newState = this.editor.state.apply(transaction);
165
- this.editor.updateState(newState);
166
- if (transaction.docChanged) {
167
- this.content = newState.doc.toJSON();
168
- if (!transaction.getMeta('fromRemote')) {
169
- this._core.store.state.objects.update(this, { temporary: true });
170
- }
171
- }
172
- },
173
- });
174
- }
175
- setContent(content) {
176
- this.content = content;
177
- if (this.editor && content) {
178
- const newDoc = this.editor.state.schema.nodeFromJSON(content);
179
- const tr = this.editor.state.tr.replaceWith(0, this.editor.state.doc.content.size, newDoc.content);
180
- tr.setMeta('fromRemote', true);
181
- this.editor.dispatch(tr);
182
- }
183
- }
184
- resize(x, y, width, height) {
185
- if (width <= 1 || height <= 1) {
186
- return;
187
- }
188
- this.width = width;
189
- this.height = height;
190
- this.translateX = x;
191
- this.translateY = y;
192
- this._core.store.state.objects.update(this);
193
- }
194
- focus(coords) {
195
- if (this.editor) {
196
- const doc = this.editor.state.doc;
197
- if ((coords === null || coords === void 0 ? void 0 : coords.x) && (coords === null || coords === void 0 ? void 0 : coords.y)) {
198
- const pos = this.editor.posAtCoords({ left: coords.x, top: coords.y });
199
- if (pos) {
200
- this.editor.dispatch(this.editor.state.tr.setSelection(TextSelection.create(doc, pos.pos)));
201
- this.editor.focus();
202
- if (KritzelDevicesHelper.isIOS()) {
203
- this.scrollIntoViewOnIOS();
204
- }
205
- return;
206
- }
207
- }
208
- const end = Math.max(1, doc.content.size - 1);
209
- this.editor.dispatch(this.editor.state.tr.setSelection(TextSelection.create(doc, end)));
210
- this.editor.focus();
211
- if (KritzelDevicesHelper.isIOS()) {
212
- this.scrollIntoViewOnIOS();
213
- }
214
- }
215
- }
216
- scrollIntoViewOnIOS() {
217
- setTimeout(() => {
218
- if (this.editor && this.editor.dom) {
219
- this.editor.dom.scrollIntoView({
220
- behavior: 'smooth',
221
- block: 'center',
222
- inline: 'nearest',
223
- });
224
- }
225
- }, 300);
226
- }
227
- edit(event) {
228
- KritzelKeyboardHelper.disableInteractiveWidget();
229
- this.uneditedObject = this.clone();
230
- this._core.store.setState('activeTool', KritzelToolRegistry.getTool('shape'));
231
- this.editor.setProps({ editable: () => true });
232
- this.isEditing = true;
233
- this._core.rerender();
234
- this.focus({ x: event === null || event === void 0 ? void 0 : event.clientX, y: event === null || event === void 0 ? void 0 : event.clientY });
235
- KritzelKeyboardHelper.enableInteractiveWidget();
236
- }
237
- save() {
238
- this.content = this.editor.state.doc.toJSON();
239
- this.editor.setProps({ editable: () => false });
240
- this.editor.dom.blur();
241
- this.isEditing = false;
242
- this._core.store.state.objects.consolidateTemporaryItems();
243
- this._core.store.state.objects.update(this);
244
- this._core.engine.emitObjectsChange();
245
- }
246
- handlePointerDown(event) {
247
- if (!this.isEditing) {
248
- return;
249
- }
250
- if (!this._core.store.state.pointers.has(event.pointerId)) {
251
- event.stopPropagation();
252
- }
253
- }
254
- handlePointerMove(event) {
255
- if (!this.isEditing) {
256
- return;
257
- }
258
- if (!this._core.store.state.pointers.has(event.pointerId)) {
259
- event.stopPropagation();
260
- }
261
- }
262
- handlePointerUp(event) {
263
- if (!this.isEditing) {
264
- return;
265
- }
266
- if (!this._core.store.state.pointers.has(event.pointerId)) {
267
- event.stopPropagation();
268
- }
269
- }
270
- copy() {
271
- const copiedObject = super.copy();
272
- copiedObject.editor = copiedObject.createEditor();
273
- if (this.content) {
274
- copiedObject.setContent(this.content);
275
- }
276
- return copiedObject;
277
- }
278
- serialize() {
279
- const _a = this, { _core, _elementRef, _schema, element, totalWidth, totalHeight, editor, uneditedObject } = _a, remainingProps = __rest(_a, ["_core", "_elementRef", "_schema", "element", "totalWidth", "totalHeight", "editor", "uneditedObject"]);
280
- const clonedProps = structuredClone(remainingProps);
281
- if (element && typeof element === 'object' && 'nodeType' in element && element.nodeType === 1) {
282
- clonedProps.element = element.cloneNode(true);
283
- }
284
- return clonedProps;
285
- }
286
- deserialize(object) {
287
- super.deserialize(object);
288
- if (object.content) {
289
- this.setContent(object.content);
290
- }
291
- return this;
292
- }
293
- /**
294
- * Called after properties are updated via updateObject.
295
- * Automatically adjusts text color based on fill color brightness.
296
- */
297
- onAfterUpdate(changedProperties) {
298
- var _a, _b, _c, _d;
299
- if (changedProperties.includes('fillColor')) {
300
- this.fontColor = KritzelColorHelper.determineTextColor(this.fillColor);
301
- // Update the editor's text color immediately
302
- if ((_b = (_a = this.editor) === null || _a === void 0 ? void 0 : _a.dom) === null || _b === void 0 ? void 0 : _b.parentElement) {
303
- this.editor.dom.parentElement.style.color = KritzelColorHelper.resolveThemeColor(this.fontColor);
304
- }
305
- }
306
- else if (changedProperties.includes('fontColor')) {
307
- // Also update editor when fontColor changes directly
308
- if ((_d = (_c = this.editor) === null || _c === void 0 ? void 0 : _c.dom) === null || _d === void 0 ? void 0 : _d.parentElement) {
309
- this.editor.dom.parentElement.style.color = KritzelColorHelper.resolveThemeColor(this.fontColor);
310
- }
311
- }
312
- }
313
- /**
314
- * Returns the clipping polygon for arrow intersection.
315
- * For ellipse: returns a many-sided polygon approximation
316
- * For triangle: returns the 3 corners
317
- * For rectangle: returns null (uses default rotatedPolygon)
318
- *
319
- * Includes padding for half the stroke width so arrow heads don't overlap the stroke.
320
- */
321
- getClipPolygon() {
322
- // Calculate world-space center and dimensions
323
- const worldWidth = this.totalWidth / this.scale;
324
- const worldHeight = this.totalHeight / this.scale;
325
- const centerX = this.translateX + worldWidth / 2;
326
- const centerY = this.translateY + worldHeight / 2;
327
- // Add padding for stroke width so arrows don't overlap the stroke
328
- const strokePadding = (this.strokeWidth / this.scale) / 2;
329
- switch (this.shapeType) {
330
- case ShapeType.Ellipse:
331
- // Return a 32-segment polygon approximation of the ellipse
332
- // Add stroke padding to radii
333
- return KritzelGeometryHelper.getEllipsePolygonApproximation(centerX, centerY, worldWidth / 2 + strokePadding, worldHeight / 2 + strokePadding, 32, this.rotation);
334
- case ShapeType.Triangle:
335
- // Return the 3 corners of the triangle in world coordinates
336
- // Triangle: top-center, bottom-right, bottom-left
337
- // Expand each vertex outward from center by strokePadding
338
- const expandVertex = (vx, vy) => {
339
- const dx = vx - centerX;
340
- const dy = vy - centerY;
341
- const dist = Math.sqrt(dx * dx + dy * dy);
342
- if (dist === 0)
343
- return { x: vx, y: vy };
344
- const scale = (dist + strokePadding) / dist;
345
- return {
346
- x: centerX + dx * scale,
347
- y: centerY + dy * scale
348
- };
349
- };
350
- const topX = this.translateX + worldWidth / 2;
351
- const topY = this.translateY;
352
- const bottomLeftX = this.translateX;
353
- const bottomLeftY = this.translateY + worldHeight;
354
- const bottomRightX = this.translateX + worldWidth;
355
- const bottomRightY = this.translateY + worldHeight;
356
- const expandedTop = expandVertex(topX, topY);
357
- const expandedBottomRight = expandVertex(bottomRightX, bottomRightY);
358
- const expandedBottomLeft = expandVertex(bottomLeftX, bottomLeftY);
359
- // Apply rotation around center if rotated
360
- if (this.rotation !== 0) {
361
- const cos = Math.cos(this.rotation);
362
- const sin = Math.sin(this.rotation);
363
- const rotate = (p) => {
364
- const dx = p.x - centerX;
365
- const dy = p.y - centerY;
366
- return {
367
- x: centerX + dx * cos - dy * sin,
368
- y: centerY + dx * sin + dy * cos
369
- };
370
- };
371
- return [
372
- rotate(expandedTop),
373
- rotate(expandedBottomRight),
374
- rotate(expandedBottomLeft)
375
- ];
376
- }
377
- return [expandedTop, expandedBottomRight, expandedBottomLeft];
378
- case ShapeType.Rectangle:
379
- default:
380
- // For rectangles, return null to use the default rotatedPolygon
381
- return null;
382
- }
383
- }
384
- /**
385
- * Returns the SVG path for rendering the shape.
386
- * The path uses screen-space coordinates relative to (x, y).
387
- */
388
- getSvgPath() {
389
- const w = this.width;
390
- const h = this.height;
391
- switch (this.shapeType) {
392
- case ShapeType.Rectangle:
393
- return `M ${this.x} ${this.y} L ${this.x + w} ${this.y} L ${this.x + w} ${this.y + h} L ${this.x} ${this.y + h} Z`;
394
- case ShapeType.Ellipse:
395
- const cx = this.x + w / 2;
396
- const cy = this.y + h / 2;
397
- const rx = w / 2;
398
- const ry = h / 2;
399
- return `M ${cx - rx} ${cy} A ${rx} ${ry} 0 1 0 ${cx + rx} ${cy} A ${rx} ${ry} 0 1 0 ${cx - rx} ${cy}`;
400
- case ShapeType.Triangle:
401
- const topX = this.x + w / 2;
402
- const topY = this.y;
403
- const bottomLeftX = this.x;
404
- const bottomLeftY = this.y + h;
405
- const bottomRightX = this.x + w;
406
- const bottomRightY = this.y + h;
407
- return `M ${topX} ${topY} L ${bottomRightX} ${bottomRightY} L ${bottomLeftX} ${bottomLeftY} Z`;
408
- default:
409
- return `M ${this.x} ${this.y} L ${this.x + w} ${this.y} L ${this.x + w} ${this.y + h} L ${this.x} ${this.y + h} Z`;
410
- }
411
- }
412
- }