@annotorious/openseadragon 3.2.0 → 3.2.1

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