kritzel-react 0.1.30 → 0.1.32
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.
- package/dist/kritzel-react/lib/components/stencil-generated/components.js +122 -0
- package/dist/kritzel-react/lib/index.js +2 -0
- package/dist/kritzel-stencil/src/classes/core/core.class.js +797 -0
- package/dist/kritzel-stencil/src/classes/core/reviver.class.js +97 -0
- package/dist/kritzel-stencil/src/classes/core/store.class.js +153 -0
- package/dist/kritzel-stencil/src/classes/core/viewport.class.js +311 -0
- package/dist/kritzel-stencil/src/classes/core/workspace.class.js +34 -0
- package/dist/kritzel-stencil/src/classes/handlers/base.handler.js +6 -0
- package/dist/kritzel-stencil/src/classes/handlers/context-menu.handler.js +63 -0
- package/dist/kritzel-stencil/src/classes/handlers/hover.handler.js +18 -0
- package/dist/kritzel-stencil/src/classes/handlers/key.handler.js +76 -0
- package/dist/kritzel-stencil/src/classes/handlers/line-handle.handler.js +382 -0
- package/dist/kritzel-stencil/src/classes/handlers/move.handler.js +213 -0
- package/dist/kritzel-stencil/src/classes/handlers/resize.handler.js +205 -0
- package/dist/kritzel-stencil/src/classes/handlers/rotation.handler.js +117 -0
- package/dist/kritzel-stencil/src/classes/handlers/selection.handler.js +313 -0
- package/dist/kritzel-stencil/src/classes/managers/anchor.manager.js +1056 -0
- package/dist/kritzel-stencil/src/classes/managers/cursor.manager.js +117 -0
- package/dist/kritzel-stencil/src/classes/managers/theme.manager.js +103 -0
- package/dist/kritzel-stencil/src/classes/objects/base-object.class.js +249 -0
- package/dist/kritzel-stencil/src/classes/objects/custom-element.class.js +60 -0
- package/dist/kritzel-stencil/src/classes/objects/group.class.js +407 -0
- package/dist/kritzel-stencil/src/classes/objects/image.class.js +55 -0
- package/dist/kritzel-stencil/src/classes/objects/line.class.js +608 -0
- package/dist/kritzel-stencil/src/classes/objects/path.class.js +401 -0
- package/dist/kritzel-stencil/src/classes/objects/selection-box.class.js +21 -0
- package/dist/kritzel-stencil/src/classes/objects/selection-group.class.js +409 -0
- package/dist/kritzel-stencil/src/classes/objects/shape.class.js +412 -0
- package/dist/kritzel-stencil/src/classes/objects/text.class.js +292 -0
- package/dist/kritzel-stencil/src/classes/providers/broadcast-sync-provider.class.js +101 -0
- package/dist/kritzel-stencil/src/classes/providers/hocuspocus-sync-provider.class.js +241 -0
- package/dist/kritzel-stencil/src/classes/providers/indexeddb-sync-provider.class.js +43 -0
- package/dist/kritzel-stencil/src/classes/providers/websocket-sync-provider.class.js +98 -0
- package/dist/kritzel-stencil/src/classes/registries/icon-registry.class.js +66 -0
- package/dist/kritzel-stencil/src/classes/registries/tool.registry.js +21 -0
- package/dist/kritzel-stencil/src/classes/structures/app-state-map.structure.js +212 -0
- package/dist/kritzel-stencil/src/classes/structures/object-map.structure.js +414 -0
- package/dist/kritzel-stencil/src/classes/structures/quadtree.structure.js +151 -0
- package/dist/kritzel-stencil/src/classes/tools/base-tool.class.js +36 -0
- package/dist/kritzel-stencil/src/classes/tools/brush-tool.class.js +161 -0
- package/dist/kritzel-stencil/src/classes/tools/eraser-tool.class.js +85 -0
- package/dist/kritzel-stencil/src/classes/tools/image-tool.class.js +83 -0
- package/dist/kritzel-stencil/src/classes/tools/line-tool.class.js +187 -0
- package/dist/kritzel-stencil/src/classes/tools/selection-tool.class.js +429 -0
- package/dist/kritzel-stencil/src/classes/tools/shape-tool.class.js +196 -0
- package/dist/kritzel-stencil/src/classes/tools/text-tool.class.js +100 -0
- package/dist/kritzel-stencil/src/components/core/kritzel-engine/kritzel-engine.js +1343 -0
- package/dist/kritzel-stencil/src/components/shared/kritzel-brush-style/kritzel-brush-style.js +46 -0
- package/dist/kritzel-stencil/src/components/shared/kritzel-dropdown/kritzel-dropdown.js +312 -0
- package/dist/kritzel-stencil/src/components/shared/kritzel-font-family/kritzel-font-family.js +60 -0
- package/dist/kritzel-stencil/src/components/shared/kritzel-line-endings/kritzel-line-endings.js +105 -0
- package/dist/kritzel-stencil/src/components/shared/kritzel-shape-fill/kritzel-shape-fill.js +53 -0
- package/dist/kritzel-stencil/src/components/ui/kritzel-context-menu/kritzel-context-menu.js +137 -0
- package/dist/kritzel-stencil/src/configs/default-brush-tool.config.js +9 -0
- package/dist/kritzel-stencil/src/configs/default-engine-config.js +63 -0
- package/dist/kritzel-stencil/src/configs/default-line-tool.config.js +9 -0
- package/dist/kritzel-stencil/src/configs/default-sync.config.js +9 -0
- package/dist/kritzel-stencil/src/configs/default-text-tool.config.js +7 -0
- package/dist/kritzel-stencil/src/constants/color-palette.constants.js +37 -0
- package/dist/kritzel-stencil/src/constants/engine.constants.js +2 -0
- package/dist/kritzel-stencil/src/enums/event-button.enum.js +6 -0
- package/dist/kritzel-stencil/src/enums/handle-type.enum.js +7 -0
- package/dist/kritzel-stencil/src/enums/shape-type.enum.js +6 -0
- package/dist/kritzel-stencil/src/helpers/class.helper.js +5 -0
- package/dist/kritzel-stencil/src/helpers/color.helper.js +106 -0
- package/dist/kritzel-stencil/src/helpers/cursor.helper.js +57 -0
- package/dist/kritzel-stencil/src/helpers/devices.helper.js +28 -0
- package/dist/kritzel-stencil/src/helpers/event.helper.js +58 -0
- package/dist/kritzel-stencil/src/helpers/geometry.helper.js +149 -0
- package/dist/kritzel-stencil/src/helpers/keyboard.helper.js +51 -0
- package/dist/kritzel-stencil/src/helpers/math.helper.js +5 -0
- package/dist/kritzel-stencil/src/helpers/object.helper.js +11 -0
- package/dist/kritzel-stencil/src/helpers/theme.helper.js +69 -0
- package/dist/kritzel-stencil/src/index.js +41 -0
- package/dist/kritzel-stencil/src/interfaces/anchor.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/arrow-head.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/bounding-box.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/clonable.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/context-menu-item.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/debug-info.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/dialog.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/displayable-shortcut.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/engine-state.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/line-options.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/master-detail.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/menu-item.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/object.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/path-options.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/point.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/polygon.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/serializable.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/settings.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/shortcut.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/sync-config.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/sync-provider.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/theme.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/tool-config.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/tool.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/toolbar-control.interface.js +1 -0
- package/dist/kritzel-stencil/src/interfaces/undo-state.interface.js +1 -0
- package/dist/kritzel-stencil/src/themes/dark-theme.js +198 -0
- package/dist/kritzel-stencil/src/themes/light-theme.js +199 -0
- package/dist/kritzel-stencil/src/types/shortcut.type.js +1 -0
- package/dist/kritzel-stencil/src/types/state.types.js +1 -0
- package/dist/types/kritzel-react/lib/components/stencil-generated/components.d.ts +74 -0
- package/dist/types/kritzel-react/lib/index.d.ts +2 -0
- package/dist/types/kritzel-stencil/src/classes/core/core.class.d.ts +101 -0
- package/dist/types/kritzel-stencil/src/classes/core/reviver.class.d.ts +6 -0
- package/dist/types/kritzel-stencil/src/classes/core/store.class.d.ts +53 -0
- package/dist/types/kritzel-stencil/src/classes/core/viewport.class.d.ts +48 -0
- package/dist/types/kritzel-stencil/src/classes/core/workspace.class.d.ts +24 -0
- package/dist/types/kritzel-stencil/src/classes/handlers/base.handler.d.ts +5 -0
- package/dist/types/kritzel-stencil/src/classes/handlers/context-menu.handler.d.ts +8 -0
- package/dist/types/kritzel-stencil/src/classes/handlers/hover.handler.d.ts +6 -0
- package/dist/types/kritzel-stencil/src/classes/handlers/key.handler.d.ts +11 -0
- package/dist/types/kritzel-stencil/src/classes/handlers/line-handle.handler.d.ts +34 -0
- package/dist/types/kritzel-stencil/src/classes/handlers/move.handler.d.ts +29 -0
- package/dist/types/kritzel-stencil/src/classes/handlers/resize.handler.d.ts +24 -0
- package/dist/types/kritzel-stencil/src/classes/handlers/rotation.handler.d.ts +12 -0
- package/dist/types/kritzel-stencil/src/classes/handlers/selection.handler.d.ts +27 -0
- package/dist/types/kritzel-stencil/src/classes/managers/anchor.manager.d.ts +180 -0
- package/dist/types/kritzel-stencil/src/classes/managers/cursor.manager.d.ts +43 -0
- package/dist/types/kritzel-stencil/src/classes/managers/theme.manager.d.ts +56 -0
- package/dist/types/kritzel-stencil/src/classes/objects/base-object.class.d.ts +76 -0
- package/dist/types/kritzel-stencil/src/classes/objects/custom-element.class.d.ts +26 -0
- package/dist/types/kritzel-stencil/src/classes/objects/group.class.d.ts +97 -0
- package/dist/types/kritzel-stencil/src/classes/objects/image.class.d.ts +17 -0
- package/dist/types/kritzel-stencil/src/classes/objects/line.class.d.ts +101 -0
- package/dist/types/kritzel-stencil/src/classes/objects/path.class.d.ts +62 -0
- package/dist/types/kritzel-stencil/src/classes/objects/selection-box.class.d.ts +6 -0
- package/dist/types/kritzel-stencil/src/classes/objects/selection-group.class.d.ts +67 -0
- package/dist/types/kritzel-stencil/src/classes/objects/shape.class.d.ts +124 -0
- package/dist/types/kritzel-stencil/src/classes/objects/text.class.d.ts +56 -0
- package/dist/types/kritzel-stencil/src/classes/providers/broadcast-sync-provider.class.d.ts +18 -0
- package/dist/types/kritzel-stencil/src/classes/providers/hocuspocus-sync-provider.class.d.ts +120 -0
- package/dist/types/kritzel-stencil/src/classes/providers/indexeddb-sync-provider.class.d.ts +22 -0
- package/dist/types/kritzel-stencil/src/classes/providers/websocket-sync-provider.class.d.ts +52 -0
- package/dist/types/kritzel-stencil/src/classes/registries/icon-registry.class.d.ts +9 -0
- package/dist/types/kritzel-stencil/src/classes/registries/tool.registry.d.ts +8 -0
- package/dist/types/kritzel-stencil/src/classes/structures/app-state-map.structure.d.ts +31 -0
- package/dist/types/kritzel-stencil/src/classes/structures/object-map.structure.d.ts +63 -0
- package/dist/types/kritzel-stencil/src/classes/structures/quadtree.structure.d.ts +36 -0
- package/dist/types/kritzel-stencil/src/classes/tools/base-tool.class.d.ts +20 -0
- package/dist/types/kritzel-stencil/src/classes/tools/brush-tool.class.d.ts +14 -0
- package/dist/types/kritzel-stencil/src/classes/tools/eraser-tool.class.d.ts +9 -0
- package/dist/types/kritzel-stencil/src/classes/tools/image-tool.class.d.ts +15 -0
- package/dist/types/kritzel-stencil/src/classes/tools/line-tool.class.d.ts +19 -0
- package/dist/types/kritzel-stencil/src/classes/tools/selection-tool.class.d.ts +54 -0
- package/dist/types/kritzel-stencil/src/classes/tools/shape-tool.class.d.ts +39 -0
- package/dist/types/kritzel-stencil/src/classes/tools/text-tool.class.d.ts +13 -0
- package/dist/types/kritzel-stencil/src/components/core/kritzel-engine/kritzel-engine.d.ts +111 -0
- package/dist/types/kritzel-stencil/src/components/shared/kritzel-brush-style/kritzel-brush-style.d.ts +11 -0
- package/dist/types/kritzel-stencil/src/components/shared/kritzel-dropdown/kritzel-dropdown.d.ts +46 -0
- package/dist/types/kritzel-stencil/src/components/shared/kritzel-font-family/kritzel-font-family.d.ts +13 -0
- package/dist/types/kritzel-stencil/src/components/shared/kritzel-line-endings/kritzel-line-endings.d.ts +21 -0
- package/dist/types/kritzel-stencil/src/components/shared/kritzel-shape-fill/kritzel-shape-fill.d.ts +10 -0
- package/dist/types/kritzel-stencil/src/components/ui/kritzel-context-menu/kritzel-context-menu.d.ts +21 -0
- package/dist/types/kritzel-stencil/src/configs/default-brush-tool.config.d.ts +2 -0
- package/dist/types/kritzel-stencil/src/configs/default-engine-config.d.ts +2 -0
- package/dist/types/kritzel-stencil/src/configs/default-line-tool.config.d.ts +2 -0
- package/dist/types/kritzel-stencil/src/configs/default-sync.config.d.ts +5 -0
- package/dist/types/kritzel-stencil/src/configs/default-text-tool.config.d.ts +2 -0
- package/dist/types/kritzel-stencil/src/constants/color-palette.constants.d.ts +29 -0
- package/dist/types/kritzel-stencil/src/constants/engine.constants.d.ts +2 -0
- package/dist/types/kritzel-stencil/src/enums/event-button.enum.d.ts +5 -0
- package/dist/types/kritzel-stencil/src/enums/handle-type.enum.d.ts +6 -0
- package/dist/types/kritzel-stencil/src/enums/shape-type.enum.d.ts +5 -0
- package/dist/types/kritzel-stencil/src/helpers/class.helper.d.ts +3 -0
- package/dist/types/kritzel-stencil/src/helpers/color.helper.d.ts +33 -0
- package/dist/types/kritzel-stencil/src/helpers/cursor.helper.d.ts +22 -0
- package/dist/types/kritzel-stencil/src/helpers/devices.helper.d.ts +8 -0
- package/dist/types/kritzel-stencil/src/helpers/event.helper.d.ts +6 -0
- package/dist/types/kritzel-stencil/src/helpers/geometry.helper.d.ts +38 -0
- package/dist/types/kritzel-stencil/src/helpers/keyboard.helper.d.ts +6 -0
- package/dist/types/kritzel-stencil/src/helpers/math.helper.d.ts +3 -0
- package/dist/types/kritzel-stencil/src/helpers/object.helper.d.ts +4 -0
- package/dist/types/kritzel-stencil/src/helpers/theme.helper.d.ts +41 -0
- package/dist/types/kritzel-stencil/src/index.d.ts +42 -0
- package/dist/types/kritzel-stencil/src/interfaces/anchor.interface.d.ts +137 -0
- package/dist/types/kritzel-stencil/src/interfaces/arrow-head.interface.d.ts +27 -0
- package/dist/types/kritzel-stencil/src/interfaces/bounding-box.interface.d.ts +8 -0
- package/dist/types/kritzel-stencil/src/interfaces/clonable.interface.d.ts +3 -0
- package/dist/types/kritzel-stencil/src/interfaces/context-menu-item.interface.d.ts +17 -0
- package/dist/types/kritzel-stencil/src/interfaces/debug-info.interface.d.ts +4 -0
- package/dist/types/kritzel-stencil/src/interfaces/dialog.interface.d.ts +4 -0
- package/dist/types/kritzel-stencil/src/interfaces/displayable-shortcut.interface.d.ts +5 -0
- package/dist/types/kritzel-stencil/src/interfaces/engine-state.interface.d.ts +73 -0
- package/dist/types/kritzel-stencil/src/interfaces/line-options.interface.d.ts +23 -0
- package/dist/types/kritzel-stencil/src/interfaces/master-detail.interface.d.ts +14 -0
- package/dist/types/kritzel-stencil/src/interfaces/menu-item.interface.d.ts +24 -0
- package/dist/types/kritzel-stencil/src/interfaces/object.interface.d.ts +53 -0
- package/dist/types/kritzel-stencil/src/interfaces/path-options.interface.d.ts +11 -0
- package/dist/types/kritzel-stencil/src/interfaces/point.interface.d.ts +4 -0
- package/dist/types/kritzel-stencil/src/interfaces/polygon.interface.d.ts +7 -0
- package/dist/types/kritzel-stencil/src/interfaces/serializable.interface.d.ts +5 -0
- package/dist/types/kritzel-stencil/src/interfaces/settings.interface.d.ts +11 -0
- package/dist/types/kritzel-stencil/src/interfaces/shortcut.interface.d.ts +10 -0
- package/dist/types/kritzel-stencil/src/interfaces/sync-config.interface.d.ts +22 -0
- package/dist/types/kritzel-stencil/src/interfaces/sync-provider.interface.d.ts +29 -0
- package/dist/types/kritzel-stencil/src/interfaces/theme.interface.d.ts +330 -0
- package/dist/types/kritzel-stencil/src/interfaces/tool-config.interface.d.ts +26 -0
- package/dist/types/kritzel-stencil/src/interfaces/tool.interface.d.ts +7 -0
- package/dist/types/kritzel-stencil/src/interfaces/toolbar-control.interface.d.ts +58 -0
- package/dist/types/kritzel-stencil/src/interfaces/undo-state.interface.d.ts +6 -0
- package/dist/types/kritzel-stencil/src/themes/dark-theme.d.ts +5 -0
- package/dist/types/kritzel-stencil/src/themes/light-theme.d.ts +5 -0
- package/dist/types/kritzel-stencil/src/types/shortcut.type.d.ts +1 -0
- package/dist/types/kritzel-stencil/src/types/state.types.d.ts +3 -0
- package/package.json +2 -2
|
@@ -0,0 +1,412 @@
|
|
|
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
|
+
}
|