@@ -296,6 +296,15 @@ export class CanvasEngine {
296
296
this . canvas . addEventListener ( "wheel" , this . mouseWheelHandler , {
297
297
passive : false ,
298
298
} ) ;
299
+ this . canvas . addEventListener ( "touchstart" , this . touchStartHandler , {
300
+ passive : false ,
301
+ } ) ;
302
+ this . canvas . addEventListener ( "touchmove" , this . touchMoveHandler , {
303
+ passive : false ,
304
+ } ) ;
305
+ this . canvas . addEventListener ( "touchend" , this . touchEndHandler , {
306
+ passive : false ,
307
+ } ) ;
299
308
}
300
309
301
310
setTool ( tool : ToolType ) {
@@ -974,6 +983,38 @@ export class CanvasEngine {
974
983
}
975
984
} ;
976
985
986
+ touchStartHandler = ( e : TouchEvent ) => {
987
+ e . preventDefault ( ) ;
988
+ const touch = e . touches [ 0 ] ;
989
+ if ( ! touch ) return ;
990
+
991
+ const simulatedMouse = new MouseEvent ( "mousedown" , {
992
+ clientX : touch . clientX ,
993
+ clientY : touch . clientY ,
994
+ } ) ;
995
+
996
+ this . mouseDownHandler ( simulatedMouse ) ;
997
+ } ;
998
+
999
+ touchMoveHandler = ( e : TouchEvent ) => {
1000
+ e . preventDefault ( ) ;
1001
+ const touch = e . touches [ 0 ] ;
1002
+ if ( ! touch ) return ;
1003
+
1004
+ const simulatedMouse = new MouseEvent ( "mousemove" , {
1005
+ clientX : touch . clientX ,
1006
+ clientY : touch . clientY ,
1007
+ } ) ;
1008
+
1009
+ this . mouseMoveHandler ( simulatedMouse ) ;
1010
+ } ;
1011
+
1012
+ touchEndHandler = ( e : TouchEvent ) => {
1013
+ e . preventDefault ( ) ;
1014
+ const simulatedMouse = new MouseEvent ( "mouseup" , { } ) ;
1015
+ this . mouseUpHandler ( simulatedMouse ) ;
1016
+ } ;
1017
+
977
1018
private handleTexty ( e : MouseEvent ) {
978
1019
const { x, y } = this . transformPanScale ( e . clientX , e . clientY ) ;
979
1020
@@ -1767,6 +1808,9 @@ export class CanvasEngine {
1767
1808
this . canvas . removeEventListener ( "mousemove" , this . mouseMoveHandler ) ;
1768
1809
this . canvas . removeEventListener ( "mouseup" , this . mouseUpHandler ) ;
1769
1810
this . canvas . removeEventListener ( "wheel" , this . mouseWheelHandler ) ;
1811
+ this . canvas . removeEventListener ( "touchstart" , this . touchStartHandler ) ;
1812
+ this . canvas . removeEventListener ( "touchmove" , this . touchMoveHandler ) ;
1813
+ this . canvas . removeEventListener ( "touchend" , this . touchEndHandler ) ;
1770
1814
1771
1815
if ( this . socket ?. readyState === WebSocket . OPEN ) {
1772
1816
this . socket . send (
0 commit comments