@holtjs/stage 0.14.0 → 0.15.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.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,20 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.15.0] - 2026-12-05
10
+
11
+ ### Added, Optimized & Fixed
12
+ - **Seamless Cross-Chunk Neighbor-Apron Tilemap Composite & Edge-Extruded Dual-Grid Baker (`@holtjs/stage/tilemap`, `src/tilemap.ts`)**:
13
+ - `mountChunkedTilemap()` now enables chunk texture pre-compositing (`chunkCache: true`) by default across **WebGPU**, **WebGL2**, and **Canvas2D** (including a zero-Canvas2D pure-RGBA compositor for pure-WebGPU headless environments), collapsing ~4,500 per-frame rotated tile quads down to ~12 chunk quads while automatically inheriting `FilterMode.LINEAR` / `FilterMode.NEAREST` from the source tileset.
14
+ - Each cached chunk texture now bakes a `2px` cross-chunk world-neighbor apron (`chunkApron: 2`, with 2-tile border mutation invalidation in `ChunkedTilemap`) so `FilterMode.LINEAR` interpolates seamlessly across `16×16` chunk boundaries with zero tile or chunk cross seams under 45° isometric rotation and non-integer zoom.
15
+ - `bakeDualGridTileset()` now performs `2px` per-side edge-and-corner texel extrusion by default (`extrude: 2`), accepts `{ createCanvas, extrude, filterMode }` options, exposes raw `rgba` / `width` / `height` / `frameRect`, and runs in zero-DOM pure-WebGPU Node/Bun without `@napi-rs/canvas`.
16
+ - **Responsive `Scale.RESIZE` Container Observer & Automatic 2.5D Viewport Sync (`src/game.ts`, `src/projection.ts`, `src/lighting.ts`)**:
17
+ - `Game` with `scale: { mode: Scale.RESIZE }` now sizes the backing canvas to `parentElement` / `window` immediately before `Scene.create()` and attaches `ResizeObserver` + `resize` / `orientationchange` listeners (`fitToResizeContainer()`), automatically updating `scene.cameras.main` and `mountStage25D` (`autoResize: true`).
18
+ - `Lighting2DSystem.resize()` now skips redundant render-target reallocations and uses bounded sequential keys (`${baseKey}_r1`, `${baseKey}_r2`) instead of unbounded `_r` suffixes.
19
+ - **Trimmed-FFmpeg Auto-Fallback (`mjpeg` `image2pipe` + `libvpx-vp9` WebM) & Headless Linux SwiftShader ICD Auto-Discovery (`src/headless.ts`, `src/webgpu-headless.ts`)**:
20
+ - `stage.encodeVideo()` / `encodeVideoWithFfmpeg()` now auto-discovers Playwright's cached `ffmpeg` when system `ffmpeg` is absent, probes supported demuxers/decoders/encoders once per binary, and automatically switches from `rawvideo` (`libx264` MP4) to `image2pipe` (`mjpeg` + `libvpx-vp9` WebM) on stripped `ffmpeg` builds (using `@napi-rs/canvas` `toBuffer('image/jpeg')` when present or a built-in zero-dependency pure-TS baseline JFIF JPEG encoder).
21
+ - `openWgpuNativeFfi()` now searches `~/.cache/holt-stage/wgpu/lib` and `~/.local/lib` for `libwgpu_native` and automatically wires Playwright/Chromium's bundled `vk_swiftshader_icd.json` (including C `setenv` under `bun:ffi`) on headless Linux hosts without system `/usr/share/vulkan/icd.d`.
22
+
9
23
  ## [0.14.0] - 2026-12-05
10
24
 
11
25
  ### Added, Optimized & Fixed
package/README.md CHANGED
@@ -26,7 +26,7 @@ A zero-dependency, tracing-first **WebGPU / WebGL2 / Canvas2D** 2D & 2.5D game,
26
26
  - `ActionMap` (`bind`, `isDown`, `justPressed`, `axis`) + `InputProvider` bus shared by hardware mouse/keyboard, `createInputTimeline({ showCursor: true })` (click directly by `trackId`!), and `createInputRecorder` / `createInputReplay`.
27
27
  - **2.5D Survival Sandbox Engine Pillars (*Don't Starve* / *Graveyard Keeper*-ready)**:
28
28
  - **`@holtjs/stage/rig2d`** (`5.7 kB` gz): 2D cutout/slot skeletal hierarchy, O(1) tool/hat/armor attachment & skin swapping without phase glitches, 2-layer base + bone-masked overlay mixer (chop while walking), keyframe events, and procedural `bakeCutoutAtlas()`.
29
- - **`@holtjs/stage/tilemap`** (`3.5 kB` gz): Sparse `ChunkedTilemap` (`±1,000,000` coords), cross-chunk dirty propagation, Oskar Stålberg **16-tile Dual-Grid** & **47-tile Blob** autotilers, island biome generator, and viewport-streaming `mountChunkedTilemap()`.
29
+ - **`@holtjs/stage/tilemap`** (`3.5 kB` gz): Sparse `ChunkedTilemap` (`±1,000,000` coords), cross-chunk dirty propagation, **16-tile Dual-Grid** & **47-tile Blob** autotilers with edge extrusion, island biome generator, and seamless neighbor-apron `mountChunkedTilemap()`.
30
30
  - **`@holtjs/stage/projection`** (`1.6 kB` gz): Rotatable oblique `Camera25D` (`worldToScreen` ↔ `screenToGround` exact inverse across 360° `yaw` spins + smooth `Q/E` rotation) and `mountStage25D()` upright cylindrical depth-sorted billboards.
31
31
  - **`@holtjs/stage/lighting`** (`4.1 kB` gz): `DayNightCycle`, Sobel 3×3 `bakeNormalMapCanvas()`, `Lighting2DSystem` (`MULTIPLY` offscreen lightmap FBO + flickering torches), and WebGL2 `createNormalLitSpritePass()`.
32
32
  - **`@holtjs/stage/world`** (`2.8 kB` gz): `ItemRegistry`, `InventoryContainer` (with `freshness01` spoilage), `RecipeRegistry`, `WorkstationScheduler` (offline tick catch-up), and compact `HWLD` binary `WorldDeltaSave`.
@@ -1,6 +1,6 @@
1
1
  import { _ as rgbToCss, a as EventEmitter, c as Scale, h as packColorAbgr, l as Scenes, m as createMatrix2D, o as FilterMode, p as WHITE_RGB, r as BlendModes, u as TintModes } from "./types-CXsCvp1p.js";
2
2
  import { AnimationManager } from "./anims.js";
3
- import { o as Renderer2D, s as Camera, t as RendererWebGpu } from "./renderer-webgpu-CnIevdNP.js";
3
+ import { o as Renderer2D, s as Camera, t as RendererWebGpu } from "./renderer-webgpu-q4vdE3kA.js";
4
4
  import { _ as TileSpriteObject, 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";
5
5
  import { TweenManager } from "./tween.js";
6
6
  import { ScriptScheduler } from "./coroutine.js";
@@ -5341,8 +5341,10 @@ var ScaleManager = class extends EventEmitter {
5341
5341
  fitToContainer(availWidth, availHeight) {
5342
5342
  const parent = this.canvas?.parentElement;
5343
5343
  const win = this.canvas?.ownerDocument?.defaultView;
5344
- const aw = Math.max(1, availWidth ?? parent?.clientWidth ?? win?.innerWidth ?? this.logicalWidth);
5345
- const ah = Math.max(1, availHeight ?? parent?.clientHeight ?? win?.innerHeight ?? this.logicalHeight);
5344
+ const parentW = parent?.clientWidth ?? 0;
5345
+ const parentH = parent?.clientHeight ?? 0;
5346
+ const aw = Math.max(1, availWidth ?? (parentW > 0 ? parentW : void 0) ?? win?.innerWidth ?? this.logicalWidth);
5347
+ const ah = Math.max(1, availHeight ?? (parentH > 0 ? parentH : void 0) ?? win?.innerHeight ?? this.logicalHeight);
5346
5348
  const lw = Math.max(1, this.logicalWidth);
5347
5349
  const lh = Math.max(1, this.logicalHeight);
5348
5350
  const scale = Math.min(aw / lw, ah / lh);
@@ -5364,11 +5366,42 @@ var ScaleManager = class extends EventEmitter {
5364
5366
  offsetY
5365
5367
  };
5366
5368
  }
5369
+ /**
5370
+ * Resize the backing canvas and `logicalWidth/logicalHeight` to fill `availWidth × availHeight`
5371
+ * (or `canvas.parentElement` / `window`) 1:1 without letterboxing (`Scale.RESIZE`), emitting `'resize'`.
5372
+ */
5373
+ fitToResizeContainer(availWidth, availHeight) {
5374
+ const parent = this.canvas?.parentElement;
5375
+ const win = this.canvas?.ownerDocument?.defaultView;
5376
+ const parentW = parent?.clientWidth ?? 0;
5377
+ const parentH = parent?.clientHeight ?? 0;
5378
+ const w = Math.max(1, Math.round(availWidth ?? (parentW > 0 ? parentW : void 0) ?? win?.innerWidth ?? this.width));
5379
+ const h = Math.max(1, Math.round(availHeight ?? (parentH > 0 ? parentH : void 0) ?? win?.innerHeight ?? this.height));
5380
+ if (this.canvas?.style) {
5381
+ this.canvas.style.width = `${w}px`;
5382
+ this.canvas.style.height = `${h}px`;
5383
+ }
5384
+ this.logicalWidth = w;
5385
+ this.logicalHeight = h;
5386
+ if (w !== this.width || h !== this.height) this.resize(w, h);
5387
+ else {
5388
+ this.displayScale.x = 1 / (this.zoom || 1);
5389
+ this.displayScale.y = 1 / (this.zoom || 1);
5390
+ }
5391
+ return {
5392
+ width: w,
5393
+ height: h
5394
+ };
5395
+ }
5367
5396
  refresh() {
5368
5397
  if (this.mode === Scale.FIT) {
5369
5398
  this.fitToContainer();
5370
5399
  return this;
5371
5400
  }
5401
+ if (this.mode === Scale.RESIZE) {
5402
+ this.fitToResizeContainer();
5403
+ return this;
5404
+ }
5372
5405
  this.displayScale.x = 1 / (this.zoom || 1);
5373
5406
  this.displayScale.y = 1 / (this.zoom || 1);
5374
5407
  return this;
@@ -5694,6 +5727,7 @@ var Game = class {
5694
5727
  ownedCanvas = false;
5695
5728
  inStep = false;
5696
5729
  onWindowResize = null;
5730
+ resizeObserver = null;
5697
5731
  constructor(config = {}) {
5698
5732
  this.config = config;
5699
5733
  const fallbackDoc = typeof document !== "undefined" ? document : void 0;
@@ -5753,13 +5787,22 @@ var Game = class {
5753
5787
  };
5754
5788
  const scaleMode = config.scale?.mode ?? Scale.NONE;
5755
5789
  this.scale = new ScaleManager(this.canvas, this.renderer, width, height, zoom, scaleMode);
5756
- if (scaleMode === Scale.FIT) {
5757
- this.scale.fitToContainer();
5790
+ if (scaleMode === Scale.FIT || scaleMode === Scale.RESIZE) {
5791
+ this.scale.refresh();
5792
+ this.onWindowResize = () => {
5793
+ if (!this.destroyed) this.scale.refresh();
5794
+ };
5758
5795
  if (this.win && typeof this.win.addEventListener === "function") {
5759
- this.onWindowResize = () => {
5760
- if (!this.destroyed) this.scale.fitToContainer();
5761
- };
5762
5796
  this.win.addEventListener("resize", this.onWindowResize);
5797
+ this.win.addEventListener("orientationchange", this.onWindowResize);
5798
+ }
5799
+ const observeEl = this.canvas?.parentElement;
5800
+ if (observeEl && typeof ResizeObserver === "function") {
5801
+ const ro = new ResizeObserver(() => {
5802
+ if (!this.destroyed) this.scale.refresh();
5803
+ });
5804
+ ro.observe(observeEl);
5805
+ this.resizeObserver = ro;
5763
5806
  }
5764
5807
  }
5765
5808
  this.cache = { json: new JsonCache() };
@@ -5840,8 +5883,13 @@ var Game = class {
5840
5883
  this.pendingDestroy = true;
5841
5884
  this.destroyed = true;
5842
5885
  this.loop.destroy();
5886
+ if (this.resizeObserver) {
5887
+ this.resizeObserver.disconnect();
5888
+ this.resizeObserver = null;
5889
+ }
5843
5890
  if (this.onWindowResize && this.win && typeof this.win.removeEventListener === "function") {
5844
5891
  this.win.removeEventListener("resize", this.onWindowResize);
5892
+ this.win.removeEventListener("orientationchange", this.onWindowResize);
5845
5893
  this.onWindowResize = null;
5846
5894
  }
5847
5895
  this.events.emit("destroy", this);
@@ -1,4 +1,4 @@
1
- import { I as ScaleMode, M as Matrix2D, N as Rect2D, O as EventEmitter, P as RgbaColor, R as TintMode, S as TextureSource, T as BlendMode, U as WorldView2D, _ as SpriteSheetConfig, d as AtlasJsonLike, g as GlTextureHost, p as Frame, r as AnimationManager, u as StageAnimation, v as Texture, x as TextureManager, y as TextureImageOptions } from "./anims-BOvaKn6w.js";
1
+ import { A as FilterModeValue, I as ScaleMode, M as Matrix2D, N as Rect2D, O as EventEmitter, P as RgbaColor, R as TintMode, S as TextureSource, T as BlendMode, U as WorldView2D, _ as SpriteSheetConfig, d as AtlasJsonLike, g as GlTextureHost, p as Frame, r as AnimationManager, u as StageAnimation, v as Texture, x as TextureManager, y as TextureImageOptions } from "./anims-BOvaKn6w.js";
2
2
  import { c as TweenManager, u as TweenStats } from "./tween-BiF1FUvc.js";
3
3
  import { a as ScriptOptions, i as ScriptHandle, o as ScriptScheduler, r as ScriptContext, s as ScriptStats, t as CoroutineGenerator } from "./coroutine-DLgJumtD.js";
4
4
  interface CameraFollowOptions {
@@ -1737,7 +1737,7 @@ declare function unpackChunkY(key: number): number;
1737
1737
  declare function floorDiv(a: number, b: number): number;
1738
1738
  declare function positiveMod(a: number, b: number): number;
1739
1739
  /**
1740
- * Compute Oskar Stålberg's 4-bit **Dual-Grid** mask (`0..15`) for visual vertex `(vx, vy)`,
1740
+ * Compute the 4-bit **Dual-Grid** mask (`0..15`) for half-offset visual vertex `(vx, vy)`,
1741
1741
  * which sits at world `(vx * tileSize - tileSize * 0.5, vy * tileSize - tileSize * 0.5)` and samples
1742
1742
  * the 4 surrounding logical cells `(vx-1, vy-1)`, `(vx, vy-1)`, `(vx-1, vy)`, `(vx, vy)`.
1743
1743
  *
@@ -1854,20 +1854,64 @@ interface DualGridLayerSpec {
1854
1854
  /** Returns true when a ground `turfId` belongs to (or sits above) this Dual-Grid terrain layer. */
1855
1855
  matches: (turfId: number) => boolean;
1856
1856
  }
1857
+ interface BakeDualGridTilesetOptions {
1858
+ /** Custom canvas factory (e.g. `@napi-rs/canvas` `createCanvas` in headless Node/Bun). */
1859
+ createCanvas?: (w: number, h: number) => HTMLCanvasElement;
1860
+ /**
1861
+ * Per-side border extrusion in pixels (`default = 2`).
1862
+ * Repeats each tile's outermost edge and corner texels into a `2 * extrude` gutter around every cell
1863
+ * so `FilterMode.LINEAR` rotated or scaled quads never bleed adjacent tiles or transparent gutters.
1864
+ */
1865
+ extrude?: number;
1866
+ /** Default `FilterMode` used by `registerOnScene()` (`default = FilterMode.NEAREST`; pass `FilterMode.LINEAR` for rotated 2.5D ground). */
1867
+ filterMode?: FilterModeValue;
1868
+ }
1857
1869
  interface BakedDualGridAtlas {
1858
1870
  readonly textureKey: string;
1859
1871
  readonly tileSize: number;
1872
+ readonly extrude: number;
1873
+ readonly cellStride: number;
1874
+ readonly filterMode: FilterModeValue;
1875
+ readonly width: number;
1876
+ readonly height: number;
1877
+ readonly rgba: Uint8ClampedArray;
1860
1878
  readonly canvas: HTMLCanvasElement;
1861
1879
  readonly layers: ReadonlyArray<DualGridLayerSpec>;
1862
1880
  frameName(layerId: string, mask: number): string;
1863
- registerOnScene(scene: SceneHostLike): void;
1881
+ frameRect(layerIndex: number, mask: number): {
1882
+ x: number;
1883
+ y: number;
1884
+ width: number;
1885
+ height: number;
1886
+ };
1887
+ registerOnScene(scene: SceneHostLike, opts?: {
1888
+ filterMode?: FilterModeValue;
1889
+ }): void;
1864
1890
  }
1865
1891
  /**
1866
1892
  * Bake one or more 16-tile (`0..15`) organic Dual-Grid terrain layers onto a single crisp texture atlas!
1867
- * Uses smooth analytical quarter-circle / saddle SDF distance fields per pixel so beaches, grass, dark forest,
1868
- * and cobblestone roads interlock with hand-crafted *Don't Starve* turf borders.
1893
+ * Uses smooth analytical quarter-circle / saddle SDF distance fields per pixel with edge-pixel extrusion
1894
+ * (`extrude = 2` by default) so rotated 2.5D ground never bleeds neighbor cells under `FilterMode.LINEAR`.
1869
1895
  */
1870
- declare function bakeDualGridTileset(textureKey: string, tileSize: number, layers: DualGridLayerSpec[], createCanvasFn?: (w: number, h: number) => HTMLCanvasElement): BakedDualGridAtlas;
1896
+ declare function bakeDualGridTileset(textureKey: string, tileSize: number, layers: DualGridLayerSpec[], createCanvasOrOpts?: ((w: number, h: number) => HTMLCanvasElement) | BakeDualGridTilesetOptions, maybeOpts?: BakeDualGridTilesetOptions): BakedDualGridAtlas;
1897
+ interface MountChunkedTilemapOptions {
1898
+ baseColor?: number;
1899
+ depth?: number;
1900
+ marginChunks?: number;
1901
+ trackId?: string;
1902
+ /**
1903
+ * Pre-composite all Dual-Grid layers of each `16×16` chunk onto a cached offscreen chunk texture (`default = true` across WebGPU, WebGL2 & Canvas2D).
1904
+ * Eliminates per-tile UV seams, inherits `filterMode` (`LINEAR` / `NEAREST`), and collapses ~4,500 tile quads/frame down to ~12 chunk quads.
1905
+ */
1906
+ chunkCache?: boolean;
1907
+ /**
1908
+ * Cross-chunk neighbor apron in pixels baked around each cached chunk texture (`default = 2`).
1909
+ * Samples actual neighboring world Dual-Grid tiles so `FilterMode.LINEAR` interpolates seamlessly across chunk boundaries.
1910
+ */
1911
+ chunkApron?: number;
1912
+ /** Override `FilterMode` for cached chunk textures (defaults to the source tileset texture's `filterMode`). */
1913
+ filterMode?: FilterModeValue;
1914
+ }
1871
1915
  interface MountedChunkedTilemap {
1872
1916
  readonly container: Container;
1873
1917
  readonly blitters: ReadonlyArray<BlitterObject>;
@@ -1886,18 +1930,12 @@ interface MountedChunkedTilemap {
1886
1930
  }
1887
1931
  /**
1888
1932
  * Mount a `ChunkedTilemap` + `BakedDualGridAtlas` onto a Stage `Scene`.
1889
- * - On WebGL2 / WebGPU: batches into 1 GPU `BlitterObject` draw call per Dual-Grid layer.
1890
- * - On Canvas2D / pure-Node `createHeadlessStage`: automatically pre-composites all Dual-Grid layers of each
1891
- * `16×16` chunk onto a cached offscreen chunk canvas keyed by `chunk.version` (collapsing ~4,500 per-frame
1892
- * rotated tile `drawImage` calls down to ~12 chunk blits — >10× faster 60 FPS headless video rendering!).
1933
+ * - By default (`chunkCache: true`) across WebGPU, WebGL2, and Canvas2D: pre-composites all Dual-Grid layers of each
1934
+ * chunk onto a cached chunk texture with a `2px` cross-chunk world-neighbor apron (`chunkApron: 2`), inheriting
1935
+ * `FilterMode.LINEAR` / `FilterMode.NEAREST` so rotated 2.5D ground has zero tile or chunk seams at ~12 quads/frame.
1936
+ * - Pass `{ chunkCache: false }` to emit individual per-layer `BlitterObject` quads instead.
1893
1937
  */
1894
- declare function mountChunkedTilemap(scene: SceneHostLike, map: ChunkedTilemap, atlas: BakedDualGridAtlas, opts?: {
1895
- baseColor?: number;
1896
- depth?: number;
1897
- marginChunks?: number;
1898
- trackId?: string;
1899
- chunkCache?: boolean;
1900
- }): MountedChunkedTilemap;
1938
+ declare function mountChunkedTilemap(scene: SceneHostLike, map: ChunkedTilemap, atlas: BakedDualGridAtlas, opts?: MountChunkedTilemapOptions): MountedChunkedTilemap;
1901
1939
  interface ItemDef {
1902
1940
  id: string;
1903
1941
  name?: string;
@@ -2463,6 +2501,14 @@ declare class ScaleManager extends EventEmitter {
2463
2501
  * preserving `logicalWidth : logicalHeight` aspect ratio (zero CSS matrix distortion; `InputPlugin` & `clientToWorld` stay exact).
2464
2502
  */
2465
2503
  fitToContainer(availWidth?: number, availHeight?: number): ViewportFitResult;
2504
+ /**
2505
+ * Resize the backing canvas and `logicalWidth/logicalHeight` to fill `availWidth × availHeight`
2506
+ * (or `canvas.parentElement` / `window`) 1:1 without letterboxing (`Scale.RESIZE`), emitting `'resize'`.
2507
+ */
2508
+ fitToResizeContainer(availWidth?: number, availHeight?: number): {
2509
+ width: number;
2510
+ height: number;
2511
+ };
2466
2512
  refresh(): this;
2467
2513
  }
2468
2514
  interface SceneLifecycleStats {
@@ -2611,10 +2657,11 @@ declare class Game {
2611
2657
  private ownedCanvas;
2612
2658
  private inStep;
2613
2659
  private onWindowResize;
2660
+ private resizeObserver;
2614
2661
  constructor(config?: GameConfig);
2615
2662
  /** Advance simulation, tweens, kernel plugins, and camera follow by one deterministic tick WITHOUT rendering pixels. */
2616
2663
  stepSimOnly(time: number, delta: number): boolean;
2617
2664
  step(time: number, delta: number): void;
2618
2665
  destroy(removeCanvas?: boolean): void;
2619
2666
  }
2620
- export { decodeWorldDeltaBytes as $, HiDpiConfigureOptions as $n, OpenWgpuNativeFfiOptions as $t, createInputRecorder as A, InstancedBatchObject as An, SceneDigestOverlayStats as At, RecipeRegistry as B, SceneHostLike as Bn, Pointer as Bt, RecordedInputEntry as C, DrawStreamBulkView as Cn, unpackChunkY as Ct, TimelineClickOptions as D, EquipmentBinding as Dn, SceneDigestEngineSandbox as Dt, StagePlugin as E, DrawStreamSpriteOptions as En, SceneDigestActiveFocus as Et, InventoryContainer as F, PanelObject as Fn, buildSceneDigest as Ft, WorkstationSnapshot as G, SpriteObject as Gn, WebGpuBootstrapResult as Gt, WorkstationInstance as H, ShapeBatchObject as Hn, RendererWebGpu as Ht, ItemDef as I, PanelOpenSide as In, sanitizeTrackToken as It, WorldDeltaSnapshot as J, TextObject as Jn, requestWebGpuDevice as Jt, WorldCatalogRuntime as K, SpritePlayOptions as Kn, WebGpuCanvasContextLike as Kt, ItemRegistry as L, PanelStyleConfig as Ln, InputConfig as Lt, createInputTimeline as M, MsdfIconConfig as Mn, SceneDigestSurfaceEntry as Mt, CatalogReloadDiff as N, MsdfIconObject as Nn, SceneDigestSurfaceSource as Nt, TimelineDragOptions as O, Graphics as On, SceneDigestNode as Ot, FrozenWorldCatalog as P, NineSliceObject as Pn, SceneDigestSurfaces as Pt, createWorldCatalogRuntime as Q, CameraFollowOptions as Qn, OpenDawnWebGpuOptions as Qt, ItemStack as R, RectClipMask as Rn, InputPlugin as Rt, InputTimelinePlugin as S, DisplaySemantics as Sn, unpackChunkX as St, StageKernel as T, DrawStreamOptions as Tn, SceneDigest as Tt, WorkstationJob as U, ShapeBatchStyleDefaults as Un, RendererWebGpuOptions as Ut, TileCellDelta as V, ShapeBatchColumns as Vn, PointerSample as Vt, WorkstationScheduler as W, SpriteAnimEventListener as Wn, RequestWebGpuOptions as Wt, applyWorldDelta as X, TileSpriteObject as Xn, HeadlessWebGpuHandle as Xt, WorldEntityRecord as Y, TextStyleConfig as Yn, HeadlessWebGpuBackend as Yt, captureWorldDelta as Z, Camera as Zn, HeadlessWebGpuOptions as Zt, ActionMap as _, CustomPassOptions as _n, floorDiv as _t, GameLoop as a, RendererGlOptions as an, ChunkedTilemapOptions as at, InputTargetSpec as b, DisplayObject as bn, packChunkKey as bt, LoaderPlugin as c, StageRenderTarget as cn, MountedChunkedTilemap as ct, SceneCtor as d, BlitterObject as dn, TileChunk as dt, openDawnWebGpu as en, HiDpiScaleLike as er, defineWorldCatalog as et, SceneInput as f, Bob as fn, bakeDualGridTileset as ft, ViewportFitResult as g, CustomPassObject as gn, fbm2D as gt, StageRenderer as h, CustomPassCallback as hn, createIslandBiomeGenerator as ht, GameConfig as i, RendererGl as in, ChunkedTilemap as it, createInputReplay as j, InstancedColumns as jn, SceneDigestSandbox as jt, TimelineKeyOptions as k, ImageObject as kn, SceneDigestOptions as kt, ScaleManager as l, AnchorPose2D as ln, SurvivalBiomes as lt, SceneManager as m, ContainerFiltersShim as mn, computeDualGridMask as mt, EngineClockSnapshot as n, requestHeadlessWebGpu as nn, BakedDualGridAtlas as nt, GameObjectFactory as o, RendererStats as on, DualGridLayerSpec as ot, SceneLifecycleStats as p, Container as pn, computeBlob47Index as pt, WorldCatalogSpec as q, SyncAttachmentOptions as qn, WebGpuDeviceLike as qt, Game as r, Renderer2D as rn, ChunkGeneratorFn as rt, JsonCache as s, Stage2DCustomImageHandler as sn, IslandBiomeConfig as st, EngineClock as t, openWgpuNativeFfi as tn, encodeWorldDeltaBytes as tt, Scene as u, BindEquipmentOptions as un, TileCellFlags as ut, InputProvider as v, DirectionalPlayOptions as vn, hash2D as vt, StageInputEvent as w, DrawStreamObject as wn, valueNoise2D as wt, InputTimelineOptions as x, DisplayObjectType as xn, positiveMod as xt, InputRecorderPlugin as y, DisplayList as yn, mountChunkedTilemap as yt, RecipeDef as z, RectangleObject as zn, KeyboardPlugin as zt };
2667
+ export { decodeWorldDeltaBytes as $, Camera as $n, HeadlessWebGpuOptions as $t, createInputRecorder as A, Graphics as An, SceneDigestNode as At, RecipeRegistry as B, RectClipMask as Bn, InputPlugin as Bt, RecordedInputEntry as C, DisplayObjectType as Cn, positiveMod as Ct, TimelineClickOptions as D, DrawStreamOptions as Dn, SceneDigest as Dt, StagePlugin as E, DrawStreamObject as En, valueNoise2D as Et, InventoryContainer as F, MsdfIconObject as Fn, SceneDigestSurfaceSource as Ft, WorkstationSnapshot as G, ShapeBatchStyleDefaults as Gn, RendererWebGpuOptions as Gt, WorkstationInstance as H, SceneHostLike as Hn, Pointer as Ht, ItemDef as I, NineSliceObject as In, SceneDigestSurfaces as It, WorldDeltaSnapshot as J, SpritePlayOptions as Jn, WebGpuCanvasContextLike as Jt, WorldCatalogRuntime as K, SpriteAnimEventListener as Kn, RequestWebGpuOptions as Kt, ItemRegistry as L, PanelObject as Ln, buildSceneDigest as Lt, createInputTimeline as M, InstancedBatchObject as Mn, SceneDigestOverlayStats as Mt, CatalogReloadDiff as N, InstancedColumns as Nn, SceneDigestSandbox as Nt, TimelineDragOptions as O, DrawStreamSpriteOptions as On, SceneDigestActiveFocus as Ot, FrozenWorldCatalog as P, MsdfIconConfig as Pn, SceneDigestSurfaceEntry as Pt, createWorldCatalogRuntime as Q, TileSpriteObject as Qn, HeadlessWebGpuHandle as Qt, ItemStack as R, PanelOpenSide as Rn, sanitizeTrackToken as Rt, InputTimelinePlugin as S, DisplayObject as Sn, packChunkKey as St, StageKernel as T, DrawStreamBulkView as Tn, unpackChunkY as Tt, WorkstationJob as U, ShapeBatchColumns as Un, PointerSample as Ut, TileCellDelta as V, RectangleObject as Vn, KeyboardPlugin as Vt, WorkstationScheduler as W, ShapeBatchObject as Wn, RendererWebGpu as Wt, applyWorldDelta as X, TextObject as Xn, requestWebGpuDevice as Xt, WorldEntityRecord as Y, SyncAttachmentOptions as Yn, WebGpuDeviceLike as Yt, captureWorldDelta as Z, TextStyleConfig as Zn, HeadlessWebGpuBackend as Zt, ActionMap as _, CustomPassCallback as _n, createIslandBiomeGenerator as _t, GameLoop as a, Renderer2D as an, ChunkedTilemap as at, InputTargetSpec as b, DirectionalPlayOptions as bn, hash2D as bt, LoaderPlugin as c, RendererStats as cn, IslandBiomeConfig as ct, SceneCtor as d, AnchorPose2D as dn, SurvivalBiomes as dt, OpenDawnWebGpuOptions as en, CameraFollowOptions as er, defineWorldCatalog as et, SceneInput as f, BindEquipmentOptions as fn, TileCellFlags as ft, ViewportFitResult as g, ContainerFiltersShim as gn, computeDualGridMask as gt, StageRenderer as h, Container as hn, computeBlob47Index as ht, GameConfig as i, requestHeadlessWebGpu as in, ChunkGeneratorFn as it, createInputReplay as j, ImageObject as jn, SceneDigestOptions as jt, TimelineKeyOptions as k, EquipmentBinding as kn, SceneDigestEngineSandbox as kt, ScaleManager as l, Stage2DCustomImageHandler as ln, MountChunkedTilemapOptions as lt, SceneManager as m, Bob as mn, bakeDualGridTileset as mt, EngineClockSnapshot as n, openDawnWebGpu as nn, HiDpiScaleLike as nr, BakeDualGridTilesetOptions as nt, GameObjectFactory as o, RendererGl as on, ChunkedTilemapOptions as ot, SceneLifecycleStats as p, BlitterObject as pn, TileChunk as pt, WorldCatalogSpec as q, SpriteObject as qn, WebGpuBootstrapResult as qt, Game as r, openWgpuNativeFfi as rn, BakedDualGridAtlas as rt, JsonCache as s, RendererGlOptions as sn, DualGridLayerSpec as st, EngineClock as t, OpenWgpuNativeFfiOptions as tn, HiDpiConfigureOptions as tr, encodeWorldDeltaBytes as tt, Scene as u, StageRenderTarget as un, MountedChunkedTilemap as ut, InputProvider as v, CustomPassObject as vn, fbm2D as vt, StageInputEvent as w, DisplaySemantics as wn, unpackChunkX as wt, InputTimelineOptions as x, DisplayList as xn, mountChunkedTilemap as xt, InputRecorderPlugin as y, CustomPassOptions as yn, floorDiv as yt, RecipeDef as z, PanelStyleConfig as zn, InputConfig as zt };
@@ -1,10 +1,10 @@
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";
1
+ import { $t as HeadlessWebGpuOptions, Dt as SceneDigest, E as StagePlugin, Qt as HeadlessWebGpuHandle, Yt as WebGpuDeviceLike, Zt as HeadlessWebGpuBackend, en as OpenDawnWebGpuOptions, f as SceneInput, in as requestHeadlessWebGpu, jt as SceneDigestOptions, n as EngineClockSnapshot, nn as openDawnWebGpu, r as Game, rn as openWgpuNativeFfi, tn as OpenWgpuNativeFfiOptions, u as Scene } from "./game-Ce35GTH4.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;
5
5
  height: number;
6
6
  getContext(contextId: '2d', options?: unknown): CanvasRenderingContext2D | null;
7
- toBuffer?(mimeType: 'image/png'): Uint8Array;
7
+ toBuffer?(mimeType: string, quality?: number): Uint8Array;
8
8
  }
9
9
  export type CreateHeadlessCanvas = (width: number, height: number) => HeadlessCanvasLike;
10
10
  export type HeadlessStageBackend = HeadlessWebGpuBackend | 'webgpu' | 'webgl' | 'canvas2d';
@@ -198,30 +198,33 @@ export interface AudioTimeline {
198
198
  * chiptune cues with 60 FPS headless video renders. Exports ready-to-mux stereo 16-bit `.wav` bytes.
199
199
  */
200
200
  export declare function createAudioTimeline(options?: AudioTimelineOptions): AudioTimeline;
201
+ export type FfmpegInputFormat = 'auto' | 'rawvideo' | 'mjpeg' | 'png';
201
202
  export interface FfmpegRawVideoArgsOptions {
202
203
  readonly width: number;
203
204
  readonly height: number;
204
205
  readonly fps: number;
205
206
  readonly outputPath: string;
207
+ /** Input pipe format (`'rawvideo'` default for `buildFfmpegRawVideoArgs`, `'mjpeg'` or `'png'` for `image2pipe`). */
208
+ readonly inputFormat?: Exclude<FfmpegInputFormat, 'auto'>;
206
209
  /** Optional path to a `.wav` audio file (e.g. written from `AudioTimeline.toWav()`). */
207
210
  readonly audioWavPath?: string;
208
- /** Video codec (default `'libx264'`). */
211
+ /** Video codec (default `'libx264'`, or `'libvpx-vp9'` when `outputPath` ends with `.webm`). */
209
212
  readonly videoCodec?: string;
210
- /** Encoder preset (default `'veryfast'`). */
213
+ /** Encoder preset (default `'veryfast'` for x264/x265). */
211
214
  readonly preset?: string;
212
- /** Constant Rate Factor quality `0..51` (default `19`). */
215
+ /** Constant Rate Factor quality `0..51` (default `19`, or `28` for VP9). */
213
216
  readonly crf?: number;
214
217
  /** Output pixel format for universal player compatibility (default `'yuv420p'`). */
215
218
  readonly outputPixelFormat?: string;
216
- /** Audio codec when `audioWavPath` is supplied (default `'aac'`). */
219
+ /** Audio codec when `audioWavPath` is supplied (default `'aac'`, or `'libopus'` for `.webm`). */
217
220
  readonly audioCodec?: string;
218
221
  /** Audio bitrate when `audioWavPath` is supplied (default `'160k'`). */
219
222
  readonly audioBitrate?: string;
220
- /** Extra CLI flags appended before `-movflags +faststart <outputPath>`. */
223
+ /** Extra CLI flags appended before `<outputPath>`. */
221
224
  readonly extraArgs?: readonly string[];
222
225
  }
223
226
  export interface EncodeVideoWithFfmpegOptions {
224
- /** Destination video file path (e.g. `'out.mp4'`). */
227
+ /** Destination video file path (e.g. `'out.mp4'` or `'out.webm'`). */
225
228
  readonly outputPath: string;
226
229
  /** Total frames to render (`frames` or `durationMs` required). */
227
230
  readonly frames?: number;
@@ -229,26 +232,36 @@ export interface EncodeVideoWithFfmpegOptions {
229
232
  readonly durationMs?: number;
230
233
  /** Optional `AudioTimeline`, stereo `.wav` `Uint8Array`, or `.wav` file path muxed into the output video. */
231
234
  readonly audio?: AudioTimeline | Uint8Array | string;
232
- /** Custom `ffmpeg` executable path (default `'ffmpeg'`). */
235
+ /** Custom `ffmpeg` executable path (auto-discovers system `ffmpeg` or Playwright's cached `ffmpeg` when omitted). */
233
236
  readonly ffmpegPath?: string;
234
- /** Video codec (default `'libx264'`). */
237
+ /**
238
+ * Frame pipe format (`default = 'auto'`):
239
+ * - `'auto'`: uses zero-copy `'rawvideo'` when supported by `ffmpeg`, falling back automatically to `'mjpeg'` on trimmed Playwright `ffmpeg` builds.
240
+ * - `'rawvideo'`: streams uncompressed `RGBA8888` (`-f rawvideo -pix_fmt rgba`).
241
+ * - `'mjpeg'`: encodes each frame as JPEG (`-f image2pipe -vcodec mjpeg`) for stripped `ffmpeg` builds.
242
+ * - `'png'`: encodes each frame as PNG (`-f image2pipe -vcodec png`).
243
+ */
244
+ readonly inputFormat?: FfmpegInputFormat;
245
+ /** JPEG quality `1..100` when `inputFormat` resolves to `'mjpeg'` (`default = 90`). */
246
+ readonly jpegQuality?: number;
247
+ /** Video codec (auto-selects `'libx264'` or `'libvpx-vp9'` based on container and `ffmpeg` capabilities when omitted). */
235
248
  readonly videoCodec?: string;
236
- /** Encoder preset (default `'veryfast'`). */
249
+ /** Encoder preset (default `'veryfast'` on x264/x265). */
237
250
  readonly preset?: string;
238
- /** Constant Rate Factor quality `0..51` (default `19`). */
251
+ /** Constant Rate Factor quality `0..51` (default `19` for H.264, `28` for VP9). */
239
252
  readonly crf?: number;
240
253
  /** Output pixel format (default `'yuv420p'`). */
241
254
  readonly outputPixelFormat?: string;
242
- /** Audio codec when `audio` is provided (default `'aac'`). */
255
+ /** Audio codec when `audio` is provided (default `'aac'` for MP4, `'libopus'` for WebM). */
243
256
  readonly audioCodec?: string;
244
257
  /** Audio bitrate when `audio` is provided (default `'160k'`). */
245
258
  readonly audioBitrate?: string;
246
- /** Extra CLI flags appended before `-movflags +faststart <outputPath>`. */
259
+ /** Extra CLI flags appended before `<outputPath>`. */
247
260
  readonly extraArgs?: readonly string[];
248
261
  /** Capture a zero-PII `SceneDigest` every N frames (`0` = disabled; default `0`). */
249
262
  readonly digestEvery?: number;
250
263
  readonly digestOptions?: SceneDigestOptions;
251
- /** Optional per-frame hook invoked after stepping each frame before piping raw RGBA8888 to `ffmpeg`. */
264
+ /** Optional per-frame hook invoked after stepping each frame before piping to `ffmpeg`. */
252
265
  readonly onFrame?: (frame: HeadlessRecordedFrame) => void | Promise<void>;
253
266
  }
254
267
  export interface EncodeVideoResult {
@@ -260,15 +273,18 @@ export interface EncodeVideoResult {
260
273
  readonly durationMs: number;
261
274
  readonly clock: EngineClockSnapshot;
262
275
  readonly digests: SceneDigest[];
276
+ readonly inputFormat: Exclude<FfmpegInputFormat, 'auto'>;
277
+ readonly videoCodec: string;
263
278
  }
264
279
  /**
265
- * Build deterministic `ffmpeg` CLI arguments that consume raw `RGBA8888` frames from `stdin` (`pipe:0`),
266
- * bypassing per-frame PNG/JPEG `image2pipe` CPU encoding overhead (~33 ms/frame saved at 1280x720!).
280
+ * Build deterministic `ffmpeg` CLI arguments that consume `rawvideo` (`RGBA8888`), `mjpeg`, or `png` frames from `stdin` (`pipe:0`),
281
+ * adapting container flags automatically for MP4 (`libx264` + `+faststart`) and WebM (`libvpx-vp9`).
267
282
  */
268
283
  export declare function buildFfmpegRawVideoArgs(options: FfmpegRawVideoArgsOptions): string[];
269
284
  /**
270
- * Step a `HeadlessStage` in Node.js or Bun and stream raw `RGBA8888` frames (`-f rawvideo -pix_fmt rgba`)
271
- * directly into `ffmpeg` stdin with backpressure handling and optional stereo `.wav` audio muxing.
285
+ * Step a `HeadlessStage` in Node.js or Bun and stream frames into `ffmpeg` stdin with backpressure handling.
286
+ * Automatically uses zero-copy `rawvideo` (`RGBA8888`) on full `ffmpeg` builds and falls back seamlessly to
287
+ * `image2pipe` (`mjpeg` + `libvpx-vp9` WebM) when only Playwright's trimmed `ffmpeg` binary is available.
272
288
  */
273
289
  export declare function encodeVideoWithFfmpeg(stage: HeadlessStage, options: EncodeVideoWithFfmpegOptions): Promise<EncodeVideoResult>;
274
290
  export { type HeadlessWebGpuBackend, type HeadlessWebGpuHandle, type HeadlessWebGpuOptions, type OpenDawnWebGpuOptions, type OpenWgpuNativeFfiOptions, openDawnWebGpu, openWgpuNativeFfi, requestHeadlessWebGpu };