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.
- package/dist/types/components/stencil-generated/components.d.ts +1 -1
- package/package.json +2 -2
- package/dist/kritzel-react/lib/components/stencil-generated/components.js +0 -122
- package/dist/kritzel-react/lib/index.js +0 -2
- package/dist/kritzel-stencil/src/classes/core/core.class.js +0 -797
- package/dist/kritzel-stencil/src/classes/core/reviver.class.js +0 -97
- package/dist/kritzel-stencil/src/classes/core/store.class.js +0 -153
- package/dist/kritzel-stencil/src/classes/core/viewport.class.js +0 -311
- package/dist/kritzel-stencil/src/classes/core/workspace.class.js +0 -34
- package/dist/kritzel-stencil/src/classes/handlers/base.handler.js +0 -6
- package/dist/kritzel-stencil/src/classes/handlers/context-menu.handler.js +0 -63
- package/dist/kritzel-stencil/src/classes/handlers/hover.handler.js +0 -18
- package/dist/kritzel-stencil/src/classes/handlers/key.handler.js +0 -76
- package/dist/kritzel-stencil/src/classes/handlers/line-handle.handler.js +0 -382
- package/dist/kritzel-stencil/src/classes/handlers/move.handler.js +0 -213
- package/dist/kritzel-stencil/src/classes/handlers/resize.handler.js +0 -205
- package/dist/kritzel-stencil/src/classes/handlers/rotation.handler.js +0 -117
- package/dist/kritzel-stencil/src/classes/handlers/selection.handler.js +0 -313
- package/dist/kritzel-stencil/src/classes/managers/anchor.manager.js +0 -1056
- package/dist/kritzel-stencil/src/classes/managers/cursor.manager.js +0 -117
- package/dist/kritzel-stencil/src/classes/managers/theme.manager.js +0 -103
- package/dist/kritzel-stencil/src/classes/objects/base-object.class.js +0 -249
- package/dist/kritzel-stencil/src/classes/objects/custom-element.class.js +0 -60
- package/dist/kritzel-stencil/src/classes/objects/group.class.js +0 -407
- package/dist/kritzel-stencil/src/classes/objects/image.class.js +0 -55
- package/dist/kritzel-stencil/src/classes/objects/line.class.js +0 -608
- package/dist/kritzel-stencil/src/classes/objects/path.class.js +0 -401
- package/dist/kritzel-stencil/src/classes/objects/selection-box.class.js +0 -21
- package/dist/kritzel-stencil/src/classes/objects/selection-group.class.js +0 -409
- package/dist/kritzel-stencil/src/classes/objects/shape.class.js +0 -412
- package/dist/kritzel-stencil/src/classes/objects/text.class.js +0 -292
- package/dist/kritzel-stencil/src/classes/providers/broadcast-sync-provider.class.js +0 -101
- package/dist/kritzel-stencil/src/classes/providers/hocuspocus-sync-provider.class.js +0 -241
- package/dist/kritzel-stencil/src/classes/providers/indexeddb-sync-provider.class.js +0 -43
- package/dist/kritzel-stencil/src/classes/providers/websocket-sync-provider.class.js +0 -98
- package/dist/kritzel-stencil/src/classes/registries/icon-registry.class.js +0 -66
- package/dist/kritzel-stencil/src/classes/registries/tool.registry.js +0 -21
- package/dist/kritzel-stencil/src/classes/structures/app-state-map.structure.js +0 -212
- package/dist/kritzel-stencil/src/classes/structures/object-map.structure.js +0 -414
- package/dist/kritzel-stencil/src/classes/structures/quadtree.structure.js +0 -151
- package/dist/kritzel-stencil/src/classes/tools/base-tool.class.js +0 -36
- package/dist/kritzel-stencil/src/classes/tools/brush-tool.class.js +0 -161
- package/dist/kritzel-stencil/src/classes/tools/eraser-tool.class.js +0 -85
- package/dist/kritzel-stencil/src/classes/tools/image-tool.class.js +0 -83
- package/dist/kritzel-stencil/src/classes/tools/line-tool.class.js +0 -187
- package/dist/kritzel-stencil/src/classes/tools/selection-tool.class.js +0 -429
- package/dist/kritzel-stencil/src/classes/tools/shape-tool.class.js +0 -196
- package/dist/kritzel-stencil/src/classes/tools/text-tool.class.js +0 -100
- package/dist/kritzel-stencil/src/components/core/kritzel-engine/kritzel-engine.js +0 -1343
- package/dist/kritzel-stencil/src/components/shared/kritzel-brush-style/kritzel-brush-style.js +0 -46
- package/dist/kritzel-stencil/src/components/shared/kritzel-dropdown/kritzel-dropdown.js +0 -312
- package/dist/kritzel-stencil/src/components/shared/kritzel-font-family/kritzel-font-family.js +0 -60
- package/dist/kritzel-stencil/src/components/shared/kritzel-line-endings/kritzel-line-endings.js +0 -105
- package/dist/kritzel-stencil/src/components/shared/kritzel-shape-fill/kritzel-shape-fill.js +0 -53
- package/dist/kritzel-stencil/src/components/ui/kritzel-context-menu/kritzel-context-menu.js +0 -137
- package/dist/kritzel-stencil/src/configs/default-brush-tool.config.js +0 -9
- package/dist/kritzel-stencil/src/configs/default-engine-config.js +0 -63
- package/dist/kritzel-stencil/src/configs/default-line-tool.config.js +0 -9
- package/dist/kritzel-stencil/src/configs/default-sync.config.js +0 -9
- package/dist/kritzel-stencil/src/configs/default-text-tool.config.js +0 -7
- package/dist/kritzel-stencil/src/constants/color-palette.constants.js +0 -37
- package/dist/kritzel-stencil/src/constants/engine.constants.js +0 -2
- package/dist/kritzel-stencil/src/enums/event-button.enum.js +0 -6
- package/dist/kritzel-stencil/src/enums/handle-type.enum.js +0 -7
- package/dist/kritzel-stencil/src/enums/shape-type.enum.js +0 -6
- package/dist/kritzel-stencil/src/helpers/class.helper.js +0 -5
- package/dist/kritzel-stencil/src/helpers/color.helper.js +0 -106
- package/dist/kritzel-stencil/src/helpers/cursor.helper.js +0 -57
- package/dist/kritzel-stencil/src/helpers/devices.helper.js +0 -28
- package/dist/kritzel-stencil/src/helpers/event.helper.js +0 -58
- package/dist/kritzel-stencil/src/helpers/geometry.helper.js +0 -149
- package/dist/kritzel-stencil/src/helpers/keyboard.helper.js +0 -51
- package/dist/kritzel-stencil/src/helpers/math.helper.js +0 -5
- package/dist/kritzel-stencil/src/helpers/object.helper.js +0 -11
- package/dist/kritzel-stencil/src/helpers/theme.helper.js +0 -69
- package/dist/kritzel-stencil/src/index.js +0 -41
- package/dist/kritzel-stencil/src/interfaces/anchor.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/arrow-head.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/bounding-box.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/clonable.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/context-menu-item.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/debug-info.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/dialog.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/displayable-shortcut.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/engine-state.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/line-options.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/master-detail.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/menu-item.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/object.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/path-options.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/point.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/polygon.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/serializable.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/settings.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/shortcut.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/sync-config.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/sync-provider.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/theme.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/tool-config.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/tool.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/toolbar-control.interface.js +0 -1
- package/dist/kritzel-stencil/src/interfaces/undo-state.interface.js +0 -1
- package/dist/kritzel-stencil/src/themes/dark-theme.js +0 -198
- package/dist/kritzel-stencil/src/themes/light-theme.js +0 -199
- package/dist/kritzel-stencil/src/types/shortcut.type.js +0 -1
- package/dist/kritzel-stencil/src/types/state.types.js +0 -1
- package/dist/types/kritzel-react/lib/components/stencil-generated/components.d.ts +0 -74
- package/dist/types/kritzel-react/lib/index.d.ts +0 -2
- package/dist/types/kritzel-stencil/src/classes/core/core.class.d.ts +0 -101
- package/dist/types/kritzel-stencil/src/classes/core/reviver.class.d.ts +0 -6
- package/dist/types/kritzel-stencil/src/classes/core/store.class.d.ts +0 -53
- package/dist/types/kritzel-stencil/src/classes/core/viewport.class.d.ts +0 -48
- package/dist/types/kritzel-stencil/src/classes/core/workspace.class.d.ts +0 -24
- package/dist/types/kritzel-stencil/src/classes/handlers/base.handler.d.ts +0 -5
- package/dist/types/kritzel-stencil/src/classes/handlers/context-menu.handler.d.ts +0 -8
- package/dist/types/kritzel-stencil/src/classes/handlers/hover.handler.d.ts +0 -6
- package/dist/types/kritzel-stencil/src/classes/handlers/key.handler.d.ts +0 -11
- package/dist/types/kritzel-stencil/src/classes/handlers/line-handle.handler.d.ts +0 -34
- package/dist/types/kritzel-stencil/src/classes/handlers/move.handler.d.ts +0 -29
- package/dist/types/kritzel-stencil/src/classes/handlers/resize.handler.d.ts +0 -24
- package/dist/types/kritzel-stencil/src/classes/handlers/rotation.handler.d.ts +0 -12
- package/dist/types/kritzel-stencil/src/classes/handlers/selection.handler.d.ts +0 -27
- package/dist/types/kritzel-stencil/src/classes/managers/anchor.manager.d.ts +0 -180
- package/dist/types/kritzel-stencil/src/classes/managers/cursor.manager.d.ts +0 -43
- package/dist/types/kritzel-stencil/src/classes/managers/theme.manager.d.ts +0 -56
- package/dist/types/kritzel-stencil/src/classes/objects/base-object.class.d.ts +0 -76
- package/dist/types/kritzel-stencil/src/classes/objects/custom-element.class.d.ts +0 -26
- package/dist/types/kritzel-stencil/src/classes/objects/group.class.d.ts +0 -97
- package/dist/types/kritzel-stencil/src/classes/objects/image.class.d.ts +0 -17
- package/dist/types/kritzel-stencil/src/classes/objects/line.class.d.ts +0 -101
- package/dist/types/kritzel-stencil/src/classes/objects/path.class.d.ts +0 -62
- package/dist/types/kritzel-stencil/src/classes/objects/selection-box.class.d.ts +0 -6
- package/dist/types/kritzel-stencil/src/classes/objects/selection-group.class.d.ts +0 -67
- package/dist/types/kritzel-stencil/src/classes/objects/shape.class.d.ts +0 -124
- package/dist/types/kritzel-stencil/src/classes/objects/text.class.d.ts +0 -56
- package/dist/types/kritzel-stencil/src/classes/providers/broadcast-sync-provider.class.d.ts +0 -18
- package/dist/types/kritzel-stencil/src/classes/providers/hocuspocus-sync-provider.class.d.ts +0 -120
- package/dist/types/kritzel-stencil/src/classes/providers/indexeddb-sync-provider.class.d.ts +0 -22
- package/dist/types/kritzel-stencil/src/classes/providers/websocket-sync-provider.class.d.ts +0 -52
- package/dist/types/kritzel-stencil/src/classes/registries/icon-registry.class.d.ts +0 -9
- package/dist/types/kritzel-stencil/src/classes/registries/tool.registry.d.ts +0 -8
- package/dist/types/kritzel-stencil/src/classes/structures/app-state-map.structure.d.ts +0 -31
- package/dist/types/kritzel-stencil/src/classes/structures/object-map.structure.d.ts +0 -63
- package/dist/types/kritzel-stencil/src/classes/structures/quadtree.structure.d.ts +0 -36
- package/dist/types/kritzel-stencil/src/classes/tools/base-tool.class.d.ts +0 -20
- package/dist/types/kritzel-stencil/src/classes/tools/brush-tool.class.d.ts +0 -14
- package/dist/types/kritzel-stencil/src/classes/tools/eraser-tool.class.d.ts +0 -9
- package/dist/types/kritzel-stencil/src/classes/tools/image-tool.class.d.ts +0 -15
- package/dist/types/kritzel-stencil/src/classes/tools/line-tool.class.d.ts +0 -19
- package/dist/types/kritzel-stencil/src/classes/tools/selection-tool.class.d.ts +0 -54
- package/dist/types/kritzel-stencil/src/classes/tools/shape-tool.class.d.ts +0 -39
- package/dist/types/kritzel-stencil/src/classes/tools/text-tool.class.d.ts +0 -13
- package/dist/types/kritzel-stencil/src/components/core/kritzel-engine/kritzel-engine.d.ts +0 -111
- package/dist/types/kritzel-stencil/src/components/shared/kritzel-brush-style/kritzel-brush-style.d.ts +0 -11
- package/dist/types/kritzel-stencil/src/components/shared/kritzel-dropdown/kritzel-dropdown.d.ts +0 -46
- package/dist/types/kritzel-stencil/src/components/shared/kritzel-font-family/kritzel-font-family.d.ts +0 -13
- package/dist/types/kritzel-stencil/src/components/shared/kritzel-line-endings/kritzel-line-endings.d.ts +0 -21
- package/dist/types/kritzel-stencil/src/components/shared/kritzel-shape-fill/kritzel-shape-fill.d.ts +0 -10
- package/dist/types/kritzel-stencil/src/components/ui/kritzel-context-menu/kritzel-context-menu.d.ts +0 -21
- package/dist/types/kritzel-stencil/src/configs/default-brush-tool.config.d.ts +0 -2
- package/dist/types/kritzel-stencil/src/configs/default-engine-config.d.ts +0 -2
- package/dist/types/kritzel-stencil/src/configs/default-line-tool.config.d.ts +0 -2
- package/dist/types/kritzel-stencil/src/configs/default-sync.config.d.ts +0 -5
- package/dist/types/kritzel-stencil/src/configs/default-text-tool.config.d.ts +0 -2
- package/dist/types/kritzel-stencil/src/constants/color-palette.constants.d.ts +0 -29
- package/dist/types/kritzel-stencil/src/constants/engine.constants.d.ts +0 -2
- package/dist/types/kritzel-stencil/src/enums/event-button.enum.d.ts +0 -5
- package/dist/types/kritzel-stencil/src/enums/handle-type.enum.d.ts +0 -6
- package/dist/types/kritzel-stencil/src/enums/shape-type.enum.d.ts +0 -5
- package/dist/types/kritzel-stencil/src/helpers/class.helper.d.ts +0 -3
- package/dist/types/kritzel-stencil/src/helpers/color.helper.d.ts +0 -33
- package/dist/types/kritzel-stencil/src/helpers/cursor.helper.d.ts +0 -22
- package/dist/types/kritzel-stencil/src/helpers/devices.helper.d.ts +0 -8
- package/dist/types/kritzel-stencil/src/helpers/event.helper.d.ts +0 -6
- package/dist/types/kritzel-stencil/src/helpers/geometry.helper.d.ts +0 -38
- package/dist/types/kritzel-stencil/src/helpers/keyboard.helper.d.ts +0 -6
- package/dist/types/kritzel-stencil/src/helpers/math.helper.d.ts +0 -3
- package/dist/types/kritzel-stencil/src/helpers/object.helper.d.ts +0 -4
- package/dist/types/kritzel-stencil/src/helpers/theme.helper.d.ts +0 -41
- package/dist/types/kritzel-stencil/src/index.d.ts +0 -42
- package/dist/types/kritzel-stencil/src/interfaces/anchor.interface.d.ts +0 -137
- package/dist/types/kritzel-stencil/src/interfaces/arrow-head.interface.d.ts +0 -27
- package/dist/types/kritzel-stencil/src/interfaces/bounding-box.interface.d.ts +0 -8
- package/dist/types/kritzel-stencil/src/interfaces/clonable.interface.d.ts +0 -3
- package/dist/types/kritzel-stencil/src/interfaces/context-menu-item.interface.d.ts +0 -17
- package/dist/types/kritzel-stencil/src/interfaces/debug-info.interface.d.ts +0 -4
- package/dist/types/kritzel-stencil/src/interfaces/dialog.interface.d.ts +0 -4
- package/dist/types/kritzel-stencil/src/interfaces/displayable-shortcut.interface.d.ts +0 -5
- package/dist/types/kritzel-stencil/src/interfaces/engine-state.interface.d.ts +0 -73
- package/dist/types/kritzel-stencil/src/interfaces/line-options.interface.d.ts +0 -23
- package/dist/types/kritzel-stencil/src/interfaces/master-detail.interface.d.ts +0 -14
- package/dist/types/kritzel-stencil/src/interfaces/menu-item.interface.d.ts +0 -24
- package/dist/types/kritzel-stencil/src/interfaces/object.interface.d.ts +0 -53
- package/dist/types/kritzel-stencil/src/interfaces/path-options.interface.d.ts +0 -11
- package/dist/types/kritzel-stencil/src/interfaces/point.interface.d.ts +0 -4
- package/dist/types/kritzel-stencil/src/interfaces/polygon.interface.d.ts +0 -7
- package/dist/types/kritzel-stencil/src/interfaces/serializable.interface.d.ts +0 -5
- package/dist/types/kritzel-stencil/src/interfaces/settings.interface.d.ts +0 -11
- package/dist/types/kritzel-stencil/src/interfaces/shortcut.interface.d.ts +0 -10
- package/dist/types/kritzel-stencil/src/interfaces/sync-config.interface.d.ts +0 -22
- package/dist/types/kritzel-stencil/src/interfaces/sync-provider.interface.d.ts +0 -29
- package/dist/types/kritzel-stencil/src/interfaces/theme.interface.d.ts +0 -330
- package/dist/types/kritzel-stencil/src/interfaces/tool-config.interface.d.ts +0 -26
- package/dist/types/kritzel-stencil/src/interfaces/tool.interface.d.ts +0 -7
- package/dist/types/kritzel-stencil/src/interfaces/toolbar-control.interface.d.ts +0 -58
- package/dist/types/kritzel-stencil/src/interfaces/undo-state.interface.d.ts +0 -6
- package/dist/types/kritzel-stencil/src/themes/dark-theme.d.ts +0 -5
- package/dist/types/kritzel-stencil/src/themes/light-theme.d.ts +0 -5
- package/dist/types/kritzel-stencil/src/types/shortcut.type.d.ts +0 -1
- package/dist/types/kritzel-stencil/src/types/state.types.d.ts +0 -3
|
@@ -1,401 +0,0 @@
|
|
|
1
|
-
import { getStroke } from 'perfect-freehand';
|
|
2
|
-
import { KritzelMathHelper } from '../../helpers/math.helper';
|
|
3
|
-
import { KritzelBaseObject } from './base-object.class';
|
|
4
|
-
import { KritzelGeometryHelper } from '../../helpers/geometry.helper';
|
|
5
|
-
export class KritzelPath extends KritzelBaseObject {
|
|
6
|
-
get viewBox() {
|
|
7
|
-
return `${this.x} ${this.y} ${this.width} ${this.height}`;
|
|
8
|
-
}
|
|
9
|
-
constructor(config) {
|
|
10
|
-
var _a, _b, _c, _d, _e, _f;
|
|
11
|
-
super();
|
|
12
|
-
this.__class__ = 'KritzelPath';
|
|
13
|
-
this.stroke = { light: 'none', dark: 'none' };
|
|
14
|
-
this.lineSlack = 0.5;
|
|
15
|
-
this.x = 0;
|
|
16
|
-
this.y = 0;
|
|
17
|
-
this.height = 0;
|
|
18
|
-
this.width = 0;
|
|
19
|
-
this.scale = 1;
|
|
20
|
-
this.isVisible = true;
|
|
21
|
-
this.isDebugInfoVisible = true;
|
|
22
|
-
this.isCompleted = false;
|
|
23
|
-
this._adjustedPoints = null;
|
|
24
|
-
this.options = config;
|
|
25
|
-
this.points = (_a = config === null || config === void 0 ? void 0 : config.points) !== null && _a !== void 0 ? _a : [];
|
|
26
|
-
this.translateX = (_b = config === null || config === void 0 ? void 0 : config.translateX) !== null && _b !== void 0 ? _b : 0;
|
|
27
|
-
this.translateY = (_c = config === null || config === void 0 ? void 0 : config.translateY) !== null && _c !== void 0 ? _c : 0;
|
|
28
|
-
this.scale = (_d = config === null || config === void 0 ? void 0 : config.scale) !== null && _d !== void 0 ? _d : 1;
|
|
29
|
-
this.strokeWidth = (_e = config === null || config === void 0 ? void 0 : config.strokeWidth) !== null && _e !== void 0 ? _e : 8;
|
|
30
|
-
this.fill = (_f = config === null || config === void 0 ? void 0 : config.fill) !== null && _f !== void 0 ? _f : { light: '#000000', dark: '#ffffff' };
|
|
31
|
-
this.d = this.generateSvgPath();
|
|
32
|
-
this.updateDimensions();
|
|
33
|
-
}
|
|
34
|
-
static create(core, options) {
|
|
35
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
36
|
-
const object = new KritzelPath();
|
|
37
|
-
object._core = core;
|
|
38
|
-
object.id = object.generateId();
|
|
39
|
-
object.workspaceId = core.store.state.activeWorkspace.id;
|
|
40
|
-
object.options = options;
|
|
41
|
-
object.points = (_a = options === null || options === void 0 ? void 0 : options.points) !== null && _a !== void 0 ? _a : [];
|
|
42
|
-
object.translateX = (_b = options === null || options === void 0 ? void 0 : options.translateX) !== null && _b !== void 0 ? _b : 0;
|
|
43
|
-
object.translateY = (_c = options === null || options === void 0 ? void 0 : options.translateY) !== null && _c !== void 0 ? _c : 0;
|
|
44
|
-
object.scale = (_d = options === null || options === void 0 ? void 0 : options.scale) !== null && _d !== void 0 ? _d : 1;
|
|
45
|
-
object.strokeWidth = (_e = options === null || options === void 0 ? void 0 : options.strokeWidth) !== null && _e !== void 0 ? _e : 8;
|
|
46
|
-
object.fill = (_f = options === null || options === void 0 ? void 0 : options.fill) !== null && _f !== void 0 ? _f : { light: '#000000', dark: '#ffffff' };
|
|
47
|
-
object.opacity = (_g = options === null || options === void 0 ? void 0 : options.opacity) !== null && _g !== void 0 ? _g : 1;
|
|
48
|
-
object.zIndex = core.store.currentZIndex;
|
|
49
|
-
object.d = object.generateSvgPath();
|
|
50
|
-
object.updateDimensions();
|
|
51
|
-
return object;
|
|
52
|
-
}
|
|
53
|
-
copy() {
|
|
54
|
-
const copiedObject = super.copy();
|
|
55
|
-
if (this.points) {
|
|
56
|
-
copiedObject.points = this.points.map(p => [...p]);
|
|
57
|
-
}
|
|
58
|
-
return copiedObject;
|
|
59
|
-
}
|
|
60
|
-
resize(x, y, width, height) {
|
|
61
|
-
if (width <= 1 || height <= 1) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
const scaleX = width / this.width;
|
|
65
|
-
const scaleY = height / this.height;
|
|
66
|
-
this.width = width;
|
|
67
|
-
this.height = height;
|
|
68
|
-
if (this.points.length === 1) {
|
|
69
|
-
const p = this.points[0];
|
|
70
|
-
const spreadX = Math.max(0, width - this.strokeWidth) / scaleX;
|
|
71
|
-
const spreadY = Math.max(0, height - this.strokeWidth) / scaleY;
|
|
72
|
-
this.points.push([p[0] + spreadX, p[1] + spreadY]);
|
|
73
|
-
}
|
|
74
|
-
this.points = this.points.map(([x, y]) => [x * scaleX, y * scaleY]);
|
|
75
|
-
this.d = this.generateSvgPath();
|
|
76
|
-
this.width = Math.max(...this.points.map(p => p[0])) - Math.min(...this.points.map(p => p[0])) + this.strokeWidth;
|
|
77
|
-
this.height = Math.max(...this.points.map(p => p[1])) - Math.min(...this.points.map(p => p[1])) + this.strokeWidth;
|
|
78
|
-
this.x = Math.min(...this.points.map(p => p[0])) - this.strokeWidth / 2;
|
|
79
|
-
this.y = Math.min(...this.points.map(p => p[1])) - this.strokeWidth / 2;
|
|
80
|
-
this.translateX = x;
|
|
81
|
-
this.translateY = y;
|
|
82
|
-
this._adjustedPoints = null;
|
|
83
|
-
this._core.store.state.objects.update(this);
|
|
84
|
-
}
|
|
85
|
-
rotate(value) {
|
|
86
|
-
this.rotation = value;
|
|
87
|
-
this._adjustedPoints = null;
|
|
88
|
-
this._core.store.state.objects.update(this);
|
|
89
|
-
}
|
|
90
|
-
move(startX, startY, endX, endY) {
|
|
91
|
-
const deltaX = (startX - endX) / this._core.store.state.scale;
|
|
92
|
-
const deltaY = (startY - endY) / this._core.store.state.scale;
|
|
93
|
-
this.translateX += deltaX;
|
|
94
|
-
this.translateY += deltaY;
|
|
95
|
-
this._adjustedPoints = null;
|
|
96
|
-
this._core.store.state.objects.update(this);
|
|
97
|
-
}
|
|
98
|
-
hitTest(x, y) {
|
|
99
|
-
const halfStroke = this.strokeWidth / this.scale / 2;
|
|
100
|
-
if (this._adjustedPoints === null) {
|
|
101
|
-
this._adjustedPoints = this.computeAdjustedPoints();
|
|
102
|
-
}
|
|
103
|
-
if (this._adjustedPoints.length === 1) {
|
|
104
|
-
const p1 = this._adjustedPoints[0];
|
|
105
|
-
const distance = this.pointToLineSegmentDistance(x, y, p1[0], p1[1], p1[0], p1[1]);
|
|
106
|
-
return distance <= halfStroke;
|
|
107
|
-
}
|
|
108
|
-
for (let i = 0; i < this._adjustedPoints.length - 1; i++) {
|
|
109
|
-
const p1 = this._adjustedPoints[i];
|
|
110
|
-
const p2 = this._adjustedPoints[i + 1];
|
|
111
|
-
const distance = this.pointToLineSegmentDistance(x, y, p1[0], p1[1], p2[0], p2[1]);
|
|
112
|
-
if (distance <= halfStroke) {
|
|
113
|
-
return true;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
hitTestPolygon(polygon) {
|
|
119
|
-
const halfStroke = this.strokeWidth / this.scale / 2;
|
|
120
|
-
if (this._adjustedPoints === null) {
|
|
121
|
-
this._adjustedPoints = this.computeAdjustedPoints();
|
|
122
|
-
}
|
|
123
|
-
const polyPoints = [
|
|
124
|
-
{ x: polygon.bottomLeft.x, y: polygon.bottomLeft.y },
|
|
125
|
-
{ x: polygon.bottomRight.x, y: polygon.bottomRight.y },
|
|
126
|
-
{ x: polygon.topRight.x, y: polygon.topRight.y },
|
|
127
|
-
{ x: polygon.topLeft.x, y: polygon.topLeft.y },
|
|
128
|
-
];
|
|
129
|
-
for (const [px, py] of this._adjustedPoints) {
|
|
130
|
-
if (KritzelGeometryHelper.isPointInPolygon({ x: px, y: py }, polyPoints)) {
|
|
131
|
-
return true;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
for (const pt of polyPoints) {
|
|
135
|
-
if (this.hitTest(pt.x, pt.y)) {
|
|
136
|
-
return true;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
for (let i = 0; i < this._adjustedPoints.length - 1; i++) {
|
|
140
|
-
const p1 = { x: this._adjustedPoints[i][0], y: this._adjustedPoints[i][1] };
|
|
141
|
-
const p2 = { x: this._adjustedPoints[i + 1][0], y: this._adjustedPoints[i + 1][1] };
|
|
142
|
-
for (let j = 0; j < polyPoints.length; j++) {
|
|
143
|
-
const q1 = polyPoints[j];
|
|
144
|
-
const q2 = polyPoints[(j + 1) % polyPoints.length];
|
|
145
|
-
if (KritzelGeometryHelper.intersectLines(p1, p2, q1, q2)) {
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
for (let i = 0; i < this._adjustedPoints.length - 1; i++) {
|
|
151
|
-
const p1 = this._adjustedPoints[i];
|
|
152
|
-
const p2 = this._adjustedPoints[i + 1];
|
|
153
|
-
for (let j = 0; j < polyPoints.length; j++) {
|
|
154
|
-
const q1 = polyPoints[j];
|
|
155
|
-
const q2 = polyPoints[(j + 1) % polyPoints.length];
|
|
156
|
-
const d1 = this.pointToLineSegmentDistance(q1.x, q1.y, p1[0], p1[1], p2[0], p2[1]);
|
|
157
|
-
const d2 = this.pointToLineSegmentDistance(q2.x, q2.y, p1[0], p1[1], p2[0], p2[1]);
|
|
158
|
-
const d3 = this.pointToLineSegmentDistance(p1[0], p1[1], q1.x, q1.y, q2.x, q2.y);
|
|
159
|
-
const d4 = this.pointToLineSegmentDistance(p2[0], p2[1], q1.x, q1.y, q2.x, q2.y);
|
|
160
|
-
const minD = Math.min(d1, d2, d3, d4);
|
|
161
|
-
if (minD <= halfStroke) {
|
|
162
|
-
return true;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
updatePosition(x, y) {
|
|
169
|
-
this.translateX = x;
|
|
170
|
-
this.translateY = y;
|
|
171
|
-
this._adjustedPoints = null;
|
|
172
|
-
this._core.store.state.objects.update(this);
|
|
173
|
-
}
|
|
174
|
-
onAfterUpdate(changedProperties) {
|
|
175
|
-
if (changedProperties.includes('strokeWidth')) {
|
|
176
|
-
this.d = this.generateSvgPath();
|
|
177
|
-
this.updateBoundingBox();
|
|
178
|
-
this._adjustedPoints = null;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
computeAdjustedPoints() {
|
|
182
|
-
var _a;
|
|
183
|
-
if (!((_a = this.points) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
184
|
-
return [];
|
|
185
|
-
}
|
|
186
|
-
const angle = this.rotation;
|
|
187
|
-
const cos = Math.cos(angle);
|
|
188
|
-
const sin = Math.sin(angle);
|
|
189
|
-
const xs = this.points.map(p => p[0]);
|
|
190
|
-
const ys = this.points.map(p => p[1]);
|
|
191
|
-
const pivot = {
|
|
192
|
-
x: (Math.min(...xs) + Math.max(...xs)) / 2,
|
|
193
|
-
y: (Math.min(...ys) + Math.max(...ys)) / 2,
|
|
194
|
-
};
|
|
195
|
-
const { x: cx, y: cy } = pivot;
|
|
196
|
-
const rotatedPoints = this.points.map(([x, y]) => {
|
|
197
|
-
const dx = x - cx;
|
|
198
|
-
const dy = y - cy;
|
|
199
|
-
return [cx + dx * cos - dy * sin, cy + dx * sin + dy * cos];
|
|
200
|
-
});
|
|
201
|
-
return rotatedPoints.map(([px, py]) => [Math.abs(px - this.x) / this.scale + this.translateX, Math.abs(py - this.y) / this.scale + this.translateY]);
|
|
202
|
-
}
|
|
203
|
-
pointToLineSegmentDistance(x, y, x1, y1, x2, y2) {
|
|
204
|
-
const A = x - x1;
|
|
205
|
-
const B = y - y1;
|
|
206
|
-
const C = x2 - x1;
|
|
207
|
-
const D = y2 - y1;
|
|
208
|
-
const dot = A * C + B * D;
|
|
209
|
-
const len_sq = C * C + D * D;
|
|
210
|
-
let param = -1;
|
|
211
|
-
if (len_sq !== 0) {
|
|
212
|
-
// in case of 0 length line
|
|
213
|
-
param = dot / len_sq;
|
|
214
|
-
}
|
|
215
|
-
let xx, yy;
|
|
216
|
-
if (param < 0) {
|
|
217
|
-
xx = x1;
|
|
218
|
-
yy = y1;
|
|
219
|
-
}
|
|
220
|
-
else if (param > 1) {
|
|
221
|
-
xx = x2;
|
|
222
|
-
yy = y2;
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
xx = x1 + param * C;
|
|
226
|
-
yy = y1 + param * D;
|
|
227
|
-
}
|
|
228
|
-
const dx = x - xx;
|
|
229
|
-
const dy = y - yy;
|
|
230
|
-
return Math.sqrt(dx * dx + dy * dy);
|
|
231
|
-
}
|
|
232
|
-
updateDimensions() {
|
|
233
|
-
const rotatedPoints = this.points.map(([x, y]) => {
|
|
234
|
-
const rotatedX = x * Math.cos(this.rotation) - y * Math.sin(this.rotation);
|
|
235
|
-
const rotatedY = x * Math.sin(this.rotation) + y * Math.cos(this.rotation);
|
|
236
|
-
return [rotatedX, rotatedY];
|
|
237
|
-
});
|
|
238
|
-
const minX = Math.min(...rotatedPoints.map(p => p[0] - this.strokeWidth / 2));
|
|
239
|
-
const minY = Math.min(...rotatedPoints.map(p => p[1] - this.strokeWidth / 2));
|
|
240
|
-
const maxX = Math.max(...rotatedPoints.map(p => p[0] + this.strokeWidth / 2));
|
|
241
|
-
const maxY = Math.max(...rotatedPoints.map(p => p[1] + this.strokeWidth / 2));
|
|
242
|
-
this.width = maxX - minX + this.lineSlack;
|
|
243
|
-
this.height = maxY - minY + this.lineSlack;
|
|
244
|
-
this.x = minX;
|
|
245
|
-
this.y = minY;
|
|
246
|
-
this.translateX = (this.x + this.translateX) / this.scale;
|
|
247
|
-
this.translateY = (this.y + this.translateY) / this.scale;
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Updates width, height, x, y based on current points and strokeWidth.
|
|
251
|
-
* Does NOT modify translateX/translateY (use updateDimensions for initial setup).
|
|
252
|
-
*/
|
|
253
|
-
updateBoundingBox() {
|
|
254
|
-
const minX = Math.min(...this.points.map(p => p[0])) - this.strokeWidth / 2;
|
|
255
|
-
const minY = Math.min(...this.points.map(p => p[1])) - this.strokeWidth / 2;
|
|
256
|
-
const maxX = Math.max(...this.points.map(p => p[0])) + this.strokeWidth / 2;
|
|
257
|
-
const maxY = Math.max(...this.points.map(p => p[1])) + this.strokeWidth / 2;
|
|
258
|
-
this.width = maxX - minX + this.lineSlack;
|
|
259
|
-
this.height = maxY - minY + this.lineSlack;
|
|
260
|
-
this.x = minX;
|
|
261
|
-
this.y = minY;
|
|
262
|
-
}
|
|
263
|
-
generateSvgPath() {
|
|
264
|
-
const stroke = this.getStrokeFromPoints(this.points, this.strokeWidth);
|
|
265
|
-
return this.getSvgPathFromStroke(stroke);
|
|
266
|
-
}
|
|
267
|
-
getStrokeFromPoints(points, strokeWidth) {
|
|
268
|
-
return getStroke(points, {
|
|
269
|
-
size: strokeWidth,
|
|
270
|
-
thinning: 0.5,
|
|
271
|
-
smoothing: 0.5,
|
|
272
|
-
streamline: 0.5,
|
|
273
|
-
easing: t => t,
|
|
274
|
-
simulatePressure: true,
|
|
275
|
-
last: true,
|
|
276
|
-
start: {
|
|
277
|
-
cap: true,
|
|
278
|
-
taper: 0,
|
|
279
|
-
easing: t => t,
|
|
280
|
-
},
|
|
281
|
-
end: {
|
|
282
|
-
cap: true,
|
|
283
|
-
taper: 0,
|
|
284
|
-
easing: t => t,
|
|
285
|
-
},
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
getSvgPathFromStroke(points, closed = true) {
|
|
289
|
-
const len = points.length;
|
|
290
|
-
if (len < 4) {
|
|
291
|
-
return ``;
|
|
292
|
-
}
|
|
293
|
-
let a = points[0];
|
|
294
|
-
let b = points[1];
|
|
295
|
-
const c = points[2];
|
|
296
|
-
let result = `M${a[0].toFixed(2)},${a[1].toFixed(2)} Q${b[0].toFixed(2)},${b[1].toFixed(2)} ${KritzelMathHelper.average(b[0], c[0]).toFixed(2)},${KritzelMathHelper.average(b[1], c[1]).toFixed(2)} T`;
|
|
297
|
-
for (let i = 2, max = len - 1; i < max; i++) {
|
|
298
|
-
a = points[i];
|
|
299
|
-
b = points[i + 1];
|
|
300
|
-
result += `${KritzelMathHelper.average(a[0], b[0]).toFixed(2)},${KritzelMathHelper.average(a[1], b[1]).toFixed(2)} `;
|
|
301
|
-
}
|
|
302
|
-
if (closed) {
|
|
303
|
-
result += 'Z';
|
|
304
|
-
}
|
|
305
|
-
return result;
|
|
306
|
-
}
|
|
307
|
-
isLowRes() {
|
|
308
|
-
if (!this._core) {
|
|
309
|
-
return false;
|
|
310
|
-
}
|
|
311
|
-
const viewportScale = this._core.store.state.scale;
|
|
312
|
-
const scaledWidth = this.boundingBox.width * viewportScale;
|
|
313
|
-
const scaledHeight = this.boundingBox.height * viewportScale;
|
|
314
|
-
return (scaledWidth * scaledHeight) < 500;
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Finds the point where a line from outsidePoint to the path's center
|
|
318
|
-
* intersects the stroke edge. Returns null if no intersection found.
|
|
319
|
-
* This is used for arrow clipping at the actual stroke edge.
|
|
320
|
-
*/
|
|
321
|
-
getClipPoint(outsidePoint) {
|
|
322
|
-
const centerX = this.centerX;
|
|
323
|
-
const centerY = this.centerY;
|
|
324
|
-
const halfStroke = this.strokeWidth / this.scale / 2;
|
|
325
|
-
// Ensure adjusted points are computed
|
|
326
|
-
if (this._adjustedPoints === null) {
|
|
327
|
-
this._adjustedPoints = this.computeAdjustedPoints();
|
|
328
|
-
}
|
|
329
|
-
if (this._adjustedPoints.length < 1) {
|
|
330
|
-
return null;
|
|
331
|
-
}
|
|
332
|
-
// Sample along the line from outsidePoint to center to find stroke edge
|
|
333
|
-
const steps = 32;
|
|
334
|
-
let prevOutside = true;
|
|
335
|
-
for (let i = 1; i <= steps; i++) {
|
|
336
|
-
const t = i / steps;
|
|
337
|
-
const sampleX = outsidePoint.x + (centerX - outsidePoint.x) * t;
|
|
338
|
-
const sampleY = outsidePoint.y + (centerY - outsidePoint.y) * t;
|
|
339
|
-
// Check distance to path stroke
|
|
340
|
-
let minDistance = Infinity;
|
|
341
|
-
if (this._adjustedPoints.length === 1) {
|
|
342
|
-
const p = this._adjustedPoints[0];
|
|
343
|
-
const dx = sampleX - p[0];
|
|
344
|
-
const dy = sampleY - p[1];
|
|
345
|
-
minDistance = Math.sqrt(dx * dx + dy * dy);
|
|
346
|
-
}
|
|
347
|
-
else {
|
|
348
|
-
for (let j = 0; j < this._adjustedPoints.length - 1; j++) {
|
|
349
|
-
const p1 = this._adjustedPoints[j];
|
|
350
|
-
const p2 = this._adjustedPoints[j + 1];
|
|
351
|
-
const dist = this.pointToLineSegmentDistance(sampleX, sampleY, p1[0], p1[1], p2[0], p2[1]);
|
|
352
|
-
if (dist < minDistance) {
|
|
353
|
-
minDistance = dist;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
const isInside = minDistance <= halfStroke;
|
|
358
|
-
// Found the edge: transition from outside to inside
|
|
359
|
-
if (prevOutside && isInside) {
|
|
360
|
-
// Refine the intersection point using binary search
|
|
361
|
-
let tLow = (i - 1) / steps;
|
|
362
|
-
let tHigh = t;
|
|
363
|
-
for (let k = 0; k < 8; k++) {
|
|
364
|
-
const tMid = (tLow + tHigh) / 2;
|
|
365
|
-
const midX = outsidePoint.x + (centerX - outsidePoint.x) * tMid;
|
|
366
|
-
const midY = outsidePoint.y + (centerY - outsidePoint.y) * tMid;
|
|
367
|
-
let midDist = Infinity;
|
|
368
|
-
if (this._adjustedPoints.length === 1) {
|
|
369
|
-
const p = this._adjustedPoints[0];
|
|
370
|
-
const dx = midX - p[0];
|
|
371
|
-
const dy = midY - p[1];
|
|
372
|
-
midDist = Math.sqrt(dx * dx + dy * dy);
|
|
373
|
-
}
|
|
374
|
-
else {
|
|
375
|
-
for (let j = 0; j < this._adjustedPoints.length - 1; j++) {
|
|
376
|
-
const p1 = this._adjustedPoints[j];
|
|
377
|
-
const p2 = this._adjustedPoints[j + 1];
|
|
378
|
-
const dist = this.pointToLineSegmentDistance(midX, midY, p1[0], p1[1], p2[0], p2[1]);
|
|
379
|
-
if (dist < midDist) {
|
|
380
|
-
midDist = dist;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
if (midDist <= halfStroke) {
|
|
385
|
-
tHigh = tMid;
|
|
386
|
-
}
|
|
387
|
-
else {
|
|
388
|
-
tLow = tMid;
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
const finalT = (tLow + tHigh) / 2;
|
|
392
|
-
return {
|
|
393
|
-
x: outsidePoint.x + (centerX - outsidePoint.x) * finalT,
|
|
394
|
-
y: outsidePoint.y + (centerY - outsidePoint.y) * finalT,
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
|
-
prevOutside = !isInside;
|
|
398
|
-
}
|
|
399
|
-
return null;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { KritzelBaseObject } from './base-object.class';
|
|
2
|
-
export class KritzelSelectionBox extends KritzelBaseObject {
|
|
3
|
-
constructor() {
|
|
4
|
-
super(...arguments);
|
|
5
|
-
this.__class__ = 'KritzelSelectionBox';
|
|
6
|
-
}
|
|
7
|
-
static create(core) {
|
|
8
|
-
const object = new KritzelSelectionBox();
|
|
9
|
-
object._core = core;
|
|
10
|
-
object.id = object.generateId();
|
|
11
|
-
object.workspaceId = core.store.state.activeWorkspace.id;
|
|
12
|
-
object.scale = core.store.state.scale;
|
|
13
|
-
object.zIndex = 99999;
|
|
14
|
-
object.backgroundColor = { light: 'rgba(0, 122, 255, 0.2)', dark: 'rgba(0, 122, 255, 0.2)' };
|
|
15
|
-
object.borderColor = { light: 'rgba(0, 122, 255, 0.5)', dark: 'rgba(0, 122, 255, 0.5)' };
|
|
16
|
-
object.borderWidth = 2;
|
|
17
|
-
object.height = 0;
|
|
18
|
-
object.width = 0;
|
|
19
|
-
return object;
|
|
20
|
-
}
|
|
21
|
-
}
|