kritzel-stencil 0.0.107 → 0.0.109

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 (117) hide show
  1. package/dist/cjs/kritzel-brush-style_18.cjs.entry.js +858 -820
  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/handlers/context-menu.handler.js +2 -47
  6. package/dist/collection/classes/handlers/context-menu.handler.js.map +1 -1
  7. package/dist/collection/classes/handlers/key.handler.js +1 -1
  8. package/dist/collection/classes/handlers/key.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/registries/icon-registry.class.js.map +1 -0
  22. package/dist/collection/classes/registries/tool.registry.js.map +1 -0
  23. package/dist/collection/classes/store.class.js +3 -54
  24. package/dist/collection/classes/store.class.js.map +1 -1
  25. package/dist/collection/classes/tools/base-tool.class.js +3 -18
  26. package/dist/collection/classes/tools/base-tool.class.js.map +1 -1
  27. package/dist/collection/classes/tools/brush-tool.class.js +79 -71
  28. package/dist/collection/classes/tools/brush-tool.class.js.map +1 -1
  29. package/dist/collection/classes/tools/eraser-tool.class.js +61 -56
  30. package/dist/collection/classes/tools/eraser-tool.class.js.map +1 -1
  31. package/dist/collection/classes/tools/image-tool.class.js +1 -1
  32. package/dist/collection/classes/tools/image-tool.class.js.map +1 -1
  33. package/dist/collection/classes/tools/selection-tool.class.js +94 -74
  34. package/dist/collection/classes/tools/selection-tool.class.js.map +1 -1
  35. package/dist/collection/classes/tools/text-tool.class.js +73 -70
  36. package/dist/collection/classes/tools/text-tool.class.js.map +1 -1
  37. package/dist/collection/classes/viewport.class.js +76 -69
  38. package/dist/collection/classes/viewport.class.js.map +1 -1
  39. package/dist/collection/components/core/kritzel-editor/kritzel-editor.css +6 -0
  40. package/dist/collection/components/core/kritzel-editor/kritzel-editor.js +2 -2
  41. package/dist/collection/components/core/kritzel-editor/kritzel-editor.js.map +1 -1
  42. package/dist/collection/components/core/kritzel-engine/kritzel-engine.css +6 -0
  43. package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +69 -121
  44. package/dist/collection/components/core/kritzel-engine/kritzel-engine.js.map +1 -1
  45. package/dist/collection/components/shared/kritzel-icon/kritzel-icon.js +1 -1
  46. package/dist/collection/components/shared/kritzel-icon/kritzel-icon.js.map +1 -1
  47. package/dist/collection/components/ui/kritzel-context-menu/kritzel-context-menu.js +1 -16
  48. package/dist/collection/components/ui/kritzel-context-menu/kritzel-context-menu.js.map +1 -1
  49. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.css +10 -2
  50. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js +9 -4
  51. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js.map +1 -1
  52. package/dist/collection/configs/default-engine-state.js +53 -0
  53. package/dist/collection/configs/default-engine-state.js.map +1 -0
  54. package/dist/collection/helpers/devices.helper.js +6 -0
  55. package/dist/collection/helpers/devices.helper.js.map +1 -0
  56. package/dist/collection/helpers/event.helper.js +43 -20
  57. package/dist/collection/helpers/event.helper.js.map +1 -1
  58. package/dist/collection/interfaces/engine-state.interface.js.map +1 -1
  59. package/dist/collection/interfaces/object.interface.js.map +1 -1
  60. package/dist/collection/interfaces/tool.interface.js.map +1 -1
  61. package/dist/components/kritzel-context-menu.js +1 -1
  62. package/dist/components/kritzel-controls.js +1 -1
  63. package/dist/components/kritzel-editor.js +6 -6
  64. package/dist/components/kritzel-editor.js.map +1 -1
  65. package/dist/components/kritzel-engine.js +1 -1
  66. package/dist/components/{p-CesjDLvT.js → p-7Ns73-wN.js} +237 -206
  67. package/dist/components/p-7Ns73-wN.js.map +1 -0
  68. package/dist/components/{p-Cbu5RSmC.js → p-BmAloSfd.js} +3 -4
  69. package/dist/components/p-BmAloSfd.js.map +1 -0
  70. package/dist/components/{p-_3gCPfqz.js → p-BmrZipyu.js} +621 -622
  71. package/dist/components/p-BmrZipyu.js.map +1 -0
  72. package/dist/components/p-CZkSABuJ.js.map +1 -1
  73. package/dist/components/{p-DTcfnx4-.js → p-Ch6TgHX3.js} +18 -8
  74. package/dist/components/p-Ch6TgHX3.js.map +1 -0
  75. package/dist/esm/kritzel-brush-style_18.entry.js +858 -820
  76. package/dist/esm/kritzel-brush-style_18.entry.js.map +1 -1
  77. package/dist/esm/loader.js +1 -1
  78. package/dist/esm/stencil.js +1 -1
  79. package/dist/stencil/p-c976660c.entry.js +2 -0
  80. package/dist/stencil/p-c976660c.entry.js.map +1 -0
  81. package/dist/stencil/stencil.esm.js +1 -1
  82. package/dist/types/classes/handlers/context-menu.handler.d.ts +1 -2
  83. package/dist/types/classes/handlers/move.handler.d.ts +3 -6
  84. package/dist/types/classes/handlers/resize.handler.d.ts +3 -6
  85. package/dist/types/classes/handlers/rotation.handler.d.ts +3 -6
  86. package/dist/types/classes/handlers/selection.handler.d.ts +3 -6
  87. package/dist/types/classes/objects/base-object.class.d.ts +1 -0
  88. package/dist/types/classes/objects/text.class.d.ts +1 -0
  89. package/dist/types/classes/{tool.registry.d.ts → registries/tool.registry.d.ts} +2 -2
  90. package/dist/types/classes/tools/base-tool.class.d.ts +3 -8
  91. package/dist/types/classes/tools/brush-tool.class.d.ts +3 -6
  92. package/dist/types/classes/tools/eraser-tool.class.d.ts +3 -6
  93. package/dist/types/classes/tools/selection-tool.class.d.ts +4 -7
  94. package/dist/types/classes/tools/text-tool.class.d.ts +2 -4
  95. package/dist/types/classes/viewport.class.d.ts +3 -6
  96. package/dist/types/components/core/kritzel-engine/kritzel-engine.d.ts +5 -10
  97. package/dist/types/components/ui/kritzel-context-menu/kritzel-context-menu.d.ts +0 -1
  98. package/dist/types/components/ui/kritzel-controls/kritzel-controls.d.ts +1 -0
  99. package/dist/types/components.d.ts +0 -2
  100. package/dist/types/configs/default-engine-state.d.ts +2 -0
  101. package/dist/types/helpers/devices.helper.d.ts +3 -0
  102. package/dist/types/helpers/event.helper.d.ts +2 -4
  103. package/dist/types/interfaces/engine-state.interface.d.ts +1 -1
  104. package/dist/types/interfaces/object.interface.d.ts +1 -0
  105. package/dist/types/interfaces/tool.interface.d.ts +3 -8
  106. package/package.json +1 -1
  107. package/dist/collection/classes/icon-registry.class.js.map +0 -1
  108. package/dist/collection/classes/tool.registry.js.map +0 -1
  109. package/dist/components/p-Cbu5RSmC.js.map +0 -1
  110. package/dist/components/p-CesjDLvT.js.map +0 -1
  111. package/dist/components/p-DTcfnx4-.js.map +0 -1
  112. package/dist/components/p-_3gCPfqz.js.map +0 -1
  113. package/dist/stencil/p-e596d004.entry.js +0 -2
  114. package/dist/stencil/p-e596d004.entry.js.map +0 -1
  115. /package/dist/collection/classes/{icon-registry.class.js → registries/icon-registry.class.js} +0 -0
  116. /package/dist/collection/classes/{tool.registry.js → registries/tool.registry.js} +0 -0
  117. /package/dist/types/classes/{icon-registry.class.d.ts → registries/icon-registry.class.d.ts} +0 -0
@@ -15,29 +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.tapTimeoutId) {
22
- clearTimeout(KritzelEventHelper.tapTimeoutId);
23
- KritzelEventHelper.tapTimeoutId = null;
24
- }
25
- if (tapLength < KritzelEventHelper.doubleTapTimeout && tapLength > 0) {
26
- KritzelEventHelper.lastTapTimestamp = 0;
27
- return true;
28
- }
29
- else {
30
- KritzelEventHelper.lastTapTimestamp = currentTime;
31
- KritzelEventHelper.tapTimeoutId = setTimeout(() => {
32
- KritzelEventHelper.tapTimeoutId = null;
33
- }, KritzelEventHelper.doubleTapTimeout);
34
- return false;
35
- }
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();
45
+ }
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;
36
62
  }
37
63
  }
38
- KritzelEventHelper.lastTapTimestamp = 0;
39
- KritzelEventHelper.tapTimeoutId = null;
40
- KritzelEventHelper.doubleTapTimeout = 300;
41
64
 
42
65
  class KritzelBaseCommand {
43
66
  constructor(store, initiator) {
@@ -298,6 +321,9 @@ class KritzelBaseObject {
298
321
  copiedObject.isMounted = false;
299
322
  return copiedObject;
300
323
  }
324
+ onSelectedClick() {
325
+ // This method can be overridden by subclasses to handle click events when the object is selected.
326
+ }
301
327
  revive(object) {
302
328
  Object.assign(this, object);
303
329
  return this;
@@ -434,28 +460,13 @@ class KritzelBaseTool {
434
460
  onDeactivate() {
435
461
  // default implementation
436
462
  }
437
- handleMouseDown(_event) {
463
+ handlePointerDown(_event) {
438
464
  // default implementation
439
465
  }
440
- handleMouseMove(_event) {
466
+ handlePointerMove(_event) {
441
467
  // default implementation
442
468
  }
443
- handleMouseUp(_event) {
444
- // default implementation
445
- }
446
- handleDoubleClick(_event) {
447
- // default implementation
448
- }
449
- handleDoubleTap(_event) {
450
- // default implementation
451
- }
452
- handleTouchStart(_event) {
453
- // default implementation
454
- }
455
- handleTouchMove(_event) {
456
- // default implementation
457
- }
458
- handleTouchEnd(_event) {
469
+ handlePointerUp(_event) {
459
470
  // default implementation
460
471
  }
461
472
  handleWheel(_event) {
@@ -478,90 +489,116 @@ class KritzelBrushTool extends KritzelBaseTool {
478
489
  highlighter: ['#ffff00', '#ffb347', '#b4ffb4'],
479
490
  };
480
491
  }
481
- handleMouseDown(event) {
482
- if (KritzelEventHelper.isLeftClick(event)) {
483
- this._store.state.isDrawing = true;
484
- const x = event.clientX - this._store.offsetX;
485
- const y = event.clientY - this._store.offsetY;
486
- this._store.state.currentPath = KritzelPath.create(this._store, {
487
- points: [[x, y]],
488
- translateX: -this._store.state.translateX,
489
- translateY: -this._store.state.translateY,
490
- scale: this._store.state.scale,
491
- fill: this.color,
492
- strokeWidth: this.size,
493
- });
494
- }
495
- }
496
- handleMouseMove(event) {
497
- if (this._store.state.isDrawing) {
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: [...this._store.state.currentPath.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
- 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
+ }
509
507
  }
510
- }
511
- handleMouseUp(_event) {
512
- if (this._store.state.isDrawing) {
513
- this._store.state.isDrawing = false;
514
- if (this._store.state.currentPath) {
515
- this._store.state.currentPath.zIndex = this._store.currentZIndex;
516
- 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();
517
523
  }
518
- this._store.state.currentPath = undefined;
519
- }
520
- }
521
- handleTouchStart(event) {
522
- if (this._store.state.touchCount === 1) {
523
- const x = Math.round(event.touches[0].clientX - this._store.offsetX);
524
- const y = Math.round(event.touches[0].clientY - this._store.offsetY);
525
- this._store.state.isDrawing = true;
526
- this._store.state.currentPath = KritzelPath.create(this._store, {
527
- points: [[x, y]],
528
- translateX: -this._store.state.translateX,
529
- translateY: -this._store.state.translateY,
530
- scale: this._store.state.scale,
531
- fill: this.color,
532
- strokeWidth: this.size,
533
- });
534
- this._store.rerender();
535
524
  }
536
525
  }
537
- handleTouchMove(event) {
538
- if (this._store.state.touchCount === 1) {
539
- const x = Math.round(event.touches[0].clientX - this._store.offsetX);
540
- const y = Math.round(event.touches[0].clientY - this._store.offsetY);
541
- this._store.state.currentPath = KritzelPath.create(this._store, {
542
- points: [...this._store.state.currentPath.points, [x, y]],
543
- translateX: -this._store.state.translateX,
544
- translateY: -this._store.state.translateY,
545
- scale: this._store.state.scale,
546
- fill: this.color,
547
- strokeWidth: this.size,
548
- });
549
- 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
+ }
550
557
  }
551
558
  }
552
- handleTouchEnd(_event) {
553
- if (this._store.state.isDrawing) {
554
- this._store.state.isDrawing = false;
555
- if (this._store.state.currentPath) {
556
- this._store.state.currentPath.zIndex = this._store.currentZIndex;
557
- 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();
558
579
  }
559
- this._store.state.currentPath = undefined;
560
- this._store.rerender();
561
580
  }
562
581
  }
563
582
  }
564
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
+
565
602
  class KritzelText extends KritzelBaseObject {
566
603
  get isReadonly() {
567
604
  return !(this._store.state.activeTool instanceof KritzelTextTool);
@@ -584,7 +621,7 @@ class KritzelText extends KritzelBaseObject {
584
621
  this.fontSize = config.fontSize || 8;
585
622
  this.fontFamily = config.fontFamily || 'Arial';
586
623
  this.fontColor = config.fontColor || '#000000';
587
- this.height = config.height || (this.fontSize * 1.2);
624
+ this.height = config.height || this.fontSize * 1.2;
588
625
  this.width = config.width || 0;
589
626
  this.scale = config.scale || 1;
590
627
  }
@@ -688,25 +725,16 @@ class KritzelText extends KritzelBaseObject {
688
725
  }
689
726
  }
690
727
  }
691
- }
692
-
693
- class KritzelToolRegistry {
694
- static registerTool(toolName, constructor, store) {
695
- const toolInstance = new constructor(store);
696
- toolInstance.name = toolName;
697
- this.registry[toolName] = toolInstance;
698
- return toolInstance;
699
- }
700
- static getTool(toolName) {
701
- const toolInstance = this.registry[toolName];
702
- if (!toolInstance) {
703
- console.warn(`Unknown tool: ${toolName}`);
704
- return null;
705
- }
706
- return toolInstance;
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);
707
736
  }
708
737
  }
709
- KritzelToolRegistry.registry = {};
710
738
 
711
739
  class KritzelKeyboardHelper {
712
740
  static forceHideKeyboard() {
@@ -763,84 +791,87 @@ class KritzelTextTool extends KritzelBaseTool {
763
791
  '#800080',
764
792
  ];
765
793
  }
766
- handleMouseDown(event) {
767
- const path = event.composedPath().slice(1);
768
- const objectElement = path.find(element => element.classList && element.classList.contains('object'));
769
- const object = this._store.findObjectById(objectElement === null || objectElement === void 0 ? void 0 : objectElement.id);
770
- if (this._store.state.activeText === null && object && object instanceof KritzelText) {
771
- this._store.state.activeText = object;
772
- object.focus();
773
- return;
774
- }
775
- if (this._store.state.activeText !== null && object instanceof KritzelText) {
776
- object.focus();
777
- return;
778
- }
779
- if (this._store.state.activeText !== null) {
780
- this._store.resetActiveText();
781
- this._store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
782
- return;
783
- }
784
- if (KritzelEventHelper.isLeftClick(event) === false) {
785
- return;
786
- }
787
- const clientX = event.clientX - this._store.offsetX;
788
- const clientY = event.clientY - this._store.offsetY;
789
- const text = KritzelText.create(this._store, this.fontSize, this.fontFamily);
790
- text.fontColor = this.fontColor;
791
- text.translateX = (clientX - this._store.state.translateX) / this._store.state.scale;
792
- text.translateY = (clientY - this._store.state.translateY) / this._store.state.scale;
793
- text.zIndex = this._store.currentZIndex;
794
- text.adjustTextareaSize();
795
- this._store.state.activeText = text;
796
- this._store.history.executeCommand(new AddObjectCommand(this._store, this, text));
797
- }
798
- handleMouseUp(_event) {
799
- var _a, _b;
800
- (_a = this._store.state.activeText) === null || _a === void 0 ? void 0 : _a.focus();
801
- (_b = this._store.state.activeText) === null || _b === void 0 ? void 0 : _b.adjustTextareaSize();
802
- }
803
- handleTouchStart(event) {
804
- const path = event.composedPath().slice(1);
805
- const objectElement = path.find(element => element.classList && element.classList.contains('object'));
806
- const object = this._store.findObjectById(objectElement === null || objectElement === void 0 ? void 0 : objectElement.id);
807
- if (this._store.state.activeText === null && object && object instanceof KritzelText) {
808
- this._store.state.activeText = object;
809
- object.focus();
810
- return;
811
- }
812
- if (this._store.state.activeText !== null && object instanceof KritzelText) {
813
- object.focus();
814
- return;
815
- }
816
- if (this._store.state.activeText !== null) {
817
- this._store.resetActiveText();
818
- this._store.setState('activeTool', KritzelToolRegistry.getTool('selection'));
819
- return;
820
- }
821
- if (this._store.state.touchCount > 1) {
822
- 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();
823
870
  }
824
- KritzelKeyboardHelper.disableInteractiveWidget();
825
- const clientX = Math.round(event.touches[0].clientX - this._store.offsetX);
826
- const clientY = Math.round(event.touches[0].clientY - this._store.offsetY);
827
- const text = KritzelText.create(this._store, this.fontSize, this.fontFamily);
828
- text.fontColor = this.fontColor;
829
- text.translateX = (clientX - this._store.state.translateX) / this._store.state.scale;
830
- text.translateY = (clientY - this._store.state.translateY) / this._store.state.scale;
831
- text.zIndex = this._store.currentZIndex;
832
- this._store.state.activeText = text;
833
- this._store.history.executeCommand(new AddObjectCommand(this._store, this, text));
834
- }
835
- handleTouchEnd(_event) {
836
- var _a, _b;
837
- (_a = this._store.state.activeText) === null || _a === void 0 ? void 0 : _a.focus();
838
- (_b = this._store.state.activeText) === null || _b === void 0 ? void 0 : _b.adjustTextareaSize();
839
- KritzelKeyboardHelper.enableInteractiveWidget();
840
871
  }
841
872
  }
842
873
 
843
- 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 };
844
- //# sourceMappingURL=p-CesjDLvT.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
845
876
 
846
- //# sourceMappingURL=p-CesjDLvT.js.map
877
+ //# sourceMappingURL=p-7Ns73-wN.js.map