createFlipbook(options)
Constructs a flipbook in the given container and returns a handle.
All options except container and pages
have sensible defaults. Mutating the returned handle is the only
way to drive the flipbook — there's no React-style
re-render-with-new-options pattern.
createFlipbook({
container: HTMLElement,
pages: readonly PageSource[],
initialPage?: number,
axis?: "horizontal" | "vertical",
radius?: number,
tilt?: number,
backColor?: [r, g, b],
flipDuration?: number,
ease?: EasingFn,
loop?: boolean,
clickNavigation?: boolean,
dragNavigation?: boolean,
dragCommitThreshold?: number,
keyboardNavigation?: boolean,
autoplay?: boolean | { intervalMs: number },
ariaLabel?: string,
}): FlipbookHandle
FlipbookHandle
The return value of createFlipbook. Reactive state
via getters (current, length,
isFlipping, isPlaying), imperative
navigation, scroll-driven seek, autoplay control,
event subscriptions. destroy() tears down the
WebGL context, removes event listeners, and detaches the canvas.
interface FlipbookHandle {
readonly current: number;
readonly length: number;
readonly isFlipping: boolean;
readonly isPlaying: boolean;
readonly ready: Promise<void>;
next(): Promise<void>;
prev(): Promise<void>;
goTo(index: number, options?: { instant?: boolean }): Promise<void>;
seek(progress: number): void;
play(): void;
pause(): void;
on(event: "change", cb: (current: number, previous: number) => void): () => void;
on(event: "flipstart", cb: (from: number, to: number) => void): () => void;
on(event: "flipend", cb: (from: number, to: number) => void): () => void;
destroy(): void;
}
PageSource
Anything you can hand to a page slot. Strings are URLs; DOM
element variants are used as-is. Rich-DOM pages are out of scope
— pre-render to a canvas if you need text overlays,
dynamic content, or HTML.
type PageSource =
| string
| HTMLImageElement
| HTMLCanvasElement;
Events
flip.on(event, cb) returns an unsubscriber. Call
it to detach without tearing down the whole flipbook.
-
change(current, previous) — emitted after a
commit. current is the new page index.
-
flipstart(from, to) — emitted when a flip
begins. Fires after click / drag-commit / autoplay tick.
-
flipend(from, to) — emitted when the curl
tween settles. change fires fractionally before
flipend.