import type { NzSafeAny } from 'ng-zorro-antd/core/types' ; license /** Creates a browser MouseEvent with the specified options. */ export function createMouseEvent ( type , x = 0 , y = 0 ) { const event = document . createEvent ( 'MouseEvent' ) ; event . initMouseEvent ( type , false , false , window , 0 , x , y , x , y , false , false , false , false , 0 , null ) ; return event ; } /** Creates a browser TouchEvent with the specified pointer coordinates. */ export function createTouchEvent ( type , pageX = 0 , pageY = 0 ) { const event = document . createEvent ( 'UIEvent' ) ; const touchDetails = { pageX , pageY } ; ( event as NzSafeAny ) . initUIEvent ( type , true , true , window , 0 ) ; Object . defineProperties ( event , { touches : { value : [ touchDetails ] } } ) ; return event ; } /** Dispatches a keydown event from an element. */ export function createKeyboardEvent ( type , keyCode , target ? , key ? ) { const event = document . createEvent ( 'KeyboardEvent' ) as NzSafeAny ; const initEventFn = ( event . initKeyEvent || event . initKeyboardEvent ) . bind ( event ) ; const originalPreventDefault = event . preventDefault ; initEventFn ( type , true , true , window , 0 , 0 , 0 , 0 , 0 , keyCode ) ; Object . defineProperties ( event , { keyCode : { get : ( ) => keyCode } , key : { get : ( ) => key } , target : { get : ( ) => target } } ) ; event . preventDefault = function ( ) : NzSafeAny { Object . defineProperty ( event , 'defaultPrevented' , { get : ( ) => true } ) ; return originalPreventDefault . apply ( this , arguments ) ; } ; return event ; } /** Creates a fake event object with any desired event type. */ export function createFakeEvent ( type , canBubble = true , cancelable = true ) { const event = document . createEvent ( 'Event' ) ; event . initEvent ( type , canBubble , cancelable ) ; return event ; }