UNPKG

@blossom-carousel/svelte

Version:

A native-scroll-first carousel component for Svelte.

81 lines (80 loc) 3.96 kB
/** * Self-contained, depth-agnostic readers of inline-axis scroll-snap geometry. * Used by the prev/next page-scroll logic and the dots' active-marker * computation so both are deterministic regardless of whether Blossom is * initialized. This intentionally does not depend on `@blossom-carousel/core` * so that the navigation controls stay lightweight and usable without a * Blossom instance. */ export type InlineAlign = "start" | "center" | "end"; /** Whether the scroller lays out its inline axis right-to-left. */ export declare function isRtl(scroller: HTMLElement): boolean; /** * The logical inline scroll offset: `0` at the inline-start edge, increasing * towards the inline-end. In RTL the physical `scrollLeft` runs `[-max, 0]`, * so it is negated to recover the same `[0, max]` range as LTR. Every snap * position in this package lives in this logical space, so comparisons against * the live scroll offset must go through this helper rather than reading * `scrollLeft` directly. */ export declare function logicalScrollLeft(scroller: HTMLElement, rtl: boolean): number; /** * A snap target paired with its resolved inline alignment — everything needed * to bring it into view via `scrollIntoView({ inline })`. */ export interface SnapTarget { /** The snap target element. */ el: HTMLElement; /** * The resolved inline `scroll-snap-align` (never `"none"` — opting out falls * back to `"start"`). Maps directly onto `scrollIntoView({ inline })`. */ align: InlineAlign; } /** * A {@link SnapTarget} plus its resolved snap position, used by prev/next * paging to locate the adjacent snap point relative to the current scroll. */ export interface SnapPoint extends SnapTarget { /** * The clamped logical scroll offset (see {@link logicalScrollLeft}) at which * the target rests when snapped. */ x: number; } /** * Resolves the inline-axis component of a computed `scroll-snap-align` value. * Returns `"none"` when snapping is not requested on the inline axis. */ export declare function inlineSnapAlign(value: string): InlineAlign | "none"; /** * Like `inlineSnapAlign`, but resolves the `"none"` case to `"start"` so the * result can be passed straight to `scrollIntoView({ inline })`. */ export declare function resolveInlineAlign(value: string): InlineAlign; /** * The (unclamped) logical scroll offset at which `target` would rest when * snapped to the given inline alignment. Unclamped on purpose: callers use the * raw value to tell whether a target can physically reach its snap position. * * Computed in logical coordinates (see {@link logicalScrollLeft}): in RTL the * inline-start edge is the physical right, so the target's offset is measured * from the scroller's right edge and the result compares directly against the * logical scroll offset in both directions. */ export declare function snapPositionFor(scroller: HTMLElement, target: HTMLElement, align: InlineAlign, scrollerRect: DOMRect, scrollPaddingStart: number, scrollPaddingEnd: number, rtl: boolean, styles?: CSSStyleDeclaration): number; /** * The snap target for each marker, in tree order (parallel to * `getMarkerTargets`): its element and resolved inline alignment. `goto` indexes * straight into the result and hands both to `scrollIntoView`, which resolves * the final scroll position natively — so this needs only a style read per * target (no layout), making it cheap to (re)build on resize/mutation. */ export declare function getMarkerSnaps(targets: HTMLElement[]): SnapTarget[]; /** * Returns the inline-axis snap points (ascending by position, near-duplicates * dropped) that prev/next paging steps through. Each carries its element and * resolved alignment so paging can `scrollIntoView` the adjacent target with * its own inline alignment, plus the clamped `x` used to locate it. */ export declare function getSnapPositions(scroller: HTMLElement): SnapPoint[];