Open History to see the last commit
1export function isTimelineScrollTarget(
2 target: EventTarget | null,
3 timeline: HTMLElement,
4 deltaY: number,
5): boolean {
6 if (!(target instanceof Element) || !timeline.contains(target) || deltaY === 0) return false;
7
8 for (
9 let element: Element | null = target;
10 element && element !== timeline;
11 element = element.parentElement
12 ) {
13 const style = getComputedStyle(element);
14 if (style.overflowY !== "auto" && style.overflowY !== "scroll") continue;
15
16 const canScroll =
17 deltaY < 0
18 ? element.scrollTop > 0
19 : element.scrollTop < element.scrollHeight - element.clientHeight;
20 if (
21 canScroll ||
22 style.overscrollBehaviorY === "contain" ||
23 style.overscrollBehaviorY === "none"
24 ) {
25 return false;
26 }
27 }
28 return true;
29}
30
31// Sandboxed iframe gestures are invisible to the parent; only their chained scroll arrives.
32export function createUpwardScrollDetector(initial: { top: number; height: number }) {
33 let baseline = initial;
34 return (next: { top: number; height: number; programmatic?: boolean }) => {
35 if (next.programmatic || next.height < baseline.height || next.top > baseline.top) {
36 baseline = next;
37 return false;
38 }
39 if (next.top < baseline.top - 1) {
40 baseline = next;
41 return true;
42 }
43 // A slow scroll can move under a pixel per event; let those moves add up.
44 baseline = { top: baseline.top, height: next.height };
45 return false;
46 };
47}