Skip to content

Devtools API

Signatures and behavior for @idlekitjs/devtools.

Private package

@idlekitjs/devtools is private and not published to npm; it is only available inside the monorepo.

Imports

ts
import { devtools, DevMetrics } from "@idlekitjs/devtools";
import type { DevtoolsExtension, DevtoolsOptions } from "@idlekitjs/devtools";

devtools

ts
function devtools<T extends object>(
  options?: DevtoolsOptions<T>,
): DevtoolsExtension<T>;

Returns an Extension<T> installable with engine.use(...).

ts
interface DevtoolsOptions<T extends object> {
  save?: SaveManager<T>;
  dispose?: () => void;
  stats?: (state: T) => Record<string, unknown>;
  hotkey?: string;
  open?: boolean;
  refreshMs?: number;
}
OptionBehavior
saveEnables overlay save and wipe actions.
disposeCalled before wiping data. Useful for stopping loops and lifecycle saves.
statsExtra rows, recomputed on each refresh.
hotkeyKeyboardEvent.key that toggles the overlay. Default: backtick.
openStart expanded. Default: true.
refreshMsText refresh interval in milliseconds. Default: 200.

The extension mounts a browser overlay when document exists and removes it on teardown. Outside the browser, setup does not mount UI.

DevtoolsExtension

ts
interface DevtoolsExtension<T extends object> extends Extension<T> {
  readonly metrics: DevMetrics;
}

The extension records one tick in update and one frame in render.

DevMetrics

ts
class DevMetrics {
  recordTick(): void;
  recordFrame(nowMs: number): void;
  readonly fps: number;
  readonly tickRate: number;
  readonly totalTicks: number;
}

fps is the smoothed render frame rate. tickRate is the measured simulation tick rate. totalTicks is the total simulation ticks recorded since start.