import type { Layout, Measured } from './layout.js'; import type { Motion } from './engine.js'; export type { Layout, Measured, Motion }; /** Where a slide is. */ export interface Place { /** The slide. */ el: HTMLElement; /** Its start edge in the view, px. */ x: number; /** * How far it is from its resting place, in slides: 1 is one slide after * the active one. */ p: number; /** How much of it is in the view, 0 to 1. */ share: number; /** Whether any of it is in the view. */ visible: boolean; } /** What plugins and `frame` listeners get. */ export interface View { /** The layout. */ layout: Layout; /** The motion. */ motion: Motion; /** Where each slide is. */ places: Place[]; /** Views per second; zero for visitors who want less motion. */ velocity: number; /** Whether the visitor wants less motion. */ still: boolean; } /** What the slider calls of a plugin. */ export interface Hooks { /** Name under which the slider has it in `plugins`. */ name?: string; /** * Gets what was measured of the slides and may change it, to lay them * out another way. */ layout?: (measured: Measured) => void; /** After every layout. */ measure?: (view: View) => void; /** Slides were added or removed. */ slides?: () => void; /** Every frame while something moves. */ frame?: (view: View, dt: number, now: number) => void; /** True asks for another frame. */ busy?: () => boolean; /** * Which slide is seen at a point of the page, for a plugin that draws * them elsewhere than the page has them; -1 for none, nothing when the * page draws them. */ at?: (x: number, y: number) => number | undefined; /** The slider goes. */ destroy?: () => void; } /** The hooks, and whatever else the plugin has for those who use it. */ export type Plugin = Hooks & Record; /** What the listeners of each event get, before the slider. */ export interface Events { /** The slider. */ ready: Slider; /** Snap the slider goes to. */ change: number; /** Snap it came to rest at. */ settle: number; /** The view. */ frame: View; /** The layout. */ measure: Layout; /** The slides. */ slides: HTMLElement[]; /** Indexes of the slides in view. */ visible: number[]; /** The motion. */ dragstart: Motion; /** Velocity it was let go with, px per second. */ dragend: number; /** The slide and the click. */ click: { index: number; event: MouseEvent; }; /** The slider. */ destroy: Slider; } /** What listens to the event of a name. */ export type Listener = K extends keyof Events ? (detail: Events[K], slider: Slider) => void : K extends '*' ? (name: string, detail: any, slider: Slider) => void : (detail: any, slider: Slider) => void; /** What `plugins` and `use()` take: makes a plugin for a slider. */ export type Create = (slider: Slider) => Plugin | void; export interface Options { /** * Slides per view; `auto` takes each slide's own width. Without it, the * CSS decides (`--gs-per-view`). */ perView?: number | 'auto'; /** Gap in px. Without it, the CSS decides (`--gs-gap`). */ gap?: number; /** * `y`: the slides follow each other downwards. The slider needs a height * then. */ axis?: 'x' | 'y'; /** Go round. */ loop?: boolean; /** Where the active slide rests in the view. */ align?: 'start' | 'center' | 'end'; /** Slides per step. */ group?: number; /** No empty space at the ends. */ contain?: boolean; /** Rest anywhere, not only on slides. */ free?: boolean; /** Time of a move, ms. */ duration?: number; /** * Curve of a move to a slide, from 0 to 1 in `duration`: instead of the * spring. A drag let go is the spring all the same. */ ease?: (u: number) => number; /** First slide shown. */ start?: number; /** Pointer dragging. */ drag?: boolean; /** Listeners, by the name of their event. */ on?: { [K in keyof Events]?: Listener; } & Record; /** What the slider does besides moving the slides of the page. */ plugins?: Create[]; } /** * @param root The slider element. * @param options Options. */ export declare function createSlider(root: HTMLElement, options?: Options): Slider; /** A slider. */ export interface Slider { /** The slider element. */ root: HTMLElement; /** Parent of the slides. */ track: HTMLElement; /** The slides. */ slides: HTMLElement[]; /** Its options, as they are now. */ options: Options; /** The motion. */ motion: Motion; /** What plugins and `frame` listeners get. */ view: View; /** Its window. */ win: Window & typeof globalThis; /** Ends with the slider: for the listeners of plugins. */ signal: AbortSignal; /** Index of the snap the slider is at or moves to. */ readonly index: number; /** Index of the snap it was at before. */ readonly previous: number; /** Whether the slider rests: nothing moves, nothing is drawn. */ readonly resting: boolean; /** Whether there is a snap to go on to. */ readonly canNext: boolean; /** Whether there is a snap to go back to. */ readonly canPrev: boolean; /** How far through its slides the slider is, 0 to 1. */ readonly progress: number; /** Number of snaps. */ count: () => number; /** Layout. */ layout: () => Layout; /** Indexes of the slides in view. */ visible: () => number[]; /** * @param to Snap index. * @param how.instant Without a move. */ to(to: number, how?: { instant?: boolean; }): void; /** * @param slide Index of a slide: with several slides per snap not * that of its snap. * @param how.instant Without a move. */ toSlide(slide: number, how?: { instant?: boolean; }): void; next: () => void; prev: () => void; /** The plugins that have a name, by their name. */ plugins: Record; /** * Adds a plugin to a slider that exists. * * @return What it made. */ use(create: Create): Plugin | void; /** Changes options of a slider that exists. Not its plugins. */ set(change: Options): void; /** * Measures again, after a change the slider cannot see. Slides that were * added or removed are seen by themselves. */ update: () => void; /** Requests a frame: for plugins that changed what they draw. */ wake: () => void; /** * Moves the slider and where it is going by the same distance: what it * is doing goes on from there. Past a snap, it tells `change`. * * @param by Distance, px. * @param push Whether it counts as speed of the slider, which effects * react to. */ shift(by: number, push?: boolean): void; /** * For what moves the slider by hand, as a pointer does: `grab()`, then * `drag( position )` as often as it moves, then `release( velocity )`. */ grab(): void; /** * @param position Position, px. Past its ends the slider follows only a * part of the way. */ drag: (position: number) => void; /** * @param velocity Velocity it is let go with, px per second. * @param from Position it was grabbed at. */ release(velocity: number, from?: number): void; /** * @param name Event, or `*` for all of them. * @param fn Listener: gets what the event has to say, then the slider. * @return Removes the listener. */ on(name: K, fn: Listener): () => void; /** * @param name Event. * @param fn Listener, heard once. * @return Removes the listener. */ once(name: K, fn: Listener): () => void; /** * @param name Event. * @param fn Listener to remove. */ off(name: string, fn: Function): void; /** * Tells the listeners of an event. * * @param name Event; plugins name theirs `plugin:event`. * @param detail What the listeners get. */ emit: (name: string, detail?: any) => void; destroy(): void; }