quake2ts 0.0.480 → 0.0.481

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.
@@ -0,0 +1,25 @@
1
+ import { AudioApi } from '@quake2ts/engine';
2
+ import { ClientConfigStrings } from '../configStrings.js';
3
+ interface MinimalEntityState {
4
+ number: number;
5
+ sound?: number;
6
+ origin: {
7
+ x: number;
8
+ y: number;
9
+ z: number;
10
+ };
11
+ volume?: number;
12
+ attenuation?: number;
13
+ }
14
+ export declare class EntitySoundSystem {
15
+ private readonly audio;
16
+ private readonly configStrings;
17
+ private readonly trackedSounds;
18
+ private currentFrame;
19
+ constructor(audio: AudioApi, configStrings: ClientConfigStrings);
20
+ update(entities: MinimalEntityState[], nowMs: number): void;
21
+ private stopSound;
22
+ reset(): void;
23
+ }
24
+ export {};
25
+ //# sourceMappingURL=entity-sound.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity-sound.d.ts","sourceRoot":"","sources":["../../../src/audio/entity-sound.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAe,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAY1D,UAAU,kBAAkB;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,qBAAa,iBAAiB;IAK1B,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,aAAa;IALhC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAmC;IACjE,OAAO,CAAC,YAAY,CAAK;gBAGN,KAAK,EAAE,QAAQ,EACf,aAAa,EAAE,mBAAmB;IAGrD,MAAM,CAAC,QAAQ,EAAE,kBAAkB,EAAE,EAAE,KAAK,EAAE,MAAM;IA+DpD,OAAO,CAAC,SAAS;IAQjB,KAAK;CAMN"}
@@ -1,4 +1,4 @@
1
- "use strict";var Quake2Engine=(()=>{var uf=Object.create;var vs=Object.defineProperty;var ff=Object.getOwnPropertyDescriptor;var hf=Object.getOwnPropertyNames;var mf=Object.getPrototypeOf,pf=Object.prototype.hasOwnProperty;var gf=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),da=(e,t)=>{for(var r in t)vs(e,r,{get:t[r],enumerable:!0})},Vc=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of hf(t))!pf.call(e,i)&&i!==r&&vs(e,i,{get:()=>t[i],enumerable:!(n=ff(t,i))||n.enumerable});return e};var yf=(e,t,r)=>(r=e!=null?uf(mf(e)):{},Vc(t||!e||!e.__esModule?vs(r,"default",{value:e,enumerable:!0}):r,e)),xf=e=>Vc(vs({},"__esModule",{value:!0}),e);var Ad=gf((p_,wd)=>{"use strict";wd.exports=Worker});var Gx={};da(Gx,{ATTN_IDLE:()=>Ea,ATTN_LOOP_NONE:()=>Aa,ATTN_NONE:()=>Vn,ATTN_NORM:()=>Ma,ATTN_STATIC:()=>Ts,AssetDependencyError:()=>Tr,AssetDependencyTracker:()=>Xi,AssetManager:()=>xo,AssetPreviewGenerator:()=>la,AudioApi:()=>$r,AudioContextController:()=>bo,AudioRegistry:()=>xn,AudioRegistryError:()=>Vi,AudioSystem:()=>Eo,BSP_SURFACE_FRAGMENT_SOURCE:()=>cl,BSP_SURFACE_VERTEX_SOURCE:()=>ll,BSP_VERTEX_LAYOUT:()=>sl,BspLoader:()=>Yr,BspParseError:()=>Q,BspSurfacePipeline:()=>Ro,Camera:()=>Do,Command:()=>On,CommandRegistry:()=>Nr,ConfigStringRegistry:()=>Kr,Cvar:()=>Wn,CvarRegistry:()=>Wr,DemoAnalyzer:()=>Pn,DemoCameraMode:()=>Rc,DemoEventType:()=>Cc,DemoPlaybackController:()=>ms,DemoReader:()=>Ct,DemoRecorder:()=>ps,DemoValidator:()=>aa,DynamicLightManager:()=>Co,EngineHost:()=>Xr,EngineRuntime:()=>Xn,FileType:()=>Fc,FixedTimestepLoop:()=>ur,Framebuffer:()=>To,IndexBuffer:()=>xe,LruCache:()=>Nt,MAX_SOUND_CHANNELS:()=>Hn,MD2_FRAGMENT_SHADER:()=>gl,MD2_VERTEX_SHADER:()=>pl,MD3_FRAGMENT_SHADER:()=>Ml,MD3_VERTEX_SHADER:()=>Al,MapAnalyzer:()=>ca,Md2Loader:()=>qr,Md2MeshBuffers:()=>zo,Md2ParseError:()=>pe,Md2Pipeline:()=>ko,Md3Loader:()=>jr,Md3ModelMesh:()=>Bo,Md3ParseError:()=>Ge,Md3Pipeline:()=>Oo,Md3SurfaceMesh:()=>Zi,MusicSystem:()=>Lo,NetworkMessageParser:()=>kt,PARTICLE_FRAGMENT_SHADER:()=>Ll,PARTICLE_VERTEX_SHADER:()=>El,PROTOCOL_VERSION_RERELEASE:()=>kn,PakArchive:()=>Zr,PakIndexStore:()=>yo,PakIngestionError:()=>Ot,PakParseError:()=>Ve,PakValidationError:()=>fr,PakValidator:()=>Cs,ParticleRenderer:()=>Uo,ParticleSystem:()=>No,PlaybackState:()=>oa,RERELEASE_KNOWN_PAKS:()=>Ta,SKYBOX_FRAGMENT_SHADER:()=>hl,SKYBOX_VERTEX_SHADER:()=>fl,SOUND_FULLVOLUME:()=>Dt,SOUND_LOOP_ATTENUATE:()=>La,ShaderProgram:()=>Ee,SkyboxPipeline:()=>Fo,SoundChannel:()=>st,SoundPrecache:()=>So,SoundRegistry:()=>vo,SpriteLoader:()=>Qr,SpriteParseError:()=>Ut,Texture2D:()=>bn,TextureCache:()=>Jr,TextureCubeMap:()=>_n,TgaParseError:()=>yt,U_ALPHA:()=>gc,U_ANGLE1:()=>mc,U_ANGLE2:()=>lc,U_ANGLE3:()=>cc,U_EFFECTS16:()=>ia,U_EFFECTS8:()=>ta,U_EVENT:()=>uc,U_FRAME16:()=>yc,U_FRAME8:()=>dc,U_INSTANCE_BITS:()=>Mc,U_LOOP_ATTENUATION_HIGH:()=>Lc,U_LOOP_VOLUME:()=>Ec,U_MODEL:()=>pc,U_MODEL2:()=>xc,U_MODEL3:()=>bc,U_MODEL4:()=>_c,U_OLDORIGIN:()=>vc,U_OLD_FRAME_HIGH:()=>Ic,U_ORIGIN1:()=>oc,U_ORIGIN2:()=>ac,U_ORIGIN3:()=>hc,U_OWNER_HIGH:()=>Tc,U_REMOVE:()=>fc,U_RENDERFX16:()=>na,U_RENDERFX8:()=>ea,U_SCALE:()=>Ac,U_SKIN16:()=>sa,U_SKIN8:()=>ra,U_SOLID:()=>wc,U_SOUND:()=>Sc,VertexArray:()=>Fe,VertexBuffer:()=>Le,VirtualFileSystem:()=>Is,advanceAnimation:()=>xd,applySurfaceState:()=>uu,attenuationToDistanceMultiplier:()=>Bt,boxIntersectsFrustum:()=>$i,buildBspGeometry:()=>iu,buildMd2Geometry:()=>yl,buildMd2VertexData:()=>xl,buildMd3SurfaceGeometry:()=>Sl,buildMd3VertexData:()=>wl,calculateMaxAudibleDistance:()=>Gn,calculatePakChecksum:()=>od,computeFrameBlend:()=>bd,computeSkyScroll:()=>mu,createAnimationState:()=>_d,createAudioGraph:()=>_o,createBspSurfaces:()=>nu,createEmptyEntityState:()=>Br,createEmptyProtocolPlayerState:()=>hs,createEngine:()=>Vx,createEngineRuntime:()=>id,createFaceLightmap:()=>Fs,createInitialChannels:()=>wo,createProgramFromSources:()=>ru,createWebGLContext:()=>eu,decodeOgg:()=>go,deriveSurfaceRenderState:()=>ul,detectFileType:()=>zc,extractFrustumPlanes:()=>su,filesToPakSources:()=>Ia,findLeafForPoint:()=>al,gatherVisibleFaces:()=>cu,groupMd2Animations:()=>md,ingestPakFiles:()=>ad,ingestPaks:()=>Rs,interpolateMd3Tag:()=>Fu,interpolateVec3:()=>vd,isBinaryFile:()=>af,isTextFile:()=>kc,parseBsp:()=>Kn,parseMd2:()=>Ca,parseMd3:()=>Ra,parsePcx:()=>qn,parseSprite:()=>Fa,parseTga:()=>za,parseWal:()=>ks,parseWalTexture:()=>Bs,parseWav:()=>Os,pcxToRgba:()=>Ps,pickChannel:()=>Ao,preparePcxTexture:()=>Ds,removeViewTranslation:()=>hu,resolveLightStyles:()=>dl,spatializeOrigin:()=>Mo,spawnBlood:()=>Pu,spawnBulletImpact:()=>zu,spawnExplosion:()=>ku,spawnMuzzleFlash:()=>Bu,spawnTeleportFlash:()=>Du,spawnTrail:()=>Ou,walToRgba:()=>ka,wireDropTarget:()=>ld,wireFileInput:()=>cd});var bf=()=>typeof performance<"u"?performance.now():Date.now(),_f=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??bf,schedule:r.schedule??_f}}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 On=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 On(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 vf=Object.defineProperty,Gc=(e,t)=>{for(var r in t)vf(e,r,{get:t[r],enumerable:!0})},Wc={x:0,y:0,z:0};var $x=Math.PI/180;function Xc(e,t){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}function Sf(e,t){return{x:e.x*t,y:e.y*t,z:e.z*t}}function fa(e,t){return e.x*t.x+e.y*t.y+e.z*t.z}function wf(e){return fa(e,e)}function ha(e){return Math.sqrt(wf(e))}function Je(e){let t=ha(e);return t===0?e:Sf(e,1/t)}var Af=Math.PI/180,Mf=180/Math.PI,Vr=Af,ma=Mf;var Ur=[[-.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 Ef(){return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function Kc(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 $c(e,t){let r=Ef();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,Pt=2;var pa=8,ga=16,Lf=32;var Tf=16384;var Ss=65536,Zc=1<<17,If=1<<18,Cf=1<<19,Rf=1<<20,Ff=1<<21,zf=1<<22,kf=1<<23,Zx=1<<24,ws=1<<25,Pf=1<<26,Yx=1<<27,qx=1<<28,jx=1<<29,As=1<<30,Qx=1<<31;var Un=0;var Yc=4,qc=8,jc=16,Qc=32,Jc=64;var Jx=1<<25,eb=1<<28,tb=1<<29,rb=1<<30,nb=1<<31;var ib=it|Pt,sb=it|Ss|Pt|ws|As,ob=it|Ss|Pt,ab=it|Zc|Pt|ws|As,lb=Lf|pa|ga,cb=it|ga|pa,Df=it|ws|As|Pt|Pf,db=If|Cf|Rf|Ff|zf|kf,ub=it|pa|ga|ws|As,fb=it|Ss|Pt,hb=it|Pt,mb=it|Ss|Pt|Zc,pb=Df|Tf;var gb=Number.MAX_SAFE_INTEGER-1;var Ms=(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))(Ms||{});var Es=256;var ya=256,xa=8192,Ls=2048,ba=512,_a=256,va=Es*2,Sa=256,ua=32,Nn=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+xa]="Sounds",e[e.Images=e.Sounds+Ls]="Images",e[e.Lights=e.Images+ba]="Lights",e[e.ShadowLights=e.Lights+ya]="ShadowLights",e[e.Items=e.ShadowLights+Sa]="Items",e[e.PlayerSkins=e.Items+_a]="PlayerSkins",e[e.General=e.PlayerSkins+Es]="General",e[e.WheelWeapons=e.General+va]="WheelWeapons",e[e.WheelAmmo=e.WheelWeapons+ua]="WheelAmmo",e[e.WheelPowerups=e.WheelAmmo+ua]="WheelPowerups",e[e.CdLoopCount=e.WheelPowerups+ua]="CdLoopCount",e[e.GameStyle=e.CdLoopCount+1]="GameStyle",e[e.MaxConfigStrings=e.GameStyle+1]="MaxConfigStrings",e))(j||{}),ed=j.MaxConfigStrings;function td(e){return e>=5&&e<59?Nn*(59-e):e>=j.General&&e<j.WheelWeapons?Nn*(j.MaxConfigStrings-e):Nn}var Bf={};Gc(Bf,{addReplayFrame:()=>Hf,createReplaySession:()=>Uf,deserializeReplay:()=>Nf,serializeReplay:()=>Of});function Of(e){return JSON.stringify(e,null,2)}function Nf(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 Uf(e,t){return{metadata:{map:e,date:new Date().toISOString(),version:"1.0",seed:t},frames:[]}}function Hf(e,t,r,n){e.frames.push({serverFrame:r,cmd:t,timestamp:Date.now()-n})}var F=(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))(F||{});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 Vf=12,Gf=9,yb=Math.ceil(Vf*Gf/16),Wf=23,Xf=2,xb=Math.ceil(Wf*Xf/16);var Kf={};Gc(Kf,{U_ANGLE1:()=>Jf,U_ANGLE2:()=>eh,U_ANGLE3:()=>th,U_EFFECTS:()=>ih,U_EVENT:()=>ah,U_FRAME:()=>rh,U_MODEL:()=>Zf,U_MODEL2:()=>ch,U_MODEL3:()=>dh,U_MODEL4:()=>uh,U_MOREBITS:()=>lh,U_NUMBER:()=>$f,U_ORIGIN1:()=>qf,U_ORIGIN2:()=>jf,U_ORIGIN3:()=>Qf,U_REMOVE:()=>fh,U_RENDERFX:()=>sh,U_SKIN:()=>nh,U_SOLID:()=>oh,U_SOUND:()=>Yf});var $f=1,Zf=2,Yf=4,qf=8,jf=16,Qf=32,Jf=64,eh=128,th=256,rh=512,nh=1024,ih=2048,sh=4096,oh=8192,ah=16384,lh=32768,ch=1,dh=2,uh=4,fh=32768;var Gr=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}getReadPosition(){return this.offset}getLength(){return this.length}getRemaining(){return this.length-this.offset}seek(e){if(e<0||e>this.length)throw new Error(`Seek out of bounds: ${e} (length: ${this.length})`);this.offset=e}setReadPosition(e){this.seek(e)}hasMore(){return this.offset<this.length}hasBytes(e){return this.offset+e<=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=Ur[t];e.x=r[0],e.y=r[1],e.z=r[2]}},wa=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<Ur.length;n++){let i=Ur[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 Hr=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 wa(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}};Hr.MAX_MSGLEN=1400;Hr.FRAGMENT_SIZE=1024;Hr.PACKET_HEADER=10;Hr.HEADER_OVERHEAD=Hr.PACKET_HEADER+2;Hr.MAX_RELIABLE_BUFFER=262144;var rd=(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))(rd||{}),bb=Object.keys(rd).length/2;var Hn=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||{}),Aa=-1,Vn=0,Ma=1,Ea=2,Ts=3,Dt=80,La=.003;function Bt(e){return e===Ts?e*.001:e*5e-4}function Gn(e){let t=Bt(e);return t<=0?Number.POSITIVE_INFINITY:Dt+1/t}var Wn=class{constructor({name:t,defaultValue:r,description:n,flags:i=Ms.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&Ms.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)}},Wr=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 Wn({...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 Xr=class{constructor(t,r,n={}){this.game=t;this.client=r;this.started=!1;this.paused_=!1;this.commands=new Nr;this.cvars=new Wr;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.paused_=!1,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,this.paused_=!1)}setPaused(t){this.paused_=t,t?this.loop.stop():this.started&&this.loop.start()}get paused(){return this.paused_}pump(t){this.loop.pump(t)}getLatestFrame(){return this.latestFrame}isRunning(){return this.loop.isRunning()}};function hh(e){if(e<0||e>=j.MaxConfigStrings)throw new RangeError(`Configstring index ${e} is out of range (0-${j.MaxConfigStrings-1})`)}function nd(e,t){let r=td(e);if(t.length>r)throw new RangeError(`Configstring ${e} exceeds maximum length (${t.length} > ${r}); limit is ${Nn} chars per slot`)}var Kr=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 hh(t),nd(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(ed).fill("");for(let[r,n]of this.values.entries())t[r]=n;return t}modelIndex(t){return this.register(t,j.Models,xa,"modelCursor")}soundIndex(t){return this.register(t,j.Sounds,Ls,"soundCursor")}findSoundIndex(t){for(let r=j.Sounds;r<j.Sounds+Ls;r+=1)if(this.values.get(r)===t)return r}imageIndex(t){return this.register(t,j.Images,ba,"imageCursor")}lightIndex(t){return this.register(t,j.Lights,ya,"lightCursor")}shadowLightIndex(t){return this.register(t,j.ShadowLights,Sa,"shadowLightCursor")}itemIndex(t){return this.register(t,j.Items,_a,"itemCursor")}playerSkinIndex(t){return this.register(t,j.PlayerSkins,Es,"playerSkinCursor")}generalIndex(t){return this.register(t,j.General,va,"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 nd(s,t),this.values.set(s,t),this[i]=s+1,s}};var $r=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 Xn=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 id(e,t,r,n,i){let s=new $r({...n,client:r}),o=new Xr(t,r,i);return{runtime:new Xn(e,o),audio:s}}var mh="PACK";function ph(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 gh(){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 yh=gh();function sd(e){let t=4294967295;for(let r=0;r<e.length;r+=1){let n=e[r];t=yh[(t^n)&255]^t>>>8}return(t^4294967295)>>>0}var Ve=class extends Error{},Zr=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!==mh)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=ph(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,sd(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 od(e){return sd(new Uint8Array(e))}var Is=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 Ta=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"}},Cs=class{constructor(t=Ta){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 xh(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 bh(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 xh(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 Rs(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 bh(l,n.onProgress),h=Zr.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 _h(e){return Array.isArray(e)?e:Array.from(e)}function Ia(e){return _h(e).map(t=>({name:t.name,data:t}))}async function ad(e,t,r){let n=Ia(t);return Rs(e,n,r??{})}function ld(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 cd(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 vh="IBSP",Sh=38,ud=19,wh=8+ud*8;var Q=class extends Error{},Yr=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),Kn(n.buffer)}};function Kn(e){if(e.byteLength<wh)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!==vh)throw new Q(`Invalid BSP magic ${r}`);let n=t.getInt32(4,!0);if(n!==Sh)throw new Q(`Unsupported BSP version ${n}`);let i=new Map;for(let S=0;S<ud;S+=1){let M=t.getInt32(8+S*8,!0),L=t.getInt32(12+S*8,!0);if(M<0||L<0||M+L>e.byteLength)throw new Q(`Invalid lump bounds for index ${S}`);i.set(S,{offset:M,length:L})}let s={version:n,lumps:i},o=Mh(e,i.get(0)),a=Lh(e,i.get(1)),d=Th(e,i.get(2)),l=Ih(e,i.get(4)),c=Ch(e,i.get(5)),h=Rh(e,i.get(6)),u=new Uint8Array(e,i.get(7).offset,i.get(7).length),f=Uh(h,i.get(7)),m=Fh(e,i.get(8)),g=zh(e,i.get(11)),p=kh(e,i.get(12)),y=Ph(e,i.get(13)),_=Dh(e,i.get(14)),b=Bh(e,i.get(15)),x=Oh(e,i.get(9),i.get(10),m),v=Nh(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,L=1/0;for(let w of o.entities){let T=w.properties.model;if(!T||!T.startsWith("*"))continue;let z=parseInt(T.substring(1),10);if(isNaN(z)||z<0||z>=y.length)continue;let U=y[z],C=Ah(S.origin,S.direction,U.mins,U.maxs);C!==null&&C<L&&(L=C,M={entity:w,model:U,distance:C})}return M}}}function Ah(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 Mh(e,t){let r=new TextDecoder().decode(new Uint8Array(e,t.offset,t.length)),n=Eh(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 Eh(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 Lh(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 Th(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 Ih(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 Ch(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 Rh(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 Fh(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 zh(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 kh(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 Ph(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 Dh(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 Bh(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 Oh(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 Nh(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:dd(e,c,n,t),phs:dd(e,h,n,t)})}return{numClusters:n,clusters:o}}function dd(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 Uh(e,t){return e.map(r=>{if(!(r.lightOffset<0))return{offset:r.lightOffset,length:Math.max(0,t.length-r.lightOffset)}})}function Fs(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 Hh=844121161,Vh=8,fd=68,Gh=[{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{},qr=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=Ca(n.buffer);return this.cache.set(t,i),i}get(t){return this.cache.get(t)}};function hd(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 $n(e,t,r,n){if(r!==0&&(t<fd||t+r>e.byteLength))throw new pe(`${n} section is out of bounds`)}function Wh(e){if(e.byteLength<fd)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!==Hh)throw new pe(`Invalid MD2 ident: ${r}`);if(n!==Vh)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 Xh(e,t){let r=t.numSkins*64;$n(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:hd(n,s*64,64)});return i}function Kh(e,t){let r=t.numTexCoords*4;$n(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 $h(e,t){let r=t.numTriangles*12;$n(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 Zh(e,t){let r=t.numFrames*t.frameSize;$n(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=hd(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=Gh[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 Yh(e,t){let r=t.numGlCommands*4;if($n(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 Ca(e){let t=Wh(e),r=Xh(e,t),n=Kh(e,t),i=$h(e,t),s=Zh(e,t),o=Yh(e,t);return{header:t,skins:r,texCoords:n,triangles:i,frames:s,glCommands:o}}function md(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 pd=860898377,qh=15,Ge=class extends Error{constructor(t){super(t),this.name="Md3ParseError"}};function Zn(e,t,r){let n=new Uint8Array(e.buffer,e.byteOffset+t,r);return new TextDecoder("utf-8").decode(n).replace(/\0.*$/,"").trim()}function jh(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 zs(e,t,r,n){if(t<0||t+r>n)throw new Ge(`${e} exceeds buffer bounds`)}function Qh(e){let t=e.getInt32(0,!0);if(t!==pd)throw new Ge(`Invalid MD3 ident: ${t}`);let r=e.getInt32(4,!0);if(r!==qh)throw new Ge(`Unsupported MD3 version: ${r}`);let n=Zn(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 Jh(e,t){let r=[];zs("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:Zn(e,s+40,16)})}return r}function em(e,t){let r=[],i=t.numFrames*t.numTags*112;zs("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:Zn(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 tm(e,t){let r=e.getInt32(t,!0);if(r!==pd)throw new Ge(`Invalid surface ident at ${t}: ${r}`);let n=Zn(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;zs(`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:Zn(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 L=0;L<a;L+=1){let w=A+(S*a+L)*8,T=e.getInt16(w,!0)/64,z=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:z,z:U},latLng:C,normal:jh(C)})}v.push(M)}return{surface:{name:n,flags:i,numFrames:s,shaders:y,triangles:g,texCoords:b,vertices:v},nextOffset:t+f}}function Ra(e){if(e.byteLength<108)throw new Ge("MD3 buffer too small for header");let t=new DataView(e),r=Qh(t);zs("MD3 end",r.ofsEnd,0,e.byteLength);let n=Jh(t,r),i=em(t,r),s=[],o=r.ofsSurfaces;for(let a=0;a<r.numSurfaces;a+=1){let{surface:d,nextOffset:l}=tm(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 jr=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=Ra(r.slice().buffer);return this.cache.set(t,n),n}get(t){return this.cache.get(t)}};var rm=844317769,nm=2,gd=64,yd=12,Ut=class extends Error{};function im(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 Fa(e){if(e.byteLength<yd)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!==rm)throw new Ut(`Invalid Sprite ident: ${r}`);if(n!==nm)throw new Ut(`Unsupported Sprite version: ${n}`);let s=[],o=16+gd,a=yd;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=im(t,a+16,gd);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),Fa(n.buffer)}};function xd(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 bd(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 _d(e){return{sequence:e,time:0}}function vd(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 Yn=class extends Error{constructor(t){super(t),this.name="WalParseError"}};function ks(e){if(e.byteLength<100)throw new Yn("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 Yn("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 Yn(`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 qn(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 Ps(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 za(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],L=y[u],w=c?255:a===32?y[u+3]:255;u+=h;for(let T=0;T<v;T++){let z=(b+T)*4;m[z]=S,m[z+1]=M,m[z+2]=L,m[z+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 ka(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 Ds(e){let t=Ps(e),r={level:0,width:e.width,height:e.height,rgba:t};return{width:e.width,height:e.height,levels:[r],source:"pcx"}}function Sd(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 Bs(e,t){return ka(ks(e),t)}var mr=class extends Error{constructor(t){super(t),this.name="WavParseError"}};function Pa(e,t,r){return new TextDecoder("ascii").decode(new Uint8Array(e.buffer,e.byteOffset+t,r))}function Os(e){if(e.byteLength<44)throw new mr("WAV buffer too small");let t=new DataView(e);if(Pa(t,0,4)!=="RIFF"||Pa(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=Pa(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 sm=(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 Da=(e,t=sm)=>{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 uf=Object.create;var vs=Object.defineProperty;var ff=Object.getOwnPropertyDescriptor;var hf=Object.getOwnPropertyNames;var mf=Object.getPrototypeOf,pf=Object.prototype.hasOwnProperty;var gf=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),da=(e,t)=>{for(var r in t)vs(e,r,{get:t[r],enumerable:!0})},Vc=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of hf(t))!pf.call(e,i)&&i!==r&&vs(e,i,{get:()=>t[i],enumerable:!(n=ff(t,i))||n.enumerable});return e};var yf=(e,t,r)=>(r=e!=null?uf(mf(e)):{},Vc(t||!e||!e.__esModule?vs(r,"default",{value:e,enumerable:!0}):r,e)),xf=e=>Vc(vs({},"__esModule",{value:!0}),e);var Ad=gf((p_,wd)=>{"use strict";wd.exports=Worker});var Gx={};da(Gx,{ATTN_IDLE:()=>Ea,ATTN_LOOP_NONE:()=>Aa,ATTN_NONE:()=>Vn,ATTN_NORM:()=>Ma,ATTN_STATIC:()=>Ts,AssetDependencyError:()=>Tr,AssetDependencyTracker:()=>Xi,AssetManager:()=>xo,AssetPreviewGenerator:()=>la,AudioApi:()=>$r,AudioContextController:()=>bo,AudioRegistry:()=>xn,AudioRegistryError:()=>Vi,AudioSystem:()=>Eo,BSP_SURFACE_FRAGMENT_SOURCE:()=>cl,BSP_SURFACE_VERTEX_SOURCE:()=>ll,BSP_VERTEX_LAYOUT:()=>sl,BspLoader:()=>Yr,BspParseError:()=>Q,BspSurfacePipeline:()=>Ro,Camera:()=>Do,Command:()=>On,CommandRegistry:()=>Nr,ConfigStringRegistry:()=>Kr,Cvar:()=>Wn,CvarRegistry:()=>Wr,DemoAnalyzer:()=>Pn,DemoCameraMode:()=>Rc,DemoEventType:()=>Cc,DemoPlaybackController:()=>ms,DemoReader:()=>Ct,DemoRecorder:()=>ps,DemoValidator:()=>aa,DynamicLightManager:()=>Co,EngineHost:()=>Xr,EngineRuntime:()=>Xn,FileType:()=>Fc,FixedTimestepLoop:()=>ur,Framebuffer:()=>To,IndexBuffer:()=>xe,LruCache:()=>Nt,MAX_SOUND_CHANNELS:()=>Hn,MD2_FRAGMENT_SHADER:()=>gl,MD2_VERTEX_SHADER:()=>pl,MD3_FRAGMENT_SHADER:()=>Ml,MD3_VERTEX_SHADER:()=>Al,MapAnalyzer:()=>ca,Md2Loader:()=>qr,Md2MeshBuffers:()=>zo,Md2ParseError:()=>pe,Md2Pipeline:()=>ko,Md3Loader:()=>jr,Md3ModelMesh:()=>Bo,Md3ParseError:()=>Ge,Md3Pipeline:()=>Oo,Md3SurfaceMesh:()=>Zi,MusicSystem:()=>Lo,NetworkMessageParser:()=>kt,PARTICLE_FRAGMENT_SHADER:()=>Ll,PARTICLE_VERTEX_SHADER:()=>El,PROTOCOL_VERSION_RERELEASE:()=>kn,PakArchive:()=>Zr,PakIndexStore:()=>yo,PakIngestionError:()=>Ot,PakParseError:()=>Ve,PakValidationError:()=>fr,PakValidator:()=>Cs,ParticleRenderer:()=>Uo,ParticleSystem:()=>No,PlaybackState:()=>oa,RERELEASE_KNOWN_PAKS:()=>Ta,SKYBOX_FRAGMENT_SHADER:()=>hl,SKYBOX_VERTEX_SHADER:()=>fl,SOUND_FULLVOLUME:()=>Dt,SOUND_LOOP_ATTENUATE:()=>La,ShaderProgram:()=>Ee,SkyboxPipeline:()=>Fo,SoundChannel:()=>st,SoundPrecache:()=>So,SoundRegistry:()=>vo,SpriteLoader:()=>Qr,SpriteParseError:()=>Ut,Texture2D:()=>bn,TextureCache:()=>Jr,TextureCubeMap:()=>_n,TgaParseError:()=>yt,U_ALPHA:()=>gc,U_ANGLE1:()=>mc,U_ANGLE2:()=>lc,U_ANGLE3:()=>cc,U_EFFECTS16:()=>ia,U_EFFECTS8:()=>ta,U_EVENT:()=>uc,U_FRAME16:()=>yc,U_FRAME8:()=>dc,U_INSTANCE_BITS:()=>Mc,U_LOOP_ATTENUATION_HIGH:()=>Lc,U_LOOP_VOLUME:()=>Ec,U_MODEL:()=>pc,U_MODEL2:()=>xc,U_MODEL3:()=>bc,U_MODEL4:()=>_c,U_OLDORIGIN:()=>vc,U_OLD_FRAME_HIGH:()=>Ic,U_ORIGIN1:()=>oc,U_ORIGIN2:()=>ac,U_ORIGIN3:()=>hc,U_OWNER_HIGH:()=>Tc,U_REMOVE:()=>fc,U_RENDERFX16:()=>na,U_RENDERFX8:()=>ea,U_SCALE:()=>Ac,U_SKIN16:()=>sa,U_SKIN8:()=>ra,U_SOLID:()=>wc,U_SOUND:()=>Sc,VertexArray:()=>Fe,VertexBuffer:()=>Le,VirtualFileSystem:()=>Is,advanceAnimation:()=>xd,applySurfaceState:()=>uu,attenuationToDistanceMultiplier:()=>Bt,boxIntersectsFrustum:()=>$i,buildBspGeometry:()=>iu,buildMd2Geometry:()=>yl,buildMd2VertexData:()=>xl,buildMd3SurfaceGeometry:()=>Sl,buildMd3VertexData:()=>wl,calculateMaxAudibleDistance:()=>Gn,calculatePakChecksum:()=>od,computeFrameBlend:()=>bd,computeSkyScroll:()=>mu,createAnimationState:()=>_d,createAudioGraph:()=>_o,createBspSurfaces:()=>nu,createEmptyEntityState:()=>Br,createEmptyProtocolPlayerState:()=>hs,createEngine:()=>Vx,createEngineRuntime:()=>id,createFaceLightmap:()=>Fs,createInitialChannels:()=>wo,createProgramFromSources:()=>ru,createWebGLContext:()=>eu,decodeOgg:()=>go,deriveSurfaceRenderState:()=>ul,detectFileType:()=>zc,extractFrustumPlanes:()=>su,filesToPakSources:()=>Ia,findLeafForPoint:()=>al,gatherVisibleFaces:()=>cu,groupMd2Animations:()=>md,ingestPakFiles:()=>ad,ingestPaks:()=>Rs,interpolateMd3Tag:()=>Fu,interpolateVec3:()=>vd,isBinaryFile:()=>af,isTextFile:()=>kc,parseBsp:()=>Kn,parseMd2:()=>Ca,parseMd3:()=>Ra,parsePcx:()=>qn,parseSprite:()=>Fa,parseTga:()=>za,parseWal:()=>ks,parseWalTexture:()=>Bs,parseWav:()=>Os,pcxToRgba:()=>Ps,pickChannel:()=>Ao,preparePcxTexture:()=>Ds,removeViewTranslation:()=>hu,resolveLightStyles:()=>dl,spatializeOrigin:()=>Mo,spawnBlood:()=>Pu,spawnBulletImpact:()=>zu,spawnExplosion:()=>ku,spawnMuzzleFlash:()=>Bu,spawnTeleportFlash:()=>Du,spawnTrail:()=>Ou,walToRgba:()=>ka,wireDropTarget:()=>ld,wireFileInput:()=>cd});var bf=()=>typeof performance<"u"?performance.now():Date.now(),_f=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??bf,schedule:r.schedule??_f}}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 On=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 On(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 vf=Object.defineProperty,Gc=(e,t)=>{for(var r in t)vf(e,r,{get:t[r],enumerable:!0})},Wc={x:0,y:0,z:0};var $x=Math.PI/180;function Xc(e,t){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}function Sf(e,t){return{x:e.x*t,y:e.y*t,z:e.z*t}}function fa(e,t){return e.x*t.x+e.y*t.y+e.z*t.z}function wf(e){return fa(e,e)}function ha(e){return Math.sqrt(wf(e))}function Je(e){let t=ha(e);return t===0?e:Sf(e,1/t)}var Af=Math.PI/180,Mf=180/Math.PI,Vr=Af,ma=Mf;var Ur=[[-.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 Ef(){return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function Kc(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 $c(e,t){let r=Ef();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,Pt=2;var pa=8,ga=16,Lf=32;var Tf=16384;var Ss=65536,Zc=1<<17,If=1<<18,Cf=1<<19,Rf=1<<20,Ff=1<<21,zf=1<<22,kf=1<<23,Zx=1<<24,ws=1<<25,Pf=1<<26,Yx=1<<27,qx=1<<28,jx=1<<29,As=1<<30,Qx=1<<31;var Un=0;var Yc=4,qc=8,jc=16,Qc=32,Jc=64;var Jx=1<<25,eb=1<<28,tb=1<<29,rb=1<<30,nb=1<<31;var ib=it|Pt,sb=it|Ss|Pt|ws|As,ob=it|Ss|Pt,ab=it|Zc|Pt|ws|As,lb=Lf|pa|ga,cb=it|ga|pa,Df=it|ws|As|Pt|Pf,db=If|Cf|Rf|Ff|zf|kf,ub=it|pa|ga|ws|As,fb=it|Ss|Pt,hb=it|Pt,mb=it|Ss|Pt|Zc,pb=Df|Tf;var gb=Number.MAX_SAFE_INTEGER-1;var Ms=(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))(Ms||{});var Es=256;var ya=256,xa=8192,Ls=2048,ba=512,_a=256,va=Es*2,Sa=256,ua=32,Nn=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+xa]="Sounds",e[e.Images=e.Sounds+Ls]="Images",e[e.Lights=e.Images+ba]="Lights",e[e.ShadowLights=e.Lights+ya]="ShadowLights",e[e.Items=e.ShadowLights+Sa]="Items",e[e.PlayerSkins=e.Items+_a]="PlayerSkins",e[e.General=e.PlayerSkins+Es]="General",e[e.WheelWeapons=e.General+va]="WheelWeapons",e[e.WheelAmmo=e.WheelWeapons+ua]="WheelAmmo",e[e.WheelPowerups=e.WheelAmmo+ua]="WheelPowerups",e[e.CdLoopCount=e.WheelPowerups+ua]="CdLoopCount",e[e.GameStyle=e.CdLoopCount+1]="GameStyle",e[e.MaxConfigStrings=e.GameStyle+1]="MaxConfigStrings",e))(j||{}),ed=j.MaxConfigStrings;function td(e){return e>=5&&e<59?Nn*(59-e):e>=j.General&&e<j.WheelWeapons?Nn*(j.MaxConfigStrings-e):Nn}var Bf={};Gc(Bf,{addReplayFrame:()=>Hf,createReplaySession:()=>Uf,deserializeReplay:()=>Nf,serializeReplay:()=>Of});function Of(e){return JSON.stringify(e,null,2)}function Nf(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 Uf(e,t){return{metadata:{map:e,date:new Date().toISOString(),version:"1.0",seed:t},frames:[]}}function Hf(e,t,r,n){e.frames.push({serverFrame:r,cmd:t,timestamp:Date.now()-n})}var F=(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))(F||{});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 Vf=12,Gf=9,yb=Math.ceil(Vf*Gf/16),Wf=23,Xf=2,xb=Math.ceil(Wf*Xf/16);var Kf={};Gc(Kf,{U_ANGLE1:()=>Jf,U_ANGLE2:()=>eh,U_ANGLE3:()=>th,U_EFFECTS:()=>ih,U_EVENT:()=>ah,U_FRAME:()=>rh,U_MODEL:()=>Zf,U_MODEL2:()=>ch,U_MODEL3:()=>dh,U_MODEL4:()=>uh,U_MOREBITS:()=>lh,U_NUMBER:()=>$f,U_ORIGIN1:()=>qf,U_ORIGIN2:()=>jf,U_ORIGIN3:()=>Qf,U_REMOVE:()=>fh,U_RENDERFX:()=>sh,U_SKIN:()=>nh,U_SOLID:()=>oh,U_SOUND:()=>Yf});var $f=1,Zf=2,Yf=4,qf=8,jf=16,Qf=32,Jf=64,eh=128,th=256,rh=512,nh=1024,ih=2048,sh=4096,oh=8192,ah=16384,lh=32768,ch=1,dh=2,uh=4,fh=32768;var Gr=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}getReadPosition(){return this.offset}getLength(){return this.length}getRemaining(){return this.length-this.offset}seek(e){if(e<0||e>this.length)throw new Error(`Seek out of bounds: ${e} (length: ${this.length})`);this.offset=e}setReadPosition(e){this.seek(e)}hasMore(){return this.offset<this.length}hasBytes(e){return this.offset+e<=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=Ur[t];e.x=r[0],e.y=r[1],e.z=r[2]}},wa=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<Ur.length;n++){let i=Ur[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 Hr=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 wa(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}};Hr.MAX_MSGLEN=1400;Hr.FRAGMENT_SIZE=1024;Hr.PACKET_HEADER=10;Hr.HEADER_OVERHEAD=Hr.PACKET_HEADER+2;Hr.MAX_RELIABLE_BUFFER=262144;var rd=(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))(rd||{}),bb=Object.keys(rd).length/2;var Hn=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||{}),Aa=-1,Vn=0,Ma=1,Ea=2,Ts=3,Dt=80,La=.003;function Bt(e){return e===Ts?e*.001:e*5e-4}function Gn(e){let t=Bt(e);return t<=0?Number.POSITIVE_INFINITY:Dt+1/t}var Wn=class{constructor({name:t,defaultValue:r,description:n,flags:i=Ms.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&Ms.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)}},Wr=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 Wn({...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 Xr=class{constructor(t,r,n={}){this.game=t;this.client=r;this.started=!1;this.paused_=!1;this.commands=new Nr;this.cvars=new Wr;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.paused_=!1,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,this.paused_=!1)}setPaused(t){this.paused_=t,t?this.loop.stop():this.started&&this.loop.start()}get paused(){return this.paused_}pump(t){this.loop.pump(t)}getLatestFrame(){return this.latestFrame}isRunning(){return this.loop.isRunning()}};function hh(e){if(e<0||e>=j.MaxConfigStrings)throw new RangeError(`Configstring index ${e} is out of range (0-${j.MaxConfigStrings-1})`)}function nd(e,t){let r=td(e);if(t.length>r)throw new RangeError(`Configstring ${e} exceeds maximum length (${t.length} > ${r}); limit is ${Nn} chars per slot`)}var Kr=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 hh(t),nd(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(ed).fill("");for(let[r,n]of this.values.entries())t[r]=n;return t}modelIndex(t){return this.register(t,j.Models,xa,"modelCursor")}soundIndex(t){return this.register(t,j.Sounds,Ls,"soundCursor")}findSoundIndex(t){for(let r=j.Sounds;r<j.Sounds+Ls;r+=1)if(this.values.get(r)===t)return r}imageIndex(t){return this.register(t,j.Images,ba,"imageCursor")}lightIndex(t){return this.register(t,j.Lights,ya,"lightCursor")}shadowLightIndex(t){return this.register(t,j.ShadowLights,Sa,"shadowLightCursor")}itemIndex(t){return this.register(t,j.Items,_a,"itemCursor")}playerSkinIndex(t){return this.register(t,j.PlayerSkins,Es,"playerSkinCursor")}generalIndex(t){return this.register(t,j.General,va,"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 nd(s,t),this.values.set(s,t),this[i]=s+1,s}};var $r=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){let o=this.system.play({entity:t,channel:r,soundIndex:n,volume:i,attenuation:s,looping:!0});return this.triggerSubtitle(n),o}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 Xn=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 id(e,t,r,n,i){let s=new $r({...n,client:r}),o=new Xr(t,r,i);return{runtime:new Xn(e,o),audio:s}}var mh="PACK";function ph(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 gh(){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 yh=gh();function sd(e){let t=4294967295;for(let r=0;r<e.length;r+=1){let n=e[r];t=yh[(t^n)&255]^t>>>8}return(t^4294967295)>>>0}var Ve=class extends Error{},Zr=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!==mh)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=ph(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,sd(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 od(e){return sd(new Uint8Array(e))}var Is=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 Ta=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"}},Cs=class{constructor(t=Ta){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 xh(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 bh(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 xh(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 Rs(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 bh(l,n.onProgress),h=Zr.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 _h(e){return Array.isArray(e)?e:Array.from(e)}function Ia(e){return _h(e).map(t=>({name:t.name,data:t}))}async function ad(e,t,r){let n=Ia(t);return Rs(e,n,r??{})}function ld(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 cd(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 vh="IBSP",Sh=38,ud=19,wh=8+ud*8;var Q=class extends Error{},Yr=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),Kn(n.buffer)}};function Kn(e){if(e.byteLength<wh)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!==vh)throw new Q(`Invalid BSP magic ${r}`);let n=t.getInt32(4,!0);if(n!==Sh)throw new Q(`Unsupported BSP version ${n}`);let i=new Map;for(let S=0;S<ud;S+=1){let M=t.getInt32(8+S*8,!0),L=t.getInt32(12+S*8,!0);if(M<0||L<0||M+L>e.byteLength)throw new Q(`Invalid lump bounds for index ${S}`);i.set(S,{offset:M,length:L})}let s={version:n,lumps:i},o=Mh(e,i.get(0)),a=Lh(e,i.get(1)),d=Th(e,i.get(2)),l=Ih(e,i.get(4)),c=Ch(e,i.get(5)),h=Rh(e,i.get(6)),u=new Uint8Array(e,i.get(7).offset,i.get(7).length),f=Uh(h,i.get(7)),m=Fh(e,i.get(8)),g=zh(e,i.get(11)),p=kh(e,i.get(12)),y=Ph(e,i.get(13)),_=Dh(e,i.get(14)),b=Bh(e,i.get(15)),x=Oh(e,i.get(9),i.get(10),m),v=Nh(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,L=1/0;for(let w of o.entities){let T=w.properties.model;if(!T||!T.startsWith("*"))continue;let z=parseInt(T.substring(1),10);if(isNaN(z)||z<0||z>=y.length)continue;let U=y[z],C=Ah(S.origin,S.direction,U.mins,U.maxs);C!==null&&C<L&&(L=C,M={entity:w,model:U,distance:C})}return M}}}function Ah(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 Mh(e,t){let r=new TextDecoder().decode(new Uint8Array(e,t.offset,t.length)),n=Eh(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 Eh(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 Lh(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 Th(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 Ih(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 Ch(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 Rh(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 Fh(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 zh(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 kh(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 Ph(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 Dh(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 Bh(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 Oh(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 Nh(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:dd(e,c,n,t),phs:dd(e,h,n,t)})}return{numClusters:n,clusters:o}}function dd(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 Uh(e,t){return e.map(r=>{if(!(r.lightOffset<0))return{offset:r.lightOffset,length:Math.max(0,t.length-r.lightOffset)}})}function Fs(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 Hh=844121161,Vh=8,fd=68,Gh=[{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{},qr=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=Ca(n.buffer);return this.cache.set(t,i),i}get(t){return this.cache.get(t)}};function hd(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 $n(e,t,r,n){if(r!==0&&(t<fd||t+r>e.byteLength))throw new pe(`${n} section is out of bounds`)}function Wh(e){if(e.byteLength<fd)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!==Hh)throw new pe(`Invalid MD2 ident: ${r}`);if(n!==Vh)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 Xh(e,t){let r=t.numSkins*64;$n(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:hd(n,s*64,64)});return i}function Kh(e,t){let r=t.numTexCoords*4;$n(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 $h(e,t){let r=t.numTriangles*12;$n(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 Zh(e,t){let r=t.numFrames*t.frameSize;$n(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=hd(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=Gh[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 Yh(e,t){let r=t.numGlCommands*4;if($n(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 Ca(e){let t=Wh(e),r=Xh(e,t),n=Kh(e,t),i=$h(e,t),s=Zh(e,t),o=Yh(e,t);return{header:t,skins:r,texCoords:n,triangles:i,frames:s,glCommands:o}}function md(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 pd=860898377,qh=15,Ge=class extends Error{constructor(t){super(t),this.name="Md3ParseError"}};function Zn(e,t,r){let n=new Uint8Array(e.buffer,e.byteOffset+t,r);return new TextDecoder("utf-8").decode(n).replace(/\0.*$/,"").trim()}function jh(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 zs(e,t,r,n){if(t<0||t+r>n)throw new Ge(`${e} exceeds buffer bounds`)}function Qh(e){let t=e.getInt32(0,!0);if(t!==pd)throw new Ge(`Invalid MD3 ident: ${t}`);let r=e.getInt32(4,!0);if(r!==qh)throw new Ge(`Unsupported MD3 version: ${r}`);let n=Zn(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 Jh(e,t){let r=[];zs("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:Zn(e,s+40,16)})}return r}function em(e,t){let r=[],i=t.numFrames*t.numTags*112;zs("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:Zn(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 tm(e,t){let r=e.getInt32(t,!0);if(r!==pd)throw new Ge(`Invalid surface ident at ${t}: ${r}`);let n=Zn(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;zs(`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:Zn(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 L=0;L<a;L+=1){let w=A+(S*a+L)*8,T=e.getInt16(w,!0)/64,z=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:z,z:U},latLng:C,normal:jh(C)})}v.push(M)}return{surface:{name:n,flags:i,numFrames:s,shaders:y,triangles:g,texCoords:b,vertices:v},nextOffset:t+f}}function Ra(e){if(e.byteLength<108)throw new Ge("MD3 buffer too small for header");let t=new DataView(e),r=Qh(t);zs("MD3 end",r.ofsEnd,0,e.byteLength);let n=Jh(t,r),i=em(t,r),s=[],o=r.ofsSurfaces;for(let a=0;a<r.numSurfaces;a+=1){let{surface:d,nextOffset:l}=tm(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 jr=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=Ra(r.slice().buffer);return this.cache.set(t,n),n}get(t){return this.cache.get(t)}};var rm=844317769,nm=2,gd=64,yd=12,Ut=class extends Error{};function im(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 Fa(e){if(e.byteLength<yd)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!==rm)throw new Ut(`Invalid Sprite ident: ${r}`);if(n!==nm)throw new Ut(`Unsupported Sprite version: ${n}`);let s=[],o=16+gd,a=yd;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=im(t,a+16,gd);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),Fa(n.buffer)}};function xd(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 bd(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 _d(e){return{sequence:e,time:0}}function vd(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 Yn=class extends Error{constructor(t){super(t),this.name="WalParseError"}};function ks(e){if(e.byteLength<100)throw new Yn("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 Yn("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 Yn(`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 qn(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 Ps(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 za(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],L=y[u],w=c?255:a===32?y[u+3]:255;u+=h;for(let T=0;T<v;T++){let z=(b+T)*4;m[z]=S,m[z+1]=M,m[z+2]=L,m[z+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 ka(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 Ds(e){let t=Ps(e),r={level:0,width:e.width,height:e.height,rgba:t};return{width:e.width,height:e.height,levels:[r],source:"pcx"}}function Sd(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 Bs(e,t){return ka(ks(e),t)}var mr=class extends Error{constructor(t){super(t),this.name="WavParseError"}};function Pa(e,t,r){return new TextDecoder("ascii").decode(new Uint8Array(e.buffer,e.byteOffset+t,r))}function Os(e){if(e.byteLength<44)throw new mr("WAV buffer too small");let t=new DataView(e);if(Pa(t,0,4)!=="RIFF"||Pa(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=Pa(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 sm=(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 Da=(e,t=sm)=>{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(Da(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=Da(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 Md=yf(Ad(),1);var om=()=>globalThis.Worker||Md.default,en=class extends om(){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 Ns=(e,t)=>{Object.defineProperty(e,"name",{value:t})};var ne=Symbol,Ed=", ",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(Ed)))})(),ot="LFE",Ht="monophonic (mono)",Vt="stereo",jn="surround",oe=(e,...t)=>`${[Ht,Vt,`linear ${jn}`,"quadraphonic",`5.0 ${jn}`,`5.1 ${jn}`,`6.1 ${jn}`,`7.1 ${jn}`][e-1]} (${t.join(Ed)})`,Qn=[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)],Ld=192e3,Td=176400,Us=96e3,Hs=88200,Id=64e3,Gt=48e3,tn=44100,rn=32e3,nn=24e3,sn=22050,on=16e3,Vs=12e3,Gs=11025,an=8e3,Cd=7350,et="absoluteGranulePosition",H="bandwidth",be="bitDepth",_e="bitrate",Jn=_e+"Maximum",ei=_e+"Minimum",ti=_e+"Nominal",at="buffer",ri=at+"Fullness",te="codec",ve=te+"Frames",ni="coupledStreamCount",ln="crc",ii=ln+"16",si=ln+"32",J="data",D="description",lt="duration",cn="emphasis",oi="hasOpusPadding",ke="header",Wt="isContinuedPacket",ai="isCopyrighted",Xt="isFirstPage",li="isHome",Pe="isLastPage",xt="isOriginal",bt="isPrivate",ci="isVbr",Ce="layer",E="length",N="mode",_t=N+"Extension",Ws="mpeg",vt=Ws+"Version",di="numberAACFrames",ui="outputGain",pr="preSkip",fi="profile",Xs=ne(),St="protection",Ba="rawData",We="segments",V="subarray",Kt="version",gr="vorbis",hi=gr+"Comments",dn=gr+"Setup",Ks="block",mi=Ks+"ingStrategy",$s=ne(),wt=Ks+"Size",$t=Ks+"size0",Zt=Ks+"size1",pi=ne(),Zs="channel",At=Zs+"MappingFamily",gi=Zs+"MappingTable",Se=Zs+"Mode",yi=ne(),k=Zs+"s",Rd="copyright",xi=Rd+"Id",bi=Rd+"IdStart",Mt="frame",Et=Mt+"Count",Re=Mt+"Length",Ys="Number",Lt=Mt+Ys,ct=Mt+"Padding",O=Mt+"Size",Fd="Rate",_i="inputSample"+Fd,Oa="page",yr=Oa+"Checksum",un=ne(),Yt=Oa+"SegmentTable",de=Oa+"Sequence"+Ys,Na="sample",vi=Na+Ys,W=Na+Fd,dt=ne(),X=Na+"s",qs="stream",Si=qs+"Count",wi=qs+"Info",ut=qs+"Serial"+Ys,Ua=qs+"StructureVersion",Ha="total",xr=Ha+"BytesOut",br=Ha+"Duration",_r=Ha+"Samples",$=ne(),Xe=ne(),Ai=ne(),qt=ne(),tt=ne(),js=ne(),Va=ne(),jt=ne(),Y=ne(),Ke=ne(),$e=ne(),ft=ne(),Qt=ne(),Qs=ne(),rt=ne(),nt=ne(),Ze=ne(),Js=ne(),we=Uint8Array,Jt=DataView,q="reserved",Ae="bad",fn="free",Mi="none",eo="16bit CRC";var Ga=(e,t,r)=>{for(let n=0;n<e[E];n++){let i=t(n);for(let s=8;s>0;s--)i=r(i);e[n]=i}return e},lm=Ga(new we(256),e=>e,e=>e&128?7^e<<1:e<<1),ae=[Ga(new Uint16Array(256),e=>e<<8,e=>e<<1^(e&32768?32773:0))],le=[Ga(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 kd=e=>{let t=0,r=e[E];for(let n=0;n!==r;n++)t=lm[t^e[n]];return t},Pd=e=>{let t=e[E],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},Dd=e=>{let t=e[E],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},Li=(...e)=>{let t=new we(e.reduce((r,n)=>r+n[E],0));return e.reduce((r,n)=>(t.set(n,r),r+n[E]),0),t},De=e=>String.fromCharCode(...e),zd=[0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15],Ei=e=>zd[e&15]<<4|zd[e>>4],to=class{constructor(t){this._data=t,this._pos=t[E]*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,(Ei(this._data[r-1])<<8)+Ei(this._data[r])>>7-n&255}},Bd=(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 Ti=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}[Qs](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}[Ke](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}*[Va](){let t;do{if(t=yield*this.Frame[$e](this._codecParser,this._headerCache,0),t)return t;this._codecParser[Xe](1)}while(!0)}*[jt](t){let r=yield*this[Va](),n=ge.get(r)[E];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*[$e](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[$](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[Lt]=null,this[xr]=null,this[_r]=null,this[br]=null,ge.get(this)[E]=r[E]}};var Wa="unsynchronizationFlag",Xa="extendedHeaderFlag",Ka="experimentalFlag",$a="footerPresent",Ii=class e{static*getID3v2Header(t,r,n){let s={},o=yield*t[$](3,n);if(o[0]!==73||o[1]!==68||o[2]!==51||(o=yield*t[$](10,n),s[Kt]=`id3v2.${o[3]}.${o[4]}`,o[5]&15)||(s[Wa]=!!(o[5]&128),s[Xa]=!!(o[5]&64),s[Ka]=!!(o[5]&32),s[$a]=!!(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[E]=10+a,new e(s)}constructor(t){this[Kt]=t[Kt],this[Wa]=t[Wa],this[Xa]=t[Xa],this[Ka]=t[Ka],this[$a]=t[$a],this[E]=t[E]}};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 Vd={0:[fn,fn,fn,fn,fn],16:[32,32,32,32,8],240:[Ae,Ae,Ae,Ae,Ae]},ro=(e,t,r)=>8*((e+r)%t+t)*(1<<(e+r)/t)-8*t*(t/8|0);for(let e=2;e<15;e++)Vd[e<<4]=[e*32,ro(e,4,0),ro(e,4,-1),ro(e,8,4),ro(e,8,0)];var cm=0,dm=1,um=2,fm=3,Od=4,no="bands ",io=" to 31",Nd={0:no+4+io,16:no+8+io,32:no+12+io,48:no+16+io},Sr="bitrateIndex",Ci="v2",co="v1",so="Intensity stereo ",oo=", MS stereo ",ao="on",lo="off",hm={0:so+lo+oo+lo,16:so+ao+oo+lo,32:so+lo+oo+ao,48:so+ao+oo+ao},Za={0:{[D]:q},2:{[D]:"Layer III",[ct]:1,[_t]:hm,[co]:{[Sr]:um,[X]:1152},[Ci]:{[Sr]:Od,[X]:576}},4:{[D]:"Layer II",[ct]:1,[_t]:Nd,[X]:1152,[co]:{[Sr]:dm},[Ci]:{[Sr]:Od}},6:{[D]:"Layer I",[ct]:4,[_t]:Nd,[X]:384,[co]:{[Sr]:cm},[Ci]:{[Sr]:fm}}},Ya="MPEG Version ",Ud="ISO/IEC ",mm={0:{[D]:`${Ya}2.5 (later extension of MPEG 2)`,[Ce]:Ci,[W]:{0:Gs,4:Vs,8:an,12:q}},8:{[D]:q},16:{[D]:`${Ya}2 (${Ud}13818-3)`,[Ce]:Ci,[W]:{0:sn,4:nn,8:on,12:q}},24:{[D]:`${Ya}1 (${Ud}11172-3)`,[Ce]:co,[W]:{0:tn,4:Gt,8:rn,12:q}},length:E},pm={0:eo,1:Mi},gm={0:Mi,1:"50/15 ms",2:q,3:"CCIT J.17"},Hd={0:{[k]:2,[D]:Vt},64:{[k]:2,[D]:"joint "+Vt},128:{[k]:2,[D]:"dual channel"},192:{[k]:1,[D]:Ht}},wr=class e extends Oe{static*[Y](t,r,n){let i={},s=yield*Ii.getID3v2Header(t,r,n);s&&(yield*t[$](s[E],n),t[Xe](s[E]));let o=yield*t[$](4,n),a=De(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=mm[o[1]&24];if(l[D]===q)return null;let c=o[1]&6;if(Za[c][D]===q)return null;let h={...Za[c],...Za[c][l[Ce]]};if(i[vt]=l[D],i[Ce]=h[D],i[X]=h[X],i[St]=pm[o[1]&1],i[E]=4,i[_e]=Vd[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]=Hd[u][D],i[k]=Hd[u][k],i[_t]=h[_t][o[3]&48],i[ai]=!!(o[3]&8),i[xt]=!!(o[3]&4),i[cn]=gm[o[3]&3],i[cn]===q)return null;i[be]=16;{let{length:f,frameLength:m,samples:g,...p}=i;r[Ke](a,i,p)}return new e(i)}constructor(t){super(t),this[_e]=t[_e],this[cn]=t[cn],this[ct]=t[ct],this[ai]=t[ai],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 Ri=class e extends Be{static*[$e](t,r,n){return yield*super[$e](wr,e,t,r,n)}constructor(t,r,n){super(t,r,n)}};var Fi=class extends Me{constructor(t,r,n){super(t,r),this.Frame=Ri,this.Header=wr,n(this[te])}get[te](){return Ws}*[ft](){return yield*this[jt]()}};var ym={0:"MPEG-4",8:"MPEG-2"},xm={0:"valid",2:Ae,4:Ae,6:Ae},bm={0:eo,1:Mi},_m={0:"AAC Main",64:"AAC LC (Low Complexity)",128:"AAC SSR (Scalable Sample Rate)",192:"AAC LTP (Long Term Prediction)"},vm={0:Us,4:Hs,8:Id,12:Gt,16:tn,20:rn,24:nn,28:sn,32:on,36:Vs,40:Gs,44:an,48:Cd,52:q,56:q,60:"frequency is written explicitly"},Gd={0:{[k]:0,[D]:"Defined in AOT Specific Config"},64:{[k]:1,[D]:Ht},128:{[k]:2,[D]:oe(2,B[0][0])},192:{[k]:3,[D]:oe(3,B[1][3])},256:{[k]:4,[D]:oe(4,B[1][3],B[3][4])},320:{[k]:5,[D]:oe(5,B[1][3],B[3][0])},384:{[k]:6,[D]:oe(6,B[1][3],B[3][0],ot)},448:{[k]:8,[D]: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[$](7,n),o=De([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]=ym[s[1]&8],i[Ce]=xm[s[1]&6],i[Ce]===Ae))return null;let l=s[1]&1;i[St]=bm[l],i[E]=l?7:9,i[Xs]=s[2]&192,i[dt]=s[2]&60;let c=s[2]&2;if(i[fi]=_m[i[Xs]],i[W]=vm[i[dt]],i[W]===q)return null;i[bt]=!!c,i[yi]=(s[2]<<8|s[3])&448,i[Se]=Gd[i[yi]][D],i[k]=Gd[i[yi]][k],i[xt]=!!(s[3]&32),i[li]=!!(s[3]&8),i[xi]=!!(s[3]&8),i[bi]=!!(s[3]&4),i[be]=16,i[X]=1024,i[di]=s[6]&3;{let{length:h,channelModeBits:u,profileBits:f,sampleRateBits:m,frameLength:g,samples:p,numberAACFrames:y,..._}=i;r[Ke](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[ri]=d===2047?"VBR":d,new e(i)}constructor(t){super(t),this[xi]=t[xi],this[bi]=t[bi],this[ri]=t[ri],this[li]=t[li],this[xt]=t[xt],this[bt]=t[bt],this[Ce]=t[Ce],this[E]=t[E],this[vt]=t[vt],this[di]=t[di],this[fi]=t[fi],this[St]=t[St]}get audioSpecificConfig(){let t=ue.get(this),r=t[Xs]+64<<5|t[dt]<<5|t[yi]>>3,n=new we(2);return new Jt(n[at]).setUint16(0,r,!1),n}};var zi=class e extends Be{static*[$e](t,r,n){return yield*super[$e](Ar,e,t,r,n)}constructor(t,r,n){super(t,r,n)}};var ki=class extends Me{constructor(t,r,n){super(t,r),this.Frame=zi,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[E]-2]<<8)+t[t[E]-1]}static[Js](t){let r=e._getFrameFooterCrc16(t),n=Pd(t[V](0,-2));return r===n}constructor(t,r,n){r[wi]=n,r[ii]=e._getFrameFooterCrc16(t),super(r,t,ue.get(r)[X])}};var Wd="get from STREAMINFO metadata block",Sm={0:"Fixed",1:"Variable"},Xd={0:q,16:192};for(let e=2;e<16;e++)Xd[e<<4]=e<6?576*2**(e-2):2**e;var wm={0:Wd,1:Hs,2:Td,3:Ld,4:an,5:on,6:sn,7:nn,8:rn,9:tn,10:Gt,11:Us,15:Ae},Am={0:{[k]:1,[D]:Ht},16:{[k]:2,[D]:oe(2,B[0][0])},32:{[k]:3,[D]:oe(3,B[0][1])},48:{[k]:4,[D]:oe(4,B[1][0],B[3][0])},64:{[k]:5,[D]:oe(5,B[1][1],B[3][0])},80:{[k]:6,[D]:oe(6,B[1][1],ot,B[3][0])},96:{[k]:7,[D]:oe(7,B[1][1],ot,B[3][4],B[2][0])},112:{[k]:8,[D]:oe(8,B[1][1],ot,B[3][0],B[2][0])},128:{[k]:2,[D]:`${Vt} (left, diff)`},144:{[k]:2,[D]:`${Vt} (diff, right)`},160:{[k]:2,[D]:`${Vt} (avg, diff)`},176:q,192:q,208:q,224:q,240:q},Mm={0:Wd,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={[$]:function*(){return t}};return e[Y](n,r,0).next().value}static*[Y](t,r,n){let i=yield*t[$](6,n);if(i[0]!==255||!(i[1]===248||i[1]===249))return null;let s={},o=De(i[V](0,4)),a=r[Y](o);if(a)Object.assign(s,a);else{if(s[$s]=i[1]&1,s[mi]=Sm[s[$s]],s[pi]=i[2]&240,s[dt]=i[2]&15,s[wt]=Xd[s[pi]],s[wt]===q||(s[W]=wm[s[dt]],s[W]===Ae)||i[3]&1)return null;let l=Am[i[3]&240];if(l===q||(s[k]=l[k],s[Se]=l[D],s[be]=Mm[i[3]&14],s[be]===q))return null}s[E]=5,i=yield*t[$](s[E]+8,n);let d=e._decodeUTF8Int(i[V](4));if(!d||(s[$s]?s[vi]=d.value:s[Lt]=d.value,s[E]+=d[E],s[pi]===96?(i[E]<s[E]&&(i=yield*t[$](s[E],n)),s[wt]=i[s[E]-1]+1,s[E]+=1):s[pi]===112&&(i[E]<s[E]&&(i=yield*t[$](s[E],n)),s[wt]=(i[s[E]-1]<<8)+i[s[E]]+1,s[E]+=2),s[X]=s[wt],s[dt]===12?(i[E]<s[E]&&(i=yield*t[$](s[E],n)),s[W]=i[s[E]-1]*1e3,s[E]+=1):s[dt]===13?(i[E]<s[E]&&(i=yield*t[$](s[E],n)),s[W]=(i[s[E]-1]<<8)+i[s[E]],s[E]+=2):s[dt]===14&&(i[E]<s[E]&&(i=yield*t[$](s[E],n)),s[W]=((i[s[E]-1]<<8)+i[s[E]])*10,s[E]+=2),i[E]<s[E]&&(i=yield*t[$](s[E],n)),s[ln]=i[s[E]-1],s[ln]!==kd(i[V](0,s[E]-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[Ke](o,s,y)}return new e(s)}constructor(t){super(t),this[ii]=null,this[mi]=t[mi],this[wt]=t[wt],this[Lt]=t[Lt],this[vi]=t[vi],this[wi]=null}};var Em=2,Lm=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[$](2,0),n=r[E]-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)[E]+Em;for(;r<=Lm;){if(this._codecParser._flushing||(yield*tr[Y](this._codecParser,this._headerCache,r))){let n=yield*this._codecParser[$](r);if(this._codecParser._flushing||(n=n[V](0,r)),er[Js](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 Er=class e{static*[Y](t,r,n){let i={},s=yield*t[$](28,n);if(s[0]!==79||s[1]!==103||s[2]!==103||s[3]!==83||(i[Ua]=s[4],s[5]&248))return null;i[Pe]=!!(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]=Bd(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[E]=d+27,s=yield*t[$](i[E],n),i[Re]=0,i[Yt]=[],i[un]=we.from(s[V](27,i[E]));for(let l=0,c=0;l<d;l++){let h=i[un][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[Pe]=t[Pe],this[Yt]=t[Yt],this[de]=t[de],this[yr]=t[yr],this[ut]=t[ut]}};var Pi=class e extends vr{static*[$e](t,r,n){let i=yield*Er[Y](t,r,n);if(i){let s=ue.get(i)[Re],o=ue.get(i)[E],a=o+s,d=(yield*t[$](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)[E]=n[E],this[ve]=[],this[Ba]=n,this[et]=t[et],this[si]=t[yr],this[lt]=0,this[Wt]=t[Wt],this[Xt]=t[Xt],this[Pe]=t[Pe],this[de]=t[de],this[X]=0,this[ut]=t[ut]}};var hn=class extends Be{constructor(t,r,n){super(r,t,n)}};var Kd={0:Qn.slice(0,2),1:Qn},Ye="SILK-only",ye="CELT-only",uo="Hybrid",rr="narrowband",fo="medium-band",nr="wideband",mn="super-wideband",pn="fullband",Tm={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]:fo,[O]:10},40:{[N]:Ye,[H]:fo,[O]:20},48:{[N]:Ye,[H]:fo,[O]:40},56:{[N]:Ye,[H]:fo,[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]:uo,[H]:mn,[O]:10},104:{[N]:uo,[H]:mn,[O]:20},112:{[N]:uo,[H]:pn,[O]:10},120:{[N]:uo,[H]:pn,[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]:mn,[O]:2.5},200:{[N]:ye,[H]:mn,[O]:5},208:{[N]:ye,[H]:mn,[O]:10},216:{[N]:ye,[H]:mn,[O]:20},224:{[N]:ye,[H]:pn,[O]:2.5},232:{[N]:ye,[H]:pn,[O]:5},240:{[N]:ye,[H]:pn,[O]:10},248:{[N]:ye,[H]:pn,[O]:20}},gn=class e extends Oe{static[Ze](t,r,n){let i={};if(i[k]=t[9],i[At]=t[18],i[E]=i[At]!==0?21+i[k]:19,t[E]<i[E])throw new Error("Out of data while inside an Ogg Page");let s=r[0]&3,o=s===3?2:1,a=De(t[V](0,i[E]))+De(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[E]));let l=new Jt(i[J][at]);if(i[be]=16,i[pr]=l.getUint16(10,!0),i[_i]=l.getUint32(12,!0),i[W]=Gt,i[ui]=l.getInt16(16,!0),i[At]in Kd&&(i[Se]=Kd[i[At]][i[k]-1],!i[Se]))return null;i[At]!==0&&(i[Si]=t[19],i[ni]=t[20],i[gi]=[...t[V](21,i[k]+21)]);let c=Tm[248&r[0]];switch(i[N]=c[N],i[H]=c[H],i[O]=c[O],s){case 0:i[Et]=1;break;case 1:case 2:i[Et]=2;break;case 3:i[ci]=!!(128&r[1]),i[oi]=!!(64&r[1]),i[Et]=63&r[1];break;default:return null}{let{length:h,data:u,channelMappingFamily:f,...m}=i;n[Ke](a,i,m)}return new e(i)}constructor(t){super(t),this[J]=t[J],this[H]=t[H],this[At]=t[At],this[gi]=t[gi],this[ni]=t[ni],this[Et]=t[Et],this[O]=t[O],this[oi]=t[oi],this[_i]=t[_i],this[ci]=t[ci],this[N]=t[N],this[ui]=t[ui],this[pr]=t[pr],this[Si]=t[Si]}};var Di=class extends Me{constructor(t,r,n){super(t,r),this.Frame=hn,this.Header=gn,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=gn[Ze](this._identificationHeader,r,this._headerCache);if(n){this._preSkipRemaining===null&&(this._preSkipRemaining=n[pr]);let i=n[O]*n[Et]/1e3*n[W];return this._preSkipRemaining>0&&(this._preSkipRemaining-=i,i=this._preSkipRemaining<0?-this._preSkipRemaining:0),new hn(r,n,i)}this._codecParser[js]("Failed to parse Ogg Opus Header","Not a valid Ogg Opus file")})),t}};var yn=class extends Be{constructor(t,r,n){super(r,t,n)}};var qa={};for(let e=0;e<8;e++)qa[e+6]=2**(6+e);var Bi=class e extends Oe{static[Ze](t,r,n,i){if(t[E]<30)throw new Error("Out of data while inside an Ogg Page");let s=De(t[V](0,30)),o=r[Y](s);if(o)return new e(o);let a={[E]: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[Kt]=d.getUint32(7,!0),a[Kt]!==0||(a[k]=t[11],a[Se]=Qn[a[k]-1]||"application defined",a[W]=d.getUint32(12,!0),a[Jn]=d.getInt32(16,!0),a[ti]=d.getInt32(20,!0),a[ei]=d.getInt32(24,!0),a[Zt]=qa[(t[28]&240)>>4],a[$t]=qa[t[28]&15],a[$t]>a[Zt])||t[29]!==1)return null;a[be]=32,a[dn]=i,a[hi]=n;{let{length:l,data:c,version:h,vorbisSetup:u,vorbisComments:f,...m}=a;r[Ke](s,a,m)}return new e(a)}constructor(t){super(t),this[Jn]=t[Jn],this[ei]=t[ei],this[ti]=t[ti],this[$t]=t[$t],this[Zt]=t[Zt],this[J]=t[J],this[hi]=t[hi],this[dn]=t[dn]}};var Oi=class extends Me{constructor(t,r,n){super(t,r),this.Frame=yn,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=Bi[Ze](this._identificationHeader,this._headerCache,this._vorbisComments,this._vorbisSetup);n?t[ve].push(new yn(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[$t],s=this._prevBlockSize===null?0:(this._prevBlockSize+i)/4;return this._prevBlockSize=i,s}_parseSetupHeader(t){let r=new to(t),n={count:0,blockFlags:[]};for(;(r.read(1)&1)!==1;);let i;for(;n.count<64&&r.position>0;){Ei(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{((Ei(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 ja=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=De(t[V](0,8));switch(r){case"fishead\0":return!1;case"OpusHead":return this._updateCodec("opus",Di),!0;case(/^\x7fFLAC/.test(r)&&r):return this._updateCodec("flac",Mr),!0;case(/^\x01vorbis/.test(r)&&r):return this._updateCodec(gr,Oi),!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[E]&&(r[We][0]=Li(this._continuedPacket,r[We][0]),this._continuedPacket=new we),n[un][n[un][E]-1]===255&&(this._continuedPacket=Li(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}},Ni=class extends Me{constructor(t,r,n){super(t,r),this._onCodec=n,this.Frame=Pi,this.Header=Er,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 ja(this._codecParser,this._headerCache,this._onCodec),this._streams.set(this._currentSerialNumber,r)),t[Pe]&&this._streams.delete(this._currentSerialNumber),r._parsePage(t)}};var Qa=()=>{},Ui=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?Dd:Qa,this[rt]()}get[te](){return this._parser?this._parser[te]:""}[rt](){this._headerCache=new Ti(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 ki(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/mpeg/))this._parser=new Fi(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 Ni(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)}}*[$](t=0,r=0){let n;for(;this._rawData[E]<=t+r;){if(n=yield,this._flushing)return this._rawData[V](r);n&&(this._totalBytesIn+=n[E],this._rawData=Li(this._rawData,n))}return this._rawData[V](r)}[Xe](t){this._currentReadPosition+=t,this._rawData=this._rawData[V](t)}[Ai](t){this._sampleRate=t[ke][W],t[ke][_e]=t[lt]>0?Math.round(t[J][E]/t[lt])*8:0,t[Lt]=this._frameNumber++,t[xr]=this._totalBytesOut,t[_r]=this._totalSamples,t[br]=this._totalSamples/this._sampleRate*1e3,t[si]=this._crc32(t[J]),this._headerCache[Qs](t[ke][_e],t[br]),this._totalBytesOut+=t[J][E],this._totalSamples+=t[X]}[qt](t){if(t[ve]){if(t[Pe]){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[Ai](n)})}else t[X]=0,t[ve].forEach(r=>{t[X]+=r[X],this[Ai](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[Ai](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[E]));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)}[js](...t){this._log(console.error,t)}};var $d=Ui;var ho=ve;var mo=J;var Zd=ke;var Yd=Pe;var qd=dn;var jd=_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,Bn,Or=0,xs=0,bs=R.length,_s=new Uint8Array((bs*3>>2)-(R[bs-2]=="=")-(R[bs-1]=="="));Or<bs;Or+=4,xs+=3)He=Z[R.charCodeAt(Or+1)],Bn=Z[R.charCodeAt(Or+2)],_s[xs]=Z[R.charCodeAt(Or)]<<2|He>>4,_s[xs+1]=He<<4|Bn>>2,_s[xs+2]=Bn<<6|Z[R.charCodeAt(Or+3)];return _s},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 Bn=setTimeout(()=>{delete b[R],x(()=>Hc(R,v()))},He);return b[R]={id:Bn,timeout_ms:He},0},S=Math.atan,M=Math.cos,L=Math.exp,w=Math.log,T=Math.pow,z=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:L,h:w,g:T,c:z,k:U,j:C};function ys(R){Dn=R.n,Pc=R.o,Dc=R.p,Bc=R.q,Oc=R.r,Nc=R.s,Uc=R.t,Hc=R.v}var Dn,Pc,Dc,Bc,Oc,Nc,Uc,Hc;function cf(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¹‡=