File
Blob: src/client/components/log-viewer-scroll.ts
| 1 | const DEFAULT_BOTTOM_TOLERANCE_PX = 20; |
| 2 | const BOTTOM_PADDING_EPSILON_PX = 2; |
| 3 | |
| 4 | export interface ScrollPositionSnapshot { |
| 5 | scrollTop: number; |
| 6 | clientHeight: number; |
| 7 | scrollHeight: number; |
| 8 | paddingBottom: number; |
| 9 | } |
| 10 | |
| 11 | export 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 | }; |