@holtjs/stage 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,13 @@
1
- import { c as TweenManager, u as TweenStats } from "./tween-D3Ztppuz.js";
1
+ import { c as TweenManager, u as TweenStats } from "./tween-BiF1FUvc.js";
2
2
  declare const AUTO = 0;
3
3
  declare const CANVAS = 1;
4
4
  declare const WEBGL = 2;
5
+ declare const WEBGPU = 3;
5
6
  declare const BlendModes: {
6
7
  readonly NORMAL: 0;
7
8
  readonly ADD: 1;
9
+ readonly MULTIPLY: 2;
10
+ readonly SCREEN: 3;
8
11
  };
9
12
  type BlendMode = (typeof BlendModes)[keyof typeof BlendModes];
10
13
  declare const TintModes: {
@@ -185,6 +188,30 @@ declare class TextureManager {
185
188
  invalidateAllGl(): void;
186
189
  destroy(): void;
187
190
  }
191
+ interface CameraFollowOptions {
192
+ /** Horizontal smoothing factor in `(0, 1]` (`1` = instant lock; default `1`). */
193
+ lerpX?: number;
194
+ /** Vertical smoothing factor in `(0, 1]` (`1` = instant lock; default `1`). */
195
+ lerpY?: number;
196
+ /** World-space horizontal offset added to `target.x` (default `0`). */
197
+ offsetX?: number;
198
+ /** World-space vertical offset added to `target.y` (default `0`). */
199
+ offsetY?: number;
200
+ /** Optional centered deadzone width in world units (camera only scrolls when target exits deadzone). */
201
+ deadzoneWidth?: number;
202
+ /** Optional centered deadzone height in world units. */
203
+ deadzoneHeight?: number;
204
+ }
205
+ interface HiDpiScaleLike {
206
+ zoom: number;
207
+ resize(width: number, height: number): unknown;
208
+ canvas?: {
209
+ style?: {
210
+ width?: string;
211
+ height?: string;
212
+ };
213
+ } | null;
214
+ }
188
215
  declare class Camera {
189
216
  x: number;
190
217
  y: number;
@@ -206,6 +233,13 @@ declare class Camera {
206
233
  transparent: boolean;
207
234
  readonly worldView: WorldView2D;
208
235
  readonly matrixCombined: Matrix2D;
236
+ private followTarget;
237
+ private followLerpX;
238
+ private followLerpY;
239
+ private followOffsetX;
240
+ private followOffsetY;
241
+ private deadzoneW;
242
+ private deadzoneH;
209
243
  constructor(width: number, height: number, transparent?: boolean, backgroundColor?: string | number);
210
244
  get displayWidth(): number;
211
245
  get displayHeight(): number;
@@ -221,10 +255,40 @@ declare class Camera {
221
255
  clampX(sx: number): number;
222
256
  clampY(sy: number): number;
223
257
  centerOn(x: number, y: number): this;
258
+ /**
259
+ * One-line HiDPI camera + backing-buffer configurator: maps logical `(0, 0)..(viewportW, viewportH)`
260
+ * 1:1 onto crisp physical `viewportW * dpr` pixels without copy-pasting origin/scroll math.
261
+ * Returns the clamped `dpr` applied.
262
+ */
263
+ configureHiDpi(scale: HiDpiScaleLike, viewportWidth: number, viewportHeight: number, dpr?: number, maxDpr?: number): number;
264
+ /** Convert canvas/backing-buffer coordinates `(screenX, screenY)` into world coordinates. */
265
+ screenToWorld(screenX: number, screenY: number, out?: {
266
+ x: number;
267
+ y: number;
268
+ }): {
269
+ x: number;
270
+ y: number;
271
+ };
272
+ /** Convert world coordinates `(worldX, worldY)` into canvas/backing-buffer coordinates. */
273
+ worldToScreen(worldX: number, worldY: number, out?: {
274
+ x: number;
275
+ y: number;
276
+ }): {
277
+ x: number;
278
+ y: number;
279
+ };
280
+ /** Lock or smoothly follow any `{ x, y }` actor/point (frame-rate independent lerp + optional deadzone). */
281
+ startFollow(target: {
282
+ x: number;
283
+ y: number;
284
+ }, options?: CameraFollowOptions): this;
285
+ stopFollow(): this;
286
+ /** Internal per-step follow update invoked automatically by `Game.step()` before rendering. */
287
+ stepFollow(deltaMs: number): void;
224
288
  /** Recompute `worldView` and world->canvas `matrixCombined`. */
225
289
  syncMetrics(): void;
226
290
  }
227
- type DisplayObjectType = 'Image' | 'NineSlice' | 'TileSprite' | 'Rectangle' | 'Panel' | 'MsdfIcon' | 'Text' | 'Graphics' | 'Blitter' | 'Container' | 'CustomPass';
291
+ type DisplayObjectType = 'Image' | 'NineSlice' | 'TileSprite' | 'Rectangle' | 'Panel' | 'MsdfIcon' | 'Text' | 'Graphics' | 'Blitter' | 'InstancedBatch' | 'Container' | 'CustomPass';
228
292
  type SceneHostLike = Scene;
229
293
  declare class DisplayList {
230
294
  readonly list: DisplayObject[];
@@ -681,10 +745,55 @@ declare class Container extends DisplayObject {
681
745
  enableFilters(): this;
682
746
  destroy(destroyChildren?: boolean): void;
683
747
  }
684
- type CustomPassCallback = (node: CustomPassObject, renderer: any, camera: Camera) => void;
748
+ type CustomPassCallback = (node: CustomPassObject, renderer: StageRenderer, camera: Camera) => void;
749
+ interface CustomPassOptions {
750
+ /** Automatically restore WebGL program/VAO/texture/blend caches after `onRender` (default `true`). */
751
+ restoreState?: boolean;
752
+ }
685
753
  declare class CustomPassObject extends DisplayObject {
686
754
  readonly onRender: CustomPassCallback;
687
- constructor(scene: SceneHostLike, onRender: CustomPassCallback);
755
+ restoreState: boolean;
756
+ constructor(scene: SceneHostLike, onRender: CustomPassCallback, options?: CustomPassOptions);
757
+ }
758
+ interface InstancedColumns {
759
+ /** Active instance count to draw (`0 .. capacity`). */
760
+ count: number;
761
+ /** World X positions (`Float32Array`). */
762
+ x: Float32Array;
763
+ /** World Y positions (`Float32Array`). */
764
+ y: Float32Array;
765
+ /** Optional uniform or X scale per instance (`Float32Array`; defaults to `1`). */
766
+ scaleX?: Float32Array | null;
767
+ /** Optional Y scale per instance (`Float32Array`; defaults to `scaleX` or `1`). */
768
+ scaleY?: Float32Array | null;
769
+ /** Optional rotation in radians per instance (`Float32Array`; defaults to `0`). */
770
+ rotation?: Float32Array | null;
771
+ /** Optional alpha `[0..1]` per instance (`Float32Array`; defaults to `1`). */
772
+ alpha?: Float32Array | null;
773
+ /** Optional `0xRRGGBB` multiply tint per instance (`Uint32Array`; defaults to `0xffffff`). */
774
+ tint?: Uint32Array | null;
775
+ /** Optional sprite-sheet frame index per instance (`Int32Array | Uint16Array`; defaults to `defaultFrame`). */
776
+ frameIndex?: Int32Array | Uint16Array | null;
777
+ /** Optional draw-order indirection indices (e.g. from `sortSlotsByDepth` / `partitionDepthBands`). */
778
+ order?: Int32Array | null;
779
+ }
780
+ /**
781
+ * High-throughput SoA instanced sprite/quad batch (`scene.add.instancedBatch(key, maxCount)`).
782
+ * Consumes `SoaWorld` `Float32Array` columns directly: renders via hardware `drawElementsInstanced`
783
+ * in WebGL2, instanced storage/vertex buffer in WebGPU, and zero-alloc loop in Canvas2D / Headless Node.
784
+ */
785
+ declare class InstancedBatchObject extends DisplayObject {
786
+ texture: Texture;
787
+ defaultFrame: Frame;
788
+ maxCount: number;
789
+ columns: InstancedColumns | null;
790
+ /** Renderer-owned GPU instance buffer cache (opaque to user code). */
791
+ _gpuCache: any;
792
+ constructor(scene: SceneHostLike, key: string, maxCount?: number, frame?: string | number);
793
+ setTexture(key: string, frame?: string | number): this;
794
+ /** Bind or update the SoA column views read on each render pass (zero copying on caller side). */
795
+ setColumns(columns: InstancedColumns): this;
796
+ destroy(fromScene?: boolean): void;
688
797
  }
689
798
  interface RendererGlOptions {
690
799
  transparent?: boolean;
@@ -712,6 +821,13 @@ interface Stage2DCustomImageHandler {
712
821
  renderStage2DImage(renderer: RendererGl, img: ImageObject, camera: Camera, mat: Matrix2D, alpha: number): void;
713
822
  flushStage2D?(renderer: RendererGl): void;
714
823
  }
824
+ interface StageRenderTarget {
825
+ readonly key: string;
826
+ readonly width: number;
827
+ readonly height: number;
828
+ readonly texture: Texture;
829
+ destroy(): void;
830
+ }
715
831
  declare class RendererGl extends EventEmitter implements GlTextureHost {
716
832
  readonly type = 2;
717
833
  readonly canvas: HTMLCanvasElement;
@@ -785,6 +901,14 @@ declare class RendererGl extends EventEmitter implements GlTextureHost {
785
901
  private readonly sfMat;
786
902
  private readonly maskWorldMat;
787
903
  private readonly bindTextSlot0;
904
+ private instProgram;
905
+ private instUres;
906
+ private instVao;
907
+ private instCornerVbo;
908
+ private instDataVbo;
909
+ private instStagingBuf;
910
+ private instF32;
911
+ private instU32;
788
912
  private readonly onLostDom;
789
913
  private readonly onRestoredDom;
790
914
  constructor(canvas: HTMLCanvasElement, width: number, height: number, opts?: RendererGlOptions);
@@ -836,6 +960,12 @@ declare class RendererGl extends EventEmitter implements GlTextureHost {
836
960
  private renderGraphics;
837
961
  private renderPanel;
838
962
  private renderMsdfIcon;
963
+ private ensureInstancedResources;
964
+ private renderInstancedBatch;
965
+ /** Create an offscreen WebGL framebuffer target backed by a registered Stage `Texture` (`key`). */
966
+ createRenderTarget(key: string, width: number, height: number, textures: TextureManager, filterMode?: 0 | 1): StageRenderTarget;
967
+ /** Render a `DisplayList` (or custom pass callback) into an offscreen `StageRenderTarget` FBO. */
968
+ renderToTarget(target: StageRenderTarget, content: DisplayList | ((renderer: RendererGl, camera: Camera) => void), camera: Camera): void;
839
969
  private renderBlitter;
840
970
  private renderNode;
841
971
  render(displayList: DisplayList, camera: Camera): void;
@@ -880,11 +1010,137 @@ declare class Renderer2D extends EventEmitter {
880
1010
  private renderMsdfIcon;
881
1011
  private renderText;
882
1012
  private renderGraphics;
1013
+ private renderInstancedBatch;
1014
+ /** Create an offscreen Canvas2D render target backed by a registered Stage `Texture` (`key`). */
1015
+ createRenderTarget(key: string, width: number, height: number, textures: TextureManager, filterMode?: 0 | 1): StageRenderTarget;
1016
+ /** Render a `DisplayList` (or callback) into an offscreen `StageRenderTarget` in Canvas2D / Headless Node. */
1017
+ renderToTarget(target: StageRenderTarget, content: DisplayList | ((renderer: Renderer2D, camera: Camera) => void), camera: Camera): void;
883
1018
  private renderBlitter;
884
1019
  private renderNode;
885
1020
  render(displayList: DisplayList, camera: Camera): void;
886
1021
  destroy(): void;
887
1022
  }
1023
+ interface WebGpuDeviceLike {
1024
+ readonly queue: {
1025
+ writeBuffer(buffer: any, bufferOffset: number, data: BufferSource, dataOffset?: number, size?: number): void;
1026
+ copyExternalImageToTexture(source: any, destination: any, copySize: any): void;
1027
+ submit(commandBuffers: any[]): void;
1028
+ };
1029
+ createShaderModule(descriptor: {
1030
+ code: string;
1031
+ }): any;
1032
+ createBuffer(descriptor: {
1033
+ size: number;
1034
+ usage: number;
1035
+ mappedAtCreation?: boolean;
1036
+ }): any;
1037
+ createTexture(descriptor: any): any;
1038
+ createSampler(descriptor?: any): any;
1039
+ createBindGroupLayout(descriptor: any): any;
1040
+ createPipelineLayout(descriptor: any): any;
1041
+ createRenderPipeline(descriptor: any): any;
1042
+ createBindGroup(descriptor: any): any;
1043
+ createCommandEncoder(descriptor?: any): any;
1044
+ destroy?(): void;
1045
+ }
1046
+ interface WebGpuCanvasContextLike {
1047
+ configure(config: {
1048
+ device: WebGpuDeviceLike;
1049
+ format: string;
1050
+ alphaMode?: 'opaque' | 'premultiplied';
1051
+ }): void;
1052
+ getCurrentTexture(): {
1053
+ createView(): any;
1054
+ };
1055
+ }
1056
+ interface RendererWebGpuOptions {
1057
+ device: WebGpuDeviceLike;
1058
+ context?: WebGpuCanvasContextLike | null;
1059
+ format?: string;
1060
+ transparent?: boolean;
1061
+ }
1062
+ interface RequestWebGpuOptions {
1063
+ powerPreference?: 'low-power' | 'high-performance';
1064
+ transparent?: boolean;
1065
+ }
1066
+ interface WebGpuBootstrapResult {
1067
+ readonly device: WebGpuDeviceLike;
1068
+ readonly context: WebGpuCanvasContextLike;
1069
+ readonly format: string;
1070
+ }
1071
+ /**
1072
+ * Asynchronously acquire a browser `GPUDevice` + configured `GPUCanvasContext` ready to pass directly into
1073
+ * `new Game({ type: WEBGPU, gpuDevice: gpu.device, gpuContext: gpu.context, gpuFormat: gpu.format })`.
1074
+ * Returns `null` cleanly when WebGPU is unsupported on the current browser/OS.
1075
+ */
1076
+ declare function requestWebGpuDevice(canvas: HTMLCanvasElement, options?: RequestWebGpuOptions): Promise<WebGpuBootstrapResult | null>;
1077
+ declare class RendererWebGpu extends EventEmitter {
1078
+ readonly type = 3;
1079
+ readonly isWebGL2 = false;
1080
+ readonly isWebGPU = true;
1081
+ readonly gl: null;
1082
+ readonly contextLost = false;
1083
+ readonly maxTextures = 16;
1084
+ readonly canvas: HTMLCanvasElement;
1085
+ readonly device: WebGpuDeviceLike;
1086
+ readonly gpuContext: WebGpuCanvasContextLike;
1087
+ readonly format: string;
1088
+ width: number;
1089
+ height: number;
1090
+ private readonly globalsBuf;
1091
+ private readonly vbo;
1092
+ private readonly ibo;
1093
+ private readonly sdfCornerVbo;
1094
+ private readonly sdfInstVbo;
1095
+ private readonly sdfQuadIbo;
1096
+ private readonly samplerLinear;
1097
+ private readonly samplerNearest;
1098
+ private readonly batchBgl;
1099
+ private readonly sdfBgl;
1100
+ private readonly sdfBindGroup;
1101
+ private readonly batchPipelines;
1102
+ private readonly sdfPipelines;
1103
+ private readonly texCache;
1104
+ private dummyEntry;
1105
+ private readonly vertRaw;
1106
+ private readonly f32;
1107
+ private readonly u32;
1108
+ private readonly indices;
1109
+ private readonly sdfRaw;
1110
+ private readonly sdfF32;
1111
+ private readonly sdfU32;
1112
+ private vertCount;
1113
+ private indexCount;
1114
+ private cmdStartIndex;
1115
+ private sdfCount;
1116
+ private sdfCmdStart;
1117
+ private curBlend;
1118
+ private curBindGroup;
1119
+ private readonly cmds;
1120
+ private readonly scissorStack;
1121
+ private readonly matPool;
1122
+ private readonly sfMat;
1123
+ private readonly maskWorldMat;
1124
+ private lastStats;
1125
+ constructor(canvas: HTMLCanvasElement, width: number, height: number, opts: RendererWebGpuOptions);
1126
+ private makeBatchBindGroup;
1127
+ stats(): RendererStats;
1128
+ resize(width: number, height: number): void;
1129
+ private ensureGpuTexture;
1130
+ private ensureSourceBindGroup;
1131
+ private currentScissor;
1132
+ private flushPendingBatch;
1133
+ private flushPendingSdf;
1134
+ private flushAllPending;
1135
+ private bindBatch;
1136
+ private pushQuad;
1137
+ private pushTri;
1138
+ private renderPanel;
1139
+ private renderGraphics;
1140
+ private renderNode;
1141
+ render(displayList: DisplayList, camera: Camera): void;
1142
+ destroy(): void;
1143
+ }
888
1144
  interface PointerSample {
889
1145
  x: number;
890
1146
  y: number;
@@ -931,9 +1187,24 @@ declare class Pointer {
931
1187
  }
932
1188
  declare class KeyboardPlugin extends EventEmitter {
933
1189
  private readonly win;
1190
+ private readonly getFrameSeq;
1191
+ private readonly downCodes;
1192
+ private readonly pressedFrame;
1193
+ private readonly releasedFrame;
934
1194
  private readonly onKeyDown;
935
1195
  private readonly onKeyUp;
936
- constructor(win: Window);
1196
+ private readonly onBlur;
1197
+ constructor(win: Window, getFrameSeq?: () => number);
1198
+ /** Returns `true` while `codeOrKey` (e.g. `'KeyW'`, `'W'`, `'ArrowLeft'`, `'Space'`) is held down. */
1199
+ isDown(codeOrKey: string): boolean;
1200
+ /** Returns `true` only on the simulation frame during which `codeOrKey` transitioned up -> down. */
1201
+ justPressed(codeOrKey: string): boolean;
1202
+ /** Returns `true` only on the simulation frame during which `codeOrKey` transitioned down -> up. */
1203
+ justReleased(codeOrKey: string): boolean;
1204
+ /** Synthesize a deterministic key event from an `InputProvider` (headless timeline, replay, or Mod controller). */
1205
+ injectKey(type: 'keydown' | 'keyup', codeOrKey: string, key?: string): void;
1206
+ /** Release all currently held keys (called automatically on window blur). */
1207
+ resetKeys(): void;
937
1208
  destroy(): void;
938
1209
  }
939
1210
  declare class InputPlugin extends EventEmitter {
@@ -954,11 +1225,322 @@ declare class InputPlugin extends EventEmitter {
954
1225
  private readonly coalescedScratch;
955
1226
  private resizeObserver;
956
1227
  private lastTouchMs;
957
- constructor(canvas: HTMLCanvasElement, win: Window, getCamera: () => Camera | null, config?: InputConfig);
1228
+ constructor(canvas: HTMLCanvasElement, win: Window, getCamera: () => Camera | null, config?: InputConfig, getFrameSeq?: () => number);
958
1229
  setPollAlways(): this;
959
1230
  destroy(): void;
960
1231
  }
961
- type StageRenderer = RendererGl | Renderer2D;
1232
+ interface SceneDigestNode {
1233
+ trackId: string | null;
1234
+ role: string | null;
1235
+ alt: string | null;
1236
+ surface: string | null;
1237
+ type: string;
1238
+ visible: boolean;
1239
+ enabled: boolean;
1240
+ zIndex: number;
1241
+ depth: number;
1242
+ alpha: number;
1243
+ bounds: [number, number, number, number];
1244
+ }
1245
+ interface SceneDigestOverlayStats {
1246
+ popovers: number;
1247
+ dropdowns: number;
1248
+ tooltipVisible: boolean;
1249
+ toasts: number;
1250
+ queuedToasts: number;
1251
+ }
1252
+ interface SceneDigestSurfaceEntry {
1253
+ id: string;
1254
+ priority: number;
1255
+ seq: number;
1256
+ scope: string;
1257
+ barrier: string;
1258
+ parent: string | null;
1259
+ }
1260
+ interface SceneDigestActiveFocus {
1261
+ tag: string;
1262
+ ui: string | null;
1263
+ role: string | null;
1264
+ }
1265
+ interface SceneDigestSurfaces {
1266
+ active: SceneDigestSurfaceEntry[];
1267
+ topBarrier: SceneDigestSurfaceEntry | null;
1268
+ worldBlocked: boolean;
1269
+ domZ: Record<string, number> | null;
1270
+ activeFocus: SceneDigestActiveFocus | null;
1271
+ }
1272
+ interface SceneDigestEngineSandbox {
1273
+ modId: string;
1274
+ ready: boolean;
1275
+ uptimeMs: number;
1276
+ renderer: string | null;
1277
+ apps: number;
1278
+ frames: number;
1279
+ longFrames: number;
1280
+ drawCalls: number;
1281
+ texBinds: number;
1282
+ errors: number;
1283
+ violations: number;
1284
+ lastHeartbeatMs: number | null;
1285
+ }
1286
+ interface SceneDigestSandbox {
1287
+ engine: SceneDigestEngineSandbox | null;
1288
+ mountedWorkers: number;
1289
+ }
1290
+ interface SceneDigest {
1291
+ clock: EngineClockSnapshot | null;
1292
+ traceId: string | null;
1293
+ viewport: {
1294
+ w: number;
1295
+ h: number;
1296
+ dpr: number;
1297
+ };
1298
+ renderer: {
1299
+ type: string;
1300
+ drawCalls?: number;
1301
+ flushes?: number;
1302
+ tris?: number;
1303
+ culled?: number;
1304
+ texBinds?: number;
1305
+ sdfPanels?: number;
1306
+ sdfDraws?: number;
1307
+ msdfIcons?: number;
1308
+ msdfDraws?: number;
1309
+ pixelAaIcons?: number;
1310
+ pixelAaDraws?: number;
1311
+ };
1312
+ lifecycle: SceneLifecycleStats | null;
1313
+ tweens: TweenStats | null;
1314
+ overlays: SceneDigestOverlayStats | null;
1315
+ surfaces: SceneDigestSurfaces | null;
1316
+ sandbox: SceneDigestSandbox | null;
1317
+ plugins: Record<string, Record<string, number | string | boolean | null>> | null;
1318
+ displayListCount: number;
1319
+ uiCount: number;
1320
+ truncated: boolean;
1321
+ nodes: SceneDigestNode[];
1322
+ }
1323
+ interface SceneDigestSurfaceSource {
1324
+ active?: () => ReadonlyArray<{
1325
+ id: string;
1326
+ priority: number;
1327
+ seq: number;
1328
+ scope: string;
1329
+ barrier: string;
1330
+ parent: string | null;
1331
+ }>;
1332
+ topBarrier?: () => {
1333
+ id: string;
1334
+ priority: number;
1335
+ seq: number;
1336
+ scope: string;
1337
+ barrier: string;
1338
+ parent: string | null;
1339
+ } | null;
1340
+ isWorldBlocked?: () => boolean;
1341
+ domZ?: () => Record<string, number>;
1342
+ activeFocus?: () => SceneDigestActiveFocus | null;
1343
+ }
1344
+ interface SceneDigestOptions {
1345
+ ui?: {
1346
+ view?: {
1347
+ w: number;
1348
+ h: number;
1349
+ };
1350
+ dpr?: number;
1351
+ registry?: {
1352
+ api?: {
1353
+ list?: () => Array<Record<string, any>>;
1354
+ };
1355
+ };
1356
+ __overlays?: {
1357
+ stats?: () => SceneDigestOverlayStats;
1358
+ } | null;
1359
+ } | null;
1360
+ surfaces?: SceneDigestSurfaceSource | null;
1361
+ sandbox?: SceneDigestSandbox | (() => SceneDigestSandbox | null) | null;
1362
+ traceId?: string | null;
1363
+ dpr?: number;
1364
+ maxNodes?: number;
1365
+ }
1366
+ /** Sanitize a privacy-safe semantic identifier (`trackId`, `role`, `surface`). Returns null if invalid or empty. */
1367
+ declare function sanitizeTrackToken(raw: unknown, maxLen?: number): string | null;
1368
+ /**
1369
+ * Build a privacy-safe structural snapshot of a Stage2D scene and optional UiRoot.
1370
+ * Never reads arbitrary `TextObject.text` or user-typed strings; only emits sanitized `trackId`/`role`/`surface`
1371
+ * tokens and explicitly declared semantic `alt` labels.
1372
+ */
1373
+ declare function buildSceneDigest(scene: Scene, opts?: SceneDigestOptions): SceneDigest;
1374
+ type StageInputEvent = {
1375
+ readonly kind: 'pointerdown' | 'pointermove' | 'pointerup';
1376
+ readonly x: number;
1377
+ readonly y: number;
1378
+ readonly button?: number;
1379
+ readonly source?: string;
1380
+ } | {
1381
+ readonly kind: 'wheel';
1382
+ readonly x: number;
1383
+ readonly y: number;
1384
+ readonly deltaX: number;
1385
+ readonly deltaY: number;
1386
+ readonly deltaZ?: number;
1387
+ readonly source?: string;
1388
+ } | {
1389
+ readonly kind: 'keydown' | 'keyup';
1390
+ readonly code: string;
1391
+ readonly key?: string;
1392
+ readonly source?: string;
1393
+ };
1394
+ /**
1395
+ * Pluggable input source feeding `StageKernel` — physical DOM mouse/keyboard/touch,
1396
+ * headless `InputTimeline` choreography, frame-exact `InputReplay`, or sandboxed Mod controllers
1397
+ * all share this exact contract.
1398
+ */
1399
+ interface InputProvider {
1400
+ readonly id: string;
1401
+ attach?(kernel: StageKernel): void | (() => void);
1402
+ poll?(kernel: StageKernel, simTimeMs: number, deltaMs: number): void;
1403
+ dispose?(): void;
1404
+ }
1405
+ /**
1406
+ * Composable kernel extension contract (`game.kernel.use(plugin)`).
1407
+ * Plugins participate in deterministic simulation ticks, post-render hooks, LIFO disposal,
1408
+ * and automatically contribute sanitized telemetry to `buildSceneDigest()`.
1409
+ */
1410
+ interface StagePlugin {
1411
+ readonly id: string;
1412
+ setup?(kernel: StageKernel): void | (() => void);
1413
+ prestep?(timeMs: number, deltaMs: number): void;
1414
+ update?(scene: Scene, timeMs: number, deltaMs: number): void;
1415
+ postrender?(renderer: StageRenderer): void;
1416
+ /** Optional privacy-safe key/value metrics merged into `SceneDigest.plugins[id]`. */
1417
+ digest?(): Record<string, number | string | boolean | null>;
1418
+ dispose?(): void;
1419
+ }
1420
+ /** Godot-inspired semantic action map binding logical game verbs (`'jump'`, `'interact'`) to key codes. */
1421
+ declare class ActionMap {
1422
+ private readonly bindings;
1423
+ private readonly game;
1424
+ constructor(game: Game);
1425
+ bind(action: string, codes: readonly string[]): this;
1426
+ unbind(action: string): this;
1427
+ codesFor(action: string): readonly string[];
1428
+ isDown(action: string): boolean;
1429
+ justPressed(action: string): boolean;
1430
+ justReleased(action: string): boolean;
1431
+ /** Compute signed `[-1, 0, +1]` axis from negative/positive action names or key codes. */
1432
+ axis(negativeActionOrCode: string, positiveActionOrCode: string): number;
1433
+ }
1434
+ declare class StageKernel {
1435
+ readonly game: Game;
1436
+ readonly actions: ActionMap;
1437
+ private readonly plugins;
1438
+ private readonly pluginOrder;
1439
+ private readonly providers;
1440
+ private readonly providerOrder;
1441
+ private readonly inputListeners;
1442
+ private inputGuard;
1443
+ private disposed;
1444
+ constructor(game: Game);
1445
+ /** Optional input barrier predicate (e.g. `() => !surfaces.isWorldBlocked()`). */
1446
+ setInputGuard(guard: ((ev: StageInputEvent) => boolean) | null): this;
1447
+ /** Subscribe to every normalized `StageInputEvent` flowing through the kernel (used by recorders/mods). */
1448
+ onInput(listener: (ev: StageInputEvent, frameSeq: number, simTimeMs: number) => void): () => void;
1449
+ /** Mount a `StagePlugin` (idempotent per `plugin.id`; LIFO-disposed on `remove` or `game.destroy()`). */
1450
+ use<T extends StagePlugin>(plugin: T): T;
1451
+ getPlugin<T extends StagePlugin = StagePlugin>(id: string): T | null;
1452
+ removePlugin(id: string): boolean;
1453
+ /** Register an `InputProvider` (DOM, headless timeline, replay, or Mod controller). */
1454
+ addInputProvider<T extends InputProvider>(provider: T): T;
1455
+ removeInputProvider(id: string): boolean;
1456
+ /** Dispatch a normalized input event into `Game.input` + `KeyboardPlugin` and notify listeners. */
1457
+ dispatchInput(event: StageInputEvent): boolean;
1458
+ /** Internal per-tick prestep invoked by `Game.step()` / `Game.stepSimOnly()`. */
1459
+ _prestep(timeMs: number, deltaMs: number): void;
1460
+ /** Internal per-scene update hook invoked by `Game.step()` / `Game.stepSimOnly()`. */
1461
+ _updateScene(scene: Scene, timeMs: number, deltaMs: number): void;
1462
+ /** Internal postrender hook invoked by `Game.step()`. */
1463
+ _postrender(renderer: StageRenderer): void;
1464
+ /** Collect sanitized plugin digests for `buildSceneDigest()`. */
1465
+ collectPluginDigests(): Record<string, Record<string, number | string | boolean | null>> | null;
1466
+ /** LIFO teardown of all mounted input providers and plugins. */
1467
+ dispose(): void;
1468
+ }
1469
+ type InputTargetSpec = string | {
1470
+ readonly x: number;
1471
+ readonly y: number;
1472
+ };
1473
+ interface TimelineClickOptions {
1474
+ readonly atMs: number;
1475
+ /** Duration in ms to smoothly glide virtual cursor before pressing (default `180`). */
1476
+ readonly moveDurationMs?: number;
1477
+ /** Hold duration in ms between pointerdown and pointerup (default `50`). */
1478
+ readonly holdMs?: number;
1479
+ readonly button?: number;
1480
+ }
1481
+ interface TimelineDragOptions {
1482
+ readonly from: InputTargetSpec;
1483
+ readonly to: InputTargetSpec;
1484
+ readonly atMs: number;
1485
+ readonly durationMs?: number;
1486
+ readonly button?: number;
1487
+ }
1488
+ interface TimelineKeyOptions {
1489
+ readonly atMs: number;
1490
+ readonly durationMs?: number;
1491
+ }
1492
+ interface InputTimelineOptions {
1493
+ readonly id?: string;
1494
+ /** Render a crisp virtual cursor & click ripple overlay on the active scene (default `false`). */
1495
+ readonly showCursor?: boolean;
1496
+ /** Initial cursor X position (default `64`). */
1497
+ readonly initialX?: number;
1498
+ /** Initial cursor Y position (default `64`). */
1499
+ readonly initialY?: number;
1500
+ /** Optional `SceneDigestOptions` used when resolving `trackId` targets. */
1501
+ readonly digestOptions?: SceneDigestOptions;
1502
+ /** Optional callback fired on every click/keypress (`simTimeMs`, `kind`) — handy for auto-scheduling SFX on `AudioTimeline`! */
1503
+ readonly onCue?: (simTimeMs: number, kind: 'click' | 'key', detail: string) => void;
1504
+ }
1505
+ interface InputTimelinePlugin extends StagePlugin, InputProvider {
1506
+ readonly cursor: {
1507
+ x: number;
1508
+ y: number;
1509
+ isDown: boolean;
1510
+ };
1511
+ moveTo(target: InputTargetSpec, options: {
1512
+ atMs: number;
1513
+ durationMs?: number;
1514
+ }): this;
1515
+ click(target: InputTargetSpec, options: TimelineClickOptions): this;
1516
+ drag(options: TimelineDragOptions): this;
1517
+ pressKey(code: string, options: TimelineKeyOptions): this;
1518
+ typeText(text: string, options: {
1519
+ atMs: number;
1520
+ intervalMs?: number;
1521
+ }): this;
1522
+ }
1523
+ /**
1524
+ * Programmable input choreography plugin & `InputProvider` for AI agents, automated gameplay tests,
1525
+ * and 60 FPS product demo videos. Supports clicking directly by `trackId` (`timeline.click('shop.buy', { atMs: 400 })`)
1526
+ * via `buildSceneDigest()` as well as coordinates, drags, key holds, typing, and optional visual cursor ripples!
1527
+ */
1528
+ declare function createInputTimeline(options?: InputTimelineOptions): InputTimelinePlugin;
1529
+ interface RecordedInputEntry {
1530
+ readonly frameSeq: number;
1531
+ readonly simTimeMs: number;
1532
+ readonly event: StageInputEvent;
1533
+ }
1534
+ interface InputRecorderPlugin extends StagePlugin {
1535
+ readonly entries: ReadonlyArray<RecordedInputEntry>;
1536
+ clear(): void;
1537
+ toJSON(): RecordedInputEntry[];
1538
+ }
1539
+ /** Records frame-stamped `StageInputEvent`s for deterministic headless replay or bug repro bundles. */
1540
+ declare function createInputRecorder(id?: string): InputRecorderPlugin;
1541
+ /** Replays a recorded `RecordedInputEntry[]` log deterministically on matching simulation timestamps. */
1542
+ declare function createInputReplay(log: ReadonlyArray<RecordedInputEntry>, id?: string): StagePlugin & InputProvider;
1543
+ type StageRenderer = RendererGl | Renderer2D | RendererWebGpu;
962
1544
  interface EngineClockSnapshot {
963
1545
  readonly frameSeq: number;
964
1546
  readonly simTimeMs: number;
@@ -987,6 +1569,14 @@ interface GameConfig {
987
1569
  parent?: HTMLElement | string | null;
988
1570
  canvas?: HTMLCanvasElement;
989
1571
  context?: WebGL2RenderingContext | WebGLRenderingContext | CanvasRenderingContext2D | null;
1572
+ /** Pre-acquired WebGPU `GPUDevice` (from `await requestWebGpuDevice(canvas)`) when `type === WEBGPU`. */
1573
+ gpuDevice?: WebGpuDeviceLike | null;
1574
+ /** Optional pre-configured `GPUCanvasContext` when `type === WEBGPU`. */
1575
+ gpuContext?: WebGpuCanvasContextLike | null;
1576
+ /** Preferred WebGPU swapchain texture format (default `'bgra8unorm'`). */
1577
+ gpuFormat?: string;
1578
+ /** Kernel plugins mounted synchronously at boot (`StagePlugin[]`). */
1579
+ plugins?: StagePlugin[];
990
1580
  canvasStyle?: string;
991
1581
  width?: number;
992
1582
  height?: number;
@@ -1063,8 +1653,9 @@ declare class GameObjectFactory {
1063
1653
  add?: boolean;
1064
1654
  }): Graphics;
1065
1655
  blitter(x: number, y: number, key: string): BlitterObject;
1656
+ instancedBatch(key: string, maxCount?: number, frame?: string | number): InstancedBatchObject;
1066
1657
  container(x?: number, y?: number, children?: DisplayObject[]): Container;
1067
- customPass(onRender: CustomPassCallback): CustomPassObject;
1658
+ customPass(onRender: CustomPassCallback, options?: CustomPassOptions): CustomPassObject;
1068
1659
  }
1069
1660
  declare class ScaleManager extends EventEmitter {
1070
1661
  readonly canvas: HTMLCanvasElement;
@@ -1190,6 +1781,7 @@ declare class Game {
1190
1781
  };
1191
1782
  readonly events: EventEmitter;
1192
1783
  readonly clock: EngineClock;
1784
+ readonly kernel: StageKernel;
1193
1785
  readonly scene: SceneManager;
1194
1786
  readonly loop: GameLoop;
1195
1787
  readonly transparent: boolean;
@@ -1199,7 +1791,9 @@ declare class Game {
1199
1791
  private destroyed;
1200
1792
  private ownedCanvas;
1201
1793
  constructor(config?: GameConfig);
1794
+ /** Advance simulation, tweens, kernel plugins, and camera follow by one deterministic tick WITHOUT rendering pixels. */
1795
+ stepSimOnly(time: number, delta: number): boolean;
1202
1796
  step(time: number, delta: number): void;
1203
1797
  destroy(removeCanvas?: boolean): void;
1204
1798
  }
1205
- export { GlTextureHost as $, CustomPassCallback as A, NineSliceObject as B, RendererGlOptions as C, WHITE_RGB as Ct, Bob as D, parseColor as Dt, BlitterObject as E, packColorAbgr as Et, DisplaySemantics as F, RectangleObject as G, PanelOpenSide as H, Graphics as I, TextStyleConfig as J, SceneHostLike as K, ImageObject as L, DisplayList as M, DisplayObject as N, Container as O, rgbToCss as Ot, DisplayObjectType as P, Frame as Q, MsdfIconConfig as R, RendererGl as S, WEBGL as St, Stage2DCustomImageHandler as T, createMatrix2D as Tt, PanelStyleConfig as U, PanelObject as V, RectClipMask as W, Camera as X, TileSpriteObject as Y, CanvasTexture as Z, InputPlugin as _, RgbaColor as _t, GameLoop as a, TextureSource as at, PointerSample as b, TintMode as bt, LoaderPlugin as c, BlendMode as ct, SceneCtor as d, EventEmitter as dt, SpriteSheetConfig as et, SceneInput as f, FilterMode as ft, InputConfig as g, Rect2D as gt, StageRenderer as h, Matrix2D as ht, GameConfig as i, TextureManager as it, CustomPassObject as j, ContainerFiltersShim as k, ScaleManager as l, BlendModes as lt, SceneManager as m, HEX_MASK as mt, EngineClockSnapshot as n, TextureImageOptions as nt, GameObjectFactory as o, AUTO as ot, SceneLifecycleStats as p, FilterModeValue as pt, TextObject as q, Game as r, TextureImageSource as rt, JsonCache as s, BLACK_RGB as st, EngineClock as t, Texture as tt, Scene as u, CANVAS as ut, KeyboardPlugin as v, Scale as vt, RendererStats as w, WorldView2D as wt, Renderer2D as x, TintModes as xt, Pointer as y, Scenes as yt, MsdfIconObject as z };
1799
+ export { WebGpuCanvasContextLike as $, FilterMode as $t, createInputReplay as A, RectangleObject as At, SceneDigestSurfaceSource as B, GlTextureHost as Bt, StageInputEvent as C, MsdfIconConfig as Ct, TimelineDragOptions as D, PanelOpenSide as Dt, TimelineClickOptions as E, PanelObject as Et, SceneDigestNode as F, Camera as Ft, InputPlugin as G, TextureManager as Gt, buildSceneDigest as H, Texture as Ht, SceneDigestOptions as I, CameraFollowOptions as It, PointerSample as J, BLACK_RGB as Jt, KeyboardPlugin as K, TextureSource as Kt, SceneDigestOverlayStats as L, HiDpiScaleLike as Lt, SceneDigest as M, TextObject as Mt, SceneDigestActiveFocus as N, TextStyleConfig as Nt, TimelineKeyOptions as O, PanelStyleConfig as Ot, SceneDigestEngineSandbox as P, TileSpriteObject as Pt, WebGpuBootstrapResult as Q, EventEmitter as Qt, SceneDigestSandbox as R, CanvasTexture as Rt, RecordedInputEntry as S, InstancedColumns as St, StagePlugin as T, NineSliceObject as Tt, sanitizeTrackToken as U, TextureImageOptions as Ut, SceneDigestSurfaces as V, SpriteSheetConfig as Vt, InputConfig as W, TextureImageSource as Wt, RendererWebGpuOptions as X, BlendModes as Xt, RendererWebGpu as Y, BlendMode as Yt, RequestWebGpuOptions as Z, CANVAS as Zt, InputProvider as _, DisplayObjectType as _t, GameLoop as a, Scale as an, RendererStats as at, InputTimelineOptions as b, ImageObject as bt, LoaderPlugin as c, TintModes as cn, BlitterObject as ct, SceneCtor as d, WHITE_RGB as dn, ContainerFiltersShim as dt, FilterModeValue as en, WebGpuDeviceLike as et, SceneInput as f, WorldView2D as fn, CustomPassCallback as ft, ActionMap as g, rgbToCss as gn, DisplayObject as gt, StageRenderer as h, parseColor as hn, DisplayList as ht, GameConfig as i, RgbaColor as in, RendererGlOptions as it, createInputTimeline as j, SceneHostLike as jt, createInputRecorder as k, RectClipMask as kt, ScaleManager as l, WEBGL as ln, Bob as lt, SceneManager as m, packColorAbgr as mn, CustomPassOptions as mt, EngineClockSnapshot as n, Matrix2D as nn, Renderer2D as nt, GameObjectFactory as o, Scenes as on, Stage2DCustomImageHandler as ot, SceneLifecycleStats as p, createMatrix2D as pn, CustomPassObject as pt, Pointer as q, AUTO as qt, Game as r, Rect2D as rn, RendererGl as rt, JsonCache as s, TintMode as sn, StageRenderTarget as st, EngineClock as t, HEX_MASK as tn, requestWebGpuDevice as tt, Scene as u, WEBGPU as un, Container as ut, InputRecorderPlugin as v, DisplaySemantics as vt, StageKernel as w, MsdfIconObject as wt, InputTimelinePlugin as x, InstancedBatchObject as xt, InputTargetSpec as y, Graphics as yt, SceneDigestSurfaceEntry as z, Frame as zt };