@micjanic/recursive-grid 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2690 @@
1
+ import { F as Ge, u as De, l as se, M as v, G as Ee, v as Oe, S as Fe, x as ae, E as u, e as E, y as S, z as Le, H as O, I as b, R as F, J as ne, K as He, t as m, b as f, i as B, w as L, L as Y, N as ze, c as J, B as k, j as U, O as M, k as T, Q as w, V as We, a as Ve, W as ie, X as oe, Y as le, Z as ue, C as P, _ as Ne, $ as A, D as H, a0 as je, P as $e, d as qe, T as X, a1 as Q, a2 as Ke, a3 as Ye, a4 as Je } from "./PixiApp-D4xu0PT4.js";
2
+ import { B as de, c as Xe } from "./colorToUniform-C2jGzNe1.js";
3
+ var Qe = `in vec2 vMaskCoord;
4
+ in vec2 vTextureCoord;
5
+
6
+ uniform sampler2D uTexture;
7
+ uniform sampler2D uMaskTexture;
8
+
9
+ uniform float uAlpha;
10
+ uniform vec4 uMaskClamp;
11
+ uniform float uInverse;
12
+
13
+ out vec4 finalColor;
14
+
15
+ void main(void)
16
+ {
17
+ float clip = step(3.5,
18
+ step(uMaskClamp.x, vMaskCoord.x) +
19
+ step(uMaskClamp.y, vMaskCoord.y) +
20
+ step(vMaskCoord.x, uMaskClamp.z) +
21
+ step(vMaskCoord.y, uMaskClamp.w));
22
+
23
+ // TODO look into why this is needed
24
+ float npmAlpha = uAlpha;
25
+ vec4 original = texture(uTexture, vTextureCoord);
26
+ vec4 masky = texture(uMaskTexture, vMaskCoord);
27
+ float alphaMul = 1.0 - npmAlpha * (1.0 - masky.a);
28
+
29
+ float a = alphaMul * masky.r * npmAlpha * clip;
30
+
31
+ if (uInverse == 1.0) {
32
+ a = 1.0 - a;
33
+ }
34
+
35
+ finalColor = original * a;
36
+ }
37
+ `, Ze = `in vec2 aPosition;
38
+
39
+ out vec2 vTextureCoord;
40
+ out vec2 vMaskCoord;
41
+
42
+
43
+ uniform vec4 uInputSize;
44
+ uniform vec4 uOutputFrame;
45
+ uniform vec4 uOutputTexture;
46
+ uniform mat3 uFilterMatrix;
47
+
48
+ vec4 filterVertexPosition( vec2 aPosition )
49
+ {
50
+ vec2 position = aPosition * uOutputFrame.zw + uOutputFrame.xy;
51
+
52
+ position.x = position.x * (2.0 / uOutputTexture.x) - 1.0;
53
+ position.y = position.y * (2.0*uOutputTexture.z / uOutputTexture.y) - uOutputTexture.z;
54
+
55
+ return vec4(position, 0.0, 1.0);
56
+ }
57
+
58
+ vec2 filterTextureCoord( vec2 aPosition )
59
+ {
60
+ return aPosition * (uOutputFrame.zw * uInputSize.zw);
61
+ }
62
+
63
+ vec2 getFilterCoord( vec2 aPosition )
64
+ {
65
+ return ( uFilterMatrix * vec3( filterTextureCoord(aPosition), 1.0) ).xy;
66
+ }
67
+
68
+ void main(void)
69
+ {
70
+ gl_Position = filterVertexPosition(aPosition);
71
+ vTextureCoord = filterTextureCoord(aPosition);
72
+ vMaskCoord = getFilterCoord(aPosition);
73
+ }
74
+ `, Z = `struct GlobalFilterUniforms {
75
+ uInputSize:vec4<f32>,
76
+ uInputPixel:vec4<f32>,
77
+ uInputClamp:vec4<f32>,
78
+ uOutputFrame:vec4<f32>,
79
+ uGlobalFrame:vec4<f32>,
80
+ uOutputTexture:vec4<f32>,
81
+ };
82
+
83
+ struct MaskUniforms {
84
+ uFilterMatrix:mat3x3<f32>,
85
+ uMaskClamp:vec4<f32>,
86
+ uAlpha:f32,
87
+ uInverse:f32,
88
+ };
89
+
90
+ @group(0) @binding(0) var<uniform> gfu: GlobalFilterUniforms;
91
+ @group(0) @binding(1) var uTexture: texture_2d<f32>;
92
+ @group(0) @binding(2) var uSampler : sampler;
93
+
94
+ @group(1) @binding(0) var<uniform> filterUniforms : MaskUniforms;
95
+ @group(1) @binding(1) var uMaskTexture: texture_2d<f32>;
96
+
97
+ struct VSOutput {
98
+ @builtin(position) position: vec4<f32>,
99
+ @location(0) uv : vec2<f32>,
100
+ @location(1) filterUv : vec2<f32>,
101
+ };
102
+
103
+ fn filterVertexPosition(aPosition:vec2<f32>) -> vec4<f32>
104
+ {
105
+ var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;
106
+
107
+ position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;
108
+ position.y = position.y * (2.0*gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;
109
+
110
+ return vec4(position, 0.0, 1.0);
111
+ }
112
+
113
+ fn filterTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
114
+ {
115
+ return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);
116
+ }
117
+
118
+ fn globalTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
119
+ {
120
+ return (aPosition.xy / gfu.uGlobalFrame.zw) + (gfu.uGlobalFrame.xy / gfu.uGlobalFrame.zw);
121
+ }
122
+
123
+ fn getFilterCoord(aPosition:vec2<f32> ) -> vec2<f32>
124
+ {
125
+ return ( filterUniforms.uFilterMatrix * vec3( filterTextureCoord(aPosition), 1.0) ).xy;
126
+ }
127
+
128
+ fn getSize() -> vec2<f32>
129
+ {
130
+ return gfu.uGlobalFrame.zw;
131
+ }
132
+
133
+ @vertex
134
+ fn mainVertex(
135
+ @location(0) aPosition : vec2<f32>,
136
+ ) -> VSOutput {
137
+ return VSOutput(
138
+ filterVertexPosition(aPosition),
139
+ filterTextureCoord(aPosition),
140
+ getFilterCoord(aPosition)
141
+ );
142
+ }
143
+
144
+ @fragment
145
+ fn mainFragment(
146
+ @location(0) uv: vec2<f32>,
147
+ @location(1) filterUv: vec2<f32>,
148
+ @builtin(position) position: vec4<f32>
149
+ ) -> @location(0) vec4<f32> {
150
+
151
+ var maskClamp = filterUniforms.uMaskClamp;
152
+ var uAlpha = filterUniforms.uAlpha;
153
+
154
+ var clip = step(3.5,
155
+ step(maskClamp.x, filterUv.x) +
156
+ step(maskClamp.y, filterUv.y) +
157
+ step(filterUv.x, maskClamp.z) +
158
+ step(filterUv.y, maskClamp.w));
159
+
160
+ var mask = textureSample(uMaskTexture, uSampler, filterUv);
161
+ var source = textureSample(uTexture, uSampler, uv);
162
+ var alphaMul = 1.0 - uAlpha * (1.0 - mask.a);
163
+
164
+ var a: f32 = alphaMul * mask.r * uAlpha * clip;
165
+
166
+ if (filterUniforms.uInverse == 1.0) {
167
+ a = 1.0 - a;
168
+ }
169
+
170
+ return source * a;
171
+ }
172
+ `;
173
+ class et extends Ge {
174
+ constructor(e) {
175
+ const { sprite: t, ...r } = e, s = new De(t.texture), n = new se({
176
+ uFilterMatrix: { value: new v(), type: "mat3x3<f32>" },
177
+ uMaskClamp: { value: s.uClampFrame, type: "vec4<f32>" },
178
+ uAlpha: { value: 1, type: "f32" },
179
+ uInverse: { value: e.inverse ? 1 : 0, type: "f32" }
180
+ }), i = Ee.from({
181
+ vertex: {
182
+ source: Z,
183
+ entryPoint: "mainVertex"
184
+ },
185
+ fragment: {
186
+ source: Z,
187
+ entryPoint: "mainFragment"
188
+ }
189
+ }), o = Oe.from({
190
+ vertex: Ze,
191
+ fragment: Qe,
192
+ name: "mask-filter"
193
+ });
194
+ super({
195
+ ...r,
196
+ gpuProgram: i,
197
+ glProgram: o,
198
+ clipToViewport: !1,
199
+ resources: {
200
+ filterUniforms: n,
201
+ uMaskTexture: t.texture.source
202
+ }
203
+ }), this.sprite = t, this._textureMatrix = s;
204
+ }
205
+ set inverse(e) {
206
+ this.resources.filterUniforms.uniforms.uInverse = e ? 1 : 0;
207
+ }
208
+ get inverse() {
209
+ return this.resources.filterUniforms.uniforms.uInverse === 1;
210
+ }
211
+ apply(e, t, r, s) {
212
+ this._textureMatrix.texture = this.sprite.texture, e.calculateSpriteMatrix(
213
+ this.resources.filterUniforms.uniforms.uFilterMatrix,
214
+ this.sprite
215
+ ).prepend(this._textureMatrix.mapCoord), this.resources.uMaskTexture = this.sprite.texture.source, e.applyFilter(this, t, r, s);
216
+ }
217
+ }
218
+ const z = class ce {
219
+ constructor(e, t) {
220
+ var r, s;
221
+ this.state = Fe.for2d(), this._batchersByInstructionSet = /* @__PURE__ */ Object.create(null), this._activeBatches = /* @__PURE__ */ Object.create(null), this.renderer = e, this._adaptor = t, (s = (r = this._adaptor).init) == null || s.call(r, this);
222
+ }
223
+ static getBatcher(e) {
224
+ return new this._availableBatchers[e]();
225
+ }
226
+ buildStart(e) {
227
+ let t = this._batchersByInstructionSet[e.uid];
228
+ t || (t = this._batchersByInstructionSet[e.uid] = /* @__PURE__ */ Object.create(null), t.default || (t.default = new ae({
229
+ maxTextures: this.renderer.limits.maxBatchableTextures
230
+ }))), this._activeBatches = t, this._activeBatch = this._activeBatches.default;
231
+ for (const r in this._activeBatches)
232
+ this._activeBatches[r].begin();
233
+ }
234
+ addToBatch(e, t) {
235
+ if (this._activeBatch.name !== e.batcherName) {
236
+ this._activeBatch.break(t);
237
+ let r = this._activeBatches[e.batcherName];
238
+ r || (r = this._activeBatches[e.batcherName] = ce.getBatcher(e.batcherName), r.begin()), this._activeBatch = r;
239
+ }
240
+ this._activeBatch.add(e);
241
+ }
242
+ break(e) {
243
+ this._activeBatch.break(e);
244
+ }
245
+ buildEnd(e) {
246
+ this._activeBatch.break(e);
247
+ const t = this._activeBatches;
248
+ for (const r in t) {
249
+ const s = t[r], n = s.geometry;
250
+ n.indexBuffer.setDataWithSize(s.indexBuffer, s.indexSize, !0), n.buffers[0].setDataWithSize(s.attributeBuffer.float32View, s.attributeSize, !1);
251
+ }
252
+ }
253
+ upload(e) {
254
+ const t = this._batchersByInstructionSet[e.uid];
255
+ for (const r in t) {
256
+ const s = t[r], n = s.geometry;
257
+ s.dirty && (s.dirty = !1, n.buffers[0].update(s.attributeSize * 4));
258
+ }
259
+ }
260
+ execute(e) {
261
+ if (e.action === "startBatch") {
262
+ const t = e.batcher, r = t.geometry, s = t.shader;
263
+ this._adaptor.start(this, r, s);
264
+ }
265
+ this._adaptor.execute(this, e);
266
+ }
267
+ destroy() {
268
+ this.state = null, this.renderer = null, this._adaptor = null;
269
+ for (const e in this._activeBatches)
270
+ this._activeBatches[e].destroy();
271
+ this._activeBatches = null;
272
+ }
273
+ };
274
+ z.extension = {
275
+ type: [
276
+ u.WebGLPipes,
277
+ u.WebGPUPipes,
278
+ u.CanvasPipes
279
+ ],
280
+ name: "batch"
281
+ };
282
+ z._availableBatchers = /* @__PURE__ */ Object.create(null);
283
+ let he = z;
284
+ E.handleByMap(u.Batcher, he._availableBatchers);
285
+ E.add(ae);
286
+ const Pt = {
287
+ name: "texture-bit",
288
+ vertex: {
289
+ header: (
290
+ /* wgsl */
291
+ `
292
+
293
+ struct TextureUniforms {
294
+ uTextureMatrix:mat3x3<f32>,
295
+ }
296
+
297
+ @group(2) @binding(2) var<uniform> textureUniforms : TextureUniforms;
298
+ `
299
+ ),
300
+ main: (
301
+ /* wgsl */
302
+ `
303
+ uv = (textureUniforms.uTextureMatrix * vec3(uv, 1.0)).xy;
304
+ `
305
+ )
306
+ },
307
+ fragment: {
308
+ header: (
309
+ /* wgsl */
310
+ `
311
+ @group(2) @binding(0) var uTexture: texture_2d<f32>;
312
+ @group(2) @binding(1) var uSampler: sampler;
313
+
314
+
315
+ `
316
+ ),
317
+ main: (
318
+ /* wgsl */
319
+ `
320
+ outColor = textureSample(uTexture, uSampler, vUV);
321
+ `
322
+ )
323
+ }
324
+ }, Rt = {
325
+ name: "texture-bit",
326
+ vertex: {
327
+ header: (
328
+ /* glsl */
329
+ `
330
+ uniform mat3 uTextureMatrix;
331
+ `
332
+ ),
333
+ main: (
334
+ /* glsl */
335
+ `
336
+ uv = (uTextureMatrix * vec3(uv, 1.0)).xy;
337
+ `
338
+ )
339
+ },
340
+ fragment: {
341
+ header: (
342
+ /* glsl */
343
+ `
344
+ uniform sampler2D uTexture;
345
+
346
+
347
+ `
348
+ ),
349
+ main: (
350
+ /* glsl */
351
+ `
352
+ outColor = texture(uTexture, vUV);
353
+ `
354
+ )
355
+ }
356
+ }, tt = new O();
357
+ class rt extends ne {
358
+ constructor() {
359
+ super(), this.filters = [new et({
360
+ sprite: new He(m.EMPTY),
361
+ inverse: !1,
362
+ resolution: "inherit",
363
+ antialias: "inherit"
364
+ })];
365
+ }
366
+ get sprite() {
367
+ return this.filters[0].sprite;
368
+ }
369
+ set sprite(e) {
370
+ this.filters[0].sprite = e;
371
+ }
372
+ get inverse() {
373
+ return this.filters[0].inverse;
374
+ }
375
+ set inverse(e) {
376
+ this.filters[0].inverse = e;
377
+ }
378
+ }
379
+ class fe {
380
+ constructor(e) {
381
+ this._activeMaskStage = [], this._renderer = e;
382
+ }
383
+ push(e, t, r) {
384
+ const s = this._renderer;
385
+ if (s.renderPipes.batch.break(r), r.add({
386
+ renderPipeId: "alphaMask",
387
+ action: "pushMaskBegin",
388
+ mask: e,
389
+ inverse: t._maskOptions.inverse,
390
+ canBundle: !1,
391
+ maskedContainer: t
392
+ }), e.inverse = t._maskOptions.inverse, e.renderMaskToTexture) {
393
+ const n = e.mask;
394
+ n.includeInBuild = !0, n.collectRenderables(
395
+ r,
396
+ s,
397
+ null
398
+ ), n.includeInBuild = !1;
399
+ }
400
+ s.renderPipes.batch.break(r), r.add({
401
+ renderPipeId: "alphaMask",
402
+ action: "pushMaskEnd",
403
+ mask: e,
404
+ maskedContainer: t,
405
+ inverse: t._maskOptions.inverse,
406
+ canBundle: !1
407
+ });
408
+ }
409
+ pop(e, t, r) {
410
+ this._renderer.renderPipes.batch.break(r), r.add({
411
+ renderPipeId: "alphaMask",
412
+ action: "popMaskEnd",
413
+ mask: e,
414
+ inverse: t._maskOptions.inverse,
415
+ canBundle: !1
416
+ });
417
+ }
418
+ execute(e) {
419
+ const t = this._renderer, r = e.mask.renderMaskToTexture;
420
+ if (e.action === "pushMaskBegin") {
421
+ const s = S.get(rt);
422
+ if (s.inverse = e.inverse, r) {
423
+ e.mask.mask.measurable = !0;
424
+ const n = Le(e.mask.mask, !0, tt);
425
+ e.mask.mask.measurable = !1, n.ceil();
426
+ const i = t.renderTarget.renderTarget.colorTexture.source, o = b.getOptimalTexture(
427
+ n.width,
428
+ n.height,
429
+ i._resolution,
430
+ i.antialias
431
+ );
432
+ t.renderTarget.push(o, !0), t.globalUniforms.push({
433
+ offset: n,
434
+ worldColor: 4294967295
435
+ });
436
+ const l = s.sprite;
437
+ l.texture = o, l.worldTransform.tx = n.minX, l.worldTransform.ty = n.minY, this._activeMaskStage.push({
438
+ filterEffect: s,
439
+ maskedContainer: e.maskedContainer,
440
+ filterTexture: o
441
+ });
442
+ } else
443
+ s.sprite = e.mask.mask, this._activeMaskStage.push({
444
+ filterEffect: s,
445
+ maskedContainer: e.maskedContainer
446
+ });
447
+ } else if (e.action === "pushMaskEnd") {
448
+ const s = this._activeMaskStage[this._activeMaskStage.length - 1];
449
+ r && (t.type === F.WEBGL && t.renderTarget.finishRenderPass(), t.renderTarget.pop(), t.globalUniforms.pop()), t.filter.push({
450
+ renderPipeId: "filter",
451
+ action: "pushFilter",
452
+ container: s.maskedContainer,
453
+ filterEffect: s.filterEffect,
454
+ canBundle: !1
455
+ });
456
+ } else if (e.action === "popMaskEnd") {
457
+ t.filter.pop();
458
+ const s = this._activeMaskStage.pop();
459
+ r && b.returnTexture(s.filterTexture), S.return(s.filterEffect);
460
+ }
461
+ }
462
+ destroy() {
463
+ this._renderer = null, this._activeMaskStage = null;
464
+ }
465
+ }
466
+ fe.extension = {
467
+ type: [
468
+ u.WebGLPipes,
469
+ u.WebGPUPipes,
470
+ u.CanvasPipes
471
+ ],
472
+ name: "alphaMask"
473
+ };
474
+ class pe {
475
+ constructor(e) {
476
+ this._colorStack = [], this._colorStackIndex = 0, this._currentColor = 0, this._renderer = e;
477
+ }
478
+ buildStart() {
479
+ this._colorStack[0] = 15, this._colorStackIndex = 1, this._currentColor = 15;
480
+ }
481
+ push(e, t, r) {
482
+ this._renderer.renderPipes.batch.break(r);
483
+ const n = this._colorStack;
484
+ n[this._colorStackIndex] = n[this._colorStackIndex - 1] & e.mask;
485
+ const i = this._colorStack[this._colorStackIndex];
486
+ i !== this._currentColor && (this._currentColor = i, r.add({
487
+ renderPipeId: "colorMask",
488
+ colorMask: i,
489
+ canBundle: !1
490
+ })), this._colorStackIndex++;
491
+ }
492
+ pop(e, t, r) {
493
+ this._renderer.renderPipes.batch.break(r);
494
+ const n = this._colorStack;
495
+ this._colorStackIndex--;
496
+ const i = n[this._colorStackIndex - 1];
497
+ i !== this._currentColor && (this._currentColor = i, r.add({
498
+ renderPipeId: "colorMask",
499
+ colorMask: i,
500
+ canBundle: !1
501
+ }));
502
+ }
503
+ execute(e) {
504
+ this._renderer.colorMask.setMask(e.colorMask);
505
+ }
506
+ destroy() {
507
+ this._colorStack = null;
508
+ }
509
+ }
510
+ pe.extension = {
511
+ type: [
512
+ u.WebGLPipes,
513
+ u.WebGPUPipes,
514
+ u.CanvasPipes
515
+ ],
516
+ name: "colorMask"
517
+ };
518
+ class me {
519
+ constructor(e) {
520
+ this._maskStackHash = {}, this._maskHash = /* @__PURE__ */ new WeakMap(), this._renderer = e;
521
+ }
522
+ push(e, t, r) {
523
+ var s;
524
+ const n = e, i = this._renderer;
525
+ i.renderPipes.batch.break(r), i.renderPipes.blendMode.setBlendMode(n.mask, "none", r), r.add({
526
+ renderPipeId: "stencilMask",
527
+ action: "pushMaskBegin",
528
+ mask: e,
529
+ inverse: t._maskOptions.inverse,
530
+ canBundle: !1
531
+ });
532
+ const o = n.mask;
533
+ o.includeInBuild = !0, this._maskHash.has(n) || this._maskHash.set(n, {
534
+ instructionsStart: 0,
535
+ instructionsLength: 0
536
+ });
537
+ const l = this._maskHash.get(n);
538
+ l.instructionsStart = r.instructionSize, o.collectRenderables(
539
+ r,
540
+ i,
541
+ null
542
+ ), o.includeInBuild = !1, i.renderPipes.batch.break(r), r.add({
543
+ renderPipeId: "stencilMask",
544
+ action: "pushMaskEnd",
545
+ mask: e,
546
+ inverse: t._maskOptions.inverse,
547
+ canBundle: !1
548
+ });
549
+ const d = r.instructionSize - l.instructionsStart - 1;
550
+ l.instructionsLength = d;
551
+ const c = i.renderTarget.renderTarget.uid;
552
+ (s = this._maskStackHash)[c] ?? (s[c] = 0);
553
+ }
554
+ pop(e, t, r) {
555
+ const s = e, n = this._renderer;
556
+ n.renderPipes.batch.break(r), n.renderPipes.blendMode.setBlendMode(s.mask, "none", r), r.add({
557
+ renderPipeId: "stencilMask",
558
+ action: "popMaskBegin",
559
+ inverse: t._maskOptions.inverse,
560
+ canBundle: !1
561
+ });
562
+ const i = this._maskHash.get(e);
563
+ for (let o = 0; o < i.instructionsLength; o++)
564
+ r.instructions[r.instructionSize++] = r.instructions[i.instructionsStart++];
565
+ r.add({
566
+ renderPipeId: "stencilMask",
567
+ action: "popMaskEnd",
568
+ canBundle: !1
569
+ });
570
+ }
571
+ execute(e) {
572
+ var t;
573
+ const r = this._renderer, s = r.renderTarget.renderTarget.uid;
574
+ let n = (t = this._maskStackHash)[s] ?? (t[s] = 0);
575
+ e.action === "pushMaskBegin" ? (r.renderTarget.ensureDepthStencil(), r.stencil.setStencilMode(f.RENDERING_MASK_ADD, n), n++, r.colorMask.setMask(0)) : e.action === "pushMaskEnd" ? (e.inverse ? r.stencil.setStencilMode(f.INVERSE_MASK_ACTIVE, n) : r.stencil.setStencilMode(f.MASK_ACTIVE, n), r.colorMask.setMask(15)) : e.action === "popMaskBegin" ? (r.colorMask.setMask(0), n !== 0 ? r.stencil.setStencilMode(f.RENDERING_MASK_REMOVE, n) : (r.renderTarget.clear(null, B.STENCIL), r.stencil.setStencilMode(f.DISABLED, n)), n--) : e.action === "popMaskEnd" && (e.inverse ? r.stencil.setStencilMode(f.INVERSE_MASK_ACTIVE, n) : r.stencil.setStencilMode(f.MASK_ACTIVE, n), r.colorMask.setMask(15)), this._maskStackHash[s] = n;
576
+ }
577
+ destroy() {
578
+ this._renderer = null, this._maskStackHash = null, this._maskHash = null;
579
+ }
580
+ }
581
+ me.extension = {
582
+ type: [
583
+ u.WebGLPipes,
584
+ u.WebGPUPipes,
585
+ u.CanvasPipes
586
+ ],
587
+ name: "stencilMask"
588
+ };
589
+ function Bt(a, e) {
590
+ for (const t in a.attributes) {
591
+ const r = a.attributes[t], s = e[t];
592
+ s ? (r.format ?? (r.format = s.format), r.offset ?? (r.offset = s.offset), r.instance ?? (r.instance = s.instance)) : L(`Attribute ${t} is not present in the shader, but is present in the geometry. Unable to infer attribute details.`);
593
+ }
594
+ st(a);
595
+ }
596
+ function st(a) {
597
+ const { buffers: e, attributes: t } = a, r = {}, s = {};
598
+ for (const n in e) {
599
+ const i = e[n];
600
+ r[i.uid] = 0, s[i.uid] = 0;
601
+ }
602
+ for (const n in t) {
603
+ const i = t[n];
604
+ r[i.buffer.uid] += Y(i.format).stride;
605
+ }
606
+ for (const n in t) {
607
+ const i = t[n];
608
+ i.stride ?? (i.stride = r[i.buffer.uid]), i.start ?? (i.start = s[i.buffer.uid]), s[i.buffer.uid] += Y(i.format).stride;
609
+ }
610
+ }
611
+ const g = [];
612
+ g[f.NONE] = void 0;
613
+ g[f.DISABLED] = {
614
+ stencilWriteMask: 0,
615
+ stencilReadMask: 0
616
+ };
617
+ g[f.RENDERING_MASK_ADD] = {
618
+ stencilFront: {
619
+ compare: "equal",
620
+ passOp: "increment-clamp"
621
+ },
622
+ stencilBack: {
623
+ compare: "equal",
624
+ passOp: "increment-clamp"
625
+ }
626
+ };
627
+ g[f.RENDERING_MASK_REMOVE] = {
628
+ stencilFront: {
629
+ compare: "equal",
630
+ passOp: "decrement-clamp"
631
+ },
632
+ stencilBack: {
633
+ compare: "equal",
634
+ passOp: "decrement-clamp"
635
+ }
636
+ };
637
+ g[f.MASK_ACTIVE] = {
638
+ stencilWriteMask: 0,
639
+ stencilFront: {
640
+ compare: "equal",
641
+ passOp: "keep"
642
+ },
643
+ stencilBack: {
644
+ compare: "equal",
645
+ passOp: "keep"
646
+ }
647
+ };
648
+ g[f.INVERSE_MASK_ACTIVE] = {
649
+ stencilWriteMask: 0,
650
+ stencilFront: {
651
+ compare: "not-equal",
652
+ passOp: "keep"
653
+ },
654
+ stencilBack: {
655
+ compare: "not-equal",
656
+ passOp: "keep"
657
+ }
658
+ };
659
+ class Ut {
660
+ constructor(e) {
661
+ this._syncFunctionHash = /* @__PURE__ */ Object.create(null), this._adaptor = e, this._systemCheck();
662
+ }
663
+ /**
664
+ * Overridable function by `pixi.js/unsafe-eval` to silence
665
+ * throwing an error if platform doesn't support unsafe-evals.
666
+ * @private
667
+ */
668
+ _systemCheck() {
669
+ if (!ze())
670
+ throw new Error("Current environment does not allow unsafe-eval, please use pixi.js/unsafe-eval module to enable support.");
671
+ }
672
+ ensureUniformGroup(e) {
673
+ const t = this.getUniformGroupData(e);
674
+ e.buffer || (e.buffer = new J({
675
+ data: new Float32Array(t.layout.size / 4),
676
+ usage: k.UNIFORM | k.COPY_DST
677
+ }));
678
+ }
679
+ getUniformGroupData(e) {
680
+ return this._syncFunctionHash[e._signature] || this._initUniformGroup(e);
681
+ }
682
+ _initUniformGroup(e) {
683
+ const t = e._signature;
684
+ let r = this._syncFunctionHash[t];
685
+ if (!r) {
686
+ const s = Object.keys(e.uniformStructures).map((o) => e.uniformStructures[o]), n = this._adaptor.createUboElements(s), i = this._generateUboSync(n.uboElements);
687
+ r = this._syncFunctionHash[t] = {
688
+ layout: n,
689
+ syncFunction: i
690
+ };
691
+ }
692
+ return this._syncFunctionHash[t];
693
+ }
694
+ _generateUboSync(e) {
695
+ return this._adaptor.generateUboSync(e);
696
+ }
697
+ syncUniformGroup(e, t, r) {
698
+ const s = this.getUniformGroupData(e);
699
+ e.buffer || (e.buffer = new J({
700
+ data: new Float32Array(s.layout.size / 4),
701
+ usage: k.UNIFORM | k.COPY_DST
702
+ }));
703
+ let n = null;
704
+ return t || (t = e.buffer.data, n = e.buffer.dataInt32), r || (r = 0), s.syncFunction(e.uniforms, t, n, r), !0;
705
+ }
706
+ updateUniformGroup(e) {
707
+ if (e.isStatic && !e._dirtyId)
708
+ return !1;
709
+ e._dirtyId = 0;
710
+ const t = this.syncUniformGroup(e);
711
+ return e.buffer.update(), t;
712
+ }
713
+ destroy() {
714
+ this._syncFunctionHash = null;
715
+ }
716
+ }
717
+ const C = [
718
+ // uploading pixi matrix object to mat3
719
+ {
720
+ type: "mat3x3<f32>",
721
+ test: (a) => a.value.a !== void 0,
722
+ ubo: `
723
+ var matrix = uv[name].toArray(true);
724
+ data[offset] = matrix[0];
725
+ data[offset + 1] = matrix[1];
726
+ data[offset + 2] = matrix[2];
727
+ data[offset + 4] = matrix[3];
728
+ data[offset + 5] = matrix[4];
729
+ data[offset + 6] = matrix[5];
730
+ data[offset + 8] = matrix[6];
731
+ data[offset + 9] = matrix[7];
732
+ data[offset + 10] = matrix[8];
733
+ `,
734
+ uniform: `
735
+ gl.uniformMatrix3fv(ud[name].location, false, uv[name].toArray(true));
736
+ `
737
+ },
738
+ // uploading a pixi rectangle as a vec4
739
+ {
740
+ type: "vec4<f32>",
741
+ test: (a) => a.type === "vec4<f32>" && a.size === 1 && a.value.width !== void 0,
742
+ ubo: `
743
+ v = uv[name];
744
+ data[offset] = v.x;
745
+ data[offset + 1] = v.y;
746
+ data[offset + 2] = v.width;
747
+ data[offset + 3] = v.height;
748
+ `,
749
+ uniform: `
750
+ cv = ud[name].value;
751
+ v = uv[name];
752
+ if (cv[0] !== v.x || cv[1] !== v.y || cv[2] !== v.width || cv[3] !== v.height) {
753
+ cv[0] = v.x;
754
+ cv[1] = v.y;
755
+ cv[2] = v.width;
756
+ cv[3] = v.height;
757
+ gl.uniform4f(ud[name].location, v.x, v.y, v.width, v.height);
758
+ }
759
+ `
760
+ },
761
+ // uploading a pixi point as a vec2
762
+ {
763
+ type: "vec2<f32>",
764
+ test: (a) => a.type === "vec2<f32>" && a.size === 1 && a.value.x !== void 0,
765
+ ubo: `
766
+ v = uv[name];
767
+ data[offset] = v.x;
768
+ data[offset + 1] = v.y;
769
+ `,
770
+ uniform: `
771
+ cv = ud[name].value;
772
+ v = uv[name];
773
+ if (cv[0] !== v.x || cv[1] !== v.y) {
774
+ cv[0] = v.x;
775
+ cv[1] = v.y;
776
+ gl.uniform2f(ud[name].location, v.x, v.y);
777
+ }
778
+ `
779
+ },
780
+ // uploading a pixi color as a vec4
781
+ {
782
+ type: "vec4<f32>",
783
+ test: (a) => a.type === "vec4<f32>" && a.size === 1 && a.value.red !== void 0,
784
+ ubo: `
785
+ v = uv[name];
786
+ data[offset] = v.red;
787
+ data[offset + 1] = v.green;
788
+ data[offset + 2] = v.blue;
789
+ data[offset + 3] = v.alpha;
790
+ `,
791
+ uniform: `
792
+ cv = ud[name].value;
793
+ v = uv[name];
794
+ if (cv[0] !== v.red || cv[1] !== v.green || cv[2] !== v.blue || cv[3] !== v.alpha) {
795
+ cv[0] = v.red;
796
+ cv[1] = v.green;
797
+ cv[2] = v.blue;
798
+ cv[3] = v.alpha;
799
+ gl.uniform4f(ud[name].location, v.red, v.green, v.blue, v.alpha);
800
+ }
801
+ `
802
+ },
803
+ // uploading a pixi color as a vec3
804
+ {
805
+ type: "vec3<f32>",
806
+ test: (a) => a.type === "vec3<f32>" && a.size === 1 && a.value.red !== void 0,
807
+ ubo: `
808
+ v = uv[name];
809
+ data[offset] = v.red;
810
+ data[offset + 1] = v.green;
811
+ data[offset + 2] = v.blue;
812
+ `,
813
+ uniform: `
814
+ cv = ud[name].value;
815
+ v = uv[name];
816
+ if (cv[0] !== v.red || cv[1] !== v.green || cv[2] !== v.blue) {
817
+ cv[0] = v.red;
818
+ cv[1] = v.green;
819
+ cv[2] = v.blue;
820
+ gl.uniform3f(ud[name].location, v.red, v.green, v.blue);
821
+ }
822
+ `
823
+ }
824
+ ];
825
+ function At(a, e, t, r) {
826
+ const s = [`
827
+ var v = null;
828
+ var v2 = null;
829
+ var t = 0;
830
+ var index = 0;
831
+ var name = null;
832
+ var arrayOffset = null;
833
+ `];
834
+ let n = 0;
835
+ for (let o = 0; o < a.length; o++) {
836
+ const l = a[o], d = l.data.name;
837
+ let c = !1, h = 0;
838
+ for (let p = 0; p < C.length; p++)
839
+ if (C[p].test(l.data)) {
840
+ h = l.offset / 4, s.push(
841
+ `name = "${d}";`,
842
+ `offset += ${h - n};`,
843
+ C[p][e] || C[p].ubo
844
+ ), c = !0;
845
+ break;
846
+ }
847
+ if (!c)
848
+ if (l.data.size > 1)
849
+ h = l.offset / 4, s.push(t(l, h - n));
850
+ else {
851
+ const p = r[l.data.type];
852
+ h = l.offset / 4, s.push(
853
+ /* wgsl */
854
+ `
855
+ v = uv.${d};
856
+ offset += ${h - n};
857
+ ${p};
858
+ `
859
+ );
860
+ }
861
+ n = h;
862
+ }
863
+ const i = s.join(`
864
+ `);
865
+ return new Function(
866
+ "uv",
867
+ "data",
868
+ "dataInt32",
869
+ "offset",
870
+ i
871
+ );
872
+ }
873
+ function x(a, e) {
874
+ return `
875
+ for (let i = 0; i < ${a * e}; i++) {
876
+ data[offset + (((i / ${a})|0) * 4) + (i % ${a})] = v[i];
877
+ }
878
+ `;
879
+ }
880
+ const at = {
881
+ f32: `
882
+ data[offset] = v;`,
883
+ i32: `
884
+ dataInt32[offset] = v;`,
885
+ "vec2<f32>": `
886
+ data[offset] = v[0];
887
+ data[offset + 1] = v[1];`,
888
+ "vec3<f32>": `
889
+ data[offset] = v[0];
890
+ data[offset + 1] = v[1];
891
+ data[offset + 2] = v[2];`,
892
+ "vec4<f32>": `
893
+ data[offset] = v[0];
894
+ data[offset + 1] = v[1];
895
+ data[offset + 2] = v[2];
896
+ data[offset + 3] = v[3];`,
897
+ "vec2<i32>": `
898
+ dataInt32[offset] = v[0];
899
+ dataInt32[offset + 1] = v[1];`,
900
+ "vec3<i32>": `
901
+ dataInt32[offset] = v[0];
902
+ dataInt32[offset + 1] = v[1];
903
+ dataInt32[offset + 2] = v[2];`,
904
+ "vec4<i32>": `
905
+ dataInt32[offset] = v[0];
906
+ dataInt32[offset + 1] = v[1];
907
+ dataInt32[offset + 2] = v[2];
908
+ dataInt32[offset + 3] = v[3];`,
909
+ "mat2x2<f32>": `
910
+ data[offset] = v[0];
911
+ data[offset + 1] = v[1];
912
+ data[offset + 4] = v[2];
913
+ data[offset + 5] = v[3];`,
914
+ "mat3x3<f32>": `
915
+ data[offset] = v[0];
916
+ data[offset + 1] = v[1];
917
+ data[offset + 2] = v[2];
918
+ data[offset + 4] = v[3];
919
+ data[offset + 5] = v[4];
920
+ data[offset + 6] = v[5];
921
+ data[offset + 8] = v[6];
922
+ data[offset + 9] = v[7];
923
+ data[offset + 10] = v[8];`,
924
+ "mat4x4<f32>": `
925
+ for (let i = 0; i < 16; i++) {
926
+ data[offset + i] = v[i];
927
+ }`,
928
+ "mat3x2<f32>": x(3, 2),
929
+ "mat4x2<f32>": x(4, 2),
930
+ "mat2x3<f32>": x(2, 3),
931
+ "mat4x3<f32>": x(4, 3),
932
+ "mat2x4<f32>": x(2, 4),
933
+ "mat3x4<f32>": x(3, 4)
934
+ }, It = {
935
+ ...at,
936
+ "mat2x2<f32>": `
937
+ data[offset] = v[0];
938
+ data[offset + 1] = v[1];
939
+ data[offset + 2] = v[2];
940
+ data[offset + 3] = v[3];
941
+ `
942
+ };
943
+ function nt(a, e, t, r, s, n) {
944
+ const i = n ? 1 : -1;
945
+ return a.identity(), a.a = 1 / r * 2, a.d = i * (1 / s * 2), a.tx = -1 - e * a.a, a.ty = -i - t * a.d, a;
946
+ }
947
+ const _ = /* @__PURE__ */ new Map();
948
+ function ve(a, e) {
949
+ if (!_.has(a)) {
950
+ const t = new m({
951
+ source: new U({
952
+ resource: a,
953
+ ...e
954
+ })
955
+ }), r = () => {
956
+ _.get(a) === t && _.delete(a);
957
+ };
958
+ t.once("destroy", r), t.source.once("destroy", r), _.set(a, t);
959
+ }
960
+ return _.get(a);
961
+ }
962
+ function it(a) {
963
+ const e = a.colorTexture.source.resource;
964
+ return globalThis.HTMLCanvasElement && e instanceof HTMLCanvasElement && document.body.contains(e);
965
+ }
966
+ const xe = class ge {
967
+ /**
968
+ * @param [descriptor] - Options for creating a render target.
969
+ */
970
+ constructor(e = {}) {
971
+ if (this.uid = M("renderTarget"), this.colorTextures = [], this.dirtyId = 0, this.isRoot = !1, this._size = new Float32Array(2), this._managedColorTextures = !1, e = { ...ge.defaultOptions, ...e }, this.stencil = e.stencil, this.depth = e.depth, this.isRoot = e.isRoot, typeof e.colorTextures == "number") {
972
+ this._managedColorTextures = !0;
973
+ for (let t = 0; t < e.colorTextures; t++)
974
+ this.colorTextures.push(
975
+ new T({
976
+ width: e.width,
977
+ height: e.height,
978
+ resolution: e.resolution,
979
+ antialias: e.antialias
980
+ })
981
+ );
982
+ } else {
983
+ this.colorTextures = [...e.colorTextures.map((r) => r.source)];
984
+ const t = this.colorTexture.source;
985
+ this.resize(t.width, t.height, t._resolution);
986
+ }
987
+ this.colorTexture.source.on("resize", this.onSourceResize, this), (e.depthStencilTexture || this.stencil) && (e.depthStencilTexture instanceof m || e.depthStencilTexture instanceof T ? this.depthStencilTexture = e.depthStencilTexture.source : this.ensureDepthStencilTexture());
988
+ }
989
+ get size() {
990
+ const e = this._size;
991
+ return e[0] = this.pixelWidth, e[1] = this.pixelHeight, e;
992
+ }
993
+ get width() {
994
+ return this.colorTexture.source.width;
995
+ }
996
+ get height() {
997
+ return this.colorTexture.source.height;
998
+ }
999
+ get pixelWidth() {
1000
+ return this.colorTexture.source.pixelWidth;
1001
+ }
1002
+ get pixelHeight() {
1003
+ return this.colorTexture.source.pixelHeight;
1004
+ }
1005
+ get resolution() {
1006
+ return this.colorTexture.source._resolution;
1007
+ }
1008
+ get colorTexture() {
1009
+ return this.colorTextures[0];
1010
+ }
1011
+ onSourceResize(e) {
1012
+ this.resize(e.width, e.height, e._resolution, !0);
1013
+ }
1014
+ /**
1015
+ * This will ensure a depthStencil texture is created for this render target.
1016
+ * Most likely called by the mask system to make sure we have stencil buffer added.
1017
+ * @internal
1018
+ */
1019
+ ensureDepthStencilTexture() {
1020
+ this.depthStencilTexture || (this.depthStencilTexture = new T({
1021
+ width: this.width,
1022
+ height: this.height,
1023
+ resolution: this.resolution,
1024
+ format: "depth24plus-stencil8",
1025
+ autoGenerateMipmaps: !1,
1026
+ antialias: !1,
1027
+ mipLevelCount: 1
1028
+ // sampleCount: handled by the render target system..
1029
+ }));
1030
+ }
1031
+ resize(e, t, r = this.resolution, s = !1) {
1032
+ this.dirtyId++, this.colorTextures.forEach((n, i) => {
1033
+ s && i === 0 || n.source.resize(e, t, r);
1034
+ }), this.depthStencilTexture && this.depthStencilTexture.source.resize(e, t, r);
1035
+ }
1036
+ destroy() {
1037
+ this.colorTexture.source.off("resize", this.onSourceResize, this), this._managedColorTextures && this.colorTextures.forEach((e) => {
1038
+ e.destroy();
1039
+ }), this.depthStencilTexture && (this.depthStencilTexture.destroy(), delete this.depthStencilTexture);
1040
+ }
1041
+ };
1042
+ xe.defaultOptions = {
1043
+ /** the width of the RenderTarget */
1044
+ width: 0,
1045
+ /** the height of the RenderTarget */
1046
+ height: 0,
1047
+ /** the resolution of the RenderTarget */
1048
+ resolution: 1,
1049
+ /** an array of textures, or a number indicating how many color textures there should be */
1050
+ colorTextures: 1,
1051
+ /** should this render target have a stencil buffer? */
1052
+ stencil: !1,
1053
+ /** should this render target have a depth buffer? */
1054
+ depth: !1,
1055
+ /** should this render target be antialiased? */
1056
+ antialias: !1,
1057
+ // save on perf by default!
1058
+ /** is this a root element, true if this is gl context owners render target */
1059
+ isRoot: !1
1060
+ };
1061
+ let I = xe;
1062
+ class Gt {
1063
+ constructor(e) {
1064
+ this.rootViewPort = new w(), this.viewport = new w(), this.onRenderTargetChange = new We("onRenderTargetChange"), this.projectionMatrix = new v(), this.defaultClearColor = [0, 0, 0, 0], this._renderSurfaceToRenderTargetHash = /* @__PURE__ */ new Map(), this._gpuRenderTargetHash = /* @__PURE__ */ Object.create(null), this._renderTargetStack = [], this._renderer = e, e.renderableGC.addManagedHash(this, "_gpuRenderTargetHash");
1065
+ }
1066
+ /** called when dev wants to finish a render pass */
1067
+ finishRenderPass() {
1068
+ this.adaptor.finishRenderPass(this.renderTarget);
1069
+ }
1070
+ /**
1071
+ * called when the renderer starts to render a scene.
1072
+ * @param options
1073
+ * @param options.target - the render target to render to
1074
+ * @param options.clear - the clear mode to use. Can be true or a CLEAR number 'COLOR | DEPTH | STENCIL' 0b111
1075
+ * @param options.clearColor - the color to clear to
1076
+ * @param options.frame - the frame to render to
1077
+ */
1078
+ renderStart({
1079
+ target: e,
1080
+ clear: t,
1081
+ clearColor: r,
1082
+ frame: s
1083
+ }) {
1084
+ var n, i;
1085
+ this._renderTargetStack.length = 0, this.push(
1086
+ e,
1087
+ t,
1088
+ r,
1089
+ s
1090
+ ), this.rootViewPort.copyFrom(this.viewport), this.rootRenderTarget = this.renderTarget, this.renderingToScreen = it(this.rootRenderTarget), (i = (n = this.adaptor).prerender) == null || i.call(n, this.rootRenderTarget);
1091
+ }
1092
+ postrender() {
1093
+ var e, t;
1094
+ (t = (e = this.adaptor).postrender) == null || t.call(e, this.rootRenderTarget);
1095
+ }
1096
+ /**
1097
+ * Binding a render surface! This is the main function of the render target system.
1098
+ * It will take the RenderSurface (which can be a texture, canvas, or render target) and bind it to the renderer.
1099
+ * Once bound all draw calls will be rendered to the render surface.
1100
+ *
1101
+ * If a frame is not provide and the render surface is a texture, the frame of the texture will be used.
1102
+ * @param renderSurface - the render surface to bind
1103
+ * @param clear - the clear mode to use. Can be true or a CLEAR number 'COLOR | DEPTH | STENCIL' 0b111
1104
+ * @param clearColor - the color to clear to
1105
+ * @param frame - the frame to render to
1106
+ * @returns the render target that was bound
1107
+ */
1108
+ bind(e, t = !0, r, s) {
1109
+ const n = this.getRenderTarget(e), i = this.renderTarget !== n;
1110
+ this.renderTarget = n, this.renderSurface = e;
1111
+ const o = this.getGpuRenderTarget(n);
1112
+ (n.pixelWidth !== o.width || n.pixelHeight !== o.height) && (this.adaptor.resizeGpuRenderTarget(n), o.width = n.pixelWidth, o.height = n.pixelHeight);
1113
+ const l = n.colorTexture, d = this.viewport, c = l.pixelWidth, h = l.pixelHeight;
1114
+ if (!s && e instanceof m && (s = e.frame), s) {
1115
+ const p = l._resolution;
1116
+ d.x = s.x * p + 0.5 | 0, d.y = s.y * p + 0.5 | 0, d.width = s.width * p + 0.5 | 0, d.height = s.height * p + 0.5 | 0;
1117
+ } else
1118
+ d.x = 0, d.y = 0, d.width = c, d.height = h;
1119
+ return nt(
1120
+ this.projectionMatrix,
1121
+ 0,
1122
+ 0,
1123
+ d.width / l.resolution,
1124
+ d.height / l.resolution,
1125
+ !n.isRoot
1126
+ ), this.adaptor.startRenderPass(n, t, r, d), i && this.onRenderTargetChange.emit(n), n;
1127
+ }
1128
+ clear(e, t = B.ALL, r) {
1129
+ t && (e && (e = this.getRenderTarget(e)), this.adaptor.clear(
1130
+ e || this.renderTarget,
1131
+ t,
1132
+ r,
1133
+ this.viewport
1134
+ ));
1135
+ }
1136
+ contextChange() {
1137
+ this._gpuRenderTargetHash = /* @__PURE__ */ Object.create(null);
1138
+ }
1139
+ /**
1140
+ * Push a render surface to the renderer. This will bind the render surface to the renderer,
1141
+ * @param renderSurface - the render surface to push
1142
+ * @param clear - the clear mode to use. Can be true or a CLEAR number 'COLOR | DEPTH | STENCIL' 0b111
1143
+ * @param clearColor - the color to clear to
1144
+ * @param frame - the frame to use when rendering to the render surface
1145
+ */
1146
+ push(e, t = B.ALL, r, s) {
1147
+ const n = this.bind(e, t, r, s);
1148
+ return this._renderTargetStack.push({
1149
+ renderTarget: n,
1150
+ frame: s
1151
+ }), n;
1152
+ }
1153
+ /** Pops the current render target from the renderer and restores the previous render target. */
1154
+ pop() {
1155
+ this._renderTargetStack.pop();
1156
+ const e = this._renderTargetStack[this._renderTargetStack.length - 1];
1157
+ this.bind(e.renderTarget, !1, null, e.frame);
1158
+ }
1159
+ /**
1160
+ * Gets the render target from the provide render surface. Eg if its a texture,
1161
+ * it will return the render target for the texture.
1162
+ * If its a render target, it will return the same render target.
1163
+ * @param renderSurface - the render surface to get the render target for
1164
+ * @returns the render target for the render surface
1165
+ */
1166
+ getRenderTarget(e) {
1167
+ return e.isTexture && (e = e.source), this._renderSurfaceToRenderTargetHash.get(e) ?? this._initRenderTarget(e);
1168
+ }
1169
+ /**
1170
+ * Copies a render surface to another texture.
1171
+ *
1172
+ * NOTE:
1173
+ * for sourceRenderSurfaceTexture, The render target must be something that is written too by the renderer
1174
+ *
1175
+ * The following is not valid:
1176
+ * @example
1177
+ * const canvas = document.createElement('canvas')
1178
+ * canvas.width = 200;
1179
+ * canvas.height = 200;
1180
+ *
1181
+ * const ctx = canvas2.getContext('2d')!
1182
+ * ctx.fillStyle = 'red'
1183
+ * ctx.fillRect(0, 0, 200, 200);
1184
+ *
1185
+ * const texture = RenderTexture.create({
1186
+ * width: 200,
1187
+ * height: 200,
1188
+ * })
1189
+ * const renderTarget = renderer.renderTarget.getRenderTarget(canvas2);
1190
+ *
1191
+ * renderer.renderTarget.copyToTexture(renderTarget,texture, {x:0,y:0},{width:200,height:200},{x:0,y:0});
1192
+ *
1193
+ * The best way to copy a canvas is to create a texture from it. Then render with that.
1194
+ *
1195
+ * Parsing in a RenderTarget canvas context (with a 2d context)
1196
+ * @param sourceRenderSurfaceTexture - the render surface to copy from
1197
+ * @param destinationTexture - the texture to copy to
1198
+ * @param originSrc - the origin of the copy
1199
+ * @param originSrc.x - the x origin of the copy
1200
+ * @param originSrc.y - the y origin of the copy
1201
+ * @param size - the size of the copy
1202
+ * @param size.width - the width of the copy
1203
+ * @param size.height - the height of the copy
1204
+ * @param originDest - the destination origin (top left to paste from!)
1205
+ * @param originDest.x - the x origin of the paste
1206
+ * @param originDest.y - the y origin of the paste
1207
+ */
1208
+ copyToTexture(e, t, r, s, n) {
1209
+ r.x < 0 && (s.width += r.x, n.x -= r.x, r.x = 0), r.y < 0 && (s.height += r.y, n.y -= r.y, r.y = 0);
1210
+ const { pixelWidth: i, pixelHeight: o } = e;
1211
+ return s.width = Math.min(s.width, i - r.x), s.height = Math.min(s.height, o - r.y), this.adaptor.copyToTexture(
1212
+ e,
1213
+ t,
1214
+ r,
1215
+ s,
1216
+ n
1217
+ );
1218
+ }
1219
+ /**
1220
+ * ensures that we have a depth stencil buffer available to render to
1221
+ * This is used by the mask system to make sure we have a stencil buffer.
1222
+ */
1223
+ ensureDepthStencil() {
1224
+ this.renderTarget.stencil || (this.renderTarget.stencil = !0, this.adaptor.startRenderPass(this.renderTarget, !1, null, this.viewport));
1225
+ }
1226
+ /** nukes the render target system */
1227
+ destroy() {
1228
+ this._renderer = null, this._renderSurfaceToRenderTargetHash.forEach((e, t) => {
1229
+ e !== t && e.destroy();
1230
+ }), this._renderSurfaceToRenderTargetHash.clear(), this._gpuRenderTargetHash = /* @__PURE__ */ Object.create(null);
1231
+ }
1232
+ _initRenderTarget(e) {
1233
+ let t = null;
1234
+ return U.test(e) && (e = ve(e).source), e instanceof I ? t = e : e instanceof T && (t = new I({
1235
+ colorTextures: [e]
1236
+ }), e.source instanceof U && (t.isRoot = !0), e.once("destroy", () => {
1237
+ t.destroy(), this._renderSurfaceToRenderTargetHash.delete(e);
1238
+ const r = this._gpuRenderTargetHash[t.uid];
1239
+ r && (this._gpuRenderTargetHash[t.uid] = null, this.adaptor.destroyGpuRenderTarget(r));
1240
+ })), this._renderSurfaceToRenderTargetHash.set(e, t), t;
1241
+ }
1242
+ getGpuRenderTarget(e) {
1243
+ return this._gpuRenderTargetHash[e.uid] || (this._gpuRenderTargetHash[e.uid] = this.adaptor.initGpuRenderTarget(e));
1244
+ }
1245
+ resetState() {
1246
+ this.renderTarget = null, this.renderSurface = null;
1247
+ }
1248
+ }
1249
+ class Dt extends Ve {
1250
+ /**
1251
+ * Create a new Buffer Resource.
1252
+ * @param options - The options for the buffer resource
1253
+ * @param options.buffer - The underlying buffer that this resource is using
1254
+ * @param options.offset - The offset of the buffer this resource is using.
1255
+ * If not provided, then it will use the offset of the buffer.
1256
+ * @param options.size - The size of the buffer this resource is using.
1257
+ * If not provided, then it will use the size of the buffer.
1258
+ */
1259
+ constructor({ buffer: e, offset: t, size: r }) {
1260
+ super(), this.uid = M("buffer"), this._resourceType = "bufferResource", this._touched = 0, this._resourceId = M("resource"), this._bufferResource = !0, this.destroyed = !1, this.buffer = e, this.offset = t | 0, this.size = r, this.buffer.on("change", this.onBufferChange, this);
1261
+ }
1262
+ onBufferChange() {
1263
+ this._resourceId = M("resource"), this.emit("change", this);
1264
+ }
1265
+ /**
1266
+ * Destroys this resource. Make sure the underlying buffer is not used anywhere else
1267
+ * if you want to destroy it as well, or code will explode
1268
+ * @param destroyBuffer - Should the underlying buffer be destroyed as well?
1269
+ */
1270
+ destroy(e = !1) {
1271
+ this.destroyed = !0, e && this.buffer.destroy(), this.emit("change", this), this.buffer = null;
1272
+ }
1273
+ }
1274
+ class _e {
1275
+ constructor(e) {
1276
+ this._renderer = e;
1277
+ }
1278
+ updateRenderable() {
1279
+ }
1280
+ destroyRenderable() {
1281
+ }
1282
+ validateRenderable() {
1283
+ return !1;
1284
+ }
1285
+ addRenderable(e, t) {
1286
+ this._renderer.renderPipes.batch.break(t), t.add(e);
1287
+ }
1288
+ execute(e) {
1289
+ e.isRenderable && e.render(this._renderer);
1290
+ }
1291
+ destroy() {
1292
+ this._renderer = null;
1293
+ }
1294
+ }
1295
+ _e.extension = {
1296
+ type: [
1297
+ u.WebGLPipes,
1298
+ u.WebGPUPipes,
1299
+ u.CanvasPipes
1300
+ ],
1301
+ name: "customRender"
1302
+ };
1303
+ function G(a, e) {
1304
+ const t = a.instructionSet, r = t.instructions;
1305
+ for (let s = 0; s < t.instructionSize; s++) {
1306
+ const n = r[s];
1307
+ e[n.renderPipeId].execute(n);
1308
+ }
1309
+ }
1310
+ const ot = new v();
1311
+ class be {
1312
+ constructor(e) {
1313
+ this._renderer = e;
1314
+ }
1315
+ addRenderGroup(e, t) {
1316
+ e.isCachedAsTexture ? this._addRenderableCacheAsTexture(e, t) : this._addRenderableDirect(e, t);
1317
+ }
1318
+ execute(e) {
1319
+ e.isRenderable && (e.isCachedAsTexture ? this._executeCacheAsTexture(e) : this._executeDirect(e));
1320
+ }
1321
+ destroy() {
1322
+ this._renderer = null;
1323
+ }
1324
+ _addRenderableDirect(e, t) {
1325
+ this._renderer.renderPipes.batch.break(t), e._batchableRenderGroup && (S.return(e._batchableRenderGroup), e._batchableRenderGroup = null), t.add(e);
1326
+ }
1327
+ _addRenderableCacheAsTexture(e, t) {
1328
+ const r = e._batchableRenderGroup ?? (e._batchableRenderGroup = S.get(de));
1329
+ r.renderable = e.root, r.transform = e.root.relativeGroupTransform, r.texture = e.texture, r.bounds = e._textureBounds, t.add(e), this._renderer.renderPipes.batch.addToBatch(r, t);
1330
+ }
1331
+ _executeCacheAsTexture(e) {
1332
+ if (e.textureNeedsUpdate) {
1333
+ e.textureNeedsUpdate = !1;
1334
+ const t = ot.identity().translate(
1335
+ -e._textureBounds.x,
1336
+ -e._textureBounds.y
1337
+ );
1338
+ this._renderer.renderTarget.push(e.texture, !0, null, e.texture.frame), this._renderer.globalUniforms.push({
1339
+ worldTransformMatrix: t,
1340
+ worldColor: 4294967295
1341
+ }), G(e, this._renderer.renderPipes), this._renderer.renderTarget.finishRenderPass(), this._renderer.renderTarget.pop(), this._renderer.globalUniforms.pop();
1342
+ }
1343
+ e._batchableRenderGroup._batcher.updateElement(e._batchableRenderGroup), e._batchableRenderGroup._batcher.geometry.buffers[0].update();
1344
+ }
1345
+ _executeDirect(e) {
1346
+ this._renderer.globalUniforms.push({
1347
+ worldTransformMatrix: e.inverseParentTextureTransform,
1348
+ worldColor: e.worldColorAlpha
1349
+ }), G(e, this._renderer.renderPipes), this._renderer.globalUniforms.pop();
1350
+ }
1351
+ }
1352
+ be.extension = {
1353
+ type: [
1354
+ u.WebGLPipes,
1355
+ u.WebGPUPipes,
1356
+ u.CanvasPipes
1357
+ ],
1358
+ name: "renderGroup"
1359
+ };
1360
+ function D(a, e) {
1361
+ e || (e = 0);
1362
+ for (let t = e; t < a.length && a[t]; t++)
1363
+ a[t] = null;
1364
+ }
1365
+ const lt = new P(), ee = oe | le | ue;
1366
+ function Te(a, e = !1) {
1367
+ ut(a);
1368
+ const t = a.childrenToUpdate, r = a.updateTick++;
1369
+ for (const s in t) {
1370
+ const n = Number(s), i = t[s], o = i.list, l = i.index;
1371
+ for (let d = 0; d < l; d++) {
1372
+ const c = o[d];
1373
+ c.parentRenderGroup === a && c.relativeRenderGroupDepth === n && ye(c, r, 0);
1374
+ }
1375
+ D(o, l), i.index = 0;
1376
+ }
1377
+ if (e)
1378
+ for (let s = 0; s < a.renderGroupChildren.length; s++)
1379
+ Te(a.renderGroupChildren[s], e);
1380
+ }
1381
+ function ut(a) {
1382
+ const e = a.root;
1383
+ let t;
1384
+ if (a.renderGroupParent) {
1385
+ const r = a.renderGroupParent;
1386
+ a.worldTransform.appendFrom(
1387
+ e.relativeGroupTransform,
1388
+ r.worldTransform
1389
+ ), a.worldColor = ie(
1390
+ e.groupColor,
1391
+ r.worldColor
1392
+ ), t = e.groupAlpha * r.worldAlpha;
1393
+ } else
1394
+ a.worldTransform.copyFrom(e.localTransform), a.worldColor = e.localColor, t = e.localAlpha;
1395
+ t = t < 0 ? 0 : t > 1 ? 1 : t, a.worldAlpha = t, a.worldColorAlpha = a.worldColor + ((t * 255 | 0) << 24);
1396
+ }
1397
+ function ye(a, e, t) {
1398
+ if (e === a.updateTick)
1399
+ return;
1400
+ a.updateTick = e, a.didChange = !1;
1401
+ const r = a.localTransform;
1402
+ a.updateLocalTransform();
1403
+ const s = a.parent;
1404
+ if (s && !s.renderGroup ? (t |= a._updateFlags, a.relativeGroupTransform.appendFrom(
1405
+ r,
1406
+ s.relativeGroupTransform
1407
+ ), t & ee && te(a, s, t)) : (t = a._updateFlags, a.relativeGroupTransform.copyFrom(r), t & ee && te(a, lt, t)), !a.renderGroup) {
1408
+ const n = a.children, i = n.length;
1409
+ for (let d = 0; d < i; d++)
1410
+ ye(n[d], e, t);
1411
+ const o = a.parentRenderGroup, l = a;
1412
+ l.renderPipeId && !o.structureDidChange && o.updateRenderable(l);
1413
+ }
1414
+ }
1415
+ function te(a, e, t) {
1416
+ if (t & le) {
1417
+ a.groupColor = ie(
1418
+ a.localColor,
1419
+ e.groupColor
1420
+ );
1421
+ let r = a.localAlpha * e.groupAlpha;
1422
+ r = r < 0 ? 0 : r > 1 ? 1 : r, a.groupAlpha = r, a.groupColorAlpha = a.groupColor + ((r * 255 | 0) << 24);
1423
+ }
1424
+ t & ue && (a.groupBlendMode = a.localBlendMode === "inherit" ? e.groupBlendMode : a.localBlendMode), t & oe && (a.globalDisplayStatus = a.localDisplayStatus & e.globalDisplayStatus), a._updateFlags = 0;
1425
+ }
1426
+ function dt(a, e) {
1427
+ const { list: t, index: r } = a.childrenRenderablesToUpdate;
1428
+ let s = !1;
1429
+ for (let n = 0; n < r; n++) {
1430
+ const i = t[n];
1431
+ if (s = e[i.renderPipeId].validateRenderable(i), s)
1432
+ break;
1433
+ }
1434
+ return a.structureDidChange = s, s;
1435
+ }
1436
+ const ct = new v();
1437
+ class ke {
1438
+ constructor(e) {
1439
+ this._renderer = e;
1440
+ }
1441
+ render({ container: e, transform: t }) {
1442
+ const r = e.parent, s = e.renderGroup.renderGroupParent;
1443
+ e.parent = null, e.renderGroup.renderGroupParent = null;
1444
+ const n = this._renderer;
1445
+ let i = ct;
1446
+ t && (i = i.copyFrom(e.renderGroup.localTransform), e.renderGroup.localTransform.copyFrom(t));
1447
+ const o = n.renderPipes;
1448
+ this._updateCachedRenderGroups(e.renderGroup, null), this._updateRenderGroups(e.renderGroup), n.globalUniforms.start({
1449
+ worldTransformMatrix: t ? e.renderGroup.localTransform : e.renderGroup.worldTransform,
1450
+ worldColor: e.renderGroup.worldColorAlpha
1451
+ }), G(e.renderGroup, o), o.uniformBatch && o.uniformBatch.renderEnd(), t && e.renderGroup.localTransform.copyFrom(i), e.parent = r, e.renderGroup.renderGroupParent = s;
1452
+ }
1453
+ destroy() {
1454
+ this._renderer = null;
1455
+ }
1456
+ _updateCachedRenderGroups(e, t) {
1457
+ if (e.isCachedAsTexture) {
1458
+ if (!e.updateCacheTexture)
1459
+ return;
1460
+ t = e;
1461
+ }
1462
+ e._parentCacheAsTextureRenderGroup = t;
1463
+ for (let r = e.renderGroupChildren.length - 1; r >= 0; r--)
1464
+ this._updateCachedRenderGroups(e.renderGroupChildren[r], t);
1465
+ if (e.invalidateMatrices(), e.isCachedAsTexture) {
1466
+ if (e.textureNeedsUpdate) {
1467
+ const r = e.root.getLocalBounds();
1468
+ r.ceil();
1469
+ const s = e.texture;
1470
+ e.texture && b.returnTexture(e.texture, !0);
1471
+ const n = this._renderer, i = e.textureOptions.resolution || n.view.resolution, o = e.textureOptions.antialias ?? n.view.antialias, l = e.textureOptions.scaleMode ?? "linear", d = b.getOptimalTexture(
1472
+ r.width,
1473
+ r.height,
1474
+ i,
1475
+ o
1476
+ );
1477
+ d._source.style = new Ne({ scaleMode: l }), e.texture = d, e._textureBounds || (e._textureBounds = new O()), e._textureBounds.copyFrom(r), s !== e.texture && e.renderGroupParent && (e.renderGroupParent.structureDidChange = !0);
1478
+ }
1479
+ } else e.texture && (b.returnTexture(e.texture, !0), e.texture = null);
1480
+ }
1481
+ _updateRenderGroups(e) {
1482
+ const t = this._renderer, r = t.renderPipes;
1483
+ if (e.runOnRender(t), e.instructionSet.renderPipes = r, e.structureDidChange ? D(e.childrenRenderablesToUpdate.list, 0) : dt(e, r), Te(e), e.structureDidChange ? (e.structureDidChange = !1, this._buildInstructions(e, t)) : this._updateRenderables(e), e.childrenRenderablesToUpdate.index = 0, t.renderPipes.batch.upload(e.instructionSet), !(e.isCachedAsTexture && !e.textureNeedsUpdate))
1484
+ for (let s = 0; s < e.renderGroupChildren.length; s++)
1485
+ this._updateRenderGroups(e.renderGroupChildren[s]);
1486
+ }
1487
+ _updateRenderables(e) {
1488
+ const { list: t, index: r } = e.childrenRenderablesToUpdate;
1489
+ for (let s = 0; s < r; s++) {
1490
+ const n = t[s];
1491
+ n.didViewUpdate && e.updateRenderable(n);
1492
+ }
1493
+ D(t, r);
1494
+ }
1495
+ _buildInstructions(e, t) {
1496
+ const r = e.root, s = e.instructionSet;
1497
+ s.reset();
1498
+ const n = t.renderPipes ? t : t.batch.renderer, i = n.renderPipes;
1499
+ i.batch.buildStart(s), i.blendMode.buildStart(), i.colorMask.buildStart(), r.sortableChildren && r.sortChildren(), r.collectRenderablesWithEffects(s, n, null), i.batch.buildEnd(s), i.blendMode.buildEnd(s);
1500
+ }
1501
+ }
1502
+ ke.extension = {
1503
+ type: [
1504
+ u.WebGLSystem,
1505
+ u.WebGPUSystem,
1506
+ u.CanvasSystem
1507
+ ],
1508
+ name: "renderGroup"
1509
+ };
1510
+ class Ce {
1511
+ constructor(e) {
1512
+ this._renderer = e;
1513
+ }
1514
+ addRenderable(e, t) {
1515
+ const r = this._getGpuSprite(e);
1516
+ e.didViewUpdate && this._updateBatchableSprite(e, r), this._renderer.renderPipes.batch.addToBatch(r, t);
1517
+ }
1518
+ updateRenderable(e) {
1519
+ const t = this._getGpuSprite(e);
1520
+ e.didViewUpdate && this._updateBatchableSprite(e, t), t._batcher.updateElement(t);
1521
+ }
1522
+ validateRenderable(e) {
1523
+ const t = this._getGpuSprite(e);
1524
+ return !t._batcher.checkAndUpdateTexture(
1525
+ t,
1526
+ e._texture
1527
+ );
1528
+ }
1529
+ _updateBatchableSprite(e, t) {
1530
+ t.bounds = e.visualBounds, t.texture = e._texture;
1531
+ }
1532
+ _getGpuSprite(e) {
1533
+ return e._gpuData[this._renderer.uid] || this._initGPUSprite(e);
1534
+ }
1535
+ _initGPUSprite(e) {
1536
+ const t = new de();
1537
+ return t.renderable = e, t.transform = e.groupTransform, t.texture = e._texture, t.bounds = e.visualBounds, t.roundPixels = this._renderer._roundPixels | e._roundPixels, e._gpuData[this._renderer.uid] = t, t;
1538
+ }
1539
+ destroy() {
1540
+ this._renderer = null;
1541
+ }
1542
+ }
1543
+ Ce.extension = {
1544
+ type: [
1545
+ u.WebGLPipes,
1546
+ u.WebGPUPipes,
1547
+ u.CanvasPipes
1548
+ ],
1549
+ name: "sprite"
1550
+ };
1551
+ const W = class Me {
1552
+ constructor() {
1553
+ this.clearBeforeRender = !0, this._backgroundColor = new A(0), this.color = this._backgroundColor, this.alpha = 1;
1554
+ }
1555
+ /**
1556
+ * initiates the background system
1557
+ * @param options - the options for the background colors
1558
+ */
1559
+ init(e) {
1560
+ e = { ...Me.defaultOptions, ...e }, this.clearBeforeRender = e.clearBeforeRender, this.color = e.background || e.backgroundColor || this._backgroundColor, this.alpha = e.backgroundAlpha, this._backgroundColor.setAlpha(e.backgroundAlpha);
1561
+ }
1562
+ /** The background color to fill if not transparent */
1563
+ get color() {
1564
+ return this._backgroundColor;
1565
+ }
1566
+ set color(e) {
1567
+ A.shared.setValue(e).alpha < 1 && this._backgroundColor.alpha === 1 && L(
1568
+ "Cannot set a transparent background on an opaque canvas. To enable transparency, set backgroundAlpha < 1 when initializing your Application."
1569
+ ), this._backgroundColor.setValue(e);
1570
+ }
1571
+ /** The background color alpha. Setting this to 0 will make the canvas transparent. */
1572
+ get alpha() {
1573
+ return this._backgroundColor.alpha;
1574
+ }
1575
+ set alpha(e) {
1576
+ this._backgroundColor.setAlpha(e);
1577
+ }
1578
+ /** The background color as an [R, G, B, A] array. */
1579
+ get colorRgba() {
1580
+ return this._backgroundColor.toArray();
1581
+ }
1582
+ /**
1583
+ * destroys the background system
1584
+ * @internal
1585
+ */
1586
+ destroy() {
1587
+ }
1588
+ };
1589
+ W.extension = {
1590
+ type: [
1591
+ u.WebGLSystem,
1592
+ u.WebGPUSystem,
1593
+ u.CanvasSystem
1594
+ ],
1595
+ name: "background",
1596
+ priority: 0
1597
+ };
1598
+ W.defaultOptions = {
1599
+ /**
1600
+ * {@link WebGLOptions.backgroundAlpha}
1601
+ * @default 1
1602
+ */
1603
+ backgroundAlpha: 1,
1604
+ /**
1605
+ * {@link WebGLOptions.backgroundColor}
1606
+ * @default 0x000000
1607
+ */
1608
+ backgroundColor: 0,
1609
+ /**
1610
+ * {@link WebGLOptions.clearBeforeRender}
1611
+ * @default true
1612
+ */
1613
+ clearBeforeRender: !0
1614
+ };
1615
+ let ht = W;
1616
+ const y = {};
1617
+ E.handle(u.BlendMode, (a) => {
1618
+ if (!a.name)
1619
+ throw new Error("BlendMode extension must have a name property");
1620
+ y[a.name] = a.ref;
1621
+ }, (a) => {
1622
+ delete y[a.name];
1623
+ });
1624
+ class Se {
1625
+ constructor(e) {
1626
+ this._isAdvanced = !1, this._filterHash = /* @__PURE__ */ Object.create(null), this._renderer = e, this._renderer.runners.prerender.add(this);
1627
+ }
1628
+ prerender() {
1629
+ this._activeBlendMode = "normal", this._isAdvanced = !1;
1630
+ }
1631
+ /**
1632
+ * This ensures that a blendMode switch is added to the instruction set if the blend mode has changed.
1633
+ * @param renderable - The renderable we are adding to the instruction set
1634
+ * @param blendMode - The blend mode of the renderable
1635
+ * @param instructionSet - The instruction set we are adding to
1636
+ */
1637
+ setBlendMode(e, t, r) {
1638
+ if (this._activeBlendMode === t) {
1639
+ this._isAdvanced && this._renderableList.push(e);
1640
+ return;
1641
+ }
1642
+ this._activeBlendMode = t, this._isAdvanced && this._endAdvancedBlendMode(r), this._isAdvanced = !!y[t], this._isAdvanced && (this._beginAdvancedBlendMode(r), this._renderableList.push(e));
1643
+ }
1644
+ _beginAdvancedBlendMode(e) {
1645
+ this._renderer.renderPipes.batch.break(e);
1646
+ const t = this._activeBlendMode;
1647
+ if (!y[t]) {
1648
+ L(`Unable to assign BlendMode: '${t}'. You may want to include: import 'pixi.js/advanced-blend-modes'`);
1649
+ return;
1650
+ }
1651
+ let r = this._filterHash[t];
1652
+ r || (r = this._filterHash[t] = new ne(), r.filters = [new y[t]()]);
1653
+ const s = {
1654
+ renderPipeId: "filter",
1655
+ action: "pushFilter",
1656
+ renderables: [],
1657
+ filterEffect: r,
1658
+ canBundle: !1
1659
+ };
1660
+ this._renderableList = s.renderables, e.add(s);
1661
+ }
1662
+ _endAdvancedBlendMode(e) {
1663
+ this._renderableList = null, this._renderer.renderPipes.batch.break(e), e.add({
1664
+ renderPipeId: "filter",
1665
+ action: "popFilter",
1666
+ canBundle: !1
1667
+ });
1668
+ }
1669
+ /**
1670
+ * called when the instruction build process is starting this will reset internally to the default blend mode
1671
+ * @internal
1672
+ */
1673
+ buildStart() {
1674
+ this._isAdvanced = !1;
1675
+ }
1676
+ /**
1677
+ * called when the instruction build process is finished, ensuring that if there is an advanced blend mode
1678
+ * active, we add the final render instructions added to the instruction set
1679
+ * @param instructionSet - The instruction set we are adding to
1680
+ * @internal
1681
+ */
1682
+ buildEnd(e) {
1683
+ this._isAdvanced && this._endAdvancedBlendMode(e);
1684
+ }
1685
+ /** @internal */
1686
+ destroy() {
1687
+ this._renderer = null, this._renderableList = null;
1688
+ for (const e in this._filterHash)
1689
+ this._filterHash[e].destroy();
1690
+ this._filterHash = null;
1691
+ }
1692
+ }
1693
+ Se.extension = {
1694
+ type: [
1695
+ u.WebGLPipes,
1696
+ u.WebGPUPipes,
1697
+ u.CanvasPipes
1698
+ ],
1699
+ name: "blendMode"
1700
+ };
1701
+ const R = {
1702
+ png: "image/png",
1703
+ jpg: "image/jpeg",
1704
+ webp: "image/webp"
1705
+ }, V = class we {
1706
+ /** @param renderer - The renderer this System works for. */
1707
+ constructor(e) {
1708
+ this._renderer = e;
1709
+ }
1710
+ _normalizeOptions(e, t = {}) {
1711
+ return e instanceof P || e instanceof m ? {
1712
+ target: e,
1713
+ ...t
1714
+ } : {
1715
+ ...t,
1716
+ ...e
1717
+ };
1718
+ }
1719
+ /**
1720
+ * Creates an IImage from a display object or texture.
1721
+ * @param options - Options for creating the image, or the target to extract
1722
+ * @returns Promise that resolves with the generated IImage
1723
+ * @example
1724
+ * ```ts
1725
+ * // Basic usage with a sprite
1726
+ * const sprite = new Sprite(texture);
1727
+ * const image = await renderer.extract.image(sprite);
1728
+ * document.body.appendChild(image);
1729
+ *
1730
+ * // Advanced usage with options
1731
+ * const image = await renderer.extract.image({
1732
+ * target: container,
1733
+ * format: 'webp',
1734
+ * quality: 0.8,
1735
+ * frame: new Rectangle(0, 0, 100, 100),
1736
+ * resolution: 2,
1737
+ * clearColor: '#ff0000',
1738
+ * antialias: true
1739
+ * });
1740
+ *
1741
+ * // Extract directly from a texture
1742
+ * const texture = Texture.from('myTexture.png');
1743
+ * const image = await renderer.extract.image(texture);
1744
+ * ```
1745
+ * @see {@link ExtractImageOptions} For detailed options
1746
+ * @see {@link ExtractSystem.base64} For base64 string output
1747
+ * @see {@link ExtractSystem.canvas} For canvas output
1748
+ * @see {@link ImageLike} For the image interface
1749
+ * @category rendering
1750
+ */
1751
+ async image(e) {
1752
+ const t = H.get().createImage();
1753
+ return t.src = await this.base64(e), t;
1754
+ }
1755
+ /**
1756
+ * Converts the target into a base64 encoded string.
1757
+ *
1758
+ * This method works by first creating
1759
+ * a canvas using `Extract.canvas` and then converting it to a base64 string.
1760
+ * @param options - The options for creating the base64 string, or the target to extract
1761
+ * @returns Promise that resolves with the base64 encoded string
1762
+ * @example
1763
+ * ```ts
1764
+ * // Basic usage with a sprite
1765
+ * const sprite = new Sprite(texture);
1766
+ * const base64 = await renderer.extract.base64(sprite);
1767
+ * console.log(base64); // data:image/png;base64,...
1768
+ *
1769
+ * // Advanced usage with options
1770
+ * const base64 = await renderer.extract.base64({
1771
+ * target: container,
1772
+ * format: 'webp',
1773
+ * quality: 0.8,
1774
+ * frame: new Rectangle(0, 0, 100, 100),
1775
+ * resolution: 2
1776
+ * });
1777
+ * ```
1778
+ * @throws Will throw an error if the platform doesn't support any of:
1779
+ * - ICanvas.toDataURL
1780
+ * - ICanvas.toBlob
1781
+ * - ICanvas.convertToBlob
1782
+ * @see {@link ExtractImageOptions} For detailed options
1783
+ * @see {@link ExtractSystem.canvas} For canvas output
1784
+ * @see {@link ExtractSystem.image} For HTMLImage output
1785
+ * @category rendering
1786
+ */
1787
+ async base64(e) {
1788
+ e = this._normalizeOptions(
1789
+ e,
1790
+ we.defaultImageOptions
1791
+ );
1792
+ const { format: t, quality: r } = e, s = this.canvas(e);
1793
+ if (s.toBlob !== void 0)
1794
+ return new Promise((n, i) => {
1795
+ s.toBlob((o) => {
1796
+ if (!o) {
1797
+ i(new Error("ICanvas.toBlob failed!"));
1798
+ return;
1799
+ }
1800
+ const l = new FileReader();
1801
+ l.onload = () => n(l.result), l.onerror = i, l.readAsDataURL(o);
1802
+ }, R[t], r);
1803
+ });
1804
+ if (s.toDataURL !== void 0)
1805
+ return s.toDataURL(R[t], r);
1806
+ if (s.convertToBlob !== void 0) {
1807
+ const n = await s.convertToBlob({ type: R[t], quality: r });
1808
+ return new Promise((i, o) => {
1809
+ const l = new FileReader();
1810
+ l.onload = () => i(l.result), l.onerror = o, l.readAsDataURL(n);
1811
+ });
1812
+ }
1813
+ throw new Error("Extract.base64() requires ICanvas.toDataURL, ICanvas.toBlob, or ICanvas.convertToBlob to be implemented");
1814
+ }
1815
+ /**
1816
+ * Creates a Canvas element, renders the target to it and returns it.
1817
+ * This method is useful for creating static images or when you need direct canvas access.
1818
+ * @param options - The options for creating the canvas, or the target to extract
1819
+ * @returns A Canvas element with the texture rendered on
1820
+ * @example
1821
+ * ```ts
1822
+ * // Basic canvas extraction from a sprite
1823
+ * const sprite = new Sprite(texture);
1824
+ * const canvas = renderer.extract.canvas(sprite);
1825
+ * document.body.appendChild(canvas);
1826
+ *
1827
+ * // Extract with custom region
1828
+ * const canvas = renderer.extract.canvas({
1829
+ * target: container,
1830
+ * frame: new Rectangle(0, 0, 100, 100)
1831
+ * });
1832
+ *
1833
+ * // Extract with high resolution
1834
+ * const canvas = renderer.extract.canvas({
1835
+ * target: sprite,
1836
+ * resolution: 2,
1837
+ * clearColor: '#ff0000'
1838
+ * });
1839
+ *
1840
+ * // Extract directly from a texture
1841
+ * const texture = Texture.from('myTexture.png');
1842
+ * const canvas = renderer.extract.canvas(texture);
1843
+ *
1844
+ * // Extract with anti-aliasing
1845
+ * const canvas = renderer.extract.canvas({
1846
+ * target: graphics,
1847
+ * antialias: true
1848
+ * });
1849
+ * ```
1850
+ * @see {@link ExtractOptions} For detailed options
1851
+ * @see {@link ExtractSystem.image} For HTMLImage output
1852
+ * @see {@link ExtractSystem.pixels} For raw pixel data
1853
+ * @category rendering
1854
+ */
1855
+ canvas(e) {
1856
+ e = this._normalizeOptions(e);
1857
+ const t = e.target, r = this._renderer;
1858
+ if (t instanceof m)
1859
+ return r.texture.generateCanvas(t);
1860
+ const s = r.textureGenerator.generateTexture(e), n = r.texture.generateCanvas(s);
1861
+ return s.destroy(!0), n;
1862
+ }
1863
+ /**
1864
+ * Returns a one-dimensional array containing the pixel data of the entire texture in RGBA order,
1865
+ * with integer values between 0 and 255 (inclusive).
1866
+ * > [!NOE] The returned array is a flat Uint8Array where every 4 values represent RGBA
1867
+ * @param options - The options for extracting the image, or the target to extract
1868
+ * @returns One-dimensional Uint8Array containing the pixel data in RGBA format
1869
+ * @example
1870
+ * ```ts
1871
+ * // Basic pixel extraction
1872
+ * const sprite = new Sprite(texture);
1873
+ * const pixels = renderer.extract.pixels(sprite);
1874
+ * console.log(pixels[0], pixels[1], pixels[2], pixels[3]); // R,G,B,A values
1875
+ *
1876
+ * // Extract with custom region
1877
+ * const pixels = renderer.extract.pixels({
1878
+ * target: sprite,
1879
+ * frame: new Rectangle(0, 0, 100, 100)
1880
+ * });
1881
+ *
1882
+ * // Extract with high resolution
1883
+ * const pixels = renderer.extract.pixels({
1884
+ * target: sprite,
1885
+ * resolution: 2
1886
+ * });
1887
+ * ```
1888
+ * @see {@link ExtractOptions} For detailed options
1889
+ * @see {@link ExtractSystem.canvas} For canvas output
1890
+ * @see {@link ExtractSystem.image} For image output
1891
+ * @category rendering
1892
+ */
1893
+ pixels(e) {
1894
+ e = this._normalizeOptions(e);
1895
+ const t = e.target, r = this._renderer, s = t instanceof m ? t : r.textureGenerator.generateTexture(e), n = r.texture.getPixels(s);
1896
+ return t instanceof P && s.destroy(!0), n;
1897
+ }
1898
+ /**
1899
+ * Creates a texture from a display object or existing texture.
1900
+ *
1901
+ * This is useful for creating
1902
+ * reusable textures from rendered content or making copies of existing textures.
1903
+ * > [!NOTE] The returned texture should be destroyed when no longer needed
1904
+ * @param options - The options for creating the texture, or the target to extract
1905
+ * @returns A new texture containing the extracted content
1906
+ * @example
1907
+ * ```ts
1908
+ * // Basic texture extraction from a sprite
1909
+ * const sprite = new Sprite(texture);
1910
+ * const extractedTexture = renderer.extract.texture(sprite);
1911
+ *
1912
+ * // Extract with custom region
1913
+ * const regionTexture = renderer.extract.texture({
1914
+ * target: container,
1915
+ * frame: new Rectangle(0, 0, 100, 100)
1916
+ * });
1917
+ *
1918
+ * // Extract with high resolution
1919
+ * const hiResTexture = renderer.extract.texture({
1920
+ * target: sprite,
1921
+ * resolution: 2,
1922
+ * clearColor: '#ff0000'
1923
+ * });
1924
+ *
1925
+ * // Create a new sprite from extracted texture
1926
+ * const newSprite = new Sprite(
1927
+ * renderer.extract.texture({
1928
+ * target: graphics,
1929
+ * antialias: true
1930
+ * })
1931
+ * );
1932
+ *
1933
+ * // Clean up when done
1934
+ * extractedTexture.destroy(true);
1935
+ * ```
1936
+ * @see {@link ExtractOptions} For detailed options
1937
+ * @see {@link Texture} For texture management
1938
+ * @see {@link GenerateTextureSystem} For texture generation
1939
+ * @category rendering
1940
+ */
1941
+ texture(e) {
1942
+ return e = this._normalizeOptions(e), e.target instanceof m ? e.target : this._renderer.textureGenerator.generateTexture(e);
1943
+ }
1944
+ /**
1945
+ * Extracts and downloads content from the renderer as an image file.
1946
+ * This is a convenient way to save screenshots or export rendered content.
1947
+ * > [!NOTE] The download will use PNG format regardless of the filename extension
1948
+ * @param options - The options for downloading and extracting the image, or the target to extract
1949
+ * @example
1950
+ * ```ts
1951
+ * // Basic download with default filename
1952
+ * const sprite = new Sprite(texture);
1953
+ * renderer.extract.download(sprite); // Downloads as 'image.png'
1954
+ *
1955
+ * // Download with custom filename
1956
+ * renderer.extract.download({
1957
+ * target: sprite,
1958
+ * filename: 'screenshot.png'
1959
+ * });
1960
+ *
1961
+ * // Download with custom region
1962
+ * renderer.extract.download({
1963
+ * target: container,
1964
+ * filename: 'region.png',
1965
+ * frame: new Rectangle(0, 0, 100, 100)
1966
+ * });
1967
+ *
1968
+ * // Download with high resolution and background
1969
+ * renderer.extract.download({
1970
+ * target: stage,
1971
+ * filename: 'hd-screenshot.png',
1972
+ * resolution: 2,
1973
+ * clearColor: '#ff0000'
1974
+ * });
1975
+ *
1976
+ * // Download with anti-aliasing
1977
+ * renderer.extract.download({
1978
+ * target: graphics,
1979
+ * filename: 'smooth.png',
1980
+ * antialias: true
1981
+ * });
1982
+ * ```
1983
+ * @see {@link ExtractDownloadOptions} For detailed options
1984
+ * @see {@link ExtractSystem.image} For creating images without download
1985
+ * @see {@link ExtractSystem.canvas} For canvas output
1986
+ * @category rendering
1987
+ */
1988
+ download(e) {
1989
+ e = this._normalizeOptions(e);
1990
+ const t = this.canvas(e), r = document.createElement("a");
1991
+ r.download = e.filename ?? "image.png", r.href = t.toDataURL("image/png"), document.body.appendChild(r), r.click(), document.body.removeChild(r);
1992
+ }
1993
+ /**
1994
+ * Logs the target to the console as an image. This is a useful way to debug what's happening in the renderer.
1995
+ * The image will be displayed in the browser's console using CSS background images.
1996
+ * @param options - The options for logging the image, or the target to log
1997
+ * @param options.width - The width of the logged image preview in the console (in pixels)
1998
+ * @example
1999
+ * ```ts
2000
+ * // Basic usage
2001
+ * const sprite = new Sprite(texture);
2002
+ * renderer.extract.log(sprite);
2003
+ * ```
2004
+ * @see {@link ExtractSystem.canvas} For getting raw canvas output
2005
+ * @see {@link ExtractSystem.pixels} For raw pixel data
2006
+ * @category rendering
2007
+ * @advanced
2008
+ */
2009
+ log(e) {
2010
+ const t = e.width ?? 200;
2011
+ e = this._normalizeOptions(e);
2012
+ const r = this.canvas(e), s = r.toDataURL();
2013
+ console.log(`[Pixi Texture] ${r.width}px ${r.height}px`);
2014
+ const n = [
2015
+ "font-size: 1px;",
2016
+ `padding: ${t}px 300px;`,
2017
+ `background: url(${s}) no-repeat;`,
2018
+ "background-size: contain;"
2019
+ ].join(" ");
2020
+ console.log("%c ", n);
2021
+ }
2022
+ destroy() {
2023
+ this._renderer = null;
2024
+ }
2025
+ };
2026
+ V.extension = {
2027
+ type: [
2028
+ u.WebGLSystem,
2029
+ u.WebGPUSystem
2030
+ ],
2031
+ name: "extract"
2032
+ };
2033
+ V.defaultImageOptions = {
2034
+ format: "png",
2035
+ quality: 1
2036
+ };
2037
+ let ft = V;
2038
+ class N extends m {
2039
+ static create(e) {
2040
+ return new N({
2041
+ source: new T(e)
2042
+ });
2043
+ }
2044
+ /**
2045
+ * Resizes the render texture.
2046
+ * @param width - The new width of the render texture.
2047
+ * @param height - The new height of the render texture.
2048
+ * @param resolution - The new resolution of the render texture.
2049
+ * @returns This texture.
2050
+ */
2051
+ resize(e, t, r) {
2052
+ return this.source.resize(e, t, r), this;
2053
+ }
2054
+ }
2055
+ const pt = new w(), mt = new O(), vt = [0, 0, 0, 0];
2056
+ class Pe {
2057
+ constructor(e) {
2058
+ this._renderer = e;
2059
+ }
2060
+ /**
2061
+ * Creates a texture from a display object that can be used for creating sprites and other textures.
2062
+ * This is particularly useful for optimizing performance when a complex container needs to be reused.
2063
+ * @param options - Generate texture options or a container to convert to texture
2064
+ * @returns A new RenderTexture containing the rendered display object
2065
+ * @example
2066
+ * ```ts
2067
+ * // Basic usage with a container
2068
+ * const container = new Container();
2069
+ * container.addChild(
2070
+ * new Graphics()
2071
+ * .circle(0, 0, 50)
2072
+ * .fill('red')
2073
+ * );
2074
+ *
2075
+ * const texture = renderer.textureGenerator.generateTexture(container);
2076
+ *
2077
+ * // Advanced usage with options
2078
+ * const texture = renderer.textureGenerator.generateTexture({
2079
+ * target: container,
2080
+ * frame: new Rectangle(0, 0, 100, 100), // Specific region
2081
+ * resolution: 2, // High DPI
2082
+ * clearColor: '#ff0000', // Red background
2083
+ * antialias: true // Smooth edges
2084
+ * });
2085
+ *
2086
+ * // Create a sprite from the generated texture
2087
+ * const sprite = new Sprite(texture);
2088
+ *
2089
+ * // Clean up when done
2090
+ * texture.destroy(true);
2091
+ * ```
2092
+ * @see {@link GenerateTextureOptions} For detailed texture generation options
2093
+ * @see {@link RenderTexture} For the type of texture created
2094
+ * @category rendering
2095
+ */
2096
+ generateTexture(e) {
2097
+ var d;
2098
+ e instanceof P && (e = {
2099
+ target: e,
2100
+ frame: void 0,
2101
+ textureSourceOptions: {},
2102
+ resolution: void 0
2103
+ });
2104
+ const t = e.resolution || this._renderer.resolution, r = e.antialias || this._renderer.view.antialias, s = e.target;
2105
+ let n = e.clearColor;
2106
+ n ? n = Array.isArray(n) && n.length === 4 ? n : A.shared.setValue(n).toArray() : n = vt;
2107
+ const i = ((d = e.frame) == null ? void 0 : d.copyTo(pt)) || je(s, mt).rectangle;
2108
+ i.width = Math.max(i.width, 1 / t) | 0, i.height = Math.max(i.height, 1 / t) | 0;
2109
+ const o = N.create({
2110
+ ...e.textureSourceOptions,
2111
+ width: i.width,
2112
+ height: i.height,
2113
+ resolution: t,
2114
+ antialias: r
2115
+ }), l = v.shared.translate(-i.x, -i.y);
2116
+ return this._renderer.render({
2117
+ container: s,
2118
+ transform: l,
2119
+ target: o,
2120
+ clearColor: n
2121
+ }), o.source.updateMipmaps(), o;
2122
+ }
2123
+ destroy() {
2124
+ this._renderer = null;
2125
+ }
2126
+ }
2127
+ Pe.extension = {
2128
+ type: [
2129
+ u.WebGLSystem,
2130
+ u.WebGPUSystem
2131
+ ],
2132
+ name: "textureGenerator"
2133
+ };
2134
+ class Re {
2135
+ constructor(e) {
2136
+ this._stackIndex = 0, this._globalUniformDataStack = [], this._uniformsPool = [], this._activeUniforms = [], this._bindGroupPool = [], this._activeBindGroups = [], this._renderer = e;
2137
+ }
2138
+ reset() {
2139
+ this._stackIndex = 0;
2140
+ for (let e = 0; e < this._activeUniforms.length; e++)
2141
+ this._uniformsPool.push(this._activeUniforms[e]);
2142
+ for (let e = 0; e < this._activeBindGroups.length; e++)
2143
+ this._bindGroupPool.push(this._activeBindGroups[e]);
2144
+ this._activeUniforms.length = 0, this._activeBindGroups.length = 0;
2145
+ }
2146
+ start(e) {
2147
+ this.reset(), this.push(e);
2148
+ }
2149
+ bind({
2150
+ size: e,
2151
+ projectionMatrix: t,
2152
+ worldTransformMatrix: r,
2153
+ worldColor: s,
2154
+ offset: n
2155
+ }) {
2156
+ const i = this._renderer.renderTarget.renderTarget, o = this._stackIndex ? this._globalUniformDataStack[this._stackIndex - 1] : {
2157
+ worldTransformMatrix: new v(),
2158
+ worldColor: 4294967295,
2159
+ offset: new $e()
2160
+ }, l = {
2161
+ projectionMatrix: t || this._renderer.renderTarget.projectionMatrix,
2162
+ resolution: e || i.size,
2163
+ worldTransformMatrix: r || o.worldTransformMatrix,
2164
+ worldColor: s || o.worldColor,
2165
+ offset: n || o.offset,
2166
+ bindGroup: null
2167
+ }, d = this._uniformsPool.pop() || this._createUniforms();
2168
+ this._activeUniforms.push(d);
2169
+ const c = d.uniforms;
2170
+ c.uProjectionMatrix = l.projectionMatrix, c.uResolution = l.resolution, c.uWorldTransformMatrix.copyFrom(l.worldTransformMatrix), c.uWorldTransformMatrix.tx -= l.offset.x, c.uWorldTransformMatrix.ty -= l.offset.y, Xe(
2171
+ l.worldColor,
2172
+ c.uWorldColorAlpha,
2173
+ 0
2174
+ ), d.update();
2175
+ let h;
2176
+ this._renderer.renderPipes.uniformBatch ? h = this._renderer.renderPipes.uniformBatch.getUniformBindGroup(d, !1) : (h = this._bindGroupPool.pop() || new qe(), this._activeBindGroups.push(h), h.setResource(d, 0)), l.bindGroup = h, this._currentGlobalUniformData = l;
2177
+ }
2178
+ push(e) {
2179
+ this.bind(e), this._globalUniformDataStack[this._stackIndex++] = this._currentGlobalUniformData;
2180
+ }
2181
+ pop() {
2182
+ this._currentGlobalUniformData = this._globalUniformDataStack[--this._stackIndex - 1], this._renderer.type === F.WEBGL && this._currentGlobalUniformData.bindGroup.resources[0].update();
2183
+ }
2184
+ get bindGroup() {
2185
+ return this._currentGlobalUniformData.bindGroup;
2186
+ }
2187
+ get globalUniformData() {
2188
+ return this._currentGlobalUniformData;
2189
+ }
2190
+ get uniformGroup() {
2191
+ return this._currentGlobalUniformData.bindGroup.resources[0];
2192
+ }
2193
+ _createUniforms() {
2194
+ return new se({
2195
+ uProjectionMatrix: { value: new v(), type: "mat3x3<f32>" },
2196
+ uWorldTransformMatrix: { value: new v(), type: "mat3x3<f32>" },
2197
+ // TODO - someone smart - set this to be a unorm8x4 rather than a vec4<f32>
2198
+ uWorldColorAlpha: { value: new Float32Array(4), type: "vec4<f32>" },
2199
+ uResolution: { value: [0, 0], type: "vec2<f32>" }
2200
+ }, {
2201
+ isStatic: !0
2202
+ });
2203
+ }
2204
+ destroy() {
2205
+ this._renderer = null;
2206
+ }
2207
+ }
2208
+ Re.extension = {
2209
+ type: [
2210
+ u.WebGLSystem,
2211
+ u.WebGPUSystem,
2212
+ u.CanvasSystem
2213
+ ],
2214
+ name: "globalUniforms"
2215
+ };
2216
+ let xt = 1;
2217
+ class Be {
2218
+ constructor() {
2219
+ this._tasks = [], this._offset = 0;
2220
+ }
2221
+ /** Initializes the scheduler system and starts the ticker. */
2222
+ init() {
2223
+ X.system.add(this._update, this);
2224
+ }
2225
+ /**
2226
+ * Schedules a repeating task.
2227
+ * @param func - The function to execute.
2228
+ * @param duration - The interval duration in milliseconds.
2229
+ * @param useOffset - this will spread out tasks so that they do not all run at the same time
2230
+ * @returns The unique identifier for the scheduled task.
2231
+ */
2232
+ repeat(e, t, r = !0) {
2233
+ const s = xt++;
2234
+ let n = 0;
2235
+ return r && (this._offset += 1e3, n = this._offset), this._tasks.push({
2236
+ func: e,
2237
+ duration: t,
2238
+ start: performance.now(),
2239
+ offset: n,
2240
+ last: performance.now(),
2241
+ repeat: !0,
2242
+ id: s
2243
+ }), s;
2244
+ }
2245
+ /**
2246
+ * Cancels a scheduled task.
2247
+ * @param id - The unique identifier of the task to cancel.
2248
+ */
2249
+ cancel(e) {
2250
+ for (let t = 0; t < this._tasks.length; t++)
2251
+ if (this._tasks[t].id === e) {
2252
+ this._tasks.splice(t, 1);
2253
+ return;
2254
+ }
2255
+ }
2256
+ /**
2257
+ * Updates and executes the scheduled tasks.
2258
+ * @private
2259
+ */
2260
+ _update() {
2261
+ const e = performance.now();
2262
+ for (let t = 0; t < this._tasks.length; t++) {
2263
+ const r = this._tasks[t];
2264
+ if (e - r.offset - r.last >= r.duration) {
2265
+ const s = e - r.start;
2266
+ r.func(s), r.last = e;
2267
+ }
2268
+ }
2269
+ }
2270
+ /**
2271
+ * Destroys the scheduler system and removes all tasks.
2272
+ * @internal
2273
+ */
2274
+ destroy() {
2275
+ X.system.remove(this._update, this), this._tasks.length = 0;
2276
+ }
2277
+ }
2278
+ Be.extension = {
2279
+ type: [
2280
+ u.WebGLSystem,
2281
+ u.WebGPUSystem,
2282
+ u.CanvasSystem
2283
+ ],
2284
+ name: "scheduler",
2285
+ priority: 0
2286
+ };
2287
+ let re = !1;
2288
+ function gt(a) {
2289
+ if (!re) {
2290
+ if (H.get().getNavigator().userAgent.toLowerCase().indexOf("chrome") > -1) {
2291
+ const e = [
2292
+ `%c %c %c %c %c PixiJS %c v${Q} (${a}) http://www.pixijs.com/
2293
+
2294
+ `,
2295
+ "background: #E72264; padding:5px 0;",
2296
+ "background: #6CA2EA; padding:5px 0;",
2297
+ "background: #B5D33D; padding:5px 0;",
2298
+ "background: #FED23F; padding:5px 0;",
2299
+ "color: #FFFFFF; background: #E72264; padding:5px 0;",
2300
+ "color: #E72264; background: #FFFFFF; padding:5px 0;"
2301
+ ];
2302
+ globalThis.console.log(...e);
2303
+ } else globalThis.console && globalThis.console.log(`PixiJS ${Q} - ${a} - http://www.pixijs.com/`);
2304
+ re = !0;
2305
+ }
2306
+ }
2307
+ class j {
2308
+ constructor(e) {
2309
+ this._renderer = e;
2310
+ }
2311
+ /**
2312
+ * It all starts here! This initiates every system, passing in the options for any system by name.
2313
+ * @param options - the config for the renderer and all its systems
2314
+ */
2315
+ init(e) {
2316
+ if (e.hello) {
2317
+ let t = this._renderer.name;
2318
+ this._renderer.type === F.WEBGL && (t += ` ${this._renderer.context.webGLVersion}`), gt(t);
2319
+ }
2320
+ }
2321
+ }
2322
+ j.extension = {
2323
+ type: [
2324
+ u.WebGLSystem,
2325
+ u.WebGPUSystem,
2326
+ u.CanvasSystem
2327
+ ],
2328
+ name: "hello",
2329
+ priority: -2
2330
+ };
2331
+ j.defaultOptions = {
2332
+ /** {@link WebGLOptions.hello} */
2333
+ hello: !1
2334
+ };
2335
+ function _t(a) {
2336
+ let e = !1;
2337
+ for (const r in a)
2338
+ if (a[r] == null) {
2339
+ e = !0;
2340
+ break;
2341
+ }
2342
+ if (!e)
2343
+ return a;
2344
+ const t = /* @__PURE__ */ Object.create(null);
2345
+ for (const r in a) {
2346
+ const s = a[r];
2347
+ s && (t[r] = s);
2348
+ }
2349
+ return t;
2350
+ }
2351
+ function bt(a) {
2352
+ let e = 0;
2353
+ for (let t = 0; t < a.length; t++)
2354
+ a[t] == null ? e++ : a[t - e] = a[t];
2355
+ return a.length -= e, a;
2356
+ }
2357
+ let Tt = 0;
2358
+ const $ = class Ue {
2359
+ /**
2360
+ * Creates a new RenderableGCSystem instance.
2361
+ * @param renderer - The renderer this garbage collection system works for
2362
+ */
2363
+ constructor(e) {
2364
+ this._managedRenderables = [], this._managedHashes = [], this._managedArrays = [], this._renderer = e;
2365
+ }
2366
+ /**
2367
+ * Initializes the garbage collection system with the provided options.
2368
+ * @param options - Configuration options for the renderer
2369
+ */
2370
+ init(e) {
2371
+ e = { ...Ue.defaultOptions, ...e }, this.maxUnusedTime = e.renderableGCMaxUnusedTime, this._frequency = e.renderableGCFrequency, this.enabled = e.renderableGCActive;
2372
+ }
2373
+ /**
2374
+ * Gets whether the garbage collection system is currently enabled.
2375
+ * @returns True if GC is enabled, false otherwise
2376
+ */
2377
+ get enabled() {
2378
+ return !!this._handler;
2379
+ }
2380
+ /**
2381
+ * Enables or disables the garbage collection system.
2382
+ * When enabled, schedules periodic cleanup of resources.
2383
+ * When disabled, cancels all scheduled cleanups.
2384
+ */
2385
+ set enabled(e) {
2386
+ this.enabled !== e && (e ? (this._handler = this._renderer.scheduler.repeat(
2387
+ () => this.run(),
2388
+ this._frequency,
2389
+ !1
2390
+ ), this._hashHandler = this._renderer.scheduler.repeat(
2391
+ () => {
2392
+ for (const t of this._managedHashes)
2393
+ t.context[t.hash] = _t(t.context[t.hash]);
2394
+ },
2395
+ this._frequency
2396
+ ), this._arrayHandler = this._renderer.scheduler.repeat(
2397
+ () => {
2398
+ for (const t of this._managedArrays)
2399
+ bt(t.context[t.hash]);
2400
+ },
2401
+ this._frequency
2402
+ )) : (this._renderer.scheduler.cancel(this._handler), this._renderer.scheduler.cancel(this._hashHandler), this._renderer.scheduler.cancel(this._arrayHandler)));
2403
+ }
2404
+ /**
2405
+ * Adds a hash table to be managed by the garbage collector.
2406
+ * @param context - The object containing the hash table
2407
+ * @param hash - The property name of the hash table
2408
+ */
2409
+ addManagedHash(e, t) {
2410
+ this._managedHashes.push({ context: e, hash: t });
2411
+ }
2412
+ /**
2413
+ * Adds an array to be managed by the garbage collector.
2414
+ * @param context - The object containing the array
2415
+ * @param hash - The property name of the array
2416
+ */
2417
+ addManagedArray(e, t) {
2418
+ this._managedArrays.push({ context: e, hash: t });
2419
+ }
2420
+ /**
2421
+ * Updates the GC timestamp and tracking before rendering.
2422
+ * @param options - The render options
2423
+ * @param options.container - The container to render
2424
+ */
2425
+ prerender({
2426
+ container: e
2427
+ }) {
2428
+ this._now = performance.now(), e.renderGroup.gcTick = Tt++, this._updateInstructionGCTick(e.renderGroup, e.renderGroup.gcTick);
2429
+ }
2430
+ /**
2431
+ * Starts tracking a renderable for garbage collection.
2432
+ * @param renderable - The renderable to track
2433
+ */
2434
+ addRenderable(e) {
2435
+ this.enabled && (e._lastUsed === -1 && (this._managedRenderables.push(e), e.once("destroyed", this._removeRenderable, this)), e._lastUsed = this._now);
2436
+ }
2437
+ /**
2438
+ * Performs garbage collection by cleaning up unused renderables.
2439
+ * Removes renderables that haven't been used for longer than maxUnusedTime.
2440
+ */
2441
+ run() {
2442
+ var n;
2443
+ const e = this._now, t = this._managedRenderables, r = this._renderer.renderPipes;
2444
+ let s = 0;
2445
+ for (let i = 0; i < t.length; i++) {
2446
+ const o = t[i];
2447
+ if (o === null) {
2448
+ s++;
2449
+ continue;
2450
+ }
2451
+ const l = o.renderGroup ?? o.parentRenderGroup, d = ((n = l == null ? void 0 : l.instructionSet) == null ? void 0 : n.gcTick) ?? -1;
2452
+ if (((l == null ? void 0 : l.gcTick) ?? 0) === d && (o._lastUsed = e), e - o._lastUsed > this.maxUnusedTime) {
2453
+ if (!o.destroyed) {
2454
+ const c = r;
2455
+ l && (l.structureDidChange = !0), c[o.renderPipeId].destroyRenderable(o);
2456
+ }
2457
+ o._lastUsed = -1, s++, o.off("destroyed", this._removeRenderable, this);
2458
+ } else
2459
+ t[i - s] = o;
2460
+ }
2461
+ t.length -= s;
2462
+ }
2463
+ /** Cleans up the garbage collection system. Disables GC and removes all tracked resources. */
2464
+ destroy() {
2465
+ this.enabled = !1, this._renderer = null, this._managedRenderables.length = 0, this._managedHashes.length = 0, this._managedArrays.length = 0;
2466
+ }
2467
+ /**
2468
+ * Removes a renderable from being tracked when it's destroyed.
2469
+ * @param renderable - The renderable to stop tracking
2470
+ */
2471
+ _removeRenderable(e) {
2472
+ const t = this._managedRenderables.indexOf(e);
2473
+ t >= 0 && (e.off("destroyed", this._removeRenderable, this), this._managedRenderables[t] = null);
2474
+ }
2475
+ /**
2476
+ * Updates the GC tick counter for a render group and its children.
2477
+ * @param renderGroup - The render group to update
2478
+ * @param gcTick - The new tick value
2479
+ */
2480
+ _updateInstructionGCTick(e, t) {
2481
+ e.instructionSet.gcTick = t;
2482
+ for (const r of e.renderGroupChildren)
2483
+ this._updateInstructionGCTick(r, t);
2484
+ }
2485
+ };
2486
+ $.extension = {
2487
+ type: [
2488
+ u.WebGLSystem,
2489
+ u.WebGPUSystem
2490
+ ],
2491
+ name: "renderableGC",
2492
+ priority: 0
2493
+ };
2494
+ $.defaultOptions = {
2495
+ /** Enable/disable the garbage collector */
2496
+ renderableGCActive: !0,
2497
+ /** Time in ms before an unused resource is collected (default 1 minute) */
2498
+ renderableGCMaxUnusedTime: 6e4,
2499
+ /** How often to run garbage collection in ms (default 30 seconds) */
2500
+ renderableGCFrequency: 3e4
2501
+ };
2502
+ let yt = $;
2503
+ const q = class Ae {
2504
+ /** @param renderer - The renderer this System works for. */
2505
+ constructor(e) {
2506
+ this._renderer = e, this.count = 0, this.checkCount = 0;
2507
+ }
2508
+ init(e) {
2509
+ e = { ...Ae.defaultOptions, ...e }, this.checkCountMax = e.textureGCCheckCountMax, this.maxIdle = e.textureGCAMaxIdle ?? e.textureGCMaxIdle, this.active = e.textureGCActive;
2510
+ }
2511
+ /**
2512
+ * Checks to see when the last time a texture was used.
2513
+ * If the texture has not been used for a specified amount of time, it will be removed from the GPU.
2514
+ */
2515
+ postrender() {
2516
+ this._renderer.renderingToScreen && (this.count++, this.active && (this.checkCount++, this.checkCount > this.checkCountMax && (this.checkCount = 0, this.run())));
2517
+ }
2518
+ /**
2519
+ * Checks to see when the last time a texture was used.
2520
+ * If the texture has not been used for a specified amount of time, it will be removed from the GPU.
2521
+ */
2522
+ run() {
2523
+ const e = this._renderer.texture.managedTextures;
2524
+ for (let t = 0; t < e.length; t++) {
2525
+ const r = e[t];
2526
+ r.autoGarbageCollect && r.resource && r._touched > -1 && this.count - r._touched > this.maxIdle && (r._touched = -1, r.unload());
2527
+ }
2528
+ }
2529
+ destroy() {
2530
+ this._renderer = null;
2531
+ }
2532
+ };
2533
+ q.extension = {
2534
+ type: [
2535
+ u.WebGLSystem,
2536
+ u.WebGPUSystem
2537
+ ],
2538
+ name: "textureGC"
2539
+ };
2540
+ q.defaultOptions = {
2541
+ /**
2542
+ * If set to true, this will enable the garbage collector on the GPU.
2543
+ * @default true
2544
+ */
2545
+ textureGCActive: !0,
2546
+ /**
2547
+ * @deprecated since 8.3.0
2548
+ * @see {@link TextureGCSystemOptions.textureGCMaxIdle}
2549
+ */
2550
+ textureGCAMaxIdle: null,
2551
+ /**
2552
+ * The maximum idle frames before a texture is destroyed by garbage collection.
2553
+ * @default 60 * 60
2554
+ */
2555
+ textureGCMaxIdle: 3600,
2556
+ /**
2557
+ * Frames between two garbage collections.
2558
+ * @default 600
2559
+ */
2560
+ textureGCCheckCountMax: 600
2561
+ };
2562
+ let kt = q;
2563
+ const K = class Ie {
2564
+ /**
2565
+ * Whether CSS dimensions of canvas view should be resized to screen dimensions automatically.
2566
+ * This is only supported for HTMLCanvasElement and will be ignored if the canvas is an OffscreenCanvas.
2567
+ * @type {boolean}
2568
+ */
2569
+ get autoDensity() {
2570
+ return this.texture.source.autoDensity;
2571
+ }
2572
+ set autoDensity(e) {
2573
+ this.texture.source.autoDensity = e;
2574
+ }
2575
+ /** The resolution / device pixel ratio of the renderer. */
2576
+ get resolution() {
2577
+ return this.texture.source._resolution;
2578
+ }
2579
+ set resolution(e) {
2580
+ this.texture.source.resize(
2581
+ this.texture.source.width,
2582
+ this.texture.source.height,
2583
+ e
2584
+ );
2585
+ }
2586
+ /**
2587
+ * initiates the view system
2588
+ * @param options - the options for the view
2589
+ */
2590
+ init(e) {
2591
+ e = {
2592
+ ...Ie.defaultOptions,
2593
+ ...e
2594
+ }, e.view && (Ke(Ye, "ViewSystem.view has been renamed to ViewSystem.canvas"), e.canvas = e.view), this.screen = new w(0, 0, e.width, e.height), this.canvas = e.canvas || H.get().createCanvas(), this.antialias = !!e.antialias, this.texture = ve(this.canvas, e), this.renderTarget = new I({
2595
+ colorTextures: [this.texture],
2596
+ depth: !!e.depth,
2597
+ isRoot: !0
2598
+ }), this.texture.source.transparent = e.backgroundAlpha < 1, this.resolution = e.resolution;
2599
+ }
2600
+ /**
2601
+ * Resizes the screen and canvas to the specified dimensions.
2602
+ * @param desiredScreenWidth - The new width of the screen.
2603
+ * @param desiredScreenHeight - The new height of the screen.
2604
+ * @param resolution
2605
+ */
2606
+ resize(e, t, r) {
2607
+ this.texture.source.resize(e, t, r), this.screen.width = this.texture.frame.width, this.screen.height = this.texture.frame.height;
2608
+ }
2609
+ /**
2610
+ * Destroys this System and optionally removes the canvas from the dom.
2611
+ * @param {options | false} options - The options for destroying the view, or "false".
2612
+ * @example
2613
+ * viewSystem.destroy();
2614
+ * viewSystem.destroy(true);
2615
+ * viewSystem.destroy({ removeView: true });
2616
+ */
2617
+ destroy(e = !1) {
2618
+ (typeof e == "boolean" ? e : !!(e != null && e.removeView)) && this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
2619
+ }
2620
+ };
2621
+ K.extension = {
2622
+ type: [
2623
+ u.WebGLSystem,
2624
+ u.WebGPUSystem,
2625
+ u.CanvasSystem
2626
+ ],
2627
+ name: "view",
2628
+ priority: 0
2629
+ };
2630
+ K.defaultOptions = {
2631
+ /**
2632
+ * {@link WebGLOptions.width}
2633
+ * @default 800
2634
+ */
2635
+ width: 800,
2636
+ /**
2637
+ * {@link WebGLOptions.height}
2638
+ * @default 600
2639
+ */
2640
+ height: 600,
2641
+ /**
2642
+ * {@link WebGLOptions.autoDensity}
2643
+ * @default false
2644
+ */
2645
+ autoDensity: !1,
2646
+ /**
2647
+ * {@link WebGLOptions.antialias}
2648
+ * @default false
2649
+ */
2650
+ antialias: !1
2651
+ };
2652
+ let Ct = K;
2653
+ const Et = [
2654
+ ht,
2655
+ Re,
2656
+ j,
2657
+ Ct,
2658
+ ke,
2659
+ kt,
2660
+ Pe,
2661
+ ft,
2662
+ Je,
2663
+ yt,
2664
+ Be
2665
+ ], Ot = [
2666
+ Se,
2667
+ he,
2668
+ Ce,
2669
+ be,
2670
+ fe,
2671
+ me,
2672
+ pe,
2673
+ _e
2674
+ ];
2675
+ export {
2676
+ Dt as B,
2677
+ g as G,
2678
+ Gt as R,
2679
+ Et as S,
2680
+ Ut as U,
2681
+ Ot as a,
2682
+ at as b,
2683
+ At as c,
2684
+ C as d,
2685
+ Bt as e,
2686
+ Rt as f,
2687
+ Pt as t,
2688
+ It as u
2689
+ };
2690
+ //# sourceMappingURL=SharedSystems-CZFehVPl.js.map