diff options
Diffstat (limited to 'dist/assets')
| -rw-r--r-- | dist/assets/SharedSystems-DVK37F7d.js | 326 | ||||
| -rw-r--r-- | dist/assets/WebGLRenderer-BVO0qznQ.js | 156 | ||||
| -rw-r--r-- | dist/assets/WebGPURenderer-CtyVoQqf.js | 41 | ||||
| -rw-r--r-- | dist/assets/browserAll-BytxDfn1.js | 14 | ||||
| -rw-r--r-- | dist/assets/colorToUniform-DmtBy-2V.js | 31 | ||||
| -rw-r--r-- | dist/assets/index-DB6B0XuI.js | 451 | ||||
| -rw-r--r-- | dist/assets/index-DCiDMyds.css | 1 | ||||
| -rw-r--r-- | dist/assets/webworkerAll-J8ccMaq4.js | 296 |
8 files changed, 1316 insertions, 0 deletions
diff --git a/dist/assets/SharedSystems-DVK37F7d.js b/dist/assets/SharedSystems-DVK37F7d.js new file mode 100644 index 0000000..5d71c0c --- /dev/null +++ b/dist/assets/SharedSystems-DVK37F7d.js @@ -0,0 +1,326 @@ +import{q as He,G as ne,t as ie,u as ze,k as oe,M as v,v as le,E as u,e as O,x as S,y as We,z as F,F as b,R as L,H as ue,I as Ve,s as m,S as f,h as B,w as H,J,K as Ne,b as X,B as k,i as U,L as je,N as M,j as T,O as w,Q as $e,a as qe,V as de,W as ce,X as he,Y as fe,C as P,Z as Ke,_ as A,$ as Q,D as z,a0 as Ye,P as Je,c as Xe,T as Z,a1 as ee,a2 as Qe,a3 as Ze,a4 as et}from"./index-DB6B0XuI.js";import{S as pe,B as me,c as tt}from"./colorToUniform-DmtBy-2V.js";const ve=class I extends He{constructor(e){e={...I.defaultOptions,...e},super(e),this.enabled=!0,this._state=pe.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)}apply(e,t,r,s){e.applyFilter(this,t,r,s)}get blendMode(){return this._state.blendMode}set blendMode(e){this._state.blendMode=e}static from(e){const{gpu:t,gl:r,...s}=e;let a,i;return t&&(a=ne.from(t)),r&&(i=ie.from(r)),new I({gpuProgram:a,glProgram:i,...s})}};ve.defaultOptions={blendMode:"normal",resolution:1,padding:0,antialias:"off",blendRequired:!1,clipToViewport:!0};let rt=ve;var st=`in vec2 vMaskCoord; +in vec2 vTextureCoord; + +uniform sampler2D uTexture; +uniform sampler2D uMaskTexture; + +uniform float uAlpha; +uniform vec4 uMaskClamp; +uniform float uInverse; + +out vec4 finalColor; + +void main(void) +{ + float clip = step(3.5, + step(uMaskClamp.x, vMaskCoord.x) + + step(uMaskClamp.y, vMaskCoord.y) + + step(vMaskCoord.x, uMaskClamp.z) + + step(vMaskCoord.y, uMaskClamp.w)); + + // TODO look into why this is needed + float npmAlpha = uAlpha; + vec4 original = texture(uTexture, vTextureCoord); + vec4 masky = texture(uMaskTexture, vMaskCoord); + float alphaMul = 1.0 - npmAlpha * (1.0 - masky.a); + + float a = alphaMul * masky.r * npmAlpha * clip; + + if (uInverse == 1.0) { + a = 1.0 - a; + } + + finalColor = original * a; +} +`,at=`in vec2 aPosition; + +out vec2 vTextureCoord; +out vec2 vMaskCoord; + + +uniform vec4 uInputSize; +uniform vec4 uOutputFrame; +uniform vec4 uOutputTexture; +uniform mat3 uFilterMatrix; + +vec4 filterVertexPosition( vec2 aPosition ) +{ + vec2 position = aPosition * uOutputFrame.zw + uOutputFrame.xy; + + position.x = position.x * (2.0 / uOutputTexture.x) - 1.0; + position.y = position.y * (2.0*uOutputTexture.z / uOutputTexture.y) - uOutputTexture.z; + + return vec4(position, 0.0, 1.0); +} + +vec2 filterTextureCoord( vec2 aPosition ) +{ + return aPosition * (uOutputFrame.zw * uInputSize.zw); +} + +vec2 getFilterCoord( vec2 aPosition ) +{ + return ( uFilterMatrix * vec3( filterTextureCoord(aPosition), 1.0) ).xy; +} + +void main(void) +{ + gl_Position = filterVertexPosition(aPosition); + vTextureCoord = filterTextureCoord(aPosition); + vMaskCoord = getFilterCoord(aPosition); +} +`,te=`struct GlobalFilterUniforms { + uInputSize:vec4<f32>, + uInputPixel:vec4<f32>, + uInputClamp:vec4<f32>, + uOutputFrame:vec4<f32>, + uGlobalFrame:vec4<f32>, + uOutputTexture:vec4<f32>, +}; + +struct MaskUniforms { + uFilterMatrix:mat3x3<f32>, + uMaskClamp:vec4<f32>, + uAlpha:f32, + uInverse:f32, +}; + +@group(0) @binding(0) var<uniform> gfu: GlobalFilterUniforms; +@group(0) @binding(1) var uTexture: texture_2d<f32>; +@group(0) @binding(2) var uSampler : sampler; + +@group(1) @binding(0) var<uniform> filterUniforms : MaskUniforms; +@group(1) @binding(1) var uMaskTexture: texture_2d<f32>; + +struct VSOutput { + @builtin(position) position: vec4<f32>, + @location(0) uv : vec2<f32>, + @location(1) filterUv : vec2<f32>, +}; + +fn filterVertexPosition(aPosition:vec2<f32>) -> vec4<f32> +{ + var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy; + + position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0; + position.y = position.y * (2.0*gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z; + + return vec4(position, 0.0, 1.0); +} + +fn filterTextureCoord( aPosition:vec2<f32> ) -> vec2<f32> +{ + return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw); +} + +fn globalTextureCoord( aPosition:vec2<f32> ) -> vec2<f32> +{ + return (aPosition.xy / gfu.uGlobalFrame.zw) + (gfu.uGlobalFrame.xy / gfu.uGlobalFrame.zw); +} + +fn getFilterCoord(aPosition:vec2<f32> ) -> vec2<f32> +{ + return ( filterUniforms.uFilterMatrix * vec3( filterTextureCoord(aPosition), 1.0) ).xy; +} + +fn getSize() -> vec2<f32> +{ + return gfu.uGlobalFrame.zw; +} + +@vertex +fn mainVertex( + @location(0) aPosition : vec2<f32>, +) -> VSOutput { + return VSOutput( + filterVertexPosition(aPosition), + filterTextureCoord(aPosition), + getFilterCoord(aPosition) + ); +} + +@fragment +fn mainFragment( + @location(0) uv: vec2<f32>, + @location(1) filterUv: vec2<f32>, + @builtin(position) position: vec4<f32> +) -> @location(0) vec4<f32> { + + var maskClamp = filterUniforms.uMaskClamp; + var uAlpha = filterUniforms.uAlpha; + + var clip = step(3.5, + step(maskClamp.x, filterUv.x) + + step(maskClamp.y, filterUv.y) + + step(filterUv.x, maskClamp.z) + + step(filterUv.y, maskClamp.w)); + + var mask = textureSample(uMaskTexture, uSampler, filterUv); + var source = textureSample(uTexture, uSampler, uv); + var alphaMul = 1.0 - uAlpha * (1.0 - mask.a); + + var a: f32 = alphaMul * mask.r * uAlpha * clip; + + if (filterUniforms.uInverse == 1.0) { + a = 1.0 - a; + } + + return source * a; +} +`;class nt extends rt{constructor(e){const{sprite:t,...r}=e,s=new ze(t.texture),a=new oe({uFilterMatrix:{value:new v,type:"mat3x3<f32>"},uMaskClamp:{value:s.uClampFrame,type:"vec4<f32>"},uAlpha:{value:1,type:"f32"},uInverse:{value:e.inverse?1:0,type:"f32"}}),i=ne.from({vertex:{source:te,entryPoint:"mainVertex"},fragment:{source:te,entryPoint:"mainFragment"}}),o=ie.from({vertex:at,fragment:st,name:"mask-filter"});super({...r,gpuProgram:i,glProgram:o,clipToViewport:!1,resources:{filterUniforms:a,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}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 W=class ge{constructor(e,t){var r,s;this.state=pe.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],a=s.geometry;a.indexBuffer.setDataWithSize(s.indexBuffer,s.indexSize,!0),a.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],a=s.geometry;s.dirty&&(s.dirty=!1,a.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}};W.extension={type:[u.WebGLPipes,u.WebGPUPipes,u.CanvasPipes],name:"batch"};W._availableBatchers=Object.create(null);let xe=W;O.handleByMap(u.Batcher,xe._availableBatchers);O.add(le);const It={name:"texture-bit",vertex:{header:` + + struct TextureUniforms { + uTextureMatrix:mat3x3<f32>, + } + + @group(2) @binding(2) var<uniform> textureUniforms : TextureUniforms; + `,main:` + uv = (textureUniforms.uTextureMatrix * vec3(uv, 1.0)).xy; + `},fragment:{header:` + @group(2) @binding(0) var uTexture: texture_2d<f32>; + @group(2) @binding(1) var uSampler: sampler; + + + `,main:` + outColor = textureSample(uTexture, uSampler, vUV); + `}},Gt={name:"texture-bit",vertex:{header:` + uniform mat3 uTextureMatrix; + `,main:` + uv = (uTextureMatrix * vec3(uv, 1.0)).xy; + `},fragment:{header:` + uniform sampler2D uTexture; + + + `,main:` + outColor = texture(uTexture, vUV); + `}},it=new F;class ot extends ue{constructor(){super(),this.filters=[new nt({sprite:new Ve(m.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}}class _e{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.renderMaskToTexture){const a=e.mask;a.includeInBuild=!0,a.collectRenderables(r,s,null),a.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=S.get(ot);if(s.inverse=e.inverse,r){e.mask.mask.measurable=!0;const a=We(e.mask.mask,!0,it);e.mask.mask.measurable=!1,a.ceil();const i=t.renderTarget.renderTarget.colorTexture.source,o=b.getOptimalTexture(a.width,a.height,i._resolution,i.antialias);t.renderTarget.push(o,!0),t.globalUniforms.push({offset:a,worldColor:4294967295});const l=s.sprite;l.texture=o,l.worldTransform.tx=a.minX,l.worldTransform.ty=a.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===L.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&&b.returnTexture(s.filterTexture),S.return(s.filterEffect)}}destroy(){this._renderer=null,this._activeMaskStage=null}}_e.extension={type:[u.WebGLPipes,u.WebGPUPipes,u.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 a=this._colorStack;a[this._colorStackIndex]=a[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 a=this._colorStack;this._colorStackIndex--;const i=a[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:[u.WebGLPipes,u.WebGPUPipes,u.CanvasPipes],name:"colorMask"};class Te{constructor(e){this._maskStackHash={},this._maskHash=new WeakMap,this._renderer=e}push(e,t,r){var s;const a=e,i=this._renderer;i.renderPipes.batch.break(r),i.renderPipes.blendMode.setBlendMode(a.mask,"none",r),r.add({renderPipeId:"stencilMask",action:"pushMaskBegin",mask:e,inverse:t._maskOptions.inverse,canBundle:!1});const o=a.mask;o.includeInBuild=!0,this._maskHash.has(a)||this._maskHash.set(a,{instructionsStart:0,instructionsLength:0});const l=this._maskHash.get(a);l.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 d=r.instructionSize-l.instructionsStart-1;l.instructionsLength=d;const c=i.renderTarget.renderTarget.uid;(s=this._maskStackHash)[c]??(s[c]=0)}pop(e,t,r){const s=e,a=this._renderer;a.renderPipes.batch.break(r),a.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.renderTarget.renderTarget.uid;let a=(t=this._maskStackHash)[s]??(t[s]=0);e.action==="pushMaskBegin"?(r.renderTarget.ensureDepthStencil(),r.stencil.setStencilMode(f.RENDERING_MASK_ADD,a),a++,r.colorMask.setMask(0)):e.action==="pushMaskEnd"?(e.inverse?r.stencil.setStencilMode(f.INVERSE_MASK_ACTIVE,a):r.stencil.setStencilMode(f.MASK_ACTIVE,a),r.colorMask.setMask(15)):e.action==="popMaskBegin"?(r.colorMask.setMask(0),a!==0?r.stencil.setStencilMode(f.RENDERING_MASK_REMOVE,a):(r.renderTarget.clear(null,B.STENCIL),r.stencil.setStencilMode(f.DISABLED,a)),a--):e.action==="popMaskEnd"&&(e.inverse?r.stencil.setStencilMode(f.INVERSE_MASK_ACTIVE,a):r.stencil.setStencilMode(f.MASK_ACTIVE,a),r.colorMask.setMask(15)),this._maskStackHash[s]=a}destroy(){this._renderer=null,this._maskStackHash=null,this._maskHash=null}}Te.extension={type:[u.WebGLPipes,u.WebGPUPipes,u.CanvasPipes],name:"stencilMask"};function Et(n,e){for(const t in n.attributes){const r=n.attributes[t],s=e[t];s?(r.format??(r.format=s.format),r.offset??(r.offset=s.offset),r.instance??(r.instance=s.instance)):H(`Attribute ${t} is not present in the shader, but is present in the geometry. Unable to infer attribute details.`)}lt(n)}function lt(n){const{buffers:e,attributes:t}=n,r={},s={};for(const a in e){const i=e[a];r[i.uid]=0,s[i.uid]=0}for(const a in t){const i=t[a];r[i.buffer.uid]+=J(i.format).stride}for(const a in t){const i=t[a];i.stride??(i.stride=r[i.buffer.uid]),i.start??(i.start=s[i.buffer.uid]),s[i.buffer.uid]+=J(i.format).stride}}const _=[];_[f.NONE]=void 0;_[f.DISABLED]={stencilWriteMask:0,stencilReadMask:0};_[f.RENDERING_MASK_ADD]={stencilFront:{compare:"equal",passOp:"increment-clamp"},stencilBack:{compare:"equal",passOp:"increment-clamp"}};_[f.RENDERING_MASK_REMOVE]={stencilFront:{compare:"equal",passOp:"decrement-clamp"},stencilBack:{compare:"equal",passOp:"decrement-clamp"}};_[f.MASK_ACTIVE]={stencilWriteMask:0,stencilFront:{compare:"equal",passOp:"keep"},stencilBack:{compare:"equal",passOp:"keep"}};_[f.INVERSE_MASK_ACTIVE]={stencilWriteMask:0,stencilFront:{compare:"not-equal",passOp:"keep"},stencilBack:{compare:"not-equal",passOp:"keep"}};class Dt{constructor(e){this._syncFunctionHash=Object.create(null),this._adaptor=e,this._systemCheck()}_systemCheck(){if(!Ne())throw new Error("Current environment does not allow unsafe-eval, please use pixi.js/unsafe-eval module to enable support.")}ensureUniformGroup(e){const t=this.getUniformGroupData(e);e.buffer||(e.buffer=new X({data:new Float32Array(t.layout.size/4),usage:k.UNIFORM|k.COPY_DST}))}getUniformGroupData(e){return this._syncFunctionHash[e._signature]||this._initUniformGroup(e)}_initUniformGroup(e){const t=e._signature;let r=this._syncFunctionHash[t];if(!r){const s=Object.keys(e.uniformStructures).map(o=>e.uniformStructures[o]),a=this._adaptor.createUboElements(s),i=this._generateUboSync(a.uboElements);r=this._syncFunctionHash[t]={layout:a,syncFunction:i}}return this._syncFunctionHash[t]}_generateUboSync(e){return this._adaptor.generateUboSync(e)}syncUniformGroup(e,t,r){const s=this.getUniformGroupData(e);e.buffer||(e.buffer=new X({data:new Float32Array(s.layout.size/4),usage:k.UNIFORM|k.COPY_DST}));let a=null;return t||(t=e.buffer.data,a=e.buffer.dataInt32),r||(r=0),s.syncFunction(e.uniforms,t,a,r),!0}updateUniformGroup(e){if(e.isStatic&&!e._dirtyId)return!1;e._dirtyId=0;const t=this.syncUniformGroup(e);return e.buffer.update(),t}destroy(){this._syncFunctionHash=null}}const C=[{type:"mat3x3<f32>",test:n=>n.value.a!==void 0,ubo:` + var matrix = uv[name].toArray(true); + data[offset] = matrix[0]; + data[offset + 1] = matrix[1]; + data[offset + 2] = matrix[2]; + data[offset + 4] = matrix[3]; + data[offset + 5] = matrix[4]; + data[offset + 6] = matrix[5]; + data[offset + 8] = matrix[6]; + data[offset + 9] = matrix[7]; + data[offset + 10] = matrix[8]; + `,uniform:` + gl.uniformMatrix3fv(ud[name].location, false, uv[name].toArray(true)); + `},{type:"vec4<f32>",test:n=>n.type==="vec4<f32>"&&n.size===1&&n.value.width!==void 0,ubo:` + v = uv[name]; + data[offset] = v.x; + data[offset + 1] = v.y; + data[offset + 2] = v.width; + data[offset + 3] = v.height; + `,uniform:` + cv = ud[name].value; + v = uv[name]; + if (cv[0] !== v.x || cv[1] !== v.y || cv[2] !== v.width || cv[3] !== v.height) { + cv[0] = v.x; + cv[1] = v.y; + cv[2] = v.width; + cv[3] = v.height; + gl.uniform4f(ud[name].location, v.x, v.y, v.width, v.height); + } + `},{type:"vec2<f32>",test:n=>n.type==="vec2<f32>"&&n.size===1&&n.value.x!==void 0,ubo:` + v = uv[name]; + data[offset] = v.x; + data[offset + 1] = v.y; + `,uniform:` + cv = ud[name].value; + v = uv[name]; + if (cv[0] !== v.x || cv[1] !== v.y) { + cv[0] = v.x; + cv[1] = v.y; + gl.uniform2f(ud[name].location, v.x, v.y); + } + `},{type:"vec4<f32>",test:n=>n.type==="vec4<f32>"&&n.size===1&&n.value.red!==void 0,ubo:` + v = uv[name]; + data[offset] = v.red; + data[offset + 1] = v.green; + data[offset + 2] = v.blue; + data[offset + 3] = v.alpha; + `,uniform:` + cv = ud[name].value; + v = uv[name]; + if (cv[0] !== v.red || cv[1] !== v.green || cv[2] !== v.blue || cv[3] !== v.alpha) { + cv[0] = v.red; + cv[1] = v.green; + cv[2] = v.blue; + cv[3] = v.alpha; + gl.uniform4f(ud[name].location, v.red, v.green, v.blue, v.alpha); + } + `},{type:"vec3<f32>",test:n=>n.type==="vec3<f32>"&&n.size===1&&n.value.red!==void 0,ubo:` + v = uv[name]; + data[offset] = v.red; + data[offset + 1] = v.green; + data[offset + 2] = v.blue; + `,uniform:` + cv = ud[name].value; + v = uv[name]; + if (cv[0] !== v.red || cv[1] !== v.green || cv[2] !== v.blue) { + cv[0] = v.red; + cv[1] = v.green; + cv[2] = v.blue; + gl.uniform3f(ud[name].location, v.red, v.green, v.blue); + } + `}];function Ot(n,e,t,r){const s=[` + var v = null; + var v2 = null; + var t = 0; + var index = 0; + var name = null; + var arrayOffset = null; + `];let a=0;for(let o=0;o<n.length;o++){const l=n[o],d=l.data.name;let c=!1,h=0;for(let p=0;p<C.length;p++)if(C[p].test(l.data)){h=l.offset/4,s.push(`name = "${d}";`,`offset += ${h-a};`,C[p][e]||C[p].ubo),c=!0;break}if(!c)if(l.data.size>1)h=l.offset/4,s.push(t(l,h-a));else{const p=r[l.data.type];h=l.offset/4,s.push(` + v = uv.${d}; + offset += ${h-a}; + ${p}; + `)}a=h}const i=s.join(` +`);return new Function("uv","data","dataInt32","offset",i)}function g(n,e){return` + for (let i = 0; i < ${n*e}; i++) { + data[offset + (((i / ${n})|0) * 4) + (i % ${n})] = v[i]; + } + `}const ut={f32:` + data[offset] = v;`,i32:` + dataInt32[offset] = v;`,"vec2<f32>":` + data[offset] = v[0]; + data[offset + 1] = v[1];`,"vec3<f32>":` + data[offset] = v[0]; + data[offset + 1] = v[1]; + data[offset + 2] = v[2];`,"vec4<f32>":` + data[offset] = v[0]; + data[offset + 1] = v[1]; + data[offset + 2] = v[2]; + data[offset + 3] = v[3];`,"vec2<i32>":` + dataInt32[offset] = v[0]; + dataInt32[offset + 1] = v[1];`,"vec3<i32>":` + dataInt32[offset] = v[0]; + dataInt32[offset + 1] = v[1]; + dataInt32[offset + 2] = v[2];`,"vec4<i32>":` + dataInt32[offset] = v[0]; + dataInt32[offset + 1] = v[1]; + dataInt32[offset + 2] = v[2]; + dataInt32[offset + 3] = v[3];`,"mat2x2<f32>":` + data[offset] = v[0]; + data[offset + 1] = v[1]; + data[offset + 4] = v[2]; + data[offset + 5] = v[3];`,"mat3x3<f32>":` + data[offset] = v[0]; + data[offset + 1] = v[1]; + data[offset + 2] = v[2]; + data[offset + 4] = v[3]; + data[offset + 5] = v[4]; + data[offset + 6] = v[5]; + data[offset + 8] = v[6]; + data[offset + 9] = v[7]; + data[offset + 10] = v[8];`,"mat4x4<f32>":` + for (let i = 0; i < 16; i++) { + data[offset + i] = v[i]; + }`,"mat3x2<f32>":g(3,2),"mat4x2<f32>":g(4,2),"mat2x3<f32>":g(2,3),"mat4x3<f32>":g(4,3),"mat2x4<f32>":g(2,4),"mat3x4<f32>":g(3,4)},Ft={...ut,"mat2x2<f32>":` + data[offset] = v[0]; + data[offset + 1] = v[1]; + data[offset + 2] = v[2]; + data[offset + 3] = v[3]; + `};function dt(n,e,t,r,s,a){const i=a?1:-1;return n.identity(),n.a=1/r*2,n.d=i*(1/s*2),n.tx=-1-e*n.a,n.ty=-i-t*n.d,n}const x=new Map;je.register(x);function ye(n,e){if(!x.has(n)){const t=new m({source:new U({resource:n,...e})}),r=()=>{x.get(n)===t&&x.delete(n)};t.once("destroy",r),t.source.once("destroy",r),x.set(n,t)}return x.get(n)}function ct(n){const e=n.colorTexture.source.resource;return globalThis.HTMLCanvasElement&&e instanceof HTMLCanvasElement&&document.body.contains(e)}const ke=class Ce{constructor(e={}){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"){this._managedColorTextures=!0;for(let t=0;t<e.colorTextures;t++)this.colorTextures.push(new T({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 m||e.depthStencilTexture instanceof T?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 T({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((a,i)=>{s&&i===0||a.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)}};ke.defaultOptions={width:0,height:0,resolution:1,colorTextures:1,stencil:!1,depth:!1,antialias:!1,isRoot:!1};let G=ke;class Lt{constructor(e){this.rootViewPort=new w,this.viewport=new w,this.onRenderTargetChange=new $e("onRenderTargetChange"),this.projectionMatrix=new v,this.defaultClearColor=[0,0,0,0],this._renderSurfaceToRenderTargetHash=new Map,this._gpuRenderTargetHash=Object.create(null),this._renderTargetStack=[],this._renderer=e,e.renderableGC.addManagedHash(this,"_gpuRenderTargetHash")}finishRenderPass(){this.adaptor.finishRenderPass(this.renderTarget)}renderStart({target:e,clear:t,clearColor:r,frame:s}){var a,i;this._renderTargetStack.length=0,this.push(e,t,r,s),this.rootViewPort.copyFrom(this.viewport),this.rootRenderTarget=this.renderTarget,this.renderingToScreen=ct(this.rootRenderTarget),(i=(a=this.adaptor).prerender)==null||i.call(a,this.rootRenderTarget)}postrender(){var e,t;(t=(e=this.adaptor).postrender)==null||t.call(e,this.rootRenderTarget)}bind(e,t=!0,r,s){const a=this.getRenderTarget(e),i=this.renderTarget!==a;this.renderTarget=a,this.renderSurface=e;const o=this.getGpuRenderTarget(a);(a.pixelWidth!==o.width||a.pixelHeight!==o.height)&&(this.adaptor.resizeGpuRenderTarget(a),o.width=a.pixelWidth,o.height=a.pixelHeight);const l=a.colorTexture,d=this.viewport,c=l.pixelWidth,h=l.pixelHeight;if(!s&&e instanceof m&&(s=e.frame),s){const p=l._resolution;d.x=s.x*p+.5|0,d.y=s.y*p+.5|0,d.width=s.width*p+.5|0,d.height=s.height*p+.5|0}else d.x=0,d.y=0,d.width=c,d.height=h;return dt(this.projectionMatrix,0,0,d.width/l.resolution,d.height/l.resolution,!a.isRoot),this.adaptor.startRenderPass(a,t,r,d),i&&this.onRenderTargetChange.emit(a),a}clear(e,t=B.ALL,r){t&&(e&&(e=this.getRenderTarget(e)),this.adaptor.clear(e||this.renderTarget,t,r,this.viewport))}contextChange(){this._gpuRenderTargetHash=Object.create(null)}push(e,t=B.ALL,r,s){const a=this.bind(e,t,r,s);return this._renderTargetStack.push({renderTarget:a,frame:s}),a}pop(){this._renderTargetStack.pop();const e=this._renderTargetStack[this._renderTargetStack.length-1];this.bind(e.renderTarget,!1,null,e.frame)}getRenderTarget(e){return e.isTexture&&(e=e.source),this._renderSurfaceToRenderTargetHash.get(e)??this._initRenderTarget(e)}copyToTexture(e,t,r,s,a){r.x<0&&(s.width+=r.x,a.x-=r.x,r.x=0),r.y<0&&(s.height+=r.y,a.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,a)}ensureDepthStencil(){this.renderTarget.stencil||(this.renderTarget.stencil=!0,this.adaptor.startRenderPass(this.renderTarget,!1,null,this.viewport))}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 U.test(e)&&(e=ye(e).source),e instanceof G?t=e:e instanceof T&&(t=new G({colorTextures:[e]}),e.source instanceof U&&(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}}class Ht extends qe{constructor({buffer:e,offset:t,size:r}){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)}onBufferChange(){this._resourceId=M("resource"),this.emit("change",this)}destroy(e=!1){this.destroyed=!0,e&&this.buffer.destroy(),this.emit("change",this),this.buffer=null}}class Me{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}}Me.extension={type:[u.WebGLPipes,u.WebGPUPipes,u.CanvasPipes],name:"customRender"};function E(n,e){const t=n.instructionSet,r=t.instructions;for(let s=0;s<t.instructionSize;s++){const a=r[s];e[a.renderPipeId].execute(a)}}const ht=new v;class Se{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&&(S.return(e._batchableRenderGroup),e._batchableRenderGroup=null),t.add(e)}_addRenderableCacheAsTexture(e,t){const r=e._batchableRenderGroup??(e._batchableRenderGroup=S.get(me));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=ht.identity().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}}),E(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}),E(e,this._renderer.renderPipes),this._renderer.globalUniforms.pop()}}Se.extension={type:[u.WebGLPipes,u.WebGPUPipes,u.CanvasPipes],name:"renderGroup"};function D(n,e){e||(e=0);for(let t=e;t<n.length&&n[t];t++)n[t]=null}const ft=new P,re=ce|he|fe;function we(n,e=!1){pt(n);const t=n.childrenToUpdate,r=n.updateTick++;for(const s in t){const a=Number(s),i=t[s],o=i.list,l=i.index;for(let d=0;d<l;d++){const c=o[d];c.parentRenderGroup===n&&c.relativeRenderGroupDepth===a&&Pe(c,r,0)}D(o,l),i.index=0}if(e)for(let s=0;s<n.renderGroupChildren.length;s++)we(n.renderGroupChildren[s],e)}function pt(n){const e=n.root;let t;if(n.renderGroupParent){const r=n.renderGroupParent;n.worldTransform.appendFrom(e.relativeGroupTransform,r.worldTransform),n.worldColor=de(e.groupColor,r.worldColor),t=e.groupAlpha*r.worldAlpha}else n.worldTransform.copyFrom(e.localTransform),n.worldColor=e.localColor,t=e.localAlpha;t=t<0?0:t>1?1:t,n.worldAlpha=t,n.worldColorAlpha=n.worldColor+((t*255|0)<<24)}function Pe(n,e,t){if(e===n.updateTick)return;n.updateTick=e,n.didChange=!1;const r=n.localTransform;n.updateLocalTransform();const s=n.parent;if(s&&!s.renderGroup?(t|=n._updateFlags,n.relativeGroupTransform.appendFrom(r,s.relativeGroupTransform),t&re&&se(n,s,t)):(t=n._updateFlags,n.relativeGroupTransform.copyFrom(r),t&re&&se(n,ft,t)),!n.renderGroup){const a=n.children,i=a.length;for(let d=0;d<i;d++)Pe(a[d],e,t);const o=n.parentRenderGroup,l=n;l.renderPipeId&&!o.structureDidChange&&o.updateRenderable(l)}}function se(n,e,t){if(t&he){n.groupColor=de(n.localColor,e.groupColor);let r=n.localAlpha*e.groupAlpha;r=r<0?0:r>1?1:r,n.groupAlpha=r,n.groupColorAlpha=n.groupColor+((r*255|0)<<24)}t&fe&&(n.groupBlendMode=n.localBlendMode==="inherit"?e.groupBlendMode:n.localBlendMode),t&ce&&(n.globalDisplayStatus=n.localDisplayStatus&e.globalDisplayStatus),n._updateFlags=0}function mt(n,e){const{list:t,index:r}=n.childrenRenderablesToUpdate;let s=!1;for(let a=0;a<r;a++){const i=t[a];if(s=e[i.renderPipeId].validateRenderable(i),s)break}return n.structureDidChange=s,s}const vt=new v;class Re{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 a=this._renderer,i=vt;t&&(i.copyFrom(e.renderGroup.localTransform),e.renderGroup.localTransform.copyFrom(t));const o=a.renderPipes;this._updateCachedRenderGroups(e.renderGroup,null),this._updateRenderGroups(e.renderGroup),a.globalUniforms.start({worldTransformMatrix:t?e.renderGroup.localTransform:e.renderGroup.worldTransform,worldColor:e.renderGroup.worldColorAlpha}),E(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();r.ceil();const s=e.texture;e.texture&&b.returnTexture(e.texture,!0);const a=this._renderer,i=e.textureOptions.resolution||a.view.resolution,o=e.textureOptions.antialias??a.view.antialias,l=e.textureOptions.scaleMode??"linear",d=b.getOptimalTexture(r.width,r.height,i,o);d._source.style=new Ke({scaleMode:l}),e.texture=d,e._textureBounds||(e._textureBounds=new F),e._textureBounds.copyFrom(r),s!==e.texture&&e.renderGroupParent&&(e.renderGroupParent.structureDidChange=!0)}}else e.texture&&(b.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?D(e.childrenRenderablesToUpdate.list,0):mt(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))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 a=t[s];a.didViewUpdate&&e.updateRenderable(a)}D(t,r)}_buildInstructions(e,t){const r=e.root,s=e.instructionSet;s.reset();const a=t.renderPipes?t:t.batch.renderer,i=a.renderPipes;i.batch.buildStart(s),i.blendMode.buildStart(),i.colorMask.buildStart(),r.sortableChildren&&r.sortChildren(),r.collectRenderablesWithEffects(s,a,null),i.batch.buildEnd(s),i.blendMode.buildEnd(s)}}Re.extension={type:[u.WebGLSystem,u.WebGPUSystem,u.CanvasSystem],name:"renderGroup"};class Be{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 me;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}}Be.extension={type:[u.WebGLPipes,u.WebGPUPipes,u.CanvasPipes],name:"sprite"};const V=class Ue{constructor(){this.clearBeforeRender=!0,this._backgroundColor=new A(0),this.color=this._backgroundColor,this.alpha=1}init(e){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)}get color(){return this._backgroundColor}set color(e){A.shared.setValue(e).alpha<1&&this._backgroundColor.alpha===1&&H("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(){}};V.extension={type:[u.WebGLSystem,u.WebGPUSystem,u.CanvasSystem],name:"background",priority:0};V.defaultOptions={backgroundAlpha:1,backgroundColor:0,clearBeforeRender:!0};let gt=V;const y={};O.handle(u.BlendMode,n=>{if(!n.name)throw new Error("BlendMode extension must have a name property");y[n.name]=n.ref},n=>{delete y[n.name]});class Ae{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 a;const s=e instanceof Q;if(this._activeBlendMode===t){this._isAdvanced&&e&&!s&&((a=this._renderableList)==null||a.push(e));return}this._isAdvanced&&this._endAdvancedBlendMode(r),this._activeBlendMode=t,e&&(this._isAdvanced=!!y[t],this._isAdvanced&&this._beginAdvancedBlendMode(e,r))}_beginAdvancedBlendMode(e,t){this._renderer.renderPipes.batch.break(t);const r=this._activeBlendMode;if(!y[r]){H(`Unable to assign BlendMode: '${r}'. You may want to include: import 'pixi.js/advanced-blend-modes'`);return}const s=this._ensureFilterEffect(r),a=e instanceof Q,i={renderPipeId:"filter",action:"pushFilter",filterEffect:s,renderables:a?null:[e],container:a?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 ue,t.filters=[new y[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}}Ae.extension={type:[u.WebGLPipes,u.WebGPUPipes,u.CanvasPipes],name:"blendMode"};const R={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},N=class Ie{constructor(e){this._renderer=e}_normalizeOptions(e,t={}){return e instanceof P||e instanceof m?{target:e,...t}:{...t,...e}}async image(e){const t=z.get().createImage();return t.src=await this.base64(e),t}async base64(e){e=this._normalizeOptions(e,Ie.defaultImageOptions);const{format:t,quality:r}=e,s=this.canvas(e);if(s.toBlob!==void 0)return new Promise((a,i)=>{s.toBlob(o=>{if(!o){i(new Error("ICanvas.toBlob failed!"));return}const l=new FileReader;l.onload=()=>a(l.result),l.onerror=i,l.readAsDataURL(o)},R[t],r)});if(s.toDataURL!==void 0)return s.toDataURL(R[t],r);if(s.convertToBlob!==void 0){const a=await s.convertToBlob({type:R[t],quality:r});return new Promise((i,o)=>{const l=new FileReader;l.onload=()=>i(l.result),l.onerror=o,l.readAsDataURL(a)})}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 m)return r.texture.generateCanvas(t);const s=r.textureGenerator.generateTexture(e),a=r.texture.generateCanvas(s);return s.destroy(!0),a}pixels(e){e=this._normalizeOptions(e);const t=e.target,r=this._renderer,s=t instanceof m?t:r.textureGenerator.generateTexture(e),a=r.texture.getPixels(s);return t instanceof P&&s.destroy(!0),a}texture(e){return e=this._normalizeOptions(e),e.target instanceof m?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 a=["font-size: 1px;",`padding: ${t}px 300px;`,`background: url(${s}) no-repeat;`,"background-size: contain;"].join(" ");console.log("%c ",a)}destroy(){this._renderer=null}};N.extension={type:[u.WebGLSystem,u.WebGPUSystem],name:"extract"};N.defaultImageOptions={format:"png",quality:1};let xt=N;class j extends m{static create(e){return new j({source:new T(e)})}resize(e,t,r){return this.source.resize(e,t,r),this}}const _t=new w,bt=new F,Tt=[0,0,0,0];class Ge{constructor(e){this._renderer=e}generateTexture(e){var d;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 a=e.clearColor;a?a=Array.isArray(a)&&a.length===4?a:A.shared.setValue(a).toArray():a=Tt;const i=((d=e.frame)==null?void 0:d.copyTo(_t))||Ye(s,bt).rectangle;i.width=Math.max(i.width,1/t)|0,i.height=Math.max(i.height,1/t)|0;const o=j.create({...e.textureSourceOptions,width:i.width,height:i.height,resolution:t,antialias:r}),l=v.shared.translate(-i.x,-i.y);return this._renderer.render({container:s,transform:l,target:o,clearColor:a}),o.source.updateMipmaps(),o}destroy(){this._renderer=null}}Ge.extension={type:[u.WebGLSystem,u.WebGPUSystem],name:"textureGenerator"};class Ee{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:a}){const i=this._renderer.renderTarget.renderTarget,o=this._stackIndex?this._globalUniformDataStack[this._stackIndex-1]:{worldTransformMatrix:new v,worldColor:4294967295,offset:new Je},l={projectionMatrix:t||this._renderer.renderTarget.projectionMatrix,resolution:e||i.size,worldTransformMatrix:r||o.worldTransformMatrix,worldColor:s||o.worldColor,offset:a||o.offset,bindGroup:null},d=this._uniformsPool.pop()||this._createUniforms();this._activeUniforms.push(d);const c=d.uniforms;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,tt(l.worldColor,c.uWorldColorAlpha,0),d.update();let h;this._renderer.renderPipes.uniformBatch?h=this._renderer.renderPipes.uniformBatch.getUniformBindGroup(d,!1):(h=this._bindGroupPool.pop()||new Xe,this._activeBindGroups.push(h),h.setResource(d,0)),l.bindGroup=h,this._currentGlobalUniformData=l}push(e){this.bind(e),this._globalUniformDataStack[this._stackIndex++]=this._currentGlobalUniformData}pop(){this._currentGlobalUniformData=this._globalUniformDataStack[--this._stackIndex-1],this._renderer.type===L.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 v,type:"mat3x3<f32>"},uWorldTransformMatrix:{value:new v,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}}Ee.extension={type:[u.WebGLSystem,u.WebGPUSystem,u.CanvasSystem],name:"globalUniforms"};let yt=1;class De{constructor(){this._tasks=[],this._offset=0}init(){Z.system.add(this._update,this)}repeat(e,t,r=!0){const s=yt++;let a=0;return r&&(this._offset+=1e3,a=this._offset),this._tasks.push({func:e,duration:t,start:performance.now(),offset:a,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(){Z.system.remove(this._update,this),this._tasks.length=0}}De.extension={type:[u.WebGLSystem,u.WebGPUSystem,u.CanvasSystem],name:"scheduler",priority:0};let ae=!1;function kt(n){if(!ae){if(z.get().getNavigator().userAgent.toLowerCase().indexOf("chrome")>-1){const e=[`%c %c %c %c %c PixiJS %c v${ee} (${n}) http://www.pixijs.com/ + +`,"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 ${ee} - ${n} - http://www.pixijs.com/`);ae=!0}}class ${constructor(e){this._renderer=e}init(e){if(e.hello){let t=this._renderer.name;this._renderer.type===L.WEBGL&&(t+=` ${this._renderer.context.webGLVersion}`),kt(t)}}}$.extension={type:[u.WebGLSystem,u.WebGPUSystem,u.CanvasSystem],name:"hello",priority:-2};$.defaultOptions={hello:!1};function Ct(n){let e=!1;for(const r in n)if(n[r]==null){e=!0;break}if(!e)return n;const t=Object.create(null);for(const r in n){const s=n[r];s&&(t[r]=s)}return t}function Mt(n){let e=0;for(let t=0;t<n.length;t++)n[t]==null?e++:n[t-e]=n[t];return n.length-=e,n}let St=0;const q=class Oe{constructor(e){this._managedRenderables=[],this._managedHashes=[],this._managedArrays=[],this._renderer=e}init(e){e={...Oe.defaultOptions,...e},this.maxUnusedTime=e.renderableGCMaxUnusedTime,this._frequency=e.renderableGCFrequency,this.enabled=e.renderableGCActive}get enabled(){return!!this._handler}set enabled(e){this.enabled!==e&&(e?(this._handler=this._renderer.scheduler.repeat(()=>this.run(),this._frequency,!1),this._hashHandler=this._renderer.scheduler.repeat(()=>{for(const t of this._managedHashes)t.context[t.hash]=Ct(t.context[t.hash])},this._frequency),this._arrayHandler=this._renderer.scheduler.repeat(()=>{for(const t of this._managedArrays)Mt(t.context[t.hash])},this._frequency)):(this._renderer.scheduler.cancel(this._handler),this._renderer.scheduler.cancel(this._hashHandler),this._renderer.scheduler.cancel(this._arrayHandler)))}addManagedHash(e,t){this._managedHashes.push({context:e,hash:t})}addManagedArray(e,t){this._managedArrays.push({context:e,hash:t})}prerender({container:e}){this._now=performance.now(),e.renderGroup.gcTick=St++,this._updateInstructionGCTick(e.renderGroup,e.renderGroup.gcTick)}addRenderable(e){this.enabled&&(e._lastUsed===-1&&(this._managedRenderables.push(e),e.once("destroyed",this._removeRenderable,this)),e._lastUsed=this._now)}run(){var a;const e=this._now,t=this._managedRenderables,r=this._renderer.renderPipes;let s=0;for(let i=0;i<t.length;i++){const o=t[i];if(o===null){s++;continue}const l=o.renderGroup??o.parentRenderGroup,d=((a=l==null?void 0:l.instructionSet)==null?void 0:a.gcTick)??-1;if(((l==null?void 0:l.gcTick)??0)===d&&(o._lastUsed=e),e-o._lastUsed>this.maxUnusedTime){if(!o.destroyed){const c=r;l&&(l.structureDidChange=!0),c[o.renderPipeId].destroyRenderable(o)}o._lastUsed=-1,s++,o.off("destroyed",this._removeRenderable,this)}else t[i-s]=o}t.length-=s}destroy(){this.enabled=!1,this._renderer=null,this._managedRenderables.length=0,this._managedHashes.length=0,this._managedArrays.length=0}_removeRenderable(e){const t=this._managedRenderables.indexOf(e);t>=0&&(e.off("destroyed",this._removeRenderable,this),this._managedRenderables[t]=null)}_updateInstructionGCTick(e,t){e.instructionSet.gcTick=t;for(const r of e.renderGroupChildren)this._updateInstructionGCTick(r,t)}};q.extension={type:[u.WebGLSystem,u.WebGPUSystem],name:"renderableGC",priority:0};q.defaultOptions={renderableGCActive:!0,renderableGCMaxUnusedTime:6e4,renderableGCFrequency:3e4};let wt=q;const K=class Fe{constructor(e){this._renderer=e,this.count=0,this.checkCount=0}init(e){e={...Fe.defaultOptions,...e},this.checkCountMax=e.textureGCCheckCountMax,this.maxIdle=e.textureGCAMaxIdle??e.textureGCMaxIdle,this.active=e.textureGCActive}postrender(){this._renderer.renderingToScreen&&(this.count++,this.active&&(this.checkCount++,this.checkCount>this.checkCountMax&&(this.checkCount=0,this.run())))}run(){const e=this._renderer.texture.managedTextures;for(let t=0;t<e.length;t++){const r=e[t];r.autoGarbageCollect&&r.resource&&r._touched>-1&&this.count-r._touched>this.maxIdle&&(r._touched=-1,r.unload())}}destroy(){this._renderer=null}};K.extension={type:[u.WebGLSystem,u.WebGPUSystem],name:"textureGC"};K.defaultOptions={textureGCActive:!0,textureGCAMaxIdle:null,textureGCMaxIdle:60*60,textureGCCheckCountMax:600};let Pt=K;const Y=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&&(Qe(Ze,"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||z.get().createCanvas(),this.antialias=!!e.antialias,this.texture=ye(this.canvas,e),this.renderTarget=new G({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()}};Y.extension={type:[u.WebGLSystem,u.WebGPUSystem,u.CanvasSystem],name:"view",priority:0};Y.defaultOptions={width:800,height:600,autoDensity:!1,antialias:!1};let Rt=Y;const zt=[gt,Ee,$,Rt,Re,Pt,Ge,xt,et,wt,De],Wt=[Ae,xe,Be,Se,_e,Te,be,Me];export{Ht as B,_ as G,Lt as R,zt as S,Dt as U,Wt as a,ut as b,Ot as c,C as d,Et as e,Gt as f,It as t,Ft as u}; diff --git a/dist/assets/WebGLRenderer-BVO0qznQ.js b/dist/assets/WebGLRenderer-BVO0qznQ.js new file mode 100644 index 0000000..2c9172d --- /dev/null +++ b/dist/assets/WebGLRenderer-BVO0qznQ.js @@ -0,0 +1,156 @@ +import{E as d,B,w as m,D as S,J as K,t as Be,q as U,s as b,a5 as Ae,j as $,a6 as Ne,S as p,O as H,i as A,h as N,k as F,M as z,a7 as Y,a8 as ye,a9 as Ce,aa as q,ab as Ie,A as De,R as Ge,e as T}from"./index-DB6B0XuI.js";import{S as O,b as Z}from"./colorToUniform-DmtBy-2V.js";import{e as Ue,G as Fe,c as Oe,b as Pe,U as Me,R as Le,B as J,d as y,f as He,S as we,a as Ve}from"./SharedSystems-DVK37F7d.js";class Q{constructor(){this._tempState=O.for2d(),this._didUploadHash={}}init(e){e.renderer.runners.contextChange.add(this)}contextChange(){this._didUploadHash={}}start(e,r,s){const n=e.renderer,i=this._didUploadHash[s.uid];n.shader.bind(s,i),i||(this._didUploadHash[s.uid]=!0),n.shader.updateUniformGroup(n.globalUniforms.uniformGroup),n.geometry.bind(r,s.glProgram)}execute(e,r){const s=e.renderer;this._tempState.blendMode=r.blendMode,s.state.set(this._tempState);const n=r.textures.textures;for(let i=0;i<r.textures.count;i++)s.texture.bind(n[i],i);s.geometry.draw(r.topology,r.size,r.start)}}Q.extension={type:[d.WebGLPipesAdaptor],name:"batch"};var x=(t=>(t[t.ELEMENT_ARRAY_BUFFER=34963]="ELEMENT_ARRAY_BUFFER",t[t.ARRAY_BUFFER=34962]="ARRAY_BUFFER",t[t.UNIFORM_BUFFER=35345]="UNIFORM_BUFFER",t))(x||{});class ke{constructor(e,r){this._lastBindBaseLocation=-1,this._lastBindCallId=-1,this.buffer=e||null,this.updateID=-1,this.byteLength=-1,this.type=r}}class ee{constructor(e){this._gpuBuffers=Object.create(null),this._boundBufferBases=Object.create(null),this._minBaseLocation=0,this._nextBindBaseIndex=this._minBaseLocation,this._bindCallId=0,this._renderer=e,this._renderer.renderableGC.addManagedHash(this,"_gpuBuffers")}destroy(){this._renderer=null,this._gl=null,this._gpuBuffers=null,this._boundBufferBases=null}contextChange(){this._gl=this._renderer.gl,this._gpuBuffers=Object.create(null),this._maxBindings=this._renderer.limits.maxUniformBindings}getGlBuffer(e){return this._gpuBuffers[e.uid]||this.createGLBuffer(e)}bind(e){const{_gl:r}=this,s=this.getGlBuffer(e);r.bindBuffer(s.type,s.buffer)}bindBufferBase(e,r){const{_gl:s}=this;this._boundBufferBases[r]!==e&&(this._boundBufferBases[r]=e,e._lastBindBaseLocation=r,s.bindBufferBase(s.UNIFORM_BUFFER,r,e.buffer))}nextBindBase(e){this._bindCallId++,this._minBaseLocation=0,e&&(this._boundBufferBases[0]=null,this._minBaseLocation=1,this._nextBindBaseIndex<1&&(this._nextBindBaseIndex=1))}freeLocationForBufferBase(e){let r=this.getLastBindBaseLocation(e);if(r>=this._minBaseLocation)return e._lastBindCallId=this._bindCallId,r;let s=0,n=this._nextBindBaseIndex;for(;s<2;){n>=this._maxBindings&&(n=this._minBaseLocation,s++);const i=this._boundBufferBases[n];if(i&&i._lastBindCallId===this._bindCallId){n++;continue}break}return r=n,this._nextBindBaseIndex=n+1,s>=2?-1:(e._lastBindCallId=this._bindCallId,this._boundBufferBases[r]=null,r)}getLastBindBaseLocation(e){const r=e._lastBindBaseLocation;return this._boundBufferBases[r]===e?r:-1}bindBufferRange(e,r,s,n){const{_gl:i}=this;s||(s=0),r||(r=0),this._boundBufferBases[r]=null,i.bindBufferRange(i.UNIFORM_BUFFER,r||0,e.buffer,s*256,n||256)}updateBuffer(e){const{_gl:r}=this,s=this.getGlBuffer(e);if(e._updateID===s.updateID)return s;s.updateID=e._updateID,r.bindBuffer(s.type,s.buffer);const n=e.data,i=e.descriptor.usage&B.STATIC?r.STATIC_DRAW:r.DYNAMIC_DRAW;return n?s.byteLength>=n.byteLength?r.bufferSubData(s.type,0,n,0,e._updateSize/n.BYTES_PER_ELEMENT):(s.byteLength=n.byteLength,r.bufferData(s.type,n,i)):(s.byteLength=e.descriptor.size,r.bufferData(s.type,s.byteLength,i)),s}destroyAll(){const e=this._gl;for(const r in this._gpuBuffers)e.deleteBuffer(this._gpuBuffers[r].buffer);this._gpuBuffers=Object.create(null)}onBufferDestroy(e,r){const s=this._gpuBuffers[e.uid],n=this._gl;r||n.deleteBuffer(s.buffer),this._gpuBuffers[e.uid]=null}createGLBuffer(e){const{_gl:r}=this;let s=x.ARRAY_BUFFER;e.descriptor.usage&B.INDEX?s=x.ELEMENT_ARRAY_BUFFER:e.descriptor.usage&B.UNIFORM&&(s=x.UNIFORM_BUFFER);const n=new ke(r.createBuffer(),s);return this._gpuBuffers[e.uid]=n,e.on("destroy",this.onBufferDestroy,this),n}resetState(){this._boundBufferBases=Object.create(null)}}ee.extension={type:[d.WebGLSystem],name:"buffer"};const P=class te{constructor(e){this.supports={uint32Indices:!0,uniformBufferObject:!0,vertexArrayObject:!0,srgbTextures:!0,nonPowOf2wrapping:!0,msaa:!0,nonPowOf2mipmaps:!0},this._renderer=e,this.extensions=Object.create(null),this.handleContextLost=this.handleContextLost.bind(this),this.handleContextRestored=this.handleContextRestored.bind(this)}get isLost(){return!this.gl||this.gl.isContextLost()}contextChange(e){this.gl=e,this._renderer.gl=e}init(e){e={...te.defaultOptions,...e};let r=this.multiView=e.multiView;if(e.context&&r&&(m("Renderer created with both a context and multiview enabled. Disabling multiView as both cannot work together."),r=!1),r?this.canvas=S.get().createCanvas(this._renderer.canvas.width,this._renderer.canvas.height):this.canvas=this._renderer.view.canvas,e.context)this.initFromContext(e.context);else{const s=this._renderer.background.alpha<1,n=e.premultipliedAlpha??!0,i=e.antialias&&!this._renderer.backBuffer.useBackBuffer;this.createContext(e.preferWebGLVersion,{alpha:s,premultipliedAlpha:n,antialias:i,stencil:!0,preserveDrawingBuffer:e.preserveDrawingBuffer,powerPreference:e.powerPreference??"default"})}}ensureCanvasSize(e){if(!this.multiView){e!==this.canvas&&m("multiView is disabled, but targetCanvas is not the main canvas");return}const{canvas:r}=this;(r.width<e.width||r.height<e.height)&&(r.width=Math.max(e.width,e.width),r.height=Math.max(e.height,e.height))}initFromContext(e){this.gl=e,this.webGLVersion=e instanceof S.get().getWebGLRenderingContext()?1:2,this.getExtensions(),this.validateContext(e),this._renderer.runners.contextChange.emit(e);const r=this._renderer.view.canvas;r.addEventListener("webglcontextlost",this.handleContextLost,!1),r.addEventListener("webglcontextrestored",this.handleContextRestored,!1)}createContext(e,r){let s;const n=this.canvas;if(e===2&&(s=n.getContext("webgl2",r)),!s&&(s=n.getContext("webgl",r),!s))throw new Error("This browser does not support WebGL. Try using the canvas renderer");this.gl=s,this.initFromContext(this.gl)}getExtensions(){const{gl:e}=this,r={anisotropicFiltering:e.getExtension("EXT_texture_filter_anisotropic"),floatTextureLinear:e.getExtension("OES_texture_float_linear"),s3tc:e.getExtension("WEBGL_compressed_texture_s3tc"),s3tc_sRGB:e.getExtension("WEBGL_compressed_texture_s3tc_srgb"),etc:e.getExtension("WEBGL_compressed_texture_etc"),etc1:e.getExtension("WEBGL_compressed_texture_etc1"),pvrtc:e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),atc:e.getExtension("WEBGL_compressed_texture_atc"),astc:e.getExtension("WEBGL_compressed_texture_astc"),bptc:e.getExtension("EXT_texture_compression_bptc"),rgtc:e.getExtension("EXT_texture_compression_rgtc"),loseContext:e.getExtension("WEBGL_lose_context")};if(this.webGLVersion===1)this.extensions={...r,drawBuffers:e.getExtension("WEBGL_draw_buffers"),depthTexture:e.getExtension("WEBGL_depth_texture"),vertexArrayObject:e.getExtension("OES_vertex_array_object")||e.getExtension("MOZ_OES_vertex_array_object")||e.getExtension("WEBKIT_OES_vertex_array_object"),uint32ElementIndex:e.getExtension("OES_element_index_uint"),floatTexture:e.getExtension("OES_texture_float"),floatTextureLinear:e.getExtension("OES_texture_float_linear"),textureHalfFloat:e.getExtension("OES_texture_half_float"),textureHalfFloatLinear:e.getExtension("OES_texture_half_float_linear"),vertexAttribDivisorANGLE:e.getExtension("ANGLE_instanced_arrays"),srgb:e.getExtension("EXT_sRGB")};else{this.extensions={...r,colorBufferFloat:e.getExtension("EXT_color_buffer_float")};const s=e.getExtension("WEBGL_provoking_vertex");s&&s.provokingVertexWEBGL(s.FIRST_VERTEX_CONVENTION_WEBGL)}}handleContextLost(e){e.preventDefault(),this._contextLossForced&&(this._contextLossForced=!1,setTimeout(()=>{var r;this.gl.isContextLost()&&((r=this.extensions.loseContext)==null||r.restoreContext())},0))}handleContextRestored(){this.getExtensions(),this._renderer.runners.contextChange.emit(this.gl)}destroy(){var r;const e=this._renderer.view.canvas;this._renderer=null,e.removeEventListener("webglcontextlost",this.handleContextLost),e.removeEventListener("webglcontextrestored",this.handleContextRestored),this.gl.useProgram(null),(r=this.extensions.loseContext)==null||r.loseContext()}forceContextLoss(){var e;(e=this.extensions.loseContext)==null||e.loseContext(),this._contextLossForced=!0}validateContext(e){const r=e.getContextAttributes();r&&!r.stencil&&m("Provided WebGL context does not have a stencil buffer, masks may not render correctly");const s=this.supports,n=this.webGLVersion===2,i=this.extensions;s.uint32Indices=n||!!i.uint32ElementIndex,s.uniformBufferObject=n,s.vertexArrayObject=n||!!i.vertexArrayObject,s.srgbTextures=n||!!i.srgb,s.nonPowOf2wrapping=n,s.nonPowOf2mipmaps=n,s.msaa=n,s.uint32Indices||m("Provided WebGL context does not support 32 index buffer, large scenes may not render correctly")}};P.extension={type:[d.WebGLSystem],name:"context"};P.defaultOptions={context:null,premultipliedAlpha:!0,preserveDrawingBuffer:!1,powerPreference:void 0,preferWebGLVersion:2,multiView:!1};let Xe=P;var D=(t=>(t[t.RGBA=6408]="RGBA",t[t.RGB=6407]="RGB",t[t.RG=33319]="RG",t[t.RED=6403]="RED",t[t.RGBA_INTEGER=36249]="RGBA_INTEGER",t[t.RGB_INTEGER=36248]="RGB_INTEGER",t[t.RG_INTEGER=33320]="RG_INTEGER",t[t.RED_INTEGER=36244]="RED_INTEGER",t[t.ALPHA=6406]="ALPHA",t[t.LUMINANCE=6409]="LUMINANCE",t[t.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA",t[t.DEPTH_COMPONENT=6402]="DEPTH_COMPONENT",t[t.DEPTH_STENCIL=34041]="DEPTH_STENCIL",t))(D||{}),re=(t=>(t[t.TEXTURE_2D=3553]="TEXTURE_2D",t[t.TEXTURE_CUBE_MAP=34067]="TEXTURE_CUBE_MAP",t[t.TEXTURE_2D_ARRAY=35866]="TEXTURE_2D_ARRAY",t[t.TEXTURE_CUBE_MAP_POSITIVE_X=34069]="TEXTURE_CUBE_MAP_POSITIVE_X",t[t.TEXTURE_CUBE_MAP_NEGATIVE_X=34070]="TEXTURE_CUBE_MAP_NEGATIVE_X",t[t.TEXTURE_CUBE_MAP_POSITIVE_Y=34071]="TEXTURE_CUBE_MAP_POSITIVE_Y",t[t.TEXTURE_CUBE_MAP_NEGATIVE_Y=34072]="TEXTURE_CUBE_MAP_NEGATIVE_Y",t[t.TEXTURE_CUBE_MAP_POSITIVE_Z=34073]="TEXTURE_CUBE_MAP_POSITIVE_Z",t[t.TEXTURE_CUBE_MAP_NEGATIVE_Z=34074]="TEXTURE_CUBE_MAP_NEGATIVE_Z",t))(re||{}),h=(t=>(t[t.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",t[t.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",t[t.UNSIGNED_SHORT_5_6_5=33635]="UNSIGNED_SHORT_5_6_5",t[t.UNSIGNED_SHORT_4_4_4_4=32819]="UNSIGNED_SHORT_4_4_4_4",t[t.UNSIGNED_SHORT_5_5_5_1=32820]="UNSIGNED_SHORT_5_5_5_1",t[t.UNSIGNED_INT=5125]="UNSIGNED_INT",t[t.UNSIGNED_INT_10F_11F_11F_REV=35899]="UNSIGNED_INT_10F_11F_11F_REV",t[t.UNSIGNED_INT_2_10_10_10_REV=33640]="UNSIGNED_INT_2_10_10_10_REV",t[t.UNSIGNED_INT_24_8=34042]="UNSIGNED_INT_24_8",t[t.UNSIGNED_INT_5_9_9_9_REV=35902]="UNSIGNED_INT_5_9_9_9_REV",t[t.BYTE=5120]="BYTE",t[t.SHORT=5122]="SHORT",t[t.INT=5124]="INT",t[t.FLOAT=5126]="FLOAT",t[t.FLOAT_32_UNSIGNED_INT_24_8_REV=36269]="FLOAT_32_UNSIGNED_INT_24_8_REV",t[t.HALF_FLOAT=36193]="HALF_FLOAT",t))(h||{});const w={uint8x2:h.UNSIGNED_BYTE,uint8x4:h.UNSIGNED_BYTE,sint8x2:h.BYTE,sint8x4:h.BYTE,unorm8x2:h.UNSIGNED_BYTE,unorm8x4:h.UNSIGNED_BYTE,snorm8x2:h.BYTE,snorm8x4:h.BYTE,uint16x2:h.UNSIGNED_SHORT,uint16x4:h.UNSIGNED_SHORT,sint16x2:h.SHORT,sint16x4:h.SHORT,unorm16x2:h.UNSIGNED_SHORT,unorm16x4:h.UNSIGNED_SHORT,snorm16x2:h.SHORT,snorm16x4:h.SHORT,float16x2:h.HALF_FLOAT,float16x4:h.HALF_FLOAT,float32:h.FLOAT,float32x2:h.FLOAT,float32x3:h.FLOAT,float32x4:h.FLOAT,uint32:h.UNSIGNED_INT,uint32x2:h.UNSIGNED_INT,uint32x3:h.UNSIGNED_INT,uint32x4:h.UNSIGNED_INT,sint32:h.INT,sint32x2:h.INT,sint32x3:h.INT,sint32x4:h.INT};function We(t){return w[t]??w.float32}const je={"point-list":0,"line-list":1,"line-strip":3,"triangle-list":4,"triangle-strip":5};class se{constructor(e){this._geometryVaoHash=Object.create(null),this._renderer=e,this._activeGeometry=null,this._activeVao=null,this.hasVao=!0,this.hasInstance=!0,this._renderer.renderableGC.addManagedHash(this,"_geometryVaoHash")}contextChange(){const e=this.gl=this._renderer.gl;if(!this._renderer.context.supports.vertexArrayObject)throw new Error("[PixiJS] Vertex Array Objects are not supported on this device");const r=this._renderer.context.extensions.vertexArrayObject;r&&(e.createVertexArray=()=>r.createVertexArrayOES(),e.bindVertexArray=n=>r.bindVertexArrayOES(n),e.deleteVertexArray=n=>r.deleteVertexArrayOES(n));const s=this._renderer.context.extensions.vertexAttribDivisorANGLE;s&&(e.drawArraysInstanced=(n,i,a,o)=>{s.drawArraysInstancedANGLE(n,i,a,o)},e.drawElementsInstanced=(n,i,a,o,c)=>{s.drawElementsInstancedANGLE(n,i,a,o,c)},e.vertexAttribDivisor=(n,i)=>s.vertexAttribDivisorANGLE(n,i)),this._activeGeometry=null,this._activeVao=null,this._geometryVaoHash=Object.create(null)}bind(e,r){const s=this.gl;this._activeGeometry=e;const n=this.getVao(e,r);this._activeVao!==n&&(this._activeVao=n,s.bindVertexArray(n)),this.updateBuffers()}resetState(){this.unbind()}updateBuffers(){const e=this._activeGeometry,r=this._renderer.buffer;for(let s=0;s<e.buffers.length;s++){const n=e.buffers[s];r.updateBuffer(n)}}checkCompatibility(e,r){const s=e.attributes,n=r._attributeData;for(const i in n)if(!s[i])throw new Error(`shader and geometry incompatible, geometry missing the "${i}" attribute`)}getSignature(e,r){const s=e.attributes,n=r._attributeData,i=["g",e.uid];for(const a in s)n[a]&&i.push(a,n[a].location);return i.join("-")}getVao(e,r){var s;return((s=this._geometryVaoHash[e.uid])==null?void 0:s[r._key])||this.initGeometryVao(e,r)}initGeometryVao(e,r,s=!0){const n=this._renderer.gl,i=this._renderer.buffer;this._renderer.shader._getProgramData(r),this.checkCompatibility(e,r);const a=this.getSignature(e,r);this._geometryVaoHash[e.uid]||(this._geometryVaoHash[e.uid]=Object.create(null),e.on("destroy",this.onGeometryDestroy,this));const o=this._geometryVaoHash[e.uid];let c=o[a];if(c)return o[r._key]=c,c;Ue(e,r._attributeData);const u=e.buffers;c=n.createVertexArray(),n.bindVertexArray(c);for(let _=0;_<u.length;_++){const f=u[_];i.bind(f)}return this.activateVao(e,r),o[r._key]=c,o[a]=c,n.bindVertexArray(null),c}onGeometryDestroy(e,r){const s=this._geometryVaoHash[e.uid],n=this.gl;if(s){if(r)for(const i in s)this._activeVao!==s[i]&&this.unbind(),n.deleteVertexArray(s[i]);this._geometryVaoHash[e.uid]=null}}destroyAll(e=!1){const r=this.gl;for(const s in this._geometryVaoHash){if(e)for(const n in this._geometryVaoHash[s]){const i=this._geometryVaoHash[s];this._activeVao!==i&&this.unbind(),r.deleteVertexArray(i[n])}this._geometryVaoHash[s]=null}}activateVao(e,r){var o;const s=this._renderer.gl,n=this._renderer.buffer,i=e.attributes;e.indexBuffer&&n.bind(e.indexBuffer);let a=null;for(const c in i){const u=i[c],_=u.buffer,f=n.getGlBuffer(_),l=r._attributeData[c];if(l){a!==f&&(n.bind(_),a=f);const E=l.location;s.enableVertexAttribArray(E);const v=K(u.format),L=We(u.format);if(((o=l.format)==null?void 0:o.substring(1,4))==="int"?s.vertexAttribIPointer(E,v.size,L,u.stride,u.offset):s.vertexAttribPointer(E,v.size,L,v.normalised,u.stride,u.offset),u.instance)if(this.hasInstance){const ve=u.divisor??1;s.vertexAttribDivisor(E,ve)}else throw new Error("geometry error, GPU Instancing is not supported on this device")}}}draw(e,r,s,n){const{gl:i}=this._renderer,a=this._activeGeometry,o=je[e||a.topology];if(n??(n=a.instanceCount),a.indexBuffer){const c=a.indexBuffer.data.BYTES_PER_ELEMENT,u=c===2?i.UNSIGNED_SHORT:i.UNSIGNED_INT;n>1?i.drawElementsInstanced(o,r||a.indexBuffer.data.length,u,(s||0)*c,n):i.drawElements(o,r||a.indexBuffer.data.length,u,(s||0)*c)}else n>1?i.drawArraysInstanced(o,s||0,r||a.getSize(),n):i.drawArrays(o,s||0,r||a.getSize());return this}unbind(){this.gl.bindVertexArray(null),this._activeVao=null,this._activeGeometry=null}destroy(){this._renderer=null,this.gl=null,this._activeVao=null,this._activeGeometry=null,this._geometryVaoHash=null}}se.extension={type:[d.WebGLSystem],name:"geometry"};const Ke=new Ae({attributes:{aPosition:[-1,-1,3,-1,-1,3]}}),M=class ne{constructor(e){this.useBackBuffer=!1,this._useBackBufferThisRender=!1,this._renderer=e}init(e={}){const{useBackBuffer:r,antialias:s}={...ne.defaultOptions,...e};this.useBackBuffer=r,this._antialias=s,this._renderer.context.supports.msaa||(m("antialiasing, is not supported on when using the back buffer"),this._antialias=!1),this._state=O.for2d();const n=new Be({vertex:` + attribute vec2 aPosition; + out vec2 vUv; + + void main() { + gl_Position = vec4(aPosition, 0.0, 1.0); + + vUv = (aPosition + 1.0) / 2.0; + + // flip dem UVs + vUv.y = 1.0 - vUv.y; + }`,fragment:` + in vec2 vUv; + out vec4 finalColor; + + uniform sampler2D uTexture; + + void main() { + finalColor = texture(uTexture, vUv); + }`,name:"big-triangle"});this._bigTriangleShader=new U({glProgram:n,resources:{uTexture:b.WHITE.source}})}renderStart(e){const r=this._renderer.renderTarget.getRenderTarget(e.target);if(this._useBackBufferThisRender=this.useBackBuffer&&!!r.isRoot,this._useBackBufferThisRender){const s=this._renderer.renderTarget.getRenderTarget(e.target);this._targetTexture=s.colorTexture,e.target=this._getBackBufferTexture(s.colorTexture)}}renderEnd(){this._presentBackBuffer()}_presentBackBuffer(){const e=this._renderer;e.renderTarget.finishRenderPass(),this._useBackBufferThisRender&&(e.renderTarget.bind(this._targetTexture,!1),this._bigTriangleShader.resources.uTexture=this._backBufferTexture.source,e.encoder.draw({geometry:Ke,shader:this._bigTriangleShader,state:this._state}))}_getBackBufferTexture(e){return this._backBufferTexture=this._backBufferTexture||new b({source:new $({width:e.width,height:e.height,resolution:e._resolution,antialias:this._antialias})}),this._backBufferTexture.source.resize(e.width,e.height,e._resolution),this._backBufferTexture}destroy(){this._backBufferTexture&&(this._backBufferTexture.destroy(),this._backBufferTexture=null)}};M.extension={type:[d.WebGLSystem],name:"backBuffer",priority:1};M.defaultOptions={useBackBuffer:!1};let $e=M;class ie{constructor(e){this._colorMaskCache=15,this._renderer=e}setMask(e){this._colorMaskCache!==e&&(this._colorMaskCache=e,this._renderer.gl.colorMask(!!(e&8),!!(e&4),!!(e&2),!!(e&1)))}}ie.extension={type:[d.WebGLSystem],name:"colorMask"};class ae{constructor(e){this.commandFinished=Promise.resolve(),this._renderer=e}setGeometry(e,r){this._renderer.geometry.bind(e,r.glProgram)}finishRenderPass(){}draw(e){const r=this._renderer,{geometry:s,shader:n,state:i,skipSync:a,topology:o,size:c,start:u,instanceCount:_}=e;r.shader.bind(n,a),r.geometry.bind(s,r.shader._activeProgram),i&&r.state.set(i),r.geometry.draw(o,c,u,_??s.instanceCount)}destroy(){this._renderer=null}}ae.extension={type:[d.WebGLSystem],name:"encoder"};class oe{constructor(e){this._renderer=e}contextChange(){const e=this._renderer.gl;this.maxTextures=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),this.maxBatchableTextures=Ne(this.maxTextures,e);const r=this._renderer.context.webGLVersion===2;this.maxUniformBindings=r?e.getParameter(e.MAX_UNIFORM_BUFFER_BINDINGS):0}destroy(){}}oe.extension={type:[d.WebGLSystem],name:"limits"};class ze{constructor(){this.width=-1,this.height=-1,this.msaa=!1,this.msaaRenderBuffer=[]}}class ce{constructor(e){this._stencilCache={enabled:!1,stencilReference:0,stencilMode:p.NONE},this._renderTargetStencilState=Object.create(null),e.renderTarget.onRenderTargetChange.add(this)}contextChange(e){this._gl=e,this._comparisonFuncMapping={always:e.ALWAYS,never:e.NEVER,equal:e.EQUAL,"not-equal":e.NOTEQUAL,less:e.LESS,"less-equal":e.LEQUAL,greater:e.GREATER,"greater-equal":e.GEQUAL},this._stencilOpsMapping={keep:e.KEEP,zero:e.ZERO,replace:e.REPLACE,invert:e.INVERT,"increment-clamp":e.INCR,"decrement-clamp":e.DECR,"increment-wrap":e.INCR_WRAP,"decrement-wrap":e.DECR_WRAP},this.resetState()}onRenderTargetChange(e){if(this._activeRenderTarget===e)return;this._activeRenderTarget=e;let r=this._renderTargetStencilState[e.uid];r||(r=this._renderTargetStencilState[e.uid]={stencilMode:p.DISABLED,stencilReference:0}),this.setStencilMode(r.stencilMode,r.stencilReference)}resetState(){this._stencilCache.enabled=!1,this._stencilCache.stencilMode=p.NONE,this._stencilCache.stencilReference=0}setStencilMode(e,r){const s=this._renderTargetStencilState[this._activeRenderTarget.uid],n=this._gl,i=Fe[e],a=this._stencilCache;if(s.stencilMode=e,s.stencilReference=r,e===p.DISABLED){this._stencilCache.enabled&&(this._stencilCache.enabled=!1,n.disable(n.STENCIL_TEST));return}this._stencilCache.enabled||(this._stencilCache.enabled=!0,n.enable(n.STENCIL_TEST)),(e!==a.stencilMode||a.stencilReference!==r)&&(a.stencilMode=e,a.stencilReference=r,n.stencilFunc(this._comparisonFuncMapping[i.stencilBack.compare],r,255),n.stencilOp(n.KEEP,n.KEEP,this._stencilOpsMapping[i.stencilBack.passOp]))}}ce.extension={type:[d.WebGLSystem],name:"stencil"};const ue={f32:4,i32:4,"vec2<f32>":8,"vec3<f32>":12,"vec4<f32>":16,"vec2<i32>":8,"vec3<i32>":12,"vec4<i32>":16,"mat2x2<f32>":16*2,"mat3x3<f32>":16*3,"mat4x4<f32>":16*4};function Ye(t){const e=t.map(i=>({data:i,offset:0,size:0})),r=16;let s=0,n=0;for(let i=0;i<e.length;i++){const a=e[i];if(s=ue[a.data.type],!s)throw new Error(`Unknown type ${a.data.type}`);a.data.size>1&&(s=Math.max(s,r)*a.data.size);const o=s===12?16:s;a.size=s;const c=n%r;c>0&&r-c<o?n+=(r-c)%16:n+=(s-c%s)%s,a.offset=n,n+=s}return n=Math.ceil(n/16)*16,{uboElements:e,size:n}}function qe(t,e){const r=Math.max(ue[t.data.type]/16,1),s=t.data.value.length/t.data.size,n=(4-s%4)%4,i=t.data.type.indexOf("i32")>=0?"dataInt32":"data";return` + v = uv.${t.data.name}; + offset += ${e}; + + arrayOffset = offset; + + t = 0; + + for(var i=0; i < ${t.data.size*r}; i++) + { + for(var j = 0; j < ${s}; j++) + { + ${i}[arrayOffset++] = v[t++]; + } + ${n!==0?`arrayOffset += ${n};`:""} + } + `}function Ze(t){return Oe(t,"uboStd40",qe,Pe)}class _e extends Me{constructor(){super({createUboElements:Ye,generateUboSync:Ze})}}_e.extension={type:[d.WebGLSystem],name:"ubo"};class Je{constructor(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new H}init(e,r){this._renderer=e,this._renderTargetSystem=r,e.runners.contextChange.add(this)}contextChange(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new H}copyToTexture(e,r,s,n,i){const a=this._renderTargetSystem,o=this._renderer,c=a.getGpuRenderTarget(e),u=o.gl;return this.finishRenderPass(e),u.bindFramebuffer(u.FRAMEBUFFER,c.resolveTargetFramebuffer),o.texture.bind(r,0),u.copyTexSubImage2D(u.TEXTURE_2D,0,i.x,i.y,s.x,s.y,n.width,n.height),r}startRenderPass(e,r=!0,s,n){const i=this._renderTargetSystem,a=e.colorTexture,o=i.getGpuRenderTarget(e);let c=n.y;e.isRoot&&(c=a.pixelHeight-n.height),e.colorTextures.forEach(f=>{this._renderer.texture.unbind(f)});const u=this._renderer.gl;u.bindFramebuffer(u.FRAMEBUFFER,o.framebuffer);const _=this._viewPortCache;(_.x!==n.x||_.y!==c||_.width!==n.width||_.height!==n.height)&&(_.x=n.x,_.y=c,_.width=n.width,_.height=n.height,u.viewport(n.x,c,n.width,n.height)),!o.depthStencilRenderBuffer&&(e.stencil||e.depth)&&this._initStencil(o),this.clear(e,r,s)}finishRenderPass(e){const s=this._renderTargetSystem.getGpuRenderTarget(e);if(!s.msaa)return;const n=this._renderer.gl;n.bindFramebuffer(n.FRAMEBUFFER,s.resolveTargetFramebuffer),n.bindFramebuffer(n.READ_FRAMEBUFFER,s.framebuffer),n.blitFramebuffer(0,0,s.width,s.height,0,0,s.width,s.height,n.COLOR_BUFFER_BIT,n.NEAREST),n.bindFramebuffer(n.FRAMEBUFFER,s.framebuffer)}initGpuRenderTarget(e){const s=this._renderer.gl,n=new ze;return e.colorTexture instanceof A?(this._renderer.context.ensureCanvasSize(e.colorTexture.resource),n.framebuffer=null,n):(this._initColor(e,n),s.bindFramebuffer(s.FRAMEBUFFER,null),n)}destroyGpuRenderTarget(e){const r=this._renderer.gl;e.framebuffer&&(r.deleteFramebuffer(e.framebuffer),e.framebuffer=null),e.resolveTargetFramebuffer&&(r.deleteFramebuffer(e.resolveTargetFramebuffer),e.resolveTargetFramebuffer=null),e.depthStencilRenderBuffer&&(r.deleteRenderbuffer(e.depthStencilRenderBuffer),e.depthStencilRenderBuffer=null),e.msaaRenderBuffer.forEach(s=>{r.deleteRenderbuffer(s)}),e.msaaRenderBuffer=null}clear(e,r,s){if(!r)return;const n=this._renderTargetSystem;typeof r=="boolean"&&(r=r?N.ALL:N.NONE);const i=this._renderer.gl;if(r&N.COLOR){s??(s=n.defaultClearColor);const a=this._clearColorCache,o=s;(a[0]!==o[0]||a[1]!==o[1]||a[2]!==o[2]||a[3]!==o[3])&&(a[0]=o[0],a[1]=o[1],a[2]=o[2],a[3]=o[3],i.clearColor(o[0],o[1],o[2],o[3]))}i.clear(r)}resizeGpuRenderTarget(e){if(e.isRoot)return;const s=this._renderTargetSystem.getGpuRenderTarget(e);this._resizeColor(e,s),(e.stencil||e.depth)&&this._resizeStencil(s)}_initColor(e,r){const s=this._renderer,n=s.gl,i=n.createFramebuffer();if(r.resolveTargetFramebuffer=i,n.bindFramebuffer(n.FRAMEBUFFER,i),r.width=e.colorTexture.source.pixelWidth,r.height=e.colorTexture.source.pixelHeight,e.colorTextures.forEach((a,o)=>{const c=a.source;c.antialias&&(s.context.supports.msaa?r.msaa=!0:m("[RenderTexture] Antialiasing on textures is not supported in WebGL1")),s.texture.bindSource(c,0);const _=s.texture.getGlSource(c).texture;n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0+o,3553,_,0)}),r.msaa){const a=n.createFramebuffer();r.framebuffer=a,n.bindFramebuffer(n.FRAMEBUFFER,a),e.colorTextures.forEach((o,c)=>{const u=n.createRenderbuffer();r.msaaRenderBuffer[c]=u})}else r.framebuffer=i;this._resizeColor(e,r)}_resizeColor(e,r){const s=e.colorTexture.source;if(r.width=s.pixelWidth,r.height=s.pixelHeight,e.colorTextures.forEach((n,i)=>{i!==0&&n.source.resize(s.width,s.height,s._resolution)}),r.msaa){const n=this._renderer,i=n.gl,a=r.framebuffer;i.bindFramebuffer(i.FRAMEBUFFER,a),e.colorTextures.forEach((o,c)=>{const u=o.source;n.texture.bindSource(u,0);const f=n.texture.getGlSource(u).internalFormat,l=r.msaaRenderBuffer[c];i.bindRenderbuffer(i.RENDERBUFFER,l),i.renderbufferStorageMultisample(i.RENDERBUFFER,4,f,u.pixelWidth,u.pixelHeight),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0+c,i.RENDERBUFFER,l)})}}_initStencil(e){if(e.framebuffer===null)return;const r=this._renderer.gl,s=r.createRenderbuffer();e.depthStencilRenderBuffer=s,r.bindRenderbuffer(r.RENDERBUFFER,s),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.DEPTH_STENCIL_ATTACHMENT,r.RENDERBUFFER,s),this._resizeStencil(e)}_resizeStencil(e){const r=this._renderer.gl;r.bindRenderbuffer(r.RENDERBUFFER,e.depthStencilRenderBuffer),e.msaa?r.renderbufferStorageMultisample(r.RENDERBUFFER,4,r.DEPTH24_STENCIL8,e.width,e.height):r.renderbufferStorage(r.RENDERBUFFER,this._renderer.context.webGLVersion===2?r.DEPTH24_STENCIL8:r.DEPTH_STENCIL,e.width,e.height)}prerender(e){const r=e.colorTexture.resource;this._renderer.context.multiView&&A.test(r)&&this._renderer.context.ensureCanvasSize(r)}postrender(e){if(this._renderer.context.multiView&&A.test(e.colorTexture.resource)){const r=this._renderer.context.canvas,s=e.colorTexture;s.context2D.drawImage(r,0,s.pixelHeight-r.height)}}}class he extends Le{constructor(e){super(e),this.adaptor=new Je,this.adaptor.init(e,this)}}he.extension={type:[d.WebGLSystem],name:"renderTarget"};function Qe(t,e){const r=[],s=[` + var g = s.groups; + var sS = r.shader; + var p = s.glProgram; + var ugS = r.uniformGroup; + var resources; + `];let n=!1,i=0;const a=e._getProgramData(t.glProgram);for(const c in t.groups){const u=t.groups[c];r.push(` + resources = g[${c}].resources; + `);for(const _ in u.resources){const f=u.resources[_];if(f instanceof F)if(f.ubo){const l=t._uniformBindMap[c][Number(_)];r.push(` + sS.bindUniformBlock( + resources[${_}], + '${l}', + ${t.glProgram._uniformBlockData[l].index} + ); + `)}else r.push(` + ugS.updateUniformGroup(resources[${_}], p, sD); + `);else if(f instanceof J){const l=t._uniformBindMap[c][Number(_)];r.push(` + sS.bindUniformBlock( + resources[${_}], + '${l}', + ${t.glProgram._uniformBlockData[l].index} + ); + `)}else if(f instanceof $){const l=t._uniformBindMap[c][_],E=a.uniformData[l];E&&(n||(n=!0,s.push(` + var tS = r.texture; + `)),e._gl.uniform1i(E.location,i),r.push(` + tS.bind(resources[${_}], ${i}); + `),i++)}}}const o=[...s,...r].join(` +`);return new Function("r","s","sD",o)}class et{constructor(e,r){this.program=e,this.uniformData=r,this.uniformGroups={},this.uniformDirtyGroups={},this.uniformBlockBindings={}}destroy(){this.uniformData=null,this.uniformGroups=null,this.uniformDirtyGroups=null,this.uniformBlockBindings=null,this.program=null}}function V(t,e,r){const s=t.createShader(e);return t.shaderSource(s,r),t.compileShader(s),s}function C(t){const e=new Array(t);for(let r=0;r<e.length;r++)e[r]=!1;return e}function fe(t,e){switch(t){case"float":return 0;case"vec2":return new Float32Array(2*e);case"vec3":return new Float32Array(3*e);case"vec4":return new Float32Array(4*e);case"int":case"uint":case"sampler2D":case"sampler2DArray":return 0;case"ivec2":return new Int32Array(2*e);case"ivec3":return new Int32Array(3*e);case"ivec4":return new Int32Array(4*e);case"uvec2":return new Uint32Array(2*e);case"uvec3":return new Uint32Array(3*e);case"uvec4":return new Uint32Array(4*e);case"bool":return!1;case"bvec2":return C(2*e);case"bvec3":return C(3*e);case"bvec4":return C(4*e);case"mat2":return new Float32Array([1,0,0,1]);case"mat3":return new Float32Array([1,0,0,0,1,0,0,0,1]);case"mat4":return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}return null}let g=null;const k={FLOAT:"float",FLOAT_VEC2:"vec2",FLOAT_VEC3:"vec3",FLOAT_VEC4:"vec4",INT:"int",INT_VEC2:"ivec2",INT_VEC3:"ivec3",INT_VEC4:"ivec4",UNSIGNED_INT:"uint",UNSIGNED_INT_VEC2:"uvec2",UNSIGNED_INT_VEC3:"uvec3",UNSIGNED_INT_VEC4:"uvec4",BOOL:"bool",BOOL_VEC2:"bvec2",BOOL_VEC3:"bvec3",BOOL_VEC4:"bvec4",FLOAT_MAT2:"mat2",FLOAT_MAT3:"mat3",FLOAT_MAT4:"mat4",SAMPLER_2D:"sampler2D",INT_SAMPLER_2D:"sampler2D",UNSIGNED_INT_SAMPLER_2D:"sampler2D",SAMPLER_CUBE:"samplerCube",INT_SAMPLER_CUBE:"samplerCube",UNSIGNED_INT_SAMPLER_CUBE:"samplerCube",SAMPLER_2D_ARRAY:"sampler2DArray",INT_SAMPLER_2D_ARRAY:"sampler2DArray",UNSIGNED_INT_SAMPLER_2D_ARRAY:"sampler2DArray"},tt={float:"float32",vec2:"float32x2",vec3:"float32x3",vec4:"float32x4",int:"sint32",ivec2:"sint32x2",ivec3:"sint32x3",ivec4:"sint32x4",uint:"uint32",uvec2:"uint32x2",uvec3:"uint32x3",uvec4:"uint32x4",bool:"uint32",bvec2:"uint32x2",bvec3:"uint32x3",bvec4:"uint32x4"};function le(t,e){if(!g){const r=Object.keys(k);g={};for(let s=0;s<r.length;++s){const n=r[s];g[t[n]]=k[n]}}return g[e]}function rt(t,e){const r=le(t,e);return tt[r]||"float32"}function st(t,e,r=!1){const s={},n=e.getProgramParameter(t,e.ACTIVE_ATTRIBUTES);for(let a=0;a<n;a++){const o=e.getActiveAttrib(t,a);if(o.name.startsWith("gl_"))continue;const c=rt(e,o.type);s[o.name]={location:0,format:c,stride:K(c).stride,offset:0,instance:!1,start:0}}const i=Object.keys(s);if(r){i.sort((a,o)=>a>o?1:-1);for(let a=0;a<i.length;a++)s[i[a]].location=a,e.bindAttribLocation(t,a,i[a]);e.linkProgram(t)}else for(let a=0;a<i.length;a++)s[i[a]].location=e.getAttribLocation(t,i[a]);return s}function nt(t,e){if(!e.ACTIVE_UNIFORM_BLOCKS)return{};const r={},s=e.getProgramParameter(t,e.ACTIVE_UNIFORM_BLOCKS);for(let n=0;n<s;n++){const i=e.getActiveUniformBlockName(t,n),a=e.getUniformBlockIndex(t,i),o=e.getActiveUniformBlockParameter(t,n,e.UNIFORM_BLOCK_DATA_SIZE);r[i]={name:i,index:a,size:o}}return r}function it(t,e){const r={},s=e.getProgramParameter(t,e.ACTIVE_UNIFORMS);for(let n=0;n<s;n++){const i=e.getActiveUniform(t,n),a=i.name.replace(/\[.*?\]$/,""),o=!!i.name.match(/\[.*?\]$/),c=le(e,i.type);r[a]={name:a,index:n,type:c,size:i.size,isArray:o,value:fe(c,i.size)}}return r}function X(t,e){const r=t.getShaderSource(e).split(` +`).map((u,_)=>`${_}: ${u}`),s=t.getShaderInfoLog(e),n=s.split(` +`),i={},a=n.map(u=>parseFloat(u.replace(/^ERROR\: 0\:([\d]+)\:.*$/,"$1"))).filter(u=>u&&!i[u]?(i[u]=!0,!0):!1),o=[""];a.forEach(u=>{r[u-1]=`%c${r[u-1]}%c`,o.push("background: #FF0000; color:#FFFFFF; font-size: 10px","font-size: 10px")});const c=r.join(` +`);o[0]=c,console.error(s),console.groupCollapsed("click to view full shader code"),console.warn(...o),console.groupEnd()}function at(t,e,r,s){t.getProgramParameter(e,t.LINK_STATUS)||(t.getShaderParameter(r,t.COMPILE_STATUS)||X(t,r),t.getShaderParameter(s,t.COMPILE_STATUS)||X(t,s),console.error("PixiJS Error: Could not initialize shader."),t.getProgramInfoLog(e)!==""&&console.warn("PixiJS Warning: gl.getProgramInfoLog()",t.getProgramInfoLog(e)))}function ot(t,e){const r=V(t,t.VERTEX_SHADER,e.vertex),s=V(t,t.FRAGMENT_SHADER,e.fragment),n=t.createProgram();t.attachShader(n,r),t.attachShader(n,s);const i=e.transformFeedbackVaryings;i&&(typeof t.transformFeedbackVaryings!="function"?m("TransformFeedback is not supported but TransformFeedbackVaryings are given."):t.transformFeedbackVaryings(n,i.names,i.bufferMode==="separate"?t.SEPARATE_ATTRIBS:t.INTERLEAVED_ATTRIBS)),t.linkProgram(n),t.getProgramParameter(n,t.LINK_STATUS)||at(t,n,r,s),e._attributeData=st(n,t,!/^[ \t]*#[ \t]*version[ \t]+300[ \t]+es[ \t]*$/m.test(e.vertex)),e._uniformData=it(n,t),e._uniformBlockData=nt(n,t),t.deleteShader(r),t.deleteShader(s);const a={};for(const c in e._uniformData){const u=e._uniformData[c];a[c]={location:t.getUniformLocation(n,c),value:fe(u.type,u.size)}}return new et(n,a)}const R={textureCount:0,blockIndex:0};class de{constructor(e){this._activeProgram=null,this._programDataHash=Object.create(null),this._shaderSyncFunctions=Object.create(null),this._renderer=e,this._renderer.renderableGC.addManagedHash(this,"_programDataHash")}contextChange(e){this._gl=e,this._programDataHash=Object.create(null),this._shaderSyncFunctions=Object.create(null),this._activeProgram=null}bind(e,r){if(this._setProgram(e.glProgram),r)return;R.textureCount=0,R.blockIndex=0;let s=this._shaderSyncFunctions[e.glProgram._key];s||(s=this._shaderSyncFunctions[e.glProgram._key]=this._generateShaderSync(e,this)),this._renderer.buffer.nextBindBase(!!e.glProgram.transformFeedbackVaryings),s(this._renderer,e,R)}updateUniformGroup(e){this._renderer.uniformGroup.updateUniformGroup(e,this._activeProgram,R)}bindUniformBlock(e,r,s=0){const n=this._renderer.buffer,i=this._getProgramData(this._activeProgram),a=e._bufferResource;a||this._renderer.ubo.updateUniformGroup(e);const o=e.buffer,c=n.updateBuffer(o),u=n.freeLocationForBufferBase(c);if(a){const{offset:f,size:l}=e;f===0&&l===o.data.byteLength?n.bindBufferBase(c,u):n.bindBufferRange(c,u,f)}else n.getLastBindBaseLocation(c)!==u&&n.bindBufferBase(c,u);const _=this._activeProgram._uniformBlockData[r].index;i.uniformBlockBindings[s]!==u&&(i.uniformBlockBindings[s]=u,this._renderer.gl.uniformBlockBinding(i.program,_,u))}_setProgram(e){if(this._activeProgram===e)return;this._activeProgram=e;const r=this._getProgramData(e);this._gl.useProgram(r.program)}_getProgramData(e){return this._programDataHash[e._key]||this._createProgramData(e)}_createProgramData(e){const r=e._key;return this._programDataHash[r]=ot(this._gl,e),this._programDataHash[r]}destroy(){for(const e of Object.keys(this._programDataHash))this._programDataHash[e].destroy(),this._programDataHash[e]=null;this._programDataHash=null,this._shaderSyncFunctions=null,this._activeProgram=null,this._renderer=null,this._gl=null}_generateShaderSync(e,r){return Qe(e,r)}resetState(){this._activeProgram=null}}de.extension={type:[d.WebGLSystem],name:"shader"};const ct={f32:`if (cv !== v) { + cu.value = v; + gl.uniform1f(location, v); + }`,"vec2<f32>":`if (cv[0] !== v[0] || cv[1] !== v[1]) { + cv[0] = v[0]; + cv[1] = v[1]; + gl.uniform2f(location, v[0], v[1]); + }`,"vec3<f32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) { + cv[0] = v[0]; + cv[1] = v[1]; + cv[2] = v[2]; + gl.uniform3f(location, v[0], v[1], v[2]); + }`,"vec4<f32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) { + cv[0] = v[0]; + cv[1] = v[1]; + cv[2] = v[2]; + cv[3] = v[3]; + gl.uniform4f(location, v[0], v[1], v[2], v[3]); + }`,i32:`if (cv !== v) { + cu.value = v; + gl.uniform1i(location, v); + }`,"vec2<i32>":`if (cv[0] !== v[0] || cv[1] !== v[1]) { + cv[0] = v[0]; + cv[1] = v[1]; + gl.uniform2i(location, v[0], v[1]); + }`,"vec3<i32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) { + cv[0] = v[0]; + cv[1] = v[1]; + cv[2] = v[2]; + gl.uniform3i(location, v[0], v[1], v[2]); + }`,"vec4<i32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) { + cv[0] = v[0]; + cv[1] = v[1]; + cv[2] = v[2]; + cv[3] = v[3]; + gl.uniform4i(location, v[0], v[1], v[2], v[3]); + }`,u32:`if (cv !== v) { + cu.value = v; + gl.uniform1ui(location, v); + }`,"vec2<u32>":`if (cv[0] !== v[0] || cv[1] !== v[1]) { + cv[0] = v[0]; + cv[1] = v[1]; + gl.uniform2ui(location, v[0], v[1]); + }`,"vec3<u32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) { + cv[0] = v[0]; + cv[1] = v[1]; + cv[2] = v[2]; + gl.uniform3ui(location, v[0], v[1], v[2]); + }`,"vec4<u32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) { + cv[0] = v[0]; + cv[1] = v[1]; + cv[2] = v[2]; + cv[3] = v[3]; + gl.uniform4ui(location, v[0], v[1], v[2], v[3]); + }`,bool:`if (cv !== v) { + cu.value = v; + gl.uniform1i(location, v); + }`,"vec2<bool>":`if (cv[0] !== v[0] || cv[1] !== v[1]) { + cv[0] = v[0]; + cv[1] = v[1]; + gl.uniform2i(location, v[0], v[1]); + }`,"vec3<bool>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) { + cv[0] = v[0]; + cv[1] = v[1]; + cv[2] = v[2]; + gl.uniform3i(location, v[0], v[1], v[2]); + }`,"vec4<bool>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) { + cv[0] = v[0]; + cv[1] = v[1]; + cv[2] = v[2]; + cv[3] = v[3]; + gl.uniform4i(location, v[0], v[1], v[2], v[3]); + }`,"mat2x2<f32>":"gl.uniformMatrix2fv(location, false, v);","mat3x3<f32>":"gl.uniformMatrix3fv(location, false, v);","mat4x4<f32>":"gl.uniformMatrix4fv(location, false, v);"},ut={f32:"gl.uniform1fv(location, v);","vec2<f32>":"gl.uniform2fv(location, v);","vec3<f32>":"gl.uniform3fv(location, v);","vec4<f32>":"gl.uniform4fv(location, v);","mat2x2<f32>":"gl.uniformMatrix2fv(location, false, v);","mat3x3<f32>":"gl.uniformMatrix3fv(location, false, v);","mat4x4<f32>":"gl.uniformMatrix4fv(location, false, v);",i32:"gl.uniform1iv(location, v);","vec2<i32>":"gl.uniform2iv(location, v);","vec3<i32>":"gl.uniform3iv(location, v);","vec4<i32>":"gl.uniform4iv(location, v);",u32:"gl.uniform1iv(location, v);","vec2<u32>":"gl.uniform2iv(location, v);","vec3<u32>":"gl.uniform3iv(location, v);","vec4<u32>":"gl.uniform4iv(location, v);",bool:"gl.uniform1iv(location, v);","vec2<bool>":"gl.uniform2iv(location, v);","vec3<bool>":"gl.uniform3iv(location, v);","vec4<bool>":"gl.uniform4iv(location, v);"};function _t(t,e){const r=[` + var v = null; + var cv = null; + var cu = null; + var t = 0; + var gl = renderer.gl; + var name = null; + `];for(const s in t.uniforms){if(!e[s]){t.uniforms[s]instanceof F?t.uniforms[s].ubo?r.push(` + renderer.shader.bindUniformBlock(uv.${s}, "${s}"); + `):r.push(` + renderer.shader.updateUniformGroup(uv.${s}); + `):t.uniforms[s]instanceof J&&r.push(` + renderer.shader.bindBufferResource(uv.${s}, "${s}"); + `);continue}const n=t.uniformStructures[s];let i=!1;for(let a=0;a<y.length;a++){const o=y[a];if(n.type===o.type&&o.test(n)){r.push(`name = "${s}";`,y[a].uniform),i=!0;break}}if(!i){const o=(n.size===1?ct:ut)[n.type].replace("location",`ud["${s}"].location`);r.push(` + cu = ud["${s}"]; + cv = cu.value; + v = uv["${s}"]; + ${o};`)}}return new Function("ud","uv","renderer","syncData",r.join(` +`))}class me{constructor(e){this._cache={},this._uniformGroupSyncHash={},this._renderer=e,this.gl=null,this._cache={}}contextChange(e){this.gl=e}updateUniformGroup(e,r,s){const n=this._renderer.shader._getProgramData(r);(!e.isStatic||e._dirtyId!==n.uniformDirtyGroups[e.uid])&&(n.uniformDirtyGroups[e.uid]=e._dirtyId,this._getUniformSyncFunction(e,r)(n.uniformData,e.uniforms,this._renderer,s))}_getUniformSyncFunction(e,r){var s;return((s=this._uniformGroupSyncHash[e._signature])==null?void 0:s[r._key])||this._createUniformSyncFunction(e,r)}_createUniformSyncFunction(e,r){const s=this._uniformGroupSyncHash[e._signature]||(this._uniformGroupSyncHash[e._signature]={}),n=this._getSignature(e,r._uniformData,"u");return this._cache[n]||(this._cache[n]=this._generateUniformsSync(e,r._uniformData)),s[r._key]=this._cache[n],s[r._key]}_generateUniformsSync(e,r){return _t(e,r)}_getSignature(e,r,s){const n=e.uniforms,i=[`${s}-`];for(const a in n)i.push(a),r[a]&&i.push(r[a].type);return i.join("-")}destroy(){this._renderer=null,this._cache=null}}me.extension={type:[d.WebGLSystem],name:"uniformGroup"};function ht(t){const e={};if(e.normal=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e.add=[t.ONE,t.ONE],e.multiply=[t.DST_COLOR,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA],e.screen=[t.ONE,t.ONE_MINUS_SRC_COLOR,t.ONE,t.ONE_MINUS_SRC_ALPHA],e.none=[0,0],e["normal-npm"]=[t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA],e["add-npm"]=[t.SRC_ALPHA,t.ONE,t.ONE,t.ONE],e["screen-npm"]=[t.SRC_ALPHA,t.ONE_MINUS_SRC_COLOR,t.ONE,t.ONE_MINUS_SRC_ALPHA],e.erase=[t.ZERO,t.ONE_MINUS_SRC_ALPHA],!(t instanceof S.get().getWebGLRenderingContext()))e.min=[t.ONE,t.ONE,t.ONE,t.ONE,t.MIN,t.MIN],e.max=[t.ONE,t.ONE,t.ONE,t.ONE,t.MAX,t.MAX];else{const s=t.getExtension("EXT_blend_minmax");s&&(e.min=[t.ONE,t.ONE,t.ONE,t.ONE,s.MIN_EXT,s.MIN_EXT],e.max=[t.ONE,t.ONE,t.ONE,t.ONE,s.MAX_EXT,s.MAX_EXT])}return e}const ft=0,lt=1,dt=2,mt=3,Et=4,bt=5,Ee=class G{constructor(e){this._invertFrontFace=!1,this.gl=null,this.stateId=0,this.polygonOffset=0,this.blendMode="none",this._blendEq=!1,this.map=[],this.map[ft]=this.setBlend,this.map[lt]=this.setOffset,this.map[dt]=this.setCullFace,this.map[mt]=this.setDepthTest,this.map[Et]=this.setFrontFace,this.map[bt]=this.setDepthMask,this.checks=[],this.defaultState=O.for2d(),e.renderTarget.onRenderTargetChange.add(this)}onRenderTargetChange(e){this._invertFrontFace=!e.isRoot,this._cullFace?this.setFrontFace(this._frontFace):this._frontFaceDirty=!0}contextChange(e){this.gl=e,this.blendModesMap=ht(e),this.resetState()}set(e){if(e||(e=this.defaultState),this.stateId!==e.data){let r=this.stateId^e.data,s=0;for(;r;)r&1&&this.map[s].call(this,!!(e.data&1<<s)),r>>=1,s++;this.stateId=e.data}for(let r=0;r<this.checks.length;r++)this.checks[r](this,e)}forceState(e){e||(e=this.defaultState);for(let r=0;r<this.map.length;r++)this.map[r].call(this,!!(e.data&1<<r));for(let r=0;r<this.checks.length;r++)this.checks[r](this,e);this.stateId=e.data}setBlend(e){this._updateCheck(G._checkBlendMode,e),this.gl[e?"enable":"disable"](this.gl.BLEND)}setOffset(e){this._updateCheck(G._checkPolygonOffset,e),this.gl[e?"enable":"disable"](this.gl.POLYGON_OFFSET_FILL)}setDepthTest(e){this.gl[e?"enable":"disable"](this.gl.DEPTH_TEST)}setDepthMask(e){this.gl.depthMask(e)}setCullFace(e){this._cullFace=e,this.gl[e?"enable":"disable"](this.gl.CULL_FACE),this._cullFace&&this._frontFaceDirty&&this.setFrontFace(this._frontFace)}setFrontFace(e){this._frontFace=e,this._frontFaceDirty=!1;const r=this._invertFrontFace?!e:e;this._glFrontFace!==r&&(this._glFrontFace=r,this.gl.frontFace(this.gl[r?"CW":"CCW"]))}setBlendMode(e){if(this.blendModesMap[e]||(e="normal"),e===this.blendMode)return;this.blendMode=e;const r=this.blendModesMap[e],s=this.gl;r.length===2?s.blendFunc(r[0],r[1]):s.blendFuncSeparate(r[0],r[1],r[2],r[3]),r.length===6?(this._blendEq=!0,s.blendEquationSeparate(r[4],r[5])):this._blendEq&&(this._blendEq=!1,s.blendEquationSeparate(s.FUNC_ADD,s.FUNC_ADD))}setPolygonOffset(e,r){this.gl.polygonOffset(e,r)}resetState(){this._glFrontFace=!1,this._frontFace=!1,this._cullFace=!1,this._frontFaceDirty=!1,this._invertFrontFace=!1,this.gl.frontFace(this.gl.CCW),this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL,!1),this.forceState(this.defaultState),this._blendEq=!0,this.blendMode="",this.setBlendMode("normal")}_updateCheck(e,r){const s=this.checks.indexOf(e);r&&s===-1?this.checks.push(e):!r&&s!==-1&&this.checks.splice(s,1)}static _checkBlendMode(e,r){e.setBlendMode(r.blendMode)}static _checkPolygonOffset(e,r){e.setPolygonOffset(1,r.polygonOffset)}destroy(){this.gl=null,this.checks.length=0}};Ee.extension={type:[d.WebGLSystem],name:"state"};let St=Ee;class pt{constructor(e){this.target=re.TEXTURE_2D,this.texture=e,this.width=-1,this.height=-1,this.type=h.UNSIGNED_BYTE,this.internalFormat=D.RGBA,this.format=D.RGBA,this.samplerType=0}}const gt={id:"buffer",upload(t,e,r){e.width===t.width||e.height===t.height?r.texSubImage2D(r.TEXTURE_2D,0,0,0,t.width,t.height,e.format,e.type,t.resource):r.texImage2D(e.target,0,e.internalFormat,t.width,t.height,0,e.format,e.type,t.resource),e.width=t.width,e.height=t.height}},Rt={"bc1-rgba-unorm":!0,"bc1-rgba-unorm-srgb":!0,"bc2-rgba-unorm":!0,"bc2-rgba-unorm-srgb":!0,"bc3-rgba-unorm":!0,"bc3-rgba-unorm-srgb":!0,"bc4-r-unorm":!0,"bc4-r-snorm":!0,"bc5-rg-unorm":!0,"bc5-rg-snorm":!0,"bc6h-rgb-ufloat":!0,"bc6h-rgb-float":!0,"bc7-rgba-unorm":!0,"bc7-rgba-unorm-srgb":!0,"etc2-rgb8unorm":!0,"etc2-rgb8unorm-srgb":!0,"etc2-rgb8a1unorm":!0,"etc2-rgb8a1unorm-srgb":!0,"etc2-rgba8unorm":!0,"etc2-rgba8unorm-srgb":!0,"eac-r11unorm":!0,"eac-r11snorm":!0,"eac-rg11unorm":!0,"eac-rg11snorm":!0,"astc-4x4-unorm":!0,"astc-4x4-unorm-srgb":!0,"astc-5x4-unorm":!0,"astc-5x4-unorm-srgb":!0,"astc-5x5-unorm":!0,"astc-5x5-unorm-srgb":!0,"astc-6x5-unorm":!0,"astc-6x5-unorm-srgb":!0,"astc-6x6-unorm":!0,"astc-6x6-unorm-srgb":!0,"astc-8x5-unorm":!0,"astc-8x5-unorm-srgb":!0,"astc-8x6-unorm":!0,"astc-8x6-unorm-srgb":!0,"astc-8x8-unorm":!0,"astc-8x8-unorm-srgb":!0,"astc-10x5-unorm":!0,"astc-10x5-unorm-srgb":!0,"astc-10x6-unorm":!0,"astc-10x6-unorm-srgb":!0,"astc-10x8-unorm":!0,"astc-10x8-unorm-srgb":!0,"astc-10x10-unorm":!0,"astc-10x10-unorm-srgb":!0,"astc-12x10-unorm":!0,"astc-12x10-unorm-srgb":!0,"astc-12x12-unorm":!0,"astc-12x12-unorm-srgb":!0},xt={id:"compressed",upload(t,e,r){r.pixelStorei(r.UNPACK_ALIGNMENT,4);let s=t.pixelWidth,n=t.pixelHeight;const i=!!Rt[t.format];for(let a=0;a<t.resource.length;a++){const o=t.resource[a];i?r.compressedTexImage2D(r.TEXTURE_2D,a,e.internalFormat,s,n,0,o):r.texImage2D(r.TEXTURE_2D,a,e.internalFormat,s,n,0,e.format,e.type,o),s=Math.max(s>>1,1),n=Math.max(n>>1,1)}}},be={id:"image",upload(t,e,r,s){const n=e.width,i=e.height,a=t.pixelWidth,o=t.pixelHeight,c=t.resourceWidth,u=t.resourceHeight;c<a||u<o?((n!==a||i!==o)&&r.texImage2D(e.target,0,e.internalFormat,a,o,0,e.format,e.type,null),s===2?r.texSubImage2D(r.TEXTURE_2D,0,0,0,c,u,e.format,e.type,t.resource):r.texSubImage2D(r.TEXTURE_2D,0,0,0,e.format,e.type,t.resource)):n===a&&i===o?r.texSubImage2D(r.TEXTURE_2D,0,0,0,e.format,e.type,t.resource):s===2?r.texImage2D(e.target,0,e.internalFormat,a,o,0,e.format,e.type,t.resource):r.texImage2D(e.target,0,e.internalFormat,e.format,e.type,t.resource),e.width=a,e.height=o}},Tt={id:"video",upload(t,e,r,s){if(!t.isValid){r.texImage2D(e.target,0,e.internalFormat,1,1,0,e.format,e.type,null);return}be.upload(t,e,r,s)}},W={linear:9729,nearest:9728},vt={linear:{linear:9987,nearest:9985},nearest:{linear:9986,nearest:9984}},I={"clamp-to-edge":33071,repeat:10497,"mirror-repeat":33648},Bt={never:512,less:513,equal:514,"less-equal":515,greater:516,"not-equal":517,"greater-equal":518,always:519};function j(t,e,r,s,n,i,a,o){const c=i;if(!o||t.addressModeU!=="repeat"||t.addressModeV!=="repeat"||t.addressModeW!=="repeat"){const u=I[a?"clamp-to-edge":t.addressModeU],_=I[a?"clamp-to-edge":t.addressModeV],f=I[a?"clamp-to-edge":t.addressModeW];e[n](c,e.TEXTURE_WRAP_S,u),e[n](c,e.TEXTURE_WRAP_T,_),e.TEXTURE_WRAP_R&&e[n](c,e.TEXTURE_WRAP_R,f)}if((!o||t.magFilter!=="linear")&&e[n](c,e.TEXTURE_MAG_FILTER,W[t.magFilter]),r){if(!o||t.mipmapFilter!=="linear"){const u=vt[t.minFilter][t.mipmapFilter];e[n](c,e.TEXTURE_MIN_FILTER,u)}}else e[n](c,e.TEXTURE_MIN_FILTER,W[t.minFilter]);if(s&&t.maxAnisotropy>1){const u=Math.min(t.maxAnisotropy,e.getParameter(s.MAX_TEXTURE_MAX_ANISOTROPY_EXT));e[n](c,s.TEXTURE_MAX_ANISOTROPY_EXT,u)}t.compare&&e[n](c,e.TEXTURE_COMPARE_FUNC,Bt[t.compare])}function At(t){return{r8unorm:t.RED,r8snorm:t.RED,r8uint:t.RED,r8sint:t.RED,r16uint:t.RED,r16sint:t.RED,r16float:t.RED,rg8unorm:t.RG,rg8snorm:t.RG,rg8uint:t.RG,rg8sint:t.RG,r32uint:t.RED,r32sint:t.RED,r32float:t.RED,rg16uint:t.RG,rg16sint:t.RG,rg16float:t.RG,rgba8unorm:t.RGBA,"rgba8unorm-srgb":t.RGBA,rgba8snorm:t.RGBA,rgba8uint:t.RGBA,rgba8sint:t.RGBA,bgra8unorm:t.RGBA,"bgra8unorm-srgb":t.RGBA,rgb9e5ufloat:t.RGB,rgb10a2unorm:t.RGBA,rg11b10ufloat:t.RGB,rg32uint:t.RG,rg32sint:t.RG,rg32float:t.RG,rgba16uint:t.RGBA,rgba16sint:t.RGBA,rgba16float:t.RGBA,rgba32uint:t.RGBA,rgba32sint:t.RGBA,rgba32float:t.RGBA,stencil8:t.STENCIL_INDEX8,depth16unorm:t.DEPTH_COMPONENT,depth24plus:t.DEPTH_COMPONENT,"depth24plus-stencil8":t.DEPTH_STENCIL,depth32float:t.DEPTH_COMPONENT,"depth32float-stencil8":t.DEPTH_STENCIL}}function Nt(t,e){let r={},s=t.RGBA;return t instanceof S.get().getWebGLRenderingContext()?e.srgb&&(r={"rgba8unorm-srgb":e.srgb.SRGB8_ALPHA8_EXT,"bgra8unorm-srgb":e.srgb.SRGB8_ALPHA8_EXT}):(r={"rgba8unorm-srgb":t.SRGB8_ALPHA8,"bgra8unorm-srgb":t.SRGB8_ALPHA8},s=t.RGBA8),{r8unorm:t.R8,r8snorm:t.R8_SNORM,r8uint:t.R8UI,r8sint:t.R8I,r16uint:t.R16UI,r16sint:t.R16I,r16float:t.R16F,rg8unorm:t.RG8,rg8snorm:t.RG8_SNORM,rg8uint:t.RG8UI,rg8sint:t.RG8I,r32uint:t.R32UI,r32sint:t.R32I,r32float:t.R32F,rg16uint:t.RG16UI,rg16sint:t.RG16I,rg16float:t.RG16F,rgba8unorm:t.RGBA,...r,rgba8snorm:t.RGBA8_SNORM,rgba8uint:t.RGBA8UI,rgba8sint:t.RGBA8I,bgra8unorm:s,rgb9e5ufloat:t.RGB9_E5,rgb10a2unorm:t.RGB10_A2,rg11b10ufloat:t.R11F_G11F_B10F,rg32uint:t.RG32UI,rg32sint:t.RG32I,rg32float:t.RG32F,rgba16uint:t.RGBA16UI,rgba16sint:t.RGBA16I,rgba16float:t.RGBA16F,rgba32uint:t.RGBA32UI,rgba32sint:t.RGBA32I,rgba32float:t.RGBA32F,stencil8:t.STENCIL_INDEX8,depth16unorm:t.DEPTH_COMPONENT16,depth24plus:t.DEPTH_COMPONENT24,"depth24plus-stencil8":t.DEPTH24_STENCIL8,depth32float:t.DEPTH_COMPONENT32F,"depth32float-stencil8":t.DEPTH32F_STENCIL8,...e.s3tc?{"bc1-rgba-unorm":e.s3tc.COMPRESSED_RGBA_S3TC_DXT1_EXT,"bc2-rgba-unorm":e.s3tc.COMPRESSED_RGBA_S3TC_DXT3_EXT,"bc3-rgba-unorm":e.s3tc.COMPRESSED_RGBA_S3TC_DXT5_EXT}:{},...e.s3tc_sRGB?{"bc1-rgba-unorm-srgb":e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,"bc2-rgba-unorm-srgb":e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,"bc3-rgba-unorm-srgb":e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}:{},...e.rgtc?{"bc4-r-unorm":e.rgtc.COMPRESSED_RED_RGTC1_EXT,"bc4-r-snorm":e.rgtc.COMPRESSED_SIGNED_RED_RGTC1_EXT,"bc5-rg-unorm":e.rgtc.COMPRESSED_RED_GREEN_RGTC2_EXT,"bc5-rg-snorm":e.rgtc.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}:{},...e.bptc?{"bc6h-rgb-float":e.bptc.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT,"bc6h-rgb-ufloat":e.bptc.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT,"bc7-rgba-unorm":e.bptc.COMPRESSED_RGBA_BPTC_UNORM_EXT,"bc7-rgba-unorm-srgb":e.bptc.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT}:{},...e.etc?{"etc2-rgb8unorm":e.etc.COMPRESSED_RGB8_ETC2,"etc2-rgb8unorm-srgb":e.etc.COMPRESSED_SRGB8_ETC2,"etc2-rgb8a1unorm":e.etc.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,"etc2-rgb8a1unorm-srgb":e.etc.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,"etc2-rgba8unorm":e.etc.COMPRESSED_RGBA8_ETC2_EAC,"etc2-rgba8unorm-srgb":e.etc.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,"eac-r11unorm":e.etc.COMPRESSED_R11_EAC,"eac-rg11unorm":e.etc.COMPRESSED_SIGNED_RG11_EAC}:{},...e.astc?{"astc-4x4-unorm":e.astc.COMPRESSED_RGBA_ASTC_4x4_KHR,"astc-4x4-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,"astc-5x4-unorm":e.astc.COMPRESSED_RGBA_ASTC_5x4_KHR,"astc-5x4-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,"astc-5x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_5x5_KHR,"astc-5x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,"astc-6x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_6x5_KHR,"astc-6x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,"astc-6x6-unorm":e.astc.COMPRESSED_RGBA_ASTC_6x6_KHR,"astc-6x6-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,"astc-8x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_8x5_KHR,"astc-8x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,"astc-8x6-unorm":e.astc.COMPRESSED_RGBA_ASTC_8x6_KHR,"astc-8x6-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,"astc-8x8-unorm":e.astc.COMPRESSED_RGBA_ASTC_8x8_KHR,"astc-8x8-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,"astc-10x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x5_KHR,"astc-10x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,"astc-10x6-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x6_KHR,"astc-10x6-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,"astc-10x8-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x8_KHR,"astc-10x8-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,"astc-10x10-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x10_KHR,"astc-10x10-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,"astc-12x10-unorm":e.astc.COMPRESSED_RGBA_ASTC_12x10_KHR,"astc-12x10-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,"astc-12x12-unorm":e.astc.COMPRESSED_RGBA_ASTC_12x12_KHR,"astc-12x12-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR}:{}}}function yt(t){return{r8unorm:t.UNSIGNED_BYTE,r8snorm:t.BYTE,r8uint:t.UNSIGNED_BYTE,r8sint:t.BYTE,r16uint:t.UNSIGNED_SHORT,r16sint:t.SHORT,r16float:t.HALF_FLOAT,rg8unorm:t.UNSIGNED_BYTE,rg8snorm:t.BYTE,rg8uint:t.UNSIGNED_BYTE,rg8sint:t.BYTE,r32uint:t.UNSIGNED_INT,r32sint:t.INT,r32float:t.FLOAT,rg16uint:t.UNSIGNED_SHORT,rg16sint:t.SHORT,rg16float:t.HALF_FLOAT,rgba8unorm:t.UNSIGNED_BYTE,"rgba8unorm-srgb":t.UNSIGNED_BYTE,rgba8snorm:t.BYTE,rgba8uint:t.UNSIGNED_BYTE,rgba8sint:t.BYTE,bgra8unorm:t.UNSIGNED_BYTE,"bgra8unorm-srgb":t.UNSIGNED_BYTE,rgb9e5ufloat:t.UNSIGNED_INT_5_9_9_9_REV,rgb10a2unorm:t.UNSIGNED_INT_2_10_10_10_REV,rg11b10ufloat:t.UNSIGNED_INT_10F_11F_11F_REV,rg32uint:t.UNSIGNED_INT,rg32sint:t.INT,rg32float:t.FLOAT,rgba16uint:t.UNSIGNED_SHORT,rgba16sint:t.SHORT,rgba16float:t.HALF_FLOAT,rgba32uint:t.UNSIGNED_INT,rgba32sint:t.INT,rgba32float:t.FLOAT,stencil8:t.UNSIGNED_BYTE,depth16unorm:t.UNSIGNED_SHORT,depth24plus:t.UNSIGNED_INT,"depth24plus-stencil8":t.UNSIGNED_INT_24_8,depth32float:t.FLOAT,"depth32float-stencil8":t.FLOAT_32_UNSIGNED_INT_24_8_REV}}const Ct=4;class Se{constructor(e){this.managedTextures=[],this._glTextures=Object.create(null),this._glSamplers=Object.create(null),this._boundTextures=[],this._activeTextureLocation=-1,this._boundSamplers=Object.create(null),this._uploads={image:be,buffer:gt,video:Tt,compressed:xt},this._premultiplyAlpha=!1,this._useSeparateSamplers=!1,this._renderer=e,this._renderer.renderableGC.addManagedHash(this,"_glTextures"),this._renderer.renderableGC.addManagedHash(this,"_glSamplers")}contextChange(e){this._gl=e,this._mapFormatToInternalFormat||(this._mapFormatToInternalFormat=Nt(e,this._renderer.context.extensions),this._mapFormatToType=yt(e),this._mapFormatToFormat=At(e)),this._glTextures=Object.create(null),this._glSamplers=Object.create(null),this._boundSamplers=Object.create(null),this._premultiplyAlpha=!1;for(let r=0;r<16;r++)this.bind(b.EMPTY,r)}initSource(e){this.bind(e)}bind(e,r=0){const s=e.source;e?(this.bindSource(s,r),this._useSeparateSamplers&&this._bindSampler(s.style,r)):(this.bindSource(null,r),this._useSeparateSamplers&&this._bindSampler(null,r))}bindSource(e,r=0){const s=this._gl;if(e._touched=this._renderer.textureGC.count,this._boundTextures[r]!==e){this._boundTextures[r]=e,this._activateLocation(r),e||(e=b.EMPTY.source);const n=this.getGlSource(e);s.bindTexture(n.target,n.texture)}}_bindSampler(e,r=0){const s=this._gl;if(!e){this._boundSamplers[r]=null,s.bindSampler(r,null);return}const n=this._getGlSampler(e);this._boundSamplers[r]!==n&&(this._boundSamplers[r]=n,s.bindSampler(r,n))}unbind(e){const r=e.source,s=this._boundTextures,n=this._gl;for(let i=0;i<s.length;i++)if(s[i]===r){this._activateLocation(i);const a=this.getGlSource(r);n.bindTexture(a.target,null),s[i]=null}}_activateLocation(e){this._activeTextureLocation!==e&&(this._activeTextureLocation=e,this._gl.activeTexture(this._gl.TEXTURE0+e))}_initSource(e){const r=this._gl,s=new pt(r.createTexture());if(s.type=this._mapFormatToType[e.format],s.internalFormat=this._mapFormatToInternalFormat[e.format],s.format=this._mapFormatToFormat[e.format],e.autoGenerateMipmaps&&(this._renderer.context.supports.nonPowOf2mipmaps||e.isPowerOfTwo)){const n=Math.max(e.width,e.height);e.mipLevelCount=Math.floor(Math.log2(n))+1}return this._glTextures[e.uid]=s,this.managedTextures.includes(e)||(e.on("update",this.onSourceUpdate,this),e.on("resize",this.onSourceUpdate,this),e.on("styleChange",this.onStyleChange,this),e.on("destroy",this.onSourceDestroy,this),e.on("unload",this.onSourceUnload,this),e.on("updateMipmaps",this.onUpdateMipmaps,this),this.managedTextures.push(e)),this.onSourceUpdate(e),this.updateStyle(e,!1),s}onStyleChange(e){this.updateStyle(e,!1)}updateStyle(e,r){const s=this._gl,n=this.getGlSource(e);s.bindTexture(s.TEXTURE_2D,n.texture),this._boundTextures[this._activeTextureLocation]=e,j(e.style,s,e.mipLevelCount>1,this._renderer.context.extensions.anisotropicFiltering,"texParameteri",s.TEXTURE_2D,!this._renderer.context.supports.nonPowOf2wrapping&&!e.isPowerOfTwo,r)}onSourceUnload(e){const r=this._glTextures[e.uid];r&&(this.unbind(e),this._glTextures[e.uid]=null,this._gl.deleteTexture(r.texture))}onSourceUpdate(e){const r=this._gl,s=this.getGlSource(e);r.bindTexture(r.TEXTURE_2D,s.texture),this._boundTextures[this._activeTextureLocation]=e;const n=e.alphaMode==="premultiply-alpha-on-upload";this._premultiplyAlpha!==n&&(this._premultiplyAlpha=n,r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,n)),this._uploads[e.uploadMethodId]?this._uploads[e.uploadMethodId].upload(e,s,r,this._renderer.context.webGLVersion):r.texImage2D(r.TEXTURE_2D,0,r.RGBA,e.pixelWidth,e.pixelHeight,0,r.RGBA,r.UNSIGNED_BYTE,null),e.autoGenerateMipmaps&&e.mipLevelCount>1&&this.onUpdateMipmaps(e,!1)}onUpdateMipmaps(e,r=!0){r&&this.bindSource(e,0);const s=this.getGlSource(e);this._gl.generateMipmap(s.target)}onSourceDestroy(e){e.off("destroy",this.onSourceDestroy,this),e.off("update",this.onSourceUpdate,this),e.off("resize",this.onSourceUpdate,this),e.off("unload",this.onSourceUnload,this),e.off("styleChange",this.onStyleChange,this),e.off("updateMipmaps",this.onUpdateMipmaps,this),this.managedTextures.splice(this.managedTextures.indexOf(e),1),this.onSourceUnload(e)}_initSampler(e){const r=this._gl,s=this._gl.createSampler();return this._glSamplers[e._resourceId]=s,j(e,r,this._boundTextures[this._activeTextureLocation].mipLevelCount>1,this._renderer.context.extensions.anisotropicFiltering,"samplerParameteri",s,!1,!0),this._glSamplers[e._resourceId]}_getGlSampler(e){return this._glSamplers[e._resourceId]||this._initSampler(e)}getGlSource(e){return this._glTextures[e.uid]||this._initSource(e)}generateCanvas(e){const{pixels:r,width:s,height:n}=this.getPixels(e),i=S.get().createCanvas();i.width=s,i.height=n;const a=i.getContext("2d");if(a){const o=a.createImageData(s,n);o.data.set(r),a.putImageData(o,0,0)}return i}getPixels(e){const r=e.source.resolution,s=e.frame,n=Math.max(Math.round(s.width*r),1),i=Math.max(Math.round(s.height*r),1),a=new Uint8Array(Ct*n*i),o=this._renderer,c=o.renderTarget.getRenderTarget(e),u=o.renderTarget.getGpuRenderTarget(c),_=o.gl;return _.bindFramebuffer(_.FRAMEBUFFER,u.resolveTargetFramebuffer),_.readPixels(Math.round(s.x*r),Math.round(s.y*r),n,i,_.RGBA,_.UNSIGNED_BYTE,a),{pixels:new Uint8ClampedArray(a.buffer),width:n,height:i}}destroy(){this.managedTextures.slice().forEach(e=>this.onSourceDestroy(e)),this.managedTextures=null,this._glTextures=null,this._glSamplers=null,this._boundTextures=null,this._boundSamplers=null,this._mapFormatToInternalFormat=null,this._mapFormatToType=null,this._mapFormatToFormat=null,this._uploads=null,this._renderer=null}resetState(){this._activeTextureLocation=-1,this._boundTextures.fill(b.EMPTY.source),this._boundSamplers=Object.create(null);const e=this._gl;this._premultiplyAlpha=!1,e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this._premultiplyAlpha)}}Se.extension={type:[d.WebGLSystem],name:"texture"};class pe{contextChange(e){const r=new F({uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uTransformMatrix:{value:new z,type:"mat3x3<f32>"},uRound:{value:0,type:"f32"}}),s=e.limits.maxBatchableTextures,n=Y({name:"graphics",bits:[ye,Ce(s),Z,q]});this.shader=new U({glProgram:n,resources:{localUniforms:r,batchSamplers:Ie(s)}})}execute(e,r){const s=r.context,n=s.customShader||this.shader,i=e.renderer,a=i.graphicsContext,{batcher:o,instructions:c}=a.getContextRenderData(s);n.groups[0]=i.globalUniforms.bindGroup,i.state.set(e.state),i.shader.bind(n),i.geometry.bind(o.geometry,n.glProgram);const u=c.instructions;for(let _=0;_<c.instructionSize;_++){const f=u[_];if(f.size){for(let l=0;l<f.textures.count;l++)i.texture.bind(f.textures.textures[l],l);i.geometry.draw(f.topology,f.size,f.start)}}}destroy(){this.shader.destroy(!0),this.shader=null}}pe.extension={type:[d.WebGLPipesAdaptor],name:"graphics"};class ge{init(){const e=Y({name:"mesh",bits:[Z,He,q]});this._shader=new U({glProgram:e,resources:{uTexture:b.EMPTY.source,textureUniforms:{uTextureMatrix:{type:"mat3x3<f32>",value:new z}}}})}execute(e,r){const s=e.renderer;let n=r._shader;if(n){if(!n.glProgram){m("Mesh shader has no glProgram",r.shader);return}}else{n=this._shader;const i=r.texture,a=i.source;n.resources.uTexture=a,n.resources.uSampler=a.style,n.resources.textureUniforms.uniforms.uTextureMatrix=i.textureMatrix.mapCoord}n.groups[100]=s.globalUniforms.bindGroup,n.groups[101]=e.localUniformsBindGroup,s.encoder.draw({geometry:r._geometry,shader:n,state:r.state})}destroy(){this._shader.destroy(!0),this._shader=null}}ge.extension={type:[d.WebGLPipesAdaptor],name:"mesh"};const It=[...we,_e,$e,Xe,oe,ee,Se,he,se,me,de,ae,St,ce,ie],Dt=[...Ve],Gt=[Q,ge,pe],Re=[],xe=[],Te=[];T.handleByNamedList(d.WebGLSystem,Re);T.handleByNamedList(d.WebGLPipes,xe);T.handleByNamedList(d.WebGLPipesAdaptor,Te);T.add(...It,...Dt,...Gt);class Pt extends De{constructor(){const e={name:"webgl",type:Ge.WEBGL,systems:Re,renderPipes:xe,renderPipeAdaptors:Te};super(e)}}export{Pt as WebGLRenderer}; diff --git a/dist/assets/WebGPURenderer-CtyVoQqf.js b/dist/assets/WebGPURenderer-CtyVoQqf.js new file mode 100644 index 0000000..f626925 --- /dev/null +++ b/dist/assets/WebGPURenderer-CtyVoQqf.js @@ -0,0 +1,41 @@ +import{g as E,E as p,f as ae,D as B,S as C,B as T,b as ue,c as L,d as M,w as v,h as y,i as ce,j as de,k as A,l as w,M as k,m as D,n as he,o as pe,p as H,q as z,s as R,A as le,R as fe,e as S}from"./index-DB6B0XuI.js";import{S as F,l as ge,a as me}from"./colorToUniform-DmtBy-2V.js";import{c as _e,u as be,U as ye,B as xe,G as Ge,e as Be,R as Se,t as Pe,S as Te,a as Ce}from"./SharedSystems-DVK37F7d.js";const x=F.for2d();class O{start(e,t,r){const s=e.renderer,i=s.encoder,n=r.gpuProgram;this._shader=r,this._geometry=t,i.setGeometry(t,n),x.blendMode="normal",s.pipeline.getPipeline(t,n,x);const o=s.globalUniforms.bindGroup;i.resetBindGroup(1),i.setBindGroup(0,o,n)}execute(e,t){const r=this._shader.gpuProgram,s=e.renderer,i=s.encoder;if(!t.bindGroup){const u=t.textures;t.bindGroup=E(u.textures,u.count,s.limits.maxBatchableTextures)}x.blendMode=t.blendMode;const n=s.bindGroup.getBindGroup(t.bindGroup,r,1),o=s.pipeline.getPipeline(this._geometry,r,x,t.topology);t.bindGroup._touch(s.textureGC.count),i.setPipeline(o),i.renderPassEncoder.setBindGroup(1,n),i.renderPassEncoder.drawIndexed(t.size,1,t.start)}}O.extension={type:[p.WebGPUPipesAdaptor],name:"batch"};class I{constructor(e){this._hash=Object.create(null),this._renderer=e,this._renderer.renderableGC.addManagedHash(this,"_hash")}contextChange(e){this._gpu=e}getBindGroup(e,t,r){return e._updateKey(),this._hash[e._key]||this._createBindGroup(e,t,r)}_createBindGroup(e,t,r){const s=this._gpu.device,i=t.layout[r],n=[],o=this._renderer;for(const l in i){const h=e.resources[l]??e.resources[i[l]];let f;if(h._resourceType==="uniformGroup"){const d=h;o.ubo.updateUniformGroup(d);const _=d.buffer;f={buffer:o.buffer.getGPUBuffer(_),offset:0,size:_.descriptor.size}}else if(h._resourceType==="buffer"){const d=h;f={buffer:o.buffer.getGPUBuffer(d),offset:0,size:d.descriptor.size}}else if(h._resourceType==="bufferResource"){const d=h;f={buffer:o.buffer.getGPUBuffer(d.buffer),offset:d.offset,size:d.size}}else if(h._resourceType==="textureSampler"){const d=h;f=o.texture.getGpuSampler(d)}else if(h._resourceType==="textureSource"){const d=h;f=o.texture.getGpuSource(d).createView({})}n.push({binding:i[l],resource:f})}const u=o.shader.getProgramData(t).bindGroups[r],c=s.createBindGroup({layout:u,entries:n});return this._hash[e._key]=c,c}destroy(){for(const e of Object.keys(this._hash))this._hash[e]=null;this._hash=null,this._renderer=null}}I.extension={type:[p.WebGPUSystem],name:"bindGroup"};class W{constructor(e){this._gpuBuffers=Object.create(null),this._managedBuffers=[],e.renderableGC.addManagedHash(this,"_gpuBuffers")}contextChange(e){this._gpu=e}getGPUBuffer(e){return this._gpuBuffers[e.uid]||this.createGPUBuffer(e)}updateBuffer(e){const t=this._gpuBuffers[e.uid]||this.createGPUBuffer(e),r=e.data;return e._updateID&&r&&(e._updateID=0,this._gpu.device.queue.writeBuffer(t,0,r.buffer,0,(e._updateSize||r.byteLength)+3&-4)),t}destroyAll(){for(const e in this._gpuBuffers)this._gpuBuffers[e].destroy();this._gpuBuffers={}}createGPUBuffer(e){this._gpuBuffers[e.uid]||(e.on("update",this.updateBuffer,this),e.on("change",this.onBufferChange,this),e.on("destroy",this.onBufferDestroy,this),this._managedBuffers.push(e));const t=this._gpu.device.createBuffer(e.descriptor);return e._updateID=0,e.data&&(ae(e.data.buffer,t.getMappedRange()),t.unmap()),this._gpuBuffers[e.uid]=t,t}onBufferChange(e){this._gpuBuffers[e.uid].destroy(),e._updateID=0,this._gpuBuffers[e.uid]=this.createGPUBuffer(e)}onBufferDestroy(e){this._managedBuffers.splice(this._managedBuffers.indexOf(e),1),this._destroyBuffer(e)}destroy(){this._managedBuffers.forEach(e=>this._destroyBuffer(e)),this._managedBuffers=null,this._gpuBuffers=null}_destroyBuffer(e){this._gpuBuffers[e.uid].destroy(),e.off("update",this.updateBuffer,this),e.off("change",this.onBufferChange,this),e.off("destroy",this.onBufferDestroy,this),this._gpuBuffers[e.uid]=null}}W.extension={type:[p.WebGPUSystem],name:"buffer"};class ve{constructor({minUniformOffsetAlignment:e}){this._minUniformOffsetAlignment=256,this.byteIndex=0,this._minUniformOffsetAlignment=e,this.data=new Float32Array(65535)}clear(){this.byteIndex=0}addEmptyGroup(e){if(e>this._minUniformOffsetAlignment/4)throw new Error(`UniformBufferBatch: array is too large: ${e*4}`);const t=this.byteIndex;let r=t+e*4;if(r=Math.ceil(r/this._minUniformOffsetAlignment)*this._minUniformOffsetAlignment,r>this.data.length*4)throw new Error("UniformBufferBatch: ubo batch got too big");return this.byteIndex=r,t}addGroup(e){const t=this.addEmptyGroup(e.length);for(let r=0;r<e.length;r++)this.data[t/4+r]=e[r];return t}destroy(){this.data=null}}class V{constructor(e){this._colorMaskCache=15,this._renderer=e}setMask(e){this._colorMaskCache!==e&&(this._colorMaskCache=e,this._renderer.pipeline.setColorMask(e))}destroy(){this._renderer=null,this._colorMaskCache=null}}V.extension={type:[p.WebGPUSystem],name:"colorMask"};class U{constructor(e){this._renderer=e}async init(e){return this._initPromise?this._initPromise:(this._initPromise=(e.gpu?Promise.resolve(e.gpu):this._createDeviceAndAdaptor(e)).then(t=>{this.gpu=t,this._renderer.runners.contextChange.emit(this.gpu)}),this._initPromise)}contextChange(e){this._renderer.gpu=e}async _createDeviceAndAdaptor(e){const t=await B.get().getNavigator().gpu.requestAdapter({powerPreference:e.powerPreference,forceFallbackAdapter:e.forceFallbackAdapter}),r=["texture-compression-bc","texture-compression-astc","texture-compression-etc2"].filter(i=>t.features.has(i)),s=await t.requestDevice({requiredFeatures:r});return{adapter:t,device:s}}destroy(){this.gpu=null,this._renderer=null}}U.extension={type:[p.WebGPUSystem],name:"device"};U.defaultOptions={powerPreference:void 0,forceFallbackAdapter:!1};class N{constructor(e){this._boundBindGroup=Object.create(null),this._boundVertexBuffer=Object.create(null),this._renderer=e}renderStart(){this.commandFinished=new Promise(e=>{this._resolveCommandFinished=e}),this.commandEncoder=this._renderer.gpu.device.createCommandEncoder()}beginRenderPass(e){this.endRenderPass(),this._clearCache(),this.renderPassEncoder=this.commandEncoder.beginRenderPass(e.descriptor)}endRenderPass(){this.renderPassEncoder&&this.renderPassEncoder.end(),this.renderPassEncoder=null}setViewport(e){this.renderPassEncoder.setViewport(e.x,e.y,e.width,e.height,0,1)}setPipelineFromGeometryProgramAndState(e,t,r,s){const i=this._renderer.pipeline.getPipeline(e,t,r,s);this.setPipeline(i)}setPipeline(e){this._boundPipeline!==e&&(this._boundPipeline=e,this.renderPassEncoder.setPipeline(e))}_setVertexBuffer(e,t){this._boundVertexBuffer[e]!==t&&(this._boundVertexBuffer[e]=t,this.renderPassEncoder.setVertexBuffer(e,this._renderer.buffer.updateBuffer(t)))}_setIndexBuffer(e){if(this._boundIndexBuffer===e)return;this._boundIndexBuffer=e;const t=e.data.BYTES_PER_ELEMENT===2?"uint16":"uint32";this.renderPassEncoder.setIndexBuffer(this._renderer.buffer.updateBuffer(e),t)}resetBindGroup(e){this._boundBindGroup[e]=null}setBindGroup(e,t,r){if(this._boundBindGroup[e]===t)return;this._boundBindGroup[e]=t,t._touch(this._renderer.textureGC.count);const s=this._renderer.bindGroup.getBindGroup(t,r,e);this.renderPassEncoder.setBindGroup(e,s)}setGeometry(e,t){const r=this._renderer.pipeline.getBufferNamesToBind(e,t);for(const s in r)this._setVertexBuffer(parseInt(s,10),e.attributes[r[s]].buffer);e.indexBuffer&&this._setIndexBuffer(e.indexBuffer)}_setShaderBindGroups(e,t){for(const r in e.groups){const s=e.groups[r];t||this._syncBindGroup(s),this.setBindGroup(r,s,e.gpuProgram)}}_syncBindGroup(e){for(const t in e.resources){const r=e.resources[t];r.isUniformGroup&&this._renderer.ubo.updateUniformGroup(r)}}draw(e){const{geometry:t,shader:r,state:s,topology:i,size:n,start:o,instanceCount:u,skipSync:c}=e;this.setPipelineFromGeometryProgramAndState(t,r.gpuProgram,s,i),this.setGeometry(t,r.gpuProgram),this._setShaderBindGroups(r,c),t.indexBuffer?this.renderPassEncoder.drawIndexed(n||t.indexBuffer.data.length,u??t.instanceCount,o||0):this.renderPassEncoder.draw(n||t.getSize(),u??t.instanceCount,o||0)}finishRenderPass(){this.renderPassEncoder&&(this.renderPassEncoder.end(),this.renderPassEncoder=null)}postrender(){this.finishRenderPass(),this._gpu.device.queue.submit([this.commandEncoder.finish()]),this._resolveCommandFinished(),this.commandEncoder=null}restoreRenderPass(){const e=this._renderer.renderTarget.adaptor.getDescriptor(this._renderer.renderTarget.renderTarget,!1,[0,0,0,1]);this.renderPassEncoder=this.commandEncoder.beginRenderPass(e);const t=this._boundPipeline,r={...this._boundVertexBuffer},s=this._boundIndexBuffer,i={...this._boundBindGroup};this._clearCache();const n=this._renderer.renderTarget.viewport;this.renderPassEncoder.setViewport(n.x,n.y,n.width,n.height,0,1),this.setPipeline(t);for(const o in r)this._setVertexBuffer(o,r[o]);for(const o in i)this.setBindGroup(o,i[o],null);this._setIndexBuffer(s)}_clearCache(){for(let e=0;e<16;e++)this._boundBindGroup[e]=null,this._boundVertexBuffer[e]=null;this._boundIndexBuffer=null,this._boundPipeline=null}destroy(){this._renderer=null,this._gpu=null,this._boundBindGroup=null,this._boundVertexBuffer=null,this._boundIndexBuffer=null,this._boundPipeline=null}contextChange(e){this._gpu=e}}N.extension={type:[p.WebGPUSystem],name:"encoder",priority:1};class j{constructor(e){this._renderer=e}contextChange(){this.maxTextures=this._renderer.device.gpu.device.limits.maxSampledTexturesPerShaderStage,this.maxBatchableTextures=this.maxTextures}destroy(){}}j.extension={type:[p.WebGPUSystem],name:"limits"};class K{constructor(e){this._renderTargetStencilState=Object.create(null),this._renderer=e,e.renderTarget.onRenderTargetChange.add(this)}onRenderTargetChange(e){let t=this._renderTargetStencilState[e.uid];t||(t=this._renderTargetStencilState[e.uid]={stencilMode:C.DISABLED,stencilReference:0}),this._activeRenderTarget=e,this.setStencilMode(t.stencilMode,t.stencilReference)}setStencilMode(e,t){const r=this._renderTargetStencilState[this._activeRenderTarget.uid];r.stencilMode=e,r.stencilReference=t;const s=this._renderer;s.pipeline.setStencilMode(e),s.encoder.renderPassEncoder.setStencilReference(t)}destroy(){this._renderer.renderTarget.onRenderTargetChange.remove(this),this._renderer=null,this._activeRenderTarget=null,this._renderTargetStencilState=null}}K.extension={type:[p.WebGPUSystem],name:"stencil"};const G={i32:{align:4,size:4},u32:{align:4,size:4},f32:{align:4,size:4},f16:{align:2,size:2},"vec2<i32>":{align:8,size:8},"vec2<u32>":{align:8,size:8},"vec2<f32>":{align:8,size:8},"vec2<f16>":{align:4,size:4},"vec3<i32>":{align:16,size:12},"vec3<u32>":{align:16,size:12},"vec3<f32>":{align:16,size:12},"vec3<f16>":{align:8,size:6},"vec4<i32>":{align:16,size:16},"vec4<u32>":{align:16,size:16},"vec4<f32>":{align:16,size:16},"vec4<f16>":{align:8,size:8},"mat2x2<f32>":{align:8,size:16},"mat2x2<f16>":{align:4,size:8},"mat3x2<f32>":{align:8,size:24},"mat3x2<f16>":{align:4,size:12},"mat4x2<f32>":{align:8,size:32},"mat4x2<f16>":{align:4,size:16},"mat2x3<f32>":{align:16,size:32},"mat2x3<f16>":{align:8,size:16},"mat3x3<f32>":{align:16,size:48},"mat3x3<f16>":{align:8,size:24},"mat4x3<f32>":{align:16,size:64},"mat4x3<f16>":{align:8,size:32},"mat2x4<f32>":{align:16,size:32},"mat2x4<f16>":{align:8,size:16},"mat3x4<f32>":{align:16,size:48},"mat3x4<f16>":{align:8,size:24},"mat4x4<f32>":{align:16,size:64},"mat4x4<f16>":{align:8,size:32}};function Ue(a){const e=a.map(r=>({data:r,offset:0,size:0}));let t=0;for(let r=0;r<e.length;r++){const s=e[r];let i=G[s.data.type].size;const n=G[s.data.type].align;if(!G[s.data.type])throw new Error(`[Pixi.js] WebGPU UniformBuffer: Unknown type ${s.data.type}`);s.data.size>1&&(i=Math.max(i,n)*s.data.size),t=Math.ceil(t/n)*n,s.size=i,s.offset=t,t+=i}return t=Math.ceil(t/16)*16,{uboElements:e,size:t}}function Me(a,e){const{size:t,align:r}=G[a.data.type],s=(r-t)/4,i=a.data.type.indexOf("i32")>=0?"dataInt32":"data";return` + v = uv.${a.data.name}; + ${e!==0?`offset += ${e};`:""} + + arrayOffset = offset; + + t = 0; + + for(var i=0; i < ${a.data.size*(t/4)}; i++) + { + for(var j = 0; j < ${t/4}; j++) + { + ${i}[arrayOffset++] = v[t++]; + } + ${s!==0?`arrayOffset += ${s};`:""} + } + `}function we(a){return _e(a,"uboWgsl",Me,be)}class q extends ye{constructor(){super({createUboElements:Ue,generateUboSync:we})}}q.extension={type:[p.WebGPUSystem],name:"ubo"};const b=128;class Y{constructor(e){this._bindGroupHash=Object.create(null),this._buffers=[],this._bindGroups=[],this._bufferResources=[],this._renderer=e,this._renderer.renderableGC.addManagedHash(this,"_bindGroupHash"),this._batchBuffer=new ve({minUniformOffsetAlignment:b});const t=256/b;for(let r=0;r<t;r++){let s=T.UNIFORM|T.COPY_DST;r===0&&(s|=T.COPY_SRC),this._buffers.push(new ue({data:this._batchBuffer.data,usage:s}))}}renderEnd(){this._uploadBindGroups(),this._resetBindGroups()}_resetBindGroups(){for(const e in this._bindGroupHash)this._bindGroupHash[e]=null;this._batchBuffer.clear()}getUniformBindGroup(e,t){if(!t&&this._bindGroupHash[e.uid])return this._bindGroupHash[e.uid];this._renderer.ubo.ensureUniformGroup(e);const r=e.buffer.data,s=this._batchBuffer.addEmptyGroup(r.length);return this._renderer.ubo.syncUniformGroup(e,this._batchBuffer.data,s/4),this._bindGroupHash[e.uid]=this._getBindGroup(s/b),this._bindGroupHash[e.uid]}getUboResource(e){this._renderer.ubo.updateUniformGroup(e);const t=e.buffer.data,r=this._batchBuffer.addGroup(t);return this._getBufferResource(r/b)}getArrayBindGroup(e){const t=this._batchBuffer.addGroup(e);return this._getBindGroup(t/b)}getArrayBufferResource(e){const r=this._batchBuffer.addGroup(e)/b;return this._getBufferResource(r)}_getBufferResource(e){if(!this._bufferResources[e]){const t=this._buffers[e%2];this._bufferResources[e]=new xe({buffer:t,offset:(e/2|0)*256,size:b})}return this._bufferResources[e]}_getBindGroup(e){if(!this._bindGroups[e]){const t=new L({0:this._getBufferResource(e)});this._bindGroups[e]=t}return this._bindGroups[e]}_uploadBindGroups(){const e=this._renderer.buffer,t=this._buffers[0];t.update(this._batchBuffer.byteIndex),e.updateBuffer(t);const r=this._renderer.gpu.device.createCommandEncoder();for(let s=1;s<this._buffers.length;s++){const i=this._buffers[s];r.copyBufferToBuffer(e.getGPUBuffer(t),b,e.getGPUBuffer(i),0,this._batchBuffer.byteIndex)}this._renderer.gpu.device.queue.submit([r.finish()])}destroy(){var e;for(let t=0;t<this._bindGroups.length;t++)(e=this._bindGroups[t])==null||e.destroy();this._bindGroups=null,this._bindGroupHash=null;for(let t=0;t<this._buffers.length;t++)this._buffers[t].destroy();this._buffers=null;for(let t=0;t<this._bufferResources.length;t++)this._bufferResources[t].destroy();this._bufferResources=null,this._batchBuffer.destroy(),this._bindGroupHash=null,this._renderer=null}}Y.extension={type:[p.WebGPUPipes],name:"uniformBatch"};const Re={"point-list":0,"line-list":1,"line-strip":2,"triangle-list":3,"triangle-strip":4};function Ee(a,e,t,r,s){return a<<24|e<<16|t<<10|r<<5|s}function Le(a,e,t,r){return t<<6|a<<3|r<<1|e}class ${constructor(e){this._moduleCache=Object.create(null),this._bufferLayoutsCache=Object.create(null),this._bindingNamesCache=Object.create(null),this._pipeCache=Object.create(null),this._pipeStateCaches=Object.create(null),this._colorMask=15,this._multisampleCount=1,this._renderer=e}contextChange(e){this._gpu=e,this.setStencilMode(C.DISABLED),this._updatePipeHash()}setMultisampleCount(e){this._multisampleCount!==e&&(this._multisampleCount=e,this._updatePipeHash())}setRenderTarget(e){this._multisampleCount=e.msaaSamples,this._depthStencilAttachment=e.descriptor.depthStencilAttachment?1:0,this._updatePipeHash()}setColorMask(e){this._colorMask!==e&&(this._colorMask=e,this._updatePipeHash())}setStencilMode(e){this._stencilMode!==e&&(this._stencilMode=e,this._stencilState=Ge[e],this._updatePipeHash())}setPipeline(e,t,r,s){const i=this.getPipeline(e,t,r);s.setPipeline(i)}getPipeline(e,t,r,s){e._layoutKey||(Be(e,t.attributeData),this._generateBufferKey(e)),s||(s=e.topology);const i=Ee(e._layoutKey,t._layoutKey,r.data,r._blendModeId,Re[s]);return this._pipeCache[i]?this._pipeCache[i]:(this._pipeCache[i]=this._createPipeline(e,t,r,s),this._pipeCache[i])}_createPipeline(e,t,r,s){const i=this._gpu.device,n=this._createVertexBufferLayouts(e,t),o=this._renderer.state.getColorTargets(r);o[0].writeMask=this._stencilMode===C.RENDERING_MASK_ADD?0:this._colorMask;const u=this._renderer.shader.getProgramData(t).pipeline,c={vertex:{module:this._getModule(t.vertex.source),entryPoint:t.vertex.entryPoint,buffers:n},fragment:{module:this._getModule(t.fragment.source),entryPoint:t.fragment.entryPoint,targets:o},primitive:{topology:s,cullMode:r.cullMode},layout:u,multisample:{count:this._multisampleCount},label:"PIXI Pipeline"};return this._depthStencilAttachment&&(c.depthStencil={...this._stencilState,format:"depth24plus-stencil8",depthWriteEnabled:r.depthTest,depthCompare:r.depthTest?"less":"always"}),i.createRenderPipeline(c)}_getModule(e){return this._moduleCache[e]||this._createModule(e)}_createModule(e){const t=this._gpu.device;return this._moduleCache[e]=t.createShaderModule({code:e}),this._moduleCache[e]}_generateBufferKey(e){const t=[];let r=0;const s=Object.keys(e.attributes).sort();for(let n=0;n<s.length;n++){const o=e.attributes[s[n]];t[r++]=o.offset,t[r++]=o.format,t[r++]=o.stride,t[r++]=o.instance}const i=t.join("|");return e._layoutKey=M(i,"geometry"),e._layoutKey}_generateAttributeLocationsKey(e){const t=[];let r=0;const s=Object.keys(e.attributeData).sort();for(let n=0;n<s.length;n++){const o=e.attributeData[s[n]];t[r++]=o.location}const i=t.join("|");return e._attributeLocationsKey=M(i,"programAttributes"),e._attributeLocationsKey}getBufferNamesToBind(e,t){const r=e._layoutKey<<16|t._attributeLocationsKey;if(this._bindingNamesCache[r])return this._bindingNamesCache[r];const s=this._createVertexBufferLayouts(e,t),i=Object.create(null),n=t.attributeData;for(let o=0;o<s.length;o++){const c=Object.values(s[o].attributes)[0].shaderLocation;for(const l in n)if(n[l].location===c){i[o]=l;break}}return this._bindingNamesCache[r]=i,i}_createVertexBufferLayouts(e,t){t._attributeLocationsKey||this._generateAttributeLocationsKey(t);const r=e._layoutKey<<16|t._attributeLocationsKey;if(this._bufferLayoutsCache[r])return this._bufferLayoutsCache[r];const s=[];return e.buffers.forEach(i=>{const n={arrayStride:0,stepMode:"vertex",attributes:[]},o=n.attributes;for(const u in t.attributeData){const c=e.attributes[u];(c.divisor??1)!==1&&v(`Attribute ${u} has an invalid divisor value of '${c.divisor}'. WebGPU only supports a divisor value of 1`),c.buffer===i&&(n.arrayStride=c.stride,n.stepMode=c.instance?"instance":"vertex",o.push({shaderLocation:t.attributeData[u].location,offset:c.offset,format:c.format}))}o.length&&s.push(n)}),this._bufferLayoutsCache[r]=s,s}_updatePipeHash(){const e=Le(this._stencilMode,this._multisampleCount,this._colorMask,this._depthStencilAttachment);this._pipeStateCaches[e]||(this._pipeStateCaches[e]=Object.create(null)),this._pipeCache=this._pipeStateCaches[e]}destroy(){this._renderer=null,this._bufferLayoutsCache=null}}$.extension={type:[p.WebGPUSystem],name:"pipeline"};class Ae{constructor(){this.contexts=[],this.msaaTextures=[],this.msaaSamples=1}}class ke{init(e,t){this._renderer=e,this._renderTargetSystem=t}copyToTexture(e,t,r,s,i){const n=this._renderer,o=this._getGpuColorTexture(e),u=n.texture.getGpuSource(t.source);return n.encoder.commandEncoder.copyTextureToTexture({texture:o,origin:r},{texture:u,origin:i},s),t}startRenderPass(e,t=!0,r,s){const n=this._renderTargetSystem.getGpuRenderTarget(e),o=this.getDescriptor(e,t,r);n.descriptor=o,this._renderer.pipeline.setRenderTarget(n),this._renderer.encoder.beginRenderPass(n),this._renderer.encoder.setViewport(s)}finishRenderPass(){this._renderer.encoder.endRenderPass()}_getGpuColorTexture(e){const t=this._renderTargetSystem.getGpuRenderTarget(e);return t.contexts[0]?t.contexts[0].getCurrentTexture():this._renderer.texture.getGpuSource(e.colorTextures[0].source)}getDescriptor(e,t,r){typeof t=="boolean"&&(t=t?y.ALL:y.NONE);const s=this._renderTargetSystem,i=s.getGpuRenderTarget(e),n=e.colorTextures.map((c,l)=>{const h=i.contexts[l];let f,d;h?f=h.getCurrentTexture().createView():f=this._renderer.texture.getGpuSource(c).createView({mipLevelCount:1}),i.msaaTextures[l]&&(d=f,f=this._renderer.texture.getTextureView(i.msaaTextures[l]));const _=t&y.COLOR?"clear":"load";return r??(r=s.defaultClearColor),{view:f,resolveTarget:d,clearValue:r,storeOp:"store",loadOp:_}});let o;if((e.stencil||e.depth)&&!e.depthStencilTexture&&(e.ensureDepthStencilTexture(),e.depthStencilTexture.source.sampleCount=i.msaa?4:1),e.depthStencilTexture){const c=t&y.STENCIL?"clear":"load",l=t&y.DEPTH?"clear":"load";o={view:this._renderer.texture.getGpuSource(e.depthStencilTexture.source).createView(),stencilStoreOp:"store",stencilLoadOp:c,depthClearValue:1,depthLoadOp:l,depthStoreOp:"store"}}return{colorAttachments:n,depthStencilAttachment:o}}clear(e,t=!0,r,s){if(!t)return;const{gpu:i,encoder:n}=this._renderer,o=i.device;if(n.commandEncoder===null){const c=o.createCommandEncoder(),l=this.getDescriptor(e,t,r),h=c.beginRenderPass(l);h.setViewport(s.x,s.y,s.width,s.height,0,1),h.end();const f=c.finish();o.queue.submit([f])}else this.startRenderPass(e,t,r,s)}initGpuRenderTarget(e){e.isRoot=!0;const t=new Ae;return e.colorTextures.forEach((r,s)=>{if(r instanceof ce){const i=r.resource.getContext("webgpu"),n=r.transparent?"premultiplied":"opaque";try{i.configure({device:this._renderer.gpu.device,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,format:"bgra8unorm",alphaMode:n})}catch(o){console.error(o)}t.contexts[s]=i}if(t.msaa=r.source.antialias,r.source.antialias){const i=new de({width:0,height:0,sampleCount:4});t.msaaTextures[s]=i}}),t.msaa&&(t.msaaSamples=4,e.depthStencilTexture&&(e.depthStencilTexture.source.sampleCount=4)),t}destroyGpuRenderTarget(e){e.contexts.forEach(t=>{t.unconfigure()}),e.msaaTextures.forEach(t=>{t.destroy()}),e.msaaTextures.length=0,e.contexts.length=0}ensureDepthStencilTexture(e){const t=this._renderTargetSystem.getGpuRenderTarget(e);e.depthStencilTexture&&t.msaa&&(e.depthStencilTexture.source.sampleCount=4)}resizeGpuRenderTarget(e){const t=this._renderTargetSystem.getGpuRenderTarget(e);t.width=e.width,t.height=e.height,t.msaa&&e.colorTextures.forEach((r,s)=>{const i=t.msaaTextures[s];i==null||i.resize(r.source.width,r.source.height,r.source._resolution)})}}class X extends Se{constructor(e){super(e),this.adaptor=new ke,this.adaptor.init(e,this)}}X.extension={type:[p.WebGPUSystem],name:"renderTarget"};class Z{constructor(){this._gpuProgramData=Object.create(null)}contextChange(e){this._gpu=e}getProgramData(e){return this._gpuProgramData[e._layoutKey]||this._createGPUProgramData(e)}_createGPUProgramData(e){const t=this._gpu.device,r=e.gpuLayout.map(i=>t.createBindGroupLayout({entries:i})),s={bindGroupLayouts:r};return this._gpuProgramData[e._layoutKey]={bindGroups:r,pipeline:t.createPipelineLayout(s)},this._gpuProgramData[e._layoutKey]}destroy(){this._gpu=null,this._gpuProgramData=null}}Z.extension={type:[p.WebGPUSystem],name:"shader"};const g={};g.normal={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}};g.add={alpha:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one",operation:"add"}};g.multiply={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"dst",dstFactor:"one-minus-src-alpha",operation:"add"}};g.screen={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one-minus-src",operation:"add"}};g.overlay={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one-minus-src",operation:"add"}};g.none={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"zero",dstFactor:"zero",operation:"add"}};g["normal-npm"]={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"}};g["add-npm"]={alpha:{srcFactor:"one",dstFactor:"one",operation:"add"},color:{srcFactor:"src-alpha",dstFactor:"one",operation:"add"}};g["screen-npm"]={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"src-alpha",dstFactor:"one-minus-src",operation:"add"}};g.erase={alpha:{srcFactor:"zero",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"zero",dstFactor:"one-minus-src",operation:"add"}};g.min={alpha:{srcFactor:"one",dstFactor:"one",operation:"min"},color:{srcFactor:"one",dstFactor:"one",operation:"min"}};g.max={alpha:{srcFactor:"one",dstFactor:"one",operation:"max"},color:{srcFactor:"one",dstFactor:"one",operation:"max"}};class J{constructor(){this.defaultState=new F,this.defaultState.blend=!0}contextChange(e){this.gpu=e}getColorTargets(e){return[{format:"bgra8unorm",writeMask:0,blend:g[e.blendMode]||g.normal}]}destroy(){this.gpu=null}}J.extension={type:[p.WebGPUSystem],name:"state"};const De={type:"image",upload(a,e,t){const r=a.resource,s=(a.pixelWidth|0)*(a.pixelHeight|0),i=r.byteLength/s;t.device.queue.writeTexture({texture:e},r,{offset:0,rowsPerImage:a.pixelHeight,bytesPerRow:a.pixelHeight*i},{width:a.pixelWidth,height:a.pixelHeight,depthOrArrayLayers:1})}},Q={"bc1-rgba-unorm":{blockBytes:8,blockWidth:4,blockHeight:4},"bc2-rgba-unorm":{blockBytes:16,blockWidth:4,blockHeight:4},"bc3-rgba-unorm":{blockBytes:16,blockWidth:4,blockHeight:4},"bc7-rgba-unorm":{blockBytes:16,blockWidth:4,blockHeight:4},"etc1-rgb-unorm":{blockBytes:8,blockWidth:4,blockHeight:4},"etc2-rgba8unorm":{blockBytes:16,blockWidth:4,blockHeight:4},"astc-4x4-unorm":{blockBytes:16,blockWidth:4,blockHeight:4}},He={blockBytes:4,blockWidth:1,blockHeight:1},ze={type:"compressed",upload(a,e,t){let r=a.pixelWidth,s=a.pixelHeight;const i=Q[a.format]||He;for(let n=0;n<a.resource.length;n++){const o=a.resource[n],u=Math.ceil(r/i.blockWidth)*i.blockBytes;t.device.queue.writeTexture({texture:e,mipLevel:n},o,{offset:0,bytesPerRow:u},{width:Math.ceil(r/i.blockWidth)*i.blockWidth,height:Math.ceil(s/i.blockHeight)*i.blockHeight,depthOrArrayLayers:1}),r=Math.max(r>>1,1),s=Math.max(s>>1,1)}}},ee={type:"image",upload(a,e,t){const r=a.resource;if(!r)return;if(globalThis.HTMLImageElement&&r instanceof HTMLImageElement){const o=B.get().createCanvas(r.width,r.height);o.getContext("2d").drawImage(r,0,0,r.width,r.height),a.resource=o,v("ImageSource: Image element passed, converting to canvas and replacing resource.")}const s=Math.min(e.width,a.resourceWidth||a.pixelWidth),i=Math.min(e.height,a.resourceHeight||a.pixelHeight),n=a.alphaMode==="premultiply-alpha-on-upload";t.device.queue.copyExternalImageToTexture({source:r},{texture:e,premultipliedAlpha:n},{width:s,height:i})}},Fe={type:"video",upload(a,e,t){ee.upload(a,e,t)}};class Oe{constructor(e){this.device=e,this.sampler=e.createSampler({minFilter:"linear"}),this.pipelines={}}_getMipmapPipeline(e){let t=this.pipelines[e];return t||(this.mipmapShaderModule||(this.mipmapShaderModule=this.device.createShaderModule({code:` + var<private> pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>( + vec2<f32>(-1.0, -1.0), vec2<f32>(-1.0, 3.0), vec2<f32>(3.0, -1.0)); + + struct VertexOutput { + @builtin(position) position : vec4<f32>, + @location(0) texCoord : vec2<f32>, + }; + + @vertex + fn vertexMain(@builtin(vertex_index) vertexIndex : u32) -> VertexOutput { + var output : VertexOutput; + output.texCoord = pos[vertexIndex] * vec2<f32>(0.5, -0.5) + vec2<f32>(0.5); + output.position = vec4<f32>(pos[vertexIndex], 0.0, 1.0); + return output; + } + + @group(0) @binding(0) var imgSampler : sampler; + @group(0) @binding(1) var img : texture_2d<f32>; + + @fragment + fn fragmentMain(@location(0) texCoord : vec2<f32>) -> @location(0) vec4<f32> { + return textureSample(img, imgSampler, texCoord); + } + `})),t=this.device.createRenderPipeline({layout:"auto",vertex:{module:this.mipmapShaderModule,entryPoint:"vertexMain"},fragment:{module:this.mipmapShaderModule,entryPoint:"fragmentMain",targets:[{format:e}]}}),this.pipelines[e]=t),t}generateMipmap(e){const t=this._getMipmapPipeline(e.format);if(e.dimension==="3d"||e.dimension==="1d")throw new Error("Generating mipmaps for non-2d textures is currently unsupported!");let r=e;const s=e.depthOrArrayLayers||1,i=e.usage&GPUTextureUsage.RENDER_ATTACHMENT;if(!i){const u={size:{width:Math.ceil(e.width/2),height:Math.ceil(e.height/2),depthOrArrayLayers:s},format:e.format,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_SRC|GPUTextureUsage.RENDER_ATTACHMENT,mipLevelCount:e.mipLevelCount-1};r=this.device.createTexture(u)}const n=this.device.createCommandEncoder({}),o=t.getBindGroupLayout(0);for(let u=0;u<s;++u){let c=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:"2d",baseArrayLayer:u,arrayLayerCount:1}),l=i?1:0;for(let h=1;h<e.mipLevelCount;++h){const f=r.createView({baseMipLevel:l++,mipLevelCount:1,dimension:"2d",baseArrayLayer:u,arrayLayerCount:1}),d=n.beginRenderPass({colorAttachments:[{view:f,storeOp:"store",loadOp:"clear",clearValue:{r:0,g:0,b:0,a:0}}]}),_=this.device.createBindGroup({layout:o,entries:[{binding:0,resource:this.sampler},{binding:1,resource:c}]});d.setPipeline(t),d.setBindGroup(0,_),d.draw(3,1,0,0),d.end(),c=f}}if(!i){const u={width:Math.ceil(e.width/2),height:Math.ceil(e.height/2),depthOrArrayLayers:s};for(let c=1;c<e.mipLevelCount;++c)n.copyTextureToTexture({texture:r,mipLevel:c-1},{texture:e,mipLevel:c},u),u.width=Math.ceil(u.width/2),u.height=Math.ceil(u.height/2)}return this.device.queue.submit([n.finish()]),i||r.destroy(),e}}class te{constructor(e){this.managedTextures=[],this._gpuSources=Object.create(null),this._gpuSamplers=Object.create(null),this._bindGroupHash=Object.create(null),this._textureViewHash=Object.create(null),this._uploads={image:ee,buffer:De,video:Fe,compressed:ze},this._renderer=e,e.renderableGC.addManagedHash(this,"_gpuSources"),e.renderableGC.addManagedHash(this,"_gpuSamplers"),e.renderableGC.addManagedHash(this,"_bindGroupHash"),e.renderableGC.addManagedHash(this,"_textureViewHash")}contextChange(e){this._gpu=e}initSource(e){return this._gpuSources[e.uid]?this._gpuSources[e.uid]:this._initSource(e)}_initSource(e){if(e.autoGenerateMipmaps){const u=Math.max(e.pixelWidth,e.pixelHeight);e.mipLevelCount=Math.floor(Math.log2(u))+1}let t=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST;e.uploadMethodId!=="compressed"&&(t|=GPUTextureUsage.RENDER_ATTACHMENT,t|=GPUTextureUsage.COPY_SRC);const r=Q[e.format]||{blockWidth:1,blockHeight:1},s=Math.ceil(e.pixelWidth/r.blockWidth)*r.blockWidth,i=Math.ceil(e.pixelHeight/r.blockHeight)*r.blockHeight,n={label:e.label,size:{width:s,height:i},format:e.format,sampleCount:e.sampleCount,mipLevelCount:e.mipLevelCount,dimension:e.dimension,usage:t},o=this._gpuSources[e.uid]=this._gpu.device.createTexture(n);return this.managedTextures.includes(e)||(e.on("update",this.onSourceUpdate,this),e.on("resize",this.onSourceResize,this),e.on("destroy",this.onSourceDestroy,this),e.on("unload",this.onSourceUnload,this),e.on("updateMipmaps",this.onUpdateMipmaps,this),this.managedTextures.push(e)),this.onSourceUpdate(e),o}onSourceUpdate(e){const t=this.getGpuSource(e);t&&(this._uploads[e.uploadMethodId]&&this._uploads[e.uploadMethodId].upload(e,t,this._gpu),e.autoGenerateMipmaps&&e.mipLevelCount>1&&this.onUpdateMipmaps(e))}onSourceUnload(e){const t=this._gpuSources[e.uid];t&&(this._gpuSources[e.uid]=null,t.destroy())}onUpdateMipmaps(e){this._mipmapGenerator||(this._mipmapGenerator=new Oe(this._gpu.device));const t=this.getGpuSource(e);this._mipmapGenerator.generateMipmap(t)}onSourceDestroy(e){e.off("update",this.onSourceUpdate,this),e.off("unload",this.onSourceUnload,this),e.off("destroy",this.onSourceDestroy,this),e.off("resize",this.onSourceResize,this),e.off("updateMipmaps",this.onUpdateMipmaps,this),this.managedTextures.splice(this.managedTextures.indexOf(e),1),this.onSourceUnload(e)}onSourceResize(e){const t=this._gpuSources[e.uid];t?(t.width!==e.pixelWidth||t.height!==e.pixelHeight)&&(this._textureViewHash[e.uid]=null,this._bindGroupHash[e.uid]=null,this.onSourceUnload(e),this.initSource(e)):this.initSource(e)}_initSampler(e){return this._gpuSamplers[e._resourceId]=this._gpu.device.createSampler(e),this._gpuSamplers[e._resourceId]}getGpuSampler(e){return this._gpuSamplers[e._resourceId]||this._initSampler(e)}getGpuSource(e){return this._gpuSources[e.uid]||this.initSource(e)}getTextureBindGroup(e){return this._bindGroupHash[e.uid]??this._createTextureBindGroup(e)}_createTextureBindGroup(e){const t=e.source;return this._bindGroupHash[e.uid]=new L({0:t,1:t.style,2:new A({uTextureMatrix:{type:"mat3x3<f32>",value:e.textureMatrix.mapCoord}})}),this._bindGroupHash[e.uid]}getTextureView(e){const t=e.source;return this._textureViewHash[t.uid]??this._createTextureView(t)}_createTextureView(e){return this._textureViewHash[e.uid]=this.getGpuSource(e).createView(),this._textureViewHash[e.uid]}generateCanvas(e){const t=this._renderer,r=t.gpu.device.createCommandEncoder(),s=B.get().createCanvas();s.width=e.source.pixelWidth,s.height=e.source.pixelHeight;const i=s.getContext("webgpu");return i.configure({device:t.gpu.device,usage:GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC,format:B.get().getNavigator().gpu.getPreferredCanvasFormat(),alphaMode:"premultiplied"}),r.copyTextureToTexture({texture:t.texture.getGpuSource(e.source),origin:{x:0,y:0}},{texture:i.getCurrentTexture()},{width:s.width,height:s.height}),t.gpu.device.queue.submit([r.finish()]),s}getPixels(e){const t=this.generateCanvas(e),r=w.getOptimalCanvasAndContext(t.width,t.height),s=r.context;s.drawImage(t,0,0);const{width:i,height:n}=t,o=s.getImageData(0,0,i,n),u=new Uint8ClampedArray(o.data.buffer);return w.returnCanvasAndContext(r),{pixels:u,width:i,height:n}}destroy(){this.managedTextures.slice().forEach(e=>this.onSourceDestroy(e)),this.managedTextures=null;for(const e of Object.keys(this._bindGroupHash)){const t=Number(e),r=this._bindGroupHash[t];r==null||r.destroy(),this._bindGroupHash[t]=null}this._gpu=null,this._mipmapGenerator=null,this._gpuSources=null,this._bindGroupHash=null,this._textureViewHash=null,this._gpuSamplers=null}}te.extension={type:[p.WebGPUSystem],name:"texture"};class re{constructor(){this._maxTextures=0}contextChange(e){const t=new A({uTransformMatrix:{value:new k,type:"mat3x3<f32>"},uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uRound:{value:0,type:"f32"}});this._maxTextures=e.limits.maxBatchableTextures;const r=D({name:"graphics",bits:[he,pe(this._maxTextures),ge,H]});this.shader=new z({gpuProgram:r,resources:{localUniforms:t}})}execute(e,t){const r=t.context,s=r.customShader||this.shader,i=e.renderer,n=i.graphicsContext,{batcher:o,instructions:u}=n.getContextRenderData(r),c=i.encoder;c.setGeometry(o.geometry,s.gpuProgram);const l=i.globalUniforms.bindGroup;c.setBindGroup(0,l,s.gpuProgram);const h=i.renderPipes.uniformBatch.getUniformBindGroup(s.resources.localUniforms,!0);c.setBindGroup(2,h,s.gpuProgram);const f=u.instructions;let d=null;for(let _=0;_<u.instructionSize;_++){const m=f[_];if(m.topology!==d&&(d=m.topology,c.setPipelineFromGeometryProgramAndState(o.geometry,s.gpuProgram,e.state,m.topology)),s.groups[1]=m.bindGroup,!m.gpuBindGroup){const P=m.textures;m.bindGroup=E(P.textures,P.count,this._maxTextures),m.gpuBindGroup=i.bindGroup.getBindGroup(m.bindGroup,s.gpuProgram,1)}c.setBindGroup(1,m.bindGroup,s.gpuProgram),c.renderPassEncoder.drawIndexed(m.size,1,m.start)}}destroy(){this.shader.destroy(!0),this.shader=null}}re.extension={type:[p.WebGPUPipesAdaptor],name:"graphics"};class se{init(){const e=D({name:"mesh",bits:[me,Pe,H]});this._shader=new z({gpuProgram:e,resources:{uTexture:R.EMPTY._source,uSampler:R.EMPTY._source.style,textureUniforms:{uTextureMatrix:{type:"mat3x3<f32>",value:new k}}}})}execute(e,t){const r=e.renderer;let s=t._shader;if(!s)s=this._shader,s.groups[2]=r.texture.getTextureBindGroup(t.texture);else if(!s.gpuProgram){v("Mesh shader has no gpuProgram",t.shader);return}const i=s.gpuProgram;if(i.autoAssignGlobalUniforms&&(s.groups[0]=r.globalUniforms.bindGroup),i.autoAssignLocalUniforms){const n=e.localUniforms;s.groups[1]=r.renderPipes.uniformBatch.getUniformBindGroup(n,!0)}r.encoder.draw({geometry:t._geometry,shader:s,state:t.state})}destroy(){this._shader.destroy(!0),this._shader=null}}se.extension={type:[p.WebGPUPipesAdaptor],name:"mesh"};const Ie=[...Te,q,N,U,j,W,te,X,Z,J,$,V,K,I],We=[...Ce,Y],Ve=[O,se,re],ie=[],ne=[],oe=[];S.handleByNamedList(p.WebGPUSystem,ie);S.handleByNamedList(p.WebGPUPipes,ne);S.handleByNamedList(p.WebGPUPipesAdaptor,oe);S.add(...Ie,...We,...Ve);class qe extends le{constructor(){const e={name:"webgpu",type:fe.WEBGPU,systems:ie,renderPipes:ne,renderPipeAdaptors:oe};super(e)}}export{qe as WebGPURenderer}; diff --git a/dist/assets/browserAll-BytxDfn1.js b/dist/assets/browserAll-BytxDfn1.js new file mode 100644 index 0000000..edb4889 --- /dev/null +++ b/dist/assets/browserAll-BytxDfn1.js @@ -0,0 +1,14 @@ +import{T as A,U as Z,P as g,r as te,E as b,a as ie,w as y,e as w,C as V}from"./index-DB6B0XuI.js";import"./webworkerAll-J8ccMaq4.js";import"./colorToUniform-DmtBy-2V.js";class q{constructor(e){this._lastTransform="",this._observer=null,this._tickerAttached=!1,this.updateTranslation=()=>{if(!this._canvas)return;const t=this._canvas.getBoundingClientRect(),i=this._canvas.width,n=this._canvas.height,s=t.width/i*this._renderer.resolution,o=t.height/n*this._renderer.resolution,r=t.left,l=t.top,d=`translate(${r}px, ${l}px) scale(${s}, ${o})`;d!==this._lastTransform&&(this._domElement.style.transform=d,this._lastTransform=d)},this._domElement=e.domElement,this._renderer=e.renderer,!(globalThis.OffscreenCanvas&&this._renderer.canvas instanceof OffscreenCanvas)&&(this._canvas=this._renderer.canvas,this._attachObserver())}get canvas(){return this._canvas}ensureAttached(){!this._domElement.parentNode&&this._canvas.parentNode&&(this._canvas.parentNode.appendChild(this._domElement),this.updateTranslation())}_attachObserver(){"ResizeObserver"in globalThis?(this._observer&&(this._observer.disconnect(),this._observer=null),this._observer=new ResizeObserver(e=>{for(const t of e){if(t.target!==this._canvas)continue;const i=this.canvas.width,n=this.canvas.height,s=t.contentRect.width/i*this._renderer.resolution,o=t.contentRect.height/n*this._renderer.resolution;(this._lastScaleX!==s||this._lastScaleY!==o)&&(this.updateTranslation(),this._lastScaleX=s,this._lastScaleY=o)}}),this._observer.observe(this._canvas)):this._tickerAttached||A.shared.add(this.updateTranslation,this,Z.HIGH)}destroy(){this._observer?(this._observer.disconnect(),this._observer=null):this._tickerAttached&&A.shared.remove(this.updateTranslation),this._domElement=null,this._renderer=null,this._canvas=null,this._tickerAttached=!1,this._lastTransform="",this._lastScaleX=null,this._lastScaleY=null}}class M{constructor(e){this.bubbles=!0,this.cancelBubble=!0,this.cancelable=!1,this.composed=!1,this.defaultPrevented=!1,this.eventPhase=M.prototype.NONE,this.propagationStopped=!1,this.propagationImmediatelyStopped=!1,this.layer=new g,this.page=new g,this.NONE=0,this.CAPTURING_PHASE=1,this.AT_TARGET=2,this.BUBBLING_PHASE=3,this.manager=e}get layerX(){return this.layer.x}get layerY(){return this.layer.y}get pageX(){return this.page.x}get pageY(){return this.page.y}get data(){return this}composedPath(){return this.manager&&(!this.path||this.path[this.path.length-1]!==this.target)&&(this.path=this.target?this.manager.propagationPath(this.target):[]),this.path}initEvent(e,t,i){throw new Error("initEvent() is a legacy DOM API. It is not implemented in the Federated Events API.")}initUIEvent(e,t,i,n,s){throw new Error("initUIEvent() is a legacy DOM API. It is not implemented in the Federated Events API.")}preventDefault(){this.nativeEvent instanceof Event&&this.nativeEvent.cancelable&&this.nativeEvent.preventDefault(),this.defaultPrevented=!0}stopImmediatePropagation(){this.propagationImmediatelyStopped=!0}stopPropagation(){this.propagationStopped=!0}}var I=/iPhone/i,C=/iPod/i,L=/iPad/i,U=/\biOS-universal(?:.+)Mac\b/i,k=/\bAndroid(?:.+)Mobile\b/i,R=/Android/i,E=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,O=/Silk/i,m=/Windows Phone/i,X=/\bWindows(?:.+)ARM\b/i,Y=/BlackBerry/i,H=/BB10/i,F=/Opera Mini/i,N=/\b(CriOS|Chrome)(?:.+)Mobile/i,$=/Mobile(?:.+)Firefox\b/i,K=function(a){return typeof a<"u"&&a.platform==="MacIntel"&&typeof a.maxTouchPoints=="number"&&a.maxTouchPoints>1&&typeof MSStream>"u"};function ne(a){return function(e){return e.test(a)}}function G(a){var e={userAgent:"",platform:"",maxTouchPoints:0};!a&&typeof navigator<"u"?e={userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints||0}:typeof a=="string"?e.userAgent=a:a&&a.userAgent&&(e={userAgent:a.userAgent,platform:a.platform,maxTouchPoints:a.maxTouchPoints||0});var t=e.userAgent,i=t.split("[FBAN");typeof i[1]<"u"&&(t=i[0]),i=t.split("Twitter"),typeof i[1]<"u"&&(t=i[0]);var n=ne(t),s={apple:{phone:n(I)&&!n(m),ipod:n(C),tablet:!n(I)&&(n(L)||K(e))&&!n(m),universal:n(U),device:(n(I)||n(C)||n(L)||n(U)||K(e))&&!n(m)},amazon:{phone:n(E),tablet:!n(E)&&n(O),device:n(E)||n(O)},android:{phone:!n(m)&&n(E)||!n(m)&&n(k),tablet:!n(m)&&!n(E)&&!n(k)&&(n(O)||n(R)),device:!n(m)&&(n(E)||n(O)||n(k)||n(R))||n(/\bokhttp\b/i)},windows:{phone:n(m),tablet:n(X),device:n(m)||n(X)},other:{blackberry:n(Y),blackberry10:n(H),opera:n(F),firefox:n($),chrome:n(N),device:n(Y)||n(H)||n(F)||n($)||n(N)},any:!1,phone:!1,tablet:!1};return s.any=s.apple.device||s.android.device||s.windows.device||s.other.device,s.phone=s.apple.phone||s.android.phone||s.windows.phone,s.tablet=s.apple.tablet||s.android.tablet||s.windows.tablet,s}const se=G.default??G,oe=se(globalThis.navigator),re=9,W=100,ae=0,he=0,j=2,z=1,le=-1e3,ce=-1e3,de=2,S=class J{constructor(e,t=oe){this._mobileInfo=t,this.debug=!1,this._activateOnTab=!0,this._deactivateOnMouseMove=!0,this._isActive=!1,this._isMobileAccessibility=!1,this._div=null,this._pool=[],this._renderId=0,this._children=[],this._androidUpdateCount=0,this._androidUpdateFrequency=500,this._hookDiv=null,(t.tablet||t.phone)&&this._createTouchHook(),this._renderer=e}get isActive(){return this._isActive}get isMobileAccessibility(){return this._isMobileAccessibility}get hookDiv(){return this._hookDiv}_createTouchHook(){const e=document.createElement("button");e.style.width=`${z}px`,e.style.height=`${z}px`,e.style.position="absolute",e.style.top=`${le}px`,e.style.left=`${ce}px`,e.style.zIndex=de.toString(),e.style.backgroundColor="#FF0000",e.title="select to enable accessibility for this content",e.addEventListener("focus",()=>{this._isMobileAccessibility=!0,this._activate(),this._destroyTouchHook()}),document.body.appendChild(e),this._hookDiv=e}_destroyTouchHook(){this._hookDiv&&(document.body.removeChild(this._hookDiv),this._hookDiv=null)}_activate(){if(this._isActive)return;this._isActive=!0,this._div||(this._div=document.createElement("div"),this._div.style.position="absolute",this._div.style.top=`${ae}px`,this._div.style.left=`${he}px`,this._div.style.pointerEvents="none",this._div.style.zIndex=j.toString(),this._canvasObserver=new q({domElement:this._div,renderer:this._renderer})),this._activateOnTab&&(this._onKeyDown=this._onKeyDown.bind(this),globalThis.addEventListener("keydown",this._onKeyDown,!1)),this._deactivateOnMouseMove&&(this._onMouseMove=this._onMouseMove.bind(this),globalThis.document.addEventListener("mousemove",this._onMouseMove,!0));const e=this._renderer.view.canvas;if(e.parentNode)this._canvasObserver.ensureAttached(),this._initAccessibilitySetup();else{const t=new MutationObserver(()=>{e.parentNode&&(t.disconnect(),this._canvasObserver.ensureAttached(),this._initAccessibilitySetup())});t.observe(document.body,{childList:!0,subtree:!0})}}_initAccessibilitySetup(){this._renderer.runners.postrender.add(this),this._renderer.lastObjectRendered&&this._updateAccessibleObjects(this._renderer.lastObjectRendered)}_deactivate(){if(!(!this._isActive||this._isMobileAccessibility)){this._isActive=!1,globalThis.document.removeEventListener("mousemove",this._onMouseMove,!0),this._activateOnTab&&globalThis.addEventListener("keydown",this._onKeyDown,!1),this._renderer.runners.postrender.remove(this);for(const e of this._children)e._accessibleDiv&&e._accessibleDiv.parentNode&&(e._accessibleDiv.parentNode.removeChild(e._accessibleDiv),e._accessibleDiv=null),e._accessibleActive=!1;this._pool.forEach(e=>{e.parentNode&&e.parentNode.removeChild(e)}),this._div&&this._div.parentNode&&this._div.parentNode.removeChild(this._div),this._pool=[],this._children=[]}}_updateAccessibleObjects(e){if(!e.visible||!e.accessibleChildren)return;e.accessible&&(e._accessibleActive||this._addChild(e),e._renderId=this._renderId);const t=e.children;if(t)for(let i=0;i<t.length;i++)this._updateAccessibleObjects(t[i])}init(e){const i={accessibilityOptions:{...J.defaultOptions,...(e==null?void 0:e.accessibilityOptions)||{}}};this.debug=i.accessibilityOptions.debug,this._activateOnTab=i.accessibilityOptions.activateOnTab,this._deactivateOnMouseMove=i.accessibilityOptions.deactivateOnMouseMove,i.accessibilityOptions.enabledByDefault?this._activate():this._activateOnTab&&(this._onKeyDown=this._onKeyDown.bind(this),globalThis.addEventListener("keydown",this._onKeyDown,!1)),this._renderer.runners.postrender.remove(this)}postrender(){const e=performance.now();if(this._mobileInfo.android.device&&e<this._androidUpdateCount||(this._androidUpdateCount=e+this._androidUpdateFrequency,!this._renderer.renderingToScreen||!this._renderer.view.canvas))return;const t=new Set;if(this._renderer.lastObjectRendered){this._updateAccessibleObjects(this._renderer.lastObjectRendered);for(const i of this._children)i._renderId===this._renderId&&t.add(this._children.indexOf(i))}for(let i=this._children.length-1;i>=0;i--){const n=this._children[i];t.has(i)||(n._accessibleDiv&&n._accessibleDiv.parentNode&&(n._accessibleDiv.parentNode.removeChild(n._accessibleDiv),this._pool.push(n._accessibleDiv),n._accessibleDiv=null),n._accessibleActive=!1,te(this._children,i,1))}this._renderer.renderingToScreen&&this._canvasObserver.ensureAttached();for(let i=0;i<this._children.length;i++){const n=this._children[i];if(!n._accessibleActive||!n._accessibleDiv)continue;const s=n._accessibleDiv,o=n.hitArea||n.getBounds().rectangle;if(n.hitArea){const r=n.worldTransform;s.style.left=`${r.tx+o.x*r.a}px`,s.style.top=`${r.ty+o.y*r.d}px`,s.style.width=`${o.width*r.a}px`,s.style.height=`${o.height*r.d}px`}else this._capHitArea(o),s.style.left=`${o.x}px`,s.style.top=`${o.y}px`,s.style.width=`${o.width}px`,s.style.height=`${o.height}px`}this._renderId++}_updateDebugHTML(e){e.innerHTML=`type: ${e.type}</br> title : ${e.title}</br> tabIndex: ${e.tabIndex}`}_capHitArea(e){e.x<0&&(e.width+=e.x,e.x=0),e.y<0&&(e.height+=e.y,e.y=0);const{width:t,height:i}=this._renderer;e.x+e.width>t&&(e.width=t-e.x),e.y+e.height>i&&(e.height=i-e.y)}_addChild(e){let t=this._pool.pop();t||(e.accessibleType==="button"?t=document.createElement("button"):(t=document.createElement(e.accessibleType),t.style.cssText=` + color: transparent; + pointer-events: none; + padding: 0; + margin: 0; + border: 0; + outline: 0; + background: transparent; + box-sizing: border-box; + user-select: none; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + `,e.accessibleText&&(t.innerText=e.accessibleText)),t.style.width=`${W}px`,t.style.height=`${W}px`,t.style.backgroundColor=this.debug?"rgba(255,255,255,0.5)":"transparent",t.style.position="absolute",t.style.zIndex=j.toString(),t.style.borderStyle="none",navigator.userAgent.toLowerCase().includes("chrome")?t.setAttribute("aria-live","off"):t.setAttribute("aria-live","polite"),navigator.userAgent.match(/rv:.*Gecko\//)?t.setAttribute("aria-relevant","additions"):t.setAttribute("aria-relevant","text"),t.addEventListener("click",this._onClick.bind(this)),t.addEventListener("focus",this._onFocus.bind(this)),t.addEventListener("focusout",this._onFocusOut.bind(this))),t.style.pointerEvents=e.accessiblePointerEvents,t.type=e.accessibleType,e.accessibleTitle&&e.accessibleTitle!==null?t.title=e.accessibleTitle:(!e.accessibleHint||e.accessibleHint===null)&&(t.title=`container ${e.tabIndex}`),e.accessibleHint&&e.accessibleHint!==null&&t.setAttribute("aria-label",e.accessibleHint),e.interactive?t.tabIndex=e.tabIndex:t.tabIndex=0,this.debug&&this._updateDebugHTML(t),e._accessibleActive=!0,e._accessibleDiv=t,t.container=e,this._children.push(e),this._div.appendChild(e._accessibleDiv)}_dispatchEvent(e,t){const{container:i}=e.target,n=this._renderer.events.rootBoundary,s=Object.assign(new M(n),{target:i});n.rootTarget=this._renderer.lastObjectRendered,t.forEach(o=>n.dispatchEvent(s,o))}_onClick(e){this._dispatchEvent(e,["click","pointertap","tap"])}_onFocus(e){e.target.getAttribute("aria-live")||e.target.setAttribute("aria-live","assertive"),this._dispatchEvent(e,["mouseover"])}_onFocusOut(e){e.target.getAttribute("aria-live")||e.target.setAttribute("aria-live","polite"),this._dispatchEvent(e,["mouseout"])}_onKeyDown(e){e.keyCode!==re||!this._activateOnTab||this._activate()}_onMouseMove(e){e.movementX===0&&e.movementY===0||this._deactivate()}destroy(){var e;this._deactivate(),this._destroyTouchHook(),(e=this._canvasObserver)==null||e.destroy(),this._canvasObserver=null,this._div=null,this._pool=null,this._children=null,this._renderer=null,this._activateOnTab&&globalThis.removeEventListener("keydown",this._onKeyDown)}setAccessibilityEnabled(e){e?this._activate():this._deactivate()}};S.extension={type:[b.WebGLSystem,b.WebGPUSystem],name:"accessibility"};S.defaultOptions={enabledByDefault:!1,debug:!1,activateOnTab:!0,deactivateOnMouseMove:!0};let ue=S;const pe={accessible:!1,accessibleTitle:null,accessibleHint:null,tabIndex:0,accessibleType:"button",accessibleText:null,accessiblePointerEvents:"auto",accessibleChildren:!0,_accessibleActive:!1,_accessibleDiv:null,_renderId:-1};class Q{constructor(e){this._attachedDomElements=[],this._renderer=e,this._renderer.runners.postrender.add(this),this._renderer.runners.init.add(this),this._domElement=document.createElement("div"),this._domElement.style.position="absolute",this._domElement.style.top="0",this._domElement.style.left="0",this._domElement.style.pointerEvents="none",this._domElement.style.zIndex="1000"}init(){this._canvasObserver=new q({domElement:this._domElement,renderer:this._renderer})}addRenderable(e,t){this._attachedDomElements.includes(e)||this._attachedDomElements.push(e)}updateRenderable(e){}validateRenderable(e){return!0}postrender(){const e=this._attachedDomElements;if(e.length===0){this._domElement.remove();return}this._canvasObserver.ensureAttached();for(let t=0;t<e.length;t++){const i=e[t],n=i.element;if(!i.parent||i.globalDisplayStatus<7)n==null||n.remove(),e.splice(t,1),t--;else{this._domElement.contains(n)||(n.style.position="absolute",n.style.pointerEvents="auto",this._domElement.appendChild(n));const s=i.worldTransform,o=i._anchor,r=i.width*o.x,l=i.height*o.y;n.style.transformOrigin=`${r}px ${l}px`,n.style.transform=`matrix(${s.a}, ${s.b}, ${s.c}, ${s.d}, ${s.tx-r}, ${s.ty-l})`,n.style.opacity=i.groupAlpha.toString()}}}destroy(){var e;this._renderer.runners.postrender.remove(this);for(let t=0;t<this._attachedDomElements.length;t++)(e=this._attachedDomElements[t].element)==null||e.remove();this._attachedDomElements.length=0,this._domElement.remove(),this._canvasObserver.destroy(),this._renderer=null}}Q.extension={type:[b.WebGLPipes,b.WebGPUPipes,b.CanvasPipes],name:"dom"};class ve{constructor(){this.interactionFrequency=10,this._deltaTime=0,this._didMove=!1,this._tickerAdded=!1,this._pauseUpdate=!0}init(e){this.removeTickerListener(),this.events=e,this.interactionFrequency=10,this._deltaTime=0,this._didMove=!1,this._tickerAdded=!1,this._pauseUpdate=!0}get pauseUpdate(){return this._pauseUpdate}set pauseUpdate(e){this._pauseUpdate=e}addTickerListener(){this._tickerAdded||!this.domElement||(A.system.add(this._tickerUpdate,this,Z.INTERACTION),this._tickerAdded=!0)}removeTickerListener(){this._tickerAdded&&(A.system.remove(this._tickerUpdate,this),this._tickerAdded=!1)}pointerMoved(){this._didMove=!0}_update(){if(!this.domElement||this._pauseUpdate)return;if(this._didMove){this._didMove=!1;return}const e=this.events._rootPointerEvent;this.events.supportsTouchEvents&&e.pointerType==="touch"||globalThis.document.dispatchEvent(this.events.supportsPointerEvents?new PointerEvent("pointermove",{clientX:e.clientX,clientY:e.clientY,pointerType:e.pointerType,pointerId:e.pointerId}):new MouseEvent("mousemove",{clientX:e.clientX,clientY:e.clientY}))}_tickerUpdate(e){this._deltaTime+=e.deltaTime,!(this._deltaTime<this.interactionFrequency)&&(this._deltaTime=0,this._update())}destroy(){this.removeTickerListener(),this.events=null,this.domElement=null,this._deltaTime=0,this._didMove=!1,this._tickerAdded=!1,this._pauseUpdate=!0}}const _=new ve;class D extends M{constructor(){super(...arguments),this.client=new g,this.movement=new g,this.offset=new g,this.global=new g,this.screen=new g}get clientX(){return this.client.x}get clientY(){return this.client.y}get x(){return this.clientX}get y(){return this.clientY}get movementX(){return this.movement.x}get movementY(){return this.movement.y}get offsetX(){return this.offset.x}get offsetY(){return this.offset.y}get globalX(){return this.global.x}get globalY(){return this.global.y}get screenX(){return this.screen.x}get screenY(){return this.screen.y}getLocalPosition(e,t,i){return e.worldTransform.applyInverse(i||this.global,t)}getModifierState(e){return"getModifierState"in this.nativeEvent&&this.nativeEvent.getModifierState(e)}initMouseEvent(e,t,i,n,s,o,r,l,d,p,u,h,v,c,Ee){throw new Error("Method not implemented.")}}class f extends D{constructor(){super(...arguments),this.width=0,this.height=0,this.isPrimary=!1}getCoalescedEvents(){return this.type==="pointermove"||this.type==="mousemove"||this.type==="touchmove"?[this]:[]}getPredictedEvents(){throw new Error("getPredictedEvents is not supported!")}}class T extends D{constructor(){super(...arguments),this.DOM_DELTA_PIXEL=0,this.DOM_DELTA_LINE=1,this.DOM_DELTA_PAGE=2}}T.DOM_DELTA_PIXEL=0;T.DOM_DELTA_LINE=1;T.DOM_DELTA_PAGE=2;const fe=2048,me=new g,P=new g;class _e{constructor(e){this.dispatch=new ie,this.moveOnAll=!1,this.enableGlobalMoveEvents=!0,this.mappingState={trackingData:{}},this.eventPool=new Map,this._allInteractiveElements=[],this._hitElements=[],this._isPointerMoveEvent=!1,this.rootTarget=e,this.hitPruneFn=this.hitPruneFn.bind(this),this.hitTestFn=this.hitTestFn.bind(this),this.mapPointerDown=this.mapPointerDown.bind(this),this.mapPointerMove=this.mapPointerMove.bind(this),this.mapPointerOut=this.mapPointerOut.bind(this),this.mapPointerOver=this.mapPointerOver.bind(this),this.mapPointerUp=this.mapPointerUp.bind(this),this.mapPointerUpOutside=this.mapPointerUpOutside.bind(this),this.mapWheel=this.mapWheel.bind(this),this.mappingTable={},this.addEventMapping("pointerdown",this.mapPointerDown),this.addEventMapping("pointermove",this.mapPointerMove),this.addEventMapping("pointerout",this.mapPointerOut),this.addEventMapping("pointerleave",this.mapPointerOut),this.addEventMapping("pointerover",this.mapPointerOver),this.addEventMapping("pointerup",this.mapPointerUp),this.addEventMapping("pointerupoutside",this.mapPointerUpOutside),this.addEventMapping("wheel",this.mapWheel)}addEventMapping(e,t){this.mappingTable[e]||(this.mappingTable[e]=[]),this.mappingTable[e].push({fn:t,priority:0}),this.mappingTable[e].sort((i,n)=>i.priority-n.priority)}dispatchEvent(e,t){e.propagationStopped=!1,e.propagationImmediatelyStopped=!1,this.propagate(e,t),this.dispatch.emit(t||e.type,e)}mapEvent(e){if(!this.rootTarget)return;const t=this.mappingTable[e.type];if(t)for(let i=0,n=t.length;i<n;i++)t[i].fn(e);else y(`[EventBoundary]: Event mapping not defined for ${e.type}`)}hitTest(e,t){_.pauseUpdate=!0;const n=this._isPointerMoveEvent&&this.enableGlobalMoveEvents?"hitTestMoveRecursive":"hitTestRecursive",s=this[n](this.rootTarget,this.rootTarget.eventMode,me.set(e,t),this.hitTestFn,this.hitPruneFn);return s&&s[0]}propagate(e,t){if(!e.target)return;const i=e.composedPath();e.eventPhase=e.CAPTURING_PHASE;for(let n=0,s=i.length-1;n<s;n++)if(e.currentTarget=i[n],this.notifyTarget(e,t),e.propagationStopped||e.propagationImmediatelyStopped)return;if(e.eventPhase=e.AT_TARGET,e.currentTarget=e.target,this.notifyTarget(e,t),!(e.propagationStopped||e.propagationImmediatelyStopped)){e.eventPhase=e.BUBBLING_PHASE;for(let n=i.length-2;n>=0;n--)if(e.currentTarget=i[n],this.notifyTarget(e,t),e.propagationStopped||e.propagationImmediatelyStopped)return}}all(e,t,i=this._allInteractiveElements){if(i.length===0)return;e.eventPhase=e.BUBBLING_PHASE;const n=Array.isArray(t)?t:[t];for(let s=i.length-1;s>=0;s--)n.forEach(o=>{e.currentTarget=i[s],this.notifyTarget(e,o)})}propagationPath(e){const t=[e];for(let i=0;i<fe&&e!==this.rootTarget&&e.parent;i++){if(!e.parent)throw new Error("Cannot find propagation path to disconnected target");t.push(e.parent),e=e.parent}return t.reverse(),t}hitTestMoveRecursive(e,t,i,n,s,o=!1){let r=!1;if(this._interactivePrune(e))return null;if((e.eventMode==="dynamic"||t==="dynamic")&&(_.pauseUpdate=!1),e.interactiveChildren&&e.children){const p=e.children;for(let u=p.length-1;u>=0;u--){const h=p[u],v=this.hitTestMoveRecursive(h,this._isInteractive(t)?t:h.eventMode,i,n,s,o||s(e,i));if(v){if(v.length>0&&!v[v.length-1].parent)continue;const c=e.isInteractive();(v.length>0||c)&&(c&&this._allInteractiveElements.push(e),v.push(e)),this._hitElements.length===0&&(this._hitElements=v),r=!0}}}const l=this._isInteractive(t),d=e.isInteractive();return d&&d&&this._allInteractiveElements.push(e),o||this._hitElements.length>0?null:r?this._hitElements:l&&!s(e,i)&&n(e,i)?d?[e]:[]:null}hitTestRecursive(e,t,i,n,s){if(this._interactivePrune(e)||s(e,i))return null;if((e.eventMode==="dynamic"||t==="dynamic")&&(_.pauseUpdate=!1),e.interactiveChildren&&e.children){const l=e.children,d=i;for(let p=l.length-1;p>=0;p--){const u=l[p],h=this.hitTestRecursive(u,this._isInteractive(t)?t:u.eventMode,d,n,s);if(h){if(h.length>0&&!h[h.length-1].parent)continue;const v=e.isInteractive();return(h.length>0||v)&&h.push(e),h}}}const o=this._isInteractive(t),r=e.isInteractive();return o&&n(e,i)?r?[e]:[]:null}_isInteractive(e){return e==="static"||e==="dynamic"}_interactivePrune(e){return!e||!e.visible||!e.renderable||!e.measurable||e.eventMode==="none"||e.eventMode==="passive"&&!e.interactiveChildren}hitPruneFn(e,t){if(e.hitArea&&(e.worldTransform.applyInverse(t,P),!e.hitArea.contains(P.x,P.y)))return!0;if(e.effects&&e.effects.length)for(let i=0;i<e.effects.length;i++){const n=e.effects[i];if(n.containsPoint&&!n.containsPoint(t,this.hitTestFn))return!0}return!1}hitTestFn(e,t){return e.hitArea?!0:e!=null&&e.containsPoint?(e.worldTransform.applyInverse(t,P),e.containsPoint(P)):!1}notifyTarget(e,t){var s,o;if(!e.currentTarget.isInteractive())return;t??(t=e.type);const i=`on${t}`;(o=(s=e.currentTarget)[i])==null||o.call(s,e);const n=e.eventPhase===e.CAPTURING_PHASE||e.eventPhase===e.AT_TARGET?`${t}capture`:t;this._notifyListeners(e,n),e.eventPhase===e.AT_TARGET&&this._notifyListeners(e,t)}mapPointerDown(e){if(!(e instanceof f)){y("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=this.createPointerEvent(e);if(this.dispatchEvent(t,"pointerdown"),t.pointerType==="touch")this.dispatchEvent(t,"touchstart");else if(t.pointerType==="mouse"||t.pointerType==="pen"){const n=t.button===2;this.dispatchEvent(t,n?"rightdown":"mousedown")}const i=this.trackingData(e.pointerId);i.pressTargetsByButton[e.button]=t.composedPath(),this.freeEvent(t)}mapPointerMove(e){var l,d;if(!(e instanceof f)){y("EventBoundary cannot map a non-pointer event as a pointer event");return}this._allInteractiveElements.length=0,this._hitElements.length=0,this._isPointerMoveEvent=!0;const t=this.createPointerEvent(e);this._isPointerMoveEvent=!1;const i=t.pointerType==="mouse"||t.pointerType==="pen",n=this.trackingData(e.pointerId),s=this.findMountedTarget(n.overTargets);if(((l=n.overTargets)==null?void 0:l.length)>0&&s!==t.target){const p=e.type==="mousemove"?"mouseout":"pointerout",u=this.createPointerEvent(e,p,s);if(this.dispatchEvent(u,"pointerout"),i&&this.dispatchEvent(u,"mouseout"),!t.composedPath().includes(s)){const h=this.createPointerEvent(e,"pointerleave",s);for(h.eventPhase=h.AT_TARGET;h.target&&!t.composedPath().includes(h.target);)h.currentTarget=h.target,this.notifyTarget(h),i&&this.notifyTarget(h,"mouseleave"),h.target=h.target.parent;this.freeEvent(h)}this.freeEvent(u)}if(s!==t.target){const p=e.type==="mousemove"?"mouseover":"pointerover",u=this.clonePointerEvent(t,p);this.dispatchEvent(u,"pointerover"),i&&this.dispatchEvent(u,"mouseover");let h=s==null?void 0:s.parent;for(;h&&h!==this.rootTarget.parent&&h!==t.target;)h=h.parent;if(!h||h===this.rootTarget.parent){const c=this.clonePointerEvent(t,"pointerenter");for(c.eventPhase=c.AT_TARGET;c.target&&c.target!==s&&c.target!==this.rootTarget.parent;)c.currentTarget=c.target,this.notifyTarget(c),i&&this.notifyTarget(c,"mouseenter"),c.target=c.target.parent;this.freeEvent(c)}this.freeEvent(u)}const o=[],r=this.enableGlobalMoveEvents??!0;this.moveOnAll?o.push("pointermove"):this.dispatchEvent(t,"pointermove"),r&&o.push("globalpointermove"),t.pointerType==="touch"&&(this.moveOnAll?o.splice(1,0,"touchmove"):this.dispatchEvent(t,"touchmove"),r&&o.push("globaltouchmove")),i&&(this.moveOnAll?o.splice(1,0,"mousemove"):this.dispatchEvent(t,"mousemove"),r&&o.push("globalmousemove"),this.cursor=(d=t.target)==null?void 0:d.cursor),o.length>0&&this.all(t,o),this._allInteractiveElements.length=0,this._hitElements.length=0,n.overTargets=t.composedPath(),this.freeEvent(t)}mapPointerOver(e){var o;if(!(e instanceof f)){y("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=this.trackingData(e.pointerId),i=this.createPointerEvent(e),n=i.pointerType==="mouse"||i.pointerType==="pen";this.dispatchEvent(i,"pointerover"),n&&this.dispatchEvent(i,"mouseover"),i.pointerType==="mouse"&&(this.cursor=(o=i.target)==null?void 0:o.cursor);const s=this.clonePointerEvent(i,"pointerenter");for(s.eventPhase=s.AT_TARGET;s.target&&s.target!==this.rootTarget.parent;)s.currentTarget=s.target,this.notifyTarget(s),n&&this.notifyTarget(s,"mouseenter"),s.target=s.target.parent;t.overTargets=i.composedPath(),this.freeEvent(i),this.freeEvent(s)}mapPointerOut(e){if(!(e instanceof f)){y("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=this.trackingData(e.pointerId);if(t.overTargets){const i=e.pointerType==="mouse"||e.pointerType==="pen",n=this.findMountedTarget(t.overTargets),s=this.createPointerEvent(e,"pointerout",n);this.dispatchEvent(s),i&&this.dispatchEvent(s,"mouseout");const o=this.createPointerEvent(e,"pointerleave",n);for(o.eventPhase=o.AT_TARGET;o.target&&o.target!==this.rootTarget.parent;)o.currentTarget=o.target,this.notifyTarget(o),i&&this.notifyTarget(o,"mouseleave"),o.target=o.target.parent;t.overTargets=null,this.freeEvent(s),this.freeEvent(o)}this.cursor=null}mapPointerUp(e){if(!(e instanceof f)){y("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=performance.now(),i=this.createPointerEvent(e);if(this.dispatchEvent(i,"pointerup"),i.pointerType==="touch")this.dispatchEvent(i,"touchend");else if(i.pointerType==="mouse"||i.pointerType==="pen"){const r=i.button===2;this.dispatchEvent(i,r?"rightup":"mouseup")}const n=this.trackingData(e.pointerId),s=this.findMountedTarget(n.pressTargetsByButton[e.button]);let o=s;if(s&&!i.composedPath().includes(s)){let r=s;for(;r&&!i.composedPath().includes(r);){if(i.currentTarget=r,this.notifyTarget(i,"pointerupoutside"),i.pointerType==="touch")this.notifyTarget(i,"touchendoutside");else if(i.pointerType==="mouse"||i.pointerType==="pen"){const l=i.button===2;this.notifyTarget(i,l?"rightupoutside":"mouseupoutside")}r=r.parent}delete n.pressTargetsByButton[e.button],o=r}if(o){const r=this.clonePointerEvent(i,"click");r.target=o,r.path=null,n.clicksByButton[e.button]||(n.clicksByButton[e.button]={clickCount:0,target:r.target,timeStamp:t});const l=n.clicksByButton[e.button];if(l.target===r.target&&t-l.timeStamp<200?++l.clickCount:l.clickCount=1,l.target=r.target,l.timeStamp=t,r.detail=l.clickCount,r.pointerType==="mouse"){const d=r.button===2;this.dispatchEvent(r,d?"rightclick":"click")}else r.pointerType==="touch"&&this.dispatchEvent(r,"tap");this.dispatchEvent(r,"pointertap"),this.freeEvent(r)}this.freeEvent(i)}mapPointerUpOutside(e){if(!(e instanceof f)){y("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=this.trackingData(e.pointerId),i=this.findMountedTarget(t.pressTargetsByButton[e.button]),n=this.createPointerEvent(e);if(i){let s=i;for(;s;)n.currentTarget=s,this.notifyTarget(n,"pointerupoutside"),n.pointerType==="touch"?this.notifyTarget(n,"touchendoutside"):(n.pointerType==="mouse"||n.pointerType==="pen")&&this.notifyTarget(n,n.button===2?"rightupoutside":"mouseupoutside"),s=s.parent;delete t.pressTargetsByButton[e.button]}this.freeEvent(n)}mapWheel(e){if(!(e instanceof T)){y("EventBoundary cannot map a non-wheel event as a wheel event");return}const t=this.createWheelEvent(e);this.dispatchEvent(t),this.freeEvent(t)}findMountedTarget(e){if(!e)return null;let t=e[0];for(let i=1;i<e.length&&e[i].parent===t;i++)t=e[i];return t}createPointerEvent(e,t,i){const n=this.allocateEvent(f);return this.copyPointerData(e,n),this.copyMouseData(e,n),this.copyData(e,n),n.nativeEvent=e.nativeEvent,n.originalEvent=e,n.target=i??this.hitTest(n.global.x,n.global.y)??this._hitElements[0],typeof t=="string"&&(n.type=t),n}createWheelEvent(e){const t=this.allocateEvent(T);return this.copyWheelData(e,t),this.copyMouseData(e,t),this.copyData(e,t),t.nativeEvent=e.nativeEvent,t.originalEvent=e,t.target=this.hitTest(t.global.x,t.global.y),t}clonePointerEvent(e,t){const i=this.allocateEvent(f);return i.nativeEvent=e.nativeEvent,i.originalEvent=e.originalEvent,this.copyPointerData(e,i),this.copyMouseData(e,i),this.copyData(e,i),i.target=e.target,i.path=e.composedPath().slice(),i.type=t??i.type,i}copyWheelData(e,t){t.deltaMode=e.deltaMode,t.deltaX=e.deltaX,t.deltaY=e.deltaY,t.deltaZ=e.deltaZ}copyPointerData(e,t){e instanceof f&&t instanceof f&&(t.pointerId=e.pointerId,t.width=e.width,t.height=e.height,t.isPrimary=e.isPrimary,t.pointerType=e.pointerType,t.pressure=e.pressure,t.tangentialPressure=e.tangentialPressure,t.tiltX=e.tiltX,t.tiltY=e.tiltY,t.twist=e.twist)}copyMouseData(e,t){e instanceof D&&t instanceof D&&(t.altKey=e.altKey,t.button=e.button,t.buttons=e.buttons,t.client.copyFrom(e.client),t.ctrlKey=e.ctrlKey,t.metaKey=e.metaKey,t.movement.copyFrom(e.movement),t.screen.copyFrom(e.screen),t.shiftKey=e.shiftKey,t.global.copyFrom(e.global))}copyData(e,t){t.isTrusted=e.isTrusted,t.srcElement=e.srcElement,t.timeStamp=performance.now(),t.type=e.type,t.detail=e.detail,t.view=e.view,t.which=e.which,t.layer.copyFrom(e.layer),t.page.copyFrom(e.page)}trackingData(e){return this.mappingState.trackingData[e]||(this.mappingState.trackingData[e]={pressTargetsByButton:{},clicksByButton:{},overTarget:null}),this.mappingState.trackingData[e]}allocateEvent(e){this.eventPool.has(e)||this.eventPool.set(e,[]);const t=this.eventPool.get(e).pop()||new e(this);return t.eventPhase=t.NONE,t.currentTarget=null,t.defaultPrevented=!1,t.path=null,t.target=null,t}freeEvent(e){if(e.manager!==this)throw new Error("It is illegal to free an event not managed by this EventBoundary!");const t=e.constructor;this.eventPool.has(t)||this.eventPool.set(t,[]),this.eventPool.get(t).push(e)}_notifyListeners(e,t){const i=e.currentTarget._events[t];if(i)if("fn"in i)i.once&&e.currentTarget.removeListener(t,i.fn,void 0,!0),i.fn.call(i.context,e);else for(let n=0,s=i.length;n<s&&!e.propagationImmediatelyStopped;n++)i[n].once&&e.currentTarget.removeListener(t,i[n].fn,void 0,!0),i[n].fn.call(i[n].context,e)}}const ge=1,ye={touchstart:"pointerdown",touchend:"pointerup",touchendoutside:"pointerupoutside",touchmove:"pointermove",touchcancel:"pointercancel"},B=class x{constructor(e){this.supportsTouchEvents="ontouchstart"in globalThis,this.supportsPointerEvents=!!globalThis.PointerEvent,this.domElement=null,this.resolution=1,this.renderer=e,this.rootBoundary=new _e(null),_.init(this),this.autoPreventDefault=!0,this._eventsAdded=!1,this._rootPointerEvent=new f(null),this._rootWheelEvent=new T(null),this.cursorStyles={default:"inherit",pointer:"pointer"},this.features=new Proxy({...x.defaultEventFeatures},{set:(t,i,n)=>(i==="globalMove"&&(this.rootBoundary.enableGlobalMoveEvents=n),t[i]=n,!0)}),this._onPointerDown=this._onPointerDown.bind(this),this._onPointerMove=this._onPointerMove.bind(this),this._onPointerUp=this._onPointerUp.bind(this),this._onPointerOverOut=this._onPointerOverOut.bind(this),this.onWheel=this.onWheel.bind(this)}static get defaultEventMode(){return this._defaultEventMode}init(e){const{canvas:t,resolution:i}=this.renderer;this.setTargetElement(t),this.resolution=i,x._defaultEventMode=e.eventMode??"passive",Object.assign(this.features,e.eventFeatures??{}),this.rootBoundary.enableGlobalMoveEvents=this.features.globalMove}resolutionChange(e){this.resolution=e}destroy(){_.destroy(),this.setTargetElement(null),this.renderer=null,this._currentCursor=null}setCursor(e){e||(e="default");let t=!0;if(globalThis.OffscreenCanvas&&this.domElement instanceof OffscreenCanvas&&(t=!1),this._currentCursor===e)return;this._currentCursor=e;const i=this.cursorStyles[e];if(i)switch(typeof i){case"string":t&&(this.domElement.style.cursor=i);break;case"function":i(e);break;case"object":t&&Object.assign(this.domElement.style,i);break}else t&&typeof e=="string"&&!Object.prototype.hasOwnProperty.call(this.cursorStyles,e)&&(this.domElement.style.cursor=e)}get pointer(){return this._rootPointerEvent}_onPointerDown(e){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;const t=this._normalizeToPointerData(e);this.autoPreventDefault&&t[0].isNormalized&&(e.cancelable||!("cancelable"in e))&&e.preventDefault();for(let i=0,n=t.length;i<n;i++){const s=t[i],o=this._bootstrapEvent(this._rootPointerEvent,s);this.rootBoundary.mapEvent(o)}this.setCursor(this.rootBoundary.cursor)}_onPointerMove(e){if(!this.features.move)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered,_.pointerMoved();const t=this._normalizeToPointerData(e);for(let i=0,n=t.length;i<n;i++){const s=this._bootstrapEvent(this._rootPointerEvent,t[i]);this.rootBoundary.mapEvent(s)}this.setCursor(this.rootBoundary.cursor)}_onPointerUp(e){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;let t=e.target;e.composedPath&&e.composedPath().length>0&&(t=e.composedPath()[0]);const i=t!==this.domElement?"outside":"",n=this._normalizeToPointerData(e);for(let s=0,o=n.length;s<o;s++){const r=this._bootstrapEvent(this._rootPointerEvent,n[s]);r.type+=i,this.rootBoundary.mapEvent(r)}this.setCursor(this.rootBoundary.cursor)}_onPointerOverOut(e){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;const t=this._normalizeToPointerData(e);for(let i=0,n=t.length;i<n;i++){const s=this._bootstrapEvent(this._rootPointerEvent,t[i]);this.rootBoundary.mapEvent(s)}this.setCursor(this.rootBoundary.cursor)}onWheel(e){if(!this.features.wheel)return;const t=this.normalizeWheelEvent(e);this.rootBoundary.rootTarget=this.renderer.lastObjectRendered,this.rootBoundary.mapEvent(t)}setTargetElement(e){this._removeEvents(),this.domElement=e,_.domElement=e,this._addEvents()}_addEvents(){if(this._eventsAdded||!this.domElement)return;_.addTickerListener();const e=this.domElement.style;e&&(globalThis.navigator.msPointerEnabled?(e.msContentZooming="none",e.msTouchAction="none"):this.supportsPointerEvents&&(e.touchAction="none")),this.supportsPointerEvents?(globalThis.document.addEventListener("pointermove",this._onPointerMove,!0),this.domElement.addEventListener("pointerdown",this._onPointerDown,!0),this.domElement.addEventListener("pointerleave",this._onPointerOverOut,!0),this.domElement.addEventListener("pointerover",this._onPointerOverOut,!0),globalThis.addEventListener("pointerup",this._onPointerUp,!0)):(globalThis.document.addEventListener("mousemove",this._onPointerMove,!0),this.domElement.addEventListener("mousedown",this._onPointerDown,!0),this.domElement.addEventListener("mouseout",this._onPointerOverOut,!0),this.domElement.addEventListener("mouseover",this._onPointerOverOut,!0),globalThis.addEventListener("mouseup",this._onPointerUp,!0),this.supportsTouchEvents&&(this.domElement.addEventListener("touchstart",this._onPointerDown,!0),this.domElement.addEventListener("touchend",this._onPointerUp,!0),this.domElement.addEventListener("touchmove",this._onPointerMove,!0))),this.domElement.addEventListener("wheel",this.onWheel,{passive:!0,capture:!0}),this._eventsAdded=!0}_removeEvents(){if(!this._eventsAdded||!this.domElement)return;_.removeTickerListener();const e=this.domElement.style;e&&(globalThis.navigator.msPointerEnabled?(e.msContentZooming="",e.msTouchAction=""):this.supportsPointerEvents&&(e.touchAction="")),this.supportsPointerEvents?(globalThis.document.removeEventListener("pointermove",this._onPointerMove,!0),this.domElement.removeEventListener("pointerdown",this._onPointerDown,!0),this.domElement.removeEventListener("pointerleave",this._onPointerOverOut,!0),this.domElement.removeEventListener("pointerover",this._onPointerOverOut,!0),globalThis.removeEventListener("pointerup",this._onPointerUp,!0)):(globalThis.document.removeEventListener("mousemove",this._onPointerMove,!0),this.domElement.removeEventListener("mousedown",this._onPointerDown,!0),this.domElement.removeEventListener("mouseout",this._onPointerOverOut,!0),this.domElement.removeEventListener("mouseover",this._onPointerOverOut,!0),globalThis.removeEventListener("mouseup",this._onPointerUp,!0),this.supportsTouchEvents&&(this.domElement.removeEventListener("touchstart",this._onPointerDown,!0),this.domElement.removeEventListener("touchend",this._onPointerUp,!0),this.domElement.removeEventListener("touchmove",this._onPointerMove,!0))),this.domElement.removeEventListener("wheel",this.onWheel,!0),this.domElement=null,this._eventsAdded=!1}mapPositionToPoint(e,t,i){const n=this.domElement.isConnected?this.domElement.getBoundingClientRect():{width:this.domElement.width,height:this.domElement.height,left:0,top:0},s=1/this.resolution;e.x=(t-n.left)*(this.domElement.width/n.width)*s,e.y=(i-n.top)*(this.domElement.height/n.height)*s}_normalizeToPointerData(e){const t=[];if(this.supportsTouchEvents&&e instanceof TouchEvent)for(let i=0,n=e.changedTouches.length;i<n;i++){const s=e.changedTouches[i];typeof s.button>"u"&&(s.button=0),typeof s.buttons>"u"&&(s.buttons=1),typeof s.isPrimary>"u"&&(s.isPrimary=e.touches.length===1&&e.type==="touchstart"),typeof s.width>"u"&&(s.width=s.radiusX||1),typeof s.height>"u"&&(s.height=s.radiusY||1),typeof s.tiltX>"u"&&(s.tiltX=0),typeof s.tiltY>"u"&&(s.tiltY=0),typeof s.pointerType>"u"&&(s.pointerType="touch"),typeof s.pointerId>"u"&&(s.pointerId=s.identifier||0),typeof s.pressure>"u"&&(s.pressure=s.force||.5),typeof s.twist>"u"&&(s.twist=0),typeof s.tangentialPressure>"u"&&(s.tangentialPressure=0),typeof s.layerX>"u"&&(s.layerX=s.offsetX=s.clientX),typeof s.layerY>"u"&&(s.layerY=s.offsetY=s.clientY),s.isNormalized=!0,s.type=e.type,t.push(s)}else if(!globalThis.MouseEvent||e instanceof MouseEvent&&(!this.supportsPointerEvents||!(e instanceof globalThis.PointerEvent))){const i=e;typeof i.isPrimary>"u"&&(i.isPrimary=!0),typeof i.width>"u"&&(i.width=1),typeof i.height>"u"&&(i.height=1),typeof i.tiltX>"u"&&(i.tiltX=0),typeof i.tiltY>"u"&&(i.tiltY=0),typeof i.pointerType>"u"&&(i.pointerType="mouse"),typeof i.pointerId>"u"&&(i.pointerId=ge),typeof i.pressure>"u"&&(i.pressure=.5),typeof i.twist>"u"&&(i.twist=0),typeof i.tangentialPressure>"u"&&(i.tangentialPressure=0),i.isNormalized=!0,t.push(i)}else t.push(e);return t}normalizeWheelEvent(e){const t=this._rootWheelEvent;return this._transferMouseData(t,e),t.deltaX=e.deltaX,t.deltaY=e.deltaY,t.deltaZ=e.deltaZ,t.deltaMode=e.deltaMode,this.mapPositionToPoint(t.screen,e.clientX,e.clientY),t.global.copyFrom(t.screen),t.offset.copyFrom(t.screen),t.nativeEvent=e,t.type=e.type,t}_bootstrapEvent(e,t){return e.originalEvent=null,e.nativeEvent=t,e.pointerId=t.pointerId,e.width=t.width,e.height=t.height,e.isPrimary=t.isPrimary,e.pointerType=t.pointerType,e.pressure=t.pressure,e.tangentialPressure=t.tangentialPressure,e.tiltX=t.tiltX,e.tiltY=t.tiltY,e.twist=t.twist,this._transferMouseData(e,t),this.mapPositionToPoint(e.screen,t.clientX,t.clientY),e.global.copyFrom(e.screen),e.offset.copyFrom(e.screen),e.isTrusted=t.isTrusted,e.type==="pointerleave"&&(e.type="pointerout"),e.type.startsWith("mouse")&&(e.type=e.type.replace("mouse","pointer")),e.type.startsWith("touch")&&(e.type=ye[e.type]||e.type),e}_transferMouseData(e,t){e.isTrusted=t.isTrusted,e.srcElement=t.srcElement,e.timeStamp=performance.now(),e.type=t.type,e.altKey=t.altKey,e.button=t.button,e.buttons=t.buttons,e.client.x=t.clientX,e.client.y=t.clientY,e.ctrlKey=t.ctrlKey,e.metaKey=t.metaKey,e.movement.x=t.movementX,e.movement.y=t.movementY,e.page.x=t.pageX,e.page.y=t.pageY,e.relatedTarget=null,e.shiftKey=t.shiftKey}};B.extension={name:"events",type:[b.WebGLSystem,b.CanvasSystem,b.WebGPUSystem],priority:-1};B.defaultEventFeatures={move:!0,globalMove:!0,click:!0,wheel:!0};let ee=B;const be={onclick:null,onmousedown:null,onmouseenter:null,onmouseleave:null,onmousemove:null,onglobalmousemove:null,onmouseout:null,onmouseover:null,onmouseup:null,onmouseupoutside:null,onpointercancel:null,onpointerdown:null,onpointerenter:null,onpointerleave:null,onpointermove:null,onglobalpointermove:null,onpointerout:null,onpointerover:null,onpointertap:null,onpointerup:null,onpointerupoutside:null,onrightclick:null,onrightdown:null,onrightup:null,onrightupoutside:null,ontap:null,ontouchcancel:null,ontouchend:null,ontouchendoutside:null,ontouchmove:null,onglobaltouchmove:null,ontouchstart:null,onwheel:null,get interactive(){return this.eventMode==="dynamic"||this.eventMode==="static"},set interactive(a){this.eventMode=a?"static":"passive"},_internalEventMode:void 0,get eventMode(){return this._internalEventMode??ee.defaultEventMode},set eventMode(a){this._internalEventMode=a},isInteractive(){return this.eventMode==="static"||this.eventMode==="dynamic"},interactiveChildren:!0,hitArea:null,addEventListener(a,e,t){const i=typeof t=="boolean"&&t||typeof t=="object"&&t.capture,n=typeof t=="object"?t.signal:void 0,s=typeof t=="object"?t.once===!0:!1,o=typeof e=="function"?void 0:e;a=i?`${a}capture`:a;const r=typeof e=="function"?e:e.handleEvent,l=this;n&&n.addEventListener("abort",()=>{l.off(a,r,o)}),s?l.once(a,r,o):l.on(a,r,o)},removeEventListener(a,e,t){const i=typeof t=="boolean"&&t||typeof t=="object"&&t.capture,n=typeof e=="function"?void 0:e;a=i?`${a}capture`:a,e=typeof e=="function"?e:e.handleEvent,this.off(a,e,n)},dispatchEvent(a){if(!(a instanceof M))throw new Error("Container cannot propagate events outside of the Federated Events API");return a.defaultPrevented=!1,a.path=null,a.target=this,a.manager.dispatchEvent(a),!a.defaultPrevented}};w.add(ue);w.mixin(V,pe);w.add(ee);w.mixin(V,be);w.add(Q); diff --git a/dist/assets/colorToUniform-DmtBy-2V.js b/dist/assets/colorToUniform-DmtBy-2V.js new file mode 100644 index 0000000..2c8be17 --- /dev/null +++ b/dist/assets/colorToUniform-DmtBy-2V.js @@ -0,0 +1,31 @@ +const f={normal:0,add:1,multiply:2,screen:3,overlay:4,erase:5,"normal-npm":6,"add-npm":7,"screen-npm":8,min:9,max:10},n=0,i=1,r=2,a=3,l=4,d=5,h=class u{constructor(){this.data=0,this.blendMode="normal",this.polygonOffset=0,this.blend=!0,this.depthMask=!0}get blend(){return!!(this.data&1<<n)}set blend(t){!!(this.data&1<<n)!==t&&(this.data^=1<<n)}get offsets(){return!!(this.data&1<<i)}set offsets(t){!!(this.data&1<<i)!==t&&(this.data^=1<<i)}set cullMode(t){if(t==="none"){this.culling=!1;return}this.culling=!0,this.clockwiseFrontFace=t==="front"}get cullMode(){return this.culling?this.clockwiseFrontFace?"front":"back":"none"}get culling(){return!!(this.data&1<<r)}set culling(t){!!(this.data&1<<r)!==t&&(this.data^=1<<r)}get depthTest(){return!!(this.data&1<<a)}set depthTest(t){!!(this.data&1<<a)!==t&&(this.data^=1<<a)}get depthMask(){return!!(this.data&1<<d)}set depthMask(t){!!(this.data&1<<d)!==t&&(this.data^=1<<d)}get clockwiseFrontFace(){return!!(this.data&1<<l)}set clockwiseFrontFace(t){!!(this.data&1<<l)!==t&&(this.data^=1<<l)}get blendMode(){return this._blendMode}set blendMode(t){this.blend=t!=="none",this._blendMode=t,this._blendModeId=f[t]||0}get polygonOffset(){return this._polygonOffset}set polygonOffset(t){this.offsets=!!t,this._polygonOffset=t}toString(){return`[pixi.js/core:State blendMode=${this.blendMode} clockwiseFrontFace=${this.clockwiseFrontFace} culling=${this.culling} depthMask=${this.depthMask} polygonOffset=${this.polygonOffset}]`}static for2d(){const t=new u;return t.depthTest=!1,t.blend=!0,t}};h.default2d=h.for2d();let m=h;const c={name:"local-uniform-bit",vertex:{header:` + + struct LocalUniforms { + uTransformMatrix:mat3x3<f32>, + uColor:vec4<f32>, + uRound:f32, + } + + @group(1) @binding(0) var<uniform> localUniforms : LocalUniforms; + `,main:` + vColor *= localUniforms.uColor; + modelMatrix *= localUniforms.uTransformMatrix; + `,end:` + if(localUniforms.uRound == 1) + { + vPosition = vec4(roundPixels(vPosition.xy, globalUniforms.uResolution), vPosition.zw); + } + `}},g={...c,vertex:{...c.vertex,header:c.vertex.header.replace("group(1)","group(2)")}},p={name:"local-uniform-bit",vertex:{header:` + + uniform mat3 uTransformMatrix; + uniform vec4 uColor; + uniform float uRound; + `,main:` + vColor *= uColor; + modelMatrix = uTransformMatrix; + `,end:` + if(uRound == 1.) + { + gl_Position.xy = roundPixels(gl_Position.xy, uResolution); + } + `}};class b{constructor(){this.batcherName="default",this.topology="triangle-list",this.attributeSize=4,this.indexSize=6,this.packAsQuad=!0,this.roundPixels=0,this._attributeStart=0,this._batcher=null,this._batch=null}get blendMode(){return this.renderable.groupBlendMode}get color(){return this.renderable.groupColorAlpha}reset(){this.renderable=null,this.texture=null,this._batcher=null,this._batch=null,this.bounds=null}destroy(){}}function M(e,t,o){const s=(e>>24&255)/255;t[o++]=(e&255)/255*s,t[o++]=(e>>8&255)/255*s,t[o++]=(e>>16&255)/255*s,t[o++]=s}export{b as B,m as S,c as a,p as b,M as c,g as l}; diff --git a/dist/assets/index-DB6B0XuI.js b/dist/assets/index-DB6B0XuI.js new file mode 100644 index 0000000..09ed45c --- /dev/null +++ b/dist/assets/index-DB6B0XuI.js @@ -0,0 +1,451 @@ +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/browserAll-BytxDfn1.js","assets/webworkerAll-J8ccMaq4.js","assets/colorToUniform-DmtBy-2V.js","assets/WebGPURenderer-CtyVoQqf.js","assets/SharedSystems-DVK37F7d.js","assets/WebGLRenderer-BVO0qznQ.js"])))=>i.map(i=>d[i]); +(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))i(r);new MutationObserver(r=>{for(const n of r)if(n.type==="childList")for(const o of n.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&i(o)}).observe(document,{childList:!0,subtree:!0});function e(r){const n={};return r.integrity&&(n.integrity=r.integrity),r.referrerPolicy&&(n.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?n.credentials="include":r.crossOrigin==="anonymous"?n.credentials="omit":n.credentials="same-origin",n}function i(r){if(r.ep)return;r.ep=!0;const n=e(r);fetch(r.href,n)}})();class Wn{constructor(){this.listeners=new Map}on(t,e){this.listeners.has(t)||this.listeners.set(t,new Set);const i=this.listeners.get(t);return i.add(e),()=>{i.delete(e),i.size===0&&this.listeners.delete(t)}}emit(t,e){const i=this.listeners.get(t);if(i)for(const r of i)r(e)}}const _r="timeplot.app-state.v1";function Ns(s){return Object.fromEntries(Object.entries(s).map(([t,e])=>[t,{...e}]))}function Us(s){return Object.fromEntries(Object.entries(s).map(([t,e])=>[t,{...e}]))}function Yn(s){return{type:s.type,preset:s.preset,sampleRateHz:s.sampleRateHz,amplitude:s.amplitude,noise:s.noise,replayRate:s.replayRate,dataFileName:s.dataFileName,wsUrl:s.wsUrl,wsReconnectMs:s.wsReconnectMs}}function Xn(s){return{plot:{showGrid:s.plot.showGrid,showPoints:s.plot.showPoints,windowDurationMs:s.plot.windowDurationMs,maxPoints:s.plot.maxPoints},time:{speed:s.time.speed},panels:Ns(s.panels),graphs:Us(s.graphs),sources:Object.fromEntries(Object.entries(s.sources).map(([t,e])=>[t,Yn(e)]))}}function jn(s,t){return!t||typeof t!="object"?s:{...s,time:t.time?{...s.time,speed:t.time.speed??s.time.speed,paused:!1}:s.time,plot:t.plot?{...s.plot,...t.plot,valueRange:s.plot.valueRange,hoveredPoint:null,tooltip:{...s.plot.tooltip}}:s.plot,panels:t.panels?Ns(Object.fromEntries(Object.entries(s.panels).map(([i,r])=>[i,{...r,...t.panels[i]??{}}]))):s.panels,graphs:t.graphs?Us(Object.fromEntries(Object.entries(s.graphs).map(([i,r])=>[i,{...r,...t.graphs[i]??{}}]))):s.graphs,sources:t.sources?Object.fromEntries(Object.entries(s.sources).map(([i,r])=>{const n=t.sources[i]??{},o=n.type??r.type;return[i,{...r,...n,type:o,dataset:[],datasetPointCount:0,datasetDurationMs:0,loadError:o==="csv-replay"&&n.dataFileName?`Reload ${n.dataFileName} to restore replay data`:"",wsStatus:"idle",wsStatusDetail:""}]})):s.sources}}function qn(){if(typeof localStorage>"u")return null;try{const s=localStorage.getItem(_r);return s?JSON.parse(s):null}catch(s){return console.warn("[timeplot] failed to load persisted state",s),null}}function Zn(s){if(!(typeof localStorage>"u"))try{localStorage.setItem(_r,JSON.stringify(Xn(s)))}catch(t){console.warn("[timeplot] failed to persist state",t)}}function br(){return{app:{title:"TimePlot",renderer:"pending"},time:{realNowMs:Date.now(),realElapsedMs:0,plotTimeMs:0,speed:1,paused:!1},plot:{showGrid:!0,showPoints:!0,windowDurationMs:2e4,maxPoints:1600,valueRange:{min:-1.6,max:1.6},hoveredPoint:null,tooltip:{visible:!1,x:0,y:0,point:null}},sources:{signalA:{id:"signal-a",label:"Signal A",type:"synthetic-wave",preset:"telemetry",sampleRateHz:60,amplitude:1,noise:.08,replayRate:1,dataset:[],dataFileName:"",datasetPointCount:0,datasetDurationMs:0,loadError:"",wsUrl:"ws://localhost:8080",wsReconnectMs:2e3,wsStatus:"idle",wsStatusDetail:""},signalB:{id:"signal-b",label:"Signal B",type:"synthetic-wave",preset:"chirp",sampleRateHz:48,amplitude:.8,noise:.04,replayRate:1,dataset:[],dataFileName:"",datasetPointCount:0,datasetDurationMs:0,loadError:"",wsUrl:"ws://localhost:8080",wsReconnectMs:2e3,wsStatus:"idle",wsStatusDetail:""}},graphs:{primary:{sourceKey:"signalA",transform:"raw",title:"Primary signal"},secondary:{sourceKey:"signalB",transform:"delta",title:"Secondary signal"}},panels:{status:{title:"Status",visible:!0},source:{title:"Data Source",visible:!0},config:{title:"Config",visible:!0},help:{title:"Help",visible:!1}}}}class Kn{constructor(t=br()){this.state=jn(t,qn()),this.listeners=new Set}getState(){return this.state}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}setState(t){const e=typeof t=="function"?t(this.state):t;this.state=e,Zn(this.state);for(const i of this.listeners)i(this.state)}patch(t){this.setState(e=>({...e,...t,time:t.time?{...e.time,...t.time}:e.time,plot:t.plot?{...e.plot,...t.plot,valueRange:t.plot.valueRange?{...e.plot.valueRange,...t.plot.valueRange}:e.plot.valueRange,tooltip:t.plot.tooltip?{...e.plot.tooltip,...t.plot.tooltip}:e.plot.tooltip}:e.plot,sources:t.sources?Object.fromEntries(Object.entries({...e.sources,...t.sources}).map(([i,r])=>[i,{...e.sources[i],...r}])):e.sources,graphs:t.graphs?Us(Object.fromEntries(Object.entries({...e.graphs,...t.graphs}).map(([i,r])=>[i,{...e.graphs[i],...r}]))):e.graphs,panels:t.panels?Ns({...e.panels,...t.panels}):e.panels}))}}class Qn{constructor(t){this.store=t,this.lastFrameTime=performance.now()}tick(t=performance.now()){const e=t-this.lastFrameTime;return this.lastFrameTime=t,this.store.setState(i=>{const r=i.time.realElapsedMs+e,n=i.time.paused?0:e*i.time.speed;return{...i,time:{...i.time,realNowMs:Date.now(),realElapsedMs:r,plotTimeMs:Math.max(0,i.time.plotTimeMs+n)}}}),e}togglePause(){this.store.setState(t=>({...t,time:{...t.time,paused:!t.time.paused}}))}setPaused(t){this.store.setState(e=>({...e,time:{...e.time,paused:t}}))}setSpeed(t){const e=Math.max(.1,Math.min(12,t));this.store.setState(i=>({...i,time:{...i.time,speed:e}}))}reset(){this.store.setState(t=>({...t,time:{...t.time,realElapsedMs:0,plotTimeMs:0},plot:{...t.plot,hoveredPoint:null,tooltip:{...t.plot.tooltip,visible:!1,point:null}}})),this.lastFrameTime=performance.now()}}class ni{constructor(t=1600){this.maxPoints=t,this.points=[]}addPoint(t){this.points.push(t),this.points.length>this.maxPoints&&this.points.splice(0,this.points.length-this.maxPoints)}clear(){this.points=[]}getVisiblePoints(t,e){const i=t-e;return this.points.filter(r=>r.timeMs>=i&&r.timeMs<=t)}}const Jn="modulepreload",to=function(s){return"/"+s},oi={},Ne=function(t,e,i){let r=Promise.resolve();if(e&&e.length>0){document.getElementsByTagName("link");const o=document.querySelector("meta[property=csp-nonce]"),a=(o==null?void 0:o.nonce)||(o==null?void 0:o.getAttribute("nonce"));r=Promise.allSettled(e.map(h=>{if(h=to(h),h in oi)return;oi[h]=!0;const l=h.endsWith(".css"),c=l?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${h}"]${c}`))return;const u=document.createElement("link");if(u.rel=l?"stylesheet":Jn,l||(u.as="script"),u.crossOrigin="",u.href=h,a&&u.setAttribute("nonce",a),document.head.appendChild(u),l)return new Promise((p,d)=>{u.addEventListener("load",p),u.addEventListener("error",()=>d(new Error(`Unable to preload CSS for ${h}`)))})}))}function n(o){const a=new Event("vite:preloadError",{cancelable:!0});if(a.payload=o,window.dispatchEvent(a),!a.defaultPrevented)throw o}return r.then(o=>{for(const a of o||[])a.status==="rejected"&&n(a.reason);return t().catch(n)})};var L=(s=>(s.Application="application",s.WebGLPipes="webgl-pipes",s.WebGLPipesAdaptor="webgl-pipes-adaptor",s.WebGLSystem="webgl-system",s.WebGPUPipes="webgpu-pipes",s.WebGPUPipesAdaptor="webgpu-pipes-adaptor",s.WebGPUSystem="webgpu-system",s.CanvasSystem="canvas-system",s.CanvasPipesAdaptor="canvas-pipes-adaptor",s.CanvasPipes="canvas-pipes",s.Asset="asset",s.LoadParser="load-parser",s.ResolveParser="resolve-parser",s.CacheParser="cache-parser",s.DetectionParser="detection-parser",s.MaskEffect="mask-effect",s.BlendMode="blend-mode",s.TextureSource="texture-source",s.Environment="environment",s.ShapeBuilder="shape-builder",s.Batcher="batcher",s))(L||{});const ys=s=>{if(typeof s=="function"||typeof s=="object"&&s.extension){if(!s.extension)throw new Error("Extension class must have an extension object");s={...typeof s.extension!="object"?{type:s.extension}:s.extension,ref:s}}if(typeof s=="object")s={...s};else throw new Error("Invalid extension type");return typeof s.type=="string"&&(s.type=[s.type]),s},ve=(s,t)=>ys(s).priority??t,rt={_addHandlers:{},_removeHandlers:{},_queue:{},remove(...s){return s.map(ys).forEach(t=>{t.type.forEach(e=>{var i,r;return(r=(i=this._removeHandlers)[e])==null?void 0:r.call(i,t)})}),this},add(...s){return s.map(ys).forEach(t=>{t.type.forEach(e=>{var n,o;const i=this._addHandlers,r=this._queue;i[e]?(o=i[e])==null||o.call(i,t):(r[e]=r[e]||[],(n=r[e])==null||n.push(t))})}),this},handle(s,t,e){var o;const i=this._addHandlers,r=this._removeHandlers;if(i[s]||r[s])throw new Error(`Extension type ${s} already has a handler`);i[s]=t,r[s]=e;const n=this._queue;return n[s]&&((o=n[s])==null||o.forEach(a=>t(a)),delete n[s]),this},handleByMap(s,t){return this.handle(s,e=>{e.name&&(t[e.name]=e.ref)},e=>{e.name&&delete t[e.name]})},handleByNamedList(s,t,e=-1){return this.handle(s,i=>{t.findIndex(n=>n.name===i.name)>=0||(t.push({name:i.name,value:i.ref}),t.sort((n,o)=>ve(o.value,e)-ve(n.value,e)))},i=>{const r=t.findIndex(n=>n.name===i.name);r!==-1&&t.splice(r,1)})},handleByList(s,t,e=-1){return this.handle(s,i=>{t.includes(i.ref)||(t.push(i.ref),t.sort((r,n)=>ve(n,e)-ve(r,e)))},i=>{const r=t.indexOf(i.ref);r!==-1&&t.splice(r,1)})},mixin(s,...t){for(const e of t)Object.defineProperties(s.prototype,Object.getOwnPropertyDescriptors(e))}},eo={extension:{type:L.Environment,name:"browser",priority:-1},test:()=>!0,load:async()=>{await Ne(()=>import("./browserAll-BytxDfn1.js"),__vite__mapDeps([0,1,2]))}},so={extension:{type:L.Environment,name:"webworker",priority:0},test:()=>typeof self<"u"&&self.WorkerGlobalScope!==void 0,load:async()=>{await Ne(()=>import("./webworkerAll-J8ccMaq4.js"),__vite__mapDeps([1,2]))}};class q{constructor(t,e,i){this._x=e||0,this._y=i||0,this._observer=t}clone(t){return new q(t??this._observer,this._x,this._y)}set(t=0,e=t){return(this._x!==t||this._y!==e)&&(this._x=t,this._y=e,this._observer._onUpdate(this)),this}copyFrom(t){return(this._x!==t.x||this._y!==t.y)&&(this._x=t.x,this._y=t.y,this._observer._onUpdate(this)),this}copyTo(t){return t.set(this._x,this._y),t}equals(t){return t.x===this._x&&t.y===this._y}toString(){return`[pixi.js/math:ObservablePoint x=${this._x} y=${this._y} scope=${this._observer}]`}get x(){return this._x}set x(t){this._x!==t&&(this._x=t,this._observer._onUpdate(this))}get y(){return this._y}set y(t){this._y!==t&&(this._y=t,this._observer._onUpdate(this))}}function wr(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}var Sr={exports:{}};(function(s){var t=Object.prototype.hasOwnProperty,e="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(e=!1));function r(h,l,c){this.fn=h,this.context=l,this.once=c||!1}function n(h,l,c,u,p){if(typeof c!="function")throw new TypeError("The listener must be a function");var d=new r(c,u||h,p),m=e?e+l:l;return h._events[m]?h._events[m].fn?h._events[m]=[h._events[m],d]:h._events[m].push(d):(h._events[m]=d,h._eventsCount++),h}function o(h,l){--h._eventsCount===0?h._events=new i:delete h._events[l]}function a(){this._events=new i,this._eventsCount=0}a.prototype.eventNames=function(){var l=[],c,u;if(this._eventsCount===0)return l;for(u in c=this._events)t.call(c,u)&&l.push(e?u.slice(1):u);return Object.getOwnPropertySymbols?l.concat(Object.getOwnPropertySymbols(c)):l},a.prototype.listeners=function(l){var c=e?e+l:l,u=this._events[c];if(!u)return[];if(u.fn)return[u.fn];for(var p=0,d=u.length,m=new Array(d);p<d;p++)m[p]=u[p].fn;return m},a.prototype.listenerCount=function(l){var c=e?e+l:l,u=this._events[c];return u?u.fn?1:u.length:0},a.prototype.emit=function(l,c,u,p,d,m){var g=e?e+l:l;if(!this._events[g])return!1;var f=this._events[g],x=arguments.length,y,_;if(f.fn){switch(f.once&&this.removeListener(l,f.fn,void 0,!0),x){case 1:return f.fn.call(f.context),!0;case 2:return f.fn.call(f.context,c),!0;case 3:return f.fn.call(f.context,c,u),!0;case 4:return f.fn.call(f.context,c,u,p),!0;case 5:return f.fn.call(f.context,c,u,p,d),!0;case 6:return f.fn.call(f.context,c,u,p,d,m),!0}for(_=1,y=new Array(x-1);_<x;_++)y[_-1]=arguments[_];f.fn.apply(f.context,y)}else{var b=f.length,v;for(_=0;_<b;_++)switch(f[_].once&&this.removeListener(l,f[_].fn,void 0,!0),x){case 1:f[_].fn.call(f[_].context);break;case 2:f[_].fn.call(f[_].context,c);break;case 3:f[_].fn.call(f[_].context,c,u);break;case 4:f[_].fn.call(f[_].context,c,u,p);break;default:if(!y)for(v=1,y=new Array(x-1);v<x;v++)y[v-1]=arguments[v];f[_].fn.apply(f[_].context,y)}}return!0},a.prototype.on=function(l,c,u){return n(this,l,c,u,!1)},a.prototype.once=function(l,c,u){return n(this,l,c,u,!0)},a.prototype.removeListener=function(l,c,u,p){var d=e?e+l:l;if(!this._events[d])return this;if(!c)return o(this,d),this;var m=this._events[d];if(m.fn)m.fn===c&&(!p||m.once)&&(!u||m.context===u)&&o(this,d);else{for(var g=0,f=[],x=m.length;g<x;g++)(m[g].fn!==c||p&&!m[g].once||u&&m[g].context!==u)&&f.push(m[g]);f.length?this._events[d]=f.length===1?f[0]:f:o(this,d)}return this},a.prototype.removeAllListeners=function(l){var c;return l?(c=e?e+l:l,this._events[c]&&o(this,c)):(this._events=new i,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=e,a.EventEmitter=a,s.exports=a})(Sr);var io=Sr.exports;const pt=wr(io),ro=Math.PI*2,no=180/Math.PI,oo=Math.PI/180;class Z{constructor(t=0,e=0){this.x=0,this.y=0,this.x=t,this.y=e}clone(){return new Z(this.x,this.y)}copyFrom(t){return this.set(t.x,t.y),this}copyTo(t){return t.set(this.x,this.y),t}equals(t){return t.x===this.x&&t.y===this.y}set(t=0,e=t){return this.x=t,this.y=e,this}toString(){return`[pixi.js/math:Point x=${this.x} y=${this.y}]`}static get shared(){return Ze.x=0,Ze.y=0,Ze}}const Ze=new Z;class I{constructor(t=1,e=0,i=0,r=1,n=0,o=0){this.array=null,this.a=t,this.b=e,this.c=i,this.d=r,this.tx=n,this.ty=o}fromArray(t){this.a=t[0],this.b=t[1],this.c=t[3],this.d=t[4],this.tx=t[2],this.ty=t[5]}set(t,e,i,r,n,o){return this.a=t,this.b=e,this.c=i,this.d=r,this.tx=n,this.ty=o,this}toArray(t,e){this.array||(this.array=new Float32Array(9));const i=e||this.array;return t?(i[0]=this.a,i[1]=this.b,i[2]=0,i[3]=this.c,i[4]=this.d,i[5]=0,i[6]=this.tx,i[7]=this.ty,i[8]=1):(i[0]=this.a,i[1]=this.c,i[2]=this.tx,i[3]=this.b,i[4]=this.d,i[5]=this.ty,i[6]=0,i[7]=0,i[8]=1),i}apply(t,e){e=e||new Z;const i=t.x,r=t.y;return e.x=this.a*i+this.c*r+this.tx,e.y=this.b*i+this.d*r+this.ty,e}applyInverse(t,e){e=e||new Z;const i=this.a,r=this.b,n=this.c,o=this.d,a=this.tx,h=this.ty,l=1/(i*o+n*-r),c=t.x,u=t.y;return e.x=o*l*c+-n*l*u+(h*n-a*o)*l,e.y=i*l*u+-r*l*c+(-h*i+a*r)*l,e}translate(t,e){return this.tx+=t,this.ty+=e,this}scale(t,e){return this.a*=t,this.d*=e,this.c*=t,this.b*=e,this.tx*=t,this.ty*=e,this}rotate(t){const e=Math.cos(t),i=Math.sin(t),r=this.a,n=this.c,o=this.tx;return this.a=r*e-this.b*i,this.b=r*i+this.b*e,this.c=n*e-this.d*i,this.d=n*i+this.d*e,this.tx=o*e-this.ty*i,this.ty=o*i+this.ty*e,this}append(t){const e=this.a,i=this.b,r=this.c,n=this.d;return this.a=t.a*e+t.b*r,this.b=t.a*i+t.b*n,this.c=t.c*e+t.d*r,this.d=t.c*i+t.d*n,this.tx=t.tx*e+t.ty*r+this.tx,this.ty=t.tx*i+t.ty*n+this.ty,this}appendFrom(t,e){const i=t.a,r=t.b,n=t.c,o=t.d,a=t.tx,h=t.ty,l=e.a,c=e.b,u=e.c,p=e.d;return this.a=i*l+r*u,this.b=i*c+r*p,this.c=n*l+o*u,this.d=n*c+o*p,this.tx=a*l+h*u+e.tx,this.ty=a*c+h*p+e.ty,this}setTransform(t,e,i,r,n,o,a,h,l){return this.a=Math.cos(a+l)*n,this.b=Math.sin(a+l)*n,this.c=-Math.sin(a-h)*o,this.d=Math.cos(a-h)*o,this.tx=t-(i*this.a+r*this.c),this.ty=e-(i*this.b+r*this.d),this}prepend(t){const e=this.tx;if(t.a!==1||t.b!==0||t.c!==0||t.d!==1){const i=this.a,r=this.c;this.a=i*t.a+this.b*t.c,this.b=i*t.b+this.b*t.d,this.c=r*t.a+this.d*t.c,this.d=r*t.b+this.d*t.d}return this.tx=e*t.a+this.ty*t.c+t.tx,this.ty=e*t.b+this.ty*t.d+t.ty,this}decompose(t){const e=this.a,i=this.b,r=this.c,n=this.d,o=t.pivot,a=-Math.atan2(-r,n),h=Math.atan2(i,e),l=Math.abs(a+h);return l<1e-5||Math.abs(ro-l)<1e-5?(t.rotation=h,t.skew.x=t.skew.y=0):(t.rotation=0,t.skew.x=a,t.skew.y=h),t.scale.x=Math.sqrt(e*e+i*i),t.scale.y=Math.sqrt(r*r+n*n),t.position.x=this.tx+(o.x*e+o.y*r),t.position.y=this.ty+(o.x*i+o.y*n),t}invert(){const t=this.a,e=this.b,i=this.c,r=this.d,n=this.tx,o=t*r-e*i;return this.a=r/o,this.b=-e/o,this.c=-i/o,this.d=t/o,this.tx=(i*this.ty-r*n)/o,this.ty=-(t*this.ty-e*n)/o,this}isIdentity(){return this.a===1&&this.b===0&&this.c===0&&this.d===1&&this.tx===0&&this.ty===0}identity(){return this.a=1,this.b=0,this.c=0,this.d=1,this.tx=0,this.ty=0,this}clone(){const t=new I;return t.a=this.a,t.b=this.b,t.c=this.c,t.d=this.d,t.tx=this.tx,t.ty=this.ty,t}copyTo(t){return t.a=this.a,t.b=this.b,t.c=this.c,t.d=this.d,t.tx=this.tx,t.ty=this.ty,t}copyFrom(t){return this.a=t.a,this.b=t.b,this.c=t.c,this.d=t.d,this.tx=t.tx,this.ty=t.ty,this}equals(t){return t.a===this.a&&t.b===this.b&&t.c===this.c&&t.d===this.d&&t.tx===this.tx&&t.ty===this.ty}toString(){return`[pixi.js:Matrix a=${this.a} b=${this.b} c=${this.c} d=${this.d} tx=${this.tx} ty=${this.ty}]`}static get IDENTITY(){return ho.identity()}static get shared(){return ao.identity()}}const ao=new I,ho=new I,kt=[1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1],Et=[0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1],Rt=[0,-1,-1,-1,0,1,1,1,0,1,1,1,0,-1,-1,-1],It=[1,1,0,-1,-1,-1,0,1,-1,-1,0,1,1,1,0,-1],_s=[],vr=[],Pe=Math.sign;function lo(){for(let s=0;s<16;s++){const t=[];_s.push(t);for(let e=0;e<16;e++){const i=Pe(kt[s]*kt[e]+Rt[s]*Et[e]),r=Pe(Et[s]*kt[e]+It[s]*Et[e]),n=Pe(kt[s]*Rt[e]+Rt[s]*It[e]),o=Pe(Et[s]*Rt[e]+It[s]*It[e]);for(let a=0;a<16;a++)if(kt[a]===i&&Et[a]===r&&Rt[a]===n&&It[a]===o){t.push(a);break}}}for(let s=0;s<16;s++){const t=new I;t.set(kt[s],Et[s],Rt[s],It[s],0,0),vr.push(t)}}lo();const z={E:0,SE:1,S:2,SW:3,W:4,NW:5,N:6,NE:7,MIRROR_VERTICAL:8,MAIN_DIAGONAL:10,MIRROR_HORIZONTAL:12,REVERSE_DIAGONAL:14,uX:s=>kt[s],uY:s=>Et[s],vX:s=>Rt[s],vY:s=>It[s],inv:s=>s&8?s&15:-s&7,add:(s,t)=>_s[s][t],sub:(s,t)=>_s[s][z.inv(t)],rotate180:s=>s^4,isVertical:s=>(s&3)===2,byDirection:(s,t)=>Math.abs(s)*2<=Math.abs(t)?t>=0?z.S:z.N:Math.abs(t)*2<=Math.abs(s)?s>0?z.E:z.W:t>0?s>0?z.SE:z.SW:s>0?z.NE:z.NW,matrixAppendRotationInv:(s,t,e=0,i=0)=>{const r=vr[z.inv(t)];r.tx=e,r.ty=i,s.append(r)},transformRectCoords:(s,t,e,i)=>{const{x:r,y:n,width:o,height:a}=s,{x:h,y:l,width:c,height:u}=t;return e===z.E?(i.set(r+h,n+l,o,a),i):e===z.S?i.set(c-n-a+h,r+l,a,o):e===z.W?i.set(c-r-o+h,u-n-a+l,o,a):e===z.N?i.set(n+h,u-r-o+l,a,o):i.set(r+h,n+l,o,a)}},Me=[new Z,new Z,new Z,new Z];class W{constructor(t=0,e=0,i=0,r=0){this.type="rectangle",this.x=Number(t),this.y=Number(e),this.width=Number(i),this.height=Number(r)}get left(){return this.x}get right(){return this.x+this.width}get top(){return this.y}get bottom(){return this.y+this.height}isEmpty(){return this.left===this.right||this.top===this.bottom}static get EMPTY(){return new W(0,0,0,0)}clone(){return new W(this.x,this.y,this.width,this.height)}copyFromBounds(t){return this.x=t.minX,this.y=t.minY,this.width=t.maxX-t.minX,this.height=t.maxY-t.minY,this}copyFrom(t){return this.x=t.x,this.y=t.y,this.width=t.width,this.height=t.height,this}copyTo(t){return t.copyFrom(this),t}contains(t,e){return this.width<=0||this.height<=0?!1:t>=this.x&&t<this.x+this.width&&e>=this.y&&e<this.y+this.height}strokeContains(t,e,i,r=.5){const{width:n,height:o}=this;if(n<=0||o<=0)return!1;const a=this.x,h=this.y,l=i*(1-r),c=i-l,u=a-l,p=a+n+l,d=h-l,m=h+o+l,g=a+c,f=a+n-c,x=h+c,y=h+o-c;return t>=u&&t<=p&&e>=d&&e<=m&&!(t>g&&t<f&&e>x&&e<y)}intersects(t,e){if(!e){const R=this.x<t.x?t.x:this.x;if((this.right>t.right?t.right:this.right)<=R)return!1;const P=this.y<t.y?t.y:this.y;return(this.bottom>t.bottom?t.bottom:this.bottom)>P}const i=this.left,r=this.right,n=this.top,o=this.bottom;if(r<=i||o<=n)return!1;const a=Me[0].set(t.left,t.top),h=Me[1].set(t.left,t.bottom),l=Me[2].set(t.right,t.top),c=Me[3].set(t.right,t.bottom);if(l.x<=a.x||h.y<=a.y)return!1;const u=Math.sign(e.a*e.d-e.b*e.c);if(u===0||(e.apply(a,a),e.apply(h,h),e.apply(l,l),e.apply(c,c),Math.max(a.x,h.x,l.x,c.x)<=i||Math.min(a.x,h.x,l.x,c.x)>=r||Math.max(a.y,h.y,l.y,c.y)<=n||Math.min(a.y,h.y,l.y,c.y)>=o))return!1;const p=u*(h.y-a.y),d=u*(a.x-h.x),m=p*i+d*n,g=p*r+d*n,f=p*i+d*o,x=p*r+d*o;if(Math.max(m,g,f,x)<=p*a.x+d*a.y||Math.min(m,g,f,x)>=p*c.x+d*c.y)return!1;const y=u*(a.y-l.y),_=u*(l.x-a.x),b=y*i+_*n,v=y*r+_*n,S=y*i+_*o,w=y*r+_*o;return!(Math.max(b,v,S,w)<=y*a.x+_*a.y||Math.min(b,v,S,w)>=y*c.x+_*c.y)}pad(t=0,e=t){return this.x-=t,this.y-=e,this.width+=t*2,this.height+=e*2,this}fit(t){const e=Math.max(this.x,t.x),i=Math.min(this.x+this.width,t.x+t.width),r=Math.max(this.y,t.y),n=Math.min(this.y+this.height,t.y+t.height);return this.x=e,this.width=Math.max(i-e,0),this.y=r,this.height=Math.max(n-r,0),this}ceil(t=1,e=.001){const i=Math.ceil((this.x+this.width-e)*t)/t,r=Math.ceil((this.y+this.height-e)*t)/t;return this.x=Math.floor((this.x+e)*t)/t,this.y=Math.floor((this.y+e)*t)/t,this.width=i-this.x,this.height=r-this.y,this}scale(t,e=t){return this.x*=t,this.y*=e,this.width*=t,this.height*=e,this}enlarge(t){const e=Math.min(this.x,t.x),i=Math.max(this.x+this.width,t.x+t.width),r=Math.min(this.y,t.y),n=Math.max(this.y+this.height,t.y+t.height);return this.x=e,this.width=i-e,this.y=r,this.height=n-r,this}getBounds(t){return t||(t=new W),t.copyFrom(this),t}containsRect(t){if(this.width<=0||this.height<=0)return!1;const e=t.x,i=t.y,r=t.x+t.width,n=t.y+t.height;return e>=this.x&&e<this.x+this.width&&i>=this.y&&i<this.y+this.height&&r>=this.x&&r<this.x+this.width&&n>=this.y&&n<this.y+this.height}set(t,e,i,r){return this.x=t,this.y=e,this.width=i,this.height=r,this}toString(){return`[pixi.js/math:Rectangle x=${this.x} y=${this.y} width=${this.width} height=${this.height}]`}}const Ke={default:-1};function V(s="default"){return Ke[s]===void 0&&(Ke[s]=-1),++Ke[s]}const ai=new Set,O="8.0.0",co="8.3.4",$t={quiet:!1,noColor:!1},F=(s,t,e=3)=>{if($t.quiet||ai.has(t))return;let i=new Error().stack;const r=`${t} +Deprecated since v${s}`,n=typeof console.groupCollapsed=="function"&&!$t.noColor;typeof i>"u"?console.warn("PixiJS Deprecation Warning: ",r):(i=i.split(` +`).splice(e).join(` +`),n?(console.groupCollapsed("%cPixiJS Deprecation Warning: %c%s","color:#614108;background:#fffbe6","font-weight:normal;color:#614108;background:#fffbe6",r),console.warn(i),console.groupEnd()):(console.warn("PixiJS Deprecation Warning: ",r),console.warn(i))),ai.add(t)};Object.defineProperties(F,{quiet:{get:()=>$t.quiet,set:s=>{$t.quiet=s},enumerable:!0,configurable:!1},noColor:{get:()=>$t.noColor,set:s=>{$t.noColor=s},enumerable:!0,configurable:!1}});const Pr=()=>{};function Vt(s){return s+=s===0?1:0,--s,s|=s>>>1,s|=s>>>2,s|=s>>>4,s|=s>>>8,s|=s>>>16,s+1}function hi(s){return!(s&s-1)&&!!s}function Mr(s){const t={};for(const e in s)s[e]!==void 0&&(t[e]=s[e]);return t}const li=Object.create(null);function uo(s){const t=li[s];return t===void 0&&(li[s]=V("resource")),t}const Cr=class Tr extends pt{constructor(t={}){super(),this._resourceType="textureSampler",this._touched=0,this._maxAnisotropy=1,this.destroyed=!1,t={...Tr.defaultOptions,...t},this.addressMode=t.addressMode,this.addressModeU=t.addressModeU??this.addressModeU,this.addressModeV=t.addressModeV??this.addressModeV,this.addressModeW=t.addressModeW??this.addressModeW,this.scaleMode=t.scaleMode,this.magFilter=t.magFilter??this.magFilter,this.minFilter=t.minFilter??this.minFilter,this.mipmapFilter=t.mipmapFilter??this.mipmapFilter,this.lodMinClamp=t.lodMinClamp,this.lodMaxClamp=t.lodMaxClamp,this.compare=t.compare,this.maxAnisotropy=t.maxAnisotropy??1}set addressMode(t){this.addressModeU=t,this.addressModeV=t,this.addressModeW=t}get addressMode(){return this.addressModeU}set wrapMode(t){F(O,"TextureStyle.wrapMode is now TextureStyle.addressMode"),this.addressMode=t}get wrapMode(){return this.addressMode}set scaleMode(t){this.magFilter=t,this.minFilter=t,this.mipmapFilter=t}get scaleMode(){return this.magFilter}set maxAnisotropy(t){this._maxAnisotropy=Math.min(t,16),this._maxAnisotropy>1&&(this.scaleMode="linear")}get maxAnisotropy(){return this._maxAnisotropy}get _resourceId(){return this._sharedResourceId||this._generateResourceId()}update(){this.emit("change",this),this._sharedResourceId=null}_generateResourceId(){const t=`${this.addressModeU}-${this.addressModeV}-${this.addressModeW}-${this.magFilter}-${this.minFilter}-${this.mipmapFilter}-${this.lodMinClamp}-${this.lodMaxClamp}-${this.compare}-${this._maxAnisotropy}`;return this._sharedResourceId=uo(t),this._resourceId}destroy(){this.destroyed=!0,this.emit("destroy",this),this.emit("change",this),this.removeAllListeners()}};Cr.defaultOptions={addressMode:"clamp-to-edge",scaleMode:"linear"};let Ue=Cr;const Ar=class kr extends pt{constructor(t={}){super(),this.options=t,this.uid=V("textureSource"),this._resourceType="textureSource",this._resourceId=V("resource"),this.uploadMethodId="unknown",this._resolution=1,this.pixelWidth=1,this.pixelHeight=1,this.width=1,this.height=1,this.sampleCount=1,this.mipLevelCount=1,this.autoGenerateMipmaps=!1,this.format="rgba8unorm",this.dimension="2d",this.antialias=!1,this._touched=0,this._batchTick=-1,this._textureBindLocation=-1,t={...kr.defaultOptions,...t},this.label=t.label??"",this.resource=t.resource,this.autoGarbageCollect=t.autoGarbageCollect,this._resolution=t.resolution,t.width?this.pixelWidth=t.width*this._resolution:this.pixelWidth=this.resource?this.resourceWidth??1:1,t.height?this.pixelHeight=t.height*this._resolution:this.pixelHeight=this.resource?this.resourceHeight??1:1,this.width=this.pixelWidth/this._resolution,this.height=this.pixelHeight/this._resolution,this.format=t.format,this.dimension=t.dimensions,this.mipLevelCount=t.mipLevelCount,this.autoGenerateMipmaps=t.autoGenerateMipmaps,this.sampleCount=t.sampleCount,this.antialias=t.antialias,this.alphaMode=t.alphaMode,this.style=new Ue(Mr(t)),this.destroyed=!1,this._refreshPOT()}get source(){return this}get style(){return this._style}set style(t){var e,i;this.style!==t&&((e=this._style)==null||e.off("change",this._onStyleChange,this),this._style=t,(i=this._style)==null||i.on("change",this._onStyleChange,this),this._onStyleChange())}set maxAnisotropy(t){this._style.maxAnisotropy=t}get maxAnisotropy(){return this._style.maxAnisotropy}get addressMode(){return this._style.addressMode}set addressMode(t){this._style.addressMode=t}get repeatMode(){return this._style.addressMode}set repeatMode(t){this._style.addressMode=t}get magFilter(){return this._style.magFilter}set magFilter(t){this._style.magFilter=t}get minFilter(){return this._style.minFilter}set minFilter(t){this._style.minFilter=t}get mipmapFilter(){return this._style.mipmapFilter}set mipmapFilter(t){this._style.mipmapFilter=t}get lodMinClamp(){return this._style.lodMinClamp}set lodMinClamp(t){this._style.lodMinClamp=t}get lodMaxClamp(){return this._style.lodMaxClamp}set lodMaxClamp(t){this._style.lodMaxClamp=t}_onStyleChange(){this.emit("styleChange",this)}update(){if(this.resource){const t=this._resolution;if(this.resize(this.resourceWidth/t,this.resourceHeight/t))return}this.emit("update",this)}destroy(){this.destroyed=!0,this.emit("destroy",this),this.emit("change",this),this._style&&(this._style.destroy(),this._style=null),this.uploadMethodId=null,this.resource=null,this.removeAllListeners()}unload(){this._resourceId=V("resource"),this.emit("change",this),this.emit("unload",this)}get resourceWidth(){const{resource:t}=this;return t.naturalWidth||t.videoWidth||t.displayWidth||t.width}get resourceHeight(){const{resource:t}=this;return t.naturalHeight||t.videoHeight||t.displayHeight||t.height}get resolution(){return this._resolution}set resolution(t){this._resolution!==t&&(this._resolution=t,this.width=this.pixelWidth/t,this.height=this.pixelHeight/t)}resize(t,e,i){i||(i=this._resolution),t||(t=this.width),e||(e=this.height);const r=Math.round(t*i),n=Math.round(e*i);return this.width=r/i,this.height=n/i,this._resolution=i,this.pixelWidth===r&&this.pixelHeight===n?!1:(this._refreshPOT(),this.pixelWidth=r,this.pixelHeight=n,this.emit("resize",this),this._resourceId=V("resource"),this.emit("change",this),!0)}updateMipmaps(){this.autoGenerateMipmaps&&this.mipLevelCount>1&&this.emit("updateMipmaps",this)}set wrapMode(t){this._style.wrapMode=t}get wrapMode(){return this._style.wrapMode}set scaleMode(t){this._style.scaleMode=t}get scaleMode(){return this._style.scaleMode}_refreshPOT(){this.isPowerOfTwo=hi(this.pixelWidth)&&hi(this.pixelHeight)}static test(t){throw new Error("Unimplemented")}};Ar.defaultOptions={resolution:1,format:"bgra8unorm",alphaMode:"premultiply-alpha-on-upload",dimensions:"2d",mipLevelCount:1,autoGenerateMipmaps:!1,sampleCount:1,antialias:!1,autoGarbageCollect:!1};let ht=Ar;class $s extends ht{constructor(t){const e=t.resource||new Float32Array(t.width*t.height*4);let i=t.format;i||(e instanceof Float32Array?i="rgba32float":e instanceof Int32Array||e instanceof Uint32Array?i="rgba32uint":e instanceof Int16Array||e instanceof Uint16Array?i="rgba16uint":(e instanceof Int8Array,i="bgra8unorm")),super({...t,resource:e,format:i}),this.uploadMethodId="buffer"}static test(t){return t instanceof Int8Array||t instanceof Uint8Array||t instanceof Uint8ClampedArray||t instanceof Int16Array||t instanceof Uint16Array||t instanceof Int32Array||t instanceof Uint32Array||t instanceof Float32Array}}$s.extension=L.TextureSource;const ci=new I;class fo{constructor(t,e){this.mapCoord=new I,this.uClampFrame=new Float32Array(4),this.uClampOffset=new Float32Array(2),this._textureID=-1,this._updateID=0,this.clampOffset=0,typeof e>"u"?this.clampMargin=t.width<10?0:.5:this.clampMargin=e,this.isSimple=!1,this.texture=t}get texture(){return this._texture}set texture(t){var e;this.texture!==t&&((e=this._texture)==null||e.removeListener("update",this.update,this),this._texture=t,this._texture.addListener("update",this.update,this),this.update())}multiplyUvs(t,e){e===void 0&&(e=t);const i=this.mapCoord;for(let r=0;r<t.length;r+=2){const n=t[r],o=t[r+1];e[r]=n*i.a+o*i.c+i.tx,e[r+1]=n*i.b+o*i.d+i.ty}return e}update(){const t=this._texture;this._updateID++;const e=t.uvs;this.mapCoord.set(e.x1-e.x0,e.y1-e.y0,e.x3-e.x0,e.y3-e.y0,e.x0,e.y0);const i=t.orig,r=t.trim;r&&(ci.set(i.width/r.width,0,0,i.height/r.height,-r.x/r.width,-r.y/r.height),this.mapCoord.append(ci));const n=t.source,o=this.uClampFrame,a=this.clampMargin/n._resolution,h=this.clampOffset/n._resolution;return o[0]=(t.frame.x+a+h)/n.width,o[1]=(t.frame.y+a+h)/n.height,o[2]=(t.frame.x+t.frame.width-a+h)/n.width,o[3]=(t.frame.y+t.frame.height-a+h)/n.height,this.uClampOffset[0]=this.clampOffset/n.pixelWidth,this.uClampOffset[1]=this.clampOffset/n.pixelHeight,this.isSimple=t.frame.width===n.width&&t.frame.height===n.height&&t.rotate===0,!0}}class D extends pt{constructor({source:t,label:e,frame:i,orig:r,trim:n,defaultAnchor:o,defaultBorders:a,rotate:h,dynamic:l}={}){if(super(),this.uid=V("texture"),this.uvs={x0:0,y0:0,x1:0,y1:0,x2:0,y2:0,x3:0,y3:0},this.frame=new W,this.noFrame=!1,this.dynamic=!1,this.isTexture=!0,this.label=e,this.source=(t==null?void 0:t.source)??new ht,this.noFrame=!i,i)this.frame.copyFrom(i);else{const{width:c,height:u}=this._source;this.frame.width=c,this.frame.height=u}this.orig=r||this.frame,this.trim=n,this.rotate=h??0,this.defaultAnchor=o,this.defaultBorders=a,this.destroyed=!1,this.dynamic=l||!1,this.updateUvs()}set source(t){this._source&&this._source.off("resize",this.update,this),this._source=t,t.on("resize",this.update,this),this.emit("update",this)}get source(){return this._source}get textureMatrix(){return this._textureMatrix||(this._textureMatrix=new fo(this)),this._textureMatrix}get width(){return this.orig.width}get height(){return this.orig.height}updateUvs(){const{uvs:t,frame:e}=this,{width:i,height:r}=this._source,n=e.x/i,o=e.y/r,a=e.width/i,h=e.height/r;let l=this.rotate;if(l){const c=a/2,u=h/2,p=n+c,d=o+u;l=z.add(l,z.NW),t.x0=p+c*z.uX(l),t.y0=d+u*z.uY(l),l=z.add(l,2),t.x1=p+c*z.uX(l),t.y1=d+u*z.uY(l),l=z.add(l,2),t.x2=p+c*z.uX(l),t.y2=d+u*z.uY(l),l=z.add(l,2),t.x3=p+c*z.uX(l),t.y3=d+u*z.uY(l)}else t.x0=n,t.y0=o,t.x1=n+a,t.y1=o,t.x2=n+a,t.y2=o+h,t.x3=n,t.y3=o+h}destroy(t=!1){this._source&&t&&(this._source.destroy(),this._source=null),this._textureMatrix=null,this.destroyed=!0,this.emit("destroy",this),this.removeAllListeners()}update(){this.noFrame&&(this.frame.width=this._source.width,this.frame.height=this._source.height),this.updateUvs(),this.emit("update",this)}get baseTexture(){return F(O,"Texture.baseTexture is now Texture.source"),this._source}}D.EMPTY=new D({label:"EMPTY",source:new ht({label:"EMPTY"})});D.EMPTY.destroy=Pr;D.WHITE=new D({source:new $s({resource:new Uint8Array([255,255,255,255]),width:1,height:1,alphaMode:"premultiply-alpha-on-upload",label:"WHITE"}),label:"WHITE"});D.WHITE.destroy=Pr;function po(s,t,e){const{width:i,height:r}=e.orig,n=e.trim;if(n){const o=n.width,a=n.height;s.minX=n.x-t._x*i,s.maxX=s.minX+o,s.minY=n.y-t._y*r,s.maxY=s.minY+a}else s.minX=-t._x*i,s.maxX=s.minX+i,s.minY=-t._y*r,s.maxY=s.minY+r}const ui=new I;class at{constructor(t=1/0,e=1/0,i=-1/0,r=-1/0){this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,this.matrix=ui,this.minX=t,this.minY=e,this.maxX=i,this.maxY=r}isEmpty(){return this.minX>this.maxX||this.minY>this.maxY}get rectangle(){this._rectangle||(this._rectangle=new W);const t=this._rectangle;return this.minX>this.maxX||this.minY>this.maxY?(t.x=0,t.y=0,t.width=0,t.height=0):t.copyFromBounds(this),t}clear(){return this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,this.matrix=ui,this}set(t,e,i,r){this.minX=t,this.minY=e,this.maxX=i,this.maxY=r}addFrame(t,e,i,r,n){n||(n=this.matrix);const o=n.a,a=n.b,h=n.c,l=n.d,c=n.tx,u=n.ty;let p=this.minX,d=this.minY,m=this.maxX,g=this.maxY,f=o*t+h*e+c,x=a*t+l*e+u;f<p&&(p=f),x<d&&(d=x),f>m&&(m=f),x>g&&(g=x),f=o*i+h*e+c,x=a*i+l*e+u,f<p&&(p=f),x<d&&(d=x),f>m&&(m=f),x>g&&(g=x),f=o*t+h*r+c,x=a*t+l*r+u,f<p&&(p=f),x<d&&(d=x),f>m&&(m=f),x>g&&(g=x),f=o*i+h*r+c,x=a*i+l*r+u,f<p&&(p=f),x<d&&(d=x),f>m&&(m=f),x>g&&(g=x),this.minX=p,this.minY=d,this.maxX=m,this.maxY=g}addRect(t,e){this.addFrame(t.x,t.y,t.x+t.width,t.y+t.height,e)}addBounds(t,e){this.addFrame(t.minX,t.minY,t.maxX,t.maxY,e)}addBoundsMask(t){this.minX=this.minX>t.minX?this.minX:t.minX,this.minY=this.minY>t.minY?this.minY:t.minY,this.maxX=this.maxX<t.maxX?this.maxX:t.maxX,this.maxY=this.maxY<t.maxY?this.maxY:t.maxY}applyMatrix(t){const e=this.minX,i=this.minY,r=this.maxX,n=this.maxY,{a:o,b:a,c:h,d:l,tx:c,ty:u}=t;let p=o*e+h*i+c,d=a*e+l*i+u;this.minX=p,this.minY=d,this.maxX=p,this.maxY=d,p=o*r+h*i+c,d=a*r+l*i+u,this.minX=p<this.minX?p:this.minX,this.minY=d<this.minY?d:this.minY,this.maxX=p>this.maxX?p:this.maxX,this.maxY=d>this.maxY?d:this.maxY,p=o*e+h*n+c,d=a*e+l*n+u,this.minX=p<this.minX?p:this.minX,this.minY=d<this.minY?d:this.minY,this.maxX=p>this.maxX?p:this.maxX,this.maxY=d>this.maxY?d:this.maxY,p=o*r+h*n+c,d=a*r+l*n+u,this.minX=p<this.minX?p:this.minX,this.minY=d<this.minY?d:this.minY,this.maxX=p>this.maxX?p:this.maxX,this.maxY=d>this.maxY?d:this.maxY}fit(t){return this.minX<t.left&&(this.minX=t.left),this.maxX>t.right&&(this.maxX=t.right),this.minY<t.top&&(this.minY=t.top),this.maxY>t.bottom&&(this.maxY=t.bottom),this}fitBounds(t,e,i,r){return this.minX<t&&(this.minX=t),this.maxX>e&&(this.maxX=e),this.minY<i&&(this.minY=i),this.maxY>r&&(this.maxY=r),this}pad(t,e=t){return this.minX-=t,this.maxX+=t,this.minY-=e,this.maxY+=e,this}ceil(){return this.minX=Math.floor(this.minX),this.minY=Math.floor(this.minY),this.maxX=Math.ceil(this.maxX),this.maxY=Math.ceil(this.maxY),this}clone(){return new at(this.minX,this.minY,this.maxX,this.maxY)}scale(t,e=t){return this.minX*=t,this.minY*=e,this.maxX*=t,this.maxY*=e,this}get x(){return this.minX}set x(t){const e=this.maxX-this.minX;this.minX=t,this.maxX=t+e}get y(){return this.minY}set y(t){const e=this.maxY-this.minY;this.minY=t,this.maxY=t+e}get width(){return this.maxX-this.minX}set width(t){this.maxX=this.minX+t}get height(){return this.maxY-this.minY}set height(t){this.maxY=this.minY+t}get left(){return this.minX}get right(){return this.maxX}get top(){return this.minY}get bottom(){return this.maxY}get isPositive(){return this.maxX-this.minX>0&&this.maxY-this.minY>0}get isValid(){return this.minX+this.minY!==1/0}addVertexData(t,e,i,r){let n=this.minX,o=this.minY,a=this.maxX,h=this.maxY;r||(r=this.matrix);const l=r.a,c=r.b,u=r.c,p=r.d,d=r.tx,m=r.ty;for(let g=e;g<i;g+=2){const f=t[g],x=t[g+1],y=l*f+u*x+d,_=c*f+p*x+m;n=y<n?y:n,o=_<o?_:o,a=y>a?y:a,h=_>h?_:h}this.minX=n,this.minY=o,this.maxX=a,this.maxY=h}containsPoint(t,e){return this.minX<=t&&this.minY<=e&&this.maxX>=t&&this.maxY>=e}toString(){return`[pixi.js:Bounds minX=${this.minX} minY=${this.minY} maxX=${this.maxX} maxY=${this.maxY} width=${this.width} height=${this.height}]`}copyFrom(t){return this.minX=t.minX,this.minY=t.minY,this.maxX=t.maxX,this.maxY=t.maxY,this}}var mo={grad:.9,turn:360,rad:360/(2*Math.PI)},mt=function(s){return typeof s=="string"?s.length>0:typeof s=="number"},X=function(s,t,e){return t===void 0&&(t=0),e===void 0&&(e=Math.pow(10,t)),Math.round(e*s)/e+0},st=function(s,t,e){return t===void 0&&(t=0),e===void 0&&(e=1),s>e?e:s>t?s:t},Er=function(s){return(s=isFinite(s)?s%360:0)>0?s:s+360},di=function(s){return{r:st(s.r,0,255),g:st(s.g,0,255),b:st(s.b,0,255),a:st(s.a)}},Qe=function(s){return{r:X(s.r),g:X(s.g),b:X(s.b),a:X(s.a,3)}},go=/^#([0-9a-f]{3,8})$/i,Ce=function(s){var t=s.toString(16);return t.length<2?"0"+t:t},Rr=function(s){var t=s.r,e=s.g,i=s.b,r=s.a,n=Math.max(t,e,i),o=n-Math.min(t,e,i),a=o?n===t?(e-i)/o:n===e?2+(i-t)/o:4+(t-e)/o:0;return{h:60*(a<0?a+6:a),s:n?o/n*100:0,v:n/255*100,a:r}},Ir=function(s){var t=s.h,e=s.s,i=s.v,r=s.a;t=t/360*6,e/=100,i/=100;var n=Math.floor(t),o=i*(1-e),a=i*(1-(t-n)*e),h=i*(1-(1-t+n)*e),l=n%6;return{r:255*[i,a,o,o,h,i][l],g:255*[h,i,i,a,o,o][l],b:255*[o,o,h,i,i,a][l],a:r}},fi=function(s){return{h:Er(s.h),s:st(s.s,0,100),l:st(s.l,0,100),a:st(s.a)}},pi=function(s){return{h:X(s.h),s:X(s.s),l:X(s.l),a:X(s.a,3)}},mi=function(s){return Ir((e=(t=s).s,{h:t.h,s:(e*=((i=t.l)<50?i:100-i)/100)>0?2*e/(i+e)*100:0,v:i+e,a:t.a}));var t,e,i},he=function(s){return{h:(t=Rr(s)).h,s:(r=(200-(e=t.s))*(i=t.v)/100)>0&&r<200?e*i/100/(r<=100?r:200-r)*100:0,l:r/2,a:t.a};var t,e,i,r},xo=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,yo=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,_o=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,bo=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,bs={string:[[function(s){var t=go.exec(s);return t?(s=t[1]).length<=4?{r:parseInt(s[0]+s[0],16),g:parseInt(s[1]+s[1],16),b:parseInt(s[2]+s[2],16),a:s.length===4?X(parseInt(s[3]+s[3],16)/255,2):1}:s.length===6||s.length===8?{r:parseInt(s.substr(0,2),16),g:parseInt(s.substr(2,2),16),b:parseInt(s.substr(4,2),16),a:s.length===8?X(parseInt(s.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(s){var t=_o.exec(s)||bo.exec(s);return t?t[2]!==t[4]||t[4]!==t[6]?null:di({r:Number(t[1])/(t[2]?100/255:1),g:Number(t[3])/(t[4]?100/255:1),b:Number(t[5])/(t[6]?100/255:1),a:t[7]===void 0?1:Number(t[7])/(t[8]?100:1)}):null},"rgb"],[function(s){var t=xo.exec(s)||yo.exec(s);if(!t)return null;var e,i,r=fi({h:(e=t[1],i=t[2],i===void 0&&(i="deg"),Number(e)*(mo[i]||1)),s:Number(t[3]),l:Number(t[4]),a:t[5]===void 0?1:Number(t[5])/(t[6]?100:1)});return mi(r)},"hsl"]],object:[[function(s){var t=s.r,e=s.g,i=s.b,r=s.a,n=r===void 0?1:r;return mt(t)&&mt(e)&&mt(i)?di({r:Number(t),g:Number(e),b:Number(i),a:Number(n)}):null},"rgb"],[function(s){var t=s.h,e=s.s,i=s.l,r=s.a,n=r===void 0?1:r;if(!mt(t)||!mt(e)||!mt(i))return null;var o=fi({h:Number(t),s:Number(e),l:Number(i),a:Number(n)});return mi(o)},"hsl"],[function(s){var t=s.h,e=s.s,i=s.v,r=s.a,n=r===void 0?1:r;if(!mt(t)||!mt(e)||!mt(i))return null;var o=function(a){return{h:Er(a.h),s:st(a.s,0,100),v:st(a.v,0,100),a:st(a.a)}}({h:Number(t),s:Number(e),v:Number(i),a:Number(n)});return Ir(o)},"hsv"]]},gi=function(s,t){for(var e=0;e<t.length;e++){var i=t[e][0](s);if(i)return[i,t[e][1]]}return[null,void 0]},wo=function(s){return typeof s=="string"?gi(s.trim(),bs.string):typeof s=="object"&&s!==null?gi(s,bs.object):[null,void 0]},Je=function(s,t){var e=he(s);return{h:e.h,s:st(e.s+100*t,0,100),l:e.l,a:e.a}},ts=function(s){return(299*s.r+587*s.g+114*s.b)/1e3/255},xi=function(s,t){var e=he(s);return{h:e.h,s:e.s,l:st(e.l+100*t,0,100),a:e.a}},ws=function(){function s(t){this.parsed=wo(t)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return s.prototype.isValid=function(){return this.parsed!==null},s.prototype.brightness=function(){return X(ts(this.rgba),2)},s.prototype.isDark=function(){return ts(this.rgba)<.5},s.prototype.isLight=function(){return ts(this.rgba)>=.5},s.prototype.toHex=function(){return t=Qe(this.rgba),e=t.r,i=t.g,r=t.b,o=(n=t.a)<1?Ce(X(255*n)):"","#"+Ce(e)+Ce(i)+Ce(r)+o;var t,e,i,r,n,o},s.prototype.toRgb=function(){return Qe(this.rgba)},s.prototype.toRgbString=function(){return t=Qe(this.rgba),e=t.r,i=t.g,r=t.b,(n=t.a)<1?"rgba("+e+", "+i+", "+r+", "+n+")":"rgb("+e+", "+i+", "+r+")";var t,e,i,r,n},s.prototype.toHsl=function(){return pi(he(this.rgba))},s.prototype.toHslString=function(){return t=pi(he(this.rgba)),e=t.h,i=t.s,r=t.l,(n=t.a)<1?"hsla("+e+", "+i+"%, "+r+"%, "+n+")":"hsl("+e+", "+i+"%, "+r+"%)";var t,e,i,r,n},s.prototype.toHsv=function(){return t=Rr(this.rgba),{h:X(t.h),s:X(t.s),v:X(t.v),a:X(t.a,3)};var t},s.prototype.invert=function(){return ct({r:255-(t=this.rgba).r,g:255-t.g,b:255-t.b,a:t.a});var t},s.prototype.saturate=function(t){return t===void 0&&(t=.1),ct(Je(this.rgba,t))},s.prototype.desaturate=function(t){return t===void 0&&(t=.1),ct(Je(this.rgba,-t))},s.prototype.grayscale=function(){return ct(Je(this.rgba,-1))},s.prototype.lighten=function(t){return t===void 0&&(t=.1),ct(xi(this.rgba,t))},s.prototype.darken=function(t){return t===void 0&&(t=.1),ct(xi(this.rgba,-t))},s.prototype.rotate=function(t){return t===void 0&&(t=15),this.hue(this.hue()+t)},s.prototype.alpha=function(t){return typeof t=="number"?ct({r:(e=this.rgba).r,g:e.g,b:e.b,a:t}):X(this.rgba.a,3);var e},s.prototype.hue=function(t){var e=he(this.rgba);return typeof t=="number"?ct({h:t,s:e.s,l:e.l,a:e.a}):X(e.h)},s.prototype.isEqual=function(t){return this.toHex()===ct(t).toHex()},s}(),ct=function(s){return s instanceof ws?s:new ws(s)},yi=[],So=function(s){s.forEach(function(t){yi.indexOf(t)<0&&(t(ws,bs),yi.push(t))})};function vo(s,t){var e={white:"#ffffff",bisque:"#ffe4c4",blue:"#0000ff",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",antiquewhite:"#faebd7",aqua:"#00ffff",azure:"#f0ffff",whitesmoke:"#f5f5f5",papayawhip:"#ffefd5",plum:"#dda0dd",blanchedalmond:"#ffebcd",black:"#000000",gold:"#ffd700",goldenrod:"#daa520",gainsboro:"#dcdcdc",cornsilk:"#fff8dc",cornflowerblue:"#6495ed",burlywood:"#deb887",aquamarine:"#7fffd4",beige:"#f5f5dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkkhaki:"#bdb76b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",peachpuff:"#ffdab9",darkmagenta:"#8b008b",darkred:"#8b0000",darkorchid:"#9932cc",darkorange:"#ff8c00",darkslateblue:"#483d8b",gray:"#808080",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",deeppink:"#ff1493",deepskyblue:"#00bfff",wheat:"#f5deb3",firebrick:"#b22222",floralwhite:"#fffaf0",ghostwhite:"#f8f8ff",darkviolet:"#9400d3",magenta:"#ff00ff",green:"#008000",dodgerblue:"#1e90ff",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",blueviolet:"#8a2be2",forestgreen:"#228b22",lawngreen:"#7cfc00",indianred:"#cd5c5c",indigo:"#4b0082",fuchsia:"#ff00ff",brown:"#a52a2a",maroon:"#800000",mediumblue:"#0000cd",lightcoral:"#f08080",darkturquoise:"#00ced1",lightcyan:"#e0ffff",ivory:"#fffff0",lightyellow:"#ffffe0",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",linen:"#faf0e6",mediumaquamarine:"#66cdaa",lemonchiffon:"#fffacd",lime:"#00ff00",khaki:"#f0e68c",mediumseagreen:"#3cb371",limegreen:"#32cd32",mediumspringgreen:"#00fa9a",lightskyblue:"#87cefa",lightblue:"#add8e6",midnightblue:"#191970",lightpink:"#ffb6c1",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",mintcream:"#f5fffa",lightslategray:"#778899",lightslategrey:"#778899",navajowhite:"#ffdead",navy:"#000080",mediumvioletred:"#c71585",powderblue:"#b0e0e6",palegoldenrod:"#eee8aa",oldlace:"#fdf5e6",paleturquoise:"#afeeee",mediumturquoise:"#48d1cc",mediumorchid:"#ba55d3",rebeccapurple:"#663399",lightsteelblue:"#b0c4de",mediumslateblue:"#7b68ee",thistle:"#d8bfd8",tan:"#d2b48c",orchid:"#da70d6",mediumpurple:"#9370db",purple:"#800080",pink:"#ffc0cb",skyblue:"#87ceeb",springgreen:"#00ff7f",palegreen:"#98fb98",red:"#ff0000",yellow:"#ffff00",slateblue:"#6a5acd",lavenderblush:"#fff0f5",peru:"#cd853f",palevioletred:"#db7093",violet:"#ee82ee",teal:"#008080",slategray:"#708090",slategrey:"#708090",aliceblue:"#f0f8ff",darkseagreen:"#8fbc8f",darkolivegreen:"#556b2f",greenyellow:"#adff2f",seagreen:"#2e8b57",seashell:"#fff5ee",tomato:"#ff6347",silver:"#c0c0c0",sienna:"#a0522d",lavender:"#e6e6fa",lightgreen:"#90ee90",orange:"#ffa500",orangered:"#ff4500",steelblue:"#4682b4",royalblue:"#4169e1",turquoise:"#40e0d0",yellowgreen:"#9acd32",salmon:"#fa8072",saddlebrown:"#8b4513",sandybrown:"#f4a460",rosybrown:"#bc8f8f",darksalmon:"#e9967a",lightgoldenrodyellow:"#fafad2",snow:"#fffafa",lightgrey:"#d3d3d3",lightgray:"#d3d3d3",dimgray:"#696969",dimgrey:"#696969",olivedrab:"#6b8e23",olive:"#808000"},i={};for(var r in e)i[e[r]]=r;var n={};s.prototype.toName=function(o){if(!(this.rgba.a||this.rgba.r||this.rgba.g||this.rgba.b))return"transparent";var a,h,l=i[this.toHex()];if(l)return l;if(o!=null&&o.closest){var c=this.toRgb(),u=1/0,p="black";if(!n.length)for(var d in e)n[d]=new s(e[d]).toRgb();for(var m in e){var g=(a=c,h=n[m],Math.pow(a.r-h.r,2)+Math.pow(a.g-h.g,2)+Math.pow(a.b-h.b,2));g<u&&(u=g,p=m)}return p}},t.string.push([function(o){var a=o.toLowerCase(),h=a==="transparent"?"#0000":e[a];return h?new s(h).toRgb():null},"name"])}So([vo]);const Wt=class re{constructor(t=16777215){this._value=null,this._components=new Float32Array(4),this._components.fill(1),this._int=16777215,this.value=t}get red(){return this._components[0]}get green(){return this._components[1]}get blue(){return this._components[2]}get alpha(){return this._components[3]}setValue(t){return this.value=t,this}set value(t){if(t instanceof re)this._value=this._cloneSource(t._value),this._int=t._int,this._components.set(t._components);else{if(t===null)throw new Error("Cannot set Color#value to null");(this._value===null||!this._isSourceEqual(this._value,t))&&(this._value=this._cloneSource(t),this._normalize(this._value))}}get value(){return this._value}_cloneSource(t){return typeof t=="string"||typeof t=="number"||t instanceof Number||t===null?t:Array.isArray(t)||ArrayBuffer.isView(t)?t.slice(0):typeof t=="object"&&t!==null?{...t}:t}_isSourceEqual(t,e){const i=typeof t;if(i!==typeof e)return!1;if(i==="number"||i==="string"||t instanceof Number)return t===e;if(Array.isArray(t)&&Array.isArray(e)||ArrayBuffer.isView(t)&&ArrayBuffer.isView(e))return t.length!==e.length?!1:t.every((n,o)=>n===e[o]);if(t!==null&&e!==null){const n=Object.keys(t),o=Object.keys(e);return n.length!==o.length?!1:n.every(a=>t[a]===e[a])}return t===e}toRgba(){const[t,e,i,r]=this._components;return{r:t,g:e,b:i,a:r}}toRgb(){const[t,e,i]=this._components;return{r:t,g:e,b:i}}toRgbaString(){const[t,e,i]=this.toUint8RgbArray();return`rgba(${t},${e},${i},${this.alpha})`}toUint8RgbArray(t){const[e,i,r]=this._components;return this._arrayRgb||(this._arrayRgb=[]),t||(t=this._arrayRgb),t[0]=Math.round(e*255),t[1]=Math.round(i*255),t[2]=Math.round(r*255),t}toArray(t){this._arrayRgba||(this._arrayRgba=[]),t||(t=this._arrayRgba);const[e,i,r,n]=this._components;return t[0]=e,t[1]=i,t[2]=r,t[3]=n,t}toRgbArray(t){this._arrayRgb||(this._arrayRgb=[]),t||(t=this._arrayRgb);const[e,i,r]=this._components;return t[0]=e,t[1]=i,t[2]=r,t}toNumber(){return this._int}toBgrNumber(){const[t,e,i]=this.toUint8RgbArray();return(i<<16)+(e<<8)+t}toLittleEndianNumber(){const t=this._int;return(t>>16)+(t&65280)+((t&255)<<16)}multiply(t){const[e,i,r,n]=re._temp.setValue(t)._components;return this._components[0]*=e,this._components[1]*=i,this._components[2]*=r,this._components[3]*=n,this._refreshInt(),this._value=null,this}premultiply(t,e=!0){return e&&(this._components[0]*=t,this._components[1]*=t,this._components[2]*=t),this._components[3]=t,this._refreshInt(),this._value=null,this}toPremultiplied(t,e=!0){if(t===1)return(255<<24)+this._int;if(t===0)return e?0:this._int;let i=this._int>>16&255,r=this._int>>8&255,n=this._int&255;return e&&(i=i*t+.5|0,r=r*t+.5|0,n=n*t+.5|0),(t*255<<24)+(i<<16)+(r<<8)+n}toHex(){const t=this._int.toString(16);return`#${"000000".substring(0,6-t.length)+t}`}toHexa(){const e=Math.round(this._components[3]*255).toString(16);return this.toHex()+"00".substring(0,2-e.length)+e}setAlpha(t){return this._components[3]=this._clamp(t),this}_normalize(t){let e,i,r,n;if((typeof t=="number"||t instanceof Number)&&t>=0&&t<=16777215){const o=t;e=(o>>16&255)/255,i=(o>>8&255)/255,r=(o&255)/255,n=1}else if((Array.isArray(t)||t instanceof Float32Array)&&t.length>=3&&t.length<=4)t=this._clamp(t),[e,i,r,n=1]=t;else if((t instanceof Uint8Array||t instanceof Uint8ClampedArray)&&t.length>=3&&t.length<=4)t=this._clamp(t,0,255),[e,i,r,n=255]=t,e/=255,i/=255,r/=255,n/=255;else if(typeof t=="string"||typeof t=="object"){if(typeof t=="string"){const a=re.HEX_PATTERN.exec(t);a&&(t=`#${a[2]}`)}const o=ct(t);o.isValid()&&({r:e,g:i,b:r,a:n}=o.rgba,e/=255,i/=255,r/=255)}if(e!==void 0)this._components[0]=e,this._components[1]=i,this._components[2]=r,this._components[3]=n,this._refreshInt();else throw new Error(`Unable to convert color ${t}`)}_refreshInt(){this._clamp(this._components);const[t,e,i]=this._components;this._int=(t*255<<16)+(e*255<<8)+(i*255|0)}_clamp(t,e=0,i=1){return typeof t=="number"?Math.min(Math.max(t,e),i):(t.forEach((r,n)=>{t[n]=Math.min(Math.max(r,e),i)}),t)}static isColorLike(t){return typeof t=="number"||typeof t=="string"||t instanceof Number||t instanceof re||Array.isArray(t)||t instanceof Uint8Array||t instanceof Uint8ClampedArray||t instanceof Float32Array||t.r!==void 0&&t.g!==void 0&&t.b!==void 0||t.r!==void 0&&t.g!==void 0&&t.b!==void 0&&t.a!==void 0||t.h!==void 0&&t.s!==void 0&&t.l!==void 0||t.h!==void 0&&t.s!==void 0&&t.l!==void 0&&t.a!==void 0||t.h!==void 0&&t.s!==void 0&&t.v!==void 0||t.h!==void 0&&t.s!==void 0&&t.v!==void 0&&t.a!==void 0}};Wt.shared=new Wt;Wt._temp=new Wt;Wt.HEX_PATTERN=/^(#|0x)?(([a-f0-9]{3}){1,2}([a-f0-9]{2})?)$/i;let Y=Wt;const Po={cullArea:null,cullable:!1,cullableChildren:!0};let es=0;const _i=500;function Q(...s){es!==_i&&(es++,es===_i?console.warn("PixiJS Warning: too many warnings, no more warnings will be reported to the console by PixiJS."):console.warn("PixiJS Warning: ",...s))}const _e={_registeredResources:new Set,register(s){this._registeredResources.add(s)},unregister(s){this._registeredResources.delete(s)},release(){this._registeredResources.forEach(s=>s.clear())},get registeredCount(){return this._registeredResources.size},isRegistered(s){return this._registeredResources.has(s)},reset(){this._registeredResources.clear()}};class Mo{constructor(t,e){this._pool=[],this._count=0,this._index=0,this._classType=t,e&&this.prepopulate(e)}prepopulate(t){for(let e=0;e<t;e++)this._pool[this._index++]=new this._classType;this._count+=t}get(t){var i;let e;return this._index>0?e=this._pool[--this._index]:e=new this._classType,(i=e.init)==null||i.call(e,t),e}return(t){var e;(e=t.reset)==null||e.call(t),this._pool[this._index++]=t}get totalSize(){return this._count}get totalFree(){return this._index}get totalUsed(){return this._count-this._index}clear(){if(this._pool.length>0&&this._pool[0].destroy)for(let t=0;t<this._index;t++)this._pool[t].destroy();this._pool.length=0,this._count=0,this._index=0}}class Co{constructor(){this._poolsByClass=new Map}prepopulate(t,e){this.getPool(t).prepopulate(e)}get(t,e){return this.getPool(t).get(e)}return(t){this.getPool(t.constructor).return(t)}getPool(t){return this._poolsByClass.has(t)||this._poolsByClass.set(t,new Mo(t)),this._poolsByClass.get(t)}stats(){const t={};return this._poolsByClass.forEach(e=>{const i=t[e._classType.name]?e._classType.name+e._classType.ID:e._classType.name;t[i]={free:e.totalFree,used:e.totalUsed,size:e.totalSize}}),t}clear(){this._poolsByClass.forEach(t=>t.clear()),this._poolsByClass.clear()}}const it=new Co;_e.register(it);const To={get isCachedAsTexture(){var s;return!!((s=this.renderGroup)!=null&&s.isCachedAsTexture)},cacheAsTexture(s){typeof s=="boolean"&&s===!1?this.disableRenderGroup():(this.enableRenderGroup(),this.renderGroup.enableCacheAsTexture(s===!0?{}:s))},updateCacheTexture(){var s;(s=this.renderGroup)==null||s.updateCacheTexture()},get cacheAsBitmap(){return this.isCachedAsTexture},set cacheAsBitmap(s){F("v8.6.0","cacheAsBitmap is deprecated, use cacheAsTexture instead."),this.cacheAsTexture(s)}};function Ao(s,t,e){const i=s.length;let r;if(t>=i||e===0)return;e=t+e>i?i-t:e;const n=i-e;for(r=t;r<n;++r)s[r]=s[r+e];s.length=n}const ko={allowChildren:!0,removeChildren(s=0,t){var n;const e=t??this.children.length,i=e-s,r=[];if(i>0&&i<=e){for(let a=e-1;a>=s;a--){const h=this.children[a];h&&(r.push(h),h.parent=null)}Ao(this.children,s,e);const o=this.renderGroup||this.parentRenderGroup;o&&o.removeChildren(r);for(let a=0;a<r.length;++a){const h=r[a];(n=h.parentRenderLayer)==null||n.detach(h),this.emit("childRemoved",h,this,a),r[a].emit("removed",this)}return r.length>0&&this._didViewChangeTick++,r}else if(i===0&&this.children.length===0)return r;throw new RangeError("removeChildren: numeric values are outside the acceptable range.")},removeChildAt(s){const t=this.getChildAt(s);return this.removeChild(t)},getChildAt(s){if(s<0||s>=this.children.length)throw new Error(`getChildAt: Index (${s}) does not exist.`);return this.children[s]},setChildIndex(s,t){if(t<0||t>=this.children.length)throw new Error(`The index ${t} supplied is out of bounds ${this.children.length}`);this.getChildIndex(s),this.addChildAt(s,t)},getChildIndex(s){const t=this.children.indexOf(s);if(t===-1)throw new Error("The supplied Container must be a child of the caller");return t},addChildAt(s,t){this.allowChildren||F(O,"addChildAt: Only Containers will be allowed to add children in v8.0.0");const{children:e}=this;if(t<0||t>e.length)throw new Error(`${s}addChildAt: The index ${t} supplied is out of bounds ${e.length}`);if(s.parent){const r=s.parent.children.indexOf(s);if(s.parent===this&&r===t)return s;r!==-1&&s.parent.children.splice(r,1)}t===e.length?e.push(s):e.splice(t,0,s),s.parent=this,s.didChange=!0,s._updateFlags=15;const i=this.renderGroup||this.parentRenderGroup;return i&&i.addChild(s),this.sortableChildren&&(this.sortDirty=!0),this.emit("childAdded",s,this,t),s.emit("added",this),s},swapChildren(s,t){if(s===t)return;const e=this.getChildIndex(s),i=this.getChildIndex(t);this.children[e]=t,this.children[i]=s;const r=this.renderGroup||this.parentRenderGroup;r&&(r.structureDidChange=!0),this._didContainerChangeTick++},removeFromParent(){var s;(s=this.parent)==null||s.removeChild(this)},reparentChild(...s){return s.length===1?this.reparentChildAt(s[0],this.children.length):(s.forEach(t=>this.reparentChildAt(t,this.children.length)),s[0])},reparentChildAt(s,t){if(s.parent===this)return this.setChildIndex(s,t),s;const e=s.worldTransform.clone();s.removeFromParent(),this.addChildAt(s,t);const i=this.worldTransform.clone();return i.invert(),e.prepend(i),s.setFromMatrix(e),s},replaceChild(s,t){s.updateLocalTransform(),this.addChildAt(t,this.getChildIndex(s)),t.setFromMatrix(s.localTransform),t.updateLocalTransform(),this.removeChild(s)}},Eo={collectRenderables(s,t,e){this.parentRenderLayer&&this.parentRenderLayer!==e||this.globalDisplayStatus<7||!this.includeInBuild||(this.sortableChildren&&this.sortChildren(),this.isSimple?this.collectRenderablesSimple(s,t,e):this.renderGroup?t.renderPipes.renderGroup.addRenderGroup(this.renderGroup,s):this.collectRenderablesWithEffects(s,t,e))},collectRenderablesSimple(s,t,e){const i=this.children,r=i.length;for(let n=0;n<r;n++)i[n].collectRenderables(s,t,e)},collectRenderablesWithEffects(s,t,e){const{renderPipes:i}=t;for(let r=0;r<this.effects.length;r++){const n=this.effects[r];i[n.pipe].push(n,this,s)}this.collectRenderablesSimple(s,t,e);for(let r=this.effects.length-1;r>=0;r--){const n=this.effects[r];i[n.pipe].pop(n,this,s)}}};class bi{constructor(){this.pipe="filter",this.priority=1}destroy(){for(let t=0;t<this.filters.length;t++)this.filters[t].destroy();this.filters=null,this.filterArea=null}}class Ro{constructor(){this._effectClasses=[],this._tests=[],this._initialized=!1}init(){this._initialized||(this._initialized=!0,this._effectClasses.forEach(t=>{this.add({test:t.test,maskClass:t})}))}add(t){this._tests.push(t)}getMaskEffect(t){this._initialized||this.init();for(let e=0;e<this._tests.length;e++){const i=this._tests[e];if(i.test(t))return it.get(i.maskClass,t)}return t}returnMaskEffect(t){it.return(t)}}const Ss=new Ro;rt.handleByList(L.MaskEffect,Ss._effectClasses);const Io={_maskEffect:null,_maskOptions:{inverse:!1},_filterEffect:null,effects:[],_markStructureAsChanged(){const s=this.renderGroup||this.parentRenderGroup;s&&(s.structureDidChange=!0)},addEffect(s){this.effects.indexOf(s)===-1&&(this.effects.push(s),this.effects.sort((e,i)=>e.priority-i.priority),this._markStructureAsChanged(),this._updateIsSimple())},removeEffect(s){const t=this.effects.indexOf(s);t!==-1&&(this.effects.splice(t,1),this._markStructureAsChanged(),this._updateIsSimple())},set mask(s){const t=this._maskEffect;(t==null?void 0:t.mask)!==s&&(t&&(this.removeEffect(t),Ss.returnMaskEffect(t),this._maskEffect=null),s!=null&&(this._maskEffect=Ss.getMaskEffect(s),this.addEffect(this._maskEffect)))},get mask(){var s;return(s=this._maskEffect)==null?void 0:s.mask},setMask(s){this._maskOptions={...this._maskOptions,...s},s.mask&&(this.mask=s.mask),this._markStructureAsChanged()},set filters(s){var n;!Array.isArray(s)&&s&&(s=[s]);const t=this._filterEffect||(this._filterEffect=new bi);s=s;const e=(s==null?void 0:s.length)>0,i=((n=t.filters)==null?void 0:n.length)>0,r=e!==i;s=Array.isArray(s)?s.slice(0):s,t.filters=Object.freeze(s),r&&(e?this.addEffect(t):(this.removeEffect(t),t.filters=s??null))},get filters(){var s;return(s=this._filterEffect)==null?void 0:s.filters},set filterArea(s){this._filterEffect||(this._filterEffect=new bi),this._filterEffect.filterArea=s},get filterArea(){var s;return(s=this._filterEffect)==null?void 0:s.filterArea}},Bo={label:null,get name(){return F(O,"Container.name property has been removed, use Container.label instead"),this.label},set name(s){F(O,"Container.name property has been removed, use Container.label instead"),this.label=s},getChildByName(s,t=!1){return this.getChildByLabel(s,t)},getChildByLabel(s,t=!1){const e=this.children;for(let i=0;i<e.length;i++){const r=e[i];if(r.label===s||s instanceof RegExp&&s.test(r.label))return r}if(t)for(let i=0;i<e.length;i++){const n=e[i].getChildByLabel(s,!0);if(n)return n}return null},getChildrenByLabel(s,t=!1,e=[]){const i=this.children;for(let r=0;r<i.length;r++){const n=i[r];(n.label===s||s instanceof RegExp&&s.test(n.label))&&e.push(n)}if(t)for(let r=0;r<i.length;r++)i[r].getChildrenByLabel(s,!0,e);return e}},K=it.getPool(I),xt=it.getPool(at),Fo=new I,Go={getFastGlobalBounds(s,t){t||(t=new at),t.clear(),this._getGlobalBoundsRecursive(!!s,t,this.parentRenderLayer),t.isValid||t.set(0,0,0,0);const e=this.renderGroup||this.parentRenderGroup;return t.applyMatrix(e.worldTransform),t},_getGlobalBoundsRecursive(s,t,e){let i=t;if(s&&this.parentRenderLayer&&this.parentRenderLayer!==e||this.localDisplayStatus!==7||!this.measurable)return;const r=!!this.effects.length;if((this.renderGroup||r)&&(i=xt.get().clear()),this.boundsArea)t.addRect(this.boundsArea,this.worldTransform);else{if(this.renderPipeId){const o=this.bounds;i.addFrame(o.minX,o.minY,o.maxX,o.maxY,this.groupTransform)}const n=this.children;for(let o=0;o<n.length;o++)n[o]._getGlobalBoundsRecursive(s,i,e)}if(r){let n=!1;const o=this.renderGroup||this.parentRenderGroup;for(let a=0;a<this.effects.length;a++)this.effects[a].addBounds&&(n||(n=!0,i.applyMatrix(o.worldTransform)),this.effects[a].addBounds(i,!0));n&&i.applyMatrix(o.worldTransform.copyTo(Fo).invert()),t.addBounds(i),xt.return(i)}else this.renderGroup&&(t.addBounds(i,this.relativeGroupTransform),xt.return(i))}};function Br(s,t,e){e.clear();let i,r;return s.parent?t?i=s.parent.worldTransform:(r=K.get().identity(),i=Os(s,r)):i=I.IDENTITY,Fr(s,e,i,t),r&&K.return(r),e.isValid||e.set(0,0,0,0),e}function Fr(s,t,e,i){var a,h;if(!s.visible||!s.measurable)return;let r;i?r=s.worldTransform:(s.updateLocalTransform(),r=K.get(),r.appendFrom(s.localTransform,e));const n=t,o=!!s.effects.length;if(o&&(t=xt.get().clear()),s.boundsArea)t.addRect(s.boundsArea,r);else{const l=s.bounds;l&&!l.isEmpty()&&(t.matrix=r,t.addBounds(l));for(let c=0;c<s.children.length;c++)Fr(s.children[c],t,r,i)}if(o){for(let l=0;l<s.effects.length;l++)(h=(a=s.effects[l]).addBounds)==null||h.call(a,t);n.addBounds(t,I.IDENTITY),xt.return(t)}i||K.return(r)}function Os(s,t){const e=s.parent;return e&&(Os(e,t),e.updateLocalTransform(),t.append(e.localTransform)),t}function Gr(s,t){if(s===16777215||!t)return t;if(t===16777215||!s)return s;const e=s>>16&255,i=s>>8&255,r=s&255,n=t>>16&255,o=t>>8&255,a=t&255,h=e*n/255|0,l=i*o/255|0,c=r*a/255|0;return(h<<16)+(l<<8)+c}const wi=16777215;function Si(s,t){return s===wi?t:t===wi?s:Gr(s,t)}function ze(s){return((s&255)<<16)+(s&65280)+(s>>16&255)}const Lo={getGlobalAlpha(s){if(s)return this.renderGroup?this.renderGroup.worldAlpha:this.parentRenderGroup?this.parentRenderGroup.worldAlpha*this.alpha:this.alpha;let t=this.alpha,e=this.parent;for(;e;)t*=e.alpha,e=e.parent;return t},getGlobalTransform(s=new I,t){if(t)return s.copyFrom(this.worldTransform);this.updateLocalTransform();const e=Os(this,K.get().identity());return s.appendFrom(this.localTransform,e),K.return(e),s},getGlobalTint(s){if(s)return this.renderGroup?ze(this.renderGroup.worldColor):this.parentRenderGroup?ze(Si(this.localColor,this.parentRenderGroup.worldColor)):this.tint;let t=this.localColor,e=this.parent;for(;e;)t=Si(t,e.localColor),e=e.parent;return ze(t)}};function Lr(s,t,e){return t.clear(),e||(e=I.IDENTITY),Dr(s,t,e,s,!0),t.isValid||t.set(0,0,0,0),t}function Dr(s,t,e,i,r){var h,l;let n;if(r)n=K.get(),n=e.copyTo(n);else{if(!s.visible||!s.measurable)return;s.updateLocalTransform();const c=s.localTransform;n=K.get(),n.appendFrom(c,e)}const o=t,a=!!s.effects.length;if(a&&(t=xt.get().clear()),s.boundsArea)t.addRect(s.boundsArea,n);else{s.renderPipeId&&(t.matrix=n,t.addBounds(s.bounds));const c=s.children;for(let u=0;u<c.length;u++)Dr(c[u],t,n,i,!1)}if(a){for(let c=0;c<s.effects.length;c++)(l=(h=s.effects[c]).addLocalBounds)==null||l.call(h,t,i);o.addBounds(t,I.IDENTITY),xt.return(t)}K.return(n)}function zr(s,t){const e=s.children;for(let i=0;i<e.length;i++){const r=e[i],n=r.uid,o=(r._didViewChangeTick&65535)<<16|r._didContainerChangeTick&65535,a=t.index;(t.data[a]!==n||t.data[a+1]!==o)&&(t.data[t.index]=n,t.data[t.index+1]=o,t.didChange=!0),t.index=a+2,r.children.length&&zr(r,t)}return t.didChange}const Do=new I,zo={_localBoundsCacheId:-1,_localBoundsCacheData:null,_setWidth(s,t){const e=Math.sign(this.scale.x)||1;t!==0?this.scale.x=s/t*e:this.scale.x=e},_setHeight(s,t){const e=Math.sign(this.scale.y)||1;t!==0?this.scale.y=s/t*e:this.scale.y=e},getLocalBounds(){this._localBoundsCacheData||(this._localBoundsCacheData={data:[],index:1,didChange:!1,localBounds:new at});const s=this._localBoundsCacheData;return s.index=1,s.didChange=!1,s.data[0]!==this._didViewChangeTick&&(s.didChange=!0,s.data[0]=this._didViewChangeTick),zr(this,s),s.didChange&&Lr(this,s.localBounds,Do),s.localBounds},getBounds(s,t){return Br(this,s,t||new at)}},Ho={_onRender:null,set onRender(s){const t=this.renderGroup||this.parentRenderGroup;if(!s){this._onRender&&(t==null||t.removeOnRender(this)),this._onRender=null;return}this._onRender||t==null||t.addOnRender(this),this._onRender=s},get onRender(){return this._onRender}},No={_zIndex:0,sortDirty:!1,sortableChildren:!1,get zIndex(){return this._zIndex},set zIndex(s){this._zIndex!==s&&(this._zIndex=s,this.depthOfChildModified())},depthOfChildModified(){this.parent&&(this.parent.sortableChildren=!0,this.parent.sortDirty=!0),this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0)},sortChildren(){this.sortDirty&&(this.sortDirty=!1,this.children.sort(Uo))}};function Uo(s,t){return s._zIndex-t._zIndex}const $o={getGlobalPosition(s=new Z,t=!1){return this.parent?this.parent.toGlobal(this._position,s,t):(s.x=this._position.x,s.y=this._position.y),s},toGlobal(s,t,e=!1){const i=this.getGlobalTransform(K.get(),e);return t=i.apply(s,t),K.return(i),t},toLocal(s,t,e,i){t&&(s=t.toGlobal(s,e,i));const r=this.getGlobalTransform(K.get(),i);return e=r.applyInverse(s,e),K.return(r),e}};class Hr{constructor(){this.uid=V("instructionSet"),this.instructions=[],this.instructionSize=0,this.renderables=[],this.gcTick=0}reset(){this.instructionSize=0}destroy(){this.instructions.length=0,this.renderables.length=0,this.renderPipes=null,this.gcTick=0}add(t){this.instructions[this.instructionSize++]=t}log(){this.instructions.length=this.instructionSize,console.table(this.instructions,["type","action"])}}let Oo=0;class Vo{constructor(t){this._poolKeyHash=Object.create(null),this._texturePool={},this.textureOptions=t||{},this.enableFullScreen=!1,this.textureStyle=new Ue(this.textureOptions)}createTexture(t,e,i){const r=new ht({...this.textureOptions,width:t,height:e,resolution:1,antialias:i,autoGarbageCollect:!1});return new D({source:r,label:`texturePool_${Oo++}`})}getOptimalTexture(t,e,i=1,r){let n=Math.ceil(t*i-1e-6),o=Math.ceil(e*i-1e-6);n=Vt(n),o=Vt(o);const a=(n<<17)+(o<<1)+(r?1:0);this._texturePool[a]||(this._texturePool[a]=[]);let h=this._texturePool[a].pop();return h||(h=this.createTexture(n,o,r)),h.source._resolution=i,h.source.width=n/i,h.source.height=o/i,h.source.pixelWidth=n,h.source.pixelHeight=o,h.frame.x=0,h.frame.y=0,h.frame.width=t,h.frame.height=e,h.updateUvs(),this._poolKeyHash[h.uid]=a,h}getSameSizeTexture(t,e=!1){const i=t.source;return this.getOptimalTexture(t.width,t.height,i._resolution,e)}returnTexture(t,e=!1){const i=this._poolKeyHash[t.uid];e&&(t.source.style=this.textureStyle),this._texturePool[i].push(t)}clear(t){if(t=t!==!1,t)for(const e in this._texturePool){const i=this._texturePool[e];if(i)for(let r=0;r<i.length;r++)i[r].destroy(!0)}this._texturePool={}}}const Nr=new Vo;_e.register(Nr);class Wo{constructor(){this.renderPipeId="renderGroup",this.root=null,this.canBundle=!1,this.renderGroupParent=null,this.renderGroupChildren=[],this.worldTransform=new I,this.worldColorAlpha=4294967295,this.worldColor=16777215,this.worldAlpha=1,this.childrenToUpdate=Object.create(null),this.updateTick=0,this.gcTick=0,this.childrenRenderablesToUpdate={list:[],index:0},this.structureDidChange=!0,this.instructionSet=new Hr,this._onRenderContainers=[],this.textureNeedsUpdate=!0,this.isCachedAsTexture=!1,this._matrixDirty=7}init(t){this.root=t,t._onRender&&this.addOnRender(t),t.didChange=!0;const e=t.children;for(let i=0;i<e.length;i++){const r=e[i];r._updateFlags=15,this.addChild(r)}}enableCacheAsTexture(t={}){this.textureOptions=t,this.isCachedAsTexture=!0,this.textureNeedsUpdate=!0}disableCacheAsTexture(){this.isCachedAsTexture=!1,this.texture&&(Nr.returnTexture(this.texture,!0),this.texture=null)}updateCacheTexture(){this.textureNeedsUpdate=!0;const t=this._parentCacheAsTextureRenderGroup;t&&!t.textureNeedsUpdate&&t.updateCacheTexture()}reset(){this.renderGroupChildren.length=0;for(const t in this.childrenToUpdate){const e=this.childrenToUpdate[t];e.list.fill(null),e.index=0}this.childrenRenderablesToUpdate.index=0,this.childrenRenderablesToUpdate.list.fill(null),this.root=null,this.updateTick=0,this.structureDidChange=!0,this._onRenderContainers.length=0,this.renderGroupParent=null,this.disableCacheAsTexture()}get localTransform(){return this.root.localTransform}addRenderGroupChild(t){t.renderGroupParent&&t.renderGroupParent._removeRenderGroupChild(t),t.renderGroupParent=this,this.renderGroupChildren.push(t)}_removeRenderGroupChild(t){const e=this.renderGroupChildren.indexOf(t);e>-1&&this.renderGroupChildren.splice(e,1),t.renderGroupParent=null}addChild(t){if(this.structureDidChange=!0,t.parentRenderGroup=this,t.updateTick=-1,t.parent===this.root?t.relativeRenderGroupDepth=1:t.relativeRenderGroupDepth=t.parent.relativeRenderGroupDepth+1,t.didChange=!0,this.onChildUpdate(t),t.renderGroup){this.addRenderGroupChild(t.renderGroup);return}t._onRender&&this.addOnRender(t);const e=t.children;for(let i=0;i<e.length;i++)this.addChild(e[i])}removeChild(t){if(this.structureDidChange=!0,t._onRender&&(t.renderGroup||this.removeOnRender(t)),t.parentRenderGroup=null,t.renderGroup){this._removeRenderGroupChild(t.renderGroup);return}const e=t.children;for(let i=0;i<e.length;i++)this.removeChild(e[i])}removeChildren(t){for(let e=0;e<t.length;e++)this.removeChild(t[e])}onChildUpdate(t){let e=this.childrenToUpdate[t.relativeRenderGroupDepth];e||(e=this.childrenToUpdate[t.relativeRenderGroupDepth]={index:0,list:[]}),e.list[e.index++]=t}updateRenderable(t){t.globalDisplayStatus<7||(this.instructionSet.renderPipes[t.renderPipeId].updateRenderable(t),t.didViewUpdate=!1)}onChildViewUpdate(t){this.childrenRenderablesToUpdate.list[this.childrenRenderablesToUpdate.index++]=t}get isRenderable(){return this.root.localDisplayStatus===7&&this.worldAlpha>0}addOnRender(t){this._onRenderContainers.push(t)}removeOnRender(t){this._onRenderContainers.splice(this._onRenderContainers.indexOf(t),1)}runOnRender(t){for(let e=0;e<this._onRenderContainers.length;e++)this._onRenderContainers[e]._onRender(t)}destroy(){this.disableCacheAsTexture(),this.renderGroupParent=null,this.root=null,this.childrenRenderablesToUpdate=null,this.childrenToUpdate=null,this.renderGroupChildren=null,this._onRenderContainers=null,this.instructionSet=null}getChildren(t=[]){const e=this.root.children;for(let i=0;i<e.length;i++)this._getChildren(e[i],t);return t}_getChildren(t,e=[]){if(e.push(t),t.renderGroup)return e;const i=t.children;for(let r=0;r<i.length;r++)this._getChildren(i[r],e);return e}invalidateMatrices(){this._matrixDirty=7}get inverseWorldTransform(){return this._matrixDirty&1?(this._matrixDirty&=-2,this._inverseWorldTransform||(this._inverseWorldTransform=new I),this._inverseWorldTransform.copyFrom(this.worldTransform).invert()):this._inverseWorldTransform}get textureOffsetInverseTransform(){return this._matrixDirty&2?(this._matrixDirty&=-3,this._textureOffsetInverseTransform||(this._textureOffsetInverseTransform=new I),this._textureOffsetInverseTransform.copyFrom(this.inverseWorldTransform).translate(-this._textureBounds.x,-this._textureBounds.y)):this._textureOffsetInverseTransform}get inverseParentTextureTransform(){if(!(this._matrixDirty&4))return this._inverseParentTextureTransform;this._matrixDirty&=-5;const t=this._parentCacheAsTextureRenderGroup;return t?(this._inverseParentTextureTransform||(this._inverseParentTextureTransform=new I),this._inverseParentTextureTransform.copyFrom(this.worldTransform).prepend(t.inverseWorldTransform).translate(-t._textureBounds.x,-t._textureBounds.y)):this.worldTransform}get cacheToLocalTransform(){return this.isCachedAsTexture?this.textureOffsetInverseTransform:this._parentCacheAsTextureRenderGroup?this._parentCacheAsTextureRenderGroup.textureOffsetInverseTransform:null}}function Yo(s,t,e={}){for(const i in t)!e[i]&&t[i]!==void 0&&(s[i]=t[i])}const ss=new q(null),Te=new q(null),is=new q(null,1,1),Ae=new q(null),vi=1,Xo=2,rs=4;class ft extends pt{constructor(t={}){var e,i;super(),this.uid=V("renderable"),this._updateFlags=15,this.renderGroup=null,this.parentRenderGroup=null,this.parentRenderGroupIndex=0,this.didChange=!1,this.didViewUpdate=!1,this.relativeRenderGroupDepth=0,this.children=[],this.parent=null,this.includeInBuild=!0,this.measurable=!0,this.isSimple=!0,this.updateTick=-1,this.localTransform=new I,this.relativeGroupTransform=new I,this.groupTransform=this.relativeGroupTransform,this.destroyed=!1,this._position=new q(this,0,0),this._scale=is,this._pivot=Te,this._origin=Ae,this._skew=ss,this._cx=1,this._sx=0,this._cy=0,this._sy=1,this._rotation=0,this.localColor=16777215,this.localAlpha=1,this.groupAlpha=1,this.groupColor=16777215,this.groupColorAlpha=4294967295,this.localBlendMode="inherit",this.groupBlendMode="normal",this.localDisplayStatus=7,this.globalDisplayStatus=7,this._didContainerChangeTick=0,this._didViewChangeTick=0,this._didLocalTransformChangeId=-1,this.effects=[],Yo(this,t,{children:!0,parent:!0,effects:!0}),(e=t.children)==null||e.forEach(r=>this.addChild(r)),(i=t.parent)==null||i.addChild(this)}static mixin(t){F("8.8.0","Container.mixin is deprecated, please use extensions.mixin instead."),rt.mixin(ft,t)}set _didChangeId(t){this._didViewChangeTick=t>>12&4095,this._didContainerChangeTick=t&4095}get _didChangeId(){return this._didContainerChangeTick&4095|(this._didViewChangeTick&4095)<<12}addChild(...t){if(this.allowChildren||F(O,"addChild: Only Containers will be allowed to add children in v8.0.0"),t.length>1){for(let r=0;r<t.length;r++)this.addChild(t[r]);return t[0]}const e=t[0],i=this.renderGroup||this.parentRenderGroup;return e.parent===this?(this.children.splice(this.children.indexOf(e),1),this.children.push(e),i&&(i.structureDidChange=!0),e):(e.parent&&e.parent.removeChild(e),this.children.push(e),this.sortableChildren&&(this.sortDirty=!0),e.parent=this,e.didChange=!0,e._updateFlags=15,i&&i.addChild(e),this.emit("childAdded",e,this,this.children.length-1),e.emit("added",this),this._didViewChangeTick++,e._zIndex!==0&&e.depthOfChildModified(),e)}removeChild(...t){if(t.length>1){for(let r=0;r<t.length;r++)this.removeChild(t[r]);return t[0]}const e=t[0],i=this.children.indexOf(e);return i>-1&&(this._didViewChangeTick++,this.children.splice(i,1),this.renderGroup?this.renderGroup.removeChild(e):this.parentRenderGroup&&this.parentRenderGroup.removeChild(e),e.parentRenderLayer&&e.parentRenderLayer.detach(e),e.parent=null,this.emit("childRemoved",e,this,i),e.emit("removed",this)),e}_onUpdate(t){t&&t===this._skew&&this._updateSkew(),this._didContainerChangeTick++,!this.didChange&&(this.didChange=!0,this.parentRenderGroup&&this.parentRenderGroup.onChildUpdate(this))}set isRenderGroup(t){!!this.renderGroup!==t&&(t?this.enableRenderGroup():this.disableRenderGroup())}get isRenderGroup(){return!!this.renderGroup}enableRenderGroup(){if(this.renderGroup)return;const t=this.parentRenderGroup;t==null||t.removeChild(this),this.renderGroup=it.get(Wo,this),this.groupTransform=I.IDENTITY,t==null||t.addChild(this),this._updateIsSimple()}disableRenderGroup(){if(!this.renderGroup)return;const t=this.parentRenderGroup;t==null||t.removeChild(this),it.return(this.renderGroup),this.renderGroup=null,this.groupTransform=this.relativeGroupTransform,t==null||t.addChild(this),this._updateIsSimple()}_updateIsSimple(){this.isSimple=!this.renderGroup&&this.effects.length===0}get worldTransform(){return this._worldTransform||(this._worldTransform=new I),this.renderGroup?this._worldTransform.copyFrom(this.renderGroup.worldTransform):this.parentRenderGroup&&this._worldTransform.appendFrom(this.relativeGroupTransform,this.parentRenderGroup.worldTransform),this._worldTransform}get x(){return this._position.x}set x(t){this._position.x=t}get y(){return this._position.y}set y(t){this._position.y=t}get position(){return this._position}set position(t){this._position.copyFrom(t)}get rotation(){return this._rotation}set rotation(t){this._rotation!==t&&(this._rotation=t,this._onUpdate(this._skew))}get angle(){return this.rotation*no}set angle(t){this.rotation=t*oo}get pivot(){return this._pivot===Te&&(this._pivot=new q(this,0,0)),this._pivot}set pivot(t){this._pivot===Te&&(this._pivot=new q(this,0,0),this._origin!==Ae&&Q("Setting both a pivot and origin on a Container is not recommended. This can lead to unexpected behavior if not handled carefully.")),typeof t=="number"?this._pivot.set(t):this._pivot.copyFrom(t)}get skew(){return this._skew===ss&&(this._skew=new q(this,0,0)),this._skew}set skew(t){this._skew===ss&&(this._skew=new q(this,0,0)),this._skew.copyFrom(t)}get scale(){return this._scale===is&&(this._scale=new q(this,1,1)),this._scale}set scale(t){this._scale===is&&(this._scale=new q(this,0,0)),typeof t=="string"&&(t=parseFloat(t)),typeof t=="number"?this._scale.set(t):this._scale.copyFrom(t)}get origin(){return this._origin===Ae&&(this._origin=new q(this,0,0)),this._origin}set origin(t){this._origin===Ae&&(this._origin=new q(this,0,0),this._pivot!==Te&&Q("Setting both a pivot and origin on a Container is not recommended. This can lead to unexpected behavior if not handled carefully.")),typeof t=="number"?this._origin.set(t):this._origin.copyFrom(t)}get width(){return Math.abs(this.scale.x*this.getLocalBounds().width)}set width(t){const e=this.getLocalBounds().width;this._setWidth(t,e)}get height(){return Math.abs(this.scale.y*this.getLocalBounds().height)}set height(t){const e=this.getLocalBounds().height;this._setHeight(t,e)}getSize(t){t||(t={});const e=this.getLocalBounds();return t.width=Math.abs(this.scale.x*e.width),t.height=Math.abs(this.scale.y*e.height),t}setSize(t,e){const i=this.getLocalBounds();typeof t=="object"?(e=t.height??t.width,t=t.width):e??(e=t),t!==void 0&&this._setWidth(t,i.width),e!==void 0&&this._setHeight(e,i.height)}_updateSkew(){const t=this._rotation,e=this._skew;this._cx=Math.cos(t+e._y),this._sx=Math.sin(t+e._y),this._cy=-Math.sin(t-e._x),this._sy=Math.cos(t-e._x)}updateTransform(t){return this.position.set(typeof t.x=="number"?t.x:this.position.x,typeof t.y=="number"?t.y:this.position.y),this.scale.set(typeof t.scaleX=="number"?t.scaleX||1:this.scale.x,typeof t.scaleY=="number"?t.scaleY||1:this.scale.y),this.rotation=typeof t.rotation=="number"?t.rotation:this.rotation,this.skew.set(typeof t.skewX=="number"?t.skewX:this.skew.x,typeof t.skewY=="number"?t.skewY:this.skew.y),this.pivot.set(typeof t.pivotX=="number"?t.pivotX:this.pivot.x,typeof t.pivotY=="number"?t.pivotY:this.pivot.y),this.origin.set(typeof t.originX=="number"?t.originX:this.origin.x,typeof t.originY=="number"?t.originY:this.origin.y),this}setFromMatrix(t){t.decompose(this)}updateLocalTransform(){const t=this._didContainerChangeTick;if(this._didLocalTransformChangeId===t)return;this._didLocalTransformChangeId=t;const e=this.localTransform,i=this._scale,r=this._pivot,n=this._origin,o=this._position,a=i._x,h=i._y,l=r._x,c=r._y,u=-n._x,p=-n._y;e.a=this._cx*a,e.b=this._sx*a,e.c=this._cy*h,e.d=this._sy*h,e.tx=o._x-(l*e.a+c*e.c)+(u*e.a+p*e.c)-u,e.ty=o._y-(l*e.b+c*e.d)+(u*e.b+p*e.d)-p}set alpha(t){t!==this.localAlpha&&(this.localAlpha=t,this._updateFlags|=vi,this._onUpdate())}get alpha(){return this.localAlpha}set tint(t){const i=Y.shared.setValue(t??16777215).toBgrNumber();i!==this.localColor&&(this.localColor=i,this._updateFlags|=vi,this._onUpdate())}get tint(){return ze(this.localColor)}set blendMode(t){this.localBlendMode!==t&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=Xo,this.localBlendMode=t,this._onUpdate())}get blendMode(){return this.localBlendMode}get visible(){return!!(this.localDisplayStatus&2)}set visible(t){const e=t?2:0;(this.localDisplayStatus&2)!==e&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=rs,this.localDisplayStatus^=2,this._onUpdate())}get culled(){return!(this.localDisplayStatus&4)}set culled(t){const e=t?0:4;(this.localDisplayStatus&4)!==e&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=rs,this.localDisplayStatus^=4,this._onUpdate())}get renderable(){return!!(this.localDisplayStatus&1)}set renderable(t){const e=t?1:0;(this.localDisplayStatus&1)!==e&&(this._updateFlags|=rs,this.localDisplayStatus^=1,this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._onUpdate())}get isRenderable(){return this.localDisplayStatus===7&&this.groupAlpha>0}destroy(t=!1){var r;if(this.destroyed)return;this.destroyed=!0;let e;if(this.children.length&&(e=this.removeChildren(0,this.children.length)),this.removeFromParent(),this.parent=null,this._maskEffect=null,this._filterEffect=null,this.effects=null,this._position=null,this._scale=null,this._pivot=null,this._origin=null,this._skew=null,this.emit("destroyed",this),this.removeAllListeners(),(typeof t=="boolean"?t:t==null?void 0:t.children)&&e)for(let n=0;n<e.length;++n)e[n].destroy(t);(r=this.renderGroup)==null||r.destroy(),this.renderGroup=null}}rt.mixin(ft,ko,Go,$o,Ho,zo,Io,Bo,No,Po,To,Lo,Eo);class Vs extends ft{constructor(t){super(t),this.canBundle=!0,this.allowChildren=!1,this._roundPixels=0,this._lastUsed=-1,this._gpuData=Object.create(null),this._bounds=new at(0,1,0,0),this._boundsDirty=!0}get bounds(){return this._boundsDirty?(this.updateBounds(),this._boundsDirty=!1,this._bounds):this._bounds}get roundPixels(){return!!this._roundPixels}set roundPixels(t){this._roundPixels=t?1:0}containsPoint(t){const e=this.bounds,{x:i,y:r}=t;return i>=e.minX&&i<=e.maxX&&r>=e.minY&&r<=e.maxY}onViewUpdate(){if(this._didViewChangeTick++,this._boundsDirty=!0,this.didViewUpdate)return;this.didViewUpdate=!0;const t=this.renderGroup||this.parentRenderGroup;t&&t.onChildViewUpdate(this)}destroy(t){var e,i;super.destroy(t),this._bounds=null;for(const r in this._gpuData)(i=(e=this._gpuData[r]).destroy)==null||i.call(e);this._gpuData=null}collectRenderablesSimple(t,e,i){const{renderPipes:r}=e;r.blendMode.pushBlendMode(this,this.groupBlendMode,t),r[this.renderPipeId].addRenderable(this,t),this.didViewUpdate=!1;const o=this.children,a=o.length;for(let h=0;h<a;h++)o[h].collectRenderables(t,e,i);r.blendMode.popBlendMode(t)}}class de extends Vs{constructor(t=D.EMPTY){t instanceof D&&(t={texture:t});const{texture:e=D.EMPTY,anchor:i,roundPixels:r,width:n,height:o,...a}=t;super({label:"Sprite",...a}),this.renderPipeId="sprite",this.batched=!0,this._visualBounds={minX:0,maxX:1,minY:0,maxY:0},this._anchor=new q({_onUpdate:()=>{this.onViewUpdate()}}),i?this.anchor=i:e.defaultAnchor&&(this.anchor=e.defaultAnchor),this.texture=e,this.allowChildren=!1,this.roundPixels=r??!1,n!==void 0&&(this.width=n),o!==void 0&&(this.height=o)}static from(t,e=!1){return t instanceof D?new de(t):new de(D.from(t,e))}set texture(t){t||(t=D.EMPTY);const e=this._texture;e!==t&&(e&&e.dynamic&&e.off("update",this.onViewUpdate,this),t.dynamic&&t.on("update",this.onViewUpdate,this),this._texture=t,this._width&&this._setWidth(this._width,this._texture.orig.width),this._height&&this._setHeight(this._height,this._texture.orig.height),this.onViewUpdate())}get texture(){return this._texture}get visualBounds(){return po(this._visualBounds,this._anchor,this._texture),this._visualBounds}get sourceBounds(){return F("8.6.1","Sprite.sourceBounds is deprecated, use visualBounds instead."),this.visualBounds}updateBounds(){const t=this._anchor,e=this._texture,i=this._bounds,{width:r,height:n}=e.orig;i.minX=-t._x*r,i.maxX=i.minX+r,i.minY=-t._y*n,i.maxY=i.minY+n}destroy(t=!1){if(super.destroy(t),typeof t=="boolean"?t:t==null?void 0:t.texture){const i=typeof t=="boolean"?t:t==null?void 0:t.textureSource;this._texture.destroy(i)}this._texture=null,this._visualBounds=null,this._bounds=null,this._anchor=null,this._gpuData=null}get anchor(){return this._anchor}set anchor(t){typeof t=="number"?this._anchor.set(t):this._anchor.copyFrom(t)}get width(){return Math.abs(this.scale.x)*this._texture.orig.width}set width(t){this._setWidth(t,this._texture.orig.width),this._width=t}get height(){return Math.abs(this.scale.y)*this._texture.orig.height}set height(t){this._setHeight(t,this._texture.orig.height),this._height=t}getSize(t){return t||(t={}),t.width=Math.abs(this.scale.x)*this._texture.orig.width,t.height=Math.abs(this.scale.y)*this._texture.orig.height,t}setSize(t,e){typeof t=="object"?(e=t.height??t.width,t=t.width):e??(e=t),t!==void 0&&this._setWidth(t,this._texture.orig.width),e!==void 0&&this._setHeight(e,this._texture.orig.height)}}const jo=new at;function Ur(s,t,e){const i=jo;s.measurable=!0,Br(s,e,i),t.addBoundsMask(i),s.measurable=!1}function $r(s,t,e){const i=xt.get();s.measurable=!0;const r=K.get().identity(),n=Or(s,e,r);Lr(s,i,n),s.measurable=!1,t.addBoundsMask(i),K.return(r),xt.return(i)}function Or(s,t,e){return s?(s!==t&&(Or(s.parent,t,e),s.updateLocalTransform(),e.append(s.localTransform)),e):(Q("Mask bounds, renderable is not inside the root container"),e)}class Vr{constructor(t){this.priority=0,this.inverse=!1,this.pipe="alphaMask",t!=null&&t.mask&&this.init(t.mask)}init(t){this.mask=t,this.renderMaskToTexture=!(t instanceof de),this.mask.renderable=this.renderMaskToTexture,this.mask.includeInBuild=!this.renderMaskToTexture,this.mask.measurable=!1}reset(){this.mask.measurable=!0,this.mask=null}addBounds(t,e){this.inverse||Ur(this.mask,t,e)}addLocalBounds(t,e){$r(this.mask,t,e)}containsPoint(t,e){const i=this.mask;return e(i,t)}destroy(){this.reset()}static test(t){return t instanceof de}}Vr.extension=L.MaskEffect;class Wr{constructor(t){this.priority=0,this.pipe="colorMask",t!=null&&t.mask&&this.init(t.mask)}init(t){this.mask=t}destroy(){}static test(t){return typeof t=="number"}}Wr.extension=L.MaskEffect;class Yr{constructor(t){this.priority=0,this.pipe="stencilMask",t!=null&&t.mask&&this.init(t.mask)}init(t){this.mask=t,this.mask.includeInBuild=!1,this.mask.measurable=!1}reset(){this.mask.measurable=!0,this.mask.includeInBuild=!0,this.mask=null}addBounds(t,e){Ur(this.mask,t,e)}addLocalBounds(t,e){$r(this.mask,t,e)}containsPoint(t,e){const i=this.mask;return e(i,t)}destroy(){this.reset()}static test(t){return t instanceof ft}}Yr.extension=L.MaskEffect;const qo={createCanvas:(s,t)=>{const e=document.createElement("canvas");return e.width=s,e.height=t,e},createImage:()=>new Image,getCanvasRenderingContext2D:()=>CanvasRenderingContext2D,getWebGLRenderingContext:()=>WebGLRenderingContext,getNavigator:()=>navigator,getBaseUrl:()=>document.baseURI??window.location.href,getFontFaceSet:()=>document.fonts,fetch:(s,t)=>fetch(s,t),parseXML:s=>new DOMParser().parseFromString(s,"text/xml")};let Pi=qo;const et={get(){return Pi},set(s){Pi=s}};class Xr extends ht{constructor(t){t.resource||(t.resource=et.get().createCanvas()),t.width||(t.width=t.resource.width,t.autoDensity||(t.width/=t.resolution)),t.height||(t.height=t.resource.height,t.autoDensity||(t.height/=t.resolution)),super(t),this.uploadMethodId="image",this.autoDensity=t.autoDensity,this.resizeCanvas(),this.transparent=!!t.transparent}resizeCanvas(){this.autoDensity&&"style"in this.resource&&(this.resource.style.width=`${this.width}px`,this.resource.style.height=`${this.height}px`),(this.resource.width!==this.pixelWidth||this.resource.height!==this.pixelHeight)&&(this.resource.width=this.pixelWidth,this.resource.height=this.pixelHeight)}resize(t=this.width,e=this.height,i=this._resolution){const r=super.resize(t,e,i);return r&&this.resizeCanvas(),r}static test(t){return globalThis.HTMLCanvasElement&&t instanceof HTMLCanvasElement||globalThis.OffscreenCanvas&&t instanceof OffscreenCanvas}get context2D(){return this._context2D||(this._context2D=this.resource.getContext("2d"))}}Xr.extension=L.TextureSource;class $e extends ht{constructor(t){super(t),this.uploadMethodId="image",this.autoGarbageCollect=!0}static test(t){return globalThis.HTMLImageElement&&t instanceof HTMLImageElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap||globalThis.VideoFrame&&t instanceof VideoFrame}}$e.extension=L.TextureSource;var vs=(s=>(s[s.INTERACTION=50]="INTERACTION",s[s.HIGH=25]="HIGH",s[s.NORMAL=0]="NORMAL",s[s.LOW=-25]="LOW",s[s.UTILITY=-50]="UTILITY",s))(vs||{});class ns{constructor(t,e=null,i=0,r=!1){this.next=null,this.previous=null,this._destroyed=!1,this._fn=t,this._context=e,this.priority=i,this._once=r}match(t,e=null){return this._fn===t&&this._context===e}emit(t){this._fn&&(this._context?this._fn.call(this._context,t):this._fn(t));const e=this.next;return this._once&&this.destroy(!0),this._destroyed&&(this.next=null),e}connect(t){this.previous=t,t.next&&(t.next.previous=this),this.next=t.next,t.next=this}destroy(t=!1){this._destroyed=!0,this._fn=null,this._context=null,this.previous&&(this.previous.next=this.next),this.next&&(this.next.previous=this.previous);const e=this.next;return this.next=t?null:e,this.previous=null,e}}const jr=class tt{constructor(){this.autoStart=!1,this.deltaTime=1,this.lastTime=-1,this.speed=1,this.started=!1,this._requestId=null,this._maxElapsedMS=100,this._minElapsedMS=0,this._protected=!1,this._lastFrame=-1,this._head=new ns(null,null,1/0),this.deltaMS=1/tt.targetFPMS,this.elapsedMS=1/tt.targetFPMS,this._tick=t=>{this._requestId=null,this.started&&(this.update(t),this.started&&this._requestId===null&&this._head.next&&(this._requestId=requestAnimationFrame(this._tick)))}}_requestIfNeeded(){this._requestId===null&&this._head.next&&(this.lastTime=performance.now(),this._lastFrame=this.lastTime,this._requestId=requestAnimationFrame(this._tick))}_cancelIfNeeded(){this._requestId!==null&&(cancelAnimationFrame(this._requestId),this._requestId=null)}_startIfPossible(){this.started?this._requestIfNeeded():this.autoStart&&this.start()}add(t,e,i=vs.NORMAL){return this._addListener(new ns(t,e,i))}addOnce(t,e,i=vs.NORMAL){return this._addListener(new ns(t,e,i,!0))}_addListener(t){let e=this._head.next,i=this._head;if(!e)t.connect(i);else{for(;e;){if(t.priority>e.priority){t.connect(i);break}i=e,e=e.next}t.previous||t.connect(i)}return this._startIfPossible(),this}remove(t,e){let i=this._head.next;for(;i;)i.match(t,e)?i=i.destroy():i=i.next;return this._head.next||this._cancelIfNeeded(),this}get count(){if(!this._head)return 0;let t=0,e=this._head;for(;e=e.next;)t++;return t}start(){this.started||(this.started=!0,this._requestIfNeeded())}stop(){this.started&&(this.started=!1,this._cancelIfNeeded())}destroy(){if(!this._protected){this.stop();let t=this._head.next;for(;t;)t=t.destroy(!0);this._head.destroy(),this._head=null}}update(t=performance.now()){let e;if(t>this.lastTime){if(e=this.elapsedMS=t-this.lastTime,e>this._maxElapsedMS&&(e=this._maxElapsedMS),e*=this.speed,this._minElapsedMS){const n=t-this._lastFrame|0;if(n<this._minElapsedMS)return;this._lastFrame=t-n%this._minElapsedMS}this.deltaMS=e,this.deltaTime=this.deltaMS*tt.targetFPMS;const i=this._head;let r=i.next;for(;r;)r=r.emit(this);i.next||this._cancelIfNeeded()}else this.deltaTime=this.deltaMS=this.elapsedMS=0;this.lastTime=t}get FPS(){return 1e3/this.elapsedMS}get minFPS(){return 1e3/this._maxElapsedMS}set minFPS(t){const e=Math.min(this.maxFPS,t),i=Math.min(Math.max(0,e)/1e3,tt.targetFPMS);this._maxElapsedMS=1/i}get maxFPS(){return this._minElapsedMS?Math.round(1e3/this._minElapsedMS):0}set maxFPS(t){if(t===0)this._minElapsedMS=0;else{const e=Math.max(this.minFPS,t);this._minElapsedMS=1/(e/1e3)}}static get shared(){if(!tt._shared){const t=tt._shared=new tt;t.autoStart=!0,t._protected=!0}return tt._shared}static get system(){if(!tt._system){const t=tt._system=new tt;t.autoStart=!0,t._protected=!0}return tt._system}};jr.targetFPMS=.06;let ke=jr,os;async function Zo(){return os??(os=(async()=>{var o;const t=et.get().createCanvas(1,1).getContext("webgl");if(!t)return"premultiply-alpha-on-upload";const e=await new Promise(a=>{const h=document.createElement("video");h.onloadeddata=()=>a(h),h.onerror=()=>a(null),h.autoplay=!1,h.crossOrigin="anonymous",h.preload="auto",h.src="data:video/webm;base64,GkXfo59ChoEBQveBAULygQRC84EIQoKEd2VibUKHgQJChYECGFOAZwEAAAAAAAHTEU2bdLpNu4tTq4QVSalmU6yBoU27i1OrhBZUrmtTrIHGTbuMU6uEElTDZ1OsggEXTbuMU6uEHFO7a1OsggG97AEAAAAAAABZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVSalmoCrXsYMPQkBNgIRMYXZmV0GETGF2ZkSJiEBEAAAAAAAAFlSua8yuAQAAAAAAAEPXgQFzxYgAAAAAAAAAAZyBACK1nIN1bmSIgQCGhVZfVlA5g4EBI+ODhAJiWgDglLCBArqBApqBAlPAgQFVsIRVuYEBElTDZ9Vzc9JjwItjxYgAAAAAAAAAAWfInEWjh0VOQ09ERVJEh49MYXZjIGxpYnZweC12cDlnyKJFo4hEVVJBVElPTkSHlDAwOjAwOjAwLjA0MDAwMDAwMAAAH0O2dcfngQCgwqGggQAAAIJJg0IAABAAFgA4JBwYSgAAICAAEb///4r+AAB1oZ2mm+6BAaWWgkmDQgAAEAAWADgkHBhKAAAgIABIQBxTu2uRu4+zgQC3iveBAfGCAXHwgQM=",h.load()});if(!e)return"premultiply-alpha-on-upload";const i=t.createTexture();t.bindTexture(t.TEXTURE_2D,i);const r=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,r),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,i,0),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),t.pixelStorei(t.UNPACK_COLORSPACE_CONVERSION_WEBGL,t.NONE),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e);const n=new Uint8Array(4);return t.readPixels(0,0,1,1,t.RGBA,t.UNSIGNED_BYTE,n),t.deleteFramebuffer(r),t.deleteTexture(i),(o=t.getExtension("WEBGL_lose_context"))==null||o.loseContext(),n[0]<=n[3]?"premultiplied-alpha":"premultiply-alpha-on-upload"})()),os}const We=class qr extends ht{constructor(t){super(t),this.isReady=!1,this.uploadMethodId="video",t={...qr.defaultOptions,...t},this._autoUpdate=!0,this._isConnectedToTicker=!1,this._updateFPS=t.updateFPS||0,this._msToNextUpdate=0,this.autoPlay=t.autoPlay!==!1,this.alphaMode=t.alphaMode??"premultiply-alpha-on-upload",this._videoFrameRequestCallback=this._videoFrameRequestCallback.bind(this),this._videoFrameRequestCallbackHandle=null,this._load=null,this._resolve=null,this._reject=null,this._onCanPlay=this._onCanPlay.bind(this),this._onCanPlayThrough=this._onCanPlayThrough.bind(this),this._onError=this._onError.bind(this),this._onPlayStart=this._onPlayStart.bind(this),this._onPlayStop=this._onPlayStop.bind(this),this._onSeeked=this._onSeeked.bind(this),t.autoLoad!==!1&&this.load()}updateFrame(){if(!this.destroyed){if(this._updateFPS){const t=ke.shared.elapsedMS*this.resource.playbackRate;this._msToNextUpdate=Math.floor(this._msToNextUpdate-t)}(!this._updateFPS||this._msToNextUpdate<=0)&&(this._msToNextUpdate=this._updateFPS?Math.floor(1e3/this._updateFPS):0),this.isValid&&this.update()}}_videoFrameRequestCallback(){this.updateFrame(),this.destroyed?this._videoFrameRequestCallbackHandle=null:this._videoFrameRequestCallbackHandle=this.resource.requestVideoFrameCallback(this._videoFrameRequestCallback)}get isValid(){return!!this.resource.videoWidth&&!!this.resource.videoHeight}async load(){if(this._load)return this._load;const t=this.resource,e=this.options;return(t.readyState===t.HAVE_ENOUGH_DATA||t.readyState===t.HAVE_FUTURE_DATA)&&t.width&&t.height&&(t.complete=!0),t.addEventListener("play",this._onPlayStart),t.addEventListener("pause",this._onPlayStop),t.addEventListener("seeked",this._onSeeked),this._isSourceReady()?this._mediaReady():(e.preload||t.addEventListener("canplay",this._onCanPlay),t.addEventListener("canplaythrough",this._onCanPlayThrough),t.addEventListener("error",this._onError,!0)),this.alphaMode=await Zo(),this._load=new Promise((i,r)=>{this.isValid?i(this):(this._resolve=i,this._reject=r,e.preloadTimeoutMs!==void 0&&(this._preloadTimeout=setTimeout(()=>{this._onError(new ErrorEvent(`Preload exceeded timeout of ${e.preloadTimeoutMs}ms`))})),t.load())}),this._load}_onError(t){this.resource.removeEventListener("error",this._onError,!0),this.emit("error",t),this._reject&&(this._reject(t),this._reject=null,this._resolve=null)}_isSourcePlaying(){const t=this.resource;return!t.paused&&!t.ended}_isSourceReady(){return this.resource.readyState>2}_onPlayStart(){this.isValid||this._mediaReady(),this._configureAutoUpdate()}_onPlayStop(){this._configureAutoUpdate()}_onSeeked(){this._autoUpdate&&!this._isSourcePlaying()&&(this._msToNextUpdate=0,this.updateFrame(),this._msToNextUpdate=0)}_onCanPlay(){this.resource.removeEventListener("canplay",this._onCanPlay),this._mediaReady()}_onCanPlayThrough(){this.resource.removeEventListener("canplaythrough",this._onCanPlay),this._preloadTimeout&&(clearTimeout(this._preloadTimeout),this._preloadTimeout=void 0),this._mediaReady()}_mediaReady(){const t=this.resource;this.isValid&&(this.isReady=!0,this.resize(t.videoWidth,t.videoHeight)),this._msToNextUpdate=0,this.updateFrame(),this._msToNextUpdate=0,this._resolve&&(this._resolve(this),this._resolve=null,this._reject=null),this._isSourcePlaying()?this._onPlayStart():this.autoPlay&&this.resource.play()}destroy(){this._configureAutoUpdate();const t=this.resource;t&&(t.removeEventListener("play",this._onPlayStart),t.removeEventListener("pause",this._onPlayStop),t.removeEventListener("seeked",this._onSeeked),t.removeEventListener("canplay",this._onCanPlay),t.removeEventListener("canplaythrough",this._onCanPlayThrough),t.removeEventListener("error",this._onError,!0),t.pause(),t.src="",t.load()),super.destroy()}get autoUpdate(){return this._autoUpdate}set autoUpdate(t){t!==this._autoUpdate&&(this._autoUpdate=t,this._configureAutoUpdate())}get updateFPS(){return this._updateFPS}set updateFPS(t){t!==this._updateFPS&&(this._updateFPS=t,this._configureAutoUpdate())}_configureAutoUpdate(){this._autoUpdate&&this._isSourcePlaying()?!this._updateFPS&&this.resource.requestVideoFrameCallback?(this._isConnectedToTicker&&(ke.shared.remove(this.updateFrame,this),this._isConnectedToTicker=!1,this._msToNextUpdate=0),this._videoFrameRequestCallbackHandle===null&&(this._videoFrameRequestCallbackHandle=this.resource.requestVideoFrameCallback(this._videoFrameRequestCallback))):(this._videoFrameRequestCallbackHandle!==null&&(this.resource.cancelVideoFrameCallback(this._videoFrameRequestCallbackHandle),this._videoFrameRequestCallbackHandle=null),this._isConnectedToTicker||(ke.shared.add(this.updateFrame,this),this._isConnectedToTicker=!0,this._msToNextUpdate=0)):(this._videoFrameRequestCallbackHandle!==null&&(this.resource.cancelVideoFrameCallback(this._videoFrameRequestCallbackHandle),this._videoFrameRequestCallbackHandle=null),this._isConnectedToTicker&&(ke.shared.remove(this.updateFrame,this),this._isConnectedToTicker=!1,this._msToNextUpdate=0))}static test(t){return globalThis.HTMLVideoElement&&t instanceof HTMLVideoElement}};We.extension=L.TextureSource;We.defaultOptions={...ht.defaultOptions,autoLoad:!0,autoPlay:!0,updateFPS:0,crossorigin:!0,loop:!1,muted:!0,playsinline:!0,preload:!1};We.MIME_TYPES={ogv:"video/ogg",mov:"video/quicktime",m4v:"video/mp4"};let Ko=We;const zt=(s,t,e=!1)=>(Array.isArray(s)||(s=[s]),t?s.map(i=>typeof i=="string"||e?t(i):i):s);class Qo{constructor(){this._parsers=[],this._cache=new Map,this._cacheMap=new Map}reset(){this._cacheMap.clear(),this._cache.clear()}has(t){return this._cache.has(t)}get(t){const e=this._cache.get(t);return e||Q(`[Assets] Asset id ${t} was not found in the Cache`),e}set(t,e){const i=zt(t);let r;for(let h=0;h<this.parsers.length;h++){const l=this.parsers[h];if(l.test(e)){r=l.getCacheableAssets(i,e);break}}const n=new Map(Object.entries(r||{}));r||i.forEach(h=>{n.set(h,e)});const o=[...n.keys()],a={cacheKeys:o,keys:i};i.forEach(h=>{this._cacheMap.set(h,a)}),o.forEach(h=>{const l=r?r[h]:e;this._cache.has(h)&&this._cache.get(h)!==l&&Q("[Cache] already has key:",h),this._cache.set(h,n.get(h))})}remove(t){if(!this._cacheMap.has(t)){Q(`[Assets] Asset id ${t} was not found in the Cache`);return}const e=this._cacheMap.get(t);e.cacheKeys.forEach(r=>{this._cache.delete(r)}),e.keys.forEach(r=>{this._cacheMap.delete(r)})}get parsers(){return this._parsers}}const Ht=new Qo,Ps=[];rt.handleByList(L.TextureSource,Ps);function Zr(s={}){const t=s&&s.resource,e=t?s.resource:s,i=t?s:{resource:s};for(let r=0;r<Ps.length;r++){const n=Ps[r];if(n.test(e))return new n(i)}throw new Error(`Could not find a source type for resource: ${i.resource}`)}function Jo(s={},t=!1){const e=s&&s.resource,i=e?s.resource:s,r=e?s:{resource:s};if(!t&&Ht.has(i))return Ht.get(i);const n=new D({source:Zr(r)});return n.on("destroy",()=>{Ht.has(i)&&Ht.remove(i)}),t||Ht.set(i,n),n}function ta(s,t=!1){return typeof s=="string"?Ht.get(s):s instanceof ht?new D({source:s}):Jo(s,t)}D.from=ta;ht.from=Zr;rt.add(Vr,Wr,Yr,Ko,$e,Xr,$s);var Kr=(s=>(s[s.Low=0]="Low",s[s.Normal=1]="Normal",s[s.High=2]="High",s))(Kr||{});function nt(s){if(typeof s!="string")throw new TypeError(`Path must be a string. Received ${JSON.stringify(s)}`)}function Qt(s){return s.split("?")[0].split("#")[0]}function ea(s){return s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function sa(s,t,e){return s.replace(new RegExp(ea(t),"g"),e)}function ia(s,t){let e="",i=0,r=-1,n=0,o=-1;for(let a=0;a<=s.length;++a){if(a<s.length)o=s.charCodeAt(a);else{if(o===47)break;o=47}if(o===47){if(!(r===a-1||n===1))if(r!==a-1&&n===2){if(e.length<2||i!==2||e.charCodeAt(e.length-1)!==46||e.charCodeAt(e.length-2)!==46){if(e.length>2){const h=e.lastIndexOf("/");if(h!==e.length-1){h===-1?(e="",i=0):(e=e.slice(0,h),i=e.length-1-e.lastIndexOf("/")),r=a,n=0;continue}}else if(e.length===2||e.length===1){e="",i=0,r=a,n=0;continue}}}else e.length>0?e+=`/${s.slice(r+1,a)}`:e=s.slice(r+1,a),i=a-r-1;r=a,n=0}else o===46&&n!==-1?++n:n=-1}return e}const fe={toPosix(s){return sa(s,"\\","/")},isUrl(s){return/^https?:/.test(this.toPosix(s))},isDataUrl(s){return/^data:([a-z]+\/[a-z0-9-+.]+(;[a-z0-9-.!#$%*+.{}|~`]+=[a-z0-9-.!#$%*+.{}()_|~`]+)*)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s<>]*?)$/i.test(s)},isBlobUrl(s){return s.startsWith("blob:")},hasProtocol(s){return/^[^/:]+:/.test(this.toPosix(s))},getProtocol(s){nt(s),s=this.toPosix(s);const t=/^file:\/\/\//.exec(s);if(t)return t[0];const e=/^[^/:]+:\/{0,2}/.exec(s);return e?e[0]:""},toAbsolute(s,t,e){if(nt(s),this.isDataUrl(s)||this.isBlobUrl(s))return s;const i=Qt(this.toPosix(t??et.get().getBaseUrl())),r=Qt(this.toPosix(e??this.rootname(i)));return s=this.toPosix(s),s.startsWith("/")?fe.join(r,s.slice(1)):this.isAbsolute(s)?s:this.join(i,s)},normalize(s){if(nt(s),s.length===0)return".";if(this.isDataUrl(s)||this.isBlobUrl(s))return s;s=this.toPosix(s);let t="";const e=s.startsWith("/");this.hasProtocol(s)&&(t=this.rootname(s),s=s.slice(t.length));const i=s.endsWith("/");return s=ia(s),s.length>0&&i&&(s+="/"),e?`/${s}`:t+s},isAbsolute(s){return nt(s),s=this.toPosix(s),this.hasProtocol(s)?!0:s.startsWith("/")},join(...s){if(s.length===0)return".";let t;for(let e=0;e<s.length;++e){const i=s[e];if(nt(i),i.length>0)if(t===void 0)t=i;else{const r=s[e-1]??"";this.joinExtensions.includes(this.extname(r).toLowerCase())?t+=`/../${i}`:t+=`/${i}`}}return t===void 0?".":this.normalize(t)},dirname(s){if(nt(s),s.length===0)return".";s=this.toPosix(s);let t=s.charCodeAt(0);const e=t===47;let i=-1,r=!0;const n=this.getProtocol(s),o=s;s=s.slice(n.length);for(let a=s.length-1;a>=1;--a)if(t=s.charCodeAt(a),t===47){if(!r){i=a;break}}else r=!1;return i===-1?e?"/":this.isUrl(o)?n+s:n:e&&i===1?"//":n+s.slice(0,i)},rootname(s){nt(s),s=this.toPosix(s);let t="";if(s.startsWith("/")?t="/":t=this.getProtocol(s),this.isUrl(s)){const e=s.indexOf("/",t.length);e!==-1?t=s.slice(0,e):t=s,t.endsWith("/")||(t+="/")}return t},basename(s,t){nt(s),t&&nt(t),s=Qt(this.toPosix(s));let e=0,i=-1,r=!0,n;if(t!==void 0&&t.length>0&&t.length<=s.length){if(t.length===s.length&&t===s)return"";let o=t.length-1,a=-1;for(n=s.length-1;n>=0;--n){const h=s.charCodeAt(n);if(h===47){if(!r){e=n+1;break}}else a===-1&&(r=!1,a=n+1),o>=0&&(h===t.charCodeAt(o)?--o===-1&&(i=n):(o=-1,i=a))}return e===i?i=a:i===-1&&(i=s.length),s.slice(e,i)}for(n=s.length-1;n>=0;--n)if(s.charCodeAt(n)===47){if(!r){e=n+1;break}}else i===-1&&(r=!1,i=n+1);return i===-1?"":s.slice(e,i)},extname(s){nt(s),s=Qt(this.toPosix(s));let t=-1,e=0,i=-1,r=!0,n=0;for(let o=s.length-1;o>=0;--o){const a=s.charCodeAt(o);if(a===47){if(!r){e=o+1;break}continue}i===-1&&(r=!1,i=o+1),a===46?t===-1?t=o:n!==1&&(n=1):t!==-1&&(n=-1)}return t===-1||i===-1||n===0||n===1&&t===i-1&&t===e+1?"":s.slice(t,i)},parse(s){nt(s);const t={root:"",dir:"",base:"",ext:"",name:""};if(s.length===0)return t;s=Qt(this.toPosix(s));let e=s.charCodeAt(0);const i=this.isAbsolute(s);let r;t.root=this.rootname(s),i||this.hasProtocol(s)?r=1:r=0;let n=-1,o=0,a=-1,h=!0,l=s.length-1,c=0;for(;l>=r;--l){if(e=s.charCodeAt(l),e===47){if(!h){o=l+1;break}continue}a===-1&&(h=!1,a=l+1),e===46?n===-1?n=l:c!==1&&(c=1):n!==-1&&(c=-1)}return n===-1||a===-1||c===0||c===1&&n===a-1&&n===o+1?a!==-1&&(o===0&&i?t.base=t.name=s.slice(1,a):t.base=t.name=s.slice(o,a)):(o===0&&i?(t.name=s.slice(1,n),t.base=s.slice(1,a)):(t.name=s.slice(o,n),t.base=s.slice(o,a)),t.ext=s.slice(n,a)),t.dir=this.dirname(s),t},sep:"/",delimiter:":",joinExtensions:[".html"]};function Qr(s,t,e,i,r){const n=t[e];for(let o=0;o<n.length;o++){const a=n[o];e<t.length-1?Qr(s.replace(i[e],a),t,e+1,i,r):r.push(s.replace(i[e],a))}}function ra(s){const t=/\{(.*?)\}/g,e=s.match(t),i=[];if(e){const r=[];e.forEach(n=>{const o=n.substring(1,n.length-1).split(",");r.push(o)}),Qr(s,r,0,e,i)}else i.push(s);return i}const Mi=s=>!Array.isArray(s);class Jr{constructor(){this._defaultBundleIdentifierOptions={connector:"-",createBundleAssetId:(t,e)=>`${t}${this._bundleIdConnector}${e}`,extractAssetIdFromBundle:(t,e)=>e.replace(`${t}${this._bundleIdConnector}`,"")},this._bundleIdConnector=this._defaultBundleIdentifierOptions.connector,this._createBundleAssetId=this._defaultBundleIdentifierOptions.createBundleAssetId,this._extractAssetIdFromBundle=this._defaultBundleIdentifierOptions.extractAssetIdFromBundle,this._assetMap={},this._preferredOrder=[],this._parsers=[],this._resolverHash={},this._bundles={}}setBundleIdentifier(t){if(this._bundleIdConnector=t.connector??this._bundleIdConnector,this._createBundleAssetId=t.createBundleAssetId??this._createBundleAssetId,this._extractAssetIdFromBundle=t.extractAssetIdFromBundle??this._extractAssetIdFromBundle,this._extractAssetIdFromBundle("foo",this._createBundleAssetId("foo","bar"))!=="bar")throw new Error("[Resolver] GenerateBundleAssetId are not working correctly")}prefer(...t){t.forEach(e=>{this._preferredOrder.push(e),e.priority||(e.priority=Object.keys(e.params))}),this._resolverHash={}}set basePath(t){this._basePath=t}get basePath(){return this._basePath}set rootPath(t){this._rootPath=t}get rootPath(){return this._rootPath}get parsers(){return this._parsers}reset(){this.setBundleIdentifier(this._defaultBundleIdentifierOptions),this._assetMap={},this._preferredOrder=[],this._resolverHash={},this._rootPath=null,this._basePath=null,this._manifest=null,this._bundles={},this._defaultSearchParams=null}setDefaultSearchParams(t){if(typeof t=="string")this._defaultSearchParams=t;else{const e=t;this._defaultSearchParams=Object.keys(e).map(i=>`${encodeURIComponent(i)}=${encodeURIComponent(e[i])}`).join("&")}}getAlias(t){const{alias:e,src:i}=t;return zt(e||i,n=>typeof n=="string"?n:Array.isArray(n)?n.map(o=>(o==null?void 0:o.src)??o):n!=null&&n.src?n.src:n,!0)}addManifest(t){this._manifest&&Q("[Resolver] Manifest already exists, this will be overwritten"),this._manifest=t,t.bundles.forEach(e=>{this.addBundle(e.name,e.assets)})}addBundle(t,e){const i=[];let r=e;Array.isArray(e)||(r=Object.entries(e).map(([n,o])=>typeof o=="string"||Array.isArray(o)?{alias:n,src:o}:{alias:n,...o})),r.forEach(n=>{const o=n.src,a=n.alias;let h;if(typeof a=="string"){const l=this._createBundleAssetId(t,a);i.push(l),h=[a,l]}else{const l=a.map(c=>this._createBundleAssetId(t,c));i.push(...l),h=[...a,...l]}this.add({...n,alias:h,src:o})}),this._bundles[t]=i}add(t){const e=[];Array.isArray(t)?e.push(...t):e.push(t);let i;i=n=>{this.hasKey(n)&&Q(`[Resolver] already has key: ${n} overwriting`)},zt(e).forEach(n=>{const{src:o}=n;let{data:a,format:h,loadParser:l,parser:c}=n;const u=zt(o).map(m=>typeof m=="string"?ra(m):Array.isArray(m)?m:[m]),p=this.getAlias(n);Array.isArray(p)?p.forEach(i):i(p);const d=[];u.forEach(m=>{m.forEach(g=>{let f={};if(typeof g!="object"){f.src=g;for(let x=0;x<this._parsers.length;x++){const y=this._parsers[x];if(y.test(g)){f=y.parse(g);break}}}else a=g.data??a,h=g.format??h,(g.loadParser||g.parser)&&(l=g.loadParser??l,c=g.parser??c),f={...f,...g};if(!p)throw new Error(`[Resolver] alias is undefined for this asset: ${f.src}`);f=this._buildResolvedAsset(f,{aliases:p,data:a,format:h,loadParser:l,parser:c}),d.push(f)})}),p.forEach(m=>{this._assetMap[m]=d})})}resolveBundle(t){const e=Mi(t);t=zt(t);const i={};return t.forEach(r=>{const n=this._bundles[r];if(n){const o=this.resolve(n),a={};for(const h in o){const l=o[h];a[this._extractAssetIdFromBundle(r,h)]=l}i[r]=a}}),e?i[t[0]]:i}resolveUrl(t){const e=this.resolve(t);if(typeof t!="string"){const i={};for(const r in e)i[r]=e[r].src;return i}return e.src}resolve(t){const e=Mi(t);t=zt(t);const i={};return t.forEach(r=>{if(!this._resolverHash[r])if(this._assetMap[r]){let n=this._assetMap[r];const o=this._getPreferredOrder(n);o==null||o.priority.forEach(a=>{o.params[a].forEach(h=>{const l=n.filter(c=>c[a]?c[a]===h:!1);l.length&&(n=l)})}),this._resolverHash[r]=n[0]}else this._resolverHash[r]=this._buildResolvedAsset({alias:[r],src:r},{});i[r]=this._resolverHash[r]}),e?i[t[0]]:i}hasKey(t){return!!this._assetMap[t]}hasBundle(t){return!!this._bundles[t]}_getPreferredOrder(t){for(let e=0;e<t.length;e++){const i=t[e],r=this._preferredOrder.find(n=>n.params.format.includes(i.format));if(r)return r}return this._preferredOrder[0]}_appendDefaultSearchParams(t){if(!this._defaultSearchParams)return t;const e=/\?/.test(t)?"&":"?";return`${t}${e}${this._defaultSearchParams}`}_buildResolvedAsset(t,e){const{aliases:i,data:r,loadParser:n,parser:o,format:a}=e;return(this._basePath||this._rootPath)&&(t.src=fe.toAbsolute(t.src,this._basePath,this._rootPath)),t.alias=i??t.alias??[t.src],t.src=this._appendDefaultSearchParams(t.src),t.data={...r||{},...t.data},t.loadParser=n??t.loadParser,t.parser=o??t.parser,t.format=a??t.format??na(t.src),t}}Jr.RETINA_PREFIX=/@([0-9\.]+)x/;function na(s){return s.split(".").pop().split("?").shift().split("#").shift()}const Ci=(s,t)=>{const e=t.split("?")[1];return e&&(s+=`?${e}`),s},tn=class ne{constructor(t,e){this.linkedSheets=[];let i=t;(t==null?void 0:t.source)instanceof ht&&(i={texture:t,data:e});const{texture:r,data:n,cachePrefix:o=""}=i;this.cachePrefix=o,this._texture=r instanceof D?r:null,this.textureSource=r.source,this.textures={},this.animations={},this.data=n;const a=parseFloat(n.meta.scale);a?(this.resolution=a,r.source.resolution=this.resolution):this.resolution=r.source._resolution,this._frames=this.data.frames,this._frameKeys=Object.keys(this._frames),this._batchIndex=0,this._callback=null}parse(){return new Promise(t=>{this._callback=t,this._batchIndex=0,this._frameKeys.length<=ne.BATCH_SIZE?(this._processFrames(0),this._processAnimations(),this._parseComplete()):this._nextBatch()})}_processFrames(t){let e=t;const i=ne.BATCH_SIZE;for(;e-t<i&&e<this._frameKeys.length;){const r=this._frameKeys[e],n=this._frames[r],o=n.frame;if(o){let a=null,h=null;const l=n.trimmed!==!1&&n.sourceSize?n.sourceSize:n.frame,c=new W(0,0,Math.floor(l.w)/this.resolution,Math.floor(l.h)/this.resolution);n.rotated?a=new W(Math.floor(o.x)/this.resolution,Math.floor(o.y)/this.resolution,Math.floor(o.h)/this.resolution,Math.floor(o.w)/this.resolution):a=new W(Math.floor(o.x)/this.resolution,Math.floor(o.y)/this.resolution,Math.floor(o.w)/this.resolution,Math.floor(o.h)/this.resolution),n.trimmed!==!1&&n.spriteSourceSize&&(h=new W(Math.floor(n.spriteSourceSize.x)/this.resolution,Math.floor(n.spriteSourceSize.y)/this.resolution,Math.floor(o.w)/this.resolution,Math.floor(o.h)/this.resolution)),this.textures[r]=new D({source:this.textureSource,frame:a,orig:c,trim:h,rotate:n.rotated?2:0,defaultAnchor:n.anchor,defaultBorders:n.borders,label:r.toString()})}e++}}_processAnimations(){const t=this.data.animations||{};for(const e in t){this.animations[e]=[];for(let i=0;i<t[e].length;i++){const r=t[e][i];this.animations[e].push(this.textures[r])}}}_parseComplete(){const t=this._callback;this._callback=null,this._batchIndex=0,t.call(this,this.textures)}_nextBatch(){this._processFrames(this._batchIndex*ne.BATCH_SIZE),this._batchIndex++,setTimeout(()=>{this._batchIndex*ne.BATCH_SIZE<this._frameKeys.length?this._nextBatch():(this._processAnimations(),this._parseComplete())},0)}destroy(t=!1){var e;for(const i in this.textures)this.textures[i].destroy();this._frames=null,this._frameKeys=null,this.data=null,this.textures=null,t&&((e=this._texture)==null||e.destroy(),this.textureSource.destroy()),this._texture=null,this.textureSource=null,this.linkedSheets=[]}};tn.BATCH_SIZE=1e3;let Ti=tn;const oa=["jpg","png","jpeg","avif","webp","basis","etc2","bc7","bc6h","bc5","bc4","bc3","bc2","bc1","eac","astc"];function en(s,t,e){const i={};if(s.forEach(r=>{i[r]=t}),Object.keys(t.textures).forEach(r=>{i[`${t.cachePrefix}${r}`]=t.textures[r]}),!e){const r=fe.dirname(s[0]);t.linkedSheets.forEach((n,o)=>{const a=en([`${r}/${t.data.meta.related_multi_packs[o]}`],n,!0);Object.assign(i,a)})}return i}const aa={extension:L.Asset,cache:{test:s=>s instanceof Ti,getCacheableAssets:(s,t)=>en(s,t,!1)},resolver:{extension:{type:L.ResolveParser,name:"resolveSpritesheet"},test:s=>{const e=s.split("?")[0].split("."),i=e.pop(),r=e.pop();return i==="json"&&oa.includes(r)},parse:s=>{var e;const t=s.split(".");return{resolution:parseFloat(((e=Jr.RETINA_PREFIX.exec(s))==null?void 0:e[1])??"1"),format:t[t.length-2],src:s}}},loader:{name:"spritesheetLoader",id:"spritesheet",extension:{type:L.LoadParser,priority:Kr.Normal,name:"spritesheetLoader"},async testParse(s,t){return fe.extname(t.src).toLowerCase()===".json"&&!!s.frames},async parse(s,t,e){var u,p;const{texture:i,imageFilename:r,textureOptions:n,cachePrefix:o}=(t==null?void 0:t.data)??{};let a=fe.dirname(t.src);a&&a.lastIndexOf("/")!==a.length-1&&(a+="/");let h;if(i instanceof D)h=i;else{const d=Ci(a+(r??s.meta.image),t.src);h=(await e.load([{src:d,data:n}]))[d]}const l=new Ti({texture:h.source,data:s,cachePrefix:o});await l.parse();const c=(u=s==null?void 0:s.meta)==null?void 0:u.related_multi_packs;if(Array.isArray(c)){const d=[];for(const g of c){if(typeof g!="string")continue;let f=a+g;(p=t.data)!=null&&p.ignoreMultiPack||(f=Ci(f,t.src),d.push(e.load({src:f,data:{textureOptions:n,ignoreMultiPack:!0}})))}const m=await Promise.all(d);l.linkedSheets=m,m.forEach(g=>{g.linkedSheets=[l].concat(l.linkedSheets.filter(f=>f!==g))})}return l},async unload(s,t,e){await e.unload(s.textureSource._sourceOrigin),s.destroy(!1)}}};rt.add(aa);const as=Object.create(null),Ai=Object.create(null);function Ws(s,t){let e=Ai[s];return e===void 0&&(as[t]===void 0&&(as[t]=1),Ai[s]=e=as[t]++),e}let Gt;function sn(){return(!Gt||Gt!=null&&Gt.isContextLost())&&(Gt=et.get().createCanvas().getContext("webgl",{})),Gt}let Ee;function ha(){if(!Ee){Ee="mediump";const s=sn();s&&s.getShaderPrecisionFormat&&(Ee=s.getShaderPrecisionFormat(s.FRAGMENT_SHADER,s.HIGH_FLOAT).precision?"highp":"mediump")}return Ee}function la(s,t,e){return t?s:e?(s=s.replace("out vec4 finalColor;",""),` + + #ifdef GL_ES // This checks if it is WebGL1 + #define in varying + #define finalColor gl_FragColor + #define texture texture2D + #endif + ${s} + `):` + + #ifdef GL_ES // This checks if it is WebGL1 + #define in attribute + #define out varying + #endif + ${s} + `}function ca(s,t,e){const i=e?t.maxSupportedFragmentPrecision:t.maxSupportedVertexPrecision;if(s.substring(0,9)!=="precision"){let r=e?t.requestedFragmentPrecision:t.requestedVertexPrecision;return r==="highp"&&i!=="highp"&&(r="mediump"),`precision ${r} float; +${s}`}else if(i!=="highp"&&s.substring(0,15)==="precision highp")return s.replace("precision highp","precision mediump");return s}function ua(s,t){return t?`#version 300 es +${s}`:s}const da={},fa={};function pa(s,{name:t="pixi-program"},e=!0){t=t.replace(/\s+/g,"-"),t+=e?"-fragment":"-vertex";const i=e?da:fa;return i[t]?(i[t]++,t+=`-${i[t]}`):i[t]=1,s.indexOf("#define SHADER_NAME")!==-1?s:`${`#define SHADER_NAME ${t}`} +${s}`}function ma(s,t){return t?s.replace("#version 300 es",""):s}const hs={stripVersion:ma,ensurePrecision:ca,addProgramDefines:la,setProgramName:pa,insertVersion:ua},Jt=Object.create(null),rn=class Ms{constructor(t){t={...Ms.defaultOptions,...t};const e=t.fragment.indexOf("#version 300 es")!==-1,i={stripVersion:e,ensurePrecision:{requestedFragmentPrecision:t.preferredFragmentPrecision,requestedVertexPrecision:t.preferredVertexPrecision,maxSupportedVertexPrecision:"highp",maxSupportedFragmentPrecision:ha()},setProgramName:{name:t.name},addProgramDefines:e,insertVersion:e};let r=t.fragment,n=t.vertex;Object.keys(hs).forEach(o=>{const a=i[o];r=hs[o](r,a,!0),n=hs[o](n,a,!1)}),this.fragment=r,this.vertex=n,this.transformFeedbackVaryings=t.transformFeedbackVaryings,this._key=Ws(`${this.vertex}:${this.fragment}`,"gl-program")}destroy(){this.fragment=null,this.vertex=null,this._attributeData=null,this._uniformData=null,this._uniformBlockData=null,this.transformFeedbackVaryings=null,Jt[this._cacheKey]=null}static from(t){const e=`${t.vertex}:${t.fragment}`;return Jt[e]||(Jt[e]=new Ms(t),Jt[e]._cacheKey=e),Jt[e]}};rn.defaultOptions={preferredVertexPrecision:"highp",preferredFragmentPrecision:"mediump"};let nn=rn;const ki={uint8x2:{size:2,stride:2,normalised:!1},uint8x4:{size:4,stride:4,normalised:!1},sint8x2:{size:2,stride:2,normalised:!1},sint8x4:{size:4,stride:4,normalised:!1},unorm8x2:{size:2,stride:2,normalised:!0},unorm8x4:{size:4,stride:4,normalised:!0},snorm8x2:{size:2,stride:2,normalised:!0},snorm8x4:{size:4,stride:4,normalised:!0},uint16x2:{size:2,stride:4,normalised:!1},uint16x4:{size:4,stride:8,normalised:!1},sint16x2:{size:2,stride:4,normalised:!1},sint16x4:{size:4,stride:8,normalised:!1},unorm16x2:{size:2,stride:4,normalised:!0},unorm16x4:{size:4,stride:8,normalised:!0},snorm16x2:{size:2,stride:4,normalised:!0},snorm16x4:{size:4,stride:8,normalised:!0},float16x2:{size:2,stride:4,normalised:!1},float16x4:{size:4,stride:8,normalised:!1},float32:{size:1,stride:4,normalised:!1},float32x2:{size:2,stride:8,normalised:!1},float32x3:{size:3,stride:12,normalised:!1},float32x4:{size:4,stride:16,normalised:!1},uint32:{size:1,stride:4,normalised:!1},uint32x2:{size:2,stride:8,normalised:!1},uint32x3:{size:3,stride:12,normalised:!1},uint32x4:{size:4,stride:16,normalised:!1},sint32:{size:1,stride:4,normalised:!1},sint32x2:{size:2,stride:8,normalised:!1},sint32x3:{size:3,stride:12,normalised:!1},sint32x4:{size:4,stride:16,normalised:!1}};function ga(s){return ki[s]??ki.float32}const xa={f32:"float32","vec2<f32>":"float32x2","vec3<f32>":"float32x3","vec4<f32>":"float32x4",vec2f:"float32x2",vec3f:"float32x3",vec4f:"float32x4",i32:"sint32","vec2<i32>":"sint32x2","vec3<i32>":"sint32x3","vec4<i32>":"sint32x4",u32:"uint32","vec2<u32>":"uint32x2","vec3<u32>":"uint32x3","vec4<u32>":"uint32x4",bool:"uint32","vec2<bool>":"uint32x2","vec3<bool>":"uint32x3","vec4<bool>":"uint32x4"};function ya({source:s,entryPoint:t}){const e={},i=s.indexOf(`fn ${t}`);if(i!==-1){const r=s.indexOf("->",i);if(r!==-1){const n=s.substring(i,r),o=/@location\((\d+)\)\s+([a-zA-Z0-9_]+)\s*:\s*([a-zA-Z0-9_<>]+)(?:,|\s|$)/g;let a;for(;(a=o.exec(n))!==null;){const h=xa[a[3]]??"float32";e[a[2]]={location:parseInt(a[1],10),format:h,stride:ga(h).stride,offset:0,instance:!1,start:0}}}}return e}function ls(s){var u,p;const t=/(^|[^/])@(group|binding)\(\d+\)[^;]+;/g,e=/@group\((\d+)\)/,i=/@binding\((\d+)\)/,r=/var(<[^>]+>)? (\w+)/,n=/:\s*(\w+)/,o=/struct\s+(\w+)\s*{([^}]+)}/g,a=/(\w+)\s*:\s*([\w\<\>]+)/g,h=/struct\s+(\w+)/,l=(u=s.match(t))==null?void 0:u.map(d=>({group:parseInt(d.match(e)[1],10),binding:parseInt(d.match(i)[1],10),name:d.match(r)[2],isUniform:d.match(r)[1]==="<uniform>",type:d.match(n)[1]}));if(!l)return{groups:[],structs:[]};const c=((p=s.match(o))==null?void 0:p.map(d=>{const m=d.match(h)[1],g=d.match(a).reduce((f,x)=>{const[y,_]=x.split(":");return f[y.trim()]=_.trim(),f},{});return g?{name:m,members:g}:null}).filter(({name:d})=>l.some(m=>m.type===d)))??[];return{groups:l,structs:c}}var oe=(s=>(s[s.VERTEX=1]="VERTEX",s[s.FRAGMENT=2]="FRAGMENT",s[s.COMPUTE=4]="COMPUTE",s))(oe||{});function _a({groups:s}){const t=[];for(let e=0;e<s.length;e++){const i=s[e];t[i.group]||(t[i.group]=[]),i.isUniform?t[i.group].push({binding:i.binding,visibility:oe.VERTEX|oe.FRAGMENT,buffer:{type:"uniform"}}):i.type==="sampler"?t[i.group].push({binding:i.binding,visibility:oe.FRAGMENT,sampler:{type:"filtering"}}):i.type==="texture_2d"&&t[i.group].push({binding:i.binding,visibility:oe.FRAGMENT,texture:{sampleType:"float",viewDimension:"2d",multisampled:!1}})}return t}function ba({groups:s}){const t=[];for(let e=0;e<s.length;e++){const i=s[e];t[i.group]||(t[i.group]={}),t[i.group][i.name]=i.binding}return t}function wa(s,t){const e=new Set,i=new Set,r=[...s.structs,...t.structs].filter(o=>e.has(o.name)?!1:(e.add(o.name),!0)),n=[...s.groups,...t.groups].filter(o=>{const a=`${o.name}-${o.binding}`;return i.has(a)?!1:(i.add(a),!0)});return{structs:r,groups:n}}const te=Object.create(null);class Ye{constructor(t){var a,h;this._layoutKey=0,this._attributeLocationsKey=0;const{fragment:e,vertex:i,layout:r,gpuLayout:n,name:o}=t;if(this.name=o,this.fragment=e,this.vertex=i,e.source===i.source){const l=ls(e.source);this.structsAndGroups=l}else{const l=ls(i.source),c=ls(e.source);this.structsAndGroups=wa(l,c)}this.layout=r??ba(this.structsAndGroups),this.gpuLayout=n??_a(this.structsAndGroups),this.autoAssignGlobalUniforms=((a=this.layout[0])==null?void 0:a.globalUniforms)!==void 0,this.autoAssignLocalUniforms=((h=this.layout[1])==null?void 0:h.localUniforms)!==void 0,this._generateProgramKey()}_generateProgramKey(){const{vertex:t,fragment:e}=this,i=t.source+e.source+t.entryPoint+e.entryPoint;this._layoutKey=Ws(i,"program")}get attributeData(){return this._attributeData??(this._attributeData=ya(this.vertex)),this._attributeData}destroy(){this.gpuLayout=null,this.layout=null,this.structsAndGroups=null,this.fragment=null,this.vertex=null,te[this._cacheKey]=null}static from(t){const e=`${t.vertex.source}:${t.fragment.source}:${t.fragment.entryPoint}:${t.vertex.entryPoint}`;return te[e]||(te[e]=new Ye(t),te[e]._cacheKey=e),te[e]}}const on=["f32","i32","vec2<f32>","vec3<f32>","vec4<f32>","mat2x2<f32>","mat3x3<f32>","mat4x4<f32>","mat3x2<f32>","mat4x2<f32>","mat2x3<f32>","mat4x3<f32>","mat2x4<f32>","mat3x4<f32>","vec2<i32>","vec3<i32>","vec4<i32>"],Sa=on.reduce((s,t)=>(s[t]=!0,s),{});function va(s,t){switch(s){case"f32":return 0;case"vec2<f32>":return new Float32Array(2*t);case"vec3<f32>":return new Float32Array(3*t);case"vec4<f32>":return new Float32Array(4*t);case"mat2x2<f32>":return new Float32Array([1,0,0,1]);case"mat3x3<f32>":return new Float32Array([1,0,0,0,1,0,0,0,1]);case"mat4x4<f32>":return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}return null}const an=class hn{constructor(t,e){this._touched=0,this.uid=V("uniform"),this._resourceType="uniformGroup",this._resourceId=V("resource"),this.isUniformGroup=!0,this._dirtyId=0,this.destroyed=!1,e={...hn.defaultOptions,...e},this.uniformStructures=t;const i={};for(const r in t){const n=t[r];if(n.name=r,n.size=n.size??1,!Sa[n.type]){const o=n.type.match(/^array<(\w+(?:<\w+>)?),\s*(\d+)>$/);if(o){const[,a,h]=o;throw new Error(`Uniform type ${n.type} is not supported. Use type: '${a}', size: ${h} instead.`)}throw new Error(`Uniform type ${n.type} is not supported. Supported uniform types are: ${on.join(", ")}`)}n.value??(n.value=va(n.type,n.size)),i[r]=n.value}this.uniforms=i,this._dirtyId=1,this.ubo=e.ubo,this.isStatic=e.isStatic,this._signature=Ws(Object.keys(i).map(r=>`${r}-${t[r].type}`).join("-"),"uniform-group")}update(){this._dirtyId++}};an.defaultOptions={ubo:!1,isStatic:!1};let ln=an;class He{constructor(t){this.resources=Object.create(null),this._dirty=!0;let e=0;for(const i in t){const r=t[i];this.setResource(r,e++)}this._updateKey()}_updateKey(){if(!this._dirty)return;this._dirty=!1;const t=[];let e=0;for(const i in this.resources)t[e++]=this.resources[i]._resourceId;this._key=t.join("|")}setResource(t,e){var r,n;const i=this.resources[e];t!==i&&(i&&((r=t.off)==null||r.call(t,"change",this.onResourceChange,this)),(n=t.on)==null||n.call(t,"change",this.onResourceChange,this),this.resources[e]=t,this._dirty=!0)}getResource(t){return this.resources[t]}_touch(t){const e=this.resources;for(const i in e)e[i]._touched=t}destroy(){var e;const t=this.resources;for(const i in t){const r=t[i];(e=r==null?void 0:r.off)==null||e.call(r,"change",this.onResourceChange,this)}this.resources=null}onResourceChange(t){if(this._dirty=!0,t.destroyed){const e=this.resources;for(const i in e)e[i]===t&&(e[i]=null)}else this._updateKey()}}var Cs=(s=>(s[s.WEBGL=1]="WEBGL",s[s.WEBGPU=2]="WEBGPU",s[s.BOTH=3]="BOTH",s))(Cs||{});class Ys extends pt{constructor(t){super(),this.uid=V("shader"),this._uniformBindMap=Object.create(null),this._ownedBindGroups=[];let{gpuProgram:e,glProgram:i,groups:r,resources:n,compatibleRenderers:o,groupMap:a}=t;this.gpuProgram=e,this.glProgram=i,o===void 0&&(o=0,e&&(o|=Cs.WEBGPU),i&&(o|=Cs.WEBGL)),this.compatibleRenderers=o;const h={};if(!n&&!r&&(n={}),n&&r)throw new Error("[Shader] Cannot have both resources and groups");if(!e&&r&&!a)throw new Error("[Shader] No group map or WebGPU shader provided - consider using resources instead.");if(!e&&r&&a)for(const l in a)for(const c in a[l]){const u=a[l][c];h[u]={group:l,binding:c,name:u}}else if(e&&r&&!a){const l=e.structsAndGroups.groups;a={},l.forEach(c=>{a[c.group]=a[c.group]||{},a[c.group][c.binding]=c.name,h[c.name]=c})}else if(n){r={},a={},e&&e.structsAndGroups.groups.forEach(u=>{a[u.group]=a[u.group]||{},a[u.group][u.binding]=u.name,h[u.name]=u});let l=0;for(const c in n)h[c]||(r[99]||(r[99]=new He,this._ownedBindGroups.push(r[99])),h[c]={group:99,binding:l,name:c},a[99]=a[99]||{},a[99][l]=c,l++);for(const c in n){const u=c;let p=n[c];!p.source&&!p._resourceType&&(p=new ln(p));const d=h[u];d&&(r[d.group]||(r[d.group]=new He,this._ownedBindGroups.push(r[d.group])),r[d.group].setResource(p,d.binding))}}this.groups=r,this._uniformBindMap=a,this.resources=this._buildResourceAccessor(r,h)}addResource(t,e,i){var r,n;(r=this._uniformBindMap)[e]||(r[e]={}),(n=this._uniformBindMap[e])[i]||(n[i]=t),this.groups[e]||(this.groups[e]=new He,this._ownedBindGroups.push(this.groups[e]))}_buildResourceAccessor(t,e){const i={};for(const r in e){const n=e[r];Object.defineProperty(i,n.name,{get(){return t[n.group].getResource(n.binding)},set(o){t[n.group].setResource(o,n.binding)}})}return i}destroy(t=!1){var e,i;this.emit("destroy",this),t&&((e=this.gpuProgram)==null||e.destroy(),(i=this.glProgram)==null||i.destroy()),this.gpuProgram=null,this.glProgram=null,this.removeAllListeners(),this._uniformBindMap=null,this._ownedBindGroups.forEach(r=>{r.destroy()}),this._ownedBindGroups=null,this.resources=null,this.groups=null}static from(t){const{gpu:e,gl:i,...r}=t;let n,o;return e&&(n=Ye.from(e)),i&&(o=nn.from(i)),new Ys({gpuProgram:n,glProgram:o,...r})}}const Ts=[];rt.handleByNamedList(L.Environment,Ts);async function Pa(s){if(!s)for(let t=0;t<Ts.length;t++){const e=Ts[t];if(e.value.test()){await e.value.load();return}}}let ee;function Ma(){if(typeof ee=="boolean")return ee;try{ee=new Function("param1","param2","param3","return param1[param2] === param3;")({a:"b"},"a","b")===!0}catch{ee=!1}return ee}function Ei(s,t,e=2){const i=t&&t.length,r=i?t[0]*e:s.length;let n=cn(s,0,r,e,!0);const o=[];if(!n||n.next===n.prev)return o;let a,h,l;if(i&&(n=Ea(s,t,n,e)),s.length>80*e){a=s[0],h=s[1];let c=a,u=h;for(let p=e;p<r;p+=e){const d=s[p],m=s[p+1];d<a&&(a=d),m<h&&(h=m),d>c&&(c=d),m>u&&(u=m)}l=Math.max(c-a,u-h),l=l!==0?32767/l:0}return pe(n,o,e,a,h,l,0),o}function cn(s,t,e,i,r){let n;if(r===Ua(s,t,e,i)>0)for(let o=t;o<e;o+=i)n=Ri(o/i|0,s[o],s[o+1],n);else for(let o=e-i;o>=t;o-=i)n=Ri(o/i|0,s[o],s[o+1],n);return n&&Yt(n,n.next)&&(ge(n),n=n.next),n}function Ft(s,t){if(!s)return s;t||(t=s);let e=s,i;do if(i=!1,!e.steiner&&(Yt(e,e.next)||U(e.prev,e,e.next)===0)){if(ge(e),e=t=e.prev,e===e.next)break;i=!0}else e=e.next;while(i||e!==t);return t}function pe(s,t,e,i,r,n,o){if(!s)return;!o&&n&&Ga(s,i,r,n);let a=s;for(;s.prev!==s.next;){const h=s.prev,l=s.next;if(n?Ta(s,i,r,n):Ca(s)){t.push(h.i,s.i,l.i),ge(s),s=l.next,a=l.next;continue}if(s=l,s===a){o?o===1?(s=Aa(Ft(s),t),pe(s,t,e,i,r,n,2)):o===2&&ka(s,t,e,i,r,n):pe(Ft(s),t,e,i,r,n,1);break}}}function Ca(s){const t=s.prev,e=s,i=s.next;if(U(t,e,i)>=0)return!1;const r=t.x,n=e.x,o=i.x,a=t.y,h=e.y,l=i.y,c=Math.min(r,n,o),u=Math.min(a,h,l),p=Math.max(r,n,o),d=Math.max(a,h,l);let m=i.next;for(;m!==t;){if(m.x>=c&&m.x<=p&&m.y>=u&&m.y<=d&&ae(r,a,n,h,o,l,m.x,m.y)&&U(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function Ta(s,t,e,i){const r=s.prev,n=s,o=s.next;if(U(r,n,o)>=0)return!1;const a=r.x,h=n.x,l=o.x,c=r.y,u=n.y,p=o.y,d=Math.min(a,h,l),m=Math.min(c,u,p),g=Math.max(a,h,l),f=Math.max(c,u,p),x=As(d,m,t,e,i),y=As(g,f,t,e,i);let _=s.prevZ,b=s.nextZ;for(;_&&_.z>=x&&b&&b.z<=y;){if(_.x>=d&&_.x<=g&&_.y>=m&&_.y<=f&&_!==r&&_!==o&&ae(a,c,h,u,l,p,_.x,_.y)&&U(_.prev,_,_.next)>=0||(_=_.prevZ,b.x>=d&&b.x<=g&&b.y>=m&&b.y<=f&&b!==r&&b!==o&&ae(a,c,h,u,l,p,b.x,b.y)&&U(b.prev,b,b.next)>=0))return!1;b=b.nextZ}for(;_&&_.z>=x;){if(_.x>=d&&_.x<=g&&_.y>=m&&_.y<=f&&_!==r&&_!==o&&ae(a,c,h,u,l,p,_.x,_.y)&&U(_.prev,_,_.next)>=0)return!1;_=_.prevZ}for(;b&&b.z<=y;){if(b.x>=d&&b.x<=g&&b.y>=m&&b.y<=f&&b!==r&&b!==o&&ae(a,c,h,u,l,p,b.x,b.y)&&U(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function Aa(s,t){let e=s;do{const i=e.prev,r=e.next.next;!Yt(i,r)&&dn(i,e,e.next,r)&&me(i,r)&&me(r,i)&&(t.push(i.i,e.i,r.i),ge(e),ge(e.next),e=s=r),e=e.next}while(e!==s);return Ft(e)}function ka(s,t,e,i,r,n){let o=s;do{let a=o.next.next;for(;a!==o.prev;){if(o.i!==a.i&&za(o,a)){let h=fn(o,a);o=Ft(o,o.next),h=Ft(h,h.next),pe(o,t,e,i,r,n,0),pe(h,t,e,i,r,n,0);return}a=a.next}o=o.next}while(o!==s)}function Ea(s,t,e,i){const r=[];for(let n=0,o=t.length;n<o;n++){const a=t[n]*i,h=n<o-1?t[n+1]*i:s.length,l=cn(s,a,h,i,!1);l===l.next&&(l.steiner=!0),r.push(Da(l))}r.sort(Ra);for(let n=0;n<r.length;n++)e=Ia(r[n],e);return e}function Ra(s,t){let e=s.x-t.x;if(e===0&&(e=s.y-t.y,e===0)){const i=(s.next.y-s.y)/(s.next.x-s.x),r=(t.next.y-t.y)/(t.next.x-t.x);e=i-r}return e}function Ia(s,t){const e=Ba(s,t);if(!e)return t;const i=fn(e,s);return Ft(i,i.next),Ft(e,e.next)}function Ba(s,t){let e=t;const i=s.x,r=s.y;let n=-1/0,o;if(Yt(s,e))return e;do{if(Yt(s,e.next))return e.next;if(r<=e.y&&r>=e.next.y&&e.next.y!==e.y){const u=e.x+(r-e.y)*(e.next.x-e.x)/(e.next.y-e.y);if(u<=i&&u>n&&(n=u,o=e.x<e.next.x?e:e.next,u===i))return o}e=e.next}while(e!==t);if(!o)return null;const a=o,h=o.x,l=o.y;let c=1/0;e=o;do{if(i>=e.x&&e.x>=h&&i!==e.x&&un(r<l?i:n,r,h,l,r<l?n:i,r,e.x,e.y)){const u=Math.abs(r-e.y)/(i-e.x);me(e,s)&&(u<c||u===c&&(e.x>o.x||e.x===o.x&&Fa(o,e)))&&(o=e,c=u)}e=e.next}while(e!==a);return o}function Fa(s,t){return U(s.prev,s,t.prev)<0&&U(t.next,s,s.next)<0}function Ga(s,t,e,i){let r=s;do r.z===0&&(r.z=As(r.x,r.y,t,e,i)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next;while(r!==s);r.prevZ.nextZ=null,r.prevZ=null,La(r)}function La(s){let t,e=1;do{let i=s,r;s=null;let n=null;for(t=0;i;){t++;let o=i,a=0;for(let l=0;l<e&&(a++,o=o.nextZ,!!o);l++);let h=e;for(;a>0||h>0&&o;)a!==0&&(h===0||!o||i.z<=o.z)?(r=i,i=i.nextZ,a--):(r=o,o=o.nextZ,h--),n?n.nextZ=r:s=r,r.prevZ=n,n=r;i=o}n.nextZ=null,e*=2}while(t>1);return s}function As(s,t,e,i,r){return s=(s-e)*r|0,t=(t-i)*r|0,s=(s|s<<8)&16711935,s=(s|s<<4)&252645135,s=(s|s<<2)&858993459,s=(s|s<<1)&1431655765,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,s|t<<1}function Da(s){let t=s,e=s;do(t.x<e.x||t.x===e.x&&t.y<e.y)&&(e=t),t=t.next;while(t!==s);return e}function un(s,t,e,i,r,n,o,a){return(r-o)*(t-a)>=(s-o)*(n-a)&&(s-o)*(i-a)>=(e-o)*(t-a)&&(e-o)*(n-a)>=(r-o)*(i-a)}function ae(s,t,e,i,r,n,o,a){return!(s===o&&t===a)&&un(s,t,e,i,r,n,o,a)}function za(s,t){return s.next.i!==t.i&&s.prev.i!==t.i&&!Ha(s,t)&&(me(s,t)&&me(t,s)&&Na(s,t)&&(U(s.prev,s,t.prev)||U(s,t.prev,t))||Yt(s,t)&&U(s.prev,s,s.next)>0&&U(t.prev,t,t.next)>0)}function U(s,t,e){return(t.y-s.y)*(e.x-t.x)-(t.x-s.x)*(e.y-t.y)}function Yt(s,t){return s.x===t.x&&s.y===t.y}function dn(s,t,e,i){const r=Ie(U(s,t,e)),n=Ie(U(s,t,i)),o=Ie(U(e,i,s)),a=Ie(U(e,i,t));return!!(r!==n&&o!==a||r===0&&Re(s,e,t)||n===0&&Re(s,i,t)||o===0&&Re(e,s,i)||a===0&&Re(e,t,i))}function Re(s,t,e){return t.x<=Math.max(s.x,e.x)&&t.x>=Math.min(s.x,e.x)&&t.y<=Math.max(s.y,e.y)&&t.y>=Math.min(s.y,e.y)}function Ie(s){return s>0?1:s<0?-1:0}function Ha(s,t){let e=s;do{if(e.i!==s.i&&e.next.i!==s.i&&e.i!==t.i&&e.next.i!==t.i&&dn(e,e.next,s,t))return!0;e=e.next}while(e!==s);return!1}function me(s,t){return U(s.prev,s,s.next)<0?U(s,t,s.next)>=0&&U(s,s.prev,t)>=0:U(s,t,s.prev)<0||U(s,s.next,t)<0}function Na(s,t){let e=s,i=!1;const r=(s.x+t.x)/2,n=(s.y+t.y)/2;do e.y>n!=e.next.y>n&&e.next.y!==e.y&&r<(e.next.x-e.x)*(n-e.y)/(e.next.y-e.y)+e.x&&(i=!i),e=e.next;while(e!==s);return i}function fn(s,t){const e=ks(s.i,s.x,s.y),i=ks(t.i,t.x,t.y),r=s.next,n=t.prev;return s.next=t,t.prev=s,e.next=r,r.prev=e,i.next=e,e.prev=i,n.next=i,i.prev=n,i}function Ri(s,t,e,i){const r=ks(s,t,e);return i?(r.next=i.next,r.prev=i,i.next.prev=r,i.next=r):(r.prev=r,r.next=r),r}function ge(s){s.next.prev=s.prev,s.prev.next=s.next,s.prevZ&&(s.prevZ.nextZ=s.nextZ),s.nextZ&&(s.nextZ.prevZ=s.prevZ)}function ks(s,t,e){return{i:s,x:t,y:e,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}function Ua(s,t,e,i){let r=0;for(let n=t,o=e-i;n<e;n+=i)r+=(s[o]-s[n])*(s[n+1]+s[o+1]),o=n;return r}const $a=Ei.default||Ei;var pn=(s=>(s[s.NONE=0]="NONE",s[s.COLOR=16384]="COLOR",s[s.STENCIL=1024]="STENCIL",s[s.DEPTH=256]="DEPTH",s[s.COLOR_DEPTH=16640]="COLOR_DEPTH",s[s.COLOR_STENCIL=17408]="COLOR_STENCIL",s[s.DEPTH_STENCIL=1280]="DEPTH_STENCIL",s[s.ALL=17664]="ALL",s))(pn||{});class Oa{constructor(t){this.items=[],this._name=t}emit(t,e,i,r,n,o,a,h){const{name:l,items:c}=this;for(let u=0,p=c.length;u<p;u++)c[u][l](t,e,i,r,n,o,a,h);return this}add(t){return t[this._name]&&(this.remove(t),this.items.push(t)),this}remove(t){const e=this.items.indexOf(t);return e!==-1&&this.items.splice(e,1),this}contains(t){return this.items.indexOf(t)!==-1}removeAll(){return this.items.length=0,this}destroy(){this.removeAll(),this.items=null,this._name=null}get empty(){return this.items.length===0}get name(){return this._name}}const Va=["init","destroy","contextChange","resolutionChange","resetState","renderEnd","renderStart","render","update","postrender","prerender"],mn=class gn extends pt{constructor(t){super(),this.uid=V("renderer"),this.runners=Object.create(null),this.renderPipes=Object.create(null),this._initOptions={},this._systemsHash=Object.create(null),this.type=t.type,this.name=t.name,this.config=t;const e=[...Va,...this.config.runners??[]];this._addRunners(...e),this._unsafeEvalCheck()}async init(t={}){const e=t.skipExtensionImports===!0?!0:t.manageImports===!1;await Pa(e),this._addSystems(this.config.systems),this._addPipes(this.config.renderPipes,this.config.renderPipeAdaptors);for(const i in this._systemsHash)t={...this._systemsHash[i].constructor.defaultOptions,...t};t={...gn.defaultOptions,...t},this._roundPixels=t.roundPixels?1:0;for(let i=0;i<this.runners.init.items.length;i++)await this.runners.init.items[i].init(t);this._initOptions=t}render(t,e){let i=t;if(i instanceof ft&&(i={container:i},e&&(F(O,"passing a second argument is deprecated, please use render options instead"),i.target=e.renderTexture)),i.target||(i.target=this.view.renderTarget),i.target===this.view.renderTarget&&(this._lastObjectRendered=i.container,i.clearColor??(i.clearColor=this.background.colorRgba),i.clear??(i.clear=this.background.clearBeforeRender)),i.clearColor){const r=Array.isArray(i.clearColor)&&i.clearColor.length===4;i.clearColor=r?i.clearColor:Y.shared.setValue(i.clearColor).toArray()}i.transform||(i.container.updateLocalTransform(),i.transform=i.container.localTransform),i.container.visible&&(i.container.enableRenderGroup(),this.runners.prerender.emit(i),this.runners.renderStart.emit(i),this.runners.render.emit(i),this.runners.renderEnd.emit(i),this.runners.postrender.emit(i))}resize(t,e,i){const r=this.view.resolution;this.view.resize(t,e,i),this.emit("resize",this.view.screen.width,this.view.screen.height,this.view.resolution),i!==void 0&&i!==r&&this.runners.resolutionChange.emit(i)}clear(t={}){const e=this;t.target||(t.target=e.renderTarget.renderTarget),t.clearColor||(t.clearColor=this.background.colorRgba),t.clear??(t.clear=pn.ALL);const{clear:i,clearColor:r,target:n}=t;Y.shared.setValue(r??this.background.colorRgba),e.renderTarget.clear(n,i,Y.shared.toArray())}get resolution(){return this.view.resolution}set resolution(t){this.view.resolution=t,this.runners.resolutionChange.emit(t)}get width(){return this.view.texture.frame.width}get height(){return this.view.texture.frame.height}get canvas(){return this.view.canvas}get lastObjectRendered(){return this._lastObjectRendered}get renderingToScreen(){return this.renderTarget.renderingToScreen}get screen(){return this.view.screen}_addRunners(...t){t.forEach(e=>{this.runners[e]=new Oa(e)})}_addSystems(t){let e;for(e in t){const i=t[e];this._addSystem(i.value,i.name)}}_addSystem(t,e){const i=new t(this);if(this[e])throw new Error(`Whoops! The name "${e}" is already in use`);this[e]=i,this._systemsHash[e]=i;for(const r in this.runners)this.runners[r].add(i);return this}_addPipes(t,e){const i=e.reduce((r,n)=>(r[n.name]=n.value,r),{});t.forEach(r=>{const n=r.value,o=r.name,a=i[o];this.renderPipes[o]=new n(this,a?new a:null),this.runners.destroy.add(this.renderPipes[o])})}destroy(t=!1){this.runners.destroy.items.reverse(),this.runners.destroy.emit(t),Object.values(this.runners).forEach(e=>{e.destroy()}),(t===!0||typeof t=="object"&&t.releaseGlobalResources)&&_e.release(),this._systemsHash=null,this.renderPipes=null}generateTexture(t){return this.textureGenerator.generateTexture(t)}get roundPixels(){return!!this._roundPixels}_unsafeEvalCheck(){if(!Ma())throw new Error("Current environment does not allow unsafe-eval, please use pixi.js/unsafe-eval module to enable support.")}resetState(){this.runners.resetState.emit()}};mn.defaultOptions={resolution:1,failIfMajorPerformanceCaveat:!1,roundPixels:!1};let xn=mn,Be;function Wa(s){return Be!==void 0||(Be=(()=>{var e;const t={stencil:!0,failIfMajorPerformanceCaveat:s??xn.defaultOptions.failIfMajorPerformanceCaveat};try{if(!et.get().getWebGLRenderingContext())return!1;let r=et.get().createCanvas().getContext("webgl",t);const n=!!((e=r==null?void 0:r.getContextAttributes())!=null&&e.stencil);if(r){const o=r.getExtension("WEBGL_lose_context");o&&o.loseContext()}return r=null,n}catch{return!1}})()),Be}let Fe;async function Ya(s={}){return Fe!==void 0||(Fe=await(async()=>{const t=et.get().getNavigator().gpu;if(!t)return!1;try{return await(await t.requestAdapter(s)).requestDevice(),!0}catch{return!1}})()),Fe}const Ii=["webgl","webgpu","canvas"];async function Xa(s){let t=[];s.preference?(t.push(s.preference),Ii.forEach(n=>{n!==s.preference&&t.push(n)})):t=Ii.slice();let e,i={};for(let n=0;n<t.length;n++){const o=t[n];if(o==="webgpu"&&await Ya()){const{WebGPURenderer:a}=await Ne(async()=>{const{WebGPURenderer:h}=await import("./WebGPURenderer-CtyVoQqf.js");return{WebGPURenderer:h}},__vite__mapDeps([3,2,4]));e=a,i={...s,...s.webgpu};break}else if(o==="webgl"&&Wa(s.failIfMajorPerformanceCaveat??xn.defaultOptions.failIfMajorPerformanceCaveat)){const{WebGLRenderer:a}=await Ne(async()=>{const{WebGLRenderer:h}=await import("./WebGLRenderer-BVO0qznQ.js");return{WebGLRenderer:h}},__vite__mapDeps([5,2,4]));e=a,i={...s,...s.webgl};break}else if(o==="canvas")throw i={...s},new Error("CanvasRenderer is not yet implemented")}if(delete i.webgpu,delete i.webgl,!e)throw new Error("No available renderer for the current environment");const r=new e;return await r.init(i),r}const yn="8.13.2";class _n{static init(){var t;(t=globalThis.__PIXI_APP_INIT__)==null||t.call(globalThis,this,yn)}static destroy(){}}_n.extension=L.Application;class ja{constructor(t){this._renderer=t}init(){var t;(t=globalThis.__PIXI_RENDERER_INIT__)==null||t.call(globalThis,this._renderer,yn)}destroy(){this._renderer=null}}ja.extension={type:[L.WebGLSystem,L.WebGPUSystem],name:"initHook",priority:-10};const bn=class Es{constructor(...t){this.stage=new ft,t[0]!==void 0&&F(O,"Application constructor options are deprecated, please use Application.init() instead.")}async init(t){t={...t},this.renderer=await Xa(t),Es._plugins.forEach(e=>{e.init.call(this,t)})}render(){this.renderer.render({container:this.stage})}get canvas(){return this.renderer.canvas}get view(){return F(O,"Application.view is deprecated, please use Application.canvas instead."),this.renderer.canvas}get screen(){return this.renderer.screen}destroy(t=!1,e=!1){const i=Es._plugins.slice(0);i.reverse(),i.forEach(r=>{r.destroy.call(this)}),this.stage.destroy(e),this.stage=null,this.renderer.destroy(t),this.renderer=null}};bn._plugins=[];let wn=bn;rt.handleByList(L.Application,wn._plugins);rt.add(_n);/** + * tiny-lru + * + * @copyright 2025 Jason Mulligan <jason.mulligan@avoidwork.com> + * @license BSD-3-Clause + * @version 11.4.5 + */class qa{constructor(t=0,e=0,i=!1){this.first=null,this.items=Object.create(null),this.last=null,this.max=t,this.resetTtl=i,this.size=0,this.ttl=e}clear(){return this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this}delete(t){if(this.has(t)){const e=this.items[t];delete this.items[t],this.size--,e.prev!==null&&(e.prev.next=e.next),e.next!==null&&(e.next.prev=e.prev),this.first===e&&(this.first=e.next),this.last===e&&(this.last=e.prev)}return this}entries(t=this.keys()){return t.map(e=>[e,this.get(e)])}evict(t=!1){if(t||this.size>0){const e=this.first;delete this.items[e.key],--this.size===0?(this.first=null,this.last=null):(this.first=e.next,this.first.prev=null)}return this}expiresAt(t){let e;return this.has(t)&&(e=this.items[t].expiry),e}get(t){const e=this.items[t];if(e!==void 0){if(this.ttl>0&&e.expiry<=Date.now()){this.delete(t);return}return this.moveToEnd(e),e.value}}has(t){return t in this.items}moveToEnd(t){this.last!==t&&(t.prev!==null&&(t.prev.next=t.next),t.next!==null&&(t.next.prev=t.prev),this.first===t&&(this.first=t.next),t.prev=this.last,t.next=null,this.last!==null&&(this.last.next=t),this.last=t,this.first===null&&(this.first=t))}keys(){const t=[];let e=this.first;for(;e!==null;)t.push(e.key),e=e.next;return t}setWithEvicted(t,e,i=this.resetTtl){let r=null;if(this.has(t))this.set(t,e,!0,i);else{this.max>0&&this.size===this.max&&(r={...this.first},this.evict(!0));let n=this.items[t]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:e};++this.size===1?this.first=n:this.last.next=n,this.last=n}return r}set(t,e,i=!1,r=this.resetTtl){let n=this.items[t];return i||n!==void 0?(n.value=e,i===!1&&r&&(n.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl),this.moveToEnd(n)):(this.max>0&&this.size===this.max&&this.evict(!0),n=this.items[t]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:e},++this.size===1?this.first=n:this.last.next=n,this.last=n),this}values(t=this.keys()){return t.map(e=>this.get(e))}}function Za(s=1e3,t=0,e=!1){if(isNaN(s)||s<0)throw new TypeError("Invalid max value");if(isNaN(t)||t<0)throw new TypeError("Invalid ttl value");if(typeof e!="boolean")throw new TypeError("Invalid resetTtl value");return new qa(s,t,e)}const Ka=["serif","sans-serif","monospace","cursive","fantasy","system-ui"];function Sn(s){const t=typeof s.fontSize=="number"?`${s.fontSize}px`:s.fontSize;let e=s.fontFamily;Array.isArray(s.fontFamily)||(e=s.fontFamily.split(","));for(let i=e.length-1;i>=0;i--){let r=e[i].trim();!/([\"\'])[^\'\"]+\1/.test(r)&&!Ka.includes(r)&&(r=`"${r}"`),e[i]=r}return`${s.fontStyle} ${s.fontVariant} ${s.fontWeight} ${t} ${e.join(",")}`}const cs={willReadFrequently:!0},lt=class T{static get experimentalLetterSpacingSupported(){let t=T._experimentalLetterSpacingSupported;if(t===void 0){const e=et.get().getCanvasRenderingContext2D().prototype;t=T._experimentalLetterSpacingSupported="letterSpacing"in e||"textLetterSpacing"in e}return t}constructor(t,e,i,r,n,o,a,h,l){this.text=t,this.style=e,this.width=i,this.height=r,this.lines=n,this.lineWidths=o,this.lineHeight=a,this.maxLineWidth=h,this.fontProperties=l}static measureText(t=" ",e,i=T._canvas,r=e.wordWrap){var y;const n=`${t}-${e.styleKey}-wordWrap-${r}`;if(T._measurementCache.has(n))return T._measurementCache.get(n);const o=Sn(e),a=T.measureFont(o);a.fontSize===0&&(a.fontSize=e.fontSize,a.ascent=e.fontSize);const h=T.__context;h.font=o;const c=(r?T._wordWrap(t,e,i):t).split(/(?:\r\n|\r|\n)/),u=new Array(c.length);let p=0;for(let _=0;_<c.length;_++){const b=T._measureText(c[_],e.letterSpacing,h);u[_]=b,p=Math.max(p,b)}const d=((y=e._stroke)==null?void 0:y.width)||0;let m=p+d;e.dropShadow&&(m+=e.dropShadow.distance);const g=e.lineHeight||a.fontSize;let f=Math.max(g,a.fontSize+d)+(c.length-1)*(g+e.leading);e.dropShadow&&(f+=e.dropShadow.distance);const x=new T(t,e,m,f,c,u,g+e.leading,p,a);return T._measurementCache.set(n,x),x}static _measureText(t,e,i){let r=!1;T.experimentalLetterSpacingSupported&&(T.experimentalLetterSpacing?(i.letterSpacing=`${e}px`,i.textLetterSpacing=`${e}px`,r=!0):(i.letterSpacing="0px",i.textLetterSpacing="0px"));const n=i.measureText(t);let o=n.width;const a=-n.actualBoundingBoxLeft;let l=n.actualBoundingBoxRight-a;if(o>0)if(r)o-=e,l-=e;else{const c=(T.graphemeSegmenter(t).length-1)*e;o+=c,l+=c}return Math.max(o,l)}static _wordWrap(t,e,i=T._canvas){const r=i.getContext("2d",cs);let n=0,o="",a="";const h=Object.create(null),{letterSpacing:l,whiteSpace:c}=e,u=T._collapseSpaces(c),p=T._collapseNewlines(c);let d=!u;const m=e.wordWrapWidth+l,g=T._tokenize(t);for(let f=0;f<g.length;f++){let x=g[f];if(T._isNewline(x)){if(!p){a+=T._addLine(o),d=!u,o="",n=0;continue}x=" "}if(u){const _=T.isBreakingSpace(x),b=T.isBreakingSpace(o[o.length-1]);if(_&&b)continue}const y=T._getFromCache(x,l,h,r);if(y>m)if(o!==""&&(a+=T._addLine(o),o="",n=0),T.canBreakWords(x,e.breakWords)){const _=T.wordWrapSplit(x);for(let b=0;b<_.length;b++){let v=_[b],S=v,w=1;for(;_[b+w];){const k=_[b+w];if(!T.canBreakChars(S,k,x,b,e.breakWords))v+=k;else break;S=k,w++}b+=w-1;const R=T._getFromCache(v,l,h,r);R+n>m&&(a+=T._addLine(o),d=!1,o="",n=0),o+=v,n+=R}}else{o.length>0&&(a+=T._addLine(o),o="",n=0);const _=f===g.length-1;a+=T._addLine(x,!_),d=!1,o="",n=0}else y+n>m&&(d=!1,a+=T._addLine(o),o="",n=0),(o.length>0||!T.isBreakingSpace(x)||d)&&(o+=x,n+=y)}return a+=T._addLine(o,!1),a}static _addLine(t,e=!0){return t=T._trimRight(t),t=e?`${t} +`:t,t}static _getFromCache(t,e,i,r){let n=i[t];return typeof n!="number"&&(n=T._measureText(t,e,r)+e,i[t]=n),n}static _collapseSpaces(t){return t==="normal"||t==="pre-line"}static _collapseNewlines(t){return t==="normal"}static _trimRight(t){if(typeof t!="string")return"";for(let e=t.length-1;e>=0;e--){const i=t[e];if(!T.isBreakingSpace(i))break;t=t.slice(0,-1)}return t}static _isNewline(t){return typeof t!="string"?!1:T._newlines.includes(t.charCodeAt(0))}static isBreakingSpace(t,e){return typeof t!="string"?!1:T._breakingSpaces.includes(t.charCodeAt(0))}static _tokenize(t){const e=[];let i="";if(typeof t!="string")return e;for(let r=0;r<t.length;r++){const n=t[r],o=t[r+1];if(T.isBreakingSpace(n,o)||T._isNewline(n)){i!==""&&(e.push(i),i=""),n==="\r"&&o===` +`?(e.push(`\r +`),r++):e.push(n);continue}i+=n}return i!==""&&e.push(i),e}static canBreakWords(t,e){return e}static canBreakChars(t,e,i,r,n){return!0}static wordWrapSplit(t){return T.graphemeSegmenter(t)}static measureFont(t){if(T._fonts[t])return T._fonts[t];const e=T._context;e.font=t;const i=e.measureText(T.METRICS_STRING+T.BASELINE_SYMBOL),r={ascent:i.actualBoundingBoxAscent,descent:i.actualBoundingBoxDescent,fontSize:i.actualBoundingBoxAscent+i.actualBoundingBoxDescent};return T._fonts[t]=r,r}static clearMetrics(t=""){t?delete T._fonts[t]:T._fonts={}}static get _canvas(){if(!T.__canvas){let t;try{const e=new OffscreenCanvas(0,0),i=e.getContext("2d",cs);if(i!=null&&i.measureText)return T.__canvas=e,e;t=et.get().createCanvas()}catch{t=et.get().createCanvas()}t.width=t.height=10,T.__canvas=t}return T.__canvas}static get _context(){return T.__context||(T.__context=T._canvas.getContext("2d",cs)),T.__context}};lt.METRICS_STRING="|ÉqÅ";lt.BASELINE_SYMBOL="M";lt.BASELINE_MULTIPLIER=1.4;lt.HEIGHT_MULTIPLIER=2;lt.graphemeSegmenter=(()=>{if(typeof(Intl==null?void 0:Intl.Segmenter)=="function"){const s=new Intl.Segmenter;return t=>{const e=s.segment(t),i=[];let r=0;for(const n of e)i[r++]=n.segment;return i}}return s=>[...s]})();lt.experimentalLetterSpacing=!1;lt._fonts={};lt._newlines=[10,13];lt._breakingSpaces=[9,32,8192,8193,8194,8195,8196,8197,8198,8200,8201,8202,8287,12288];lt._measurementCache=Za(1e3);let Nt=lt;const Bi=[{offset:0,color:"white"},{offset:1,color:"black"}],Xs=class Rs{constructor(...t){this.uid=V("fillGradient"),this._tick=0,this.type="linear",this.colorStops=[];let e=Qa(t);e={...e.type==="radial"?Rs.defaultRadialOptions:Rs.defaultLinearOptions,...Mr(e)},this._textureSize=e.textureSize,this._wrapMode=e.wrapMode,e.type==="radial"?(this.center=e.center,this.outerCenter=e.outerCenter??this.center,this.innerRadius=e.innerRadius,this.outerRadius=e.outerRadius,this.scale=e.scale,this.rotation=e.rotation):(this.start=e.start,this.end=e.end),this.textureSpace=e.textureSpace,this.type=e.type,e.colorStops.forEach(r=>{this.addColorStop(r.offset,r.color)})}addColorStop(t,e){return this.colorStops.push({offset:t,color:Y.shared.setValue(e).toHexa()}),this}buildLinearGradient(){if(this.texture)return;let{x:t,y:e}=this.start,{x:i,y:r}=this.end,n=i-t,o=r-e;const a=n<0||o<0;if(this._wrapMode==="clamp-to-edge"){if(n<0){const f=t;t=i,i=f,n*=-1}if(o<0){const f=e;e=r,r=f,o*=-1}}const h=this.colorStops.length?this.colorStops:Bi,l=this._textureSize,{canvas:c,context:u}=Gi(l,1),p=a?u.createLinearGradient(this._textureSize,0,0,0):u.createLinearGradient(0,0,this._textureSize,0);Fi(p,h),u.fillStyle=p,u.fillRect(0,0,l,1),this.texture=new D({source:new $e({resource:c,addressMode:this._wrapMode})});const d=Math.sqrt(n*n+o*o),m=Math.atan2(o,n),g=new I;g.scale(d/l,1),g.rotate(m),g.translate(t,e),this.textureSpace==="local"&&g.scale(l,l),this.transform=g}buildGradient(){this.texture||this._tick++,this.type==="linear"?this.buildLinearGradient():this.buildRadialGradient()}buildRadialGradient(){if(this.texture)return;const t=this.colorStops.length?this.colorStops:Bi,e=this._textureSize,{canvas:i,context:r}=Gi(e,e),{x:n,y:o}=this.center,{x:a,y:h}=this.outerCenter,l=this.innerRadius,c=this.outerRadius,u=a-c,p=h-c,d=e/(c*2),m=(n-u)*d,g=(o-p)*d,f=r.createRadialGradient(m,g,l*d,(a-u)*d,(h-p)*d,c*d);Fi(f,t),r.fillStyle=t[t.length-1].color,r.fillRect(0,0,e,e),r.fillStyle=f,r.translate(m,g),r.rotate(this.rotation),r.scale(1,this.scale),r.translate(-m,-g),r.fillRect(0,0,e,e),this.texture=new D({source:new $e({resource:i,addressMode:this._wrapMode})});const x=new I;x.scale(1/d,1/d),x.translate(u,p),this.textureSpace==="local"&&x.scale(e,e),this.transform=x}destroy(){var t;(t=this.texture)==null||t.destroy(!0),this.texture=null,this.transform=null,this.colorStops=[],this.start=null,this.end=null,this.center=null,this.outerCenter=null}get styleKey(){return`fill-gradient-${this.uid}-${this._tick}`}};Xs.defaultLinearOptions={start:{x:0,y:0},end:{x:0,y:1},colorStops:[],textureSpace:"local",type:"linear",textureSize:256,wrapMode:"clamp-to-edge"};Xs.defaultRadialOptions={center:{x:.5,y:.5},innerRadius:0,outerRadius:.5,colorStops:[],scale:1,textureSpace:"local",type:"radial",textureSize:256,wrapMode:"clamp-to-edge"};let _t=Xs;function Fi(s,t){for(let e=0;e<t.length;e++){const i=t[e];s.addColorStop(i.offset,i.color)}}function Gi(s,t){const e=et.get().createCanvas(s,t),i=e.getContext("2d");return{canvas:e,context:i}}function Qa(s){let t=s[0]??{};return(typeof t=="number"||s[1])&&(F("8.5.2","use options object instead"),t={type:"linear",start:{x:s[0],y:s[1]},end:{x:s[2],y:s[3]},textureSpace:s[4],textureSize:s[5]??_t.defaultLinearOptions.textureSize}),t}const Li={repeat:{addressModeU:"repeat",addressModeV:"repeat"},"repeat-x":{addressModeU:"repeat",addressModeV:"clamp-to-edge"},"repeat-y":{addressModeU:"clamp-to-edge",addressModeV:"repeat"},"no-repeat":{addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge"}};class Xe{constructor(t,e){this.uid=V("fillPattern"),this._tick=0,this.transform=new I,this.texture=t,this.transform.scale(1/t.frame.width,1/t.frame.height),e&&(t.source.style.addressModeU=Li[e].addressModeU,t.source.style.addressModeV=Li[e].addressModeV)}setTransform(t){const e=this.texture;this.transform.copyFrom(t),this.transform.invert(),this.transform.scale(1/e.frame.width,1/e.frame.height),this._tick++}get texture(){return this._texture}set texture(t){this._texture!==t&&(this._texture=t,this._tick++)}get styleKey(){return`fill-pattern-${this.uid}-${this._tick}`}destroy(){this.texture.destroy(!0),this.texture=null}}var Ja=eh,us={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},th=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function eh(s){var t=[];return s.replace(th,function(e,i,r){var n=i.toLowerCase();for(r=ih(r),n=="m"&&r.length>2&&(t.push([i].concat(r.splice(0,2))),n="l",i=i=="m"?"l":"L");;){if(r.length==us[n])return r.unshift(i),t.push(r);if(r.length<us[n])throw new Error("malformed path data");t.push([i].concat(r.splice(0,us[n])))}}),t}var sh=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function ih(s){var t=s.match(sh);return t?t.map(Number):[]}const rh=wr(Ja);function nh(s,t){const e=rh(s),i=[];let r=null,n=0,o=0;for(let a=0;a<e.length;a++){const h=e[a],l=h[0],c=h;switch(l){case"M":n=c[1],o=c[2],t.moveTo(n,o);break;case"m":n+=c[1],o+=c[2],t.moveTo(n,o);break;case"H":n=c[1],t.lineTo(n,o);break;case"h":n+=c[1],t.lineTo(n,o);break;case"V":o=c[1],t.lineTo(n,o);break;case"v":o+=c[1],t.lineTo(n,o);break;case"L":n=c[1],o=c[2],t.lineTo(n,o);break;case"l":n+=c[1],o+=c[2],t.lineTo(n,o);break;case"C":n=c[5],o=c[6],t.bezierCurveTo(c[1],c[2],c[3],c[4],n,o);break;case"c":t.bezierCurveTo(n+c[1],o+c[2],n+c[3],o+c[4],n+c[5],o+c[6]),n+=c[5],o+=c[6];break;case"S":n=c[3],o=c[4],t.bezierCurveToShort(c[1],c[2],n,o);break;case"s":t.bezierCurveToShort(n+c[1],o+c[2],n+c[3],o+c[4]),n+=c[3],o+=c[4];break;case"Q":n=c[3],o=c[4],t.quadraticCurveTo(c[1],c[2],n,o);break;case"q":t.quadraticCurveTo(n+c[1],o+c[2],n+c[3],o+c[4]),n+=c[3],o+=c[4];break;case"T":n=c[1],o=c[2],t.quadraticCurveToShort(n,o);break;case"t":n+=c[1],o+=c[2],t.quadraticCurveToShort(n,o);break;case"A":n=c[6],o=c[7],t.arcToSvg(c[1],c[2],c[3],c[4],c[5],n,o);break;case"a":n+=c[6],o+=c[7],t.arcToSvg(c[1],c[2],c[3],c[4],c[5],n,o);break;case"Z":case"z":t.closePath(),i.length>0&&(r=i.pop(),r?(n=r.startX,o=r.startY):(n=0,o=0)),r=null;break;default:Q(`Unknown SVG path command: ${l}`)}l!=="Z"&&l!=="z"&&r===null&&(r={startX:n,startY:o},i.push(r))}return t}class js{constructor(t=0,e=0,i=0){this.type="circle",this.x=t,this.y=e,this.radius=i}clone(){return new js(this.x,this.y,this.radius)}contains(t,e){if(this.radius<=0)return!1;const i=this.radius*this.radius;let r=this.x-t,n=this.y-e;return r*=r,n*=n,r+n<=i}strokeContains(t,e,i,r=.5){if(this.radius===0)return!1;const n=this.x-t,o=this.y-e,a=this.radius,h=(1-r)*i,l=Math.sqrt(n*n+o*o);return l<=a+h&&l>a-(i-h)}getBounds(t){return t||(t=new W),t.x=this.x-this.radius,t.y=this.y-this.radius,t.width=this.radius*2,t.height=this.radius*2,t}copyFrom(t){return this.x=t.x,this.y=t.y,this.radius=t.radius,this}copyTo(t){return t.copyFrom(this),t}toString(){return`[pixi.js/math:Circle x=${this.x} y=${this.y} radius=${this.radius}]`}}class qs{constructor(t=0,e=0,i=0,r=0){this.type="ellipse",this.x=t,this.y=e,this.halfWidth=i,this.halfHeight=r}clone(){return new qs(this.x,this.y,this.halfWidth,this.halfHeight)}contains(t,e){if(this.halfWidth<=0||this.halfHeight<=0)return!1;let i=(t-this.x)/this.halfWidth,r=(e-this.y)/this.halfHeight;return i*=i,r*=r,i+r<=1}strokeContains(t,e,i,r=.5){const{halfWidth:n,halfHeight:o}=this;if(n<=0||o<=0)return!1;const a=i*(1-r),h=i-a,l=n-h,c=o-h,u=n+a,p=o+a,d=t-this.x,m=e-this.y,g=d*d/(l*l)+m*m/(c*c),f=d*d/(u*u)+m*m/(p*p);return g>1&&f<=1}getBounds(t){return t||(t=new W),t.x=this.x-this.halfWidth,t.y=this.y-this.halfHeight,t.width=this.halfWidth*2,t.height=this.halfHeight*2,t}copyFrom(t){return this.x=t.x,this.y=t.y,this.halfWidth=t.halfWidth,this.halfHeight=t.halfHeight,this}copyTo(t){return t.copyFrom(this),t}toString(){return`[pixi.js/math:Ellipse x=${this.x} y=${this.y} halfWidth=${this.halfWidth} halfHeight=${this.halfHeight}]`}}function oh(s,t,e,i,r,n){const o=s-e,a=t-i,h=r-e,l=n-i,c=o*h+a*l,u=h*h+l*l;let p=-1;u!==0&&(p=c/u);let d,m;p<0?(d=e,m=i):p>1?(d=r,m=n):(d=e+p*h,m=i+p*l);const g=s-d,f=t-m;return g*g+f*f}let ah,hh;class le{constructor(...t){this.type="polygon";let e=Array.isArray(t[0])?t[0]:t;if(typeof e[0]!="number"){const i=[];for(let r=0,n=e.length;r<n;r++)i.push(e[r].x,e[r].y);e=i}this.points=e,this.closePath=!0}isClockwise(){let t=0;const e=this.points,i=e.length;for(let r=0;r<i;r+=2){const n=e[r],o=e[r+1],a=e[(r+2)%i],h=e[(r+3)%i];t+=(a-n)*(h+o)}return t<0}containsPolygon(t){const e=this.getBounds(ah),i=t.getBounds(hh);if(!e.containsRect(i))return!1;const r=t.points;for(let n=0;n<r.length;n+=2){const o=r[n],a=r[n+1];if(!this.contains(o,a))return!1}return!0}clone(){const t=this.points.slice(),e=new le(t);return e.closePath=this.closePath,e}contains(t,e){let i=!1;const r=this.points.length/2;for(let n=0,o=r-1;n<r;o=n++){const a=this.points[n*2],h=this.points[n*2+1],l=this.points[o*2],c=this.points[o*2+1];h>e!=c>e&&t<(l-a)*((e-h)/(c-h))+a&&(i=!i)}return i}strokeContains(t,e,i,r=.5){const n=i*i,o=n*(1-r),a=n-o,{points:h}=this,l=h.length-(this.closePath?0:2);for(let c=0;c<l;c+=2){const u=h[c],p=h[c+1],d=h[(c+2)%h.length],m=h[(c+3)%h.length],g=oh(t,e,u,p,d,m),f=Math.sign((d-u)*(e-p)-(m-p)*(t-u));if(g<=(f<0?a:o))return!0}return!1}getBounds(t){t||(t=new W);const e=this.points;let i=1/0,r=-1/0,n=1/0,o=-1/0;for(let a=0,h=e.length;a<h;a+=2){const l=e[a],c=e[a+1];i=l<i?l:i,r=l>r?l:r,n=c<n?c:n,o=c>o?c:o}return t.x=i,t.width=r-i,t.y=n,t.height=o-n,t}copyFrom(t){return this.points=t.points.slice(),this.closePath=t.closePath,this}copyTo(t){return t.copyFrom(this),t}toString(){return`[pixi.js/math:PolygoncloseStroke=${this.closePath}points=${this.points.reduce((t,e)=>`${t}, ${e}`,"")}]`}get lastX(){return this.points[this.points.length-2]}get lastY(){return this.points[this.points.length-1]}get x(){return F("8.11.0","Polygon.lastX is deprecated, please use Polygon.lastX instead."),this.points[this.points.length-2]}get y(){return F("8.11.0","Polygon.y is deprecated, please use Polygon.lastY instead."),this.points[this.points.length-1]}get startX(){return this.points[0]}get startY(){return this.points[1]}}const Ge=(s,t,e,i,r,n,o)=>{const a=s-e,h=t-i,l=Math.sqrt(a*a+h*h);return l>=r-n&&l<=r+o};class Zs{constructor(t=0,e=0,i=0,r=0,n=20){this.type="roundedRectangle",this.x=t,this.y=e,this.width=i,this.height=r,this.radius=n}getBounds(t){return t||(t=new W),t.x=this.x,t.y=this.y,t.width=this.width,t.height=this.height,t}clone(){return new Zs(this.x,this.y,this.width,this.height,this.radius)}copyFrom(t){return this.x=t.x,this.y=t.y,this.width=t.width,this.height=t.height,this}copyTo(t){return t.copyFrom(this),t}contains(t,e){if(this.width<=0||this.height<=0)return!1;if(t>=this.x&&t<=this.x+this.width&&e>=this.y&&e<=this.y+this.height){const i=Math.max(0,Math.min(this.radius,Math.min(this.width,this.height)/2));if(e>=this.y+i&&e<=this.y+this.height-i||t>=this.x+i&&t<=this.x+this.width-i)return!0;let r=t-(this.x+i),n=e-(this.y+i);const o=i*i;if(r*r+n*n<=o||(r=t-(this.x+this.width-i),r*r+n*n<=o)||(n=e-(this.y+this.height-i),r*r+n*n<=o)||(r=t-(this.x+i),r*r+n*n<=o))return!0}return!1}strokeContains(t,e,i,r=.5){const{x:n,y:o,width:a,height:h,radius:l}=this,c=i*(1-r),u=i-c,p=n+l,d=o+l,m=a-l*2,g=h-l*2,f=n+a,x=o+h;return(t>=n-c&&t<=n+u||t>=f-u&&t<=f+c)&&e>=d&&e<=d+g||(e>=o-c&&e<=o+u||e>=x-u&&e<=x+c)&&t>=p&&t<=p+m?!0:t<p&&e<d&&Ge(t,e,p,d,l,u,c)||t>f-l&&e<d&&Ge(t,e,f-l,d,l,u,c)||t>f-l&&e>x-l&&Ge(t,e,f-l,x-l,l,u,c)||t<p&&e>x-l&&Ge(t,e,p,x-l,l,u,c)}toString(){return`[pixi.js/math:RoundedRectangle x=${this.x} y=${this.y}width=${this.width} height=${this.height} radius=${this.radius}]`}}const vn={};function lh(s,t,e){let i=2166136261;for(let r=0;r<t;r++)i^=s[r].uid,i=Math.imul(i,16777619),i>>>=0;return vn[i]||ch(s,t,i,e)}function ch(s,t,e,i){const r={};let n=0;for(let a=0;a<i;a++){const h=a<t?s[a]:D.EMPTY.source;r[n++]=h.source,r[n++]=h.style}const o=new He(r);return vn[e]=o,o}class Di{constructor(t){typeof t=="number"?this.rawBinaryData=new ArrayBuffer(t):t instanceof Uint8Array?this.rawBinaryData=t.buffer:this.rawBinaryData=t,this.uint32View=new Uint32Array(this.rawBinaryData),this.float32View=new Float32Array(this.rawBinaryData),this.size=this.rawBinaryData.byteLength}get int8View(){return this._int8View||(this._int8View=new Int8Array(this.rawBinaryData)),this._int8View}get uint8View(){return this._uint8View||(this._uint8View=new Uint8Array(this.rawBinaryData)),this._uint8View}get int16View(){return this._int16View||(this._int16View=new Int16Array(this.rawBinaryData)),this._int16View}get int32View(){return this._int32View||(this._int32View=new Int32Array(this.rawBinaryData)),this._int32View}get float64View(){return this._float64Array||(this._float64Array=new Float64Array(this.rawBinaryData)),this._float64Array}get bigUint64View(){return this._bigUint64Array||(this._bigUint64Array=new BigUint64Array(this.rawBinaryData)),this._bigUint64Array}view(t){return this[`${t}View`]}destroy(){this.rawBinaryData=null,this._int8View=null,this._uint8View=null,this._int16View=null,this.uint16View=null,this._int32View=null,this.uint32View=null,this.float32View=null}static sizeOf(t){switch(t){case"int8":case"uint8":return 1;case"int16":case"uint16":return 2;case"int32":case"uint32":case"float32":return 4;default:throw new Error(`${t} isn't a valid view type`)}}}function zi(s,t){const e=s.byteLength/8|0,i=new Float64Array(s,0,e);new Float64Array(t,0,e).set(i);const n=s.byteLength-e*8;if(n>0){const o=new Uint8Array(s,e*8,n);new Uint8Array(t,e*8,n).set(o)}}const uh={normal:"normal-npm",add:"add-npm",screen:"screen-npm"};var dh=(s=>(s[s.DISABLED=0]="DISABLED",s[s.RENDERING_MASK_ADD=1]="RENDERING_MASK_ADD",s[s.MASK_ACTIVE=2]="MASK_ACTIVE",s[s.INVERSE_MASK_ACTIVE=3]="INVERSE_MASK_ACTIVE",s[s.RENDERING_MASK_REMOVE=4]="RENDERING_MASK_REMOVE",s[s.NONE=5]="NONE",s))(dh||{});function Hi(s,t){return t.alphaMode==="no-premultiply-alpha"&&uh[s]||s}const fh=["precision mediump float;","void main(void){","float test = 0.1;","%forloop%","gl_FragColor = vec4(0.0);","}"].join(` +`);function ph(s){let t="";for(let e=0;e<s;++e)e>0&&(t+=` +else `),e<s-1&&(t+=`if(test == ${e}.0){}`);return t}function mh(s,t){if(s===0)throw new Error("Invalid value of `0` passed to `checkMaxIfStatementsInShader`");const e=t.createShader(t.FRAGMENT_SHADER);try{for(;;){const i=fh.replace(/%forloop%/gi,ph(s));if(t.shaderSource(e,i),t.compileShader(e),!t.getShaderParameter(e,t.COMPILE_STATUS))s=s/2|0;else break}}finally{t.deleteShader(e)}return s}let Lt=null;function gh(){var t;if(Lt)return Lt;const s=sn();return Lt=s.getParameter(s.MAX_TEXTURE_IMAGE_UNITS),Lt=mh(Lt,s),(t=s.getExtension("WEBGL_lose_context"))==null||t.loseContext(),Lt}class xh{constructor(){this.ids=Object.create(null),this.textures=[],this.count=0}clear(){for(let t=0;t<this.count;t++){const e=this.textures[t];this.textures[t]=null,this.ids[e.uid]=null}this.count=0}}class yh{constructor(){this.renderPipeId="batch",this.action="startBatch",this.start=0,this.size=0,this.textures=new xh,this.blendMode="normal",this.topology="triangle-strip",this.canBundle=!0}destroy(){this.textures=null,this.gpuBindGroup=null,this.bindGroup=null,this.batcher=null}}const ce=[];let Oe=0;_e.register({clear:()=>{if(ce.length>0)for(const s of ce)s&&s.destroy();ce.length=0,Oe=0}});function Ni(){return Oe>0?ce[--Oe]:new yh}function Ui(s){ce[Oe++]=s}let se=0;const Pn=class Mn{constructor(t){this.uid=V("batcher"),this.dirty=!0,this.batchIndex=0,this.batches=[],this._elements=[],t={...Mn.defaultOptions,...t},t.maxTextures||(F("v8.8.0","maxTextures is a required option for Batcher now, please pass it in the options"),t.maxTextures=gh());const{maxTextures:e,attributesInitialSize:i,indicesInitialSize:r}=t;this.attributeBuffer=new Di(i*4),this.indexBuffer=new Uint16Array(r),this.maxTextures=e}begin(){this.elementSize=0,this.elementStart=0,this.indexSize=0,this.attributeSize=0;for(let t=0;t<this.batchIndex;t++)Ui(this.batches[t]);this.batchIndex=0,this._batchIndexStart=0,this._batchIndexSize=0,this.dirty=!0}add(t){this._elements[this.elementSize++]=t,t._indexStart=this.indexSize,t._attributeStart=this.attributeSize,t._batcher=this,this.indexSize+=t.indexSize,this.attributeSize+=t.attributeSize*this.vertexSize}checkAndUpdateTexture(t,e){const i=t._batch.textures.ids[e._source.uid];return!i&&i!==0?!1:(t._textureId=i,t.texture=e,!0)}updateElement(t){this.dirty=!0;const e=this.attributeBuffer;t.packAsQuad?this.packQuadAttributes(t,e.float32View,e.uint32View,t._attributeStart,t._textureId):this.packAttributes(t,e.float32View,e.uint32View,t._attributeStart,t._textureId)}break(t){const e=this._elements;if(!e[this.elementStart])return;let i=Ni(),r=i.textures;r.clear();const n=e[this.elementStart];let o=Hi(n.blendMode,n.texture._source),a=n.topology;this.attributeSize*4>this.attributeBuffer.size&&this._resizeAttributeBuffer(this.attributeSize*4),this.indexSize>this.indexBuffer.length&&this._resizeIndexBuffer(this.indexSize);const h=this.attributeBuffer.float32View,l=this.attributeBuffer.uint32View,c=this.indexBuffer;let u=this._batchIndexSize,p=this._batchIndexStart,d="startBatch";const m=this.maxTextures;for(let g=this.elementStart;g<this.elementSize;++g){const f=e[g];e[g]=null;const y=f.texture._source,_=Hi(f.blendMode,y),b=o!==_||a!==f.topology;if(y._batchTick===se&&!b){f._textureId=y._textureBindLocation,u+=f.indexSize,f.packAsQuad?(this.packQuadAttributes(f,h,l,f._attributeStart,f._textureId),this.packQuadIndex(c,f._indexStart,f._attributeStart/this.vertexSize)):(this.packAttributes(f,h,l,f._attributeStart,f._textureId),this.packIndex(f,c,f._indexStart,f._attributeStart/this.vertexSize)),f._batch=i;continue}y._batchTick=se,(r.count>=m||b)&&(this._finishBatch(i,p,u-p,r,o,a,t,d),d="renderBatch",p=u,o=_,a=f.topology,i=Ni(),r=i.textures,r.clear(),++se),f._textureId=y._textureBindLocation=r.count,r.ids[y.uid]=r.count,r.textures[r.count++]=y,f._batch=i,u+=f.indexSize,f.packAsQuad?(this.packQuadAttributes(f,h,l,f._attributeStart,f._textureId),this.packQuadIndex(c,f._indexStart,f._attributeStart/this.vertexSize)):(this.packAttributes(f,h,l,f._attributeStart,f._textureId),this.packIndex(f,c,f._indexStart,f._attributeStart/this.vertexSize))}r.count>0&&(this._finishBatch(i,p,u-p,r,o,a,t,d),p=u,++se),this.elementStart=this.elementSize,this._batchIndexStart=p,this._batchIndexSize=u}_finishBatch(t,e,i,r,n,o,a,h){t.gpuBindGroup=null,t.bindGroup=null,t.action=h,t.batcher=this,t.textures=r,t.blendMode=n,t.topology=o,t.start=e,t.size=i,++se,this.batches[this.batchIndex++]=t,a.add(t)}finish(t){this.break(t)}ensureAttributeBuffer(t){t*4<=this.attributeBuffer.size||this._resizeAttributeBuffer(t*4)}ensureIndexBuffer(t){t<=this.indexBuffer.length||this._resizeIndexBuffer(t)}_resizeAttributeBuffer(t){const e=Math.max(t,this.attributeBuffer.size*2),i=new Di(e);zi(this.attributeBuffer.rawBinaryData,i.rawBinaryData),this.attributeBuffer=i}_resizeIndexBuffer(t){const e=this.indexBuffer;let i=Math.max(t,e.length*1.5);i+=i%2;const r=i>65535?new Uint32Array(i):new Uint16Array(i);if(r.BYTES_PER_ELEMENT!==e.BYTES_PER_ELEMENT)for(let n=0;n<e.length;n++)r[n]=e[n];else zi(e.buffer,r.buffer);this.indexBuffer=r}packQuadIndex(t,e,i){t[e]=i+0,t[e+1]=i+1,t[e+2]=i+2,t[e+3]=i+0,t[e+4]=i+2,t[e+5]=i+3}packIndex(t,e,i,r){const n=t.indices,o=t.indexSize,a=t.indexOffset,h=t.attributeOffset;for(let l=0;l<o;l++)e[i++]=r+n[l+a]-h}destroy(){if(this.batches!==null){for(let t=0;t<this.batches.length;t++)Ui(this.batches[t]);this.batches=null;for(let t=0;t<this._elements.length;t++)this._elements[t]&&(this._elements[t]._batch=null);this._elements=null,this.indexBuffer=null,this.attributeBuffer.destroy(),this.attributeBuffer=null}}};Pn.defaultOptions={maxTextures:null,attributesInitialSize:4,indicesInitialSize:6};let _h=Pn;var J=(s=>(s[s.MAP_READ=1]="MAP_READ",s[s.MAP_WRITE=2]="MAP_WRITE",s[s.COPY_SRC=4]="COPY_SRC",s[s.COPY_DST=8]="COPY_DST",s[s.INDEX=16]="INDEX",s[s.VERTEX=32]="VERTEX",s[s.UNIFORM=64]="UNIFORM",s[s.STORAGE=128]="STORAGE",s[s.INDIRECT=256]="INDIRECT",s[s.QUERY_RESOLVE=512]="QUERY_RESOLVE",s[s.STATIC=1024]="STATIC",s))(J||{});class xe extends pt{constructor(t){let{data:e,size:i}=t;const{usage:r,label:n,shrinkToFit:o}=t;super(),this.uid=V("buffer"),this._resourceType="buffer",this._resourceId=V("resource"),this._touched=0,this._updateID=1,this._dataInt32=null,this.shrinkToFit=!0,this.destroyed=!1,e instanceof Array&&(e=new Float32Array(e)),this._data=e,i??(i=e==null?void 0:e.byteLength);const a=!!e;this.descriptor={size:i,usage:r,mappedAtCreation:a,label:n},this.shrinkToFit=o??!0}get data(){return this._data}set data(t){this.setDataWithSize(t,t.length,!0)}get dataInt32(){return this._dataInt32||(this._dataInt32=new Int32Array(this.data.buffer)),this._dataInt32}get static(){return!!(this.descriptor.usage&J.STATIC)}set static(t){t?this.descriptor.usage|=J.STATIC:this.descriptor.usage&=~J.STATIC}setDataWithSize(t,e,i){if(this._updateID++,this._updateSize=e*t.BYTES_PER_ELEMENT,this._data===t){i&&this.emit("update",this);return}const r=this._data;if(this._data=t,this._dataInt32=null,!r||r.length!==t.length){!this.shrinkToFit&&r&&t.byteLength<r.byteLength?i&&this.emit("update",this):(this.descriptor.size=t.byteLength,this._resourceId=V("resource"),this.emit("change",this));return}i&&this.emit("update",this)}update(t){this._updateSize=t??this._updateSize,this._updateID++,this.emit("update",this)}destroy(){this.destroyed=!0,this.emit("destroy",this),this.emit("change",this),this._data=null,this.descriptor=null,this.removeAllListeners()}}function Cn(s,t){if(!(s instanceof xe)){let e=t?J.INDEX:J.VERTEX;s instanceof Array&&(t?(s=new Uint32Array(s),e=J.INDEX|J.COPY_DST):(s=new Float32Array(s),e=J.VERTEX|J.COPY_DST)),s=new xe({data:s,label:t?"index-mesh-buffer":"vertex-mesh-buffer",usage:e})}return s}function bh(s,t,e){const i=s.getAttribute(t);if(!i)return e.minX=0,e.minY=0,e.maxX=0,e.maxY=0,e;const r=i.buffer.data;let n=1/0,o=1/0,a=-1/0,h=-1/0;const l=r.BYTES_PER_ELEMENT,c=(i.offset||0)/l,u=(i.stride||2*4)/l;for(let p=c;p<r.length;p+=u){const d=r[p],m=r[p+1];d>a&&(a=d),m>h&&(h=m),d<n&&(n=d),m<o&&(o=m)}return e.minX=n,e.minY=o,e.maxX=a,e.maxY=h,e}function wh(s){return(s instanceof xe||Array.isArray(s)||s.BYTES_PER_ELEMENT)&&(s={buffer:s}),s.buffer=Cn(s.buffer,!1),s}class Sh extends pt{constructor(t={}){super(),this.uid=V("geometry"),this._layoutKey=0,this.instanceCount=1,this._bounds=new at,this._boundsDirty=!0;const{attributes:e,indexBuffer:i,topology:r}=t;if(this.buffers=[],this.attributes={},e)for(const n in e)this.addAttribute(n,e[n]);this.instanceCount=t.instanceCount??1,i&&this.addIndex(i),this.topology=r||"triangle-list"}onBufferUpdate(){this._boundsDirty=!0,this.emit("update",this)}getAttribute(t){return this.attributes[t]}getIndex(){return this.indexBuffer}getBuffer(t){return this.getAttribute(t).buffer}getSize(){for(const t in this.attributes){const e=this.attributes[t];return e.buffer.data.length/(e.stride/4||e.size)}return 0}addAttribute(t,e){const i=wh(e);this.buffers.indexOf(i.buffer)===-1&&(this.buffers.push(i.buffer),i.buffer.on("update",this.onBufferUpdate,this),i.buffer.on("change",this.onBufferUpdate,this)),this.attributes[t]=i}addIndex(t){this.indexBuffer=Cn(t,!0),this.buffers.push(this.indexBuffer)}get bounds(){return this._boundsDirty?(this._boundsDirty=!1,bh(this,"aPosition",this._bounds)):this._bounds}destroy(t=!1){this.emit("destroy",this),this.removeAllListeners(),t&&this.buffers.forEach(e=>e.destroy()),this.attributes=null,this.buffers=null,this.indexBuffer=null,this._bounds=null}}const vh=new Float32Array(1),Ph=new Uint32Array(1);class Mh extends Sh{constructor(){const e=new xe({data:vh,label:"attribute-batch-buffer",usage:J.VERTEX|J.COPY_DST,shrinkToFit:!1}),i=new xe({data:Ph,label:"index-batch-buffer",usage:J.INDEX|J.COPY_DST,shrinkToFit:!1}),r=6*4;super({attributes:{aPosition:{buffer:e,format:"float32x2",stride:r,offset:0},aUV:{buffer:e,format:"float32x2",stride:r,offset:2*4},aColor:{buffer:e,format:"unorm8x4",stride:r,offset:4*4},aTextureIdAndRound:{buffer:e,format:"uint16x2",stride:r,offset:5*4}},indexBuffer:i})}}function $i(s,t,e){if(s)for(const i in s){const r=i.toLocaleLowerCase(),n=t[r];if(n){let o=s[i];i==="header"&&(o=o.replace(/@in\s+[^;]+;\s*/g,"").replace(/@out\s+[^;]+;\s*/g,"")),e&&n.push(`//----${e}----//`),n.push(o)}else Q(`${i} placement hook does not exist in shader`)}}const Ch=/\{\{(.*?)\}\}/g;function Oi(s){var i;const t={};return(((i=s.match(Ch))==null?void 0:i.map(r=>r.replace(/[{()}]/g,"")))??[]).forEach(r=>{t[r]=[]}),t}function Vi(s,t){let e;const i=/@in\s+([^;]+);/g;for(;(e=i.exec(s))!==null;)t.push(e[1])}function Wi(s,t,e=!1){const i=[];Vi(t,i),s.forEach(a=>{a.header&&Vi(a.header,i)});const r=i;e&&r.sort();const n=r.map((a,h)=>` @location(${h}) ${a},`).join(` +`);let o=t.replace(/@in\s+[^;]+;\s*/g,"");return o=o.replace("{{in}}",` +${n} +`),o}function Yi(s,t){let e;const i=/@out\s+([^;]+);/g;for(;(e=i.exec(s))!==null;)t.push(e[1])}function Th(s){const e=/\b(\w+)\s*:/g.exec(s);return e?e[1]:""}function Ah(s){const t=/@.*?\s+/g;return s.replace(t,"")}function kh(s,t){const e=[];Yi(t,e),s.forEach(h=>{h.header&&Yi(h.header,e)});let i=0;const r=e.sort().map(h=>h.indexOf("builtin")>-1?h:`@location(${i++}) ${h}`).join(`, +`),n=e.sort().map(h=>` var ${Ah(h)};`).join(` +`),o=`return VSOutput( + ${e.sort().map(h=>` ${Th(h)}`).join(`, +`)});`;let a=t.replace(/@out\s+[^;]+;\s*/g,"");return a=a.replace("{{struct}}",` +${r} +`),a=a.replace("{{start}}",` +${n} +`),a=a.replace("{{return}}",` +${o} +`),a}function Xi(s,t){let e=s;for(const i in t){const r=t[i];r.join(` +`).length?e=e.replace(`{{${i}}}`,`//-----${i} START-----// +${r.join(` +`)} +//----${i} FINISH----//`):e=e.replace(`{{${i}}}`,"")}return e}const St=Object.create(null),ds=new Map;let Eh=0;function Rh({template:s,bits:t}){const e=Tn(s,t);if(St[e])return St[e];const{vertex:i,fragment:r}=Bh(s,t);return St[e]=An(i,r,t),St[e]}function Ih({template:s,bits:t}){const e=Tn(s,t);return St[e]||(St[e]=An(s.vertex,s.fragment,t)),St[e]}function Bh(s,t){const e=t.map(o=>o.vertex).filter(o=>!!o),i=t.map(o=>o.fragment).filter(o=>!!o);let r=Wi(e,s.vertex,!0);r=kh(e,r);const n=Wi(i,s.fragment,!0);return{vertex:r,fragment:n}}function Tn(s,t){return t.map(e=>(ds.has(e)||ds.set(e,Eh++),ds.get(e))).sort((e,i)=>e-i).join("-")+s.vertex+s.fragment}function An(s,t,e){const i=Oi(s),r=Oi(t);return e.forEach(n=>{$i(n.vertex,i,n.name),$i(n.fragment,r,n.name)}),{vertex:Xi(s,i),fragment:Xi(t,r)}}const Fh=` + @in aPosition: vec2<f32>; + @in aUV: vec2<f32>; + + @out @builtin(position) vPosition: vec4<f32>; + @out vUV : vec2<f32>; + @out vColor : vec4<f32>; + + {{header}} + + struct VSOutput { + {{struct}} + }; + + @vertex + fn main( {{in}} ) -> VSOutput { + + var worldTransformMatrix = globalUniforms.uWorldTransformMatrix; + var modelMatrix = mat3x3<f32>( + 1.0, 0.0, 0.0, + 0.0, 1.0, 0.0, + 0.0, 0.0, 1.0 + ); + var position = aPosition; + var uv = aUV; + + {{start}} + + vColor = vec4<f32>(1., 1., 1., 1.); + + {{main}} + + vUV = uv; + + var modelViewProjectionMatrix = globalUniforms.uProjectionMatrix * worldTransformMatrix * modelMatrix; + + vPosition = vec4<f32>((modelViewProjectionMatrix * vec3<f32>(position, 1.0)).xy, 0.0, 1.0); + + vColor *= globalUniforms.uWorldColorAlpha; + + {{end}} + + {{return}} + }; +`,Gh=` + @in vUV : vec2<f32>; + @in vColor : vec4<f32>; + + {{header}} + + @fragment + fn main( + {{in}} + ) -> @location(0) vec4<f32> { + + {{start}} + + var outColor:vec4<f32>; + + {{main}} + + var finalColor:vec4<f32> = outColor * vColor; + + {{end}} + + return finalColor; + }; +`,Lh=` + in vec2 aPosition; + in vec2 aUV; + + out vec4 vColor; + out vec2 vUV; + + {{header}} + + void main(void){ + + mat3 worldTransformMatrix = uWorldTransformMatrix; + mat3 modelMatrix = mat3( + 1.0, 0.0, 0.0, + 0.0, 1.0, 0.0, + 0.0, 0.0, 1.0 + ); + vec2 position = aPosition; + vec2 uv = aUV; + + {{start}} + + vColor = vec4(1.); + + {{main}} + + vUV = uv; + + mat3 modelViewProjectionMatrix = uProjectionMatrix * worldTransformMatrix * modelMatrix; + + gl_Position = vec4((modelViewProjectionMatrix * vec3(position, 1.0)).xy, 0.0, 1.0); + + vColor *= uWorldColorAlpha; + + {{end}} + } +`,Dh=` + + in vec4 vColor; + in vec2 vUV; + + out vec4 finalColor; + + {{header}} + + void main(void) { + + {{start}} + + vec4 outColor; + + {{main}} + + finalColor = outColor * vColor; + + {{end}} + } +`,zh={name:"global-uniforms-bit",vertex:{header:` + struct GlobalUniforms { + uProjectionMatrix:mat3x3<f32>, + uWorldTransformMatrix:mat3x3<f32>, + uWorldColorAlpha: vec4<f32>, + uResolution: vec2<f32>, + } + + @group(0) @binding(0) var<uniform> globalUniforms : GlobalUniforms; + `}},Hh={name:"global-uniforms-bit",vertex:{header:` + uniform mat3 uProjectionMatrix; + uniform mat3 uWorldTransformMatrix; + uniform vec4 uWorldColorAlpha; + uniform vec2 uResolution; + `}};function Nh({bits:s,name:t}){const e=Rh({template:{fragment:Gh,vertex:Fh},bits:[zh,...s]});return Ye.from({name:t,vertex:{source:e.vertex,entryPoint:"main"},fragment:{source:e.fragment,entryPoint:"main"}})}function Uh({bits:s,name:t}){return new nn({name:t,...Ih({template:{vertex:Lh,fragment:Dh},bits:[Hh,...s]})})}const $h={name:"color-bit",vertex:{header:` + @in aColor: vec4<f32>; + `,main:` + vColor *= vec4<f32>(aColor.rgb * aColor.a, aColor.a); + `}},Oh={name:"color-bit",vertex:{header:` + in vec4 aColor; + `,main:` + vColor *= vec4(aColor.rgb * aColor.a, aColor.a); + `}},fs={};function Vh(s){const t=[];if(s===1)t.push("@group(1) @binding(0) var textureSource1: texture_2d<f32>;"),t.push("@group(1) @binding(1) var textureSampler1: sampler;");else{let e=0;for(let i=0;i<s;i++)t.push(`@group(1) @binding(${e++}) var textureSource${i+1}: texture_2d<f32>;`),t.push(`@group(1) @binding(${e++}) var textureSampler${i+1}: sampler;`)}return t.join(` +`)}function Wh(s){const t=[];if(s===1)t.push("outColor = textureSampleGrad(textureSource1, textureSampler1, vUV, uvDx, uvDy);");else{t.push("switch vTextureId {");for(let e=0;e<s;e++)e===s-1?t.push(" default:{"):t.push(` case ${e}:{`),t.push(` outColor = textureSampleGrad(textureSource${e+1}, textureSampler${e+1}, vUV, uvDx, uvDy);`),t.push(" break;}");t.push("}")}return t.join(` +`)}function Yh(s){return fs[s]||(fs[s]={name:"texture-batch-bit",vertex:{header:` + @in aTextureIdAndRound: vec2<u32>; + @out @interpolate(flat) vTextureId : u32; + `,main:` + vTextureId = aTextureIdAndRound.y; + `,end:` + if(aTextureIdAndRound.x == 1) + { + vPosition = vec4<f32>(roundPixels(vPosition.xy, globalUniforms.uResolution), vPosition.zw); + } + `},fragment:{header:` + @in @interpolate(flat) vTextureId: u32; + + ${Vh(s)} + `,main:` + var uvDx = dpdx(vUV); + var uvDy = dpdy(vUV); + + ${Wh(s)} + `}}),fs[s]}const ps={};function Xh(s){const t=[];for(let e=0;e<s;e++)e>0&&t.push("else"),e<s-1&&t.push(`if(vTextureId < ${e}.5)`),t.push("{"),t.push(` outColor = texture(uTextures[${e}], vUV);`),t.push("}");return t.join(` +`)}function jh(s){return ps[s]||(ps[s]={name:"texture-batch-bit",vertex:{header:` + in vec2 aTextureIdAndRound; + out float vTextureId; + + `,main:` + vTextureId = aTextureIdAndRound.y; + `,end:` + if(aTextureIdAndRound.x == 1.) + { + gl_Position.xy = roundPixels(gl_Position.xy, uResolution); + } + `},fragment:{header:` + in float vTextureId; + + uniform sampler2D uTextures[${s}]; + + `,main:` + + ${Xh(s)} + `}}),ps[s]}const qh={name:"round-pixels-bit",vertex:{header:` + fn roundPixels(position: vec2<f32>, targetSize: vec2<f32>) -> vec2<f32> + { + return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0; + } + `}},Zh={name:"round-pixels-bit",vertex:{header:` + vec2 roundPixels(vec2 position, vec2 targetSize) + { + return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0; + } + `}},ji={};function Kh(s){let t=ji[s];if(t)return t;const e=new Int32Array(s);for(let i=0;i<s;i++)e[i]=i;return t=ji[s]=new ln({uTextures:{value:e,type:"i32",size:s}},{isStatic:!0}),t}class Qh extends Ys{constructor(t){const e=Uh({name:"batch",bits:[Oh,jh(t),Zh]}),i=Nh({name:"batch",bits:[$h,Yh(t),qh]});super({glProgram:e,gpuProgram:i,resources:{batchSamplers:Kh(t)}})}}let ms=null;const kn=class En extends _h{constructor(t){super(t),this.geometry=new Mh,this.name=En.extension.name,this.vertexSize=6,ms??(ms=new Qh(t.maxTextures)),this.shader=ms}packAttributes(t,e,i,r,n){const o=n<<16|t.roundPixels&65535,a=t.transform,h=a.a,l=a.b,c=a.c,u=a.d,p=a.tx,d=a.ty,{positions:m,uvs:g}=t,f=t.color,x=t.attributeOffset,y=x+t.attributeSize;for(let _=x;_<y;_++){const b=_*2,v=m[b],S=m[b+1];e[r++]=h*v+c*S+p,e[r++]=u*S+l*v+d,e[r++]=g[b],e[r++]=g[b+1],i[r++]=f,i[r++]=o}}packQuadAttributes(t,e,i,r,n){const o=t.texture,a=t.transform,h=a.a,l=a.b,c=a.c,u=a.d,p=a.tx,d=a.ty,m=t.bounds,g=m.maxX,f=m.minX,x=m.maxY,y=m.minY,_=o.uvs,b=t.color,v=n<<16|t.roundPixels&65535;e[r+0]=h*f+c*y+p,e[r+1]=u*y+l*f+d,e[r+2]=_.x0,e[r+3]=_.y0,i[r+4]=b,i[r+5]=v,e[r+6]=h*g+c*y+p,e[r+7]=u*y+l*g+d,e[r+8]=_.x1,e[r+9]=_.y1,i[r+10]=b,i[r+11]=v,e[r+12]=h*g+c*x+p,e[r+13]=u*x+l*g+d,e[r+14]=_.x2,e[r+15]=_.y2,i[r+16]=b,i[r+17]=v,e[r+18]=h*f+c*x+p,e[r+19]=u*x+l*f+d,e[r+20]=_.x3,e[r+21]=_.y3,i[r+22]=b,i[r+23]=v}};kn.extension={type:[L.Batcher],name:"default"};let Jh=kn;function tl(s,t,e,i,r,n,o,a=null){let h=0;e*=t,r*=n;const l=a.a,c=a.b,u=a.c,p=a.d,d=a.tx,m=a.ty;for(;h<o;){const g=s[e],f=s[e+1];i[r]=l*g+u*f+d,i[r+1]=c*g+p*f+m,r+=n,e+=t,h++}}function el(s,t,e,i){let r=0;for(t*=e;r<i;)s[t]=0,s[t+1]=0,t+=e,r++}function Rn(s,t,e,i,r){const n=t.a,o=t.b,a=t.c,h=t.d,l=t.tx,c=t.ty;e||(e=0),i||(i=2),r||(r=s.length/i-e);let u=e*i;for(let p=0;p<r;p++){const d=s[u],m=s[u+1];s[u]=n*d+a*m+l,s[u+1]=o*d+h*m+c,u+=i}}const sl=new I;class In{constructor(){this.packAsQuad=!1,this.batcherName="default",this.topology="triangle-list",this.applyTransform=!0,this.roundPixels=0,this._batcher=null,this._batch=null}get uvs(){return this.geometryData.uvs}get positions(){return this.geometryData.vertices}get indices(){return this.geometryData.indices}get blendMode(){return this.renderable&&this.applyTransform?this.renderable.groupBlendMode:"normal"}get color(){const t=this.baseColor,e=t>>16|t&65280|(t&255)<<16,i=this.renderable;return i?Gr(e,i.groupColor)+(this.alpha*i.groupAlpha*255<<24):e+(this.alpha*255<<24)}get transform(){var t;return((t=this.renderable)==null?void 0:t.groupTransform)||sl}copyTo(t){t.indexOffset=this.indexOffset,t.indexSize=this.indexSize,t.attributeOffset=this.attributeOffset,t.attributeSize=this.attributeSize,t.baseColor=this.baseColor,t.alpha=this.alpha,t.texture=this.texture,t.geometryData=this.geometryData,t.topology=this.topology}reset(){this.applyTransform=!0,this.renderable=null,this.topology="triangle-list"}destroy(){this.renderable=null,this.texture=null,this.geometryData=null,this._batcher=null,this._batch=null}}const ye={extension:{type:L.ShapeBuilder,name:"circle"},build(s,t){let e,i,r,n,o,a;if(s.type==="circle"){const b=s;if(o=a=b.radius,o<=0)return!1;e=b.x,i=b.y,r=n=0}else if(s.type==="ellipse"){const b=s;if(o=b.halfWidth,a=b.halfHeight,o<=0||a<=0)return!1;e=b.x,i=b.y,r=n=0}else{const b=s,v=b.width/2,S=b.height/2;e=b.x+v,i=b.y+S,o=a=Math.max(0,Math.min(b.radius,Math.min(v,S))),r=v-o,n=S-a}if(r<0||n<0)return!1;const h=Math.ceil(2.3*Math.sqrt(o+a)),l=h*8+(r?4:0)+(n?4:0);if(l===0)return!1;if(h===0)return t[0]=t[6]=e+r,t[1]=t[3]=i+n,t[2]=t[4]=e-r,t[5]=t[7]=i-n,!0;let c=0,u=h*4+(r?2:0)+2,p=u,d=l,m=r+o,g=n,f=e+m,x=e-m,y=i+g;if(t[c++]=f,t[c++]=y,t[--u]=y,t[--u]=x,n){const b=i-g;t[p++]=x,t[p++]=b,t[--d]=b,t[--d]=f}for(let b=1;b<h;b++){const v=Math.PI/2*(b/h),S=r+Math.cos(v)*o,w=n+Math.sin(v)*a,R=e+S,k=e-S,P=i+w,M=i-w;t[c++]=R,t[c++]=P,t[--u]=P,t[--u]=k,t[p++]=k,t[p++]=M,t[--d]=M,t[--d]=R}m=r,g=n+a,f=e+m,x=e-m,y=i+g;const _=i-g;return t[c++]=f,t[c++]=y,t[--d]=_,t[--d]=f,r&&(t[c++]=x,t[c++]=y,t[--d]=_,t[--d]=x),!0},triangulate(s,t,e,i,r,n){if(s.length===0)return;let o=0,a=0;for(let c=0;c<s.length;c+=2)o+=s[c],a+=s[c+1];o/=s.length/2,a/=s.length/2;let h=i;t[h*e]=o,t[h*e+1]=a;const l=h++;for(let c=0;c<s.length;c+=2)t[h*e]=s[c],t[h*e+1]=s[c+1],c>0&&(r[n++]=h,r[n++]=l,r[n++]=h-1),h++;r[n++]=l+1,r[n++]=l,r[n++]=h-1}},il={...ye,extension:{...ye.extension,name:"ellipse"}},rl={...ye,extension:{...ye.extension,name:"roundedRectangle"}},Bn=1e-4,qi=1e-4;function nl(s){const t=s.length;if(t<6)return 1;let e=0;for(let i=0,r=s[t-2],n=s[t-1];i<t;i+=2){const o=s[i],a=s[i+1];e+=(o-r)*(a+n),r=o,n=a}return e<0?-1:1}function Zi(s,t,e,i,r,n,o,a){const h=s-e*r,l=t-i*r,c=s+e*n,u=t+i*n;let p,d;o?(p=i,d=-e):(p=-i,d=e);const m=h+p,g=l+d,f=c+p,x=u+d;return a.push(m,g),a.push(f,x),2}function Tt(s,t,e,i,r,n,o,a){const h=e-s,l=i-t;let c=Math.atan2(h,l),u=Math.atan2(r-s,n-t);a&&c<u?c+=Math.PI*2:!a&&c>u&&(u+=Math.PI*2);let p=c;const d=u-c,m=Math.abs(d),g=Math.sqrt(h*h+l*l),f=(15*m*Math.sqrt(g)/Math.PI>>0)+1,x=d/f;if(p+=x,a){o.push(s,t),o.push(e,i);for(let y=1,_=p;y<f;y++,_+=x)o.push(s,t),o.push(s+Math.sin(_)*g,t+Math.cos(_)*g);o.push(s,t),o.push(r,n)}else{o.push(e,i),o.push(s,t);for(let y=1,_=p;y<f;y++,_+=x)o.push(s+Math.sin(_)*g,t+Math.cos(_)*g),o.push(s,t);o.push(r,n),o.push(s,t)}return f*2}function ol(s,t,e,i,r,n){const o=Bn;if(s.length===0)return;const a=t;let h=a.alignment;if(t.alignment!==.5){let B=nl(s);h=(h-.5)*B+.5}const l=new Z(s[0],s[1]),c=new Z(s[s.length-2],s[s.length-1]),u=i,p=Math.abs(l.x-c.x)<o&&Math.abs(l.y-c.y)<o;if(u){s=s.slice(),p&&(s.pop(),s.pop(),c.set(s[s.length-2],s[s.length-1]));const B=(l.x+c.x)*.5,wt=(c.y+l.y)*.5;s.unshift(B,wt),s.push(B,wt)}const d=r,m=s.length/2;let g=s.length;const f=d.length/2,x=a.width/2,y=x*x,_=a.miterLimit*a.miterLimit;let b=s[0],v=s[1],S=s[2],w=s[3],R=0,k=0,P=-(v-w),M=b-S,G=0,E=0,N=Math.sqrt(P*P+M*M);P/=N,M/=N,P*=x,M*=x;const bt=h,C=(1-bt)*2,A=bt*2;u||(a.cap==="round"?g+=Tt(b-P*(C-A)*.5,v-M*(C-A)*.5,b-P*C,v-M*C,b+P*A,v+M*A,d,!0)+2:a.cap==="square"&&(g+=Zi(b,v,P,M,C,A,!0,d))),d.push(b-P*C,v-M*C),d.push(b+P*A,v+M*A);for(let B=1;B<m-1;++B){b=s[(B-1)*2],v=s[(B-1)*2+1],S=s[B*2],w=s[B*2+1],R=s[(B+1)*2],k=s[(B+1)*2+1],P=-(v-w),M=b-S,N=Math.sqrt(P*P+M*M),P/=N,M/=N,P*=x,M*=x,G=-(w-k),E=S-R,N=Math.sqrt(G*G+E*E),G/=N,E/=N,G*=x,E*=x;const wt=S-b,jt=v-w,qt=S-R,Zt=k-w,ei=wt*qt+jt*Zt,be=jt*qt-Zt*wt,Kt=be<0;if(Math.abs(be)<.001*Math.abs(ei)){d.push(S-P*C,w-M*C),d.push(S+P*A,w+M*A),ei>=0&&(a.join==="round"?g+=Tt(S,w,S-P*C,w-M*C,S-G*C,w-E*C,d,!1)+4:g+=2,d.push(S-G*A,w-E*A),d.push(S+G*C,w+E*C));continue}const si=(-P+b)*(-M+w)-(-P+S)*(-M+v),ii=(-G+R)*(-E+w)-(-G+S)*(-E+k),we=(wt*ii-qt*si)/be,Se=(Zt*si-jt*ii)/be,qe=(we-S)*(we-S)+(Se-w)*(Se-w),vt=S+(we-S)*C,Pt=w+(Se-w)*C,Mt=S-(we-S)*A,Ct=w-(Se-w)*A,On=Math.min(wt*wt+jt*jt,qt*qt+Zt*Zt),ri=Kt?C:A,Vn=On+ri*ri*y;qe<=Vn?a.join==="bevel"||qe/y>_?(Kt?(d.push(vt,Pt),d.push(S+P*A,w+M*A),d.push(vt,Pt),d.push(S+G*A,w+E*A)):(d.push(S-P*C,w-M*C),d.push(Mt,Ct),d.push(S-G*C,w-E*C),d.push(Mt,Ct)),g+=2):a.join==="round"?Kt?(d.push(vt,Pt),d.push(S+P*A,w+M*A),g+=Tt(S,w,S+P*A,w+M*A,S+G*A,w+E*A,d,!0)+4,d.push(vt,Pt),d.push(S+G*A,w+E*A)):(d.push(S-P*C,w-M*C),d.push(Mt,Ct),g+=Tt(S,w,S-P*C,w-M*C,S-G*C,w-E*C,d,!1)+4,d.push(S-G*C,w-E*C),d.push(Mt,Ct)):(d.push(vt,Pt),d.push(Mt,Ct)):(d.push(S-P*C,w-M*C),d.push(S+P*A,w+M*A),a.join==="round"?Kt?g+=Tt(S,w,S+P*A,w+M*A,S+G*A,w+E*A,d,!0)+2:g+=Tt(S,w,S-P*C,w-M*C,S-G*C,w-E*C,d,!1)+2:a.join==="miter"&&qe/y<=_&&(Kt?(d.push(Mt,Ct),d.push(Mt,Ct)):(d.push(vt,Pt),d.push(vt,Pt)),g+=2),d.push(S-G*C,w-E*C),d.push(S+G*A,w+E*A),g+=2)}b=s[(m-2)*2],v=s[(m-2)*2+1],S=s[(m-1)*2],w=s[(m-1)*2+1],P=-(v-w),M=b-S,N=Math.sqrt(P*P+M*M),P/=N,M/=N,P*=x,M*=x,d.push(S-P*C,w-M*C),d.push(S+P*A,w+M*A),u||(a.cap==="round"?g+=Tt(S-P*(C-A)*.5,w-M*(C-A)*.5,S-P*C,w-M*C,S+P*A,w+M*A,d,!1)+2:a.cap==="square"&&(g+=Zi(S,w,P,M,C,A,!1,d)));const Xt=qi*qi;for(let B=f;B<g+f-2;++B)b=d[B*2],v=d[B*2+1],S=d[(B+1)*2],w=d[(B+1)*2+1],R=d[(B+2)*2],k=d[(B+2)*2+1],!(Math.abs(b*(w-k)+S*(k-v)+R*(v-w))<Xt)&&n.push(B,B+1,B+2)}function al(s,t,e,i){const r=Bn;if(s.length===0)return;const n=s[0],o=s[1],a=s[s.length-2],h=s[s.length-1],l=t||Math.abs(n-a)<r&&Math.abs(o-h)<r,c=e,u=s.length/2,p=c.length/2;for(let d=0;d<u;d++)c.push(s[d*2]),c.push(s[d*2+1]);for(let d=0;d<u-1;d++)i.push(p+d,p+d+1);l&&i.push(p+u-1,p)}function Fn(s,t,e,i,r,n,o){const a=$a(s,t,2);if(!a)return;for(let l=0;l<a.length;l+=3)n[o++]=a[l]+r,n[o++]=a[l+1]+r,n[o++]=a[l+2]+r;let h=r*i;for(let l=0;l<s.length;l+=2)e[h]=s[l],e[h+1]=s[l+1],h+=i}const hl=[],ll={extension:{type:L.ShapeBuilder,name:"polygon"},build(s,t){for(let e=0;e<s.points.length;e++)t[e]=s.points[e];return!0},triangulate(s,t,e,i,r,n){Fn(s,hl,t,e,i,r,n)}},cl={extension:{type:L.ShapeBuilder,name:"rectangle"},build(s,t){const e=s,i=e.x,r=e.y,n=e.width,o=e.height;return n>0&&o>0?(t[0]=i,t[1]=r,t[2]=i+n,t[3]=r,t[4]=i+n,t[5]=r+o,t[6]=i,t[7]=r+o,!0):!1},triangulate(s,t,e,i,r,n){let o=0;i*=e,t[i+o]=s[0],t[i+o+1]=s[1],o+=e,t[i+o]=s[2],t[i+o+1]=s[3],o+=e,t[i+o]=s[6],t[i+o+1]=s[7],o+=e,t[i+o]=s[4],t[i+o+1]=s[5],o+=e;const a=i/e;r[n++]=a,r[n++]=a+1,r[n++]=a+2,r[n++]=a+1,r[n++]=a+3,r[n++]=a+2}},ul={extension:{type:L.ShapeBuilder,name:"triangle"},build(s,t){return t[0]=s.x,t[1]=s.y,t[2]=s.x2,t[3]=s.y2,t[4]=s.x3,t[5]=s.y3,!0},triangulate(s,t,e,i,r,n){let o=0;i*=e,t[i+o]=s[0],t[i+o+1]=s[1],o+=e,t[i+o]=s[2],t[i+o+1]=s[3],o+=e,t[i+o]=s[4],t[i+o+1]=s[5];const a=i/e;r[n++]=a,r[n++]=a+1,r[n++]=a+2}},dl=new I,fl=new W;function pl(s,t,e,i){const r=t.matrix?s.copyFrom(t.matrix).invert():s.identity();if(t.textureSpace==="local"){const o=e.getBounds(fl);t.width&&o.pad(t.width);const{x:a,y:h}=o,l=1/o.width,c=1/o.height,u=-a*l,p=-h*c,d=r.a,m=r.b,g=r.c,f=r.d;r.a*=l,r.b*=l,r.c*=c,r.d*=c,r.tx=u*d+p*g+r.tx,r.ty=u*m+p*f+r.ty}else r.translate(t.texture.frame.x,t.texture.frame.y),r.scale(1/t.texture.source.width,1/t.texture.source.height);const n=t.texture.source.style;return!(t.fill instanceof _t)&&n.addressMode==="clamp-to-edge"&&(n.addressMode="repeat",n.update()),i&&r.append(dl.copyFrom(i).invert()),r}const je={};rt.handleByMap(L.ShapeBuilder,je);rt.add(cl,ll,ul,ye,il,rl);const ml=new W,gl=new I;function xl(s,t){const{geometryData:e,batches:i}=t;i.length=0,e.indices.length=0,e.vertices.length=0,e.uvs.length=0;for(let r=0;r<s.instructions.length;r++){const n=s.instructions[r];if(n.action==="texture")yl(n.data,i,e);else if(n.action==="fill"||n.action==="stroke"){const o=n.action==="stroke",a=n.data.path.shapePath,h=n.data.style,l=n.data.hole;o&&l&&Ki(l.shapePath,h,!0,i,e),l&&(a.shapePrimitives[a.shapePrimitives.length-1].holes=l.shapePath.shapePrimitives),Ki(a,h,o,i,e)}}}function yl(s,t,e){const i=[],r=je.rectangle,n=ml;n.x=s.dx,n.y=s.dy,n.width=s.dw,n.height=s.dh;const o=s.transform;if(!r.build(n,i))return;const{vertices:a,uvs:h,indices:l}=e,c=l.length,u=a.length/2;o&&Rn(i,o),r.triangulate(i,a,2,u,l,c);const p=s.image,d=p.uvs;h.push(d.x0,d.y0,d.x1,d.y1,d.x3,d.y3,d.x2,d.y2);const m=it.get(In);m.indexOffset=c,m.indexSize=l.length-c,m.attributeOffset=u,m.attributeSize=a.length/2-u,m.baseColor=s.style,m.alpha=s.alpha,m.texture=p,m.geometryData=e,t.push(m)}function Ki(s,t,e,i,r){const{vertices:n,uvs:o,indices:a}=r;s.shapePrimitives.forEach(({shape:h,transform:l,holes:c})=>{const u=[],p=je[h.type];if(!p.build(h,u))return;const d=a.length,m=n.length/2;let g="triangle-list";if(l&&Rn(u,l),e){const _=h.closePath??!0,b=t;b.pixelLine?(al(u,_,n,a),g="line-list"):ol(u,b,!1,_,n,a)}else if(c){const _=[],b=u.slice();_l(c).forEach(S=>{_.push(b.length/2),b.push(...S)}),Fn(b,_,n,2,m,a,d)}else p.triangulate(u,n,2,m,a,d);const f=o.length/2,x=t.texture;if(x!==D.WHITE){const _=pl(gl,t,h,l);tl(n,2,m,o,f,2,n.length/2-m,_)}else el(o,f,2,n.length/2-m);const y=it.get(In);y.indexOffset=d,y.indexSize=a.length-d,y.attributeOffset=m,y.attributeSize=n.length/2-m,y.baseColor=t.color,y.alpha=t.alpha,y.texture=x,y.geometryData=r,y.topology=g,i.push(y)})}function _l(s){const t=[];for(let e=0;e<s.length;e++){const i=s[e].shape,r=[];je[i.type].build(i,r)&&t.push(r)}return t}class bl{constructor(){this.batches=[],this.geometryData={vertices:[],uvs:[],indices:[]}}}class wl{constructor(){this.instructions=new Hr}init(t){this.batcher=new Jh({maxTextures:t}),this.instructions.reset()}get geometry(){return F(co,"GraphicsContextRenderData#geometry is deprecated, please use batcher.geometry instead."),this.batcher.geometry}destroy(){this.batcher.destroy(),this.instructions.destroy(),this.batcher=null,this.instructions=null}}const Ks=class Is{constructor(t){this._gpuContextHash={},this._graphicsDataContextHash=Object.create(null),this._renderer=t,t.renderableGC.addManagedHash(this,"_gpuContextHash"),t.renderableGC.addManagedHash(this,"_graphicsDataContextHash")}init(t){Is.defaultOptions.bezierSmoothness=(t==null?void 0:t.bezierSmoothness)??Is.defaultOptions.bezierSmoothness}getContextRenderData(t){return this._graphicsDataContextHash[t.uid]||this._initContextRenderData(t)}updateGpuContext(t){let e=this._gpuContextHash[t.uid]||this._initContext(t);if(t.dirty){e?this._cleanGraphicsContextData(t):e=this._initContext(t),xl(t,e);const i=t.batchMode;t.customShader||i==="no-batch"?e.isBatchable=!1:i==="auto"?e.isBatchable=e.geometryData.vertices.length<400:e.isBatchable=!0,t.dirty=!1}return e}getGpuContext(t){return this._gpuContextHash[t.uid]||this._initContext(t)}_initContextRenderData(t){const e=it.get(wl,{maxTextures:this._renderer.limits.maxBatchableTextures}),{batches:i,geometryData:r}=this._gpuContextHash[t.uid],n=r.vertices.length,o=r.indices.length;for(let c=0;c<i.length;c++)i[c].applyTransform=!1;const a=e.batcher;a.ensureAttributeBuffer(n),a.ensureIndexBuffer(o),a.begin();for(let c=0;c<i.length;c++){const u=i[c];a.add(u)}a.finish(e.instructions);const h=a.geometry;h.indexBuffer.setDataWithSize(a.indexBuffer,a.indexSize,!0),h.buffers[0].setDataWithSize(a.attributeBuffer.float32View,a.attributeSize,!0);const l=a.batches;for(let c=0;c<l.length;c++){const u=l[c];u.bindGroup=lh(u.textures.textures,u.textures.count,this._renderer.limits.maxBatchableTextures)}return this._graphicsDataContextHash[t.uid]=e,e}_initContext(t){const e=new bl;return e.context=t,this._gpuContextHash[t.uid]=e,t.on("destroy",this.onGraphicsContextDestroy,this),this._gpuContextHash[t.uid]}onGraphicsContextDestroy(t){this._cleanGraphicsContextData(t),t.off("destroy",this.onGraphicsContextDestroy,this),this._gpuContextHash[t.uid]=null}_cleanGraphicsContextData(t){const e=this._gpuContextHash[t.uid];e.isBatchable||this._graphicsDataContextHash[t.uid]&&(it.return(this.getContextRenderData(t)),this._graphicsDataContextHash[t.uid]=null),e.batches&&e.batches.forEach(i=>{it.return(i)})}destroy(){for(const t in this._gpuContextHash)this._gpuContextHash[t]&&this.onGraphicsContextDestroy(this._gpuContextHash[t].context)}};Ks.extension={type:[L.WebGLSystem,L.WebGPUSystem,L.CanvasSystem],name:"graphicsContext"};Ks.defaultOptions={bezierSmoothness:.5};let Gn=Ks;const Sl=8,Le=11920929e-14,vl=1;function Ln(s,t,e,i,r,n,o,a,h,l){const u=Math.min(.99,Math.max(0,l??Gn.defaultOptions.bezierSmoothness));let p=(vl-u)/1;return p*=p,Pl(t,e,i,r,n,o,a,h,s,p),s}function Pl(s,t,e,i,r,n,o,a,h,l){Bs(s,t,e,i,r,n,o,a,h,l,0),h.push(o,a)}function Bs(s,t,e,i,r,n,o,a,h,l,c){if(c>Sl)return;const u=(s+e)/2,p=(t+i)/2,d=(e+r)/2,m=(i+n)/2,g=(r+o)/2,f=(n+a)/2,x=(u+d)/2,y=(p+m)/2,_=(d+g)/2,b=(m+f)/2,v=(x+_)/2,S=(y+b)/2;if(c>0){let w=o-s,R=a-t;const k=Math.abs((e-o)*R-(i-a)*w),P=Math.abs((r-o)*R-(n-a)*w);if(k>Le&&P>Le){if((k+P)*(k+P)<=l*(w*w+R*R)){h.push(v,S);return}}else if(k>Le){if(k*k<=l*(w*w+R*R)){h.push(v,S);return}}else if(P>Le){if(P*P<=l*(w*w+R*R)){h.push(v,S);return}}else if(w=v-(s+o)/2,R=S-(t+a)/2,w*w+R*R<=l){h.push(v,S);return}}Bs(s,t,u,p,x,y,v,S,h,l,c+1),Bs(v,S,_,b,g,f,o,a,h,l,c+1)}const Ml=8,Cl=11920929e-14,Tl=1;function Al(s,t,e,i,r,n,o,a){const l=Math.min(.99,Math.max(0,a??Gn.defaultOptions.bezierSmoothness));let c=(Tl-l)/1;return c*=c,kl(t,e,i,r,n,o,s,c),s}function kl(s,t,e,i,r,n,o,a){Fs(o,s,t,e,i,r,n,a,0),o.push(r,n)}function Fs(s,t,e,i,r,n,o,a,h){if(h>Ml)return;const l=(t+i)/2,c=(e+r)/2,u=(i+n)/2,p=(r+o)/2,d=(l+u)/2,m=(c+p)/2;let g=n-t,f=o-e;const x=Math.abs((i-n)*f-(r-o)*g);if(x>Cl){if(x*x<=a*(g*g+f*f)){s.push(d,m);return}}else if(g=d-(t+n)/2,f=m-(e+o)/2,g*g+f*f<=a){s.push(d,m);return}Fs(s,t,e,l,c,d,m,a,h+1),Fs(s,d,m,u,p,n,o,a,h+1)}function Dn(s,t,e,i,r,n,o,a){let h=Math.abs(r-n);(!o&&r>n||o&&n>r)&&(h=2*Math.PI-h),a||(a=Math.max(6,Math.floor(6*Math.pow(i,1/3)*(h/Math.PI)))),a=Math.max(a,3);let l=h/a,c=r;l*=o?-1:1;for(let u=0;u<a+1;u++){const p=Math.cos(c),d=Math.sin(c),m=t+p*i,g=e+d*i;s.push(m,g),c+=l}}function El(s,t,e,i,r,n){const o=s[s.length-2],h=s[s.length-1]-e,l=o-t,c=r-e,u=i-t,p=Math.abs(h*u-l*c);if(p<1e-8||n===0){(s[s.length-2]!==t||s[s.length-1]!==e)&&s.push(t,e);return}const d=h*h+l*l,m=c*c+u*u,g=h*c+l*u,f=n*Math.sqrt(d)/p,x=n*Math.sqrt(m)/p,y=f*g/d,_=x*g/m,b=f*u+x*l,v=f*c+x*h,S=l*(x+y),w=h*(x+y),R=u*(f+_),k=c*(f+_),P=Math.atan2(w-v,S-b),M=Math.atan2(k-v,R-b);Dn(s,b+t,v+e,n,P,M,l*c>u*h)}const ue=Math.PI*2,gs={centerX:0,centerY:0,ang1:0,ang2:0},xs=({x:s,y:t},e,i,r,n,o,a,h)=>{s*=e,t*=i;const l=r*s-n*t,c=n*s+r*t;return h.x=l+o,h.y=c+a,h};function Rl(s,t){const e=t===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(t/4),i=t===1.5707963267948966?.551915024494:e,r=Math.cos(s),n=Math.sin(s),o=Math.cos(s+t),a=Math.sin(s+t);return[{x:r-n*i,y:n+r*i},{x:o+a*i,y:a-o*i},{x:o,y:a}]}const Qi=(s,t,e,i)=>{const r=s*i-t*e<0?-1:1;let n=s*e+t*i;return n>1&&(n=1),n<-1&&(n=-1),r*Math.acos(n)},Il=(s,t,e,i,r,n,o,a,h,l,c,u,p)=>{const d=Math.pow(r,2),m=Math.pow(n,2),g=Math.pow(c,2),f=Math.pow(u,2);let x=d*m-d*f-m*g;x<0&&(x=0),x/=d*f+m*g,x=Math.sqrt(x)*(o===a?-1:1);const y=x*r/n*u,_=x*-n/r*c,b=l*y-h*_+(s+e)/2,v=h*y+l*_+(t+i)/2,S=(c-y)/r,w=(u-_)/n,R=(-c-y)/r,k=(-u-_)/n,P=Qi(1,0,S,w);let M=Qi(S,w,R,k);a===0&&M>0&&(M-=ue),a===1&&M<0&&(M+=ue),p.centerX=b,p.centerY=v,p.ang1=P,p.ang2=M};function Bl(s,t,e,i,r,n,o,a=0,h=0,l=0){if(n===0||o===0)return;const c=Math.sin(a*ue/360),u=Math.cos(a*ue/360),p=u*(t-i)/2+c*(e-r)/2,d=-c*(t-i)/2+u*(e-r)/2;if(p===0&&d===0)return;n=Math.abs(n),o=Math.abs(o);const m=Math.pow(p,2)/Math.pow(n,2)+Math.pow(d,2)/Math.pow(o,2);m>1&&(n*=Math.sqrt(m),o*=Math.sqrt(m)),Il(t,e,i,r,n,o,h,l,c,u,p,d,gs);let{ang1:g,ang2:f}=gs;const{centerX:x,centerY:y}=gs;let _=Math.abs(f)/(ue/4);Math.abs(1-_)<1e-7&&(_=1);const b=Math.max(Math.ceil(_),1);f/=b;let v=s[s.length-2],S=s[s.length-1];const w={x:0,y:0};for(let R=0;R<b;R++){const k=Rl(g,f),{x:P,y:M}=xs(k[0],n,o,u,c,x,y,w),{x:G,y:E}=xs(k[1],n,o,u,c,x,y,w),{x:N,y:bt}=xs(k[2],n,o,u,c,x,y,w);Ln(s,v,S,P,M,G,E,N,bt),v=N,S=bt,g+=f}}function Fl(s,t,e){const i=(o,a)=>{const h=a.x-o.x,l=a.y-o.y,c=Math.sqrt(h*h+l*l),u=h/c,p=l/c;return{len:c,nx:u,ny:p}},r=(o,a)=>{o===0?s.moveTo(a.x,a.y):s.lineTo(a.x,a.y)};let n=t[t.length-1];for(let o=0;o<t.length;o++){const a=t[o%t.length],h=a.radius??e;if(h<=0){r(o,a),n=a;continue}const l=t[(o+1)%t.length],c=i(a,n),u=i(a,l);if(c.len<1e-4||u.len<1e-4){r(o,a),n=a;continue}let p=Math.asin(c.nx*u.ny-c.ny*u.nx),d=1,m=!1;c.nx*u.nx-c.ny*-u.ny<0?p<0?p=Math.PI+p:(p=Math.PI-p,d=-1,m=!0):p>0&&(d=-1,m=!0);const g=p/2;let f,x=Math.abs(Math.cos(g)*h/Math.sin(g));x>Math.min(c.len/2,u.len/2)?(x=Math.min(c.len/2,u.len/2),f=Math.abs(x*Math.sin(g)/Math.cos(g))):f=h;const y=a.x+u.nx*x+-u.ny*f*d,_=a.y+u.ny*x+u.nx*f*d,b=Math.atan2(c.ny,c.nx)+Math.PI/2*d,v=Math.atan2(u.ny,u.nx)-Math.PI/2*d;o===0&&s.moveTo(y+Math.cos(b)*f,_+Math.sin(b)*f),s.arc(y,_,f,b,v,m),n=a}}function Gl(s,t,e,i){const r=(a,h)=>Math.sqrt((a.x-h.x)**2+(a.y-h.y)**2),n=(a,h,l)=>({x:a.x+(h.x-a.x)*l,y:a.y+(h.y-a.y)*l}),o=t.length;for(let a=0;a<o;a++){const h=t[(a+1)%o],l=h.radius??e;if(l<=0){a===0?s.moveTo(h.x,h.y):s.lineTo(h.x,h.y);continue}const c=t[a],u=t[(a+2)%o],p=r(c,h);let d;if(p<1e-4)d=h;else{const f=Math.min(p/2,l);d=n(h,c,f/p)}const m=r(u,h);let g;if(m<1e-4)g=h;else{const f=Math.min(m/2,l);g=n(h,u,f/m)}a===0?s.moveTo(d.x,d.y):s.lineTo(d.x,d.y),s.quadraticCurveTo(h.x,h.y,g.x,g.y,i)}}const Ll=new W;class Dl{constructor(t){this.shapePrimitives=[],this._currentPoly=null,this._bounds=new at,this._graphicsPath2D=t,this.signed=t.checkForHoles}moveTo(t,e){return this.startPoly(t,e),this}lineTo(t,e){this._ensurePoly();const i=this._currentPoly.points,r=i[i.length-2],n=i[i.length-1];return(r!==t||n!==e)&&i.push(t,e),this}arc(t,e,i,r,n,o){this._ensurePoly(!1);const a=this._currentPoly.points;return Dn(a,t,e,i,r,n,o),this}arcTo(t,e,i,r,n){this._ensurePoly();const o=this._currentPoly.points;return El(o,t,e,i,r,n),this}arcToSvg(t,e,i,r,n,o,a){const h=this._currentPoly.points;return Bl(h,this._currentPoly.lastX,this._currentPoly.lastY,o,a,t,e,i,r,n),this}bezierCurveTo(t,e,i,r,n,o,a){this._ensurePoly();const h=this._currentPoly;return Ln(this._currentPoly.points,h.lastX,h.lastY,t,e,i,r,n,o,a),this}quadraticCurveTo(t,e,i,r,n){this._ensurePoly();const o=this._currentPoly;return Al(this._currentPoly.points,o.lastX,o.lastY,t,e,i,r,n),this}closePath(){return this.endPoly(!0),this}addPath(t,e){this.endPoly(),e&&!e.isIdentity()&&(t=t.clone(!0),t.transform(e));const i=this.shapePrimitives,r=i.length;for(let n=0;n<t.instructions.length;n++){const o=t.instructions[n];this[o.action](...o.data)}if(t.checkForHoles&&i.length-r>1){let n=null;for(let o=r;o<i.length;o++){const a=i[o];if(a.shape.type==="polygon"){const h=a.shape,l=n==null?void 0:n.shape;l&&l.containsPolygon(h)?(n.holes||(n.holes=[]),n.holes.push(a),i.copyWithin(o,o+1),i.length--,o--):n=a}}}return this}finish(t=!1){this.endPoly(t)}rect(t,e,i,r,n){return this.drawShape(new W(t,e,i,r),n),this}circle(t,e,i,r){return this.drawShape(new js(t,e,i),r),this}poly(t,e,i){const r=new le(t);return r.closePath=e,this.drawShape(r,i),this}regularPoly(t,e,i,r,n=0,o){r=Math.max(r|0,3);const a=-1*Math.PI/2+n,h=Math.PI*2/r,l=[];for(let c=0;c<r;c++){const u=a-c*h;l.push(t+i*Math.cos(u),e+i*Math.sin(u))}return this.poly(l,!0,o),this}roundPoly(t,e,i,r,n,o=0,a){if(r=Math.max(r|0,3),n<=0)return this.regularPoly(t,e,i,r,o);const h=i*Math.sin(Math.PI/r)-.001;n=Math.min(n,h);const l=-1*Math.PI/2+o,c=Math.PI*2/r,u=(r-2)*Math.PI/r/2;for(let p=0;p<r;p++){const d=p*c+l,m=t+i*Math.cos(d),g=e+i*Math.sin(d),f=d+Math.PI+u,x=d-Math.PI-u,y=m+n*Math.cos(f),_=g+n*Math.sin(f),b=m+n*Math.cos(x),v=g+n*Math.sin(x);p===0?this.moveTo(y,_):this.lineTo(y,_),this.quadraticCurveTo(m,g,b,v,a)}return this.closePath()}roundShape(t,e,i=!1,r){return t.length<3?this:(i?Gl(this,t,e,r):Fl(this,t,e),this.closePath())}filletRect(t,e,i,r,n){if(n===0)return this.rect(t,e,i,r);const o=Math.min(i,r)/2,a=Math.min(o,Math.max(-o,n)),h=t+i,l=e+r,c=a<0?-a:0,u=Math.abs(a);return this.moveTo(t,e+u).arcTo(t+c,e+c,t+u,e,u).lineTo(h-u,e).arcTo(h-c,e+c,h,e+u,u).lineTo(h,l-u).arcTo(h-c,l-c,t+i-u,l,u).lineTo(t+u,l).arcTo(t+c,l-c,t,l-u,u).closePath()}chamferRect(t,e,i,r,n,o){if(n<=0)return this.rect(t,e,i,r);const a=Math.min(n,Math.min(i,r)/2),h=t+i,l=e+r,c=[t+a,e,h-a,e,h,e+a,h,l-a,h-a,l,t+a,l,t,l-a,t,e+a];for(let u=c.length-1;u>=2;u-=2)c[u]===c[u-2]&&c[u-1]===c[u-3]&&c.splice(u-1,2);return this.poly(c,!0,o)}ellipse(t,e,i,r,n){return this.drawShape(new qs(t,e,i,r),n),this}roundRect(t,e,i,r,n,o){return this.drawShape(new Zs(t,e,i,r,n),o),this}drawShape(t,e){return this.endPoly(),this.shapePrimitives.push({shape:t,transform:e}),this}startPoly(t,e){let i=this._currentPoly;return i&&this.endPoly(),i=new le,i.points.push(t,e),this._currentPoly=i,this}endPoly(t=!1){const e=this._currentPoly;return e&&e.points.length>2&&(e.closePath=t,this.shapePrimitives.push({shape:e})),this._currentPoly=null,this}_ensurePoly(t=!0){if(!this._currentPoly&&(this._currentPoly=new le,t)){const e=this.shapePrimitives[this.shapePrimitives.length-1];if(e){let i=e.shape.x,r=e.shape.y;if(e.transform&&!e.transform.isIdentity()){const n=e.transform,o=i;i=n.a*i+n.c*r+n.tx,r=n.b*o+n.d*r+n.ty}this._currentPoly.points.push(i,r)}else this._currentPoly.points.push(0,0)}}buildPath(){const t=this._graphicsPath2D;this.shapePrimitives.length=0,this._currentPoly=null;for(let e=0;e<t.instructions.length;e++){const i=t.instructions[e];this[i.action](...i.data)}this.finish()}get bounds(){const t=this._bounds;t.clear();const e=this.shapePrimitives;for(let i=0;i<e.length;i++){const r=e[i],n=r.shape.getBounds(Ll);r.transform?t.addRect(n,r.transform):t.addRect(n)}return t}}class yt{constructor(t,e=!1){this.instructions=[],this.uid=V("graphicsPath"),this._dirty=!0,this.checkForHoles=e,typeof t=="string"?nh(t,this):this.instructions=(t==null?void 0:t.slice())??[]}get shapePath(){return this._shapePath||(this._shapePath=new Dl(this)),this._dirty&&(this._dirty=!1,this._shapePath.buildPath()),this._shapePath}addPath(t,e){return t=t.clone(),this.instructions.push({action:"addPath",data:[t,e]}),this._dirty=!0,this}arc(...t){return this.instructions.push({action:"arc",data:t}),this._dirty=!0,this}arcTo(...t){return this.instructions.push({action:"arcTo",data:t}),this._dirty=!0,this}arcToSvg(...t){return this.instructions.push({action:"arcToSvg",data:t}),this._dirty=!0,this}bezierCurveTo(...t){return this.instructions.push({action:"bezierCurveTo",data:t}),this._dirty=!0,this}bezierCurveToShort(t,e,i,r,n){const o=this.instructions[this.instructions.length-1],a=this.getLastPoint(Z.shared);let h=0,l=0;if(!o||o.action!=="bezierCurveTo")h=a.x,l=a.y;else{h=o.data[2],l=o.data[3];const c=a.x,u=a.y;h=c+(c-h),l=u+(u-l)}return this.instructions.push({action:"bezierCurveTo",data:[h,l,t,e,i,r,n]}),this._dirty=!0,this}closePath(){return this.instructions.push({action:"closePath",data:[]}),this._dirty=!0,this}ellipse(...t){return this.instructions.push({action:"ellipse",data:t}),this._dirty=!0,this}lineTo(...t){return this.instructions.push({action:"lineTo",data:t}),this._dirty=!0,this}moveTo(...t){return this.instructions.push({action:"moveTo",data:t}),this}quadraticCurveTo(...t){return this.instructions.push({action:"quadraticCurveTo",data:t}),this._dirty=!0,this}quadraticCurveToShort(t,e,i){const r=this.instructions[this.instructions.length-1],n=this.getLastPoint(Z.shared);let o=0,a=0;if(!r||r.action!=="quadraticCurveTo")o=n.x,a=n.y;else{o=r.data[0],a=r.data[1];const h=n.x,l=n.y;o=h+(h-o),a=l+(l-a)}return this.instructions.push({action:"quadraticCurveTo",data:[o,a,t,e,i]}),this._dirty=!0,this}rect(t,e,i,r,n){return this.instructions.push({action:"rect",data:[t,e,i,r,n]}),this._dirty=!0,this}circle(t,e,i,r){return this.instructions.push({action:"circle",data:[t,e,i,r]}),this._dirty=!0,this}roundRect(...t){return this.instructions.push({action:"roundRect",data:t}),this._dirty=!0,this}poly(...t){return this.instructions.push({action:"poly",data:t}),this._dirty=!0,this}regularPoly(...t){return this.instructions.push({action:"regularPoly",data:t}),this._dirty=!0,this}roundPoly(...t){return this.instructions.push({action:"roundPoly",data:t}),this._dirty=!0,this}roundShape(...t){return this.instructions.push({action:"roundShape",data:t}),this._dirty=!0,this}filletRect(...t){return this.instructions.push({action:"filletRect",data:t}),this._dirty=!0,this}chamferRect(...t){return this.instructions.push({action:"chamferRect",data:t}),this._dirty=!0,this}star(t,e,i,r,n,o,a){n||(n=r/2);const h=-1*Math.PI/2+o,l=i*2,c=Math.PI*2/l,u=[];for(let p=0;p<l;p++){const d=p%2?n:r,m=p*c+h;u.push(t+d*Math.cos(m),e+d*Math.sin(m))}return this.poly(u,!0,a),this}clone(t=!1){const e=new yt;if(e.checkForHoles=this.checkForHoles,!t)e.instructions=this.instructions.slice();else for(let i=0;i<this.instructions.length;i++){const r=this.instructions[i];e.instructions.push({action:r.action,data:r.data.slice()})}return e}clear(){return this.instructions.length=0,this._dirty=!0,this}transform(t){if(t.isIdentity())return this;const e=t.a,i=t.b,r=t.c,n=t.d,o=t.tx,a=t.ty;let h=0,l=0,c=0,u=0,p=0,d=0,m=0,g=0;for(let f=0;f<this.instructions.length;f++){const x=this.instructions[f],y=x.data;switch(x.action){case"moveTo":case"lineTo":h=y[0],l=y[1],y[0]=e*h+r*l+o,y[1]=i*h+n*l+a;break;case"bezierCurveTo":c=y[0],u=y[1],p=y[2],d=y[3],h=y[4],l=y[5],y[0]=e*c+r*u+o,y[1]=i*c+n*u+a,y[2]=e*p+r*d+o,y[3]=i*p+n*d+a,y[4]=e*h+r*l+o,y[5]=i*h+n*l+a;break;case"quadraticCurveTo":c=y[0],u=y[1],h=y[2],l=y[3],y[0]=e*c+r*u+o,y[1]=i*c+n*u+a,y[2]=e*h+r*l+o,y[3]=i*h+n*l+a;break;case"arcToSvg":h=y[5],l=y[6],m=y[0],g=y[1],y[0]=e*m+r*g,y[1]=i*m+n*g,y[5]=e*h+r*l+o,y[6]=i*h+n*l+a;break;case"circle":y[4]=ie(y[3],t);break;case"rect":y[4]=ie(y[4],t);break;case"ellipse":y[8]=ie(y[8],t);break;case"roundRect":y[5]=ie(y[5],t);break;case"addPath":y[0].transform(t);break;case"poly":y[2]=ie(y[2],t);break;default:Q("unknown transform action",x.action);break}}return this._dirty=!0,this}get bounds(){return this.shapePath.bounds}getLastPoint(t){let e=this.instructions.length-1,i=this.instructions[e];if(!i)return t.x=0,t.y=0,t;for(;i.action==="closePath";){if(e--,e<0)return t.x=0,t.y=0,t;i=this.instructions[e]}switch(i.action){case"moveTo":case"lineTo":t.x=i.data[0],t.y=i.data[1];break;case"quadraticCurveTo":t.x=i.data[2],t.y=i.data[3];break;case"bezierCurveTo":t.x=i.data[4],t.y=i.data[5];break;case"arc":case"arcToSvg":t.x=i.data[5],t.y=i.data[6];break;case"addPath":i.data[0].getLastPoint(t);break}return t}}function ie(s,t){return s?s.prepend(t):t.clone()}function $(s,t,e){const i=s.getAttribute(t);return i?Number(i):e}function zl(s,t){const e=s.querySelectorAll("defs");for(let i=0;i<e.length;i++){const r=e[i];for(let n=0;n<r.children.length;n++){const o=r.children[n];switch(o.nodeName.toLowerCase()){case"lineargradient":t.defs[o.id]=Hl(o);break;case"radialgradient":t.defs[o.id]=Nl();break}}}}function Hl(s){const t=$(s,"x1",0),e=$(s,"y1",0),i=$(s,"x2",1),r=$(s,"y2",0),n=s.getAttribute("gradientUnits")||"objectBoundingBox",o=new _t(t,e,i,r,n==="objectBoundingBox"?"local":"global");for(let a=0;a<s.children.length;a++){const h=s.children[a],l=$(h,"offset",0),c=Y.shared.setValue(h.getAttribute("stop-color")).toNumber();o.addColorStop(l,c)}return o}function Nl(s){return Q("[SVG Parser] Radial gradients are not yet supported"),new _t(0,0,1,0)}function Ji(s){const t=s.match(/url\s*\(\s*['"]?\s*#([^'"\s)]+)\s*['"]?\s*\)/i);return t?t[1]:""}const tr={fill:{type:"paint",default:0},"fill-opacity":{type:"number",default:1},stroke:{type:"paint",default:0},"stroke-width":{type:"number",default:1},"stroke-opacity":{type:"number",default:1},"stroke-linecap":{type:"string",default:"butt"},"stroke-linejoin":{type:"string",default:"miter"},"stroke-miterlimit":{type:"number",default:10},"stroke-dasharray":{type:"string",default:"none"},"stroke-dashoffset":{type:"number",default:0},opacity:{type:"number",default:1}};function zn(s,t){const e=s.getAttribute("style"),i={},r={},n={strokeStyle:i,fillStyle:r,useFill:!1,useStroke:!1};for(const o in tr){const a=s.getAttribute(o);a&&er(t,n,o,a.trim())}if(e){const o=e.split(";");for(let a=0;a<o.length;a++){const h=o[a].trim(),[l,c]=h.split(":");tr[l]&&er(t,n,l,c.trim())}}return{strokeStyle:n.useStroke?i:null,fillStyle:n.useFill?r:null,useFill:n.useFill,useStroke:n.useStroke}}function er(s,t,e,i){switch(e){case"stroke":if(i!=="none"){if(i.startsWith("url(")){const r=Ji(i);t.strokeStyle.fill=s.defs[r]}else t.strokeStyle.color=Y.shared.setValue(i).toNumber();t.useStroke=!0}break;case"stroke-width":t.strokeStyle.width=Number(i);break;case"fill":if(i!=="none"){if(i.startsWith("url(")){const r=Ji(i);t.fillStyle.fill=s.defs[r]}else t.fillStyle.color=Y.shared.setValue(i).toNumber();t.useFill=!0}break;case"fill-opacity":t.fillStyle.alpha=Number(i);break;case"stroke-opacity":t.strokeStyle.alpha=Number(i);break;case"opacity":t.fillStyle.alpha=Number(i),t.strokeStyle.alpha=Number(i);break}}function Ul(s){if(s.length<=2)return!0;const t=s.map(a=>a.area).sort((a,h)=>h-a),[e,i]=t,r=t[t.length-1],n=e/i,o=i/r;return!(n>3&&o<2)}function $l(s){return s.split(/(?=[Mm])/).filter(i=>i.trim().length>0)}function Ol(s){const t=s.match(/[-+]?[0-9]*\.?[0-9]+/g);if(!t||t.length<4)return 0;const e=t.map(Number),i=[],r=[];for(let c=0;c<e.length;c+=2)c+1<e.length&&(i.push(e[c]),r.push(e[c+1]));if(i.length===0||r.length===0)return 0;const n=Math.min(...i),o=Math.max(...i),a=Math.min(...r),h=Math.max(...r);return(o-n)*(h-a)}function sr(s,t){const e=new yt(s,!1);for(const i of e.instructions)t.instructions.push(i)}function Vl(s,t){if(typeof s=="string"){const o=document.createElement("div");o.innerHTML=s.trim(),s=o.querySelector("svg")}const e={context:t,defs:{},path:new yt};zl(s,e);const i=s.children,{fillStyle:r,strokeStyle:n}=zn(s,e);for(let o=0;o<i.length;o++){const a=i[o];a.nodeName.toLowerCase()!=="defs"&&Hn(a,e,r,n)}return t}function Hn(s,t,e,i){const r=s.children,{fillStyle:n,strokeStyle:o}=zn(s,t);n&&e?e={...e,...n}:n&&(e=n),o&&i?i={...i,...o}:o&&(i=o);const a=!e&&!i;a&&(e={color:0});let h,l,c,u,p,d,m,g,f,x,y,_,b,v,S,w,R;switch(s.nodeName.toLowerCase()){case"path":{v=s.getAttribute("d");const k=s.getAttribute("fill-rule"),P=$l(v),M=k==="evenodd",G=P.length>1;if(M&&G){const N=P.map(C=>({path:C,area:Ol(C)}));if(N.sort((C,A)=>A.area-C.area),P.length>3||!Ul(N))for(let C=0;C<N.length;C++){const A=N[C],Xt=C===0;t.context.beginPath();const B=new yt(void 0,!0);sr(A.path,B),t.context.path(B),Xt?(e&&t.context.fill(e),i&&t.context.stroke(i)):t.context.cut()}else for(let C=0;C<N.length;C++){const A=N[C],Xt=C%2===1;t.context.beginPath();const B=new yt(void 0,!0);sr(A.path,B),t.context.path(B),Xt?t.context.cut():(e&&t.context.fill(e),i&&t.context.stroke(i))}}else{const N=k?k==="evenodd":!0;S=new yt(v,N),t.context.path(S),e&&t.context.fill(e),i&&t.context.stroke(i)}break}case"circle":m=$(s,"cx",0),g=$(s,"cy",0),f=$(s,"r",0),t.context.ellipse(m,g,f,f),e&&t.context.fill(e),i&&t.context.stroke(i);break;case"rect":h=$(s,"x",0),l=$(s,"y",0),w=$(s,"width",0),R=$(s,"height",0),x=$(s,"rx",0),y=$(s,"ry",0),x||y?t.context.roundRect(h,l,w,R,x||y):t.context.rect(h,l,w,R),e&&t.context.fill(e),i&&t.context.stroke(i);break;case"ellipse":m=$(s,"cx",0),g=$(s,"cy",0),x=$(s,"rx",0),y=$(s,"ry",0),t.context.beginPath(),t.context.ellipse(m,g,x,y),e&&t.context.fill(e),i&&t.context.stroke(i);break;case"line":c=$(s,"x1",0),u=$(s,"y1",0),p=$(s,"x2",0),d=$(s,"y2",0),t.context.beginPath(),t.context.moveTo(c,u),t.context.lineTo(p,d),i&&t.context.stroke(i);break;case"polygon":b=s.getAttribute("points"),_=b.match(/\d+/g).map(k=>parseInt(k,10)),t.context.poly(_,!0),e&&t.context.fill(e),i&&t.context.stroke(i);break;case"polyline":b=s.getAttribute("points"),_=b.match(/\d+/g).map(k=>parseInt(k,10)),t.context.poly(_,!1),i&&t.context.stroke(i);break;case"g":case"svg":break;default:{Q(`[SVG parser] <${s.nodeName}> elements unsupported`);break}}a&&(e=null);for(let k=0;k<r.length;k++)Hn(r[k],t,e,i)}function Wl(s){return Y.isColorLike(s)}function ir(s){return s instanceof Xe}function rr(s){return s instanceof _t}function Yl(s){return s instanceof D}function Xl(s,t,e){const i=Y.shared.setValue(t??0);return s.color=i.toNumber(),s.alpha=i.alpha===1?e.alpha:i.alpha,s.texture=D.WHITE,{...e,...s}}function jl(s,t,e){return s.texture=t,{...e,...s}}function nr(s,t,e){return s.fill=t,s.color=16777215,s.texture=t.texture,s.matrix=t.transform,{...e,...s}}function or(s,t,e){return t.buildGradient(),s.fill=t,s.color=16777215,s.texture=t.texture,s.matrix=t.transform,s.textureSpace=t.textureSpace,{...e,...s}}function ql(s,t){const e={...t,...s},i=Y.shared.setValue(e.color);return e.alpha*=i.alpha,e.color=i.toNumber(),e}function Bt(s,t){if(s==null)return null;const e={},i=s;return Wl(s)?Xl(e,s,t):Yl(s)?jl(e,s,t):ir(s)?nr(e,s,t):rr(s)?or(e,s,t):i.fill&&ir(i.fill)?nr(i,i.fill,t):i.fill&&rr(i.fill)?or(i,i.fill,t):ql(i,t)}function Ve(s,t){const{width:e,alignment:i,miterLimit:r,cap:n,join:o,pixelLine:a,...h}=t,l=Bt(s,h);return l?{width:e,alignment:i,miterLimit:r,cap:n,join:o,pixelLine:a,...l}:null}const Zl=new Z,ar=new I,Qs=class ut extends pt{constructor(){super(...arguments),this.uid=V("graphicsContext"),this.dirty=!0,this.batchMode="auto",this.instructions=[],this._activePath=new yt,this._transform=new I,this._fillStyle={...ut.defaultFillStyle},this._strokeStyle={...ut.defaultStrokeStyle},this._stateStack=[],this._tick=0,this._bounds=new at,this._boundsDirty=!0}clone(){const t=new ut;return t.batchMode=this.batchMode,t.instructions=this.instructions.slice(),t._activePath=this._activePath.clone(),t._transform=this._transform.clone(),t._fillStyle={...this._fillStyle},t._strokeStyle={...this._strokeStyle},t._stateStack=this._stateStack.slice(),t._bounds=this._bounds.clone(),t._boundsDirty=!0,t}get fillStyle(){return this._fillStyle}set fillStyle(t){this._fillStyle=Bt(t,ut.defaultFillStyle)}get strokeStyle(){return this._strokeStyle}set strokeStyle(t){this._strokeStyle=Ve(t,ut.defaultStrokeStyle)}setFillStyle(t){return this._fillStyle=Bt(t,ut.defaultFillStyle),this}setStrokeStyle(t){return this._strokeStyle=Bt(t,ut.defaultStrokeStyle),this}texture(t,e,i,r,n,o){return this.instructions.push({action:"texture",data:{image:t,dx:i||0,dy:r||0,dw:n||t.frame.width,dh:o||t.frame.height,transform:this._transform.clone(),alpha:this._fillStyle.alpha,style:e?Y.shared.setValue(e).toNumber():16777215}}),this.onUpdate(),this}beginPath(){return this._activePath=new yt,this}fill(t,e){let i;const r=this.instructions[this.instructions.length-1];return this._tick===0&&r&&r.action==="stroke"?i=r.data.path:i=this._activePath.clone(),i?(t!=null&&(e!==void 0&&typeof t=="number"&&(F(O,"GraphicsContext.fill(color, alpha) is deprecated, use GraphicsContext.fill({ color, alpha }) instead"),t={color:t,alpha:e}),this._fillStyle=Bt(t,ut.defaultFillStyle)),this.instructions.push({action:"fill",data:{style:this.fillStyle,path:i}}),this.onUpdate(),this._initNextPathLocation(),this._tick=0,this):this}_initNextPathLocation(){const{x:t,y:e}=this._activePath.getLastPoint(Z.shared);this._activePath.clear(),this._activePath.moveTo(t,e)}stroke(t){let e;const i=this.instructions[this.instructions.length-1];return this._tick===0&&i&&i.action==="fill"?e=i.data.path:e=this._activePath.clone(),e?(t!=null&&(this._strokeStyle=Ve(t,ut.defaultStrokeStyle)),this.instructions.push({action:"stroke",data:{style:this.strokeStyle,path:e}}),this.onUpdate(),this._initNextPathLocation(),this._tick=0,this):this}cut(){for(let t=0;t<2;t++){const e=this.instructions[this.instructions.length-1-t],i=this._activePath.clone();if(e&&(e.action==="stroke"||e.action==="fill"))if(e.data.hole)e.data.hole.addPath(i);else{e.data.hole=i;break}}return this._initNextPathLocation(),this}arc(t,e,i,r,n,o){this._tick++;const a=this._transform;return this._activePath.arc(a.a*t+a.c*e+a.tx,a.b*t+a.d*e+a.ty,i,r,n,o),this}arcTo(t,e,i,r,n){this._tick++;const o=this._transform;return this._activePath.arcTo(o.a*t+o.c*e+o.tx,o.b*t+o.d*e+o.ty,o.a*i+o.c*r+o.tx,o.b*i+o.d*r+o.ty,n),this}arcToSvg(t,e,i,r,n,o,a){this._tick++;const h=this._transform;return this._activePath.arcToSvg(t,e,i,r,n,h.a*o+h.c*a+h.tx,h.b*o+h.d*a+h.ty),this}bezierCurveTo(t,e,i,r,n,o,a){this._tick++;const h=this._transform;return this._activePath.bezierCurveTo(h.a*t+h.c*e+h.tx,h.b*t+h.d*e+h.ty,h.a*i+h.c*r+h.tx,h.b*i+h.d*r+h.ty,h.a*n+h.c*o+h.tx,h.b*n+h.d*o+h.ty,a),this}closePath(){var t;return this._tick++,(t=this._activePath)==null||t.closePath(),this}ellipse(t,e,i,r){return this._tick++,this._activePath.ellipse(t,e,i,r,this._transform.clone()),this}circle(t,e,i){return this._tick++,this._activePath.circle(t,e,i,this._transform.clone()),this}path(t){return this._tick++,this._activePath.addPath(t,this._transform.clone()),this}lineTo(t,e){this._tick++;const i=this._transform;return this._activePath.lineTo(i.a*t+i.c*e+i.tx,i.b*t+i.d*e+i.ty),this}moveTo(t,e){this._tick++;const i=this._transform,r=this._activePath.instructions,n=i.a*t+i.c*e+i.tx,o=i.b*t+i.d*e+i.ty;return r.length===1&&r[0].action==="moveTo"?(r[0].data[0]=n,r[0].data[1]=o,this):(this._activePath.moveTo(n,o),this)}quadraticCurveTo(t,e,i,r,n){this._tick++;const o=this._transform;return this._activePath.quadraticCurveTo(o.a*t+o.c*e+o.tx,o.b*t+o.d*e+o.ty,o.a*i+o.c*r+o.tx,o.b*i+o.d*r+o.ty,n),this}rect(t,e,i,r){return this._tick++,this._activePath.rect(t,e,i,r,this._transform.clone()),this}roundRect(t,e,i,r,n){return this._tick++,this._activePath.roundRect(t,e,i,r,n,this._transform.clone()),this}poly(t,e){return this._tick++,this._activePath.poly(t,e,this._transform.clone()),this}regularPoly(t,e,i,r,n=0,o){return this._tick++,this._activePath.regularPoly(t,e,i,r,n,o),this}roundPoly(t,e,i,r,n,o){return this._tick++,this._activePath.roundPoly(t,e,i,r,n,o),this}roundShape(t,e,i,r){return this._tick++,this._activePath.roundShape(t,e,i,r),this}filletRect(t,e,i,r,n){return this._tick++,this._activePath.filletRect(t,e,i,r,n),this}chamferRect(t,e,i,r,n,o){return this._tick++,this._activePath.chamferRect(t,e,i,r,n,o),this}star(t,e,i,r,n=0,o=0){return this._tick++,this._activePath.star(t,e,i,r,n,o,this._transform.clone()),this}svg(t){return this._tick++,Vl(t,this),this}restore(){const t=this._stateStack.pop();return t&&(this._transform=t.transform,this._fillStyle=t.fillStyle,this._strokeStyle=t.strokeStyle),this}save(){return this._stateStack.push({transform:this._transform.clone(),fillStyle:{...this._fillStyle},strokeStyle:{...this._strokeStyle}}),this}getTransform(){return this._transform}resetTransform(){return this._transform.identity(),this}rotate(t){return this._transform.rotate(t),this}scale(t,e=t){return this._transform.scale(t,e),this}setTransform(t,e,i,r,n,o){return t instanceof I?(this._transform.set(t.a,t.b,t.c,t.d,t.tx,t.ty),this):(this._transform.set(t,e,i,r,n,o),this)}transform(t,e,i,r,n,o){return t instanceof I?(this._transform.append(t),this):(ar.set(t,e,i,r,n,o),this._transform.append(ar),this)}translate(t,e=t){return this._transform.translate(t,e),this}clear(){return this._activePath.clear(),this.instructions.length=0,this.resetTransform(),this.onUpdate(),this}onUpdate(){this._boundsDirty=!0,!this.dirty&&(this.emit("update",this,16),this.dirty=!0)}get bounds(){if(!this._boundsDirty)return this._bounds;this._boundsDirty=!1;const t=this._bounds;t.clear();for(let e=0;e<this.instructions.length;e++){const i=this.instructions[e],r=i.action;if(r==="fill"){const n=i.data;t.addBounds(n.path.bounds)}else if(r==="texture"){const n=i.data;t.addFrame(n.dx,n.dy,n.dx+n.dw,n.dy+n.dh,n.transform)}if(r==="stroke"){const n=i.data,o=n.style.alignment,a=n.style.width*(1-o),h=n.path.bounds;t.addFrame(h.minX-a,h.minY-a,h.maxX+a,h.maxY+a)}}return t}containsPoint(t){var r;if(!this.bounds.containsPoint(t.x,t.y))return!1;const e=this.instructions;let i=!1;for(let n=0;n<e.length;n++){const o=e[n],a=o.data,h=a.path;if(!o.action||!h)continue;const l=a.style,c=h.shapePath.shapePrimitives;for(let u=0;u<c.length;u++){const p=c[u].shape;if(!l||!p)continue;const d=c[u].transform,m=d?d.applyInverse(t,Zl):t;if(o.action==="fill")i=p.contains(m.x,m.y);else{const f=l;i=p.strokeContains(m.x,m.y,f.width,f.alignment)}const g=a.hole;if(g){const f=(r=g.shapePath)==null?void 0:r.shapePrimitives;if(f)for(let x=0;x<f.length;x++)f[x].shape.contains(m.x,m.y)&&(i=!1)}if(i)return!0}}return i}destroy(t=!1){if(this._stateStack.length=0,this._transform=null,this.emit("destroy",this),this.removeAllListeners(),typeof t=="boolean"?t:t==null?void 0:t.texture){const i=typeof t=="boolean"?t:t==null?void 0:t.textureSource;this._fillStyle.texture&&(this._fillStyle.fill&&"uid"in this._fillStyle.fill?this._fillStyle.fill.destroy():this._fillStyle.texture.destroy(i)),this._strokeStyle.texture&&(this._strokeStyle.fill&&"uid"in this._strokeStyle.fill?this._strokeStyle.fill.destroy():this._strokeStyle.texture.destroy(i))}this._fillStyle=null,this._strokeStyle=null,this.instructions=null,this._activePath=null,this._bounds=null,this._stateStack=null,this.customShader=null,this._transform=null}};Qs.defaultFillStyle={color:16777215,alpha:1,texture:D.WHITE,matrix:null,fill:null,textureSpace:"local"};Qs.defaultStrokeStyle={width:1,color:16777215,alpha:1,alignment:.5,miterLimit:10,cap:"butt",join:"miter",texture:D.WHITE,matrix:null,fill:null,textureSpace:"local",pixelLine:!1};let ot=Qs;const Js=class Ut extends pt{constructor(t={}){super(),this.uid=V("textStyle"),this._tick=0,Kl(t);const e={...Ut.defaultTextStyle,...t};for(const i in e){const r=i;this[r]=e[i]}this.update(),this._tick=0}get align(){return this._align}set align(t){this._align=t,this.update()}get breakWords(){return this._breakWords}set breakWords(t){this._breakWords=t,this.update()}get dropShadow(){return this._dropShadow}set dropShadow(t){t!==null&&typeof t=="object"?this._dropShadow=this._createProxy({...Ut.defaultDropShadow,...t}):this._dropShadow=t?this._createProxy({...Ut.defaultDropShadow}):null,this.update()}get fontFamily(){return this._fontFamily}set fontFamily(t){this._fontFamily=t,this.update()}get fontSize(){return this._fontSize}set fontSize(t){typeof t=="string"?this._fontSize=parseInt(t,10):this._fontSize=t,this.update()}get fontStyle(){return this._fontStyle}set fontStyle(t){this._fontStyle=t.toLowerCase(),this.update()}get fontVariant(){return this._fontVariant}set fontVariant(t){this._fontVariant=t,this.update()}get fontWeight(){return this._fontWeight}set fontWeight(t){this._fontWeight=t,this.update()}get leading(){return this._leading}set leading(t){this._leading=t,this.update()}get letterSpacing(){return this._letterSpacing}set letterSpacing(t){this._letterSpacing=t,this.update()}get lineHeight(){return this._lineHeight}set lineHeight(t){this._lineHeight=t,this.update()}get padding(){return this._padding}set padding(t){this._padding=t,this.update()}get filters(){return this._filters}set filters(t){this._filters=Object.freeze(t),this.update()}get trim(){return this._trim}set trim(t){this._trim=t,this.update()}get textBaseline(){return this._textBaseline}set textBaseline(t){this._textBaseline=t,this.update()}get whiteSpace(){return this._whiteSpace}set whiteSpace(t){this._whiteSpace=t,this.update()}get wordWrap(){return this._wordWrap}set wordWrap(t){this._wordWrap=t,this.update()}get wordWrapWidth(){return this._wordWrapWidth}set wordWrapWidth(t){this._wordWrapWidth=t,this.update()}get fill(){return this._originalFill}set fill(t){t!==this._originalFill&&(this._originalFill=t,this._isFillStyle(t)&&(this._originalFill=this._createProxy({...ot.defaultFillStyle,...t},()=>{this._fill=Bt({...this._originalFill},ot.defaultFillStyle)})),this._fill=Bt(t===0?"black":t,ot.defaultFillStyle),this.update())}get stroke(){return this._originalStroke}set stroke(t){t!==this._originalStroke&&(this._originalStroke=t,this._isFillStyle(t)&&(this._originalStroke=this._createProxy({...ot.defaultStrokeStyle,...t},()=>{this._stroke=Ve({...this._originalStroke},ot.defaultStrokeStyle)})),this._stroke=Ve(t,ot.defaultStrokeStyle),this.update())}update(){this._tick++,this.emit("update",this)}reset(){const t=Ut.defaultTextStyle;for(const e in t)this[e]=t[e]}get styleKey(){return`${this.uid}-${this._tick}`}clone(){return new Ut({align:this.align,breakWords:this.breakWords,dropShadow:this._dropShadow?{...this._dropShadow}:null,fill:this._fill,fontFamily:this.fontFamily,fontSize:this.fontSize,fontStyle:this.fontStyle,fontVariant:this.fontVariant,fontWeight:this.fontWeight,leading:this.leading,letterSpacing:this.letterSpacing,lineHeight:this.lineHeight,padding:this.padding,stroke:this._stroke,textBaseline:this.textBaseline,whiteSpace:this.whiteSpace,wordWrap:this.wordWrap,wordWrapWidth:this.wordWrapWidth,filters:this._filters?[...this._filters]:void 0})}_getFinalPadding(){let t=0;if(this._filters)for(let e=0;e<this._filters.length;e++)t+=this._filters[e].padding;return Math.max(this._padding,t)}destroy(t=!1){var i,r,n,o;if(this.removeAllListeners(),typeof t=="boolean"?t:t==null?void 0:t.texture){const a=typeof t=="boolean"?t:t==null?void 0:t.textureSource;(i=this._fill)!=null&&i.texture&&this._fill.texture.destroy(a),(r=this._originalFill)!=null&&r.texture&&this._originalFill.texture.destroy(a),(n=this._stroke)!=null&&n.texture&&this._stroke.texture.destroy(a),(o=this._originalStroke)!=null&&o.texture&&this._originalStroke.texture.destroy(a)}this._fill=null,this._stroke=null,this.dropShadow=null,this._originalStroke=null,this._originalFill=null}_createProxy(t,e){return new Proxy(t,{set:(i,r,n)=>(i[r]=n,e==null||e(r,n),this.update(),!0)})}_isFillStyle(t){return(t??null)!==null&&!(Y.isColorLike(t)||t instanceof _t||t instanceof Xe)}};Js.defaultDropShadow={alpha:1,angle:Math.PI/6,blur:0,color:"black",distance:5};Js.defaultTextStyle={align:"left",breakWords:!1,dropShadow:null,fill:"black",fontFamily:"Arial",fontSize:26,fontStyle:"normal",fontVariant:"normal",fontWeight:"normal",leading:0,letterSpacing:0,lineHeight:0,padding:0,stroke:null,textBaseline:"alphabetic",trim:!1,whiteSpace:"pre",wordWrap:!1,wordWrapWidth:100};let Nn=Js;function Kl(s){const t=s;if(typeof t.dropShadow=="boolean"&&t.dropShadow){const e=Nn.defaultDropShadow;s.dropShadow={alpha:t.dropShadowAlpha??e.alpha,angle:t.dropShadowAngle??e.angle,blur:t.dropShadowBlur??e.blur,color:t.dropShadowColor??e.color,distance:t.dropShadowDistance??e.distance}}if(t.strokeThickness!==void 0){F(O,"strokeThickness is now a part of stroke");const e=t.stroke;let i={};if(Y.isColorLike(e))i.color=e;else if(e instanceof _t||e instanceof Xe)i.fill=e;else if(Object.hasOwnProperty.call(e,"color")||Object.hasOwnProperty.call(e,"fill"))i=e;else throw new Error("Invalid stroke value.");s.stroke={...i,width:t.strokeThickness}}if(Array.isArray(t.fillGradientStops)){if(F(O,"gradient fill is now a fill pattern: `new FillGradient(...)`"),!Array.isArray(t.fill)||t.fill.length===0)throw new Error("Invalid fill value. Expected an array of colors for gradient fill.");t.fill.length!==t.fillGradientStops.length&&Q("The number of fill colors must match the number of fill gradient stops.");const e=new _t({start:{x:0,y:0},end:{x:0,y:1},textureSpace:"local"}),i=t.fillGradientStops.slice(),r=t.fill.map(n=>Y.shared.setValue(n).toNumber());i.forEach((n,o)=>{e.addColorStop(n,r[o])}),s.fill={fill:e}}}class Ql{constructor(t){this._canvasPool=Object.create(null),this.canvasOptions=t||{},this.enableFullScreen=!1}_createCanvasAndContext(t,e){const i=et.get().createCanvas();i.width=t,i.height=e;const r=i.getContext("2d");return{canvas:i,context:r}}getOptimalCanvasAndContext(t,e,i=1){t=Math.ceil(t*i-1e-6),e=Math.ceil(e*i-1e-6),t=Vt(t),e=Vt(e);const r=(t<<17)+(e<<1);this._canvasPool[r]||(this._canvasPool[r]=[]);let n=this._canvasPool[r].pop();return n||(n=this._createCanvasAndContext(t,e)),n}returnCanvasAndContext(t){const e=t.canvas,{width:i,height:r}=e,n=(i<<17)+(r<<1);t.context.resetTransform(),t.context.clearRect(0,0,i,r),this._canvasPool[n].push(t)}clear(){this._canvasPool={}}}const Gs=new Ql;_e.register(Gs);const hr=1e5;function lr(s,t,e,i=0){if(s.texture===D.WHITE&&!s.fill)return Y.shared.setValue(s.color).setAlpha(s.alpha??1).toHexa();if(s.fill){if(s.fill instanceof Xe){const r=s.fill,n=t.createPattern(r.texture.source.resource,"repeat"),o=r.transform.copyTo(I.shared);return o.scale(r.texture.frame.width,r.texture.frame.height),n.setTransform(o),n}else if(s.fill instanceof _t){const r=s.fill,n=r.type==="linear",o=r.textureSpace==="local";let a=1,h=1;o&&e&&(a=e.width+i,h=e.height+i);let l,c=!1;if(n){const{start:u,end:p}=r;l=t.createLinearGradient(u.x*a,u.y*h,p.x*a,p.y*h),c=Math.abs(p.x-u.x)<Math.abs((p.y-u.y)*.1)}else{const{center:u,innerRadius:p,outerCenter:d,outerRadius:m}=r;l=t.createRadialGradient(u.x*a,u.y*h,p*a,d.x*a,d.y*h,m*a)}if(c&&o&&e){const u=e.lineHeight/h;for(let p=0;p<e.lines.length;p++){const d=(p*e.lineHeight+i/2)/h;r.colorStops.forEach(m=>{const g=d+m.offset*u;l.addColorStop(Math.floor(g*hr)/hr,Y.shared.setValue(m.color).toHex())})}}else r.colorStops.forEach(u=>{l.addColorStop(u.offset,Y.shared.setValue(u.color).toHex())});return l}}else{const r=t.createPattern(s.texture.source.resource,"repeat"),n=s.matrix.copyTo(I.shared);return n.scale(s.texture.frame.width,s.texture.frame.height),r.setTransform(n),r}return Q("FillStyle not recognised",s),"red"}class dt extends Vs{constructor(t){t instanceof ot&&(t={context:t});const{context:e,roundPixels:i,...r}=t||{};super({label:"Graphics",...r}),this.renderPipeId="graphics",e?this._context=e:this._context=this._ownedContext=new ot,this._context.on("update",this.onViewUpdate,this),this.didViewUpdate=!0,this.allowChildren=!1,this.roundPixels=i??!1}set context(t){t!==this._context&&(this._context.off("update",this.onViewUpdate,this),this._context=t,this._context.on("update",this.onViewUpdate,this),this.onViewUpdate())}get context(){return this._context}get bounds(){return this._context.bounds}updateBounds(){}containsPoint(t){return this._context.containsPoint(t)}destroy(t){this._ownedContext&&!t?this._ownedContext.destroy(t):(t===!0||(t==null?void 0:t.context)===!0)&&this._context.destroy(t),this._ownedContext=null,this._context=null,super.destroy(t)}_callContextMethod(t,e){return this.context[t](...e),this}setFillStyle(...t){return this._callContextMethod("setFillStyle",t)}setStrokeStyle(...t){return this._callContextMethod("setStrokeStyle",t)}fill(...t){return this._callContextMethod("fill",t)}stroke(...t){return this._callContextMethod("stroke",t)}texture(...t){return this._callContextMethod("texture",t)}beginPath(){return this._callContextMethod("beginPath",[])}cut(){return this._callContextMethod("cut",[])}arc(...t){return this._callContextMethod("arc",t)}arcTo(...t){return this._callContextMethod("arcTo",t)}arcToSvg(...t){return this._callContextMethod("arcToSvg",t)}bezierCurveTo(...t){return this._callContextMethod("bezierCurveTo",t)}closePath(){return this._callContextMethod("closePath",[])}ellipse(...t){return this._callContextMethod("ellipse",t)}circle(...t){return this._callContextMethod("circle",t)}path(...t){return this._callContextMethod("path",t)}lineTo(...t){return this._callContextMethod("lineTo",t)}moveTo(...t){return this._callContextMethod("moveTo",t)}quadraticCurveTo(...t){return this._callContextMethod("quadraticCurveTo",t)}rect(...t){return this._callContextMethod("rect",t)}roundRect(...t){return this._callContextMethod("roundRect",t)}poly(...t){return this._callContextMethod("poly",t)}regularPoly(...t){return this._callContextMethod("regularPoly",t)}roundPoly(...t){return this._callContextMethod("roundPoly",t)}roundShape(...t){return this._callContextMethod("roundShape",t)}filletRect(...t){return this._callContextMethod("filletRect",t)}chamferRect(...t){return this._callContextMethod("chamferRect",t)}star(...t){return this._callContextMethod("star",t)}svg(...t){return this._callContextMethod("svg",t)}restore(...t){return this._callContextMethod("restore",t)}save(){return this._callContextMethod("save",[])}getTransform(){return this.context.getTransform()}resetTransform(){return this._callContextMethod("resetTransform",[])}rotateTransform(...t){return this._callContextMethod("rotate",t)}scaleTransform(...t){return this._callContextMethod("scale",t)}setTransform(...t){return this._callContextMethod("setTransform",t)}transform(...t){return this._callContextMethod("transform",t)}translateTransform(...t){return this._callContextMethod("translate",t)}clear(){return this._callContextMethod("clear",[])}get fillStyle(){return this._context.fillStyle}set fillStyle(t){this._context.fillStyle=t}get strokeStyle(){return this._context.strokeStyle}set strokeStyle(t){this._context.strokeStyle=t}clone(t=!1){return t?new dt(this._context.clone()):(this._ownedContext=null,new dt(this._context))}lineStyle(t,e,i){F(O,"Graphics#lineStyle is no longer needed. Use Graphics#setStrokeStyle to set the stroke style.");const r={};return t&&(r.width=t),e&&(r.color=e),i&&(r.alpha=i),this.context.strokeStyle=r,this}beginFill(t,e){F(O,"Graphics#beginFill is no longer needed. Use Graphics#fill to fill the shape with the desired style.");const i={};return t!==void 0&&(i.color=t),e!==void 0&&(i.alpha=e),this.context.fillStyle=i,this}endFill(){F(O,"Graphics#endFill is no longer needed. Use Graphics#fill to fill the shape with the desired style."),this.context.fill();const t=this.context.strokeStyle;return(t.width!==ot.defaultStrokeStyle.width||t.color!==ot.defaultStrokeStyle.color||t.alpha!==ot.defaultStrokeStyle.alpha)&&this.context.stroke(),this}drawCircle(...t){return F(O,"Graphics#drawCircle has been renamed to Graphics#circle"),this._callContextMethod("circle",t)}drawEllipse(...t){return F(O,"Graphics#drawEllipse has been renamed to Graphics#ellipse"),this._callContextMethod("ellipse",t)}drawPolygon(...t){return F(O,"Graphics#drawPolygon has been renamed to Graphics#poly"),this._callContextMethod("poly",t)}drawRect(...t){return F(O,"Graphics#drawRect has been renamed to Graphics#rect"),this._callContextMethod("rect",t)}drawRoundedRect(...t){return F(O,"Graphics#drawRoundedRect has been renamed to Graphics#roundRect"),this._callContextMethod("roundRect",t)}drawStar(...t){return F(O,"Graphics#drawStar has been renamed to Graphics#star"),this._callContextMethod("star",t)}}class Jl extends Vs{constructor(t,e){const{text:i,resolution:r,style:n,anchor:o,width:a,height:h,roundPixels:l,...c}=t;super({...c}),this.batched=!0,this._resolution=null,this._autoResolution=!0,this._didTextUpdate=!0,this._styleClass=e,this.text=i??"",this.style=n,this.resolution=r??null,this.allowChildren=!1,this._anchor=new q({_onUpdate:()=>{this.onViewUpdate()}}),o&&(this.anchor=o),this.roundPixels=l??!1,a!==void 0&&(this.width=a),h!==void 0&&(this.height=h)}get anchor(){return this._anchor}set anchor(t){typeof t=="number"?this._anchor.set(t):this._anchor.copyFrom(t)}set text(t){t=t.toString(),this._text!==t&&(this._text=t,this.onViewUpdate())}get text(){return this._text}set resolution(t){this._autoResolution=t===null,this._resolution=t,this.onViewUpdate()}get resolution(){return this._resolution}get style(){return this._style}set style(t){var e;t||(t={}),(e=this._style)==null||e.off("update",this.onViewUpdate,this),t instanceof this._styleClass?this._style=t:this._style=new this._styleClass(t),this._style.on("update",this.onViewUpdate,this),this.onViewUpdate()}get width(){return Math.abs(this.scale.x)*this.bounds.width}set width(t){this._setWidth(t,this.bounds.width)}get height(){return Math.abs(this.scale.y)*this.bounds.height}set height(t){this._setHeight(t,this.bounds.height)}getSize(t){return t||(t={}),t.width=Math.abs(this.scale.x)*this.bounds.width,t.height=Math.abs(this.scale.y)*this.bounds.height,t}setSize(t,e){typeof t=="object"?(e=t.height??t.width,t=t.width):e??(e=t),t!==void 0&&this._setWidth(t,this.bounds.width),e!==void 0&&this._setHeight(e,this.bounds.height)}containsPoint(t){const e=this.bounds.width,i=this.bounds.height,r=-e*this.anchor.x;let n=0;return t.x>=r&&t.x<=r+e&&(n=-i*this.anchor.y,t.y>=n&&t.y<=n+i)}onViewUpdate(){this.didViewUpdate||(this._didTextUpdate=!0),super.onViewUpdate()}destroy(t=!1){super.destroy(t),this.owner=null,this._bounds=null,this._anchor=null,(typeof t=="boolean"?t:t!=null&&t.style)&&this._style.destroy(t),this._style=null,this._text=null}get styleKey(){return`${this._text}:${this._style.styleKey}:${this._resolution}`}}function tc(s,t){let e=s[0]??{};return(typeof e=="string"||s[1])&&(F(O,`use new ${t}({ text: "hi!", style }) instead`),e={text:e,style:s[1]}),e}let At=null,gt=null;function ec(s,t){At||(At=et.get().createCanvas(256,128),gt=At.getContext("2d",{willReadFrequently:!0}),gt.globalCompositeOperation="copy",gt.globalAlpha=1),(At.width<s||At.height<t)&&(At.width=Vt(s),At.height=Vt(t))}function cr(s,t,e){for(let i=0,r=4*e*t;i<t;++i,r+=4)if(s[r+3]!==0)return!1;return!0}function ur(s,t,e,i,r){const n=4*t;for(let o=i,a=i*n+4*e;o<=r;++o,a+=n)if(s[a+3]!==0)return!1;return!0}function sc(...s){let t=s[0];t.canvas||(t={canvas:s[0],resolution:s[1]});const{canvas:e}=t,i=Math.min(t.resolution??1,1),r=t.width??e.width,n=t.height??e.height;let o=t.output;if(ec(r,n),!gt)throw new TypeError("Failed to get canvas 2D context");gt.drawImage(e,0,0,r,n,0,0,r*i,n*i);const h=gt.getImageData(0,0,r,n).data;let l=0,c=0,u=r-1,p=n-1;for(;c<n&&cr(h,r,c);)++c;if(c===n)return W.EMPTY;for(;cr(h,r,p);)--p;for(;ur(h,r,l,c,p);)++l;for(;ur(h,r,u,c,p);)--u;return++u,++p,gt.globalCompositeOperation="source-over",gt.strokeRect(l,c,u-l,p-c),gt.globalCompositeOperation="copy",o??(o=new W),o.set(l/i,c/i,(u-l)/i,(p-c)/i),o}const dr=new W;class ic{getCanvasAndContext(t){const{text:e,style:i,resolution:r=1}=t,n=i._getFinalPadding(),o=Nt.measureText(e||" ",i),a=Math.ceil(Math.ceil(Math.max(1,o.width)+n*2)*r),h=Math.ceil(Math.ceil(Math.max(1,o.height)+n*2)*r),l=Gs.getOptimalCanvasAndContext(a,h);this._renderTextToCanvas(e,i,n,r,l);const c=i.trim?sc({canvas:l.canvas,width:a,height:h,resolution:1,output:dr}):dr.set(0,0,a,h);return{canvasAndContext:l,frame:c}}returnCanvasAndContext(t){Gs.returnCanvasAndContext(t)}_renderTextToCanvas(t,e,i,r,n){var _,b,v,S;const{canvas:o,context:a}=n,h=Sn(e),l=Nt.measureText(t||" ",e),c=l.lines,u=l.lineHeight,p=l.lineWidths,d=l.maxLineWidth,m=l.fontProperties,g=o.height;if(a.resetTransform(),a.scale(r,r),a.textBaseline=e.textBaseline,(_=e._stroke)!=null&&_.width){const w=e._stroke;a.lineWidth=w.width,a.miterLimit=w.miterLimit,a.lineJoin=w.join,a.lineCap=w.cap}a.font=h;let f,x;const y=e.dropShadow?2:1;for(let w=0;w<y;++w){const R=e.dropShadow&&w===0,k=R?Math.ceil(Math.max(1,g)+i*2):0,P=k*r;if(R){a.fillStyle="black",a.strokeStyle="black";const E=e.dropShadow,N=E.color,bt=E.alpha;a.shadowColor=Y.shared.setValue(N).setAlpha(bt).toRgbaString();const C=E.blur*r,A=E.distance*r;a.shadowBlur=C,a.shadowOffsetX=Math.cos(E.angle)*A,a.shadowOffsetY=Math.sin(E.angle)*A+P}else{if(a.fillStyle=e._fill?lr(e._fill,a,l,i*2):null,(b=e._stroke)!=null&&b.width){const E=e._stroke.width*.5+i*2;a.strokeStyle=lr(e._stroke,a,l,E)}a.shadowColor="black"}let M=(u-m.fontSize)/2;u-m.fontSize<0&&(M=0);const G=((v=e._stroke)==null?void 0:v.width)??0;for(let E=0;E<c.length;E++)f=G/2,x=G/2+E*u+m.ascent+M,e.align==="right"?f+=d-p[E]:e.align==="center"&&(f+=(d-p[E])/2),(S=e._stroke)!=null&&S.width&&this._drawLetterSpacing(c[E],e,n,f+i,x+i-k,!0),e._fill!==void 0&&this._drawLetterSpacing(c[E],e,n,f+i,x+i-k)}}_drawLetterSpacing(t,e,i,r,n,o=!1){const{context:a}=i,h=e.letterSpacing;let l=!1;if(Nt.experimentalLetterSpacingSupported&&(Nt.experimentalLetterSpacing?(a.letterSpacing=`${h}px`,a.textLetterSpacing=`${h}px`,l=!0):(a.letterSpacing="0px",a.textLetterSpacing="0px")),h===0||l){o?a.strokeText(t,r,n):a.fillText(t,r,n);return}let c=r;const u=Nt.graphemeSegmenter(t);let p=a.measureText(t).width,d=0;for(let m=0;m<u.length;++m){const g=u[m];o?a.strokeText(g,c,n):a.fillText(g,c,n);let f="";for(let x=m+1;x<u.length;++x)f+=u[x];d=a.measureText(f).width,c+=p-d+h,p=d}}}const fr=new ic;class Dt extends Jl{constructor(...t){const e=tc(t,"Text");super(e,Nn),this.renderPipeId="text",e.textureStyle&&(this.textureStyle=e.textureStyle instanceof Ue?e.textureStyle:new Ue(e.textureStyle))}updateBounds(){const t=this._bounds,e=this._anchor;let i=0,r=0;if(this._style.trim){const{frame:n,canvasAndContext:o}=fr.getCanvasAndContext({text:this.text,style:this._style,resolution:1});fr.returnCanvasAndContext(o),i=n.width,r=n.height}else{const n=Nt.measureText(this._text,this._style);i=n.width,r=n.height}t.minX=-e._x*i,t.maxX=t.minX+i,t.minY=-e._y*r,t.maxY=t.minY+r}}rt.add(eo,so);function Ot(s){const t=Math.max(0,s/1e3);if(t<60)return`${t.toFixed(2)}s`;const e=Math.floor(t/60),i=t%60;return`${e}m ${i.toFixed(1)}s`}function Un(s){return new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit",second:"2-digit"}).format(new Date(s))}function Ls(s){return Number.isFinite(s)?s.toFixed(3):"—"}function De(s,t,e){return Math.min(e,Math.max(t,s))}function rc(s,t,e,i,r,n,o,a){s.roundRect(t,e,i,r,n),s.fill(o),s.stroke(a)}class pr{constructor({host:t,panelId:e="primary",title:i="Vertical plot",subtitle:r=null,showReadouts:n=!0,lineColor:o=10473983,pointColor:a=15201023}){this.host=t,this.panelId=e,this.panelTitle=i,this.panelSubtitle=r,this.showReadouts=n,this.lineColor=o,this.pointColor=a,this.app=new wn,this.container=new ft,this.background=new dt,this.grid=new dt,this.axes=new dt,this.line=new dt,this.points=new dt,this.crosshair=new dt,this.overlay=new ft,this.readoutBackground=new dt,this.axisLabelLayer=new ft,this.titleText=new Dt({text:"Plot viewport",style:{fill:15660287,fontFamily:"Inter, sans-serif",fontSize:16}}),this.subtitleText=new Dt({text:"Synthetic data stream",style:{fill:9216967,fontFamily:"Inter, sans-serif",fontSize:12}}),this.realTimeText=new Dt({text:"",style:{fill:15265527,fontFamily:"IBM Plex Mono, monospace",fontSize:11}}),this.plotTimeText=new Dt({text:"",style:{fill:15265527,fontFamily:"IBM Plex Mono, monospace",fontSize:11}}),this.axisTitleText=new Dt({text:"",style:{fill:9478327,fontFamily:"Inter, sans-serif",fontSize:10,fontWeight:"600",letterSpacing:1.5}}),this.screenPoints=[],this.bounds={width:100,height:100},this.hoverRadiusPx=20,this.pointer=null,this.lastPointerEventAt=0,this.axisLabels=[]}async init(){const t=navigator.gpu?"webgpu":"webgl";return await this.app.init({preference:t,resizeTo:this.host,antialias:!0,backgroundAlpha:0,resolution:Math.min(window.devicePixelRatio||1,2)}),this.app.stage.addChild(this.container),this.container.addChild(this.background),this.container.addChild(this.grid),this.container.addChild(this.axes),this.container.addChild(this.line),this.container.addChild(this.points),this.container.addChild(this.crosshair),this.container.addChild(this.overlay),this.overlay.addChild(this.readoutBackground),this.overlay.addChild(this.axisLabelLayer),this.overlay.addChild(this.titleText),this.overlay.addChild(this.subtitleText),this.overlay.addChild(this.realTimeText),this.overlay.addChild(this.plotTimeText),this.overlay.addChild(this.axisTitleText),this.host.appendChild(this.app.canvas),this.attachPointerListeners(),t}attachPointerListeners(){this.host.addEventListener("pointerleave",()=>{this.pointer=null,this.lastPointerEventAt=performance.now()}),this.host.addEventListener("pointermove",t=>{const e=this.host.getBoundingClientRect();this.pointer={x:t.clientX-e.left,y:t.clientY-e.top},this.lastPointerEventAt=performance.now()})}resize(){this.bounds={width:this.host.clientWidth,height:this.host.clientHeight}}render(t,e){this.resize(),this.renderFrame(t,e),this.clearHover()}clearHover(){this.crosshair.clear()}getHoverCandidate(){if(!this.pointer||this.screenPoints.length===0)return null;let t=null,e=1/0;for(const i of this.screenPoints){const r=i.x-this.pointer.x,n=i.y-this.pointer.y,o=Math.sqrt(r*r+n*n);o<e&&(t=i,e=o)}return!t||e>this.hoverRadiusPx?null:{panelId:this.panelId,point:t,x:De(t.x,0,this.bounds.width),y:De(t.y,0,this.bounds.height),pointerX:this.pointer.x,pointerY:this.pointer.y,distance:e,lastPointerEventAt:this.lastPointerEventAt}}hasPointer(){return this.pointer!==null}findNearestScreenPointByTime(t){if(this.screenPoints.length===0)return null;let e=null,i=1/0;for(const r of this.screenPoints){const n=Math.abs(r.timeMs-t);n<i&&(e=r,i=n)}return e}renderLinkedHover(t){if(this.crosshair.clear(),!t)return;const e=De(t.x,0,this.bounds.width),i=De(t.y,0,this.bounds.height);this.crosshair.moveTo(e,0),this.crosshair.lineTo(e,this.bounds.height),this.crosshair.moveTo(0,i),this.crosshair.lineTo(this.bounds.width,i),this.crosshair.stroke({color:9222399,width:1,alpha:.24}),this.crosshair.rect(e-4,i-4,8,8),this.crosshair.stroke({color:16777215,width:1.5,alpha:.95})}ensureAxisLabelCount(t){for(;this.axisLabels.length<t;){const e=new Dt({text:"",style:{fill:9478327,fontFamily:"IBM Plex Mono, monospace",fontSize:10}});this.axisLabels.push(e),this.axisLabelLayer.addChild(e)}for(;this.axisLabels.length>t;){const e=this.axisLabels.pop();this.axisLabelLayer.removeChild(e),e.destroy()}}renderAxes({padding:t,plotWidth:e,plotHeight:i,minTime:r,maxTime:n,minValue:o,maxValue:a,width:h}){const d=[];this.axes.clear(),this.axes.moveTo(t.left,t.top),this.axes.lineTo(t.left,t.top+i),this.axes.lineTo(t.left+e,t.top+i),this.axes.stroke({color:4082783,width:1,alpha:1});for(let m=0;m<5;m+=1){const g=m/4,f=t.top+g*i,x=r+g*(n-r);this.axes.moveTo(t.left-8,f),this.axes.lineTo(t.left,f),this.axes.stroke({color:5202554,width:1,alpha:1}),d.push({text:Ot(x),x:14,y:f-7,anchorX:0})}for(let m=0;m<5;m+=1){const g=m/4,f=t.left+g*e,x=o+g*(a-o);this.axes.moveTo(f,t.top+i),this.axes.lineTo(f,t.top+i+8),this.axes.stroke({color:5202554,width:1,alpha:1}),d.push({text:Ls(x),x:f,y:t.top+i+10,anchorX:.5})}this.ensureAxisLabelCount(d.length),d.forEach((m,g)=>{const f=this.axisLabels[g];f.text=m.text,f.x=m.x,f.y=m.y,f.anchor.set(m.anchorX,0)}),this.axisTitleText.text="TIME",this.axisTitleText.x=18,this.axisTitleText.y=t.top-18,this.axisTitleText.rotation=0,this.axes.moveTo(t.left+e,t.top+i),this.axes.lineTo(h-14,t.top+i),this.axes.stroke({color:2107957,width:1,alpha:1})}renderReadouts(t,e){if(!this.showReadouts){this.readoutBackground.clear(),this.realTimeText.text="",this.plotTimeText.text="";return}const i=168,r=22,n=6,o=e-i-18,a=14;this.readoutBackground.clear(),this.readoutBackground.rect(o,a,i,r),this.readoutBackground.fill({color:1054237,alpha:1}),this.readoutBackground.stroke({color:3095629,width:1,alpha:1}),this.readoutBackground.rect(o,a+r+n,i,r),this.readoutBackground.fill({color:1054237,alpha:1}),this.readoutBackground.stroke({color:3095629,width:1,alpha:1}),this.realTimeText.text=`REAL ${Un(t.time.realNowMs)}`,this.realTimeText.x=o+10,this.realTimeText.y=a+5,this.plotTimeText.text=`PLOT ${Ot(t.time.plotTimeMs)}`,this.plotTimeText.x=o+10,this.plotTimeText.y=a+r+n+5}renderFrame(t,e){const i=this.bounds.width,r=this.bounds.height,n={top:72,right:28,bottom:46,left:88},o=Math.max(10,i-n.left-n.right),a=Math.max(10,r-n.top-n.bottom),h=t.time.plotTimeMs-t.plot.windowDurationMs,l=Math.max(t.time.plotTimeMs,h+1),{min:c,max:u}=t.plot.valueRange,p=Math.max(.001,u-c);if(this.background.clear(),rc(this.background,0,0,i,r,6,{color:329483,alpha:1},{color:2898765,width:1}),this.grid.clear(),t.plot.showGrid){for(let m=0;m<=6;m+=1){const g=n.left+o*m/6;this.grid.moveTo(g,n.top),this.grid.lineTo(g,n.top+a),this.grid.stroke({color:2176074,width:1,alpha:.85})}for(let m=0;m<=8;m+=1){const g=n.top+a*m/8;this.grid.moveTo(n.left,g),this.grid.lineTo(n.left+o,g),this.grid.stroke({color:2176074,width:1,alpha:.85})}}if(this.renderAxes({padding:n,plotWidth:o,plotHeight:a,minTime:h,maxTime:l,minValue:c,maxValue:u,width:i}),this.line.clear(),this.points.clear(),this.screenPoints=[],e.length>0&&(e.forEach((d,m)=>{const g=n.left+(d.value-c)/p*o,f=n.top+(d.timeMs-h)/(l-h)*a;this.screenPoints.push({...d,x:g,y:f}),m===0?this.line.moveTo(g,f):this.line.lineTo(g,f)}),this.line.stroke({color:this.lineColor,width:2,alpha:.96,cap:"square",join:"miter"}),t.plot.showPoints))for(const d of this.screenPoints)this.points.rect(d.x-2,d.y-2,4,4),this.points.fill({color:this.pointColor,alpha:.92});this.titleText.text=this.panelTitle,this.titleText.x=20,this.titleText.y=14,this.subtitleText.text=this.panelSubtitle??`value → ${t.source.preset} · ${t.source.sampleRateHz} hz · time ↓`,this.subtitleText.x=20,this.subtitleText.y=36,this.renderReadouts(t,i)}destroy(){this.app.destroy(!0,{children:!0})}}class ti{constructor(t={}){this.config={...t},this.running=!1}start(){this.running=!0}stop(){this.running=!1}updateConfig(t){this.config={...this.config,...t}}}function nc(s,t,e){return Math.min(e,Math.max(t,s))}class oc extends ti{constructor(t={}){super({replayRate:1,dataset:[],...t}),this.sourceType="csv-replay",this.nextPointIndex=0}start(t=0){super.start(),this.reset(t)}reset(){this.nextPointIndex=0}updateConfig(t){const e=t.dataset!==this.config.dataset;super.updateConfig(t),e&&this.reset()}update(t){if(!this.running||!Array.isArray(this.config.dataset)||this.config.dataset.length===0)return[];const e=nc(this.config.replayRate??1,.1,8),i=t*e,r=[];for(;this.nextPointIndex<this.config.dataset.length;){const n=this.config.dataset[this.nextPointIndex];if(n.timeMs>i)break;r.push({timeMs:n.timeMs/e,value:n.value,sourceId:this.config.id??"csv-replay"}),this.nextPointIndex+=1}return r}}function ac(s,t,e){return Math.min(e,Math.max(t,s))}function hc(s){const t=Math.sin(s*12.9898)*43758.5453;return t-Math.floor(t)}class lc extends ti{constructor(t={}){super({sampleRateHz:60,preset:"telemetry",amplitude:1,noise:.08,...t}),this.sourceType="synthetic-wave",this.lastEmittedPlotTimeMs=0}start(t=0){super.start(),this.lastEmittedPlotTimeMs=t}stop(){super.stop()}reset(t=0){this.lastEmittedPlotTimeMs=t}sampleValue(t){const e=t/1e3,i=this.config.amplitude,r=this.config.noise,n=(hc(t*.017)-.5)*2*r;switch(this.config.preset){case"chirp":{const o=Math.sin(e*e*1.4);return i*(.7*o+.3*Math.sin(e*7.5))+n}case"burst":{const o=e%6-1.5,a=Math.sin(e*9.5)*Math.exp(-(o**2)*.8);return i*(.45*Math.sin(e*2.1)+a)+n}case"telemetry":default:{const o=Math.sin(e*2.2),a=.35*Math.cos(e*6.4+Math.sin(e*.8)),h=.15*Math.sin(e*.33);return i*(o+a+h)+n}}}update(t){if(!this.running)return[];const e=1e3/ac(this.config.sampleRateHz,1,240);if(t<this.lastEmittedPlotTimeMs)return this.lastEmittedPlotTimeMs=t,[];const i=[];for(;this.lastEmittedPlotTimeMs+e<=t;)this.lastEmittedPlotTimeMs+=e,i.push({timeMs:this.lastEmittedPlotTimeMs,value:this.sampleValue(this.lastEmittedPlotTimeMs),sourceId:"synthetic-wave"});return i}}function cc(s,t,e){return Math.min(e,Math.max(t,s))}function $n(s){return typeof s=="number"&&Number.isFinite(s)}function Ds(s){if(Array.isArray(s))return s.flatMap(t=>Ds(t));if($n(s))return[{value:s,timestampMs:null}];if(typeof s=="string"){const t=s.trim();if(!t)return[];const e=Number(t);if(Number.isFinite(e))return[{value:e,timestampMs:null}];try{return Ds(JSON.parse(t))}catch{return[]}}if(s&&typeof s=="object"){const t=[s.value,s.y,s.signal,s.data].find(i=>Number.isFinite(Number(i)));if(t===void 0)return[];const e=[s.timeMs,s.timestampMs,s.timestamp,s.t].find(i=>Number.isFinite(Number(i)));return[{value:Number(t),timestampMs:e===void 0?null:Number(e)}]}return[]}class uc extends ti{constructor(t={},{onStatusChange:e}={}){super({wsUrl:"ws://localhost:8080",wsReconnectMs:2e3,...t}),this.sourceType="websocket",this.onStatusChange=e,this.socket=null,this.queue=[],this.lastPlotTimeMs=0,this.reconnectTimer=null,this.shouldReconnect=!1,this.firstSourceTimestampMs=null,this.basePlotTimeMs=0}start(t=0){super.start(),this.lastPlotTimeMs=t,this.basePlotTimeMs=t,this.shouldReconnect=!0,this.connect()}stop(){super.stop(),this.shouldReconnect=!1,this.clearReconnectTimer(),this.socket&&(this.socket.close(),this.socket=null),this.setStatus("disconnected","socket closed")}reset(t=0){this.queue=[],this.lastPlotTimeMs=t,this.basePlotTimeMs=t,this.firstSourceTimestampMs=null}updateConfig(t){const e=this.config.wsUrl,i=this.config.wsReconnectMs;super.updateConfig(t),(e!==this.config.wsUrl||i!==this.config.wsReconnectMs)&&this.running&&this.reconnect()}update(t){if(this.lastPlotTimeMs=t,this.queue.length===0)return[];const e=[];for(;this.queue.length>0;){const i=this.queue.shift();let r=t;$n(i.timestampMs)&&(this.firstSourceTimestampMs===null&&(this.firstSourceTimestampMs=i.timestampMs,this.basePlotTimeMs=t),r=this.basePlotTimeMs+(i.timestampMs-this.firstSourceTimestampMs)),e.push({timeMs:r,value:i.value,sourceId:this.config.id??"websocket"})}return e}reconnect(){this.running&&(this.clearReconnectTimer(),this.socket&&(this.socket.close(),this.socket=null),this.connect())}connect(){var e;const t=(e=this.config.wsUrl)==null?void 0:e.trim();if(!t){this.setStatus("idle","enter a websocket url");return}this.clearReconnectTimer(),this.setStatus("connecting",t);try{this.socket=new WebSocket(t)}catch(i){this.setStatus("error",i instanceof Error?i.message:String(i)),this.scheduleReconnect();return}this.socket.addEventListener("open",()=>{this.setStatus("connected",t)}),this.socket.addEventListener("message",i=>{const r=Ds(i.data);r.length!==0&&this.queue.push(...r)}),this.socket.addEventListener("error",()=>{this.setStatus("error","socket error")}),this.socket.addEventListener("close",()=>{this.socket=null,this.running&&(this.setStatus("disconnected","retrying"),this.scheduleReconnect())})}scheduleReconnect(){if(!this.shouldReconnect||!this.running)return;const t=cc(Number(this.config.wsReconnectMs)||2e3,250,3e4);this.clearReconnectTimer(),this.reconnectTimer=window.setTimeout(()=>{this.connect()},t)}clearReconnectTimer(){this.reconnectTimer!==null&&(window.clearTimeout(this.reconnectTimer),this.reconnectTimer=null)}setStatus(t,e=""){var i;(i=this.onStatusChange)==null||i.call(this,{wsStatus:t,wsStatusDetail:e})}}class dc{constructor(t,e){this.store=t,this.bus=e,this.sources=new Map,this.syncFromState()}syncFromState(){const t=this.store.getState(),e=Object.entries(t.sources),i=new Set(e.map(([r])=>r));for(const[r,n]of e){const o=this.sources.get(r);if(!o){const a=this.createSource(r,n);this.sources.set(r,a),a.start(t.time.plotTimeMs);continue}if(o.sourceType!==n.type){o.stop();const a=this.createSource(r,n);this.sources.set(r,a),a.start(t.time.plotTimeMs);continue}o.updateConfig(n)}for(const[r,n]of this.sources.entries())i.has(r)||(n.stop(),this.sources.delete(r))}createSource(t,e){switch(e.type){case"csv-replay":return new oc(e);case"websocket":return new uc(e,{onStatusChange:i=>{this.store.setState(r=>({...r,sources:{...r.sources,[t]:{...r.sources[t],...i}}}))}});case"synthetic-wave":default:return new lc(e)}}update(t){for(const[e,i]of this.sources.entries()){const r=i.update(t);for(const n of r)this.bus.emit("data:point",{...n,sourceId:e})}}reset(){const t=this.store.getState().time.plotTimeMs;for(const e of this.sources.values())e.reset(t)}}function fc(s){return s.split(/[;,\t]/).map(t=>t.trim())}function zs(s){return s!==""&&Number.isFinite(Number(s))}function pc(s){if(s.length===0)return{hasHeader:!1,headers:[]};const[t]=s,e=t.some(i=>!zs(i));return{hasHeader:e,headers:e?t.map(i=>i.toLowerCase()):[]}}function mc(s){const t=s.find(e=>e.includes("time")||e.includes("timestamp"));return t&&t.includes("sec")&&!t.includes("msec")&&!t.includes("ms")?1e3:1}function gc(s,t){if(s.length===0)return{timeIndex:t>1?0:-1,valueIndex:t>1?1:0};const e=s.findIndex(r=>r.includes("time")||r.includes("timestamp")),i=s.findIndex(r=>r.includes("value")||r.includes("signal")||r.includes("y"));return{timeIndex:e,valueIndex:i>=0?i:s.length>1?1:0}}function xc(s,{sampleRateHz:t=60}={}){var m;const e=s.split(/\r?\n/).map(g=>g.trim()).filter(g=>g&&!g.startsWith("#")).map(fc).filter(g=>g.some(f=>f!==""));if(e.length===0)throw new Error("CSV file is empty");const{hasHeader:i,headers:r}=pc(e),n=i?e.slice(1):e,o=e[0].length,{timeIndex:a,valueIndex:h}=gc(r,o),l=mc(r),c=1e3/Math.max(1,t),u=n.map((g,f)=>{const x=g[h];if(!zs(x))return null;const y=Number(x);return{timeMs:a>=0&&zs(g[a])?Number(g[a])*l:f*c,value:y}}).filter(Boolean).sort((g,f)=>g.timeMs-f.timeMs);if(u.length===0)throw new Error("CSV file did not contain any numeric data points");const p=u[0].timeMs,d=u.map(g=>({timeMs:g.timeMs-p,value:g.value}));return{points:d,metadata:{pointCount:d.length,durationMs:((m=d.at(-1))==null?void 0:m.timeMs)??0}}}function H(s,t,e){const i=document.createElement(s);return t&&(i.className=t),e&&(i.textContent=e),i}function mr(s,t){s.dataset.active=String(t)}function gr(s){return s.tagName==="SELECT"?s.value:s instanceof HTMLInputElement?s.type==="checkbox"?s.checked:s.type==="number"||s.type==="range"?Number(s.value):s.value:s.value}function j(s,t){if(!(!s||document.activeElement===s)){if(s instanceof HTMLInputElement&&s.type==="checkbox"){s.checked=!!t;return}s.value=String(t??"")}}class yc{constructor({root:t,store:e,actions:i}){this.root=t,this.store=e,this.actions=i,this.elements={}}mount(){const t=H("div","timeplot-shell"),e=H("header","timeplot-topbar"),i=H("section","timeplot-viewport"),r=H("div","timeplot-plot-grid"),n=H("section","timeplot-plot-panel"),o=H("section","timeplot-plot-panel"),a=H("div","timeplot-canvas-host"),h=H("div","timeplot-canvas-host"),l=H("aside","timeplot-sidebar"),c=H("div","timeplot-tooltip"),u=H("div","timeplot-tooltip");c.hidden=!0,u.hidden=!0;const p=H("div","timeplot-brand"),d=H("h1","timeplot-title","TimePlot"),m=H("div","timeplot-subtitle","Dual synchronized signal monitor");p.append(d,m);const g=H("div","timeplot-toolbar");return g.append(this.createTransportControls(),this.createPanelToggles()),e.append(p,g),n.append(a,c),o.append(h,u),r.append(n,o),i.append(r),t.append(e,i,l),this.root.replaceChildren(t),this.elements={...this.elements,shell:t,topbar:e,viewport:i,plotGrid:r,primaryPlotPanel:n,secondaryPlotPanel:o,primaryCanvasHost:a,secondaryCanvasHost:h,sidebar:l,primaryTooltip:c,secondaryTooltip:u,title:d,subtitle:m,statusPanel:this.createStatusPanel(),sourcePanel:this.createSourcePanel(),configPanel:this.createConfigPanel(),helpPanel:this.createHelpPanel()},l.append(this.elements.statusPanel,this.elements.sourcePanel,this.elements.configPanel,this.elements.helpPanel),this.elements}createTransportControls(){const t=H("div","control-group"),e=H("button","control-button","Pause"),i=H("button","control-button","Reset"),r=H("span",null,"Speed"),n=document.createElement("input");n.type="range",n.min="0.1",n.max="6",n.step="0.1";const o=H("span",null,"1.0×");return e.addEventListener("click",()=>this.actions.togglePause()),i.addEventListener("click",()=>this.actions.resetScene()),n.addEventListener("input",a=>this.actions.setSpeed(Number(a.target.value))),t.append(e,i,r,n,o),this.elements.pauseButton=e,this.elements.resetButton=i,this.elements.speedInput=n,this.elements.speedValue=o,t}createPanelToggles(){const t=H("div","control-group"),e=["status","source","config","help"];this.elements.panelButtons={};for(const i of e){const r=H("button","panel-toggle",i);r.addEventListener("click",()=>this.actions.togglePanel(i)),this.elements.panelButtons[i]=r,t.append(r)}return t}createStatusPanel(){const t=H("section","panel");return t.innerHTML=` + <h2>Status</h2> + <dl class="kv-list"> + <dt>Renderer</dt><dd data-field="renderer">—</dd> + <dt>Real time</dt><dd data-field="realTime">—</dd> + <dt>Real elapsed</dt><dd data-field="realElapsed">—</dd> + <dt>Plot time</dt><dd data-field="plotTime">—</dd> + <dt>Playback</dt><dd data-field="playback">—</dd> + <dt>Points</dt><dd data-field="points">—</dd> + </dl> + `,t}createSourcePanel(){const t=H("section","panel");return t.innerHTML=` + <h2>Data Source</h2> + <div class="panel-subsection" data-source-config="signalA"> + <div class="panel-section-title">Signal A</div> + <div class="field-grid"> + <label> + Source type + <select data-source-key="signalA" data-source-field="type"> + <option value="synthetic-wave">Synthetic wave</option> + <option value="csv-replay">CSV replay</option> + <option value="websocket">WebSocket</option> + </select> + </label> + </div> + <div class="field-grid" data-source-mode="synthetic-wave"> + <label> + Preset + <select data-source-key="signalA" data-source-field="preset"> + <option value="telemetry">Telemetry</option> + <option value="chirp">Chirp</option> + <option value="burst">Burst</option> + </select> + </label> + <label> + Sample rate (Hz) + <input data-source-key="signalA" data-source-field="sampleRateHz" type="number" min="1" max="240" step="1" /> + </label> + <label> + Amplitude + <input data-source-key="signalA" data-source-field="amplitude" type="number" min="0.1" max="3" step="0.1" /> + </label> + <label> + Noise + <input data-source-key="signalA" data-source-field="noise" type="number" min="0" max="0.5" step="0.01" /> + </label> + </div> + <div class="field-grid" data-source-mode="csv-replay"> + <label> + CSV file + <input data-source-key="signalA" data-source-file="dataset" type="file" accept=".csv,text/csv" /> + </label> + <label> + Replay rate + <input data-source-key="signalA" data-source-field="replayRate" type="number" min="0.1" max="8" step="0.1" /> + </label> + <div class="source-meta" data-source-key="signalA" data-source-meta></div> + </div> + <div class="field-grid" data-source-mode="websocket"> + <label> + WebSocket URL + <input data-source-key="signalA" data-source-field="wsUrl" type="url" placeholder="ws://localhost:8080" /> + </label> + <label> + Reconnect (ms) + <input data-source-key="signalA" data-source-field="wsReconnectMs" type="number" min="250" max="30000" step="250" /> + </label> + <div class="source-meta" data-source-key="signalA" data-source-ws-meta></div> + </div> + </div> + <div class="panel-subsection" data-source-config="signalB"> + <div class="panel-section-title">Signal B</div> + <div class="field-grid"> + <label> + Source type + <select data-source-key="signalB" data-source-field="type"> + <option value="synthetic-wave">Synthetic wave</option> + <option value="csv-replay">CSV replay</option> + <option value="websocket">WebSocket</option> + </select> + </label> + </div> + <div class="field-grid" data-source-mode="synthetic-wave"> + <label> + Preset + <select data-source-key="signalB" data-source-field="preset"> + <option value="telemetry">Telemetry</option> + <option value="chirp">Chirp</option> + <option value="burst">Burst</option> + </select> + </label> + <label> + Sample rate (Hz) + <input data-source-key="signalB" data-source-field="sampleRateHz" type="number" min="1" max="240" step="1" /> + </label> + <label> + Amplitude + <input data-source-key="signalB" data-source-field="amplitude" type="number" min="0.1" max="3" step="0.1" /> + </label> + <label> + Noise + <input data-source-key="signalB" data-source-field="noise" type="number" min="0" max="0.5" step="0.01" /> + </label> + </div> + <div class="field-grid" data-source-mode="csv-replay"> + <label> + CSV file + <input data-source-key="signalB" data-source-file="dataset" type="file" accept=".csv,text/csv" /> + </label> + <label> + Replay rate + <input data-source-key="signalB" data-source-field="replayRate" type="number" min="0.1" max="8" step="0.1" /> + </label> + <div class="source-meta" data-source-key="signalB" data-source-meta></div> + </div> + <div class="field-grid" data-source-mode="websocket"> + <label> + WebSocket URL + <input data-source-key="signalB" data-source-field="wsUrl" type="url" placeholder="ws://localhost:8080" /> + </label> + <label> + Reconnect (ms) + <input data-source-key="signalB" data-source-field="wsReconnectMs" type="number" min="250" max="30000" step="250" /> + </label> + <div class="source-meta" data-source-key="signalB" data-source-ws-meta></div> + </div> + </div> + `,t.querySelectorAll("[data-source-field]").forEach(e=>{const i=e.tagName==="SELECT"?"change":"input";e.addEventListener(i,()=>{const r=e.getAttribute("data-source-key"),n=e.getAttribute("data-source-field"),o=gr(e);this.actions.updateSource(r,n,o)})}),t.querySelectorAll("[data-source-file]").forEach(e=>{e.addEventListener("change",async()=>{var n;const i=e.getAttribute("data-source-key"),r=(n=e.files)==null?void 0:n[0];r&&(await this.actions.loadSourceFile(i,r),e.value="")})}),t}createConfigPanel(){const t=H("section","panel");return t.innerHTML=` + <h2>Config</h2> + <div class="field-grid"> + <label> + Visible window (ms) + <input data-plot-field="windowDurationMs" type="number" min="2000" max="120000" step="1000" /> + </label> + <label> + Max points + <input data-plot-field="maxPoints" type="number" min="200" max="4000" step="100" /> + </label> + <div class="panel-row"> + <span>Show grid</span> + <input data-plot-field="showGrid" type="checkbox" /> + </div> + <div class="panel-row"> + <span>Show points</span> + <input data-plot-field="showPoints" type="checkbox" /> + </div> + </div> + <div class="panel-subsection"> + <div class="panel-section-title">Graph routing</div> + <div class="field-grid"> + <label> + Primary graph source + <select data-graph-id="primary" data-graph-field="sourceKey"> + <option value="signalA">Signal A</option> + <option value="signalB">Signal B</option> + </select> + </label> + <label> + Primary graph transform + <select data-graph-id="primary" data-graph-field="transform"> + <option value="raw">Raw</option> + <option value="delta">Delta</option> + <option value="smooth">Smooth</option> + </select> + </label> + <label> + Secondary graph source + <select data-graph-id="secondary" data-graph-field="sourceKey"> + <option value="signalA">Signal A</option> + <option value="signalB">Signal B</option> + </select> + </label> + <label> + Secondary graph transform + <select data-graph-id="secondary" data-graph-field="transform"> + <option value="raw">Raw</option> + <option value="delta">Delta</option> + <option value="smooth">Smooth</option> + </select> + </label> + </div> + </div> + `,t.querySelectorAll("[data-plot-field]").forEach(e=>{const i=e instanceof HTMLInputElement&&e.type==="checkbox"?"change":"input";e.addEventListener(i,()=>{const r=e.getAttribute("data-plot-field"),n=gr(e);this.actions.updatePlot(r,n)})}),t.querySelectorAll("[data-graph-field]").forEach(e=>{e.addEventListener("change",()=>{const i=e.getAttribute("data-graph-id"),r=e.getAttribute("data-graph-field");this.actions.updateGraph(i,r,e.value)})}),t}createHelpPanel(){const t=H("section","panel");return t.innerHTML=` + <h2>Help</h2> + <ol class="help-list"> + <li>Each signal can be synthetic or file-backed CSV replay.</li> + <li>Each graph can target Signal A or Signal B independently.</li> + <li>Each graph can render raw, delta, or smoothed data.</li> + <li>Hover either trace to inspect the nearest synchronized sample.</li> + <li>Use pause and speed controls to inspect timing behavior.</li> + </ol> + `,t}sync(t,e){this.elements.title.textContent=t.app.title,this.elements.subtitle.textContent="Dual synchronized signal monitor",this.elements.pauseButton.textContent=t.time.paused?"Resume":"Pause",mr(this.elements.pauseButton,t.time.paused),j(this.elements.speedInput,t.time.speed),this.elements.speedValue.textContent=`${t.time.speed.toFixed(1)}×`;const i=this.elements.statusPanel.querySelectorAll("[data-field]"),r=Object.fromEntries(Array.from(i).map(n=>[n.getAttribute("data-field"),n]));r.renderer.textContent=t.app.renderer,r.realTime.textContent=Un(t.time.realNowMs),r.realElapsed.textContent=Ot(t.time.realElapsedMs),r.plotTime.textContent=Ot(t.time.plotTimeMs),r.playback.textContent=t.time.paused?"Paused":`${t.time.speed.toFixed(1)}×`,r.points.textContent=typeof e=="object"?`${e.primary} / ${e.secondary}`:`${e}`,this.syncSourcePanel(t),this.syncConfigPanel(t),this.syncPanels(t),this.syncTooltip(t)}syncSourcePanel(t){Object.entries(t.sources).forEach(([e,i])=>{j(this.elements.sourcePanel.querySelector(`[data-source-key="${e}"][data-source-field="type"]`),i.type),j(this.elements.sourcePanel.querySelector(`[data-source-key="${e}"][data-source-field="preset"]`),i.preset),j(this.elements.sourcePanel.querySelector(`[data-source-key="${e}"][data-source-field="sampleRateHz"]`),i.sampleRateHz),j(this.elements.sourcePanel.querySelector(`[data-source-key="${e}"][data-source-field="amplitude"]`),i.amplitude),j(this.elements.sourcePanel.querySelector(`[data-source-key="${e}"][data-source-field="noise"]`),i.noise);const r=this.elements.sourcePanel.querySelector(`[data-source-key="${e}"][data-source-field="replayRate"]`);r&&j(r,i.replayRate??1),this.elements.sourcePanel.querySelector(`[data-source-config="${e}"]`).querySelectorAll("[data-source-mode]").forEach(c=>{c.hidden=c.getAttribute("data-source-mode")!==i.type});const o=this.elements.sourcePanel.querySelector(`[data-source-key="${e}"][data-source-meta]`);o&&(i.type==="csv-replay"?o.innerHTML=i.loadError?`<span class="source-meta-error">${i.loadError}</span>`:`${i.dataFileName||"No file loaded"}${i.datasetPointCount?` · ${i.datasetPointCount} pts · ${Ot(i.datasetDurationMs||0)}`:""}`:i.type==="websocket"?o.textContent="":o.textContent="Generates data procedurally in-browser");const a=this.elements.sourcePanel.querySelector(`[data-source-key="${e}"][data-source-field="wsUrl"]`),h=this.elements.sourcePanel.querySelector(`[data-source-key="${e}"][data-source-field="wsReconnectMs"]`),l=this.elements.sourcePanel.querySelector(`[data-source-key="${e}"][data-source-ws-meta]`);a&&j(a,i.wsUrl??""),h&&j(h,i.wsReconnectMs??2e3),l&&(l.innerHTML=i.type==="websocket"?`status: <span class="source-meta-status source-meta-status-${i.wsStatus||"idle"}">${i.wsStatus||"idle"}</span>${i.wsStatusDetail?` · ${i.wsStatusDetail}`:""}`:"")})}syncConfigPanel(t){j(this.elements.configPanel.querySelector('[data-plot-field="windowDurationMs"]'),t.plot.windowDurationMs),j(this.elements.configPanel.querySelector('[data-plot-field="maxPoints"]'),t.plot.maxPoints),j(this.elements.configPanel.querySelector('[data-plot-field="showGrid"]'),t.plot.showGrid),j(this.elements.configPanel.querySelector('[data-plot-field="showPoints"]'),t.plot.showPoints),j(this.elements.configPanel.querySelector('[data-graph-id="primary"][data-graph-field="sourceKey"]'),t.graphs.primary.sourceKey),j(this.elements.configPanel.querySelector('[data-graph-id="primary"][data-graph-field="transform"]'),t.graphs.primary.transform),j(this.elements.configPanel.querySelector('[data-graph-id="secondary"][data-graph-field="sourceKey"]'),t.graphs.secondary.sourceKey),j(this.elements.configPanel.querySelector('[data-graph-id="secondary"][data-graph-field="transform"]'),t.graphs.secondary.transform)}syncPanels(t){const e={status:this.elements.statusPanel,source:this.elements.sourcePanel,config:this.elements.configPanel,help:this.elements.helpPanel};for(const[i,r]of Object.entries(t.panels))e[i].hidden=!r.visible,mr(this.elements.panelButtons[i],r.visible)}syncTooltip(t){const e=t.plot.tooltip;if(this.elements.primaryTooltip.hidden=!0,this.elements.secondaryTooltip.hidden=!0,!e.visible||!e.point)return;const i=e.panelId==="secondary"?this.elements.secondaryTooltip:this.elements.primaryTooltip;i.hidden=!1,i.style.left=`${e.x}px`,i.style.top=`${e.y}px`,i.innerHTML=` + <div class="timeplot-tooltip-title">Hovered sample</div> + <div class="timeplot-tooltip-row"><span class="muted">Panel</span><span>${e.panelLabel??"Primary"}</span></div> + <div class="timeplot-tooltip-row"><span class="muted">Plot time</span><span>${Ot(e.point.timeMs)}</span></div> + <div class="timeplot-tooltip-row"><span class="muted">Value</span><span>${Ls(e.point.value)}</span></div> + <div class="timeplot-tooltip-row"><span class="muted">Source</span><span>${e.point.sourceId}</span></div> + ${e.linkedPoint?`<div class="timeplot-tooltip-row"><span class="muted">Linked panel</span><span>${e.linkedPanelLabel??"Linked"}</span></div>`:""} + ${e.linkedPoint?`<div class="timeplot-tooltip-row"><span class="muted">Linked value</span><span>${Ls(e.linkedPoint.value)}</span></div>`:""} + `}}function xr(s,t,e){return Math.min(e,Math.max(t,s))}function _c(s){if(s.length<2)return[];const t=[];for(let e=1;e<s.length;e+=1){const i=s[e-1],r=s[e],n=Math.max(1,r.timeMs-i.timeMs);t.push({...r,value:(r.value-i.value)/n*1e3,sourceId:`${r.sourceId}:delta`})}return t}function bc(s,t=5){if(s.length===0)return[];const e=[];for(let i=0;i<s.length;i+=1){const r=Math.max(0,i-t+1),n=s.slice(r,i+1),o=n.reduce((a,h)=>a+h.value,0)/n.length;e.push({...s[i],value:o,sourceId:`${s[i].sourceId}:smooth`})}return e}function wc(s,t){switch(t){case"delta":return _c(s);case"smooth":return bc(s);case"raw":default:return s}}function yr(s){switch(s){case"delta":return"Δvalue / second";case"smooth":return"moving average";case"raw":default:return"raw signal"}}function Sc(s,t){if(s.length===0)return t;let e=1/0,i=-1/0;for(const n of s)e=Math.min(e,n.value),i=Math.max(i,n.value);const r=Math.max(Math.abs(e),Math.abs(i),.1);return{min:-r,max:r}}function vc(s,t){return!s&&!t?null:s&&!t?s:!s&&t?t:s.lastPointerEventAt>=t.lastPointerEventAt?s:t}async function Pc(s){const t=new Wn,e=new Kn(br()),i=new Qn(e),r=new Map(Object.keys(e.getState().sources).map(f=>[f,new ni(e.getState().plot.maxPoints)]));let n;const o=()=>{const f=e.getState();for(const x of Object.keys(f.sources))r.has(x)||r.set(x,new ni(f.plot.maxPoints)),r.get(x).maxPoints=f.plot.maxPoints;for(const x of Array.from(r.keys()))f.sources[x]||r.delete(x)},a=f=>{var x;(x=r.get(f))==null||x.clear()},h=(f,x)=>{const y=f.graphs[x],_=r.get(y.sourceKey),b=_?_.getVisiblePoints(f.time.plotTimeMs,f.plot.windowDurationMs):[],v=wc(b,y.transform);return{graphConfig:y,points:v,range:Sc(v,f.plot.valueRange)}},l={togglePause:()=>i.togglePause(),setSpeed:f=>i.setSpeed(f),resetScene:()=>{i.reset(),r.forEach(f=>f.clear()),n.reset()},togglePanel:f=>{e.setState(x=>({...x,panels:{...x.panels,[f]:{...x.panels[f],visible:!x.panels[f].visible}}}))},updateSource:(f,x,y)=>{e.setState(_=>({..._,sources:{..._.sources,[f]:{..._.sources[f],[x]:y,...x==="type"?{loadError:y==="csv-replay"&&_.sources[f].dataset.length===0?_.sources[f].dataFileName?`Reload ${_.sources[f].dataFileName} to restore replay data`:"Load a CSV file to begin replay":"",wsStatus:y==="websocket"?_.sources[f].wsStatus:"idle",wsStatusDetail:y==="websocket"?_.sources[f].wsStatusDetail:""}:{}}}})),n.syncFromState(),o(),(x==="type"||x==="wsUrl"||x==="wsReconnectMs")&&(a(f),n.reset())},loadSourceFile:async(f,x)=>{var y;try{const b=((y=e.getState().sources[f])==null?void 0:y.sampleRateHz)??60,v=await x.text(),{points:S,metadata:w}=xc(v,{sampleRateHz:b});a(f),e.setState(R=>({...R,sources:{...R.sources,[f]:{...R.sources[f],type:"csv-replay",dataset:S,dataFileName:x.name,datasetPointCount:w.pointCount,datasetDurationMs:w.durationMs,loadError:"",wsStatus:"idle",wsStatusDetail:""}}})),n.syncFromState(),n.reset()}catch(_){e.setState(b=>({...b,sources:{...b.sources,[f]:{...b.sources[f],loadError:_ instanceof Error?_.message:String(_)}}}))}},updatePlot:(f,x)=>{e.setState(y=>({...y,plot:{...y.plot,[f]:x}})),f==="maxPoints"&&(buffer.maxPoints=xr(x,200,4e3),r.forEach(y=>{y.maxPoints=xr(x,200,4e3)}))},updateGraph:(f,x,y)=>{e.setState(_=>({..._,graphs:{..._.graphs,[f]:{..._.graphs[f],[x]:y}}}))}},c=new yc({root:s,store:e,actions:l}),u=c.mount(),p=new pr({host:u.primaryCanvasHost,panelId:"primary",title:"Primary signal",subtitle:null,showReadouts:!0,lineColor:10473983,pointColor:15201023}),d=new pr({host:u.secondaryCanvasHost,panelId:"secondary",title:"Secondary signal",subtitle:null,showReadouts:!1,lineColor:16761963,pointColor:16769456}),m=await p.init();await d.init(),e.patch({app:{...e.getState().app,renderer:m}}),n=new dc(e,t),t.on("data:point",f=>{var x;(x=r.get(f.sourceId))==null||x.addPoint(f)});const g=f=>{if(!(f.target instanceof HTMLInputElement||f.target instanceof HTMLSelectElement)){if(f.code==="Space"){f.preventDefault(),l.togglePause();return}if(f.key==="["){l.setSpeed(e.getState().time.speed-.1);return}if(f.key==="]"){l.setSpeed(e.getState().time.speed+.1);return}f.key.toLowerCase()==="g"&&l.updatePlot("showGrid",!e.getState().plot.showGrid)}};return window.addEventListener("keydown",g),p.app.ticker.add(()=>{i.tick(),n.syncFromState(),o(),n.update(e.getState().time.plotTimeMs);const f=e.getState(),x=h(f,"primary"),y=h(f,"secondary");p.panelTitle=f.graphs.primary.title,p.panelSubtitle=`${f.sources[f.graphs.primary.sourceKey].label} · ${yr(f.graphs.primary.transform)} · time ↓`,d.panelTitle=f.graphs.secondary.title,d.panelSubtitle=`${f.sources[f.graphs.secondary.sourceKey].label} · ${yr(f.graphs.secondary.transform)} · time ↓`;const _={...f,plot:{...f.plot,valueRange:x.range}},b={...f,plot:{...f.plot,valueRange:y.range}};p.render(_,x.points),d.render(b,y.points);const v=p.getHoverCandidate(),S=d.getHoverCandidate(),w=vc(v,S);if(!w){p.clearHover(),d.clearHover(),e.setState(E=>({...E,plot:{...E.plot,hoveredPoint:null,tooltip:{...E.plot.tooltip,visible:!1,point:null,linkedPoint:null}}})),c.sync(e.getState(),{primary:x.points.length,secondary:y.points.length});return}const R=p.findNearestScreenPointByTime(w.point.timeMs),k=d.findNearestScreenPointByTime(w.point.timeMs);p.renderLinkedHover(R),d.renderLinkedHover(k);const P=w.panelId==="secondary"?f.graphs.secondary.title:f.graphs.primary.title,M=w.panelId==="secondary"?R:k,G=w.panelId==="secondary"?f.graphs.primary.title:f.graphs.secondary.title;e.setState(E=>({...E,plot:{...E.plot,hoveredPoint:w.point,tooltip:{...E.plot.tooltip,visible:!0,panelId:w.panelId,panelLabel:P,x:w.x,y:w.y,point:w.point,linkedPoint:M,linkedPanelLabel:G}}})),c.sync(e.getState(),{primary:x.points.length,secondary:y.points.length})}),{destroy(){window.removeEventListener("keydown",g),p.destroy(),d.destroy()}}}const Hs=document.getElementById("app");if(!Hs)throw new Error("App root not found");Pc(Hs).catch(s=>{console.error("Failed to start TimePlot",s),Hs.innerHTML=` + <div style="padding: 24px; color: #fff; font-family: sans-serif;"> + <h1>TimePlot failed to start</h1> + <pre>${String(s)}</pre> + </div> + `});export{Wo as $,xn as A,J as B,ft as C,et as D,L as E,Nr as F,Ye as G,bi as H,de as I,ga as J,Ma as K,_e as L,I as M,V as N,W as O,Z as P,Oa as Q,Cs as R,dh as S,ke as T,vs as U,Si as V,rs as W,vi as X,Xo as Y,Ue as Z,Y as _,pt as a,Lr as a0,yn as a1,F as a2,O as a3,ja as a4,Sh as a5,mh as a6,Uh as a7,Oh as a8,jh as a9,Zh as aa,Kh as ab,Sn as ac,Nt as ad,$e as ae,lr as af,Nn as ag,Za as ah,Ht as ai,In as aj,Hi as ak,Di as al,dt as am,po as an,fr as ao,Gn as ap,xe as b,He as c,Ws as d,rt as e,zi as f,lh as g,pn as h,Xr as i,ht as j,ln as k,Gs as l,Nh as m,$h as n,Yh as o,qh as p,Ys as q,Ao as r,D as s,nn as t,fo as u,Jh as v,Q as w,it as x,Br as y,at as z}; diff --git a/dist/assets/index-DCiDMyds.css b/dist/assets/index-DCiDMyds.css new file mode 100644 index 0000000..5b91335 --- /dev/null +++ b/dist/assets/index-DCiDMyds.css @@ -0,0 +1 @@ +:root{color-scheme:dark;--bg: #0a0c10;--bg-alt: #0f1319;--surface: #11161d;--surface-strong: #0d1117;--surface-raised: #171d26;--border: #28313d;--border-strong: #394657;--text: #edf2f7;--muted: #97a3b4;--accent: #9fc7ff;--accent-strong: #d8e8ff;--shadow: none;font-family:Inter,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif}*{box-sizing:border-box}html,body,#app{width:100%;height:100%;margin:0}body{background:linear-gradient(180deg,#080a0d,#0d1015);color:var(--text);overflow:hidden}button,input,select{font:inherit}.timeplot-shell{display:grid;grid-template-columns:minmax(0,1fr) 340px;grid-template-rows:auto minmax(0,1fr);width:100%;height:100%;gap:10px;padding:10px}.timeplot-topbar{grid-column:1 / -1;display:flex;align-items:center;justify-content:space-between;gap:16px;padding:12px 14px;border:1px solid var(--border-strong);background:var(--surface);border-radius:4px;box-shadow:var(--shadow)}.timeplot-brand{display:flex;flex-direction:column;gap:2px}.timeplot-title{margin:0;font-size:1rem;letter-spacing:.08em;text-transform:uppercase;font-weight:700}.timeplot-subtitle{color:var(--muted);font-size:.78rem;letter-spacing:.04em;text-transform:uppercase}.timeplot-toolbar{display:flex;align-items:center;gap:10px;flex-wrap:wrap;justify-content:flex-end}.control-group{display:flex;align-items:center;gap:8px;padding:6px 8px;background:var(--surface-raised);border:1px solid var(--border);border-radius:3px}.control-group label,.control-group span{color:var(--muted);font-size:.74rem;letter-spacing:.08em;text-transform:uppercase}.control-group input[type=range]{width:118px}.control-group input[type=range]{accent-color:var(--accent)}.control-button,.panel-toggle{color:var(--text);background:var(--surface);border:1px solid var(--border-strong);border-radius:2px;padding:7px 11px;cursor:pointer;transition:border-color .12s ease,background .12s ease,color .12s ease;text-transform:uppercase;letter-spacing:.08em;font-size:.72rem;line-height:1}.control-button:hover,.panel-toggle:hover{border-color:var(--accent);color:var(--accent-strong)}.control-button[data-active=true],.panel-toggle[data-active=true]{background:#1a2230;border-color:var(--accent);color:var(--accent-strong)}.timeplot-viewport{position:relative;min-height:0;border-radius:4px;overflow:hidden;border:1px solid var(--border-strong);background:#06080b;box-shadow:var(--shadow);padding:10px}.timeplot-plot-grid{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:10px;width:100%;height:100%;min-height:0}.timeplot-plot-panel{position:relative;min-width:0;min-height:0;border:1px solid var(--border);background:#070a0d}.timeplot-canvas-host{width:100%;height:100%}.timeplot-sidebar{display:flex;flex-direction:column;gap:10px;min-height:0;overflow-y:auto;padding-right:2px}.panel{border:1px solid var(--border-strong);background:var(--surface-strong);border-radius:4px;padding:14px}.panel[hidden]{display:none}.panel h2{margin:0 0 12px;font-size:.8rem;letter-spacing:.08em;text-transform:uppercase}.panel-subsection+.panel-subsection{margin-top:14px;padding-top:14px;border-top:1px solid var(--border)}.panel-section-title{margin-bottom:10px;color:var(--accent-strong);font-size:.72rem;letter-spacing:.08em;text-transform:uppercase}.kv-list{display:grid;grid-template-columns:auto 1fr;gap:10px 12px;align-items:center;margin:0}.kv-list dt{color:var(--muted);font-size:.73rem;letter-spacing:.05em;text-transform:uppercase}.kv-list dd{margin:0;text-align:right;font-variant-numeric:tabular-nums;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,monospace}.field-grid{display:grid;gap:12px}.field-grid label{display:grid;gap:6px;color:var(--muted);font-size:.74rem;letter-spacing:.05em;text-transform:uppercase}.field-grid[data-source-mode][hidden]{display:none}.source-meta{min-height:20px;color:var(--muted);font-size:.76rem;line-height:1.4}.source-meta-error{color:#ff9d9d}.source-meta-status{text-transform:uppercase;letter-spacing:.06em}.source-meta-status-connected{color:#99e2b4}.source-meta-status-connecting{color:#ffd27f}.source-meta-status-disconnected,.source-meta-status-idle{color:var(--muted)}.source-meta-status-error{color:#ff9d9d}.field-grid input,.field-grid select{width:100%;padding:9px 10px;border-radius:2px;border:1px solid var(--border);background:var(--surface-raised);color:var(--text)}.field-grid input:focus,.field-grid select:focus{outline:none;border-color:var(--accent)}.panel-row{display:flex;align-items:center;justify-content:space-between;gap:10px;color:var(--muted);font-size:.74rem;letter-spacing:.05em;text-transform:uppercase}.panel-row+.panel-row{margin-top:10px}.panel-row input[type=checkbox]{inline-size:16px;block-size:16px;accent-color:var(--accent)}.muted{color:var(--muted)}.help-list{display:grid;gap:8px;margin:0;padding-left:18px;color:var(--muted);font-size:.82rem}.timeplot-tooltip{position:absolute;min-width:180px;padding:10px 12px;border-radius:3px;border:1px solid var(--border-strong);background:#0d1218;box-shadow:var(--shadow);pointer-events:none;transform:translate(12px,-50%);z-index:10}.timeplot-tooltip[hidden]{display:none}.timeplot-tooltip-title{margin-bottom:8px;font-size:.72rem;color:var(--accent-strong);letter-spacing:.08em;text-transform:uppercase}.timeplot-tooltip-row{display:flex;justify-content:space-between;gap:16px;font-size:.78rem}.timeplot-tooltip-row+.timeplot-tooltip-row{margin-top:4px}.timeplot-empty{color:var(--muted);font-size:.85rem}@media (max-width: 1100px){.timeplot-shell{grid-template-columns:minmax(0,1fr);grid-template-rows:auto minmax(360px,1fr) auto}.timeplot-plot-grid{grid-template-columns:minmax(0,1fr);grid-template-rows:repeat(2,minmax(260px,1fr))}.timeplot-sidebar{overflow:visible}} diff --git a/dist/assets/webworkerAll-J8ccMaq4.js b/dist/assets/webworkerAll-J8ccMaq4.js new file mode 100644 index 0000000..1626284 --- /dev/null +++ b/dist/assets/webworkerAll-J8ccMaq4.js @@ -0,0 +1,296 @@ +import{E as g,U as ot,T as de,a as ut,a2 as w,a3 as U,s as C,ac as he,Z as W,ad as D,O as lt,l as Y,ae as ct,af as fe,_ as Ce,ag as I,ah as dt,ai as P,w as X,M as R,k as z,c as Se,F,a5 as se,R as ie,z as Pe,b as O,B,D as ne,x as K,aj as ht,ak as ae,J as te,al as L,q as oe,t as ft,G as pt,m as Fe,p as Be,a7 as Re,aa as Me,n as gt,o as mt,a8 as xt,a9 as _t,ab as yt,am as bt,an as vt,ao as N,e as T,ap as Tt}from"./index-DB6B0XuI.js";import{S as j,c as $,a as wt,b as Ct,B as Ue}from"./colorToUniform-DmtBy-2V.js";class Ge{static init(e){Object.defineProperty(this,"resizeTo",{set(t){globalThis.removeEventListener("resize",this.queueResize),this._resizeTo=t,t&&(globalThis.addEventListener("resize",this.queueResize),this.resize())},get(){return this._resizeTo}}),this.queueResize=()=>{this._resizeTo&&(this._cancelResize(),this._resizeId=requestAnimationFrame(()=>this.resize()))},this._cancelResize=()=>{this._resizeId&&(cancelAnimationFrame(this._resizeId),this._resizeId=null)},this.resize=()=>{if(!this._resizeTo)return;this._cancelResize();let t,r;if(this._resizeTo===globalThis.window)t=globalThis.innerWidth,r=globalThis.innerHeight;else{const{clientWidth:s,clientHeight:i}=this._resizeTo;t=s,r=i}this.renderer.resize(t,r),this.render()},this._resizeId=null,this._resizeTo=null,this.resizeTo=e.resizeTo||null}static destroy(){globalThis.removeEventListener("resize",this.queueResize),this._cancelResize(),this._cancelResize=null,this.queueResize=null,this.resizeTo=null,this.resize=null}}Ge.extension=g.Application;class Ae{static init(e){e=Object.assign({autoStart:!0,sharedTicker:!1},e),Object.defineProperty(this,"ticker",{set(t){this._ticker&&this._ticker.remove(this.render,this),this._ticker=t,t&&t.add(this.render,this,ot.LOW)},get(){return this._ticker}}),this.stop=()=>{this._ticker.stop()},this.start=()=>{this._ticker.start()},this._ticker=null,this.ticker=e.sharedTicker?de.shared:new de,e.autoStart&&this.start()}static destroy(){if(this._ticker){const e=this._ticker;this.ticker=null,e.destroy()}}}Ae.extension=g.Application;class St extends ut{constructor(){super(...arguments),this.chars=Object.create(null),this.lineHeight=0,this.fontFamily="",this.fontMetrics={fontSize:0,ascent:0,descent:0},this.baseLineOffset=0,this.distanceField={type:"none",range:0},this.pages=[],this.applyFillAsTint=!0,this.baseMeasurementFontSize=100,this.baseRenderedFontSize=100}get font(){return w(U,"BitmapFont.font is deprecated, please use BitmapFont.fontFamily instead."),this.fontFamily}get pageTextures(){return w(U,"BitmapFont.pageTextures is deprecated, please use BitmapFont.pages instead."),this.pages}get size(){return w(U,"BitmapFont.size is deprecated, please use BitmapFont.fontMetrics.fontSize instead."),this.fontMetrics.fontSize}get distanceFieldRange(){return w(U,"BitmapFont.distanceFieldRange is deprecated, please use BitmapFont.distanceField.range instead."),this.distanceField.range}get distanceFieldType(){return w(U,"BitmapFont.distanceFieldType is deprecated, please use BitmapFont.distanceField.type instead."),this.distanceField.type}destroy(e=!1){var t;this.emit("destroy",this),this.removeAllListeners();for(const r in this.chars)(t=this.chars[r].texture)==null||t.destroy();this.chars=null,e&&(this.pages.forEach(r=>r.texture.destroy(!0)),this.pages=null)}}const ze=class ke extends St{constructor(e){super(),this.resolution=1,this.pages=[],this._padding=0,this._measureCache=Object.create(null),this._currentChars=[],this._currentX=0,this._currentY=0,this._currentMaxCharHeight=0,this._currentPageIndex=-1,this._skipKerning=!1;const t={...ke.defaultOptions,...e};this._textureSize=t.textureSize,this._mipmap=t.mipmap;const r=t.style.clone();t.overrideFill&&(r._fill.color=16777215,r._fill.alpha=1,r._fill.texture=C.WHITE,r._fill.fill=null),this.applyFillAsTint=t.overrideFill;const s=r.fontSize;r.fontSize=this.baseMeasurementFontSize;const i=he(r);t.overrideSize?r._stroke&&(r._stroke.width*=this.baseRenderedFontSize/s):r.fontSize=this.baseRenderedFontSize=s,this._style=r,this._skipKerning=t.skipKerning??!1,this.resolution=t.resolution??1,this._padding=t.padding??4,t.textureStyle&&(this._textureStyle=t.textureStyle instanceof W?t.textureStyle:new W(t.textureStyle)),this.fontMetrics=D.measureFont(i),this.lineHeight=r.lineHeight||this.fontMetrics.fontSize||r.fontSize}ensureCharacters(e){var x,p;const t=D.graphemeSegmenter(e).filter(_=>!this._currentChars.includes(_)).filter((_,b,v)=>v.indexOf(_)===b);if(!t.length)return;this._currentChars=[...this._currentChars,...t];let r;this._currentPageIndex===-1?r=this._nextPage():r=this.pages[this._currentPageIndex];let{canvas:s,context:i}=r.canvasAndContext,n=r.texture.source;const a=this._style;let u=this._currentX,l=this._currentY,d=this._currentMaxCharHeight;const c=this.baseRenderedFontSize/this.baseMeasurementFontSize,h=this._padding*c;let f=!1;const y=s.width/this.resolution,m=s.height/this.resolution;for(let _=0;_<t.length;_++){const b=t[_],v=D.measureText(b,a,s,!1);v.lineHeight=v.height;const S=v.width*c,G=Math.ceil((a.fontStyle==="italic"?2:1)*S),k=v.height*c,M=G+h*2,E=k+h*2;if(f=!1,b!==` +`&&b!=="\r"&&b!==" "&&b!==" "&&(f=!0,d=Math.ceil(Math.max(E,d))),u+M>y&&(l+=d,d=E,u=0,l+d>m)){n.update();const A=this._nextPage();s=A.canvasAndContext.canvas,i=A.canvasAndContext.context,n=A.texture.source,u=0,l=0,d=0}const nt=S/c-(((x=a.dropShadow)==null?void 0:x.distance)??0)-(((p=a._stroke)==null?void 0:p.width)??0);if(this.chars[b]={id:b.codePointAt(0),xOffset:-this._padding,yOffset:-this._padding,xAdvance:nt,kerning:{}},f){this._drawGlyph(i,v,u+h,l+h,c,a);const A=n.width*c,ce=n.height*c,at=new lt(u/A*n.width,l/ce*n.height,M/A*n.width,E/ce*n.height);this.chars[b].texture=new C({source:n,frame:at}),u+=Math.ceil(M)}}n.update(),this._currentX=u,this._currentY=l,this._currentMaxCharHeight=d,this._skipKerning&&this._applyKerning(t,i)}get pageTextures(){return w(U,"BitmapFont.pageTextures is deprecated, please use BitmapFont.pages instead."),this.pages}_applyKerning(e,t){const r=this._measureCache;for(let s=0;s<e.length;s++){const i=e[s];for(let n=0;n<this._currentChars.length;n++){const a=this._currentChars[n];let u=r[i];u||(u=r[i]=t.measureText(i).width);let l=r[a];l||(l=r[a]=t.measureText(a).width);let d=t.measureText(i+a).width,c=d-(u+l);c&&(this.chars[i].kerning[a]=c),d=t.measureText(i+a).width,c=d-(u+l),c&&(this.chars[a].kerning[i]=c)}}}_nextPage(){this._currentPageIndex++;const e=this.resolution,t=Y.getOptimalCanvasAndContext(this._textureSize,this._textureSize,e);this._setupContext(t.context,this._style,e);const r=e*(this.baseRenderedFontSize/this.baseMeasurementFontSize),s=new C({source:new ct({resource:t.canvas,resolution:r,alphaMode:"premultiply-alpha-on-upload",autoGenerateMipmaps:this._mipmap})});this._textureStyle&&(s.source.style=this._textureStyle);const i={canvasAndContext:t,texture:s};return this.pages[this._currentPageIndex]=i,i}_setupContext(e,t,r){t.fontSize=this.baseRenderedFontSize,e.scale(r,r),e.font=he(t),t.fontSize=this.baseMeasurementFontSize,e.textBaseline=t.textBaseline;const s=t._stroke,i=(s==null?void 0:s.width)??0;if(s&&(e.lineWidth=i,e.lineJoin=s.join,e.miterLimit=s.miterLimit,e.strokeStyle=fe(s,e)),t._fill&&(e.fillStyle=fe(t._fill,e)),t.dropShadow){const n=t.dropShadow,a=Ce.shared.setValue(n.color).toArray(),u=n.blur*r,l=n.distance*r;e.shadowColor=`rgba(${a[0]*255},${a[1]*255},${a[2]*255},${n.alpha})`,e.shadowBlur=u,e.shadowOffsetX=Math.cos(n.angle)*l,e.shadowOffsetY=Math.sin(n.angle)*l}else e.shadowColor="black",e.shadowBlur=0,e.shadowOffsetX=0,e.shadowOffsetY=0}_drawGlyph(e,t,r,s,i,n){const a=t.text,u=t.fontProperties,l=n._stroke,d=((l==null?void 0:l.width)??0)*i,c=r+d/2,h=s-d/2,f=u.descent*i,y=t.lineHeight*i;let m=!1;n.stroke&&d&&(m=!0,e.strokeText(a,c,h+y-f));const{shadowBlur:x,shadowOffsetX:p,shadowOffsetY:_}=e;n._fill&&(m&&(e.shadowBlur=0,e.shadowOffsetX=0,e.shadowOffsetY=0),e.fillText(a,c,h+y-f)),m&&(e.shadowBlur=x,e.shadowOffsetX=p,e.shadowOffsetY=_)}destroy(){super.destroy();for(let e=0;e<this.pages.length;e++){const{canvasAndContext:t,texture:r}=this.pages[e];Y.returnCanvasAndContext(t),r.destroy(!0)}this.pages=null}};ze.defaultOptions={textureSize:512,style:new I,mipmap:!0};let pe=ze;function De(o,e,t,r){const s={width:0,height:0,offsetY:0,scale:e.fontSize/t.baseMeasurementFontSize,lines:[{width:0,charPositions:[],spaceWidth:0,spacesIndex:[],chars:[]}]};s.offsetY=t.baseLineOffset;let i=s.lines[0],n=null,a=!0;const u={width:0,start:0,index:0,positions:[],chars:[]},l=t.baseMeasurementFontSize/e.fontSize,d=e.letterSpacing*l,c=e.wordWrapWidth*l,h=e.lineHeight?e.lineHeight*l:t.lineHeight,f=e.wordWrap&&e.breakWords,y=p=>{const _=i.width;for(let b=0;b<u.index;b++){const v=p.positions[b];i.chars.push(p.chars[b]),i.charPositions.push(v+_)}i.width+=p.width,a=!1,u.width=0,u.index=0,u.chars.length=0},m=()=>{let p=i.chars.length-1;if(r){let _=i.chars[p];for(;_===" ";)i.width-=t.chars[_].xAdvance,_=i.chars[--p]}s.width=Math.max(s.width,i.width),i={width:0,charPositions:[],chars:[],spaceWidth:0,spacesIndex:[]},a=!0,s.lines.push(i),s.height+=h},x=p=>p-d>c;for(let p=0;p<o.length+1;p++){let _;const b=p===o.length;b||(_=o[p]);const v=t.chars[_]||t.chars[" "];if(/(?:\s)/.test(_)||_==="\r"||_===` +`||b){if(!a&&e.wordWrap&&x(i.width+u.width)?(m(),y(u),b||i.charPositions.push(0)):(u.start=i.width,y(u),b||i.charPositions.push(0)),_==="\r"||_===` +`)m();else if(!b){const M=v.xAdvance+(v.kerning[n]||0)+d;i.width+=M,i.spaceWidth=M,i.spacesIndex.push(i.charPositions.length),i.chars.push(_)}}else{const k=v.kerning[n]||0,M=v.xAdvance+k+d;f&&x(i.width+u.width+M)&&(y(u),m()),u.positions[u.index++]=u.width+k,u.chars.push(_),u.width+=M}n=_}return m(),e.align==="center"?Pt(s):e.align==="right"?Ft(s):e.align==="justify"&&Bt(s),s}function Pt(o){for(let e=0;e<o.lines.length;e++){const t=o.lines[e],r=o.width/2-t.width/2;for(let s=0;s<t.charPositions.length;s++)t.charPositions[s]+=r}}function Ft(o){for(let e=0;e<o.lines.length;e++){const t=o.lines[e],r=o.width-t.width;for(let s=0;s<t.charPositions.length;s++)t.charPositions[s]+=r}}function Bt(o){const e=o.width;for(let t=0;t<o.lines.length;t++){const r=o.lines[t];let s=0,i=r.spacesIndex[s++],n=0;const a=r.spacesIndex.length,l=(e-r.width)/a;for(let d=0;d<r.charPositions.length;d++)d===i&&(i=r.spacesIndex[s++],n+=l),r.charPositions[d]+=n}}function Rt(o){if(o==="")return[];typeof o=="string"&&(o=[o]);const e=[];for(let t=0,r=o.length;t<r;t++){const s=o[t];if(Array.isArray(s)){if(s.length!==2)throw new Error(`[BitmapFont]: Invalid character range length, expecting 2 got ${s.length}.`);if(s[0].length===0||s[1].length===0)throw new Error("[BitmapFont]: Invalid character delimiter.");const i=s[0].charCodeAt(0),n=s[1].charCodeAt(0);if(n<i)throw new Error("[BitmapFont]: Invalid character range.");for(let a=i,u=n;a<=u;a++)e.push(String.fromCharCode(a))}else e.push(...Array.from(s))}if(e.length===0)throw new Error("[BitmapFont]: Empty set when resolving characters.");return e}let H=0;class Mt{constructor(){this.ALPHA=[["a","z"],["A","Z"]," "],this.NUMERIC=[["0","9"]],this.ALPHANUMERIC=[["a","z"],["A","Z"],["0","9"]," "],this.ASCII=[[" ","~"]],this.defaultOptions={chars:this.ALPHANUMERIC,resolution:1,padding:4,skipKerning:!1,textureStyle:null},this.measureCache=dt(1e3)}getFont(e,t){var n;let r=`${t.fontFamily}-bitmap`,s=!0;if(t._fill.fill&&!t._stroke?(r+=t._fill.fill.styleKey,s=!1):(t._stroke||t.dropShadow)&&(r=`${t.styleKey}-bitmap`,s=!1),!P.has(r)){const a=Object.create(t);a.lineHeight=0;const u=new pe({style:a,overrideFill:s,overrideSize:!0,...this.defaultOptions});H++,H>50&&X("BitmapText",`You have dynamically created ${H} bitmap fonts, this can be inefficient. Try pre installing your font styles using \`BitmapFont.install({name:"style1", style})\``),u.once("destroy",()=>{H--,P.remove(r)}),P.set(r,u)}const i=P.get(r);return(n=i.ensureCharacters)==null||n.call(i,e),i}getLayout(e,t,r=!0){const s=this.getFont(e,t),i=`${e}-${t.styleKey}-${r}`;if(this.measureCache.has(i))return this.measureCache.get(i);const n=D.graphemeSegmenter(e),a=De(n,t,s,r);return this.measureCache.set(i,a),a}measureText(e,t,r=!0){return this.getLayout(e,t,r)}install(...e){var l,d,c,h;let t=e[0];typeof t=="string"&&(t={name:t,style:e[1],chars:(l=e[2])==null?void 0:l.chars,resolution:(d=e[2])==null?void 0:d.resolution,padding:(c=e[2])==null?void 0:c.padding,skipKerning:(h=e[2])==null?void 0:h.skipKerning},w(U,"BitmapFontManager.install(name, style, options) is deprecated, use BitmapFontManager.install({name, style, ...options})"));const r=t==null?void 0:t.name;if(!r)throw new Error("[BitmapFontManager] Property `name` is required.");t={...this.defaultOptions,...t};const s=t.style,i=s instanceof I?s:new I(s),n=t.dynamicFill??this._canUseTintForStyle(i),a=new pe({style:i,overrideFill:n,skipKerning:t.skipKerning,padding:t.padding,resolution:t.resolution,overrideSize:!1,textureStyle:t.textureStyle}),u=Rt(t.chars);return a.ensureCharacters(u.join("")),P.set(`${r}-bitmap`,a),a.once("destroy",()=>P.remove(`${r}-bitmap`)),a}uninstall(e){const t=`${e}-bitmap`,r=P.get(t);r&&r.destroy()}_canUseTintForStyle(e){return!e._stroke&&(!e.dropShadow||e.dropShadow.color===0)&&!e._fill.fill&&e._fill.color===16777215}}const Ut=new Mt;class Oe{constructor(e){this._renderer=e}push(e,t,r){this._renderer.renderPipes.batch.break(r),r.add({renderPipeId:"filter",canBundle:!1,action:"pushFilter",container:t,filterEffect:e})}pop(e,t,r){this._renderer.renderPipes.batch.break(r),r.add({renderPipeId:"filter",action:"popFilter",canBundle:!1})}execute(e){e.action==="pushFilter"?this._renderer.filter.push(e):e.action==="popFilter"&&this._renderer.filter.pop()}destroy(){this._renderer=null}}Oe.extension={type:[g.WebGLPipes,g.WebGPUPipes,g.CanvasPipes],name:"filter"};const ge=new R;function Gt(o,e){e.clear();const t=e.matrix;for(let r=0;r<o.length;r++){const s=o[r];if(s.globalDisplayStatus<7)continue;const i=s.renderGroup??s.parentRenderGroup;i!=null&&i.isCachedAsTexture?e.matrix=ge.copyFrom(i.textureOffsetInverseTransform).append(s.worldTransform):i!=null&&i._parentCacheAsTextureRenderGroup?e.matrix=ge.copyFrom(i._parentCacheAsTextureRenderGroup.inverseWorldTransform).append(s.groupTransform):e.matrix=s.worldTransform,e.addBounds(s.bounds)}return e.matrix=t,e}const At=new se({attributes:{aPosition:{buffer:new Float32Array([0,0,1,0,1,1,0,1]),format:"float32x2",stride:2*4,offset:0}},indexBuffer:new Uint32Array([0,1,2,0,2,3])});class zt{constructor(){this.skip=!1,this.inputTexture=null,this.backTexture=null,this.filters=null,this.bounds=new Pe,this.container=null,this.blendRequired=!1,this.outputRenderSurface=null,this.globalFrame={x:0,y:0,width:0,height:0}}}class We{constructor(e){this._filterStackIndex=0,this._filterStack=[],this._filterGlobalUniforms=new z({uInputSize:{value:new Float32Array(4),type:"vec4<f32>"},uInputPixel:{value:new Float32Array(4),type:"vec4<f32>"},uInputClamp:{value:new Float32Array(4),type:"vec4<f32>"},uOutputFrame:{value:new Float32Array(4),type:"vec4<f32>"},uGlobalFrame:{value:new Float32Array(4),type:"vec4<f32>"},uOutputTexture:{value:new Float32Array(4),type:"vec4<f32>"}}),this._globalFilterBindGroup=new Se({}),this.renderer=e}get activeBackTexture(){var e;return(e=this._activeFilterData)==null?void 0:e.backTexture}push(e){const t=this.renderer,r=e.filterEffect.filters,s=this._pushFilterData();s.skip=!1,s.filters=r,s.container=e.container,s.outputRenderSurface=t.renderTarget.renderSurface;const i=t.renderTarget.renderTarget.colorTexture.source,n=i.resolution,a=i.antialias;if(r.length===0){s.skip=!0;return}const u=s.bounds;if(this._calculateFilterArea(e,u),this._calculateFilterBounds(s,t.renderTarget.rootViewPort,a,n,1),s.skip)return;const l=this._getPreviousFilterData(),d=this._findFilterResolution(n);let c=0,h=0;l&&(c=l.bounds.minX,h=l.bounds.minY),this._calculateGlobalFrame(s,c,h,d,i.width,i.height),this._setupFilterTextures(s,u,t,l)}generateFilteredTexture({texture:e,filters:t}){const r=this._pushFilterData();this._activeFilterData=r,r.skip=!1,r.filters=t;const s=e.source,i=s.resolution,n=s.antialias;if(t.length===0)return r.skip=!0,e;const a=r.bounds;if(a.addRect(e.frame),this._calculateFilterBounds(r,a.rectangle,n,i,0),r.skip)return e;const u=i;this._calculateGlobalFrame(r,0,0,u,s.width,s.height),r.outputRenderSurface=F.getOptimalTexture(a.width,a.height,r.resolution,r.antialias),r.backTexture=C.EMPTY,r.inputTexture=e,this.renderer.renderTarget.finishRenderPass(),this._applyFiltersToTexture(r,!0);const h=r.outputRenderSurface;return h.source.alphaMode="premultiplied-alpha",h}pop(){const e=this.renderer,t=this._popFilterData();t.skip||(e.globalUniforms.pop(),e.renderTarget.finishRenderPass(),this._activeFilterData=t,this._applyFiltersToTexture(t,!1),t.blendRequired&&F.returnTexture(t.backTexture),F.returnTexture(t.inputTexture))}getBackTexture(e,t,r){const s=e.colorTexture.source._resolution,i=F.getOptimalTexture(t.width,t.height,s,!1);let n=t.minX,a=t.minY;r&&(n-=r.minX,a-=r.minY),n=Math.floor(n*s),a=Math.floor(a*s);const u=Math.ceil(t.width*s),l=Math.ceil(t.height*s);return this.renderer.renderTarget.copyToTexture(e,i,{x:n,y:a},{width:u,height:l},{x:0,y:0}),i}applyFilter(e,t,r,s){const i=this.renderer,n=this._activeFilterData,u=n.outputRenderSurface===r,l=i.renderTarget.rootRenderTarget.colorTexture.source._resolution,d=this._findFilterResolution(l);let c=0,h=0;if(u){const f=this._findPreviousFilterOffset();c=f.x,h=f.y}this._updateFilterUniforms(t,r,n,c,h,d,u,s),this._setupBindGroupsAndRender(e,t,i)}calculateSpriteMatrix(e,t){const r=this._activeFilterData,s=e.set(r.inputTexture._source.width,0,0,r.inputTexture._source.height,r.bounds.minX,r.bounds.minY),i=t.worldTransform.copyTo(R.shared),n=t.renderGroup||t.parentRenderGroup;return n&&n.cacheToLocalTransform&&i.prepend(n.cacheToLocalTransform),i.invert(),s.prepend(i),s.scale(1/t.texture.orig.width,1/t.texture.orig.height),s.translate(t.anchor.x,t.anchor.y),s}destroy(){}_setupBindGroupsAndRender(e,t,r){if(r.renderPipes.uniformBatch){const s=r.renderPipes.uniformBatch.getUboResource(this._filterGlobalUniforms);this._globalFilterBindGroup.setResource(s,0)}else this._globalFilterBindGroup.setResource(this._filterGlobalUniforms,0);this._globalFilterBindGroup.setResource(t.source,1),this._globalFilterBindGroup.setResource(t.source.style,2),e.groups[0]=this._globalFilterBindGroup,r.encoder.draw({geometry:At,shader:e,state:e._state,topology:"triangle-list"}),r.type===ie.WEBGL&&r.renderTarget.finishRenderPass()}_setupFilterTextures(e,t,r,s){if(e.backTexture=C.EMPTY,e.inputTexture=F.getOptimalTexture(t.width,t.height,e.resolution,e.antialias),e.blendRequired){r.renderTarget.finishRenderPass();const i=r.renderTarget.getRenderTarget(e.outputRenderSurface);e.backTexture=this.getBackTexture(i,t,s==null?void 0:s.bounds)}r.renderTarget.bind(e.inputTexture,!0),r.globalUniforms.push({offset:t})}_calculateGlobalFrame(e,t,r,s,i,n){const a=e.globalFrame;a.x=t*s,a.y=r*s,a.width=i*s,a.height=n*s}_updateFilterUniforms(e,t,r,s,i,n,a,u){const l=this._filterGlobalUniforms.uniforms,d=l.uOutputFrame,c=l.uInputSize,h=l.uInputPixel,f=l.uInputClamp,y=l.uGlobalFrame,m=l.uOutputTexture;a?(d[0]=r.bounds.minX-s,d[1]=r.bounds.minY-i):(d[0]=0,d[1]=0),d[2]=e.frame.width,d[3]=e.frame.height,c[0]=e.source.width,c[1]=e.source.height,c[2]=1/c[0],c[3]=1/c[1],h[0]=e.source.pixelWidth,h[1]=e.source.pixelHeight,h[2]=1/h[0],h[3]=1/h[1],f[0]=.5*h[2],f[1]=.5*h[3],f[2]=e.frame.width*c[2]-.5*h[2],f[3]=e.frame.height*c[3]-.5*h[3];const x=this.renderer.renderTarget.rootRenderTarget.colorTexture;y[0]=s*n,y[1]=i*n,y[2]=x.source.width*n,y[3]=x.source.height*n,t instanceof C&&(t.source.resource=null);const p=this.renderer.renderTarget.getRenderTarget(t);this.renderer.renderTarget.bind(t,!!u),t instanceof C?(m[0]=t.frame.width,m[1]=t.frame.height):(m[0]=p.width,m[1]=p.height),m[2]=p.isRoot?-1:1,this._filterGlobalUniforms.update()}_findFilterResolution(e){let t=this._filterStackIndex-1;for(;t>0&&this._filterStack[t].skip;)--t;return t>0&&this._filterStack[t].inputTexture?this._filterStack[t].inputTexture.source._resolution:e}_findPreviousFilterOffset(){let e=0,t=0,r=this._filterStackIndex;for(;r>0;){r--;const s=this._filterStack[r];if(!s.skip){e=s.bounds.minX,t=s.bounds.minY;break}}return{x:e,y:t}}_calculateFilterArea(e,t){if(e.renderables?Gt(e.renderables,t):e.filterEffect.filterArea?(t.clear(),t.addRect(e.filterEffect.filterArea),t.applyMatrix(e.container.worldTransform)):e.container.getFastGlobalBounds(!0,t),e.container){const s=(e.container.renderGroup||e.container.parentRenderGroup).cacheToLocalTransform;s&&t.applyMatrix(s)}}_applyFiltersToTexture(e,t){const r=e.inputTexture,s=e.bounds,i=e.filters;if(this._globalFilterBindGroup.setResource(r.source.style,2),this._globalFilterBindGroup.setResource(e.backTexture.source,3),i.length===1)i[0].apply(this,r,e.outputRenderSurface,t);else{let n=e.inputTexture;const a=F.getOptimalTexture(s.width,s.height,n.source._resolution,!1);let u=a,l=0;for(l=0;l<i.length-1;++l){i[l].apply(this,n,u,!0);const c=n;n=u,u=c}i[l].apply(this,n,e.outputRenderSurface,t),F.returnTexture(a)}}_calculateFilterBounds(e,t,r,s,i){var m;const n=this.renderer,a=e.bounds,u=e.filters;let l=1/0,d=0,c=!0,h=!1,f=!1,y=!0;for(let x=0;x<u.length;x++){const p=u[x];if(l=Math.min(l,p.resolution==="inherit"?s:p.resolution),d+=p.padding,p.antialias==="off"?c=!1:p.antialias==="inherit"&&c&&(c=r),p.clipToViewport||(y=!1),!!!(p.compatibleRenderers&n.type)){f=!1;break}if(p.blendRequired&&!(((m=n.backBuffer)==null?void 0:m.useBackBuffer)??!0)){X("Blend filter requires backBuffer on WebGL renderer to be enabled. Set `useBackBuffer: true` in the renderer options."),f=!1;break}f=p.enabled||f,h||(h=p.blendRequired)}if(!f){e.skip=!0;return}if(y&&a.fitBounds(0,t.width/s,0,t.height/s),a.scale(l).ceil().scale(1/l).pad((d|0)*i),!a.isPositive){e.skip=!0;return}e.antialias=c,e.resolution=l,e.blendRequired=h}_popFilterData(){return this._filterStackIndex--,this._filterStack[this._filterStackIndex]}_getPreviousFilterData(){let e,t=this._filterStackIndex-1;for(;t>0&&(t--,e=this._filterStack[t],!!e.skip););return e}_pushFilterData(){let e=this._filterStack[this._filterStackIndex];return e||(e=this._filterStack[this._filterStackIndex]=new zt),this._filterStackIndex++,e}}We.extension={type:[g.WebGLSystem,g.WebGPUSystem],name:"filter"};const Ie=class Ee extends se{constructor(...e){let t=e[0]??{};t instanceof Float32Array&&(w(U,"use new MeshGeometry({ positions, uvs, indices }) instead"),t={positions:t,uvs:e[1],indices:e[2]}),t={...Ee.defaultOptions,...t};const r=t.positions||new Float32Array([0,0,1,0,1,1,0,1]);let s=t.uvs;s||(t.positions?s=new Float32Array(r.length):s=new Float32Array([0,0,1,0,1,1,0,1]));const i=t.indices||new Uint32Array([0,1,2,0,2,3]),n=t.shrinkBuffersToFit,a=new O({data:r,label:"attribute-mesh-positions",shrinkToFit:n,usage:B.VERTEX|B.COPY_DST}),u=new O({data:s,label:"attribute-mesh-uvs",shrinkToFit:n,usage:B.VERTEX|B.COPY_DST}),l=new O({data:i,label:"index-mesh-buffer",shrinkToFit:n,usage:B.INDEX|B.COPY_DST});super({attributes:{aPosition:{buffer:a,format:"float32x2",stride:2*4,offset:0},aUV:{buffer:u,format:"float32x2",stride:2*4,offset:0}},indexBuffer:l,topology:t.topology}),this.batchMode="auto"}get positions(){return this.attributes.aPosition.buffer.data}set positions(e){this.attributes.aPosition.buffer.data=e}get uvs(){return this.attributes.aUV.buffer.data}set uvs(e){this.attributes.aUV.buffer.data=e}get indices(){return this.indexBuffer.data}set indices(e){this.indexBuffer.data=e}};Ie.defaultOptions={topology:"triangle-list",shrinkBuffersToFit:!1};let ue=Ie;const me="http://www.w3.org/2000/svg",xe="http://www.w3.org/1999/xhtml";class Le{constructor(){this.svgRoot=document.createElementNS(me,"svg"),this.foreignObject=document.createElementNS(me,"foreignObject"),this.domElement=document.createElementNS(xe,"div"),this.styleElement=document.createElementNS(xe,"style");const{foreignObject:e,svgRoot:t,styleElement:r,domElement:s}=this;e.setAttribute("width","10000"),e.setAttribute("height","10000"),e.style.overflow="hidden",t.appendChild(e),e.appendChild(r),e.appendChild(s),this.image=ne.get().createImage()}destroy(){this.svgRoot.remove(),this.foreignObject.remove(),this.styleElement.remove(),this.domElement.remove(),this.image.src="",this.image.remove(),this.svgRoot=null,this.foreignObject=null,this.styleElement=null,this.domElement=null,this.image=null,this.canvasAndContext=null}}let _e;function kt(o,e,t,r){r||(r=_e||(_e=new Le));const{domElement:s,styleElement:i,svgRoot:n}=r;s.innerHTML=`<style>${e.cssStyle};</style><div style='padding:0'>${o}</div>`,s.setAttribute("style","transform-origin: top left; display: inline-block"),t&&(i.textContent=t),document.body.appendChild(n);const a=s.getBoundingClientRect();n.remove();const u=e.padding*2;return{width:a.width-u,height:a.height-u}}class Dt{constructor(){this.batches=[],this.batched=!1}destroy(){this.batches.forEach(e=>{K.return(e)}),this.batches.length=0}}class He{constructor(e,t){this.state=j.for2d(),this.renderer=e,this._adaptor=t,this.renderer.runners.contextChange.add(this)}contextChange(){this._adaptor.contextChange(this.renderer)}validateRenderable(e){const t=e.context,r=!!e._gpuData,s=this.renderer.graphicsContext.updateGpuContext(t);return!!(s.isBatchable||r!==s.isBatchable)}addRenderable(e,t){const r=this.renderer.graphicsContext.updateGpuContext(e.context);e.didViewUpdate&&this._rebuild(e),r.isBatchable?this._addToBatcher(e,t):(this.renderer.renderPipes.batch.break(t),t.add(e))}updateRenderable(e){const r=this._getGpuDataForRenderable(e).batches;for(let s=0;s<r.length;s++){const i=r[s];i._batcher.updateElement(i)}}execute(e){if(!e.isRenderable)return;const t=this.renderer,r=e.context;if(!t.graphicsContext.getGpuContext(r).batches.length)return;const i=r.customShader||this._adaptor.shader;this.state.blendMode=e.groupBlendMode;const n=i.resources.localUniforms.uniforms;n.uTransformMatrix=e.groupTransform,n.uRound=t._roundPixels|e._roundPixels,$(e.groupColorAlpha,n.uColor,0),this._adaptor.execute(this,e)}_rebuild(e){const t=this._getGpuDataForRenderable(e),r=this.renderer.graphicsContext.updateGpuContext(e.context);t.destroy(),r.isBatchable&&this._updateBatchesForRenderable(e,t)}_addToBatcher(e,t){const r=this.renderer.renderPipes.batch,s=this._getGpuDataForRenderable(e).batches;for(let i=0;i<s.length;i++){const n=s[i];r.addToBatch(n,t)}}_getGpuDataForRenderable(e){return e._gpuData[this.renderer.uid]||this._initGpuDataForRenderable(e)}_initGpuDataForRenderable(e){const t=new Dt;return e._gpuData[this.renderer.uid]=t,t}_updateBatchesForRenderable(e,t){const r=e.context,s=this.renderer.graphicsContext.getGpuContext(r),i=this.renderer._roundPixels|e._roundPixels;t.batches=s.batches.map(n=>{const a=K.get(ht);return n.copyTo(a),a.renderable=e,a.roundPixels=i,a})}destroy(){this.renderer=null,this._adaptor.destroy(),this._adaptor=null,this.state=null}}He.extension={type:[g.WebGLPipes,g.WebGPUPipes,g.CanvasPipes],name:"graphics"};const Ve=class Ye extends ue{constructor(...e){super({});let t=e[0]??{};typeof t=="number"&&(w(U,"PlaneGeometry constructor changed please use { width, height, verticesX, verticesY } instead"),t={width:t,height:e[1],verticesX:e[2],verticesY:e[3]}),this.build(t)}build(e){e={...Ye.defaultOptions,...e},this.verticesX=this.verticesX??e.verticesX,this.verticesY=this.verticesY??e.verticesY,this.width=this.width??e.width,this.height=this.height??e.height;const t=this.verticesX*this.verticesY,r=[],s=[],i=[],n=this.verticesX-1,a=this.verticesY-1,u=this.width/n,l=this.height/a;for(let c=0;c<t;c++){const h=c%this.verticesX,f=c/this.verticesX|0;r.push(h*u,f*l),s.push(h/n,f/a)}const d=n*a;for(let c=0;c<d;c++){const h=c%n,f=c/n|0,y=f*this.verticesX+h,m=f*this.verticesX+h+1,x=(f+1)*this.verticesX+h,p=(f+1)*this.verticesX+h+1;i.push(y,m,x,m,p,x)}this.buffers[0].data=new Float32Array(r),this.buffers[1].data=new Float32Array(s),this.indexBuffer.data=new Uint32Array(i),this.buffers[0].update(),this.buffers[1].update(),this.indexBuffer.update()}};Ve.defaultOptions={width:100,height:100,verticesX:10,verticesY:10};let Ot=Ve;class le{constructor(){this.batcherName="default",this.packAsQuad=!1,this.indexOffset=0,this.attributeOffset=0,this.roundPixels=0,this._batcher=null,this._batch=null,this._textureMatrixUpdateId=-1,this._uvUpdateId=-1}get blendMode(){return this.renderable.groupBlendMode}get topology(){return this._topology||this.geometry.topology}set topology(e){this._topology=e}reset(){this.renderable=null,this.texture=null,this._batcher=null,this._batch=null,this.geometry=null,this._uvUpdateId=-1,this._textureMatrixUpdateId=-1}setTexture(e){this.texture!==e&&(this.texture=e,this._textureMatrixUpdateId=-1)}get uvs(){const t=this.geometry.getBuffer("aUV"),r=t.data;let s=r;const i=this.texture.textureMatrix;return i.isSimple||(s=this._transformedUvs,(this._textureMatrixUpdateId!==i._updateID||this._uvUpdateId!==t._updateID)&&((!s||s.length<r.length)&&(s=this._transformedUvs=new Float32Array(r.length)),this._textureMatrixUpdateId=i._updateID,this._uvUpdateId=t._updateID,i.multiplyUvs(r,s))),s}get positions(){return this.geometry.positions}get indices(){return this.geometry.indices}get color(){return this.renderable.groupColorAlpha}get groupTransform(){return this.renderable.groupTransform}get attributeSize(){return this.geometry.positions.length/2}get indexSize(){return this.geometry.indices.length}}class ye{destroy(){}}class Xe{constructor(e,t){this.localUniforms=new z({uTransformMatrix:{value:new R,type:"mat3x3<f32>"},uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uRound:{value:0,type:"f32"}}),this.localUniformsBindGroup=new Se({0:this.localUniforms}),this.renderer=e,this._adaptor=t,this._adaptor.init()}validateRenderable(e){const t=this._getMeshData(e),r=t.batched,s=e.batched;if(t.batched=s,r!==s)return!0;if(s){const i=e._geometry;if(i.indices.length!==t.indexSize||i.positions.length!==t.vertexSize)return t.indexSize=i.indices.length,t.vertexSize=i.positions.length,!0;const n=this._getBatchableMesh(e);return n.texture.uid!==e._texture.uid&&(n._textureMatrixUpdateId=-1),!n._batcher.checkAndUpdateTexture(n,e._texture)}return!1}addRenderable(e,t){var i,n;const r=this.renderer.renderPipes.batch,s=this._getMeshData(e);if(e.didViewUpdate&&(s.indexSize=(i=e._geometry.indices)==null?void 0:i.length,s.vertexSize=(n=e._geometry.positions)==null?void 0:n.length),s.batched){const a=this._getBatchableMesh(e);a.setTexture(e._texture),a.geometry=e._geometry,r.addToBatch(a,t)}else r.break(t),t.add(e)}updateRenderable(e){if(e.batched){const t=this._getBatchableMesh(e);t.setTexture(e._texture),t.geometry=e._geometry,t._batcher.updateElement(t)}}execute(e){if(!e.isRenderable)return;e.state.blendMode=ae(e.groupBlendMode,e.texture._source);const t=this.localUniforms;t.uniforms.uTransformMatrix=e.groupTransform,t.uniforms.uRound=this.renderer._roundPixels|e._roundPixels,t.update(),$(e.groupColorAlpha,t.uniforms.uColor,0),this._adaptor.execute(this,e)}_getMeshData(e){var t,r;return(t=e._gpuData)[r=this.renderer.uid]||(t[r]=new ye),e._gpuData[this.renderer.uid].meshData||this._initMeshData(e)}_initMeshData(e){return e._gpuData[this.renderer.uid].meshData={batched:e.batched,indexSize:0,vertexSize:0},e._gpuData[this.renderer.uid].meshData}_getBatchableMesh(e){var t,r;return(t=e._gpuData)[r=this.renderer.uid]||(t[r]=new ye),e._gpuData[this.renderer.uid].batchableMesh||this._initBatchableMesh(e)}_initBatchableMesh(e){const t=new le;return t.renderable=e,t.setTexture(e._texture),t.transform=e.groupTransform,t.roundPixels=this.renderer._roundPixels|e._roundPixels,e._gpuData[this.renderer.uid].batchableMesh=t,t}destroy(){this.localUniforms=null,this.localUniformsBindGroup=null,this._adaptor.destroy(),this._adaptor=null,this.renderer=null}}Xe.extension={type:[g.WebGLPipes,g.WebGPUPipes,g.CanvasPipes],name:"mesh"};class Wt{execute(e,t){const r=e.state,s=e.renderer,i=t.shader||e.defaultShader;i.resources.uTexture=t.texture._source,i.resources.uniforms=e.localUniforms;const n=s.gl,a=e.getBuffers(t);s.shader.bind(i),s.state.set(r),s.geometry.bind(a.geometry,i.glProgram);const l=a.geometry.indexBuffer.data.BYTES_PER_ELEMENT===2?n.UNSIGNED_SHORT:n.UNSIGNED_INT;n.drawElements(n.TRIANGLES,t.particleChildren.length*6,l,0)}}class It{execute(e,t){const r=e.renderer,s=t.shader||e.defaultShader;s.groups[0]=r.renderPipes.uniformBatch.getUniformBindGroup(e.localUniforms,!0),s.groups[1]=r.texture.getTextureBindGroup(t.texture);const i=e.state,n=e.getBuffers(t);r.encoder.draw({geometry:n.geometry,shader:t.shader||e.defaultShader,state:i,size:t.particleChildren.length*6})}}function be(o,e=null){const t=o*6;if(t>65535?e||(e=new Uint32Array(t)):e||(e=new Uint16Array(t)),e.length!==t)throw new Error(`Out buffer length is incorrect, got ${e.length} and expected ${t}`);for(let r=0,s=0;r<t;r+=6,s+=4)e[r+0]=s+0,e[r+1]=s+1,e[r+2]=s+2,e[r+3]=s+0,e[r+4]=s+2,e[r+5]=s+3;return e}function Et(o){return{dynamicUpdate:ve(o,!0),staticUpdate:ve(o,!1)}}function ve(o,e){const t=[];t.push(` + + var index = 0; + + for (let i = 0; i < ps.length; ++i) + { + const p = ps[i]; + + `);let r=0;for(const i in o){const n=o[i];if(e!==n.dynamic)continue;t.push(`offset = index + ${r}`),t.push(n.code);const a=te(n.format);r+=a.stride/4}t.push(` + index += stride * 4; + } + `),t.unshift(` + var stride = ${r}; + `);const s=t.join(` +`);return new Function("ps","f32v","u32v",s)}class Lt{constructor(e){this._size=0,this._generateParticleUpdateCache={};const t=this._size=e.size??1e3,r=e.properties;let s=0,i=0;for(const d in r){const c=r[d],h=te(c.format);c.dynamic?i+=h.stride:s+=h.stride}this._dynamicStride=i/4,this._staticStride=s/4,this.staticAttributeBuffer=new L(t*4*s),this.dynamicAttributeBuffer=new L(t*4*i),this.indexBuffer=be(t);const n=new se;let a=0,u=0;this._staticBuffer=new O({data:new Float32Array(1),label:"static-particle-buffer",shrinkToFit:!1,usage:B.VERTEX|B.COPY_DST}),this._dynamicBuffer=new O({data:new Float32Array(1),label:"dynamic-particle-buffer",shrinkToFit:!1,usage:B.VERTEX|B.COPY_DST});for(const d in r){const c=r[d],h=te(c.format);c.dynamic?(n.addAttribute(c.attributeName,{buffer:this._dynamicBuffer,stride:this._dynamicStride*4,offset:a*4,format:c.format}),a+=h.size):(n.addAttribute(c.attributeName,{buffer:this._staticBuffer,stride:this._staticStride*4,offset:u*4,format:c.format}),u+=h.size)}n.addIndex(this.indexBuffer);const l=this.getParticleUpdate(r);this._dynamicUpload=l.dynamicUpdate,this._staticUpload=l.staticUpdate,this.geometry=n}getParticleUpdate(e){const t=Ht(e);return this._generateParticleUpdateCache[t]?this._generateParticleUpdateCache[t]:(this._generateParticleUpdateCache[t]=this.generateParticleUpdate(e),this._generateParticleUpdateCache[t])}generateParticleUpdate(e){return Et(e)}update(e,t){e.length>this._size&&(t=!0,this._size=Math.max(e.length,this._size*1.5|0),this.staticAttributeBuffer=new L(this._size*this._staticStride*4*4),this.dynamicAttributeBuffer=new L(this._size*this._dynamicStride*4*4),this.indexBuffer=be(this._size),this.geometry.indexBuffer.setDataWithSize(this.indexBuffer,this.indexBuffer.byteLength,!0));const r=this.dynamicAttributeBuffer;if(this._dynamicUpload(e,r.float32View,r.uint32View),this._dynamicBuffer.setDataWithSize(this.dynamicAttributeBuffer.float32View,e.length*this._dynamicStride*4,!0),t){const s=this.staticAttributeBuffer;this._staticUpload(e,s.float32View,s.uint32View),this._staticBuffer.setDataWithSize(s.float32View,e.length*this._staticStride*4,!0)}}destroy(){this._staticBuffer.destroy(),this._dynamicBuffer.destroy(),this.geometry.destroy()}}function Ht(o){const e=[];for(const t in o){const r=o[t];e.push(t,r.code,r.dynamic?"d":"s")}return e.join("_")}var Vt=`varying vec2 vUV; +varying vec4 vColor; + +uniform sampler2D uTexture; + +void main(void){ + vec4 color = texture2D(uTexture, vUV) * vColor; + gl_FragColor = color; +}`,Yt=`attribute vec2 aVertex; +attribute vec2 aUV; +attribute vec4 aColor; + +attribute vec2 aPosition; +attribute float aRotation; + +uniform mat3 uTranslationMatrix; +uniform float uRound; +uniform vec2 uResolution; +uniform vec4 uColor; + +varying vec2 vUV; +varying vec4 vColor; + +vec2 roundPixels(vec2 position, vec2 targetSize) +{ + return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0; +} + +void main(void){ + float cosRotation = cos(aRotation); + float sinRotation = sin(aRotation); + float x = aVertex.x * cosRotation - aVertex.y * sinRotation; + float y = aVertex.x * sinRotation + aVertex.y * cosRotation; + + vec2 v = vec2(x, y); + v = v + aPosition; + + gl_Position = vec4((uTranslationMatrix * vec3(v, 1.0)).xy, 0.0, 1.0); + + if(uRound == 1.0) + { + gl_Position.xy = roundPixels(gl_Position.xy, uResolution); + } + + vUV = aUV; + vColor = vec4(aColor.rgb * aColor.a, aColor.a) * uColor; +} +`,Te=` +struct ParticleUniforms { + uTranslationMatrix:mat3x3<f32>, + uColor:vec4<f32>, + uRound:f32, + uResolution:vec2<f32>, +}; + +fn roundPixels(position: vec2<f32>, targetSize: vec2<f32>) -> vec2<f32> +{ + return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0; +} + +@group(0) @binding(0) var<uniform> uniforms: ParticleUniforms; + +@group(1) @binding(0) var uTexture: texture_2d<f32>; +@group(1) @binding(1) var uSampler : sampler; + +struct VSOutput { + @builtin(position) position: vec4<f32>, + @location(0) uv : vec2<f32>, + @location(1) color : vec4<f32>, + }; +@vertex +fn mainVertex( + @location(0) aVertex: vec2<f32>, + @location(1) aPosition: vec2<f32>, + @location(2) aUV: vec2<f32>, + @location(3) aColor: vec4<f32>, + @location(4) aRotation: f32, +) -> VSOutput { + + let v = vec2( + aVertex.x * cos(aRotation) - aVertex.y * sin(aRotation), + aVertex.x * sin(aRotation) + aVertex.y * cos(aRotation) + ) + aPosition; + + var position = vec4((uniforms.uTranslationMatrix * vec3(v, 1.0)).xy, 0.0, 1.0); + + if(uniforms.uRound == 1.0) { + position = vec4(roundPixels(position.xy, uniforms.uResolution), position.zw); + } + + let vColor = vec4(aColor.rgb * aColor.a, aColor.a) * uniforms.uColor; + + return VSOutput( + position, + aUV, + vColor, + ); +} + +@fragment +fn mainFragment( + @location(0) uv: vec2<f32>, + @location(1) color: vec4<f32>, + @builtin(position) position: vec4<f32>, +) -> @location(0) vec4<f32> { + + var sample = textureSample(uTexture, uSampler, uv) * color; + + return sample; +}`;class Xt extends oe{constructor(){const e=ft.from({vertex:Yt,fragment:Vt}),t=pt.from({fragment:{source:Te,entryPoint:"mainFragment"},vertex:{source:Te,entryPoint:"mainVertex"}});super({glProgram:e,gpuProgram:t,resources:{uTexture:C.WHITE.source,uSampler:new W({}),uniforms:{uTranslationMatrix:{value:new R,type:"mat3x3<f32>"},uColor:{value:new Ce(16777215),type:"vec4<f32>"},uRound:{value:1,type:"f32"},uResolution:{value:[0,0],type:"vec2<f32>"}}}})}}class Ke{constructor(e,t){this.state=j.for2d(),this.localUniforms=new z({uTranslationMatrix:{value:new R,type:"mat3x3<f32>"},uColor:{value:new Float32Array(4),type:"vec4<f32>"},uRound:{value:1,type:"f32"},uResolution:{value:[0,0],type:"vec2<f32>"}}),this.renderer=e,this.adaptor=t,this.defaultShader=new Xt,this.state=j.for2d()}validateRenderable(e){return!1}addRenderable(e,t){this.renderer.renderPipes.batch.break(t),t.add(e)}getBuffers(e){return e._gpuData[this.renderer.uid]||this._initBuffer(e)}_initBuffer(e){return e._gpuData[this.renderer.uid]=new Lt({size:e.particleChildren.length,properties:e._properties}),e._gpuData[this.renderer.uid]}updateRenderable(e){}execute(e){const t=e.particleChildren;if(t.length===0)return;const r=this.renderer,s=this.getBuffers(e);e.texture||(e.texture=t[0].texture);const i=this.state;s.update(t,e._childrenDirty),e._childrenDirty=!1,i.blendMode=ae(e.blendMode,e.texture._source);const n=this.localUniforms.uniforms,a=n.uTranslationMatrix;e.worldTransform.copyTo(a),a.prepend(r.globalUniforms.globalUniformData.projectionMatrix),n.uResolution=r.globalUniforms.globalUniformData.resolution,n.uRound=r._roundPixels|e._roundPixels,$(e.groupColorAlpha,n.uColor,0),this.adaptor.execute(this,e)}destroy(){this.renderer=null,this.defaultShader&&(this.defaultShader.destroy(),this.defaultShader=null)}}class je extends Ke{constructor(e){super(e,new Wt)}}je.extension={type:[g.WebGLPipes],name:"particle"};class $e extends Ke{constructor(e){super(e,new It)}}$e.extension={type:[g.WebGPUPipes],name:"particle"};const Ne=class qe extends Ot{constructor(e={}){e={...qe.defaultOptions,...e},super({width:e.width,height:e.height,verticesX:4,verticesY:4}),this.update(e)}update(e){var t,r;this.width=e.width??this.width,this.height=e.height??this.height,this._originalWidth=e.originalWidth??this._originalWidth,this._originalHeight=e.originalHeight??this._originalHeight,this._leftWidth=e.leftWidth??this._leftWidth,this._rightWidth=e.rightWidth??this._rightWidth,this._topHeight=e.topHeight??this._topHeight,this._bottomHeight=e.bottomHeight??this._bottomHeight,this._anchorX=(t=e.anchor)==null?void 0:t.x,this._anchorY=(r=e.anchor)==null?void 0:r.y,this.updateUvs(),this.updatePositions()}updatePositions(){const e=this.positions,{width:t,height:r,_leftWidth:s,_rightWidth:i,_topHeight:n,_bottomHeight:a,_anchorX:u,_anchorY:l}=this,d=s+i,c=t>d?1:t/d,h=n+a,f=r>h?1:r/h,y=Math.min(c,f),m=u*t,x=l*r;e[0]=e[8]=e[16]=e[24]=-m,e[2]=e[10]=e[18]=e[26]=s*y-m,e[4]=e[12]=e[20]=e[28]=t-i*y-m,e[6]=e[14]=e[22]=e[30]=t-m,e[1]=e[3]=e[5]=e[7]=-x,e[9]=e[11]=e[13]=e[15]=n*y-x,e[17]=e[19]=e[21]=e[23]=r-a*y-x,e[25]=e[27]=e[29]=e[31]=r-x,this.getBuffer("aPosition").update()}updateUvs(){const e=this.uvs;e[0]=e[8]=e[16]=e[24]=0,e[1]=e[3]=e[5]=e[7]=0,e[6]=e[14]=e[22]=e[30]=1,e[25]=e[27]=e[29]=e[31]=1;const t=1/this._originalWidth,r=1/this._originalHeight;e[2]=e[10]=e[18]=e[26]=t*this._leftWidth,e[9]=e[11]=e[13]=e[15]=r*this._topHeight,e[4]=e[12]=e[20]=e[28]=1-t*this._rightWidth,e[17]=e[19]=e[21]=e[23]=1-r*this._bottomHeight,this.getBuffer("aUV").update()}};Ne.defaultOptions={width:100,height:100,leftWidth:10,topHeight:10,rightWidth:10,bottomHeight:10,originalWidth:100,originalHeight:100};let Kt=Ne;class jt extends le{constructor(){super(),this.geometry=new Kt}destroy(){this.geometry.destroy()}}class Qe{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.geometry.update(e),t.setTexture(e._texture)}_getGpuSprite(e){return e._gpuData[this._renderer.uid]||this._initGPUSprite(e)}_initGPUSprite(e){const t=e._gpuData[this._renderer.uid]=new jt,r=t;return r.renderable=e,r.transform=e.groupTransform,r.texture=e._texture,r.roundPixels=this._renderer._roundPixels|e._roundPixels,e.didViewUpdate||this._updateBatchableSprite(e,r),t}destroy(){this._renderer=null}}Qe.extension={type:[g.WebGLPipes,g.WebGPUPipes,g.CanvasPipes],name:"nineSliceSprite"};const $t={name:"tiling-bit",vertex:{header:` + struct TilingUniforms { + uMapCoord:mat3x3<f32>, + uClampFrame:vec4<f32>, + uClampOffset:vec2<f32>, + uTextureTransform:mat3x3<f32>, + uSizeAnchor:vec4<f32> + }; + + @group(2) @binding(0) var<uniform> tilingUniforms: TilingUniforms; + @group(2) @binding(1) var uTexture: texture_2d<f32>; + @group(2) @binding(2) var uSampler: sampler; + `,main:` + uv = (tilingUniforms.uTextureTransform * vec3(uv, 1.0)).xy; + + position = (position - tilingUniforms.uSizeAnchor.zw) * tilingUniforms.uSizeAnchor.xy; + `},fragment:{header:` + struct TilingUniforms { + uMapCoord:mat3x3<f32>, + uClampFrame:vec4<f32>, + uClampOffset:vec2<f32>, + uTextureTransform:mat3x3<f32>, + uSizeAnchor:vec4<f32> + }; + + @group(2) @binding(0) var<uniform> tilingUniforms: TilingUniforms; + @group(2) @binding(1) var uTexture: texture_2d<f32>; + @group(2) @binding(2) var uSampler: sampler; + `,main:` + + var coord = vUV + ceil(tilingUniforms.uClampOffset - vUV); + coord = (tilingUniforms.uMapCoord * vec3(coord, 1.0)).xy; + var unclamped = coord; + coord = clamp(coord, tilingUniforms.uClampFrame.xy, tilingUniforms.uClampFrame.zw); + + var bias = 0.; + + if(unclamped.x == coord.x && unclamped.y == coord.y) + { + bias = -32.; + } + + outColor = textureSampleBias(uTexture, uSampler, coord, bias); + `}},Nt={name:"tiling-bit",vertex:{header:` + uniform mat3 uTextureTransform; + uniform vec4 uSizeAnchor; + + `,main:` + uv = (uTextureTransform * vec3(aUV, 1.0)).xy; + + position = (position - uSizeAnchor.zw) * uSizeAnchor.xy; + `},fragment:{header:` + uniform sampler2D uTexture; + uniform mat3 uMapCoord; + uniform vec4 uClampFrame; + uniform vec2 uClampOffset; + `,main:` + + vec2 coord = vUV + ceil(uClampOffset - vUV); + coord = (uMapCoord * vec3(coord, 1.0)).xy; + vec2 unclamped = coord; + coord = clamp(coord, uClampFrame.xy, uClampFrame.zw); + + outColor = texture(uTexture, coord, unclamped == coord ? 0.0 : -32.0);// lod-bias very negative to force lod 0 + + `}};let q,Q;class qt extends oe{constructor(){q??(q=Fe({name:"tiling-sprite-shader",bits:[wt,$t,Be]})),Q??(Q=Re({name:"tiling-sprite-shader",bits:[Ct,Nt,Me]}));const e=new z({uMapCoord:{value:new R,type:"mat3x3<f32>"},uClampFrame:{value:new Float32Array([0,0,1,1]),type:"vec4<f32>"},uClampOffset:{value:new Float32Array([0,0]),type:"vec2<f32>"},uTextureTransform:{value:new R,type:"mat3x3<f32>"},uSizeAnchor:{value:new Float32Array([100,100,.5,.5]),type:"vec4<f32>"}});super({glProgram:Q,gpuProgram:q,resources:{localUniforms:new z({uTransformMatrix:{value:new R,type:"mat3x3<f32>"},uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uRound:{value:0,type:"f32"}}),tilingUniforms:e,uTexture:C.EMPTY.source,uSampler:C.EMPTY.source.style}})}updateUniforms(e,t,r,s,i,n){const a=this.resources.tilingUniforms,u=n.width,l=n.height,d=n.textureMatrix,c=a.uniforms.uTextureTransform;c.set(r.a*u/e,r.b*u/t,r.c*l/e,r.d*l/t,r.tx/e,r.ty/t),c.invert(),a.uniforms.uMapCoord=d.mapCoord,a.uniforms.uClampFrame=d.uClampFrame,a.uniforms.uClampOffset=d.uClampOffset,a.uniforms.uTextureTransform=c,a.uniforms.uSizeAnchor[0]=e,a.uniforms.uSizeAnchor[1]=t,a.uniforms.uSizeAnchor[2]=s,a.uniforms.uSizeAnchor[3]=i,n&&(this.resources.uTexture=n.source,this.resources.uSampler=n.source.style)}}class Qt extends ue{constructor(){super({positions:new Float32Array([0,0,1,0,1,1,0,1]),uvs:new Float32Array([0,0,1,0,1,1,0,1]),indices:new Uint32Array([0,1,2,0,2,3])})}}function Jt(o,e){const t=o.anchor.x,r=o.anchor.y;e[0]=-t*o.width,e[1]=-r*o.height,e[2]=(1-t)*o.width,e[3]=-r*o.height,e[4]=(1-t)*o.width,e[5]=(1-r)*o.height,e[6]=-t*o.width,e[7]=(1-r)*o.height}function Zt(o,e,t,r){let s=0;const i=o.length/e,n=r.a,a=r.b,u=r.c,l=r.d,d=r.tx,c=r.ty;for(t*=e;s<i;){const h=o[t],f=o[t+1];o[t]=n*h+u*f+d,o[t+1]=a*h+l*f+c,t+=e,s++}}function er(o,e){const t=o.texture,r=t.frame.width,s=t.frame.height;let i=0,n=0;o.applyAnchorToTexture&&(i=o.anchor.x,n=o.anchor.y),e[0]=e[6]=-i,e[2]=e[4]=1-i,e[1]=e[3]=-n,e[5]=e[7]=1-n;const a=R.shared;a.copyFrom(o._tileTransform.matrix),a.tx/=o.width,a.ty/=o.height,a.invert(),a.scale(o.width/r,o.height/s),Zt(e,2,0,a)}const V=new Qt;class tr{constructor(){this.canBatch=!0,this.geometry=new ue({indices:V.indices.slice(),positions:V.positions.slice(),uvs:V.uvs.slice()})}destroy(){var e;this.geometry.destroy(),(e=this.shader)==null||e.destroy()}}class Je{constructor(e){this._state=j.default2d,this._renderer=e}validateRenderable(e){const t=this._getTilingSpriteData(e),r=t.canBatch;this._updateCanBatch(e);const s=t.canBatch;if(s&&s===r){const{batchableMesh:i}=t;return!i._batcher.checkAndUpdateTexture(i,e.texture)}return r!==s}addRenderable(e,t){const r=this._renderer.renderPipes.batch;this._updateCanBatch(e);const s=this._getTilingSpriteData(e),{geometry:i,canBatch:n}=s;if(n){s.batchableMesh||(s.batchableMesh=new le);const a=s.batchableMesh;e.didViewUpdate&&(this._updateBatchableMesh(e),a.geometry=i,a.renderable=e,a.transform=e.groupTransform,a.setTexture(e._texture)),a.roundPixels=this._renderer._roundPixels|e._roundPixels,r.addToBatch(a,t)}else r.break(t),s.shader||(s.shader=new qt),this.updateRenderable(e),t.add(e)}execute(e){const{shader:t}=this._getTilingSpriteData(e);t.groups[0]=this._renderer.globalUniforms.bindGroup;const r=t.resources.localUniforms.uniforms;r.uTransformMatrix=e.groupTransform,r.uRound=this._renderer._roundPixels|e._roundPixels,$(e.groupColorAlpha,r.uColor,0),this._state.blendMode=ae(e.groupBlendMode,e.texture._source),this._renderer.encoder.draw({geometry:V,shader:t,state:this._state})}updateRenderable(e){const t=this._getTilingSpriteData(e),{canBatch:r}=t;if(r){const{batchableMesh:s}=t;e.didViewUpdate&&this._updateBatchableMesh(e),s._batcher.updateElement(s)}else if(e.didViewUpdate){const{shader:s}=t;s.updateUniforms(e.width,e.height,e._tileTransform.matrix,e.anchor.x,e.anchor.y,e.texture)}}_getTilingSpriteData(e){return e._gpuData[this._renderer.uid]||this._initTilingSpriteData(e)}_initTilingSpriteData(e){const t=new tr;return t.renderable=e,e._gpuData[this._renderer.uid]=t,t}_updateBatchableMesh(e){const t=this._getTilingSpriteData(e),{geometry:r}=t,s=e.texture.source.style;s.addressMode!=="repeat"&&(s.addressMode="repeat",s.update()),er(e,r.uvs),Jt(e,r.positions)}destroy(){this._renderer=null}_updateCanBatch(e){const t=this._getTilingSpriteData(e),r=e.texture;let s=!0;return this._renderer.type===ie.WEBGL&&(s=this._renderer.context.supports.nonPowOf2wrapping),t.canBatch=r.textureMatrix.isSimple&&(s||r.source.isPowerOfTwo),t.canBatch}}Je.extension={type:[g.WebGLPipes,g.WebGPUPipes,g.CanvasPipes],name:"tilingSprite"};const rr={name:"local-uniform-msdf-bit",vertex:{header:` + struct LocalUniforms { + uColor:vec4<f32>, + uTransformMatrix:mat3x3<f32>, + uDistance: f32, + uRound:f32, + } + + @group(2) @binding(0) var<uniform> localUniforms : LocalUniforms; + `,main:` + vColor *= localUniforms.uColor; + modelMatrix *= localUniforms.uTransformMatrix; + `,end:` + if(localUniforms.uRound == 1) + { + vPosition = vec4(roundPixels(vPosition.xy, globalUniforms.uResolution), vPosition.zw); + } + `},fragment:{header:` + struct LocalUniforms { + uColor:vec4<f32>, + uTransformMatrix:mat3x3<f32>, + uDistance: f32 + } + + @group(2) @binding(0) var<uniform> localUniforms : LocalUniforms; + `,main:` + outColor = vec4<f32>(calculateMSDFAlpha(outColor, localUniforms.uColor, localUniforms.uDistance)); + `}},sr={name:"local-uniform-msdf-bit",vertex:{header:` + uniform mat3 uTransformMatrix; + uniform vec4 uColor; + uniform float uRound; + `,main:` + vColor *= uColor; + modelMatrix *= uTransformMatrix; + `,end:` + if(uRound == 1.) + { + gl_Position.xy = roundPixels(gl_Position.xy, uResolution); + } + `},fragment:{header:` + uniform float uDistance; + `,main:` + outColor = vec4(calculateMSDFAlpha(outColor, vColor, uDistance)); + `}},ir={name:"msdf-bit",fragment:{header:` + fn calculateMSDFAlpha(msdfColor:vec4<f32>, shapeColor:vec4<f32>, distance:f32) -> f32 { + + // MSDF + var median = msdfColor.r + msdfColor.g + msdfColor.b - + min(msdfColor.r, min(msdfColor.g, msdfColor.b)) - + max(msdfColor.r, max(msdfColor.g, msdfColor.b)); + + // SDF + median = min(median, msdfColor.a); + + var screenPxDistance = distance * (median - 0.5); + var alpha = clamp(screenPxDistance + 0.5, 0.0, 1.0); + if (median < 0.01) { + alpha = 0.0; + } else if (median > 0.99) { + alpha = 1.0; + } + + // Gamma correction for coverage-like alpha + var luma: f32 = dot(shapeColor.rgb, vec3<f32>(0.299, 0.587, 0.114)); + var gamma: f32 = mix(1.0, 1.0 / 2.2, luma); + var coverage: f32 = pow(shapeColor.a * alpha, gamma); + + return coverage; + + } + `}},nr={name:"msdf-bit",fragment:{header:` + float calculateMSDFAlpha(vec4 msdfColor, vec4 shapeColor, float distance) { + + // MSDF + float median = msdfColor.r + msdfColor.g + msdfColor.b - + min(msdfColor.r, min(msdfColor.g, msdfColor.b)) - + max(msdfColor.r, max(msdfColor.g, msdfColor.b)); + + // SDF + median = min(median, msdfColor.a); + + float screenPxDistance = distance * (median - 0.5); + float alpha = clamp(screenPxDistance + 0.5, 0.0, 1.0); + + if (median < 0.01) { + alpha = 0.0; + } else if (median > 0.99) { + alpha = 1.0; + } + + // Gamma correction for coverage-like alpha + float luma = dot(shapeColor.rgb, vec3(0.299, 0.587, 0.114)); + float gamma = mix(1.0, 1.0 / 2.2, luma); + float coverage = pow(shapeColor.a * alpha, gamma); + + return coverage; + } + `}};let J,Z;class ar extends oe{constructor(e){const t=new z({uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uTransformMatrix:{value:new R,type:"mat3x3<f32>"},uDistance:{value:4,type:"f32"},uRound:{value:0,type:"f32"}});J??(J=Fe({name:"sdf-shader",bits:[gt,mt(e),rr,ir,Be]})),Z??(Z=Re({name:"sdf-shader",bits:[xt,_t(e),sr,nr,Me]})),super({glProgram:Z,gpuProgram:J,resources:{localUniforms:t,batchSamplers:yt(e)}})}}class or extends bt{destroy(){this.context.customShader&&this.context.customShader.destroy(),super.destroy()}}class Ze{constructor(e){this._renderer=e}validateRenderable(e){const t=this._getGpuBitmapText(e);return this._renderer.renderPipes.graphics.validateRenderable(t)}addRenderable(e,t){const r=this._getGpuBitmapText(e);we(e,r),e._didTextUpdate&&(e._didTextUpdate=!1,this._updateContext(e,r)),this._renderer.renderPipes.graphics.addRenderable(r,t),r.context.customShader&&this._updateDistanceField(e)}updateRenderable(e){const t=this._getGpuBitmapText(e);we(e,t),this._renderer.renderPipes.graphics.updateRenderable(t),t.context.customShader&&this._updateDistanceField(e)}_updateContext(e,t){const{context:r}=t,s=Ut.getFont(e.text,e._style);r.clear(),s.distanceField.type!=="none"&&(r.customShader||(r.customShader=new ar(this._renderer.limits.maxBatchableTextures)));const i=D.graphemeSegmenter(e.text),n=e._style;let a=s.baseLineOffset;const u=De(i,n,s,!0),l=n.padding,d=u.scale;let c=u.width,h=u.height+u.offsetY;n._stroke&&(c+=n._stroke.width/d,h+=n._stroke.width/d),r.translate(-e._anchor._x*c-l,-e._anchor._y*h-l).scale(d,d);const f=s.applyFillAsTint?n._fill.color:16777215;let y=s.fontMetrics.fontSize,m=s.lineHeight;n.lineHeight&&(y=n.fontSize/d,m=n.lineHeight/d);let x=(m-y)/2;x-s.baseLineOffset<0&&(x=0);for(let p=0;p<u.lines.length;p++){const _=u.lines[p];for(let b=0;b<_.charPositions.length;b++){const v=_.chars[b],S=s.chars[v];if(S!=null&&S.texture){const G=S.texture;r.texture(G,f||"black",Math.round(_.charPositions[b]+S.xOffset),Math.round(a+S.yOffset+x),G.orig.width,G.orig.height)}}a+=m}}_getGpuBitmapText(e){return e._gpuData[this._renderer.uid]||this.initGpuText(e)}initGpuText(e){const t=new or;return e._gpuData[this._renderer.uid]=t,this._updateContext(e,t),t}_updateDistanceField(e){const t=this._getGpuBitmapText(e).context,r=e._style.fontFamily,s=P.get(`${r}-bitmap`),{a:i,b:n,c:a,d:u}=e.groupTransform,l=Math.sqrt(i*i+n*n),d=Math.sqrt(a*a+u*u),c=(Math.abs(l)+Math.abs(d))/2,h=s.baseRenderedFontSize/e._style.fontSize,f=c*s.distanceField.range*(1/h);t.customShader.resources.localUniforms.uniforms.uDistance=f}destroy(){this._renderer=null}}Ze.extension={type:[g.WebGLPipes,g.WebGPUPipes,g.CanvasPipes],name:"bitmapText"};function we(o,e){e.groupTransform=o.groupTransform,e.groupColorAlpha=o.groupColorAlpha,e.groupColor=o.groupColor,e.groupBlendMode=o.groupBlendMode,e.globalDisplayStatus=o.globalDisplayStatus,e.groupTransform=o.groupTransform,e.localDisplayStatus=o.localDisplayStatus,e.groupAlpha=o.groupAlpha,e._roundPixels=o._roundPixels}class ur extends Ue{constructor(e){super(),this.generatingTexture=!1,this.currentKey="--",this._renderer=e,e.runners.resolutionChange.add(this)}resolutionChange(){const e=this.renderable;e._autoResolution&&e.onViewUpdate()}destroy(){const{htmlText:e}=this._renderer;e.getReferenceCount(this.currentKey)===null?e.returnTexturePromise(this.texturePromise):e.decreaseReferenceCount(this.currentKey),this._renderer.runners.resolutionChange.remove(this),this.texturePromise=null,this._renderer=null}}function re(o,e){const{texture:t,bounds:r}=o,s=e._style._getFinalPadding();vt(r,e._anchor,t);const i=e._anchor._x*s*2,n=e._anchor._y*s*2;r.minX-=s-i,r.minY-=s-n,r.maxX-=s-i,r.maxY-=s-n}class et{constructor(e){this._renderer=e}validateRenderable(e){const t=this._getGpuText(e),r=e.styleKey;return t.currentKey!==r}addRenderable(e,t){const r=this._getGpuText(e);if(e._didTextUpdate){const s=e._autoResolution?this._renderer.resolution:e.resolution;(r.currentKey!==e.styleKey||e.resolution!==s)&&this._updateGpuText(e).catch(i=>{console.error(i)}),e._didTextUpdate=!1,re(r,e)}this._renderer.renderPipes.batch.addToBatch(r,t)}updateRenderable(e){const t=this._getGpuText(e);t._batcher.updateElement(t)}async _updateGpuText(e){e._didTextUpdate=!1;const t=this._getGpuText(e);if(t.generatingTexture)return;const r=t.texturePromise;t.texturePromise=null,t.generatingTexture=!0,e._resolution=e._autoResolution?this._renderer.resolution:e.resolution;let s=this._renderer.htmlText.getTexturePromise(e);r&&(s=s.finally(()=>{this._renderer.htmlText.decreaseReferenceCount(t.currentKey),this._renderer.htmlText.returnTexturePromise(r)})),t.texturePromise=s,t.currentKey=e.styleKey,t.texture=await s;const i=e.renderGroup||e.parentRenderGroup;i&&(i.structureDidChange=!0),t.generatingTexture=!1,re(t,e)}_getGpuText(e){return e._gpuData[this._renderer.uid]||this.initGpuText(e)}initGpuText(e){const t=new ur(this._renderer);return t.renderable=e,t.transform=e.groupTransform,t.texture=C.EMPTY,t.bounds={minX:0,maxX:1,minY:0,maxY:0},t.roundPixels=this._renderer._roundPixels|e._roundPixels,e._resolution=e._autoResolution?this._renderer.resolution:e.resolution,e._gpuData[this._renderer.uid]=t,t}destroy(){this._renderer=null}}et.extension={type:[g.WebGLPipes,g.WebGPUPipes,g.CanvasPipes],name:"htmlText"};function lr(){const{userAgent:o}=ne.get().getNavigator();return/^((?!chrome|android).)*safari/i.test(o)}const cr=new Pe;function tt(o,e,t,r){const s=cr;s.minX=0,s.minY=0,s.maxX=o.width/r|0,s.maxY=o.height/r|0;const i=F.getOptimalTexture(s.width,s.height,r,!1);return i.source.uploadMethodId="image",i.source.resource=o,i.source.alphaMode="premultiply-alpha-on-upload",i.frame.width=e/r,i.frame.height=t/r,i.source.emit("update",i.source),i.updateUvs(),i}function dr(o,e){const t=e.fontFamily,r=[],s={},i=/font-family:([^;"\s]+)/g,n=o.match(i);function a(u){s[u]||(r.push(u),s[u]=!0)}if(Array.isArray(t))for(let u=0;u<t.length;u++)a(t[u]);else a(t);n&&n.forEach(u=>{const l=u.split(":")[1].trim();a(l)});for(const u in e.tagStyles){const l=e.tagStyles[u].fontFamily;a(l)}return r}async function hr(o){const t=await(await ne.get().fetch(o)).blob(),r=new FileReader;return await new Promise((i,n)=>{r.onloadend=()=>i(r.result),r.onerror=n,r.readAsDataURL(t)})}async function fr(o,e){const t=await hr(e);return`@font-face { + font-family: "${o.fontFamily}"; + font-weight: ${o.fontWeight}; + font-style: ${o.fontStyle}; + src: url('${t}'); + }`}const ee=new Map;async function pr(o){const e=o.filter(t=>P.has(`${t}-and-url`)).map(t=>{if(!ee.has(t)){const{entries:r}=P.get(`${t}-and-url`),s=[];r.forEach(i=>{const n=i.url,u=i.faces.map(l=>({weight:l.weight,style:l.style}));s.push(...u.map(l=>fr({fontWeight:l.weight,fontStyle:l.style,fontFamily:t},n)))}),ee.set(t,Promise.all(s).then(i=>i.join(` +`)))}return ee.get(t)});return(await Promise.all(e)).join(` +`)}function gr(o,e,t,r,s){const{domElement:i,styleElement:n,svgRoot:a}=s;i.innerHTML=`<style>${e.cssStyle}</style><div style='padding:0;'>${o}</div>`,i.setAttribute("style",`transform: scale(${t});transform-origin: top left; display: inline-block`),n.textContent=r;const{width:u,height:l}=s.image;return a.setAttribute("width",u.toString()),a.setAttribute("height",l.toString()),new XMLSerializer().serializeToString(a)}function mr(o,e){const t=Y.getOptimalCanvasAndContext(o.width,o.height,e),{context:r}=t;return r.clearRect(0,0,o.width,o.height),r.drawImage(o,0,0),t}function xr(o,e,t){return new Promise(async r=>{t&&await new Promise(s=>setTimeout(s,100)),o.onload=()=>{r()},o.src=`data:image/svg+xml;charset=utf8,${encodeURIComponent(e)}`,o.crossOrigin="anonymous"})}class rt{constructor(e){this._activeTextures={},this._renderer=e,this._createCanvas=e.type===ie.WEBGPU}getTexture(e){return this.getTexturePromise(e)}getManagedTexture(e){const t=e.styleKey;if(this._activeTextures[t])return this._increaseReferenceCount(t),this._activeTextures[t].promise;const r=this._buildTexturePromise(e).then(s=>(this._activeTextures[t].texture=s,s));return this._activeTextures[t]={texture:null,promise:r,usageCount:1},r}getReferenceCount(e){var t;return((t=this._activeTextures[e])==null?void 0:t.usageCount)??null}_increaseReferenceCount(e){this._activeTextures[e].usageCount++}decreaseReferenceCount(e){const t=this._activeTextures[e];t&&(t.usageCount--,t.usageCount===0&&(t.texture?this._cleanUp(t.texture):t.promise.then(r=>{t.texture=r,this._cleanUp(t.texture)}).catch(()=>{X("HTMLTextSystem: Failed to clean texture")}),this._activeTextures[e]=null))}getTexturePromise(e){return this._buildTexturePromise(e)}async _buildTexturePromise(e){const{text:t,style:r,resolution:s,textureStyle:i}=e,n=K.get(Le),a=dr(t,r),u=await pr(a),l=kt(t,r,u,n),d=Math.ceil(Math.ceil(Math.max(1,l.width)+r.padding*2)*s),c=Math.ceil(Math.ceil(Math.max(1,l.height)+r.padding*2)*s),h=n.image,f=2;h.width=(d|0)+f,h.height=(c|0)+f;const y=gr(t,r,s,u,n);await xr(h,y,lr()&&a.length>0);const m=h;let x;this._createCanvas&&(x=mr(h,s));const p=tt(x?x.canvas:m,h.width-f,h.height-f,s);return i&&(p.source.style=i),this._createCanvas&&(this._renderer.texture.initSource(p.source),Y.returnCanvasAndContext(x)),K.return(n),p}returnTexturePromise(e){e.then(t=>{this._cleanUp(t)}).catch(()=>{X("HTMLTextSystem: Failed to clean texture")})}_cleanUp(e){F.returnTexture(e,!0),e.source.resource=null,e.source.uploadMethodId="unknown"}destroy(){this._renderer=null;for(const e in this._activeTextures)this._activeTextures[e]&&this.returnTexturePromise(this._activeTextures[e].promise);this._activeTextures=null}}rt.extension={type:[g.WebGLSystem,g.WebGPUSystem,g.CanvasSystem],name:"htmlText"};class _r extends Ue{constructor(e){super(),this._renderer=e,e.runners.resolutionChange.add(this)}resolutionChange(){const e=this.renderable;e._autoResolution&&e.onViewUpdate()}destroy(){const{canvasText:e}=this._renderer;e.getReferenceCount(this.currentKey)>0?e.decreaseReferenceCount(this.currentKey):this.texture&&e.returnTexture(this.texture),this._renderer.runners.resolutionChange.remove(this),this._renderer=null}}class st{constructor(e){this._renderer=e}validateRenderable(e){const t=this._getGpuText(e),r=e.styleKey;return t.currentKey!==r?!0:e._didTextUpdate}addRenderable(e,t){const r=this._getGpuText(e);if(e._didTextUpdate){const s=e._autoResolution?this._renderer.resolution:e.resolution;(r.currentKey!==e.styleKey||e.resolution!==s)&&this._updateGpuText(e),e._didTextUpdate=!1}this._renderer.renderPipes.batch.addToBatch(r,t)}updateRenderable(e){const t=this._getGpuText(e);t._batcher.updateElement(t)}_updateGpuText(e){const t=this._getGpuText(e);t.texture&&this._renderer.canvasText.decreaseReferenceCount(t.currentKey),e._resolution=e._autoResolution?this._renderer.resolution:e.resolution,t.texture=this._renderer.canvasText.getManagedTexture(e),t.currentKey=e.styleKey,re(t,e)}_getGpuText(e){return e._gpuData[this._renderer.uid]||this.initGpuText(e)}initGpuText(e){const t=new _r(this._renderer);return t.currentKey="--",t.renderable=e,t.transform=e.groupTransform,t.bounds={minX:0,maxX:1,minY:0,maxY:0},t.roundPixels=this._renderer._roundPixels|e._roundPixels,e._gpuData[this._renderer.uid]=t,t}destroy(){this._renderer=null}}st.extension={type:[g.WebGLPipes,g.WebGPUPipes,g.CanvasPipes],name:"text"};class it{constructor(e){this._activeTextures={},this._renderer=e}getTexture(e,t,r,s){typeof e=="string"&&(w("8.0.0","CanvasTextSystem.getTexture: Use object TextOptions instead of separate arguments"),e={text:e,style:r,resolution:t}),e.style instanceof I||(e.style=new I(e.style)),e.textureStyle instanceof W||(e.textureStyle=new W(e.textureStyle)),typeof e.text!="string"&&(e.text=e.text.toString());const{text:i,style:n,textureStyle:a}=e,u=e.resolution??this._renderer.resolution,{frame:l,canvasAndContext:d}=N.getCanvasAndContext({text:i,style:n,resolution:u}),c=tt(d.canvas,l.width,l.height,u);if(a&&(c.source.style=a),n.trim&&(l.pad(n.padding),c.frame.copyFrom(l),c.frame.scale(1/u),c.updateUvs()),n.filters){const h=this._applyFilters(c,n.filters);return this.returnTexture(c),N.returnCanvasAndContext(d),h}return this._renderer.texture.initSource(c._source),N.returnCanvasAndContext(d),c}returnTexture(e){const t=e.source;t.resource=null,t.uploadMethodId="unknown",t.alphaMode="no-premultiply-alpha",F.returnTexture(e,!0)}renderTextToCanvas(){w("8.10.0","CanvasTextSystem.renderTextToCanvas: no longer supported, use CanvasTextSystem.getTexture instead")}getManagedTexture(e){e._resolution=e._autoResolution?this._renderer.resolution:e.resolution;const t=e.styleKey;if(this._activeTextures[t])return this._increaseReferenceCount(t),this._activeTextures[t].texture;const r=this.getTexture({text:e.text,style:e.style,resolution:e._resolution,textureStyle:e.textureStyle});return this._activeTextures[t]={texture:r,usageCount:1},r}decreaseReferenceCount(e){const t=this._activeTextures[e];t.usageCount--,t.usageCount===0&&(this.returnTexture(t.texture),this._activeTextures[e]=null)}getReferenceCount(e){var t;return((t=this._activeTextures[e])==null?void 0:t.usageCount)??0}_increaseReferenceCount(e){this._activeTextures[e].usageCount++}_applyFilters(e,t){const r=this._renderer.renderTarget.renderTarget,s=this._renderer.filter.generateFilteredTexture({texture:e,filters:t});return this._renderer.renderTarget.bind(r,!1),s}destroy(){this._renderer=null;for(const e in this._activeTextures)this._activeTextures[e]&&this.returnTexture(this._activeTextures[e].texture);this._activeTextures=null}}it.extension={type:[g.WebGLSystem,g.WebGPUSystem,g.CanvasSystem],name:"canvasText"};T.add(Ge);T.add(Ae);T.add(He);T.add(Tt);T.add(Xe);T.add(je);T.add($e);T.add(it);T.add(st);T.add(Ze);T.add(rt);T.add(et);T.add(Je);T.add(Qe);T.add(We);T.add(Oe); |
