(
root: HTMLElement,
options?: { pin?: boolean; smooth?: boolean; factor?: number },
)
| 182 | * With `pin: false`, only scroll when the reader is already near the bottom. |
| 183 | */ |
| 184 | export function syncNestedStreamScroll( |
| 185 | root: HTMLElement, |
| 186 | options?: { pin?: boolean; smooth?: boolean; factor?: number }, |
| 187 | ): void { |
| 188 | const thresholdPx = options?.pin === false ? 80 : Number.POSITIVE_INFINITY; |
| 189 | const smooth = options?.smooth ?? false; |
| 190 | const factor = options?.factor ?? DEFAULT_STREAM_SCROLL_EASE; |
| 191 | |
| 192 | root.querySelectorAll(NESTED_SCROLL_SELECTOR).forEach((node) => { |
| 193 | const el = node as HTMLElement; |
| 194 | if (!isVerticallyScrollable(el)) { |
| 195 | return; |
| 196 | } |
| 197 | const distanceFromBottom = |
| 198 | el.scrollHeight - el.scrollTop - el.clientHeight; |
| 199 | if (distanceFromBottom <= thresholdPx) { |
| 200 | if (smooth) { |
| 201 | easeScrollToBottom(el, factor); |
| 202 | } else { |
| 203 | el.scrollTop = el.scrollHeight; |
| 204 | } |
| 205 | } |
| 206 | }); |
| 207 | } |
no test coverage detected