@@ -24,13 +24,7 @@ export function emulateTouchFromMouseEvent(
2424 case 'mouseReleased' :
2525 triggerTouchEvent ( 'touchend' , el , x , y )
2626 if ( isClick ) {
27- el . dispatchEvent (
28- new MouseEvent ( 'click' , {
29- bubbles : true ,
30- cancelable : true ,
31- view : window ,
32- } )
33- )
27+ triggerMouseEvent ( 'click' , el , x , y )
3428 }
3529 isClick = false
3630 break
@@ -42,6 +36,47 @@ export function emulateTouchFromMouseEvent(
4236 }
4337}
4438
39+ export function dispatchMouseEvent ( params : Input . DispatchMouseEventRequest ) {
40+ const { type, x, y, deltaX, deltaY } = params
41+
42+ const el = document . elementFromPoint ( x , y ) || document . documentElement
43+
44+ switch ( type ) {
45+ case 'mousePressed' :
46+ isClick = true
47+ triggerMouseEvent ( 'mousedown' , el , x , y )
48+ break
49+ case 'mouseMoved' :
50+ isClick = false
51+ triggerMouseEvent ( 'mousemove' , el , x , y )
52+ break
53+ case 'mouseReleased' :
54+ triggerMouseEvent ( 'mouseup' , el , x , y )
55+ if ( isClick ) {
56+ triggerMouseEvent ( 'click' , el , x , y )
57+ }
58+ isClick = false
59+ break
60+ case 'mouseWheel' :
61+ if ( ! isUndef ( deltaX ) && ! isUndef ( deltaY ) ) {
62+ triggerScroll ( el , deltaX , deltaY )
63+ }
64+ break
65+ }
66+ }
67+
68+ function triggerMouseEvent ( type : string , el : Element , x : number , y : number ) {
69+ el . dispatchEvent (
70+ new MouseEvent ( type , {
71+ bubbles : true ,
72+ cancelable : true ,
73+ view : window ,
74+ clientX : x ,
75+ clientY : y ,
76+ } )
77+ )
78+ }
79+
4580function triggerTouchEvent ( type : string , el : Element , x : number , y : number ) {
4681 const touch = new Touch ( {
4782 identifier : 0 ,
0 commit comments