import{D as et,E as T,p as y,w as j,B as st,I as it}from"./sprite-view-Br3916N3.js";const P=Object.create(null),V=Object.create(null);function A(i,t){let e=V[i];return e===void 0&&(P[t]===void 0&&(P[t]=1),V[i]=e=P[t]++),e}let x;function rt(){return(!x||x?.isContextLost())&&(x=et.get().createCanvas().getContext("webgl",{})),x}let E;function nt(){if(!E){E="mediump";const i=rt();i&&i.getShaderPrecisionFormat&&(E=i.getShaderPrecisionFormat(i.FRAGMENT_SHADER,i.HIGH_FLOAT).precision?"highp":"mediump")}return E}function ot(i,t,e){return t?i:e?(i=i.replace("out vec4 finalColor;",""),`

        #ifdef GL_ES // This checks if it is WebGL1
        #define in varying
        #define finalColor gl_FragColor
        #define texture texture2D
        #endif
        ${i}
        `):`

        #ifdef GL_ES // This checks if it is WebGL1
        #define in attribute
        #define out varying
        #endif
        ${i}
        `}function at(i,t,e){const s=e?t.maxSupportedFragmentPrecision:t.maxSupportedVertexPrecision;if(i.substring(0,9)!=="precision"){let r=e?t.requestedFragmentPrecision:t.requestedVertexPrecision;return r==="highp"&&s!=="highp"&&(r="mediump"),`precision ${r} float;
${i}`}else if(s!=="highp"&&i.substring(0,15)==="precision highp")return i.replace("precision highp","precision mediump");return i}function ut(i,t){return t?`#version 300 es
${i}`:i}const ct={},ht={};function ft(i,{name:t="pixi-program"},e=!0){t=t.replace(/\s+/g,"-"),t+=e?"-fragment":"-vertex";const s=e?ct:ht;return s[t]?(s[t]++,t+=`-${s[t]}`):s[t]=1,i.indexOf("#define SHADER_NAME")!==-1?i:`${`#define SHADER_NAME ${t}`}
${i}`}function dt(i,t){return t?i.replace("#version 300 es",""):i}const D={stripVersion:dt,ensurePrecision:at,addProgramDefines:ot,setProgramName:ft,insertVersion:ut},_=Object.create(null),W=class I{constructor(t){t={...I.defaultOptions,...t};const e=t.fragment.indexOf("#version 300 es")!==-1,s={stripVersion:e,ensurePrecision:{requestedFragmentPrecision:t.preferredFragmentPrecision,requestedVertexPrecision:t.preferredVertexPrecision,maxSupportedVertexPrecision:"highp",maxSupportedFragmentPrecision:nt()},setProgramName:{name:t.name},addProgramDefines:e,insertVersion:e};let r=t.fragment,n=t.vertex;Object.keys(D).forEach(a=>{const o=s[a];r=D[a](r,o,!0),n=D[a](n,o,!1)}),this.fragment=r,this.vertex=n,this.transformFeedbackVaryings=t.transformFeedbackVaryings,this._key=A(`${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,_[this._cacheKey]=null}static from(t){const e=`${t.vertex}:${t.fragment}`;return _[e]||(_[e]=new I(t),_[e]._cacheKey=e),_[e]}};W.defaultOptions={preferredVertexPrecision:"highp",preferredFragmentPrecision:"mediump"};let lt=W;const k={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 mt(i){return k[i]??k.float32}const pt={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",vec2i:"sint32x2",vec3i:"sint32x3",vec4i:"sint32x4",u32:"uint32","vec2<u32>":"uint32x2","vec3<u32>":"uint32x3","vec4<u32>":"uint32x4",vec2u:"uint32x2",vec3u:"uint32x3",vec4u:"uint32x4",bool:"uint32","vec2<bool>":"uint32x2","vec3<bool>":"uint32x3","vec4<bool>":"uint32x4"},X=/@location\((\d+)\)\s+([a-zA-Z0-9_]+)\s*:\s*([a-zA-Z0-9_<>]+)(?:,|\s|\)|$)/g;function B(i,t){let e;for(;(e=X.exec(i))!==null;){const s=pt[e[3]]??"float32";t[e[2]]={location:parseInt(e[1],10),format:s,stride:mt(s).stride,offset:0,instance:!1,start:0}}X.lastIndex=0}function gt(i){return i.replace(/\/\/.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"")}function yt({source:i,entryPoint:t}){const e={},s=gt(i),r=s.indexOf(`fn ${t}(`);if(r===-1)return e;const n=s.indexOf("->",r);if(n===-1)return e;const a=s.substring(r,n);if(B(a,e),Object.keys(e).length===0){const o=a.match(/\(\s*\w+\s*:\s*(\w+)/);if(o){const p=o[1],d=new RegExp(`struct\\s+${p}\\s*\\{([^}]+)\\}`,"s"),l=s.match(d);l&&B(l[1],e)}}return e}function G(i){const t=/(^|[^/])@(group|binding)\(\d+\)[^;]+;/g,e=/@group\((\d+)\)/,s=/@binding\((\d+)\)/,r=/var(<[^>]+>)? (\w+)/,n=/:\s*([\w<>]+)/,a=/struct\s+(\w+)\s*{([^}]+)}/g,o=/(\w+)\s*:\s*([\w\<\>]+)/g,p=/struct\s+(\w+)/,d=i.match(t)?.map(u=>{const c=u.match(r),m=c?.[1]??"";let f;return m==="<uniform>"?f="uniform":m.startsWith("<storage")&&(f="storage"),{group:parseInt(u.match(e)[1],10),binding:parseInt(u.match(s)[1],10),name:c[2],accessMode:f,type:u.match(n)[1]}});if(!d)return{groups:[],structs:[]};const l=i.match(a)?.map(u=>{const c=u.match(p)[1],m=u.match(o).reduce((f,Z)=>{const[J,tt]=Z.split(":");return f[J.trim()]=tt.trim(),f},{});return m?{name:c,members:m}:null}).filter(({name:u})=>d.some(c=>c.type===u||c.type.includes(`<${u}>`)))??[];return{groups:d,structs:l}}var h=(i=>(i[i.VERTEX=1]="VERTEX",i[i.FRAGMENT=2]="FRAGMENT",i[i.COMPUTE=4]="COMPUTE",i))(h||{});function _t({groups:i}){const t=[];for(let e=0;e<i.length;e++){const s=i[e];t[s.group]||(t[s.group]=[]),s.accessMode==="uniform"?t[s.group].push({binding:s.binding,visibility:h.VERTEX|h.FRAGMENT,buffer:{type:"uniform"}}):s.accessMode==="storage"?t[s.group].push({binding:s.binding,visibility:h.VERTEX|h.FRAGMENT,buffer:{type:"read-only-storage"}}):s.type==="sampler"?t[s.group].push({binding:s.binding,visibility:h.VERTEX|h.FRAGMENT,sampler:{type:"filtering"}}):s.type==="sampler_comparison"?t[s.group].push({binding:s.binding,visibility:h.VERTEX|h.FRAGMENT,sampler:{type:"comparison"}}):s.type==="texture_2d"||s.type.startsWith("texture_2d<")?t[s.group].push({binding:s.binding,visibility:h.VERTEX|h.FRAGMENT,texture:{sampleType:"float",viewDimension:"2d",multisampled:!1}}):s.type==="texture_depth_2d"?t[s.group].push({binding:s.binding,visibility:h.VERTEX|h.FRAGMENT,texture:{sampleType:"depth",viewDimension:"2d",multisampled:!1}}):s.type==="texture_depth_2d_array"?t[s.group].push({binding:s.binding,visibility:h.VERTEX|h.FRAGMENT,texture:{sampleType:"depth",viewDimension:"2d-array",multisampled:!1}}):s.type==="texture_2d_array"||s.type.startsWith("texture_2d_array<")?t[s.group].push({binding:s.binding,visibility:h.VERTEX|h.FRAGMENT,texture:{sampleType:"float",viewDimension:"2d-array",multisampled:!1}}):(s.type==="texture_cube"||s.type.startsWith("texture_cube<"))&&t[s.group].push({binding:s.binding,visibility:h.VERTEX|h.FRAGMENT,texture:{sampleType:"float",viewDimension:"cube",multisampled:!1}})}for(let e=0;e<t.length;e++)t[e]||(t[e]=[]);return t}function bt({groups:i}){const t=[];for(let e=0;e<i.length;e++){const s=i[e];t[s.group]||(t[s.group]={}),t[s.group][s.name]=s.binding}return t}function xt(i,t){const e=new Set,s=new Set,r=[...i.structs,...t.structs].filter(a=>e.has(a.name)?!1:(e.add(a.name),!0)),n=[...i.groups,...t.groups].filter(a=>{const o=`${a.name}-${a.binding}`;return s.has(o)?!1:(s.add(o),!0)});return{structs:r,groups:n}}const b=Object.create(null);class ${constructor(t){this._layoutKey=0,this._attributeLocationsKey=0;const{fragment:e,vertex:s,layout:r,gpuLayout:n,name:a}=t;if(this.name=a,this.fragment=e,this.vertex=s,e.source===s.source){const o=G(e.source);this.structsAndGroups=o}else{const o=G(s.source),p=G(e.source);this.structsAndGroups=xt(o,p)}this.layout=r??bt(this.structsAndGroups),this.gpuLayout=n??_t(this.structsAndGroups),this.autoAssignGlobalUniforms=this.layout[0]?.globalUniforms!==void 0,this.autoAssignLocalUniforms=this.layout[1]?.localUniforms!==void 0,this._generateProgramKey()}_generateProgramKey(){const{vertex:t,fragment:e}=this,s=t.source+e.source+t.entryPoint+e.entryPoint;this._layoutKey=A(s,"program")}get attributeData(){return this._attributeData??(this._attributeData=yt(this.vertex)),this._attributeData}destroy(){this.gpuLayout=null,this.layout=null,this.structsAndGroups=null,this.fragment=null,this.vertex=null,b[this._cacheKey]=null}static from(t){const e=`${t.vertex.source}:${t.fragment.source}:${t.fragment.entryPoint}:${t.vertex.entryPoint}`;return b[e]||(b[e]=new $(t),b[e]._cacheKey=e),b[e]}}const Y=["f32","i32","u32","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>","vec2<u32>","vec3<u32>","vec4<u32>"],Et=Y.reduce((i,t)=>(i[t]=!0,i),{});function vt(i,t){switch(i){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 U=class H extends T{constructor(t,e){super(),this._touched=0,this.uid=y("uniform"),this._resourceType="uniformGroup",this._resourceId=y("resource"),this.isUniformGroup=!0,this._dirtyId=0,this.destroyed=!1,e={...H.defaultOptions,...e},this.uniformStructures=t;const s={};for(const r in t){const n=t[r];if(n.name=r,n.size=n.size??1,!Et[n.type]){const a=n.type.match(/^array<(\w+(?:<\w+>)?),\s*(\d+)>$/);if(a){const[,o,p]=a;throw new Error(`Uniform type ${n.type} is not supported. Use type: '${o}', size: ${p} instead.`)}throw new Error(`Uniform type ${n.type} is not supported. Supported uniform types are: ${Y.join(", ")}`)}n.value??(n.value=vt(n.type,n.size)),s[r]=n.value}this.uniforms=s,this._dirtyId=1,this.ubo=e.ubo,this.isStatic=e.isStatic,this._signature=A(Object.keys(s).map(r=>`${r}-${t[r].type}`).join("-"),"uniform-group")}get buffer(){return this._buffer}set buffer(t){this._buffer!==t&&(this._buffer?.off("change",this.onBufferChange,this),this._buffer=t,t?.on("change",this.onBufferChange,this))}get _gcLastUsed(){return this._buffer?._gcLastUsed??-1}set _gcLastUsed(t){this._buffer&&(this._buffer._gcLastUsed=t)}onBufferChange(){this._resourceId=y("resource"),this.emit("change",this)}update(){this._dirtyId++}};U.defaultOptions={ubo:!1,isStatic:!1};let Tt=U;class S{constructor(t){this.resources=Object.create(null),this._dirty=!0;let e=0;for(const s in t){const r=t[s];this.setResource(r,e++)}}get _key(){if(this._dirty){this._dirty=!1;const t=[];let e=0;for(const s in this.resources)t[e++]=this.resources[s]?this.resources[s]._resourceId:-1;this._keyValue=t.join("|")}return this._keyValue}setResource(t,e){const s=this.resources[e];t!==s&&(s&&s.off?.("change",this.onResourceChange,this),t.on?.("change",this.onResourceChange,this),this.resources[e]=t,this._dirty=!0)}getResource(t){return this.resources[t]}_touch(t,e){const s=this.resources;for(const r in s){const n=s[r];n&&(n._gcLastUsed=t,n._touched=e)}}destroy(){const t=this.resources;for(const e in t)t[e]?.off?.("change",this.onResourceChange,this);this.resources=null}onResourceChange(t){if(this._dirty=!0,t.destroyed){const e=this.resources;for(const s in e)e[s]===t&&(e[s]=null);j(`[BindGroup] a '${t._resourceType}' was destroyed while still bound to a shader. Remove it from the shader before destroying it.`)}}}var N=(i=>(i[i.WEBGL=1]="WEBGL",i[i.WEBGPU=2]="WEBGPU",i[i.CANVAS=4]="CANVAS",i[i.BOTH=3]="BOTH",i))(N||{});class v{constructor(t){this.data={...t};const e=Object.keys(t).sort().map(s=>`${s}:${t[s]}`).join("|");this.id=A(e,"shader-overrides")}static from(t){return t instanceof v?t:new v(t)}}class K extends T{constructor(t){super(),this.uid=y("shader"),this._uniformBindMap=Object.create(null),this._ownedBindGroups=[],this._destroyed=!1;let{gpuProgram:e,glProgram:s,groups:r,resources:n,compatibleRenderers:a,groupMap:o,overrides:p}=t;this._overrides=p?v.from(p):null,this.gpuProgram=e,this.glProgram=s,a===void 0&&(a=0,e&&(a|=N.WEBGPU),s&&(a|=N.WEBGL)),this.compatibleRenderers=a;const d={};if(o)for(const l in o)for(const u in o[l]){const c=o[l][u];d[c]={group:l,binding:u,name:c}}if(!n&&!r&&(n={}),n&&r)throw new Error("[Shader] Cannot have both resources and groups");if(!e&&r&&!o)throw new Error("[Shader] No group map or WebGPU shader provided - consider using resources instead.");if(e&&r&&!o){const l=e.structsAndGroups.groups;o={},l.forEach(u=>{o[u.group]=o[u.group]||{},o[u.group][u.binding]=u.name,d[u.name]=u})}else if(n){r={},o||(o={}),e&&e.structsAndGroups.groups.forEach(c=>{o[c.group]=o[c.group]||{},o[c.group][c.binding]=c.name,d[c.name]=c});let l=0;for(const u in n)d[u]||(e&&!s&&j(`[Shader] the resource '${u}' matches no binding in the WGSL source — is the name correct?`),r[99]||(r[99]=new S,this._ownedBindGroups.push(r[99])),d[u]={group:99,binding:l,name:u},o[99]=o[99]||{},o[99][l]=u,l++);for(const u in n){const c=u;let m=n[u];!m.source&&!m._resourceType&&(m=new Tt(m));const f=d[c];f&&(r[f.group]||(r[f.group]=new S,this._ownedBindGroups.push(r[f.group])),r[f.group].setResource(m,f.binding))}}this.groups=r,this._uniformBindMap=o,this.resources=this._buildResourceAccessor(r,d)}addResource(t,e,s){var r,n;(r=this._uniformBindMap)[e]||(r[e]={}),(n=this._uniformBindMap[e])[s]||(n[s]=t),this.groups[e]||(this.groups[e]=new S,this._ownedBindGroups.push(this.groups[e]))}_buildResourceAccessor(t,e){const s={};for(const r in e){const n=e[r];Object.defineProperty(s,n.name,{get(){return t[n.group].getResource(n.binding)},set(a){t[n.group].setResource(a,n.binding)}})}return s}destroy(t=!1){this._destroyed||(this._destroyed=!0,this.emit("destroy",this),t&&(this.gpuProgram?.destroy(),this.glProgram?.destroy()),this.gpuProgram=null,this.glProgram=null,this.removeAllListeners(),this._uniformBindMap=null,this._ownedBindGroups.forEach(e=>{e.destroy()}),this._ownedBindGroups=null,this.resources=null,this.groups=null,this._overrides=null)}static from(t){const{gpu:e,gl:s,...r}=t;let n,a;return e&&(n=$.from(e)),s&&(a=lt.from(s)),new K({gpuProgram:n,glProgram:a,...r})}}const At={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},Pt={BLEND:0,OFFSET:1,CULLING:2,DEPTH_TEST:3,WINDING:4,DEPTH_MASK:5},{BLEND:w,OFFSET:R,CULLING:F,DEPTH_TEST:C,WINDING:M,DEPTH_MASK:O}=Pt,z=class q{constructor(){this.data=0,this.blendMode="normal",this.polygonOffset=0,this.blend=!0,this.depthMask=!0}get blend(){return!!(this.data&1<<w)}set blend(t){!!(this.data&1<<w)!==t&&(this.data^=1<<w)}get offsets(){return!!(this.data&1<<R)}set offsets(t){!!(this.data&1<<R)!==t&&(this.data^=1<<R)}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<<F)}set culling(t){!!(this.data&1<<F)!==t&&(this.data^=1<<F)}get depthTest(){return!!(this.data&1<<C)}set depthTest(t){!!(this.data&1<<C)!==t&&(this.data^=1<<C)}get depthMask(){return!!(this.data&1<<O)}set depthMask(t){!!(this.data&1<<O)!==t&&(this.data^=1<<O)}get clockwiseFrontFace(){return!!(this.data&1<<M)}set clockwiseFrontFace(t){!!(this.data&1<<M)!==t&&(this.data^=1<<M)}get blendMode(){return this._blendMode}set blendMode(t){this.blend=t!=="none",this._blendMode=t,this._blendModeId=At[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 q;return t.depthTest=!1,t.depthMask=!1,t.blend=!0,t}};z.default2d=z.for2d();let wt=z;var g=(i=>(i[i.MAP_READ=1]="MAP_READ",i[i.MAP_WRITE=2]="MAP_WRITE",i[i.COPY_SRC=4]="COPY_SRC",i[i.COPY_DST=8]="COPY_DST",i[i.INDEX=16]="INDEX",i[i.VERTEX=32]="VERTEX",i[i.UNIFORM=64]="UNIFORM",i[i.STORAGE=128]="STORAGE",i[i.INDIRECT=256]="INDIRECT",i[i.QUERY_RESOLVE=512]="QUERY_RESOLVE",i[i.STATIC=1024]="STATIC",i))(g||{});class L extends T{constructor(t){let{data:e,size:s}=t;const{usage:r,label:n,shrinkToFit:a}=t;super(),this._gpuData=Object.create(null),this._gcLastUsed=-1,this.autoGarbageCollect=!0,this.uid=y("buffer"),this._resourceType="buffer",this._resourceId=y("resource"),this._touched=0,this._updateID=1,this._updateOffset=0,this._dataInt32=null,this.shrinkToFit=!0,this.destroyed=!1,e instanceof Array&&(e=new Float32Array(e)),this._data=e,s??(s=e?.byteLength);const o=!!e;this.descriptor={size:s,usage:r,mappedAtCreation:o,label:n},this.shrinkToFit=a??!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&g.STATIC)}set static(t){t?this.descriptor.usage|=g.STATIC:this.descriptor.usage&=~g.STATIC}setDataWithSize(t,e,s){if(this._updateID++,this._updateSize=e*t.BYTES_PER_ELEMENT,this._updateOffset=0,this._data===t){s&&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?s&&this.emit("update",this):(this.descriptor.size=t.byteLength,this._resourceId=y("resource"),this.emit("change",this));return}s&&this.emit("update",this)}update(t,e){this._updateSize=t??this._updateSize,this._updateOffset=e||0,this._updateID++,this.emit("update",this)}unload(){this.emit("unload",this);for(const t in this._gpuData)this._gpuData[t]?.destroy();this._gpuData=Object.create(null),this.destroyed||(this._resourceId=y("resource"),this.emit("change",this))}destroy(){this.destroyed=!0,this.unload(),this.emit("destroy",this),this.emit("change",this),this._data=null,this.descriptor=null,this.removeAllListeners()}}function Q(i,t){if(!(i instanceof L)){let e=t?g.INDEX:g.VERTEX;i instanceof Array&&(t?(i=new Uint32Array(i),e=g.INDEX|g.COPY_DST):(i=new Float32Array(i),e=g.VERTEX|g.COPY_DST)),i=new L({data:i,label:t?"index-mesh-buffer":"vertex-mesh-buffer",usage:e})}return i}function Dt(i,t,e){const s=i.getAttribute(t);if(!s)return e.minX=0,e.minY=0,e.maxX=0,e.maxY=0,e;const r=s.buffer.data;let n=1/0,a=1/0,o=-1/0,p=-1/0;const d=r.BYTES_PER_ELEMENT,l=(s.offset||0)/d,u=(s.stride||2*4)/d;for(let c=l;c<r.length;c+=u){const m=r[c],f=r[c+1];m>o&&(o=m),f>p&&(p=f),m<n&&(n=m),f<a&&(a=f)}return e.minX=n,e.minY=a,e.maxX=o,e.maxY=p,e}function Gt(i){return(i instanceof L||Array.isArray(i)||i.BYTES_PER_ELEMENT)&&(i={buffer:i}),i.buffer=Q(i.buffer,!1),i}class Rt extends T{constructor(t={}){super(),this._gpuData=Object.create(null),this.autoGarbageCollect=!0,this._gcLastUsed=-1,this.uid=y("geometry"),this._layoutKey=0,this.instanceCount=1,this._bounds=new st,this._boundsDirty=!0,this._vertexCount=0,this._vertexCountDirty=!0;const{attributes:e,indexBuffer:s,topology:r}=t;if(this.buffers=[],this.attributes={},e)for(const n in e)this.addAttribute(n,e[n]);this.instanceCount=t.instanceCount??1,s&&this.addIndex(s),this.topology=r||"triangle-list"}onBufferUpdate(){this._boundsDirty=!0,this._vertexCountDirty=!0,this.emit("update",this)}getAttribute(t){return this.attributes[t]}getIndex(){return this.indexBuffer}getBuffer(t){return this.getAttribute(t).buffer}get vertexCount(){if(!this._vertexCountDirty)return this._vertexCount;this._vertexCountDirty=!1;const t=this.attributes;for(const e in t){const s=t[e];if(s.instance)continue;const r=s.buffer;return this._vertexCount=r.data.length/(s.stride/4||s.size),this._vertexCount}return this._vertexCount=0,0}getSize(){return it("8.20.0","Geometry.getSize is deprecated, please use Geometry.vertexCount instead."),this.vertexCount}addAttribute(t,e){const s=Gt(e);this.buffers.indexOf(s.buffer)===-1&&(this.buffers.push(s.buffer),s.buffer.on("update",this.onBufferUpdate,this),s.buffer.on("change",this.onBufferUpdate,this)),this.attributes[t]=s,this._vertexCountDirty=!0}addIndex(t){this.indexBuffer=Q(t,!0),this.buffers.push(this.indexBuffer)}get bounds(){return this._boundsDirty?(this._boundsDirty=!1,Dt(this,"aPosition",this._bounds)):this._bounds}unload(){this.emit("unload",this);for(const t in this._gpuData)this._gpuData[t]?.destroy();this._gpuData=Object.create(null)}destroy(t=!1){this.emit("destroy",this),this.removeAllListeners(),t&&this.buffers.forEach(e=>e.destroy()),this.unload(),this.attributes=null,this.buffers=null,this.indexBuffer=null,this._bounds=null}}export{S as B,$ as G,N as R,K as S,Tt as U,wt as a,lt as b,L as c,g as d,rt as e,Rt as f,mt as g,A as h,v as i,Pt as j};
