import { ref , onMounted , onUnmounted , Ref } from '@src/api' ; const errorMsg = 'IntersectionObserver is not supported, please install a polyfill' ; export function useIntersection ( elRef , options = { } , runOnMount = true ) { const observedEntry = ref ( null ) ; const handleObserver = ( entries ) => { observedEntry . value = entries [ 0 ] ; } ; let observer = null ; const start = ( ) => { if ( ! ( 'IntersectionObserver' in window ) ) throw new Error ( errorMsg ) ; if ( observer || ! elRef . value ) return ; observer = new IntersectionObserver ( handleObserver , options ) ; observer . observe ( elRef . value ) ; } ; const stop = ( ) => { if ( ! observer ) return ; observer . disconnect ( ) ; observer = null ; } ; onMounted ( ( ) => runOnMount && start ( ) ) ; onUnmounted ( stop ) ; return { observedEntry , start , stop } ; }