/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * The Schematic canvas's camera (#57, #1393): its live ref, which the input * handlers move and one frame applies to every surface (`requestRender`, the * coalesced frame), and a throttled snapshot of it for what the render * derives; the canvas's size and its pixel ratio; Fit's camera — home — and the * zoom's limit (invariants 23, 24); the interaction-mode machine a gesture * supersedes a fly by; the fly, on one clock (invariant 25); a zoom about a * point — the toolbar's, about the middle, and the wheel's, about the cursor; * Fit; the minimap's jump; the fly to the narrowing's matches, keyed on the * narrowing itself (invariant 22); * and what the camera tells as it moves — as it comes to rest, never during a * fly, the zone the viewport is in, for the Index (#1570), and where the * viewport rests, for the reader; where the zoom stands, for the toolbar; and * each move the viewer makes, for the frame, whose refusal's words go with it. * Its maths is `camera.ts`'. * * The commit-phase snapshot reads the camera (`use-paint.ts`, invariant 1), and * what moves it reads the snapshot and calls the painter's apply: * {@link useCamera} holds the camera, and is made before the snapshot; * {@link useCameraMoves} holds what moves it, and is made after it. * * @packageDocumentation */ import { type RefObject } from "react"; import type { SchematicViewportStore } from "../area.js"; import { type CameraEvent, type Viewport } from "./camera"; import type { DrawnItem, DrawnZone } from "./drawn"; import { type LodTier, type WorldBox } from "./model"; import type { Paint } from "./use-paint"; import type { SchematicCanvasFit } from "./view"; import type { ZoomRange } from "../../shared/schedule/zoom.js"; /** The world box a fly to a point frames: 8 × 6 units about it. */ export declare function pointFrame(p: { x: number; y: number; }): { x: number; y: number; w: number; h: number; }; /** * The world box a fly to an item frames (#1393): 8 × 6 units about its centre — or, for an item held to its own width * whose card that box shows too narrow for its words, the box about it at whose zoom its card draws whole * (`cardWhole`), so a step, Find's pick or the Index's lands on its card, as far as the zoom's limit reaches. * * @param item - The item * @param size - The canvas's size, in CSS px * @returns The world box */ export declare function itemFrame(item: DrawnItem, size: { readonly w: number; readonly h: number; }): { x: number; y: number; w: number; h: number; }; /** What {@link useCamera} reads. */ export interface CameraProps { /** The canvas's element: what its size is measured by. */ readonly canvasRef: RefObject; /** The drawing's extent's width, in world units. */ readonly W: number; /** The drawing's extent's height, in world units. */ readonly H: number; /** The items drawn, a hidden layer's left out: the zoom's limit follows the smallest of them held to its own width. */ readonly items: readonly DrawnItem[]; } /** * The camera, as the canvas renders by it (see the module docs). * * @param props - The canvas's element, the drawing's extent and its items * @returns The canvas's size and its pixel ratio, the camera's live ref and its snapshot, the fit and Fit's camera, the * zoom's px a world unit and its limit */ export declare function useCamera({ canvasRef, W, H, items }: CameraProps): { size: { w: number; h: number; } | null; dpr: number; cameraRef: RefObject; cameraSnapshot: Viewport; setCameraSnapshot: import("react").Dispatch>; fit: number; home: Viewport; ppu: number; maxZoom: number; }; /** The camera, as the canvas renders by it: {@link useCamera}'s. */ export type Camera = ReturnType; /** What {@link useCameraMoves} reads. */ export interface CameraMovesProps { /** The canvas's element: what the wheel is heard on. */ readonly canvasRef: RefObject; /** The drawing's extent's width, in world units. */ readonly W: number; /** The drawing's extent's height, in world units. */ readonly H: number; /** The tier the zoom's band draws its items at: what the reader is told the viewport rests at. */ readonly lod: LodTier; /** The zones drawn, a hidden layer's left out. */ readonly shownZones: readonly DrawnZone[]; /** What the narrowing takes out of every list and of the selection (#1392): the Index lists none of it. */ readonly narrowedOut: ReadonlySet; /** Told the zone the viewport is in, by its id — `undefined` for none — as that changes, once the camera rests (#1389, #1570). */ readonly onZoneInView: ((zone: string | undefined) => void) | undefined; /** Where the canvas writes its viewport as its camera comes to rest (#1393); `undefined`, it writes nowhere. */ readonly viewport: SchematicViewportStore | undefined; /** Told whether the zoom stands at Fit and at its limit, as either changes (#1393). */ readonly onZoomRange: ((range: ZoomRange) => void) | undefined; /** * Told as the viewer acts on the camera — a press, the wheel, a pinch, a zoom, Fit, the minimap, a fly — each its * transition into a mode; never a resize, which moves the camera by none. */ readonly onAction: (() => void) | undefined; /** What `fit` flies the camera to as the narrowing changes (§10.3): the narrowing it is keyed on, and whether what it flies to is read. */ readonly narrowingFit: SchematicCanvasFit; /** The box `fit` flies to: the matches the canvas draws of the kinds read whole or complete, and each kind read by area's narrowing's. */ readonly fitBox: WorldBox | undefined; /** The camera ({@link useCamera}'s). */ readonly camera: Camera; /** The commit-phase snapshot and the painter's apply (`use-paint.ts`). */ readonly paint: Paint; } /** * What moves the camera, and what the camera tells as it moves (see the module docs). * * @param props - The canvas's element and the drawing's extent, what the camera tells and whom, the narrowing's look and * its matches, the camera, and the snapshot and the painter's apply * @returns The frame applier, a press's draw of a frame still waiting, the mode machine's transition, the fly, Fit, a * zoom about the middle, and the minimap's jump and the pointer dragging it */ export declare function useCameraMoves({ canvasRef, W, H, lod, shownZones, narrowedOut, onZoneInView, viewport, onZoomRange, onAction, narrowingFit, fitBox, camera, paint, }: CameraMovesProps): { requestRender: () => void; drawPending: () => void; transition: (event: CameraEvent) => void; flyTo: (rect: { x: number; y: number; w: number; h: number; }, clearRight?: number) => void; resetView: () => void; zoomBy: (factor: number) => void; minimapJump: (el: HTMLElement, clientX: number, clientY: number) => void; }; /** What moves the camera: {@link useCameraMoves}'s. */ export type CameraMoves = ReturnType; //# sourceMappingURL=use-camera.d.ts.map