@phil65/demoreel 0.6.0 → 0.7.1

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.
Files changed (33) hide show
  1. package/README.md +8 -5
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/dist/args.js +1 -1
  4. package/dist/cli.js +3 -3
  5. package/dist/compose.d.ts +9 -1
  6. package/dist/compose.js +34 -2
  7. package/dist/idle.js +1 -1
  8. package/dist/index.d.ts +3 -3
  9. package/dist/index.js +2 -2
  10. package/dist/mcp.js +2 -2
  11. package/dist/project.d.ts +247 -11
  12. package/dist/project.js +244 -8
  13. package/dist/record.js +8 -0
  14. package/dist/renderer/assets/{CanvasPool-PBu3bHFZ.js → CanvasPool-SkgMbnEH.js} +1 -1
  15. package/dist/renderer/assets/{CanvasRenderer-HmF-4gyW.js → CanvasRenderer-CEGuSdsG.js} +1 -1
  16. package/dist/renderer/assets/{RenderTargetSystem-Dk1U4wDJ.js → RenderTargetSystem-um8Nv1HQ.js} +1 -1
  17. package/dist/renderer/assets/{WebGLRenderer-C0v9HBel.js → WebGLRenderer-BnY2xfDL.js} +1 -1
  18. package/dist/renderer/assets/{WebGPURenderer-Ce0-U9Q1.js → WebGPURenderer-D9KI_sD9.js} +1 -1
  19. package/dist/renderer/assets/{browserAll-DhvWQ7nM.js → browserAll-vQt6iTAv.js} +1 -1
  20. package/dist/renderer/assets/{canvasUtils-KRroregW.js → canvasUtils-CZLntkW8.js} +1 -1
  21. package/dist/renderer/assets/{getTexelRangeRects-D3pwCyRt.js → getTexelRangeRects-CRAnqulP.js} +1 -1
  22. package/dist/renderer/assets/{index-CE-lli1m.js → index-41-d13J1.js} +4 -4
  23. package/dist/renderer/assets/{init-DfmWKarH.js → init-D6nA7FlC.js} +1 -1
  24. package/dist/renderer/assets/webworkerAll-BEIrFubI.js +1 -0
  25. package/dist/renderer/index.html +1 -1
  26. package/dist/scene.d.ts +87 -1
  27. package/dist/scene.js +151 -1
  28. package/dist/types.d.ts +71 -1
  29. package/dist/voice.d.ts +8 -5
  30. package/dist/voice.js +43 -6
  31. package/package.json +2 -2
  32. package/skills/demoreel/SKILL.md +5 -1
  33. package/dist/renderer/assets/webworkerAll-B41hok0-.js +0 -1
package/dist/project.js CHANGED
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import fs from "node:fs";
7
7
  import path from "node:path";
8
+ import { boxToStage, stageLayout } from "./layout.js";
8
9
  export const PROJECT_VERSION = 2;
9
10
  export const CURSOR_TELEMETRY_VERSION = 2;
10
11
  export const DEFAULT_LOOK = {
@@ -12,10 +13,12 @@ export const DEFAULT_LOOK = {
12
13
  padding: 40,
13
14
  borderRadius: 14,
14
15
  shadowIntensity: 0.6,
16
+ showBlur: false,
15
17
  motionBlurAmount: 0.2,
16
18
  aspectRatio: "16:9",
17
19
  captionPosition: "auto",
18
20
  captionFontSize: 30,
21
+ captionAnimation: "none",
19
22
  showKeys: false,
20
23
  };
21
24
  /** Caption box in percent of the output canvas (OpenScreen annotation position/size). */
@@ -107,7 +110,7 @@ export function keycapAnnotations(actions, look = DEFAULT_LOOK, startZIndex = 1)
107
110
  };
108
111
  });
109
112
  }
110
- export function captionAnnotations(captions, look = DEFAULT_LOOK) {
113
+ export function captionAnnotations(captions, look = DEFAULT_LOOK, startZIndex = 1) {
111
114
  return captions.map((c, i) => {
112
115
  const r = captionRect(c.position ?? look.captionPosition);
113
116
  return {
@@ -128,17 +131,250 @@ export function captionAnnotations(captions, look = DEFAULT_LOOK) {
128
131
  fontStyle: "normal",
129
132
  textDecoration: "none",
130
133
  textAlign: "center",
131
- textAnimation: "none",
134
+ textAnimation: c.animation ?? look.captionAnimation ?? "none",
135
+ },
136
+ zIndex: startZIndex + i,
137
+ };
138
+ });
139
+ }
140
+ const DEFAULT_BASE_STYLE = {
141
+ color: "#ffffff",
142
+ backgroundColor: "transparent",
143
+ fontSize: 32,
144
+ fontFamily: "Inter",
145
+ fontWeight: "bold",
146
+ fontStyle: "normal",
147
+ textDecoration: "none",
148
+ textAlign: "left",
149
+ textAnimation: "none",
150
+ };
151
+ const MIME_BY_EXT = {
152
+ ".png": "image/png",
153
+ ".jpg": "image/jpeg",
154
+ ".jpeg": "image/jpeg",
155
+ ".webp": "image/webp",
156
+ ".svg": "image/svg+xml",
157
+ ".gif": "image/gif",
158
+ };
159
+ /** Resolves a `data:image/...` URL or reads a local image file and encodes it as a data URL. */
160
+ export function resolveImageDataUrl(src, baseDir) {
161
+ if (src.startsWith("data:image/"))
162
+ return src;
163
+ const resolved = path.isAbsolute(src) ? src : path.resolve(baseDir ?? process.cwd(), src);
164
+ if (!fs.existsSync(resolved)) {
165
+ throw new Error(`image annotation not found: ${resolved}`);
166
+ }
167
+ const ext = path.extname(resolved).toLowerCase();
168
+ const mime = MIME_BY_EXT[ext] ?? "image/png";
169
+ const b64 = fs.readFileSync(resolved).toString("base64");
170
+ return `data:${mime};base64,${b64}`;
171
+ }
172
+ function clampPct(v, min = 0, max = 100) {
173
+ return Math.round(Math.min(max, Math.max(min, v)) * 100) / 100;
174
+ }
175
+ const DEFAULT_BLUR_FREEHAND_POINTS = [
176
+ { x: 10, y: 30 },
177
+ { x: 25, y: 10 },
178
+ { x: 55, y: 8 },
179
+ { x: 82, y: 20 },
180
+ { x: 90, y: 45 },
181
+ { x: 78, y: 72 },
182
+ { x: 52, y: 90 },
183
+ { x: 22, y: 84 },
184
+ { x: 8, y: 58 },
185
+ ];
186
+ /** Converts recorded `BlurAnnotation`s into OpenScreen `type: "blur"` regions. */
187
+ export function blurAnnotations(blurs, opts) {
188
+ const z0 = opts.startZIndex ?? 1;
189
+ return blurs.map((b, i) => {
190
+ let x;
191
+ let y;
192
+ let width;
193
+ let height;
194
+ if (b.rect) {
195
+ ({ x, y, width, height } = b.rect);
196
+ }
197
+ else if (b.box) {
198
+ const pad = b.padding ?? 4;
199
+ const padded = {
200
+ x: Math.max(0, b.box.x - pad),
201
+ y: Math.max(0, b.box.y - pad),
202
+ width: b.box.width + pad * 2,
203
+ height: b.box.height + pad * 2,
204
+ };
205
+ const stage = boxToStage(opts.layout, opts.viewport, padded);
206
+ x = stage.x * 100;
207
+ y = stage.y * 100;
208
+ width = stage.w * 100;
209
+ height = stage.h * 100;
210
+ }
211
+ else {
212
+ x = 25;
213
+ y = 25;
214
+ width = 20;
215
+ height = 10;
216
+ }
217
+ const endMs = b.endMs === "end" ? Math.max(b.startMs + 100, opts.durationMs) : b.endMs;
218
+ return {
219
+ id: `blur-${i + 1}`,
220
+ startMs: Math.round(b.startMs),
221
+ endMs: Math.round(endMs),
222
+ type: "blur",
223
+ content: "",
224
+ position: { x: clampPct(x), y: clampPct(y) },
225
+ size: { width: clampPct(width, 1, 100), height: clampPct(height, 1, 100) },
226
+ style: { ...DEFAULT_BASE_STYLE },
227
+ zIndex: z0 + i,
228
+ blurData: {
229
+ type: b.type ?? "blur",
230
+ shape: b.shape ?? "rectangle",
231
+ color: b.color ?? "black",
232
+ intensity: Math.min(40, Math.max(2, b.intensity ?? 14)),
233
+ blockSize: Math.min(48, Math.max(4, b.blockSize ?? 12)),
234
+ freehandPoints: DEFAULT_BLUR_FREEHAND_POINTS.map((p) => ({ ...p })),
235
+ },
236
+ };
237
+ });
238
+ }
239
+ /** Places a directional arrow box just outside a target rect pointing toward it. */
240
+ function arrowRectForTarget(stage, dir, sizePct) {
241
+ const tx = stage.x * 100;
242
+ const ty = stage.y * 100;
243
+ const tw = stage.w * 100;
244
+ const th = stage.h * 100;
245
+ const cx = tx + tw / 2;
246
+ const cy = ty + th / 2;
247
+ const gap = 1.2;
248
+ const w = sizePct;
249
+ const h = sizePct;
250
+ let x = cx - w / 2;
251
+ let y = cy - h / 2;
252
+ if (dir === "down")
253
+ y = ty - h - gap;
254
+ else if (dir === "up")
255
+ y = ty + th + gap;
256
+ else if (dir === "right")
257
+ x = tx - w - gap;
258
+ else if (dir === "left")
259
+ x = tx + tw + gap;
260
+ else if (dir === "down-right") {
261
+ x = tx - w - gap * 0.5;
262
+ y = ty - h - gap * 0.5;
263
+ }
264
+ else if (dir === "down-left") {
265
+ x = tx + tw + gap * 0.5;
266
+ y = ty - h - gap * 0.5;
267
+ }
268
+ else if (dir === "up-right") {
269
+ x = tx - w - gap * 0.5;
270
+ y = ty + th + gap * 0.5;
271
+ }
272
+ else if (dir === "up-left") {
273
+ x = tx + tw + gap * 0.5;
274
+ y = ty + th + gap * 0.5;
275
+ }
276
+ return { x: clampPct(x, 0, 100 - w), y: clampPct(y, 0, 100 - h), width: w, height: h };
277
+ }
278
+ /** Converts recorded `ArrowAnnotation`s into OpenScreen `type: "figure"` arrow regions. */
279
+ export function arrowAnnotations(arrows, opts) {
280
+ const z0 = opts.startZIndex ?? 1;
281
+ return arrows.map((a, i) => {
282
+ const sizePct = Math.min(40, Math.max(3, a.size ?? 9));
283
+ const rect = a.rect
284
+ ? a.rect
285
+ : a.box
286
+ ? arrowRectForTarget(boxToStage(opts.layout, opts.viewport, a.box), a.direction, sizePct)
287
+ : { x: 45, y: 45, width: sizePct, height: sizePct };
288
+ return {
289
+ id: `arrow-${i + 1}`,
290
+ startMs: Math.round(a.startMs),
291
+ endMs: Math.round(a.endMs),
292
+ type: "figure",
293
+ content: "",
294
+ position: { x: clampPct(rect.x), y: clampPct(rect.y) },
295
+ size: { width: clampPct(rect.width, 1, 100), height: clampPct(rect.height, 1, 100) },
296
+ style: { ...DEFAULT_BASE_STYLE },
297
+ zIndex: z0 + i,
298
+ figureData: {
299
+ arrowDirection: a.direction,
300
+ color: a.color ?? "#ffcc00",
301
+ strokeWidth: a.strokeWidth ?? 4,
132
302
  },
133
- zIndex: i + 1,
134
303
  };
135
304
  });
136
305
  }
306
+ /** Converts recorded `ImageAnnotation`s (and optional `look.watermark`) into OpenScreen `type: "image"` regions. */
307
+ export function imageAnnotations(images, opts) {
308
+ const z0 = opts.startZIndex ?? 1;
309
+ const list = [...images];
310
+ if (opts.watermark) {
311
+ const wm = opts.watermark;
312
+ const w = wm.width ?? 10;
313
+ const h = wm.height ?? 8;
314
+ const pos = wm.position ?? "bottom-right";
315
+ let x;
316
+ let y;
317
+ if (typeof pos === "object") {
318
+ x = pos.x;
319
+ y = pos.y;
320
+ }
321
+ else {
322
+ x = pos.endsWith("left") ? 2.5 : 97.5 - w;
323
+ y = pos.startsWith("top") ? 2.5 : 97.5 - h;
324
+ }
325
+ list.push({
326
+ startMs: 0,
327
+ endMs: "end",
328
+ src: wm.src,
329
+ x,
330
+ y,
331
+ width: w,
332
+ height: h,
333
+ label: "watermark",
334
+ });
335
+ }
336
+ return list.map((img, i) => {
337
+ const dataUrl = resolveImageDataUrl(img.src, opts.baseDir);
338
+ const endMs = img.endMs === "end" ? Math.max(img.startMs + 100, opts.durationMs) : img.endMs;
339
+ return {
340
+ id: img.label === "watermark" ? "watermark" : `image-${i + 1}`,
341
+ startMs: Math.round(img.startMs),
342
+ endMs: Math.round(endMs),
343
+ type: "image",
344
+ content: dataUrl,
345
+ imageContent: dataUrl,
346
+ position: { x: clampPct(img.x), y: clampPct(img.y) },
347
+ size: { width: clampPct(img.width, 1, 100), height: clampPct(img.height, 1, 100) },
348
+ style: { ...DEFAULT_BASE_STYLE },
349
+ zIndex: z0 + i,
350
+ };
351
+ });
352
+ }
353
+ function normalizeCrop(crop) {
354
+ if (!crop)
355
+ return { x: 0, y: 0, width: 1, height: 1 };
356
+ const x = Math.min(0.95, Math.max(0, crop.x));
357
+ const y = Math.min(0.95, Math.max(0, crop.y));
358
+ const width = Math.min(1 - x, Math.max(0.05, crop.width));
359
+ const height = Math.min(1 - y, Math.max(0.05, crop.height));
360
+ return { x, y, width, height };
361
+ }
137
362
  export function buildProject(opts) {
138
363
  const look = { ...DEFAULT_LOOK, ...opts.look };
139
364
  const videoPath = path.resolve(opts.videoPath);
140
- const captions = captionAnnotations(opts.captions, look);
141
- const keycaps = keycapAnnotations(opts.actions ?? [], look, captions.length + 1);
365
+ const viewport = opts.viewport ?? { width: 1920, height: 1080 };
366
+ const layout = stageLayout(viewport, look);
367
+ const durationMs = opts.durationMs ?? Math.max(1000, ...opts.captions.map((c) => c.endMs), ...(opts.actions ?? []).map((a) => a.endMs));
368
+ let z = 1;
369
+ const blurs = blurAnnotations(opts.blurs ?? [], { viewport, layout, durationMs, startZIndex: z });
370
+ z += blurs.length;
371
+ const images = imageAnnotations(opts.images ?? [], { durationMs, baseDir: opts.baseDir, watermark: look.watermark, startZIndex: z });
372
+ z += images.length;
373
+ const arrows = arrowAnnotations(opts.arrows ?? [], { viewport, layout, startZIndex: z });
374
+ z += arrows.length;
375
+ const captions = captionAnnotations(opts.captions, look, z);
376
+ z += captions.length;
377
+ const keycaps = keycapAnnotations(opts.actions ?? [], look, z);
142
378
  return {
143
379
  version: PROJECT_VERSION,
144
380
  // Legacy field: OpenScreen <= 1.2 (v1 projects) only reads `videoPath`; >= 1.3 prefers `media`.
@@ -150,18 +386,18 @@ export function buildProject(opts) {
150
386
  editor: {
151
387
  wallpaper: look.wallpaper,
152
388
  shadowIntensity: look.shadowIntensity,
153
- showBlur: false,
389
+ showBlur: Boolean(look.showBlur),
154
390
  showTrimWaveform: true,
155
391
  motionBlurAmount: look.motionBlurAmount,
156
392
  borderRadius: look.borderRadius,
157
393
  padding: look.padding,
158
- cropRegion: { x: 0, y: 0, width: 1, height: 1 },
394
+ cropRegion: normalizeCrop(look.crop),
159
395
  zoomRegions: opts.zoomRegions,
160
396
  autoZoomEnabled: false,
161
397
  autoFocusAll: false,
162
398
  trimRegions: opts.trimRegions ?? [],
163
399
  speedRegions: opts.speedRegions ?? [],
164
- annotationRegions: [...captions, ...keycaps],
400
+ annotationRegions: [...blurs, ...images, ...arrows, ...captions, ...keycaps],
165
401
  aspectRatio: look.aspectRatio,
166
402
  webcamLayoutPreset: "picture-in-picture",
167
403
  webcamMaskShape: "rectangle",
package/dist/record.js CHANGED
@@ -126,9 +126,11 @@ export async function recordScenario(input, opts = {}) {
126
126
  const frameTimes = rec.frameTimes;
127
127
  fs.rmSync(framesDir, { recursive: true, force: true });
128
128
  timings.recordTotalMs = Date.now() - t0;
129
+ const baseDir = opts.scenarioFile ? path.dirname(path.resolve(opts.scenarioFile)) : process.cwd();
129
130
  const composed = compose({
130
131
  name: session.scenario.name,
131
132
  outDir,
133
+ baseDir,
132
134
  videoPath,
133
135
  durationMs,
134
136
  frameCount,
@@ -136,6 +138,9 @@ export async function recordScenario(input, opts = {}) {
136
138
  frameSize: rec.frameSize,
137
139
  actions: scene.actions,
138
140
  captions: scene.captions,
141
+ blurs: scene.blurs,
142
+ arrows: scene.arrows,
143
+ images: scene.images,
139
144
  voiceCues: scene.voiceCues,
140
145
  samples: scene.samples,
141
146
  frameTimes,
@@ -154,6 +159,9 @@ export async function recordScenario(input, opts = {}) {
154
159
  samples: scene.samples,
155
160
  actions: scene.actions,
156
161
  captions: scene.captions,
162
+ ...(scene.blurs.length ? { blurs: scene.blurs } : {}),
163
+ ...(scene.arrows.length ? { arrows: scene.arrows } : {}),
164
+ ...(scene.images.length ? { images: scene.images } : {}),
157
165
  ...(scene.voiceCues.length ? { voiceCues: scene.voiceCues } : {}),
158
166
  frameTimes,
159
167
  frameCount,
@@ -1 +1 @@
1
- import{Q as e,_t as t,ct as n,ht as r,mt as i,q as a,st as o,yt as s}from"./index-CE-lli1m.js";var c=32767;function l(e,t){return(e<<17)+(t<<2)}var u=new class{constructor(t){this._buckets=new Map,this._screens=new e,this._enableFullScreen=!1,this.canvasOptions=t||{}}get enableFullScreen(){return t(s,`CanvasPool.enableFullScreen is no longer used, the pool sizes canvases to the screens registered with setScreenSize.`),this._enableFullScreen}set enableFullScreen(e){t(s,`CanvasPool.enableFullScreen is no longer used, the pool sizes canvases to the screens registered with setScreenSize.`),this._enableFullScreen=e}_createCanvasAndContext(e,t){let n=a.get().createCanvas();return n.width=e,n.height=t,{canvas:n,context:n.getContext(`2d`)}}getOptimalCanvasAndContext(e,t,r=1){let{width:i,height:a}=this.getOptimalSize(e,t,r);(i>c||a>c)&&n(`CanvasPool: ${i}x${a} is larger than the ${c}px pool key limit, canvases of this size may be pooled together`);let o=l(i,a),s=this._buckets.get(o);s||(s=[],this._buckets.set(o,s));let u=s.pop();return u||=this._createCanvasAndContext(i,a),u}getOptimalSize(e,t,n=1){let i=Math.ceil(e*n-1e-6),a=Math.ceil(t*n-1e-6),o=r(i),s=this._screens.getFittingWidth(i),c=r(a),l=this._screens.getFittingHeight(a);return{width:s===void 0?o:Math.min(s,o),height:l===void 0?c:Math.min(l,c)}}returnCanvasAndContext(e){let{width:t,height:n}=e.canvas,r=this._buckets.get(l(t,n));r&&(e.context.resetTransform(),e.context.clearRect(0,0,t,n),r.push(e))}setScreenSize(e,t,n){this._screens.set(e,t,n)&&this._pruneScreenCanvases()}removeScreen(e){this._screens.remove(e)&&this._pruneScreenCanvases()}clear(){this._buckets.clear()}_pruneScreenCanvases(){for(let[e]of this._buckets){let t=e>>>17,n=e>>>2&32767;(!i(t)&&!this._screens.hasWidth(t)||!i(n)&&!this._screens.hasHeight(n))&&this._buckets.delete(e)}}};o.register(u);export{u as t};
1
+ import{Q as e,_t as t,ct as n,ht as r,mt as i,q as a,st as o,yt as s}from"./index-41-d13J1.js";var c=32767;function l(e,t){return(e<<17)+(t<<2)}var u=new class{constructor(t){this._buckets=new Map,this._screens=new e,this._enableFullScreen=!1,this.canvasOptions=t||{}}get enableFullScreen(){return t(s,`CanvasPool.enableFullScreen is no longer used, the pool sizes canvases to the screens registered with setScreenSize.`),this._enableFullScreen}set enableFullScreen(e){t(s,`CanvasPool.enableFullScreen is no longer used, the pool sizes canvases to the screens registered with setScreenSize.`),this._enableFullScreen=e}_createCanvasAndContext(e,t){let n=a.get().createCanvas();return n.width=e,n.height=t,{canvas:n,context:n.getContext(`2d`)}}getOptimalCanvasAndContext(e,t,r=1){let{width:i,height:a}=this.getOptimalSize(e,t,r);(i>c||a>c)&&n(`CanvasPool: ${i}x${a} is larger than the ${c}px pool key limit, canvases of this size may be pooled together`);let o=l(i,a),s=this._buckets.get(o);s||(s=[],this._buckets.set(o,s));let u=s.pop();return u||=this._createCanvasAndContext(i,a),u}getOptimalSize(e,t,n=1){let i=Math.ceil(e*n-1e-6),a=Math.ceil(t*n-1e-6),o=r(i),s=this._screens.getFittingWidth(i),c=r(a),l=this._screens.getFittingHeight(a);return{width:s===void 0?o:Math.min(s,o),height:l===void 0?c:Math.min(l,c)}}returnCanvasAndContext(e){let{width:t,height:n}=e.canvas,r=this._buckets.get(l(t,n));r&&(e.context.resetTransform(),e.context.clearRect(0,0,t,n),r.push(e))}setScreenSize(e,t,n){this._screens.set(e,t,n)&&this._pruneScreenCanvases()}removeScreen(e){this._screens.remove(e)&&this._pruneScreenCanvases()}clear(){this._buckets.clear()}_pruneScreenCanvases(){for(let[e]of this._buckets){let t=e>>>17,n=e>>>2&32767;(!i(t)&&!this._screens.hasWidth(t)||!i(n)&&!this._screens.hasHeight(n))&&this._buckets.delete(e)}}};o.register(u);export{u as t};
@@ -1 +1 @@
1
- import{Ct as e,Dt as t,Et as n,K as r,L as i,O as a,St as o,a as s,ct as c,dt as l,et as u,i as d,lt as f,nt as p,o as m,q as h,r as g,s as _,t as v}from"./index-CE-lli1m.js";import{a as y,c as b,i as x,l as S,o as C,r as w,s as T,t as E}from"./RenderTargetSystem-Dk1U4wDJ.js";import{n as D,t as O}from"./canvasUtils-KRroregW.js";var k=class e{static _getPatternRepeat(e,t){let n=e&&e!==`clamp-to-edge`,r=t&&t!==`clamp-to-edge`;return n&&r?`repeat`:n?`repeat-x`:r?`repeat-y`:`no-repeat`}start(e,t,n){}execute(t,n){let r=n.elements;if(!r||!r.length)return;let i=t.renderer,a=i.canvasContext,s=a.activeContext;for(let t=0;t<r.length;t++){let c=r[t];if(!c.packAsQuad)continue;let l=c,d=l.texture,f=d?O.getCanvasSource(d):null;if(!f)continue;let m=d.source.style,h=a.smoothProperty,g=m.scaleMode!==`nearest`;s[h]!==g&&(s[h]=g),a.setBlendMode(n.blendMode);let _=i.globalUniforms.globalUniformData?.worldColor??0xffffffff,v=l.color,y=(_>>>24&255)/255,b=(v>>>24&255)/255,x=i.filter?.alphaMultiplier??1,S=y*b*x;if(S<=0)continue;s.globalAlpha=S;let C=_&0xffffff,w=v&0xffffff,T=u(p(w,C)),E=d.frame,D=m.addressModeU??m.addressMode,k=m.addressModeV??m.addressMode,A=e._getPatternRepeat(D,k),j=d.source._resolution??d.source.resolution??1,M=l.renderable?.renderGroup?.isCachedAsTexture,N=E.x*j,P=E.y*j,F=E.width*j,I=E.height*j,L=l.bounds,R=i.renderTarget.renderTarget.isRoot,z=L.minX,B=L.minY,V=L.maxX-L.minX,H=L.maxY-L.minY,U=d.rotate,W=d.uvs,G=Math.min(W.x0,W.x1,W.x2,W.x3,W.y0,W.y1,W.y2,W.y3),K=Math.max(W.x0,W.x1,W.x2,W.x3,W.y0,W.y1,W.y2,W.y3),q=A!==`no-repeat`&&(G<0||K>1),J=U&&(!!q||T===0xffffff&&!U);J?(e._tempPatternMatrix.copyFrom(l.transform),o.matrixAppendRotationInv(e._tempPatternMatrix,U,z,B,V,H),a.setContextTransform(e._tempPatternMatrix,l.roundPixels===1,void 0,M&&R)):a.setContextTransform(l.transform,l.roundPixels===1,void 0,M&&R);let Y=V,X=H,Z=J?0:z,Q=J?0:B;if(!J&&l.roundPixels===1&&(Z|=0,Q|=0),q){let t=f,n=T!==0xffffff&&!U,r=E.width<=d.source.width&&E.height<=d.source.height;n&&r&&(t=O.getTintedCanvas({texture:d},T));let i=s.createPattern(t,A);if(!i)continue;let a=Y,o=X;if(a===0||o===0)continue;let c=1/a,l=1/o,u=(W.x1-W.x0)*c,p=(W.y1-W.y0)*c,m=(W.x3-W.x0)*l,h=(W.y3-W.y0)*l,g=W.x0-u*Z-m*Q,_=W.y0-p*Z-h*Q,v=d.source.pixelWidth,y=d.source.pixelHeight;e._tempPatternMatrix.set(u*v,p*y,m*v,h*y,g*v,_*y),O.applyPatternTransform(i,e._tempPatternMatrix),s.fillStyle=i,s.fillRect(Z,Q,Y,X)}else{let e=T!==0xffffff||U?O.getTintedCanvas({texture:d},T):f,t=e!==f;s.drawImage(e,t?0:N,t?0:P,t?e.width:F,t?e.height:I,Z,Q,Y,X)}}}};k._tempPatternMatrix=new e,k.extension={type:[n.CanvasPipesAdaptor],name:`batch`};var A=k,j=class{constructor(e){this._colorStack=[],this._colorStackIndex=0,this._currentColor=0,this._renderer=e}buildStart(){this._colorStack[0]=15,this._colorStackIndex=1,this._currentColor=15}push(e,t,n){this._renderer.renderPipes.batch.break(n);let r=this._colorStack;r[this._colorStackIndex]=r[this._colorStackIndex-1]&e.mask;let i=this._colorStack[this._colorStackIndex];i!==this._currentColor&&(this._currentColor=i,n.add({renderPipeId:`colorMask`,colorMask:i,canBundle:!1})),this._colorStackIndex++}pop(e,t,n){this._renderer.renderPipes.batch.break(n);let r=this._colorStack;this._colorStackIndex--;let i=r[this._colorStackIndex-1];i!==this._currentColor&&(this._currentColor=i,n.add({renderPipeId:`colorMask`,colorMask:i,canBundle:!1}))}execute(e){}destroy(){this._renderer=null,this._colorStack=null}};j.extension={type:[n.CanvasPipes],name:`colorMask`};function M(e,t,n,r,i,a){a=Math.max(0,Math.min(a,Math.min(r,i)/2)),e.moveTo(t+a,n),e.lineTo(t+r-a,n),e.quadraticCurveTo(t+r,n,t+r,n+a),e.lineTo(t+r,n+i-a),e.quadraticCurveTo(t+r,n+i,t+r-a,n+i),e.lineTo(t+a,n+i),e.quadraticCurveTo(t,n+i,t,n+i-a),e.lineTo(t,n+a),e.quadraticCurveTo(t,n,t+a,n)}function N(e,t){switch(t.type){case`rectangle`:{let n=t;e.rect(n.x,n.y,n.width,n.height);break}case`roundedRectangle`:{let n=t;M(e,n.x,n.y,n.width,n.height,n.radius);break}case`circle`:{let n=t;e.moveTo(n.x+n.radius,n.y),e.arc(n.x,n.y,n.radius,0,Math.PI*2);break}case`ellipse`:{let n=t;e.ellipse?(e.moveTo(n.x+n.halfWidth,n.y),e.ellipse(n.x,n.y,n.halfWidth,n.halfHeight,0,0,Math.PI*2)):(e.save(),e.translate(n.x,n.y),e.scale(n.halfWidth,n.halfHeight),e.moveTo(1,0),e.arc(0,0,1,0,Math.PI*2),e.restore());break}case`triangle`:{let n=t;e.moveTo(n.x,n.y),e.lineTo(n.x2,n.y2),e.lineTo(n.x3,n.y3),e.closePath();break}default:{let n=t,r=n.points;if(!r?.length)break;e.moveTo(r[0],r[1]);for(let t=2;t<r.length;t+=2)e.lineTo(r[t],r[t+1]);n.closePath&&e.closePath();break}}}function P(e,t,n){let r=[],i=[],a=[];if(!d[t.type]?.build(t,r))return!1;let o=t.closePath??!0;_(r,n,!1,o,i,a);for(let t=0;t<a.length;t+=3){let n=a[t]*2,r=a[t+1]*2,o=a[t+2]*2;e.moveTo(i[n],i[n+1]),e.lineTo(i[r],i[r+1]),e.lineTo(i[o],i[o+1]),e.closePath()}return!0}function F(e,t){if(!t?.length)return!1;for(let n=0;n<t.length;n++){let r=t[n];if(!r?.shape)continue;let i=r.transform,a=i&&!i.isIdentity();a&&(e.save(),e.transform(i.a,i.b,i.c,i.d,i.tx,i.ty)),N(e,r.shape),a&&e.restore()}return!0}var I=class{constructor(e){this._warnedMaskTypes=new Set,this._canvasMaskStack=[],this._renderer=e}push(e,t,n){this._renderer.renderPipes.batch.break(n),n.add({renderPipeId:`stencilMask`,action:`pushMaskBegin`,mask:e,inverse:t._maskOptions.inverse,canBundle:!1})}pop(e,t,n){this._renderer.renderPipes.batch.break(n),n.add({renderPipeId:`stencilMask`,action:`popMaskEnd`,mask:e,inverse:t._maskOptions.inverse,canBundle:!1})}execute(e){if(e.action!==`pushMaskBegin`&&e.action!==`popMaskEnd`)return;let t=this._renderer,n=t.canvasContext,r=n?.activeContext;if(!r)return;if(e.action===`popMaskEnd`){this._canvasMaskStack.pop()&&r.restore();return}e.inverse&&this._warnOnce(`inverse`,`CanvasRenderer: inverse masks are not supported on Canvas2D; ignoring inverse flag.`);let i=e.mask.mask;if(!(i instanceof v)){this._warnOnce(`nonGraphics`,`CanvasRenderer: only Graphics masks are supported in Canvas2D; skipping mask.`),this._canvasMaskStack.push(!1);return}let a=i,o=a.context?.instructions;if(!o?.length){this._canvasMaskStack.push(!1);return}r.save(),n.setContextTransform(a.groupTransform,(t._roundPixels|a._roundPixels)===1),r.beginPath();let s=!1,c=!1;for(let e=0;e<o.length;e++){let t=o[e],n=t.action;if(n!==`fill`&&n!==`stroke`)continue;let i=t.data,a=i?.path?.shapePath;if(!a?.shapePrimitives?.length)continue;let l=n===`stroke`,u=a.shapePrimitives;for(let e=0;e<u.length;e++){let t=u[e];if(!t?.shape)continue;let n=t.transform,a=n&&!n.isIdentity();a&&(r.save(),r.transform(n.a,n.b,n.c,n.d,n.tx,n.ty)),l&&i.style?s=P(r,t.shape,i.style)||s:(N(r,t.shape),c=F(r,t.holes)||c,s=!0),a&&r.restore()}}s?(c?r.clip(`evenodd`):r.clip(),this._canvasMaskStack.push(!0)):(r.restore(),this._canvasMaskStack.push(!1))}destroy(){this._renderer=null,this._warnedMaskTypes=null,this._canvasMaskStack=null}_warnOnce(e,t){this._warnedMaskTypes.has(e)||(this._warnedMaskTypes.add(e),c(t))}};I.extension={type:[n.CanvasPipes],name:`stencilMask`};var L=`source-over`;function R(){let e=D(),t=Object.create(null);return t.inherit=L,t.none=L,t.normal=`source-over`,t.add=`lighter`,t.multiply=e?`multiply`:L,t.screen=e?`screen`:L,t.overlay=e?`overlay`:L,t.darken=e?`darken`:L,t.lighten=e?`lighten`:L,t[`color-dodge`]=e?`color-dodge`:L,t[`color-burn`]=e?`color-burn`:L,t[`hard-light`]=e?`hard-light`:L,t[`soft-light`]=e?`soft-light`:L,t.difference=e?`difference`:L,t.exclusion=e?`exclusion`:L,t.saturation=e?`saturation`:L,t.color=e?`color`:L,t.luminosity=e?`luminosity`:L,t[`linear-burn`]=e?`color-burn`:L,t[`linear-dodge`]=e?`color-dodge`:L,t[`linear-light`]=e?`hard-light`:L,t[`pin-light`]=e?`hard-light`:L,t[`vivid-light`]=e?`hard-light`:L,t[`hard-mix`]=L,t.negation=e?`difference`:L,t[`normal-npm`]=t.normal,t[`add-npm`]=t.add,t[`screen-npm`]=t.screen,t.erase=`destination-out`,t.subtract=L,t.divide=L,t.min=L,t.max=L,t}var z=new e,B=class{constructor(e){this.activeResolution=1,this.smoothProperty=`imageSmoothingEnabled`,this.blendModes=R(),this._activeBlendMode=`normal`,this._projTransform=null,this._outerBlend=!1,this._warnedBlendModes=new Set,this._renderer=e}resolutionChange(e){this.activeResolution=e}init(){let e=this._renderer.background.alpha<1;if(this.rootContext=this._renderer.canvas.getContext(`2d`,{alpha:e}),this.activeContext=this.rootContext,this.activeResolution=this._renderer.resolution,!this.rootContext.imageSmoothingEnabled){let e=this.rootContext;e.webkitImageSmoothingEnabled?this.smoothProperty=`webkitImageSmoothingEnabled`:e.mozImageSmoothingEnabled?this.smoothProperty=`mozImageSmoothingEnabled`:e.oImageSmoothingEnabled?this.smoothProperty=`oImageSmoothingEnabled`:e.msImageSmoothingEnabled&&(this.smoothProperty=`msImageSmoothingEnabled`)}}setContextTransform(t,n,r,i){let a=i?e.IDENTITY:this._renderer.globalUniforms.globalUniformData?.worldTransformMatrix||e.IDENTITY,o=z;o.copyFrom(a),o.append(t);let s=this._projTransform,c=this.activeResolution;if(r||=c,s){let t=e.shared;t.copyFrom(o),t.prepend(s),o=t}n?this.activeContext.setTransform(o.a*r,o.b*r,o.c*r,o.d*r,o.tx*c|0,o.ty*c|0):this.activeContext.setTransform(o.a*r,o.b*r,o.c*r,o.d*r,o.tx*c,o.ty*c)}clear(e,t){let n=this.activeContext,r=this._renderer;if(n.clearRect(0,0,r.width,r.height),e){let i=f.shared.setValue(e);n.globalAlpha=t??i.alpha,n.fillStyle=i.toHex(),n.fillRect(0,0,r.width,r.height),n.globalAlpha=1}}setBlendMode(e){if(this._activeBlendMode===e)return;this._activeBlendMode=e,this._outerBlend=!1;let t=this.blendModes[e];t?this.activeContext.globalCompositeOperation=t:(this._warnedBlendModes.has(e)||(console.warn(`CanvasRenderer: blend mode "${e}" is not supported in Canvas2D; falling back to "source-over".`),this._warnedBlendModes.add(e)),this.activeContext.globalCompositeOperation=`source-over`)}destroy(){this.rootContext=null,this.activeContext=null,this._warnedBlendModes.clear()}};B.extension={type:[n.CanvasSystem],name:`canvasContext`};var V=class{constructor(){this.maxTextures=16,this.maxBatchableTextures=16,this.maxUniformBindings=0,this.minUniformBufferOffsetAlignment=0}init(){}};V.extension={type:[n.CanvasSystem],name:`limits`};var H=`#808080`,U=new e,W=new e,G=new e,K=new e,q=new e;function J(e,t,n){e.beginPath();for(let r=0;r<n.length;r+=3){let i=n[r]*2,a=n[r+1]*2,o=n[r+2]*2;e.moveTo(t[i],t[i+1]),e.lineTo(t[a],t[a+1]),e.lineTo(t[o],t[o+1]),e.closePath()}e.fill()}function Y(e){return`#${(e&0xffffff).toString(16).padStart(6,`0`)}`}function X(e,t,n,r,i,a){a=Math.max(0,Math.min(a,Math.min(r,i)/2)),e.moveTo(t+a,n),e.lineTo(t+r-a,n),e.quadraticCurveTo(t+r,n,t+r,n+a),e.lineTo(t+r,n+i-a),e.quadraticCurveTo(t+r,n+i,t+r-a,n+i),e.lineTo(t+a,n+i),e.quadraticCurveTo(t,n+i,t,n+i-a),e.lineTo(t,n+a),e.quadraticCurveTo(t,n,t+a,n)}function Z(e,t){switch(t.type){case`rectangle`:{let n=t;e.rect(n.x,n.y,n.width,n.height);break}case`roundedRectangle`:{let n=t;X(e,n.x,n.y,n.width,n.height,n.radius);break}case`circle`:{let n=t;e.arc(n.x,n.y,n.radius,0,Math.PI*2);break}case`ellipse`:{let n=t;e.ellipse?e.ellipse(n.x,n.y,n.halfWidth,n.halfHeight,0,0,Math.PI*2):(e.save(),e.translate(n.x,n.y),e.scale(n.halfWidth,n.halfHeight),e.arc(0,0,1,0,Math.PI*2),e.restore());break}case`triangle`:{let n=t;e.moveTo(n.x,n.y),e.lineTo(n.x2,n.y2),e.lineTo(n.x3,n.y3),e.closePath();break}default:{let n=t,r=n.points;if(!r?.length)break;e.moveTo(r[0],r[1]);for(let t=2;t<r.length;t+=2)e.lineTo(r[t],r[t+1]);n.closePath&&e.closePath();break}}}function Q(e,t){if(!t?.length)return!1;for(let n=0;n<t.length;n++){let r=t[n];if(!r?.shape)continue;let i=r.transform,a=i&&!i.isIdentity();a&&(e.save(),e.transform(i.a,i.b,i.c,i.d,i.tx,i.ty)),Z(e,r.shape),a&&e.restore()}return!0}function ee(e,t,n,r){let i=e.fill;if(i instanceof m){i.buildGradient();let a=i.texture;if(a){let o=O.getTintedPattern(a,t),s=n?K.copyFrom(n).scale(a.source.pixelWidth,a.source.pixelHeight):K.copyFrom(i.transform);return r&&!e.textureSpace&&s.append(r),O.applyPatternTransform(o,s),o}}if(i instanceof g){let e=O.getTintedPattern(i.texture,t);return O.applyPatternTransform(e,i.transform,!1),e}let a=e.texture;if(a&&a!==l.WHITE){if(!a.source.resource)return H;let r=O.getTintedPattern(a,t),i=e.matrix;if(n){let{resolution:e}=a.source;if(i=K.copyFrom(n),a.rotate){let{uvs:t,orig:n}=a;i.prepend(q.set(t.x1-t.x0,t.y1-t.y0,t.x3-t.x0,t.y3-t.y0,t.x0,t.y0).invert()).scale(n.width*e,n.height*e)}else i.scale(a.source.pixelWidth,a.source.pixelHeight).translate(-a.frame.x*e,-a.frame.y*e)}return O.applyPatternTransform(r,i),r}return Y(t)}var $=class{constructor(){this.shader=null}contextChange(e){}execute(e,t){let n=e.renderer,r=n.canvasContext,i=r.activeContext,a=t.groupTransform,c=n.globalUniforms.globalUniformData?.worldColor??0xffffffff,f=t.groupColorAlpha,m=(c>>>24&255)/255,h=(f>>>24&255)/255,g=n.filter?.alphaMultiplier??1,v=m*h*g;if(v<=0)return;let y=c&0xffffff,b=f&0xffffff,x=u(p(b,y)),S=n._roundPixels|t._roundPixels;i.save(),r.setContextTransform(a,S===1),r.setBlendMode(t.groupBlendMode);let C=t.context.instructions;for(let e=0;e<C.length;e++){let t=C[e];if(t.action===`texture`){let e=t.data,n=e.image,s=n?O.getCanvasSource(n):null;if(!s)continue;let c=e.alpha*v;if(c<=0)continue;let l=p(e.style,x);i.globalAlpha=c;let u=s;l!==0xffffff&&(u=O.getTintedCanvas({texture:n},l));let d=n.frame,f=n.source._resolution??n.source.resolution??1,m=d.x*f,h=d.y*f,g=d.width*f,_=d.height*f;u!==s&&(m=0,h=0);let y=e.transform,b=y&&!y.isIdentity(),C=n.rotate;b||C?(U.copyFrom(a),b&&U.append(y),C&&o.matrixAppendRotationInv(U,C,e.dx,e.dy,e.dw,e.dh),r.setContextTransform(U,S===1)):r.setContextTransform(a,S===1),i.drawImage(u,m,h,u===s?g:u.width,u===s?_:u.height,C?0:e.dx,C?0:e.dy,e.dw,e.dh),(b||C)&&r.setContextTransform(a,S===1);continue}let n=t.data,c=n?.path?.shapePath;if(!c?.shapePrimitives?.length)continue;let u=n.style,f=p(u.color,x),m=u.alpha*v;if(m<=0)continue;let h=t.action===`stroke`;if(i.globalAlpha=m,h){let e=u;i.lineWidth=e.width,i.lineCap=e.cap,i.lineJoin=e.join,i.miterLimit=e.miterLimit}let g=c.shapePrimitives;if(!h&&n.hole?.shapePath?.shapePrimitives?.length){let e=g[g.length-1];e.holes=n.hole.shapePath.shapePrimitives}for(let e=0;e<g.length;e++){let t=g[e];if(!t?.shape)continue;let n=t.transform,r=n&&!n.isIdentity(),o=u.texture&&u.texture!==l.WHITE,c=u.textureSpace===`global`?n:null,p=ee(u,f,o?s(W,u,t.shape,c):null,r?G.copyFrom(a).append(n):a);if(r&&(i.save(),i.transform(n.a,n.b,n.c,n.d,n.tx,n.ty)),h){let e=u;if(e.alignment!==.5&&!e.pixelLine){let n=[],r=[],a=[];if(d[t.shape.type]?.build(t.shape,n)){let o=t.shape.closePath??!0;_(n,e,!1,o,r,a),i.fillStyle=p,J(i,r,a)}else i.strokeStyle=p,i.beginPath(),Z(i,t.shape),i.stroke()}else i.strokeStyle=p,i.beginPath(),Z(i,t.shape),i.stroke()}else i.fillStyle=p,i.beginPath(),Z(i,t.shape),Q(i,t.holes)?i.fill(`evenodd`):i.fill();r&&i.restore()}}i.restore()}destroy(){this.shader=null}};$.extension={type:[n.CanvasPipesAdaptor],name:`graphics`};var te=class{init(e,t){this._renderer=e,this._renderTargetSystem=t}initGpuRenderTarget(e){let t=e.colorTexture,{canvas:n,context:r}=this._ensureCanvas(t);return{canvas:n,context:r,width:n.width,height:n.height}}resizeGpuRenderTarget(e){let t=e.colorTexture,{canvas:n}=this._ensureCanvas(t);n.width=e.pixelWidth,n.height=e.pixelHeight}startRenderPass(e,t,n,r){let i=this._renderTargetSystem.getGpuRenderTarget(e);this._renderer.canvasContext.activeContext=i.context,this._renderer.canvasContext.activeResolution=e.resolution,t&&this.clear(e,t,n,r)}clear(e,t,n,r){let i=this._renderTargetSystem.getGpuRenderTarget(e).context,a=r||{x:0,y:0,width:e.pixelWidth,height:e.pixelHeight};if(i.setTransform(1,0,0,1,0,0),i.clearRect(a.x,a.y,a.width,a.height),n){let e=f.shared.setValue(n);e.alpha>0&&(i.globalAlpha=e.alpha,i.fillStyle=e.toHex(),i.fillRect(a.x,a.y,a.width,a.height),i.globalAlpha=1)}}finishRenderPass(){}copyToTexture(e,t,n,r,i){let a=this._renderTargetSystem.getGpuRenderTarget(e).canvas,o=t.source,{context:s}=this._ensureCanvas(o),c=i?.x??0,l=i?.y??0;return s.drawImage(a,n.x,n.y,r.width,r.height,c,l,r.width,r.height),o.update(),t}copyDepthTexture(e,t,n,r,i){c(`[CanvasRenderTargetAdaptor] copyDepthTexture is not supported in the canvas renderer`)}destroyGpuRenderTarget(e){}_ensureCanvas(e){let t=e.resource;t&&r.test(t)||(t=h.get().createCanvas(e.pixelWidth,e.pixelHeight),e.resource=t),(t.width!==e.pixelWidth||t.height!==e.pixelHeight)&&(t.width=e.pixelWidth,t.height=e.pixelHeight);let n=t.getContext(`2d`);return{canvas:t,context:n}}},ne=class extends E{constructor(e){super(e),this.adaptor=new te,this.adaptor.init(e,this)}};ne.extension={type:[n.CanvasSystem],name:`renderTarget`};var re=class{constructor(e){}init(){}initSource(e){}generateCanvas(e){let t=h.get().createCanvas(),n=t.getContext(`2d`),r=O.getCanvasSource(e);if(!r)return t;let i=e.frame,a=e.source._resolution??e.source.resolution??1,o=i.x*a,s=i.y*a,c=i.width*a,l=i.height*a;return t.width=Math.ceil(c),t.height=Math.ceil(l),n.drawImage(r,o,s,c,l,0,0,c,l),t}getPixels(e){let t=this.generateCanvas(e);return{pixels:t.getContext(`2d`,{willReadFrequently:!0}).getImageData(0,0,t.width,t.height).data,width:t.width,height:t.height}}destroy(){}};re.extension={type:[n.CanvasSystem],name:`texture`};var ie=[...w,B,V,re,ne],ae=[x,S,y,C,b,I,j,T],oe=[A,$],se=[],ce=[],le=[],ue=[];t.handleByNamedList(n.CanvasSystem,se),t.handleByNamedList(n.CanvasPipes,ce),t.handleByNamedList(n.CanvasPipesAdaptor,le),t.handleByNamedList(n.CanvasLoader,ue),t.add(...ie,...ae,...oe);var de=class extends a{constructor(){let e={name:`canvas`,type:i.CANVAS,systems:se,renderPipes:ce,renderPipeAdaptors:le,loaders:ue};super(e)}};export{de as CanvasRenderer};
1
+ import{Ct as e,Dt as t,Et as n,K as r,L as i,O as a,St as o,a as s,ct as c,dt as l,et as u,i as d,lt as f,nt as p,o as m,q as h,r as g,s as _,t as v}from"./index-41-d13J1.js";import{a as y,c as b,i as x,l as S,o as C,r as w,s as T,t as E}from"./RenderTargetSystem-um8Nv1HQ.js";import{n as D,t as O}from"./canvasUtils-CZLntkW8.js";var k=class e{static _getPatternRepeat(e,t){let n=e&&e!==`clamp-to-edge`,r=t&&t!==`clamp-to-edge`;return n&&r?`repeat`:n?`repeat-x`:r?`repeat-y`:`no-repeat`}start(e,t,n){}execute(t,n){let r=n.elements;if(!r||!r.length)return;let i=t.renderer,a=i.canvasContext,s=a.activeContext;for(let t=0;t<r.length;t++){let c=r[t];if(!c.packAsQuad)continue;let l=c,d=l.texture,f=d?O.getCanvasSource(d):null;if(!f)continue;let m=d.source.style,h=a.smoothProperty,g=m.scaleMode!==`nearest`;s[h]!==g&&(s[h]=g),a.setBlendMode(n.blendMode);let _=i.globalUniforms.globalUniformData?.worldColor??0xffffffff,v=l.color,y=(_>>>24&255)/255,b=(v>>>24&255)/255,x=i.filter?.alphaMultiplier??1,S=y*b*x;if(S<=0)continue;s.globalAlpha=S;let C=_&0xffffff,w=v&0xffffff,T=u(p(w,C)),E=d.frame,D=m.addressModeU??m.addressMode,k=m.addressModeV??m.addressMode,A=e._getPatternRepeat(D,k),j=d.source._resolution??d.source.resolution??1,M=l.renderable?.renderGroup?.isCachedAsTexture,N=E.x*j,P=E.y*j,F=E.width*j,I=E.height*j,L=l.bounds,R=i.renderTarget.renderTarget.isRoot,z=L.minX,B=L.minY,V=L.maxX-L.minX,H=L.maxY-L.minY,U=d.rotate,W=d.uvs,G=Math.min(W.x0,W.x1,W.x2,W.x3,W.y0,W.y1,W.y2,W.y3),K=Math.max(W.x0,W.x1,W.x2,W.x3,W.y0,W.y1,W.y2,W.y3),q=A!==`no-repeat`&&(G<0||K>1),J=U&&(!!q||T===0xffffff&&!U);J?(e._tempPatternMatrix.copyFrom(l.transform),o.matrixAppendRotationInv(e._tempPatternMatrix,U,z,B,V,H),a.setContextTransform(e._tempPatternMatrix,l.roundPixels===1,void 0,M&&R)):a.setContextTransform(l.transform,l.roundPixels===1,void 0,M&&R);let Y=V,X=H,Z=J?0:z,Q=J?0:B;if(!J&&l.roundPixels===1&&(Z|=0,Q|=0),q){let t=f,n=T!==0xffffff&&!U,r=E.width<=d.source.width&&E.height<=d.source.height;n&&r&&(t=O.getTintedCanvas({texture:d},T));let i=s.createPattern(t,A);if(!i)continue;let a=Y,o=X;if(a===0||o===0)continue;let c=1/a,l=1/o,u=(W.x1-W.x0)*c,p=(W.y1-W.y0)*c,m=(W.x3-W.x0)*l,h=(W.y3-W.y0)*l,g=W.x0-u*Z-m*Q,_=W.y0-p*Z-h*Q,v=d.source.pixelWidth,y=d.source.pixelHeight;e._tempPatternMatrix.set(u*v,p*y,m*v,h*y,g*v,_*y),O.applyPatternTransform(i,e._tempPatternMatrix),s.fillStyle=i,s.fillRect(Z,Q,Y,X)}else{let e=T!==0xffffff||U?O.getTintedCanvas({texture:d},T):f,t=e!==f;s.drawImage(e,t?0:N,t?0:P,t?e.width:F,t?e.height:I,Z,Q,Y,X)}}}};k._tempPatternMatrix=new e,k.extension={type:[n.CanvasPipesAdaptor],name:`batch`};var A=k,j=class{constructor(e){this._colorStack=[],this._colorStackIndex=0,this._currentColor=0,this._renderer=e}buildStart(){this._colorStack[0]=15,this._colorStackIndex=1,this._currentColor=15}push(e,t,n){this._renderer.renderPipes.batch.break(n);let r=this._colorStack;r[this._colorStackIndex]=r[this._colorStackIndex-1]&e.mask;let i=this._colorStack[this._colorStackIndex];i!==this._currentColor&&(this._currentColor=i,n.add({renderPipeId:`colorMask`,colorMask:i,canBundle:!1})),this._colorStackIndex++}pop(e,t,n){this._renderer.renderPipes.batch.break(n);let r=this._colorStack;this._colorStackIndex--;let i=r[this._colorStackIndex-1];i!==this._currentColor&&(this._currentColor=i,n.add({renderPipeId:`colorMask`,colorMask:i,canBundle:!1}))}execute(e){}destroy(){this._renderer=null,this._colorStack=null}};j.extension={type:[n.CanvasPipes],name:`colorMask`};function M(e,t,n,r,i,a){a=Math.max(0,Math.min(a,Math.min(r,i)/2)),e.moveTo(t+a,n),e.lineTo(t+r-a,n),e.quadraticCurveTo(t+r,n,t+r,n+a),e.lineTo(t+r,n+i-a),e.quadraticCurveTo(t+r,n+i,t+r-a,n+i),e.lineTo(t+a,n+i),e.quadraticCurveTo(t,n+i,t,n+i-a),e.lineTo(t,n+a),e.quadraticCurveTo(t,n,t+a,n)}function N(e,t){switch(t.type){case`rectangle`:{let n=t;e.rect(n.x,n.y,n.width,n.height);break}case`roundedRectangle`:{let n=t;M(e,n.x,n.y,n.width,n.height,n.radius);break}case`circle`:{let n=t;e.moveTo(n.x+n.radius,n.y),e.arc(n.x,n.y,n.radius,0,Math.PI*2);break}case`ellipse`:{let n=t;e.ellipse?(e.moveTo(n.x+n.halfWidth,n.y),e.ellipse(n.x,n.y,n.halfWidth,n.halfHeight,0,0,Math.PI*2)):(e.save(),e.translate(n.x,n.y),e.scale(n.halfWidth,n.halfHeight),e.moveTo(1,0),e.arc(0,0,1,0,Math.PI*2),e.restore());break}case`triangle`:{let n=t;e.moveTo(n.x,n.y),e.lineTo(n.x2,n.y2),e.lineTo(n.x3,n.y3),e.closePath();break}default:{let n=t,r=n.points;if(!r?.length)break;e.moveTo(r[0],r[1]);for(let t=2;t<r.length;t+=2)e.lineTo(r[t],r[t+1]);n.closePath&&e.closePath();break}}}function P(e,t,n){let r=[],i=[],a=[];if(!d[t.type]?.build(t,r))return!1;let o=t.closePath??!0;_(r,n,!1,o,i,a);for(let t=0;t<a.length;t+=3){let n=a[t]*2,r=a[t+1]*2,o=a[t+2]*2;e.moveTo(i[n],i[n+1]),e.lineTo(i[r],i[r+1]),e.lineTo(i[o],i[o+1]),e.closePath()}return!0}function F(e,t){if(!t?.length)return!1;for(let n=0;n<t.length;n++){let r=t[n];if(!r?.shape)continue;let i=r.transform,a=i&&!i.isIdentity();a&&(e.save(),e.transform(i.a,i.b,i.c,i.d,i.tx,i.ty)),N(e,r.shape),a&&e.restore()}return!0}var I=class{constructor(e){this._warnedMaskTypes=new Set,this._canvasMaskStack=[],this._renderer=e}push(e,t,n){this._renderer.renderPipes.batch.break(n),n.add({renderPipeId:`stencilMask`,action:`pushMaskBegin`,mask:e,inverse:t._maskOptions.inverse,canBundle:!1})}pop(e,t,n){this._renderer.renderPipes.batch.break(n),n.add({renderPipeId:`stencilMask`,action:`popMaskEnd`,mask:e,inverse:t._maskOptions.inverse,canBundle:!1})}execute(e){if(e.action!==`pushMaskBegin`&&e.action!==`popMaskEnd`)return;let t=this._renderer,n=t.canvasContext,r=n?.activeContext;if(!r)return;if(e.action===`popMaskEnd`){this._canvasMaskStack.pop()&&r.restore();return}e.inverse&&this._warnOnce(`inverse`,`CanvasRenderer: inverse masks are not supported on Canvas2D; ignoring inverse flag.`);let i=e.mask.mask;if(!(i instanceof v)){this._warnOnce(`nonGraphics`,`CanvasRenderer: only Graphics masks are supported in Canvas2D; skipping mask.`),this._canvasMaskStack.push(!1);return}let a=i,o=a.context?.instructions;if(!o?.length){this._canvasMaskStack.push(!1);return}r.save(),n.setContextTransform(a.groupTransform,(t._roundPixels|a._roundPixels)===1),r.beginPath();let s=!1,c=!1;for(let e=0;e<o.length;e++){let t=o[e],n=t.action;if(n!==`fill`&&n!==`stroke`)continue;let i=t.data,a=i?.path?.shapePath;if(!a?.shapePrimitives?.length)continue;let l=n===`stroke`,u=a.shapePrimitives;for(let e=0;e<u.length;e++){let t=u[e];if(!t?.shape)continue;let n=t.transform,a=n&&!n.isIdentity();a&&(r.save(),r.transform(n.a,n.b,n.c,n.d,n.tx,n.ty)),l&&i.style?s=P(r,t.shape,i.style)||s:(N(r,t.shape),c=F(r,t.holes)||c,s=!0),a&&r.restore()}}s?(c?r.clip(`evenodd`):r.clip(),this._canvasMaskStack.push(!0)):(r.restore(),this._canvasMaskStack.push(!1))}destroy(){this._renderer=null,this._warnedMaskTypes=null,this._canvasMaskStack=null}_warnOnce(e,t){this._warnedMaskTypes.has(e)||(this._warnedMaskTypes.add(e),c(t))}};I.extension={type:[n.CanvasPipes],name:`stencilMask`};var L=`source-over`;function R(){let e=D(),t=Object.create(null);return t.inherit=L,t.none=L,t.normal=`source-over`,t.add=`lighter`,t.multiply=e?`multiply`:L,t.screen=e?`screen`:L,t.overlay=e?`overlay`:L,t.darken=e?`darken`:L,t.lighten=e?`lighten`:L,t[`color-dodge`]=e?`color-dodge`:L,t[`color-burn`]=e?`color-burn`:L,t[`hard-light`]=e?`hard-light`:L,t[`soft-light`]=e?`soft-light`:L,t.difference=e?`difference`:L,t.exclusion=e?`exclusion`:L,t.saturation=e?`saturation`:L,t.color=e?`color`:L,t.luminosity=e?`luminosity`:L,t[`linear-burn`]=e?`color-burn`:L,t[`linear-dodge`]=e?`color-dodge`:L,t[`linear-light`]=e?`hard-light`:L,t[`pin-light`]=e?`hard-light`:L,t[`vivid-light`]=e?`hard-light`:L,t[`hard-mix`]=L,t.negation=e?`difference`:L,t[`normal-npm`]=t.normal,t[`add-npm`]=t.add,t[`screen-npm`]=t.screen,t.erase=`destination-out`,t.subtract=L,t.divide=L,t.min=L,t.max=L,t}var z=new e,B=class{constructor(e){this.activeResolution=1,this.smoothProperty=`imageSmoothingEnabled`,this.blendModes=R(),this._activeBlendMode=`normal`,this._projTransform=null,this._outerBlend=!1,this._warnedBlendModes=new Set,this._renderer=e}resolutionChange(e){this.activeResolution=e}init(){let e=this._renderer.background.alpha<1;if(this.rootContext=this._renderer.canvas.getContext(`2d`,{alpha:e}),this.activeContext=this.rootContext,this.activeResolution=this._renderer.resolution,!this.rootContext.imageSmoothingEnabled){let e=this.rootContext;e.webkitImageSmoothingEnabled?this.smoothProperty=`webkitImageSmoothingEnabled`:e.mozImageSmoothingEnabled?this.smoothProperty=`mozImageSmoothingEnabled`:e.oImageSmoothingEnabled?this.smoothProperty=`oImageSmoothingEnabled`:e.msImageSmoothingEnabled&&(this.smoothProperty=`msImageSmoothingEnabled`)}}setContextTransform(t,n,r,i){let a=i?e.IDENTITY:this._renderer.globalUniforms.globalUniformData?.worldTransformMatrix||e.IDENTITY,o=z;o.copyFrom(a),o.append(t);let s=this._projTransform,c=this.activeResolution;if(r||=c,s){let t=e.shared;t.copyFrom(o),t.prepend(s),o=t}n?this.activeContext.setTransform(o.a*r,o.b*r,o.c*r,o.d*r,o.tx*c|0,o.ty*c|0):this.activeContext.setTransform(o.a*r,o.b*r,o.c*r,o.d*r,o.tx*c,o.ty*c)}clear(e,t){let n=this.activeContext,r=this._renderer;if(n.clearRect(0,0,r.width,r.height),e){let i=f.shared.setValue(e);n.globalAlpha=t??i.alpha,n.fillStyle=i.toHex(),n.fillRect(0,0,r.width,r.height),n.globalAlpha=1}}setBlendMode(e){if(this._activeBlendMode===e)return;this._activeBlendMode=e,this._outerBlend=!1;let t=this.blendModes[e];t?this.activeContext.globalCompositeOperation=t:(this._warnedBlendModes.has(e)||(console.warn(`CanvasRenderer: blend mode "${e}" is not supported in Canvas2D; falling back to "source-over".`),this._warnedBlendModes.add(e)),this.activeContext.globalCompositeOperation=`source-over`)}destroy(){this.rootContext=null,this.activeContext=null,this._warnedBlendModes.clear()}};B.extension={type:[n.CanvasSystem],name:`canvasContext`};var V=class{constructor(){this.maxTextures=16,this.maxBatchableTextures=16,this.maxUniformBindings=0,this.minUniformBufferOffsetAlignment=0}init(){}};V.extension={type:[n.CanvasSystem],name:`limits`};var H=`#808080`,U=new e,W=new e,G=new e,K=new e,q=new e;function J(e,t,n){e.beginPath();for(let r=0;r<n.length;r+=3){let i=n[r]*2,a=n[r+1]*2,o=n[r+2]*2;e.moveTo(t[i],t[i+1]),e.lineTo(t[a],t[a+1]),e.lineTo(t[o],t[o+1]),e.closePath()}e.fill()}function Y(e){return`#${(e&0xffffff).toString(16).padStart(6,`0`)}`}function X(e,t,n,r,i,a){a=Math.max(0,Math.min(a,Math.min(r,i)/2)),e.moveTo(t+a,n),e.lineTo(t+r-a,n),e.quadraticCurveTo(t+r,n,t+r,n+a),e.lineTo(t+r,n+i-a),e.quadraticCurveTo(t+r,n+i,t+r-a,n+i),e.lineTo(t+a,n+i),e.quadraticCurveTo(t,n+i,t,n+i-a),e.lineTo(t,n+a),e.quadraticCurveTo(t,n,t+a,n)}function Z(e,t){switch(t.type){case`rectangle`:{let n=t;e.rect(n.x,n.y,n.width,n.height);break}case`roundedRectangle`:{let n=t;X(e,n.x,n.y,n.width,n.height,n.radius);break}case`circle`:{let n=t;e.arc(n.x,n.y,n.radius,0,Math.PI*2);break}case`ellipse`:{let n=t;e.ellipse?e.ellipse(n.x,n.y,n.halfWidth,n.halfHeight,0,0,Math.PI*2):(e.save(),e.translate(n.x,n.y),e.scale(n.halfWidth,n.halfHeight),e.arc(0,0,1,0,Math.PI*2),e.restore());break}case`triangle`:{let n=t;e.moveTo(n.x,n.y),e.lineTo(n.x2,n.y2),e.lineTo(n.x3,n.y3),e.closePath();break}default:{let n=t,r=n.points;if(!r?.length)break;e.moveTo(r[0],r[1]);for(let t=2;t<r.length;t+=2)e.lineTo(r[t],r[t+1]);n.closePath&&e.closePath();break}}}function Q(e,t){if(!t?.length)return!1;for(let n=0;n<t.length;n++){let r=t[n];if(!r?.shape)continue;let i=r.transform,a=i&&!i.isIdentity();a&&(e.save(),e.transform(i.a,i.b,i.c,i.d,i.tx,i.ty)),Z(e,r.shape),a&&e.restore()}return!0}function ee(e,t,n,r){let i=e.fill;if(i instanceof m){i.buildGradient();let a=i.texture;if(a){let o=O.getTintedPattern(a,t),s=n?K.copyFrom(n).scale(a.source.pixelWidth,a.source.pixelHeight):K.copyFrom(i.transform);return r&&!e.textureSpace&&s.append(r),O.applyPatternTransform(o,s),o}}if(i instanceof g){let e=O.getTintedPattern(i.texture,t);return O.applyPatternTransform(e,i.transform,!1),e}let a=e.texture;if(a&&a!==l.WHITE){if(!a.source.resource)return H;let r=O.getTintedPattern(a,t),i=e.matrix;if(n){let{resolution:e}=a.source;if(i=K.copyFrom(n),a.rotate){let{uvs:t,orig:n}=a;i.prepend(q.set(t.x1-t.x0,t.y1-t.y0,t.x3-t.x0,t.y3-t.y0,t.x0,t.y0).invert()).scale(n.width*e,n.height*e)}else i.scale(a.source.pixelWidth,a.source.pixelHeight).translate(-a.frame.x*e,-a.frame.y*e)}return O.applyPatternTransform(r,i),r}return Y(t)}var $=class{constructor(){this.shader=null}contextChange(e){}execute(e,t){let n=e.renderer,r=n.canvasContext,i=r.activeContext,a=t.groupTransform,c=n.globalUniforms.globalUniformData?.worldColor??0xffffffff,f=t.groupColorAlpha,m=(c>>>24&255)/255,h=(f>>>24&255)/255,g=n.filter?.alphaMultiplier??1,v=m*h*g;if(v<=0)return;let y=c&0xffffff,b=f&0xffffff,x=u(p(b,y)),S=n._roundPixels|t._roundPixels;i.save(),r.setContextTransform(a,S===1),r.setBlendMode(t.groupBlendMode);let C=t.context.instructions;for(let e=0;e<C.length;e++){let t=C[e];if(t.action===`texture`){let e=t.data,n=e.image,s=n?O.getCanvasSource(n):null;if(!s)continue;let c=e.alpha*v;if(c<=0)continue;let l=p(e.style,x);i.globalAlpha=c;let u=s;l!==0xffffff&&(u=O.getTintedCanvas({texture:n},l));let d=n.frame,f=n.source._resolution??n.source.resolution??1,m=d.x*f,h=d.y*f,g=d.width*f,_=d.height*f;u!==s&&(m=0,h=0);let y=e.transform,b=y&&!y.isIdentity(),C=n.rotate;b||C?(U.copyFrom(a),b&&U.append(y),C&&o.matrixAppendRotationInv(U,C,e.dx,e.dy,e.dw,e.dh),r.setContextTransform(U,S===1)):r.setContextTransform(a,S===1),i.drawImage(u,m,h,u===s?g:u.width,u===s?_:u.height,C?0:e.dx,C?0:e.dy,e.dw,e.dh),(b||C)&&r.setContextTransform(a,S===1);continue}let n=t.data,c=n?.path?.shapePath;if(!c?.shapePrimitives?.length)continue;let u=n.style,f=p(u.color,x),m=u.alpha*v;if(m<=0)continue;let h=t.action===`stroke`;if(i.globalAlpha=m,h){let e=u;i.lineWidth=e.width,i.lineCap=e.cap,i.lineJoin=e.join,i.miterLimit=e.miterLimit}let g=c.shapePrimitives;if(!h&&n.hole?.shapePath?.shapePrimitives?.length){let e=g[g.length-1];e.holes=n.hole.shapePath.shapePrimitives}for(let e=0;e<g.length;e++){let t=g[e];if(!t?.shape)continue;let n=t.transform,r=n&&!n.isIdentity(),o=u.texture&&u.texture!==l.WHITE,c=u.textureSpace===`global`?n:null,p=ee(u,f,o?s(W,u,t.shape,c):null,r?G.copyFrom(a).append(n):a);if(r&&(i.save(),i.transform(n.a,n.b,n.c,n.d,n.tx,n.ty)),h){let e=u;if(e.alignment!==.5&&!e.pixelLine){let n=[],r=[],a=[];if(d[t.shape.type]?.build(t.shape,n)){let o=t.shape.closePath??!0;_(n,e,!1,o,r,a),i.fillStyle=p,J(i,r,a)}else i.strokeStyle=p,i.beginPath(),Z(i,t.shape),i.stroke()}else i.strokeStyle=p,i.beginPath(),Z(i,t.shape),i.stroke()}else i.fillStyle=p,i.beginPath(),Z(i,t.shape),Q(i,t.holes)?i.fill(`evenodd`):i.fill();r&&i.restore()}}i.restore()}destroy(){this.shader=null}};$.extension={type:[n.CanvasPipesAdaptor],name:`graphics`};var te=class{init(e,t){this._renderer=e,this._renderTargetSystem=t}initGpuRenderTarget(e){let t=e.colorTexture,{canvas:n,context:r}=this._ensureCanvas(t);return{canvas:n,context:r,width:n.width,height:n.height}}resizeGpuRenderTarget(e){let t=e.colorTexture,{canvas:n}=this._ensureCanvas(t);n.width=e.pixelWidth,n.height=e.pixelHeight}startRenderPass(e,t,n,r){let i=this._renderTargetSystem.getGpuRenderTarget(e);this._renderer.canvasContext.activeContext=i.context,this._renderer.canvasContext.activeResolution=e.resolution,t&&this.clear(e,t,n,r)}clear(e,t,n,r){let i=this._renderTargetSystem.getGpuRenderTarget(e).context,a=r||{x:0,y:0,width:e.pixelWidth,height:e.pixelHeight};if(i.setTransform(1,0,0,1,0,0),i.clearRect(a.x,a.y,a.width,a.height),n){let e=f.shared.setValue(n);e.alpha>0&&(i.globalAlpha=e.alpha,i.fillStyle=e.toHex(),i.fillRect(a.x,a.y,a.width,a.height),i.globalAlpha=1)}}finishRenderPass(){}copyToTexture(e,t,n,r,i){let a=this._renderTargetSystem.getGpuRenderTarget(e).canvas,o=t.source,{context:s}=this._ensureCanvas(o),c=i?.x??0,l=i?.y??0;return s.drawImage(a,n.x,n.y,r.width,r.height,c,l,r.width,r.height),o.update(),t}copyDepthTexture(e,t,n,r,i){c(`[CanvasRenderTargetAdaptor] copyDepthTexture is not supported in the canvas renderer`)}destroyGpuRenderTarget(e){}_ensureCanvas(e){let t=e.resource;t&&r.test(t)||(t=h.get().createCanvas(e.pixelWidth,e.pixelHeight),e.resource=t),(t.width!==e.pixelWidth||t.height!==e.pixelHeight)&&(t.width=e.pixelWidth,t.height=e.pixelHeight);let n=t.getContext(`2d`);return{canvas:t,context:n}}},ne=class extends E{constructor(e){super(e),this.adaptor=new te,this.adaptor.init(e,this)}};ne.extension={type:[n.CanvasSystem],name:`renderTarget`};var re=class{constructor(e){}init(){}initSource(e){}generateCanvas(e){let t=h.get().createCanvas(),n=t.getContext(`2d`),r=O.getCanvasSource(e);if(!r)return t;let i=e.frame,a=e.source._resolution??e.source.resolution??1,o=i.x*a,s=i.y*a,c=i.width*a,l=i.height*a;return t.width=Math.ceil(c),t.height=Math.ceil(l),n.drawImage(r,o,s,c,l,0,0,c,l),t}getPixels(e){let t=this.generateCanvas(e);return{pixels:t.getContext(`2d`,{willReadFrequently:!0}).getImageData(0,0,t.width,t.height).data,width:t.width,height:t.height}}destroy(){}};re.extension={type:[n.CanvasSystem],name:`texture`};var ie=[...w,B,V,re,ne],ae=[x,S,y,C,b,I,j,T],oe=[A,$],se=[],ce=[],le=[],ue=[];t.handleByNamedList(n.CanvasSystem,se),t.handleByNamedList(n.CanvasPipes,ce),t.handleByNamedList(n.CanvasPipesAdaptor,le),t.handleByNamedList(n.CanvasLoader,ue),t.add(...ie,...ae,...oe);var de=class extends a{constructor(){let e={name:`canvas`,type:i.CANVAS,systems:se,renderPipes:ce,renderPipeAdaptors:le,loaders:ue};super(e)}};export{de as CanvasRenderer};
@@ -1,4 +1,4 @@
1
- import{$ as e,A as t,B as n,Ct as r,D as i,Dt as a,E as o,Et as s,H as c,J as l,K as u,L as d,M as f,P as p,R as m,Tt as h,W as g,X as _,Y as v,Z as y,_t as b,bt as ee,ct as x,dt as S,ft as te,gt as C,it as w,k as ne,lt as T,n as re,ot as E,pt as D,q as O,rt as ie,st as ae,tt as oe,u as se,ut as k,vt as ce,w as A,wt as le,xt as j,yt as ue,z as de}from"./index-CE-lli1m.js";import{t as fe}from"./CanvasPool-PBu3bHFZ.js";var pe=`in vec2 vMaskCoord;
1
+ import{$ as e,A as t,B as n,Ct as r,D as i,Dt as a,E as o,Et as s,H as c,J as l,K as u,L as d,M as f,P as p,R as m,Tt as h,W as g,X as _,Y as v,Z as y,_t as b,bt as ee,ct as x,dt as S,ft as te,gt as C,it as w,k as ne,lt as T,n as re,ot as E,pt as D,q as O,rt as ie,st as ae,tt as oe,u as se,ut as k,vt as ce,w as A,wt as le,xt as j,yt as ue,z as de}from"./index-41-d13J1.js";import{t as fe}from"./CanvasPool-SkgMbnEH.js";var pe=`in vec2 vMaskCoord;
2
2
  in vec2 vTextureCoord;
3
3
 
4
4
  uniform sampler2D uTexture;
@@ -1,4 +1,4 @@
1
- import{A as e,C as t,Ct as n,Dt as r,Et as i,F as a,H as o,K as s,L as c,N as l,O as u,P as d,S as f,Tt as p,V as m,_ as ee,b as te,bt as ne,c as h,ct as g,d as re,dt as _,gt as v,h as ie,p as y,pt as b,q as x,v as S,w as C,xt as w,z as T}from"./index-CE-lli1m.js";import{a as ae,c as oe,d as se,l as ce,n as le,o as E,p as D,r as ue,s as de,t as fe}from"./getTexelRangeRects-D3pwCyRt.js";import{n as pe,r as me,t as he}from"./RenderTargetSystem-Dk1U4wDJ.js";function ge(){let{userAgent:e}=x.get().getNavigator();return/^((?!chrome|android).)*safari/i.test(e)}var O=class{constructor(){this._tempState=d.for2d(),this._didUploadHash={}}init(e){e.renderer.runners.contextChange.add(this)}contextChange(){this._didUploadHash={}}start(e,t,n){let r=e.renderer,i=this._didUploadHash[n.uid];r.shader.bind(n,i),i||(this._didUploadHash[n.uid]=!0),r.shader.updateUniformGroup(r.globalUniforms.uniformGroup),r.geometry.bind(t,n.glProgram)}execute(e,t){let n=e.renderer;this._tempState.blendMode=t.blendMode,n.state.set(this._tempState);let r=t.textures.textures;for(let e=0;e<t.textures.count;e++)n.texture.bind(r[e],e);n.texture.unbindIntegerTextures(t.textures.count),n.geometry.draw(t.topology,t.size,t.start)}};O.extension={type:[i.WebGLPipesAdaptor],name:`batch`};var k=(e=>(e[e.ELEMENT_ARRAY_BUFFER=34963]=`ELEMENT_ARRAY_BUFFER`,e[e.ARRAY_BUFFER=34962]=`ARRAY_BUFFER`,e[e.UNIFORM_BUFFER=35345]=`UNIFORM_BUFFER`,e))(k||{}),_e=class{constructor(e,t){this.buffer=e||null,this.updateID=-1,this.byteLength=-1,this.type=t}destroy(){this.buffer=null,this.updateID=-1,this.byteLength=-1,this.type=-1}},A=class{constructor(e){this._boundBuffers=[],this._boundOffsets=[],this._boundSizes=[],this._renderer=e,this._managedBuffers=new h({renderer:e,type:`resource`,onUnload:this.onBufferUnload.bind(this),name:`glBuffer`})}destroy(){this._managedBuffers.destroy(),this._renderer=null,this._gl=null,this._boundBuffers.length=0}contextChange(){this._gl=this._renderer.gl,this.destroyAll(!0),this._boundBuffers.length=0}getGlBuffer(e){return e._gcLastUsed=this._renderer.gc.now,e._gpuData[this._renderer.uid]||this.createGLBuffer(e)}bind(e){let{_gl:t}=this,n=this.getGlBuffer(e);t.bindBuffer(n.type,n.buffer)}bindBufferBase(e,t){(this._boundBuffers[t]!==e||this._boundSizes[t]!==-1)&&(this._boundBuffers[t]=e,this._boundOffsets[t]=0,this._boundSizes[t]=-1,this._gl.bindBufferBase(this._gl.UNIFORM_BUFFER,t,e.buffer))}bindBufferRange(e,t=0,n=0,r){r??=e.byteLength-n,(this._boundBuffers[t]!==e||this._boundOffsets[t]!==n||this._boundSizes[t]!==r)&&(this._boundBuffers[t]=e,this._boundOffsets[t]=n,this._boundSizes[t]=r,this._gl.bindBufferRange(this._gl.UNIFORM_BUFFER,t,e.buffer,n,r))}updateBuffer(e){let t=this.getGlBuffer(e);return this._upload(e,t,t.type),t}_upload(e,t,n){let{_gl:r}=this;if(e._updateID===t.updateID)return;t.updateID=e._updateID,r.bindBuffer(n,t.buffer);let i=e.data,a=e.descriptor.usage&f.STATIC?r.STATIC_DRAW:r.DYNAMIC_DRAW;if(i){if(t.byteLength>=i.byteLength){let t=e._updateOffset/i.BYTES_PER_ELEMENT,a=(e._updateSize||i.byteLength)/i.BYTES_PER_ELEMENT;this._renderer.context.webGLVersion===2?r.bufferSubData(n,e._updateOffset,i,t,a):r.bufferSubData(n,e._updateOffset,a===i.length?i:i.subarray(t,t+a))}else t.byteLength=i.byteLength,r.bufferData(n,i,a)}else t.byteLength=e.descriptor.size,r.bufferData(n,t.byteLength,a)}destroyAll(e=!1){this._managedBuffers.removeAll(e)}onBufferUnload(e,t=!1){e.off(`update`,this.updateBuffer,this),e.off(`update`,this._updateIndexBuffer,this);let n=e._gpuData[this._renderer.uid];n&&(t||this._gl.deleteBuffer(n.buffer))}createGLBuffer(e){let{_gl:t}=this,n=k.ARRAY_BUFFER;e.descriptor.usage&f.INDEX?n=k.ELEMENT_ARRAY_BUFFER:e.descriptor.usage&f.UNIFORM&&(n=k.UNIFORM_BUFFER);let r=new _e(t.createBuffer(),n);return e._gpuData[this._renderer.uid]=r,this._managedBuffers.add(e)&&(n===k.ELEMENT_ARRAY_BUFFER?e.on(`update`,this._updateIndexBuffer,this):e.on(`update`,this.updateBuffer,this)),r}_updateIndexBuffer(e){let t=this.getGlBuffer(e);t.byteLength<0||(this._renderer.context.webGLVersion===2?this._upload(e,t,this._gl.COPY_WRITE_BUFFER):(this._renderer.geometry._activeVao&&this._renderer.geometry.resetState(),this._upload(e,t,t.type)))}resetState(){this._boundBuffers.length=0}};A.extension={type:[i.WebGLSystem],name:`buffer`};var j=class e{constructor(e){this.supports={uint32Indices:!0,uniformBufferObject:!0,vertexArrayObject:!0,srgbTextures:!0,nonPowOf2wrapping:!0,msaa:!0,nonPowOf2mipmaps:!0},this._renderer=e,this.extensions=Object.create(null),this.handleContextLost=this.handleContextLost.bind(this),this.handleContextRestored=this.handleContextRestored.bind(this)}get isLost(){return!this.gl||this.gl.isContextLost()}contextChange(e){this.gl=e,this._renderer.gl=e}init(t){t={...e.defaultOptions,...t};let n=this.multiView=t.multiView;if(t.context&&n&&(g(`Renderer created with both a context and multiview enabled. Disabling multiView as both cannot work together.`),n=!1),this.canvas=n?x.get().createCanvas(this._renderer.canvas.width,this._renderer.canvas.height):this._renderer.view.canvas,t.context)this.initFromContext(t.context);else{let e=this._renderer.background.alpha<1,n=t.premultipliedAlpha??!0,r=t.antialias&&!this._renderer.backBuffer.useBackBuffer;this.createContext(t.preferWebGLVersion,{alpha:e,premultipliedAlpha:n,antialias:r,stencil:!0,preserveDrawingBuffer:t.preserveDrawingBuffer,powerPreference:t.powerPreference??`default`})}}ensureCanvasSize(e){if(!this.multiView){e!==this.canvas&&g(`multiView is disabled, but targetCanvas is not the main canvas`);return}let{canvas:t}=this;(t.width<e.width||t.height<e.height)&&(t.width=Math.max(e.width,e.width),t.height=Math.max(e.height,e.height))}initFromContext(e){this.gl=e,this.webGLVersion=e instanceof x.get().getWebGLRenderingContext()?1:2,this.getExtensions(),this.validateContext(e),this._renderer.runners.contextChange.emit(e);let t=this._renderer.view.canvas;t.addEventListener(`webglcontextlost`,this.handleContextLost,!1),t.addEventListener(`webglcontextrestored`,this.handleContextRestored,!1)}createContext(e,t){let n,r=this.canvas;if(e===2&&(n=r.getContext(`webgl2`,t)),!n&&(n=r.getContext(`webgl`,t),!n))throw Error(`This browser does not support WebGL. Try using the canvas renderer`);this.gl=n,this.initFromContext(this.gl)}getExtensions(){let{gl:e}=this,t={anisotropicFiltering:e.getExtension(`EXT_texture_filter_anisotropic`),floatTextureLinear:e.getExtension(`OES_texture_float_linear`),s3tc:e.getExtension(`WEBGL_compressed_texture_s3tc`),s3tc_sRGB:e.getExtension(`WEBGL_compressed_texture_s3tc_srgb`),etc:e.getExtension(`WEBGL_compressed_texture_etc`),etc1:e.getExtension(`WEBGL_compressed_texture_etc1`),pvrtc:e.getExtension(`WEBGL_compressed_texture_pvrtc`)||e.getExtension(`WEBKIT_WEBGL_compressed_texture_pvrtc`),atc:e.getExtension(`WEBGL_compressed_texture_atc`),astc:e.getExtension(`WEBGL_compressed_texture_astc`),bptc:e.getExtension(`EXT_texture_compression_bptc`),rgtc:e.getExtension(`EXT_texture_compression_rgtc`),loseContext:e.getExtension(`WEBGL_lose_context`)};if(this.webGLVersion===1)this.extensions={...t,drawBuffers:e.getExtension(`WEBGL_draw_buffers`),depthTexture:e.getExtension(`WEBGL_depth_texture`),vertexArrayObject:e.getExtension(`OES_vertex_array_object`)||e.getExtension(`MOZ_OES_vertex_array_object`)||e.getExtension(`WEBKIT_OES_vertex_array_object`),uint32ElementIndex:e.getExtension(`OES_element_index_uint`),floatTexture:e.getExtension(`OES_texture_float`),floatTextureLinear:e.getExtension(`OES_texture_float_linear`),textureHalfFloat:e.getExtension(`OES_texture_half_float`),textureHalfFloatLinear:e.getExtension(`OES_texture_half_float_linear`),vertexAttribDivisorANGLE:e.getExtension(`ANGLE_instanced_arrays`),srgb:e.getExtension(`EXT_sRGB`)};else{this.extensions={...t,colorBufferFloat:e.getExtension(`EXT_color_buffer_float`)};let n=e.getExtension(`WEBGL_provoking_vertex`);n&&n.provokingVertexWEBGL(n.FIRST_VERTEX_CONVENTION_WEBGL)}}handleContextLost(e){e.preventDefault(),this._contextLossForced&&(this._contextLossForced=!1,setTimeout(()=>{this.gl.isContextLost()&&this.extensions.loseContext?.restoreContext()},0))}handleContextRestored(){this.getExtensions(),this._renderer.runners.contextChange.emit(this.gl)}destroy(){let e=this._renderer.view.canvas;this._renderer=null,e.removeEventListener(`webglcontextlost`,this.handleContextLost),e.removeEventListener(`webglcontextrestored`,this.handleContextRestored),this.gl.useProgram(null),this.extensions.loseContext?.loseContext()}forceContextLoss(){this.extensions.loseContext?.loseContext(),this._contextLossForced=!0}validateContext(e){let t=e.getContextAttributes();t&&!t.stencil&&g(`Provided WebGL context does not have a stencil buffer, masks may not render correctly`);let n=this.supports,r=this.webGLVersion===2,i=this.extensions;n.uint32Indices=r||!!i.uint32ElementIndex,n.uniformBufferObject=r,n.vertexArrayObject=r||!!i.vertexArrayObject,n.srgbTextures=r||!!i.srgb,n.nonPowOf2wrapping=r,n.nonPowOf2mipmaps=r,n.msaa=r,n.uint32Indices||g(`Provided WebGL context does not support 32 index buffer, large scenes may not render correctly`)}};j.extension={type:[i.WebGLSystem],name:`context`},j.defaultOptions={context:null,premultipliedAlpha:!0,preserveDrawingBuffer:!1,powerPreference:void 0,preferWebGLVersion:2,multiView:!1};var ve=j,M=(e=>(e[e.RGBA=6408]=`RGBA`,e[e.RGB=6407]=`RGB`,e[e.RG=33319]=`RG`,e[e.RED=6403]=`RED`,e[e.RGBA_INTEGER=36249]=`RGBA_INTEGER`,e[e.RGB_INTEGER=36248]=`RGB_INTEGER`,e[e.RG_INTEGER=33320]=`RG_INTEGER`,e[e.RED_INTEGER=36244]=`RED_INTEGER`,e[e.ALPHA=6406]=`ALPHA`,e[e.LUMINANCE=6409]=`LUMINANCE`,e[e.LUMINANCE_ALPHA=6410]=`LUMINANCE_ALPHA`,e[e.DEPTH_COMPONENT=6402]=`DEPTH_COMPONENT`,e[e.DEPTH_STENCIL=34041]=`DEPTH_STENCIL`,e))(M||{}),N=(e=>(e[e.TEXTURE_2D=3553]=`TEXTURE_2D`,e[e.TEXTURE_CUBE_MAP=34067]=`TEXTURE_CUBE_MAP`,e[e.TEXTURE_2D_ARRAY=35866]=`TEXTURE_2D_ARRAY`,e[e.TEXTURE_3D=32879]=`TEXTURE_3D`,e[e.TEXTURE_CUBE_MAP_POSITIVE_X=34069]=`TEXTURE_CUBE_MAP_POSITIVE_X`,e[e.TEXTURE_CUBE_MAP_NEGATIVE_X=34070]=`TEXTURE_CUBE_MAP_NEGATIVE_X`,e[e.TEXTURE_CUBE_MAP_POSITIVE_Y=34071]=`TEXTURE_CUBE_MAP_POSITIVE_Y`,e[e.TEXTURE_CUBE_MAP_NEGATIVE_Y=34072]=`TEXTURE_CUBE_MAP_NEGATIVE_Y`,e[e.TEXTURE_CUBE_MAP_POSITIVE_Z=34073]=`TEXTURE_CUBE_MAP_POSITIVE_Z`,e[e.TEXTURE_CUBE_MAP_NEGATIVE_Z=34074]=`TEXTURE_CUBE_MAP_NEGATIVE_Z`,e))(N||{}),P=(e=>(e[e.UNSIGNED_BYTE=5121]=`UNSIGNED_BYTE`,e[e.UNSIGNED_SHORT=5123]=`UNSIGNED_SHORT`,e[e.UNSIGNED_SHORT_5_6_5=33635]=`UNSIGNED_SHORT_5_6_5`,e[e.UNSIGNED_SHORT_4_4_4_4=32819]=`UNSIGNED_SHORT_4_4_4_4`,e[e.UNSIGNED_SHORT_5_5_5_1=32820]=`UNSIGNED_SHORT_5_5_5_1`,e[e.UNSIGNED_INT=5125]=`UNSIGNED_INT`,e[e.UNSIGNED_INT_10F_11F_11F_REV=35899]=`UNSIGNED_INT_10F_11F_11F_REV`,e[e.UNSIGNED_INT_2_10_10_10_REV=33640]=`UNSIGNED_INT_2_10_10_10_REV`,e[e.UNSIGNED_INT_24_8=34042]=`UNSIGNED_INT_24_8`,e[e.UNSIGNED_INT_5_9_9_9_REV=35902]=`UNSIGNED_INT_5_9_9_9_REV`,e[e.BYTE=5120]=`BYTE`,e[e.SHORT=5122]=`SHORT`,e[e.INT=5124]=`INT`,e[e.FLOAT=5126]=`FLOAT`,e[e.FLOAT_32_UNSIGNED_INT_24_8_REV=36269]=`FLOAT_32_UNSIGNED_INT_24_8_REV`,e[e.HALF_FLOAT=36193]=`HALF_FLOAT`,e))(P||{}),F={uint8x2:P.UNSIGNED_BYTE,uint8x4:P.UNSIGNED_BYTE,sint8x2:P.BYTE,sint8x4:P.BYTE,unorm8x2:P.UNSIGNED_BYTE,unorm8x4:P.UNSIGNED_BYTE,snorm8x2:P.BYTE,snorm8x4:P.BYTE,uint16x2:P.UNSIGNED_SHORT,uint16x4:P.UNSIGNED_SHORT,sint16x2:P.SHORT,sint16x4:P.SHORT,unorm16x2:P.UNSIGNED_SHORT,unorm16x4:P.UNSIGNED_SHORT,snorm16x2:P.SHORT,snorm16x4:P.SHORT,float16x2:P.HALF_FLOAT,float16x4:P.HALF_FLOAT,float32:P.FLOAT,float32x2:P.FLOAT,float32x3:P.FLOAT,float32x4:P.FLOAT,uint32:P.UNSIGNED_INT,uint32x2:P.UNSIGNED_INT,uint32x3:P.UNSIGNED_INT,uint32x4:P.UNSIGNED_INT,sint32:P.INT,sint32x2:P.INT,sint32x3:P.INT,sint32x4:P.INT};function ye(e){return F[e]??F.float32}var be={"point-list":0,"line-list":1,"line-strip":3,"triangle-list":4,"triangle-strip":5},xe=class{constructor(){this.vaoCache=Object.create(null)}destroy(){this.vaoCache=Object.create(null)}},I=class{constructor(e){this._renderer=e,this._activeGeometry=null,this._activeVao=null,this.hasVao=!0,this.hasInstance=!0,this._managedGeometries=new h({renderer:e,type:`resource`,onUnload:this.onGeometryUnload.bind(this),name:`glGeometry`})}contextChange(){let e=this.gl=this._renderer.gl;if(!this._renderer.context.supports.vertexArrayObject)throw Error(`[PixiJS] Vertex Array Objects are not supported on this device`);this.destroyAll(!0);let t=this._renderer.context.extensions.vertexArrayObject;t&&(e.createVertexArray=()=>t.createVertexArrayOES(),e.bindVertexArray=e=>t.bindVertexArrayOES(e),e.deleteVertexArray=e=>t.deleteVertexArrayOES(e));let n=this._renderer.context.extensions.vertexAttribDivisorANGLE;n&&(e.drawArraysInstanced=(e,t,r,i)=>{n.drawArraysInstancedANGLE(e,t,r,i)},e.drawElementsInstanced=(e,t,r,i,a)=>{n.drawElementsInstancedANGLE(e,t,r,i,a)},e.vertexAttribDivisor=(e,t)=>n.vertexAttribDivisorANGLE(e,t)),this._activeGeometry=null,this._activeVao=null}bind(e,t){let n=this.gl;this._activeGeometry=e;let r=this.getVao(e,t);this._activeVao!==r&&(this._activeVao=r,n.bindVertexArray(r)),this.updateBuffers()}resetState(){this.unbind()}updateBuffers(){let e=this._activeGeometry,t=this._renderer.buffer;for(let n=0;n<e.buffers.length;n++){let r=e.buffers[n];t.updateBuffer(r)}e._gcLastUsed=this._renderer.gc.now}checkCompatibility(e,t){let n=e.attributes,r=t._attributeData;for(let e in r)if(!n[e])throw Error(`shader and geometry incompatible, geometry missing the "${e}" attribute`)}getSignature(e,t){let n=e.attributes,r=t._attributeData,i=[`g`,e.uid];for(let e in n)r[e]&&i.push(e,r[e].location);return i.join(`-`)}getVao(e,t){return e._gpuData[this._renderer.uid]?.vaoCache[t._key]||this.initGeometryVao(e,t)}initGeometryVao(e,t,n=!0){let r=this._renderer.gl,i=this._renderer.buffer;this._renderer.shader._getProgramData(t),this.checkCompatibility(e,t);let a=this.getSignature(e,t),o=e._gpuData[this._renderer.uid];o||(o=new xe,e._gpuData[this._renderer.uid]=o,this._managedGeometries.add(e));let s=o.vaoCache,c=s[a];if(c)return s[t._key]=c,c;ce(e,t._attributeData);let l=e.buffers;c=r.createVertexArray(),r.bindVertexArray(c);for(let e=0;e<l.length;e++){let t=l[e];i.bind(t)}return this.activateVao(e,t),s[t._key]=c,s[a]=c,r.bindVertexArray(null),c}onGeometryUnload(e,t=!1){let n=e._gpuData[this._renderer.uid];if(!n)return;let r=n.vaoCache;if(!t)for(let e in r)this._activeVao===r[e]&&this.resetState(),this.gl.deleteVertexArray(r[e])}destroyAll(e=!1){this._managedGeometries.removeAll(e)}activateVao(e,t){let n=this._renderer.gl,r=this._renderer.buffer,i=e.attributes;e.indexBuffer&&r.bind(e.indexBuffer);let a=null;for(let e in i){let o=i[e],s=o.buffer,c=r.getGlBuffer(s),l=t._attributeData[e];if(l){a!==c&&(r.bind(s),a=c);let e=l.location;n.enableVertexAttribArray(e);let t=m(o.format),i=ye(o.format);if(l.format?.substring(1,4)===`int`?n.vertexAttribIPointer(e,t.size,i,o.stride,o.offset):n.vertexAttribPointer(e,t.size,i,t.normalised,o.stride,o.offset),o.instance){if(this.hasInstance){let t=o.divisor??1;n.vertexAttribDivisor(e,t)}else throw Error(`geometry error, GPU Instancing is not supported on this device`)}}}}draw(e,t,n,r){let{gl:i}=this._renderer,a=this._activeGeometry,o=be[e||a.topology];if(r??=a.instanceCount,a.indexBuffer){let e=a.indexBuffer.data.BYTES_PER_ELEMENT,s=e===2?i.UNSIGNED_SHORT:i.UNSIGNED_INT,c=t||a.indexCount||a.indexBuffer.data.length,l=(n||0)*e;r===1?i.drawElements(o,c,s,l):i.drawElementsInstanced(o,c,s,l,r)}else r===1?i.drawArrays(o,n||0,t||a.vertexCount):i.drawArraysInstanced(o,n||0,t||a.vertexCount,r);return this}unbind(){this.gl.bindVertexArray(null),this._activeVao=null,this._activeGeometry=null}destroy(){this._managedGeometries.destroy(),this._renderer=null,this.gl=null,this._activeVao=null,this._activeGeometry=null}};I.extension={type:[i.WebGLSystem],name:`geometry`};var Se=new te({attributes:{aPosition:[-1,-1,3,-1,-1,3]}}),L=class e{constructor(e){this.useBackBuffer=!1,this._useBackBufferThisRender=!1,this._renderer=e}init(t={}){let{useBackBuffer:n,antialias:r}={...e.defaultOptions,...t};this.useBackBuffer=n,this._antialias=r,this._renderer.context.supports.msaa||(g(`antialiasing, is not supported on when using the back buffer`),this._antialias=!1),this._state=d.for2d();let i=new o({vertex:`
1
+ import{A as e,C as t,Ct as n,Dt as r,Et as i,F as a,H as o,K as s,L as c,N as l,O as u,P as d,S as f,Tt as p,V as m,_ as ee,b as te,bt as ne,c as h,ct as g,d as re,dt as _,gt as v,h as ie,p as y,pt as b,q as x,v as S,w as C,xt as w,z as T}from"./index-41-d13J1.js";import{a as ae,c as oe,d as se,l as ce,n as le,o as E,p as D,r as ue,s as de,t as fe}from"./getTexelRangeRects-CRAnqulP.js";import{n as pe,r as me,t as he}from"./RenderTargetSystem-um8Nv1HQ.js";function ge(){let{userAgent:e}=x.get().getNavigator();return/^((?!chrome|android).)*safari/i.test(e)}var O=class{constructor(){this._tempState=d.for2d(),this._didUploadHash={}}init(e){e.renderer.runners.contextChange.add(this)}contextChange(){this._didUploadHash={}}start(e,t,n){let r=e.renderer,i=this._didUploadHash[n.uid];r.shader.bind(n,i),i||(this._didUploadHash[n.uid]=!0),r.shader.updateUniformGroup(r.globalUniforms.uniformGroup),r.geometry.bind(t,n.glProgram)}execute(e,t){let n=e.renderer;this._tempState.blendMode=t.blendMode,n.state.set(this._tempState);let r=t.textures.textures;for(let e=0;e<t.textures.count;e++)n.texture.bind(r[e],e);n.texture.unbindIntegerTextures(t.textures.count),n.geometry.draw(t.topology,t.size,t.start)}};O.extension={type:[i.WebGLPipesAdaptor],name:`batch`};var k=(e=>(e[e.ELEMENT_ARRAY_BUFFER=34963]=`ELEMENT_ARRAY_BUFFER`,e[e.ARRAY_BUFFER=34962]=`ARRAY_BUFFER`,e[e.UNIFORM_BUFFER=35345]=`UNIFORM_BUFFER`,e))(k||{}),_e=class{constructor(e,t){this.buffer=e||null,this.updateID=-1,this.byteLength=-1,this.type=t}destroy(){this.buffer=null,this.updateID=-1,this.byteLength=-1,this.type=-1}},A=class{constructor(e){this._boundBuffers=[],this._boundOffsets=[],this._boundSizes=[],this._renderer=e,this._managedBuffers=new h({renderer:e,type:`resource`,onUnload:this.onBufferUnload.bind(this),name:`glBuffer`})}destroy(){this._managedBuffers.destroy(),this._renderer=null,this._gl=null,this._boundBuffers.length=0}contextChange(){this._gl=this._renderer.gl,this.destroyAll(!0),this._boundBuffers.length=0}getGlBuffer(e){return e._gcLastUsed=this._renderer.gc.now,e._gpuData[this._renderer.uid]||this.createGLBuffer(e)}bind(e){let{_gl:t}=this,n=this.getGlBuffer(e);t.bindBuffer(n.type,n.buffer)}bindBufferBase(e,t){(this._boundBuffers[t]!==e||this._boundSizes[t]!==-1)&&(this._boundBuffers[t]=e,this._boundOffsets[t]=0,this._boundSizes[t]=-1,this._gl.bindBufferBase(this._gl.UNIFORM_BUFFER,t,e.buffer))}bindBufferRange(e,t=0,n=0,r){r??=e.byteLength-n,(this._boundBuffers[t]!==e||this._boundOffsets[t]!==n||this._boundSizes[t]!==r)&&(this._boundBuffers[t]=e,this._boundOffsets[t]=n,this._boundSizes[t]=r,this._gl.bindBufferRange(this._gl.UNIFORM_BUFFER,t,e.buffer,n,r))}updateBuffer(e){let t=this.getGlBuffer(e);return this._upload(e,t,t.type),t}_upload(e,t,n){let{_gl:r}=this;if(e._updateID===t.updateID)return;t.updateID=e._updateID,r.bindBuffer(n,t.buffer);let i=e.data,a=e.descriptor.usage&f.STATIC?r.STATIC_DRAW:r.DYNAMIC_DRAW;if(i){if(t.byteLength>=i.byteLength){let t=e._updateOffset/i.BYTES_PER_ELEMENT,a=(e._updateSize||i.byteLength)/i.BYTES_PER_ELEMENT;this._renderer.context.webGLVersion===2?r.bufferSubData(n,e._updateOffset,i,t,a):r.bufferSubData(n,e._updateOffset,a===i.length?i:i.subarray(t,t+a))}else t.byteLength=i.byteLength,r.bufferData(n,i,a)}else t.byteLength=e.descriptor.size,r.bufferData(n,t.byteLength,a)}destroyAll(e=!1){this._managedBuffers.removeAll(e)}onBufferUnload(e,t=!1){e.off(`update`,this.updateBuffer,this),e.off(`update`,this._updateIndexBuffer,this);let n=e._gpuData[this._renderer.uid];n&&(t||this._gl.deleteBuffer(n.buffer))}createGLBuffer(e){let{_gl:t}=this,n=k.ARRAY_BUFFER;e.descriptor.usage&f.INDEX?n=k.ELEMENT_ARRAY_BUFFER:e.descriptor.usage&f.UNIFORM&&(n=k.UNIFORM_BUFFER);let r=new _e(t.createBuffer(),n);return e._gpuData[this._renderer.uid]=r,this._managedBuffers.add(e)&&(n===k.ELEMENT_ARRAY_BUFFER?e.on(`update`,this._updateIndexBuffer,this):e.on(`update`,this.updateBuffer,this)),r}_updateIndexBuffer(e){let t=this.getGlBuffer(e);t.byteLength<0||(this._renderer.context.webGLVersion===2?this._upload(e,t,this._gl.COPY_WRITE_BUFFER):(this._renderer.geometry._activeVao&&this._renderer.geometry.resetState(),this._upload(e,t,t.type)))}resetState(){this._boundBuffers.length=0}};A.extension={type:[i.WebGLSystem],name:`buffer`};var j=class e{constructor(e){this.supports={uint32Indices:!0,uniformBufferObject:!0,vertexArrayObject:!0,srgbTextures:!0,nonPowOf2wrapping:!0,msaa:!0,nonPowOf2mipmaps:!0},this._renderer=e,this.extensions=Object.create(null),this.handleContextLost=this.handleContextLost.bind(this),this.handleContextRestored=this.handleContextRestored.bind(this)}get isLost(){return!this.gl||this.gl.isContextLost()}contextChange(e){this.gl=e,this._renderer.gl=e}init(t){t={...e.defaultOptions,...t};let n=this.multiView=t.multiView;if(t.context&&n&&(g(`Renderer created with both a context and multiview enabled. Disabling multiView as both cannot work together.`),n=!1),this.canvas=n?x.get().createCanvas(this._renderer.canvas.width,this._renderer.canvas.height):this._renderer.view.canvas,t.context)this.initFromContext(t.context);else{let e=this._renderer.background.alpha<1,n=t.premultipliedAlpha??!0,r=t.antialias&&!this._renderer.backBuffer.useBackBuffer;this.createContext(t.preferWebGLVersion,{alpha:e,premultipliedAlpha:n,antialias:r,stencil:!0,preserveDrawingBuffer:t.preserveDrawingBuffer,powerPreference:t.powerPreference??`default`})}}ensureCanvasSize(e){if(!this.multiView){e!==this.canvas&&g(`multiView is disabled, but targetCanvas is not the main canvas`);return}let{canvas:t}=this;(t.width<e.width||t.height<e.height)&&(t.width=Math.max(e.width,e.width),t.height=Math.max(e.height,e.height))}initFromContext(e){this.gl=e,this.webGLVersion=e instanceof x.get().getWebGLRenderingContext()?1:2,this.getExtensions(),this.validateContext(e),this._renderer.runners.contextChange.emit(e);let t=this._renderer.view.canvas;t.addEventListener(`webglcontextlost`,this.handleContextLost,!1),t.addEventListener(`webglcontextrestored`,this.handleContextRestored,!1)}createContext(e,t){let n,r=this.canvas;if(e===2&&(n=r.getContext(`webgl2`,t)),!n&&(n=r.getContext(`webgl`,t),!n))throw Error(`This browser does not support WebGL. Try using the canvas renderer`);this.gl=n,this.initFromContext(this.gl)}getExtensions(){let{gl:e}=this,t={anisotropicFiltering:e.getExtension(`EXT_texture_filter_anisotropic`),floatTextureLinear:e.getExtension(`OES_texture_float_linear`),s3tc:e.getExtension(`WEBGL_compressed_texture_s3tc`),s3tc_sRGB:e.getExtension(`WEBGL_compressed_texture_s3tc_srgb`),etc:e.getExtension(`WEBGL_compressed_texture_etc`),etc1:e.getExtension(`WEBGL_compressed_texture_etc1`),pvrtc:e.getExtension(`WEBGL_compressed_texture_pvrtc`)||e.getExtension(`WEBKIT_WEBGL_compressed_texture_pvrtc`),atc:e.getExtension(`WEBGL_compressed_texture_atc`),astc:e.getExtension(`WEBGL_compressed_texture_astc`),bptc:e.getExtension(`EXT_texture_compression_bptc`),rgtc:e.getExtension(`EXT_texture_compression_rgtc`),loseContext:e.getExtension(`WEBGL_lose_context`)};if(this.webGLVersion===1)this.extensions={...t,drawBuffers:e.getExtension(`WEBGL_draw_buffers`),depthTexture:e.getExtension(`WEBGL_depth_texture`),vertexArrayObject:e.getExtension(`OES_vertex_array_object`)||e.getExtension(`MOZ_OES_vertex_array_object`)||e.getExtension(`WEBKIT_OES_vertex_array_object`),uint32ElementIndex:e.getExtension(`OES_element_index_uint`),floatTexture:e.getExtension(`OES_texture_float`),floatTextureLinear:e.getExtension(`OES_texture_float_linear`),textureHalfFloat:e.getExtension(`OES_texture_half_float`),textureHalfFloatLinear:e.getExtension(`OES_texture_half_float_linear`),vertexAttribDivisorANGLE:e.getExtension(`ANGLE_instanced_arrays`),srgb:e.getExtension(`EXT_sRGB`)};else{this.extensions={...t,colorBufferFloat:e.getExtension(`EXT_color_buffer_float`)};let n=e.getExtension(`WEBGL_provoking_vertex`);n&&n.provokingVertexWEBGL(n.FIRST_VERTEX_CONVENTION_WEBGL)}}handleContextLost(e){e.preventDefault(),this._contextLossForced&&(this._contextLossForced=!1,setTimeout(()=>{this.gl.isContextLost()&&this.extensions.loseContext?.restoreContext()},0))}handleContextRestored(){this.getExtensions(),this._renderer.runners.contextChange.emit(this.gl)}destroy(){let e=this._renderer.view.canvas;this._renderer=null,e.removeEventListener(`webglcontextlost`,this.handleContextLost),e.removeEventListener(`webglcontextrestored`,this.handleContextRestored),this.gl.useProgram(null),this.extensions.loseContext?.loseContext()}forceContextLoss(){this.extensions.loseContext?.loseContext(),this._contextLossForced=!0}validateContext(e){let t=e.getContextAttributes();t&&!t.stencil&&g(`Provided WebGL context does not have a stencil buffer, masks may not render correctly`);let n=this.supports,r=this.webGLVersion===2,i=this.extensions;n.uint32Indices=r||!!i.uint32ElementIndex,n.uniformBufferObject=r,n.vertexArrayObject=r||!!i.vertexArrayObject,n.srgbTextures=r||!!i.srgb,n.nonPowOf2wrapping=r,n.nonPowOf2mipmaps=r,n.msaa=r,n.uint32Indices||g(`Provided WebGL context does not support 32 index buffer, large scenes may not render correctly`)}};j.extension={type:[i.WebGLSystem],name:`context`},j.defaultOptions={context:null,premultipliedAlpha:!0,preserveDrawingBuffer:!1,powerPreference:void 0,preferWebGLVersion:2,multiView:!1};var ve=j,M=(e=>(e[e.RGBA=6408]=`RGBA`,e[e.RGB=6407]=`RGB`,e[e.RG=33319]=`RG`,e[e.RED=6403]=`RED`,e[e.RGBA_INTEGER=36249]=`RGBA_INTEGER`,e[e.RGB_INTEGER=36248]=`RGB_INTEGER`,e[e.RG_INTEGER=33320]=`RG_INTEGER`,e[e.RED_INTEGER=36244]=`RED_INTEGER`,e[e.ALPHA=6406]=`ALPHA`,e[e.LUMINANCE=6409]=`LUMINANCE`,e[e.LUMINANCE_ALPHA=6410]=`LUMINANCE_ALPHA`,e[e.DEPTH_COMPONENT=6402]=`DEPTH_COMPONENT`,e[e.DEPTH_STENCIL=34041]=`DEPTH_STENCIL`,e))(M||{}),N=(e=>(e[e.TEXTURE_2D=3553]=`TEXTURE_2D`,e[e.TEXTURE_CUBE_MAP=34067]=`TEXTURE_CUBE_MAP`,e[e.TEXTURE_2D_ARRAY=35866]=`TEXTURE_2D_ARRAY`,e[e.TEXTURE_3D=32879]=`TEXTURE_3D`,e[e.TEXTURE_CUBE_MAP_POSITIVE_X=34069]=`TEXTURE_CUBE_MAP_POSITIVE_X`,e[e.TEXTURE_CUBE_MAP_NEGATIVE_X=34070]=`TEXTURE_CUBE_MAP_NEGATIVE_X`,e[e.TEXTURE_CUBE_MAP_POSITIVE_Y=34071]=`TEXTURE_CUBE_MAP_POSITIVE_Y`,e[e.TEXTURE_CUBE_MAP_NEGATIVE_Y=34072]=`TEXTURE_CUBE_MAP_NEGATIVE_Y`,e[e.TEXTURE_CUBE_MAP_POSITIVE_Z=34073]=`TEXTURE_CUBE_MAP_POSITIVE_Z`,e[e.TEXTURE_CUBE_MAP_NEGATIVE_Z=34074]=`TEXTURE_CUBE_MAP_NEGATIVE_Z`,e))(N||{}),P=(e=>(e[e.UNSIGNED_BYTE=5121]=`UNSIGNED_BYTE`,e[e.UNSIGNED_SHORT=5123]=`UNSIGNED_SHORT`,e[e.UNSIGNED_SHORT_5_6_5=33635]=`UNSIGNED_SHORT_5_6_5`,e[e.UNSIGNED_SHORT_4_4_4_4=32819]=`UNSIGNED_SHORT_4_4_4_4`,e[e.UNSIGNED_SHORT_5_5_5_1=32820]=`UNSIGNED_SHORT_5_5_5_1`,e[e.UNSIGNED_INT=5125]=`UNSIGNED_INT`,e[e.UNSIGNED_INT_10F_11F_11F_REV=35899]=`UNSIGNED_INT_10F_11F_11F_REV`,e[e.UNSIGNED_INT_2_10_10_10_REV=33640]=`UNSIGNED_INT_2_10_10_10_REV`,e[e.UNSIGNED_INT_24_8=34042]=`UNSIGNED_INT_24_8`,e[e.UNSIGNED_INT_5_9_9_9_REV=35902]=`UNSIGNED_INT_5_9_9_9_REV`,e[e.BYTE=5120]=`BYTE`,e[e.SHORT=5122]=`SHORT`,e[e.INT=5124]=`INT`,e[e.FLOAT=5126]=`FLOAT`,e[e.FLOAT_32_UNSIGNED_INT_24_8_REV=36269]=`FLOAT_32_UNSIGNED_INT_24_8_REV`,e[e.HALF_FLOAT=36193]=`HALF_FLOAT`,e))(P||{}),F={uint8x2:P.UNSIGNED_BYTE,uint8x4:P.UNSIGNED_BYTE,sint8x2:P.BYTE,sint8x4:P.BYTE,unorm8x2:P.UNSIGNED_BYTE,unorm8x4:P.UNSIGNED_BYTE,snorm8x2:P.BYTE,snorm8x4:P.BYTE,uint16x2:P.UNSIGNED_SHORT,uint16x4:P.UNSIGNED_SHORT,sint16x2:P.SHORT,sint16x4:P.SHORT,unorm16x2:P.UNSIGNED_SHORT,unorm16x4:P.UNSIGNED_SHORT,snorm16x2:P.SHORT,snorm16x4:P.SHORT,float16x2:P.HALF_FLOAT,float16x4:P.HALF_FLOAT,float32:P.FLOAT,float32x2:P.FLOAT,float32x3:P.FLOAT,float32x4:P.FLOAT,uint32:P.UNSIGNED_INT,uint32x2:P.UNSIGNED_INT,uint32x3:P.UNSIGNED_INT,uint32x4:P.UNSIGNED_INT,sint32:P.INT,sint32x2:P.INT,sint32x3:P.INT,sint32x4:P.INT};function ye(e){return F[e]??F.float32}var be={"point-list":0,"line-list":1,"line-strip":3,"triangle-list":4,"triangle-strip":5},xe=class{constructor(){this.vaoCache=Object.create(null)}destroy(){this.vaoCache=Object.create(null)}},I=class{constructor(e){this._renderer=e,this._activeGeometry=null,this._activeVao=null,this.hasVao=!0,this.hasInstance=!0,this._managedGeometries=new h({renderer:e,type:`resource`,onUnload:this.onGeometryUnload.bind(this),name:`glGeometry`})}contextChange(){let e=this.gl=this._renderer.gl;if(!this._renderer.context.supports.vertexArrayObject)throw Error(`[PixiJS] Vertex Array Objects are not supported on this device`);this.destroyAll(!0);let t=this._renderer.context.extensions.vertexArrayObject;t&&(e.createVertexArray=()=>t.createVertexArrayOES(),e.bindVertexArray=e=>t.bindVertexArrayOES(e),e.deleteVertexArray=e=>t.deleteVertexArrayOES(e));let n=this._renderer.context.extensions.vertexAttribDivisorANGLE;n&&(e.drawArraysInstanced=(e,t,r,i)=>{n.drawArraysInstancedANGLE(e,t,r,i)},e.drawElementsInstanced=(e,t,r,i,a)=>{n.drawElementsInstancedANGLE(e,t,r,i,a)},e.vertexAttribDivisor=(e,t)=>n.vertexAttribDivisorANGLE(e,t)),this._activeGeometry=null,this._activeVao=null}bind(e,t){let n=this.gl;this._activeGeometry=e;let r=this.getVao(e,t);this._activeVao!==r&&(this._activeVao=r,n.bindVertexArray(r)),this.updateBuffers()}resetState(){this.unbind()}updateBuffers(){let e=this._activeGeometry,t=this._renderer.buffer;for(let n=0;n<e.buffers.length;n++){let r=e.buffers[n];t.updateBuffer(r)}e._gcLastUsed=this._renderer.gc.now}checkCompatibility(e,t){let n=e.attributes,r=t._attributeData;for(let e in r)if(!n[e])throw Error(`shader and geometry incompatible, geometry missing the "${e}" attribute`)}getSignature(e,t){let n=e.attributes,r=t._attributeData,i=[`g`,e.uid];for(let e in n)r[e]&&i.push(e,r[e].location);return i.join(`-`)}getVao(e,t){return e._gpuData[this._renderer.uid]?.vaoCache[t._key]||this.initGeometryVao(e,t)}initGeometryVao(e,t,n=!0){let r=this._renderer.gl,i=this._renderer.buffer;this._renderer.shader._getProgramData(t),this.checkCompatibility(e,t);let a=this.getSignature(e,t),o=e._gpuData[this._renderer.uid];o||(o=new xe,e._gpuData[this._renderer.uid]=o,this._managedGeometries.add(e));let s=o.vaoCache,c=s[a];if(c)return s[t._key]=c,c;ce(e,t._attributeData);let l=e.buffers;c=r.createVertexArray(),r.bindVertexArray(c);for(let e=0;e<l.length;e++){let t=l[e];i.bind(t)}return this.activateVao(e,t),s[t._key]=c,s[a]=c,r.bindVertexArray(null),c}onGeometryUnload(e,t=!1){let n=e._gpuData[this._renderer.uid];if(!n)return;let r=n.vaoCache;if(!t)for(let e in r)this._activeVao===r[e]&&this.resetState(),this.gl.deleteVertexArray(r[e])}destroyAll(e=!1){this._managedGeometries.removeAll(e)}activateVao(e,t){let n=this._renderer.gl,r=this._renderer.buffer,i=e.attributes;e.indexBuffer&&r.bind(e.indexBuffer);let a=null;for(let e in i){let o=i[e],s=o.buffer,c=r.getGlBuffer(s),l=t._attributeData[e];if(l){a!==c&&(r.bind(s),a=c);let e=l.location;n.enableVertexAttribArray(e);let t=m(o.format),i=ye(o.format);if(l.format?.substring(1,4)===`int`?n.vertexAttribIPointer(e,t.size,i,o.stride,o.offset):n.vertexAttribPointer(e,t.size,i,t.normalised,o.stride,o.offset),o.instance){if(this.hasInstance){let t=o.divisor??1;n.vertexAttribDivisor(e,t)}else throw Error(`geometry error, GPU Instancing is not supported on this device`)}}}}draw(e,t,n,r){let{gl:i}=this._renderer,a=this._activeGeometry,o=be[e||a.topology];if(r??=a.instanceCount,a.indexBuffer){let e=a.indexBuffer.data.BYTES_PER_ELEMENT,s=e===2?i.UNSIGNED_SHORT:i.UNSIGNED_INT,c=t||a.indexCount||a.indexBuffer.data.length,l=(n||0)*e;r===1?i.drawElements(o,c,s,l):i.drawElementsInstanced(o,c,s,l,r)}else r===1?i.drawArrays(o,n||0,t||a.vertexCount):i.drawArraysInstanced(o,n||0,t||a.vertexCount,r);return this}unbind(){this.gl.bindVertexArray(null),this._activeVao=null,this._activeGeometry=null}destroy(){this._managedGeometries.destroy(),this._renderer=null,this.gl=null,this._activeVao=null,this._activeGeometry=null}};I.extension={type:[i.WebGLSystem],name:`geometry`};var Se=new te({attributes:{aPosition:[-1,-1,3,-1,-1,3]}}),L=class e{constructor(e){this.useBackBuffer=!1,this._useBackBufferThisRender=!1,this._renderer=e}init(t={}){let{useBackBuffer:n,antialias:r}={...e.defaultOptions,...t};this.useBackBuffer=n,this._antialias=r,this._renderer.context.supports.msaa||(g(`antialiasing, is not supported on when using the back buffer`),this._antialias=!1),this._state=d.for2d();let i=new o({vertex:`
2
2
  attribute vec2 aPosition;
3
3
  out vec2 vUv;
4
4
 
@@ -1,4 +1,4 @@
1
- import{A as e,Ct as t,Dt as n,Et as r,F as i,I as a,K as o,L as s,O as c,P as l,R as u,S as d,T as f,U as p,c as m,ct as h,dt as g,f as _,g as v,gt as y,l as b,m as x,pt as S,q as C,w,x as ee,xt as T,y as E,z as D}from"./index-CE-lli1m.js";import{a as te,c as ne,f as re,i as ie,l as O,m as ae,n as oe,s as se,t as ce,u as le}from"./getTexelRangeRects-D3pwCyRt.js";import{n as ue,r as de,t as fe}from"./RenderTargetSystem-Dk1U4wDJ.js";import{t as k}from"./CanvasPool-PBu3bHFZ.js";var A=l.for2d(),j=class{start(e,t,n){let r=e.renderer,i=r.encoder,a=n.gpuProgram;this._shader=n,this._geometry=t,i.setGeometry(t,a),A.blendMode=`normal`,r.pipeline.getPipeline(t,a,A,void 0,n._overrides);let o=r.globalUniforms.bindGroup;i.resetBindGroup(1),i.setBindGroup(0,o,a)}execute(e,t){let n=this._shader.gpuProgram,r=e.renderer,i=r.encoder;if(!t.bindGroup){let e=t.textures;t.bindGroup=b(e.textures,e.count,r.limits.maxBatchableTextures)}A.blendMode=t.blendMode;let a=r.bindGroup.getBindGroup(t.bindGroup,n,1),o=r.pipeline.getPipeline(this._geometry,n,A,t.topology,this._shader._overrides);t.bindGroup._touch(r.gc.now),i.setPipeline(o),i.renderPassEncoder.setBindGroup(1,a),i.renderPassEncoder.drawIndexed(t.size,1,t.start)}};j.extension={type:[r.WebGPUPipesAdaptor],name:`batch`};var pe=0,me=class{constructor(e,t,n,r,i,a){this.autoGarbageCollect=!0,this._gpuData=null,this.gpuBindGroup=e,this._gcLastUsed=t,this.keyLow=n,this.keyHigh=r,this.layoutKey=i,this.cacheId=a}unload(){this.gpuBindGroup=null}},M=class{constructor(e){this._hash=Object.create(null),this._cacheId=0,this._renderer=e,e.gc.addResourceHash(this,`_hash`,`resource`),e.gc.addCollection(this,`_hash`,`hash`)}contextChange(e){this._gpu=e,this._cacheId=++pe,this._hash=Object.create(null)}getBindGroup(e,t,n){let r=t._layoutKey<<4|n,i=e._gpuEntry;if(i!==null&&e._gpuEntryLayoutKey===r&&i.gpuBindGroup!==null&&i.cacheId===this._cacheId)return i._gcLastUsed=this._renderer.gc.now,i.gpuBindGroup;let a=e._keyLow,o=e._keyHigh,s=(a^Math.imul(r+1,0x9e3779b1))&0x3fffffff;return i=this._hash[s],i&&i.keyLow===a&&i.keyHigh===o&&i.layoutKey===r?i._gcLastUsed=this._renderer.gc.now:(i=new me(this._createBindGroup(e,t,n),this._renderer.gc.now,a,o,r,this._cacheId),this._hash[s]=i),e._gpuEntry=i,e._gpuEntryLayoutKey=r,i.gpuBindGroup}_createBindGroup(e,t,n){let r=this._gpu.device,i=t.layout[n],a=e.layout,o=[],s=this._renderer;for(let t in i){let n=e.resources[a?a[t]:i[t]];if(!n||n.destroyed)throw Error(`[BindGroup] no usable resource for the shader's '${t}' binding: it was never set, was destroyed while a shader still uses it, or is missing from the bind group's layout.`);let r;if(n._resourceType===`uniformGroup`){let e=n;s.ubo.updateUniformGroup(e);let t=e.buffer;r={buffer:s.buffer.getGPUBuffer(t),offset:0,size:t.descriptor.size}}else if(n._resourceType===`buffer`){let e=n;r={buffer:s.buffer.getGPUBuffer(e),offset:0,size:e.descriptor.size}}else if(n._resourceType===`bufferResource`){let e=n;r={buffer:s.buffer.getGPUBuffer(e.buffer),offset:e.offset,size:e.size}}else if(n._resourceType===`textureSampler`){let e=n;r=s.texture.getGpuSampler(e)}else if(n._resourceType===`textureSource`){let e=n;r=s.texture.getTextureView(e)}else if(n._resourceType===`textureView`){let e=n;r=s.texture.getTextureView(e.source,e.viewDescriptor)}o.push({binding:i[t],resource:r})}let c=s.shader.getProgramData(t).bindGroups[n];return r.createBindGroup({layout:c,entries:o})}destroy(){this._hash=null,this._renderer=null}};M.extension={type:[r.WebGPUSystem],name:`bindGroup`};var he=class{constructor(e){this.gpuBuffer=e}destroy(){this.gpuBuffer.destroy(),this.gpuBuffer=null}},N=class{constructor(e){this._renderer=e,this._managedBuffers=new m({renderer:e,type:`resource`,onUnload:this.onBufferUnload.bind(this),name:`gpuBuffer`})}contextChange(e){this._gpu=e,this.destroyAll()}getGPUBuffer(e){return e._gcLastUsed=this._renderer.gc.now,e._gpuData[this._renderer.uid]?.gpuBuffer||this.createGPUBuffer(e)}updateBuffer(e){let t=this.getGPUBuffer(e),n=e.data;return e._updateID&&n&&(e._updateID=0,this._gpu.device.queue.writeBuffer(t,e._updateOffset,n.buffer,n.byteOffset+e._updateOffset,(e._updateSize||n.byteLength)+3&-4)),t}destroyAll(){this._managedBuffers.removeAll()}onBufferUnload(e){e.off(`update`,this.updateBuffer,this),e.off(`change`,this.onBufferChange,this)}createGPUBuffer(e){let t=this._gpu.device.createBuffer(e.descriptor);return e._updateID=0,e.data&&(f(e.data.buffer,t.getMappedRange(),e.data.byteOffset,e.data.byteLength),t.unmap()),e._gpuData[this._renderer.uid]=new he(t),this._managedBuffers.add(e)&&(e.on(`update`,this.updateBuffer,this),e.on(`change`,this.onBufferChange,this)),t}onBufferChange(e){this._managedBuffers.remove(e),e._updateID=0,this.createGPUBuffer(e)}destroy(){this._managedBuffers.destroy(),this._renderer=null,this._gpu=null}};N.extension={type:[r.WebGPUSystem],name:`buffer`};var ge=class{constructor({minUniformOffsetAlignment:e}){this._minUniformOffsetAlignment=256,this.byteIndex=0,this._minUniformOffsetAlignment=e,this.data=new Float32Array(65535)}clear(){this.byteIndex=0}addEmptyGroup(e){if(e>this._minUniformOffsetAlignment/4)throw Error(`UniformBufferBatch: array is too large: ${e*4}`);let t=this.byteIndex,n=t+e*4;if(n=Math.ceil(n/this._minUniformOffsetAlignment)*this._minUniformOffsetAlignment,n>this.data.length*4)throw Error(`UniformBufferBatch: ubo batch got too big`);return this.byteIndex=n,t}addGroup(e){let t=this.addEmptyGroup(e.length);for(let n=0;n<e.length;n++)this.data[t/4+n]=e[n];return t}destroy(){this.data=null}},P=class{constructor(e){this._colorMaskCache=15,this._renderer=e}setMask(e){this._colorMaskCache!==e&&(this._colorMaskCache=e,this._renderer.pipeline.setColorMask(e))}destroy(){this._renderer=null,this._colorMaskCache=null}};P.extension={type:[r.WebGPUSystem],name:`colorMask`};function _e(e){let{userAgent:t}=C.get().getNavigator();if(!/AppleWebKit\//.test(t)||/Chrome\/|Chromium\//.test(t))return!1;if(!e)return!0;let n=/Version\/([\d.]+)/.exec(t)?.[1];return!n||!(e.from&&F(n,e.from)<0||e.before&&F(n,e.before)>=0)}function F(e,t){let n=e.split(`.`),r=t.split(`.`);for(let e=0;e<Math.max(n.length,r.length);e++){let t=(parseInt(n[e],10)||0)-(parseInt(r[e],10)||0);if(t)return t}return 0}var ve=new Set([`apple`,`arm`,`qualcomm`,`img-tec`]),I=class{constructor(e){this._renderer=e}async init(e){return this._initPromise||=(this._options=e,(e.gpu?Promise.resolve(e.gpu):this._createDeviceAndAdaptor(e)).then(e=>this._setGpu(e))),this._initPromise}_setGpu(e){this.gpu=e,this.extensions={transientAttachment:typeof GPUTextureUsage.TRANSIENT_ATTACHMENT==`number`&&!_e({from:`27.1`,before:`28`}),tileBased:ve.has(e.adapter?.info?.vendor)},this._options.gpu||e.device.lost.then(()=>this._restoreDevice()).catch(e=>h(`WebGPU device was lost and could not be restored`,e)),this._renderer.runners.contextChange.emit(this.gpu)}async _restoreDevice(){if(!this._renderer)return;let e=await this._createDeviceAndAdaptor(this._options);this._renderer?this._setGpu(e):e.device.destroy()}contextChange(e){this._renderer.gpu=e}async _createDeviceAndAdaptor(e){let t=await C.get().getNavigator().gpu.requestAdapter({powerPreference:e.powerPreference,forceFallbackAdapter:e.forceFallbackAdapter});if(!t)throw Error(`WebGPU not supported. No GPU adapter was returned by navigator.gpu.requestAdapter().`);let n=[`texture-compression-bc`,`texture-compression-astc`,`texture-compression-etc2`,`indirect-first-instance`,`bgra8unorm-storage`,`texture-formats-tier1`].filter(e=>t.features.has(e));return{adapter:t,device:await t.requestDevice({requiredFeatures:n,requiredLimits:{maxSampledTexturesPerShaderStage:t.limits.maxSampledTexturesPerShaderStage,maxSamplersPerShaderStage:t.limits.maxSamplersPerShaderStage,minUniformBufferOffsetAlignment:t.limits.minUniformBufferOffsetAlignment}})}}destroy(){this._options?.gpu||this.gpu?.device.destroy(),this.gpu=null,this.extensions=null,this._renderer=null}};I.extension={type:[r.WebGPUSystem],name:`device`},I.defaultOptions={powerPreference:void 0,forceFallbackAdapter:!1};var ye=class{constructor(e,t,n,r){this.gpuBundle=e,this.stateKey=t,this.device=n,this.label=r}},L=class{constructor(e){this._boundBindGroup=Object.create(null),this._boundVertexBuffer=Object.create(null),this._renderer=e;for(let e=0;e<16;e++)this._boundBindGroup[e]={bindGroup:null,program:null,entry:null}}renderStart(){this.commandFinished=new Promise(e=>{this._resolveCommandFinished=e}),this.commandEncoder=this._renderer.gpu.device.createCommandEncoder()}beginRenderPass(e){return this.endRenderPass(),this._clearCache(),this._passEncoder=this.commandEncoder.beginRenderPass(e.descriptor),this.renderPassEncoder=this._passEncoder,this._passEncoder}endRenderPass(){this._passEncoder&&this._passEncoder.end(),this.renderPassEncoder=null,this._passEncoder=null}beginBundle(e){if(this._passEncoder!==this.renderPassEncoder)throw Error(`Cannot begin a new render bundle while one is already being recorded.`);this._clearCache();let t=this._renderer.pipeline,n=t.getBundleDescriptor();n.label=e,this._bundleStateKey=t.bundleStateKey,this._bundleLabel=e,this.renderPassEncoder=this._gpu.device.createRenderBundleEncoder(n)}endBundle(){let e=this.renderPassEncoder;if(!e||!(`finish`in e))throw Error(`endBundle called without an active render bundle.`);let t=e.finish({label:this._bundleLabel});return this.renderPassEncoder=this._passEncoder,this._clearCache(),new ye(t,this._bundleStateKey,this._gpu.device,this._bundleLabel)}isBundleValid(e){return e?.stateKey===this._renderer.pipeline.bundleStateKey&&e.device===this._gpu.device}executeBundle(e){let t=[];if(Array.isArray(e))for(let n=0;n<e.length;n++)t[n]=this._getGpuBundle(e[n]);else t[0]=this._getGpuBundle(e);this._clearCache(),this._passEncoder.executeBundles(t)}_getGpuBundle(e){return this.isBundleValid(e)||h(`Render bundle ${e?.label??`(unlabeled)`} was recorded against a different render target state or on a lost device. Re-record it \u2014 replaying it will either be rejected by WebGPU or draw with the wrong winding. Check encoder.isBundleValid(bundle) before executing.`),e.gpuBundle}setViewport(e){this._passEncoder.setViewport(e.x,e.y,e.width,e.height,0,1)}setStencilReference(e){this._passEncoder.setStencilReference(e)}setPipelineFromGeometryProgramAndState(e,t,n,r,i){let a=this._renderer.pipeline.getPipeline(e,t,n,r,i);this.setPipeline(a)}setPipeline(e){this._boundPipeline!==e&&(this._boundPipeline=e,this.renderPassEncoder.setPipeline(e))}_setVertexBuffer(e,t){this._boundVertexBuffer[e]!==t&&(this._boundVertexBuffer[e]=t,this.renderPassEncoder.setVertexBuffer(e,this._renderer.buffer.updateBuffer(t)))}_setIndexBuffer(e){if(this._boundIndexBuffer===e)return;this._boundIndexBuffer=e;let t=e.data.BYTES_PER_ELEMENT===2?`uint16`:`uint32`;this.renderPassEncoder.setIndexBuffer(this._renderer.buffer.updateBuffer(e),t)}resetBindGroup(e){let t=this._boundBindGroup[e];t.bindGroup=null,t.program=null,t.entry=null}setBindGroup(e,t,n){let r=this._boundBindGroup[e];if(r.bindGroup===t&&r.program===n&&r.entry===t._gpuEntry)return;r.bindGroup=t,r.program=n,t._touch(this._renderer.gc.now);let i=this._renderer.bindGroup.getBindGroup(t,n,e);r.entry=t._gpuEntry,this.renderPassEncoder.setBindGroup(e,i)}setGeometry(e,t){let n=this._renderer.pipeline.getBufferNamesToBind(e,t);for(let t=0;t<n.length;t++)this._setVertexBuffer(t,e.attributes[n[t]].buffer);e.indexBuffer&&this._setIndexBuffer(e.indexBuffer)}_setShaderBindGroups(e,t){let n=e.gpuProgram,r=n.layout;for(let i=0;i<r.length;i++){let a=e.groups[i];r[i]&&a&&(t||this._syncBindGroup(a),this.setBindGroup(i,a,n))}}_syncBindGroup(e){let t=e.resources,n=e._resourceKeys;for(let e=0;e<n.length;e++){let r=t[n[e]];r&&r.isUniformGroup&&this._renderer.ubo.updateUniformGroup(r)}}draw(e){let{geometry:t,shader:n,state:r,topology:i,size:a,start:o,baseVertex:s,instanceCount:c,skipSync:l,firstInstance:u}=e;this.setPipelineFromGeometryProgramAndState(t,n.gpuProgram,r,i,n._overrides),this.setGeometry(t,n.gpuProgram),this._setShaderBindGroups(n,l),t.indexBuffer?this.renderPassEncoder.drawIndexed(a||t.indexCount||t.indexBuffer.data.length,c??t.instanceCount,o||0,s||0,u||0):this.renderPassEncoder.draw(a||t.vertexCount,c??t.instanceCount,o||0,u||0)}drawIndirect(e){let{geometry:t,shader:n,state:r,topology:i,skipSync:a,indirectBuffer:o,indirectOffset:s}=e;this.setPipelineFromGeometryProgramAndState(t,n.gpuProgram,r,i,n._overrides),this.setGeometry(t,n.gpuProgram),this._setShaderBindGroups(n,a),t.indexBuffer?this.renderPassEncoder.drawIndexedIndirect(o,s):this.renderPassEncoder.drawIndirect(o,s)}finishRenderPass(){this._passEncoder&&=(this._passEncoder.end(),this.renderPassEncoder=null,null)}postrender(){this.finishRenderPass(),this._gpu.device.queue.submit([this.commandEncoder.finish()]),this._resolveCommandFinished(),this.commandEncoder=null}_clearCache(){for(let e=0;e<16;e++){let t=this._boundBindGroup[e];t.bindGroup=null,t.program=null,t.entry=null,this._boundVertexBuffer[e]=null}this._boundIndexBuffer=null,this._boundPipeline=null}destroy(){this._renderer=null,this._gpu=null,this._boundBindGroup=null,this._boundVertexBuffer=null,this._boundIndexBuffer=null,this._boundPipeline=null,this.renderPassEncoder=null,this._passEncoder=null}contextChange(e){this._gpu=e}};L.extension={type:[r.WebGPUSystem],name:`encoder`,priority:1};var R=class{constructor(e){this.supportsOverrideConstants=!1,this._renderer=e}contextChange(){let e=this._renderer.device.gpu.device;this.maxTextures=Math.min(e.limits.maxSampledTexturesPerShaderStage,e.limits.maxSamplersPerShaderStage),this.maxBatchableTextures=this.maxTextures,this.minUniformBufferOffsetAlignment=e.limits.minUniformBufferOffsetAlignment,this._detectOverrideConstantsSupport(e)}_detectOverrideConstantsSupport(e){e.pushErrorScope(`validation`);let t=e.createShaderModule({code:`override TEST_VALUE: f32 = 0.0;
1
+ import{A as e,Ct as t,Dt as n,Et as r,F as i,I as a,K as o,L as s,O as c,P as l,R as u,S as d,T as f,U as p,c as m,ct as h,dt as g,f as _,g as v,gt as y,l as b,m as x,pt as S,q as C,w,x as ee,xt as T,y as E,z as D}from"./index-41-d13J1.js";import{a as te,c as ne,f as re,i as ie,l as O,m as ae,n as oe,s as se,t as ce,u as le}from"./getTexelRangeRects-CRAnqulP.js";import{n as ue,r as de,t as fe}from"./RenderTargetSystem-um8Nv1HQ.js";import{t as k}from"./CanvasPool-SkgMbnEH.js";var A=l.for2d(),j=class{start(e,t,n){let r=e.renderer,i=r.encoder,a=n.gpuProgram;this._shader=n,this._geometry=t,i.setGeometry(t,a),A.blendMode=`normal`,r.pipeline.getPipeline(t,a,A,void 0,n._overrides);let o=r.globalUniforms.bindGroup;i.resetBindGroup(1),i.setBindGroup(0,o,a)}execute(e,t){let n=this._shader.gpuProgram,r=e.renderer,i=r.encoder;if(!t.bindGroup){let e=t.textures;t.bindGroup=b(e.textures,e.count,r.limits.maxBatchableTextures)}A.blendMode=t.blendMode;let a=r.bindGroup.getBindGroup(t.bindGroup,n,1),o=r.pipeline.getPipeline(this._geometry,n,A,t.topology,this._shader._overrides);t.bindGroup._touch(r.gc.now),i.setPipeline(o),i.renderPassEncoder.setBindGroup(1,a),i.renderPassEncoder.drawIndexed(t.size,1,t.start)}};j.extension={type:[r.WebGPUPipesAdaptor],name:`batch`};var pe=0,me=class{constructor(e,t,n,r,i,a){this.autoGarbageCollect=!0,this._gpuData=null,this.gpuBindGroup=e,this._gcLastUsed=t,this.keyLow=n,this.keyHigh=r,this.layoutKey=i,this.cacheId=a}unload(){this.gpuBindGroup=null}},M=class{constructor(e){this._hash=Object.create(null),this._cacheId=0,this._renderer=e,e.gc.addResourceHash(this,`_hash`,`resource`),e.gc.addCollection(this,`_hash`,`hash`)}contextChange(e){this._gpu=e,this._cacheId=++pe,this._hash=Object.create(null)}getBindGroup(e,t,n){let r=t._layoutKey<<4|n,i=e._gpuEntry;if(i!==null&&e._gpuEntryLayoutKey===r&&i.gpuBindGroup!==null&&i.cacheId===this._cacheId)return i._gcLastUsed=this._renderer.gc.now,i.gpuBindGroup;let a=e._keyLow,o=e._keyHigh,s=(a^Math.imul(r+1,0x9e3779b1))&0x3fffffff;return i=this._hash[s],i&&i.keyLow===a&&i.keyHigh===o&&i.layoutKey===r?i._gcLastUsed=this._renderer.gc.now:(i=new me(this._createBindGroup(e,t,n),this._renderer.gc.now,a,o,r,this._cacheId),this._hash[s]=i),e._gpuEntry=i,e._gpuEntryLayoutKey=r,i.gpuBindGroup}_createBindGroup(e,t,n){let r=this._gpu.device,i=t.layout[n],a=e.layout,o=[],s=this._renderer;for(let t in i){let n=e.resources[a?a[t]:i[t]];if(!n||n.destroyed)throw Error(`[BindGroup] no usable resource for the shader's '${t}' binding: it was never set, was destroyed while a shader still uses it, or is missing from the bind group's layout.`);let r;if(n._resourceType===`uniformGroup`){let e=n;s.ubo.updateUniformGroup(e);let t=e.buffer;r={buffer:s.buffer.getGPUBuffer(t),offset:0,size:t.descriptor.size}}else if(n._resourceType===`buffer`){let e=n;r={buffer:s.buffer.getGPUBuffer(e),offset:0,size:e.descriptor.size}}else if(n._resourceType===`bufferResource`){let e=n;r={buffer:s.buffer.getGPUBuffer(e.buffer),offset:e.offset,size:e.size}}else if(n._resourceType===`textureSampler`){let e=n;r=s.texture.getGpuSampler(e)}else if(n._resourceType===`textureSource`){let e=n;r=s.texture.getTextureView(e)}else if(n._resourceType===`textureView`){let e=n;r=s.texture.getTextureView(e.source,e.viewDescriptor)}o.push({binding:i[t],resource:r})}let c=s.shader.getProgramData(t).bindGroups[n];return r.createBindGroup({layout:c,entries:o})}destroy(){this._hash=null,this._renderer=null}};M.extension={type:[r.WebGPUSystem],name:`bindGroup`};var he=class{constructor(e){this.gpuBuffer=e}destroy(){this.gpuBuffer.destroy(),this.gpuBuffer=null}},N=class{constructor(e){this._renderer=e,this._managedBuffers=new m({renderer:e,type:`resource`,onUnload:this.onBufferUnload.bind(this),name:`gpuBuffer`})}contextChange(e){this._gpu=e,this.destroyAll()}getGPUBuffer(e){return e._gcLastUsed=this._renderer.gc.now,e._gpuData[this._renderer.uid]?.gpuBuffer||this.createGPUBuffer(e)}updateBuffer(e){let t=this.getGPUBuffer(e),n=e.data;return e._updateID&&n&&(e._updateID=0,this._gpu.device.queue.writeBuffer(t,e._updateOffset,n.buffer,n.byteOffset+e._updateOffset,(e._updateSize||n.byteLength)+3&-4)),t}destroyAll(){this._managedBuffers.removeAll()}onBufferUnload(e){e.off(`update`,this.updateBuffer,this),e.off(`change`,this.onBufferChange,this)}createGPUBuffer(e){let t=this._gpu.device.createBuffer(e.descriptor);return e._updateID=0,e.data&&(f(e.data.buffer,t.getMappedRange(),e.data.byteOffset,e.data.byteLength),t.unmap()),e._gpuData[this._renderer.uid]=new he(t),this._managedBuffers.add(e)&&(e.on(`update`,this.updateBuffer,this),e.on(`change`,this.onBufferChange,this)),t}onBufferChange(e){this._managedBuffers.remove(e),e._updateID=0,this.createGPUBuffer(e)}destroy(){this._managedBuffers.destroy(),this._renderer=null,this._gpu=null}};N.extension={type:[r.WebGPUSystem],name:`buffer`};var ge=class{constructor({minUniformOffsetAlignment:e}){this._minUniformOffsetAlignment=256,this.byteIndex=0,this._minUniformOffsetAlignment=e,this.data=new Float32Array(65535)}clear(){this.byteIndex=0}addEmptyGroup(e){if(e>this._minUniformOffsetAlignment/4)throw Error(`UniformBufferBatch: array is too large: ${e*4}`);let t=this.byteIndex,n=t+e*4;if(n=Math.ceil(n/this._minUniformOffsetAlignment)*this._minUniformOffsetAlignment,n>this.data.length*4)throw Error(`UniformBufferBatch: ubo batch got too big`);return this.byteIndex=n,t}addGroup(e){let t=this.addEmptyGroup(e.length);for(let n=0;n<e.length;n++)this.data[t/4+n]=e[n];return t}destroy(){this.data=null}},P=class{constructor(e){this._colorMaskCache=15,this._renderer=e}setMask(e){this._colorMaskCache!==e&&(this._colorMaskCache=e,this._renderer.pipeline.setColorMask(e))}destroy(){this._renderer=null,this._colorMaskCache=null}};P.extension={type:[r.WebGPUSystem],name:`colorMask`};function _e(e){let{userAgent:t}=C.get().getNavigator();if(!/AppleWebKit\//.test(t)||/Chrome\/|Chromium\//.test(t))return!1;if(!e)return!0;let n=/Version\/([\d.]+)/.exec(t)?.[1];return!n||!(e.from&&F(n,e.from)<0||e.before&&F(n,e.before)>=0)}function F(e,t){let n=e.split(`.`),r=t.split(`.`);for(let e=0;e<Math.max(n.length,r.length);e++){let t=(parseInt(n[e],10)||0)-(parseInt(r[e],10)||0);if(t)return t}return 0}var ve=new Set([`apple`,`arm`,`qualcomm`,`img-tec`]),I=class{constructor(e){this._renderer=e}async init(e){return this._initPromise||=(this._options=e,(e.gpu?Promise.resolve(e.gpu):this._createDeviceAndAdaptor(e)).then(e=>this._setGpu(e))),this._initPromise}_setGpu(e){this.gpu=e,this.extensions={transientAttachment:typeof GPUTextureUsage.TRANSIENT_ATTACHMENT==`number`&&!_e({from:`27.1`,before:`28`}),tileBased:ve.has(e.adapter?.info?.vendor)},this._options.gpu||e.device.lost.then(()=>this._restoreDevice()).catch(e=>h(`WebGPU device was lost and could not be restored`,e)),this._renderer.runners.contextChange.emit(this.gpu)}async _restoreDevice(){if(!this._renderer)return;let e=await this._createDeviceAndAdaptor(this._options);this._renderer?this._setGpu(e):e.device.destroy()}contextChange(e){this._renderer.gpu=e}async _createDeviceAndAdaptor(e){let t=await C.get().getNavigator().gpu.requestAdapter({powerPreference:e.powerPreference,forceFallbackAdapter:e.forceFallbackAdapter});if(!t)throw Error(`WebGPU not supported. No GPU adapter was returned by navigator.gpu.requestAdapter().`);let n=[`texture-compression-bc`,`texture-compression-astc`,`texture-compression-etc2`,`indirect-first-instance`,`bgra8unorm-storage`,`texture-formats-tier1`].filter(e=>t.features.has(e));return{adapter:t,device:await t.requestDevice({requiredFeatures:n,requiredLimits:{maxSampledTexturesPerShaderStage:t.limits.maxSampledTexturesPerShaderStage,maxSamplersPerShaderStage:t.limits.maxSamplersPerShaderStage,minUniformBufferOffsetAlignment:t.limits.minUniformBufferOffsetAlignment}})}}destroy(){this._options?.gpu||this.gpu?.device.destroy(),this.gpu=null,this.extensions=null,this._renderer=null}};I.extension={type:[r.WebGPUSystem],name:`device`},I.defaultOptions={powerPreference:void 0,forceFallbackAdapter:!1};var ye=class{constructor(e,t,n,r){this.gpuBundle=e,this.stateKey=t,this.device=n,this.label=r}},L=class{constructor(e){this._boundBindGroup=Object.create(null),this._boundVertexBuffer=Object.create(null),this._renderer=e;for(let e=0;e<16;e++)this._boundBindGroup[e]={bindGroup:null,program:null,entry:null}}renderStart(){this.commandFinished=new Promise(e=>{this._resolveCommandFinished=e}),this.commandEncoder=this._renderer.gpu.device.createCommandEncoder()}beginRenderPass(e){return this.endRenderPass(),this._clearCache(),this._passEncoder=this.commandEncoder.beginRenderPass(e.descriptor),this.renderPassEncoder=this._passEncoder,this._passEncoder}endRenderPass(){this._passEncoder&&this._passEncoder.end(),this.renderPassEncoder=null,this._passEncoder=null}beginBundle(e){if(this._passEncoder!==this.renderPassEncoder)throw Error(`Cannot begin a new render bundle while one is already being recorded.`);this._clearCache();let t=this._renderer.pipeline,n=t.getBundleDescriptor();n.label=e,this._bundleStateKey=t.bundleStateKey,this._bundleLabel=e,this.renderPassEncoder=this._gpu.device.createRenderBundleEncoder(n)}endBundle(){let e=this.renderPassEncoder;if(!e||!(`finish`in e))throw Error(`endBundle called without an active render bundle.`);let t=e.finish({label:this._bundleLabel});return this.renderPassEncoder=this._passEncoder,this._clearCache(),new ye(t,this._bundleStateKey,this._gpu.device,this._bundleLabel)}isBundleValid(e){return e?.stateKey===this._renderer.pipeline.bundleStateKey&&e.device===this._gpu.device}executeBundle(e){let t=[];if(Array.isArray(e))for(let n=0;n<e.length;n++)t[n]=this._getGpuBundle(e[n]);else t[0]=this._getGpuBundle(e);this._clearCache(),this._passEncoder.executeBundles(t)}_getGpuBundle(e){return this.isBundleValid(e)||h(`Render bundle ${e?.label??`(unlabeled)`} was recorded against a different render target state or on a lost device. Re-record it \u2014 replaying it will either be rejected by WebGPU or draw with the wrong winding. Check encoder.isBundleValid(bundle) before executing.`),e.gpuBundle}setViewport(e){this._passEncoder.setViewport(e.x,e.y,e.width,e.height,0,1)}setStencilReference(e){this._passEncoder.setStencilReference(e)}setPipelineFromGeometryProgramAndState(e,t,n,r,i){let a=this._renderer.pipeline.getPipeline(e,t,n,r,i);this.setPipeline(a)}setPipeline(e){this._boundPipeline!==e&&(this._boundPipeline=e,this.renderPassEncoder.setPipeline(e))}_setVertexBuffer(e,t){this._boundVertexBuffer[e]!==t&&(this._boundVertexBuffer[e]=t,this.renderPassEncoder.setVertexBuffer(e,this._renderer.buffer.updateBuffer(t)))}_setIndexBuffer(e){if(this._boundIndexBuffer===e)return;this._boundIndexBuffer=e;let t=e.data.BYTES_PER_ELEMENT===2?`uint16`:`uint32`;this.renderPassEncoder.setIndexBuffer(this._renderer.buffer.updateBuffer(e),t)}resetBindGroup(e){let t=this._boundBindGroup[e];t.bindGroup=null,t.program=null,t.entry=null}setBindGroup(e,t,n){let r=this._boundBindGroup[e];if(r.bindGroup===t&&r.program===n&&r.entry===t._gpuEntry)return;r.bindGroup=t,r.program=n,t._touch(this._renderer.gc.now);let i=this._renderer.bindGroup.getBindGroup(t,n,e);r.entry=t._gpuEntry,this.renderPassEncoder.setBindGroup(e,i)}setGeometry(e,t){let n=this._renderer.pipeline.getBufferNamesToBind(e,t);for(let t=0;t<n.length;t++)this._setVertexBuffer(t,e.attributes[n[t]].buffer);e.indexBuffer&&this._setIndexBuffer(e.indexBuffer)}_setShaderBindGroups(e,t){let n=e.gpuProgram,r=n.layout;for(let i=0;i<r.length;i++){let a=e.groups[i];r[i]&&a&&(t||this._syncBindGroup(a),this.setBindGroup(i,a,n))}}_syncBindGroup(e){let t=e.resources,n=e._resourceKeys;for(let e=0;e<n.length;e++){let r=t[n[e]];r&&r.isUniformGroup&&this._renderer.ubo.updateUniformGroup(r)}}draw(e){let{geometry:t,shader:n,state:r,topology:i,size:a,start:o,baseVertex:s,instanceCount:c,skipSync:l,firstInstance:u}=e;this.setPipelineFromGeometryProgramAndState(t,n.gpuProgram,r,i,n._overrides),this.setGeometry(t,n.gpuProgram),this._setShaderBindGroups(n,l),t.indexBuffer?this.renderPassEncoder.drawIndexed(a||t.indexCount||t.indexBuffer.data.length,c??t.instanceCount,o||0,s||0,u||0):this.renderPassEncoder.draw(a||t.vertexCount,c??t.instanceCount,o||0,u||0)}drawIndirect(e){let{geometry:t,shader:n,state:r,topology:i,skipSync:a,indirectBuffer:o,indirectOffset:s}=e;this.setPipelineFromGeometryProgramAndState(t,n.gpuProgram,r,i,n._overrides),this.setGeometry(t,n.gpuProgram),this._setShaderBindGroups(n,a),t.indexBuffer?this.renderPassEncoder.drawIndexedIndirect(o,s):this.renderPassEncoder.drawIndirect(o,s)}finishRenderPass(){this._passEncoder&&=(this._passEncoder.end(),this.renderPassEncoder=null,null)}postrender(){this.finishRenderPass(),this._gpu.device.queue.submit([this.commandEncoder.finish()]),this._resolveCommandFinished(),this.commandEncoder=null}_clearCache(){for(let e=0;e<16;e++){let t=this._boundBindGroup[e];t.bindGroup=null,t.program=null,t.entry=null,this._boundVertexBuffer[e]=null}this._boundIndexBuffer=null,this._boundPipeline=null}destroy(){this._renderer=null,this._gpu=null,this._boundBindGroup=null,this._boundVertexBuffer=null,this._boundIndexBuffer=null,this._boundPipeline=null,this.renderPassEncoder=null,this._passEncoder=null}contextChange(e){this._gpu=e}};L.extension={type:[r.WebGPUSystem],name:`encoder`,priority:1};var R=class{constructor(e){this.supportsOverrideConstants=!1,this._renderer=e}contextChange(){let e=this._renderer.device.gpu.device;this.maxTextures=Math.min(e.limits.maxSampledTexturesPerShaderStage,e.limits.maxSamplersPerShaderStage),this.maxBatchableTextures=this.maxTextures,this.minUniformBufferOffsetAlignment=e.limits.minUniformBufferOffsetAlignment,this._detectOverrideConstantsSupport(e)}_detectOverrideConstantsSupport(e){e.pushErrorScope(`validation`);let t=e.createShaderModule({code:`override TEST_VALUE: f32 = 0.0;
2
2
  @compute @workgroup_size(1) fn main() {}`});e.createComputePipeline({layout:`auto`,compute:{module:t,entryPoint:`main`,constants:{TEST_VALUE:1}}}),e.popErrorScope().then(e=>{this.supportsOverrideConstants=!e})}destroy(){}};R.extension={type:[r.WebGPUSystem],name:`limits`};var z=class{constructor(e){this._renderer=e,e.renderTarget.onRenderTargetChange.add(this)}contextChange(){this._activeGpuRenderTarget=null}onRenderTargetChange(e){let t=this._renderer.renderTarget.getGpuRenderTarget(e);this._activeRenderTarget=e,this._activeGpuRenderTarget=t,this.setStencilMode(t.stencilMode,t.stencilReference)}setStencilMode(e,t){let n=this._activeGpuRenderTarget??=this._renderer.renderTarget.getGpuRenderTarget(this._activeRenderTarget);n.stencilMode=e,n.stencilReference=t;let r=this._renderer;r.pipeline.setStencilMode(e),r.encoder.setStencilReference(t)}destroy(){this._renderer.renderTarget.onRenderTargetChange.remove(this),this._renderer=null,this._activeRenderTarget=null,this._activeGpuRenderTarget=null}};z.extension={type:[r.WebGPUSystem],name:`stencil`};var B={i32:{align:4,size:4},u32:{align:4,size:4},f32:{align:4,size:4},f16:{align:2,size:2},"vec2<i32>":{align:8,size:8},"vec2<u32>":{align:8,size:8},"vec2<f32>":{align:8,size:8},"vec2<f16>":{align:4,size:4},"vec3<i32>":{align:16,size:12},"vec3<u32>":{align:16,size:12},"vec3<f32>":{align:16,size:12},"vec3<f16>":{align:8,size:6},"vec4<i32>":{align:16,size:16},"vec4<u32>":{align:16,size:16},"vec4<f32>":{align:16,size:16},"vec4<f16>":{align:8,size:8},"mat2x2<f32>":{align:8,size:16},"mat2x2<f16>":{align:4,size:8},"mat3x2<f32>":{align:8,size:24},"mat3x2<f16>":{align:4,size:12},"mat4x2<f32>":{align:8,size:32},"mat4x2<f16>":{align:4,size:16},"mat2x3<f32>":{align:16,size:32},"mat2x3<f16>":{align:8,size:16},"mat3x3<f32>":{align:16,size:48},"mat3x3<f16>":{align:8,size:24},"mat4x3<f32>":{align:16,size:64},"mat4x3<f16>":{align:8,size:32},"mat2x4<f32>":{align:16,size:32},"mat2x4<f16>":{align:8,size:16},"mat3x4<f32>":{align:16,size:48},"mat3x4<f16>":{align:8,size:24},"mat4x4<f32>":{align:16,size:64},"mat4x4<f16>":{align:8,size:32}};function be(e){let t=e.map(e=>({data:e,offset:0,size:0})),n=0;for(let e=0;e<t.length;e++){let r=t[e],i=B[r.data.type].size,a=B[r.data.type].align;if(!B[r.data.type])throw Error(`[Pixi.js] WebGPU UniformBuffer: Unknown type ${r.data.type}`);r.data.size>1&&(i=Math.max(i,a)*r.data.size),n=Math.ceil(n/a)*a,r.size=i,r.offset=n,n+=i}return n=Math.ceil(n/16)*16,{uboElements:t,size:n}}function xe(e,t){let{size:n,align:r}=B[e.data.type],i=(Math.max(n,r)-n)/4,a=e.data.type.indexOf(`i32`)>=0?`dataInt32`:`data`;return`
3
3
  v = uv.${e.data.name};
4
4
  ${t===0?``:`offset += ${t};`}