/** * Push-based stats-gl adapters for worker-owned rendering. * * The worker adapter owns render-worker GPU/CPU measurement. The main adapter owns DOM * panels and main-thread frame timing; remote metrics arrive only through pushed snapshots, * never frame-by-frame RPC polling. * * @module three-blocks/stats */ export interface StatsSnapshot { readonly sequence: number; readonly timestamp: number; readonly fps: number; readonly cpu: number; readonly gpu: number; readonly gpuCompute: number; } export interface StatsTextureFrame { readonly sequence: number; readonly timestamp: number; readonly name: string; readonly bitmap: TBitmap; readonly width: number; readonly height: number; } export interface StatsProfilerData { readonly fps: number; readonly cpu: number; readonly gpu: number; readonly gpuCompute: number; } export interface StatsProfilerOptions { readonly trackGPU?: boolean; readonly trackCPT?: boolean; readonly trackHz?: boolean; readonly trackFPS?: boolean; readonly logsPerSecond?: number; readonly graphsPerSecond?: number; readonly samplesLog?: number; readonly samplesGraph?: number; readonly precision?: number; readonly maxTimestampPairs?: number; } export interface StatsProfilerLike { init(renderer: unknown): PromiseLike | void; begin(): void; end(): void; update(): void; getData(): StatsProfilerData; captureTexture?(source: unknown, sourceId?: string): PromiseLike; dispose(): void; } export type StatsProfilerFactory = (options: StatsProfilerOptions) => PromiseLike | StatsProfilerLike; export interface StatsWorkerOptions { /** Disabled adapters do not import stats-gl or add update-loop work. */ readonly enabled?: boolean; /** Maximum pushed metric snapshots per second. Defaults to 15. */ readonly sampleRate?: number; readonly profiler?: StatsProfilerOptions; readonly createProfiler?: StatsProfilerFactory; readonly publish: (snapshot: StatsSnapshot) => void; readonly publishTexture?: (frame: StatsTextureFrame, transfer: readonly object[]) => void; /** Monotonic milliseconds. */ readonly now?: () => number; } export interface StatsTexturePanelState { readonly enabled: boolean; readonly visible: boolean; } /** Long-lived worker profiler that survives scene/component HMR. */ export declare class StatsWorkerAdapter { #private; constructor(options: StatsWorkerOptions); get enabled(): boolean; get initialized(): boolean; init(renderer: unknown): Promise; beginFrame(): void; /** Complete profiling and drain renderer timestamps every frame, but throttle snapshots. */ endFrame(): StatsSnapshot | undefined; setTexturePanelState(name: string, state: StatsTexturePanelState): void; captureTexture(name: string, source: unknown, width: number, height: number): Promise; dispose(): void; } export type StatsPanelMode = 'compact' | 'expanded' | 'hidden'; interface StyleLike { display?: string; } interface PanelChildLike { readonly style: StyleLike; } interface PanelDomLike { readonly style: StyleLike; readonly children?: ArrayLike; setAttribute?(name: string, value: string): void; } export interface StatsMainPanelLike { readonly dom: PanelDomLike; begin(): void; setData(data: StatsProfilerData & { readonly isWorker?: boolean; }): void; update(): void; showPanel?(id: number): void; addTexturePanel(name: string): unknown; setTextureBitmap(name: string, bitmap: object, width?: number, height?: number): void; dispose(): void; } export type StatsMainPanelFactory = () => PromiseLike | StatsMainPanelLike; interface ContainerLike { appendChild(child: unknown): unknown; } interface KeyboardEventLike { readonly code?: string; readonly key?: string; } interface KeyboardTargetLike { addEventListener(type: 'keydown', listener: (event: KeyboardEventLike) => void): void; removeEventListener(type: 'keydown', listener: (event: KeyboardEventLike) => void): void; } export interface StatsMainOptions { readonly enabled?: boolean; readonly mode?: StatsPanelMode; readonly toggleKey?: string; readonly texturePanels?: readonly string[]; /** Main-thread surfaces sampled locally without worker readback or image transfer. */ readonly textureSources?: readonly StatsMainTextureSource[]; readonly onTexturePanelState?: (name: string, state: StatsTexturePanelState) => void; readonly onTextureUpdate?: (name: string) => void; readonly container?: ContainerLike; readonly keyboardTarget?: KeyboardTargetLike; readonly createPanel?: StatsMainPanelFactory; } export interface StatsMainTextureSource { readonly name: string; readonly source: object | (() => object | null | undefined); readonly width: number; readonly height: number; /** Maximum local texture-thumbnail refreshes per second. Defaults to 15. */ readonly sampleRate?: number; } /** DOM-side stats panel with local CPU timing and push-driven worker metrics. */ export declare class StatsMainAdapter { #private; constructor(options?: StatsMainOptions); get mode(): StatsPanelMode; get initialized(): boolean; init(): Promise; receive(snapshot: StatsSnapshot): void; receiveTexture(frame: StatsTextureFrame): void; setMode(mode: StatsPanelMode): void; dispose(): void; } export declare function createStatsWorker(options: StatsWorkerOptions): StatsWorkerAdapter; export declare function createStatsMain(options?: StatsMainOptions): StatsMainAdapter; export {};