import { MaybeRef , round , unRef } from '@react-hooks-library/shared' ; import { _document } from '../_ssr.config' ; import { useEventListener } from '../useEventListener' ; param target param callback see https export function useScroll ( target = _document ?. documentElement , callback ) { const getPositions = ( ) => { const el = unRef ( target ) ; if ( ! el ) return ; return { x : round ( el . scrollLeft / ( el . scrollWidth - el . clientWidth ) ) , y : round ( el . scrollTop / ( el . scrollHeight - el . clientHeight ) ) } ; } ; useEventListener ( target , 'scroll' , ( ) => { const newScrollValues = getPositions ( ) ; if ( ! newScrollValues ) return ; const { x , y } = newScrollValues ; callback ( { scrollX : x , scrollY : y } ) ; } , { capture : false , passive : true } ) ; }