@holtjs/stage 0.5.2 → 0.6.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,312 @@
1
- import { _ as rgbToCss, a as EventEmitter, h as packColorAbgr, m as createMatrix2D, o as FilterMode, p as WHITE_RGB, r as BlendModes, s as HEX_MASK, u as TintModes } from "./types-DRFB0Klc.js";
1
+ import { _ as rgbToCss, a as EventEmitter, g as parseColor, h as packColorAbgr, m as createMatrix2D, o as FilterMode, p as WHITE_RGB, r as BlendModes, s as HEX_MASK, u as TintModes } from "./types-CXsCvp1p.js";
2
+ // src/camera.ts
3
+ var Camera = class {
4
+ x = 0;
5
+ y = 0;
6
+ width;
7
+ height;
8
+ scrollX = 0;
9
+ scrollY = 0;
10
+ zoom = 1;
11
+ /** Active device-pixel ratio applied via `configureHiDpi()` (`1` when unconfigured). */
12
+ dpr = 1;
13
+ alpha = 1;
14
+ originX = .5;
15
+ originY = .5;
16
+ roundPixels = false;
17
+ useBounds = false;
18
+ boundsX = 0;
19
+ boundsY = 0;
20
+ boundsWidth = 0;
21
+ boundsHeight = 0;
22
+ backgroundColor;
23
+ transparent;
24
+ worldView = {
25
+ x: 0,
26
+ y: 0,
27
+ width: 0,
28
+ height: 0,
29
+ right: 0,
30
+ bottom: 0
31
+ };
32
+ matrixCombined = createMatrix2D();
33
+ followTarget = null;
34
+ followLerpX = 1;
35
+ followLerpY = 1;
36
+ followOffsetX = 0;
37
+ followOffsetY = 0;
38
+ deadzoneW = 0;
39
+ deadzoneH = 0;
40
+ constructor(width, height, transparent = false, backgroundColor) {
41
+ this.width = Math.max(1, width);
42
+ this.height = Math.max(1, height);
43
+ this.transparent = transparent;
44
+ this.backgroundColor = backgroundColor !== void 0 ? parseColor(backgroundColor, transparent ? 0 : 1) : {
45
+ r: 0,
46
+ g: 0,
47
+ b: 0,
48
+ a: transparent ? 0 : 1
49
+ };
50
+ this.syncMetrics();
51
+ }
52
+ get displayWidth() {
53
+ return this.width / (this.zoom || 1);
54
+ }
55
+ get displayHeight() {
56
+ return this.height / (this.zoom || 1);
57
+ }
58
+ setBackgroundColor(color) {
59
+ this.backgroundColor = parseColor(color, 1);
60
+ this.transparent = this.backgroundColor.a <= 0;
61
+ return this;
62
+ }
63
+ setRoundPixels(v) {
64
+ this.roundPixels = !!v;
65
+ return this;
66
+ }
67
+ setOrigin(x = .5, y = x) {
68
+ this.originX = x;
69
+ this.originY = y;
70
+ this.syncMetrics();
71
+ return this;
72
+ }
73
+ setZoom(z) {
74
+ this.zoom = z > 0 ? z : 1;
75
+ if (this.useBounds) {
76
+ this.scrollX = this.clampX(this.scrollX);
77
+ this.scrollY = this.clampY(this.scrollY);
78
+ }
79
+ this.syncMetrics();
80
+ return this;
81
+ }
82
+ setScroll(x, y) {
83
+ this.scrollX = this.useBounds ? this.clampX(x) : x;
84
+ this.scrollY = this.useBounds ? this.clampY(y) : y;
85
+ this.syncMetrics();
86
+ return this;
87
+ }
88
+ setViewport(x, y, width, height) {
89
+ this.x = x;
90
+ this.y = y;
91
+ this.width = Math.max(1, width);
92
+ this.height = Math.max(1, height);
93
+ if (this.useBounds) {
94
+ this.scrollX = this.clampX(this.scrollX);
95
+ this.scrollY = this.clampY(this.scrollY);
96
+ }
97
+ this.syncMetrics();
98
+ return this;
99
+ }
100
+ setSize(width, height) {
101
+ this.width = Math.max(1, width);
102
+ this.height = Math.max(1, height);
103
+ if (this.useBounds) {
104
+ this.scrollX = this.clampX(this.scrollX);
105
+ this.scrollY = this.clampY(this.scrollY);
106
+ }
107
+ this.syncMetrics();
108
+ return this;
109
+ }
110
+ setAlpha(a) {
111
+ this.alpha = Math.max(0, Math.min(1, a));
112
+ return this;
113
+ }
114
+ setBounds(x, y, width, height) {
115
+ this.useBounds = true;
116
+ this.boundsX = x;
117
+ this.boundsY = y;
118
+ this.boundsWidth = width;
119
+ this.boundsHeight = height;
120
+ this.scrollX = this.clampX(this.scrollX);
121
+ this.scrollY = this.clampY(this.scrollY);
122
+ this.syncMetrics();
123
+ return this;
124
+ }
125
+ /** Disable world-bounds scroll clamping (`removeBounds()` alias included for Phaser familiarity). */
126
+ clearBounds() {
127
+ this.useBounds = false;
128
+ return this;
129
+ }
130
+ removeBounds() {
131
+ return this.clearBounds();
132
+ }
133
+ clampX(sx) {
134
+ if (!this.useBounds || this.boundsWidth <= 0) return sx;
135
+ const z = this.zoom || 1;
136
+ const ox = this.width * this.originX;
137
+ const dw = this.width / z;
138
+ if (dw >= this.boundsWidth) return this.boundsX + this.boundsWidth * .5 - dw * .5 - ox + ox / z;
139
+ const minSx = this.boundsX - ox + ox / z;
140
+ const maxSx = this.boundsX + this.boundsWidth - dw - ox + ox / z;
141
+ return sx < minSx ? minSx : sx > maxSx ? maxSx : sx;
142
+ }
143
+ clampY(sy) {
144
+ if (!this.useBounds || this.boundsHeight <= 0) return sy;
145
+ const z = this.zoom || 1;
146
+ const oy = this.height * this.originY;
147
+ const dh = this.height / z;
148
+ if (dh >= this.boundsHeight) return this.boundsY + this.boundsHeight * .5 - dh * .5 - oy + oy / z;
149
+ const minSy = this.boundsY - oy + oy / z;
150
+ const maxSy = this.boundsY + this.boundsHeight - dh - oy + oy / z;
151
+ return sy < minSy ? minSy : sy > maxSy ? maxSy : sy;
152
+ }
153
+ centerOn(x, y) {
154
+ const z = this.zoom || 1;
155
+ const ox = this.width * this.originX;
156
+ const oy = this.height * this.originY;
157
+ const dw = this.width / z;
158
+ const dh = this.height / z;
159
+ return this.setScroll(x - dw * .5 - ox + ox / z, y - dh * .5 - oy + oy / z);
160
+ }
161
+ /**
162
+ * One-line HiDPI camera + backing-buffer configurator: maps logical `(0, 0)..(viewportW, viewportH)`
163
+ * 1:1 onto crisp physical `viewportW * dpr` pixels without copy-pasting origin/scroll math.
164
+ * Pass `{ fit: true }` (or configure `scale: { mode: Scale.FIT }`) for automatic aspect-preserving CSS letterboxing.
165
+ * Returns the clamped `dpr` applied.
166
+ */
167
+ configureHiDpi(scale, viewportWidth, viewportHeight, dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1, maxDpr = 2, options) {
168
+ const safeDpr = Math.min(Math.max(1, maxDpr), Math.max(1, Number.isFinite(dpr) ? dpr : 1));
169
+ const vw = Math.max(1, Math.round(viewportWidth));
170
+ const vh = Math.max(1, Math.round(viewportHeight));
171
+ this.dpr = safeDpr;
172
+ scale.logicalWidth = vw;
173
+ scale.logicalHeight = vh;
174
+ scale.zoom = 1 / safeDpr;
175
+ const hadBounds = this.useBounds;
176
+ this.useBounds = false;
177
+ scale.resize(Math.round(vw * safeDpr), Math.round(vh * safeDpr));
178
+ if ((options?.fit || scale.mode === 1) && typeof scale.fitToContainer === "function") scale.fitToContainer(options?.containerWidth, options?.containerHeight);
179
+ else if (scale.canvas?.style) {
180
+ scale.canvas.style.width = `${vw}px`;
181
+ scale.canvas.style.height = `${vh}px`;
182
+ }
183
+ const ox = this.width * this.originX;
184
+ const oy = this.height * this.originY;
185
+ this.zoom = safeDpr;
186
+ this.useBounds = hadBounds;
187
+ this.setScroll(ox / safeDpr - ox, oy / safeDpr - oy);
188
+ return safeDpr;
189
+ }
190
+ /** Convert canvas/backing-buffer coordinates `(screenX, screenY)` into world coordinates. */
191
+ screenToWorld(screenX, screenY, out = {
192
+ x: 0,
193
+ y: 0
194
+ }) {
195
+ const m = this.matrixCombined;
196
+ out.x = (screenX - m.tx) / (m.a || 1);
197
+ out.y = (screenY - m.ty) / (m.d || 1);
198
+ return out;
199
+ }
200
+ /** Convert world coordinates `(worldX, worldY)` into canvas/backing-buffer coordinates. */
201
+ worldToScreen(worldX, worldY, out = {
202
+ x: 0,
203
+ y: 0
204
+ }) {
205
+ const m = this.matrixCombined;
206
+ out.x = worldX * m.a + m.tx;
207
+ out.y = worldY * m.d + m.ty;
208
+ return out;
209
+ }
210
+ /** Convert logical/CSS viewport coordinates `(0..viewportW, 0..viewportH)` into world coordinates (HiDPI-aware). */
211
+ logicalToWorld(logicalX, logicalY, out = {
212
+ x: 0,
213
+ y: 0
214
+ }) {
215
+ return this.screenToWorld(logicalX * this.dpr, logicalY * this.dpr, out);
216
+ }
217
+ /** Convert world coordinates into logical/CSS viewport coordinates `(0..viewportW, 0..viewportH)` (HiDPI-aware). */
218
+ worldToLogical(worldX, worldY, out = {
219
+ x: 0,
220
+ y: 0
221
+ }) {
222
+ this.worldToScreen(worldX, worldY, out);
223
+ const inv = 1 / (this.dpr || 1);
224
+ out.x *= inv;
225
+ out.y *= inv;
226
+ return out;
227
+ }
228
+ /** Convert raw DOM `MouseEvent`/`PointerEvent` `(clientX, clientY)` directly into world coordinates across HiDPI & `Scale.FIT`. */
229
+ clientToWorld(clientX, clientY, canvas, out = {
230
+ x: 0,
231
+ y: 0
232
+ }) {
233
+ const rect = canvas.getBoundingClientRect();
234
+ const sx = (clientX - rect.left) * canvas.width / (rect.width || 1);
235
+ const sy = (clientY - rect.top) * canvas.height / (rect.height || 1);
236
+ return this.screenToWorld(sx, sy, out);
237
+ }
238
+ /** Lock or smoothly follow any `{ x, y }` actor/point (frame-rate independent lerp + optional deadzone & bounds). */
239
+ startFollow(target, options = {}) {
240
+ this.followTarget = target;
241
+ this.followLerpX = Math.max(.001, Math.min(1, options.lerpX ?? 1));
242
+ this.followLerpY = Math.max(.001, Math.min(1, options.lerpY ?? this.followLerpX));
243
+ this.followOffsetX = options.offsetX ?? 0;
244
+ this.followOffsetY = options.offsetY ?? 0;
245
+ this.deadzoneW = Math.max(0, options.deadzoneWidth ?? 0);
246
+ this.deadzoneH = Math.max(0, options.deadzoneHeight ?? 0);
247
+ if (options.bounds) this.setBounds(options.bounds.x, options.bounds.y, options.bounds.width, options.bounds.height);
248
+ return this;
249
+ }
250
+ stopFollow() {
251
+ this.followTarget = null;
252
+ return this;
253
+ }
254
+ /** Internal per-step follow update invoked automatically by `Game.step()` before rendering. */
255
+ stepFollow(deltaMs) {
256
+ const target = this.followTarget;
257
+ if (!target) return;
258
+ const tx = target.x + this.followOffsetX;
259
+ const ty = target.y + this.followOffsetY;
260
+ const curCx = this.worldView.x + this.worldView.width * .5;
261
+ const curCy = this.worldView.y + this.worldView.height * .5;
262
+ let wantCx = curCx;
263
+ let wantCy = curCy;
264
+ const halfDzW = this.deadzoneW * .5;
265
+ const halfDzH = this.deadzoneH * .5;
266
+ if (tx < curCx - halfDzW) wantCx = tx + halfDzW;
267
+ else if (tx > curCx + halfDzW) wantCx = tx - halfDzW;
268
+ if (ty < curCy - halfDzH) wantCy = ty + halfDzH;
269
+ else if (ty > curCy + halfDzH) wantCy = ty - halfDzH;
270
+ const frames = Math.max(.1, deltaMs / (1e3 / 60));
271
+ const ax = this.followLerpX >= 1 ? 1 : 1 - Math.pow(1 - this.followLerpX, frames);
272
+ const ay = this.followLerpY >= 1 ? 1 : 1 - Math.pow(1 - this.followLerpY, frames);
273
+ const nextCx = curCx + (wantCx - curCx) * ax;
274
+ const nextCy = curCy + (wantCy - curCy) * ay;
275
+ const ox = this.width * this.originX;
276
+ const oy = this.height * this.originY;
277
+ const z = this.zoom || 1;
278
+ const nextSx = nextCx - this.worldView.width * .5 - ox + ox / z;
279
+ const nextSy = nextCy - this.worldView.height * .5 - oy + oy / z;
280
+ this.setScroll(nextSx, nextSy);
281
+ }
282
+ /** Recompute `worldView` and world->canvas `matrixCombined`. */
283
+ syncMetrics() {
284
+ const z = this.zoom || 1;
285
+ const ox = this.width * this.originX;
286
+ const oy = this.height * this.originY;
287
+ const sx = this.roundPixels ? Math.round(this.scrollX) : this.scrollX;
288
+ const sy = this.roundPixels ? Math.round(this.scrollY) : this.scrollY;
289
+ const dw = this.width / z;
290
+ const dh = this.height / z;
291
+ const vx = sx + ox - ox / z;
292
+ const vy = sy + oy - oy / z;
293
+ this.worldView.x = vx;
294
+ this.worldView.y = vy;
295
+ this.worldView.width = dw;
296
+ this.worldView.height = dh;
297
+ this.worldView.right = vx + dw;
298
+ this.worldView.bottom = vy + dh;
299
+ const m = this.matrixCombined;
300
+ m.a = z;
301
+ m.b = 0;
302
+ m.c = 0;
303
+ m.d = z;
304
+ m.tx = (-sx - ox) * z + ox + this.x;
305
+ m.ty = (-sy - oy) * z + oy + this.y;
306
+ m.scaleX = z;
307
+ m.scaleY = z;
308
+ }
309
+ };
2
310
  // src/display.ts
3
311
  var DisplayList = class {
4
312
  list = [];
@@ -956,8 +1264,14 @@ var Graphics = class extends DisplayObject {
956
1264
  numLen = 0;
957
1265
  /** Monotonic geometry revision bumped on every clear/draw op so WebGL can cache static tessellation meshes. */
958
1266
  version = 0;
1267
+ /** True when curved SDF-capable primitives (`fillCircle`, `strokeCircle`, `fillRoundedRect`, `strokeRoundedRect`) are recorded. */
1268
+ _hasSdfShapes = false;
1269
+ /** True when arbitrary polygons, lines, arcs, or eccentric ellipses requiring polygon tessellation are recorded. */
1270
+ _hasNonSdfOps = false;
959
1271
  /** Renderer-owned tessellated local-space mesh cache (opaque to user code). */
960
1272
  _glCache = null;
1273
+ /** Canvas2D retained `Path2D` cache keyed by `version` (opaque to user code). */
1274
+ _c2dCache = null;
961
1275
  /** Last filled rectangle bounds (used O(1) by `Pane` and `ScrollList` rect clip masks). */
962
1276
  maskRect = null;
963
1277
  constructor(scene) {
@@ -988,6 +1302,8 @@ var Graphics = class extends DisplayObject {
988
1302
  if (this.opLen !== 0 || this.numLen !== 0 || this.maskRect !== null) {
989
1303
  this.opLen = 0;
990
1304
  this.numLen = 0;
1305
+ this._hasSdfShapes = false;
1306
+ this._hasNonSdfOps = false;
991
1307
  this.maskRect = null;
992
1308
  this.version++;
993
1309
  }
@@ -1044,6 +1360,7 @@ var Graphics = class extends DisplayObject {
1044
1360
  }
1045
1361
  fillRoundedRect(x, y, w, h, radius = 8) {
1046
1362
  const r = typeof radius === "number" ? radius : radius.tl ?? radius.tr ?? 8;
1363
+ this._hasSdfShapes = true;
1047
1364
  const i = this.pushOp(5, 5);
1048
1365
  this.nums[i] = x;
1049
1366
  this.nums[i + 1] = y;
@@ -1054,6 +1371,7 @@ var Graphics = class extends DisplayObject {
1054
1371
  }
1055
1372
  strokeRoundedRect(x, y, w, h, radius = 8) {
1056
1373
  const r = typeof radius === "number" ? radius : radius.tl ?? radius.tr ?? 8;
1374
+ this._hasSdfShapes = true;
1057
1375
  const i = this.pushOp(6, 5);
1058
1376
  this.nums[i] = x;
1059
1377
  this.nums[i + 1] = y;
@@ -1063,6 +1381,7 @@ var Graphics = class extends DisplayObject {
1063
1381
  return this;
1064
1382
  }
1065
1383
  fillCircle(x, y, r) {
1384
+ this._hasSdfShapes = true;
1066
1385
  const i = this.pushOp(7, 3);
1067
1386
  this.nums[i] = x;
1068
1387
  this.nums[i + 1] = y;
@@ -1070,6 +1389,7 @@ var Graphics = class extends DisplayObject {
1070
1389
  return this;
1071
1390
  }
1072
1391
  strokeCircle(x, y, r) {
1392
+ this._hasSdfShapes = true;
1073
1393
  const i = this.pushOp(8, 3);
1074
1394
  this.nums[i] = x;
1075
1395
  this.nums[i + 1] = y;
@@ -1077,6 +1397,8 @@ var Graphics = class extends DisplayObject {
1077
1397
  return this;
1078
1398
  }
1079
1399
  fillEllipse(x, y, width, height) {
1400
+ if (Math.abs(width - height) <= 1e-4) this._hasSdfShapes = true;
1401
+ else this._hasNonSdfOps = true;
1080
1402
  const i = this.pushOp(9, 4);
1081
1403
  this.nums[i] = x;
1082
1404
  this.nums[i + 1] = y;
@@ -1085,6 +1407,8 @@ var Graphics = class extends DisplayObject {
1085
1407
  return this;
1086
1408
  }
1087
1409
  strokeEllipse(x, y, width, height) {
1410
+ if (Math.abs(width - height) <= 1e-4) this._hasSdfShapes = true;
1411
+ else this._hasNonSdfOps = true;
1088
1412
  const i = this.pushOp(10, 4);
1089
1413
  this.nums[i] = x;
1090
1414
  this.nums[i + 1] = y;
@@ -1093,6 +1417,7 @@ var Graphics = class extends DisplayObject {
1093
1417
  return this;
1094
1418
  }
1095
1419
  fillTriangle(x0, y0, x1, y1, x2, y2) {
1420
+ this._hasNonSdfOps = true;
1096
1421
  const i = this.pushOp(11, 6);
1097
1422
  this.nums[i] = x0;
1098
1423
  this.nums[i + 1] = y0;
@@ -1103,6 +1428,7 @@ var Graphics = class extends DisplayObject {
1103
1428
  return this;
1104
1429
  }
1105
1430
  strokeTriangle(x0, y0, x1, y1, x2, y2) {
1431
+ this._hasNonSdfOps = true;
1106
1432
  const i = this.pushOp(12, 6);
1107
1433
  this.nums[i] = x0;
1108
1434
  this.nums[i + 1] = y0;
@@ -1113,6 +1439,7 @@ var Graphics = class extends DisplayObject {
1113
1439
  return this;
1114
1440
  }
1115
1441
  lineBetween(x1, y1, x2, y2) {
1442
+ this._hasNonSdfOps = true;
1116
1443
  const i = this.pushOp(13, 4);
1117
1444
  this.nums[i] = x1;
1118
1445
  this.nums[i + 1] = y1;
@@ -1121,22 +1448,26 @@ var Graphics = class extends DisplayObject {
1121
1448
  return this;
1122
1449
  }
1123
1450
  beginPath() {
1451
+ this._hasNonSdfOps = true;
1124
1452
  this.pushOp(14, 0);
1125
1453
  return this;
1126
1454
  }
1127
1455
  moveTo(x, y) {
1456
+ this._hasNonSdfOps = true;
1128
1457
  const i = this.pushOp(15, 2);
1129
1458
  this.nums[i] = x;
1130
1459
  this.nums[i + 1] = y;
1131
1460
  return this;
1132
1461
  }
1133
1462
  lineTo(x, y) {
1463
+ this._hasNonSdfOps = true;
1134
1464
  const i = this.pushOp(16, 2);
1135
1465
  this.nums[i] = x;
1136
1466
  this.nums[i + 1] = y;
1137
1467
  return this;
1138
1468
  }
1139
1469
  arc(x, y, r, startAngle, endAngle, anticlockwise = false) {
1470
+ this._hasNonSdfOps = true;
1140
1471
  const i = this.pushOp(17, 6);
1141
1472
  this.nums[i] = x;
1142
1473
  this.nums[i + 1] = y;
@@ -1147,6 +1478,7 @@ var Graphics = class extends DisplayObject {
1147
1478
  return this;
1148
1479
  }
1149
1480
  slice(x, y, r, startAngle, endAngle, anticlockwise = false) {
1481
+ this._hasNonSdfOps = true;
1150
1482
  const i = this.pushOp(18, 6);
1151
1483
  this.nums[i] = x;
1152
1484
  this.nums[i + 1] = y;
@@ -1198,6 +1530,7 @@ var Graphics = class extends DisplayObject {
1198
1530
  }
1199
1531
  destroy(fromScene) {
1200
1532
  this._glCache = null;
1533
+ this._c2dCache = null;
1201
1534
  super.destroy(fromScene);
1202
1535
  }
1203
1536
  };
@@ -1430,6 +1763,51 @@ var InstancedBatchObject = class extends DisplayObject {
1430
1763
  super.destroy(fromScene);
1431
1764
  }
1432
1765
  };
1766
+ /**
1767
+ * Zero-texture GPU analytical SDF shape batch (`scene.add.shapeBatch(maxCount, defaults?)`).
1768
+ * Renders thousands of dynamic circles, rings, pills, capsules, shadows, health bars, or rounded rects
1769
+ * directly from `SoaWorld` `Float32Array` / `Uint32Array` columns — 1 analytical SDF quad (2 tris) per shape
1770
+ * on WebGL2 & WebGPU with zero sprite atlas baking and zero CPU polygon triangulation.
1771
+ */
1772
+ var ShapeBatchObject = class extends DisplayObject {
1773
+ maxCount;
1774
+ defaultWidth;
1775
+ defaultHeight;
1776
+ defaultRadius;
1777
+ defaultFillColor;
1778
+ defaultFillAlpha;
1779
+ defaultBorderColor;
1780
+ defaultBorderAlpha;
1781
+ defaultBorderWidth;
1782
+ pixelStep;
1783
+ columns = null;
1784
+ constructor(scene, maxCount = 1024, defaults = {}) {
1785
+ super(scene, "ShapeBatch");
1786
+ this.maxCount = Math.max(1, Math.floor(maxCount));
1787
+ this.originX = .5;
1788
+ this.originY = .5;
1789
+ const w = defaults.width ?? 12;
1790
+ const h = defaults.height ?? w;
1791
+ this.defaultWidth = w;
1792
+ this.defaultHeight = h;
1793
+ this.defaultRadius = defaults.radius ?? Math.min(w, h) * .5;
1794
+ this.defaultFillColor = (defaults.fillColor ?? 0xffffff) & HEX_MASK;
1795
+ this.defaultFillAlpha = defaults.fillAlpha ?? 1;
1796
+ this.defaultBorderColor = (defaults.borderColor ?? 0) & HEX_MASK;
1797
+ this.defaultBorderAlpha = defaults.borderAlpha ?? 1;
1798
+ this.defaultBorderWidth = defaults.borderWidth ?? 0;
1799
+ this.pixelStep = defaults.pixelStep ?? 0;
1800
+ }
1801
+ /** Bind or update the SoA column views read on each render pass (zero copying on caller side). */
1802
+ setColumns(columns) {
1803
+ this.columns = columns;
1804
+ return this;
1805
+ }
1806
+ destroy(fromScene) {
1807
+ this.columns = null;
1808
+ super.destroy(fromScene);
1809
+ }
1810
+ };
1433
1811
  // src/renderer-2d.ts
1434
1812
  function addPerCornerRoundedRectSubpath(ctx, x, y, w, h, tl, tr, br, bl) {
1435
1813
  const maxR = Math.min(w, h) * .5;
@@ -1486,6 +1864,7 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1486
1864
  height;
1487
1865
  tintCanvas = null;
1488
1866
  tintCtx = null;
1867
+ tintCache = /* @__PURE__ */ new Map();
1489
1868
  maskWorldMat = createMatrix2D();
1490
1869
  pathCache = /* @__PURE__ */ new Map();
1491
1870
  curDrawCalls = 0;
@@ -1530,12 +1909,42 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1530
1909
  this.canvas.width = w;
1531
1910
  this.canvas.height = h;
1532
1911
  }
1533
- getTintedSource(img, sx, sy, sw, sh, rgb, fill) {
1912
+ getTintedSource(img, sx, sy, sw, sh, rgb, fill, texSource) {
1534
1913
  const iw = Math.max(1, Math.ceil(sw));
1535
1914
  const ih = Math.max(1, Math.ceil(sh));
1915
+ const doc = this.canvas.ownerDocument ?? (typeof document !== "undefined" ? document : null);
1916
+ if (!doc) return null;
1917
+ if (texSource && !texSource.isRenderTarget && iw <= 512 && ih <= 512) {
1918
+ const cacheKey = `${texSource.id}:${texSource.version}:${sx},${sy},${sw},${sh}:${rgb}:${fill ? 1 : 0}`;
1919
+ const hit = this.tintCache.get(cacheKey);
1920
+ if (hit) {
1921
+ this.tintCache.delete(cacheKey);
1922
+ this.tintCache.set(cacheKey, hit);
1923
+ return hit;
1924
+ }
1925
+ const entry = doc.createElement("canvas");
1926
+ entry.width = iw;
1927
+ entry.height = ih;
1928
+ const eg = entry.getContext("2d");
1929
+ if (eg) {
1930
+ eg.globalCompositeOperation = "source-over";
1931
+ eg.drawImage(img, sx, sy, sw, sh, 0, 0, iw, ih);
1932
+ eg.globalCompositeOperation = fill ? "source-in" : "multiply";
1933
+ eg.fillStyle = rgbToCss(rgb, 1);
1934
+ eg.fillRect(0, 0, iw, ih);
1935
+ if (!fill) {
1936
+ eg.globalCompositeOperation = "destination-in";
1937
+ eg.drawImage(img, sx, sy, sw, sh, 0, 0, iw, ih);
1938
+ }
1939
+ if (this.tintCache.size >= 256) {
1940
+ const oldest = this.tintCache.keys().next().value;
1941
+ if (oldest !== void 0) this.tintCache.delete(oldest);
1942
+ }
1943
+ this.tintCache.set(cacheKey, entry);
1944
+ return entry;
1945
+ }
1946
+ }
1536
1947
  if (!this.tintCanvas) {
1537
- const doc = this.canvas.ownerDocument ?? (typeof document !== "undefined" ? document : null);
1538
- if (!doc) return null;
1539
1948
  this.tintCanvas = doc.createElement("canvas");
1540
1949
  this.tintCtx = this.tintCanvas.getContext("2d");
1541
1950
  }
@@ -1595,7 +2004,7 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1595
2004
  ctx.scale(img.flipX ? -1 : 1, img.flipY ? -1 : 1);
1596
2005
  }
1597
2006
  if (img.isTinted && (img.tint !== 0xffffff || img.tintMode === TintModes.FILL)) {
1598
- const tinted = this.getTintedSource(srcImg, sx, sy, sw, sh, img.tint, img.tintMode === TintModes.FILL);
2007
+ const tinted = this.getTintedSource(srcImg, sx, sy, sw, sh, img.tint, img.tintMode === TintModes.FILL, frame.source);
1599
2008
  if (tinted) {
1600
2009
  ctx.drawImage(tinted, 0, 0, Math.ceil(sw), Math.ceil(sh), dx, dy, dw, dh);
1601
2010
  this.curDrawCalls++;
@@ -1680,7 +2089,7 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1680
2089
  let drawSrc = srcImg;
1681
2090
  let baseSx = frame.cutX, baseSy = frame.cutY;
1682
2091
  if (ts.isTinted && ts.tint !== 0xffffff) {
1683
- const tinted = this.getTintedSource(srcImg, frame.cutX, frame.cutY, frame.cutWidth, frame.cutHeight, ts.tint, false);
2092
+ const tinted = this.getTintedSource(srcImg, frame.cutX, frame.cutY, frame.cutWidth, frame.cutHeight, ts.tint, false, frame.source);
1684
2093
  if (tinted) {
1685
2094
  drawSrc = tinted;
1686
2095
  baseSx = 0;
@@ -1825,23 +2234,201 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1825
2234
  renderGraphics(g, ctx) {
1826
2235
  if (g.opLen === 0) return;
1827
2236
  this.curDrawCalls++;
2237
+ const cached = g._c2dCache;
2238
+ if (cached && cached.version === g.version) {
2239
+ for (let i = 0; i < cached.runs.length; i++) {
2240
+ const run = cached.runs[i];
2241
+ if (run.kind === "fill") {
2242
+ ctx.fillStyle = run.style;
2243
+ ctx.fill(run.path);
2244
+ } else {
2245
+ ctx.lineWidth = run.lw;
2246
+ ctx.strokeStyle = run.style;
2247
+ ctx.stroke(run.path);
2248
+ }
2249
+ }
2250
+ return;
2251
+ }
2252
+ if (g._c2dSeenVer === g.version && typeof Path2D === "function" && !g._hasNonSdfOps) {
2253
+ const runs = [];
2254
+ let curFillStyle = "";
2255
+ let curFillPath = null;
2256
+ let fillRgb = WHITE_RGB, fillA = 1;
2257
+ let lineW = 1, lineRgb = WHITE_RGB, lineA = 1;
2258
+ const stack = [];
2259
+ const ops = g.ops;
2260
+ const nums = g.nums;
2261
+ let ni = 0;
2262
+ const ensureFillRun = (style, canBatch) => {
2263
+ if (canBatch && curFillPath && curFillStyle === style) return curFillPath;
2264
+ const p = new Path2D();
2265
+ runs.push({
2266
+ kind: "fill",
2267
+ style,
2268
+ lw: 0,
2269
+ path: p
2270
+ });
2271
+ curFillPath = canBatch ? p : null;
2272
+ curFillStyle = canBatch ? style : "";
2273
+ return p;
2274
+ };
2275
+ const pushStrokeRun = (style, lw) => {
2276
+ curFillPath = null;
2277
+ curFillStyle = "";
2278
+ const p = new Path2D();
2279
+ runs.push({
2280
+ kind: "stroke",
2281
+ style,
2282
+ lw,
2283
+ path: p
2284
+ });
2285
+ return p;
2286
+ };
2287
+ const addRRectToPath = (p, x, y, w, h, radius) => {
2288
+ const r = Math.max(0, Math.min(radius, w * .5, h * .5));
2289
+ p.moveTo(x + r, y);
2290
+ p.lineTo(x + w - r, y);
2291
+ if (r > 0) p.quadraticCurveTo(x + w, y, x + w, y + r);
2292
+ p.lineTo(x + w, y + h - r);
2293
+ if (r > 0) p.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
2294
+ p.lineTo(x + r, y + h);
2295
+ if (r > 0) p.quadraticCurveTo(x, y + h, x, y + h - r);
2296
+ p.lineTo(x, y + r);
2297
+ if (r > 0) p.quadraticCurveTo(x, y, x + r, y);
2298
+ p.closePath();
2299
+ };
2300
+ for (let oi = 0; oi < g.opLen; oi++) switch (ops[oi]) {
2301
+ case 22:
2302
+ stack.push(fillRgb, fillA, lineW, lineRgb, lineA);
2303
+ break;
2304
+ case 23:
2305
+ if (stack.length >= 5) {
2306
+ lineA = stack.pop();
2307
+ lineRgb = stack.pop();
2308
+ lineW = stack.pop();
2309
+ fillA = stack.pop();
2310
+ fillRgb = stack.pop();
2311
+ }
2312
+ break;
2313
+ case 1:
2314
+ fillRgb = nums[ni++];
2315
+ fillA = nums[ni++];
2316
+ break;
2317
+ case 2:
2318
+ lineW = nums[ni++];
2319
+ lineRgb = nums[ni++];
2320
+ lineA = nums[ni++];
2321
+ break;
2322
+ case 3: {
2323
+ const x = nums[ni++], y = nums[ni++], w = nums[ni++], h = nums[ni++];
2324
+ if (fillA > 0) ensureFillRun(rgbToCss(fillRgb, fillA), fillA >= 1).rect(x, y, w, h);
2325
+ break;
2326
+ }
2327
+ case 4: {
2328
+ const x = nums[ni++], y = nums[ni++], w = nums[ni++], h = nums[ni++];
2329
+ if (lineA > 0 && lineW > 0) pushStrokeRun(rgbToCss(lineRgb, lineA), lineW).rect(x, y, w, h);
2330
+ break;
2331
+ }
2332
+ case 5: {
2333
+ const x = nums[ni++], y = nums[ni++], w = nums[ni++], h = nums[ni++], r = nums[ni++];
2334
+ if (fillA > 0 && w > 0 && h > 0) addRRectToPath(ensureFillRun(rgbToCss(fillRgb, fillA), fillA >= 1), x, y, w, h, r);
2335
+ break;
2336
+ }
2337
+ case 6: {
2338
+ const x = nums[ni++], y = nums[ni++], w = nums[ni++], h = nums[ni++], r = nums[ni++];
2339
+ if (lineA > 0 && lineW > 0 && w > 0 && h > 0) addRRectToPath(pushStrokeRun(rgbToCss(lineRgb, lineA), lineW), x, y, w, h, r);
2340
+ break;
2341
+ }
2342
+ case 7: {
2343
+ const cx = nums[ni++], cy = nums[ni++], r = nums[ni++];
2344
+ if (fillA > 0 && r > 0) {
2345
+ const p = ensureFillRun(rgbToCss(fillRgb, fillA), fillA >= 1);
2346
+ p.moveTo(cx + r, cy);
2347
+ p.arc(cx, cy, r, 0, Math.PI * 2);
2348
+ }
2349
+ break;
2350
+ }
2351
+ case 8: {
2352
+ const cx = nums[ni++], cy = nums[ni++], r = nums[ni++];
2353
+ if (lineA > 0 && lineW > 0 && r > 0) {
2354
+ const p = pushStrokeRun(rgbToCss(lineRgb, lineA), lineW);
2355
+ p.moveTo(cx + r, cy);
2356
+ p.arc(cx, cy, r, 0, Math.PI * 2);
2357
+ }
2358
+ break;
2359
+ }
2360
+ case 9: {
2361
+ const cx = nums[ni++], cy = nums[ni++], w = nums[ni++], h = nums[ni++];
2362
+ if (fillA > 0 && w > 0 && h > 0) {
2363
+ const p = ensureFillRun(rgbToCss(fillRgb, fillA), fillA >= 1);
2364
+ p.moveTo(cx + w * .5, cy);
2365
+ p.ellipse(cx, cy, w * .5, h * .5, 0, 0, Math.PI * 2);
2366
+ }
2367
+ break;
2368
+ }
2369
+ case 10: {
2370
+ const cx = nums[ni++], cy = nums[ni++], w = nums[ni++], h = nums[ni++];
2371
+ if (lineA > 0 && lineW > 0 && w > 0 && h > 0) {
2372
+ const p = pushStrokeRun(rgbToCss(lineRgb, lineA), lineW);
2373
+ p.moveTo(cx + w * .5, cy);
2374
+ p.ellipse(cx, cy, w * .5, h * .5, 0, 0, Math.PI * 2);
2375
+ }
2376
+ break;
2377
+ }
2378
+ }
2379
+ g._c2dCache = {
2380
+ version: g.version,
2381
+ runs
2382
+ };
2383
+ for (let i = 0; i < runs.length; i++) {
2384
+ const run = runs[i];
2385
+ if (run.kind === "fill") {
2386
+ ctx.fillStyle = run.style;
2387
+ ctx.fill(run.path);
2388
+ } else {
2389
+ ctx.lineWidth = run.lw;
2390
+ ctx.strokeStyle = run.style;
2391
+ ctx.stroke(run.path);
2392
+ }
2393
+ }
2394
+ return;
2395
+ }
2396
+ g._c2dSeenVer = g.version;
1828
2397
  let fillRgb = WHITE_RGB, fillA = 1;
1829
2398
  let lineW = 1, lineRgb = WHITE_RGB, lineA = 1;
2399
+ ctx.fillStyle = rgbToCss(fillRgb, fillA);
2400
+ ctx.lineWidth = lineW;
2401
+ ctx.strokeStyle = rgbToCss(lineRgb, lineA);
2402
+ let batchFillOpen = false;
2403
+ const flushBatchFill = () => {
2404
+ if (batchFillOpen) {
2405
+ ctx.fill();
2406
+ batchFillOpen = false;
2407
+ }
2408
+ };
1830
2409
  const ops = g.ops;
1831
2410
  const nums = g.nums;
1832
2411
  let ni = 0;
1833
2412
  for (let oi = 0; oi < g.opLen; oi++) switch (ops[oi]) {
1834
2413
  case 22:
2414
+ flushBatchFill();
1835
2415
  ctx.save();
1836
2416
  break;
1837
2417
  case 23:
2418
+ flushBatchFill();
1838
2419
  ctx.restore();
1839
2420
  break;
1840
- case 1:
1841
- fillRgb = nums[ni++];
1842
- fillA = nums[ni++];
1843
- ctx.fillStyle = rgbToCss(fillRgb, fillA);
2421
+ case 1: {
2422
+ const nextRgb = nums[ni++];
2423
+ const nextA = nums[ni++];
2424
+ if (nextRgb !== fillRgb || nextA !== fillA) {
2425
+ flushBatchFill();
2426
+ fillRgb = nextRgb;
2427
+ fillA = nextA;
2428
+ ctx.fillStyle = rgbToCss(fillRgb, fillA);
2429
+ }
1844
2430
  break;
2431
+ }
1845
2432
  case 2:
1846
2433
  lineW = nums[ni++];
1847
2434
  lineRgb = nums[ni++];
@@ -1851,17 +2438,30 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1851
2438
  break;
1852
2439
  case 3: {
1853
2440
  const x = nums[ni++], y = nums[ni++], w = nums[ni++], h = nums[ni++];
1854
- if (fillA > 0) ctx.fillRect(x, y, w, h);
2441
+ if (fillA >= 1) {
2442
+ if (!batchFillOpen) {
2443
+ ctx.beginPath();
2444
+ batchFillOpen = true;
2445
+ }
2446
+ ctx.rect(x, y, w, h);
2447
+ } else if (fillA > 0) {
2448
+ flushBatchFill();
2449
+ ctx.fillRect(x, y, w, h);
2450
+ }
1855
2451
  break;
1856
2452
  }
1857
2453
  case 4: {
1858
2454
  const x = nums[ni++], y = nums[ni++], w = nums[ni++], h = nums[ni++];
1859
- if (lineA > 0 && lineW > 0) ctx.strokeRect(x, y, w, h);
2455
+ if (lineA > 0 && lineW > 0) {
2456
+ flushBatchFill();
2457
+ ctx.strokeRect(x, y, w, h);
2458
+ }
1860
2459
  break;
1861
2460
  }
1862
2461
  case 5: {
1863
2462
  const x = nums[ni++], y = nums[ni++], w = nums[ni++], h = nums[ni++], r = nums[ni++];
1864
2463
  if (fillA > 0 && w > 0 && h > 0) {
2464
+ flushBatchFill();
1865
2465
  roundedRectPath(ctx, x, y, w, h, r);
1866
2466
  ctx.fill();
1867
2467
  }
@@ -1870,6 +2470,7 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1870
2470
  case 6: {
1871
2471
  const x = nums[ni++], y = nums[ni++], w = nums[ni++], h = nums[ni++], r = nums[ni++];
1872
2472
  if (lineA > 0 && lineW > 0 && w > 0 && h > 0) {
2473
+ flushBatchFill();
1873
2474
  roundedRectPath(ctx, x, y, w, h, r);
1874
2475
  ctx.stroke();
1875
2476
  }
@@ -1877,7 +2478,15 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1877
2478
  }
1878
2479
  case 7: {
1879
2480
  const cx = nums[ni++], cy = nums[ni++], r = nums[ni++];
1880
- if (fillA > 0 && r > 0) {
2481
+ if (fillA >= 1 && r > 0) {
2482
+ if (!batchFillOpen) {
2483
+ ctx.beginPath();
2484
+ batchFillOpen = true;
2485
+ }
2486
+ ctx.moveTo(cx + r, cy);
2487
+ ctx.arc(cx, cy, r, 0, Math.PI * 2);
2488
+ } else if (fillA > 0 && r > 0) {
2489
+ flushBatchFill();
1881
2490
  ctx.beginPath();
1882
2491
  ctx.arc(cx, cy, r, 0, Math.PI * 2);
1883
2492
  ctx.fill();
@@ -1887,6 +2496,7 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1887
2496
  case 8: {
1888
2497
  const cx = nums[ni++], cy = nums[ni++], r = nums[ni++];
1889
2498
  if (lineA > 0 && lineW > 0 && r > 0) {
2499
+ flushBatchFill();
1890
2500
  ctx.beginPath();
1891
2501
  ctx.arc(cx, cy, r, 0, Math.PI * 2);
1892
2502
  ctx.stroke();
@@ -1895,7 +2505,15 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1895
2505
  }
1896
2506
  case 9: {
1897
2507
  const cx = nums[ni++], cy = nums[ni++], w = nums[ni++], h = nums[ni++];
1898
- if (fillA > 0 && w > 0 && h > 0) {
2508
+ if (fillA >= 1 && w > 0 && h > 0) {
2509
+ if (!batchFillOpen) {
2510
+ ctx.beginPath();
2511
+ batchFillOpen = true;
2512
+ }
2513
+ ctx.moveTo(cx + w * .5, cy);
2514
+ ctx.ellipse(cx, cy, w * .5, h * .5, 0, 0, Math.PI * 2);
2515
+ } else if (fillA > 0 && w > 0 && h > 0) {
2516
+ flushBatchFill();
1899
2517
  ctx.beginPath();
1900
2518
  ctx.ellipse(cx, cy, w * .5, h * .5, 0, 0, Math.PI * 2);
1901
2519
  ctx.fill();
@@ -1905,6 +2523,7 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1905
2523
  case 10: {
1906
2524
  const cx = nums[ni++], cy = nums[ni++], w = nums[ni++], h = nums[ni++];
1907
2525
  if (lineA > 0 && lineW > 0 && w > 0 && h > 0) {
2526
+ flushBatchFill();
1908
2527
  ctx.beginPath();
1909
2528
  ctx.ellipse(cx, cy, w * .5, h * .5, 0, 0, Math.PI * 2);
1910
2529
  ctx.stroke();
@@ -1914,6 +2533,7 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1914
2533
  case 11: {
1915
2534
  const x0 = nums[ni++], y0 = nums[ni++], x1 = nums[ni++], y1 = nums[ni++], x2 = nums[ni++], y2 = nums[ni++];
1916
2535
  if (fillA > 0) {
2536
+ flushBatchFill();
1917
2537
  ctx.beginPath();
1918
2538
  ctx.moveTo(x0, y0);
1919
2539
  ctx.lineTo(x1, y1);
@@ -1926,6 +2546,7 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1926
2546
  case 12: {
1927
2547
  const x0 = nums[ni++], y0 = nums[ni++], x1 = nums[ni++], y1 = nums[ni++], x2 = nums[ni++], y2 = nums[ni++];
1928
2548
  if (lineA > 0 && lineW > 0) {
2549
+ flushBatchFill();
1929
2550
  ctx.beginPath();
1930
2551
  ctx.moveTo(x0, y0);
1931
2552
  ctx.lineTo(x1, y1);
@@ -1938,6 +2559,7 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1938
2559
  case 13: {
1939
2560
  const x0 = nums[ni++], y0 = nums[ni++], x1 = nums[ni++], y1 = nums[ni++];
1940
2561
  if (lineA > 0 && lineW > 0) {
2562
+ flushBatchFill();
1941
2563
  ctx.beginPath();
1942
2564
  ctx.moveTo(x0, y0);
1943
2565
  ctx.lineTo(x1, y1);
@@ -1946,6 +2568,7 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1946
2568
  break;
1947
2569
  }
1948
2570
  case 14:
2571
+ flushBatchFill();
1949
2572
  ctx.beginPath();
1950
2573
  break;
1951
2574
  case 15:
@@ -1974,6 +2597,7 @@ var Renderer2D = class Renderer2D extends EventEmitter {
1974
2597
  break;
1975
2598
  case 21: if (lineA > 0 && lineW > 0) ctx.stroke();
1976
2599
  }
2600
+ flushBatchFill();
1977
2601
  }
1978
2602
  renderInstancedBatch(batch, ctx) {
1979
2603
  const cols = batch.columns;
@@ -2007,7 +2631,7 @@ var Renderer2D = class Renderer2D extends EventEmitter {
2007
2631
  if (sx !== 1 || sy !== 1) ctx.scale(sx, sy);
2008
2632
  if (rgb !== 0xffffff && fr.cutWidth > 0 && fr.cutHeight > 0) {
2009
2633
  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);
2634
+ cachedTinted = this.getTintedSource(srcImg, fr.cutX, fr.cutY, fr.cutWidth, fr.cutHeight, rgb, false, fr.source);
2011
2635
  lastTintImg = srcImg;
2012
2636
  lastCutX = fr.cutX;
2013
2637
  lastCutY = fr.cutY;
@@ -2034,6 +2658,109 @@ var Renderer2D = class Renderer2D extends EventEmitter {
2034
2658
  this.curTris += vis * 2;
2035
2659
  }
2036
2660
  }
2661
+ renderShapeBatch(batch, ctx) {
2662
+ const cols = batch.columns;
2663
+ if (!cols || cols.count <= 0) return;
2664
+ const baseAlpha = ctx.globalAlpha;
2665
+ const n = Math.min(cols.count, batch.maxCount, cols.x.length, cols.y.length);
2666
+ const oxRatio = batch.originX;
2667
+ const oyRatio = batch.originY;
2668
+ const wCol = typeof cols.width === "object" && cols.width ? cols.width : null;
2669
+ const wDef = typeof cols.width === "number" ? cols.width : batch.defaultWidth;
2670
+ const hCol = typeof cols.height === "object" && cols.height ? cols.height : null;
2671
+ const hDef = typeof cols.height === "number" ? cols.height : typeof cols.width === "number" ? cols.width : batch.defaultHeight;
2672
+ const rCol = typeof cols.radius === "object" && cols.radius ? cols.radius : null;
2673
+ const rDef = typeof cols.radius === "number" ? cols.radius : batch.defaultRadius;
2674
+ const fcCol = typeof cols.fillColor === "object" && cols.fillColor ? cols.fillColor : null;
2675
+ const fcDef = typeof cols.fillColor === "number" ? cols.fillColor : batch.defaultFillColor;
2676
+ const faCol = typeof cols.fillAlpha === "object" && cols.fillAlpha ? cols.fillAlpha : null;
2677
+ const faDef = typeof cols.fillAlpha === "number" ? cols.fillAlpha : batch.defaultFillAlpha;
2678
+ const bcCol = typeof cols.borderColor === "object" && cols.borderColor ? cols.borderColor : null;
2679
+ const bcDef = typeof cols.borderColor === "number" ? cols.borderColor : batch.defaultBorderColor;
2680
+ const baCol = typeof cols.borderAlpha === "object" && cols.borderAlpha ? cols.borderAlpha : null;
2681
+ const baDef = typeof cols.borderAlpha === "number" ? cols.borderAlpha : batch.defaultBorderAlpha;
2682
+ const bwCol = typeof cols.borderWidth === "object" && cols.borderWidth ? cols.borderWidth : null;
2683
+ const bwDef = typeof cols.borderWidth === "number" ? cols.borderWidth : batch.defaultBorderWidth;
2684
+ const rotCol = cols.rotation ?? null;
2685
+ const ordCol = cols.order ?? null;
2686
+ let vis = 0;
2687
+ let lastFc = -1, lastFa = -1, fillCss = "";
2688
+ let lastBc = -1, lastBa = -1, borderCss = "";
2689
+ for (let i = 0; i < n; i++) {
2690
+ const s = ordCol ? ordCol[i] : i;
2691
+ const w = wCol ? wCol[s] : wDef;
2692
+ const h = hCol ? hCol[s] : wCol ? w : hDef;
2693
+ if (w <= 0 || h <= 0) continue;
2694
+ const fa = faCol ? faCol[s] : faDef;
2695
+ const bw = bwCol ? bwCol[s] : bwDef;
2696
+ const ba = bw > 0 ? baCol ? baCol[s] : baDef : 0;
2697
+ if (fa <= 0 && ba <= 0) continue;
2698
+ const rad = Math.max(0, Math.min(rCol ? rCol[s] : rDef, Math.min(w, h) * .5));
2699
+ const px = cols.x[s];
2700
+ const py = cols.y[s];
2701
+ const rot = rotCol ? rotCol[s] : 0;
2702
+ if (fa > 0) {
2703
+ const fc = fcCol ? fcCol[s] : fcDef;
2704
+ if (fc !== lastFc || fa !== lastFa) {
2705
+ lastFc = fc;
2706
+ lastFa = fa;
2707
+ fillCss = rgbToCss(fc, fa);
2708
+ }
2709
+ }
2710
+ if (ba > 0) {
2711
+ const bc = bcCol ? bcCol[s] : bcDef;
2712
+ if (bc !== lastBc || ba !== lastBa) {
2713
+ lastBc = bc;
2714
+ lastBa = ba;
2715
+ borderCss = rgbToCss(bc, ba);
2716
+ }
2717
+ }
2718
+ const rx = rot === 0 ? px - w * oxRatio : -w * oxRatio;
2719
+ const ry = rot === 0 ? py - h * oyRatio : -h * oyRatio;
2720
+ if (rot !== 0) {
2721
+ ctx.save();
2722
+ ctx.translate(px, py);
2723
+ ctx.rotate(rot);
2724
+ }
2725
+ if (rad <= 0 && bw <= 0) {
2726
+ ctx.fillStyle = fillCss;
2727
+ ctx.fillRect(rx, ry, w, h);
2728
+ } else if (Math.abs(w - h) <= 1e-4 && rad >= w * .5 - 1e-4) {
2729
+ ctx.beginPath();
2730
+ ctx.arc(rx + w * .5, ry + h * .5, Math.max(0, w * .5 - bw * .5), 0, Math.PI * 2);
2731
+ if (fa > 0) {
2732
+ ctx.fillStyle = fillCss;
2733
+ ctx.fill();
2734
+ }
2735
+ if (ba > 0 && bw > 0) {
2736
+ ctx.lineWidth = bw;
2737
+ ctx.strokeStyle = borderCss;
2738
+ ctx.stroke();
2739
+ }
2740
+ } else {
2741
+ roundedRectPath(ctx, rx + bw * .5, ry + bw * .5, Math.max(0, w - bw), Math.max(0, h - bw), Math.max(0, rad - bw * .5));
2742
+ if (fa > 0) {
2743
+ ctx.fillStyle = fillCss;
2744
+ ctx.fill();
2745
+ }
2746
+ if (ba > 0 && bw > 0) {
2747
+ ctx.lineWidth = bw;
2748
+ ctx.strokeStyle = borderCss;
2749
+ ctx.stroke();
2750
+ }
2751
+ }
2752
+ if (rot !== 0) ctx.restore();
2753
+ vis++;
2754
+ }
2755
+ ctx.globalAlpha = baseAlpha;
2756
+ if (vis > 0) {
2757
+ this.curDrawCalls++;
2758
+ this.curFlushes++;
2759
+ this.curQuads += vis;
2760
+ this.curTris += vis * 2;
2761
+ this.curSdfPanels += vis;
2762
+ }
2763
+ }
2037
2764
  /** Create an offscreen Canvas2D render target backed by a registered Stage `Texture` (`key`). */
2038
2765
  createRenderTarget(key, width, height, textures, filterMode = FilterMode.LINEAR) {
2039
2766
  const w = Math.max(1, Math.round(width));
@@ -2046,21 +2773,30 @@ var Renderer2D = class Renderer2D extends EventEmitter {
2046
2773
  const tex = textures.addCanvas(key, rtCanvas);
2047
2774
  if (!tex) throw new Error("Stage: failed to register Canvas2D RenderTarget texture");
2048
2775
  tex.source[0]?.setFilter(filterMode);
2776
+ const rtCamera = new Camera(w, h, true);
2049
2777
  const rtRenderer = new Renderer2D(rtCanvas, w, h);
2050
2778
  return {
2051
2779
  key,
2052
2780
  width: w,
2053
2781
  height: h,
2054
2782
  texture: tex,
2783
+ camera: rtCamera,
2055
2784
  _rtRenderer: rtRenderer,
2785
+ readPixels: (out) => {
2786
+ const byteLen = w * h * 4;
2787
+ const dst = out && out.length >= byteLen ? out : new Uint8Array(byteLen);
2788
+ const img = rtRenderer.ctx.getImageData(0, 0, w, h);
2789
+ dst.set(img.data.subarray(0, byteLen));
2790
+ return dst;
2791
+ },
2056
2792
  destroy: () => {
2057
2793
  rtRenderer.destroy();
2058
2794
  textures.remove(key);
2059
2795
  }
2060
2796
  };
2061
2797
  }
2062
- /** Render a `DisplayList` (or callback) into an offscreen `StageRenderTarget` in Canvas2D / Headless Node. */
2063
- renderToTarget(target, content, camera) {
2798
+ /** Render a `DisplayList` (or callback) into an offscreen `StageRenderTarget` in Canvas2D / Headless Node (`camera` defaults to `target.camera`). */
2799
+ renderToTarget(target, content, camera = target.camera) {
2064
2800
  const sub = target._rtRenderer;
2065
2801
  if (!sub) return;
2066
2802
  if (typeof content === "function") {
@@ -2068,7 +2804,10 @@ var Renderer2D = class Renderer2D extends EventEmitter {
2068
2804
  content(sub, camera);
2069
2805
  } else sub.render(content, camera);
2070
2806
  const src = target.texture.source[0];
2071
- if (src) src.dirty = true;
2807
+ if (src) {
2808
+ src.version++;
2809
+ src.dirty = true;
2810
+ }
2072
2811
  }
2073
2812
  renderBlitter(blitter, ctx) {
2074
2813
  const list = blitter.children.list;
@@ -2166,6 +2905,9 @@ var Renderer2D = class Renderer2D extends EventEmitter {
2166
2905
  case "InstancedBatch":
2167
2906
  this.renderInstancedBatch(obj, ctx);
2168
2907
  break;
2908
+ case "ShapeBatch":
2909
+ this.renderShapeBatch(obj, ctx);
2910
+ break;
2169
2911
  case "Container": {
2170
2912
  const list = obj.sortedChildren();
2171
2913
  for (let i = 0; i < list.length; i++) this.renderNode(list[i], camera, ctx, false);
@@ -2206,6 +2948,7 @@ var Renderer2D = class Renderer2D extends EventEmitter {
2206
2948
  }
2207
2949
  destroy() {
2208
2950
  this.removeAllListeners();
2951
+ this.tintCache.clear();
2209
2952
  this.tintCanvas = null;
2210
2953
  this.tintCtx = null;
2211
2954
  }
@@ -2246,7 +2989,7 @@ const MAX_VERTS = 16384;
2246
2989
  const MAX_INDICES = 32768;
2247
2990
  const VERT_FLOATS = 6;
2248
2991
  const VERT_STRIDE = 24;
2249
- const MAX_SDF_PANELS = 1024;
2992
+ const MAX_SDF_PANELS = 16384;
2250
2993
  const SDF_FLOATS = 16;
2251
2994
  const SDF_STRIDE = 64;
2252
2995
  const WGSL_BATCH_SRC = `
@@ -2945,18 +3688,13 @@ var RendererWebGpu = class extends EventEmitter {
2945
3688
  this.vertCount = bv + 3;
2946
3689
  this.indexCount = ii + 3;
2947
3690
  }
2948
- renderPanel(panel, m, alpha) {
2949
- if (this.sdfCount >= MAX_SDF_PANELS) return;
3691
+ pushSdfInstance(m, rx, ry, w, h, rTL, rTR, rBR, rBL, borderW, pixelStep, fillAbgr, borderAbgr, blend) {
3692
+ if (this.sdfCount >= MAX_SDF_PANELS || w <= 0 || h <= 0) return;
2950
3693
  if (this.indexCount > this.cmdStartIndex) this.flushPendingBatch();
2951
- if (this.curBlend !== panel.blendMode && this.sdfCount > this.sdfCmdStart) this.flushPendingSdf();
2952
- this.curBlend = panel.blendMode;
2953
- const w = panel.width;
2954
- const h = panel.height;
2955
- if (w <= 0 || h <= 0) return;
2956
- const ox = panel.displayOriginX;
2957
- const oy = panel.displayOriginY;
2958
- const tx = m.a * -ox + m.c * -oy + m.tx;
2959
- const ty = m.b * -ox + m.d * -oy + m.ty;
3694
+ if (this.curBlend !== blend && this.sdfCount > this.sdfCmdStart) this.flushPendingSdf();
3695
+ this.curBlend = blend;
3696
+ const tx = m.a * rx + m.c * ry + m.tx;
3697
+ const ty = m.b * rx + m.d * ry + m.ty;
2960
3698
  const maxR = Math.min(w, h) * .5;
2961
3699
  const base = this.sdfCount * SDF_FLOATS;
2962
3700
  const f = this.sdfF32;
@@ -2969,16 +3707,22 @@ var RendererWebGpu = class extends EventEmitter {
2969
3707
  f[base + 5] = ty;
2970
3708
  f[base + 6] = w;
2971
3709
  f[base + 7] = h;
2972
- f[base + 8] = Math.min(maxR, panel.radiusTL);
2973
- f[base + 9] = Math.min(maxR, panel.radiusTR);
2974
- f[base + 10] = Math.min(maxR, panel.radiusBR);
2975
- f[base + 11] = Math.min(maxR, panel.radiusBL);
2976
- f[base + 12] = panel.borderWidth;
2977
- f[base + 13] = panel.pixelStep;
2978
- u[base + 14] = packColorAbgr(panel.fillColor, panel.fillAlpha * alpha);
2979
- u[base + 15] = packColorAbgr(panel.borderColor, panel.borderAlpha * alpha);
3710
+ f[base + 8] = Math.max(0, Math.min(maxR, rTL));
3711
+ f[base + 9] = Math.max(0, Math.min(maxR, rTR));
3712
+ f[base + 10] = Math.max(0, Math.min(maxR, rBR));
3713
+ f[base + 11] = Math.max(0, Math.min(maxR, rBL));
3714
+ f[base + 12] = Math.max(0, Math.min(maxR, borderW));
3715
+ f[base + 13] = pixelStep;
3716
+ u[base + 14] = fillAbgr;
3717
+ u[base + 15] = borderAbgr;
2980
3718
  this.sdfCount++;
2981
3719
  }
3720
+ renderPanel(panel, m, alpha) {
3721
+ const w = panel.width;
3722
+ const h = panel.height;
3723
+ if (w <= 0 || h <= 0) return;
3724
+ this.pushSdfInstance(m, -panel.displayOriginX, -panel.displayOriginY, w, h, panel.radiusTL, panel.radiusTR, panel.radiusBR, panel.radiusBL, panel.borderWidth, panel.pixelStep, packColorAbgr(panel.fillColor, panel.fillAlpha * alpha), packColorAbgr(panel.borderColor, panel.borderAlpha * alpha), panel.blendMode);
3725
+ }
2982
3726
  renderGraphics(g, m, alpha) {
2983
3727
  const ops = g.ops;
2984
3728
  const nums = g.nums;
@@ -3021,17 +3765,18 @@ var RendererWebGpu = class extends EventEmitter {
3021
3765
  lineRgb = nums[ni++];
3022
3766
  lineA = nums[ni++];
3023
3767
  break;
3024
- case 3:
3025
- case 5: {
3768
+ case 3: {
3026
3769
  const x = nums[ni++], y = nums[ni++], w = nums[ni++], h = nums[ni++];
3027
- if (op === 5) ni++;
3028
3770
  if (fillA * alpha > 0) this.pushQuad(m, x, y, x + w, y + h, 0, 0, 1, 1, packColorAbgr(fillRgb, fillA * alpha), 2, g.blendMode, this.dummyEntry.bindGroupLinear);
3029
3771
  break;
3030
3772
  }
3031
- case 4:
3032
- case 6: {
3773
+ case 5: {
3774
+ const x = nums[ni++], y = nums[ni++], w = nums[ni++], h = nums[ni++], r = nums[ni++];
3775
+ if (fillA * alpha > 0 && w > 0 && h > 0) this.pushSdfInstance(m, x, y, w, h, r, r, r, r, 0, 0, packColorAbgr(fillRgb, fillA * alpha), 0, g.blendMode);
3776
+ break;
3777
+ }
3778
+ case 4: {
3033
3779
  const x = nums[ni++], y = nums[ni++], w = nums[ni++], h = nums[ni++];
3034
- if (op === 6) ni++;
3035
3780
  if (lineA * alpha > 0 && lineW > 0) {
3036
3781
  const abgr = packColorAbgr(lineRgb, lineA * alpha);
3037
3782
  lineSeg(x, y, x + w, y, abgr);
@@ -3041,34 +3786,59 @@ var RendererWebGpu = class extends EventEmitter {
3041
3786
  }
3042
3787
  break;
3043
3788
  }
3044
- case 7:
3789
+ case 6: {
3790
+ const x = nums[ni++], y = nums[ni++], w = nums[ni++], h = nums[ni++], r = nums[ni++];
3791
+ if (lineA * alpha > 0 && lineW > 0 && w > 0 && h > 0) {
3792
+ const hw = lineW * .5, rad = Math.max(0, r) + hw;
3793
+ this.pushSdfInstance(m, x - hw, y - hw, w + lineW, h + lineW, rad, rad, rad, rad, lineW, 0, 0, packColorAbgr(lineRgb, lineA * alpha), g.blendMode);
3794
+ }
3795
+ break;
3796
+ }
3797
+ case 7: {
3798
+ const cx = nums[ni++], cy = nums[ni++], r = nums[ni++];
3799
+ if (fillA * alpha > 0 && r > 0) this.pushSdfInstance(m, cx - r, cy - r, r * 2, r * 2, r, r, r, r, 0, 0, packColorAbgr(fillRgb, fillA * alpha), 0, g.blendMode);
3800
+ break;
3801
+ }
3045
3802
  case 9: {
3046
- const cx = nums[ni++], cy = nums[ni++];
3047
- const rx = op === 7 ? nums[ni++] : nums[ni++] * .5;
3048
- const ry = op === 7 ? rx : nums[ni++] * .5;
3803
+ const cx = nums[ni++], cy = nums[ni++], w = nums[ni++], h = nums[ni++];
3804
+ const rx = w * .5, ry = h * .5;
3049
3805
  if (fillA * alpha > 0 && rx > 0 && ry > 0) {
3050
- const segs = Math.max(12, Math.min(48, Math.ceil(Math.max(rx, ry) * 1.4)));
3051
- const abgr = packColorAbgr(fillRgb, fillA * alpha);
3052
- for (let s = 0; s < segs; s++) {
3053
- const a0 = s / segs * Math.PI * 2;
3054
- const a1 = (s + 1) / segs * Math.PI * 2;
3055
- this.pushTri(m, cx, cy, cx + Math.cos(a0) * rx, cy + Math.sin(a0) * ry, cx + Math.cos(a1) * rx, cy + Math.sin(a1) * ry, abgr, g.blendMode);
3806
+ if (Math.abs(w - h) <= 1e-4) this.pushSdfInstance(m, cx - rx, cy - ry, w, h, rx, rx, rx, rx, 0, 0, packColorAbgr(fillRgb, fillA * alpha), 0, g.blendMode);
3807
+ else {
3808
+ const segs = Math.max(12, Math.min(48, Math.ceil(Math.max(rx, ry) * 1.4)));
3809
+ const abgr = packColorAbgr(fillRgb, fillA * alpha);
3810
+ for (let s = 0; s < segs; s++) {
3811
+ const a0 = s / segs * Math.PI * 2;
3812
+ const a1 = (s + 1) / segs * Math.PI * 2;
3813
+ this.pushTri(m, cx, cy, cx + Math.cos(a0) * rx, cy + Math.sin(a0) * ry, cx + Math.cos(a1) * rx, cy + Math.sin(a1) * ry, abgr, g.blendMode);
3814
+ }
3056
3815
  }
3057
3816
  }
3058
3817
  break;
3059
3818
  }
3060
- case 8:
3819
+ case 8: {
3820
+ const cx = nums[ni++], cy = nums[ni++], r = nums[ni++];
3821
+ if (lineA * alpha > 0 && lineW > 0 && r > 0) {
3822
+ const ro = r + lineW * .5;
3823
+ this.pushSdfInstance(m, cx - ro, cy - ro, ro * 2, ro * 2, ro, ro, ro, ro, lineW, 0, 0, packColorAbgr(lineRgb, lineA * alpha), g.blendMode);
3824
+ }
3825
+ break;
3826
+ }
3061
3827
  case 10: {
3062
- const cx = nums[ni++], cy = nums[ni++];
3063
- const rx = op === 8 ? nums[ni++] : nums[ni++] * .5;
3064
- const ry = op === 8 ? rx : nums[ni++] * .5;
3828
+ const cx = nums[ni++], cy = nums[ni++], w = nums[ni++], h = nums[ni++];
3829
+ const rx = w * .5, ry = h * .5;
3065
3830
  if (lineA * alpha > 0 && lineW > 0 && rx > 0 && ry > 0) {
3066
- const segs = Math.max(12, Math.min(48, Math.ceil(Math.max(rx, ry) * 1.4)));
3067
- const abgr = packColorAbgr(lineRgb, lineA * alpha);
3068
- for (let s = 0; s < segs; s++) {
3069
- const a0 = s / segs * Math.PI * 2;
3070
- const a1 = (s + 1) / segs * Math.PI * 2;
3071
- lineSeg(cx + Math.cos(a0) * rx, cy + Math.sin(a0) * ry, cx + Math.cos(a1) * rx, cy + Math.sin(a1) * ry, abgr);
3831
+ if (Math.abs(w - h) <= 1e-4) {
3832
+ const ro = rx + lineW * .5;
3833
+ this.pushSdfInstance(m, cx - ro, cy - ro, ro * 2, ro * 2, ro, ro, ro, ro, lineW, 0, 0, packColorAbgr(lineRgb, lineA * alpha), g.blendMode);
3834
+ } else {
3835
+ const segs = Math.max(12, Math.min(48, Math.ceil(Math.max(rx, ry) * 1.4)));
3836
+ const abgr = packColorAbgr(lineRgb, lineA * alpha);
3837
+ for (let s = 0; s < segs; s++) {
3838
+ const a0 = s / segs * Math.PI * 2;
3839
+ const a1 = (s + 1) / segs * Math.PI * 2;
3840
+ lineSeg(cx + Math.cos(a0) * rx, cy + Math.sin(a0) * ry, cx + Math.cos(a1) * rx, cy + Math.sin(a1) * ry, abgr);
3841
+ }
3072
3842
  }
3073
3843
  }
3074
3844
  break;
@@ -3183,7 +3953,7 @@ var RendererWebGpu = class extends EventEmitter {
3183
3953
  }
3184
3954
  case "Rectangle": {
3185
3955
  const r = obj;
3186
- if (r.isFilled && r.fillAlpha * effAlpha > 0) {
3956
+ if (r.width > 0 && r.height > 0 && r.fillAlpha * effAlpha > 0) {
3187
3957
  const ox = r.displayOriginX, oy = r.displayOriginY;
3188
3958
  this.pushQuad(m, -ox, -oy, r.width - ox, r.height - oy, 0, 0, 1, 1, packColorAbgr(r.fillColor, r.fillAlpha * effAlpha), 2, r.blendMode, this.dummyEntry.bindGroupLinear);
3189
3959
  }
@@ -3260,6 +4030,48 @@ var RendererWebGpu = class extends EventEmitter {
3260
4030
  }
3261
4031
  break;
3262
4032
  }
4033
+ case "ShapeBatch": {
4034
+ const batch = obj;
4035
+ const cols = batch.columns;
4036
+ if (!cols || cols.count <= 0) break;
4037
+ const n = Math.min(cols.count, batch.maxCount, cols.x.length, cols.y.length);
4038
+ const wCol = typeof cols.width === "object" && cols.width ? cols.width : null;
4039
+ const wDef = typeof cols.width === "number" ? cols.width : batch.defaultWidth;
4040
+ const hCol = typeof cols.height === "object" && cols.height ? cols.height : null;
4041
+ const hDef = typeof cols.height === "number" ? cols.height : typeof cols.width === "number" ? cols.width : batch.defaultHeight;
4042
+ const rCol = typeof cols.radius === "object" && cols.radius ? cols.radius : null;
4043
+ const rDef = typeof cols.radius === "number" ? cols.radius : batch.defaultRadius;
4044
+ const fcCol = typeof cols.fillColor === "object" && cols.fillColor ? cols.fillColor : null;
4045
+ const fcDef = typeof cols.fillColor === "number" ? cols.fillColor : batch.defaultFillColor;
4046
+ const faCol = typeof cols.fillAlpha === "object" && cols.fillAlpha ? cols.fillAlpha : null;
4047
+ const faDef = typeof cols.fillAlpha === "number" ? cols.fillAlpha : batch.defaultFillAlpha;
4048
+ const bcCol = typeof cols.borderColor === "object" && cols.borderColor ? cols.borderColor : null;
4049
+ const bcDef = typeof cols.borderColor === "number" ? cols.borderColor : batch.defaultBorderColor;
4050
+ const baCol = typeof cols.borderAlpha === "object" && cols.borderAlpha ? cols.borderAlpha : null;
4051
+ const baDef = typeof cols.borderAlpha === "number" ? cols.borderAlpha : batch.defaultBorderAlpha;
4052
+ const bwCol = typeof cols.borderWidth === "object" && cols.borderWidth ? cols.borderWidth : null;
4053
+ const bwDef = typeof cols.borderWidth === "number" ? cols.borderWidth : batch.defaultBorderWidth;
4054
+ const rotCol = cols.rotation ?? null;
4055
+ const ordCol = cols.order ?? null;
4056
+ for (let i = 0; i < n; i++) {
4057
+ const s = ordCol ? ordCol[i] : i;
4058
+ const w = wCol ? wCol[s] : wDef;
4059
+ const h = hCol ? hCol[s] : wCol ? w : hDef;
4060
+ if (w <= 0 || h <= 0) continue;
4061
+ const fa = (faCol ? faCol[s] : faDef) * effAlpha;
4062
+ const bw = bwCol ? bwCol[s] : bwDef;
4063
+ const ba = bw > 0 ? (baCol ? baCol[s] : baDef) * effAlpha : 0;
4064
+ if (fa <= 0 && ba <= 0) continue;
4065
+ const rad = rCol ? rCol[s] : rDef;
4066
+ const fc = fcCol ? fcCol[s] : fcDef;
4067
+ const bc = bcCol ? bcCol[s] : bcDef;
4068
+ const rot = rotCol ? rotCol[s] : 0;
4069
+ const im = depth + 1 >= this.matPool.length ? createMatrix2D() : this.matPool[depth + 1];
4070
+ multiplyMat(m, cols.x[s], cols.y[s], 1, 1, rot, im);
4071
+ this.pushSdfInstance(im, -w * batch.originX, -h * batch.originY, w, h, rad, rad, rad, rad, bw, batch.pixelStep, packColorAbgr(fc, fa), bw > 0 ? packColorAbgr(bc, ba) : 0, batch.blendMode);
4072
+ }
4073
+ break;
4074
+ }
3263
4075
  case "Container": {
3264
4076
  const cont = obj;
3265
4077
  const mask = cont.clipMask;
@@ -3395,21 +4207,30 @@ var RendererWebGpu = class extends EventEmitter {
3395
4207
  const tex = textures.addCanvas(key, rtCanvas);
3396
4208
  if (!tex) throw new Error("Stage: failed to register WebGPU RenderTarget texture");
3397
4209
  tex.source[0]?.setFilter(filterMode);
4210
+ const rtCamera = new Camera(w, h, true);
3398
4211
  const rtRenderer = new Renderer2D(rtCanvas, w, h);
3399
4212
  return {
3400
4213
  key,
3401
4214
  width: w,
3402
4215
  height: h,
3403
4216
  texture: tex,
4217
+ camera: rtCamera,
3404
4218
  _rtRenderer: rtRenderer,
4219
+ readPixels: (out) => {
4220
+ const byteLen = w * h * 4;
4221
+ const dst = out && out.length >= byteLen ? out : new Uint8Array(byteLen);
4222
+ const img = rtRenderer.ctx.getImageData(0, 0, w, h);
4223
+ dst.set(img.data.subarray(0, byteLen));
4224
+ return dst;
4225
+ },
3405
4226
  destroy: () => {
3406
4227
  rtRenderer.destroy();
3407
4228
  textures.remove(key);
3408
4229
  }
3409
4230
  };
3410
4231
  }
3411
- /** Render a `DisplayList` (or callback) into an offscreen `StageRenderTarget` and mark its texture dirty for WebGPU upload. */
3412
- renderToTarget(target, content, camera) {
4232
+ /** Render a `DisplayList` (or callback) into an offscreen `StageRenderTarget` and mark its texture dirty for WebGPU upload (`camera` defaults to `target.camera`). */
4233
+ renderToTarget(target, content, camera = target.camera) {
3413
4234
  const sub = target._rtRenderer;
3414
4235
  if (!sub) return;
3415
4236
  if (typeof content === "function") {
@@ -3432,4 +4253,4 @@ var RendererWebGpu = class extends EventEmitter {
3432
4253
  } catch {}
3433
4254
  }
3434
4255
  };
3435
- export { TileSpriteObject as _, Container as a, DisplayObject as c, InstancedBatchObject as d, MsdfIconObject as f, TextObject as g, RectangleObject as h, BlitterObject as i, Graphics as l, PanelObject as m, requestWebGpuDevice as n, CustomPassObject as o, NineSliceObject as p, Renderer2D as r, DisplayList as s, RendererWebGpu as t, ImageObject as u };
4256
+ export { TextObject as _, Container as a, DisplayObject as c, InstancedBatchObject as d, MsdfIconObject as f, ShapeBatchObject as g, RectangleObject as h, BlitterObject as i, Graphics as l, PanelObject as m, requestWebGpuDevice as n, CustomPassObject as o, NineSliceObject as p, Renderer2D as r, DisplayList as s, RendererWebGpu as t, ImageObject as u, TileSpriteObject as v, Camera as y };