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.
Files changed (99) hide show
  1. package/dist/cjs/kritzel-brush-style_18.cjs.entry.js +854 -833
  2. package/dist/cjs/kritzel-brush-style_18.cjs.entry.js.map +1 -1
  3. package/dist/cjs/loader.cjs.js +1 -1
  4. package/dist/cjs/stencil.cjs.js +1 -1
  5. package/dist/collection/classes/commands/remove-selection-group.command.js +1 -1
  6. package/dist/collection/classes/commands/remove-selection-group.command.js.map +1 -1
  7. package/dist/collection/classes/handlers/context-menu.handler.js +2 -47
  8. package/dist/collection/classes/handlers/context-menu.handler.js.map +1 -1
  9. package/dist/collection/classes/handlers/move.handler.js +62 -55
  10. package/dist/collection/classes/handlers/move.handler.js.map +1 -1
  11. package/dist/collection/classes/handlers/resize.handler.js +122 -113
  12. package/dist/collection/classes/handlers/resize.handler.js.map +1 -1
  13. package/dist/collection/classes/handlers/rotation.handler.js +74 -66
  14. package/dist/collection/classes/handlers/rotation.handler.js.map +1 -1
  15. package/dist/collection/classes/handlers/selection.handler.js +59 -50
  16. package/dist/collection/classes/handlers/selection.handler.js.map +1 -1
  17. package/dist/collection/classes/objects/base-object.class.js +3 -0
  18. package/dist/collection/classes/objects/base-object.class.js.map +1 -1
  19. package/dist/collection/classes/objects/text.class.js +11 -1
  20. package/dist/collection/classes/objects/text.class.js.map +1 -1
  21. package/dist/collection/classes/tools/base-tool.class.js +3 -18
  22. package/dist/collection/classes/tools/base-tool.class.js.map +1 -1
  23. package/dist/collection/classes/tools/brush-tool.class.js +79 -71
  24. package/dist/collection/classes/tools/brush-tool.class.js.map +1 -1
  25. package/dist/collection/classes/tools/eraser-tool.class.js +61 -56
  26. package/dist/collection/classes/tools/eraser-tool.class.js.map +1 -1
  27. package/dist/collection/classes/tools/selection-tool.class.js +93 -73
  28. package/dist/collection/classes/tools/selection-tool.class.js.map +1 -1
  29. package/dist/collection/classes/tools/text-tool.class.js +73 -70
  30. package/dist/collection/classes/tools/text-tool.class.js.map +1 -1
  31. package/dist/collection/classes/viewport.class.js +76 -69
  32. package/dist/collection/classes/viewport.class.js.map +1 -1
  33. package/dist/collection/components/core/kritzel-editor/kritzel-editor.css +6 -0
  34. package/dist/collection/components/core/kritzel-engine/kritzel-engine.css +6 -0
  35. package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +66 -120
  36. package/dist/collection/components/core/kritzel-engine/kritzel-engine.js.map +1 -1
  37. package/dist/collection/components/ui/kritzel-context-menu/kritzel-context-menu.js +1 -16
  38. package/dist/collection/components/ui/kritzel-context-menu/kritzel-context-menu.js.map +1 -1
  39. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.css +10 -2
  40. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js +9 -4
  41. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js.map +1 -1
  42. package/dist/collection/configs/default-engine-state.js +1 -1
  43. package/dist/collection/configs/default-engine-state.js.map +1 -1
  44. package/dist/collection/helpers/devices.helper.js +6 -0
  45. package/dist/collection/helpers/devices.helper.js.map +1 -0
  46. package/dist/collection/helpers/event.helper.js +43 -34
  47. package/dist/collection/helpers/event.helper.js.map +1 -1
  48. package/dist/collection/interfaces/engine-state.interface.js.map +1 -1
  49. package/dist/collection/interfaces/object.interface.js.map +1 -1
  50. package/dist/collection/interfaces/tool.interface.js.map +1 -1
  51. package/dist/components/kritzel-context-menu.js +1 -1
  52. package/dist/components/kritzel-controls.js +1 -1
  53. package/dist/components/kritzel-editor.js +5 -5
  54. package/dist/components/kritzel-editor.js.map +1 -1
  55. package/dist/components/kritzel-engine.js +1 -1
  56. package/dist/components/{p-BNfHRlWL.js → p-7Ns73-wN.js} +237 -220
  57. package/dist/components/p-7Ns73-wN.js.map +1 -0
  58. package/dist/components/{p-Cbu5RSmC.js → p-BmAloSfd.js} +3 -4
  59. package/dist/components/p-BmAloSfd.js.map +1 -0
  60. package/dist/components/{p-Box62paJ.js → p-Ch6TgHX3.js} +18 -8
  61. package/dist/components/p-Ch6TgHX3.js.map +1 -0
  62. package/dist/components/{p-CqJr3YCp.js → p-mD9nNnTx.js} +618 -622
  63. package/dist/components/p-mD9nNnTx.js.map +1 -0
  64. package/dist/esm/kritzel-brush-style_18.entry.js +854 -833
  65. package/dist/esm/kritzel-brush-style_18.entry.js.map +1 -1
  66. package/dist/esm/loader.js +1 -1
  67. package/dist/esm/stencil.js +1 -1
  68. package/dist/stencil/p-d23bb1ad.entry.js +2 -0
  69. package/dist/stencil/p-d23bb1ad.entry.js.map +1 -0
  70. package/dist/stencil/stencil.esm.js +1 -1
  71. package/dist/types/classes/handlers/context-menu.handler.d.ts +1 -2
  72. package/dist/types/classes/handlers/move.handler.d.ts +3 -6
  73. package/dist/types/classes/handlers/resize.handler.d.ts +3 -6
  74. package/dist/types/classes/handlers/rotation.handler.d.ts +3 -6
  75. package/dist/types/classes/handlers/selection.handler.d.ts +3 -6
  76. package/dist/types/classes/objects/base-object.class.d.ts +1 -0
  77. package/dist/types/classes/objects/text.class.d.ts +1 -0
  78. package/dist/types/classes/tools/base-tool.class.d.ts +3 -8
  79. package/dist/types/classes/tools/brush-tool.class.d.ts +3 -6
  80. package/dist/types/classes/tools/eraser-tool.class.d.ts +3 -6
  81. package/dist/types/classes/tools/selection-tool.class.d.ts +4 -7
  82. package/dist/types/classes/tools/text-tool.class.d.ts +2 -4
  83. package/dist/types/classes/viewport.class.d.ts +3 -6
  84. package/dist/types/components/core/kritzel-engine/kritzel-engine.d.ts +5 -10
  85. package/dist/types/components/ui/kritzel-context-menu/kritzel-context-menu.d.ts +0 -1
  86. package/dist/types/components/ui/kritzel-controls/kritzel-controls.d.ts +1 -0
  87. package/dist/types/components.d.ts +0 -2
  88. package/dist/types/helpers/devices.helper.d.ts +3 -0
  89. package/dist/types/helpers/event.helper.d.ts +2 -6
  90. package/dist/types/interfaces/engine-state.interface.d.ts +1 -1
  91. package/dist/types/interfaces/object.interface.d.ts +1 -0
  92. package/dist/types/interfaces/tool.interface.d.ts +3 -8
  93. package/package.json +1 -1
  94. package/dist/components/p-BNfHRlWL.js.map +0 -1
  95. package/dist/components/p-Box62paJ.js.map +0 -1
  96. package/dist/components/p-Cbu5RSmC.js.map +0 -1
  97. package/dist/components/p-CqJr3YCp.js.map +0 -1
  98. package/dist/stencil/p-3a7d7b58.entry.js +0 -2
  99. 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 detectDoubleTap() {
19
- const currentTime = Date.now();
20
- const tapLength = currentTime - KritzelEventHelper.lastTapTimestamp;
21
- if (KritzelEventHelper.twoFingerTouchDetected) {
22
- KritzelEventHelper.lastTapTimestamp = 0;
23
- KritzelEventHelper.twoFingerTouchDetected = false;
24
- if (KritzelEventHelper.tapTimeoutId) {
25
- clearTimeout(KritzelEventHelper.tapTimeoutId);
26
- KritzelEventHelper.tapTimeoutId = null;
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
- return false;
29
- }
30
- if (KritzelEventHelper.tapTimeoutId) {
31
- clearTimeout(KritzelEventHelper.tapTimeoutId);
32
- KritzelEventHelper.tapTimeoutId = null;
33
- }
34
- if (tapLength < KritzelEventHelper.doubleTapTimeout && tapLength > 0) {
35
- KritzelEventHelper.lastTapTimestamp = 0;
36
- return true;
37
- }
38
- else {
39
- KritzelEventHelper.lastTapTimestamp = currentTime;
40
- KritzelEventHelper.tapTimeoutId = setTimeout(() => {
41
- KritzelEventHelper.tapTimeoutId = null;
42
- KritzelEventHelper.twoFingerTouchDetected = false;
43
- }, KritzelEventHelper.doubleTapTimeout);
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
- handleMouseDown(_event) {
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
- handleDoubleTap(_event) {
466
+ handlePointerMove(_event) {
464
467
  // default implementation
465
468
  }
466
- handleTouchStart(_event) {
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
- handleMouseDown(event) {
496
- if (KritzelEventHelper.isLeftClick(event)) {
497
- this._store.state.isDrawing = true;
498
- const x = event.clientX - this._store.offsetX;
499
- const y = event.clientY - this._store.offsetY;
500
- this._store.state.currentPath = KritzelPath.create(this._store, {
501
- points: [[x, y]],
502
- translateX: -this._store.state.translateX,
503
- translateY: -this._store.state.translateY,
504
- scale: this._store.state.scale,
505
- fill: this.color,
506
- strokeWidth: this.size,
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
- handleMouseUp(_event) {
526
- if (this._store.state.isDrawing) {
527
- this._store.state.isDrawing = false;
528
- if (this._store.state.currentPath) {
529
- this._store.state.currentPath.zIndex = this._store.currentZIndex;
530
- this._store.history.executeCommand(new AddObjectCommand(this._store, this, this._store.state.currentPath));
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
- handleTouchMove(event) {
552
- if (this._store.state.touchCount === 1) {
553
- const x = Math.round(event.touches[0].clientX - this._store.offsetX);
554
- const y = Math.round(event.touches[0].clientY - this._store.offsetY);
555
- this._store.state.currentPath = KritzelPath.create(this._store, {
556
- points: [...this._store.state.currentPath.points, [x, y]],
557
- translateX: -this._store.state.translateX,
558
- translateY: -this._store.state.translateY,
559
- scale: this._store.state.scale,
560
- fill: this.color,
561
- strokeWidth: this.size,
562
- });
563
- this._store.rerender();
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
- handleTouchEnd(_event) {
567
- if (this._store.state.isDrawing) {
568
- this._store.state.isDrawing = false;
569
- if (this._store.state.currentPath) {
570
- this._store.state.currentPath.zIndex = this._store.currentZIndex;
571
- this._store.history.executeCommand(new AddObjectCommand(this._store, this, this._store.state.currentPath));
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 || (this.fontSize * 1.2);
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
- handleMouseDown(event) {
781
- const path = event.composedPath().slice(1);
782
- const objectElement = path.find(element => element.classList && element.classList.contains('object'));
783
- const object = this._store.findObjectById(objectElement === null || objectElement === void 0 ? void 0 : objectElement.id);
784
- if (this._store.state.activeText === null && object && object instanceof KritzelText) {
785
- this._store.state.activeText = object;
786
- object.focus();
787
- return;
788
- }
789
- if (this._store.state.activeText !== null && object instanceof KritzelText) {
790
- object.focus();
791
- return;
792
- }
793
- if (this._store.state.activeText !== null) {
794
- this._store.resetActiveText();
795
- this._store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
796
- return;
797
- }
798
- if (KritzelEventHelper.isLeftClick(event) === false) {
799
- return;
800
- }
801
- const clientX = event.clientX - this._store.offsetX;
802
- const clientY = event.clientY - this._store.offsetY;
803
- const text = KritzelText.create(this._store, this.fontSize, this.fontFamily);
804
- text.fontColor = this.fontColor;
805
- text.translateX = (clientX - this._store.state.translateX) / this._store.state.scale;
806
- text.translateY = (clientY - this._store.state.translateY) / this._store.state.scale;
807
- text.zIndex = this._store.currentZIndex;
808
- text.adjustTextareaSize();
809
- this._store.state.activeText = text;
810
- this._store.history.executeCommand(new AddObjectCommand(this._store, this, text));
811
- }
812
- handleMouseUp(_event) {
813
- var _a, _b;
814
- (_a = this._store.state.activeText) === null || _a === void 0 ? void 0 : _a.focus();
815
- (_b = this._store.state.activeText) === null || _b === void 0 ? void 0 : _b.adjustTextareaSize();
816
- }
817
- handleTouchStart(event) {
818
- const path = event.composedPath().slice(1);
819
- const objectElement = path.find(element => element.classList && element.classList.contains('object'));
820
- const object = this._store.findObjectById(objectElement === null || objectElement === void 0 ? void 0 : objectElement.id);
821
- if (this._store.state.activeText === null && object && object instanceof KritzelText) {
822
- this._store.state.activeText = object;
823
- object.focus();
824
- return;
825
- }
826
- if (this._store.state.activeText !== null && object instanceof KritzelText) {
827
- object.focus();
828
- return;
829
- }
830
- if (this._store.state.activeText !== null) {
831
- this._store.resetActiveText();
832
- this._store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
833
- return;
834
- }
835
- if (this._store.state.touchCount > 1) {
836
- return;
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, KritzelKeyboardHelper as i };
858
- //# sourceMappingURL=p-BNfHRlWL.js.map
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-BNfHRlWL.js.map
877
+ //# sourceMappingURL=p-7Ns73-wN.js.map