import { NEVER , Observable , Subject , defer , distinctUntilChanged , filter , finalize , map , merge , of , shareReplay , switchMap , tap } from "rxjs" ; import { getElementContentSize , getElementSize , watchElementContentOffset } from "~/browser" ; /**
 * Intersection observer entry subject
 */ const entry$ = new Subject < IntersectionObserverEntry > ( ) ; see https const observer$ = defer ( ( ) => of ( new IntersectionObserver ( entries => { for ( const entry of entries ) entry$ . next ( entry ) ; } , { threshold : 1 } ) ) ) . pipe ( switchMap ( observer => merge ( NEVER , of ( observer ) ) . pipe ( finalize ( ( ) => observer . disconnect ( ) ) ) ) , shareReplay ( 1 ) ) ; param el returns export function watchElementVisibility ( el ) { return observer$ . pipe ( tap ( observer => observer . observe ( el ) ) , switchMap ( observer => entry$ . pipe ( filter ( ( { target } ) => target === el ) , finalize ( ( ) => observer . unobserve ( el ) ) , map ( ( { isIntersecting } ) => isIntersecting ) ) ) ) ; } param el param threshold returns export function watchElementBoundary ( el , threshold = 16 ) { return watchElementContentOffset ( el ) . pipe ( map ( ( { y } ) => { const visible = getElementSize ( el ) ; const content = getElementContentSize ( el ) ; return y >= ( content . height - visible . height - threshold ) ; } ) , distinctUntilChanged ( ) ) ; }