MCPcopy Create free account
hub / github.com/Alphanimble/htmlstream / syncNestedStreamScroll

Function syncNestedStreamScroll

src/hold-stream.ts:184–207  ·  view source on GitHub ↗
(
  root: HTMLElement,
  options?: { pin?: boolean; smooth?: boolean; factor?: number },
)

Source from the content-addressed store, hash-verified

182 * With `pin: false`, only scroll when the reader is already near the bottom.
183 */
184export 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}

Callers 2

tickFunction · 0.90

Calls 2

isVerticallyScrollableFunction · 0.85
easeScrollToBottomFunction · 0.85

Tested by

no test coverage detected