import { Region , RegionCardinality , Regions } from "../../regions" ; /**
 * Returns the scroll{Left,Top} offsets of the provided region based on its
 * cardinality.
 */ export function getScrollPositionForRegion ( region , currScrollLeft , currScrollTop , getLeftOffset , getTopOffset , numFrozenRows = 0 , numFrozenColumns = 0 ) { const cardinality = Regions . getRegionCardinality ( region ) ; let scrollTop = currScrollTop ; let scrollLeft = currScrollLeft ; const frozenColumnsCumulativeWidth = getLeftOffset ( numFrozenColumns ) ; const frozenRowsCumulativeHeight = getTopOffset ( numFrozenRows ) ; switch ( cardinality ) { case RegionCardinality . CELLS : { const topOffset = getTopOffset ( region . rows [ 0 ] ) ; const leftOffset = getLeftOffset ( region . cols [ 0 ] ) ; scrollTop = getClampedScrollPosition ( topOffset , frozenRowsCumulativeHeight ) ; scrollLeft = getClampedScrollPosition ( leftOffset , frozenColumnsCumulativeWidth ) ; break ; } case RegionCardinality . FULL_ROWS : { const topOffset = getTopOffset ( region . rows [ 0 ] ) ; scrollTop = getClampedScrollPosition ( topOffset , frozenRowsCumulativeHeight ) ; break ; } case RegionCardinality . FULL_COLUMNS : { const leftOffset = getLeftOffset ( region . cols [ 0 ] ) ; scrollLeft = getClampedScrollPosition ( leftOffset , frozenColumnsCumulativeWidth ) ; break ; } default : { scrollTop = 0 ; scrollLeft = 0 ; break ; } } return { scrollLeft , scrollTop } ; } /**
 * Returns the thickness of the target scroll bar in pixels.
 * If the target scroll bar is not present, 0 is returned.
 */ export function measureScrollBarThickness ( element , direction ) { if ( element == null ) { return 0 ; } return direction === "horizontal" ? element . offsetHeight - element . clientHeight : element . offsetWidth - element . clientWidth ; } /**
 * Adjust the scroll position to align content just beyond the frozen region, if necessary.
 */ function getClampedScrollPosition ( scrollOffset , frozenRegionCumulativeSize ) { return Math . max ( scrollOffset - frozenRegionCumulativeSize , 0 ) ; }