/** * @file glass.ts * @brief Canvas lifecycle and demand-driven rendering. * @details Frames reuse storage except when measuring elements followed on every frame. */ import type { BackdropPixels } from "../layout.js"; import { type DisplayBrightness } from "../hdr.js"; import { Renderer } from "../renderer/renderer.js"; import { type Result } from "../result.js"; import { GlassGroup } from "./group.js"; import { GlassShape } from "./shape.js"; import type { Appearance, EnvironmentOptions, Fit, Follow, GlassOptions, GroupOptions, ShapeOptions, StackingMode } from "./types.js"; /** * @brief Glass on a canvas: shapes and groups, a backdrop, and a render loop that runs while * something changes. */ export declare class Glass { /** @brief The canvas the glass is drawn on. */ readonly canvas: HTMLCanvasElement; /** * @brief The renderer underneath, for low-level calls (`update()` afterwards schedules a * frame). */ readonly renderer: Renderer; private readonly items; private readonly leaving; private readonly followers; private readonly backdrop; private readonly surroundings; private readonly onFrame; private readonly onWarm; private readonly onResolution; private readonly onLost; private readonly onRestored; private readonly lostCallback; private readonly restoredCallback; private resolutionQuery; private canvasObserver; private appearance; private dark; private env; private envBits; private range; private headroom; private extended; private rangeShown; private share; private pixelWidth; private pixelHeight; private ratio; private readonly maxRatio; private frameId; private warmId; private drawn; private measure; private reorder; private busy; private lost; private destroyed; /** @brief Why the glass could not be rebuilt after the context came back ("" otherwise). */ error: string; /** @brief Width of the canvas in CSS pixels. */ get width(): number; /** @brief Height of the canvas in CSS pixels. */ get height(): number; /** @brief The surroundings in effect, as `ENV_*` bits ("auto" settings resolved). */ get environment(): number; /** @brief True while the glass is drawn in extended range. */ get extendedRange(): boolean; /** @brief Supplied display multiplier; 1 until a finite value of at least 1 is supplied. */ get displayHeadroom(): number; /** * @brief True while the WebGL context is lost; drawing resumes on its own when it is back. */ get contextLost(): boolean; /** * @brief Add a shape. * @details Only the frame is required. */ add(o: ShapeOptions): GlassShape; /** * @brief Add a group: outlines added to it share one piece of glass and merge within `spacing`. */ addGroup(o?: GroupOptions): GlassGroup; /** * @brief Set the picture behind the glass. * @details It is laid on the canvas by `fit` and laid again when the canvas is resized. null * removes uploaded pixels and the retained source, including live and raw backdrops. * @param live Upload it again as it changes: a video when it shows a new picture, an animated * canvas on every frame. */ setBackdrop(source: TexImageSource | null, fit?: Fit, live?: boolean): void; /** @brief Remove the backdrop pixels and retained source, returning to the empty backdrop. */ clearBackdrop(): void; /** * @brief Set target-sized encoded extended-sRGB premultiplied float/half pixels. * @details RGB can exceed 1. Replaces a DOM/live backdrop after a successful upload, bypasses * 2D canvas fitting, and retains a snapshot for context restoration. Resubmit after resizing. */ setBackdropPixels(pixels: BackdropPixels): Result; /** @brief Change the default surroundings of the shapes. */ setAppearance(appearance: Appearance): void; /** * @brief Change the surroundings of the built-in materials: window activity, the tinted * setting, reduced transparency, increased contrast, reduced motion. * @details Fields left out keep their value; "auto" follows the device. */ setEnvironment(environment: EnvironmentOptions): void; /** * @brief Draw in extended range (values above the standard white on screens that show them) or * go back to standard range. * @details It can be turned on only when the glass was created with the `extendedRange` option * (true or "auto"): the drawing buffer needs an alpha channel for it, which is decided when the * context is made. * @param on true, false, or "auto" to follow `dynamic-range: high`. * @param headroom Brightest value of the screen relative to the standard white (kept when left * out). * @returns True when the glass is drawn in extended range now. */ setExtendedRange(on: Follow, headroom?: number): boolean; /** * @brief Set display headroom from brightness state supplied by the host. * @details Keeps the requested output range and independent surface/context scales. Invalid * state leaves the previous headroom and rendered frame intact; no device state is queried. * @returns The resolved display multiplier, or an input validation error. */ setDisplayBrightness(state: DisplayBrightness): Result; /** * @brief Turn every rim light by `radians` clockwise (for a light that follows a pointer or a * device's tilt). */ setLightAngle(radians: number): void; /** @brief Current default color-separation multiplier for shapes and groups. */ get chromaticAberration(): number; /** @brief Change color separation for items that inherit the canvas default. */ setChromaticAberration(strength: number): void; /** @brief Glass over glass: "overlap" (default), "exact" or "flat". */ setStacking(mode: StackingMode): void; /** * @brief Size the drawing buffer. * @details Without arguments it takes the displayed size of the canvas and the pixel ratio of * the screen (what `autoResize` does on its own). */ resize(width?: number, height?: number, ratio?: number): void; /** @brief Draw now (otherwise frames are drawn on their own after every change). */ render(now?: number): void; /** @brief Ask for a frame (after low-level calls on `renderer`). */ update(): void; /** @brief Stop the loop, drop the listeners and release the GPU objects. */ destroy(): void; private tick; private warm; private order; private setSize; private watchResolution; private surroundingsChanged; private applyEnvironment; private applyRange; private showRange; private whenLost; private whenRestored; private upload; } /** * @brief Put glass on a canvas: create a WebGL2 context and renderer, size the canvas to its * displayed size, draw when anything changes, and rebuild after context restoration. * @returns The glass, or why the canvas cannot be used. */ export declare function createGlass(canvas: HTMLCanvasElement, options?: GlassOptions): Result;