@blossom-carousel/svelte
Version:
A native-scroll-first carousel component for Svelte.
24 lines (23 loc) • 1.3 kB
TypeScript
import type { NavigationState } from "./types.js";
/**
* Computes the current navigation state of a scroller via native reads. Uses
* the cached, scroll-invariant marker list and geometry when available so the
* per-frame work on the scroll hot loop is free of DOM queries, style reads,
* sorts, and allocations — only the scroll metrics are read live.
*/
export declare function getNavigationState(scroller: HTMLElement): NavigationState;
type Subscriber = (state: NavigationState) => void;
/**
* Subscribes to everything that can change the navigation state (scrolling,
* snap settling, resizes, and added/removed slides) and pushes a fresh
* `NavigationState` to the callback, coalesced to one update per frame. Returns
* a cleanup function that removes the subscriber.
*
* Ref-counted per scroller: multiple controls pointing at the same scroller
* share one observer set and one frame loop, computing the state once and
* fanning it out to every subscriber. The observers (and the per-scroller snap
* cache they maintain — off the scroll path, since snap geometry only changes
* on resize/mutation) are torn down once the last subscriber unsubscribes.
*/
export declare function observeNavigationState(scroller: HTMLElement, callback: Subscriber): () => void;
export {};