kritzel-stencil 0.0.141 → 0.0.142
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-BKstgWru.js → index-SaGfCHX3.js} +276 -805
- package/dist/cjs/index-SaGfCHX3.js.map +1 -0
- package/dist/cjs/index.cjs.js +1 -1
- package/dist/cjs/kritzel-color_22.cjs.entry.js +114 -77
- package/dist/collection/classes/commands/add-object.command.js +1 -0
- package/dist/collection/classes/commands/add-object.command.js.map +1 -1
- package/dist/collection/classes/commands/base.command.js +2 -0
- package/dist/collection/classes/commands/base.command.js.map +1 -1
- package/dist/collection/classes/commands/remove-object.command.js +1 -3
- package/dist/collection/classes/commands/remove-object.command.js.map +1 -1
- package/dist/collection/classes/commands/update-object.command.js +2 -0
- package/dist/collection/classes/commands/update-object.command.js.map +1 -1
- package/dist/collection/classes/core/command-manager.class.js +51 -0
- package/dist/collection/classes/core/command-manager.class.js.map +1 -0
- package/dist/collection/classes/core/core.class.js +23 -14
- package/dist/collection/classes/core/core.class.js.map +1 -1
- package/dist/collection/classes/core/history.class.js +2 -40
- package/dist/collection/classes/core/history.class.js.map +1 -1
- package/dist/collection/classes/core/viewport.class.js +16 -5
- package/dist/collection/classes/core/viewport.class.js.map +1 -1
- package/dist/collection/classes/handlers/context-menu.handler.js +1 -1
- package/dist/collection/classes/handlers/context-menu.handler.js.map +1 -1
- package/dist/collection/classes/handlers/move.handler.js +11 -6
- package/dist/collection/classes/handlers/move.handler.js.map +1 -1
- package/dist/collection/classes/handlers/resize.handler.js +29 -5
- package/dist/collection/classes/handlers/resize.handler.js.map +1 -1
- package/dist/collection/classes/handlers/rotation.handler.js +2 -2
- package/dist/collection/classes/handlers/rotation.handler.js.map +1 -1
- package/dist/collection/classes/handlers/selection.handler.js +4 -4
- package/dist/collection/classes/handlers/selection.handler.js.map +1 -1
- package/dist/collection/classes/objects/base-object.class.js +15 -14
- package/dist/collection/classes/objects/base-object.class.js.map +1 -1
- package/dist/collection/classes/objects/custom-element.class.js +7 -1
- package/dist/collection/classes/objects/custom-element.class.js.map +1 -1
- package/dist/collection/classes/objects/text.class.js +109 -49
- package/dist/collection/classes/objects/text.class.js.map +1 -1
- package/dist/collection/classes/tools/brush-tool.class.js +2 -2
- package/dist/collection/classes/tools/brush-tool.class.js.map +1 -1
- package/dist/collection/classes/tools/eraser-tool.class.js +2 -2
- package/dist/collection/classes/tools/eraser-tool.class.js.map +1 -1
- package/dist/collection/classes/tools/image-tool.class.js +1 -1
- package/dist/collection/classes/tools/image-tool.class.js.map +1 -1
- package/dist/collection/classes/tools/selection-tool.class.js +2 -2
- package/dist/collection/classes/tools/selection-tool.class.js.map +1 -1
- package/dist/collection/classes/tools/text-tool.class.js +17 -11
- package/dist/collection/classes/tools/text-tool.class.js.map +1 -1
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.css +1 -1
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +21 -15
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.js.map +1 -1
- package/dist/collection/interfaces/object.interface.js.map +1 -1
- package/dist/components/index.js +2 -2
- package/dist/components/kritzel-controls.js +1 -1
- package/dist/components/kritzel-editor.js +3 -3
- package/dist/components/kritzel-engine.js +1 -1
- package/dist/components/{p-ChLi4Ufe.js → p-C8calcQF.js} +3 -3
- package/dist/components/{p-ChLi4Ufe.js.map → p-C8calcQF.js.map} +1 -1
- package/dist/components/{p-BuDVaqTF.js → p-CZk591FE.js} +165 -728
- package/dist/components/p-CZk591FE.js.map +1 -0
- package/dist/components/{p-C4nj29RW.js → p-CziwfEQh.js} +227 -156
- package/dist/components/p-CziwfEQh.js.map +1 -0
- package/dist/esm/{index-D0Q2MKPn.js → index-SIM_s7ed.js} +276 -805
- package/dist/esm/index-SIM_s7ed.js.map +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/kritzel-color_22.entry.js +114 -77
- package/dist/stencil/index.esm.js +1 -1
- package/dist/stencil/p-SIM_s7ed.js +2 -0
- package/dist/stencil/p-SIM_s7ed.js.map +1 -0
- package/dist/stencil/p-b697b2c1.entry.js +2 -0
- package/dist/stencil/p-b697b2c1.entry.js.map +1 -0
- package/dist/stencil/stencil.esm.js +1 -1
- package/dist/types/classes/commands/add-object.command.d.ts +2 -2
- package/dist/types/classes/commands/base.command.d.ts +2 -1
- package/dist/types/classes/commands/remove-object.command.d.ts +2 -2
- package/dist/types/classes/commands/update-object.command.d.ts +2 -2
- package/dist/types/classes/core/command-manager.class.d.ts +16 -0
- package/dist/types/classes/core/core.class.d.ts +4 -0
- package/dist/types/classes/core/history.class.d.ts +0 -8
- package/dist/types/classes/core/viewport.class.d.ts +2 -0
- package/dist/types/classes/handlers/resize.handler.d.ts +1 -0
- package/dist/types/classes/objects/base-object.class.d.ts +6 -4
- package/dist/types/classes/objects/text.class.d.ts +13 -2
- package/dist/types/interfaces/object.interface.d.ts +1 -3
- package/package.json +1 -1
- package/dist/cjs/index-BKstgWru.js.map +0 -1
- package/dist/components/p-BuDVaqTF.js.map +0 -1
- package/dist/components/p-C4nj29RW.js.map +0 -1
- package/dist/esm/index-D0Q2MKPn.js.map +0 -1
- package/dist/stencil/p-73784709.entry.js +0 -2
- package/dist/stencil/p-73784709.entry.js.map +0 -1
- package/dist/stencil/p-D0Q2MKPn.js +0 -2
- package/dist/stencil/p-D0Q2MKPn.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { p as proxyCustomElement, H, c as createEvent, h, d as Host } from './p-C9hrbrUN.js';
|
|
2
2
|
import { K as KritzelMouseButton } from './p-D8W6LE-c.js';
|
|
3
|
-
import { e as KritzelBaseObject, f as KritzelBaseCommand, g as KritzelBaseTool, h as KritzelEventHelper, c as KritzelTextTool, b as KritzelBrushTool, K as KritzelText, a as KritzelPath, A as AddObjectCommand, i as KritzelToolRegistry, U as UpdateObjectCommand, d as KritzelKeyboardHelper } from './p-
|
|
3
|
+
import { e as KritzelBaseObject, f as KritzelBaseCommand, g as KritzelBaseTool, h as KritzelEventHelper, c as KritzelTextTool, b as KritzelBrushTool, K as KritzelText, a as KritzelPath, A as AddObjectCommand, i as KritzelToolRegistry, U as UpdateObjectCommand, d as KritzelKeyboardHelper } from './p-CZk591FE.js';
|
|
4
4
|
import { K as KritzelWorkspace } from './p-YqK8ch2R.js';
|
|
5
5
|
import { K as KritzelContextMenu, d as defineCustomElement$3 } from './p-DqsgZIHC.js';
|
|
6
6
|
import { O as ObjectHelper } from './p-B0kd2rUI.js';
|
|
@@ -75,59 +75,6 @@ class BatchCommand extends KritzelBaseCommand {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
class KritzelCustomElement extends KritzelBaseObject {
|
|
79
|
-
__class__ = 'KritzelCustomElement';
|
|
80
|
-
element;
|
|
81
|
-
isInteractive = true;
|
|
82
|
-
constructor(config) {
|
|
83
|
-
super();
|
|
84
|
-
if (config) {
|
|
85
|
-
this.translateX = config.translateX || 0;
|
|
86
|
-
this.translateY = config.translateY || 0;
|
|
87
|
-
this.scale = config.scale || 1;
|
|
88
|
-
this.element = config.element;
|
|
89
|
-
this.height = config.height || 0;
|
|
90
|
-
this.width = config.width || 0;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
static create(core, config) {
|
|
94
|
-
const object = new KritzelCustomElement(config);
|
|
95
|
-
object._core = core;
|
|
96
|
-
object.id = object.generateId();
|
|
97
|
-
object.workspaceId = core.store.state.activeWorkspace.id;
|
|
98
|
-
return object;
|
|
99
|
-
}
|
|
100
|
-
mount(element) {
|
|
101
|
-
if (this.isMounted) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
this.elementRef = element;
|
|
105
|
-
this.isMounted = true;
|
|
106
|
-
this.elementRef.appendChild(this.element);
|
|
107
|
-
}
|
|
108
|
-
resize(x, y, width, height) {
|
|
109
|
-
if (width <= 1 || height <= 1) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
this.width = width;
|
|
113
|
-
this.height = height;
|
|
114
|
-
this.translateX = x;
|
|
115
|
-
this.translateY = y;
|
|
116
|
-
if (this.element) {
|
|
117
|
-
this.element.style.width = `${width}px`;
|
|
118
|
-
this.element.style.height = `${height}px`;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
copy() {
|
|
122
|
-
const copiedObject = Object.create(Object.getPrototypeOf(this));
|
|
123
|
-
Object.assign(copiedObject, this);
|
|
124
|
-
copiedObject.id = this.generateId();
|
|
125
|
-
copiedObject.isMounted = false;
|
|
126
|
-
copiedObject.element = this.element.cloneNode(true);
|
|
127
|
-
return copiedObject;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
78
|
class RemoveObjectCommand extends KritzelBaseCommand {
|
|
132
79
|
object;
|
|
133
80
|
constructor(core, initiator, object, skipHistory = false) {
|
|
@@ -135,13 +82,12 @@ class RemoveObjectCommand extends KritzelBaseCommand {
|
|
|
135
82
|
this.object = object;
|
|
136
83
|
}
|
|
137
84
|
execute() {
|
|
85
|
+
this.object.isMounted = false;
|
|
138
86
|
this._core.store.state.objectsMap.remove(object => object.id === this.object.id);
|
|
139
|
-
this._core.store.state.objectsMap.filter(object => object instanceof KritzelCustomElement).forEach(object => object.remount());
|
|
140
87
|
this._core.deleteObjectFromDatabase(this.object.id);
|
|
141
88
|
}
|
|
142
89
|
undo() {
|
|
143
90
|
this._core.store.state.objectsMap.insert(this.object);
|
|
144
|
-
this._core.store.state.objectsMap.filter(object => object instanceof KritzelCustomElement).forEach(object => object.remount());
|
|
145
91
|
this._core.addObjectToDatabase(this.object);
|
|
146
92
|
}
|
|
147
93
|
}
|
|
@@ -204,7 +150,7 @@ class KritzelEraserTool extends KritzelBaseTool {
|
|
|
204
150
|
return new RemoveObjectCommand(this._core, this, object);
|
|
205
151
|
});
|
|
206
152
|
if (removeCommands.length > 0) {
|
|
207
|
-
this._core.
|
|
153
|
+
this._core.commandManager.executeCommand(new BatchCommand(this._core, this, removeCommands));
|
|
208
154
|
}
|
|
209
155
|
this._core.store.state.isErasing = false;
|
|
210
156
|
}
|
|
@@ -219,7 +165,7 @@ class KritzelEraserTool extends KritzelBaseTool {
|
|
|
219
165
|
return new RemoveObjectCommand(this._core, this, object);
|
|
220
166
|
});
|
|
221
167
|
if (removeCommands.length > 0) {
|
|
222
|
-
this._core.
|
|
168
|
+
this._core.commandManager.executeCommand(new BatchCommand(this._core, this, removeCommands));
|
|
223
169
|
}
|
|
224
170
|
this._core.store.state.isErasing = false;
|
|
225
171
|
}
|
|
@@ -370,10 +316,15 @@ class KritzelMoveHandler extends KritzelBaseHandler {
|
|
|
370
316
|
const clientY = event.clientY - this._core.store.offsetY;
|
|
371
317
|
this.endX = clientX;
|
|
372
318
|
this.endY = clientY;
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
319
|
+
const moveDeltaX = Math.abs(clientX - this.startX);
|
|
320
|
+
const moveDeltaY = Math.abs(clientY - this.startY);
|
|
321
|
+
const moveThreshold = 5;
|
|
322
|
+
if (moveDeltaX > moveThreshold || moveDeltaY > moveThreshold) {
|
|
323
|
+
this._core.store.state.selectionGroup.move(clientX, clientY, this.dragStartX, this.dragStartY);
|
|
324
|
+
this.dragStartX = clientX;
|
|
325
|
+
this.dragStartY = clientY;
|
|
326
|
+
this.hasMoved = true;
|
|
327
|
+
}
|
|
377
328
|
}
|
|
378
329
|
}
|
|
379
330
|
if (event.pointerType === 'touch') {
|
|
@@ -408,7 +359,7 @@ class KritzelMoveHandler extends KritzelBaseHandler {
|
|
|
408
359
|
if (this._core.store.state.isDragging) {
|
|
409
360
|
this._core.store.state.isDragging = false;
|
|
410
361
|
if (this.hasMoved) {
|
|
411
|
-
this._core.
|
|
362
|
+
this._core.commandManager.executeCommand(new MoveSelectionGroupCommand(this._core, this, this.endX, this.endY, this.startX, this.startY, true));
|
|
412
363
|
this._core.store.state.hasObjectsChanged = true;
|
|
413
364
|
}
|
|
414
365
|
}
|
|
@@ -417,7 +368,7 @@ class KritzelMoveHandler extends KritzelBaseHandler {
|
|
|
417
368
|
if (this._core.store.state.isDragging) {
|
|
418
369
|
this._core.store.state.isDragging = false;
|
|
419
370
|
if (this.hasMoved) {
|
|
420
|
-
this._core.
|
|
371
|
+
this._core.commandManager.executeCommand(new MoveSelectionGroupCommand(this._core, this, this.endX, this.endY, this.startX, this.startY, true));
|
|
421
372
|
this._core.store.state.hasObjectsChanged = true;
|
|
422
373
|
}
|
|
423
374
|
}
|
|
@@ -467,6 +418,7 @@ class KritzelResizeHandler extends KritzelBaseHandler {
|
|
|
467
418
|
initialMouseY = 0;
|
|
468
419
|
initialSize = { x: 0, y: 0, width: 0, height: 0 };
|
|
469
420
|
newSize = { x: 0, y: 0, width: 0, height: 0 };
|
|
421
|
+
hasResized = false;
|
|
470
422
|
constructor(core) {
|
|
471
423
|
super(core);
|
|
472
424
|
}
|
|
@@ -475,6 +427,7 @@ class KritzelResizeHandler extends KritzelBaseHandler {
|
|
|
475
427
|
this.initialMouseY = 0;
|
|
476
428
|
this.initialSize = { x: 0, y: 0, width: 0, height: 0 };
|
|
477
429
|
this.newSize = { x: 0, y: 0, width: 0, height: 0 };
|
|
430
|
+
this.hasResized = false;
|
|
478
431
|
}
|
|
479
432
|
handlePointerDown(event) {
|
|
480
433
|
if (event.pointerType === 'mouse') {
|
|
@@ -521,6 +474,15 @@ class KritzelResizeHandler extends KritzelBaseHandler {
|
|
|
521
474
|
const clientY = event.clientY - this._core.store.offsetY;
|
|
522
475
|
const dx = clientX - this.initialMouseX;
|
|
523
476
|
const dy = clientY - this.initialMouseY;
|
|
477
|
+
const resizeDeltaX = Math.abs(dx);
|
|
478
|
+
const resizeDeltaY = Math.abs(dy);
|
|
479
|
+
const resizeThreshold = 5;
|
|
480
|
+
if (resizeDeltaX > resizeThreshold || resizeDeltaY > resizeThreshold) {
|
|
481
|
+
this.hasResized = true;
|
|
482
|
+
}
|
|
483
|
+
if (!this.hasResized) {
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
524
486
|
switch (this._core.store.state.resizeHandleType) {
|
|
525
487
|
case KritzelHandleType.TopLeft:
|
|
526
488
|
this.newSize.width = this.initialSize.width - dx;
|
|
@@ -561,6 +523,16 @@ class KritzelResizeHandler extends KritzelBaseHandler {
|
|
|
561
523
|
const clientY = Math.round(oneFingerTouch.clientY - this._core.store.offsetY);
|
|
562
524
|
const dx = clientX - this.initialMouseX;
|
|
563
525
|
const dy = clientY - this.initialMouseY;
|
|
526
|
+
const resizeDeltaX = Math.abs(dx);
|
|
527
|
+
const resizeDeltaY = Math.abs(dy);
|
|
528
|
+
const resizeThreshold = 5;
|
|
529
|
+
if (resizeDeltaX > resizeThreshold || resizeDeltaY > resizeThreshold) {
|
|
530
|
+
clearTimeout(this._core.store.state.longTouchTimeout);
|
|
531
|
+
this.hasResized = true;
|
|
532
|
+
}
|
|
533
|
+
if (!this.hasResized) {
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
564
536
|
switch (this._core.store.state.resizeHandleType) {
|
|
565
537
|
case KritzelHandleType.TopLeft:
|
|
566
538
|
this.newSize.width = this.initialSize.width - dx;
|
|
@@ -588,24 +560,27 @@ class KritzelResizeHandler extends KritzelBaseHandler {
|
|
|
588
560
|
break;
|
|
589
561
|
}
|
|
590
562
|
this._core.store.state.selectionGroup.resize(this.newSize.x, this.newSize.y, this.newSize.width, this.newSize.height);
|
|
591
|
-
clearTimeout(this._core.store.state.longTouchTimeout);
|
|
592
563
|
}
|
|
593
564
|
}
|
|
594
565
|
}
|
|
595
566
|
handlePointerUp(event) {
|
|
596
567
|
if (event.pointerType === 'mouse') {
|
|
597
568
|
if (this._core.store.state.isResizing) {
|
|
598
|
-
this._core.history.executeCommand(new ResizeSelectionGroupCommand(this._core, this, structuredClone(this.initialSize), structuredClone(this.newSize)));
|
|
599
569
|
this._core.store.state.isResizing = false;
|
|
600
|
-
this.
|
|
570
|
+
if (this.hasResized) {
|
|
571
|
+
this._core.commandManager.executeCommand(new ResizeSelectionGroupCommand(this._core, this, structuredClone(this.initialSize), structuredClone(this.newSize)));
|
|
572
|
+
this._core.store.state.hasObjectsChanged = true;
|
|
573
|
+
}
|
|
601
574
|
this.reset();
|
|
602
575
|
}
|
|
603
576
|
}
|
|
604
577
|
if (event.pointerType === 'touch') {
|
|
605
578
|
if (this._core.store.state.isResizing) {
|
|
606
|
-
this._core.history.executeCommand(new ResizeSelectionGroupCommand(this._core, this, structuredClone(this.initialSize), structuredClone(this.newSize)));
|
|
607
579
|
this._core.store.state.isResizing = false;
|
|
608
|
-
this.
|
|
580
|
+
if (this.hasResized) {
|
|
581
|
+
this._core.commandManager.executeCommand(new ResizeSelectionGroupCommand(this._core, this, structuredClone(this.initialSize), structuredClone(this.newSize)));
|
|
582
|
+
this._core.store.state.hasObjectsChanged = true;
|
|
583
|
+
}
|
|
609
584
|
this.reset();
|
|
610
585
|
clearTimeout(this._core.store.state.longTouchTimeout);
|
|
611
586
|
}
|
|
@@ -731,7 +706,7 @@ class KritzelRotationHandler extends KritzelBaseHandler {
|
|
|
731
706
|
handlePointerUp(event) {
|
|
732
707
|
if (event.pointerType === 'mouse') {
|
|
733
708
|
if (this._core.store.state.isRotating) {
|
|
734
|
-
this._core.
|
|
709
|
+
this._core.commandManager.executeCommand(new RotateSelectionGroupCommand(this._core, this, this.rotation, this.initialSelectionGroupRotation));
|
|
735
710
|
this._core.store.state.isRotating = false;
|
|
736
711
|
this._core.store.state.hasObjectsChanged = true;
|
|
737
712
|
this.reset();
|
|
@@ -739,7 +714,7 @@ class KritzelRotationHandler extends KritzelBaseHandler {
|
|
|
739
714
|
}
|
|
740
715
|
if (event.pointerType === 'touch') {
|
|
741
716
|
if (this._core.store.state.isRotating) {
|
|
742
|
-
this._core.
|
|
717
|
+
this._core.commandManager.executeCommand(new RotateSelectionGroupCommand(this._core, this, this.rotation, this.initialSelectionGroupRotation));
|
|
743
718
|
this._core.store.state.isRotating = false;
|
|
744
719
|
this._core.store.state.hasObjectsChanged = true;
|
|
745
720
|
this.reset();
|
|
@@ -843,7 +818,7 @@ class KritzelSelectionHandler extends KritzelBaseHandler {
|
|
|
843
818
|
if (KritzelEventHelper.isLeftClick(event)) {
|
|
844
819
|
const hasObjectsMoved = this._core.store.state.hasObjectsChanged;
|
|
845
820
|
if (this._core.store.state.selectionGroup?.objects.length === 1 && hasObjectsMoved === false) {
|
|
846
|
-
this._core.store.state.selectionGroup.objects[0].edit();
|
|
821
|
+
this._core.store.state.selectionGroup.objects[0].edit(event);
|
|
847
822
|
}
|
|
848
823
|
this._core.store.state.hasObjectsChanged = false;
|
|
849
824
|
if (this._core.store.state.isSelecting) {
|
|
@@ -862,7 +837,7 @@ class KritzelSelectionHandler extends KritzelBaseHandler {
|
|
|
862
837
|
clearTimeout(this.touchStartTimeout);
|
|
863
838
|
const hasObjectsMoved = this._core.store.state.hasObjectsChanged;
|
|
864
839
|
if (this._core.store.state.selectionGroup?.objects.length === 1 && hasObjectsMoved === false) {
|
|
865
|
-
this._core.store.state.selectionGroup.objects[0].edit();
|
|
840
|
+
this._core.store.state.selectionGroup.objects[0].edit(event);
|
|
866
841
|
}
|
|
867
842
|
this._core.store.state.hasObjectsChanged = false;
|
|
868
843
|
if (this._core.store.state.isSelecting) {
|
|
@@ -1005,7 +980,7 @@ class KritzelSelectionHandler extends KritzelBaseHandler {
|
|
|
1005
980
|
selectionGroup.addOrRemove(object);
|
|
1006
981
|
selectionGroup.isSelected = true;
|
|
1007
982
|
selectionGroup.rotation = object.rotation;
|
|
1008
|
-
this._core.
|
|
983
|
+
this._core.commandManager.executeCommand(new AddSelectionGroupCommand(this._core, this, selectionGroup));
|
|
1009
984
|
}
|
|
1010
985
|
addSelectedObjectsToSelectionGroup() {
|
|
1011
986
|
const selectedObjects = this._core.store.selectedObjects;
|
|
@@ -1022,7 +997,7 @@ class KritzelSelectionHandler extends KritzelBaseHandler {
|
|
|
1022
997
|
if (selectionGroup.length === 1) {
|
|
1023
998
|
selectionGroup.rotation = selectionGroup.objects[0].rotation;
|
|
1024
999
|
}
|
|
1025
|
-
this._core.
|
|
1000
|
+
this._core.commandManager.executeCommand(new AddSelectionGroupCommand(this._core, this, selectionGroup));
|
|
1026
1001
|
}
|
|
1027
1002
|
}
|
|
1028
1003
|
|
|
@@ -1071,7 +1046,7 @@ class KritzelSelectionTool extends KritzelBaseTool {
|
|
|
1071
1046
|
this._core.store.state.selectionGroup &&
|
|
1072
1047
|
!this._core.store.state.isResizeHandleSelected &&
|
|
1073
1048
|
!this._core.store.state.isRotationHandleSelected) {
|
|
1074
|
-
this._core.
|
|
1049
|
+
this._core.commandManager.executeCommand(new RemoveSelectionGroupCommand(this._core, this._core.store.state.selectionGroup));
|
|
1075
1050
|
}
|
|
1076
1051
|
if (selectedObject && selectedObject.isSelected === false && selectedObject?.objects.length === 1 && selectedObject.objects[0].isInteractive) {
|
|
1077
1052
|
return;
|
|
@@ -1100,7 +1075,7 @@ class KritzelSelectionTool extends KritzelBaseTool {
|
|
|
1100
1075
|
this._core.store.state.selectionGroup &&
|
|
1101
1076
|
!this._core.store.state.isResizeHandleSelected &&
|
|
1102
1077
|
!this._core.store.state.isRotationHandleSelected) {
|
|
1103
|
-
this._core.
|
|
1078
|
+
this._core.commandManager.executeCommand(new RemoveSelectionGroupCommand(this._core, this._core.store.state.selectionGroup));
|
|
1104
1079
|
}
|
|
1105
1080
|
}
|
|
1106
1081
|
this.rotationHandler.handlePointerDown(event);
|
|
@@ -1194,6 +1169,65 @@ class KritzelSelectionTool extends KritzelBaseTool {
|
|
|
1194
1169
|
}
|
|
1195
1170
|
}
|
|
1196
1171
|
|
|
1172
|
+
class KritzelCustomElement extends KritzelBaseObject {
|
|
1173
|
+
__class__ = 'KritzelCustomElement';
|
|
1174
|
+
element;
|
|
1175
|
+
isInteractive = true;
|
|
1176
|
+
constructor(config) {
|
|
1177
|
+
super();
|
|
1178
|
+
if (config) {
|
|
1179
|
+
this.translateX = config.translateX || 0;
|
|
1180
|
+
this.translateY = config.translateY || 0;
|
|
1181
|
+
this.scale = config.scale || 1;
|
|
1182
|
+
this.element = config.element;
|
|
1183
|
+
this.height = config.height || 0;
|
|
1184
|
+
this.width = config.width || 0;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
static create(core, config) {
|
|
1188
|
+
const object = new KritzelCustomElement(config);
|
|
1189
|
+
object._core = core;
|
|
1190
|
+
object.id = object.generateId();
|
|
1191
|
+
object.workspaceId = core.store.state.activeWorkspace.id;
|
|
1192
|
+
return object;
|
|
1193
|
+
}
|
|
1194
|
+
mount(element) {
|
|
1195
|
+
if (element === null) {
|
|
1196
|
+
return;
|
|
1197
|
+
}
|
|
1198
|
+
// If already mounted to the same element and content is still attached, skip
|
|
1199
|
+
if (this.isMounted && this.elementRef === element && this.element.parentElement === element) {
|
|
1200
|
+
return;
|
|
1201
|
+
}
|
|
1202
|
+
this.elementRef = element;
|
|
1203
|
+
this.isMounted = true;
|
|
1204
|
+
// Clear existing content and append the element
|
|
1205
|
+
this.elementRef.innerHTML = '';
|
|
1206
|
+
this.elementRef.appendChild(this.element);
|
|
1207
|
+
}
|
|
1208
|
+
resize(x, y, width, height) {
|
|
1209
|
+
if (width <= 1 || height <= 1) {
|
|
1210
|
+
return;
|
|
1211
|
+
}
|
|
1212
|
+
this.width = width;
|
|
1213
|
+
this.height = height;
|
|
1214
|
+
this.translateX = x;
|
|
1215
|
+
this.translateY = y;
|
|
1216
|
+
if (this.element) {
|
|
1217
|
+
this.element.style.width = `${width}px`;
|
|
1218
|
+
this.element.style.height = `${height}px`;
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
copy() {
|
|
1222
|
+
const copiedObject = Object.create(Object.getPrototypeOf(this));
|
|
1223
|
+
Object.assign(copiedObject, this);
|
|
1224
|
+
copiedObject.id = this.generateId();
|
|
1225
|
+
copiedObject.isMounted = false;
|
|
1226
|
+
copiedObject.element = this.element.cloneNode(true);
|
|
1227
|
+
return copiedObject;
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1197
1231
|
class KritzelReviver {
|
|
1198
1232
|
_core;
|
|
1199
1233
|
constructor(core) {
|
|
@@ -1501,7 +1535,7 @@ class KritzelImageTool extends KritzelBaseTool {
|
|
|
1501
1535
|
selectionGroup.isSelected = true;
|
|
1502
1536
|
const addImageCommand = new AddObjectCommand(this._core, this, image);
|
|
1503
1537
|
const addSelectionGroupCommand = new AddSelectionGroupCommand(this._core, this, selectionGroup);
|
|
1504
|
-
this._core.
|
|
1538
|
+
this._core.commandManager.executeCommand(new BatchCommand(this._core, this, [addImageCommand, addSelectionGroupCommand]));
|
|
1505
1539
|
this._core.store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
|
|
1506
1540
|
}
|
|
1507
1541
|
handleCancel() {
|
|
@@ -1514,6 +1548,7 @@ const ABSOLUTE_SCALE_MIN = 0.0001;
|
|
|
1514
1548
|
|
|
1515
1549
|
class KritzelViewport {
|
|
1516
1550
|
_core;
|
|
1551
|
+
_debounceUpdate;
|
|
1517
1552
|
initialTouchDistance = 0;
|
|
1518
1553
|
startX = 0;
|
|
1519
1554
|
startY = 0;
|
|
@@ -1526,6 +1561,16 @@ class KritzelViewport {
|
|
|
1526
1561
|
this._core.store.state.startY = 0;
|
|
1527
1562
|
this._core.store.state.translateX = 0;
|
|
1528
1563
|
this._core.store.state.translateY = 0;
|
|
1564
|
+
this._debounceUpdate = this.debounce(() => {
|
|
1565
|
+
this._core.updateWorkspaceViewport(this._core.store.state.translateX, this._core.store.state.translateY, this._core.store.state.scale);
|
|
1566
|
+
}, 0);
|
|
1567
|
+
}
|
|
1568
|
+
debounce(func, delay) {
|
|
1569
|
+
let timeoutId;
|
|
1570
|
+
return () => {
|
|
1571
|
+
clearTimeout(timeoutId);
|
|
1572
|
+
timeoutId = setTimeout(func, delay);
|
|
1573
|
+
};
|
|
1529
1574
|
}
|
|
1530
1575
|
handleResize() {
|
|
1531
1576
|
this._core.store.state.viewportWidth = this._core.store.state.host.clientWidth;
|
|
@@ -1576,7 +1621,7 @@ class KritzelViewport {
|
|
|
1576
1621
|
this._core.store.state.hasViewportChanged = true;
|
|
1577
1622
|
this._core.store.state.skipContextMenu = true;
|
|
1578
1623
|
this._core.rerender();
|
|
1579
|
-
this.
|
|
1624
|
+
this._debounceUpdate();
|
|
1580
1625
|
}
|
|
1581
1626
|
}
|
|
1582
1627
|
if (event.pointerType === 'touch') {
|
|
@@ -1612,7 +1657,7 @@ class KritzelViewport {
|
|
|
1612
1657
|
this.startY = midpointY;
|
|
1613
1658
|
this._core.store.state.hasViewportChanged = true;
|
|
1614
1659
|
this._core.rerender();
|
|
1615
|
-
this.
|
|
1660
|
+
this._debounceUpdate();
|
|
1616
1661
|
}
|
|
1617
1662
|
}
|
|
1618
1663
|
}
|
|
@@ -1646,7 +1691,7 @@ class KritzelViewport {
|
|
|
1646
1691
|
this._core.store.state.translateY = viewportHeight / 2 - objectCenterY * scale;
|
|
1647
1692
|
this._core.store.state.hasViewportChanged = true;
|
|
1648
1693
|
this._core.rerender();
|
|
1649
|
-
this.
|
|
1694
|
+
this._debounceUpdate();
|
|
1650
1695
|
}
|
|
1651
1696
|
centerFitInViewport(object) {
|
|
1652
1697
|
const scaleX = this._core.store.state.viewportWidth / (object.rotatedBoundingBox.width * 1.1);
|
|
@@ -1673,7 +1718,7 @@ class KritzelViewport {
|
|
|
1673
1718
|
this._core.store.state.translateY = this._core.store.state.translateY - translateYAdjustment;
|
|
1674
1719
|
this._core.store.state.hasViewportChanged = true;
|
|
1675
1720
|
this._core.rerender();
|
|
1676
|
-
this.
|
|
1721
|
+
this._debounceUpdate();
|
|
1677
1722
|
setTimeout(() => {
|
|
1678
1723
|
this._core.store.state.isScaling = false;
|
|
1679
1724
|
}, 300);
|
|
@@ -1684,7 +1729,7 @@ class KritzelViewport {
|
|
|
1684
1729
|
this._core.store.state.translateY = this._core.store.state.translateY - event.deltaY * panSpeed;
|
|
1685
1730
|
this._core.store.state.hasViewportChanged = true;
|
|
1686
1731
|
this._core.rerender();
|
|
1687
|
-
this.
|
|
1732
|
+
this._debounceUpdate();
|
|
1688
1733
|
}
|
|
1689
1734
|
}
|
|
1690
1735
|
|
|
@@ -1778,7 +1823,7 @@ class KritzelContextMenuHandler extends KritzelBaseHandler {
|
|
|
1778
1823
|
new RemoveSelectionGroupCommand(this._core, this._core.store.state.selectionGroup),
|
|
1779
1824
|
new AddSelectionGroupCommand(this._core, this, selectionGroup),
|
|
1780
1825
|
]);
|
|
1781
|
-
this._core.
|
|
1826
|
+
this._core.commandManager.executeCommand(batch);
|
|
1782
1827
|
}
|
|
1783
1828
|
this._core.store.state.contextMenuItems = this._core.store.state.selectionGroup ? this.objectContextMenuItems : this.globalContextMenuItems;
|
|
1784
1829
|
let x = event.clientX - this._core.store.offsetX;
|
|
@@ -2181,47 +2226,24 @@ class KritzelHistory {
|
|
|
2181
2226
|
_core;
|
|
2182
2227
|
undoStack;
|
|
2183
2228
|
redoStack;
|
|
2184
|
-
previousViewport;
|
|
2185
2229
|
constructor(core) {
|
|
2186
2230
|
this._core = core;
|
|
2187
2231
|
this.undoStack = new KritzelCircularBuffer(this._core.store.state.historyBufferSize);
|
|
2188
2232
|
this.redoStack = new KritzelCircularBuffer(this._core.store.state.historyBufferSize);
|
|
2189
|
-
this.previousViewport = {
|
|
2190
|
-
scale: this._core.store.state.scale,
|
|
2191
|
-
scaleStep: this._core.store.state.scaleStep,
|
|
2192
|
-
translateX: this._core.store.state.translateX,
|
|
2193
|
-
translateY: this._core.store.state.translateY,
|
|
2194
|
-
};
|
|
2195
2233
|
}
|
|
2196
2234
|
reset() {
|
|
2197
2235
|
this.undoStack.clear();
|
|
2198
2236
|
this.redoStack.clear();
|
|
2199
|
-
this.previousViewport = {
|
|
2237
|
+
this._core.commandManager.previousViewport = {
|
|
2200
2238
|
scale: this._core.store.state.scale,
|
|
2201
2239
|
scaleStep: this._core.store.state.scaleStep,
|
|
2202
2240
|
translateX: this._core.store.state.translateX,
|
|
2203
2241
|
translateY: this._core.store.state.translateY
|
|
2204
2242
|
};
|
|
2205
2243
|
}
|
|
2206
|
-
executeCommand(command) {
|
|
2207
|
-
if (this._core.store.state.hasViewportChanged) {
|
|
2208
|
-
this.addUpdateViewportCommand();
|
|
2209
|
-
}
|
|
2210
|
-
command.execute();
|
|
2211
|
-
if (command.skipHistory === false) {
|
|
2212
|
-
if (this._core.store.state.debugInfo.logCommands) {
|
|
2213
|
-
console.info('add', command);
|
|
2214
|
-
}
|
|
2215
|
-
this.undoStack.add(command);
|
|
2216
|
-
if (this.redoStack.isEmpty() === false) {
|
|
2217
|
-
this.redoStack.clear();
|
|
2218
|
-
}
|
|
2219
|
-
}
|
|
2220
|
-
this._core.rerender();
|
|
2221
|
-
}
|
|
2222
2244
|
undo() {
|
|
2223
2245
|
if (this._core.store.state.hasViewportChanged) {
|
|
2224
|
-
const command = new UpdateViewportCommand(this._core, this, this.previousViewport);
|
|
2246
|
+
const command = new UpdateViewportCommand(this._core, this, this._core.commandManager.previousViewport);
|
|
2225
2247
|
command.undo();
|
|
2226
2248
|
this._core.store.state.hasViewportChanged = false;
|
|
2227
2249
|
this._core.rerender();
|
|
@@ -2247,21 +2269,6 @@ class KritzelHistory {
|
|
|
2247
2269
|
}
|
|
2248
2270
|
this._core.rerender();
|
|
2249
2271
|
}
|
|
2250
|
-
addUpdateViewportCommand() {
|
|
2251
|
-
const command = new UpdateViewportCommand(this._core, this, this.previousViewport);
|
|
2252
|
-
command.execute();
|
|
2253
|
-
this.undoStack.add(command);
|
|
2254
|
-
if (this.redoStack.isEmpty() === false) {
|
|
2255
|
-
this.redoStack.clear();
|
|
2256
|
-
}
|
|
2257
|
-
this._core.store.state.hasViewportChanged = false;
|
|
2258
|
-
this.previousViewport = {
|
|
2259
|
-
scale: this._core.store.state.scale,
|
|
2260
|
-
scaleStep: this._core.store.state.scaleStep,
|
|
2261
|
-
translateX: this._core.store.state.translateX,
|
|
2262
|
-
translateY: this._core.store.state.translateY,
|
|
2263
|
-
};
|
|
2264
|
-
}
|
|
2265
2272
|
}
|
|
2266
2273
|
|
|
2267
2274
|
class KritzelObjectMap {
|
|
@@ -2358,10 +2365,61 @@ class KritzelStore {
|
|
|
2358
2365
|
}
|
|
2359
2366
|
}
|
|
2360
2367
|
|
|
2368
|
+
class KritzelCommandManager {
|
|
2369
|
+
_core;
|
|
2370
|
+
_history;
|
|
2371
|
+
previousViewport;
|
|
2372
|
+
constructor(core) {
|
|
2373
|
+
this._core = core;
|
|
2374
|
+
this._history = this._core.history;
|
|
2375
|
+
this.previousViewport = {
|
|
2376
|
+
scale: this._core.store.state.scale,
|
|
2377
|
+
scaleStep: this._core.store.state.scaleStep,
|
|
2378
|
+
translateX: this._core.store.state.translateX,
|
|
2379
|
+
translateY: this._core.store.state.translateY,
|
|
2380
|
+
};
|
|
2381
|
+
}
|
|
2382
|
+
executeCommand(command) {
|
|
2383
|
+
if (this._core.store.state.hasViewportChanged) {
|
|
2384
|
+
this.addUpdateViewportCommand();
|
|
2385
|
+
}
|
|
2386
|
+
command.execute();
|
|
2387
|
+
if (this.isSkipped(command) === false) {
|
|
2388
|
+
if (this._core.store.state.debugInfo.logCommands) {
|
|
2389
|
+
console.log('execute', command);
|
|
2390
|
+
}
|
|
2391
|
+
this._history.undoStack.add(command);
|
|
2392
|
+
if (this._history.redoStack.isEmpty() === false) {
|
|
2393
|
+
this._history.redoStack.clear();
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
this._core.rerender();
|
|
2397
|
+
}
|
|
2398
|
+
isSkipped(command) {
|
|
2399
|
+
return command.skipHistory === true;
|
|
2400
|
+
}
|
|
2401
|
+
addUpdateViewportCommand() {
|
|
2402
|
+
const command = new UpdateViewportCommand(this._core, this, this.previousViewport);
|
|
2403
|
+
command.execute();
|
|
2404
|
+
this._history.undoStack.add(command);
|
|
2405
|
+
if (this._history.redoStack.isEmpty() === false) {
|
|
2406
|
+
this._history.redoStack.clear();
|
|
2407
|
+
}
|
|
2408
|
+
this._core.store.state.hasViewportChanged = false;
|
|
2409
|
+
this.previousViewport = {
|
|
2410
|
+
scale: this._core.store.state.scale,
|
|
2411
|
+
scaleStep: this._core.store.state.scaleStep,
|
|
2412
|
+
translateX: this._core.store.state.translateX,
|
|
2413
|
+
translateY: this._core.store.state.translateY,
|
|
2414
|
+
};
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
|
|
2361
2418
|
class KritzelCore {
|
|
2362
2419
|
_kritzelEngine;
|
|
2363
2420
|
_store;
|
|
2364
2421
|
_history;
|
|
2422
|
+
_commandManager;
|
|
2365
2423
|
_database;
|
|
2366
2424
|
get engine() {
|
|
2367
2425
|
return this._kritzelEngine;
|
|
@@ -2369,6 +2427,9 @@ class KritzelCore {
|
|
|
2369
2427
|
get history() {
|
|
2370
2428
|
return this._history;
|
|
2371
2429
|
}
|
|
2430
|
+
get commandManager() {
|
|
2431
|
+
return this._commandManager;
|
|
2432
|
+
}
|
|
2372
2433
|
get database() {
|
|
2373
2434
|
return this._database;
|
|
2374
2435
|
}
|
|
@@ -2379,6 +2440,7 @@ class KritzelCore {
|
|
|
2379
2440
|
this._kritzelEngine = kritzelEngine;
|
|
2380
2441
|
this._store = new KritzelStore(DEFAULT_ENGINE_STATE);
|
|
2381
2442
|
this._history = new KritzelHistory(this);
|
|
2443
|
+
this._commandManager = new KritzelCommandManager(this);
|
|
2382
2444
|
this._database = new KritzelDatabase('kritzelDB', 1, this._store.state.debugInfo.logDatabase);
|
|
2383
2445
|
}
|
|
2384
2446
|
async initializeDatabase() {
|
|
@@ -2531,7 +2593,7 @@ class KritzelCore {
|
|
|
2531
2593
|
}
|
|
2532
2594
|
deselectAllObjects() {
|
|
2533
2595
|
if (this._store.state.selectionGroup) {
|
|
2534
|
-
this.
|
|
2596
|
+
this.commandManager.executeCommand(new RemoveSelectionGroupCommand(this, this, true));
|
|
2535
2597
|
}
|
|
2536
2598
|
}
|
|
2537
2599
|
delete() {
|
|
@@ -2541,13 +2603,13 @@ class KritzelCore {
|
|
|
2541
2603
|
const deleteSelectedObjectsCommand = this._store.state.selectionGroup.objects.map(obj => new RemoveObjectCommand(this, this._store.state.selectionGroup, obj));
|
|
2542
2604
|
const removeSelectionGroupCommand = new RemoveSelectionGroupCommand(this, this._store.state.selectionGroup);
|
|
2543
2605
|
const commands = [...deleteSelectedObjectsCommand, removeSelectionGroupCommand];
|
|
2544
|
-
this.
|
|
2606
|
+
this.commandManager.executeCommand(new BatchCommand(this, this._store.state.selectionGroup, commands));
|
|
2545
2607
|
}
|
|
2546
2608
|
deleteObject(id, skipHistory = false) {
|
|
2547
2609
|
const object = this.findObjectById(id);
|
|
2548
2610
|
if (object) {
|
|
2549
2611
|
const removeObjectCommand = new RemoveObjectCommand(this, this, object, skipHistory);
|
|
2550
|
-
this.
|
|
2612
|
+
this.commandManager.executeCommand(removeObjectCommand);
|
|
2551
2613
|
}
|
|
2552
2614
|
}
|
|
2553
2615
|
copy() {
|
|
@@ -2581,7 +2643,7 @@ class KritzelCore {
|
|
|
2581
2643
|
const addCopiedObjectsCommands = this._store.state.copiedObjects.objects.map(obj => new AddObjectCommand(this, this, obj));
|
|
2582
2644
|
const addCopiedObjectsAsSelectionGroupCommand = new AddSelectionGroupCommand(this, this, this._store.state.copiedObjects, previousSelectionGroup);
|
|
2583
2645
|
commands.push(...addCopiedObjectsCommands, addCopiedObjectsAsSelectionGroupCommand);
|
|
2584
|
-
this.
|
|
2646
|
+
this.commandManager.executeCommand(new BatchCommand(this, this, commands));
|
|
2585
2647
|
this._store.state.isSelecting = false;
|
|
2586
2648
|
this._store.state.copiedObjects = this._store.state.selectionGroup.copy();
|
|
2587
2649
|
this._store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
|
|
@@ -2596,7 +2658,7 @@ class KritzelCore {
|
|
|
2596
2658
|
}
|
|
2597
2659
|
return new UpdateObjectCommand(this, this, obj, { zIndex: obj.zIndex + 1 });
|
|
2598
2660
|
});
|
|
2599
|
-
this.
|
|
2661
|
+
this.commandManager.executeCommand(new BatchCommand(this, this, increaseZIndexCommands));
|
|
2600
2662
|
}
|
|
2601
2663
|
sendBackward(object) {
|
|
2602
2664
|
const objects = object ? [object] : this._store.state.selectionGroup.objects;
|
|
@@ -2608,7 +2670,7 @@ class KritzelCore {
|
|
|
2608
2670
|
}
|
|
2609
2671
|
return new UpdateObjectCommand(this, this, obj, { zIndex: obj.zIndex - 1 });
|
|
2610
2672
|
});
|
|
2611
|
-
this.
|
|
2673
|
+
this.commandManager.executeCommand(new BatchCommand(this, this, decreaseZIndexCommands));
|
|
2612
2674
|
}
|
|
2613
2675
|
bringToFront(object) {
|
|
2614
2676
|
const objects = object ? [object] : this._store.state.selectionGroup.objects;
|
|
@@ -2617,7 +2679,7 @@ class KritzelCore {
|
|
|
2617
2679
|
const increaseZIndexCommands = objects.map(obj => {
|
|
2618
2680
|
return new UpdateObjectCommand(this, this, obj, { zIndex: max });
|
|
2619
2681
|
});
|
|
2620
|
-
this.
|
|
2682
|
+
this.commandManager.executeCommand(new BatchCommand(this, this, increaseZIndexCommands));
|
|
2621
2683
|
}
|
|
2622
2684
|
sendToBack(object) {
|
|
2623
2685
|
const objects = object ? [object] : this._store.state.selectionGroup.objects;
|
|
@@ -2626,7 +2688,7 @@ class KritzelCore {
|
|
|
2626
2688
|
const decreaseZIndexCommands = objects.map(obj => {
|
|
2627
2689
|
return new UpdateObjectCommand(this, this, obj, { zIndex: min });
|
|
2628
2690
|
});
|
|
2629
|
-
this.
|
|
2691
|
+
this.commandManager.executeCommand(new BatchCommand(this, this, decreaseZIndexCommands));
|
|
2630
2692
|
}
|
|
2631
2693
|
selectObjects(objects) {
|
|
2632
2694
|
if (objects.length === 0) {
|
|
@@ -2642,7 +2704,7 @@ class KritzelCore {
|
|
|
2642
2704
|
if (objects.length === 1) {
|
|
2643
2705
|
selectionGroup.rotation = selectionGroup.objects[0].rotation;
|
|
2644
2706
|
}
|
|
2645
|
-
this.
|
|
2707
|
+
this.commandManager.executeCommand(new AddSelectionGroupCommand(this, this, selectionGroup));
|
|
2646
2708
|
}
|
|
2647
2709
|
selectAllObjectsInViewport() {
|
|
2648
2710
|
const objectsInViewport = this._store.state.objectsMap
|
|
@@ -2659,13 +2721,13 @@ class KritzelCore {
|
|
|
2659
2721
|
if (objectsInViewport.length === 1) {
|
|
2660
2722
|
selectionGroup.rotation = selectionGroup.objects[0].rotation;
|
|
2661
2723
|
}
|
|
2662
|
-
this.
|
|
2724
|
+
this.commandManager.executeCommand(new AddSelectionGroupCommand(this, this, selectionGroup));
|
|
2663
2725
|
this._store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
|
|
2664
2726
|
}
|
|
2665
2727
|
}
|
|
2666
2728
|
clearSelection() {
|
|
2667
|
-
const command = new RemoveSelectionGroupCommand(this, this
|
|
2668
|
-
this.
|
|
2729
|
+
const command = new RemoveSelectionGroupCommand(this, this);
|
|
2730
|
+
this.commandManager.executeCommand(command);
|
|
2669
2731
|
this._store.state.selectionGroup = null;
|
|
2670
2732
|
this._store.state.selectionBox = null;
|
|
2671
2733
|
this._store.state.isSelecting = false;
|
|
@@ -2676,11 +2738,9 @@ class KritzelCore {
|
|
|
2676
2738
|
resetActiveText() {
|
|
2677
2739
|
if (this._store.state.activeText) {
|
|
2678
2740
|
if (this._store.state.activeText.isEmpty) {
|
|
2679
|
-
console.log('Deleting empty text object', this._store.state.activeText.id);
|
|
2680
2741
|
this.deleteObject(this._store.state.activeText.id, true);
|
|
2681
2742
|
}
|
|
2682
2743
|
else {
|
|
2683
|
-
console.log('Saving active text object before resetting', this._store.state.activeText.id);
|
|
2684
2744
|
this._store.state.activeText.save();
|
|
2685
2745
|
}
|
|
2686
2746
|
}
|
|
@@ -2737,15 +2797,21 @@ class KritzelCore {
|
|
|
2737
2797
|
const worldY = yWithoutTranslate / this._store.state.scale;
|
|
2738
2798
|
return { x: worldX, y: worldY };
|
|
2739
2799
|
}
|
|
2800
|
+
beforeWorkspaceChange() {
|
|
2801
|
+
this.resetActiveText();
|
|
2802
|
+
this.clearSelection();
|
|
2803
|
+
this._store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
|
|
2804
|
+
}
|
|
2740
2805
|
}
|
|
2741
2806
|
|
|
2742
|
-
const kritzelEngineCss = ":host{display:block;position:relative;height:100%;width:100%;overflow:hidden;background-color:var(--kritzel-engine-background-color, #ffffff)}:host,:host *{touch-action:none;user-select:none}.ProseMirror{outline:none}p{margin:0;padding:0}.debug-panel{position:absolute;pointer-events:none;top:0;right:0}.origin{position:relative;top:0;left:0;height:0;width:0;pointer-events:none;-webkit-transform-origin:top left;-moz-transform-origin:top left;transform-origin:top left;overflow:visible}.object{overflow:visible}.resize-handle-overlay.top-left,.resize-handle-overlay.bottom-right{cursor:nwse-resize}.resize-handle-overlay.top-right,.resize-handle-overlay.bottom-left{cursor:nesw-resize}.rotation-handle-overlay{cursor:grab}.PlaygroundEditorTheme__quote{margin:0;margin-left:20px;margin-bottom:10px;font-size:15px;color:rgb(101, 103, 107);border-left-color:rgb(206, 208, 212);border-left-width:4px;border-left-style:solid;padding-left:16px}";
|
|
2807
|
+
const kritzelEngineCss = ":host{display:block;position:relative;height:100%;width:100%;overflow:hidden;background-color:var(--kritzel-engine-background-color, #ffffff)}:host,:host *{touch-action:none;user-select:none}.ProseMirror{outline:none}p,h1,h2,h3,h4,h5,h6,blockquote,pre{margin:0;padding:0}.debug-panel{position:absolute;pointer-events:none;top:0;right:0}.origin{position:relative;top:0;left:0;height:0;width:0;pointer-events:none;-webkit-transform-origin:top left;-moz-transform-origin:top left;transform-origin:top left;overflow:visible}.object{overflow:visible}.resize-handle-overlay.top-left,.resize-handle-overlay.bottom-right{cursor:nwse-resize}.resize-handle-overlay.top-right,.resize-handle-overlay.bottom-left{cursor:nesw-resize}.rotation-handle-overlay{cursor:grab}.PlaygroundEditorTheme__quote{margin:0;margin-left:20px;margin-bottom:10px;font-size:15px;color:rgb(101, 103, 107);border-left-color:rgb(206, 208, 212);border-left-width:4px;border-left-style:solid;padding-left:16px}";
|
|
2743
2808
|
|
|
2744
2809
|
const KritzelEngine = /*@__PURE__*/ proxyCustomElement(class KritzelEngine extends H {
|
|
2745
2810
|
get host() { return this; }
|
|
2746
2811
|
workspace;
|
|
2747
2812
|
onWorkspaceChange(newWorkspace) {
|
|
2748
2813
|
if (this.core.store.state.activeWorkspace !== newWorkspace) {
|
|
2814
|
+
this.core.beforeWorkspaceChange();
|
|
2749
2815
|
this.core.initializeWorkspace(newWorkspace);
|
|
2750
2816
|
}
|
|
2751
2817
|
}
|
|
@@ -2931,19 +2997,19 @@ const KritzelEngine = /*@__PURE__*/ proxyCustomElement(class KritzelEngine exten
|
|
|
2931
2997
|
object.scale = object.scale ? object.scale : this.core.store.state.scale;
|
|
2932
2998
|
object.zIndex = this.core.store.currentZIndex;
|
|
2933
2999
|
const command = new AddObjectCommand(this.core, this, object);
|
|
2934
|
-
this.core.
|
|
3000
|
+
this.core.commandManager.executeCommand(command);
|
|
2935
3001
|
return object;
|
|
2936
3002
|
}
|
|
2937
3003
|
async updateObject(object, updatedProperties) {
|
|
2938
3004
|
this.core.deselectAllObjects();
|
|
2939
3005
|
const command = new UpdateObjectCommand(this.core, this, object, updatedProperties);
|
|
2940
|
-
this.core.
|
|
3006
|
+
this.core.commandManager.executeCommand(command);
|
|
2941
3007
|
return object;
|
|
2942
3008
|
}
|
|
2943
3009
|
async removeObject(object) {
|
|
2944
3010
|
this.core.deselectAllObjects();
|
|
2945
3011
|
const command = new RemoveObjectCommand(this.core, this, object);
|
|
2946
|
-
this.core.
|
|
3012
|
+
this.core.commandManager.executeCommand(command);
|
|
2947
3013
|
return object;
|
|
2948
3014
|
}
|
|
2949
3015
|
async getSelectedObjects() {
|
|
@@ -2967,7 +3033,7 @@ const KritzelEngine = /*@__PURE__*/ proxyCustomElement(class KritzelEngine exten
|
|
|
2967
3033
|
async centerObjectInViewport(object) {
|
|
2968
3034
|
object.centerInViewport();
|
|
2969
3035
|
const command = new UpdateObjectCommand(this.core, this, object, object);
|
|
2970
|
-
this.core.
|
|
3036
|
+
this.core.commandManager.executeCommand(command);
|
|
2971
3037
|
return object;
|
|
2972
3038
|
}
|
|
2973
3039
|
async getCopiedObjects() {
|
|
@@ -3038,11 +3104,16 @@ const KritzelEngine = /*@__PURE__*/ proxyCustomElement(class KritzelEngine exten
|
|
|
3038
3104
|
_handleActiveToolChange(activeTool) {
|
|
3039
3105
|
if (!(activeTool instanceof KritzelSelectionTool)) {
|
|
3040
3106
|
this.core.clearSelection();
|
|
3107
|
+
this.core.store.state.selectionBox = null;
|
|
3108
|
+
this.core.store.state.isSelecting = false;
|
|
3109
|
+
this.core.store.state.isResizeHandleSelected = false;
|
|
3110
|
+
this.core.store.state.isRotationHandleSelected = false;
|
|
3041
3111
|
}
|
|
3042
3112
|
this.core.store.state.skipContextMenu = false;
|
|
3043
3113
|
this.core.store.state.copiedObjects = null;
|
|
3044
3114
|
this.activeToolChange.emit(activeTool);
|
|
3045
3115
|
KritzelKeyboardHelper.forceHideKeyboard();
|
|
3116
|
+
this.core.rerender();
|
|
3046
3117
|
}
|
|
3047
3118
|
render() {
|
|
3048
3119
|
const computedStyle = window.getComputedStyle(this.host);
|
|
@@ -3051,7 +3122,7 @@ const KritzelEngine = /*@__PURE__*/ proxyCustomElement(class KritzelEngine exten
|
|
|
3051
3122
|
const baseHandleTouchSize = baseHandleSize * 2 < 14 ? 14 : baseHandleSize;
|
|
3052
3123
|
const viewportCenterX = this.core.store.state.viewportWidth / 2 + this.core.store.state.translateX;
|
|
3053
3124
|
const viewportCenterY = this.core.store.state.viewportHeight / 2 + this.core.store.state.translateY;
|
|
3054
|
-
return (h(Host, { key: '
|
|
3125
|
+
return (h(Host, { key: 'f7fc3c4c6a91ccdabb83832671e36ebf49ce56c0' }, h("div", { key: 'f6a2ce9e78a1d0e9ea0590035f5b8811f62c8633', class: "debug-panel", style: { display: this.core.store.state.debugInfo.showViewportInfo ? 'block' : 'none' } }, h("div", { key: '5752045746f275223bd42c16dd7e848adaaae9f2' }, "ActiveWorkspaceId: ", this.core.store.state?.activeWorkspace?.id), h("div", { key: 'd99595b135243a7b69a583be33f7b195908ec716' }, "ActiveWorkspaceName: ", this.core.store.state?.activeWorkspace?.name), h("div", { key: '7cecdccad47d3957370ea923f3dfbcd618b5d28e' }, "TranslateX: ", this.core.store.state?.translateX), h("div", { key: '3a5ed989f2343eda92c7c81855c785dbf58fa770' }, "TranslateY: ", this.core.store.state?.translateY), h("div", { key: 'b78074a29463276300ce498b2ddb328cef9026cd' }, "ViewportWidth: ", this.core.store.state?.viewportWidth), h("div", { key: 'd4c8dcfddfa1984eedf695d74f9401fc3284c60b' }, "ViewportHeight: ", this.core.store.state?.viewportHeight), h("div", { key: '566b6dc9afd904ee49e59587ed664e5f46decead' }, "Scale: ", this.core.store.state?.scale), h("div", { key: 'd3feb7a11727c4337ca75a26b3275a0b5d639961' }, "ActiveTool: ", this.core.store.state?.activeTool?.name), h("div", { key: '3991c34df53c7d6fd97c83b0d4b8c9fb438c88fc' }, "HasViewportChanged: ", this.core.store.state?.hasViewportChanged ? 'true' : 'false'), h("div", { key: '5a4244b43871f96d08144483352064804f04e538' }, "IsEnabled: ", this.core.store.state?.isEnabled ? 'true' : 'false'), h("div", { key: '197655c09e24d624ea4dcd312169aeb449ed57ce' }, "IsScaling: ", this.core.store.state?.isScaling ? 'true' : 'false'), h("div", { key: 'a3e4a75a9853c8cee1485cbf8621377466babf90' }, "IsPanning: ", this.core.store.state?.isPanning ? 'true' : 'false'), h("div", { key: '171e0df3e1856e9fe8cd18be5c258c7472317453' }, "IsSelecting: ", this.isSelecting ? 'true' : 'false'), h("div", { key: '66f5a56333dbac1da34e01f5ee1f577e1a964701' }, "IsSelectionActive: ", this.isSelectionActive ? 'true' : 'false'), h("div", { key: 'b869e07b76c2fa21ab5383788e81a40ffdad1b2c' }, "IsResizeHandleSelected: ", this.core.store.state.isResizeHandleSelected ? 'true' : 'false'), h("div", { key: 'd936326f8ea675e170d418f4e97a5d46057bc385' }, "IsRotationHandleSelected: ", this.core.store.state.isRotationHandleSelected ? 'true' : 'false'), h("div", { key: '8594489402204ae4a9cd1bc7795169dbfa2d633d' }, "IsDrawing: ", this.core.store.state.isDrawing ? 'true' : 'false'), h("div", { key: 'f7a254dc35bfe6d42c32d25d0f277b211d86b03f' }, "IsWriting: ", this.core.store.state.isWriting ? 'true' : 'false'), h("div", { key: '053ebd21504bfa3622e4b3e965e39f707c19794d' }, "PointerX: ", this.core.store.state?.pointerX), h("div", { key: 'f330c65821326062874441355352134927760d61' }, "PointerY: ", this.core.store.state?.pointerY), h("div", { key: 'f6c6902562f3e74afa3a0426e72b0c803977250b' }, "SelectedObjects: ", this.core.store.state.selectionGroup?.objects.length || 0), h("div", { key: '99a2d4280d5e79d7dd9a7a27d809e70f90eac38b' }, "ViewportCenter: (", viewportCenterX.toFixed(2), ", ", viewportCenterY.toFixed(2), ")")), h("div", { key: 'dac21fa0ac9487b74c89ac7408e80d9fb89b4558', id: "origin", class: "origin", style: {
|
|
3055
3126
|
transform: `matrix(${this.core.store.state?.scale}, 0, 0, ${this.core.store.state?.scale}, ${this.core.store.state?.translateX}, ${this.core.store.state?.translateY})`,
|
|
3056
3127
|
} }, this.core.store.state.objectsMap.allObjects()?.map(object => {
|
|
3057
3128
|
return (h("div", { key: object.id, style: {
|
|
@@ -3079,17 +3150,17 @@ const KritzelEngine = /*@__PURE__*/ proxyCustomElement(class KritzelEngine exten
|
|
|
3079
3150
|
borderStyle: 'solid',
|
|
3080
3151
|
padding: object.padding + 'px',
|
|
3081
3152
|
overflow: 'visible',
|
|
3082
|
-
} }, KritzelClassHelper.isInstanceOf(object, 'KritzelPath') && (h("svg", { ref: el =>
|
|
3153
|
+
} }, KritzelClassHelper.isInstanceOf(object, 'KritzelPath') && (h("svg", { ref: el => object.mount(el), xmlns: "http://www.w3.org/2000/svg", style: {
|
|
3083
3154
|
height: object?.height.toString(),
|
|
3084
3155
|
width: object?.width.toString(),
|
|
3085
3156
|
position: 'absolute',
|
|
3086
3157
|
overflow: 'visible',
|
|
3087
|
-
}, viewBox: object?.viewBox }, h("path", { d: object?.d, fill: object.fill, stroke: object?.stroke }))), KritzelClassHelper.isInstanceOf(object, 'KritzelImage') && (h("img", { ref: el =>
|
|
3158
|
+
}, viewBox: object?.viewBox }, h("path", { d: object?.d, fill: object.fill, stroke: object?.stroke }))), KritzelClassHelper.isInstanceOf(object, 'KritzelImage') && (h("img", { ref: el => object.mount(el), src: object.src, style: {
|
|
3088
3159
|
width: '100%',
|
|
3089
3160
|
height: '100%',
|
|
3090
3161
|
userSelect: 'none',
|
|
3091
3162
|
pointerEvents: 'none',
|
|
3092
|
-
}, draggable: false, onDragStart: e => e.preventDefault() })), KritzelClassHelper.isInstanceOf(object, 'KritzelText') && (h("div", { ref: el =>
|
|
3163
|
+
}, draggable: false, onDragStart: e => e.preventDefault() })), KritzelClassHelper.isInstanceOf(object, 'KritzelText') && (h("div", { ref: el => object.mount(el), onPointerDown: e => object.handlePointerDown(e), onPointerMove: e => object.handlePointerMove(e), onPointerUp: e => object.handlePointerUp(e), style: {
|
|
3093
3164
|
minWidth: object.initialWidth + 'px',
|
|
3094
3165
|
minHeight: object.initialHeight + 'px',
|
|
3095
3166
|
maxWidth: '500px',
|
|
@@ -3098,17 +3169,17 @@ const KritzelEngine = /*@__PURE__*/ proxyCustomElement(class KritzelEngine exten
|
|
|
3098
3169
|
transformOrigin: 'top left',
|
|
3099
3170
|
transform: `scale(${object.scaleFactor})`,
|
|
3100
3171
|
backgroundColor: object.backgroundColor,
|
|
3101
|
-
overflow: 'visible'
|
|
3102
|
-
} })), KritzelClassHelper.isInstanceOf(object, 'KritzelCustomElement') && (h("div", { ref: el =>
|
|
3172
|
+
overflow: 'visible',
|
|
3173
|
+
} })), KritzelClassHelper.isInstanceOf(object, 'KritzelCustomElement') && (h("div", { ref: el => object.mount(el), style: {
|
|
3103
3174
|
width: '100%',
|
|
3104
3175
|
height: '100%',
|
|
3105
3176
|
pointerEvents: 'auto',
|
|
3106
3177
|
overflow: 'hidden',
|
|
3107
3178
|
display: 'block',
|
|
3108
|
-
} })), KritzelClassHelper.isInstanceOf(object, 'KritzelSelectionGroup') && (h("div", { ref: el =>
|
|
3179
|
+
} })), KritzelClassHelper.isInstanceOf(object, 'KritzelSelectionGroup') && (h("div", { ref: el => object.mount(el), style: {
|
|
3109
3180
|
width: '100%',
|
|
3110
3181
|
height: '100%',
|
|
3111
|
-
} })), KritzelClassHelper.isInstanceOf(object, 'KrtizelSelectionBox') && (h("div", { ref: el =>
|
|
3182
|
+
} })), KritzelClassHelper.isInstanceOf(object, 'KrtizelSelectionBox') && (h("div", { ref: el => object.mount(el), style: {
|
|
3112
3183
|
width: '100%',
|
|
3113
3184
|
height: '100%',
|
|
3114
3185
|
backgroundColor: KritzelDevicesHelper.isFirefox() ? object.backgroundColor : 'transparent',
|
|
@@ -3155,7 +3226,7 @@ const KritzelEngine = /*@__PURE__*/ proxyCustomElement(class KritzelEngine exten
|
|
|
3155
3226
|
}, visibility: object.isSelected && !this.isSelecting ? 'visible' : 'hidden' }), h("circle", { class: "rotation-handle-overlay", cx: object.totalWidth / 2, cy: -((15 * object.scale) / this.core.store.state?.scale), r: `${(baseHandleTouchSize * object.scale) / this.core.store.state?.scale}`, style: {
|
|
3156
3227
|
fill: 'transparent',
|
|
3157
3228
|
cursor: 'grab',
|
|
3158
|
-
}, visibility: object.isSelected && !this.isSelecting ? 'visible' : 'hidden' }), h("g", { style: { display: this.core.store.state.debugInfo.showObjectInfo ? 'block' : 'none', pointerEvents: 'none' } }, h("foreignObject", { x: object.totalWidth.toString(), y: "0", width: "400px", height: "160px", style: { minHeight: '0', minWidth: '0', display: object.isDebugInfoVisible ? 'block' : 'none' } }, h("div", { style: { width: '100%', height: '100%' } }, h("div", { style: {
|
|
3229
|
+
}, visibility: object.isSelected && !this.isSelecting ? 'visible' : 'hidden' }), h("g", { style: { display: this.core.store.state.debugInfo.showObjectInfo ? 'block' : 'none', pointerEvents: 'none' } }, h("foreignObject", { x: object.totalWidth.toString(), y: "0", width: "400px", height: "160px", style: { minHeight: '0', minWidth: '0', display: object.isDebugInfoVisible ? 'block' : 'none' } }, h("div", { style: { width: '100%', height: '100%' } }, h("div", { style: { whitespace: 'nowrap' } }, "Id: ", object.id), h("div", { style: { whiteSpace: 'nowrap' } }, "width: ", object.width), h("div", { style: { whiteSpace: 'nowrap' } }, "height: ", object.height)))))));
|
|
3159
3230
|
}), h("svg", { key: "current-path", class: "object", xmlns: "http://www.w3.org/2000/svg", width: this.core.store.state.currentPath?.width, height: this.core.store.state.currentPath?.height, style: {
|
|
3160
3231
|
left: '0',
|
|
3161
3232
|
top: '0',
|
|
@@ -3164,7 +3235,7 @@ const KritzelEngine = /*@__PURE__*/ proxyCustomElement(class KritzelEngine exten
|
|
|
3164
3235
|
transform: this.core.store.state.currentPath?.transformationMatrix,
|
|
3165
3236
|
transformOrigin: 'top left',
|
|
3166
3237
|
overflow: 'visible',
|
|
3167
|
-
}, viewBox: this.core.store.state.currentPath?.viewBox }, h("path", { key: '
|
|
3238
|
+
}, viewBox: this.core.store.state.currentPath?.viewBox }, h("path", { key: 'f3aaf24804430eeb0308a15ae4a38df302d0566f', d: this.core.store.state.currentPath?.d, fill: this.core.store.state.currentPath?.fill, stroke: this.core.store.state.currentPath?.stroke }))), this.core.store.state.isContextMenuVisible && (h("kritzel-context-menu", { key: 'd99a76a11b613167d5723d1c16e9289e45eee8a3', class: "context-menu", ref: el => (this.contextMenuElement = el), items: this.core.store.state.contextMenuItems, objects: this.core.store.state.selectionGroup?.objects || [], style: {
|
|
3168
3239
|
position: 'fixed',
|
|
3169
3240
|
left: `${this.core.store.state.contextMenuX}px`,
|
|
3170
3241
|
top: `${this.core.store.state.contextMenuY}px`,
|
|
@@ -3175,7 +3246,7 @@ const KritzelEngine = /*@__PURE__*/ proxyCustomElement(class KritzelEngine exten
|
|
|
3175
3246
|
y: (-this.core.store.state.translateY + this.core.store.state.contextMenuY) / this.core.store.state.scale,
|
|
3176
3247
|
}, this.core.store.state.selectionGroup?.objects);
|
|
3177
3248
|
this.hideContextMenu();
|
|
3178
|
-
}, onClose: () => this.hideContextMenu() })), this.core.store.state?.activeTool instanceof KritzelEraserTool && !this.core.store.state.isScaling && h("kritzel-cursor-trail", { key: '
|
|
3249
|
+
}, onClose: () => this.hideContextMenu() })), this.core.store.state?.activeTool instanceof KritzelEraserTool && !this.core.store.state.isScaling && h("kritzel-cursor-trail", { key: 'fc7c474156442dfb5c057ef4ed4f0e5f015c2502', core: this.core })));
|
|
3179
3250
|
}
|
|
3180
3251
|
static get watchers() { return {
|
|
3181
3252
|
"workspace": ["onWorkspaceChange"],
|
|
@@ -3255,6 +3326,6 @@ function defineCustomElement() {
|
|
|
3255
3326
|
}
|
|
3256
3327
|
|
|
3257
3328
|
export { ABSOLUTE_SCALE_MAX as A, KritzelImage as K, KritzelEraserTool as a, KritzelImageTool as b, KritzelSelectionTool as c, KritzelEngine as d, defineCustomElement as e, ABSOLUTE_SCALE_MIN as f };
|
|
3258
|
-
//# sourceMappingURL=p-
|
|
3329
|
+
//# sourceMappingURL=p-CziwfEQh.js.map
|
|
3259
3330
|
|
|
3260
|
-
//# sourceMappingURL=p-
|
|
3331
|
+
//# sourceMappingURL=p-CziwfEQh.js.map
|