@@ -296,6 +296,15 @@ export class CanvasEngine {
296296 this . canvas . addEventListener ( "wheel" , this . mouseWheelHandler , {
297297 passive : false ,
298298 } ) ;
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+ } ) ;
299308 }
300309
301310 setTool ( tool : ToolType ) {
@@ -974,6 +983,38 @@ export class CanvasEngine {
974983 }
975984 } ;
976985
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+
9771018 private handleTexty ( e : MouseEvent ) {
9781019 const { x, y } = this . transformPanScale ( e . clientX , e . clientY ) ;
9791020
@@ -1767,6 +1808,9 @@ export class CanvasEngine {
17671808 this . canvas . removeEventListener ( "mousemove" , this . mouseMoveHandler ) ;
17681809 this . canvas . removeEventListener ( "mouseup" , this . mouseUpHandler ) ;
17691810 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 ) ;
17701814
17711815 if ( this . socket ?. readyState === WebSocket . OPEN ) {
17721816 this . socket . send (
0 commit comments