import { Page } from 'playwright' ; import { Point , isPoint } from './Point' ; import { ElementHandle , MousePressOptions , ClickOptions } from './types' ; const isElementHandle = ( thing ) : thing is ElementHandle => { return typeof thing === 'object' && typeof thing . centerPoint === 'function' ; } ; class public export default class Mouse { constructor ( private page ) { } /**
     * Dispatches a `mousedown` event
     */ public async down ( options ? ) { return this . page . mouse . down ( options ) ; } /**
     * Dispatches a `mouseup` event
     */ public async up ( options ? ) { return this . page . mouse . up ( options ) ; } /**
     * Dispatches a `mousemove` event
     */ public async move ( x , y , options ? ) { return this . page . mouse . move ( x , y , options ) ; } /**
     * Shortcut for `mouse.move`, `mouse.down`, `mouse.move` and `mouse.up`.
     */ public async drag ( from , to ) { await this . move ( ... from ) ; await this . down ( ) ; await this . move ( ... to ) ; await this . up ( ) ; } /**
     * Shortcut for `mouse.move`, `mouse.down` and `mouse.up`.
     */ public async click ( x , options ? ) ; public async click ( x , options ? ) ; public async click ( x , y , options ? ) ; public async click ( x , y ? , options ? ) { if ( isElementHandle ( x ) && typeof y !== 'number' ) { const coords = await x . centerPoint ( ) ; return this . page . mouse . click ( coords [ 0 ] , coords [ 1 ] , y ) ; } else if ( isPoint ( x ) && typeof y !== 'number' ) { return this . page . mouse . click ( x [ 0 ] , x [ 1 ] , y ) ; } else if ( typeof x === 'number' && typeof y === 'number' ) { return this . page . mouse . click ( x , y , options ) ; } } }