import { report } from '../../../utils' ; import { getIntersectionRatioOfHandle } from '../get-intersection-ratio-of-handle' ; import { VerboseOptions } from '../is-handle-visible' ; import { ElementHandle } from 'playwright' ; declare const window ; export async function isHandleVisibleInViewport ( selector , options ) { if ( selector === undefined || selector === null ) { return false ; } const visibleRatio = await getIntersectionRatioOfHandle ( selector ) ; report ( `visible ratio is ${ visibleRatio }` , options . verbose ) ; if ( visibleRatio <= 0 ) { report ( `selector is not visible in the current viewport` , options . verbose ) ; return false ; } const result = await selector . evaluate ( ( el ) : boolean => { function hasVisibleBoundingBox ( element ) { const rect = element . getBoundingClientRect ( ) ; return ! ! ( rect . top || rect . bottom || rect . width || rect . height ) ; } const style = window . getComputedStyle ( el ) ; if ( style && style . opacity && style . opacity === '0' ) { return false ; } const isVisible = style && style . visibility !== 'hidden' && hasVisibleBoundingBox ( el ) ; return isVisible ; } ) ; return result ; }