The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | export function isTimelineScrollTarget( |
| 2 | target: EventTarget | null, |
| 3 | timeline: HTMLElement, |
| 4 | deltaY: number, |
| 5 | wheel?: Pick<WheelEvent, "deltaX" | "shiftKey">, |
| 6 | ): boolean { |
| 7 | if (!(target instanceof Element) || !timeline.contains(target) || deltaY === 0) return false; |
| 8 | // Shift-wheel scrolls sideways; trackpads can add vertical noise to a horizontal swipe. |
| 9 | if (wheel?.shiftKey || Math.abs(wheel?.deltaX ?? 0) > Math.abs(deltaY)) return false; |
| 10 | |
| 11 | for ( |
| 12 | let element: Element | null = target; |
| 13 | element && element !== timeline; |
| 14 | element = element.parentElement |
| 15 | ) { |
| 16 | const style = getComputedStyle(element); |
| 17 | if (style.overflowY !== "auto" && style.overflowY !== "scroll") continue; |
| 18 | |
| 19 | const canScroll = |
| 20 | deltaY < 0 |
| 21 | ? element.scrollTop > 0 |
| 22 | : element.scrollTop < element.scrollHeight - element.clientHeight; |
| 23 | if ( |
| 24 | canScroll || |
| 25 | style.overscrollBehaviorY === "contain" || |
| 26 | style.overscrollBehaviorY === "none" |
| 27 | ) { |
| 28 | return false; |
| 29 | } |
| 30 | } |
| 31 | return true; |
| 32 | } |
| 33 | |
| 34 | // Sandboxed iframe gestures are invisible to the parent; only their chained scroll arrives. |
| 35 | export function createUpwardScrollDetector(initial: { top: number; height: number }) { |
| 36 | let baseline = initial; |
| 37 | return (next: { top: number; height: number; programmatic?: boolean }) => { |
| 38 | if (next.programmatic || next.height < baseline.height || next.top > baseline.top) { |
| 39 | baseline = next; |
| 40 | return false; |
| 41 | } |
| 42 | if (next.top < baseline.top - 1) { |
| 43 | baseline = next; |
| 44 | return true; |
| 45 | } |
| 46 | // A slow scroll can move under a pixel per event; let those moves add up. |
| 47 | baseline = { top: baseline.top, height: next.height }; |
| 48 | return false; |
| 49 | }; |
| 50 | } |