kritzel-stencil 0.0.119 → 0.0.121
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/cjs/{index-CXT94beA.js → index-BcrLbdO1.js} +50 -10
- package/dist/cjs/index-BcrLbdO1.js.map +1 -0
- package/dist/cjs/index-BjLSiQIM.js +2342 -0
- package/dist/cjs/index-BjLSiQIM.js.map +1 -0
- package/dist/cjs/index.cjs.js +8 -1
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/cjs/kritzel-brush-style_18.cjs.entry.js +363 -1743
- package/dist/cjs/kritzel-brush-style_18.cjs.entry.js.map +1 -1
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/stencil.cjs.js +3 -3
- package/dist/cjs/stencil.cjs.js.map +1 -1
- package/dist/collection/classes/commands/add-selection-group.command.js +2 -0
- package/dist/collection/classes/commands/add-selection-group.command.js.map +1 -1
- package/dist/collection/classes/objects/base-object.class.js +4 -0
- package/dist/collection/classes/objects/base-object.class.js.map +1 -1
- package/dist/collection/classes/objects/image.class.js +23 -2
- package/dist/collection/classes/objects/image.class.js.map +1 -1
- package/dist/collection/classes/objects/path.class.js +15 -5
- package/dist/collection/classes/objects/path.class.js.map +1 -1
- package/dist/collection/classes/objects/text.class.js +2 -1
- package/dist/collection/classes/objects/text.class.js.map +1 -1
- package/dist/collection/classes/store.class.js +2 -13
- package/dist/collection/classes/store.class.js.map +1 -1
- package/dist/collection/classes/tools/image-tool.class.js +6 -23
- package/dist/collection/classes/tools/image-tool.class.js.map +1 -1
- package/dist/collection/classes/tools/selection-tool.class.js +4 -13
- package/dist/collection/classes/tools/selection-tool.class.js.map +1 -1
- package/dist/collection/classes/viewport.class.js.map +1 -1
- package/dist/collection/collection-manifest.json +1 -1
- package/dist/collection/components/core/kritzel-editor/kritzel-editor.js +217 -13
- package/dist/collection/components/core/kritzel-editor/kritzel-editor.js.map +1 -1
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +159 -68
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.js.map +1 -1
- package/dist/collection/components/ui/kritzel-context-menu/kritzel-context-menu.js +104 -4
- package/dist/collection/components/ui/kritzel-context-menu/kritzel-context-menu.js.map +1 -1
- package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js +30 -9
- package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js.map +1 -1
- package/dist/collection/configs/default-brush-tool.config.js +60 -0
- package/dist/collection/configs/default-brush-tool.config.js.map +1 -0
- package/dist/collection/configs/default-engine-state.js +6 -2
- package/dist/collection/configs/default-engine-state.js.map +1 -1
- package/dist/collection/configs/default-text-tool.config.js +32 -0
- package/dist/collection/configs/default-text-tool.config.js.map +1 -0
- package/dist/collection/constants/engine.constants.js +3 -0
- package/dist/collection/constants/engine.constants.js.map +1 -0
- package/dist/collection/index.js +8 -0
- package/dist/collection/index.js.map +1 -1
- package/dist/collection/interfaces/context-menu-item.interface.js.map +1 -1
- package/dist/collection/interfaces/engine-state.interface.js.map +1 -1
- package/dist/collection/interfaces/object.interface.js.map +1 -1
- package/dist/components/index.js +4 -4
- package/dist/components/kritzel-brush-style.js +1 -1
- package/dist/components/kritzel-color-palette.js +1 -1
- package/dist/components/kritzel-color.js +1 -1
- package/dist/components/kritzel-context-menu.js +1 -1
- package/dist/components/kritzel-control-brush-config.js +1 -1
- package/dist/components/kritzel-control-text-config.js +1 -1
- package/dist/components/kritzel-controls.js +1 -1
- package/dist/components/kritzel-cursor-trail.js +1 -1
- package/dist/components/kritzel-dropdown.js +1 -1
- package/dist/components/kritzel-editor.js +110 -68
- package/dist/components/kritzel-editor.js.map +1 -1
- package/dist/components/kritzel-engine.js +1 -1
- package/dist/components/kritzel-font-family.js +1 -1
- package/dist/components/kritzel-font-size.js +1 -1
- package/dist/components/kritzel-font.js +1 -1
- package/dist/components/kritzel-icon.js +1 -1
- package/dist/components/kritzel-stroke-size.js +1 -1
- package/dist/components/kritzel-tooltip.js +1 -1
- package/dist/components/kritzel-utility-panel.js +1 -1
- package/dist/components/{p-CtNzxQ7T.js → p--2FkikYE.js} +4 -4
- package/dist/components/{p-CtNzxQ7T.js.map → p--2FkikYE.js.map} +1 -1
- package/dist/components/{p-LIijWPsT.js → p--tElassI.js} +4 -4
- package/dist/components/{p-LIijWPsT.js.map → p--tElassI.js.map} +1 -1
- package/dist/components/{p-C6kzcN4b.js → p-B2wWYPH8.js} +4 -4
- package/dist/components/{p-C6kzcN4b.js.map → p-B2wWYPH8.js.map} +1 -1
- package/dist/components/{p-93b-eQ0s.js → p-BAMl2Ww6.js} +29 -27
- package/dist/components/p-BAMl2Ww6.js.map +1 -0
- package/dist/components/{p-B8nuvSxt.js → p-BSS4UREq.js} +10 -10
- package/dist/components/{p-B8nuvSxt.js.map → p-BSS4UREq.js.map} +1 -1
- package/dist/components/{p-JQA2FRVr.js → p-C3E9PtD3.js} +11 -11
- package/dist/components/{p-JQA2FRVr.js.map → p-C3E9PtD3.js.map} +1 -1
- package/dist/components/{p-B57pFHwJ.js → p-CDpq9L_H.js} +4 -4
- package/dist/components/{p-B57pFHwJ.js.map → p-CDpq9L_H.js.map} +1 -1
- package/dist/components/p-CEYRFk55.js +119 -0
- package/dist/components/p-CEYRFk55.js.map +1 -0
- package/dist/components/{p-BV9-NuyD.js → p-CIb4IA9u.js} +6 -6
- package/dist/components/{p-BV9-NuyD.js.map → p-CIb4IA9u.js.map} +1 -1
- package/dist/components/{p-eBBOf568.js → p-CqPrOhzi.js} +5 -5
- package/dist/components/{p-eBBOf568.js.map → p-CqPrOhzi.js.map} +1 -1
- package/dist/components/{p-CaQ7Iei7.js → p-CxmkJbeV.js} +4 -4
- package/dist/components/{p-CaQ7Iei7.js.map → p-CxmkJbeV.js.map} +1 -1
- package/dist/components/{p-yBnfPxIa.js → p-D-Rf05Ov.js} +5 -5
- package/dist/components/{p-yBnfPxIa.js.map → p-D-Rf05Ov.js.map} +1 -1
- package/dist/components/{p-CSSrNLad.js → p-D0L3GqSK.js} +4 -4
- package/dist/components/{p-CSSrNLad.js.map → p-D0L3GqSK.js.map} +1 -1
- package/dist/components/{p-fmNiA3Yr.js → p-D1oFXBAp.js} +5 -5
- package/dist/components/{p-fmNiA3Yr.js.map → p-D1oFXBAp.js.map} +1 -1
- package/dist/components/{p-DRuQsvUx.js → p-DC3j4P1n.js} +23 -8
- package/dist/components/p-DC3j4P1n.js.map +1 -0
- package/dist/components/{p-D04aTZsR.js → p-DbPbyRLO.js} +5 -5
- package/dist/components/{p-D04aTZsR.js.map → p-DbPbyRLO.js.map} +1 -1
- package/dist/components/{p-DoQOtXjT.js → p-dCaxwGmu.js} +44 -9
- package/dist/components/p-dCaxwGmu.js.map +1 -0
- package/dist/components/{p-BBIuV3j1.js → p-gDLg_PJJ.js} +5 -5
- package/dist/components/{p-BBIuV3j1.js.map → p-gDLg_PJJ.js.map} +1 -1
- package/dist/components/{p-DuWb7MaD.js → p-q-xqpmae.js} +137 -125
- package/dist/components/p-q-xqpmae.js.map +1 -0
- package/dist/esm/{index-CGHvfMWF.js → index-BPFXWTBp.js} +50 -10
- package/dist/esm/index-BPFXWTBp.js.map +1 -0
- package/dist/esm/index-DsUDklEm.js +2318 -0
- package/dist/esm/index-DsUDklEm.js.map +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/kritzel-brush-style_18.entry.js +333 -1713
- package/dist/esm/kritzel-brush-style_18.entry.js.map +1 -1
- package/dist/esm/loader.js +3 -3
- package/dist/esm/stencil.js +4 -4
- package/dist/esm/stencil.js.map +1 -1
- package/dist/stencil/index.esm.js +1 -1
- package/dist/stencil/p-3797c300.entry.js +2 -0
- package/dist/stencil/p-3797c300.entry.js.map +1 -0
- package/dist/stencil/p-BPFXWTBp.js +3 -0
- package/dist/stencil/p-BPFXWTBp.js.map +1 -0
- package/dist/stencil/p-DsUDklEm.js +2 -0
- package/dist/stencil/p-DsUDklEm.js.map +1 -0
- package/dist/stencil/stencil.esm.js +1 -1
- package/dist/stencil/stencil.esm.js.map +1 -1
- package/dist/types/classes/objects/base-object.class.d.ts +3 -1
- package/dist/types/classes/objects/image.class.d.ts +8 -0
- package/dist/types/classes/objects/path.class.d.ts +9 -0
- package/dist/types/classes/objects/text.class.d.ts +2 -1
- package/dist/types/classes/store.class.d.ts +1 -1
- package/dist/types/classes/tools/image-tool.class.d.ts +0 -4
- package/dist/types/components/core/kritzel-editor/kritzel-editor.d.ts +9 -3
- package/dist/types/components/core/kritzel-engine/kritzel-engine.d.ts +12 -4
- package/dist/types/components/ui/kritzel-context-menu/kritzel-context-menu.d.ts +8 -0
- package/dist/types/components/ui/kritzel-controls/kritzel-controls.d.ts +2 -1
- package/dist/types/components.d.ts +77 -22
- package/dist/types/configs/default-brush-tool.config.d.ts +2 -0
- package/dist/types/configs/default-text-tool.config.d.ts +2 -0
- package/dist/types/constants/engine.constants.d.ts +2 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/interfaces/context-menu-item.interface.d.ts +13 -2
- package/dist/types/interfaces/engine-state.interface.d.ts +4 -0
- package/dist/types/interfaces/object.interface.d.ts +2 -0
- package/package.json +1 -1
- package/dist/cjs/index-CXT94beA.js.map +0 -1
- package/dist/cjs/index-aaWestcD.js +0 -827
- package/dist/cjs/index-aaWestcD.js.map +0 -1
- package/dist/collection/configs/default-toolbar-controls.js +0 -139
- package/dist/collection/configs/default-toolbar-controls.js.map +0 -1
- package/dist/components/p-93b-eQ0s.js.map +0 -1
- package/dist/components/p-CYnE3twZ.js +0 -49
- package/dist/components/p-CYnE3twZ.js.map +0 -1
- package/dist/components/p-DRuQsvUx.js.map +0 -1
- package/dist/components/p-DoQOtXjT.js.map +0 -1
- package/dist/components/p-DuWb7MaD.js.map +0 -1
- package/dist/esm/index-CGHvfMWF.js.map +0 -1
- package/dist/esm/index-Dn7aP72S.js +0 -814
- package/dist/esm/index-Dn7aP72S.js.map +0 -1
- package/dist/stencil/p-6c35ba88.entry.js +0 -2
- package/dist/stencil/p-6c35ba88.entry.js.map +0 -1
- package/dist/stencil/p-CGHvfMWF.js +0 -3
- package/dist/stencil/p-CGHvfMWF.js.map +0 -1
- package/dist/stencil/p-Dn7aP72S.js +0 -2
- package/dist/stencil/p-Dn7aP72S.js.map +0 -1
- package/dist/types/configs/default-toolbar-controls.d.ts +0 -4
|
@@ -1,814 +0,0 @@
|
|
|
1
|
-
class KritzelToolRegistry {
|
|
2
|
-
static registerTool(toolName, constructor, store) {
|
|
3
|
-
const toolInstance = new constructor(store);
|
|
4
|
-
toolInstance.name = toolName;
|
|
5
|
-
this.registry[toolName] = toolInstance;
|
|
6
|
-
return toolInstance;
|
|
7
|
-
}
|
|
8
|
-
static getTool(toolName) {
|
|
9
|
-
const toolInstance = this.registry[toolName];
|
|
10
|
-
if (!toolInstance) {
|
|
11
|
-
console.warn(`Unknown tool: ${toolName}`);
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
return toolInstance;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
KritzelToolRegistry.registry = {};
|
|
18
|
-
|
|
19
|
-
class KritzelBaseTool {
|
|
20
|
-
constructor(store) {
|
|
21
|
-
this.__class__ = this.constructor.name;
|
|
22
|
-
this.name = 'base-tool';
|
|
23
|
-
this._store = store;
|
|
24
|
-
}
|
|
25
|
-
onActivate() {
|
|
26
|
-
// default implementation
|
|
27
|
-
}
|
|
28
|
-
onDeactivate() {
|
|
29
|
-
// default implementation
|
|
30
|
-
}
|
|
31
|
-
handlePointerDown(_event) {
|
|
32
|
-
// default implementation
|
|
33
|
-
}
|
|
34
|
-
handlePointerMove(_event) {
|
|
35
|
-
// default implementation
|
|
36
|
-
}
|
|
37
|
-
handlePointerUp(_event) {
|
|
38
|
-
// default implementation
|
|
39
|
-
}
|
|
40
|
-
handleWheel(_event) {
|
|
41
|
-
// default implementation
|
|
42
|
-
}
|
|
43
|
-
revive(object) {
|
|
44
|
-
Object.assign(this, object);
|
|
45
|
-
return this;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
class KritzelBaseCommand {
|
|
50
|
-
constructor(store, initiator) {
|
|
51
|
-
var _a, _b;
|
|
52
|
-
this._store = store;
|
|
53
|
-
this.initiator = (_b = (_a = initiator === null || initiator === void 0 ? void 0 : initiator.constructor) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : 'Unknown';
|
|
54
|
-
this.isUndoable = true;
|
|
55
|
-
}
|
|
56
|
-
execute() {
|
|
57
|
-
throw new Error('Method not implemented.');
|
|
58
|
-
}
|
|
59
|
-
undo() {
|
|
60
|
-
throw new Error('Method not implemented.');
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
class AddObjectCommand extends KritzelBaseCommand {
|
|
65
|
-
constructor(store, initiator, object) {
|
|
66
|
-
super(store, initiator);
|
|
67
|
-
this.object = object;
|
|
68
|
-
}
|
|
69
|
-
execute() {
|
|
70
|
-
this._store.state.objectsOctree.insert(this.object);
|
|
71
|
-
}
|
|
72
|
-
undo() {
|
|
73
|
-
this._store.state.objectsOctree.remove(object => object.id === this.object.id);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
var KritzelMouseButton;
|
|
78
|
-
(function (KritzelMouseButton) {
|
|
79
|
-
KritzelMouseButton[KritzelMouseButton["Left"] = 0] = "Left";
|
|
80
|
-
KritzelMouseButton[KritzelMouseButton["Middle"] = 1] = "Middle";
|
|
81
|
-
KritzelMouseButton[KritzelMouseButton["Right"] = 2] = "Right";
|
|
82
|
-
})(KritzelMouseButton || (KritzelMouseButton = {}));
|
|
83
|
-
|
|
84
|
-
class KritzelEventHelper {
|
|
85
|
-
static isRightClick(ev) {
|
|
86
|
-
return ev.button === KritzelMouseButton.Right;
|
|
87
|
-
}
|
|
88
|
-
static isLeftClick(ev) {
|
|
89
|
-
return ev.button === KritzelMouseButton.Left;
|
|
90
|
-
}
|
|
91
|
-
static isMainMouseWheel(event) {
|
|
92
|
-
return Math.abs(event.deltaY) > 0 && Math.abs(event.deltaX) === 0 && Number.isInteger(event.deltaY);
|
|
93
|
-
}
|
|
94
|
-
static isPointerEventOnContextMenu(event) {
|
|
95
|
-
const path = event.composedPath();
|
|
96
|
-
const contextMenu = path.find(element => element.classList && element.classList.contains('context-menu'));
|
|
97
|
-
return !!contextMenu;
|
|
98
|
-
}
|
|
99
|
-
static onLongTouchPress(event, onSuccess, onCancel) {
|
|
100
|
-
if (event.pointerType !== 'touch') {
|
|
101
|
-
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
102
|
-
return () => { };
|
|
103
|
-
}
|
|
104
|
-
const longPressTimeout = 400;
|
|
105
|
-
const moveThreshold = 10;
|
|
106
|
-
const startX = event.clientX;
|
|
107
|
-
const startY = event.clientY;
|
|
108
|
-
const target = event.target;
|
|
109
|
-
const timer = setTimeout(() => {
|
|
110
|
-
removeListeners();
|
|
111
|
-
onSuccess(event);
|
|
112
|
-
}, longPressTimeout);
|
|
113
|
-
const cancel = () => {
|
|
114
|
-
clearTimeout(timer);
|
|
115
|
-
removeListeners();
|
|
116
|
-
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
117
|
-
};
|
|
118
|
-
const onPointerMove = (e) => {
|
|
119
|
-
if (Math.abs(e.clientX - startX) > moveThreshold || Math.abs(e.clientY - startY) > moveThreshold) {
|
|
120
|
-
cancel();
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
const onPointerUp = () => {
|
|
124
|
-
cancel();
|
|
125
|
-
};
|
|
126
|
-
const onPointerCancel = () => {
|
|
127
|
-
cancel();
|
|
128
|
-
};
|
|
129
|
-
const removeListeners = () => {
|
|
130
|
-
target.removeEventListener('pointermove', onPointerMove);
|
|
131
|
-
target.removeEventListener('pointerup', onPointerUp);
|
|
132
|
-
target.removeEventListener('pointercancel', onPointerCancel);
|
|
133
|
-
};
|
|
134
|
-
target.addEventListener('pointermove', onPointerMove, { passive: true });
|
|
135
|
-
target.addEventListener('pointerup', onPointerUp, { once: true });
|
|
136
|
-
target.addEventListener('pointercancel', onPointerCancel, { once: true });
|
|
137
|
-
return cancel;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
class KritzelKeyboardHelper {
|
|
142
|
-
static forceHideKeyboard() {
|
|
143
|
-
if (document.activeElement instanceof HTMLElement) {
|
|
144
|
-
document.activeElement.blur();
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
static enableInteractiveWidget() {
|
|
148
|
-
const meta = document.querySelector('meta[name="viewport"][content*="interactive-widget=resizes-content"]');
|
|
149
|
-
if (meta) {
|
|
150
|
-
let currentContent = meta.getAttribute('content');
|
|
151
|
-
if (!currentContent.includes('interactive-widget=resizes-content')) {
|
|
152
|
-
currentContent += ', interactive-widget=resizes-content';
|
|
153
|
-
}
|
|
154
|
-
meta.setAttribute('content', currentContent);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
static disableInteractiveWidget() {
|
|
158
|
-
const meta = document.querySelector('meta[name="viewport"][content*="interactive-widget=resizes-content"]');
|
|
159
|
-
if (meta) {
|
|
160
|
-
let currentContent = meta.getAttribute('content');
|
|
161
|
-
let newContent = currentContent.replace(/\s*interactive-widget=resizes-content\s*[,;]?/g, '');
|
|
162
|
-
newContent = newContent
|
|
163
|
-
.replace(/,(\s*,)+/g, ',')
|
|
164
|
-
.replace(/^,/, '')
|
|
165
|
-
.replace(/,$/, '')
|
|
166
|
-
.trim();
|
|
167
|
-
meta.setAttribute('content', newContent);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
class KritzelTextTool extends KritzelBaseTool {
|
|
173
|
-
constructor(store) {
|
|
174
|
-
super(store);
|
|
175
|
-
this.fontFamily = 'Arial';
|
|
176
|
-
this.fontSize = 16;
|
|
177
|
-
this.fontColor = '#000000';
|
|
178
|
-
this.palette = [
|
|
179
|
-
'#000000',
|
|
180
|
-
'#FFFFFF',
|
|
181
|
-
'#FF0000',
|
|
182
|
-
'#00FF00',
|
|
183
|
-
'#0000FF',
|
|
184
|
-
'#FFFF00',
|
|
185
|
-
'#FF00FF',
|
|
186
|
-
'#00FFFF',
|
|
187
|
-
'#808080',
|
|
188
|
-
'#C0C0C0',
|
|
189
|
-
'#800000',
|
|
190
|
-
'#008000',
|
|
191
|
-
'#000080',
|
|
192
|
-
'#808000',
|
|
193
|
-
'#800080',
|
|
194
|
-
];
|
|
195
|
-
}
|
|
196
|
-
handlePointerDown(event) {
|
|
197
|
-
if (event.cancelable) {
|
|
198
|
-
event.preventDefault();
|
|
199
|
-
}
|
|
200
|
-
if (event.pointerType === 'mouse') {
|
|
201
|
-
const path = event.composedPath().slice(1);
|
|
202
|
-
const objectElement = path.find(element => element.classList && element.classList.contains('object'));
|
|
203
|
-
const object = this._store.findObjectById(objectElement === null || objectElement === void 0 ? void 0 : objectElement.id);
|
|
204
|
-
if (this._store.state.activeText === null && object && object instanceof KritzelText) {
|
|
205
|
-
this._store.state.activeText = object;
|
|
206
|
-
object.focus();
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
if (this._store.state.activeText !== null && object instanceof KritzelText) {
|
|
210
|
-
object.focus();
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
if (this._store.state.activeText !== null) {
|
|
214
|
-
this._store.resetActiveText();
|
|
215
|
-
this._store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
if (KritzelEventHelper.isLeftClick(event) === false) {
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
const clientX = event.clientX - this._store.offsetX;
|
|
222
|
-
const clientY = event.clientY - this._store.offsetY;
|
|
223
|
-
const text = KritzelText.create(this._store, this.fontSize, this.fontFamily);
|
|
224
|
-
text.fontColor = this.fontColor;
|
|
225
|
-
text.translateX = (clientX - this._store.state.translateX) / this._store.state.scale;
|
|
226
|
-
text.translateY = (clientY - this._store.state.translateY) / this._store.state.scale;
|
|
227
|
-
text.zIndex = this._store.currentZIndex;
|
|
228
|
-
this._store.state.activeText = text;
|
|
229
|
-
this._store.history.executeCommand(new AddObjectCommand(this._store, this, text));
|
|
230
|
-
}
|
|
231
|
-
if (event.pointerType === 'touch') {
|
|
232
|
-
const activePointers = Array.from(this._store.state.pointers.values());
|
|
233
|
-
const path = event.composedPath().slice(1);
|
|
234
|
-
const objectElement = path.find(element => element.classList && element.classList.contains('object'));
|
|
235
|
-
const object = this._store.findObjectById(objectElement === null || objectElement === void 0 ? void 0 : objectElement.id);
|
|
236
|
-
if (this._store.state.activeText === null && object && object instanceof KritzelText) {
|
|
237
|
-
this._store.state.activeText = object;
|
|
238
|
-
object.focus();
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
if (this._store.state.activeText !== null && object instanceof KritzelText) {
|
|
242
|
-
object.focus();
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
if (this._store.state.activeText !== null) {
|
|
246
|
-
this._store.resetActiveText();
|
|
247
|
-
this._store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
if (activePointers.length > 1) {
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
KritzelKeyboardHelper.disableInteractiveWidget();
|
|
254
|
-
const clientX = Math.round(activePointers[0].clientX - this._store.offsetX);
|
|
255
|
-
const clientY = Math.round(activePointers[0].clientY - this._store.offsetY);
|
|
256
|
-
const text = KritzelText.create(this._store, this.fontSize, this.fontFamily);
|
|
257
|
-
text.fontColor = this.fontColor;
|
|
258
|
-
text.translateX = (clientX - this._store.state.translateX) / this._store.state.scale;
|
|
259
|
-
text.translateY = (clientY - this._store.state.translateY) / this._store.state.scale;
|
|
260
|
-
text.zIndex = this._store.currentZIndex;
|
|
261
|
-
this._store.state.activeText = text;
|
|
262
|
-
this._store.history.executeCommand(new AddObjectCommand(this._store, this, text));
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
handlePointerUp(event) {
|
|
266
|
-
var _a, _b, _c, _d;
|
|
267
|
-
if (event.cancelable) {
|
|
268
|
-
event.preventDefault();
|
|
269
|
-
}
|
|
270
|
-
if (event.pointerType === 'mouse') {
|
|
271
|
-
(_a = this._store.state.activeText) === null || _a === void 0 ? void 0 : _a.adjustTextareaSize();
|
|
272
|
-
(_b = this._store.state.activeText) === null || _b === void 0 ? void 0 : _b.focus();
|
|
273
|
-
}
|
|
274
|
-
if (event.pointerType === 'touch') {
|
|
275
|
-
(_c = this._store.state.activeText) === null || _c === void 0 ? void 0 : _c.adjustTextareaSize();
|
|
276
|
-
(_d = this._store.state.activeText) === null || _d === void 0 ? void 0 : _d.focus();
|
|
277
|
-
KritzelKeyboardHelper.enableInteractiveWidget();
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
var __rest = (undefined && undefined.__rest) || function (s, e) {
|
|
283
|
-
var t = {};
|
|
284
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
285
|
-
t[p] = s[p];
|
|
286
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
287
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
288
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
289
|
-
t[p[i]] = s[p[i]];
|
|
290
|
-
}
|
|
291
|
-
return t;
|
|
292
|
-
};
|
|
293
|
-
class ObjectHelper {
|
|
294
|
-
static generateUUID() {
|
|
295
|
-
return Math.random().toString(36).substr(2, 9);
|
|
296
|
-
}
|
|
297
|
-
static clone(objOrObjs) {
|
|
298
|
-
const cloneObject = (obj) => {
|
|
299
|
-
const remainingProps = __rest(obj, ["_store", "_elementRef", "totalWidth", "totalHeight"]);
|
|
300
|
-
return structuredClone(remainingProps);
|
|
301
|
-
};
|
|
302
|
-
if (Array.isArray(objOrObjs)) {
|
|
303
|
-
return objOrObjs.map(cloneObject);
|
|
304
|
-
}
|
|
305
|
-
return cloneObject(objOrObjs);
|
|
306
|
-
}
|
|
307
|
-
static isEmpty(obj) {
|
|
308
|
-
if (obj === null || obj === undefined) {
|
|
309
|
-
return true;
|
|
310
|
-
}
|
|
311
|
-
return (Object === null || Object === void 0 ? void 0 : Object.keys(obj).length) === 0 && (obj === null || obj === void 0 ? void 0 : obj.constructor) === Object;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
class KritzelBaseObject {
|
|
316
|
-
get totalWidth() {
|
|
317
|
-
return this.width + this.padding * 2;
|
|
318
|
-
}
|
|
319
|
-
get totalHeight() {
|
|
320
|
-
return this.height + this.padding * 2;
|
|
321
|
-
}
|
|
322
|
-
set elementRef(element) {
|
|
323
|
-
this._elementRef = element;
|
|
324
|
-
}
|
|
325
|
-
get elementRef() {
|
|
326
|
-
return this._elementRef;
|
|
327
|
-
}
|
|
328
|
-
get boundingBox() {
|
|
329
|
-
return {
|
|
330
|
-
x: this.translateX,
|
|
331
|
-
y: this.translateY,
|
|
332
|
-
z: this.scale,
|
|
333
|
-
width: this.totalWidth / this.scale,
|
|
334
|
-
height: this.totalHeight / this.scale,
|
|
335
|
-
depth: 0,
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
get rotatedBoundingBox() {
|
|
339
|
-
return {
|
|
340
|
-
x: this.minXRotated,
|
|
341
|
-
y: this.minYRotated,
|
|
342
|
-
z: this.scale,
|
|
343
|
-
width: this.maxXRotated - this.minXRotated,
|
|
344
|
-
height: this.maxYRotated - this.minYRotated,
|
|
345
|
-
depth: 0,
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
get rotatedPolygon() {
|
|
349
|
-
const cx = (this.translateX + this.totalWidth / 2 / this.scale);
|
|
350
|
-
const cy = (this.translateY + this.totalHeight / 2 / this.scale);
|
|
351
|
-
const angle = this.rotation;
|
|
352
|
-
const adjustedWidth = this.totalWidth / this.scale;
|
|
353
|
-
const adjustedHeight = this.totalHeight / this.scale;
|
|
354
|
-
const corners = {
|
|
355
|
-
topLeft: { x: this.translateX, y: this.translateY },
|
|
356
|
-
topRight: { x: this.translateX + adjustedWidth, y: this.translateY },
|
|
357
|
-
bottomRight: { x: this.translateX + adjustedWidth, y: this.translateY + adjustedHeight },
|
|
358
|
-
bottomLeft: { x: this.translateX, y: this.translateY + adjustedHeight },
|
|
359
|
-
};
|
|
360
|
-
const rotatedCorners = Object.keys(corners).reduce((acc, key) => {
|
|
361
|
-
const corner = corners[key];
|
|
362
|
-
const rotatedX = Math.cos(angle) * (corner.x - cx) - Math.sin(angle) * (corner.y - cy) + cx;
|
|
363
|
-
const rotatedY = Math.sin(angle) * (corner.x - cx) + Math.cos(angle) * (corner.y - cy) + cy;
|
|
364
|
-
acc[key] = { x: rotatedX, y: rotatedY };
|
|
365
|
-
return acc;
|
|
366
|
-
}, {});
|
|
367
|
-
return rotatedCorners;
|
|
368
|
-
}
|
|
369
|
-
get minXRotated() {
|
|
370
|
-
const corners = [
|
|
371
|
-
this.rotatedPolygon.topLeft.x,
|
|
372
|
-
this.rotatedPolygon.topRight.x,
|
|
373
|
-
this.rotatedPolygon.bottomRight.x,
|
|
374
|
-
this.rotatedPolygon.bottomLeft.x,
|
|
375
|
-
];
|
|
376
|
-
return Math.min(...corners);
|
|
377
|
-
}
|
|
378
|
-
get minYRotated() {
|
|
379
|
-
const corners = [
|
|
380
|
-
this.rotatedPolygon.topLeft.y,
|
|
381
|
-
this.rotatedPolygon.topRight.y,
|
|
382
|
-
this.rotatedPolygon.bottomRight.y,
|
|
383
|
-
this.rotatedPolygon.bottomLeft.y,
|
|
384
|
-
];
|
|
385
|
-
return Math.min(...corners);
|
|
386
|
-
}
|
|
387
|
-
get maxXRotated() {
|
|
388
|
-
const corners = [
|
|
389
|
-
this.rotatedPolygon.topLeft.x,
|
|
390
|
-
this.rotatedPolygon.topRight.x,
|
|
391
|
-
this.rotatedPolygon.bottomRight.x,
|
|
392
|
-
this.rotatedPolygon.bottomLeft.x,
|
|
393
|
-
];
|
|
394
|
-
return Math.max(...corners);
|
|
395
|
-
}
|
|
396
|
-
get maxYRotated() {
|
|
397
|
-
const corners = [
|
|
398
|
-
this.rotatedPolygon.topLeft.y,
|
|
399
|
-
this.rotatedPolygon.topRight.y,
|
|
400
|
-
this.rotatedPolygon.bottomRight.y,
|
|
401
|
-
this.rotatedPolygon.bottomLeft.y,
|
|
402
|
-
];
|
|
403
|
-
return Math.max(...corners);
|
|
404
|
-
}
|
|
405
|
-
get transformationMatrix() {
|
|
406
|
-
const scale = 1 / this.scale;
|
|
407
|
-
const translateX = this.translateX;
|
|
408
|
-
const translateY = this.translateY;
|
|
409
|
-
return `matrix(${scale}, 0, 0, ${scale}, ${translateX}, ${translateY})`;
|
|
410
|
-
}
|
|
411
|
-
get rotationDegrees() {
|
|
412
|
-
return this.rotation * (180 / Math.PI);
|
|
413
|
-
}
|
|
414
|
-
get centerX() {
|
|
415
|
-
return this.translateX + this.totalWidth / 2;
|
|
416
|
-
}
|
|
417
|
-
get centerY() {
|
|
418
|
-
return this.translateY + this.totalHeight / 2;
|
|
419
|
-
}
|
|
420
|
-
constructor() {
|
|
421
|
-
this.__class__ = 'KritzelBaseObject';
|
|
422
|
-
this.visible = true;
|
|
423
|
-
this.borderWidth = 0;
|
|
424
|
-
this.opacity = 1;
|
|
425
|
-
this.padding = 0;
|
|
426
|
-
this.selected = false;
|
|
427
|
-
this.resizing = false;
|
|
428
|
-
this.rotation = 0;
|
|
429
|
-
this.markedForRemoval = false;
|
|
430
|
-
this.isMounted = false;
|
|
431
|
-
this.zIndex = 0;
|
|
432
|
-
this.debugInfoVisible = false;
|
|
433
|
-
this.id = this.generateId();
|
|
434
|
-
}
|
|
435
|
-
static create(store) {
|
|
436
|
-
const object = new KritzelBaseObject();
|
|
437
|
-
object._store = store;
|
|
438
|
-
object.zIndex = store.currentZIndex;
|
|
439
|
-
return object;
|
|
440
|
-
}
|
|
441
|
-
mount(element) {
|
|
442
|
-
if (this.isMounted) {
|
|
443
|
-
return;
|
|
444
|
-
}
|
|
445
|
-
this.elementRef = element;
|
|
446
|
-
this.isMounted = true;
|
|
447
|
-
}
|
|
448
|
-
generateId() {
|
|
449
|
-
return ObjectHelper.generateUUID();
|
|
450
|
-
}
|
|
451
|
-
isInViewport() {
|
|
452
|
-
const viewportBounds = {
|
|
453
|
-
x: -this._store.state.translateX / this._store.state.scale,
|
|
454
|
-
y: -this._store.state.translateY / this._store.state.scale,
|
|
455
|
-
width: this._store.state.viewportWidth / this._store.state.scale,
|
|
456
|
-
height: this._store.state.viewportHeight / this._store.state.scale};
|
|
457
|
-
return this.boundingBox.x < viewportBounds.x + viewportBounds.width &&
|
|
458
|
-
this.boundingBox.x + this.boundingBox.width > viewportBounds.x &&
|
|
459
|
-
this.boundingBox.y < viewportBounds.y + viewportBounds.height &&
|
|
460
|
-
this.boundingBox.y + this.boundingBox.height > viewportBounds.y;
|
|
461
|
-
}
|
|
462
|
-
centerInViewport() {
|
|
463
|
-
const scale = this._store.state.scale;
|
|
464
|
-
this.translateX = (this._store.state.viewportWidth / 2 - this.totalWidth / 2 - this._store.state.translateX) / scale;
|
|
465
|
-
this.translateY = (this._store.state.viewportHeight / 2 - this.totalHeight / 2 - this._store.state.translateY) / scale;
|
|
466
|
-
}
|
|
467
|
-
move(startX, startY, endX, endY) {
|
|
468
|
-
const deltaX = (startX - endX) / this._store.state.scale;
|
|
469
|
-
const deltaY = (startY - endY) / this._store.state.scale;
|
|
470
|
-
this.translateX += deltaX;
|
|
471
|
-
this.translateY += deltaY;
|
|
472
|
-
}
|
|
473
|
-
resize(x, y, width, height) {
|
|
474
|
-
if (width <= 1 || height <= 1) {
|
|
475
|
-
return;
|
|
476
|
-
}
|
|
477
|
-
this.width = width;
|
|
478
|
-
this.height = height;
|
|
479
|
-
this.translateX = x;
|
|
480
|
-
this.translateY = y;
|
|
481
|
-
}
|
|
482
|
-
rotate(value) {
|
|
483
|
-
this.rotation = value;
|
|
484
|
-
}
|
|
485
|
-
copy() {
|
|
486
|
-
const copiedObject = Object.create(Object.getPrototypeOf(this));
|
|
487
|
-
Object.assign(copiedObject, this);
|
|
488
|
-
copiedObject.id = this.generateId();
|
|
489
|
-
copiedObject.isMounted = false;
|
|
490
|
-
return copiedObject;
|
|
491
|
-
}
|
|
492
|
-
onSelectedClick() {
|
|
493
|
-
// This method can be overridden by subclasses to handle click events when the object is selected.
|
|
494
|
-
}
|
|
495
|
-
revive(object) {
|
|
496
|
-
Object.assign(this, object);
|
|
497
|
-
return this;
|
|
498
|
-
}
|
|
499
|
-
isClass(className) {
|
|
500
|
-
return this.__class__ === className;
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
class KritzelText extends KritzelBaseObject {
|
|
505
|
-
get isReadonly() {
|
|
506
|
-
return !(this._store.state.activeTool instanceof KritzelTextTool);
|
|
507
|
-
}
|
|
508
|
-
constructor(config) {
|
|
509
|
-
super();
|
|
510
|
-
this.__class__ = 'KritzelText';
|
|
511
|
-
this.value = '';
|
|
512
|
-
this.fontFamily = 'Arial';
|
|
513
|
-
this.fontSize = 8;
|
|
514
|
-
this.fontColor = '#000000';
|
|
515
|
-
this.initialWidth = 3;
|
|
516
|
-
this.isNew = true;
|
|
517
|
-
this.debugInfoVisible = true;
|
|
518
|
-
this.rows = 1;
|
|
519
|
-
if (config) {
|
|
520
|
-
this.value = config.value || ' ';
|
|
521
|
-
this.translateX = config.translateX || 0;
|
|
522
|
-
this.translateY = config.translateY || 0;
|
|
523
|
-
this.fontSize = config.fontSize || 8;
|
|
524
|
-
this.fontFamily = config.fontFamily || 'Arial';
|
|
525
|
-
this.fontColor = config.fontColor || '#000000';
|
|
526
|
-
this.height = config.height || this.fontSize * 1.2;
|
|
527
|
-
this.width = config.width || 0;
|
|
528
|
-
this.scale = config.scale || 1;
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
static create(store, fontSize, fontFamily) {
|
|
532
|
-
const object = new KritzelText();
|
|
533
|
-
object._store = store;
|
|
534
|
-
object.fontSize = fontSize;
|
|
535
|
-
object.fontFamily = fontFamily;
|
|
536
|
-
object.translateX = 0;
|
|
537
|
-
object.translateY = 0;
|
|
538
|
-
object.width = object.initialWidth / (object._store.state.scale < 0 ? object._store.state.scale : 1);
|
|
539
|
-
object.height = (object.fontSize * 1.2) / (object._store.state.scale < 0 ? object._store.state.scale : 1);
|
|
540
|
-
object.padding = 5;
|
|
541
|
-
object.backgroundColor = 'transparent';
|
|
542
|
-
object.scale = object._store.state.scale;
|
|
543
|
-
object.value = ' ';
|
|
544
|
-
object.zIndex = store.currentZIndex;
|
|
545
|
-
return object;
|
|
546
|
-
}
|
|
547
|
-
mount(element) {
|
|
548
|
-
if ((this.isMounted && this.elementRef === element) || this.isInViewport() === false) {
|
|
549
|
-
return;
|
|
550
|
-
}
|
|
551
|
-
this.elementRef = element;
|
|
552
|
-
this.isMounted = true;
|
|
553
|
-
}
|
|
554
|
-
resize(x, y, width, height) {
|
|
555
|
-
if (width <= 1 || height <= 1) {
|
|
556
|
-
return;
|
|
557
|
-
}
|
|
558
|
-
const scaleFactor = height / this.height;
|
|
559
|
-
this.fontSize = this.fontSize * scaleFactor;
|
|
560
|
-
this.width = this.width * scaleFactor;
|
|
561
|
-
this.height = height;
|
|
562
|
-
this.translateX = x;
|
|
563
|
-
this.translateY = y;
|
|
564
|
-
}
|
|
565
|
-
handleKeyDown(event) {
|
|
566
|
-
if (this.isReadonly) {
|
|
567
|
-
event.preventDefault();
|
|
568
|
-
event.stopPropagation();
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
handleInput(event) {
|
|
572
|
-
const target = event.target;
|
|
573
|
-
if (target.value === '') {
|
|
574
|
-
this.value = ' ';
|
|
575
|
-
target.value = ' ';
|
|
576
|
-
target.selectionStart = target.selectionEnd = target.value.length;
|
|
577
|
-
}
|
|
578
|
-
else {
|
|
579
|
-
this.value = target.value.trim();
|
|
580
|
-
}
|
|
581
|
-
this.adjustTextareaSize();
|
|
582
|
-
}
|
|
583
|
-
adjustTextareaSize() {
|
|
584
|
-
if (this.elementRef) {
|
|
585
|
-
const span = document.createElement('span');
|
|
586
|
-
span.style.position = 'absolute';
|
|
587
|
-
span.style.whiteSpace = 'pre-wrap';
|
|
588
|
-
span.style.visibility = 'hidden';
|
|
589
|
-
span.style.fontSize = window.getComputedStyle(this.elementRef).fontSize;
|
|
590
|
-
span.style.fontFamily = window.getComputedStyle(this.elementRef).fontFamily;
|
|
591
|
-
span.innerHTML = this.elementRef.value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\n/g, '<br>') + '<br>';
|
|
592
|
-
document.body.appendChild(span);
|
|
593
|
-
const textWidth = span.offsetWidth;
|
|
594
|
-
const textHeight = span.offsetHeight;
|
|
595
|
-
document.body.removeChild(span);
|
|
596
|
-
this.width = textWidth;
|
|
597
|
-
this.height = textHeight;
|
|
598
|
-
this._store.rerender();
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
focus() {
|
|
602
|
-
if (this.elementRef) {
|
|
603
|
-
this.elementRef.focus();
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
selectAll() {
|
|
607
|
-
if (this.elementRef) {
|
|
608
|
-
this.elementRef.select();
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
insertFromClipboard() {
|
|
612
|
-
if (this.elementRef) {
|
|
613
|
-
this.elementRef.focus();
|
|
614
|
-
try {
|
|
615
|
-
navigator.clipboard.readText().then(text => {
|
|
616
|
-
const start = this.elementRef.selectionStart;
|
|
617
|
-
const end = this.elementRef.selectionEnd;
|
|
618
|
-
const value = this.elementRef.value;
|
|
619
|
-
this.elementRef.value = value.substring(0, start) + text + value.substring(end);
|
|
620
|
-
this.elementRef.selectionStart = this.elementRef.selectionEnd = start + text.length;
|
|
621
|
-
this.value = this.elementRef.value;
|
|
622
|
-
this.adjustTextareaSize();
|
|
623
|
-
});
|
|
624
|
-
}
|
|
625
|
-
catch (err) {
|
|
626
|
-
console.error('Failed to read clipboard contents:', err);
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
onSelectedClick() {
|
|
631
|
-
this._store.setState('activeTool', KritzelToolRegistry.getTool('text'));
|
|
632
|
-
this._store.state.selectionGroup = null;
|
|
633
|
-
this._store.state.selectionBox = null;
|
|
634
|
-
this._store.state.activeText = this;
|
|
635
|
-
setTimeout(() => {
|
|
636
|
-
this.focus();
|
|
637
|
-
}, 300);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
var cjs = {};
|
|
642
|
-
|
|
643
|
-
var hasRequiredCjs;
|
|
644
|
-
|
|
645
|
-
function requireCjs () {
|
|
646
|
-
if (hasRequiredCjs) return cjs;
|
|
647
|
-
hasRequiredCjs = 1;
|
|
648
|
-
(function (exports) {
|
|
649
|
-
var pe=Object.defineProperty;var ge=e=>pe(e,"__esModule",{value:true});var de=(e,t)=>{ge(e);for(var s in t)pe(e,s,{get:t[s],enumerable:true});};de(exports,{default:()=>ve,getStroke:()=>ne,getStrokeOutlinePoints:()=>te,getStrokePoints:()=>re});function $(e,t,s,x=h=>h){return e*x(.5-t*(.5-s))}function ce(e){return [-e[0],-e[1]]}function l(e,t){return [e[0]+t[0],e[1]+t[1]]}function a(e,t){return [e[0]-t[0],e[1]-t[1]]}function b(e,t){return [e[0]*t,e[1]*t]}function xe(e,t){return [e[0]/t,e[1]/t]}function R(e){return [e[1],-e[0]]}function B(e,t){return e[0]*t[0]+e[1]*t[1]}function me(e,t){return e[0]===t[0]&&e[1]===t[1]}function Se(e){return Math.hypot(e[0],e[1])}function Pe(e){return e[0]*e[0]+e[1]*e[1]}function A(e,t){return Pe(a(e,t))}function G(e){return xe(e,Se(e))}function ae(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function L(e,t,s){let x=Math.sin(s),h=Math.cos(s),y=e[0]-t[0],n=e[1]-t[1],f=y*h-n*x,d=y*x+n*h;return [f+t[0],d+t[1]]}function K(e,t,s){return l(e,b(a(t,e),s))}function ee(e,t,s){return l(e,b(t,s))}var{min:C,PI:ke}=Math,le=.275,V=ke+1e-4;function te(e,t={}){let{size:s=16,smoothing:x=.5,thinning:h=.5,simulatePressure:y=true,easing:n=r=>r,start:f={},end:d={},last:D=false}=t,{cap:S=true,easing:j=r=>r*(2-r)}=f,{cap:q=true,easing:c=r=>--r*r*r+1}=d;if(e.length===0||s<=0)return [];let p=e[e.length-1].runningLength,g=f.taper===false?0:f.taper===true?Math.max(s,p):f.taper,T=d.taper===false?0:d.taper===true?Math.max(s,p):d.taper,oe=Math.pow(s*x,2),_=[],M=[],H=e.slice(0,10).reduce((r,i)=>{let o=i.pressure;if(y){let u=C(1,i.distance/s),W=C(1,1-u);o=C(1,r+(W-r)*(u*le));}return (r+o)/2},e[0].pressure),m=$(s,h,e[e.length-1].pressure,n),U,X=e[0].vector,z=e[0].point,F=z,O=z,E=F,J=false;for(let r=0;r<e.length;r++){let{pressure:i}=e[r],{point:o,vector:u,distance:W,runningLength:I}=e[r];if(r<e.length-1&&p-I<3)continue;if(h){if(y){let v=C(1,W/s),Z=C(1,1-v);i=C(1,H+(Z-H)*(v*le));}m=$(s,h,i,n);}else m=s/2;U===void 0&&(U=m);let fe=I<g?j(I/g):1,be=p-I<T?c((p-I)/T):1;m=Math.max(.01,m*Math.min(fe,be));let se=(r<e.length-1?e[r+1]:e[r]).vector,Y=r<e.length-1?B(u,se):1,he=B(u,X)<0&&!J,ue=Y!==null&&Y<0;if(he||ue){let v=b(R(X),m);for(let Z=1/13,w=0;w<=1;w+=Z)O=L(a(o,v),o,V*w),_.push(O),E=L(l(o,v),o,V*-w),M.push(E);z=O,F=E,ue&&(J=true);continue}if(J=false,r===e.length-1){let v=b(R(u),m);_.push(a(o,v)),M.push(l(o,v));continue}let ie=b(R(K(se,u,Y)),m);O=a(o,ie),(r<=1||A(z,O)>oe)&&(_.push(O),z=O),E=l(o,ie),(r<=1||A(F,E)>oe)&&(M.push(E),F=E),H=i,X=u;}let P=e[0].point.slice(0,2),k=e.length>1?e[e.length-1].point.slice(0,2):l(e[0].point,[1,1]),Q=[],N=[];if(e.length===1){if(!(g||T)||D){let r=ee(P,G(R(a(P,k))),-(U||m)),i=[];for(let o=1/13,u=o;u<=1;u+=o)i.push(L(r,P,V*2*u));return i}}else {if(!(g||T&&e.length===1))if(S)for(let i=1/13,o=i;o<=1;o+=i){let u=L(M[0],P,V*o);Q.push(u);}else {let i=a(_[0],M[0]),o=b(i,.5),u=b(i,.51);Q.push(a(P,o),a(P,u),l(P,u),l(P,o));}let r=R(ce(e[e.length-1].vector));if(T||g&&e.length===1)N.push(k);else if(q){let i=ee(k,r,m);for(let o=1/29,u=o;u<1;u+=o)N.push(L(i,k,V*3*u));}else N.push(l(k,b(r,m)),l(k,b(r,m*.99)),a(k,b(r,m*.99)),a(k,b(r,m)));}return _.concat(N,M.reverse(),Q)}function re(e,t={}){var q;let{streamline:s=.5,size:x=16,last:h=false}=t;if(e.length===0)return [];let y=.15+(1-s)*.85,n=Array.isArray(e[0])?e:e.map(({x:c,y:p,pressure:g=.5})=>[c,p,g]);if(n.length===2){let c=n[1];n=n.slice(0,-1);for(let p=1;p<5;p++)n.push(K(n[0],c,p/4));}n.length===1&&(n=[...n,[...l(n[0],[1,1]),...n[0].slice(2)]]);let f=[{point:[n[0][0],n[0][1]],pressure:n[0][2]>=0?n[0][2]:.25,vector:[1,1],distance:0,runningLength:0}],d=false,D=0,S=f[0],j=n.length-1;for(let c=1;c<n.length;c++){let p=h&&c===j?n[c].slice(0,2):K(S.point,n[c],y);if(me(S.point,p))continue;let g=ae(p,S.point);if(D+=g,c<j&&!d){if(D<x)continue;d=true;}S={point:p,pressure:n[c][2]>=0?n[c][2]:.5,vector:G(a(S.point,p)),distance:g,runningLength:D},f.push(S);}return f[0].vector=((q=f[1])==null?void 0:q.vector)||[0,0],f}function ne(e,t={}){return te(re(e,t),t)}var ve=ne;
|
|
650
|
-
} (cjs));
|
|
651
|
-
return cjs;
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
var cjsExports = requireCjs();
|
|
655
|
-
|
|
656
|
-
class KritzelMathHelper {
|
|
657
|
-
static average(a, b) {
|
|
658
|
-
return (a + b) / 2;
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
class KritzelPath extends KritzelBaseObject {
|
|
663
|
-
constructor() {
|
|
664
|
-
super(...arguments);
|
|
665
|
-
this.__class__ = 'KritzelPath';
|
|
666
|
-
this.stroke = 'none';
|
|
667
|
-
this.lineSlack = 0.5;
|
|
668
|
-
this.x = 0;
|
|
669
|
-
this.y = 0;
|
|
670
|
-
this.height = 0;
|
|
671
|
-
this.width = 0;
|
|
672
|
-
this.scale = 1;
|
|
673
|
-
this.visible = true;
|
|
674
|
-
this.debugInfoVisible = true;
|
|
675
|
-
}
|
|
676
|
-
get viewBox() {
|
|
677
|
-
return `${this.x} ${this.y} ${this.width} ${this.height}`;
|
|
678
|
-
}
|
|
679
|
-
static create(store, options) {
|
|
680
|
-
var _a, _b, _c, _d, _e, _f;
|
|
681
|
-
const object = new KritzelPath();
|
|
682
|
-
object._store = store;
|
|
683
|
-
object.id = object.generateId();
|
|
684
|
-
object.options = options;
|
|
685
|
-
object.points = (_a = options === null || options === void 0 ? void 0 : options.points) !== null && _a !== void 0 ? _a : [];
|
|
686
|
-
object.translateX = (_b = options === null || options === void 0 ? void 0 : options.translateX) !== null && _b !== void 0 ? _b : 0;
|
|
687
|
-
object.translateY = (_c = options === null || options === void 0 ? void 0 : options.translateY) !== null && _c !== void 0 ? _c : 0;
|
|
688
|
-
object.scale = (_d = options === null || options === void 0 ? void 0 : options.scale) !== null && _d !== void 0 ? _d : 1;
|
|
689
|
-
object.strokeWidth = (_e = options === null || options === void 0 ? void 0 : options.strokeWidth) !== null && _e !== void 0 ? _e : 8;
|
|
690
|
-
object.fill = (_f = options === null || options === void 0 ? void 0 : options.fill) !== null && _f !== void 0 ? _f : '#000000';
|
|
691
|
-
object.zIndex = store.currentZIndex;
|
|
692
|
-
object.d = object.generateSvgPath();
|
|
693
|
-
object.updateDimensions();
|
|
694
|
-
return object;
|
|
695
|
-
}
|
|
696
|
-
resize(x, y, width, height) {
|
|
697
|
-
if (width <= 1 || height <= 1) {
|
|
698
|
-
return;
|
|
699
|
-
}
|
|
700
|
-
const scaleX = width / this.width;
|
|
701
|
-
const scaleY = height / this.height;
|
|
702
|
-
this.width = width;
|
|
703
|
-
this.height = height;
|
|
704
|
-
this.points = this.points.map(([x, y]) => [x * scaleX, y * scaleY]);
|
|
705
|
-
this.d = this.generateSvgPath();
|
|
706
|
-
this.width = Math.max(...this.points.map(p => p[0])) - Math.min(...this.points.map(p => p[0])) + this.strokeWidth;
|
|
707
|
-
this.height = Math.max(...this.points.map(p => p[1])) - Math.min(...this.points.map(p => p[1])) + this.strokeWidth;
|
|
708
|
-
this.x = Math.min(...this.points.map(p => p[0])) - this.strokeWidth / 2;
|
|
709
|
-
this.y = Math.min(...this.points.map(p => p[1])) - this.strokeWidth / 2;
|
|
710
|
-
this.translateX = x;
|
|
711
|
-
this.translateY = y;
|
|
712
|
-
}
|
|
713
|
-
rotate(value) {
|
|
714
|
-
super.rotate(value);
|
|
715
|
-
this.updateDimensions();
|
|
716
|
-
}
|
|
717
|
-
updateDimensions() {
|
|
718
|
-
const rotatedPoints = this.points.map(([x, y]) => {
|
|
719
|
-
const rotatedX = x * Math.cos(this.rotation) - y * Math.sin(this.rotation);
|
|
720
|
-
const rotatedY = x * Math.sin(this.rotation) + y * Math.cos(this.rotation);
|
|
721
|
-
return [rotatedX, rotatedY];
|
|
722
|
-
});
|
|
723
|
-
const minX = Math.min(...rotatedPoints.map(p => p[0] - this.strokeWidth / 2));
|
|
724
|
-
const minY = Math.min(...rotatedPoints.map(p => p[1] - this.strokeWidth / 2));
|
|
725
|
-
const maxX = Math.max(...rotatedPoints.map(p => p[0] + this.strokeWidth / 2));
|
|
726
|
-
const maxY = Math.max(...rotatedPoints.map(p => p[1] + this.strokeWidth / 2));
|
|
727
|
-
this.width = maxX - minX + this.lineSlack;
|
|
728
|
-
this.height = maxY - minY + this.lineSlack;
|
|
729
|
-
this.x = minX;
|
|
730
|
-
this.y = minY;
|
|
731
|
-
this.translateX = (this.x + this.translateX) / this.scale;
|
|
732
|
-
this.translateY = (this.y + this.translateY) / this.scale;
|
|
733
|
-
}
|
|
734
|
-
generateSvgPath() {
|
|
735
|
-
const stroke = this.getStrokeFromPoints(this.points, this.strokeWidth);
|
|
736
|
-
return this.getSvgPathFromStroke(stroke);
|
|
737
|
-
}
|
|
738
|
-
getStrokeFromPoints(points, strokeWidth) {
|
|
739
|
-
return cjsExports.getStroke(points, {
|
|
740
|
-
size: strokeWidth,
|
|
741
|
-
thinning: 0.5,
|
|
742
|
-
smoothing: 0.5,
|
|
743
|
-
streamline: 0.5,
|
|
744
|
-
easing: t => t,
|
|
745
|
-
simulatePressure: true,
|
|
746
|
-
last: true,
|
|
747
|
-
start: {
|
|
748
|
-
cap: true,
|
|
749
|
-
taper: 0,
|
|
750
|
-
easing: t => t,
|
|
751
|
-
},
|
|
752
|
-
end: {
|
|
753
|
-
cap: true,
|
|
754
|
-
taper: 0,
|
|
755
|
-
easing: t => t,
|
|
756
|
-
},
|
|
757
|
-
});
|
|
758
|
-
}
|
|
759
|
-
getSvgPathFromStroke(points, closed = true) {
|
|
760
|
-
const len = points.length;
|
|
761
|
-
if (len < 4) {
|
|
762
|
-
return ``;
|
|
763
|
-
}
|
|
764
|
-
let a = points[0];
|
|
765
|
-
let b = points[1];
|
|
766
|
-
const c = points[2];
|
|
767
|
-
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`;
|
|
768
|
-
for (let i = 2, max = len - 1; i < max; i++) {
|
|
769
|
-
a = points[i];
|
|
770
|
-
b = points[i + 1];
|
|
771
|
-
result += `${KritzelMathHelper.average(a[0], b[0]).toFixed(2)},${KritzelMathHelper.average(a[1], b[1]).toFixed(2)} `;
|
|
772
|
-
}
|
|
773
|
-
if (closed) {
|
|
774
|
-
result += 'Z';
|
|
775
|
-
}
|
|
776
|
-
return result;
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
class KritzelImage extends KritzelBaseObject {
|
|
781
|
-
constructor() {
|
|
782
|
-
super(...arguments);
|
|
783
|
-
this.__class__ = 'KritzelImage';
|
|
784
|
-
this.src = '';
|
|
785
|
-
this.debugInfoVisible = true;
|
|
786
|
-
}
|
|
787
|
-
static create(store) {
|
|
788
|
-
const object = new KritzelImage();
|
|
789
|
-
object._store = store;
|
|
790
|
-
object.id = object.generateId();
|
|
791
|
-
object.x = 0;
|
|
792
|
-
object.y = 0;
|
|
793
|
-
object.translateX = 0;
|
|
794
|
-
object.translateY = 0;
|
|
795
|
-
object.scale = object._store.state.scale;
|
|
796
|
-
object.zIndex = store.currentZIndex;
|
|
797
|
-
return object;
|
|
798
|
-
}
|
|
799
|
-
resize(x, y, width, height) {
|
|
800
|
-
if (width <= 1 || height <= 1) {
|
|
801
|
-
return;
|
|
802
|
-
}
|
|
803
|
-
const scaleFactor = height / this.height;
|
|
804
|
-
this.width = this.width * scaleFactor;
|
|
805
|
-
this.height = this.height * scaleFactor;
|
|
806
|
-
this.translateX = x;
|
|
807
|
-
this.translateY = y;
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
export { AddObjectCommand as A, KritzelBaseTool as K, ObjectHelper as O, KritzelEventHelper as a, KritzelPath as b, KritzelTextTool as c, KritzelMouseButton as d, KritzelBaseCommand as e, KritzelBaseObject as f, KritzelImage as g, KritzelText as h, KritzelToolRegistry as i, KritzelKeyboardHelper as j };
|
|
812
|
-
//# sourceMappingURL=index-Dn7aP72S.js.map
|
|
813
|
-
|
|
814
|
-
//# sourceMappingURL=index-Dn7aP72S.js.map
|