quake2ts 0.0.231 → 0.0.232

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.
@@ -1,4 +1,4 @@
1
- "use strict";var Quake2Engine=(()=>{var Sl=Object.create;var li=Object.defineProperty;var Al=Object.getOwnPropertyDescriptor;var Ml=Object.getOwnPropertyNames;var wl=Object.getPrototypeOf,Ll=Object.prototype.hasOwnProperty;var El=(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))!Ll.call(t,i)&&i!==r&&li(t,i,{get:()=>e[i],enumerable:!(n=Al(e,i))||n.enumerable});return t};var Tl=(t,e,r)=>(r=t!=null?Sl(wl(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=El((Mm,Qa)=>{"use strict";Qa.exports=Worker});var Qf={};qo(Qf,{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:()=>hr,Md2MeshBuffers:()=>So,Md2ParseError:()=>le,Md2Pipeline:()=>Ao,Md3Loader:()=>mr,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:()=>mt,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:()=>_o,SoundChannel:()=>oo,SoundPrecache:()=>fo,SoundRegistry:()=>uo,SpriteLoader:()=>pr,SpriteParseError:()=>yt,Texture2D:()=>Or,TextureCache:()=>yr,TextureCubeMap:()=>Dr,TgaParseError:()=>et,U_ALPHA:()=>bl,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:()=>_e,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:()=>ho,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:()=>_i,parseWalTexture:()=>Mi,parseWav:()=>wi,pcxToRgba:()=>Si,pickChannel:()=>mo,preparePcxTexture:()=>Ai,removeViewTranslation:()=>Yc,resolveLightStyles:()=>Ws,spatializeOrigin:()=>po,spawnBlood:()=>pl,spawnBulletImpact:()=>hl,spawnExplosion:()=>ml,spawnMuzzleFlash:()=>gl,spawnTeleportFlash:()=>yl,spawnTrail:()=>xl,walToRgba:()=>hs,wireDropTarget:()=>Da,wireFileInput:()=>Na});var Cl=()=>typeof performance<"u"?performance.now():Date.now(),Rl=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??Cl,schedule:r.schedule??Rl}}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 zl=Object.defineProperty,ga=(t,e)=>{for(var r in e)zl(t,r,{get:e[r],enumerable:!0})},xa={x:0,y:0,z:0};var rh=Math.PI/180;function ba(t,e){return{x:t.x-e.x,y:t.y-e.y,z:t.z-e.z}}function Fl(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 Jo(t){return Math.sqrt(Pl(t))}function He(t){let e=Jo(t);return e===0?t:Fl(t,1/e)}var Bl=Math.PI/180,nh=180/Math.PI,sr=Bl;var Ol=[[-.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 Dl(){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 _a(t,e){let r=Dl();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,ht=2;var Qo=8,Zo=16,Nl=32;var kl=16384;var di=65536,Sa=1<<17,Ul=1<<18,Hl=1<<19,Vl=1<<20,Gl=1<<21,Wl=1<<22,Xl=1<<23,ih=1<<24,ui=1<<25,Kl=1<<26,oh=1<<27,sh=1<<28,ah=1<<29,fi=1<<30,ch=1<<31;var Kr=0;var Aa=4,Ma=8,wa=16,La=32,Ea=64;var lh=1<<25,dh=1<<28,uh=1<<29,fh=1<<30,hh=1<<31;var mh=Ke|ht,ph=Ke|di|ht|ui|fi,yh=Ke|di|ht,gh=Ke|Sa|ht|ui|fi,xh=Nl|Qo|Zo,bh=Ke|Zo|Qo,Yl=Ke|ui|fi|ht|Kl,vh=Ul|Hl|Vl|Gl|Wl|Xl,_h=Ke|Qo|Zo|ui|fi,Sh=Ke|di|ht,Ah=Ke|ht,Mh=Ke|di|ht|Sa,wh=Yl|kl;var Lh=Number.MAX_SAFE_INTEGER-1;var hi=(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))(hi||{});var mi=256;var es=256,ts=8192,pi=2048,rs=512,ns=256,is=mi*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+mi]="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 ql={};ga(ql,{addReplayFrame:()=>Ql,createReplaySession:()=>Jl,deserializeReplay:()=>jl,serializeReplay:()=>$l});function $l(t){return JSON.stringify(t,null,2)}function jl(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 R=(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[t.splitclient=21]="splitclient",t[t.configblast=22]="configblast",t[t.spawnbaselineblast=23]="spawnbaselineblast",t[t.level_restart=24]="level_restart",t[t.damage=25]="damage",t[t.locprint=26]="locprint",t[t.fog=27]="fog",t[t.waitingforplayers=28]="waitingforplayers",t[t.bot_chat=29]="bot_chat",t[t.poi=30]="poi",t[t.help_path=31]="help_path",t[t.muzzleflash3=32]="muzzleflash3",t[t.achievement=33]="achievement",t))(R||{});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 Zl=12,ed=9,Eh=Math.ceil(Zl*ed/16),td=23,rd=2,Th=Math.ceil(td*rd/16);var nd={};ga(nd,{U_ANGLE1:()=>dd,U_ANGLE2:()=>ud,U_ANGLE3:()=>fd,U_EFFECTS:()=>pd,U_EVENT:()=>xd,U_FRAME:()=>hd,U_MODEL:()=>od,U_MODEL2:()=>vd,U_MODEL3:()=>_d,U_MODEL4:()=>Sd,U_MOREBITS:()=>bd,U_NUMBER:()=>id,U_ORIGIN1:()=>ad,U_ORIGIN2:()=>cd,U_ORIGIN3:()=>ld,U_REMOVE:()=>Ad,U_RENDERFX:()=>yd,U_SKIN:()=>md,U_SOLID:()=>gd,U_SOUND:()=>sd});var id=1,od=2,sd=4,ad=8,cd=16,ld=32,dd=64,ud=128,fd=256,hd=512,md=1024,pd=2048,yd=4096,gd=8192,xd=16384,bd=32768,vd=1,_d=2,Sd=4,Ad=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=Ol[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||{}),Ih=Object.keys(Ra).length/2;var Yr=class{constructor({name:e,defaultValue:r,description:n,flags:i=hi.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&hi.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 Md(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 Md(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,mi,"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 wd="PACK";function Ld(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 Ed(){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 Td=Ed();function Pa(t){let e=4294967295;for(let r=0;r<t.length;r+=1){let n=t[r];e=Td[(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!==wd)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,h=Ld(n,f,56),m=ie(h),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 ${h||"<unnamed>"} (offset=${y}, length=${p})`);if(!m)throw new ze(`Entry ${u} has an empty name`);let g={name:m,offset:y,length:p};d.set(m,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 mt=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 Id(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 mt("blob",new Error("Unsupported Blob type"))}async function Cd(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 Id(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 Cd(l,n.onProgress),u=ur.fromArrayBuffer(l.name,d),f=n.validator?.validateArchive(u);if(f){n.onValidationResult?.(f);let h=f.status==="mismatch",m=f.status==="unknown";if(h&&o||m&&!s){let y=new Dt(f);if(n.onError?.(l.name,y),a)throw new mt(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(h){if(n.onError?.(l.name,h),a)throw new mt(l.name,h)}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 mt(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 Rd(t){return Array.isArray(t)?t:Array.from(t)}function as(t){return Rd(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 zd="IBSP",Fd=38,Ua=19,Pd=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<Pd)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!==zd)throw new q(`Invalid BSP magic ${r}`);let n=e.getInt32(4,!0);if(n!==Fd)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=Od(t,i.get(0)),a=Nd(t,i.get(1)),c=kd(t,i.get(2)),l=Ud(t,i.get(4)),d=Hd(t,i.get(5)),u=Vd(t,i.get(6)),f=new Uint8Array(t,i.get(7).offset,i.get(7).length),h=Jd(u,i.get(7)),m=Gd(t,i.get(8)),y=Wd(t,i.get(11)),p=Xd(t,i.get(12)),g=Kd(t,i.get(13)),_=Yd(t,i.get(14)),x=qd(t,i.get(15)),v=$d(t,i.get(9),i.get(10),m),b=jd(t,i.get(3));return{header:o,entities:s,planes:a,vertices:c,nodes:l,texInfo:d,faces:u,lightMaps:f,lightMapInfo:h,leafs:m,leafLists:v,edges:y,surfEdges:p,models:g,brushes:_,brushSides:x,visibility:b,pickEntity(M){let w=null,E=1/0;for(let L of s.entities){let O=L.properties.model;if(!O||!O.startsWith("*"))continue;let N=parseInt(O.substring(1),10);if(isNaN(N)||N<0||N>=g.length)continue;let H=g[N],C=Bd(M.origin,M.direction,H.mins,H.maxs);C!==null&&C<E&&(E=C,w={entity:L,model:H,distance:C})}return w}}}function Bd(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 Od(t,e){let r=new TextDecoder().decode(new Uint8Array(t,e.offset,e.length)),n=Dd(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 Dd(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 Nd(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 kd(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 Ud(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),h=r.getUint16(a+26,!0);o.push({planeIndex:c,children:l,mins:d,maxs:u,firstFace:f,numFaces:h})}return o}function Hd(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),h=r.getInt32(a+36,!0),m=new Uint8Array(t,e.offset+a+40,32),y=new TextDecoder("utf-8").decode(m).replace(/\0.*$/,""),p=r.getInt32(a+72,!0);o.push({s:c,sOffset:l,t:d,tOffset:u,flags:f,value:h,texture:y,nextTexInfo:p})}return o}function Vd(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),h=[r.getUint8(a+12),r.getUint8(a+13),r.getUint8(a+14),r.getUint8(a+15)],m=r.getInt32(a+16,!0);o.push({planeIndex:c,side:l,firstEdge:d,numEdges:u,texInfo:f,styles:h,lightOffset:m})}return o}function Gd(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)],h=r.getUint16(a+20,!0),m=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:h,numLeafFaces:m,firstLeafBrush:y,numLeafBrushes:p})}return o}function Wd(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 Xd(t,e){let r=e.length/4;if(r%1!==0)throw new q("SurfEdge lump has invalid length");let n=new DataView(t,e.offset,e.length),i=new Int32Array(r);for(let o=0;o<r;o+=1)i[o]=n.getInt32(o*4,!0);return i}function Kd(t,e){let r=new DataView(t,e.offset,e.length),n=48;if(e.length%n!==0)throw new q("Model lump has invalid length");let i=e.length/n,o=[];for(let s=0;s<i;s+=1){let a=s*n,c=[r.getFloat32(a,!0),r.getFloat32(a+4,!0),r.getFloat32(a+8,!0)],l=[r.getFloat32(a+12,!0),r.getFloat32(a+16,!0),r.getFloat32(a+20,!0)],d=[r.getFloat32(a+24,!0),r.getFloat32(a+28,!0),r.getFloat32(a+32,!0)],u=r.getInt32(a+36,!0),f=r.getInt32(a+40,!0),h=r.getInt32(a+44,!0);o.push({mins:c,maxs:l,origin:d,headNode:u,firstFace:f,numFaces:h})}return o}function Yd(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 qd(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 $d(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 h=0;h<d.numLeafFaces;h+=1)u.push(c.getUint16((d.firstLeafFace+h)*2,!0));let f=[];for(let h=0;h<d.numLeafBrushes;h+=1)f.push(l.getUint16((d.firstLeafBrush+h)*2,!0));i.push(u),o.push(f)}return{leafFaces:i,leafBrushes:o}}function jd(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 Qd=844121161,Zd=8,Ha=68,e0=[{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{},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=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 t0(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!==Qd)throw new le(`Invalid MD2 ident: ${r}`);if(n!==Zd)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 r0(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 n0(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 i0(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 o0(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,h=1/0,m=-1/0,y=-1/0,p=-1/0;for(let g=0;g<e.numVertices;g+=1){let _=40+g*4,x=s.getUint8(_)*a.x+c.x,v=s.getUint8(_+1)*a.y+c.y,b=s.getUint8(_+2)*a.z+c.z;x<u&&(u=x),v<f&&(f=v),b<h&&(h=b),x>m&&(m=x),v>y&&(y=v),b>p&&(p=b);let A={x,y:v,z:b},M=s.getUint8(_+3),w=e0[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:h},maxBounds:{x:m,y,z:p}})}return n}function s0(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),h=n.getInt32(o+8,!0);if(o+=12,h<0||h>=e.numVertices)throw new le("GL command references invalid vertex index");c.push({s:u,t:f,vertexIndex:h})}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=t0(t),r=r0(t,e),n=n0(t,e),i=i0(t,e),o=o0(t,e),s=s0(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,a0=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 c0(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 l0(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!==a0)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 d0(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 u0(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 f0(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),h=t.getInt32(e+104,!0);if(o<=0||a<=0||c<=0)throw new Fe(`Invalid surface counts for ${n}`);let m=h;vi(`Surface ${n}`,e,m,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=[],_=e+d;for(let M=0;M<s;M+=1){let w=_+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,O=t.getInt16(L,!0)/64,N=t.getInt16(L+2,!0)/64,H=t.getInt16(L+4,!0)/64,C=t.getUint16(L+6,!0);w.push({position:{x:O,y:N,z:H},latLng:C,normal:c0(C)})}b.push(w)}return{surface:{name:n,flags:i,numFrames:o,shaders:g,triangles:y,texCoords:x,vertices:b},nextOffset:e+h}}function ds(t){if(t.byteLength<108)throw new Fe("MD3 buffer too small for header");let e=new DataView(t),r=l0(e);vi("MD3 end",r.ofsEnd,0,t.byteLength);let n=d0(e,r),i=u0(e,r),o=[],s=r.ofsSurfaces;for(let a=0;a<r.numSurfaces;a+=1){let{surface:c,nextOffset:l}=f0(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 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=ds(r.slice().buffer);return this.cache.set(e,n),n}get(e){return this.cache.get(e)}};var h0=844317769,m0=2,Xa=64,Ka=12,yt=class extends Error{};function p0(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!==h0)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),h=p0(e,a+16,Xa);o.push({width:l,height:d,originX:u,originY:f,name:h}),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 _i(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=[],h=i,m=o;for(let y=0;y<s.length;y+=1){let p=s[y],g=Math.max(1,h*m|0);if(p<=0||p+g>t.byteLength)throw new Jr(`Invalid WAL mip offset for level ${y}`);let _=new Uint8Array(t,p,g);f.push({level:y,width:h,height:m,data:_}),h=Math.max(1,h>>1),m=Math.max(1,m>>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 h=new Uint8Array(t,f+1,768),m=new Uint8Array(t,128,f-128),y=new Uint8Array(l*d),p=0,g=0;for(let _=0;_<d;_+=1){let x=0;for(;x<u&&p<m.length;){let v=1,b=m[p++];if((b&192)===192){if(v=b&63,p>=m.length)throw new Nt("Unexpected end of PCX RLE data");b=m[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:h}}function Si(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 h=o*s,m=new Uint8Array(h*4),y=(c&32)!==0,p=0,g=new Uint8Array(t),_=x=>{if(d){let v=g[f++];m[x]=v,m[x+1]=v,m[x+2]=v,m[x+3]=255}else{let v=g[f++],b=g[f++],A=g[f++],M=a===32?g[f++]:255;m[x]=A,m[x+1]=b,m[x+2]=v,m[x+3]=M}};if(l){let x=0;for(;x<h;){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>h)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 O=0;O<b;O++){let N=(x+O)*4;m[N]=M,m[N+1]=w,m[N+2]=E,m[N+3]=L}}else for(let M=0;M<b;M++)_((x+M)*4);x+=b}}else for(let x=0;x<h;x++){if(f>=t.byteLength)throw new et("Unexpected end of TGA data");_(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(m.subarray(A,A+x)),m.set(m.subarray(M,M+x),A),m.set(v,M)}}return{width:o,height:s,bitsPerPixel:32,pixels:m}}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 hs(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=Si(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 hs(_i(t),e)}var kt=class extends Error{constructor(e){super(e),this.name="WavParseError"}};function ms(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(ms(e,0,4)!=="RIFF"||ms(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 m=ms(e,r,4),y=e.getUint32(r+4,!0),p=r+8;m==="fmt "?(n=p,o=y):m==="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),h=new Float32Array(f*c);for(let m=0;m<f;m+=1)for(let y=0;y<c;y+=1){let p=m*c+y,g=i+p*u,_=0;if(d===8)_=e.getUint8(g),h[p]=(_-128)/128;else if(d===16)_=e.getInt16(g,!0),h[p]=_/32768;else if(d===24){let x=e.getUint8(g),v=e.getUint8(g+1),b=e.getInt8(g+2);_=x|v<<8|b<<16,h[p]=_/8388608}else throw new kt(`Unsupported bitsPerSample: ${d}`)}return{sampleRate:l,channels:c,bitsPerSample:d,samples:h}}var y0=(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=y0)=>{let r=p=>new Uint8Array(p.length/2).map(((g,_)=>parseInt(p.substring(2*_,2*(_+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",h=0;f&&(h=11,a=n(t.substring(9,h)),a<=1&&(h+=2,u=n(t.substring(11,h))),a===1&&(h+=8,c=(p=>new DataView(r(p).buffer).getInt32(0,!0))(t.substring(13,h))));let m=256-u;for(let p=h;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+m: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 Al=Object.getOwnPropertyDescriptor;var Ml=Object.getOwnPropertyNames;var wl=Object.getPrototypeOf,Ll=Object.prototype.hasOwnProperty;var El=(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))!Ll.call(t,i)&&i!==r&&li(t,i,{get:()=>e[i],enumerable:!(n=Al(e,i))||n.enumerable});return t};var Tl=(t,e,r)=>(r=t!=null?Sl(wl(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=El((wm,Qa)=>{"use strict";Qa.exports=Worker});var Zf={};qo(Zf,{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:()=>hr,Md2MeshBuffers:()=>So,Md2ParseError:()=>le,Md2Pipeline:()=>Ao,Md3Loader:()=>mr,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:()=>mt,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:()=>_o,SoundChannel:()=>oo,SoundPrecache:()=>fo,SoundRegistry:()=>uo,SpriteLoader:()=>pr,SpriteParseError:()=>yt,Texture2D:()=>Or,TextureCache:()=>yr,TextureCubeMap:()=>Dr,TgaParseError:()=>et,U_ALPHA:()=>bl,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:()=>_e,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:()=>Qf,createEngineRuntime:()=>Fa,createFaceLightmap:()=>bi,createInitialChannels:()=>ho,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:()=>_i,parseWalTexture:()=>Mi,parseWav:()=>wi,pcxToRgba:()=>Si,pickChannel:()=>mo,preparePcxTexture:()=>Ai,removeViewTranslation:()=>Yc,resolveLightStyles:()=>Ws,spatializeOrigin:()=>po,spawnBlood:()=>pl,spawnBulletImpact:()=>hl,spawnExplosion:()=>ml,spawnMuzzleFlash:()=>gl,spawnTeleportFlash:()=>yl,spawnTrail:()=>xl,walToRgba:()=>hs,wireDropTarget:()=>Da,wireFileInput:()=>Na});var Cl=()=>typeof performance<"u"?performance.now():Date.now(),Rl=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??Cl,schedule:r.schedule??Rl}}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 zl=Object.defineProperty,ga=(t,e)=>{for(var r in e)zl(t,r,{get:e[r],enumerable:!0})},xa={x:0,y:0,z:0};var nh=Math.PI/180;function ba(t,e){return{x:t.x-e.x,y:t.y-e.y,z:t.z-e.z}}function Fl(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 Jo(t){return Math.sqrt(Pl(t))}function He(t){let e=Jo(t);return e===0?t:Fl(t,1/e)}var Bl=Math.PI/180,ih=180/Math.PI,sr=Bl;var Ol=[[-.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 Dl(){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 _a(t,e){let r=Dl();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,ht=2;var Qo=8,Zo=16,Nl=32;var kl=16384;var di=65536,Sa=1<<17,Ul=1<<18,Hl=1<<19,Vl=1<<20,Gl=1<<21,Wl=1<<22,Xl=1<<23,oh=1<<24,ui=1<<25,Kl=1<<26,sh=1<<27,ah=1<<28,ch=1<<29,fi=1<<30,lh=1<<31;var Kr=0;var Aa=4,Ma=8,wa=16,La=32,Ea=64;var dh=1<<25,uh=1<<28,fh=1<<29,hh=1<<30,mh=1<<31;var ph=Ke|ht,yh=Ke|di|ht|ui|fi,gh=Ke|di|ht,xh=Ke|Sa|ht|ui|fi,bh=Nl|Qo|Zo,vh=Ke|Zo|Qo,Yl=Ke|ui|fi|ht|Kl,_h=Ul|Hl|Vl|Gl|Wl|Xl,Sh=Ke|Qo|Zo|ui|fi,Ah=Ke|di|ht,Mh=Ke|ht,wh=Ke|di|ht|Sa,Lh=Yl|kl;var Eh=Number.MAX_SAFE_INTEGER-1;var hi=(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))(hi||{});var mi=256;var es=256,ts=8192,pi=2048,rs=512,ns=256,is=mi*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+mi]="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 ql={};ga(ql,{addReplayFrame:()=>Ql,createReplaySession:()=>Jl,deserializeReplay:()=>jl,serializeReplay:()=>$l});function $l(t){return JSON.stringify(t,null,2)}function jl(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 R=(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[t.splitclient=21]="splitclient",t[t.configblast=22]="configblast",t[t.spawnbaselineblast=23]="spawnbaselineblast",t[t.level_restart=24]="level_restart",t[t.damage=25]="damage",t[t.locprint=26]="locprint",t[t.fog=27]="fog",t[t.waitingforplayers=28]="waitingforplayers",t[t.bot_chat=29]="bot_chat",t[t.poi=30]="poi",t[t.help_path=31]="help_path",t[t.muzzleflash3=32]="muzzleflash3",t[t.achievement=33]="achievement",t))(R||{});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 Zl=12,ed=9,Th=Math.ceil(Zl*ed/16),td=23,rd=2,Ih=Math.ceil(td*rd/16);var nd={};ga(nd,{U_ANGLE1:()=>dd,U_ANGLE2:()=>ud,U_ANGLE3:()=>fd,U_EFFECTS:()=>pd,U_EVENT:()=>xd,U_FRAME:()=>hd,U_MODEL:()=>od,U_MODEL2:()=>vd,U_MODEL3:()=>_d,U_MODEL4:()=>Sd,U_MOREBITS:()=>bd,U_NUMBER:()=>id,U_ORIGIN1:()=>ad,U_ORIGIN2:()=>cd,U_ORIGIN3:()=>ld,U_REMOVE:()=>Ad,U_RENDERFX:()=>yd,U_SKIN:()=>md,U_SOLID:()=>gd,U_SOUND:()=>sd});var id=1,od=2,sd=4,ad=8,cd=16,ld=32,dd=64,ud=128,fd=256,hd=512,md=1024,pd=2048,yd=4096,gd=8192,xd=16384,bd=32768,vd=1,_d=2,Sd=4,Ad=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=Ol[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||{}),Ch=Object.keys(Ra).length/2;var Yr=class{constructor({name:e,defaultValue:r,description:n,flags:i=hi.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&hi.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 Md(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 Md(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,mi,"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 wd="PACK";function Ld(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 Ed(){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 Td=Ed();function Pa(t){let e=4294967295;for(let r=0;r<t.length;r+=1){let n=t[r];e=Td[(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!==wd)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,h=Ld(n,f,56),m=ie(h),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 ${h||"<unnamed>"} (offset=${y}, length=${p})`);if(!m)throw new ze(`Entry ${u} has an empty name`);let g={name:m,offset:y,length:p};d.set(m,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 mt=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 Id(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 mt("blob",new Error("Unsupported Blob type"))}async function Cd(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 Id(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 Cd(l,n.onProgress),u=ur.fromArrayBuffer(l.name,d),f=n.validator?.validateArchive(u);if(f){n.onValidationResult?.(f);let h=f.status==="mismatch",m=f.status==="unknown";if(h&&o||m&&!s){let y=new Dt(f);if(n.onError?.(l.name,y),a)throw new mt(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(h){if(n.onError?.(l.name,h),a)throw new mt(l.name,h)}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 mt(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 Rd(t){return Array.isArray(t)?t:Array.from(t)}function as(t){return Rd(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 zd="IBSP",Fd=38,Ua=19,Pd=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<Pd)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!==zd)throw new q(`Invalid BSP magic ${r}`);let n=e.getInt32(4,!0);if(n!==Fd)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=Od(t,i.get(0)),a=Nd(t,i.get(1)),c=kd(t,i.get(2)),l=Ud(t,i.get(4)),d=Hd(t,i.get(5)),u=Vd(t,i.get(6)),f=new Uint8Array(t,i.get(7).offset,i.get(7).length),h=Jd(u,i.get(7)),m=Gd(t,i.get(8)),y=Wd(t,i.get(11)),p=Xd(t,i.get(12)),g=Kd(t,i.get(13)),_=Yd(t,i.get(14)),x=qd(t,i.get(15)),v=$d(t,i.get(9),i.get(10),m),b=jd(t,i.get(3));return{header:o,entities:s,planes:a,vertices:c,nodes:l,texInfo:d,faces:u,lightMaps:f,lightMapInfo:h,leafs:m,leafLists:v,edges:y,surfEdges:p,models:g,brushes:_,brushSides:x,visibility:b,pickEntity(M){let w=null,E=1/0;for(let L of s.entities){let O=L.properties.model;if(!O||!O.startsWith("*"))continue;let N=parseInt(O.substring(1),10);if(isNaN(N)||N<0||N>=g.length)continue;let H=g[N],C=Bd(M.origin,M.direction,H.mins,H.maxs);C!==null&&C<E&&(E=C,w={entity:L,model:H,distance:C})}return w}}}function Bd(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 Od(t,e){let r=new TextDecoder().decode(new Uint8Array(t,e.offset,e.length)),n=Dd(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 Dd(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 Nd(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 kd(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 Ud(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),h=r.getUint16(a+26,!0);o.push({planeIndex:c,children:l,mins:d,maxs:u,firstFace:f,numFaces:h})}return o}function Hd(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),h=r.getInt32(a+36,!0),m=new Uint8Array(t,e.offset+a+40,32),y=new TextDecoder("utf-8").decode(m).replace(/\0.*$/,""),p=r.getInt32(a+72,!0);o.push({s:c,sOffset:l,t:d,tOffset:u,flags:f,value:h,texture:y,nextTexInfo:p})}return o}function Vd(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),h=[r.getUint8(a+12),r.getUint8(a+13),r.getUint8(a+14),r.getUint8(a+15)],m=r.getInt32(a+16,!0);o.push({planeIndex:c,side:l,firstEdge:d,numEdges:u,texInfo:f,styles:h,lightOffset:m})}return o}function Gd(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)],h=r.getUint16(a+20,!0),m=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:h,numLeafFaces:m,firstLeafBrush:y,numLeafBrushes:p})}return o}function Wd(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 Xd(t,e){let r=e.length/4;if(r%1!==0)throw new q("SurfEdge lump has invalid length");let n=new DataView(t,e.offset,e.length),i=new Int32Array(r);for(let o=0;o<r;o+=1)i[o]=n.getInt32(o*4,!0);return i}function Kd(t,e){let r=new DataView(t,e.offset,e.length),n=48;if(e.length%n!==0)throw new q("Model lump has invalid length");let i=e.length/n,o=[];for(let s=0;s<i;s+=1){let a=s*n,c=[r.getFloat32(a,!0),r.getFloat32(a+4,!0),r.getFloat32(a+8,!0)],l=[r.getFloat32(a+12,!0),r.getFloat32(a+16,!0),r.getFloat32(a+20,!0)],d=[r.getFloat32(a+24,!0),r.getFloat32(a+28,!0),r.getFloat32(a+32,!0)],u=r.getInt32(a+36,!0),f=r.getInt32(a+40,!0),h=r.getInt32(a+44,!0);o.push({mins:c,maxs:l,origin:d,headNode:u,firstFace:f,numFaces:h})}return o}function Yd(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 qd(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 $d(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 h=0;h<d.numLeafFaces;h+=1)u.push(c.getUint16((d.firstLeafFace+h)*2,!0));let f=[];for(let h=0;h<d.numLeafBrushes;h+=1)f.push(l.getUint16((d.firstLeafBrush+h)*2,!0));i.push(u),o.push(f)}return{leafFaces:i,leafBrushes:o}}function jd(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 Qd=844121161,Zd=8,Ha=68,e0=[{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{},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=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 t0(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!==Qd)throw new le(`Invalid MD2 ident: ${r}`);if(n!==Zd)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 r0(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 n0(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 i0(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 o0(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,h=1/0,m=-1/0,y=-1/0,p=-1/0;for(let g=0;g<e.numVertices;g+=1){let _=40+g*4,x=s.getUint8(_)*a.x+c.x,v=s.getUint8(_+1)*a.y+c.y,b=s.getUint8(_+2)*a.z+c.z;x<u&&(u=x),v<f&&(f=v),b<h&&(h=b),x>m&&(m=x),v>y&&(y=v),b>p&&(p=b);let A={x,y:v,z:b},M=s.getUint8(_+3),w=e0[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:h},maxBounds:{x:m,y,z:p}})}return n}function s0(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),h=n.getInt32(o+8,!0);if(o+=12,h<0||h>=e.numVertices)throw new le("GL command references invalid vertex index");c.push({s:u,t:f,vertexIndex:h})}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=t0(t),r=r0(t,e),n=n0(t,e),i=i0(t,e),o=o0(t,e),s=s0(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,a0=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 c0(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 l0(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!==a0)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 d0(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 u0(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 f0(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),h=t.getInt32(e+104,!0);if(o<=0||a<=0||c<=0)throw new Fe(`Invalid surface counts for ${n}`);let m=h;vi(`Surface ${n}`,e,m,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=[],_=e+d;for(let M=0;M<s;M+=1){let w=_+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,O=t.getInt16(L,!0)/64,N=t.getInt16(L+2,!0)/64,H=t.getInt16(L+4,!0)/64,C=t.getUint16(L+6,!0);w.push({position:{x:O,y:N,z:H},latLng:C,normal:c0(C)})}b.push(w)}return{surface:{name:n,flags:i,numFrames:o,shaders:g,triangles:y,texCoords:x,vertices:b},nextOffset:e+h}}function ds(t){if(t.byteLength<108)throw new Fe("MD3 buffer too small for header");let e=new DataView(t),r=l0(e);vi("MD3 end",r.ofsEnd,0,t.byteLength);let n=d0(e,r),i=u0(e,r),o=[],s=r.ofsSurfaces;for(let a=0;a<r.numSurfaces;a+=1){let{surface:c,nextOffset:l}=f0(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 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=ds(r.slice().buffer);return this.cache.set(e,n),n}get(e){return this.cache.get(e)}};var h0=844317769,m0=2,Xa=64,Ka=12,yt=class extends Error{};function p0(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!==h0)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),h=p0(e,a+16,Xa);o.push({width:l,height:d,originX:u,originY:f,name:h}),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 _i(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=[],h=i,m=o;for(let y=0;y<s.length;y+=1){let p=s[y],g=Math.max(1,h*m|0);if(p<=0||p+g>t.byteLength)throw new Jr(`Invalid WAL mip offset for level ${y}`);let _=new Uint8Array(t,p,g);f.push({level:y,width:h,height:m,data:_}),h=Math.max(1,h>>1),m=Math.max(1,m>>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 h=new Uint8Array(t,f+1,768),m=new Uint8Array(t,128,f-128),y=new Uint8Array(l*d),p=0,g=0;for(let _=0;_<d;_+=1){let x=0;for(;x<u&&p<m.length;){let v=1,b=m[p++];if((b&192)===192){if(v=b&63,p>=m.length)throw new Nt("Unexpected end of PCX RLE data");b=m[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:h}}function Si(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 h=o*s,m=new Uint8Array(h*4),y=(c&32)!==0,p=0,g=new Uint8Array(t),_=x=>{if(d){let v=g[f++];m[x]=v,m[x+1]=v,m[x+2]=v,m[x+3]=255}else{let v=g[f++],b=g[f++],A=g[f++],M=a===32?g[f++]:255;m[x]=A,m[x+1]=b,m[x+2]=v,m[x+3]=M}};if(l){let x=0;for(;x<h;){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>h)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 O=0;O<b;O++){let N=(x+O)*4;m[N]=M,m[N+1]=w,m[N+2]=E,m[N+3]=L}}else for(let M=0;M<b;M++)_((x+M)*4);x+=b}}else for(let x=0;x<h;x++){if(f>=t.byteLength)throw new et("Unexpected end of TGA data");_(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(m.subarray(A,A+x)),m.set(m.subarray(M,M+x),A),m.set(v,M)}}return{width:o,height:s,bitsPerPixel:32,pixels:m}}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 hs(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=Si(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 hs(_i(t),e)}var kt=class extends Error{constructor(e){super(e),this.name="WavParseError"}};function ms(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(ms(e,0,4)!=="RIFF"||ms(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 m=ms(e,r,4),y=e.getUint32(r+4,!0),p=r+8;m==="fmt "?(n=p,o=y):m==="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),h=new Float32Array(f*c);for(let m=0;m<f;m+=1)for(let y=0;y<c;y+=1){let p=m*c+y,g=i+p*u,_=0;if(d===8)_=e.getUint8(g),h[p]=(_-128)/128;else if(d===16)_=e.getInt16(g,!0),h[p]=_/32768;else if(d===24){let x=e.getUint8(g),v=e.getUint8(g+1),b=e.getInt8(g+2);_=x|v<<8|b<<16,h[p]=_/8388608}else throw new kt(`Unsupported bitsPerSample: ${d}`)}return{sampleRate:l,channels:c,bitsPerSample:d,samples:h}}var y0=(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=y0)=>{let r=p=>new Uint8Array(p.length/2).map(((g,_)=>parseInt(p.substring(2*_,2*(_+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",h=0;f&&(h=11,a=n(t.substring(9,h)),a<=1&&(h+=2,u=n(t.substring(11,h))),a===1&&(h+=8,c=(p=>new DataView(r(p).buffer).getInt32(0,!0))(t.substring(13,h))));let m=256-u;for(let p=h;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+m: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
3
  `,"Visit https://github.com/eshaz/simple-yenc for more information"),Error(g)}}return y};function Z(){let t=Uint8Array,e=Float32Array;Z.modules||Object.defineProperties(Z,{modules:{value:new WeakMap},setModule:{value(r,n){Z.modules.set(r,Promise.resolve(n))}},getModule:{value(r,n){let i=Z.modules.get(r);return i||(n?i=WebAssembly.compile(ps(n)):(n=r.wasm,i=Z.inflateDynEncodeString(n).then(o=>WebAssembly.compile(o))),Z.modules.set(r,i)),i}},concatFloat32:{value(r,n){let i=new e(n),o=0,s=0;for(;o<r.length;)i.set(r[o],s),s+=r[o++].length;return i}},getDecodedAudio:{value:(r,n,i,o,s)=>({errors:r,channelData:n,samplesDecoded:i,sampleRate:o,bitDepth:s})},getDecodedAudioMultiChannel:{value(r,n,i,o,s,a){let c=[],l,d;for(l=0;l<i;l++){let u=[];for(d=0;d<n.length;)u.push(n[d++][l]||[]);c.push(Z.concatFloat32(u,o))}return Z.getDecodedAudio(r,c,o,s,a)}},inflateDynEncodeString:{value(r){return r=ps(r),new Promise(n=>{let i=String.raw`dynEncode012804c7886d(‰›•)((()>+ˆ*§§)§ˆ,§§§§)§ˆ+§§§)§+.-()(*)-+)(ˆ.7*§)i¸¸,3§(i¸¸,3/G+.••—š¡*(,˜ŽŽ(,3‡‡‰˜‡Š‰›+)2å:-œ),§H(P*DI*H(P*@I++hH)H*r,hH(H(P*<J,i)’^*<H,H(P*4’U((I-H(H*i0’J,^*DH+H-H*œšI+H,I*4)33H(H*H)“^*DH(H+H)^*@H+i§H)œi§›™3æ*).§K(iH“I/+§H,iHn,§H+i(H+i(rCJ0I,H*I-+hH,,hH(H-V)(i)œ’J.H.W)(i)’c)(H,i)“I,H-i*’I-4)33i(I.*hH(V)(H+n5(H(i*’I-i(I,i)I.+hH,i*’J+iHn,hi(I-i*I,+hH,H/’H-c)(H,iFn,hi(I,+hH,H0n5-H*V)(J(,hH/H(i)œ’J(H(V)(J(i)’c)(H)H(i)œ’H,c)(3H*i*’I*H,i)’I,4(3(-H(H,’W)(H-’I-H,i*’I,4)3(3(3H,H-’I1H+I,H.i)œH1V)(“J.i(v5(33H.-H(H,’i(c)(H,i*’I,4)333–)-§i*I*+§H*iHn,hiž73H,H(i)8(H+šJ+H)P*(H*’V)(J-“r,§H)P*,H.i)œ’H+H,“i)œ’V)(-H*i*’I*H+i)œI+H-H.’I.H,H-’i)œI,4)333Ã+)-§iø7i(^*(iü7I,*h+hH+iDn,h*hilI+i)I,+hH+,hH+iô7’H,c)(i)H+i´8’W)(œH,’I,H+i*’I+4)-+hH(H)8*J-i(p5.*h*h*hH-i')u,hH(P*(J+,hH(P*0J,H(P*,n50H+H,’H-b((3H(P*0i)’I.4)3H-i¨*n5*H-iÅ*s,hiž73H-i)œJ+V)&+I,H(H+V)æ,8(I.H(H*8*J-i(p51H-i)œJ+i¸7’V)(H(H+iø7’V)(8(’J/H(P*0J+s,hi73H+H,H.’J,’I.H(P*(m5(H.H(P*,s5.+hH,m5*H(P*(J.H+’H.H+H/“’U((b((H(H(P*0i)’J+^*0H,i)“I,4(3(3H(H.^*03H-i¨*o5)33i(73(3(3-H,H+i)žc)(H,i*’I,H+i)’I+4)33i)I-3H-3!2)0§K(i2“J,L(H,H(^*(H,H*^*4H,i(^*0H,i(^*DH,j(_*<H,H)P*(^*,H,H+P*(^*8*h*h+hH,i)8(I3i§I**h*h*h*h*h*h*hH,i*8(6+(),03H,j(_*@i*I-H,P*<J.i,’J(H,P*8J/s50H,H.i+’J0^*<i¦I*H.H,P*4J1’J.U(*H.U((J2›i')o5/H.U()I.H,H(^*<H0H1’U((H.i0œJ.i§›i0ži')™o5/H/H.H2šJ*H(’J.q50H,P*0J/H*’I-H,P*(J0,hH,P*,H-q,hi)I-423+hH*m5+H/H0’H(H1’U((b((H/i)’I/H(i)’I(H*i)“I*4(3(3H,H.^*<H,H-^*04*3iØ1U((5+i(I(i¨7i1^*(i$6iè1^*(i°7iè6^*(i¬7iÈ6^*(+hH(iÈ*n,hiÈ*I(+hH(i¨,n,hi¨,I(+hH(iØ,n,hiØ,I(+hH(iè,o,hH,i-’H(’i0c)(H(i*’I(4)33iè1i1H,i-’iÈ*8)Bi(I(+hH(ido,hH,i-’H(’i-c)(H(i*’I(4)33iÈ6iè6H,i-’iF8)BiØ1i)b((41-H,i-’H(’i/c)(H(i*’I(4)3(3(-H,i-’H(’i1c)(H(i*’I(4)3(3(-H,i-’H(’i0c)(H(i*’I(4)3(3(3H,H/^*0H,H(^*<3i(I*4*3H,H,i¸)’^*TH,H,iø-’^*PH,H,iX’^*LH,H,i(’^*HH,i-8(I(H,i-8(I-i¥I*H,i,8(I.H(iErH-iErš5)H(i©*’I1H-i)’I0i(i;H.i,’J(i(H(i(rCJ(“J*H*i;sCI*i¨1I-H(I/+hH/,hH,i-’H-V)(i)œ’H,i+8(c)(H/i)“I/H-i*’I-H*i)’I*4)-H(i)œi¨1’I/+hH(H*o,hH,i-’H/V)(i)œ’i(c)(H/i*’I/H(i)’I(4)33i¤I*H,iø-’H,i¸)’H,i-’i;8)5+H0H1’I2i(I-+hH-H2p,hH,H,iP’8*J*i(p5-H*i7u,hH,i-’H-i)œ’H*c)(H-i)’I-4*3i(I/i+I.i+I(*h*h*hH*i8“6*(*)3H-m,hi£I*403H-i)œH,’W)-I/i*I(4)3i3I.i/I(3H2H,H(8(H.’J(H-’J.p,hi¢I*4.3H,i-’H-i)œ’I*+hH(,hH*H/c)(H*i*’I*H(i)“I(4)-H.I-4+3(3(33H,W)1m,hiŸI*4,3H,iø-’H,i¸)’H,i-’H18)J(,hi¡I*H(i(p5,H1H,V)ú-H,V)ø-’o5,3H,i(’H,iX’H,i-’H1i)œ’H08)J(,hi I*H(i(p5,H0H,V)šH,V)˜’o5,3H,H,iP’H,iH’8+I*4+3(3(3H,i$6i¬78+I*3H*H3šm5(3i)I-H*i(r5)3H)H,P*0^*(H+H,P*<^*(H*I-3H,i2’L(H-33Á)+(i¨03b+(,(-(.(/(0(1(2(3(5(7(9(;(?(C(G(K(S([(c(k({(‹(›(«(Ë(ë( (*)(iø03O)()()()(*(*(*(*(+(+(+(+(,(,(,(,(-(-(-(-(i¨13M8(9(:(((0(/(1(.(2(-(3(,(4(+(5(*(6()(7(T7œ‰šœ‡Ž‰œš›*S7•œ‰Š”U”—Љ”›S0›‘–U œ`;Z.getModule(Z,i).then(o=>WebAssembly.instantiate(o,{})).then(({exports:o})=>{let s=new Map(Object.entries(o)),a=s.get("puff"),c=s.get("memory").buffer,l=new t(c),d=new DataView(c),u=s.get("__heap_base"),f=r.length,h=u;u+=4,d.setInt32(h,f,!0);let m=u;u+=f,l.set(r,m);let y=u;u+=4,d.setInt32(y,l.byteLength-u,!0),a(u,y,m,h),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=Tl(Za(),1);var g0=()=>globalThis.Worker||ec.default,gr=class extends g0(){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,h,m=new Promise(y=>{h=y});self.onmessage=({data:{id:y,command:p,data:g}})=>{let _=m,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),h()):p==="free"?f.free():p==="ready"?_=_.then(()=>f.ready):p==="reset"?_=_.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):[]),_.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,Ti=88200,ic=64e3,bt=48e3,xr=44100,br=32e3,vr=24e3,_r=22050,Sr=16e3,Ii=12e3,Ci=11025,Ar=8e3,oc=7350,Ve="absoluteGranulePosition",k="bandwidth",he="bitDepth",me="bitrate",tn=me+"Maximum",rn=me+"Minimum",nn=me+"Nominal",qe="buffer",on=qe+"Fullness",J="codec",pe=J+"Frames",sn="coupledStreamCount",Mr="crc",an=Mr+"16",cn=Mr+"32",$="data",F="description",$e="duration",wr="emphasis",ln="hasOpusPadding",Le="header",vt="isContinuedPacket",dn="isCopyrighted",_t="isFirstPage",un="isHome",Ee="isLastPage",tt="isOriginal",rt="isPrivate",fn="isVbr",Ae="layer",S="length",D="mode",nt=D+"Extension",Ri="mpeg",it=Ri+"Version",hn="numberAACFrames",mn="outputGain",Ut="preSkip",pn="profile",zi=ee(),ot="protection",ys="rawData",Pe="segments",U="subarray",St="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(),z=Bi+"s",sc="copyright",_n=sc+"Id",Sn=sc+"IdStart",ct="frame",lt=ct+"Count",Me=ct+"Length",Oi="Number",dt=ct+Oi,je=ct+"Padding",B=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(),_s=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 Ss=(t,e,r)=>{for(let n=0;n<t[S];n++){let i=e(n);for(let o=8;o>0;o--)i=r(i);t[n]=i}return t},b0=Ss(new ge(256),t=>t,t=>t&128?7^t<<1:t<<1),re=[Ss(new Uint16Array(256),t=>t<<8,t=>t<<1^(t&32768?32773:0))],ne=[Ss(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[S];for(let n=0;n!==r;n++)e=b0[e^t[n]];return e},dc=t=>{let e=t[S],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[S],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[S],0));return t.reduce((r,n)=>(e.set(n,r),r+n[S]),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[S]*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}*[_s](){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[_s](),n=de.get(r)[S];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))[U](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)[S]=r[S]}};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[St]=`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[S]=10+a,new t(o)}constructor(e){this[St]=e[St],this[As]=e[As],this[Ms]=e[Ms],this[ws]=e[ws],this[Ls]=e[Ls],this[S]=e[S]}};var Ce=class{constructor(e){ce.set(this,e),this[he]=e[he],this[me]=null,this[z]=e[z],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 v0=0,_0=1,S0=2,A0=3,hc=4,Wi="bands ",Xi=" to 31",mc={0:Wi+4+Xi,16:Wi+8+Xi,32:Wi+12+Xi,48:Wi+16+Xi},Yt="bitrateIndex",Fn="v2",ji="v1",Ki="Intensity stereo ",Yi=", MS stereo ",qi="on",$i="off",M0={0:Ki+$i+Yi+$i,16:Ki+qi+Yi+$i,32:Ki+$i+Yi+qi,48:Ki+qi+Yi+qi},Es={0:{[F]:K},2:{[F]:"Layer III",[je]:1,[nt]:M0,[ji]:{[Yt]:S0,[G]:1152},[Fn]:{[Yt]:hc,[G]:576}},4:{[F]:"Layer II",[je]:1,[nt]:mc,[G]:1152,[ji]:{[Yt]:_0},[Fn]:{[Yt]:hc}},6:{[F]:"Layer I",[je]:4,[nt]:mc,[G]:384,[ji]:{[Yt]:v0},[Fn]:{[Yt]:A0}}},Ts="MPEG Version ",pc="ISO/IEC ",w0={0:{[F]:`${Ts}2.5 (later extension of MPEG 2)`,[Ae]:Fn,[V]:{0:Ci,4:Ii,8:Ar,12:K}},8:{[F]:K},16:{[F]:`${Ts}2 (${pc}13818-3)`,[Ae]:Fn,[V]:{0:_r,4:vr,8:Sr,12:K}},24:{[F]:`${Ts}1 (${pc}11172-3)`,[Ae]:ji,[V]:{0:xr,4:bt,8:br,12:K}},length:S},L0={0:Hi,1:Tn},E0={0:Tn,1:"50/15 ms",2:K,3:"CCIT J.17"},yc={0:{[z]:2,[F]:xt},64:{[z]:2,[F]:"joint "+xt},128:{[z]:2,[F]:"dual channel"},192:{[z]:1,[F]: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[S],n),e[Be](o[S]));let s=yield*e[W](4,n),a=Te(s[U](0,4)),c=r[X](a);if(c)return new t(c);if(s[0]!==255||s[1]<224)return null;let l=w0[s[1]&24];if(l[F]===K)return null;let d=s[1]&6;if(Es[d][F]===K)return null;let u={...Es[d],...Es[d][l[Ae]]};if(i[it]=l[F],i[Ae]=u[F],i[G]=u[G],i[ot]=L0[s[1]&1],i[S]=4,i[me]=gc[s[2]&240][u[Yt]],i[me]===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[me]*i[G]/i[V]+i[je]),!i[Me]))return null;let f=s[3]&192;if(i[ye]=yc[f][F],i[z]=yc[f][z],i[nt]=u[nt][s[3]&48],i[dn]=!!(s[3]&8),i[tt]=!!(s[3]&4),i[wr]=E0[s[3]&3],i[wr]===K)return null;i[he]=16;{let{length:h,frameLength:m,samples:y,...p}=i;r[Oe](a,i,p)}return new t(i)}constructor(e){super(e),this[me]=e[me],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 T0={0:"MPEG-4",8:"MPEG-2"},I0={0:"valid",2:xe,4:xe,6:xe},C0={0:Hi,1:Tn},R0={0:"AAC Main",64:"AAC LC (Low Complexity)",128:"AAC SSR (Scalable Sample Rate)",192:"AAC LTP (Long Term Prediction)"},z0={0:Ei,4:Ti,8:ic,12:bt,16:xr,20:br,24:vr,28:_r,32:Sr,36:Ii,40:Ci,44:Ar,48:oc,52:K,56:K,60:"frequency is written explicitly"},xc={0:{[z]:0,[F]:"Defined in AOT Specific Config"},64:{[z]:1,[F]:gt},128:{[z]:2,[F]:te(2,P[0][0])},192:{[z]:3,[F]:te(3,P[1][3])},256:{[z]:4,[F]:te(4,P[1][3],P[3][4])},320:{[z]:5,[F]:te(5,P[1][3],P[3][0])},384:{[z]:6,[F]:te(6,P[1][3],P[3][0],Ye)},448:{[z]:8,[F]: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=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]=T0[o[1]&8],i[Ae]=I0[o[1]&6],i[Ae]===xe))return null;let l=o[1]&1;i[ot]=C0[l],i[S]=l?7:9,i[zi]=o[2]&192,i[Je]=o[2]&60;let d=o[2]&2;if(i[pn]=R0[i[zi]],i[V]=z0[i[Je]],i[V]===K)return null;i[rt]=!!d,i[vn]=(o[2]<<8|o[3])&448,i[ye]=xc[i[vn]][F],i[z]=xc[i[vn]][z],i[tt]=!!(o[3]&32),i[un]=!!(o[3]&8),i[_n]=!!(o[3]&8),i[Sn]=!!(o[3]&4),i[he]=16,i[G]=1024,i[hn]=o[6]&3;{let{length:u,channelModeBits:f,profileBits:h,sampleRateBits:m,frameLength:y,samples:p,numberAACFrames:g,..._}=i;r[Oe](s,i,_)}}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[_n]=e[_n],this[Sn]=e[Sn],this[on]=e[on],this[un]=e[un],this[tt]=e[tt],this[rt]=e[rt],this[Ae]=e[Ae],this[S]=e[S],this[it]=e[it],this[hn]=e[hn],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[S]-2]<<8)+e[e[S]-1]}static[Ui](e){let r=t._getFrameFooterCrc16(e),n=dc(e[U](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",F0={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 P0={0:bc,1:Ti,2:nc,3:rc,4:Ar,5:Sr,6:_r,7:vr,8:br,9:xr,10:bt,11:Ei,15:xe},B0={0:{[z]:1,[F]:gt},16:{[z]:2,[F]:te(2,P[0][0])},32:{[z]:3,[F]:te(3,P[0][1])},48:{[z]:4,[F]:te(4,P[1][0],P[3][0])},64:{[z]:5,[F]:te(5,P[1][1],P[3][0])},80:{[z]:6,[F]:te(6,P[1][1],Ye,P[3][0])},96:{[z]:7,[F]:te(7,P[1][1],Ye,P[3][4],P[2][0])},112:{[z]:8,[F]:te(8,P[1][1],Ye,P[3][0],P[2][0])},128:{[z]:2,[F]:`${xt} (left, diff)`},144:{[z]:2,[F]:`${xt} (diff, right)`},160:{[z]:2,[F]:`${xt} (avg, diff)`},176:K,192:K,208:K,224:K,240:K},O0={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[U](0,4)),a=r[X](s);if(a)Object.assign(o,a);else{if(o[Pi]=i[1]&1,o[gn]=F0[o[Pi]],o[xn]=i[2]&240,o[Je]=i[2]&15,o[st]=vc[o[xn]],o[st]===K||(o[V]=P0[o[Je]],o[V]===xe)||i[3]&1)return null;let l=B0[i[3]&240];if(l===K||(o[z]=l[z],o[ye]=l[F],o[he]=O0[i[3]&14],o[he]===K))return null}o[S]=5,i=yield*e[W](o[S]+8,n);let c=t._decodeUTF8Int(i[U](4));if(!c||(o[Pi]?o[Mn]=c.value:o[dt]=c.value,o[S]+=c[S],o[xn]===96?(i[S]<o[S]&&(i=yield*e[W](o[S],n)),o[st]=i[o[S]-1]+1,o[S]+=1):o[xn]===112&&(i[S]<o[S]&&(i=yield*e[W](o[S],n)),o[st]=(i[o[S]-1]<<8)+i[o[S]]+1,o[S]+=2),o[G]=o[st],o[Je]===12?(i[S]<o[S]&&(i=yield*e[W](o[S],n)),o[V]=i[o[S]-1]*1e3,o[S]+=1):o[Je]===13?(i[S]<o[S]&&(i=yield*e[W](o[S],n)),o[V]=(i[o[S]-1]<<8)+i[o[S]],o[S]+=2):o[Je]===14&&(i[S]<o[S]&&(i=yield*e[W](o[S],n)),o[V]=((i[o[S]-1]<<8)+i[o[S]])*10,o[S]+=2),i[S]<o[S]&&(i=yield*e[W](o[S],n)),o[Mr]=i[o[S]-1],o[Mr]!==lc(i[U](0,o[S]-1))))return null;if(!a){let{blockingStrategyBits:l,frameNumber:d,sampleNumber:u,samples:f,sampleRateBits:h,blockSizeBits:m,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 D0=2,N0=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[S]-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)[S]+D0;for(;r<=N0;){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[U](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[$][U](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[_t]=!!(o[5]&2),i[vt]=!!(o[5]&1);let a=new It(ge.from(o[U](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[S]=c+27,o=yield*e[W](i[S],n),i[Me]=0,i[wt]=[],i[Er]=ge.from(o[U](27,i[S]));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[_t]=e[_t],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)[S],a=s+o,c=(yield*e[W](a,0))[U](0,a),l=c[U](s,a);return new t(i,l,c)}else return null}constructor(e,r,n){super(e,r),de.get(this)[S]=n[S],this[pe]=[],this[ys]=n,this[Ve]=e[Ve],this[cn]=e[Vt],this[$e]=0,this[vt]=e[vt],this[_t]=e[_t],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 _c={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",k0={0:{[D]:ke,[k]:zt,[B]:10},8:{[D]:ke,[k]:zt,[B]:20},16:{[D]:ke,[k]:zt,[B]:40},24:{[D]:ke,[k]:zt,[B]:60},32:{[D]:ke,[k]:Qi,[B]:10},40:{[D]:ke,[k]:Qi,[B]:20},48:{[D]:ke,[k]:Qi,[B]:40},56:{[D]:ke,[k]:Qi,[B]:60},64:{[D]:ke,[k]:Ft,[B]:10},72:{[D]:ke,[k]:Ft,[B]:20},80:{[D]:ke,[k]:Ft,[B]:40},88:{[D]:ke,[k]:Ft,[B]:60},96:{[D]:Ji,[k]:Cr,[B]:10},104:{[D]:Ji,[k]:Cr,[B]:20},112:{[D]:Ji,[k]:Rr,[B]:10},120:{[D]:Ji,[k]:Rr,[B]:20},128:{[D]:ue,[k]:zt,[B]:2.5},136:{[D]:ue,[k]:zt,[B]:5},144:{[D]:ue,[k]:zt,[B]:10},152:{[D]:ue,[k]:zt,[B]:20},160:{[D]:ue,[k]:Ft,[B]:2.5},168:{[D]:ue,[k]:Ft,[B]:5},176:{[D]:ue,[k]:Ft,[B]:10},184:{[D]:ue,[k]:Ft,[B]:20},192:{[D]:ue,[k]:Cr,[B]:2.5},200:{[D]:ue,[k]:Cr,[B]:5},208:{[D]:ue,[k]:Cr,[B]:10},216:{[D]:ue,[k]:Cr,[B]:20},224:{[D]:ue,[k]:Rr,[B]:2.5},232:{[D]:ue,[k]:Rr,[B]:5},240:{[D]:ue,[k]:Rr,[B]:10},248:{[D]:ue,[k]:Rr,[B]:20}},zr=class t extends Ce{static[Ne](e,r,n){let i={};if(i[z]=e[9],i[at]=e[18],i[S]=i[at]!==0?21+i[z]:19,e[S]<i[S])throw new Error("Out of data while inside an Ogg Page");let o=r[0]&3,s=o===3?2:1,a=Te(e[U](0,i[S]))+Te(r[U](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[U](0,i[S]));let l=new It(i[$][qe]);if(i[he]=16,i[Ut]=l.getUint16(10,!0),i[An]=l.getUint32(12,!0),i[V]=bt,i[mn]=l.getInt16(16,!0),i[at]in _c&&(i[ye]=_c[i[at]][i[z]-1],!i[ye]))return null;i[at]!==0&&(i[wn]=e[19],i[sn]=e[20],i[bn]=[...e[U](21,i[z]+21)]);let d=k0[248&r[0]];switch(i[D]=d[D],i[k]=d[k],i[B]=d[B],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:h,...m}=i;n[Oe](a,i,m)}return new t(i)}constructor(e){super(e),this[$]=e[$],this[k]=e[k],this[at]=e[at],this[bn]=e[bn],this[sn]=e[sn],this[lt]=e[lt],this[B]=e[B],this[ln]=e[ln],this[An]=e[An],this[fn]=e[fn],this[D]=e[D],this[mn]=e[mn],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[B]*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[S]<30)throw new Error("Out of data while inside an Ogg Page");let o=Te(e[U](0,30)),s=r[X](o);if(s)return new t(s);let a={[S]:30};if(o.substr(0,7)!=="vorbis")return null;a[$]=ge.from(e[U](0,30));let c=new It(a[$][qe]);if(a[St]=c.getUint32(7,!0),a[St]!==0||(a[z]=e[11],a[ye]=en[a[z]-1]||"application defined",a[V]=c.getUint32(12,!0),a[tn]=c.getInt32(16,!0),a[nn]=c.getInt32(20,!0),a[rn]=c.getInt32(24,!0),a[Mt]=Is[(e[28]&240)>>4],a[At]=Is[e[28]&15],a[At]>a[Mt])||e[29]!==1)return null;a[he]=32,a[Lr]=i,a[yn]=n;{let{length:l,data:d,version:u,vorbisSetup:f,vorbisComments:h,...m}=a;r[Oe](o,a,m)}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[U](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[$][U](i,i+=o)),this._continuedPacket[S]&&(r[Pe][0]=Cn(this._continuedPacket,r[Pe][0]),this._continuedPacket=new ge),n[Er][n[Er][S]-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[S]<=e+r;){if(n=yield,this._flushing)return this._rawData[U](r);n&&(this._totalBytesIn+=n[S],this._rawData=Cn(this._rawData,n))}return this._rawData[U](r)}[Be](e){this._currentReadPosition+=e,this._rawData=this._rawData[U](e)}[En](e){this._sampleRate=e[Le][V],e[Le][me]=e[$e]>0?Math.round(e[$][S]/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][me],e[Wt]),this._totalBytesOut+=e[$][S],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[S]));r.push(`--stats--${"-".repeat(i-9)}`,...n,"-".repeat(i)),e("codec-parser",r.reduce((o,s)=>o+`
4
4
  `+s,""))}}[Ge](...e){this._log(console.warn,e)}[Ni](...e){this._log(console.error,e)}};var Sc=Gn;var Zi=pe;var eo=$;var 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,h,m;function y(){var I=m.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),h=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(""),_=()=>{},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,O=Math.pow,N=Math.sin,H=I=>{var Re=a.length;return I>>>=0,!1},C=I=>{throw`exit(${I})`},Q=new Uint8Array(123),Se=25;Se>=0;--Se)Q[48+Se]=52+Se,Q[65+Se]=Se,Q[97+Se]=26+Se;Q[43]=62,Q[47]=63;var Bt={e:g,d:_,f:A,b:M,a:w,i:E,h:L,g:O,c:N,k:H,j:C};function oi(I){Vr=I.n,la=I.o,da=I.p,ua=I.q,fa=I.r,ha=I.s,ma=I.t,pa=I.v}var Vr,la,da,ua,fa,ha,ma,pa;function vl(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¹‡= 
@@ -363,7 +363,7 @@ void main() {
363
363
  }
364
364
 
365
365
  o_color = finalColor;
366
- }`;function ou(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 su(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:su(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 h=$c(u.position,f.position,o),m=ou($c(u.normal,f.normal,o)),y=d*8;c[y]=h.x,c[y+1]=h.y,c[y+2]=h.z,c[y+3]=m.x,c[y+4]=m.y,c[y+5]=m.z,c[y+6]=l.texCoord[0],c[y+7]=l.texCoord[1]}),c}var So=class{constructor(e,r,n){this.gl=e,this.geometry=Js(r),this.vertexBuffer=new _e(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,h=[1,1,1,1];l&&(l.mode==="solid"||l.mode==="wireframe"?f=1:l.mode==="solid-faceted"&&(f=2),l.color?h=[...l.color]:l.generateRandomColor),this.gl.uniform1i(this.uniformRenderMode,f),this.gl.uniform4f(this.uniformSolidColor,h[0],h[1],h[2],h[3]);let m=Math.min(c.length,Pt);this.gl.uniform1i(this.uniformNumDlights,m);for(let y=0;y<m;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,pg=180/Math.PI;var ae={};qo(ae,{add:()=>Xu,adjoint:()=>mu,clone:()=>cu,copy:()=>lu,create:()=>au,decompose:()=>Ru,determinant:()=>pu,equals:()=>$u,exactEquals:()=>qu,frob:()=>Wu,fromQuat:()=>Pu,fromQuat2:()=>Tu,fromRotation:()=>Mu,fromRotationTranslation:()=>Zc,fromRotationTranslationScale:()=>zu,fromRotationTranslationScaleOrigin:()=>Fu,fromScaling:()=>Au,fromTranslation:()=>Su,fromValues:()=>du,fromXRotation:()=>wu,fromYRotation:()=>Lu,fromZRotation:()=>Eu,frustum:()=>Bu,getRotation:()=>Cu,getScaling:()=>el,getTranslation:()=>Iu,identity:()=>Jc,invert:()=>hu,lookAt:()=>Hu,mul:()=>ju,multiply:()=>Qc,multiplyScalar:()=>Ku,multiplyScalarAndAdd:()=>Yu,ortho:()=>ku,orthoNO:()=>rl,orthoZO:()=>Uu,perspective:()=>Ou,perspectiveFromFieldOfView:()=>Nu,perspectiveNO:()=>tl,perspectiveZO:()=>Du,rotate:()=>xu,rotateX:()=>bu,rotateY:()=>vu,rotateZ:()=>_u,scale:()=>gu,set:()=>uu,str:()=>Gu,sub:()=>Ju,subtract:()=>nl,targetTo:()=>Vu,translate:()=>yu,transpose:()=>fu});function au(){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 cu(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 lu(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 du(t,e,r,n,i,o,s,a,c,l,d,u,f,h,m,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]=h,p[14]=m,p[15]=y,p}function uu(t,e,r,n,i,o,s,a,c,l,d,u,f,h,m,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]=h,t[13]=m,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 fu(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 hu(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],h=e[11],m=e[12],y=e[13],p=e[14],g=e[15],_=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*m,E=d*p-f*m,L=d*g-h*m,O=u*p-f*y,N=u*g-h*y,H=f*g-h*p,C=_*H-x*N+v*O+b*L-A*E+M*w;return C?(C=1/C,t[0]=(a*H-c*N+l*O)*C,t[1]=(i*N-n*H-o*O)*C,t[2]=(y*M-p*A+g*b)*C,t[3]=(f*A-u*M-h*b)*C,t[4]=(c*L-s*H-l*E)*C,t[5]=(r*H-i*L+o*E)*C,t[6]=(p*v-m*M-g*x)*C,t[7]=(d*M-f*v+h*x)*C,t[8]=(s*N-a*L+l*w)*C,t[9]=(n*L-r*N-o*w)*C,t[10]=(m*A-y*v+g*_)*C,t[11]=(u*v-d*A-h*_)*C,t[12]=(a*E-s*O-c*w)*C,t[13]=(r*O-n*E+i*w)*C,t[14]=(y*x-m*b-p*_)*C,t[15]=(d*b-u*x+f*_)*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],h=e[11],m=e[12],y=e[13],p=e[14],g=e[15],_=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*m,E=d*p-f*m,L=d*g-h*m,O=u*p-f*y,N=u*g-h*y,H=f*g-h*p;return t[0]=a*H-c*N+l*O,t[1]=i*N-n*H-o*O,t[2]=y*M-p*A+g*b,t[3]=f*A-u*M-h*b,t[4]=c*L-s*H-l*E,t[5]=r*H-i*L+o*E,t[6]=p*v-m*M-g*x,t[7]=d*M-f*v+h*x,t[8]=s*N-a*L+l*w,t[9]=n*L-r*N-o*w,t[10]=m*A-y*v+g*_,t[11]=u*v-d*A-h*_,t[12]=a*E-s*O-c*w,t[13]=r*O-n*E+i*w,t[14]=y*x-m*b-p*_,t[15]=d*b-u*x+f*_,t}function pu(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],h=t[12],m=t[13],y=t[14],p=t[15],g=e*s-r*o,_=e*a-n*o,x=r*a-n*s,v=l*m-d*h,b=l*y-u*h,A=d*y-u*m,M=e*A-r*b+n*v,w=o*A-s*b+a*v,E=l*x-d*_+u*g,L=h*x-m*_+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],h=e[10],m=e[11],y=e[12],p=e[13],g=e[14],_=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*h+A*g,t[3]=x*s+v*d+b*m+A*_,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*h+A*g,t[7]=x*s+v*d+b*m+A*_,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*h+A*g,t[11]=x*s+v*d+b*m+A*_,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*h+A*g,t[15]=x*s+v*d+b*m+A*_,t}function yu(t,e,r){var n=r[0],i=r[1],o=r[2],s,a,c,l,d,u,f,h,m,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],h=e[7],m=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]=h,t[8]=m,t[9]=y,t[10]=p,t[11]=g,t[12]=s*n+d*i+m*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+h*i+g*o+e[15]),t}function gu(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 xu(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,h,m,y,p,g,_,x,v,b,A,M,w,E,L,O,N,H,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],h=e[2],m=e[3],y=e[4],p=e[5],g=e[6],_=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,O=o*o*d+l,N=s*o*d+i*c,H=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]=h*M+g*w+b*E,t[3]=m*M+_*w+A*E,t[4]=u*L+y*O+x*N,t[5]=f*L+p*O+v*N,t[6]=h*L+g*O+b*N,t[7]=m*L+_*O+A*N,t[8]=u*H+y*C+x*Q,t[9]=f*H+p*C+v*Q,t[10]=h*H+g*C+b*Q,t[11]=m*H+_*C+A*Q,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}function bu(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 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[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 _u(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 Au(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 Mu(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 wu(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 Lu(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 Eu(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,h=i*c,m=i*l,y=o*l,p=s*a,g=s*c,_=s*l;return t[0]=1-(h+y),t[1]=u+_,t[2]=f-g,t[3]=0,t[4]=u-_,t[5]=1-(d+y),t[6]=m+p,t[7]=0,t[8]=f+g,t[9]=m-p,t[10]=1-(d+h),t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function Tu(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 Iu(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 Cu(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,h=e[9]*i,m=e[10]*o,y=s+d+m,p=0;return y>0?(p=Math.sqrt(y+1)*2,t[3]=.25*p,t[0]=(u-h)/p,t[1]=(f-c)/p,t[2]=(a-l)/p):s>d&&s>m?(p=Math.sqrt(1+s-d-m)*2,t[3]=(u-h)/p,t[0]=.25*p,t[1]=(a+l)/p,t[2]=(f+c)/p):d>m?(p=Math.sqrt(1+d-s-m)*2,t[3]=(f-c)/p,t[0]=(a+l)/p,t[1]=.25*p,t[2]=(u+h)/p):(p=Math.sqrt(1+m-s-d)*2,t[3]=(a-l)/p,t[0]=(f+c)/p,t[1]=(u+h)/p,t[2]=.25*p),t}function Ru(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 h=1/r[0],m=1/r[1],y=1/r[2],p=i*h,g=o*m,_=s*y,x=a*h,v=c*m,b=l*y,A=d*h,M=u*m,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-_)/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+_)/L):v>w?(L=Math.sqrt(1+v-p-w)*2,t[3]=(A-_)/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+_)/L,t[1]=(b+M)/L,t[2]=.25*L),t}function zu(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,h=i*d,m=o*l,y=o*d,p=s*d,g=a*c,_=a*l,x=a*d,v=n[0],b=n[1],A=n[2];return t[0]=(1-(m+p))*v,t[1]=(f+x)*v,t[2]=(h-_)*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]=(h+_)*A,t[9]=(y-g)*A,t[10]=(1-(u+m))*A,t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function Fu(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,h=o*d,m=o*u,y=s*d,p=s*u,g=a*u,_=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],O=(1-(y+g))*b,N=(h+v)*b,H=(m-x)*b,C=(h-v)*A,Q=(1-(f+g))*A,Se=(p+_)*A,Bt=(m+x)*M,oi=(p-_)*M,Vr=(1-(f+y))*M;return t[0]=O,t[1]=N,t[2]=H,t[3]=0,t[4]=C,t[5]=Q,t[6]=Se,t[7]=0,t[8]=Bt,t[9]=oi,t[10]=Vr,t[11]=0,t[12]=r[0]+w-(O*w+C*E+Bt*L),t[13]=r[1]+E-(N*w+Q*E+oi*L),t[14]=r[2]+L-(H*w+Se*E+Vr*L),t[15]=1,t}function Pu(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,h=i*a,m=i*c,y=o*s,p=o*a,g=o*c;return t[0]=1-u-m,t[1]=d+g,t[2]=f-p,t[3]=0,t[4]=d-g,t[5]=1-l-m,t[6]=h+y,t[7]=0,t[8]=f+p,t[9]=h-y,t[10]=1-l-u,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Bu(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 Ou=tl;function Du(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 Nu(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 ku=rl;function Uu(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 Hu(t,e,r,n){var i,o,s,a,c,l,d,u,f,h,m=e[0],y=e[1],p=e[2],g=n[0],_=n[1],x=n[2],v=r[0],b=r[1],A=r[2];return Math.abs(m-v)<j&&Math.abs(y-b)<j&&Math.abs(p-A)<j?Jc(t):(d=m-v,u=y-b,f=p-A,h=1/Math.sqrt(d*d+u*u+f*f),d*=h,u*=h,f*=h,i=_*f-x*u,o=x*d-g*f,s=g*u-_*d,h=Math.sqrt(i*i+o*o+s*s),h?(h=1/h,i*=h,o*=h,s*=h):(i=0,o=0,s=0),a=u*s-f*o,c=f*i-d*s,l=d*o-u*i,h=Math.sqrt(a*a+c*c+l*l),h?(h=1/h,a*=h,c*=h,l*=h):(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*m+o*y+s*p),t[13]=-(a*m+c*y+l*p),t[14]=-(d*m+u*y+f*p),t[15]=1,t)}function Vu(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],h=d*d+u*u+f*f;h>0&&(h=1/Math.sqrt(h),d*=h,u*=h,f*=h);var m=c*f-l*u,y=l*d-a*f,p=a*u-c*d;return h=m*m+y*y+p*p,h>0&&(h=1/Math.sqrt(h),m*=h,y*=h,p*=h),t[0]=m,t[1]=y,t[2]=p,t[3]=0,t[4]=u*p-f*y,t[5]=f*m-d*p,t[6]=d*y-u*m,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 Gu(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 Wu(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 Xu(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 Ku(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t[4]=e[4]*r,t[5]=e[5]*r,t[6]=e[6]*r,t[7]=e[7]*r,t[8]=e[8]*r,t[9]=e[9]*r,t[10]=e[10]*r,t[11]=e[11]*r,t[12]=e[12]*r,t[13]=e[13]*r,t[14]=e[14]*r,t[15]=e[15]*r,t}function Yu(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 qu(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 $u(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],h=t[11],m=t[12],y=t[13],p=t[14],g=t[15],_=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],O=e[9],N=e[10],H=e[11],C=e[12],Q=e[13],Se=e[14],Bt=e[15];return Math.abs(r-_)<=j*Math.max(1,Math.abs(r),Math.abs(_))&&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-O)<=j*Math.max(1,Math.abs(u),Math.abs(O))&&Math.abs(f-N)<=j*Math.max(1,Math.abs(f),Math.abs(N))&&Math.abs(h-H)<=j*Math.max(1,Math.abs(h),Math.abs(H))&&Math.abs(m-C)<=j*Math.max(1,Math.abs(m),Math.abs(C))&&Math.abs(y-Q)<=j*Math.max(1,Math.abs(y),Math.abs(Q))&&Math.abs(p-Se)<=j*Math.max(1,Math.abs(p),Math.abs(Se))&&Math.abs(g-Bt)<=j*Math.max(1,Math.abs(g),Math.abs(Bt))}var ju=Qc,Ju=nl;var se={};qo(se,{add:()=>rf,angle:()=>Lf,bezier:()=>xf,ceil:()=>nf,clone:()=>Qu,copy:()=>ef,create:()=>il,cross:()=>mf,dist:()=>Pf,distance:()=>ll,div:()=>Ff,divide:()=>cl,dot:()=>ea,equals:()=>Cf,exactEquals:()=>If,floor:()=>of,forEach:()=>Nf,fromValues:()=>Zu,hermite:()=>gf,inverse:()=>ff,len:()=>Of,length:()=>ol,lerp:()=>pf,max:()=>af,min:()=>sf,mul:()=>zf,multiply:()=>al,negate:()=>uf,normalize:()=>hf,random:()=>bf,rotateX:()=>Af,rotateY:()=>Mf,rotateZ:()=>wf,round:()=>cf,scale:()=>lf,scaleAndAdd:()=>df,set:()=>tf,slerp:()=>yf,sqrDist:()=>Bf,sqrLen:()=>Df,squaredDistance:()=>dl,squaredLength:()=>ul,str:()=>Tf,sub:()=>Rf,subtract:()=>sl,transformMat3:()=>_f,transformMat4:()=>vf,transformQuat:()=>Sf,zero:()=>Ef});function il(){var t=new Ue(3);return Ue!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function Qu(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 Zu(t,e,r){var n=new Ue(3);return n[0]=t,n[1]=e,n[2]=r,n}function ef(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function tf(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t}function rf(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 nf(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t[2]=Math.ceil(e[2]),t}function of(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t[2]=Math.floor(e[2]),t}function sf(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 af(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 cf(t,e){return t[0]=Mo(e[0]),t[1]=Mo(e[1]),t[2]=Mo(e[2]),t}function lf(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t}function df(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 uf(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t}function ff(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t}function hf(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 pf(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 yf(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 gf(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 xf(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 bf(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 vf(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 _f(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 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[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 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[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 wf(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 Lf(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 Ef(t){return t[0]=0,t[1]=0,t[2]=0,t}function Tf(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"}function If(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]}function Cf(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 Rf=sl,zf=al,Ff=cl,Pf=ll,Bf=dl,Of=ol,Df=ul,Nf=(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 h=se.fromValues(f[1]||0,f[2]||0,f[0]||0);ae.copy(this._viewMatrix,l),this._viewMatrix[12]=h[0],this._viewMatrix[13]=h[1],this._viewMatrix[14]=h[2],ae.multiply(this._viewProjectionMatrix,this._projectionMatrix,this._viewMatrix),this._dirty=!1}};var kf=[.2,.2,.2],Uf={x:0,y:0,z:1},Hf=[.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 Vf(t,e,r){let n=r?.ambient??kf,i=r?.directional??{direction:Uf,color:Hf},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 h=u.x-f.origin.x,m=u.y-f.origin.y,y=u.z-f.origin.z,p=h*h+m*m+y*y,g=f.radius*f.radius;if(p<g&&g>0){let _=1-Math.sqrt(p)/f.radius,x=Math.sqrt(p),v=x>0?Ur(-(h*o.x+m*o.y+y*o.z)/x):0,b=Ur(_*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)),h=Vf(f,u,n),m=c*12;s[m]=u.x,s[m+1]=u.y,s[m+2]=u.z,s[m+3]=f.x,s[m+4]=f.y,s[m+5]=f.z,s[m+6]=a.texCoord[0],s[m+7]=a.texCoord[1],s[m+8]=h[0],s[m+9]=h[1],s[m+10]=h[2],s[m+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)}),h=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}),m=[u,f,h];return{origin:a,axis:m,matrix:_a(a,m)}}var ia=`#version 300 es
366
+ }`;function ou(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 su(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:su(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 h=$c(u.position,f.position,o),m=ou($c(u.normal,f.normal,o)),y=d*8;c[y]=h.x,c[y+1]=h.y,c[y+2]=h.z,c[y+3]=m.x,c[y+4]=m.y,c[y+5]=m.z,c[y+6]=l.texCoord[0],c[y+7]=l.texCoord[1]}),c}var So=class{constructor(e,r,n){this.gl=e,this.geometry=Js(r),this.vertexBuffer=new _e(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,h=[1,1,1,1];l&&(l.mode==="solid"||l.mode==="wireframe"?f=1:l.mode==="solid-faceted"&&(f=2),l.color?h=[...l.color]:l.generateRandomColor),this.gl.uniform1i(this.uniformRenderMode,f),this.gl.uniform4f(this.uniformSolidColor,h[0],h[1],h[2],h[3]);let m=Math.min(c.length,Pt);this.gl.uniform1i(this.uniformNumDlights,m);for(let y=0;y<m;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 pg=Math.PI/180,yg=180/Math.PI;var ae={};qo(ae,{add:()=>Xu,adjoint:()=>mu,clone:()=>cu,copy:()=>lu,create:()=>au,decompose:()=>Ru,determinant:()=>pu,equals:()=>$u,exactEquals:()=>qu,frob:()=>Wu,fromQuat:()=>Pu,fromQuat2:()=>Tu,fromRotation:()=>Mu,fromRotationTranslation:()=>Zc,fromRotationTranslationScale:()=>zu,fromRotationTranslationScaleOrigin:()=>Fu,fromScaling:()=>Au,fromTranslation:()=>Su,fromValues:()=>du,fromXRotation:()=>wu,fromYRotation:()=>Lu,fromZRotation:()=>Eu,frustum:()=>Bu,getRotation:()=>Cu,getScaling:()=>el,getTranslation:()=>Iu,identity:()=>Jc,invert:()=>hu,lookAt:()=>Hu,mul:()=>ju,multiply:()=>Qc,multiplyScalar:()=>Ku,multiplyScalarAndAdd:()=>Yu,ortho:()=>ku,orthoNO:()=>rl,orthoZO:()=>Uu,perspective:()=>Ou,perspectiveFromFieldOfView:()=>Nu,perspectiveNO:()=>tl,perspectiveZO:()=>Du,rotate:()=>xu,rotateX:()=>bu,rotateY:()=>vu,rotateZ:()=>_u,scale:()=>gu,set:()=>uu,str:()=>Gu,sub:()=>Ju,subtract:()=>nl,targetTo:()=>Vu,translate:()=>yu,transpose:()=>fu});function au(){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 cu(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 lu(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 du(t,e,r,n,i,o,s,a,c,l,d,u,f,h,m,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]=h,p[14]=m,p[15]=y,p}function uu(t,e,r,n,i,o,s,a,c,l,d,u,f,h,m,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]=h,t[13]=m,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 fu(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 hu(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],h=e[11],m=e[12],y=e[13],p=e[14],g=e[15],_=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*m,E=d*p-f*m,L=d*g-h*m,O=u*p-f*y,N=u*g-h*y,H=f*g-h*p,C=_*H-x*N+v*O+b*L-A*E+M*w;return C?(C=1/C,t[0]=(a*H-c*N+l*O)*C,t[1]=(i*N-n*H-o*O)*C,t[2]=(y*M-p*A+g*b)*C,t[3]=(f*A-u*M-h*b)*C,t[4]=(c*L-s*H-l*E)*C,t[5]=(r*H-i*L+o*E)*C,t[6]=(p*v-m*M-g*x)*C,t[7]=(d*M-f*v+h*x)*C,t[8]=(s*N-a*L+l*w)*C,t[9]=(n*L-r*N-o*w)*C,t[10]=(m*A-y*v+g*_)*C,t[11]=(u*v-d*A-h*_)*C,t[12]=(a*E-s*O-c*w)*C,t[13]=(r*O-n*E+i*w)*C,t[14]=(y*x-m*b-p*_)*C,t[15]=(d*b-u*x+f*_)*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],h=e[11],m=e[12],y=e[13],p=e[14],g=e[15],_=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*m,E=d*p-f*m,L=d*g-h*m,O=u*p-f*y,N=u*g-h*y,H=f*g-h*p;return t[0]=a*H-c*N+l*O,t[1]=i*N-n*H-o*O,t[2]=y*M-p*A+g*b,t[3]=f*A-u*M-h*b,t[4]=c*L-s*H-l*E,t[5]=r*H-i*L+o*E,t[6]=p*v-m*M-g*x,t[7]=d*M-f*v+h*x,t[8]=s*N-a*L+l*w,t[9]=n*L-r*N-o*w,t[10]=m*A-y*v+g*_,t[11]=u*v-d*A-h*_,t[12]=a*E-s*O-c*w,t[13]=r*O-n*E+i*w,t[14]=y*x-m*b-p*_,t[15]=d*b-u*x+f*_,t}function pu(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],h=t[12],m=t[13],y=t[14],p=t[15],g=e*s-r*o,_=e*a-n*o,x=r*a-n*s,v=l*m-d*h,b=l*y-u*h,A=d*y-u*m,M=e*A-r*b+n*v,w=o*A-s*b+a*v,E=l*x-d*_+u*g,L=h*x-m*_+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],h=e[10],m=e[11],y=e[12],p=e[13],g=e[14],_=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*h+A*g,t[3]=x*s+v*d+b*m+A*_,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*h+A*g,t[7]=x*s+v*d+b*m+A*_,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*h+A*g,t[11]=x*s+v*d+b*m+A*_,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*h+A*g,t[15]=x*s+v*d+b*m+A*_,t}function yu(t,e,r){var n=r[0],i=r[1],o=r[2],s,a,c,l,d,u,f,h,m,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],h=e[7],m=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]=h,t[8]=m,t[9]=y,t[10]=p,t[11]=g,t[12]=s*n+d*i+m*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+h*i+g*o+e[15]),t}function gu(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 xu(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,h,m,y,p,g,_,x,v,b,A,M,w,E,L,O,N,H,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],h=e[2],m=e[3],y=e[4],p=e[5],g=e[6],_=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,O=o*o*d+l,N=s*o*d+i*c,H=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]=h*M+g*w+b*E,t[3]=m*M+_*w+A*E,t[4]=u*L+y*O+x*N,t[5]=f*L+p*O+v*N,t[6]=h*L+g*O+b*N,t[7]=m*L+_*O+A*N,t[8]=u*H+y*C+x*Q,t[9]=f*H+p*C+v*Q,t[10]=h*H+g*C+b*Q,t[11]=m*H+_*C+A*Q,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}function bu(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 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[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 _u(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 Au(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 Mu(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 wu(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 Lu(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 Eu(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,h=i*c,m=i*l,y=o*l,p=s*a,g=s*c,_=s*l;return t[0]=1-(h+y),t[1]=u+_,t[2]=f-g,t[3]=0,t[4]=u-_,t[5]=1-(d+y),t[6]=m+p,t[7]=0,t[8]=f+g,t[9]=m-p,t[10]=1-(d+h),t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function Tu(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 Iu(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 Cu(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,h=e[9]*i,m=e[10]*o,y=s+d+m,p=0;return y>0?(p=Math.sqrt(y+1)*2,t[3]=.25*p,t[0]=(u-h)/p,t[1]=(f-c)/p,t[2]=(a-l)/p):s>d&&s>m?(p=Math.sqrt(1+s-d-m)*2,t[3]=(u-h)/p,t[0]=.25*p,t[1]=(a+l)/p,t[2]=(f+c)/p):d>m?(p=Math.sqrt(1+d-s-m)*2,t[3]=(f-c)/p,t[0]=(a+l)/p,t[1]=.25*p,t[2]=(u+h)/p):(p=Math.sqrt(1+m-s-d)*2,t[3]=(a-l)/p,t[0]=(f+c)/p,t[1]=(u+h)/p,t[2]=.25*p),t}function Ru(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 h=1/r[0],m=1/r[1],y=1/r[2],p=i*h,g=o*m,_=s*y,x=a*h,v=c*m,b=l*y,A=d*h,M=u*m,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-_)/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+_)/L):v>w?(L=Math.sqrt(1+v-p-w)*2,t[3]=(A-_)/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+_)/L,t[1]=(b+M)/L,t[2]=.25*L),t}function zu(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,h=i*d,m=o*l,y=o*d,p=s*d,g=a*c,_=a*l,x=a*d,v=n[0],b=n[1],A=n[2];return t[0]=(1-(m+p))*v,t[1]=(f+x)*v,t[2]=(h-_)*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]=(h+_)*A,t[9]=(y-g)*A,t[10]=(1-(u+m))*A,t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function Fu(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,h=o*d,m=o*u,y=s*d,p=s*u,g=a*u,_=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],O=(1-(y+g))*b,N=(h+v)*b,H=(m-x)*b,C=(h-v)*A,Q=(1-(f+g))*A,Se=(p+_)*A,Bt=(m+x)*M,oi=(p-_)*M,Vr=(1-(f+y))*M;return t[0]=O,t[1]=N,t[2]=H,t[3]=0,t[4]=C,t[5]=Q,t[6]=Se,t[7]=0,t[8]=Bt,t[9]=oi,t[10]=Vr,t[11]=0,t[12]=r[0]+w-(O*w+C*E+Bt*L),t[13]=r[1]+E-(N*w+Q*E+oi*L),t[14]=r[2]+L-(H*w+Se*E+Vr*L),t[15]=1,t}function Pu(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,h=i*a,m=i*c,y=o*s,p=o*a,g=o*c;return t[0]=1-u-m,t[1]=d+g,t[2]=f-p,t[3]=0,t[4]=d-g,t[5]=1-l-m,t[6]=h+y,t[7]=0,t[8]=f+p,t[9]=h-y,t[10]=1-l-u,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Bu(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 Ou=tl;function Du(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 Nu(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 ku=rl;function Uu(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 Hu(t,e,r,n){var i,o,s,a,c,l,d,u,f,h,m=e[0],y=e[1],p=e[2],g=n[0],_=n[1],x=n[2],v=r[0],b=r[1],A=r[2];return Math.abs(m-v)<j&&Math.abs(y-b)<j&&Math.abs(p-A)<j?Jc(t):(d=m-v,u=y-b,f=p-A,h=1/Math.sqrt(d*d+u*u+f*f),d*=h,u*=h,f*=h,i=_*f-x*u,o=x*d-g*f,s=g*u-_*d,h=Math.sqrt(i*i+o*o+s*s),h?(h=1/h,i*=h,o*=h,s*=h):(i=0,o=0,s=0),a=u*s-f*o,c=f*i-d*s,l=d*o-u*i,h=Math.sqrt(a*a+c*c+l*l),h?(h=1/h,a*=h,c*=h,l*=h):(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*m+o*y+s*p),t[13]=-(a*m+c*y+l*p),t[14]=-(d*m+u*y+f*p),t[15]=1,t)}function Vu(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],h=d*d+u*u+f*f;h>0&&(h=1/Math.sqrt(h),d*=h,u*=h,f*=h);var m=c*f-l*u,y=l*d-a*f,p=a*u-c*d;return h=m*m+y*y+p*p,h>0&&(h=1/Math.sqrt(h),m*=h,y*=h,p*=h),t[0]=m,t[1]=y,t[2]=p,t[3]=0,t[4]=u*p-f*y,t[5]=f*m-d*p,t[6]=d*y-u*m,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 Gu(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 Wu(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 Xu(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 Ku(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t[4]=e[4]*r,t[5]=e[5]*r,t[6]=e[6]*r,t[7]=e[7]*r,t[8]=e[8]*r,t[9]=e[9]*r,t[10]=e[10]*r,t[11]=e[11]*r,t[12]=e[12]*r,t[13]=e[13]*r,t[14]=e[14]*r,t[15]=e[15]*r,t}function Yu(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 qu(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 $u(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],h=t[11],m=t[12],y=t[13],p=t[14],g=t[15],_=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],O=e[9],N=e[10],H=e[11],C=e[12],Q=e[13],Se=e[14],Bt=e[15];return Math.abs(r-_)<=j*Math.max(1,Math.abs(r),Math.abs(_))&&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-O)<=j*Math.max(1,Math.abs(u),Math.abs(O))&&Math.abs(f-N)<=j*Math.max(1,Math.abs(f),Math.abs(N))&&Math.abs(h-H)<=j*Math.max(1,Math.abs(h),Math.abs(H))&&Math.abs(m-C)<=j*Math.max(1,Math.abs(m),Math.abs(C))&&Math.abs(y-Q)<=j*Math.max(1,Math.abs(y),Math.abs(Q))&&Math.abs(p-Se)<=j*Math.max(1,Math.abs(p),Math.abs(Se))&&Math.abs(g-Bt)<=j*Math.max(1,Math.abs(g),Math.abs(Bt))}var ju=Qc,Ju=nl;var se={};qo(se,{add:()=>rf,angle:()=>Lf,bezier:()=>xf,ceil:()=>nf,clone:()=>Qu,copy:()=>ef,create:()=>il,cross:()=>mf,dist:()=>Pf,distance:()=>ll,div:()=>Ff,divide:()=>cl,dot:()=>ea,equals:()=>Cf,exactEquals:()=>If,floor:()=>of,forEach:()=>Nf,fromValues:()=>Zu,hermite:()=>gf,inverse:()=>ff,len:()=>Of,length:()=>ol,lerp:()=>pf,max:()=>af,min:()=>sf,mul:()=>zf,multiply:()=>al,negate:()=>uf,normalize:()=>hf,random:()=>bf,rotateX:()=>Af,rotateY:()=>Mf,rotateZ:()=>wf,round:()=>cf,scale:()=>lf,scaleAndAdd:()=>df,set:()=>tf,slerp:()=>yf,sqrDist:()=>Bf,sqrLen:()=>Df,squaredDistance:()=>dl,squaredLength:()=>ul,str:()=>Tf,sub:()=>Rf,subtract:()=>sl,transformMat3:()=>_f,transformMat4:()=>vf,transformQuat:()=>Sf,zero:()=>Ef});function il(){var t=new Ue(3);return Ue!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function Qu(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 Zu(t,e,r){var n=new Ue(3);return n[0]=t,n[1]=e,n[2]=r,n}function ef(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function tf(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t}function rf(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 nf(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t[2]=Math.ceil(e[2]),t}function of(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t[2]=Math.floor(e[2]),t}function sf(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 af(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 cf(t,e){return t[0]=Mo(e[0]),t[1]=Mo(e[1]),t[2]=Mo(e[2]),t}function lf(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t}function df(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 uf(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t}function ff(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t}function hf(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 pf(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 yf(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 gf(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 xf(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 bf(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 vf(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 _f(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 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[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 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[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 wf(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 Lf(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 Ef(t){return t[0]=0,t[1]=0,t[2]=0,t}function Tf(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"}function If(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]}function Cf(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 Rf=sl,zf=al,Ff=cl,Pf=ll,Bf=dl,Of=ol,Df=ul,Nf=(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 h=se.fromValues(f[1]||0,f[2]||0,f[0]||0);ae.copy(this._viewMatrix,l),this._viewMatrix[12]=h[0],this._viewMatrix[13]=h[1],this._viewMatrix[14]=h[2],ae.multiply(this._viewProjectionMatrix,this._projectionMatrix,this._viewMatrix),this._dirty=!1}};var kf=[.2,.2,.2],Uf={x:0,y:0,z:1},Hf=[.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 Vf(t,e,r){let n=r?.ambient??kf,i=r?.directional??{direction:Uf,color:Hf},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 h=u.x-f.origin.x,m=u.y-f.origin.y,y=u.z-f.origin.z,p=h*h+m*m+y*y,g=f.radius*f.radius;if(p<g&&g>0){let _=1-Math.sqrt(p)/f.radius,x=Math.sqrt(p),v=x>0?Ur(-(h*o.x+m*o.y+y*o.z)/x):0,b=Ur(_*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)),h=Vf(f,u,n),m=c*12;s[m]=u.x,s[m+1]=u.y,s[m+2]=u.z,s[m+3]=f.x,s[m+4]=f.y,s[m+5]=f.z,s[m+6]=a.texCoord[0],s[m+7]=a.texCoord[1],s[m+8]=h[0],s[m+9]=h[1],s[m+10]=h[2],s[m+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)}),h=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}),m=[u,f,h];return{origin:a,axis:m,matrix:_a(a,m)}}var ia=`#version 300 es
367
367
  precision highp float;
368
368
 
369
369
  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
- }`,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 _e(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 hl(t){let{system:e,origin:r,normal:n={x:0,y:0,z:1}}=t;for(let i=0;i<12;i+=1){let o=200+e.random()*180,s=e.random()*.35;e.spawn({position:r,velocity:{x:n.x*o+(e.random()-.5)*80,y:n.y*o+(e.random()-.5)*80,z:Math.max(n.z*o,120)+s*80},color:[1,.8,.4,1],size:2.5,lifetime:.45+e.random()*.1,gravity:600,damping:2,bounce:.45,blendMode:"additive",fade:!0})}for(let i=0;i<8;i+=1)e.spawn({position:r,velocity:{x:(e.random()-.5)*40,y:(e.random()-.5)*40,z:80+e.random()*40},color:[.45,.45,.45,.75],size:6,lifetime:.6,gravity:200,damping:4,bounce:.15,blendMode:"alpha",fade:!0})}function ml(t){let{system:e,origin:r}=t;for(let n=0;n<40;n+=1){let i=e.random()*Math.PI*2,o=Math.acos(2*e.random()-1),s=220+e.random()*260,a={x:Math.sin(o)*Math.cos(i),y:Math.sin(o)*Math.sin(i),z:Math.cos(o)};e.spawn({position:r,velocity:{x:a.x*s,y:a.y*s,z:a.z*s},color:[1,.6,.2,1],size:5,lifetime:.9,gravity:700,damping:1,bounce:.35,blendMode:"additive",fade:!0})}for(let n=0;n<16;n+=1)e.spawn({position:r,velocity:{x:(e.random()-.5)*30,y:(e.random()-.5)*30,z:120+e.random()*120},color:[.25,.25,.25,.9],size:12,lifetime:1.2,gravity:300,damping:3,blendMode:"alpha",fade:!0})}function 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,Wf=128,Xf=256,Do=512,No=1024,ko=2048,Qn=4096,Zn=16384,Kf=32768,ei=65536,Uo=1<<17,ti=1<<18,ri=1<<19,Ho=1<<20,Vo=1<<21,Go=1<<22,Yf=1<<23,Wo=1<<24,ni=1<<25,Xo=1<<26,Ko=1<<27,bl=8192;var qf=1,$f=2,jf=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,alpha:0,scale:0,instanceBits:0,loopVolume:0,loopAttenuation:0,owner:0,oldFrame: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),gunskin:0,gunrate:0,damage_blend:[0,0,0,0],team_id:0}),nr=class{constructor(e,r){this.protocolVersion=0;this.isDemo=qf;this.stream=e,this.handler=r}translateCommand(e){if(this.protocolVersion===0){if(e===7)return R.serverdata;if(e===12)return R.serverdata}if(this.protocolVersion===25){if(e>=7&&e<=15)return e+5;if(e===1)return R.print;if(e===2)return R.stufftext;if(e===3)return R.sound;if(e===4)return R.nop;if(e===5)return R.disconnect;if(e===6)return R.reconnect;if(e===16)return R.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 R.nop:break;case R.disconnect:this.handler&&this.handler.onDisconnect&&this.handler.onDisconnect();break;case R.reconnect:this.handler&&this.handler.onReconnect&&this.handler.onReconnect();break;case R.print:this.parsePrint();break;case R.serverdata:this.parseServerData();break;case R.configstring:this.parseConfigString();break;case R.spawnbaseline:this.parseSpawnBaseline();break;case R.centerprint:this.parseCenterPrint();break;case R.download:this.parseDownload();break;case R.frame:this.parseFrame();break;case R.packetentities:this.parsePacketEntities(!1);break;case R.deltapacketentities:this.parsePacketEntities(!0);break;case R.playerinfo:this.parsePlayerState();break;case R.stufftext:this.parseStuffText();break;case R.layout:this.parseLayout();break;case R.inventory:this.parseInventory();break;case R.sound:this.parseSound();break;case R.muzzleflash:this.parseMuzzleFlash();break;case R.muzzleflash2:this.parseMuzzleFlash2();break;case R.temp_entity:this.parseTempEntity();break;case R.splitclient:break;case R.configblast:break;case R.spawnbaselineblast:break;case R.level_restart:this.handler&&this.handler.onLevelRestart&&this.handler.onLevelRestart();break;case R.damage:break;case R.locprint:break;case R.fog:break;case R.waitingforplayers:this.handler&&this.handler.onWaitingForPlayers&&this.handler.onWaitingForPlayers();break;case R.bot_chat:break;case R.poi:break;case R.help_path:break;case R.muzzleflash3:this.parseMuzzleFlash3();break;case R.achievement: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();this.handler&&this.handler.onPrint(e,r)}parseStuffText(){let e=this.stream.readString();this.handler&&this.handler.onStuffText(e)}parseLayout(){let e=this.stream.readString();this.handler&&this.handler.onLayout(e)}parseCenterPrint(){let e=this.stream.readString();this.handler&&this.handler.onCenterPrint(e)}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)}parseMuzzleFlash3(){let e=this.stream.readShort(),r=this.stream.readShort();this.handler&&this.handler.onMuzzleFlash3&&this.handler.onMuzzleFlash3(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!==R.playerinfo)throw new Error(`Expected svc_playerinfo after svc_frame, got ${s}`);let a=this.parsePlayerState();if(this.isDemo===jf){let c=this.stream.readByte();for(let l=0;l<c;l++)this.stream.readByte()}this.isDemo===$f&&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&Wf&&(e|=this.stream.readByte()<<8),e&Kf&&(e|=this.stream.readByte()<<16),e&Yf&&(e|=this.stream.readByte()<<24);let r;return e&Xf?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 Il(Qf);})();
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 _e(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 hl(t){let{system:e,origin:r,normal:n={x:0,y:0,z:1}}=t;for(let i=0;i<12;i+=1){let o=200+e.random()*180,s=e.random()*.35;e.spawn({position:r,velocity:{x:n.x*o+(e.random()-.5)*80,y:n.y*o+(e.random()-.5)*80,z:Math.max(n.z*o,120)+s*80},color:[1,.8,.4,1],size:2.5,lifetime:.45+e.random()*.1,gravity:600,damping:2,bounce:.45,blendMode:"additive",fade:!0})}for(let i=0;i<8;i+=1)e.spawn({position:r,velocity:{x:(e.random()-.5)*40,y:(e.random()-.5)*40,z:80+e.random()*40},color:[.45,.45,.45,.75],size:6,lifetime:.6,gravity:200,damping:4,bounce:.15,blendMode:"alpha",fade:!0})}function ml(t){let{system:e,origin:r}=t;for(let n=0;n<40;n+=1){let i=e.random()*Math.PI*2,o=Math.acos(2*e.random()-1),s=220+e.random()*260,a={x:Math.sin(o)*Math.cos(i),y:Math.sin(o)*Math.sin(i),z:Math.cos(o)};e.spawn({position:r,velocity:{x:a.x*s,y:a.y*s,z:a.z*s},color:[1,.6,.2,1],size:5,lifetime:.9,gravity:700,damping:1,bounce:.35,blendMode:"additive",fade:!0})}for(let n=0;n<16;n+=1)e.spawn({position:r,velocity:{x:(e.random()-.5)*30,y:(e.random()-.5)*30,z:120+e.random()*120},color:[.25,.25,.25,.9],size:12,lifetime:1.2,gravity:300,damping:3,blendMode:"alpha",fade:!0})}function 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 Wf=2023,Ro=1,zo=2,Fo=4,Po=8,Bo=16,Oo=32,ca=64,Xf=128,Kf=256,Do=512,No=1024,ko=2048,Qn=4096,Zn=16384,Yf=32768,ei=65536,Uo=1<<17,ti=1<<18,ri=1<<19,Ho=1<<20,Vo=1<<21,Go=1<<22,qf=1<<23,Wo=1<<24,ni=1<<25,Xo=1<<26,Ko=1<<27,bl=8192;var $f=1,jf=2,Jf=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,alpha:0,scale:0,instanceBits:0,loopVolume:0,loopAttenuation:0,owner:0,oldFrame: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),gunskin:0,gunrate:0,damage_blend:[0,0,0,0],team_id:0}),nr=class{constructor(e,r){this.protocolVersion=0;this.isDemo=$f;this.stream=e,this.handler=r}translateCommand(e){if(this.protocolVersion===0){if(e===7)return R.serverdata;if(e===12)return R.serverdata}if(this.protocolVersion===25){if(e>=7&&e<=15)return e+5;if(e===1)return R.print;if(e===2)return R.stufftext;if(e===3)return R.sound;if(e===4)return R.nop;if(e===5)return R.disconnect;if(e===6)return R.reconnect;if(e===16)return R.temp_entity}return this.protocolVersion===Wf,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 R.nop:break;case R.disconnect:this.handler&&this.handler.onDisconnect&&this.handler.onDisconnect();break;case R.reconnect:this.handler&&this.handler.onReconnect&&this.handler.onReconnect();break;case R.print:this.parsePrint();break;case R.serverdata:this.parseServerData();break;case R.configstring:this.parseConfigString();break;case R.spawnbaseline:this.parseSpawnBaseline();break;case R.centerprint:this.parseCenterPrint();break;case R.download:this.parseDownload();break;case R.frame:this.parseFrame();break;case R.packetentities:this.parsePacketEntities(!1);break;case R.deltapacketentities:this.parsePacketEntities(!0);break;case R.playerinfo:this.parsePlayerState();break;case R.stufftext:this.parseStuffText();break;case R.layout:this.parseLayout();break;case R.inventory:this.parseInventory();break;case R.sound:this.parseSound();break;case R.muzzleflash:this.parseMuzzleFlash();break;case R.muzzleflash2:this.parseMuzzleFlash2();break;case R.temp_entity:this.parseTempEntity();break;case R.splitclient:break;case R.configblast:break;case R.spawnbaselineblast:break;case R.level_restart:this.handler&&this.handler.onLevelRestart&&this.handler.onLevelRestart();break;case R.damage:break;case R.locprint:break;case R.fog:break;case R.waitingforplayers:this.handler&&this.handler.onWaitingForPlayers&&this.handler.onWaitingForPlayers();break;case R.bot_chat:break;case R.poi:break;case R.help_path:break;case R.muzzleflash3:this.parseMuzzleFlash3();break;case R.achievement: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();this.handler&&this.handler.onPrint(e,r)}parseStuffText(){let e=this.stream.readString();this.handler&&this.handler.onStuffText(e)}parseLayout(){let e=this.stream.readString();this.handler&&this.handler.onLayout(e)}parseCenterPrint(){let e=this.stream.readString();this.handler&&this.handler.onCenterPrint(e)}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)}parseMuzzleFlash3(){let e=this.stream.readShort(),r=this.stream.readShort();this.handler&&this.handler.onMuzzleFlash3&&this.handler.onMuzzleFlash3(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!==R.playerinfo)throw new Error(`Expected svc_playerinfo after svc_frame, got ${s}`);let a=this.parsePlayerState();if(this.isDemo===Jf){let c=this.stream.readByte();for(let l=0;l<c;l++)this.stream.readByte()}this.isDemo===jf&&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&Xf&&(e|=this.stream.readByte()<<8),e&Yf&&(e|=this.stream.readByte()<<16),e&qf&&(e|=this.stream.readByte()<<24);let r;return e&Kf?r=this.stream.readShort():r=this.stream.readByte(),{number:r,bits:e}}parseDelta(e,r,n,i){r.number=e.number,r.modelindex=e.modelindex,r.modelindex2=e.modelindex2,r.modelindex3=e.modelindex3,r.modelindex4=e.modelindex4,r.frame=e.frame,r.skinnum=e.skinnum,r.effects=e.effects,r.renderfx=e.renderfx,r.origin.x=e.origin.x,r.origin.y=e.origin.y,r.origin.z=e.origin.z,r.old_origin.x=e.origin.x,r.old_origin.y=e.origin.y,r.old_origin.z=e.origin.z,r.angles.x=e.angles.x,r.angles.y=e.angles.y,r.angles.z=e.angles.z,r.sound=e.sound,r.event=e.event,r.solid=e.solid,r.number=n,r.bits=i,i&ko&&(r.modelindex=this.stream.readByte()),i&Ho&&(r.modelindex2=this.stream.readByte()),i&Vo&&(r.modelindex3=this.stream.readByte()),i&Go&&(r.modelindex4=this.stream.readByte()),i&Bo&&(r.frame=this.stream.readByte()),i&Uo&&(r.frame=this.stream.readShort()),i&ei&&i&ni?r.skinnum=this.stream.readLong():i&ei?r.skinnum=this.stream.readByte():i&ni&&(r.skinnum=this.stream.readShort()),i&Zn&&i&ri?r.effects=this.stream.readLong():i&Zn?r.effects=this.stream.readByte():i&ri&&(r.effects=this.stream.readShort()),i&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 Qf(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(Zf);})();
450
450
  //# sourceMappingURL=index.global.js.map