import * as THREE from 'three'; import { type Rect } from './framing.js'; import type { GoToOptions } from './LeafThrough.js'; import { type LeafThroughOptions, type Layout, type PageChangeDetail, type PaperDeform } from './options.js'; /** * The magazine's options, less those about its own canvas and DOM. Of `lighting`, only * `shadows` (whether sheets cast and receive them) and `sun.position` apply: the lights are * your scene's. Point `sun.position` towards your shadow-casting directional light, in the * magazine's own frame; it places the shadow a turning sheet casts right by the spine. * `lighting.shadows` changes without a rebuild. * * Its sheets stand apart by default (`paper.sheetGap` `0.0005`, about 0.1 mm paper on a * 210 mm page) and `paper.depthBias` is off, so they sort by real depth from any side. */ export type LeafThroughObjectOptions = Omit & { /** Reshapes the paper in your own GLSL. Experimental. */ deform?: PaperDeform; }; /** What the magazine draws with, from your scene. */ export interface LeafThroughObjectContext { /** The renderer drawing your scene. Pages load into it. */ renderer: THREE.WebGLRenderer; /** The camera your scene is drawn with. Pointer input is cast from it; change it later through `camera`. */ camera: THREE.Camera; /** * Takes pointer input, and keys with `interaction.keyboard: true` while it has focus. It must * show the camera's whole view. Default `renderer.domElement`. */ domElement?: HTMLElement; } export interface LeafThroughObjectEventMap extends THREE.Object3DEventMap { pagechange: { detail: PageChangeDetail; }; ready: {}; pageload: { detail: { page: number; }; }; error: { detail: { error: unknown; page?: number; }; }; /** Something changed between frames: draw one, and keep drawing while `tick()` returns true. */ change: {}; } /** Where the magazine lies in its own units. */ export interface LeafThroughBounds { /** The pages at rest: what to frame. */ pages: Rect; /** Everything a turning page can sweep through. */ reach: Rect; } /** * A 3D magazine to add to your own three.js scene. It draws nothing itself: call `tick()` * every frame you render, and render again whenever it fires `change`. * * In its own units a page is 1 wide and `pageAspect` tall, the spine runs up the y axis at * x = 0, and the pages lie on the z = 0 plane facing +z. Move, turn and scale it like any * object. Pointer input is cast through `camera` onto the pages, wherever they are. * * ```ts * const magazine = new LeafThroughObject({ renderer, camera }, { pages, layout: 'spread' }) * scene.add(magazine) * renderer.setAnimationLoop((now) => { * magazine.tick(now) * renderer.render(scene, camera) * }) * ``` */ export declare class LeafThroughObject extends THREE.Group { /** The camera your scene is drawn with; pointer input is cast from it. */ camera: THREE.Camera; readonly domElement: HTMLElement; private inputEnabled; /** * Whether it takes pointer and key input. Turn it off while it's tucked away or moving, * and on again; the pages stay as they are. Turning it off lets go of a page being held. * Default `true`. */ get enabled(): boolean; set enabled(value: boolean); private readonly renderer; private options; private readonly paper; private loader; private view; private spreadMedia; private readonly motionMedia; private readonly abort; private readonly riffle; private readonly metrics; private readonly ray; private readonly point; private readonly ends; private needsRender; private lastPagesKey; private loadVersion; private lastDetailKey; private inView; private ready; private readyFired; private disposed; constructor({ renderer, camera, domElement }: LeafThroughObjectContext, options: LeafThroughObjectOptions); /** First visible page, 0-based. */ get page(): number; get pageCount(): number; get layout(): Layout; get visiblePages(): number[]; /** True while a page is being dragged or is completing its turn. */ get turning(): boolean; /** * Where the magazine lies in its own units: frame `pages` with your camera. Changes with * the layout, which `'auto'` can switch as the window resizes. */ get bounds(): LeafThroughBounds; /** Turns to the next page. Returns false at the end. */ next(): boolean; /** Turns to the previous page. Returns false at the start. */ prev(): boolean; /** Shows `page` (0-based), jumping there or turning the pages one by one. */ goTo(page: number, { animate }?: GoToOptions): void; /** Loads the pages that failed again. Also happens by itself when the browser comes back online. */ retry(): void; /** Changes some options and keeps the rest. Structural changes rebuild the pages and keep the current page. */ update(options: Partial): void; /** Replaces every option at once: anything left out goes back to its default. */ setOptions(options: LeafThroughObjectOptions): void; /** * Whether a press at this point on screen lands on the magazine, which then takes it. Check * it in your own pointer handlers to leave such presses alone. False while it's hidden or * not `enabled`. */ covers(clientX: number, clientY: number): boolean; /** * Advances the pages to `now` (a `requestAnimationFrame` timestamp). Call it every frame * before rendering. Returns true while the pages are moving and need another frame. */ tick(now?: number): boolean; /** Frees the pages, textures and listeners, and takes the magazine out of its parent. */ dispose(): void; private applyOptions; private pickLayout; private watchSpreadQuery; private remount; private resolve; private readonly axis; private pageAxis; private dragWidth; private shown; private requestFrame; private pagesKey; private loadPages; private startPages; private followReader; private fail; private detail; private emitPageChange; }