quake2ts 0.0.427 → 0.0.429

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 of=Object.create;var xs=Object.defineProperty;var af=Object.getOwnPropertyDescriptor;var lf=Object.getOwnPropertyNames;var cf=Object.getPrototypeOf,df=Object.prototype.hasOwnProperty;var uf=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),aa=(e,t)=>{for(var r in t)xs(e,r,{get:t[r],enumerable:!0})},Bc=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of lf(t))!df.call(e,i)&&i!==r&&xs(e,i,{get:()=>t[i],enumerable:!(n=af(t,i))||n.enumerable});return e};var ff=(e,t,r)=>(r=e!=null?of(cf(e)):{},Bc(t||!e||!e.__esModule?xs(r,"default",{value:e,enumerable:!0}):r,e)),hf=e=>Bc(xs({},"__esModule",{value:!0}),e);var bd=uf((d_,xd)=>{"use strict";xd.exports=Worker});var Ox={};aa(Ox,{ATTN_IDLE:()=>Aa,ATTN_LOOP_NONE:()=>Sa,ATTN_NONE:()=>Nn,ATTN_NORM:()=>wa,ATTN_STATIC:()=>Ms,AssetDependencyError:()=>Tr,AssetDependencyTracker:()=>Vi,AssetManager:()=>po,AssetPreviewGenerator:()=>sa,AudioApi:()=>Xr,AudioContextController:()=>go,AudioRegistry:()=>gn,AudioRegistryError:()=>Ni,AudioSystem:()=>wo,BSP_SURFACE_FRAGMENT_SOURCE:()=>al,BSP_SURFACE_VERTEX_SOURCE:()=>ol,BSP_VERTEX_LAYOUT:()=>nl,BspLoader:()=>Kr,BspParseError:()=>Q,BspSurfacePipeline:()=>To,Camera:()=>zo,Command:()=>kn,CommandRegistry:()=>Nr,ConfigStringRegistry:()=>Wr,Cvar:()=>Hn,CvarRegistry:()=>Vr,DemoPlaybackController:()=>us,DemoReader:()=>Ct,DemoRecorder:()=>fs,DemoValidator:()=>ia,DynamicLightManager:()=>Eo,EngineHost:()=>Gr,EngineRuntime:()=>Vn,FileType:()=>Ec,FixedTimestepLoop:()=>ur,Framebuffer:()=>Mo,IndexBuffer:()=>xe,LruCache:()=>Nt,MAX_SOUND_CHANNELS:()=>On,MD2_FRAGMENT_SHADER:()=>ml,MD2_VERTEX_SHADER:()=>hl,MD3_FRAGMENT_SHADER:()=>wl,MD3_VERTEX_SHADER:()=>Sl,MapAnalyzer:()=>oa,Md2Loader:()=>Zr,Md2MeshBuffers:()=>Co,Md2ParseError:()=>pe,Md2Pipeline:()=>Ro,Md3Loader:()=>Yr,Md3ModelMesh:()=>ko,Md3ParseError:()=>Ge,Md3Pipeline:()=>Do,Md3SurfaceMesh:()=>Xi,MusicSystem:()=>Ao,NetworkMessageParser:()=>kt,PARTICLE_FRAGMENT_SHADER:()=>Ml,PARTICLE_VERTEX_SHADER:()=>Al,PROTOCOL_VERSION_RERELEASE:()=>Rn,PakArchive:()=>$r,PakIndexStore:()=>mo,PakIngestionError:()=>Ot,PakParseError:()=>Ve,PakValidationError:()=>fr,PakValidator:()=>Es,ParticleRenderer:()=>Bo,ParticleSystem:()=>Po,PlaybackState:()=>na,RERELEASE_KNOWN_PAKS:()=>La,SKYBOX_FRAGMENT_SHADER:()=>ul,SKYBOX_VERTEX_SHADER:()=>dl,SOUND_FULLVOLUME:()=>Pt,SOUND_LOOP_ATTENUATE:()=>Ma,ShaderProgram:()=>Le,SkyboxPipeline:()=>Io,SoundChannel:()=>st,SoundPrecache:()=>bo,SoundRegistry:()=>xo,SpriteLoader:()=>qr,SpriteParseError:()=>Ut,Texture2D:()=>yn,TextureCache:()=>jr,TextureCubeMap:()=>xn,TgaParseError:()=>yt,U_ALPHA:()=>hc,U_ANGLE1:()=>uc,U_ANGLE2:()=>sc,U_ANGLE3:()=>oc,U_EFFECTS16:()=>ea,U_EFFECTS8:()=>jo,U_EVENT:()=>lc,U_FRAME16:()=>mc,U_FRAME8:()=>ac,U_INSTANCE_BITS:()=>Sc,U_LOOP_ATTENUATION_HIGH:()=>Ac,U_LOOP_VOLUME:()=>wc,U_MODEL:()=>fc,U_MODEL2:()=>pc,U_MODEL3:()=>gc,U_MODEL4:()=>yc,U_OLDORIGIN:()=>xc,U_OLD_FRAME_HIGH:()=>Lc,U_ORIGIN1:()=>nc,U_ORIGIN2:()=>ic,U_ORIGIN3:()=>dc,U_OWNER_HIGH:()=>Mc,U_REMOVE:()=>cc,U_RENDERFX16:()=>Jo,U_RENDERFX8:()=>qo,U_SCALE:()=>vc,U_SKIN16:()=>ta,U_SKIN8:()=>Qo,U_SOLID:()=>_c,U_SOUND:()=>bc,VertexArray:()=>Fe,VertexBuffer:()=>Ee,VirtualFileSystem:()=>Ls,advanceAnimation:()=>hd,applySurfaceState:()=>ou,attenuationToDistanceMultiplier:()=>Bt,boxIntersectsFrustum:()=>Wi,buildBspGeometry:()=>Jd,buildMd2Geometry:()=>pl,buildMd2VertexData:()=>gl,buildMd3SurfaceGeometry:()=>_l,buildMd3VertexData:()=>vl,calculateMaxAudibleDistance:()=>Un,calculatePakChecksum:()=>td,computeFrameBlend:()=>md,computeSkyScroll:()=>cu,createAnimationState:()=>pd,createAudioGraph:()=>yo,createBspSurfaces:()=>Qd,createEmptyEntityState:()=>Br,createEmptyProtocolPlayerState:()=>ds,createEngine:()=>Bx,createEngineRuntime:()=>Jc,createFaceLightmap:()=>Is,createInitialChannels:()=>_o,createProgramFromSources:()=>jd,createWebGLContext:()=>Yd,decodeOgg:()=>ho,deriveSurfaceRenderState:()=>cl,detectFileType:()=>Tc,extractFrustumPlanes:()=>eu,filesToPakSources:()=>Ea,findLeafForPoint:()=>sl,gatherVisibleFaces:()=>iu,groupMd2Animations:()=>cd,ingestPakFiles:()=>rd,ingestPaks:()=>Ts,interpolateMd3Tag:()=>Eu,interpolateVec3:()=>gd,isBinaryFile:()=>tf,isTextFile:()=>Ic,parseBsp:()=>Gn,parseMd2:()=>Ta,parseMd3:()=>Ia,parsePcx:()=>Kn,parseSprite:()=>Ca,parseTga:()=>Ra,parseWal:()=>Rs,parseWalTexture:()=>ks,parseWav:()=>Ds,pcxToRgba:()=>Fs,pickChannel:()=>vo,preparePcxTexture:()=>zs,removeViewTranslation:()=>lu,resolveLightStyles:()=>ll,spatializeOrigin:()=>So,spawnBlood:()=>Cu,spawnBulletImpact:()=>Tu,spawnExplosion:()=>Iu,spawnMuzzleFlash:()=>Fu,spawnTeleportFlash:()=>Ru,spawnTrail:()=>zu,walToRgba:()=>Fa,wireDropTarget:()=>nd,wireFileInput:()=>id});var mf=()=>typeof performance<"u"?performance.now():Date.now(),pf=e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>e()):setTimeout(e,25)},ur=class{constructor(t,r={}){this.callbacks=t;this.accumulatorMs=0;this.frame=0;this.running=!1;this.tick=()=>{if(!this.running)return;let t=this.options.now(),r=this.lastTimeMs===void 0?0:t-this.lastTimeMs;this.lastTimeMs=t,this.advance(r,t),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??mf,schedule:r.schedule??pf}}start(){this.running||(this.running=!0,this.lastTimeMs=this.options.startTimeMs??this.options.now(),this.options.schedule(this.tick))}stop(){this.running=!1}pump(t){let r=(this.lastTimeMs??0)+t;this.lastTimeMs=r,this.advance(t,r)}isRunning(){return this.running}get frameNumber(){return this.frame}advance(t,r){let n=Math.min(Math.max(t,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 s=this.options.fixedDeltaMs===0?0:this.accumulatorMs/this.options.fixedDeltaMs;this.callbacks.render?.({alpha:s,nowMs:r,accumulatorMs:this.accumulatorMs,frame:this.frame})}};var kn=class{constructor(t,r,n){this.name=t,this.callback=r,this.description=n}execute(t){this.callback(t)}},Nr=class{constructor(){this.commands=new Map}register(t,r,n){let i=new kn(t,r,n);return this.commands.set(t,i),i}registerCommand(t,r){this.register(t,r)}get(t){return this.commands.get(t)}execute(t){let r=this.tokenize(t);if(r.length===0)return!1;let n=r[0],i=r.slice(1),s=this.get(n);return s?(s.execute(i),!0):(this.onConsoleOutput?.(`Unknown command "${n}"`),!1)}executeCommand(t){this.execute(t)}tokenize(t){let r=[],n="",i=!1;for(let s=0;s<t.length;s++){let o=t[s];o==='"'?i=!i:o===" "&&!i?n.length>0&&(r.push(n),n=""):n+=o}return n.length>0&&r.push(n),r}list(){return[...this.commands.values()].sort((t,r)=>t.name.localeCompare(r.name))}};var gf=Object.defineProperty,Oc=(e,t)=>{for(var r in t)gf(e,r,{get:t[r],enumerable:!0})},Nc={x:0,y:0,z:0};var Vx=Math.PI/180;function Uc(e,t){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}function yf(e,t){return{x:e.x*t,y:e.y*t,z:e.z*t}}function da(e,t){return e.x*t.x+e.y*t.y+e.z*t.z}function xf(e){return da(e,e)}function ua(e){return Math.sqrt(xf(e))}function Je(e){let t=ua(e);return t===0?e:yf(e,1/t)}var bf=Math.PI/180,_f=180/Math.PI,Hr=bf,fa=_f;var ca=[[-.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 vf(){return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function Hc(e,t){let r=t.x,n=t.y,i=t.z;return{x:e[0]*r+e[4]*n+e[8]*i+e[12],y:e[1]*r+e[5]*n+e[9]*i+e[13],z:e[2]*r+e[6]*n+e[10]*i+e[14]}}function Vc(e,t){let r=vf();return r[0]=t[0].x,r[1]=t[0].y,r[2]=t[0].z,r[4]=t[1].x,r[5]=t[1].y,r[6]=t[1].z,r[8]=t[2].x,r[9]=t[2].y,r[10]=t[2].z,r[12]=e.x,r[13]=e.y,r[14]=e.z,r}var it=1,Dt=2;var ha=8,ma=16,Sf=32;var wf=16384;var bs=65536,Gc=1<<17,Af=1<<18,Mf=1<<19,Lf=1<<20,Ef=1<<21,Tf=1<<22,If=1<<23,Gx=1<<24,_s=1<<25,Cf=1<<26,Wx=1<<27,Xx=1<<28,$x=1<<29,vs=1<<30,Kx=1<<31;var Pn=0;var Wc=4,Xc=8,$c=16,Kc=32,Zc=64;var Zx=1<<25,Yx=1<<28,qx=1<<29,jx=1<<30,Qx=1<<31;var Jx=it|Dt,eb=it|bs|Dt|_s|vs,tb=it|bs|Dt,rb=it|Gc|Dt|_s|vs,nb=Sf|ha|ma,ib=it|ma|ha,Rf=it|_s|vs|Dt|Cf,sb=Af|Mf|Lf|Ef|Tf|If,ob=it|ha|ma|_s|vs,ab=it|bs|Dt,lb=it|Dt,cb=it|bs|Dt|Gc,db=Rf|wf;var ub=Number.MAX_SAFE_INTEGER-1;var Ss=(e=>(e[e.None=0]="None",e[e.Archive=1]="Archive",e[e.UserInfo=2]="UserInfo",e[e.ServerInfo=4]="ServerInfo",e[e.Latch=8]="Latch",e[e.Cheat=16]="Cheat",e))(Ss||{});var ws=256;var pa=256,ga=8192,As=2048,ya=512,xa=256,ba=ws*2,_a=256,la=32,Dn=96;var j=(e=>(e[e.Name=0]="Name",e[e.CdTrack=1]="CdTrack",e[e.Sky=2]="Sky",e[e.SkyAxis=3]="SkyAxis",e[e.SkyRotate=4]="SkyRotate",e[e.StatusBar=5]="StatusBar",e[e.HealthBarName=55]="HealthBarName",e[e.CONFIG_N64_PHYSICS=56]="CONFIG_N64_PHYSICS",e[e.CONFIG_CTF_TEAMS=57]="CONFIG_CTF_TEAMS",e[e.CONFIG_COOP_RESPAWN_STRING=58]="CONFIG_COOP_RESPAWN_STRING",e[e.Story=54]="Story",e[e.AirAccel=59]="AirAccel",e[e.MaxClients=60]="MaxClients",e[e.MapChecksum=61]="MapChecksum",e[e.Models=62]="Models",e[e.Sounds=62+ga]="Sounds",e[e.Images=e.Sounds+As]="Images",e[e.Lights=e.Images+ya]="Lights",e[e.ShadowLights=e.Lights+pa]="ShadowLights",e[e.Items=e.ShadowLights+_a]="Items",e[e.PlayerSkins=e.Items+xa]="PlayerSkins",e[e.General=e.PlayerSkins+ws]="General",e[e.WheelWeapons=e.General+ba]="WheelWeapons",e[e.WheelAmmo=e.WheelWeapons+la]="WheelAmmo",e[e.WheelPowerups=e.WheelAmmo+la]="WheelPowerups",e[e.CdLoopCount=e.WheelPowerups+la]="CdLoopCount",e[e.GameStyle=e.CdLoopCount+1]="GameStyle",e[e.MaxConfigStrings=e.GameStyle+1]="MaxConfigStrings",e))(j||{}),Yc=j.MaxConfigStrings;function qc(e){return e>=5&&e<59?Dn*(59-e):e>=j.General&&e<j.WheelWeapons?Dn*(j.MaxConfigStrings-e):Dn}var Ff={};Oc(Ff,{addReplayFrame:()=>Pf,createReplaySession:()=>Df,deserializeReplay:()=>kf,serializeReplay:()=>zf});function zf(e){return JSON.stringify(e,null,2)}function kf(e){let t=JSON.parse(e);if(!t.metadata||!Array.isArray(t.frames))throw new Error("Invalid replay format: missing metadata or frames");return t}function Df(e,t){return{metadata:{map:e,date:new Date().toISOString(),version:"1.0",seed:t},frames:[]}}function Pf(e,t,r,n){e.frames.push({serverFrame:r,cmd:t,timestamp:Date.now()-n})}var z=(e=>(e[e.bad=0]="bad",e[e.muzzleflash=1]="muzzleflash",e[e.muzzleflash2=2]="muzzleflash2",e[e.temp_entity=3]="temp_entity",e[e.layout=4]="layout",e[e.inventory=5]="inventory",e[e.nop=6]="nop",e[e.disconnect=7]="disconnect",e[e.reconnect=8]="reconnect",e[e.sound=9]="sound",e[e.print=10]="print",e[e.stufftext=11]="stufftext",e[e.serverdata=12]="serverdata",e[e.configstring=13]="configstring",e[e.spawnbaseline=14]="spawnbaseline",e[e.centerprint=15]="centerprint",e[e.download=16]="download",e[e.playerinfo=17]="playerinfo",e[e.packetentities=18]="packetentities",e[e.deltapacketentities=19]="deltapacketentities",e[e.frame=20]="frame",e[e.splitclient=21]="splitclient",e[e.configblast=22]="configblast",e[e.spawnbaselineblast=23]="spawnbaselineblast",e[e.level_restart=24]="level_restart",e[e.damage=25]="damage",e[e.locprint=26]="locprint",e[e.fog=27]="fog",e[e.waitingforplayers=28]="waitingforplayers",e[e.bot_chat=29]="bot_chat",e[e.poi=30]="poi",e[e.help_path=31]="help_path",e[e.muzzleflash3=32]="muzzleflash3",e[e.achievement=33]="achievement",e))(z||{});var I=(e=>(e[e.GUNSHOT=0]="GUNSHOT",e[e.BLOOD=1]="BLOOD",e[e.BLASTER=2]="BLASTER",e[e.RAILTRAIL=3]="RAILTRAIL",e[e.SHOTGUN=4]="SHOTGUN",e[e.EXPLOSION1=5]="EXPLOSION1",e[e.EXPLOSION2=6]="EXPLOSION2",e[e.ROCKET_EXPLOSION=7]="ROCKET_EXPLOSION",e[e.GRENADE_EXPLOSION=8]="GRENADE_EXPLOSION",e[e.SPARKS=9]="SPARKS",e[e.SPLASH=10]="SPLASH",e[e.BUBBLETRAIL=11]="BUBBLETRAIL",e[e.SCREEN_SPARKS=12]="SCREEN_SPARKS",e[e.SHIELD_SPARKS=13]="SHIELD_SPARKS",e[e.BULLET_SPARKS=14]="BULLET_SPARKS",e[e.LASER_SPARKS=15]="LASER_SPARKS",e[e.PARASITE_ATTACK=16]="PARASITE_ATTACK",e[e.ROCKET_EXPLOSION_WATER=17]="ROCKET_EXPLOSION_WATER",e[e.GRENADE_EXPLOSION_WATER=18]="GRENADE_EXPLOSION_WATER",e[e.MEDIC_CABLE_ATTACK=19]="MEDIC_CABLE_ATTACK",e[e.BFG_EXPLOSION=20]="BFG_EXPLOSION",e[e.BFG_BIGEXPLOSION=21]="BFG_BIGEXPLOSION",e[e.BOSSTPORT=22]="BOSSTPORT",e[e.BFG_LASER=23]="BFG_LASER",e[e.GRAPPLE_CABLE=24]="GRAPPLE_CABLE",e[e.WELDING_SPARKS=25]="WELDING_SPARKS",e[e.GREENBLOOD=26]="GREENBLOOD",e[e.BLUEHYPERBLASTER=27]="BLUEHYPERBLASTER",e[e.PLASMA_EXPLOSION=28]="PLASMA_EXPLOSION",e[e.TUNNEL_SPARKS=29]="TUNNEL_SPARKS",e[e.BLASTER2=30]="BLASTER2",e[e.RAILTRAIL2=31]="RAILTRAIL2",e[e.FLAME=32]="FLAME",e[e.LIGHTNING=33]="LIGHTNING",e[e.DEBUGTRAIL=34]="DEBUGTRAIL",e[e.PLAIN_EXPLOSION=35]="PLAIN_EXPLOSION",e[e.FLASHLIGHT=36]="FLASHLIGHT",e[e.FORCEWALL=37]="FORCEWALL",e[e.HEATBEAM=38]="HEATBEAM",e[e.MONSTER_HEATBEAM=39]="MONSTER_HEATBEAM",e[e.STEAM=40]="STEAM",e[e.BUBBLETRAIL2=41]="BUBBLETRAIL2",e[e.MOREBLOOD=42]="MOREBLOOD",e[e.HEATBEAM_SPARKS=43]="HEATBEAM_SPARKS",e[e.HEATBEAM_STEAM=44]="HEATBEAM_STEAM",e[e.CHAINFIST_SMOKE=45]="CHAINFIST_SMOKE",e[e.ELECTRIC_SPARKS=46]="ELECTRIC_SPARKS",e[e.TRACKER_EXPLOSION=47]="TRACKER_EXPLOSION",e[e.TELEPORT_EFFECT=48]="TELEPORT_EFFECT",e[e.DBALL_GOAL=49]="DBALL_GOAL",e[e.WIDOWBEAMOUT=50]="WIDOWBEAMOUT",e[e.NUKEBLAST=51]="NUKEBLAST",e[e.WIDOWSPLASH=52]="WIDOWSPLASH",e[e.EXPLOSION1_BIG=53]="EXPLOSION1_BIG",e[e.EXPLOSION1_NP=54]="EXPLOSION1_NP",e[e.FLECHETTE=55]="FLECHETTE",e[e.BLUEHYPERBLASTER_KEX=56]="BLUEHYPERBLASTER_KEX",e[e.BFG_ZAP=57]="BFG_ZAP",e[e.BERSERK_SLAM=58]="BERSERK_SLAM",e[e.GRAPPLE_CABLE_2=59]="GRAPPLE_CABLE_2",e[e.POWER_SPLASH=60]="POWER_SPLASH",e[e.LIGHTNING_BEAM=61]="LIGHTNING_BEAM",e[e.EXPLOSION1_NL=62]="EXPLOSION1_NL",e[e.EXPLOSION2_NL=63]="EXPLOSION2_NL",e))(I||{});var Bf=12,Of=9,fb=Math.ceil(Bf*Of/16),Nf=23,Uf=2,hb=Math.ceil(Nf*Uf/16);var Hf={};Oc(Hf,{U_ANGLE1:()=>Zf,U_ANGLE2:()=>Yf,U_ANGLE3:()=>qf,U_EFFECTS:()=>Jf,U_EVENT:()=>rh,U_FRAME:()=>jf,U_MODEL:()=>Gf,U_MODEL2:()=>ih,U_MODEL3:()=>sh,U_MODEL4:()=>oh,U_MOREBITS:()=>nh,U_NUMBER:()=>Vf,U_ORIGIN1:()=>Xf,U_ORIGIN2:()=>$f,U_ORIGIN3:()=>Kf,U_REMOVE:()=>ah,U_RENDERFX:()=>eh,U_SKIN:()=>Qf,U_SOLID:()=>th,U_SOUND:()=>Wf});var Vf=1,Gf=2,Wf=4,Xf=8,$f=16,Kf=32,Zf=64,Yf=128,qf=256,jf=512,Qf=1024,Jf=2048,eh=4096,th=8192,rh=16384,nh=32768,ih=1,sh=2,oh=4,ah=32768;var Bn=class{constructor(e){e instanceof Uint8Array?this.view=new DataView(e.buffer,e.byteOffset,e.byteLength):this.view=new DataView(e),this.offset=0,this.length=this.view.byteLength}getPosition(){return this.offset}getLength(){return this.length}seek(e){if(e<0||e>this.length)throw new Error(`Seek out of bounds: ${e} (length: ${this.length})`);this.offset=e}hasMore(){return this.offset<this.length}readChar(){let e=this.view.getInt8(this.offset);return this.offset+=1,e}readByte(){let e=this.view.getUint8(this.offset);return this.offset+=1,e}readShort(){let e=this.view.getInt16(this.offset,!0);return this.offset+=2,e}readUShort(){let e=this.view.getUint16(this.offset,!0);return this.offset+=2,e}readLong(){let e=this.view.getInt32(this.offset,!0);return this.offset+=4,e}readULong(){let e=this.view.getUint32(this.offset,!0);return this.offset+=4,e}readFloat(){let e=this.view.getFloat32(this.offset,!0);return this.offset+=4,e}readString(){let e="";for(;this.offset<this.length;){let t=this.readChar();if(t===-1||t===0)break;e+=String.fromCharCode(t)}return e}readStringLine(){let e="";for(;this.offset<this.length;){let t=this.readChar();if(t===-1||t===0||t===10)break;e+=String.fromCharCode(t)}return e}readCoord(){return this.readShort()*(1/8)}readAngle(){return this.readChar()*(360/256)}readAngle16(){return this.readShort()*360/65536}readData(e){if(this.offset+e>this.length)throw new Error(`Read out of bounds: ${this.offset+e} (length: ${this.length})`);let t=new Uint8Array(this.view.buffer,this.view.byteOffset+this.offset,e);return this.offset+=e,new Uint8Array(t)}readPos(e){e.x=this.readCoord(),e.y=this.readCoord(),e.z=this.readCoord()}readDir(e){let t=this.readByte();if(t>=162){e.x=0,e.y=0,e.z=0;return}let r=ca[t];e.x=r[0],e.y=r[1],e.z=r[2]}},va=class{constructor(e=1400){typeof e=="number"?(this.buffer=new Uint8Array(e),this.fixed=!1):(this.buffer=e,this.fixed=!0),this.view=new DataView(this.buffer.buffer,this.buffer.byteOffset,this.buffer.byteLength),this.offset=0}ensureSpace(e){if(this.offset+e>this.buffer.byteLength){if(this.fixed)throw new Error(`Buffer overflow: capacity ${this.buffer.byteLength}, needed ${this.offset+e}`);let t=Math.max(this.buffer.byteLength*2,this.offset+e),r=new Uint8Array(t);r.set(this.buffer),this.buffer=r,this.view=new DataView(this.buffer.buffer,this.buffer.byteOffset,this.buffer.byteLength)}}writeByte(e){this.ensureSpace(1),this.view.setUint8(this.offset,e),this.offset+=1}writeChar(e){this.ensureSpace(1),this.view.setInt8(this.offset,e),this.offset+=1}writeShort(e){this.ensureSpace(2),this.view.setInt16(this.offset,e,!0),this.offset+=2}writeLong(e){this.ensureSpace(4),this.view.setInt32(this.offset,e,!0),this.offset+=4}writeFloat(e){this.ensureSpace(4),this.view.setFloat32(this.offset,e,!0),this.offset+=4}writeString(e){let t=e.length;this.ensureSpace(t+1);for(let r=0;r<t;r++)this.view.setUint8(this.offset+r,e.charCodeAt(r));this.view.setUint8(this.offset+t,0),this.offset+=t+1}writeCoord(e){this.writeShort(Math.trunc(e*8))}writeAngle(e){this.writeByte(Math.trunc(e*256/360)&255)}writeAngle16(e){this.writeShort(Math.trunc(e*65536/360)&65535)}writePos(e){this.writeCoord(e.x),this.writeCoord(e.y),this.writeCoord(e.z)}writeDir(e){let t=-1,r=0;if(e.x===0&&e.y===0&&e.z===0){this.writeByte(0);return}for(let n=0;n<ca.length;n++){let i=ca[n],s=e.x*i[0]+e.y*i[1]+e.z*i[2];s>t&&(t=s,r=n)}this.writeByte(r)}getData(){return this.buffer.slice(0,this.offset)}getBuffer(){return this.buffer}getOffset(){return this.offset}reset(){this.offset=0}};var Ur=class me{constructor(){this.qport=0,this.incomingSequence=0,this.outgoingSequence=0,this.incomingAcknowledged=0,this.incomingReliableAcknowledged=!1,this.incomingReliableSequence=0,this.outgoingReliableSequence=0,this.reliableLength=0,this.fragmentSendOffset=0,this.fragmentBuffer=null,this.fragmentLength=0,this.fragmentReceived=0,this.lastReceived=0,this.lastSent=0,this.remoteAddress=null,this.reliableMessage=new va(me.MAX_RELIABLE_BUFFER);let t=Date.now();this.lastReceived=t,this.lastSent=t,this.qport=Math.floor(Math.random()*65536)}setup(t,r=null){this.qport=t,this.remoteAddress=r,this.reset()}reset(){this.incomingSequence=0,this.outgoingSequence=0,this.incomingAcknowledged=0,this.incomingReliableAcknowledged=!1,this.incomingReliableSequence=0,this.outgoingReliableSequence=0,this.reliableLength=0,this.reliableMessage.reset(),this.fragmentSendOffset=0,this.fragmentBuffer=null,this.fragmentLength=0,this.fragmentReceived=0,this.lastReceived=Date.now(),this.lastSent=Date.now()}transmit(t){this.outgoingSequence++,this.lastSent=Date.now();let r=0,n=!1,i=0;this.reliableLength>0&&(this.reliableLength>me.FRAGMENT_SIZE?(n=!0,this.fragmentSendOffset>=this.reliableLength&&(this.fragmentSendOffset=0),r=this.reliableLength-this.fragmentSendOffset,r>me.FRAGMENT_SIZE&&(r=me.FRAGMENT_SIZE),i=this.fragmentSendOffset,this.fragmentSendOffset+=r):r=this.reliableLength);let s=me.PACKET_HEADER,o=r>0?2+(n?8:0):0,a=t?t.length:0;s+o+r+a>me.MAX_MSGLEN&&(a=me.MAX_MSGLEN-s-o-r,a<0&&(a=0));let d=new ArrayBuffer(s+o+r+a),l=new DataView(d),c=new Uint8Array(d),h=this.outgoingSequence;r>0&&(h|=2147483648,(this.outgoingReliableSequence&1)!==0&&(h|=1073741824)),l.setUint32(0,h,!0);let u=this.incomingSequence;(this.incomingReliableSequence&1)!==0&&(u|=2147483648),l.setUint32(4,u,!0),l.setUint16(8,this.qport,!0);let f=s;if(r>0){let m=r;n&&(m|=32768),l.setUint16(f,m,!0),f+=2,n&&(l.setUint32(f,i,!0),f+=4,l.setUint32(f,this.reliableLength,!0),f+=4);let p=this.reliableMessage.getBuffer().subarray(i,i+r);c.set(p,f),f+=r}if(t&&a>0){let m=t.slice(0,a);c.set(m,f)}return c}process(t){if(t.length<me.PACKET_HEADER)return null;this.lastReceived=Date.now();let r=new DataView(t.buffer,t.byteOffset,t.byteLength),n=r.getUint32(0,!0),i=r.getUint32(4,!0),s=r.getUint16(8,!0);if(this.qport!==s)return null;let o=n&1073741823;if((o-this.incomingSequence|0)<=0)return null;this.incomingSequence=o;let a=i&2147483647,d=(i&2147483648)!==0;if(a>this.incomingAcknowledged&&(this.incomingAcknowledged=a),this.reliableLength>0){let m=d?1:0,g=this.outgoingReliableSequence&1;m!==g&&(this.reliableLength=0,this.reliableMessage.reset(),this.outgoingReliableSequence^=1,this.fragmentSendOffset=0)}let l=(n&2147483648)!==0,c=(n&1073741824)!==0?1:0,h=me.PACKET_HEADER,u=null;if(l){if(h+2>t.byteLength)return null;let m=r.getUint16(h,!0);h+=2;let g=(m&32768)!==0;m&=32767;let p=this.incomingReliableSequence&1;if(c===p)if(g){if(h+8>t.byteLength)return null;let y=r.getUint32(h,!0);h+=4;let _=r.getUint32(h,!0);if(h+=4,_>me.MAX_RELIABLE_BUFFER)return console.warn(`NetChan: received invalid fragment total ${_} > ${me.MAX_RELIABLE_BUFFER}`),null;if((!this.fragmentBuffer||this.fragmentBuffer.length!==_)&&(this.fragmentBuffer=new Uint8Array(_),this.fragmentLength=_,this.fragmentReceived=0),h+m>t.byteLength)return null;let b=t.subarray(h,h+m);y===this.fragmentReceived&&y+m<=_&&(this.fragmentBuffer.set(b,y),this.fragmentReceived+=m,this.fragmentReceived>=_&&(u=this.fragmentBuffer,this.incomingReliableSequence++,this.fragmentBuffer=null,this.fragmentLength=0,this.fragmentReceived=0))}else{if(this.incomingReliableSequence++,h+m>t.byteLength)return null;u=t.slice(h,h+m)}h+=m}let f=t.slice(h);if(u&&u.length>0){let m=u.length+f.length,g=new Uint8Array(m);return g.set(u,0),g.set(f,u.length),g}return f||new Uint8Array(0)}canSendReliable(){return this.reliableLength===0}writeReliableByte(t){if(this.reliableLength+1>me.MAX_RELIABLE_BUFFER)throw new Error("NetChan reliable buffer overflow");this.reliableMessage.writeByte(t),this.reliableLength++}writeReliableShort(t){if(this.reliableLength+2>me.MAX_RELIABLE_BUFFER)throw new Error("NetChan reliable buffer overflow");this.reliableMessage.writeShort(t),this.reliableLength+=2}writeReliableLong(t){if(this.reliableLength+4>me.MAX_RELIABLE_BUFFER)throw new Error("NetChan reliable buffer overflow");this.reliableMessage.writeLong(t),this.reliableLength+=4}writeReliableString(t){let r=t.length+1;if(this.reliableLength+r>me.MAX_RELIABLE_BUFFER)throw new Error("NetChan reliable buffer overflow");this.reliableMessage.writeString(t),this.reliableLength+=r}getReliableData(){return this.reliableLength===0?new Uint8Array(0):this.reliableMessage.getBuffer().subarray(0,this.reliableLength)}needsKeepalive(t){return t-this.lastSent>1e3}isTimedOut(t,r=3e4){return t-this.lastReceived>r}};Ur.MAX_MSGLEN=1400;Ur.FRAGMENT_SIZE=1024;Ur.PACKET_HEADER=10;Ur.HEADER_OVERHEAD=Ur.PACKET_HEADER+2;Ur.MAX_RELIABLE_BUFFER=262144;var jc=(e=>(e[e.Bullets=0]="Bullets",e[e.Shells=1]="Shells",e[e.Rockets=2]="Rockets",e[e.Grenades=3]="Grenades",e[e.Cells=4]="Cells",e[e.Slugs=5]="Slugs",e[e.MagSlugs=6]="MagSlugs",e[e.Trap=7]="Trap",e[e.Flechettes=8]="Flechettes",e[e.Tesla=9]="Tesla",e[e.Disruptor=10]="Disruptor",e[e.Prox=11]="Prox",e[e.Nuke=12]="Nuke",e[e.Rounds=13]="Rounds",e))(jc||{}),mb=Object.keys(jc).length/2;var On=32,st=(e=>(e[e.Auto=0]="Auto",e[e.Weapon=1]="Weapon",e[e.Voice=2]="Voice",e[e.Item=3]="Item",e[e.Body=4]="Body",e[e.Aux=5]="Aux",e[e.Footstep=6]="Footstep",e[e.Aux3=7]="Aux3",e[e.NoPhsAdd=8]="NoPhsAdd",e[e.Reliable=16]="Reliable",e[e.ForcePos=32]="ForcePos",e))(st||{}),Sa=-1,Nn=0,wa=1,Aa=2,Ms=3,Pt=80,Ma=.003;function Bt(e){return e===Ms?e*.001:e*5e-4}function Un(e){let t=Bt(e);return t<=0?Number.POSITIVE_INFINITY:Pt+1/t}var Hn=class{constructor({name:t,defaultValue:r,description:n,flags:i=Ss.None,onChange:s}){this.modifiedCount=0;this.name=t,this.defaultValue=r,this.description=n,this.flags=i,this._value=r,this.onChange=s}get string(){return this._value}get number(){return Number(this._value)}get integer(){return Math.trunc(this.number)}get boolean(){return!!this.integer}set(t){if(this.flags&Ss.Latch){if(t===this._value){this.latched=void 0;return}if(this.latched===t)return;this.latched!==t&&(this.latched=t);return}this.apply(t)}reset(){this.latched=void 0,this.apply(this.defaultValue)}applyLatched(){if(this.latched===void 0)return!1;let t=this.latched;return this.latched=void 0,t===this._value?!1:(this.apply(t),!0)}apply(t){if(this._value===t)return;let r=this._value;this._value=t,this.modifiedCount+=1,this.onChange?.(this,r)}},Vr=class{constructor(){this.cvars=new Map}register(t){let r=this.cvars.get(t.name);if(r)return r;let n=t.onChange,i=(o,a)=>{n?.(o,a),this.onCvarChange?.(o.name,o.string)},s=new Hn({...t,onChange:i});return this.cvars.set(t.name,s),s}get(t){return this.cvars.get(t)}getCvar(t){return this.get(t)}setValue(t,r){let n=this.get(t);if(!n)throw new Error(`Unknown cvar: ${t}`);return n.set(r),n}setCvar(t,r){this.setValue(t,r)}resetAll(){for(let t of this.cvars.values())t.reset()}applyLatched(){let t=!1;for(let r of this.cvars.values())t=r.applyLatched()||t;return t}list(){return[...this.cvars.values()].sort((t,r)=>t.name.localeCompare(r.name))}listCvars(){return this.list().map(t=>({name:t.name,value:t.string,defaultValue:t.defaultValue,flags:t.flags,description:t.description}))}};var Gr=class{constructor(t,r,n={}){this.game=t;this.client=r;this.started=!1;this.commands=new Nr;this.cvars=new Vr;this.stepSimulation=t=>{this.previousFrame=this.latestFrame,this.latestFrame=this.game.frame(t,this.latestCommand)};this.renderClient=t=>{this.client&&(this.latestCommand=this.client.render({...t,previous:this.previousFrame,latest:this.latestFrame}))};let i=n.loop?.now?.()??Date.now();this.startTimeMs=n.startTimeMs??n.loop?.startTimeMs??i,this.loop=new ur({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(t){throw this.game.shutdown(),this.client?.shutdown(),t}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(t){this.loop.pump(t)}getLatestFrame(){return this.latestFrame}isRunning(){return this.loop.isRunning()}};function lh(e){if(e<0||e>=j.MaxConfigStrings)throw new RangeError(`Configstring index ${e} is out of range (0-${j.MaxConfigStrings-1})`)}function Qc(e,t){let r=qc(e);if(t.length>r)throw new RangeError(`Configstring ${e} exceeds maximum length (${t.length} > ${r}); limit is ${Dn} chars per slot`)}var Wr=class{constructor(){this.values=new Map;this.modelCursor=j.Models;this.soundCursor=j.Sounds;this.imageCursor=j.Images;this.lightCursor=j.Lights;this.shadowLightCursor=j.ShadowLights;this.itemCursor=j.Items;this.playerSkinCursor=j.PlayerSkins;this.generalCursor=j.General}set(t,r){return lh(t),Qc(t,r),this.values.set(t,r),t}get(t){return this.values.get(t)}getName(t){return this.get(t)}getAll(){let t=new Array(Yc).fill("");for(let[r,n]of this.values.entries())t[r]=n;return t}modelIndex(t){return this.register(t,j.Models,ga,"modelCursor")}soundIndex(t){return this.register(t,j.Sounds,As,"soundCursor")}findSoundIndex(t){for(let r=j.Sounds;r<j.Sounds+As;r+=1)if(this.values.get(r)===t)return r}imageIndex(t){return this.register(t,j.Images,ya,"imageCursor")}lightIndex(t){return this.register(t,j.Lights,pa,"lightCursor")}shadowLightIndex(t){return this.register(t,j.ShadowLights,_a,"shadowLightCursor")}itemIndex(t){return this.register(t,j.Items,xa,"itemCursor")}playerSkinIndex(t){return this.register(t,j.PlayerSkins,ws,"playerSkinCursor")}generalIndex(t){return this.register(t,j.General,ba,"generalCursor")}register(t,r,n,i){for(let a=r;a<r+n;a+=1)if(this.values.get(a)===t)return a;let s=this[i],o=r+n;if(s>=o)throw new RangeError(`Out of configstring slots for range starting at ${r}`);return Qc(s,t),this.values.set(s,t),this[i]=s+1,s}};var Xr=class{constructor(t){this.registry=t.registry,this.system=t.system,this.music=t.music,this.client=t.client}soundindex(t){return this.registry.registerName(t)}sound(t,r,n,i,s,o){this.system.play({entity:t,channel:r,soundIndex:n,volume:i,attenuation:s,timeOffsetMs:o}),this.triggerSubtitle(n)}positioned_sound(t,r,n,i){this.system.positionedSound(t,r,n,i),this.triggerSubtitle(r)}loop_sound(t,r,n,i,s){this.system.play({entity:t,channel:r,soundIndex:n,volume:i,attenuation:s,looping:!0}),this.triggerSubtitle(n)}stop_entity_sounds(t){this.system.stopEntitySounds(t)}setPlaybackRate(t){this.system.setPlaybackRate(t)}set_listener(t){this.system.setListener(t)}play_music(t,r=!0){return this.music?this.music.play(t,{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(t){this.music?.setVolume(t)}play_ambient(t,r,n){this.system.ambientSound(t,r,n),this.triggerSubtitle(r)}play_channel(t){this.system.play({...t}),this.triggerSubtitle(t.soundIndex)}triggerSubtitle(t){if(!this.client)return;let r=this.registry.getName(t);if(!r)return;let n=r.match(/\[(.*?)\]/);n&&this.client.showSubtitle(n[1],r)}};var Vn=class{constructor(t,r){this.engine=t;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(t){this.host.pump(t)}getLatestFrame(){return this.host.getLatestFrame()}isRunning(){return this.started&&this.host.isRunning()}};function Jc(e,t,r,n,i){let s=new Xr({...n,client:r}),o=new Gr(t,r,i);return{runtime:new Vn(e,o),audio:s}}var ch="PACK";function dh(e,t,r){let n=[];for(let i=0;i<r;i+=1){let s=e.getUint8(t+i);if(s===0)break;n.push(s)}return String.fromCharCode(...n)}function se(e){return e.replace(/\\/g,"/").replace(/^\/+/,"").toLowerCase()}function uh(){let e=new Uint32Array(256);for(let t=0;t<256;t+=1){let r=t;for(let n=0;n<8;n+=1)r=(r&1)!==0?3988292384^r>>>1:r>>>1;e[t]=r>>>0}return e}var fh=uh();function ed(e){let t=4294967295;for(let r=0;r<e.length;r+=1){let n=e[r];t=fh[(t^n)&255]^t>>>8}return(t^4294967295)>>>0}var Ve=class extends Error{},$r=class e{constructor(t,r,n,i){this.name=t;this.buffer=r;this.entries=new Map(n.map(s=>[s.name,s])),this.checksum=i,this.size=r.byteLength}static fromArrayBuffer(t,r){let n=new DataView(r);if(r.byteLength<12)throw new Ve("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!==ch)throw new Ve(`Invalid PAK header magic: ${i}`);let s=n.getInt32(4,!0),o=n.getInt32(8,!0);if(s<12)throw new Ve(`Invalid directory offset: ${s}`);if(o<=0||o%64!==0)throw new Ve(`Invalid directory length: ${o}`);if(s+o>r.byteLength)throw new Ve("Directory exceeds buffer length");let d=o/64,l=[],c=new Map;for(let h=0;h<d;h+=1){let u=s+h*64,f=dh(n,u,56),m=se(f),g=n.getInt32(u+56,!0),p=n.getInt32(u+60,!0);if(g<0||p<0||g+p>r.byteLength)throw new Ve(`Invalid entry bounds for ${f||"<unnamed>"} (offset=${g}, length=${p})`);if(!m)throw new Ve(`Entry ${h} has an empty name`);let y={name:m,offset:g,length:p};c.set(m,y)}return l.push(...c.values()),new e(t,r,l,ed(new Uint8Array(r)))}getEntry(t){return this.entries.get(se(t))}listEntries(){return Array.from(this.entries.values())}readFile(t){let r=this.getEntry(t);if(!r)throw new Ve(`File not found in PAK: ${t}`);return new Uint8Array(this.buffer,r.offset,r.length)}validate(){return{checksum:this.checksum,entries:this.listEntries()}}};function td(e){return ed(new Uint8Array(e))}var Ls=class{constructor(t=[]){this.mounts=[];this.files=new Map;t.forEach(r=>this.mountPak(r))}mountPak(t){this.mounts.push(t);for(let r of t.listEntries()){let n=se(r.name);this.files.set(n,{archive:t,entry:r})}}get mountedPaks(){return[...this.mounts]}hasFile(t){return this.files.has(se(t))}stat(t){let r=this.files.get(se(t));if(r)return{path:r.entry.name,size:r.entry.length,sourcePak:r.archive.name}}getFileMetadata(t){let r=this.files.get(se(t));if(r)return{path:r.entry.name,size:r.entry.length,sourcePak:r.archive.name,offset:r.entry.offset}}async readFile(t){let r=this.files.get(se(t));if(!r)throw new Error(`File not found in VFS: ${t}`);return r.archive.readFile(t)}async readBinaryFile(t){return this.readFile(t)}streamFile(t,r=1024*1024){let n=this.files.get(se(t));if(!n)throw new Error(`File not found in VFS: ${t}`);let{archive:i,entry:s}=n,o=i.readFile(t),a=0,d=o.length;return new ReadableStream({pull(l){if(a>=d){l.close();return}let c=Math.min(a+r,d),h=o.slice(a,c);a=c,l.enqueue(h)}})}async readTextFile(t){let r=await this.readFile(t);return new TextDecoder("utf-8").decode(r)}list(t=""){let r=se(t).replace(/\/+$|^\//g,""),n=[],i=new Set,s=r?`${r}/`:"";for(let o of this.files.values()){if(r&&!o.entry.name.startsWith(s))continue;let a=r?o.entry.name.slice(s.length):o.entry.name,d=a.indexOf("/");d===-1?n.push({path:o.entry.name,size:o.entry.length,sourcePak:o.archive.name}):i.add(a.slice(0,d))}return n.sort((o,a)=>o.path.localeCompare(a.path)),{files:n,directories:[...i].sort()}}async listDirectory(t){return this.list(t).files}findByExtension(t){let r=t.startsWith(".")?t.toLowerCase():`.${t.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,s)=>i.path.localeCompare(s.path))}listByExtension(t){let r=new Set(t.map(i=>i.startsWith(".")?i.toLowerCase():`.${i.toLowerCase()}`)),n=[];for(let i of this.files.values()){let s=i.entry.name.toLowerCase();for(let o of r)if(s.endsWith(o)){n.push({path:i.entry.name,size:i.entry.length,sourcePak:i.archive.name});break}}return n.sort((i,s)=>i.path.localeCompare(s.path))}searchFiles(t){let r=[];for(let n of this.files.values())t.test(n.entry.name)&&r.push({path:n.entry.name,size:n.entry.length,sourcePak:n.archive.name});return r.sort((n,i)=>n.path.localeCompare(i.path))}getPakInfo(){return this.mounts.map(t=>({filename:t.name,entryCount:t.listEntries().length,totalSize:t.size}))}getDirectoryTree(){let t={name:"",path:"",files:[],directories:[]},r=new Map;r.set("",t);let n=Array.from(this.files.values()).map(i=>({path:i.entry.name,size:i.entry.length,sourcePak:i.archive.name})).sort((i,s)=>i.path.localeCompare(s.path));for(let i of n){let s=i.path.split("/"),o=s.pop(),a="",d=t;for(let l of s){let c=a;a=a?`${a}/${l}`:l;let h=r.get(a);h||(h={name:l,path:a,files:[],directories:[]},d.directories.push(h),r.set(a,h)),d=h}d.files.push(i)}return t}};var La=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"}]),fr=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"}},Es=class{constructor(t=La){this.known=new Map;t.forEach(r=>this.known.set(this.normalizePakName(r.name),r))}validateArchive(t,r){let n=this.normalizePakName(r??("name"in t?t.name:"unknown")),i=t.checksum,s="size"in t?t.size:void 0,o=this.known.get(n);return o?o.checksum!==i?{name:n,checksum:i,expectedChecksum:o.checksum,status:"mismatch",size:s,description:o.description}:{name:n,checksum:i,expectedChecksum:o.checksum,status:"valid",size:s,description:o.description}:{name:n,checksum:i,status:"unknown",size:s}}assertValid(t,r){let n=this.validateArchive(t,r);if(n.status==="mismatch")throw new fr(n);return n}normalizePakName(t){let r=se(t),n=r.split("/"),i=n.pop()??r,s=n.pop();return s?`${i}@${s}`:i}};var Ot=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 hh(e,t){if(typeof e.arrayBuffer=="function"){let r=await e.arrayBuffer();return t?.({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=s=>{t?.({file:"blob",loadedBytes:s.loaded,totalBytes:s.total||e.size,state:"reading"})},i.onload=()=>{let s=i.result;s instanceof ArrayBuffer?r(s):n(new Error("Unexpected FileReader result"))},i.readAsArrayBuffer(e)});if(typeof Response<"u"){let r=await new Response(e).arrayBuffer();return t?.({file:"blob",loadedBytes:r.byteLength,totalBytes:r.byteLength,state:"reading"}),r}if(typeof e.stream=="function"){let r=e.stream().getReader(),n=[],i=0;for(;;){let{done:a,value:d}=await r.read();if(a)break;if(!d)continue;let l=d;n.push(l),i+=l.byteLength,t?.({file:"blob",loadedBytes:i,totalBytes:e.size,state:"reading"})}let s=new Uint8Array(i),o=0;for(let a of n)s.set(a,o),o+=a.byteLength;return s.buffer}throw new Ot("blob",new Error("Unsupported Blob type"))}async function mh(e,t){if(e.data instanceof ArrayBuffer)return t?.({file:e.name,loadedBytes:e.data.byteLength,totalBytes:e.data.byteLength,state:"reading"}),e.data;if(e.data instanceof Blob){let n=e.data.size;return hh(e.data,i=>t?.({...i,file:e.name,totalBytes:n}))}let r=e.data.buffer.slice(e.data.byteOffset,e.data.byteOffset+e.data.byteLength);return t?.({file:e.name,loadedBytes:r.byteLength,totalBytes:r.byteLength,state:"reading"}),r}async function Ts(e,t,r){let n=typeof r=="function"?{onProgress:r}:r??{},i=n.persistIndexes??!!n.pakIndexStore,s=n.enforceValidation??!!n.validator,o=n.allowUnknownPaks??!0,a=n.stopOnError??!1,d=[];for(let l of t)try{let c=await mh(l,n.onProgress),h=$r.fromArrayBuffer(l.name,c),u=n.validator?.validateArchive(h);if(u){n.onValidationResult?.(u);let f=u.status==="mismatch",m=u.status==="unknown";if(f&&s||m&&!o){let g=new fr(u);if(n.onError?.(l.name,g),a)throw new Ot(l.name,g);d.push({archive:h,mounted:!1,validation:u});continue}}if(e.mountPak(h),i&&n.pakIndexStore)try{await n.pakIndexStore.persist(h)}catch(f){if(n.onError?.(l.name,f),a)throw new Ot(l.name,f)}n.onProgress?.({file:l.name,loadedBytes:c.byteLength,totalBytes:c.byteLength,state:"parsed"}),d.push({archive:h,mounted:!0,validation:u})}catch(c){if(n.onProgress?.({file:l.name,loadedBytes:0,totalBytes:0,state:"error"}),n.onError?.(l.name,c),a)throw new Ot(l.name,c)}return d}var Nt=class{constructor(t){this.capacity=t;this.map=new Map;if(t<=0)throw new RangeError("LRU cache capacity must be greater than zero")}get size(){return this.map.size}has(t){return this.map.has(t)}get(t){let r=this.map.get(t);if(r!==void 0)return this.map.delete(t),this.map.set(t,r),r}set(t,r){if(this.map.has(t)&&this.map.delete(t),this.map.set(t,r),this.map.size>this.capacity){let n=this.map.keys().next();n.done||this.map.delete(n.value)}}delete(t){return this.map.delete(t)}clear(){this.map.clear()}entries(){return Array.from(this.map.entries()).reverse().map(([t,r])=>({key:t,value:r}))}};function ph(e){return Array.isArray(e)?e:Array.from(e)}function Ea(e){return ph(e).map(t=>({name:t.name,data:t}))}async function rd(e,t,r){let n=Ea(t);return Ts(e,n,r??{})}function nd(e,t){let r=i=>{i.preventDefault(),i.dataTransfer?.dropEffect&&(i.dataTransfer.dropEffect="copy")},n=i=>{i.preventDefault();let s=i.dataTransfer?.files;s&&s.length>0&&t(Array.from(s))};return e.addEventListener("dragover",r),e.addEventListener("drop",n),()=>{e.removeEventListener("dragover",r),e.removeEventListener("drop",n)}}function id(e,t){let r=n=>{let i=n.target;!i||!i.files||i.files.length===0||(t(i.files),i.value="")};return e.addEventListener("change",r),()=>e.removeEventListener("change",r)}var gh="IBSP",yh=38,od=19,xh=8+od*8;var Q=class extends Error{},Kr=class{constructor(t){this.vfs=t}async load(t){let r=await this.vfs.readFile(t),n=new Uint8Array(r.byteLength);return n.set(r),Gn(n.buffer)}};function Gn(e){if(e.byteLength<xh)throw new Q("BSP too small to contain header");let t=new DataView(e),r=String.fromCharCode(t.getUint8(0),t.getUint8(1),t.getUint8(2),t.getUint8(3));if(r!==gh)throw new Q(`Invalid BSP magic ${r}`);let n=t.getInt32(4,!0);if(n!==yh)throw new Q(`Unsupported BSP version ${n}`);let i=new Map;for(let S=0;S<od;S+=1){let M=t.getInt32(8+S*8,!0),E=t.getInt32(12+S*8,!0);if(M<0||E<0||M+E>e.byteLength)throw new Q(`Invalid lump bounds for index ${S}`);i.set(S,{offset:M,length:E})}let s={version:n,lumps:i},o=_h(e,i.get(0)),a=Sh(e,i.get(1)),d=wh(e,i.get(2)),l=Ah(e,i.get(4)),c=Mh(e,i.get(5)),h=Lh(e,i.get(6)),u=new Uint8Array(e,i.get(7).offset,i.get(7).length),f=Dh(h,i.get(7)),m=Eh(e,i.get(8)),g=Th(e,i.get(11)),p=Ih(e,i.get(12)),y=Ch(e,i.get(13)),_=Rh(e,i.get(14)),b=Fh(e,i.get(15)),x=zh(e,i.get(9),i.get(10),m),v=kh(e,i.get(3));return{header:s,entities:o,planes:a,vertices:d,nodes:l,texInfo:c,faces:h,lightMaps:u,lightMapInfo:f,leafs:m,leafLists:x,edges:g,surfEdges:p,models:y,brushes:_,brushSides:b,visibility:v,pickEntity(S){let M=null,E=1/0;for(let w of o.entities){let T=w.properties.model;if(!T||!T.startsWith("*"))continue;let F=parseInt(T.substring(1),10);if(isNaN(F)||F<0||F>=y.length)continue;let U=y[F],C=bh(S.origin,S.direction,U.mins,U.maxs);C!==null&&C<E&&(E=C,M={entity:w,model:U,distance:C})}return M}}}function bh(e,t,r,n){let i=0,s=1/0;for(let o=0;o<3;o++)if(Math.abs(t[o])<1e-8){if(e[o]<r[o]||e[o]>n[o])return null}else{let a=1/t[o],d=(r[o]-e[o])*a,l=(n[o]-e[o])*a;if(d>l){let c=d;d=l,l=c}if(i=Math.max(i,d),s=Math.min(s,l),i>s)return null}return i}function _h(e,t){let r=new TextDecoder().decode(new Uint8Array(e,t.offset,t.length)),n=vh(r),i=n.find(s=>s.classname==="worldspawn");return{raw:r,entities:n,worldspawn:i,getUniqueClassnames(){let s=new Set;for(let o of n)o.classname&&s.add(o.classname);return Array.from(s).sort()}}}function vh(e){let t=[],r=/\{([^}]*)\}/gms,n;for(;(n=r.exec(e))!==null;){let i=n[1],s={},o=/"([^\"]*)"\s+"([^\"]*)"/g,a;for(;(a=o.exec(i))!==null;)s[a[1]]=a[2];t.push({classname:s.classname,properties:s})}return t}function Sh(e,t){let r=new DataView(e,t.offset,t.length),n=t.length/20;if(n%1!==0)throw new Q("Plane lump has invalid length");let i=[];for(let s=0;s<n;s+=1){let o=[r.getFloat32(s*20,!0),r.getFloat32(s*20+4,!0),r.getFloat32(s*20+8,!0)],a=r.getFloat32(s*20+12,!0),d=r.getInt32(s*20+16,!0);i.push({normal:o,dist:a,type:d})}return i}function wh(e,t){let r=new DataView(e,t.offset,t.length),n=t.length/12;if(n%1!==0)throw new Q("Vertex lump has invalid length");let i=[];for(let s=0;s<n;s+=1)i.push([r.getFloat32(s*12,!0),r.getFloat32(s*12+4,!0),r.getFloat32(s*12+8,!0)]);return i}function Ah(e,t){let r=new DataView(e,t.offset,t.length),n=28,i=t.length/n;if(i%1!==0)throw new Q("Node lump has invalid length");let s=[];for(let o=0;o<i;o+=1){let a=o*n,d=r.getInt32(a,!0),l=[r.getInt32(a+4,!0),r.getInt32(a+8,!0)],c=[r.getInt16(a+12,!0),r.getInt16(a+14,!0),r.getInt16(a+16,!0)],h=[r.getInt16(a+18,!0),r.getInt16(a+20,!0),r.getInt16(a+22,!0)],u=r.getUint16(a+24,!0),f=r.getUint16(a+26,!0);s.push({planeIndex:d,children:l,mins:c,maxs:h,firstFace:u,numFaces:f})}return s}function Mh(e,t){let r=new DataView(e,t.offset,t.length),n=76,i=t.length/n;if(i%1!==0)throw new Q("TexInfo lump has invalid length");let s=[];for(let o=0;o<i;o+=1){let a=o*n,d=[r.getFloat32(a,!0),r.getFloat32(a+4,!0),r.getFloat32(a+8,!0)],l=r.getFloat32(a+12,!0),c=[r.getFloat32(a+16,!0),r.getFloat32(a+20,!0),r.getFloat32(a+24,!0)],h=r.getFloat32(a+28,!0),u=r.getInt32(a+32,!0),f=r.getInt32(a+36,!0),m=new Uint8Array(e,t.offset+a+40,32),g=new TextDecoder("utf-8").decode(m).replace(/\0.*$/,""),p=r.getInt32(a+72,!0);s.push({s:d,sOffset:l,t:c,tOffset:h,flags:u,value:f,texture:g,nextTexInfo:p})}return s}function Lh(e,t){let r=new DataView(e,t.offset,t.length),n=20,i=t.length/n;if(i%1!==0)throw new Q("Face lump has invalid length");let s=[];for(let o=0;o<i;o+=1){let a=o*n,d=r.getUint16(a,!0),l=r.getInt16(a+2,!0),c=r.getInt32(a+4,!0),h=r.getInt16(a+8,!0),u=r.getInt16(a+10,!0),f=[r.getUint8(a+12),r.getUint8(a+13),r.getUint8(a+14),r.getUint8(a+15)],m=r.getInt32(a+16,!0);s.push({planeIndex:d,side:l,firstEdge:c,numEdges:h,texInfo:u,styles:f,lightOffset:m})}return s}function Eh(e,t){let r=new DataView(e,t.offset,t.length),n=28,i=t.length/n;if(i%1!==0)throw new Q("Leaf lump has invalid length");let s=[];for(let o=0;o<i;o+=1){let a=o*n,d=r.getInt32(a,!0),l=r.getInt16(a+4,!0),c=r.getInt16(a+6,!0),h=[r.getInt16(a+8,!0),r.getInt16(a+10,!0),r.getInt16(a+12,!0)],u=[r.getInt16(a+14,!0),r.getInt16(a+16,!0),r.getInt16(a+18,!0)],f=r.getUint16(a+20,!0),m=r.getUint16(a+22,!0),g=r.getUint16(a+24,!0),p=r.getUint16(a+26,!0);s.push({contents:d,cluster:l,area:c,mins:h,maxs:u,firstLeafFace:f,numLeafFaces:m,firstLeafBrush:g,numLeafBrushes:p})}return s}function Th(e,t){let r=new DataView(e,t.offset,t.length),n=4,i=t.length/n;if(i%1!==0)throw new Q("Edge lump has invalid length");let s=[];for(let o=0;o<i;o+=1){let a=o*n;s.push({vertices:[r.getUint16(a,!0),r.getUint16(a+2,!0)]})}return s}function Ih(e,t){let r=t.length/4;if(r%1!==0)throw new Q("SurfEdge lump has invalid length");let n=new DataView(e,t.offset,t.length),i=new Int32Array(r);for(let s=0;s<r;s+=1)i[s]=n.getInt32(s*4,!0);return i}function Ch(e,t){let r=new DataView(e,t.offset,t.length),n=48;if(t.length%n!==0)throw new Q("Model lump has invalid length");let i=t.length/n,s=[];for(let o=0;o<i;o+=1){let a=o*n,d=[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)],c=[r.getFloat32(a+24,!0),r.getFloat32(a+28,!0),r.getFloat32(a+32,!0)],h=r.getInt32(a+36,!0),u=r.getInt32(a+40,!0),f=r.getInt32(a+44,!0);s.push({mins:d,maxs:l,origin:c,headNode:h,firstFace:u,numFaces:f})}return s}function Rh(e,t){let r=new DataView(e,t.offset,t.length),n=12,i=t.length/n;if(i%1!==0)throw new Q("Brush lump has invalid length");let s=[];for(let o=0;o<i;o+=1){let a=o*n;s.push({firstSide:r.getInt32(a,!0),numSides:r.getInt32(a+4,!0),contents:r.getInt32(a+8,!0)})}return s}function Fh(e,t){let r=new DataView(e,t.offset,t.length),n=4,i=t.length/n;if(i%1!==0)throw new Q("Brush side lump has invalid length");let s=[];for(let o=0;o<i;o+=1){let a=o*n;s.push({planeIndex:r.getUint16(a,!0),texInfo:r.getInt16(a+2,!0)})}return s}function zh(e,t,r,n){let i=[],s=[],o=t.length/2,a=r.length/2,d=new DataView(e,t.offset,t.length),l=new DataView(e,r.offset,r.length);for(let c of n){if(c.firstLeafFace+c.numLeafFaces>o)throw new Q("Leaf faces reference data past lump bounds");if(c.firstLeafBrush+c.numLeafBrushes>a)throw new Q("Leaf brushes reference data past lump bounds");let h=[];for(let f=0;f<c.numLeafFaces;f+=1)h.push(d.getUint16((c.firstLeafFace+f)*2,!0));let u=[];for(let f=0;f<c.numLeafBrushes;f+=1)u.push(l.getUint16((c.firstLeafBrush+f)*2,!0));i.push(h),s.push(u)}return{leafFaces:i,leafBrushes:s}}function kh(e,t){if(t.length===0)return;if(t.length<4)throw new Q("Visibility lump too small");let r=new DataView(e,t.offset,t.length),n=r.getInt32(0,!0),i=4+n*8;if(n<0||i>t.length)throw new Q("Visibility lump truncated");let s=4,o=[];for(let a=0;a<n;a+=1){let d=r.getInt32(s,!0),l=r.getInt32(s+4,!0);s+=8;let c=t.offset+d,h=t.offset+l,u=t.offset+t.length;if(d<0||l<0||c>=u||h>=u)throw new Q("Visibility offsets out of range");o.push({pvs:sd(e,c,n,t),phs:sd(e,h,n,t)})}return{numClusters:n,clusters:o}}function sd(e,t,r,n){let i=Math.ceil(r/8),s=new Uint8Array(i),o=new Uint8Array(e),a=t,d=0,l=n.offset+n.length;for(;d<i;){if(a>=l)throw new Q("Visibility data truncated");let c=o[a++];if(c!==0){s[d++]=c;continue}if(a>=l)throw new Q("Visibility run exceeds lump bounds");let h=o[a++];for(let u=0;u<h&&d<i;u+=1)s[d++]=0}return s}function Dh(e,t){return e.map(r=>{if(!(r.lightOffset<0))return{offset:r.lightOffset,length:Math.max(0,t.length-r.lightOffset)}})}function Is(e,t,r){if(e.lightOffset<0||e.lightOffset>=t.byteLength)return;let n=t.byteLength-e.lightOffset,i=Math.min(r?.length??n,n);if(!(i<=0))return t.subarray(e.lightOffset,e.lightOffset+i)}var Ph=844121161,Bh=8,ad=68,Oh=[{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}],pe=class extends Error{},Zr=class{constructor(t){this.vfs=t;this.cache=new Map}async load(t){if(this.cache.has(t))return this.cache.get(t);let r=await this.vfs.readFile(t),n=new Uint8Array(r.byteLength);n.set(r);let i=Ta(n.buffer);return this.cache.set(t,i),i}get(t){return this.cache.get(t)}};function ld(e,t,r){let n=[];for(let i=0;i<r;i+=1){let s=e.getUint8(t+i);if(s===0)break;n.push(s)}return String.fromCharCode(...n)}function Wn(e,t,r,n){if(r!==0&&(t<ad||t+r>e.byteLength))throw new pe(`${n} section is out of bounds`)}function Nh(e){if(e.byteLength<ad)throw new pe("MD2 buffer too small to contain header");let t=new DataView(e),r=t.getInt32(0,!0),n=t.getInt32(4,!0);if(r!==Ph)throw new pe(`Invalid MD2 ident: ${r}`);if(n!==Bh)throw new pe(`Unsupported MD2 version: ${n}`);let i={ident:r,version:n,skinWidth:t.getInt32(8,!0),skinHeight:t.getInt32(12,!0),frameSize:t.getInt32(16,!0),numSkins:t.getInt32(20,!0),numVertices:t.getInt32(24,!0),numTexCoords:t.getInt32(28,!0),numTriangles:t.getInt32(32,!0),numGlCommands:t.getInt32(36,!0),numFrames:t.getInt32(40,!0),offsetSkins:t.getInt32(44,!0),offsetTexCoords:t.getInt32(48,!0),offsetTriangles:t.getInt32(52,!0),offsetFrames:t.getInt32(56,!0),offsetGlCommands:t.getInt32(60,!0),offsetEnd:t.getInt32(64,!0),magic:r},s=40+i.numVertices*4;if(i.frameSize!==s)throw new pe(`Unexpected frame size ${i.frameSize}, expected ${s}`);if(i.offsetEnd>e.byteLength)throw new pe("MD2 offset_end exceeds buffer length");return i}function Uh(e,t){let r=t.numSkins*64;Wn(e,t.offsetSkins,r,"skins");let n=new DataView(e,t.offsetSkins,r),i=[];for(let s=0;s<t.numSkins;s+=1)i.push({name:ld(n,s*64,64)});return i}function Hh(e,t){let r=t.numTexCoords*4;Wn(e,t.offsetTexCoords,r,"texcoords");let n=new DataView(e,t.offsetTexCoords,r),i=[];for(let s=0;s<t.numTexCoords;s+=1){let o=s*4;i.push({s:n.getInt16(o,!0),t:n.getInt16(o+2,!0)})}return i}function Vh(e,t){let r=t.numTriangles*12;Wn(e,t.offsetTriangles,r,"triangles");let n=new DataView(e,t.offsetTriangles,r),i=[];for(let s=0;s<t.numTriangles;s+=1){let o=s*12,a=[n.getUint16(o,!0),n.getUint16(o+2,!0),n.getUint16(o+4,!0)],d=[n.getUint16(o+6,!0),n.getUint16(o+8,!0),n.getUint16(o+10,!0)];if(a.some(l=>l>=t.numVertices)||d.some(l=>l>=t.numTexCoords))throw new pe("Triangle references out of range vertex or texcoord");i.push({vertexIndices:a,texCoordIndices:d})}return i}function Gh(e,t){let r=t.numFrames*t.frameSize;Wn(e,t.offsetFrames,r,"frames");let n=[];for(let i=0;i<t.numFrames;i+=1){let s=t.offsetFrames+i*t.frameSize,o=new DataView(e,s,t.frameSize),a={x:o.getFloat32(0,!0),y:o.getFloat32(4,!0),z:o.getFloat32(8,!0)},d={x:o.getFloat32(12,!0),y:o.getFloat32(16,!0),z:o.getFloat32(20,!0)},l=ld(o,24,16),c=[],h=1/0,u=1/0,f=1/0,m=-1/0,g=-1/0,p=-1/0;for(let y=0;y<t.numVertices;y+=1){let _=40+y*4,b=o.getUint8(_)*a.x+d.x,x=o.getUint8(_+1)*a.y+d.y,v=o.getUint8(_+2)*a.z+d.z;b<h&&(h=b),x<u&&(u=x),v<f&&(f=v),b>m&&(m=b),x>g&&(g=x),v>p&&(p=v);let A={x:b,y:x,z:v},S=o.getUint8(_+3),M=Oh[S];if(!M)throw new pe(`Invalid normal index ${S} in frame ${l}`);c.push({position:A,normalIndex:S,normal:M})}n.push({name:l,vertices:c,minBounds:{x:h,y:u,z:f},maxBounds:{x:m,y:g,z:p}})}return n}function Wh(e,t){let r=t.numGlCommands*4;if(Wn(e,t.offsetGlCommands,r,"gl commands"),r===0)return[];let n=new DataView(e,t.offsetGlCommands,r),i=[],s=0;for(;;){if(s+4>r)throw new pe("GL command list ended unexpectedly");let o=n.getInt32(s,!0);if(s+=4,o===0)break;let a=Math.abs(o),d=[],l=a*12;if(s+l>r)throw new pe("GL command vertex block exceeds buffer");for(let c=0;c<a;c+=1){let h=n.getFloat32(s,!0),u=n.getFloat32(s+4,!0),f=n.getInt32(s+8,!0);if(s+=12,f<0||f>=t.numVertices)throw new pe("GL command references invalid vertex index");d.push({s:h,t:u,vertexIndex:f})}i.push({mode:o>0?"strip":"fan",vertices:d})}if(s!==r)throw new pe("GL command list did not consume expected data");return i}function Ta(e){let t=Nh(e),r=Uh(e,t),n=Hh(e,t),i=Vh(e,t),s=Gh(e,t),o=Wh(e,t);return{header:t,skins:r,texCoords:n,triangles:i,frames:s,glCommands:o}}function cd(e){let t=[],r=0;for(;r<e.length;){let n=e[r].name,i=n.replace(/\d+$/,"")||n,s=r;for(;s+1<e.length&&(e[s+1].name.replace(/\d+$/,"")||e[s+1].name)===i;)s+=1;t.push({name:i,firstFrame:r,lastFrame:s}),r=s+1}return t}var dd=860898377,Xh=15,Ge=class extends Error{constructor(t){super(t),this.name="Md3ParseError"}};function Xn(e,t,r){let n=new Uint8Array(e.buffer,e.byteOffset+t,r);return new TextDecoder("utf-8").decode(n).replace(/\0.*$/,"").trim()}function $h(e){let t=(e>>8&255)*(2*Math.PI/255),r=(e&255)*(2*Math.PI/255),n=Math.sin(r);return{x:Math.cos(t)*n,y:Math.sin(t)*n,z:Math.cos(r)}}function Cs(e,t,r,n){if(t<0||t+r>n)throw new Ge(`${e} exceeds buffer bounds`)}function Kh(e){let t=e.getInt32(0,!0);if(t!==dd)throw new Ge(`Invalid MD3 ident: ${t}`);let r=e.getInt32(4,!0);if(r!==Xh)throw new Ge(`Unsupported MD3 version: ${r}`);let n=Xn(e,8,64),i=e.getInt32(72,!0),s=e.getInt32(76,!0),o=e.getInt32(80,!0),a=e.getInt32(84,!0),d=e.getInt32(88,!0),l=e.getInt32(92,!0),c=e.getInt32(96,!0),h=e.getInt32(100,!0),u=e.getInt32(104,!0);if(s<=0||a<0||o<0)throw new Ge("Invalid MD3 counts");return{ident:t,version:r,name:n,flags:i,numFrames:s,numTags:o,numSurfaces:a,numSkins:d,ofsFrames:l,ofsTags:c,ofsSurfaces:h,ofsEnd:u,magic:t}}function Zh(e,t){let r=[];Cs("Frames",t.ofsFrames,t.numFrames*56,e.byteLength);for(let i=0;i<t.numFrames;i+=1){let s=t.ofsFrames+i*56;r.push({minBounds:{x:e.getFloat32(s,!0),y:e.getFloat32(s+4,!0),z:e.getFloat32(s+8,!0)},maxBounds:{x:e.getFloat32(s+12,!0),y:e.getFloat32(s+16,!0),z:e.getFloat32(s+20,!0)},localOrigin:{x:e.getFloat32(s+24,!0),y:e.getFloat32(s+28,!0),z:e.getFloat32(s+32,!0)},radius:e.getFloat32(s+36,!0),name:Xn(e,s+40,16)})}return r}function Yh(e,t){let r=[],i=t.numFrames*t.numTags*112;Cs("Tags",t.ofsTags,i,e.byteLength);for(let s=0;s<t.numFrames;s+=1){let o=[];for(let a=0;a<t.numTags;a+=1){let d=t.ofsTags+(s*t.numTags+a)*112,l=d+64,c=l+12;o.push({name:Xn(e,d,64),origin:{x:e.getFloat32(l,!0),y:e.getFloat32(l+4,!0),z:e.getFloat32(l+8,!0)},axis:[{x:e.getFloat32(c,!0),y:e.getFloat32(c+4,!0),z:e.getFloat32(c+8,!0)},{x:e.getFloat32(c+12,!0),y:e.getFloat32(c+16,!0),z:e.getFloat32(c+20,!0)},{x:e.getFloat32(c+24,!0),y:e.getFloat32(c+28,!0),z:e.getFloat32(c+32,!0)}]})}r.push(o)}return r}function qh(e,t){let r=e.getInt32(t,!0);if(r!==dd)throw new Ge(`Invalid surface ident at ${t}: ${r}`);let n=Xn(e,t+4,64),i=e.getInt32(t+68,!0),s=e.getInt32(t+72,!0),o=e.getInt32(t+76,!0),a=e.getInt32(t+80,!0),d=e.getInt32(t+84,!0),l=e.getInt32(t+88,!0),c=e.getInt32(t+92,!0),h=e.getInt32(t+96,!0),u=e.getInt32(t+100,!0),f=e.getInt32(t+104,!0);if(s<=0||a<=0||d<=0)throw new Ge(`Invalid surface counts for ${n}`);let m=f;Cs(`Surface ${n}`,t,m,e.byteLength);let g=[],p=t+l;for(let S=0;S<d;S+=1){let M=p+S*12;g.push({indices:[e.getInt32(M,!0),e.getInt32(M+4,!0),e.getInt32(M+8,!0)]})}let y=[],_=t+c;for(let S=0;S<o;S+=1){let M=_+S*68;y.push({name:Xn(e,M,64),shaderIndex:e.getInt32(M+64,!0)})}let b=[],x=t+h;for(let S=0;S<a;S+=1){let M=x+S*8;b.push({s:e.getFloat32(M,!0),t:e.getFloat32(M+4,!0)})}let v=[],A=t+u;for(let S=0;S<s;S+=1){let M=[];for(let E=0;E<a;E+=1){let w=A+(S*a+E)*8,T=e.getInt16(w,!0)/64,F=e.getInt16(w+2,!0)/64,U=e.getInt16(w+4,!0)/64,C=e.getUint16(w+6,!0);M.push({position:{x:T,y:F,z:U},latLng:C,normal:$h(C)})}v.push(M)}return{surface:{name:n,flags:i,numFrames:s,shaders:y,triangles:g,texCoords:b,vertices:v},nextOffset:t+f}}function Ia(e){if(e.byteLength<108)throw new Ge("MD3 buffer too small for header");let t=new DataView(e),r=Kh(t);Cs("MD3 end",r.ofsEnd,0,e.byteLength);let n=Zh(t,r),i=Yh(t,r),s=[],o=r.ofsSurfaces;for(let a=0;a<r.numSurfaces;a+=1){let{surface:d,nextOffset:l}=qh(t,o);s.push(d),o=l}if(o!==r.ofsEnd)throw new Ge("Surface parsing did not reach ofsEnd");return{header:r,frames:n,tags:i,surfaces:s}}var Yr=class{constructor(t){this.vfs=t;this.cache=new Map}async load(t){if(this.cache.has(t))return this.cache.get(t);let r=await this.vfs.readFile(t),n=Ia(r.slice().buffer);return this.cache.set(t,n),n}get(t){return this.cache.get(t)}};var jh=844317769,Qh=2,ud=64,fd=12,Ut=class extends Error{};function Jh(e,t,r){let n=[];for(let i=0;i<r;i+=1){let s=e.getUint8(t+i);if(s===0)break;n.push(s)}return String.fromCharCode(...n)}function Ca(e){if(e.byteLength<fd)throw new Ut("Sprite buffer too small to contain header");let t=new DataView(e),r=t.getInt32(0,!0),n=t.getInt32(4,!0),i=t.getInt32(8,!0);if(r!==jh)throw new Ut(`Invalid Sprite ident: ${r}`);if(n!==Qh)throw new Ut(`Unsupported Sprite version: ${n}`);let s=[],o=16+ud,a=fd;for(let d=0;d<i;d+=1){if(a+o>e.byteLength)throw new Ut("Sprite frame data exceeds buffer length");let l=t.getInt32(a,!0),c=t.getInt32(a+4,!0),h=t.getInt32(a+8,!0),u=t.getInt32(a+12,!0),f=Jh(t,a+16,ud);s.push({width:l,height:c,originX:h,originY:u,name:f}),a+=o}return{ident:r,version:n,numFrames:i,frames:s}}var qr=class{constructor(t){this.vfs=t}async load(t){let r=await this.vfs.readFile(t),n=new Uint8Array(r.byteLength);return n.set(r),Ca(n.buffer)}};function hd(e,t){let r=(e.sequence.end-e.sequence.start+1)/e.sequence.fps,n=e.sequence.loop!==!1,i=e.time+t;return n?i=(i%r+r)%r:i>r&&(i=r),{...e,time:Math.max(0,Math.min(i,r))}}function md(e){let t=e.sequence.end-e.sequence.start+1,r=1/e.sequence.fps,n=e.sequence.loop!==!1,i=e.time/r;if(!n&&i>=t)return{frame0:e.sequence.end,frame1:e.sequence.end,lerp:0};let s=n?i%t:Math.min(i,t-1),o=Math.floor(s),a=e.sequence.start+o,d=o+1>=t?n?e.sequence.start:e.sequence.end:a+1,l=!n&&o>=t-1?0:s-o;return{frame0:a,frame1:d,lerp:l}}function pd(e){return{sequence:e,time:0}}function gd(e,t,r){return{x:e.x+(t.x-e.x)*r,y:e.y+(t.y-e.y)*r,z:e.z+(t.z-e.z)*r}}var $n=class extends Error{constructor(t){super(t),this.name="WalParseError"}};function Rs(e){if(e.byteLength<100)throw new $n("WAL buffer too small");let t=new DataView(e),r=new Uint8Array(e,0,32),n=new TextDecoder("utf-8").decode(r).replace(/\0.*$/,"").trim(),i=t.getInt32(32,!0),s=t.getInt32(36,!0),o=[t.getInt32(40,!0),t.getInt32(44,!0),t.getInt32(48,!0),t.getInt32(52,!0)],a=new Uint8Array(e,56,32),d=new TextDecoder("utf-8").decode(a).replace(/\0.*$/,"").trim(),l=t.getInt32(88,!0),c=t.getInt32(92,!0),h=t.getInt32(96,!0);if(i<=0||s<=0)throw new $n("Invalid WAL dimensions");let u=[],f=i,m=s;for(let g=0;g<o.length;g+=1){let p=o[g],y=Math.max(1,f*m|0);if(p<=0||p+y>e.byteLength)throw new $n(`Invalid WAL mip offset for level ${g}`);let _=new Uint8Array(e,p,y);u.push({level:g,width:f,height:m,data:_}),f=Math.max(1,f>>1),m=Math.max(1,m>>1)}return{name:n,width:i,height:s,mipmaps:u,animName:d,flags:l,contents:c,value:h}}var hr=class extends Error{constructor(t){super(t),this.name="PcxParseError"}};function Kn(e){if(e.byteLength<128)throw new hr("PCX buffer too small for header");let t=new DataView(e),r=t.getUint8(0),n=t.getUint8(2),i=t.getUint8(3),s=t.getUint16(4,!0),o=t.getUint16(6,!0),a=t.getUint16(8,!0),d=t.getUint16(10,!0);if(r!==10||n!==1)throw new hr("Unsupported PCX encoding");if(i!==8)throw new hr("Only 8bpp PCX files are supported");let l=a-s+1,c=d-o+1,h=t.getUint16(66,!0),u=e.byteLength-769;if(u<128||new DataView(e,u,1).getUint8(0)!==12)throw new hr("Missing PCX palette");let f=new Uint8Array(e,u+1,768),m=new Uint8Array(e,128,u-128),g=new Uint8Array(l*c),p=0,y=0;for(let _=0;_<c;_+=1){let b=0;for(;b<h&&p<m.length;){let x=1,v=m[p++];if((v&192)===192){if(x=v&63,p>=m.length)throw new hr("Unexpected end of PCX RLE data");v=m[p++]}for(let A=0;A<x&&b<h;A+=1)b<l&&(g[y++]=v),b+=1}}return{width:l,height:c,bitsPerPixel:i,pixels:g,palette:f}}function Fs(e){let t=new Uint8Array(e.width*e.height*4);for(let r=0;r<e.pixels.length;r+=1){let n=e.pixels[r],i=n*3,s=r*4;t[s]=e.palette[i],t[s+1]=e.palette[i+1],t[s+2]=e.palette[i+2],t[s+3]=n===255?0:255}return t}var yt=class extends Error{constructor(t){super(t),this.name="TgaParseError"}};function Ra(e){let t=new DataView(e);if(e.byteLength<18)throw new yt("Buffer too small for TGA header");let r=t.getUint8(0),n=t.getUint8(1),i=t.getUint8(2),s=t.getUint16(12,!0),o=t.getUint16(14,!0),a=t.getUint8(16),d=t.getUint8(17);if(i!==2&&i!==10&&i!==3&&i!==11)throw new yt(`Unsupported TGA image type: ${i} (only RGB/Grayscale supported)`);if(a!==24&&a!==32&&a!==8)throw new yt(`Unsupported pixel depth: ${a} (only 8, 24, 32 bpp supported)`);let l=i>=9,c=i===3||i===11,h=a/8,u=18+r;if(n===1){let b=t.getUint16(5,!0),x=t.getUint8(7);u+=b*(x/8)}let f=s*o,m=new Uint8Array(f*4),g=(d&32)!==0,p=0,y=new Uint8Array(e),_=b=>{if(c){let x=y[u++];m[b]=x,m[b+1]=x,m[b+2]=x,m[b+3]=255}else{let x=y[u++],v=y[u++],A=y[u++],S=a===32?y[u++]:255;m[b]=A,m[b+1]=v,m[b+2]=x,m[b+3]=S}};if(l){let b=0;for(;b<f;){if(u>=e.byteLength)throw new yt("Unexpected end of TGA RLE data");let x=y[u++],v=(x&127)+1,A=(x&128)!==0;if(b+v>f)throw new yt("TGA RLE packet exceeds image bounds");if(A){let S=c?y[u]:y[u+2],M=c?y[u]:y[u+1],E=y[u],w=c?255:a===32?y[u+3]:255;u+=h;for(let T=0;T<v;T++){let F=(b+T)*4;m[F]=S,m[F+1]=M,m[F+2]=E,m[F+3]=w}}else for(let S=0;S<v;S++)_((b+S)*4);b+=v}}else for(let b=0;b<f;b++){if(u>=e.byteLength)throw new yt("Unexpected end of TGA data");_(b*4)}if(!g){let b=s*4,x=new Uint8Array(b);for(let v=0;v<o/2;v++){let A=v*b,S=(o-1-v)*b;x.set(m.subarray(A,A+b)),m.set(m.subarray(S,S+b),A),m.set(x,S)}}return{width:s,height:o,bitsPerPixel:32,pixels:m}}var jr=class{constructor(t={}){this.cache=new Nt(t.capacity??128)}get size(){return this.cache.size}get(t){return this.cache.get(t.toLowerCase())}set(t,r){this.cache.set(t.toLowerCase(),r)}clear(){this.cache.clear()}};function Fa(e,t){let r=[];for(let n of e.mipmaps){let i=new Uint8Array(n.width*n.height*4);for(let s=0;s<n.data.length;s+=1){let o=n.data[s],a=o*3,d=s*4;i[d]=t[a],i[d+1]=t[a+1],i[d+2]=t[a+2],i[d+3]=o===255?0:255}r.push({level:n.level,width:n.width,height:n.height,rgba:i})}return{width:e.width,height:e.height,levels:r,source:"wal"}}function zs(e){let t=Fs(e),r={level:0,width:e.width,height:e.height,rgba:t};return{width:e.width,height:e.height,levels:[r],source:"pcx"}}function yd(e){let t={level:0,width:e.width,height:e.height,rgba:e.pixels};return{width:e.width,height:e.height,levels:[t],source:"tga"}}function ks(e,t){return Fa(Rs(e),t)}var mr=class extends Error{constructor(t){super(t),this.name="WavParseError"}};function za(e,t,r){return new TextDecoder("ascii").decode(new Uint8Array(e.buffer,e.byteOffset+t,r))}function Ds(e){if(e.byteLength<44)throw new mr("WAV buffer too small");let t=new DataView(e);if(za(t,0,4)!=="RIFF"||za(t,8,4)!=="WAVE")throw new mr("Invalid WAV header");let r=12,n=-1,i=-1,s=0,o=0;for(;r+8<=e.byteLength;){let m=za(t,r,4),g=t.getUint32(r+4,!0),p=r+8;m==="fmt "?(n=p,s=g):m==="data"&&(i=p,o=g),r=p+g}if(n===-1||i===-1)throw new mr("Missing fmt or data chunk");let a=t.getUint16(n,!0),d=t.getUint16(n+2,!0),l=t.getUint32(n+4,!0),c=t.getUint16(n+14,!0);if(a!==1)throw new mr("Only PCM WAV is supported");let h=c/8,u=o/(h*d),f=new Float32Array(u*d);for(let m=0;m<u;m+=1)for(let g=0;g<d;g+=1){let p=m*d+g,y=i+p*h,_=0;if(c===8)_=t.getUint8(y),f[p]=(_-128)/128;else if(c===16)_=t.getInt16(y,!0),f[p]=_/32768;else if(c===24){let b=t.getUint8(y),x=t.getUint8(y+1),v=t.getInt8(y+2);_=b|x<<8|v<<16,f[p]=_/8388608}else throw new mr(`Unsupported bitsPerSample: ${c}`)}return{sampleRate:l,channels:d,bitsPerSample:c,samples:f}}var em=(e,t=4294967295,r=79764919)=>{let n=new Int32Array(256),i,s,o,a=t;for(i=0;i<256;i++){for(o=i<<24,s=8;s>0;--s)o=2147483648&o?o<<1^r:o<<1;n[i]=o}for(i=0;i<e.length;i++)a=a<<8^n[255&(a>>24^e[i])];return a};var ka=(e,t=em)=>{let r=p=>new Uint8Array(p.length/2).map(((y,_)=>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,y)=>i.set(p,y)));let s=new Uint8Array(e.length),o,a,d,l=!1,c=0,h=42,u=e.length>13&&e.substring(0,9)==="dynEncode",f=0;u&&(f=11,a=n(e.substring(9,f)),a<=1&&(f+=2,h=n(e.substring(11,f))),a===1&&(f+=8,d=(p=>new DataView(r(p).buffer).getInt32(0,!0))(e.substring(13,f))));let m=256-h;for(let p=f;p<e.length;p++)if(o=e.charCodeAt(p),o!==61||l){if(o===92&&p<e.length-5&&u){let y=e.charCodeAt(p+1);y!==117&&y!==85||(o=parseInt(e.substring(p+2,p+6),16),p+=5)}if(o>255){let y=i.get(o);y&&(o=y+127)}l&&(l=!1,o-=64),s[c++]=o<h&&o>0?o+m:o-h}else l=!0;let g=s.subarray(0,c);if(u&&a===1){let p=t(g);if(p!==d){let y="Decode failed crc32 validation";throw console.error("`simple-yenc`\n",y+`
1
+ "use strict";var Quake2Engine=(()=>{var of=Object.create;var xs=Object.defineProperty;var af=Object.getOwnPropertyDescriptor;var lf=Object.getOwnPropertyNames;var cf=Object.getPrototypeOf,df=Object.prototype.hasOwnProperty;var uf=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),aa=(e,t)=>{for(var r in t)xs(e,r,{get:t[r],enumerable:!0})},Bc=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of lf(t))!df.call(e,i)&&i!==r&&xs(e,i,{get:()=>t[i],enumerable:!(n=af(t,i))||n.enumerable});return e};var ff=(e,t,r)=>(r=e!=null?of(cf(e)):{},Bc(t||!e||!e.__esModule?xs(r,"default",{value:e,enumerable:!0}):r,e)),hf=e=>Bc(xs({},"__esModule",{value:!0}),e);var bd=uf((d_,xd)=>{"use strict";xd.exports=Worker});var Ox={};aa(Ox,{ATTN_IDLE:()=>Aa,ATTN_LOOP_NONE:()=>Sa,ATTN_NONE:()=>Nn,ATTN_NORM:()=>wa,ATTN_STATIC:()=>Ms,AssetDependencyError:()=>Tr,AssetDependencyTracker:()=>Vi,AssetManager:()=>po,AssetPreviewGenerator:()=>sa,AudioApi:()=>Xr,AudioContextController:()=>go,AudioRegistry:()=>gn,AudioRegistryError:()=>Ni,AudioSystem:()=>wo,BSP_SURFACE_FRAGMENT_SOURCE:()=>al,BSP_SURFACE_VERTEX_SOURCE:()=>ol,BSP_VERTEX_LAYOUT:()=>nl,BspLoader:()=>Kr,BspParseError:()=>Q,BspSurfacePipeline:()=>To,Camera:()=>zo,Command:()=>kn,CommandRegistry:()=>Nr,ConfigStringRegistry:()=>Wr,Cvar:()=>Hn,CvarRegistry:()=>Vr,DemoPlaybackController:()=>us,DemoReader:()=>Ct,DemoRecorder:()=>fs,DemoValidator:()=>ia,DynamicLightManager:()=>Eo,EngineHost:()=>Gr,EngineRuntime:()=>Vn,FileType:()=>Ec,FixedTimestepLoop:()=>ur,Framebuffer:()=>Mo,IndexBuffer:()=>xe,LruCache:()=>Nt,MAX_SOUND_CHANNELS:()=>On,MD2_FRAGMENT_SHADER:()=>ml,MD2_VERTEX_SHADER:()=>hl,MD3_FRAGMENT_SHADER:()=>wl,MD3_VERTEX_SHADER:()=>Sl,MapAnalyzer:()=>oa,Md2Loader:()=>Zr,Md2MeshBuffers:()=>Co,Md2ParseError:()=>pe,Md2Pipeline:()=>Ro,Md3Loader:()=>Yr,Md3ModelMesh:()=>ko,Md3ParseError:()=>Ge,Md3Pipeline:()=>Do,Md3SurfaceMesh:()=>Xi,MusicSystem:()=>Ao,NetworkMessageParser:()=>kt,PARTICLE_FRAGMENT_SHADER:()=>Ml,PARTICLE_VERTEX_SHADER:()=>Al,PROTOCOL_VERSION_RERELEASE:()=>Rn,PakArchive:()=>$r,PakIndexStore:()=>mo,PakIngestionError:()=>Ot,PakParseError:()=>Ve,PakValidationError:()=>fr,PakValidator:()=>Es,ParticleRenderer:()=>Bo,ParticleSystem:()=>Po,PlaybackState:()=>na,RERELEASE_KNOWN_PAKS:()=>La,SKYBOX_FRAGMENT_SHADER:()=>ul,SKYBOX_VERTEX_SHADER:()=>dl,SOUND_FULLVOLUME:()=>Pt,SOUND_LOOP_ATTENUATE:()=>Ma,ShaderProgram:()=>Le,SkyboxPipeline:()=>Io,SoundChannel:()=>st,SoundPrecache:()=>bo,SoundRegistry:()=>xo,SpriteLoader:()=>qr,SpriteParseError:()=>Ut,Texture2D:()=>yn,TextureCache:()=>jr,TextureCubeMap:()=>xn,TgaParseError:()=>yt,U_ALPHA:()=>hc,U_ANGLE1:()=>uc,U_ANGLE2:()=>sc,U_ANGLE3:()=>oc,U_EFFECTS16:()=>ea,U_EFFECTS8:()=>jo,U_EVENT:()=>lc,U_FRAME16:()=>mc,U_FRAME8:()=>ac,U_INSTANCE_BITS:()=>Sc,U_LOOP_ATTENUATION_HIGH:()=>Ac,U_LOOP_VOLUME:()=>wc,U_MODEL:()=>fc,U_MODEL2:()=>pc,U_MODEL3:()=>gc,U_MODEL4:()=>yc,U_OLDORIGIN:()=>xc,U_OLD_FRAME_HIGH:()=>Lc,U_ORIGIN1:()=>nc,U_ORIGIN2:()=>ic,U_ORIGIN3:()=>dc,U_OWNER_HIGH:()=>Mc,U_REMOVE:()=>cc,U_RENDERFX16:()=>Jo,U_RENDERFX8:()=>qo,U_SCALE:()=>vc,U_SKIN16:()=>ta,U_SKIN8:()=>Qo,U_SOLID:()=>_c,U_SOUND:()=>bc,VertexArray:()=>Fe,VertexBuffer:()=>Ee,VirtualFileSystem:()=>Ls,advanceAnimation:()=>hd,applySurfaceState:()=>ou,attenuationToDistanceMultiplier:()=>Bt,boxIntersectsFrustum:()=>Wi,buildBspGeometry:()=>Jd,buildMd2Geometry:()=>pl,buildMd2VertexData:()=>gl,buildMd3SurfaceGeometry:()=>_l,buildMd3VertexData:()=>vl,calculateMaxAudibleDistance:()=>Un,calculatePakChecksum:()=>td,computeFrameBlend:()=>md,computeSkyScroll:()=>cu,createAnimationState:()=>pd,createAudioGraph:()=>yo,createBspSurfaces:()=>Qd,createEmptyEntityState:()=>Br,createEmptyProtocolPlayerState:()=>ds,createEngine:()=>Bx,createEngineRuntime:()=>Jc,createFaceLightmap:()=>Is,createInitialChannels:()=>_o,createProgramFromSources:()=>jd,createWebGLContext:()=>Yd,decodeOgg:()=>ho,deriveSurfaceRenderState:()=>cl,detectFileType:()=>Tc,extractFrustumPlanes:()=>eu,filesToPakSources:()=>Ea,findLeafForPoint:()=>sl,gatherVisibleFaces:()=>iu,groupMd2Animations:()=>cd,ingestPakFiles:()=>rd,ingestPaks:()=>Ts,interpolateMd3Tag:()=>Eu,interpolateVec3:()=>gd,isBinaryFile:()=>tf,isTextFile:()=>Ic,parseBsp:()=>Gn,parseMd2:()=>Ta,parseMd3:()=>Ia,parsePcx:()=>Kn,parseSprite:()=>Ca,parseTga:()=>Ra,parseWal:()=>Rs,parseWalTexture:()=>ks,parseWav:()=>Ds,pcxToRgba:()=>Fs,pickChannel:()=>vo,preparePcxTexture:()=>zs,removeViewTranslation:()=>lu,resolveLightStyles:()=>ll,spatializeOrigin:()=>So,spawnBlood:()=>Cu,spawnBulletImpact:()=>Tu,spawnExplosion:()=>Iu,spawnMuzzleFlash:()=>Fu,spawnTeleportFlash:()=>Ru,spawnTrail:()=>zu,walToRgba:()=>Fa,wireDropTarget:()=>nd,wireFileInput:()=>id});var mf=()=>typeof performance<"u"?performance.now():Date.now(),pf=e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>e()):setTimeout(e,25)},ur=class{constructor(t,r={}){this.callbacks=t;this.accumulatorMs=0;this.frame=0;this.running=!1;this.tick=()=>{if(!this.running)return;let t=this.options.now(),r=this.lastTimeMs===void 0?0:t-this.lastTimeMs;this.lastTimeMs=t,this.advance(r,t),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??mf,schedule:r.schedule??pf}}start(){this.running||(this.running=!0,this.lastTimeMs=this.options.startTimeMs??this.options.now(),this.options.schedule(this.tick))}stop(){this.running=!1}pump(t){let r=(this.lastTimeMs??0)+t;this.lastTimeMs=r,this.advance(t,r)}isRunning(){return this.running}get frameNumber(){return this.frame}advance(t,r){let n=Math.min(Math.max(t,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 s=this.options.fixedDeltaMs===0?0:this.accumulatorMs/this.options.fixedDeltaMs;this.callbacks.render?.({alpha:s,nowMs:r,accumulatorMs:this.accumulatorMs,frame:this.frame})}};var kn=class{constructor(t,r,n){this.name=t,this.callback=r,this.description=n}execute(t){this.callback(t)}},Nr=class{constructor(){this.commands=new Map;this.history=[];this.historyLimit=64;this.autocompleteProviders=[]}register(t,r,n){let i=new kn(t,r,n);return this.commands.set(t,i),i}registerCommand(t,r){this.register(t,r)}registerAutocompleteProvider(t){this.autocompleteProviders.push(t)}get(t){return this.commands.get(t)}execute(t){let r=t.trim();if(r.length===0)return!1;(this.history.length===0||this.history[this.history.length-1]!==r)&&(this.history.push(r),this.history.length>this.historyLimit&&this.history.shift());let n=this.tokenize(t);if(n.length===0)return!1;let i=n[0],s=n.slice(1),o=this.get(i);return o?(o.execute(s),!0):(this.onConsoleOutput?.(`Unknown command "${i}"`),!1)}executeCommand(t){this.execute(t)}getHistory(){return[...this.history]}getSuggestions(t){let r=new Set;for(let n of this.commands.keys())n.startsWith(t)&&r.add(n);for(let n of this.autocompleteProviders){let i=n();for(let s of i)s.startsWith(t)&&r.add(s)}return Array.from(r).sort()}tokenize(t){let r=[],n="",i=!1;for(let s=0;s<t.length;s++){let o=t[s];o==='"'?i=!i:o===" "&&!i?n.length>0&&(r.push(n),n=""):n+=o}return n.length>0&&r.push(n),r}list(){return[...this.commands.values()].sort((t,r)=>t.name.localeCompare(r.name))}};var gf=Object.defineProperty,Oc=(e,t)=>{for(var r in t)gf(e,r,{get:t[r],enumerable:!0})},Nc={x:0,y:0,z:0};var Vx=Math.PI/180;function Uc(e,t){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}function yf(e,t){return{x:e.x*t,y:e.y*t,z:e.z*t}}function da(e,t){return e.x*t.x+e.y*t.y+e.z*t.z}function xf(e){return da(e,e)}function ua(e){return Math.sqrt(xf(e))}function Je(e){let t=ua(e);return t===0?e:yf(e,1/t)}var bf=Math.PI/180,_f=180/Math.PI,Hr=bf,fa=_f;var ca=[[-.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 vf(){return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function Hc(e,t){let r=t.x,n=t.y,i=t.z;return{x:e[0]*r+e[4]*n+e[8]*i+e[12],y:e[1]*r+e[5]*n+e[9]*i+e[13],z:e[2]*r+e[6]*n+e[10]*i+e[14]}}function Vc(e,t){let r=vf();return r[0]=t[0].x,r[1]=t[0].y,r[2]=t[0].z,r[4]=t[1].x,r[5]=t[1].y,r[6]=t[1].z,r[8]=t[2].x,r[9]=t[2].y,r[10]=t[2].z,r[12]=e.x,r[13]=e.y,r[14]=e.z,r}var it=1,Dt=2;var ha=8,ma=16,Sf=32;var wf=16384;var bs=65536,Gc=1<<17,Af=1<<18,Mf=1<<19,Lf=1<<20,Ef=1<<21,Tf=1<<22,If=1<<23,Gx=1<<24,_s=1<<25,Cf=1<<26,Wx=1<<27,Xx=1<<28,$x=1<<29,vs=1<<30,Kx=1<<31;var Pn=0;var Wc=4,Xc=8,$c=16,Kc=32,Zc=64;var Zx=1<<25,Yx=1<<28,qx=1<<29,jx=1<<30,Qx=1<<31;var Jx=it|Dt,eb=it|bs|Dt|_s|vs,tb=it|bs|Dt,rb=it|Gc|Dt|_s|vs,nb=Sf|ha|ma,ib=it|ma|ha,Rf=it|_s|vs|Dt|Cf,sb=Af|Mf|Lf|Ef|Tf|If,ob=it|ha|ma|_s|vs,ab=it|bs|Dt,lb=it|Dt,cb=it|bs|Dt|Gc,db=Rf|wf;var ub=Number.MAX_SAFE_INTEGER-1;var Ss=(e=>(e[e.None=0]="None",e[e.Archive=1]="Archive",e[e.UserInfo=2]="UserInfo",e[e.ServerInfo=4]="ServerInfo",e[e.Latch=8]="Latch",e[e.Cheat=16]="Cheat",e))(Ss||{});var ws=256;var pa=256,ga=8192,As=2048,ya=512,xa=256,ba=ws*2,_a=256,la=32,Dn=96;var j=(e=>(e[e.Name=0]="Name",e[e.CdTrack=1]="CdTrack",e[e.Sky=2]="Sky",e[e.SkyAxis=3]="SkyAxis",e[e.SkyRotate=4]="SkyRotate",e[e.StatusBar=5]="StatusBar",e[e.HealthBarName=55]="HealthBarName",e[e.CONFIG_N64_PHYSICS=56]="CONFIG_N64_PHYSICS",e[e.CONFIG_CTF_TEAMS=57]="CONFIG_CTF_TEAMS",e[e.CONFIG_COOP_RESPAWN_STRING=58]="CONFIG_COOP_RESPAWN_STRING",e[e.Story=54]="Story",e[e.AirAccel=59]="AirAccel",e[e.MaxClients=60]="MaxClients",e[e.MapChecksum=61]="MapChecksum",e[e.Models=62]="Models",e[e.Sounds=62+ga]="Sounds",e[e.Images=e.Sounds+As]="Images",e[e.Lights=e.Images+ya]="Lights",e[e.ShadowLights=e.Lights+pa]="ShadowLights",e[e.Items=e.ShadowLights+_a]="Items",e[e.PlayerSkins=e.Items+xa]="PlayerSkins",e[e.General=e.PlayerSkins+ws]="General",e[e.WheelWeapons=e.General+ba]="WheelWeapons",e[e.WheelAmmo=e.WheelWeapons+la]="WheelAmmo",e[e.WheelPowerups=e.WheelAmmo+la]="WheelPowerups",e[e.CdLoopCount=e.WheelPowerups+la]="CdLoopCount",e[e.GameStyle=e.CdLoopCount+1]="GameStyle",e[e.MaxConfigStrings=e.GameStyle+1]="MaxConfigStrings",e))(j||{}),Yc=j.MaxConfigStrings;function qc(e){return e>=5&&e<59?Dn*(59-e):e>=j.General&&e<j.WheelWeapons?Dn*(j.MaxConfigStrings-e):Dn}var Ff={};Oc(Ff,{addReplayFrame:()=>Pf,createReplaySession:()=>Df,deserializeReplay:()=>kf,serializeReplay:()=>zf});function zf(e){return JSON.stringify(e,null,2)}function kf(e){let t=JSON.parse(e);if(!t.metadata||!Array.isArray(t.frames))throw new Error("Invalid replay format: missing metadata or frames");return t}function Df(e,t){return{metadata:{map:e,date:new Date().toISOString(),version:"1.0",seed:t},frames:[]}}function Pf(e,t,r,n){e.frames.push({serverFrame:r,cmd:t,timestamp:Date.now()-n})}var z=(e=>(e[e.bad=0]="bad",e[e.muzzleflash=1]="muzzleflash",e[e.muzzleflash2=2]="muzzleflash2",e[e.temp_entity=3]="temp_entity",e[e.layout=4]="layout",e[e.inventory=5]="inventory",e[e.nop=6]="nop",e[e.disconnect=7]="disconnect",e[e.reconnect=8]="reconnect",e[e.sound=9]="sound",e[e.print=10]="print",e[e.stufftext=11]="stufftext",e[e.serverdata=12]="serverdata",e[e.configstring=13]="configstring",e[e.spawnbaseline=14]="spawnbaseline",e[e.centerprint=15]="centerprint",e[e.download=16]="download",e[e.playerinfo=17]="playerinfo",e[e.packetentities=18]="packetentities",e[e.deltapacketentities=19]="deltapacketentities",e[e.frame=20]="frame",e[e.splitclient=21]="splitclient",e[e.configblast=22]="configblast",e[e.spawnbaselineblast=23]="spawnbaselineblast",e[e.level_restart=24]="level_restart",e[e.damage=25]="damage",e[e.locprint=26]="locprint",e[e.fog=27]="fog",e[e.waitingforplayers=28]="waitingforplayers",e[e.bot_chat=29]="bot_chat",e[e.poi=30]="poi",e[e.help_path=31]="help_path",e[e.muzzleflash3=32]="muzzleflash3",e[e.achievement=33]="achievement",e))(z||{});var I=(e=>(e[e.GUNSHOT=0]="GUNSHOT",e[e.BLOOD=1]="BLOOD",e[e.BLASTER=2]="BLASTER",e[e.RAILTRAIL=3]="RAILTRAIL",e[e.SHOTGUN=4]="SHOTGUN",e[e.EXPLOSION1=5]="EXPLOSION1",e[e.EXPLOSION2=6]="EXPLOSION2",e[e.ROCKET_EXPLOSION=7]="ROCKET_EXPLOSION",e[e.GRENADE_EXPLOSION=8]="GRENADE_EXPLOSION",e[e.SPARKS=9]="SPARKS",e[e.SPLASH=10]="SPLASH",e[e.BUBBLETRAIL=11]="BUBBLETRAIL",e[e.SCREEN_SPARKS=12]="SCREEN_SPARKS",e[e.SHIELD_SPARKS=13]="SHIELD_SPARKS",e[e.BULLET_SPARKS=14]="BULLET_SPARKS",e[e.LASER_SPARKS=15]="LASER_SPARKS",e[e.PARASITE_ATTACK=16]="PARASITE_ATTACK",e[e.ROCKET_EXPLOSION_WATER=17]="ROCKET_EXPLOSION_WATER",e[e.GRENADE_EXPLOSION_WATER=18]="GRENADE_EXPLOSION_WATER",e[e.MEDIC_CABLE_ATTACK=19]="MEDIC_CABLE_ATTACK",e[e.BFG_EXPLOSION=20]="BFG_EXPLOSION",e[e.BFG_BIGEXPLOSION=21]="BFG_BIGEXPLOSION",e[e.BOSSTPORT=22]="BOSSTPORT",e[e.BFG_LASER=23]="BFG_LASER",e[e.GRAPPLE_CABLE=24]="GRAPPLE_CABLE",e[e.WELDING_SPARKS=25]="WELDING_SPARKS",e[e.GREENBLOOD=26]="GREENBLOOD",e[e.BLUEHYPERBLASTER=27]="BLUEHYPERBLASTER",e[e.PLASMA_EXPLOSION=28]="PLASMA_EXPLOSION",e[e.TUNNEL_SPARKS=29]="TUNNEL_SPARKS",e[e.BLASTER2=30]="BLASTER2",e[e.RAILTRAIL2=31]="RAILTRAIL2",e[e.FLAME=32]="FLAME",e[e.LIGHTNING=33]="LIGHTNING",e[e.DEBUGTRAIL=34]="DEBUGTRAIL",e[e.PLAIN_EXPLOSION=35]="PLAIN_EXPLOSION",e[e.FLASHLIGHT=36]="FLASHLIGHT",e[e.FORCEWALL=37]="FORCEWALL",e[e.HEATBEAM=38]="HEATBEAM",e[e.MONSTER_HEATBEAM=39]="MONSTER_HEATBEAM",e[e.STEAM=40]="STEAM",e[e.BUBBLETRAIL2=41]="BUBBLETRAIL2",e[e.MOREBLOOD=42]="MOREBLOOD",e[e.HEATBEAM_SPARKS=43]="HEATBEAM_SPARKS",e[e.HEATBEAM_STEAM=44]="HEATBEAM_STEAM",e[e.CHAINFIST_SMOKE=45]="CHAINFIST_SMOKE",e[e.ELECTRIC_SPARKS=46]="ELECTRIC_SPARKS",e[e.TRACKER_EXPLOSION=47]="TRACKER_EXPLOSION",e[e.TELEPORT_EFFECT=48]="TELEPORT_EFFECT",e[e.DBALL_GOAL=49]="DBALL_GOAL",e[e.WIDOWBEAMOUT=50]="WIDOWBEAMOUT",e[e.NUKEBLAST=51]="NUKEBLAST",e[e.WIDOWSPLASH=52]="WIDOWSPLASH",e[e.EXPLOSION1_BIG=53]="EXPLOSION1_BIG",e[e.EXPLOSION1_NP=54]="EXPLOSION1_NP",e[e.FLECHETTE=55]="FLECHETTE",e[e.BLUEHYPERBLASTER_KEX=56]="BLUEHYPERBLASTER_KEX",e[e.BFG_ZAP=57]="BFG_ZAP",e[e.BERSERK_SLAM=58]="BERSERK_SLAM",e[e.GRAPPLE_CABLE_2=59]="GRAPPLE_CABLE_2",e[e.POWER_SPLASH=60]="POWER_SPLASH",e[e.LIGHTNING_BEAM=61]="LIGHTNING_BEAM",e[e.EXPLOSION1_NL=62]="EXPLOSION1_NL",e[e.EXPLOSION2_NL=63]="EXPLOSION2_NL",e))(I||{});var Bf=12,Of=9,fb=Math.ceil(Bf*Of/16),Nf=23,Uf=2,hb=Math.ceil(Nf*Uf/16);var Hf={};Oc(Hf,{U_ANGLE1:()=>Zf,U_ANGLE2:()=>Yf,U_ANGLE3:()=>qf,U_EFFECTS:()=>Jf,U_EVENT:()=>rh,U_FRAME:()=>jf,U_MODEL:()=>Gf,U_MODEL2:()=>ih,U_MODEL3:()=>sh,U_MODEL4:()=>oh,U_MOREBITS:()=>nh,U_NUMBER:()=>Vf,U_ORIGIN1:()=>Xf,U_ORIGIN2:()=>$f,U_ORIGIN3:()=>Kf,U_REMOVE:()=>ah,U_RENDERFX:()=>eh,U_SKIN:()=>Qf,U_SOLID:()=>th,U_SOUND:()=>Wf});var Vf=1,Gf=2,Wf=4,Xf=8,$f=16,Kf=32,Zf=64,Yf=128,qf=256,jf=512,Qf=1024,Jf=2048,eh=4096,th=8192,rh=16384,nh=32768,ih=1,sh=2,oh=4,ah=32768;var Bn=class{constructor(e){e instanceof Uint8Array?this.view=new DataView(e.buffer,e.byteOffset,e.byteLength):this.view=new DataView(e),this.offset=0,this.length=this.view.byteLength}getPosition(){return this.offset}getLength(){return this.length}seek(e){if(e<0||e>this.length)throw new Error(`Seek out of bounds: ${e} (length: ${this.length})`);this.offset=e}hasMore(){return this.offset<this.length}readChar(){let e=this.view.getInt8(this.offset);return this.offset+=1,e}readByte(){let e=this.view.getUint8(this.offset);return this.offset+=1,e}readShort(){let e=this.view.getInt16(this.offset,!0);return this.offset+=2,e}readUShort(){let e=this.view.getUint16(this.offset,!0);return this.offset+=2,e}readLong(){let e=this.view.getInt32(this.offset,!0);return this.offset+=4,e}readULong(){let e=this.view.getUint32(this.offset,!0);return this.offset+=4,e}readFloat(){let e=this.view.getFloat32(this.offset,!0);return this.offset+=4,e}readString(){let e="";for(;this.offset<this.length;){let t=this.readChar();if(t===-1||t===0)break;e+=String.fromCharCode(t)}return e}readStringLine(){let e="";for(;this.offset<this.length;){let t=this.readChar();if(t===-1||t===0||t===10)break;e+=String.fromCharCode(t)}return e}readCoord(){return this.readShort()*(1/8)}readAngle(){return this.readChar()*(360/256)}readAngle16(){return this.readShort()*360/65536}readData(e){if(this.offset+e>this.length)throw new Error(`Read out of bounds: ${this.offset+e} (length: ${this.length})`);let t=new Uint8Array(this.view.buffer,this.view.byteOffset+this.offset,e);return this.offset+=e,new Uint8Array(t)}readPos(e){e.x=this.readCoord(),e.y=this.readCoord(),e.z=this.readCoord()}readDir(e){let t=this.readByte();if(t>=162){e.x=0,e.y=0,e.z=0;return}let r=ca[t];e.x=r[0],e.y=r[1],e.z=r[2]}},va=class{constructor(e=1400){typeof e=="number"?(this.buffer=new Uint8Array(e),this.fixed=!1):(this.buffer=e,this.fixed=!0),this.view=new DataView(this.buffer.buffer,this.buffer.byteOffset,this.buffer.byteLength),this.offset=0}ensureSpace(e){if(this.offset+e>this.buffer.byteLength){if(this.fixed)throw new Error(`Buffer overflow: capacity ${this.buffer.byteLength}, needed ${this.offset+e}`);let t=Math.max(this.buffer.byteLength*2,this.offset+e),r=new Uint8Array(t);r.set(this.buffer),this.buffer=r,this.view=new DataView(this.buffer.buffer,this.buffer.byteOffset,this.buffer.byteLength)}}writeByte(e){this.ensureSpace(1),this.view.setUint8(this.offset,e),this.offset+=1}writeChar(e){this.ensureSpace(1),this.view.setInt8(this.offset,e),this.offset+=1}writeShort(e){this.ensureSpace(2),this.view.setInt16(this.offset,e,!0),this.offset+=2}writeLong(e){this.ensureSpace(4),this.view.setInt32(this.offset,e,!0),this.offset+=4}writeFloat(e){this.ensureSpace(4),this.view.setFloat32(this.offset,e,!0),this.offset+=4}writeString(e){let t=e.length;this.ensureSpace(t+1);for(let r=0;r<t;r++)this.view.setUint8(this.offset+r,e.charCodeAt(r));this.view.setUint8(this.offset+t,0),this.offset+=t+1}writeCoord(e){this.writeShort(Math.trunc(e*8))}writeAngle(e){this.writeByte(Math.trunc(e*256/360)&255)}writeAngle16(e){this.writeShort(Math.trunc(e*65536/360)&65535)}writePos(e){this.writeCoord(e.x),this.writeCoord(e.y),this.writeCoord(e.z)}writeDir(e){let t=-1,r=0;if(e.x===0&&e.y===0&&e.z===0){this.writeByte(0);return}for(let n=0;n<ca.length;n++){let i=ca[n],s=e.x*i[0]+e.y*i[1]+e.z*i[2];s>t&&(t=s,r=n)}this.writeByte(r)}getData(){return this.buffer.slice(0,this.offset)}getBuffer(){return this.buffer}getOffset(){return this.offset}reset(){this.offset=0}};var Ur=class me{constructor(){this.qport=0,this.incomingSequence=0,this.outgoingSequence=0,this.incomingAcknowledged=0,this.incomingReliableAcknowledged=!1,this.incomingReliableSequence=0,this.outgoingReliableSequence=0,this.reliableLength=0,this.fragmentSendOffset=0,this.fragmentBuffer=null,this.fragmentLength=0,this.fragmentReceived=0,this.lastReceived=0,this.lastSent=0,this.remoteAddress=null,this.reliableMessage=new va(me.MAX_RELIABLE_BUFFER);let t=Date.now();this.lastReceived=t,this.lastSent=t,this.qport=Math.floor(Math.random()*65536)}setup(t,r=null){this.qport=t,this.remoteAddress=r,this.reset()}reset(){this.incomingSequence=0,this.outgoingSequence=0,this.incomingAcknowledged=0,this.incomingReliableAcknowledged=!1,this.incomingReliableSequence=0,this.outgoingReliableSequence=0,this.reliableLength=0,this.reliableMessage.reset(),this.fragmentSendOffset=0,this.fragmentBuffer=null,this.fragmentLength=0,this.fragmentReceived=0,this.lastReceived=Date.now(),this.lastSent=Date.now()}transmit(t){this.outgoingSequence++,this.lastSent=Date.now();let r=0,n=!1,i=0;this.reliableLength>0&&(this.reliableLength>me.FRAGMENT_SIZE?(n=!0,this.fragmentSendOffset>=this.reliableLength&&(this.fragmentSendOffset=0),r=this.reliableLength-this.fragmentSendOffset,r>me.FRAGMENT_SIZE&&(r=me.FRAGMENT_SIZE),i=this.fragmentSendOffset,this.fragmentSendOffset+=r):r=this.reliableLength);let s=me.PACKET_HEADER,o=r>0?2+(n?8:0):0,a=t?t.length:0;s+o+r+a>me.MAX_MSGLEN&&(a=me.MAX_MSGLEN-s-o-r,a<0&&(a=0));let d=new ArrayBuffer(s+o+r+a),l=new DataView(d),c=new Uint8Array(d),h=this.outgoingSequence;r>0&&(h|=2147483648,(this.outgoingReliableSequence&1)!==0&&(h|=1073741824)),l.setUint32(0,h,!0);let u=this.incomingSequence;(this.incomingReliableSequence&1)!==0&&(u|=2147483648),l.setUint32(4,u,!0),l.setUint16(8,this.qport,!0);let f=s;if(r>0){let m=r;n&&(m|=32768),l.setUint16(f,m,!0),f+=2,n&&(l.setUint32(f,i,!0),f+=4,l.setUint32(f,this.reliableLength,!0),f+=4);let p=this.reliableMessage.getBuffer().subarray(i,i+r);c.set(p,f),f+=r}if(t&&a>0){let m=t.slice(0,a);c.set(m,f)}return c}process(t){if(t.length<me.PACKET_HEADER)return null;this.lastReceived=Date.now();let r=new DataView(t.buffer,t.byteOffset,t.byteLength),n=r.getUint32(0,!0),i=r.getUint32(4,!0),s=r.getUint16(8,!0);if(this.qport!==s)return null;let o=n&1073741823;if((o-this.incomingSequence|0)<=0)return null;this.incomingSequence=o;let a=i&2147483647,d=(i&2147483648)!==0;if(a>this.incomingAcknowledged&&(this.incomingAcknowledged=a),this.reliableLength>0){let m=d?1:0,g=this.outgoingReliableSequence&1;m!==g&&(this.reliableLength=0,this.reliableMessage.reset(),this.outgoingReliableSequence^=1,this.fragmentSendOffset=0)}let l=(n&2147483648)!==0,c=(n&1073741824)!==0?1:0,h=me.PACKET_HEADER,u=null;if(l){if(h+2>t.byteLength)return null;let m=r.getUint16(h,!0);h+=2;let g=(m&32768)!==0;m&=32767;let p=this.incomingReliableSequence&1;if(c===p)if(g){if(h+8>t.byteLength)return null;let y=r.getUint32(h,!0);h+=4;let _=r.getUint32(h,!0);if(h+=4,_>me.MAX_RELIABLE_BUFFER)return console.warn(`NetChan: received invalid fragment total ${_} > ${me.MAX_RELIABLE_BUFFER}`),null;if((!this.fragmentBuffer||this.fragmentBuffer.length!==_)&&(this.fragmentBuffer=new Uint8Array(_),this.fragmentLength=_,this.fragmentReceived=0),h+m>t.byteLength)return null;let b=t.subarray(h,h+m);y===this.fragmentReceived&&y+m<=_&&(this.fragmentBuffer.set(b,y),this.fragmentReceived+=m,this.fragmentReceived>=_&&(u=this.fragmentBuffer,this.incomingReliableSequence++,this.fragmentBuffer=null,this.fragmentLength=0,this.fragmentReceived=0))}else{if(this.incomingReliableSequence++,h+m>t.byteLength)return null;u=t.slice(h,h+m)}h+=m}let f=t.slice(h);if(u&&u.length>0){let m=u.length+f.length,g=new Uint8Array(m);return g.set(u,0),g.set(f,u.length),g}return f||new Uint8Array(0)}canSendReliable(){return this.reliableLength===0}writeReliableByte(t){if(this.reliableLength+1>me.MAX_RELIABLE_BUFFER)throw new Error("NetChan reliable buffer overflow");this.reliableMessage.writeByte(t),this.reliableLength++}writeReliableShort(t){if(this.reliableLength+2>me.MAX_RELIABLE_BUFFER)throw new Error("NetChan reliable buffer overflow");this.reliableMessage.writeShort(t),this.reliableLength+=2}writeReliableLong(t){if(this.reliableLength+4>me.MAX_RELIABLE_BUFFER)throw new Error("NetChan reliable buffer overflow");this.reliableMessage.writeLong(t),this.reliableLength+=4}writeReliableString(t){let r=t.length+1;if(this.reliableLength+r>me.MAX_RELIABLE_BUFFER)throw new Error("NetChan reliable buffer overflow");this.reliableMessage.writeString(t),this.reliableLength+=r}getReliableData(){return this.reliableLength===0?new Uint8Array(0):this.reliableMessage.getBuffer().subarray(0,this.reliableLength)}needsKeepalive(t){return t-this.lastSent>1e3}isTimedOut(t,r=3e4){return t-this.lastReceived>r}};Ur.MAX_MSGLEN=1400;Ur.FRAGMENT_SIZE=1024;Ur.PACKET_HEADER=10;Ur.HEADER_OVERHEAD=Ur.PACKET_HEADER+2;Ur.MAX_RELIABLE_BUFFER=262144;var jc=(e=>(e[e.Bullets=0]="Bullets",e[e.Shells=1]="Shells",e[e.Rockets=2]="Rockets",e[e.Grenades=3]="Grenades",e[e.Cells=4]="Cells",e[e.Slugs=5]="Slugs",e[e.MagSlugs=6]="MagSlugs",e[e.Trap=7]="Trap",e[e.Flechettes=8]="Flechettes",e[e.Tesla=9]="Tesla",e[e.Disruptor=10]="Disruptor",e[e.Prox=11]="Prox",e[e.Nuke=12]="Nuke",e[e.Rounds=13]="Rounds",e))(jc||{}),mb=Object.keys(jc).length/2;var On=32,st=(e=>(e[e.Auto=0]="Auto",e[e.Weapon=1]="Weapon",e[e.Voice=2]="Voice",e[e.Item=3]="Item",e[e.Body=4]="Body",e[e.Aux=5]="Aux",e[e.Footstep=6]="Footstep",e[e.Aux3=7]="Aux3",e[e.NoPhsAdd=8]="NoPhsAdd",e[e.Reliable=16]="Reliable",e[e.ForcePos=32]="ForcePos",e))(st||{}),Sa=-1,Nn=0,wa=1,Aa=2,Ms=3,Pt=80,Ma=.003;function Bt(e){return e===Ms?e*.001:e*5e-4}function Un(e){let t=Bt(e);return t<=0?Number.POSITIVE_INFINITY:Pt+1/t}var Hn=class{constructor({name:t,defaultValue:r,description:n,flags:i=Ss.None,onChange:s}){this.modifiedCount=0;this.name=t,this.defaultValue=r,this.description=n,this.flags=i,this._value=r,this.onChange=s}get string(){return this._value}get number(){return Number(this._value)}get integer(){return Math.trunc(this.number)}get boolean(){return!!this.integer}set(t){if(this.flags&Ss.Latch){if(t===this._value){this.latched=void 0;return}if(this.latched===t)return;this.latched!==t&&(this.latched=t);return}this.apply(t)}reset(){this.latched=void 0,this.apply(this.defaultValue)}applyLatched(){if(this.latched===void 0)return!1;let t=this.latched;return this.latched=void 0,t===this._value?!1:(this.apply(t),!0)}apply(t){if(this._value===t)return;let r=this._value;this._value=t,this.modifiedCount+=1,this.onChange?.(this,r)}},Vr=class{constructor(){this.cvars=new Map}register(t){let r=this.cvars.get(t.name);if(r)return r;let n=t.onChange,i=(o,a)=>{n?.(o,a),this.onCvarChange?.(o.name,o.string)},s=new Hn({...t,onChange:i});return this.cvars.set(t.name,s),s}get(t){return this.cvars.get(t)}getCvar(t){return this.get(t)}setValue(t,r){let n=this.get(t);if(!n)throw new Error(`Unknown cvar: ${t}`);return n.set(r),n}setCvar(t,r){this.setValue(t,r)}resetAll(){for(let t of this.cvars.values())t.reset()}applyLatched(){let t=!1;for(let r of this.cvars.values())t=r.applyLatched()||t;return t}list(){return[...this.cvars.values()].sort((t,r)=>t.name.localeCompare(r.name))}listCvars(){return this.list().map(t=>({name:t.name,value:t.string,defaultValue:t.defaultValue,flags:t.flags,description:t.description}))}};var Gr=class{constructor(t,r,n={}){this.game=t;this.client=r;this.started=!1;this.commands=new Nr;this.cvars=new Vr;this.stepSimulation=t=>{this.previousFrame=this.latestFrame,this.latestFrame=this.game.frame(t,this.latestCommand)};this.renderClient=t=>{this.client&&(this.latestCommand=this.client.render({...t,previous:this.previousFrame,latest:this.latestFrame}))};let i=n.loop?.now?.()??Date.now();this.startTimeMs=n.startTimeMs??n.loop?.startTimeMs??i,this.loop=new ur({simulate:this.stepSimulation,render:this.renderClient},{...n.loop,startTimeMs:this.startTimeMs}),this.commands.registerAutocompleteProvider(()=>this.cvars.list().map(s=>s.name))}start(){if(!this.started){try{this.latestFrame=this.game.init(this.startTimeMs)??this.latestFrame,this.client?.init(this.latestFrame)}catch(t){throw this.game.shutdown(),this.client?.shutdown(),t}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(t){this.loop.pump(t)}getLatestFrame(){return this.latestFrame}isRunning(){return this.loop.isRunning()}};function lh(e){if(e<0||e>=j.MaxConfigStrings)throw new RangeError(`Configstring index ${e} is out of range (0-${j.MaxConfigStrings-1})`)}function Qc(e,t){let r=qc(e);if(t.length>r)throw new RangeError(`Configstring ${e} exceeds maximum length (${t.length} > ${r}); limit is ${Dn} chars per slot`)}var Wr=class{constructor(){this.values=new Map;this.modelCursor=j.Models;this.soundCursor=j.Sounds;this.imageCursor=j.Images;this.lightCursor=j.Lights;this.shadowLightCursor=j.ShadowLights;this.itemCursor=j.Items;this.playerSkinCursor=j.PlayerSkins;this.generalCursor=j.General}set(t,r){return lh(t),Qc(t,r),this.values.set(t,r),t}get(t){return this.values.get(t)}getName(t){return this.get(t)}getAll(){let t=new Array(Yc).fill("");for(let[r,n]of this.values.entries())t[r]=n;return t}modelIndex(t){return this.register(t,j.Models,ga,"modelCursor")}soundIndex(t){return this.register(t,j.Sounds,As,"soundCursor")}findSoundIndex(t){for(let r=j.Sounds;r<j.Sounds+As;r+=1)if(this.values.get(r)===t)return r}imageIndex(t){return this.register(t,j.Images,ya,"imageCursor")}lightIndex(t){return this.register(t,j.Lights,pa,"lightCursor")}shadowLightIndex(t){return this.register(t,j.ShadowLights,_a,"shadowLightCursor")}itemIndex(t){return this.register(t,j.Items,xa,"itemCursor")}playerSkinIndex(t){return this.register(t,j.PlayerSkins,ws,"playerSkinCursor")}generalIndex(t){return this.register(t,j.General,ba,"generalCursor")}register(t,r,n,i){for(let a=r;a<r+n;a+=1)if(this.values.get(a)===t)return a;let s=this[i],o=r+n;if(s>=o)throw new RangeError(`Out of configstring slots for range starting at ${r}`);return Qc(s,t),this.values.set(s,t),this[i]=s+1,s}};var Xr=class{constructor(t){this.registry=t.registry,this.system=t.system,this.music=t.music,this.client=t.client}soundindex(t){return this.registry.registerName(t)}sound(t,r,n,i,s,o){this.system.play({entity:t,channel:r,soundIndex:n,volume:i,attenuation:s,timeOffsetMs:o}),this.triggerSubtitle(n)}positioned_sound(t,r,n,i){this.system.positionedSound(t,r,n,i),this.triggerSubtitle(r)}loop_sound(t,r,n,i,s){this.system.play({entity:t,channel:r,soundIndex:n,volume:i,attenuation:s,looping:!0}),this.triggerSubtitle(n)}stop_entity_sounds(t){this.system.stopEntitySounds(t)}setPlaybackRate(t){this.system.setPlaybackRate(t)}set_listener(t){this.system.setListener(t)}play_music(t,r=!0){return this.music?this.music.play(t,{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(t){this.music?.setVolume(t)}play_ambient(t,r,n){this.system.ambientSound(t,r,n),this.triggerSubtitle(r)}play_channel(t){this.system.play({...t}),this.triggerSubtitle(t.soundIndex)}triggerSubtitle(t){if(!this.client)return;let r=this.registry.getName(t);if(!r)return;let n=r.match(/\[(.*?)\]/);n&&this.client.showSubtitle(n[1],r)}};var Vn=class{constructor(t,r){this.engine=t;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(t){this.host.pump(t)}getLatestFrame(){return this.host.getLatestFrame()}isRunning(){return this.started&&this.host.isRunning()}};function Jc(e,t,r,n,i){let s=new Xr({...n,client:r}),o=new Gr(t,r,i);return{runtime:new Vn(e,o),audio:s}}var ch="PACK";function dh(e,t,r){let n=[];for(let i=0;i<r;i+=1){let s=e.getUint8(t+i);if(s===0)break;n.push(s)}return String.fromCharCode(...n)}function se(e){return e.replace(/\\/g,"/").replace(/^\/+/,"").toLowerCase()}function uh(){let e=new Uint32Array(256);for(let t=0;t<256;t+=1){let r=t;for(let n=0;n<8;n+=1)r=(r&1)!==0?3988292384^r>>>1:r>>>1;e[t]=r>>>0}return e}var fh=uh();function ed(e){let t=4294967295;for(let r=0;r<e.length;r+=1){let n=e[r];t=fh[(t^n)&255]^t>>>8}return(t^4294967295)>>>0}var Ve=class extends Error{},$r=class e{constructor(t,r,n,i){this.name=t;this.buffer=r;this.entries=new Map(n.map(s=>[s.name,s])),this.checksum=i,this.size=r.byteLength}static fromArrayBuffer(t,r){let n=new DataView(r);if(r.byteLength<12)throw new Ve("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!==ch)throw new Ve(`Invalid PAK header magic: ${i}`);let s=n.getInt32(4,!0),o=n.getInt32(8,!0);if(s<12)throw new Ve(`Invalid directory offset: ${s}`);if(o<=0||o%64!==0)throw new Ve(`Invalid directory length: ${o}`);if(s+o>r.byteLength)throw new Ve("Directory exceeds buffer length");let d=o/64,l=[],c=new Map;for(let h=0;h<d;h+=1){let u=s+h*64,f=dh(n,u,56),m=se(f),g=n.getInt32(u+56,!0),p=n.getInt32(u+60,!0);if(g<0||p<0||g+p>r.byteLength)throw new Ve(`Invalid entry bounds for ${f||"<unnamed>"} (offset=${g}, length=${p})`);if(!m)throw new Ve(`Entry ${h} has an empty name`);let y={name:m,offset:g,length:p};c.set(m,y)}return l.push(...c.values()),new e(t,r,l,ed(new Uint8Array(r)))}getEntry(t){return this.entries.get(se(t))}listEntries(){return Array.from(this.entries.values())}readFile(t){let r=this.getEntry(t);if(!r)throw new Ve(`File not found in PAK: ${t}`);return new Uint8Array(this.buffer,r.offset,r.length)}validate(){return{checksum:this.checksum,entries:this.listEntries()}}};function td(e){return ed(new Uint8Array(e))}var Ls=class{constructor(t=[]){this.mounts=[];this.files=new Map;t.forEach(r=>this.mountPak(r))}mountPak(t){this.mounts.push(t);for(let r of t.listEntries()){let n=se(r.name);this.files.set(n,{archive:t,entry:r})}}get mountedPaks(){return[...this.mounts]}hasFile(t){return this.files.has(se(t))}stat(t){let r=this.files.get(se(t));if(r)return{path:r.entry.name,size:r.entry.length,sourcePak:r.archive.name}}getFileMetadata(t){let r=this.files.get(se(t));if(r)return{path:r.entry.name,size:r.entry.length,sourcePak:r.archive.name,offset:r.entry.offset}}async readFile(t){let r=this.files.get(se(t));if(!r)throw new Error(`File not found in VFS: ${t}`);return r.archive.readFile(t)}async readBinaryFile(t){return this.readFile(t)}streamFile(t,r=1024*1024){let n=this.files.get(se(t));if(!n)throw new Error(`File not found in VFS: ${t}`);let{archive:i,entry:s}=n,o=i.readFile(t),a=0,d=o.length;return new ReadableStream({pull(l){if(a>=d){l.close();return}let c=Math.min(a+r,d),h=o.slice(a,c);a=c,l.enqueue(h)}})}async readTextFile(t){let r=await this.readFile(t);return new TextDecoder("utf-8").decode(r)}list(t=""){let r=se(t).replace(/\/+$|^\//g,""),n=[],i=new Set,s=r?`${r}/`:"";for(let o of this.files.values()){if(r&&!o.entry.name.startsWith(s))continue;let a=r?o.entry.name.slice(s.length):o.entry.name,d=a.indexOf("/");d===-1?n.push({path:o.entry.name,size:o.entry.length,sourcePak:o.archive.name}):i.add(a.slice(0,d))}return n.sort((o,a)=>o.path.localeCompare(a.path)),{files:n,directories:[...i].sort()}}async listDirectory(t){return this.list(t).files}findByExtension(t){let r=t.startsWith(".")?t.toLowerCase():`.${t.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,s)=>i.path.localeCompare(s.path))}listByExtension(t){let r=new Set(t.map(i=>i.startsWith(".")?i.toLowerCase():`.${i.toLowerCase()}`)),n=[];for(let i of this.files.values()){let s=i.entry.name.toLowerCase();for(let o of r)if(s.endsWith(o)){n.push({path:i.entry.name,size:i.entry.length,sourcePak:i.archive.name});break}}return n.sort((i,s)=>i.path.localeCompare(s.path))}searchFiles(t){let r=[];for(let n of this.files.values())t.test(n.entry.name)&&r.push({path:n.entry.name,size:n.entry.length,sourcePak:n.archive.name});return r.sort((n,i)=>n.path.localeCompare(i.path))}getPakInfo(){return this.mounts.map(t=>({filename:t.name,entryCount:t.listEntries().length,totalSize:t.size}))}getDirectoryTree(){let t={name:"",path:"",files:[],directories:[]},r=new Map;r.set("",t);let n=Array.from(this.files.values()).map(i=>({path:i.entry.name,size:i.entry.length,sourcePak:i.archive.name})).sort((i,s)=>i.path.localeCompare(s.path));for(let i of n){let s=i.path.split("/"),o=s.pop(),a="",d=t;for(let l of s){let c=a;a=a?`${a}/${l}`:l;let h=r.get(a);h||(h={name:l,path:a,files:[],directories:[]},d.directories.push(h),r.set(a,h)),d=h}d.files.push(i)}return t}};var La=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"}]),fr=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"}},Es=class{constructor(t=La){this.known=new Map;t.forEach(r=>this.known.set(this.normalizePakName(r.name),r))}validateArchive(t,r){let n=this.normalizePakName(r??("name"in t?t.name:"unknown")),i=t.checksum,s="size"in t?t.size:void 0,o=this.known.get(n);return o?o.checksum!==i?{name:n,checksum:i,expectedChecksum:o.checksum,status:"mismatch",size:s,description:o.description}:{name:n,checksum:i,expectedChecksum:o.checksum,status:"valid",size:s,description:o.description}:{name:n,checksum:i,status:"unknown",size:s}}assertValid(t,r){let n=this.validateArchive(t,r);if(n.status==="mismatch")throw new fr(n);return n}normalizePakName(t){let r=se(t),n=r.split("/"),i=n.pop()??r,s=n.pop();return s?`${i}@${s}`:i}};var Ot=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 hh(e,t){if(typeof e.arrayBuffer=="function"){let r=await e.arrayBuffer();return t?.({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=s=>{t?.({file:"blob",loadedBytes:s.loaded,totalBytes:s.total||e.size,state:"reading"})},i.onload=()=>{let s=i.result;s instanceof ArrayBuffer?r(s):n(new Error("Unexpected FileReader result"))},i.readAsArrayBuffer(e)});if(typeof Response<"u"){let r=await new Response(e).arrayBuffer();return t?.({file:"blob",loadedBytes:r.byteLength,totalBytes:r.byteLength,state:"reading"}),r}if(typeof e.stream=="function"){let r=e.stream().getReader(),n=[],i=0;for(;;){let{done:a,value:d}=await r.read();if(a)break;if(!d)continue;let l=d;n.push(l),i+=l.byteLength,t?.({file:"blob",loadedBytes:i,totalBytes:e.size,state:"reading"})}let s=new Uint8Array(i),o=0;for(let a of n)s.set(a,o),o+=a.byteLength;return s.buffer}throw new Ot("blob",new Error("Unsupported Blob type"))}async function mh(e,t){if(e.data instanceof ArrayBuffer)return t?.({file:e.name,loadedBytes:e.data.byteLength,totalBytes:e.data.byteLength,state:"reading"}),e.data;if(e.data instanceof Blob){let n=e.data.size;return hh(e.data,i=>t?.({...i,file:e.name,totalBytes:n}))}let r=e.data.buffer.slice(e.data.byteOffset,e.data.byteOffset+e.data.byteLength);return t?.({file:e.name,loadedBytes:r.byteLength,totalBytes:r.byteLength,state:"reading"}),r}async function Ts(e,t,r){let n=typeof r=="function"?{onProgress:r}:r??{},i=n.persistIndexes??!!n.pakIndexStore,s=n.enforceValidation??!!n.validator,o=n.allowUnknownPaks??!0,a=n.stopOnError??!1,d=[];for(let l of t)try{let c=await mh(l,n.onProgress),h=$r.fromArrayBuffer(l.name,c),u=n.validator?.validateArchive(h);if(u){n.onValidationResult?.(u);let f=u.status==="mismatch",m=u.status==="unknown";if(f&&s||m&&!o){let g=new fr(u);if(n.onError?.(l.name,g),a)throw new Ot(l.name,g);d.push({archive:h,mounted:!1,validation:u});continue}}if(e.mountPak(h),i&&n.pakIndexStore)try{await n.pakIndexStore.persist(h)}catch(f){if(n.onError?.(l.name,f),a)throw new Ot(l.name,f)}n.onProgress?.({file:l.name,loadedBytes:c.byteLength,totalBytes:c.byteLength,state:"parsed"}),d.push({archive:h,mounted:!0,validation:u})}catch(c){if(n.onProgress?.({file:l.name,loadedBytes:0,totalBytes:0,state:"error"}),n.onError?.(l.name,c),a)throw new Ot(l.name,c)}return d}var Nt=class{constructor(t){this.capacity=t;this.map=new Map;if(t<=0)throw new RangeError("LRU cache capacity must be greater than zero")}get size(){return this.map.size}has(t){return this.map.has(t)}get(t){let r=this.map.get(t);if(r!==void 0)return this.map.delete(t),this.map.set(t,r),r}set(t,r){if(this.map.has(t)&&this.map.delete(t),this.map.set(t,r),this.map.size>this.capacity){let n=this.map.keys().next();n.done||this.map.delete(n.value)}}delete(t){return this.map.delete(t)}clear(){this.map.clear()}entries(){return Array.from(this.map.entries()).reverse().map(([t,r])=>({key:t,value:r}))}};function ph(e){return Array.isArray(e)?e:Array.from(e)}function Ea(e){return ph(e).map(t=>({name:t.name,data:t}))}async function rd(e,t,r){let n=Ea(t);return Ts(e,n,r??{})}function nd(e,t){let r=i=>{i.preventDefault(),i.dataTransfer?.dropEffect&&(i.dataTransfer.dropEffect="copy")},n=i=>{i.preventDefault();let s=i.dataTransfer?.files;s&&s.length>0&&t(Array.from(s))};return e.addEventListener("dragover",r),e.addEventListener("drop",n),()=>{e.removeEventListener("dragover",r),e.removeEventListener("drop",n)}}function id(e,t){let r=n=>{let i=n.target;!i||!i.files||i.files.length===0||(t(i.files),i.value="")};return e.addEventListener("change",r),()=>e.removeEventListener("change",r)}var gh="IBSP",yh=38,od=19,xh=8+od*8;var Q=class extends Error{},Kr=class{constructor(t){this.vfs=t}async load(t){let r=await this.vfs.readFile(t),n=new Uint8Array(r.byteLength);return n.set(r),Gn(n.buffer)}};function Gn(e){if(e.byteLength<xh)throw new Q("BSP too small to contain header");let t=new DataView(e),r=String.fromCharCode(t.getUint8(0),t.getUint8(1),t.getUint8(2),t.getUint8(3));if(r!==gh)throw new Q(`Invalid BSP magic ${r}`);let n=t.getInt32(4,!0);if(n!==yh)throw new Q(`Unsupported BSP version ${n}`);let i=new Map;for(let S=0;S<od;S+=1){let M=t.getInt32(8+S*8,!0),E=t.getInt32(12+S*8,!0);if(M<0||E<0||M+E>e.byteLength)throw new Q(`Invalid lump bounds for index ${S}`);i.set(S,{offset:M,length:E})}let s={version:n,lumps:i},o=_h(e,i.get(0)),a=Sh(e,i.get(1)),d=wh(e,i.get(2)),l=Ah(e,i.get(4)),c=Mh(e,i.get(5)),h=Lh(e,i.get(6)),u=new Uint8Array(e,i.get(7).offset,i.get(7).length),f=Dh(h,i.get(7)),m=Eh(e,i.get(8)),g=Th(e,i.get(11)),p=Ih(e,i.get(12)),y=Ch(e,i.get(13)),_=Rh(e,i.get(14)),b=Fh(e,i.get(15)),x=zh(e,i.get(9),i.get(10),m),v=kh(e,i.get(3));return{header:s,entities:o,planes:a,vertices:d,nodes:l,texInfo:c,faces:h,lightMaps:u,lightMapInfo:f,leafs:m,leafLists:x,edges:g,surfEdges:p,models:y,brushes:_,brushSides:b,visibility:v,pickEntity(S){let M=null,E=1/0;for(let w of o.entities){let T=w.properties.model;if(!T||!T.startsWith("*"))continue;let F=parseInt(T.substring(1),10);if(isNaN(F)||F<0||F>=y.length)continue;let U=y[F],C=bh(S.origin,S.direction,U.mins,U.maxs);C!==null&&C<E&&(E=C,M={entity:w,model:U,distance:C})}return M}}}function bh(e,t,r,n){let i=0,s=1/0;for(let o=0;o<3;o++)if(Math.abs(t[o])<1e-8){if(e[o]<r[o]||e[o]>n[o])return null}else{let a=1/t[o],d=(r[o]-e[o])*a,l=(n[o]-e[o])*a;if(d>l){let c=d;d=l,l=c}if(i=Math.max(i,d),s=Math.min(s,l),i>s)return null}return i}function _h(e,t){let r=new TextDecoder().decode(new Uint8Array(e,t.offset,t.length)),n=vh(r),i=n.find(s=>s.classname==="worldspawn");return{raw:r,entities:n,worldspawn:i,getUniqueClassnames(){let s=new Set;for(let o of n)o.classname&&s.add(o.classname);return Array.from(s).sort()}}}function vh(e){let t=[],r=/\{([^}]*)\}/gms,n;for(;(n=r.exec(e))!==null;){let i=n[1],s={},o=/"([^\"]*)"\s+"([^\"]*)"/g,a;for(;(a=o.exec(i))!==null;)s[a[1]]=a[2];t.push({classname:s.classname,properties:s})}return t}function Sh(e,t){let r=new DataView(e,t.offset,t.length),n=t.length/20;if(n%1!==0)throw new Q("Plane lump has invalid length");let i=[];for(let s=0;s<n;s+=1){let o=[r.getFloat32(s*20,!0),r.getFloat32(s*20+4,!0),r.getFloat32(s*20+8,!0)],a=r.getFloat32(s*20+12,!0),d=r.getInt32(s*20+16,!0);i.push({normal:o,dist:a,type:d})}return i}function wh(e,t){let r=new DataView(e,t.offset,t.length),n=t.length/12;if(n%1!==0)throw new Q("Vertex lump has invalid length");let i=[];for(let s=0;s<n;s+=1)i.push([r.getFloat32(s*12,!0),r.getFloat32(s*12+4,!0),r.getFloat32(s*12+8,!0)]);return i}function Ah(e,t){let r=new DataView(e,t.offset,t.length),n=28,i=t.length/n;if(i%1!==0)throw new Q("Node lump has invalid length");let s=[];for(let o=0;o<i;o+=1){let a=o*n,d=r.getInt32(a,!0),l=[r.getInt32(a+4,!0),r.getInt32(a+8,!0)],c=[r.getInt16(a+12,!0),r.getInt16(a+14,!0),r.getInt16(a+16,!0)],h=[r.getInt16(a+18,!0),r.getInt16(a+20,!0),r.getInt16(a+22,!0)],u=r.getUint16(a+24,!0),f=r.getUint16(a+26,!0);s.push({planeIndex:d,children:l,mins:c,maxs:h,firstFace:u,numFaces:f})}return s}function Mh(e,t){let r=new DataView(e,t.offset,t.length),n=76,i=t.length/n;if(i%1!==0)throw new Q("TexInfo lump has invalid length");let s=[];for(let o=0;o<i;o+=1){let a=o*n,d=[r.getFloat32(a,!0),r.getFloat32(a+4,!0),r.getFloat32(a+8,!0)],l=r.getFloat32(a+12,!0),c=[r.getFloat32(a+16,!0),r.getFloat32(a+20,!0),r.getFloat32(a+24,!0)],h=r.getFloat32(a+28,!0),u=r.getInt32(a+32,!0),f=r.getInt32(a+36,!0),m=new Uint8Array(e,t.offset+a+40,32),g=new TextDecoder("utf-8").decode(m).replace(/\0.*$/,""),p=r.getInt32(a+72,!0);s.push({s:d,sOffset:l,t:c,tOffset:h,flags:u,value:f,texture:g,nextTexInfo:p})}return s}function Lh(e,t){let r=new DataView(e,t.offset,t.length),n=20,i=t.length/n;if(i%1!==0)throw new Q("Face lump has invalid length");let s=[];for(let o=0;o<i;o+=1){let a=o*n,d=r.getUint16(a,!0),l=r.getInt16(a+2,!0),c=r.getInt32(a+4,!0),h=r.getInt16(a+8,!0),u=r.getInt16(a+10,!0),f=[r.getUint8(a+12),r.getUint8(a+13),r.getUint8(a+14),r.getUint8(a+15)],m=r.getInt32(a+16,!0);s.push({planeIndex:d,side:l,firstEdge:c,numEdges:h,texInfo:u,styles:f,lightOffset:m})}return s}function Eh(e,t){let r=new DataView(e,t.offset,t.length),n=28,i=t.length/n;if(i%1!==0)throw new Q("Leaf lump has invalid length");let s=[];for(let o=0;o<i;o+=1){let a=o*n,d=r.getInt32(a,!0),l=r.getInt16(a+4,!0),c=r.getInt16(a+6,!0),h=[r.getInt16(a+8,!0),r.getInt16(a+10,!0),r.getInt16(a+12,!0)],u=[r.getInt16(a+14,!0),r.getInt16(a+16,!0),r.getInt16(a+18,!0)],f=r.getUint16(a+20,!0),m=r.getUint16(a+22,!0),g=r.getUint16(a+24,!0),p=r.getUint16(a+26,!0);s.push({contents:d,cluster:l,area:c,mins:h,maxs:u,firstLeafFace:f,numLeafFaces:m,firstLeafBrush:g,numLeafBrushes:p})}return s}function Th(e,t){let r=new DataView(e,t.offset,t.length),n=4,i=t.length/n;if(i%1!==0)throw new Q("Edge lump has invalid length");let s=[];for(let o=0;o<i;o+=1){let a=o*n;s.push({vertices:[r.getUint16(a,!0),r.getUint16(a+2,!0)]})}return s}function Ih(e,t){let r=t.length/4;if(r%1!==0)throw new Q("SurfEdge lump has invalid length");let n=new DataView(e,t.offset,t.length),i=new Int32Array(r);for(let s=0;s<r;s+=1)i[s]=n.getInt32(s*4,!0);return i}function Ch(e,t){let r=new DataView(e,t.offset,t.length),n=48;if(t.length%n!==0)throw new Q("Model lump has invalid length");let i=t.length/n,s=[];for(let o=0;o<i;o+=1){let a=o*n,d=[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)],c=[r.getFloat32(a+24,!0),r.getFloat32(a+28,!0),r.getFloat32(a+32,!0)],h=r.getInt32(a+36,!0),u=r.getInt32(a+40,!0),f=r.getInt32(a+44,!0);s.push({mins:d,maxs:l,origin:c,headNode:h,firstFace:u,numFaces:f})}return s}function Rh(e,t){let r=new DataView(e,t.offset,t.length),n=12,i=t.length/n;if(i%1!==0)throw new Q("Brush lump has invalid length");let s=[];for(let o=0;o<i;o+=1){let a=o*n;s.push({firstSide:r.getInt32(a,!0),numSides:r.getInt32(a+4,!0),contents:r.getInt32(a+8,!0)})}return s}function Fh(e,t){let r=new DataView(e,t.offset,t.length),n=4,i=t.length/n;if(i%1!==0)throw new Q("Brush side lump has invalid length");let s=[];for(let o=0;o<i;o+=1){let a=o*n;s.push({planeIndex:r.getUint16(a,!0),texInfo:r.getInt16(a+2,!0)})}return s}function zh(e,t,r,n){let i=[],s=[],o=t.length/2,a=r.length/2,d=new DataView(e,t.offset,t.length),l=new DataView(e,r.offset,r.length);for(let c of n){if(c.firstLeafFace+c.numLeafFaces>o)throw new Q("Leaf faces reference data past lump bounds");if(c.firstLeafBrush+c.numLeafBrushes>a)throw new Q("Leaf brushes reference data past lump bounds");let h=[];for(let f=0;f<c.numLeafFaces;f+=1)h.push(d.getUint16((c.firstLeafFace+f)*2,!0));let u=[];for(let f=0;f<c.numLeafBrushes;f+=1)u.push(l.getUint16((c.firstLeafBrush+f)*2,!0));i.push(h),s.push(u)}return{leafFaces:i,leafBrushes:s}}function kh(e,t){if(t.length===0)return;if(t.length<4)throw new Q("Visibility lump too small");let r=new DataView(e,t.offset,t.length),n=r.getInt32(0,!0),i=4+n*8;if(n<0||i>t.length)throw new Q("Visibility lump truncated");let s=4,o=[];for(let a=0;a<n;a+=1){let d=r.getInt32(s,!0),l=r.getInt32(s+4,!0);s+=8;let c=t.offset+d,h=t.offset+l,u=t.offset+t.length;if(d<0||l<0||c>=u||h>=u)throw new Q("Visibility offsets out of range");o.push({pvs:sd(e,c,n,t),phs:sd(e,h,n,t)})}return{numClusters:n,clusters:o}}function sd(e,t,r,n){let i=Math.ceil(r/8),s=new Uint8Array(i),o=new Uint8Array(e),a=t,d=0,l=n.offset+n.length;for(;d<i;){if(a>=l)throw new Q("Visibility data truncated");let c=o[a++];if(c!==0){s[d++]=c;continue}if(a>=l)throw new Q("Visibility run exceeds lump bounds");let h=o[a++];for(let u=0;u<h&&d<i;u+=1)s[d++]=0}return s}function Dh(e,t){return e.map(r=>{if(!(r.lightOffset<0))return{offset:r.lightOffset,length:Math.max(0,t.length-r.lightOffset)}})}function Is(e,t,r){if(e.lightOffset<0||e.lightOffset>=t.byteLength)return;let n=t.byteLength-e.lightOffset,i=Math.min(r?.length??n,n);if(!(i<=0))return t.subarray(e.lightOffset,e.lightOffset+i)}var Ph=844121161,Bh=8,ad=68,Oh=[{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}],pe=class extends Error{},Zr=class{constructor(t){this.vfs=t;this.cache=new Map}async load(t){if(this.cache.has(t))return this.cache.get(t);let r=await this.vfs.readFile(t),n=new Uint8Array(r.byteLength);n.set(r);let i=Ta(n.buffer);return this.cache.set(t,i),i}get(t){return this.cache.get(t)}};function ld(e,t,r){let n=[];for(let i=0;i<r;i+=1){let s=e.getUint8(t+i);if(s===0)break;n.push(s)}return String.fromCharCode(...n)}function Wn(e,t,r,n){if(r!==0&&(t<ad||t+r>e.byteLength))throw new pe(`${n} section is out of bounds`)}function Nh(e){if(e.byteLength<ad)throw new pe("MD2 buffer too small to contain header");let t=new DataView(e),r=t.getInt32(0,!0),n=t.getInt32(4,!0);if(r!==Ph)throw new pe(`Invalid MD2 ident: ${r}`);if(n!==Bh)throw new pe(`Unsupported MD2 version: ${n}`);let i={ident:r,version:n,skinWidth:t.getInt32(8,!0),skinHeight:t.getInt32(12,!0),frameSize:t.getInt32(16,!0),numSkins:t.getInt32(20,!0),numVertices:t.getInt32(24,!0),numTexCoords:t.getInt32(28,!0),numTriangles:t.getInt32(32,!0),numGlCommands:t.getInt32(36,!0),numFrames:t.getInt32(40,!0),offsetSkins:t.getInt32(44,!0),offsetTexCoords:t.getInt32(48,!0),offsetTriangles:t.getInt32(52,!0),offsetFrames:t.getInt32(56,!0),offsetGlCommands:t.getInt32(60,!0),offsetEnd:t.getInt32(64,!0),magic:r},s=40+i.numVertices*4;if(i.frameSize!==s)throw new pe(`Unexpected frame size ${i.frameSize}, expected ${s}`);if(i.offsetEnd>e.byteLength)throw new pe("MD2 offset_end exceeds buffer length");return i}function Uh(e,t){let r=t.numSkins*64;Wn(e,t.offsetSkins,r,"skins");let n=new DataView(e,t.offsetSkins,r),i=[];for(let s=0;s<t.numSkins;s+=1)i.push({name:ld(n,s*64,64)});return i}function Hh(e,t){let r=t.numTexCoords*4;Wn(e,t.offsetTexCoords,r,"texcoords");let n=new DataView(e,t.offsetTexCoords,r),i=[];for(let s=0;s<t.numTexCoords;s+=1){let o=s*4;i.push({s:n.getInt16(o,!0),t:n.getInt16(o+2,!0)})}return i}function Vh(e,t){let r=t.numTriangles*12;Wn(e,t.offsetTriangles,r,"triangles");let n=new DataView(e,t.offsetTriangles,r),i=[];for(let s=0;s<t.numTriangles;s+=1){let o=s*12,a=[n.getUint16(o,!0),n.getUint16(o+2,!0),n.getUint16(o+4,!0)],d=[n.getUint16(o+6,!0),n.getUint16(o+8,!0),n.getUint16(o+10,!0)];if(a.some(l=>l>=t.numVertices)||d.some(l=>l>=t.numTexCoords))throw new pe("Triangle references out of range vertex or texcoord");i.push({vertexIndices:a,texCoordIndices:d})}return i}function Gh(e,t){let r=t.numFrames*t.frameSize;Wn(e,t.offsetFrames,r,"frames");let n=[];for(let i=0;i<t.numFrames;i+=1){let s=t.offsetFrames+i*t.frameSize,o=new DataView(e,s,t.frameSize),a={x:o.getFloat32(0,!0),y:o.getFloat32(4,!0),z:o.getFloat32(8,!0)},d={x:o.getFloat32(12,!0),y:o.getFloat32(16,!0),z:o.getFloat32(20,!0)},l=ld(o,24,16),c=[],h=1/0,u=1/0,f=1/0,m=-1/0,g=-1/0,p=-1/0;for(let y=0;y<t.numVertices;y+=1){let _=40+y*4,b=o.getUint8(_)*a.x+d.x,x=o.getUint8(_+1)*a.y+d.y,v=o.getUint8(_+2)*a.z+d.z;b<h&&(h=b),x<u&&(u=x),v<f&&(f=v),b>m&&(m=b),x>g&&(g=x),v>p&&(p=v);let A={x:b,y:x,z:v},S=o.getUint8(_+3),M=Oh[S];if(!M)throw new pe(`Invalid normal index ${S} in frame ${l}`);c.push({position:A,normalIndex:S,normal:M})}n.push({name:l,vertices:c,minBounds:{x:h,y:u,z:f},maxBounds:{x:m,y:g,z:p}})}return n}function Wh(e,t){let r=t.numGlCommands*4;if(Wn(e,t.offsetGlCommands,r,"gl commands"),r===0)return[];let n=new DataView(e,t.offsetGlCommands,r),i=[],s=0;for(;;){if(s+4>r)throw new pe("GL command list ended unexpectedly");let o=n.getInt32(s,!0);if(s+=4,o===0)break;let a=Math.abs(o),d=[],l=a*12;if(s+l>r)throw new pe("GL command vertex block exceeds buffer");for(let c=0;c<a;c+=1){let h=n.getFloat32(s,!0),u=n.getFloat32(s+4,!0),f=n.getInt32(s+8,!0);if(s+=12,f<0||f>=t.numVertices)throw new pe("GL command references invalid vertex index");d.push({s:h,t:u,vertexIndex:f})}i.push({mode:o>0?"strip":"fan",vertices:d})}if(s!==r)throw new pe("GL command list did not consume expected data");return i}function Ta(e){let t=Nh(e),r=Uh(e,t),n=Hh(e,t),i=Vh(e,t),s=Gh(e,t),o=Wh(e,t);return{header:t,skins:r,texCoords:n,triangles:i,frames:s,glCommands:o}}function cd(e){let t=[],r=0;for(;r<e.length;){let n=e[r].name,i=n.replace(/\d+$/,"")||n,s=r;for(;s+1<e.length&&(e[s+1].name.replace(/\d+$/,"")||e[s+1].name)===i;)s+=1;t.push({name:i,firstFrame:r,lastFrame:s}),r=s+1}return t}var dd=860898377,Xh=15,Ge=class extends Error{constructor(t){super(t),this.name="Md3ParseError"}};function Xn(e,t,r){let n=new Uint8Array(e.buffer,e.byteOffset+t,r);return new TextDecoder("utf-8").decode(n).replace(/\0.*$/,"").trim()}function $h(e){let t=(e>>8&255)*(2*Math.PI/255),r=(e&255)*(2*Math.PI/255),n=Math.sin(r);return{x:Math.cos(t)*n,y:Math.sin(t)*n,z:Math.cos(r)}}function Cs(e,t,r,n){if(t<0||t+r>n)throw new Ge(`${e} exceeds buffer bounds`)}function Kh(e){let t=e.getInt32(0,!0);if(t!==dd)throw new Ge(`Invalid MD3 ident: ${t}`);let r=e.getInt32(4,!0);if(r!==Xh)throw new Ge(`Unsupported MD3 version: ${r}`);let n=Xn(e,8,64),i=e.getInt32(72,!0),s=e.getInt32(76,!0),o=e.getInt32(80,!0),a=e.getInt32(84,!0),d=e.getInt32(88,!0),l=e.getInt32(92,!0),c=e.getInt32(96,!0),h=e.getInt32(100,!0),u=e.getInt32(104,!0);if(s<=0||a<0||o<0)throw new Ge("Invalid MD3 counts");return{ident:t,version:r,name:n,flags:i,numFrames:s,numTags:o,numSurfaces:a,numSkins:d,ofsFrames:l,ofsTags:c,ofsSurfaces:h,ofsEnd:u,magic:t}}function Zh(e,t){let r=[];Cs("Frames",t.ofsFrames,t.numFrames*56,e.byteLength);for(let i=0;i<t.numFrames;i+=1){let s=t.ofsFrames+i*56;r.push({minBounds:{x:e.getFloat32(s,!0),y:e.getFloat32(s+4,!0),z:e.getFloat32(s+8,!0)},maxBounds:{x:e.getFloat32(s+12,!0),y:e.getFloat32(s+16,!0),z:e.getFloat32(s+20,!0)},localOrigin:{x:e.getFloat32(s+24,!0),y:e.getFloat32(s+28,!0),z:e.getFloat32(s+32,!0)},radius:e.getFloat32(s+36,!0),name:Xn(e,s+40,16)})}return r}function Yh(e,t){let r=[],i=t.numFrames*t.numTags*112;Cs("Tags",t.ofsTags,i,e.byteLength);for(let s=0;s<t.numFrames;s+=1){let o=[];for(let a=0;a<t.numTags;a+=1){let d=t.ofsTags+(s*t.numTags+a)*112,l=d+64,c=l+12;o.push({name:Xn(e,d,64),origin:{x:e.getFloat32(l,!0),y:e.getFloat32(l+4,!0),z:e.getFloat32(l+8,!0)},axis:[{x:e.getFloat32(c,!0),y:e.getFloat32(c+4,!0),z:e.getFloat32(c+8,!0)},{x:e.getFloat32(c+12,!0),y:e.getFloat32(c+16,!0),z:e.getFloat32(c+20,!0)},{x:e.getFloat32(c+24,!0),y:e.getFloat32(c+28,!0),z:e.getFloat32(c+32,!0)}]})}r.push(o)}return r}function qh(e,t){let r=e.getInt32(t,!0);if(r!==dd)throw new Ge(`Invalid surface ident at ${t}: ${r}`);let n=Xn(e,t+4,64),i=e.getInt32(t+68,!0),s=e.getInt32(t+72,!0),o=e.getInt32(t+76,!0),a=e.getInt32(t+80,!0),d=e.getInt32(t+84,!0),l=e.getInt32(t+88,!0),c=e.getInt32(t+92,!0),h=e.getInt32(t+96,!0),u=e.getInt32(t+100,!0),f=e.getInt32(t+104,!0);if(s<=0||a<=0||d<=0)throw new Ge(`Invalid surface counts for ${n}`);let m=f;Cs(`Surface ${n}`,t,m,e.byteLength);let g=[],p=t+l;for(let S=0;S<d;S+=1){let M=p+S*12;g.push({indices:[e.getInt32(M,!0),e.getInt32(M+4,!0),e.getInt32(M+8,!0)]})}let y=[],_=t+c;for(let S=0;S<o;S+=1){let M=_+S*68;y.push({name:Xn(e,M,64),shaderIndex:e.getInt32(M+64,!0)})}let b=[],x=t+h;for(let S=0;S<a;S+=1){let M=x+S*8;b.push({s:e.getFloat32(M,!0),t:e.getFloat32(M+4,!0)})}let v=[],A=t+u;for(let S=0;S<s;S+=1){let M=[];for(let E=0;E<a;E+=1){let w=A+(S*a+E)*8,T=e.getInt16(w,!0)/64,F=e.getInt16(w+2,!0)/64,U=e.getInt16(w+4,!0)/64,C=e.getUint16(w+6,!0);M.push({position:{x:T,y:F,z:U},latLng:C,normal:$h(C)})}v.push(M)}return{surface:{name:n,flags:i,numFrames:s,shaders:y,triangles:g,texCoords:b,vertices:v},nextOffset:t+f}}function Ia(e){if(e.byteLength<108)throw new Ge("MD3 buffer too small for header");let t=new DataView(e),r=Kh(t);Cs("MD3 end",r.ofsEnd,0,e.byteLength);let n=Zh(t,r),i=Yh(t,r),s=[],o=r.ofsSurfaces;for(let a=0;a<r.numSurfaces;a+=1){let{surface:d,nextOffset:l}=qh(t,o);s.push(d),o=l}if(o!==r.ofsEnd)throw new Ge("Surface parsing did not reach ofsEnd");return{header:r,frames:n,tags:i,surfaces:s}}var Yr=class{constructor(t){this.vfs=t;this.cache=new Map}async load(t){if(this.cache.has(t))return this.cache.get(t);let r=await this.vfs.readFile(t),n=Ia(r.slice().buffer);return this.cache.set(t,n),n}get(t){return this.cache.get(t)}};var jh=844317769,Qh=2,ud=64,fd=12,Ut=class extends Error{};function Jh(e,t,r){let n=[];for(let i=0;i<r;i+=1){let s=e.getUint8(t+i);if(s===0)break;n.push(s)}return String.fromCharCode(...n)}function Ca(e){if(e.byteLength<fd)throw new Ut("Sprite buffer too small to contain header");let t=new DataView(e),r=t.getInt32(0,!0),n=t.getInt32(4,!0),i=t.getInt32(8,!0);if(r!==jh)throw new Ut(`Invalid Sprite ident: ${r}`);if(n!==Qh)throw new Ut(`Unsupported Sprite version: ${n}`);let s=[],o=16+ud,a=fd;for(let d=0;d<i;d+=1){if(a+o>e.byteLength)throw new Ut("Sprite frame data exceeds buffer length");let l=t.getInt32(a,!0),c=t.getInt32(a+4,!0),h=t.getInt32(a+8,!0),u=t.getInt32(a+12,!0),f=Jh(t,a+16,ud);s.push({width:l,height:c,originX:h,originY:u,name:f}),a+=o}return{ident:r,version:n,numFrames:i,frames:s}}var qr=class{constructor(t){this.vfs=t}async load(t){let r=await this.vfs.readFile(t),n=new Uint8Array(r.byteLength);return n.set(r),Ca(n.buffer)}};function hd(e,t){let r=(e.sequence.end-e.sequence.start+1)/e.sequence.fps,n=e.sequence.loop!==!1,i=e.time+t;return n?i=(i%r+r)%r:i>r&&(i=r),{...e,time:Math.max(0,Math.min(i,r))}}function md(e){let t=e.sequence.end-e.sequence.start+1,r=1/e.sequence.fps,n=e.sequence.loop!==!1,i=e.time/r;if(!n&&i>=t)return{frame0:e.sequence.end,frame1:e.sequence.end,lerp:0};let s=n?i%t:Math.min(i,t-1),o=Math.floor(s),a=e.sequence.start+o,d=o+1>=t?n?e.sequence.start:e.sequence.end:a+1,l=!n&&o>=t-1?0:s-o;return{frame0:a,frame1:d,lerp:l}}function pd(e){return{sequence:e,time:0}}function gd(e,t,r){return{x:e.x+(t.x-e.x)*r,y:e.y+(t.y-e.y)*r,z:e.z+(t.z-e.z)*r}}var $n=class extends Error{constructor(t){super(t),this.name="WalParseError"}};function Rs(e){if(e.byteLength<100)throw new $n("WAL buffer too small");let t=new DataView(e),r=new Uint8Array(e,0,32),n=new TextDecoder("utf-8").decode(r).replace(/\0.*$/,"").trim(),i=t.getInt32(32,!0),s=t.getInt32(36,!0),o=[t.getInt32(40,!0),t.getInt32(44,!0),t.getInt32(48,!0),t.getInt32(52,!0)],a=new Uint8Array(e,56,32),d=new TextDecoder("utf-8").decode(a).replace(/\0.*$/,"").trim(),l=t.getInt32(88,!0),c=t.getInt32(92,!0),h=t.getInt32(96,!0);if(i<=0||s<=0)throw new $n("Invalid WAL dimensions");let u=[],f=i,m=s;for(let g=0;g<o.length;g+=1){let p=o[g],y=Math.max(1,f*m|0);if(p<=0||p+y>e.byteLength)throw new $n(`Invalid WAL mip offset for level ${g}`);let _=new Uint8Array(e,p,y);u.push({level:g,width:f,height:m,data:_}),f=Math.max(1,f>>1),m=Math.max(1,m>>1)}return{name:n,width:i,height:s,mipmaps:u,animName:d,flags:l,contents:c,value:h}}var hr=class extends Error{constructor(t){super(t),this.name="PcxParseError"}};function Kn(e){if(e.byteLength<128)throw new hr("PCX buffer too small for header");let t=new DataView(e),r=t.getUint8(0),n=t.getUint8(2),i=t.getUint8(3),s=t.getUint16(4,!0),o=t.getUint16(6,!0),a=t.getUint16(8,!0),d=t.getUint16(10,!0);if(r!==10||n!==1)throw new hr("Unsupported PCX encoding");if(i!==8)throw new hr("Only 8bpp PCX files are supported");let l=a-s+1,c=d-o+1,h=t.getUint16(66,!0),u=e.byteLength-769;if(u<128||new DataView(e,u,1).getUint8(0)!==12)throw new hr("Missing PCX palette");let f=new Uint8Array(e,u+1,768),m=new Uint8Array(e,128,u-128),g=new Uint8Array(l*c),p=0,y=0;for(let _=0;_<c;_+=1){let b=0;for(;b<h&&p<m.length;){let x=1,v=m[p++];if((v&192)===192){if(x=v&63,p>=m.length)throw new hr("Unexpected end of PCX RLE data");v=m[p++]}for(let A=0;A<x&&b<h;A+=1)b<l&&(g[y++]=v),b+=1}}return{width:l,height:c,bitsPerPixel:i,pixels:g,palette:f}}function Fs(e){let t=new Uint8Array(e.width*e.height*4);for(let r=0;r<e.pixels.length;r+=1){let n=e.pixels[r],i=n*3,s=r*4;t[s]=e.palette[i],t[s+1]=e.palette[i+1],t[s+2]=e.palette[i+2],t[s+3]=n===255?0:255}return t}var yt=class extends Error{constructor(t){super(t),this.name="TgaParseError"}};function Ra(e){let t=new DataView(e);if(e.byteLength<18)throw new yt("Buffer too small for TGA header");let r=t.getUint8(0),n=t.getUint8(1),i=t.getUint8(2),s=t.getUint16(12,!0),o=t.getUint16(14,!0),a=t.getUint8(16),d=t.getUint8(17);if(i!==2&&i!==10&&i!==3&&i!==11)throw new yt(`Unsupported TGA image type: ${i} (only RGB/Grayscale supported)`);if(a!==24&&a!==32&&a!==8)throw new yt(`Unsupported pixel depth: ${a} (only 8, 24, 32 bpp supported)`);let l=i>=9,c=i===3||i===11,h=a/8,u=18+r;if(n===1){let b=t.getUint16(5,!0),x=t.getUint8(7);u+=b*(x/8)}let f=s*o,m=new Uint8Array(f*4),g=(d&32)!==0,p=0,y=new Uint8Array(e),_=b=>{if(c){let x=y[u++];m[b]=x,m[b+1]=x,m[b+2]=x,m[b+3]=255}else{let x=y[u++],v=y[u++],A=y[u++],S=a===32?y[u++]:255;m[b]=A,m[b+1]=v,m[b+2]=x,m[b+3]=S}};if(l){let b=0;for(;b<f;){if(u>=e.byteLength)throw new yt("Unexpected end of TGA RLE data");let x=y[u++],v=(x&127)+1,A=(x&128)!==0;if(b+v>f)throw new yt("TGA RLE packet exceeds image bounds");if(A){let S=c?y[u]:y[u+2],M=c?y[u]:y[u+1],E=y[u],w=c?255:a===32?y[u+3]:255;u+=h;for(let T=0;T<v;T++){let F=(b+T)*4;m[F]=S,m[F+1]=M,m[F+2]=E,m[F+3]=w}}else for(let S=0;S<v;S++)_((b+S)*4);b+=v}}else for(let b=0;b<f;b++){if(u>=e.byteLength)throw new yt("Unexpected end of TGA data");_(b*4)}if(!g){let b=s*4,x=new Uint8Array(b);for(let v=0;v<o/2;v++){let A=v*b,S=(o-1-v)*b;x.set(m.subarray(A,A+b)),m.set(m.subarray(S,S+b),A),m.set(x,S)}}return{width:s,height:o,bitsPerPixel:32,pixels:m}}var jr=class{constructor(t={}){this.cache=new Nt(t.capacity??128)}get size(){return this.cache.size}get(t){return this.cache.get(t.toLowerCase())}set(t,r){this.cache.set(t.toLowerCase(),r)}clear(){this.cache.clear()}};function Fa(e,t){let r=[];for(let n of e.mipmaps){let i=new Uint8Array(n.width*n.height*4);for(let s=0;s<n.data.length;s+=1){let o=n.data[s],a=o*3,d=s*4;i[d]=t[a],i[d+1]=t[a+1],i[d+2]=t[a+2],i[d+3]=o===255?0:255}r.push({level:n.level,width:n.width,height:n.height,rgba:i})}return{width:e.width,height:e.height,levels:r,source:"wal"}}function zs(e){let t=Fs(e),r={level:0,width:e.width,height:e.height,rgba:t};return{width:e.width,height:e.height,levels:[r],source:"pcx"}}function yd(e){let t={level:0,width:e.width,height:e.height,rgba:e.pixels};return{width:e.width,height:e.height,levels:[t],source:"tga"}}function ks(e,t){return Fa(Rs(e),t)}var mr=class extends Error{constructor(t){super(t),this.name="WavParseError"}};function za(e,t,r){return new TextDecoder("ascii").decode(new Uint8Array(e.buffer,e.byteOffset+t,r))}function Ds(e){if(e.byteLength<44)throw new mr("WAV buffer too small");let t=new DataView(e);if(za(t,0,4)!=="RIFF"||za(t,8,4)!=="WAVE")throw new mr("Invalid WAV header");let r=12,n=-1,i=-1,s=0,o=0;for(;r+8<=e.byteLength;){let m=za(t,r,4),g=t.getUint32(r+4,!0),p=r+8;m==="fmt "?(n=p,s=g):m==="data"&&(i=p,o=g),r=p+g}if(n===-1||i===-1)throw new mr("Missing fmt or data chunk");let a=t.getUint16(n,!0),d=t.getUint16(n+2,!0),l=t.getUint32(n+4,!0),c=t.getUint16(n+14,!0);if(a!==1)throw new mr("Only PCM WAV is supported");let h=c/8,u=o/(h*d),f=new Float32Array(u*d);for(let m=0;m<u;m+=1)for(let g=0;g<d;g+=1){let p=m*d+g,y=i+p*h,_=0;if(c===8)_=t.getUint8(y),f[p]=(_-128)/128;else if(c===16)_=t.getInt16(y,!0),f[p]=_/32768;else if(c===24){let b=t.getUint8(y),x=t.getUint8(y+1),v=t.getInt8(y+2);_=b|x<<8|v<<16,f[p]=_/8388608}else throw new mr(`Unsupported bitsPerSample: ${c}`)}return{sampleRate:l,channels:d,bitsPerSample:c,samples:f}}var em=(e,t=4294967295,r=79764919)=>{let n=new Int32Array(256),i,s,o,a=t;for(i=0;i<256;i++){for(o=i<<24,s=8;s>0;--s)o=2147483648&o?o<<1^r:o<<1;n[i]=o}for(i=0;i<e.length;i++)a=a<<8^n[255&(a>>24^e[i])];return a};var ka=(e,t=em)=>{let r=p=>new Uint8Array(p.length/2).map(((y,_)=>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,y)=>i.set(p,y)));let s=new Uint8Array(e.length),o,a,d,l=!1,c=0,h=42,u=e.length>13&&e.substring(0,9)==="dynEncode",f=0;u&&(f=11,a=n(e.substring(9,f)),a<=1&&(f+=2,h=n(e.substring(11,f))),a===1&&(f+=8,d=(p=>new DataView(r(p).buffer).getInt32(0,!0))(e.substring(13,f))));let m=256-h;for(let p=f;p<e.length;p++)if(o=e.charCodeAt(p),o!==61||l){if(o===92&&p<e.length-5&&u){let y=e.charCodeAt(p+1);y!==117&&y!==85||(o=parseInt(e.substring(p+2,p+6),16),p+=5)}if(o>255){let y=i.get(o);y&&(o=y+127)}l&&(l=!1,o-=64),s[c++]=o<h&&o>0?o+m:o-h}else l=!0;let g=s.subarray(0,c);if(u&&a===1){let p=t(g);if(p!==d){let y="Decode failed crc32 validation";throw console.error("`simple-yenc`\n",y+`
2
2
  `,"Expected: "+d+"; Got: "+p+`
3
3
  `,"Visit https://github.com/eshaz/simple-yenc for more information"),Error(y)}}return g};function re(){let e=Uint8Array,t=Float32Array;re.modules||Object.defineProperties(re,{modules:{value:new WeakMap},setModule:{value(r,n){re.modules.set(r,Promise.resolve(n))}},getModule:{value(r,n){let i=re.modules.get(r);return i||(n?i=WebAssembly.compile(ka(n)):(n=r.wasm,i=re.inflateDynEncodeString(n).then(s=>WebAssembly.compile(s))),re.modules.set(r,i)),i}},concatFloat32:{value(r,n){let i=new t(n),s=0,o=0;for(;s<r.length;)i.set(r[s],o),o+=r[s++].length;return i}},getDecodedAudio:{value:(r,n,i,s,o)=>({errors:r,channelData:n,samplesDecoded:i,sampleRate:s,bitDepth:o})},getDecodedAudioMultiChannel:{value(r,n,i,s,o,a){let d=[],l,c;for(l=0;l<i;l++){let h=[];for(c=0;c<n.length;)h.push(n[c++][l]||[]);d.push(re.concatFloat32(h,s))}return re.getDecodedAudio(r,d,s,o,a)}},inflateDynEncodeString:{value(r){return r=ka(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 œ`;re.getModule(re,i).then(s=>WebAssembly.instantiate(s,{})).then(({exports:s})=>{let o=new Map(Object.entries(s)),a=o.get("puff"),d=o.get("memory").buffer,l=new e(d),c=new DataView(d),h=o.get("__heap_base"),u=r.length,f=h;h+=4,c.setInt32(f,u,!0);let m=h;h+=u,l.set(r,m);let g=h;h+=4,c.setInt32(g,l.byteLength-h,!0),a(h,g,m,f),n(l.slice(h,h+c.getInt32(g,!0)))})})}}}),Object.defineProperty(this,"wasm",{enumerable:!0,get:()=>this._wasm}),this.getOutputChannels=(r,n,i)=>{let s=[],o=0;for(;o<n;)s.push(r.slice(o*i,o++*i+i));return s},this.allocateTypedArray=(r,n,i=!0)=>{let s=this._wasm.malloc(n.BYTES_PER_ELEMENT*r);return i&&this._pointers.add(s),{ptr:s,len:r,buf:new n(this._wasm.HEAP,s,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 s=i[r];s!==0;s=i[++r])n.push(s);return String.fromCharCode.apply(null,n)},this.addError=(r,n,i,s,o,a)=>{r.push({message:n,frameLength:i,frameNumber:s,inputBytes:o,outputSamples:a})},this.instantiate=(r,n)=>(n&&re.setModule(r,n),this._wasm=new r(re).instantiate(),this._pointers=new Set,this._wasm.ready.then(()=>this))}var _d=ff(bd(),1);var tm=()=>globalThis.Worker||_d.default,Qr=class extends tm(){constructor(t,r,n,i){re.modules||new re;let s=re.modules.get(n);if(!s){let o="text/javascript",a,d=`'use strict';(${((l,c,h)=>{let u,f,m=new Promise(g=>{f=g});self.onmessage=({data:{id:g,command:p,data:y}})=>{let _=m,b={id:g},x;p==="init"?(Object.defineProperties(l,{WASMAudioDecoderCommon:{value:c},EmscriptenWASM:{value:h},module:{value:y.module},isWebWorker:{value:!0}}),u=new l(y.options),f()):p==="free"?u.free():p==="ready"?_=_.then(()=>u.ready):p==="reset"?_=_.then(()=>u.reset()):(Object.assign(b,u[p](Array.isArray(y)?y.map(v=>new Uint8Array(v)):new Uint8Array(y))),x=b.channelData?b.channelData.map(v=>v.buffer):[]),_.then(()=>self.postMessage(b,x))}}).toString()})(${n}, ${re}, ${i})`;try{a=typeof process.versions.node<"u"}catch{}s=a?`data:${o};base64,${Buffer.from(d).toString("base64")}`:URL.createObjectURL(new Blob([d],{type:o})),re.modules.set(n,s)}super(s,{name:r}),this._id=Number.MIN_SAFE_INTEGER,this._enqueuedOperations=new Map,this.onmessage=({data:o})=>{let{id:a,...d}=o;this._enqueuedOperations.get(a)(d),this._enqueuedOperations.delete(a)},new i(re).getModule().then(o=>{this.postToDecoder("init",{module:o,options:t})})}async postToDecoder(t,r){return new Promise(n=>{this.postMessage({command:t,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 Ps=(e,t)=>{Object.defineProperty(e,"name",{value:t})};var ne=Symbol,vd=", ",B=(()=>{let e="front",t="side",r="rear",n="left",i="center",s="right";return["",e+" ",t+" ",r+" "].map(o=>[[n,s],[n,s,i],[n,i,s],[i,n,s],[i]].flatMap(a=>a.map(d=>o+d).join(vd)))})(),ot="LFE",Ht="monophonic (mono)",Vt="stereo",Zn="surround",oe=(e,...t)=>`${[Ht,Vt,`linear ${Zn}`,"quadraphonic",`5.0 ${Zn}`,`5.1 ${Zn}`,`6.1 ${Zn}`,`7.1 ${Zn}`][e-1]} (${t.join(vd)})`,Yn=[Ht,oe(2,B[0][0]),oe(3,B[0][2]),oe(4,B[1][0],B[3][0]),oe(5,B[1][2],B[3][0]),oe(6,B[1][2],B[3][0],ot),oe(7,B[1][2],B[2][0],B[3][4],ot),oe(8,B[1][2],B[2][0],B[3][0],ot)],Sd=192e3,wd=176400,Bs=96e3,Os=88200,Ad=64e3,Gt=48e3,Jr=44100,en=32e3,tn=24e3,rn=22050,nn=16e3,Ns=12e3,Us=11025,sn=8e3,Md=7350,et="absoluteGranulePosition",H="bandwidth",be="bitDepth",_e="bitrate",qn=_e+"Maximum",jn=_e+"Minimum",Qn=_e+"Nominal",at="buffer",Jn=at+"Fullness",te="codec",ve=te+"Frames",ei="coupledStreamCount",on="crc",ti=on+"16",ri=on+"32",J="data",P="description",lt="duration",an="emphasis",ni="hasOpusPadding",ke="header",Wt="isContinuedPacket",ii="isCopyrighted",Xt="isFirstPage",si="isHome",De="isLastPage",xt="isOriginal",bt="isPrivate",oi="isVbr",Ce="layer",L="length",N="mode",_t=N+"Extension",Hs="mpeg",vt=Hs+"Version",ai="numberAACFrames",li="outputGain",pr="preSkip",ci="profile",Vs=ne(),St="protection",Da="rawData",We="segments",V="subarray",$t="version",gr="vorbis",di=gr+"Comments",ln=gr+"Setup",Gs="block",ui=Gs+"ingStrategy",Ws=ne(),wt=Gs+"Size",Kt=Gs+"size0",Zt=Gs+"size1",fi=ne(),Xs="channel",At=Xs+"MappingFamily",hi=Xs+"MappingTable",Se=Xs+"Mode",mi=ne(),k=Xs+"s",Ld="copyright",pi=Ld+"Id",gi=Ld+"IdStart",Mt="frame",Lt=Mt+"Count",Re=Mt+"Length",$s="Number",Et=Mt+$s,ct=Mt+"Padding",O=Mt+"Size",Ed="Rate",yi="inputSample"+Ed,Pa="page",yr=Pa+"Checksum",cn=ne(),Yt=Pa+"SegmentTable",de=Pa+"Sequence"+$s,Ba="sample",xi=Ba+$s,W=Ba+Ed,dt=ne(),X=Ba+"s",Ks="stream",bi=Ks+"Count",_i=Ks+"Info",ut=Ks+"Serial"+$s,Oa=Ks+"StructureVersion",Na="total",xr=Na+"BytesOut",br=Na+"Duration",_r=Na+"Samples",K=ne(),Xe=ne(),vi=ne(),qt=ne(),tt=ne(),Zs=ne(),Ua=ne(),jt=ne(),Y=ne(),$e=ne(),Ke=ne(),ft=ne(),Qt=ne(),Ys=ne(),rt=ne(),nt=ne(),Ze=ne(),qs=ne(),we=Uint8Array,Jt=DataView,q="reserved",Ae="bad",dn="free",Si="none",js="16bit CRC";var Ha=(e,t,r)=>{for(let n=0;n<e[L];n++){let i=t(n);for(let s=8;s>0;s--)i=r(i);e[n]=i}return e},nm=Ha(new we(256),e=>e,e=>e&128?7^e<<1:e<<1),ae=[Ha(new Uint16Array(256),e=>e<<8,e=>e<<1^(e&32768?32773:0))],le=[Ha(new Uint32Array(256),e=>e,e=>e>>>1^(e&1)*3988292384)];for(let e=0;e<15;e++){ae.push(new Uint16Array(256)),le.push(new Uint32Array(256));for(let t=0;t<=255;t++)ae[e+1][t]=ae[0][ae[e][t]>>>8]^ae[e][t]<<8,le[e+1][t]=le[e][t]>>>8^le[0][le[e][t]&255]}var Id=e=>{let t=0,r=e[L];for(let n=0;n!==r;n++)t=nm[t^e[n]];return t},Cd=e=>{let t=e[L],r=t-16,n=0,i=0;for(;i<=r;)n^=e[i++]<<8|e[i++],n=ae[15][n>>8]^ae[14][n&255]^ae[13][e[i++]]^ae[12][e[i++]]^ae[11][e[i++]]^ae[10][e[i++]]^ae[9][e[i++]]^ae[8][e[i++]]^ae[7][e[i++]]^ae[6][e[i++]]^ae[5][e[i++]]^ae[4][e[i++]]^ae[3][e[i++]]^ae[2][e[i++]]^ae[1][e[i++]]^ae[0][e[i++]];for(;i!==t;)n=(n&255)<<8^ae[0][n>>8^e[i++]];return n},Rd=e=>{let t=e[L],r=t-16,n=0,i=0;for(;i<=r;)n=le[15][(e[i++]^n)&255]^le[14][(e[i++]^n>>>8)&255]^le[13][(e[i++]^n>>>16)&255]^le[12][e[i++]^n>>>24]^le[11][e[i++]]^le[10][e[i++]]^le[9][e[i++]]^le[8][e[i++]]^le[7][e[i++]]^le[6][e[i++]]^le[5][e[i++]]^le[4][e[i++]]^le[3][e[i++]]^le[2][e[i++]]^le[1][e[i++]]^le[0][e[i++]];for(;i!==t;)n=le[0][(n^e[i++])&255]^n>>>8;return n^-1},Ai=(...e)=>{let t=new we(e.reduce((r,n)=>r+n[L],0));return e.reduce((r,n)=>(t.set(n,r),r+n[L]),0),t},Pe=e=>String.fromCharCode(...e),Td=[0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15],wi=e=>Td[e&15]<<4|Td[e>>4],Qs=class{constructor(t){this._data=t,this._pos=t[L]*8}set position(t){this._pos=t}get position(){return this._pos}read(t){let r=Math.floor(this._pos/8),n=this._pos%8;return this._pos-=t,(wi(this._data[r-1])<<8)+wi(this._data[r])>>7-n&255}},Fd=(e,t)=>{try{return e.getBigInt64(t,!0)}catch{let r=e.getUint8(t+7)&128?-1:1,n=e.getUint32(t,!0),i=e.getUint32(t+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 Mi=class{constructor(t,r){this._onCodecHeader=t,this._onCodecUpdate=r,this[rt]()}[nt](){this._isEnabled=!0}[rt](){this._headerCache=new Map,this._codecUpdateData=new WeakMap,this._codecHeaderSent=!1,this._codecShouldUpdate=!1,this._bitrate=null,this._isEnabled=!1}[Ys](t,r){if(this._onCodecUpdate){this._bitrate!==t&&(this._bitrate=t,this._codecShouldUpdate=!0);let n=this._codecUpdateData.get(this._headerCache.get(this._currentHeader));this._codecShouldUpdate&&n&&this._onCodecUpdate({bitrate:t,...n},r),this._codecShouldUpdate=!1}}[Y](t){let r=this._headerCache.get(t);return r&&this._updateCurrentHeader(t),r}[$e](t,r,n){this._isEnabled&&(this._codecHeaderSent||(this._onCodecHeader({...r}),this._codecHeaderSent=!0),this._updateCurrentHeader(t),this._headerCache.set(t,r),this._codecUpdateData.set(r,n))}_updateCurrentHeader(t){this._onCodecUpdate&&t!==this._currentHeader&&(this._codecShouldUpdate=!0,this._currentHeader=t)}};var ue=new WeakMap,ge=new WeakMap;var Me=class{constructor(t,r){this._codecParser=t,this._headerCache=r}*[Ua](){let t;do{if(t=yield*this.Frame[Ke](this._codecParser,this._headerCache,0),t)return t;this._codecParser[Xe](1)}while(!0)}*[jt](t){let r=yield*this[Ua](),n=ge.get(r)[L];if(t||this._codecParser._flushing||(yield*this.Header[Y](this._codecParser,this._headerCache,n)))return this._headerCache[nt](),this._codecParser[Xe](n),this._codecParser[qt](r),r;this._codecParser[tt](`Missing ${Mt} at ${n} bytes from current position.`,`Dropping current ${Mt} and trying again.`),this._headerCache[rt](),this._codecParser[Xe](1)}};var vr=class{constructor(t,r){ge.set(this,{[ke]:t}),this[J]=r}};var Be=class extends vr{static*[Ke](t,r,n,i,s){let o=yield*t[Y](n,i,s);if(o){let a=ue.get(o)[Re],d=ue.get(o)[X],l=(yield*n[K](a,s))[V](0,a);return new r(o,l,d)}else return null}constructor(t,r,n){super(t,r),this[ke]=t,this[X]=n,this[lt]=n/t[W]*1e3,this[Et]=null,this[xr]=null,this[_r]=null,this[br]=null,ge.get(this)[L]=r[L]}};var Va="unsynchronizationFlag",Ga="extendedHeaderFlag",Wa="experimentalFlag",Xa="footerPresent",Li=class e{static*getID3v2Header(t,r,n){let s={},o=yield*t[K](3,n);if(o[0]!==73||o[1]!==68||o[2]!==51||(o=yield*t[K](10,n),s[$t]=`id3v2.${o[3]}.${o[4]}`,o[5]&15)||(s[Va]=!!(o[5]&128),s[Ga]=!!(o[5]&64),s[Wa]=!!(o[5]&32),s[Xa]=!!(o[5]&16),o[6]&128||o[7]&128||o[8]&128||o[9]&128))return null;let a=o[6]<<21|o[7]<<14|o[8]<<7|o[9];return s[L]=10+a,new e(s)}constructor(t){this[$t]=t[$t],this[Va]=t[Va],this[Ga]=t[Ga],this[Wa]=t[Wa],this[Xa]=t[Xa],this[L]=t[L]}};var Oe=class{constructor(t){ue.set(this,t),this[be]=t[be],this[_e]=null,this[k]=t[k],this[Se]=t[Se],this[W]=t[W]}};var Bd={0:[dn,dn,dn,dn,dn],16:[32,32,32,32,8],240:[Ae,Ae,Ae,Ae,Ae]},Js=(e,t,r)=>8*((e+r)%t+t)*(1<<(e+r)/t)-8*t*(t/8|0);for(let e=2;e<15;e++)Bd[e<<4]=[e*32,Js(e,4,0),Js(e,4,-1),Js(e,8,4),Js(e,8,0)];var im=0,sm=1,om=2,am=3,zd=4,eo="bands ",to=" to 31",kd={0:eo+4+to,16:eo+8+to,32:eo+12+to,48:eo+16+to},Sr="bitrateIndex",Ei="v2",oo="v1",ro="Intensity stereo ",no=", MS stereo ",io="on",so="off",lm={0:ro+so+no+so,16:ro+io+no+so,32:ro+so+no+io,48:ro+io+no+io},$a={0:{[P]:q},2:{[P]:"Layer III",[ct]:1,[_t]:lm,[oo]:{[Sr]:om,[X]:1152},[Ei]:{[Sr]:zd,[X]:576}},4:{[P]:"Layer II",[ct]:1,[_t]:kd,[X]:1152,[oo]:{[Sr]:sm},[Ei]:{[Sr]:zd}},6:{[P]:"Layer I",[ct]:4,[_t]:kd,[X]:384,[oo]:{[Sr]:im},[Ei]:{[Sr]:am}}},Ka="MPEG Version ",Dd="ISO/IEC ",cm={0:{[P]:`${Ka}2.5 (later extension of MPEG 2)`,[Ce]:Ei,[W]:{0:Us,4:Ns,8:sn,12:q}},8:{[P]:q},16:{[P]:`${Ka}2 (${Dd}13818-3)`,[Ce]:Ei,[W]:{0:rn,4:tn,8:nn,12:q}},24:{[P]:`${Ka}1 (${Dd}11172-3)`,[Ce]:oo,[W]:{0:Jr,4:Gt,8:en,12:q}},length:L},dm={0:js,1:Si},um={0:Si,1:"50/15 ms",2:q,3:"CCIT J.17"},Pd={0:{[k]:2,[P]:Vt},64:{[k]:2,[P]:"joint "+Vt},128:{[k]:2,[P]:"dual channel"},192:{[k]:1,[P]:Ht}},wr=class e extends Oe{static*[Y](t,r,n){let i={},s=yield*Li.getID3v2Header(t,r,n);s&&(yield*t[K](s[L],n),t[Xe](s[L]));let o=yield*t[K](4,n),a=Pe(o[V](0,4)),d=r[Y](a);if(d)return new e(d);if(o[0]!==255||o[1]<224)return null;let l=cm[o[1]&24];if(l[P]===q)return null;let c=o[1]&6;if($a[c][P]===q)return null;let h={...$a[c],...$a[c][l[Ce]]};if(i[vt]=l[P],i[Ce]=h[P],i[X]=h[X],i[St]=dm[o[1]&1],i[L]=4,i[_e]=Bd[o[2]&240][h[Sr]],i[_e]===Ae||(i[W]=l[W][o[2]&12],i[W]===q)||(i[ct]=o[2]&2&&h[ct],i[bt]=!!(o[2]&1),i[Re]=Math.floor(125*i[_e]*i[X]/i[W]+i[ct]),!i[Re]))return null;let u=o[3]&192;if(i[Se]=Pd[u][P],i[k]=Pd[u][k],i[_t]=h[_t][o[3]&48],i[ii]=!!(o[3]&8),i[xt]=!!(o[3]&4),i[an]=um[o[3]&3],i[an]===q)return null;i[be]=16;{let{length:f,frameLength:m,samples:g,...p}=i;r[$e](a,i,p)}return new e(i)}constructor(t){super(t),this[_e]=t[_e],this[an]=t[an],this[ct]=t[ct],this[ii]=t[ii],this[xt]=t[xt],this[bt]=t[bt],this[Ce]=t[Ce],this[_t]=t[_t],this[vt]=t[vt],this[St]=t[St]}};var Ti=class e extends Be{static*[Ke](t,r,n){return yield*super[Ke](wr,e,t,r,n)}constructor(t,r,n){super(t,r,n)}};var Ii=class extends Me{constructor(t,r,n){super(t,r),this.Frame=Ti,this.Header=wr,n(this[te])}get[te](){return Hs}*[ft](){return yield*this[jt]()}};var fm={0:"MPEG-4",8:"MPEG-2"},hm={0:"valid",2:Ae,4:Ae,6:Ae},mm={0:js,1:Si},pm={0:"AAC Main",64:"AAC LC (Low Complexity)",128:"AAC SSR (Scalable Sample Rate)",192:"AAC LTP (Long Term Prediction)"},gm={0:Bs,4:Os,8:Ad,12:Gt,16:Jr,20:en,24:tn,28:rn,32:nn,36:Ns,40:Us,44:sn,48:Md,52:q,56:q,60:"frequency is written explicitly"},Od={0:{[k]:0,[P]:"Defined in AOT Specific Config"},64:{[k]:1,[P]:Ht},128:{[k]:2,[P]:oe(2,B[0][0])},192:{[k]:3,[P]:oe(3,B[1][3])},256:{[k]:4,[P]:oe(4,B[1][3],B[3][4])},320:{[k]:5,[P]:oe(5,B[1][3],B[3][0])},384:{[k]:6,[P]:oe(6,B[1][3],B[3][0],ot)},448:{[k]:8,[P]:oe(8,B[1][3],B[2][0],B[3][0],ot)}},Ar=class e extends Oe{static*[Y](t,r,n){let i={},s=yield*t[K](7,n),o=Pe([s[0],s[1],s[2],s[3]&252|s[6]&3]),a=r[Y](o);if(a)Object.assign(i,a);else{if(s[0]!==255||s[1]<240||(i[vt]=fm[s[1]&8],i[Ce]=hm[s[1]&6],i[Ce]===Ae))return null;let l=s[1]&1;i[St]=mm[l],i[L]=l?7:9,i[Vs]=s[2]&192,i[dt]=s[2]&60;let c=s[2]&2;if(i[ci]=pm[i[Vs]],i[W]=gm[i[dt]],i[W]===q)return null;i[bt]=!!c,i[mi]=(s[2]<<8|s[3])&448,i[Se]=Od[i[mi]][P],i[k]=Od[i[mi]][k],i[xt]=!!(s[3]&32),i[si]=!!(s[3]&8),i[pi]=!!(s[3]&8),i[gi]=!!(s[3]&4),i[be]=16,i[X]=1024,i[ai]=s[6]&3;{let{length:h,channelModeBits:u,profileBits:f,sampleRateBits:m,frameLength:g,samples:p,numberAACFrames:y,..._}=i;r[$e](o,i,_)}}if(i[Re]=(s[3]<<11|s[4]<<3|s[5]>>5)&8191,!i[Re])return null;let d=(s[5]<<6|s[6]>>2)&2047;return i[Jn]=d===2047?"VBR":d,new e(i)}constructor(t){super(t),this[pi]=t[pi],this[gi]=t[gi],this[Jn]=t[Jn],this[si]=t[si],this[xt]=t[xt],this[bt]=t[bt],this[Ce]=t[Ce],this[L]=t[L],this[vt]=t[vt],this[ai]=t[ai],this[ci]=t[ci],this[St]=t[St]}get audioSpecificConfig(){let t=ue.get(this),r=t[Vs]+64<<5|t[dt]<<5|t[mi]>>3,n=new we(2);return new Jt(n[at]).setUint16(0,r,!1),n}};var Ci=class e extends Be{static*[Ke](t,r,n){return yield*super[Ke](Ar,e,t,r,n)}constructor(t,r,n){super(t,r,n)}};var Ri=class extends Me{constructor(t,r,n){super(t,r),this.Frame=Ci,this.Header=Ar,n(this[te])}get[te](){return"aac"}*[ft](){return yield*this[jt]()}};var er=class e extends Be{static _getFrameFooterCrc16(t){return(t[t[L]-2]<<8)+t[t[L]-1]}static[qs](t){let r=e._getFrameFooterCrc16(t),n=Cd(t[V](0,-2));return r===n}constructor(t,r,n){r[_i]=n,r[ti]=e._getFrameFooterCrc16(t),super(r,t,ue.get(r)[X])}};var Nd="get from STREAMINFO metadata block",ym={0:"Fixed",1:"Variable"},Ud={0:q,16:192};for(let e=2;e<16;e++)Ud[e<<4]=e<6?576*2**(e-2):2**e;var xm={0:Nd,1:Os,2:wd,3:Sd,4:sn,5:nn,6:rn,7:tn,8:en,9:Jr,10:Gt,11:Bs,15:Ae},bm={0:{[k]:1,[P]:Ht},16:{[k]:2,[P]:oe(2,B[0][0])},32:{[k]:3,[P]:oe(3,B[0][1])},48:{[k]:4,[P]:oe(4,B[1][0],B[3][0])},64:{[k]:5,[P]:oe(5,B[1][1],B[3][0])},80:{[k]:6,[P]:oe(6,B[1][1],ot,B[3][0])},96:{[k]:7,[P]:oe(7,B[1][1],ot,B[3][4],B[2][0])},112:{[k]:8,[P]:oe(8,B[1][1],ot,B[3][0],B[2][0])},128:{[k]:2,[P]:`${Vt} (left, diff)`},144:{[k]:2,[P]:`${Vt} (diff, right)`},160:{[k]:2,[P]:`${Vt} (avg, diff)`},176:q,192:q,208:q,224:q,240:q},_m={0:Nd,2:8,4:12,6:q,8:16,10:20,12:24,14:q},tr=class e extends Oe{static _decodeUTF8Int(t){if(t[0]>254)return null;if(t[0]<128)return{value:t[0],length:1};let r=1;for(let o=64;o&t[0];o>>=1)r++;let n=r-1,i=0,s=0;for(;n>0;s+=6,n--){if((t[n]&192)!==128)return null;i|=(t[n]&63)<<s}return i|=(t[n]&127>>r)<<s,{value:i,length:r}}static[Ze](t,r){let n={[K]:function*(){return t}};return e[Y](n,r,0).next().value}static*[Y](t,r,n){let i=yield*t[K](6,n);if(i[0]!==255||!(i[1]===248||i[1]===249))return null;let s={},o=Pe(i[V](0,4)),a=r[Y](o);if(a)Object.assign(s,a);else{if(s[Ws]=i[1]&1,s[ui]=ym[s[Ws]],s[fi]=i[2]&240,s[dt]=i[2]&15,s[wt]=Ud[s[fi]],s[wt]===q||(s[W]=xm[s[dt]],s[W]===Ae)||i[3]&1)return null;let l=bm[i[3]&240];if(l===q||(s[k]=l[k],s[Se]=l[P],s[be]=_m[i[3]&14],s[be]===q))return null}s[L]=5,i=yield*t[K](s[L]+8,n);let d=e._decodeUTF8Int(i[V](4));if(!d||(s[Ws]?s[xi]=d.value:s[Et]=d.value,s[L]+=d[L],s[fi]===96?(i[L]<s[L]&&(i=yield*t[K](s[L],n)),s[wt]=i[s[L]-1]+1,s[L]+=1):s[fi]===112&&(i[L]<s[L]&&(i=yield*t[K](s[L],n)),s[wt]=(i[s[L]-1]<<8)+i[s[L]]+1,s[L]+=2),s[X]=s[wt],s[dt]===12?(i[L]<s[L]&&(i=yield*t[K](s[L],n)),s[W]=i[s[L]-1]*1e3,s[L]+=1):s[dt]===13?(i[L]<s[L]&&(i=yield*t[K](s[L],n)),s[W]=(i[s[L]-1]<<8)+i[s[L]],s[L]+=2):s[dt]===14&&(i[L]<s[L]&&(i=yield*t[K](s[L],n)),s[W]=((i[s[L]-1]<<8)+i[s[L]])*10,s[L]+=2),i[L]<s[L]&&(i=yield*t[K](s[L],n)),s[on]=i[s[L]-1],s[on]!==Id(i[V](0,s[L]-1))))return null;if(!a){let{blockingStrategyBits:l,frameNumber:c,sampleNumber:h,samples:u,sampleRateBits:f,blockSizeBits:m,crc:g,length:p,...y}=s;r[$e](o,s,y)}return new e(s)}constructor(t){super(t),this[ti]=null,this[ui]=t[ui],this[wt]=t[wt],this[Et]=t[Et],this[xi]=t[xi],this[_i]=null}};var vm=2,Sm=512*1024,Mr=class extends Me{constructor(t,r,n){super(t,r),this.Frame=er,this.Header=tr,n(this[te])}get[te](){return"flac"}*_getNextFrameSyncOffset(t){let r=yield*this._codecParser[K](2,0),n=r[L]-2;for(;t<n;){if(r[t]===255){let s=r[t+1];if(s===248||s===249)break;s!==255&&t++}t++}return t}*[ft](){do{let t=yield*tr[Y](this._codecParser,this._headerCache,0);if(t){let r=ue.get(t)[L]+vm;for(;r<=Sm;){if(this._codecParser._flushing||(yield*tr[Y](this._codecParser,this._headerCache,r))){let n=yield*this._codecParser[K](r);if(this._codecParser._flushing||(n=n[V](0,r)),er[qs](n)){let i=new er(n,t);return this._headerCache[nt](),this._codecParser[Xe](r),this._codecParser[qt](i),i}}r=yield*this._getNextFrameSyncOffset(r+1)}this._codecParser[tt](`Unable to sync FLAC frame after searching ${r} bytes.`),this._codecParser[Xe](r)}else this._codecParser[Xe](yield*this._getNextFrameSyncOffset(1))}while(!0)}[Qt](t){return t[de]===0?(this._headerCache[nt](),this._streamInfo=t[J][V](13)):t[de]===1||(t[ve]=ge.get(t)[We].map(r=>{let n=tr[Ze](r,this._headerCache);if(n)return new er(r,n,this._streamInfo);this._codecParser[tt]("Failed to parse Ogg FLAC frame","Skipping invalid FLAC frame")}).filter(r=>!!r)),t}};var Lr=class e{static*[Y](t,r,n){let i={},s=yield*t[K](28,n);if(s[0]!==79||s[1]!==103||s[2]!==103||s[3]!==83||(i[Oa]=s[4],s[5]&248))return null;i[De]=!!(s[5]&4),i[Xt]=!!(s[5]&2),i[Wt]=!!(s[5]&1);let a=new Jt(we.from(s[V](0,28))[at]);i[et]=Fd(a,6),i[ut]=a.getInt32(14,!0),i[de]=a.getInt32(18,!0),i[yr]=a.getInt32(22,!0);let d=s[26];i[L]=d+27,s=yield*t[K](i[L],n),i[Re]=0,i[Yt]=[],i[cn]=we.from(s[V](27,i[L]));for(let l=0,c=0;l<d;l++){let h=i[cn][l];i[Re]+=h,c+=h,(h!==255||l===d-1)&&(i[Yt].push(c),c=0)}return new e(i)}constructor(t){ue.set(this,t),this[et]=t[et],this[Wt]=t[Wt],this[Xt]=t[Xt],this[De]=t[De],this[Yt]=t[Yt],this[de]=t[de],this[yr]=t[yr],this[ut]=t[ut]}};var Fi=class e extends vr{static*[Ke](t,r,n){let i=yield*Lr[Y](t,r,n);if(i){let s=ue.get(i)[Re],o=ue.get(i)[L],a=o+s,d=(yield*t[K](a,0))[V](0,a),l=d[V](o,a);return new e(i,l,d)}else return null}constructor(t,r,n){super(t,r),ge.get(this)[L]=n[L],this[ve]=[],this[Da]=n,this[et]=t[et],this[ri]=t[yr],this[lt]=0,this[Wt]=t[Wt],this[Xt]=t[Xt],this[De]=t[De],this[de]=t[de],this[X]=0,this[ut]=t[ut]}};var un=class extends Be{constructor(t,r,n){super(r,t,n)}};var Hd={0:Yn.slice(0,2),1:Yn},Ye="SILK-only",ye="CELT-only",ao="Hybrid",rr="narrowband",lo="medium-band",nr="wideband",fn="super-wideband",hn="fullband",wm={0:{[N]:Ye,[H]:rr,[O]:10},8:{[N]:Ye,[H]:rr,[O]:20},16:{[N]:Ye,[H]:rr,[O]:40},24:{[N]:Ye,[H]:rr,[O]:60},32:{[N]:Ye,[H]:lo,[O]:10},40:{[N]:Ye,[H]:lo,[O]:20},48:{[N]:Ye,[H]:lo,[O]:40},56:{[N]:Ye,[H]:lo,[O]:60},64:{[N]:Ye,[H]:nr,[O]:10},72:{[N]:Ye,[H]:nr,[O]:20},80:{[N]:Ye,[H]:nr,[O]:40},88:{[N]:Ye,[H]:nr,[O]:60},96:{[N]:ao,[H]:fn,[O]:10},104:{[N]:ao,[H]:fn,[O]:20},112:{[N]:ao,[H]:hn,[O]:10},120:{[N]:ao,[H]:hn,[O]:20},128:{[N]:ye,[H]:rr,[O]:2.5},136:{[N]:ye,[H]:rr,[O]:5},144:{[N]:ye,[H]:rr,[O]:10},152:{[N]:ye,[H]:rr,[O]:20},160:{[N]:ye,[H]:nr,[O]:2.5},168:{[N]:ye,[H]:nr,[O]:5},176:{[N]:ye,[H]:nr,[O]:10},184:{[N]:ye,[H]:nr,[O]:20},192:{[N]:ye,[H]:fn,[O]:2.5},200:{[N]:ye,[H]:fn,[O]:5},208:{[N]:ye,[H]:fn,[O]:10},216:{[N]:ye,[H]:fn,[O]:20},224:{[N]:ye,[H]:hn,[O]:2.5},232:{[N]:ye,[H]:hn,[O]:5},240:{[N]:ye,[H]:hn,[O]:10},248:{[N]:ye,[H]:hn,[O]:20}},mn=class e extends Oe{static[Ze](t,r,n){let i={};if(i[k]=t[9],i[At]=t[18],i[L]=i[At]!==0?21+i[k]:19,t[L]<i[L])throw new Error("Out of data while inside an Ogg Page");let s=r[0]&3,o=s===3?2:1,a=Pe(t[V](0,i[L]))+Pe(r[V](0,o)),d=n[Y](a);if(d)return new e(d);if(a.substr(0,8)!=="OpusHead"||t[8]!==1)return null;i[J]=we.from(t[V](0,i[L]));let l=new Jt(i[J][at]);if(i[be]=16,i[pr]=l.getUint16(10,!0),i[yi]=l.getUint32(12,!0),i[W]=Gt,i[li]=l.getInt16(16,!0),i[At]in Hd&&(i[Se]=Hd[i[At]][i[k]-1],!i[Se]))return null;i[At]!==0&&(i[bi]=t[19],i[ei]=t[20],i[hi]=[...t[V](21,i[k]+21)]);let c=wm[248&r[0]];switch(i[N]=c[N],i[H]=c[H],i[O]=c[O],s){case 0:i[Lt]=1;break;case 1:case 2:i[Lt]=2;break;case 3:i[oi]=!!(128&r[1]),i[ni]=!!(64&r[1]),i[Lt]=63&r[1];break;default:return null}{let{length:h,data:u,channelMappingFamily:f,...m}=i;n[$e](a,i,m)}return new e(i)}constructor(t){super(t),this[J]=t[J],this[H]=t[H],this[At]=t[At],this[hi]=t[hi],this[ei]=t[ei],this[Lt]=t[Lt],this[O]=t[O],this[ni]=t[ni],this[yi]=t[yi],this[oi]=t[oi],this[N]=t[N],this[li]=t[li],this[pr]=t[pr],this[bi]=t[bi]}};var zi=class extends Me{constructor(t,r,n){super(t,r),this.Frame=un,this.Header=mn,n(this[te]),this._identificationHeader=null,this._preSkipRemaining=null}get[te](){return"opus"}[Qt](t){return t[de]===0?(this._headerCache[nt](),this._identificationHeader=t[J]):t[de]===1||(t[ve]=ge.get(t)[We].map(r=>{let n=mn[Ze](this._identificationHeader,r,this._headerCache);if(n){this._preSkipRemaining===null&&(this._preSkipRemaining=n[pr]);let i=n[O]*n[Lt]/1e3*n[W];return this._preSkipRemaining>0&&(this._preSkipRemaining-=i,i=this._preSkipRemaining<0?-this._preSkipRemaining:0),new un(r,n,i)}this._codecParser[Zs]("Failed to parse Ogg Opus Header","Not a valid Ogg Opus file")})),t}};var pn=class extends Be{constructor(t,r,n){super(r,t,n)}};var Za={};for(let e=0;e<8;e++)Za[e+6]=2**(6+e);var ki=class e extends Oe{static[Ze](t,r,n,i){if(t[L]<30)throw new Error("Out of data while inside an Ogg Page");let s=Pe(t[V](0,30)),o=r[Y](s);if(o)return new e(o);let a={[L]:30};if(s.substr(0,7)!=="vorbis")return null;a[J]=we.from(t[V](0,30));let d=new Jt(a[J][at]);if(a[$t]=d.getUint32(7,!0),a[$t]!==0||(a[k]=t[11],a[Se]=Yn[a[k]-1]||"application defined",a[W]=d.getUint32(12,!0),a[qn]=d.getInt32(16,!0),a[Qn]=d.getInt32(20,!0),a[jn]=d.getInt32(24,!0),a[Zt]=Za[(t[28]&240)>>4],a[Kt]=Za[t[28]&15],a[Kt]>a[Zt])||t[29]!==1)return null;a[be]=32,a[ln]=i,a[di]=n;{let{length:l,data:c,version:h,vorbisSetup:u,vorbisComments:f,...m}=a;r[$e](s,a,m)}return new e(a)}constructor(t){super(t),this[qn]=t[qn],this[jn]=t[jn],this[Qn]=t[Qn],this[Kt]=t[Kt],this[Zt]=t[Zt],this[J]=t[J],this[di]=t[di],this[ln]=t[ln]}};var Di=class extends Me{constructor(t,r,n){super(t,r),this.Frame=pn,n(this[te]),this._identificationHeader=null,this._setupComplete=!1,this._prevBlockSize=null}get[te](){return gr}[Qt](t){t[ve]=[];for(let r of ge.get(t)[We])if(r[0]===1)this._headerCache[nt](),this._identificationHeader=t[J],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=ki[Ze](this._identificationHeader,this._headerCache,this._vorbisComments,this._vorbisSetup);n?t[ve].push(new pn(r,n,this._getSamples(r,n))):this._codecParser[logError]("Failed to parse Ogg Vorbis Header","Not a valid Ogg Vorbis file")}return t}_getSamples(t,r){let i=this._mode.blockFlags[t[0]>>1&this._mode.mask]?r[Zt]:r[Kt],s=this._prevBlockSize===null?0:(this._prevBlockSize+i)/4;return this._prevBlockSize=i,s}_parseSetupHeader(t){let r=new Qs(t),n={count:0,blockFlags:[]};for(;(r.read(1)&1)!==1;);let i;for(;n.count<64&&r.position>0;){wi(r.read(8));let s=0;for(;r.read(8)===0&&s++<3;);if(s===4)i=r.read(7),n.blockFlags.unshift(i&1),r.position+=6,n.count++;else{((wi(i)&126)>>1)+1!==n.count&&this._codecParser[tt]("vorbis derived mode count did not match actual mode count");break}}return n.mask=(1<<Math.log2(n.count))-1,n}};var Ya=class{constructor(t,r,n){this._codecParser=t,this._headerCache=r,this._onCodec=n,this._continuedPacket=new we,this._codec=null,this._isSupported=null,this._previousAbsoluteGranulePosition=null}get[te](){return this._codec||""}_updateCodec(t,r){this._codec!==t&&(this._headerCache[rt](),this._parser=new r(this._codecParser,this._headerCache,this._onCodec),this._codec=t)}_checkCodecSupport({data:t}){let r=Pe(t[V](0,8));switch(r){case"fishead\0":return!1;case"OpusHead":return this._updateCodec("opus",zi),!0;case(/^\x7fFLAC/.test(r)&&r):return this._updateCodec("flac",Mr),!0;case(/^\x01vorbis/.test(r)&&r):return this._updateCodec(gr,Di),!0;default:return!1}}_checkPageSequenceNumber(t){t[de]!==this._pageSequenceNumber+1&&this._pageSequenceNumber>1&&t[de]>1&&this._codecParser[tt]("Unexpected gap in Ogg Page Sequence Number.",`Expected: ${this._pageSequenceNumber+1}, Got: ${t[de]}`),this._pageSequenceNumber=t[de]}_parsePage(t){this._isSupported===null&&(this._pageSequenceNumber=t[de],this._isSupported=this._checkCodecSupport(t)),this._checkPageSequenceNumber(t);let r=ge.get(t),n=ue.get(r[ke]),i=0;if(r[We]=n[Yt].map(s=>t[J][V](i,i+=s)),this._continuedPacket[L]&&(r[We][0]=Ai(this._continuedPacket,r[We][0]),this._continuedPacket=new we),n[cn][n[cn][L]-1]===255&&(this._continuedPacket=Ai(this._continuedPacket,r[We].pop())),this._previousAbsoluteGranulePosition!==null&&(t[X]=Number(t[et]-this._previousAbsoluteGranulePosition)),this._previousAbsoluteGranulePosition=t[et],this._isSupported){let s=this._parser[Qt](t);return this._codecParser[qt](s),s}else return t}},Pi=class extends Me{constructor(t,r,n){super(t,r),this._onCodec=n,this.Frame=Fi,this.Header=Lr,this._streams=new Map,this._currentSerialNumber=null}get[te](){let t=this._streams.get(this._currentSerialNumber);return t?t.codec:""}*[ft](){let t=yield*this[jt](!0);this._currentSerialNumber=t[ut];let r=this._streams.get(this._currentSerialNumber);return r||(r=new Ya(this._codecParser,this._headerCache,this._onCodec),this._streams.set(this._currentSerialNumber,r)),t[De]&&this._streams.delete(this._currentSerialNumber),r._parsePage(t)}};var qa=()=>{},Bi=class{constructor(t,{onCodec:r,onCodecHeader:n,onCodecUpdate:i,enableLogging:s=!1,enableFrameCRC32:o=!0}={}){this._inputMimeType=t,this._onCodec=r||qa,this._onCodecHeader=n||qa,this._onCodecUpdate=i,this._enableLogging=s,this._crc32=o?Rd:qa,this[rt]()}get[te](){return this._parser?this._parser[te]:""}[rt](){this._headerCache=new Mi(this._onCodecHeader,this._onCodecUpdate),this._generator=this._getGenerator(),this._generator.next()}*flush(){this._flushing=!0;for(let t=this._generator.next();t.value;t=this._generator.next())yield t.value;this._flushing=!1,this[rt]()}*parseChunk(t){for(let r=this._generator.next(t);r.value;r=this._generator.next())yield r.value}parseAll(t){return[...this.parseChunk(t),...this.flush()]}*_getGenerator(){if(this._inputMimeType.match(/aac/))this._parser=new Ri(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/mpeg/))this._parser=new Ii(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/flac/))this._parser=new Mr(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/ogg/))this._parser=new Pi(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 t=yield*this._parser[ft]();t&&(yield t)}}*[K](t=0,r=0){let n;for(;this._rawData[L]<=t+r;){if(n=yield,this._flushing)return this._rawData[V](r);n&&(this._totalBytesIn+=n[L],this._rawData=Ai(this._rawData,n))}return this._rawData[V](r)}[Xe](t){this._currentReadPosition+=t,this._rawData=this._rawData[V](t)}[vi](t){this._sampleRate=t[ke][W],t[ke][_e]=t[lt]>0?Math.round(t[J][L]/t[lt])*8:0,t[Et]=this._frameNumber++,t[xr]=this._totalBytesOut,t[_r]=this._totalSamples,t[br]=this._totalSamples/this._sampleRate*1e3,t[ri]=this._crc32(t[J]),this._headerCache[Ys](t[ke][_e],t[br]),this._totalBytesOut+=t[J][L],this._totalSamples+=t[X]}[qt](t){if(t[ve]){if(t[De]){let r=t[X];t[ve].forEach(n=>{let i=n[X];r<i&&(n[X]=r>0?r:0,n[lt]=n[X]/n[ke][W]*1e3),r-=i,this[vi](n)})}else t[X]=0,t[ve].forEach(r=>{t[X]+=r[X],this[vi](r)});t[lt]=t[X]/this._sampleRate*1e3||0,t[_r]=this._totalSamples,t[br]=this._totalSamples/this._sampleRate*1e3||0,t[xr]=this._totalBytesOut}else this[vi](t)}_log(t,r){if(this._enableLogging){let n=[`${te}: ${this[te]}`,`inputMimeType: ${this._inputMimeType}`,`readPosition: ${this._currentReadPosition}`,`totalBytesIn: ${this._totalBytesIn}`,`${xr}: ${this._totalBytesOut}`],i=Math.max(...n.map(s=>s[L]));r.push(`--stats--${"-".repeat(i-9)}`,...n,"-".repeat(i)),t("codec-parser",r.reduce((s,o)=>s+`
4
4
  `+o,""))}}[tt](...t){this._log(console.warn,t)}[Zs](...t){this._log(console.error,t)}};var Vd=Bi;var co=ve;var uo=J;var Gd=ke;var Wd=De;var Xd=ln;var $d=_r;function Tt(e){var t=t;function r(){}t={};function n(R){throw R}var i,s,o,a,d,l,c,h,u,f,m;function g(){var R=m.buffer;i=new Int8Array(R),s=new Int16Array(R),a=new Uint8Array(R),d=new Uint16Array(R),o=new Int32Array(R),l=new Uint32Array(R),c=new Float32Array(R),h=new Float64Array(R),u=new BigInt64Array(R),f=new BigUint64Array(R)}for(var p=R=>{for(var He,zn,Or=0,ps=0,gs=R.length,ys=new Uint8Array((gs*3>>2)-(R[gs-2]=="=")-(R[gs-1]=="="));Or<gs;Or+=4,ps+=3)He=Z[R.charCodeAt(Or+1)],zn=Z[R.charCodeAt(Or+2)],ys[ps]=Z[R.charCodeAt(Or)]<<2|He>>4,ys[ps+1]=He<<4|zn>>2,ys[ps+2]=zn<<6|Z[R.charCodeAt(Or+3)];return ys},y=()=>n(""),_=()=>{},b={},x=R=>R(),v=()=>performance.now(),A=(R,He)=>{if(b[R]&&(clearTimeout(b[R].id),delete b[R]),!He)return 0;var zn=setTimeout(()=>{delete b[R],x(()=>Pc(R,v()))},He);return b[R]={id:zn,timeout_ms:He},0},S=Math.atan,M=Math.cos,E=Math.exp,w=Math.log,T=Math.pow,F=Math.sin,U=R=>{var He=a.length;return R>>>=0,!1},C=R=>{throw`exit(${R})`},Z=new Uint8Array(123),Ie=25;Ie>=0;--Ie)Z[48+Ie]=52+Ie,Z[65+Ie]=Ie,Z[97+Ie]=26+Ie;Z[43]=62,Z[47]=63;var dr={e:y,d:_,f:A,b:S,a:M,i:E,h:w,g:T,c:F,k:U,j:C};function ms(R){Fn=R.n,Cc=R.o,Rc=R.p,Fc=R.q,zc=R.r,kc=R.s,Dc=R.t,Pc=R.v}var Fn,Cc,Rc,Fc,zc,kc,Dc,Pc;function nf(R){R.m()}Tt.wasm||Object.defineProperty(Tt,"wasm",{get:()=>String.raw`dynEncode012091253f87dì%nä= 4&¿nÝØä‘ÂLÚªã9ÚØ[äº\ ¼¡³R=}L]ŸÈÿ2 ÿù¶J1jj¡é,zäV|i¸Qk¹‡=