kritzel-stencil 0.0.112 → 0.0.114
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/app-globals-V2Kpy_OQ.js +8 -0
- package/dist/cjs/app-globals-V2Kpy_OQ.js.map +1 -0
- package/dist/cjs/index-C2M4eyxF.js +652 -0
- package/dist/cjs/index-C2M4eyxF.js.map +1 -0
- package/dist/cjs/{index-D62tBCuq.js → index-CXT94beA.js} +111 -109
- package/dist/cjs/index-CXT94beA.js.map +1 -0
- package/dist/cjs/index.cjs.js +5 -0
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/cjs/kritzel-brush-style_18.cjs.entry.js +131 -734
- package/dist/cjs/kritzel-brush-style_18.cjs.entry.js.map +1 -1
- package/dist/cjs/loader.cjs.js +4 -3
- package/dist/cjs/loader.cjs.js.map +1 -1
- package/dist/cjs/stencil.cjs.js +5 -4
- package/dist/cjs/stencil.cjs.js.map +1 -1
- package/dist/collection/classes/handlers/key.handler.js +8 -5
- package/dist/collection/classes/handlers/key.handler.js.map +1 -1
- package/dist/collection/classes/store.class.js +12 -8
- package/dist/collection/classes/store.class.js.map +1 -1
- package/dist/collection/collection-manifest.json +1 -1
- package/dist/collection/components/core/kritzel-editor/kritzel-editor.js +217 -4
- package/dist/collection/components/core/kritzel-editor/kritzel-editor.js.map +1 -1
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +96 -20
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.js.map +1 -1
- package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js +4 -5
- package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js.map +1 -1
- package/dist/collection/index.js +10 -1
- package/dist/collection/index.js.map +1 -1
- package/dist/components/index.js +2 -1
- package/dist/components/index.js.map +1 -1
- 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 +52 -24
- 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-CmckGlXt.js → p-B57pFHwJ.js} +3 -3
- package/dist/components/{p-CmckGlXt.js.map → p-B57pFHwJ.js.map} +1 -1
- package/dist/components/{p-Ddfewfv9.js → p-B94Na1ee.js} +4 -4
- package/dist/components/{p-Ddfewfv9.js.map → p-B94Na1ee.js.map} +1 -1
- package/dist/components/{p-Ck2d5Wd1.js → p-BH1Tkwyh.js} +5 -5
- package/dist/components/{p-Ck2d5Wd1.js.map → p-BH1Tkwyh.js.map} +1 -1
- package/dist/components/{p-DqZOaMbq.js → p-BIlVkMTU.js} +378 -378
- package/dist/components/p-BIlVkMTU.js.map +1 -0
- package/dist/components/{p-BXJ8s30N.js → p-BtjtAfGW.js} +10 -10
- package/dist/components/{p-BXJ8s30N.js.map → p-BtjtAfGW.js.map} +1 -1
- package/dist/components/{p-DInF8Iby.js → p-C9FTWNZY.js} +3 -3
- package/dist/components/{p-DInF8Iby.js.map → p-C9FTWNZY.js.map} +1 -1
- package/dist/components/{p-B7P9QBiE.js → p-C9ZagG9K.js} +4 -4
- package/dist/components/{p-B7P9QBiE.js.map → p-C9ZagG9K.js.map} +1 -1
- package/dist/components/{p-BmAloSfd.js → p-CRiUM-tD.js} +4 -4
- package/dist/components/{p-BmAloSfd.js.map → p-CRiUM-tD.js.map} +1 -1
- package/dist/components/{p-BvPTbq7F.js → p-CSSrNLad.js} +3 -3
- package/dist/components/{p-BvPTbq7F.js.map → p-CSSrNLad.js.map} +1 -1
- package/dist/components/{p-DFhbw-Fr.js → p-CaQ7Iei7.js} +3 -3
- package/dist/components/{p-DFhbw-Fr.js.map → p-CaQ7Iei7.js.map} +1 -1
- package/dist/components/{p-CPjl7Inl.js → p-D04aTZsR.js} +4 -4
- package/dist/components/{p-CPjl7Inl.js.map → p-D04aTZsR.js.map} +1 -1
- package/dist/components/{p-maiDeBe9.js → p-DLV-5gE_.js} +9 -9
- package/dist/components/{p-maiDeBe9.js.map → p-DLV-5gE_.js.map} +1 -1
- package/dist/components/{p-DC8SDK2U.js → p-DoQOtXjT.js} +111 -107
- package/dist/components/p-DoQOtXjT.js.map +1 -0
- package/dist/components/{p--2WHhuBI.js → p-aZgXbW1r.js} +51 -36
- package/dist/components/{p--2WHhuBI.js.map → p-aZgXbW1r.js.map} +1 -1
- package/dist/components/{p-DfMdBA8L.js → p-fmNiA3Yr.js} +4 -4
- package/dist/components/{p-DfMdBA8L.js.map → p-fmNiA3Yr.js.map} +1 -1
- package/dist/components/{p-c6tIpE_t.js → p-h3bqYufZ.js} +3 -3
- package/dist/components/{p-c6tIpE_t.js.map → p-h3bqYufZ.js.map} +1 -1
- package/dist/components/{p-CZkSABuJ.js → p-ksTCzgsY.js} +3 -3
- package/dist/components/{p-CZkSABuJ.js.map → p-ksTCzgsY.js.map} +1 -1
- package/dist/components/{p-BnsTGnvc.js → p-mz1ayKXG.js} +21 -22
- package/dist/components/p-mz1ayKXG.js.map +1 -0
- package/dist/components/{p-DHT5gK0E.js → p-yBnfPxIa.js} +4 -4
- package/dist/components/{p-DHT5gK0E.js.map → p-yBnfPxIa.js.map} +1 -1
- package/dist/esm/app-globals-DQuL1Twl.js +6 -0
- package/dist/esm/app-globals-DQuL1Twl.js.map +1 -0
- package/dist/esm/{index-BOJOOWaP.js → index-CGHvfMWF.js} +112 -109
- package/dist/esm/index-CGHvfMWF.js.map +1 -0
- package/dist/esm/index-rckCSz7Y.js +641 -0
- package/dist/esm/index-rckCSz7Y.js.map +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/kritzel-brush-style_18.entry.js +73 -676
- package/dist/esm/kritzel-brush-style_18.entry.js.map +1 -1
- package/dist/esm/loader.js +4 -3
- package/dist/esm/loader.js.map +1 -1
- package/dist/esm/stencil.js +5 -4
- package/dist/esm/stencil.js.map +1 -1
- package/dist/stencil/index.esm.js +1 -1
- package/dist/stencil/loader.esm.js.map +1 -1
- package/dist/stencil/p-9394d74e.entry.js +2 -0
- package/dist/stencil/p-9394d74e.entry.js.map +1 -0
- package/dist/stencil/p-CGHvfMWF.js +3 -0
- package/dist/stencil/p-CGHvfMWF.js.map +1 -0
- package/dist/stencil/p-DQuL1Twl.js +2 -0
- package/dist/stencil/p-DQuL1Twl.js.map +1 -0
- package/dist/stencil/p-rckCSz7Y.js +2 -0
- package/dist/stencil/p-rckCSz7Y.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/store.class.d.ts +4 -4
- package/dist/types/components/core/kritzel-editor/kritzel-editor.d.ts +10 -2
- package/dist/types/components/core/kritzel-engine/kritzel-engine.d.ts +4 -2
- package/dist/types/components.d.ts +13 -4
- package/dist/types/index.d.ts +1 -0
- package/dist/types/stencil-public-runtime.d.ts +12 -5
- package/package.json +1 -1
- package/dist/cjs/index-D62tBCuq.js.map +0 -1
- package/dist/components/p-BnsTGnvc.js.map +0 -1
- package/dist/components/p-DC8SDK2U.js.map +0 -1
- package/dist/components/p-DqZOaMbq.js.map +0 -1
- package/dist/esm/index-BOJOOWaP.js.map +0 -1
- package/dist/stencil/p-65e86254.entry.js +0 -2
- package/dist/stencil/p-65e86254.entry.js.map +0 -1
- package/dist/stencil/p-BOJOOWaP.js +0 -3
- package/dist/stencil/p-BOJOOWaP.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-globals-V2Kpy_OQ.js","sources":["@stencil/core/internal/app-globals"],"sourcesContent":["export const globalScripts = () => {};\nexport const globalStyles = \"\";\n"],"names":[],"mappings":";;AAAY,MAAC,aAAa,GAAG,MAAM;;;;"}
|
|
@@ -0,0 +1,652 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
class KritzelToolRegistry {
|
|
4
|
+
static registerTool(toolName, constructor, store) {
|
|
5
|
+
const toolInstance = new constructor(store);
|
|
6
|
+
toolInstance.name = toolName;
|
|
7
|
+
this.registry[toolName] = toolInstance;
|
|
8
|
+
return toolInstance;
|
|
9
|
+
}
|
|
10
|
+
static getTool(toolName) {
|
|
11
|
+
const toolInstance = this.registry[toolName];
|
|
12
|
+
if (!toolInstance) {
|
|
13
|
+
console.warn(`Unknown tool: ${toolName}`);
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return toolInstance;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
KritzelToolRegistry.registry = {};
|
|
20
|
+
|
|
21
|
+
class KritzelBaseTool {
|
|
22
|
+
constructor(store) {
|
|
23
|
+
this.__class__ = this.constructor.name;
|
|
24
|
+
this.name = 'base-tool';
|
|
25
|
+
this._store = store;
|
|
26
|
+
}
|
|
27
|
+
onActivate() {
|
|
28
|
+
// default implementation
|
|
29
|
+
}
|
|
30
|
+
onDeactivate() {
|
|
31
|
+
// default implementation
|
|
32
|
+
}
|
|
33
|
+
handlePointerDown(_event) {
|
|
34
|
+
// default implementation
|
|
35
|
+
}
|
|
36
|
+
handlePointerMove(_event) {
|
|
37
|
+
// default implementation
|
|
38
|
+
}
|
|
39
|
+
handlePointerUp(_event) {
|
|
40
|
+
// default implementation
|
|
41
|
+
}
|
|
42
|
+
handleWheel(_event) {
|
|
43
|
+
// default implementation
|
|
44
|
+
}
|
|
45
|
+
revive(object) {
|
|
46
|
+
Object.assign(this, object);
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
class KritzelBaseCommand {
|
|
52
|
+
constructor(store, initiator) {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
this._store = store;
|
|
55
|
+
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';
|
|
56
|
+
this.isUndoable = true;
|
|
57
|
+
}
|
|
58
|
+
execute() {
|
|
59
|
+
throw new Error('Method not implemented.');
|
|
60
|
+
}
|
|
61
|
+
undo() {
|
|
62
|
+
throw new Error('Method not implemented.');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
class AddObjectCommand extends KritzelBaseCommand {
|
|
67
|
+
constructor(store, initiator, object) {
|
|
68
|
+
super(store, initiator);
|
|
69
|
+
this.object = object;
|
|
70
|
+
}
|
|
71
|
+
execute() {
|
|
72
|
+
this._store.state.objectsOctree.insert(this.object);
|
|
73
|
+
}
|
|
74
|
+
undo() {
|
|
75
|
+
this._store.state.objectsOctree.remove(object => object.id === this.object.id);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
exports.KritzelMouseButton = void 0;
|
|
80
|
+
(function (KritzelMouseButton) {
|
|
81
|
+
KritzelMouseButton[KritzelMouseButton["Left"] = 0] = "Left";
|
|
82
|
+
KritzelMouseButton[KritzelMouseButton["Middle"] = 1] = "Middle";
|
|
83
|
+
KritzelMouseButton[KritzelMouseButton["Right"] = 2] = "Right";
|
|
84
|
+
})(exports.KritzelMouseButton || (exports.KritzelMouseButton = {}));
|
|
85
|
+
|
|
86
|
+
class KritzelEventHelper {
|
|
87
|
+
static isRightClick(ev) {
|
|
88
|
+
return ev.button === exports.KritzelMouseButton.Right;
|
|
89
|
+
}
|
|
90
|
+
static isLeftClick(ev) {
|
|
91
|
+
return ev.button === exports.KritzelMouseButton.Left;
|
|
92
|
+
}
|
|
93
|
+
static isMainMouseWheel(event) {
|
|
94
|
+
return Math.abs(event.deltaY) > 0 && Math.abs(event.deltaX) === 0 && Number.isInteger(event.deltaY);
|
|
95
|
+
}
|
|
96
|
+
static isPointerEventOnContextMenu(event) {
|
|
97
|
+
const path = event.composedPath();
|
|
98
|
+
const contextMenu = path.find(element => element.classList && element.classList.contains('context-menu'));
|
|
99
|
+
return !!contextMenu;
|
|
100
|
+
}
|
|
101
|
+
static onLongTouchPress(event, onSuccess, onCancel) {
|
|
102
|
+
if (event.pointerType !== 'touch') {
|
|
103
|
+
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
104
|
+
return () => { };
|
|
105
|
+
}
|
|
106
|
+
const longPressTimeout = 400;
|
|
107
|
+
const moveThreshold = 10;
|
|
108
|
+
const startX = event.clientX;
|
|
109
|
+
const startY = event.clientY;
|
|
110
|
+
const target = event.target;
|
|
111
|
+
const timer = setTimeout(() => {
|
|
112
|
+
removeListeners();
|
|
113
|
+
onSuccess(event);
|
|
114
|
+
}, longPressTimeout);
|
|
115
|
+
const cancel = () => {
|
|
116
|
+
clearTimeout(timer);
|
|
117
|
+
removeListeners();
|
|
118
|
+
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
119
|
+
};
|
|
120
|
+
const onPointerMove = (e) => {
|
|
121
|
+
if (Math.abs(e.clientX - startX) > moveThreshold || Math.abs(e.clientY - startY) > moveThreshold) {
|
|
122
|
+
cancel();
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
const onPointerUp = () => {
|
|
126
|
+
cancel();
|
|
127
|
+
};
|
|
128
|
+
const onPointerCancel = () => {
|
|
129
|
+
cancel();
|
|
130
|
+
};
|
|
131
|
+
const removeListeners = () => {
|
|
132
|
+
target.removeEventListener('pointermove', onPointerMove);
|
|
133
|
+
target.removeEventListener('pointerup', onPointerUp);
|
|
134
|
+
target.removeEventListener('pointercancel', onPointerCancel);
|
|
135
|
+
};
|
|
136
|
+
target.addEventListener('pointermove', onPointerMove, { passive: true });
|
|
137
|
+
target.addEventListener('pointerup', onPointerUp, { once: true });
|
|
138
|
+
target.addEventListener('pointercancel', onPointerCancel, { once: true });
|
|
139
|
+
return cancel;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
class KritzelKeyboardHelper {
|
|
144
|
+
static forceHideKeyboard() {
|
|
145
|
+
if (document.activeElement instanceof HTMLElement) {
|
|
146
|
+
document.activeElement.blur();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
static enableInteractiveWidget() {
|
|
150
|
+
const meta = document.querySelector('meta[name="viewport"][content*="interactive-widget=resizes-content"]');
|
|
151
|
+
if (meta) {
|
|
152
|
+
let currentContent = meta.getAttribute('content');
|
|
153
|
+
if (!currentContent.includes('interactive-widget=resizes-content')) {
|
|
154
|
+
currentContent += ', interactive-widget=resizes-content';
|
|
155
|
+
}
|
|
156
|
+
meta.setAttribute('content', currentContent);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
static disableInteractiveWidget() {
|
|
160
|
+
const meta = document.querySelector('meta[name="viewport"][content*="interactive-widget=resizes-content"]');
|
|
161
|
+
if (meta) {
|
|
162
|
+
let currentContent = meta.getAttribute('content');
|
|
163
|
+
let newContent = currentContent.replace(/\s*interactive-widget=resizes-content\s*[,;]?/g, '');
|
|
164
|
+
newContent = newContent
|
|
165
|
+
.replace(/,(\s*,)+/g, ',')
|
|
166
|
+
.replace(/^,/, '')
|
|
167
|
+
.replace(/,$/, '')
|
|
168
|
+
.trim();
|
|
169
|
+
meta.setAttribute('content', newContent);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
class KritzelTextTool extends KritzelBaseTool {
|
|
175
|
+
constructor(store) {
|
|
176
|
+
super(store);
|
|
177
|
+
this.fontFamily = 'Arial';
|
|
178
|
+
this.fontSize = 16;
|
|
179
|
+
this.fontColor = '#000000';
|
|
180
|
+
this.palette = [
|
|
181
|
+
'#000000',
|
|
182
|
+
'#FFFFFF',
|
|
183
|
+
'#FF0000',
|
|
184
|
+
'#00FF00',
|
|
185
|
+
'#0000FF',
|
|
186
|
+
'#FFFF00',
|
|
187
|
+
'#FF00FF',
|
|
188
|
+
'#00FFFF',
|
|
189
|
+
'#808080',
|
|
190
|
+
'#C0C0C0',
|
|
191
|
+
'#800000',
|
|
192
|
+
'#008000',
|
|
193
|
+
'#000080',
|
|
194
|
+
'#808000',
|
|
195
|
+
'#800080',
|
|
196
|
+
];
|
|
197
|
+
}
|
|
198
|
+
handlePointerDown(event) {
|
|
199
|
+
if (event.cancelable) {
|
|
200
|
+
event.preventDefault();
|
|
201
|
+
}
|
|
202
|
+
if (event.pointerType === 'mouse') {
|
|
203
|
+
const path = event.composedPath().slice(1);
|
|
204
|
+
const objectElement = path.find(element => element.classList && element.classList.contains('object'));
|
|
205
|
+
const object = this._store.findObjectById(objectElement === null || objectElement === void 0 ? void 0 : objectElement.id);
|
|
206
|
+
if (this._store.state.activeText === null && object && object instanceof KritzelText) {
|
|
207
|
+
this._store.state.activeText = object;
|
|
208
|
+
object.focus();
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (this._store.state.activeText !== null && object instanceof KritzelText) {
|
|
212
|
+
object.focus();
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (this._store.state.activeText !== null) {
|
|
216
|
+
this._store.resetActiveText();
|
|
217
|
+
this._store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (KritzelEventHelper.isLeftClick(event) === false) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
const clientX = event.clientX - this._store.offsetX;
|
|
224
|
+
const clientY = event.clientY - this._store.offsetY;
|
|
225
|
+
const text = KritzelText.create(this._store, this.fontSize, this.fontFamily);
|
|
226
|
+
text.fontColor = this.fontColor;
|
|
227
|
+
text.translateX = (clientX - this._store.state.translateX) / this._store.state.scale;
|
|
228
|
+
text.translateY = (clientY - this._store.state.translateY) / this._store.state.scale;
|
|
229
|
+
text.zIndex = this._store.currentZIndex;
|
|
230
|
+
this._store.state.activeText = text;
|
|
231
|
+
this._store.history.executeCommand(new AddObjectCommand(this._store, this, text));
|
|
232
|
+
}
|
|
233
|
+
if (event.pointerType === 'touch') {
|
|
234
|
+
const activePointers = Array.from(this._store.state.pointers.values());
|
|
235
|
+
const path = event.composedPath().slice(1);
|
|
236
|
+
const objectElement = path.find(element => element.classList && element.classList.contains('object'));
|
|
237
|
+
const object = this._store.findObjectById(objectElement === null || objectElement === void 0 ? void 0 : objectElement.id);
|
|
238
|
+
if (this._store.state.activeText === null && object && object instanceof KritzelText) {
|
|
239
|
+
this._store.state.activeText = object;
|
|
240
|
+
object.focus();
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (this._store.state.activeText !== null && object instanceof KritzelText) {
|
|
244
|
+
object.focus();
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
if (this._store.state.activeText !== null) {
|
|
248
|
+
this._store.resetActiveText();
|
|
249
|
+
this._store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if (activePointers.length > 1) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
KritzelKeyboardHelper.disableInteractiveWidget();
|
|
256
|
+
const clientX = Math.round(activePointers[0].clientX - this._store.offsetX);
|
|
257
|
+
const clientY = Math.round(activePointers[0].clientY - this._store.offsetY);
|
|
258
|
+
const text = KritzelText.create(this._store, this.fontSize, this.fontFamily);
|
|
259
|
+
text.fontColor = this.fontColor;
|
|
260
|
+
text.translateX = (clientX - this._store.state.translateX) / this._store.state.scale;
|
|
261
|
+
text.translateY = (clientY - this._store.state.translateY) / this._store.state.scale;
|
|
262
|
+
text.zIndex = this._store.currentZIndex;
|
|
263
|
+
this._store.state.activeText = text;
|
|
264
|
+
this._store.history.executeCommand(new AddObjectCommand(this._store, this, text));
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
handlePointerUp(event) {
|
|
268
|
+
var _a, _b, _c, _d;
|
|
269
|
+
if (event.cancelable) {
|
|
270
|
+
event.preventDefault();
|
|
271
|
+
}
|
|
272
|
+
if (event.pointerType === 'mouse') {
|
|
273
|
+
(_a = this._store.state.activeText) === null || _a === void 0 ? void 0 : _a.adjustTextareaSize();
|
|
274
|
+
(_b = this._store.state.activeText) === null || _b === void 0 ? void 0 : _b.focus();
|
|
275
|
+
}
|
|
276
|
+
if (event.pointerType === 'touch') {
|
|
277
|
+
(_c = this._store.state.activeText) === null || _c === void 0 ? void 0 : _c.adjustTextareaSize();
|
|
278
|
+
(_d = this._store.state.activeText) === null || _d === void 0 ? void 0 : _d.focus();
|
|
279
|
+
KritzelKeyboardHelper.enableInteractiveWidget();
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
var __rest = (undefined && undefined.__rest) || function (s, e) {
|
|
285
|
+
var t = {};
|
|
286
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
287
|
+
t[p] = s[p];
|
|
288
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
289
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
290
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
291
|
+
t[p[i]] = s[p[i]];
|
|
292
|
+
}
|
|
293
|
+
return t;
|
|
294
|
+
};
|
|
295
|
+
class ObjectHelper {
|
|
296
|
+
static generateUUID() {
|
|
297
|
+
return Math.random().toString(36).substr(2, 9);
|
|
298
|
+
}
|
|
299
|
+
static clone(objOrObjs) {
|
|
300
|
+
const cloneObject = (obj) => {
|
|
301
|
+
const remainingProps = __rest(obj, ["_store", "_elementRef", "totalWidth", "totalHeight"]);
|
|
302
|
+
return structuredClone(remainingProps);
|
|
303
|
+
};
|
|
304
|
+
if (Array.isArray(objOrObjs)) {
|
|
305
|
+
return objOrObjs.map(cloneObject);
|
|
306
|
+
}
|
|
307
|
+
return cloneObject(objOrObjs);
|
|
308
|
+
}
|
|
309
|
+
static isEmpty(obj) {
|
|
310
|
+
if (obj === null || obj === undefined) {
|
|
311
|
+
return true;
|
|
312
|
+
}
|
|
313
|
+
return (Object === null || Object === void 0 ? void 0 : Object.keys(obj).length) === 0 && (obj === null || obj === void 0 ? void 0 : obj.constructor) === Object;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
class KritzelBaseObject {
|
|
318
|
+
get totalWidth() {
|
|
319
|
+
return this.width + this.padding * 2;
|
|
320
|
+
}
|
|
321
|
+
get totalHeight() {
|
|
322
|
+
return this.height + this.padding * 2;
|
|
323
|
+
}
|
|
324
|
+
set elementRef(element) {
|
|
325
|
+
this._elementRef = element;
|
|
326
|
+
}
|
|
327
|
+
get elementRef() {
|
|
328
|
+
return this._elementRef;
|
|
329
|
+
}
|
|
330
|
+
get boundingBox() {
|
|
331
|
+
return {
|
|
332
|
+
x: this.translateX,
|
|
333
|
+
y: this.translateY,
|
|
334
|
+
z: this.scale,
|
|
335
|
+
width: this.totalWidth / this.scale,
|
|
336
|
+
height: this.totalHeight / this.scale,
|
|
337
|
+
depth: 0,
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
get rotatedBoundingBox() {
|
|
341
|
+
return {
|
|
342
|
+
x: this.minXRotated,
|
|
343
|
+
y: this.minYRotated,
|
|
344
|
+
z: this.scale,
|
|
345
|
+
width: this.maxXRotated - this.minXRotated,
|
|
346
|
+
height: this.maxYRotated - this.minYRotated,
|
|
347
|
+
depth: 0,
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
get rotatedPolygon() {
|
|
351
|
+
const cx = (this.translateX + this.totalWidth / 2 / this.scale);
|
|
352
|
+
const cy = (this.translateY + this.totalHeight / 2 / this.scale);
|
|
353
|
+
const angle = this.rotation;
|
|
354
|
+
const adjustedWidth = this.totalWidth / this.scale;
|
|
355
|
+
const adjustedHeight = this.totalHeight / this.scale;
|
|
356
|
+
const corners = {
|
|
357
|
+
topLeft: { x: this.translateX, y: this.translateY },
|
|
358
|
+
topRight: { x: this.translateX + adjustedWidth, y: this.translateY },
|
|
359
|
+
bottomRight: { x: this.translateX + adjustedWidth, y: this.translateY + adjustedHeight },
|
|
360
|
+
bottomLeft: { x: this.translateX, y: this.translateY + adjustedHeight },
|
|
361
|
+
};
|
|
362
|
+
const rotatedCorners = Object.keys(corners).reduce((acc, key) => {
|
|
363
|
+
const corner = corners[key];
|
|
364
|
+
const rotatedX = Math.cos(angle) * (corner.x - cx) - Math.sin(angle) * (corner.y - cy) + cx;
|
|
365
|
+
const rotatedY = Math.sin(angle) * (corner.x - cx) + Math.cos(angle) * (corner.y - cy) + cy;
|
|
366
|
+
acc[key] = { x: rotatedX, y: rotatedY };
|
|
367
|
+
return acc;
|
|
368
|
+
}, {});
|
|
369
|
+
return rotatedCorners;
|
|
370
|
+
}
|
|
371
|
+
get minXRotated() {
|
|
372
|
+
const corners = [
|
|
373
|
+
this.rotatedPolygon.topLeft.x,
|
|
374
|
+
this.rotatedPolygon.topRight.x,
|
|
375
|
+
this.rotatedPolygon.bottomRight.x,
|
|
376
|
+
this.rotatedPolygon.bottomLeft.x,
|
|
377
|
+
];
|
|
378
|
+
return Math.min(...corners);
|
|
379
|
+
}
|
|
380
|
+
get minYRotated() {
|
|
381
|
+
const corners = [
|
|
382
|
+
this.rotatedPolygon.topLeft.y,
|
|
383
|
+
this.rotatedPolygon.topRight.y,
|
|
384
|
+
this.rotatedPolygon.bottomRight.y,
|
|
385
|
+
this.rotatedPolygon.bottomLeft.y,
|
|
386
|
+
];
|
|
387
|
+
return Math.min(...corners);
|
|
388
|
+
}
|
|
389
|
+
get maxXRotated() {
|
|
390
|
+
const corners = [
|
|
391
|
+
this.rotatedPolygon.topLeft.x,
|
|
392
|
+
this.rotatedPolygon.topRight.x,
|
|
393
|
+
this.rotatedPolygon.bottomRight.x,
|
|
394
|
+
this.rotatedPolygon.bottomLeft.x,
|
|
395
|
+
];
|
|
396
|
+
return Math.max(...corners);
|
|
397
|
+
}
|
|
398
|
+
get maxYRotated() {
|
|
399
|
+
const corners = [
|
|
400
|
+
this.rotatedPolygon.topLeft.y,
|
|
401
|
+
this.rotatedPolygon.topRight.y,
|
|
402
|
+
this.rotatedPolygon.bottomRight.y,
|
|
403
|
+
this.rotatedPolygon.bottomLeft.y,
|
|
404
|
+
];
|
|
405
|
+
return Math.max(...corners);
|
|
406
|
+
}
|
|
407
|
+
get transformationMatrix() {
|
|
408
|
+
const scale = 1 / this.scale;
|
|
409
|
+
const translateX = this.translateX;
|
|
410
|
+
const translateY = this.translateY;
|
|
411
|
+
return `matrix(${scale}, 0, 0, ${scale}, ${translateX}, ${translateY})`;
|
|
412
|
+
}
|
|
413
|
+
get rotationDegrees() {
|
|
414
|
+
return this.rotation * (180 / Math.PI);
|
|
415
|
+
}
|
|
416
|
+
get centerX() {
|
|
417
|
+
return this.translateX + this.totalWidth / 2;
|
|
418
|
+
}
|
|
419
|
+
get centerY() {
|
|
420
|
+
return this.translateY + this.totalHeight / 2;
|
|
421
|
+
}
|
|
422
|
+
constructor() {
|
|
423
|
+
this.__class__ = 'KritzelBaseObject';
|
|
424
|
+
this.visible = true;
|
|
425
|
+
this.borderWidth = 0;
|
|
426
|
+
this.opacity = 1;
|
|
427
|
+
this.padding = 0;
|
|
428
|
+
this.selected = false;
|
|
429
|
+
this.resizing = false;
|
|
430
|
+
this.rotation = 0;
|
|
431
|
+
this.markedForRemoval = false;
|
|
432
|
+
this.isMounted = false;
|
|
433
|
+
this.zIndex = 0;
|
|
434
|
+
this.debugInfoVisible = false;
|
|
435
|
+
this.id = this.generateId();
|
|
436
|
+
}
|
|
437
|
+
static create(store) {
|
|
438
|
+
const object = new KritzelBaseObject();
|
|
439
|
+
object._store = store;
|
|
440
|
+
object.zIndex = store.currentZIndex;
|
|
441
|
+
return object;
|
|
442
|
+
}
|
|
443
|
+
mount(element) {
|
|
444
|
+
if (this.isMounted) {
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
this.elementRef = element;
|
|
448
|
+
this.isMounted = true;
|
|
449
|
+
}
|
|
450
|
+
generateId() {
|
|
451
|
+
return ObjectHelper.generateUUID();
|
|
452
|
+
}
|
|
453
|
+
isInViewport() {
|
|
454
|
+
const viewportBounds = {
|
|
455
|
+
x: -this._store.state.translateX / this._store.state.scale,
|
|
456
|
+
y: -this._store.state.translateY / this._store.state.scale,
|
|
457
|
+
width: this._store.state.viewportWidth / this._store.state.scale,
|
|
458
|
+
height: this._store.state.viewportHeight / this._store.state.scale};
|
|
459
|
+
return this.boundingBox.x < viewportBounds.x + viewportBounds.width &&
|
|
460
|
+
this.boundingBox.x + this.boundingBox.width > viewportBounds.x &&
|
|
461
|
+
this.boundingBox.y < viewportBounds.y + viewportBounds.height &&
|
|
462
|
+
this.boundingBox.y + this.boundingBox.height > viewportBounds.y;
|
|
463
|
+
}
|
|
464
|
+
centerInViewport() {
|
|
465
|
+
const scale = this._store.state.scale;
|
|
466
|
+
this.translateX = (this._store.state.viewportWidth / 2 - this.totalWidth / 2 - this._store.state.translateX) / scale;
|
|
467
|
+
this.translateY = (this._store.state.viewportHeight / 2 - this.totalHeight / 2 - this._store.state.translateY) / scale;
|
|
468
|
+
}
|
|
469
|
+
move(startX, startY, endX, endY) {
|
|
470
|
+
const deltaX = (startX - endX) / this._store.state.scale;
|
|
471
|
+
const deltaY = (startY - endY) / this._store.state.scale;
|
|
472
|
+
this.translateX += deltaX;
|
|
473
|
+
this.translateY += deltaY;
|
|
474
|
+
}
|
|
475
|
+
resize(x, y, width, height) {
|
|
476
|
+
if (width <= 1 || height <= 1) {
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
this.width = width;
|
|
480
|
+
this.height = height;
|
|
481
|
+
this.translateX = x;
|
|
482
|
+
this.translateY = y;
|
|
483
|
+
}
|
|
484
|
+
rotate(value) {
|
|
485
|
+
this.rotation = value;
|
|
486
|
+
}
|
|
487
|
+
copy() {
|
|
488
|
+
const copiedObject = Object.create(Object.getPrototypeOf(this));
|
|
489
|
+
Object.assign(copiedObject, this);
|
|
490
|
+
copiedObject.id = this.generateId();
|
|
491
|
+
copiedObject.isMounted = false;
|
|
492
|
+
return copiedObject;
|
|
493
|
+
}
|
|
494
|
+
onSelectedClick() {
|
|
495
|
+
// This method can be overridden by subclasses to handle click events when the object is selected.
|
|
496
|
+
}
|
|
497
|
+
revive(object) {
|
|
498
|
+
Object.assign(this, object);
|
|
499
|
+
return this;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
class KritzelText extends KritzelBaseObject {
|
|
504
|
+
get isReadonly() {
|
|
505
|
+
return !(this._store.state.activeTool instanceof KritzelTextTool);
|
|
506
|
+
}
|
|
507
|
+
constructor(config) {
|
|
508
|
+
super();
|
|
509
|
+
this.__class__ = 'KritzelText';
|
|
510
|
+
this.value = '';
|
|
511
|
+
this.fontFamily = 'Arial';
|
|
512
|
+
this.fontSize = 8;
|
|
513
|
+
this.fontColor = '#000000';
|
|
514
|
+
this.initialWidth = 3;
|
|
515
|
+
this.isNew = true;
|
|
516
|
+
this.debugInfoVisible = true;
|
|
517
|
+
this.rows = 1;
|
|
518
|
+
if (config) {
|
|
519
|
+
this.value = config.value || ' ';
|
|
520
|
+
this.translateX = config.translateX || 0;
|
|
521
|
+
this.translateY = config.translateY || 0;
|
|
522
|
+
this.fontSize = config.fontSize || 8;
|
|
523
|
+
this.fontFamily = config.fontFamily || 'Arial';
|
|
524
|
+
this.fontColor = config.fontColor || '#000000';
|
|
525
|
+
this.height = config.height || this.fontSize * 1.2;
|
|
526
|
+
this.width = config.width || 0;
|
|
527
|
+
this.scale = config.scale || 1;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
static create(store, fontSize, fontFamily) {
|
|
531
|
+
const object = new KritzelText();
|
|
532
|
+
object._store = store;
|
|
533
|
+
object.fontSize = fontSize;
|
|
534
|
+
object.fontFamily = fontFamily;
|
|
535
|
+
object.translateX = 0;
|
|
536
|
+
object.translateY = 0;
|
|
537
|
+
object.width = object.initialWidth / (object._store.state.scale < 0 ? object._store.state.scale : 1);
|
|
538
|
+
object.height = (object.fontSize * 1.2) / (object._store.state.scale < 0 ? object._store.state.scale : 1);
|
|
539
|
+
object.padding = 5;
|
|
540
|
+
object.backgroundColor = 'transparent';
|
|
541
|
+
object.scale = object._store.state.scale;
|
|
542
|
+
object.value = ' ';
|
|
543
|
+
object.zIndex = store.currentZIndex;
|
|
544
|
+
return object;
|
|
545
|
+
}
|
|
546
|
+
mount(element) {
|
|
547
|
+
if ((this.isMounted && this.elementRef === element) || this.isInViewport() === false) {
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
this.elementRef = element;
|
|
551
|
+
this.isMounted = true;
|
|
552
|
+
}
|
|
553
|
+
resize(x, y, width, height) {
|
|
554
|
+
if (width <= 1 || height <= 1) {
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
const scaleFactor = height / this.height;
|
|
558
|
+
this.fontSize = this.fontSize * scaleFactor;
|
|
559
|
+
this.width = this.width * scaleFactor;
|
|
560
|
+
this.height = height;
|
|
561
|
+
this.translateX = x;
|
|
562
|
+
this.translateY = y;
|
|
563
|
+
}
|
|
564
|
+
handleKeyDown(event) {
|
|
565
|
+
if (this.isReadonly) {
|
|
566
|
+
event.preventDefault();
|
|
567
|
+
event.stopPropagation();
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
handleInput(event) {
|
|
571
|
+
const target = event.target;
|
|
572
|
+
if (target.value === '') {
|
|
573
|
+
this.value = ' ';
|
|
574
|
+
target.value = ' ';
|
|
575
|
+
target.selectionStart = target.selectionEnd = target.value.length;
|
|
576
|
+
}
|
|
577
|
+
else {
|
|
578
|
+
this.value = target.value.trim();
|
|
579
|
+
}
|
|
580
|
+
this.adjustTextareaSize();
|
|
581
|
+
}
|
|
582
|
+
adjustTextareaSize() {
|
|
583
|
+
if (this.elementRef) {
|
|
584
|
+
const span = document.createElement('span');
|
|
585
|
+
span.style.position = 'absolute';
|
|
586
|
+
span.style.whiteSpace = 'pre-wrap';
|
|
587
|
+
span.style.visibility = 'hidden';
|
|
588
|
+
span.style.fontSize = window.getComputedStyle(this.elementRef).fontSize;
|
|
589
|
+
span.style.fontFamily = window.getComputedStyle(this.elementRef).fontFamily;
|
|
590
|
+
span.innerHTML = this.elementRef.value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\n/g, '<br>') + '<br>';
|
|
591
|
+
document.body.appendChild(span);
|
|
592
|
+
const textWidth = span.offsetWidth;
|
|
593
|
+
const textHeight = span.offsetHeight;
|
|
594
|
+
document.body.removeChild(span);
|
|
595
|
+
this.width = textWidth;
|
|
596
|
+
this.height = textHeight;
|
|
597
|
+
this._store.rerender();
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
focus() {
|
|
601
|
+
if (this.elementRef) {
|
|
602
|
+
this.elementRef.focus();
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
selectAll() {
|
|
606
|
+
if (this.elementRef) {
|
|
607
|
+
this.elementRef.select();
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
insertFromClipboard() {
|
|
611
|
+
if (this.elementRef) {
|
|
612
|
+
this.elementRef.focus();
|
|
613
|
+
try {
|
|
614
|
+
navigator.clipboard.readText().then(text => {
|
|
615
|
+
const start = this.elementRef.selectionStart;
|
|
616
|
+
const end = this.elementRef.selectionEnd;
|
|
617
|
+
const value = this.elementRef.value;
|
|
618
|
+
this.elementRef.value = value.substring(0, start) + text + value.substring(end);
|
|
619
|
+
this.elementRef.selectionStart = this.elementRef.selectionEnd = start + text.length;
|
|
620
|
+
this.value = this.elementRef.value;
|
|
621
|
+
this.adjustTextareaSize();
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
catch (err) {
|
|
625
|
+
console.error('Failed to read clipboard contents:', err);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
onSelectedClick() {
|
|
630
|
+
this._store.setState('activeTool', KritzelToolRegistry.getTool('text'));
|
|
631
|
+
this._store.state.selectionGroup = null;
|
|
632
|
+
this._store.state.selectionBox = null;
|
|
633
|
+
this._store.state.activeText = this;
|
|
634
|
+
setTimeout(() => {
|
|
635
|
+
this.focus();
|
|
636
|
+
}, 300);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
exports.AddObjectCommand = AddObjectCommand;
|
|
641
|
+
exports.KritzelBaseCommand = KritzelBaseCommand;
|
|
642
|
+
exports.KritzelBaseObject = KritzelBaseObject;
|
|
643
|
+
exports.KritzelBaseTool = KritzelBaseTool;
|
|
644
|
+
exports.KritzelEventHelper = KritzelEventHelper;
|
|
645
|
+
exports.KritzelKeyboardHelper = KritzelKeyboardHelper;
|
|
646
|
+
exports.KritzelText = KritzelText;
|
|
647
|
+
exports.KritzelTextTool = KritzelTextTool;
|
|
648
|
+
exports.KritzelToolRegistry = KritzelToolRegistry;
|
|
649
|
+
exports.ObjectHelper = ObjectHelper;
|
|
650
|
+
//# sourceMappingURL=index-C2M4eyxF.js.map
|
|
651
|
+
|
|
652
|
+
//# sourceMappingURL=index-C2M4eyxF.js.map
|