@holtjs/stage 0.5.1 → 0.5.2

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.5.2] - 2026-12-04
10
+
11
+ ### Fixed
12
+ - **WebGL `createRenderTarget()` & `renderToTarget()` Feedback Loop (`GL_INVALID_OPERATION`)**:
13
+ - Unbound newly allocated FBO textures from unit `0` (`this.bindTextureAt(0, this.dummyTex)`) inside `createRenderTarget()` and `uploadTextureSource()`, and added `evictTextureFromUnits()` before `gl.bindFramebuffer` in `renderToTarget()` (both on entry and when unwinding nested `prevFbo` targets) so drawing textured sprites or ping-pong blur passes into an offscreen `StageRenderTarget` never forms a sampler/FBO feedback loop without requiring a manual `restoreState()` call (reported by @Ivy).
14
+ - **Real DOM Keyboard `KeyboardPlugin.justPressed()` / `justReleased()` & `ActionMap` Off-by-One Frame Bug + `' '` Space Token**:
15
+ - Mapped inter-frame DOM `keydown`/`keyup`/`blur` and external `HeadlessStage.keyDown()` transitions (`!game.inStep`) to `clock.frameSeq + 1` while keeping intra-step `InputTimeline` / `InputReplay` `poll()` transitions on `clock.frameSeq`, and preserved `' '` literal space normalization before `.trim()` so real browser presses, sub-16ms taps, `blur` releases, and `HeadlessStage.keyDown() + step(1)` all fire `justPressed()` / `justReleased()` accurately (reported by @Ivy).
16
+ - **`RendererGl.restoreState()` Pipeline Completeness**:
17
+ - Reset `gl.disable(gl.DEPTH_TEST)`, `gl.disable(gl.STENCIL_TEST)`, `gl.disable(gl.CULL_FACE)`, `gl.depthMask(true)`, `gl.frontFace(gl.CCW)`, `gl.colorMask(true, true, true, true)`, and `gl.blendEquation(gl.FUNC_ADD)` in `restoreState()` alongside `pixelStorei`, `BLEND`, `viewport`, `scissor`, and `activeFbo` (reported by @Ivy).
18
+ - **Canvas2D `Renderer2D` `InstancedBatchObject` Per-Instance `cols.tint` & Telemetry Parity**:
19
+ - Added `cols.tint` multiplication in `Renderer2D.renderInstancedBatch()` (with consecutive frame/tint caching) and populated per-frame `drawCalls`, `flushes`, `quads`, `tris`, `sdfPanels`, and `msdfIcons` in `Renderer2D.stats()` (reported by @Ivy).
20
+ - **Agent Skill Reference Sync**:
21
+ - Fixed `createAudioTimeline().toStereoPcm16()` method name in `skills/stage/references/subpaths.md` and added `scene.tweens.to()` + offscreen `StageRenderTarget` dedicated `Camera` recipe in `skills/stage/SKILL.md` (reported by @Ivy).
22
+
9
23
  ## [0.5.1] - 2026-12-04
10
24
 
11
25
  ### Fixed
@@ -1,5 +1,5 @@
1
1
  import { _ as rgbToCss, a as EventEmitter, g as parseColor, h as packColorAbgr, l as Scenes, m as createMatrix2D, o as FilterMode, p as WHITE_RGB, r as BlendModes, u as TintModes } from "./types-DRFB0Klc.js";
2
- import { _ as TileSpriteObject, a as Container, d as InstancedBatchObject, f as MsdfIconObject, g as TextObject, h as RectangleObject, i as BlitterObject, l as Graphics, m as PanelObject, o as CustomPassObject, p as NineSliceObject, r as Renderer2D, s as DisplayList, t as RendererWebGpu, u as ImageObject } from "./renderer-webgpu-BE6fTBzo.js";
2
+ import { _ as TileSpriteObject, a as Container, d as InstancedBatchObject, f as MsdfIconObject, g as TextObject, h as RectangleObject, i as BlitterObject, l as Graphics, m as PanelObject, o as CustomPassObject, p as NineSliceObject, r as Renderer2D, s as DisplayList, t as RendererWebGpu, u as ImageObject } from "./renderer-webgpu-Djk7FayG.js";
3
3
  import { TweenManager } from "./tween.js";
4
4
  import { StageKernel } from "./kernel.js";
5
5
  // src/texture.ts
@@ -2330,6 +2330,7 @@ var RendererGl = class extends EventEmitter {
2330
2330
  maskWorldMat = createMatrix2D();
2331
2331
  bindTextSlot0;
2332
2332
  activeFbo = null;
2333
+ activeFboTex = null;
2333
2334
  instProgram = null;
2334
2335
  instUres = null;
2335
2336
  instVao = null;
@@ -2379,6 +2380,7 @@ var RendererGl = class extends EventEmitter {
2379
2380
  e.preventDefault();
2380
2381
  this.contextLost = true;
2381
2382
  this.activeFbo = null;
2383
+ this.activeFboTex = null;
2382
2384
  this.boundTexCache.fill(null);
2383
2385
  this.activeTexUnit = -1;
2384
2386
  this.batchStateBound = false;
@@ -2641,6 +2643,7 @@ var RendererGl = class extends EventEmitter {
2641
2643
  src.glHeight = src.height;
2642
2644
  src.glRepeat = canRepeat;
2643
2645
  src.glPremultiplyAlpha = src.premultiplyAlpha;
2646
+ this.bindTextureAt(0, this.dummyTex);
2644
2647
  } else if (!isNew && src.glWidth === src.width && src.glHeight === src.height && src.glRepeat === canRepeat && src.glPremultiplyAlpha === src.premultiplyAlpha) gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, src.image);
2645
2648
  else {
2646
2649
  const wrap = canRepeat ? gl.REPEAT : gl.CLAMP_TO_EDGE;
@@ -2707,12 +2710,13 @@ var RendererGl = class extends EventEmitter {
2707
2710
  this.batchStateBound = true;
2708
2711
  }
2709
2712
  }
2710
- /** Full state restore for external callers that may have mutated viewport/blend/textures/pixelStore/FBO directly. */
2713
+ /** Full state restore for external callers that may have mutated viewport/blend/cull/depth/stencil/colorMask/textures/pixelStore/FBO directly. */
2711
2714
  restoreState() {
2712
2715
  const gl = this.gl;
2713
2716
  this.invalidateProgramState();
2714
2717
  this.boundTexCache.fill(null);
2715
2718
  this.activeTexUnit = -1;
2719
+ if (this.activeFboTex) this.evictTextureFromUnits(this.activeFboTex);
2716
2720
  if (typeof gl.bindFramebuffer === "function") gl.bindFramebuffer(gl.FRAMEBUFFER, this.activeFbo);
2717
2721
  if (typeof gl.pixelStorei === "function") {
2718
2722
  gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
@@ -2722,10 +2726,21 @@ var RendererGl = class extends EventEmitter {
2722
2726
  if (gl2.UNPACK_ROW_LENGTH !== void 0) gl.pixelStorei(gl2.UNPACK_ROW_LENGTH, 0);
2723
2727
  }
2724
2728
  gl.viewport(0, 0, this.width, this.height);
2729
+ gl.disable(gl.DEPTH_TEST);
2730
+ if (gl.STENCIL_TEST !== void 0) gl.disable(gl.STENCIL_TEST);
2731
+ gl.disable(gl.CULL_FACE);
2732
+ if (typeof gl.depthMask === "function") gl.depthMask(true);
2733
+ if (typeof gl.frontFace === "function" && gl.CCW !== void 0) gl.frontFace(gl.CCW);
2734
+ if (typeof gl.colorMask === "function") gl.colorMask(true, true, true, true);
2725
2735
  gl.enable(gl.BLEND);
2736
+ if (typeof gl.blendEquation === "function" && gl.FUNC_ADD !== void 0) gl.blendEquation(gl.FUNC_ADD);
2726
2737
  this.ensureBatchState();
2727
2738
  this.applyCurrentScissor();
2728
2739
  }
2740
+ /** Evict `tex` (and populate any post-restore `null` slots with `dummyTex`) so binding its FBO never forms a GL feedback loop. */
2741
+ evictTextureFromUnits(tex) {
2742
+ for (let i = 0; i < this.boundTexCache.length; i++) if (this.boundTexCache[i] === tex || this.boundTexCache[i] === null) this.bindTextureAt(i, this.dummyTex);
2743
+ }
2729
2744
  setBlend(mode) {
2730
2745
  if (this.curBlend === mode) return;
2731
2746
  this.flushAll();
@@ -3638,6 +3653,7 @@ var RendererGl = class extends EventEmitter {
3638
3653
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filt);
3639
3654
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filt);
3640
3655
  gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, w, h, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
3656
+ this.bindTextureAt(0, this.dummyTex);
3641
3657
  gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
3642
3658
  gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, glTex, 0);
3643
3659
  gl.bindFramebuffer(gl.FRAMEBUFFER, this.activeFbo);
@@ -3683,6 +3699,7 @@ var RendererGl = class extends EventEmitter {
3683
3699
  const gl = this.gl;
3684
3700
  const src = target.texture.source[0];
3685
3701
  if (!src?.glTexture) return;
3702
+ this.evictTextureFromUnits(src.glTexture);
3686
3703
  let fbo = target._fbo;
3687
3704
  if (!fbo) {
3688
3705
  const created = gl.createFramebuffer();
@@ -3693,9 +3710,11 @@ var RendererGl = class extends EventEmitter {
3693
3710
  target._fbo = fbo;
3694
3711
  } else gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
3695
3712
  const prevFbo = this.activeFbo;
3713
+ const prevFboTex = this.activeFboTex;
3696
3714
  const prevW = this.width;
3697
3715
  const prevH = this.height;
3698
3716
  this.activeFbo = fbo;
3717
+ this.activeFboTex = src.glTexture;
3699
3718
  this.width = target.width;
3700
3719
  this.height = target.height;
3701
3720
  this.updateProjection();
@@ -3716,7 +3735,9 @@ var RendererGl = class extends EventEmitter {
3716
3735
  for (let i = 0; i < list.length; i++) this.renderNode(list[i], camera, null, camAlpha, 0);
3717
3736
  }
3718
3737
  this.flushAll();
3738
+ if (prevFboTex) this.evictTextureFromUnits(prevFboTex);
3719
3739
  this.activeFbo = prevFbo;
3740
+ this.activeFboTex = prevFboTex;
3720
3741
  gl.bindFramebuffer(gl.FRAMEBUFFER, prevFbo);
3721
3742
  this.width = prevW;
3722
3743
  this.height = prevH;
@@ -3976,9 +3997,10 @@ var Pointer = class {
3976
3997
  }
3977
3998
  };
3978
3999
  function normalizeKeyToken(codeOrKey) {
3979
- const raw = String(codeOrKey ?? "").trim();
4000
+ const str = String(codeOrKey ?? "");
4001
+ if (str === " ") return "SPACE";
4002
+ const raw = str.trim();
3980
4003
  if (!raw) return "";
3981
- if (raw === " ") return "SPACE";
3982
4004
  const up = raw.toUpperCase();
3983
4005
  if (up.length === 1 && up >= "A" && up <= "Z") return `KEY${up}`;
3984
4006
  if (up.length === 1 && up >= "0" && up <= "9") return `DIGIT${up}`;
@@ -3987,22 +4009,24 @@ function normalizeKeyToken(codeOrKey) {
3987
4009
  var KeyboardPlugin = class extends EventEmitter {
3988
4010
  win;
3989
4011
  getFrameSeq;
4012
+ getWriteFrameSeq;
3990
4013
  downCodes = /* @__PURE__ */ new Set();
3991
- pressedFrame = /* @__PURE__ */ new Map();
3992
- releasedFrame = /* @__PURE__ */ new Map();
4014
+ pressedUntil = /* @__PURE__ */ new Map();
4015
+ releasedUntil = /* @__PURE__ */ new Map();
3993
4016
  onKeyDown;
3994
4017
  onKeyUp;
3995
4018
  onBlur;
3996
- constructor(win, getFrameSeq = () => 0) {
4019
+ constructor(win, getFrameSeq = () => 0, getWriteFrameSeq = getFrameSeq) {
3997
4020
  super();
3998
4021
  this.win = win;
3999
4022
  this.getFrameSeq = getFrameSeq;
4023
+ this.getWriteFrameSeq = getWriteFrameSeq;
4000
4024
  this.onKeyDown = (e) => {
4001
4025
  const code = normalizeKeyToken(e.code || e.key);
4002
4026
  if (code) {
4003
4027
  if (!this.downCodes.has(code)) {
4004
4028
  this.downCodes.add(code);
4005
- this.pressedFrame.set(code, this.getFrameSeq());
4029
+ this.pressedUntil.set(code, this.getWriteFrameSeq());
4006
4030
  }
4007
4031
  }
4008
4032
  this.emit("keydown", e);
@@ -4010,7 +4034,7 @@ var KeyboardPlugin = class extends EventEmitter {
4010
4034
  };
4011
4035
  this.onKeyUp = (e) => {
4012
4036
  const code = normalizeKeyToken(e.code || e.key);
4013
- if (code && this.downCodes.delete(code)) this.releasedFrame.set(code, this.getFrameSeq());
4037
+ if (code && this.downCodes.delete(code)) this.releasedUntil.set(code, this.getWriteFrameSeq());
4014
4038
  this.emit("keyup", e);
4015
4039
  if (code) this.emit(`keyup-${code}`, e);
4016
4040
  };
@@ -4021,22 +4045,24 @@ var KeyboardPlugin = class extends EventEmitter {
4021
4045
  win.addEventListener("keyup", this.onKeyUp);
4022
4046
  win.addEventListener("blur", this.onBlur);
4023
4047
  }
4024
- /** Returns `true` while `codeOrKey` (e.g. `'KeyW'`, `'W'`, `'ArrowLeft'`, `'Space'`) is held down. */
4048
+ /** Returns `true` while `codeOrKey` (e.g. `'KeyW'`, `'W'`, `'ArrowLeft'`, `'Space'`, `' '`) is held down. */
4025
4049
  isDown(codeOrKey) {
4026
4050
  const code = normalizeKeyToken(codeOrKey);
4027
4051
  return code ? this.downCodes.has(code) : false;
4028
4052
  }
4029
- /** Returns `true` only on the simulation frame during which `codeOrKey` transitioned up -> down. */
4053
+ /** Returns `true` only through the simulation frame during which `codeOrKey` transitioned up -> down. */
4030
4054
  justPressed(codeOrKey) {
4031
4055
  const code = normalizeKeyToken(codeOrKey);
4032
4056
  if (!code) return false;
4033
- return this.pressedFrame.get(code) === this.getFrameSeq();
4057
+ const until = this.pressedUntil.get(code);
4058
+ return until !== void 0 && this.getFrameSeq() <= until;
4034
4059
  }
4035
- /** Returns `true` only on the simulation frame during which `codeOrKey` transitioned down -> up. */
4060
+ /** Returns `true` only through the simulation frame during which `codeOrKey` transitioned down -> up. */
4036
4061
  justReleased(codeOrKey) {
4037
4062
  const code = normalizeKeyToken(codeOrKey);
4038
4063
  if (!code) return false;
4039
- return this.releasedFrame.get(code) === this.getFrameSeq();
4064
+ const until = this.releasedUntil.get(code);
4065
+ return until !== void 0 && this.getFrameSeq() <= until;
4040
4066
  }
4041
4067
  /** Synthesize a deterministic key event from an `InputProvider` (headless timeline, replay, or Mod controller). */
4042
4068
  injectKey(type, codeOrKey, key) {
@@ -4054,8 +4080,8 @@ var KeyboardPlugin = class extends EventEmitter {
4054
4080
  }
4055
4081
  /** Release all currently held keys (called automatically on window blur). */
4056
4082
  resetKeys() {
4057
- const f = this.getFrameSeq();
4058
- for (const c of this.downCodes) this.releasedFrame.set(c, f);
4083
+ const f = this.getWriteFrameSeq();
4084
+ for (const c of this.downCodes) this.releasedUntil.set(c, f);
4059
4085
  this.downCodes.clear();
4060
4086
  }
4061
4087
  destroy() {
@@ -4063,8 +4089,8 @@ var KeyboardPlugin = class extends EventEmitter {
4063
4089
  this.win.removeEventListener("keyup", this.onKeyUp);
4064
4090
  this.win.removeEventListener("blur", this.onBlur);
4065
4091
  this.downCodes.clear();
4066
- this.pressedFrame.clear();
4067
- this.releasedFrame.clear();
4092
+ this.pressedUntil.clear();
4093
+ this.releasedUntil.clear();
4068
4094
  this.removeAllListeners();
4069
4095
  }
4070
4096
  };
@@ -4083,7 +4109,7 @@ var InputPlugin = class extends EventEmitter {
4083
4109
  coalescedScratch = [];
4084
4110
  resizeObserver = null;
4085
4111
  lastTouchMs = -1e9;
4086
- constructor(canvas, win, getCamera, config = {}, getFrameSeq = () => 0) {
4112
+ constructor(canvas, win, getCamera, config = {}, getFrameSeq = () => 0, getWriteFrameSeq = getFrameSeq) {
4087
4113
  super();
4088
4114
  this.canvas = canvas;
4089
4115
  this.win = win;
@@ -4101,7 +4127,7 @@ var InputPlugin = class extends EventEmitter {
4101
4127
  pointers: [this.mousePointer, ...this.touchPointers],
4102
4128
  canvas
4103
4129
  };
4104
- this.keyboard = config.keyboard === false ? null : new KeyboardPlugin(win, getFrameSeq);
4130
+ this.keyboard = config.keyboard === false ? null : new KeyboardPlugin(win, getFrameSeq, getWriteFrameSeq);
4105
4131
  const preventDown = config.mouse?.preventDefaultDown ?? false;
4106
4132
  const preventMove = config.mouse?.preventDefaultMove ?? false;
4107
4133
  const preventUp = config.mouse?.preventDefaultUp ?? false;
@@ -5120,6 +5146,7 @@ var Game = class {
5120
5146
  pendingDestroy = false;
5121
5147
  destroyed = false;
5122
5148
  ownedCanvas = false;
5149
+ inStep = false;
5123
5150
  constructor(config = {}) {
5124
5151
  this.config = config;
5125
5152
  const fallbackDoc = typeof document !== "undefined" ? document : void 0;
@@ -5179,7 +5206,7 @@ var Game = class {
5179
5206
  this.scale = new ScaleManager(this.canvas, this.renderer, width, height, zoom);
5180
5207
  this.cache = { json: new JsonCache() };
5181
5208
  this.scene = new SceneManager(this);
5182
- this.input = new InputPlugin(this.canvas, this.win, () => this.scene.getPrimaryCamera(), config.input, () => this.clock.frameSeq);
5209
+ this.input = new InputPlugin(this.canvas, this.win, () => this.scene.getPrimaryCamera(), config.input, () => this.clock.frameSeq, () => this.inStep ? this.clock.frameSeq : this.clock.frameSeq + 1);
5183
5210
  this.kernel = new StageKernel(this);
5184
5211
  if (config.plugins) for (let i = 0; i < config.plugins.length; i++) this.kernel.use(config.plugins[i]);
5185
5212
  this.loop = new GameLoop(this, this.win);
@@ -5199,34 +5226,46 @@ var Game = class {
5199
5226
  /** Advance simulation, tweens, kernel plugins, and camera follow by one deterministic tick WITHOUT rendering pixels. */
5200
5227
  stepSimOnly(time, delta) {
5201
5228
  if (this.pendingDestroy || this.destroyed || this.isPaused) return false;
5202
- this.clock.advance(time, delta);
5203
- this.kernel._prestep(time, delta);
5204
- this.events.emit("prestep", time, delta);
5205
- const scenes = this.scene.scenes;
5206
- for (let i = 0; i < scenes.length; i++) {
5207
- const sc = scenes[i];
5208
- if (sc.sys.settings.status === Scenes.RUNNING) {
5209
- sc.events.emit("preupdate", time, delta);
5210
- if (sc.tweens.hasActive) sc.tweens.step(this.clock.lastDeltaMs);
5211
- sc.update?.(time, delta);
5212
- this.kernel._updateScene(sc, time, delta);
5213
- sc.cameras.main.stepFollow(this.clock.lastDeltaMs);
5214
- sc.events.emit("update", time, delta);
5215
- sc.events.emit("postupdate", time, delta);
5229
+ const prevInStep = this.inStep;
5230
+ this.inStep = true;
5231
+ try {
5232
+ this.clock.advance(time, delta);
5233
+ this.kernel._prestep(time, delta);
5234
+ this.events.emit("prestep", time, delta);
5235
+ const scenes = this.scene.scenes;
5236
+ for (let i = 0; i < scenes.length; i++) {
5237
+ const sc = scenes[i];
5238
+ if (sc.sys.settings.status === Scenes.RUNNING) {
5239
+ sc.events.emit("preupdate", time, delta);
5240
+ if (sc.tweens.hasActive) sc.tweens.step(this.clock.lastDeltaMs);
5241
+ sc.update?.(time, delta);
5242
+ this.kernel._updateScene(sc, time, delta);
5243
+ sc.cameras.main.stepFollow(this.clock.lastDeltaMs);
5244
+ sc.events.emit("update", time, delta);
5245
+ sc.events.emit("postupdate", time, delta);
5246
+ }
5216
5247
  }
5248
+ return true;
5249
+ } finally {
5250
+ this.inStep = prevInStep;
5217
5251
  }
5218
- return true;
5219
5252
  }
5220
5253
  step(time, delta) {
5221
- if (!this.stepSimOnly(time, delta)) return;
5222
- const scenes = this.scene.scenes;
5223
- this.events.emit("prerender", this.renderer);
5224
- for (let i = 0; i < scenes.length; i++) {
5225
- const sc = scenes[i];
5226
- if (sc.sys.settings.status === Scenes.RUNNING) this.renderer.render(sc._displayList, sc.cameras.main);
5254
+ const prevInStep = this.inStep;
5255
+ this.inStep = true;
5256
+ try {
5257
+ if (!this.stepSimOnly(time, delta)) return;
5258
+ const scenes = this.scene.scenes;
5259
+ this.events.emit("prerender", this.renderer);
5260
+ for (let i = 0; i < scenes.length; i++) {
5261
+ const sc = scenes[i];
5262
+ if (sc.sys.settings.status === Scenes.RUNNING) this.renderer.render(sc._displayList, sc.cameras.main);
5263
+ }
5264
+ this.kernel._postrender(this.renderer);
5265
+ this.events.emit("postrender", this.renderer);
5266
+ } finally {
5267
+ this.inStep = prevInStep;
5227
5268
  }
5228
- this.kernel._postrender(this.renderer);
5229
- this.events.emit("postrender", this.renderer);
5230
5269
  }
5231
5270
  destroy(removeCanvas = false) {
5232
5271
  if (this.destroyed) return;
@@ -905,6 +905,7 @@ declare class RendererGl extends EventEmitter implements GlTextureHost {
905
905
  private readonly maskWorldMat;
906
906
  private readonly bindTextSlot0;
907
907
  private activeFbo;
908
+ private activeFboTex;
908
909
  private instProgram;
909
910
  private instUres;
910
911
  private instVao;
@@ -936,8 +937,10 @@ declare class RendererGl extends EventEmitter implements GlTextureHost {
936
937
  ensureGlTexture(src: TextureSource): WebGLTexture | null;
937
938
  getDummyGlTexture(): WebGLTexture | null;
938
939
  private ensureBatchState;
939
- /** Full state restore for external callers that may have mutated viewport/blend/textures/pixelStore/FBO directly. */
940
+ /** Full state restore for external callers that may have mutated viewport/blend/cull/depth/stencil/colorMask/textures/pixelStore/FBO directly. */
940
941
  restoreState(): void;
942
+ /** Evict `tex` (and populate any post-restore `null` slots with `dummyTex`) so binding its FBO never forms a GL feedback loop. */
943
+ private evictTextureFromUnits;
941
944
  private setBlend;
942
945
  private assignTextureUnit;
943
946
  private reserve;
@@ -988,6 +991,13 @@ declare class Renderer2D extends EventEmitter {
988
991
  private tintCtx;
989
992
  private readonly maskWorldMat;
990
993
  private readonly pathCache;
994
+ private curDrawCalls;
995
+ private curFlushes;
996
+ private curQuads;
997
+ private curTris;
998
+ private curSdfPanels;
999
+ private curMsdfIcons;
1000
+ private readonly lastStats;
991
1001
  constructor(canvas: HTMLCanvasElement, width: number, height: number, existingCtx?: CanvasRenderingContext2D | null);
992
1002
  stats(): {
993
1003
  drawCalls: number;
@@ -1196,18 +1206,19 @@ declare class Pointer {
1196
1206
  declare class KeyboardPlugin extends EventEmitter {
1197
1207
  private readonly win;
1198
1208
  private readonly getFrameSeq;
1209
+ private readonly getWriteFrameSeq;
1199
1210
  private readonly downCodes;
1200
- private readonly pressedFrame;
1201
- private readonly releasedFrame;
1211
+ private readonly pressedUntil;
1212
+ private readonly releasedUntil;
1202
1213
  private readonly onKeyDown;
1203
1214
  private readonly onKeyUp;
1204
1215
  private readonly onBlur;
1205
- constructor(win: Window, getFrameSeq?: () => number);
1206
- /** Returns `true` while `codeOrKey` (e.g. `'KeyW'`, `'W'`, `'ArrowLeft'`, `'Space'`) is held down. */
1216
+ constructor(win: Window, getFrameSeq?: () => number, getWriteFrameSeq?: () => number);
1217
+ /** Returns `true` while `codeOrKey` (e.g. `'KeyW'`, `'W'`, `'ArrowLeft'`, `'Space'`, `' '`) is held down. */
1207
1218
  isDown(codeOrKey: string): boolean;
1208
- /** Returns `true` only on the simulation frame during which `codeOrKey` transitioned up -> down. */
1219
+ /** Returns `true` only through the simulation frame during which `codeOrKey` transitioned up -> down. */
1209
1220
  justPressed(codeOrKey: string): boolean;
1210
- /** Returns `true` only on the simulation frame during which `codeOrKey` transitioned down -> up. */
1221
+ /** Returns `true` only through the simulation frame during which `codeOrKey` transitioned down -> up. */
1211
1222
  justReleased(codeOrKey: string): boolean;
1212
1223
  /** Synthesize a deterministic key event from an `InputProvider` (headless timeline, replay, or Mod controller). */
1213
1224
  injectKey(type: 'keydown' | 'keyup', codeOrKey: string, key?: string): void;
@@ -1233,7 +1244,7 @@ declare class InputPlugin extends EventEmitter {
1233
1244
  private readonly coalescedScratch;
1234
1245
  private resizeObserver;
1235
1246
  private lastTouchMs;
1236
- constructor(canvas: HTMLCanvasElement, win: Window, getCamera: () => Camera | null, config?: InputConfig, getFrameSeq?: () => number);
1247
+ constructor(canvas: HTMLCanvasElement, win: Window, getCamera: () => Camera | null, config?: InputConfig, getFrameSeq?: () => number, getWriteFrameSeq?: () => number);
1237
1248
  setPollAlways(): this;
1238
1249
  destroy(): void;
1239
1250
  }
@@ -1798,6 +1809,7 @@ declare class Game {
1798
1809
  pendingDestroy: boolean;
1799
1810
  private destroyed;
1800
1811
  private ownedCanvas;
1812
+ private inStep;
1801
1813
  constructor(config?: GameConfig);
1802
1814
  /** Advance simulation, tweens, kernel plugins, and camera follow by one deterministic tick WITHOUT rendering pixels. */
1803
1815
  stepSimOnly(time: number, delta: number): boolean;
@@ -1,4 +1,4 @@
1
- import { I as SceneDigestOptions, M as SceneDigest, T as StagePlugin, f as SceneInput, n as EngineClockSnapshot, r as Game, u as Scene } from "./game-CfUZiazr.js";
1
+ import { I as SceneDigestOptions, M as SceneDigest, T as StagePlugin, f as SceneInput, n as EngineClockSnapshot, r as Game, u as Scene } from "./game-DWELKTnB.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;
package/dist/headless.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./types-DRFB0Klc.js";
2
- import { n as Game } from "./game-C5za2LGl.js";
2
+ import { n as Game } from "./game-B8UlnEB_.js";
3
3
  import { buildSceneDigest } from "./trace.js";
4
4
  // src/headless.ts
5
5
  function createVirtualDomHost(createCanvas, width, height) {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as WebGpuCanvasContextLike, $t as FilterMode, A as createInputReplay, At as RectangleObject, B as SceneDigestSurfaceSource, Bt as GlTextureHost, C as StageInputEvent, Ct as MsdfIconConfig, D as TimelineDragOptions, Dt as PanelOpenSide, E as TimelineClickOptions, Et as PanelObject, F as SceneDigestNode, Ft as Camera, G as InputPlugin, Gt as TextureManager, H as buildSceneDigest, Ht as Texture, I as SceneDigestOptions, It as CameraFollowOptions, J as PointerSample, Jt as BLACK_RGB, K as KeyboardPlugin, Kt as TextureSource, L as SceneDigestOverlayStats, Lt as HiDpiScaleLike, M as SceneDigest, Mt as TextObject, N as SceneDigestActiveFocus, Nt as TextStyleConfig, O as TimelineKeyOptions, Ot as PanelStyleConfig, P as SceneDigestEngineSandbox, Pt as TileSpriteObject, Q as WebGpuBootstrapResult, Qt as EventEmitter, R as SceneDigestSandbox, Rt as CanvasTexture, S as RecordedInputEntry, St as InstancedColumns, T as StagePlugin, Tt as NineSliceObject, U as sanitizeTrackToken, Ut as TextureImageOptions, V as SceneDigestSurfaces, Vt as SpriteSheetConfig, W as InputConfig, Wt as TextureImageSource, X as RendererWebGpuOptions, Xt as BlendModes, Y as RendererWebGpu, Yt as BlendMode, Z as RequestWebGpuOptions, Zt as CANVAS, _ as InputProvider, _t as DisplayObjectType, a as GameLoop, an as Scale, at as RendererStats, b as InputTimelineOptions, bt as ImageObject, c as LoaderPlugin, cn as TintModes, ct as BlitterObject, d as SceneCtor, dn as WHITE_RGB, dt as ContainerFiltersShim, en as FilterModeValue, et as WebGpuDeviceLike, f as SceneInput, fn as WorldView2D, ft as CustomPassCallback, g as ActionMap, gn as rgbToCss, gt as DisplayObject, h as StageRenderer, hn as parseColor, ht as DisplayList, i as GameConfig$1, in as RgbaColor, it as RendererGlOptions, j as createInputTimeline, jt as SceneHostLike, k as createInputRecorder, kt as RectClipMask, l as ScaleManager, ln as WEBGL, lt as Bob$1, m as SceneManager, mn as packColorAbgr, mt as CustomPassOptions, n as EngineClockSnapshot, nn as Matrix2D, nt as Renderer2D, o as GameObjectFactory, on as Scenes, ot as Stage2DCustomImageHandler, p as SceneLifecycleStats, pn as createMatrix2D, pt as CustomPassObject, q as Pointer, qt as AUTO, r as Game, rn as Rect2D, rt as RendererGl, s as JsonCache, sn as TintMode, st as StageRenderTarget, t as EngineClock, tn as HEX_MASK, tt as requestWebGpuDevice, u as Scene, un as WEBGPU, ut as Container, v as InputRecorderPlugin, vt as DisplaySemantics, w as StageKernel, wt as MsdfIconObject, x as InputTimelinePlugin, xt as InstancedBatchObject, y as InputTargetSpec, yt as Graphics, z as SceneDigestSurfaceEntry, zt as Frame } from "./game-CfUZiazr.js";
1
+ import { $ as WebGpuCanvasContextLike, $t as FilterMode, A as createInputReplay, At as RectangleObject, B as SceneDigestSurfaceSource, Bt as GlTextureHost, C as StageInputEvent, Ct as MsdfIconConfig, D as TimelineDragOptions, Dt as PanelOpenSide, E as TimelineClickOptions, Et as PanelObject, F as SceneDigestNode, Ft as Camera, G as InputPlugin, Gt as TextureManager, H as buildSceneDigest, Ht as Texture, I as SceneDigestOptions, It as CameraFollowOptions, J as PointerSample, Jt as BLACK_RGB, K as KeyboardPlugin, Kt as TextureSource, L as SceneDigestOverlayStats, Lt as HiDpiScaleLike, M as SceneDigest, Mt as TextObject, N as SceneDigestActiveFocus, Nt as TextStyleConfig, O as TimelineKeyOptions, Ot as PanelStyleConfig, P as SceneDigestEngineSandbox, Pt as TileSpriteObject, Q as WebGpuBootstrapResult, Qt as EventEmitter, R as SceneDigestSandbox, Rt as CanvasTexture, S as RecordedInputEntry, St as InstancedColumns, T as StagePlugin, Tt as NineSliceObject, U as sanitizeTrackToken, Ut as TextureImageOptions, V as SceneDigestSurfaces, Vt as SpriteSheetConfig, W as InputConfig, Wt as TextureImageSource, X as RendererWebGpuOptions, Xt as BlendModes, Y as RendererWebGpu, Yt as BlendMode, Z as RequestWebGpuOptions, Zt as CANVAS, _ as InputProvider, _t as DisplayObjectType, a as GameLoop, an as Scale, at as RendererStats, b as InputTimelineOptions, bt as ImageObject, c as LoaderPlugin, cn as TintModes, ct as BlitterObject, d as SceneCtor, dn as WHITE_RGB, dt as ContainerFiltersShim, en as FilterModeValue, et as WebGpuDeviceLike, f as SceneInput, fn as WorldView2D, ft as CustomPassCallback, g as ActionMap, gn as rgbToCss, gt as DisplayObject, h as StageRenderer, hn as parseColor, ht as DisplayList, i as GameConfig$1, in as RgbaColor, it as RendererGlOptions, j as createInputTimeline, jt as SceneHostLike, k as createInputRecorder, kt as RectClipMask, l as ScaleManager, ln as WEBGL, lt as Bob$1, m as SceneManager, mn as packColorAbgr, mt as CustomPassOptions, n as EngineClockSnapshot, nn as Matrix2D, nt as Renderer2D, o as GameObjectFactory, on as Scenes, ot as Stage2DCustomImageHandler, p as SceneLifecycleStats, pn as createMatrix2D, pt as CustomPassObject, q as Pointer, qt as AUTO, r as Game, rn as Rect2D, rt as RendererGl, s as JsonCache, sn as TintMode, st as StageRenderTarget, t as EngineClock, tn as HEX_MASK, tt as requestWebGpuDevice, u as Scene, un as WEBGPU, ut as Container, v as InputRecorderPlugin, vt as DisplaySemantics, w as StageKernel, wt as MsdfIconObject, x as InputTimelinePlugin, xt as InstancedBatchObject, y as InputTargetSpec, yt as Graphics, z as SceneDigestSurfaceEntry, zt as Frame } from "./game-DWELKTnB.js";
2
2
  import { FlexAlign, FlexContainerSpec, FlexDir, FlexItemRect, FlexItemSpec, FlexJustify, FlexPadding, FlexResult, WrapContainerSpec, WrapItemRect, WrapItemSpec, WrapJustify, WrapResult, computeFlexLayout, computeWrapLayout, resolvePadding } from "./flex.js";
3
3
  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";
4
4
  import { JoystickDpad, JoystickDpadOptions, JoystickState, JoystickVector, JoystickViewport, JoystickZone, JoystickZonePredicate, JoystickZoneRect, VirtualJoystick, VirtualJoystickMode, VirtualJoystickOptions, VirtualJoystickStyle, clampJoystickOrigin, computeJoystickVector, isInJoystickZone, pullJoystickOrigin, quantizeJoystickDpad } from "./joystick.js";
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
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-DRFB0Klc.js";
2
- import { S as TextureSource, _ as Camera, a as JsonCache, b as Texture, 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 CanvasTexture, x as TextureManager, y as Frame } from "./game-C5za2LGl.js";
3
- import { _ as TileSpriteObject, a as Container, c as DisplayObject, d as InstancedBatchObject, f as MsdfIconObject, g as TextObject, h as RectangleObject, i as BlitterObject, l as Graphics, m as PanelObject, n as requestWebGpuDevice, o as CustomPassObject, p as NineSliceObject, r as Renderer2D, s as DisplayList, t as RendererWebGpu, u as ImageObject } from "./renderer-webgpu-BE6fTBzo.js";
2
+ import { S as TextureSource, _ as Camera, a as JsonCache, b as Texture, 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 CanvasTexture, x as TextureManager, y as Frame } from "./game-B8UlnEB_.js";
3
+ import { _ as TileSpriteObject, a as Container, c as DisplayObject, d as InstancedBatchObject, f as MsdfIconObject, g as TextObject, h as RectangleObject, i as BlitterObject, l as Graphics, m as PanelObject, n as requestWebGpuDevice, o as CustomPassObject, p as NineSliceObject, r as Renderer2D, s as DisplayList, t as RendererWebGpu, u as ImageObject } from "./renderer-webgpu-Djk7FayG.js";
4
4
  import { ActionMap, StageKernel, createInputRecorder, createInputReplay, createInputTimeline } from "./kernel.js";
5
5
  import { buildSceneDigest, sanitizeTrackToken } from "./trace.js";
6
6
  import { computeFlexLayout, computeWrapLayout, resolvePadding } from "./flex.js";
@@ -1,4 +1,4 @@
1
- import { Et as PanelObject, q as Pointer, u as Scene, ut as Container } from "./game-CfUZiazr.js";
1
+ import { Et as PanelObject, q as Pointer, u as Scene, ut as Container } from "./game-DWELKTnB.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,2 +1,2 @@
1
- import { A as createInputReplay, C as StageInputEvent, D as TimelineDragOptions, E as TimelineClickOptions, O as TimelineKeyOptions, S as RecordedInputEntry, T as StagePlugin, _ as InputProvider, b as InputTimelineOptions, g as ActionMap, j as createInputTimeline, k as createInputRecorder, v as InputRecorderPlugin, w as StageKernel, x as InputTimelinePlugin, y as InputTargetSpec } from "./game-CfUZiazr.js";
1
+ import { A as createInputReplay, C as StageInputEvent, D as TimelineDragOptions, E as TimelineClickOptions, O as TimelineKeyOptions, S as RecordedInputEntry, T as StagePlugin, _ as InputProvider, b as InputTimelineOptions, g as ActionMap, j as createInputTimeline, k as createInputRecorder, v as InputRecorderPlugin, w as StageKernel, x as InputTimelinePlugin, y as InputTargetSpec } from "./game-DWELKTnB.js";
2
2
  export { ActionMap, InputProvider, InputRecorderPlugin, InputTargetSpec, InputTimelineOptions, InputTimelinePlugin, RecordedInputEntry, StageInputEvent, StageKernel, StagePlugin, TimelineClickOptions, TimelineDragOptions, TimelineKeyOptions, createInputRecorder, createInputReplay, createInputTimeline };
@@ -1,4 +1,4 @@
1
- import { bt as ImageObject, jt as SceneHostLike, pt as CustomPassObject } from "./game-CfUZiazr.js";
1
+ import { bt as ImageObject, jt as SceneHostLike, pt as CustomPassObject } from "./game-DWELKTnB.js";
2
2
  export type DayPhase = 'day' | 'dusk' | 'night';
3
3
  export interface DayNightConfig {
4
4
  dayLengthMs?: number;
@@ -1,4 +1,4 @@
1
- import { gt as DisplayObject, jt as SceneHostLike, ut as Container } from "./game-CfUZiazr.js";
1
+ import { gt as DisplayObject, jt as SceneHostLike, ut as Container } from "./game-DWELKTnB.js";
2
2
  export interface Camera25DConfig {
3
3
  viewportWidth: number;
4
4
  viewportHeight: number;
@@ -1488,6 +1488,27 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1488
1488
  tintCtx = null;
1489
1489
  maskWorldMat = createMatrix2D();
1490
1490
  pathCache = /* @__PURE__ */ new Map();
1491
+ curDrawCalls = 0;
1492
+ curFlushes = 0;
1493
+ curQuads = 0;
1494
+ curTris = 0;
1495
+ curSdfPanels = 0;
1496
+ curMsdfIcons = 0;
1497
+ lastStats = {
1498
+ drawCalls: 0,
1499
+ flushes: 0,
1500
+ quads: 0,
1501
+ tris: 0,
1502
+ culled: 0,
1503
+ texBinds: 0,
1504
+ batchMaxUnits: 0,
1505
+ sdfPanels: 0,
1506
+ sdfDraws: 0,
1507
+ msdfIcons: 0,
1508
+ msdfDraws: 0,
1509
+ pixelAaIcons: 0,
1510
+ pixelAaDraws: 0
1511
+ };
1491
1512
  constructor(canvas, width, height, existingCtx) {
1492
1513
  super();
1493
1514
  this.canvas = canvas;
@@ -1498,21 +1519,7 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1498
1519
  this.ctx = ctx;
1499
1520
  }
1500
1521
  stats() {
1501
- return {
1502
- drawCalls: 0,
1503
- flushes: 0,
1504
- quads: 0,
1505
- tris: 0,
1506
- culled: 0,
1507
- texBinds: 0,
1508
- batchMaxUnits: 0,
1509
- sdfPanels: 0,
1510
- sdfDraws: 0,
1511
- msdfIcons: 0,
1512
- msdfDraws: 0,
1513
- pixelAaIcons: 0,
1514
- pixelAaDraws: 0
1515
- };
1522
+ return this.lastStats;
1516
1523
  }
1517
1524
  resize(width, height) {
1518
1525
  const w = Math.max(1, Math.round(width));
@@ -1591,10 +1598,16 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1591
1598
  const tinted = this.getTintedSource(srcImg, sx, sy, sw, sh, img.tint, img.tintMode === TintModes.FILL);
1592
1599
  if (tinted) {
1593
1600
  ctx.drawImage(tinted, 0, 0, Math.ceil(sw), Math.ceil(sh), dx, dy, dw, dh);
1601
+ this.curDrawCalls++;
1602
+ this.curQuads++;
1603
+ this.curTris += 2;
1594
1604
  return;
1595
1605
  }
1596
1606
  }
1597
1607
  ctx.drawImage(srcImg, sx, sy, sw, sh, dx, dy, dw, dh);
1608
+ this.curDrawCalls++;
1609
+ this.curQuads++;
1610
+ this.curTris += 2;
1598
1611
  }
1599
1612
  renderNineSlice(ns, ctx) {
1600
1613
  const frame = ns.frame;
@@ -1638,6 +1651,7 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1638
1651
  -oy + h - B,
1639
1652
  -oy + h
1640
1653
  ];
1654
+ let patches = 0;
1641
1655
  for (let r = 0; r < 3; r++) {
1642
1656
  const sh = sys[r + 1] - sys[r], dh = dys[r + 1] - dys[r];
1643
1657
  if (sh <= 0 || dh <= 0) continue;
@@ -1645,8 +1659,14 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1645
1659
  const sw = sxs[c + 1] - sxs[c], dw = dxs[c + 1] - dxs[c];
1646
1660
  if (sw <= 0 || dw <= 0) continue;
1647
1661
  ctx.drawImage(srcImg, sxs[c], sys[r], sw, sh, dxs[c], dys[r], dw, dh);
1662
+ patches++;
1648
1663
  }
1649
1664
  }
1665
+ if (patches > 0) {
1666
+ this.curDrawCalls++;
1667
+ this.curQuads += patches;
1668
+ this.curTris += patches * 2;
1669
+ }
1650
1670
  }
1651
1671
  renderTileSprite(ts, ctx) {
1652
1672
  const frame = ts.frame;
@@ -1667,6 +1687,7 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1667
1687
  baseSy = 0;
1668
1688
  }
1669
1689
  }
1690
+ let tiles = 0;
1670
1691
  for (let y = 0; y < ts.height;) {
1671
1692
  const ty = (y + offY) % fh;
1672
1693
  const dh = Math.min(fh - ty, ts.height - y);
@@ -1674,19 +1695,32 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1674
1695
  const tx = (x + offX) % fw;
1675
1696
  const dw = Math.min(fw - tx, ts.width - x);
1676
1697
  ctx.drawImage(drawSrc, baseSx + tx, baseSy + ty, dw, dh, -ox + x, -oy + y, dw, dh);
1698
+ tiles++;
1677
1699
  x += dw;
1678
1700
  }
1679
1701
  y += dh;
1680
1702
  }
1703
+ if (tiles > 0) {
1704
+ this.curDrawCalls++;
1705
+ this.curQuads += tiles;
1706
+ this.curTris += tiles * 2;
1707
+ }
1681
1708
  }
1682
1709
  renderRectangle(r, ctx) {
1683
1710
  if (r.fillAlpha <= 0 || r.width <= 0 || r.height <= 0) return;
1684
1711
  ctx.fillStyle = rgbToCss(r.fillColor, r.fillAlpha);
1685
1712
  ctx.fillRect(-r.displayOriginX, -r.displayOriginY, r.width, r.height);
1713
+ this.curDrawCalls++;
1714
+ this.curQuads++;
1715
+ this.curTris += 2;
1686
1716
  }
1687
1717
  renderPanel(p, ctx) {
1688
1718
  const w = p.width, h = p.height;
1689
1719
  if (w <= 0 || h <= 0) return;
1720
+ this.curDrawCalls++;
1721
+ this.curQuads++;
1722
+ this.curTris += 2;
1723
+ this.curSdfPanels++;
1690
1724
  const x = -p.displayOriginX, y = -p.displayOriginY;
1691
1725
  const bw = Math.max(0, Math.min(p.borderWidth, Math.min(w, h) * .5));
1692
1726
  if (bw > 0 && p.openSide !== 0) {
@@ -1757,6 +1791,10 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1757
1791
  ctx.fill(p2d);
1758
1792
  }
1759
1793
  ctx.restore();
1794
+ this.curDrawCalls++;
1795
+ this.curQuads++;
1796
+ this.curTris += 2;
1797
+ this.curMsdfIcons++;
1760
1798
  }
1761
1799
  renderText(txt, ctx) {
1762
1800
  const cv = txt.ensureCanvas();
@@ -1765,6 +1803,9 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1765
1803
  const ox = txt.displayOriginX, oy = txt.displayOriginY;
1766
1804
  if (!txt.isCropped) {
1767
1805
  ctx.drawImage(cv, 0, 0, cv.width, cv.height, -ox, -oy, txt.width, txt.height);
1806
+ this.curDrawCalls++;
1807
+ this.curQuads++;
1808
+ this.curTris += 2;
1768
1809
  return;
1769
1810
  }
1770
1811
  const fw = txt.frame.cutWidth || cv.width || 1;
@@ -1777,9 +1818,13 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1777
1818
  const resX = fw / txt.width;
1778
1819
  const resY = fh / txt.height;
1779
1820
  ctx.drawImage(cv, rx, ry, rw, rh, -ox + rx / resX, -oy + ry / resY, rw / resX, rh / resY);
1821
+ this.curDrawCalls++;
1822
+ this.curQuads++;
1823
+ this.curTris += 2;
1780
1824
  }
1781
1825
  renderGraphics(g, ctx) {
1782
1826
  if (g.opLen === 0) return;
1827
+ this.curDrawCalls++;
1783
1828
  let fillRgb = WHITE_RGB, fillA = 1;
1784
1829
  let lineW = 1, lineRgb = WHITE_RGB, lineA = 1;
1785
1830
  const ops = g.ops;
@@ -1935,26 +1980,59 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1935
1980
  if (!cols || cols.count <= 0) return;
1936
1981
  const baseAlpha = ctx.globalAlpha;
1937
1982
  const n = Math.min(cols.count, batch.maxCount, cols.x.length, cols.y.length);
1983
+ let vis = 0;
1984
+ let lastTintImg = null;
1985
+ let lastCutX = -1, lastCutY = -1, lastCutW = -1, lastCutH = -1, lastRgb = -1;
1986
+ let cachedTinted = null;
1938
1987
  for (let i = 0; i < n; i++) {
1939
1988
  const s = cols.order ? cols.order[i] : i;
1940
1989
  const a = baseAlpha * (cols.alpha ? cols.alpha[s] : 1);
1941
1990
  if (a <= 0) continue;
1942
1991
  const fr = cols.frameIndex ? batch.texture.get(cols.frameIndex[s]) : batch.defaultFrame;
1992
+ if (!fr || fr.width <= 0 || fr.height <= 0) continue;
1943
1993
  const sx = cols.scaleX ? cols.scaleX[s] : 1;
1944
1994
  const sy = cols.scaleY ? cols.scaleY[s] : sx;
1945
1995
  const rot = cols.rotation ? cols.rotation[s] : 0;
1996
+ const rgb = cols.tint ? cols.tint[s] ?? 0xffffff : WHITE_RGB;
1946
1997
  const px = cols.x[s];
1947
1998
  const py = cols.y[s];
1999
+ const dx = -fr.width * batch.originX;
2000
+ const dy = -fr.height * batch.originY;
2001
+ const srcImg = fr.source.image;
1948
2002
  ctx.save();
1949
2003
  ctx.globalAlpha = a;
1950
2004
  ctx.imageSmoothingEnabled = fr.source.filterMode !== FilterMode.NEAREST;
1951
2005
  ctx.translate(px, py);
1952
2006
  if (rot !== 0) ctx.rotate(rot);
1953
2007
  if (sx !== 1 || sy !== 1) ctx.scale(sx, sy);
1954
- ctx.drawImage(fr.source.image, fr.cutX, fr.cutY, fr.cutWidth, fr.cutHeight, -fr.width * batch.originX, -fr.height * batch.originY, fr.width, fr.height);
2008
+ if (rgb !== 0xffffff && fr.cutWidth > 0 && fr.cutHeight > 0) {
2009
+ if (srcImg !== lastTintImg || fr.cutX !== lastCutX || fr.cutY !== lastCutY || fr.cutWidth !== lastCutW || fr.cutHeight !== lastCutH || rgb !== lastRgb) {
2010
+ cachedTinted = this.getTintedSource(srcImg, fr.cutX, fr.cutY, fr.cutWidth, fr.cutHeight, rgb, false);
2011
+ lastTintImg = srcImg;
2012
+ lastCutX = fr.cutX;
2013
+ lastCutY = fr.cutY;
2014
+ lastCutW = fr.cutWidth;
2015
+ lastCutH = fr.cutHeight;
2016
+ lastRgb = rgb;
2017
+ }
2018
+ if (cachedTinted) {
2019
+ ctx.drawImage(cachedTinted, 0, 0, Math.ceil(fr.cutWidth), Math.ceil(fr.cutHeight), dx, dy, fr.width, fr.height);
2020
+ ctx.restore();
2021
+ vis++;
2022
+ continue;
2023
+ }
2024
+ }
2025
+ ctx.drawImage(srcImg, fr.cutX, fr.cutY, fr.cutWidth, fr.cutHeight, dx, dy, fr.width, fr.height);
1955
2026
  ctx.restore();
2027
+ vis++;
1956
2028
  }
1957
2029
  ctx.globalAlpha = baseAlpha;
2030
+ if (vis > 0) {
2031
+ this.curDrawCalls++;
2032
+ this.curFlushes++;
2033
+ this.curQuads += vis;
2034
+ this.curTris += vis * 2;
2035
+ }
1958
2036
  }
1959
2037
  /** Create an offscreen Canvas2D render target backed by a registered Stage `Texture` (`key`). */
1960
2038
  createRenderTarget(key, width, height, textures, filterMode = FilterMode.LINEAR) {
@@ -1995,6 +2073,7 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1995
2073
  renderBlitter(blitter, ctx) {
1996
2074
  const list = blitter.children.list;
1997
2075
  const baseAlpha = ctx.globalAlpha;
2076
+ let vis = 0;
1998
2077
  for (let i = 0; i < list.length; i++) {
1999
2078
  const bob = list[i];
2000
2079
  if (!bob.visible || bob.alpha <= 0) continue;
@@ -2002,8 +2081,14 @@ var Renderer2D = class Renderer2D extends EventEmitter {
2002
2081
  ctx.imageSmoothingEnabled = frame.source.filterMode !== FilterMode.NEAREST;
2003
2082
  ctx.globalAlpha = baseAlpha * bob.alpha;
2004
2083
  ctx.drawImage(frame.source.image, frame.cutX, frame.cutY, frame.cutWidth, frame.cutHeight, bob.x, bob.y, frame.width, frame.height);
2084
+ vis++;
2005
2085
  }
2006
2086
  ctx.globalAlpha = baseAlpha;
2087
+ if (vis > 0) {
2088
+ this.curDrawCalls++;
2089
+ this.curQuads += vis;
2090
+ this.curTris += vis * 2;
2091
+ }
2007
2092
  }
2008
2093
  renderNode(obj, camera, ctx, isRoot) {
2009
2094
  if (!obj.visible || obj.alpha <= 0) return;
@@ -2090,6 +2175,12 @@ var Renderer2D = class Renderer2D extends EventEmitter {
2090
2175
  ctx.restore();
2091
2176
  }
2092
2177
  render(displayList, camera) {
2178
+ this.curDrawCalls = 0;
2179
+ this.curFlushes = 0;
2180
+ this.curQuads = 0;
2181
+ this.curTris = 0;
2182
+ this.curSdfPanels = 0;
2183
+ this.curMsdfIcons = 0;
2093
2184
  camera.syncMetrics();
2094
2185
  const ctx = this.ctx;
2095
2186
  ctx.setTransform(1, 0, 0, 1, 0, 0);
@@ -2104,6 +2195,14 @@ var Renderer2D = class Renderer2D extends EventEmitter {
2104
2195
  ctx.globalAlpha = camera.alpha;
2105
2196
  const list = displayList.sorted();
2106
2197
  for (let i = 0; i < list.length; i++) this.renderNode(list[i], camera, ctx, true);
2198
+ this.lastStats.drawCalls = this.curDrawCalls;
2199
+ this.lastStats.flushes = this.curFlushes;
2200
+ this.lastStats.quads = this.curQuads;
2201
+ this.lastStats.tris = this.curTris;
2202
+ this.lastStats.sdfPanels = this.curSdfPanels;
2203
+ this.lastStats.sdfDraws = this.curSdfPanels > 0 ? 1 : 0;
2204
+ this.lastStats.msdfIcons = this.curMsdfIcons;
2205
+ this.lastStats.msdfDraws = this.curMsdfIcons > 0 ? 1 : 0;
2107
2206
  }
2108
2207
  destroy() {
2109
2208
  this.removeAllListeners();
@@ -1,2 +1,2 @@
1
- import { $ as WebGpuCanvasContextLike, Q as WebGpuBootstrapResult, X as RendererWebGpuOptions, Y as RendererWebGpu, Z as RequestWebGpuOptions, et as WebGpuDeviceLike, tt as requestWebGpuDevice } from "./game-CfUZiazr.js";
1
+ import { $ as WebGpuCanvasContextLike, Q as WebGpuBootstrapResult, X as RendererWebGpuOptions, Y as RendererWebGpu, Z as RequestWebGpuOptions, et as WebGpuDeviceLike, tt as requestWebGpuDevice } from "./game-DWELKTnB.js";
2
2
  export { RendererWebGpu, RendererWebGpuOptions, RequestWebGpuOptions, WebGpuBootstrapResult, WebGpuCanvasContextLike, WebGpuDeviceLike, requestWebGpuDevice };
@@ -1 +1 @@
1
- export { t as RendererWebGpu, n as requestWebGpuDevice } from "./renderer-webgpu-BE6fTBzo.js";
1
+ export { t as RendererWebGpu, n as requestWebGpuDevice } from "./renderer-webgpu-Djk7FayG.js";
package/dist/rig2d.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Yt as BlendMode, bt as ImageObject, jt as SceneHostLike, ut as Container, yt as Graphics } from "./game-CfUZiazr.js";
1
+ import { Yt as BlendMode, bt as ImageObject, jt as SceneHostLike, ut as Container, yt as Graphics } from "./game-DWELKTnB.js";
2
2
  export type RigCurveKind = 'linear' | 'step' | 'smoothstep' | 'outBack';
3
3
  export interface RigBoneDef {
4
4
  name: string;
package/dist/tilemap.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ct as BlitterObject, jt as SceneHostLike, ut as Container } from "./game-CfUZiazr.js";
1
+ import { ct as BlitterObject, jt as SceneHostLike, ut as Container } from "./game-DWELKTnB.js";
2
2
  /** Pack signed 16-bit chunk coordinates `[-32768..32767]` into a single 32-bit integer Map key (zero string allocation). */
3
3
  export declare function packChunkKey(cx: number, cy: number): number;
4
4
  export declare function unpackChunkX(key: number): number;
package/dist/trace.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { B as SceneDigestSurfaceSource, F as SceneDigestNode, H as buildSceneDigest, I as SceneDigestOptions, L as SceneDigestOverlayStats, M as SceneDigest, N as SceneDigestActiveFocus, P as SceneDigestEngineSandbox, R as SceneDigestSandbox, U as sanitizeTrackToken, V as SceneDigestSurfaces, z as SceneDigestSurfaceEntry } from "./game-CfUZiazr.js";
1
+ import { B as SceneDigestSurfaceSource, F as SceneDigestNode, H as buildSceneDigest, I as SceneDigestOptions, L as SceneDigestOverlayStats, M as SceneDigest, N as SceneDigestActiveFocus, P as SceneDigestEngineSandbox, R as SceneDigestSandbox, U as sanitizeTrackToken, V as SceneDigestSurfaces, z as SceneDigestSurfaceEntry } from "./game-DWELKTnB.js";
2
2
  export { SceneDigest, SceneDigestActiveFocus, SceneDigestEngineSandbox, SceneDigestNode, SceneDigestOptions, SceneDigestOverlayStats, SceneDigestSandbox, SceneDigestSurfaceEntry, SceneDigestSurfaceSource, SceneDigestSurfaces, buildSceneDigest, sanitizeTrackToken };
package/llms.txt CHANGED
@@ -7,7 +7,7 @@
7
7
  - [Official Docs & Live Playground](https://holt.js.org): Interactive KAPLAY-green playground, WebGPU & Kernel guide, 2.5D Survival Sandbox guide, and subpath references.
8
8
  - [README](https://github.com/botiverse-play/stage/blob/main/README.md): Overview, install, 20-subpath table, quick starts for WebGPU, `StageKernel`, 60 FPS video, and 2.5D survival games.
9
9
  - [Architecture](https://github.com/botiverse-play/stage/blob/main/docs/architecture.md): WebGPU/WebGL2/Canvas2D batchers, `StageKernel`, DPR/camera contracts, LIFO disposal, `SurfaceTree`, tracing-first observability.
10
- - [Changelog](https://github.com/botiverse-play/stage/blob/main/CHANGELOG.md): Release history (`0.1.0` – `0.5.0`).
10
+ - [Changelog](https://github.com/botiverse-play/stage/blob/main/CHANGELOG.md): Release history (`0.1.0` – `0.5.2`).
11
11
  - [Contributing](https://github.com/botiverse-play/stage/blob/main/CONTRIBUTING.md): Setup, invariants, verification gate, PR guidelines.
12
12
 
13
13
  ## AI Agent Skills & Instructions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holtjs/stage",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Zero-dependency TypeScript stage engine for 2D WebGPU/WebGL2/Canvas2D games, GPU SDF UI, procedural audio, StageKernel plugins, tracing-native observability, and deterministic 60 FPS headless image & video rendering.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Botiverse, Inc.",
@@ -5,7 +5,7 @@ description: Build zero-dependency WebGPU/WebGL2/Canvas2D 2D & 2.5D games, GPU S
5
5
 
6
6
  # Building 2D/2.5D Games, WebGPU UI & 60 FPS Video with `@holtjs/stage`
7
7
 
8
- Use this skill whenever creating or modifying a browser 2D/2.5D game, WebGPU/WebGL2 canvas UI, survival sandbox, automated `InputTimeline` test, or pure-Node headless image/storyboard/60 FPS video pipeline built on `@holtjs/stage` (`v0.5.0`, 20 subpaths).
8
+ Use this skill whenever creating or modifying a browser 2D/2.5D game, WebGPU/WebGL2 canvas UI, survival sandbox, automated `InputTimeline` test, or pure-Node headless image/storyboard/60 FPS video pipeline built on `@holtjs/stage` (`v0.5.2`, 20 subpaths).
9
9
 
10
10
  For the exhaustive exported symbol list across all 20 subpaths, see [references/subpaths.md](references/subpaths.md).
11
11
 
@@ -208,6 +208,8 @@ scene.tweens.spring({
208
208
  owner: card,
209
209
  onUpdate: (y) => { card.y = y; },
210
210
  });
211
+ // Or duration-based tween (`scene.tweens.to(...)` / `scene.tweens.add(...)`):
212
+ scene.tweens.to({ targets: card, alpha: { from: 0, to: 1 }, duration: 180, ease: 'outCubic' });
211
213
  ```
212
214
 
213
215
  ## 7. Zero-Browser 60 FPS Image, Storyboard & Video Rendering (`@holtjs/stage/headless`)
@@ -253,3 +255,5 @@ stage.destroy();
253
255
  - Destroying a parent `Container` unwinds children and disposers in strict LIFO order.
254
256
  5. **Respect `SurfaceTree` barriers everywhere & keep `trackId` PII-free**:
255
257
  - Gate world input on `!surfaces.isWorldBlocked()` and keep `trackId` static semantic tokens (`'craft.torch'`, `'hud.inventory'`). `buildSceneDigest()` never scrapes `TextObject.text`.
258
+ 6. **Use a dedicated `new Camera(rt.width, rt.height, true)` when rendering into an offscreen `StageRenderTarget`**:
259
+ - Passing `scene.cameras.main` applies the main camera's scroll/zoom/background; construct a dedicated transparent camera (`new Camera(rt.width, rt.height, true)`) for 1:1 FBO lightmap or post-FX passes.
@@ -1,6 +1,6 @@
1
1
  # `@holtjs/stage` Subpath API Quick Reference
2
2
 
3
- All symbols verified against `src/*.ts` (`@holtjs/stage@0.5.0`, 20 subpaths).
3
+ All symbols verified against `src/*.ts` (`@holtjs/stage@0.5.2`, 20 subpaths).
4
4
 
5
5
  ## `@holtjs/stage` (~57.3 kB gz · Core Engine Barrel)
6
6
  - **Bootstrap & Lifecycle**: `Stage` / `Stage2D` (namespaces), `AUTO`, `WEBGPU`, `WEBGL`, `CANVAS`, `Scale`, `Scenes`, `Game` (`.stepSimOnly()`, `.kernel`), `Scene`, `SceneManager`, `ScaleManager`, `GameLoop`, `EngineClock`, `LoaderPlugin`, `JsonCache`, `GameObjectFactory` (`scene.add.instancedBatch`, `customPass`, `panel`, `blitter`, etc.)
@@ -25,7 +25,7 @@ All symbols verified against `src/*.ts` (`@holtjs/stage@0.5.0`, 20 subpaths).
25
25
  ## `@holtjs/stage/headless` (~38.6 kB gz · pure Node with `@napi-rs/canvas`)
26
26
  - `createHeadlessStage(opts)`: `.step()`, `.stepToMs()`, `.stepToFrame()`, `.fastForward(frames)`, `.pointerDown/Move/Up()`, `.keyDown/Up()`, `.toRgba()`, `.toPng()`, `.digest()`, `.recordFrames()`
27
27
  - `renderStoryboard(stage, opts)` -> `{ png, width, height, digests }`
28
- - `createAudioTimeline(opts?)`: `.addAtMs()`, `.addAtFrame()`, `.renderStereo()`, `.toWav()`
28
+ - `createAudioTimeline(opts?)`: `.addAtMs()`, `.addAtFrame()`, `.toStereoPcm16()`, `.toWav()`
29
29
  - Types: `HeadlessCanvasLike`, `CreateHeadlessCanvas`, `HeadlessStageOptions`, `HeadlessRecordedFrame`, `RecordFramesOptions`, `HeadlessStage`, `StoryboardOptions`, `StoryboardResult`, `AudioCueOptions`, `AudioTimelineOptions`, `AudioTimeline`
30
30
 
31
31
  ## `@holtjs/stage/rig2d` (~5.7 kB gz · zero DOM)