import { Position } from "./types" ; export interface ScrollManagerDelegate { scrollPositionChanged ( position ) : void ; } export class ScrollManager { readonly delegate : ScrollManagerDelegate ; started = false ; constructor ( delegate ) { this . delegate = delegate ; } start ( ) { if ( ! this . started ) { addEventListener ( "scroll" , this . onScroll , false ) ; this . onScroll ( ) ; this . started = true ; } } stop ( ) { if ( this . started ) { removeEventListener ( "scroll" , this . onScroll , false ) ; this . started = false ; } } scrollToElement ( element ) { element . scrollIntoView ( ) ; } scrollToPosition ( { x , y } ) { window . scrollTo ( x , y ) ; } onScroll = ( ) => { this . updatePosition ( { x : window . pageXOffset , y : window . pageYOffset } ) ; } ; updatePosition ( position ) { this . delegate . scrollPositionChanged ( position ) ; } }