@holtjs/stage 0.12.0 → 0.14.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,4 +1,4 @@
1
- import { $t as OpenWgpuNativeFfiOptions, E as StagePlugin, Qt as OpenDawnWebGpuOptions, Tt as SceneDigest, Xt as HeadlessWebGpuHandle, Yt as HeadlessWebGpuBackend, Zt as HeadlessWebGpuOptions, en as openDawnWebGpu, f as SceneInput, kt as SceneDigestOptions, n as EngineClockSnapshot, nn as requestHeadlessWebGpu, qt as WebGpuDeviceLike, r as Game, tn as openWgpuNativeFfi, u as Scene } from "./game-CT_WCPjJ.js";
1
+ import { $t as OpenWgpuNativeFfiOptions, E as StagePlugin, Qt as OpenDawnWebGpuOptions, Tt as SceneDigest, Xt as HeadlessWebGpuHandle, Yt as HeadlessWebGpuBackend, Zt as HeadlessWebGpuOptions, en as openDawnWebGpu, f as SceneInput, kt as SceneDigestOptions, n as EngineClockSnapshot, nn as requestHeadlessWebGpu, qt as WebGpuDeviceLike, r as Game, tn as openWgpuNativeFfi, u as Scene } from "./game-rKghsNlA.js";
2
2
  /** Minimal Canvas2D surface compatible with `@napi-rs/canvas`, `node-canvas`, and browser `<canvas>`. */
3
3
  export interface HeadlessCanvasLike {
4
4
  width: number;
@@ -7,9 +7,13 @@ export interface HeadlessCanvasLike {
7
7
  toBuffer?(mimeType: 'image/png'): Uint8Array;
8
8
  }
9
9
  export type CreateHeadlessCanvas = (width: number, height: number) => HeadlessCanvasLike;
10
+ export type HeadlessStageBackend = HeadlessWebGpuBackend | 'webgpu' | 'webgl' | 'canvas2d';
10
11
  export interface HeadlessStageOptions {
11
- /** Canvas factory such as `createCanvas` from `@napi-rs/canvas`. */
12
- readonly createCanvas: CreateHeadlessCanvas;
12
+ /**
13
+ * Canvas factory such as `createCanvas` from `@napi-rs/canvas`.
14
+ * Required for `CANVAS` rendering or `TextObject` rasterization; optional when `gpuDevice` or `glContext` is supplied.
15
+ */
16
+ readonly createCanvas?: CreateHeadlessCanvas;
13
17
  /** Optional `Path2D` constructor (e.g. from `@napi-rs/canvas`) so `MsdfIconObject` paths render in Node. */
14
18
  readonly Path2D?: typeof Path2D;
15
19
  /** Viewport width in pixels (default `1280`). */
@@ -30,11 +34,26 @@ export interface HeadlessStageOptions {
30
34
  readonly gpuDevice?: WebGpuDeviceLike | null;
31
35
  /** Optional WebGPU offscreen render format when `gpuDevice` is passed (default `'rgba8unorm'`). */
32
36
  readonly gpuFormat?: string;
37
+ /** Optional explicit backend label recorded on `stage.backend`. */
38
+ readonly backend?: HeadlessStageBackend;
39
+ /** Optional cleanup hook invoked when `stage.destroy()` runs. */
40
+ readonly onDestroy?: () => void;
33
41
  /** Optional `StagePlugin[]` (e.g. `createInputTimeline`, `createInputRecorder`) mounted at boot. */
34
42
  readonly plugins?: StagePlugin[];
35
43
  /** Scene instance or constructor to boot synchronously at frame 0. */
36
44
  readonly scene: SceneInput;
37
45
  }
46
+ export interface AsyncHeadlessStageOptions extends Omit<HeadlessStageOptions, 'gpuDevice' | 'gpuFormat' | 'backend'> {
47
+ /**
48
+ * Renderer selection (`default = 'auto'`):
49
+ * - `'auto'`: acquires native Headless WebGPU (`wgpu-native` FFI -> Dawn `webgpu` -> `navigator.gpu`) when available, falling back cleanly to Canvas2D.
50
+ * - `'webgpu'`: requires native Headless WebGPU and throws an actionable setup error if no GPU driver is available.
51
+ * - `'canvas'`: forces deterministic CPU Canvas2D rendering.
52
+ */
53
+ readonly renderer?: 'auto' | 'webgpu' | 'canvas';
54
+ /** Optional native WebGPU discovery options (`libPath`, `backend`, `powerPreference`, `dawnFlags`). */
55
+ readonly webgpu?: HeadlessWebGpuOptions;
56
+ }
38
57
  export interface HeadlessRecordedFrame {
39
58
  /** Zero-based recorded frame index (`0 .. frames - 1`). */
40
59
  readonly index: number;
@@ -65,6 +84,8 @@ export interface HeadlessStage {
65
84
  readonly game: Game;
66
85
  readonly scene: Scene;
67
86
  readonly canvas: HeadlessCanvasLike;
87
+ /** Active headless rendering backend (`'wgpu-bun-ffi' | 'wgpu-node-koffi' | 'dawn' | 'navigator' | 'webgpu' | 'webgl' | 'canvas2d'`). */
88
+ readonly backend: HeadlessStageBackend;
68
89
  readonly width: number;
69
90
  readonly height: number;
70
91
  readonly fps: number;
@@ -113,6 +134,15 @@ export interface HeadlessStage {
113
134
  * (such as `@napi-rs/canvas` in Node) for AI-agent drawing, CI visual assertions, and 60 FPS video rendering.
114
135
  */
115
136
  export declare function createHeadlessStage(options: HeadlessStageOptions): HeadlessStage;
137
+ /**
138
+ * Turnkey async headless Stage initializer across **Bun**, **Node.js**, and **Deno**:
139
+ * - Automatically discovers native Headless WebGPU (`wgpu-native` FFI -> Dawn `webgpu` -> `navigator.gpu`) when `renderer` is `'auto'` (default) or `'webgpu'`
140
+ * - Automatically discovers `@napi-rs/canvas` (`createCanvas` & `Path2D`) if installed when `createCanvas` is omitted (and runs pure-GPU scenes with zero npm dependencies!)
141
+ * - Manages `GPUDevice` cleanup automatically inside `stage.destroy()` and exposes the active backend via `stage.backend`
142
+ */
143
+ export declare function createHeadlessStageAsync(options: AsyncHeadlessStageOptions): Promise<HeadlessStage>;
144
+ /** Alias for `createHeadlessStageAsync` (`await openHeadlessStage({ renderer: 'webgpu', scene })`). */
145
+ export declare const openHeadlessStage: typeof createHeadlessStageAsync;
116
146
  export interface StoryboardOptions {
117
147
  /** Ascending frame numbers to capture (e.g. `[0, 30, 60, 90, 120, 150]`). */
118
148
  readonly frames: readonly number[];
package/dist/headless.js CHANGED
@@ -1,8 +1,127 @@
1
1
  import "./types-CXsCvp1p.js";
2
- import { n as Game } from "./game-DZoRjZNH.js";
3
- import { a as requestHeadlessWebGpu, i as openWgpuNativeFfi, r as openDawnWebGpu } from "./renderer-webgpu-B8vktrUk.js";
2
+ import { n as Game } from "./game-BF1ZbJRC.js";
3
+ import { a as requestHeadlessWebGpu, i as openWgpuNativeFfi, r as openDawnWebGpu } from "./renderer-webgpu-CnIevdNP.js";
4
4
  import { buildSceneDigest } from "./trace.js";
5
5
  // src/headless.ts
6
+ let pngCrcTable = null;
7
+ function getPngCrcTable() {
8
+ if (pngCrcTable) return pngCrcTable;
9
+ const table = /* @__PURE__ */ new Uint32Array(256);
10
+ for (let n = 0; n < 256; n++) {
11
+ let c = n;
12
+ for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ c >>> 1 : c >>> 1;
13
+ table[n] = c >>> 0;
14
+ }
15
+ pngCrcTable = table;
16
+ return table;
17
+ }
18
+ function pngCrc32(buf, start, len) {
19
+ const table = getPngCrcTable();
20
+ let c = 0xffffffff;
21
+ for (let i = 0; i < len; i++) c = table[(c ^ buf[start + i]) & 255] ^ c >>> 8;
22
+ return (c ^ 0xffffffff) >>> 0;
23
+ }
24
+ /** Zero-dependency pure-TS RGBA8888 -> PNG encoder (used when running pure WebGPU/WebGL without `@napi-rs/canvas`). */
25
+ function encodeRgbaToPngFallback(rgba, width, height) {
26
+ const rowStride = width * 4;
27
+ const rawLen = height * (1 + rowStride);
28
+ const raw = new Uint8Array(rawLen);
29
+ let s1 = 1;
30
+ let s2 = 0;
31
+ let dstOff = 0;
32
+ for (let y = 0; y < height; y++) {
33
+ raw[dstOff++] = 0;
34
+ s2 = (s2 + s1) % 65521;
35
+ const srcRow = y * rowStride;
36
+ for (let x = 0; x < rowStride; x++) {
37
+ const b = rgba[srcRow + x];
38
+ raw[dstOff++] = b;
39
+ s1 = (s1 + b) % 65521;
40
+ s2 = (s2 + s1) % 65521;
41
+ }
42
+ }
43
+ const adler = (s2 << 16 | s1) >>> 0;
44
+ const numBlocks = Math.max(1, Math.ceil(rawLen / 65535));
45
+ const idatDataLen = 2 + rawLen + numBlocks * 5 + 4;
46
+ const out = new Uint8Array(57 + idatDataLen);
47
+ const dv = new DataView(out.buffer);
48
+ out.set([
49
+ 137,
50
+ 80,
51
+ 78,
52
+ 71,
53
+ 13,
54
+ 10,
55
+ 26,
56
+ 10
57
+ ], 0);
58
+ dv.setUint32(8, 13, false);
59
+ out.set([
60
+ 73,
61
+ 72,
62
+ 68,
63
+ 82
64
+ ], 12);
65
+ dv.setUint32(16, width, false);
66
+ dv.setUint32(20, height, false);
67
+ out[24] = 8;
68
+ out[25] = 6;
69
+ out[26] = 0;
70
+ out[27] = 0;
71
+ out[28] = 0;
72
+ dv.setUint32(29, pngCrc32(out, 12, 17), false);
73
+ dv.setUint32(33, idatDataLen, false);
74
+ out.set([
75
+ 73,
76
+ 68,
77
+ 65,
78
+ 84
79
+ ], 37);
80
+ let p = 41;
81
+ out[p++] = 120;
82
+ out[p++] = 1;
83
+ let rem = rawLen;
84
+ let rOff = 0;
85
+ while (rem > 0 || rOff === 0) {
86
+ const chunk = Math.min(65535, rem);
87
+ const isFinal = rem - chunk <= 0 ? 1 : 0;
88
+ out[p++] = isFinal;
89
+ out[p++] = chunk & 255;
90
+ out[p++] = chunk >>> 8 & 255;
91
+ const nlen = ~chunk & 65535;
92
+ out[p++] = nlen & 255;
93
+ out[p++] = nlen >>> 8 & 255;
94
+ if (chunk > 0) {
95
+ out.set(raw.subarray(rOff, rOff + chunk), p);
96
+ p += chunk;
97
+ rOff += chunk;
98
+ rem -= chunk;
99
+ }
100
+ if (isFinal) break;
101
+ }
102
+ dv.setUint32(p, adler, false);
103
+ p += 4;
104
+ dv.setUint32(p, pngCrc32(out, 37, 4 + idatDataLen), false);
105
+ p += 4;
106
+ dv.setUint32(p, 0, false);
107
+ out.set([
108
+ 73,
109
+ 69,
110
+ 78,
111
+ 68
112
+ ], p + 4);
113
+ dv.setUint32(p + 8, pngCrc32(out, p + 4, 4), false);
114
+ return out;
115
+ }
116
+ function createGpuStubCanvas(width, height) {
117
+ return {
118
+ width,
119
+ height,
120
+ getContext() {
121
+ return null;
122
+ }
123
+ };
124
+ }
6
125
  function createVirtualDomHost(createCanvas, width, height) {
7
126
  const winStub = {
8
127
  innerWidth: width,
@@ -72,8 +191,9 @@ function createHeadlessStage(options) {
72
191
  const height = Math.max(1, Math.round(options.height ?? 720));
73
192
  const fps = Math.max(1, Math.min(240, options.fps ?? 60));
74
193
  const dt = 1e3 / fps;
194
+ if (!options.createCanvas && !options.gpuDevice && !options.glContext) throw new Error("createHeadlessStage: pass createCanvas (e.g. from @napi-rs/canvas) for Canvas2D, or use await createHeadlessStageAsync({ renderer: \"webgpu\" | \"auto\", ... })");
75
195
  if (options.Path2D && typeof globalThis.Path2D !== "function") globalThis.Path2D = options.Path2D;
76
- const { rootCanvas } = createVirtualDomHost(options.createCanvas, width, height);
196
+ const { rootCanvas } = createVirtualDomHost(options.createCanvas ?? createGpuStubCanvas, width, height);
77
197
  const game = new Game({
78
198
  type: options.gpuDevice ? 3 : options.glContext ? 2 : 1,
79
199
  canvas: rootCanvas,
@@ -182,20 +302,28 @@ function createHeadlessStage(options) {
182
302
  return toRgba();
183
303
  };
184
304
  const toPng = () => {
185
- if (game.renderer.type !== 1) syncGpuPixelsToRootCanvas(toRgba());
305
+ const cw = rootCanvas.width || width;
306
+ const ch = rootCanvas.height || height;
307
+ const rgba = game.renderer.type !== 1 ? toRgba() : null;
308
+ if (rgba) syncGpuPixelsToRootCanvas(rgba);
186
309
  if (typeof rootCanvas.toBuffer === "function") {
187
310
  const buf = rootCanvas.toBuffer("image/png");
188
311
  return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
189
312
  }
190
- throw new Error("HeadlessStage.toPng: canvas does not implement toBuffer(\"image/png\"); pass createCanvas from @napi-rs/canvas");
313
+ if (rgba) return encodeRgbaToPngFallback(rgba, cw, ch);
314
+ return encodeRgbaToPngFallback(toRgba(), cw, ch);
191
315
  };
192
316
  const toPngAsync = async () => {
193
- if (game.renderer.type !== 1) syncGpuPixelsToRootCanvas(await toRgbaAsync());
317
+ const cw = rootCanvas.width || width;
318
+ const ch = rootCanvas.height || height;
319
+ const rgba = game.renderer.type !== 1 ? await toRgbaAsync() : null;
320
+ if (rgba) syncGpuPixelsToRootCanvas(rgba);
194
321
  if (typeof rootCanvas.toBuffer === "function") {
195
322
  const buf = rootCanvas.toBuffer("image/png");
196
323
  return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
197
324
  }
198
- throw new Error("HeadlessStage.toPngAsync: canvas does not implement toBuffer(\"image/png\"); pass createCanvas from @napi-rs/canvas");
325
+ if (rgba) return encodeRgbaToPngFallback(rgba, cw, ch);
326
+ return encodeRgbaToPngFallback(await toRgbaAsync(), cw, ch);
199
327
  };
200
328
  const digest = (digestOpts) => buildSceneDigest(primaryScene, digestOpts);
201
329
  const recordFrames = async (recOpts) => {
@@ -232,6 +360,7 @@ function createHeadlessStage(options) {
232
360
  game,
233
361
  scene: primaryScene,
234
362
  canvas: rootCanvas,
363
+ backend: options.backend ?? (game.renderer.type === 3 ? "webgpu" : game.renderer.type === 2 ? "webgl" : "canvas2d"),
235
364
  width,
236
365
  height,
237
366
  fps,
@@ -281,10 +410,73 @@ function createHeadlessStage(options) {
281
410
  digest,
282
411
  recordFrames,
283
412
  encodeVideo: (encOpts) => encodeVideoWithFfmpeg(self, encOpts),
284
- destroy: () => game.destroy(false)
413
+ destroy: () => {
414
+ game.destroy(false);
415
+ options.onDestroy?.();
416
+ }
285
417
  };
286
418
  return self;
287
419
  }
420
+ const dynamicImportHeadless = (specifier) => import(
421
+ /* @vite-ignore */
422
+ specifier
423
+ );
424
+ async function tryAutoDiscoverCanvasFactory() {
425
+ try {
426
+ const mod = await dynamicImportHeadless("@napi-rs/canvas");
427
+ if (mod && typeof mod.createCanvas === "function") return {
428
+ createCanvas: mod.createCanvas,
429
+ Path2D: mod.Path2D
430
+ };
431
+ } catch {}
432
+ const proc = globalThis.process;
433
+ if (!proc || typeof proc.cwd !== "function") return {};
434
+ try {
435
+ const [modNs, pathNs] = await Promise.all([dynamicImportHeadless("node:module"), dynamicImportHeadless("node:path")]);
436
+ const mod = modNs.createRequire(pathNs.join(proc.cwd(), "__stage_canvas_resolve__.cjs"))("@napi-rs/canvas");
437
+ if (mod && typeof mod.createCanvas === "function") return {
438
+ createCanvas: mod.createCanvas,
439
+ Path2D: mod.Path2D
440
+ };
441
+ } catch {}
442
+ return {};
443
+ }
444
+ /**
445
+ * Turnkey async headless Stage initializer across **Bun**, **Node.js**, and **Deno**:
446
+ * - Automatically discovers native Headless WebGPU (`wgpu-native` FFI -> Dawn `webgpu` -> `navigator.gpu`) when `renderer` is `'auto'` (default) or `'webgpu'`
447
+ * - Automatically discovers `@napi-rs/canvas` (`createCanvas` & `Path2D`) if installed when `createCanvas` is omitted (and runs pure-GPU scenes with zero npm dependencies!)
448
+ * - Manages `GPUDevice` cleanup automatically inside `stage.destroy()` and exposes the active backend via `stage.backend`
449
+ */
450
+ async function createHeadlessStageAsync(options) {
451
+ const mode = options.renderer ?? "auto";
452
+ let createCanvas = options.createCanvas;
453
+ let path2DCtor = options.Path2D;
454
+ if (!createCanvas) {
455
+ const discovered = await tryAutoDiscoverCanvasFactory();
456
+ createCanvas = discovered.createCanvas;
457
+ if (!path2DCtor && discovered.Path2D) path2DCtor = discovered.Path2D;
458
+ }
459
+ let gpu = null;
460
+ if (mode === "webgpu" || mode === "auto") {
461
+ gpu = await requestHeadlessWebGpu(options.webgpu);
462
+ if (!gpu && mode === "webgpu") throw new Error("createHeadlessStageAsync: WebGPU requested (renderer: \"webgpu\") but no native WebGPU backend was found. Set STAGE_WGPU_LIB=/path/to/libwgpu_native.{so,dylib,dll}, install the \"webgpu\" (Dawn) package, run on Deno with --unstable-webgpu, or pass renderer: \"auto\" to allow Canvas2D fallback.");
463
+ }
464
+ if (!gpu && !options.glContext && !createCanvas) throw new Error("createHeadlessStageAsync: neither a Headless WebGPU backend nor @napi-rs/canvas was found; install @napi-rs/canvas or configure WebGPU.");
465
+ return createHeadlessStage({
466
+ ...options,
467
+ createCanvas,
468
+ Path2D: path2DCtor,
469
+ gpuDevice: gpu?.device ?? null,
470
+ gpuFormat: gpu?.format,
471
+ backend: gpu ? gpu.backend : options.glContext ? "webgl" : "canvas2d",
472
+ onDestroy: () => {
473
+ options.onDestroy?.();
474
+ gpu?.destroy();
475
+ }
476
+ });
477
+ }
478
+ /** Alias for `createHeadlessStageAsync` (`await openHeadlessStage({ renderer: 'webgpu', scene })`). */
479
+ const openHeadlessStage = createHeadlessStageAsync;
288
480
  /**
289
481
  * Step a `HeadlessStage` across target keyframes and composite a single multi-panel
290
482
  * storyboard contact sheet + paired `SceneDigest` array so AI agents can visually and
@@ -630,4 +822,4 @@ async function encodeVideoWithFfmpeg(stage, options) {
630
822
  } catch {}
631
823
  }
632
824
  }
633
- export { buildFfmpegRawVideoArgs, createAudioTimeline, createHeadlessStage, encodeVideoWithFfmpeg, openDawnWebGpu, openWgpuNativeFfi, renderStoryboard, requestHeadlessWebGpu };
825
+ export { buildFfmpegRawVideoArgs, createAudioTimeline, createHeadlessStage, createHeadlessStageAsync, encodeVideoWithFfmpeg, openDawnWebGpu, openHeadlessStage, openWgpuNativeFfi, renderStoryboard, requestHeadlessWebGpu };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { $n as HiDpiConfigureOptions, $t as OpenWgpuNativeFfiOptions, A as createInputRecorder, An as InstancedBatchObject, At as SceneDigestOverlayStats, Bn as SceneHostLike, Bt as Pointer, C as RecordedInputEntry, Cn as DrawStreamBulkView, D as TimelineClickOptions, Dn as EquipmentBinding, Dt as SceneDigestEngineSandbox, E as StagePlugin, En as DrawStreamSpriteOptions, Et as SceneDigestActiveFocus, Fn as PanelObject, Ft as buildSceneDigest, Gn as SpriteObject, Gt as WebGpuBootstrapResult, Hn as ShapeBatchObject, Ht as RendererWebGpu, In as PanelOpenSide, It as sanitizeTrackToken, Jn as TextObject, Jt as requestWebGpuDevice, Kn as SpritePlayOptions, Kt as WebGpuCanvasContextLike, Ln as PanelStyleConfig, Lt as InputConfig, M as createInputTimeline, Mn as MsdfIconConfig, Mt as SceneDigestSurfaceEntry, Nn as MsdfIconObject, Nt as SceneDigestSurfaceSource, O as TimelineDragOptions, On as Graphics, Ot as SceneDigestNode, Pn as NineSliceObject, Pt as SceneDigestSurfaces, Qn as CameraFollowOptions, Qt as OpenDawnWebGpuOptions, Rn as RectClipMask, Rt as InputPlugin, S as InputTimelinePlugin, Sn as DisplaySemantics, T as StageKernel, Tn as DrawStreamOptions, Tt as SceneDigest, Un as ShapeBatchStyleDefaults, Ut as RendererWebGpuOptions, Vn as ShapeBatchColumns, Vt as PointerSample, Wn as SpriteAnimEventListener, Wt as RequestWebGpuOptions, Xn as TileSpriteObject, Xt as HeadlessWebGpuHandle, Yn as TextStyleConfig, Yt as HeadlessWebGpuBackend, Zn as Camera, Zt as HeadlessWebGpuOptions, _ as ActionMap, _n as CustomPassOptions, a as GameLoop, an as RendererGlOptions, b as InputTargetSpec, bn as DisplayObject, c as LoaderPlugin, cn as StageRenderTarget, d as SceneCtor, dn as BlitterObject, en as openDawnWebGpu, er as HiDpiScaleLike, f as SceneInput, fn as Bob$1, g as ViewportFitResult, gn as CustomPassObject, h as StageRenderer, hn as CustomPassCallback, i as GameConfig$1, in as RendererGl, j as createInputReplay, jn as InstancedColumns, jt as SceneDigestSandbox, k as TimelineKeyOptions, kn as ImageObject, kt as SceneDigestOptions, l as ScaleManager, ln as AnchorPose2D, m as SceneManager, mn as ContainerFiltersShim, n as EngineClockSnapshot, nn as requestHeadlessWebGpu, o as GameObjectFactory, on as RendererStats, p as SceneLifecycleStats, pn as Container, qn as SyncAttachmentOptions, qt as WebGpuDeviceLike, r as Game, rn as Renderer2D, s as JsonCache, sn as Stage2DCustomImageHandler, t as EngineClock, tn as openWgpuNativeFfi, u as Scene, un as BindEquipmentOptions, v as InputProvider, vn as DirectionalPlayOptions, w as StageInputEvent, wn as DrawStreamObject, x as InputTimelineOptions, xn as DisplayObjectType, y as InputRecorderPlugin, yn as DisplayList, zn as RectangleObject, zt as KeyboardPlugin } from "./game-CT_WCPjJ.js";
2
- import { A as FilterModeValue, B as WEBGL, C as AUTO, D as CANVAS, E as BlendModes, F as Scale, G as packColorAbgr, H as WHITE_RGB, I as ScaleMode, K as parseColor, L as Scenes, M as Matrix2D, N as Rect2D, O as EventEmitter, P as RgbaColor, R as TintMode, S as TextureSource, T as BlendMode, U as WorldView2D, V as WEBGPU, W as createMatrix2D, _ as SpriteSheetConfig, a as AtlasClipRule, b as TextureImageSource, c as GenerateFrameNamesConfig, d as AtlasJsonLike, f as CanvasTexture, g as GlTextureHost, h as FrameExtraMeta, i as AtlasAutoAnimOptions, j as HEX_MASK, k as FilterMode, l as GenerateFrameNumbersConfig, m as FrameAnchorTuple, n as AnimationFrameInput, o as CompiledAnimationFrame, p as Frame, q as rgbToCss, r as AnimationManager, s as DirectionalAnimGroup, t as AnimationConfig, u as StageAnimation, v as Texture, w as BLACK_RGB, x as TextureManager, y as TextureImageOptions, z as TintModes } from "./anims-BYBzSNXO.js";
1
+ import { $n as HiDpiConfigureOptions, $t as OpenWgpuNativeFfiOptions, A as createInputRecorder, An as InstancedBatchObject, At as SceneDigestOverlayStats, Bn as SceneHostLike, Bt as Pointer, C as RecordedInputEntry, Cn as DrawStreamBulkView, D as TimelineClickOptions, Dn as EquipmentBinding, Dt as SceneDigestEngineSandbox, E as StagePlugin, En as DrawStreamSpriteOptions, Et as SceneDigestActiveFocus, Fn as PanelObject, Ft as buildSceneDigest, Gn as SpriteObject, Gt as WebGpuBootstrapResult, Hn as ShapeBatchObject, Ht as RendererWebGpu, In as PanelOpenSide, It as sanitizeTrackToken, Jn as TextObject, Jt as requestWebGpuDevice, Kn as SpritePlayOptions, Kt as WebGpuCanvasContextLike, Ln as PanelStyleConfig, Lt as InputConfig, M as createInputTimeline, Mn as MsdfIconConfig, Mt as SceneDigestSurfaceEntry, Nn as MsdfIconObject, Nt as SceneDigestSurfaceSource, O as TimelineDragOptions, On as Graphics, Ot as SceneDigestNode, Pn as NineSliceObject, Pt as SceneDigestSurfaces, Qn as CameraFollowOptions, Qt as OpenDawnWebGpuOptions, Rn as RectClipMask, Rt as InputPlugin, S as InputTimelinePlugin, Sn as DisplaySemantics, T as StageKernel, Tn as DrawStreamOptions, Tt as SceneDigest, Un as ShapeBatchStyleDefaults, Ut as RendererWebGpuOptions, Vn as ShapeBatchColumns, Vt as PointerSample, Wn as SpriteAnimEventListener, Wt as RequestWebGpuOptions, Xn as TileSpriteObject, Xt as HeadlessWebGpuHandle, Yn as TextStyleConfig, Yt as HeadlessWebGpuBackend, Zn as Camera, Zt as HeadlessWebGpuOptions, _ as ActionMap, _n as CustomPassOptions, a as GameLoop, an as RendererGlOptions, b as InputTargetSpec, bn as DisplayObject, c as LoaderPlugin, cn as StageRenderTarget, d as SceneCtor, dn as BlitterObject, en as openDawnWebGpu, er as HiDpiScaleLike, f as SceneInput, fn as Bob$1, g as ViewportFitResult, gn as CustomPassObject, h as StageRenderer, hn as CustomPassCallback, i as GameConfig$1, in as RendererGl, j as createInputReplay, jn as InstancedColumns, jt as SceneDigestSandbox, k as TimelineKeyOptions, kn as ImageObject, kt as SceneDigestOptions, l as ScaleManager, ln as AnchorPose2D, m as SceneManager, mn as ContainerFiltersShim, n as EngineClockSnapshot, nn as requestHeadlessWebGpu, o as GameObjectFactory, on as RendererStats, p as SceneLifecycleStats, pn as Container, qn as SyncAttachmentOptions, qt as WebGpuDeviceLike, r as Game, rn as Renderer2D, s as JsonCache, sn as Stage2DCustomImageHandler, t as EngineClock, tn as openWgpuNativeFfi, u as Scene, un as BindEquipmentOptions, v as InputProvider, vn as DirectionalPlayOptions, w as StageInputEvent, wn as DrawStreamObject, x as InputTimelineOptions, xn as DisplayObjectType, y as InputRecorderPlugin, yn as DisplayList, zn as RectangleObject, zt as KeyboardPlugin } from "./game-rKghsNlA.js";
2
+ import { A as FilterModeValue, B as WEBGL, C as AUTO, D as CANVAS, E as BlendModes, F as Scale, G as packColorAbgr, H as WHITE_RGB, I as ScaleMode, K as parseColor, L as Scenes, M as Matrix2D, N as Rect2D, O as EventEmitter, P as RgbaColor, R as TintMode, S as TextureSource, T as BlendMode, U as WorldView2D, V as WEBGPU, W as createMatrix2D, _ as SpriteSheetConfig, a as AtlasClipRule, b as TextureImageSource, c as GenerateFrameNamesConfig, d as AtlasJsonLike, f as CanvasTexture, g as GlTextureHost, h as FrameExtraMeta, i as AtlasAutoAnimOptions, j as HEX_MASK, k as FilterMode, l as GenerateFrameNumbersConfig, m as FrameAnchorTuple, n as AnimationFrameInput, o as CompiledAnimationFrame, p as Frame, q as rgbToCss, r as AnimationManager, s as DirectionalAnimGroup, t as AnimationConfig, u as StageAnimation, v as Texture, w as BLACK_RGB, x as TextureManager, y as TextureImageOptions, z as TintModes } from "./anims-BOvaKn6w.js";
3
3
  import { FlattenedFlexNode, FlattenedFlexTree, FlexAlign, FlexContainerSpec, FlexDir, FlexIconSpec, FlexItemRect, FlexItemSpec, FlexJustify, FlexNodeSpec, FlexPadding, FlexPanelStyle, FlexResult, FlexTextSpec, MountFlexUiOptions, MountedFlexUi, WrapContainerSpec, WrapItemRect, WrapItemSpec, WrapJustify, WrapResult, computeFlexLayout, computeWrapLayout, flattenFlexTree, mountFlexUi, resolvePadding } from "./flex.js";
4
4
  import { a as SpringHandle, c as TweenManager, i as Easings, l as TweenOptions, n as EasingFn, o as SpringOptions, r as EasingName, s as TweenHandle, t as DisposableOwner, u as TweenStats } from "./tween-BiF1FUvc.js";
5
5
  import { a as ScriptOptions, i as ScriptHandle, o as ScriptScheduler, r as ScriptContext, s as ScriptStats, t as CoroutineGenerator } from "./coroutine-DLgJumtD.js";
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { _ as rgbToCss, a as EventEmitter, c as Scale, d as WEBGL, f as WEBGPU, g as parseColor, h as packColorAbgr, i as CANVAS, l as Scenes, m as createMatrix2D, n as BLACK_RGB, o as FilterMode, p as WHITE_RGB, r as BlendModes, s as HEX_MASK, t as AUTO, u as TintModes } from "./types-CXsCvp1p.js";
2
- import { _ as CanvasTexture, a as JsonCache, b as TextureManager, c as Scene, d as KeyboardPlugin, f as Pointer, g as SdfPanelBatcher, h as MsdfIconBatcher, i as GameObjectFactory, l as SceneManager, m as PixelAaBatcher, n as Game, o as LoaderPlugin, p as RendererGl, r as GameLoop, s as ScaleManager, t as EngineClock, u as InputPlugin, v as Frame, x as TextureSource, y as Texture } from "./game-DZoRjZNH.js";
2
+ import { _ as CanvasTexture, a as JsonCache, b as TextureManager, c as Scene, d as KeyboardPlugin, f as Pointer, g as SdfPanelBatcher, h as MsdfIconBatcher, i as GameObjectFactory, l as SceneManager, m as PixelAaBatcher, n as Game, o as LoaderPlugin, p as RendererGl, r as GameLoop, s as ScaleManager, t as EngineClock, u as InputPlugin, v as Frame, x as TextureSource, y as Texture } from "./game-BF1ZbJRC.js";
3
3
  import { AnimationManager } from "./anims.js";
4
- import { a as requestHeadlessWebGpu, i as openWgpuNativeFfi, n as requestWebGpuDevice, o as Renderer2D, r as openDawnWebGpu, s as Camera, t as RendererWebGpu } from "./renderer-webgpu-B8vktrUk.js";
5
- import { _ as TileSpriteObject, a as DisplayObject, c as ImageObject, d as NineSliceObject, f as PanelObject, g as TextObject, h as SpriteObject, i as DisplayList, l as InstancedBatchObject, m as ShapeBatchObject, n as Container, o as DrawStreamObject, p as RectangleObject, r as CustomPassObject, s as Graphics, t as BlitterObject, u as MsdfIconObject } from "./display-CuyQc8oE.js";
4
+ import { a as requestHeadlessWebGpu, i as openWgpuNativeFfi, n as requestWebGpuDevice, o as Renderer2D, r as openDawnWebGpu, s as Camera, t as RendererWebGpu } from "./renderer-webgpu-CnIevdNP.js";
5
+ import { _ as TileSpriteObject, a as DisplayObject, c as ImageObject, d as NineSliceObject, f as PanelObject, g as TextObject, h as SpriteObject, i as DisplayList, l as InstancedBatchObject, m as ShapeBatchObject, n as Container, o as DrawStreamObject, p as RectangleObject, r as CustomPassObject, s as Graphics, t as BlitterObject, u as MsdfIconObject } from "./display-CVjvA8ZO.js";
6
6
  import { ActionMap, StageKernel, createInputRecorder, createInputReplay, createInputTimeline } from "./kernel.js";
7
7
  import { buildSceneDigest, sanitizeTrackToken } from "./trace.js";
8
8
  import { computeFlexLayout, computeWrapLayout, flattenFlexTree, mountFlexUi, resolvePadding } from "./flex.js";
@@ -1,4 +1,4 @@
1
- import { Bt as Pointer, Fn as PanelObject, pn as Container, u as Scene } from "./game-CT_WCPjJ.js";
1
+ import { Bt as Pointer, Fn as PanelObject, pn as Container, u as Scene } from "./game-rKghsNlA.js";
2
2
  export type VirtualJoystickMode = 'floating' | 'fixed';
3
3
  export interface JoystickVector {
4
4
  /** Normalized X axis in [-1, 1] after deadzone remapping. */
package/dist/kernel.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { a as ScriptOptions, i as ScriptHandle, o as ScriptScheduler, r as ScriptContext, s as ScriptStats, t as CoroutineGenerator } from "./coroutine-DLgJumtD.js";
2
- import { A as createInputRecorder, C as RecordedInputEntry, D as TimelineClickOptions, E as StagePlugin, M as createInputTimeline, O as TimelineDragOptions, S as InputTimelinePlugin, T as StageKernel, _ as ActionMap, b as InputTargetSpec, j as createInputReplay, k as TimelineKeyOptions, v as InputProvider, w as StageInputEvent, x as InputTimelineOptions, y as InputRecorderPlugin } from "./game-CT_WCPjJ.js";
2
+ import { A as createInputRecorder, C as RecordedInputEntry, D as TimelineClickOptions, E as StagePlugin, M as createInputTimeline, O as TimelineDragOptions, S as InputTimelinePlugin, T as StageKernel, _ as ActionMap, b as InputTargetSpec, j as createInputReplay, k as TimelineKeyOptions, v as InputProvider, w as StageInputEvent, x as InputTimelineOptions, y as InputRecorderPlugin } from "./game-rKghsNlA.js";
3
3
  export { ActionMap, type CoroutineGenerator, InputProvider, InputRecorderPlugin, InputTargetSpec, InputTimelineOptions, InputTimelinePlugin, RecordedInputEntry, type ScriptContext, type ScriptHandle, type ScriptOptions, ScriptScheduler, type ScriptStats, StageInputEvent, StageKernel, StagePlugin, TimelineClickOptions, TimelineDragOptions, TimelineKeyOptions, createInputRecorder, createInputReplay, createInputTimeline };
@@ -1,4 +1,4 @@
1
- import { Bn as SceneHostLike, bn as DisplayObject, gn as CustomPassObject, kn as ImageObject, pn as Container } from "./game-CT_WCPjJ.js";
1
+ import { Bn as SceneHostLike, bn as DisplayObject, gn as CustomPassObject, kn as ImageObject, pn as Container } from "./game-rKghsNlA.js";
2
2
  export type DayPhase = 'day' | 'dusk' | 'night';
3
3
  export interface DayNightConfig {
4
4
  dayLengthMs?: number;
package/dist/lighting.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { m as createMatrix2D, o as FilterMode, r as BlendModes } from "./types-CXsCvp1p.js";
2
- import { l as InstancedBatchObject } from "./display-CuyQc8oE.js";
2
+ import { l as InstancedBatchObject } from "./display-CVjvA8ZO.js";
3
3
  // src/lighting.ts
4
4
  function lerpChannel(a, b, t) {
5
5
  return Math.round(a + (b - a) * t) & 255;
@@ -247,34 +247,39 @@ const RADIAL_GLOW_SIZE = 128;
247
247
  function ensureRadialGlowTexture(textures) {
248
248
  if (textures.exists(RADIAL_GLOW_KEY)) return true;
249
249
  try {
250
- const ct = textures.createCanvas(RADIAL_GLOW_KEY, RADIAL_GLOW_SIZE, RADIAL_GLOW_SIZE);
251
- if (!ct) return false;
252
- const ctx = ct.canvas.getContext("2d");
253
- if (!ctx || typeof ctx.createImageData !== "function" || typeof ctx.putImageData !== "function") {
254
- textures.remove(RADIAL_GLOW_KEY);
255
- return false;
256
- }
257
- const img = ctx.createImageData(RADIAL_GLOW_SIZE, RADIAL_GLOW_SIZE);
258
- const data = img.data;
250
+ const raw = /* @__PURE__ */ new Uint8Array(65536);
259
251
  const half = 63.5;
260
252
  const invR = 1 / half;
261
253
  for (let y = 0; y < RADIAL_GLOW_SIZE; y++) for (let x = 0; x < RADIAL_GLOW_SIZE; x++) {
262
254
  const r = Math.hypot(x - half, y - half) * invR;
263
255
  const idx = (y * RADIAL_GLOW_SIZE + x) * 4;
264
- data[idx] = 255;
265
- data[idx + 1] = 255;
266
- data[idx + 2] = 255;
267
- if (r >= 1) data[idx + 3] = 0;
256
+ raw[idx] = 255;
257
+ raw[idx + 1] = 255;
258
+ raw[idx + 2] = 255;
259
+ if (r >= 1) raw[idx + 3] = 0;
268
260
  else {
269
261
  const u = 1 - r;
270
262
  const falloff = u * u * (.78 + .22 * u * u);
271
- data[idx + 3] = Math.round(falloff * 255);
263
+ raw[idx + 3] = Math.round(falloff * 255);
272
264
  }
273
265
  }
274
- ctx.putImageData(img, 0, 0);
275
- ct.refresh();
276
- ct.source[0]?.setFilter(FilterMode.LINEAR);
277
- return true;
266
+ const ct = textures.createCanvas(RADIAL_GLOW_KEY, RADIAL_GLOW_SIZE, RADIAL_GLOW_SIZE);
267
+ const ctx = ct?.canvas.getContext?.("2d");
268
+ if (ct && ctx && typeof ctx.createImageData === "function" && typeof ctx.putImageData === "function") {
269
+ const img = ctx.createImageData(RADIAL_GLOW_SIZE, RADIAL_GLOW_SIZE);
270
+ img.data.set(raw);
271
+ ctx.putImageData(img, 0, 0);
272
+ ct.refresh();
273
+ ct.source[0]?.setFilter(FilterMode.LINEAR);
274
+ return true;
275
+ }
276
+ if (ct) textures.remove(RADIAL_GLOW_KEY);
277
+ const dataTex = textures.addImage(RADIAL_GLOW_KEY, {
278
+ width: RADIAL_GLOW_SIZE,
279
+ height: RADIAL_GLOW_SIZE,
280
+ data: raw
281
+ }, { filterMode: FilterMode.LINEAR });
282
+ return Boolean(dataTex);
278
283
  } catch {
279
284
  if (textures.exists(RADIAL_GLOW_KEY)) textures.remove(RADIAL_GLOW_KEY);
280
285
  return false;
@@ -984,7 +989,10 @@ function createSceneNormalLitPass(scene, opts) {
984
989
  if (!scene.textures.exists(normKey)) return;
985
990
  const normTex = scene.textures.get(normKey);
986
991
  const diffGl = glRenderer.ensureGlTexture(fr.source);
987
- const normGl = glRenderer.ensureGlTexture(normTex.source[0]);
992
+ const normFrame = normTex.has(fr.name) ? normTex.get(fr.name) : null;
993
+ const normSrc = normFrame ? normFrame.source : normTex.source[fr.sourceIndex] ?? normTex.source[0];
994
+ if (!normSrc) return;
995
+ const normGl = glRenderer.ensureGlTexture(normSrc);
988
996
  if (!diffGl || !normGl) return;
989
997
  if (diffGl !== curDiffGl || normGl !== curNormGl) {
990
998
  flushBatch();
@@ -1,4 +1,4 @@
1
- import { Bn as SceneHostLike, bn as DisplayObject, pn as Container } from "./game-CT_WCPjJ.js";
1
+ import { Bn as SceneHostLike, bn as DisplayObject, pn as Container } from "./game-rKghsNlA.js";
2
2
  export interface Camera25DConfig {
3
3
  viewportWidth: number;
4
4
  viewportHeight: number;