The best way to control Claude Code, Codex and more from any computer or phone
| 1 | const STICKY_EDGE_TOLERANCE_PX = 1; |
| 2 | |
| 3 | export function sectionCollapseAnchorScrollTop(input: { |
| 4 | readonly scrollTop: number; |
| 5 | readonly viewportTop: number; |
| 6 | readonly sectionTop: number; |
| 7 | readonly headingTop: number; |
| 8 | }): number | null { |
| 9 | const sectionHasScrolledPastViewport = input.sectionTop < input.viewportTop; |
| 10 | const headingIsPinned = input.headingTop <= input.viewportTop + STICKY_EDGE_TOLERANCE_PX; |
| 11 | if (!sectionHasScrolledPastViewport || !headingIsPinned) return null; |
| 12 | |
| 13 | return Math.max(0, input.scrollTop + input.sectionTop - input.viewportTop); |
| 14 | } |