xxscreeps-mod-client 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -23,7 +23,7 @@ Environment variables:
23
23
  | Mount path | `SCREEPS_MOD_CLIENT_MOUNT_PATH` | `/` |
24
24
  | Redirect `/` → mount path | `SCREEPS_MOD_CLIENT_ROOT_REDIRECT` | `true` if `mountPath !== '/'`, else `false` |
25
25
 
26
- When mounted at `/`, the mod only serves paths that map to an existing file in `dist/` or that look like an SPA route (no file extension). Requests to xxscreeps' own endpoints (`/api/`, `/socket/`, …) are passed through to subsequent middleware.
26
+ When mounted at `/`, the mod only serves paths that map to an existing file in the client bundle or that look like an SPA route (no file extension). Requests to xxscreeps' own endpoints (`/api/`, `/socket/`, …) are passed through to subsequent middleware.
27
27
 
28
28
  ### Example
29
29
 
@@ -31,18 +31,9 @@ When mounted at `/`, the mod only serves paths that map to an existing file in `
31
31
  SCREEPS_MOD_CLIENT_MOUNT_PATH=/play npx xxscreeps start
32
32
  ```
33
33
 
34
- ## Build
34
+ ## How it works
35
35
 
36
- ```sh
37
- pnpm --filter xxscreeps-mod-client build
38
- ```
39
-
40
- This builds `screeps-client` with `base=/` (absolute asset URLs at the server root) and copies the artifacts into `dist/`. The shipped bundle is tied to its build-time base path — overriding `SCREEPS_MOD_CLIENT_MOUNT_PATH` at runtime requires a rebuild with a matching base:
41
-
42
- ```sh
43
- SCREEPS_MOD_CLIENT_BUILD_BASE=/play/ pnpm --filter xxscreeps-mod-client build
44
- SCREEPS_MOD_CLIENT_MOUNT_PATH=/play npx xxscreeps start
45
- ```
36
+ The mod resolves the client bundle from its [`screeps-client`](../screeps-client) dependency at runtime — no separate build step is needed. The shipped bundle is built with `base=/` (absolute asset URLs at the server root), which means non-default mount paths require a custom build of `screeps-client` with a matching base.
46
37
 
47
38
  ## xxscreeps mode
48
39
 
package/backend.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import path from 'node:path'
2
- import { fileURLToPath } from 'node:url'
2
+ import { createRequire } from 'node:module'
3
3
  import { createReadStream, existsSync, statSync } from 'node:fs'
4
4
  import { hooks } from 'xxscreeps/backend/index.js'
5
5
 
6
- const __dirname = path.dirname(fileURLToPath(import.meta.url))
7
- const distDir = path.join(__dirname, 'dist')
6
+ const require = createRequire(import.meta.url)
7
+ const clientPkgPath = require.resolve('screeps-client/package.json')
8
+ const distDir = path.join(path.dirname(clientPkgPath), 'dist', 'xxscreeps-mod')
8
9
  const indexFile = path.join(distDir, 'index.html')
9
10
 
10
11
  const CONTENT_TYPES = {
@@ -64,7 +65,7 @@ function sendFile(ctx, filePath, stat) {
64
65
 
65
66
  hooks.register('middleware', koa => {
66
67
  if (!existsSync(indexFile)) {
67
- console.error(`[xxscreeps-mod-client] dist/index.html not found at ${indexFile}. Run "pnpm --filter xxscreeps-mod-client build" first.`)
68
+ console.error(`[xxscreeps-mod-client] client bundle not found at ${indexFile}. Run "pnpm --filter screeps-client build:embedded:xxscreeps" first.`)
68
69
  return
69
70
  }
70
71
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xxscreeps-mod-client",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "xxscreeps mod that serves the screeps-client and connects it to the same server.",
5
5
  "type": "module",
6
6
  "xxscreeps": true,
@@ -10,8 +10,7 @@
10
10
  },
11
11
  "files": [
12
12
  "index.js",
13
- "backend.js",
14
- "dist/"
13
+ "backend.js"
15
14
  ],
16
15
  "repository": {
17
16
  "type": "git",
@@ -23,11 +22,15 @@
23
22
  "engines": {
24
23
  "node": ">=20"
25
24
  },
25
+ "dependencies": {
26
+ "screeps-client": "^0.3.0"
27
+ },
26
28
  "peerDependencies": {
27
29
  "xxscreeps": "*"
28
30
  },
29
- "scripts": {
30
- "build": "node ./scripts/build-client.js && node ./scripts/copy-dist.js",
31
- "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\""
31
+ "peerDependenciesMeta": {
32
+ "xxscreeps": {
33
+ "optional": true
34
+ }
32
35
  }
33
36
  }
@@ -1,185 +0,0 @@
1
- import{ap as U,a9 as g,S as c,an as S,d as _,e as m,E as I,am as h}from"./index-CINA8e_Z.js";const x={name:"local-uniform-bit",vertex:{header:`
2
-
3
- struct LocalUniforms {
4
- uTransformMatrix:mat3x3<f32>,
5
- uColor:vec4<f32>,
6
- uRound:f32,
7
- }
8
-
9
- @group(1) @binding(0) var<uniform> localUniforms : LocalUniforms;
10
- `,main:`
11
- vColor *= localUniforms.uColor;
12
- modelMatrix *= localUniforms.uTransformMatrix;
13
- `,end:`
14
- if(localUniforms.uRound == 1)
15
- {
16
- vPosition = vec4(roundPixels(vPosition.xy, globalUniforms.uResolution), vPosition.zw);
17
- }
18
- `}},C={...x,vertex:{...x.vertex,header:x.vertex.header.replace("group(1)","group(2)")}},D={name:"local-uniform-bit",vertex:{header:`
19
-
20
- uniform mat3 uTransformMatrix;
21
- uniform vec4 uColor;
22
- uniform float uRound;
23
- `,main:`
24
- vColor *= uColor;
25
- modelMatrix = uTransformMatrix;
26
- `,end:`
27
- if(uRound == 1.)
28
- {
29
- gl_Position.xy = roundPixels(gl_Position.xy, uResolution);
30
- }
31
- `}},O={name:"texture-bit",vertex:{header:`
32
-
33
- struct TextureUniforms {
34
- uTextureMatrix:mat3x3<f32>,
35
- }
36
-
37
- @group(2) @binding(2) var<uniform> textureUniforms : TextureUniforms;
38
- `,main:`
39
- uv = (textureUniforms.uTextureMatrix * vec3(uv, 1.0)).xy;
40
- `},fragment:{header:`
41
- @group(2) @binding(0) var uTexture: texture_2d<f32>;
42
- @group(2) @binding(1) var uSampler: sampler;
43
-
44
-
45
- `,main:`
46
- outColor = textureSample(uTexture, uSampler, vUV);
47
- `}},R={name:"texture-bit",vertex:{header:`
48
- uniform mat3 uTextureMatrix;
49
- `,main:`
50
- uv = (uTextureMatrix * vec3(uv, 1.0)).xy;
51
- `},fragment:{header:`
52
- uniform sampler2D uTexture;
53
-
54
-
55
- `,main:`
56
- outColor = texture(uTexture, vUV);
57
- `}};function A(e,t){for(const a in e.attributes){const s=e.attributes[a],r=t[a];r?(s.format??(s.format=r.format),s.offset??(s.offset=r.offset),s.instance??(s.instance=r.instance)):U(`Attribute ${a} is not present in the shader, but is present in the geometry. Unable to infer attribute details.`)}M(e)}function M(e){const{buffers:t,attributes:a}=e,s={},r={};for(const n in t){const o=t[n];s[o.uid]=0,r[o.uid]=0}for(const n in a){const o=a[n];s[o.buffer.uid]+=g(o.format).stride}for(const n in a){const o=a[n];o.stride??(o.stride=s[o.buffer.uid]),o.start??(o.start=r[o.buffer.uid]),r[o.buffer.uid]+=g(o.format).stride}}const d=[];d[c.NONE]=void 0;d[c.DISABLED]={stencilWriteMask:0,stencilReadMask:0};d[c.RENDERING_MASK_ADD]={stencilFront:{compare:"equal",passOp:"increment-clamp"},stencilBack:{compare:"equal",passOp:"increment-clamp"}};d[c.RENDERING_MASK_REMOVE]={stencilFront:{compare:"equal",passOp:"decrement-clamp"},stencilBack:{compare:"equal",passOp:"decrement-clamp"}};d[c.MASK_ACTIVE]={stencilWriteMask:0,stencilFront:{compare:"equal",passOp:"keep"},stencilBack:{compare:"equal",passOp:"keep"}};d[c.INVERSE_MASK_ACTIVE]={stencilWriteMask:0,stencilFront:{compare:"not-equal",passOp:"keep"},stencilBack:{compare:"not-equal",passOp:"keep"}};class k{constructor(t){this._syncFunctionHash=Object.create(null),this._adaptor=t,this._systemCheck()}_systemCheck(){if(!S())throw new Error("Current environment does not allow unsafe-eval, please use pixi.js/unsafe-eval module to enable support.")}ensureUniformGroup(t){const a=this.getUniformGroupData(t);t.buffer||(t.buffer=new _({data:new Float32Array(a.layout.size/4),usage:m.UNIFORM|m.COPY_DST}))}getUniformGroupData(t){return this._syncFunctionHash[t._signature]||this._initUniformGroup(t)}_initUniformGroup(t){const a=t._signature;let s=this._syncFunctionHash[a];if(!s){const r=Object.keys(t.uniformStructures).map(l=>t.uniformStructures[l]),n=this._adaptor.createUboElements(r),o=this._generateUboSync(n.uboElements);s=this._syncFunctionHash[a]={layout:n,syncFunction:o}}return this._syncFunctionHash[a]}_generateUboSync(t){return this._adaptor.generateUboSync(t)}syncUniformGroup(t,a,s){const r=this.getUniformGroupData(t);t.buffer||(t.buffer=new _({data:new Float32Array(r.layout.size/4),usage:m.UNIFORM|m.COPY_DST}));let n=null;return a||(a=t.buffer.data,n=t.buffer.dataInt32),s||(s=0),r.syncFunction(t.uniforms,a,n,s),!0}updateUniformGroup(t){if(t.isStatic&&!t._dirtyId)return!1;t._dirtyId=0;const a=this.syncUniformGroup(t);return t.buffer.update(),a}destroy(){this._syncFunctionHash=null}}const p=[{type:"mat3x3<f32>",test:e=>e.value.a!==void 0,ubo:`
58
- var matrix = uv[name].toArray(true);
59
- data[offset] = matrix[0];
60
- data[offset + 1] = matrix[1];
61
- data[offset + 2] = matrix[2];
62
- data[offset + 4] = matrix[3];
63
- data[offset + 5] = matrix[4];
64
- data[offset + 6] = matrix[5];
65
- data[offset + 8] = matrix[6];
66
- data[offset + 9] = matrix[7];
67
- data[offset + 10] = matrix[8];
68
- `,uniform:`
69
- gl.uniformMatrix3fv(ud[name].location, false, uv[name].toArray(true));
70
- `},{type:"vec4<f32>",test:e=>e.type==="vec4<f32>"&&e.size===1&&e.value.width!==void 0,ubo:`
71
- v = uv[name];
72
- data[offset] = v.x;
73
- data[offset + 1] = v.y;
74
- data[offset + 2] = v.width;
75
- data[offset + 3] = v.height;
76
- `,uniform:`
77
- cv = ud[name].value;
78
- v = uv[name];
79
- if (cv[0] !== v.x || cv[1] !== v.y || cv[2] !== v.width || cv[3] !== v.height) {
80
- cv[0] = v.x;
81
- cv[1] = v.y;
82
- cv[2] = v.width;
83
- cv[3] = v.height;
84
- gl.uniform4f(ud[name].location, v.x, v.y, v.width, v.height);
85
- }
86
- `},{type:"vec2<f32>",test:e=>e.type==="vec2<f32>"&&e.size===1&&e.value.x!==void 0,ubo:`
87
- v = uv[name];
88
- data[offset] = v.x;
89
- data[offset + 1] = v.y;
90
- `,uniform:`
91
- cv = ud[name].value;
92
- v = uv[name];
93
- if (cv[0] !== v.x || cv[1] !== v.y) {
94
- cv[0] = v.x;
95
- cv[1] = v.y;
96
- gl.uniform2f(ud[name].location, v.x, v.y);
97
- }
98
- `},{type:"vec4<f32>",test:e=>e.type==="vec4<f32>"&&e.size===1&&e.value.red!==void 0,ubo:`
99
- v = uv[name];
100
- data[offset] = v.red;
101
- data[offset + 1] = v.green;
102
- data[offset + 2] = v.blue;
103
- data[offset + 3] = v.alpha;
104
- `,uniform:`
105
- cv = ud[name].value;
106
- v = uv[name];
107
- if (cv[0] !== v.red || cv[1] !== v.green || cv[2] !== v.blue || cv[3] !== v.alpha) {
108
- cv[0] = v.red;
109
- cv[1] = v.green;
110
- cv[2] = v.blue;
111
- cv[3] = v.alpha;
112
- gl.uniform4f(ud[name].location, v.red, v.green, v.blue, v.alpha);
113
- }
114
- `},{type:"vec3<f32>",test:e=>e.type==="vec3<f32>"&&e.size===1&&e.value.red!==void 0,ubo:`
115
- v = uv[name];
116
- data[offset] = v.red;
117
- data[offset + 1] = v.green;
118
- data[offset + 2] = v.blue;
119
- `,uniform:`
120
- cv = ud[name].value;
121
- v = uv[name];
122
- if (cv[0] !== v.red || cv[1] !== v.green || cv[2] !== v.blue) {
123
- cv[0] = v.red;
124
- cv[1] = v.green;
125
- cv[2] = v.blue;
126
- gl.uniform3f(ud[name].location, v.red, v.green, v.blue);
127
- }
128
- `}];function B(e,t,a,s){const r=[`
129
- var v = null;
130
- var v2 = null;
131
- var t = 0;
132
- var index = 0;
133
- var name = null;
134
- var arrayOffset = null;
135
- `];let n=0;for(let l=0;l<e.length;l++){const f=e[l],b=f.data.name;let y=!1,i=0;for(let u=0;u<p.length;u++)if(p[u].test(f.data)){i=f.offset/4,r.push(`name = "${b}";`,`offset += ${i-n};`,p[u][t]||p[u].ubo),y=!0;break}if(!y)if(f.data.size>1)i=f.offset/4,r.push(a(f,i-n));else{const u=s[f.data.type];i=f.offset/4,r.push(`
136
- v = uv.${b};
137
- offset += ${i-n};
138
- ${u};
139
- `)}n=i}const o=r.join(`
140
- `);return new Function("uv","data","dataInt32","offset",o)}function v(e,t){return`
141
- for (let i = 0; i < ${e*t}; i++) {
142
- data[offset + (((i / ${e})|0) * 4) + (i % ${e})] = v[i];
143
- }
144
- `}const F={f32:`
145
- data[offset] = v;`,i32:`
146
- dataInt32[offset] = v;`,"vec2<f32>":`
147
- data[offset] = v[0];
148
- data[offset + 1] = v[1];`,"vec3<f32>":`
149
- data[offset] = v[0];
150
- data[offset + 1] = v[1];
151
- data[offset + 2] = v[2];`,"vec4<f32>":`
152
- data[offset] = v[0];
153
- data[offset + 1] = v[1];
154
- data[offset + 2] = v[2];
155
- data[offset + 3] = v[3];`,"vec2<i32>":`
156
- dataInt32[offset] = v[0];
157
- dataInt32[offset + 1] = v[1];`,"vec3<i32>":`
158
- dataInt32[offset] = v[0];
159
- dataInt32[offset + 1] = v[1];
160
- dataInt32[offset + 2] = v[2];`,"vec4<i32>":`
161
- dataInt32[offset] = v[0];
162
- dataInt32[offset + 1] = v[1];
163
- dataInt32[offset + 2] = v[2];
164
- dataInt32[offset + 3] = v[3];`,"mat2x2<f32>":`
165
- data[offset] = v[0];
166
- data[offset + 1] = v[1];
167
- data[offset + 4] = v[2];
168
- data[offset + 5] = v[3];`,"mat3x3<f32>":`
169
- data[offset] = v[0];
170
- data[offset + 1] = v[1];
171
- data[offset + 2] = v[2];
172
- data[offset + 4] = v[3];
173
- data[offset + 5] = v[4];
174
- data[offset + 6] = v[5];
175
- data[offset + 8] = v[6];
176
- data[offset + 9] = v[7];
177
- data[offset + 10] = v[8];`,"mat4x4<f32>":`
178
- for (let i = 0; i < 16; i++) {
179
- data[offset + i] = v[i];
180
- }`,"mat3x2<f32>":v(3,2),"mat4x2<f32>":v(4,2),"mat2x3<f32>":v(2,3),"mat4x3<f32>":v(4,3),"mat2x4<f32>":v(2,4),"mat3x4<f32>":v(3,4)},w={...F,"mat2x2<f32>":`
181
- data[offset] = v[0];
182
- data[offset + 1] = v[1];
183
- data[offset + 2] = v[2];
184
- data[offset + 3] = v[3];
185
- `};class P extends I{constructor({buffer:t,offset:a,size:s}){super(),this.uid=h("buffer"),this._resourceType="bufferResource",this._touched=0,this._resourceId=h("resource"),this._bufferResource=!0,this.destroyed=!1,this.buffer=t,this.offset=a|0,this.size=s,this.buffer.on("change",this.onBufferChange,this)}onBufferChange(){this._resourceId=h("resource"),this.emit("change",this)}destroy(t=!1){this.destroyed=!0,t&&this.buffer.destroy(),this.emit("change",this),this.buffer=null,this.removeAllListeners()}}export{P as B,d as G,k as U,D as a,C as b,B as c,R as d,A as e,w as f,p as g,x as l,O as t,F as u};
@@ -1 +0,0 @@
1
- import{af as Se,W as Me,ah as ae,M as U,k as R,r as Ve,ap as Xe,al as we,X as Ie,h as Re,T as Ae,a8 as $e,F as Je,l as Ke,g as Qe,D as Be,A as ze,u as Ze,a4 as re}from"./index-CINA8e_Z.js";import{b as et,c as tt,a as st,B as nt,d as at,R as ot,A as rt,C as it}from"./RenderTargetSystem-EVgeaEAK.js";import{a as P,c as ct}from"./canvasUtils-Dmy9CrII.js";import"./Filter-ZZPoYeTC.js";const ge=class ${static _getPatternRepeat(e,t){const s=e&&e!=="clamp-to-edge",n=t&&t!=="clamp-to-edge";return s&&n?"repeat":s?"repeat-x":n?"repeat-y":"no-repeat"}start(e,t,s){}execute(e,t){var i,c,u,m;const s=t.elements;if(!s||!s.length)return;const n=e.renderer,o=n.canvasContext,r=o.activeContext;for(let x=0;x<s.length;x++){const G=s[x];if(!G.packAsQuad)continue;const y=G,f=y.texture,S=f?P.getCanvasSource(f):null;if(!S)continue;const v=f.source.style,A=o.smoothProperty,Y=v.scaleMode!=="nearest";r[A]!==Y&&(r[A]=Y),o.setBlendMode(t.blendMode);const q=((i=n.globalUniforms.globalUniformData)==null?void 0:i.worldColor)??4294967295,E=y.color,k=(q>>>24&255)/255,C=(E>>>24&255)/255,V=((c=n.filter)==null?void 0:c.alphaMultiplier)??1,z=k*C*V;if(z<=0)continue;r.globalAlpha=z;const Z=q&16777215,J=E&16777215,b=Me(ae(J,Z)),M=f.frame,w=v.addressModeU??v.addressMode,ie=v.addressModeV??v.addressMode,ee=$._getPatternRepeat(w,ie),D=f.source._resolution??f.source.resolution??1,X=(m=(u=y.renderable)==null?void 0:u.renderGroup)==null?void 0:m.isCachedAsTexture,d=M.x*D,p=M.y*D,g=M.width*D,L=M.height*D,I=y.bounds,_=n.renderTarget.renderTarget.isRoot,W=I.minX,F=I.minY,B=I.maxX-I.minX,H=I.maxY-I.minY,O=f.rotate,l=f.uvs,N=Math.min(l.x0,l.x1,l.x2,l.x3,l.y0,l.y1,l.y2,l.y3),j=Math.max(l.x0,l.x1,l.x2,l.x3,l.y0,l.y1,l.y2,l.y3),T=ee!=="no-repeat"&&(N<0||j>1),ce=O&&!(!T&&(b!==16777215||O));ce?($._tempPatternMatrix.copyFrom(y.transform),Se.matrixAppendRotationInv($._tempPatternMatrix,O,W,F,B,H),o.setContextTransform($._tempPatternMatrix,y.roundPixels===1,void 0,X&&_)):o.setContextTransform(y.transform,y.roundPixels===1,void 0,X&&_);const te=ce?0:W,se=ce?0:F,le=B,he=H;if(T){let de=S;const K=b!==16777215&&!O,Q=M.width<=f.source.width&&M.height<=f.source.height;K&&Q&&(de=P.getTintedCanvas({texture:f},b));const pe=r.createPattern(de,ee);if(!pe)continue;const ye=le,xe=he;if(ye===0||xe===0)continue;const Ce=1/ye,Te=1/xe,Pe=(l.x1-l.x0)*Ce,ke=(l.y1-l.y0)*Ce,be=(l.x3-l.x0)*Te,_e=(l.y3-l.y0)*Te,je=l.x0-Pe*te-be*se,Ye=l.y0-ke*te-_e*se,ue=f.source.pixelWidth,me=f.source.pixelHeight;$._tempPatternMatrix.set(Pe*ue,ke*me,be*ue,_e*me,je*ue,Ye*me),P.applyPatternTransform(pe,$._tempPatternMatrix),r.fillStyle=pe,r.fillRect(te,se,le,he)}else{const K=b!==16777215||O?P.getTintedCanvas({texture:f},b):S,Q=K!==S;r.drawImage(K,Q?0:d,Q?0:p,Q?K.width:g,Q?K.height:L,te,se,le,he)}}}};ge._tempPatternMatrix=new U;ge.extension={type:[R.CanvasPipesAdaptor],name:"batch"};let lt=ge;class He{constructor(e){this._colorStack=[],this._colorStackIndex=0,this._currentColor=0,this._renderer=e}buildStart(){this._colorStack[0]=15,this._colorStackIndex=1,this._currentColor=15}push(e,t,s){this._renderer.renderPipes.batch.break(s);const n=this._colorStack;n[this._colorStackIndex]=n[this._colorStackIndex-1]&e.mask;const o=this._colorStack[this._colorStackIndex];o!==this._currentColor&&(this._currentColor=o,s.add({renderPipeId:"colorMask",colorMask:o,canBundle:!1})),this._colorStackIndex++}pop(e,t,s){this._renderer.renderPipes.batch.break(s);const n=this._colorStack;this._colorStackIndex--;const o=n[this._colorStackIndex-1];o!==this._currentColor&&(this._currentColor=o,s.add({renderPipeId:"colorMask",colorMask:o,canBundle:!1}))}execute(e){}destroy(){this._renderer=null,this._colorStack=null}}He.extension={type:[R.CanvasPipes],name:"colorMask"};function ht(a,e,t,s,n,o){o=Math.max(0,Math.min(o,Math.min(s,n)/2)),a.moveTo(e+o,t),a.lineTo(e+s-o,t),a.quadraticCurveTo(e+s,t,e+s,t+o),a.lineTo(e+s,t+n-o),a.quadraticCurveTo(e+s,t+n,e+s-o,t+n),a.lineTo(e+o,t+n),a.quadraticCurveTo(e,t+n,e,t+n-o),a.lineTo(e,t+o),a.quadraticCurveTo(e,t,e+o,t)}function Ge(a,e){switch(e.type){case"rectangle":{const t=e;a.rect(t.x,t.y,t.width,t.height);break}case"roundedRectangle":{const t=e;ht(a,t.x,t.y,t.width,t.height,t.radius);break}case"circle":{const t=e;a.moveTo(t.x+t.radius,t.y),a.arc(t.x,t.y,t.radius,0,Math.PI*2);break}case"ellipse":{const t=e;a.ellipse?(a.moveTo(t.x+t.halfWidth,t.y),a.ellipse(t.x,t.y,t.halfWidth,t.halfHeight,0,0,Math.PI*2)):(a.save(),a.translate(t.x,t.y),a.scale(t.halfWidth,t.halfHeight),a.moveTo(1,0),a.arc(0,0,1,0,Math.PI*2),a.restore());break}case"triangle":{const t=e;a.moveTo(t.x,t.y),a.lineTo(t.x2,t.y2),a.lineTo(t.x3,t.y3),a.closePath();break}case"polygon":default:{const t=e,s=t.points;if(!(s!=null&&s.length))break;a.moveTo(s[0],s[1]);for(let n=2;n<s.length;n+=2)a.lineTo(s[n],s[n+1]);t.closePath&&a.closePath();break}}}function dt(a,e,t){const s=[],n=[],o=[],r=we[e.type];if(!(r!=null&&r.build(e,s)))return!1;const i=e.closePath??!0;Ie(s,t,!1,i,n,o);for(let c=0;c<o.length;c+=3){const u=o[c]*2,m=o[c+1]*2,x=o[c+2]*2;a.moveTo(n[u],n[u+1]),a.lineTo(n[m],n[m+1]),a.lineTo(n[x],n[x+1]),a.closePath()}return!0}function pt(a,e){if(!(e!=null&&e.length))return!1;for(let t=0;t<e.length;t++){const s=e[t];if(!(s!=null&&s.shape))continue;const n=s.transform,o=n&&!n.isIdentity();o&&(a.save(),a.transform(n.a,n.b,n.c,n.d,n.tx,n.ty)),Ge(a,s.shape),o&&a.restore()}return!0}class Ee{constructor(e){this._warnedMaskTypes=new Set,this._canvasMaskStack=[],this._renderer=e}push(e,t,s){this._renderer.renderPipes.batch.break(s),s.add({renderPipeId:"stencilMask",action:"pushMaskBegin",mask:e,inverse:t._maskOptions.inverse,canBundle:!1})}pop(e,t,s){this._renderer.renderPipes.batch.break(s),s.add({renderPipeId:"stencilMask",action:"popMaskEnd",mask:e,inverse:t._maskOptions.inverse,canBundle:!1})}execute(e){var m,x,G;if(e.action!=="pushMaskBegin"&&e.action!=="popMaskEnd")return;const t=this._renderer,s=t.canvasContext,n=s==null?void 0:s.activeContext;if(!n)return;if(e.action==="popMaskEnd"){this._canvasMaskStack.pop()&&n.restore();return}e.inverse&&this._warnOnce("inverse","CanvasRenderer: inverse masks are not supported on Canvas2D; ignoring inverse flag.");const o=e.mask.mask;if(!(o instanceof Ve)){this._warnOnce("nonGraphics","CanvasRenderer: only Graphics masks are supported in Canvas2D; skipping mask."),this._canvasMaskStack.push(!1);return}const r=o,i=(m=r.context)==null?void 0:m.instructions;if(!(i!=null&&i.length)){this._canvasMaskStack.push(!1);return}n.save(),s.setContextTransform(r.groupTransform,(t._roundPixels|r._roundPixels)===1),n.beginPath();let c=!1,u=!1;for(let y=0;y<i.length;y++){const f=i[y],S=f.action;if(S!=="fill"&&S!=="stroke")continue;const v=f.data,A=(x=v==null?void 0:v.path)==null?void 0:x.shapePath;if(!((G=A==null?void 0:A.shapePrimitives)!=null&&G.length))continue;const Y=S==="stroke",q=A.shapePrimitives;for(let E=0;E<q.length;E++){const k=q[E];if(!(k!=null&&k.shape))continue;const C=k.transform,V=C&&!C.isIdentity();V&&(n.save(),n.transform(C.a,C.b,C.c,C.d,C.tx,C.ty)),Y&&v.style?c=dt(n,k.shape,v.style)||c:(Ge(n,k.shape),u=pt(n,k.holes)||u,c=!0),V&&n.restore()}}if(!c){n.restore(),this._canvasMaskStack.push(!1);return}u?n.clip("evenodd"):n.clip(),this._canvasMaskStack.push(!0)}destroy(){this._renderer=null,this._warnedMaskTypes=null,this._canvasMaskStack=null}_warnOnce(e,t){this._warnedMaskTypes.has(e)||(this._warnedMaskTypes.add(e),Xe(t))}}Ee.extension={type:[R.CanvasPipes],name:"stencilMask"};const h="source-over";function ut(){const a=ct(),e=Object.create(null);return e.inherit=h,e.none=h,e.normal="source-over",e.add="lighter",e.multiply=a?"multiply":h,e.screen=a?"screen":h,e.overlay=a?"overlay":h,e.darken=a?"darken":h,e.lighten=a?"lighten":h,e["color-dodge"]=a?"color-dodge":h,e["color-burn"]=a?"color-burn":h,e["hard-light"]=a?"hard-light":h,e["soft-light"]=a?"soft-light":h,e.difference=a?"difference":h,e.exclusion=a?"exclusion":h,e.saturation=a?"saturation":h,e.color=a?"color":h,e.luminosity=a?"luminosity":h,e["linear-burn"]=a?"color-burn":h,e["linear-dodge"]=a?"color-dodge":h,e["linear-light"]=a?"hard-light":h,e["pin-light"]=a?"hard-light":h,e["vivid-light"]=a?"hard-light":h,e["hard-mix"]=h,e.negation=a?"difference":h,e["normal-npm"]=e.normal,e["add-npm"]=e.add,e["screen-npm"]=e.screen,e.erase="destination-out",e.subtract=h,e.divide=h,e.min=h,e.max=h,e}const mt=new U;class We{constructor(e){this.activeResolution=1,this.smoothProperty="imageSmoothingEnabled",this.blendModes=ut(),this._activeBlendMode="normal",this._projTransform=null,this._outerBlend=!1,this._warnedBlendModes=new Set,this._renderer=e}resolutionChange(e){this.activeResolution=e}init(){const e=this._renderer.background.alpha<1;if(this.rootContext=this._renderer.canvas.getContext("2d",{alpha:e}),this.activeContext=this.rootContext,this.activeResolution=this._renderer.resolution,!this.rootContext.imageSmoothingEnabled){const t=this.rootContext;t.webkitImageSmoothingEnabled?this.smoothProperty="webkitImageSmoothingEnabled":t.mozImageSmoothingEnabled?this.smoothProperty="mozImageSmoothingEnabled":t.oImageSmoothingEnabled?this.smoothProperty="oImageSmoothingEnabled":t.msImageSmoothingEnabled&&(this.smoothProperty="msImageSmoothingEnabled")}}setContextTransform(e,t,s,n){var u;const o=n?U.IDENTITY:((u=this._renderer.globalUniforms.globalUniformData)==null?void 0:u.worldTransformMatrix)||U.IDENTITY;let r=mt;r.copyFrom(o),r.append(e);const i=this._projTransform,c=this.activeResolution;if(s=s||c,i){const m=U.shared;m.copyFrom(r),m.prepend(i),r=m}t?this.activeContext.setTransform(r.a*s,r.b*s,r.c*s,r.d*s,r.tx*c|0,r.ty*c|0):this.activeContext.setTransform(r.a*s,r.b*s,r.c*s,r.d*s,r.tx*c,r.ty*c)}clear(e,t){const s=this.activeContext,n=this._renderer;if(s.clearRect(0,0,n.width,n.height),e){const o=Re.shared.setValue(e);s.globalAlpha=t??o.alpha,s.fillStyle=o.toHex(),s.fillRect(0,0,n.width,n.height),s.globalAlpha=1}}setBlendMode(e){if(this._activeBlendMode===e)return;this._activeBlendMode=e,this._outerBlend=!1;const t=this.blendModes[e];if(!t){this._warnedBlendModes.has(e)||(console.warn(`CanvasRenderer: blend mode "${e}" is not supported in Canvas2D; falling back to "source-over".`),this._warnedBlendModes.add(e)),this.activeContext.globalCompositeOperation="source-over";return}this.activeContext.globalCompositeOperation=t}destroy(){this.rootContext=null,this.activeContext=null,this._warnedBlendModes.clear()}}We.extension={type:[R.CanvasSystem],name:"canvasContext"};class Fe{constructor(){this.maxTextures=16,this.maxBatchableTextures=16,this.maxUniformBindings=0}init(){}}Fe.extension={type:[R.CanvasSystem],name:"limits"};const ft="#808080",ne=new U,gt=new U,vt=new U,fe=new U;function yt(a,e,t){a.beginPath();for(let s=0;s<t.length;s+=3){const n=t[s]*2,o=t[s+1]*2,r=t[s+2]*2;a.moveTo(e[n],e[n+1]),a.lineTo(e[o],e[o+1]),a.lineTo(e[r],e[r+1]),a.closePath()}a.fill()}function xt(a){return`#${(a&16777215).toString(16).padStart(6,"0")}`}function Ct(a,e,t,s,n,o){o=Math.max(0,Math.min(o,Math.min(s,n)/2)),a.moveTo(e+o,t),a.lineTo(e+s-o,t),a.quadraticCurveTo(e+s,t,e+s,t+o),a.lineTo(e+s,t+n-o),a.quadraticCurveTo(e+s,t+n,e+s-o,t+n),a.lineTo(e+o,t+n),a.quadraticCurveTo(e,t+n,e,t+n-o),a.lineTo(e,t+o),a.quadraticCurveTo(e,t,e+o,t)}function oe(a,e){switch(e.type){case"rectangle":{const t=e;a.rect(t.x,t.y,t.width,t.height);break}case"roundedRectangle":{const t=e;Ct(a,t.x,t.y,t.width,t.height,t.radius);break}case"circle":{const t=e;a.arc(t.x,t.y,t.radius,0,Math.PI*2);break}case"ellipse":{const t=e;a.ellipse?a.ellipse(t.x,t.y,t.halfWidth,t.halfHeight,0,0,Math.PI*2):(a.save(),a.translate(t.x,t.y),a.scale(t.halfWidth,t.halfHeight),a.arc(0,0,1,0,Math.PI*2),a.restore());break}case"triangle":{const t=e;a.moveTo(t.x,t.y),a.lineTo(t.x2,t.y2),a.lineTo(t.x3,t.y3),a.closePath();break}case"polygon":default:{const t=e,s=t.points;if(!(s!=null&&s.length))break;a.moveTo(s[0],s[1]);for(let n=2;n<s.length;n+=2)a.lineTo(s[n],s[n+1]);t.closePath&&a.closePath();break}}}function Tt(a,e){if(!(e!=null&&e.length))return!1;for(let t=0;t<e.length;t++){const s=e[t];if(!(s!=null&&s.shape))continue;const n=s.transform,o=n&&!n.isIdentity();o&&(a.save(),a.transform(n.a,n.b,n.c,n.d,n.tx,n.ty)),oe(a,s.shape),o&&a.restore()}return!0}function Pt(a,e,t,s){const n=a.fill;if(n instanceof Je){n.buildGradient();const r=n.texture;if(r){const i=P.getTintedPattern(r,e),c=t?fe.copyFrom(t).scale(r.source.pixelWidth,r.source.pixelHeight):fe.copyFrom(n.transform);return s&&!a.textureSpace&&c.append(s),P.applyPatternTransform(i,c),i}}if(n instanceof Ke){const r=P.getTintedPattern(n.texture,e);return P.applyPatternTransform(r,n.transform),r}const o=a.texture;if(o&&o!==Ae.WHITE){if(!o.source.resource)return ft;const r=P.getTintedPattern(o,e),i=t?fe.copyFrom(t).scale(o.source.pixelWidth,o.source.pixelHeight):a.matrix;return P.applyPatternTransform(r,i),r}return xt(e)}class Ue{constructor(){this.shader=null}contextChange(e){}execute(e,t){var Y,q,E,k,C,V,z;const s=e.renderer,n=s.canvasContext,o=n.activeContext,r=t.groupTransform,i=((Y=s.globalUniforms.globalUniformData)==null?void 0:Y.worldColor)??4294967295,c=t.groupColorAlpha,u=(i>>>24&255)/255,m=(c>>>24&255)/255,x=((q=s.filter)==null?void 0:q.alphaMultiplier)??1,G=u*m*x;if(G<=0)return;const y=i&16777215,f=c&16777215,S=Me(ae(f,y)),v=s._roundPixels|t._roundPixels;o.save(),n.setContextTransform(r,v===1),n.setBlendMode(t.groupBlendMode);const A=t.context.instructions;for(let Z=0;Z<A.length;Z++){const J=A[Z];if(J.action==="texture"){const d=J.data,p=d.image,g=p?P.getCanvasSource(p):null;if(!g)continue;const L=d.alpha*G;if(L<=0)continue;const I=ae(d.style,S);o.globalAlpha=L;let _=g;I!==16777215&&(_=P.getTintedCanvas({texture:p},I));const W=p.frame,F=p.source._resolution??p.source.resolution??1;let B=W.x*F,H=W.y*F;const O=W.width*F,l=W.height*F;_!==g&&(B=0,H=0);const N=d.transform,j=N&&!N.isIdentity(),T=p.rotate;j||T?(ne.copyFrom(r),j&&ne.append(N),T&&Se.matrixAppendRotationInv(ne,T,d.dx,d.dy,d.dw,d.dh),n.setContextTransform(ne,v===1)):n.setContextTransform(r,v===1),o.drawImage(_,B,H,_===g?O:_.width,_===g?l:_.height,T?0:d.dx,T?0:d.dy,d.dw,d.dh),(j||T)&&n.setContextTransform(r,v===1);continue}const b=J.data,M=(E=b==null?void 0:b.path)==null?void 0:E.shapePath;if(!((k=M==null?void 0:M.shapePrimitives)!=null&&k.length))continue;const w=b.style,ie=ae(w.color,S),ee=w.alpha*G;if(ee<=0)continue;const D=J.action==="stroke";if(o.globalAlpha=ee,D){const d=w;o.lineWidth=d.width,o.lineCap=d.cap,o.lineJoin=d.join,o.miterLimit=d.miterLimit}const X=M.shapePrimitives;if(!D&&((z=(V=(C=b.hole)==null?void 0:C.shapePath)==null?void 0:V.shapePrimitives)!=null&&z.length)){const d=X[X.length-1];d.holes=b.hole.shapePath.shapePrimitives}for(let d=0;d<X.length;d++){const p=X[d];if(!(p!=null&&p.shape))continue;const g=p.transform,L=g&&!g.isIdentity(),I=w.texture&&w.texture!==Ae.WHITE,_=w.textureSpace==="global"?g:null,W=I?$e(gt,w,p.shape,_):null,F=L?vt.copyFrom(r).append(g):r,B=Pt(w,ie,W,F);if(L&&(o.save(),o.transform(g.a,g.b,g.c,g.d,g.tx,g.ty)),D){const H=w;if(H.alignment!==.5&&!H.pixelLine){const l=[],N=[],j=[],T=we[p.shape.type];if(T!=null&&T.build(p.shape,l)){const ve=p.shape.closePath??!0;Ie(l,H,!1,ve,N,j),o.fillStyle=B,yt(o,N,j)}else o.strokeStyle=B,o.beginPath(),oe(o,p.shape),o.stroke()}else o.strokeStyle=B,o.beginPath(),oe(o,p.shape),o.stroke()}else o.fillStyle=B,o.beginPath(),oe(o,p.shape),Tt(o,p.holes)?o.fill("evenodd"):o.fill();L&&o.restore()}}o.restore()}destroy(){this.shader=null}}Ue.extension={type:[R.CanvasPipesAdaptor],name:"graphics"};class kt{init(e,t){this._renderer=e,this._renderTargetSystem=t}initGpuRenderTarget(e){const t=e.colorTexture,{canvas:s,context:n}=this._ensureCanvas(t);return{canvas:s,context:n,width:s.width,height:s.height}}resizeGpuRenderTarget(e){const t=e.colorTexture,{canvas:s}=this._ensureCanvas(t);s.width=e.pixelWidth,s.height=e.pixelHeight}startRenderPass(e,t,s,n){const o=this._renderTargetSystem.getGpuRenderTarget(e);this._renderer.canvasContext.activeContext=o.context,this._renderer.canvasContext.activeResolution=e.resolution,t&&this.clear(e,t,s,n)}clear(e,t,s,n){const r=this._renderTargetSystem.getGpuRenderTarget(e).context,i=n||{x:0,y:0,width:e.pixelWidth,height:e.pixelHeight};if(r.setTransform(1,0,0,1,0,0),r.clearRect(i.x,i.y,i.width,i.height),s){const c=Re.shared.setValue(s);c.alpha>0&&(r.globalAlpha=c.alpha,r.fillStyle=c.toHex(),r.fillRect(i.x,i.y,i.width,i.height),r.globalAlpha=1)}}finishRenderPass(){}copyToTexture(e,t,s,n,o){const i=this._renderTargetSystem.getGpuRenderTarget(e).canvas,c=t.source,{context:u}=this._ensureCanvas(c),m=(o==null?void 0:o.x)??0,x=(o==null?void 0:o.y)??0;return u.drawImage(i,s.x,s.y,n.width,n.height,m,x,n.width,n.height),c.update(),t}destroyGpuRenderTarget(e){}_ensureCanvas(e){let t=e.resource;(!t||!Qe.test(t))&&(t=Be.get().createCanvas(e.pixelWidth,e.pixelHeight),e.resource=t),(t.width!==e.pixelWidth||t.height!==e.pixelHeight)&&(t.width=e.pixelWidth,t.height=e.pixelHeight);const s=t.getContext("2d");return{canvas:t,context:s}}}class qe extends et{constructor(e){super(e),this.adaptor=new kt,this.adaptor.init(e,this)}}qe.extension={type:[R.CanvasSystem],name:"renderTarget"};class De{constructor(e){}init(){}initSource(e){}generateCanvas(e){const t=Be.get().createCanvas(),s=t.getContext("2d"),n=P.getCanvasSource(e);if(!n)return t;const o=e.frame,r=e.source._resolution??e.source.resolution??1,i=o.x*r,c=o.y*r,u=o.width*r,m=o.height*r;return t.width=Math.ceil(u),t.height=Math.ceil(m),s.drawImage(n,i,c,u,m,0,0,u,m),t}getPixels(e){const t=this.generateCanvas(e);return{pixels:t.getContext("2d",{willReadFrequently:!0}).getImageData(0,0,t.width,t.height).data,width:t.width,height:t.height}}destroy(){}}De.extension={type:[R.CanvasSystem],name:"texture"};const bt=[...tt,We,Fe,De,qe],_t=[st,nt,at,ot,rt,Ee,He,it],St=[lt,Ue],Le=[],Oe=[],Ne=[];re.handleByNamedList(R.CanvasSystem,Le);re.handleByNamedList(R.CanvasPipes,Oe);re.handleByNamedList(R.CanvasPipesAdaptor,Ne);re.add(...bt,..._t,...St);class At extends ze{constructor(){const e={name:"canvas",type:Ze.CANVAS,systems:Le,renderPipes:Oe,renderPipeAdaptors:Ne};super(e)}}export{At as CanvasRenderer};
@@ -1 +0,0 @@
1
- import{v as n,x as o,q as u,o as f}from"./index-CINA8e_Z.js";const s=class i extends n{constructor(e){e={...i.defaultOptions,...e},super(e),this.enabled=!0,this._state=o.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),e.blendRequired&&this.addResource("uBackTexture",0,3)}apply(e,t,a,r){e.applyFilter(this,t,a,r)}get blendMode(){return this._state.blendMode}set blendMode(e){this._state.blendMode=e}static from(e){const{gpu:t,gl:a,...r}=e;let l,d;return t&&(l=u.from(t)),a&&(d=f.from(a)),new i({gpuProgram:l,glProgram:d,...r})}};s.defaultOptions={blendMode:"normal",resolution:1,padding:0,antialias:"off",blendRequired:!1,clipToViewport:!0};let b=s;export{b as F};
@@ -1,184 +0,0 @@
1
- import{z as Ve,Q as oe,M as m,q as Ne,o as je,x as $e,j as le,k as l,a4 as W,a as w,ab as qe,c as z,H as T,u as V,m as de,w as Ke,T as p,S as g,C as D,B as ue,ap as ce,s as ee,ag as he,O as fe,L as pe,U as me,i as P,J as Ye,h as O,D as N,I as y,R as B,ac as Je,P as Xe,Z as Qe,b as Ze,K as te,V as re,a3 as f,am as et,g as E,p as tt,ao as rt,t as st,y as nt}from"./index-CINA8e_Z.js";import{F as at}from"./Filter-ZZPoYeTC.js";var it=`in vec2 vMaskCoord;
2
- in vec2 vTextureCoord;
3
-
4
- uniform sampler2D uTexture;
5
- uniform sampler2D uMaskTexture;
6
-
7
- uniform float uAlpha;
8
- uniform vec4 uMaskClamp;
9
- uniform float uInverse;
10
- uniform float uChannel;
11
-
12
- out vec4 finalColor;
13
-
14
- void main(void)
15
- {
16
- float clip = step(3.5,
17
- step(uMaskClamp.x, vMaskCoord.x) +
18
- step(uMaskClamp.y, vMaskCoord.y) +
19
- step(vMaskCoord.x, uMaskClamp.z) +
20
- step(vMaskCoord.y, uMaskClamp.w));
21
-
22
- // TODO look into why this is needed
23
- float npmAlpha = uAlpha;
24
- vec4 original = texture(uTexture, vTextureCoord);
25
- vec4 masky = texture(uMaskTexture, vMaskCoord);
26
-
27
- float a;
28
- if (uChannel == 1.0) {
29
- a = masky.a * npmAlpha * clip;
30
- } else {
31
- float alphaMul = 1.0 - npmAlpha * (1.0 - masky.a);
32
- a = alphaMul * masky.r * npmAlpha * clip;
33
- }
34
-
35
- if (uInverse == 1.0) {
36
- a = 1.0 - a;
37
- }
38
-
39
- finalColor = original * a;
40
- }
41
- `,ot=`in vec2 aPosition;
42
-
43
- out vec2 vTextureCoord;
44
- out vec2 vMaskCoord;
45
-
46
-
47
- uniform vec4 uInputSize;
48
- uniform vec4 uOutputFrame;
49
- uniform vec4 uOutputTexture;
50
- uniform mat3 uFilterMatrix;
51
-
52
- vec4 filterVertexPosition( vec2 aPosition )
53
- {
54
- vec2 position = aPosition * uOutputFrame.zw + uOutputFrame.xy;
55
-
56
- position.x = position.x * (2.0 / uOutputTexture.x) - 1.0;
57
- position.y = position.y * (2.0*uOutputTexture.z / uOutputTexture.y) - uOutputTexture.z;
58
-
59
- return vec4(position, 0.0, 1.0);
60
- }
61
-
62
- vec2 filterTextureCoord( vec2 aPosition )
63
- {
64
- return aPosition * (uOutputFrame.zw * uInputSize.zw);
65
- }
66
-
67
- vec2 getFilterCoord( vec2 aPosition )
68
- {
69
- return ( uFilterMatrix * vec3( filterTextureCoord(aPosition), 1.0) ).xy;
70
- }
71
-
72
- void main(void)
73
- {
74
- gl_Position = filterVertexPosition(aPosition);
75
- vTextureCoord = filterTextureCoord(aPosition);
76
- vMaskCoord = getFilterCoord(aPosition);
77
- }
78
- `,se=`struct GlobalFilterUniforms {
79
- uInputSize:vec4<f32>,
80
- uInputPixel:vec4<f32>,
81
- uInputClamp:vec4<f32>,
82
- uOutputFrame:vec4<f32>,
83
- uGlobalFrame:vec4<f32>,
84
- uOutputTexture:vec4<f32>,
85
- };
86
-
87
- struct MaskUniforms {
88
- uFilterMatrix:mat3x3<f32>,
89
- uMaskClamp:vec4<f32>,
90
- uAlpha:f32,
91
- uInverse:f32,
92
- uChannel:f32,
93
- };
94
-
95
- @group(0) @binding(0) var<uniform> gfu: GlobalFilterUniforms;
96
- @group(0) @binding(1) var uTexture: texture_2d<f32>;
97
- @group(0) @binding(2) var uSampler : sampler;
98
-
99
- @group(1) @binding(0) var<uniform> filterUniforms : MaskUniforms;
100
- @group(1) @binding(1) var uMaskTexture: texture_2d<f32>;
101
-
102
- struct VSOutput {
103
- @builtin(position) position: vec4<f32>,
104
- @location(0) uv : vec2<f32>,
105
- @location(1) filterUv : vec2<f32>,
106
- };
107
-
108
- fn filterVertexPosition(aPosition:vec2<f32>) -> vec4<f32>
109
- {
110
- var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;
111
-
112
- position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;
113
- position.y = position.y * (2.0*gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;
114
-
115
- return vec4(position, 0.0, 1.0);
116
- }
117
-
118
- fn filterTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
119
- {
120
- return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);
121
- }
122
-
123
- fn globalTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
124
- {
125
- return (aPosition.xy / gfu.uGlobalFrame.zw) + (gfu.uGlobalFrame.xy / gfu.uGlobalFrame.zw);
126
- }
127
-
128
- fn getFilterCoord(aPosition:vec2<f32> ) -> vec2<f32>
129
- {
130
- return ( filterUniforms.uFilterMatrix * vec3( filterTextureCoord(aPosition), 1.0) ).xy;
131
- }
132
-
133
- fn getSize() -> vec2<f32>
134
- {
135
- return gfu.uGlobalFrame.zw;
136
- }
137
-
138
- @vertex
139
- fn mainVertex(
140
- @location(0) aPosition : vec2<f32>,
141
- ) -> VSOutput {
142
- return VSOutput(
143
- filterVertexPosition(aPosition),
144
- filterTextureCoord(aPosition),
145
- getFilterCoord(aPosition)
146
- );
147
- }
148
-
149
- @fragment
150
- fn mainFragment(
151
- @location(0) uv: vec2<f32>,
152
- @location(1) filterUv: vec2<f32>,
153
- @builtin(position) position: vec4<f32>
154
- ) -> @location(0) vec4<f32> {
155
-
156
- var maskClamp = filterUniforms.uMaskClamp;
157
- var uAlpha = filterUniforms.uAlpha;
158
-
159
- var clip = step(3.5,
160
- step(maskClamp.x, filterUv.x) +
161
- step(maskClamp.y, filterUv.y) +
162
- step(filterUv.x, maskClamp.z) +
163
- step(filterUv.y, maskClamp.w));
164
-
165
- var mask = textureSample(uMaskTexture, uSampler, filterUv);
166
- var source = textureSample(uTexture, uSampler, uv);
167
-
168
- var a: f32;
169
- if (filterUniforms.uChannel == 1.0) {
170
- a = mask.a * uAlpha * clip;
171
- } else {
172
- var alphaMul = 1.0 - uAlpha * (1.0 - mask.a);
173
- a = alphaMul * mask.r * uAlpha * clip;
174
- }
175
-
176
- if (filterUniforms.uInverse == 1.0) {
177
- a = 1.0 - a;
178
- }
179
-
180
- return source * a;
181
- }
182
- `;class lt extends at{constructor(e){const{sprite:t,...r}=e,s=new Ve(t.texture),n=new oe({uFilterMatrix:{value:new m,type:"mat3x3<f32>"},uMaskClamp:{value:s.uClampFrame,type:"vec4<f32>"},uAlpha:{value:1,type:"f32"},uInverse:{value:e.inverse?1:0,type:"f32"},uChannel:{value:e.channel==="alpha"?1:0,type:"f32"}}),i=Ne.from({vertex:{source:se,entryPoint:"mainVertex"},fragment:{source:se,entryPoint:"mainFragment"}}),o=je.from({vertex:ot,fragment:it,name:"mask-filter"});super({...r,gpuProgram:i,glProgram:o,clipToViewport:!1,resources:{filterUniforms:n,uMaskTexture:t.texture.source}}),this.sprite=t,this._textureMatrix=s}set inverse(e){this.resources.filterUniforms.uniforms.uInverse=e?1:0}get inverse(){return this.resources.filterUniforms.uniforms.uInverse===1}set channel(e){this.resources.filterUniforms.uniforms.uChannel=e==="alpha"?1:0}get channel(){return this.resources.filterUniforms.uniforms.uChannel===1?"alpha":"red"}apply(e,t,r,s){this._textureMatrix.texture=this.sprite.texture,e.calculateSpriteMatrix(this.resources.filterUniforms.uniforms.uFilterMatrix,this.sprite).prepend(this._textureMatrix.mapCoord),this.resources.uMaskTexture=this.sprite.texture.source,e.applyFilter(this,t,r,s)}}const j=class ge{constructor(e,t){var r,s;this.state=$e.for2d(),this._batchersByInstructionSet=Object.create(null),this._activeBatches=Object.create(null),this.renderer=e,this._adaptor=t,(s=(r=this._adaptor).init)==null||s.call(r,this)}static getBatcher(e){return new this._availableBatchers[e]}buildStart(e){let t=this._batchersByInstructionSet[e.uid];t||(t=this._batchersByInstructionSet[e.uid]=Object.create(null),t.default||(t.default=new le({maxTextures:this.renderer.limits.maxBatchableTextures}))),this._activeBatches=t,this._activeBatch=this._activeBatches.default;for(const r in this._activeBatches)this._activeBatches[r].begin()}addToBatch(e,t){if(this._activeBatch.name!==e.batcherName){this._activeBatch.break(t);let r=this._activeBatches[e.batcherName];r||(r=this._activeBatches[e.batcherName]=ge.getBatcher(e.batcherName),r.begin()),this._activeBatch=r}this._activeBatch.add(e)}break(e){this._activeBatch.break(e)}buildEnd(e){this._activeBatch.break(e);const t=this._activeBatches;for(const r in t){const s=t[r],n=s.geometry;n.indexBuffer.setDataWithSize(s.indexBuffer,s.indexSize,!0),n.buffers[0].setDataWithSize(s.attributeBuffer.float32View,s.attributeSize,!1)}}upload(e){const t=this._batchersByInstructionSet[e.uid];for(const r in t){const s=t[r],n=s.geometry;s.dirty&&(s.dirty=!1,n.buffers[0].update(s.attributeSize*4))}}execute(e){if(e.action==="startBatch"){const t=e.batcher,r=t.geometry,s=t.shader;this._adaptor.start(this,r,s)}this._adaptor.execute(this,e)}destroy(){this.state=null,this.renderer=null,this._adaptor=null;for(const e in this._activeBatches)this._activeBatches[e].destroy();this._activeBatches=null}};j.extension={type:[l.WebGLPipes,l.WebGPUPipes,l.CanvasPipes],name:"batch"};j._availableBatchers=Object.create(null);let _e=j;W.handleByMap(l.Batcher,_e._availableBatchers);W.add(le);const dt=new z;class ut extends de{constructor(){super(),this.filters=[new lt({sprite:new Ke(p.EMPTY),inverse:!1,resolution:"inherit",antialias:"inherit"})]}get sprite(){return this.filters[0].sprite}set sprite(e){this.filters[0].sprite=e}get inverse(){return this.filters[0].inverse}set inverse(e){this.filters[0].inverse=e}get channel(){return this.filters[0].channel}set channel(e){this.filters[0].channel=e}}class xe{constructor(e){this._activeMaskStage=[],this._renderer=e}push(e,t,r){const s=this._renderer;if(s.renderPipes.batch.break(r),r.add({renderPipeId:"alphaMask",action:"pushMaskBegin",mask:e,inverse:t._maskOptions.inverse,canBundle:!1,maskedContainer:t}),e.inverse=t._maskOptions.inverse,e.channel=t._maskOptions.channel??"red",e.renderMaskToTexture){const n=e.mask;n.includeInBuild=!0,n.collectRenderables(r,s,null),n.includeInBuild=!1}s.renderPipes.batch.break(r),r.add({renderPipeId:"alphaMask",action:"pushMaskEnd",mask:e,maskedContainer:t,inverse:t._maskOptions.inverse,canBundle:!1})}pop(e,t,r){this._renderer.renderPipes.batch.break(r),r.add({renderPipeId:"alphaMask",action:"popMaskEnd",mask:e,inverse:t._maskOptions.inverse,canBundle:!1})}execute(e){const t=this._renderer,r=e.mask.renderMaskToTexture;if(e.action==="pushMaskBegin"){const s=w.get(ut);if(s.inverse=e.inverse,s.channel=e.mask.channel,r){e.mask.mask.measurable=!0;const n=qe(e.mask.mask,!0,dt);e.mask.mask.measurable=!1,n.ceil();const i=t.renderTarget.renderTarget.colorTexture.source,o=T.getOptimalTexture(n.width,n.height,i._resolution,i.antialias);t.renderTarget.push(o,!0),t.globalUniforms.push({offset:n,worldColor:4294967295});const d=s.sprite;d.texture=o,d.worldTransform.tx=n.minX,d.worldTransform.ty=n.minY,this._activeMaskStage.push({filterEffect:s,maskedContainer:e.maskedContainer,filterTexture:o})}else s.sprite=e.mask.mask,this._activeMaskStage.push({filterEffect:s,maskedContainer:e.maskedContainer})}else if(e.action==="pushMaskEnd"){const s=this._activeMaskStage[this._activeMaskStage.length-1];r&&(t.type===V.WEBGL&&t.renderTarget.finishRenderPass(),t.renderTarget.pop(),t.globalUniforms.pop()),t.filter.push({renderPipeId:"filter",action:"pushFilter",container:s.maskedContainer,filterEffect:s.filterEffect,canBundle:!1})}else if(e.action==="popMaskEnd"){t.filter.pop();const s=this._activeMaskStage.pop();r&&T.returnTexture(s.filterTexture),w.return(s.filterEffect)}}destroy(){this._renderer=null,this._activeMaskStage=null}}xe.extension={type:[l.WebGLPipes,l.WebGPUPipes,l.CanvasPipes],name:"alphaMask"};class be{constructor(e){this._colorStack=[],this._colorStackIndex=0,this._currentColor=0,this._renderer=e}buildStart(){this._colorStack[0]=15,this._colorStackIndex=1,this._currentColor=15}push(e,t,r){this._renderer.renderPipes.batch.break(r);const n=this._colorStack;n[this._colorStackIndex]=n[this._colorStackIndex-1]&e.mask;const i=this._colorStack[this._colorStackIndex];i!==this._currentColor&&(this._currentColor=i,r.add({renderPipeId:"colorMask",colorMask:i,canBundle:!1})),this._colorStackIndex++}pop(e,t,r){this._renderer.renderPipes.batch.break(r);const n=this._colorStack;this._colorStackIndex--;const i=n[this._colorStackIndex-1];i!==this._currentColor&&(this._currentColor=i,r.add({renderPipeId:"colorMask",colorMask:i,canBundle:!1}))}execute(e){this._renderer.colorMask.setMask(e.colorMask)}destroy(){this._renderer=null,this._colorStack=null}}be.extension={type:[l.WebGLPipes,l.WebGPUPipes],name:"colorMask"};class Te{constructor(e){this._maskStackHash={},this._maskHash=new WeakMap,this._renderer=e}push(e,t,r){var s;const n=e,i=this._renderer;i.renderPipes.batch.break(r),i.renderPipes.blendMode.setBlendMode(n.mask,"none",r),r.add({renderPipeId:"stencilMask",action:"pushMaskBegin",mask:e,inverse:t._maskOptions.inverse,canBundle:!1});const o=n.mask;o.includeInBuild=!0,this._maskHash.has(n)||this._maskHash.set(n,{instructionsStart:0,instructionsLength:0});const d=this._maskHash.get(n);d.instructionsStart=r.instructionSize,o.collectRenderables(r,i,null),o.includeInBuild=!1,i.renderPipes.batch.break(r),r.add({renderPipeId:"stencilMask",action:"pushMaskEnd",mask:e,inverse:t._maskOptions.inverse,canBundle:!1});const h=r.instructionSize-d.instructionsStart-1;d.instructionsLength=h;const c=i.renderTarget.renderTarget.uid;(s=this._maskStackHash)[c]??(s[c]=0)}pop(e,t,r){const s=e,n=this._renderer;n.renderPipes.batch.break(r),n.renderPipes.blendMode.setBlendMode(s.mask,"none",r),r.add({renderPipeId:"stencilMask",action:"popMaskBegin",inverse:t._maskOptions.inverse,canBundle:!1});const i=this._maskHash.get(e);for(let o=0;o<i.instructionsLength;o++)r.instructions[r.instructionSize++]=r.instructions[i.instructionsStart++];r.add({renderPipeId:"stencilMask",action:"popMaskEnd",canBundle:!1})}execute(e){var t;const r=this._renderer,s=r,n=r.renderTarget.renderTarget.uid;let i=(t=this._maskStackHash)[n]??(t[n]=0);e.action==="pushMaskBegin"?(s.renderTarget.ensureDepthStencil(),s.stencil.setStencilMode(g.RENDERING_MASK_ADD,i),i++,s.colorMask.setMask(0)):e.action==="pushMaskEnd"?(e.inverse?s.stencil.setStencilMode(g.INVERSE_MASK_ACTIVE,i):s.stencil.setStencilMode(g.MASK_ACTIVE,i),s.colorMask.setMask(15)):e.action==="popMaskBegin"?(s.colorMask.setMask(0),i!==0?s.stencil.setStencilMode(g.RENDERING_MASK_REMOVE,i):(s.renderTarget.clear(null,D.STENCIL),s.stencil.setStencilMode(g.DISABLED,i)),i--):e.action==="popMaskEnd"&&(e.inverse?s.stencil.setStencilMode(g.INVERSE_MASK_ACTIVE,i):s.stencil.setStencilMode(g.MASK_ACTIVE,i),s.colorMask.setMask(15)),this._maskStackHash[n]=i}destroy(){this._renderer=null,this._maskStackHash=null,this._maskHash=null}}Te.extension={type:[l.WebGLPipes,l.WebGPUPipes],name:"stencilMask"};class ye{constructor(e){this._renderer=e}updateRenderable(){}destroyRenderable(){}validateRenderable(){return!1}addRenderable(e,t){this._renderer.renderPipes.batch.break(t),t.add(e)}execute(e){e.isRenderable&&e.render(this._renderer)}destroy(){this._renderer=null}}ye.extension={type:[l.WebGLPipes,l.WebGPUPipes,l.CanvasPipes],name:"customRender"};function L(a,e){const t=a.instructionSet,r=t.instructions;for(let s=0;s<t.instructionSize;s++){const n=r[s];e[n.renderPipeId].execute(n)}}class ve{constructor(e){this._renderer=e}addRenderGroup(e,t){e.isCachedAsTexture?this._addRenderableCacheAsTexture(e,t):this._addRenderableDirect(e,t)}execute(e){e.isRenderable&&(e.isCachedAsTexture?this._executeCacheAsTexture(e):this._executeDirect(e))}destroy(){this._renderer=null}_addRenderableDirect(e,t){this._renderer.renderPipes.batch.break(t),e._batchableRenderGroup&&(w.return(e._batchableRenderGroup),e._batchableRenderGroup=null),t.add(e)}_addRenderableCacheAsTexture(e,t){const r=e._batchableRenderGroup??(e._batchableRenderGroup=w.get(ue));r.renderable=e.root,r.transform=e.root.relativeGroupTransform,r.texture=e.texture,r.bounds=e._textureBounds,t.add(e),this._renderer.renderPipes.blendMode.pushBlendMode(e,e.root.groupBlendMode,t),this._renderer.renderPipes.batch.addToBatch(r,t),this._renderer.renderPipes.blendMode.popBlendMode(t)}_executeCacheAsTexture(e){if(e.textureNeedsUpdate){e.textureNeedsUpdate=!1;const t=new m().translate(-e._textureBounds.x,-e._textureBounds.y);this._renderer.renderTarget.push(e.texture,!0,null,e.texture.frame),this._renderer.globalUniforms.push({worldTransformMatrix:t,worldColor:4294967295,offset:{x:0,y:0}}),L(e,this._renderer.renderPipes),this._renderer.renderTarget.finishRenderPass(),this._renderer.renderTarget.pop(),this._renderer.globalUniforms.pop()}e._batchableRenderGroup._batcher.updateElement(e._batchableRenderGroup),e._batchableRenderGroup._batcher.geometry.buffers[0].update()}_executeDirect(e){this._renderer.globalUniforms.push({worldTransformMatrix:e.inverseParentTextureTransform,worldColor:e.worldColorAlpha}),L(e,this._renderer.renderPipes),this._renderer.globalUniforms.pop()}}ve.extension={type:[l.WebGLPipes,l.WebGPUPipes,l.CanvasPipes],name:"renderGroup"};class Ce{constructor(e){this._renderer=e}addRenderable(e,t){const r=this._getGpuSprite(e);e.didViewUpdate&&this._updateBatchableSprite(e,r),this._renderer.renderPipes.batch.addToBatch(r,t)}updateRenderable(e){const t=this._getGpuSprite(e);e.didViewUpdate&&this._updateBatchableSprite(e,t),t._batcher.updateElement(t)}validateRenderable(e){const t=this._getGpuSprite(e);return!t._batcher.checkAndUpdateTexture(t,e._texture)}_updateBatchableSprite(e,t){t.bounds=e.visualBounds,t.texture=e._texture}_getGpuSprite(e){return e._gpuData[this._renderer.uid]||this._initGPUSprite(e)}_initGPUSprite(e){const t=new ue;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}destroy(){this._renderer=null}}Ce.extension={type:[l.WebGLPipes,l.WebGPUPipes,l.CanvasPipes],name:"sprite"};const v={};W.handle(l.BlendMode,a=>{if(!a.name)throw new Error("BlendMode extension must have a name property");v[a.name]=a.ref},a=>{delete v[a.name]});class ke{constructor(e){this._blendModeStack=[],this._isAdvanced=!1,this._filterHash=Object.create(null),this._renderer=e,this._renderer.runners.prerender.add(this)}prerender(){this._activeBlendMode="normal",this._isAdvanced=!1}pushBlendMode(e,t,r){this._blendModeStack.push(t),this.setBlendMode(e,t,r)}popBlendMode(e){this._blendModeStack.pop();const t=this._blendModeStack[this._activeBlendMode.length-1]??"normal";this.setBlendMode(null,t,e)}setBlendMode(e,t,r){var n;const s=e instanceof ee;if(this._activeBlendMode===t){this._isAdvanced&&e&&!s&&((n=this._renderableList)==null||n.push(e));return}this._isAdvanced&&this._endAdvancedBlendMode(r),this._activeBlendMode=t,e&&(this._isAdvanced=!!v[t],this._isAdvanced&&this._beginAdvancedBlendMode(e,r))}_beginAdvancedBlendMode(e,t){this._renderer.renderPipes.batch.break(t);const r=this._activeBlendMode;if(!v[r]){ce(`Unable to assign BlendMode: '${r}'. You may want to include: import 'pixi.js/advanced-blend-modes'`);return}const s=this._ensureFilterEffect(r),n=e instanceof ee,i={renderPipeId:"filter",action:"pushFilter",filterEffect:s,renderables:n?null:[e],container:n?e.root:null,canBundle:!1};this._renderableList=i.renderables,t.add(i)}_ensureFilterEffect(e){let t=this._filterHash[e];return t||(t=this._filterHash[e]=new de,t.filters=[new v[e]]),t}_endAdvancedBlendMode(e){this._isAdvanced=!1,this._renderableList=null,this._renderer.renderPipes.batch.break(e),e.add({renderPipeId:"filter",action:"popFilter",canBundle:!1})}buildStart(){this._isAdvanced=!1}buildEnd(e){this._isAdvanced&&this._endAdvancedBlendMode(e)}destroy(){this._renderer=null,this._renderableList=null;for(const e in this._filterHash)this._filterHash[e].destroy();this._filterHash=null}}ke.extension={type:[l.WebGLPipes,l.WebGPUPipes,l.CanvasPipes],name:"blendMode"};function H(a,e){e||(e=0);for(let t=e;t<a.length&&a[t];t++)a[t]=null}const ct=new P,ne=fe|pe|me;function Me(a,e=!1){ht(a);const t=a.childrenToUpdate,r=a.updateTick++;for(const s in t){const n=Number(s),i=t[s],o=i.list,d=i.index;for(let h=0;h<d;h++){const c=o[h];c.parentRenderGroup===a&&c.relativeRenderGroupDepth===n&&Re(c,r,0)}H(o,d),i.index=0}if(e)for(let s=0;s<a.renderGroupChildren.length;s++)Me(a.renderGroupChildren[s],e)}function ht(a){const e=a.root;let t;if(a.renderGroupParent){const r=a.renderGroupParent;a.worldTransform.appendFrom(e.relativeGroupTransform,r.worldTransform),a.worldColor=he(e.groupColor,r.worldColor),t=e.groupAlpha*r.worldAlpha}else a.worldTransform.copyFrom(e.localTransform),a.worldColor=e.localColor,t=e.localAlpha;t=t<0?0:t>1?1:t,a.worldAlpha=t,a.worldColorAlpha=a.worldColor+((t*255|0)<<24)}function Re(a,e,t){if(e===a.updateTick)return;a.updateTick=e,a.didChange=!1;const r=a.localTransform;a.updateLocalTransform();const s=a.parent;if(s&&!s.renderGroup?(t|=a._updateFlags,a.relativeGroupTransform.appendFrom(r,s.relativeGroupTransform),t&ne&&ae(a,s,t)):(t=a._updateFlags,a.relativeGroupTransform.copyFrom(r),t&ne&&ae(a,ct,t)),!a.renderGroup){const n=a.children,i=n.length;for(let h=0;h<i;h++)Re(n[h],e,t);const o=a.parentRenderGroup,d=a;d.renderPipeId&&!o.structureDidChange&&o.updateRenderable(d)}}function ae(a,e,t){if(t&pe){a.groupColor=he(a.localColor,e.groupColor);let r=a.localAlpha*e.groupAlpha;r=r<0?0:r>1?1:r,a.groupAlpha=r,a.groupColorAlpha=a.groupColor+((r*255|0)<<24)}t&me&&(a.groupBlendMode=a.localBlendMode==="inherit"?e.groupBlendMode:a.localBlendMode),t&fe&&(a.globalDisplayStatus=a.localDisplayStatus&e.globalDisplayStatus),a._updateFlags=0}function ft(a,e){const{list:t}=a.childrenRenderablesToUpdate;let r=!1;for(let s=0;s<a.childrenRenderablesToUpdate.index;s++){const n=t[s];if(r=e[n.renderPipeId].validateRenderable(n),r)break}return a.structureDidChange=r,r}const pt=new m;class Se{constructor(e){this._renderer=e}render({container:e,transform:t}){const r=e.parent,s=e.renderGroup.renderGroupParent;e.parent=null,e.renderGroup.renderGroupParent=null;const n=this._renderer,i=pt;t&&(i.copyFrom(e.renderGroup.localTransform),e.renderGroup.localTransform.copyFrom(t));const o=n.renderPipes;this._updateCachedRenderGroups(e.renderGroup,null),this._updateRenderGroups(e.renderGroup),n.globalUniforms.start({worldTransformMatrix:t?e.renderGroup.localTransform:e.renderGroup.worldTransform,worldColor:e.renderGroup.worldColorAlpha}),L(e.renderGroup,o),o.uniformBatch&&o.uniformBatch.renderEnd(),t&&e.renderGroup.localTransform.copyFrom(i),e.parent=r,e.renderGroup.renderGroupParent=s}destroy(){this._renderer=null}_updateCachedRenderGroups(e,t){if(e._parentCacheAsTextureRenderGroup=t,e.isCachedAsTexture){if(!e.textureNeedsUpdate)return;t=e}for(let r=e.renderGroupChildren.length-1;r>=0;r--)this._updateCachedRenderGroups(e.renderGroupChildren[r],t);if(e.invalidateMatrices(),e.isCachedAsTexture){if(e.textureNeedsUpdate){const r=e.root.getLocalBounds(),s=this._renderer,n=e.textureOptions.resolution||s.view.resolution,i=e.textureOptions.antialias??s.view.antialias,o=e.textureOptions.scaleMode??"linear",d=e.texture;r.ceil(),e.texture&&T.returnTexture(e.texture,!0);const h=T.getOptimalTexture(r.width,r.height,n,i);h._source.style=new Ye({scaleMode:o}),e.texture=h,e._textureBounds||(e._textureBounds=new z),e._textureBounds.copyFrom(r),d!==e.texture&&e.renderGroupParent&&(e.renderGroupParent.structureDidChange=!0)}}else e.texture&&(T.returnTexture(e.texture,!0),e.texture=null)}_updateRenderGroups(e){const t=this._renderer,r=t.renderPipes;if(e.runOnRender(t),e.instructionSet.renderPipes=r,e.structureDidChange?H(e.childrenRenderablesToUpdate.list,0):ft(e,r),Me(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))for(let s=0;s<e.renderGroupChildren.length;s++)this._updateRenderGroups(e.renderGroupChildren[s])}_updateRenderables(e){const{list:t,index:r}=e.childrenRenderablesToUpdate;for(let s=0;s<r;s++){const n=t[s];n.didViewUpdate&&e.updateRenderable(n)}H(t,r)}_buildInstructions(e,t){const r=e.root,s=e.instructionSet;s.reset();const n=t.renderPipes?t:t.batch.renderer,i=n.renderPipes;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)}}Se.extension={type:[l.WebGLSystem,l.WebGPUSystem,l.CanvasSystem],name:"renderGroup"};const $=class we{constructor(){this.clearBeforeRender=!0,this._backgroundColor=new O(0),this.color=this._backgroundColor,this.alpha=1}init(e){e={...we.defaultOptions,...e},this.clearBeforeRender=e.clearBeforeRender,this.color=e.background||e.backgroundColor||this._backgroundColor,this.alpha=e.backgroundAlpha,this._backgroundColor.setAlpha(e.backgroundAlpha)}get color(){return this._backgroundColor}set color(e){O.shared.setValue(e).alpha<1&&this._backgroundColor.alpha===1&&ce("Cannot set a transparent background on an opaque canvas. To enable transparency, set backgroundAlpha < 1 when initializing your Application."),this._backgroundColor.setValue(e)}get alpha(){return this._backgroundColor.alpha}set alpha(e){this._backgroundColor.setAlpha(e)}get colorRgba(){return this._backgroundColor.toArray()}destroy(){}};$.extension={type:[l.WebGLSystem,l.WebGPUSystem,l.CanvasSystem],name:"background",priority:0};$.defaultOptions={backgroundAlpha:1,backgroundColor:0,clearBeforeRender:!0};let mt=$;const I={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},q=class Pe{constructor(e){this._renderer=e}_normalizeOptions(e,t={}){return e instanceof P||e instanceof p?{target:e,...t}:{...t,...e}}async image(e){const t=N.get().createImage();return t.src=await this.base64(e),t}async base64(e){e=this._normalizeOptions(e,Pe.defaultImageOptions);const{format:t,quality:r}=e,s=this.canvas(e);if(s.toBlob!==void 0)return new Promise((n,i)=>{s.toBlob(o=>{if(!o){i(new Error("ICanvas.toBlob failed!"));return}const d=new FileReader;d.onload=()=>n(d.result),d.onerror=i,d.readAsDataURL(o)},I[t],r)});if(s.toDataURL!==void 0)return s.toDataURL(I[t],r);if(s.convertToBlob!==void 0){const n=await s.convertToBlob({type:I[t],quality:r});return new Promise((i,o)=>{const d=new FileReader;d.onload=()=>i(d.result),d.onerror=o,d.readAsDataURL(n)})}throw new Error("Extract.base64() requires ICanvas.toDataURL, ICanvas.toBlob, or ICanvas.convertToBlob to be implemented")}canvas(e){e=this._normalizeOptions(e);const t=e.target,r=this._renderer;if(t instanceof p)return r.texture.generateCanvas(t);const s=r.textureGenerator.generateTexture(e),n=r.texture.generateCanvas(s);return s.destroy(!0),n}pixels(e){e=this._normalizeOptions(e);const t=e.target,r=this._renderer,s=t instanceof p?t:r.textureGenerator.generateTexture(e),n=r.texture.getPixels(s);return t instanceof P&&s.destroy(!0),n}texture(e){return e=this._normalizeOptions(e),e.target instanceof p?e.target:this._renderer.textureGenerator.generateTexture(e)}download(e){e=this._normalizeOptions(e);const t=this.canvas(e),r=document.createElement("a");r.download=e.filename??"image.png",r.href=t.toDataURL("image/png"),document.body.appendChild(r),r.click(),document.body.removeChild(r)}log(e){const t=e.width??200;e=this._normalizeOptions(e);const r=this.canvas(e),s=r.toDataURL();console.log(`[Pixi Texture] ${r.width}px ${r.height}px`);const n=["font-size: 1px;",`padding: ${t}px 300px;`,`background: url(${s}) no-repeat;`,"background-size: contain;"].join(" ");console.log("%c ",n)}destroy(){this._renderer=null}};q.extension={type:[l.WebGLSystem,l.WebGPUSystem,l.CanvasSystem],name:"extract"};q.defaultImageOptions={format:"png",quality:1};let gt=q;class K extends p{static create(e){const{dynamic:t,textureOptions:r,...s}=e;return new K({...r,source:new y(s),dynamic:t??!1})}resize(e,t,r){return this.source.resize(e,t,r),this}}const _t=new B,xt=new z,bt=[0,0,0,0];class Be{constructor(e){this._renderer=e}generateTexture(e){var c;e instanceof P&&(e={target:e,frame:void 0,textureSourceOptions:{},resolution:void 0});const t=e.resolution||this._renderer.resolution,r=e.antialias||this._renderer.view.antialias,s=e.target;let n=e.clearColor;n?n=Array.isArray(n)&&n.length===4?n:O.shared.setValue(n).toArray():n=bt;const i=((c=e.frame)==null?void 0:c.copyTo(_t))||Je(s,xt).rectangle,o=e.defaultAnchor&&{defaultAnchor:e.defaultAnchor};i.width=Math.max(i.width,1/t)|0,i.height=Math.max(i.height,1/t)|0;const d=K.create({...e.textureSourceOptions,width:i.width,height:i.height,resolution:t,antialias:r,textureOptions:o}),h=m.shared.translate(-i.x,-i.y);return this._renderer.render({container:s,transform:h,target:d,clearColor:n}),d.source.updateMipmaps(),d}destroy(){this._renderer=null}}Be.extension={type:[l.WebGLSystem,l.WebGPUSystem,l.CanvasSystem],name:"textureGenerator"};function Tt(a){let e=!1;for(const r in a)if(a[r]==null){e=!0;break}if(!e)return a;const t=Object.create(null);for(const r in a){const s=a[r];s&&(t[r]=s)}return t}function yt(a){let e=0;for(let t=0;t<a.length;t++)a[t]==null?e++:a[t-e]=a[t];return a.length-=e,a}const Y=class Ge{constructor(e){this._managedResources=[],this._managedResourceHashes=[],this._managedCollections=[],this._ready=!1,this._renderer=e}init(e){e={...Ge.defaultOptions,...e},this.maxUnusedTime=e.gcMaxUnusedTime,this._frequency=e.gcFrequency,this.enabled=e.gcActive,this.now=performance.now()}get enabled(){return!!this._handler}set enabled(e){this.enabled!==e&&(e?(this._handler=this._renderer.scheduler.repeat(()=>{this._ready=!0},this._frequency,!1),this._collectionsHandler=this._renderer.scheduler.repeat(()=>{for(const t of this._managedCollections){const{context:r,collection:s,type:n}=t;n==="hash"?r[s]=Tt(r[s]):r[s]=yt(r[s])}},this._frequency)):(this._renderer.scheduler.cancel(this._handler),this._renderer.scheduler.cancel(this._collectionsHandler),this._handler=0,this._collectionsHandler=0))}prerender({container:e}){this.now=performance.now(),e.renderGroup.gcTick=this._renderer.tick++,this._updateInstructionGCTick(e.renderGroup,e.renderGroup.gcTick)}postrender(){!this._ready||!this.enabled||(this.run(),this._ready=!1)}_updateInstructionGCTick(e,t){e.instructionSet.gcTick=t,e.gcTick=t;for(const r of e.renderGroupChildren)this._updateInstructionGCTick(r,t)}addCollection(e,t,r){this._managedCollections.push({context:e,collection:t,type:r})}addResource(e,t){var s,n;if(e._gcLastUsed!==-1){e._gcLastUsed=this.now,(s=e._onTouch)==null||s.call(e,this.now);return}const r=this._managedResources.length;e._gcData={index:r,type:t},e._gcLastUsed=this.now,(n=e._onTouch)==null||n.call(e,this.now),e.once("unload",this.removeResource,this),this._managedResources.push(e)}removeResource(e){const t=e._gcData;if(!t)return;const r=t.index,s=this._managedResources.length-1;if(r!==s){const n=this._managedResources[s];this._managedResources[r]=n,n._gcData.index=r}this._managedResources.length--,e._gcData=null,e._gcLastUsed=-1}addResourceHash(e,t,r,s=0){this._managedResourceHashes.push({context:e,hash:t,type:r,priority:s}),this._managedResourceHashes.sort((n,i)=>n.priority-i.priority)}run(){const e=performance.now(),t=this._managedResourceHashes;for(const s of t)this.runOnHash(s,e);let r=0;for(let s=0;s<this._managedResources.length;s++){const n=this._managedResources[s];r=this.runOnResource(n,e,r)}this._managedResources.length=r}updateRenderableGCTick(e,t){var n,i;const r=e.renderGroup??e.parentRenderGroup,s=((n=r==null?void 0:r.instructionSet)==null?void 0:n.gcTick)??-1;((r==null?void 0:r.gcTick)??0)===s&&(e._gcLastUsed=t,(i=e._onTouch)==null||i.call(e,t))}runOnResource(e,t,r){const s=e._gcData;return s.type==="renderable"&&this.updateRenderableGCTick(e,t),t-e._gcLastUsed<this.maxUnusedTime||!e.autoGarbageCollect?(this._managedResources[r]=e,s.index=r,r++):(e.unload(),e._gcData=null,e._gcLastUsed=-1,e.off("unload",this.removeResource,this)),r}_createHashClone(e,t){const r=Object.create(null);for(const s in e){if(s===t)break;e[s]!==null&&(r[s]=e[s])}return r}runOnHash(e,t){var h;const{context:r,hash:s,type:n}=e,i=r[s];let o=null,d=0;for(const c in i){const u=i[c];if(u===null){d++,d===1e4&&!o&&(o=this._createHashClone(i,c));continue}if(u._gcLastUsed===-1){u._gcLastUsed=t,(h=u._onTouch)==null||h.call(u,t),o&&(o[c]=u);continue}if(n==="renderable"&&this.updateRenderableGCTick(u,t),!(t-u._gcLastUsed<this.maxUnusedTime)&&u.autoGarbageCollect){if(o||(d+1!==1e4?(i[c]=null,d++):o=this._createHashClone(i,c)),n==="renderable"){const _=u,x=_.renderGroup??_.parentRenderGroup;x&&(x.structureDidChange=!0)}u.unload(),u._gcData=null,u._gcLastUsed=-1}else o&&(o[c]=u)}o&&(r[s]=o)}destroy(){this.enabled=!1,this._managedResources.forEach(e=>{e.off("unload",this.removeResource,this)}),this._managedResources.length=0,this._managedResourceHashes.length=0,this._managedCollections.length=0,this._renderer=null}};Y.extension={type:[l.WebGLSystem,l.WebGPUSystem,l.CanvasSystem],name:"gc",priority:0};Y.defaultOptions={gcActive:!0,gcMaxUnusedTime:6e4,gcFrequency:3e4};let vt=Y;class Ue{constructor(e){this._stackIndex=0,this._globalUniformDataStack=[],this._uniformsPool=[],this._activeUniforms=[],this._bindGroupPool=[],this._activeBindGroups=[],this._renderer=e}reset(){this._stackIndex=0;for(let e=0;e<this._activeUniforms.length;e++)this._uniformsPool.push(this._activeUniforms[e]);for(let e=0;e<this._activeBindGroups.length;e++)this._bindGroupPool.push(this._activeBindGroups[e]);this._activeUniforms.length=0,this._activeBindGroups.length=0}start(e){this.reset(),this.push(e)}bind({size:e,projectionMatrix:t,worldTransformMatrix:r,worldColor:s,offset:n}){const i=this._renderer.renderTarget.renderTarget,o=this._stackIndex?this._globalUniformDataStack[this._stackIndex-1]:{worldTransformMatrix:new m,worldColor:4294967295,offset:new Xe},d={projectionMatrix:t||this._renderer.renderTarget.projectionMatrix,resolution:e||i.size,worldTransformMatrix:r||o.worldTransformMatrix,worldColor:s||o.worldColor,offset:n||o.offset,bindGroup:null},h=this._uniformsPool.pop()||this._createUniforms();this._activeUniforms.push(h);const c=h.uniforms;c.uProjectionMatrix=d.projectionMatrix,c.uResolution=d.resolution,c.uWorldTransformMatrix.copyFrom(d.worldTransformMatrix),c.uWorldTransformMatrix.tx-=d.offset.x,c.uWorldTransformMatrix.ty-=d.offset.y,Qe(d.worldColor,c.uWorldColorAlpha,0),h.update();let u;this._renderer.renderPipes.uniformBatch?u=this._renderer.renderPipes.uniformBatch.getUniformBindGroup(h,!1):(u=this._bindGroupPool.pop()||new Ze,this._activeBindGroups.push(u),u.setResource(h,0)),d.bindGroup=u,this._currentGlobalUniformData=d}push(e){this.bind(e),this._globalUniformDataStack[this._stackIndex++]=this._currentGlobalUniformData}pop(){this._currentGlobalUniformData=this._globalUniformDataStack[--this._stackIndex-1],this._renderer.type===V.WEBGL&&this._currentGlobalUniformData.bindGroup.resources[0].update()}get bindGroup(){return this._currentGlobalUniformData.bindGroup}get globalUniformData(){return this._currentGlobalUniformData}get uniformGroup(){return this._currentGlobalUniformData.bindGroup.resources[0]}_createUniforms(){return new oe({uProjectionMatrix:{value:new m,type:"mat3x3<f32>"},uWorldTransformMatrix:{value:new m,type:"mat3x3<f32>"},uWorldColorAlpha:{value:new Float32Array(4),type:"vec4<f32>"},uResolution:{value:[0,0],type:"vec2<f32>"}},{isStatic:!0})}destroy(){this._renderer=null,this._globalUniformDataStack.length=0,this._uniformsPool.length=0,this._activeUniforms.length=0,this._bindGroupPool.length=0,this._activeBindGroups.length=0,this._currentGlobalUniformData=null}}Ue.extension={type:[l.WebGLSystem,l.WebGPUSystem,l.CanvasSystem],name:"globalUniforms"};let Ct=1;class Ae{constructor(){this._tasks=[],this._offset=0}init(){te.system.add(this._update,this)}repeat(e,t,r=!0){const s=Ct++;let n=0;return r&&(this._offset+=1e3,n=this._offset),this._tasks.push({func:e,duration:t,start:performance.now(),offset:n,last:performance.now(),repeat:!0,id:s}),s}cancel(e){for(let t=0;t<this._tasks.length;t++)if(this._tasks[t].id===e){this._tasks.splice(t,1);return}}_update(){const e=performance.now();for(let t=0;t<this._tasks.length;t++){const r=this._tasks[t];if(e-r.offset-r.last>=r.duration){const s=e-r.start;r.func(s),r.last=e}}}destroy(){te.system.remove(this._update,this),this._tasks.length=0}}Ae.extension={type:[l.WebGLSystem,l.WebGPUSystem,l.CanvasSystem],name:"scheduler",priority:0};let ie=!1;function kt(a){if(!ie){if(N.get().getNavigator().userAgent.toLowerCase().indexOf("chrome")>-1){const e=[`%c %c %c %c %c PixiJS %c v${re} (${a}) http://www.pixijs.com/
183
-
184
- `,"background: #E72264; padding:5px 0;","background: #6CA2EA; padding:5px 0;","background: #B5D33D; padding:5px 0;","background: #FED23F; padding:5px 0;","color: #FFFFFF; background: #E72264; padding:5px 0;","color: #E72264; background: #FFFFFF; padding:5px 0;"];globalThis.console.log(...e)}else globalThis.console&&globalThis.console.log(`PixiJS ${re} - ${a} - http://www.pixijs.com/`);ie=!0}}class J{constructor(e){this._renderer=e}init(e){if(e.hello){let t=this._renderer.name;this._renderer.type===V.WEBGL&&(t+=` ${this._renderer.context.webGLVersion}`),kt(t)}}}J.extension={type:[l.WebGLSystem,l.WebGPUSystem,l.CanvasSystem],name:"hello",priority:-2};J.defaultOptions={hello:!1};const X=class Ie{constructor(e){this._renderer=e}init(e){e={...Ie.defaultOptions,...e},this.maxUnusedTime=e.renderableGCMaxUnusedTime}get enabled(){return f("8.15.0","RenderableGCSystem.enabled is deprecated, please use the GCSystem.enabled instead."),this._renderer.gc.enabled}set enabled(e){f("8.15.0","RenderableGCSystem.enabled is deprecated, please use the GCSystem.enabled instead."),this._renderer.gc.enabled=e}addManagedHash(e,t){f("8.15.0","RenderableGCSystem.addManagedHash is deprecated, please use the GCSystem.addCollection instead."),this._renderer.gc.addCollection(e,t,"hash")}addManagedArray(e,t){f("8.15.0","RenderableGCSystem.addManagedArray is deprecated, please use the GCSystem.addCollection instead."),this._renderer.gc.addCollection(e,t,"array")}addRenderable(e){f("8.15.0","RenderableGCSystem.addRenderable is deprecated, please use the GCSystem instead."),this._renderer.gc.addResource(e,"renderable")}run(){f("8.15.0","RenderableGCSystem.run is deprecated, please use the GCSystem instead."),this._renderer.gc.run()}destroy(){this._renderer=null}};X.extension={type:[l.WebGLSystem,l.WebGPUSystem,l.CanvasSystem],name:"renderableGC",priority:0};X.defaultOptions={renderableGCActive:!0,renderableGCMaxUnusedTime:6e4,renderableGCFrequency:3e4};let Mt=X;const Q=class S{get count(){return this._renderer.tick}get checkCount(){return this._checkCount}set checkCount(e){f("8.15.0","TextureGCSystem.run is deprecated, please use the GCSystem instead."),this._checkCount=e}get maxIdle(){return this._renderer.gc.maxUnusedTime/1e3*60}set maxIdle(e){f("8.15.0","TextureGCSystem.run is deprecated, please use the GCSystem instead."),this._renderer.gc.maxUnusedTime=e/60*1e3}get checkCountMax(){return Math.floor(this._renderer.gc._frequency/1e3)}set checkCountMax(e){f("8.15.0","TextureGCSystem.run is deprecated, please use the GCSystem instead.")}get active(){return this._renderer.gc.enabled}set active(e){f("8.15.0","TextureGCSystem.run is deprecated, please use the GCSystem instead."),this._renderer.gc.enabled=e}constructor(e){this._renderer=e,this._checkCount=0}init(e){e.textureGCActive!==S.defaultOptions.textureGCActive&&(this.active=e.textureGCActive),e.textureGCMaxIdle!==S.defaultOptions.textureGCMaxIdle&&(this.maxIdle=e.textureGCMaxIdle),e.textureGCCheckCountMax!==S.defaultOptions.textureGCCheckCountMax&&(this.checkCountMax=e.textureGCCheckCountMax)}run(){f("8.15.0","TextureGCSystem.run is deprecated, please use the GCSystem instead."),this._renderer.gc.run()}destroy(){this._renderer=null}};Q.extension={type:[l.WebGLSystem,l.WebGPUSystem],name:"textureGC"};Q.defaultOptions={textureGCActive:!0,textureGCAMaxIdle:null,textureGCMaxIdle:3600,textureGCCheckCountMax:600};let Rt=Q;const De=class Oe{constructor(e={}){if(this.uid=et("renderTarget"),this.colorTextures=[],this.dirtyId=0,this.isRoot=!1,this._size=new Float32Array(2),this._managedColorTextures=!1,e={...Oe.defaultOptions,...e},this.stencil=e.stencil,this.depth=e.depth,this.isRoot=e.isRoot,typeof e.colorTextures=="number"){this._managedColorTextures=!0;for(let t=0;t<e.colorTextures;t++)this.colorTextures.push(new y({width:e.width,height:e.height,resolution:e.resolution,antialias:e.antialias}))}else{this.colorTextures=[...e.colorTextures.map(r=>r.source)];const t=this.colorTexture.source;this.resize(t.width,t.height,t._resolution)}this.colorTexture.source.on("resize",this.onSourceResize,this),(e.depthStencilTexture||this.stencil)&&(e.depthStencilTexture instanceof p||e.depthStencilTexture instanceof y?this.depthStencilTexture=e.depthStencilTexture.source:this.ensureDepthStencilTexture())}get size(){const e=this._size;return e[0]=this.pixelWidth,e[1]=this.pixelHeight,e}get width(){return this.colorTexture.source.width}get height(){return this.colorTexture.source.height}get pixelWidth(){return this.colorTexture.source.pixelWidth}get pixelHeight(){return this.colorTexture.source.pixelHeight}get resolution(){return this.colorTexture.source._resolution}get colorTexture(){return this.colorTextures[0]}onSourceResize(e){this.resize(e.width,e.height,e._resolution,!0)}ensureDepthStencilTexture(){this.depthStencilTexture||(this.depthStencilTexture=new y({width:this.width,height:this.height,resolution:this.resolution,format:"depth24plus-stencil8",autoGenerateMipmaps:!1,antialias:!1,mipLevelCount:1}))}resize(e,t,r=this.resolution,s=!1){this.dirtyId++,this.colorTextures.forEach((n,i)=>{s&&i===0||n.source.resize(e,t,r)}),this.depthStencilTexture&&this.depthStencilTexture.source.resize(e,t,r)}destroy(){this.colorTexture.source.off("resize",this.onSourceResize,this),this._managedColorTextures&&this.colorTextures.forEach(e=>{e.destroy()}),this.depthStencilTexture&&(this.depthStencilTexture.destroy(),delete this.depthStencilTexture)}};De.defaultOptions={width:0,height:0,resolution:1,colorTextures:1,stencil:!1,depth:!1,antialias:!1,isRoot:!1};let F=De;const b=new Map;tt.register(b);function Ee(a,e){if(!b.has(a)){const t=new p({source:new E({resource:a,...e})}),r=()=>{b.get(a)===t&&b.delete(a)};t.once("destroy",r),t.source.once("destroy",r),b.set(a,t)}return b.get(a)}const Z=class Le{get autoDensity(){return this.texture.source.autoDensity}set autoDensity(e){this.texture.source.autoDensity=e}get resolution(){return this.texture.source._resolution}set resolution(e){this.texture.source.resize(this.texture.source.width,this.texture.source.height,e)}init(e){e={...Le.defaultOptions,...e},e.view&&(f(rt,"ViewSystem.view has been renamed to ViewSystem.canvas"),e.canvas=e.view),this.screen=new B(0,0,e.width,e.height),this.canvas=e.canvas||N.get().createCanvas(),this.antialias=!!e.antialias,this.texture=Ee(this.canvas,e),this.renderTarget=new F({colorTextures:[this.texture],depth:!!e.depth,isRoot:!0}),this.texture.source.transparent=e.backgroundAlpha<1,this.resolution=e.resolution}resize(e,t,r){this.texture.source.resize(e,t,r),this.screen.width=this.texture.frame.width,this.screen.height=this.texture.frame.height}destroy(e=!1){(typeof e=="boolean"?e:!!(e!=null&&e.removeView))&&this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas),this.texture.destroy()}};Z.extension={type:[l.WebGLSystem,l.WebGPUSystem,l.CanvasSystem],name:"view",priority:0};Z.defaultOptions={width:800,height:600,autoDensity:!1,antialias:!1};let St=Z;const Ut=[mt,Ue,J,St,Se,vt,Rt,Be,gt,st,Mt,Ae],At=[ke,_e,Ce,ve,xe,Te,be,ye];function wt(a,e,t,r,s,n){const i=n?1:-1;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}function Pt(a){const e=a.colorTexture.source.resource;return globalThis.HTMLCanvasElement&&e instanceof HTMLCanvasElement&&document.body.contains(e)}class It{constructor(e){this.rootViewPort=new B,this.viewport=new B,this.mipLevel=0,this.layer=0,this.onRenderTargetChange=new nt("onRenderTargetChange"),this.projectionMatrix=new m,this.defaultClearColor=[0,0,0,0],this._renderSurfaceToRenderTargetHash=new Map,this._gpuRenderTargetHash=Object.create(null),this._renderTargetStack=[],this._renderer=e,e.gc.addCollection(this,"_gpuRenderTargetHash","hash")}finishRenderPass(){this.adaptor.finishRenderPass(this.renderTarget)}renderStart({target:e,clear:t,clearColor:r,frame:s,mipLevel:n,layer:i}){var o,d;this._renderTargetStack.length=0,this.push(e,t,r,s,n??0,i??0),this.rootViewPort.copyFrom(this.viewport),this.rootRenderTarget=this.renderTarget,this.renderingToScreen=Pt(this.rootRenderTarget),(d=(o=this.adaptor).prerender)==null||d.call(o,this.rootRenderTarget)}postrender(){var e,t;(t=(e=this.adaptor).postrender)==null||t.call(e,this.rootRenderTarget)}bind(e,t=!0,r,s,n=0,i=0){const o=this.getRenderTarget(e),d=this.renderTarget!==o;this.renderTarget=o,this.renderSurface=e;const h=this.getGpuRenderTarget(o);(o.pixelWidth!==h.width||o.pixelHeight!==h.height)&&(this.adaptor.resizeGpuRenderTarget(o),h.width=o.pixelWidth,h.height=o.pixelHeight);const c=o.colorTexture,u=this.viewport,G=c.arrayLayerCount||1;if((i|0)!==i&&(i|=0),i<0||i>=G)throw new Error(`[RenderTargetSystem] layer ${i} is out of bounds (arrayLayerCount=${G}).`);this.mipLevel=n|0,this.layer=i|0;const _=Math.max(c.pixelWidth>>n,1),x=Math.max(c.pixelHeight>>n,1);if(!s&&e instanceof p&&(s=e.frame),s){const C=c._resolution,k=1<<Math.max(n|0,0),He=s.x*C+.5|0,Fe=s.y*C+.5|0,We=s.width*C+.5|0,ze=s.height*C+.5|0;let M=Math.floor(He/k),R=Math.floor(Fe/k),U=Math.ceil(We/k),A=Math.ceil(ze/k);M=Math.min(Math.max(M,0),_-1),R=Math.min(Math.max(R,0),x-1),U=Math.min(Math.max(U,1),_-M),A=Math.min(Math.max(A,1),x-R),u.x=M,u.y=R,u.width=U,u.height=A}else u.x=0,u.y=0,u.width=_,u.height=x;return wt(this.projectionMatrix,0,0,u.width/c.resolution,u.height/c.resolution,!o.isRoot),this.adaptor.startRenderPass(o,t,r,u,n,i),d&&this.onRenderTargetChange.emit(o),o}clear(e,t=D.ALL,r,s=this.mipLevel,n=this.layer){t&&(e&&(e=this.getRenderTarget(e)),this.adaptor.clear(e||this.renderTarget,t,r,this.viewport,s,n))}contextChange(){this._gpuRenderTargetHash=Object.create(null)}push(e,t=D.ALL,r,s,n=0,i=0){const o=this.bind(e,t,r,s,n,i);return this._renderTargetStack.push({renderTarget:o,frame:s,mipLevel:n,layer:i}),o}pop(){this._renderTargetStack.pop();const e=this._renderTargetStack[this._renderTargetStack.length-1];this.bind(e.renderTarget,!1,null,e.frame,e.mipLevel,e.layer)}getRenderTarget(e){return e.isTexture&&(e=e.source),this._renderSurfaceToRenderTargetHash.get(e)??this._initRenderTarget(e)}copyToTexture(e,t,r,s,n){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);const{pixelWidth:i,pixelHeight:o}=e;return s.width=Math.min(s.width,i-r.x),s.height=Math.min(s.height,o-r.y),this.adaptor.copyToTexture(e,t,r,s,n)}ensureDepthStencil(){this.renderTarget.stencil||(this.renderTarget.stencil=!0,this.adaptor.startRenderPass(this.renderTarget,!1,null,this.viewport,0,this.layer))}destroy(){this._renderer=null,this._renderSurfaceToRenderTargetHash.forEach((e,t)=>{e!==t&&e.destroy()}),this._renderSurfaceToRenderTargetHash.clear(),this._gpuRenderTargetHash=Object.create(null)}_initRenderTarget(e){let t=null;return E.test(e)&&(e=Ee(e).source),e instanceof F?t=e:e instanceof y&&(t=new F({colorTextures:[e]}),e.source instanceof E&&(t.isRoot=!0),e.once("destroy",()=>{t.destroy(),this._renderSurfaceToRenderTargetHash.delete(e);const r=this._gpuRenderTargetHash[t.uid];r&&(this._gpuRenderTargetHash[t.uid]=null,this.adaptor.destroyGpuRenderTarget(r))})),this._renderSurfaceToRenderTargetHash.set(e,t),t}getGpuRenderTarget(e){return this._gpuRenderTargetHash[e.uid]||(this._gpuRenderTargetHash[e.uid]=this.adaptor.initGpuRenderTarget(e))}resetState(){this.renderTarget=null,this.renderSurface=null}}export{xe as A,_e as B,ye as C,ve as R,At as S,ke as a,It as b,Ut as c,Ce as d};