kritzel-stencil 0.0.108 → 0.0.110
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/kritzel-brush-style_18.cjs.entry.js +854 -833
- package/dist/cjs/kritzel-brush-style_18.cjs.entry.js.map +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/stencil.cjs.js +1 -1
- package/dist/collection/classes/commands/remove-selection-group.command.js +1 -1
- package/dist/collection/classes/commands/remove-selection-group.command.js.map +1 -1
- package/dist/collection/classes/handlers/context-menu.handler.js +2 -47
- package/dist/collection/classes/handlers/context-menu.handler.js.map +1 -1
- package/dist/collection/classes/handlers/move.handler.js +62 -55
- package/dist/collection/classes/handlers/move.handler.js.map +1 -1
- package/dist/collection/classes/handlers/resize.handler.js +122 -113
- package/dist/collection/classes/handlers/resize.handler.js.map +1 -1
- package/dist/collection/classes/handlers/rotation.handler.js +74 -66
- package/dist/collection/classes/handlers/rotation.handler.js.map +1 -1
- package/dist/collection/classes/handlers/selection.handler.js +59 -50
- package/dist/collection/classes/handlers/selection.handler.js.map +1 -1
- package/dist/collection/classes/objects/base-object.class.js +3 -0
- package/dist/collection/classes/objects/base-object.class.js.map +1 -1
- package/dist/collection/classes/objects/text.class.js +11 -1
- package/dist/collection/classes/objects/text.class.js.map +1 -1
- package/dist/collection/classes/tools/base-tool.class.js +3 -18
- package/dist/collection/classes/tools/base-tool.class.js.map +1 -1
- package/dist/collection/classes/tools/brush-tool.class.js +79 -71
- package/dist/collection/classes/tools/brush-tool.class.js.map +1 -1
- package/dist/collection/classes/tools/eraser-tool.class.js +61 -56
- package/dist/collection/classes/tools/eraser-tool.class.js.map +1 -1
- package/dist/collection/classes/tools/selection-tool.class.js +93 -73
- package/dist/collection/classes/tools/selection-tool.class.js.map +1 -1
- package/dist/collection/classes/tools/text-tool.class.js +73 -70
- package/dist/collection/classes/tools/text-tool.class.js.map +1 -1
- package/dist/collection/classes/viewport.class.js +76 -69
- package/dist/collection/classes/viewport.class.js.map +1 -1
- package/dist/collection/components/core/kritzel-editor/kritzel-editor.css +6 -0
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.css +6 -0
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +66 -120
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.js.map +1 -1
- package/dist/collection/components/ui/kritzel-context-menu/kritzel-context-menu.js +1 -16
- package/dist/collection/components/ui/kritzel-context-menu/kritzel-context-menu.js.map +1 -1
- package/dist/collection/components/ui/kritzel-controls/kritzel-controls.css +10 -2
- package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js +9 -4
- package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js.map +1 -1
- package/dist/collection/configs/default-engine-state.js +1 -1
- package/dist/collection/configs/default-engine-state.js.map +1 -1
- package/dist/collection/helpers/devices.helper.js +6 -0
- package/dist/collection/helpers/devices.helper.js.map +1 -0
- package/dist/collection/helpers/event.helper.js +43 -34
- package/dist/collection/helpers/event.helper.js.map +1 -1
- package/dist/collection/interfaces/engine-state.interface.js.map +1 -1
- package/dist/collection/interfaces/object.interface.js.map +1 -1
- package/dist/collection/interfaces/tool.interface.js.map +1 -1
- package/dist/components/kritzel-context-menu.js +1 -1
- package/dist/components/kritzel-controls.js +1 -1
- package/dist/components/kritzel-editor.js +5 -5
- package/dist/components/kritzel-editor.js.map +1 -1
- package/dist/components/kritzel-engine.js +1 -1
- package/dist/components/{p-BNfHRlWL.js → p-7Ns73-wN.js} +237 -220
- package/dist/components/p-7Ns73-wN.js.map +1 -0
- package/dist/components/{p-Cbu5RSmC.js → p-BmAloSfd.js} +3 -4
- package/dist/components/p-BmAloSfd.js.map +1 -0
- package/dist/components/{p-Box62paJ.js → p-Ch6TgHX3.js} +18 -8
- package/dist/components/p-Ch6TgHX3.js.map +1 -0
- package/dist/components/{p-CqJr3YCp.js → p-mD9nNnTx.js} +618 -622
- package/dist/components/p-mD9nNnTx.js.map +1 -0
- package/dist/esm/kritzel-brush-style_18.entry.js +854 -833
- package/dist/esm/kritzel-brush-style_18.entry.js.map +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/stencil.js +1 -1
- package/dist/stencil/p-d23bb1ad.entry.js +2 -0
- package/dist/stencil/p-d23bb1ad.entry.js.map +1 -0
- package/dist/stencil/stencil.esm.js +1 -1
- package/dist/types/classes/handlers/context-menu.handler.d.ts +1 -2
- package/dist/types/classes/handlers/move.handler.d.ts +3 -6
- package/dist/types/classes/handlers/resize.handler.d.ts +3 -6
- package/dist/types/classes/handlers/rotation.handler.d.ts +3 -6
- package/dist/types/classes/handlers/selection.handler.d.ts +3 -6
- package/dist/types/classes/objects/base-object.class.d.ts +1 -0
- package/dist/types/classes/objects/text.class.d.ts +1 -0
- package/dist/types/classes/tools/base-tool.class.d.ts +3 -8
- package/dist/types/classes/tools/brush-tool.class.d.ts +3 -6
- package/dist/types/classes/tools/eraser-tool.class.d.ts +3 -6
- package/dist/types/classes/tools/selection-tool.class.d.ts +4 -7
- package/dist/types/classes/tools/text-tool.class.d.ts +2 -4
- package/dist/types/classes/viewport.class.d.ts +3 -6
- package/dist/types/components/core/kritzel-engine/kritzel-engine.d.ts +5 -10
- package/dist/types/components/ui/kritzel-context-menu/kritzel-context-menu.d.ts +0 -1
- package/dist/types/components/ui/kritzel-controls/kritzel-controls.d.ts +1 -0
- package/dist/types/components.d.ts +0 -2
- package/dist/types/helpers/devices.helper.d.ts +3 -0
- package/dist/types/helpers/event.helper.d.ts +2 -6
- package/dist/types/interfaces/engine-state.interface.d.ts +1 -1
- package/dist/types/interfaces/object.interface.d.ts +1 -0
- package/dist/types/interfaces/tool.interface.d.ts +3 -8
- package/package.json +1 -1
- package/dist/components/p-BNfHRlWL.js.map +0 -1
- package/dist/components/p-Box62paJ.js.map +0 -1
- package/dist/components/p-Cbu5RSmC.js.map +0 -1
- package/dist/components/p-CqJr3YCp.js.map +0 -1
- package/dist/stencil/p-3a7d7b58.entry.js +0 -2
- package/dist/stencil/p-3a7d7b58.entry.js.map +0 -1
|
@@ -15,43 +15,52 @@ class KritzelEventHelper {
|
|
|
15
15
|
static isMainMouseWheel(event) {
|
|
16
16
|
return Math.abs(event.deltaY) > 0 && Math.abs(event.deltaX) === 0 && Number.isInteger(event.deltaY);
|
|
17
17
|
}
|
|
18
|
-
static
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
static isPointerEventOnContextMenu(event) {
|
|
19
|
+
const path = event.composedPath();
|
|
20
|
+
const contextMenu = path.find(element => element.classList && element.classList.contains('context-menu'));
|
|
21
|
+
return !!contextMenu;
|
|
22
|
+
}
|
|
23
|
+
static onLongTouchPress(event, onSuccess, onCancel) {
|
|
24
|
+
if (event.pointerType !== 'touch') {
|
|
25
|
+
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
26
|
+
return () => { };
|
|
27
|
+
}
|
|
28
|
+
const longPressTimeout = 400;
|
|
29
|
+
const moveThreshold = 10;
|
|
30
|
+
const startX = event.clientX;
|
|
31
|
+
const startY = event.clientY;
|
|
32
|
+
const target = event.target;
|
|
33
|
+
const timer = setTimeout(() => {
|
|
34
|
+
removeListeners();
|
|
35
|
+
onSuccess(event);
|
|
36
|
+
}, longPressTimeout);
|
|
37
|
+
const cancel = () => {
|
|
38
|
+
clearTimeout(timer);
|
|
39
|
+
removeListeners();
|
|
40
|
+
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
41
|
+
};
|
|
42
|
+
const onPointerMove = (e) => {
|
|
43
|
+
if (Math.abs(e.clientX - startX) > moveThreshold || Math.abs(e.clientY - startY) > moveThreshold) {
|
|
44
|
+
cancel();
|
|
27
45
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
static notifyTwoFingerTouch() {
|
|
48
|
-
KritzelEventHelper.twoFingerTouchDetected = true;
|
|
46
|
+
};
|
|
47
|
+
const onPointerUp = () => {
|
|
48
|
+
cancel();
|
|
49
|
+
};
|
|
50
|
+
const onPointerCancel = () => {
|
|
51
|
+
cancel();
|
|
52
|
+
};
|
|
53
|
+
const removeListeners = () => {
|
|
54
|
+
target.removeEventListener('pointermove', onPointerMove);
|
|
55
|
+
target.removeEventListener('pointerup', onPointerUp);
|
|
56
|
+
target.removeEventListener('pointercancel', onPointerCancel);
|
|
57
|
+
};
|
|
58
|
+
target.addEventListener('pointermove', onPointerMove, { passive: true });
|
|
59
|
+
target.addEventListener('pointerup', onPointerUp, { once: true });
|
|
60
|
+
target.addEventListener('pointercancel', onPointerCancel, { once: true });
|
|
61
|
+
return cancel;
|
|
49
62
|
}
|
|
50
63
|
}
|
|
51
|
-
KritzelEventHelper.lastTapTimestamp = 0;
|
|
52
|
-
KritzelEventHelper.tapTimeoutId = null;
|
|
53
|
-
KritzelEventHelper.doubleTapTimeout = 300;
|
|
54
|
-
KritzelEventHelper.twoFingerTouchDetected = false;
|
|
55
64
|
|
|
56
65
|
class KritzelBaseCommand {
|
|
57
66
|
constructor(store, initiator) {
|
|
@@ -312,6 +321,9 @@ class KritzelBaseObject {
|
|
|
312
321
|
copiedObject.isMounted = false;
|
|
313
322
|
return copiedObject;
|
|
314
323
|
}
|
|
324
|
+
onSelectedClick() {
|
|
325
|
+
// This method can be overridden by subclasses to handle click events when the object is selected.
|
|
326
|
+
}
|
|
315
327
|
revive(object) {
|
|
316
328
|
Object.assign(this, object);
|
|
317
329
|
return this;
|
|
@@ -448,28 +460,13 @@ class KritzelBaseTool {
|
|
|
448
460
|
onDeactivate() {
|
|
449
461
|
// default implementation
|
|
450
462
|
}
|
|
451
|
-
|
|
452
|
-
// default implementation
|
|
453
|
-
}
|
|
454
|
-
handleMouseMove(_event) {
|
|
455
|
-
// default implementation
|
|
456
|
-
}
|
|
457
|
-
handleMouseUp(_event) {
|
|
458
|
-
// default implementation
|
|
459
|
-
}
|
|
460
|
-
handleDoubleClick(_event) {
|
|
463
|
+
handlePointerDown(_event) {
|
|
461
464
|
// default implementation
|
|
462
465
|
}
|
|
463
|
-
|
|
466
|
+
handlePointerMove(_event) {
|
|
464
467
|
// default implementation
|
|
465
468
|
}
|
|
466
|
-
|
|
467
|
-
// default implementation
|
|
468
|
-
}
|
|
469
|
-
handleTouchMove(_event) {
|
|
470
|
-
// default implementation
|
|
471
|
-
}
|
|
472
|
-
handleTouchEnd(_event) {
|
|
469
|
+
handlePointerUp(_event) {
|
|
473
470
|
// default implementation
|
|
474
471
|
}
|
|
475
472
|
handleWheel(_event) {
|
|
@@ -492,90 +489,116 @@ class KritzelBrushTool extends KritzelBaseTool {
|
|
|
492
489
|
highlighter: ['#ffff00', '#ffb347', '#b4ffb4'],
|
|
493
490
|
};
|
|
494
491
|
}
|
|
495
|
-
|
|
496
|
-
if (
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
handleMouseMove(event) {
|
|
511
|
-
if (this._store.state.isDrawing) {
|
|
512
|
-
const x = event.clientX - this._store.offsetX;
|
|
513
|
-
const y = event.clientY - this._store.offsetY;
|
|
514
|
-
this._store.state.currentPath = KritzelPath.create(this._store, {
|
|
515
|
-
points: [...this._store.state.currentPath.points, [x, y]],
|
|
516
|
-
translateX: -this._store.state.translateX,
|
|
517
|
-
translateY: -this._store.state.translateY,
|
|
518
|
-
scale: this._store.state.scale,
|
|
519
|
-
fill: this.color,
|
|
520
|
-
strokeWidth: this.size,
|
|
521
|
-
});
|
|
522
|
-
this._store.rerender();
|
|
492
|
+
handlePointerDown(event) {
|
|
493
|
+
if (event.pointerType === 'mouse') {
|
|
494
|
+
if (KritzelEventHelper.isLeftClick(event)) {
|
|
495
|
+
this._store.state.isDrawing = true;
|
|
496
|
+
const x = event.clientX - this._store.offsetX;
|
|
497
|
+
const y = event.clientY - this._store.offsetY;
|
|
498
|
+
this._store.state.currentPath = KritzelPath.create(this._store, {
|
|
499
|
+
points: [[x, y]],
|
|
500
|
+
translateX: -this._store.state.translateX,
|
|
501
|
+
translateY: -this._store.state.translateY,
|
|
502
|
+
scale: this._store.state.scale,
|
|
503
|
+
fill: this.color,
|
|
504
|
+
strokeWidth: this.size,
|
|
505
|
+
});
|
|
506
|
+
}
|
|
523
507
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
this._store.state.
|
|
530
|
-
this._store.
|
|
508
|
+
if (event.pointerType === 'touch') {
|
|
509
|
+
const activePointers = Array.from(this._store.state.pointers.values());
|
|
510
|
+
if (activePointers.length === 1) {
|
|
511
|
+
const x = Math.round(activePointers[0].clientX - this._store.offsetX);
|
|
512
|
+
const y = Math.round(activePointers[0].clientY - this._store.offsetY);
|
|
513
|
+
this._store.state.isDrawing = true;
|
|
514
|
+
this._store.state.currentPath = KritzelPath.create(this._store, {
|
|
515
|
+
points: [[x, y]],
|
|
516
|
+
translateX: -this._store.state.translateX,
|
|
517
|
+
translateY: -this._store.state.translateY,
|
|
518
|
+
scale: this._store.state.scale,
|
|
519
|
+
fill: this.color,
|
|
520
|
+
strokeWidth: this.size,
|
|
521
|
+
});
|
|
522
|
+
this._store.rerender();
|
|
531
523
|
}
|
|
532
|
-
this._store.state.currentPath = undefined;
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
handleTouchStart(event) {
|
|
536
|
-
if (this._store.state.touchCount === 1) {
|
|
537
|
-
const x = Math.round(event.touches[0].clientX - this._store.offsetX);
|
|
538
|
-
const y = Math.round(event.touches[0].clientY - this._store.offsetY);
|
|
539
|
-
this._store.state.isDrawing = true;
|
|
540
|
-
this._store.state.currentPath = KritzelPath.create(this._store, {
|
|
541
|
-
points: [[x, y]],
|
|
542
|
-
translateX: -this._store.state.translateX,
|
|
543
|
-
translateY: -this._store.state.translateY,
|
|
544
|
-
scale: this._store.state.scale,
|
|
545
|
-
fill: this.color,
|
|
546
|
-
strokeWidth: this.size,
|
|
547
|
-
});
|
|
548
|
-
this._store.rerender();
|
|
549
524
|
}
|
|
550
525
|
}
|
|
551
|
-
|
|
552
|
-
if (
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
526
|
+
handlePointerMove(event) {
|
|
527
|
+
if (event.pointerType === 'mouse') {
|
|
528
|
+
if (this._store.state.isDrawing) {
|
|
529
|
+
const x = event.clientX - this._store.offsetX;
|
|
530
|
+
const y = event.clientY - this._store.offsetY;
|
|
531
|
+
this._store.state.currentPath = KritzelPath.create(this._store, {
|
|
532
|
+
points: [...this._store.state.currentPath.points, [x, y]],
|
|
533
|
+
translateX: -this._store.state.translateX,
|
|
534
|
+
translateY: -this._store.state.translateY,
|
|
535
|
+
scale: this._store.state.scale,
|
|
536
|
+
fill: this.color,
|
|
537
|
+
strokeWidth: this.size,
|
|
538
|
+
});
|
|
539
|
+
this._store.rerender();
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
if (event.pointerType === 'touch') {
|
|
543
|
+
const activePointers = Array.from(this._store.state.pointers.values());
|
|
544
|
+
if (activePointers.length === 1) {
|
|
545
|
+
const x = Math.round(activePointers[0].clientX - this._store.offsetX);
|
|
546
|
+
const y = Math.round(activePointers[0].clientY - this._store.offsetY);
|
|
547
|
+
this._store.state.currentPath = KritzelPath.create(this._store, {
|
|
548
|
+
points: [...this._store.state.currentPath.points, [x, y]],
|
|
549
|
+
translateX: -this._store.state.translateX,
|
|
550
|
+
translateY: -this._store.state.translateY,
|
|
551
|
+
scale: this._store.state.scale,
|
|
552
|
+
fill: this.color,
|
|
553
|
+
strokeWidth: this.size,
|
|
554
|
+
});
|
|
555
|
+
this._store.rerender();
|
|
556
|
+
}
|
|
564
557
|
}
|
|
565
558
|
}
|
|
566
|
-
|
|
567
|
-
if (
|
|
568
|
-
this._store.state.isDrawing
|
|
569
|
-
|
|
570
|
-
this._store.state.currentPath
|
|
571
|
-
|
|
559
|
+
handlePointerUp(event) {
|
|
560
|
+
if (event.pointerType === 'mouse') {
|
|
561
|
+
if (this._store.state.isDrawing) {
|
|
562
|
+
this._store.state.isDrawing = false;
|
|
563
|
+
if (this._store.state.currentPath) {
|
|
564
|
+
this._store.state.currentPath.zIndex = this._store.currentZIndex;
|
|
565
|
+
this._store.history.executeCommand(new AddObjectCommand(this._store, this, this._store.state.currentPath));
|
|
566
|
+
}
|
|
567
|
+
this._store.state.currentPath = undefined;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
if (event.pointerType === 'touch') {
|
|
571
|
+
if (this._store.state.isDrawing) {
|
|
572
|
+
this._store.state.isDrawing = false;
|
|
573
|
+
if (this._store.state.currentPath) {
|
|
574
|
+
this._store.state.currentPath.zIndex = this._store.currentZIndex;
|
|
575
|
+
this._store.history.executeCommand(new AddObjectCommand(this._store, this, this._store.state.currentPath));
|
|
576
|
+
}
|
|
577
|
+
this._store.state.currentPath = undefined;
|
|
578
|
+
this._store.rerender();
|
|
572
579
|
}
|
|
573
|
-
this._store.state.currentPath = undefined;
|
|
574
|
-
this._store.rerender();
|
|
575
580
|
}
|
|
576
581
|
}
|
|
577
582
|
}
|
|
578
583
|
|
|
584
|
+
class KritzelToolRegistry {
|
|
585
|
+
static registerTool(toolName, constructor, store) {
|
|
586
|
+
const toolInstance = new constructor(store);
|
|
587
|
+
toolInstance.name = toolName;
|
|
588
|
+
this.registry[toolName] = toolInstance;
|
|
589
|
+
return toolInstance;
|
|
590
|
+
}
|
|
591
|
+
static getTool(toolName) {
|
|
592
|
+
const toolInstance = this.registry[toolName];
|
|
593
|
+
if (!toolInstance) {
|
|
594
|
+
console.warn(`Unknown tool: ${toolName}`);
|
|
595
|
+
return null;
|
|
596
|
+
}
|
|
597
|
+
return toolInstance;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
KritzelToolRegistry.registry = {};
|
|
601
|
+
|
|
579
602
|
class KritzelText extends KritzelBaseObject {
|
|
580
603
|
get isReadonly() {
|
|
581
604
|
return !(this._store.state.activeTool instanceof KritzelTextTool);
|
|
@@ -598,7 +621,7 @@ class KritzelText extends KritzelBaseObject {
|
|
|
598
621
|
this.fontSize = config.fontSize || 8;
|
|
599
622
|
this.fontFamily = config.fontFamily || 'Arial';
|
|
600
623
|
this.fontColor = config.fontColor || '#000000';
|
|
601
|
-
this.height = config.height ||
|
|
624
|
+
this.height = config.height || this.fontSize * 1.2;
|
|
602
625
|
this.width = config.width || 0;
|
|
603
626
|
this.scale = config.scale || 1;
|
|
604
627
|
}
|
|
@@ -702,6 +725,15 @@ class KritzelText extends KritzelBaseObject {
|
|
|
702
725
|
}
|
|
703
726
|
}
|
|
704
727
|
}
|
|
728
|
+
onSelectedClick() {
|
|
729
|
+
this._store.setState('activeTool', KritzelToolRegistry.getTool('text'));
|
|
730
|
+
this._store.state.selectionGroup = null;
|
|
731
|
+
this._store.state.selectionBox = null;
|
|
732
|
+
this._store.state.activeText = this;
|
|
733
|
+
setTimeout(() => {
|
|
734
|
+
this.focus();
|
|
735
|
+
}, 300);
|
|
736
|
+
}
|
|
705
737
|
}
|
|
706
738
|
|
|
707
739
|
class KritzelKeyboardHelper {
|
|
@@ -735,24 +767,6 @@ class KritzelKeyboardHelper {
|
|
|
735
767
|
}
|
|
736
768
|
}
|
|
737
769
|
|
|
738
|
-
class KritzelToolRegistry {
|
|
739
|
-
static registerTool(toolName, constructor, store) {
|
|
740
|
-
const toolInstance = new constructor(store);
|
|
741
|
-
toolInstance.name = toolName;
|
|
742
|
-
this.registry[toolName] = toolInstance;
|
|
743
|
-
return toolInstance;
|
|
744
|
-
}
|
|
745
|
-
static getTool(toolName) {
|
|
746
|
-
const toolInstance = this.registry[toolName];
|
|
747
|
-
if (!toolInstance) {
|
|
748
|
-
console.warn(`Unknown tool: ${toolName}`);
|
|
749
|
-
return null;
|
|
750
|
-
}
|
|
751
|
-
return toolInstance;
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
KritzelToolRegistry.registry = {};
|
|
755
|
-
|
|
756
770
|
class KritzelTextTool extends KritzelBaseTool {
|
|
757
771
|
constructor(store) {
|
|
758
772
|
super(store);
|
|
@@ -777,84 +791,87 @@ class KritzelTextTool extends KritzelBaseTool {
|
|
|
777
791
|
'#800080',
|
|
778
792
|
];
|
|
779
793
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
this._store.state.activeText
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
object
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
this._store.
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
this._store.state.activeText
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
794
|
+
handlePointerDown(event) {
|
|
795
|
+
if (event.pointerType === 'mouse') {
|
|
796
|
+
const path = event.composedPath().slice(1);
|
|
797
|
+
const objectElement = path.find(element => element.classList && element.classList.contains('object'));
|
|
798
|
+
const object = this._store.findObjectById(objectElement === null || objectElement === void 0 ? void 0 : objectElement.id);
|
|
799
|
+
if (this._store.state.activeText === null && object && object instanceof KritzelText) {
|
|
800
|
+
this._store.state.activeText = object;
|
|
801
|
+
object.focus();
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
if (this._store.state.activeText !== null && object instanceof KritzelText) {
|
|
805
|
+
object.focus();
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
if (this._store.state.activeText !== null) {
|
|
809
|
+
this._store.resetActiveText();
|
|
810
|
+
this._store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
if (KritzelEventHelper.isLeftClick(event) === false) {
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
const clientX = event.clientX - this._store.offsetX;
|
|
817
|
+
const clientY = event.clientY - this._store.offsetY;
|
|
818
|
+
const text = KritzelText.create(this._store, this.fontSize, this.fontFamily);
|
|
819
|
+
text.fontColor = this.fontColor;
|
|
820
|
+
text.translateX = (clientX - this._store.state.translateX) / this._store.state.scale;
|
|
821
|
+
text.translateY = (clientY - this._store.state.translateY) / this._store.state.scale;
|
|
822
|
+
text.zIndex = this._store.currentZIndex;
|
|
823
|
+
this._store.state.activeText = text;
|
|
824
|
+
this._store.history.executeCommand(new AddObjectCommand(this._store, this, text));
|
|
825
|
+
}
|
|
826
|
+
if (event.pointerType === 'touch') {
|
|
827
|
+
const activePointers = Array.from(this._store.state.pointers.values());
|
|
828
|
+
const path = event.composedPath().slice(1);
|
|
829
|
+
const objectElement = path.find(element => element.classList && element.classList.contains('object'));
|
|
830
|
+
const object = this._store.findObjectById(objectElement === null || objectElement === void 0 ? void 0 : objectElement.id);
|
|
831
|
+
if (this._store.state.activeText === null && object && object instanceof KritzelText) {
|
|
832
|
+
this._store.state.activeText = object;
|
|
833
|
+
object.focus();
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
836
|
+
if (this._store.state.activeText !== null && object instanceof KritzelText) {
|
|
837
|
+
object.focus();
|
|
838
|
+
return;
|
|
839
|
+
}
|
|
840
|
+
if (this._store.state.activeText !== null) {
|
|
841
|
+
this._store.resetActiveText();
|
|
842
|
+
this._store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
if (activePointers.length > 1) {
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
KritzelKeyboardHelper.disableInteractiveWidget();
|
|
849
|
+
const clientX = Math.round(activePointers[0].clientX - this._store.offsetX);
|
|
850
|
+
const clientY = Math.round(activePointers[0].clientY - this._store.offsetY);
|
|
851
|
+
const text = KritzelText.create(this._store, this.fontSize, this.fontFamily);
|
|
852
|
+
text.fontColor = this.fontColor;
|
|
853
|
+
text.translateX = (clientX - this._store.state.translateX) / this._store.state.scale;
|
|
854
|
+
text.translateY = (clientY - this._store.state.translateY) / this._store.state.scale;
|
|
855
|
+
text.zIndex = this._store.currentZIndex;
|
|
856
|
+
this._store.state.activeText = text;
|
|
857
|
+
this._store.history.executeCommand(new AddObjectCommand(this._store, this, text));
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
handlePointerUp(event) {
|
|
861
|
+
var _a, _b, _c, _d;
|
|
862
|
+
if (event.pointerType === 'mouse') {
|
|
863
|
+
(_a = this._store.state.activeText) === null || _a === void 0 ? void 0 : _a.adjustTextareaSize();
|
|
864
|
+
(_b = this._store.state.activeText) === null || _b === void 0 ? void 0 : _b.focus();
|
|
865
|
+
}
|
|
866
|
+
if (event.pointerType === 'touch') {
|
|
867
|
+
(_c = this._store.state.activeText) === null || _c === void 0 ? void 0 : _c.adjustTextareaSize();
|
|
868
|
+
(_d = this._store.state.activeText) === null || _d === void 0 ? void 0 : _d.focus();
|
|
869
|
+
KritzelKeyboardHelper.enableInteractiveWidget();
|
|
837
870
|
}
|
|
838
|
-
KritzelKeyboardHelper.disableInteractiveWidget();
|
|
839
|
-
const clientX = Math.round(event.touches[0].clientX - this._store.offsetX);
|
|
840
|
-
const clientY = Math.round(event.touches[0].clientY - this._store.offsetY);
|
|
841
|
-
const text = KritzelText.create(this._store, this.fontSize, this.fontFamily);
|
|
842
|
-
text.fontColor = this.fontColor;
|
|
843
|
-
text.translateX = (clientX - this._store.state.translateX) / this._store.state.scale;
|
|
844
|
-
text.translateY = (clientY - this._store.state.translateY) / this._store.state.scale;
|
|
845
|
-
text.zIndex = this._store.currentZIndex;
|
|
846
|
-
this._store.state.activeText = text;
|
|
847
|
-
this._store.history.executeCommand(new AddObjectCommand(this._store, this, text));
|
|
848
|
-
}
|
|
849
|
-
handleTouchEnd(_event) {
|
|
850
|
-
var _a, _b;
|
|
851
|
-
(_a = this._store.state.activeText) === null || _a === void 0 ? void 0 : _a.focus();
|
|
852
|
-
(_b = this._store.state.activeText) === null || _b === void 0 ? void 0 : _b.adjustTextareaSize();
|
|
853
|
-
KritzelKeyboardHelper.enableInteractiveWidget();
|
|
854
871
|
}
|
|
855
872
|
}
|
|
856
873
|
|
|
857
|
-
export { AddObjectCommand as A, KritzelBrushTool as K, ObjectHelper as O, KritzelTextTool as a, KritzelBaseCommand as b, KritzelBaseTool as c, KritzelEventHelper as d, KritzelBaseObject as e, KritzelText as f, KritzelToolRegistry as g, KritzelPath as h,
|
|
858
|
-
//# sourceMappingURL=p-
|
|
874
|
+
export { AddObjectCommand as A, KritzelBrushTool as K, ObjectHelper as O, KritzelTextTool as a, KritzelBaseCommand as b, KritzelBaseTool as c, KritzelEventHelper as d, KritzelBaseObject as e, KritzelText as f, KritzelToolRegistry as g, KritzelPath as h, KritzelMouseButton as i, KritzelKeyboardHelper as j };
|
|
875
|
+
//# sourceMappingURL=p-7Ns73-wN.js.map
|
|
859
876
|
|
|
860
|
-
//# sourceMappingURL=p-
|
|
877
|
+
//# sourceMappingURL=p-7Ns73-wN.js.map
|