quake2ts 0.0.175 → 0.0.176

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/package.json +1 -1
  2. package/packages/client/dist/browser/index.global.js +3 -3
  3. package/packages/client/dist/browser/index.global.js.map +1 -1
  4. package/packages/client/dist/cjs/index.cjs.map +1 -1
  5. package/packages/client/dist/esm/index.js.map +1 -1
  6. package/packages/client/dist/tsconfig.tsbuildinfo +1 -1
  7. package/packages/engine/dist/browser/index.global.js +8 -8
  8. package/packages/engine/dist/browser/index.global.js.map +1 -1
  9. package/packages/engine/dist/cjs/index.cjs +64 -3
  10. package/packages/engine/dist/cjs/index.cjs.map +1 -1
  11. package/packages/engine/dist/esm/index.js +64 -3
  12. package/packages/engine/dist/esm/index.js.map +1 -1
  13. package/packages/engine/dist/tsconfig.tsbuildinfo +1 -1
  14. package/packages/engine/dist/types/assets/bsp.d.ts +18 -0
  15. package/packages/engine/dist/types/assets/bsp.d.ts.map +1 -1
  16. package/packages/engine/dist/types/render/bsp/geometry.d.ts +4 -1
  17. package/packages/engine/dist/types/render/bsp/geometry.d.ts.map +1 -1
  18. package/packages/game/dist/browser/index.global.js +2 -2
  19. package/packages/game/dist/browser/index.global.js.map +1 -1
  20. package/packages/game/dist/cjs/index.cjs +77 -35
  21. package/packages/game/dist/cjs/index.cjs.map +1 -1
  22. package/packages/game/dist/esm/index.js +77 -35
  23. package/packages/game/dist/esm/index.js.map +1 -1
  24. package/packages/game/dist/tsconfig.tsbuildinfo +1 -1
  25. package/packages/game/dist/types/combat/damage.d.ts +2 -2
  26. package/packages/game/dist/types/combat/damage.d.ts.map +1 -1
  27. package/packages/game/dist/types/combat/specialDamage.d.ts.map +1 -1
  28. package/packages/game/dist/types/combat/weapons/firing.d.ts.map +1 -1
  29. package/packages/game/dist/types/entities/monsters/attack.d.ts.map +1 -1
  30. package/packages/game/dist/types/entities/monsters/berserk.d.ts.map +1 -1
  31. package/packages/game/dist/types/entities/monsters/mutant.d.ts.map +1 -1
  32. package/packages/game/dist/types/entities/monsters/parasite.d.ts.map +1 -1
  33. package/packages/game/dist/types/entities/projectiles/rocket.d.ts.map +1 -1
  34. package/packages/game/dist/types/entities/projectiles.d.ts.map +1 -1
  35. package/packages/game/dist/types/inventory/playerInventory.d.ts +3 -1
  36. package/packages/game/dist/types/inventory/playerInventory.d.ts.map +1 -1
@@ -1,7 +1,7 @@
1
- "use strict";var Quake2Engine=(()=>{var vl=Object.create;var li=Object.defineProperty;var Sl=Object.getOwnPropertyDescriptor;var Ml=Object.getOwnPropertyNames;var _l=Object.getPrototypeOf,Al=Object.prototype.hasOwnProperty;var wl=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),qo=(t,e)=>{for(var r in e)li(t,r,{get:e[r],enumerable:!0})},ya=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ml(e))!Al.call(t,i)&&i!==r&&li(t,i,{get:()=>e[i],enumerable:!(n=Sl(e,i))||n.enumerable});return t};var Ll=(t,e,r)=>(r=t!=null?vl(_l(t)):{},ya(e||!t||!t.__esModule?li(r,"default",{value:t,enumerable:!0}):r,t)),El=t=>ya(li({},"__esModule",{value:!0}),t);var Ja=wl((hh,Qa)=>{"use strict";Qa.exports=Worker});var Xf={};qo(Xf,{ATTN_IDLE:()=>Pc,ATTN_LOOP_NONE:()=>Ec,ATTN_NONE:()=>so,ATTN_NORM:()=>Ic,ATTN_STATIC:()=>Cc,AssetDependencyError:()=>Zt,AssetDependencyTracker:()=>qn,AssetManager:()=>io,AudioApi:()=>dr,AudioContextController:()=>co,AudioRegistry:()=>Fr,AudioRegistryError:()=>Xn,AudioSystem:()=>yo,BSP_SURFACE_FRAGMENT_SOURCE:()=>Gs,BSP_SURFACE_VERTEX_SOURCE:()=>Vs,BSP_VERTEX_LAYOUT:()=>ks,BspLoader:()=>fr,BspParseError:()=>q,BspSurfacePipeline:()=>vo,Camera:()=>wo,Command:()=>Wr,CommandRegistry:()=>or,ConfigStringRegistry:()=>lr,Cvar:()=>Yr,CvarRegistry:()=>ar,DemoPlaybackController:()=>ii,DemoReader:()=>tr,EngineHost:()=>cr,EngineRuntime:()=>qr,FixedTimestepLoop:()=>Dt,Framebuffer:()=>xo,IndexBuffer:()=>fe,LruCache:()=>pt,MAX_SOUND_CHANNELS:()=>Bs,MD2_FRAGMENT_SHADER:()=>js,MD2_VERTEX_SHADER:()=>$s,MD3_FRAGMENT_SHADER:()=>oa,MD3_VERTEX_SHADER:()=>ia,Md2Loader:()=>mr,Md2MeshBuffers:()=>Mo,Md2ParseError:()=>le,Md2Pipeline:()=>_o,Md3Loader:()=>hr,Md3ModelMesh:()=>Lo,Md3ParseError:()=>Te,Md3Pipeline:()=>Eo,Md3SurfaceMesh:()=>Qn,MusicSystem:()=>go,NetworkMessageParser:()=>nr,PARTICLE_FRAGMENT_SHADER:()=>aa,PARTICLE_VERTEX_SHADER:()=>sa,PakArchive:()=>ur,PakIndexStore:()=>no,PakIngestionError:()=>ht,PakParseError:()=>Re,PakValidationError:()=>Ot,PakValidator:()=>gi,ParticleRenderer:()=>Po,ParticleSystem:()=>Io,PlaybackState:()=>Yo,RERELEASE_KNOWN_PAKS:()=>ss,SKYBOX_FRAGMENT_SHADER:()=>Ys,SKYBOX_VERTEX_SHADER:()=>Ks,SOUND_FULLVOLUME:()=>Br,SOUND_LOOP_ATTENUATE:()=>zc,ShaderProgram:()=>ve,SkyboxPipeline:()=>So,SoundChannel:()=>oo,SoundPrecache:()=>fo,SoundRegistry:()=>uo,SpriteLoader:()=>pr,SpriteParseError:()=>yt,Texture2D:()=>Dr,TextureCache:()=>yr,TextureCubeMap:()=>Or,TgaParseError:()=>et,U_ANGLE1:()=>No,U_ANGLE2:()=>To,U_ANGLE3:()=>Fo,U_EFFECTS16:()=>ri,U_EFFECTS8:()=>Zn,U_EVENT:()=>Do,U_FRAME16:()=>Uo,U_FRAME8:()=>Bo,U_MODEL:()=>ko,U_MODEL2:()=>Ho,U_MODEL3:()=>Vo,U_MODEL4:()=>Go,U_OLDORIGIN:()=>Wo,U_ORIGIN1:()=>zo,U_ORIGIN2:()=>Ro,U_ORIGIN3:()=>Oo,U_REMOVE:()=>ca,U_RENDERFX16:()=>ti,U_RENDERFX8:()=>Jn,U_SKIN16:()=>ni,U_SKIN8:()=>ei,U_SOLID:()=>Ko,U_SOUND:()=>Xo,VertexArray:()=>we,VertexBuffer:()=>Se,VirtualFileSystem:()=>yi,advanceAnimation:()=>Ka,applySurfaceState:()=>Wc,attenuationToDistanceMultiplier:()=>er,boxIntersectsFrustum:()=>jn,buildBspGeometry:()=>Oc,buildMd2Geometry:()=>Qs,buildMd2VertexData:()=>Js,buildMd3SurfaceGeometry:()=>ra,buildMd3VertexData:()=>na,calculateMaxAudibleDistance:()=>ao,calculatePakChecksum:()=>Fa,computeFrameBlend:()=>Ya,computeSkyScroll:()=>Yc,createAnimationState:()=>qa,createAudioGraph:()=>lo,createBspSurfaces:()=>Dc,createEmptyEntityState:()=>rr,createEmptyProtocolPlayerState:()=>Co,createEngine:()=>Wf,createEngineRuntime:()=>Ra,createFaceLightmap:()=>bi,createInitialChannels:()=>mo,createProgramFromSources:()=>Bc,createWebGLContext:()=>Tc,decodeOgg:()=>ro,deriveSurfaceRenderState:()=>Xs,extractFrustumPlanes:()=>Nc,filesToPakSources:()=>as,findLeafForPoint:()=>Hs,gatherVisibleFaces:()=>Vc,groupMd2Animations:()=>Va,ingestPakFiles:()=>Ba,ingestPaks:()=>xi,interpolateMd3Tag:()=>ul,interpolateVec3:()=>$a,parseBsp:()=>cs,parseMd2:()=>ls,parseMd3:()=>ds,parsePcx:()=>Jr,parseSprite:()=>us,parseTga:()=>fs,parseWal:()=>Si,parseWalTexture:()=>Ai,parseWav:()=>wi,pcxToRgba:()=>Mi,pickChannel:()=>ho,preparePcxTexture:()=>_i,removeViewTranslation:()=>Kc,resolveLightStyles:()=>Ws,spatializeOrigin:()=>po,spawnBlood:()=>hl,spawnBulletImpact:()=>fl,spawnExplosion:()=>ml,spawnMuzzleFlash:()=>yl,spawnTeleportFlash:()=>pl,spawnTrail:()=>gl,walToRgba:()=>ms,wireDropTarget:()=>Da,wireFileInput:()=>Oa});var Il=()=>typeof performance<"u"?performance.now():Date.now(),Pl=t=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>t()):setTimeout(t,25)},Dt=class{constructor(e,r={}){this.callbacks=e;this.accumulatorMs=0;this.frame=0;this.running=!1;this.tick=()=>{if(!this.running)return;let e=this.options.now(),r=this.lastTimeMs===void 0?0:e-this.lastTimeMs;this.lastTimeMs=e,this.advance(r,e),this.running&&this.options.schedule(this.tick)};let n=r.fixedDeltaMs??25,i=r.maxSubSteps??5;this.options={fixedDeltaMs:n,maxSubSteps:i,maxDeltaMs:r.maxDeltaMs??n*i,startTimeMs:r.startTimeMs,now:r.now??Il,schedule:r.schedule??Pl}}start(){this.running||(this.running=!0,this.lastTimeMs=this.options.startTimeMs??this.options.now(),this.options.schedule(this.tick))}stop(){this.running=!1}pump(e){let r=(this.lastTimeMs??0)+e;this.lastTimeMs=r,this.advance(e,r)}isRunning(){return this.running}get frameNumber(){return this.frame}advance(e,r){let n=Math.min(Math.max(e,0),this.options.maxDeltaMs);this.accumulatorMs=Math.min(this.accumulatorMs+n,this.options.fixedDeltaMs*this.options.maxSubSteps);let i=0;for(;this.accumulatorMs>=this.options.fixedDeltaMs&&i<this.options.maxSubSteps;)this.frame+=1,this.callbacks.simulate({frame:this.frame,deltaMs:this.options.fixedDeltaMs,nowMs:r}),this.accumulatorMs-=this.options.fixedDeltaMs,i+=1;let o=this.options.fixedDeltaMs===0?0:this.accumulatorMs/this.options.fixedDeltaMs;this.callbacks.render?.({alpha:o,nowMs:r,accumulatorMs:this.accumulatorMs,frame:this.frame})}};var Wr=class{constructor(e,r,n){this.name=e,this.callback=r,this.description=n}execute(e){this.callback(e)}},or=class{constructor(){this.commands=new Map}register(e,r,n){let i=new Wr(e,r,n);return this.commands.set(e,i),i}get(e){return this.commands.get(e)}execute(e){let r=this.tokenize(e);if(r.length===0)return!1;let n=r[0],i=r.slice(1),o=this.get(n);return o?(o.execute(i),!0):!1}tokenize(e){return e.trim().split(/\s+/)}list(){return[...this.commands.values()].sort((e,r)=>e.name.localeCompare(r.name))}};var Cl=Object.defineProperty,ga=(t,e)=>{for(var r in e)Cl(t,r,{get:e[r],enumerable:!0})},xa={x:0,y:0,z:0};var $f=Math.PI/180;function ba(t,e){return{x:t.x-e.x,y:t.y-e.y,z:t.z-e.z}}function zl(t,e){return{x:t.x*e,y:t.y*e,z:t.z*e}}function jo(t,e){return t.x*e.x+t.y*e.y+t.z*e.z}function Rl(t){return jo(t,t)}function Qo(t){return Math.sqrt(Rl(t))}function He(t){let e=Qo(t);return e===0?t:zl(t,1/e)}var Tl=Math.PI/180,jf=180/Math.PI,sr=Tl;var Fl=[[-.525731,0,.850651],[-.442863,.238856,.864188],[-.295242,0,.955423],[-.309017,.5,.809017],[-.16246,.262866,.951056],[0,0,1],[0,.850651,.525731],[-.147621,.716567,.681718],[.147621,.716567,.681718],[0,.525731,.850651],[.309017,.5,.809017],[.525731,0,.850651],[.295242,0,.955423],[.442863,.238856,.864188],[.16246,.262866,.951056],[-.681718,.147621,.716567],[-.809017,.309017,.5],[-.587785,.425325,.688191],[-.850651,.525731,0],[-.864188,.442863,.238856],[-.716567,.681718,.147621],[-.688191,.587785,.425325],[-.5,.809017,.309017],[-.238856,.864188,.442863],[-.425325,.688191,.587785],[-.716567,.681718,-.147621],[-.5,.809017,-.309017],[-.525731,.850651,0],[0,.850651,-.525731],[-.238856,.864188,-.442863],[0,.955423,-.295242],[-.262866,.951056,-.16246],[0,1,0],[0,.955423,.295242],[-.262866,.951056,.16246],[.238856,.864188,.442863],[.262866,.951056,.16246],[.5,.809017,.309017],[.238856,.864188,-.442863],[.262866,.951056,-.16246],[.5,.809017,-.309017],[.850651,.525731,0],[.716567,.681718,.147621],[.716567,.681718,-.147621],[.525731,.850651,0],[.425325,.688191,.587785],[.864188,.442863,.238856],[.688191,.587785,.425325],[.809017,.309017,.5],[.681718,.147621,.716567],[.587785,.425325,.688191],[.955423,.295242,0],[1,0,0],[.951056,.16246,.262866],[.850651,-.525731,0],[.955423,-.295242,0],[.864188,-.442863,.238856],[.951056,-.16246,.262866],[.809017,-.309017,.5],[.681718,-.147621,.716567],[.850651,0,.525731],[.864188,.442863,-.238856],[.809017,.309017,-.5],[.951056,.16246,-.262866],[.525731,0,-.850651],[.681718,.147621,-.716567],[.681718,-.147621,-.716567],[.850651,0,-.525731],[.809017,-.309017,-.5],[.864188,-.442863,-.238856],[.951056,-.16246,-.262866],[.147621,.716567,-.681718],[.309017,.5,-.809017],[.425325,.688191,-.587785],[.442863,.238856,-.864188],[.587785,.425325,-.688191],[.688191,.587785,-.425325],[-.147621,.716567,-.681718],[-.309017,.5,-.809017],[0,.525731,-.850651],[-.525731,0,-.850651],[-.442863,.238856,-.864188],[-.295242,0,-.955423],[-.16246,.262866,-.951056],[0,0,-1],[.295242,0,-.955423],[.16246,.262866,-.951056],[-.442863,-.238856,-.864188],[-.309017,-.5,-.809017],[-.16246,-.262866,-.951056],[0,-.850651,-.525731],[-.147621,-.716567,-.681718],[.147621,-.716567,-.681718],[0,-.525731,-.850651],[.309017,-.5,-.809017],[.442863,-.238856,-.864188],[.16246,-.262866,-.951056],[.238856,-.864188,-.442863],[.5,-.809017,-.309017],[.425325,-.688191,-.587785],[.716567,-.681718,-.147621],[.688191,-.587785,-.425325],[.587785,-.425325,-.688191],[0,-.955423,-.295242],[0,-1,0],[.262866,-.951056,-.16246],[0,-.850651,.525731],[0,-.955423,.295242],[.238856,-.864188,.442863],[.262866,-.951056,.16246],[.5,-.809017,.309017],[.716567,-.681718,.147621],[.525731,-.850651,0],[-.238856,-.864188,-.442863],[-.5,-.809017,-.309017],[-.262866,-.951056,-.16246],[-.850651,-.525731,0],[-.716567,-.681718,-.147621],[-.716567,-.681718,.147621],[-.525731,-.850651,0],[-.5,-.809017,.309017],[-.238856,-.864188,.442863],[-.262866,-.951056,.16246],[-.864188,-.442863,.238856],[-.809017,-.309017,.5],[-.688191,-.587785,.425325],[-.681718,-.147621,.716567],[-.442863,-.238856,.864188],[-.587785,-.425325,.688191],[-.309017,-.5,.809017],[-.147621,-.716567,.681718],[-.425325,-.688191,.587785],[-.16246,-.262866,.951056],[.442863,-.238856,.864188],[.16246,-.262866,.951056],[.309017,-.5,.809017],[.147621,-.716567,.681718],[0,-.525731,.850651],[.425325,-.688191,.587785],[.587785,-.425325,.688191],[.688191,-.587785,.425325],[-.955423,.295242,0],[-.951056,.16246,.262866],[-1,0,0],[-.850651,0,.525731],[-.955423,-.295242,0],[-.951056,-.16246,.262866],[-.864188,.442863,-.238856],[-.951056,.16246,-.262866],[-.809017,.309017,-.5],[-.864188,-.442863,-.238856],[-.951056,-.16246,-.262866],[-.809017,-.309017,-.5],[-.681718,.147621,-.716567],[-.681718,-.147621,-.716567],[-.850651,0,-.525731],[-.688191,.587785,-.425325],[-.587785,.425325,-.688191],[-.425325,.688191,-.587785],[-.425325,-.688191,-.587785],[-.587785,-.425325,-.688191],[-.688191,-.587785,-.425325]];function Bl(){return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function va(t,e){let r=e.x,n=e.y,i=e.z;return{x:t[0]*r+t[4]*n+t[8]*i+t[12],y:t[1]*r+t[5]*n+t[9]*i+t[13],z:t[2]*r+t[6]*n+t[10]*i+t[14]}}function Sa(t,e){let r=Bl();return r[0]=e[0].x,r[1]=e[0].y,r[2]=e[0].z,r[4]=e[1].x,r[5]=e[1].y,r[6]=e[1].z,r[8]=e[2].x,r[9]=e[2].y,r[10]=e[2].z,r[12]=t.x,r[13]=t.y,r[14]=t.z,r}var Ke=1,mt=2;var Jo=8,Zo=16,Dl=32;var Ol=16384;var di=65536,Ma=1<<17,Nl=1<<18,kl=1<<19,Ul=1<<20,Hl=1<<21,Vl=1<<22,Gl=1<<23,Qf=1<<24,ui=1<<25,Wl=1<<26,Jf=1<<27,Zf=1<<28,em=1<<29,fi=1<<30,tm=1<<31;var Kr=0;var _a=4,Aa=8,wa=16,La=32,Ea=64;var rm=1<<25,nm=1<<28,im=1<<29,om=1<<30,sm=1<<31;var am=Ke|mt,cm=Ke|di|mt|ui|fi,lm=Ke|di|mt,dm=Ke|Ma|mt|ui|fi,um=Dl|Jo|Zo,fm=Ke|Zo|Jo,Xl=Ke|ui|fi|mt|Wl,mm=Nl|kl|Ul|Hl|Vl|Gl,hm=Ke|Jo|Zo|ui|fi,pm=Ke|di|mt,ym=Ke|mt,gm=Ke|di|mt|Ma,xm=Xl|Ol;var bm=Number.MAX_SAFE_INTEGER-1;var mi=(t=>(t[t.None=0]="None",t[t.Archive=1]="Archive",t[t.UserInfo=2]="UserInfo",t[t.ServerInfo=4]="ServerInfo",t[t.Latch=8]="Latch",t[t.Cheat=16]="Cheat",t))(mi||{});var hi=256;var es=256,ts=8192,pi=2048,rs=512,ns=256,is=hi*2,os=256,$o=32,Xr=96;var Y=(t=>(t[t.Name=0]="Name",t[t.CdTrack=1]="CdTrack",t[t.Sky=2]="Sky",t[t.SkyAxis=3]="SkyAxis",t[t.SkyRotate=4]="SkyRotate",t[t.StatusBar=5]="StatusBar",t[t.AirAccel=59]="AirAccel",t[t.MaxClients=60]="MaxClients",t[t.MapChecksum=61]="MapChecksum",t[t.Models=62]="Models",t[t.Sounds=62+ts]="Sounds",t[t.Images=t.Sounds+pi]="Images",t[t.Lights=t.Images+rs]="Lights",t[t.ShadowLights=t.Lights+es]="ShadowLights",t[t.Items=t.ShadowLights+os]="Items",t[t.PlayerSkins=t.Items+ns]="PlayerSkins",t[t.General=t.PlayerSkins+hi]="General",t[t.WheelWeapons=t.General+is]="WheelWeapons",t[t.WheelAmmo=t.WheelWeapons+$o]="WheelAmmo",t[t.WheelPowerups=t.WheelAmmo+$o]="WheelPowerups",t[t.CdLoopCount=t.WheelPowerups+$o]="CdLoopCount",t[t.GameStyle=t.CdLoopCount+1]="GameStyle",t[t.MaxConfigStrings=t.GameStyle+1]="MaxConfigStrings",t))(Y||{}),Ia=Y.MaxConfigStrings;function Pa(t){return t>=5&&t<59?Xr*(59-t):t>=Y.General&&t<Y.WheelWeapons?Xr*(Y.MaxConfigStrings-t):Xr}var Kl={};ga(Kl,{addReplayFrame:()=>jl,createReplaySession:()=>$l,deserializeReplay:()=>ql,serializeReplay:()=>Yl});function Yl(t){return JSON.stringify(t,null,2)}function ql(t){let e=JSON.parse(t);if(!e.metadata||!Array.isArray(e.frames))throw new Error("Invalid replay format: missing metadata or frames");return e}function $l(t,e){return{metadata:{map:t,date:new Date().toISOString(),version:"1.0",seed:e},frames:[]}}function jl(t,e,r,n){t.frames.push({serverFrame:r,cmd:e,timestamp:Date.now()-n})}var U=(t=>(t[t.bad=0]="bad",t[t.muzzleflash=1]="muzzleflash",t[t.muzzleflash2=2]="muzzleflash2",t[t.temp_entity=3]="temp_entity",t[t.layout=4]="layout",t[t.inventory=5]="inventory",t[t.nop=6]="nop",t[t.disconnect=7]="disconnect",t[t.reconnect=8]="reconnect",t[t.sound=9]="sound",t[t.print=10]="print",t[t.stufftext=11]="stufftext",t[t.serverdata=12]="serverdata",t[t.configstring=13]="configstring",t[t.spawnbaseline=14]="spawnbaseline",t[t.centerprint=15]="centerprint",t[t.download=16]="download",t[t.playerinfo=17]="playerinfo",t[t.packetentities=18]="packetentities",t[t.deltapacketentities=19]="deltapacketentities",t[t.frame=20]="frame",t))(U||{});var E=(t=>(t[t.GUNSHOT=0]="GUNSHOT",t[t.BLOOD=1]="BLOOD",t[t.BLASTER=2]="BLASTER",t[t.RAILTRAIL=3]="RAILTRAIL",t[t.SHOTGUN=4]="SHOTGUN",t[t.EXPLOSION1=5]="EXPLOSION1",t[t.EXPLOSION2=6]="EXPLOSION2",t[t.ROCKET_EXPLOSION=7]="ROCKET_EXPLOSION",t[t.GRENADE_EXPLOSION=8]="GRENADE_EXPLOSION",t[t.SPARKS=9]="SPARKS",t[t.SPLASH=10]="SPLASH",t[t.BUBBLETRAIL=11]="BUBBLETRAIL",t[t.SCREEN_SPARKS=12]="SCREEN_SPARKS",t[t.SHIELD_SPARKS=13]="SHIELD_SPARKS",t[t.BULLET_SPARKS=14]="BULLET_SPARKS",t[t.LASER_SPARKS=15]="LASER_SPARKS",t[t.PARASITE_ATTACK=16]="PARASITE_ATTACK",t[t.ROCKET_EXPLOSION_WATER=17]="ROCKET_EXPLOSION_WATER",t[t.GRENADE_EXPLOSION_WATER=18]="GRENADE_EXPLOSION_WATER",t[t.MEDIC_CABLE_ATTACK=19]="MEDIC_CABLE_ATTACK",t[t.BFG_EXPLOSION=20]="BFG_EXPLOSION",t[t.BFG_BIGEXPLOSION=21]="BFG_BIGEXPLOSION",t[t.BOSSTPORT=22]="BOSSTPORT",t[t.BFG_LASER=23]="BFG_LASER",t[t.GRAPPLE_CABLE=24]="GRAPPLE_CABLE",t[t.WELDING_SPARKS=25]="WELDING_SPARKS",t[t.GREENBLOOD=26]="GREENBLOOD",t[t.BLUEHYPERBLASTER=27]="BLUEHYPERBLASTER",t[t.PLASMA_EXPLOSION=28]="PLASMA_EXPLOSION",t[t.TUNNEL_SPARKS=29]="TUNNEL_SPARKS",t[t.BLASTER2=30]="BLASTER2",t[t.RAILTRAIL2=31]="RAILTRAIL2",t[t.FLAME=32]="FLAME",t[t.LIGHTNING=33]="LIGHTNING",t[t.DEBUGTRAIL=34]="DEBUGTRAIL",t[t.PLAIN_EXPLOSION=35]="PLAIN_EXPLOSION",t[t.FLASHLIGHT=36]="FLASHLIGHT",t[t.FORCEWALL=37]="FORCEWALL",t[t.HEATBEAM=38]="HEATBEAM",t[t.MONSTER_HEATBEAM=39]="MONSTER_HEATBEAM",t[t.STEAM=40]="STEAM",t[t.BUBBLETRAIL2=41]="BUBBLETRAIL2",t[t.MOREBLOOD=42]="MOREBLOOD",t[t.HEATBEAM_SPARKS=43]="HEATBEAM_SPARKS",t[t.HEATBEAM_STEAM=44]="HEATBEAM_STEAM",t[t.CHAINFIST_SMOKE=45]="CHAINFIST_SMOKE",t[t.ELECTRIC_SPARKS=46]="ELECTRIC_SPARKS",t[t.TRACKER_EXPLOSION=47]="TRACKER_EXPLOSION",t[t.TELEPORT_EFFECT=48]="TELEPORT_EFFECT",t[t.DBALL_GOAL=49]="DBALL_GOAL",t[t.WIDOWBEAMOUT=50]="WIDOWBEAMOUT",t[t.NUKEBLAST=51]="NUKEBLAST",t[t.WIDOWSPLASH=52]="WIDOWSPLASH",t[t.EXPLOSION1_BIG=53]="EXPLOSION1_BIG",t[t.EXPLOSION1_NP=54]="EXPLOSION1_NP",t[t.FLECHETTE=55]="FLECHETTE",t[t.BLUEHYPERBLASTER_KEX=56]="BLUEHYPERBLASTER_KEX",t[t.BFG_ZAP=57]="BFG_ZAP",t[t.BERSERK_SLAM=58]="BERSERK_SLAM",t[t.GRAPPLE_CABLE_2=59]="GRAPPLE_CABLE_2",t[t.POWER_SPLASH=60]="POWER_SPLASH",t[t.LIGHTNING_BEAM=61]="LIGHTNING_BEAM",t[t.EXPLOSION1_NL=62]="EXPLOSION1_NL",t[t.EXPLOSION2_NL=63]="EXPLOSION2_NL",t))(E||{}),Ql={};ga(Ql,{U_ANGLE1:()=>id,U_ANGLE2:()=>od,U_ANGLE3:()=>sd,U_EFFECTS:()=>ld,U_EVENT:()=>fd,U_FRAME:()=>ad,U_MODEL:()=>Zl,U_MODEL2:()=>hd,U_MODEL3:()=>pd,U_MODEL4:()=>yd,U_MOREBITS:()=>md,U_NUMBER:()=>Jl,U_ORIGIN1:()=>td,U_ORIGIN2:()=>rd,U_ORIGIN3:()=>nd,U_REMOVE:()=>gd,U_RENDERFX:()=>dd,U_SKIN:()=>cd,U_SOLID:()=>ud,U_SOUND:()=>ed});var Jl=1,Zl=2,ed=4,td=8,rd=16,nd=32,id=64,od=128,sd=256,ad=512,cd=1024,ld=2048,dd=4096,ud=8192,fd=16384,md=32768,hd=1,pd=2,yd=4,gd=32768;var Ca=class{constructor(t){t instanceof Uint8Array?this.view=new DataView(t.buffer,t.byteOffset,t.byteLength):this.view=new DataView(t),this.offset=0,this.length=this.view.byteLength}getPosition(){return this.offset}seek(t){if(t<0||t>this.length)throw new Error(`Seek out of bounds: ${t} (length: ${this.length})`);this.offset=t}hasMore(){return this.offset<this.length}readChar(){let t=this.view.getInt8(this.offset);return this.offset+=1,t}readByte(){let t=this.view.getUint8(this.offset);return this.offset+=1,t}readShort(){let t=this.view.getInt16(this.offset,!0);return this.offset+=2,t}readLong(){let t=this.view.getInt32(this.offset,!0);return this.offset+=4,t}readFloat(){let t=this.view.getFloat32(this.offset,!0);return this.offset+=4,t}readString(){let t="";for(;this.offset<this.length;){let e=this.readChar();if(e===-1||e===0)break;t+=String.fromCharCode(e)}return t}readStringLine(){let t="";for(;this.offset<this.length;){let e=this.readChar();if(e===-1||e===0||e===10)break;t+=String.fromCharCode(e)}return t}readCoord(){return this.readShort()*(1/8)}readAngle(){return this.readChar()*(360/256)}readAngle16(){return this.readShort()*360/65536}readData(t){if(this.offset+t>this.length)throw new Error(`Read out of bounds: ${this.offset+t} (length: ${this.length})`);let e=new Uint8Array(this.view.buffer,this.view.byteOffset+this.offset,t);return this.offset+=t,new Uint8Array(e)}readPos(t){t.x=this.readCoord(),t.y=this.readCoord(),t.z=this.readCoord()}readDir(t){let e=this.readByte();if(e>=162){t.x=0,t.y=0,t.z=0;return}let r=Fl[e];t.x=r[0],t.y=r[1],t.z=r[2]}};var Yr=class{constructor({name:e,defaultValue:r,description:n,flags:i=mi.None,onChange:o}){this.modifiedCount=0;this.name=e,this.defaultValue=r,this.description=n,this.flags=i,this._value=r,this.onChange=o}get string(){return this._value}get number(){return Number(this._value)}get integer(){return Math.trunc(this.number)}get boolean(){return!!this.integer}set(e){if(this.flags&mi.Latch){if(e===this._value){this.latched=void 0;return}if(this.latched===e)return;this.latched!==e&&(this.latched=e);return}this.apply(e)}reset(){this.latched=void 0,this.apply(this.defaultValue)}applyLatched(){if(this.latched===void 0)return!1;let e=this.latched;return this.latched=void 0,e===this._value?!1:(this.apply(e),!0)}apply(e){if(this._value===e)return;let r=this._value;this._value=e,this.modifiedCount+=1,this.onChange?.(this,r)}},ar=class{constructor(){this.cvars=new Map}register(e){let r=this.cvars.get(e.name);if(r)return r;let n=new Yr(e);return this.cvars.set(e.name,n),n}get(e){return this.cvars.get(e)}setValue(e,r){let n=this.get(e);if(!n)throw new Error(`Unknown cvar: ${e}`);return n.set(r),n}resetAll(){for(let e of this.cvars.values())e.reset()}applyLatched(){let e=!1;for(let r of this.cvars.values())e=r.applyLatched()||e;return e}list(){return[...this.cvars.values()].sort((e,r)=>e.name.localeCompare(r.name))}};var cr=class{constructor(e,r,n={}){this.game=e;this.client=r;this.started=!1;this.commands=new or;this.cvars=new ar;this.stepSimulation=e=>{this.previousFrame=this.latestFrame,this.latestFrame=this.game.frame(e,this.latestCommand)};this.renderClient=e=>{this.client&&(this.latestCommand=this.client.render({...e,previous:this.previousFrame,latest:this.latestFrame}))};let i=n.loop?.now?.()??Date.now();this.startTimeMs=n.startTimeMs??n.loop?.startTimeMs??i,this.loop=new Dt({simulate:this.stepSimulation,render:this.renderClient},{...n.loop,startTimeMs:this.startTimeMs})}start(){if(!this.started){try{this.latestFrame=this.game.init(this.startTimeMs)??this.latestFrame,this.client?.init(this.latestFrame)}catch(e){throw this.game.shutdown(),this.client?.shutdown(),e}this.started=!0,this.loop.start()}}stop(){this.started&&(this.loop.stop(),this.client?.shutdown(),this.game.shutdown(),this.previousFrame=void 0,this.latestFrame=void 0,this.started=!1)}pump(e){this.loop.pump(e)}getLatestFrame(){return this.latestFrame}isRunning(){return this.loop.isRunning()}};function xd(t){if(t<0||t>=Y.MaxConfigStrings)throw new RangeError(`Configstring index ${t} is out of range (0-${Y.MaxConfigStrings-1})`)}function za(t,e){let r=Pa(t);if(e.length>r)throw new RangeError(`Configstring ${t} exceeds maximum length (${e.length} > ${r}); limit is ${Xr} chars per slot`)}var lr=class{constructor(){this.values=new Map;this.modelCursor=Y.Models;this.soundCursor=Y.Sounds;this.imageCursor=Y.Images;this.lightCursor=Y.Lights;this.shadowLightCursor=Y.ShadowLights;this.itemCursor=Y.Items;this.playerSkinCursor=Y.PlayerSkins;this.generalCursor=Y.General}set(e,r){return xd(e),za(e,r),this.values.set(e,r),e}get(e){return this.values.get(e)}getName(e){return this.get(e)}getAll(){let e=new Array(Ia).fill("");for(let[r,n]of this.values.entries())e[r]=n;return e}modelIndex(e){return this.register(e,Y.Models,ts,"modelCursor")}soundIndex(e){return this.register(e,Y.Sounds,pi,"soundCursor")}findSoundIndex(e){for(let r=Y.Sounds;r<Y.Sounds+pi;r+=1)if(this.values.get(r)===e)return r}imageIndex(e){return this.register(e,Y.Images,rs,"imageCursor")}lightIndex(e){return this.register(e,Y.Lights,es,"lightCursor")}shadowLightIndex(e){return this.register(e,Y.ShadowLights,os,"shadowLightCursor")}itemIndex(e){return this.register(e,Y.Items,ns,"itemCursor")}playerSkinIndex(e){return this.register(e,Y.PlayerSkins,hi,"playerSkinCursor")}generalIndex(e){return this.register(e,Y.General,is,"generalCursor")}register(e,r,n,i){for(let a=r;a<r+n;a+=1)if(this.values.get(a)===e)return a;let o=this[i],s=r+n;if(o>=s)throw new RangeError(`Out of configstring slots for range starting at ${r}`);return za(o,e),this.values.set(o,e),this[i]=o+1,o}};var dr=class{constructor(e){this.registry=e.registry,this.system=e.system,this.music=e.music,this.client=e.client}soundindex(e){return this.registry.registerName(e)}sound(e,r,n,i,o,s){this.system.play({entity:e,channel:r,soundIndex:n,volume:i,attenuation:o,timeOffsetMs:s}),this.triggerSubtitle(n)}positioned_sound(e,r,n,i){this.system.positionedSound(e,r,n,i),this.triggerSubtitle(r)}loop_sound(e,r,n,i,o){this.system.play({entity:e,channel:r,soundIndex:n,volume:i,attenuation:o,looping:!0}),this.triggerSubtitle(n)}stop_entity_sounds(e){this.system.stopEntitySounds(e)}set_listener(e){this.system.setListener(e)}play_music(e,r=!0){return this.music?this.music.play(e,{loop:r}):Promise.resolve()}pause_music(){this.music?.pause()}resume_music(){return this.music?.resume()??Promise.resolve()}stop_music(){this.music?.stop()}set_music_volume(e){this.music?.setVolume(e)}play_ambient(e,r,n){this.system.ambientSound(e,r,n),this.triggerSubtitle(r)}play_channel(e){this.system.play({...e}),this.triggerSubtitle(e.soundIndex)}triggerSubtitle(e){if(!this.client)return;let r=this.registry.getName(e);if(!r)return;let n=r.match(/\[(.*?)\]/);n&&this.client.showSubtitle(n[1],r)}};var qr=class{constructor(e,r){this.engine=e;this.host=r;this.started=!1}start(){this.started||(this.engine.init(),this.host.start(),this.started=!0)}stop(){this.started&&(this.host.stop(),this.engine.shutdown(),this.started=!1)}pump(e){this.host.pump(e)}getLatestFrame(){return this.host.getLatestFrame()}isRunning(){return this.started&&this.host.isRunning()}};function Ra(t,e,r,n,i){let o=new dr({...n,client:r}),s=new cr(e,r,i);return{runtime:new qr(t,s),audio:o}}var bd="PACK";function vd(t,e,r){let n=[];for(let i=0;i<r;i+=1){let o=t.getUint8(e+i);if(o===0)break;n.push(o)}return String.fromCharCode(...n)}function ie(t){return t.replace(/\\/g,"/").replace(/^\/+/,"").toLowerCase()}function Sd(){let t=new Uint32Array(256);for(let e=0;e<256;e+=1){let r=e;for(let n=0;n<8;n+=1)r=(r&1)!==0?3988292384^r>>>1:r>>>1;t[e]=r>>>0}return t}var Md=Sd();function Ta(t){let e=4294967295;for(let r=0;r<t.length;r+=1){let n=t[r];e=Md[(e^n)&255]^e>>>8}return(e^4294967295)>>>0}var Re=class extends Error{},ur=class t{constructor(e,r,n,i){this.name=e;this.buffer=r;this.entries=new Map(n.map(o=>[o.name,o])),this.checksum=i,this.size=r.byteLength}static fromArrayBuffer(e,r){let n=new DataView(r);if(r.byteLength<12)throw new Re("PAK buffer too small to contain header");let i=String.fromCharCode(n.getUint8(0),n.getUint8(1),n.getUint8(2),n.getUint8(3));if(i!==bd)throw new Re(`Invalid PAK header magic: ${i}`);let o=n.getInt32(4,!0),s=n.getInt32(8,!0);if(o<12)throw new Re(`Invalid directory offset: ${o}`);if(s<=0||s%64!==0)throw new Re(`Invalid directory length: ${s}`);if(o+s>r.byteLength)throw new Re("Directory exceeds buffer length");let c=s/64,l=[],d=new Map;for(let u=0;u<c;u+=1){let f=o+u*64,m=vd(n,f,56),p=ie(m),y=n.getInt32(f+56,!0),h=n.getInt32(f+60,!0);if(y<0||h<0||y+h>r.byteLength)throw new Re(`Invalid entry bounds for ${m||"<unnamed>"} (offset=${y}, length=${h})`);if(!p)throw new Re(`Entry ${u} has an empty name`);let g={name:p,offset:y,length:h};d.set(p,g)}return l.push(...d.values()),new t(e,r,l,Ta(new Uint8Array(r)))}getEntry(e){return this.entries.get(ie(e))}listEntries(){return Array.from(this.entries.values())}readFile(e){let r=this.getEntry(e);if(!r)throw new Re(`File not found in PAK: ${e}`);return new Uint8Array(this.buffer,r.offset,r.length)}validate(){return{checksum:this.checksum,entries:this.listEntries()}}};function Fa(t){return Ta(new Uint8Array(t))}var yi=class{constructor(e=[]){this.mounts=[];this.files=new Map;e.forEach(r=>this.mountPak(r))}mountPak(e){this.mounts.push(e);for(let r of e.listEntries()){let n=ie(r.name);this.files.set(n,{archive:e,entry:r})}}get mountedPaks(){return[...this.mounts]}hasFile(e){return this.files.has(ie(e))}stat(e){let r=this.files.get(ie(e));if(r)return{path:r.entry.name,size:r.entry.length,sourcePak:r.archive.name}}async readFile(e){let r=this.files.get(ie(e));if(!r)throw new Error(`File not found in VFS: ${e}`);return r.archive.readFile(e)}list(e=""){let r=ie(e).replace(/\/+$|^\//g,""),n=[],i=new Set,o=r?`${r}/`:"";for(let s of this.files.values()){if(r&&!s.entry.name.startsWith(o))continue;let a=r?s.entry.name.slice(o.length):s.entry.name,c=a.indexOf("/");c===-1?n.push({path:s.entry.name,size:s.entry.length,sourcePak:s.archive.name}):i.add(a.slice(0,c))}return n.sort((s,a)=>s.path.localeCompare(a.path)),{files:n,directories:[...i].sort()}}findByExtension(e){let r=e.startsWith(".")?e.toLowerCase():`.${e.toLowerCase()}`,n=[];for(let i of this.files.values())i.entry.name.toLowerCase().endsWith(r)&&n.push({path:i.entry.name,size:i.entry.length,sourcePak:i.archive.name});return n.sort((i,o)=>i.path.localeCompare(o.path))}};var ss=Object.freeze([{name:"pak0.pak",checksum:2378051181,description:"Base game assets"},{name:"pak0.pak@baseq2",checksum:2378051181,description:"Base game assets (baseq2)"},{name:"pak0.pak@rogue",checksum:3373211245,description:"Ground Zero (rogue) mission pack"},{name:"pak0.pak@xatrix",checksum:1358269824,description:"The Reckoning (xatrix) mission pack"}]),Ot=class extends Error{constructor(r){super(r.status==="unknown"?`Unknown PAK not allowed: ${r.name}`:`PAK checksum mismatch for ${r.name}`);this.result=r;this.name="PakValidationError"}},gi=class{constructor(e=ss){this.known=new Map;e.forEach(r=>this.known.set(this.normalizePakName(r.name),r))}validateArchive(e,r){let n=this.normalizePakName(r??("name"in e?e.name:"unknown")),i=e.checksum,o="size"in e?e.size:void 0,s=this.known.get(n);return s?s.checksum!==i?{name:n,checksum:i,expectedChecksum:s.checksum,status:"mismatch",size:o,description:s.description}:{name:n,checksum:i,expectedChecksum:s.checksum,status:"valid",size:o,description:s.description}:{name:n,checksum:i,status:"unknown",size:o}}assertValid(e,r){let n=this.validateArchive(e,r);if(n.status==="mismatch")throw new Ot(n);return n}normalizePakName(e){let r=ie(e),n=r.split("/"),i=n.pop()??r,o=n.pop();return o?`${i}@${o}`:i}};var ht=class extends Error{constructor(r,n){super(`Failed to ingest PAK: ${r}`);this.file=r;this.name="PakIngestionError",n instanceof Error&&n.stack&&(this.stack=n.stack),this.cause=n}};async function _d(t,e){if(typeof t.arrayBuffer=="function"){let r=await t.arrayBuffer();return e?.({file:"blob",loadedBytes:r.byteLength,totalBytes:r.byteLength,state:"reading"}),r}if(typeof FileReader<"u")return new Promise((r,n)=>{let i=new FileReader;i.onerror=()=>n(i.error??new Error("Unknown FileReader error")),i.onprogress=o=>{e?.({file:"blob",loadedBytes:o.loaded,totalBytes:o.total||t.size,state:"reading"})},i.onload=()=>{let o=i.result;o instanceof ArrayBuffer?r(o):n(new Error("Unexpected FileReader result"))},i.readAsArrayBuffer(t)});if(typeof Response<"u"){let r=await new Response(t).arrayBuffer();return e?.({file:"blob",loadedBytes:r.byteLength,totalBytes:r.byteLength,state:"reading"}),r}if(typeof t.stream=="function"){let r=t.stream().getReader(),n=[],i=0;for(;;){let{done:a,value:c}=await r.read();if(a)break;if(!c)continue;let l=c;n.push(l),i+=l.byteLength,e?.({file:"blob",loadedBytes:i,totalBytes:t.size,state:"reading"})}let o=new Uint8Array(i),s=0;for(let a of n)o.set(a,s),s+=a.byteLength;return o.buffer}throw new ht("blob",new Error("Unsupported Blob type"))}async function Ad(t,e){if(t.data instanceof ArrayBuffer)return e?.({file:t.name,loadedBytes:t.data.byteLength,totalBytes:t.data.byteLength,state:"reading"}),t.data;if(t.data instanceof Blob){let n=t.data.size;return _d(t.data,i=>e?.({...i,file:t.name,totalBytes:n}))}let r=t.data.buffer.slice(t.data.byteOffset,t.data.byteOffset+t.data.byteLength);return e?.({file:t.name,loadedBytes:r.byteLength,totalBytes:r.byteLength,state:"reading"}),r}async function xi(t,e,r){let n=typeof r=="function"?{onProgress:r}:r??{},i=n.persistIndexes??!!n.pakIndexStore,o=n.enforceValidation??!!n.validator,s=n.allowUnknownPaks??!0,a=n.stopOnError??!1,c=[];for(let l of e)try{let d=await Ad(l,n.onProgress),u=ur.fromArrayBuffer(l.name,d),f=n.validator?.validateArchive(u);if(f){n.onValidationResult?.(f);let m=f.status==="mismatch",p=f.status==="unknown";if(m&&o||p&&!s){let y=new Ot(f);if(n.onError?.(l.name,y),a)throw new ht(l.name,y);c.push({archive:u,mounted:!1,validation:f});continue}}if(t.mountPak(u),i&&n.pakIndexStore)try{await n.pakIndexStore.persist(u)}catch(m){if(n.onError?.(l.name,m),a)throw new ht(l.name,m)}n.onProgress?.({file:l.name,loadedBytes:d.byteLength,totalBytes:d.byteLength,state:"parsed"}),c.push({archive:u,mounted:!0,validation:f})}catch(d){if(n.onProgress?.({file:l.name,loadedBytes:0,totalBytes:0,state:"error"}),n.onError?.(l.name,d),a)throw new ht(l.name,d)}return c}var pt=class{constructor(e){this.capacity=e;this.map=new Map;if(e<=0)throw new RangeError("LRU cache capacity must be greater than zero")}get size(){return this.map.size}has(e){return this.map.has(e)}get(e){let r=this.map.get(e);if(r!==void 0)return this.map.delete(e),this.map.set(e,r),r}set(e,r){if(this.map.has(e)&&this.map.delete(e),this.map.set(e,r),this.map.size>this.capacity){let n=this.map.keys().next();n.done||this.map.delete(n.value)}}delete(e){return this.map.delete(e)}clear(){this.map.clear()}entries(){return Array.from(this.map.entries()).reverse().map(([e,r])=>({key:e,value:r}))}};function wd(t){return Array.isArray(t)?t:Array.from(t)}function as(t){return wd(t).map(e=>({name:e.name,data:e}))}async function Ba(t,e,r){let n=as(e);return xi(t,n,r??{})}function Da(t,e){let r=i=>{i.preventDefault(),i.dataTransfer?.dropEffect&&(i.dataTransfer.dropEffect="copy")},n=i=>{i.preventDefault();let o=i.dataTransfer?.files;o&&o.length>0&&e(Array.from(o))};return t.addEventListener("dragover",r),t.addEventListener("drop",n),()=>{t.removeEventListener("dragover",r),t.removeEventListener("drop",n)}}function Oa(t,e){let r=n=>{let i=n.target;!i||!i.files||i.files.length===0||(e(i.files),i.value="")};return t.addEventListener("change",r),()=>t.removeEventListener("change",r)}var Ld="IBSP",Ed=38,ka=19,Id=8+ka*8;var q=class extends Error{},fr=class{constructor(e){this.vfs=e}async load(e){let r=await this.vfs.readFile(e),n=new Uint8Array(r.byteLength);return n.set(r),cs(n.buffer)}};function cs(t){if(t.byteLength<Id)throw new q("BSP too small to contain header");let e=new DataView(t),r=String.fromCharCode(e.getUint8(0),e.getUint8(1),e.getUint8(2),e.getUint8(3));if(r!==Ld)throw new q(`Invalid BSP magic ${r}`);let n=e.getInt32(4,!0);if(n!==Ed)throw new q(`Unsupported BSP version ${n}`);let i=new Map;for(let S=0;S<ka;S+=1){let A=e.getInt32(8+S*8,!0),w=e.getInt32(12+S*8,!0);if(A<0||w<0||A+w>t.byteLength)throw new q(`Invalid lump bounds for index ${S}`);i.set(S,{offset:A,length:w})}let o={version:n,lumps:i},s=Pd(t,i.get(0)),a=zd(t,i.get(1)),c=Rd(t,i.get(2)),l=Td(t,i.get(4)),d=Fd(t,i.get(5)),u=Bd(t,i.get(6)),f=new Uint8Array(t,i.get(7).offset,i.get(7).length),m=Wd(u,i.get(7)),p=Dd(t,i.get(8)),y=Od(t,i.get(11)),h=Nd(t,i.get(12)),g=kd(t,i.get(13)),M=Ud(t,i.get(14)),x=Hd(t,i.get(15)),v=Vd(t,i.get(9),i.get(10),p),b=Gd(t,i.get(3));return{header:o,entities:s,planes:a,vertices:c,nodes:l,texInfo:d,faces:u,lightMaps:f,lightMapInfo:m,leafs:p,leafLists:v,edges:y,surfEdges:h,models:g,brushes:M,brushSides:x,visibility:b}}function Pd(t,e){let r=new TextDecoder().decode(new Uint8Array(t,e.offset,e.length)),n=Cd(r),i=n.find(o=>o.classname==="worldspawn");return{raw:r,entities:n,worldspawn:i}}function Cd(t){let e=[],r=/\{([^}]*)\}/gms,n;for(;(n=r.exec(t))!==null;){let i=n[1],o={},s=/"([^\"]*)"\s+"([^\"]*)"/g,a;for(;(a=s.exec(i))!==null;)o[a[1]]=a[2];e.push({classname:o.classname,properties:o})}return e}function zd(t,e){let r=new DataView(t,e.offset,e.length),n=e.length/20;if(n%1!==0)throw new q("Plane lump has invalid length");let i=[];for(let o=0;o<n;o+=1){let s=[r.getFloat32(o*20,!0),r.getFloat32(o*20+4,!0),r.getFloat32(o*20+8,!0)],a=r.getFloat32(o*20+12,!0),c=r.getInt32(o*20+16,!0);i.push({normal:s,dist:a,type:c})}return i}function Rd(t,e){let r=new DataView(t,e.offset,e.length),n=e.length/12;if(n%1!==0)throw new q("Vertex lump has invalid length");let i=[];for(let o=0;o<n;o+=1)i.push([r.getFloat32(o*12,!0),r.getFloat32(o*12+4,!0),r.getFloat32(o*12+8,!0)]);return i}function Td(t,e){let r=new DataView(t,e.offset,e.length),n=28,i=e.length/n;if(i%1!==0)throw new q("Node lump has invalid length");let o=[];for(let s=0;s<i;s+=1){let a=s*n,c=r.getInt32(a,!0),l=[r.getInt32(a+4,!0),r.getInt32(a+8,!0)],d=[r.getInt16(a+12,!0),r.getInt16(a+14,!0),r.getInt16(a+16,!0)],u=[r.getInt16(a+18,!0),r.getInt16(a+20,!0),r.getInt16(a+22,!0)],f=r.getUint16(a+24,!0),m=r.getUint16(a+26,!0);o.push({planeIndex:c,children:l,mins:d,maxs:u,firstFace:f,numFaces:m})}return o}function Fd(t,e){let r=new DataView(t,e.offset,e.length),n=76,i=e.length/n;if(i%1!==0)throw new q("TexInfo lump has invalid length");let o=[];for(let s=0;s<i;s+=1){let a=s*n,c=[r.getFloat32(a,!0),r.getFloat32(a+4,!0),r.getFloat32(a+8,!0)],l=r.getFloat32(a+12,!0),d=[r.getFloat32(a+16,!0),r.getFloat32(a+20,!0),r.getFloat32(a+24,!0)],u=r.getFloat32(a+28,!0),f=r.getInt32(a+32,!0),m=r.getInt32(a+36,!0),p=new Uint8Array(t,e.offset+a+40,32),y=new TextDecoder("utf-8").decode(p).replace(/\0.*$/,""),h=r.getInt32(a+72,!0);o.push({s:c,sOffset:l,t:d,tOffset:u,flags:f,value:m,texture:y,nextTexInfo:h})}return o}function Bd(t,e){let r=new DataView(t,e.offset,e.length),n=20,i=e.length/n;if(i%1!==0)throw new q("Face lump has invalid length");let o=[];for(let s=0;s<i;s+=1){let a=s*n,c=r.getUint16(a,!0),l=r.getInt16(a+2,!0),d=r.getInt32(a+4,!0),u=r.getInt16(a+8,!0),f=r.getInt16(a+10,!0),m=[r.getUint8(a+12),r.getUint8(a+13),r.getUint8(a+14),r.getUint8(a+15)],p=r.getInt32(a+16,!0);o.push({planeIndex:c,side:l,firstEdge:d,numEdges:u,texInfo:f,styles:m,lightOffset:p})}return o}function Dd(t,e){let r=new DataView(t,e.offset,e.length),n=28,i=e.length/n;if(i%1!==0)throw new q("Leaf lump has invalid length");let o=[];for(let s=0;s<i;s+=1){let a=s*n,c=r.getInt32(a,!0),l=r.getInt16(a+4,!0),d=r.getInt16(a+6,!0),u=[r.getInt16(a+8,!0),r.getInt16(a+10,!0),r.getInt16(a+12,!0)],f=[r.getInt16(a+14,!0),r.getInt16(a+16,!0),r.getInt16(a+18,!0)],m=r.getUint16(a+20,!0),p=r.getUint16(a+22,!0),y=r.getUint16(a+24,!0),h=r.getUint16(a+26,!0);o.push({contents:c,cluster:l,area:d,mins:u,maxs:f,firstLeafFace:m,numLeafFaces:p,firstLeafBrush:y,numLeafBrushes:h})}return o}function Od(t,e){let r=new DataView(t,e.offset,e.length),n=4,i=e.length/n;if(i%1!==0)throw new q("Edge lump has invalid length");let o=[];for(let s=0;s<i;s+=1){let a=s*n;o.push({vertices:[r.getUint16(a,!0),r.getUint16(a+2,!0)]})}return o}function Nd(t,e){let r=e.length/4;if(r%1!==0)throw new q("SurfEdge lump has invalid length");let n=new DataView(t,e.offset,e.length),i=new Int32Array(r);for(let o=0;o<r;o+=1)i[o]=n.getInt32(o*4,!0);return i}function kd(t,e){let r=new DataView(t,e.offset,e.length),n=48;if(e.length%n!==0)throw new q("Model lump has invalid length");let i=e.length/n,o=[];for(let s=0;s<i;s+=1){let a=s*n,c=[r.getFloat32(a,!0),r.getFloat32(a+4,!0),r.getFloat32(a+8,!0)],l=[r.getFloat32(a+12,!0),r.getFloat32(a+16,!0),r.getFloat32(a+20,!0)],d=[r.getFloat32(a+24,!0),r.getFloat32(a+28,!0),r.getFloat32(a+32,!0)],u=r.getInt32(a+36,!0),f=r.getInt32(a+40,!0),m=r.getInt32(a+44,!0);o.push({mins:c,maxs:l,origin:d,headNode:u,firstFace:f,numFaces:m})}return o}function Ud(t,e){let r=new DataView(t,e.offset,e.length),n=12,i=e.length/n;if(i%1!==0)throw new q("Brush lump has invalid length");let o=[];for(let s=0;s<i;s+=1){let a=s*n;o.push({firstSide:r.getInt32(a,!0),numSides:r.getInt32(a+4,!0),contents:r.getInt32(a+8,!0)})}return o}function Hd(t,e){let r=new DataView(t,e.offset,e.length),n=4,i=e.length/n;if(i%1!==0)throw new q("Brush side lump has invalid length");let o=[];for(let s=0;s<i;s+=1){let a=s*n;o.push({planeIndex:r.getUint16(a,!0),texInfo:r.getInt16(a+2,!0)})}return o}function Vd(t,e,r,n){let i=[],o=[],s=e.length/2,a=r.length/2,c=new DataView(t,e.offset,e.length),l=new DataView(t,r.offset,r.length);for(let d of n){if(d.firstLeafFace+d.numLeafFaces>s)throw new q("Leaf faces reference data past lump bounds");if(d.firstLeafBrush+d.numLeafBrushes>a)throw new q("Leaf brushes reference data past lump bounds");let u=[];for(let m=0;m<d.numLeafFaces;m+=1)u.push(c.getUint16((d.firstLeafFace+m)*2,!0));let f=[];for(let m=0;m<d.numLeafBrushes;m+=1)f.push(l.getUint16((d.firstLeafBrush+m)*2,!0));i.push(u),o.push(f)}return{leafFaces:i,leafBrushes:o}}function Gd(t,e){if(e.length===0)return;if(e.length<4)throw new q("Visibility lump too small");let r=new DataView(t,e.offset,e.length),n=r.getInt32(0,!0),i=4+n*8;if(n<0||i>e.length)throw new q("Visibility lump truncated");let o=4,s=[];for(let a=0;a<n;a+=1){let c=r.getInt32(o,!0),l=r.getInt32(o+4,!0);o+=8;let d=e.offset+c,u=e.offset+l,f=e.offset+e.length;if(c<0||l<0||d>=f||u>=f)throw new q("Visibility offsets out of range");s.push({pvs:Na(t,d,n,e),phs:Na(t,u,n,e)})}return{numClusters:n,clusters:s}}function Na(t,e,r,n){let i=Math.ceil(r/8),o=new Uint8Array(i),s=new Uint8Array(t),a=e,c=0,l=n.offset+n.length;for(;c<i;){if(a>=l)throw new q("Visibility data truncated");let d=s[a++];if(d!==0){o[c++]=d;continue}if(a>=l)throw new q("Visibility run exceeds lump bounds");let u=s[a++];for(let f=0;f<u&&c<i;f+=1)o[c++]=0}return o}function Wd(t,e){return t.map(r=>{if(!(r.lightOffset<0))return{offset:r.lightOffset,length:Math.max(0,e.length-r.lightOffset)}})}function bi(t,e,r){if(t.lightOffset<0||t.lightOffset>=e.byteLength)return;let n=e.byteLength-t.lightOffset,i=Math.min(r?.length??n,n);if(!(i<=0))return e.subarray(t.lightOffset,t.lightOffset+i)}var Xd=844121161,Kd=8,Ua=68,Yd=[{x:-.525731,y:0,z:.850651},{x:-.442863,y:.238856,z:.864188},{x:-.295242,y:0,z:.955423},{x:-.309017,y:.5,z:.809017},{x:-.16246,y:.262866,z:.951056},{x:0,y:0,z:1},{x:0,y:.850651,z:.525731},{x:-.147621,y:.716567,z:.681718},{x:.147621,y:.716567,z:.681718},{x:0,y:.525731,z:.850651},{x:.309017,y:.5,z:.809017},{x:.525731,y:0,z:.850651},{x:.295242,y:0,z:.955423},{x:.442863,y:.238856,z:.864188},{x:.16246,y:.262866,z:.951056},{x:-.681718,y:.147621,z:.716567},{x:-.809017,y:.309017,z:.5},{x:-.587785,y:.425325,z:.688191},{x:-.850651,y:.525731,z:0},{x:-.864188,y:.442863,z:.238856},{x:-.716567,y:.681718,z:.147621},{x:-.688191,y:.587785,z:.425325},{x:-.5,y:.809017,z:.309017},{x:-.238856,y:.864188,z:.442863},{x:-.425325,y:.688191,z:.587785},{x:-.716567,y:.681718,z:-.147621},{x:-.5,y:.809017,z:-.309017},{x:-.525731,y:.850651,z:0},{x:0,y:.850651,z:-.525731},{x:-.238856,y:.864188,z:-.442863},{x:0,y:.955423,z:-.295242},{x:-.262866,y:.951056,z:-.16246},{x:0,y:1,z:0},{x:0,y:.955423,z:.295242},{x:-.262866,y:.951056,z:.16246},{x:.238856,y:.864188,z:.442863},{x:.262866,y:.951056,z:.16246},{x:.5,y:.809017,z:.309017},{x:.238856,y:.864188,z:-.442863},{x:.262866,y:.951056,z:-.16246},{x:.5,y:.809017,z:-.309017},{x:.850651,y:.525731,z:0},{x:.716567,y:.681718,z:.147621},{x:.716567,y:.681718,z:-.147621},{x:.525731,y:.850651,z:0},{x:.425325,y:.688191,z:.587785},{x:.864188,y:.442863,z:.238856},{x:.688191,y:.587785,z:.425325},{x:.809017,y:.309017,z:.5},{x:.681718,y:.147621,z:.716567},{x:.587785,y:.425325,z:.688191},{x:.955423,y:.295242,z:0},{x:1,y:0,z:0},{x:.951056,y:.16246,z:.262866},{x:.850651,y:-.525731,z:0},{x:.955423,y:-.295242,z:0},{x:.864188,y:-.442863,z:.238856},{x:.951056,y:-.16246,z:.262866},{x:.809017,y:-.309017,z:.5},{x:.681718,y:-.147621,z:.716567},{x:.850651,y:0,z:.525731},{x:.864188,y:.442863,z:-.238856},{x:.809017,y:.309017,z:-.5},{x:.951056,y:.16246,z:-.262866},{x:.525731,y:0,z:-.850651},{x:.681718,y:.147621,z:-.716567},{x:.681718,y:-.147621,z:-.716567},{x:.850651,y:0,z:-.525731},{x:.809017,y:-.309017,z:-.5},{x:.864188,y:-.442863,z:-.238856},{x:.951056,y:-.16246,z:-.262866},{x:.147621,y:.716567,z:-.681718},{x:.309017,y:.5,z:-.809017},{x:.425325,y:.688191,z:-.587785},{x:.442863,y:.238856,z:-.864188},{x:.587785,y:.425325,z:-.688191},{x:.688191,y:.587785,z:-.425325},{x:-.147621,y:.716567,z:-.681718},{x:-.309017,y:.5,z:-.809017},{x:0,y:.525731,z:-.850651},{x:-.525731,y:0,z:-.850651},{x:-.442863,y:.238856,z:-.864188},{x:-.295242,y:0,z:-.955423},{x:-.16246,y:.262866,z:-.951056},{x:0,y:0,z:-1},{x:.295242,y:0,z:-.955423},{x:.16246,y:.262866,z:-.951056},{x:-.442863,y:-.238856,z:-.864188},{x:-.309017,y:-.5,z:-.809017},{x:-.16246,y:-.262866,z:-.951056},{x:0,y:-.850651,z:-.525731},{x:-.147621,y:-.716567,z:-.681718},{x:.147621,y:-.716567,z:-.681718},{x:0,y:-.525731,z:-.850651},{x:.309017,y:-.5,z:-.809017},{x:.442863,y:-.238856,z:-.864188},{x:.16246,y:-.262866,z:-.951056},{x:.238856,y:-.864188,z:-.442863},{x:.5,y:-.809017,z:-.309017},{x:.425325,y:-.688191,z:-.587785},{x:.716567,y:-.681718,z:-.147621},{x:.688191,y:-.587785,z:-.425325},{x:.587785,y:-.425325,z:-.688191},{x:0,y:-.955423,z:-.295242},{x:0,y:-1,z:0},{x:.262866,y:-.951056,z:-.16246},{x:0,y:-.850651,z:.525731},{x:0,y:-.955423,z:.295242},{x:.238856,y:-.864188,z:.442863},{x:.262866,y:-.951056,z:.16246},{x:.5,y:-.809017,z:.309017},{x:.716567,y:-.681718,z:.147621},{x:.525731,y:-.850651,z:0},{x:-.238856,y:-.864188,z:-.442863},{x:-.5,y:-.809017,z:-.309017},{x:-.262866,y:-.951056,z:-.16246},{x:-.850651,y:-.525731,z:0},{x:-.716567,y:-.681718,z:-.147621},{x:-.716567,y:-.681718,z:.147621},{x:-.525731,y:-.850651,z:0},{x:-.5,y:-.809017,z:.309017},{x:-.238856,y:-.864188,z:.442863},{x:-.262866,y:-.951056,z:.16246},{x:-.864188,y:-.442863,z:.238856},{x:-.809017,y:-.309017,z:.5},{x:-.688191,y:-.587785,z:.425325},{x:-.681718,y:-.147621,z:.716567},{x:-.442863,y:-.238856,z:.864188},{x:-.587785,y:-.425325,z:.688191},{x:-.309017,y:-.5,z:.809017},{x:-.147621,y:-.716567,z:.681718},{x:-.425325,y:-.688191,z:.587785},{x:-.16246,y:-.262866,z:.951056},{x:.442863,y:-.238856,z:.864188},{x:.16246,y:-.262866,z:.951056},{x:.309017,y:-.5,z:.809017},{x:.147621,y:-.716567,z:.681718},{x:0,y:-.525731,z:.850651},{x:.425325,y:-.688191,z:.587785},{x:.587785,y:-.425325,z:.688191},{x:.688191,y:-.587785,z:.425325},{x:-.955423,y:.295242,z:0},{x:-.951056,y:.16246,z:.262866},{x:-1,y:0,z:0},{x:-.850651,y:0,z:.525731},{x:-.955423,y:-.295242,z:0},{x:-.951056,y:-.16246,z:.262866},{x:-.864188,y:.442863,z:-.238856},{x:-.951056,y:.16246,z:-.262866},{x:-.809017,y:.309017,z:-.5},{x:-.864188,y:-.442863,z:-.238856},{x:-.951056,y:-.16246,z:-.262866},{x:-.809017,y:-.309017,z:-.5},{x:-.681718,y:.147621,z:-.716567},{x:-.681718,y:-.147621,z:-.716567},{x:-.850651,y:0,z:-.525731},{x:-.688191,y:.587785,z:-.425325},{x:-.587785,y:.425325,z:-.688191},{x:-.425325,y:.688191,z:-.587785},{x:-.425325,y:-.688191,z:-.587785},{x:-.587785,y:-.425325,z:-.688191},{x:-.688191,y:-.587785,z:-.425325}],le=class extends Error{},mr=class{constructor(e){this.vfs=e;this.cache=new Map}async load(e){if(this.cache.has(e))return this.cache.get(e);let r=await this.vfs.readFile(e),n=new Uint8Array(r.byteLength);n.set(r);let i=ls(n.buffer);return this.cache.set(e,i),i}get(e){return this.cache.get(e)}};function Ha(t,e,r){let n=[];for(let i=0;i<r;i+=1){let o=t.getUint8(e+i);if(o===0)break;n.push(o)}return String.fromCharCode(...n)}function $r(t,e,r,n){if(r!==0&&(e<Ua||e+r>t.byteLength))throw new le(`${n} section is out of bounds`)}function qd(t){if(t.byteLength<Ua)throw new le("MD2 buffer too small to contain header");let e=new DataView(t),r=e.getInt32(0,!0),n=e.getInt32(4,!0);if(r!==Xd)throw new le(`Invalid MD2 ident: ${r}`);if(n!==Kd)throw new le(`Unsupported MD2 version: ${n}`);let i={ident:r,version:n,skinWidth:e.getInt32(8,!0),skinHeight:e.getInt32(12,!0),frameSize:e.getInt32(16,!0),numSkins:e.getInt32(20,!0),numVertices:e.getInt32(24,!0),numTexCoords:e.getInt32(28,!0),numTriangles:e.getInt32(32,!0),numGlCommands:e.getInt32(36,!0),numFrames:e.getInt32(40,!0),offsetSkins:e.getInt32(44,!0),offsetTexCoords:e.getInt32(48,!0),offsetTriangles:e.getInt32(52,!0),offsetFrames:e.getInt32(56,!0),offsetGlCommands:e.getInt32(60,!0),offsetEnd:e.getInt32(64,!0),magic:r},o=40+i.numVertices*4;if(i.frameSize!==o)throw new le(`Unexpected frame size ${i.frameSize}, expected ${o}`);if(i.offsetEnd>t.byteLength)throw new le("MD2 offset_end exceeds buffer length");return i}function $d(t,e){let r=e.numSkins*64;$r(t,e.offsetSkins,r,"skins");let n=new DataView(t,e.offsetSkins,r),i=[];for(let o=0;o<e.numSkins;o+=1)i.push({name:Ha(n,o*64,64)});return i}function jd(t,e){let r=e.numTexCoords*4;$r(t,e.offsetTexCoords,r,"texcoords");let n=new DataView(t,e.offsetTexCoords,r),i=[];for(let o=0;o<e.numTexCoords;o+=1){let s=o*4;i.push({s:n.getInt16(s,!0),t:n.getInt16(s+2,!0)})}return i}function Qd(t,e){let r=e.numTriangles*12;$r(t,e.offsetTriangles,r,"triangles");let n=new DataView(t,e.offsetTriangles,r),i=[];for(let o=0;o<e.numTriangles;o+=1){let s=o*12,a=[n.getUint16(s,!0),n.getUint16(s+2,!0),n.getUint16(s+4,!0)],c=[n.getUint16(s+6,!0),n.getUint16(s+8,!0),n.getUint16(s+10,!0)];if(a.some(l=>l>=e.numVertices)||c.some(l=>l>=e.numTexCoords))throw new le("Triangle references out of range vertex or texcoord");i.push({vertexIndices:a,texCoordIndices:c})}return i}function Jd(t,e){let r=e.numFrames*e.frameSize;$r(t,e.offsetFrames,r,"frames");let n=[];for(let i=0;i<e.numFrames;i+=1){let o=e.offsetFrames+i*e.frameSize,s=new DataView(t,o,e.frameSize),a={x:s.getFloat32(0,!0),y:s.getFloat32(4,!0),z:s.getFloat32(8,!0)},c={x:s.getFloat32(12,!0),y:s.getFloat32(16,!0),z:s.getFloat32(20,!0)},l=Ha(s,24,16),d=[],u=1/0,f=1/0,m=1/0,p=-1/0,y=-1/0,h=-1/0;for(let g=0;g<e.numVertices;g+=1){let M=40+g*4,x=s.getUint8(M)*a.x+c.x,v=s.getUint8(M+1)*a.y+c.y,b=s.getUint8(M+2)*a.z+c.z;x<u&&(u=x),v<f&&(f=v),b<m&&(m=b),x>p&&(p=x),v>y&&(y=v),b>h&&(h=b);let S={x,y:v,z:b},A=s.getUint8(M+3),w=Yd[A];if(!w)throw new le(`Invalid normal index ${A} in frame ${l}`);d.push({position:S,normalIndex:A,normal:w})}n.push({name:l,vertices:d,minBounds:{x:u,y:f,z:m},maxBounds:{x:p,y,z:h}})}return n}function Zd(t,e){let r=e.numGlCommands*4;if($r(t,e.offsetGlCommands,r,"gl commands"),r===0)return[];let n=new DataView(t,e.offsetGlCommands,r),i=[],o=0;for(;;){if(o+4>r)throw new le("GL command list ended unexpectedly");let s=n.getInt32(o,!0);if(o+=4,s===0)break;let a=Math.abs(s),c=[],l=a*12;if(o+l>r)throw new le("GL command vertex block exceeds buffer");for(let d=0;d<a;d+=1){let u=n.getFloat32(o,!0),f=n.getFloat32(o+4,!0),m=n.getInt32(o+8,!0);if(o+=12,m<0||m>=e.numVertices)throw new le("GL command references invalid vertex index");c.push({s:u,t:f,vertexIndex:m})}i.push({mode:s>0?"strip":"fan",vertices:c})}if(o!==r)throw new le("GL command list did not consume expected data");return i}function ls(t){let e=qd(t),r=$d(t,e),n=jd(t,e),i=Qd(t,e),o=Jd(t,e),s=Zd(t,e);return{header:e,skins:r,texCoords:n,triangles:i,frames:o,glCommands:s}}function Va(t){let e=[],r=0;for(;r<t.length;){let n=t[r].name,i=n.replace(/\d+$/,"")||n,o=r;for(;o+1<t.length&&(t[o+1].name.replace(/\d+$/,"")||t[o+1].name)===i;)o+=1;e.push({name:i,firstFrame:r,lastFrame:o}),r=o+1}return e}var Ga=860898377,e0=15,Te=class extends Error{constructor(e){super(e),this.name="Md3ParseError"}};function jr(t,e,r){let n=new Uint8Array(t.buffer,t.byteOffset+e,r);return new TextDecoder("utf-8").decode(n).replace(/\0.*$/,"").trim()}function t0(t){let e=(t>>8&255)*(2*Math.PI/255),r=(t&255)*(2*Math.PI/255),n=Math.sin(r);return{x:Math.cos(e)*n,y:Math.sin(e)*n,z:Math.cos(r)}}function vi(t,e,r,n){if(e<0||e+r>n)throw new Te(`${t} exceeds buffer bounds`)}function r0(t){let e=t.getInt32(0,!0);if(e!==Ga)throw new Te(`Invalid MD3 ident: ${e}`);let r=t.getInt32(4,!0);if(r!==e0)throw new Te(`Unsupported MD3 version: ${r}`);let n=jr(t,8,64),i=t.getInt32(72,!0),o=t.getInt32(76,!0),s=t.getInt32(80,!0),a=t.getInt32(84,!0),c=t.getInt32(88,!0),l=t.getInt32(92,!0),d=t.getInt32(96,!0),u=t.getInt32(100,!0),f=t.getInt32(104,!0);if(o<=0||a<0||s<0)throw new Te("Invalid MD3 counts");return{ident:e,version:r,name:n,flags:i,numFrames:o,numTags:s,numSurfaces:a,numSkins:c,ofsFrames:l,ofsTags:d,ofsSurfaces:u,ofsEnd:f,magic:e}}function n0(t,e){let r=[];vi("Frames",e.ofsFrames,e.numFrames*56,t.byteLength);for(let i=0;i<e.numFrames;i+=1){let o=e.ofsFrames+i*56;r.push({minBounds:{x:t.getFloat32(o,!0),y:t.getFloat32(o+4,!0),z:t.getFloat32(o+8,!0)},maxBounds:{x:t.getFloat32(o+12,!0),y:t.getFloat32(o+16,!0),z:t.getFloat32(o+20,!0)},localOrigin:{x:t.getFloat32(o+24,!0),y:t.getFloat32(o+28,!0),z:t.getFloat32(o+32,!0)},radius:t.getFloat32(o+36,!0),name:jr(t,o+40,16)})}return r}function i0(t,e){let r=[],i=e.numFrames*e.numTags*112;vi("Tags",e.ofsTags,i,t.byteLength);for(let o=0;o<e.numFrames;o+=1){let s=[];for(let a=0;a<e.numTags;a+=1){let c=e.ofsTags+(o*e.numTags+a)*112,l=c+64,d=l+12;s.push({name:jr(t,c,64),origin:{x:t.getFloat32(l,!0),y:t.getFloat32(l+4,!0),z:t.getFloat32(l+8,!0)},axis:[{x:t.getFloat32(d,!0),y:t.getFloat32(d+4,!0),z:t.getFloat32(d+8,!0)},{x:t.getFloat32(d+12,!0),y:t.getFloat32(d+16,!0),z:t.getFloat32(d+20,!0)},{x:t.getFloat32(d+24,!0),y:t.getFloat32(d+28,!0),z:t.getFloat32(d+32,!0)}]})}r.push(s)}return r}function o0(t,e){let r=t.getInt32(e,!0);if(r!==Ga)throw new Te(`Invalid surface ident at ${e}: ${r}`);let n=jr(t,e+4,64),i=t.getInt32(e+68,!0),o=t.getInt32(e+72,!0),s=t.getInt32(e+76,!0),a=t.getInt32(e+80,!0),c=t.getInt32(e+84,!0),l=t.getInt32(e+88,!0),d=t.getInt32(e+92,!0),u=t.getInt32(e+96,!0),f=t.getInt32(e+100,!0),m=t.getInt32(e+104,!0);if(o<=0||a<=0||c<=0)throw new Te(`Invalid surface counts for ${n}`);let p=m;vi(`Surface ${n}`,e,p,t.byteLength);let y=[],h=e+l;for(let A=0;A<c;A+=1){let w=h+A*12;y.push({indices:[t.getInt32(w,!0),t.getInt32(w+4,!0),t.getInt32(w+8,!0)]})}let g=[],M=e+d;for(let A=0;A<s;A+=1){let w=M+A*68;g.push({name:jr(t,w,64),shaderIndex:t.getInt32(w+64,!0)})}let x=[],v=e+u;for(let A=0;A<a;A+=1){let w=v+A*8;x.push({s:t.getFloat32(w,!0),t:t.getFloat32(w+4,!0)})}let b=[],S=e+f;for(let A=0;A<o;A+=1){let w=[];for(let P=0;P<a;P+=1){let L=S+(A*a+P)*8,O=t.getInt16(L,!0)/64,k=t.getInt16(L+2,!0)/64,W=t.getInt16(L+4,!0)/64,T=t.getUint16(L+6,!0);w.push({position:{x:O,y:k,z:W},latLng:T,normal:t0(T)})}b.push(w)}return{surface:{name:n,flags:i,numFrames:o,shaders:g,triangles:y,texCoords:x,vertices:b},nextOffset:e+m}}function ds(t){if(t.byteLength<108)throw new Te("MD3 buffer too small for header");let e=new DataView(t),r=r0(e);vi("MD3 end",r.ofsEnd,0,t.byteLength);let n=n0(e,r),i=i0(e,r),o=[],s=r.ofsSurfaces;for(let a=0;a<r.numSurfaces;a+=1){let{surface:c,nextOffset:l}=o0(e,s);o.push(c),s=l}if(s!==r.ofsEnd)throw new Te("Surface parsing did not reach ofsEnd");return{header:r,frames:n,tags:i,surfaces:o}}var hr=class{constructor(e){this.vfs=e;this.cache=new Map}async load(e){if(this.cache.has(e))return this.cache.get(e);let r=await this.vfs.readFile(e),n=ds(r.slice().buffer);return this.cache.set(e,n),n}get(e){return this.cache.get(e)}};var s0=844317769,a0=2,Wa=64,Xa=12,yt=class extends Error{};function c0(t,e,r){let n=[];for(let i=0;i<r;i+=1){let o=t.getUint8(e+i);if(o===0)break;n.push(o)}return String.fromCharCode(...n)}function us(t){if(t.byteLength<Xa)throw new yt("Sprite buffer too small to contain header");let e=new DataView(t),r=e.getInt32(0,!0),n=e.getInt32(4,!0),i=e.getInt32(8,!0);if(r!==s0)throw new yt(`Invalid Sprite ident: ${r}`);if(n!==a0)throw new yt(`Unsupported Sprite version: ${n}`);let o=[],s=16+Wa,a=Xa;for(let c=0;c<i;c+=1){if(a+s>t.byteLength)throw new yt("Sprite frame data exceeds buffer length");let l=e.getInt32(a,!0),d=e.getInt32(a+4,!0),u=e.getInt32(a+8,!0),f=e.getInt32(a+12,!0),m=c0(e,a+16,Wa);o.push({width:l,height:d,originX:u,originY:f,name:m}),a+=s}return{ident:r,version:n,numFrames:i,frames:o}}var pr=class{constructor(e){this.vfs=e}async load(e){let r=await this.vfs.readFile(e),n=new Uint8Array(r.byteLength);return n.set(r),us(n.buffer)}};function Ka(t,e){let r=(t.sequence.end-t.sequence.start+1)/t.sequence.fps,n=t.sequence.loop!==!1,i=t.time+e;return n?i=(i%r+r)%r:i>r&&(i=r),{...t,time:Math.max(0,Math.min(i,r))}}function Ya(t){let e=t.sequence.end-t.sequence.start+1,r=1/t.sequence.fps,n=t.sequence.loop!==!1,i=t.time/r;if(!n&&i>=e)return{frame0:t.sequence.end,frame1:t.sequence.end,lerp:0};let o=n?i%e:Math.min(i,e-1),s=Math.floor(o),a=t.sequence.start+s,c=s+1>=e?n?t.sequence.start:t.sequence.end:a+1,l=!n&&s>=e-1?0:o-s;return{frame0:a,frame1:c,lerp:l}}function qa(t){return{sequence:t,time:0}}function $a(t,e,r){return{x:t.x+(e.x-t.x)*r,y:t.y+(e.y-t.y)*r,z:t.z+(e.z-t.z)*r}}var Qr=class extends Error{constructor(e){super(e),this.name="WalParseError"}};function Si(t){if(t.byteLength<100)throw new Qr("WAL buffer too small");let e=new DataView(t),r=new Uint8Array(t,0,32),n=new TextDecoder("utf-8").decode(r).replace(/\0.*$/,"").trim(),i=e.getInt32(32,!0),o=e.getInt32(36,!0),s=[e.getInt32(40,!0),e.getInt32(44,!0),e.getInt32(48,!0),e.getInt32(52,!0)],a=new Uint8Array(t,56,32),c=new TextDecoder("utf-8").decode(a).replace(/\0.*$/,"").trim(),l=e.getInt32(88,!0),d=e.getInt32(92,!0),u=e.getInt32(96,!0);if(i<=0||o<=0)throw new Qr("Invalid WAL dimensions");let f=[],m=i,p=o;for(let y=0;y<s.length;y+=1){let h=s[y],g=Math.max(1,m*p|0);if(h<=0||h+g>t.byteLength)throw new Qr(`Invalid WAL mip offset for level ${y}`);let M=new Uint8Array(t,h,g);f.push({level:y,width:m,height:p,data:M}),m=Math.max(1,m>>1),p=Math.max(1,p>>1)}return{name:n,width:i,height:o,mipmaps:f,animName:c,flags:l,contents:d,value:u}}var Nt=class extends Error{constructor(e){super(e),this.name="PcxParseError"}};function Jr(t){if(t.byteLength<128)throw new Nt("PCX buffer too small for header");let e=new DataView(t),r=e.getUint8(0),n=e.getUint8(2),i=e.getUint8(3),o=e.getUint16(4,!0),s=e.getUint16(6,!0),a=e.getUint16(8,!0),c=e.getUint16(10,!0);if(r!==10||n!==1)throw new Nt("Unsupported PCX encoding");if(i!==8)throw new Nt("Only 8bpp PCX files are supported");let l=a-o+1,d=c-s+1,u=e.getUint16(66,!0),f=t.byteLength-769;if(f<128||new DataView(t,f,1).getUint8(0)!==12)throw new Nt("Missing PCX palette");let m=new Uint8Array(t,f+1,768),p=new Uint8Array(t,128,f-128),y=new Uint8Array(l*d),h=0,g=0;for(let M=0;M<d;M+=1){let x=0;for(;x<u&&h<p.length;){let v=1,b=p[h++];if((b&192)===192){if(v=b&63,h>=p.length)throw new Nt("Unexpected end of PCX RLE data");b=p[h++]}for(let S=0;S<v&&x<u;S+=1)x<l&&(y[g++]=b),x+=1}}return{width:l,height:d,bitsPerPixel:i,pixels:y,palette:m}}function Mi(t){let e=new Uint8Array(t.width*t.height*4);for(let r=0;r<t.pixels.length;r+=1){let n=t.pixels[r],i=n*3,o=r*4;e[o]=t.palette[i],e[o+1]=t.palette[i+1],e[o+2]=t.palette[i+2],e[o+3]=n===255?0:255}return e}var et=class extends Error{constructor(e){super(e),this.name="TgaParseError"}};function fs(t){let e=new DataView(t);if(t.byteLength<18)throw new et("Buffer too small for TGA header");let r=e.getUint8(0),n=e.getUint8(1),i=e.getUint8(2),o=e.getUint16(12,!0),s=e.getUint16(14,!0),a=e.getUint8(16),c=e.getUint8(17);if(i!==2&&i!==10&&i!==3&&i!==11)throw new et(`Unsupported TGA image type: ${i} (only RGB/Grayscale supported)`);if(a!==24&&a!==32&&a!==8)throw new et(`Unsupported pixel depth: ${a} (only 8, 24, 32 bpp supported)`);let l=i>=9,d=i===3||i===11,u=a/8,f=18+r;if(n===1){let x=e.getUint16(5,!0),v=e.getUint8(7);f+=x*(v/8)}let m=o*s,p=new Uint8Array(m*4),y=(c&32)!==0,h=0,g=new Uint8Array(t),M=x=>{if(d){let v=g[f++];p[x]=v,p[x+1]=v,p[x+2]=v,p[x+3]=255}else{let v=g[f++],b=g[f++],S=g[f++],A=a===32?g[f++]:255;p[x]=S,p[x+1]=b,p[x+2]=v,p[x+3]=A}};if(l){let x=0;for(;x<m;){if(f>=t.byteLength)throw new et("Unexpected end of TGA RLE data");let v=g[f++],b=(v&127)+1,S=(v&128)!==0;if(x+b>m)throw new et("TGA RLE packet exceeds image bounds");if(S){let A=d?g[f]:g[f+2],w=d?g[f]:g[f+1],P=g[f],L=d?255:a===32?g[f+3]:255;f+=u;for(let O=0;O<b;O++){let k=(x+O)*4;p[k]=A,p[k+1]=w,p[k+2]=P,p[k+3]=L}}else for(let A=0;A<b;A++)M((x+A)*4);x+=b}}else for(let x=0;x<m;x++){if(f>=t.byteLength)throw new et("Unexpected end of TGA data");M(x*4)}if(!y){let x=o*4,v=new Uint8Array(x);for(let b=0;b<s/2;b++){let S=b*x,A=(s-1-b)*x;v.set(p.subarray(S,S+x)),p.set(p.subarray(A,A+x),S),p.set(v,A)}}return{width:o,height:s,bitsPerPixel:32,pixels:p}}var yr=class{constructor(e={}){this.cache=new pt(e.capacity??128)}get size(){return this.cache.size}get(e){return this.cache.get(e.toLowerCase())}set(e,r){this.cache.set(e.toLowerCase(),r)}clear(){this.cache.clear()}};function ms(t,e){let r=[];for(let n of t.mipmaps){let i=new Uint8Array(n.width*n.height*4);for(let o=0;o<n.data.length;o+=1){let s=n.data[o],a=s*3,c=o*4;i[c]=e[a],i[c+1]=e[a+1],i[c+2]=e[a+2],i[c+3]=s===255?0:255}r.push({level:n.level,width:n.width,height:n.height,rgba:i})}return{width:t.width,height:t.height,levels:r,source:"wal"}}function _i(t){let e=Mi(t),r={level:0,width:t.width,height:t.height,rgba:e};return{width:t.width,height:t.height,levels:[r],source:"pcx"}}function ja(t){let e={level:0,width:t.width,height:t.height,rgba:t.pixels};return{width:t.width,height:t.height,levels:[e],source:"tga"}}function Ai(t,e){return ms(Si(t),e)}var kt=class extends Error{constructor(e){super(e),this.name="WavParseError"}};function hs(t,e,r){return new TextDecoder("ascii").decode(new Uint8Array(t.buffer,t.byteOffset+e,r))}function wi(t){if(t.byteLength<44)throw new kt("WAV buffer too small");let e=new DataView(t);if(hs(e,0,4)!=="RIFF"||hs(e,8,4)!=="WAVE")throw new kt("Invalid WAV header");let r=12,n=-1,i=-1,o=0,s=0;for(;r+8<=t.byteLength;){let p=hs(e,r,4),y=e.getUint32(r+4,!0),h=r+8;p==="fmt "?(n=h,o=y):p==="data"&&(i=h,s=y),r=h+y}if(n===-1||i===-1)throw new kt("Missing fmt or data chunk");let a=e.getUint16(n,!0),c=e.getUint16(n+2,!0),l=e.getUint32(n+4,!0),d=e.getUint16(n+14,!0);if(a!==1)throw new kt("Only PCM WAV is supported");let u=d/8,f=s/(u*c),m=new Float32Array(f*c);for(let p=0;p<f;p+=1)for(let y=0;y<c;y+=1){let h=p*c+y,g=i+h*u,M=0;if(d===8)M=e.getUint8(g),m[h]=(M-128)/128;else if(d===16)M=e.getInt16(g,!0),m[h]=M/32768;else if(d===24){let x=e.getUint8(g),v=e.getUint8(g+1),b=e.getInt8(g+2);M=x|v<<8|b<<16,m[h]=M/8388608}else throw new kt(`Unsupported bitsPerSample: ${d}`)}return{sampleRate:l,channels:c,bitsPerSample:d,samples:m}}var l0=(t,e=4294967295,r=79764919)=>{let n=new Int32Array(256),i,o,s,a=e;for(i=0;i<256;i++){for(s=i<<24,o=8;o>0;--o)s=2147483648&s?s<<1^r:s<<1;n[i]=s}for(i=0;i<t.length;i++)a=a<<8^n[255&(a>>24^t[i])];return a};var ps=(t,e=l0)=>{let r=h=>new Uint8Array(h.length/2).map(((g,M)=>parseInt(h.substring(2*M,2*(M+1)),16))),n=h=>r(h)[0],i=new Map;[,8364,,8218,402,8222,8230,8224,8225,710,8240,352,8249,338,,381,,,8216,8217,8220,8221,8226,8211,8212,732,8482,353,8250,339,,382,376].forEach(((h,g)=>i.set(h,g)));let o=new Uint8Array(t.length),s,a,c,l=!1,d=0,u=42,f=t.length>13&&t.substring(0,9)==="dynEncode",m=0;f&&(m=11,a=n(t.substring(9,m)),a<=1&&(m+=2,u=n(t.substring(11,m))),a===1&&(m+=8,c=(h=>new DataView(r(h).buffer).getInt32(0,!0))(t.substring(13,m))));let p=256-u;for(let h=m;h<t.length;h++)if(s=t.charCodeAt(h),s!==61||l){if(s===92&&h<t.length-5&&f){let g=t.charCodeAt(h+1);g!==117&&g!==85||(s=parseInt(t.substring(h+2,h+6),16),h+=5)}if(s>255){let g=i.get(s);g&&(s=g+127)}l&&(l=!1,s-=64),o[d++]=s<u&&s>0?s+p:s-u}else l=!0;let y=o.subarray(0,d);if(f&&a===1){let h=e(y);if(h!==c){let g="Decode failed crc32 validation";throw console.error("`simple-yenc`\n",g+`
1
+ "use strict";var Quake2Engine=(()=>{var vl=Object.create;var li=Object.defineProperty;var Sl=Object.getOwnPropertyDescriptor;var Ml=Object.getOwnPropertyNames;var _l=Object.getPrototypeOf,Al=Object.prototype.hasOwnProperty;var wl=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),qo=(t,e)=>{for(var r in e)li(t,r,{get:e[r],enumerable:!0})},ya=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ml(e))!Al.call(t,i)&&i!==r&&li(t,i,{get:()=>e[i],enumerable:!(n=Sl(e,i))||n.enumerable});return t};var Ll=(t,e,r)=>(r=t!=null?vl(_l(t)):{},ya(e||!t||!t.__esModule?li(r,"default",{value:t,enumerable:!0}):r,t)),El=t=>ya(li({},"__esModule",{value:!0}),t);var Ja=wl((ph,Qa)=>{"use strict";Qa.exports=Worker});var Kf={};qo(Kf,{ATTN_IDLE:()=>Pc,ATTN_LOOP_NONE:()=>Ec,ATTN_NONE:()=>so,ATTN_NORM:()=>Ic,ATTN_STATIC:()=>Cc,AssetDependencyError:()=>Zt,AssetDependencyTracker:()=>qn,AssetManager:()=>io,AudioApi:()=>dr,AudioContextController:()=>co,AudioRegistry:()=>Fr,AudioRegistryError:()=>Xn,AudioSystem:()=>yo,BSP_SURFACE_FRAGMENT_SOURCE:()=>Gs,BSP_SURFACE_VERTEX_SOURCE:()=>Vs,BSP_VERTEX_LAYOUT:()=>ks,BspLoader:()=>fr,BspParseError:()=>q,BspSurfacePipeline:()=>vo,Camera:()=>wo,Command:()=>Wr,CommandRegistry:()=>or,ConfigStringRegistry:()=>lr,Cvar:()=>Yr,CvarRegistry:()=>ar,DemoPlaybackController:()=>ii,DemoReader:()=>tr,EngineHost:()=>cr,EngineRuntime:()=>qr,FixedTimestepLoop:()=>Dt,Framebuffer:()=>xo,IndexBuffer:()=>fe,LruCache:()=>pt,MAX_SOUND_CHANNELS:()=>Bs,MD2_FRAGMENT_SHADER:()=>js,MD2_VERTEX_SHADER:()=>$s,MD3_FRAGMENT_SHADER:()=>oa,MD3_VERTEX_SHADER:()=>ia,Md2Loader:()=>mr,Md2MeshBuffers:()=>Mo,Md2ParseError:()=>le,Md2Pipeline:()=>_o,Md3Loader:()=>hr,Md3ModelMesh:()=>Lo,Md3ParseError:()=>Te,Md3Pipeline:()=>Eo,Md3SurfaceMesh:()=>Qn,MusicSystem:()=>go,NetworkMessageParser:()=>nr,PARTICLE_FRAGMENT_SHADER:()=>aa,PARTICLE_VERTEX_SHADER:()=>sa,PakArchive:()=>ur,PakIndexStore:()=>no,PakIngestionError:()=>ht,PakParseError:()=>Re,PakValidationError:()=>Ot,PakValidator:()=>gi,ParticleRenderer:()=>Po,ParticleSystem:()=>Io,PlaybackState:()=>Yo,RERELEASE_KNOWN_PAKS:()=>ss,SKYBOX_FRAGMENT_SHADER:()=>Ys,SKYBOX_VERTEX_SHADER:()=>Ks,SOUND_FULLVOLUME:()=>Br,SOUND_LOOP_ATTENUATE:()=>zc,ShaderProgram:()=>ve,SkyboxPipeline:()=>So,SoundChannel:()=>oo,SoundPrecache:()=>fo,SoundRegistry:()=>uo,SpriteLoader:()=>pr,SpriteParseError:()=>yt,Texture2D:()=>Dr,TextureCache:()=>yr,TextureCubeMap:()=>Or,TgaParseError:()=>et,U_ANGLE1:()=>No,U_ANGLE2:()=>To,U_ANGLE3:()=>Fo,U_EFFECTS16:()=>ri,U_EFFECTS8:()=>Zn,U_EVENT:()=>Do,U_FRAME16:()=>Uo,U_FRAME8:()=>Bo,U_MODEL:()=>ko,U_MODEL2:()=>Ho,U_MODEL3:()=>Vo,U_MODEL4:()=>Go,U_OLDORIGIN:()=>Wo,U_ORIGIN1:()=>zo,U_ORIGIN2:()=>Ro,U_ORIGIN3:()=>Oo,U_REMOVE:()=>ca,U_RENDERFX16:()=>ti,U_RENDERFX8:()=>Jn,U_SKIN16:()=>ni,U_SKIN8:()=>ei,U_SOLID:()=>Ko,U_SOUND:()=>Xo,VertexArray:()=>we,VertexBuffer:()=>Se,VirtualFileSystem:()=>yi,advanceAnimation:()=>Ka,applySurfaceState:()=>Wc,attenuationToDistanceMultiplier:()=>er,boxIntersectsFrustum:()=>jn,buildBspGeometry:()=>Oc,buildMd2Geometry:()=>Qs,buildMd2VertexData:()=>Js,buildMd3SurfaceGeometry:()=>ra,buildMd3VertexData:()=>na,calculateMaxAudibleDistance:()=>ao,calculatePakChecksum:()=>Fa,computeFrameBlend:()=>Ya,computeSkyScroll:()=>Yc,createAnimationState:()=>qa,createAudioGraph:()=>lo,createBspSurfaces:()=>Dc,createEmptyEntityState:()=>rr,createEmptyProtocolPlayerState:()=>Co,createEngine:()=>Xf,createEngineRuntime:()=>Ra,createFaceLightmap:()=>bi,createInitialChannels:()=>mo,createProgramFromSources:()=>Bc,createWebGLContext:()=>Tc,decodeOgg:()=>ro,deriveSurfaceRenderState:()=>Xs,extractFrustumPlanes:()=>Nc,filesToPakSources:()=>as,findLeafForPoint:()=>Hs,gatherVisibleFaces:()=>Vc,groupMd2Animations:()=>Va,ingestPakFiles:()=>Ba,ingestPaks:()=>xi,interpolateMd3Tag:()=>ul,interpolateVec3:()=>$a,parseBsp:()=>cs,parseMd2:()=>ls,parseMd3:()=>ds,parsePcx:()=>Jr,parseSprite:()=>us,parseTga:()=>fs,parseWal:()=>Si,parseWalTexture:()=>Ai,parseWav:()=>wi,pcxToRgba:()=>Mi,pickChannel:()=>ho,preparePcxTexture:()=>_i,removeViewTranslation:()=>Kc,resolveLightStyles:()=>Ws,spatializeOrigin:()=>po,spawnBlood:()=>hl,spawnBulletImpact:()=>fl,spawnExplosion:()=>ml,spawnMuzzleFlash:()=>yl,spawnTeleportFlash:()=>pl,spawnTrail:()=>gl,walToRgba:()=>ms,wireDropTarget:()=>Da,wireFileInput:()=>Oa});var Il=()=>typeof performance<"u"?performance.now():Date.now(),Pl=t=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>t()):setTimeout(t,25)},Dt=class{constructor(e,r={}){this.callbacks=e;this.accumulatorMs=0;this.frame=0;this.running=!1;this.tick=()=>{if(!this.running)return;let e=this.options.now(),r=this.lastTimeMs===void 0?0:e-this.lastTimeMs;this.lastTimeMs=e,this.advance(r,e),this.running&&this.options.schedule(this.tick)};let n=r.fixedDeltaMs??25,i=r.maxSubSteps??5;this.options={fixedDeltaMs:n,maxSubSteps:i,maxDeltaMs:r.maxDeltaMs??n*i,startTimeMs:r.startTimeMs,now:r.now??Il,schedule:r.schedule??Pl}}start(){this.running||(this.running=!0,this.lastTimeMs=this.options.startTimeMs??this.options.now(),this.options.schedule(this.tick))}stop(){this.running=!1}pump(e){let r=(this.lastTimeMs??0)+e;this.lastTimeMs=r,this.advance(e,r)}isRunning(){return this.running}get frameNumber(){return this.frame}advance(e,r){let n=Math.min(Math.max(e,0),this.options.maxDeltaMs);this.accumulatorMs=Math.min(this.accumulatorMs+n,this.options.fixedDeltaMs*this.options.maxSubSteps);let i=0;for(;this.accumulatorMs>=this.options.fixedDeltaMs&&i<this.options.maxSubSteps;)this.frame+=1,this.callbacks.simulate({frame:this.frame,deltaMs:this.options.fixedDeltaMs,nowMs:r}),this.accumulatorMs-=this.options.fixedDeltaMs,i+=1;let o=this.options.fixedDeltaMs===0?0:this.accumulatorMs/this.options.fixedDeltaMs;this.callbacks.render?.({alpha:o,nowMs:r,accumulatorMs:this.accumulatorMs,frame:this.frame})}};var Wr=class{constructor(e,r,n){this.name=e,this.callback=r,this.description=n}execute(e){this.callback(e)}},or=class{constructor(){this.commands=new Map}register(e,r,n){let i=new Wr(e,r,n);return this.commands.set(e,i),i}get(e){return this.commands.get(e)}execute(e){let r=this.tokenize(e);if(r.length===0)return!1;let n=r[0],i=r.slice(1),o=this.get(n);return o?(o.execute(i),!0):!1}tokenize(e){return e.trim().split(/\s+/)}list(){return[...this.commands.values()].sort((e,r)=>e.name.localeCompare(r.name))}};var Cl=Object.defineProperty,ga=(t,e)=>{for(var r in e)Cl(t,r,{get:e[r],enumerable:!0})},xa={x:0,y:0,z:0};var jf=Math.PI/180;function ba(t,e){return{x:t.x-e.x,y:t.y-e.y,z:t.z-e.z}}function zl(t,e){return{x:t.x*e,y:t.y*e,z:t.z*e}}function jo(t,e){return t.x*e.x+t.y*e.y+t.z*e.z}function Rl(t){return jo(t,t)}function Qo(t){return Math.sqrt(Rl(t))}function He(t){let e=Qo(t);return e===0?t:zl(t,1/e)}var Tl=Math.PI/180,Qf=180/Math.PI,sr=Tl;var Fl=[[-.525731,0,.850651],[-.442863,.238856,.864188],[-.295242,0,.955423],[-.309017,.5,.809017],[-.16246,.262866,.951056],[0,0,1],[0,.850651,.525731],[-.147621,.716567,.681718],[.147621,.716567,.681718],[0,.525731,.850651],[.309017,.5,.809017],[.525731,0,.850651],[.295242,0,.955423],[.442863,.238856,.864188],[.16246,.262866,.951056],[-.681718,.147621,.716567],[-.809017,.309017,.5],[-.587785,.425325,.688191],[-.850651,.525731,0],[-.864188,.442863,.238856],[-.716567,.681718,.147621],[-.688191,.587785,.425325],[-.5,.809017,.309017],[-.238856,.864188,.442863],[-.425325,.688191,.587785],[-.716567,.681718,-.147621],[-.5,.809017,-.309017],[-.525731,.850651,0],[0,.850651,-.525731],[-.238856,.864188,-.442863],[0,.955423,-.295242],[-.262866,.951056,-.16246],[0,1,0],[0,.955423,.295242],[-.262866,.951056,.16246],[.238856,.864188,.442863],[.262866,.951056,.16246],[.5,.809017,.309017],[.238856,.864188,-.442863],[.262866,.951056,-.16246],[.5,.809017,-.309017],[.850651,.525731,0],[.716567,.681718,.147621],[.716567,.681718,-.147621],[.525731,.850651,0],[.425325,.688191,.587785],[.864188,.442863,.238856],[.688191,.587785,.425325],[.809017,.309017,.5],[.681718,.147621,.716567],[.587785,.425325,.688191],[.955423,.295242,0],[1,0,0],[.951056,.16246,.262866],[.850651,-.525731,0],[.955423,-.295242,0],[.864188,-.442863,.238856],[.951056,-.16246,.262866],[.809017,-.309017,.5],[.681718,-.147621,.716567],[.850651,0,.525731],[.864188,.442863,-.238856],[.809017,.309017,-.5],[.951056,.16246,-.262866],[.525731,0,-.850651],[.681718,.147621,-.716567],[.681718,-.147621,-.716567],[.850651,0,-.525731],[.809017,-.309017,-.5],[.864188,-.442863,-.238856],[.951056,-.16246,-.262866],[.147621,.716567,-.681718],[.309017,.5,-.809017],[.425325,.688191,-.587785],[.442863,.238856,-.864188],[.587785,.425325,-.688191],[.688191,.587785,-.425325],[-.147621,.716567,-.681718],[-.309017,.5,-.809017],[0,.525731,-.850651],[-.525731,0,-.850651],[-.442863,.238856,-.864188],[-.295242,0,-.955423],[-.16246,.262866,-.951056],[0,0,-1],[.295242,0,-.955423],[.16246,.262866,-.951056],[-.442863,-.238856,-.864188],[-.309017,-.5,-.809017],[-.16246,-.262866,-.951056],[0,-.850651,-.525731],[-.147621,-.716567,-.681718],[.147621,-.716567,-.681718],[0,-.525731,-.850651],[.309017,-.5,-.809017],[.442863,-.238856,-.864188],[.16246,-.262866,-.951056],[.238856,-.864188,-.442863],[.5,-.809017,-.309017],[.425325,-.688191,-.587785],[.716567,-.681718,-.147621],[.688191,-.587785,-.425325],[.587785,-.425325,-.688191],[0,-.955423,-.295242],[0,-1,0],[.262866,-.951056,-.16246],[0,-.850651,.525731],[0,-.955423,.295242],[.238856,-.864188,.442863],[.262866,-.951056,.16246],[.5,-.809017,.309017],[.716567,-.681718,.147621],[.525731,-.850651,0],[-.238856,-.864188,-.442863],[-.5,-.809017,-.309017],[-.262866,-.951056,-.16246],[-.850651,-.525731,0],[-.716567,-.681718,-.147621],[-.716567,-.681718,.147621],[-.525731,-.850651,0],[-.5,-.809017,.309017],[-.238856,-.864188,.442863],[-.262866,-.951056,.16246],[-.864188,-.442863,.238856],[-.809017,-.309017,.5],[-.688191,-.587785,.425325],[-.681718,-.147621,.716567],[-.442863,-.238856,.864188],[-.587785,-.425325,.688191],[-.309017,-.5,.809017],[-.147621,-.716567,.681718],[-.425325,-.688191,.587785],[-.16246,-.262866,.951056],[.442863,-.238856,.864188],[.16246,-.262866,.951056],[.309017,-.5,.809017],[.147621,-.716567,.681718],[0,-.525731,.850651],[.425325,-.688191,.587785],[.587785,-.425325,.688191],[.688191,-.587785,.425325],[-.955423,.295242,0],[-.951056,.16246,.262866],[-1,0,0],[-.850651,0,.525731],[-.955423,-.295242,0],[-.951056,-.16246,.262866],[-.864188,.442863,-.238856],[-.951056,.16246,-.262866],[-.809017,.309017,-.5],[-.864188,-.442863,-.238856],[-.951056,-.16246,-.262866],[-.809017,-.309017,-.5],[-.681718,.147621,-.716567],[-.681718,-.147621,-.716567],[-.850651,0,-.525731],[-.688191,.587785,-.425325],[-.587785,.425325,-.688191],[-.425325,.688191,-.587785],[-.425325,-.688191,-.587785],[-.587785,-.425325,-.688191],[-.688191,-.587785,-.425325]];function Bl(){return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function va(t,e){let r=e.x,n=e.y,i=e.z;return{x:t[0]*r+t[4]*n+t[8]*i+t[12],y:t[1]*r+t[5]*n+t[9]*i+t[13],z:t[2]*r+t[6]*n+t[10]*i+t[14]}}function Sa(t,e){let r=Bl();return r[0]=e[0].x,r[1]=e[0].y,r[2]=e[0].z,r[4]=e[1].x,r[5]=e[1].y,r[6]=e[1].z,r[8]=e[2].x,r[9]=e[2].y,r[10]=e[2].z,r[12]=t.x,r[13]=t.y,r[14]=t.z,r}var Ke=1,mt=2;var Jo=8,Zo=16,Dl=32;var Ol=16384;var di=65536,Ma=1<<17,Nl=1<<18,kl=1<<19,Ul=1<<20,Hl=1<<21,Vl=1<<22,Gl=1<<23,Jf=1<<24,ui=1<<25,Wl=1<<26,Zf=1<<27,em=1<<28,tm=1<<29,fi=1<<30,rm=1<<31;var Kr=0;var _a=4,Aa=8,wa=16,La=32,Ea=64;var nm=1<<25,im=1<<28,om=1<<29,sm=1<<30,am=1<<31;var cm=Ke|mt,lm=Ke|di|mt|ui|fi,dm=Ke|di|mt,um=Ke|Ma|mt|ui|fi,fm=Dl|Jo|Zo,mm=Ke|Zo|Jo,Xl=Ke|ui|fi|mt|Wl,hm=Nl|kl|Ul|Hl|Vl|Gl,pm=Ke|Jo|Zo|ui|fi,ym=Ke|di|mt,gm=Ke|mt,xm=Ke|di|mt|Ma,bm=Xl|Ol;var vm=Number.MAX_SAFE_INTEGER-1;var mi=(t=>(t[t.None=0]="None",t[t.Archive=1]="Archive",t[t.UserInfo=2]="UserInfo",t[t.ServerInfo=4]="ServerInfo",t[t.Latch=8]="Latch",t[t.Cheat=16]="Cheat",t))(mi||{});var hi=256;var es=256,ts=8192,pi=2048,rs=512,ns=256,is=hi*2,os=256,$o=32,Xr=96;var Y=(t=>(t[t.Name=0]="Name",t[t.CdTrack=1]="CdTrack",t[t.Sky=2]="Sky",t[t.SkyAxis=3]="SkyAxis",t[t.SkyRotate=4]="SkyRotate",t[t.StatusBar=5]="StatusBar",t[t.AirAccel=59]="AirAccel",t[t.MaxClients=60]="MaxClients",t[t.MapChecksum=61]="MapChecksum",t[t.Models=62]="Models",t[t.Sounds=62+ts]="Sounds",t[t.Images=t.Sounds+pi]="Images",t[t.Lights=t.Images+rs]="Lights",t[t.ShadowLights=t.Lights+es]="ShadowLights",t[t.Items=t.ShadowLights+os]="Items",t[t.PlayerSkins=t.Items+ns]="PlayerSkins",t[t.General=t.PlayerSkins+hi]="General",t[t.WheelWeapons=t.General+is]="WheelWeapons",t[t.WheelAmmo=t.WheelWeapons+$o]="WheelAmmo",t[t.WheelPowerups=t.WheelAmmo+$o]="WheelPowerups",t[t.CdLoopCount=t.WheelPowerups+$o]="CdLoopCount",t[t.GameStyle=t.CdLoopCount+1]="GameStyle",t[t.MaxConfigStrings=t.GameStyle+1]="MaxConfigStrings",t))(Y||{}),Ia=Y.MaxConfigStrings;function Pa(t){return t>=5&&t<59?Xr*(59-t):t>=Y.General&&t<Y.WheelWeapons?Xr*(Y.MaxConfigStrings-t):Xr}var Kl={};ga(Kl,{addReplayFrame:()=>jl,createReplaySession:()=>$l,deserializeReplay:()=>ql,serializeReplay:()=>Yl});function Yl(t){return JSON.stringify(t,null,2)}function ql(t){let e=JSON.parse(t);if(!e.metadata||!Array.isArray(e.frames))throw new Error("Invalid replay format: missing metadata or frames");return e}function $l(t,e){return{metadata:{map:t,date:new Date().toISOString(),version:"1.0",seed:e},frames:[]}}function jl(t,e,r,n){t.frames.push({serverFrame:r,cmd:e,timestamp:Date.now()-n})}var H=(t=>(t[t.bad=0]="bad",t[t.muzzleflash=1]="muzzleflash",t[t.muzzleflash2=2]="muzzleflash2",t[t.temp_entity=3]="temp_entity",t[t.layout=4]="layout",t[t.inventory=5]="inventory",t[t.nop=6]="nop",t[t.disconnect=7]="disconnect",t[t.reconnect=8]="reconnect",t[t.sound=9]="sound",t[t.print=10]="print",t[t.stufftext=11]="stufftext",t[t.serverdata=12]="serverdata",t[t.configstring=13]="configstring",t[t.spawnbaseline=14]="spawnbaseline",t[t.centerprint=15]="centerprint",t[t.download=16]="download",t[t.playerinfo=17]="playerinfo",t[t.packetentities=18]="packetentities",t[t.deltapacketentities=19]="deltapacketentities",t[t.frame=20]="frame",t))(H||{});var I=(t=>(t[t.GUNSHOT=0]="GUNSHOT",t[t.BLOOD=1]="BLOOD",t[t.BLASTER=2]="BLASTER",t[t.RAILTRAIL=3]="RAILTRAIL",t[t.SHOTGUN=4]="SHOTGUN",t[t.EXPLOSION1=5]="EXPLOSION1",t[t.EXPLOSION2=6]="EXPLOSION2",t[t.ROCKET_EXPLOSION=7]="ROCKET_EXPLOSION",t[t.GRENADE_EXPLOSION=8]="GRENADE_EXPLOSION",t[t.SPARKS=9]="SPARKS",t[t.SPLASH=10]="SPLASH",t[t.BUBBLETRAIL=11]="BUBBLETRAIL",t[t.SCREEN_SPARKS=12]="SCREEN_SPARKS",t[t.SHIELD_SPARKS=13]="SHIELD_SPARKS",t[t.BULLET_SPARKS=14]="BULLET_SPARKS",t[t.LASER_SPARKS=15]="LASER_SPARKS",t[t.PARASITE_ATTACK=16]="PARASITE_ATTACK",t[t.ROCKET_EXPLOSION_WATER=17]="ROCKET_EXPLOSION_WATER",t[t.GRENADE_EXPLOSION_WATER=18]="GRENADE_EXPLOSION_WATER",t[t.MEDIC_CABLE_ATTACK=19]="MEDIC_CABLE_ATTACK",t[t.BFG_EXPLOSION=20]="BFG_EXPLOSION",t[t.BFG_BIGEXPLOSION=21]="BFG_BIGEXPLOSION",t[t.BOSSTPORT=22]="BOSSTPORT",t[t.BFG_LASER=23]="BFG_LASER",t[t.GRAPPLE_CABLE=24]="GRAPPLE_CABLE",t[t.WELDING_SPARKS=25]="WELDING_SPARKS",t[t.GREENBLOOD=26]="GREENBLOOD",t[t.BLUEHYPERBLASTER=27]="BLUEHYPERBLASTER",t[t.PLASMA_EXPLOSION=28]="PLASMA_EXPLOSION",t[t.TUNNEL_SPARKS=29]="TUNNEL_SPARKS",t[t.BLASTER2=30]="BLASTER2",t[t.RAILTRAIL2=31]="RAILTRAIL2",t[t.FLAME=32]="FLAME",t[t.LIGHTNING=33]="LIGHTNING",t[t.DEBUGTRAIL=34]="DEBUGTRAIL",t[t.PLAIN_EXPLOSION=35]="PLAIN_EXPLOSION",t[t.FLASHLIGHT=36]="FLASHLIGHT",t[t.FORCEWALL=37]="FORCEWALL",t[t.HEATBEAM=38]="HEATBEAM",t[t.MONSTER_HEATBEAM=39]="MONSTER_HEATBEAM",t[t.STEAM=40]="STEAM",t[t.BUBBLETRAIL2=41]="BUBBLETRAIL2",t[t.MOREBLOOD=42]="MOREBLOOD",t[t.HEATBEAM_SPARKS=43]="HEATBEAM_SPARKS",t[t.HEATBEAM_STEAM=44]="HEATBEAM_STEAM",t[t.CHAINFIST_SMOKE=45]="CHAINFIST_SMOKE",t[t.ELECTRIC_SPARKS=46]="ELECTRIC_SPARKS",t[t.TRACKER_EXPLOSION=47]="TRACKER_EXPLOSION",t[t.TELEPORT_EFFECT=48]="TELEPORT_EFFECT",t[t.DBALL_GOAL=49]="DBALL_GOAL",t[t.WIDOWBEAMOUT=50]="WIDOWBEAMOUT",t[t.NUKEBLAST=51]="NUKEBLAST",t[t.WIDOWSPLASH=52]="WIDOWSPLASH",t[t.EXPLOSION1_BIG=53]="EXPLOSION1_BIG",t[t.EXPLOSION1_NP=54]="EXPLOSION1_NP",t[t.FLECHETTE=55]="FLECHETTE",t[t.BLUEHYPERBLASTER_KEX=56]="BLUEHYPERBLASTER_KEX",t[t.BFG_ZAP=57]="BFG_ZAP",t[t.BERSERK_SLAM=58]="BERSERK_SLAM",t[t.GRAPPLE_CABLE_2=59]="GRAPPLE_CABLE_2",t[t.POWER_SPLASH=60]="POWER_SPLASH",t[t.LIGHTNING_BEAM=61]="LIGHTNING_BEAM",t[t.EXPLOSION1_NL=62]="EXPLOSION1_NL",t[t.EXPLOSION2_NL=63]="EXPLOSION2_NL",t))(I||{}),Ql={};ga(Ql,{U_ANGLE1:()=>id,U_ANGLE2:()=>od,U_ANGLE3:()=>sd,U_EFFECTS:()=>ld,U_EVENT:()=>fd,U_FRAME:()=>ad,U_MODEL:()=>Zl,U_MODEL2:()=>hd,U_MODEL3:()=>pd,U_MODEL4:()=>yd,U_MOREBITS:()=>md,U_NUMBER:()=>Jl,U_ORIGIN1:()=>td,U_ORIGIN2:()=>rd,U_ORIGIN3:()=>nd,U_REMOVE:()=>gd,U_RENDERFX:()=>dd,U_SKIN:()=>cd,U_SOLID:()=>ud,U_SOUND:()=>ed});var Jl=1,Zl=2,ed=4,td=8,rd=16,nd=32,id=64,od=128,sd=256,ad=512,cd=1024,ld=2048,dd=4096,ud=8192,fd=16384,md=32768,hd=1,pd=2,yd=4,gd=32768;var Ca=class{constructor(t){t instanceof Uint8Array?this.view=new DataView(t.buffer,t.byteOffset,t.byteLength):this.view=new DataView(t),this.offset=0,this.length=this.view.byteLength}getPosition(){return this.offset}seek(t){if(t<0||t>this.length)throw new Error(`Seek out of bounds: ${t} (length: ${this.length})`);this.offset=t}hasMore(){return this.offset<this.length}readChar(){let t=this.view.getInt8(this.offset);return this.offset+=1,t}readByte(){let t=this.view.getUint8(this.offset);return this.offset+=1,t}readShort(){let t=this.view.getInt16(this.offset,!0);return this.offset+=2,t}readLong(){let t=this.view.getInt32(this.offset,!0);return this.offset+=4,t}readFloat(){let t=this.view.getFloat32(this.offset,!0);return this.offset+=4,t}readString(){let t="";for(;this.offset<this.length;){let e=this.readChar();if(e===-1||e===0)break;t+=String.fromCharCode(e)}return t}readStringLine(){let t="";for(;this.offset<this.length;){let e=this.readChar();if(e===-1||e===0||e===10)break;t+=String.fromCharCode(e)}return t}readCoord(){return this.readShort()*(1/8)}readAngle(){return this.readChar()*(360/256)}readAngle16(){return this.readShort()*360/65536}readData(t){if(this.offset+t>this.length)throw new Error(`Read out of bounds: ${this.offset+t} (length: ${this.length})`);let e=new Uint8Array(this.view.buffer,this.view.byteOffset+this.offset,t);return this.offset+=t,new Uint8Array(e)}readPos(t){t.x=this.readCoord(),t.y=this.readCoord(),t.z=this.readCoord()}readDir(t){let e=this.readByte();if(e>=162){t.x=0,t.y=0,t.z=0;return}let r=Fl[e];t.x=r[0],t.y=r[1],t.z=r[2]}};var Yr=class{constructor({name:e,defaultValue:r,description:n,flags:i=mi.None,onChange:o}){this.modifiedCount=0;this.name=e,this.defaultValue=r,this.description=n,this.flags=i,this._value=r,this.onChange=o}get string(){return this._value}get number(){return Number(this._value)}get integer(){return Math.trunc(this.number)}get boolean(){return!!this.integer}set(e){if(this.flags&mi.Latch){if(e===this._value){this.latched=void 0;return}if(this.latched===e)return;this.latched!==e&&(this.latched=e);return}this.apply(e)}reset(){this.latched=void 0,this.apply(this.defaultValue)}applyLatched(){if(this.latched===void 0)return!1;let e=this.latched;return this.latched=void 0,e===this._value?!1:(this.apply(e),!0)}apply(e){if(this._value===e)return;let r=this._value;this._value=e,this.modifiedCount+=1,this.onChange?.(this,r)}},ar=class{constructor(){this.cvars=new Map}register(e){let r=this.cvars.get(e.name);if(r)return r;let n=new Yr(e);return this.cvars.set(e.name,n),n}get(e){return this.cvars.get(e)}setValue(e,r){let n=this.get(e);if(!n)throw new Error(`Unknown cvar: ${e}`);return n.set(r),n}resetAll(){for(let e of this.cvars.values())e.reset()}applyLatched(){let e=!1;for(let r of this.cvars.values())e=r.applyLatched()||e;return e}list(){return[...this.cvars.values()].sort((e,r)=>e.name.localeCompare(r.name))}};var cr=class{constructor(e,r,n={}){this.game=e;this.client=r;this.started=!1;this.commands=new or;this.cvars=new ar;this.stepSimulation=e=>{this.previousFrame=this.latestFrame,this.latestFrame=this.game.frame(e,this.latestCommand)};this.renderClient=e=>{this.client&&(this.latestCommand=this.client.render({...e,previous:this.previousFrame,latest:this.latestFrame}))};let i=n.loop?.now?.()??Date.now();this.startTimeMs=n.startTimeMs??n.loop?.startTimeMs??i,this.loop=new Dt({simulate:this.stepSimulation,render:this.renderClient},{...n.loop,startTimeMs:this.startTimeMs})}start(){if(!this.started){try{this.latestFrame=this.game.init(this.startTimeMs)??this.latestFrame,this.client?.init(this.latestFrame)}catch(e){throw this.game.shutdown(),this.client?.shutdown(),e}this.started=!0,this.loop.start()}}stop(){this.started&&(this.loop.stop(),this.client?.shutdown(),this.game.shutdown(),this.previousFrame=void 0,this.latestFrame=void 0,this.started=!1)}pump(e){this.loop.pump(e)}getLatestFrame(){return this.latestFrame}isRunning(){return this.loop.isRunning()}};function xd(t){if(t<0||t>=Y.MaxConfigStrings)throw new RangeError(`Configstring index ${t} is out of range (0-${Y.MaxConfigStrings-1})`)}function za(t,e){let r=Pa(t);if(e.length>r)throw new RangeError(`Configstring ${t} exceeds maximum length (${e.length} > ${r}); limit is ${Xr} chars per slot`)}var lr=class{constructor(){this.values=new Map;this.modelCursor=Y.Models;this.soundCursor=Y.Sounds;this.imageCursor=Y.Images;this.lightCursor=Y.Lights;this.shadowLightCursor=Y.ShadowLights;this.itemCursor=Y.Items;this.playerSkinCursor=Y.PlayerSkins;this.generalCursor=Y.General}set(e,r){return xd(e),za(e,r),this.values.set(e,r),e}get(e){return this.values.get(e)}getName(e){return this.get(e)}getAll(){let e=new Array(Ia).fill("");for(let[r,n]of this.values.entries())e[r]=n;return e}modelIndex(e){return this.register(e,Y.Models,ts,"modelCursor")}soundIndex(e){return this.register(e,Y.Sounds,pi,"soundCursor")}findSoundIndex(e){for(let r=Y.Sounds;r<Y.Sounds+pi;r+=1)if(this.values.get(r)===e)return r}imageIndex(e){return this.register(e,Y.Images,rs,"imageCursor")}lightIndex(e){return this.register(e,Y.Lights,es,"lightCursor")}shadowLightIndex(e){return this.register(e,Y.ShadowLights,os,"shadowLightCursor")}itemIndex(e){return this.register(e,Y.Items,ns,"itemCursor")}playerSkinIndex(e){return this.register(e,Y.PlayerSkins,hi,"playerSkinCursor")}generalIndex(e){return this.register(e,Y.General,is,"generalCursor")}register(e,r,n,i){for(let a=r;a<r+n;a+=1)if(this.values.get(a)===e)return a;let o=this[i],s=r+n;if(o>=s)throw new RangeError(`Out of configstring slots for range starting at ${r}`);return za(o,e),this.values.set(o,e),this[i]=o+1,o}};var dr=class{constructor(e){this.registry=e.registry,this.system=e.system,this.music=e.music,this.client=e.client}soundindex(e){return this.registry.registerName(e)}sound(e,r,n,i,o,s){this.system.play({entity:e,channel:r,soundIndex:n,volume:i,attenuation:o,timeOffsetMs:s}),this.triggerSubtitle(n)}positioned_sound(e,r,n,i){this.system.positionedSound(e,r,n,i),this.triggerSubtitle(r)}loop_sound(e,r,n,i,o){this.system.play({entity:e,channel:r,soundIndex:n,volume:i,attenuation:o,looping:!0}),this.triggerSubtitle(n)}stop_entity_sounds(e){this.system.stopEntitySounds(e)}set_listener(e){this.system.setListener(e)}play_music(e,r=!0){return this.music?this.music.play(e,{loop:r}):Promise.resolve()}pause_music(){this.music?.pause()}resume_music(){return this.music?.resume()??Promise.resolve()}stop_music(){this.music?.stop()}set_music_volume(e){this.music?.setVolume(e)}play_ambient(e,r,n){this.system.ambientSound(e,r,n),this.triggerSubtitle(r)}play_channel(e){this.system.play({...e}),this.triggerSubtitle(e.soundIndex)}triggerSubtitle(e){if(!this.client)return;let r=this.registry.getName(e);if(!r)return;let n=r.match(/\[(.*?)\]/);n&&this.client.showSubtitle(n[1],r)}};var qr=class{constructor(e,r){this.engine=e;this.host=r;this.started=!1}start(){this.started||(this.engine.init(),this.host.start(),this.started=!0)}stop(){this.started&&(this.host.stop(),this.engine.shutdown(),this.started=!1)}pump(e){this.host.pump(e)}getLatestFrame(){return this.host.getLatestFrame()}isRunning(){return this.started&&this.host.isRunning()}};function Ra(t,e,r,n,i){let o=new dr({...n,client:r}),s=new cr(e,r,i);return{runtime:new qr(t,s),audio:o}}var bd="PACK";function vd(t,e,r){let n=[];for(let i=0;i<r;i+=1){let o=t.getUint8(e+i);if(o===0)break;n.push(o)}return String.fromCharCode(...n)}function ie(t){return t.replace(/\\/g,"/").replace(/^\/+/,"").toLowerCase()}function Sd(){let t=new Uint32Array(256);for(let e=0;e<256;e+=1){let r=e;for(let n=0;n<8;n+=1)r=(r&1)!==0?3988292384^r>>>1:r>>>1;t[e]=r>>>0}return t}var Md=Sd();function Ta(t){let e=4294967295;for(let r=0;r<t.length;r+=1){let n=t[r];e=Md[(e^n)&255]^e>>>8}return(e^4294967295)>>>0}var Re=class extends Error{},ur=class t{constructor(e,r,n,i){this.name=e;this.buffer=r;this.entries=new Map(n.map(o=>[o.name,o])),this.checksum=i,this.size=r.byteLength}static fromArrayBuffer(e,r){let n=new DataView(r);if(r.byteLength<12)throw new Re("PAK buffer too small to contain header");let i=String.fromCharCode(n.getUint8(0),n.getUint8(1),n.getUint8(2),n.getUint8(3));if(i!==bd)throw new Re(`Invalid PAK header magic: ${i}`);let o=n.getInt32(4,!0),s=n.getInt32(8,!0);if(o<12)throw new Re(`Invalid directory offset: ${o}`);if(s<=0||s%64!==0)throw new Re(`Invalid directory length: ${s}`);if(o+s>r.byteLength)throw new Re("Directory exceeds buffer length");let c=s/64,l=[],d=new Map;for(let u=0;u<c;u+=1){let f=o+u*64,m=vd(n,f,56),p=ie(m),y=n.getInt32(f+56,!0),h=n.getInt32(f+60,!0);if(y<0||h<0||y+h>r.byteLength)throw new Re(`Invalid entry bounds for ${m||"<unnamed>"} (offset=${y}, length=${h})`);if(!p)throw new Re(`Entry ${u} has an empty name`);let g={name:p,offset:y,length:h};d.set(p,g)}return l.push(...d.values()),new t(e,r,l,Ta(new Uint8Array(r)))}getEntry(e){return this.entries.get(ie(e))}listEntries(){return Array.from(this.entries.values())}readFile(e){let r=this.getEntry(e);if(!r)throw new Re(`File not found in PAK: ${e}`);return new Uint8Array(this.buffer,r.offset,r.length)}validate(){return{checksum:this.checksum,entries:this.listEntries()}}};function Fa(t){return Ta(new Uint8Array(t))}var yi=class{constructor(e=[]){this.mounts=[];this.files=new Map;e.forEach(r=>this.mountPak(r))}mountPak(e){this.mounts.push(e);for(let r of e.listEntries()){let n=ie(r.name);this.files.set(n,{archive:e,entry:r})}}get mountedPaks(){return[...this.mounts]}hasFile(e){return this.files.has(ie(e))}stat(e){let r=this.files.get(ie(e));if(r)return{path:r.entry.name,size:r.entry.length,sourcePak:r.archive.name}}async readFile(e){let r=this.files.get(ie(e));if(!r)throw new Error(`File not found in VFS: ${e}`);return r.archive.readFile(e)}list(e=""){let r=ie(e).replace(/\/+$|^\//g,""),n=[],i=new Set,o=r?`${r}/`:"";for(let s of this.files.values()){if(r&&!s.entry.name.startsWith(o))continue;let a=r?s.entry.name.slice(o.length):s.entry.name,c=a.indexOf("/");c===-1?n.push({path:s.entry.name,size:s.entry.length,sourcePak:s.archive.name}):i.add(a.slice(0,c))}return n.sort((s,a)=>s.path.localeCompare(a.path)),{files:n,directories:[...i].sort()}}findByExtension(e){let r=e.startsWith(".")?e.toLowerCase():`.${e.toLowerCase()}`,n=[];for(let i of this.files.values())i.entry.name.toLowerCase().endsWith(r)&&n.push({path:i.entry.name,size:i.entry.length,sourcePak:i.archive.name});return n.sort((i,o)=>i.path.localeCompare(o.path))}};var ss=Object.freeze([{name:"pak0.pak",checksum:2378051181,description:"Base game assets"},{name:"pak0.pak@baseq2",checksum:2378051181,description:"Base game assets (baseq2)"},{name:"pak0.pak@rogue",checksum:3373211245,description:"Ground Zero (rogue) mission pack"},{name:"pak0.pak@xatrix",checksum:1358269824,description:"The Reckoning (xatrix) mission pack"}]),Ot=class extends Error{constructor(r){super(r.status==="unknown"?`Unknown PAK not allowed: ${r.name}`:`PAK checksum mismatch for ${r.name}`);this.result=r;this.name="PakValidationError"}},gi=class{constructor(e=ss){this.known=new Map;e.forEach(r=>this.known.set(this.normalizePakName(r.name),r))}validateArchive(e,r){let n=this.normalizePakName(r??("name"in e?e.name:"unknown")),i=e.checksum,o="size"in e?e.size:void 0,s=this.known.get(n);return s?s.checksum!==i?{name:n,checksum:i,expectedChecksum:s.checksum,status:"mismatch",size:o,description:s.description}:{name:n,checksum:i,expectedChecksum:s.checksum,status:"valid",size:o,description:s.description}:{name:n,checksum:i,status:"unknown",size:o}}assertValid(e,r){let n=this.validateArchive(e,r);if(n.status==="mismatch")throw new Ot(n);return n}normalizePakName(e){let r=ie(e),n=r.split("/"),i=n.pop()??r,o=n.pop();return o?`${i}@${o}`:i}};var ht=class extends Error{constructor(r,n){super(`Failed to ingest PAK: ${r}`);this.file=r;this.name="PakIngestionError",n instanceof Error&&n.stack&&(this.stack=n.stack),this.cause=n}};async function _d(t,e){if(typeof t.arrayBuffer=="function"){let r=await t.arrayBuffer();return e?.({file:"blob",loadedBytes:r.byteLength,totalBytes:r.byteLength,state:"reading"}),r}if(typeof FileReader<"u")return new Promise((r,n)=>{let i=new FileReader;i.onerror=()=>n(i.error??new Error("Unknown FileReader error")),i.onprogress=o=>{e?.({file:"blob",loadedBytes:o.loaded,totalBytes:o.total||t.size,state:"reading"})},i.onload=()=>{let o=i.result;o instanceof ArrayBuffer?r(o):n(new Error("Unexpected FileReader result"))},i.readAsArrayBuffer(t)});if(typeof Response<"u"){let r=await new Response(t).arrayBuffer();return e?.({file:"blob",loadedBytes:r.byteLength,totalBytes:r.byteLength,state:"reading"}),r}if(typeof t.stream=="function"){let r=t.stream().getReader(),n=[],i=0;for(;;){let{done:a,value:c}=await r.read();if(a)break;if(!c)continue;let l=c;n.push(l),i+=l.byteLength,e?.({file:"blob",loadedBytes:i,totalBytes:t.size,state:"reading"})}let o=new Uint8Array(i),s=0;for(let a of n)o.set(a,s),s+=a.byteLength;return o.buffer}throw new ht("blob",new Error("Unsupported Blob type"))}async function Ad(t,e){if(t.data instanceof ArrayBuffer)return e?.({file:t.name,loadedBytes:t.data.byteLength,totalBytes:t.data.byteLength,state:"reading"}),t.data;if(t.data instanceof Blob){let n=t.data.size;return _d(t.data,i=>e?.({...i,file:t.name,totalBytes:n}))}let r=t.data.buffer.slice(t.data.byteOffset,t.data.byteOffset+t.data.byteLength);return e?.({file:t.name,loadedBytes:r.byteLength,totalBytes:r.byteLength,state:"reading"}),r}async function xi(t,e,r){let n=typeof r=="function"?{onProgress:r}:r??{},i=n.persistIndexes??!!n.pakIndexStore,o=n.enforceValidation??!!n.validator,s=n.allowUnknownPaks??!0,a=n.stopOnError??!1,c=[];for(let l of e)try{let d=await Ad(l,n.onProgress),u=ur.fromArrayBuffer(l.name,d),f=n.validator?.validateArchive(u);if(f){n.onValidationResult?.(f);let m=f.status==="mismatch",p=f.status==="unknown";if(m&&o||p&&!s){let y=new Ot(f);if(n.onError?.(l.name,y),a)throw new ht(l.name,y);c.push({archive:u,mounted:!1,validation:f});continue}}if(t.mountPak(u),i&&n.pakIndexStore)try{await n.pakIndexStore.persist(u)}catch(m){if(n.onError?.(l.name,m),a)throw new ht(l.name,m)}n.onProgress?.({file:l.name,loadedBytes:d.byteLength,totalBytes:d.byteLength,state:"parsed"}),c.push({archive:u,mounted:!0,validation:f})}catch(d){if(n.onProgress?.({file:l.name,loadedBytes:0,totalBytes:0,state:"error"}),n.onError?.(l.name,d),a)throw new ht(l.name,d)}return c}var pt=class{constructor(e){this.capacity=e;this.map=new Map;if(e<=0)throw new RangeError("LRU cache capacity must be greater than zero")}get size(){return this.map.size}has(e){return this.map.has(e)}get(e){let r=this.map.get(e);if(r!==void 0)return this.map.delete(e),this.map.set(e,r),r}set(e,r){if(this.map.has(e)&&this.map.delete(e),this.map.set(e,r),this.map.size>this.capacity){let n=this.map.keys().next();n.done||this.map.delete(n.value)}}delete(e){return this.map.delete(e)}clear(){this.map.clear()}entries(){return Array.from(this.map.entries()).reverse().map(([e,r])=>({key:e,value:r}))}};function wd(t){return Array.isArray(t)?t:Array.from(t)}function as(t){return wd(t).map(e=>({name:e.name,data:e}))}async function Ba(t,e,r){let n=as(e);return xi(t,n,r??{})}function Da(t,e){let r=i=>{i.preventDefault(),i.dataTransfer?.dropEffect&&(i.dataTransfer.dropEffect="copy")},n=i=>{i.preventDefault();let o=i.dataTransfer?.files;o&&o.length>0&&e(Array.from(o))};return t.addEventListener("dragover",r),t.addEventListener("drop",n),()=>{t.removeEventListener("dragover",r),t.removeEventListener("drop",n)}}function Oa(t,e){let r=n=>{let i=n.target;!i||!i.files||i.files.length===0||(e(i.files),i.value="")};return t.addEventListener("change",r),()=>t.removeEventListener("change",r)}var Ld="IBSP",Ed=38,ka=19,Id=8+ka*8;var q=class extends Error{},fr=class{constructor(e){this.vfs=e}async load(e){let r=await this.vfs.readFile(e),n=new Uint8Array(r.byteLength);return n.set(r),cs(n.buffer)}};function cs(t){if(t.byteLength<Id)throw new q("BSP too small to contain header");let e=new DataView(t),r=String.fromCharCode(e.getUint8(0),e.getUint8(1),e.getUint8(2),e.getUint8(3));if(r!==Ld)throw new q(`Invalid BSP magic ${r}`);let n=e.getInt32(4,!0);if(n!==Ed)throw new q(`Unsupported BSP version ${n}`);let i=new Map;for(let A=0;A<ka;A+=1){let w=e.getInt32(8+A*8,!0),E=e.getInt32(12+A*8,!0);if(w<0||E<0||w+E>t.byteLength)throw new q(`Invalid lump bounds for index ${A}`);i.set(A,{offset:w,length:E})}let o={version:n,lumps:i},s=Cd(t,i.get(0)),a=Rd(t,i.get(1)),c=Td(t,i.get(2)),l=Fd(t,i.get(4)),d=Bd(t,i.get(5)),u=Dd(t,i.get(6)),f=new Uint8Array(t,i.get(7).offset,i.get(7).length),m=Xd(u,i.get(7)),p=Od(t,i.get(8)),y=Nd(t,i.get(11)),h=kd(t,i.get(12)),g=Ud(t,i.get(13)),S=Hd(t,i.get(14)),x=Vd(t,i.get(15)),v=Gd(t,i.get(9),i.get(10),p),b=Wd(t,i.get(3));return{header:o,entities:s,planes:a,vertices:c,nodes:l,texInfo:d,faces:u,lightMaps:f,lightMapInfo:m,leafs:p,leafLists:v,edges:y,surfEdges:h,models:g,brushes:S,brushSides:x,visibility:b,pickEntity(A){let w=null,E=1/0;for(let L of s.entities){let B=L.properties.model;if(!B||!B.startsWith("*"))continue;let O=parseInt(B.substring(1),10);if(isNaN(O)||O<0||O>=g.length)continue;let U=g[O],C=Pd(A.origin,A.direction,U.mins,U.maxs);C!==null&&C<E&&(E=C,w={entity:L,model:U,distance:C})}return w}}}function Pd(t,e,r,n){let i=0,o=1/0;for(let s=0;s<3;s++)if(Math.abs(e[s])<1e-8){if(t[s]<r[s]||t[s]>n[s])return null}else{let a=1/e[s],c=(r[s]-t[s])*a,l=(n[s]-t[s])*a;if(c>l){let d=c;c=l,l=d}if(i=Math.max(i,c),o=Math.min(o,l),i>o)return null}return i}function Cd(t,e){let r=new TextDecoder().decode(new Uint8Array(t,e.offset,e.length)),n=zd(r),i=n.find(o=>o.classname==="worldspawn");return{raw:r,entities:n,worldspawn:i,getUniqueClassnames(){let o=new Set;for(let s of n)s.classname&&o.add(s.classname);return Array.from(o).sort()}}}function zd(t){let e=[],r=/\{([^}]*)\}/gms,n;for(;(n=r.exec(t))!==null;){let i=n[1],o={},s=/"([^\"]*)"\s+"([^\"]*)"/g,a;for(;(a=s.exec(i))!==null;)o[a[1]]=a[2];e.push({classname:o.classname,properties:o})}return e}function Rd(t,e){let r=new DataView(t,e.offset,e.length),n=e.length/20;if(n%1!==0)throw new q("Plane lump has invalid length");let i=[];for(let o=0;o<n;o+=1){let s=[r.getFloat32(o*20,!0),r.getFloat32(o*20+4,!0),r.getFloat32(o*20+8,!0)],a=r.getFloat32(o*20+12,!0),c=r.getInt32(o*20+16,!0);i.push({normal:s,dist:a,type:c})}return i}function Td(t,e){let r=new DataView(t,e.offset,e.length),n=e.length/12;if(n%1!==0)throw new q("Vertex lump has invalid length");let i=[];for(let o=0;o<n;o+=1)i.push([r.getFloat32(o*12,!0),r.getFloat32(o*12+4,!0),r.getFloat32(o*12+8,!0)]);return i}function Fd(t,e){let r=new DataView(t,e.offset,e.length),n=28,i=e.length/n;if(i%1!==0)throw new q("Node lump has invalid length");let o=[];for(let s=0;s<i;s+=1){let a=s*n,c=r.getInt32(a,!0),l=[r.getInt32(a+4,!0),r.getInt32(a+8,!0)],d=[r.getInt16(a+12,!0),r.getInt16(a+14,!0),r.getInt16(a+16,!0)],u=[r.getInt16(a+18,!0),r.getInt16(a+20,!0),r.getInt16(a+22,!0)],f=r.getUint16(a+24,!0),m=r.getUint16(a+26,!0);o.push({planeIndex:c,children:l,mins:d,maxs:u,firstFace:f,numFaces:m})}return o}function Bd(t,e){let r=new DataView(t,e.offset,e.length),n=76,i=e.length/n;if(i%1!==0)throw new q("TexInfo lump has invalid length");let o=[];for(let s=0;s<i;s+=1){let a=s*n,c=[r.getFloat32(a,!0),r.getFloat32(a+4,!0),r.getFloat32(a+8,!0)],l=r.getFloat32(a+12,!0),d=[r.getFloat32(a+16,!0),r.getFloat32(a+20,!0),r.getFloat32(a+24,!0)],u=r.getFloat32(a+28,!0),f=r.getInt32(a+32,!0),m=r.getInt32(a+36,!0),p=new Uint8Array(t,e.offset+a+40,32),y=new TextDecoder("utf-8").decode(p).replace(/\0.*$/,""),h=r.getInt32(a+72,!0);o.push({s:c,sOffset:l,t:d,tOffset:u,flags:f,value:m,texture:y,nextTexInfo:h})}return o}function Dd(t,e){let r=new DataView(t,e.offset,e.length),n=20,i=e.length/n;if(i%1!==0)throw new q("Face lump has invalid length");let o=[];for(let s=0;s<i;s+=1){let a=s*n,c=r.getUint16(a,!0),l=r.getInt16(a+2,!0),d=r.getInt32(a+4,!0),u=r.getInt16(a+8,!0),f=r.getInt16(a+10,!0),m=[r.getUint8(a+12),r.getUint8(a+13),r.getUint8(a+14),r.getUint8(a+15)],p=r.getInt32(a+16,!0);o.push({planeIndex:c,side:l,firstEdge:d,numEdges:u,texInfo:f,styles:m,lightOffset:p})}return o}function Od(t,e){let r=new DataView(t,e.offset,e.length),n=28,i=e.length/n;if(i%1!==0)throw new q("Leaf lump has invalid length");let o=[];for(let s=0;s<i;s+=1){let a=s*n,c=r.getInt32(a,!0),l=r.getInt16(a+4,!0),d=r.getInt16(a+6,!0),u=[r.getInt16(a+8,!0),r.getInt16(a+10,!0),r.getInt16(a+12,!0)],f=[r.getInt16(a+14,!0),r.getInt16(a+16,!0),r.getInt16(a+18,!0)],m=r.getUint16(a+20,!0),p=r.getUint16(a+22,!0),y=r.getUint16(a+24,!0),h=r.getUint16(a+26,!0);o.push({contents:c,cluster:l,area:d,mins:u,maxs:f,firstLeafFace:m,numLeafFaces:p,firstLeafBrush:y,numLeafBrushes:h})}return o}function Nd(t,e){let r=new DataView(t,e.offset,e.length),n=4,i=e.length/n;if(i%1!==0)throw new q("Edge lump has invalid length");let o=[];for(let s=0;s<i;s+=1){let a=s*n;o.push({vertices:[r.getUint16(a,!0),r.getUint16(a+2,!0)]})}return o}function kd(t,e){let r=e.length/4;if(r%1!==0)throw new q("SurfEdge lump has invalid length");let n=new DataView(t,e.offset,e.length),i=new Int32Array(r);for(let o=0;o<r;o+=1)i[o]=n.getInt32(o*4,!0);return i}function Ud(t,e){let r=new DataView(t,e.offset,e.length),n=48;if(e.length%n!==0)throw new q("Model lump has invalid length");let i=e.length/n,o=[];for(let s=0;s<i;s+=1){let a=s*n,c=[r.getFloat32(a,!0),r.getFloat32(a+4,!0),r.getFloat32(a+8,!0)],l=[r.getFloat32(a+12,!0),r.getFloat32(a+16,!0),r.getFloat32(a+20,!0)],d=[r.getFloat32(a+24,!0),r.getFloat32(a+28,!0),r.getFloat32(a+32,!0)],u=r.getInt32(a+36,!0),f=r.getInt32(a+40,!0),m=r.getInt32(a+44,!0);o.push({mins:c,maxs:l,origin:d,headNode:u,firstFace:f,numFaces:m})}return o}function Hd(t,e){let r=new DataView(t,e.offset,e.length),n=12,i=e.length/n;if(i%1!==0)throw new q("Brush lump has invalid length");let o=[];for(let s=0;s<i;s+=1){let a=s*n;o.push({firstSide:r.getInt32(a,!0),numSides:r.getInt32(a+4,!0),contents:r.getInt32(a+8,!0)})}return o}function Vd(t,e){let r=new DataView(t,e.offset,e.length),n=4,i=e.length/n;if(i%1!==0)throw new q("Brush side lump has invalid length");let o=[];for(let s=0;s<i;s+=1){let a=s*n;o.push({planeIndex:r.getUint16(a,!0),texInfo:r.getInt16(a+2,!0)})}return o}function Gd(t,e,r,n){let i=[],o=[],s=e.length/2,a=r.length/2,c=new DataView(t,e.offset,e.length),l=new DataView(t,r.offset,r.length);for(let d of n){if(d.firstLeafFace+d.numLeafFaces>s)throw new q("Leaf faces reference data past lump bounds");if(d.firstLeafBrush+d.numLeafBrushes>a)throw new q("Leaf brushes reference data past lump bounds");let u=[];for(let m=0;m<d.numLeafFaces;m+=1)u.push(c.getUint16((d.firstLeafFace+m)*2,!0));let f=[];for(let m=0;m<d.numLeafBrushes;m+=1)f.push(l.getUint16((d.firstLeafBrush+m)*2,!0));i.push(u),o.push(f)}return{leafFaces:i,leafBrushes:o}}function Wd(t,e){if(e.length===0)return;if(e.length<4)throw new q("Visibility lump too small");let r=new DataView(t,e.offset,e.length),n=r.getInt32(0,!0),i=4+n*8;if(n<0||i>e.length)throw new q("Visibility lump truncated");let o=4,s=[];for(let a=0;a<n;a+=1){let c=r.getInt32(o,!0),l=r.getInt32(o+4,!0);o+=8;let d=e.offset+c,u=e.offset+l,f=e.offset+e.length;if(c<0||l<0||d>=f||u>=f)throw new q("Visibility offsets out of range");s.push({pvs:Na(t,d,n,e),phs:Na(t,u,n,e)})}return{numClusters:n,clusters:s}}function Na(t,e,r,n){let i=Math.ceil(r/8),o=new Uint8Array(i),s=new Uint8Array(t),a=e,c=0,l=n.offset+n.length;for(;c<i;){if(a>=l)throw new q("Visibility data truncated");let d=s[a++];if(d!==0){o[c++]=d;continue}if(a>=l)throw new q("Visibility run exceeds lump bounds");let u=s[a++];for(let f=0;f<u&&c<i;f+=1)o[c++]=0}return o}function Xd(t,e){return t.map(r=>{if(!(r.lightOffset<0))return{offset:r.lightOffset,length:Math.max(0,e.length-r.lightOffset)}})}function bi(t,e,r){if(t.lightOffset<0||t.lightOffset>=e.byteLength)return;let n=e.byteLength-t.lightOffset,i=Math.min(r?.length??n,n);if(!(i<=0))return e.subarray(t.lightOffset,t.lightOffset+i)}var Kd=844121161,Yd=8,Ua=68,qd=[{x:-.525731,y:0,z:.850651},{x:-.442863,y:.238856,z:.864188},{x:-.295242,y:0,z:.955423},{x:-.309017,y:.5,z:.809017},{x:-.16246,y:.262866,z:.951056},{x:0,y:0,z:1},{x:0,y:.850651,z:.525731},{x:-.147621,y:.716567,z:.681718},{x:.147621,y:.716567,z:.681718},{x:0,y:.525731,z:.850651},{x:.309017,y:.5,z:.809017},{x:.525731,y:0,z:.850651},{x:.295242,y:0,z:.955423},{x:.442863,y:.238856,z:.864188},{x:.16246,y:.262866,z:.951056},{x:-.681718,y:.147621,z:.716567},{x:-.809017,y:.309017,z:.5},{x:-.587785,y:.425325,z:.688191},{x:-.850651,y:.525731,z:0},{x:-.864188,y:.442863,z:.238856},{x:-.716567,y:.681718,z:.147621},{x:-.688191,y:.587785,z:.425325},{x:-.5,y:.809017,z:.309017},{x:-.238856,y:.864188,z:.442863},{x:-.425325,y:.688191,z:.587785},{x:-.716567,y:.681718,z:-.147621},{x:-.5,y:.809017,z:-.309017},{x:-.525731,y:.850651,z:0},{x:0,y:.850651,z:-.525731},{x:-.238856,y:.864188,z:-.442863},{x:0,y:.955423,z:-.295242},{x:-.262866,y:.951056,z:-.16246},{x:0,y:1,z:0},{x:0,y:.955423,z:.295242},{x:-.262866,y:.951056,z:.16246},{x:.238856,y:.864188,z:.442863},{x:.262866,y:.951056,z:.16246},{x:.5,y:.809017,z:.309017},{x:.238856,y:.864188,z:-.442863},{x:.262866,y:.951056,z:-.16246},{x:.5,y:.809017,z:-.309017},{x:.850651,y:.525731,z:0},{x:.716567,y:.681718,z:.147621},{x:.716567,y:.681718,z:-.147621},{x:.525731,y:.850651,z:0},{x:.425325,y:.688191,z:.587785},{x:.864188,y:.442863,z:.238856},{x:.688191,y:.587785,z:.425325},{x:.809017,y:.309017,z:.5},{x:.681718,y:.147621,z:.716567},{x:.587785,y:.425325,z:.688191},{x:.955423,y:.295242,z:0},{x:1,y:0,z:0},{x:.951056,y:.16246,z:.262866},{x:.850651,y:-.525731,z:0},{x:.955423,y:-.295242,z:0},{x:.864188,y:-.442863,z:.238856},{x:.951056,y:-.16246,z:.262866},{x:.809017,y:-.309017,z:.5},{x:.681718,y:-.147621,z:.716567},{x:.850651,y:0,z:.525731},{x:.864188,y:.442863,z:-.238856},{x:.809017,y:.309017,z:-.5},{x:.951056,y:.16246,z:-.262866},{x:.525731,y:0,z:-.850651},{x:.681718,y:.147621,z:-.716567},{x:.681718,y:-.147621,z:-.716567},{x:.850651,y:0,z:-.525731},{x:.809017,y:-.309017,z:-.5},{x:.864188,y:-.442863,z:-.238856},{x:.951056,y:-.16246,z:-.262866},{x:.147621,y:.716567,z:-.681718},{x:.309017,y:.5,z:-.809017},{x:.425325,y:.688191,z:-.587785},{x:.442863,y:.238856,z:-.864188},{x:.587785,y:.425325,z:-.688191},{x:.688191,y:.587785,z:-.425325},{x:-.147621,y:.716567,z:-.681718},{x:-.309017,y:.5,z:-.809017},{x:0,y:.525731,z:-.850651},{x:-.525731,y:0,z:-.850651},{x:-.442863,y:.238856,z:-.864188},{x:-.295242,y:0,z:-.955423},{x:-.16246,y:.262866,z:-.951056},{x:0,y:0,z:-1},{x:.295242,y:0,z:-.955423},{x:.16246,y:.262866,z:-.951056},{x:-.442863,y:-.238856,z:-.864188},{x:-.309017,y:-.5,z:-.809017},{x:-.16246,y:-.262866,z:-.951056},{x:0,y:-.850651,z:-.525731},{x:-.147621,y:-.716567,z:-.681718},{x:.147621,y:-.716567,z:-.681718},{x:0,y:-.525731,z:-.850651},{x:.309017,y:-.5,z:-.809017},{x:.442863,y:-.238856,z:-.864188},{x:.16246,y:-.262866,z:-.951056},{x:.238856,y:-.864188,z:-.442863},{x:.5,y:-.809017,z:-.309017},{x:.425325,y:-.688191,z:-.587785},{x:.716567,y:-.681718,z:-.147621},{x:.688191,y:-.587785,z:-.425325},{x:.587785,y:-.425325,z:-.688191},{x:0,y:-.955423,z:-.295242},{x:0,y:-1,z:0},{x:.262866,y:-.951056,z:-.16246},{x:0,y:-.850651,z:.525731},{x:0,y:-.955423,z:.295242},{x:.238856,y:-.864188,z:.442863},{x:.262866,y:-.951056,z:.16246},{x:.5,y:-.809017,z:.309017},{x:.716567,y:-.681718,z:.147621},{x:.525731,y:-.850651,z:0},{x:-.238856,y:-.864188,z:-.442863},{x:-.5,y:-.809017,z:-.309017},{x:-.262866,y:-.951056,z:-.16246},{x:-.850651,y:-.525731,z:0},{x:-.716567,y:-.681718,z:-.147621},{x:-.716567,y:-.681718,z:.147621},{x:-.525731,y:-.850651,z:0},{x:-.5,y:-.809017,z:.309017},{x:-.238856,y:-.864188,z:.442863},{x:-.262866,y:-.951056,z:.16246},{x:-.864188,y:-.442863,z:.238856},{x:-.809017,y:-.309017,z:.5},{x:-.688191,y:-.587785,z:.425325},{x:-.681718,y:-.147621,z:.716567},{x:-.442863,y:-.238856,z:.864188},{x:-.587785,y:-.425325,z:.688191},{x:-.309017,y:-.5,z:.809017},{x:-.147621,y:-.716567,z:.681718},{x:-.425325,y:-.688191,z:.587785},{x:-.16246,y:-.262866,z:.951056},{x:.442863,y:-.238856,z:.864188},{x:.16246,y:-.262866,z:.951056},{x:.309017,y:-.5,z:.809017},{x:.147621,y:-.716567,z:.681718},{x:0,y:-.525731,z:.850651},{x:.425325,y:-.688191,z:.587785},{x:.587785,y:-.425325,z:.688191},{x:.688191,y:-.587785,z:.425325},{x:-.955423,y:.295242,z:0},{x:-.951056,y:.16246,z:.262866},{x:-1,y:0,z:0},{x:-.850651,y:0,z:.525731},{x:-.955423,y:-.295242,z:0},{x:-.951056,y:-.16246,z:.262866},{x:-.864188,y:.442863,z:-.238856},{x:-.951056,y:.16246,z:-.262866},{x:-.809017,y:.309017,z:-.5},{x:-.864188,y:-.442863,z:-.238856},{x:-.951056,y:-.16246,z:-.262866},{x:-.809017,y:-.309017,z:-.5},{x:-.681718,y:.147621,z:-.716567},{x:-.681718,y:-.147621,z:-.716567},{x:-.850651,y:0,z:-.525731},{x:-.688191,y:.587785,z:-.425325},{x:-.587785,y:.425325,z:-.688191},{x:-.425325,y:.688191,z:-.587785},{x:-.425325,y:-.688191,z:-.587785},{x:-.587785,y:-.425325,z:-.688191},{x:-.688191,y:-.587785,z:-.425325}],le=class extends Error{},mr=class{constructor(e){this.vfs=e;this.cache=new Map}async load(e){if(this.cache.has(e))return this.cache.get(e);let r=await this.vfs.readFile(e),n=new Uint8Array(r.byteLength);n.set(r);let i=ls(n.buffer);return this.cache.set(e,i),i}get(e){return this.cache.get(e)}};function Ha(t,e,r){let n=[];for(let i=0;i<r;i+=1){let o=t.getUint8(e+i);if(o===0)break;n.push(o)}return String.fromCharCode(...n)}function $r(t,e,r,n){if(r!==0&&(e<Ua||e+r>t.byteLength))throw new le(`${n} section is out of bounds`)}function $d(t){if(t.byteLength<Ua)throw new le("MD2 buffer too small to contain header");let e=new DataView(t),r=e.getInt32(0,!0),n=e.getInt32(4,!0);if(r!==Kd)throw new le(`Invalid MD2 ident: ${r}`);if(n!==Yd)throw new le(`Unsupported MD2 version: ${n}`);let i={ident:r,version:n,skinWidth:e.getInt32(8,!0),skinHeight:e.getInt32(12,!0),frameSize:e.getInt32(16,!0),numSkins:e.getInt32(20,!0),numVertices:e.getInt32(24,!0),numTexCoords:e.getInt32(28,!0),numTriangles:e.getInt32(32,!0),numGlCommands:e.getInt32(36,!0),numFrames:e.getInt32(40,!0),offsetSkins:e.getInt32(44,!0),offsetTexCoords:e.getInt32(48,!0),offsetTriangles:e.getInt32(52,!0),offsetFrames:e.getInt32(56,!0),offsetGlCommands:e.getInt32(60,!0),offsetEnd:e.getInt32(64,!0),magic:r},o=40+i.numVertices*4;if(i.frameSize!==o)throw new le(`Unexpected frame size ${i.frameSize}, expected ${o}`);if(i.offsetEnd>t.byteLength)throw new le("MD2 offset_end exceeds buffer length");return i}function jd(t,e){let r=e.numSkins*64;$r(t,e.offsetSkins,r,"skins");let n=new DataView(t,e.offsetSkins,r),i=[];for(let o=0;o<e.numSkins;o+=1)i.push({name:Ha(n,o*64,64)});return i}function Qd(t,e){let r=e.numTexCoords*4;$r(t,e.offsetTexCoords,r,"texcoords");let n=new DataView(t,e.offsetTexCoords,r),i=[];for(let o=0;o<e.numTexCoords;o+=1){let s=o*4;i.push({s:n.getInt16(s,!0),t:n.getInt16(s+2,!0)})}return i}function Jd(t,e){let r=e.numTriangles*12;$r(t,e.offsetTriangles,r,"triangles");let n=new DataView(t,e.offsetTriangles,r),i=[];for(let o=0;o<e.numTriangles;o+=1){let s=o*12,a=[n.getUint16(s,!0),n.getUint16(s+2,!0),n.getUint16(s+4,!0)],c=[n.getUint16(s+6,!0),n.getUint16(s+8,!0),n.getUint16(s+10,!0)];if(a.some(l=>l>=e.numVertices)||c.some(l=>l>=e.numTexCoords))throw new le("Triangle references out of range vertex or texcoord");i.push({vertexIndices:a,texCoordIndices:c})}return i}function Zd(t,e){let r=e.numFrames*e.frameSize;$r(t,e.offsetFrames,r,"frames");let n=[];for(let i=0;i<e.numFrames;i+=1){let o=e.offsetFrames+i*e.frameSize,s=new DataView(t,o,e.frameSize),a={x:s.getFloat32(0,!0),y:s.getFloat32(4,!0),z:s.getFloat32(8,!0)},c={x:s.getFloat32(12,!0),y:s.getFloat32(16,!0),z:s.getFloat32(20,!0)},l=Ha(s,24,16),d=[],u=1/0,f=1/0,m=1/0,p=-1/0,y=-1/0,h=-1/0;for(let g=0;g<e.numVertices;g+=1){let S=40+g*4,x=s.getUint8(S)*a.x+c.x,v=s.getUint8(S+1)*a.y+c.y,b=s.getUint8(S+2)*a.z+c.z;x<u&&(u=x),v<f&&(f=v),b<m&&(m=b),x>p&&(p=x),v>y&&(y=v),b>h&&(h=b);let _={x,y:v,z:b},A=s.getUint8(S+3),w=qd[A];if(!w)throw new le(`Invalid normal index ${A} in frame ${l}`);d.push({position:_,normalIndex:A,normal:w})}n.push({name:l,vertices:d,minBounds:{x:u,y:f,z:m},maxBounds:{x:p,y,z:h}})}return n}function e0(t,e){let r=e.numGlCommands*4;if($r(t,e.offsetGlCommands,r,"gl commands"),r===0)return[];let n=new DataView(t,e.offsetGlCommands,r),i=[],o=0;for(;;){if(o+4>r)throw new le("GL command list ended unexpectedly");let s=n.getInt32(o,!0);if(o+=4,s===0)break;let a=Math.abs(s),c=[],l=a*12;if(o+l>r)throw new le("GL command vertex block exceeds buffer");for(let d=0;d<a;d+=1){let u=n.getFloat32(o,!0),f=n.getFloat32(o+4,!0),m=n.getInt32(o+8,!0);if(o+=12,m<0||m>=e.numVertices)throw new le("GL command references invalid vertex index");c.push({s:u,t:f,vertexIndex:m})}i.push({mode:s>0?"strip":"fan",vertices:c})}if(o!==r)throw new le("GL command list did not consume expected data");return i}function ls(t){let e=$d(t),r=jd(t,e),n=Qd(t,e),i=Jd(t,e),o=Zd(t,e),s=e0(t,e);return{header:e,skins:r,texCoords:n,triangles:i,frames:o,glCommands:s}}function Va(t){let e=[],r=0;for(;r<t.length;){let n=t[r].name,i=n.replace(/\d+$/,"")||n,o=r;for(;o+1<t.length&&(t[o+1].name.replace(/\d+$/,"")||t[o+1].name)===i;)o+=1;e.push({name:i,firstFrame:r,lastFrame:o}),r=o+1}return e}var Ga=860898377,t0=15,Te=class extends Error{constructor(e){super(e),this.name="Md3ParseError"}};function jr(t,e,r){let n=new Uint8Array(t.buffer,t.byteOffset+e,r);return new TextDecoder("utf-8").decode(n).replace(/\0.*$/,"").trim()}function r0(t){let e=(t>>8&255)*(2*Math.PI/255),r=(t&255)*(2*Math.PI/255),n=Math.sin(r);return{x:Math.cos(e)*n,y:Math.sin(e)*n,z:Math.cos(r)}}function vi(t,e,r,n){if(e<0||e+r>n)throw new Te(`${t} exceeds buffer bounds`)}function n0(t){let e=t.getInt32(0,!0);if(e!==Ga)throw new Te(`Invalid MD3 ident: ${e}`);let r=t.getInt32(4,!0);if(r!==t0)throw new Te(`Unsupported MD3 version: ${r}`);let n=jr(t,8,64),i=t.getInt32(72,!0),o=t.getInt32(76,!0),s=t.getInt32(80,!0),a=t.getInt32(84,!0),c=t.getInt32(88,!0),l=t.getInt32(92,!0),d=t.getInt32(96,!0),u=t.getInt32(100,!0),f=t.getInt32(104,!0);if(o<=0||a<0||s<0)throw new Te("Invalid MD3 counts");return{ident:e,version:r,name:n,flags:i,numFrames:o,numTags:s,numSurfaces:a,numSkins:c,ofsFrames:l,ofsTags:d,ofsSurfaces:u,ofsEnd:f,magic:e}}function i0(t,e){let r=[];vi("Frames",e.ofsFrames,e.numFrames*56,t.byteLength);for(let i=0;i<e.numFrames;i+=1){let o=e.ofsFrames+i*56;r.push({minBounds:{x:t.getFloat32(o,!0),y:t.getFloat32(o+4,!0),z:t.getFloat32(o+8,!0)},maxBounds:{x:t.getFloat32(o+12,!0),y:t.getFloat32(o+16,!0),z:t.getFloat32(o+20,!0)},localOrigin:{x:t.getFloat32(o+24,!0),y:t.getFloat32(o+28,!0),z:t.getFloat32(o+32,!0)},radius:t.getFloat32(o+36,!0),name:jr(t,o+40,16)})}return r}function o0(t,e){let r=[],i=e.numFrames*e.numTags*112;vi("Tags",e.ofsTags,i,t.byteLength);for(let o=0;o<e.numFrames;o+=1){let s=[];for(let a=0;a<e.numTags;a+=1){let c=e.ofsTags+(o*e.numTags+a)*112,l=c+64,d=l+12;s.push({name:jr(t,c,64),origin:{x:t.getFloat32(l,!0),y:t.getFloat32(l+4,!0),z:t.getFloat32(l+8,!0)},axis:[{x:t.getFloat32(d,!0),y:t.getFloat32(d+4,!0),z:t.getFloat32(d+8,!0)},{x:t.getFloat32(d+12,!0),y:t.getFloat32(d+16,!0),z:t.getFloat32(d+20,!0)},{x:t.getFloat32(d+24,!0),y:t.getFloat32(d+28,!0),z:t.getFloat32(d+32,!0)}]})}r.push(s)}return r}function s0(t,e){let r=t.getInt32(e,!0);if(r!==Ga)throw new Te(`Invalid surface ident at ${e}: ${r}`);let n=jr(t,e+4,64),i=t.getInt32(e+68,!0),o=t.getInt32(e+72,!0),s=t.getInt32(e+76,!0),a=t.getInt32(e+80,!0),c=t.getInt32(e+84,!0),l=t.getInt32(e+88,!0),d=t.getInt32(e+92,!0),u=t.getInt32(e+96,!0),f=t.getInt32(e+100,!0),m=t.getInt32(e+104,!0);if(o<=0||a<=0||c<=0)throw new Te(`Invalid surface counts for ${n}`);let p=m;vi(`Surface ${n}`,e,p,t.byteLength);let y=[],h=e+l;for(let A=0;A<c;A+=1){let w=h+A*12;y.push({indices:[t.getInt32(w,!0),t.getInt32(w+4,!0),t.getInt32(w+8,!0)]})}let g=[],S=e+d;for(let A=0;A<s;A+=1){let w=S+A*68;g.push({name:jr(t,w,64),shaderIndex:t.getInt32(w+64,!0)})}let x=[],v=e+u;for(let A=0;A<a;A+=1){let w=v+A*8;x.push({s:t.getFloat32(w,!0),t:t.getFloat32(w+4,!0)})}let b=[],_=e+f;for(let A=0;A<o;A+=1){let w=[];for(let E=0;E<a;E+=1){let L=_+(A*a+E)*8,B=t.getInt16(L,!0)/64,O=t.getInt16(L+2,!0)/64,U=t.getInt16(L+4,!0)/64,C=t.getUint16(L+6,!0);w.push({position:{x:B,y:O,z:U},latLng:C,normal:r0(C)})}b.push(w)}return{surface:{name:n,flags:i,numFrames:o,shaders:g,triangles:y,texCoords:x,vertices:b},nextOffset:e+m}}function ds(t){if(t.byteLength<108)throw new Te("MD3 buffer too small for header");let e=new DataView(t),r=n0(e);vi("MD3 end",r.ofsEnd,0,t.byteLength);let n=i0(e,r),i=o0(e,r),o=[],s=r.ofsSurfaces;for(let a=0;a<r.numSurfaces;a+=1){let{surface:c,nextOffset:l}=s0(e,s);o.push(c),s=l}if(s!==r.ofsEnd)throw new Te("Surface parsing did not reach ofsEnd");return{header:r,frames:n,tags:i,surfaces:o}}var hr=class{constructor(e){this.vfs=e;this.cache=new Map}async load(e){if(this.cache.has(e))return this.cache.get(e);let r=await this.vfs.readFile(e),n=ds(r.slice().buffer);return this.cache.set(e,n),n}get(e){return this.cache.get(e)}};var a0=844317769,c0=2,Wa=64,Xa=12,yt=class extends Error{};function l0(t,e,r){let n=[];for(let i=0;i<r;i+=1){let o=t.getUint8(e+i);if(o===0)break;n.push(o)}return String.fromCharCode(...n)}function us(t){if(t.byteLength<Xa)throw new yt("Sprite buffer too small to contain header");let e=new DataView(t),r=e.getInt32(0,!0),n=e.getInt32(4,!0),i=e.getInt32(8,!0);if(r!==a0)throw new yt(`Invalid Sprite ident: ${r}`);if(n!==c0)throw new yt(`Unsupported Sprite version: ${n}`);let o=[],s=16+Wa,a=Xa;for(let c=0;c<i;c+=1){if(a+s>t.byteLength)throw new yt("Sprite frame data exceeds buffer length");let l=e.getInt32(a,!0),d=e.getInt32(a+4,!0),u=e.getInt32(a+8,!0),f=e.getInt32(a+12,!0),m=l0(e,a+16,Wa);o.push({width:l,height:d,originX:u,originY:f,name:m}),a+=s}return{ident:r,version:n,numFrames:i,frames:o}}var pr=class{constructor(e){this.vfs=e}async load(e){let r=await this.vfs.readFile(e),n=new Uint8Array(r.byteLength);return n.set(r),us(n.buffer)}};function Ka(t,e){let r=(t.sequence.end-t.sequence.start+1)/t.sequence.fps,n=t.sequence.loop!==!1,i=t.time+e;return n?i=(i%r+r)%r:i>r&&(i=r),{...t,time:Math.max(0,Math.min(i,r))}}function Ya(t){let e=t.sequence.end-t.sequence.start+1,r=1/t.sequence.fps,n=t.sequence.loop!==!1,i=t.time/r;if(!n&&i>=e)return{frame0:t.sequence.end,frame1:t.sequence.end,lerp:0};let o=n?i%e:Math.min(i,e-1),s=Math.floor(o),a=t.sequence.start+s,c=s+1>=e?n?t.sequence.start:t.sequence.end:a+1,l=!n&&s>=e-1?0:o-s;return{frame0:a,frame1:c,lerp:l}}function qa(t){return{sequence:t,time:0}}function $a(t,e,r){return{x:t.x+(e.x-t.x)*r,y:t.y+(e.y-t.y)*r,z:t.z+(e.z-t.z)*r}}var Qr=class extends Error{constructor(e){super(e),this.name="WalParseError"}};function Si(t){if(t.byteLength<100)throw new Qr("WAL buffer too small");let e=new DataView(t),r=new Uint8Array(t,0,32),n=new TextDecoder("utf-8").decode(r).replace(/\0.*$/,"").trim(),i=e.getInt32(32,!0),o=e.getInt32(36,!0),s=[e.getInt32(40,!0),e.getInt32(44,!0),e.getInt32(48,!0),e.getInt32(52,!0)],a=new Uint8Array(t,56,32),c=new TextDecoder("utf-8").decode(a).replace(/\0.*$/,"").trim(),l=e.getInt32(88,!0),d=e.getInt32(92,!0),u=e.getInt32(96,!0);if(i<=0||o<=0)throw new Qr("Invalid WAL dimensions");let f=[],m=i,p=o;for(let y=0;y<s.length;y+=1){let h=s[y],g=Math.max(1,m*p|0);if(h<=0||h+g>t.byteLength)throw new Qr(`Invalid WAL mip offset for level ${y}`);let S=new Uint8Array(t,h,g);f.push({level:y,width:m,height:p,data:S}),m=Math.max(1,m>>1),p=Math.max(1,p>>1)}return{name:n,width:i,height:o,mipmaps:f,animName:c,flags:l,contents:d,value:u}}var Nt=class extends Error{constructor(e){super(e),this.name="PcxParseError"}};function Jr(t){if(t.byteLength<128)throw new Nt("PCX buffer too small for header");let e=new DataView(t),r=e.getUint8(0),n=e.getUint8(2),i=e.getUint8(3),o=e.getUint16(4,!0),s=e.getUint16(6,!0),a=e.getUint16(8,!0),c=e.getUint16(10,!0);if(r!==10||n!==1)throw new Nt("Unsupported PCX encoding");if(i!==8)throw new Nt("Only 8bpp PCX files are supported");let l=a-o+1,d=c-s+1,u=e.getUint16(66,!0),f=t.byteLength-769;if(f<128||new DataView(t,f,1).getUint8(0)!==12)throw new Nt("Missing PCX palette");let m=new Uint8Array(t,f+1,768),p=new Uint8Array(t,128,f-128),y=new Uint8Array(l*d),h=0,g=0;for(let S=0;S<d;S+=1){let x=0;for(;x<u&&h<p.length;){let v=1,b=p[h++];if((b&192)===192){if(v=b&63,h>=p.length)throw new Nt("Unexpected end of PCX RLE data");b=p[h++]}for(let _=0;_<v&&x<u;_+=1)x<l&&(y[g++]=b),x+=1}}return{width:l,height:d,bitsPerPixel:i,pixels:y,palette:m}}function Mi(t){let e=new Uint8Array(t.width*t.height*4);for(let r=0;r<t.pixels.length;r+=1){let n=t.pixels[r],i=n*3,o=r*4;e[o]=t.palette[i],e[o+1]=t.palette[i+1],e[o+2]=t.palette[i+2],e[o+3]=n===255?0:255}return e}var et=class extends Error{constructor(e){super(e),this.name="TgaParseError"}};function fs(t){let e=new DataView(t);if(t.byteLength<18)throw new et("Buffer too small for TGA header");let r=e.getUint8(0),n=e.getUint8(1),i=e.getUint8(2),o=e.getUint16(12,!0),s=e.getUint16(14,!0),a=e.getUint8(16),c=e.getUint8(17);if(i!==2&&i!==10&&i!==3&&i!==11)throw new et(`Unsupported TGA image type: ${i} (only RGB/Grayscale supported)`);if(a!==24&&a!==32&&a!==8)throw new et(`Unsupported pixel depth: ${a} (only 8, 24, 32 bpp supported)`);let l=i>=9,d=i===3||i===11,u=a/8,f=18+r;if(n===1){let x=e.getUint16(5,!0),v=e.getUint8(7);f+=x*(v/8)}let m=o*s,p=new Uint8Array(m*4),y=(c&32)!==0,h=0,g=new Uint8Array(t),S=x=>{if(d){let v=g[f++];p[x]=v,p[x+1]=v,p[x+2]=v,p[x+3]=255}else{let v=g[f++],b=g[f++],_=g[f++],A=a===32?g[f++]:255;p[x]=_,p[x+1]=b,p[x+2]=v,p[x+3]=A}};if(l){let x=0;for(;x<m;){if(f>=t.byteLength)throw new et("Unexpected end of TGA RLE data");let v=g[f++],b=(v&127)+1,_=(v&128)!==0;if(x+b>m)throw new et("TGA RLE packet exceeds image bounds");if(_){let A=d?g[f]:g[f+2],w=d?g[f]:g[f+1],E=g[f],L=d?255:a===32?g[f+3]:255;f+=u;for(let B=0;B<b;B++){let O=(x+B)*4;p[O]=A,p[O+1]=w,p[O+2]=E,p[O+3]=L}}else for(let A=0;A<b;A++)S((x+A)*4);x+=b}}else for(let x=0;x<m;x++){if(f>=t.byteLength)throw new et("Unexpected end of TGA data");S(x*4)}if(!y){let x=o*4,v=new Uint8Array(x);for(let b=0;b<s/2;b++){let _=b*x,A=(s-1-b)*x;v.set(p.subarray(_,_+x)),p.set(p.subarray(A,A+x),_),p.set(v,A)}}return{width:o,height:s,bitsPerPixel:32,pixels:p}}var yr=class{constructor(e={}){this.cache=new pt(e.capacity??128)}get size(){return this.cache.size}get(e){return this.cache.get(e.toLowerCase())}set(e,r){this.cache.set(e.toLowerCase(),r)}clear(){this.cache.clear()}};function ms(t,e){let r=[];for(let n of t.mipmaps){let i=new Uint8Array(n.width*n.height*4);for(let o=0;o<n.data.length;o+=1){let s=n.data[o],a=s*3,c=o*4;i[c]=e[a],i[c+1]=e[a+1],i[c+2]=e[a+2],i[c+3]=s===255?0:255}r.push({level:n.level,width:n.width,height:n.height,rgba:i})}return{width:t.width,height:t.height,levels:r,source:"wal"}}function _i(t){let e=Mi(t),r={level:0,width:t.width,height:t.height,rgba:e};return{width:t.width,height:t.height,levels:[r],source:"pcx"}}function ja(t){let e={level:0,width:t.width,height:t.height,rgba:t.pixels};return{width:t.width,height:t.height,levels:[e],source:"tga"}}function Ai(t,e){return ms(Si(t),e)}var kt=class extends Error{constructor(e){super(e),this.name="WavParseError"}};function hs(t,e,r){return new TextDecoder("ascii").decode(new Uint8Array(t.buffer,t.byteOffset+e,r))}function wi(t){if(t.byteLength<44)throw new kt("WAV buffer too small");let e=new DataView(t);if(hs(e,0,4)!=="RIFF"||hs(e,8,4)!=="WAVE")throw new kt("Invalid WAV header");let r=12,n=-1,i=-1,o=0,s=0;for(;r+8<=t.byteLength;){let p=hs(e,r,4),y=e.getUint32(r+4,!0),h=r+8;p==="fmt "?(n=h,o=y):p==="data"&&(i=h,s=y),r=h+y}if(n===-1||i===-1)throw new kt("Missing fmt or data chunk");let a=e.getUint16(n,!0),c=e.getUint16(n+2,!0),l=e.getUint32(n+4,!0),d=e.getUint16(n+14,!0);if(a!==1)throw new kt("Only PCM WAV is supported");let u=d/8,f=s/(u*c),m=new Float32Array(f*c);for(let p=0;p<f;p+=1)for(let y=0;y<c;y+=1){let h=p*c+y,g=i+h*u,S=0;if(d===8)S=e.getUint8(g),m[h]=(S-128)/128;else if(d===16)S=e.getInt16(g,!0),m[h]=S/32768;else if(d===24){let x=e.getUint8(g),v=e.getUint8(g+1),b=e.getInt8(g+2);S=x|v<<8|b<<16,m[h]=S/8388608}else throw new kt(`Unsupported bitsPerSample: ${d}`)}return{sampleRate:l,channels:c,bitsPerSample:d,samples:m}}var d0=(t,e=4294967295,r=79764919)=>{let n=new Int32Array(256),i,o,s,a=e;for(i=0;i<256;i++){for(s=i<<24,o=8;o>0;--o)s=2147483648&s?s<<1^r:s<<1;n[i]=s}for(i=0;i<t.length;i++)a=a<<8^n[255&(a>>24^t[i])];return a};var ps=(t,e=d0)=>{let r=h=>new Uint8Array(h.length/2).map(((g,S)=>parseInt(h.substring(2*S,2*(S+1)),16))),n=h=>r(h)[0],i=new Map;[,8364,,8218,402,8222,8230,8224,8225,710,8240,352,8249,338,,381,,,8216,8217,8220,8221,8226,8211,8212,732,8482,353,8250,339,,382,376].forEach(((h,g)=>i.set(h,g)));let o=new Uint8Array(t.length),s,a,c,l=!1,d=0,u=42,f=t.length>13&&t.substring(0,9)==="dynEncode",m=0;f&&(m=11,a=n(t.substring(9,m)),a<=1&&(m+=2,u=n(t.substring(11,m))),a===1&&(m+=8,c=(h=>new DataView(r(h).buffer).getInt32(0,!0))(t.substring(13,m))));let p=256-u;for(let h=m;h<t.length;h++)if(s=t.charCodeAt(h),s!==61||l){if(s===92&&h<t.length-5&&f){let g=t.charCodeAt(h+1);g!==117&&g!==85||(s=parseInt(t.substring(h+2,h+6),16),h+=5)}if(s>255){let g=i.get(s);g&&(s=g+127)}l&&(l=!1,s-=64),o[d++]=s<u&&s>0?s+p:s-u}else l=!0;let y=o.subarray(0,d);if(f&&a===1){let h=e(y);if(h!==c){let g="Decode failed crc32 validation";throw console.error("`simple-yenc`\n",g+`
2
2
  `,"Expected: "+c+"; Got: "+h+`
3
- `,"Visit https://github.com/eshaz/simple-yenc for more information"),Error(g)}}return y};function Z(){let t=Uint8Array,e=Float32Array;Z.modules||Object.defineProperties(Z,{modules:{value:new WeakMap},setModule:{value(r,n){Z.modules.set(r,Promise.resolve(n))}},getModule:{value(r,n){let i=Z.modules.get(r);return i||(n?i=WebAssembly.compile(ps(n)):(n=r.wasm,i=Z.inflateDynEncodeString(n).then(o=>WebAssembly.compile(o))),Z.modules.set(r,i)),i}},concatFloat32:{value(r,n){let i=new e(n),o=0,s=0;for(;o<r.length;)i.set(r[o],s),s+=r[o++].length;return i}},getDecodedAudio:{value:(r,n,i,o,s)=>({errors:r,channelData:n,samplesDecoded:i,sampleRate:o,bitDepth:s})},getDecodedAudioMultiChannel:{value(r,n,i,o,s,a){let c=[],l,d;for(l=0;l<i;l++){let u=[];for(d=0;d<n.length;)u.push(n[d++][l]||[]);c.push(Z.concatFloat32(u,o))}return Z.getDecodedAudio(r,c,o,s,a)}},inflateDynEncodeString:{value(r){return r=ps(r),new Promise(n=>{let i=String.raw`dynEncode012804c7886d(‰›•)((()>+ˆ*§§)§ˆ,§§§§)§ˆ+§§§)§+.-()(*)-+)(ˆ.7*§)i¸¸,3§(i¸¸,3/G+.••—š¡*(,˜ŽŽ(,3‡‡‰˜‡Š‰›+)2å:-œ),§H(P*DI*H(P*@I++hH)H*r,hH(H(P*<J,i)’^*<H,H(P*4’U((I-H(H*i0’J,^*DH+H-H*œšI+H,I*4)33H(H*H)“^*DH(H+H)^*@H+i§H)œi§›™3æ*).§K(iH“I/+§H,iHn,§H+i(H+i(rCJ0I,H*I-+hH,,hH(H-V)(i)œ’J.H.W)(i)’c)(H,i)“I,H-i*’I-4)33i(I.*hH(V)(H+n5(H(i*’I-i(I,i)I.+hH,i*’J+iHn,hi(I-i*I,+hH,H/’H-c)(H,iFn,hi(I,+hH,H0n5-H*V)(J(,hH/H(i)œ’J(H(V)(J(i)’c)(H)H(i)œ’H,c)(3H*i*’I*H,i)’I,4(3(-H(H,’W)(H-’I-H,i*’I,4)3(3(3H,H-’I1H+I,H.i)œH1V)(“J.i(v5(33H.-H(H,’i(c)(H,i*’I,4)333–)-§i*I*+§H*iHn,hiž73H,H(i)8(H+šJ+H)P*(H*’V)(J-“r,§H)P*,H.i)œ’H+H,“i)œ’V)(-H*i*’I*H+i)œI+H-H.’I.H,H-’i)œI,4)333Ã+)-§iø7i(^*(iü7I,*h+hH+iDn,h*hilI+i)I,+hH+,hH+iô7’H,c)(i)H+i´8’W)(œH,’I,H+i*’I+4)-+hH(H)8*J-i(p5.*h*h*hH-i')u,hH(P*(J+,hH(P*0J,H(P*,n50H+H,’H-b((3H(P*0i)’I.4)3H-i¨*n5*H-iÅ*s,hiž73H-i)œJ+V)&+I,H(H+V)æ,8(I.H(H*8*J-i(p51H-i)œJ+i¸7’V)(H(H+iø7’V)(8(’J/H(P*0J+s,hi73H+H,H.’J,’I.H(P*(m5(H.H(P*,s5.+hH,m5*H(P*(J.H+’H.H+H/“’U((b((H(H(P*0i)’J+^*0H,i)“I,4(3(3H(H.^*03H-i¨*o5)33i(73(3(3-H,H+i)žc)(H,i*’I,H+i)’I+4)33i)I-3H-3!2)0§K(i2“J,L(H,H(^*(H,H*^*4H,i(^*0H,i(^*DH,j(_*<H,H)P*(^*,H,H+P*(^*8*h*h+hH,i)8(I3i§I**h*h*h*h*h*h*hH,i*8(6+(),03H,j(_*@i*I-H,P*<J.i,’J(H,P*8J/s50H,H.i+’J0^*<i¦I*H.H,P*4J1’J.U(*H.U((J2›i')o5/H.U()I.H,H(^*<H0H1’U((H.i0œJ.i§›i0ži')™o5/H/H.H2šJ*H(’J.q50H,P*0J/H*’I-H,P*(J0,hH,P*,H-q,hi)I-423+hH*m5+H/H0’H(H1’U((b((H/i)’I/H(i)’I(H*i)“I*4(3(3H,H.^*<H,H-^*04*3iØ1U((5+i(I(i¨7i1^*(i$6iè1^*(i°7iè6^*(i¬7iÈ6^*(+hH(iÈ*n,hiÈ*I(+hH(i¨,n,hi¨,I(+hH(iØ,n,hiØ,I(+hH(iè,o,hH,i-’H(’i0c)(H(i*’I(4)33iè1i1H,i-’iÈ*8)Bi(I(+hH(ido,hH,i-’H(’i-c)(H(i*’I(4)33iÈ6iè6H,i-’iF8)BiØ1i)b((41-H,i-’H(’i/c)(H(i*’I(4)3(3(-H,i-’H(’i1c)(H(i*’I(4)3(3(-H,i-’H(’i0c)(H(i*’I(4)3(3(3H,H/^*0H,H(^*<3i(I*4*3H,H,i¸)’^*TH,H,iø-’^*PH,H,iX’^*LH,H,i(’^*HH,i-8(I(H,i-8(I-i¥I*H,i,8(I.H(iErH-iErš5)H(i©*’I1H-i)’I0i(i;H.i,’J(i(H(i(rCJ(“J*H*i;sCI*i¨1I-H(I/+hH/,hH,i-’H-V)(i)œ’H,i+8(c)(H/i)“I/H-i*’I-H*i)’I*4)-H(i)œi¨1’I/+hH(H*o,hH,i-’H/V)(i)œ’i(c)(H/i*’I/H(i)’I(4)33i¤I*H,iø-’H,i¸)’H,i-’i;8)5+H0H1’I2i(I-+hH-H2p,hH,H,iP’8*J*i(p5-H*i7u,hH,i-’H-i)œ’H*c)(H-i)’I-4*3i(I/i+I.i+I(*h*h*hH*i8“6*(*)3H-m,hi£I*403H-i)œH,’W)-I/i*I(4)3i3I.i/I(3H2H,H(8(H.’J(H-’J.p,hi¢I*4.3H,i-’H-i)œ’I*+hH(,hH*H/c)(H*i*’I*H(i)“I(4)-H.I-4+3(3(33H,W)1m,hiŸI*4,3H,iø-’H,i¸)’H,i-’H18)J(,hi¡I*H(i(p5,H1H,V)ú-H,V)ø-’o5,3H,i(’H,iX’H,i-’H1i)œ’H08)J(,hi I*H(i(p5,H0H,V)šH,V)˜’o5,3H,H,iP’H,iH’8+I*4+3(3(3H,i$6i¬78+I*3H*H3šm5(3i)I-H*i(r5)3H)H,P*0^*(H+H,P*<^*(H*I-3H,i2’L(H-33Á)+(i¨03b+(,(-(.(/(0(1(2(3(5(7(9(;(?(C(G(K(S([(c(k({(‹(›(«(Ë(ë( (*)(iø03O)()()()(*(*(*(*(+(+(+(+(,(,(,(,(-(-(-(-(i¨13M8(9(:(((0(/(1(.(2(-(3(,(4(+(5(*(6()(7(T7œ‰šœ‡Ž‰œš›*S7•œ‰Š”U”—Љ”›S0›‘–U œ`;Z.getModule(Z,i).then(o=>WebAssembly.instantiate(o,{})).then(({exports:o})=>{let s=new Map(Object.entries(o)),a=s.get("puff"),c=s.get("memory").buffer,l=new t(c),d=new DataView(c),u=s.get("__heap_base"),f=r.length,m=u;u+=4,d.setInt32(m,f,!0);let p=u;u+=f,l.set(r,p);let y=u;u+=4,d.setInt32(y,l.byteLength-u,!0),a(u,y,p,m),n(l.slice(u,u+d.getInt32(y,!0)))})})}}}),Object.defineProperty(this,"wasm",{enumerable:!0,get:()=>this._wasm}),this.getOutputChannels=(r,n,i)=>{let o=[],s=0;for(;s<n;)o.push(r.slice(s*i,s++*i+i));return o},this.allocateTypedArray=(r,n,i=!0)=>{let o=this._wasm.malloc(n.BYTES_PER_ELEMENT*r);return i&&this._pointers.add(o),{ptr:o,len:r,buf:new n(this._wasm.HEAP,o,r)}},this.free=()=>{this._pointers.forEach(r=>{this._wasm.free(r)}),this._pointers.clear()},this.codeToString=r=>{let n=[],i=new Uint8Array(this._wasm.HEAP);for(let o=i[r];o!==0;o=i[++r])n.push(o);return String.fromCharCode.apply(null,n)},this.addError=(r,n,i,o,s,a)=>{r.push({message:n,frameLength:i,frameNumber:o,inputBytes:s,outputSamples:a})},this.instantiate=(r,n)=>(n&&Z.setModule(r,n),this._wasm=new r(Z).instantiate(),this._pointers=new Set,this._wasm.ready.then(()=>this))}var Za=Ll(Ja(),1);var d0=()=>globalThis.Worker||Za.default,gr=class extends d0(){constructor(e,r,n,i){Z.modules||new Z;let o=Z.modules.get(n);if(!o){let s="text/javascript",a,c=`'use strict';(${((l,d,u)=>{let f,m,p=new Promise(y=>{m=y});self.onmessage=({data:{id:y,command:h,data:g}})=>{let M=p,x={id:y},v;h==="init"?(Object.defineProperties(l,{WASMAudioDecoderCommon:{value:d},EmscriptenWASM:{value:u},module:{value:g.module},isWebWorker:{value:!0}}),f=new l(g.options),m()):h==="free"?f.free():h==="ready"?M=M.then(()=>f.ready):h==="reset"?M=M.then(()=>f.reset()):(Object.assign(x,f[h](Array.isArray(g)?g.map(b=>new Uint8Array(b)):new Uint8Array(g))),v=x.channelData?x.channelData.map(b=>b.buffer):[]),M.then(()=>self.postMessage(x,v))}}).toString()})(${n}, ${Z}, ${i})`;try{a=typeof process.versions.node<"u"}catch{}o=a?`data:${s};base64,${Buffer.from(c).toString("base64")}`:URL.createObjectURL(new Blob([c],{type:s})),Z.modules.set(n,o)}super(o,{name:r}),this._id=Number.MIN_SAFE_INTEGER,this._enqueuedOperations=new Map,this.onmessage=({data:s})=>{let{id:a,...c}=s;this._enqueuedOperations.get(a)(c),this._enqueuedOperations.delete(a)},new i(Z).getModule().then(s=>{this.postToDecoder("init",{module:s,options:e})})}async postToDecoder(e,r){return new Promise(n=>{this.postMessage({command:e,id:this._id,data:r}),this._enqueuedOperations.set(this._id++,n)})}get ready(){return this.postToDecoder("ready")}async free(){await this.postToDecoder("free").finally(()=>{this.terminate()})}async reset(){await this.postToDecoder("reset")}};var Li=(t,e)=>{Object.defineProperty(t,"name",{value:e})};var ee=Symbol,ec=", ",R=(()=>{let t="front",e="side",r="rear",n="left",i="center",o="right";return["",t+" ",e+" ",r+" "].map(s=>[[n,o],[n,o,i],[n,i,o],[i,n,o],[i]].flatMap(a=>a.map(c=>s+c).join(ec)))})(),Ye="LFE",gt="monophonic (mono)",xt="stereo",Zr="surround",te=(t,...e)=>`${[gt,xt,`linear ${Zr}`,"quadraphonic",`5.0 ${Zr}`,`5.1 ${Zr}`,`6.1 ${Zr}`,`7.1 ${Zr}`][t-1]} (${e.join(ec)})`,en=[gt,te(2,R[0][0]),te(3,R[0][2]),te(4,R[1][0],R[3][0]),te(5,R[1][2],R[3][0]),te(6,R[1][2],R[3][0],Ye),te(7,R[1][2],R[2][0],R[3][4],Ye),te(8,R[1][2],R[2][0],R[3][0],Ye)],tc=192e3,rc=176400,Ei=96e3,Ii=88200,nc=64e3,bt=48e3,xr=44100,br=32e3,vr=24e3,Sr=22050,Mr=16e3,Pi=12e3,Ci=11025,_r=8e3,ic=7350,Ve="absoluteGranulePosition",D="bandwidth",me="bitDepth",he="bitrate",tn=he+"Maximum",rn=he+"Minimum",nn=he+"Nominal",qe="buffer",on=qe+"Fullness",Q="codec",pe=Q+"Frames",sn="coupledStreamCount",Ar="crc",an=Ar+"16",cn=Ar+"32",$="data",z="description",$e="duration",wr="emphasis",ln="hasOpusPadding",Le="header",vt="isContinuedPacket",dn="isCopyrighted",St="isFirstPage",un="isHome",Ee="isLastPage",tt="isOriginal",rt="isPrivate",fn="isVbr",_e="layer",_="length",B="mode",nt=B+"Extension",zi="mpeg",it=zi+"Version",mn="numberAACFrames",hn="outputGain",Ut="preSkip",pn="profile",Ri=ee(),ot="protection",ys="rawData",Fe="segments",N="subarray",Mt="version",Ht="vorbis",yn=Ht+"Comments",Lr=Ht+"Setup",Ti="block",gn=Ti+"ingStrategy",Fi=ee(),st=Ti+"Size",_t=Ti+"size0",At=Ti+"size1",xn=ee(),Bi="channel",at=Bi+"MappingFamily",bn=Bi+"MappingTable",ye=Bi+"Mode",vn=ee(),C=Bi+"s",oc="copyright",Sn=oc+"Id",Mn=oc+"IdStart",ct="frame",lt=ct+"Count",Ae=ct+"Length",Di="Number",dt=ct+Di,je=ct+"Padding",F=ct+"Size",sc="Rate",_n="inputSample"+sc,gs="page",Vt=gs+"Checksum",Er=ee(),wt=gs+"SegmentTable",oe=gs+"Sequence"+Di,xs="sample",An=xs+Di,H=xs+sc,Qe=ee(),V=xs+"s",Oi="stream",wn=Oi+"Count",Ln=Oi+"Info",Je=Oi+"Serial"+Di,bs=Oi+"StructureVersion",vs="total",Gt=vs+"BytesOut",Wt=vs+"Duration",Xt=vs+"Samples",G=ee(),Be=ee(),En=ee(),Lt=ee(),Ge=ee(),Ni=ee(),Ss=ee(),Et=ee(),X=ee(),De=ee(),Oe=ee(),Ze=ee(),It=ee(),ki=ee(),We=ee(),Xe=ee(),Ne=ee(),Ui=ee(),ge=Uint8Array,Pt=DataView,K="reserved",xe="bad",Ir="free",In="none",Hi="16bit CRC";var Ms=(t,e,r)=>{for(let n=0;n<t[_];n++){let i=e(n);for(let o=8;o>0;o--)i=r(i);t[n]=i}return t},f0=Ms(new ge(256),t=>t,t=>t&128?7^t<<1:t<<1),re=[Ms(new Uint16Array(256),t=>t<<8,t=>t<<1^(t&32768?32773:0))],ne=[Ms(new Uint32Array(256),t=>t,t=>t>>>1^(t&1)*3988292384)];for(let t=0;t<15;t++){re.push(new Uint16Array(256)),ne.push(new Uint32Array(256));for(let e=0;e<=255;e++)re[t+1][e]=re[0][re[t][e]>>>8]^re[t][e]<<8,ne[t+1][e]=ne[t][e]>>>8^ne[0][ne[t][e]&255]}var cc=t=>{let e=0,r=t[_];for(let n=0;n!==r;n++)e=f0[e^t[n]];return e},lc=t=>{let e=t[_],r=e-16,n=0,i=0;for(;i<=r;)n^=t[i++]<<8|t[i++],n=re[15][n>>8]^re[14][n&255]^re[13][t[i++]]^re[12][t[i++]]^re[11][t[i++]]^re[10][t[i++]]^re[9][t[i++]]^re[8][t[i++]]^re[7][t[i++]]^re[6][t[i++]]^re[5][t[i++]]^re[4][t[i++]]^re[3][t[i++]]^re[2][t[i++]]^re[1][t[i++]]^re[0][t[i++]];for(;i!==e;)n=(n&255)<<8^re[0][n>>8^t[i++]];return n},dc=t=>{let e=t[_],r=e-16,n=0,i=0;for(;i<=r;)n=ne[15][(t[i++]^n)&255]^ne[14][(t[i++]^n>>>8)&255]^ne[13][(t[i++]^n>>>16)&255]^ne[12][t[i++]^n>>>24]^ne[11][t[i++]]^ne[10][t[i++]]^ne[9][t[i++]]^ne[8][t[i++]]^ne[7][t[i++]]^ne[6][t[i++]]^ne[5][t[i++]]^ne[4][t[i++]]^ne[3][t[i++]]^ne[2][t[i++]]^ne[1][t[i++]]^ne[0][t[i++]];for(;i!==e;)n=ne[0][(n^t[i++])&255]^n>>>8;return n^-1},Cn=(...t)=>{let e=new ge(t.reduce((r,n)=>r+n[_],0));return t.reduce((r,n)=>(e.set(n,r),r+n[_]),0),e},Ie=t=>String.fromCharCode(...t),ac=[0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15],Pn=t=>ac[t&15]<<4|ac[t>>4],Vi=class{constructor(e){this._data=e,this._pos=e[_]*8}set position(e){this._pos=e}get position(){return this._pos}read(e){let r=Math.floor(this._pos/8),n=this._pos%8;return this._pos-=e,(Pn(this._data[r-1])<<8)+Pn(this._data[r])>>7-n&255}},uc=(t,e)=>{try{return t.getBigInt64(e,!0)}catch{let r=t.getUint8(e+7)&128?-1:1,n=t.getUint32(e,!0),i=t.getUint32(e+4,!0);return r===-1&&(n=~n+1,i=~i+1),i>1048575&&console.warn("This platform does not support BigInt"),r*(n+i*2**32)}};var zn=class{constructor(e,r){this._onCodecHeader=e,this._onCodecUpdate=r,this[We]()}[Xe](){this._isEnabled=!0}[We](){this._headerCache=new Map,this._codecUpdateData=new WeakMap,this._codecHeaderSent=!1,this._codecShouldUpdate=!1,this._bitrate=null,this._isEnabled=!1}[ki](e,r){if(this._onCodecUpdate){this._bitrate!==e&&(this._bitrate=e,this._codecShouldUpdate=!0);let n=this._codecUpdateData.get(this._headerCache.get(this._currentHeader));this._codecShouldUpdate&&n&&this._onCodecUpdate({bitrate:e,...n},r),this._codecShouldUpdate=!1}}[X](e){let r=this._headerCache.get(e);return r&&this._updateCurrentHeader(e),r}[De](e,r,n){this._isEnabled&&(this._codecHeaderSent||(this._onCodecHeader({...r}),this._codecHeaderSent=!0),this._updateCurrentHeader(e),this._headerCache.set(e,r),this._codecUpdateData.set(r,n))}_updateCurrentHeader(e){this._onCodecUpdate&&e!==this._currentHeader&&(this._codecShouldUpdate=!0,this._currentHeader=e)}};var ce=new WeakMap,de=new WeakMap;var be=class{constructor(e,r){this._codecParser=e,this._headerCache=r}*[Ss](){let e;do{if(e=yield*this.Frame[Oe](this._codecParser,this._headerCache,0),e)return e;this._codecParser[Be](1)}while(!0)}*[Et](e){let r=yield*this[Ss](),n=de.get(r)[_];if(e||this._codecParser._flushing||(yield*this.Header[X](this._codecParser,this._headerCache,n)))return this._headerCache[Xe](),this._codecParser[Be](n),this._codecParser[Lt](r),r;this._codecParser[Ge](`Missing ${ct} at ${n} bytes from current position.`,`Dropping current ${ct} and trying again.`),this._headerCache[We](),this._codecParser[Be](1)}};var Kt=class{constructor(e,r){de.set(this,{[Le]:e}),this[$]=r}};var Pe=class extends Kt{static*[Oe](e,r,n,i,o){let s=yield*e[X](n,i,o);if(s){let a=ce.get(s)[Ae],c=ce.get(s)[V],l=(yield*n[G](a,o))[N](0,a);return new r(s,l,c)}else return null}constructor(e,r,n){super(e,r),this[Le]=e,this[V]=n,this[$e]=n/e[H]*1e3,this[dt]=null,this[Gt]=null,this[Xt]=null,this[Wt]=null,de.get(this)[_]=r[_]}};var _s="unsynchronizationFlag",As="extendedHeaderFlag",ws="experimentalFlag",Ls="footerPresent",Rn=class t{static*getID3v2Header(e,r,n){let o={},s=yield*e[G](3,n);if(s[0]!==73||s[1]!==68||s[2]!==51||(s=yield*e[G](10,n),o[Mt]=`id3v2.${s[3]}.${s[4]}`,s[5]&15)||(o[_s]=!!(s[5]&128),o[As]=!!(s[5]&64),o[ws]=!!(s[5]&32),o[Ls]=!!(s[5]&16),s[6]&128||s[7]&128||s[8]&128||s[9]&128))return null;let a=s[6]<<21|s[7]<<14|s[8]<<7|s[9];return o[_]=10+a,new t(o)}constructor(e){this[Mt]=e[Mt],this[_s]=e[_s],this[As]=e[As],this[ws]=e[ws],this[Ls]=e[Ls],this[_]=e[_]}};var Ce=class{constructor(e){ce.set(this,e),this[me]=e[me],this[he]=null,this[C]=e[C],this[ye]=e[ye],this[H]=e[H]}};var yc={0:[Ir,Ir,Ir,Ir,Ir],16:[32,32,32,32,8],240:[xe,xe,xe,xe,xe]},Gi=(t,e,r)=>8*((t+r)%e+e)*(1<<(t+r)/e)-8*e*(e/8|0);for(let t=2;t<15;t++)yc[t<<4]=[t*32,Gi(t,4,0),Gi(t,4,-1),Gi(t,8,4),Gi(t,8,0)];var m0=0,h0=1,p0=2,y0=3,fc=4,Wi="bands ",Xi=" to 31",mc={0:Wi+4+Xi,16:Wi+8+Xi,32:Wi+12+Xi,48:Wi+16+Xi},Yt="bitrateIndex",Tn="v2",ji="v1",Ki="Intensity stereo ",Yi=", MS stereo ",qi="on",$i="off",g0={0:Ki+$i+Yi+$i,16:Ki+qi+Yi+$i,32:Ki+$i+Yi+qi,48:Ki+qi+Yi+qi},Es={0:{[z]:K},2:{[z]:"Layer III",[je]:1,[nt]:g0,[ji]:{[Yt]:p0,[V]:1152},[Tn]:{[Yt]:fc,[V]:576}},4:{[z]:"Layer II",[je]:1,[nt]:mc,[V]:1152,[ji]:{[Yt]:h0},[Tn]:{[Yt]:fc}},6:{[z]:"Layer I",[je]:4,[nt]:mc,[V]:384,[ji]:{[Yt]:m0},[Tn]:{[Yt]:y0}}},Is="MPEG Version ",hc="ISO/IEC ",x0={0:{[z]:`${Is}2.5 (later extension of MPEG 2)`,[_e]:Tn,[H]:{0:Ci,4:Pi,8:_r,12:K}},8:{[z]:K},16:{[z]:`${Is}2 (${hc}13818-3)`,[_e]:Tn,[H]:{0:Sr,4:vr,8:Mr,12:K}},24:{[z]:`${Is}1 (${hc}11172-3)`,[_e]:ji,[H]:{0:xr,4:bt,8:br,12:K}},length:_},b0={0:Hi,1:In},v0={0:In,1:"50/15 ms",2:K,3:"CCIT J.17"},pc={0:{[C]:2,[z]:xt},64:{[C]:2,[z]:"joint "+xt},128:{[C]:2,[z]:"dual channel"},192:{[C]:1,[z]:gt}},qt=class t extends Ce{static*[X](e,r,n){let i={},o=yield*Rn.getID3v2Header(e,r,n);o&&(yield*e[G](o[_],n),e[Be](o[_]));let s=yield*e[G](4,n),a=Ie(s[N](0,4)),c=r[X](a);if(c)return new t(c);if(s[0]!==255||s[1]<224)return null;let l=x0[s[1]&24];if(l[z]===K)return null;let d=s[1]&6;if(Es[d][z]===K)return null;let u={...Es[d],...Es[d][l[_e]]};if(i[it]=l[z],i[_e]=u[z],i[V]=u[V],i[ot]=b0[s[1]&1],i[_]=4,i[he]=yc[s[2]&240][u[Yt]],i[he]===xe||(i[H]=l[H][s[2]&12],i[H]===K)||(i[je]=s[2]&2&&u[je],i[rt]=!!(s[2]&1),i[Ae]=Math.floor(125*i[he]*i[V]/i[H]+i[je]),!i[Ae]))return null;let f=s[3]&192;if(i[ye]=pc[f][z],i[C]=pc[f][C],i[nt]=u[nt][s[3]&48],i[dn]=!!(s[3]&8),i[tt]=!!(s[3]&4),i[wr]=v0[s[3]&3],i[wr]===K)return null;i[me]=16;{let{length:m,frameLength:p,samples:y,...h}=i;r[De](a,i,h)}return new t(i)}constructor(e){super(e),this[he]=e[he],this[wr]=e[wr],this[je]=e[je],this[dn]=e[dn],this[tt]=e[tt],this[rt]=e[rt],this[_e]=e[_e],this[nt]=e[nt],this[it]=e[it],this[ot]=e[ot]}};var Fn=class t extends Pe{static*[Oe](e,r,n){return yield*super[Oe](qt,t,e,r,n)}constructor(e,r,n){super(e,r,n)}};var Bn=class extends be{constructor(e,r,n){super(e,r),this.Frame=Fn,this.Header=qt,n(this[Q])}get[Q](){return zi}*[Ze](){return yield*this[Et]()}};var S0={0:"MPEG-4",8:"MPEG-2"},M0={0:"valid",2:xe,4:xe,6:xe},_0={0:Hi,1:In},A0={0:"AAC Main",64:"AAC LC (Low Complexity)",128:"AAC SSR (Scalable Sample Rate)",192:"AAC LTP (Long Term Prediction)"},w0={0:Ei,4:Ii,8:nc,12:bt,16:xr,20:br,24:vr,28:Sr,32:Mr,36:Pi,40:Ci,44:_r,48:ic,52:K,56:K,60:"frequency is written explicitly"},gc={0:{[C]:0,[z]:"Defined in AOT Specific Config"},64:{[C]:1,[z]:gt},128:{[C]:2,[z]:te(2,R[0][0])},192:{[C]:3,[z]:te(3,R[1][3])},256:{[C]:4,[z]:te(4,R[1][3],R[3][4])},320:{[C]:5,[z]:te(5,R[1][3],R[3][0])},384:{[C]:6,[z]:te(6,R[1][3],R[3][0],Ye)},448:{[C]:8,[z]:te(8,R[1][3],R[2][0],R[3][0],Ye)}},$t=class t extends Ce{static*[X](e,r,n){let i={},o=yield*e[G](7,n),s=Ie([o[0],o[1],o[2],o[3]&252|o[6]&3]),a=r[X](s);if(a)Object.assign(i,a);else{if(o[0]!==255||o[1]<240||(i[it]=S0[o[1]&8],i[_e]=M0[o[1]&6],i[_e]===xe))return null;let l=o[1]&1;i[ot]=_0[l],i[_]=l?7:9,i[Ri]=o[2]&192,i[Qe]=o[2]&60;let d=o[2]&2;if(i[pn]=A0[i[Ri]],i[H]=w0[i[Qe]],i[H]===K)return null;i[rt]=!!d,i[vn]=(o[2]<<8|o[3])&448,i[ye]=gc[i[vn]][z],i[C]=gc[i[vn]][C],i[tt]=!!(o[3]&32),i[un]=!!(o[3]&8),i[Sn]=!!(o[3]&8),i[Mn]=!!(o[3]&4),i[me]=16,i[V]=1024,i[mn]=o[6]&3;{let{length:u,channelModeBits:f,profileBits:m,sampleRateBits:p,frameLength:y,samples:h,numberAACFrames:g,...M}=i;r[De](s,i,M)}}if(i[Ae]=(o[3]<<11|o[4]<<3|o[5]>>5)&8191,!i[Ae])return null;let c=(o[5]<<6|o[6]>>2)&2047;return i[on]=c===2047?"VBR":c,new t(i)}constructor(e){super(e),this[Sn]=e[Sn],this[Mn]=e[Mn],this[on]=e[on],this[un]=e[un],this[tt]=e[tt],this[rt]=e[rt],this[_e]=e[_e],this[_]=e[_],this[it]=e[it],this[mn]=e[mn],this[pn]=e[pn],this[ot]=e[ot]}get audioSpecificConfig(){let e=ce.get(this),r=e[Ri]+64<<5|e[Qe]<<5|e[vn]>>3,n=new ge(2);return new Pt(n[qe]).setUint16(0,r,!1),n}};var Dn=class t extends Pe{static*[Oe](e,r,n){return yield*super[Oe]($t,t,e,r,n)}constructor(e,r,n){super(e,r,n)}};var On=class extends be{constructor(e,r,n){super(e,r),this.Frame=Dn,this.Header=$t,n(this[Q])}get[Q](){return"aac"}*[Ze](){return yield*this[Et]()}};var Ct=class t extends Pe{static _getFrameFooterCrc16(e){return(e[e[_]-2]<<8)+e[e[_]-1]}static[Ui](e){let r=t._getFrameFooterCrc16(e),n=lc(e[N](0,-2));return r===n}constructor(e,r,n){r[Ln]=n,r[an]=t._getFrameFooterCrc16(e),super(r,e,ce.get(r)[V])}};var xc="get from STREAMINFO metadata block",L0={0:"Fixed",1:"Variable"},bc={0:K,16:192};for(let t=2;t<16;t++)bc[t<<4]=t<6?576*2**(t-2):2**t;var E0={0:xc,1:Ii,2:rc,3:tc,4:_r,5:Mr,6:Sr,7:vr,8:br,9:xr,10:bt,11:Ei,15:xe},I0={0:{[C]:1,[z]:gt},16:{[C]:2,[z]:te(2,R[0][0])},32:{[C]:3,[z]:te(3,R[0][1])},48:{[C]:4,[z]:te(4,R[1][0],R[3][0])},64:{[C]:5,[z]:te(5,R[1][1],R[3][0])},80:{[C]:6,[z]:te(6,R[1][1],Ye,R[3][0])},96:{[C]:7,[z]:te(7,R[1][1],Ye,R[3][4],R[2][0])},112:{[C]:8,[z]:te(8,R[1][1],Ye,R[3][0],R[2][0])},128:{[C]:2,[z]:`${xt} (left, diff)`},144:{[C]:2,[z]:`${xt} (diff, right)`},160:{[C]:2,[z]:`${xt} (avg, diff)`},176:K,192:K,208:K,224:K,240:K},P0={0:xc,2:8,4:12,6:K,8:16,10:20,12:24,14:K},zt=class t extends Ce{static _decodeUTF8Int(e){if(e[0]>254)return null;if(e[0]<128)return{value:e[0],length:1};let r=1;for(let s=64;s&e[0];s>>=1)r++;let n=r-1,i=0,o=0;for(;n>0;o+=6,n--){if((e[n]&192)!==128)return null;i|=(e[n]&63)<<o}return i|=(e[n]&127>>r)<<o,{value:i,length:r}}static[Ne](e,r){let n={[G]:function*(){return e}};return t[X](n,r,0).next().value}static*[X](e,r,n){let i=yield*e[G](6,n);if(i[0]!==255||!(i[1]===248||i[1]===249))return null;let o={},s=Ie(i[N](0,4)),a=r[X](s);if(a)Object.assign(o,a);else{if(o[Fi]=i[1]&1,o[gn]=L0[o[Fi]],o[xn]=i[2]&240,o[Qe]=i[2]&15,o[st]=bc[o[xn]],o[st]===K||(o[H]=E0[o[Qe]],o[H]===xe)||i[3]&1)return null;let l=I0[i[3]&240];if(l===K||(o[C]=l[C],o[ye]=l[z],o[me]=P0[i[3]&14],o[me]===K))return null}o[_]=5,i=yield*e[G](o[_]+8,n);let c=t._decodeUTF8Int(i[N](4));if(!c||(o[Fi]?o[An]=c.value:o[dt]=c.value,o[_]+=c[_],o[xn]===96?(i[_]<o[_]&&(i=yield*e[G](o[_],n)),o[st]=i[o[_]-1]+1,o[_]+=1):o[xn]===112&&(i[_]<o[_]&&(i=yield*e[G](o[_],n)),o[st]=(i[o[_]-1]<<8)+i[o[_]]+1,o[_]+=2),o[V]=o[st],o[Qe]===12?(i[_]<o[_]&&(i=yield*e[G](o[_],n)),o[H]=i[o[_]-1]*1e3,o[_]+=1):o[Qe]===13?(i[_]<o[_]&&(i=yield*e[G](o[_],n)),o[H]=(i[o[_]-1]<<8)+i[o[_]],o[_]+=2):o[Qe]===14&&(i[_]<o[_]&&(i=yield*e[G](o[_],n)),o[H]=((i[o[_]-1]<<8)+i[o[_]])*10,o[_]+=2),i[_]<o[_]&&(i=yield*e[G](o[_],n)),o[Ar]=i[o[_]-1],o[Ar]!==cc(i[N](0,o[_]-1))))return null;if(!a){let{blockingStrategyBits:l,frameNumber:d,sampleNumber:u,samples:f,sampleRateBits:m,blockSizeBits:p,crc:y,length:h,...g}=o;r[De](s,o,g)}return new t(o)}constructor(e){super(e),this[an]=null,this[gn]=e[gn],this[st]=e[st],this[dt]=e[dt],this[An]=e[An],this[Ln]=null}};var C0=2,z0=512*1024,jt=class extends be{constructor(e,r,n){super(e,r),this.Frame=Ct,this.Header=zt,n(this[Q])}get[Q](){return"flac"}*_getNextFrameSyncOffset(e){let r=yield*this._codecParser[G](2,0),n=r[_]-2;for(;e<n;){if(r[e]===255){let o=r[e+1];if(o===248||o===249)break;o!==255&&e++}e++}return e}*[Ze](){do{let e=yield*zt[X](this._codecParser,this._headerCache,0);if(e){let r=ce.get(e)[_]+C0;for(;r<=z0;){if(this._codecParser._flushing||(yield*zt[X](this._codecParser,this._headerCache,r))){let n=yield*this._codecParser[G](r);if(this._codecParser._flushing||(n=n[N](0,r)),Ct[Ui](n)){let i=new Ct(n,e);return this._headerCache[Xe](),this._codecParser[Be](r),this._codecParser[Lt](i),i}}r=yield*this._getNextFrameSyncOffset(r+1)}this._codecParser[Ge](`Unable to sync FLAC frame after searching ${r} bytes.`),this._codecParser[Be](r)}else this._codecParser[Be](yield*this._getNextFrameSyncOffset(1))}while(!0)}[It](e){return e[oe]===0?(this._headerCache[Xe](),this._streamInfo=e[$][N](13)):e[oe]===1||(e[pe]=de.get(e)[Fe].map(r=>{let n=zt[Ne](r,this._headerCache);if(n)return new Ct(r,n,this._streamInfo);this._codecParser[Ge]("Failed to parse Ogg FLAC frame","Skipping invalid FLAC frame")}).filter(r=>!!r)),e}};var Qt=class t{static*[X](e,r,n){let i={},o=yield*e[G](28,n);if(o[0]!==79||o[1]!==103||o[2]!==103||o[3]!==83||(i[bs]=o[4],o[5]&248))return null;i[Ee]=!!(o[5]&4),i[St]=!!(o[5]&2),i[vt]=!!(o[5]&1);let a=new Pt(ge.from(o[N](0,28))[qe]);i[Ve]=uc(a,6),i[Je]=a.getInt32(14,!0),i[oe]=a.getInt32(18,!0),i[Vt]=a.getInt32(22,!0);let c=o[26];i[_]=c+27,o=yield*e[G](i[_],n),i[Ae]=0,i[wt]=[],i[Er]=ge.from(o[N](27,i[_]));for(let l=0,d=0;l<c;l++){let u=i[Er][l];i[Ae]+=u,d+=u,(u!==255||l===c-1)&&(i[wt].push(d),d=0)}return new t(i)}constructor(e){ce.set(this,e),this[Ve]=e[Ve],this[vt]=e[vt],this[St]=e[St],this[Ee]=e[Ee],this[wt]=e[wt],this[oe]=e[oe],this[Vt]=e[Vt],this[Je]=e[Je]}};var Nn=class t extends Kt{static*[Oe](e,r,n){let i=yield*Qt[X](e,r,n);if(i){let o=ce.get(i)[Ae],s=ce.get(i)[_],a=s+o,c=(yield*e[G](a,0))[N](0,a),l=c[N](s,a);return new t(i,l,c)}else return null}constructor(e,r,n){super(e,r),de.get(this)[_]=n[_],this[pe]=[],this[ys]=n,this[Ve]=e[Ve],this[cn]=e[Vt],this[$e]=0,this[vt]=e[vt],this[St]=e[St],this[Ee]=e[Ee],this[oe]=e[oe],this[V]=0,this[Je]=e[Je]}};var Pr=class extends Pe{constructor(e,r,n){super(r,e,n)}};var vc={0:en.slice(0,2),1:en},ke="SILK-only",ue="CELT-only",Qi="Hybrid",Rt="narrowband",Ji="medium-band",Tt="wideband",Cr="super-wideband",zr="fullband",R0={0:{[B]:ke,[D]:Rt,[F]:10},8:{[B]:ke,[D]:Rt,[F]:20},16:{[B]:ke,[D]:Rt,[F]:40},24:{[B]:ke,[D]:Rt,[F]:60},32:{[B]:ke,[D]:Ji,[F]:10},40:{[B]:ke,[D]:Ji,[F]:20},48:{[B]:ke,[D]:Ji,[F]:40},56:{[B]:ke,[D]:Ji,[F]:60},64:{[B]:ke,[D]:Tt,[F]:10},72:{[B]:ke,[D]:Tt,[F]:20},80:{[B]:ke,[D]:Tt,[F]:40},88:{[B]:ke,[D]:Tt,[F]:60},96:{[B]:Qi,[D]:Cr,[F]:10},104:{[B]:Qi,[D]:Cr,[F]:20},112:{[B]:Qi,[D]:zr,[F]:10},120:{[B]:Qi,[D]:zr,[F]:20},128:{[B]:ue,[D]:Rt,[F]:2.5},136:{[B]:ue,[D]:Rt,[F]:5},144:{[B]:ue,[D]:Rt,[F]:10},152:{[B]:ue,[D]:Rt,[F]:20},160:{[B]:ue,[D]:Tt,[F]:2.5},168:{[B]:ue,[D]:Tt,[F]:5},176:{[B]:ue,[D]:Tt,[F]:10},184:{[B]:ue,[D]:Tt,[F]:20},192:{[B]:ue,[D]:Cr,[F]:2.5},200:{[B]:ue,[D]:Cr,[F]:5},208:{[B]:ue,[D]:Cr,[F]:10},216:{[B]:ue,[D]:Cr,[F]:20},224:{[B]:ue,[D]:zr,[F]:2.5},232:{[B]:ue,[D]:zr,[F]:5},240:{[B]:ue,[D]:zr,[F]:10},248:{[B]:ue,[D]:zr,[F]:20}},Rr=class t extends Ce{static[Ne](e,r,n){let i={};if(i[C]=e[9],i[at]=e[18],i[_]=i[at]!==0?21+i[C]:19,e[_]<i[_])throw new Error("Out of data while inside an Ogg Page");let o=r[0]&3,s=o===3?2:1,a=Ie(e[N](0,i[_]))+Ie(r[N](0,s)),c=n[X](a);if(c)return new t(c);if(a.substr(0,8)!=="OpusHead"||e[8]!==1)return null;i[$]=ge.from(e[N](0,i[_]));let l=new Pt(i[$][qe]);if(i[me]=16,i[Ut]=l.getUint16(10,!0),i[_n]=l.getUint32(12,!0),i[H]=bt,i[hn]=l.getInt16(16,!0),i[at]in vc&&(i[ye]=vc[i[at]][i[C]-1],!i[ye]))return null;i[at]!==0&&(i[wn]=e[19],i[sn]=e[20],i[bn]=[...e[N](21,i[C]+21)]);let d=R0[248&r[0]];switch(i[B]=d[B],i[D]=d[D],i[F]=d[F],o){case 0:i[lt]=1;break;case 1:case 2:i[lt]=2;break;case 3:i[fn]=!!(128&r[1]),i[ln]=!!(64&r[1]),i[lt]=63&r[1];break;default:return null}{let{length:u,data:f,channelMappingFamily:m,...p}=i;n[De](a,i,p)}return new t(i)}constructor(e){super(e),this[$]=e[$],this[D]=e[D],this[at]=e[at],this[bn]=e[bn],this[sn]=e[sn],this[lt]=e[lt],this[F]=e[F],this[ln]=e[ln],this[_n]=e[_n],this[fn]=e[fn],this[B]=e[B],this[hn]=e[hn],this[Ut]=e[Ut],this[wn]=e[wn]}};var kn=class extends be{constructor(e,r,n){super(e,r),this.Frame=Pr,this.Header=Rr,n(this[Q]),this._identificationHeader=null,this._preSkipRemaining=null}get[Q](){return"opus"}[It](e){return e[oe]===0?(this._headerCache[Xe](),this._identificationHeader=e[$]):e[oe]===1||(e[pe]=de.get(e)[Fe].map(r=>{let n=Rr[Ne](this._identificationHeader,r,this._headerCache);if(n){this._preSkipRemaining===null&&(this._preSkipRemaining=n[Ut]);let i=n[F]*n[lt]/1e3*n[H];return this._preSkipRemaining>0&&(this._preSkipRemaining-=i,i=this._preSkipRemaining<0?-this._preSkipRemaining:0),new Pr(r,n,i)}this._codecParser[Ni]("Failed to parse Ogg Opus Header","Not a valid Ogg Opus file")})),e}};var Tr=class extends Pe{constructor(e,r,n){super(r,e,n)}};var Ps={};for(let t=0;t<8;t++)Ps[t+6]=2**(6+t);var Un=class t extends Ce{static[Ne](e,r,n,i){if(e[_]<30)throw new Error("Out of data while inside an Ogg Page");let o=Ie(e[N](0,30)),s=r[X](o);if(s)return new t(s);let a={[_]:30};if(o.substr(0,7)!=="vorbis")return null;a[$]=ge.from(e[N](0,30));let c=new Pt(a[$][qe]);if(a[Mt]=c.getUint32(7,!0),a[Mt]!==0||(a[C]=e[11],a[ye]=en[a[C]-1]||"application defined",a[H]=c.getUint32(12,!0),a[tn]=c.getInt32(16,!0),a[nn]=c.getInt32(20,!0),a[rn]=c.getInt32(24,!0),a[At]=Ps[(e[28]&240)>>4],a[_t]=Ps[e[28]&15],a[_t]>a[At])||e[29]!==1)return null;a[me]=32,a[Lr]=i,a[yn]=n;{let{length:l,data:d,version:u,vorbisSetup:f,vorbisComments:m,...p}=a;r[De](o,a,p)}return new t(a)}constructor(e){super(e),this[tn]=e[tn],this[rn]=e[rn],this[nn]=e[nn],this[_t]=e[_t],this[At]=e[At],this[$]=e[$],this[yn]=e[yn],this[Lr]=e[Lr]}};var Hn=class extends be{constructor(e,r,n){super(e,r),this.Frame=Tr,n(this[Q]),this._identificationHeader=null,this._setupComplete=!1,this._prevBlockSize=null}get[Q](){return Ht}[It](e){e[pe]=[];for(let r of de.get(e)[Fe])if(r[0]===1)this._headerCache[Xe](),this._identificationHeader=e[$],this._setupComplete=!1;else if(r[0]===3)this._vorbisComments=r;else if(r[0]===5)this._vorbisSetup=r,this._mode=this._parseSetupHeader(r),this._setupComplete=!0;else if(this._setupComplete){let n=Un[Ne](this._identificationHeader,this._headerCache,this._vorbisComments,this._vorbisSetup);n?e[pe].push(new Tr(r,n,this._getSamples(r,n))):this._codecParser[logError]("Failed to parse Ogg Vorbis Header","Not a valid Ogg Vorbis file")}return e}_getSamples(e,r){let i=this._mode.blockFlags[e[0]>>1&this._mode.mask]?r[At]:r[_t],o=this._prevBlockSize===null?0:(this._prevBlockSize+i)/4;return this._prevBlockSize=i,o}_parseSetupHeader(e){let r=new Vi(e),n={count:0,blockFlags:[]};for(;(r.read(1)&1)!==1;);let i;for(;n.count<64&&r.position>0;){Pn(r.read(8));let o=0;for(;r.read(8)===0&&o++<3;);if(o===4)i=r.read(7),n.blockFlags.unshift(i&1),r.position+=6,n.count++;else{((Pn(i)&126)>>1)+1!==n.count&&this._codecParser[Ge]("vorbis derived mode count did not match actual mode count");break}}return n.mask=(1<<Math.log2(n.count))-1,n}};var Cs=class{constructor(e,r,n){this._codecParser=e,this._headerCache=r,this._onCodec=n,this._continuedPacket=new ge,this._codec=null,this._isSupported=null,this._previousAbsoluteGranulePosition=null}get[Q](){return this._codec||""}_updateCodec(e,r){this._codec!==e&&(this._headerCache[We](),this._parser=new r(this._codecParser,this._headerCache,this._onCodec),this._codec=e)}_checkCodecSupport({data:e}){let r=Ie(e[N](0,8));switch(r){case"fishead\0":return!1;case"OpusHead":return this._updateCodec("opus",kn),!0;case(/^\x7fFLAC/.test(r)&&r):return this._updateCodec("flac",jt),!0;case(/^\x01vorbis/.test(r)&&r):return this._updateCodec(Ht,Hn),!0;default:return!1}}_checkPageSequenceNumber(e){e[oe]!==this._pageSequenceNumber+1&&this._pageSequenceNumber>1&&e[oe]>1&&this._codecParser[Ge]("Unexpected gap in Ogg Page Sequence Number.",`Expected: ${this._pageSequenceNumber+1}, Got: ${e[oe]}`),this._pageSequenceNumber=e[oe]}_parsePage(e){this._isSupported===null&&(this._pageSequenceNumber=e[oe],this._isSupported=this._checkCodecSupport(e)),this._checkPageSequenceNumber(e);let r=de.get(e),n=ce.get(r[Le]),i=0;if(r[Fe]=n[wt].map(o=>e[$][N](i,i+=o)),this._continuedPacket[_]&&(r[Fe][0]=Cn(this._continuedPacket,r[Fe][0]),this._continuedPacket=new ge),n[Er][n[Er][_]-1]===255&&(this._continuedPacket=Cn(this._continuedPacket,r[Fe].pop())),this._previousAbsoluteGranulePosition!==null&&(e[V]=Number(e[Ve]-this._previousAbsoluteGranulePosition)),this._previousAbsoluteGranulePosition=e[Ve],this._isSupported){let o=this._parser[It](e);return this._codecParser[Lt](o),o}else return e}},Vn=class extends be{constructor(e,r,n){super(e,r),this._onCodec=n,this.Frame=Nn,this.Header=Qt,this._streams=new Map,this._currentSerialNumber=null}get[Q](){let e=this._streams.get(this._currentSerialNumber);return e?e.codec:""}*[Ze](){let e=yield*this[Et](!0);this._currentSerialNumber=e[Je];let r=this._streams.get(this._currentSerialNumber);return r||(r=new Cs(this._codecParser,this._headerCache,this._onCodec),this._streams.set(this._currentSerialNumber,r)),e[Ee]&&this._streams.delete(this._currentSerialNumber),r._parsePage(e)}};var zs=()=>{},Gn=class{constructor(e,{onCodec:r,onCodecHeader:n,onCodecUpdate:i,enableLogging:o=!1,enableFrameCRC32:s=!0}={}){this._inputMimeType=e,this._onCodec=r||zs,this._onCodecHeader=n||zs,this._onCodecUpdate=i,this._enableLogging=o,this._crc32=s?dc:zs,this[We]()}get[Q](){return this._parser?this._parser[Q]:""}[We](){this._headerCache=new zn(this._onCodecHeader,this._onCodecUpdate),this._generator=this._getGenerator(),this._generator.next()}*flush(){this._flushing=!0;for(let e=this._generator.next();e.value;e=this._generator.next())yield e.value;this._flushing=!1,this[We]()}*parseChunk(e){for(let r=this._generator.next(e);r.value;r=this._generator.next())yield r.value}parseAll(e){return[...this.parseChunk(e),...this.flush()]}*_getGenerator(){if(this._inputMimeType.match(/aac/))this._parser=new On(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/mpeg/))this._parser=new Bn(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/flac/))this._parser=new jt(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/ogg/))this._parser=new Vn(this,this._headerCache,this._onCodec);else throw new Error(`Unsupported Codec ${mimeType}`);for(this._frameNumber=0,this._currentReadPosition=0,this._totalBytesIn=0,this._totalBytesOut=0,this._totalSamples=0,this._sampleRate=void 0,this._rawData=new Uint8Array(0);;){let e=yield*this._parser[Ze]();e&&(yield e)}}*[G](e=0,r=0){let n;for(;this._rawData[_]<=e+r;){if(n=yield,this._flushing)return this._rawData[N](r);n&&(this._totalBytesIn+=n[_],this._rawData=Cn(this._rawData,n))}return this._rawData[N](r)}[Be](e){this._currentReadPosition+=e,this._rawData=this._rawData[N](e)}[En](e){this._sampleRate=e[Le][H],e[Le][he]=e[$e]>0?Math.round(e[$][_]/e[$e])*8:0,e[dt]=this._frameNumber++,e[Gt]=this._totalBytesOut,e[Xt]=this._totalSamples,e[Wt]=this._totalSamples/this._sampleRate*1e3,e[cn]=this._crc32(e[$]),this._headerCache[ki](e[Le][he],e[Wt]),this._totalBytesOut+=e[$][_],this._totalSamples+=e[V]}[Lt](e){if(e[pe]){if(e[Ee]){let r=e[V];e[pe].forEach(n=>{let i=n[V];r<i&&(n[V]=r>0?r:0,n[$e]=n[V]/n[Le][H]*1e3),r-=i,this[En](n)})}else e[V]=0,e[pe].forEach(r=>{e[V]+=r[V],this[En](r)});e[$e]=e[V]/this._sampleRate*1e3||0,e[Xt]=this._totalSamples,e[Wt]=this._totalSamples/this._sampleRate*1e3||0,e[Gt]=this._totalBytesOut}else this[En](e)}_log(e,r){if(this._enableLogging){let n=[`${Q}: ${this[Q]}`,`inputMimeType: ${this._inputMimeType}`,`readPosition: ${this._currentReadPosition}`,`totalBytesIn: ${this._totalBytesIn}`,`${Gt}: ${this._totalBytesOut}`],i=Math.max(...n.map(o=>o[_]));r.push(`--stats--${"-".repeat(i-9)}`,...n,"-".repeat(i)),e("codec-parser",r.reduce((o,s)=>o+`
4
- `+s,""))}}[Ge](...e){this._log(console.warn,e)}[Ni](...e){this._log(console.error,e)}};var Sc=Gn;var Zi=pe;var eo=$;var Mc=Le;var _c=Ee;var Ac=Lr;var wc=Xt;function ut(t){var e=e;function r(){}e={};function n(I){throw I}var i,o,s,a,c,l,d,u,f,m,p;function y(){var I=p.buffer;i=new Int8Array(I),o=new Int16Array(I),a=new Uint8Array(I),c=new Uint16Array(I),s=new Int32Array(I),l=new Uint32Array(I),d=new Float32Array(I),u=new Float64Array(I),f=new BigInt64Array(I),m=new BigUint64Array(I)}for(var h=I=>{for(var ze,Gr,ir=0,si=0,ai=I.length,ci=new Uint8Array((ai*3>>2)-(I[ai-2]=="=")-(I[ai-1]=="="));ir<ai;ir+=4,si+=3)ze=J[I.charCodeAt(ir+1)],Gr=J[I.charCodeAt(ir+2)],ci[si]=J[I.charCodeAt(ir)]<<2|ze>>4,ci[si+1]=ze<<4|Gr>>2,ci[si+2]=Gr<<6|J[I.charCodeAt(ir+3)];return ci},g=()=>n(""),M=()=>{},x={},v=I=>I(),b=()=>performance.now(),S=(I,ze)=>{if(x[I]&&(clearTimeout(x[I].id),delete x[I]),!ze)return 0;var Gr=setTimeout(()=>{delete x[I],v(()=>pa(I,b()))},ze);return x[I]={id:Gr,timeout_ms:ze},0},A=Math.atan,w=Math.cos,P=Math.exp,L=Math.log,O=Math.pow,k=Math.sin,W=I=>{var ze=a.length;return I>>>=0,!1},T=I=>{throw`exit(${I})`},J=new Uint8Array(123),Me=25;Me>=0;--Me)J[48+Me]=52+Me,J[65+Me]=Me,J[97+Me]=26+Me;J[43]=62,J[47]=63;var Bt={e:g,d:M,f:S,b:A,a:w,i:P,h:L,g:O,c:k,k:W,j:T};function oi(I){Vr=I.n,la=I.o,da=I.p,ua=I.q,fa=I.r,ma=I.s,ha=I.t,pa=I.v}var Vr,la,da,ua,fa,ma,ha,pa;function xl(I){I.m()}ut.wasm||Object.defineProperty(ut,"wasm",{get:()=>String.raw`dynEncode012091253f87dì%nä= 4&¿nÝØä‘ÂLÚªã9ÚØ[äº\ ¼¡³R=}L]ŸÈÿ2 ÿù¶J1jj¡é,zäV|i¸Qk¹‡= 
3
+ `,"Visit https://github.com/eshaz/simple-yenc for more information"),Error(g)}}return y};function Z(){let t=Uint8Array,e=Float32Array;Z.modules||Object.defineProperties(Z,{modules:{value:new WeakMap},setModule:{value(r,n){Z.modules.set(r,Promise.resolve(n))}},getModule:{value(r,n){let i=Z.modules.get(r);return i||(n?i=WebAssembly.compile(ps(n)):(n=r.wasm,i=Z.inflateDynEncodeString(n).then(o=>WebAssembly.compile(o))),Z.modules.set(r,i)),i}},concatFloat32:{value(r,n){let i=new e(n),o=0,s=0;for(;o<r.length;)i.set(r[o],s),s+=r[o++].length;return i}},getDecodedAudio:{value:(r,n,i,o,s)=>({errors:r,channelData:n,samplesDecoded:i,sampleRate:o,bitDepth:s})},getDecodedAudioMultiChannel:{value(r,n,i,o,s,a){let c=[],l,d;for(l=0;l<i;l++){let u=[];for(d=0;d<n.length;)u.push(n[d++][l]||[]);c.push(Z.concatFloat32(u,o))}return Z.getDecodedAudio(r,c,o,s,a)}},inflateDynEncodeString:{value(r){return r=ps(r),new Promise(n=>{let i=String.raw`dynEncode012804c7886d(‰›•)((()>+ˆ*§§)§ˆ,§§§§)§ˆ+§§§)§+.-()(*)-+)(ˆ.7*§)i¸¸,3§(i¸¸,3/G+.••—š¡*(,˜ŽŽ(,3‡‡‰˜‡Š‰›+)2å:-œ),§H(P*DI*H(P*@I++hH)H*r,hH(H(P*<J,i)’^*<H,H(P*4’U((I-H(H*i0’J,^*DH+H-H*œšI+H,I*4)33H(H*H)“^*DH(H+H)^*@H+i§H)œi§›™3æ*).§K(iH“I/+§H,iHn,§H+i(H+i(rCJ0I,H*I-+hH,,hH(H-V)(i)œ’J.H.W)(i)’c)(H,i)“I,H-i*’I-4)33i(I.*hH(V)(H+n5(H(i*’I-i(I,i)I.+hH,i*’J+iHn,hi(I-i*I,+hH,H/’H-c)(H,iFn,hi(I,+hH,H0n5-H*V)(J(,hH/H(i)œ’J(H(V)(J(i)’c)(H)H(i)œ’H,c)(3H*i*’I*H,i)’I,4(3(-H(H,’W)(H-’I-H,i*’I,4)3(3(3H,H-’I1H+I,H.i)œH1V)(“J.i(v5(33H.-H(H,’i(c)(H,i*’I,4)333–)-§i*I*+§H*iHn,hiž73H,H(i)8(H+šJ+H)P*(H*’V)(J-“r,§H)P*,H.i)œ’H+H,“i)œ’V)(-H*i*’I*H+i)œI+H-H.’I.H,H-’i)œI,4)333Ã+)-§iø7i(^*(iü7I,*h+hH+iDn,h*hilI+i)I,+hH+,hH+iô7’H,c)(i)H+i´8’W)(œH,’I,H+i*’I+4)-+hH(H)8*J-i(p5.*h*h*hH-i')u,hH(P*(J+,hH(P*0J,H(P*,n50H+H,’H-b((3H(P*0i)’I.4)3H-i¨*n5*H-iÅ*s,hiž73H-i)œJ+V)&+I,H(H+V)æ,8(I.H(H*8*J-i(p51H-i)œJ+i¸7’V)(H(H+iø7’V)(8(’J/H(P*0J+s,hi73H+H,H.’J,’I.H(P*(m5(H.H(P*,s5.+hH,m5*H(P*(J.H+’H.H+H/“’U((b((H(H(P*0i)’J+^*0H,i)“I,4(3(3H(H.^*03H-i¨*o5)33i(73(3(3-H,H+i)žc)(H,i*’I,H+i)’I+4)33i)I-3H-3!2)0§K(i2“J,L(H,H(^*(H,H*^*4H,i(^*0H,i(^*DH,j(_*<H,H)P*(^*,H,H+P*(^*8*h*h+hH,i)8(I3i§I**h*h*h*h*h*h*hH,i*8(6+(),03H,j(_*@i*I-H,P*<J.i,’J(H,P*8J/s50H,H.i+’J0^*<i¦I*H.H,P*4J1’J.U(*H.U((J2›i')o5/H.U()I.H,H(^*<H0H1’U((H.i0œJ.i§›i0ži')™o5/H/H.H2šJ*H(’J.q50H,P*0J/H*’I-H,P*(J0,hH,P*,H-q,hi)I-423+hH*m5+H/H0’H(H1’U((b((H/i)’I/H(i)’I(H*i)“I*4(3(3H,H.^*<H,H-^*04*3iØ1U((5+i(I(i¨7i1^*(i$6iè1^*(i°7iè6^*(i¬7iÈ6^*(+hH(iÈ*n,hiÈ*I(+hH(i¨,n,hi¨,I(+hH(iØ,n,hiØ,I(+hH(iè,o,hH,i-’H(’i0c)(H(i*’I(4)33iè1i1H,i-’iÈ*8)Bi(I(+hH(ido,hH,i-’H(’i-c)(H(i*’I(4)33iÈ6iè6H,i-’iF8)BiØ1i)b((41-H,i-’H(’i/c)(H(i*’I(4)3(3(-H,i-’H(’i1c)(H(i*’I(4)3(3(-H,i-’H(’i0c)(H(i*’I(4)3(3(3H,H/^*0H,H(^*<3i(I*4*3H,H,i¸)’^*TH,H,iø-’^*PH,H,iX’^*LH,H,i(’^*HH,i-8(I(H,i-8(I-i¥I*H,i,8(I.H(iErH-iErš5)H(i©*’I1H-i)’I0i(i;H.i,’J(i(H(i(rCJ(“J*H*i;sCI*i¨1I-H(I/+hH/,hH,i-’H-V)(i)œ’H,i+8(c)(H/i)“I/H-i*’I-H*i)’I*4)-H(i)œi¨1’I/+hH(H*o,hH,i-’H/V)(i)œ’i(c)(H/i*’I/H(i)’I(4)33i¤I*H,iø-’H,i¸)’H,i-’i;8)5+H0H1’I2i(I-+hH-H2p,hH,H,iP’8*J*i(p5-H*i7u,hH,i-’H-i)œ’H*c)(H-i)’I-4*3i(I/i+I.i+I(*h*h*hH*i8“6*(*)3H-m,hi£I*403H-i)œH,’W)-I/i*I(4)3i3I.i/I(3H2H,H(8(H.’J(H-’J.p,hi¢I*4.3H,i-’H-i)œ’I*+hH(,hH*H/c)(H*i*’I*H(i)“I(4)-H.I-4+3(3(33H,W)1m,hiŸI*4,3H,iø-’H,i¸)’H,i-’H18)J(,hi¡I*H(i(p5,H1H,V)ú-H,V)ø-’o5,3H,i(’H,iX’H,i-’H1i)œ’H08)J(,hi I*H(i(p5,H0H,V)šH,V)˜’o5,3H,H,iP’H,iH’8+I*4+3(3(3H,i$6i¬78+I*3H*H3šm5(3i)I-H*i(r5)3H)H,P*0^*(H+H,P*<^*(H*I-3H,i2’L(H-33Á)+(i¨03b+(,(-(.(/(0(1(2(3(5(7(9(;(?(C(G(K(S([(c(k({(‹(›(«(Ë(ë( (*)(iø03O)()()()(*(*(*(*(+(+(+(+(,(,(,(,(-(-(-(-(i¨13M8(9(:(((0(/(1(.(2(-(3(,(4(+(5(*(6()(7(T7œ‰šœ‡Ž‰œš›*S7•œ‰Š”U”—Љ”›S0›‘–U œ`;Z.getModule(Z,i).then(o=>WebAssembly.instantiate(o,{})).then(({exports:o})=>{let s=new Map(Object.entries(o)),a=s.get("puff"),c=s.get("memory").buffer,l=new t(c),d=new DataView(c),u=s.get("__heap_base"),f=r.length,m=u;u+=4,d.setInt32(m,f,!0);let p=u;u+=f,l.set(r,p);let y=u;u+=4,d.setInt32(y,l.byteLength-u,!0),a(u,y,p,m),n(l.slice(u,u+d.getInt32(y,!0)))})})}}}),Object.defineProperty(this,"wasm",{enumerable:!0,get:()=>this._wasm}),this.getOutputChannels=(r,n,i)=>{let o=[],s=0;for(;s<n;)o.push(r.slice(s*i,s++*i+i));return o},this.allocateTypedArray=(r,n,i=!0)=>{let o=this._wasm.malloc(n.BYTES_PER_ELEMENT*r);return i&&this._pointers.add(o),{ptr:o,len:r,buf:new n(this._wasm.HEAP,o,r)}},this.free=()=>{this._pointers.forEach(r=>{this._wasm.free(r)}),this._pointers.clear()},this.codeToString=r=>{let n=[],i=new Uint8Array(this._wasm.HEAP);for(let o=i[r];o!==0;o=i[++r])n.push(o);return String.fromCharCode.apply(null,n)},this.addError=(r,n,i,o,s,a)=>{r.push({message:n,frameLength:i,frameNumber:o,inputBytes:s,outputSamples:a})},this.instantiate=(r,n)=>(n&&Z.setModule(r,n),this._wasm=new r(Z).instantiate(),this._pointers=new Set,this._wasm.ready.then(()=>this))}var Za=Ll(Ja(),1);var u0=()=>globalThis.Worker||Za.default,gr=class extends u0(){constructor(e,r,n,i){Z.modules||new Z;let o=Z.modules.get(n);if(!o){let s="text/javascript",a,c=`'use strict';(${((l,d,u)=>{let f,m,p=new Promise(y=>{m=y});self.onmessage=({data:{id:y,command:h,data:g}})=>{let S=p,x={id:y},v;h==="init"?(Object.defineProperties(l,{WASMAudioDecoderCommon:{value:d},EmscriptenWASM:{value:u},module:{value:g.module},isWebWorker:{value:!0}}),f=new l(g.options),m()):h==="free"?f.free():h==="ready"?S=S.then(()=>f.ready):h==="reset"?S=S.then(()=>f.reset()):(Object.assign(x,f[h](Array.isArray(g)?g.map(b=>new Uint8Array(b)):new Uint8Array(g))),v=x.channelData?x.channelData.map(b=>b.buffer):[]),S.then(()=>self.postMessage(x,v))}}).toString()})(${n}, ${Z}, ${i})`;try{a=typeof process.versions.node<"u"}catch{}o=a?`data:${s};base64,${Buffer.from(c).toString("base64")}`:URL.createObjectURL(new Blob([c],{type:s})),Z.modules.set(n,o)}super(o,{name:r}),this._id=Number.MIN_SAFE_INTEGER,this._enqueuedOperations=new Map,this.onmessage=({data:s})=>{let{id:a,...c}=s;this._enqueuedOperations.get(a)(c),this._enqueuedOperations.delete(a)},new i(Z).getModule().then(s=>{this.postToDecoder("init",{module:s,options:e})})}async postToDecoder(e,r){return new Promise(n=>{this.postMessage({command:e,id:this._id,data:r}),this._enqueuedOperations.set(this._id++,n)})}get ready(){return this.postToDecoder("ready")}async free(){await this.postToDecoder("free").finally(()=>{this.terminate()})}async reset(){await this.postToDecoder("reset")}};var Li=(t,e)=>{Object.defineProperty(t,"name",{value:e})};var ee=Symbol,ec=", ",T=(()=>{let t="front",e="side",r="rear",n="left",i="center",o="right";return["",t+" ",e+" ",r+" "].map(s=>[[n,o],[n,o,i],[n,i,o],[i,n,o],[i]].flatMap(a=>a.map(c=>s+c).join(ec)))})(),Ye="LFE",gt="monophonic (mono)",xt="stereo",Zr="surround",te=(t,...e)=>`${[gt,xt,`linear ${Zr}`,"quadraphonic",`5.0 ${Zr}`,`5.1 ${Zr}`,`6.1 ${Zr}`,`7.1 ${Zr}`][t-1]} (${e.join(ec)})`,en=[gt,te(2,T[0][0]),te(3,T[0][2]),te(4,T[1][0],T[3][0]),te(5,T[1][2],T[3][0]),te(6,T[1][2],T[3][0],Ye),te(7,T[1][2],T[2][0],T[3][4],Ye),te(8,T[1][2],T[2][0],T[3][0],Ye)],tc=192e3,rc=176400,Ei=96e3,Ii=88200,nc=64e3,bt=48e3,xr=44100,br=32e3,vr=24e3,Sr=22050,Mr=16e3,Pi=12e3,Ci=11025,_r=8e3,ic=7350,Ve="absoluteGranulePosition",N="bandwidth",me="bitDepth",he="bitrate",tn=he+"Maximum",rn=he+"Minimum",nn=he+"Nominal",qe="buffer",on=qe+"Fullness",Q="codec",pe=Q+"Frames",sn="coupledStreamCount",Ar="crc",an=Ar+"16",cn=Ar+"32",$="data",R="description",$e="duration",wr="emphasis",ln="hasOpusPadding",Le="header",vt="isContinuedPacket",dn="isCopyrighted",St="isFirstPage",un="isHome",Ee="isLastPage",tt="isOriginal",rt="isPrivate",fn="isVbr",_e="layer",M="length",D="mode",nt=D+"Extension",zi="mpeg",it=zi+"Version",mn="numberAACFrames",hn="outputGain",Ut="preSkip",pn="profile",Ri=ee(),ot="protection",ys="rawData",Fe="segments",k="subarray",Mt="version",Ht="vorbis",yn=Ht+"Comments",Lr=Ht+"Setup",Ti="block",gn=Ti+"ingStrategy",Fi=ee(),st=Ti+"Size",_t=Ti+"size0",At=Ti+"size1",xn=ee(),Bi="channel",at=Bi+"MappingFamily",bn=Bi+"MappingTable",ye=Bi+"Mode",vn=ee(),z=Bi+"s",oc="copyright",Sn=oc+"Id",Mn=oc+"IdStart",ct="frame",lt=ct+"Count",Ae=ct+"Length",Di="Number",dt=ct+Di,je=ct+"Padding",F=ct+"Size",sc="Rate",_n="inputSample"+sc,gs="page",Vt=gs+"Checksum",Er=ee(),wt=gs+"SegmentTable",oe=gs+"Sequence"+Di,xs="sample",An=xs+Di,V=xs+sc,Qe=ee(),G=xs+"s",Oi="stream",wn=Oi+"Count",Ln=Oi+"Info",Je=Oi+"Serial"+Di,bs=Oi+"StructureVersion",vs="total",Gt=vs+"BytesOut",Wt=vs+"Duration",Xt=vs+"Samples",W=ee(),Be=ee(),En=ee(),Lt=ee(),Ge=ee(),Ni=ee(),Ss=ee(),Et=ee(),X=ee(),De=ee(),Oe=ee(),Ze=ee(),It=ee(),ki=ee(),We=ee(),Xe=ee(),Ne=ee(),Ui=ee(),ge=Uint8Array,Pt=DataView,K="reserved",xe="bad",Ir="free",In="none",Hi="16bit CRC";var Ms=(t,e,r)=>{for(let n=0;n<t[M];n++){let i=e(n);for(let o=8;o>0;o--)i=r(i);t[n]=i}return t},m0=Ms(new ge(256),t=>t,t=>t&128?7^t<<1:t<<1),re=[Ms(new Uint16Array(256),t=>t<<8,t=>t<<1^(t&32768?32773:0))],ne=[Ms(new Uint32Array(256),t=>t,t=>t>>>1^(t&1)*3988292384)];for(let t=0;t<15;t++){re.push(new Uint16Array(256)),ne.push(new Uint32Array(256));for(let e=0;e<=255;e++)re[t+1][e]=re[0][re[t][e]>>>8]^re[t][e]<<8,ne[t+1][e]=ne[t][e]>>>8^ne[0][ne[t][e]&255]}var cc=t=>{let e=0,r=t[M];for(let n=0;n!==r;n++)e=m0[e^t[n]];return e},lc=t=>{let e=t[M],r=e-16,n=0,i=0;for(;i<=r;)n^=t[i++]<<8|t[i++],n=re[15][n>>8]^re[14][n&255]^re[13][t[i++]]^re[12][t[i++]]^re[11][t[i++]]^re[10][t[i++]]^re[9][t[i++]]^re[8][t[i++]]^re[7][t[i++]]^re[6][t[i++]]^re[5][t[i++]]^re[4][t[i++]]^re[3][t[i++]]^re[2][t[i++]]^re[1][t[i++]]^re[0][t[i++]];for(;i!==e;)n=(n&255)<<8^re[0][n>>8^t[i++]];return n},dc=t=>{let e=t[M],r=e-16,n=0,i=0;for(;i<=r;)n=ne[15][(t[i++]^n)&255]^ne[14][(t[i++]^n>>>8)&255]^ne[13][(t[i++]^n>>>16)&255]^ne[12][t[i++]^n>>>24]^ne[11][t[i++]]^ne[10][t[i++]]^ne[9][t[i++]]^ne[8][t[i++]]^ne[7][t[i++]]^ne[6][t[i++]]^ne[5][t[i++]]^ne[4][t[i++]]^ne[3][t[i++]]^ne[2][t[i++]]^ne[1][t[i++]]^ne[0][t[i++]];for(;i!==e;)n=ne[0][(n^t[i++])&255]^n>>>8;return n^-1},Cn=(...t)=>{let e=new ge(t.reduce((r,n)=>r+n[M],0));return t.reduce((r,n)=>(e.set(n,r),r+n[M]),0),e},Ie=t=>String.fromCharCode(...t),ac=[0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15],Pn=t=>ac[t&15]<<4|ac[t>>4],Vi=class{constructor(e){this._data=e,this._pos=e[M]*8}set position(e){this._pos=e}get position(){return this._pos}read(e){let r=Math.floor(this._pos/8),n=this._pos%8;return this._pos-=e,(Pn(this._data[r-1])<<8)+Pn(this._data[r])>>7-n&255}},uc=(t,e)=>{try{return t.getBigInt64(e,!0)}catch{let r=t.getUint8(e+7)&128?-1:1,n=t.getUint32(e,!0),i=t.getUint32(e+4,!0);return r===-1&&(n=~n+1,i=~i+1),i>1048575&&console.warn("This platform does not support BigInt"),r*(n+i*2**32)}};var zn=class{constructor(e,r){this._onCodecHeader=e,this._onCodecUpdate=r,this[We]()}[Xe](){this._isEnabled=!0}[We](){this._headerCache=new Map,this._codecUpdateData=new WeakMap,this._codecHeaderSent=!1,this._codecShouldUpdate=!1,this._bitrate=null,this._isEnabled=!1}[ki](e,r){if(this._onCodecUpdate){this._bitrate!==e&&(this._bitrate=e,this._codecShouldUpdate=!0);let n=this._codecUpdateData.get(this._headerCache.get(this._currentHeader));this._codecShouldUpdate&&n&&this._onCodecUpdate({bitrate:e,...n},r),this._codecShouldUpdate=!1}}[X](e){let r=this._headerCache.get(e);return r&&this._updateCurrentHeader(e),r}[De](e,r,n){this._isEnabled&&(this._codecHeaderSent||(this._onCodecHeader({...r}),this._codecHeaderSent=!0),this._updateCurrentHeader(e),this._headerCache.set(e,r),this._codecUpdateData.set(r,n))}_updateCurrentHeader(e){this._onCodecUpdate&&e!==this._currentHeader&&(this._codecShouldUpdate=!0,this._currentHeader=e)}};var ce=new WeakMap,de=new WeakMap;var be=class{constructor(e,r){this._codecParser=e,this._headerCache=r}*[Ss](){let e;do{if(e=yield*this.Frame[Oe](this._codecParser,this._headerCache,0),e)return e;this._codecParser[Be](1)}while(!0)}*[Et](e){let r=yield*this[Ss](),n=de.get(r)[M];if(e||this._codecParser._flushing||(yield*this.Header[X](this._codecParser,this._headerCache,n)))return this._headerCache[Xe](),this._codecParser[Be](n),this._codecParser[Lt](r),r;this._codecParser[Ge](`Missing ${ct} at ${n} bytes from current position.`,`Dropping current ${ct} and trying again.`),this._headerCache[We](),this._codecParser[Be](1)}};var Kt=class{constructor(e,r){de.set(this,{[Le]:e}),this[$]=r}};var Pe=class extends Kt{static*[Oe](e,r,n,i,o){let s=yield*e[X](n,i,o);if(s){let a=ce.get(s)[Ae],c=ce.get(s)[G],l=(yield*n[W](a,o))[k](0,a);return new r(s,l,c)}else return null}constructor(e,r,n){super(e,r),this[Le]=e,this[G]=n,this[$e]=n/e[V]*1e3,this[dt]=null,this[Gt]=null,this[Xt]=null,this[Wt]=null,de.get(this)[M]=r[M]}};var _s="unsynchronizationFlag",As="extendedHeaderFlag",ws="experimentalFlag",Ls="footerPresent",Rn=class t{static*getID3v2Header(e,r,n){let o={},s=yield*e[W](3,n);if(s[0]!==73||s[1]!==68||s[2]!==51||(s=yield*e[W](10,n),o[Mt]=`id3v2.${s[3]}.${s[4]}`,s[5]&15)||(o[_s]=!!(s[5]&128),o[As]=!!(s[5]&64),o[ws]=!!(s[5]&32),o[Ls]=!!(s[5]&16),s[6]&128||s[7]&128||s[8]&128||s[9]&128))return null;let a=s[6]<<21|s[7]<<14|s[8]<<7|s[9];return o[M]=10+a,new t(o)}constructor(e){this[Mt]=e[Mt],this[_s]=e[_s],this[As]=e[As],this[ws]=e[ws],this[Ls]=e[Ls],this[M]=e[M]}};var Ce=class{constructor(e){ce.set(this,e),this[me]=e[me],this[he]=null,this[z]=e[z],this[ye]=e[ye],this[V]=e[V]}};var yc={0:[Ir,Ir,Ir,Ir,Ir],16:[32,32,32,32,8],240:[xe,xe,xe,xe,xe]},Gi=(t,e,r)=>8*((t+r)%e+e)*(1<<(t+r)/e)-8*e*(e/8|0);for(let t=2;t<15;t++)yc[t<<4]=[t*32,Gi(t,4,0),Gi(t,4,-1),Gi(t,8,4),Gi(t,8,0)];var h0=0,p0=1,y0=2,g0=3,fc=4,Wi="bands ",Xi=" to 31",mc={0:Wi+4+Xi,16:Wi+8+Xi,32:Wi+12+Xi,48:Wi+16+Xi},Yt="bitrateIndex",Tn="v2",ji="v1",Ki="Intensity stereo ",Yi=", MS stereo ",qi="on",$i="off",x0={0:Ki+$i+Yi+$i,16:Ki+qi+Yi+$i,32:Ki+$i+Yi+qi,48:Ki+qi+Yi+qi},Es={0:{[R]:K},2:{[R]:"Layer III",[je]:1,[nt]:x0,[ji]:{[Yt]:y0,[G]:1152},[Tn]:{[Yt]:fc,[G]:576}},4:{[R]:"Layer II",[je]:1,[nt]:mc,[G]:1152,[ji]:{[Yt]:p0},[Tn]:{[Yt]:fc}},6:{[R]:"Layer I",[je]:4,[nt]:mc,[G]:384,[ji]:{[Yt]:h0},[Tn]:{[Yt]:g0}}},Is="MPEG Version ",hc="ISO/IEC ",b0={0:{[R]:`${Is}2.5 (later extension of MPEG 2)`,[_e]:Tn,[V]:{0:Ci,4:Pi,8:_r,12:K}},8:{[R]:K},16:{[R]:`${Is}2 (${hc}13818-3)`,[_e]:Tn,[V]:{0:Sr,4:vr,8:Mr,12:K}},24:{[R]:`${Is}1 (${hc}11172-3)`,[_e]:ji,[V]:{0:xr,4:bt,8:br,12:K}},length:M},v0={0:Hi,1:In},S0={0:In,1:"50/15 ms",2:K,3:"CCIT J.17"},pc={0:{[z]:2,[R]:xt},64:{[z]:2,[R]:"joint "+xt},128:{[z]:2,[R]:"dual channel"},192:{[z]:1,[R]:gt}},qt=class t extends Ce{static*[X](e,r,n){let i={},o=yield*Rn.getID3v2Header(e,r,n);o&&(yield*e[W](o[M],n),e[Be](o[M]));let s=yield*e[W](4,n),a=Ie(s[k](0,4)),c=r[X](a);if(c)return new t(c);if(s[0]!==255||s[1]<224)return null;let l=b0[s[1]&24];if(l[R]===K)return null;let d=s[1]&6;if(Es[d][R]===K)return null;let u={...Es[d],...Es[d][l[_e]]};if(i[it]=l[R],i[_e]=u[R],i[G]=u[G],i[ot]=v0[s[1]&1],i[M]=4,i[he]=yc[s[2]&240][u[Yt]],i[he]===xe||(i[V]=l[V][s[2]&12],i[V]===K)||(i[je]=s[2]&2&&u[je],i[rt]=!!(s[2]&1),i[Ae]=Math.floor(125*i[he]*i[G]/i[V]+i[je]),!i[Ae]))return null;let f=s[3]&192;if(i[ye]=pc[f][R],i[z]=pc[f][z],i[nt]=u[nt][s[3]&48],i[dn]=!!(s[3]&8),i[tt]=!!(s[3]&4),i[wr]=S0[s[3]&3],i[wr]===K)return null;i[me]=16;{let{length:m,frameLength:p,samples:y,...h}=i;r[De](a,i,h)}return new t(i)}constructor(e){super(e),this[he]=e[he],this[wr]=e[wr],this[je]=e[je],this[dn]=e[dn],this[tt]=e[tt],this[rt]=e[rt],this[_e]=e[_e],this[nt]=e[nt],this[it]=e[it],this[ot]=e[ot]}};var Fn=class t extends Pe{static*[Oe](e,r,n){return yield*super[Oe](qt,t,e,r,n)}constructor(e,r,n){super(e,r,n)}};var Bn=class extends be{constructor(e,r,n){super(e,r),this.Frame=Fn,this.Header=qt,n(this[Q])}get[Q](){return zi}*[Ze](){return yield*this[Et]()}};var M0={0:"MPEG-4",8:"MPEG-2"},_0={0:"valid",2:xe,4:xe,6:xe},A0={0:Hi,1:In},w0={0:"AAC Main",64:"AAC LC (Low Complexity)",128:"AAC SSR (Scalable Sample Rate)",192:"AAC LTP (Long Term Prediction)"},L0={0:Ei,4:Ii,8:nc,12:bt,16:xr,20:br,24:vr,28:Sr,32:Mr,36:Pi,40:Ci,44:_r,48:ic,52:K,56:K,60:"frequency is written explicitly"},gc={0:{[z]:0,[R]:"Defined in AOT Specific Config"},64:{[z]:1,[R]:gt},128:{[z]:2,[R]:te(2,T[0][0])},192:{[z]:3,[R]:te(3,T[1][3])},256:{[z]:4,[R]:te(4,T[1][3],T[3][4])},320:{[z]:5,[R]:te(5,T[1][3],T[3][0])},384:{[z]:6,[R]:te(6,T[1][3],T[3][0],Ye)},448:{[z]:8,[R]:te(8,T[1][3],T[2][0],T[3][0],Ye)}},$t=class t extends Ce{static*[X](e,r,n){let i={},o=yield*e[W](7,n),s=Ie([o[0],o[1],o[2],o[3]&252|o[6]&3]),a=r[X](s);if(a)Object.assign(i,a);else{if(o[0]!==255||o[1]<240||(i[it]=M0[o[1]&8],i[_e]=_0[o[1]&6],i[_e]===xe))return null;let l=o[1]&1;i[ot]=A0[l],i[M]=l?7:9,i[Ri]=o[2]&192,i[Qe]=o[2]&60;let d=o[2]&2;if(i[pn]=w0[i[Ri]],i[V]=L0[i[Qe]],i[V]===K)return null;i[rt]=!!d,i[vn]=(o[2]<<8|o[3])&448,i[ye]=gc[i[vn]][R],i[z]=gc[i[vn]][z],i[tt]=!!(o[3]&32),i[un]=!!(o[3]&8),i[Sn]=!!(o[3]&8),i[Mn]=!!(o[3]&4),i[me]=16,i[G]=1024,i[mn]=o[6]&3;{let{length:u,channelModeBits:f,profileBits:m,sampleRateBits:p,frameLength:y,samples:h,numberAACFrames:g,...S}=i;r[De](s,i,S)}}if(i[Ae]=(o[3]<<11|o[4]<<3|o[5]>>5)&8191,!i[Ae])return null;let c=(o[5]<<6|o[6]>>2)&2047;return i[on]=c===2047?"VBR":c,new t(i)}constructor(e){super(e),this[Sn]=e[Sn],this[Mn]=e[Mn],this[on]=e[on],this[un]=e[un],this[tt]=e[tt],this[rt]=e[rt],this[_e]=e[_e],this[M]=e[M],this[it]=e[it],this[mn]=e[mn],this[pn]=e[pn],this[ot]=e[ot]}get audioSpecificConfig(){let e=ce.get(this),r=e[Ri]+64<<5|e[Qe]<<5|e[vn]>>3,n=new ge(2);return new Pt(n[qe]).setUint16(0,r,!1),n}};var Dn=class t extends Pe{static*[Oe](e,r,n){return yield*super[Oe]($t,t,e,r,n)}constructor(e,r,n){super(e,r,n)}};var On=class extends be{constructor(e,r,n){super(e,r),this.Frame=Dn,this.Header=$t,n(this[Q])}get[Q](){return"aac"}*[Ze](){return yield*this[Et]()}};var Ct=class t extends Pe{static _getFrameFooterCrc16(e){return(e[e[M]-2]<<8)+e[e[M]-1]}static[Ui](e){let r=t._getFrameFooterCrc16(e),n=lc(e[k](0,-2));return r===n}constructor(e,r,n){r[Ln]=n,r[an]=t._getFrameFooterCrc16(e),super(r,e,ce.get(r)[G])}};var xc="get from STREAMINFO metadata block",E0={0:"Fixed",1:"Variable"},bc={0:K,16:192};for(let t=2;t<16;t++)bc[t<<4]=t<6?576*2**(t-2):2**t;var I0={0:xc,1:Ii,2:rc,3:tc,4:_r,5:Mr,6:Sr,7:vr,8:br,9:xr,10:bt,11:Ei,15:xe},P0={0:{[z]:1,[R]:gt},16:{[z]:2,[R]:te(2,T[0][0])},32:{[z]:3,[R]:te(3,T[0][1])},48:{[z]:4,[R]:te(4,T[1][0],T[3][0])},64:{[z]:5,[R]:te(5,T[1][1],T[3][0])},80:{[z]:6,[R]:te(6,T[1][1],Ye,T[3][0])},96:{[z]:7,[R]:te(7,T[1][1],Ye,T[3][4],T[2][0])},112:{[z]:8,[R]:te(8,T[1][1],Ye,T[3][0],T[2][0])},128:{[z]:2,[R]:`${xt} (left, diff)`},144:{[z]:2,[R]:`${xt} (diff, right)`},160:{[z]:2,[R]:`${xt} (avg, diff)`},176:K,192:K,208:K,224:K,240:K},C0={0:xc,2:8,4:12,6:K,8:16,10:20,12:24,14:K},zt=class t extends Ce{static _decodeUTF8Int(e){if(e[0]>254)return null;if(e[0]<128)return{value:e[0],length:1};let r=1;for(let s=64;s&e[0];s>>=1)r++;let n=r-1,i=0,o=0;for(;n>0;o+=6,n--){if((e[n]&192)!==128)return null;i|=(e[n]&63)<<o}return i|=(e[n]&127>>r)<<o,{value:i,length:r}}static[Ne](e,r){let n={[W]:function*(){return e}};return t[X](n,r,0).next().value}static*[X](e,r,n){let i=yield*e[W](6,n);if(i[0]!==255||!(i[1]===248||i[1]===249))return null;let o={},s=Ie(i[k](0,4)),a=r[X](s);if(a)Object.assign(o,a);else{if(o[Fi]=i[1]&1,o[gn]=E0[o[Fi]],o[xn]=i[2]&240,o[Qe]=i[2]&15,o[st]=bc[o[xn]],o[st]===K||(o[V]=I0[o[Qe]],o[V]===xe)||i[3]&1)return null;let l=P0[i[3]&240];if(l===K||(o[z]=l[z],o[ye]=l[R],o[me]=C0[i[3]&14],o[me]===K))return null}o[M]=5,i=yield*e[W](o[M]+8,n);let c=t._decodeUTF8Int(i[k](4));if(!c||(o[Fi]?o[An]=c.value:o[dt]=c.value,o[M]+=c[M],o[xn]===96?(i[M]<o[M]&&(i=yield*e[W](o[M],n)),o[st]=i[o[M]-1]+1,o[M]+=1):o[xn]===112&&(i[M]<o[M]&&(i=yield*e[W](o[M],n)),o[st]=(i[o[M]-1]<<8)+i[o[M]]+1,o[M]+=2),o[G]=o[st],o[Qe]===12?(i[M]<o[M]&&(i=yield*e[W](o[M],n)),o[V]=i[o[M]-1]*1e3,o[M]+=1):o[Qe]===13?(i[M]<o[M]&&(i=yield*e[W](o[M],n)),o[V]=(i[o[M]-1]<<8)+i[o[M]],o[M]+=2):o[Qe]===14&&(i[M]<o[M]&&(i=yield*e[W](o[M],n)),o[V]=((i[o[M]-1]<<8)+i[o[M]])*10,o[M]+=2),i[M]<o[M]&&(i=yield*e[W](o[M],n)),o[Ar]=i[o[M]-1],o[Ar]!==cc(i[k](0,o[M]-1))))return null;if(!a){let{blockingStrategyBits:l,frameNumber:d,sampleNumber:u,samples:f,sampleRateBits:m,blockSizeBits:p,crc:y,length:h,...g}=o;r[De](s,o,g)}return new t(o)}constructor(e){super(e),this[an]=null,this[gn]=e[gn],this[st]=e[st],this[dt]=e[dt],this[An]=e[An],this[Ln]=null}};var z0=2,R0=512*1024,jt=class extends be{constructor(e,r,n){super(e,r),this.Frame=Ct,this.Header=zt,n(this[Q])}get[Q](){return"flac"}*_getNextFrameSyncOffset(e){let r=yield*this._codecParser[W](2,0),n=r[M]-2;for(;e<n;){if(r[e]===255){let o=r[e+1];if(o===248||o===249)break;o!==255&&e++}e++}return e}*[Ze](){do{let e=yield*zt[X](this._codecParser,this._headerCache,0);if(e){let r=ce.get(e)[M]+z0;for(;r<=R0;){if(this._codecParser._flushing||(yield*zt[X](this._codecParser,this._headerCache,r))){let n=yield*this._codecParser[W](r);if(this._codecParser._flushing||(n=n[k](0,r)),Ct[Ui](n)){let i=new Ct(n,e);return this._headerCache[Xe](),this._codecParser[Be](r),this._codecParser[Lt](i),i}}r=yield*this._getNextFrameSyncOffset(r+1)}this._codecParser[Ge](`Unable to sync FLAC frame after searching ${r} bytes.`),this._codecParser[Be](r)}else this._codecParser[Be](yield*this._getNextFrameSyncOffset(1))}while(!0)}[It](e){return e[oe]===0?(this._headerCache[Xe](),this._streamInfo=e[$][k](13)):e[oe]===1||(e[pe]=de.get(e)[Fe].map(r=>{let n=zt[Ne](r,this._headerCache);if(n)return new Ct(r,n,this._streamInfo);this._codecParser[Ge]("Failed to parse Ogg FLAC frame","Skipping invalid FLAC frame")}).filter(r=>!!r)),e}};var Qt=class t{static*[X](e,r,n){let i={},o=yield*e[W](28,n);if(o[0]!==79||o[1]!==103||o[2]!==103||o[3]!==83||(i[bs]=o[4],o[5]&248))return null;i[Ee]=!!(o[5]&4),i[St]=!!(o[5]&2),i[vt]=!!(o[5]&1);let a=new Pt(ge.from(o[k](0,28))[qe]);i[Ve]=uc(a,6),i[Je]=a.getInt32(14,!0),i[oe]=a.getInt32(18,!0),i[Vt]=a.getInt32(22,!0);let c=o[26];i[M]=c+27,o=yield*e[W](i[M],n),i[Ae]=0,i[wt]=[],i[Er]=ge.from(o[k](27,i[M]));for(let l=0,d=0;l<c;l++){let u=i[Er][l];i[Ae]+=u,d+=u,(u!==255||l===c-1)&&(i[wt].push(d),d=0)}return new t(i)}constructor(e){ce.set(this,e),this[Ve]=e[Ve],this[vt]=e[vt],this[St]=e[St],this[Ee]=e[Ee],this[wt]=e[wt],this[oe]=e[oe],this[Vt]=e[Vt],this[Je]=e[Je]}};var Nn=class t extends Kt{static*[Oe](e,r,n){let i=yield*Qt[X](e,r,n);if(i){let o=ce.get(i)[Ae],s=ce.get(i)[M],a=s+o,c=(yield*e[W](a,0))[k](0,a),l=c[k](s,a);return new t(i,l,c)}else return null}constructor(e,r,n){super(e,r),de.get(this)[M]=n[M],this[pe]=[],this[ys]=n,this[Ve]=e[Ve],this[cn]=e[Vt],this[$e]=0,this[vt]=e[vt],this[St]=e[St],this[Ee]=e[Ee],this[oe]=e[oe],this[G]=0,this[Je]=e[Je]}};var Pr=class extends Pe{constructor(e,r,n){super(r,e,n)}};var vc={0:en.slice(0,2),1:en},ke="SILK-only",ue="CELT-only",Qi="Hybrid",Rt="narrowband",Ji="medium-band",Tt="wideband",Cr="super-wideband",zr="fullband",T0={0:{[D]:ke,[N]:Rt,[F]:10},8:{[D]:ke,[N]:Rt,[F]:20},16:{[D]:ke,[N]:Rt,[F]:40},24:{[D]:ke,[N]:Rt,[F]:60},32:{[D]:ke,[N]:Ji,[F]:10},40:{[D]:ke,[N]:Ji,[F]:20},48:{[D]:ke,[N]:Ji,[F]:40},56:{[D]:ke,[N]:Ji,[F]:60},64:{[D]:ke,[N]:Tt,[F]:10},72:{[D]:ke,[N]:Tt,[F]:20},80:{[D]:ke,[N]:Tt,[F]:40},88:{[D]:ke,[N]:Tt,[F]:60},96:{[D]:Qi,[N]:Cr,[F]:10},104:{[D]:Qi,[N]:Cr,[F]:20},112:{[D]:Qi,[N]:zr,[F]:10},120:{[D]:Qi,[N]:zr,[F]:20},128:{[D]:ue,[N]:Rt,[F]:2.5},136:{[D]:ue,[N]:Rt,[F]:5},144:{[D]:ue,[N]:Rt,[F]:10},152:{[D]:ue,[N]:Rt,[F]:20},160:{[D]:ue,[N]:Tt,[F]:2.5},168:{[D]:ue,[N]:Tt,[F]:5},176:{[D]:ue,[N]:Tt,[F]:10},184:{[D]:ue,[N]:Tt,[F]:20},192:{[D]:ue,[N]:Cr,[F]:2.5},200:{[D]:ue,[N]:Cr,[F]:5},208:{[D]:ue,[N]:Cr,[F]:10},216:{[D]:ue,[N]:Cr,[F]:20},224:{[D]:ue,[N]:zr,[F]:2.5},232:{[D]:ue,[N]:zr,[F]:5},240:{[D]:ue,[N]:zr,[F]:10},248:{[D]:ue,[N]:zr,[F]:20}},Rr=class t extends Ce{static[Ne](e,r,n){let i={};if(i[z]=e[9],i[at]=e[18],i[M]=i[at]!==0?21+i[z]:19,e[M]<i[M])throw new Error("Out of data while inside an Ogg Page");let o=r[0]&3,s=o===3?2:1,a=Ie(e[k](0,i[M]))+Ie(r[k](0,s)),c=n[X](a);if(c)return new t(c);if(a.substr(0,8)!=="OpusHead"||e[8]!==1)return null;i[$]=ge.from(e[k](0,i[M]));let l=new Pt(i[$][qe]);if(i[me]=16,i[Ut]=l.getUint16(10,!0),i[_n]=l.getUint32(12,!0),i[V]=bt,i[hn]=l.getInt16(16,!0),i[at]in vc&&(i[ye]=vc[i[at]][i[z]-1],!i[ye]))return null;i[at]!==0&&(i[wn]=e[19],i[sn]=e[20],i[bn]=[...e[k](21,i[z]+21)]);let d=T0[248&r[0]];switch(i[D]=d[D],i[N]=d[N],i[F]=d[F],o){case 0:i[lt]=1;break;case 1:case 2:i[lt]=2;break;case 3:i[fn]=!!(128&r[1]),i[ln]=!!(64&r[1]),i[lt]=63&r[1];break;default:return null}{let{length:u,data:f,channelMappingFamily:m,...p}=i;n[De](a,i,p)}return new t(i)}constructor(e){super(e),this[$]=e[$],this[N]=e[N],this[at]=e[at],this[bn]=e[bn],this[sn]=e[sn],this[lt]=e[lt],this[F]=e[F],this[ln]=e[ln],this[_n]=e[_n],this[fn]=e[fn],this[D]=e[D],this[hn]=e[hn],this[Ut]=e[Ut],this[wn]=e[wn]}};var kn=class extends be{constructor(e,r,n){super(e,r),this.Frame=Pr,this.Header=Rr,n(this[Q]),this._identificationHeader=null,this._preSkipRemaining=null}get[Q](){return"opus"}[It](e){return e[oe]===0?(this._headerCache[Xe](),this._identificationHeader=e[$]):e[oe]===1||(e[pe]=de.get(e)[Fe].map(r=>{let n=Rr[Ne](this._identificationHeader,r,this._headerCache);if(n){this._preSkipRemaining===null&&(this._preSkipRemaining=n[Ut]);let i=n[F]*n[lt]/1e3*n[V];return this._preSkipRemaining>0&&(this._preSkipRemaining-=i,i=this._preSkipRemaining<0?-this._preSkipRemaining:0),new Pr(r,n,i)}this._codecParser[Ni]("Failed to parse Ogg Opus Header","Not a valid Ogg Opus file")})),e}};var Tr=class extends Pe{constructor(e,r,n){super(r,e,n)}};var Ps={};for(let t=0;t<8;t++)Ps[t+6]=2**(6+t);var Un=class t extends Ce{static[Ne](e,r,n,i){if(e[M]<30)throw new Error("Out of data while inside an Ogg Page");let o=Ie(e[k](0,30)),s=r[X](o);if(s)return new t(s);let a={[M]:30};if(o.substr(0,7)!=="vorbis")return null;a[$]=ge.from(e[k](0,30));let c=new Pt(a[$][qe]);if(a[Mt]=c.getUint32(7,!0),a[Mt]!==0||(a[z]=e[11],a[ye]=en[a[z]-1]||"application defined",a[V]=c.getUint32(12,!0),a[tn]=c.getInt32(16,!0),a[nn]=c.getInt32(20,!0),a[rn]=c.getInt32(24,!0),a[At]=Ps[(e[28]&240)>>4],a[_t]=Ps[e[28]&15],a[_t]>a[At])||e[29]!==1)return null;a[me]=32,a[Lr]=i,a[yn]=n;{let{length:l,data:d,version:u,vorbisSetup:f,vorbisComments:m,...p}=a;r[De](o,a,p)}return new t(a)}constructor(e){super(e),this[tn]=e[tn],this[rn]=e[rn],this[nn]=e[nn],this[_t]=e[_t],this[At]=e[At],this[$]=e[$],this[yn]=e[yn],this[Lr]=e[Lr]}};var Hn=class extends be{constructor(e,r,n){super(e,r),this.Frame=Tr,n(this[Q]),this._identificationHeader=null,this._setupComplete=!1,this._prevBlockSize=null}get[Q](){return Ht}[It](e){e[pe]=[];for(let r of de.get(e)[Fe])if(r[0]===1)this._headerCache[Xe](),this._identificationHeader=e[$],this._setupComplete=!1;else if(r[0]===3)this._vorbisComments=r;else if(r[0]===5)this._vorbisSetup=r,this._mode=this._parseSetupHeader(r),this._setupComplete=!0;else if(this._setupComplete){let n=Un[Ne](this._identificationHeader,this._headerCache,this._vorbisComments,this._vorbisSetup);n?e[pe].push(new Tr(r,n,this._getSamples(r,n))):this._codecParser[logError]("Failed to parse Ogg Vorbis Header","Not a valid Ogg Vorbis file")}return e}_getSamples(e,r){let i=this._mode.blockFlags[e[0]>>1&this._mode.mask]?r[At]:r[_t],o=this._prevBlockSize===null?0:(this._prevBlockSize+i)/4;return this._prevBlockSize=i,o}_parseSetupHeader(e){let r=new Vi(e),n={count:0,blockFlags:[]};for(;(r.read(1)&1)!==1;);let i;for(;n.count<64&&r.position>0;){Pn(r.read(8));let o=0;for(;r.read(8)===0&&o++<3;);if(o===4)i=r.read(7),n.blockFlags.unshift(i&1),r.position+=6,n.count++;else{((Pn(i)&126)>>1)+1!==n.count&&this._codecParser[Ge]("vorbis derived mode count did not match actual mode count");break}}return n.mask=(1<<Math.log2(n.count))-1,n}};var Cs=class{constructor(e,r,n){this._codecParser=e,this._headerCache=r,this._onCodec=n,this._continuedPacket=new ge,this._codec=null,this._isSupported=null,this._previousAbsoluteGranulePosition=null}get[Q](){return this._codec||""}_updateCodec(e,r){this._codec!==e&&(this._headerCache[We](),this._parser=new r(this._codecParser,this._headerCache,this._onCodec),this._codec=e)}_checkCodecSupport({data:e}){let r=Ie(e[k](0,8));switch(r){case"fishead\0":return!1;case"OpusHead":return this._updateCodec("opus",kn),!0;case(/^\x7fFLAC/.test(r)&&r):return this._updateCodec("flac",jt),!0;case(/^\x01vorbis/.test(r)&&r):return this._updateCodec(Ht,Hn),!0;default:return!1}}_checkPageSequenceNumber(e){e[oe]!==this._pageSequenceNumber+1&&this._pageSequenceNumber>1&&e[oe]>1&&this._codecParser[Ge]("Unexpected gap in Ogg Page Sequence Number.",`Expected: ${this._pageSequenceNumber+1}, Got: ${e[oe]}`),this._pageSequenceNumber=e[oe]}_parsePage(e){this._isSupported===null&&(this._pageSequenceNumber=e[oe],this._isSupported=this._checkCodecSupport(e)),this._checkPageSequenceNumber(e);let r=de.get(e),n=ce.get(r[Le]),i=0;if(r[Fe]=n[wt].map(o=>e[$][k](i,i+=o)),this._continuedPacket[M]&&(r[Fe][0]=Cn(this._continuedPacket,r[Fe][0]),this._continuedPacket=new ge),n[Er][n[Er][M]-1]===255&&(this._continuedPacket=Cn(this._continuedPacket,r[Fe].pop())),this._previousAbsoluteGranulePosition!==null&&(e[G]=Number(e[Ve]-this._previousAbsoluteGranulePosition)),this._previousAbsoluteGranulePosition=e[Ve],this._isSupported){let o=this._parser[It](e);return this._codecParser[Lt](o),o}else return e}},Vn=class extends be{constructor(e,r,n){super(e,r),this._onCodec=n,this.Frame=Nn,this.Header=Qt,this._streams=new Map,this._currentSerialNumber=null}get[Q](){let e=this._streams.get(this._currentSerialNumber);return e?e.codec:""}*[Ze](){let e=yield*this[Et](!0);this._currentSerialNumber=e[Je];let r=this._streams.get(this._currentSerialNumber);return r||(r=new Cs(this._codecParser,this._headerCache,this._onCodec),this._streams.set(this._currentSerialNumber,r)),e[Ee]&&this._streams.delete(this._currentSerialNumber),r._parsePage(e)}};var zs=()=>{},Gn=class{constructor(e,{onCodec:r,onCodecHeader:n,onCodecUpdate:i,enableLogging:o=!1,enableFrameCRC32:s=!0}={}){this._inputMimeType=e,this._onCodec=r||zs,this._onCodecHeader=n||zs,this._onCodecUpdate=i,this._enableLogging=o,this._crc32=s?dc:zs,this[We]()}get[Q](){return this._parser?this._parser[Q]:""}[We](){this._headerCache=new zn(this._onCodecHeader,this._onCodecUpdate),this._generator=this._getGenerator(),this._generator.next()}*flush(){this._flushing=!0;for(let e=this._generator.next();e.value;e=this._generator.next())yield e.value;this._flushing=!1,this[We]()}*parseChunk(e){for(let r=this._generator.next(e);r.value;r=this._generator.next())yield r.value}parseAll(e){return[...this.parseChunk(e),...this.flush()]}*_getGenerator(){if(this._inputMimeType.match(/aac/))this._parser=new On(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/mpeg/))this._parser=new Bn(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/flac/))this._parser=new jt(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/ogg/))this._parser=new Vn(this,this._headerCache,this._onCodec);else throw new Error(`Unsupported Codec ${mimeType}`);for(this._frameNumber=0,this._currentReadPosition=0,this._totalBytesIn=0,this._totalBytesOut=0,this._totalSamples=0,this._sampleRate=void 0,this._rawData=new Uint8Array(0);;){let e=yield*this._parser[Ze]();e&&(yield e)}}*[W](e=0,r=0){let n;for(;this._rawData[M]<=e+r;){if(n=yield,this._flushing)return this._rawData[k](r);n&&(this._totalBytesIn+=n[M],this._rawData=Cn(this._rawData,n))}return this._rawData[k](r)}[Be](e){this._currentReadPosition+=e,this._rawData=this._rawData[k](e)}[En](e){this._sampleRate=e[Le][V],e[Le][he]=e[$e]>0?Math.round(e[$][M]/e[$e])*8:0,e[dt]=this._frameNumber++,e[Gt]=this._totalBytesOut,e[Xt]=this._totalSamples,e[Wt]=this._totalSamples/this._sampleRate*1e3,e[cn]=this._crc32(e[$]),this._headerCache[ki](e[Le][he],e[Wt]),this._totalBytesOut+=e[$][M],this._totalSamples+=e[G]}[Lt](e){if(e[pe]){if(e[Ee]){let r=e[G];e[pe].forEach(n=>{let i=n[G];r<i&&(n[G]=r>0?r:0,n[$e]=n[G]/n[Le][V]*1e3),r-=i,this[En](n)})}else e[G]=0,e[pe].forEach(r=>{e[G]+=r[G],this[En](r)});e[$e]=e[G]/this._sampleRate*1e3||0,e[Xt]=this._totalSamples,e[Wt]=this._totalSamples/this._sampleRate*1e3||0,e[Gt]=this._totalBytesOut}else this[En](e)}_log(e,r){if(this._enableLogging){let n=[`${Q}: ${this[Q]}`,`inputMimeType: ${this._inputMimeType}`,`readPosition: ${this._currentReadPosition}`,`totalBytesIn: ${this._totalBytesIn}`,`${Gt}: ${this._totalBytesOut}`],i=Math.max(...n.map(o=>o[M]));r.push(`--stats--${"-".repeat(i-9)}`,...n,"-".repeat(i)),e("codec-parser",r.reduce((o,s)=>o+`
4
+ `+s,""))}}[Ge](...e){this._log(console.warn,e)}[Ni](...e){this._log(console.error,e)}};var Sc=Gn;var Zi=pe;var eo=$;var Mc=Le;var _c=Ee;var Ac=Lr;var wc=Xt;function ut(t){var e=e;function r(){}e={};function n(P){throw P}var i,o,s,a,c,l,d,u,f,m,p;function y(){var P=p.buffer;i=new Int8Array(P),o=new Int16Array(P),a=new Uint8Array(P),c=new Uint16Array(P),s=new Int32Array(P),l=new Uint32Array(P),d=new Float32Array(P),u=new Float64Array(P),f=new BigInt64Array(P),m=new BigUint64Array(P)}for(var h=P=>{for(var ze,Gr,ir=0,si=0,ai=P.length,ci=new Uint8Array((ai*3>>2)-(P[ai-2]=="=")-(P[ai-1]=="="));ir<ai;ir+=4,si+=3)ze=J[P.charCodeAt(ir+1)],Gr=J[P.charCodeAt(ir+2)],ci[si]=J[P.charCodeAt(ir)]<<2|ze>>4,ci[si+1]=ze<<4|Gr>>2,ci[si+2]=Gr<<6|J[P.charCodeAt(ir+3)];return ci},g=()=>n(""),S=()=>{},x={},v=P=>P(),b=()=>performance.now(),_=(P,ze)=>{if(x[P]&&(clearTimeout(x[P].id),delete x[P]),!ze)return 0;var Gr=setTimeout(()=>{delete x[P],v(()=>pa(P,b()))},ze);return x[P]={id:Gr,timeout_ms:ze},0},A=Math.atan,w=Math.cos,E=Math.exp,L=Math.log,B=Math.pow,O=Math.sin,U=P=>{var ze=a.length;return P>>>=0,!1},C=P=>{throw`exit(${P})`},J=new Uint8Array(123),Me=25;Me>=0;--Me)J[48+Me]=52+Me,J[65+Me]=Me,J[97+Me]=26+Me;J[43]=62,J[47]=63;var Bt={e:g,d:S,f:_,b:A,a:w,i:E,h:L,g:B,c:O,k:U,j:C};function oi(P){Vr=P.n,la=P.o,da=P.p,ua=P.q,fa=P.r,ma=P.s,ha=P.t,pa=P.v}var Vr,la,da,ua,fa,ma,ha,pa;function xl(P){P.m()}ut.wasm||Object.defineProperty(ut,"wasm",{get:()=>String.raw`dynEncode012091253f87dì%nä= 4&¿nÝØä‘ÂLÚªã9ÚØ[äº\ ¼¡³R=}L]ŸÈÿ2 ÿù¶J1jj¡é,zäV|i¸Qk¹‡= 
5
5
  ¨¨Ÿ%‰€ýv²†±»ŸoúâLa:ê±ÊäÌÓ.÷؇ý×>àW>z¯°8¯ñ€\Ñós 9ˆ\§ôÊ@Ü (tÂø4° ¢7fqÓg²Jè6x[zç®&4=} p.(°tÍޖ™ã¾>÷CõË"*k?¿~ 7‚~H2ÛÜâ.ÏQä;Œ6{ÜãFÑá'DœD¤±°HQ>MínÎϕÎöʵ’Ñӓ…™Þ“‰Ž‘š†Š‚œÌP¼P¨Þˆ*X²E=M¦qíxMà ±=M̚ë4/<šgNO‰™/¢ ¢>ˆa~Ï®”ììììì0”ìœa笡çëOÓÇM Q9tùµyuéµµÞϒ/Ÿ±Óõò}E{òÓJ¹Û|· ôfÒ c’¬”Wêaûÿlʽp¹|)‘ÖEL–†¦ }‰ypÕSϹI†]¢ˆºãæ°ÿo¶7ÛRqš¾ÔÅEߨ‘]æˉwÚ{óç‰Vwó1¾”E­Øpˆàe"Æùû–¡Áª ‡ Ààð´Lõ›€ÎxEÓ¢N¦‘…9Ÿëùši&€ Ò§Ø!ÇFçS=MbäO?ß·™縪‡7ùa}5ðšûÕtsUŒþ£Kïg‡ˆN™¾)ø§\V0uSIö:ÌU4ж¯´Õn9ÔƒèE£ZƼ{hµmى¾6ÆžÑ+xñ´«„þ¸=M‚ߤ·å®«ïÆGFÝì|H?äE"þ!9«Æïpæ'][¯ù·£W÷O§&#aŸ‡x$qf=}ø ô bϗŸ×W÷LôožÝWQÕӎ)u †÷½èV|¥Gà¨Ö¸˜@Œê| ÇK5ò €A·Â9’CS2š¸‹¼¿,ä›Ý ÑÝy™!ÑR„%ÆÝÎ0Âv§ qTcó±hØÉã‰=}Z=}Ælü­ën¯ð(-°ÜwVχï.th¥í­‡S~SÏ»Z”ZÔZ
6
6
  3–BÌÛ¬•<éæO)ÎyÚ¯O*®uìÛ$öI¥Ý9ôø³\¤ò³Ù¹ÇP¸J׎y@ÔyOÇm—’ô½üœš¾|S?2àú¤F?½ûoo3ôž;<àáûܘ8‚ì²7ïë¨RäY¹|ÓºÌF,ƒÐ™-¸*\P!FJÒ8= o6HwLrúº”¶Ð۞\Ù¬o¢–9Iq„Ý.ôf¶Îȏ{Ī×N|Mfs…•¤ „ÉݖàŸâ§‘*+ã§­’ô¯î¬7ç×§ä)€Š!Z¨ƒÉž,Äp~ý·wsSGó—äs„E€\ýï鞧Ö:Ò'“Cç(_X$\¦½eҒ8$’X˜F|e‚•œíٙә‚†¡¤Û<ØÞÛ¸9‰¿ðÃÎ#b~× ‚4éîÿÏq
7
7
  ˜ód‡|0•wU‰—&®è·vh6¨—{Ú珁Ú18ә(ÓY‚\ƒ0¦= çˆèíß)Ø=} ˜[xü-v˜?N(Kk‘gš0}âډ´ð“†¬”œÕQNÍ¢usѳ=}. ëg…û= Í M—Bp'²¨ œx’4è@9t“§eݵ¾âð½ z?†‹Z¹FH'‰Ì¯¿<ŒK,üµ<{˜ ¶JãývåàÆeù0Ð"F¥ÃÒÞŽþԛÉvC›zl}„ðN’£ Í^ƒP%²¸FX»WÎêô¶…ŠäÉJ^gƒ×SÃã.žÄt*'ªG‘«ÒB<ÜӅ¿ºp­\àuV¯£›Åݑ½á–Þ ùߞ=}ÎÚ^‹Ÿÿí>¥!¨ â=M·? */¤"å)â·ÿîÿî*(%*›2[½"üríÔ4š’l½»a}¯CwpCÓèìGc-ã6®=M32†k?Êg­…–!So-™x›>³G+ã@ò,™ Áïƒá„åN0þŠÙ‚è.~È÷¡vTr¶‰­‚Æ[üB±º»ávëw¹{pÜºû"Aæ’±9Æ^¹³òïRIAy5GÂwÉfœ4@Tù|qý7†ðªwBL|ÔqŽ‘v!ª°|]KiÐJVQ5‰¸åõ§‡‡åŒ"H¼0e¬<óBîÚS€ÏUìHPÙA+çÉ'se†ÌNf°@ÈM,ð½egÖ¬x©“„‹û½2~«ŠÒ1;ֈ«…¯°4&90èE»Ó׺ç‚ʧJ<Æ¿&~Nu¼ãÙµ¢.UÇä(qQô^ö–·“%!É
@@ -138,7 +138,7 @@ KÙ:KµºKí{K]ûK£[KÚKóšKÓ½R׿ÿ'P^j9TîçmóœþL¿_o©×hÙtÙ
138
138
  ÁiŸ;ª•äÀž‡%Ёn= =M+W= ÓÖc[aS
139
139
  FÁð]Nô‡Ý'= “qr(¶ù¤nŒü«òÿ¿d&ÿ ÈõT4Þ=}z|ö ¿OW×SMtdH.τãRX&§o3ؘÜXÍ^œÊM–í£W´iâ]NüOå£S£Å·ƒç÷­˜Ý§½GÑU y¹¦ß§/6P0(Cúýb"þ¥°VٌÄᣈ’ÓÙ@¾YýòDŽŒ{òÃv?’EP©”=MBé­\ĽYäýRò øfâëEEf¼D+gC×úDZGÅÿ±Ç?TzÙ¡±†Ï€ÁÕ¯¦ð‰vZ’mT}Œ3x˘z×cºrÑM=M„ c-ɩԈ™7½wæc§Î»cû¾yf‡ÙWòŒÆÝÔc¥³ôØfƒ«Äñ·9‰ø%­g:y”^+{U]¤þ‚…[&fӁÏY낫‡Gªõ‡¹¦ÖŒðþ¬m„oÛø‘?/ÛS’.[S›9ÛùœC›…/û2”²Y£ÎÑ%/sy¢×ÌùJ­W6Oí\g0^JùêßÏ0í[Ü“'ÏÔ>žÀ-¿[ÔW?Y]±ž ØÙÃî<~ÎëR~Ìf¾Z—/×¼_á¾Þê+îoÐñ{Þ\e3K%©¹§íB¹§(c=}ËÈ·SzÔnf§èx}o\9öf|%Ýå¥~©‚Iǀ ü€ñY8}FfŸú@Rú1éþ3‚÷˂‹ótQøvœû|³Îaá,Óé>BG6Òê}—ÄJ|¶=}°Žˆöf6žõk¶ÌºHgN’j‡Ò{柾M;9·é—§WèO±›Ä3қËÒyt™ ;ù´ˆà©aš|—Ó^!ÝøûšÄ
140
140
  (VV¸ ÇÙcÏ>yoçz ÃvòG{3Þ£½šŠcמôŒ íŚé;°OÛ‰GØ<wÜW> rU]Žq­{û'ùÝír{*øï?t-ígùWÿ…&§] m}×ût¥‚Ë~ß&>&Õv!b#ÅÌ‚q¢µ|jŽÍüùÉ^Æ&™ôžþŸ~sIµ"“]d)uâ´‘ºvk Å\<͉ÿ­öꍽƒÂ
141
- ïBçϧmÙIólÜoëVbƒ¦¯éWÇû3`});var bl={a:Bt};this.setModule=I=>{t.setModule(ut,I)},this.getModule=()=>t.getModule(ut),this.instantiate=()=>(this.getModule().then(I=>WebAssembly.instantiate(I,bl)).then(I=>{let ze=I.exports;oi(ze),p=ze.l,y(),xl(ze),r()}),this.ready=new Promise(I=>{r=I}).then(()=>{this.HEAP=p.buffer,this.malloc=la,this.free=ha,this.create_decoder=Vr,this.send_setup=da,this.init_dsp=ua,this.decode_packets=fa,this.destroy_decoder=ma}),this)}function Jt(){return this._init=()=>new this._WASMAudioDecoderCommon().instantiate(this._EmscriptenWASM,this._module).then(t=>{this._common=t,this._input=this._common.allocateTypedArray(this._inputSize,Uint8Array),this._firstPage=!0,this._inputLen=this._common.allocateTypedArray(1,Uint32Array),this._outputBufferPtr=this._common.allocateTypedArray(1,Uint32Array),this._channels=this._common.allocateTypedArray(1,Uint32Array),this._sampleRate=this._common.allocateTypedArray(1,Uint32Array),this._samplesDecoded=this._common.allocateTypedArray(1,Uint32Array);let e=256;this._errors=this._common.allocateTypedArray(e,Uint32Array),this._errorsLength=this._common.allocateTypedArray(1,Int32Array),this._frameNumber=0,this._inputBytes=0,this._outputSamples=0,this._decoder=this._common.wasm.create_decoder(this._input.ptr,this._inputLen.ptr,this._outputBufferPtr.ptr,this._channels.ptr,this._sampleRate.ptr,this._samplesDecoded.ptr,this._errors.ptr,this._errorsLength.ptr,e)}),Object.defineProperty(this,"ready",{enumerable:!0,get:()=>this._ready}),this.reset=()=>(this.free(),this._init()),this.free=()=>{this._common.wasm.destroy_decoder(this._decoder),this._common.free()},this.sendSetupHeader=t=>{this._input.buf.set(t),this._inputLen.buf[0]=t.length,this._common.wasm.send_setup(this._decoder,this._firstPage),this._firstPage=!1},this.initDsp=()=>{this._common.wasm.init_dsp(this._decoder)},this.decodePackets=t=>{let e=[],r=0,n=[];for(let i=0;i<t.length;i++){let o=t[i];this._input.buf.set(o),this._inputLen.buf[0]=o.length,this._common.wasm.decode_packets(this._decoder);let s=this._samplesDecoded.buf[0],a=[],c=new Uint32Array(this._common.wasm.HEAP,this._outputBufferPtr.buf[0],this._channels.buf[0]);for(let l=0;l<this._channels.buf[0];l++){let d=new Float32Array(s);s&&d.set(new Float32Array(this._common.wasm.HEAP,c[l],s)),a.push(d)}e.push(a),r+=s,this._frameNumber++,this._inputBytes+=o.length,this._outputSamples+=s;for(let l=0;l<this._errorsLength.buf;l+=2){let d=this._common.codeToString(this._errors.buf[l]),u=this._common.codeToString(this._errors.buf[l+1]);n.push({message:d+" vorbis_synthesis"+u,frameLength:o.length,frameNumber:this._frameNumber,inputBytes:this._inputBytes,outputSamples:this._outputSamples})}this._errorsLength.buf[0]=0}return this._WASMAudioDecoderCommon.getDecodedAudioMultiChannel(n,e,this._channels.buf[0],r,this._sampleRate.buf[0],16)},this._isWebWorker=Jt.isWebWorker,this._WASMAudioDecoderCommon=Jt.WASMAudioDecoderCommon||Z,this._EmscriptenWASM=Jt.EmscriptenWASM||ut,this._module=Jt.module,this._inputSize=128*1024,this._ready=this._init(),this}var to=Symbol(),ft=class{constructor(){this._onCodec=e=>{if(e!=="vorbis")throw new Error("@wasm-audio-decoders/ogg-vorbis does not support this codec "+e)},new Z,this._init(),this._ready=this[to](Jt)}_init(){this._vorbisSetupInProgress=!0,this._totalSamplesDecoded=0,this._codecParser=new Sc("audio/ogg",{onCodec:this._onCodec,enableFrameCRC32:!1})}async[to](e){if(this._decoder){let r=this._decoder;await r.ready.then(()=>r.free())}return this._decoder=new e,this._decoder.ready}get ready(){return this._ready}async reset(){return this._init(),this._decoder.reset()}free(){this._decoder.free()}async decodeOggPages(e){let r=[];for(let o=0;o<e.length;o++){let s=e[o];if(this._vorbisSetupInProgress&&(s[eo][0]===1&&this._decoder.sendSetupHeader(s[eo]),s[Zi].length)){let a=s[Zi][0][Mc];this._decoder.sendSetupHeader(a[Ac]),this._decoder.initDsp(),this._vorbisSetupInProgress=!1}r.push(...s[Zi].map(a=>a[eo]))}let n=await this._decoder.decodePackets(r);this._totalSamplesDecoded+=n.samplesDecoded;let i=e[e.length-1];if(i&&i[_c]){let o=this._totalSamplesDecoded-i[wc];if(o>0){for(let s=0;s<n.channelData.length;s++)n.channelData[s]=n.channelData[s].subarray(0,n.samplesDecoded-o);n.samplesDecoded-=o,this._totalSamplesDecoded-=o}}return n}async decode(e){return this.decodeOggPages([...this._codecParser.parseChunk(e)])}async flush(){let e=await this.decodeOggPages([...this._codecParser.flush()]);return await this.reset(),e}async decodeFile(e){let r=await this.decodeOggPages([...this._codecParser.parseAll(e)]);return await this.reset(),r}};var Rs=class extends gr{constructor(e){super(e,"ogg-vorbis-decoder",Jt,ut)}async sendSetupHeader(e){return this.postToDecoder("sendSetupHeader",e)}async initDsp(){return this.postToDecoder("initDsp")}async decodePackets(e){return this.postToDecoder("decodePackets",e)}},Wn=class extends ft{constructor(){super(),this._ready=super[to](Rs)}async free(){await this._decoder.free()}terminate(){this._decoder.terminate()}};Li(ft,"OggVorbisDecoder");Li(Wn,"OggVorbisDecoderWebWorker");var Ts=class extends Error{constructor(e){super(e),this.name="OggDecodeError"}};async function ro(t,e=new ft){await e.ready;let r=await e.decode(new Uint8Array(t)),n=r.errors;if(n&&n.length>0)throw new Ts(n.map(i=>i.message).join("; "));return{sampleRate:r.sampleRate,channels:r.channelData.length,bitDepth:r.bitDepth,channelData:r.channelData}}var Xn=class extends Error{constructor(e){super(e),this.name="AudioRegistryError"}},Fr=class{constructor(e,r={}){this.vfs=e;this.refCounts=new Map;this.cache=new pt(r.cacheSize??64)}get size(){return this.cache.size}async load(e){let r=e.toLowerCase(),n=this.cache.get(r);if(n)return this.refCounts.set(r,(this.refCounts.get(r)??0)+1),n;let o=(await this.vfs.readFile(e)).slice().buffer,s=await this.decodeByExtension(e,o);return this.cache.set(r,s),this.refCounts.set(r,1),s}release(e){let r=e.toLowerCase(),n=this.refCounts.get(r)??0;n<=1?(this.cache.delete(r),this.refCounts.delete(r)):this.refCounts.set(r,n-1)}clearAll(){this.cache.clear(),this.refCounts.clear()}async decodeByExtension(e,r){let n=e.toLowerCase();if(n.endsWith(".wav")){let i=wi(r),o=i.channels,s=Array.from({length:o},()=>new Float32Array(i.samples.length/o));for(let a=0;a<i.samples.length;a+=1)s[a%o][Math.floor(a/o)]=i.samples[a];return{sampleRate:i.sampleRate,channels:o,bitDepth:i.bitsPerSample,channelData:s}}if(n.endsWith(".ogg")||n.endsWith(".oga"))return ro(r);throw new Xn(`Unsupported audio format: ${e}`)}};var T0="quake2ts-pak-indexes",F0="pak-indexes";function Lc(){if(typeof indexedDB<"u")return indexedDB;if(typeof window<"u"&&"indexedDB"in window)return window.indexedDB;if(typeof globalThis<"u"&&"indexedDB"in globalThis)return globalThis.indexedDB}function Kn(t,e){let r=Lc();return r?new Promise((n,i)=>{let o=r.open(t,1);o.onupgradeneeded=()=>{let{result:s}=o;s.objectStoreNames.contains(e)||s.createObjectStore(e,{keyPath:"key"})},o.onerror=()=>i(o.error??new Error("Unknown IndexedDB error")),o.onsuccess=()=>n(o.result)}):Promise.reject(new Error("IndexedDB is not available in this environment"))}function Yn(t,e,r,n){return new Promise((i,o)=>{let a=t.transaction(e,r).objectStore(e),c=n(a);c.onsuccess=()=>i(c.result),c.onerror=()=>o(c.error??new Error("IndexedDB transaction error"))})}function Fs(t,e){return`${ie(t)}:${e.toString(16)}`}function B0(t){return t.map(e=>({...e}))}var no=class{constructor(e=T0,r=F0){this.dbName=e;this.storeName=r}get isSupported(){return!!Lc()}async persist(e){if(!this.isSupported)return;let r=e.validate(),n={...r,key:Fs(e.name,r.checksum),name:e.name,size:e.size,persistedAt:Date.now(),entries:B0(r.entries)},i=await Kn(this.dbName,this.storeName);return await Yn(i,this.storeName,"readwrite",o=>o.put(n)),i.close(),n}async find(e,r){if(!this.isSupported)return;let n=await Kn(this.dbName,this.storeName),i=r!==void 0?Fs(e,r):void 0,o=await Yn(n,this.storeName,"readonly",s=>i?s.get(i):s.getAll());if(n.close(),!!o){if(Array.isArray(o)){let s=ie(e),a=o.filter(c=>ie(c.name)===s);return a.length===0?void 0:a.sort((c,l)=>l.persistedAt-c.persistedAt)[0]}return o}}async remove(e,r){if(!this.isSupported)return!1;let n=await Kn(this.dbName,this.storeName),i=r!==void 0?Fs(e,r):void 0,o=await Yn(n,this.storeName,"readwrite",s=>{if(i)return s.delete(i);let a=`${ie(e)}:`;return s.delete(IDBKeyRange.bound(a,`${a}\uFFFF`,!1,!0))});return n.close(),typeof o=="number"?o>0:!0}async clear(){if(!this.isSupported)return;let e=await Kn(this.dbName,this.storeName);await Yn(e,this.storeName,"readwrite",r=>r.clear()),e.close()}async list(){if(!this.isSupported)return[];let e=await Kn(this.dbName,this.storeName),r=await Yn(e,this.storeName,"readonly",n=>n.getAll());return e.close(),r.sort((n,i)=>i.persistedAt-n.persistedAt)}};var Zt=class extends Error{constructor(r,n){super(n??`Missing dependencies: ${r.join(", ")}`);this.missing=r;this.name="AssetDependencyError"}},qn=class{constructor(){this.nodes=new Map}register(e,r=[]){let n=this.nodes.get(e)??{dependencies:new Set,loaded:!1};r.forEach(i=>n.dependencies.add(i)),this.nodes.set(e,n),r.forEach(i=>{this.nodes.has(i)||this.nodes.set(i,{dependencies:new Set,loaded:!1})})}markLoaded(e){let r=this.nodes.get(e)??{dependencies:new Set,loaded:!1},n=this.getMissingDependencies(e,r);if(n.length>0)throw new Zt(n,`Asset ${e} is missing dependencies: ${n.join(", ")}`);r.loaded=!0,this.nodes.set(e,r)}markUnloaded(e){let r=this.nodes.get(e);r&&(r.loaded=!1)}isLoaded(e){return this.nodes.get(e)?.loaded??!1}missingDependencies(e){let r=this.nodes.get(e);return r?this.getMissingDependencies(e,r):[]}reset(){this.nodes.clear()}getMissingDependencies(e,r){let n=[];for(let i of r.dependencies)this.nodes.get(i)?.loaded||n.push(i);return n}},io=class{constructor(e,r={}){this.vfs=e;this.maps=new Map;this.textures=new yr({capacity:r.textureCacheCapacity??128}),this.audio=new Fr(e,{cacheSize:r.audioCacheSize??64}),this.dependencyTracker=r.dependencyTracker??new qn,this.md2=new mr(e),this.md3=new hr(e),this.sprite=new pr(e),this.bsp=new fr(e),this.palette=new Uint8Array(768);for(let n=0;n<256;n++)this.palette[n*3]=n,this.palette[n*3+1]=n,this.palette[n*3+2]=n}async loadPalette(e="pics/colormap.pcx"){try{let r=await this.vfs.readFile(e),n=Jr(r);n.palette&&(this.palette=n.palette)}catch(r){console.warn(`Failed to load palette from ${e}:`,r)}}isAssetLoaded(e,r){return this.dependencyTracker.isLoaded(this.makeKey(e,r))}registerTexture(e,r){this.textures.set(e,r);let n=this.makeKey("texture",e);this.dependencyTracker.register(n),this.dependencyTracker.markLoaded(n)}async loadTexture(e){let r=this.textures.get(e);if(r)return r;let n=await this.vfs.readFile(e),i=e.split(".").pop()?.toLowerCase(),o;if(i==="wal")o=Ai(n,this.palette);else if(i==="pcx")o=_i(Jr(n));else if(i==="tga")o=ja(fs(n));else throw new Error(`Unsupported texture format for loadTexture: ${i}`);return this.registerTexture(e,o),o}async loadSound(e){let r=await this.audio.load(e),n=this.makeKey("sound",e);return this.dependencyTracker.register(n),this.dependencyTracker.markLoaded(n),r}async loadMd2Model(e,r=[]){let n=this.makeKey("model",e),i=r.map(a=>this.makeKey("texture",a));this.dependencyTracker.register(n,i);let o=this.dependencyTracker.missingDependencies(n);if(o.length>0)throw new Zt(o,`Asset ${n} is missing dependencies: ${o.join(", ")}`);let s=await this.md2.load(e);return this.dependencyTracker.markLoaded(n),s}getMd2Model(e){return this.md2.get(e)}async loadMd3Model(e,r=[]){let n=this.makeKey("model",e),i=r.map(a=>this.makeKey("texture",a));this.dependencyTracker.register(n,i);let o=this.dependencyTracker.missingDependencies(n);if(o.length>0)throw new Zt(o,`Asset ${n} is missing dependencies: ${o.join(", ")}`);let s=await this.md3.load(e);return this.dependencyTracker.markLoaded(n),s}getMd3Model(e){return this.md3.get(e)}async loadSprite(e){let r=this.makeKey("sprite",e);this.dependencyTracker.register(r);let n=await this.sprite.load(e);return this.dependencyTracker.markLoaded(r),n}async loadMap(e){let r=this.makeKey("map",e);if(this.maps.has(e))return this.maps.get(e);this.dependencyTracker.register(r);let n=await this.bsp.load(e);return this.maps.set(e,n),this.dependencyTracker.markLoaded(r),n}getMap(e){return this.maps.get(e)}listFiles(e){return this.vfs.findByExtension(e)}resetForLevelChange(){this.textures.clear(),this.audio.clearAll(),this.dependencyTracker.reset(),this.maps.clear()}makeKey(e,r){return`${e}:${ie(r)}`}};var Bs=32,oo=(u=>(u[u.Auto=0]="Auto",u[u.Weapon=1]="Weapon",u[u.Voice=2]="Voice",u[u.Item=3]="Item",u[u.Body=4]="Body",u[u.Aux=5]="Aux",u[u.Footstep=6]="Footstep",u[u.Aux3=7]="Aux3",u[u.NoPhsAdd=8]="NoPhsAdd",u[u.Reliable=16]="Reliable",u[u.ForcePos=32]="ForcePos",u))(oo||{}),Ec=-1,so=0,Ic=1,Pc=2,Cc=3,Br=80,zc=.003;function er(t){return t===3?t*.001:t*5e-4}function ao(t){let e=er(t);return e<=0?Number.POSITIVE_INFINITY:80+1/e}var co=class{constructor(e){this.factory=e}getContext(){return this.context||(this.context=this.factory()),this.context}async resume(){let e=this.getContext();e.state==="suspended"&&await e.resume()}getState(){return this.context?.state??"suspended"}};function lo(t){let e=t.getContext(),r=e.createGain();r.gain.value=1;let n=e.createDynamicsCompressor(),i=e.createBiquadFilter?.();return i?(i.type="lowpass",i.frequency.value=2e4,i.Q.value=.707,r.connect(i),i.connect(n)):r.connect(n),n.connect(e.destination),{context:e,master:r,compressor:n,filter:i}}var uo=class{constructor(e=new lr){this.configStrings=e;this.buffers=new Map}registerName(e){return this.configStrings.soundIndex(e)}register(e,r){let n=this.registerName(e);return this.buffers.set(n,r),n}find(e){return this.configStrings.findSoundIndex(e)}get(e){return this.buffers.get(e)}has(e){return this.buffers.has(e)}getName(e){return this.configStrings.getName(e)}};var fo=class{constructor(e){this.vfs=e.vfs,this.registry=e.registry,this.contextController=e.context,this.soundRoot=e.soundRoot??"sound/",this.decodeAudio=e.decodeAudio??((r,n)=>{if(!r.decodeAudioData)throw new Error("decodeAudioData is not available on the provided audio context");return r.decodeAudioData(n)})}async precache(e){let r=[...new Set(e.map(o=>this.normalize(o)))],n={loaded:[],skipped:[],missing:[],errors:{}},i=this.contextController.getContext();for(let o of r)try{let s=this.registry.find(o);if(s!==void 0&&this.registry.has(s)){n.skipped.push(o);continue}if(!this.vfs.stat(o)){n.missing.push(o);continue}let l=(await this.vfs.readFile(o)).slice().buffer,d=await this.decodeAudio(i,l);this.registry.register(o,d),n.loaded.push(o)}catch(s){let a=s instanceof Error?s:new Error(String(s));n.errors[o]=a}return n}normalize(e){let r=ie(e.replace(/^\//,""));return r.startsWith(this.soundRoot)?r:ie(`${this.soundRoot}${r}`)}};var D0=7,$n=t=>t&D0;function mo(t){return Array.from({length:32},()=>({entnum:0,entchannel:0,endTimeMs:0,isPlayer:!1,active:!1})).map(e=>({...e,isPlayer:e.entnum===t}))}function ho(t,e,r,n){if(r<0)throw new Error("pickChannel: entchannel must be non-negative");let i=$n(r),o=-1,s=Number.POSITIVE_INFINITY;for(let a=0;a<t.length;a+=1){let c=t[a],l=$n(c.entchannel);if(i!==0&&c.entnum===e&&l===i){o=a;break}if(c.active&&c.entnum===n.playerEntity&&e!==n.playerEntity)continue;let d=c.endTimeMs-n.nowMs;(o===-1||d<s)&&(s=d,o=a)}return o===-1?void 0:o}function po(t,e,r,n,i){if(i)return{left:r,right:r,distanceComponent:0};let o=ba(t,e.origin),s=Qo(o),a=He(o),c=s-80;c<0&&(c=0),c*=er(n);let l=jo(e.right,a),d=e.mono??!1,u=d||n===0?1:.5*(1+l),f=d||n===0?1:.5*(1-l),m=Math.max(0,Math.floor(r*(1-c)*u));return{left:Math.max(0,Math.floor(r*(1-c)*f)),right:m,distanceComponent:c}}var yo=class{constructor(e){this.activeSources=new Map;this.contextController=e.context,this.registry=e.registry,this.playerEntity=e.playerEntity,this.channels=mo(e.playerEntity),this.listener=e.listener??{origin:xa,right:{x:1,y:0,z:0}},this.sfxVolume=e.sfxVolume??1,this.masterVolume=e.masterVolume??1,this.resolveOcclusion=e.resolveOcclusion,this.graph=lo(this.contextController),this.graph.master.gain.value=this.masterVolume}setListener(e){this.listener=e}setMasterVolume(e){this.masterVolume=e,this.graph.master.gain.value=e}setSfxVolume(e){this.sfxVolume=e}async ensureRunning(){await this.contextController.resume()}play(e){let r=this.registry.get(e.soundIndex);if(!r)return;let n=this.graph.context,i=n.currentTime*1e3,o=ho(this.channels,e.entity,e.channel,{nowMs:i,playerEntity:this.playerEntity});if(o===void 0)return;let s=this.activeSources.get(o);s&&(s.source.onended=null,s.source.stop(),this.activeSources.delete(o));let a=n.createBufferSource();a.buffer=r,a.loop=e.looping??!1;let c=e.origin??this.listener.origin,l=n.createGain(),d=this.createPanner(n,e.attenuation),u=this.resolveOcclusion?.(this.listener,c,e.attenuation),f=Rc(u?.gainScale??1),m=this.resolveOcclusion?this.createOcclusionFilter(n,u?.lowpassHz??2e4):void 0;this.applyOriginToPanner(d,c);let p=e.entity===this.playerEntity,y=po(c,this.listener,e.volume,e.attenuation,p),g=(e.volume===0?0:Math.max(y.left,y.right)/Math.max(1,e.volume))*(e.volume/255)*this.masterVolume*this.sfxVolume;l.gain.value=g*f;let M=n.currentTime+(e.timeOffsetMs??0)/1e3,x=(e.looping?Number.POSITIVE_INFINITY:r.duration*1e3)+M*1e3;a.connect(d),m?(d.connect(m),m.connect(l)):d.connect(l),l.connect(this.graph.master),a.start(M),a.onended=()=>{this.channels[o].active=!1,this.activeSources.delete(o)};let v={channelIndex:o,entnum:e.entity,entchannel:$n(e.channel),endTimeMs:x,source:a,panner:d,gain:l,baseGain:g,origin:c,attenuation:e.attenuation,occlusion:m?{scale:f,lowpassHz:u?.lowpassHz,filter:m}:u?{scale:f,lowpassHz:u.lowpassHz}:void 0};return this.channels[o]={entnum:e.entity,entchannel:$n(e.channel),endTimeMs:x,isPlayer:e.entity===this.playerEntity,active:!0},this.activeSources.set(o,v),v}stop(e){let r=this.activeSources.get(e);r&&(r.source.stop(),this.channels[e].active=!1,this.activeSources.delete(e))}stopEntitySounds(e){for(let[r,n]of[...this.activeSources.entries()])n.entnum===e&&(n.source.stop(),this.channels[r].active=!1,this.activeSources.delete(r))}updateEntityPosition(e,r){for(let n of this.activeSources.values())if(n.entnum===e&&(this.applyOriginToPanner(n.panner,r),n.origin=r,this.resolveOcclusion)){let i=this.resolveOcclusion(this.listener,r,n.attenuation);this.applyOcclusion(n,i)}}positionedSound(e,r,n,i){return this.play({entity:0,channel:0,soundIndex:r,volume:n,attenuation:i,origin:e})}ambientSound(e,r,n){return this.play({entity:0,channel:0,soundIndex:r,volume:n,attenuation:0,origin:e,looping:!0})}getChannelState(e){return this.channels[e]}getDiagnostics(){return{activeChannels:this.activeSources.size,masterVolume:this.masterVolume,sfxVolume:this.sfxVolume,channels:[...this.channels],activeSounds:[...this.activeSources.values()].map(e=>({entnum:e.entnum,entchannel:e.entchannel,channelIndex:e.channelIndex,origin:e.origin,gain:e.gain.gain.value,baseGain:e.baseGain,attenuation:e.attenuation,maxDistance:e.panner.maxDistance,distanceModel:e.panner.distanceModel,occlusion:e.occlusion?{scale:e.occlusion.scale,lowpassHz:e.occlusion.lowpassHz}:void 0}))}}setUnderwater(e,r=400){let n=this.graph.filter;n&&(n.type="lowpass",n.Q.value=.707,n.frequency.value=e?r:2e4)}createPanner(e,r){let n=e.createPanner?e.createPanner():Object.assign(e.createGain(),{positionX:{value:this.listener.origin.x},positionY:{value:this.listener.origin.y},positionZ:{value:this.listener.origin.z}});return this.configurePanner(n,r)}configurePanner(e,r){let n=er(r);return e.refDistance=80,e.maxDistance=ao(r),e.rolloffFactor=n,e.distanceModel=r===0?"linear":"inverse",e.positionX.value=this.listener.origin.x,e.positionY.value=this.listener.origin.y,e.positionZ.value=this.listener.origin.z,e}applyOriginToPanner(e,r){e.positionX.value=r.x,e.positionY.value=r.y,e.positionZ.value=r.z}createOcclusionFilter(e,r){if(!e.createBiquadFilter)return;let n=e.createBiquadFilter();return n.type="lowpass",n.Q.value=.707,n.frequency.value=Ds(r,10,2e4),n}applyOcclusion(e,r){let n=Rc(r?.gainScale??1);if(e.gain.gain.value=e.baseGain*n,e.occlusion?.filter){let i=r?.lowpassHz??2e4;e.occlusion.filter.frequency.value=Ds(i,10,2e4)}e.occlusion?(e.occlusion.scale=n,e.occlusion.lowpassHz=r?.lowpassHz):r&&(e.occlusion={scale:n,lowpassHz:r.lowpassHz})}},Ds=(t,e,r)=>Math.min(r,Math.max(e,t)),Rc=t=>Ds(t,0,1);var go=class{constructor(e){this.createElement=e.createElement,this.resolveSource=e.resolveSource??(async r=>r),this.volume=e.volume??1}async play(e,{loop:r=!0,restart:n=!1}={}){if(this.track===e&&this.element){this.element.loop=r,this.element.volume=this.volume,n&&(this.element.currentTime=0),(this.element.paused||n)&&await this.element.play();return}let i=await this.resolveSource(e),o=this.createElement();o.src=i,o.loop=r,o.volume=this.volume,o.currentTime=0,o.load(),await o.play(),this.element=o,this.track=e}pause(){!this.element||this.element.paused||this.element.pause()}async resume(){!this.element||!this.element.paused||await this.element.play()}stop(){this.element&&(this.element.pause(),this.element.currentTime=0,this.element=void 0,this.track=void 0)}setVolume(e){this.volume=e,this.element&&(this.element.volume=e)}getState(){let e=!!(this.element&&!this.element.paused&&!this.element.ended),r=!!this.element?.paused;return{track:this.track,paused:r,playing:e,volume:this.volume}}};function O0(t){t.enable(t.DEPTH_TEST),t.depthFunc(t.LEQUAL),t.enable(t.CULL_FACE),t.cullFace(t.BACK),t.enable(t.BLEND),t.blendFuncSeparate(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA)}function N0(t,e,r,n){for(let i of e){let o=t.getExtension(i);if(!o)throw new Error(`Missing required WebGL extension: ${i}`);n.set(i,o)}for(let i of r){let o=t.getExtension(i);o&&n.set(i,o)}}function Tc(t,e={}){let{contextAttributes:r,requiredExtensions:n=[],optionalExtensions:i=[]}=e,o=t.getContext("webgl2",r??{antialias:!0});if(!o)throw new Error("WebGL2 not supported or failed to initialize");O0(o);let s=new Map;N0(o,n,i,s);let a=!1,c=new Set,l=new Set,d=f=>{a=!0,f.preventDefault();for(let m of c)m()},u=()=>{a=!1;for(let f of l)f()};return t.addEventListener("webglcontextlost",d),t.addEventListener("webglcontextrestored",u),{gl:o,extensions:s,isLost:()=>a,onLost(f){return c.add(f),()=>c.delete(f)},onRestored(f){return l.add(f),()=>l.delete(f)},dispose(){t.removeEventListener("webglcontextlost",d),t.removeEventListener("webglcontextrestored",u),c.clear(),l.clear(),s.clear()}}}function Fc(t,e,r){let n=t.createShader(e);if(!n)throw new Error("Failed to allocate shader");if(t.shaderSource(n,r),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS)){let o=t.getShaderInfoLog(n)??"Unknown shader compile failure";throw t.deleteShader(n),new Error(o)}return n}function k0(t,e,r,n){let i=t.createProgram();if(!i)throw new Error("Failed to allocate shader program");if(t.attachShader(i,e),t.attachShader(i,r),n)for(let[s,a]of Object.entries(n))t.bindAttribLocation(i,a,s);if(t.linkProgram(i),!t.getProgramParameter(i,t.LINK_STATUS)){let s=t.getProgramInfoLog(i)??"Unknown shader link failure";throw t.deleteProgram(i),new Error(s)}return i}var ve=class t{constructor(e,r){this.uniformLocations=new Map;this.attributeLocations=new Map;this.gl=e,this.program=r}static create(e,r,n){let i=Fc(e,e.VERTEX_SHADER,r.vertex),o=Fc(e,e.FRAGMENT_SHADER,r.fragment);try{let s=k0(e,i,o,n);return new t(e,s)}finally{e.deleteShader(i),e.deleteShader(o)}}use(){this.gl.useProgram(this.program)}getUniformLocation(e){if(!this.uniformLocations.has(e)){let r=this.gl.getUniformLocation(this.program,e);this.uniformLocations.set(e,r)}return this.uniformLocations.get(e)??null}getAttributeLocation(e){if(!this.attributeLocations.has(e)){let r=this.gl.getAttribLocation(this.program,e);this.attributeLocations.set(e,r)}return this.attributeLocations.get(e)??-1}dispose(){this.gl.deleteProgram(this.program),this.uniformLocations.clear(),this.attributeLocations.clear()}};function Bc(t,e,r){return ve.create(t,e,r)}var Se=class{constructor(e,r=e.STATIC_DRAW,n){this.gl=e,this.target=n??e.ARRAY_BUFFER;let i=e.createBuffer();if(!i)throw new Error("Failed to allocate buffer");this.buffer=i,e.bindBuffer(this.target,this.buffer),e.bufferData(this.target,0,r)}bind(){this.gl.bindBuffer(this.target,this.buffer)}upload(e,r=this.gl.STATIC_DRAW){this.bind(),this.gl.bufferData(this.target,e,r)}update(e,r=0){this.bind(),this.gl.bufferSubData(this.target,r,e)}dispose(){this.gl.deleteBuffer(this.buffer)}},fe=class extends Se{constructor(e,r=e.STATIC_DRAW){super(e,r,e.ELEMENT_ARRAY_BUFFER)}},we=class{constructor(e){this.gl=e;let r=e.createVertexArray();if(!r)throw new Error("Failed to allocate vertex array object");this.vao=r}bind(){this.gl.bindVertexArray(this.vao)}configureAttributes(e,r){this.bind(),r&&r.bind();for(let n of e)this.gl.enableVertexAttribArray(n.index),this.gl.vertexAttribPointer(n.index,n.size,n.type,n.normalized??!1,n.stride??0,n.offset??0),n.divisor!==void 0&&this.gl.vertexAttribDivisor(n.index,n.divisor)}dispose(){this.gl.deleteVertexArray(this.vao)}},Dr=class{constructor(e,r=e.TEXTURE_2D){this.width=0;this.height=0;this.gl=e,this.target=r;let n=e.createTexture();if(!n)throw new Error("Failed to allocate texture");this.texture=n}bind(e=0){this.gl.activeTexture(this.gl.TEXTURE0+e),this.gl.bindTexture(this.target,this.texture)}setParameters(e){this.bind(),e.wrapS!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_S,e.wrapS),e.wrapT!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_T,e.wrapT),e.minFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MIN_FILTER,e.minFilter),e.magFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MAG_FILTER,e.magFilter)}upload(e,r,n){this.width=e,this.height=r,this.uploadImage(0,this.gl.RGBA,e,r,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,n)}uploadImage(e,r,n,i,o,s,a,c){this.bind(),this.gl.texImage2D(this.target,e,r,n,i,o,s,a,c)}dispose(){this.gl.deleteTexture(this.texture)}},Or=class{constructor(e){this.gl=e,this.target=e.TEXTURE_CUBE_MAP;let r=e.createTexture();if(!r)throw new Error("Failed to allocate cubemap texture");this.texture=r}bind(e=0){this.gl.activeTexture(this.gl.TEXTURE0+e),this.gl.bindTexture(this.target,this.texture)}setParameters(e){this.bind(),e.wrapS!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_S,e.wrapS),e.wrapT!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_T,e.wrapT),e.minFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MIN_FILTER,e.minFilter),e.magFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MAG_FILTER,e.magFilter)}uploadFace(e,r,n,i,o,s,a,c,l){this.bind(),this.gl.texImage2D(e,r,n,i,o,s,a,c,l)}dispose(){this.gl.deleteTexture(this.texture)}},xo=class{constructor(e){this.gl=e;let r=e.createFramebuffer();if(!r)throw new Error("Failed to allocate framebuffer");this.framebuffer=r}bind(e=this.gl.FRAMEBUFFER){this.gl.bindFramebuffer(e,this.framebuffer)}attachTexture2D(e,r,n=0){this.bind(),this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,e,r.target,r.texture,n)}dispose(){this.gl.deleteFramebuffer(this.framebuffer)}};var Ns=4,Os=7*Ns,ks=[{index:0,size:3,type:5126,stride:Os,offset:0},{index:1,size:2,type:5126,stride:Os,offset:3*Ns},{index:2,size:2,type:5126,stride:Os,offset:5*Ns}];function U0(t,e){return{width:t,height:t,padding:e,data:new Uint8Array(t*t*4),cursorX:0,cursorY:0,rowHeight:0}}function H0(t){let e=t.width*t.height;if(e===0)throw new Error("Invalid lightmap with zero area");let r=t.samples.byteLength/e;if(!Number.isInteger(r)||r<3||r>4)throw new Error("Unsupported lightmap channel count");return r}function V0(t,e,r){let n=H0(r),i=t.width*4,o=e.x+t.padding,s=e.y+t.padding,a=0;for(let c=0;c<r.height;c++){let l=(s+c)*i+o*4;for(let d=0;d<r.width;d++){let u=l+d*4;t.data[u]=r.samples[a],t.data[u+1]=r.samples[a+1],t.data[u+2]=r.samples[a+2],t.data[u+3]=n===4?r.samples[a+3]:255,a+=n}}}function G0(t,e,r){let n=e.width+r.lightmapPadding*2,i=e.height+r.lightmapPadding*2;if(n>r.atlasSize||i>r.atlasSize)throw new Error("Lightmap too large for atlas");for(let a of t){if(a.cursorX+n>a.width&&(a.cursorX=0,a.cursorY+=a.rowHeight+r.lightmapPadding,a.rowHeight=0),a.cursorY+i>a.height)continue;let c={atlasIndex:t.indexOf(a),x:a.cursorX,y:a.cursorY,width:e.width,height:e.height};return a.cursorX+=n+r.lightmapPadding,a.rowHeight=Math.max(a.rowHeight,i),{placement:c,atlas:a}}let o=U0(r.atlasSize,r.lightmapPadding);t.push(o);let s={atlasIndex:t.length-1,x:0,y:0,width:e.width,height:e.height};return o.cursorX=n+r.lightmapPadding,o.rowHeight=i,{placement:s,atlas:o}}function bo(t){return t instanceof Float32Array?t:new Float32Array(t)}function W0(t,e){if(!t){let n=new Uint16Array(e);for(let i=0;i<e;i++)n[i]=i;return n}return t instanceof Uint16Array?t:new Uint16Array(t)}function X0(t,e){let r=new Float32Array(t.length);for(let n=0;n<t.length;n+=2)r[n]=e.offset[0]+t[n]*e.scale[0],r[n+1]=e.offset[1]+t[n+1]*e.scale[1];return r}function K0(t,e){let r=bo(t.vertices),n=bo(t.textureCoords),i=e?X0(bo(t.lightmapCoords??t.textureCoords),e):bo(t.lightmapCoords??new Float32Array(n.length)),o=r.length/3;if(n.length/2!==o)throw new Error("Texture coordinates count mismatch");if(i.length/2!==o)throw new Error("Lightmap coordinates count mismatch");let s=new Float32Array(o*7);for(let a=0;a<o;a++){let c=a*3,l=a*2,d=a*7;s[d]=r[c],s[d+1]=r[c+1],s[d+2]=r[c+2],s[d+3]=n[l],s[d+4]=n[l+1],s[d+5]=i[l],s[d+6]=i[l+1]}return s}function Dc(t){let e=[];for(let r=0;r<t.faces.length;r++){let n=t.faces[r];if(n.texInfo<0)continue;let i=t.texInfo[n.texInfo],o=[],s=[],a=[];for(let f=0;f<n.numEdges;f++){let m=t.surfEdges[n.firstEdge+f],p=t.edges[Math.abs(m)],y=m>=0?p.vertices[0]:p.vertices[1],h=t.vertices[y];o.push(h[0],h[1],h[2]);let g=h[0]*i.s[0]+h[1]*i.s[1]+h[2]*i.s[2]+i.sOffset,M=h[0]*i.t[0]+h[1]*i.t[1]+h[2]*i.t[2]+i.tOffset;s.push(g,M),a.push(g,M)}let c=[],l=o.length/3;for(let f=1;f<l-1;f++)c.push(0,f,f+1);let d,u=t.lightMapInfo[r];if(u){let f=1/0,m=-1/0,p=1/0,y=-1/0;for(let b=0;b<s.length;b+=2){let S=s[b],A=s[b+1];S<f&&(f=S),S>m&&(m=S),A<p&&(p=A),A>y&&(y=A)}let h=Math.floor(f/16),g=Math.floor(p/16),M=Math.ceil(m/16)-h+1,x=Math.ceil(y/16)-g+1,v=bi(n,t.lightMaps,u);if(v&&v.length===M*x*3){d={width:M,height:x,samples:v};for(let b=0;b<a.length;b+=2)a[b]=s[b]/16-h+.5,a[b+1]=s[b+1]/16-g+.5}}e.push({vertices:new Float32Array(o),textureCoords:new Float32Array(s),lightmapCoords:new Float32Array(a),indices:new Uint16Array(c),texture:i.texture,surfaceFlags:i.flags,lightmap:d})}return e}function Oc(t,e,r={}){let n={atlasSize:r.atlasSize??1024,lightmapPadding:r.lightmapPadding??1},i=[],o=new Map;e.forEach((c,l)=>{if(!c.lightmap)return;let{placement:d,atlas:u}=G0(i,c.lightmap,n);V0(u,d,c.lightmap),o.set(l,{atlasIndex:d.atlasIndex,offset:[(d.x+n.lightmapPadding)/n.atlasSize,(d.y+n.lightmapPadding)/n.atlasSize],scale:[d.width/n.atlasSize,d.height/n.atlasSize]})});let s=i.map(c=>{let l=new Dr(t);return l.setParameters({wrapS:t.CLAMP_TO_EDGE,wrapT:t.CLAMP_TO_EDGE,minFilter:t.LINEAR,magFilter:t.LINEAR}),l.uploadImage(0,t.RGBA,c.width,c.height,0,t.RGBA,t.UNSIGNED_BYTE,c.data),{texture:l,width:c.width,height:c.height,pixels:c.data}});return{surfaces:e.map((c,l)=>{let d=o.get(l),u=K0(c,d),f=W0(c.indices,u.length/7),m=new Se(t,t.STATIC_DRAW,t.ARRAY_BUFFER);m.upload(u);let p=new fe(t,t.STATIC_DRAW);p.upload(f);let y=new we(t);return y.configureAttributes(ks,m),{vao:y,vertexBuffer:m,indexBuffer:p,indexCount:f.length,vertexCount:u.length/7,texture:c.texture,surfaceFlags:c.surfaceFlags??Kr,lightmap:d,vertexData:u,indexData:f}}),lightmaps:s}}function Nr(t){let{normal:e,distance:r}=t,n=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);if(n===0)return t;let i=1/n;return{normal:{x:e.x*i,y:e.y*i,z:e.z*i},distance:r*i}}function Nc(t){if(t.length!==16)throw new Error("View-projection matrix must contain 16 elements");let e=t[0],r=t[4],n=t[8],i=t[12],o=t[1],s=t[5],a=t[9],c=t[13],l=t[2],d=t[6],u=t[10],f=t[14],m=t[3],p=t[7],y=t[11],h=t[15];return[Nr({normal:{x:m+e,y:p+r,z:y+n},distance:h+i}),Nr({normal:{x:m-e,y:p-r,z:y-n},distance:h-i}),Nr({normal:{x:m+o,y:p+s,z:y+a},distance:h+c}),Nr({normal:{x:m-o,y:p-s,z:y-a},distance:h-c}),Nr({normal:{x:m+l,y:p+d,z:y+u},distance:h+f}),Nr({normal:{x:m-l,y:p-d,z:y-u},distance:h-f})]}function Y0(t,e){return t.normal.x*e.x+t.normal.y*e.y+t.normal.z*e.z+t.distance}function jn(t,e,r){for(let n of r){let i=n.normal.x>=0?e.x:t.x,o=n.normal.y>=0?e.y:t.y,s=n.normal.z>=0?e.z:t.z;if(Y0(n,{x:i,y:o,z:s})<0)return!1}return!0}function kc(t){return t<0}function Uc(t){return-t-1}function Hc(t,e){return t.normal[0]*e.x+t.normal[1]*e.y+t.normal[2]*e.z-t.dist}function q0(t,e,r){if(!t||e<0||r<0)return!0;let n=Math.ceil(t.numClusters/8),i=t.clusters[e].pvs,o=Math.floor(r/8),s=1<<r%8;return o<0||o>=n?!1:(i[o]&s)!==0}function $0(t,e){let r={x:t.mins[0],y:t.mins[1],z:t.mins[2]},n={x:t.maxs[0],y:t.maxs[1],z:t.maxs[2]};return jn(r,n,e)}function Hs(t,e){let r=0;for(;r>=0;){let n=t.nodes[r],i=t.planes[n.planeIndex],s=Hc(i,e)>=0?0:1,a=n.children[s];if(kc(a))return Uc(a);r=a}return-1}function j0(t,e){let r=t.leafs[e],n=[];for(let i=0;i<r.numLeafFaces;i+=1)n.push(t.leafLists.leafFaces[e][i]);return n}function Us(t,e,r,n,i,o,s){if(kc(e)){let f=Uc(e),m=t.leafs[f];if(!q0(t.visibility,i,m.cluster)||!$0(m,n))return;let p={x:(m.mins[0]+m.maxs[0])*.5,y:(m.mins[1]+m.maxs[1])*.5,z:(m.mins[2]+m.maxs[2])*.5},y=p.x-r.x,h=p.y-r.y,g=p.z-r.z,M=-(y*y+h*h+g*g);for(let x of j0(t,f))s.has(x)||(s.add(x),o.push({faceIndex:x,leafIndex:f,sortKey:M}));return}let a=t.nodes[e],c=t.planes[a.planeIndex],l=Hc(c,r),d=l>=0?a.children[0]:a.children[1],u=l>=0?a.children[1]:a.children[0];jn({x:a.mins[0],y:a.mins[1],z:a.mins[2]},{x:a.maxs[0],y:a.maxs[1],z:a.maxs[2]},n)&&(Us(t,d,r,n,i,o,s),Us(t,u,r,n,i,o,s))}function Vc(t,e,r){let n=Hs(t,e),i=n>=0?t.leafs[n].cluster:-1,o=[];return Us(t,0,e,r,i,o,new Set),o}var Ft=32;function kr(t){let e=[];for(let r=0;r<t.length;r+=3){let n=t[r],i=t[r+1],o=t[r+2];e.push(n,i,i,o,o,n)}return t instanceof Uint32Array||Math.max(...e)>65535?new Uint32Array(e):new Uint16Array(e)}var Vs=`#version 300 es
141
+ ïBçϧmÙIólÜoëVbƒ¦¯éWÇû3`});var bl={a:Bt};this.setModule=P=>{t.setModule(ut,P)},this.getModule=()=>t.getModule(ut),this.instantiate=()=>(this.getModule().then(P=>WebAssembly.instantiate(P,bl)).then(P=>{let ze=P.exports;oi(ze),p=ze.l,y(),xl(ze),r()}),this.ready=new Promise(P=>{r=P}).then(()=>{this.HEAP=p.buffer,this.malloc=la,this.free=ha,this.create_decoder=Vr,this.send_setup=da,this.init_dsp=ua,this.decode_packets=fa,this.destroy_decoder=ma}),this)}function Jt(){return this._init=()=>new this._WASMAudioDecoderCommon().instantiate(this._EmscriptenWASM,this._module).then(t=>{this._common=t,this._input=this._common.allocateTypedArray(this._inputSize,Uint8Array),this._firstPage=!0,this._inputLen=this._common.allocateTypedArray(1,Uint32Array),this._outputBufferPtr=this._common.allocateTypedArray(1,Uint32Array),this._channels=this._common.allocateTypedArray(1,Uint32Array),this._sampleRate=this._common.allocateTypedArray(1,Uint32Array),this._samplesDecoded=this._common.allocateTypedArray(1,Uint32Array);let e=256;this._errors=this._common.allocateTypedArray(e,Uint32Array),this._errorsLength=this._common.allocateTypedArray(1,Int32Array),this._frameNumber=0,this._inputBytes=0,this._outputSamples=0,this._decoder=this._common.wasm.create_decoder(this._input.ptr,this._inputLen.ptr,this._outputBufferPtr.ptr,this._channels.ptr,this._sampleRate.ptr,this._samplesDecoded.ptr,this._errors.ptr,this._errorsLength.ptr,e)}),Object.defineProperty(this,"ready",{enumerable:!0,get:()=>this._ready}),this.reset=()=>(this.free(),this._init()),this.free=()=>{this._common.wasm.destroy_decoder(this._decoder),this._common.free()},this.sendSetupHeader=t=>{this._input.buf.set(t),this._inputLen.buf[0]=t.length,this._common.wasm.send_setup(this._decoder,this._firstPage),this._firstPage=!1},this.initDsp=()=>{this._common.wasm.init_dsp(this._decoder)},this.decodePackets=t=>{let e=[],r=0,n=[];for(let i=0;i<t.length;i++){let o=t[i];this._input.buf.set(o),this._inputLen.buf[0]=o.length,this._common.wasm.decode_packets(this._decoder);let s=this._samplesDecoded.buf[0],a=[],c=new Uint32Array(this._common.wasm.HEAP,this._outputBufferPtr.buf[0],this._channels.buf[0]);for(let l=0;l<this._channels.buf[0];l++){let d=new Float32Array(s);s&&d.set(new Float32Array(this._common.wasm.HEAP,c[l],s)),a.push(d)}e.push(a),r+=s,this._frameNumber++,this._inputBytes+=o.length,this._outputSamples+=s;for(let l=0;l<this._errorsLength.buf;l+=2){let d=this._common.codeToString(this._errors.buf[l]),u=this._common.codeToString(this._errors.buf[l+1]);n.push({message:d+" vorbis_synthesis"+u,frameLength:o.length,frameNumber:this._frameNumber,inputBytes:this._inputBytes,outputSamples:this._outputSamples})}this._errorsLength.buf[0]=0}return this._WASMAudioDecoderCommon.getDecodedAudioMultiChannel(n,e,this._channels.buf[0],r,this._sampleRate.buf[0],16)},this._isWebWorker=Jt.isWebWorker,this._WASMAudioDecoderCommon=Jt.WASMAudioDecoderCommon||Z,this._EmscriptenWASM=Jt.EmscriptenWASM||ut,this._module=Jt.module,this._inputSize=128*1024,this._ready=this._init(),this}var to=Symbol(),ft=class{constructor(){this._onCodec=e=>{if(e!=="vorbis")throw new Error("@wasm-audio-decoders/ogg-vorbis does not support this codec "+e)},new Z,this._init(),this._ready=this[to](Jt)}_init(){this._vorbisSetupInProgress=!0,this._totalSamplesDecoded=0,this._codecParser=new Sc("audio/ogg",{onCodec:this._onCodec,enableFrameCRC32:!1})}async[to](e){if(this._decoder){let r=this._decoder;await r.ready.then(()=>r.free())}return this._decoder=new e,this._decoder.ready}get ready(){return this._ready}async reset(){return this._init(),this._decoder.reset()}free(){this._decoder.free()}async decodeOggPages(e){let r=[];for(let o=0;o<e.length;o++){let s=e[o];if(this._vorbisSetupInProgress&&(s[eo][0]===1&&this._decoder.sendSetupHeader(s[eo]),s[Zi].length)){let a=s[Zi][0][Mc];this._decoder.sendSetupHeader(a[Ac]),this._decoder.initDsp(),this._vorbisSetupInProgress=!1}r.push(...s[Zi].map(a=>a[eo]))}let n=await this._decoder.decodePackets(r);this._totalSamplesDecoded+=n.samplesDecoded;let i=e[e.length-1];if(i&&i[_c]){let o=this._totalSamplesDecoded-i[wc];if(o>0){for(let s=0;s<n.channelData.length;s++)n.channelData[s]=n.channelData[s].subarray(0,n.samplesDecoded-o);n.samplesDecoded-=o,this._totalSamplesDecoded-=o}}return n}async decode(e){return this.decodeOggPages([...this._codecParser.parseChunk(e)])}async flush(){let e=await this.decodeOggPages([...this._codecParser.flush()]);return await this.reset(),e}async decodeFile(e){let r=await this.decodeOggPages([...this._codecParser.parseAll(e)]);return await this.reset(),r}};var Rs=class extends gr{constructor(e){super(e,"ogg-vorbis-decoder",Jt,ut)}async sendSetupHeader(e){return this.postToDecoder("sendSetupHeader",e)}async initDsp(){return this.postToDecoder("initDsp")}async decodePackets(e){return this.postToDecoder("decodePackets",e)}},Wn=class extends ft{constructor(){super(),this._ready=super[to](Rs)}async free(){await this._decoder.free()}terminate(){this._decoder.terminate()}};Li(ft,"OggVorbisDecoder");Li(Wn,"OggVorbisDecoderWebWorker");var Ts=class extends Error{constructor(e){super(e),this.name="OggDecodeError"}};async function ro(t,e=new ft){await e.ready;let r=await e.decode(new Uint8Array(t)),n=r.errors;if(n&&n.length>0)throw new Ts(n.map(i=>i.message).join("; "));return{sampleRate:r.sampleRate,channels:r.channelData.length,bitDepth:r.bitDepth,channelData:r.channelData}}var Xn=class extends Error{constructor(e){super(e),this.name="AudioRegistryError"}},Fr=class{constructor(e,r={}){this.vfs=e;this.refCounts=new Map;this.cache=new pt(r.cacheSize??64)}get size(){return this.cache.size}async load(e){let r=e.toLowerCase(),n=this.cache.get(r);if(n)return this.refCounts.set(r,(this.refCounts.get(r)??0)+1),n;let o=(await this.vfs.readFile(e)).slice().buffer,s=await this.decodeByExtension(e,o);return this.cache.set(r,s),this.refCounts.set(r,1),s}release(e){let r=e.toLowerCase(),n=this.refCounts.get(r)??0;n<=1?(this.cache.delete(r),this.refCounts.delete(r)):this.refCounts.set(r,n-1)}clearAll(){this.cache.clear(),this.refCounts.clear()}async decodeByExtension(e,r){let n=e.toLowerCase();if(n.endsWith(".wav")){let i=wi(r),o=i.channels,s=Array.from({length:o},()=>new Float32Array(i.samples.length/o));for(let a=0;a<i.samples.length;a+=1)s[a%o][Math.floor(a/o)]=i.samples[a];return{sampleRate:i.sampleRate,channels:o,bitDepth:i.bitsPerSample,channelData:s}}if(n.endsWith(".ogg")||n.endsWith(".oga"))return ro(r);throw new Xn(`Unsupported audio format: ${e}`)}};var F0="quake2ts-pak-indexes",B0="pak-indexes";function Lc(){if(typeof indexedDB<"u")return indexedDB;if(typeof window<"u"&&"indexedDB"in window)return window.indexedDB;if(typeof globalThis<"u"&&"indexedDB"in globalThis)return globalThis.indexedDB}function Kn(t,e){let r=Lc();return r?new Promise((n,i)=>{let o=r.open(t,1);o.onupgradeneeded=()=>{let{result:s}=o;s.objectStoreNames.contains(e)||s.createObjectStore(e,{keyPath:"key"})},o.onerror=()=>i(o.error??new Error("Unknown IndexedDB error")),o.onsuccess=()=>n(o.result)}):Promise.reject(new Error("IndexedDB is not available in this environment"))}function Yn(t,e,r,n){return new Promise((i,o)=>{let a=t.transaction(e,r).objectStore(e),c=n(a);c.onsuccess=()=>i(c.result),c.onerror=()=>o(c.error??new Error("IndexedDB transaction error"))})}function Fs(t,e){return`${ie(t)}:${e.toString(16)}`}function D0(t){return t.map(e=>({...e}))}var no=class{constructor(e=F0,r=B0){this.dbName=e;this.storeName=r}get isSupported(){return!!Lc()}async persist(e){if(!this.isSupported)return;let r=e.validate(),n={...r,key:Fs(e.name,r.checksum),name:e.name,size:e.size,persistedAt:Date.now(),entries:D0(r.entries)},i=await Kn(this.dbName,this.storeName);return await Yn(i,this.storeName,"readwrite",o=>o.put(n)),i.close(),n}async find(e,r){if(!this.isSupported)return;let n=await Kn(this.dbName,this.storeName),i=r!==void 0?Fs(e,r):void 0,o=await Yn(n,this.storeName,"readonly",s=>i?s.get(i):s.getAll());if(n.close(),!!o){if(Array.isArray(o)){let s=ie(e),a=o.filter(c=>ie(c.name)===s);return a.length===0?void 0:a.sort((c,l)=>l.persistedAt-c.persistedAt)[0]}return o}}async remove(e,r){if(!this.isSupported)return!1;let n=await Kn(this.dbName,this.storeName),i=r!==void 0?Fs(e,r):void 0,o=await Yn(n,this.storeName,"readwrite",s=>{if(i)return s.delete(i);let a=`${ie(e)}:`;return s.delete(IDBKeyRange.bound(a,`${a}\uFFFF`,!1,!0))});return n.close(),typeof o=="number"?o>0:!0}async clear(){if(!this.isSupported)return;let e=await Kn(this.dbName,this.storeName);await Yn(e,this.storeName,"readwrite",r=>r.clear()),e.close()}async list(){if(!this.isSupported)return[];let e=await Kn(this.dbName,this.storeName),r=await Yn(e,this.storeName,"readonly",n=>n.getAll());return e.close(),r.sort((n,i)=>i.persistedAt-n.persistedAt)}};var Zt=class extends Error{constructor(r,n){super(n??`Missing dependencies: ${r.join(", ")}`);this.missing=r;this.name="AssetDependencyError"}},qn=class{constructor(){this.nodes=new Map}register(e,r=[]){let n=this.nodes.get(e)??{dependencies:new Set,loaded:!1};r.forEach(i=>n.dependencies.add(i)),this.nodes.set(e,n),r.forEach(i=>{this.nodes.has(i)||this.nodes.set(i,{dependencies:new Set,loaded:!1})})}markLoaded(e){let r=this.nodes.get(e)??{dependencies:new Set,loaded:!1},n=this.getMissingDependencies(e,r);if(n.length>0)throw new Zt(n,`Asset ${e} is missing dependencies: ${n.join(", ")}`);r.loaded=!0,this.nodes.set(e,r)}markUnloaded(e){let r=this.nodes.get(e);r&&(r.loaded=!1)}isLoaded(e){return this.nodes.get(e)?.loaded??!1}missingDependencies(e){let r=this.nodes.get(e);return r?this.getMissingDependencies(e,r):[]}reset(){this.nodes.clear()}getMissingDependencies(e,r){let n=[];for(let i of r.dependencies)this.nodes.get(i)?.loaded||n.push(i);return n}},io=class{constructor(e,r={}){this.vfs=e;this.maps=new Map;this.textures=new yr({capacity:r.textureCacheCapacity??128}),this.audio=new Fr(e,{cacheSize:r.audioCacheSize??64}),this.dependencyTracker=r.dependencyTracker??new qn,this.md2=new mr(e),this.md3=new hr(e),this.sprite=new pr(e),this.bsp=new fr(e),this.palette=new Uint8Array(768);for(let n=0;n<256;n++)this.palette[n*3]=n,this.palette[n*3+1]=n,this.palette[n*3+2]=n}async loadPalette(e="pics/colormap.pcx"){try{let r=await this.vfs.readFile(e),n=Jr(r);n.palette&&(this.palette=n.palette)}catch(r){console.warn(`Failed to load palette from ${e}:`,r)}}isAssetLoaded(e,r){return this.dependencyTracker.isLoaded(this.makeKey(e,r))}registerTexture(e,r){this.textures.set(e,r);let n=this.makeKey("texture",e);this.dependencyTracker.register(n),this.dependencyTracker.markLoaded(n)}async loadTexture(e){let r=this.textures.get(e);if(r)return r;let n=await this.vfs.readFile(e),i=e.split(".").pop()?.toLowerCase(),o;if(i==="wal")o=Ai(n,this.palette);else if(i==="pcx")o=_i(Jr(n));else if(i==="tga")o=ja(fs(n));else throw new Error(`Unsupported texture format for loadTexture: ${i}`);return this.registerTexture(e,o),o}async loadSound(e){let r=await this.audio.load(e),n=this.makeKey("sound",e);return this.dependencyTracker.register(n),this.dependencyTracker.markLoaded(n),r}async loadMd2Model(e,r=[]){let n=this.makeKey("model",e),i=r.map(a=>this.makeKey("texture",a));this.dependencyTracker.register(n,i);let o=this.dependencyTracker.missingDependencies(n);if(o.length>0)throw new Zt(o,`Asset ${n} is missing dependencies: ${o.join(", ")}`);let s=await this.md2.load(e);return this.dependencyTracker.markLoaded(n),s}getMd2Model(e){return this.md2.get(e)}async loadMd3Model(e,r=[]){let n=this.makeKey("model",e),i=r.map(a=>this.makeKey("texture",a));this.dependencyTracker.register(n,i);let o=this.dependencyTracker.missingDependencies(n);if(o.length>0)throw new Zt(o,`Asset ${n} is missing dependencies: ${o.join(", ")}`);let s=await this.md3.load(e);return this.dependencyTracker.markLoaded(n),s}getMd3Model(e){return this.md3.get(e)}async loadSprite(e){let r=this.makeKey("sprite",e);this.dependencyTracker.register(r);let n=await this.sprite.load(e);return this.dependencyTracker.markLoaded(r),n}async loadMap(e){let r=this.makeKey("map",e);if(this.maps.has(e))return this.maps.get(e);this.dependencyTracker.register(r);let n=await this.bsp.load(e);return this.maps.set(e,n),this.dependencyTracker.markLoaded(r),n}getMap(e){return this.maps.get(e)}listFiles(e){return this.vfs.findByExtension(e)}resetForLevelChange(){this.textures.clear(),this.audio.clearAll(),this.dependencyTracker.reset(),this.maps.clear()}makeKey(e,r){return`${e}:${ie(r)}`}};var Bs=32,oo=(u=>(u[u.Auto=0]="Auto",u[u.Weapon=1]="Weapon",u[u.Voice=2]="Voice",u[u.Item=3]="Item",u[u.Body=4]="Body",u[u.Aux=5]="Aux",u[u.Footstep=6]="Footstep",u[u.Aux3=7]="Aux3",u[u.NoPhsAdd=8]="NoPhsAdd",u[u.Reliable=16]="Reliable",u[u.ForcePos=32]="ForcePos",u))(oo||{}),Ec=-1,so=0,Ic=1,Pc=2,Cc=3,Br=80,zc=.003;function er(t){return t===3?t*.001:t*5e-4}function ao(t){let e=er(t);return e<=0?Number.POSITIVE_INFINITY:80+1/e}var co=class{constructor(e){this.factory=e}getContext(){return this.context||(this.context=this.factory()),this.context}async resume(){let e=this.getContext();e.state==="suspended"&&await e.resume()}getState(){return this.context?.state??"suspended"}};function lo(t){let e=t.getContext(),r=e.createGain();r.gain.value=1;let n=e.createDynamicsCompressor(),i=e.createBiquadFilter?.();return i?(i.type="lowpass",i.frequency.value=2e4,i.Q.value=.707,r.connect(i),i.connect(n)):r.connect(n),n.connect(e.destination),{context:e,master:r,compressor:n,filter:i}}var uo=class{constructor(e=new lr){this.configStrings=e;this.buffers=new Map}registerName(e){return this.configStrings.soundIndex(e)}register(e,r){let n=this.registerName(e);return this.buffers.set(n,r),n}find(e){return this.configStrings.findSoundIndex(e)}get(e){return this.buffers.get(e)}has(e){return this.buffers.has(e)}getName(e){return this.configStrings.getName(e)}};var fo=class{constructor(e){this.vfs=e.vfs,this.registry=e.registry,this.contextController=e.context,this.soundRoot=e.soundRoot??"sound/",this.decodeAudio=e.decodeAudio??((r,n)=>{if(!r.decodeAudioData)throw new Error("decodeAudioData is not available on the provided audio context");return r.decodeAudioData(n)})}async precache(e){let r=[...new Set(e.map(o=>this.normalize(o)))],n={loaded:[],skipped:[],missing:[],errors:{}},i=this.contextController.getContext();for(let o of r)try{let s=this.registry.find(o);if(s!==void 0&&this.registry.has(s)){n.skipped.push(o);continue}if(!this.vfs.stat(o)){n.missing.push(o);continue}let l=(await this.vfs.readFile(o)).slice().buffer,d=await this.decodeAudio(i,l);this.registry.register(o,d),n.loaded.push(o)}catch(s){let a=s instanceof Error?s:new Error(String(s));n.errors[o]=a}return n}normalize(e){let r=ie(e.replace(/^\//,""));return r.startsWith(this.soundRoot)?r:ie(`${this.soundRoot}${r}`)}};var O0=7,$n=t=>t&O0;function mo(t){return Array.from({length:32},()=>({entnum:0,entchannel:0,endTimeMs:0,isPlayer:!1,active:!1})).map(e=>({...e,isPlayer:e.entnum===t}))}function ho(t,e,r,n){if(r<0)throw new Error("pickChannel: entchannel must be non-negative");let i=$n(r),o=-1,s=Number.POSITIVE_INFINITY;for(let a=0;a<t.length;a+=1){let c=t[a],l=$n(c.entchannel);if(i!==0&&c.entnum===e&&l===i){o=a;break}if(c.active&&c.entnum===n.playerEntity&&e!==n.playerEntity)continue;let d=c.endTimeMs-n.nowMs;(o===-1||d<s)&&(s=d,o=a)}return o===-1?void 0:o}function po(t,e,r,n,i){if(i)return{left:r,right:r,distanceComponent:0};let o=ba(t,e.origin),s=Qo(o),a=He(o),c=s-80;c<0&&(c=0),c*=er(n);let l=jo(e.right,a),d=e.mono??!1,u=d||n===0?1:.5*(1+l),f=d||n===0?1:.5*(1-l),m=Math.max(0,Math.floor(r*(1-c)*u));return{left:Math.max(0,Math.floor(r*(1-c)*f)),right:m,distanceComponent:c}}var yo=class{constructor(e){this.activeSources=new Map;this.contextController=e.context,this.registry=e.registry,this.playerEntity=e.playerEntity,this.channels=mo(e.playerEntity),this.listener=e.listener??{origin:xa,right:{x:1,y:0,z:0}},this.sfxVolume=e.sfxVolume??1,this.masterVolume=e.masterVolume??1,this.resolveOcclusion=e.resolveOcclusion,this.graph=lo(this.contextController),this.graph.master.gain.value=this.masterVolume}setListener(e){this.listener=e}setMasterVolume(e){this.masterVolume=e,this.graph.master.gain.value=e}setSfxVolume(e){this.sfxVolume=e}async ensureRunning(){await this.contextController.resume()}play(e){let r=this.registry.get(e.soundIndex);if(!r)return;let n=this.graph.context,i=n.currentTime*1e3,o=ho(this.channels,e.entity,e.channel,{nowMs:i,playerEntity:this.playerEntity});if(o===void 0)return;let s=this.activeSources.get(o);s&&(s.source.onended=null,s.source.stop(),this.activeSources.delete(o));let a=n.createBufferSource();a.buffer=r,a.loop=e.looping??!1;let c=e.origin??this.listener.origin,l=n.createGain(),d=this.createPanner(n,e.attenuation),u=this.resolveOcclusion?.(this.listener,c,e.attenuation),f=Rc(u?.gainScale??1),m=this.resolveOcclusion?this.createOcclusionFilter(n,u?.lowpassHz??2e4):void 0;this.applyOriginToPanner(d,c);let p=e.entity===this.playerEntity,y=po(c,this.listener,e.volume,e.attenuation,p),g=(e.volume===0?0:Math.max(y.left,y.right)/Math.max(1,e.volume))*(e.volume/255)*this.masterVolume*this.sfxVolume;l.gain.value=g*f;let S=n.currentTime+(e.timeOffsetMs??0)/1e3,x=(e.looping?Number.POSITIVE_INFINITY:r.duration*1e3)+S*1e3;a.connect(d),m?(d.connect(m),m.connect(l)):d.connect(l),l.connect(this.graph.master),a.start(S),a.onended=()=>{this.channels[o].active=!1,this.activeSources.delete(o)};let v={channelIndex:o,entnum:e.entity,entchannel:$n(e.channel),endTimeMs:x,source:a,panner:d,gain:l,baseGain:g,origin:c,attenuation:e.attenuation,occlusion:m?{scale:f,lowpassHz:u?.lowpassHz,filter:m}:u?{scale:f,lowpassHz:u.lowpassHz}:void 0};return this.channels[o]={entnum:e.entity,entchannel:$n(e.channel),endTimeMs:x,isPlayer:e.entity===this.playerEntity,active:!0},this.activeSources.set(o,v),v}stop(e){let r=this.activeSources.get(e);r&&(r.source.stop(),this.channels[e].active=!1,this.activeSources.delete(e))}stopEntitySounds(e){for(let[r,n]of[...this.activeSources.entries()])n.entnum===e&&(n.source.stop(),this.channels[r].active=!1,this.activeSources.delete(r))}updateEntityPosition(e,r){for(let n of this.activeSources.values())if(n.entnum===e&&(this.applyOriginToPanner(n.panner,r),n.origin=r,this.resolveOcclusion)){let i=this.resolveOcclusion(this.listener,r,n.attenuation);this.applyOcclusion(n,i)}}positionedSound(e,r,n,i){return this.play({entity:0,channel:0,soundIndex:r,volume:n,attenuation:i,origin:e})}ambientSound(e,r,n){return this.play({entity:0,channel:0,soundIndex:r,volume:n,attenuation:0,origin:e,looping:!0})}getChannelState(e){return this.channels[e]}getDiagnostics(){return{activeChannels:this.activeSources.size,masterVolume:this.masterVolume,sfxVolume:this.sfxVolume,channels:[...this.channels],activeSounds:[...this.activeSources.values()].map(e=>({entnum:e.entnum,entchannel:e.entchannel,channelIndex:e.channelIndex,origin:e.origin,gain:e.gain.gain.value,baseGain:e.baseGain,attenuation:e.attenuation,maxDistance:e.panner.maxDistance,distanceModel:e.panner.distanceModel,occlusion:e.occlusion?{scale:e.occlusion.scale,lowpassHz:e.occlusion.lowpassHz}:void 0}))}}setUnderwater(e,r=400){let n=this.graph.filter;n&&(n.type="lowpass",n.Q.value=.707,n.frequency.value=e?r:2e4)}createPanner(e,r){let n=e.createPanner?e.createPanner():Object.assign(e.createGain(),{positionX:{value:this.listener.origin.x},positionY:{value:this.listener.origin.y},positionZ:{value:this.listener.origin.z}});return this.configurePanner(n,r)}configurePanner(e,r){let n=er(r);return e.refDistance=80,e.maxDistance=ao(r),e.rolloffFactor=n,e.distanceModel=r===0?"linear":"inverse",e.positionX.value=this.listener.origin.x,e.positionY.value=this.listener.origin.y,e.positionZ.value=this.listener.origin.z,e}applyOriginToPanner(e,r){e.positionX.value=r.x,e.positionY.value=r.y,e.positionZ.value=r.z}createOcclusionFilter(e,r){if(!e.createBiquadFilter)return;let n=e.createBiquadFilter();return n.type="lowpass",n.Q.value=.707,n.frequency.value=Ds(r,10,2e4),n}applyOcclusion(e,r){let n=Rc(r?.gainScale??1);if(e.gain.gain.value=e.baseGain*n,e.occlusion?.filter){let i=r?.lowpassHz??2e4;e.occlusion.filter.frequency.value=Ds(i,10,2e4)}e.occlusion?(e.occlusion.scale=n,e.occlusion.lowpassHz=r?.lowpassHz):r&&(e.occlusion={scale:n,lowpassHz:r.lowpassHz})}},Ds=(t,e,r)=>Math.min(r,Math.max(e,t)),Rc=t=>Ds(t,0,1);var go=class{constructor(e){this.createElement=e.createElement,this.resolveSource=e.resolveSource??(async r=>r),this.volume=e.volume??1}async play(e,{loop:r=!0,restart:n=!1}={}){if(this.track===e&&this.element){this.element.loop=r,this.element.volume=this.volume,n&&(this.element.currentTime=0),(this.element.paused||n)&&await this.element.play();return}let i=await this.resolveSource(e),o=this.createElement();o.src=i,o.loop=r,o.volume=this.volume,o.currentTime=0,o.load(),await o.play(),this.element=o,this.track=e}pause(){!this.element||this.element.paused||this.element.pause()}async resume(){!this.element||!this.element.paused||await this.element.play()}stop(){this.element&&(this.element.pause(),this.element.currentTime=0,this.element=void 0,this.track=void 0)}setVolume(e){this.volume=e,this.element&&(this.element.volume=e)}getState(){let e=!!(this.element&&!this.element.paused&&!this.element.ended),r=!!this.element?.paused;return{track:this.track,paused:r,playing:e,volume:this.volume}}};function N0(t){t.enable(t.DEPTH_TEST),t.depthFunc(t.LEQUAL),t.enable(t.CULL_FACE),t.cullFace(t.BACK),t.enable(t.BLEND),t.blendFuncSeparate(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA)}function k0(t,e,r,n){for(let i of e){let o=t.getExtension(i);if(!o)throw new Error(`Missing required WebGL extension: ${i}`);n.set(i,o)}for(let i of r){let o=t.getExtension(i);o&&n.set(i,o)}}function Tc(t,e={}){let{contextAttributes:r,requiredExtensions:n=[],optionalExtensions:i=[]}=e,o=t.getContext("webgl2",r??{antialias:!0});if(!o)throw new Error("WebGL2 not supported or failed to initialize");N0(o);let s=new Map;k0(o,n,i,s);let a=!1,c=new Set,l=new Set,d=f=>{a=!0,f.preventDefault();for(let m of c)m()},u=()=>{a=!1;for(let f of l)f()};return t.addEventListener("webglcontextlost",d),t.addEventListener("webglcontextrestored",u),{gl:o,extensions:s,isLost:()=>a,onLost(f){return c.add(f),()=>c.delete(f)},onRestored(f){return l.add(f),()=>l.delete(f)},dispose(){t.removeEventListener("webglcontextlost",d),t.removeEventListener("webglcontextrestored",u),c.clear(),l.clear(),s.clear()}}}function Fc(t,e,r){let n=t.createShader(e);if(!n)throw new Error("Failed to allocate shader");if(t.shaderSource(n,r),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS)){let o=t.getShaderInfoLog(n)??"Unknown shader compile failure";throw t.deleteShader(n),new Error(o)}return n}function U0(t,e,r,n){let i=t.createProgram();if(!i)throw new Error("Failed to allocate shader program");if(t.attachShader(i,e),t.attachShader(i,r),n)for(let[s,a]of Object.entries(n))t.bindAttribLocation(i,a,s);if(t.linkProgram(i),!t.getProgramParameter(i,t.LINK_STATUS)){let s=t.getProgramInfoLog(i)??"Unknown shader link failure";throw t.deleteProgram(i),new Error(s)}return i}var ve=class t{constructor(e,r){this.uniformLocations=new Map;this.attributeLocations=new Map;this.gl=e,this.program=r}static create(e,r,n){let i=Fc(e,e.VERTEX_SHADER,r.vertex),o=Fc(e,e.FRAGMENT_SHADER,r.fragment);try{let s=U0(e,i,o,n);return new t(e,s)}finally{e.deleteShader(i),e.deleteShader(o)}}use(){this.gl.useProgram(this.program)}getUniformLocation(e){if(!this.uniformLocations.has(e)){let r=this.gl.getUniformLocation(this.program,e);this.uniformLocations.set(e,r)}return this.uniformLocations.get(e)??null}getAttributeLocation(e){if(!this.attributeLocations.has(e)){let r=this.gl.getAttribLocation(this.program,e);this.attributeLocations.set(e,r)}return this.attributeLocations.get(e)??-1}dispose(){this.gl.deleteProgram(this.program),this.uniformLocations.clear(),this.attributeLocations.clear()}};function Bc(t,e,r){return ve.create(t,e,r)}var Se=class{constructor(e,r=e.STATIC_DRAW,n){this.gl=e,this.target=n??e.ARRAY_BUFFER;let i=e.createBuffer();if(!i)throw new Error("Failed to allocate buffer");this.buffer=i,e.bindBuffer(this.target,this.buffer),e.bufferData(this.target,0,r)}bind(){this.gl.bindBuffer(this.target,this.buffer)}upload(e,r=this.gl.STATIC_DRAW){this.bind(),this.gl.bufferData(this.target,e,r)}update(e,r=0){this.bind(),this.gl.bufferSubData(this.target,r,e)}dispose(){this.gl.deleteBuffer(this.buffer)}},fe=class extends Se{constructor(e,r=e.STATIC_DRAW){super(e,r,e.ELEMENT_ARRAY_BUFFER)}},we=class{constructor(e){this.gl=e;let r=e.createVertexArray();if(!r)throw new Error("Failed to allocate vertex array object");this.vao=r}bind(){this.gl.bindVertexArray(this.vao)}configureAttributes(e,r){this.bind(),r&&r.bind();for(let n of e)this.gl.enableVertexAttribArray(n.index),this.gl.vertexAttribPointer(n.index,n.size,n.type,n.normalized??!1,n.stride??0,n.offset??0),n.divisor!==void 0&&this.gl.vertexAttribDivisor(n.index,n.divisor)}dispose(){this.gl.deleteVertexArray(this.vao)}},Dr=class{constructor(e,r=e.TEXTURE_2D){this.width=0;this.height=0;this.gl=e,this.target=r;let n=e.createTexture();if(!n)throw new Error("Failed to allocate texture");this.texture=n}bind(e=0){this.gl.activeTexture(this.gl.TEXTURE0+e),this.gl.bindTexture(this.target,this.texture)}setParameters(e){this.bind(),e.wrapS!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_S,e.wrapS),e.wrapT!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_T,e.wrapT),e.minFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MIN_FILTER,e.minFilter),e.magFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MAG_FILTER,e.magFilter)}upload(e,r,n){this.width=e,this.height=r,this.uploadImage(0,this.gl.RGBA,e,r,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,n)}uploadImage(e,r,n,i,o,s,a,c){this.bind(),this.gl.texImage2D(this.target,e,r,n,i,o,s,a,c)}dispose(){this.gl.deleteTexture(this.texture)}},Or=class{constructor(e){this.gl=e,this.target=e.TEXTURE_CUBE_MAP;let r=e.createTexture();if(!r)throw new Error("Failed to allocate cubemap texture");this.texture=r}bind(e=0){this.gl.activeTexture(this.gl.TEXTURE0+e),this.gl.bindTexture(this.target,this.texture)}setParameters(e){this.bind(),e.wrapS!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_S,e.wrapS),e.wrapT!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_T,e.wrapT),e.minFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MIN_FILTER,e.minFilter),e.magFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MAG_FILTER,e.magFilter)}uploadFace(e,r,n,i,o,s,a,c,l){this.bind(),this.gl.texImage2D(e,r,n,i,o,s,a,c,l)}dispose(){this.gl.deleteTexture(this.texture)}},xo=class{constructor(e){this.gl=e;let r=e.createFramebuffer();if(!r)throw new Error("Failed to allocate framebuffer");this.framebuffer=r}bind(e=this.gl.FRAMEBUFFER){this.gl.bindFramebuffer(e,this.framebuffer)}attachTexture2D(e,r,n=0){this.bind(),this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,e,r.target,r.texture,n)}dispose(){this.gl.deleteFramebuffer(this.framebuffer)}};var Ns=4,Os=7*Ns,ks=[{index:0,size:3,type:5126,stride:Os,offset:0},{index:1,size:2,type:5126,stride:Os,offset:3*Ns},{index:2,size:2,type:5126,stride:Os,offset:5*Ns}];function H0(t,e){return{width:t,height:t,padding:e,data:new Uint8Array(t*t*4),cursorX:0,cursorY:0,rowHeight:0}}function V0(t){let e=t.width*t.height;if(e===0)throw new Error("Invalid lightmap with zero area");let r=t.samples.byteLength/e;if(!Number.isInteger(r)||r<3||r>4)throw new Error("Unsupported lightmap channel count");return r}function G0(t,e,r){let n=V0(r),i=t.width*4,o=e.x+t.padding,s=e.y+t.padding,a=0;for(let c=0;c<r.height;c++){let l=(s+c)*i+o*4;for(let d=0;d<r.width;d++){let u=l+d*4;t.data[u]=r.samples[a],t.data[u+1]=r.samples[a+1],t.data[u+2]=r.samples[a+2],t.data[u+3]=n===4?r.samples[a+3]:255,a+=n}}}function W0(t,e,r){let n=e.width+r.lightmapPadding*2,i=e.height+r.lightmapPadding*2;if(n>r.atlasSize||i>r.atlasSize)throw new Error("Lightmap too large for atlas");for(let a of t){if(a.cursorX+n>a.width&&(a.cursorX=0,a.cursorY+=a.rowHeight+r.lightmapPadding,a.rowHeight=0),a.cursorY+i>a.height)continue;let c={atlasIndex:t.indexOf(a),x:a.cursorX,y:a.cursorY,width:e.width,height:e.height};return a.cursorX+=n+r.lightmapPadding,a.rowHeight=Math.max(a.rowHeight,i),{placement:c,atlas:a}}let o=H0(r.atlasSize,r.lightmapPadding);t.push(o);let s={atlasIndex:t.length-1,x:0,y:0,width:e.width,height:e.height};return o.cursorX=n+r.lightmapPadding,o.rowHeight=i,{placement:s,atlas:o}}function bo(t){return t instanceof Float32Array?t:new Float32Array(t)}function X0(t,e){if(!t){let n=new Uint16Array(e);for(let i=0;i<e;i++)n[i]=i;return n}return t instanceof Uint16Array?t:new Uint16Array(t)}function K0(t,e){let r=new Float32Array(t.length);for(let n=0;n<t.length;n+=2)r[n]=e.offset[0]+t[n]*e.scale[0],r[n+1]=e.offset[1]+t[n+1]*e.scale[1];return r}function Y0(t,e){let r=bo(t.vertices),n=bo(t.textureCoords),i=e?K0(bo(t.lightmapCoords??t.textureCoords),e):bo(t.lightmapCoords??new Float32Array(n.length)),o=r.length/3;if(n.length/2!==o)throw new Error("Texture coordinates count mismatch");if(i.length/2!==o)throw new Error("Lightmap coordinates count mismatch");let s=new Float32Array(o*7);for(let a=0;a<o;a++){let c=a*3,l=a*2,d=a*7;s[d]=r[c],s[d+1]=r[c+1],s[d+2]=r[c+2],s[d+3]=n[l],s[d+4]=n[l+1],s[d+5]=i[l],s[d+6]=i[l+1]}return s}function Dc(t){let e=[];for(let r=0;r<t.faces.length;r++){let n=t.faces[r];if(n.texInfo<0)continue;let i=t.texInfo[n.texInfo],o=[],s=[],a=[];for(let f=0;f<n.numEdges;f++){let m=t.surfEdges[n.firstEdge+f],p=t.edges[Math.abs(m)],y=m>=0?p.vertices[0]:p.vertices[1],h=t.vertices[y];o.push(h[0],h[1],h[2]);let g=h[0]*i.s[0]+h[1]*i.s[1]+h[2]*i.s[2]+i.sOffset,S=h[0]*i.t[0]+h[1]*i.t[1]+h[2]*i.t[2]+i.tOffset;s.push(g,S),a.push(g,S)}let c=[],l=o.length/3;for(let f=1;f<l-1;f++)c.push(0,f,f+1);let d,u=t.lightMapInfo[r];if(u){let f=1/0,m=-1/0,p=1/0,y=-1/0;for(let b=0;b<s.length;b+=2){let _=s[b],A=s[b+1];_<f&&(f=_),_>m&&(m=_),A<p&&(p=A),A>y&&(y=A)}let h=Math.floor(f/16),g=Math.floor(p/16),S=Math.ceil(m/16)-h+1,x=Math.ceil(y/16)-g+1,v=bi(n,t.lightMaps,u);if(v&&v.length===S*x*3){d={width:S,height:x,samples:v};for(let b=0;b<a.length;b+=2)a[b]=s[b]/16-h+.5,a[b+1]=s[b+1]/16-g+.5}}e.push({vertices:new Float32Array(o),textureCoords:new Float32Array(s),lightmapCoords:new Float32Array(a),indices:new Uint16Array(c),texture:i.texture,surfaceFlags:i.flags,lightmap:d})}return e}function Oc(t,e,r={}){let n={atlasSize:r.atlasSize??1024,lightmapPadding:r.lightmapPadding??1},i=[],o=new Map;e.forEach((c,l)=>{if(!c.lightmap)return;let{placement:d,atlas:u}=W0(i,c.lightmap,n);G0(u,d,c.lightmap),o.set(l,{atlasIndex:d.atlasIndex,offset:[(d.x+n.lightmapPadding)/n.atlasSize,(d.y+n.lightmapPadding)/n.atlasSize],scale:[d.width/n.atlasSize,d.height/n.atlasSize]})});let s=i.map(c=>{let l=new Dr(t);return l.setParameters({wrapS:t.CLAMP_TO_EDGE,wrapT:t.CLAMP_TO_EDGE,minFilter:t.LINEAR,magFilter:t.LINEAR}),l.uploadImage(0,t.RGBA,c.width,c.height,0,t.RGBA,t.UNSIGNED_BYTE,c.data),{texture:l,width:c.width,height:c.height,pixels:c.data}});return{surfaces:e.map((c,l)=>{let d=o.get(l),u=Y0(c,d),f=X0(c.indices,u.length/7),m=new Se(t,t.STATIC_DRAW,t.ARRAY_BUFFER);m.upload(u);let p=new fe(t,t.STATIC_DRAW);p.upload(f);let y=new we(t);return y.configureAttributes(ks,m),{vao:y,vertexBuffer:m,indexBuffer:p,indexCount:f.length,vertexCount:u.length/7,texture:c.texture,surfaceFlags:c.surfaceFlags??Kr,lightmap:d,vertexData:u,indexData:f}}),lightmaps:s}}function Nr(t){let{normal:e,distance:r}=t,n=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);if(n===0)return t;let i=1/n;return{normal:{x:e.x*i,y:e.y*i,z:e.z*i},distance:r*i}}function Nc(t){if(t.length!==16)throw new Error("View-projection matrix must contain 16 elements");let e=t[0],r=t[4],n=t[8],i=t[12],o=t[1],s=t[5],a=t[9],c=t[13],l=t[2],d=t[6],u=t[10],f=t[14],m=t[3],p=t[7],y=t[11],h=t[15];return[Nr({normal:{x:m+e,y:p+r,z:y+n},distance:h+i}),Nr({normal:{x:m-e,y:p-r,z:y-n},distance:h-i}),Nr({normal:{x:m+o,y:p+s,z:y+a},distance:h+c}),Nr({normal:{x:m-o,y:p-s,z:y-a},distance:h-c}),Nr({normal:{x:m+l,y:p+d,z:y+u},distance:h+f}),Nr({normal:{x:m-l,y:p-d,z:y-u},distance:h-f})]}function q0(t,e){return t.normal.x*e.x+t.normal.y*e.y+t.normal.z*e.z+t.distance}function jn(t,e,r){for(let n of r){let i=n.normal.x>=0?e.x:t.x,o=n.normal.y>=0?e.y:t.y,s=n.normal.z>=0?e.z:t.z;if(q0(n,{x:i,y:o,z:s})<0)return!1}return!0}function kc(t){return t<0}function Uc(t){return-t-1}function Hc(t,e){return t.normal[0]*e.x+t.normal[1]*e.y+t.normal[2]*e.z-t.dist}function $0(t,e,r){if(!t||e<0||r<0)return!0;let n=Math.ceil(t.numClusters/8),i=t.clusters[e].pvs,o=Math.floor(r/8),s=1<<r%8;return o<0||o>=n?!1:(i[o]&s)!==0}function j0(t,e){let r={x:t.mins[0],y:t.mins[1],z:t.mins[2]},n={x:t.maxs[0],y:t.maxs[1],z:t.maxs[2]};return jn(r,n,e)}function Hs(t,e){let r=0;for(;r>=0;){let n=t.nodes[r],i=t.planes[n.planeIndex],s=Hc(i,e)>=0?0:1,a=n.children[s];if(kc(a))return Uc(a);r=a}return-1}function Q0(t,e){let r=t.leafs[e],n=[];for(let i=0;i<r.numLeafFaces;i+=1)n.push(t.leafLists.leafFaces[e][i]);return n}function Us(t,e,r,n,i,o,s){if(kc(e)){let f=Uc(e),m=t.leafs[f];if(!$0(t.visibility,i,m.cluster)||!j0(m,n))return;let p={x:(m.mins[0]+m.maxs[0])*.5,y:(m.mins[1]+m.maxs[1])*.5,z:(m.mins[2]+m.maxs[2])*.5},y=p.x-r.x,h=p.y-r.y,g=p.z-r.z,S=-(y*y+h*h+g*g);for(let x of Q0(t,f))s.has(x)||(s.add(x),o.push({faceIndex:x,leafIndex:f,sortKey:S}));return}let a=t.nodes[e],c=t.planes[a.planeIndex],l=Hc(c,r),d=l>=0?a.children[0]:a.children[1],u=l>=0?a.children[1]:a.children[0];jn({x:a.mins[0],y:a.mins[1],z:a.mins[2]},{x:a.maxs[0],y:a.maxs[1],z:a.maxs[2]},n)&&(Us(t,d,r,n,i,o,s),Us(t,u,r,n,i,o,s))}function Vc(t,e,r){let n=Hs(t,e),i=n>=0?t.leafs[n].cluster:-1,o=[];return Us(t,0,e,r,i,o,new Set),o}var Ft=32;function kr(t){let e=[];for(let r=0;r<t.length;r+=3){let n=t[r],i=t[r+1],o=t[r+2];e.push(n,i,i,o,o,n)}return t instanceof Uint32Array||Math.max(...e)>65535?new Uint32Array(e):new Uint16Array(e)}var Vs=`#version 300 es
142
142
  precision highp float;
143
143
 
144
144
  layout(location = 0) in vec3 a_position;
@@ -250,7 +250,7 @@ void main() {
250
250
  }
251
251
 
252
252
  o_color = finalColor;
253
- }`,Gc=[0,255,255,255];function Ws(t=Gc,e=[]){let r=new Float32Array(4);for(let n=0;n<4;n+=1){let i=t[n]??255;if(i===255){r[n]=0;continue}let o=e[i];r[n]=o!==void 0?o:1}return r}function Q0(t){return[-(t*.25%1),0]}function Xs(t=Kr,e=0){let r=(t&Ea)!==0,n=(t&Aa)!==0,i=(t&_a)!==0,o=(t&wa)!==0,s=(t&La)!==0,a=o?.33:s?.66:1,c=o||s,l=!c&&!i,d=r?Q0(e):[0,0];return{alpha:a,blend:c,depthWrite:l,warp:n,flowOffset:d,sky:i}}var vo=class{constructor(e){this.uniformDlights=[];this.gl=e,this.program=ve.create(e,{vertex:Vs,fragment:Gs},{a_position:0,a_texCoord:1,a_lightmapCoord:2}),this.uniformMvp=this.program.getUniformLocation("u_modelViewProjection"),this.uniformTexScroll=this.program.getUniformLocation("u_texScroll"),this.uniformLmScroll=this.program.getUniformLocation("u_lightmapScroll"),this.uniformLightStyles=this.program.getUniformLocation("u_lightStyleFactors"),this.uniformAlpha=this.program.getUniformLocation("u_alpha"),this.uniformApplyLightmap=this.program.getUniformLocation("u_applyLightmap"),this.uniformWarp=this.program.getUniformLocation("u_warp"),this.uniformDiffuse=this.program.getUniformLocation("u_diffuseMap"),this.uniformLightmap=this.program.getUniformLocation("u_lightmapAtlas"),this.uniformTime=this.program.getUniformLocation("u_time"),this.uniformRenderMode=this.program.getUniformLocation("u_renderMode"),this.uniformSolidColor=this.program.getUniformLocation("u_solidColor"),this.uniformNumDlights=this.program.getUniformLocation("u_numDlights");for(let r=0;r<Ft;r++)this.uniformDlights.push({pos:this.program.getUniformLocation(`u_dlights[${r}].position`),color:this.program.getUniformLocation(`u_dlights[${r}].color`),intensity:this.program.getUniformLocation(`u_dlights[${r}].intensity`)})}bind(e){let{modelViewProjection:r,styleIndices:n=Gc,styleValues:i=[],diffuseSampler:o=0,lightmapSampler:s,surfaceFlags:a=Kr,timeSeconds:c=0,texScroll:l,alpha:d,warp:u,dlights:f=[],renderMode:m}=e,p=Xs(a,c),y=Ws(n,i),h=l?l[0]:p.flowOffset[0],g=l?l[1]:p.flowOffset[1],M=d!==void 0?d:p.alpha,x=u!==void 0?u:p.warp;this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,r),this.gl.uniform2f(this.uniformTexScroll,h,g),this.gl.uniform2f(this.uniformLmScroll,p.flowOffset[0],p.flowOffset[1]),this.gl.uniform4fv(this.uniformLightStyles,y),this.gl.uniform1f(this.uniformAlpha,M);let v=!p.sky&&s!==void 0;this.gl.uniform1i(this.uniformApplyLightmap,v?1:0),this.gl.uniform1i(this.uniformWarp,x?1:0),this.gl.uniform1f(this.uniformTime,c),this.gl.uniform1i(this.uniformDiffuse,o),this.gl.uniform1i(this.uniformLightmap,s??0);let b=0,S=[1,1,1,1];m&&(m.mode==="solid"||m.mode==="wireframe"?b=1:m.mode==="solid-faceted"&&(b=2),m.color?S=[...m.color]:m.generateRandomColor&&(S=[1,1,1,1])),this.gl.uniform1i(this.uniformRenderMode,b),this.gl.uniform4f(this.uniformSolidColor,S[0],S[1],S[2],S[3]);let A=Math.min(f.length,Ft);this.gl.uniform1i(this.uniformNumDlights,A);for(let w=0;w<A;w++){let P=f[w];this.gl.uniform3f(this.uniformDlights[w].pos,P.origin.x,P.origin.y,P.origin.z),this.gl.uniform3f(this.uniformDlights[w].color,P.color.x,P.color.y,P.color.z),this.gl.uniform1f(this.uniformDlights[w].intensity,P.intensity)}return p}draw(e,r){if(e.vao.bind(),r&&r.mode==="wireframe"){if(!e.wireframeIndexBuffer){let n=e;n.wireframeIndexBuffer=new fe(this.gl,this.gl.STATIC_DRAW);let i=kr(e.indexData);n.wireframeIndexBuffer.upload(i),n.wireframeIndexCount=i.length}e.wireframeIndexBuffer.bind(),this.gl.drawElements(this.gl.LINES,e.wireframeIndexCount,this.gl.UNSIGNED_SHORT,0)}else e.indexBuffer.bind(),this.gl.drawElements(this.gl.TRIANGLES,e.indexCount,this.gl.UNSIGNED_SHORT,0)}dispose(){this.program.dispose()}};function Wc(t,e){t.depthMask(e.depthWrite),e.blend?(t.enable(t.BLEND),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA)):t.disable(t.BLEND)}var Xc=new Float32Array([-1,-1,1,1,-1,1,1,1,1,-1,-1,1,1,1,1,-1,1,1,-1,-1,-1,-1,1,-1,1,1,-1,-1,-1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1,-1,-1,-1,1,1,-1,1,-1,1,-1,-1,1,1,-1,1,1,1,1,-1,-1,1,1,1,1,-1,1,-1,1,-1,-1,1,1,1,1,1,-1,1,-1,1,1,1,1,1,-1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,-1,1,-1,1,-1,-1,1]),Ks=`#version 300 es
253
+ }`,Gc=[0,255,255,255];function Ws(t=Gc,e=[]){let r=new Float32Array(4);for(let n=0;n<4;n+=1){let i=t[n]??255;if(i===255){r[n]=0;continue}let o=e[i];r[n]=o!==void 0?o:1}return r}function J0(t){return[-(t*.25%1),0]}function Xs(t=Kr,e=0){let r=(t&Ea)!==0,n=(t&Aa)!==0,i=(t&_a)!==0,o=(t&wa)!==0,s=(t&La)!==0,a=o?.33:s?.66:1,c=o||s,l=!c&&!i,d=r?J0(e):[0,0];return{alpha:a,blend:c,depthWrite:l,warp:n,flowOffset:d,sky:i}}var vo=class{constructor(e){this.uniformDlights=[];this.gl=e,this.program=ve.create(e,{vertex:Vs,fragment:Gs},{a_position:0,a_texCoord:1,a_lightmapCoord:2}),this.uniformMvp=this.program.getUniformLocation("u_modelViewProjection"),this.uniformTexScroll=this.program.getUniformLocation("u_texScroll"),this.uniformLmScroll=this.program.getUniformLocation("u_lightmapScroll"),this.uniformLightStyles=this.program.getUniformLocation("u_lightStyleFactors"),this.uniformAlpha=this.program.getUniformLocation("u_alpha"),this.uniformApplyLightmap=this.program.getUniformLocation("u_applyLightmap"),this.uniformWarp=this.program.getUniformLocation("u_warp"),this.uniformDiffuse=this.program.getUniformLocation("u_diffuseMap"),this.uniformLightmap=this.program.getUniformLocation("u_lightmapAtlas"),this.uniformTime=this.program.getUniformLocation("u_time"),this.uniformRenderMode=this.program.getUniformLocation("u_renderMode"),this.uniformSolidColor=this.program.getUniformLocation("u_solidColor"),this.uniformNumDlights=this.program.getUniformLocation("u_numDlights");for(let r=0;r<Ft;r++)this.uniformDlights.push({pos:this.program.getUniformLocation(`u_dlights[${r}].position`),color:this.program.getUniformLocation(`u_dlights[${r}].color`),intensity:this.program.getUniformLocation(`u_dlights[${r}].intensity`)})}bind(e){let{modelViewProjection:r,styleIndices:n=Gc,styleValues:i=[],diffuseSampler:o=0,lightmapSampler:s,surfaceFlags:a=Kr,timeSeconds:c=0,texScroll:l,alpha:d,warp:u,dlights:f=[],renderMode:m}=e,p=Xs(a,c),y=Ws(n,i),h=l?l[0]:p.flowOffset[0],g=l?l[1]:p.flowOffset[1],S=d!==void 0?d:p.alpha,x=u!==void 0?u:p.warp;this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,r),this.gl.uniform2f(this.uniformTexScroll,h,g),this.gl.uniform2f(this.uniformLmScroll,p.flowOffset[0],p.flowOffset[1]),this.gl.uniform4fv(this.uniformLightStyles,y),this.gl.uniform1f(this.uniformAlpha,S);let v=!p.sky&&s!==void 0;this.gl.uniform1i(this.uniformApplyLightmap,v?1:0),this.gl.uniform1i(this.uniformWarp,x?1:0),this.gl.uniform1f(this.uniformTime,c),this.gl.uniform1i(this.uniformDiffuse,o),this.gl.uniform1i(this.uniformLightmap,s??0);let b=0,_=[1,1,1,1];m&&(m.mode==="solid"||m.mode==="wireframe"?b=1:m.mode==="solid-faceted"&&(b=2),m.color?_=[...m.color]:m.generateRandomColor&&(_=[1,1,1,1])),this.gl.uniform1i(this.uniformRenderMode,b),this.gl.uniform4f(this.uniformSolidColor,_[0],_[1],_[2],_[3]);let A=Math.min(f.length,Ft);this.gl.uniform1i(this.uniformNumDlights,A);for(let w=0;w<A;w++){let E=f[w];this.gl.uniform3f(this.uniformDlights[w].pos,E.origin.x,E.origin.y,E.origin.z),this.gl.uniform3f(this.uniformDlights[w].color,E.color.x,E.color.y,E.color.z),this.gl.uniform1f(this.uniformDlights[w].intensity,E.intensity)}return p}draw(e,r){if(e.vao.bind(),r&&r.mode==="wireframe"){if(!e.wireframeIndexBuffer){let n=e;n.wireframeIndexBuffer=new fe(this.gl,this.gl.STATIC_DRAW);let i=kr(e.indexData);n.wireframeIndexBuffer.upload(i),n.wireframeIndexCount=i.length}e.wireframeIndexBuffer.bind(),this.gl.drawElements(this.gl.LINES,e.wireframeIndexCount,this.gl.UNSIGNED_SHORT,0)}else e.indexBuffer.bind(),this.gl.drawElements(this.gl.TRIANGLES,e.indexCount,this.gl.UNSIGNED_SHORT,0)}dispose(){this.program.dispose()}};function Wc(t,e){t.depthMask(e.depthWrite),e.blend?(t.enable(t.BLEND),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA)):t.disable(t.BLEND)}var Xc=new Float32Array([-1,-1,1,1,-1,1,1,1,1,-1,-1,1,1,1,1,-1,1,1,-1,-1,-1,-1,1,-1,1,1,-1,-1,-1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1,-1,-1,-1,1,1,-1,1,-1,1,-1,-1,1,1,-1,1,1,1,1,-1,-1,1,1,1,1,-1,1,-1,1,-1,-1,1,1,1,1,1,-1,1,-1,1,1,1,1,1,-1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,-1,1,-1,1,-1,-1,1]),Ks=`#version 300 es
254
254
  precision highp float;
255
255
 
256
256
  layout(location = 0) in vec3 a_position;
@@ -363,7 +363,7 @@ void main() {
363
363
  }
364
364
 
365
365
  o_color = finalColor;
366
- }`;function J0(t){let e=t.x*t.x+t.y*t.y+t.z*t.z;if(e<=0)return{x:0,y:0,z:1};let r=1/Math.sqrt(e);return{x:t.x*r,y:t.y*r,z:t.z*r}}function qs(t,e,r){return t+(e-t)*r}function qc(t,e,r){return{x:qs(t.x,e.x,r),y:qs(t.y,e.y,r),z:qs(t.z,e.z,r)}}function Z0(t,e,r){return[t/r.skinWidth,1-e/r.skinHeight]}function Qs(t){if(t.glCommands.length===0){let n=[],i=[];return t.triangles.forEach(o=>{let s=n.length;for(let a=0;a<3;a+=1){let c=o.vertexIndices[a],l=o.texCoordIndices[a],d=t.texCoords[l];n.push({vertexIndex:c,texCoord:Z0(d.s,d.t,t.header)})}i.push(s,s+1,s+2)}),{vertices:n,indices:new Uint16Array(i)}}let e=[],r=[];for(let n of t.glCommands){let i=e.length;if(e.push(...n.vertices.map(o=>({vertexIndex:o.vertexIndex,texCoord:[o.s,1-o.t]}))),n.mode==="strip")for(let o=0;o<n.vertices.length-2;o+=1){let s=o%2===0,a=i+o+(s?0:1),c=i+o+(s?1:0),l=i+o+2;r.push(a,c,l)}else for(let o=1;o<n.vertices.length-1;o+=1)r.push(i,i+o,i+o+1)}return{vertices:e,indices:new Uint16Array(r)}}function Js(t,e,r){let{frame0:n,frame1:i,lerp:o}=r,s=t.frames[n],a=t.frames[i];if(!s||!a)throw new Error("Requested MD2 frames are out of range");let c=new Float32Array(e.vertices.length*8);return e.vertices.forEach((l,d)=>{let u=s.vertices[l.vertexIndex],f=a.vertices[l.vertexIndex];if(!u||!f)throw new Error("MD2 vertex index out of range for frame");let m=qc(u.position,f.position,o),p=J0(qc(u.normal,f.normal,o)),y=d*8;c[y]=m.x,c[y+1]=m.y,c[y+2]=m.z,c[y+3]=p.x,c[y+4]=p.y,c[y+5]=p.z,c[y+6]=l.texCoord[0],c[y+7]=l.texCoord[1]}),c}var Mo=class{constructor(e,r,n){this.gl=e,this.geometry=Qs(r),this.vertexBuffer=new Se(e,e.STATIC_DRAW),this.indexBuffer=new fe(e,e.STATIC_DRAW),this.vertexArray=new we(e),this.indexCount=this.geometry.indices.length,this.vertexArray.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:32,offset:0},{index:1,size:3,type:e.FLOAT,stride:32,offset:12},{index:2,size:2,type:e.FLOAT,stride:32,offset:24}],this.vertexBuffer),this.vertexArray.bind(),this.indexBuffer.bind(),this.indexBuffer.upload(this.geometry.indices,e.STATIC_DRAW),this.update(r,n)}update(e,r){let n=Js(e,this.geometry,r);this.vertexBuffer.upload(n,this.gl.STATIC_DRAW)}bind(){this.vertexArray.bind(),this.indexBuffer.bind()}dispose(){this.vertexBuffer.dispose(),this.indexBuffer.dispose(),this.vertexArray.dispose(),this.wireframeIndexBuffer?.dispose()}},_o=class{constructor(e){this.uniformDlights=[];this.gl=e,this.program=ve.create(e,{vertex:$s,fragment:js},{a_position:0,a_normal:1,a_texCoord:2}),this.uniformMvp=this.program.getUniformLocation("u_modelViewProjection"),this.uniformModelMatrix=this.program.getUniformLocation("u_modelMatrix"),this.uniformLightDir=this.program.getUniformLocation("u_lightDir"),this.uniformAmbient=this.program.getUniformLocation("u_ambient"),this.uniformTint=this.program.getUniformLocation("u_tint"),this.uniformDiffuse=this.program.getUniformLocation("u_diffuseMap"),this.uniformRenderMode=this.program.getUniformLocation("u_renderMode"),this.uniformSolidColor=this.program.getUniformLocation("u_solidColor"),this.uniformNumDlights=this.program.getUniformLocation("u_numDlights");for(let r=0;r<Ft;r++)this.uniformDlights.push({pos:this.program.getUniformLocation(`u_dlights[${r}].position`),color:this.program.getUniformLocation(`u_dlights[${r}].color`),intensity:this.program.getUniformLocation(`u_dlights[${r}].intensity`)})}bind(e){let{modelViewProjection:r,modelMatrix:n,lightDirection:i=[0,0,1],ambientLight:o=.2,tint:s=[1,1,1,1],diffuseSampler:a=0,dlights:c=[],renderMode:l}=e,d=new Float32Array(i),u=new Float32Array(s);this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,r),n?this.gl.uniformMatrix4fv(this.uniformModelMatrix,!1,n):this.gl.uniformMatrix4fv(this.uniformModelMatrix,!1,new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])),this.gl.uniform3fv(this.uniformLightDir,d),this.gl.uniform1f(this.uniformAmbient,o),this.gl.uniform4fv(this.uniformTint,u),this.gl.uniform1i(this.uniformDiffuse,a);let f=0,m=[1,1,1,1];l&&(l.mode==="solid"||l.mode==="wireframe"?f=1:l.mode==="solid-faceted"&&(f=2),l.color?m=[...l.color]:l.generateRandomColor),this.gl.uniform1i(this.uniformRenderMode,f),this.gl.uniform4f(this.uniformSolidColor,m[0],m[1],m[2],m[3]);let p=Math.min(c.length,Ft);this.gl.uniform1i(this.uniformNumDlights,p);for(let y=0;y<p;y++){let h=c[y];this.gl.uniform3f(this.uniformDlights[y].pos,h.origin.x,h.origin.y,h.origin.z),this.gl.uniform3f(this.uniformDlights[y].color,h.color.x,h.color.y,h.color.z),this.gl.uniform1f(this.uniformDlights[y].intensity,h.intensity)}}draw(e,r){if(e.vertexArray.bind(),r&&r.mode==="wireframe"){if(!e.wireframeIndexBuffer){e.wireframeIndexBuffer=new fe(this.gl,this.gl.STATIC_DRAW);let n=kr(e.geometry.indices);e.wireframeIndexBuffer.upload(n),e.wireframeIndexCount=n.length}e.wireframeIndexBuffer.bind(),this.gl.drawElements(this.gl.LINES,e.wireframeIndexCount,this.gl.UNSIGNED_SHORT,0)}else e.indexBuffer.bind(),this.gl.drawElements(this.gl.TRIANGLES,e.indexCount,this.gl.UNSIGNED_SHORT,0)}dispose(){this.program.dispose()}};var j=1e-6,Ue=typeof Float32Array<"u"?Float32Array:Array,Zs=Math.random;function Ao(t){return t>=0?Math.round(t):t%.5===0?Math.floor(t):Math.round(t)}var ig=Math.PI/180,og=180/Math.PI;var ae={};qo(ae,{add:()=>Nu,adjoint:()=>au,clone:()=>tu,copy:()=>ru,create:()=>eu,decompose:()=>Au,determinant:()=>cu,equals:()=>Vu,exactEquals:()=>Hu,frob:()=>Ou,fromQuat:()=>Eu,fromQuat2:()=>Su,fromRotation:()=>gu,fromRotationTranslation:()=>Jc,fromRotationTranslationScale:()=>wu,fromRotationTranslationScaleOrigin:()=>Lu,fromScaling:()=>yu,fromTranslation:()=>pu,fromValues:()=>nu,fromXRotation:()=>xu,fromYRotation:()=>bu,fromZRotation:()=>vu,frustum:()=>Iu,getRotation:()=>_u,getScaling:()=>Zc,getTranslation:()=>Mu,identity:()=>jc,invert:()=>su,lookAt:()=>Fu,mul:()=>Gu,multiply:()=>Qc,multiplyScalar:()=>ku,multiplyScalarAndAdd:()=>Uu,ortho:()=>Ru,orthoNO:()=>tl,orthoZO:()=>Tu,perspective:()=>Pu,perspectiveFromFieldOfView:()=>zu,perspectiveNO:()=>el,perspectiveZO:()=>Cu,rotate:()=>uu,rotateX:()=>fu,rotateY:()=>mu,rotateZ:()=>hu,scale:()=>du,set:()=>iu,str:()=>Du,sub:()=>Wu,subtract:()=>rl,targetTo:()=>Bu,translate:()=>lu,transpose:()=>ou});function eu(){var t=new Ue(16);return Ue!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function tu(t){var e=new Ue(16);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function ru(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function nu(t,e,r,n,i,o,s,a,c,l,d,u,f,m,p,y){var h=new Ue(16);return h[0]=t,h[1]=e,h[2]=r,h[3]=n,h[4]=i,h[5]=o,h[6]=s,h[7]=a,h[8]=c,h[9]=l,h[10]=d,h[11]=u,h[12]=f,h[13]=m,h[14]=p,h[15]=y,h}function iu(t,e,r,n,i,o,s,a,c,l,d,u,f,m,p,y,h){return t[0]=e,t[1]=r,t[2]=n,t[3]=i,t[4]=o,t[5]=s,t[6]=a,t[7]=c,t[8]=l,t[9]=d,t[10]=u,t[11]=f,t[12]=m,t[13]=p,t[14]=y,t[15]=h,t}function jc(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function ou(t,e){if(t===e){var r=e[1],n=e[2],i=e[3],o=e[6],s=e[7],a=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=r,t[6]=e[9],t[7]=e[13],t[8]=n,t[9]=o,t[11]=e[14],t[12]=i,t[13]=s,t[14]=a}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t}function su(t,e){var r=e[0],n=e[1],i=e[2],o=e[3],s=e[4],a=e[5],c=e[6],l=e[7],d=e[8],u=e[9],f=e[10],m=e[11],p=e[12],y=e[13],h=e[14],g=e[15],M=r*a-n*s,x=r*c-i*s,v=r*l-o*s,b=n*c-i*a,S=n*l-o*a,A=i*l-o*c,w=d*y-u*p,P=d*h-f*p,L=d*g-m*p,O=u*h-f*y,k=u*g-m*y,W=f*g-m*h,T=M*W-x*k+v*O+b*L-S*P+A*w;return T?(T=1/T,t[0]=(a*W-c*k+l*O)*T,t[1]=(i*k-n*W-o*O)*T,t[2]=(y*A-h*S+g*b)*T,t[3]=(f*S-u*A-m*b)*T,t[4]=(c*L-s*W-l*P)*T,t[5]=(r*W-i*L+o*P)*T,t[6]=(h*v-p*A-g*x)*T,t[7]=(d*A-f*v+m*x)*T,t[8]=(s*k-a*L+l*w)*T,t[9]=(n*L-r*k-o*w)*T,t[10]=(p*S-y*v+g*M)*T,t[11]=(u*v-d*S-m*M)*T,t[12]=(a*P-s*O-c*w)*T,t[13]=(r*O-n*P+i*w)*T,t[14]=(y*x-p*b-h*M)*T,t[15]=(d*b-u*x+f*M)*T,t):null}function au(t,e){var r=e[0],n=e[1],i=e[2],o=e[3],s=e[4],a=e[5],c=e[6],l=e[7],d=e[8],u=e[9],f=e[10],m=e[11],p=e[12],y=e[13],h=e[14],g=e[15],M=r*a-n*s,x=r*c-i*s,v=r*l-o*s,b=n*c-i*a,S=n*l-o*a,A=i*l-o*c,w=d*y-u*p,P=d*h-f*p,L=d*g-m*p,O=u*h-f*y,k=u*g-m*y,W=f*g-m*h;return t[0]=a*W-c*k+l*O,t[1]=i*k-n*W-o*O,t[2]=y*A-h*S+g*b,t[3]=f*S-u*A-m*b,t[4]=c*L-s*W-l*P,t[5]=r*W-i*L+o*P,t[6]=h*v-p*A-g*x,t[7]=d*A-f*v+m*x,t[8]=s*k-a*L+l*w,t[9]=n*L-r*k-o*w,t[10]=p*S-y*v+g*M,t[11]=u*v-d*S-m*M,t[12]=a*P-s*O-c*w,t[13]=r*O-n*P+i*w,t[14]=y*x-p*b-h*M,t[15]=d*b-u*x+f*M,t}function cu(t){var e=t[0],r=t[1],n=t[2],i=t[3],o=t[4],s=t[5],a=t[6],c=t[7],l=t[8],d=t[9],u=t[10],f=t[11],m=t[12],p=t[13],y=t[14],h=t[15],g=e*s-r*o,M=e*a-n*o,x=r*a-n*s,v=l*p-d*m,b=l*y-u*m,S=d*y-u*p,A=e*S-r*b+n*v,w=o*S-s*b+a*v,P=l*x-d*M+u*g,L=m*x-p*M+y*g;return c*A-i*w+h*P-f*L}function Qc(t,e,r){var n=e[0],i=e[1],o=e[2],s=e[3],a=e[4],c=e[5],l=e[6],d=e[7],u=e[8],f=e[9],m=e[10],p=e[11],y=e[12],h=e[13],g=e[14],M=e[15],x=r[0],v=r[1],b=r[2],S=r[3];return t[0]=x*n+v*a+b*u+S*y,t[1]=x*i+v*c+b*f+S*h,t[2]=x*o+v*l+b*m+S*g,t[3]=x*s+v*d+b*p+S*M,x=r[4],v=r[5],b=r[6],S=r[7],t[4]=x*n+v*a+b*u+S*y,t[5]=x*i+v*c+b*f+S*h,t[6]=x*o+v*l+b*m+S*g,t[7]=x*s+v*d+b*p+S*M,x=r[8],v=r[9],b=r[10],S=r[11],t[8]=x*n+v*a+b*u+S*y,t[9]=x*i+v*c+b*f+S*h,t[10]=x*o+v*l+b*m+S*g,t[11]=x*s+v*d+b*p+S*M,x=r[12],v=r[13],b=r[14],S=r[15],t[12]=x*n+v*a+b*u+S*y,t[13]=x*i+v*c+b*f+S*h,t[14]=x*o+v*l+b*m+S*g,t[15]=x*s+v*d+b*p+S*M,t}function lu(t,e,r){var n=r[0],i=r[1],o=r[2],s,a,c,l,d,u,f,m,p,y,h,g;return e===t?(t[12]=e[0]*n+e[4]*i+e[8]*o+e[12],t[13]=e[1]*n+e[5]*i+e[9]*o+e[13],t[14]=e[2]*n+e[6]*i+e[10]*o+e[14],t[15]=e[3]*n+e[7]*i+e[11]*o+e[15]):(s=e[0],a=e[1],c=e[2],l=e[3],d=e[4],u=e[5],f=e[6],m=e[7],p=e[8],y=e[9],h=e[10],g=e[11],t[0]=s,t[1]=a,t[2]=c,t[3]=l,t[4]=d,t[5]=u,t[6]=f,t[7]=m,t[8]=p,t[9]=y,t[10]=h,t[11]=g,t[12]=s*n+d*i+p*o+e[12],t[13]=a*n+u*i+y*o+e[13],t[14]=c*n+f*i+h*o+e[14],t[15]=l*n+m*i+g*o+e[15]),t}function du(t,e,r){var n=r[0],i=r[1],o=r[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*o,t[9]=e[9]*o,t[10]=e[10]*o,t[11]=e[11]*o,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function uu(t,e,r,n){var i=n[0],o=n[1],s=n[2],a=Math.sqrt(i*i+o*o+s*s),c,l,d,u,f,m,p,y,h,g,M,x,v,b,S,A,w,P,L,O,k,W,T,J;return a<j?null:(a=1/a,i*=a,o*=a,s*=a,c=Math.sin(r),l=Math.cos(r),d=1-l,u=e[0],f=e[1],m=e[2],p=e[3],y=e[4],h=e[5],g=e[6],M=e[7],x=e[8],v=e[9],b=e[10],S=e[11],A=i*i*d+l,w=o*i*d+s*c,P=s*i*d-o*c,L=i*o*d-s*c,O=o*o*d+l,k=s*o*d+i*c,W=i*s*d+o*c,T=o*s*d-i*c,J=s*s*d+l,t[0]=u*A+y*w+x*P,t[1]=f*A+h*w+v*P,t[2]=m*A+g*w+b*P,t[3]=p*A+M*w+S*P,t[4]=u*L+y*O+x*k,t[5]=f*L+h*O+v*k,t[6]=m*L+g*O+b*k,t[7]=p*L+M*O+S*k,t[8]=u*W+y*T+x*J,t[9]=f*W+h*T+v*J,t[10]=m*W+g*T+b*J,t[11]=p*W+M*T+S*J,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}function fu(t,e,r){var n=Math.sin(r),i=Math.cos(r),o=e[4],s=e[5],a=e[6],c=e[7],l=e[8],d=e[9],u=e[10],f=e[11];return e!==t&&(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[4]=o*i+l*n,t[5]=s*i+d*n,t[6]=a*i+u*n,t[7]=c*i+f*n,t[8]=l*i-o*n,t[9]=d*i-s*n,t[10]=u*i-a*n,t[11]=f*i-c*n,t}function mu(t,e,r){var n=Math.sin(r),i=Math.cos(r),o=e[0],s=e[1],a=e[2],c=e[3],l=e[8],d=e[9],u=e[10],f=e[11];return e!==t&&(t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=o*i-l*n,t[1]=s*i-d*n,t[2]=a*i-u*n,t[3]=c*i-f*n,t[8]=o*n+l*i,t[9]=s*n+d*i,t[10]=a*n+u*i,t[11]=c*n+f*i,t}function hu(t,e,r){var n=Math.sin(r),i=Math.cos(r),o=e[0],s=e[1],a=e[2],c=e[3],l=e[4],d=e[5],u=e[6],f=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=o*i+l*n,t[1]=s*i+d*n,t[2]=a*i+u*n,t[3]=c*i+f*n,t[4]=l*i-o*n,t[5]=d*i-s*n,t[6]=u*i-a*n,t[7]=f*i-c*n,t}function pu(t,e){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=e[0],t[13]=e[1],t[14]=e[2],t[15]=1,t}function yu(t,e){return t[0]=e[0],t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=e[1],t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=e[2],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function gu(t,e,r){var n=r[0],i=r[1],o=r[2],s=Math.sqrt(n*n+i*i+o*o),a,c,l;return s<j?null:(s=1/s,n*=s,i*=s,o*=s,a=Math.sin(e),c=Math.cos(e),l=1-c,t[0]=n*n*l+c,t[1]=i*n*l+o*a,t[2]=o*n*l-i*a,t[3]=0,t[4]=n*i*l-o*a,t[5]=i*i*l+c,t[6]=o*i*l+n*a,t[7]=0,t[8]=n*o*l+i*a,t[9]=i*o*l-n*a,t[10]=o*o*l+c,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t)}function xu(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=n,t[6]=r,t[7]=0,t[8]=0,t[9]=-r,t[10]=n,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function bu(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=n,t[1]=0,t[2]=-r,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=r,t[9]=0,t[10]=n,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function vu(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=n,t[1]=r,t[2]=0,t[3]=0,t[4]=-r,t[5]=n,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Jc(t,e,r){var n=e[0],i=e[1],o=e[2],s=e[3],a=n+n,c=i+i,l=o+o,d=n*a,u=n*c,f=n*l,m=i*c,p=i*l,y=o*l,h=s*a,g=s*c,M=s*l;return t[0]=1-(m+y),t[1]=u+M,t[2]=f-g,t[3]=0,t[4]=u-M,t[5]=1-(d+y),t[6]=p+h,t[7]=0,t[8]=f+g,t[9]=p-h,t[10]=1-(d+m),t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function Su(t,e){var r=new Ue(3),n=-e[0],i=-e[1],o=-e[2],s=e[3],a=e[4],c=e[5],l=e[6],d=e[7],u=n*n+i*i+o*o+s*s;return u>0?(r[0]=(a*s+d*n+c*o-l*i)*2/u,r[1]=(c*s+d*i+l*n-a*o)*2/u,r[2]=(l*s+d*o+a*i-c*n)*2/u):(r[0]=(a*s+d*n+c*o-l*i)*2,r[1]=(c*s+d*i+l*n-a*o)*2,r[2]=(l*s+d*o+a*i-c*n)*2),Jc(t,e,r),t}function Mu(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}function Zc(t,e){var r=e[0],n=e[1],i=e[2],o=e[4],s=e[5],a=e[6],c=e[8],l=e[9],d=e[10];return t[0]=Math.sqrt(r*r+n*n+i*i),t[1]=Math.sqrt(o*o+s*s+a*a),t[2]=Math.sqrt(c*c+l*l+d*d),t}function _u(t,e){var r=new Ue(3);Zc(r,e);var n=1/r[0],i=1/r[1],o=1/r[2],s=e[0]*n,a=e[1]*i,c=e[2]*o,l=e[4]*n,d=e[5]*i,u=e[6]*o,f=e[8]*n,m=e[9]*i,p=e[10]*o,y=s+d+p,h=0;return y>0?(h=Math.sqrt(y+1)*2,t[3]=.25*h,t[0]=(u-m)/h,t[1]=(f-c)/h,t[2]=(a-l)/h):s>d&&s>p?(h=Math.sqrt(1+s-d-p)*2,t[3]=(u-m)/h,t[0]=.25*h,t[1]=(a+l)/h,t[2]=(f+c)/h):d>p?(h=Math.sqrt(1+d-s-p)*2,t[3]=(f-c)/h,t[0]=(a+l)/h,t[1]=.25*h,t[2]=(u+m)/h):(h=Math.sqrt(1+p-s-d)*2,t[3]=(a-l)/h,t[0]=(f+c)/h,t[1]=(u+m)/h,t[2]=.25*h),t}function Au(t,e,r,n){e[0]=n[12],e[1]=n[13],e[2]=n[14];var i=n[0],o=n[1],s=n[2],a=n[4],c=n[5],l=n[6],d=n[8],u=n[9],f=n[10];r[0]=Math.sqrt(i*i+o*o+s*s),r[1]=Math.sqrt(a*a+c*c+l*l),r[2]=Math.sqrt(d*d+u*u+f*f);var m=1/r[0],p=1/r[1],y=1/r[2],h=i*m,g=o*p,M=s*y,x=a*m,v=c*p,b=l*y,S=d*m,A=u*p,w=f*y,P=h+v+w,L=0;return P>0?(L=Math.sqrt(P+1)*2,t[3]=.25*L,t[0]=(b-A)/L,t[1]=(S-M)/L,t[2]=(g-x)/L):h>v&&h>w?(L=Math.sqrt(1+h-v-w)*2,t[3]=(b-A)/L,t[0]=.25*L,t[1]=(g+x)/L,t[2]=(S+M)/L):v>w?(L=Math.sqrt(1+v-h-w)*2,t[3]=(S-M)/L,t[0]=(g+x)/L,t[1]=.25*L,t[2]=(b+A)/L):(L=Math.sqrt(1+w-h-v)*2,t[3]=(g-x)/L,t[0]=(S+M)/L,t[1]=(b+A)/L,t[2]=.25*L),t}function wu(t,e,r,n){var i=e[0],o=e[1],s=e[2],a=e[3],c=i+i,l=o+o,d=s+s,u=i*c,f=i*l,m=i*d,p=o*l,y=o*d,h=s*d,g=a*c,M=a*l,x=a*d,v=n[0],b=n[1],S=n[2];return t[0]=(1-(p+h))*v,t[1]=(f+x)*v,t[2]=(m-M)*v,t[3]=0,t[4]=(f-x)*b,t[5]=(1-(u+h))*b,t[6]=(y+g)*b,t[7]=0,t[8]=(m+M)*S,t[9]=(y-g)*S,t[10]=(1-(u+p))*S,t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function Lu(t,e,r,n,i){var o=e[0],s=e[1],a=e[2],c=e[3],l=o+o,d=s+s,u=a+a,f=o*l,m=o*d,p=o*u,y=s*d,h=s*u,g=a*u,M=c*l,x=c*d,v=c*u,b=n[0],S=n[1],A=n[2],w=i[0],P=i[1],L=i[2],O=(1-(y+g))*b,k=(m+v)*b,W=(p-x)*b,T=(m-v)*S,J=(1-(f+g))*S,Me=(h+M)*S,Bt=(p+x)*A,oi=(h-M)*A,Vr=(1-(f+y))*A;return t[0]=O,t[1]=k,t[2]=W,t[3]=0,t[4]=T,t[5]=J,t[6]=Me,t[7]=0,t[8]=Bt,t[9]=oi,t[10]=Vr,t[11]=0,t[12]=r[0]+w-(O*w+T*P+Bt*L),t[13]=r[1]+P-(k*w+J*P+oi*L),t[14]=r[2]+L-(W*w+Me*P+Vr*L),t[15]=1,t}function Eu(t,e){var r=e[0],n=e[1],i=e[2],o=e[3],s=r+r,a=n+n,c=i+i,l=r*s,d=n*s,u=n*a,f=i*s,m=i*a,p=i*c,y=o*s,h=o*a,g=o*c;return t[0]=1-u-p,t[1]=d+g,t[2]=f-h,t[3]=0,t[4]=d-g,t[5]=1-l-p,t[6]=m+y,t[7]=0,t[8]=f+h,t[9]=m-y,t[10]=1-l-u,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Iu(t,e,r,n,i,o,s){var a=1/(r-e),c=1/(i-n),l=1/(o-s);return t[0]=o*2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=o*2*c,t[6]=0,t[7]=0,t[8]=(r+e)*a,t[9]=(i+n)*c,t[10]=(s+o)*l,t[11]=-1,t[12]=0,t[13]=0,t[14]=s*o*2*l,t[15]=0,t}function el(t,e,r,n,i){var o=1/Math.tan(e/2);if(t[0]=o/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=o,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,i!=null&&i!==1/0){var s=1/(n-i);t[10]=(i+n)*s,t[14]=2*i*n*s}else t[10]=-1,t[14]=-2*n;return t}var Pu=el;function Cu(t,e,r,n,i){var o=1/Math.tan(e/2);if(t[0]=o/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=o,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,i!=null&&i!==1/0){var s=1/(n-i);t[10]=i*s,t[14]=i*n*s}else t[10]=-1,t[14]=-n;return t}function zu(t,e,r,n){var i=Math.tan(e.upDegrees*Math.PI/180),o=Math.tan(e.downDegrees*Math.PI/180),s=Math.tan(e.leftDegrees*Math.PI/180),a=Math.tan(e.rightDegrees*Math.PI/180),c=2/(s+a),l=2/(i+o);return t[0]=c,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=l,t[6]=0,t[7]=0,t[8]=-((s-a)*c*.5),t[9]=(i-o)*l*.5,t[10]=n/(r-n),t[11]=-1,t[12]=0,t[13]=0,t[14]=n*r/(r-n),t[15]=0,t}function tl(t,e,r,n,i,o,s){var a=1/(e-r),c=1/(n-i),l=1/(o-s);return t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*c,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*l,t[11]=0,t[12]=(e+r)*a,t[13]=(i+n)*c,t[14]=(s+o)*l,t[15]=1,t}var Ru=tl;function Tu(t,e,r,n,i,o,s){var a=1/(e-r),c=1/(n-i),l=1/(o-s);return t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*c,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=l,t[11]=0,t[12]=(e+r)*a,t[13]=(i+n)*c,t[14]=o*l,t[15]=1,t}function Fu(t,e,r,n){var i,o,s,a,c,l,d,u,f,m,p=e[0],y=e[1],h=e[2],g=n[0],M=n[1],x=n[2],v=r[0],b=r[1],S=r[2];return Math.abs(p-v)<j&&Math.abs(y-b)<j&&Math.abs(h-S)<j?jc(t):(d=p-v,u=y-b,f=h-S,m=1/Math.sqrt(d*d+u*u+f*f),d*=m,u*=m,f*=m,i=M*f-x*u,o=x*d-g*f,s=g*u-M*d,m=Math.sqrt(i*i+o*o+s*s),m?(m=1/m,i*=m,o*=m,s*=m):(i=0,o=0,s=0),a=u*s-f*o,c=f*i-d*s,l=d*o-u*i,m=Math.sqrt(a*a+c*c+l*l),m?(m=1/m,a*=m,c*=m,l*=m):(a=0,c=0,l=0),t[0]=i,t[1]=a,t[2]=d,t[3]=0,t[4]=o,t[5]=c,t[6]=u,t[7]=0,t[8]=s,t[9]=l,t[10]=f,t[11]=0,t[12]=-(i*p+o*y+s*h),t[13]=-(a*p+c*y+l*h),t[14]=-(d*p+u*y+f*h),t[15]=1,t)}function Bu(t,e,r,n){var i=e[0],o=e[1],s=e[2],a=n[0],c=n[1],l=n[2],d=i-r[0],u=o-r[1],f=s-r[2],m=d*d+u*u+f*f;m>0&&(m=1/Math.sqrt(m),d*=m,u*=m,f*=m);var p=c*f-l*u,y=l*d-a*f,h=a*u-c*d;return m=p*p+y*y+h*h,m>0&&(m=1/Math.sqrt(m),p*=m,y*=m,h*=m),t[0]=p,t[1]=y,t[2]=h,t[3]=0,t[4]=u*h-f*y,t[5]=f*p-d*h,t[6]=d*y-u*p,t[7]=0,t[8]=d,t[9]=u,t[10]=f,t[11]=0,t[12]=i,t[13]=o,t[14]=s,t[15]=1,t}function Du(t){return"mat4("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+", "+t[6]+", "+t[7]+", "+t[8]+", "+t[9]+", "+t[10]+", "+t[11]+", "+t[12]+", "+t[13]+", "+t[14]+", "+t[15]+")"}function Ou(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]+t[3]*t[3]+t[4]*t[4]+t[5]*t[5]+t[6]*t[6]+t[7]*t[7]+t[8]*t[8]+t[9]*t[9]+t[10]*t[10]+t[11]*t[11]+t[12]*t[12]+t[13]*t[13]+t[14]*t[14]+t[15]*t[15])}function Nu(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t[3]=e[3]+r[3],t[4]=e[4]+r[4],t[5]=e[5]+r[5],t[6]=e[6]+r[6],t[7]=e[7]+r[7],t[8]=e[8]+r[8],t[9]=e[9]+r[9],t[10]=e[10]+r[10],t[11]=e[11]+r[11],t[12]=e[12]+r[12],t[13]=e[13]+r[13],t[14]=e[14]+r[14],t[15]=e[15]+r[15],t}function rl(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t[3]=e[3]-r[3],t[4]=e[4]-r[4],t[5]=e[5]-r[5],t[6]=e[6]-r[6],t[7]=e[7]-r[7],t[8]=e[8]-r[8],t[9]=e[9]-r[9],t[10]=e[10]-r[10],t[11]=e[11]-r[11],t[12]=e[12]-r[12],t[13]=e[13]-r[13],t[14]=e[14]-r[14],t[15]=e[15]-r[15],t}function ku(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t[4]=e[4]*r,t[5]=e[5]*r,t[6]=e[6]*r,t[7]=e[7]*r,t[8]=e[8]*r,t[9]=e[9]*r,t[10]=e[10]*r,t[11]=e[11]*r,t[12]=e[12]*r,t[13]=e[13]*r,t[14]=e[14]*r,t[15]=e[15]*r,t}function Uu(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t[3]=e[3]+r[3]*n,t[4]=e[4]+r[4]*n,t[5]=e[5]+r[5]*n,t[6]=e[6]+r[6]*n,t[7]=e[7]+r[7]*n,t[8]=e[8]+r[8]*n,t[9]=e[9]+r[9]*n,t[10]=e[10]+r[10]*n,t[11]=e[11]+r[11]*n,t[12]=e[12]+r[12]*n,t[13]=e[13]+r[13]*n,t[14]=e[14]+r[14]*n,t[15]=e[15]+r[15]*n,t}function Hu(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]&&t[3]===e[3]&&t[4]===e[4]&&t[5]===e[5]&&t[6]===e[6]&&t[7]===e[7]&&t[8]===e[8]&&t[9]===e[9]&&t[10]===e[10]&&t[11]===e[11]&&t[12]===e[12]&&t[13]===e[13]&&t[14]===e[14]&&t[15]===e[15]}function Vu(t,e){var r=t[0],n=t[1],i=t[2],o=t[3],s=t[4],a=t[5],c=t[6],l=t[7],d=t[8],u=t[9],f=t[10],m=t[11],p=t[12],y=t[13],h=t[14],g=t[15],M=e[0],x=e[1],v=e[2],b=e[3],S=e[4],A=e[5],w=e[6],P=e[7],L=e[8],O=e[9],k=e[10],W=e[11],T=e[12],J=e[13],Me=e[14],Bt=e[15];return Math.abs(r-M)<=j*Math.max(1,Math.abs(r),Math.abs(M))&&Math.abs(n-x)<=j*Math.max(1,Math.abs(n),Math.abs(x))&&Math.abs(i-v)<=j*Math.max(1,Math.abs(i),Math.abs(v))&&Math.abs(o-b)<=j*Math.max(1,Math.abs(o),Math.abs(b))&&Math.abs(s-S)<=j*Math.max(1,Math.abs(s),Math.abs(S))&&Math.abs(a-A)<=j*Math.max(1,Math.abs(a),Math.abs(A))&&Math.abs(c-w)<=j*Math.max(1,Math.abs(c),Math.abs(w))&&Math.abs(l-P)<=j*Math.max(1,Math.abs(l),Math.abs(P))&&Math.abs(d-L)<=j*Math.max(1,Math.abs(d),Math.abs(L))&&Math.abs(u-O)<=j*Math.max(1,Math.abs(u),Math.abs(O))&&Math.abs(f-k)<=j*Math.max(1,Math.abs(f),Math.abs(k))&&Math.abs(m-W)<=j*Math.max(1,Math.abs(m),Math.abs(W))&&Math.abs(p-T)<=j*Math.max(1,Math.abs(p),Math.abs(T))&&Math.abs(y-J)<=j*Math.max(1,Math.abs(y),Math.abs(J))&&Math.abs(h-Me)<=j*Math.max(1,Math.abs(h),Math.abs(Me))&&Math.abs(g-Bt)<=j*Math.max(1,Math.abs(g),Math.abs(Bt))}var Gu=Qc,Wu=rl;var se={};qo(se,{add:()=>$u,angle:()=>bf,bezier:()=>uf,ceil:()=>ju,clone:()=>Xu,copy:()=>Yu,create:()=>nl,cross:()=>af,dist:()=>Ef,distance:()=>cl,div:()=>Lf,divide:()=>al,dot:()=>ea,equals:()=>_f,exactEquals:()=>Mf,floor:()=>Qu,forEach:()=>zf,fromValues:()=>Ku,hermite:()=>df,inverse:()=>of,len:()=>Pf,length:()=>il,lerp:()=>cf,max:()=>Zu,min:()=>Ju,mul:()=>wf,multiply:()=>sl,negate:()=>nf,normalize:()=>sf,random:()=>ff,rotateX:()=>yf,rotateY:()=>gf,rotateZ:()=>xf,round:()=>ef,scale:()=>tf,scaleAndAdd:()=>rf,set:()=>qu,slerp:()=>lf,sqrDist:()=>If,sqrLen:()=>Cf,squaredDistance:()=>ll,squaredLength:()=>dl,str:()=>Sf,sub:()=>Af,subtract:()=>ol,transformMat3:()=>hf,transformMat4:()=>mf,transformQuat:()=>pf,zero:()=>vf});function nl(){var t=new Ue(3);return Ue!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function Xu(t){var e=new Ue(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function il(t){var e=t[0],r=t[1],n=t[2];return Math.sqrt(e*e+r*r+n*n)}function Ku(t,e,r){var n=new Ue(3);return n[0]=t,n[1]=e,n[2]=r,n}function Yu(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function qu(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t}function $u(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t}function ol(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t}function sl(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t}function al(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t}function ju(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t[2]=Math.ceil(e[2]),t}function Qu(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t[2]=Math.floor(e[2]),t}function Ju(t,e,r){return t[0]=Math.min(e[0],r[0]),t[1]=Math.min(e[1],r[1]),t[2]=Math.min(e[2],r[2]),t}function Zu(t,e,r){return t[0]=Math.max(e[0],r[0]),t[1]=Math.max(e[1],r[1]),t[2]=Math.max(e[2],r[2]),t}function ef(t,e){return t[0]=Ao(e[0]),t[1]=Ao(e[1]),t[2]=Ao(e[2]),t}function tf(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t}function rf(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t}function cl(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2];return Math.sqrt(r*r+n*n+i*i)}function ll(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2];return r*r+n*n+i*i}function dl(t){var e=t[0],r=t[1],n=t[2];return e*e+r*r+n*n}function nf(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t}function of(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t}function sf(t,e){var r=e[0],n=e[1],i=e[2],o=r*r+n*n+i*i;return o>0&&(o=1/Math.sqrt(o)),t[0]=e[0]*o,t[1]=e[1]*o,t[2]=e[2]*o,t}function ea(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function af(t,e,r){var n=e[0],i=e[1],o=e[2],s=r[0],a=r[1],c=r[2];return t[0]=i*c-o*a,t[1]=o*s-n*c,t[2]=n*a-i*s,t}function cf(t,e,r,n){var i=e[0],o=e[1],s=e[2];return t[0]=i+n*(r[0]-i),t[1]=o+n*(r[1]-o),t[2]=s+n*(r[2]-s),t}function lf(t,e,r,n){var i=Math.acos(Math.min(Math.max(ea(e,r),-1),1)),o=Math.sin(i),s=Math.sin((1-n)*i)/o,a=Math.sin(n*i)/o;return t[0]=s*e[0]+a*r[0],t[1]=s*e[1]+a*r[1],t[2]=s*e[2]+a*r[2],t}function df(t,e,r,n,i,o){var s=o*o,a=s*(2*o-3)+1,c=s*(o-2)+o,l=s*(o-1),d=s*(3-2*o);return t[0]=e[0]*a+r[0]*c+n[0]*l+i[0]*d,t[1]=e[1]*a+r[1]*c+n[1]*l+i[1]*d,t[2]=e[2]*a+r[2]*c+n[2]*l+i[2]*d,t}function uf(t,e,r,n,i,o){var s=1-o,a=s*s,c=o*o,l=a*s,d=3*o*a,u=3*c*s,f=c*o;return t[0]=e[0]*l+r[0]*d+n[0]*u+i[0]*f,t[1]=e[1]*l+r[1]*d+n[1]*u+i[1]*f,t[2]=e[2]*l+r[2]*d+n[2]*u+i[2]*f,t}function ff(t,e){e=e===void 0?1:e;var r=Zs()*2*Math.PI,n=Zs()*2-1,i=Math.sqrt(1-n*n)*e;return t[0]=Math.cos(r)*i,t[1]=Math.sin(r)*i,t[2]=n*e,t}function mf(t,e,r){var n=e[0],i=e[1],o=e[2],s=r[3]*n+r[7]*i+r[11]*o+r[15];return s=s||1,t[0]=(r[0]*n+r[4]*i+r[8]*o+r[12])/s,t[1]=(r[1]*n+r[5]*i+r[9]*o+r[13])/s,t[2]=(r[2]*n+r[6]*i+r[10]*o+r[14])/s,t}function hf(t,e,r){var n=e[0],i=e[1],o=e[2];return t[0]=n*r[0]+i*r[3]+o*r[6],t[1]=n*r[1]+i*r[4]+o*r[7],t[2]=n*r[2]+i*r[5]+o*r[8],t}function pf(t,e,r){var n=r[0],i=r[1],o=r[2],s=r[3],a=e[0],c=e[1],l=e[2],d=i*l-o*c,u=o*a-n*l,f=n*c-i*a;return d=d+d,u=u+u,f=f+f,t[0]=a+s*d+i*f-o*u,t[1]=c+s*u+o*d-n*f,t[2]=l+s*f+n*u-i*d,t}function yf(t,e,r,n){var i=[],o=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],o[0]=i[0],o[1]=i[1]*Math.cos(n)-i[2]*Math.sin(n),o[2]=i[1]*Math.sin(n)+i[2]*Math.cos(n),t[0]=o[0]+r[0],t[1]=o[1]+r[1],t[2]=o[2]+r[2],t}function gf(t,e,r,n){var i=[],o=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],o[0]=i[2]*Math.sin(n)+i[0]*Math.cos(n),o[1]=i[1],o[2]=i[2]*Math.cos(n)-i[0]*Math.sin(n),t[0]=o[0]+r[0],t[1]=o[1]+r[1],t[2]=o[2]+r[2],t}function xf(t,e,r,n){var i=[],o=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],o[0]=i[0]*Math.cos(n)-i[1]*Math.sin(n),o[1]=i[0]*Math.sin(n)+i[1]*Math.cos(n),o[2]=i[2],t[0]=o[0]+r[0],t[1]=o[1]+r[1],t[2]=o[2]+r[2],t}function bf(t,e){var r=t[0],n=t[1],i=t[2],o=e[0],s=e[1],a=e[2],c=Math.sqrt((r*r+n*n+i*i)*(o*o+s*s+a*a)),l=c&&ea(t,e)/c;return Math.acos(Math.min(Math.max(l,-1),1))}function vf(t){return t[0]=0,t[1]=0,t[2]=0,t}function Sf(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"}function Mf(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]}function _f(t,e){var r=t[0],n=t[1],i=t[2],o=e[0],s=e[1],a=e[2];return Math.abs(r-o)<=j*Math.max(1,Math.abs(r),Math.abs(o))&&Math.abs(n-s)<=j*Math.max(1,Math.abs(n),Math.abs(s))&&Math.abs(i-a)<=j*Math.max(1,Math.abs(i),Math.abs(a))}var Af=ol,wf=sl,Lf=al,Ef=cl,If=ll,Pf=il,Cf=dl,zf=(function(){var t=nl();return function(e,r,n,i,o,s){var a,c;for(r||(r=3),n||(n=0),i?c=Math.min(i*r+n,e.length):c=e.length,a=n;a<c;a+=r)t[0]=e[a],t[1]=e[a+1],t[2]=e[a+2],o(t,t,s),e[a]=t[0],e[a+1]=t[1],e[a+2]=t[2];return e}})();var wo=class{constructor(){this._position=se.create();this._angles=se.create();this._bobAngles=se.create();this._bobOffset=se.create();this._kickAngles=se.create();this._rollAngle=0;this._fov=90;this._aspect=1;this._near=.1;this._far=1e3;this._viewMatrix=ae.create();this._projectionMatrix=ae.create();this._viewProjectionMatrix=ae.create();this._dirty=!0}get position(){return this._position}set position(e){se.copy(this._position,e),this._dirty=!0}get angles(){return this._angles}set angles(e){se.copy(this._angles,e),this._dirty=!0}get bobAngles(){return this._bobAngles}set bobAngles(e){se.copy(this._bobAngles,e),this._dirty=!0}get kickAngles(){return this._kickAngles}set kickAngles(e){se.copy(this._kickAngles,e),this._dirty=!0}get bobOffset(){return this._bobOffset}set bobOffset(e){se.copy(this._bobOffset,e),this._dirty=!0}get rollAngle(){return this._rollAngle}set rollAngle(e){this._rollAngle=e,this._dirty=!0}get fov(){return this._fov}set fov(e){this._fov=e,this._dirty=!0}get aspect(){return this._aspect}set aspect(e){this._aspect=e,this._dirty=!0}get viewMatrix(){return this.updateMatrices(),this._viewMatrix}get projectionMatrix(){return this.updateMatrices(),this._projectionMatrix}get viewProjectionMatrix(){return this.updateMatrices(),this._viewProjectionMatrix}getViewmodelProjectionMatrix(e){let r=ae.create();return ae.perspective(r,e*sr,this._aspect,this._near,this._far),r}updateMatrices(){if(!this._dirty)return;ae.perspective(this._projectionMatrix,this._fov*sr,this._aspect,this._near,this._far);let e=ae.fromValues(0,-1,0,0,0,0,1,0,-1,0,0,0,0,0,0,1),r=this._angles[0]+this._bobAngles[0]+this._kickAngles[0],n=this._angles[1]+this._bobAngles[1]+this._kickAngles[1],i=this._angles[2]+this._bobAngles[2]+this._kickAngles[2]+this._rollAngle,o=r*sr,s=n*sr,a=i*sr,c=ae.create();ae.identity(c),ae.rotateZ(c,c,-s),ae.rotateY(c,c,-o),ae.rotateX(c,c,-a);let l=ae.create();ae.multiply(l,e,c);let d=se.add(se.create(),this._position,this._bobOffset),u=se.negate(se.create(),d),f=se.create();se.transformMat4(f,u,c);let m=se.fromValues(f[1]||0,f[2]||0,f[0]||0);ae.copy(this._viewMatrix,l),this._viewMatrix[12]=m[0],this._viewMatrix[13]=m[1],this._viewMatrix[14]=m[2],ae.multiply(this._viewProjectionMatrix,this._projectionMatrix,this._viewMatrix),this._dirty=!1}};var Rf=[.2,.2,.2],Tf={x:0,y:0,z:1},Ff=[.8,.8,.8];function ta(t,e,r){return t+(e-t)*r}function Hr(t,e,r){return{x:ta(t.x,e.x,r),y:ta(t.y,e.y,r),z:ta(t.z,e.z,r)}}function Ur(t){return t<0?0:t>1?1:t}function ra(t){let e=[],r=[];for(let n of t.triangles){let i=e.length,[o,s,a]=n.indices,c=t.texCoords[o],l=t.texCoords[s],d=t.texCoords[a];if(!c||!l||!d)throw new Error(`Missing texCoord for triangle in surface ${t.name}`);e.push({vertexIndex:o,texCoord:[c.s,1-c.t]},{vertexIndex:s,texCoord:[l.s,1-l.t]},{vertexIndex:a,texCoord:[d.s,1-d.t]}),r.push(i,i+1,i+2)}return{vertices:e,indices:new Uint16Array(r)}}function Bf(t,e,r){let n=r?.ambient??Rf,i=r?.directional??{direction:Tf,color:Ff},o=He(t),s=He(i.direction),a=Ur(o.x*s.x+o.y*s.y+o.z*s.z),c=n[0]+i.color[0]*a,l=n[1]+i.color[1]*a,d=n[2]+i.color[2]*a;if(r?.dynamicLights){let u=r.modelMatrix?va(r.modelMatrix,e):e;for(let f of r.dynamicLights){let m=u.x-f.origin.x,p=u.y-f.origin.y,y=u.z-f.origin.z,h=m*m+p*p+y*y,g=f.radius*f.radius;if(h<g&&g>0){let M=1-Math.sqrt(h)/f.radius,x=Math.sqrt(h),v=x>0?Ur(-(m*o.x+p*o.y+y*o.z)/x):0,b=Ur(M*v);c+=f.color[0]*b,l+=f.color[1]*b,d+=f.color[2]*b}}}return[Ur(c),Ur(l),Ur(d)]}function na(t,e,r,n){let i=t.vertices[r.frame0],o=t.vertices[r.frame1];if(!i||!o)throw new Error("Requested MD3 frames are out of range");let s=new Float32Array(e.vertices.length*12);return e.vertices.forEach((a,c)=>{let l=i[a.vertexIndex],d=o[a.vertexIndex];if(!l||!d)throw new Error(`Vertex index ${a.vertexIndex} missing for frame`);let u=Hr(l.position,d.position,r.lerp),f=He(Hr(l.normal,d.normal,r.lerp)),m=Bf(f,u,n),p=c*12;s[p]=u.x,s[p+1]=u.y,s[p+2]=u.z,s[p+3]=f.x,s[p+4]=f.y,s[p+5]=f.z,s[p+6]=a.texCoord[0],s[p+7]=a.texCoord[1],s[p+8]=m[0],s[p+9]=m[1],s[p+10]=m[2],s[p+11]=1}),s}function ul(t,e,r){let n=t.tags[0];if(!n)return null;let i=n.findIndex(y=>y.name===r);if(i===-1)return null;let o=t.tags[e.frame0]?.[i],s=t.tags[e.frame1]?.[i];if(!o||!s)throw new Error(`Tag ${r} is missing for one of the interpolated frames`);let a=Hr(o.origin,s.origin,e.lerp),c=He(Hr(o.axis[0],s.axis[0],e.lerp)),l=He(Hr(o.axis[1],s.axis[1],e.lerp)),d=He(Hr(o.axis[2],s.axis[2],e.lerp)),u=c,f=He({x:l.x-u.x*(u.x*l.x+u.y*l.y+u.z*l.z),y:l.y-u.y*(u.x*l.x+u.y*l.y+u.z*l.z),z:l.z-u.z*(u.x*l.x+u.y*l.y+u.z*l.z)}),m=He({x:u.y*f.z-u.z*f.y,y:u.z*f.x-u.x*f.z,z:u.x*f.y-u.y*f.x}),p=[u,f,m];return{origin:a,axis:p,matrix:Sa(a,p)}}var ia=`#version 300 es
366
+ }`;function Z0(t){let e=t.x*t.x+t.y*t.y+t.z*t.z;if(e<=0)return{x:0,y:0,z:1};let r=1/Math.sqrt(e);return{x:t.x*r,y:t.y*r,z:t.z*r}}function qs(t,e,r){return t+(e-t)*r}function qc(t,e,r){return{x:qs(t.x,e.x,r),y:qs(t.y,e.y,r),z:qs(t.z,e.z,r)}}function eu(t,e,r){return[t/r.skinWidth,1-e/r.skinHeight]}function Qs(t){if(t.glCommands.length===0){let n=[],i=[];return t.triangles.forEach(o=>{let s=n.length;for(let a=0;a<3;a+=1){let c=o.vertexIndices[a],l=o.texCoordIndices[a],d=t.texCoords[l];n.push({vertexIndex:c,texCoord:eu(d.s,d.t,t.header)})}i.push(s,s+1,s+2)}),{vertices:n,indices:new Uint16Array(i)}}let e=[],r=[];for(let n of t.glCommands){let i=e.length;if(e.push(...n.vertices.map(o=>({vertexIndex:o.vertexIndex,texCoord:[o.s,1-o.t]}))),n.mode==="strip")for(let o=0;o<n.vertices.length-2;o+=1){let s=o%2===0,a=i+o+(s?0:1),c=i+o+(s?1:0),l=i+o+2;r.push(a,c,l)}else for(let o=1;o<n.vertices.length-1;o+=1)r.push(i,i+o,i+o+1)}return{vertices:e,indices:new Uint16Array(r)}}function Js(t,e,r){let{frame0:n,frame1:i,lerp:o}=r,s=t.frames[n],a=t.frames[i];if(!s||!a)throw new Error("Requested MD2 frames are out of range");let c=new Float32Array(e.vertices.length*8);return e.vertices.forEach((l,d)=>{let u=s.vertices[l.vertexIndex],f=a.vertices[l.vertexIndex];if(!u||!f)throw new Error("MD2 vertex index out of range for frame");let m=qc(u.position,f.position,o),p=Z0(qc(u.normal,f.normal,o)),y=d*8;c[y]=m.x,c[y+1]=m.y,c[y+2]=m.z,c[y+3]=p.x,c[y+4]=p.y,c[y+5]=p.z,c[y+6]=l.texCoord[0],c[y+7]=l.texCoord[1]}),c}var Mo=class{constructor(e,r,n){this.gl=e,this.geometry=Qs(r),this.vertexBuffer=new Se(e,e.STATIC_DRAW),this.indexBuffer=new fe(e,e.STATIC_DRAW),this.vertexArray=new we(e),this.indexCount=this.geometry.indices.length,this.vertexArray.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:32,offset:0},{index:1,size:3,type:e.FLOAT,stride:32,offset:12},{index:2,size:2,type:e.FLOAT,stride:32,offset:24}],this.vertexBuffer),this.vertexArray.bind(),this.indexBuffer.bind(),this.indexBuffer.upload(this.geometry.indices,e.STATIC_DRAW),this.update(r,n)}update(e,r){let n=Js(e,this.geometry,r);this.vertexBuffer.upload(n,this.gl.STATIC_DRAW)}bind(){this.vertexArray.bind(),this.indexBuffer.bind()}dispose(){this.vertexBuffer.dispose(),this.indexBuffer.dispose(),this.vertexArray.dispose(),this.wireframeIndexBuffer?.dispose()}},_o=class{constructor(e){this.uniformDlights=[];this.gl=e,this.program=ve.create(e,{vertex:$s,fragment:js},{a_position:0,a_normal:1,a_texCoord:2}),this.uniformMvp=this.program.getUniformLocation("u_modelViewProjection"),this.uniformModelMatrix=this.program.getUniformLocation("u_modelMatrix"),this.uniformLightDir=this.program.getUniformLocation("u_lightDir"),this.uniformAmbient=this.program.getUniformLocation("u_ambient"),this.uniformTint=this.program.getUniformLocation("u_tint"),this.uniformDiffuse=this.program.getUniformLocation("u_diffuseMap"),this.uniformRenderMode=this.program.getUniformLocation("u_renderMode"),this.uniformSolidColor=this.program.getUniformLocation("u_solidColor"),this.uniformNumDlights=this.program.getUniformLocation("u_numDlights");for(let r=0;r<Ft;r++)this.uniformDlights.push({pos:this.program.getUniformLocation(`u_dlights[${r}].position`),color:this.program.getUniformLocation(`u_dlights[${r}].color`),intensity:this.program.getUniformLocation(`u_dlights[${r}].intensity`)})}bind(e){let{modelViewProjection:r,modelMatrix:n,lightDirection:i=[0,0,1],ambientLight:o=.2,tint:s=[1,1,1,1],diffuseSampler:a=0,dlights:c=[],renderMode:l}=e,d=new Float32Array(i),u=new Float32Array(s);this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,r),n?this.gl.uniformMatrix4fv(this.uniformModelMatrix,!1,n):this.gl.uniformMatrix4fv(this.uniformModelMatrix,!1,new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])),this.gl.uniform3fv(this.uniformLightDir,d),this.gl.uniform1f(this.uniformAmbient,o),this.gl.uniform4fv(this.uniformTint,u),this.gl.uniform1i(this.uniformDiffuse,a);let f=0,m=[1,1,1,1];l&&(l.mode==="solid"||l.mode==="wireframe"?f=1:l.mode==="solid-faceted"&&(f=2),l.color?m=[...l.color]:l.generateRandomColor),this.gl.uniform1i(this.uniformRenderMode,f),this.gl.uniform4f(this.uniformSolidColor,m[0],m[1],m[2],m[3]);let p=Math.min(c.length,Ft);this.gl.uniform1i(this.uniformNumDlights,p);for(let y=0;y<p;y++){let h=c[y];this.gl.uniform3f(this.uniformDlights[y].pos,h.origin.x,h.origin.y,h.origin.z),this.gl.uniform3f(this.uniformDlights[y].color,h.color.x,h.color.y,h.color.z),this.gl.uniform1f(this.uniformDlights[y].intensity,h.intensity)}}draw(e,r){if(e.vertexArray.bind(),r&&r.mode==="wireframe"){if(!e.wireframeIndexBuffer){e.wireframeIndexBuffer=new fe(this.gl,this.gl.STATIC_DRAW);let n=kr(e.geometry.indices);e.wireframeIndexBuffer.upload(n),e.wireframeIndexCount=n.length}e.wireframeIndexBuffer.bind(),this.gl.drawElements(this.gl.LINES,e.wireframeIndexCount,this.gl.UNSIGNED_SHORT,0)}else e.indexBuffer.bind(),this.gl.drawElements(this.gl.TRIANGLES,e.indexCount,this.gl.UNSIGNED_SHORT,0)}dispose(){this.program.dispose()}};var j=1e-6,Ue=typeof Float32Array<"u"?Float32Array:Array,Zs=Math.random;function Ao(t){return t>=0?Math.round(t):t%.5===0?Math.floor(t):Math.round(t)}var og=Math.PI/180,sg=180/Math.PI;var ae={};qo(ae,{add:()=>ku,adjoint:()=>cu,clone:()=>ru,copy:()=>nu,create:()=>tu,decompose:()=>wu,determinant:()=>lu,equals:()=>Gu,exactEquals:()=>Vu,frob:()=>Nu,fromQuat:()=>Iu,fromQuat2:()=>Mu,fromRotation:()=>xu,fromRotationTranslation:()=>Jc,fromRotationTranslationScale:()=>Lu,fromRotationTranslationScaleOrigin:()=>Eu,fromScaling:()=>gu,fromTranslation:()=>yu,fromValues:()=>iu,fromXRotation:()=>bu,fromYRotation:()=>vu,fromZRotation:()=>Su,frustum:()=>Pu,getRotation:()=>Au,getScaling:()=>Zc,getTranslation:()=>_u,identity:()=>jc,invert:()=>au,lookAt:()=>Bu,mul:()=>Wu,multiply:()=>Qc,multiplyScalar:()=>Uu,multiplyScalarAndAdd:()=>Hu,ortho:()=>Tu,orthoNO:()=>tl,orthoZO:()=>Fu,perspective:()=>Cu,perspectiveFromFieldOfView:()=>Ru,perspectiveNO:()=>el,perspectiveZO:()=>zu,rotate:()=>fu,rotateX:()=>mu,rotateY:()=>hu,rotateZ:()=>pu,scale:()=>uu,set:()=>ou,str:()=>Ou,sub:()=>Xu,subtract:()=>rl,targetTo:()=>Du,translate:()=>du,transpose:()=>su});function tu(){var t=new Ue(16);return Ue!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function ru(t){var e=new Ue(16);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function nu(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function iu(t,e,r,n,i,o,s,a,c,l,d,u,f,m,p,y){var h=new Ue(16);return h[0]=t,h[1]=e,h[2]=r,h[3]=n,h[4]=i,h[5]=o,h[6]=s,h[7]=a,h[8]=c,h[9]=l,h[10]=d,h[11]=u,h[12]=f,h[13]=m,h[14]=p,h[15]=y,h}function ou(t,e,r,n,i,o,s,a,c,l,d,u,f,m,p,y,h){return t[0]=e,t[1]=r,t[2]=n,t[3]=i,t[4]=o,t[5]=s,t[6]=a,t[7]=c,t[8]=l,t[9]=d,t[10]=u,t[11]=f,t[12]=m,t[13]=p,t[14]=y,t[15]=h,t}function jc(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function su(t,e){if(t===e){var r=e[1],n=e[2],i=e[3],o=e[6],s=e[7],a=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=r,t[6]=e[9],t[7]=e[13],t[8]=n,t[9]=o,t[11]=e[14],t[12]=i,t[13]=s,t[14]=a}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t}function au(t,e){var r=e[0],n=e[1],i=e[2],o=e[3],s=e[4],a=e[5],c=e[6],l=e[7],d=e[8],u=e[9],f=e[10],m=e[11],p=e[12],y=e[13],h=e[14],g=e[15],S=r*a-n*s,x=r*c-i*s,v=r*l-o*s,b=n*c-i*a,_=n*l-o*a,A=i*l-o*c,w=d*y-u*p,E=d*h-f*p,L=d*g-m*p,B=u*h-f*y,O=u*g-m*y,U=f*g-m*h,C=S*U-x*O+v*B+b*L-_*E+A*w;return C?(C=1/C,t[0]=(a*U-c*O+l*B)*C,t[1]=(i*O-n*U-o*B)*C,t[2]=(y*A-h*_+g*b)*C,t[3]=(f*_-u*A-m*b)*C,t[4]=(c*L-s*U-l*E)*C,t[5]=(r*U-i*L+o*E)*C,t[6]=(h*v-p*A-g*x)*C,t[7]=(d*A-f*v+m*x)*C,t[8]=(s*O-a*L+l*w)*C,t[9]=(n*L-r*O-o*w)*C,t[10]=(p*_-y*v+g*S)*C,t[11]=(u*v-d*_-m*S)*C,t[12]=(a*E-s*B-c*w)*C,t[13]=(r*B-n*E+i*w)*C,t[14]=(y*x-p*b-h*S)*C,t[15]=(d*b-u*x+f*S)*C,t):null}function cu(t,e){var r=e[0],n=e[1],i=e[2],o=e[3],s=e[4],a=e[5],c=e[6],l=e[7],d=e[8],u=e[9],f=e[10],m=e[11],p=e[12],y=e[13],h=e[14],g=e[15],S=r*a-n*s,x=r*c-i*s,v=r*l-o*s,b=n*c-i*a,_=n*l-o*a,A=i*l-o*c,w=d*y-u*p,E=d*h-f*p,L=d*g-m*p,B=u*h-f*y,O=u*g-m*y,U=f*g-m*h;return t[0]=a*U-c*O+l*B,t[1]=i*O-n*U-o*B,t[2]=y*A-h*_+g*b,t[3]=f*_-u*A-m*b,t[4]=c*L-s*U-l*E,t[5]=r*U-i*L+o*E,t[6]=h*v-p*A-g*x,t[7]=d*A-f*v+m*x,t[8]=s*O-a*L+l*w,t[9]=n*L-r*O-o*w,t[10]=p*_-y*v+g*S,t[11]=u*v-d*_-m*S,t[12]=a*E-s*B-c*w,t[13]=r*B-n*E+i*w,t[14]=y*x-p*b-h*S,t[15]=d*b-u*x+f*S,t}function lu(t){var e=t[0],r=t[1],n=t[2],i=t[3],o=t[4],s=t[5],a=t[6],c=t[7],l=t[8],d=t[9],u=t[10],f=t[11],m=t[12],p=t[13],y=t[14],h=t[15],g=e*s-r*o,S=e*a-n*o,x=r*a-n*s,v=l*p-d*m,b=l*y-u*m,_=d*y-u*p,A=e*_-r*b+n*v,w=o*_-s*b+a*v,E=l*x-d*S+u*g,L=m*x-p*S+y*g;return c*A-i*w+h*E-f*L}function Qc(t,e,r){var n=e[0],i=e[1],o=e[2],s=e[3],a=e[4],c=e[5],l=e[6],d=e[7],u=e[8],f=e[9],m=e[10],p=e[11],y=e[12],h=e[13],g=e[14],S=e[15],x=r[0],v=r[1],b=r[2],_=r[3];return t[0]=x*n+v*a+b*u+_*y,t[1]=x*i+v*c+b*f+_*h,t[2]=x*o+v*l+b*m+_*g,t[3]=x*s+v*d+b*p+_*S,x=r[4],v=r[5],b=r[6],_=r[7],t[4]=x*n+v*a+b*u+_*y,t[5]=x*i+v*c+b*f+_*h,t[6]=x*o+v*l+b*m+_*g,t[7]=x*s+v*d+b*p+_*S,x=r[8],v=r[9],b=r[10],_=r[11],t[8]=x*n+v*a+b*u+_*y,t[9]=x*i+v*c+b*f+_*h,t[10]=x*o+v*l+b*m+_*g,t[11]=x*s+v*d+b*p+_*S,x=r[12],v=r[13],b=r[14],_=r[15],t[12]=x*n+v*a+b*u+_*y,t[13]=x*i+v*c+b*f+_*h,t[14]=x*o+v*l+b*m+_*g,t[15]=x*s+v*d+b*p+_*S,t}function du(t,e,r){var n=r[0],i=r[1],o=r[2],s,a,c,l,d,u,f,m,p,y,h,g;return e===t?(t[12]=e[0]*n+e[4]*i+e[8]*o+e[12],t[13]=e[1]*n+e[5]*i+e[9]*o+e[13],t[14]=e[2]*n+e[6]*i+e[10]*o+e[14],t[15]=e[3]*n+e[7]*i+e[11]*o+e[15]):(s=e[0],a=e[1],c=e[2],l=e[3],d=e[4],u=e[5],f=e[6],m=e[7],p=e[8],y=e[9],h=e[10],g=e[11],t[0]=s,t[1]=a,t[2]=c,t[3]=l,t[4]=d,t[5]=u,t[6]=f,t[7]=m,t[8]=p,t[9]=y,t[10]=h,t[11]=g,t[12]=s*n+d*i+p*o+e[12],t[13]=a*n+u*i+y*o+e[13],t[14]=c*n+f*i+h*o+e[14],t[15]=l*n+m*i+g*o+e[15]),t}function uu(t,e,r){var n=r[0],i=r[1],o=r[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*o,t[9]=e[9]*o,t[10]=e[10]*o,t[11]=e[11]*o,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function fu(t,e,r,n){var i=n[0],o=n[1],s=n[2],a=Math.sqrt(i*i+o*o+s*s),c,l,d,u,f,m,p,y,h,g,S,x,v,b,_,A,w,E,L,B,O,U,C,J;return a<j?null:(a=1/a,i*=a,o*=a,s*=a,c=Math.sin(r),l=Math.cos(r),d=1-l,u=e[0],f=e[1],m=e[2],p=e[3],y=e[4],h=e[5],g=e[6],S=e[7],x=e[8],v=e[9],b=e[10],_=e[11],A=i*i*d+l,w=o*i*d+s*c,E=s*i*d-o*c,L=i*o*d-s*c,B=o*o*d+l,O=s*o*d+i*c,U=i*s*d+o*c,C=o*s*d-i*c,J=s*s*d+l,t[0]=u*A+y*w+x*E,t[1]=f*A+h*w+v*E,t[2]=m*A+g*w+b*E,t[3]=p*A+S*w+_*E,t[4]=u*L+y*B+x*O,t[5]=f*L+h*B+v*O,t[6]=m*L+g*B+b*O,t[7]=p*L+S*B+_*O,t[8]=u*U+y*C+x*J,t[9]=f*U+h*C+v*J,t[10]=m*U+g*C+b*J,t[11]=p*U+S*C+_*J,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}function mu(t,e,r){var n=Math.sin(r),i=Math.cos(r),o=e[4],s=e[5],a=e[6],c=e[7],l=e[8],d=e[9],u=e[10],f=e[11];return e!==t&&(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[4]=o*i+l*n,t[5]=s*i+d*n,t[6]=a*i+u*n,t[7]=c*i+f*n,t[8]=l*i-o*n,t[9]=d*i-s*n,t[10]=u*i-a*n,t[11]=f*i-c*n,t}function hu(t,e,r){var n=Math.sin(r),i=Math.cos(r),o=e[0],s=e[1],a=e[2],c=e[3],l=e[8],d=e[9],u=e[10],f=e[11];return e!==t&&(t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=o*i-l*n,t[1]=s*i-d*n,t[2]=a*i-u*n,t[3]=c*i-f*n,t[8]=o*n+l*i,t[9]=s*n+d*i,t[10]=a*n+u*i,t[11]=c*n+f*i,t}function pu(t,e,r){var n=Math.sin(r),i=Math.cos(r),o=e[0],s=e[1],a=e[2],c=e[3],l=e[4],d=e[5],u=e[6],f=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=o*i+l*n,t[1]=s*i+d*n,t[2]=a*i+u*n,t[3]=c*i+f*n,t[4]=l*i-o*n,t[5]=d*i-s*n,t[6]=u*i-a*n,t[7]=f*i-c*n,t}function yu(t,e){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=e[0],t[13]=e[1],t[14]=e[2],t[15]=1,t}function gu(t,e){return t[0]=e[0],t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=e[1],t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=e[2],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function xu(t,e,r){var n=r[0],i=r[1],o=r[2],s=Math.sqrt(n*n+i*i+o*o),a,c,l;return s<j?null:(s=1/s,n*=s,i*=s,o*=s,a=Math.sin(e),c=Math.cos(e),l=1-c,t[0]=n*n*l+c,t[1]=i*n*l+o*a,t[2]=o*n*l-i*a,t[3]=0,t[4]=n*i*l-o*a,t[5]=i*i*l+c,t[6]=o*i*l+n*a,t[7]=0,t[8]=n*o*l+i*a,t[9]=i*o*l-n*a,t[10]=o*o*l+c,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t)}function bu(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=n,t[6]=r,t[7]=0,t[8]=0,t[9]=-r,t[10]=n,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function vu(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=n,t[1]=0,t[2]=-r,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=r,t[9]=0,t[10]=n,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Su(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=n,t[1]=r,t[2]=0,t[3]=0,t[4]=-r,t[5]=n,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Jc(t,e,r){var n=e[0],i=e[1],o=e[2],s=e[3],a=n+n,c=i+i,l=o+o,d=n*a,u=n*c,f=n*l,m=i*c,p=i*l,y=o*l,h=s*a,g=s*c,S=s*l;return t[0]=1-(m+y),t[1]=u+S,t[2]=f-g,t[3]=0,t[4]=u-S,t[5]=1-(d+y),t[6]=p+h,t[7]=0,t[8]=f+g,t[9]=p-h,t[10]=1-(d+m),t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function Mu(t,e){var r=new Ue(3),n=-e[0],i=-e[1],o=-e[2],s=e[3],a=e[4],c=e[5],l=e[6],d=e[7],u=n*n+i*i+o*o+s*s;return u>0?(r[0]=(a*s+d*n+c*o-l*i)*2/u,r[1]=(c*s+d*i+l*n-a*o)*2/u,r[2]=(l*s+d*o+a*i-c*n)*2/u):(r[0]=(a*s+d*n+c*o-l*i)*2,r[1]=(c*s+d*i+l*n-a*o)*2,r[2]=(l*s+d*o+a*i-c*n)*2),Jc(t,e,r),t}function _u(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}function Zc(t,e){var r=e[0],n=e[1],i=e[2],o=e[4],s=e[5],a=e[6],c=e[8],l=e[9],d=e[10];return t[0]=Math.sqrt(r*r+n*n+i*i),t[1]=Math.sqrt(o*o+s*s+a*a),t[2]=Math.sqrt(c*c+l*l+d*d),t}function Au(t,e){var r=new Ue(3);Zc(r,e);var n=1/r[0],i=1/r[1],o=1/r[2],s=e[0]*n,a=e[1]*i,c=e[2]*o,l=e[4]*n,d=e[5]*i,u=e[6]*o,f=e[8]*n,m=e[9]*i,p=e[10]*o,y=s+d+p,h=0;return y>0?(h=Math.sqrt(y+1)*2,t[3]=.25*h,t[0]=(u-m)/h,t[1]=(f-c)/h,t[2]=(a-l)/h):s>d&&s>p?(h=Math.sqrt(1+s-d-p)*2,t[3]=(u-m)/h,t[0]=.25*h,t[1]=(a+l)/h,t[2]=(f+c)/h):d>p?(h=Math.sqrt(1+d-s-p)*2,t[3]=(f-c)/h,t[0]=(a+l)/h,t[1]=.25*h,t[2]=(u+m)/h):(h=Math.sqrt(1+p-s-d)*2,t[3]=(a-l)/h,t[0]=(f+c)/h,t[1]=(u+m)/h,t[2]=.25*h),t}function wu(t,e,r,n){e[0]=n[12],e[1]=n[13],e[2]=n[14];var i=n[0],o=n[1],s=n[2],a=n[4],c=n[5],l=n[6],d=n[8],u=n[9],f=n[10];r[0]=Math.sqrt(i*i+o*o+s*s),r[1]=Math.sqrt(a*a+c*c+l*l),r[2]=Math.sqrt(d*d+u*u+f*f);var m=1/r[0],p=1/r[1],y=1/r[2],h=i*m,g=o*p,S=s*y,x=a*m,v=c*p,b=l*y,_=d*m,A=u*p,w=f*y,E=h+v+w,L=0;return E>0?(L=Math.sqrt(E+1)*2,t[3]=.25*L,t[0]=(b-A)/L,t[1]=(_-S)/L,t[2]=(g-x)/L):h>v&&h>w?(L=Math.sqrt(1+h-v-w)*2,t[3]=(b-A)/L,t[0]=.25*L,t[1]=(g+x)/L,t[2]=(_+S)/L):v>w?(L=Math.sqrt(1+v-h-w)*2,t[3]=(_-S)/L,t[0]=(g+x)/L,t[1]=.25*L,t[2]=(b+A)/L):(L=Math.sqrt(1+w-h-v)*2,t[3]=(g-x)/L,t[0]=(_+S)/L,t[1]=(b+A)/L,t[2]=.25*L),t}function Lu(t,e,r,n){var i=e[0],o=e[1],s=e[2],a=e[3],c=i+i,l=o+o,d=s+s,u=i*c,f=i*l,m=i*d,p=o*l,y=o*d,h=s*d,g=a*c,S=a*l,x=a*d,v=n[0],b=n[1],_=n[2];return t[0]=(1-(p+h))*v,t[1]=(f+x)*v,t[2]=(m-S)*v,t[3]=0,t[4]=(f-x)*b,t[5]=(1-(u+h))*b,t[6]=(y+g)*b,t[7]=0,t[8]=(m+S)*_,t[9]=(y-g)*_,t[10]=(1-(u+p))*_,t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function Eu(t,e,r,n,i){var o=e[0],s=e[1],a=e[2],c=e[3],l=o+o,d=s+s,u=a+a,f=o*l,m=o*d,p=o*u,y=s*d,h=s*u,g=a*u,S=c*l,x=c*d,v=c*u,b=n[0],_=n[1],A=n[2],w=i[0],E=i[1],L=i[2],B=(1-(y+g))*b,O=(m+v)*b,U=(p-x)*b,C=(m-v)*_,J=(1-(f+g))*_,Me=(h+S)*_,Bt=(p+x)*A,oi=(h-S)*A,Vr=(1-(f+y))*A;return t[0]=B,t[1]=O,t[2]=U,t[3]=0,t[4]=C,t[5]=J,t[6]=Me,t[7]=0,t[8]=Bt,t[9]=oi,t[10]=Vr,t[11]=0,t[12]=r[0]+w-(B*w+C*E+Bt*L),t[13]=r[1]+E-(O*w+J*E+oi*L),t[14]=r[2]+L-(U*w+Me*E+Vr*L),t[15]=1,t}function Iu(t,e){var r=e[0],n=e[1],i=e[2],o=e[3],s=r+r,a=n+n,c=i+i,l=r*s,d=n*s,u=n*a,f=i*s,m=i*a,p=i*c,y=o*s,h=o*a,g=o*c;return t[0]=1-u-p,t[1]=d+g,t[2]=f-h,t[3]=0,t[4]=d-g,t[5]=1-l-p,t[6]=m+y,t[7]=0,t[8]=f+h,t[9]=m-y,t[10]=1-l-u,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Pu(t,e,r,n,i,o,s){var a=1/(r-e),c=1/(i-n),l=1/(o-s);return t[0]=o*2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=o*2*c,t[6]=0,t[7]=0,t[8]=(r+e)*a,t[9]=(i+n)*c,t[10]=(s+o)*l,t[11]=-1,t[12]=0,t[13]=0,t[14]=s*o*2*l,t[15]=0,t}function el(t,e,r,n,i){var o=1/Math.tan(e/2);if(t[0]=o/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=o,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,i!=null&&i!==1/0){var s=1/(n-i);t[10]=(i+n)*s,t[14]=2*i*n*s}else t[10]=-1,t[14]=-2*n;return t}var Cu=el;function zu(t,e,r,n,i){var o=1/Math.tan(e/2);if(t[0]=o/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=o,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,i!=null&&i!==1/0){var s=1/(n-i);t[10]=i*s,t[14]=i*n*s}else t[10]=-1,t[14]=-n;return t}function Ru(t,e,r,n){var i=Math.tan(e.upDegrees*Math.PI/180),o=Math.tan(e.downDegrees*Math.PI/180),s=Math.tan(e.leftDegrees*Math.PI/180),a=Math.tan(e.rightDegrees*Math.PI/180),c=2/(s+a),l=2/(i+o);return t[0]=c,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=l,t[6]=0,t[7]=0,t[8]=-((s-a)*c*.5),t[9]=(i-o)*l*.5,t[10]=n/(r-n),t[11]=-1,t[12]=0,t[13]=0,t[14]=n*r/(r-n),t[15]=0,t}function tl(t,e,r,n,i,o,s){var a=1/(e-r),c=1/(n-i),l=1/(o-s);return t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*c,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*l,t[11]=0,t[12]=(e+r)*a,t[13]=(i+n)*c,t[14]=(s+o)*l,t[15]=1,t}var Tu=tl;function Fu(t,e,r,n,i,o,s){var a=1/(e-r),c=1/(n-i),l=1/(o-s);return t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*c,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=l,t[11]=0,t[12]=(e+r)*a,t[13]=(i+n)*c,t[14]=o*l,t[15]=1,t}function Bu(t,e,r,n){var i,o,s,a,c,l,d,u,f,m,p=e[0],y=e[1],h=e[2],g=n[0],S=n[1],x=n[2],v=r[0],b=r[1],_=r[2];return Math.abs(p-v)<j&&Math.abs(y-b)<j&&Math.abs(h-_)<j?jc(t):(d=p-v,u=y-b,f=h-_,m=1/Math.sqrt(d*d+u*u+f*f),d*=m,u*=m,f*=m,i=S*f-x*u,o=x*d-g*f,s=g*u-S*d,m=Math.sqrt(i*i+o*o+s*s),m?(m=1/m,i*=m,o*=m,s*=m):(i=0,o=0,s=0),a=u*s-f*o,c=f*i-d*s,l=d*o-u*i,m=Math.sqrt(a*a+c*c+l*l),m?(m=1/m,a*=m,c*=m,l*=m):(a=0,c=0,l=0),t[0]=i,t[1]=a,t[2]=d,t[3]=0,t[4]=o,t[5]=c,t[6]=u,t[7]=0,t[8]=s,t[9]=l,t[10]=f,t[11]=0,t[12]=-(i*p+o*y+s*h),t[13]=-(a*p+c*y+l*h),t[14]=-(d*p+u*y+f*h),t[15]=1,t)}function Du(t,e,r,n){var i=e[0],o=e[1],s=e[2],a=n[0],c=n[1],l=n[2],d=i-r[0],u=o-r[1],f=s-r[2],m=d*d+u*u+f*f;m>0&&(m=1/Math.sqrt(m),d*=m,u*=m,f*=m);var p=c*f-l*u,y=l*d-a*f,h=a*u-c*d;return m=p*p+y*y+h*h,m>0&&(m=1/Math.sqrt(m),p*=m,y*=m,h*=m),t[0]=p,t[1]=y,t[2]=h,t[3]=0,t[4]=u*h-f*y,t[5]=f*p-d*h,t[6]=d*y-u*p,t[7]=0,t[8]=d,t[9]=u,t[10]=f,t[11]=0,t[12]=i,t[13]=o,t[14]=s,t[15]=1,t}function Ou(t){return"mat4("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+", "+t[6]+", "+t[7]+", "+t[8]+", "+t[9]+", "+t[10]+", "+t[11]+", "+t[12]+", "+t[13]+", "+t[14]+", "+t[15]+")"}function Nu(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]+t[3]*t[3]+t[4]*t[4]+t[5]*t[5]+t[6]*t[6]+t[7]*t[7]+t[8]*t[8]+t[9]*t[9]+t[10]*t[10]+t[11]*t[11]+t[12]*t[12]+t[13]*t[13]+t[14]*t[14]+t[15]*t[15])}function ku(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t[3]=e[3]+r[3],t[4]=e[4]+r[4],t[5]=e[5]+r[5],t[6]=e[6]+r[6],t[7]=e[7]+r[7],t[8]=e[8]+r[8],t[9]=e[9]+r[9],t[10]=e[10]+r[10],t[11]=e[11]+r[11],t[12]=e[12]+r[12],t[13]=e[13]+r[13],t[14]=e[14]+r[14],t[15]=e[15]+r[15],t}function rl(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t[3]=e[3]-r[3],t[4]=e[4]-r[4],t[5]=e[5]-r[5],t[6]=e[6]-r[6],t[7]=e[7]-r[7],t[8]=e[8]-r[8],t[9]=e[9]-r[9],t[10]=e[10]-r[10],t[11]=e[11]-r[11],t[12]=e[12]-r[12],t[13]=e[13]-r[13],t[14]=e[14]-r[14],t[15]=e[15]-r[15],t}function Uu(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t[4]=e[4]*r,t[5]=e[5]*r,t[6]=e[6]*r,t[7]=e[7]*r,t[8]=e[8]*r,t[9]=e[9]*r,t[10]=e[10]*r,t[11]=e[11]*r,t[12]=e[12]*r,t[13]=e[13]*r,t[14]=e[14]*r,t[15]=e[15]*r,t}function Hu(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t[3]=e[3]+r[3]*n,t[4]=e[4]+r[4]*n,t[5]=e[5]+r[5]*n,t[6]=e[6]+r[6]*n,t[7]=e[7]+r[7]*n,t[8]=e[8]+r[8]*n,t[9]=e[9]+r[9]*n,t[10]=e[10]+r[10]*n,t[11]=e[11]+r[11]*n,t[12]=e[12]+r[12]*n,t[13]=e[13]+r[13]*n,t[14]=e[14]+r[14]*n,t[15]=e[15]+r[15]*n,t}function Vu(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]&&t[3]===e[3]&&t[4]===e[4]&&t[5]===e[5]&&t[6]===e[6]&&t[7]===e[7]&&t[8]===e[8]&&t[9]===e[9]&&t[10]===e[10]&&t[11]===e[11]&&t[12]===e[12]&&t[13]===e[13]&&t[14]===e[14]&&t[15]===e[15]}function Gu(t,e){var r=t[0],n=t[1],i=t[2],o=t[3],s=t[4],a=t[5],c=t[6],l=t[7],d=t[8],u=t[9],f=t[10],m=t[11],p=t[12],y=t[13],h=t[14],g=t[15],S=e[0],x=e[1],v=e[2],b=e[3],_=e[4],A=e[5],w=e[6],E=e[7],L=e[8],B=e[9],O=e[10],U=e[11],C=e[12],J=e[13],Me=e[14],Bt=e[15];return Math.abs(r-S)<=j*Math.max(1,Math.abs(r),Math.abs(S))&&Math.abs(n-x)<=j*Math.max(1,Math.abs(n),Math.abs(x))&&Math.abs(i-v)<=j*Math.max(1,Math.abs(i),Math.abs(v))&&Math.abs(o-b)<=j*Math.max(1,Math.abs(o),Math.abs(b))&&Math.abs(s-_)<=j*Math.max(1,Math.abs(s),Math.abs(_))&&Math.abs(a-A)<=j*Math.max(1,Math.abs(a),Math.abs(A))&&Math.abs(c-w)<=j*Math.max(1,Math.abs(c),Math.abs(w))&&Math.abs(l-E)<=j*Math.max(1,Math.abs(l),Math.abs(E))&&Math.abs(d-L)<=j*Math.max(1,Math.abs(d),Math.abs(L))&&Math.abs(u-B)<=j*Math.max(1,Math.abs(u),Math.abs(B))&&Math.abs(f-O)<=j*Math.max(1,Math.abs(f),Math.abs(O))&&Math.abs(m-U)<=j*Math.max(1,Math.abs(m),Math.abs(U))&&Math.abs(p-C)<=j*Math.max(1,Math.abs(p),Math.abs(C))&&Math.abs(y-J)<=j*Math.max(1,Math.abs(y),Math.abs(J))&&Math.abs(h-Me)<=j*Math.max(1,Math.abs(h),Math.abs(Me))&&Math.abs(g-Bt)<=j*Math.max(1,Math.abs(g),Math.abs(Bt))}var Wu=Qc,Xu=rl;var se={};qo(se,{add:()=>ju,angle:()=>vf,bezier:()=>ff,ceil:()=>Qu,clone:()=>Ku,copy:()=>qu,create:()=>nl,cross:()=>cf,dist:()=>If,distance:()=>cl,div:()=>Ef,divide:()=>al,dot:()=>ea,equals:()=>Af,exactEquals:()=>_f,floor:()=>Ju,forEach:()=>Rf,fromValues:()=>Yu,hermite:()=>uf,inverse:()=>sf,len:()=>Cf,length:()=>il,lerp:()=>lf,max:()=>ef,min:()=>Zu,mul:()=>Lf,multiply:()=>sl,negate:()=>of,normalize:()=>af,random:()=>mf,rotateX:()=>gf,rotateY:()=>xf,rotateZ:()=>bf,round:()=>tf,scale:()=>rf,scaleAndAdd:()=>nf,set:()=>$u,slerp:()=>df,sqrDist:()=>Pf,sqrLen:()=>zf,squaredDistance:()=>ll,squaredLength:()=>dl,str:()=>Mf,sub:()=>wf,subtract:()=>ol,transformMat3:()=>pf,transformMat4:()=>hf,transformQuat:()=>yf,zero:()=>Sf});function nl(){var t=new Ue(3);return Ue!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function Ku(t){var e=new Ue(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function il(t){var e=t[0],r=t[1],n=t[2];return Math.sqrt(e*e+r*r+n*n)}function Yu(t,e,r){var n=new Ue(3);return n[0]=t,n[1]=e,n[2]=r,n}function qu(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function $u(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t}function ju(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t}function ol(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t}function sl(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t}function al(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t}function Qu(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t[2]=Math.ceil(e[2]),t}function Ju(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t[2]=Math.floor(e[2]),t}function Zu(t,e,r){return t[0]=Math.min(e[0],r[0]),t[1]=Math.min(e[1],r[1]),t[2]=Math.min(e[2],r[2]),t}function ef(t,e,r){return t[0]=Math.max(e[0],r[0]),t[1]=Math.max(e[1],r[1]),t[2]=Math.max(e[2],r[2]),t}function tf(t,e){return t[0]=Ao(e[0]),t[1]=Ao(e[1]),t[2]=Ao(e[2]),t}function rf(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t}function nf(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t}function cl(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2];return Math.sqrt(r*r+n*n+i*i)}function ll(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2];return r*r+n*n+i*i}function dl(t){var e=t[0],r=t[1],n=t[2];return e*e+r*r+n*n}function of(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t}function sf(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t}function af(t,e){var r=e[0],n=e[1],i=e[2],o=r*r+n*n+i*i;return o>0&&(o=1/Math.sqrt(o)),t[0]=e[0]*o,t[1]=e[1]*o,t[2]=e[2]*o,t}function ea(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function cf(t,e,r){var n=e[0],i=e[1],o=e[2],s=r[0],a=r[1],c=r[2];return t[0]=i*c-o*a,t[1]=o*s-n*c,t[2]=n*a-i*s,t}function lf(t,e,r,n){var i=e[0],o=e[1],s=e[2];return t[0]=i+n*(r[0]-i),t[1]=o+n*(r[1]-o),t[2]=s+n*(r[2]-s),t}function df(t,e,r,n){var i=Math.acos(Math.min(Math.max(ea(e,r),-1),1)),o=Math.sin(i),s=Math.sin((1-n)*i)/o,a=Math.sin(n*i)/o;return t[0]=s*e[0]+a*r[0],t[1]=s*e[1]+a*r[1],t[2]=s*e[2]+a*r[2],t}function uf(t,e,r,n,i,o){var s=o*o,a=s*(2*o-3)+1,c=s*(o-2)+o,l=s*(o-1),d=s*(3-2*o);return t[0]=e[0]*a+r[0]*c+n[0]*l+i[0]*d,t[1]=e[1]*a+r[1]*c+n[1]*l+i[1]*d,t[2]=e[2]*a+r[2]*c+n[2]*l+i[2]*d,t}function ff(t,e,r,n,i,o){var s=1-o,a=s*s,c=o*o,l=a*s,d=3*o*a,u=3*c*s,f=c*o;return t[0]=e[0]*l+r[0]*d+n[0]*u+i[0]*f,t[1]=e[1]*l+r[1]*d+n[1]*u+i[1]*f,t[2]=e[2]*l+r[2]*d+n[2]*u+i[2]*f,t}function mf(t,e){e=e===void 0?1:e;var r=Zs()*2*Math.PI,n=Zs()*2-1,i=Math.sqrt(1-n*n)*e;return t[0]=Math.cos(r)*i,t[1]=Math.sin(r)*i,t[2]=n*e,t}function hf(t,e,r){var n=e[0],i=e[1],o=e[2],s=r[3]*n+r[7]*i+r[11]*o+r[15];return s=s||1,t[0]=(r[0]*n+r[4]*i+r[8]*o+r[12])/s,t[1]=(r[1]*n+r[5]*i+r[9]*o+r[13])/s,t[2]=(r[2]*n+r[6]*i+r[10]*o+r[14])/s,t}function pf(t,e,r){var n=e[0],i=e[1],o=e[2];return t[0]=n*r[0]+i*r[3]+o*r[6],t[1]=n*r[1]+i*r[4]+o*r[7],t[2]=n*r[2]+i*r[5]+o*r[8],t}function yf(t,e,r){var n=r[0],i=r[1],o=r[2],s=r[3],a=e[0],c=e[1],l=e[2],d=i*l-o*c,u=o*a-n*l,f=n*c-i*a;return d=d+d,u=u+u,f=f+f,t[0]=a+s*d+i*f-o*u,t[1]=c+s*u+o*d-n*f,t[2]=l+s*f+n*u-i*d,t}function gf(t,e,r,n){var i=[],o=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],o[0]=i[0],o[1]=i[1]*Math.cos(n)-i[2]*Math.sin(n),o[2]=i[1]*Math.sin(n)+i[2]*Math.cos(n),t[0]=o[0]+r[0],t[1]=o[1]+r[1],t[2]=o[2]+r[2],t}function xf(t,e,r,n){var i=[],o=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],o[0]=i[2]*Math.sin(n)+i[0]*Math.cos(n),o[1]=i[1],o[2]=i[2]*Math.cos(n)-i[0]*Math.sin(n),t[0]=o[0]+r[0],t[1]=o[1]+r[1],t[2]=o[2]+r[2],t}function bf(t,e,r,n){var i=[],o=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],o[0]=i[0]*Math.cos(n)-i[1]*Math.sin(n),o[1]=i[0]*Math.sin(n)+i[1]*Math.cos(n),o[2]=i[2],t[0]=o[0]+r[0],t[1]=o[1]+r[1],t[2]=o[2]+r[2],t}function vf(t,e){var r=t[0],n=t[1],i=t[2],o=e[0],s=e[1],a=e[2],c=Math.sqrt((r*r+n*n+i*i)*(o*o+s*s+a*a)),l=c&&ea(t,e)/c;return Math.acos(Math.min(Math.max(l,-1),1))}function Sf(t){return t[0]=0,t[1]=0,t[2]=0,t}function Mf(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"}function _f(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]}function Af(t,e){var r=t[0],n=t[1],i=t[2],o=e[0],s=e[1],a=e[2];return Math.abs(r-o)<=j*Math.max(1,Math.abs(r),Math.abs(o))&&Math.abs(n-s)<=j*Math.max(1,Math.abs(n),Math.abs(s))&&Math.abs(i-a)<=j*Math.max(1,Math.abs(i),Math.abs(a))}var wf=ol,Lf=sl,Ef=al,If=cl,Pf=ll,Cf=il,zf=dl,Rf=(function(){var t=nl();return function(e,r,n,i,o,s){var a,c;for(r||(r=3),n||(n=0),i?c=Math.min(i*r+n,e.length):c=e.length,a=n;a<c;a+=r)t[0]=e[a],t[1]=e[a+1],t[2]=e[a+2],o(t,t,s),e[a]=t[0],e[a+1]=t[1],e[a+2]=t[2];return e}})();var wo=class{constructor(){this._position=se.create();this._angles=se.create();this._bobAngles=se.create();this._bobOffset=se.create();this._kickAngles=se.create();this._rollAngle=0;this._fov=90;this._aspect=1;this._near=.1;this._far=1e3;this._viewMatrix=ae.create();this._projectionMatrix=ae.create();this._viewProjectionMatrix=ae.create();this._dirty=!0}get position(){return this._position}set position(e){se.copy(this._position,e),this._dirty=!0}get angles(){return this._angles}set angles(e){se.copy(this._angles,e),this._dirty=!0}get bobAngles(){return this._bobAngles}set bobAngles(e){se.copy(this._bobAngles,e),this._dirty=!0}get kickAngles(){return this._kickAngles}set kickAngles(e){se.copy(this._kickAngles,e),this._dirty=!0}get bobOffset(){return this._bobOffset}set bobOffset(e){se.copy(this._bobOffset,e),this._dirty=!0}get rollAngle(){return this._rollAngle}set rollAngle(e){this._rollAngle=e,this._dirty=!0}get fov(){return this._fov}set fov(e){this._fov=e,this._dirty=!0}get aspect(){return this._aspect}set aspect(e){this._aspect=e,this._dirty=!0}get viewMatrix(){return this.updateMatrices(),this._viewMatrix}get projectionMatrix(){return this.updateMatrices(),this._projectionMatrix}get viewProjectionMatrix(){return this.updateMatrices(),this._viewProjectionMatrix}getViewmodelProjectionMatrix(e){let r=ae.create();return ae.perspective(r,e*sr,this._aspect,this._near,this._far),r}updateMatrices(){if(!this._dirty)return;ae.perspective(this._projectionMatrix,this._fov*sr,this._aspect,this._near,this._far);let e=ae.fromValues(0,-1,0,0,0,0,1,0,-1,0,0,0,0,0,0,1),r=this._angles[0]+this._bobAngles[0]+this._kickAngles[0],n=this._angles[1]+this._bobAngles[1]+this._kickAngles[1],i=this._angles[2]+this._bobAngles[2]+this._kickAngles[2]+this._rollAngle,o=r*sr,s=n*sr,a=i*sr,c=ae.create();ae.identity(c),ae.rotateZ(c,c,-s),ae.rotateY(c,c,-o),ae.rotateX(c,c,-a);let l=ae.create();ae.multiply(l,e,c);let d=se.add(se.create(),this._position,this._bobOffset),u=se.negate(se.create(),d),f=se.create();se.transformMat4(f,u,c);let m=se.fromValues(f[1]||0,f[2]||0,f[0]||0);ae.copy(this._viewMatrix,l),this._viewMatrix[12]=m[0],this._viewMatrix[13]=m[1],this._viewMatrix[14]=m[2],ae.multiply(this._viewProjectionMatrix,this._projectionMatrix,this._viewMatrix),this._dirty=!1}};var Tf=[.2,.2,.2],Ff={x:0,y:0,z:1},Bf=[.8,.8,.8];function ta(t,e,r){return t+(e-t)*r}function Hr(t,e,r){return{x:ta(t.x,e.x,r),y:ta(t.y,e.y,r),z:ta(t.z,e.z,r)}}function Ur(t){return t<0?0:t>1?1:t}function ra(t){let e=[],r=[];for(let n of t.triangles){let i=e.length,[o,s,a]=n.indices,c=t.texCoords[o],l=t.texCoords[s],d=t.texCoords[a];if(!c||!l||!d)throw new Error(`Missing texCoord for triangle in surface ${t.name}`);e.push({vertexIndex:o,texCoord:[c.s,1-c.t]},{vertexIndex:s,texCoord:[l.s,1-l.t]},{vertexIndex:a,texCoord:[d.s,1-d.t]}),r.push(i,i+1,i+2)}return{vertices:e,indices:new Uint16Array(r)}}function Df(t,e,r){let n=r?.ambient??Tf,i=r?.directional??{direction:Ff,color:Bf},o=He(t),s=He(i.direction),a=Ur(o.x*s.x+o.y*s.y+o.z*s.z),c=n[0]+i.color[0]*a,l=n[1]+i.color[1]*a,d=n[2]+i.color[2]*a;if(r?.dynamicLights){let u=r.modelMatrix?va(r.modelMatrix,e):e;for(let f of r.dynamicLights){let m=u.x-f.origin.x,p=u.y-f.origin.y,y=u.z-f.origin.z,h=m*m+p*p+y*y,g=f.radius*f.radius;if(h<g&&g>0){let S=1-Math.sqrt(h)/f.radius,x=Math.sqrt(h),v=x>0?Ur(-(m*o.x+p*o.y+y*o.z)/x):0,b=Ur(S*v);c+=f.color[0]*b,l+=f.color[1]*b,d+=f.color[2]*b}}}return[Ur(c),Ur(l),Ur(d)]}function na(t,e,r,n){let i=t.vertices[r.frame0],o=t.vertices[r.frame1];if(!i||!o)throw new Error("Requested MD3 frames are out of range");let s=new Float32Array(e.vertices.length*12);return e.vertices.forEach((a,c)=>{let l=i[a.vertexIndex],d=o[a.vertexIndex];if(!l||!d)throw new Error(`Vertex index ${a.vertexIndex} missing for frame`);let u=Hr(l.position,d.position,r.lerp),f=He(Hr(l.normal,d.normal,r.lerp)),m=Df(f,u,n),p=c*12;s[p]=u.x,s[p+1]=u.y,s[p+2]=u.z,s[p+3]=f.x,s[p+4]=f.y,s[p+5]=f.z,s[p+6]=a.texCoord[0],s[p+7]=a.texCoord[1],s[p+8]=m[0],s[p+9]=m[1],s[p+10]=m[2],s[p+11]=1}),s}function ul(t,e,r){let n=t.tags[0];if(!n)return null;let i=n.findIndex(y=>y.name===r);if(i===-1)return null;let o=t.tags[e.frame0]?.[i],s=t.tags[e.frame1]?.[i];if(!o||!s)throw new Error(`Tag ${r} is missing for one of the interpolated frames`);let a=Hr(o.origin,s.origin,e.lerp),c=He(Hr(o.axis[0],s.axis[0],e.lerp)),l=He(Hr(o.axis[1],s.axis[1],e.lerp)),d=He(Hr(o.axis[2],s.axis[2],e.lerp)),u=c,f=He({x:l.x-u.x*(u.x*l.x+u.y*l.y+u.z*l.z),y:l.y-u.y*(u.x*l.x+u.y*l.y+u.z*l.z),z:l.z-u.z*(u.x*l.x+u.y*l.y+u.z*l.z)}),m=He({x:u.y*f.z-u.z*f.y,y:u.z*f.x-u.x*f.z,z:u.x*f.y-u.y*f.x}),p=[u,f,m];return{origin:a,axis:p,matrix:Sa(a,p)}}var ia=`#version 300 es
367
367
  precision highp float;
368
368
 
369
369
  layout(location = 0) in vec3 a_position;
@@ -418,7 +418,7 @@ void main() {
418
418
  }
419
419
 
420
420
  o_color = finalColor;
421
- }`,Qn=class{constructor(e,r,n,i){this.gl=e,this.geometry=ra(r),this.vertexBuffer=new Se(e,e.STATIC_DRAW),this.indexBuffer=new fe(e,e.STATIC_DRAW),this.vertexArray=new we(e),this.indexCount=this.geometry.indices.length,this.vertexArray.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:48,offset:0},{index:1,size:3,type:e.FLOAT,stride:48,offset:12},{index:2,size:2,type:e.FLOAT,stride:48,offset:24},{index:3,size:4,type:e.FLOAT,stride:48,offset:32}],this.vertexBuffer),this.vertexArray.bind(),this.indexBuffer.bind(),this.indexBuffer.upload(this.geometry.indices,e.STATIC_DRAW),this.update(r,n,i)}update(e,r,n){let i=na(e,this.geometry,r,n);this.vertexBuffer.upload(i,this.gl.STATIC_DRAW)}bind(){this.vertexArray.bind(),this.indexBuffer.bind()}dispose(){this.vertexBuffer.dispose(),this.indexBuffer.dispose(),this.vertexArray.dispose(),this.wireframeIndexBuffer?.dispose()}},Lo=class{constructor(e,r,n,i){this.surfaces=new Map;this.gl=e,this.model=r,this.blend=n,this.lighting=i,r.surfaces.forEach(o=>{this.surfaces.set(o.name,new Qn(e,o,n,i))})}update(e,r){this.blend=e,this.lighting=r??this.lighting;for(let n of this.model.surfaces)this.surfaces.get(n.name)?.update(n,e,this.lighting)}dispose(){for(let e of this.surfaces.values())e.dispose();this.surfaces.clear()}},Eo=class{constructor(e){this.gl=e,this.program=ve.create(e,{vertex:ia,fragment:oa},{a_position:0,a_normal:1,a_texCoord:2,a_color:3}),this.uniformMvp=this.program.getUniformLocation("u_modelViewProjection"),this.uniformTint=this.program.getUniformLocation("u_tint"),this.uniformDiffuse=this.program.getUniformLocation("u_diffuseMap"),this.uniformRenderMode=this.program.getUniformLocation("u_renderMode"),this.uniformSolidColor=this.program.getUniformLocation("u_solidColor")}bind(e,r=[1,1,1,1],n=0){this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,e),this.gl.uniform4fv(this.uniformTint,new Float32Array(r)),this.gl.uniform1i(this.uniformDiffuse,n),this.gl.uniform1i(this.uniformRenderMode,0),this.gl.uniform4f(this.uniformSolidColor,1,1,1,1)}drawSurface(e,r){let n=r?.diffuseSampler??0,i=r?.tint??[1,1,1,1],o=r?.renderMode;this.gl.uniform4fv(this.uniformTint,new Float32Array(i)),this.gl.uniform1i(this.uniformDiffuse,n);let s=0,a=[1,1,1,1];if(o&&(o.mode==="solid"||o.mode==="wireframe"?s=1:o.mode==="solid-faceted"&&(s=2),o.color&&(a=[...o.color])),this.gl.uniform1i(this.uniformRenderMode,s),this.gl.uniform4f(this.uniformSolidColor,a[0],a[1],a[2],a[3]),e.vertexArray.bind(),o&&o.mode==="wireframe"){if(!e.wireframeIndexBuffer){e.wireframeIndexBuffer=new fe(this.gl,this.gl.STATIC_DRAW);let c=kr(e.geometry.indices);e.wireframeIndexBuffer.upload(c),e.wireframeIndexCount=c.length}e.wireframeIndexBuffer.bind(),this.gl.drawElements(this.gl.LINES,e.wireframeIndexCount,this.gl.UNSIGNED_SHORT,0)}else e.indexBuffer.bind(),this.gl.drawElements(this.gl.TRIANGLES,e.indexCount,this.gl.UNSIGNED_SHORT,0)}dispose(){this.program.dispose()}};var Df=[1,1,1,1],Io=class{constructor(e,r=Math.random){this.maxParticles=e,this.random=r,this.alive=new Uint8Array(e),this.positionX=new Float32Array(e),this.positionY=new Float32Array(e),this.positionZ=new Float32Array(e),this.velocityX=new Float32Array(e),this.velocityY=new Float32Array(e),this.velocityZ=new Float32Array(e),this.colorR=new Float32Array(e),this.colorG=new Float32Array(e),this.colorB=new Float32Array(e),this.colorA=new Float32Array(e),this.size=new Float32Array(e),this.lifetime=new Float32Array(e),this.remaining=new Float32Array(e),this.gravity=new Float32Array(e),this.damping=new Float32Array(e),this.bounce=new Float32Array(e),this.fade=new Uint8Array(e),this.blendMode=new Uint8Array(e)}spawn(e){let r=this.findFreeSlot();if(r===-1)return null;let n=e.color??Df,i=e.velocity??{x:0,y:0,z:0};return this.alive[r]=1,this.positionX[r]=e.position.x,this.positionY[r]=e.position.y,this.positionZ[r]=e.position.z,this.velocityX[r]=i.x,this.velocityY[r]=i.y,this.velocityZ[r]=i.z,this.colorR[r]=n[0],this.colorG[r]=n[1],this.colorB[r]=n[2],this.colorA[r]=n[3],this.size[r]=e.size??2.5,this.lifetime[r]=e.lifetime,this.remaining[r]=e.lifetime,this.gravity[r]=e.gravity??800,this.damping[r]=e.damping??0,this.bounce[r]=e.bounce??.25,this.fade[r]=e.fade?1:0,this.blendMode[r]=e.blendMode==="additive"?1:0,r}update(e,r={}){let n=r.floorZ??-1/0;for(let i=0;i<this.maxParticles;i+=1){if(!this.alive[i])continue;if(this.remaining[i]-=e,this.remaining[i]<=0){this.alive[i]=0;continue}let o=Math.max(0,1-this.damping[i]*e);this.velocityX[i]*=o,this.velocityY[i]*=o,this.velocityZ[i]=this.velocityZ[i]*o-this.gravity[i]*e,this.positionX[i]+=this.velocityX[i]*e,this.positionY[i]+=this.velocityY[i]*e,this.positionZ[i]+=this.velocityZ[i]*e,this.positionZ[i]<n&&(this.positionZ[i]=n,this.velocityZ[i]=-this.velocityZ[i]*this.bounce[i],this.velocityX[i]*=.7,this.velocityY[i]*=.7)}}killAll(){this.alive.fill(0)}aliveCount(){let e=0;for(let r=0;r<this.maxParticles;r+=1)this.alive[r]&&(e+=1);return e}getState(e){return{alive:this.alive[e]===1,position:{x:this.positionX[e],y:this.positionY[e],z:this.positionZ[e]},velocity:{x:this.velocityX[e],y:this.velocityY[e],z:this.velocityZ[e]},remaining:this.remaining[e],color:[this.colorR[e],this.colorG[e],this.colorB[e],this.colorA[e]],size:this.size[e],blendMode:this.blendMode[e]===1?"additive":"alpha"}}buildMesh(e,r){let n=[],i=[],o=[],s=a=>{let c=i.length,l=0;for(let d=0;d<this.maxParticles;d+=1){if(!this.alive[d]||(a==="additive"?1:0)!==this.blendMode[d])continue;l+=1;let u=n.length/9,f=this.size[d]*.5,m=this.fade[d]?Math.max(this.remaining[d]/this.lifetime[d],0):1,p=this.blendMode[d]===1?1.2:1,y=this.colorR[d]*p,h=this.colorG[d]*p,g=this.colorB[d]*p,M=this.colorA[d]*m,x=this.positionX[d],v=this.positionY[d],b=this.positionZ[d],S=e.x*f,A=e.y*f,w=e.z*f,P=r.x*f,L=r.y*f,O=r.z*f,k=[{x:x-S-P,y:v-A-L,z:b-w-O},{x:x+S-P,y:v+A-L,z:b+w-O},{x:x-S+P,y:v-A+L,z:b-w+O},{x:x+S+P,y:v+A+L,z:b+w+O}],W=[[0,1],[1,1],[0,0],[1,0]];k.forEach((T,J)=>{n.push(T.x,T.y,T.z,W[J]?.[0]??0,W[J]?.[1]??0,y,h,g,M)}),i.push(u,u+1,u+2,u+2,u+1,u+3)}l>0&&o.push({blendMode:a,start:c,count:i.length-c})};return s("alpha"),s("additive"),{vertices:new Float32Array(n),indices:new Uint16Array(i),batches:o}}findFreeSlot(){for(let e=0;e<this.maxParticles;e+=1)if(!this.alive[e])return e;return-1}},sa=`#version 300 es
421
+ }`,Qn=class{constructor(e,r,n,i){this.gl=e,this.geometry=ra(r),this.vertexBuffer=new Se(e,e.STATIC_DRAW),this.indexBuffer=new fe(e,e.STATIC_DRAW),this.vertexArray=new we(e),this.indexCount=this.geometry.indices.length,this.vertexArray.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:48,offset:0},{index:1,size:3,type:e.FLOAT,stride:48,offset:12},{index:2,size:2,type:e.FLOAT,stride:48,offset:24},{index:3,size:4,type:e.FLOAT,stride:48,offset:32}],this.vertexBuffer),this.vertexArray.bind(),this.indexBuffer.bind(),this.indexBuffer.upload(this.geometry.indices,e.STATIC_DRAW),this.update(r,n,i)}update(e,r,n){let i=na(e,this.geometry,r,n);this.vertexBuffer.upload(i,this.gl.STATIC_DRAW)}bind(){this.vertexArray.bind(),this.indexBuffer.bind()}dispose(){this.vertexBuffer.dispose(),this.indexBuffer.dispose(),this.vertexArray.dispose(),this.wireframeIndexBuffer?.dispose()}},Lo=class{constructor(e,r,n,i){this.surfaces=new Map;this.gl=e,this.model=r,this.blend=n,this.lighting=i,r.surfaces.forEach(o=>{this.surfaces.set(o.name,new Qn(e,o,n,i))})}update(e,r){this.blend=e,this.lighting=r??this.lighting;for(let n of this.model.surfaces)this.surfaces.get(n.name)?.update(n,e,this.lighting)}dispose(){for(let e of this.surfaces.values())e.dispose();this.surfaces.clear()}},Eo=class{constructor(e){this.gl=e,this.program=ve.create(e,{vertex:ia,fragment:oa},{a_position:0,a_normal:1,a_texCoord:2,a_color:3}),this.uniformMvp=this.program.getUniformLocation("u_modelViewProjection"),this.uniformTint=this.program.getUniformLocation("u_tint"),this.uniformDiffuse=this.program.getUniformLocation("u_diffuseMap"),this.uniformRenderMode=this.program.getUniformLocation("u_renderMode"),this.uniformSolidColor=this.program.getUniformLocation("u_solidColor")}bind(e,r=[1,1,1,1],n=0){this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,e),this.gl.uniform4fv(this.uniformTint,new Float32Array(r)),this.gl.uniform1i(this.uniformDiffuse,n),this.gl.uniform1i(this.uniformRenderMode,0),this.gl.uniform4f(this.uniformSolidColor,1,1,1,1)}drawSurface(e,r){let n=r?.diffuseSampler??0,i=r?.tint??[1,1,1,1],o=r?.renderMode;this.gl.uniform4fv(this.uniformTint,new Float32Array(i)),this.gl.uniform1i(this.uniformDiffuse,n);let s=0,a=[1,1,1,1];if(o&&(o.mode==="solid"||o.mode==="wireframe"?s=1:o.mode==="solid-faceted"&&(s=2),o.color&&(a=[...o.color])),this.gl.uniform1i(this.uniformRenderMode,s),this.gl.uniform4f(this.uniformSolidColor,a[0],a[1],a[2],a[3]),e.vertexArray.bind(),o&&o.mode==="wireframe"){if(!e.wireframeIndexBuffer){e.wireframeIndexBuffer=new fe(this.gl,this.gl.STATIC_DRAW);let c=kr(e.geometry.indices);e.wireframeIndexBuffer.upload(c),e.wireframeIndexCount=c.length}e.wireframeIndexBuffer.bind(),this.gl.drawElements(this.gl.LINES,e.wireframeIndexCount,this.gl.UNSIGNED_SHORT,0)}else e.indexBuffer.bind(),this.gl.drawElements(this.gl.TRIANGLES,e.indexCount,this.gl.UNSIGNED_SHORT,0)}dispose(){this.program.dispose()}};var Of=[1,1,1,1],Io=class{constructor(e,r=Math.random){this.maxParticles=e,this.random=r,this.alive=new Uint8Array(e),this.positionX=new Float32Array(e),this.positionY=new Float32Array(e),this.positionZ=new Float32Array(e),this.velocityX=new Float32Array(e),this.velocityY=new Float32Array(e),this.velocityZ=new Float32Array(e),this.colorR=new Float32Array(e),this.colorG=new Float32Array(e),this.colorB=new Float32Array(e),this.colorA=new Float32Array(e),this.size=new Float32Array(e),this.lifetime=new Float32Array(e),this.remaining=new Float32Array(e),this.gravity=new Float32Array(e),this.damping=new Float32Array(e),this.bounce=new Float32Array(e),this.fade=new Uint8Array(e),this.blendMode=new Uint8Array(e)}spawn(e){let r=this.findFreeSlot();if(r===-1)return null;let n=e.color??Of,i=e.velocity??{x:0,y:0,z:0};return this.alive[r]=1,this.positionX[r]=e.position.x,this.positionY[r]=e.position.y,this.positionZ[r]=e.position.z,this.velocityX[r]=i.x,this.velocityY[r]=i.y,this.velocityZ[r]=i.z,this.colorR[r]=n[0],this.colorG[r]=n[1],this.colorB[r]=n[2],this.colorA[r]=n[3],this.size[r]=e.size??2.5,this.lifetime[r]=e.lifetime,this.remaining[r]=e.lifetime,this.gravity[r]=e.gravity??800,this.damping[r]=e.damping??0,this.bounce[r]=e.bounce??.25,this.fade[r]=e.fade?1:0,this.blendMode[r]=e.blendMode==="additive"?1:0,r}update(e,r={}){let n=r.floorZ??-1/0;for(let i=0;i<this.maxParticles;i+=1){if(!this.alive[i])continue;if(this.remaining[i]-=e,this.remaining[i]<=0){this.alive[i]=0;continue}let o=Math.max(0,1-this.damping[i]*e);this.velocityX[i]*=o,this.velocityY[i]*=o,this.velocityZ[i]=this.velocityZ[i]*o-this.gravity[i]*e,this.positionX[i]+=this.velocityX[i]*e,this.positionY[i]+=this.velocityY[i]*e,this.positionZ[i]+=this.velocityZ[i]*e,this.positionZ[i]<n&&(this.positionZ[i]=n,this.velocityZ[i]=-this.velocityZ[i]*this.bounce[i],this.velocityX[i]*=.7,this.velocityY[i]*=.7)}}killAll(){this.alive.fill(0)}aliveCount(){let e=0;for(let r=0;r<this.maxParticles;r+=1)this.alive[r]&&(e+=1);return e}getState(e){return{alive:this.alive[e]===1,position:{x:this.positionX[e],y:this.positionY[e],z:this.positionZ[e]},velocity:{x:this.velocityX[e],y:this.velocityY[e],z:this.velocityZ[e]},remaining:this.remaining[e],color:[this.colorR[e],this.colorG[e],this.colorB[e],this.colorA[e]],size:this.size[e],blendMode:this.blendMode[e]===1?"additive":"alpha"}}buildMesh(e,r){let n=[],i=[],o=[],s=a=>{let c=i.length,l=0;for(let d=0;d<this.maxParticles;d+=1){if(!this.alive[d]||(a==="additive"?1:0)!==this.blendMode[d])continue;l+=1;let u=n.length/9,f=this.size[d]*.5,m=this.fade[d]?Math.max(this.remaining[d]/this.lifetime[d],0):1,p=this.blendMode[d]===1?1.2:1,y=this.colorR[d]*p,h=this.colorG[d]*p,g=this.colorB[d]*p,S=this.colorA[d]*m,x=this.positionX[d],v=this.positionY[d],b=this.positionZ[d],_=e.x*f,A=e.y*f,w=e.z*f,E=r.x*f,L=r.y*f,B=r.z*f,O=[{x:x-_-E,y:v-A-L,z:b-w-B},{x:x+_-E,y:v+A-L,z:b+w-B},{x:x-_+E,y:v-A+L,z:b-w+B},{x:x+_+E,y:v+A+L,z:b+w+B}],U=[[0,1],[1,1],[0,0],[1,0]];O.forEach((C,J)=>{n.push(C.x,C.y,C.z,U[J]?.[0]??0,U[J]?.[1]??0,y,h,g,S)}),i.push(u,u+1,u+2,u+2,u+1,u+3)}l>0&&o.push({blendMode:a,start:c,count:i.length-c})};return s("alpha"),s("additive"),{vertices:new Float32Array(n),indices:new Uint16Array(i),batches:o}}findFreeSlot(){for(let e=0;e<this.maxParticles;e+=1)if(!this.alive[e])return e;return-1}},sa=`#version 300 es
422
422
  precision highp float;
423
423
 
424
424
  layout(location = 0) in vec3 a_position;
@@ -446,5 +446,5 @@ void main() {
446
446
  float dist = distance(v_uv, vec2(0.5));
447
447
  float alpha = v_color.a * (1.0 - smoothstep(0.35, 0.5, dist));
448
448
  o_color = vec4(v_color.rgb, alpha);
449
- }`,Po=class{constructor(e,r){this.vertexCapacity=0;this.indexCapacity=0;this.gl=e,this.system=r,this.program=ve.create(e,{vertex:sa,fragment:aa}),this.vertexBuffer=new Se(e,e.DYNAMIC_DRAW),this.indexBuffer=new fe(e,e.DYNAMIC_DRAW),this.vertexArray=new we(e),this.vertexArray.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:36,offset:0},{index:1,size:2,type:e.FLOAT,stride:36,offset:12},{index:2,size:4,type:e.FLOAT,stride:36,offset:20}],this.vertexBuffer)}render(e){let r=this.system.buildMesh(e.viewRight,e.viewUp);if(r.indices.length===0)return;let n=r.vertices;r.vertices.byteLength>this.vertexCapacity?(this.vertexCapacity=r.vertices.byteLength,this.vertexBuffer.upload(n,this.gl.DYNAMIC_DRAW)):this.vertexBuffer.update(n);let i=r.indices;r.indices.byteLength>this.indexCapacity?(this.indexCapacity=r.indices.byteLength,this.indexBuffer.upload(i,this.gl.DYNAMIC_DRAW)):this.indexBuffer.update(i),this.gl.depthMask(!1),this.program.use();let o=this.program.getUniformLocation("u_viewProjection");this.gl.uniformMatrix4fv(o,!1,e.viewProjection),this.vertexArray.bind();for(let s of r.batches)s.blendMode==="additive"?this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE):this.gl.blendFuncSeparate(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA),this.gl.drawElements(this.gl.TRIANGLES,s.count,this.gl.UNSIGNED_SHORT,s.start*2);this.gl.depthMask(!0)}dispose(){this.program.dispose(),this.vertexBuffer.dispose(),this.indexBuffer.dispose(),this.vertexArray.dispose()}};function fl(t){let{system:e,origin:r,normal:n={x:0,y:0,z:1}}=t;for(let i=0;i<12;i+=1){let o=200+e.random()*180,s=e.random()*.35;e.spawn({position:r,velocity:{x:n.x*o+(e.random()-.5)*80,y:n.y*o+(e.random()-.5)*80,z:Math.max(n.z*o,120)+s*80},color:[1,.8,.4,1],size:2.5,lifetime:.45+e.random()*.1,gravity:600,damping:2,bounce:.45,blendMode:"additive",fade:!0})}for(let i=0;i<8;i+=1)e.spawn({position:r,velocity:{x:(e.random()-.5)*40,y:(e.random()-.5)*40,z:80+e.random()*40},color:[.45,.45,.45,.75],size:6,lifetime:.6,gravity:200,damping:4,bounce:.15,blendMode:"alpha",fade:!0})}function ml(t){let{system:e,origin:r}=t;for(let n=0;n<40;n+=1){let i=e.random()*Math.PI*2,o=Math.acos(2*e.random()-1),s=220+e.random()*260,a={x:Math.sin(o)*Math.cos(i),y:Math.sin(o)*Math.sin(i),z:Math.cos(o)};e.spawn({position:r,velocity:{x:a.x*s,y:a.y*s,z:a.z*s},color:[1,.6,.2,1],size:5,lifetime:.9,gravity:700,damping:1,bounce:.35,blendMode:"additive",fade:!0})}for(let n=0;n<16;n+=1)e.spawn({position:r,velocity:{x:(e.random()-.5)*30,y:(e.random()-.5)*30,z:120+e.random()*120},color:[.25,.25,.25,.9],size:12,lifetime:1.2,gravity:300,damping:3,blendMode:"alpha",fade:!0})}function hl(t){let{system:e,origin:r,direction:n={x:0,y:0,z:1}}=t;for(let i=0;i<24;i+=1){let o=120+e.random()*180;e.spawn({position:r,velocity:{x:n.x*o+(e.random()-.5)*70,y:n.y*o+(e.random()-.5)*70,z:n.z*o+e.random()*80},color:[.6,0,0,.95],size:3,lifetime:.8,gravity:900,damping:1,bounce:.2,blendMode:"alpha",fade:!0})}}function pl(t){let{system:e,origin:r}=t;for(let n=0;n<30;n+=1){let i=e.random()*Math.PI*2,o=8+e.random()*8;e.spawn({position:r,velocity:{x:Math.cos(i)*o,y:Math.sin(i)*o,z:100+e.random()*80},color:[.4,.6,1,.9],size:4,lifetime:.5,gravity:300,damping:2,blendMode:"additive",fade:!0})}}function yl(t){let{system:e,origin:r,direction:n={x:1,y:0,z:0}}=t;for(let i=0;i<10;i+=1){let o=350+e.random()*100;e.spawn({position:r,velocity:{x:n.x*o+(e.random()-.5)*30,y:n.y*o+(e.random()-.5)*30,z:n.z*o+(e.random()-.5)*30},color:[1,.8,.3,1],size:3,lifetime:.25,gravity:200,damping:1,blendMode:"additive",fade:!0})}}function gl(t){let{system:e,origin:r,direction:n={x:0,y:0,z:0}}=t;for(let i=0;i<6;i+=1)e.spawn({position:{x:r.x+n.x*i*2,y:r.y+n.y*i*2,z:r.z+n.z*i*2},velocity:{x:(e.random()-.5)*15,y:(e.random()-.5)*15,z:20+e.random()*15},color:[.6,.6,.6,.8],size:2.2,lifetime:.6,gravity:200,damping:1.5,blendMode:"alpha",fade:!0})}var tr=class{constructor(e){this.buffer=e,this.view=new DataView(e),this.offset=0}hasMore(){return this.offset<this.buffer.byteLength}readNextBlock(){if(this.offset+4>this.buffer.byteLength)return null;let e=this.view.getInt32(this.offset,!0);if(this.offset+=4,e<0||e>262144)return console.warn(`DemoReader: Invalid block length ${e} at offset ${this.offset-4}`),null;if(this.offset+e>this.buffer.byteLength)return console.warn(`DemoReader: Incomplete block. Expected ${e} bytes, but only ${this.buffer.byteLength-this.offset} remain.`),null;let r=this.buffer.slice(this.offset,this.offset+e);return this.offset+=e,{length:e,data:new Ca(r)}}reset(){this.offset=0}getOffset(){return this.offset}};var zo=1,Ro=2,To=4,Fo=8,Bo=16,Do=32,ca=64,Of=128,Nf=256,Oo=512,No=1024,ko=2048,Jn=4096,Zn=16384,kf=32768,ei=65536,Uo=1<<17,ti=1<<18,ri=1<<19,Ho=1<<20,Vo=1<<21,Go=1<<22,Uf=1<<23,Wo=1<<24,ni=1<<25,Xo=1<<26,Ko=1<<27;var Hf=1,Vf=2,Gf=128,rr=()=>({number:0,modelindex:0,modelindex2:0,modelindex3:0,modelindex4:0,frame:0,skinnum:0,effects:0,renderfx:0,origin:{x:0,y:0,z:0},old_origin:{x:0,y:0,z:0},angles:{x:0,y:0,z:0},sound:0,event:0,solid:0,bits:0}),Co=()=>({pm_type:0,origin:{x:0,y:0,z:0},velocity:{x:0,y:0,z:0},pm_time:0,pm_flags:0,gravity:0,delta_angles:{x:0,y:0,z:0},viewoffset:{x:0,y:0,z:0},viewangles:{x:0,y:0,z:0},kick_angles:{x:0,y:0,z:0},gun_index:0,gun_frame:0,gun_offset:{x:0,y:0,z:0},gun_angles:{x:0,y:0,z:0},blend:[0,0,0,0],fov:0,rdflags:0,stats:new Array(32).fill(0)}),nr=class{constructor(e,r){this.protocolVersion=0;this.isDemo=Hf;this.stream=e,this.handler=r}translateCommand(e){if(this.protocolVersion===0){if(e===7)return U.serverdata;if(e===12)return U.serverdata}if(this.protocolVersion===25){if(e>=7&&e<=15)return e+5;if(e===1)return U.print;if(e===2)return U.stufftext;if(e===3)return U.sound;if(e===4)return U.nop;if(e===5)return U.disconnect;if(e===6)return U.reconnect;if(e===16)return U.temp_entity}return e}parseMessage(){for(;this.stream.hasMore();){let e=this.stream.readByte();if(e===-1)break;let r=e;e=this.translateCommand(e);try{switch(e){case U.nop:break;case U.disconnect:break;case U.reconnect:break;case U.print:this.parsePrint();break;case U.serverdata:this.parseServerData();break;case U.configstring:this.parseConfigString();break;case U.spawnbaseline:this.parseSpawnBaseline();break;case U.centerprint:this.parseCenterPrint();break;case U.download:this.parseDownload();break;case U.frame:this.parseFrame();break;case U.packetentities:this.parsePacketEntities(!1);break;case U.deltapacketentities:this.parsePacketEntities(!0);break;case U.playerinfo:this.parsePlayerState();break;case U.stufftext:this.parseStuffText();break;case U.layout:this.parseLayout();break;case U.inventory:this.parseInventory();break;case U.sound:this.parseSound();break;case U.muzzleflash:this.parseMuzzleFlash();break;case U.muzzleflash2:this.parseMuzzleFlash2();break;case U.temp_entity:this.parseTempEntity();break;default:console.warn(`Unknown server command: ${r} (translated: ${e}) at offset ${this.stream.getPosition()-1}`);return}}catch(n){console.warn(`Error parsing command ${e}: ${n.message}`);return}}}parsePrint(){let e=this.stream.readByte(),r=this.stream.readString()}parseStuffText(){let e=this.stream.readString()}parseLayout(){let e=this.stream.readString()}parseCenterPrint(){let e=this.stream.readString()}parseServerData(){this.protocolVersion=this.stream.readLong();let e=this.stream.readLong();this.isDemo=this.stream.readByte();let r=0,n=this.stream.readString(),i=this.stream.readShort(),o=this.stream.readString();this.handler?this.handler.onServerData(this.protocolVersion,e,r,n,i,o):console.log(`Server Data: Protocol ${this.protocolVersion}, Level ${o}, GameDir ${n}`)}parseConfigString(){let e=this.stream.readShort(),r=this.stream.readString();this.handler&&this.handler.onConfigString(e,r)}parseDownload(){let e=this.stream.readShort(),r=this.stream.readByte(),n;e>0&&(n=this.stream.readData(e)),this.handler&&this.handler.onDownload(e,r,n)}parseInventory(){let r=new Array(256);for(let n=0;n<256;n++)r[n]=this.stream.readShort();this.handler&&this.handler.onInventory(r)}parseSound(){let e=this.stream.readByte(),r=this.stream.readByte(),n,i,o,s,a;if(e&1&&(n=this.stream.readByte()),e&2&&(i=this.stream.readByte()),e&16&&(o=this.stream.readByte()),e&8&&(s=this.stream.readShort()),e&4){let c={x:0,y:0,z:0};this.stream.readPos(c),a=c}this.handler&&this.handler.onSound(e,r,n,i,o,s,a)}parseMuzzleFlash(){let e=this.stream.readShort(),r=this.stream.readByte();this.handler&&this.handler.onMuzzleFlash(e,r)}parseMuzzleFlash2(){let e=this.stream.readShort(),r=this.stream.readByte();this.handler&&this.handler.onMuzzleFlash2(e,r)}parseTempEntity(){let e=this.stream.readByte(),r={x:0,y:0,z:0},n={x:0,y:0,z:0},i={x:0,y:0,z:0},o,s,a,c,l;switch(e){case E.EXPLOSION1:case E.EXPLOSION2:case E.ROCKET_EXPLOSION:case E.GRENADE_EXPLOSION:case E.ROCKET_EXPLOSION_WATER:case E.GRENADE_EXPLOSION_WATER:case E.BFG_EXPLOSION:case E.BFG_BIGEXPLOSION:case E.BOSSTPORT:case E.PLASMA_EXPLOSION:case E.PLAIN_EXPLOSION:case E.CHAINFIST_SMOKE:case E.TRACKER_EXPLOSION:case E.TELEPORT_EFFECT:case E.DBALL_GOAL:case E.NUKEBLAST:case E.WIDOWSPLASH:case E.EXPLOSION1_BIG:case E.EXPLOSION1_NP:this.stream.readPos(r);break;case E.GUNSHOT:case E.BLOOD:case E.BLASTER:case E.SHOTGUN:case E.SPARKS:case E.BULLET_SPARKS:case E.SCREEN_SPARKS:case E.SHIELD_SPARKS:case E.BLASTER2:case E.FLECHETTE:case E.MOREBLOOD:case E.ELECTRIC_SPARKS:case E.HEATBEAM_SPARKS:case E.HEATBEAM_STEAM:this.stream.readPos(r),this.stream.readDir(i);break;case E.SPLASH:case E.LASER_SPARKS:case E.WELDING_SPARKS:case E.TUNNEL_SPARKS:o=this.stream.readByte(),this.stream.readPos(r),this.stream.readDir(i),s=this.stream.readByte();break;case E.BLUEHYPERBLASTER:this.protocolVersion>=32?(this.stream.readPos(r),this.stream.readPos(n)):(this.stream.readPos(r),this.stream.readDir(i));break;case E.GREENBLOOD:this.protocolVersion>=32?(this.stream.readPos(r),this.stream.readDir(i)):(this.stream.readPos(r),this.stream.readPos(n));break;case E.RAILTRAIL:case E.BUBBLETRAIL:case E.BFG_LASER:case E.DEBUGTRAIL:case E.BUBBLETRAIL2:this.stream.readPos(r),this.stream.readPos(n);break;case E.PARASITE_ATTACK:case E.MEDIC_CABLE_ATTACK:this.stream.readShort(),this.stream.readPos(r),this.stream.readPos(n);break;case E.GRAPPLE_CABLE:a=this.stream.readShort(),this.stream.readPos(r),this.stream.readPos(n),this.stream.readPos(i);break;case E.LIGHTNING:c=this.stream.readShort(),l=this.stream.readShort(),this.stream.readPos(r),this.stream.readPos(n);break;case E.FLASHLIGHT:this.stream.readPos(r),a=this.stream.readShort();break;case E.FORCEWALL:this.stream.readPos(r),this.stream.readPos(n),s=this.stream.readByte();break;case E.STEAM:let d=this.stream.readShort();o=this.stream.readByte(),this.stream.readPos(r),this.stream.readDir(i),s=this.stream.readByte(),this.stream.readShort(),d!==-1&&this.stream.readLong();break;case E.WIDOWBEAMOUT:this.stream.readShort();case E.HEATBEAM:case E.MONSTER_HEATBEAM:a=this.stream.readShort(),this.stream.readPos(r),this.stream.readPos(n),this.stream.readPos(i);break;default:break}this.handler&&this.handler.onTempEntity(e,r,n,i,o,s,a,c,l)}parseSpawnBaseline(){let e=this.parseEntityBits(),r=rr();this.parseDelta(rr(),r,e.number,e.bits),this.handler&&this.handler.onSpawnBaseline(r)}parseFrame(){let e=this.stream.readLong(),r=this.stream.readLong(),n=this.stream.readByte(),i=this.stream.readByte(),o=this.stream.readData(i),s=this.stream.readByte();if(s!==U.playerinfo)throw new Error(`Expected svc_playerinfo after svc_frame, got ${s}`);let a=this.parsePlayerState();if(this.isDemo===Gf){let c=this.stream.readByte();for(let l=0;l<c;l++)this.stream.readByte()}this.isDemo===Vf&&this.stream.readLong(),this.handler&&this.handler.onFrame({serverFrame:e,deltaFrame:r,surpressCount:n,areaBytes:i,areaBits:o,playerState:a,packetEntities:{delta:!1,entities:[]}})}parsePlayerState(){let e=Co(),r=this.stream.readShort();r&1&&(e.pm_type=this.stream.readByte()),r&2&&(e.origin.x=this.stream.readShort()*.125,e.origin.y=this.stream.readShort()*.125,e.origin.z=this.stream.readShort()*.125),r&4&&(e.velocity.x=this.stream.readShort()*.125,e.velocity.y=this.stream.readShort()*.125,e.velocity.z=this.stream.readShort()*.125),r&8&&(e.pm_time=this.stream.readByte()),r&16&&(e.pm_flags=this.stream.readByte()),r&32&&(e.gravity=this.stream.readShort()),r&64&&(e.delta_angles.x=this.stream.readShort()*(180/32768),e.delta_angles.y=this.stream.readShort()*(180/32768),e.delta_angles.z=this.stream.readShort()*(180/32768)),r&128&&(e.viewoffset.x=this.stream.readChar()*.25,e.viewoffset.y=this.stream.readChar()*.25,e.viewoffset.z=this.stream.readChar()*.25),r&256&&(e.viewangles.x=this.stream.readAngle16(),e.viewangles.y=this.stream.readAngle16(),e.viewangles.z=this.stream.readAngle16()),r&512&&(e.kick_angles.x=this.stream.readChar()*.25,e.kick_angles.y=this.stream.readChar()*.25,e.kick_angles.z=this.stream.readChar()*.25),r&4096&&(e.gun_index=this.stream.readByte()),r&8192&&(e.gun_frame=this.stream.readByte(),e.gun_offset.x=this.stream.readChar()*.25,e.gun_offset.y=this.stream.readChar()*.25,e.gun_offset.z=this.stream.readChar()*.25,e.gun_angles.x=this.stream.readChar()*.25,e.gun_angles.y=this.stream.readChar()*.25,e.gun_angles.z=this.stream.readChar()*.25),r&1024&&(e.blend[0]=this.stream.readByte(),e.blend[1]=this.stream.readByte(),e.blend[2]=this.stream.readByte(),e.blend[3]=this.stream.readByte()),r&2048&&(e.fov=this.stream.readByte()),r&16384&&(e.rdflags=this.stream.readByte());let n=this.stream.readLong();for(let i=0;i<32;i++)n&1<<i&&(e.stats[i]=this.stream.readShort());return e}parsePacketEntities(e){let r=this.collectPacketEntities();this.handler&&this.handler.onFrame({serverFrame:0,deltaFrame:0,surpressCount:0,areaBytes:0,areaBits:new Uint8Array,playerState:Co(),packetEntities:{delta:e,entities:r}})}collectPacketEntities(){let e=[];for(;;){let r=this.parseEntityBits();if(r.number===0)break;let n=rr();this.parseDelta(rr(),n,r.number,r.bits),e.push(n)}return e}parseEntityBits(){let e=this.stream.readByte();e&Of&&(e|=this.stream.readByte()<<8),e&kf&&(e|=this.stream.readByte()<<16),e&Uf&&(e|=this.stream.readByte()<<24);let r;return e&Nf?r=this.stream.readShort():r=this.stream.readByte(),{number:r,bits:e}}parseDelta(e,r,n,i){r.number=e.number,r.modelindex=e.modelindex,r.modelindex2=e.modelindex2,r.modelindex3=e.modelindex3,r.modelindex4=e.modelindex4,r.frame=e.frame,r.skinnum=e.skinnum,r.effects=e.effects,r.renderfx=e.renderfx,r.origin.x=e.origin.x,r.origin.y=e.origin.y,r.origin.z=e.origin.z,r.old_origin.x=e.origin.x,r.old_origin.y=e.origin.y,r.old_origin.z=e.origin.z,r.angles.x=e.angles.x,r.angles.y=e.angles.y,r.angles.z=e.angles.z,r.sound=e.sound,r.event=e.event,r.solid=e.solid,r.number=n,r.bits=i,i&ko&&(r.modelindex=this.stream.readByte()),i&Ho&&(r.modelindex2=this.stream.readByte()),i&Vo&&(r.modelindex3=this.stream.readByte()),i&Go&&(r.modelindex4=this.stream.readByte()),i&Bo&&(r.frame=this.stream.readByte()),i&Uo&&(r.frame=this.stream.readShort()),i&ei&&i&ni?r.skinnum=this.stream.readLong():i&ei?r.skinnum=this.stream.readByte():i&ni&&(r.skinnum=this.stream.readShort()),i&Zn&&i&ri?r.effects=this.stream.readLong():i&Zn?r.effects=this.stream.readByte():i&ri&&(r.effects=this.stream.readShort()),i&Jn&&i&ti?r.renderfx=this.stream.readLong():i&Jn?r.renderfx=this.stream.readByte():i&ti&&(r.renderfx=this.stream.readShort()),i&zo&&(r.origin.x=this.stream.readCoord()),i&Ro&&(r.origin.y=this.stream.readCoord()),i&Oo&&(r.origin.z=this.stream.readCoord()),i&No&&(r.angles.x=this.stream.readAngle()),i&To&&(r.angles.y=this.stream.readAngle()),i&Fo&&(r.angles.z=this.stream.readAngle()),i&Wo&&this.stream.readPos(r.old_origin),i&Xo&&(r.sound=this.stream.readByte()),i&Do?r.event=this.stream.readByte():r.event=0,i&Ko&&(r.solid=this.stream.readShort())}};var Yo=(i=>(i[i.Stopped=0]="Stopped",i[i.Playing=1]="Playing",i[i.Paused=2]="Paused",i[i.Finished=3]="Finished",i))(Yo||{}),ii=class{constructor(){this.reader=null;this.state=0;this.playbackSpeed=1;this.accumulatedTime=0;this.frameDuration=100}setHandler(e){this.handler=e}loadDemo(e){this.reader=new tr(e),this.state=0,this.accumulatedTime=0}play(){this.reader&&(this.state=1)}pause(){this.state===1&&(this.state=2)}stop(){this.state=0,this.reader&&this.reader.reset(),this.accumulatedTime=0}update(e){if(!(this.state!==1||!this.reader))for(this.accumulatedTime+=e*1e3*this.playbackSpeed;this.accumulatedTime>=this.frameDuration;){if(!this.reader.hasMore()){this.state=3;return}let r=this.reader.readNextBlock();if(!r){this.state=3;return}new nr(r.data,this.handler).parseMessage(),this.accumulatedTime-=this.frameDuration}}getState(){return this.state}};function Wf(t){return{init(){t.trace({x:0,y:0,z:0},{x:0,y:0,z:0})},shutdown(){},createMainLoop(e,r){return new Dt(e,r)}}}return El(Xf);})();
449
+ }`,Po=class{constructor(e,r){this.vertexCapacity=0;this.indexCapacity=0;this.gl=e,this.system=r,this.program=ve.create(e,{vertex:sa,fragment:aa}),this.vertexBuffer=new Se(e,e.DYNAMIC_DRAW),this.indexBuffer=new fe(e,e.DYNAMIC_DRAW),this.vertexArray=new we(e),this.vertexArray.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:36,offset:0},{index:1,size:2,type:e.FLOAT,stride:36,offset:12},{index:2,size:4,type:e.FLOAT,stride:36,offset:20}],this.vertexBuffer)}render(e){let r=this.system.buildMesh(e.viewRight,e.viewUp);if(r.indices.length===0)return;let n=r.vertices;r.vertices.byteLength>this.vertexCapacity?(this.vertexCapacity=r.vertices.byteLength,this.vertexBuffer.upload(n,this.gl.DYNAMIC_DRAW)):this.vertexBuffer.update(n);let i=r.indices;r.indices.byteLength>this.indexCapacity?(this.indexCapacity=r.indices.byteLength,this.indexBuffer.upload(i,this.gl.DYNAMIC_DRAW)):this.indexBuffer.update(i),this.gl.depthMask(!1),this.program.use();let o=this.program.getUniformLocation("u_viewProjection");this.gl.uniformMatrix4fv(o,!1,e.viewProjection),this.vertexArray.bind();for(let s of r.batches)s.blendMode==="additive"?this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE):this.gl.blendFuncSeparate(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA),this.gl.drawElements(this.gl.TRIANGLES,s.count,this.gl.UNSIGNED_SHORT,s.start*2);this.gl.depthMask(!0)}dispose(){this.program.dispose(),this.vertexBuffer.dispose(),this.indexBuffer.dispose(),this.vertexArray.dispose()}};function fl(t){let{system:e,origin:r,normal:n={x:0,y:0,z:1}}=t;for(let i=0;i<12;i+=1){let o=200+e.random()*180,s=e.random()*.35;e.spawn({position:r,velocity:{x:n.x*o+(e.random()-.5)*80,y:n.y*o+(e.random()-.5)*80,z:Math.max(n.z*o,120)+s*80},color:[1,.8,.4,1],size:2.5,lifetime:.45+e.random()*.1,gravity:600,damping:2,bounce:.45,blendMode:"additive",fade:!0})}for(let i=0;i<8;i+=1)e.spawn({position:r,velocity:{x:(e.random()-.5)*40,y:(e.random()-.5)*40,z:80+e.random()*40},color:[.45,.45,.45,.75],size:6,lifetime:.6,gravity:200,damping:4,bounce:.15,blendMode:"alpha",fade:!0})}function ml(t){let{system:e,origin:r}=t;for(let n=0;n<40;n+=1){let i=e.random()*Math.PI*2,o=Math.acos(2*e.random()-1),s=220+e.random()*260,a={x:Math.sin(o)*Math.cos(i),y:Math.sin(o)*Math.sin(i),z:Math.cos(o)};e.spawn({position:r,velocity:{x:a.x*s,y:a.y*s,z:a.z*s},color:[1,.6,.2,1],size:5,lifetime:.9,gravity:700,damping:1,bounce:.35,blendMode:"additive",fade:!0})}for(let n=0;n<16;n+=1)e.spawn({position:r,velocity:{x:(e.random()-.5)*30,y:(e.random()-.5)*30,z:120+e.random()*120},color:[.25,.25,.25,.9],size:12,lifetime:1.2,gravity:300,damping:3,blendMode:"alpha",fade:!0})}function hl(t){let{system:e,origin:r,direction:n={x:0,y:0,z:1}}=t;for(let i=0;i<24;i+=1){let o=120+e.random()*180;e.spawn({position:r,velocity:{x:n.x*o+(e.random()-.5)*70,y:n.y*o+(e.random()-.5)*70,z:n.z*o+e.random()*80},color:[.6,0,0,.95],size:3,lifetime:.8,gravity:900,damping:1,bounce:.2,blendMode:"alpha",fade:!0})}}function pl(t){let{system:e,origin:r}=t;for(let n=0;n<30;n+=1){let i=e.random()*Math.PI*2,o=8+e.random()*8;e.spawn({position:r,velocity:{x:Math.cos(i)*o,y:Math.sin(i)*o,z:100+e.random()*80},color:[.4,.6,1,.9],size:4,lifetime:.5,gravity:300,damping:2,blendMode:"additive",fade:!0})}}function yl(t){let{system:e,origin:r,direction:n={x:1,y:0,z:0}}=t;for(let i=0;i<10;i+=1){let o=350+e.random()*100;e.spawn({position:r,velocity:{x:n.x*o+(e.random()-.5)*30,y:n.y*o+(e.random()-.5)*30,z:n.z*o+(e.random()-.5)*30},color:[1,.8,.3,1],size:3,lifetime:.25,gravity:200,damping:1,blendMode:"additive",fade:!0})}}function gl(t){let{system:e,origin:r,direction:n={x:0,y:0,z:0}}=t;for(let i=0;i<6;i+=1)e.spawn({position:{x:r.x+n.x*i*2,y:r.y+n.y*i*2,z:r.z+n.z*i*2},velocity:{x:(e.random()-.5)*15,y:(e.random()-.5)*15,z:20+e.random()*15},color:[.6,.6,.6,.8],size:2.2,lifetime:.6,gravity:200,damping:1.5,blendMode:"alpha",fade:!0})}var tr=class{constructor(e){this.buffer=e,this.view=new DataView(e),this.offset=0}hasMore(){return this.offset<this.buffer.byteLength}readNextBlock(){if(this.offset+4>this.buffer.byteLength)return null;let e=this.view.getInt32(this.offset,!0);if(this.offset+=4,e<0||e>262144)return console.warn(`DemoReader: Invalid block length ${e} at offset ${this.offset-4}`),null;if(this.offset+e>this.buffer.byteLength)return console.warn(`DemoReader: Incomplete block. Expected ${e} bytes, but only ${this.buffer.byteLength-this.offset} remain.`),null;let r=this.buffer.slice(this.offset,this.offset+e);return this.offset+=e,{length:e,data:new Ca(r)}}reset(){this.offset=0}getOffset(){return this.offset}};var zo=1,Ro=2,To=4,Fo=8,Bo=16,Do=32,ca=64,Nf=128,kf=256,Oo=512,No=1024,ko=2048,Jn=4096,Zn=16384,Uf=32768,ei=65536,Uo=1<<17,ti=1<<18,ri=1<<19,Ho=1<<20,Vo=1<<21,Go=1<<22,Hf=1<<23,Wo=1<<24,ni=1<<25,Xo=1<<26,Ko=1<<27;var Vf=1,Gf=2,Wf=128,rr=()=>({number:0,modelindex:0,modelindex2:0,modelindex3:0,modelindex4:0,frame:0,skinnum:0,effects:0,renderfx:0,origin:{x:0,y:0,z:0},old_origin:{x:0,y:0,z:0},angles:{x:0,y:0,z:0},sound:0,event:0,solid:0,bits:0}),Co=()=>({pm_type:0,origin:{x:0,y:0,z:0},velocity:{x:0,y:0,z:0},pm_time:0,pm_flags:0,gravity:0,delta_angles:{x:0,y:0,z:0},viewoffset:{x:0,y:0,z:0},viewangles:{x:0,y:0,z:0},kick_angles:{x:0,y:0,z:0},gun_index:0,gun_frame:0,gun_offset:{x:0,y:0,z:0},gun_angles:{x:0,y:0,z:0},blend:[0,0,0,0],fov:0,rdflags:0,stats:new Array(32).fill(0)}),nr=class{constructor(e,r){this.protocolVersion=0;this.isDemo=Vf;this.stream=e,this.handler=r}translateCommand(e){if(this.protocolVersion===0){if(e===7)return H.serverdata;if(e===12)return H.serverdata}if(this.protocolVersion===25){if(e>=7&&e<=15)return e+5;if(e===1)return H.print;if(e===2)return H.stufftext;if(e===3)return H.sound;if(e===4)return H.nop;if(e===5)return H.disconnect;if(e===6)return H.reconnect;if(e===16)return H.temp_entity}return e}parseMessage(){for(;this.stream.hasMore();){let e=this.stream.readByte();if(e===-1)break;let r=e;e=this.translateCommand(e);try{switch(e){case H.nop:break;case H.disconnect:break;case H.reconnect:break;case H.print:this.parsePrint();break;case H.serverdata:this.parseServerData();break;case H.configstring:this.parseConfigString();break;case H.spawnbaseline:this.parseSpawnBaseline();break;case H.centerprint:this.parseCenterPrint();break;case H.download:this.parseDownload();break;case H.frame:this.parseFrame();break;case H.packetentities:this.parsePacketEntities(!1);break;case H.deltapacketentities:this.parsePacketEntities(!0);break;case H.playerinfo:this.parsePlayerState();break;case H.stufftext:this.parseStuffText();break;case H.layout:this.parseLayout();break;case H.inventory:this.parseInventory();break;case H.sound:this.parseSound();break;case H.muzzleflash:this.parseMuzzleFlash();break;case H.muzzleflash2:this.parseMuzzleFlash2();break;case H.temp_entity:this.parseTempEntity();break;default:console.warn(`Unknown server command: ${r} (translated: ${e}) at offset ${this.stream.getPosition()-1}`);return}}catch(n){console.warn(`Error parsing command ${e}: ${n.message}`);return}}}parsePrint(){let e=this.stream.readByte(),r=this.stream.readString()}parseStuffText(){let e=this.stream.readString()}parseLayout(){let e=this.stream.readString()}parseCenterPrint(){let e=this.stream.readString()}parseServerData(){this.protocolVersion=this.stream.readLong();let e=this.stream.readLong();this.isDemo=this.stream.readByte();let r=0,n=this.stream.readString(),i=this.stream.readShort(),o=this.stream.readString();this.handler?this.handler.onServerData(this.protocolVersion,e,r,n,i,o):console.log(`Server Data: Protocol ${this.protocolVersion}, Level ${o}, GameDir ${n}`)}parseConfigString(){let e=this.stream.readShort(),r=this.stream.readString();this.handler&&this.handler.onConfigString(e,r)}parseDownload(){let e=this.stream.readShort(),r=this.stream.readByte(),n;e>0&&(n=this.stream.readData(e)),this.handler&&this.handler.onDownload(e,r,n)}parseInventory(){let r=new Array(256);for(let n=0;n<256;n++)r[n]=this.stream.readShort();this.handler&&this.handler.onInventory(r)}parseSound(){let e=this.stream.readByte(),r=this.stream.readByte(),n,i,o,s,a;if(e&1&&(n=this.stream.readByte()),e&2&&(i=this.stream.readByte()),e&16&&(o=this.stream.readByte()),e&8&&(s=this.stream.readShort()),e&4){let c={x:0,y:0,z:0};this.stream.readPos(c),a=c}this.handler&&this.handler.onSound(e,r,n,i,o,s,a)}parseMuzzleFlash(){let e=this.stream.readShort(),r=this.stream.readByte();this.handler&&this.handler.onMuzzleFlash(e,r)}parseMuzzleFlash2(){let e=this.stream.readShort(),r=this.stream.readByte();this.handler&&this.handler.onMuzzleFlash2(e,r)}parseTempEntity(){let e=this.stream.readByte(),r={x:0,y:0,z:0},n={x:0,y:0,z:0},i={x:0,y:0,z:0},o,s,a,c,l;switch(e){case I.EXPLOSION1:case I.EXPLOSION2:case I.ROCKET_EXPLOSION:case I.GRENADE_EXPLOSION:case I.ROCKET_EXPLOSION_WATER:case I.GRENADE_EXPLOSION_WATER:case I.BFG_EXPLOSION:case I.BFG_BIGEXPLOSION:case I.BOSSTPORT:case I.PLASMA_EXPLOSION:case I.PLAIN_EXPLOSION:case I.CHAINFIST_SMOKE:case I.TRACKER_EXPLOSION:case I.TELEPORT_EFFECT:case I.DBALL_GOAL:case I.NUKEBLAST:case I.WIDOWSPLASH:case I.EXPLOSION1_BIG:case I.EXPLOSION1_NP:this.stream.readPos(r);break;case I.GUNSHOT:case I.BLOOD:case I.BLASTER:case I.SHOTGUN:case I.SPARKS:case I.BULLET_SPARKS:case I.SCREEN_SPARKS:case I.SHIELD_SPARKS:case I.BLASTER2:case I.FLECHETTE:case I.MOREBLOOD:case I.ELECTRIC_SPARKS:case I.HEATBEAM_SPARKS:case I.HEATBEAM_STEAM:this.stream.readPos(r),this.stream.readDir(i);break;case I.SPLASH:case I.LASER_SPARKS:case I.WELDING_SPARKS:case I.TUNNEL_SPARKS:o=this.stream.readByte(),this.stream.readPos(r),this.stream.readDir(i),s=this.stream.readByte();break;case I.BLUEHYPERBLASTER:this.protocolVersion>=32?(this.stream.readPos(r),this.stream.readPos(n)):(this.stream.readPos(r),this.stream.readDir(i));break;case I.GREENBLOOD:this.protocolVersion>=32?(this.stream.readPos(r),this.stream.readDir(i)):(this.stream.readPos(r),this.stream.readPos(n));break;case I.RAILTRAIL:case I.BUBBLETRAIL:case I.BFG_LASER:case I.DEBUGTRAIL:case I.BUBBLETRAIL2:this.stream.readPos(r),this.stream.readPos(n);break;case I.PARASITE_ATTACK:case I.MEDIC_CABLE_ATTACK:this.stream.readShort(),this.stream.readPos(r),this.stream.readPos(n);break;case I.GRAPPLE_CABLE:a=this.stream.readShort(),this.stream.readPos(r),this.stream.readPos(n),this.stream.readPos(i);break;case I.LIGHTNING:c=this.stream.readShort(),l=this.stream.readShort(),this.stream.readPos(r),this.stream.readPos(n);break;case I.FLASHLIGHT:this.stream.readPos(r),a=this.stream.readShort();break;case I.FORCEWALL:this.stream.readPos(r),this.stream.readPos(n),s=this.stream.readByte();break;case I.STEAM:let d=this.stream.readShort();o=this.stream.readByte(),this.stream.readPos(r),this.stream.readDir(i),s=this.stream.readByte(),this.stream.readShort(),d!==-1&&this.stream.readLong();break;case I.WIDOWBEAMOUT:this.stream.readShort();case I.HEATBEAM:case I.MONSTER_HEATBEAM:a=this.stream.readShort(),this.stream.readPos(r),this.stream.readPos(n),this.stream.readPos(i);break;default:break}this.handler&&this.handler.onTempEntity(e,r,n,i,o,s,a,c,l)}parseSpawnBaseline(){let e=this.parseEntityBits(),r=rr();this.parseDelta(rr(),r,e.number,e.bits),this.handler&&this.handler.onSpawnBaseline(r)}parseFrame(){let e=this.stream.readLong(),r=this.stream.readLong(),n=this.stream.readByte(),i=this.stream.readByte(),o=this.stream.readData(i),s=this.stream.readByte();if(s!==H.playerinfo)throw new Error(`Expected svc_playerinfo after svc_frame, got ${s}`);let a=this.parsePlayerState();if(this.isDemo===Wf){let c=this.stream.readByte();for(let l=0;l<c;l++)this.stream.readByte()}this.isDemo===Gf&&this.stream.readLong(),this.handler&&this.handler.onFrame({serverFrame:e,deltaFrame:r,surpressCount:n,areaBytes:i,areaBits:o,playerState:a,packetEntities:{delta:!1,entities:[]}})}parsePlayerState(){let e=Co(),r=this.stream.readShort();r&1&&(e.pm_type=this.stream.readByte()),r&2&&(e.origin.x=this.stream.readShort()*.125,e.origin.y=this.stream.readShort()*.125,e.origin.z=this.stream.readShort()*.125),r&4&&(e.velocity.x=this.stream.readShort()*.125,e.velocity.y=this.stream.readShort()*.125,e.velocity.z=this.stream.readShort()*.125),r&8&&(e.pm_time=this.stream.readByte()),r&16&&(e.pm_flags=this.stream.readByte()),r&32&&(e.gravity=this.stream.readShort()),r&64&&(e.delta_angles.x=this.stream.readShort()*(180/32768),e.delta_angles.y=this.stream.readShort()*(180/32768),e.delta_angles.z=this.stream.readShort()*(180/32768)),r&128&&(e.viewoffset.x=this.stream.readChar()*.25,e.viewoffset.y=this.stream.readChar()*.25,e.viewoffset.z=this.stream.readChar()*.25),r&256&&(e.viewangles.x=this.stream.readAngle16(),e.viewangles.y=this.stream.readAngle16(),e.viewangles.z=this.stream.readAngle16()),r&512&&(e.kick_angles.x=this.stream.readChar()*.25,e.kick_angles.y=this.stream.readChar()*.25,e.kick_angles.z=this.stream.readChar()*.25),r&4096&&(e.gun_index=this.stream.readByte()),r&8192&&(e.gun_frame=this.stream.readByte(),e.gun_offset.x=this.stream.readChar()*.25,e.gun_offset.y=this.stream.readChar()*.25,e.gun_offset.z=this.stream.readChar()*.25,e.gun_angles.x=this.stream.readChar()*.25,e.gun_angles.y=this.stream.readChar()*.25,e.gun_angles.z=this.stream.readChar()*.25),r&1024&&(e.blend[0]=this.stream.readByte(),e.blend[1]=this.stream.readByte(),e.blend[2]=this.stream.readByte(),e.blend[3]=this.stream.readByte()),r&2048&&(e.fov=this.stream.readByte()),r&16384&&(e.rdflags=this.stream.readByte());let n=this.stream.readLong();for(let i=0;i<32;i++)n&1<<i&&(e.stats[i]=this.stream.readShort());return e}parsePacketEntities(e){let r=this.collectPacketEntities();this.handler&&this.handler.onFrame({serverFrame:0,deltaFrame:0,surpressCount:0,areaBytes:0,areaBits:new Uint8Array,playerState:Co(),packetEntities:{delta:e,entities:r}})}collectPacketEntities(){let e=[];for(;;){let r=this.parseEntityBits();if(r.number===0)break;let n=rr();this.parseDelta(rr(),n,r.number,r.bits),e.push(n)}return e}parseEntityBits(){let e=this.stream.readByte();e&Nf&&(e|=this.stream.readByte()<<8),e&Uf&&(e|=this.stream.readByte()<<16),e&Hf&&(e|=this.stream.readByte()<<24);let r;return e&kf?r=this.stream.readShort():r=this.stream.readByte(),{number:r,bits:e}}parseDelta(e,r,n,i){r.number=e.number,r.modelindex=e.modelindex,r.modelindex2=e.modelindex2,r.modelindex3=e.modelindex3,r.modelindex4=e.modelindex4,r.frame=e.frame,r.skinnum=e.skinnum,r.effects=e.effects,r.renderfx=e.renderfx,r.origin.x=e.origin.x,r.origin.y=e.origin.y,r.origin.z=e.origin.z,r.old_origin.x=e.origin.x,r.old_origin.y=e.origin.y,r.old_origin.z=e.origin.z,r.angles.x=e.angles.x,r.angles.y=e.angles.y,r.angles.z=e.angles.z,r.sound=e.sound,r.event=e.event,r.solid=e.solid,r.number=n,r.bits=i,i&ko&&(r.modelindex=this.stream.readByte()),i&Ho&&(r.modelindex2=this.stream.readByte()),i&Vo&&(r.modelindex3=this.stream.readByte()),i&Go&&(r.modelindex4=this.stream.readByte()),i&Bo&&(r.frame=this.stream.readByte()),i&Uo&&(r.frame=this.stream.readShort()),i&ei&&i&ni?r.skinnum=this.stream.readLong():i&ei?r.skinnum=this.stream.readByte():i&ni&&(r.skinnum=this.stream.readShort()),i&Zn&&i&ri?r.effects=this.stream.readLong():i&Zn?r.effects=this.stream.readByte():i&ri&&(r.effects=this.stream.readShort()),i&Jn&&i&ti?r.renderfx=this.stream.readLong():i&Jn?r.renderfx=this.stream.readByte():i&ti&&(r.renderfx=this.stream.readShort()),i&zo&&(r.origin.x=this.stream.readCoord()),i&Ro&&(r.origin.y=this.stream.readCoord()),i&Oo&&(r.origin.z=this.stream.readCoord()),i&No&&(r.angles.x=this.stream.readAngle()),i&To&&(r.angles.y=this.stream.readAngle()),i&Fo&&(r.angles.z=this.stream.readAngle()),i&Wo&&this.stream.readPos(r.old_origin),i&Xo&&(r.sound=this.stream.readByte()),i&Do?r.event=this.stream.readByte():r.event=0,i&Ko&&(r.solid=this.stream.readShort())}};var Yo=(i=>(i[i.Stopped=0]="Stopped",i[i.Playing=1]="Playing",i[i.Paused=2]="Paused",i[i.Finished=3]="Finished",i))(Yo||{}),ii=class{constructor(){this.reader=null;this.state=0;this.playbackSpeed=1;this.accumulatedTime=0;this.frameDuration=100}setHandler(e){this.handler=e}loadDemo(e){this.reader=new tr(e),this.state=0,this.accumulatedTime=0}play(){this.reader&&(this.state=1)}pause(){this.state===1&&(this.state=2)}stop(){this.state=0,this.reader&&this.reader.reset(),this.accumulatedTime=0}update(e){if(!(this.state!==1||!this.reader))for(this.accumulatedTime+=e*1e3*this.playbackSpeed;this.accumulatedTime>=this.frameDuration;){if(!this.reader.hasMore()){this.state=3;return}let r=this.reader.readNextBlock();if(!r){this.state=3;return}new nr(r.data,this.handler).parseMessage(),this.accumulatedTime-=this.frameDuration}}getState(){return this.state}};function Xf(t){return{init(){t.trace({x:0,y:0,z:0},{x:0,y:0,z:0})},shutdown(){},createMainLoop(e,r){return new Dt(e,r)}}}return El(Kf);})();
450
450
  //# sourceMappingURL=index.global.js.map