/** * Pure, DOM-independent scroll logic for `seki-message-scroller`. * * These functions carry the "hard" math of the scroller — edge detection, * follow engagement, prepend-scroll preservation and anchor resolution — as * pure functions so they can be unit-tested without a browser (jsdom can't lay * out real scroll geometry). The component feeds them measured numbers * (scrollTop / scrollHeight / clientHeight / element offsets) and applies the * results imperatively to the DOM. */ export interface ScrollMetrics { /** Current scroll offset of the viewport. */ scrollTop: number; /** Total scrollable content height. */ scrollHeight: number; /** Visible height of the viewport. */ clientHeight: number; } export interface EdgeState { /** Scrolled to (or within threshold of) the very top. */ atStart: boolean; /** Scrolled to (or within threshold of) the very bottom (live edge). */ atEnd: boolean; } /** Position of an item within the viewport's scroll coordinate space. */ export interface ItemPosition { /** Distance from the top of the scroll content to the item's top. */ offset: number; /** Whether the item is a turn boundary (`scroll-anchor`). */ isAnchor: boolean; } export type ScrollPosition = 'start' | 'end' | 'last-anchor'; /** * Default distance (px) from an edge that still counts as "at" that edge. * A small slack keeps follow-output engaged through sub-pixel rounding and the * momentary gap while a streamed token grows the last row. */ export declare const DEFAULT_EDGE_THRESHOLD = 24; /** Largest scrollTop the viewport can reach given its metrics. */ export declare function maxScrollTop(m: ScrollMetrics): number; /** * Resolve whether the viewport sits at the start and/or end edge. * When the content is shorter than the viewport (no scrollbar) both edges are * true — there is nowhere to scroll, so every position is simultaneously the * start and the live edge. */ export declare function computeEdgeState(m: ScrollMetrics, threshold?: number): EdgeState; /** * Whether follow-output should be engaged for the given metrics. * Follow is engaged only while the reader is parked at the live edge; any * upward scroll that moves past the threshold disengages it. This is derived * purely from position, so re-reaching the bottom re-engages automatically. */ export declare function shouldEngageFollow(m: ScrollMetrics, threshold?: number): boolean; /** * New scrollTop that keeps the current view visually stationary after content is * prepended above it. * * `prevMeasure` / `newMeasure` are a before/after measure of however much * content sits above the fold — the caller supplies whatever measurement is * accurate for its case (e.g. `0` and the summed real height of just the rows * it inserted, measured directly via `getBoundingClientRect()` rather than a * general scrollHeight delta, which can be skewed by `content-visibility: * auto` placeholder sizing on off-screen rows). The difference is the height * inserted above the fold, so shifting scrollTop by it cancels the visual jump. */ export declare function computePrependScrollTop(currentScrollTop: number, prevMeasure: number, newMeasure: number): number; /** * Offset of the last `scroll-anchor` item, minus a peek of the previous turn. * Returns `null` when there are no anchor rows. */ export declare function resolveLastAnchorScrollTop(items: ItemPosition[], peek?: number): number | null; /** * Resolve the scrollTop to apply on mount for a `defaultScrollPosition`. * `last-anchor` falls back to the live edge when no anchor rows exist, and is * always clamped to the reachable scroll range. */ export declare function resolveInitialScrollTop(position: ScrollPosition, m: ScrollMetrics, items?: ItemPosition[], peek?: number): number;