import { floatyDebug } from './floaty-debug' ; import { Radius } from './interface' ; import { isRadius , isRect , isRegExp , isUiObject } from './type-check' ; import { simpleUiObject } from './ui-object' ; type Position = ( bounds : Rect | Radius ) => { x : number ; y : number ; } ; function boundsClick ( rect ? , delay ? , position ? ) ; function boundsClick ( ele ? , delay ? , position ? ) ; function boundsClick ( str ? , delay ? , position ? ) ; function boundsClick ( reg ? , delay ? , position ? ) ; function boundsClick ( radius ? , delay ? , position ? ) ; function boundsClick ( param ? , delay = 2000 , position = ( bounds ) => { let tmp ; if ( isRect ( bounds ) ) { tmp = { x : bounds . centerX ( ) , y : bounds . centerY ( ) } ; } else { tmp = bounds ; } if ( tmp . x === null || tmp . x === null || tmp . x === undefined || tmp . x === undefined ) { throw new Error ( 'no position found' ) ; } return tmp ; } ) { let bounds ; if ( typeof param === 'undefined' || param === null ) { return false ; } if ( typeof param === 'string' ) { bounds = textContains ( param ) . findOnce ( ) ?. bounds ( ) ; } else if ( isRegExp ( param ) ) { bounds = textMatches ( param ) . findOnce ( ) ?. bounds ( ) ; } else if ( isRect ( param ) ) { bounds = param ; } else if ( isRadius ( param ) ) { bounds = param ; } else if ( isUiObject ( param ) ) { console . log ( simpleUiObject ( param ) ) ; bounds = param ?. bounds ( ) ; } if ( ! bounds ) { return false ; } floatyDebug ( bounds ) ; const { x , y } = position ( bounds ) ; click ( x , y ) ; sleep ( delay ) ; return true ; } export { boundsClick } ;