import { IPositionStats , IScrollState , IScrollerDistance } from '../models' ; export function shouldFireScrollEvent ( container , distance , scrollingDown ) { let remaining ; let containerBreakpoint ; if ( container . totalToScroll <= 0 ) { return false ; } const scrolledUntilNow = container . isWindow ? container . scrolled : container . height + container . scrolled ; if ( scrollingDown ) { remaining = ( container . totalToScroll - scrolledUntilNow ) / container . totalToScroll ; containerBreakpoint = distance . down / 10 ; } else { const totalHiddenContentHeight = container . scrolled + ( container . totalToScroll - scrolledUntilNow ) ; remaining = container . scrolled / totalHiddenContentHeight ; containerBreakpoint = distance . up / 10 ; } const shouldFireEvent = remaining <= containerBreakpoint ; return shouldFireEvent ; } export function isScrollingDownwards ( lastScrollPosition , container ) { return lastScrollPosition < container . scrolled ; } export function getScrollStats ( lastScrollPosition , container , distance ) { const scrollDown = isScrollingDownwards ( lastScrollPosition , container ) ; return { fire : shouldFireScrollEvent ( container , distance , scrollDown ) , scrollDown } ; } export function updateScrollPosition ( position , scrollState ) { return ( scrollState . lastScrollPosition = position ) ; } export function updateTotalToScroll ( totalToScroll , scrollState ) { if ( scrollState . lastTotalToScroll !== totalToScroll ) { scrollState . lastTotalToScroll = scrollState . totalToScroll ; scrollState . totalToScroll = totalToScroll ; } } export function isSameTotalToScroll ( scrollState ) { return scrollState . totalToScroll === scrollState . lastTotalToScroll ; } export function updateTriggeredFlag ( scroll , scrollState , triggered , isScrollingDown ) { if ( isScrollingDown ) { scrollState . triggered . down = scroll ; } else { scrollState . triggered . up = scroll ; } } export function isTriggeredScroll ( totalToScroll , scrollState , isScrollingDown ) { return isScrollingDown ? scrollState . triggered . down === totalToScroll : scrollState . triggered . up === totalToScroll ; } export function updateScrollState ( scrollState , scrolledUntilNow , totalToScroll ) { updateScrollPosition ( scrolledUntilNow , scrollState ) ; updateTotalToScroll ( totalToScroll , scrollState ) ; }