quake2ts 0.0.201 → 0.0.202
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/packages/cgame/dist/index.cjs +1 -1
- package/packages/cgame/dist/index.cjs.map +1 -1
- package/packages/cgame/dist/index.js +2 -2
- package/packages/cgame/dist/index.js.map +1 -1
- package/packages/client/dist/browser/index.global.js +11 -11
- package/packages/client/dist/browser/index.global.js.map +1 -1
- package/packages/client/dist/cjs/index.cjs +28 -14
- package/packages/client/dist/cjs/index.cjs.map +1 -1
- package/packages/client/dist/esm/index.js +28 -14
- package/packages/client/dist/esm/index.js.map +1 -1
- package/packages/client/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/engine/dist/browser/index.global.js +10 -10
- package/packages/engine/dist/browser/index.global.js.map +1 -1
- package/packages/engine/dist/cjs/index.cjs +14 -7
- package/packages/engine/dist/cjs/index.cjs.map +1 -1
- package/packages/engine/dist/esm/index.js +14 -7
- package/packages/engine/dist/esm/index.js.map +1 -1
- package/packages/engine/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/game/dist/browser/index.global.js +2 -2
- package/packages/game/dist/browser/index.global.js.map +1 -1
- package/packages/game/dist/cjs/index.cjs +233 -55
- package/packages/game/dist/cjs/index.cjs.map +1 -1
- package/packages/game/dist/esm/index.js +233 -55
- package/packages/game/dist/esm/index.js.map +1 -1
- package/packages/game/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/game/dist/types/entities/playerStats.d.ts.map +1 -1
- package/packages/shared/dist/browser/index.global.js +1 -1
- package/packages/shared/dist/browser/index.global.js.map +1 -1
- package/packages/shared/dist/cjs/index.cjs +197 -52
- package/packages/shared/dist/cjs/index.cjs.map +1 -1
- package/packages/shared/dist/esm/index.js +191 -52
- package/packages/shared/dist/esm/index.js.map +1 -1
- package/packages/shared/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/shared/dist/types/items/ammo.d.ts +8 -7
- package/packages/shared/dist/types/items/ammo.d.ts.map +1 -1
- package/packages/shared/dist/types/protocol/stats.d.ts +41 -8
- package/packages/shared/dist/types/protocol/stats.d.ts.map +1 -1
- package/packages/tools/dist/tsconfig.tsbuildinfo +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";var Quake2Engine=(()=>{var Sl=Object.create;var li=Object.defineProperty;var _l=Object.getOwnPropertyDescriptor;var Ml=Object.getOwnPropertyNames;var Al=Object.getPrototypeOf,wl=Object.prototype.hasOwnProperty;var Ll=(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))!wl.call(t,i)&&i!==r&&li(t,i,{get:()=>e[i],enumerable:!(n=_l(e,i))||n.enumerable});return t};var El=(t,e,r)=>(r=t!=null?Sl(Al(t)):{},ya(e||!t||!t.__esModule?li(r,"default",{value:t,enumerable:!0}):r,t)),Il=t=>ya(li({},"__esModule",{value:!0}),t);var Za=Ll((gh,Ja)=>{"use strict";Ja.exports=Worker});var Yf={};qo(Yf,{ATTN_IDLE:()=>Cc,ATTN_LOOP_NONE:()=>Ic,ATTN_NONE:()=>so,ATTN_NORM:()=>Tc,ATTN_STATIC:()=>Rc,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:()=>Ot,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:()=>_o,Md2ParseError:()=>le,Md2Pipeline:()=>Mo,Md3Loader:()=>hr,Md3ModelMesh:()=>Lo,Md3ParseError:()=>Pe,Md3Pipeline:()=>Eo,Md3SurfaceMesh:()=>Qn,MusicSystem:()=>go,NetworkMessageParser:()=>nr,PARTICLE_FRAGMENT_SHADER:()=>aa,PARTICLE_VERTEX_SHADER:()=>sa,PakArchive:()=>ur,PakIndexStore:()=>no,PakIngestionError:()=>ht,PakParseError:()=>ze,PakValidationError:()=>Dt,PakValidator:()=>gi,ParticleRenderer:()=>To,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:()=>Or,TextureCache:()=>yr,TextureCubeMap:()=>Dr,TgaParseError:()=>et,U_ANGLE1:()=>No,U_ANGLE2:()=>Po,U_ANGLE3:()=>Fo,U_EFFECTS16:()=>ri,U_EFFECTS8:()=>Zn,U_EVENT:()=>Oo,U_FRAME16:()=>Uo,U_FRAME8:()=>Bo,U_MODEL:()=>ko,U_MODEL2:()=>Ho,U_MODEL3:()=>Vo,U_MODEL4:()=>Go,U_OLDORIGIN:()=>Wo,U_ORIGIN1:()=>Ro,U_ORIGIN2:()=>zo,U_ORIGIN3:()=>Do,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:()=>Ya,applySurfaceState:()=>Xc,attenuationToDistanceMultiplier:()=>er,boxIntersectsFrustum:()=>jn,buildBspGeometry:()=>Nc,buildMd2Geometry:()=>Qs,buildMd2VertexData:()=>Js,buildMd3SurfaceGeometry:()=>ra,buildMd3VertexData:()=>na,calculateMaxAudibleDistance:()=>ao,calculatePakChecksum:()=>Ba,computeFrameBlend:()=>qa,computeSkyScroll:()=>qc,createAnimationState:()=>$a,createAudioGraph:()=>lo,createBspSurfaces:()=>Dc,createEmptyEntityState:()=>rr,createEmptyProtocolPlayerState:()=>Co,createEngine:()=>Kf,createEngineRuntime:()=>Pa,createFaceLightmap:()=>bi,createInitialChannels:()=>mo,createProgramFromSources:()=>Oc,createWebGLContext:()=>Fc,decodeOgg:()=>ro,deriveSurfaceRenderState:()=>Xs,extractFrustumPlanes:()=>kc,filesToPakSources:()=>as,findLeafForPoint:()=>Hs,gatherVisibleFaces:()=>Gc,groupMd2Animations:()=>Ga,ingestPakFiles:()=>Oa,ingestPaks:()=>xi,interpolateMd3Tag:()=>fl,interpolateVec3:()=>ja,parseBsp:()=>cs,parseMd2:()=>ls,parseMd3:()=>ds,parsePcx:()=>Jr,parseSprite:()=>us,parseTga:()=>fs,parseWal:()=>Si,parseWalTexture:()=>Ai,parseWav:()=>wi,pcxToRgba:()=>_i,pickChannel:()=>ho,preparePcxTexture:()=>Mi,removeViewTranslation:()=>Yc,resolveLightStyles:()=>Ws,spatializeOrigin:()=>po,spawnBlood:()=>pl,spawnBulletImpact:()=>ml,spawnExplosion:()=>hl,spawnMuzzleFlash:()=>gl,spawnTeleportFlash:()=>yl,spawnTrail:()=>xl,walToRgba:()=>ms,wireDropTarget:()=>Da,wireFileInput:()=>Na});var Tl=()=>typeof performance<"u"?performance.now():Date.now(),Cl=t=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>t()):setTimeout(t,25)},Ot=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??Tl,schedule:r.schedule??Cl}}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 Rl=Object.defineProperty,ga=(t,e)=>{for(var r in e)Rl(t,r,{get:e[r],enumerable:!0})},xa={x:0,y:0,z:0};var Qf=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 Pl(t){return jo(t,t)}function Qo(t){return Math.sqrt(Pl(t))}function He(t){let e=Qo(t);return e===0?t:zl(t,1/e)}var Fl=Math.PI/180,Jf=180/Math.PI,sr=Fl;var Bl=[[-.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 Ol(){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=Ol();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 Nl=16384;var di=65536,_a=1<<17,kl=1<<18,Ul=1<<19,Hl=1<<20,Vl=1<<21,Gl=1<<22,Wl=1<<23,Zf=1<<24,ui=1<<25,Xl=1<<26,em=1<<27,tm=1<<28,rm=1<<29,fi=1<<30,nm=1<<31;var Kr=0;var Ma=4,Aa=8,wa=16,La=32,Ea=64;var im=1<<25,om=1<<28,sm=1<<29,am=1<<30,cm=1<<31;var lm=Ke|mt,dm=Ke|di|mt|ui|fi,um=Ke|di|mt,fm=Ke|_a|mt|ui|fi,mm=Dl|Jo|Zo,hm=Ke|Zo|Jo,Kl=Ke|ui|fi|mt|Xl,pm=kl|Ul|Hl|Vl|Gl|Wl,ym=Ke|Jo|Zo|ui|fi,gm=Ke|di|mt,xm=Ke|mt,bm=Ke|di|mt|_a,vm=Kl|Nl;var Sm=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.CONFIG_N64_PHYSICS=56]="CONFIG_N64_PHYSICS",t[t.CONFIG_CTF_TEAMS=57]="CONFIG_CTF_TEAMS",t[t.CONFIG_COOP_RESPAWN_STRING=58]="CONFIG_COOP_RESPAWN_STRING",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 Ta(t){return t>=5&&t<59?Xr*(59-t):t>=Y.General&&t<Y.WheelWeapons?Xr*(Y.MaxConfigStrings-t):Xr}var Yl={};ga(Yl,{addReplayFrame:()=>Ql,createReplaySession:()=>jl,deserializeReplay:()=>$l,serializeReplay:()=>ql});function ql(t){return JSON.stringify(t,null,2)}function $l(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 jl(t,e){return{metadata:{map:t,date:new Date().toISOString(),version:"1.0",seed:e},frames:[]}}function Ql(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||{});var Jl={};ga(Jl,{U_ANGLE1:()=>od,U_ANGLE2:()=>sd,U_ANGLE3:()=>ad,U_EFFECTS:()=>dd,U_EVENT:()=>md,U_FRAME:()=>cd,U_MODEL:()=>ed,U_MODEL2:()=>pd,U_MODEL3:()=>yd,U_MODEL4:()=>gd,U_MOREBITS:()=>hd,U_NUMBER:()=>Zl,U_ORIGIN1:()=>rd,U_ORIGIN2:()=>nd,U_ORIGIN3:()=>id,U_REMOVE:()=>xd,U_RENDERFX:()=>ud,U_SKIN:()=>ld,U_SOLID:()=>fd,U_SOUND:()=>td});var Zl=1,ed=2,td=4,rd=8,nd=16,id=32,od=64,sd=128,ad=256,cd=512,ld=1024,dd=2048,ud=4096,fd=8192,md=16384,hd=32768,pd=1,yd=2,gd=4,xd=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=Bl[e];t.x=r[0],t.y=r[1],t.z=r[2]}};var Ra=(t=>(t[t.Bullets=0]="Bullets",t[t.Shells=1]="Shells",t[t.Rockets=2]="Rockets",t[t.Grenades=3]="Grenades",t[t.Cells=4]="Cells",t[t.Slugs=5]="Slugs",t[t.Trap=6]="Trap",t[t.Tesla=7]="Tesla",t[t.MagSlugs=8]="MagSlugs",t[t.Flechettes=9]="Flechettes",t[t.Prox=10]="Prox",t[t.Nuke=11]="Nuke",t[t.Rounds=12]="Rounds",t))(Ra||{}),_m=Object.keys(Ra).length/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 Ot({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 bd(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=Ta(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 bd(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 Pa(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 vd="PACK";function Sd(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 _d(){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=_d();function Fa(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 ze=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 ze("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!==vd)throw new ze(`Invalid PAK header magic: ${i}`);let o=n.getInt32(4,!0),s=n.getInt32(8,!0);if(o<12)throw new ze(`Invalid directory offset: ${o}`);if(s<=0||s%64!==0)throw new ze(`Invalid directory length: ${s}`);if(o+s>r.byteLength)throw new ze("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=Sd(n,f,56),h=ie(m),y=n.getInt32(f+56,!0),p=n.getInt32(f+60,!0);if(y<0||p<0||y+p>r.byteLength)throw new ze(`Invalid entry bounds for ${m||"<unnamed>"} (offset=${y}, length=${p})`);if(!h)throw new ze(`Entry ${u} has an empty name`);let g={name:h,offset:y,length:p};d.set(h,g)}return l.push(...d.values()),new t(e,r,l,Fa(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 ze(`File not found in PAK: ${e}`);return new Uint8Array(this.buffer,r.offset,r.length)}validate(){return{checksum:this.checksum,entries:this.listEntries()}}};function Ba(t){return Fa(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"}]),Dt=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 Dt(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 Ad(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 wd(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 Ad(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 wd(l,n.onProgress),u=ur.fromArrayBuffer(l.name,d),f=n.validator?.validateArchive(u);if(f){n.onValidationResult?.(f);let m=f.status==="mismatch",h=f.status==="unknown";if(m&&o||h&&!s){let y=new Dt(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 Ld(t){return Array.isArray(t)?t:Array.from(t)}function as(t){return Ld(t).map(e=>({name:e.name,data:e}))}async function Oa(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 Na(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 Ed="IBSP",Id=38,Ua=19,Td=8+Ua*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<Td)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!==Ed)throw new q(`Invalid BSP magic ${r}`);let n=e.getInt32(4,!0);if(n!==Id)throw new q(`Unsupported BSP version ${n}`);let i=new Map;for(let A=0;A<Ua;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=Rd(t,i.get(0)),a=Pd(t,i.get(1)),c=Fd(t,i.get(2)),l=Bd(t,i.get(4)),d=Od(t,i.get(5)),u=Dd(t,i.get(6)),f=new Uint8Array(t,i.get(7).offset,i.get(7).length),m=Kd(u,i.get(7)),h=Nd(t,i.get(8)),y=kd(t,i.get(11)),p=Ud(t,i.get(12)),g=Hd(t,i.get(13)),S=Vd(t,i.get(14)),x=Gd(t,i.get(15)),v=Wd(t,i.get(9),i.get(10),h),b=Xd(t,i.get(3));return{header:o,entities:s,planes:a,vertices:c,nodes:l,texInfo:d,faces:u,lightMaps:f,lightMapInfo:m,leafs:h,leafLists:v,edges:y,surfEdges:p,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 D=parseInt(B.substring(1),10);if(isNaN(D)||D<0||D>=g.length)continue;let U=g[D],C=Cd(A.origin,A.direction,U.mins,U.maxs);C!==null&&C<E&&(E=C,w={entity:L,model:U,distance:C})}return w}}}function Cd(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 Rd(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 Pd(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 Fd(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 Bd(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 Od(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),h=new Uint8Array(t,e.offset+a+40,32),y=new TextDecoder("utf-8").decode(h).replace(/\0.*$/,""),p=r.getInt32(a+72,!0);o.push({s:c,sOffset:l,t:d,tOffset:u,flags:f,value:m,texture:y,nextTexInfo:p})}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)],h=r.getInt32(a+16,!0);o.push({planeIndex:c,side:l,firstEdge:d,numEdges:u,texInfo:f,styles:m,lightOffset:h})}return o}function Nd(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),h=r.getUint16(a+22,!0),y=r.getUint16(a+24,!0),p=r.getUint16(a+26,!0);o.push({contents:c,cluster:l,area:d,mins:u,maxs:f,firstLeafFace:m,numLeafFaces:h,firstLeafBrush:y,numLeafBrushes:p})}return o}function kd(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 Ud(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 Hd(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 Vd(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 Gd(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 Wd(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 Xd(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:ka(t,d,n,e),phs:ka(t,u,n,e)})}return{numClusters:n,clusters:s}}function ka(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 Kd(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 Yd=844121161,qd=8,Ha=68,$d=[{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 Va(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<Ha||e+r>t.byteLength))throw new le(`${n} section is out of bounds`)}function jd(t){if(t.byteLength<Ha)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!==Yd)throw new le(`Invalid MD2 ident: ${r}`);if(n!==qd)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 Qd(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:Va(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 Zd(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 e0(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=Va(s,24,16),d=[],u=1/0,f=1/0,m=1/0,h=-1/0,y=-1/0,p=-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>h&&(h=x),v>y&&(y=v),b>p&&(p=b);let M={x,y:v,z:b},A=s.getUint8(S+3),w=$d[A];if(!w)throw new le(`Invalid normal index ${A} in frame ${l}`);d.push({position:M,normalIndex:A,normal:w})}n.push({name:l,vertices:d,minBounds:{x:u,y:f,z:m},maxBounds:{x:h,y,z:p}})}return n}function t0(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=jd(t),r=Qd(t,e),n=Jd(t,e),i=Zd(t,e),o=e0(t,e),s=t0(t,e);return{header:e,skins:r,texCoords:n,triangles:i,frames:o,glCommands:s}}function Ga(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 Wa=860898377,r0=15,Pe=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 n0(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 Pe(`${t} exceeds buffer bounds`)}function i0(t){let e=t.getInt32(0,!0);if(e!==Wa)throw new Pe(`Invalid MD3 ident: ${e}`);let r=t.getInt32(4,!0);if(r!==r0)throw new Pe(`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 Pe("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 o0(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 s0(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 a0(t,e){let r=t.getInt32(e,!0);if(r!==Wa)throw new Pe(`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 Pe(`Invalid surface counts for ${n}`);let h=m;vi(`Surface ${n}`,e,h,t.byteLength);let y=[],p=e+l;for(let A=0;A<c;A+=1){let w=p+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=[],M=e+f;for(let A=0;A<o;A+=1){let w=[];for(let E=0;E<a;E+=1){let L=M+(A*a+E)*8,B=t.getInt16(L,!0)/64,D=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:D,z:U},latLng:C,normal:n0(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 Pe("MD3 buffer too small for header");let e=new DataView(t),r=i0(e);vi("MD3 end",r.ofsEnd,0,t.byteLength);let n=o0(e,r),i=s0(e,r),o=[],s=r.ofsSurfaces;for(let a=0;a<r.numSurfaces;a+=1){let{surface:c,nextOffset:l}=a0(e,s);o.push(c),s=l}if(s!==r.ofsEnd)throw new Pe("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 c0=844317769,l0=2,Xa=64,Ka=12,yt=class extends Error{};function d0(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<Ka)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!==c0)throw new yt(`Invalid Sprite ident: ${r}`);if(n!==l0)throw new yt(`Unsupported Sprite version: ${n}`);let o=[],s=16+Xa,a=Ka;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=d0(e,a+16,Xa);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 Ya(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 qa(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 $a(t){return{sequence:t,time:0}}function ja(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,h=o;for(let y=0;y<s.length;y+=1){let p=s[y],g=Math.max(1,m*h|0);if(p<=0||p+g>t.byteLength)throw new Qr(`Invalid WAL mip offset for level ${y}`);let S=new Uint8Array(t,p,g);f.push({level:y,width:m,height:h,data:S}),m=Math.max(1,m>>1),h=Math.max(1,h>>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),h=new Uint8Array(t,128,f-128),y=new Uint8Array(l*d),p=0,g=0;for(let S=0;S<d;S+=1){let x=0;for(;x<u&&p<h.length;){let v=1,b=h[p++];if((b&192)===192){if(v=b&63,p>=h.length)throw new Nt("Unexpected end of PCX RLE data");b=h[p++]}for(let M=0;M<v&&x<u;M+=1)x<l&&(y[g++]=b),x+=1}}return{width:l,height:d,bitsPerPixel:i,pixels:y,palette:m}}function _i(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,h=new Uint8Array(m*4),y=(c&32)!==0,p=0,g=new Uint8Array(t),S=x=>{if(d){let v=g[f++];h[x]=v,h[x+1]=v,h[x+2]=v,h[x+3]=255}else{let v=g[f++],b=g[f++],M=g[f++],A=a===32?g[f++]:255;h[x]=M,h[x+1]=b,h[x+2]=v,h[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,M=(v&128)!==0;if(x+b>m)throw new et("TGA RLE packet exceeds image bounds");if(M){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 D=(x+B)*4;h[D]=A,h[D+1]=w,h[D+2]=E,h[D+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 M=b*x,A=(s-1-b)*x;v.set(h.subarray(M,M+x)),h.set(h.subarray(A,A+x),M),h.set(v,A)}}return{width:o,height:s,bitsPerPixel:32,pixels:h}}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 Mi(t){let e=_i(t),r={level:0,width:t.width,height:t.height,rgba:e};return{width:t.width,height:t.height,levels:[r],source:"pcx"}}function Qa(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 h=hs(e,r,4),y=e.getUint32(r+4,!0),p=r+8;h==="fmt "?(n=p,o=y):h==="data"&&(i=p,s=y),r=p+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 h=0;h<f;h+=1)for(let y=0;y<c;y+=1){let p=h*c+y,g=i+p*u,S=0;if(d===8)S=e.getUint8(g),m[p]=(S-128)/128;else if(d===16)S=e.getInt16(g,!0),m[p]=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[p]=S/8388608}else throw new kt(`Unsupported bitsPerSample: ${d}`)}return{sampleRate:l,channels:c,bitsPerSample:d,samples:m}}var u0=(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=u0)=>{let r=p=>new Uint8Array(p.length/2).map(((g,S)=>parseInt(p.substring(2*S,2*(S+1)),16))),n=p=>r(p)[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(((p,g)=>i.set(p,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=(p=>new DataView(r(p).buffer).getInt32(0,!0))(t.substring(13,m))));let h=256-u;for(let p=m;p<t.length;p++)if(s=t.charCodeAt(p),s!==61||l){if(s===92&&p<t.length-5&&f){let g=t.charCodeAt(p+1);g!==117&&g!==85||(s=parseInt(t.substring(p+2,p+6),16),p+=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+h:s-u}else l=!0;let y=o.subarray(0,d);if(f&&a===1){let p=e(y);if(p!==c){let g="Decode failed crc32 validation";throw console.error("`simple-yenc`\n",g+`
|
|
1
|
+
"use strict";var Quake2Engine=(()=>{var Sl=Object.create;var li=Object.defineProperty;var _l=Object.getOwnPropertyDescriptor;var Al=Object.getOwnPropertyNames;var Ml=Object.getPrototypeOf,wl=Object.prototype.hasOwnProperty;var Ll=(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 Al(e))!wl.call(t,i)&&i!==r&&li(t,i,{get:()=>e[i],enumerable:!(n=_l(e,i))||n.enumerable});return t};var El=(t,e,r)=>(r=t!=null?Sl(Ml(t)):{},ya(e||!t||!t.__esModule?li(r,"default",{value:t,enumerable:!0}):r,t)),Tl=t=>ya(li({},"__esModule",{value:!0}),t);var Za=Ll((Ah,Qa)=>{"use strict";Qa.exports=Worker});var Jf={};qo(Jf,{ATTN_IDLE:()=>Cc,ATTN_LOOP_NONE:()=>Tc,ATTN_NONE:()=>so,ATTN_NORM:()=>Ic,ATTN_STATIC:()=>Rc,AssetDependencyError:()=>Zt,AssetDependencyTracker:()=>qn,AssetManager:()=>io,AudioApi:()=>dr,AudioContextController:()=>co,AudioRegistry:()=>Pr,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:()=>Ot,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:()=>_o,Md2ParseError:()=>le,Md2Pipeline:()=>Ao,Md3Loader:()=>hr,Md3ModelMesh:()=>Lo,Md3ParseError:()=>Fe,Md3Pipeline:()=>Eo,Md3SurfaceMesh:()=>Jn,MusicSystem:()=>go,NetworkMessageParser:()=>nr,PARTICLE_FRAGMENT_SHADER:()=>aa,PARTICLE_VERTEX_SHADER:()=>sa,PakArchive:()=>ur,PakIndexStore:()=>no,PakIngestionError:()=>ht,PakParseError:()=>ze,PakValidationError:()=>Dt,PakValidator:()=>gi,ParticleRenderer:()=>Io,ParticleSystem:()=>To,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:()=>Or,TextureCache:()=>yr,TextureCubeMap:()=>Dr,TgaParseError:()=>et,U_ANGLE1:()=>No,U_ANGLE2:()=>Fo,U_ANGLE3:()=>Po,U_EFFECTS16:()=>ri,U_EFFECTS8:()=>Zn,U_EVENT:()=>Oo,U_FRAME16:()=>Uo,U_FRAME8:()=>Bo,U_MODEL:()=>ko,U_MODEL2:()=>Ho,U_MODEL3:()=>Vo,U_MODEL4:()=>Go,U_OLDORIGIN:()=>Wo,U_ORIGIN1:()=>Ro,U_ORIGIN2:()=>zo,U_ORIGIN3:()=>Do,U_REMOVE:()=>ca,U_RENDERFX16:()=>ti,U_RENDERFX8:()=>Qn,U_SKIN16:()=>ni,U_SKIN8:()=>ei,U_SOLID:()=>Ko,U_SOUND:()=>Xo,VertexArray:()=>we,VertexBuffer:()=>Se,VirtualFileSystem:()=>yi,advanceAnimation:()=>Ya,applySurfaceState:()=>Xc,attenuationToDistanceMultiplier:()=>er,boxIntersectsFrustum:()=>jn,buildBspGeometry:()=>Nc,buildMd2Geometry:()=>Js,buildMd2VertexData:()=>Qs,buildMd3SurfaceGeometry:()=>ra,buildMd3VertexData:()=>na,calculateMaxAudibleDistance:()=>ao,calculatePakChecksum:()=>Ba,computeFrameBlend:()=>qa,computeSkyScroll:()=>qc,createAnimationState:()=>$a,createAudioGraph:()=>lo,createBspSurfaces:()=>Dc,createEmptyEntityState:()=>rr,createEmptyProtocolPlayerState:()=>Co,createEngine:()=>jf,createEngineRuntime:()=>Fa,createFaceLightmap:()=>bi,createInitialChannels:()=>mo,createProgramFromSources:()=>Oc,createWebGLContext:()=>Pc,decodeOgg:()=>ro,deriveSurfaceRenderState:()=>Xs,extractFrustumPlanes:()=>kc,filesToPakSources:()=>as,findLeafForPoint:()=>Hs,gatherVisibleFaces:()=>Gc,groupMd2Animations:()=>Ga,ingestPakFiles:()=>Oa,ingestPaks:()=>xi,interpolateMd3Tag:()=>fl,interpolateVec3:()=>ja,parseBsp:()=>cs,parseMd2:()=>ls,parseMd3:()=>ds,parsePcx:()=>Qr,parseSprite:()=>us,parseTga:()=>fs,parseWal:()=>Si,parseWalTexture:()=>Mi,parseWav:()=>wi,pcxToRgba:()=>_i,pickChannel:()=>ho,preparePcxTexture:()=>Ai,removeViewTranslation:()=>Yc,resolveLightStyles:()=>Ws,spatializeOrigin:()=>po,spawnBlood:()=>pl,spawnBulletImpact:()=>ml,spawnExplosion:()=>hl,spawnMuzzleFlash:()=>gl,spawnTeleportFlash:()=>yl,spawnTrail:()=>xl,walToRgba:()=>ms,wireDropTarget:()=>Da,wireFileInput:()=>Na});var Il=()=>typeof performance<"u"?performance.now():Date.now(),Cl=t=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>t()):setTimeout(t,25)},Ot=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??Cl}}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 Rl=Object.defineProperty,ga=(t,e)=>{for(var r in e)Rl(t,r,{get:e[r],enumerable:!0})},xa={x:0,y:0,z:0};var tm=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 Fl(t){return jo(t,t)}function Jo(t){return Math.sqrt(Fl(t))}function He(t){let e=Jo(t);return e===0?t:zl(t,1/e)}var Pl=Math.PI/180,rm=180/Math.PI,sr=Pl;var Bl=[[-.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 Ol(){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=Ol();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 Qo=8,Zo=16,Dl=32;var Nl=16384;var di=65536,_a=1<<17,kl=1<<18,Ul=1<<19,Hl=1<<20,Vl=1<<21,Gl=1<<22,Wl=1<<23,nm=1<<24,ui=1<<25,Xl=1<<26,im=1<<27,om=1<<28,sm=1<<29,fi=1<<30,am=1<<31;var Kr=0;var Aa=4,Ma=8,wa=16,La=32,Ea=64;var cm=1<<25,lm=1<<28,dm=1<<29,um=1<<30,fm=1<<31;var mm=Ke|mt,hm=Ke|di|mt|ui|fi,pm=Ke|di|mt,ym=Ke|_a|mt|ui|fi,gm=Dl|Qo|Zo,xm=Ke|Zo|Qo,Kl=Ke|ui|fi|mt|Xl,bm=kl|Ul|Hl|Vl|Gl|Wl,vm=Ke|Qo|Zo|ui|fi,Sm=Ke|di|mt,_m=Ke|mt,Am=Ke|di|mt|_a,Mm=Kl|Nl;var wm=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.CONFIG_N64_PHYSICS=56]="CONFIG_N64_PHYSICS",t[t.CONFIG_CTF_TEAMS=57]="CONFIG_CTF_TEAMS",t[t.CONFIG_COOP_RESPAWN_STRING=58]="CONFIG_COOP_RESPAWN_STRING",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||{}),Ta=Y.MaxConfigStrings;function Ia(t){return t>=5&&t<59?Xr*(59-t):t>=Y.General&&t<Y.WheelWeapons?Xr*(Y.MaxConfigStrings-t):Xr}var Yl={};ga(Yl,{addReplayFrame:()=>Jl,createReplaySession:()=>jl,deserializeReplay:()=>$l,serializeReplay:()=>ql});function ql(t){return JSON.stringify(t,null,2)}function $l(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 jl(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 T=(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))(T||{});var Ql=12,Zl=9,Lm=Math.ceil(Ql*Zl/16),ed=23,td=2,Em=Math.ceil(ed*td/16);var rd={};ga(rd,{U_ANGLE1:()=>ld,U_ANGLE2:()=>dd,U_ANGLE3:()=>ud,U_EFFECTS:()=>hd,U_EVENT:()=>gd,U_FRAME:()=>fd,U_MODEL:()=>id,U_MODEL2:()=>bd,U_MODEL3:()=>vd,U_MODEL4:()=>Sd,U_MOREBITS:()=>xd,U_NUMBER:()=>nd,U_ORIGIN1:()=>sd,U_ORIGIN2:()=>ad,U_ORIGIN3:()=>cd,U_REMOVE:()=>_d,U_RENDERFX:()=>pd,U_SKIN:()=>md,U_SOLID:()=>yd,U_SOUND:()=>od});var nd=1,id=2,od=4,sd=8,ad=16,cd=32,ld=64,dd=128,ud=256,fd=512,md=1024,hd=2048,pd=4096,yd=8192,gd=16384,xd=32768,bd=1,vd=2,Sd=4,_d=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=Bl[e];t.x=r[0],t.y=r[1],t.z=r[2]}};var Ra=(t=>(t[t.Bullets=0]="Bullets",t[t.Shells=1]="Shells",t[t.Rockets=2]="Rockets",t[t.Grenades=3]="Grenades",t[t.Cells=4]="Cells",t[t.Slugs=5]="Slugs",t[t.MagSlugs=6]="MagSlugs",t[t.Trap=7]="Trap",t[t.Flechettes=8]="Flechettes",t[t.Tesla=9]="Tesla",t[t.Disruptor=10]="Disruptor",t[t.Prox=11]="Prox",t[t.Nuke=12]="Nuke",t[t.Rounds=13]="Rounds",t))(Ra||{}),Tm=Object.keys(Ra).length/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 Ot({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 Ad(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=Ia(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 Ad(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(Ta).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 Fa(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 Md="PACK";function wd(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 Ld(){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 Ed=Ld();function Pa(t){let e=4294967295;for(let r=0;r<t.length;r+=1){let n=t[r];e=Ed[(e^n)&255]^e>>>8}return(e^4294967295)>>>0}var ze=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 ze("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!==Md)throw new ze(`Invalid PAK header magic: ${i}`);let o=n.getInt32(4,!0),s=n.getInt32(8,!0);if(o<12)throw new ze(`Invalid directory offset: ${o}`);if(s<=0||s%64!==0)throw new ze(`Invalid directory length: ${s}`);if(o+s>r.byteLength)throw new ze("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=wd(n,f,56),h=ie(m),y=n.getInt32(f+56,!0),p=n.getInt32(f+60,!0);if(y<0||p<0||y+p>r.byteLength)throw new ze(`Invalid entry bounds for ${m||"<unnamed>"} (offset=${y}, length=${p})`);if(!h)throw new ze(`Entry ${u} has an empty name`);let g={name:h,offset:y,length:p};d.set(h,g)}return l.push(...d.values()),new t(e,r,l,Pa(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 ze(`File not found in PAK: ${e}`);return new Uint8Array(this.buffer,r.offset,r.length)}validate(){return{checksum:this.checksum,entries:this.listEntries()}}};function Ba(t){return Pa(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"}]),Dt=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 Dt(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 Td(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 Id(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 Td(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 Id(l,n.onProgress),u=ur.fromArrayBuffer(l.name,d),f=n.validator?.validateArchive(u);if(f){n.onValidationResult?.(f);let m=f.status==="mismatch",h=f.status==="unknown";if(m&&o||h&&!s){let y=new Dt(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 Cd(t){return Array.isArray(t)?t:Array.from(t)}function as(t){return Cd(t).map(e=>({name:e.name,data:e}))}async function Oa(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 Na(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 Rd="IBSP",zd=38,Ua=19,Fd=8+Ua*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<Fd)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!==Rd)throw new q(`Invalid BSP magic ${r}`);let n=e.getInt32(4,!0);if(n!==zd)throw new q(`Unsupported BSP version ${n}`);let i=new Map;for(let M=0;M<Ua;M+=1){let w=e.getInt32(8+M*8,!0),E=e.getInt32(12+M*8,!0);if(w<0||E<0||w+E>t.byteLength)throw new q(`Invalid lump bounds for index ${M}`);i.set(M,{offset:w,length:E})}let o={version:n,lumps:i},s=Bd(t,i.get(0)),a=Dd(t,i.get(1)),c=Nd(t,i.get(2)),l=kd(t,i.get(4)),d=Ud(t,i.get(5)),u=Hd(t,i.get(6)),f=new Uint8Array(t,i.get(7).offset,i.get(7).length),m=jd(u,i.get(7)),h=Vd(t,i.get(8)),y=Gd(t,i.get(11)),p=Wd(t,i.get(12)),g=Xd(t,i.get(13)),S=Kd(t,i.get(14)),x=Yd(t,i.get(15)),v=qd(t,i.get(9),i.get(10),h),b=$d(t,i.get(3));return{header:o,entities:s,planes:a,vertices:c,nodes:l,texInfo:d,faces:u,lightMaps:f,lightMapInfo:m,leafs:h,leafLists:v,edges:y,surfEdges:p,models:g,brushes:S,brushSides:x,visibility:b,pickEntity(M){let w=null,E=1/0;for(let L of s.entities){let B=L.properties.model;if(!B||!B.startsWith("*"))continue;let D=parseInt(B.substring(1),10);if(isNaN(D)||D<0||D>=g.length)continue;let U=g[D],C=Pd(M.origin,M.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 Bd(t,e){let r=new TextDecoder().decode(new Uint8Array(t,e.offset,e.length)),n=Od(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 Od(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 Dd(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 Nd(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 kd(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 Ud(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),h=new Uint8Array(t,e.offset+a+40,32),y=new TextDecoder("utf-8").decode(h).replace(/\0.*$/,""),p=r.getInt32(a+72,!0);o.push({s:c,sOffset:l,t:d,tOffset:u,flags:f,value:m,texture:y,nextTexInfo:p})}return o}function Hd(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)],h=r.getInt32(a+16,!0);o.push({planeIndex:c,side:l,firstEdge:d,numEdges:u,texInfo:f,styles:m,lightOffset:h})}return o}function Vd(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),h=r.getUint16(a+22,!0),y=r.getUint16(a+24,!0),p=r.getUint16(a+26,!0);o.push({contents:c,cluster:l,area:d,mins:u,maxs:f,firstLeafFace:m,numLeafFaces:h,firstLeafBrush:y,numLeafBrushes:p})}return o}function Gd(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 Wd(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 Xd(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 Kd(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 Yd(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 qd(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 $d(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:ka(t,d,n,e),phs:ka(t,u,n,e)})}return{numClusters:n,clusters:s}}function ka(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 jd(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 Jd=844121161,Qd=8,Ha=68,Zd=[{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 Va(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<Ha||e+r>t.byteLength))throw new le(`${n} section is out of bounds`)}function e0(t){if(t.byteLength<Ha)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!==Jd)throw new le(`Invalid MD2 ident: ${r}`);if(n!==Qd)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 t0(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:Va(n,o*64,64)});return i}function r0(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 n0(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 i0(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=Va(s,24,16),d=[],u=1/0,f=1/0,m=1/0,h=-1/0,y=-1/0,p=-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>h&&(h=x),v>y&&(y=v),b>p&&(p=b);let A={x,y:v,z:b},M=s.getUint8(S+3),w=Zd[M];if(!w)throw new le(`Invalid normal index ${M} in frame ${l}`);d.push({position:A,normalIndex:M,normal:w})}n.push({name:l,vertices:d,minBounds:{x:u,y:f,z:m},maxBounds:{x:h,y,z:p}})}return n}function o0(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=e0(t),r=t0(t,e),n=r0(t,e),i=n0(t,e),o=i0(t,e),s=o0(t,e);return{header:e,skins:r,texCoords:n,triangles:i,frames:o,glCommands:s}}function Ga(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 Wa=860898377,s0=15,Fe=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 a0(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 Fe(`${t} exceeds buffer bounds`)}function c0(t){let e=t.getInt32(0,!0);if(e!==Wa)throw new Fe(`Invalid MD3 ident: ${e}`);let r=t.getInt32(4,!0);if(r!==s0)throw new Fe(`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 Fe("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 l0(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 d0(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 u0(t,e){let r=t.getInt32(e,!0);if(r!==Wa)throw new Fe(`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 Fe(`Invalid surface counts for ${n}`);let h=m;vi(`Surface ${n}`,e,h,t.byteLength);let y=[],p=e+l;for(let M=0;M<c;M+=1){let w=p+M*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 M=0;M<s;M+=1){let w=S+M*68;g.push({name:jr(t,w,64),shaderIndex:t.getInt32(w+64,!0)})}let x=[],v=e+u;for(let M=0;M<a;M+=1){let w=v+M*8;x.push({s:t.getFloat32(w,!0),t:t.getFloat32(w+4,!0)})}let b=[],A=e+f;for(let M=0;M<o;M+=1){let w=[];for(let E=0;E<a;E+=1){let L=A+(M*a+E)*8,B=t.getInt16(L,!0)/64,D=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:D,z:U},latLng:C,normal:a0(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 Fe("MD3 buffer too small for header");let e=new DataView(t),r=c0(e);vi("MD3 end",r.ofsEnd,0,t.byteLength);let n=l0(e,r),i=d0(e,r),o=[],s=r.ofsSurfaces;for(let a=0;a<r.numSurfaces;a+=1){let{surface:c,nextOffset:l}=u0(e,s);o.push(c),s=l}if(s!==r.ofsEnd)throw new Fe("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 f0=844317769,m0=2,Xa=64,Ka=12,yt=class extends Error{};function h0(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<Ka)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!==f0)throw new yt(`Invalid Sprite ident: ${r}`);if(n!==m0)throw new yt(`Unsupported Sprite version: ${n}`);let o=[],s=16+Xa,a=Ka;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=h0(e,a+16,Xa);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 Ya(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 qa(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 $a(t){return{sequence:t,time:0}}function ja(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 Jr=class extends Error{constructor(e){super(e),this.name="WalParseError"}};function Si(t){if(t.byteLength<100)throw new Jr("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 Jr("Invalid WAL dimensions");let f=[],m=i,h=o;for(let y=0;y<s.length;y+=1){let p=s[y],g=Math.max(1,m*h|0);if(p<=0||p+g>t.byteLength)throw new Jr(`Invalid WAL mip offset for level ${y}`);let S=new Uint8Array(t,p,g);f.push({level:y,width:m,height:h,data:S}),m=Math.max(1,m>>1),h=Math.max(1,h>>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 Qr(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),h=new Uint8Array(t,128,f-128),y=new Uint8Array(l*d),p=0,g=0;for(let S=0;S<d;S+=1){let x=0;for(;x<u&&p<h.length;){let v=1,b=h[p++];if((b&192)===192){if(v=b&63,p>=h.length)throw new Nt("Unexpected end of PCX RLE data");b=h[p++]}for(let A=0;A<v&&x<u;A+=1)x<l&&(y[g++]=b),x+=1}}return{width:l,height:d,bitsPerPixel:i,pixels:y,palette:m}}function _i(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,h=new Uint8Array(m*4),y=(c&32)!==0,p=0,g=new Uint8Array(t),S=x=>{if(d){let v=g[f++];h[x]=v,h[x+1]=v,h[x+2]=v,h[x+3]=255}else{let v=g[f++],b=g[f++],A=g[f++],M=a===32?g[f++]:255;h[x]=A,h[x+1]=b,h[x+2]=v,h[x+3]=M}};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,A=(v&128)!==0;if(x+b>m)throw new et("TGA RLE packet exceeds image bounds");if(A){let M=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 D=(x+B)*4;h[D]=M,h[D+1]=w,h[D+2]=E,h[D+3]=L}}else for(let M=0;M<b;M++)S((x+M)*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 A=b*x,M=(s-1-b)*x;v.set(h.subarray(A,A+x)),h.set(h.subarray(M,M+x),A),h.set(v,M)}}return{width:o,height:s,bitsPerPixel:32,pixels:h}}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 Ai(t){let e=_i(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 Mi(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 h=hs(e,r,4),y=e.getUint32(r+4,!0),p=r+8;h==="fmt "?(n=p,o=y):h==="data"&&(i=p,s=y),r=p+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 h=0;h<f;h+=1)for(let y=0;y<c;y+=1){let p=h*c+y,g=i+p*u,S=0;if(d===8)S=e.getUint8(g),m[p]=(S-128)/128;else if(d===16)S=e.getInt16(g,!0),m[p]=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[p]=S/8388608}else throw new kt(`Unsupported bitsPerSample: ${d}`)}return{sampleRate:l,channels:c,bitsPerSample:d,samples:m}}var p0=(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=p0)=>{let r=p=>new Uint8Array(p.length/2).map(((g,S)=>parseInt(p.substring(2*S,2*(S+1)),16))),n=p=>r(p)[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(((p,g)=>i.set(p,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=(p=>new DataView(r(p).buffer).getInt32(0,!0))(t.substring(13,m))));let h=256-u;for(let p=m;p<t.length;p++)if(s=t.charCodeAt(p),s!==61||l){if(s===92&&p<t.length-5&&f){let g=t.charCodeAt(p+1);g!==117&&g!==85||(s=parseInt(t.substring(p+2,p+6),16),p+=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+h:s-u}else l=!0;let y=o.subarray(0,d);if(f&&a===1){let p=e(y);if(p!==c){let g="Decode failed crc32 validation";throw console.error("`simple-yenc`\n",g+`
|
|
2
2
|
`,"Expected: "+c+"; Got: "+p+`
|
|
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*4U((I-H(H*i0J,^*DH+H-H*I+H,I*4)33H(H*H)^*DH(H+H)^*@H+i§H)i§3æ*).§K(iHI/+§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,hi73H,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ô7H,c)(i)H+i´8W)(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,hi73H-i)J+V)&+I,H(H+V)æ,8(I.H(H*8*J-i(p51H-i)J+i¸7V)(H(H+iø7V)(8(J/H(P*0J+s,hi73H+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(i2J,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*4J1J.U(*H.U((J2i')o5/H.U()I.H,H(^*<H0H1U((H.i0J.i§i0i')o5/H/H.H2J*H(J.q50H,P*0J/H*I-H,P*(J0,hH,P*,H-q,hi)I-423+hH*m5+H/H0H(H1U((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-iEr5)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¨1I/+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+H0H1I2i(I-+hH-H2p,hH,H,iP8*J*i(p5-H*i7u,hH,i-H-i)H*c)(H-i)I-4*3i(I/i+I.i+I(*h*h*hH*i86*(*)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,hiI*4,3H,iø-H,i¸)H,i-H18)J(,hi¡I*H(i(p5,H1H,V)ú-H,V)ø-o5,3H,i(H,iXH,i-H1i)H08)J(,hi I*H(i(p5,H0H,V)H,V)o5,3H,H,iPH,iH8+I*4+3(3(3H,i$6i¬78+I*3H*H3m5(3i)I-H*i(r5)3H)H,P*0^*(H+H,P*<^*(H*I-3H,i2L(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*S7US0U `;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 h=u;u+=f,l.set(r,h);let y=u;u+=4,d.setInt32(y,l.byteLength-u,!0),a(u,y,h,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 ec=El(Za(),1);var f0=()=>globalThis.Worker||ec.default,gr=class extends f0(){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,h=new Promise(y=>{m=y});self.onmessage=({data:{id:y,command:p,data:g}})=>{let S=h,x={id:y},v;p==="init"?(Object.defineProperties(l,{WASMAudioDecoderCommon:{value:d},EmscriptenWASM:{value:u},module:{value:g.module},isWebWorker:{value:!0}}),f=new l(g.options),m()):p==="free"?f.free():p==="ready"?S=S.then(()=>f.ready):p==="reset"?S=S.then(()=>f.reset()):(Object.assign(x,f[p](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,tc=", ",P=(()=>{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(tc)))})(),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(tc)})`,en=[gt,te(2,P[0][0]),te(3,P[0][2]),te(4,P[1][0],P[3][0]),te(5,P[1][2],P[3][0]),te(6,P[1][2],P[3][0],Ye),te(7,P[1][2],P[2][0],P[3][4],Ye),te(8,P[1][2],P[2][0],P[3][0],Ye)],rc=192e3,nc=176400,Ei=96e3,Ii=88200,ic=64e3,bt=48e3,xr=44100,br=32e3,vr=24e3,Sr=22050,_r=16e3,Ti=12e3,Ci=11025,Mr=8e3,oc=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",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",Me="layer",_="length",O="mode",nt=O+"Extension",Ri="mpeg",it=Ri+"Version",mn="numberAACFrames",hn="outputGain",Ut="preSkip",pn="profile",zi=ee(),ot="protection",ys="rawData",Fe="segments",k="subarray",_t="version",Ht="vorbis",yn=Ht+"Comments",Lr=Ht+"Setup",Pi="block",gn=Pi+"ingStrategy",Fi=ee(),st=Pi+"Size",Mt=Pi+"size0",At=Pi+"size1",xn=ee(),Bi="channel",at=Bi+"MappingFamily",bn=Bi+"MappingTable",ye=Bi+"Mode",vn=ee(),R=Bi+"s",sc="copyright",Sn=sc+"Id",_n=sc+"IdStart",ct="frame",lt=ct+"Count",Ae=ct+"Length",Oi="Number",dt=ct+Oi,je=ct+"Padding",F=ct+"Size",ac="Rate",Mn="inputSample"+ac,gs="page",Vt=gs+"Checksum",Er=ee(),wt=gs+"SegmentTable",oe=gs+"Sequence"+Oi,xs="sample",An=xs+Oi,V=xs+ac,Qe=ee(),G=xs+"s",Di="stream",wn=Di+"Count",Ln=Di+"Info",Je=Di+"Serial"+Oi,bs=Di+"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(),Oe=ee(),De=ee(),Ze=ee(),It=ee(),ki=ee(),We=ee(),Xe=ee(),Ne=ee(),Ui=ee(),ge=Uint8Array,Tt=DataView,K="reserved",xe="bad",Ir="free",In="none",Hi="16bit CRC";var _s=(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},h0=_s(new ge(256),t=>t,t=>t&128?7^t<<1:t<<1),re=[_s(new Uint16Array(256),t=>t<<8,t=>t<<1^(t&32768?32773:0))],ne=[_s(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 lc=t=>{let e=0,r=t[_];for(let n=0;n!==r;n++)e=h0[e^t[n]];return e},dc=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},uc=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),cc=[0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15],Tn=t=>cc[t&15]<<4|cc[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,(Tn(this._data[r-1])<<8)+Tn(this._data[r])>>7-n&255}},fc=(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 Rn=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}[Oe](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[De](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 Te=class extends Kt{static*[De](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)[_]=r[_]}};var Ms="unsynchronizationFlag",As="extendedHeaderFlag",ws="experimentalFlag",Ls="footerPresent",zn=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[_t]=`id3v2.${s[3]}.${s[4]}`,s[5]&15)||(o[Ms]=!!(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[_t]=e[_t],this[Ms]=e[Ms],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[R]=e[R],this[ye]=e[ye],this[V]=e[V]}};var gc={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++)gc[t<<4]=[t*32,Gi(t,4,0),Gi(t,4,-1),Gi(t,8,4),Gi(t,8,0)];var p0=0,y0=1,g0=2,x0=3,mc=4,Wi="bands ",Xi=" to 31",hc={0:Wi+4+Xi,16:Wi+8+Xi,32:Wi+12+Xi,48:Wi+16+Xi},Yt="bitrateIndex",Pn="v2",ji="v1",Ki="Intensity stereo ",Yi=", MS stereo ",qi="on",$i="off",b0={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]:b0,[ji]:{[Yt]:g0,[G]:1152},[Pn]:{[Yt]:mc,[G]:576}},4:{[z]:"Layer II",[je]:1,[nt]:hc,[G]:1152,[ji]:{[Yt]:y0},[Pn]:{[Yt]:mc}},6:{[z]:"Layer I",[je]:4,[nt]:hc,[G]:384,[ji]:{[Yt]:p0},[Pn]:{[Yt]:x0}}},Is="MPEG Version ",pc="ISO/IEC ",v0={0:{[z]:`${Is}2.5 (later extension of MPEG 2)`,[Me]:Pn,[V]:{0:Ci,4:Ti,8:Mr,12:K}},8:{[z]:K},16:{[z]:`${Is}2 (${pc}13818-3)`,[Me]:Pn,[V]:{0:Sr,4:vr,8:_r,12:K}},24:{[z]:`${Is}1 (${pc}11172-3)`,[Me]:ji,[V]:{0:xr,4:bt,8:br,12:K}},length:_},S0={0:Hi,1:In},_0={0:In,1:"50/15 ms",2:K,3:"CCIT J.17"},yc={0:{[R]:2,[z]:xt},64:{[R]:2,[z]:"joint "+xt},128:{[R]:2,[z]:"dual channel"},192:{[R]:1,[z]:gt}},qt=class t extends Ce{static*[X](e,r,n){let i={},o=yield*zn.getID3v2Header(e,r,n);o&&(yield*e[W](o[_],n),e[Be](o[_]));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=v0[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[Me]]};if(i[it]=l[z],i[Me]=u[z],i[G]=u[G],i[ot]=S0[s[1]&1],i[_]=4,i[he]=gc[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]=yc[f][z],i[R]=yc[f][R],i[nt]=u[nt][s[3]&48],i[dn]=!!(s[3]&8),i[tt]=!!(s[3]&4),i[wr]=_0[s[3]&3],i[wr]===K)return null;i[me]=16;{let{length:m,frameLength:h,samples:y,...p}=i;r[Oe](a,i,p)}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[Me]=e[Me],this[nt]=e[nt],this[it]=e[it],this[ot]=e[ot]}};var Fn=class t extends Te{static*[De](e,r,n){return yield*super[De](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 Ri}*[Ze](){return yield*this[Et]()}};var M0={0:"MPEG-4",8:"MPEG-2"},A0={0:"valid",2:xe,4:xe,6:xe},w0={0:Hi,1:In},L0={0:"AAC Main",64:"AAC LC (Low Complexity)",128:"AAC SSR (Scalable Sample Rate)",192:"AAC LTP (Long Term Prediction)"},E0={0:Ei,4:Ii,8:ic,12:bt,16:xr,20:br,24:vr,28:Sr,32:_r,36:Ti,40:Ci,44:Mr,48:oc,52:K,56:K,60:"frequency is written explicitly"},xc={0:{[R]:0,[z]:"Defined in AOT Specific Config"},64:{[R]:1,[z]:gt},128:{[R]:2,[z]:te(2,P[0][0])},192:{[R]:3,[z]:te(3,P[1][3])},256:{[R]:4,[z]:te(4,P[1][3],P[3][4])},320:{[R]:5,[z]:te(5,P[1][3],P[3][0])},384:{[R]:6,[z]:te(6,P[1][3],P[3][0],Ye)},448:{[R]:8,[z]:te(8,P[1][3],P[2][0],P[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[Me]=A0[o[1]&6],i[Me]===xe))return null;let l=o[1]&1;i[ot]=w0[l],i[_]=l?7:9,i[zi]=o[2]&192,i[Qe]=o[2]&60;let d=o[2]&2;if(i[pn]=L0[i[zi]],i[V]=E0[i[Qe]],i[V]===K)return null;i[rt]=!!d,i[vn]=(o[2]<<8|o[3])&448,i[ye]=xc[i[vn]][z],i[R]=xc[i[vn]][R],i[tt]=!!(o[3]&32),i[un]=!!(o[3]&8),i[Sn]=!!(o[3]&8),i[_n]=!!(o[3]&4),i[me]=16,i[G]=1024,i[mn]=o[6]&3;{let{length:u,channelModeBits:f,profileBits:m,sampleRateBits:h,frameLength:y,samples:p,numberAACFrames:g,...S}=i;r[Oe](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[_n]=e[_n],this[on]=e[on],this[un]=e[un],this[tt]=e[tt],this[rt]=e[rt],this[Me]=e[Me],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[zi]+64<<5|e[Qe]<<5|e[vn]>>3,n=new ge(2);return new Tt(n[qe]).setUint16(0,r,!1),n}};var On=class t extends Te{static*[De](e,r,n){return yield*super[De]($t,t,e,r,n)}constructor(e,r,n){super(e,r,n)}};var Dn=class extends be{constructor(e,r,n){super(e,r),this.Frame=On,this.Header=$t,n(this[Q])}get[Q](){return"aac"}*[Ze](){return yield*this[Et]()}};var Ct=class t extends Te{static _getFrameFooterCrc16(e){return(e[e[_]-2]<<8)+e[e[_]-1]}static[Ui](e){let r=t._getFrameFooterCrc16(e),n=dc(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 bc="get from STREAMINFO metadata block",I0={0:"Fixed",1:"Variable"},vc={0:K,16:192};for(let t=2;t<16;t++)vc[t<<4]=t<6?576*2**(t-2):2**t;var T0={0:bc,1:Ii,2:nc,3:rc,4:Mr,5:_r,6:Sr,7:vr,8:br,9:xr,10:bt,11:Ei,15:xe},C0={0:{[R]:1,[z]:gt},16:{[R]:2,[z]:te(2,P[0][0])},32:{[R]:3,[z]:te(3,P[0][1])},48:{[R]:4,[z]:te(4,P[1][0],P[3][0])},64:{[R]:5,[z]:te(5,P[1][1],P[3][0])},80:{[R]:6,[z]:te(6,P[1][1],Ye,P[3][0])},96:{[R]:7,[z]:te(7,P[1][1],Ye,P[3][4],P[2][0])},112:{[R]:8,[z]:te(8,P[1][1],Ye,P[3][0],P[2][0])},128:{[R]:2,[z]:`${xt} (left, diff)`},144:{[R]:2,[z]:`${xt} (diff, right)`},160:{[R]:2,[z]:`${xt} (avg, diff)`},176:K,192:K,208:K,224:K,240:K},R0={0:bc,2:8,4:12,6:K,8:16,10:20,12:24,14:K},Rt=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]=I0[o[Fi]],o[xn]=i[2]&240,o[Qe]=i[2]&15,o[st]=vc[o[xn]],o[st]===K||(o[V]=T0[o[Qe]],o[V]===xe)||i[3]&1)return null;let l=C0[i[3]&240];if(l===K||(o[R]=l[R],o[ye]=l[z],o[me]=R0[i[3]&14],o[me]===K))return null}o[_]=5,i=yield*e[W](o[_]+8,n);let c=t._decodeUTF8Int(i[k](4));if(!c||(o[Fi]?o[An]=c.value:o[dt]=c.value,o[_]+=c[_],o[xn]===96?(i[_]<o[_]&&(i=yield*e[W](o[_],n)),o[st]=i[o[_]-1]+1,o[_]+=1):o[xn]===112&&(i[_]<o[_]&&(i=yield*e[W](o[_],n)),o[st]=(i[o[_]-1]<<8)+i[o[_]]+1,o[_]+=2),o[G]=o[st],o[Qe]===12?(i[_]<o[_]&&(i=yield*e[W](o[_],n)),o[V]=i[o[_]-1]*1e3,o[_]+=1):o[Qe]===13?(i[_]<o[_]&&(i=yield*e[W](o[_],n)),o[V]=(i[o[_]-1]<<8)+i[o[_]],o[_]+=2):o[Qe]===14&&(i[_]<o[_]&&(i=yield*e[W](o[_],n)),o[V]=((i[o[_]-1]<<8)+i[o[_]])*10,o[_]+=2),i[_]<o[_]&&(i=yield*e[W](o[_],n)),o[Ar]=i[o[_]-1],o[Ar]!==lc(i[k](0,o[_]-1))))return null;if(!a){let{blockingStrategyBits:l,frameNumber:d,sampleNumber:u,samples:f,sampleRateBits:m,blockSizeBits:h,crc:y,length:p,...g}=o;r[Oe](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,P0=512*1024,jt=class extends be{constructor(e,r,n){super(e,r),this.Frame=Ct,this.Header=Rt,n(this[Q])}get[Q](){return"flac"}*_getNextFrameSyncOffset(e){let r=yield*this._codecParser[W](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*Rt[X](this._codecParser,this._headerCache,0);if(e){let r=ce.get(e)[_]+z0;for(;r<=P0;){if(this._codecParser._flushing||(yield*Rt[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=Rt[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 Tt(ge.from(o[k](0,28))[qe]);i[Ve]=fc(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[W](i[_],n),i[Ae]=0,i[wt]=[],i[Er]=ge.from(o[k](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*[De](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[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)[_]=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[G]=0,this[Je]=e[Je]}};var Tr=class extends Te{constructor(e,r,n){super(r,e,n)}};var Sc={0:en.slice(0,2),1:en},ke="SILK-only",ue="CELT-only",Qi="Hybrid",zt="narrowband",Ji="medium-band",Pt="wideband",Cr="super-wideband",Rr="fullband",F0={0:{[O]:ke,[N]:zt,[F]:10},8:{[O]:ke,[N]:zt,[F]:20},16:{[O]:ke,[N]:zt,[F]:40},24:{[O]:ke,[N]:zt,[F]:60},32:{[O]:ke,[N]:Ji,[F]:10},40:{[O]:ke,[N]:Ji,[F]:20},48:{[O]:ke,[N]:Ji,[F]:40},56:{[O]:ke,[N]:Ji,[F]:60},64:{[O]:ke,[N]:Pt,[F]:10},72:{[O]:ke,[N]:Pt,[F]:20},80:{[O]:ke,[N]:Pt,[F]:40},88:{[O]:ke,[N]:Pt,[F]:60},96:{[O]:Qi,[N]:Cr,[F]:10},104:{[O]:Qi,[N]:Cr,[F]:20},112:{[O]:Qi,[N]:Rr,[F]:10},120:{[O]:Qi,[N]:Rr,[F]:20},128:{[O]:ue,[N]:zt,[F]:2.5},136:{[O]:ue,[N]:zt,[F]:5},144:{[O]:ue,[N]:zt,[F]:10},152:{[O]:ue,[N]:zt,[F]:20},160:{[O]:ue,[N]:Pt,[F]:2.5},168:{[O]:ue,[N]:Pt,[F]:5},176:{[O]:ue,[N]:Pt,[F]:10},184:{[O]:ue,[N]:Pt,[F]:20},192:{[O]:ue,[N]:Cr,[F]:2.5},200:{[O]:ue,[N]:Cr,[F]:5},208:{[O]:ue,[N]:Cr,[F]:10},216:{[O]:ue,[N]:Cr,[F]:20},224:{[O]:ue,[N]:Rr,[F]:2.5},232:{[O]:ue,[N]:Rr,[F]:5},240:{[O]:ue,[N]:Rr,[F]:10},248:{[O]:ue,[N]:Rr,[F]:20}},zr=class t extends Ce{static[Ne](e,r,n){let i={};if(i[R]=e[9],i[at]=e[18],i[_]=i[at]!==0?21+i[R]: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[k](0,i[_]))+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[_]));let l=new Tt(i[$][qe]);if(i[me]=16,i[Ut]=l.getUint16(10,!0),i[Mn]=l.getUint32(12,!0),i[V]=bt,i[hn]=l.getInt16(16,!0),i[at]in Sc&&(i[ye]=Sc[i[at]][i[R]-1],!i[ye]))return null;i[at]!==0&&(i[wn]=e[19],i[sn]=e[20],i[bn]=[...e[k](21,i[R]+21)]);let d=F0[248&r[0]];switch(i[O]=d[O],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,...h}=i;n[Oe](a,i,h)}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[Mn]=e[Mn],this[fn]=e[fn],this[O]=e[O],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=Tr,this.Header=zr,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=zr[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 Tr(r,n,i)}this._codecParser[Ni]("Failed to parse Ogg Opus Header","Not a valid Ogg Opus file")})),e}};var Pr=class extends Te{constructor(e,r,n){super(r,e,n)}};var Ts={};for(let t=0;t<8;t++)Ts[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[k](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[k](0,30));let c=new Tt(a[$][qe]);if(a[_t]=c.getUint32(7,!0),a[_t]!==0||(a[R]=e[11],a[ye]=en[a[R]-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]=Ts[(e[28]&240)>>4],a[Mt]=Ts[e[28]&15],a[Mt]>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,...h}=a;r[Oe](o,a,h)}return new t(a)}constructor(e){super(e),this[tn]=e[tn],this[rn]=e[rn],this[nn]=e[nn],this[Mt]=e[Mt],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=Pr,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 Pr(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[Mt],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;){Tn(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{((Tn(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[_]&&(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[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 Rs=()=>{},Gn=class{constructor(e,{onCodec:r,onCodecHeader:n,onCodecUpdate:i,enableLogging:o=!1,enableFrameCRC32:s=!0}={}){this._inputMimeType=e,this._onCodec=r||Rs,this._onCodecHeader=n||Rs,this._onCodecUpdate=i,this._enableLogging=o,this._crc32=s?uc:Rs,this[We]()}get[Q](){return this._parser?this._parser[Q]:""}[We](){this._headerCache=new Rn(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 Dn(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[_]<=e+r;){if(n=yield,this._flushing)return this._rawData[k](r);n&&(this._totalBytesIn+=n[_],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[$][_]/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[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[_]));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 _c=Gn;var Zi=pe;var eo=$;var
|
|
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*4U((I-H(H*i0J,^*DH+H-H*I+H,I*4)33H(H*H)^*DH(H+H)^*@H+i§H)i§3æ*).§K(iHI/+§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,hi73H,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ô7H,c)(i)H+i´8W)(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,hi73H-i)J+V)&+I,H(H+V)æ,8(I.H(H*8*J-i(p51H-i)J+i¸7V)(H(H+iø7V)(8(J/H(P*0J+s,hi73H+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(i2J,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*4J1J.U(*H.U((J2i')o5/H.U()I.H,H(^*<H0H1U((H.i0J.i§i0i')o5/H/H.H2J*H(J.q50H,P*0J/H*I-H,P*(J0,hH,P*,H-q,hi)I-423+hH*m5+H/H0H(H1U((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-iEr5)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¨1I/+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+H0H1I2i(I-+hH-H2p,hH,H,iP8*J*i(p5-H*i7u,hH,i-H-i)H*c)(H-i)I-4*3i(I/i+I.i+I(*h*h*hH*i86*(*)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,hiI*4,3H,iø-H,i¸)H,i-H18)J(,hi¡I*H(i(p5,H1H,V)ú-H,V)ø-o5,3H,i(H,iXH,i-H1i)H08)J(,hi I*H(i(p5,H0H,V)H,V)o5,3H,H,iPH,iH8+I*4+3(3(3H,i$6i¬78+I*3H*H3m5(3i)I-H*i(r5)3H)H,P*0^*(H+H,P*<^*(H*I-3H,i2L(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*S7US0U `;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 h=u;u+=f,l.set(r,h);let y=u;u+=4,d.setInt32(y,l.byteLength-u,!0),a(u,y,h,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 ec=El(Za(),1);var y0=()=>globalThis.Worker||ec.default,gr=class extends y0(){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,h=new Promise(y=>{m=y});self.onmessage=({data:{id:y,command:p,data:g}})=>{let S=h,x={id:y},v;p==="init"?(Object.defineProperties(l,{WASMAudioDecoderCommon:{value:d},EmscriptenWASM:{value:u},module:{value:g.module},isWebWorker:{value:!0}}),f=new l(g.options),m()):p==="free"?f.free():p==="ready"?S=S.then(()=>f.ready):p==="reset"?S=S.then(()=>f.reset()):(Object.assign(x,f[p](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,tc=", ",F=(()=>{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(tc)))})(),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(tc)})`,en=[gt,te(2,F[0][0]),te(3,F[0][2]),te(4,F[1][0],F[3][0]),te(5,F[1][2],F[3][0]),te(6,F[1][2],F[3][0],Ye),te(7,F[1][2],F[2][0],F[3][4],Ye),te(8,F[1][2],F[2][0],F[3][0],Ye)],rc=192e3,nc=176400,Ei=96e3,Ti=88200,ic=64e3,bt=48e3,xr=44100,br=32e3,vr=24e3,Sr=22050,_r=16e3,Ii=12e3,Ci=11025,Ar=8e3,oc=7350,Ve="absoluteGranulePosition",N="bandwidth",me="bitDepth",he="bitrate",tn=he+"Maximum",rn=he+"Minimum",nn=he+"Nominal",qe="buffer",on=qe+"Fullness",J="codec",pe=J+"Frames",sn="coupledStreamCount",Mr="crc",an=Mr+"16",cn=Mr+"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",Ae="layer",_="length",O="mode",nt=O+"Extension",Ri="mpeg",it=Ri+"Version",mn="numberAACFrames",hn="outputGain",Ut="preSkip",pn="profile",zi=ee(),ot="protection",ys="rawData",Pe="segments",k="subarray",_t="version",Ht="vorbis",yn=Ht+"Comments",Lr=Ht+"Setup",Fi="block",gn=Fi+"ingStrategy",Pi=ee(),st=Fi+"Size",At=Fi+"size0",Mt=Fi+"size1",xn=ee(),Bi="channel",at=Bi+"MappingFamily",bn=Bi+"MappingTable",ye=Bi+"Mode",vn=ee(),R=Bi+"s",sc="copyright",Sn=sc+"Id",_n=sc+"IdStart",ct="frame",lt=ct+"Count",Me=ct+"Length",Oi="Number",dt=ct+Oi,je=ct+"Padding",P=ct+"Size",ac="Rate",An="inputSample"+ac,gs="page",Vt=gs+"Checksum",Er=ee(),wt=gs+"SegmentTable",oe=gs+"Sequence"+Oi,xs="sample",Mn=xs+Oi,V=xs+ac,Je=ee(),G=xs+"s",Di="stream",wn=Di+"Count",Ln=Di+"Info",Qe=Di+"Serial"+Oi,bs=Di+"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(),Oe=ee(),De=ee(),Ze=ee(),Tt=ee(),ki=ee(),We=ee(),Xe=ee(),Ne=ee(),Ui=ee(),ge=Uint8Array,It=DataView,K="reserved",xe="bad",Tr="free",Tn="none",Hi="16bit CRC";var _s=(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},x0=_s(new ge(256),t=>t,t=>t&128?7^t<<1:t<<1),re=[_s(new Uint16Array(256),t=>t<<8,t=>t<<1^(t&32768?32773:0))],ne=[_s(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 lc=t=>{let e=0,r=t[_];for(let n=0;n!==r;n++)e=x0[e^t[n]];return e},dc=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},uc=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},Te=t=>String.fromCharCode(...t),cc=[0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15],In=t=>cc[t&15]<<4|cc[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,(In(this._data[r-1])<<8)+In(this._data[r])>>7-n&255}},fc=(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 Rn=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}[Oe](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[De](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 Ie=class extends Kt{static*[De](e,r,n,i,o){let s=yield*e[X](n,i,o);if(s){let a=ce.get(s)[Me],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)[_]=r[_]}};var As="unsynchronizationFlag",Ms="extendedHeaderFlag",ws="experimentalFlag",Ls="footerPresent",zn=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[_t]=`id3v2.${s[3]}.${s[4]}`,s[5]&15)||(o[As]=!!(s[5]&128),o[Ms]=!!(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[_t]=e[_t],this[As]=e[As],this[Ms]=e[Ms],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[R]=e[R],this[ye]=e[ye],this[V]=e[V]}};var gc={0:[Tr,Tr,Tr,Tr,Tr],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++)gc[t<<4]=[t*32,Gi(t,4,0),Gi(t,4,-1),Gi(t,8,4),Gi(t,8,0)];var b0=0,v0=1,S0=2,_0=3,mc=4,Wi="bands ",Xi=" to 31",hc={0:Wi+4+Xi,16:Wi+8+Xi,32:Wi+12+Xi,48:Wi+16+Xi},Yt="bitrateIndex",Fn="v2",ji="v1",Ki="Intensity stereo ",Yi=", MS stereo ",qi="on",$i="off",A0={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]:A0,[ji]:{[Yt]:S0,[G]:1152},[Fn]:{[Yt]:mc,[G]:576}},4:{[z]:"Layer II",[je]:1,[nt]:hc,[G]:1152,[ji]:{[Yt]:v0},[Fn]:{[Yt]:mc}},6:{[z]:"Layer I",[je]:4,[nt]:hc,[G]:384,[ji]:{[Yt]:b0},[Fn]:{[Yt]:_0}}},Ts="MPEG Version ",pc="ISO/IEC ",M0={0:{[z]:`${Ts}2.5 (later extension of MPEG 2)`,[Ae]:Fn,[V]:{0:Ci,4:Ii,8:Ar,12:K}},8:{[z]:K},16:{[z]:`${Ts}2 (${pc}13818-3)`,[Ae]:Fn,[V]:{0:Sr,4:vr,8:_r,12:K}},24:{[z]:`${Ts}1 (${pc}11172-3)`,[Ae]:ji,[V]:{0:xr,4:bt,8:br,12:K}},length:_},w0={0:Hi,1:Tn},L0={0:Tn,1:"50/15 ms",2:K,3:"CCIT J.17"},yc={0:{[R]:2,[z]:xt},64:{[R]:2,[z]:"joint "+xt},128:{[R]:2,[z]:"dual channel"},192:{[R]:1,[z]:gt}},qt=class t extends Ce{static*[X](e,r,n){let i={},o=yield*zn.getID3v2Header(e,r,n);o&&(yield*e[W](o[_],n),e[Be](o[_]));let s=yield*e[W](4,n),a=Te(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=M0[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[Ae]]};if(i[it]=l[z],i[Ae]=u[z],i[G]=u[G],i[ot]=w0[s[1]&1],i[_]=4,i[he]=gc[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[Me]=Math.floor(125*i[he]*i[G]/i[V]+i[je]),!i[Me]))return null;let f=s[3]&192;if(i[ye]=yc[f][z],i[R]=yc[f][R],i[nt]=u[nt][s[3]&48],i[dn]=!!(s[3]&8),i[tt]=!!(s[3]&4),i[wr]=L0[s[3]&3],i[wr]===K)return null;i[me]=16;{let{length:m,frameLength:h,samples:y,...p}=i;r[Oe](a,i,p)}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[Ae]=e[Ae],this[nt]=e[nt],this[it]=e[it],this[ot]=e[ot]}};var Pn=class t extends Ie{static*[De](e,r,n){return yield*super[De](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=Pn,this.Header=qt,n(this[J])}get[J](){return Ri}*[Ze](){return yield*this[Et]()}};var E0={0:"MPEG-4",8:"MPEG-2"},T0={0:"valid",2:xe,4:xe,6:xe},I0={0:Hi,1:Tn},C0={0:"AAC Main",64:"AAC LC (Low Complexity)",128:"AAC SSR (Scalable Sample Rate)",192:"AAC LTP (Long Term Prediction)"},R0={0:Ei,4:Ti,8:ic,12:bt,16:xr,20:br,24:vr,28:Sr,32:_r,36:Ii,40:Ci,44:Ar,48:oc,52:K,56:K,60:"frequency is written explicitly"},xc={0:{[R]:0,[z]:"Defined in AOT Specific Config"},64:{[R]:1,[z]:gt},128:{[R]:2,[z]:te(2,F[0][0])},192:{[R]:3,[z]:te(3,F[1][3])},256:{[R]:4,[z]:te(4,F[1][3],F[3][4])},320:{[R]:5,[z]:te(5,F[1][3],F[3][0])},384:{[R]:6,[z]:te(6,F[1][3],F[3][0],Ye)},448:{[R]:8,[z]:te(8,F[1][3],F[2][0],F[3][0],Ye)}},$t=class t extends Ce{static*[X](e,r,n){let i={},o=yield*e[W](7,n),s=Te([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]=E0[o[1]&8],i[Ae]=T0[o[1]&6],i[Ae]===xe))return null;let l=o[1]&1;i[ot]=I0[l],i[_]=l?7:9,i[zi]=o[2]&192,i[Je]=o[2]&60;let d=o[2]&2;if(i[pn]=C0[i[zi]],i[V]=R0[i[Je]],i[V]===K)return null;i[rt]=!!d,i[vn]=(o[2]<<8|o[3])&448,i[ye]=xc[i[vn]][z],i[R]=xc[i[vn]][R],i[tt]=!!(o[3]&32),i[un]=!!(o[3]&8),i[Sn]=!!(o[3]&8),i[_n]=!!(o[3]&4),i[me]=16,i[G]=1024,i[mn]=o[6]&3;{let{length:u,channelModeBits:f,profileBits:m,sampleRateBits:h,frameLength:y,samples:p,numberAACFrames:g,...S}=i;r[Oe](s,i,S)}}if(i[Me]=(o[3]<<11|o[4]<<3|o[5]>>5)&8191,!i[Me])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[_n]=e[_n],this[on]=e[on],this[un]=e[un],this[tt]=e[tt],this[rt]=e[rt],this[Ae]=e[Ae],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[zi]+64<<5|e[Je]<<5|e[vn]>>3,n=new ge(2);return new It(n[qe]).setUint16(0,r,!1),n}};var On=class t extends Ie{static*[De](e,r,n){return yield*super[De]($t,t,e,r,n)}constructor(e,r,n){super(e,r,n)}};var Dn=class extends be{constructor(e,r,n){super(e,r),this.Frame=On,this.Header=$t,n(this[J])}get[J](){return"aac"}*[Ze](){return yield*this[Et]()}};var Ct=class t extends Ie{static _getFrameFooterCrc16(e){return(e[e[_]-2]<<8)+e[e[_]-1]}static[Ui](e){let r=t._getFrameFooterCrc16(e),n=dc(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 bc="get from STREAMINFO metadata block",z0={0:"Fixed",1:"Variable"},vc={0:K,16:192};for(let t=2;t<16;t++)vc[t<<4]=t<6?576*2**(t-2):2**t;var F0={0:bc,1:Ti,2:nc,3:rc,4:Ar,5:_r,6:Sr,7:vr,8:br,9:xr,10:bt,11:Ei,15:xe},P0={0:{[R]:1,[z]:gt},16:{[R]:2,[z]:te(2,F[0][0])},32:{[R]:3,[z]:te(3,F[0][1])},48:{[R]:4,[z]:te(4,F[1][0],F[3][0])},64:{[R]:5,[z]:te(5,F[1][1],F[3][0])},80:{[R]:6,[z]:te(6,F[1][1],Ye,F[3][0])},96:{[R]:7,[z]:te(7,F[1][1],Ye,F[3][4],F[2][0])},112:{[R]:8,[z]:te(8,F[1][1],Ye,F[3][0],F[2][0])},128:{[R]:2,[z]:`${xt} (left, diff)`},144:{[R]:2,[z]:`${xt} (diff, right)`},160:{[R]:2,[z]:`${xt} (avg, diff)`},176:K,192:K,208:K,224:K,240:K},B0={0:bc,2:8,4:12,6:K,8:16,10:20,12:24,14:K},Rt=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=Te(i[k](0,4)),a=r[X](s);if(a)Object.assign(o,a);else{if(o[Pi]=i[1]&1,o[gn]=z0[o[Pi]],o[xn]=i[2]&240,o[Je]=i[2]&15,o[st]=vc[o[xn]],o[st]===K||(o[V]=F0[o[Je]],o[V]===xe)||i[3]&1)return null;let l=P0[i[3]&240];if(l===K||(o[R]=l[R],o[ye]=l[z],o[me]=B0[i[3]&14],o[me]===K))return null}o[_]=5,i=yield*e[W](o[_]+8,n);let c=t._decodeUTF8Int(i[k](4));if(!c||(o[Pi]?o[Mn]=c.value:o[dt]=c.value,o[_]+=c[_],o[xn]===96?(i[_]<o[_]&&(i=yield*e[W](o[_],n)),o[st]=i[o[_]-1]+1,o[_]+=1):o[xn]===112&&(i[_]<o[_]&&(i=yield*e[W](o[_],n)),o[st]=(i[o[_]-1]<<8)+i[o[_]]+1,o[_]+=2),o[G]=o[st],o[Je]===12?(i[_]<o[_]&&(i=yield*e[W](o[_],n)),o[V]=i[o[_]-1]*1e3,o[_]+=1):o[Je]===13?(i[_]<o[_]&&(i=yield*e[W](o[_],n)),o[V]=(i[o[_]-1]<<8)+i[o[_]],o[_]+=2):o[Je]===14&&(i[_]<o[_]&&(i=yield*e[W](o[_],n)),o[V]=((i[o[_]-1]<<8)+i[o[_]])*10,o[_]+=2),i[_]<o[_]&&(i=yield*e[W](o[_],n)),o[Mr]=i[o[_]-1],o[Mr]!==lc(i[k](0,o[_]-1))))return null;if(!a){let{blockingStrategyBits:l,frameNumber:d,sampleNumber:u,samples:f,sampleRateBits:m,blockSizeBits:h,crc:y,length:p,...g}=o;r[Oe](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[Mn]=e[Mn],this[Ln]=null}};var O0=2,D0=512*1024,jt=class extends be{constructor(e,r,n){super(e,r),this.Frame=Ct,this.Header=Rt,n(this[J])}get[J](){return"flac"}*_getNextFrameSyncOffset(e){let r=yield*this._codecParser[W](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*Rt[X](this._codecParser,this._headerCache,0);if(e){let r=ce.get(e)[_]+O0;for(;r<=D0;){if(this._codecParser._flushing||(yield*Rt[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)}[Tt](e){return e[oe]===0?(this._headerCache[Xe](),this._streamInfo=e[$][k](13)):e[oe]===1||(e[pe]=de.get(e)[Pe].map(r=>{let n=Rt[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 Jt=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 It(ge.from(o[k](0,28))[qe]);i[Ve]=fc(a,6),i[Qe]=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[W](i[_],n),i[Me]=0,i[wt]=[],i[Er]=ge.from(o[k](27,i[_]));for(let l=0,d=0;l<c;l++){let u=i[Er][l];i[Me]+=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[Qe]=e[Qe]}};var Nn=class t extends Kt{static*[De](e,r,n){let i=yield*Jt[X](e,r,n);if(i){let o=ce.get(i)[Me],s=ce.get(i)[_],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)[_]=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[G]=0,this[Qe]=e[Qe]}};var Ir=class extends Ie{constructor(e,r,n){super(r,e,n)}};var Sc={0:en.slice(0,2),1:en},ke="SILK-only",ue="CELT-only",Ji="Hybrid",zt="narrowband",Qi="medium-band",Ft="wideband",Cr="super-wideband",Rr="fullband",N0={0:{[O]:ke,[N]:zt,[P]:10},8:{[O]:ke,[N]:zt,[P]:20},16:{[O]:ke,[N]:zt,[P]:40},24:{[O]:ke,[N]:zt,[P]:60},32:{[O]:ke,[N]:Qi,[P]:10},40:{[O]:ke,[N]:Qi,[P]:20},48:{[O]:ke,[N]:Qi,[P]:40},56:{[O]:ke,[N]:Qi,[P]:60},64:{[O]:ke,[N]:Ft,[P]:10},72:{[O]:ke,[N]:Ft,[P]:20},80:{[O]:ke,[N]:Ft,[P]:40},88:{[O]:ke,[N]:Ft,[P]:60},96:{[O]:Ji,[N]:Cr,[P]:10},104:{[O]:Ji,[N]:Cr,[P]:20},112:{[O]:Ji,[N]:Rr,[P]:10},120:{[O]:Ji,[N]:Rr,[P]:20},128:{[O]:ue,[N]:zt,[P]:2.5},136:{[O]:ue,[N]:zt,[P]:5},144:{[O]:ue,[N]:zt,[P]:10},152:{[O]:ue,[N]:zt,[P]:20},160:{[O]:ue,[N]:Ft,[P]:2.5},168:{[O]:ue,[N]:Ft,[P]:5},176:{[O]:ue,[N]:Ft,[P]:10},184:{[O]:ue,[N]:Ft,[P]:20},192:{[O]:ue,[N]:Cr,[P]:2.5},200:{[O]:ue,[N]:Cr,[P]:5},208:{[O]:ue,[N]:Cr,[P]:10},216:{[O]:ue,[N]:Cr,[P]:20},224:{[O]:ue,[N]:Rr,[P]:2.5},232:{[O]:ue,[N]:Rr,[P]:5},240:{[O]:ue,[N]:Rr,[P]:10},248:{[O]:ue,[N]:Rr,[P]:20}},zr=class t extends Ce{static[Ne](e,r,n){let i={};if(i[R]=e[9],i[at]=e[18],i[_]=i[at]!==0?21+i[R]: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=Te(e[k](0,i[_]))+Te(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[_]));let l=new It(i[$][qe]);if(i[me]=16,i[Ut]=l.getUint16(10,!0),i[An]=l.getUint32(12,!0),i[V]=bt,i[hn]=l.getInt16(16,!0),i[at]in Sc&&(i[ye]=Sc[i[at]][i[R]-1],!i[ye]))return null;i[at]!==0&&(i[wn]=e[19],i[sn]=e[20],i[bn]=[...e[k](21,i[R]+21)]);let d=N0[248&r[0]];switch(i[O]=d[O],i[N]=d[N],i[P]=d[P],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,...h}=i;n[Oe](a,i,h)}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[P]=e[P],this[ln]=e[ln],this[An]=e[An],this[fn]=e[fn],this[O]=e[O],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=Ir,this.Header=zr,n(this[J]),this._identificationHeader=null,this._preSkipRemaining=null}get[J](){return"opus"}[Tt](e){return e[oe]===0?(this._headerCache[Xe](),this._identificationHeader=e[$]):e[oe]===1||(e[pe]=de.get(e)[Pe].map(r=>{let n=zr[Ne](this._identificationHeader,r,this._headerCache);if(n){this._preSkipRemaining===null&&(this._preSkipRemaining=n[Ut]);let i=n[P]*n[lt]/1e3*n[V];return this._preSkipRemaining>0&&(this._preSkipRemaining-=i,i=this._preSkipRemaining<0?-this._preSkipRemaining:0),new Ir(r,n,i)}this._codecParser[Ni]("Failed to parse Ogg Opus Header","Not a valid Ogg Opus file")})),e}};var Fr=class extends Ie{constructor(e,r,n){super(r,e,n)}};var Is={};for(let t=0;t<8;t++)Is[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=Te(e[k](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[k](0,30));let c=new It(a[$][qe]);if(a[_t]=c.getUint32(7,!0),a[_t]!==0||(a[R]=e[11],a[ye]=en[a[R]-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[Mt]=Is[(e[28]&240)>>4],a[At]=Is[e[28]&15],a[At]>a[Mt])||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,...h}=a;r[Oe](o,a,h)}return new t(a)}constructor(e){super(e),this[tn]=e[tn],this[rn]=e[rn],this[nn]=e[nn],this[At]=e[At],this[Mt]=e[Mt],this[$]=e[$],this[yn]=e[yn],this[Lr]=e[Lr]}};var Hn=class extends be{constructor(e,r,n){super(e,r),this.Frame=Fr,n(this[J]),this._identificationHeader=null,this._setupComplete=!1,this._prevBlockSize=null}get[J](){return Ht}[Tt](e){e[pe]=[];for(let r of de.get(e)[Pe])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 Fr(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[Mt]:r[At],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;){In(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{((In(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[J](){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=Te(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[Pe]=n[wt].map(o=>e[$][k](i,i+=o)),this._continuedPacket[_]&&(r[Pe][0]=Cn(this._continuedPacket,r[Pe][0]),this._continuedPacket=new ge),n[Er][n[Er][_]-1]===255&&(this._continuedPacket=Cn(this._continuedPacket,r[Pe].pop())),this._previousAbsoluteGranulePosition!==null&&(e[G]=Number(e[Ve]-this._previousAbsoluteGranulePosition)),this._previousAbsoluteGranulePosition=e[Ve],this._isSupported){let o=this._parser[Tt](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=Jt,this._streams=new Map,this._currentSerialNumber=null}get[J](){let e=this._streams.get(this._currentSerialNumber);return e?e.codec:""}*[Ze](){let e=yield*this[Et](!0);this._currentSerialNumber=e[Qe];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 Rs=()=>{},Gn=class{constructor(e,{onCodec:r,onCodecHeader:n,onCodecUpdate:i,enableLogging:o=!1,enableFrameCRC32:s=!0}={}){this._inputMimeType=e,this._onCodec=r||Rs,this._onCodecHeader=n||Rs,this._onCodecUpdate=i,this._enableLogging=o,this._crc32=s?uc:Rs,this[We]()}get[J](){return this._parser?this._parser[J]:""}[We](){this._headerCache=new Rn(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 Dn(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[_]<=e+r;){if(n=yield,this._flushing)return this._rawData[k](r);n&&(this._totalBytesIn+=n[_],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[$][_]/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[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=[`${J}: ${this[J]}`,`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 _c=Gn;var Zi=pe;var eo=$;var Ac=Le;var Mc=Ee;var wc=Lr;var Lc=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,h;function y(){var I=h.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 p=I=>{for(var Re,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)Re=Q[I.charCodeAt(ir+1)],Gr=Q[I.charCodeAt(ir+2)],ci[si]=Q[I.charCodeAt(ir)]<<2|Re>>4,ci[si+1]=Re<<4|Gr>>2,ci[si+2]=Gr<<6|Q[I.charCodeAt(ir+3)];return ci},g=()=>n(""),S=()=>{},x={},v=I=>I(),b=()=>performance.now(),A=(I,Re)=>{if(x[I]&&(clearTimeout(x[I].id),delete x[I]),!Re)return 0;var Gr=setTimeout(()=>{delete x[I],v(()=>pa(I,b()))},Re);return x[I]={id:Gr,timeout_ms:Re},0},M=Math.atan,w=Math.cos,E=Math.exp,L=Math.log,B=Math.pow,D=Math.sin,U=I=>{var Re=a.length;return I>>>=0,!1},C=I=>{throw`exit(${I})`},Q=new Uint8Array(123),_e=25;_e>=0;--_e)Q[48+_e]=52+_e,Q[65+_e]=_e,Q[97+_e]=26+_e;Q[43]=62,Q[47]=63;var Bt={e:g,d:S,f:A,b:M,a:w,i:E,h:L,g:B,c:D,k:U,j:C};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 bl(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¹=
|
|
5
5
|
¨¨%ýv²±»oúâLa:ê±ÊäÌÓ.÷Øý×>àW>z¯°8¯ñ\Ñós9\§ôÊ@Ü (tÃø4° ¢7fqÓg²Jè6x[zç®&4=} p.(°tÍÞã¾>÷CõË"*k?¿~7~H2ÛÜâ.ÏQä;6{ÜãFÑá'DD¤±°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ïgN¾)ø§\V0uSIö:ÌU4ж¯´Õn9ÔèE£ZƼ{hµmÙ¾6ÆÑ+xñ´«þ¸=Mߤ·å®«ïÆGFÝì|H?äE"þ!9«Æïpæ'][¯ù·£W÷O§&#ax$qf=}ø ô bÏ×W÷LôoÝWQÕÓ)u÷½èV|¥Gà¨Ö¸@ê|ÇK5ò A·Â9CS2¸¼¿,äÝÑÝy!ÑR%ÆÝÎ0Âv§ qTcó±hØÉã=}Z=}Ælüën¯ð(-°ÜwVÏï.th¥íS~SÏ»ZZÔZ
|
|
6
6
|
3BÌÛ¬<éæ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óäsE\ýïé§Ö:Ò'Cç(_X$\¦½eÒ8$XF|eíÙÓ¡¤Û<ØÞÛ¸9¿ðÃÎ#b~× 4éîÿÏq
|
|
7
7
|
ód|0wU&®è·vh6¨{ÚçÚ18Ó(ÓY\0¦= çèíß)Ø=}[xü-v?N(Kkg0}âÚ´ð¬ÕQNÍ¢usѳ=}. ëg
û= ÍMBp'²¨ x4è@9t§eݵ¾âð½ z?Z¹FH'̯¿<K,üµ<{ ¶JãývåàÆeù0Ð"F¥ÃÒÞþÔÉvCzl}ðN£ Í^P%²¸FX»WÎêô¶
äÉJ^g×SÃã.Ät*'ªG«ÒB<ÜÓ
¿ºp\àuV¯£ÅݽáÞ ùß=}ÎÚ^ÿí>¥!¨ â=M·?*/¤"å)â·ÿîÿî*(%*2[½"üríÔ4l½»a}¯CwpCÓèìGc-ã6®=M32k?Êg
!So-x>³G+ã@ò, ÁïáåN0þÙè.~È÷¡vTr¶Ã[üB±º»ávëw¹{pܺû"Aæ±9Æ^¹³òïRIAy5GÂwÉf4@Tù|qý7ðªwBL|Ôqv!ª°|]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ÑUy¹¦ß§/6P0(Cúýb"þ¥°VÙÄá£ÓÙ@¾YýòD{òÃv?EP©=MBé\ĽYäýRò øfâëEEf¼D+gC×úDZGÅÿ±Ç?TzÙ¡±ÏÁÕ¯¦ðvZmT}3xËz×cºrÑM=Mc-É©Ô7½wæc§Î»cû¾yfÙWòÆÝÔc¥³ôØf«Äñ·9ø%g:y^+{U]¤þ
[&fÓÏYë«Gªõ¹¦Öðþ¬moÛø?/ÛS.[S9ÛùC
/û2²Y£ÎÑ%/sy¢×ÌùJW6Oí\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¶ÌºHgNjÒ{æ¾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 vl={a:Bt};this.setModule=T=>{t.setModule(ut,T)},this.getModule=()=>t.getModule(ut),this.instantiate=()=>(this.getModule().then(T=>WebAssembly.instantiate(T,vl)).then(T=>{let Re=T.exports;oi(Re),h=Re.l,y(),bl(Re),r()}),this.ready=new Promise(T=>{r=T}).then(()=>{this.HEAP=h.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 _c("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[wc]),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[Ac]){let o=this._totalSamplesDecoded-i[Lc];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 zs=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](zs)}async free(){await this._decoder.free()}terminate(){this._decoder.terminate()}};Li(ft,"OggVorbisDecoder");Li(Wn,"OggVorbisDecoderWebWorker");var Ps=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 Ps(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 B0="quake2ts-pak-indexes",O0="pak-indexes";function Ec(){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=Ec();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=B0,r=O0){this.dbName=e;this.storeName=r}get isSupported(){return!!Ec()}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=Mi(Jr(n));else if(i==="tga")o=Qa(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||{}),Ic=-1,so=0,Tc=1,Cc=2,Rc=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 N0=7,$n=t=>t&N0;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=Pc(u?.gainScale??1),m=this.resolveOcclusion?this.createOcclusionFilter(n,u?.lowpassHz??2e4):void 0;this.applyOriginToPanner(d,c);let h=e.entity===this.playerEntity,y=po(c,this.listener,e.volume,e.attenuation,h),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=Os(r,10,2e4),n}applyOcclusion(e,r){let n=Pc(r?.gainScale??1);if(e.gain.gain.value=e.baseGain*n,e.occlusion?.filter){let i=r?.lowpassHz??2e4;e.occlusion.filter.frequency.value=Os(i,10,2e4)}e.occlusion?(e.occlusion.scale=n,e.occlusion.lowpassHz=r?.lowpassHz):r&&(e.occlusion={scale:n,lowpassHz:r.lowpassHz})}},Os=(t,e,r)=>Math.min(r,Math.max(e,t)),Pc=t=>Os(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 k0(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 U0(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 Fc(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");k0(o);let s=new Map;U0(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 Bc(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 H0(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=Bc(e,e.VERTEX_SHADER,r.vertex),o=Bc(e,e.FRAGMENT_SHADER,r.fragment);try{let s=H0(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 Oc(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)}},Or=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)}},Dr=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,Ds=7*Ns,ks=[{index:0,size:3,type:5126,stride:Ds,offset:0},{index:1,size:2,type:5126,stride:Ds,offset:3*Ns},{index:2,size:2,type:5126,stride:Ds,offset:5*Ns}];function V0(t,e){return{width:t,height:t,padding:e,data:new Uint8Array(t*t*4),cursorX:0,cursorY:0,rowHeight:0}}function G0(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 W0(t,e,r){let n=G0(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 X0(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=V0(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 K0(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 Y0(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 q0(t,e){let r=bo(t.vertices),n=bo(t.textureCoords),i=e?Y0(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],h=t.edges[Math.abs(m)],y=m>=0?h.vertices[0]:h.vertices[1],p=t.vertices[y];o.push(p[0],p[1],p[2]);let g=p[0]*i.s[0]+p[1]*i.s[1]+p[2]*i.s[2]+i.sOffset,S=p[0]*i.t[0]+p[1]*i.t[1]+p[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,h=1/0,y=-1/0;for(let b=0;b<s.length;b+=2){let M=s[b],A=s[b+1];M<f&&(f=M),M>m&&(m=M),A<h&&(h=A),A>y&&(y=A)}let p=Math.floor(f/16),g=Math.floor(h/16),S=Math.ceil(m/16)-p+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-p+.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,faceIndex:r})}return e}function Nc(t,e,r,n={}){let i=e;if(r&&n.hiddenClassnames&&n.hiddenClassnames.size>0){let d=new Set;for(let u of r.entities.entities)if(u.classname&&n.hiddenClassnames.has(u.classname)){let f=u.properties.model;if(f&&f.startsWith("*")){let m=parseInt(f.substring(1),10);if(!isNaN(m)&&m>=0&&m<r.models.length){let h=r.models[m];for(let y=0;y<h.numFaces;y++)d.add(h.firstFace+y)}}}d.size>0&&(i=e.filter(u=>!d.has(u.faceIndex)))}let o={atlasSize:n.atlasSize??1024,lightmapPadding:n.lightmapPadding??1,hiddenClassnames:n.hiddenClassnames??new Set},s=[],a=new Map;i.forEach((d,u)=>{if(!d.lightmap)return;let{placement:f,atlas:m}=X0(s,d.lightmap,o);W0(m,f,d.lightmap),a.set(u,{atlasIndex:f.atlasIndex,offset:[(f.x+o.lightmapPadding)/o.atlasSize,(f.y+o.lightmapPadding)/o.atlasSize],scale:[f.width/o.atlasSize,f.height/o.atlasSize]})});let c=s.map(d=>{let u=new Or(t);return u.setParameters({wrapS:t.CLAMP_TO_EDGE,wrapT:t.CLAMP_TO_EDGE,minFilter:t.LINEAR,magFilter:t.LINEAR}),u.uploadImage(0,t.RGBA,d.width,d.height,0,t.RGBA,t.UNSIGNED_BYTE,d.data),{texture:u,width:d.width,height:d.height,pixels:d.data}});return{surfaces:i.map((d,u)=>{let f=a.get(u),m=q0(d,f),h=K0(d.indices,m.length/7),y=new Se(t,t.STATIC_DRAW,t.ARRAY_BUFFER);y.upload(m);let p=new fe(t,t.STATIC_DRAW);p.upload(h);let g=new we(t);return g.configureAttributes(ks,y),{vao:g,vertexBuffer:y,indexBuffer:p,indexCount:h.length,vertexCount:m.length/7,texture:d.texture,surfaceFlags:d.surfaceFlags??Kr,lightmap:f,vertexData:m,indexData:h}}),lightmaps:c}}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 kc(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],h=t[7],y=t[11],p=t[15];return[Nr({normal:{x:m+e,y:h+r,z:y+n},distance:p+i}),Nr({normal:{x:m-e,y:h-r,z:y-n},distance:p-i}),Nr({normal:{x:m+o,y:h+s,z:y+a},distance:p+c}),Nr({normal:{x:m-o,y:h-s,z:y-a},distance:p-c}),Nr({normal:{x:m+l,y:h+d,z:y+u},distance:p+f}),Nr({normal:{x:m-l,y:h-d,z:y-u},distance:p-f})]}function $0(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($0(n,{x:i,y:o,z:s})<0)return!1}return!0}function Uc(t){return t<0}function Hc(t){return-t-1}function Vc(t,e){return t.normal[0]*e.x+t.normal[1]*e.y+t.normal[2]*e.z-t.dist}function j0(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 Q0(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=Vc(i,e)>=0?0:1,a=n.children[s];if(Uc(a))return Hc(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(Uc(e)){let f=Hc(e),m=t.leafs[f];if(!j0(t.visibility,i,m.cluster)||!Q0(m,n))return;let h={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=h.x-r.x,p=h.y-r.y,g=h.z-r.z,S=-(y*y+p*p+g*g);for(let x of J0(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=Vc(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 Gc(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 vl={a:Bt};this.setModule=I=>{t.setModule(ut,I)},this.getModule=()=>t.getModule(ut),this.instantiate=()=>(this.getModule().then(I=>WebAssembly.instantiate(I,vl)).then(I=>{let Re=I.exports;oi(Re),h=Re.l,y(),bl(Re),r()}),this.ready=new Promise(I=>{r=I}).then(()=>{this.HEAP=h.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 Qt(){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=Qt.isWebWorker,this._WASMAudioDecoderCommon=Qt.WASMAudioDecoderCommon||Z,this._EmscriptenWASM=Qt.EmscriptenWASM||ut,this._module=Qt.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](Qt)}_init(){this._vorbisSetupInProgress=!0,this._totalSamplesDecoded=0,this._codecParser=new _c("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][Ac];this._decoder.sendSetupHeader(a[wc]),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[Mc]){let o=this._totalSamplesDecoded-i[Lc];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 zs=class extends gr{constructor(e){super(e,"ogg-vorbis-decoder",Qt,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](zs)}async free(){await this._decoder.free()}terminate(){this._decoder.terminate()}};Li(ft,"OggVorbisDecoder");Li(Wn,"OggVorbisDecoderWebWorker");var Fs=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 Fs(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"}},Pr=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 k0="quake2ts-pak-indexes",U0="pak-indexes";function Ec(){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=Ec();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 Ps(t,e){return`${ie(t)}:${e.toString(16)}`}function H0(t){return t.map(e=>({...e}))}var no=class{constructor(e=k0,r=U0){this.dbName=e;this.storeName=r}get isSupported(){return!!Ec()}async persist(e){if(!this.isSupported)return;let r=e.validate(),n={...r,key:Ps(e.name,r.checksum),name:e.name,size:e.size,persistedAt:Date.now(),entries:H0(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?Ps(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?Ps(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 Pr(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=Qr(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=Mi(n,this.palette);else if(i==="pcx")o=Ai(Qr(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||{}),Tc=-1,so=0,Ic=1,Cc=2,Rc=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 V0=7,$n=t=>t&V0;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=Jo(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=Fc(u?.gainScale??1),m=this.resolveOcclusion?this.createOcclusionFilter(n,u?.lowpassHz??2e4):void 0;this.applyOriginToPanner(d,c);let h=e.entity===this.playerEntity,y=po(c,this.listener,e.volume,e.attenuation,h),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=Os(r,10,2e4),n}applyOcclusion(e,r){let n=Fc(r?.gainScale??1);if(e.gain.gain.value=e.baseGain*n,e.occlusion?.filter){let i=r?.lowpassHz??2e4;e.occlusion.filter.frequency.value=Os(i,10,2e4)}e.occlusion?(e.occlusion.scale=n,e.occlusion.lowpassHz=r?.lowpassHz):r&&(e.occlusion={scale:n,lowpassHz:r.lowpassHz})}},Os=(t,e,r)=>Math.min(r,Math.max(e,t)),Fc=t=>Os(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 G0(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 W0(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 Pc(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");G0(o);let s=new Map;W0(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 Bc(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 X0(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=Bc(e,e.VERTEX_SHADER,r.vertex),o=Bc(e,e.FRAGMENT_SHADER,r.fragment);try{let s=X0(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 Oc(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)}},Or=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)}},Dr=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,Ds=7*Ns,ks=[{index:0,size:3,type:5126,stride:Ds,offset:0},{index:1,size:2,type:5126,stride:Ds,offset:3*Ns},{index:2,size:2,type:5126,stride:Ds,offset:5*Ns}];function K0(t,e){return{width:t,height:t,padding:e,data:new Uint8Array(t*t*4),cursorX:0,cursorY:0,rowHeight:0}}function Y0(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 q0(t,e,r){let n=Y0(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 $0(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=K0(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 j0(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 J0(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 Q0(t,e){let r=bo(t.vertices),n=bo(t.textureCoords),i=e?J0(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],h=t.edges[Math.abs(m)],y=m>=0?h.vertices[0]:h.vertices[1],p=t.vertices[y];o.push(p[0],p[1],p[2]);let g=p[0]*i.s[0]+p[1]*i.s[1]+p[2]*i.s[2]+i.sOffset,S=p[0]*i.t[0]+p[1]*i.t[1]+p[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,h=1/0,y=-1/0;for(let b=0;b<s.length;b+=2){let A=s[b],M=s[b+1];A<f&&(f=A),A>m&&(m=A),M<h&&(h=M),M>y&&(y=M)}let p=Math.floor(f/16),g=Math.floor(h/16),S=Math.ceil(m/16)-p+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-p+.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,faceIndex:r})}return e}function Nc(t,e,r,n={}){let i=e;if(r&&n.hiddenClassnames&&n.hiddenClassnames.size>0){let d=new Set;for(let u of r.entities.entities)if(u.classname&&n.hiddenClassnames.has(u.classname)){let f=u.properties.model;if(f&&f.startsWith("*")){let m=parseInt(f.substring(1),10);if(!isNaN(m)&&m>=0&&m<r.models.length){let h=r.models[m];for(let y=0;y<h.numFaces;y++)d.add(h.firstFace+y)}}}d.size>0&&(i=e.filter(u=>!d.has(u.faceIndex)))}let o={atlasSize:n.atlasSize??1024,lightmapPadding:n.lightmapPadding??1,hiddenClassnames:n.hiddenClassnames??new Set},s=[],a=new Map;i.forEach((d,u)=>{if(!d.lightmap)return;let{placement:f,atlas:m}=$0(s,d.lightmap,o);q0(m,f,d.lightmap),a.set(u,{atlasIndex:f.atlasIndex,offset:[(f.x+o.lightmapPadding)/o.atlasSize,(f.y+o.lightmapPadding)/o.atlasSize],scale:[f.width/o.atlasSize,f.height/o.atlasSize]})});let c=s.map(d=>{let u=new Or(t);return u.setParameters({wrapS:t.CLAMP_TO_EDGE,wrapT:t.CLAMP_TO_EDGE,minFilter:t.LINEAR,magFilter:t.LINEAR}),u.uploadImage(0,t.RGBA,d.width,d.height,0,t.RGBA,t.UNSIGNED_BYTE,d.data),{texture:u,width:d.width,height:d.height,pixels:d.data}});return{surfaces:i.map((d,u)=>{let f=a.get(u),m=Q0(d,f),h=j0(d.indices,m.length/7),y=new Se(t,t.STATIC_DRAW,t.ARRAY_BUFFER);y.upload(m);let p=new fe(t,t.STATIC_DRAW);p.upload(h);let g=new we(t);return g.configureAttributes(ks,y),{vao:g,vertexBuffer:y,indexBuffer:p,indexCount:h.length,vertexCount:m.length/7,texture:d.texture,surfaceFlags:d.surfaceFlags??Kr,lightmap:f,vertexData:m,indexData:h}}),lightmaps:c}}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 kc(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],h=t[7],y=t[11],p=t[15];return[Nr({normal:{x:m+e,y:h+r,z:y+n},distance:p+i}),Nr({normal:{x:m-e,y:h-r,z:y-n},distance:p-i}),Nr({normal:{x:m+o,y:h+s,z:y+a},distance:p+c}),Nr({normal:{x:m-o,y:h-s,z:y-a},distance:p-c}),Nr({normal:{x:m+l,y:h+d,z:y+u},distance:p+f}),Nr({normal:{x:m-l,y:h-d,z:y-u},distance:p-f})]}function Z0(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(Z0(n,{x:i,y:o,z:s})<0)return!1}return!0}function Uc(t){return t<0}function Hc(t){return-t-1}function Vc(t,e){return t.normal[0]*e.x+t.normal[1]*e.y+t.normal[2]*e.z-t.dist}function eu(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 tu(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=Vc(i,e)>=0?0:1,a=n.children[s];if(Uc(a))return Hc(a);r=a}return-1}function ru(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(Uc(e)){let f=Hc(e),m=t.leafs[f];if(!eu(t.visibility,i,m.cluster)||!tu(m,n))return;let h={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=h.x-r.x,p=h.y-r.y,g=h.z-r.z,S=-(y*y+p*p+g*g);for(let x of ru(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=Vc(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 Gc(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 Pt=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;
|
|
@@ -171,7 +171,7 @@ struct DLight {
|
|
|
171
171
|
float intensity;
|
|
172
172
|
};
|
|
173
173
|
|
|
174
|
-
const int MAX_DLIGHTS = ${
|
|
174
|
+
const int MAX_DLIGHTS = ${Pt};
|
|
175
175
|
|
|
176
176
|
in vec2 v_texCoord;
|
|
177
177
|
in vec2 v_lightmapCoord;
|
|
@@ -250,7 +250,7 @@ void main() {
|
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
o_color = finalColor;
|
|
253
|
-
}`,Wc=[0,255,255,255];function Ws(t=Wc,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
|
|
253
|
+
}`,Wc=[0,255,255,255];function Ws(t=Wc,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 nu(t){return[-(t*.25%1),0]}function Xs(t=Kr,e=0){let r=(t&Ea)!==0,n=(t&Ma)!==0,i=(t&Aa)!==0,o=(t&wa)!==0,s=(t&La)!==0,a=o?.33:s?.66:1,c=o||s,l=!c&&!i,d=r?nu(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<Pt;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=Wc,styleValues:i=[],diffuseSampler:o=0,lightmapSampler:s,surfaceFlags:a=Kr,timeSeconds:c=0,texScroll:l,alpha:d,warp:u,dlights:f=[],renderMode:m}=e,h=Xs(a,c),y=Ws(n,i),p=l?l[0]:h.flowOffset[0],g=l?l[1]:h.flowOffset[1],S=d!==void 0?d:h.alpha,x=u!==void 0?u:h.warp;this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,r),this.gl.uniform2f(this.uniformTexScroll,p,g),this.gl.uniform2f(this.uniformLmScroll,h.flowOffset[0],h.flowOffset[1]),this.gl.uniform4fv(this.uniformLightStyles,y),this.gl.uniform1f(this.uniformAlpha,S);let v=!h.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,A=[1,1,1,1];m&&(m.mode==="solid"||m.mode==="wireframe"?b=1:m.mode==="solid-faceted"&&(b=2),m.color?A=[...m.color]:m.generateRandomColor&&(A=[1,1,1,1])),this.gl.uniform1i(this.uniformRenderMode,b),this.gl.uniform4f(this.uniformSolidColor,A[0],A[1],A[2],A[3]);let M=Math.min(f.length,Pt);this.gl.uniform1i(this.uniformNumDlights,M);for(let w=0;w<M;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 h}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 Xc(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 Kc=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;
|
|
@@ -288,7 +288,7 @@ struct DLight {
|
|
|
288
288
|
float intensity;
|
|
289
289
|
};
|
|
290
290
|
|
|
291
|
-
const int MAX_DLIGHTS = ${
|
|
291
|
+
const int MAX_DLIGHTS = ${Pt};
|
|
292
292
|
|
|
293
293
|
uniform mat4 u_modelViewProjection;
|
|
294
294
|
uniform mat4 u_modelMatrix;
|
|
@@ -363,7 +363,7 @@ void main() {
|
|
|
363
363
|
}
|
|
364
364
|
|
|
365
365
|
o_color = finalColor;
|
|
366
|
-
}`;function eu(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 $c(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 tu(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:tu(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=$c(u.position,f.position,o),h=eu($c(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]=h.x,c[y+4]=h.y,c[y+5]=h.z,c[y+6]=l.texCoord[0],c[y+7]=l.texCoord[1]}),c}var _o=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()}},Mo=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 h=Math.min(c.length,Ft);this.gl.uniform1i(this.uniformNumDlights,h);for(let y=0;y<h;y++){let p=c[y];this.gl.uniform3f(this.uniformDlights[y].pos,p.origin.x,p.origin.y,p.origin.z),this.gl.uniform3f(this.uniformDlights[y].color,p.color.x,p.color.y,p.color.z),this.gl.uniform1f(this.uniformDlights[y].intensity,p.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 ag=Math.PI/180,cg=180/Math.PI;var ae={};qo(ae,{add:()=>Uu,adjoint:()=>lu,clone:()=>nu,copy:()=>iu,create:()=>ru,decompose:()=>Lu,determinant:()=>du,equals:()=>Wu,exactEquals:()=>Gu,frob:()=>ku,fromQuat:()=>Tu,fromQuat2:()=>Mu,fromRotation:()=>bu,fromRotationTranslation:()=>Zc,fromRotationTranslationScale:()=>Eu,fromRotationTranslationScaleOrigin:()=>Iu,fromScaling:()=>xu,fromTranslation:()=>gu,fromValues:()=>ou,fromXRotation:()=>vu,fromYRotation:()=>Su,fromZRotation:()=>_u,frustum:()=>Cu,getRotation:()=>wu,getScaling:()=>el,getTranslation:()=>Au,identity:()=>Qc,invert:()=>cu,lookAt:()=>Ou,mul:()=>Xu,multiply:()=>Jc,multiplyScalar:()=>Hu,multiplyScalarAndAdd:()=>Vu,ortho:()=>Fu,orthoNO:()=>rl,orthoZO:()=>Bu,perspective:()=>Ru,perspectiveFromFieldOfView:()=>Pu,perspectiveNO:()=>tl,perspectiveZO:()=>zu,rotate:()=>mu,rotateX:()=>hu,rotateY:()=>pu,rotateZ:()=>yu,scale:()=>fu,set:()=>su,str:()=>Nu,sub:()=>Ku,subtract:()=>nl,targetTo:()=>Du,translate:()=>uu,transpose:()=>au});function ru(){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 nu(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 iu(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 ou(t,e,r,n,i,o,s,a,c,l,d,u,f,m,h,y){var p=new Ue(16);return p[0]=t,p[1]=e,p[2]=r,p[3]=n,p[4]=i,p[5]=o,p[6]=s,p[7]=a,p[8]=c,p[9]=l,p[10]=d,p[11]=u,p[12]=f,p[13]=m,p[14]=h,p[15]=y,p}function su(t,e,r,n,i,o,s,a,c,l,d,u,f,m,h,y,p){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]=h,t[14]=y,t[15]=p,t}function Qc(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 au(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 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],h=e[12],y=e[13],p=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,M=n*l-o*a,A=i*l-o*c,w=d*y-u*h,E=d*p-f*h,L=d*g-m*h,B=u*p-f*y,D=u*g-m*y,U=f*g-m*p,C=S*U-x*D+v*B+b*L-M*E+A*w;return C?(C=1/C,t[0]=(a*U-c*D+l*B)*C,t[1]=(i*D-n*U-o*B)*C,t[2]=(y*A-p*M+g*b)*C,t[3]=(f*M-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]=(p*v-h*A-g*x)*C,t[7]=(d*A-f*v+m*x)*C,t[8]=(s*D-a*L+l*w)*C,t[9]=(n*L-r*D-o*w)*C,t[10]=(h*M-y*v+g*S)*C,t[11]=(u*v-d*M-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-h*b-p*S)*C,t[15]=(d*b-u*x+f*S)*C,t):null}function lu(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],h=e[12],y=e[13],p=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,M=n*l-o*a,A=i*l-o*c,w=d*y-u*h,E=d*p-f*h,L=d*g-m*h,B=u*p-f*y,D=u*g-m*y,U=f*g-m*p;return t[0]=a*U-c*D+l*B,t[1]=i*D-n*U-o*B,t[2]=y*A-p*M+g*b,t[3]=f*M-u*A-m*b,t[4]=c*L-s*U-l*E,t[5]=r*U-i*L+o*E,t[6]=p*v-h*A-g*x,t[7]=d*A-f*v+m*x,t[8]=s*D-a*L+l*w,t[9]=n*L-r*D-o*w,t[10]=h*M-y*v+g*S,t[11]=u*v-d*M-m*S,t[12]=a*E-s*B-c*w,t[13]=r*B-n*E+i*w,t[14]=y*x-h*b-p*S,t[15]=d*b-u*x+f*S,t}function du(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],h=t[13],y=t[14],p=t[15],g=e*s-r*o,S=e*a-n*o,x=r*a-n*s,v=l*h-d*m,b=l*y-u*m,M=d*y-u*h,A=e*M-r*b+n*v,w=o*M-s*b+a*v,E=l*x-d*S+u*g,L=m*x-h*S+y*g;return c*A-i*w+p*E-f*L}function Jc(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],h=e[11],y=e[12],p=e[13],g=e[14],S=e[15],x=r[0],v=r[1],b=r[2],M=r[3];return t[0]=x*n+v*a+b*u+M*y,t[1]=x*i+v*c+b*f+M*p,t[2]=x*o+v*l+b*m+M*g,t[3]=x*s+v*d+b*h+M*S,x=r[4],v=r[5],b=r[6],M=r[7],t[4]=x*n+v*a+b*u+M*y,t[5]=x*i+v*c+b*f+M*p,t[6]=x*o+v*l+b*m+M*g,t[7]=x*s+v*d+b*h+M*S,x=r[8],v=r[9],b=r[10],M=r[11],t[8]=x*n+v*a+b*u+M*y,t[9]=x*i+v*c+b*f+M*p,t[10]=x*o+v*l+b*m+M*g,t[11]=x*s+v*d+b*h+M*S,x=r[12],v=r[13],b=r[14],M=r[15],t[12]=x*n+v*a+b*u+M*y,t[13]=x*i+v*c+b*f+M*p,t[14]=x*o+v*l+b*m+M*g,t[15]=x*s+v*d+b*h+M*S,t}function uu(t,e,r){var n=r[0],i=r[1],o=r[2],s,a,c,l,d,u,f,m,h,y,p,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],h=e[8],y=e[9],p=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]=h,t[9]=y,t[10]=p,t[11]=g,t[12]=s*n+d*i+h*o+e[12],t[13]=a*n+u*i+y*o+e[13],t[14]=c*n+f*i+p*o+e[14],t[15]=l*n+m*i+g*o+e[15]),t}function fu(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 mu(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,h,y,p,g,S,x,v,b,M,A,w,E,L,B,D,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],h=e[3],y=e[4],p=e[5],g=e[6],S=e[7],x=e[8],v=e[9],b=e[10],M=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,D=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+p*w+v*E,t[2]=m*A+g*w+b*E,t[3]=h*A+S*w+M*E,t[4]=u*L+y*B+x*D,t[5]=f*L+p*B+v*D,t[6]=m*L+g*B+b*D,t[7]=h*L+S*B+M*D,t[8]=u*U+y*C+x*J,t[9]=f*U+p*C+v*J,t[10]=m*U+g*C+b*J,t[11]=h*U+S*C+M*J,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}function hu(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 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[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 yu(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 gu(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 xu(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 bu(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 vu(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 Su(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 _u(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 Zc(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,h=i*l,y=o*l,p=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]=h+p,t[7]=0,t[8]=f+g,t[9]=h-p,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),Zc(t,e,r),t}function Au(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}function el(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 wu(t,e){var r=new Ue(3);el(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,h=e[10]*o,y=s+d+h,p=0;return y>0?(p=Math.sqrt(y+1)*2,t[3]=.25*p,t[0]=(u-m)/p,t[1]=(f-c)/p,t[2]=(a-l)/p):s>d&&s>h?(p=Math.sqrt(1+s-d-h)*2,t[3]=(u-m)/p,t[0]=.25*p,t[1]=(a+l)/p,t[2]=(f+c)/p):d>h?(p=Math.sqrt(1+d-s-h)*2,t[3]=(f-c)/p,t[0]=(a+l)/p,t[1]=.25*p,t[2]=(u+m)/p):(p=Math.sqrt(1+h-s-d)*2,t[3]=(a-l)/p,t[0]=(f+c)/p,t[1]=(u+m)/p,t[2]=.25*p),t}function Lu(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],h=1/r[1],y=1/r[2],p=i*m,g=o*h,S=s*y,x=a*m,v=c*h,b=l*y,M=d*m,A=u*h,w=f*y,E=p+v+w,L=0;return E>0?(L=Math.sqrt(E+1)*2,t[3]=.25*L,t[0]=(b-A)/L,t[1]=(M-S)/L,t[2]=(g-x)/L):p>v&&p>w?(L=Math.sqrt(1+p-v-w)*2,t[3]=(b-A)/L,t[0]=.25*L,t[1]=(g+x)/L,t[2]=(M+S)/L):v>w?(L=Math.sqrt(1+v-p-w)*2,t[3]=(M-S)/L,t[0]=(g+x)/L,t[1]=.25*L,t[2]=(b+A)/L):(L=Math.sqrt(1+w-p-v)*2,t[3]=(g-x)/L,t[0]=(M+S)/L,t[1]=(b+A)/L,t[2]=.25*L),t}function Eu(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,h=o*l,y=o*d,p=s*d,g=a*c,S=a*l,x=a*d,v=n[0],b=n[1],M=n[2];return t[0]=(1-(h+p))*v,t[1]=(f+x)*v,t[2]=(m-S)*v,t[3]=0,t[4]=(f-x)*b,t[5]=(1-(u+p))*b,t[6]=(y+g)*b,t[7]=0,t[8]=(m+S)*M,t[9]=(y-g)*M,t[10]=(1-(u+h))*M,t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function Iu(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,h=o*u,y=s*d,p=s*u,g=a*u,S=c*l,x=c*d,v=c*u,b=n[0],M=n[1],A=n[2],w=i[0],E=i[1],L=i[2],B=(1-(y+g))*b,D=(m+v)*b,U=(h-x)*b,C=(m-v)*M,J=(1-(f+g))*M,_e=(p+S)*M,Bt=(h+x)*A,oi=(p-S)*A,Vr=(1-(f+y))*A;return t[0]=B,t[1]=D,t[2]=U,t[3]=0,t[4]=C,t[5]=J,t[6]=_e,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-(D*w+J*E+oi*L),t[14]=r[2]+L-(U*w+_e*E+Vr*L),t[15]=1,t}function Tu(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,h=i*c,y=o*s,p=o*a,g=o*c;return t[0]=1-u-h,t[1]=d+g,t[2]=f-p,t[3]=0,t[4]=d-g,t[5]=1-l-h,t[6]=m+y,t[7]=0,t[8]=f+p,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 Cu(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 tl(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 Ru=tl;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 Pu(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 rl(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 Fu=rl;function Bu(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 Ou(t,e,r,n){var i,o,s,a,c,l,d,u,f,m,h=e[0],y=e[1],p=e[2],g=n[0],S=n[1],x=n[2],v=r[0],b=r[1],M=r[2];return Math.abs(h-v)<j&&Math.abs(y-b)<j&&Math.abs(p-M)<j?Qc(t):(d=h-v,u=y-b,f=p-M,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*h+o*y+s*p),t[13]=-(a*h+c*y+l*p),t[14]=-(d*h+u*y+f*p),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 h=c*f-l*u,y=l*d-a*f,p=a*u-c*d;return m=h*h+y*y+p*p,m>0&&(m=1/Math.sqrt(m),h*=m,y*=m,p*=m),t[0]=h,t[1]=y,t[2]=p,t[3]=0,t[4]=u*p-f*y,t[5]=f*h-d*p,t[6]=d*y-u*h,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 Nu(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 ku(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 Uu(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 nl(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 Hu(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 Vu(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 Gu(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 Wu(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],h=t[12],y=t[13],p=t[14],g=t[15],S=e[0],x=e[1],v=e[2],b=e[3],M=e[4],A=e[5],w=e[6],E=e[7],L=e[8],B=e[9],D=e[10],U=e[11],C=e[12],J=e[13],_e=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-M)<=j*Math.max(1,Math.abs(s),Math.abs(M))&&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-D)<=j*Math.max(1,Math.abs(f),Math.abs(D))&&Math.abs(m-U)<=j*Math.max(1,Math.abs(m),Math.abs(U))&&Math.abs(h-C)<=j*Math.max(1,Math.abs(h),Math.abs(C))&&Math.abs(y-J)<=j*Math.max(1,Math.abs(y),Math.abs(J))&&Math.abs(p-_e)<=j*Math.max(1,Math.abs(p),Math.abs(_e))&&Math.abs(g-Bt)<=j*Math.max(1,Math.abs(g),Math.abs(Bt))}var Xu=Jc,Ku=nl;var se={};qo(se,{add:()=>Qu,angle:()=>Sf,bezier:()=>mf,ceil:()=>Ju,clone:()=>Yu,copy:()=>$u,create:()=>il,cross:()=>lf,dist:()=>Tf,distance:()=>ll,div:()=>If,divide:()=>cl,dot:()=>ea,equals:()=>wf,exactEquals:()=>Af,floor:()=>Zu,forEach:()=>Pf,fromValues:()=>qu,hermite:()=>ff,inverse:()=>af,len:()=>Rf,length:()=>ol,lerp:()=>df,max:()=>tf,min:()=>ef,mul:()=>Ef,multiply:()=>al,negate:()=>sf,normalize:()=>cf,random:()=>hf,rotateX:()=>xf,rotateY:()=>bf,rotateZ:()=>vf,round:()=>rf,scale:()=>nf,scaleAndAdd:()=>of,set:()=>ju,slerp:()=>uf,sqrDist:()=>Cf,sqrLen:()=>zf,squaredDistance:()=>dl,squaredLength:()=>ul,str:()=>Mf,sub:()=>Lf,subtract:()=>sl,transformMat3:()=>yf,transformMat4:()=>pf,transformQuat:()=>gf,zero:()=>_f});function il(){var t=new Ue(3);return Ue!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function Yu(t){var e=new Ue(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function ol(t){var e=t[0],r=t[1],n=t[2];return Math.sqrt(e*e+r*r+n*n)}function qu(t,e,r){var n=new Ue(3);return n[0]=t,n[1]=e,n[2]=r,n}function $u(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function ju(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t}function Qu(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 cl(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 Zu(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t[2]=Math.floor(e[2]),t}function ef(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 tf(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 rf(t,e){return t[0]=Ao(e[0]),t[1]=Ao(e[1]),t[2]=Ao(e[2]),t}function nf(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t}function of(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 ll(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 dl(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 ul(t){var e=t[0],r=t[1],n=t[2];return e*e+r*r+n*n}function sf(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t}function af(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t}function cf(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 lf(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 df(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 uf(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 ff(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 mf(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 hf(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 pf(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 yf(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 gf(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 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],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 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[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 vf(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 Sf(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 _f(t){return t[0]=0,t[1]=0,t[2]=0,t}function Mf(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"}function Af(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]}function wf(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 Lf=sl,Ef=al,If=cl,Tf=ll,Cf=dl,Rf=ol,zf=ul,Pf=(function(){var t=il();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 Ff=[.2,.2,.2],Bf={x:0,y:0,z:1},Of=[.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??Ff,i=r?.directional??{direction:Bf,color:Of},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,h=u.y-f.origin.y,y=u.z-f.origin.z,p=m*m+h*h+y*y,g=f.radius*f.radius;if(p<g&&g>0){let S=1-Math.sqrt(p)/f.radius,x=Math.sqrt(p),v=x>0?Ur(-(m*o.x+h*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),h=c*12;s[h]=u.x,s[h+1]=u.y,s[h+2]=u.z,s[h+3]=f.x,s[h+4]=f.y,s[h+5]=f.z,s[h+6]=a.texCoord[0],s[h+7]=a.texCoord[1],s[h+8]=m[0],s[h+9]=m[1],s[h+10]=m[2],s[h+11]=1}),s}function fl(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}),h=[u,f,m];return{origin:a,axis:h,matrix:Sa(a,h)}}var ia=`#version 300 es
|
|
366
|
+
}`;function iu(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 $c(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 ou(t,e,r){return[t/r.skinWidth,1-e/r.skinHeight]}function Js(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:ou(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 Qs(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=$c(u.position,f.position,o),h=iu($c(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]=h.x,c[y+4]=h.y,c[y+5]=h.z,c[y+6]=l.texCoord[0],c[y+7]=l.texCoord[1]}),c}var _o=class{constructor(e,r,n){this.gl=e,this.geometry=Js(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=Qs(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()}},Ao=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<Pt;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 h=Math.min(c.length,Pt);this.gl.uniform1i(this.uniformNumDlights,h);for(let y=0;y<h;y++){let p=c[y];this.gl.uniform3f(this.uniformDlights[y].pos,p.origin.x,p.origin.y,p.origin.z),this.gl.uniform3f(this.uniformDlights[y].color,p.color.x,p.color.y,p.color.z),this.gl.uniform1f(this.uniformDlights[y].intensity,p.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 Mo(t){return t>=0?Math.round(t):t%.5===0?Math.floor(t):Math.round(t)}var mg=Math.PI/180,hg=180/Math.PI;var ae={};qo(ae,{add:()=>Wu,adjoint:()=>mu,clone:()=>au,copy:()=>cu,create:()=>su,decompose:()=>Cu,determinant:()=>hu,equals:()=>qu,exactEquals:()=>Yu,frob:()=>Gu,fromQuat:()=>Fu,fromQuat2:()=>Eu,fromRotation:()=>Au,fromRotationTranslation:()=>Zc,fromRotationTranslationScale:()=>Ru,fromRotationTranslationScaleOrigin:()=>zu,fromScaling:()=>_u,fromTranslation:()=>Su,fromValues:()=>lu,fromXRotation:()=>Mu,fromYRotation:()=>wu,fromZRotation:()=>Lu,frustum:()=>Pu,getRotation:()=>Iu,getScaling:()=>el,getTranslation:()=>Tu,identity:()=>Jc,invert:()=>fu,lookAt:()=>Uu,mul:()=>$u,multiply:()=>Qc,multiplyScalar:()=>Xu,multiplyScalarAndAdd:()=>Ku,ortho:()=>Nu,orthoNO:()=>rl,orthoZO:()=>ku,perspective:()=>Bu,perspectiveFromFieldOfView:()=>Du,perspectiveNO:()=>tl,perspectiveZO:()=>Ou,rotate:()=>gu,rotateX:()=>xu,rotateY:()=>bu,rotateZ:()=>vu,scale:()=>yu,set:()=>du,str:()=>Vu,sub:()=>ju,subtract:()=>nl,targetTo:()=>Hu,translate:()=>pu,transpose:()=>uu});function su(){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 au(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 cu(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 lu(t,e,r,n,i,o,s,a,c,l,d,u,f,m,h,y){var p=new Ue(16);return p[0]=t,p[1]=e,p[2]=r,p[3]=n,p[4]=i,p[5]=o,p[6]=s,p[7]=a,p[8]=c,p[9]=l,p[10]=d,p[11]=u,p[12]=f,p[13]=m,p[14]=h,p[15]=y,p}function du(t,e,r,n,i,o,s,a,c,l,d,u,f,m,h,y,p){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]=h,t[14]=y,t[15]=p,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 uu(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 fu(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],h=e[12],y=e[13],p=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,A=n*l-o*a,M=i*l-o*c,w=d*y-u*h,E=d*p-f*h,L=d*g-m*h,B=u*p-f*y,D=u*g-m*y,U=f*g-m*p,C=S*U-x*D+v*B+b*L-A*E+M*w;return C?(C=1/C,t[0]=(a*U-c*D+l*B)*C,t[1]=(i*D-n*U-o*B)*C,t[2]=(y*M-p*A+g*b)*C,t[3]=(f*A-u*M-m*b)*C,t[4]=(c*L-s*U-l*E)*C,t[5]=(r*U-i*L+o*E)*C,t[6]=(p*v-h*M-g*x)*C,t[7]=(d*M-f*v+m*x)*C,t[8]=(s*D-a*L+l*w)*C,t[9]=(n*L-r*D-o*w)*C,t[10]=(h*A-y*v+g*S)*C,t[11]=(u*v-d*A-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-h*b-p*S)*C,t[15]=(d*b-u*x+f*S)*C,t):null}function mu(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],h=e[12],y=e[13],p=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,A=n*l-o*a,M=i*l-o*c,w=d*y-u*h,E=d*p-f*h,L=d*g-m*h,B=u*p-f*y,D=u*g-m*y,U=f*g-m*p;return t[0]=a*U-c*D+l*B,t[1]=i*D-n*U-o*B,t[2]=y*M-p*A+g*b,t[3]=f*A-u*M-m*b,t[4]=c*L-s*U-l*E,t[5]=r*U-i*L+o*E,t[6]=p*v-h*M-g*x,t[7]=d*M-f*v+m*x,t[8]=s*D-a*L+l*w,t[9]=n*L-r*D-o*w,t[10]=h*A-y*v+g*S,t[11]=u*v-d*A-m*S,t[12]=a*E-s*B-c*w,t[13]=r*B-n*E+i*w,t[14]=y*x-h*b-p*S,t[15]=d*b-u*x+f*S,t}function hu(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],h=t[13],y=t[14],p=t[15],g=e*s-r*o,S=e*a-n*o,x=r*a-n*s,v=l*h-d*m,b=l*y-u*m,A=d*y-u*h,M=e*A-r*b+n*v,w=o*A-s*b+a*v,E=l*x-d*S+u*g,L=m*x-h*S+y*g;return c*M-i*w+p*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],h=e[11],y=e[12],p=e[13],g=e[14],S=e[15],x=r[0],v=r[1],b=r[2],A=r[3];return t[0]=x*n+v*a+b*u+A*y,t[1]=x*i+v*c+b*f+A*p,t[2]=x*o+v*l+b*m+A*g,t[3]=x*s+v*d+b*h+A*S,x=r[4],v=r[5],b=r[6],A=r[7],t[4]=x*n+v*a+b*u+A*y,t[5]=x*i+v*c+b*f+A*p,t[6]=x*o+v*l+b*m+A*g,t[7]=x*s+v*d+b*h+A*S,x=r[8],v=r[9],b=r[10],A=r[11],t[8]=x*n+v*a+b*u+A*y,t[9]=x*i+v*c+b*f+A*p,t[10]=x*o+v*l+b*m+A*g,t[11]=x*s+v*d+b*h+A*S,x=r[12],v=r[13],b=r[14],A=r[15],t[12]=x*n+v*a+b*u+A*y,t[13]=x*i+v*c+b*f+A*p,t[14]=x*o+v*l+b*m+A*g,t[15]=x*s+v*d+b*h+A*S,t}function pu(t,e,r){var n=r[0],i=r[1],o=r[2],s,a,c,l,d,u,f,m,h,y,p,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],h=e[8],y=e[9],p=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]=h,t[9]=y,t[10]=p,t[11]=g,t[12]=s*n+d*i+h*o+e[12],t[13]=a*n+u*i+y*o+e[13],t[14]=c*n+f*i+p*o+e[14],t[15]=l*n+m*i+g*o+e[15]),t}function yu(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 gu(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,h,y,p,g,S,x,v,b,A,M,w,E,L,B,D,U,C,Q;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],h=e[3],y=e[4],p=e[5],g=e[6],S=e[7],x=e[8],v=e[9],b=e[10],A=e[11],M=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,D=s*o*d+i*c,U=i*s*d+o*c,C=o*s*d-i*c,Q=s*s*d+l,t[0]=u*M+y*w+x*E,t[1]=f*M+p*w+v*E,t[2]=m*M+g*w+b*E,t[3]=h*M+S*w+A*E,t[4]=u*L+y*B+x*D,t[5]=f*L+p*B+v*D,t[6]=m*L+g*B+b*D,t[7]=h*L+S*B+A*D,t[8]=u*U+y*C+x*Q,t[9]=f*U+p*C+v*Q,t[10]=m*U+g*C+b*Q,t[11]=h*U+S*C+A*Q,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}function xu(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 bu(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 vu(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 Su(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 _u(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 Au(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 Mu(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 wu(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 Lu(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 Zc(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,h=i*l,y=o*l,p=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]=h+p,t[7]=0,t[8]=f+g,t[9]=h-p,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 Eu(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),Zc(t,e,r),t}function Tu(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}function el(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 Iu(t,e){var r=new Ue(3);el(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,h=e[10]*o,y=s+d+h,p=0;return y>0?(p=Math.sqrt(y+1)*2,t[3]=.25*p,t[0]=(u-m)/p,t[1]=(f-c)/p,t[2]=(a-l)/p):s>d&&s>h?(p=Math.sqrt(1+s-d-h)*2,t[3]=(u-m)/p,t[0]=.25*p,t[1]=(a+l)/p,t[2]=(f+c)/p):d>h?(p=Math.sqrt(1+d-s-h)*2,t[3]=(f-c)/p,t[0]=(a+l)/p,t[1]=.25*p,t[2]=(u+m)/p):(p=Math.sqrt(1+h-s-d)*2,t[3]=(a-l)/p,t[0]=(f+c)/p,t[1]=(u+m)/p,t[2]=.25*p),t}function Cu(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],h=1/r[1],y=1/r[2],p=i*m,g=o*h,S=s*y,x=a*m,v=c*h,b=l*y,A=d*m,M=u*h,w=f*y,E=p+v+w,L=0;return E>0?(L=Math.sqrt(E+1)*2,t[3]=.25*L,t[0]=(b-M)/L,t[1]=(A-S)/L,t[2]=(g-x)/L):p>v&&p>w?(L=Math.sqrt(1+p-v-w)*2,t[3]=(b-M)/L,t[0]=.25*L,t[1]=(g+x)/L,t[2]=(A+S)/L):v>w?(L=Math.sqrt(1+v-p-w)*2,t[3]=(A-S)/L,t[0]=(g+x)/L,t[1]=.25*L,t[2]=(b+M)/L):(L=Math.sqrt(1+w-p-v)*2,t[3]=(g-x)/L,t[0]=(A+S)/L,t[1]=(b+M)/L,t[2]=.25*L),t}function Ru(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,h=o*l,y=o*d,p=s*d,g=a*c,S=a*l,x=a*d,v=n[0],b=n[1],A=n[2];return t[0]=(1-(h+p))*v,t[1]=(f+x)*v,t[2]=(m-S)*v,t[3]=0,t[4]=(f-x)*b,t[5]=(1-(u+p))*b,t[6]=(y+g)*b,t[7]=0,t[8]=(m+S)*A,t[9]=(y-g)*A,t[10]=(1-(u+h))*A,t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function zu(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,h=o*u,y=s*d,p=s*u,g=a*u,S=c*l,x=c*d,v=c*u,b=n[0],A=n[1],M=n[2],w=i[0],E=i[1],L=i[2],B=(1-(y+g))*b,D=(m+v)*b,U=(h-x)*b,C=(m-v)*A,Q=(1-(f+g))*A,_e=(p+S)*A,Bt=(h+x)*M,oi=(p-S)*M,Vr=(1-(f+y))*M;return t[0]=B,t[1]=D,t[2]=U,t[3]=0,t[4]=C,t[5]=Q,t[6]=_e,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-(D*w+Q*E+oi*L),t[14]=r[2]+L-(U*w+_e*E+Vr*L),t[15]=1,t}function Fu(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,h=i*c,y=o*s,p=o*a,g=o*c;return t[0]=1-u-h,t[1]=d+g,t[2]=f-p,t[3]=0,t[4]=d-g,t[5]=1-l-h,t[6]=m+y,t[7]=0,t[8]=f+p,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 tl(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 Bu=tl;function Ou(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 Du(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 rl(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 Nu=rl;function ku(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 Uu(t,e,r,n){var i,o,s,a,c,l,d,u,f,m,h=e[0],y=e[1],p=e[2],g=n[0],S=n[1],x=n[2],v=r[0],b=r[1],A=r[2];return Math.abs(h-v)<j&&Math.abs(y-b)<j&&Math.abs(p-A)<j?Jc(t):(d=h-v,u=y-b,f=p-A,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*h+o*y+s*p),t[13]=-(a*h+c*y+l*p),t[14]=-(d*h+u*y+f*p),t[15]=1,t)}function Hu(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 h=c*f-l*u,y=l*d-a*f,p=a*u-c*d;return m=h*h+y*y+p*p,m>0&&(m=1/Math.sqrt(m),h*=m,y*=m,p*=m),t[0]=h,t[1]=y,t[2]=p,t[3]=0,t[4]=u*p-f*y,t[5]=f*h-d*p,t[6]=d*y-u*h,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 Vu(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 Gu(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 Wu(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 nl(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 Xu(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 Ku(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 Yu(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 qu(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],h=t[12],y=t[13],p=t[14],g=t[15],S=e[0],x=e[1],v=e[2],b=e[3],A=e[4],M=e[5],w=e[6],E=e[7],L=e[8],B=e[9],D=e[10],U=e[11],C=e[12],Q=e[13],_e=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-A)<=j*Math.max(1,Math.abs(s),Math.abs(A))&&Math.abs(a-M)<=j*Math.max(1,Math.abs(a),Math.abs(M))&&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-D)<=j*Math.max(1,Math.abs(f),Math.abs(D))&&Math.abs(m-U)<=j*Math.max(1,Math.abs(m),Math.abs(U))&&Math.abs(h-C)<=j*Math.max(1,Math.abs(h),Math.abs(C))&&Math.abs(y-Q)<=j*Math.max(1,Math.abs(y),Math.abs(Q))&&Math.abs(p-_e)<=j*Math.max(1,Math.abs(p),Math.abs(_e))&&Math.abs(g-Bt)<=j*Math.max(1,Math.abs(g),Math.abs(Bt))}var $u=Qc,ju=nl;var se={};qo(se,{add:()=>tf,angle:()=>wf,bezier:()=>gf,ceil:()=>rf,clone:()=>Ju,copy:()=>Zu,create:()=>il,cross:()=>mf,dist:()=>Ff,distance:()=>ll,div:()=>zf,divide:()=>cl,dot:()=>ea,equals:()=>If,exactEquals:()=>Tf,floor:()=>nf,forEach:()=>Df,fromValues:()=>Qu,hermite:()=>yf,inverse:()=>uf,len:()=>Bf,length:()=>ol,lerp:()=>hf,max:()=>sf,min:()=>of,mul:()=>Rf,multiply:()=>al,negate:()=>df,normalize:()=>ff,random:()=>xf,rotateX:()=>_f,rotateY:()=>Af,rotateZ:()=>Mf,round:()=>af,scale:()=>cf,scaleAndAdd:()=>lf,set:()=>ef,slerp:()=>pf,sqrDist:()=>Pf,sqrLen:()=>Of,squaredDistance:()=>dl,squaredLength:()=>ul,str:()=>Ef,sub:()=>Cf,subtract:()=>sl,transformMat3:()=>vf,transformMat4:()=>bf,transformQuat:()=>Sf,zero:()=>Lf});function il(){var t=new Ue(3);return Ue!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function Ju(t){var e=new Ue(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function ol(t){var e=t[0],r=t[1],n=t[2];return Math.sqrt(e*e+r*r+n*n)}function Qu(t,e,r){var n=new Ue(3);return n[0]=t,n[1]=e,n[2]=r,n}function Zu(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function ef(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t}function tf(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 cl(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t}function rf(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t[2]=Math.ceil(e[2]),t}function nf(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t[2]=Math.floor(e[2]),t}function of(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 sf(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 af(t,e){return t[0]=Mo(e[0]),t[1]=Mo(e[1]),t[2]=Mo(e[2]),t}function cf(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t}function lf(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 ll(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 dl(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 ul(t){var e=t[0],r=t[1],n=t[2];return e*e+r*r+n*n}function df(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t}function uf(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t}function ff(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 mf(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 hf(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 pf(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 yf(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 gf(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 xf(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 bf(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 vf(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 Sf(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 _f(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 Af(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 Mf(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 wf(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 Lf(t){return t[0]=0,t[1]=0,t[2]=0,t}function Ef(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"}function Tf(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]}function If(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 Cf=sl,Rf=al,zf=cl,Ff=ll,Pf=dl,Bf=ol,Of=ul,Df=(function(){var t=il();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 Nf=[.2,.2,.2],kf={x:0,y:0,z:1},Uf=[.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 Hf(t,e,r){let n=r?.ambient??Nf,i=r?.directional??{direction:kf,color:Uf},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,h=u.y-f.origin.y,y=u.z-f.origin.z,p=m*m+h*h+y*y,g=f.radius*f.radius;if(p<g&&g>0){let S=1-Math.sqrt(p)/f.radius,x=Math.sqrt(p),v=x>0?Ur(-(m*o.x+h*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=Hf(f,u,n),h=c*12;s[h]=u.x,s[h+1]=u.y,s[h+2]=u.z,s[h+3]=f.x,s[h+4]=f.y,s[h+5]=f.z,s[h+6]=a.texCoord[0],s[h+7]=a.texCoord[1],s[h+8]=m[0],s[h+9]=m[1],s[h+10]=m[2],s[h+11]=1}),s}function fl(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}),h=[u,f,m];return{origin:a,axis:h,matrix:Sa(a,h)}}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
|
-
}`,
|
|
421
|
+
}`,Jn=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 Jn(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 Vf=[1,1,1,1],To=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??Vf,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,h=this.blendMode[d]===1?1.2:1,y=this.colorR[d]*h,p=this.colorG[d]*h,g=this.colorB[d]*h,S=this.colorA[d]*m,x=this.positionX[d],v=this.positionY[d],b=this.positionZ[d],A=e.x*f,M=e.y*f,w=e.z*f,E=r.x*f,L=r.y*f,B=r.z*f,D=[{x:x-A-E,y:v-M-L,z:b-w-B},{x:x+A-E,y:v+M-L,z:b+w-B},{x:x-A+E,y:v-M+L,z:b-w+B},{x:x+A+E,y:v+M+L,z:b+w+B}],U=[[0,1],[1,1],[0,0],[1,0]];D.forEach((C,Q)=>{n.push(C.x,C.y,C.z,U[Q]?.[0]??0,U[Q]?.[1]??0,y,p,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
|
-
}`,To=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 ml(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 hl(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 pl(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 yl(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 gl(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 xl(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 Ro=1,zo=2,Po=4,Fo=8,Bo=16,Oo=32,ca=64,kf=128,Uf=256,Do=512,No=1024,ko=2048,Jn=4096,Zn=16384,Hf=32768,ei=65536,Uo=1<<17,ti=1<<18,ri=1<<19,Ho=1<<20,Vo=1<<21,Go=1<<22,Vf=1<<23,Wo=1<<24,ni=1<<25,Xo=1<<26,Ko=1<<27;var Gf=1,Wf=2,Xf=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=Gf;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===Xf){let c=this.stream.readByte();for(let l=0;l<c;l++)this.stream.readByte()}this.isDemo===Wf&&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&kf&&(e|=this.stream.readByte()<<8),e&Hf&&(e|=this.stream.readByte()<<16),e&Vf&&(e|=this.stream.readByte()<<24);let r;return e&Uf?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&Ro&&(r.origin.x=this.stream.readCoord()),i&zo&&(r.origin.y=this.stream.readCoord()),i&Do&&(r.origin.z=this.stream.readCoord()),i&No&&(r.angles.x=this.stream.readAngle()),i&Po&&(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&Oo?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 Kf(t){return{init(){t.trace({x:0,y:0,z:0},{x:0,y:0,z:0})},shutdown(){},createMainLoop(e,r){return new Ot(e,r)}}}return Il(Yf);})();
|
|
449
|
+
}`,Io=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 ml(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 hl(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 pl(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 yl(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 gl(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 xl(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 Ro=1,zo=2,Fo=4,Po=8,Bo=16,Oo=32,ca=64,Gf=128,Wf=256,Do=512,No=1024,ko=2048,Qn=4096,Zn=16384,Xf=32768,ei=65536,Uo=1<<17,ti=1<<18,ri=1<<19,Ho=1<<20,Vo=1<<21,Go=1<<22,Kf=1<<23,Wo=1<<24,ni=1<<25,Xo=1<<26,Ko=1<<27;var Yf=1,qf=2,$f=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=Yf;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 T.EXPLOSION1:case T.EXPLOSION2:case T.ROCKET_EXPLOSION:case T.GRENADE_EXPLOSION:case T.ROCKET_EXPLOSION_WATER:case T.GRENADE_EXPLOSION_WATER:case T.BFG_EXPLOSION:case T.BFG_BIGEXPLOSION:case T.BOSSTPORT:case T.PLASMA_EXPLOSION:case T.PLAIN_EXPLOSION:case T.CHAINFIST_SMOKE:case T.TRACKER_EXPLOSION:case T.TELEPORT_EFFECT:case T.DBALL_GOAL:case T.NUKEBLAST:case T.WIDOWSPLASH:case T.EXPLOSION1_BIG:case T.EXPLOSION1_NP:this.stream.readPos(r);break;case T.GUNSHOT:case T.BLOOD:case T.BLASTER:case T.SHOTGUN:case T.SPARKS:case T.BULLET_SPARKS:case T.SCREEN_SPARKS:case T.SHIELD_SPARKS:case T.BLASTER2:case T.FLECHETTE:case T.MOREBLOOD:case T.ELECTRIC_SPARKS:case T.HEATBEAM_SPARKS:case T.HEATBEAM_STEAM:this.stream.readPos(r),this.stream.readDir(i);break;case T.SPLASH:case T.LASER_SPARKS:case T.WELDING_SPARKS:case T.TUNNEL_SPARKS:o=this.stream.readByte(),this.stream.readPos(r),this.stream.readDir(i),s=this.stream.readByte();break;case T.BLUEHYPERBLASTER:this.protocolVersion>=32?(this.stream.readPos(r),this.stream.readPos(n)):(this.stream.readPos(r),this.stream.readDir(i));break;case T.GREENBLOOD:this.protocolVersion>=32?(this.stream.readPos(r),this.stream.readDir(i)):(this.stream.readPos(r),this.stream.readPos(n));break;case T.RAILTRAIL:case T.BUBBLETRAIL:case T.BFG_LASER:case T.DEBUGTRAIL:case T.BUBBLETRAIL2:this.stream.readPos(r),this.stream.readPos(n);break;case T.PARASITE_ATTACK:case T.MEDIC_CABLE_ATTACK:this.stream.readShort(),this.stream.readPos(r),this.stream.readPos(n);break;case T.GRAPPLE_CABLE:a=this.stream.readShort(),this.stream.readPos(r),this.stream.readPos(n),this.stream.readPos(i);break;case T.LIGHTNING:c=this.stream.readShort(),l=this.stream.readShort(),this.stream.readPos(r),this.stream.readPos(n);break;case T.FLASHLIGHT:this.stream.readPos(r),a=this.stream.readShort();break;case T.FORCEWALL:this.stream.readPos(r),this.stream.readPos(n),s=this.stream.readByte();break;case T.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 T.WIDOWBEAMOUT:this.stream.readShort();case T.HEATBEAM:case T.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===$f){let c=this.stream.readByte();for(let l=0;l<c;l++)this.stream.readByte()}this.isDemo===qf&&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&Gf&&(e|=this.stream.readByte()<<8),e&Xf&&(e|=this.stream.readByte()<<16),e&Kf&&(e|=this.stream.readByte()<<24);let r;return e&Wf?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&Qn&&i&ti?r.renderfx=this.stream.readLong():i&Qn?r.renderfx=this.stream.readByte():i&ti&&(r.renderfx=this.stream.readShort()),i&Ro&&(r.origin.x=this.stream.readCoord()),i&zo&&(r.origin.y=this.stream.readCoord()),i&Do&&(r.origin.z=this.stream.readCoord()),i&No&&(r.angles.x=this.stream.readAngle()),i&Fo&&(r.angles.y=this.stream.readAngle()),i&Po&&(r.angles.z=this.stream.readAngle()),i&Wo&&this.stream.readPos(r.old_origin),i&Xo&&(r.sound=this.stream.readByte()),i&Oo?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 jf(t){return{init(){t.trace({x:0,y:0,z:0},{x:0,y:0,z:0})},shutdown(){},createMainLoop(e,r){return new Ot(e,r)}}}return Tl(Jf);})();
|
|
450
450
|
//# sourceMappingURL=index.global.js.map
|