license import CharacterStatsCalculator from './character-stats-calculator' ; export default class ScrollStabilizer { stabilizing = false ; latestScrollStats ? : { containerWidth : number ; exploredCharCount : number ; } ; constructor ( private window ) { } onResize ( containerWidth , calculator ) { if ( this . latestScrollStats && Math . abs ( this . latestScrollStats . containerWidth - containerWidth ) > 10 ) { const scrollPos = calculator . getScrollPosByCharCount ( this . latestScrollStats . exploredCharCount ) ; this . stabilizing = true ; this . window . scrollTo ( scrollPos , 0 ) ; this . latestScrollStats . containerWidth = containerWidth ; } } }