Skip to content
File

Blob: src/client/components/log-viewer-scroll.ts

typescript21 lines
1const DEFAULT_BOTTOM_TOLERANCE_PX = 20;
2const BOTTOM_PADDING_EPSILON_PX = 2;
3 
4export interface ScrollPositionSnapshot {
5 scrollTop: number;
6 clientHeight: number;
7 scrollHeight: number;
8 paddingBottom: number;
9}
10 
11export const isLogViewerPinnedToLatest = ({
12 scrollTop,
13 clientHeight,
14 scrollHeight,
15 paddingBottom,
16}: ScrollPositionSnapshot) => {
17 const bottomGap = Math.max(0, scrollHeight - clientHeight - scrollTop);
18 const bottomTolerance = Math.max(DEFAULT_BOTTOM_TOLERANCE_PX, Math.max(0, paddingBottom) + BOTTOM_PADDING_EPSILON_PX);
19 return bottomGap <= bottomTolerance;
20};