quake2ts 0.0.593 → 0.0.596
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/packages/client/dist/browser/index.global.js.map +1 -1
- package/packages/client/dist/cjs/index.cjs.map +1 -1
- package/packages/client/dist/esm/index.js.map +1 -1
- package/packages/client/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/engine/dist/browser/index.global.js +3 -3
- package/packages/engine/dist/browser/index.global.js.map +1 -1
- package/packages/engine/dist/cjs/index.cjs +116 -125
- package/packages/engine/dist/cjs/index.cjs.map +1 -1
- package/packages/engine/dist/esm/index.js +116 -125
- package/packages/engine/dist/esm/index.js.map +1 -1
- package/packages/engine/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/engine/dist/types/index.d.ts +3 -4
- package/packages/engine/dist/types/index.d.ts.map +1 -1
- package/packages/engine/dist/types/render/interface.d.ts +20 -28
- package/packages/engine/dist/types/render/interface.d.ts.map +1 -1
- package/packages/engine/dist/types/render/renderer.d.ts.map +1 -1
- package/packages/engine/dist/types/render/webgpu/context.d.ts +11 -5
- package/packages/engine/dist/types/render/webgpu/context.d.ts.map +1 -1
- package/packages/engine/dist/types/render/webgpu/headless.d.ts.map +1 -1
- package/packages/game/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/test-utils/dist/index.cjs +108 -88
- package/packages/test-utils/dist/index.cjs.map +1 -1
- package/packages/test-utils/dist/index.d.cts +23 -57
- package/packages/test-utils/dist/index.d.ts +23 -57
- package/packages/test-utils/dist/index.js +93 -78
- package/packages/test-utils/dist/index.js.map +1 -1
- package/packages/tools/dist/browser/index.global.js.map +1 -1
- package/packages/tools/dist/tsconfig.tsbuildinfo +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Quake2Engine=(()=>{var Gh=Object.create;var ta=Object.defineProperty;var Vh=Object.getOwnPropertyDescriptor;var Wh=Object.getOwnPropertyNames;var Xh=Object.getPrototypeOf,Kh=Object.prototype.hasOwnProperty;var $h=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),$o=(t,e)=>{for(var r in e)ta(t,r,{get:e[r],enumerable:!0})},nd=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Wh(e))!Kh.call(t,i)&&i!==r&&ta(t,i,{get:()=>e[i],enumerable:!(n=Vh(e,i))||n.enumerable});return t};var Zh=(t,e,r)=>(r=t!=null?Gh(Xh(t)):{},nd(e||!t||!t.__esModule?ta(r,"default",{value:t,enumerable:!0}):r,t)),Yh=t=>nd(ta({},"__esModule",{value:!0}),t);var Hd=$h((J_,Ud)=>{"use strict";Ud.exports=Worker});var ex={};$o(ex,{ATTN_IDLE:()=>ol,ATTN_LOOP_NONE:()=>sl,ATTN_NONE:()=>wi,ATTN_NORM:()=>al,ATTN_STATIC:()=>ll,AssetDependencyError:()=>on,AssetDependencyTracker:()=>As,AssetManager:()=>Ja,AssetPreviewGenerator:()=>Xo,AudioApi:()=>Tn,AudioContextController:()=>eo,AudioOcclusion:()=>Es,AudioRegistry:()=>Qn,AudioRegistryError:()=>vs,AudioSystem:()=>oo,BSP_SURFACE_FRAGMENT_SOURCE:()=>Zl,BSP_SURFACE_VERTEX_SOURCE:()=>$l,BSP_VERTEX_LAYOUT:()=>Wl,BspLoader:()=>In,BspParseError:()=>Q,BspSurfacePipeline:()=>ho,Camera:()=>bo,Command:()=>bi,CommandRegistry:()=>xn,ConfigStringRegistry:()=>Ln,Cvar:()=>Si,CvarRegistry:()=>Mn,DemoAnalyzer:()=>pi,DemoCameraMode:()=>Kc,DemoClipper:()=>Wo,DemoEventType:()=>Xc,DemoPlaybackController:()=>Gt,DemoReader:()=>je,DemoRecorder:()=>Ys,DemoValidator:()=>Ho,DynamicLightManager:()=>fo,EngineHost:()=>En,EngineRuntime:()=>Ai,FileType:()=>$c,FixedTimestepLoop:()=>Hr,Framebuffer:()=>co,IndexBuffer:()=>_e,LruCache:()=>Kt,MAX_SOUND_CHANNELS:()=>vi,MD2_FRAGMENT_SHADER:()=>tc,MD2_VERTEX_SHADER:()=>ec,MD3_FRAGMENT_SHADER:()=>dc,MD3_VERTEX_SHADER:()=>cc,MapAnalyzer:()=>Ko,Md2Loader:()=>kn,Md2MeshBuffers:()=>po,Md2ParseError:()=>ye,Md2Pipeline:()=>go,Md3Loader:()=>Rn,Md3ModelMesh:()=>xo,Md3ParseError:()=>Ve,Md3Pipeline:()=>_o,Md3SurfaceMesh:()=>Ts,MessageWriter:()=>yn,MusicSystem:()=>lo,NetworkMessageParser:()=>it,PARTICLE_FRAGMENT_SHADER:()=>fc,PARTICLE_VERTEX_SHADER:()=>uc,PROTOCOL_VERSION_RERELEASE:()=>mi,PakArchive:()=>Cn,PakIndexStore:()=>Qa,PakIngestionError:()=>Xt,PakParseError:()=>fe,PakValidationError:()=>Wr,PakValidator:()=>fa,PakWriter:()=>ca,ParticleRenderer:()=>wo,ParticleSystem:()=>vo,PlaybackState:()=>Uo,RERELEASE_KNOWN_PAKS:()=>hl,ResourceLoadTracker:()=>da,ResourceType:()=>fl,SKYBOX_FRAGMENT_SHADER:()=>Ql,SKYBOX_VERTEX_SHADER:()=>jl,SOUND_FULLVOLUME:()=>Sn,SOUND_LOOP_ATTENUATE:()=>cl,ShaderProgram:()=>Te,SkyboxPipeline:()=>mo,SoundChannel:()=>at,SoundPrecache:()=>no,SoundRegistry:()=>ro,SpriteLoader:()=>Pn,SpriteParseError:()=>$t,StreamingPakArchive:()=>la,Texture2D:()=>Jn,TextureCache:()=>Fn,TextureCubeMap:()=>ei,TgaParseError:()=>Mt,U_ALPHA:()=>Er,U_ANGLE1:()=>Ar,U_ANGLE2:()=>xr,U_ANGLE3:()=>_r,U_EFFECTS16:()=>wt,U_EFFECTS8:()=>xt,U_EVENT:()=>wr,U_FRAME16:()=>Lr,U_FRAME8:()=>vr,U_INSTANCE_BITS:()=>Br,U_LOOP_ATTENUATION_HIGH:()=>Or,U_LOOP_VOLUME:()=>Dr,U_MODEL:()=>Mr,U_MODEL2:()=>Tr,U_MODEL3:()=>Cr,U_MODEL4:()=>Ir,U_OLDORIGIN:()=>kr,U_OLD_FRAME_HIGH:()=>Nr,U_ORIGIN1:()=>yr,U_ORIGIN2:()=>br,U_ORIGIN3:()=>Sr,U_OWNER_HIGH:()=>zr,U_REMOVE:()=>Zs,U_RENDERFX16:()=>vt,U_RENDERFX8:()=>bt,U_SCALE:()=>Fr,U_SKIN16:()=>St,U_SKIN8:()=>_t,U_SOLID:()=>Pr,U_SOUND:()=>Rr,VertexArray:()=>Pe,VertexBuffer:()=>Ce,VirtualFileSystem:()=>ua,advanceAnimation:()=>Bd,applyEntityDelta:()=>Vo,applySurfaceState:()=>Cu,attenuationToDistanceMultiplier:()=>An,boxIntersectsFrustum:()=>Ls,buildBspGeometry:()=>wu,buildMd2Geometry:()=>rc,buildMd2VertexData:()=>nc,buildMd3SurfaceGeometry:()=>oc,buildMd3VertexData:()=>lc,calculateMaxAudibleDistance:()=>Vr,calculatePakChecksum:()=>_d,captureRenderTarget:()=>Nh,computeFrameBlend:()=>Dd,computeSkyScroll:()=>Ru,createAnimationState:()=>Od,createAudioGraph:()=>to,createBspSurfaces:()=>vu,createEmptyEntityState:()=>Ht,createEmptyProtocolPlayerState:()=>gn,createEngine:()=>Jb,createEngineRuntime:()=>bd,createFaceLightmap:()=>ma,createHeadlessRenderTarget:()=>zh,createInitialChannels:()=>io,createOcclusionResolver:()=>yu,createProgramFromSources:()=>_u,createWebGLContext:()=>bu,createWebGPUContext:()=>Dh,decodeOgg:()=>ja,deriveSurfaceRenderState:()=>ql,detectFileType:()=>Zc,extractFrustumPlanes:()=>Su,filesToPakSources:()=>ml,findLeafForPoint:()=>Kl,gatherVisibleFaces:()=>Lu,groupMd2Animations:()=>kd,ingestPakFiles:()=>Ad,ingestPaks:()=>ha,interpolateMd3Tag:()=>qu,interpolateVec3:()=>zd,isBinaryFile:()=>kh,isTextFile:()=>Yc,parseBsp:()=>Mi,parseEntLump:()=>Ph,parseMd2:()=>pl,parseMd3:()=>gl,parsePcx:()=>Ci,parseSprite:()=>yl,parseTga:()=>bl,parseWal:()=>ga,parseWalTexture:()=>xa,parseWav:()=>_a,pcxToRgba:()=>ya,pickChannel:()=>so,preparePcxTexture:()=>ba,queryCapabilities:()=>Oh,removeViewTranslation:()=>ku,resolveLightStyles:()=>Yl,serializeEntLump:()=>Fh,spawnBfgExplosion:()=>cf,spawnBlasterImpact:()=>lf,spawnBlood:()=>Ju,spawnBulletImpact:()=>ju,spawnExplosion:()=>Qu,spawnMuzzleFlash:()=>tf,spawnRailTrail:()=>af,spawnSparks:()=>of,spawnSplash:()=>nf,spawnSteam:()=>sf,spawnTeleportFlash:()=>ef,spawnTrail:()=>rf,validateEntity:()=>Bh,walToRgba:()=>xl,wireDropTarget:()=>Md,wireFileInput:()=>Ed});var qh=()=>typeof performance<"u"?performance.now():Date.now(),jh=t=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>t()):setTimeout(t,25)},Hr=class{constructor(e,r={}){this.callbacks=e;this.accumulatorMs=0;this.frame=0;this.running=!1;this.tick=()=>{if(!this.running)return;let e=this.options.now(),r=this.lastTimeMs===void 0?0:e-this.lastTimeMs;this.lastTimeMs=e,this.advance(r,e),this.running&&this.options.schedule(this.tick)};let n=r.fixedDeltaMs??25,i=r.maxSubSteps??5;this.options={fixedDeltaMs:n,maxSubSteps:i,maxDeltaMs:r.maxDeltaMs??n*i,startTimeMs:r.startTimeMs,now:r.now??qh,schedule:r.schedule??jh}}start(){this.running||(this.running=!0,this.lastTimeMs=this.options.startTimeMs??this.options.now(),this.options.schedule(this.tick))}stop(){this.running=!1}pump(e){let r=(this.lastTimeMs??0)+e;this.lastTimeMs=r,this.advance(e,r)}isRunning(){return this.running}get frameNumber(){return this.frame}advance(e,r){let n=Math.min(Math.max(e,0),this.options.maxDeltaMs);this.accumulatorMs=Math.min(this.accumulatorMs+n,this.options.fixedDeltaMs*this.options.maxSubSteps);let i=0;for(;this.accumulatorMs>=this.options.fixedDeltaMs&&i<this.options.maxSubSteps;)this.frame+=1,this.callbacks.simulate({frame:this.frame,deltaMs:this.options.fixedDeltaMs,nowMs:r}),this.accumulatorMs-=this.options.fixedDeltaMs,i+=1;let 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 bi=class{constructor(e,r,n){this.name=e,this.callback=r,this.description=n}execute(e){this.callback(e)}},xn=class{constructor(){this.commands=new Map;this.history=[];this.historyLimit=64;this.autocompleteProviders=[]}register(e,r,n){let i=new bi(e,r,n);return this.commands.set(e,i),i}registerCommand(e,r){this.register(e,r)}registerAutocompleteProvider(e){this.autocompleteProviders.push(e)}get(e){return this.commands.get(e)}execute(e){let r=e.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(e);if(n.length===0)return!1;let i=n[0],s=n.slice(1),a=this.get(i);return a?(a.execute(s),!0):(this.onConsoleOutput?.(`Unknown command "${i}"`),!1)}executeCommand(e){this.execute(e)}getHistory(){return[...this.history]}getSuggestions(e){let r=new Set;for(let n of this.commands.keys())n.startsWith(e)&&r.add(n);for(let n of this.autocompleteProviders){let i=n();for(let s of i)s.startsWith(e)&&r.add(s)}return Array.from(r).sort()}tokenize(e){let r=[],n="",i=!1;for(let s=0;s<e.length;s++){let a=e[s];a==='"'?i=!i:a===" "&&!i?n.length>0&&(r.push(n),n=""):n+=a}return n.length>0&&r.push(n),r}list(){return[...this.commands.values()].sort((e,r)=>e.name.localeCompare(r.name))}};var Qh=Object.defineProperty,Jh=(t,e)=>{for(var r in e)Qh(t,r,{get:e[r],enumerable:!0})},id={x:0,y:0,z:0};var ix=Math.PI/180;function sd(t,e){return{x:t.x-e.x,y:t.y-e.y,z:t.z-e.z}}function e0(t,e){return{x:t.x*e,y:t.y*e,z:t.z*e}}function t0(t,e){return t.x*e.x+t.y*e.y+t.z*e.z}function r0(t){return t0(t,t)}function Yo(t){return Math.sqrt(r0(t))}function At(t){let e=Yo(t);return e===0?t:e0(t,1/e)}var n0=Math.PI/180,i0=180/Math.PI,vn=n0,qo=i0;var Vt=[[-.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 s0(){return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function ad(t,e){let r=e.x,n=e.y,i=e.z;return{x:t[0]*r+t[4]*n+t[8]*i+t[12],y:t[1]*r+t[5]*n+t[9]*i+t[13],z:t[2]*r+t[6]*n+t[10]*i+t[14]}}function od(t,e){let r=s0();return r[0]=e[0].x,r[1]=e[0].y,r[2]=e[0].z,r[4]=e[1].x,r[5]=e[1].y,r[6]=e[1].z,r[8]=e[2].x,r[9]=e[2].y,r[10]=e[2].z,r[12]=t.x,r[13]=t.y,r[14]=t.z,r}var st=1,Wt=2;var jo=8,Qo=16,a0=32;var o0=16384;var ra=65536,ld=1<<17,l0=1<<18,c0=1<<19,d0=1<<20,u0=1<<21,f0=1<<22,h0=1<<23,sx=1<<24,na=1<<25,m0=1<<26,ax=1<<27,ox=1<<28,lx=1<<29,ia=1<<30,cx=1<<31;var _i=0;var cd=4,dd=8,ud=16,fd=32,hd=64;var dx=1<<25,ux=1<<28,fx=1<<29,hx=1<<30,mx=1<<31;var px=st|Wt,gx=st|ra|Wt|na|ia,yx=st|ra|Wt,bx=st|ld|Wt|na|ia,xx=a0|jo|Qo,_x=st|Qo|jo,p0=st|na|ia|Wt|m0,vx=l0|c0|d0|u0|f0|h0,wx=st|jo|Qo|na|ia,Sx=st|ra|Wt,Ax=st|Wt,Mx=st|ra|Wt|ld,Ex=p0|o0;var Lx=Number.MAX_SAFE_INTEGER-1;var sa=(t=>(t[t.None=0]="None",t[t.Archive=1]="Archive",t[t.UserInfo=2]="UserInfo",t[t.ServerInfo=4]="ServerInfo",t[t.Latch=8]="Latch",t[t.Cheat=16]="Cheat",t))(sa||{});var aa=256;var Jo=256,el=8192,oa=2048,tl=512,rl=256,nl=aa*2,il=256,Zo=32,xi=96;var X=(t=>(t[t.Name=0]="Name",t[t.CdTrack=1]="CdTrack",t[t.Sky=2]="Sky",t[t.SkyAxis=3]="SkyAxis",t[t.SkyRotate=4]="SkyRotate",t[t.StatusBar=5]="StatusBar",t[t.HealthBarName=55]="HealthBarName",t[t.CONFIG_N64_PHYSICS=56]="CONFIG_N64_PHYSICS",t[t.CONFIG_CTF_TEAMS=57]="CONFIG_CTF_TEAMS",t[t.CONFIG_COOP_RESPAWN_STRING=58]="CONFIG_COOP_RESPAWN_STRING",t[t.Story=54]="Story",t[t.AirAccel=59]="AirAccel",t[t.MaxClients=60]="MaxClients",t[t.MapChecksum=61]="MapChecksum",t[t.Models=62]="Models",t[t.Sounds=62+el]="Sounds",t[t.Images=t.Sounds+oa]="Images",t[t.Lights=t.Images+tl]="Lights",t[t.ShadowLights=t.Lights+Jo]="ShadowLights",t[t.Items=t.ShadowLights+il]="Items",t[t.Players=t.Items+rl]="Players",t[t.PlayerSkins=t.Players]="PlayerSkins",t[t.General=t.Players+aa]="General",t[t.WheelWeapons=t.General+nl]="WheelWeapons",t[t.WheelAmmo=t.WheelWeapons+Zo]="WheelAmmo",t[t.WheelPowerups=t.WheelAmmo+Zo]="WheelPowerups",t[t.CdLoopCount=t.WheelPowerups+Zo]="CdLoopCount",t[t.GameStyle=t.CdLoopCount+1]="GameStyle",t[t.MaxConfigStrings=t.GameStyle+1]="MaxConfigStrings",t))(X||{}),md=X.MaxConfigStrings;function pd(t){return t>=5&&t<59?xi*(59-t):t>=X.General&&t<X.WheelWeapons?xi*(X.MaxConfigStrings-t):xi}var Tx=X.Sounds,Cx=X.Images,Ix=X.Lights,kx=X.Items,Rx=X.Players,Px=X.General,g0={};Jh(g0,{addReplayFrame:()=>_0,createReplaySession:()=>x0,deserializeReplay:()=>b0,serializeReplay:()=>y0});function y0(t){return JSON.stringify(t,null,2)}function b0(t){let e=JSON.parse(t);if(!e.metadata||!Array.isArray(e.frames))throw new Error("Invalid replay format: missing metadata or frames");return e}function x0(t,e){return{metadata:{map:t,date:new Date().toISOString(),version:"1.0",seed:e},frames:[]}}function _0(t,e,r,n){t.frames.push({serverFrame:r,cmd:e,timestamp:Date.now()-n})}var M=(t=>(t[t.bad=0]="bad",t[t.muzzleflash=1]="muzzleflash",t[t.muzzleflash2=2]="muzzleflash2",t[t.temp_entity=3]="temp_entity",t[t.layout=4]="layout",t[t.inventory=5]="inventory",t[t.nop=6]="nop",t[t.disconnect=7]="disconnect",t[t.reconnect=8]="reconnect",t[t.sound=9]="sound",t[t.print=10]="print",t[t.stufftext=11]="stufftext",t[t.serverdata=12]="serverdata",t[t.configstring=13]="configstring",t[t.spawnbaseline=14]="spawnbaseline",t[t.centerprint=15]="centerprint",t[t.download=16]="download",t[t.playerinfo=17]="playerinfo",t[t.packetentities=18]="packetentities",t[t.deltapacketentities=19]="deltapacketentities",t[t.frame=20]="frame",t[t.splitclient=21]="splitclient",t[t.configblast=22]="configblast",t[t.spawnbaselineblast=23]="spawnbaselineblast",t[t.level_restart=24]="level_restart",t[t.damage=25]="damage",t[t.locprint=26]="locprint",t[t.fog=27]="fog",t[t.waitingforplayers=28]="waitingforplayers",t[t.bot_chat=29]="bot_chat",t[t.poi=30]="poi",t[t.help_path=31]="help_path",t[t.muzzleflash3=32]="muzzleflash3",t[t.achievement=33]="achievement",t))(M||{});var E=(t=>(t[t.GUNSHOT=0]="GUNSHOT",t[t.BLOOD=1]="BLOOD",t[t.BLASTER=2]="BLASTER",t[t.RAILTRAIL=3]="RAILTRAIL",t[t.SHOTGUN=4]="SHOTGUN",t[t.EXPLOSION1=5]="EXPLOSION1",t[t.EXPLOSION2=6]="EXPLOSION2",t[t.ROCKET_EXPLOSION=7]="ROCKET_EXPLOSION",t[t.GRENADE_EXPLOSION=8]="GRENADE_EXPLOSION",t[t.SPARKS=9]="SPARKS",t[t.SPLASH=10]="SPLASH",t[t.BUBBLETRAIL=11]="BUBBLETRAIL",t[t.SCREEN_SPARKS=12]="SCREEN_SPARKS",t[t.SHIELD_SPARKS=13]="SHIELD_SPARKS",t[t.BULLET_SPARKS=14]="BULLET_SPARKS",t[t.LASER_SPARKS=15]="LASER_SPARKS",t[t.PARASITE_ATTACK=16]="PARASITE_ATTACK",t[t.ROCKET_EXPLOSION_WATER=17]="ROCKET_EXPLOSION_WATER",t[t.GRENADE_EXPLOSION_WATER=18]="GRENADE_EXPLOSION_WATER",t[t.MEDIC_CABLE_ATTACK=19]="MEDIC_CABLE_ATTACK",t[t.BFG_EXPLOSION=20]="BFG_EXPLOSION",t[t.BFG_BIGEXPLOSION=21]="BFG_BIGEXPLOSION",t[t.BOSSTPORT=22]="BOSSTPORT",t[t.BFG_LASER=23]="BFG_LASER",t[t.GRAPPLE_CABLE=24]="GRAPPLE_CABLE",t[t.WELDING_SPARKS=25]="WELDING_SPARKS",t[t.GREENBLOOD=26]="GREENBLOOD",t[t.BLUEHYPERBLASTER=27]="BLUEHYPERBLASTER",t[t.PLASMA_EXPLOSION=28]="PLASMA_EXPLOSION",t[t.TUNNEL_SPARKS=29]="TUNNEL_SPARKS",t[t.BLASTER2=30]="BLASTER2",t[t.RAILTRAIL2=31]="RAILTRAIL2",t[t.FLAME=32]="FLAME",t[t.LIGHTNING=33]="LIGHTNING",t[t.DEBUGTRAIL=34]="DEBUGTRAIL",t[t.PLAIN_EXPLOSION=35]="PLAIN_EXPLOSION",t[t.FLASHLIGHT=36]="FLASHLIGHT",t[t.FORCEWALL=37]="FORCEWALL",t[t.HEATBEAM=38]="HEATBEAM",t[t.MONSTER_HEATBEAM=39]="MONSTER_HEATBEAM",t[t.STEAM=40]="STEAM",t[t.BUBBLETRAIL2=41]="BUBBLETRAIL2",t[t.MOREBLOOD=42]="MOREBLOOD",t[t.HEATBEAM_SPARKS=43]="HEATBEAM_SPARKS",t[t.HEATBEAM_STEAM=44]="HEATBEAM_STEAM",t[t.CHAINFIST_SMOKE=45]="CHAINFIST_SMOKE",t[t.ELECTRIC_SPARKS=46]="ELECTRIC_SPARKS",t[t.TRACKER_EXPLOSION=47]="TRACKER_EXPLOSION",t[t.TELEPORT_EFFECT=48]="TELEPORT_EFFECT",t[t.DBALL_GOAL=49]="DBALL_GOAL",t[t.WIDOWBEAMOUT=50]="WIDOWBEAMOUT",t[t.NUKEBLAST=51]="NUKEBLAST",t[t.WIDOWSPLASH=52]="WIDOWSPLASH",t[t.EXPLOSION1_BIG=53]="EXPLOSION1_BIG",t[t.EXPLOSION1_NP=54]="EXPLOSION1_NP",t[t.FLECHETTE=55]="FLECHETTE",t[t.BLUEHYPERBLASTER_KEX=56]="BLUEHYPERBLASTER_KEX",t[t.BFG_ZAP=57]="BFG_ZAP",t[t.BERSERK_SLAM=58]="BERSERK_SLAM",t[t.GRAPPLE_CABLE_2=59]="GRAPPLE_CABLE_2",t[t.POWER_SPLASH=60]="POWER_SPLASH",t[t.LIGHTNING_BEAM=61]="LIGHTNING_BEAM",t[t.EXPLOSION1_NL=62]="EXPLOSION1_NL",t[t.EXPLOSION2_NL=63]="EXPLOSION2_NL",t))(E||{});var v0=12,w0=9,Fx=Math.ceil(v0*w0/16),S0=23,A0=2,Bx=Math.ceil(S0*A0/16);var Dx=1<<17,Ox=1<<18,zx=1<<19,Nx=1<<20,Ux=1<<21,Hx=1<<22,Gx=1<<23,Vx=1<<24,Wx=1<<25,Xx=1<<26,Kx=1<<27,$x=1<<28,Zx=1<<29,Yx=1<<30;var wn=class{constructor(t){t instanceof Uint8Array?this.view=new DataView(t.buffer,t.byteOffset,t.byteLength):this.view=new DataView(t),this.offset=0,this.length=this.view.byteLength}getPosition(){return this.offset}getReadPosition(){return this.offset}getLength(){return this.length}getRemaining(){return this.length-this.offset}seek(t){if(t<0||t>this.length)throw new Error(`Seek out of bounds: ${t} (length: ${this.length})`);this.offset=t}setReadPosition(t){this.seek(t)}hasMore(){return this.offset<this.length}hasBytes(t){return this.offset+t<=this.length}readChar(){let t=this.view.getInt8(this.offset);return this.offset+=1,t}readByte(){let t=this.view.getUint8(this.offset);return this.offset+=1,t}readShort(){let t=this.view.getInt16(this.offset,!0);return this.offset+=2,t}readUShort(){let t=this.view.getUint16(this.offset,!0);return this.offset+=2,t}readLong(){let t=this.view.getInt32(this.offset,!0);return this.offset+=4,t}readULong(){let t=this.view.getUint32(this.offset,!0);return this.offset+=4,t}readFloat(){let t=this.view.getFloat32(this.offset,!0);return this.offset+=4,t}readString(){let t="";for(;this.offset<this.length;){let e=this.readChar();if(e===-1||e===0)break;t+=String.fromCharCode(e)}return t}readStringLine(){let t="";for(;this.offset<this.length;){let e=this.readChar();if(e===-1||e===0||e===10)break;t+=String.fromCharCode(e)}return t}readCoord(){return this.readShort()*(1/8)}readAngle(){return this.readChar()*(360/256)}readAngle16(){return this.readShort()*360/65536}readData(t){if(this.offset+t>this.length)throw new Error(`Read out of bounds: ${this.offset+t} (length: ${this.length})`);let e=new Uint8Array(this.view.buffer,this.view.byteOffset+this.offset,t);return this.offset+=t,new Uint8Array(e)}readPos(t){t.x=this.readCoord(),t.y=this.readCoord(),t.z=this.readCoord()}readDir(t){let e=this.readByte();if(e>=162){t.x=0,t.y=0,t.z=0;return}let r=Vt[e];t.x=r[0],t.y=r[1],t.z=r[2]}},Gr=class{constructor(t=1400){typeof t=="number"?(this.buffer=new Uint8Array(t),this.fixed=!1):(this.buffer=t,this.fixed=!0),this.view=new DataView(this.buffer.buffer,this.buffer.byteOffset,this.buffer.byteLength),this.offset=0}ensureSpace(t){if(this.offset+t>this.buffer.byteLength){if(this.fixed)throw new Error(`Buffer overflow: capacity ${this.buffer.byteLength}, needed ${this.offset+t}`);let e=Math.max(this.buffer.byteLength*2,this.offset+t),r=new Uint8Array(e);r.set(this.buffer),this.buffer=r,this.view=new DataView(this.buffer.buffer,this.buffer.byteOffset,this.buffer.byteLength)}}writeByte(t){this.ensureSpace(1),this.view.setUint8(this.offset,t),this.offset+=1}writeBytes(t){this.ensureSpace(t.byteLength),this.buffer.set(t,this.offset),this.offset+=t.byteLength}writeChar(t){this.ensureSpace(1),this.view.setInt8(this.offset,t),this.offset+=1}writeShort(t){this.ensureSpace(2),this.view.setInt16(this.offset,t,!0),this.offset+=2}writeLong(t){this.ensureSpace(4),this.view.setInt32(this.offset,t,!0),this.offset+=4}writeFloat(t){this.ensureSpace(4),this.view.setFloat32(this.offset,t,!0),this.offset+=4}writeString(t){let e=t.length;this.ensureSpace(e+1);for(let r=0;r<e;r++)this.view.setUint8(this.offset+r,t.charCodeAt(r));this.view.setUint8(this.offset+e,0),this.offset+=e+1}writeCoord(t){this.writeShort(Math.trunc(t*8))}writeAngle(t){this.writeByte(Math.trunc(t*256/360)&255)}writeAngle16(t){this.writeShort(Math.trunc(t*65536/360)&65535)}writePos(t){this.writeCoord(t.x),this.writeCoord(t.y),this.writeCoord(t.z)}writeDir(t){let e=-1,r=0;if(t.x===0&&t.y===0&&t.z===0){this.writeByte(0);return}for(let n=0;n<Vt.length;n++){let i=Vt[n],s=t.x*i[0]+t.y*i[1]+t.z*i[2];s>e&&(e=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 _n=class ge{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 Gr(ge.MAX_RELIABLE_BUFFER);let e=Date.now();this.lastReceived=e,this.lastSent=e,this.qport=Math.floor(Math.random()*65536)}setup(e,r=null){this.qport=e,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(e){this.outgoingSequence++,this.lastSent=Date.now();let r=0,n=!1,i=0;this.reliableLength>0&&(this.reliableLength>ge.FRAGMENT_SIZE?(n=!0,this.fragmentSendOffset>=this.reliableLength&&(this.fragmentSendOffset=0),r=this.reliableLength-this.fragmentSendOffset,r>ge.FRAGMENT_SIZE&&(r=ge.FRAGMENT_SIZE),i=this.fragmentSendOffset,this.fragmentSendOffset+=r):r=this.reliableLength);let s=ge.PACKET_HEADER,a=r>0?2+(n?8:0):0,o=e?e.length:0;s+a+r+o>ge.MAX_MSGLEN&&(o=ge.MAX_MSGLEN-s-a-r,o<0&&(o=0));let d=new ArrayBuffer(s+a+r+o),l=new DataView(d),c=new Uint8Array(d),f=this.outgoingSequence;r>0&&(f|=2147483648,(this.outgoingReliableSequence&1)!==0&&(f|=1073741824)),l.setUint32(0,f,!0);let u=this.incomingSequence;(this.incomingReliableSequence&1)!==0&&(u|=2147483648),l.setUint32(4,u,!0),l.setUint16(8,this.qport,!0);let h=s;if(r>0){let m=r;n&&(m|=32768),l.setUint16(h,m,!0),h+=2,n&&(l.setUint32(h,i,!0),h+=4,l.setUint32(h,this.reliableLength,!0),h+=4);let p=this.reliableMessage.getBuffer().subarray(i,i+r);c.set(p,h),h+=r}if(e&&o>0){let m=e.slice(0,o);c.set(m,h)}return c}process(e){if(e.length<ge.PACKET_HEADER)return null;this.lastReceived=Date.now();let r=new DataView(e.buffer,e.byteOffset,e.byteLength),n=r.getUint32(0,!0),i=r.getUint32(4,!0),s=r.getUint16(8,!0);if(this.qport!==s)return null;let a=n&1073741823;if((a-this.incomingSequence|0)<=0)return null;this.incomingSequence=a;let o=i&2147483647,d=(i&2147483648)!==0;if(o>this.incomingAcknowledged&&(this.incomingAcknowledged=o),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,f=ge.PACKET_HEADER,u=null;if(l){if(f+2>e.byteLength)return null;let m=r.getUint16(f,!0);f+=2;let g=(m&32768)!==0;m&=32767;let p=this.incomingReliableSequence&1;if(c===p)if(g){if(f+8>e.byteLength)return null;let y=r.getUint32(f,!0);f+=4;let _=r.getUint32(f,!0);if(f+=4,_>ge.MAX_RELIABLE_BUFFER)return console.warn(`NetChan: received invalid fragment total ${_} > ${ge.MAX_RELIABLE_BUFFER}`),null;if((!this.fragmentBuffer||this.fragmentBuffer.length!==_)&&(this.fragmentBuffer=new Uint8Array(_),this.fragmentLength=_,this.fragmentReceived=0),f+m>e.byteLength)return null;let x=e.subarray(f,f+m);y===this.fragmentReceived&&y+m<=_&&(this.fragmentBuffer.set(x,y),this.fragmentReceived+=m,this.fragmentReceived>=_&&(u=this.fragmentBuffer,this.incomingReliableSequence++,this.fragmentBuffer=null,this.fragmentLength=0,this.fragmentReceived=0))}else{if(this.incomingReliableSequence++,f+m>e.byteLength)return null;u=e.slice(f,f+m)}f+=m}let h=e.slice(f);if(u&&u.length>0){let m=u.length+h.length,g=new Uint8Array(m);return g.set(u,0),g.set(h,u.length),g}return h||new Uint8Array(0)}canSendReliable(){return this.reliableLength===0}writeReliableByte(e){if(this.reliableLength+1>ge.MAX_RELIABLE_BUFFER)throw new Error("NetChan reliable buffer overflow");this.reliableMessage.writeByte(e),this.reliableLength++}writeReliableShort(e){if(this.reliableLength+2>ge.MAX_RELIABLE_BUFFER)throw new Error("NetChan reliable buffer overflow");this.reliableMessage.writeShort(e),this.reliableLength+=2}writeReliableLong(e){if(this.reliableLength+4>ge.MAX_RELIABLE_BUFFER)throw new Error("NetChan reliable buffer overflow");this.reliableMessage.writeLong(e),this.reliableLength+=4}writeReliableString(e){let r=e.length+1;if(this.reliableLength+r>ge.MAX_RELIABLE_BUFFER)throw new Error("NetChan reliable buffer overflow");this.reliableMessage.writeString(e),this.reliableLength+=r}getReliableData(){return this.reliableLength===0?new Uint8Array(0):this.reliableMessage.getBuffer().subarray(0,this.reliableLength)}needsKeepalive(e){return e-this.lastSent>1e3}isTimedOut(e,r=3e4){return e-this.lastReceived>r}};_n.MAX_MSGLEN=1400;_n.FRAGMENT_SIZE=1024;_n.PACKET_HEADER=10;_n.HEADER_OVERHEAD=_n.PACKET_HEADER+2;_n.MAX_RELIABLE_BUFFER=262144;var gd=(t=>(t[t.Bullets=0]="Bullets",t[t.Shells=1]="Shells",t[t.Rockets=2]="Rockets",t[t.Grenades=3]="Grenades",t[t.Cells=4]="Cells",t[t.Slugs=5]="Slugs",t[t.MagSlugs=6]="MagSlugs",t[t.Trap=7]="Trap",t[t.Flechettes=8]="Flechettes",t[t.Tesla=9]="Tesla",t[t.Disruptor=10]="Disruptor",t[t.Prox=11]="Prox",t[t.Nuke=12]="Nuke",t[t.Rounds=13]="Rounds",t))(gd||{}),qx=Object.keys(gd).length/2;var vi=32,at=(t=>(t[t.Auto=0]="Auto",t[t.Weapon=1]="Weapon",t[t.Voice=2]="Voice",t[t.Item=3]="Item",t[t.Body=4]="Body",t[t.Aux=5]="Aux",t[t.Footstep=6]="Footstep",t[t.Aux3=7]="Aux3",t[t.NoPhsAdd=8]="NoPhsAdd",t[t.Reliable=16]="Reliable",t[t.ForcePos=32]="ForcePos",t))(at||{}),sl=-1,wi=0,al=1,ol=2,ll=3,Sn=80,cl=.003;function An(t){return t*.001}function Vr(t){let e=An(t);return e<=0?Number.POSITIVE_INFINITY:Sn+1/e}var Si=class{constructor({name:e,defaultValue:r,description:n,flags:i=sa.None,onChange:s}){this.modifiedCount=0;this.name=e,this.defaultValue=r,this.description=n,this.flags=i,this._value=r,this.onChange=s}get string(){return this._value}getString(){return this.string}get number(){return Number(this._value)}getFloat(){return this.number}get integer(){return Math.trunc(this.number)}getInt(){return this.integer}get boolean(){return!!this.integer}getBoolean(){return this.boolean}set(e){if(this.flags&sa.Latch){if(e===this._value){this.latched=void 0;return}if(this.latched===e)return;this.latched!==e&&(this.latched=e);return}this.apply(e)}reset(){this.latched=void 0,this.apply(this.defaultValue)}applyLatched(){if(this.latched===void 0)return!1;let e=this.latched;return this.latched=void 0,e===this._value?!1:(this.apply(e),!0)}apply(e){if(this._value===e)return;let r=this._value;this._value=e,this.modifiedCount+=1,this.onChange?.(this,r)}},Mn=class{constructor(){this.cvars=new Map}register(e){let r=this.cvars.get(e.name);if(r)return r;let n=e.onChange,i=(a,o)=>{n?.(a,o),this.onCvarChange?.(a.name,a.string)},s=new Si({...e,onChange:i});return this.cvars.set(e.name,s),s}get(e){return this.cvars.get(e)}getCvar(e){return this.get(e)}setValue(e,r){let n=this.get(e);if(!n)throw new Error(`Unknown cvar: ${e}`);return n.set(r),n}setCvar(e,r){this.setValue(e,r)}resetAll(){for(let e of this.cvars.values())e.reset()}applyLatched(){let e=!1;for(let r of this.cvars.values())e=r.applyLatched()||e;return e}list(){return[...this.cvars.values()].sort((e,r)=>e.name.localeCompare(r.name))}listCvars(){return this.list().map(e=>({name:e.name,value:e.string,defaultValue:e.defaultValue,flags:e.flags,description:e.description}))}};var En=class{constructor(e,r,n={}){this.game=e;this.client=r;this.started=!1;this.paused_=!1;this.commands=new xn;this.cvars=new Mn;this.stepSimulation=e=>{this.previousFrame=this.latestFrame,this.latestFrame=this.game.frame(e,this.latestCommand)};this.renderClient=e=>{this.client&&(this.latestCommand=this.client.render({...e,previous:this.previousFrame,latest:this.latestFrame}))};let i=n.loop?.now?.()??Date.now();this.startTimeMs=n.startTimeMs??n.loop?.startTimeMs??i,this.loop=new Hr({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(e){throw this.game.shutdown(),this.client?.shutdown(),e}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(e){this.paused_=e,e?this.loop.stop():this.started&&this.loop.start()}get paused(){return this.paused_}pump(e){this.loop.pump(e)}getLatestFrame(){return this.latestFrame}isRunning(){return this.loop.isRunning()}};function M0(t){if(t<0||t>=X.MaxConfigStrings)throw new RangeError(`Configstring index ${t} is out of range (0-${X.MaxConfigStrings-1})`)}function yd(t,e){let r=pd(t);if(e.length>r)throw new RangeError(`Configstring ${t} exceeds maximum length (${e.length} > ${r}); limit is ${xi} chars per slot`)}var Ln=class{constructor(){this.values=new Map;this.modelCursor=X.Models;this.soundCursor=X.Sounds;this.imageCursor=X.Images;this.lightCursor=X.Lights;this.shadowLightCursor=X.ShadowLights;this.itemCursor=X.Items;this.playerSkinCursor=X.PlayerSkins;this.generalCursor=X.General}set(e,r){return M0(e),yd(e,r),this.values.set(e,r),e}get(e){return this.values.get(e)}getName(e){return this.get(e)}getAll(){let e=new Array(md).fill("");for(let[r,n]of this.values.entries())e[r]=n;return e}modelIndex(e){return this.register(e,X.Models,el,"modelCursor")}soundIndex(e){return this.register(e,X.Sounds,oa,"soundCursor")}findSoundIndex(e){for(let r=X.Sounds;r<X.Sounds+oa;r+=1)if(this.values.get(r)===e)return r}imageIndex(e){return this.register(e,X.Images,tl,"imageCursor")}lightIndex(e){return this.register(e,X.Lights,Jo,"lightCursor")}shadowLightIndex(e){return this.register(e,X.ShadowLights,il,"shadowLightCursor")}itemIndex(e){return this.register(e,X.Items,rl,"itemCursor")}playerSkinIndex(e){return this.register(e,X.PlayerSkins,aa,"playerSkinCursor")}generalIndex(e){return this.register(e,X.General,nl,"generalCursor")}register(e,r,n,i){for(let o=r;o<r+n;o+=1)if(this.values.get(o)===e)return o;let s=this[i],a=r+n;if(s>=a)throw new RangeError(`Out of configstring slots for range starting at ${r}`);return yd(s,e),this.values.set(s,e),this[i]=s+1,s}};var Tn=class{constructor(e){this.registry=e.registry,this.system=e.system,this.music=e.music,this.client=e.client}soundindex(e){return this.registry.registerName(e)}sound(e,r,n,i,s,a){this.system.play({entity:e,channel:r,soundIndex:n,volume:i,attenuation:s,timeOffsetMs:a}),this.triggerSubtitle(n)}positioned_sound(e,r,n,i){this.system.positionedSound(e,r,n,i),this.triggerSubtitle(r)}loop_sound(e,r,n,i,s){let a=this.system.play({entity:e,channel:r,soundIndex:n,volume:i,attenuation:s,looping:!0});return this.triggerSubtitle(n),a}stop_entity_sounds(e){this.system.stopEntitySounds(e)}setPlaybackRate(e){this.system.setPlaybackRate(e)}set_listener(e){this.system.setListener(e)}play_music(e,r=!0){return this.music?this.music.play(e,{loop:r}):Promise.resolve()}play_track(e,r=!0){return this.music?this.music.playTrack(e):Promise.resolve()}pause_music(){this.music?.pause()}resume_music(){return this.music?.resume()??Promise.resolve()}stop_music(){this.music?.stop()}set_music_volume(e){this.music?.setVolume(e)}play_ambient(e,r,n){this.system.ambientSound(e,r,n),this.triggerSubtitle(r)}play_channel(e){this.system.play({...e}),this.triggerSubtitle(e.soundIndex)}triggerSubtitle(e){if(!this.client)return;let r=this.registry.getName(e);if(!r)return;let n=r.match(/\[(.*?)\]/);n&&this.client.showSubtitle(n[1],r)}};var Ai=class{constructor(e,r){this.engine=e;this.host=r;this.started=!1}start(){this.started||(this.engine.init(),this.host.start(),this.started=!0)}stop(){this.started&&(this.host.stop(),this.engine.shutdown(),this.started=!1)}pump(e){this.host.pump(e)}getLatestFrame(){return this.host.getLatestFrame()}isRunning(){return this.started&&this.host.isRunning()}};function bd(t,e,r,n,i){let s=new Tn({...n,client:r}),a=new En(e,r,i);return{runtime:new Ai(t,a),audio:s}}var E0="PACK";function L0(t,e,r){let n=[];for(let i=0;i<r;i+=1){let s=t.getUint8(e+i);if(s===0)break;n.push(s)}return String.fromCharCode(...n)}function ae(t){return t.replace(/\\/g,"/").replace(/^\/+/,"").toLowerCase()}function T0(){let t=new Uint32Array(256);for(let e=0;e<256;e+=1){let r=e;for(let n=0;n<8;n+=1)r=(r&1)!==0?3988292384^r>>>1:r>>>1;t[e]=r>>>0}return t}var C0=T0();function xd(t){let e=4294967295;for(let r=0;r<t.length;r+=1){let n=t[r];e=C0[(e^n)&255]^e>>>8}return(e^4294967295)>>>0}var fe=class extends Error{},Cn=class t{constructor(e,r,n,i){this.name=e;this.buffer=r;this.entries=new Map(n.map(s=>[s.name,s])),this.checksum=i,this.size=r.byteLength}static fromArrayBuffer(e,r){let n=new DataView(r);if(r.byteLength<12)throw new fe("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!==E0)throw new fe(`Invalid PAK header magic: ${i}`);let s=n.getInt32(4,!0),a=n.getInt32(8,!0);if(s<12)throw new fe(`Invalid directory offset: ${s}`);if(a<0||a%64!==0)throw new fe(`Invalid directory length: ${a}`);if(s+a>r.byteLength)throw new fe("Directory exceeds buffer length");let d=a/64,l=[],c=new Map;for(let f=0;f<d;f+=1){let u=s+f*64,h=L0(n,u,56),m=ae(h),g=n.getInt32(u+56,!0),p=n.getInt32(u+60,!0);if(g<0||p<0||g+p>r.byteLength)throw new fe(`Invalid entry bounds for ${h||"<unnamed>"} (offset=${g}, length=${p})`);if(!m)throw new fe(`Entry ${f} has an empty name`);let y={name:m,offset:g,length:p};c.set(m,y)}return l.push(...c.values()),new t(e,r,l,xd(new Uint8Array(r)))}getEntry(e){return this.entries.get(ae(e))}listEntries(){return Array.from(this.entries.values())}list(){return Array.from(this.entries.keys())}readFile(e){let r=this.getEntry(e);if(!r)throw new fe(`File not found in PAK: ${e}`);return new Uint8Array(this.buffer,r.offset,r.length)}validate(){return{checksum:this.checksum,entries:this.listEntries()}}};function _d(t){return xd(new Uint8Array(t))}var I0="PACK",vd=12,dl=64;function wd(t){return t.replace(/\\/g,"/").replace(/^\/+/,"").toLowerCase()}var la=class{constructor(e){this.source=e;this.entries=null}async readDirectory(){if(this.entries)return Array.from(this.entries.values());let e=await this.readChunk(0,vd),r=new DataView(e),n=String.fromCharCode(r.getUint8(0),r.getUint8(1),r.getUint8(2),r.getUint8(3));if(n!==I0)throw new fe(`Invalid PAK header magic: ${n}`);let i=r.getInt32(4,!0),s=r.getInt32(8,!0);if(i<vd)throw new fe(`Invalid directory offset: ${i}`);if(s<0||s%dl!==0)throw new fe(`Invalid directory length: ${s}`);let a=await this.readChunk(i,s),o=new DataView(a),d=s/dl,l=new Map;for(let c=0;c<d;c++){let f=c*dl,u=this.readCString(o,f,56),h=wd(u),m=o.getInt32(f+56,!0),g=o.getInt32(f+60,!0);m<0||g<0||m+g>this.source.size,h&&l.set(h,{name:h,offset:m,length:g})}return this.entries=l,Array.from(l.values())}async readFile(e){let r=await this.getEntry(e);if(!r)throw new fe(`File not found in PAK: ${e}`);return this.source.slice(r.offset,r.offset+r.length).stream()}async getFileBlob(e){let r=await this.getEntry(e);if(!r)throw new fe(`File not found in PAK: ${e}`);return this.source.slice(r.offset,r.offset+r.length)}async getEntry(e){return this.entries||await this.readDirectory(),this.entries.get(wd(e))}async readChunk(e,r){let n=this.source.slice(e,e+r);return"arrayBuffer"in n?await n.arrayBuffer():new Response(n).arrayBuffer()}readCString(e,r,n){let i=[];for(let s=0;s<n;s+=1){let a=e.getUint8(r+s);if(a===0)break;i.push(a)}return String.fromCharCode(...i)}};var ul=12,Sd=64,ca=class t{constructor(){this.entries=new Map}addFile(e,r){let n=ae(e);if(n.length>56)throw new Error(`Path too long: '${n}' (max 56 chars)`);this.entries.set(n,r)}removeFile(e){return this.entries.delete(ae(e))}build(){let e=0;for(let u of this.entries.values())e+=u.byteLength;let r=this.entries.size*Sd,n=ul+e+r,i=new Uint8Array(n),s=new DataView(i.buffer);s.setUint8(0,80),s.setUint8(1,65),s.setUint8(2,67),s.setUint8(3,75);let a=ul+e;s.setInt32(4,a,!0),s.setInt32(8,r,!0);let o=ul,d=new Map,l=Array.from(this.entries.keys()).sort();for(let u of l){let h=this.entries.get(u);d.set(u,o),i.set(h,o),o+=h.byteLength}let c=a,f=new TextEncoder;for(let u of l){let h=this.entries.get(u),m=f.encode(u);if(m.length>56)throw new Error(`Path too long after encoding: ${u}`);for(let g=0;g<56;g++)g<m.length?s.setUint8(c+g,m[g]):s.setUint8(c+g,0);s.setInt32(c+56,d.get(u),!0),s.setInt32(c+60,h.byteLength,!0),c+=Sd}return i}static buildFromEntries(e){let r=new t;for(let[n,i]of e)r.addFile(n,i);return r.build()}};var fl=(a=>(a.Texture="texture",a.Sound="sound",a.Model="model",a.Map="map",a.Sprite="sprite",a.ConfigString="configString",a))(fl||{}),da=class{constructor(){this.tracking=!1;this.entries=[];this.currentFrame=0;this.currentTime=0}startTracking(){this.tracking=!0,this.entries=[]}stopTracking(){this.tracking=!1;let e={byFrame:new Map,byTime:new Map,uniqueResources:new Map};for(let r of this.entries){e.byFrame.has(r.frame)||e.byFrame.set(r.frame,[]),e.byFrame.get(r.frame).push(r),e.byTime.has(r.timestamp)||e.byTime.set(r.timestamp,[]),e.byTime.get(r.timestamp).push(r);let n=`${r.type}:${r.path}`;e.uniqueResources.has(n)||e.uniqueResources.set(n,r)}return e}recordLoad(e,r,n,i){this.tracking&&this.entries.push({type:e,path:r,timestamp:this.currentTime,frame:this.currentFrame,size:n,pakSource:i})}setCurrentFrame(e){this.currentFrame=e}setCurrentTime(e){this.currentTime=e}};var ua=class{constructor(e=[]){this.mounts=[];this.files=new Map;e.forEach(r=>this.mountPak(r))}mountPak(e,r=0){let n=this.mounts.findIndex(i=>i.pak===e);n!==-1&&this.mounts.splice(n,1),this.mounts.push({pak:e,priority:r}),this.mounts.sort((i,s)=>s.priority-i.priority);for(let i of e.listEntries()){let s=ae(i.name),a={archive:e,entry:i,priority:r};this.files.has(s)||this.files.set(s,[]);let o=this.files.get(s),d=o.findIndex(l=>l.archive===e);d!==-1&&o.splice(d,1),o.unshift(a),o.sort((l,c)=>c.priority-l.priority)}return e}setPriority(e,r){this.mountPak(e,r)}getPaks(){return[...this.mounts].sort((e,r)=>e.priority-r.priority)}get mountedPaks(){return this.mounts.map(e=>e.pak)}hasFile(e){return this.files.has(ae(e))}getSource(e){let r=this.files.get(ae(e));if(!(!r||r.length===0))return r[0]}stat(e){let r=this.getSource(e);if(r)return{path:r.entry.name,size:r.entry.length,sourcePak:r.archive.name}}getFileMetadata(e){let r=this.getSource(e);if(r)return{path:r.entry.name,size:r.entry.length,sourcePak:r.archive.name,offset:r.entry.offset}}async readFile(e){let r=this.getSource(e);if(!r)throw new Error(`File not found in VFS: ${e}`);return r.archive.readFile(e)}async readBinaryFile(e){return this.readFile(e)}streamFile(e,r=1024*1024){let n=this.getSource(e);if(!n)throw new Error(`File not found in VFS: ${e}`);let{archive:i}=n,s=i.readFile(e),a=0,o=s.length;return new ReadableStream({pull(d){if(a>=o){d.close();return}let l=Math.min(a+r,o),c=s.slice(a,l);a=l,d.enqueue(c)}})}async readTextFile(e){let r=await this.readFile(e);return new TextDecoder("utf-8").decode(r)}list(e=""){let r=ae(e).replace(/\/+$|^\//g,""),n=[],i=new Set,s=r?`${r}/`:"";for(let[a,o]of this.files){let d=o[0];if(r&&!d.entry.name.startsWith(s))continue;let l=r?d.entry.name.slice(s.length):d.entry.name,c=l.indexOf("/");c===-1?n.push({path:d.entry.name,size:d.entry.length,sourcePak:d.archive.name}):i.add(l.slice(0,c))}return n.sort((a,o)=>a.path.localeCompare(o.path)),{files:n,directories:[...i].sort()}}async listDirectory(e){return this.list(e).files}findByExtension(e){if(e instanceof RegExp)return this.searchFiles(e);if(Array.isArray(e))return this.listByExtension(e);let r=e.startsWith(".")?e.toLowerCase():`.${e.toLowerCase()}`,n=[];for(let[i,s]of this.files){let a=s[0];a.entry.name.toLowerCase().endsWith(r)&&n.push({path:a.entry.name,size:a.entry.length,sourcePak:a.archive.name})}return n.sort((i,s)=>i.path.localeCompare(s.path))}listByExtension(e){let r=new Set(e.map(i=>i.startsWith(".")?i.toLowerCase():`.${i.toLowerCase()}`)),n=[];for(let[i,s]of this.files){let a=s[0],o=a.entry.name.toLowerCase();for(let d of r)if(o.endsWith(d)){n.push({path:a.entry.name,size:a.entry.length,sourcePak:a.archive.name});break}}return n.sort((i,s)=>i.path.localeCompare(s.path))}searchFiles(e){let r=[];for(let[n,i]of this.files){let s=i[0];e.test(s.entry.name)&&r.push({path:s.entry.name,size:s.entry.length,sourcePak:s.archive.name})}return r.sort((n,i)=>n.path.localeCompare(i.path))}getPakInfo(){return this.mounts.map(e=>({filename:e.pak.name,entryCount:e.pak.listEntries().length,totalSize:e.pak.size,priority:e.priority}))}getDirectoryTree(){let e={name:"",path:"",files:[],directories:[]},r=new Map;r.set("",e);let n=Array.from(this.files.values()).map(i=>{let s=i[0];return{path:s.entry.name,size:s.entry.length,sourcePak:s.archive.name}}).sort((i,s)=>i.path.localeCompare(s.path));for(let i of n){let s=i.path.split("/"),a=s.pop(),o="",d=e;for(let l of s){let c=o;o=o?`${o}/${l}`:l;let f=r.get(o);f||(f={name:l,path:o,files:[],directories:[]},d.directories.push(f),r.set(o,f)),d=f}d.files.push(i)}return e}};var hl=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"}]),Wr=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"}},fa=class{constructor(e=hl){this.known=new Map;e.forEach(r=>this.known.set(this.normalizePakName(r.name),r))}validateArchive(e,r){let n=this.normalizePakName(r??("name"in e?e.name:"unknown")),i=e.checksum,s="size"in e?e.size:void 0,a=this.known.get(n);return a?a.checksum!==i?{name:n,checksum:i,expectedChecksum:a.checksum,status:"mismatch",size:s,description:a.description}:{name:n,checksum:i,expectedChecksum:a.checksum,status:"valid",size:s,description:a.description}:{name:n,checksum:i,status:"unknown",size:s}}assertValid(e,r){let n=this.validateArchive(e,r);if(n.status==="mismatch")throw new Wr(n);return n}normalizePakName(e){let r=ae(e),n=r.split("/"),i=n.pop()??r,s=n.pop();return s?`${i}@${s}`:i}};var Xt=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 k0(t,e){if(typeof t.arrayBuffer=="function"){let r=await t.arrayBuffer();return e?.({file:"blob",loadedBytes:r.byteLength,totalBytes:r.byteLength,state:"reading"}),r}if(typeof FileReader<"u")return new Promise((r,n)=>{let i=new FileReader;i.onerror=()=>n(i.error??new Error("Unknown FileReader error")),i.onprogress=s=>{e?.({file:"blob",loadedBytes:s.loaded,totalBytes:s.total||t.size,state:"reading"})},i.onload=()=>{let s=i.result;s instanceof ArrayBuffer?r(s):n(new Error("Unexpected FileReader result"))},i.readAsArrayBuffer(t)});if(typeof Response<"u"){let r=await new Response(t).arrayBuffer();return e?.({file:"blob",loadedBytes:r.byteLength,totalBytes:r.byteLength,state:"reading"}),r}if(typeof t.stream=="function"){let r=t.stream().getReader(),n=[],i=0;for(;;){let{done:o,value:d}=await r.read();if(o)break;if(!d)continue;let l=d;n.push(l),i+=l.byteLength,e?.({file:"blob",loadedBytes:i,totalBytes:t.size,state:"reading"})}let s=new Uint8Array(i),a=0;for(let o of n)s.set(o,a),a+=o.byteLength;return s.buffer}throw new Xt("blob",new Error("Unsupported Blob type"))}async function R0(t,e){if(t.data instanceof ArrayBuffer)return e?.({file:t.name,loadedBytes:t.data.byteLength,totalBytes:t.data.byteLength,state:"reading"}),t.data;if(t.data instanceof Blob){let n=t.data.size;return k0(t.data,i=>e?.({...i,file:t.name,totalBytes:n}))}let r=t.data.buffer.slice(t.data.byteOffset,t.data.byteOffset+t.data.byteLength);return e?.({file:t.name,loadedBytes:r.byteLength,totalBytes:r.byteLength,state:"reading"}),r}async function ha(t,e,r){let n=typeof r=="function"?{onProgress:r}:r??{},i=n.persistIndexes??!!n.pakIndexStore,s=n.enforceValidation??!!n.validator,a=n.allowUnknownPaks??!0,o=n.stopOnError??!1,d=[];for(let l of e)try{let c=await R0(l,n.onProgress),f=Cn.fromArrayBuffer(l.name,c),u=n.validator?.validateArchive(f);if(u){n.onValidationResult?.(u);let h=u.status==="mismatch",m=u.status==="unknown";if(h&&s||m&&!a){let g=new Wr(u);if(n.onError?.(l.name,g),o)throw new Xt(l.name,g);d.push({archive:f,mounted:!1,validation:u});continue}}if(t.mountPak(f),i&&n.pakIndexStore)try{await n.pakIndexStore.persist(f)}catch(h){if(n.onError?.(l.name,h),o)throw new Xt(l.name,h)}n.onProgress?.({file:l.name,loadedBytes:c.byteLength,totalBytes:c.byteLength,state:"parsed"}),d.push({archive:f,mounted:!0,validation:u})}catch(c){if(n.onProgress?.({file:l.name,loadedBytes:0,totalBytes:0,state:"error"}),n.onError?.(l.name,c),o)throw new Xt(l.name,c)}return d}var Kt=class{constructor(e,r=1/0,n=()=>0){this.capacity=e;this.maxMemory=r;this.sizeCalculator=n;this.map=new Map;this.currentMemoryUsage=0;if(e<=0)throw new RangeError("LRU cache capacity must be greater than zero")}get size(){return this.map.size}get memoryUsage(){return this.currentMemoryUsage}has(e){return this.map.has(e)}get(e){let r=this.map.get(e);if(r!==void 0)return this.map.delete(e),this.map.set(e,r),r}set(e,r){let n=this.sizeCalculator(r);this.map.has(e)&&this.delete(e),this.map.set(e,r),this.currentMemoryUsage+=n,this.evict()}delete(e){let r=this.map.get(e);return r!==void 0?(this.currentMemoryUsage-=this.sizeCalculator(r),this.map.delete(e)):!1}clear(){this.map.clear(),this.currentMemoryUsage=0}entries(){return Array.from(this.map.entries()).reverse().map(([e,r])=>({key:e,value:r}))}evict(){for(;this.map.size>this.capacity;){let e=this.map.keys().next();if(!e.done)this.delete(e.value);else break}for(;this.currentMemoryUsage>this.maxMemory&&this.map.size>0;){let e=this.map.keys().next();if(!e.done)this.delete(e.value);else break}}};function P0(t){return Array.isArray(t)?t:Array.from(t)}function ml(t){return P0(t).map(e=>({name:e.name,data:e}))}async function Ad(t,e,r){let n=ml(e);return ha(t,n,r??{})}function Md(t,e){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&&e(Array.from(s))};return t.addEventListener("dragover",r),t.addEventListener("drop",n),()=>{t.removeEventListener("dragover",r),t.removeEventListener("drop",n)}}function Ed(t,e){let r=n=>{let i=n.target;!i||!i.files||i.files.length===0||(e(i.files),i.value="")};return t.addEventListener("change",r),()=>t.removeEventListener("change",r)}var F0="IBSP",B0=38,Td=19,D0=8+Td*8;var Q=class extends Error{},In=class{constructor(e){this.vfs=e}async load(e){let r=await this.vfs.readFile(e),n=new Uint8Array(r.byteLength);return n.set(r),Mi(n.buffer)}};function Mi(t){if(t.byteLength<D0)throw new Q("BSP too small to contain header");let e=new DataView(t),r=String.fromCharCode(e.getUint8(0),e.getUint8(1),e.getUint8(2),e.getUint8(3));if(r!==F0)throw new Q(`Invalid BSP magic ${r}`);let n=e.getInt32(4,!0);if(n!==B0)throw new Q(`Unsupported BSP version ${n}`);let i=new Map;for(let w=0;w<Td;w+=1){let L=e.getInt32(8+w*8,!0),T=e.getInt32(12+w*8,!0);if(L<0||T<0||L+T>t.byteLength)throw new Q(`Invalid lump bounds for index ${w}`);i.set(w,{offset:L,length:T})}let s={version:n,lumps:i},a=z0(t,i.get(0)),o=U0(t,i.get(1)),d=H0(t,i.get(2)),l=G0(t,i.get(4)),c=V0(t,i.get(5)),f=W0(t,i.get(6)),u=new Uint8Array(t,i.get(7).offset,i.get(7).length),h=J0(f,i.get(7)),m=X0(t,i.get(8)),g=K0(t,i.get(11)),p=$0(t,i.get(12)),y=Z0(t,i.get(13)),_=Y0(t,i.get(14)),x=q0(t,i.get(15)),b=j0(t,i.get(9),i.get(10),m),v=Q0(t,i.get(3));return{header:s,entities:a,planes:o,vertices:d,nodes:l,texInfo:c,faces:f,lightMaps:u,lightMapInfo:h,leafs:m,leafLists:b,edges:g,surfEdges:p,models:y,brushes:_,brushSides:x,visibility:v,pickEntity(w){let L=null,T=1/0;for(let A of a.entities){let I=A.properties.model;if(!I||!I.startsWith("*"))continue;let R=parseInt(I.substring(1),10);if(isNaN(R)||R<0||R>=y.length)continue;let F=y[R],k=O0(w.origin,w.direction,F.mins,F.maxs);k!==null&&k<T&&(T=k,L={entity:A,model:F,distance:k})}return L}}}function O0(t,e,r,n){let i=0,s=1/0;for(let a=0;a<3;a++)if(Math.abs(e[a])<1e-8){if(t[a]<r[a]||t[a]>n[a])return null}else{let o=1/e[a],d=(r[a]-t[a])*o,l=(n[a]-t[a])*o;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 z0(t,e){let r=new TextDecoder().decode(new Uint8Array(t,e.offset,e.length)),n=N0(r),i=n.find(s=>s.classname==="worldspawn");return{raw:r,entities:n,worldspawn:i,getUniqueClassnames(){let s=new Set;for(let a of n)a.classname&&s.add(a.classname);return Array.from(s).sort()}}}function N0(t){let e=[],r=/\{([^}]*)\}/gms,n;for(;(n=r.exec(t))!==null;){let i=n[1],s={},a=/"([^\"]*)"\s+"([^\"]*)"/g,o;for(;(o=a.exec(i))!==null;)s[o[1]]=o[2];e.push({classname:s.classname,properties:s})}return e}function U0(t,e){let r=new DataView(t,e.offset,e.length),n=e.length/20;if(n%1!==0)throw new Q("Plane lump has invalid length");let i=[];for(let s=0;s<n;s+=1){let a=[r.getFloat32(s*20,!0),r.getFloat32(s*20+4,!0),r.getFloat32(s*20+8,!0)],o=r.getFloat32(s*20+12,!0),d=r.getInt32(s*20+16,!0);i.push({normal:a,dist:o,type:d})}return i}function H0(t,e){let r=new DataView(t,e.offset,e.length),n=e.length/12;if(n%1!==0)throw new Q("Vertex lump has invalid length");let i=[];for(let 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 G0(t,e){let r=new DataView(t,e.offset,e.length),n=28,i=e.length/n;if(i%1!==0)throw new Q("Node lump has invalid length");let s=[];for(let a=0;a<i;a+=1){let o=a*n,d=r.getInt32(o,!0),l=[r.getInt32(o+4,!0),r.getInt32(o+8,!0)],c=[r.getInt16(o+12,!0),r.getInt16(o+14,!0),r.getInt16(o+16,!0)],f=[r.getInt16(o+18,!0),r.getInt16(o+20,!0),r.getInt16(o+22,!0)],u=r.getUint16(o+24,!0),h=r.getUint16(o+26,!0);s.push({planeIndex:d,children:l,mins:c,maxs:f,firstFace:u,numFaces:h})}return s}function V0(t,e){let r=new DataView(t,e.offset,e.length),n=76,i=e.length/n;if(i%1!==0)throw new Q("TexInfo lump has invalid length");let s=[];for(let a=0;a<i;a+=1){let o=a*n,d=[r.getFloat32(o,!0),r.getFloat32(o+4,!0),r.getFloat32(o+8,!0)],l=r.getFloat32(o+12,!0),c=[r.getFloat32(o+16,!0),r.getFloat32(o+20,!0),r.getFloat32(o+24,!0)],f=r.getFloat32(o+28,!0),u=r.getInt32(o+32,!0),h=r.getInt32(o+36,!0),m=new Uint8Array(t,e.offset+o+40,32),g=new TextDecoder("utf-8").decode(m).replace(/\0.*$/,""),p=r.getInt32(o+72,!0);s.push({s:d,sOffset:l,t:c,tOffset:f,flags:u,value:h,texture:g,nextTexInfo:p})}return s}function W0(t,e){let r=new DataView(t,e.offset,e.length),n=20,i=e.length/n;if(i%1!==0)throw new Q("Face lump has invalid length");let s=[];for(let a=0;a<i;a+=1){let o=a*n,d=r.getUint16(o,!0),l=r.getInt16(o+2,!0),c=r.getInt32(o+4,!0),f=r.getInt16(o+8,!0),u=r.getInt16(o+10,!0),h=[r.getUint8(o+12),r.getUint8(o+13),r.getUint8(o+14),r.getUint8(o+15)],m=r.getInt32(o+16,!0);s.push({planeIndex:d,side:l,firstEdge:c,numEdges:f,texInfo:u,styles:h,lightOffset:m})}return s}function X0(t,e){let r=new DataView(t,e.offset,e.length),n=28,i=e.length/n;if(i%1!==0)throw new Q("Leaf lump has invalid length");let s=[];for(let a=0;a<i;a+=1){let o=a*n,d=r.getInt32(o,!0),l=r.getInt16(o+4,!0),c=r.getInt16(o+6,!0),f=[r.getInt16(o+8,!0),r.getInt16(o+10,!0),r.getInt16(o+12,!0)],u=[r.getInt16(o+14,!0),r.getInt16(o+16,!0),r.getInt16(o+18,!0)],h=r.getUint16(o+20,!0),m=r.getUint16(o+22,!0),g=r.getUint16(o+24,!0),p=r.getUint16(o+26,!0);s.push({contents:d,cluster:l,area:c,mins:f,maxs:u,firstLeafFace:h,numLeafFaces:m,firstLeafBrush:g,numLeafBrushes:p})}return s}function K0(t,e){let r=new DataView(t,e.offset,e.length),n=4,i=e.length/n;if(i%1!==0)throw new Q("Edge lump has invalid length");let s=[];for(let a=0;a<i;a+=1){let o=a*n;s.push({vertices:[r.getUint16(o,!0),r.getUint16(o+2,!0)]})}return s}function $0(t,e){let r=e.length/4;if(r%1!==0)throw new Q("SurfEdge lump has invalid length");let n=new DataView(t,e.offset,e.length),i=new Int32Array(r);for(let s=0;s<r;s+=1)i[s]=n.getInt32(s*4,!0);return i}function Z0(t,e){let r=new DataView(t,e.offset,e.length),n=48;if(e.length%n!==0)throw new Q("Model lump has invalid length");let i=e.length/n,s=[];for(let a=0;a<i;a+=1){let o=a*n,d=[r.getFloat32(o,!0),r.getFloat32(o+4,!0),r.getFloat32(o+8,!0)],l=[r.getFloat32(o+12,!0),r.getFloat32(o+16,!0),r.getFloat32(o+20,!0)],c=[r.getFloat32(o+24,!0),r.getFloat32(o+28,!0),r.getFloat32(o+32,!0)],f=r.getInt32(o+36,!0),u=r.getInt32(o+40,!0),h=r.getInt32(o+44,!0);s.push({mins:d,maxs:l,origin:c,headNode:f,firstFace:u,numFaces:h})}return s}function Y0(t,e){let r=new DataView(t,e.offset,e.length),n=12,i=e.length/n;if(i%1!==0)throw new Q("Brush lump has invalid length");let s=[];for(let a=0;a<i;a+=1){let o=a*n;s.push({firstSide:r.getInt32(o,!0),numSides:r.getInt32(o+4,!0),contents:r.getInt32(o+8,!0)})}return s}function q0(t,e){let r=new DataView(t,e.offset,e.length),n=4,i=e.length/n;if(i%1!==0)throw new Q("Brush side lump has invalid length");let s=[];for(let a=0;a<i;a+=1){let o=a*n;s.push({planeIndex:r.getUint16(o,!0),texInfo:r.getInt16(o+2,!0)})}return s}function j0(t,e,r,n){let i=[],s=[],a=e.length/2,o=r.length/2,d=new DataView(t,e.offset,e.length),l=new DataView(t,r.offset,r.length);for(let c of n){if(c.firstLeafFace+c.numLeafFaces>a)throw new Q("Leaf faces reference data past lump bounds");if(c.firstLeafBrush+c.numLeafBrushes>o)throw new Q("Leaf brushes reference data past lump bounds");let f=[];for(let h=0;h<c.numLeafFaces;h+=1)f.push(d.getUint16((c.firstLeafFace+h)*2,!0));let u=[];for(let h=0;h<c.numLeafBrushes;h+=1)u.push(l.getUint16((c.firstLeafBrush+h)*2,!0));i.push(f),s.push(u)}return{leafFaces:i,leafBrushes:s}}function Q0(t,e){if(e.length===0)return;if(e.length<4)throw new Q("Visibility lump too small");let r=new DataView(t,e.offset,e.length),n=r.getInt32(0,!0),i=4+n*8;if(n<0||i>e.length)throw new Q("Visibility lump truncated");let s=4,a=[];for(let o=0;o<n;o+=1){let d=r.getInt32(s,!0),l=r.getInt32(s+4,!0);s+=8;let c=e.offset+d,f=e.offset+l,u=e.offset+e.length;if(d<0||l<0||c>=u||f>=u)throw new Q("Visibility offsets out of range");a.push({pvs:Ld(t,c,n,e),phs:Ld(t,f,n,e)})}return{numClusters:n,clusters:a}}function Ld(t,e,r,n){let i=Math.ceil(r/8),s=new Uint8Array(i),a=new Uint8Array(t),o=e,d=0,l=n.offset+n.length;for(;d<i;){if(o>=l)throw new Q("Visibility data truncated");let c=a[o++];if(c!==0){s[d++]=c;continue}if(o>=l)throw new Q("Visibility run exceeds lump bounds");let f=a[o++];for(let u=0;u<f&&d<i;u+=1)s[d++]=0}return s}function J0(t,e){return t.map(r=>{if(!(r.lightOffset<0))return{offset:r.lightOffset,length:Math.max(0,e.length-r.lightOffset)}})}function ma(t,e,r){if(t.lightOffset<0||t.lightOffset>=e.byteLength)return;let n=e.byteLength-t.lightOffset,i=Math.min(r?.length??n,n);if(!(i<=0))return e.subarray(t.lightOffset,t.lightOffset+i)}var em=844121161,tm=8,Cd=68,ye=class extends Error{},kn=class{constructor(e){this.vfs=e;this.cache=new Map}async load(e){if(this.cache.has(e))return this.cache.get(e);let r=await this.vfs.readFile(e),n=new Uint8Array(r.byteLength);n.set(r);let i=pl(n.buffer);return this.cache.set(e,i),i}get(e){return this.cache.get(e)}};function Id(t,e,r){let n=[];for(let i=0;i<r;i+=1){let s=t.getUint8(e+i);if(s===0)break;n.push(s)}return String.fromCharCode(...n)}function Ei(t,e,r,n){if(r!==0&&(e<Cd||e+r>t.byteLength))throw new ye(`${n} section is out of bounds`)}function rm(t){if(t.byteLength<Cd)throw new ye("MD2 buffer too small to contain header");let e=new DataView(t),r=e.getInt32(0,!0),n=e.getInt32(4,!0);if(r!==em)throw new ye(`Invalid MD2 ident: ${r}`);if(n!==tm)throw new ye(`Unsupported MD2 version: ${n}`);let i={ident:r,version:n,skinWidth:e.getInt32(8,!0),skinHeight:e.getInt32(12,!0),frameSize:e.getInt32(16,!0),numSkins:e.getInt32(20,!0),numVertices:e.getInt32(24,!0),numTexCoords:e.getInt32(28,!0),numTriangles:e.getInt32(32,!0),numGlCommands:e.getInt32(36,!0),numFrames:e.getInt32(40,!0),offsetSkins:e.getInt32(44,!0),offsetTexCoords:e.getInt32(48,!0),offsetTriangles:e.getInt32(52,!0),offsetFrames:e.getInt32(56,!0),offsetGlCommands:e.getInt32(60,!0),offsetEnd:e.getInt32(64,!0),magic:r},s=40+i.numVertices*4;if(i.frameSize!==s)throw new ye(`Unexpected frame size ${i.frameSize}, expected ${s}`);if(i.offsetEnd>t.byteLength)throw new ye("MD2 offset_end exceeds buffer length");return i}function nm(t,e){let r=e.numSkins*64;Ei(t,e.offsetSkins,r,"skins");let n=new DataView(t,e.offsetSkins,r),i=[];for(let s=0;s<e.numSkins;s+=1)i.push({name:Id(n,s*64,64)});return i}function im(t,e){let r=e.numTexCoords*4;Ei(t,e.offsetTexCoords,r,"texcoords");let n=new DataView(t,e.offsetTexCoords,r),i=[];for(let s=0;s<e.numTexCoords;s+=1){let a=s*4;i.push({s:n.getInt16(a,!0),t:n.getInt16(a+2,!0)})}return i}function sm(t,e){let r=e.numTriangles*12;Ei(t,e.offsetTriangles,r,"triangles");let n=new DataView(t,e.offsetTriangles,r),i=[];for(let s=0;s<e.numTriangles;s+=1){let a=s*12,o=[n.getUint16(a,!0),n.getUint16(a+2,!0),n.getUint16(a+4,!0)],d=[n.getUint16(a+6,!0),n.getUint16(a+8,!0),n.getUint16(a+10,!0)];if(o.some(l=>l>=e.numVertices)||d.some(l=>l>=e.numTexCoords))throw new ye("Triangle references out of range vertex or texcoord");i.push({vertexIndices:o,texCoordIndices:d})}return i}function am(t,e){let r=e.numFrames*e.frameSize;Ei(t,e.offsetFrames,r,"frames");let n=[];for(let i=0;i<e.numFrames;i+=1){let s=e.offsetFrames+i*e.frameSize,a=new DataView(t,s,e.frameSize),o={x:a.getFloat32(0,!0),y:a.getFloat32(4,!0),z:a.getFloat32(8,!0)},d={x:a.getFloat32(12,!0),y:a.getFloat32(16,!0),z:a.getFloat32(20,!0)},l=Id(a,24,16),c=[],f=1/0,u=1/0,h=1/0,m=-1/0,g=-1/0,p=-1/0;for(let y=0;y<e.numVertices;y+=1){let _=40+y*4,x=a.getUint8(_)*o.x+d.x,b=a.getUint8(_+1)*o.y+d.y,v=a.getUint8(_+2)*o.z+d.z;x<f&&(f=x),b<u&&(u=b),v<h&&(h=v),x>m&&(m=x),b>g&&(g=b),v>p&&(p=v);let S={x,y:b,z:v},w=a.getUint8(_+3),L=Vt[w];if(!L)throw new ye(`Invalid normal index ${w} in frame ${l}`);let T={x:L[0],y:L[1],z:L[2]};c.push({position:S,normalIndex:w,normal:T})}n.push({name:l,vertices:c,minBounds:{x:f,y:u,z:h},maxBounds:{x:m,y:g,z:p}})}return n}function om(t,e){let r=e.numGlCommands*4;if(Ei(t,e.offsetGlCommands,r,"gl commands"),r===0)return[];let n=new DataView(t,e.offsetGlCommands,r),i=[],s=0;for(;;){if(s+4>r)throw new ye("GL command list ended unexpectedly");let a=n.getInt32(s,!0);if(s+=4,a===0)break;let o=Math.abs(a),d=[],l=o*12;if(s+l>r)throw new ye("GL command vertex block exceeds buffer");for(let c=0;c<o;c+=1){let f=n.getFloat32(s,!0),u=n.getFloat32(s+4,!0),h=n.getInt32(s+8,!0);if(s+=12,h<0||h>=e.numVertices)throw new ye("GL command references invalid vertex index");d.push({s:f,t:u,vertexIndex:h})}i.push({mode:a>0?"strip":"fan",vertices:d})}if(s!==r)throw new ye("GL command list did not consume expected data");return i}function pl(t){let e=rm(t),r=nm(t,e),n=im(t,e),i=sm(t,e),s=am(t,e),a=om(t,e);return{header:e,skins:r,texCoords:n,triangles:i,frames:s,glCommands:a}}function kd(t){let e=[],r=0;for(;r<t.length;){let n=t[r].name,i=n.replace(/\d+$/,"")||n,s=r;for(;s+1<t.length&&(t[s+1].name.replace(/\d+$/,"")||t[s+1].name)===i;)s+=1;e.push({name:i,firstFrame:r,lastFrame:s}),r=s+1}return e}var Rd=860898377,lm=15,Ve=class extends Error{constructor(e){super(e),this.name="Md3ParseError"}};function Li(t,e,r){let n=new Uint8Array(t.buffer,t.byteOffset+e,r);return new TextDecoder("utf-8").decode(n).replace(/\0.*$/,"").trim()}function cm(t){let e=(t>>8&255)*(2*Math.PI/255),r=(t&255)*(2*Math.PI/255),n=Math.sin(r);return{x:Math.cos(e)*n,y:Math.sin(e)*n,z:Math.cos(r)}}function pa(t,e,r,n){if(e<0||e+r>n)throw new Ve(`${t} exceeds buffer bounds`)}function dm(t){let e=t.getInt32(0,!0);if(e!==Rd)throw new Ve(`Invalid MD3 ident: ${e}`);let r=t.getInt32(4,!0);if(r!==lm)throw new Ve(`Unsupported MD3 version: ${r}`);let n=Li(t,8,64),i=t.getInt32(72,!0),s=t.getInt32(76,!0),a=t.getInt32(80,!0),o=t.getInt32(84,!0),d=t.getInt32(88,!0),l=t.getInt32(92,!0),c=t.getInt32(96,!0),f=t.getInt32(100,!0),u=t.getInt32(104,!0);if(s<=0||o<0||a<0)throw new Ve("Invalid MD3 counts");return{ident:e,version:r,name:n,flags:i,numFrames:s,numTags:a,numSurfaces:o,numSkins:d,ofsFrames:l,ofsTags:c,ofsSurfaces:f,ofsEnd:u,magic:e}}function um(t,e){let r=[];pa("Frames",e.ofsFrames,e.numFrames*56,t.byteLength);for(let i=0;i<e.numFrames;i+=1){let s=e.ofsFrames+i*56;r.push({minBounds:{x:t.getFloat32(s,!0),y:t.getFloat32(s+4,!0),z:t.getFloat32(s+8,!0)},maxBounds:{x:t.getFloat32(s+12,!0),y:t.getFloat32(s+16,!0),z:t.getFloat32(s+20,!0)},localOrigin:{x:t.getFloat32(s+24,!0),y:t.getFloat32(s+28,!0),z:t.getFloat32(s+32,!0)},radius:t.getFloat32(s+36,!0),name:Li(t,s+40,16)})}return r}function fm(t,e){let r=[],i=e.numFrames*e.numTags*112;pa("Tags",e.ofsTags,i,t.byteLength);for(let s=0;s<e.numFrames;s+=1){let a=[];for(let o=0;o<e.numTags;o+=1){let d=e.ofsTags+(s*e.numTags+o)*112,l=d+64,c=l+12;a.push({name:Li(t,d,64),origin:{x:t.getFloat32(l,!0),y:t.getFloat32(l+4,!0),z:t.getFloat32(l+8,!0)},axis:[{x:t.getFloat32(c,!0),y:t.getFloat32(c+4,!0),z:t.getFloat32(c+8,!0)},{x:t.getFloat32(c+12,!0),y:t.getFloat32(c+16,!0),z:t.getFloat32(c+20,!0)},{x:t.getFloat32(c+24,!0),y:t.getFloat32(c+28,!0),z:t.getFloat32(c+32,!0)}]})}r.push(a)}return r}function hm(t,e){let r=t.getInt32(e,!0);if(r!==Rd)throw new Ve(`Invalid surface ident at ${e}: ${r}`);let n=Li(t,e+4,64),i=t.getInt32(e+68,!0),s=t.getInt32(e+72,!0),a=t.getInt32(e+76,!0),o=t.getInt32(e+80,!0),d=t.getInt32(e+84,!0),l=t.getInt32(e+88,!0),c=t.getInt32(e+92,!0),f=t.getInt32(e+96,!0),u=t.getInt32(e+100,!0),h=t.getInt32(e+104,!0);if(s<=0||o<=0||d<=0)throw new Ve(`Invalid surface counts for ${n}`);let m=h;pa(`Surface ${n}`,e,m,t.byteLength);let g=[],p=e+l;for(let w=0;w<d;w+=1){let L=p+w*12;g.push({indices:[t.getInt32(L,!0),t.getInt32(L+4,!0),t.getInt32(L+8,!0)]})}let y=[],_=e+c;for(let w=0;w<a;w+=1){let L=_+w*68;y.push({name:Li(t,L,64),shaderIndex:t.getInt32(L+64,!0)})}let x=[],b=e+f;for(let w=0;w<o;w+=1){let L=b+w*8;x.push({s:t.getFloat32(L,!0),t:t.getFloat32(L+4,!0)})}let v=[],S=e+u;for(let w=0;w<s;w+=1){let L=[];for(let T=0;T<o;T+=1){let A=S+(w*o+T)*8,I=t.getInt16(A,!0)/64,R=t.getInt16(A+2,!0)/64,F=t.getInt16(A+4,!0)/64,k=t.getUint16(A+6,!0);L.push({position:{x:I,y:R,z:F},latLng:k,normal:cm(k)})}v.push(L)}return{surface:{name:n,flags:i,numFrames:s,shaders:y,triangles:g,texCoords:x,vertices:v},nextOffset:e+h}}function gl(t){if(t.byteLength<108)throw new Ve("MD3 buffer too small for header");let e=new DataView(t),r=dm(e);pa("MD3 end",r.ofsEnd,0,t.byteLength);let n=um(e,r),i=fm(e,r),s=[],a=r.ofsSurfaces;for(let o=0;o<r.numSurfaces;o+=1){let{surface:d,nextOffset:l}=hm(e,a);s.push(d),a=l}if(a!==r.ofsEnd)throw new Ve("Surface parsing did not reach ofsEnd");return{header:r,frames:n,tags:i,surfaces:s}}var Rn=class{constructor(e){this.vfs=e;this.cache=new Map}async load(e){if(this.cache.has(e))return this.cache.get(e);let r=await this.vfs.readFile(e),n=gl(r.slice().buffer);return this.cache.set(e,n),n}get(e){return this.cache.get(e)}};var mm=844317769,pm=2,Pd=64,Fd=12,$t=class extends Error{};function gm(t,e,r){let n=[];for(let i=0;i<r;i+=1){let s=t.getUint8(e+i);if(s===0)break;n.push(s)}return String.fromCharCode(...n)}function yl(t){if(t.byteLength<Fd)throw new $t("Sprite buffer too small to contain header");let e=new DataView(t),r=e.getInt32(0,!0),n=e.getInt32(4,!0),i=e.getInt32(8,!0);if(r!==mm)throw new $t(`Invalid Sprite ident: ${r}`);if(n!==pm)throw new $t(`Unsupported Sprite version: ${n}`);let s=[],a=16+Pd,o=Fd;for(let d=0;d<i;d+=1){if(o+a>t.byteLength)throw new $t("Sprite frame data exceeds buffer length");let l=e.getInt32(o,!0),c=e.getInt32(o+4,!0),f=e.getInt32(o+8,!0),u=e.getInt32(o+12,!0),h=gm(e,o+16,Pd);s.push({width:l,height:c,originX:f,originY:u,name:h}),o+=a}return{ident:r,version:n,numFrames:i,frames:s}}var Pn=class{constructor(e){this.vfs=e}async load(e){let r=await this.vfs.readFile(e),n=new Uint8Array(r.byteLength);return n.set(r),yl(n.buffer)}};function Bd(t,e){let r=(t.sequence.end-t.sequence.start+1)/t.sequence.fps,n=t.sequence.loop!==!1,i=t.time+e;return n?i=(i%r+r)%r:i>r&&(i=r),{...t,time:Math.max(0,Math.min(i,r))}}function Dd(t){let e=t.sequence.end-t.sequence.start+1,r=1/t.sequence.fps,n=t.sequence.loop!==!1,i=t.time/r;if(!n&&i>=e)return{frame0:t.sequence.end,frame1:t.sequence.end,lerp:0};let s=n?i%e:Math.min(i,e-1),a=Math.floor(s),o=t.sequence.start+a,d=a+1>=e?n?t.sequence.start:t.sequence.end:o+1,l=!n&&a>=e-1?0:s-a;return{frame0:o,frame1:d,lerp:l}}function Od(t){return{sequence:t,time:0}}function zd(t,e,r){return{x:t.x+(e.x-t.x)*r,y:t.y+(e.y-t.y)*r,z:t.z+(e.z-t.z)*r}}var Ti=class extends Error{constructor(e){super(e),this.name="WalParseError"}};function ga(t){if(t.byteLength<100)throw new Ti("WAL buffer too small");let e=new DataView(t),r=new Uint8Array(t,0,32),n=new TextDecoder("utf-8").decode(r).replace(/\0.*$/,"").trim(),i=e.getInt32(32,!0),s=e.getInt32(36,!0),a=[e.getInt32(40,!0),e.getInt32(44,!0),e.getInt32(48,!0),e.getInt32(52,!0)],o=new Uint8Array(t,56,32),d=new TextDecoder("utf-8").decode(o).replace(/\0.*$/,"").trim(),l=e.getInt32(88,!0),c=e.getInt32(92,!0),f=e.getInt32(96,!0);if(i<=0||s<=0)throw new Ti("Invalid WAL dimensions");let u=[],h=i,m=s;for(let g=0;g<a.length;g+=1){let p=a[g],y=Math.max(1,h*m|0);if(p<=0||p+y>t.byteLength)throw new Ti(`Invalid WAL mip offset for level ${g}`);let _=new Uint8Array(t,p,y);u.push({level:g,width:h,height:m,data:_}),h=Math.max(1,h>>1),m=Math.max(1,m>>1)}return{name:n,width:i,height:s,mipmaps:u,animName:d,flags:l,contents:c,value:f}}var Xr=class extends Error{constructor(e){super(e),this.name="PcxParseError"}};function Ci(t){if(t.byteLength<128)throw new Xr("PCX buffer too small for header");let e=new DataView(t),r=e.getUint8(0),n=e.getUint8(2),i=e.getUint8(3),s=e.getUint16(4,!0),a=e.getUint16(6,!0),o=e.getUint16(8,!0),d=e.getUint16(10,!0);if(r!==10||n!==1)throw new Xr("Unsupported PCX encoding");if(i!==8)throw new Xr("Only 8bpp PCX files are supported");let l=o-s+1,c=d-a+1,f=e.getUint16(66,!0),u=t.byteLength-769;if(u<128||new DataView(t,u,1).getUint8(0)!==12)throw new Xr("Missing PCX palette");let h=new Uint8Array(t,u+1,768),m=new Uint8Array(t,128,u-128),g=new Uint8Array(l*c),p=0,y=0;for(let _=0;_<c;_+=1){let x=0;for(;x<f&&p<m.length;){let b=1,v=m[p++];if((v&192)===192){if(b=v&63,p>=m.length)throw new Xr("Unexpected end of PCX RLE data");v=m[p++]}for(let S=0;S<b&&x<f;S+=1)x<l&&(g[y++]=v),x+=1}}return{width:l,height:c,bitsPerPixel:i,pixels:g,palette:h}}function ya(t){let e=new Uint8Array(t.width*t.height*4);for(let r=0;r<t.pixels.length;r+=1){let n=t.pixels[r],i=n*3,s=r*4;e[s]=t.palette[i],e[s+1]=t.palette[i+1],e[s+2]=t.palette[i+2],e[s+3]=n===255?0:255}return e}var Mt=class extends Error{constructor(e){super(e),this.name="TgaParseError"}};function bl(t){let e=new DataView(t);if(t.byteLength<18)throw new Mt("Buffer too small for TGA header");let r=e.getUint8(0),n=e.getUint8(1),i=e.getUint8(2),s=e.getUint16(12,!0),a=e.getUint16(14,!0),o=e.getUint8(16),d=e.getUint8(17);if(i!==2&&i!==10&&i!==3&&i!==11)throw new Mt(`Unsupported TGA image type: ${i} (only RGB/Grayscale supported)`);if(o!==24&&o!==32&&o!==8)throw new Mt(`Unsupported pixel depth: ${o} (only 8, 24, 32 bpp supported)`);let l=i>=9,c=i===3||i===11,f=o/8,u=18+r;if(n===1){let x=e.getUint16(5,!0),b=e.getUint8(7);u+=x*(b/8)}let h=s*a,m=new Uint8Array(h*4),g=(d&32)!==0,p=0,y=new Uint8Array(t),_=x=>{if(c){let b=y[u++];m[x]=b,m[x+1]=b,m[x+2]=b,m[x+3]=255}else{let b=y[u++],v=y[u++],S=y[u++],w=o===32?y[u++]:255;m[x]=S,m[x+1]=v,m[x+2]=b,m[x+3]=w}};if(l){let x=0;for(;x<h;){if(u>=t.byteLength)throw new Mt("Unexpected end of TGA RLE data");let b=y[u++],v=(b&127)+1,S=(b&128)!==0;if(x+v>h)throw new Mt("TGA RLE packet exceeds image bounds");if(S){let w=c?y[u]:y[u+2],L=c?y[u]:y[u+1],T=y[u],A=c?255:o===32?y[u+3]:255;u+=f;for(let I=0;I<v;I++){let R=(x+I)*4;m[R]=w,m[R+1]=L,m[R+2]=T,m[R+3]=A}}else for(let w=0;w<v;w++)_((x+w)*4);x+=v}}else for(let x=0;x<h;x++){if(u>=t.byteLength)throw new Mt("Unexpected end of TGA data");_(x*4)}if(!g){let x=s*4,b=new Uint8Array(x);for(let v=0;v<a/2;v++){let S=v*x,w=(a-1-v)*x;b.set(m.subarray(S,S+x)),m.set(m.subarray(w,w+x),S),m.set(b,w)}}return{width:s,height:a,bitsPerPixel:32,pixels:m}}function ym(t){let e=0;for(let r of t.levels)e+=r.rgba.byteLength;return e}var Fn=class{constructor(e={}){this.cache=new Kt(e.capacity??128,e.maxMemory??256*1024*1024,ym)}get size(){return this.cache.size}get memoryUsage(){return this.cache.memoryUsage}get(e){return this.cache.get(e.toLowerCase())}set(e,r){this.cache.set(e.toLowerCase(),r)}clear(){this.cache.clear()}};function xl(t,e){let r=[];for(let n of t.mipmaps){let i=new Uint8Array(n.width*n.height*4);for(let s=0;s<n.data.length;s+=1){let a=n.data[s],o=a*3,d=s*4;i[d]=e[o],i[d+1]=e[o+1],i[d+2]=e[o+2],i[d+3]=a===255?0:255}r.push({level:n.level,width:n.width,height:n.height,rgba:i})}return{width:t.width,height:t.height,levels:r,source:"wal"}}function ba(t){let e=ya(t),r={level:0,width:t.width,height:t.height,rgba:e};return{width:t.width,height:t.height,levels:[r],source:"pcx"}}function Nd(t){let e={level:0,width:t.width,height:t.height,rgba:t.pixels};return{width:t.width,height:t.height,levels:[e],source:"tga"}}function xa(t,e){return xl(ga(t),e)}var Kr=class extends Error{constructor(e){super(e),this.name="WavParseError"}};function _l(t,e,r){return new TextDecoder("ascii").decode(new Uint8Array(t.buffer,t.byteOffset+e,r))}function _a(t){if(t.byteLength<44)throw new Kr("WAV buffer too small");let e=new DataView(t);if(_l(e,0,4)!=="RIFF"||_l(e,8,4)!=="WAVE")throw new Kr("Invalid WAV header");let r=12,n=-1,i=-1,s=0,a=0;for(;r+8<=t.byteLength;){let m=_l(e,r,4),g=e.getUint32(r+4,!0),p=r+8;m==="fmt "?(n=p,s=g):m==="data"&&(i=p,a=g),r=p+g}if(n===-1||i===-1)throw new Kr("Missing fmt or data chunk");let o=e.getUint16(n,!0),d=e.getUint16(n+2,!0),l=e.getUint32(n+4,!0),c=e.getUint16(n+14,!0);if(o!==1)throw new Kr("Only PCM WAV is supported");let f=c/8,u=a/(f*d),h=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*f,_=0;if(c===8)_=e.getUint8(y),h[p]=(_-128)/128;else if(c===16)_=e.getInt16(y,!0),h[p]=_/32768;else if(c===24){let x=e.getUint8(y),b=e.getUint8(y+1),v=e.getInt8(y+2);_=x|b<<8|v<<16,h[p]=_/8388608}else throw new Kr(`Unsupported bitsPerSample: ${c}`)}return{sampleRate:l,channels:d,bitsPerSample:c,samples:h}}var bm=(t,e=4294967295,r=79764919)=>{let n=new Int32Array(256),i,s,a,o=e;for(i=0;i<256;i++){for(a=i<<24,s=8;s>0;--s)a=2147483648&a?a<<1^r:a<<1;n[i]=a}for(i=0;i<t.length;i++)o=o<<8^n[255&(o>>24^t[i])];return o};var vl=(t,e=bm)=>{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(t.length),a,o,d,l=!1,c=0,f=42,u=t.length>13&&t.substring(0,9)==="dynEncode",h=0;u&&(h=11,o=n(t.substring(9,h)),o<=1&&(h+=2,f=n(t.substring(11,h))),o===1&&(h+=8,d=(p=>new DataView(r(p).buffer).getInt32(0,!0))(t.substring(13,h))));let m=256-f;for(let p=h;p<t.length;p++)if(a=t.charCodeAt(p),a!==61||l){if(a===92&&p<t.length-5&&u){let y=t.charCodeAt(p+1);y!==117&&y!==85||(a=parseInt(t.substring(p+2,p+6),16),p+=5)}if(a>255){let y=i.get(a);y&&(a=y+127)}l&&(l=!1,a-=64),s[c++]=a<f&&a>0?a+m:a-f}else l=!0;let g=s.subarray(0,c);if(u&&o===1){let p=e(g);if(p!==d){let y="Decode failed crc32 validation";throw console.error("`simple-yenc`\n",y+`
|
|
1
|
+
"use strict";var Quake2Engine=(()=>{var Gh=Object.create;var ta=Object.defineProperty;var Vh=Object.getOwnPropertyDescriptor;var Wh=Object.getOwnPropertyNames;var Xh=Object.getPrototypeOf,Kh=Object.prototype.hasOwnProperty;var $h=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),$o=(t,e)=>{for(var r in e)ta(t,r,{get:e[r],enumerable:!0})},nd=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Wh(e))!Kh.call(t,i)&&i!==r&&ta(t,i,{get:()=>e[i],enumerable:!(n=Vh(e,i))||n.enumerable});return t};var Zh=(t,e,r)=>(r=t!=null?Gh(Xh(t)):{},nd(e||!t||!t.__esModule?ta(r,"default",{value:t,enumerable:!0}):r,t)),Yh=t=>nd(ta({},"__esModule",{value:!0}),t);var Hd=$h((J_,Ud)=>{"use strict";Ud.exports=Worker});var ex={};$o(ex,{ATTN_IDLE:()=>ol,ATTN_LOOP_NONE:()=>sl,ATTN_NONE:()=>wi,ATTN_NORM:()=>al,ATTN_STATIC:()=>ll,AssetDependencyError:()=>on,AssetDependencyTracker:()=>As,AssetManager:()=>Ja,AssetPreviewGenerator:()=>Xo,AudioApi:()=>Ln,AudioContextController:()=>eo,AudioOcclusion:()=>Es,AudioRegistry:()=>Qn,AudioRegistryError:()=>vs,AudioSystem:()=>oo,BSP_SURFACE_FRAGMENT_SOURCE:()=>Zl,BSP_SURFACE_VERTEX_SOURCE:()=>$l,BSP_VERTEX_LAYOUT:()=>Wl,BspLoader:()=>In,BspParseError:()=>Q,BspSurfacePipeline:()=>ho,Camera:()=>bo,Command:()=>bi,CommandRegistry:()=>xn,ConfigStringRegistry:()=>Tn,Cvar:()=>Si,CvarRegistry:()=>Mn,DemoAnalyzer:()=>pi,DemoCameraMode:()=>Kc,DemoClipper:()=>Wo,DemoEventType:()=>Xc,DemoPlaybackController:()=>Gt,DemoReader:()=>je,DemoRecorder:()=>Ys,DemoValidator:()=>Ho,DynamicLightManager:()=>fo,EngineHost:()=>En,EngineRuntime:()=>Ai,FileType:()=>$c,FixedTimestepLoop:()=>Hr,Framebuffer:()=>co,IndexBuffer:()=>_e,LruCache:()=>Kt,MAX_SOUND_CHANNELS:()=>vi,MD2_FRAGMENT_SHADER:()=>tc,MD2_VERTEX_SHADER:()=>ec,MD3_FRAGMENT_SHADER:()=>dc,MD3_VERTEX_SHADER:()=>cc,MapAnalyzer:()=>Ko,Md2Loader:()=>kn,Md2MeshBuffers:()=>po,Md2ParseError:()=>ye,Md2Pipeline:()=>go,Md3Loader:()=>Rn,Md3ModelMesh:()=>xo,Md3ParseError:()=>Ve,Md3Pipeline:()=>_o,Md3SurfaceMesh:()=>Ts,MessageWriter:()=>yn,MusicSystem:()=>lo,NetworkMessageParser:()=>it,PARTICLE_FRAGMENT_SHADER:()=>fc,PARTICLE_VERTEX_SHADER:()=>uc,PROTOCOL_VERSION_RERELEASE:()=>mi,PakArchive:()=>Cn,PakIndexStore:()=>Qa,PakIngestionError:()=>Xt,PakParseError:()=>fe,PakValidationError:()=>Wr,PakValidator:()=>fa,PakWriter:()=>ca,ParticleRenderer:()=>wo,ParticleSystem:()=>vo,PlaybackState:()=>Uo,RERELEASE_KNOWN_PAKS:()=>hl,ResourceLoadTracker:()=>da,ResourceType:()=>fl,SKYBOX_FRAGMENT_SHADER:()=>Ql,SKYBOX_VERTEX_SHADER:()=>jl,SOUND_FULLVOLUME:()=>Sn,SOUND_LOOP_ATTENUATE:()=>cl,ShaderProgram:()=>Te,SkyboxPipeline:()=>mo,SoundChannel:()=>at,SoundPrecache:()=>no,SoundRegistry:()=>ro,SpriteLoader:()=>Pn,SpriteParseError:()=>$t,StreamingPakArchive:()=>la,Texture2D:()=>Jn,TextureCache:()=>Fn,TextureCubeMap:()=>ei,TgaParseError:()=>Mt,U_ALPHA:()=>Er,U_ANGLE1:()=>Ar,U_ANGLE2:()=>xr,U_ANGLE3:()=>_r,U_EFFECTS16:()=>wt,U_EFFECTS8:()=>xt,U_EVENT:()=>wr,U_FRAME16:()=>Lr,U_FRAME8:()=>vr,U_INSTANCE_BITS:()=>Br,U_LOOP_ATTENUATION_HIGH:()=>Or,U_LOOP_VOLUME:()=>Dr,U_MODEL:()=>Mr,U_MODEL2:()=>Tr,U_MODEL3:()=>Cr,U_MODEL4:()=>Ir,U_OLDORIGIN:()=>kr,U_OLD_FRAME_HIGH:()=>Nr,U_ORIGIN1:()=>yr,U_ORIGIN2:()=>br,U_ORIGIN3:()=>Sr,U_OWNER_HIGH:()=>zr,U_REMOVE:()=>Zs,U_RENDERFX16:()=>vt,U_RENDERFX8:()=>bt,U_SCALE:()=>Fr,U_SKIN16:()=>St,U_SKIN8:()=>_t,U_SOLID:()=>Pr,U_SOUND:()=>Rr,VertexArray:()=>Pe,VertexBuffer:()=>Ce,VirtualFileSystem:()=>ua,advanceAnimation:()=>Bd,applyEntityDelta:()=>Vo,applySurfaceState:()=>Cu,attenuationToDistanceMultiplier:()=>An,boxIntersectsFrustum:()=>Ls,buildBspGeometry:()=>wu,buildMd2Geometry:()=>rc,buildMd2VertexData:()=>nc,buildMd3SurfaceGeometry:()=>oc,buildMd3VertexData:()=>lc,calculateMaxAudibleDistance:()=>Vr,calculatePakChecksum:()=>_d,captureRenderTarget:()=>Nh,computeFrameBlend:()=>Dd,computeSkyScroll:()=>Ru,createAnimationState:()=>Od,createAudioGraph:()=>to,createBspSurfaces:()=>vu,createEmptyEntityState:()=>Ht,createEmptyProtocolPlayerState:()=>gn,createEngine:()=>Jb,createEngineRuntime:()=>yd,createFaceLightmap:()=>ma,createHeadlessRenderTarget:()=>zh,createInitialChannels:()=>io,createOcclusionResolver:()=>yu,createProgramFromSources:()=>_u,createWebGLContext:()=>bu,createWebGPUContext:()=>Dh,decodeOgg:()=>ja,deriveSurfaceRenderState:()=>ql,detectFileType:()=>Zc,extractFrustumPlanes:()=>Su,filesToPakSources:()=>ml,findLeafForPoint:()=>Kl,gatherVisibleFaces:()=>Lu,groupMd2Animations:()=>kd,ingestPakFiles:()=>Ad,ingestPaks:()=>ha,interpolateMd3Tag:()=>qu,interpolateVec3:()=>zd,isBinaryFile:()=>kh,isTextFile:()=>Yc,parseBsp:()=>Mi,parseEntLump:()=>Ph,parseMd2:()=>pl,parseMd3:()=>gl,parsePcx:()=>Ci,parseSprite:()=>yl,parseTga:()=>bl,parseWal:()=>ga,parseWalTexture:()=>xa,parseWav:()=>_a,pcxToRgba:()=>ya,pickChannel:()=>so,preparePcxTexture:()=>ba,queryCapabilities:()=>Oh,removeViewTranslation:()=>ku,resolveLightStyles:()=>Yl,serializeEntLump:()=>Fh,spawnBfgExplosion:()=>cf,spawnBlasterImpact:()=>lf,spawnBlood:()=>Ju,spawnBulletImpact:()=>ju,spawnExplosion:()=>Qu,spawnMuzzleFlash:()=>tf,spawnRailTrail:()=>af,spawnSparks:()=>of,spawnSplash:()=>nf,spawnSteam:()=>sf,spawnTeleportFlash:()=>ef,spawnTrail:()=>rf,validateEntity:()=>Bh,walToRgba:()=>xl,wireDropTarget:()=>Md,wireFileInput:()=>Ed});var qh=()=>typeof performance<"u"?performance.now():Date.now(),jh=t=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>t()):setTimeout(t,25)},Hr=class{constructor(e,r={}){this.callbacks=e;this.accumulatorMs=0;this.frame=0;this.running=!1;this.tick=()=>{if(!this.running)return;let e=this.options.now(),r=this.lastTimeMs===void 0?0:e-this.lastTimeMs;this.lastTimeMs=e,this.advance(r,e),this.running&&this.options.schedule(this.tick)};let n=r.fixedDeltaMs??25,i=r.maxSubSteps??5;this.options={fixedDeltaMs:n,maxSubSteps:i,maxDeltaMs:r.maxDeltaMs??n*i,startTimeMs:r.startTimeMs,now:r.now??qh,schedule:r.schedule??jh}}start(){this.running||(this.running=!0,this.lastTimeMs=this.options.startTimeMs??this.options.now(),this.options.schedule(this.tick))}stop(){this.running=!1}pump(e){let r=(this.lastTimeMs??0)+e;this.lastTimeMs=r,this.advance(e,r)}isRunning(){return this.running}get frameNumber(){return this.frame}advance(e,r){let n=Math.min(Math.max(e,0),this.options.maxDeltaMs);this.accumulatorMs=Math.min(this.accumulatorMs+n,this.options.fixedDeltaMs*this.options.maxSubSteps);let i=0;for(;this.accumulatorMs>=this.options.fixedDeltaMs&&i<this.options.maxSubSteps;)this.frame+=1,this.callbacks.simulate({frame:this.frame,deltaMs:this.options.fixedDeltaMs,nowMs:r}),this.accumulatorMs-=this.options.fixedDeltaMs,i+=1;let 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 bi=class{constructor(e,r,n){this.name=e,this.callback=r,this.description=n}execute(e){this.callback(e)}},xn=class{constructor(){this.commands=new Map;this.history=[];this.historyLimit=64;this.autocompleteProviders=[]}register(e,r,n){let i=new bi(e,r,n);return this.commands.set(e,i),i}registerCommand(e,r){this.register(e,r)}registerAutocompleteProvider(e){this.autocompleteProviders.push(e)}get(e){return this.commands.get(e)}execute(e){let r=e.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(e);if(n.length===0)return!1;let i=n[0],s=n.slice(1),a=this.get(i);return a?(a.execute(s),!0):(this.onConsoleOutput?.(`Unknown command "${i}"`),!1)}executeCommand(e){this.execute(e)}getHistory(){return[...this.history]}getSuggestions(e){let r=new Set;for(let n of this.commands.keys())n.startsWith(e)&&r.add(n);for(let n of this.autocompleteProviders){let i=n();for(let s of i)s.startsWith(e)&&r.add(s)}return Array.from(r).sort()}tokenize(e){let r=[],n="",i=!1;for(let s=0;s<e.length;s++){let a=e[s];a==='"'?i=!i:a===" "&&!i?n.length>0&&(r.push(n),n=""):n+=a}return n.length>0&&r.push(n),r}list(){return[...this.commands.values()].sort((e,r)=>e.name.localeCompare(r.name))}};var Qh=Object.defineProperty,Jh=(t,e)=>{for(var r in e)Qh(t,r,{get:e[r],enumerable:!0})},id={x:0,y:0,z:0};var ix=Math.PI/180;function sd(t,e){return{x:t.x-e.x,y:t.y-e.y,z:t.z-e.z}}function e0(t,e){return{x:t.x*e,y:t.y*e,z:t.z*e}}function t0(t,e){return t.x*e.x+t.y*e.y+t.z*e.z}function r0(t){return t0(t,t)}function Yo(t){return Math.sqrt(r0(t))}function At(t){let e=Yo(t);return e===0?t:e0(t,1/e)}var n0=Math.PI/180,i0=180/Math.PI,vn=n0,qo=i0;var Vt=[[-.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 s0(){return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function ad(t,e){let r=e.x,n=e.y,i=e.z;return{x:t[0]*r+t[4]*n+t[8]*i+t[12],y:t[1]*r+t[5]*n+t[9]*i+t[13],z:t[2]*r+t[6]*n+t[10]*i+t[14]}}function od(t,e){let r=s0();return r[0]=e[0].x,r[1]=e[0].y,r[2]=e[0].z,r[4]=e[1].x,r[5]=e[1].y,r[6]=e[1].z,r[8]=e[2].x,r[9]=e[2].y,r[10]=e[2].z,r[12]=t.x,r[13]=t.y,r[14]=t.z,r}var st=1,Wt=2;var jo=8,Qo=16,a0=32;var o0=16384;var ra=65536,ld=1<<17,l0=1<<18,c0=1<<19,d0=1<<20,u0=1<<21,f0=1<<22,h0=1<<23,sx=1<<24,na=1<<25,m0=1<<26,ax=1<<27,ox=1<<28,lx=1<<29,ia=1<<30,cx=1<<31;var _i=0;var cd=4,dd=8,ud=16,fd=32,hd=64;var dx=1<<25,ux=1<<28,fx=1<<29,hx=1<<30,mx=1<<31;var px=st|Wt,gx=st|ra|Wt|na|ia,yx=st|ra|Wt,bx=st|ld|Wt|na|ia,xx=a0|jo|Qo,_x=st|Qo|jo,p0=st|na|ia|Wt|m0,vx=l0|c0|d0|u0|f0|h0,wx=st|jo|Qo|na|ia,Sx=st|ra|Wt,Ax=st|Wt,Mx=st|ra|Wt|ld,Ex=p0|o0;var Lx=Number.MAX_SAFE_INTEGER-1;var sa=(t=>(t[t.None=0]="None",t[t.Archive=1]="Archive",t[t.UserInfo=2]="UserInfo",t[t.ServerInfo=4]="ServerInfo",t[t.Latch=8]="Latch",t[t.Cheat=16]="Cheat",t))(sa||{});var aa=256;var Jo=256,el=8192,oa=2048,tl=512,rl=256,nl=aa*2,il=256,Zo=32,xi=96;var X=(t=>(t[t.Name=0]="Name",t[t.CdTrack=1]="CdTrack",t[t.Sky=2]="Sky",t[t.SkyAxis=3]="SkyAxis",t[t.SkyRotate=4]="SkyRotate",t[t.StatusBar=5]="StatusBar",t[t.HealthBarName=55]="HealthBarName",t[t.CONFIG_N64_PHYSICS=56]="CONFIG_N64_PHYSICS",t[t.CONFIG_CTF_TEAMS=57]="CONFIG_CTF_TEAMS",t[t.CONFIG_COOP_RESPAWN_STRING=58]="CONFIG_COOP_RESPAWN_STRING",t[t.Story=54]="Story",t[t.AirAccel=59]="AirAccel",t[t.MaxClients=60]="MaxClients",t[t.MapChecksum=61]="MapChecksum",t[t.Models=62]="Models",t[t.Sounds=62+el]="Sounds",t[t.Images=t.Sounds+oa]="Images",t[t.Lights=t.Images+tl]="Lights",t[t.ShadowLights=t.Lights+Jo]="ShadowLights",t[t.Items=t.ShadowLights+il]="Items",t[t.Players=t.Items+rl]="Players",t[t.PlayerSkins=t.Players]="PlayerSkins",t[t.General=t.Players+aa]="General",t[t.WheelWeapons=t.General+nl]="WheelWeapons",t[t.WheelAmmo=t.WheelWeapons+Zo]="WheelAmmo",t[t.WheelPowerups=t.WheelAmmo+Zo]="WheelPowerups",t[t.CdLoopCount=t.WheelPowerups+Zo]="CdLoopCount",t[t.GameStyle=t.CdLoopCount+1]="GameStyle",t[t.MaxConfigStrings=t.GameStyle+1]="MaxConfigStrings",t))(X||{}),md=X.MaxConfigStrings;function pd(t){return t>=5&&t<59?xi*(59-t):t>=X.General&&t<X.WheelWeapons?xi*(X.MaxConfigStrings-t):xi}var Tx=X.Sounds,Cx=X.Images,Ix=X.Lights,kx=X.Items,Rx=X.Players,Px=X.General,g0={};Jh(g0,{addReplayFrame:()=>_0,createReplaySession:()=>x0,deserializeReplay:()=>b0,serializeReplay:()=>y0});function y0(t){return JSON.stringify(t,null,2)}function b0(t){let e=JSON.parse(t);if(!e.metadata||!Array.isArray(e.frames))throw new Error("Invalid replay format: missing metadata or frames");return e}function x0(t,e){return{metadata:{map:t,date:new Date().toISOString(),version:"1.0",seed:e},frames:[]}}function _0(t,e,r,n){t.frames.push({serverFrame:r,cmd:e,timestamp:Date.now()-n})}var M=(t=>(t[t.bad=0]="bad",t[t.muzzleflash=1]="muzzleflash",t[t.muzzleflash2=2]="muzzleflash2",t[t.temp_entity=3]="temp_entity",t[t.layout=4]="layout",t[t.inventory=5]="inventory",t[t.nop=6]="nop",t[t.disconnect=7]="disconnect",t[t.reconnect=8]="reconnect",t[t.sound=9]="sound",t[t.print=10]="print",t[t.stufftext=11]="stufftext",t[t.serverdata=12]="serverdata",t[t.configstring=13]="configstring",t[t.spawnbaseline=14]="spawnbaseline",t[t.centerprint=15]="centerprint",t[t.download=16]="download",t[t.playerinfo=17]="playerinfo",t[t.packetentities=18]="packetentities",t[t.deltapacketentities=19]="deltapacketentities",t[t.frame=20]="frame",t[t.splitclient=21]="splitclient",t[t.configblast=22]="configblast",t[t.spawnbaselineblast=23]="spawnbaselineblast",t[t.level_restart=24]="level_restart",t[t.damage=25]="damage",t[t.locprint=26]="locprint",t[t.fog=27]="fog",t[t.waitingforplayers=28]="waitingforplayers",t[t.bot_chat=29]="bot_chat",t[t.poi=30]="poi",t[t.help_path=31]="help_path",t[t.muzzleflash3=32]="muzzleflash3",t[t.achievement=33]="achievement",t))(M||{});var E=(t=>(t[t.GUNSHOT=0]="GUNSHOT",t[t.BLOOD=1]="BLOOD",t[t.BLASTER=2]="BLASTER",t[t.RAILTRAIL=3]="RAILTRAIL",t[t.SHOTGUN=4]="SHOTGUN",t[t.EXPLOSION1=5]="EXPLOSION1",t[t.EXPLOSION2=6]="EXPLOSION2",t[t.ROCKET_EXPLOSION=7]="ROCKET_EXPLOSION",t[t.GRENADE_EXPLOSION=8]="GRENADE_EXPLOSION",t[t.SPARKS=9]="SPARKS",t[t.SPLASH=10]="SPLASH",t[t.BUBBLETRAIL=11]="BUBBLETRAIL",t[t.SCREEN_SPARKS=12]="SCREEN_SPARKS",t[t.SHIELD_SPARKS=13]="SHIELD_SPARKS",t[t.BULLET_SPARKS=14]="BULLET_SPARKS",t[t.LASER_SPARKS=15]="LASER_SPARKS",t[t.PARASITE_ATTACK=16]="PARASITE_ATTACK",t[t.ROCKET_EXPLOSION_WATER=17]="ROCKET_EXPLOSION_WATER",t[t.GRENADE_EXPLOSION_WATER=18]="GRENADE_EXPLOSION_WATER",t[t.MEDIC_CABLE_ATTACK=19]="MEDIC_CABLE_ATTACK",t[t.BFG_EXPLOSION=20]="BFG_EXPLOSION",t[t.BFG_BIGEXPLOSION=21]="BFG_BIGEXPLOSION",t[t.BOSSTPORT=22]="BOSSTPORT",t[t.BFG_LASER=23]="BFG_LASER",t[t.GRAPPLE_CABLE=24]="GRAPPLE_CABLE",t[t.WELDING_SPARKS=25]="WELDING_SPARKS",t[t.GREENBLOOD=26]="GREENBLOOD",t[t.BLUEHYPERBLASTER=27]="BLUEHYPERBLASTER",t[t.PLASMA_EXPLOSION=28]="PLASMA_EXPLOSION",t[t.TUNNEL_SPARKS=29]="TUNNEL_SPARKS",t[t.BLASTER2=30]="BLASTER2",t[t.RAILTRAIL2=31]="RAILTRAIL2",t[t.FLAME=32]="FLAME",t[t.LIGHTNING=33]="LIGHTNING",t[t.DEBUGTRAIL=34]="DEBUGTRAIL",t[t.PLAIN_EXPLOSION=35]="PLAIN_EXPLOSION",t[t.FLASHLIGHT=36]="FLASHLIGHT",t[t.FORCEWALL=37]="FORCEWALL",t[t.HEATBEAM=38]="HEATBEAM",t[t.MONSTER_HEATBEAM=39]="MONSTER_HEATBEAM",t[t.STEAM=40]="STEAM",t[t.BUBBLETRAIL2=41]="BUBBLETRAIL2",t[t.MOREBLOOD=42]="MOREBLOOD",t[t.HEATBEAM_SPARKS=43]="HEATBEAM_SPARKS",t[t.HEATBEAM_STEAM=44]="HEATBEAM_STEAM",t[t.CHAINFIST_SMOKE=45]="CHAINFIST_SMOKE",t[t.ELECTRIC_SPARKS=46]="ELECTRIC_SPARKS",t[t.TRACKER_EXPLOSION=47]="TRACKER_EXPLOSION",t[t.TELEPORT_EFFECT=48]="TELEPORT_EFFECT",t[t.DBALL_GOAL=49]="DBALL_GOAL",t[t.WIDOWBEAMOUT=50]="WIDOWBEAMOUT",t[t.NUKEBLAST=51]="NUKEBLAST",t[t.WIDOWSPLASH=52]="WIDOWSPLASH",t[t.EXPLOSION1_BIG=53]="EXPLOSION1_BIG",t[t.EXPLOSION1_NP=54]="EXPLOSION1_NP",t[t.FLECHETTE=55]="FLECHETTE",t[t.BLUEHYPERBLASTER_KEX=56]="BLUEHYPERBLASTER_KEX",t[t.BFG_ZAP=57]="BFG_ZAP",t[t.BERSERK_SLAM=58]="BERSERK_SLAM",t[t.GRAPPLE_CABLE_2=59]="GRAPPLE_CABLE_2",t[t.POWER_SPLASH=60]="POWER_SPLASH",t[t.LIGHTNING_BEAM=61]="LIGHTNING_BEAM",t[t.EXPLOSION1_NL=62]="EXPLOSION1_NL",t[t.EXPLOSION2_NL=63]="EXPLOSION2_NL",t))(E||{});var v0=12,w0=9,Fx=Math.ceil(v0*w0/16),S0=23,A0=2,Bx=Math.ceil(S0*A0/16);var Dx=1<<17,Ox=1<<18,zx=1<<19,Nx=1<<20,Ux=1<<21,Hx=1<<22,Gx=1<<23,Vx=1<<24,Wx=1<<25,Xx=1<<26,Kx=1<<27,$x=1<<28,Zx=1<<29,Yx=1<<30;var wn=class{constructor(t){t instanceof Uint8Array?this.view=new DataView(t.buffer,t.byteOffset,t.byteLength):this.view=new DataView(t),this.offset=0,this.length=this.view.byteLength}getPosition(){return this.offset}getReadPosition(){return this.offset}getLength(){return this.length}getRemaining(){return this.length-this.offset}seek(t){if(t<0||t>this.length)throw new Error(`Seek out of bounds: ${t} (length: ${this.length})`);this.offset=t}setReadPosition(t){this.seek(t)}hasMore(){return this.offset<this.length}hasBytes(t){return this.offset+t<=this.length}readChar(){let t=this.view.getInt8(this.offset);return this.offset+=1,t}readByte(){let t=this.view.getUint8(this.offset);return this.offset+=1,t}readShort(){let t=this.view.getInt16(this.offset,!0);return this.offset+=2,t}readUShort(){let t=this.view.getUint16(this.offset,!0);return this.offset+=2,t}readLong(){let t=this.view.getInt32(this.offset,!0);return this.offset+=4,t}readULong(){let t=this.view.getUint32(this.offset,!0);return this.offset+=4,t}readFloat(){let t=this.view.getFloat32(this.offset,!0);return this.offset+=4,t}readString(){let t="";for(;this.offset<this.length;){let e=this.readChar();if(e===-1||e===0)break;t+=String.fromCharCode(e)}return t}readStringLine(){let t="";for(;this.offset<this.length;){let e=this.readChar();if(e===-1||e===0||e===10)break;t+=String.fromCharCode(e)}return t}readCoord(){return this.readShort()*(1/8)}readAngle(){return this.readChar()*(360/256)}readAngle16(){return this.readShort()*360/65536}readData(t){if(this.offset+t>this.length)throw new Error(`Read out of bounds: ${this.offset+t} (length: ${this.length})`);let e=new Uint8Array(this.view.buffer,this.view.byteOffset+this.offset,t);return this.offset+=t,new Uint8Array(e)}readPos(t){t.x=this.readCoord(),t.y=this.readCoord(),t.z=this.readCoord()}readDir(t){let e=this.readByte();if(e>=162){t.x=0,t.y=0,t.z=0;return}let r=Vt[e];t.x=r[0],t.y=r[1],t.z=r[2]}},Gr=class{constructor(t=1400){typeof t=="number"?(this.buffer=new Uint8Array(t),this.fixed=!1):(this.buffer=t,this.fixed=!0),this.view=new DataView(this.buffer.buffer,this.buffer.byteOffset,this.buffer.byteLength),this.offset=0}ensureSpace(t){if(this.offset+t>this.buffer.byteLength){if(this.fixed)throw new Error(`Buffer overflow: capacity ${this.buffer.byteLength}, needed ${this.offset+t}`);let e=Math.max(this.buffer.byteLength*2,this.offset+t),r=new Uint8Array(e);r.set(this.buffer),this.buffer=r,this.view=new DataView(this.buffer.buffer,this.buffer.byteOffset,this.buffer.byteLength)}}writeByte(t){this.ensureSpace(1),this.view.setUint8(this.offset,t),this.offset+=1}writeBytes(t){this.ensureSpace(t.byteLength),this.buffer.set(t,this.offset),this.offset+=t.byteLength}writeChar(t){this.ensureSpace(1),this.view.setInt8(this.offset,t),this.offset+=1}writeShort(t){this.ensureSpace(2),this.view.setInt16(this.offset,t,!0),this.offset+=2}writeLong(t){this.ensureSpace(4),this.view.setInt32(this.offset,t,!0),this.offset+=4}writeFloat(t){this.ensureSpace(4),this.view.setFloat32(this.offset,t,!0),this.offset+=4}writeString(t){let e=t.length;this.ensureSpace(e+1);for(let r=0;r<e;r++)this.view.setUint8(this.offset+r,t.charCodeAt(r));this.view.setUint8(this.offset+e,0),this.offset+=e+1}writeCoord(t){this.writeShort(Math.trunc(t*8))}writeAngle(t){this.writeByte(Math.trunc(t*256/360)&255)}writeAngle16(t){this.writeShort(Math.trunc(t*65536/360)&65535)}writePos(t){this.writeCoord(t.x),this.writeCoord(t.y),this.writeCoord(t.z)}writeDir(t){let e=-1,r=0;if(t.x===0&&t.y===0&&t.z===0){this.writeByte(0);return}for(let n=0;n<Vt.length;n++){let i=Vt[n],s=t.x*i[0]+t.y*i[1]+t.z*i[2];s>e&&(e=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 _n=class ge{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 Gr(ge.MAX_RELIABLE_BUFFER);let e=Date.now();this.lastReceived=e,this.lastSent=e,this.qport=Math.floor(Math.random()*65536)}setup(e,r=null){this.qport=e,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(e){this.outgoingSequence++,this.lastSent=Date.now();let r=0,n=!1,i=0;this.reliableLength>0&&(this.reliableLength>ge.FRAGMENT_SIZE?(n=!0,this.fragmentSendOffset>=this.reliableLength&&(this.fragmentSendOffset=0),r=this.reliableLength-this.fragmentSendOffset,r>ge.FRAGMENT_SIZE&&(r=ge.FRAGMENT_SIZE),i=this.fragmentSendOffset,this.fragmentSendOffset+=r):r=this.reliableLength);let s=ge.PACKET_HEADER,a=r>0?2+(n?8:0):0,o=e?e.length:0;s+a+r+o>ge.MAX_MSGLEN&&(o=ge.MAX_MSGLEN-s-a-r,o<0&&(o=0));let d=new ArrayBuffer(s+a+r+o),l=new DataView(d),c=new Uint8Array(d),f=this.outgoingSequence;r>0&&(f|=2147483648,(this.outgoingReliableSequence&1)!==0&&(f|=1073741824)),l.setUint32(0,f,!0);let u=this.incomingSequence;(this.incomingReliableSequence&1)!==0&&(u|=2147483648),l.setUint32(4,u,!0),l.setUint16(8,this.qport,!0);let h=s;if(r>0){let m=r;n&&(m|=32768),l.setUint16(h,m,!0),h+=2,n&&(l.setUint32(h,i,!0),h+=4,l.setUint32(h,this.reliableLength,!0),h+=4);let p=this.reliableMessage.getBuffer().subarray(i,i+r);c.set(p,h),h+=r}if(e&&o>0){let m=e.slice(0,o);c.set(m,h)}return c}process(e){if(e.length<ge.PACKET_HEADER)return null;this.lastReceived=Date.now();let r=new DataView(e.buffer,e.byteOffset,e.byteLength),n=r.getUint32(0,!0),i=r.getUint32(4,!0),s=r.getUint16(8,!0);if(this.qport!==s)return null;let a=n&1073741823;if((a-this.incomingSequence|0)<=0)return null;this.incomingSequence=a;let o=i&2147483647,d=(i&2147483648)!==0;if(o>this.incomingAcknowledged&&(this.incomingAcknowledged=o),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,f=ge.PACKET_HEADER,u=null;if(l){if(f+2>e.byteLength)return null;let m=r.getUint16(f,!0);f+=2;let g=(m&32768)!==0;m&=32767;let p=this.incomingReliableSequence&1;if(c===p)if(g){if(f+8>e.byteLength)return null;let y=r.getUint32(f,!0);f+=4;let _=r.getUint32(f,!0);if(f+=4,_>ge.MAX_RELIABLE_BUFFER)return console.warn(`NetChan: received invalid fragment total ${_} > ${ge.MAX_RELIABLE_BUFFER}`),null;if((!this.fragmentBuffer||this.fragmentBuffer.length!==_)&&(this.fragmentBuffer=new Uint8Array(_),this.fragmentLength=_,this.fragmentReceived=0),f+m>e.byteLength)return null;let x=e.subarray(f,f+m);y===this.fragmentReceived&&y+m<=_&&(this.fragmentBuffer.set(x,y),this.fragmentReceived+=m,this.fragmentReceived>=_&&(u=this.fragmentBuffer,this.incomingReliableSequence++,this.fragmentBuffer=null,this.fragmentLength=0,this.fragmentReceived=0))}else{if(this.incomingReliableSequence++,f+m>e.byteLength)return null;u=e.slice(f,f+m)}f+=m}let h=e.slice(f);if(u&&u.length>0){let m=u.length+h.length,g=new Uint8Array(m);return g.set(u,0),g.set(h,u.length),g}return h||new Uint8Array(0)}canSendReliable(){return this.reliableLength===0}writeReliableByte(e){if(this.reliableLength+1>ge.MAX_RELIABLE_BUFFER)throw new Error("NetChan reliable buffer overflow");this.reliableMessage.writeByte(e),this.reliableLength++}writeReliableShort(e){if(this.reliableLength+2>ge.MAX_RELIABLE_BUFFER)throw new Error("NetChan reliable buffer overflow");this.reliableMessage.writeShort(e),this.reliableLength+=2}writeReliableLong(e){if(this.reliableLength+4>ge.MAX_RELIABLE_BUFFER)throw new Error("NetChan reliable buffer overflow");this.reliableMessage.writeLong(e),this.reliableLength+=4}writeReliableString(e){let r=e.length+1;if(this.reliableLength+r>ge.MAX_RELIABLE_BUFFER)throw new Error("NetChan reliable buffer overflow");this.reliableMessage.writeString(e),this.reliableLength+=r}getReliableData(){return this.reliableLength===0?new Uint8Array(0):this.reliableMessage.getBuffer().subarray(0,this.reliableLength)}needsKeepalive(e){return e-this.lastSent>1e3}isTimedOut(e,r=3e4){return e-this.lastReceived>r}};_n.MAX_MSGLEN=1400;_n.FRAGMENT_SIZE=1024;_n.PACKET_HEADER=10;_n.HEADER_OVERHEAD=_n.PACKET_HEADER+2;_n.MAX_RELIABLE_BUFFER=262144;var gd=(t=>(t[t.Bullets=0]="Bullets",t[t.Shells=1]="Shells",t[t.Rockets=2]="Rockets",t[t.Grenades=3]="Grenades",t[t.Cells=4]="Cells",t[t.Slugs=5]="Slugs",t[t.MagSlugs=6]="MagSlugs",t[t.Trap=7]="Trap",t[t.Flechettes=8]="Flechettes",t[t.Tesla=9]="Tesla",t[t.Disruptor=10]="Disruptor",t[t.Prox=11]="Prox",t[t.Nuke=12]="Nuke",t[t.Rounds=13]="Rounds",t))(gd||{}),qx=Object.keys(gd).length/2;var vi=32,at=(t=>(t[t.Auto=0]="Auto",t[t.Weapon=1]="Weapon",t[t.Voice=2]="Voice",t[t.Item=3]="Item",t[t.Body=4]="Body",t[t.Aux=5]="Aux",t[t.Footstep=6]="Footstep",t[t.Aux3=7]="Aux3",t[t.NoPhsAdd=8]="NoPhsAdd",t[t.Reliable=16]="Reliable",t[t.ForcePos=32]="ForcePos",t))(at||{}),sl=-1,wi=0,al=1,ol=2,ll=3,Sn=80,cl=.003;function An(t){return t*.001}function Vr(t){let e=An(t);return e<=0?Number.POSITIVE_INFINITY:Sn+1/e}var Si=class{constructor({name:e,defaultValue:r,description:n,flags:i=sa.None,onChange:s}){this.modifiedCount=0;this.name=e,this.defaultValue=r,this.description=n,this.flags=i,this._value=r,this.onChange=s}get string(){return this._value}getString(){return this.string}get number(){return Number(this._value)}getFloat(){return this.number}get integer(){return Math.trunc(this.number)}getInt(){return this.integer}get boolean(){return!!this.integer}getBoolean(){return this.boolean}set(e){if(this.flags&sa.Latch){if(e===this._value){this.latched=void 0;return}if(this.latched===e)return;this.latched!==e&&(this.latched=e);return}this.apply(e)}reset(){this.latched=void 0,this.apply(this.defaultValue)}applyLatched(){if(this.latched===void 0)return!1;let e=this.latched;return this.latched=void 0,e===this._value?!1:(this.apply(e),!0)}apply(e){if(this._value===e)return;let r=this._value;this._value=e,this.modifiedCount+=1,this.onChange?.(this,r)}},Mn=class{constructor(){this.cvars=new Map}register(e){let r=this.cvars.get(e.name);if(r)return r;let n=e.onChange,i=(a,o)=>{n?.(a,o),this.onCvarChange?.(a.name,a.string)},s=new Si({...e,onChange:i});return this.cvars.set(e.name,s),s}get(e){return this.cvars.get(e)}getCvar(e){return this.get(e)}setValue(e,r){let n=this.get(e);if(!n)throw new Error(`Unknown cvar: ${e}`);return n.set(r),n}setCvar(e,r){this.setValue(e,r)}resetAll(){for(let e of this.cvars.values())e.reset()}applyLatched(){let e=!1;for(let r of this.cvars.values())e=r.applyLatched()||e;return e}list(){return[...this.cvars.values()].sort((e,r)=>e.name.localeCompare(r.name))}listCvars(){return this.list().map(e=>({name:e.name,value:e.string,defaultValue:e.defaultValue,flags:e.flags,description:e.description}))}};var En=class{constructor(e,r,n={}){this.game=e;this.client=r;this.started=!1;this.paused_=!1;this.commands=new xn;this.cvars=new Mn;this.stepSimulation=e=>{this.previousFrame=this.latestFrame,this.latestFrame=this.game.frame(e,this.latestCommand)};this.renderClient=e=>{this.client&&(this.latestCommand=this.client.render({...e,previous:this.previousFrame,latest:this.latestFrame}))};let i=n.loop?.now?.()??Date.now();this.startTimeMs=n.startTimeMs??n.loop?.startTimeMs??i,this.loop=new Hr({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(e){throw this.game.shutdown(),this.client?.shutdown(),e}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(e){this.paused_=e,e?this.loop.stop():this.started&&this.loop.start()}get paused(){return this.paused_}pump(e){this.loop.pump(e)}getLatestFrame(){return this.latestFrame}isRunning(){return this.loop.isRunning()}};var Ln=class{constructor(e){this.registry=e.registry,this.system=e.system,this.music=e.music,this.client=e.client}soundindex(e){return this.registry.registerName(e)}sound(e,r,n,i,s,a){this.system.play({entity:e,channel:r,soundIndex:n,volume:i,attenuation:s,timeOffsetMs:a}),this.triggerSubtitle(n)}positioned_sound(e,r,n,i){this.system.positionedSound(e,r,n,i),this.triggerSubtitle(r)}loop_sound(e,r,n,i,s){let a=this.system.play({entity:e,channel:r,soundIndex:n,volume:i,attenuation:s,looping:!0});return this.triggerSubtitle(n),a}stop_entity_sounds(e){this.system.stopEntitySounds(e)}setPlaybackRate(e){this.system.setPlaybackRate(e)}set_listener(e){this.system.setListener(e)}play_music(e,r=!0){return this.music?this.music.play(e,{loop:r}):Promise.resolve()}play_track(e,r=!0){return this.music?this.music.playTrack(e):Promise.resolve()}pause_music(){this.music?.pause()}resume_music(){return this.music?.resume()??Promise.resolve()}stop_music(){this.music?.stop()}set_music_volume(e){this.music?.setVolume(e)}play_ambient(e,r,n){this.system.ambientSound(e,r,n),this.triggerSubtitle(r)}play_channel(e){this.system.play({...e}),this.triggerSubtitle(e.soundIndex)}triggerSubtitle(e){if(!this.client)return;let r=this.registry.getName(e);if(!r)return;let n=r.match(/\[(.*?)\]/);n&&this.client.showSubtitle(n[1],r)}};var Ai=class{constructor(e,r){this.engine=e;this.host=r;this.started=!1}start(){this.started||(this.engine.init(),this.host.start(),this.started=!0)}stop(){this.started&&(this.host.stop(),this.engine.shutdown(),this.started=!1)}pump(e){this.host.pump(e)}getLatestFrame(){return this.host.getLatestFrame()}isRunning(){return this.started&&this.host.isRunning()}};function yd(t,e,r,n,i){let s=new Ln({...n,client:r}),a=new En(e,r,i);return{runtime:new Ai(t,a),audio:s}}function M0(t){if(t<0||t>=X.MaxConfigStrings)throw new RangeError(`Configstring index ${t} is out of range (0-${X.MaxConfigStrings-1})`)}function bd(t,e){let r=pd(t);if(e.length>r)throw new RangeError(`Configstring ${t} exceeds maximum length (${e.length} > ${r}); limit is ${xi} chars per slot`)}var Tn=class{constructor(){this.values=new Map;this.modelCursor=X.Models;this.soundCursor=X.Sounds;this.imageCursor=X.Images;this.lightCursor=X.Lights;this.shadowLightCursor=X.ShadowLights;this.itemCursor=X.Items;this.playerSkinCursor=X.PlayerSkins;this.generalCursor=X.General}set(e,r){return M0(e),bd(e,r),this.values.set(e,r),e}get(e){return this.values.get(e)}getName(e){return this.get(e)}getAll(){let e=new Array(md).fill("");for(let[r,n]of this.values.entries())e[r]=n;return e}modelIndex(e){return this.register(e,X.Models,el,"modelCursor")}soundIndex(e){return this.register(e,X.Sounds,oa,"soundCursor")}findSoundIndex(e){for(let r=X.Sounds;r<X.Sounds+oa;r+=1)if(this.values.get(r)===e)return r}imageIndex(e){return this.register(e,X.Images,tl,"imageCursor")}lightIndex(e){return this.register(e,X.Lights,Jo,"lightCursor")}shadowLightIndex(e){return this.register(e,X.ShadowLights,il,"shadowLightCursor")}itemIndex(e){return this.register(e,X.Items,rl,"itemCursor")}playerSkinIndex(e){return this.register(e,X.PlayerSkins,aa,"playerSkinCursor")}generalIndex(e){return this.register(e,X.General,nl,"generalCursor")}register(e,r,n,i){for(let o=r;o<r+n;o+=1)if(this.values.get(o)===e)return o;let s=this[i],a=r+n;if(s>=a)throw new RangeError(`Out of configstring slots for range starting at ${r}`);return bd(s,e),this.values.set(s,e),this[i]=s+1,s}};var E0="PACK";function L0(t,e,r){let n=[];for(let i=0;i<r;i+=1){let s=t.getUint8(e+i);if(s===0)break;n.push(s)}return String.fromCharCode(...n)}function ae(t){return t.replace(/\\/g,"/").replace(/^\/+/,"").toLowerCase()}function T0(){let t=new Uint32Array(256);for(let e=0;e<256;e+=1){let r=e;for(let n=0;n<8;n+=1)r=(r&1)!==0?3988292384^r>>>1:r>>>1;t[e]=r>>>0}return t}var C0=T0();function xd(t){let e=4294967295;for(let r=0;r<t.length;r+=1){let n=t[r];e=C0[(e^n)&255]^e>>>8}return(e^4294967295)>>>0}var fe=class extends Error{},Cn=class t{constructor(e,r,n,i){this.name=e;this.buffer=r;this.entries=new Map(n.map(s=>[s.name,s])),this.checksum=i,this.size=r.byteLength}static fromArrayBuffer(e,r){let n=new DataView(r);if(r.byteLength<12)throw new fe("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!==E0)throw new fe(`Invalid PAK header magic: ${i}`);let s=n.getInt32(4,!0),a=n.getInt32(8,!0);if(s<12)throw new fe(`Invalid directory offset: ${s}`);if(a<0||a%64!==0)throw new fe(`Invalid directory length: ${a}`);if(s+a>r.byteLength)throw new fe("Directory exceeds buffer length");let d=a/64,l=[],c=new Map;for(let f=0;f<d;f+=1){let u=s+f*64,h=L0(n,u,56),m=ae(h),g=n.getInt32(u+56,!0),p=n.getInt32(u+60,!0);if(g<0||p<0||g+p>r.byteLength)throw new fe(`Invalid entry bounds for ${h||"<unnamed>"} (offset=${g}, length=${p})`);if(!m)throw new fe(`Entry ${f} has an empty name`);let y={name:m,offset:g,length:p};c.set(m,y)}return l.push(...c.values()),new t(e,r,l,xd(new Uint8Array(r)))}getEntry(e){return this.entries.get(ae(e))}listEntries(){return Array.from(this.entries.values())}list(){return Array.from(this.entries.keys())}readFile(e){let r=this.getEntry(e);if(!r)throw new fe(`File not found in PAK: ${e}`);return new Uint8Array(this.buffer,r.offset,r.length)}validate(){return{checksum:this.checksum,entries:this.listEntries()}}};function _d(t){return xd(new Uint8Array(t))}var I0="PACK",vd=12,dl=64;function wd(t){return t.replace(/\\/g,"/").replace(/^\/+/,"").toLowerCase()}var la=class{constructor(e){this.source=e;this.entries=null}async readDirectory(){if(this.entries)return Array.from(this.entries.values());let e=await this.readChunk(0,vd),r=new DataView(e),n=String.fromCharCode(r.getUint8(0),r.getUint8(1),r.getUint8(2),r.getUint8(3));if(n!==I0)throw new fe(`Invalid PAK header magic: ${n}`);let i=r.getInt32(4,!0),s=r.getInt32(8,!0);if(i<vd)throw new fe(`Invalid directory offset: ${i}`);if(s<0||s%dl!==0)throw new fe(`Invalid directory length: ${s}`);let a=await this.readChunk(i,s),o=new DataView(a),d=s/dl,l=new Map;for(let c=0;c<d;c++){let f=c*dl,u=this.readCString(o,f,56),h=wd(u),m=o.getInt32(f+56,!0),g=o.getInt32(f+60,!0);m<0||g<0||m+g>this.source.size,h&&l.set(h,{name:h,offset:m,length:g})}return this.entries=l,Array.from(l.values())}async readFile(e){let r=await this.getEntry(e);if(!r)throw new fe(`File not found in PAK: ${e}`);return this.source.slice(r.offset,r.offset+r.length).stream()}async getFileBlob(e){let r=await this.getEntry(e);if(!r)throw new fe(`File not found in PAK: ${e}`);return this.source.slice(r.offset,r.offset+r.length)}async getEntry(e){return this.entries||await this.readDirectory(),this.entries.get(wd(e))}async readChunk(e,r){let n=this.source.slice(e,e+r);return"arrayBuffer"in n?await n.arrayBuffer():new Response(n).arrayBuffer()}readCString(e,r,n){let i=[];for(let s=0;s<n;s+=1){let a=e.getUint8(r+s);if(a===0)break;i.push(a)}return String.fromCharCode(...i)}};var ul=12,Sd=64,ca=class t{constructor(){this.entries=new Map}addFile(e,r){let n=ae(e);if(n.length>56)throw new Error(`Path too long: '${n}' (max 56 chars)`);this.entries.set(n,r)}removeFile(e){return this.entries.delete(ae(e))}build(){let e=0;for(let u of this.entries.values())e+=u.byteLength;let r=this.entries.size*Sd,n=ul+e+r,i=new Uint8Array(n),s=new DataView(i.buffer);s.setUint8(0,80),s.setUint8(1,65),s.setUint8(2,67),s.setUint8(3,75);let a=ul+e;s.setInt32(4,a,!0),s.setInt32(8,r,!0);let o=ul,d=new Map,l=Array.from(this.entries.keys()).sort();for(let u of l){let h=this.entries.get(u);d.set(u,o),i.set(h,o),o+=h.byteLength}let c=a,f=new TextEncoder;for(let u of l){let h=this.entries.get(u),m=f.encode(u);if(m.length>56)throw new Error(`Path too long after encoding: ${u}`);for(let g=0;g<56;g++)g<m.length?s.setUint8(c+g,m[g]):s.setUint8(c+g,0);s.setInt32(c+56,d.get(u),!0),s.setInt32(c+60,h.byteLength,!0),c+=Sd}return i}static buildFromEntries(e){let r=new t;for(let[n,i]of e)r.addFile(n,i);return r.build()}};var fl=(a=>(a.Texture="texture",a.Sound="sound",a.Model="model",a.Map="map",a.Sprite="sprite",a.ConfigString="configString",a))(fl||{}),da=class{constructor(){this.tracking=!1;this.entries=[];this.currentFrame=0;this.currentTime=0}startTracking(){this.tracking=!0,this.entries=[]}stopTracking(){this.tracking=!1;let e={byFrame:new Map,byTime:new Map,uniqueResources:new Map};for(let r of this.entries){e.byFrame.has(r.frame)||e.byFrame.set(r.frame,[]),e.byFrame.get(r.frame).push(r),e.byTime.has(r.timestamp)||e.byTime.set(r.timestamp,[]),e.byTime.get(r.timestamp).push(r);let n=`${r.type}:${r.path}`;e.uniqueResources.has(n)||e.uniqueResources.set(n,r)}return e}recordLoad(e,r,n,i){this.tracking&&this.entries.push({type:e,path:r,timestamp:this.currentTime,frame:this.currentFrame,size:n,pakSource:i})}setCurrentFrame(e){this.currentFrame=e}setCurrentTime(e){this.currentTime=e}};var ua=class{constructor(e=[]){this.mounts=[];this.files=new Map;e.forEach(r=>this.mountPak(r))}mountPak(e,r=0){let n=this.mounts.findIndex(i=>i.pak===e);n!==-1&&this.mounts.splice(n,1),this.mounts.push({pak:e,priority:r}),this.mounts.sort((i,s)=>s.priority-i.priority);for(let i of e.listEntries()){let s=ae(i.name),a={archive:e,entry:i,priority:r};this.files.has(s)||this.files.set(s,[]);let o=this.files.get(s),d=o.findIndex(l=>l.archive===e);d!==-1&&o.splice(d,1),o.unshift(a),o.sort((l,c)=>c.priority-l.priority)}return e}setPriority(e,r){this.mountPak(e,r)}getPaks(){return[...this.mounts].sort((e,r)=>e.priority-r.priority)}get mountedPaks(){return this.mounts.map(e=>e.pak)}hasFile(e){return this.files.has(ae(e))}getSource(e){let r=this.files.get(ae(e));if(!(!r||r.length===0))return r[0]}stat(e){let r=this.getSource(e);if(r)return{path:r.entry.name,size:r.entry.length,sourcePak:r.archive.name}}getFileMetadata(e){let r=this.getSource(e);if(r)return{path:r.entry.name,size:r.entry.length,sourcePak:r.archive.name,offset:r.entry.offset}}async readFile(e){let r=this.getSource(e);if(!r)throw new Error(`File not found in VFS: ${e}`);return r.archive.readFile(e)}async readBinaryFile(e){return this.readFile(e)}streamFile(e,r=1024*1024){let n=this.getSource(e);if(!n)throw new Error(`File not found in VFS: ${e}`);let{archive:i}=n,s=i.readFile(e),a=0,o=s.length;return new ReadableStream({pull(d){if(a>=o){d.close();return}let l=Math.min(a+r,o),c=s.slice(a,l);a=l,d.enqueue(c)}})}async readTextFile(e){let r=await this.readFile(e);return new TextDecoder("utf-8").decode(r)}list(e=""){let r=ae(e).replace(/\/+$|^\//g,""),n=[],i=new Set,s=r?`${r}/`:"";for(let[a,o]of this.files){let d=o[0];if(r&&!d.entry.name.startsWith(s))continue;let l=r?d.entry.name.slice(s.length):d.entry.name,c=l.indexOf("/");c===-1?n.push({path:d.entry.name,size:d.entry.length,sourcePak:d.archive.name}):i.add(l.slice(0,c))}return n.sort((a,o)=>a.path.localeCompare(o.path)),{files:n,directories:[...i].sort()}}async listDirectory(e){return this.list(e).files}findByExtension(e){if(e instanceof RegExp)return this.searchFiles(e);if(Array.isArray(e))return this.listByExtension(e);let r=e.startsWith(".")?e.toLowerCase():`.${e.toLowerCase()}`,n=[];for(let[i,s]of this.files){let a=s[0];a.entry.name.toLowerCase().endsWith(r)&&n.push({path:a.entry.name,size:a.entry.length,sourcePak:a.archive.name})}return n.sort((i,s)=>i.path.localeCompare(s.path))}listByExtension(e){let r=new Set(e.map(i=>i.startsWith(".")?i.toLowerCase():`.${i.toLowerCase()}`)),n=[];for(let[i,s]of this.files){let a=s[0],o=a.entry.name.toLowerCase();for(let d of r)if(o.endsWith(d)){n.push({path:a.entry.name,size:a.entry.length,sourcePak:a.archive.name});break}}return n.sort((i,s)=>i.path.localeCompare(s.path))}searchFiles(e){let r=[];for(let[n,i]of this.files){let s=i[0];e.test(s.entry.name)&&r.push({path:s.entry.name,size:s.entry.length,sourcePak:s.archive.name})}return r.sort((n,i)=>n.path.localeCompare(i.path))}getPakInfo(){return this.mounts.map(e=>({filename:e.pak.name,entryCount:e.pak.listEntries().length,totalSize:e.pak.size,priority:e.priority}))}getDirectoryTree(){let e={name:"",path:"",files:[],directories:[]},r=new Map;r.set("",e);let n=Array.from(this.files.values()).map(i=>{let s=i[0];return{path:s.entry.name,size:s.entry.length,sourcePak:s.archive.name}}).sort((i,s)=>i.path.localeCompare(s.path));for(let i of n){let s=i.path.split("/"),a=s.pop(),o="",d=e;for(let l of s){let c=o;o=o?`${o}/${l}`:l;let f=r.get(o);f||(f={name:l,path:o,files:[],directories:[]},d.directories.push(f),r.set(o,f)),d=f}d.files.push(i)}return e}};var hl=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"}]),Wr=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"}},fa=class{constructor(e=hl){this.known=new Map;e.forEach(r=>this.known.set(this.normalizePakName(r.name),r))}validateArchive(e,r){let n=this.normalizePakName(r??("name"in e?e.name:"unknown")),i=e.checksum,s="size"in e?e.size:void 0,a=this.known.get(n);return a?a.checksum!==i?{name:n,checksum:i,expectedChecksum:a.checksum,status:"mismatch",size:s,description:a.description}:{name:n,checksum:i,expectedChecksum:a.checksum,status:"valid",size:s,description:a.description}:{name:n,checksum:i,status:"unknown",size:s}}assertValid(e,r){let n=this.validateArchive(e,r);if(n.status==="mismatch")throw new Wr(n);return n}normalizePakName(e){let r=ae(e),n=r.split("/"),i=n.pop()??r,s=n.pop();return s?`${i}@${s}`:i}};var Xt=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 k0(t,e){if(typeof t.arrayBuffer=="function"){let r=await t.arrayBuffer();return e?.({file:"blob",loadedBytes:r.byteLength,totalBytes:r.byteLength,state:"reading"}),r}if(typeof FileReader<"u")return new Promise((r,n)=>{let i=new FileReader;i.onerror=()=>n(i.error??new Error("Unknown FileReader error")),i.onprogress=s=>{e?.({file:"blob",loadedBytes:s.loaded,totalBytes:s.total||t.size,state:"reading"})},i.onload=()=>{let s=i.result;s instanceof ArrayBuffer?r(s):n(new Error("Unexpected FileReader result"))},i.readAsArrayBuffer(t)});if(typeof Response<"u"){let r=await new Response(t).arrayBuffer();return e?.({file:"blob",loadedBytes:r.byteLength,totalBytes:r.byteLength,state:"reading"}),r}if(typeof t.stream=="function"){let r=t.stream().getReader(),n=[],i=0;for(;;){let{done:o,value:d}=await r.read();if(o)break;if(!d)continue;let l=d;n.push(l),i+=l.byteLength,e?.({file:"blob",loadedBytes:i,totalBytes:t.size,state:"reading"})}let s=new Uint8Array(i),a=0;for(let o of n)s.set(o,a),a+=o.byteLength;return s.buffer}throw new Xt("blob",new Error("Unsupported Blob type"))}async function R0(t,e){if(t.data instanceof ArrayBuffer)return e?.({file:t.name,loadedBytes:t.data.byteLength,totalBytes:t.data.byteLength,state:"reading"}),t.data;if(t.data instanceof Blob){let n=t.data.size;return k0(t.data,i=>e?.({...i,file:t.name,totalBytes:n}))}let r=t.data.buffer.slice(t.data.byteOffset,t.data.byteOffset+t.data.byteLength);return e?.({file:t.name,loadedBytes:r.byteLength,totalBytes:r.byteLength,state:"reading"}),r}async function ha(t,e,r){let n=typeof r=="function"?{onProgress:r}:r??{},i=n.persistIndexes??!!n.pakIndexStore,s=n.enforceValidation??!!n.validator,a=n.allowUnknownPaks??!0,o=n.stopOnError??!1,d=[];for(let l of e)try{let c=await R0(l,n.onProgress),f=Cn.fromArrayBuffer(l.name,c),u=n.validator?.validateArchive(f);if(u){n.onValidationResult?.(u);let h=u.status==="mismatch",m=u.status==="unknown";if(h&&s||m&&!a){let g=new Wr(u);if(n.onError?.(l.name,g),o)throw new Xt(l.name,g);d.push({archive:f,mounted:!1,validation:u});continue}}if(t.mountPak(f),i&&n.pakIndexStore)try{await n.pakIndexStore.persist(f)}catch(h){if(n.onError?.(l.name,h),o)throw new Xt(l.name,h)}n.onProgress?.({file:l.name,loadedBytes:c.byteLength,totalBytes:c.byteLength,state:"parsed"}),d.push({archive:f,mounted:!0,validation:u})}catch(c){if(n.onProgress?.({file:l.name,loadedBytes:0,totalBytes:0,state:"error"}),n.onError?.(l.name,c),o)throw new Xt(l.name,c)}return d}var Kt=class{constructor(e,r=1/0,n=()=>0){this.capacity=e;this.maxMemory=r;this.sizeCalculator=n;this.map=new Map;this.currentMemoryUsage=0;if(e<=0)throw new RangeError("LRU cache capacity must be greater than zero")}get size(){return this.map.size}get memoryUsage(){return this.currentMemoryUsage}has(e){return this.map.has(e)}get(e){let r=this.map.get(e);if(r!==void 0)return this.map.delete(e),this.map.set(e,r),r}set(e,r){let n=this.sizeCalculator(r);this.map.has(e)&&this.delete(e),this.map.set(e,r),this.currentMemoryUsage+=n,this.evict()}delete(e){let r=this.map.get(e);return r!==void 0?(this.currentMemoryUsage-=this.sizeCalculator(r),this.map.delete(e)):!1}clear(){this.map.clear(),this.currentMemoryUsage=0}entries(){return Array.from(this.map.entries()).reverse().map(([e,r])=>({key:e,value:r}))}evict(){for(;this.map.size>this.capacity;){let e=this.map.keys().next();if(!e.done)this.delete(e.value);else break}for(;this.currentMemoryUsage>this.maxMemory&&this.map.size>0;){let e=this.map.keys().next();if(!e.done)this.delete(e.value);else break}}};function P0(t){return Array.isArray(t)?t:Array.from(t)}function ml(t){return P0(t).map(e=>({name:e.name,data:e}))}async function Ad(t,e,r){let n=ml(e);return ha(t,n,r??{})}function Md(t,e){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&&e(Array.from(s))};return t.addEventListener("dragover",r),t.addEventListener("drop",n),()=>{t.removeEventListener("dragover",r),t.removeEventListener("drop",n)}}function Ed(t,e){let r=n=>{let i=n.target;!i||!i.files||i.files.length===0||(e(i.files),i.value="")};return t.addEventListener("change",r),()=>t.removeEventListener("change",r)}var F0="IBSP",B0=38,Td=19,D0=8+Td*8;var Q=class extends Error{},In=class{constructor(e){this.vfs=e}async load(e){let r=await this.vfs.readFile(e),n=new Uint8Array(r.byteLength);return n.set(r),Mi(n.buffer)}};function Mi(t){if(t.byteLength<D0)throw new Q("BSP too small to contain header");let e=new DataView(t),r=String.fromCharCode(e.getUint8(0),e.getUint8(1),e.getUint8(2),e.getUint8(3));if(r!==F0)throw new Q(`Invalid BSP magic ${r}`);let n=e.getInt32(4,!0);if(n!==B0)throw new Q(`Unsupported BSP version ${n}`);let i=new Map;for(let w=0;w<Td;w+=1){let L=e.getInt32(8+w*8,!0),T=e.getInt32(12+w*8,!0);if(L<0||T<0||L+T>t.byteLength)throw new Q(`Invalid lump bounds for index ${w}`);i.set(w,{offset:L,length:T})}let s={version:n,lumps:i},a=z0(t,i.get(0)),o=U0(t,i.get(1)),d=H0(t,i.get(2)),l=G0(t,i.get(4)),c=V0(t,i.get(5)),f=W0(t,i.get(6)),u=new Uint8Array(t,i.get(7).offset,i.get(7).length),h=J0(f,i.get(7)),m=X0(t,i.get(8)),g=K0(t,i.get(11)),p=$0(t,i.get(12)),y=Z0(t,i.get(13)),_=Y0(t,i.get(14)),x=q0(t,i.get(15)),b=j0(t,i.get(9),i.get(10),m),v=Q0(t,i.get(3));return{header:s,entities:a,planes:o,vertices:d,nodes:l,texInfo:c,faces:f,lightMaps:u,lightMapInfo:h,leafs:m,leafLists:b,edges:g,surfEdges:p,models:y,brushes:_,brushSides:x,visibility:v,pickEntity(w){let L=null,T=1/0;for(let A of a.entities){let I=A.properties.model;if(!I||!I.startsWith("*"))continue;let R=parseInt(I.substring(1),10);if(isNaN(R)||R<0||R>=y.length)continue;let F=y[R],k=O0(w.origin,w.direction,F.mins,F.maxs);k!==null&&k<T&&(T=k,L={entity:A,model:F,distance:k})}return L}}}function O0(t,e,r,n){let i=0,s=1/0;for(let a=0;a<3;a++)if(Math.abs(e[a])<1e-8){if(t[a]<r[a]||t[a]>n[a])return null}else{let o=1/e[a],d=(r[a]-t[a])*o,l=(n[a]-t[a])*o;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 z0(t,e){let r=new TextDecoder().decode(new Uint8Array(t,e.offset,e.length)),n=N0(r),i=n.find(s=>s.classname==="worldspawn");return{raw:r,entities:n,worldspawn:i,getUniqueClassnames(){let s=new Set;for(let a of n)a.classname&&s.add(a.classname);return Array.from(s).sort()}}}function N0(t){let e=[],r=/\{([^}]*)\}/gms,n;for(;(n=r.exec(t))!==null;){let i=n[1],s={},a=/"([^\"]*)"\s+"([^\"]*)"/g,o;for(;(o=a.exec(i))!==null;)s[o[1]]=o[2];e.push({classname:s.classname,properties:s})}return e}function U0(t,e){let r=new DataView(t,e.offset,e.length),n=e.length/20;if(n%1!==0)throw new Q("Plane lump has invalid length");let i=[];for(let s=0;s<n;s+=1){let a=[r.getFloat32(s*20,!0),r.getFloat32(s*20+4,!0),r.getFloat32(s*20+8,!0)],o=r.getFloat32(s*20+12,!0),d=r.getInt32(s*20+16,!0);i.push({normal:a,dist:o,type:d})}return i}function H0(t,e){let r=new DataView(t,e.offset,e.length),n=e.length/12;if(n%1!==0)throw new Q("Vertex lump has invalid length");let i=[];for(let 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 G0(t,e){let r=new DataView(t,e.offset,e.length),n=28,i=e.length/n;if(i%1!==0)throw new Q("Node lump has invalid length");let s=[];for(let a=0;a<i;a+=1){let o=a*n,d=r.getInt32(o,!0),l=[r.getInt32(o+4,!0),r.getInt32(o+8,!0)],c=[r.getInt16(o+12,!0),r.getInt16(o+14,!0),r.getInt16(o+16,!0)],f=[r.getInt16(o+18,!0),r.getInt16(o+20,!0),r.getInt16(o+22,!0)],u=r.getUint16(o+24,!0),h=r.getUint16(o+26,!0);s.push({planeIndex:d,children:l,mins:c,maxs:f,firstFace:u,numFaces:h})}return s}function V0(t,e){let r=new DataView(t,e.offset,e.length),n=76,i=e.length/n;if(i%1!==0)throw new Q("TexInfo lump has invalid length");let s=[];for(let a=0;a<i;a+=1){let o=a*n,d=[r.getFloat32(o,!0),r.getFloat32(o+4,!0),r.getFloat32(o+8,!0)],l=r.getFloat32(o+12,!0),c=[r.getFloat32(o+16,!0),r.getFloat32(o+20,!0),r.getFloat32(o+24,!0)],f=r.getFloat32(o+28,!0),u=r.getInt32(o+32,!0),h=r.getInt32(o+36,!0),m=new Uint8Array(t,e.offset+o+40,32),g=new TextDecoder("utf-8").decode(m).replace(/\0.*$/,""),p=r.getInt32(o+72,!0);s.push({s:d,sOffset:l,t:c,tOffset:f,flags:u,value:h,texture:g,nextTexInfo:p})}return s}function W0(t,e){let r=new DataView(t,e.offset,e.length),n=20,i=e.length/n;if(i%1!==0)throw new Q("Face lump has invalid length");let s=[];for(let a=0;a<i;a+=1){let o=a*n,d=r.getUint16(o,!0),l=r.getInt16(o+2,!0),c=r.getInt32(o+4,!0),f=r.getInt16(o+8,!0),u=r.getInt16(o+10,!0),h=[r.getUint8(o+12),r.getUint8(o+13),r.getUint8(o+14),r.getUint8(o+15)],m=r.getInt32(o+16,!0);s.push({planeIndex:d,side:l,firstEdge:c,numEdges:f,texInfo:u,styles:h,lightOffset:m})}return s}function X0(t,e){let r=new DataView(t,e.offset,e.length),n=28,i=e.length/n;if(i%1!==0)throw new Q("Leaf lump has invalid length");let s=[];for(let a=0;a<i;a+=1){let o=a*n,d=r.getInt32(o,!0),l=r.getInt16(o+4,!0),c=r.getInt16(o+6,!0),f=[r.getInt16(o+8,!0),r.getInt16(o+10,!0),r.getInt16(o+12,!0)],u=[r.getInt16(o+14,!0),r.getInt16(o+16,!0),r.getInt16(o+18,!0)],h=r.getUint16(o+20,!0),m=r.getUint16(o+22,!0),g=r.getUint16(o+24,!0),p=r.getUint16(o+26,!0);s.push({contents:d,cluster:l,area:c,mins:f,maxs:u,firstLeafFace:h,numLeafFaces:m,firstLeafBrush:g,numLeafBrushes:p})}return s}function K0(t,e){let r=new DataView(t,e.offset,e.length),n=4,i=e.length/n;if(i%1!==0)throw new Q("Edge lump has invalid length");let s=[];for(let a=0;a<i;a+=1){let o=a*n;s.push({vertices:[r.getUint16(o,!0),r.getUint16(o+2,!0)]})}return s}function $0(t,e){let r=e.length/4;if(r%1!==0)throw new Q("SurfEdge lump has invalid length");let n=new DataView(t,e.offset,e.length),i=new Int32Array(r);for(let s=0;s<r;s+=1)i[s]=n.getInt32(s*4,!0);return i}function Z0(t,e){let r=new DataView(t,e.offset,e.length),n=48;if(e.length%n!==0)throw new Q("Model lump has invalid length");let i=e.length/n,s=[];for(let a=0;a<i;a+=1){let o=a*n,d=[r.getFloat32(o,!0),r.getFloat32(o+4,!0),r.getFloat32(o+8,!0)],l=[r.getFloat32(o+12,!0),r.getFloat32(o+16,!0),r.getFloat32(o+20,!0)],c=[r.getFloat32(o+24,!0),r.getFloat32(o+28,!0),r.getFloat32(o+32,!0)],f=r.getInt32(o+36,!0),u=r.getInt32(o+40,!0),h=r.getInt32(o+44,!0);s.push({mins:d,maxs:l,origin:c,headNode:f,firstFace:u,numFaces:h})}return s}function Y0(t,e){let r=new DataView(t,e.offset,e.length),n=12,i=e.length/n;if(i%1!==0)throw new Q("Brush lump has invalid length");let s=[];for(let a=0;a<i;a+=1){let o=a*n;s.push({firstSide:r.getInt32(o,!0),numSides:r.getInt32(o+4,!0),contents:r.getInt32(o+8,!0)})}return s}function q0(t,e){let r=new DataView(t,e.offset,e.length),n=4,i=e.length/n;if(i%1!==0)throw new Q("Brush side lump has invalid length");let s=[];for(let a=0;a<i;a+=1){let o=a*n;s.push({planeIndex:r.getUint16(o,!0),texInfo:r.getInt16(o+2,!0)})}return s}function j0(t,e,r,n){let i=[],s=[],a=e.length/2,o=r.length/2,d=new DataView(t,e.offset,e.length),l=new DataView(t,r.offset,r.length);for(let c of n){if(c.firstLeafFace+c.numLeafFaces>a)throw new Q("Leaf faces reference data past lump bounds");if(c.firstLeafBrush+c.numLeafBrushes>o)throw new Q("Leaf brushes reference data past lump bounds");let f=[];for(let h=0;h<c.numLeafFaces;h+=1)f.push(d.getUint16((c.firstLeafFace+h)*2,!0));let u=[];for(let h=0;h<c.numLeafBrushes;h+=1)u.push(l.getUint16((c.firstLeafBrush+h)*2,!0));i.push(f),s.push(u)}return{leafFaces:i,leafBrushes:s}}function Q0(t,e){if(e.length===0)return;if(e.length<4)throw new Q("Visibility lump too small");let r=new DataView(t,e.offset,e.length),n=r.getInt32(0,!0),i=4+n*8;if(n<0||i>e.length)throw new Q("Visibility lump truncated");let s=4,a=[];for(let o=0;o<n;o+=1){let d=r.getInt32(s,!0),l=r.getInt32(s+4,!0);s+=8;let c=e.offset+d,f=e.offset+l,u=e.offset+e.length;if(d<0||l<0||c>=u||f>=u)throw new Q("Visibility offsets out of range");a.push({pvs:Ld(t,c,n,e),phs:Ld(t,f,n,e)})}return{numClusters:n,clusters:a}}function Ld(t,e,r,n){let i=Math.ceil(r/8),s=new Uint8Array(i),a=new Uint8Array(t),o=e,d=0,l=n.offset+n.length;for(;d<i;){if(o>=l)throw new Q("Visibility data truncated");let c=a[o++];if(c!==0){s[d++]=c;continue}if(o>=l)throw new Q("Visibility run exceeds lump bounds");let f=a[o++];for(let u=0;u<f&&d<i;u+=1)s[d++]=0}return s}function J0(t,e){return t.map(r=>{if(!(r.lightOffset<0))return{offset:r.lightOffset,length:Math.max(0,e.length-r.lightOffset)}})}function ma(t,e,r){if(t.lightOffset<0||t.lightOffset>=e.byteLength)return;let n=e.byteLength-t.lightOffset,i=Math.min(r?.length??n,n);if(!(i<=0))return e.subarray(t.lightOffset,t.lightOffset+i)}var em=844121161,tm=8,Cd=68,ye=class extends Error{},kn=class{constructor(e){this.vfs=e;this.cache=new Map}async load(e){if(this.cache.has(e))return this.cache.get(e);let r=await this.vfs.readFile(e),n=new Uint8Array(r.byteLength);n.set(r);let i=pl(n.buffer);return this.cache.set(e,i),i}get(e){return this.cache.get(e)}};function Id(t,e,r){let n=[];for(let i=0;i<r;i+=1){let s=t.getUint8(e+i);if(s===0)break;n.push(s)}return String.fromCharCode(...n)}function Ei(t,e,r,n){if(r!==0&&(e<Cd||e+r>t.byteLength))throw new ye(`${n} section is out of bounds`)}function rm(t){if(t.byteLength<Cd)throw new ye("MD2 buffer too small to contain header");let e=new DataView(t),r=e.getInt32(0,!0),n=e.getInt32(4,!0);if(r!==em)throw new ye(`Invalid MD2 ident: ${r}`);if(n!==tm)throw new ye(`Unsupported MD2 version: ${n}`);let i={ident:r,version:n,skinWidth:e.getInt32(8,!0),skinHeight:e.getInt32(12,!0),frameSize:e.getInt32(16,!0),numSkins:e.getInt32(20,!0),numVertices:e.getInt32(24,!0),numTexCoords:e.getInt32(28,!0),numTriangles:e.getInt32(32,!0),numGlCommands:e.getInt32(36,!0),numFrames:e.getInt32(40,!0),offsetSkins:e.getInt32(44,!0),offsetTexCoords:e.getInt32(48,!0),offsetTriangles:e.getInt32(52,!0),offsetFrames:e.getInt32(56,!0),offsetGlCommands:e.getInt32(60,!0),offsetEnd:e.getInt32(64,!0),magic:r},s=40+i.numVertices*4;if(i.frameSize!==s)throw new ye(`Unexpected frame size ${i.frameSize}, expected ${s}`);if(i.offsetEnd>t.byteLength)throw new ye("MD2 offset_end exceeds buffer length");return i}function nm(t,e){let r=e.numSkins*64;Ei(t,e.offsetSkins,r,"skins");let n=new DataView(t,e.offsetSkins,r),i=[];for(let s=0;s<e.numSkins;s+=1)i.push({name:Id(n,s*64,64)});return i}function im(t,e){let r=e.numTexCoords*4;Ei(t,e.offsetTexCoords,r,"texcoords");let n=new DataView(t,e.offsetTexCoords,r),i=[];for(let s=0;s<e.numTexCoords;s+=1){let a=s*4;i.push({s:n.getInt16(a,!0),t:n.getInt16(a+2,!0)})}return i}function sm(t,e){let r=e.numTriangles*12;Ei(t,e.offsetTriangles,r,"triangles");let n=new DataView(t,e.offsetTriangles,r),i=[];for(let s=0;s<e.numTriangles;s+=1){let a=s*12,o=[n.getUint16(a,!0),n.getUint16(a+2,!0),n.getUint16(a+4,!0)],d=[n.getUint16(a+6,!0),n.getUint16(a+8,!0),n.getUint16(a+10,!0)];if(o.some(l=>l>=e.numVertices)||d.some(l=>l>=e.numTexCoords))throw new ye("Triangle references out of range vertex or texcoord");i.push({vertexIndices:o,texCoordIndices:d})}return i}function am(t,e){let r=e.numFrames*e.frameSize;Ei(t,e.offsetFrames,r,"frames");let n=[];for(let i=0;i<e.numFrames;i+=1){let s=e.offsetFrames+i*e.frameSize,a=new DataView(t,s,e.frameSize),o={x:a.getFloat32(0,!0),y:a.getFloat32(4,!0),z:a.getFloat32(8,!0)},d={x:a.getFloat32(12,!0),y:a.getFloat32(16,!0),z:a.getFloat32(20,!0)},l=Id(a,24,16),c=[],f=1/0,u=1/0,h=1/0,m=-1/0,g=-1/0,p=-1/0;for(let y=0;y<e.numVertices;y+=1){let _=40+y*4,x=a.getUint8(_)*o.x+d.x,b=a.getUint8(_+1)*o.y+d.y,v=a.getUint8(_+2)*o.z+d.z;x<f&&(f=x),b<u&&(u=b),v<h&&(h=v),x>m&&(m=x),b>g&&(g=b),v>p&&(p=v);let S={x,y:b,z:v},w=a.getUint8(_+3),L=Vt[w];if(!L)throw new ye(`Invalid normal index ${w} in frame ${l}`);let T={x:L[0],y:L[1],z:L[2]};c.push({position:S,normalIndex:w,normal:T})}n.push({name:l,vertices:c,minBounds:{x:f,y:u,z:h},maxBounds:{x:m,y:g,z:p}})}return n}function om(t,e){let r=e.numGlCommands*4;if(Ei(t,e.offsetGlCommands,r,"gl commands"),r===0)return[];let n=new DataView(t,e.offsetGlCommands,r),i=[],s=0;for(;;){if(s+4>r)throw new ye("GL command list ended unexpectedly");let a=n.getInt32(s,!0);if(s+=4,a===0)break;let o=Math.abs(a),d=[],l=o*12;if(s+l>r)throw new ye("GL command vertex block exceeds buffer");for(let c=0;c<o;c+=1){let f=n.getFloat32(s,!0),u=n.getFloat32(s+4,!0),h=n.getInt32(s+8,!0);if(s+=12,h<0||h>=e.numVertices)throw new ye("GL command references invalid vertex index");d.push({s:f,t:u,vertexIndex:h})}i.push({mode:a>0?"strip":"fan",vertices:d})}if(s!==r)throw new ye("GL command list did not consume expected data");return i}function pl(t){let e=rm(t),r=nm(t,e),n=im(t,e),i=sm(t,e),s=am(t,e),a=om(t,e);return{header:e,skins:r,texCoords:n,triangles:i,frames:s,glCommands:a}}function kd(t){let e=[],r=0;for(;r<t.length;){let n=t[r].name,i=n.replace(/\d+$/,"")||n,s=r;for(;s+1<t.length&&(t[s+1].name.replace(/\d+$/,"")||t[s+1].name)===i;)s+=1;e.push({name:i,firstFrame:r,lastFrame:s}),r=s+1}return e}var Rd=860898377,lm=15,Ve=class extends Error{constructor(e){super(e),this.name="Md3ParseError"}};function Li(t,e,r){let n=new Uint8Array(t.buffer,t.byteOffset+e,r);return new TextDecoder("utf-8").decode(n).replace(/\0.*$/,"").trim()}function cm(t){let e=(t>>8&255)*(2*Math.PI/255),r=(t&255)*(2*Math.PI/255),n=Math.sin(r);return{x:Math.cos(e)*n,y:Math.sin(e)*n,z:Math.cos(r)}}function pa(t,e,r,n){if(e<0||e+r>n)throw new Ve(`${t} exceeds buffer bounds`)}function dm(t){let e=t.getInt32(0,!0);if(e!==Rd)throw new Ve(`Invalid MD3 ident: ${e}`);let r=t.getInt32(4,!0);if(r!==lm)throw new Ve(`Unsupported MD3 version: ${r}`);let n=Li(t,8,64),i=t.getInt32(72,!0),s=t.getInt32(76,!0),a=t.getInt32(80,!0),o=t.getInt32(84,!0),d=t.getInt32(88,!0),l=t.getInt32(92,!0),c=t.getInt32(96,!0),f=t.getInt32(100,!0),u=t.getInt32(104,!0);if(s<=0||o<0||a<0)throw new Ve("Invalid MD3 counts");return{ident:e,version:r,name:n,flags:i,numFrames:s,numTags:a,numSurfaces:o,numSkins:d,ofsFrames:l,ofsTags:c,ofsSurfaces:f,ofsEnd:u,magic:e}}function um(t,e){let r=[];pa("Frames",e.ofsFrames,e.numFrames*56,t.byteLength);for(let i=0;i<e.numFrames;i+=1){let s=e.ofsFrames+i*56;r.push({minBounds:{x:t.getFloat32(s,!0),y:t.getFloat32(s+4,!0),z:t.getFloat32(s+8,!0)},maxBounds:{x:t.getFloat32(s+12,!0),y:t.getFloat32(s+16,!0),z:t.getFloat32(s+20,!0)},localOrigin:{x:t.getFloat32(s+24,!0),y:t.getFloat32(s+28,!0),z:t.getFloat32(s+32,!0)},radius:t.getFloat32(s+36,!0),name:Li(t,s+40,16)})}return r}function fm(t,e){let r=[],i=e.numFrames*e.numTags*112;pa("Tags",e.ofsTags,i,t.byteLength);for(let s=0;s<e.numFrames;s+=1){let a=[];for(let o=0;o<e.numTags;o+=1){let d=e.ofsTags+(s*e.numTags+o)*112,l=d+64,c=l+12;a.push({name:Li(t,d,64),origin:{x:t.getFloat32(l,!0),y:t.getFloat32(l+4,!0),z:t.getFloat32(l+8,!0)},axis:[{x:t.getFloat32(c,!0),y:t.getFloat32(c+4,!0),z:t.getFloat32(c+8,!0)},{x:t.getFloat32(c+12,!0),y:t.getFloat32(c+16,!0),z:t.getFloat32(c+20,!0)},{x:t.getFloat32(c+24,!0),y:t.getFloat32(c+28,!0),z:t.getFloat32(c+32,!0)}]})}r.push(a)}return r}function hm(t,e){let r=t.getInt32(e,!0);if(r!==Rd)throw new Ve(`Invalid surface ident at ${e}: ${r}`);let n=Li(t,e+4,64),i=t.getInt32(e+68,!0),s=t.getInt32(e+72,!0),a=t.getInt32(e+76,!0),o=t.getInt32(e+80,!0),d=t.getInt32(e+84,!0),l=t.getInt32(e+88,!0),c=t.getInt32(e+92,!0),f=t.getInt32(e+96,!0),u=t.getInt32(e+100,!0),h=t.getInt32(e+104,!0);if(s<=0||o<=0||d<=0)throw new Ve(`Invalid surface counts for ${n}`);let m=h;pa(`Surface ${n}`,e,m,t.byteLength);let g=[],p=e+l;for(let w=0;w<d;w+=1){let L=p+w*12;g.push({indices:[t.getInt32(L,!0),t.getInt32(L+4,!0),t.getInt32(L+8,!0)]})}let y=[],_=e+c;for(let w=0;w<a;w+=1){let L=_+w*68;y.push({name:Li(t,L,64),shaderIndex:t.getInt32(L+64,!0)})}let x=[],b=e+f;for(let w=0;w<o;w+=1){let L=b+w*8;x.push({s:t.getFloat32(L,!0),t:t.getFloat32(L+4,!0)})}let v=[],S=e+u;for(let w=0;w<s;w+=1){let L=[];for(let T=0;T<o;T+=1){let A=S+(w*o+T)*8,I=t.getInt16(A,!0)/64,R=t.getInt16(A+2,!0)/64,F=t.getInt16(A+4,!0)/64,k=t.getUint16(A+6,!0);L.push({position:{x:I,y:R,z:F},latLng:k,normal:cm(k)})}v.push(L)}return{surface:{name:n,flags:i,numFrames:s,shaders:y,triangles:g,texCoords:x,vertices:v},nextOffset:e+h}}function gl(t){if(t.byteLength<108)throw new Ve("MD3 buffer too small for header");let e=new DataView(t),r=dm(e);pa("MD3 end",r.ofsEnd,0,t.byteLength);let n=um(e,r),i=fm(e,r),s=[],a=r.ofsSurfaces;for(let o=0;o<r.numSurfaces;o+=1){let{surface:d,nextOffset:l}=hm(e,a);s.push(d),a=l}if(a!==r.ofsEnd)throw new Ve("Surface parsing did not reach ofsEnd");return{header:r,frames:n,tags:i,surfaces:s}}var Rn=class{constructor(e){this.vfs=e;this.cache=new Map}async load(e){if(this.cache.has(e))return this.cache.get(e);let r=await this.vfs.readFile(e),n=gl(r.slice().buffer);return this.cache.set(e,n),n}get(e){return this.cache.get(e)}};var mm=844317769,pm=2,Pd=64,Fd=12,$t=class extends Error{};function gm(t,e,r){let n=[];for(let i=0;i<r;i+=1){let s=t.getUint8(e+i);if(s===0)break;n.push(s)}return String.fromCharCode(...n)}function yl(t){if(t.byteLength<Fd)throw new $t("Sprite buffer too small to contain header");let e=new DataView(t),r=e.getInt32(0,!0),n=e.getInt32(4,!0),i=e.getInt32(8,!0);if(r!==mm)throw new $t(`Invalid Sprite ident: ${r}`);if(n!==pm)throw new $t(`Unsupported Sprite version: ${n}`);let s=[],a=16+Pd,o=Fd;for(let d=0;d<i;d+=1){if(o+a>t.byteLength)throw new $t("Sprite frame data exceeds buffer length");let l=e.getInt32(o,!0),c=e.getInt32(o+4,!0),f=e.getInt32(o+8,!0),u=e.getInt32(o+12,!0),h=gm(e,o+16,Pd);s.push({width:l,height:c,originX:f,originY:u,name:h}),o+=a}return{ident:r,version:n,numFrames:i,frames:s}}var Pn=class{constructor(e){this.vfs=e}async load(e){let r=await this.vfs.readFile(e),n=new Uint8Array(r.byteLength);return n.set(r),yl(n.buffer)}};function Bd(t,e){let r=(t.sequence.end-t.sequence.start+1)/t.sequence.fps,n=t.sequence.loop!==!1,i=t.time+e;return n?i=(i%r+r)%r:i>r&&(i=r),{...t,time:Math.max(0,Math.min(i,r))}}function Dd(t){let e=t.sequence.end-t.sequence.start+1,r=1/t.sequence.fps,n=t.sequence.loop!==!1,i=t.time/r;if(!n&&i>=e)return{frame0:t.sequence.end,frame1:t.sequence.end,lerp:0};let s=n?i%e:Math.min(i,e-1),a=Math.floor(s),o=t.sequence.start+a,d=a+1>=e?n?t.sequence.start:t.sequence.end:o+1,l=!n&&a>=e-1?0:s-a;return{frame0:o,frame1:d,lerp:l}}function Od(t){return{sequence:t,time:0}}function zd(t,e,r){return{x:t.x+(e.x-t.x)*r,y:t.y+(e.y-t.y)*r,z:t.z+(e.z-t.z)*r}}var Ti=class extends Error{constructor(e){super(e),this.name="WalParseError"}};function ga(t){if(t.byteLength<100)throw new Ti("WAL buffer too small");let e=new DataView(t),r=new Uint8Array(t,0,32),n=new TextDecoder("utf-8").decode(r).replace(/\0.*$/,"").trim(),i=e.getInt32(32,!0),s=e.getInt32(36,!0),a=[e.getInt32(40,!0),e.getInt32(44,!0),e.getInt32(48,!0),e.getInt32(52,!0)],o=new Uint8Array(t,56,32),d=new TextDecoder("utf-8").decode(o).replace(/\0.*$/,"").trim(),l=e.getInt32(88,!0),c=e.getInt32(92,!0),f=e.getInt32(96,!0);if(i<=0||s<=0)throw new Ti("Invalid WAL dimensions");let u=[],h=i,m=s;for(let g=0;g<a.length;g+=1){let p=a[g],y=Math.max(1,h*m|0);if(p<=0||p+y>t.byteLength)throw new Ti(`Invalid WAL mip offset for level ${g}`);let _=new Uint8Array(t,p,y);u.push({level:g,width:h,height:m,data:_}),h=Math.max(1,h>>1),m=Math.max(1,m>>1)}return{name:n,width:i,height:s,mipmaps:u,animName:d,flags:l,contents:c,value:f}}var Xr=class extends Error{constructor(e){super(e),this.name="PcxParseError"}};function Ci(t){if(t.byteLength<128)throw new Xr("PCX buffer too small for header");let e=new DataView(t),r=e.getUint8(0),n=e.getUint8(2),i=e.getUint8(3),s=e.getUint16(4,!0),a=e.getUint16(6,!0),o=e.getUint16(8,!0),d=e.getUint16(10,!0);if(r!==10||n!==1)throw new Xr("Unsupported PCX encoding");if(i!==8)throw new Xr("Only 8bpp PCX files are supported");let l=o-s+1,c=d-a+1,f=e.getUint16(66,!0),u=t.byteLength-769;if(u<128||new DataView(t,u,1).getUint8(0)!==12)throw new Xr("Missing PCX palette");let h=new Uint8Array(t,u+1,768),m=new Uint8Array(t,128,u-128),g=new Uint8Array(l*c),p=0,y=0;for(let _=0;_<c;_+=1){let x=0;for(;x<f&&p<m.length;){let b=1,v=m[p++];if((v&192)===192){if(b=v&63,p>=m.length)throw new Xr("Unexpected end of PCX RLE data");v=m[p++]}for(let S=0;S<b&&x<f;S+=1)x<l&&(g[y++]=v),x+=1}}return{width:l,height:c,bitsPerPixel:i,pixels:g,palette:h}}function ya(t){let e=new Uint8Array(t.width*t.height*4);for(let r=0;r<t.pixels.length;r+=1){let n=t.pixels[r],i=n*3,s=r*4;e[s]=t.palette[i],e[s+1]=t.palette[i+1],e[s+2]=t.palette[i+2],e[s+3]=n===255?0:255}return e}var Mt=class extends Error{constructor(e){super(e),this.name="TgaParseError"}};function bl(t){let e=new DataView(t);if(t.byteLength<18)throw new Mt("Buffer too small for TGA header");let r=e.getUint8(0),n=e.getUint8(1),i=e.getUint8(2),s=e.getUint16(12,!0),a=e.getUint16(14,!0),o=e.getUint8(16),d=e.getUint8(17);if(i!==2&&i!==10&&i!==3&&i!==11)throw new Mt(`Unsupported TGA image type: ${i} (only RGB/Grayscale supported)`);if(o!==24&&o!==32&&o!==8)throw new Mt(`Unsupported pixel depth: ${o} (only 8, 24, 32 bpp supported)`);let l=i>=9,c=i===3||i===11,f=o/8,u=18+r;if(n===1){let x=e.getUint16(5,!0),b=e.getUint8(7);u+=x*(b/8)}let h=s*a,m=new Uint8Array(h*4),g=(d&32)!==0,p=0,y=new Uint8Array(t),_=x=>{if(c){let b=y[u++];m[x]=b,m[x+1]=b,m[x+2]=b,m[x+3]=255}else{let b=y[u++],v=y[u++],S=y[u++],w=o===32?y[u++]:255;m[x]=S,m[x+1]=v,m[x+2]=b,m[x+3]=w}};if(l){let x=0;for(;x<h;){if(u>=t.byteLength)throw new Mt("Unexpected end of TGA RLE data");let b=y[u++],v=(b&127)+1,S=(b&128)!==0;if(x+v>h)throw new Mt("TGA RLE packet exceeds image bounds");if(S){let w=c?y[u]:y[u+2],L=c?y[u]:y[u+1],T=y[u],A=c?255:o===32?y[u+3]:255;u+=f;for(let I=0;I<v;I++){let R=(x+I)*4;m[R]=w,m[R+1]=L,m[R+2]=T,m[R+3]=A}}else for(let w=0;w<v;w++)_((x+w)*4);x+=v}}else for(let x=0;x<h;x++){if(u>=t.byteLength)throw new Mt("Unexpected end of TGA data");_(x*4)}if(!g){let x=s*4,b=new Uint8Array(x);for(let v=0;v<a/2;v++){let S=v*x,w=(a-1-v)*x;b.set(m.subarray(S,S+x)),m.set(m.subarray(w,w+x),S),m.set(b,w)}}return{width:s,height:a,bitsPerPixel:32,pixels:m}}function ym(t){let e=0;for(let r of t.levels)e+=r.rgba.byteLength;return e}var Fn=class{constructor(e={}){this.cache=new Kt(e.capacity??128,e.maxMemory??256*1024*1024,ym)}get size(){return this.cache.size}get memoryUsage(){return this.cache.memoryUsage}get(e){return this.cache.get(e.toLowerCase())}set(e,r){this.cache.set(e.toLowerCase(),r)}clear(){this.cache.clear()}};function xl(t,e){let r=[];for(let n of t.mipmaps){let i=new Uint8Array(n.width*n.height*4);for(let s=0;s<n.data.length;s+=1){let a=n.data[s],o=a*3,d=s*4;i[d]=e[o],i[d+1]=e[o+1],i[d+2]=e[o+2],i[d+3]=a===255?0:255}r.push({level:n.level,width:n.width,height:n.height,rgba:i})}return{width:t.width,height:t.height,levels:r,source:"wal"}}function ba(t){let e=ya(t),r={level:0,width:t.width,height:t.height,rgba:e};return{width:t.width,height:t.height,levels:[r],source:"pcx"}}function Nd(t){let e={level:0,width:t.width,height:t.height,rgba:t.pixels};return{width:t.width,height:t.height,levels:[e],source:"tga"}}function xa(t,e){return xl(ga(t),e)}var Kr=class extends Error{constructor(e){super(e),this.name="WavParseError"}};function _l(t,e,r){return new TextDecoder("ascii").decode(new Uint8Array(t.buffer,t.byteOffset+e,r))}function _a(t){if(t.byteLength<44)throw new Kr("WAV buffer too small");let e=new DataView(t);if(_l(e,0,4)!=="RIFF"||_l(e,8,4)!=="WAVE")throw new Kr("Invalid WAV header");let r=12,n=-1,i=-1,s=0,a=0;for(;r+8<=t.byteLength;){let m=_l(e,r,4),g=e.getUint32(r+4,!0),p=r+8;m==="fmt "?(n=p,s=g):m==="data"&&(i=p,a=g),r=p+g}if(n===-1||i===-1)throw new Kr("Missing fmt or data chunk");let o=e.getUint16(n,!0),d=e.getUint16(n+2,!0),l=e.getUint32(n+4,!0),c=e.getUint16(n+14,!0);if(o!==1)throw new Kr("Only PCM WAV is supported");let f=c/8,u=a/(f*d),h=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*f,_=0;if(c===8)_=e.getUint8(y),h[p]=(_-128)/128;else if(c===16)_=e.getInt16(y,!0),h[p]=_/32768;else if(c===24){let x=e.getUint8(y),b=e.getUint8(y+1),v=e.getInt8(y+2);_=x|b<<8|v<<16,h[p]=_/8388608}else throw new Kr(`Unsupported bitsPerSample: ${c}`)}return{sampleRate:l,channels:d,bitsPerSample:c,samples:h}}var bm=(t,e=4294967295,r=79764919)=>{let n=new Int32Array(256),i,s,a,o=e;for(i=0;i<256;i++){for(a=i<<24,s=8;s>0;--s)a=2147483648&a?a<<1^r:a<<1;n[i]=a}for(i=0;i<t.length;i++)o=o<<8^n[255&(o>>24^t[i])];return o};var vl=(t,e=bm)=>{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(t.length),a,o,d,l=!1,c=0,f=42,u=t.length>13&&t.substring(0,9)==="dynEncode",h=0;u&&(h=11,o=n(t.substring(9,h)),o<=1&&(h+=2,f=n(t.substring(11,h))),o===1&&(h+=8,d=(p=>new DataView(r(p).buffer).getInt32(0,!0))(t.substring(13,h))));let m=256-f;for(let p=h;p<t.length;p++)if(a=t.charCodeAt(p),a!==61||l){if(a===92&&p<t.length-5&&u){let y=t.charCodeAt(p+1);y!==117&&y!==85||(a=parseInt(t.substring(p+2,p+6),16),p+=5)}if(a>255){let y=i.get(a);y&&(a=y+127)}l&&(l=!1,a-=64),s[c++]=a<f&&a>0?a+m:a-f}else l=!0;let g=s.subarray(0,c);if(u&&o===1){let p=e(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 t=Uint8Array,e=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(vl(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 e(n),s=0,a=0;for(;s<r.length;)i.set(r[s],a),a+=r[s++].length;return i}},getDecodedAudio:{value:(r,n,i,s,a)=>({errors:r,channelData:n,samplesDecoded:i,sampleRate:s,bitDepth:a})},getDecodedAudioMultiChannel:{value(r,n,i,s,a,o){let d=[],l,c;for(l=0;l<i;l++){let f=[];for(c=0;c<n.length;)f.push(n[c++][l]||[]);d.push(re.concatFloat32(f,s))}return re.getDecodedAudio(r,d,s,a,o)}},inflateDynEncodeString:{value(r){return r=vl(r),new Promise(n=>{let i=String.raw`dynEncode012804c7886d()((()>+*§§)§,§§§§)§+§§§)§+.-()(*)-+)(.7*§)i¸¸,3§(i¸¸,3/G+.¡*(,(,3+)2å:-),§H(P*DI*H(P*@I++hH)H*r,hH(H(P*<J,i)^*<H,H(P*4U((I-H(H*i0J,^*DH+H-H*I+H,I*4)33H(H*H)^*DH(H+H)^*@H+i§H)i§3æ*).§K(iHI/+§H,iHn,§H+i(H+i(rCJ0I,H*I-+hH,,hH(H-V)(i)J.H.W)(i)c)(H,i)I,H-i*I-4)33i(I.*hH(V)(H+n5(H(i*I-i(I,i)I.+hH,i*J+iHn,hi(I-i*I,+hH,H/H-c)(H,iFn,hi(I,+hH,H0n5-H*V)(J(,hH/H(i)J(H(V)(J(i)c)(H)H(i)H,c)(3H*i*I*H,i)I,4(3(-H(H,W)(H-I-H,i*I,4)3(3(3H,H-I1H+I,H.i)H1V)(J.i(v5(33H.-H(H,i(c)(H,i*I,4)333)-§i*I*+§H*iHn,hi73H,H(i)8(H+J+H)P*(H*V)(J-r,§H)P*,H.i)H+H,i)V)(-H*i*I*H+i)I+H-H.I.H,H-i)I,4)333Ã+)-§iø7i(^*(iü7I,*h+hH+iDn,h*hilI+i)I,+hH+,hH+iô7H,c)(i)H+i´8W)(H,I,H+i*I+4)-+hH(H)8*J-i(p5.*h*h*hH-i')u,hH(P*(J+,hH(P*0J,H(P*,n50H+H,H-b((3H(P*0i)I.4)3H-i¨*n5*H-iÅ*s,hi73H-i)J+V)&+I,H(H+V)æ,8(I.H(H*8*J-i(p51H-i)J+i¸7V)(H(H+iø7V)(8(J/H(P*0J+s,hi73H+H,H.J,I.H(P*(m5(H.H(P*,s5.+hH,m5*H(P*(J.H+H.H+H/U((b((H(H(P*0i)J+^*0H,i)I,4(3(3H(H.^*03H-i¨*o5)33i(73(3(3-H,H+i)c)(H,i*I,H+i)I+4)33i)I-3H-3!2)0§K(i2J,L(H,H(^*(H,H*^*4H,i(^*0H,i(^*DH,j(_*<H,H)P*(^*,H,H+P*(^*8*h*h+hH,i)8(I3i§I**h*h*h*h*h*h*hH,i*8(6+(),03H,j(_*@i*I-H,P*<J.i,J(H,P*8J/s50H,H.i+J0^*<i¦I*H.H,P*4J1J.U(*H.U((J2i')o5/H.U()I.H,H(^*<H0H1U((H.i0J.i§i0i')o5/H/H.H2J*H(J.q50H,P*0J/H*I-H,P*(J0,hH,P*,H-q,hi)I-423+hH*m5+H/H0H(H1U((b((H/i)I/H(i)I(H*i)I*4(3(3H,H.^*<H,H-^*04*3iØ1U((5+i(I(i¨7i1^*(i$6iè1^*(i°7iè6^*(i¬7iÈ6^*(+hH(iÈ*n,hiÈ*I(+hH(i¨,n,hi¨,I(+hH(iØ,n,hiØ,I(+hH(iè,o,hH,i-H(i0c)(H(i*I(4)33iè1i1H,i-iÈ*8)Bi(I(+hH(ido,hH,i-H(i-c)(H(i*I(4)33iÈ6iè6H,i-iF8)BiØ1i)b((41-H,i-H(i/c)(H(i*I(4)3(3(-H,i-H(i1c)(H(i*I(4)3(3(-H,i-H(i0c)(H(i*I(4)3(3(3H,H/^*0H,H(^*<3i(I*4*3H,H,i¸)^*TH,H,iø-^*PH,H,iX^*LH,H,i(^*HH,i-8(I(H,i-8(I-i¥I*H,i,8(I.H(iErH-iEr5)H(i©*I1H-i)I0i(i;H.i,J(i(H(i(rCJ(J*H*i;sCI*i¨1I-H(I/+hH/,hH,i-H-V)(i)H,i+8(c)(H/i)I/H-i*I-H*i)I*4)-H(i)i¨1I/+hH(H*o,hH,i-H/V)(i)i(c)(H/i*I/H(i)I(4)33i¤I*H,iø-H,i¸)H,i-i;8)5+H0H1I2i(I-+hH-H2p,hH,H,iP8*J*i(p5-H*i7u,hH,i-H-i)H*c)(H-i)I-4*3i(I/i+I.i+I(*h*h*hH*i86*(*)3H-m,hi£I*403H-i)H,W)-I/i*I(4)3i3I.i/I(3H2H,H(8(H.J(H-J.p,hi¢I*4.3H,i-H-i)I*+hH(,hH*H/c)(H*i*I*H(i)I(4)-H.I-4+3(3(33H,W)1m,hiI*4,3H,iø-H,i¸)H,i-H18)J(,hi¡I*H(i(p5,H1H,V)ú-H,V)ø-o5,3H,i(H,iXH,i-H1i)H08)J(,hi I*H(i(p5,H0H,V)H,V)o5,3H,H,iPH,iH8+I*4+3(3(3H,i$6i¬78+I*3H*H3m5(3i)I-H*i(r5)3H)H,P*0^*(H+H,P*<^*(H*I-3H,i2L(H-33Á)+(i¨03b+(,(-(.(/(0(1(2(3(5(7(9(;(?(C(G(K(S([(c(k({(((«(Ë(ë((*)(iø03O)()()()(*(*(*(*(+(+(+(+(,(,(,(,(-(-(-(-(i¨13M8(9(:(((0(/(1(.(2(-(3(,(4(+(5(*(6()(7(T7*S7US0U `;re.getModule(re,i).then(s=>WebAssembly.instantiate(s,{})).then(({exports:s})=>{let a=new Map(Object.entries(s)),o=a.get("puff"),d=a.get("memory").buffer,l=new t(d),c=new DataView(d),f=a.get("__heap_base"),u=r.length,h=f;f+=4,c.setInt32(h,u,!0);let m=f;f+=u,l.set(r,m);let g=f;f+=4,c.setInt32(g,l.byteLength-f,!0),o(f,g,m,h),n(l.slice(f,f+c.getInt32(g,!0)))})})}}}),Object.defineProperty(this,"wasm",{enumerable:!0,get:()=>this._wasm}),this.getOutputChannels=(r,n,i)=>{let s=[],a=0;for(;a<n;)s.push(r.slice(a*i,a++*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,a,o)=>{r.push({message:n,frameLength:i,frameNumber:s,inputBytes:a,outputSamples:o})},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 Gd=Zh(Hd(),1);var xm=()=>globalThis.Worker||Gd.default,Bn=class extends xm(){constructor(e,r,n,i){re.modules||new re;let s=re.modules.get(n);if(!s){let a="text/javascript",o,d=`'use strict';(${((l,c,f)=>{let u,h,m=new Promise(g=>{h=g});self.onmessage=({data:{id:g,command:p,data:y}})=>{let _=m,x={id:g},b;p==="init"?(Object.defineProperties(l,{WASMAudioDecoderCommon:{value:c},EmscriptenWASM:{value:f},module:{value:y.module},isWebWorker:{value:!0}}),u=new l(y.options),h()):p==="free"?u.free():p==="ready"?_=_.then(()=>u.ready):p==="reset"?_=_.then(()=>u.reset()):(Object.assign(x,u[p](Array.isArray(y)?y.map(v=>new Uint8Array(v)):new Uint8Array(y))),b=x.channelData?x.channelData.map(v=>v.buffer):[]),_.then(()=>self.postMessage(x,b))}}).toString()})(${n}, ${re}, ${i})`;try{o=typeof process.versions.node<"u"}catch{}s=o?`data:${a};base64,${Buffer.from(d).toString("base64")}`:URL.createObjectURL(new Blob([d],{type:a})),re.modules.set(n,s)}super(s,{name:r}),this._id=Number.MIN_SAFE_INTEGER,this._enqueuedOperations=new Map,this.onmessage=({data:a})=>{let{id:o,...d}=a;this._enqueuedOperations.get(o)(d),this._enqueuedOperations.delete(o)},new i(re).getModule().then(a=>{this.postToDecoder("init",{module:a,options:e})})}async postToDecoder(e,r){return new Promise(n=>{this.postMessage({command:e,id:this._id,data:r}),this._enqueuedOperations.set(this._id++,n)})}get ready(){return this.postToDecoder("ready")}async free(){await this.postToDecoder("free").finally(()=>{this.terminate()})}async reset(){await this.postToDecoder("reset")}};var va=(t,e)=>{Object.defineProperty(t,"name",{value:e})};var ne=Symbol,Vd=", ",z=(()=>{let t="front",e="side",r="rear",n="left",i="center",s="right";return["",t+" ",e+" ",r+" "].map(a=>[[n,s],[n,s,i],[n,i,s],[i,n,s],[i]].flatMap(o=>o.map(d=>a+d).join(Vd)))})(),ot="LFE",Zt="monophonic (mono)",Yt="stereo",Ii="surround",oe=(t,...e)=>`${[Zt,Yt,`linear ${Ii}`,"quadraphonic",`5.0 ${Ii}`,`5.1 ${Ii}`,`6.1 ${Ii}`,`7.1 ${Ii}`][t-1]} (${e.join(Vd)})`,ki=[Zt,oe(2,z[0][0]),oe(3,z[0][2]),oe(4,z[1][0],z[3][0]),oe(5,z[1][2],z[3][0]),oe(6,z[1][2],z[3][0],ot),oe(7,z[1][2],z[2][0],z[3][4],ot),oe(8,z[1][2],z[2][0],z[3][0],ot)],Wd=192e3,Xd=176400,wa=96e3,Sa=88200,Kd=64e3,qt=48e3,Dn=44100,On=32e3,zn=24e3,Nn=22050,Un=16e3,Aa=12e3,Ma=11025,Hn=8e3,$d=7350,et="absoluteGranulePosition",H="bandwidth",ve="bitDepth",we="bitrate",Ri=we+"Maximum",Pi=we+"Minimum",Fi=we+"Nominal",lt="buffer",Bi=lt+"Fullness",te="codec",Se=te+"Frames",Di="coupledStreamCount",Gn="crc",Oi=Gn+"16",zi=Gn+"32",J="data",O="description",ct="duration",Vn="emphasis",Ni="hasOpusPadding",Be="header",jt="isContinuedPacket",Ui="isCopyrighted",Qt="isFirstPage",Hi="isHome",De="isLastPage",Et="isOriginal",Lt="isPrivate",Gi="isVbr",ke="layer",C="length",U="mode",Tt=U+"Extension",Ea="mpeg",Ct=Ea+"Version",Vi="numberAACFrames",Wi="outputGain",$r="preSkip",Xi="profile",La=ne(),It="protection",wl="rawData",We="segments",V="subarray",Jt="version",Zr="vorbis",Ki=Zr+"Comments",Wn=Zr+"Setup",Ta="block",$i=Ta+"ingStrategy",Ca=ne(),kt=Ta+"Size",er=Ta+"size0",tr=Ta+"size1",Zi=ne(),Ia="channel",Rt=Ia+"MappingFamily",Yi=Ia+"MappingTable",Ae=Ia+"Mode",qi=ne(),B=Ia+"s",Zd="copyright",ji=Zd+"Id",Qi=Zd+"IdStart",Pt="frame",Ft=Pt+"Count",Re=Pt+"Length",ka="Number",Bt=Pt+ka,dt=Pt+"Padding",N=Pt+"Size",Yd="Rate",Ji="inputSample"+Yd,Sl="page",Yr=Sl+"Checksum",Xn=ne(),rr=Sl+"SegmentTable",ue=Sl+"Sequence"+ka,Al="sample",es=Al+ka,K=Al+Yd,ut=ne(),$=Al+"s",Ra="stream",ts=Ra+"Count",rs=Ra+"Info",ft=Ra+"Serial"+ka,Ml=Ra+"StructureVersion",El="total",qr=El+"BytesOut",jr=El+"Duration",Qr=El+"Samples",Y=ne(),Xe=ne(),ns=ne(),nr=ne(),tt=ne(),Pa=ne(),Ll=ne(),ir=ne(),q=ne(),Ke=ne(),$e=ne(),ht=ne(),sr=ne(),Fa=ne(),rt=ne(),nt=ne(),Ze=ne(),Ba=ne(),Me=Uint8Array,ar=DataView,j="reserved",Ee="bad",Kn="free",is="none",Da="16bit CRC";var Tl=(t,e,r)=>{for(let n=0;n<t[C];n++){let i=e(n);for(let s=8;s>0;s--)i=r(i);t[n]=i}return t},vm=Tl(new Me(256),t=>t,t=>t&128?7^t<<1:t<<1),le=[Tl(new Uint16Array(256),t=>t<<8,t=>t<<1^(t&32768?32773:0))],ce=[Tl(new Uint32Array(256),t=>t,t=>t>>>1^(t&1)*3988292384)];for(let t=0;t<15;t++){le.push(new Uint16Array(256)),ce.push(new Uint32Array(256));for(let e=0;e<=255;e++)le[t+1][e]=le[0][le[t][e]>>>8]^le[t][e]<<8,ce[t+1][e]=ce[t][e]>>>8^ce[0][ce[t][e]&255]}var jd=t=>{let e=0,r=t[C];for(let n=0;n!==r;n++)e=vm[e^t[n]];return e},Qd=t=>{let e=t[C],r=e-16,n=0,i=0;for(;i<=r;)n^=t[i++]<<8|t[i++],n=le[15][n>>8]^le[14][n&255]^le[13][t[i++]]^le[12][t[i++]]^le[11][t[i++]]^le[10][t[i++]]^le[9][t[i++]]^le[8][t[i++]]^le[7][t[i++]]^le[6][t[i++]]^le[5][t[i++]]^le[4][t[i++]]^le[3][t[i++]]^le[2][t[i++]]^le[1][t[i++]]^le[0][t[i++]];for(;i!==e;)n=(n&255)<<8^le[0][n>>8^t[i++]];return n},Jd=t=>{let e=t[C],r=e-16,n=0,i=0;for(;i<=r;)n=ce[15][(t[i++]^n)&255]^ce[14][(t[i++]^n>>>8)&255]^ce[13][(t[i++]^n>>>16)&255]^ce[12][t[i++]^n>>>24]^ce[11][t[i++]]^ce[10][t[i++]]^ce[9][t[i++]]^ce[8][t[i++]]^ce[7][t[i++]]^ce[6][t[i++]]^ce[5][t[i++]]^ce[4][t[i++]]^ce[3][t[i++]]^ce[2][t[i++]]^ce[1][t[i++]]^ce[0][t[i++]];for(;i!==e;)n=ce[0][(n^t[i++])&255]^n>>>8;return n^-1},as=(...t)=>{let e=new Me(t.reduce((r,n)=>r+n[C],0));return t.reduce((r,n)=>(e.set(n,r),r+n[C]),0),e},Oe=t=>String.fromCharCode(...t),qd=[0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15],ss=t=>qd[t&15]<<4|qd[t>>4],Oa=class{constructor(e){this._data=e,this._pos=e[C]*8}set position(e){this._pos=e}get position(){return this._pos}read(e){let r=Math.floor(this._pos/8),n=this._pos%8;return this._pos-=e,(ss(this._data[r-1])<<8)+ss(this._data[r])>>7-n&255}},eu=(t,e)=>{try{return t.getBigInt64(e,!0)}catch{let r=t.getUint8(e+7)&128?-1:1,n=t.getUint32(e,!0),i=t.getUint32(e+4,!0);return r===-1&&(n=~n+1,i=~i+1),i>1048575&&console.warn("This platform does not support BigInt"),r*(n+i*2**32)}};var os=class{constructor(e,r){this._onCodecHeader=e,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}[Fa](e,r){if(this._onCodecUpdate){this._bitrate!==e&&(this._bitrate=e,this._codecShouldUpdate=!0);let n=this._codecUpdateData.get(this._headerCache.get(this._currentHeader));this._codecShouldUpdate&&n&&this._onCodecUpdate({bitrate:e,...n},r),this._codecShouldUpdate=!1}}[q](e){let r=this._headerCache.get(e);return r&&this._updateCurrentHeader(e),r}[Ke](e,r,n){this._isEnabled&&(this._codecHeaderSent||(this._onCodecHeader({...r}),this._codecHeaderSent=!0),this._updateCurrentHeader(e),this._headerCache.set(e,r),this._codecUpdateData.set(r,n))}_updateCurrentHeader(e){this._onCodecUpdate&&e!==this._currentHeader&&(this._codecShouldUpdate=!0,this._currentHeader=e)}};var he=new WeakMap,be=new WeakMap;var Le=class{constructor(e,r){this._codecParser=e,this._headerCache=r}*[Ll](){let e;do{if(e=yield*this.Frame[$e](this._codecParser,this._headerCache,0),e)return e;this._codecParser[Xe](1)}while(!0)}*[ir](e){let r=yield*this[Ll](),n=be.get(r)[C];if(e||this._codecParser._flushing||(yield*this.Header[q](this._codecParser,this._headerCache,n)))return this._headerCache[nt](),this._codecParser[Xe](n),this._codecParser[nr](r),r;this._codecParser[tt](`Missing ${Pt} at ${n} bytes from current position.`,`Dropping current ${Pt} and trying again.`),this._headerCache[rt](),this._codecParser[Xe](1)}};var Jr=class{constructor(e,r){be.set(this,{[Be]:e}),this[J]=r}};var ze=class extends Jr{static*[$e](e,r,n,i,s){let a=yield*e[q](n,i,s);if(a){let o=he.get(a)[Re],d=he.get(a)[$],l=(yield*n[Y](o,s))[V](0,o);return new r(a,l,d)}else return null}constructor(e,r,n){super(e,r),this[Be]=e,this[$]=n,this[ct]=n/e[K]*1e3,this[Bt]=null,this[qr]=null,this[Qr]=null,this[jr]=null,be.get(this)[C]=r[C]}};var Cl="unsynchronizationFlag",Il="extendedHeaderFlag",kl="experimentalFlag",Rl="footerPresent",ls=class t{static*getID3v2Header(e,r,n){let s={},a=yield*e[Y](3,n);if(a[0]!==73||a[1]!==68||a[2]!==51||(a=yield*e[Y](10,n),s[Jt]=`id3v2.${a[3]}.${a[4]}`,a[5]&15)||(s[Cl]=!!(a[5]&128),s[Il]=!!(a[5]&64),s[kl]=!!(a[5]&32),s[Rl]=!!(a[5]&16),a[6]&128||a[7]&128||a[8]&128||a[9]&128))return null;let o=a[6]<<21|a[7]<<14|a[8]<<7|a[9];return s[C]=10+o,new t(s)}constructor(e){this[Jt]=e[Jt],this[Cl]=e[Cl],this[Il]=e[Il],this[kl]=e[kl],this[Rl]=e[Rl],this[C]=e[C]}};var Ne=class{constructor(e){he.set(this,e),this[ve]=e[ve],this[we]=null,this[B]=e[B],this[Ae]=e[Ae],this[K]=e[K]}};var su={0:[Kn,Kn,Kn,Kn,Kn],16:[32,32,32,32,8],240:[Ee,Ee,Ee,Ee,Ee]},za=(t,e,r)=>8*((t+r)%e+e)*(1<<(t+r)/e)-8*e*(e/8|0);for(let t=2;t<15;t++)su[t<<4]=[t*32,za(t,4,0),za(t,4,-1),za(t,8,4),za(t,8,0)];var wm=0,Sm=1,Am=2,Mm=3,tu=4,Na="bands ",Ua=" to 31",ru={0:Na+4+Ua,16:Na+8+Ua,32:Na+12+Ua,48:Na+16+Ua},en="bitrateIndex",cs="v2",Xa="v1",Ha="Intensity stereo ",Ga=", MS stereo ",Va="on",Wa="off",Em={0:Ha+Wa+Ga+Wa,16:Ha+Va+Ga+Wa,32:Ha+Wa+Ga+Va,48:Ha+Va+Ga+Va},Pl={0:{[O]:j},2:{[O]:"Layer III",[dt]:1,[Tt]:Em,[Xa]:{[en]:Am,[$]:1152},[cs]:{[en]:tu,[$]:576}},4:{[O]:"Layer II",[dt]:1,[Tt]:ru,[$]:1152,[Xa]:{[en]:Sm},[cs]:{[en]:tu}},6:{[O]:"Layer I",[dt]:4,[Tt]:ru,[$]:384,[Xa]:{[en]:wm},[cs]:{[en]:Mm}}},Fl="MPEG Version ",nu="ISO/IEC ",Lm={0:{[O]:`${Fl}2.5 (later extension of MPEG 2)`,[ke]:cs,[K]:{0:Ma,4:Aa,8:Hn,12:j}},8:{[O]:j},16:{[O]:`${Fl}2 (${nu}13818-3)`,[ke]:cs,[K]:{0:Nn,4:zn,8:Un,12:j}},24:{[O]:`${Fl}1 (${nu}11172-3)`,[ke]:Xa,[K]:{0:Dn,4:qt,8:On,12:j}},length:C},Tm={0:Da,1:is},Cm={0:is,1:"50/15 ms",2:j,3:"CCIT J.17"},iu={0:{[B]:2,[O]:Yt},64:{[B]:2,[O]:"joint "+Yt},128:{[B]:2,[O]:"dual channel"},192:{[B]:1,[O]:Zt}},tn=class t extends Ne{static*[q](e,r,n){let i={},s=yield*ls.getID3v2Header(e,r,n);s&&(yield*e[Y](s[C],n),e[Xe](s[C]));let a=yield*e[Y](4,n),o=Oe(a[V](0,4)),d=r[q](o);if(d)return new t(d);if(a[0]!==255||a[1]<224)return null;let l=Lm[a[1]&24];if(l[O]===j)return null;let c=a[1]&6;if(Pl[c][O]===j)return null;let f={...Pl[c],...Pl[c][l[ke]]};if(i[Ct]=l[O],i[ke]=f[O],i[$]=f[$],i[It]=Tm[a[1]&1],i[C]=4,i[we]=su[a[2]&240][f[en]],i[we]===Ee||(i[K]=l[K][a[2]&12],i[K]===j)||(i[dt]=a[2]&2&&f[dt],i[Lt]=!!(a[2]&1),i[Re]=Math.floor(125*i[we]*i[$]/i[K]+i[dt]),!i[Re]))return null;let u=a[3]&192;if(i[Ae]=iu[u][O],i[B]=iu[u][B],i[Tt]=f[Tt][a[3]&48],i[Ui]=!!(a[3]&8),i[Et]=!!(a[3]&4),i[Vn]=Cm[a[3]&3],i[Vn]===j)return null;i[ve]=16;{let{length:h,frameLength:m,samples:g,...p}=i;r[Ke](o,i,p)}return new t(i)}constructor(e){super(e),this[we]=e[we],this[Vn]=e[Vn],this[dt]=e[dt],this[Ui]=e[Ui],this[Et]=e[Et],this[Lt]=e[Lt],this[ke]=e[ke],this[Tt]=e[Tt],this[Ct]=e[Ct],this[It]=e[It]}};var ds=class t extends ze{static*[$e](e,r,n){return yield*super[$e](tn,t,e,r,n)}constructor(e,r,n){super(e,r,n)}};var us=class extends Le{constructor(e,r,n){super(e,r),this.Frame=ds,this.Header=tn,n(this[te])}get[te](){return Ea}*[ht](){return yield*this[ir]()}};var Im={0:"MPEG-4",8:"MPEG-2"},km={0:"valid",2:Ee,4:Ee,6:Ee},Rm={0:Da,1:is},Pm={0:"AAC Main",64:"AAC LC (Low Complexity)",128:"AAC SSR (Scalable Sample Rate)",192:"AAC LTP (Long Term Prediction)"},Fm={0:wa,4:Sa,8:Kd,12:qt,16:Dn,20:On,24:zn,28:Nn,32:Un,36:Aa,40:Ma,44:Hn,48:$d,52:j,56:j,60:"frequency is written explicitly"},au={0:{[B]:0,[O]:"Defined in AOT Specific Config"},64:{[B]:1,[O]:Zt},128:{[B]:2,[O]:oe(2,z[0][0])},192:{[B]:3,[O]:oe(3,z[1][3])},256:{[B]:4,[O]:oe(4,z[1][3],z[3][4])},320:{[B]:5,[O]:oe(5,z[1][3],z[3][0])},384:{[B]:6,[O]:oe(6,z[1][3],z[3][0],ot)},448:{[B]:8,[O]:oe(8,z[1][3],z[2][0],z[3][0],ot)}},rn=class t extends Ne{static*[q](e,r,n){let i={},s=yield*e[Y](7,n),a=Oe([s[0],s[1],s[2],s[3]&252|s[6]&3]),o=r[q](a);if(o)Object.assign(i,o);else{if(s[0]!==255||s[1]<240||(i[Ct]=Im[s[1]&8],i[ke]=km[s[1]&6],i[ke]===Ee))return null;let l=s[1]&1;i[It]=Rm[l],i[C]=l?7:9,i[La]=s[2]&192,i[ut]=s[2]&60;let c=s[2]&2;if(i[Xi]=Pm[i[La]],i[K]=Fm[i[ut]],i[K]===j)return null;i[Lt]=!!c,i[qi]=(s[2]<<8|s[3])&448,i[Ae]=au[i[qi]][O],i[B]=au[i[qi]][B],i[Et]=!!(s[3]&32),i[Hi]=!!(s[3]&8),i[ji]=!!(s[3]&8),i[Qi]=!!(s[3]&4),i[ve]=16,i[$]=1024,i[Vi]=s[6]&3;{let{length:f,channelModeBits:u,profileBits:h,sampleRateBits:m,frameLength:g,samples:p,numberAACFrames:y,..._}=i;r[Ke](a,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[Bi]=d===2047?"VBR":d,new t(i)}constructor(e){super(e),this[ji]=e[ji],this[Qi]=e[Qi],this[Bi]=e[Bi],this[Hi]=e[Hi],this[Et]=e[Et],this[Lt]=e[Lt],this[ke]=e[ke],this[C]=e[C],this[Ct]=e[Ct],this[Vi]=e[Vi],this[Xi]=e[Xi],this[It]=e[It]}get audioSpecificConfig(){let e=he.get(this),r=e[La]+64<<5|e[ut]<<5|e[qi]>>3,n=new Me(2);return new ar(n[lt]).setUint16(0,r,!1),n}};var fs=class t extends ze{static*[$e](e,r,n){return yield*super[$e](rn,t,e,r,n)}constructor(e,r,n){super(e,r,n)}};var hs=class extends Le{constructor(e,r,n){super(e,r),this.Frame=fs,this.Header=rn,n(this[te])}get[te](){return"aac"}*[ht](){return yield*this[ir]()}};var or=class t extends ze{static _getFrameFooterCrc16(e){return(e[e[C]-2]<<8)+e[e[C]-1]}static[Ba](e){let r=t._getFrameFooterCrc16(e),n=Qd(e[V](0,-2));return r===n}constructor(e,r,n){r[rs]=n,r[Oi]=t._getFrameFooterCrc16(e),super(r,e,he.get(r)[$])}};var ou="get from STREAMINFO metadata block",Bm={0:"Fixed",1:"Variable"},lu={0:j,16:192};for(let t=2;t<16;t++)lu[t<<4]=t<6?576*2**(t-2):2**t;var Dm={0:ou,1:Sa,2:Xd,3:Wd,4:Hn,5:Un,6:Nn,7:zn,8:On,9:Dn,10:qt,11:wa,15:Ee},Om={0:{[B]:1,[O]:Zt},16:{[B]:2,[O]:oe(2,z[0][0])},32:{[B]:3,[O]:oe(3,z[0][1])},48:{[B]:4,[O]:oe(4,z[1][0],z[3][0])},64:{[B]:5,[O]:oe(5,z[1][1],z[3][0])},80:{[B]:6,[O]:oe(6,z[1][1],ot,z[3][0])},96:{[B]:7,[O]:oe(7,z[1][1],ot,z[3][4],z[2][0])},112:{[B]:8,[O]:oe(8,z[1][1],ot,z[3][0],z[2][0])},128:{[B]:2,[O]:`${Yt} (left, diff)`},144:{[B]:2,[O]:`${Yt} (diff, right)`},160:{[B]:2,[O]:`${Yt} (avg, diff)`},176:j,192:j,208:j,224:j,240:j},zm={0:ou,2:8,4:12,6:j,8:16,10:20,12:24,14:j},lr=class t extends Ne{static _decodeUTF8Int(e){if(e[0]>254)return null;if(e[0]<128)return{value:e[0],length:1};let r=1;for(let a=64;a&e[0];a>>=1)r++;let n=r-1,i=0,s=0;for(;n>0;s+=6,n--){if((e[n]&192)!==128)return null;i|=(e[n]&63)<<s}return i|=(e[n]&127>>r)<<s,{value:i,length:r}}static[Ze](e,r){let n={[Y]:function*(){return e}};return t[q](n,r,0).next().value}static*[q](e,r,n){let i=yield*e[Y](6,n);if(i[0]!==255||!(i[1]===248||i[1]===249))return null;let s={},a=Oe(i[V](0,4)),o=r[q](a);if(o)Object.assign(s,o);else{if(s[Ca]=i[1]&1,s[$i]=Bm[s[Ca]],s[Zi]=i[2]&240,s[ut]=i[2]&15,s[kt]=lu[s[Zi]],s[kt]===j||(s[K]=Dm[s[ut]],s[K]===Ee)||i[3]&1)return null;let l=Om[i[3]&240];if(l===j||(s[B]=l[B],s[Ae]=l[O],s[ve]=zm[i[3]&14],s[ve]===j))return null}s[C]=5,i=yield*e[Y](s[C]+8,n);let d=t._decodeUTF8Int(i[V](4));if(!d||(s[Ca]?s[es]=d.value:s[Bt]=d.value,s[C]+=d[C],s[Zi]===96?(i[C]<s[C]&&(i=yield*e[Y](s[C],n)),s[kt]=i[s[C]-1]+1,s[C]+=1):s[Zi]===112&&(i[C]<s[C]&&(i=yield*e[Y](s[C],n)),s[kt]=(i[s[C]-1]<<8)+i[s[C]]+1,s[C]+=2),s[$]=s[kt],s[ut]===12?(i[C]<s[C]&&(i=yield*e[Y](s[C],n)),s[K]=i[s[C]-1]*1e3,s[C]+=1):s[ut]===13?(i[C]<s[C]&&(i=yield*e[Y](s[C],n)),s[K]=(i[s[C]-1]<<8)+i[s[C]],s[C]+=2):s[ut]===14&&(i[C]<s[C]&&(i=yield*e[Y](s[C],n)),s[K]=((i[s[C]-1]<<8)+i[s[C]])*10,s[C]+=2),i[C]<s[C]&&(i=yield*e[Y](s[C],n)),s[Gn]=i[s[C]-1],s[Gn]!==jd(i[V](0,s[C]-1))))return null;if(!o){let{blockingStrategyBits:l,frameNumber:c,sampleNumber:f,samples:u,sampleRateBits:h,blockSizeBits:m,crc:g,length:p,...y}=s;r[Ke](a,s,y)}return new t(s)}constructor(e){super(e),this[Oi]=null,this[$i]=e[$i],this[kt]=e[kt],this[Bt]=e[Bt],this[es]=e[es],this[rs]=null}};var Nm=2,Um=512*1024,nn=class extends Le{constructor(e,r,n){super(e,r),this.Frame=or,this.Header=lr,n(this[te])}get[te](){return"flac"}*_getNextFrameSyncOffset(e){let r=yield*this._codecParser[Y](2,0),n=r[C]-2;for(;e<n;){if(r[e]===255){let s=r[e+1];if(s===248||s===249)break;s!==255&&e++}e++}return e}*[ht](){do{let e=yield*lr[q](this._codecParser,this._headerCache,0);if(e){let r=he.get(e)[C]+Nm;for(;r<=Um;){if(this._codecParser._flushing||(yield*lr[q](this._codecParser,this._headerCache,r))){let n=yield*this._codecParser[Y](r);if(this._codecParser._flushing||(n=n[V](0,r)),or[Ba](n)){let i=new or(n,e);return this._headerCache[nt](),this._codecParser[Xe](r),this._codecParser[nr](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)}[sr](e){return e[ue]===0?(this._headerCache[nt](),this._streamInfo=e[J][V](13)):e[ue]===1||(e[Se]=be.get(e)[We].map(r=>{let n=lr[Ze](r,this._headerCache);if(n)return new or(r,n,this._streamInfo);this._codecParser[tt]("Failed to parse Ogg FLAC frame","Skipping invalid FLAC frame")}).filter(r=>!!r)),e}};var sn=class t{static*[q](e,r,n){let i={},s=yield*e[Y](28,n);if(s[0]!==79||s[1]!==103||s[2]!==103||s[3]!==83||(i[Ml]=s[4],s[5]&248))return null;i[De]=!!(s[5]&4),i[Qt]=!!(s[5]&2),i[jt]=!!(s[5]&1);let o=new ar(Me.from(s[V](0,28))[lt]);i[et]=eu(o,6),i[ft]=o.getInt32(14,!0),i[ue]=o.getInt32(18,!0),i[Yr]=o.getInt32(22,!0);let d=s[26];i[C]=d+27,s=yield*e[Y](i[C],n),i[Re]=0,i[rr]=[],i[Xn]=Me.from(s[V](27,i[C]));for(let l=0,c=0;l<d;l++){let f=i[Xn][l];i[Re]+=f,c+=f,(f!==255||l===d-1)&&(i[rr].push(c),c=0)}return new t(i)}constructor(e){he.set(this,e),this[et]=e[et],this[jt]=e[jt],this[Qt]=e[Qt],this[De]=e[De],this[rr]=e[rr],this[ue]=e[ue],this[Yr]=e[Yr],this[ft]=e[ft]}};var ms=class t extends Jr{static*[$e](e,r,n){let i=yield*sn[q](e,r,n);if(i){let s=he.get(i)[Re],a=he.get(i)[C],o=a+s,d=(yield*e[Y](o,0))[V](0,o),l=d[V](a,o);return new t(i,l,d)}else return null}constructor(e,r,n){super(e,r),be.get(this)[C]=n[C],this[Se]=[],this[wl]=n,this[et]=e[et],this[zi]=e[Yr],this[ct]=0,this[jt]=e[jt],this[Qt]=e[Qt],this[De]=e[De],this[ue]=e[ue],this[$]=0,this[ft]=e[ft]}};var $n=class extends ze{constructor(e,r,n){super(r,e,n)}};var cu={0:ki.slice(0,2),1:ki},Ye="SILK-only",xe="CELT-only",Ka="Hybrid",cr="narrowband",$a="medium-band",dr="wideband",Zn="super-wideband",Yn="fullband",Hm={0:{[U]:Ye,[H]:cr,[N]:10},8:{[U]:Ye,[H]:cr,[N]:20},16:{[U]:Ye,[H]:cr,[N]:40},24:{[U]:Ye,[H]:cr,[N]:60},32:{[U]:Ye,[H]:$a,[N]:10},40:{[U]:Ye,[H]:$a,[N]:20},48:{[U]:Ye,[H]:$a,[N]:40},56:{[U]:Ye,[H]:$a,[N]:60},64:{[U]:Ye,[H]:dr,[N]:10},72:{[U]:Ye,[H]:dr,[N]:20},80:{[U]:Ye,[H]:dr,[N]:40},88:{[U]:Ye,[H]:dr,[N]:60},96:{[U]:Ka,[H]:Zn,[N]:10},104:{[U]:Ka,[H]:Zn,[N]:20},112:{[U]:Ka,[H]:Yn,[N]:10},120:{[U]:Ka,[H]:Yn,[N]:20},128:{[U]:xe,[H]:cr,[N]:2.5},136:{[U]:xe,[H]:cr,[N]:5},144:{[U]:xe,[H]:cr,[N]:10},152:{[U]:xe,[H]:cr,[N]:20},160:{[U]:xe,[H]:dr,[N]:2.5},168:{[U]:xe,[H]:dr,[N]:5},176:{[U]:xe,[H]:dr,[N]:10},184:{[U]:xe,[H]:dr,[N]:20},192:{[U]:xe,[H]:Zn,[N]:2.5},200:{[U]:xe,[H]:Zn,[N]:5},208:{[U]:xe,[H]:Zn,[N]:10},216:{[U]:xe,[H]:Zn,[N]:20},224:{[U]:xe,[H]:Yn,[N]:2.5},232:{[U]:xe,[H]:Yn,[N]:5},240:{[U]:xe,[H]:Yn,[N]:10},248:{[U]:xe,[H]:Yn,[N]:20}},qn=class t extends Ne{static[Ze](e,r,n){let i={};if(i[B]=e[9],i[Rt]=e[18],i[C]=i[Rt]!==0?21+i[B]:19,e[C]<i[C])throw new Error("Out of data while inside an Ogg Page");let s=r[0]&3,a=s===3?2:1,o=Oe(e[V](0,i[C]))+Oe(r[V](0,a)),d=n[q](o);if(d)return new t(d);if(o.substr(0,8)!=="OpusHead"||e[8]!==1)return null;i[J]=Me.from(e[V](0,i[C]));let l=new ar(i[J][lt]);if(i[ve]=16,i[$r]=l.getUint16(10,!0),i[Ji]=l.getUint32(12,!0),i[K]=qt,i[Wi]=l.getInt16(16,!0),i[Rt]in cu&&(i[Ae]=cu[i[Rt]][i[B]-1],!i[Ae]))return null;i[Rt]!==0&&(i[ts]=e[19],i[Di]=e[20],i[Yi]=[...e[V](21,i[B]+21)]);let c=Hm[248&r[0]];switch(i[U]=c[U],i[H]=c[H],i[N]=c[N],s){case 0:i[Ft]=1;break;case 1:case 2:i[Ft]=2;break;case 3:i[Gi]=!!(128&r[1]),i[Ni]=!!(64&r[1]),i[Ft]=63&r[1];break;default:return null}{let{length:f,data:u,channelMappingFamily:h,...m}=i;n[Ke](o,i,m)}return new t(i)}constructor(e){super(e),this[J]=e[J],this[H]=e[H],this[Rt]=e[Rt],this[Yi]=e[Yi],this[Di]=e[Di],this[Ft]=e[Ft],this[N]=e[N],this[Ni]=e[Ni],this[Ji]=e[Ji],this[Gi]=e[Gi],this[U]=e[U],this[Wi]=e[Wi],this[$r]=e[$r],this[ts]=e[ts]}};var ps=class extends Le{constructor(e,r,n){super(e,r),this.Frame=$n,this.Header=qn,n(this[te]),this._identificationHeader=null,this._preSkipRemaining=null}get[te](){return"opus"}[sr](e){return e[ue]===0?(this._headerCache[nt](),this._identificationHeader=e[J]):e[ue]===1||(e[Se]=be.get(e)[We].map(r=>{let n=qn[Ze](this._identificationHeader,r,this._headerCache);if(n){this._preSkipRemaining===null&&(this._preSkipRemaining=n[$r]);let i=n[N]*n[Ft]/1e3*n[K];return this._preSkipRemaining>0&&(this._preSkipRemaining-=i,i=this._preSkipRemaining<0?-this._preSkipRemaining:0),new $n(r,n,i)}this._codecParser[Pa]("Failed to parse Ogg Opus Header","Not a valid Ogg Opus file")})),e}};var jn=class extends ze{constructor(e,r,n){super(r,e,n)}};var Bl={};for(let t=0;t<8;t++)Bl[t+6]=2**(6+t);var gs=class t extends Ne{static[Ze](e,r,n,i){if(e[C]<30)throw new Error("Out of data while inside an Ogg Page");let s=Oe(e[V](0,30)),a=r[q](s);if(a)return new t(a);let o={[C]:30};if(s.substr(0,7)!=="vorbis")return null;o[J]=Me.from(e[V](0,30));let d=new ar(o[J][lt]);if(o[Jt]=d.getUint32(7,!0),o[Jt]!==0||(o[B]=e[11],o[Ae]=ki[o[B]-1]||"application defined",o[K]=d.getUint32(12,!0),o[Ri]=d.getInt32(16,!0),o[Fi]=d.getInt32(20,!0),o[Pi]=d.getInt32(24,!0),o[tr]=Bl[(e[28]&240)>>4],o[er]=Bl[e[28]&15],o[er]>o[tr])||e[29]!==1)return null;o[ve]=32,o[Wn]=i,o[Ki]=n;{let{length:l,data:c,version:f,vorbisSetup:u,vorbisComments:h,...m}=o;r[Ke](s,o,m)}return new t(o)}constructor(e){super(e),this[Ri]=e[Ri],this[Pi]=e[Pi],this[Fi]=e[Fi],this[er]=e[er],this[tr]=e[tr],this[J]=e[J],this[Ki]=e[Ki],this[Wn]=e[Wn]}};var ys=class extends Le{constructor(e,r,n){super(e,r),this.Frame=jn,n(this[te]),this._identificationHeader=null,this._setupComplete=!1,this._prevBlockSize=null}get[te](){return Zr}[sr](e){e[Se]=[];for(let r of be.get(e)[We])if(r[0]===1)this._headerCache[nt](),this._identificationHeader=e[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=gs[Ze](this._identificationHeader,this._headerCache,this._vorbisComments,this._vorbisSetup);n?e[Se].push(new jn(r,n,this._getSamples(r,n))):this._codecParser[logError]("Failed to parse Ogg Vorbis Header","Not a valid Ogg Vorbis file")}return e}_getSamples(e,r){let i=this._mode.blockFlags[e[0]>>1&this._mode.mask]?r[tr]:r[er],s=this._prevBlockSize===null?0:(this._prevBlockSize+i)/4;return this._prevBlockSize=i,s}_parseSetupHeader(e){let r=new Oa(e),n={count:0,blockFlags:[]};for(;(r.read(1)&1)!==1;);let i;for(;n.count<64&&r.position>0;){ss(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{((ss(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 Dl=class{constructor(e,r,n){this._codecParser=e,this._headerCache=r,this._onCodec=n,this._continuedPacket=new Me,this._codec=null,this._isSupported=null,this._previousAbsoluteGranulePosition=null}get[te](){return this._codec||""}_updateCodec(e,r){this._codec!==e&&(this._headerCache[rt](),this._parser=new r(this._codecParser,this._headerCache,this._onCodec),this._codec=e)}_checkCodecSupport({data:e}){let r=Oe(e[V](0,8));switch(r){case"fishead\0":return!1;case"OpusHead":return this._updateCodec("opus",ps),!0;case(/^\x7fFLAC/.test(r)&&r):return this._updateCodec("flac",nn),!0;case(/^\x01vorbis/.test(r)&&r):return this._updateCodec(Zr,ys),!0;default:return!1}}_checkPageSequenceNumber(e){e[ue]!==this._pageSequenceNumber+1&&this._pageSequenceNumber>1&&e[ue]>1&&this._codecParser[tt]("Unexpected gap in Ogg Page Sequence Number.",`Expected: ${this._pageSequenceNumber+1}, Got: ${e[ue]}`),this._pageSequenceNumber=e[ue]}_parsePage(e){this._isSupported===null&&(this._pageSequenceNumber=e[ue],this._isSupported=this._checkCodecSupport(e)),this._checkPageSequenceNumber(e);let r=be.get(e),n=he.get(r[Be]),i=0;if(r[We]=n[rr].map(s=>e[J][V](i,i+=s)),this._continuedPacket[C]&&(r[We][0]=as(this._continuedPacket,r[We][0]),this._continuedPacket=new Me),n[Xn][n[Xn][C]-1]===255&&(this._continuedPacket=as(this._continuedPacket,r[We].pop())),this._previousAbsoluteGranulePosition!==null&&(e[$]=Number(e[et]-this._previousAbsoluteGranulePosition)),this._previousAbsoluteGranulePosition=e[et],this._isSupported){let s=this._parser[sr](e);return this._codecParser[nr](s),s}else return e}},bs=class extends Le{constructor(e,r,n){super(e,r),this._onCodec=n,this.Frame=ms,this.Header=sn,this._streams=new Map,this._currentSerialNumber=null}get[te](){let e=this._streams.get(this._currentSerialNumber);return e?e.codec:""}*[ht](){let e=yield*this[ir](!0);this._currentSerialNumber=e[ft];let r=this._streams.get(this._currentSerialNumber);return r||(r=new Dl(this._codecParser,this._headerCache,this._onCodec),this._streams.set(this._currentSerialNumber,r)),e[De]&&this._streams.delete(this._currentSerialNumber),r._parsePage(e)}};var Ol=()=>{},xs=class{constructor(e,{onCodec:r,onCodecHeader:n,onCodecUpdate:i,enableLogging:s=!1,enableFrameCRC32:a=!0}={}){this._inputMimeType=e,this._onCodec=r||Ol,this._onCodecHeader=n||Ol,this._onCodecUpdate=i,this._enableLogging=s,this._crc32=a?Jd:Ol,this[rt]()}get[te](){return this._parser?this._parser[te]:""}[rt](){this._headerCache=new os(this._onCodecHeader,this._onCodecUpdate),this._generator=this._getGenerator(),this._generator.next()}*flush(){this._flushing=!0;for(let e=this._generator.next();e.value;e=this._generator.next())yield e.value;this._flushing=!1,this[rt]()}*parseChunk(e){for(let r=this._generator.next(e);r.value;r=this._generator.next())yield r.value}parseAll(e){return[...this.parseChunk(e),...this.flush()]}*_getGenerator(){if(this._inputMimeType.match(/aac/))this._parser=new hs(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/mpeg/))this._parser=new us(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/flac/))this._parser=new nn(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/ogg/))this._parser=new bs(this,this._headerCache,this._onCodec);else throw new Error(`Unsupported Codec ${mimeType}`);for(this._frameNumber=0,this._currentReadPosition=0,this._totalBytesIn=0,this._totalBytesOut=0,this._totalSamples=0,this._sampleRate=void 0,this._rawData=new Uint8Array(0);;){let e=yield*this._parser[ht]();e&&(yield e)}}*[Y](e=0,r=0){let n;for(;this._rawData[C]<=e+r;){if(n=yield,this._flushing)return this._rawData[V](r);n&&(this._totalBytesIn+=n[C],this._rawData=as(this._rawData,n))}return this._rawData[V](r)}[Xe](e){this._currentReadPosition+=e,this._rawData=this._rawData[V](e)}[ns](e){this._sampleRate=e[Be][K],e[Be][we]=e[ct]>0?Math.round(e[J][C]/e[ct])*8:0,e[Bt]=this._frameNumber++,e[qr]=this._totalBytesOut,e[Qr]=this._totalSamples,e[jr]=this._totalSamples/this._sampleRate*1e3,e[zi]=this._crc32(e[J]),this._headerCache[Fa](e[Be][we],e[jr]),this._totalBytesOut+=e[J][C],this._totalSamples+=e[$]}[nr](e){if(e[Se]){if(e[De]){let r=e[$];e[Se].forEach(n=>{let i=n[$];r<i&&(n[$]=r>0?r:0,n[ct]=n[$]/n[Be][K]*1e3),r-=i,this[ns](n)})}else e[$]=0,e[Se].forEach(r=>{e[$]+=r[$],this[ns](r)});e[ct]=e[$]/this._sampleRate*1e3||0,e[Qr]=this._totalSamples,e[jr]=this._totalSamples/this._sampleRate*1e3||0,e[qr]=this._totalBytesOut}else this[ns](e)}_log(e,r){if(this._enableLogging){let n=[`${te}: ${this[te]}`,`inputMimeType: ${this._inputMimeType}`,`readPosition: ${this._currentReadPosition}`,`totalBytesIn: ${this._totalBytesIn}`,`${qr}: ${this._totalBytesOut}`],i=Math.max(...n.map(s=>s[C]));r.push(`--stats--${"-".repeat(i-9)}`,...n,"-".repeat(i)),e("codec-parser",r.reduce((s,a)=>s+`
|
|
4
4
|
`+a,""))}}[tt](...e){this._log(console.warn,e)}[Pa](...e){this._log(console.error,e)}};var du=xs;var Za=Se;var Ya=J;var uu=Be;var fu=De;var hu=Wn;var mu=Qr;function Dt(t){var e=e;function r(){}e={};function n(P){throw P}var i,s,a,o,d,l,c,f,u,h,m;function g(){var P=m.buffer;i=new Int8Array(P),s=new Int16Array(P),o=new Uint8Array(P),d=new Uint16Array(P),a=new Int32Array(P),l=new Uint32Array(P),c=new Float32Array(P),f=new Float64Array(P),u=new BigInt64Array(P),h=new BigUint64Array(P)}for(var p=P=>{for(var Ge,yi,bn=0,Qs=0,Js=P.length,ea=new Uint8Array((Js*3>>2)-(P[Js-2]=="=")-(P[Js-1]=="="));bn<Js;bn+=4,Qs+=3)Ge=G[P.charCodeAt(bn+1)],yi=G[P.charCodeAt(bn+2)],ea[Qs]=G[P.charCodeAt(bn)]<<2|Ge>>4,ea[Qs+1]=Ge<<4|yi>>2,ea[Qs+2]=yi<<6|G[P.charCodeAt(bn+3)];return ea},y=()=>n(""),_=()=>{},x={},b=P=>P(),v=()=>performance.now(),S=(P,Ge)=>{if(x[P]&&(clearTimeout(x[P].id),delete x[P]),!Ge)return 0;var yi=setTimeout(()=>{delete x[P],b(()=>rd(P,v()))},Ge);return x[P]={id:yi,timeout_ms:Ge},0},w=Math.atan,L=Math.cos,T=Math.exp,A=Math.log,I=Math.pow,R=Math.sin,F=P=>{var Ge=o.length;return P>>>=0,!1},k=P=>{throw`exit(${P})`},G=new Uint8Array(123),se=25;se>=0;--se)G[48+se]=52+se,G[65+se]=se,G[97+se]=26+se;G[43]=62,G[47]=63;var Ur={e:y,d:_,f:S,b:w,a:L,i:T,h:A,g:I,c:R,k:F,j:k};function js(P){gi=P.n,qc=P.o,jc=P.p,Qc=P.q,Jc=P.r,ed=P.s,td=P.t,rd=P.v}var gi,qc,jc,Qc,Jc,ed,td,rd;function Uh(P){P.m()}Dt.wasm||Object.defineProperty(Dt,"wasm",{get:()=>String.raw`dynEncode012091253f87dì%nä= 4&¿nÝØäÂLÚªã9ÚØ[äº\ ¼¡³R=}L]Èÿ2 ÿù¶J1jj¡é,zäV|i¸Qk¹=
|
|
@@ -138,7 +138,7 @@ KÙ:KµºKí{K]ûK£[KÚKóKÓ½R׿ÿ'P^j9TîçmóþL¿_o©×hÙtÙ
|
|
|
138
138
|
Ái;ªäÀ%n= =M+W= ÓÖc[aS
|
|
139
139
|
FÁð]NôÝ'= qr(¶ù¤nü«òÿ¿d&ÿÈõT4Þ=}z|ö ¿OW×SMtdH.ÏãRX&§o3ØÜXÍ^ÊMí£W´iâ]NüOå£S£Å·ç÷ݧ½GÑUy¹¦ß§/6P0(Cúýb"þ¥°VÙÄá£ÓÙ@¾YýòD{òÃv?EP©=MBé\ĽYäýRò øfâëEEf¼D+gC×úDZGÅÿ±Ç?TzÙ¡±ÏÁÕ¯¦ðvZmT}3xËz×cºrÑM=Mc-É©Ô7½wæc§Î»cû¾yfÙWòÆÝÔc¥³ôØf«Äñ·9ø%g:y^+{U]¤þ
[&fÓÏYë«Gªõ¹¦Öðþ¬moÛø?/ÛS.[S9ÛùC
/û2²Y£ÎÑ%/sy¢×ÌùJW6Oí\g0^JùêßÏ0í[Ü'ÏÔ>À-¿[ÔW?Y]±ØÙÃî<~ÎëR~Ìf¾Z/×¼_á¾Þê+îoÐñ{Þ\e3K%©¹§íB¹§(c=}ËÈ·SzÔnf§èx}o\9öf|%Ýå¥~©IÇüñY8}Ffú@Rú1éþ3÷ËótQøvû|³Îaá,Óé>BG6Òê}ÃJ|¶=}°öf6õk¶ÌºHgNjÒ{æ¾M;9·é§WèO±Ä3ÒËÒyt ;ù´à©a|Ó^!ÝøûÂÄ
|
|
140
140
|
(VV¸ÇÙcÏ>yoçzÃvòG{3Þ£½c×ôíÅé;°OÛGØ<wÜW> rU]q{û'ùÝír{*øï?t-ígùWÿ
&§]m}×ût¥Ë~ß&>&Õv!b#ÅÌq¢µ|jÍüùÉ^Æ&ôþ~sIµ"]d)uâ´ºvk Å\<Íÿöê½Â
|
|
141
|
-
ïBçϧmÙIólÜoëVb¦¯éWÇû3`});var Hh={a:Ur};this.setModule=P=>{t.setModule(Dt,P)},this.getModule=()=>t.getModule(Dt),this.instantiate=()=>(this.getModule().then(P=>WebAssembly.instantiate(P,Hh)).then(P=>{let Ge=P.exports;js(Ge),m=Ge.l,g(),Uh(Ge),r()}),this.ready=new Promise(P=>{r=P}).then(()=>{this.HEAP=m.buffer,this.malloc=qc,this.free=td,this.create_decoder=gi,this.send_setup=jc,this.init_dsp=Qc,this.decode_packets=Jc,this.destroy_decoder=ed}),this)}function an(){return this._init=()=>new this._WASMAudioDecoderCommon().instantiate(this._EmscriptenWASM,this._module).then(t=>{this._common=t,this._input=this._common.allocateTypedArray(this._inputSize,Uint8Array),this._firstPage=!0,this._inputLen=this._common.allocateTypedArray(1,Uint32Array),this._outputBufferPtr=this._common.allocateTypedArray(1,Uint32Array),this._channels=this._common.allocateTypedArray(1,Uint32Array),this._sampleRate=this._common.allocateTypedArray(1,Uint32Array),this._samplesDecoded=this._common.allocateTypedArray(1,Uint32Array);let e=256;this._errors=this._common.allocateTypedArray(e,Uint32Array),this._errorsLength=this._common.allocateTypedArray(1,Int32Array),this._frameNumber=0,this._inputBytes=0,this._outputSamples=0,this._decoder=this._common.wasm.create_decoder(this._input.ptr,this._inputLen.ptr,this._outputBufferPtr.ptr,this._channels.ptr,this._sampleRate.ptr,this._samplesDecoded.ptr,this._errors.ptr,this._errorsLength.ptr,e)}),Object.defineProperty(this,"ready",{enumerable:!0,get:()=>this._ready}),this.reset=()=>(this.free(),this._init()),this.free=()=>{this._common.wasm.destroy_decoder(this._decoder),this._common.free()},this.sendSetupHeader=t=>{this._input.buf.set(t),this._inputLen.buf[0]=t.length,this._common.wasm.send_setup(this._decoder,this._firstPage),this._firstPage=!1},this.initDsp=()=>{this._common.wasm.init_dsp(this._decoder)},this.decodePackets=t=>{let e=[],r=0,n=[];for(let i=0;i<t.length;i++){let s=t[i];this._input.buf.set(s),this._inputLen.buf[0]=s.length,this._common.wasm.decode_packets(this._decoder);let a=this._samplesDecoded.buf[0],o=[],d=new Uint32Array(this._common.wasm.HEAP,this._outputBufferPtr.buf[0],this._channels.buf[0]);for(let l=0;l<this._channels.buf[0];l++){let c=new Float32Array(a);a&&c.set(new Float32Array(this._common.wasm.HEAP,d[l],a)),o.push(c)}e.push(o),r+=a,this._frameNumber++,this._inputBytes+=s.length,this._outputSamples+=a;for(let l=0;l<this._errorsLength.buf;l+=2){let c=this._common.codeToString(this._errors.buf[l]),f=this._common.codeToString(this._errors.buf[l+1]);n.push({message:c+" vorbis_synthesis"+f,frameLength:s.length,frameNumber:this._frameNumber,inputBytes:this._inputBytes,outputSamples:this._outputSamples})}this._errorsLength.buf[0]=0}return this._WASMAudioDecoderCommon.getDecodedAudioMultiChannel(n,e,this._channels.buf[0],r,this._sampleRate.buf[0],16)},this._isWebWorker=an.isWebWorker,this._WASMAudioDecoderCommon=an.WASMAudioDecoderCommon||re,this._EmscriptenWASM=an.EmscriptenWASM||Dt,this._module=an.module,this._inputSize=128*1024,this._ready=this._init(),this}var qa=Symbol(),Ot=class{constructor(){this._onCodec=e=>{if(e!=="vorbis")throw new Error("@wasm-audio-decoders/ogg-vorbis does not support this codec "+e)},new re,this._init(),this._ready=this[qa](an)}_init(){this._vorbisSetupInProgress=!0,this._totalSamplesDecoded=0,this._codecParser=new du("audio/ogg",{onCodec:this._onCodec,enableFrameCRC32:!1})}async[qa](e){if(this._decoder){let r=this._decoder;await r.ready.then(()=>r.free())}return this._decoder=new e,this._decoder.ready}get ready(){return this._ready}async reset(){return this._init(),this._decoder.reset()}free(){this._decoder.free()}async decodeOggPages(e){let r=[];for(let s=0;s<e.length;s++){let a=e[s];if(this._vorbisSetupInProgress&&(a[Ya][0]===1&&this._decoder.sendSetupHeader(a[Ya]),a[Za].length)){let o=a[Za][0][uu];this._decoder.sendSetupHeader(o[hu]),this._decoder.initDsp(),this._vorbisSetupInProgress=!1}r.push(...a[Za].map(o=>o[Ya]))}let n=await this._decoder.decodePackets(r);this._totalSamplesDecoded+=n.samplesDecoded;let i=e[e.length-1];if(i&&i[fu]){let s=this._totalSamplesDecoded-i[mu];if(s>0){for(let a=0;a<n.channelData.length;a++)n.channelData[a]=n.channelData[a].subarray(0,n.samplesDecoded-s);n.samplesDecoded-=s,this._totalSamplesDecoded-=s}}return n}async decode(e){return this.decodeOggPages([...this._codecParser.parseChunk(e)])}async flush(){let e=await this.decodeOggPages([...this._codecParser.flush()]);return await this.reset(),e}async decodeFile(e){let r=await this.decodeOggPages([...this._codecParser.parseAll(e)]);return await this.reset(),r}};var zl=class extends Bn{constructor(e){super(e,"ogg-vorbis-decoder",an,Dt)}async sendSetupHeader(e){return this.postToDecoder("sendSetupHeader",e)}async initDsp(){return this.postToDecoder("initDsp")}async decodePackets(e){return this.postToDecoder("decodePackets",e)}},_s=class extends Ot{constructor(){super(),this._ready=super[qa](zl)}async free(){await this._decoder.free()}terminate(){this._decoder.terminate()}};va(Ot,"OggVorbisDecoder");va(_s,"OggVorbisDecoderWebWorker");var Nl=class extends Error{constructor(e){super(e),this.name="OggDecodeError"}};async function ja(t,e=new Ot){await e.ready;let r=await e.decode(new Uint8Array(t)),n=r.errors;if(n&&n.length>0)throw new Nl(n.map(i=>i.message).join("; "));return{sampleRate:r.sampleRate,channels:r.channelData.length,bitDepth:r.bitDepth,channelData:r.channelData}}var vs=class extends Error{constructor(e){super(e),this.name="AudioRegistryError"}},Qn=class{constructor(e,r={}){this.vfs=e;this.refCounts=new Map;this.cache=new Kt(r.cacheSize??64)}get size(){return this.cache.size}async load(e){let r=e.toLowerCase(),n=this.cache.get(r);if(n)return this.refCounts.set(r,(this.refCounts.get(r)??0)+1),n;let s=(await this.vfs.readFile(e)).slice().buffer,a=await this.decodeByExtension(e,s);return this.cache.set(r,a),this.refCounts.set(r,1),a}release(e){let r=e.toLowerCase(),n=this.refCounts.get(r)??0;n<=1?(this.cache.delete(r),this.refCounts.delete(r)):this.refCounts.set(r,n-1)}clearAll(){this.cache.clear(),this.refCounts.clear()}async decodeByExtension(e,r){let n=e.toLowerCase();if(n.endsWith(".wav")){let i=_a(r),s=i.channels,a=Array.from({length:s},()=>new Float32Array(i.samples.length/s));for(let o=0;o<i.samples.length;o+=1)a[o%s][Math.floor(o/s)]=i.samples[o];return{sampleRate:i.sampleRate,channels:s,bitDepth:i.bitsPerSample,channelData:a}}if(n.endsWith(".ogg")||n.endsWith(".oga"))return ja(r);throw new vs(`Unsupported audio format: ${e}`)}};var Gm="quake2ts-pak-indexes",Vm="pak-indexes";function pu(){if(typeof indexedDB<"u")return indexedDB;if(typeof window<"u"&&"indexedDB"in window)return window.indexedDB;if(typeof globalThis<"u"&&"indexedDB"in globalThis)return globalThis.indexedDB}function ws(t,e){let r=pu();return r?new Promise((n,i)=>{let s=r.open(t,1);s.onupgradeneeded=()=>{let{result:a}=s;a.objectStoreNames.contains(e)||a.createObjectStore(e,{keyPath:"key"})},s.onerror=()=>i(s.error??new Error("Unknown IndexedDB error")),s.onsuccess=()=>n(s.result)}):Promise.reject(new Error("IndexedDB is not available in this environment"))}function Ss(t,e,r,n){return new Promise((i,s)=>{let o=t.transaction(e,r).objectStore(e),d=n(o);d.onsuccess=()=>i(d.result),d.onerror=()=>s(d.error??new Error("IndexedDB transaction error"))})}function Ul(t,e){return`${ae(t)}:${e.toString(16)}`}function Wm(t){return t.map(e=>({...e}))}var Qa=class{constructor(e=Gm,r=Vm){this.dbName=e;this.storeName=r}get isSupported(){return!!pu()}async persist(e){if(!this.isSupported)return;let r=e.validate(),n={...r,key:Ul(e.name,r.checksum),name:e.name,size:e.size,persistedAt:Date.now(),entries:Wm(r.entries)},i=await ws(this.dbName,this.storeName);return await Ss(i,this.storeName,"readwrite",s=>s.put(n)),i.close(),n}async find(e,r){if(!this.isSupported)return;let n=await ws(this.dbName,this.storeName),i=r!==void 0?Ul(e,r):void 0,s=await Ss(n,this.storeName,"readonly",a=>i?a.get(i):a.getAll());if(n.close(),!!s){if(Array.isArray(s)){let a=ae(e),o=s.filter(d=>ae(d.name)===a);return o.length===0?void 0:o.sort((d,l)=>l.persistedAt-d.persistedAt)[0]}return s}}async remove(e,r){if(!this.isSupported)return!1;let n=await ws(this.dbName,this.storeName),i=r!==void 0?Ul(e,r):void 0,s=await Ss(n,this.storeName,"readwrite",a=>{if(i)return a.delete(i);let o=`${ae(e)}:`;return a.delete(IDBKeyRange.bound(o,`${o}\uFFFF`,!1,!0))});return n.close(),typeof s=="number"?s>0:!0}async clear(){if(!this.isSupported)return;let e=await ws(this.dbName,this.storeName);await Ss(e,this.storeName,"readwrite",r=>r.clear()),e.close()}async list(){if(!this.isSupported)return[];let e=await ws(this.dbName,this.storeName),r=await Ss(e,this.storeName,"readonly",n=>n.getAll());return e.close(),r.sort((n,i)=>i.persistedAt-n.persistedAt)}};var on=class extends Error{constructor(r,n){super(n??`Missing dependencies: ${r.join(", ")}`);this.missing=r;this.name="AssetDependencyError"}},As=class{constructor(){this.nodes=new Map}register(e,r=[]){let n=this.nodes.get(e)??{dependencies:new Set,loaded:!1};r.forEach(i=>n.dependencies.add(i)),this.nodes.set(e,n),r.forEach(i=>{this.nodes.has(i)||this.nodes.set(i,{dependencies:new Set,loaded:!1})})}markLoaded(e){let r=this.nodes.get(e)??{dependencies:new Set,loaded:!1},n=this.getMissingDependencies(e,r);if(n.length>0)throw new on(n,`Asset ${e} is missing dependencies: ${n.join(", ")}`);r.loaded=!0,this.nodes.set(e,r)}markUnloaded(e){let r=this.nodes.get(e);r&&(r.loaded=!1)}isLoaded(e){return this.nodes.get(e)?.loaded??!1}missingDependencies(e){let r=this.nodes.get(e);return r?this.getMissingDependencies(e,r):[]}reset(){this.nodes.clear()}getMissingDependencies(e,r){let n=[];for(let i of r.dependencies)this.nodes.get(i)?.loaded||n.push(i);return n}},Ja=class{constructor(e,r={}){this.vfs=e;this.maps=new Map;this.loadQueue=[];this.activeLoads=0;this.textures=new Fn({capacity:r.textureCacheCapacity??128,maxMemory:r.textureMemoryLimit}),this.audio=new Qn(e,{cacheSize:r.audioCacheSize??64}),this.dependencyTracker=r.dependencyTracker??new As,this.resourceTracker=r.resourceTracker,this.md2=new kn(e),this.md3=new Rn(e),this.sprite=new Pn(e),this.bsp=new In(e),this.maxConcurrentLoads=r.maxConcurrentLoads??4,this.palette=new Uint8Array(768);for(let n=0;n<256;n++)this.palette[n*3]=n,this.palette[n*3+1]=n,this.palette[n*3+2]=n}async loadPalette(e="pics/colormap.pcx"){try{let r=await this.vfs.readFile(e),n=Ci(r);n.palette&&(this.palette=n.palette)}catch(r){console.warn(`Failed to load palette from ${e}:`,r)}}isAssetLoaded(e,r){return this.dependencyTracker.isLoaded(this.makeKey(e,r))}registerTexture(e,r){this.textures.set(e,r);let n=this.makeKey("texture",e);this.dependencyTracker.register(n),this.dependencyTracker.markLoaded(n)}async loadTexture(e){if(this.resourceTracker){let a=this.vfs.stat(e);this.resourceTracker.recordLoad("texture",e,a?.size,a?.sourcePak)}let r=this.textures.get(e);if(r)return r;let n=await this.vfs.readFile(e),i=e.split(".").pop()?.toLowerCase(),s;if(i==="wal")s=xa(n,this.palette);else if(i==="pcx")s=ba(Ci(n));else if(i==="tga")s=Nd(bl(n));else throw new Error(`Unsupported texture format for loadTexture: ${i}`);return this.registerTexture(e,s),s}async loadSound(e){if(this.resourceTracker){let i=this.vfs.stat(e);this.resourceTracker.recordLoad("sound",e,i?.size,i?.sourcePak)}let r=await this.audio.load(e),n=this.makeKey("sound",e);return this.dependencyTracker.register(n),this.dependencyTracker.markLoaded(n),r}async loadMd2Model(e,r=[]){if(this.resourceTracker){let o=this.vfs.stat(e);this.resourceTracker.recordLoad("model",e,o?.size,o?.sourcePak)}let n=this.makeKey("model",e),i=r.map(o=>this.makeKey("texture",o));this.dependencyTracker.register(n,i);let s=this.dependencyTracker.missingDependencies(n);if(s.length>0)throw new on(s,`Asset ${n} is missing dependencies: ${s.join(", ")}`);let a=await this.md2.load(e);return this.dependencyTracker.markLoaded(n),a}getMd2Model(e){if(this.resourceTracker){let r=this.vfs.stat(e);this.resourceTracker.recordLoad("model",e,r?.size,r?.sourcePak)}return this.md2.get(e)}async loadMd3Model(e,r=[]){if(this.resourceTracker){let o=this.vfs.stat(e);this.resourceTracker.recordLoad("model",e,o?.size,o?.sourcePak)}let n=this.makeKey("model",e),i=r.map(o=>this.makeKey("texture",o));this.dependencyTracker.register(n,i);let s=this.dependencyTracker.missingDependencies(n);if(s.length>0)throw new on(s,`Asset ${n} is missing dependencies: ${s.join(", ")}`);let a=await this.md3.load(e);return this.dependencyTracker.markLoaded(n),a}getMd3Model(e){if(this.resourceTracker){let r=this.vfs.stat(e);this.resourceTracker.recordLoad("model",e,r?.size,r?.sourcePak)}return this.md3.get(e)}async loadSprite(e){if(this.resourceTracker){let i=this.vfs.stat(e);this.resourceTracker.recordLoad("sprite",e,i?.size,i?.sourcePak)}let r=this.makeKey("sprite",e);this.dependencyTracker.register(r);let n=await this.sprite.load(e);return this.dependencyTracker.markLoaded(r),n}async loadMap(e){if(this.resourceTracker){let i=this.vfs.stat(e);this.resourceTracker.recordLoad("map",e,i?.size,i?.sourcePak)}let r=this.makeKey("map",e);if(this.maps.has(e))return this.maps.get(e);this.dependencyTracker.register(r);let n=await this.bsp.load(e);return this.maps.set(e,n),this.dependencyTracker.markLoaded(r),n}getMap(e){return this.maps.get(e)}listFiles(e){return this.vfs.findByExtension(e)}resetForLevelChange(){this.textures.clear(),this.audio.clearAll(),this.dependencyTracker.reset(),this.maps.clear(),this.loadQueue.length=0}getMemoryUsage(){let e=0,r=0;if(typeof process<"u"&&process.memoryUsage){let n=process.memoryUsage();e=n.heapTotal,r=n.heapUsed}return{textures:this.textures.memoryUsage,audio:0,heapTotal:e,heapUsed:r}}clearCache(e){switch(e){case"texture":this.textures.clear();break;case"sound":this.audio.clearAll();break;case"map":this.maps.clear();break}}async preloadAssets(e){let r=e.map(n=>{let i=this.detectAssetType(n);return i?this.queueLoad(n,i,0):Promise.resolve()});await Promise.all(r)}queueLoad(e,r,n=1){return r==="texture"&&this.textures.get(e)?Promise.resolve(this.textures.get(e)):new Promise((i,s)=>{this.loadQueue.push({path:e,type:r,priority:n,resolve:i,reject:s}),this.loadQueue.sort((a,o)=>o.priority-a.priority),this.processQueue()})}async processQueue(){if(this.activeLoads>=this.maxConcurrentLoads||this.loadQueue.length===0)return;let e=this.loadQueue.shift();this.activeLoads++;try{let r;switch(e.type){case"texture":r=await this.loadTexture(e.path);break;case"sound":r=await this.loadSound(e.path);break;case"model":e.path.endsWith(".md2")?r=await this.loadMd2Model(e.path):e.path.endsWith(".md3")&&(r=await this.loadMd3Model(e.path));break;case"sprite":r=await this.loadSprite(e.path);break;case"map":r=await this.loadMap(e.path);break;default:throw new Error(`Unknown asset type ${e.type}`)}e.resolve(r)}catch(r){e.reject(r)}finally{this.activeLoads--,this.processQueue()}}detectAssetType(e){let r=e.split(".").pop()?.toLowerCase();return r?["wal","pcx","tga","png","jpg"].includes(r)?"texture":["wav","ogg"].includes(r)?"sound":["md2","md3"].includes(r)?"model":["sp2"].includes(r)?"sprite":["bsp"].includes(r)?"map":null:null}makeKey(e,r){return`${e}:${ae(r)}`}};var eo=class{constructor(e){this.factory=e}getContext(){return this.context||(this.context=this.factory()),this.context}async resume(){let e=this.getContext();e.state==="suspended"&&await e.resume()}getState(){return this.context?.state??"suspended"}};function to(t){let e=t.getContext(),r=e.createGain();r.gain.value=1;let n=e.createDynamicsCompressor(),i=e.createBiquadFilter?.(),s;if(e.createConvolver&&e.createGain){let a=e.createConvolver(),o=e.createGain(),d=e.createGain();o.connect(a),a.connect(d),s={convolver:a,input:o,output:d}}return i?(i.type="lowpass",i.frequency.value=2e4,i.Q.value=.707,r.connect(i),i.connect(n),s&&s.output.connect(i)):(r.connect(n),s&&s.output.connect(n)),n.connect(e.destination),{context:e,master:r,compressor:n,filter:i,reverb:s}}var ro=class{constructor(e=new Ln){this.configStrings=e;this.buffers=new Map}registerName(e){return this.configStrings.soundIndex(e)}register(e,r){let n=this.registerName(e);return this.buffers.set(n,r),n}find(e){return this.configStrings.findSoundIndex(e)}get(e){return this.buffers.get(e)}has(e){return this.buffers.has(e)}getName(e){return this.configStrings.getName(e)}};var no=class{constructor(e){this.vfs=e.vfs,this.registry=e.registry,this.contextController=e.context,this.soundRoot=e.soundRoot??"sound/",this.decodeAudio=e.decodeAudio??((r,n)=>{if(!r.decodeAudioData)throw new Error("decodeAudioData is not available on the provided audio context");return r.decodeAudioData(n)})}async precache(e){let r=[...new Set(e.map(s=>this.normalize(s)))],n={loaded:[],skipped:[],missing:[],errors:{}},i=this.contextController.getContext();for(let s of r)try{let a=this.registry.find(s);if(a!==void 0&&this.registry.has(a)){n.skipped.push(s);continue}if(!this.vfs.stat(s)){n.missing.push(s);continue}let l=(await this.vfs.readFile(s)).slice().buffer,c=await this.decodeAudio(i,l);this.registry.register(s,c),n.loaded.push(s)}catch(a){let o=a instanceof Error?a:new Error(String(a));n.errors[s]=o}return n}normalize(e){let r=ae(e.replace(/^\//,""));return r.startsWith(this.soundRoot)?r:ae(`${this.soundRoot}${r}`)}};var Xm=7,Ms=t=>t&Xm;function io(t){return Array.from({length:vi},()=>({entnum:0,entchannel:at.Auto,endTimeMs:0,isPlayer:!1,active:!1})).map(e=>({...e,isPlayer:e.entnum===t}))}function so(t,e,r,n){if(r<0)throw new Error("pickChannel: entchannel must be non-negative");let i=Ms(r),s=-1,a=Number.POSITIVE_INFINITY;for(let o=0;o<t.length;o+=1){let d=t[o],l=Ms(d.entchannel);if(i!==at.Auto&&d.entnum===e&&l===i){s=o;break}if(d.active&&d.entnum===n.playerEntity&&e!==n.playerEntity)continue;let c=d.endTimeMs-n.nowMs;(s===-1||c<a)&&(a=c,s=o)}return s===-1?void 0:s}var ao=class{constructor(e){this.activePreset=null;this.enabled=!0;this.node=e,this.node.input.gain.value=.5,this.node.output.gain.value=1}setPreset(e){this.activePreset=e,this.node.convolver.buffer!==(e?.buffer??null)&&(this.node.convolver.buffer=e?.buffer??null),e&&e.gain!==void 0?this.node.output.gain.value=e.gain:this.node.output.gain.value=1}setEnabled(e){this.enabled=e,e?this.node.input.gain.value=.5:this.node.input.gain.value=0}getOutputNode(){return this.node.output}getInputNode(){return this.node.input}};var oo=class{constructor(e){this.activeSources=new Map;this.playbackRate=1;this.contextController=e.context,this.registry=e.registry,this.playerEntity=e.playerEntity,this.channels=io(e.playerEntity),this.listener=e.listener??{origin:id,right:{x:1,y:0,z:0}},this.sfxVolume=e.sfxVolume??1,this.masterVolume=e.masterVolume??1,this.resolveOcclusion=e.resolveOcclusion,this.graph=to(this.contextController),this.graph.master.gain.value=this.masterVolume,this.graph.reverb&&(this.reverb=new ao(this.graph.reverb))}setListener(e){this.listener=e}setMasterVolume(e){this.masterVolume=e,this.graph.master.gain.value=e}setSfxVolume(e){this.sfxVolume=e}setPlaybackRate(e){this.playbackRate=e;for(let r of this.activeSources.values())r.source.playbackRate&&(r.source.playbackRate.value=e),this.updateSourceGain(r)}async ensureRunning(){await this.contextController.resume()}setReverbPreset(e){this.reverb?.setPreset(e)}play(e){let r=this.registry.get(e.soundIndex);if(!r)return;let n=this.graph.context,i=n.currentTime*1e3,s=so(this.channels,e.entity,e.channel,{nowMs:i,playerEntity:this.playerEntity});if(s===void 0)return;let a=this.activeSources.get(s);a&&(a.source.onended=null,a.source.stop(),this.activeSources.delete(s));let o=n.createBufferSource();o.buffer=r,o.loop=e.looping??!1,o.playbackRate&&(o.playbackRate.value=this.playbackRate);let d=e.origin??this.listener.origin,l=n.createGain(),c=this.createPanner(n,e.attenuation),f=this.resolveOcclusion?.(this.listener,d,e.attenuation),u=gu(f?.gainScale??1),h=this.resolveOcclusion?this.createOcclusionFilter(n,f?.lowpassHz??2e4):void 0;this.applyOriginToPanner(c,d);let g=e.volume/255*this.sfxVolume,p=Math.abs(this.playbackRate-1)<.001?1:0;l.gain.value=g*u*p;let y=n.currentTime+(e.timeOffsetMs??0)/1e3,_=(e.looping?Number.POSITIVE_INFINITY:r.duration*1e3)+y*1e3;o.connect(c);let x=c;h?(c.connect(h),h.connect(l),x=l):(c.connect(l),x=l),l.connect(this.graph.master),this.reverb&&l.connect(this.reverb.getInputNode()),o.start(y),o.onended=()=>{this.channels[s].active=!1,this.activeSources.delete(s)};let b={channelIndex:s,entnum:e.entity,entchannel:Ms(e.channel),endTimeMs:_,source:o,panner:c,gain:l,baseGain:g,origin:d,attenuation:e.attenuation,occlusion:h?{scale:u,lowpassHz:f?.lowpassHz,filter:h}:f?{scale:u,lowpassHz:f.lowpassHz}:void 0};return this.channels[s]={entnum:e.entity,entchannel:Ms(e.channel),endTimeMs:_,isPlayer:e.entity===this.playerEntity,active:!0},this.activeSources.set(s,b),b}stop(e){let r=this.activeSources.get(e);r&&(r.source.stop(),this.channels[e].active=!1,this.activeSources.delete(e))}stopEntitySounds(e){for(let[r,n]of[...this.activeSources.entries()])n.entnum===e&&(n.source.stop(),this.channels[r].active=!1,this.activeSources.delete(r))}updateEntityPosition(e,r){for(let n of this.activeSources.values())if(n.entnum===e&&(this.applyOriginToPanner(n.panner,r),n.origin=r,this.resolveOcclusion)){let i=this.resolveOcclusion(this.listener,r,n.attenuation);this.applyOcclusion(n,i)}}positionedSound(e,r,n,i){return this.play({entity:0,channel:at.Auto,soundIndex:r,volume:n,attenuation:i,origin:e})}ambientSound(e,r,n){return this.play({entity:0,channel:at.Auto,soundIndex:r,volume:n,attenuation:wi,origin:e,looping:!0})}getChannelState(e){return this.channels[e]}getDiagnostics(){return{activeChannels:this.activeSources.size,masterVolume:this.masterVolume,sfxVolume:this.sfxVolume,channels:[...this.channels],activeSounds:[...this.activeSources.values()].map(e=>({entnum:e.entnum,entchannel:e.entchannel,channelIndex:e.channelIndex,origin:e.origin,gain:e.gain.gain.value,baseGain:e.baseGain,attenuation:e.attenuation,maxDistance:e.panner.maxDistance,distanceModel:e.panner.distanceModel,occlusion:e.occlusion?{scale:e.occlusion.scale,lowpassHz:e.occlusion.lowpassHz}:void 0}))}}setUnderwater(e,r=400){let n=this.graph.filter;n&&(n.type="lowpass",n.Q.value=.707,n.frequency.value=e?r:2e4)}createPanner(e,r){let n=e.createPanner?e.createPanner():Object.assign(e.createGain(),{positionX:{value:this.listener.origin.x},positionY:{value:this.listener.origin.y},positionZ:{value:this.listener.origin.z}});return this.configurePanner(n,r)}configurePanner(e,r){let n=An(r);return e.refDistance=Sn,e.maxDistance=Vr(r),e.rolloffFactor=n,e.distanceModel="linear",e.positionX.value=this.listener.origin.x,e.positionY.value=this.listener.origin.y,e.positionZ.value=this.listener.origin.z,e}applyOriginToPanner(e,r){e.positionX.value=r.x,e.positionY.value=r.y,e.positionZ.value=r.z}createOcclusionFilter(e,r){if(!e.createBiquadFilter)return;let n=e.createBiquadFilter();return n.type="lowpass",n.Q.value=.707,n.frequency.value=Hl(r,10,2e4),n}updateSourceGain(e){let r=e.occlusion?.scale??1,n=Math.abs(this.playbackRate-1)<.001?1:0;e.gain.gain.value=e.baseGain*r*n}applyOcclusion(e,r){let n=gu(r?.gainScale??1),i=Math.abs(this.playbackRate-1)<.001?1:0;if(e.gain.gain.value=e.baseGain*n*i,e.occlusion?.filter){let s=r?.lowpassHz??2e4;e.occlusion.filter.frequency.value=Hl(s,10,2e4)}e.occlusion?(e.occlusion.scale=n,e.occlusion.lowpassHz=r?.lowpassHz):r&&(e.occlusion={scale:n,lowpassHz:r.lowpassHz})}},Hl=(t,e,r)=>Math.min(r,Math.max(e,t)),gu=t=>Hl(t,0,1);var Es=class{constructor(e){this.trace=e;this.resolve=(e,r,n)=>{let i=Yo(sd(r,e.origin)),s=Vr(n),d=2e4*(1-Math.min(i,s)/Math.max(1,s)*.9),l=this.trace(e.origin,r,void 0,void 0),c=1,f=2e4;l.fraction<1&&(c=.3,f=400);let u=Math.min(d,f);if(c<1||u<2e4)return{gainScale:c,lowpassHz:u}}}};function yu(t){return new Es(t).resolve}var lo=class{constructor(e){this.createElement=e.createElement,this.resolveSource=e.resolveSource??(async r=>r),this.volume=e.volume??1,this.crossfadeDuration=e.crossfadeDuration??1}async playTrack(e){let r=`music/track${e.toString().padStart(2,"0")}.ogg`;return this.play(r)}async play(e,{loop:r=!0,restart:n=!1}={}){if(this.track===e&&this.currentElement){this.currentElement.loop=r,this.cancelFade(),this.fadingElement&&(this.fadingElement.pause(),this.fadingElement=void 0),this.currentElement.volume=this.volume,n&&(this.currentElement.currentTime=0),(this.currentElement.paused||n)&&await this.currentElement.play();return}let i=await this.resolveSource(e);this.cancelFade(),this.fadingElement&&(this.fadingElement.pause(),this.fadingElement=void 0),this.currentElement&&(this.fadingElement=this.currentElement,this.currentElement=void 0);let s=this.createElement();s.src=i,s.loop=r,s.volume=0,s.currentTime=0,s.load();try{await s.play()}catch(a){console.warn(`MusicSystem: Failed to play ${e}`,a),this.fadingElement}this.currentElement=s,this.track=e,this.startCrossfade()}pause(){this.cancelFade(),this.currentElement&&!this.currentElement.paused&&this.currentElement.pause(),this.fadingElement&&(this.fadingElement.pause(),this.fadingElement=void 0)}async resume(){!this.currentElement||!this.currentElement.paused||(await this.currentElement.play(),this.currentElement.volume=this.volume)}stop(){this.cancelFade(),this.currentElement&&(this.currentElement.pause(),this.currentElement.currentTime=0,this.currentElement=void 0),this.fadingElement&&(this.fadingElement.pause(),this.fadingElement=void 0),this.track=void 0}setVolume(e){this.volume=e,this.currentElement&&!this.fadeInterval&&(this.currentElement.volume=e)}getState(){let e=!!(this.currentElement&&!this.currentElement.paused&&!this.currentElement.ended),r=!!this.currentElement?.paused;return{track:this.track,paused:r,playing:e,volume:this.volume}}startCrossfade(){let r=this.crossfadeDuration*1e3/50,n=this.volume/r,i=0,s=this.fadingElement?this.fadingElement.volume:0,a=()=>{let o=!1;this.currentElement&&(i=Math.min(this.volume,i+n),this.currentElement.volume=i,i<this.volume&&(o=!0)),this.fadingElement&&(s=Math.max(0,s-n),this.fadingElement.volume=s,s>0?o=!0:(this.fadingElement.pause(),this.fadingElement=void 0)),o||this.cancelFade()};a(),(this.currentElement&&this.currentElement.volume<this.volume||this.fadingElement)&&(this.fadeInterval=setInterval(a,50))}cancelFade(){this.fadeInterval&&(clearInterval(this.fadeInterval),this.fadeInterval=void 0)}};function Km(t){t.enable(t.DEPTH_TEST),t.depthFunc(t.LEQUAL),t.enable(t.CULL_FACE),t.cullFace(t.BACK),t.enable(t.BLEND),t.blendFuncSeparate(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA)}function $m(t,e,r,n){for(let i of e){let s=t.getExtension(i);if(!s)throw new Error(`Missing required WebGL extension: ${i}`);n.set(i,s)}for(let i of r){let s=t.getExtension(i);s&&n.set(i,s)}}function bu(t,e={}){let{contextAttributes:r,requiredExtensions:n=[],optionalExtensions:i=[]}=e,s=t.getContext("webgl2",r??{antialias:!0});if(!s)throw new Error("WebGL2 not supported or failed to initialize");Km(s);let a=new Map;$m(s,n,i,a);let o=!1,d=new Set,l=new Set,c=u=>{o=!0,u.preventDefault();for(let h of d)h()},f=()=>{o=!1;for(let u of l)u()};return t.addEventListener("webglcontextlost",c),t.addEventListener("webglcontextrestored",f),{gl:s,extensions:a,isLost:()=>o,onLost(u){return d.add(u),()=>d.delete(u)},onRestored(u){return l.add(u),()=>l.delete(u)},dispose(){t.removeEventListener("webglcontextlost",c),t.removeEventListener("webglcontextrestored",f),d.clear(),l.clear(),a.clear()}}}function xu(t,e,r){let n=t.createShader(e);if(!n)throw new Error("Failed to allocate shader");if(t.shaderSource(n,r),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS)){let s=t.getShaderInfoLog(n)??"Unknown shader compile failure";throw t.deleteShader(n),new Error(s)}return n}function Zm(t,e,r,n){let i=t.createProgram();if(!i)throw new Error("Failed to allocate shader program");if(t.attachShader(i,e),t.attachShader(i,r),n)for(let[a,o]of Object.entries(n))t.bindAttribLocation(i,o,a);if(t.linkProgram(i),!t.getProgramParameter(i,t.LINK_STATUS)){let a=t.getProgramInfoLog(i)??"Unknown shader link failure";throw t.deleteProgram(i),new Error(a)}return i}var Te=class t{constructor(e,r,n){this.uniformLocations=new Map;this.attributeLocations=new Map;this.gl=e,this.program=r,this.sourceSize=n}static create(e,r,n){let i=xu(e,e.VERTEX_SHADER,r.vertex),s=xu(e,e.FRAGMENT_SHADER,r.fragment);try{let a=Zm(e,i,s,n),o=r.vertex.length+r.fragment.length;return new t(e,a,o)}finally{e.deleteShader(i),e.deleteShader(s)}}use(){this.gl.useProgram(this.program)}getUniformLocation(e){if(!this.uniformLocations.has(e)){let r=this.gl.getUniformLocation(this.program,e);this.uniformLocations.set(e,r)}return this.uniformLocations.get(e)??null}getAttributeLocation(e){if(!this.attributeLocations.has(e)){let r=this.gl.getAttribLocation(this.program,e);this.attributeLocations.set(e,r)}return this.attributeLocations.get(e)??-1}dispose(){this.gl.deleteProgram(this.program),this.uniformLocations.clear(),this.attributeLocations.clear()}};function _u(t,e,r){return Te.create(t,e,r)}var Ce=class{constructor(e,r=e.STATIC_DRAW,n){this.gl=e,this.target=n??e.ARRAY_BUFFER;let i=e.createBuffer();if(!i)throw new Error("Failed to allocate buffer");this.buffer=i,e.bindBuffer(this.target,this.buffer),e.bufferData(this.target,0,r)}bind(){this.gl.bindBuffer(this.target,this.buffer)}upload(e,r=this.gl.STATIC_DRAW){this.bind(),this.gl.bufferData(this.target,e,r)}update(e,r=0){this.bind(),this.gl.bufferSubData(this.target,r,e)}dispose(){this.gl.deleteBuffer(this.buffer)}},_e=class extends Ce{constructor(e,r=e.STATIC_DRAW){super(e,r,e.ELEMENT_ARRAY_BUFFER)}},Pe=class{constructor(e){this.gl=e;let r=e.createVertexArray();if(!r)throw new Error("Failed to allocate vertex array object");this.vao=r}bind(){this.gl.bindVertexArray(this.vao)}configureAttributes(e,r){this.bind(),r&&r.bind();for(let n of e)this.gl.enableVertexAttribArray(n.index),this.gl.vertexAttribPointer(n.index,n.size,n.type,n.normalized??!1,n.stride??0,n.offset??0),n.divisor!==void 0&&this.gl.vertexAttribDivisor(n.index,n.divisor)}dispose(){this.gl.deleteVertexArray(this.vao)}},Jn=class{constructor(e,r=e.TEXTURE_2D){this.width=0;this.height=0;this.gl=e,this.target=r;let n=e.createTexture();if(!n)throw new Error("Failed to allocate texture");this.texture=n}bind(e=0){this.gl.activeTexture(this.gl.TEXTURE0+e),this.gl.bindTexture(this.target,this.texture)}setParameters(e){this.bind(),e.wrapS!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_S,e.wrapS),e.wrapT!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_T,e.wrapT),e.minFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MIN_FILTER,e.minFilter),e.magFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MAG_FILTER,e.magFilter)}upload(e,r,n){this.width=e,this.height=r,this.uploadImage(0,this.gl.RGBA,e,r,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,n)}uploadImage(e,r,n,i,s,a,o,d){this.bind(),this.gl.texImage2D(this.target,e,r,n,i,s,a,o,d)}dispose(){this.gl.deleteTexture(this.texture)}},ei=class{constructor(e){this.gl=e,this.target=e.TEXTURE_CUBE_MAP;let r=e.createTexture();if(!r)throw new Error("Failed to allocate cubemap texture");this.texture=r}bind(e=0){this.gl.activeTexture(this.gl.TEXTURE0+e),this.gl.bindTexture(this.target,this.texture)}setParameters(e){this.bind(),e.wrapS!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_S,e.wrapS),e.wrapT!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_T,e.wrapT),e.minFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MIN_FILTER,e.minFilter),e.magFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MAG_FILTER,e.magFilter)}uploadFace(e,r,n,i,s,a,o,d,l){this.bind(),this.gl.texImage2D(e,r,n,i,s,a,o,d,l)}dispose(){this.gl.deleteTexture(this.texture)}},co=class{constructor(e){this.gl=e;let r=e.createFramebuffer();if(!r)throw new Error("Failed to allocate framebuffer");this.framebuffer=r}bind(e=this.gl.FRAMEBUFFER){this.gl.bindFramebuffer(e,this.framebuffer)}attachTexture2D(e,r,n=0){this.bind(),this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,e,r.target,r.texture,n)}dispose(){this.gl.deleteFramebuffer(this.framebuffer)}};var Vl=4,Gl=7*Vl,Wl=[{index:0,size:3,type:5126,stride:Gl,offset:0},{index:1,size:2,type:5126,stride:Gl,offset:3*Vl},{index:2,size:2,type:5126,stride:Gl,offset:5*Vl}];function Ym(t,e){return{width:t,height:t,padding:e,data:new Uint8Array(t*t*4),cursorX:0,cursorY:0,rowHeight:0}}function qm(t){let e=t.width*t.height;if(e===0)throw new Error("Invalid lightmap with zero area");let r=t.samples.byteLength/e;if(!Number.isInteger(r)||r<3||r>4)throw new Error("Unsupported lightmap channel count");return r}function jm(t,e,r){let n=qm(r),i=t.width*4,s=e.x+t.padding,a=e.y+t.padding,o=0;for(let d=0;d<r.height;d++){let l=(a+d)*i+s*4;for(let c=0;c<r.width;c++){let f=l+c*4;t.data[f]=r.samples[o],t.data[f+1]=r.samples[o+1],t.data[f+2]=r.samples[o+2],t.data[f+3]=n===4?r.samples[o+3]:255,o+=n}}}function Qm(t,e,r){let n=e.width+r.lightmapPadding*2,i=e.height+r.lightmapPadding*2;if(n>r.atlasSize||i>r.atlasSize)throw new Error("Lightmap too large for atlas");for(let o of t){if(o.cursorX+n>o.width&&(o.cursorX=0,o.cursorY+=o.rowHeight+r.lightmapPadding,o.rowHeight=0),o.cursorY+i>o.height)continue;let d={atlasIndex:t.indexOf(o),x:o.cursorX,y:o.cursorY,width:e.width,height:e.height};return o.cursorX+=n+r.lightmapPadding,o.rowHeight=Math.max(o.rowHeight,i),{placement:d,atlas:o}}let s=Ym(r.atlasSize,r.lightmapPadding);t.push(s);let a={atlasIndex:t.length-1,x:0,y:0,width:e.width,height:e.height};return s.cursorX=n+r.lightmapPadding,s.rowHeight=i,{placement:a,atlas:s}}function uo(t){return t instanceof Float32Array?t:new Float32Array(t)}function Jm(t,e){if(!t){let n=new Uint16Array(e);for(let i=0;i<e;i++)n[i]=i;return n}return t instanceof Uint16Array?t:new Uint16Array(t)}function ep(t,e){let r=new Float32Array(t.length);for(let n=0;n<t.length;n+=2)r[n]=e.offset[0]+t[n]*e.scale[0],r[n+1]=e.offset[1]+t[n+1]*e.scale[1];return r}function tp(t,e){let r=uo(t.vertices),n=uo(t.textureCoords),i=e?ep(uo(t.lightmapCoords??t.textureCoords),e):uo(t.lightmapCoords??new Float32Array(n.length)),s=r.length/3;if(n.length/2!==s)throw new Error("Texture coordinates count mismatch");if(i.length/2!==s)throw new Error("Lightmap coordinates count mismatch");let a=new Float32Array(s*7);for(let o=0;o<s;o++){let d=o*3,l=o*2,c=o*7;a[c]=r[d],a[c+1]=r[d+1],a[c+2]=r[d+2],a[c+3]=n[l],a[c+4]=n[l+1],a[c+5]=i[l],a[c+6]=i[l+1]}return a}function vu(t){let e=[];for(let r=0;r<t.faces.length;r++){let n=t.faces[r];if(n.texInfo<0)continue;let i=t.texInfo[n.texInfo],s=[],a=[],o=[];for(let u=0;u<n.numEdges;u++){let h=t.surfEdges[n.firstEdge+u],m=t.edges[Math.abs(h)],g=h>=0?m.vertices[0]:m.vertices[1],p=t.vertices[g];s.push(p[0],p[1],p[2]);let y=p[0]*i.s[0]+p[1]*i.s[1]+p[2]*i.s[2]+i.sOffset,_=p[0]*i.t[0]+p[1]*i.t[1]+p[2]*i.t[2]+i.tOffset;a.push(y,_),o.push(y,_)}let d=[],l=s.length/3;for(let u=1;u<l-1;u++)d.push(0,u,u+1);let c,f=t.lightMapInfo[r];if(f){let u=1/0,h=-1/0,m=1/0,g=-1/0;for(let v=0;v<a.length;v+=2){let S=a[v],w=a[v+1];S<u&&(u=S),S>h&&(h=S),w<m&&(m=w),w>g&&(g=w)}let p=Math.floor(u/16),y=Math.floor(m/16),_=Math.ceil(h/16)-p+1,x=Math.ceil(g/16)-y+1,b=ma(n,t.lightMaps,f);if(b&&b.length===_*x*3){c={width:_,height:x,samples:b};for(let v=0;v<o.length;v+=2)o[v]=a[v]/16-p+.5,o[v+1]=a[v+1]/16-y+.5}}e.push({vertices:new Float32Array(s),textureCoords:new Float32Array(a),lightmapCoords:new Float32Array(o),indices:new Uint16Array(d),texture:i.texture,surfaceFlags:i.flags,lightmap:c,faceIndex:r})}return e}function wu(t,e,r,n={}){let i=e;if(r&&n.hiddenClassnames&&n.hiddenClassnames.size>0){let c=new Set;for(let f of r.entities.entities)if(f.classname&&n.hiddenClassnames.has(f.classname)){let u=f.properties.model;if(u&&u.startsWith("*")){let h=parseInt(u.substring(1),10);if(!isNaN(h)&&h>=0&&h<r.models.length){let m=r.models[h];for(let g=0;g<m.numFaces;g++)c.add(m.firstFace+g)}}}c.size>0&&(i=e.filter(f=>!c.has(f.faceIndex)))}let s={atlasSize:n.atlasSize??1024,lightmapPadding:n.lightmapPadding??1,hiddenClassnames:n.hiddenClassnames??new Set},a=[],o=new Map;i.forEach((c,f)=>{if(!c.lightmap)return;let{placement:u,atlas:h}=Qm(a,c.lightmap,s);jm(h,u,c.lightmap),o.set(f,{atlasIndex:u.atlasIndex,offset:[(u.x+s.lightmapPadding)/s.atlasSize,(u.y+s.lightmapPadding)/s.atlasSize],scale:[u.width/s.atlasSize,u.height/s.atlasSize]})});let d=a.map(c=>{let f=new Jn(t);return f.setParameters({wrapS:t.CLAMP_TO_EDGE,wrapT:t.CLAMP_TO_EDGE,minFilter:t.LINEAR,magFilter:t.LINEAR}),f.uploadImage(0,t.RGBA,c.width,c.height,0,t.RGBA,t.UNSIGNED_BYTE,c.data),{texture:f,width:c.width,height:c.height,pixels:c.data}});return{surfaces:i.map((c,f)=>{let u=o.get(f),h=tp(c,u),m=Jm(c.indices,h.length/7),g=new Ce(t,t.STATIC_DRAW,t.ARRAY_BUFFER);g.upload(h);let p=new _e(t,t.STATIC_DRAW);p.upload(m);let y=new Pe(t);return y.configureAttributes(Wl,g),{vao:y,vertexBuffer:g,indexBuffer:p,indexCount:m.length,vertexCount:h.length/7,texture:c.texture,surfaceFlags:c.surfaceFlags??_i,lightmap:u,vertexData:h,indexData:m}}),lightmaps:d}}function ti(t){let{normal:e,distance:r}=t,n=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);if(n===0)return t;let i=1/n;return{normal:{x:e.x*i,y:e.y*i,z:e.z*i},distance:r*i}}function Su(t){if(t.length!==16)throw new Error("View-projection matrix must contain 16 elements");let e=t[0],r=t[4],n=t[8],i=t[12],s=t[1],a=t[5],o=t[9],d=t[13],l=t[2],c=t[6],f=t[10],u=t[14],h=t[3],m=t[7],g=t[11],p=t[15];return[ti({normal:{x:h+e,y:m+r,z:g+n},distance:p+i}),ti({normal:{x:h-e,y:m-r,z:g-n},distance:p-i}),ti({normal:{x:h+s,y:m+a,z:g+o},distance:p+d}),ti({normal:{x:h-s,y:m-a,z:g-o},distance:p-d}),ti({normal:{x:h+l,y:m+c,z:g+f},distance:p+u}),ti({normal:{x:h-l,y:m-c,z:g-f},distance:p-u})]}function rp(t,e){return t.normal.x*e.x+t.normal.y*e.y+t.normal.z*e.z+t.distance}function Ls(t,e,r){for(let n of r){let i=n.normal.x>=0?e.x:t.x,s=n.normal.y>=0?e.y:t.y,a=n.normal.z>=0?e.z:t.z;if(rp(n,{x:i,y:s,z:a})<0)return!1}return!0}function Au(t){return t<0}function Mu(t){return-t-1}function Eu(t,e){return t.normal[0]*e.x+t.normal[1]*e.y+t.normal[2]*e.z-t.dist}function np(t,e,r){if(!t||e<0||r<0)return!0;let n=Math.ceil(t.numClusters/8),i=t.clusters[e].pvs,s=Math.floor(r/8),a=1<<r%8;return s<0||s>=n?!1:(i[s]&a)!==0}function ip(t,e){let r={x:t.mins[0],y:t.mins[1],z:t.mins[2]},n={x:t.maxs[0],y:t.maxs[1],z:t.maxs[2]};return Ls(r,n,e)}function Kl(t,e){let r=0;for(;r>=0;){let n=t.nodes[r],i=t.planes[n.planeIndex],a=Eu(i,e)>=0?0:1,o=n.children[a];if(Au(o))return Mu(o);r=o}return-1}function sp(t,e){let r=t.leafs[e],n=[];for(let i=0;i<r.numLeafFaces;i+=1)n.push(t.leafLists.leafFaces[e][i]);return n}function Xl(t,e,r,n,i,s,a){if(Au(e)){let u=Mu(e),h=t.leafs[u];if(!np(t.visibility,i,h.cluster)||!ip(h,n))return;let m={x:(h.mins[0]+h.maxs[0])*.5,y:(h.mins[1]+h.maxs[1])*.5,z:(h.mins[2]+h.maxs[2])*.5},g=m.x-r.x,p=m.y-r.y,y=m.z-r.z,_=-(g*g+p*p+y*y);for(let x of sp(t,u))a.has(x)||(a.add(x),s.push({faceIndex:x,leafIndex:u,sortKey:_}));return}let o=t.nodes[e],d=t.planes[o.planeIndex],l=Eu(d,r),c=l>=0?o.children[0]:o.children[1],f=l>=0?o.children[1]:o.children[0];Ls({x:o.mins[0],y:o.mins[1],z:o.mins[2]},{x:o.maxs[0],y:o.maxs[1],z:o.maxs[2]},n)&&(Xl(t,c,r,n,i,s,a),Xl(t,f,r,n,i,s,a))}function Lu(t,e,r){let n=Kl(t,e),i=n>=0?t.leafs[n].cluster:-1,s=[];return Xl(t,0,e,r,i,s,new Set),s}var ur=32,fo=class{constructor(){this.lights=[]}addLight(e,r){if(e.key!==void 0){let n=this.lights.findIndex(i=>i.key===e.key);if(n!==-1){this.lights[n]=e;return}}this.lights.push(e)}clear(){this.lights=[]}update(e,r=0){if(this.lights=this.lights.filter(n=>n.die>e),r>0)for(let n of this.lights)n.radiusSpeed!==void 0&&n.radiusSpeed!==0&&(n.intensity+=n.radiusSpeed*r,n.intensity<0&&(n.intensity=0))}getActiveLights(){return this.lights}};function ri(t){let e=[];for(let r=0;r<t.length;r+=3){let n=t[r],i=t[r+1],s=t[r+2];e.push(n,i,i,s,s,n)}return t instanceof Uint32Array||Math.max(...e)>65535?new Uint32Array(e):new Uint16Array(e)}var $l=`#version 300 es
|
|
141
|
+
ïBçϧmÙIólÜoëVb¦¯éWÇû3`});var Hh={a:Ur};this.setModule=P=>{t.setModule(Dt,P)},this.getModule=()=>t.getModule(Dt),this.instantiate=()=>(this.getModule().then(P=>WebAssembly.instantiate(P,Hh)).then(P=>{let Ge=P.exports;js(Ge),m=Ge.l,g(),Uh(Ge),r()}),this.ready=new Promise(P=>{r=P}).then(()=>{this.HEAP=m.buffer,this.malloc=qc,this.free=td,this.create_decoder=gi,this.send_setup=jc,this.init_dsp=Qc,this.decode_packets=Jc,this.destroy_decoder=ed}),this)}function an(){return this._init=()=>new this._WASMAudioDecoderCommon().instantiate(this._EmscriptenWASM,this._module).then(t=>{this._common=t,this._input=this._common.allocateTypedArray(this._inputSize,Uint8Array),this._firstPage=!0,this._inputLen=this._common.allocateTypedArray(1,Uint32Array),this._outputBufferPtr=this._common.allocateTypedArray(1,Uint32Array),this._channels=this._common.allocateTypedArray(1,Uint32Array),this._sampleRate=this._common.allocateTypedArray(1,Uint32Array),this._samplesDecoded=this._common.allocateTypedArray(1,Uint32Array);let e=256;this._errors=this._common.allocateTypedArray(e,Uint32Array),this._errorsLength=this._common.allocateTypedArray(1,Int32Array),this._frameNumber=0,this._inputBytes=0,this._outputSamples=0,this._decoder=this._common.wasm.create_decoder(this._input.ptr,this._inputLen.ptr,this._outputBufferPtr.ptr,this._channels.ptr,this._sampleRate.ptr,this._samplesDecoded.ptr,this._errors.ptr,this._errorsLength.ptr,e)}),Object.defineProperty(this,"ready",{enumerable:!0,get:()=>this._ready}),this.reset=()=>(this.free(),this._init()),this.free=()=>{this._common.wasm.destroy_decoder(this._decoder),this._common.free()},this.sendSetupHeader=t=>{this._input.buf.set(t),this._inputLen.buf[0]=t.length,this._common.wasm.send_setup(this._decoder,this._firstPage),this._firstPage=!1},this.initDsp=()=>{this._common.wasm.init_dsp(this._decoder)},this.decodePackets=t=>{let e=[],r=0,n=[];for(let i=0;i<t.length;i++){let s=t[i];this._input.buf.set(s),this._inputLen.buf[0]=s.length,this._common.wasm.decode_packets(this._decoder);let a=this._samplesDecoded.buf[0],o=[],d=new Uint32Array(this._common.wasm.HEAP,this._outputBufferPtr.buf[0],this._channels.buf[0]);for(let l=0;l<this._channels.buf[0];l++){let c=new Float32Array(a);a&&c.set(new Float32Array(this._common.wasm.HEAP,d[l],a)),o.push(c)}e.push(o),r+=a,this._frameNumber++,this._inputBytes+=s.length,this._outputSamples+=a;for(let l=0;l<this._errorsLength.buf;l+=2){let c=this._common.codeToString(this._errors.buf[l]),f=this._common.codeToString(this._errors.buf[l+1]);n.push({message:c+" vorbis_synthesis"+f,frameLength:s.length,frameNumber:this._frameNumber,inputBytes:this._inputBytes,outputSamples:this._outputSamples})}this._errorsLength.buf[0]=0}return this._WASMAudioDecoderCommon.getDecodedAudioMultiChannel(n,e,this._channels.buf[0],r,this._sampleRate.buf[0],16)},this._isWebWorker=an.isWebWorker,this._WASMAudioDecoderCommon=an.WASMAudioDecoderCommon||re,this._EmscriptenWASM=an.EmscriptenWASM||Dt,this._module=an.module,this._inputSize=128*1024,this._ready=this._init(),this}var qa=Symbol(),Ot=class{constructor(){this._onCodec=e=>{if(e!=="vorbis")throw new Error("@wasm-audio-decoders/ogg-vorbis does not support this codec "+e)},new re,this._init(),this._ready=this[qa](an)}_init(){this._vorbisSetupInProgress=!0,this._totalSamplesDecoded=0,this._codecParser=new du("audio/ogg",{onCodec:this._onCodec,enableFrameCRC32:!1})}async[qa](e){if(this._decoder){let r=this._decoder;await r.ready.then(()=>r.free())}return this._decoder=new e,this._decoder.ready}get ready(){return this._ready}async reset(){return this._init(),this._decoder.reset()}free(){this._decoder.free()}async decodeOggPages(e){let r=[];for(let s=0;s<e.length;s++){let a=e[s];if(this._vorbisSetupInProgress&&(a[Ya][0]===1&&this._decoder.sendSetupHeader(a[Ya]),a[Za].length)){let o=a[Za][0][uu];this._decoder.sendSetupHeader(o[hu]),this._decoder.initDsp(),this._vorbisSetupInProgress=!1}r.push(...a[Za].map(o=>o[Ya]))}let n=await this._decoder.decodePackets(r);this._totalSamplesDecoded+=n.samplesDecoded;let i=e[e.length-1];if(i&&i[fu]){let s=this._totalSamplesDecoded-i[mu];if(s>0){for(let a=0;a<n.channelData.length;a++)n.channelData[a]=n.channelData[a].subarray(0,n.samplesDecoded-s);n.samplesDecoded-=s,this._totalSamplesDecoded-=s}}return n}async decode(e){return this.decodeOggPages([...this._codecParser.parseChunk(e)])}async flush(){let e=await this.decodeOggPages([...this._codecParser.flush()]);return await this.reset(),e}async decodeFile(e){let r=await this.decodeOggPages([...this._codecParser.parseAll(e)]);return await this.reset(),r}};var zl=class extends Bn{constructor(e){super(e,"ogg-vorbis-decoder",an,Dt)}async sendSetupHeader(e){return this.postToDecoder("sendSetupHeader",e)}async initDsp(){return this.postToDecoder("initDsp")}async decodePackets(e){return this.postToDecoder("decodePackets",e)}},_s=class extends Ot{constructor(){super(),this._ready=super[qa](zl)}async free(){await this._decoder.free()}terminate(){this._decoder.terminate()}};va(Ot,"OggVorbisDecoder");va(_s,"OggVorbisDecoderWebWorker");var Nl=class extends Error{constructor(e){super(e),this.name="OggDecodeError"}};async function ja(t,e=new Ot){await e.ready;let r=await e.decode(new Uint8Array(t)),n=r.errors;if(n&&n.length>0)throw new Nl(n.map(i=>i.message).join("; "));return{sampleRate:r.sampleRate,channels:r.channelData.length,bitDepth:r.bitDepth,channelData:r.channelData}}var vs=class extends Error{constructor(e){super(e),this.name="AudioRegistryError"}},Qn=class{constructor(e,r={}){this.vfs=e;this.refCounts=new Map;this.cache=new Kt(r.cacheSize??64)}get size(){return this.cache.size}async load(e){let r=e.toLowerCase(),n=this.cache.get(r);if(n)return this.refCounts.set(r,(this.refCounts.get(r)??0)+1),n;let s=(await this.vfs.readFile(e)).slice().buffer,a=await this.decodeByExtension(e,s);return this.cache.set(r,a),this.refCounts.set(r,1),a}release(e){let r=e.toLowerCase(),n=this.refCounts.get(r)??0;n<=1?(this.cache.delete(r),this.refCounts.delete(r)):this.refCounts.set(r,n-1)}clearAll(){this.cache.clear(),this.refCounts.clear()}async decodeByExtension(e,r){let n=e.toLowerCase();if(n.endsWith(".wav")){let i=_a(r),s=i.channels,a=Array.from({length:s},()=>new Float32Array(i.samples.length/s));for(let o=0;o<i.samples.length;o+=1)a[o%s][Math.floor(o/s)]=i.samples[o];return{sampleRate:i.sampleRate,channels:s,bitDepth:i.bitsPerSample,channelData:a}}if(n.endsWith(".ogg")||n.endsWith(".oga"))return ja(r);throw new vs(`Unsupported audio format: ${e}`)}};var Gm="quake2ts-pak-indexes",Vm="pak-indexes";function pu(){if(typeof indexedDB<"u")return indexedDB;if(typeof window<"u"&&"indexedDB"in window)return window.indexedDB;if(typeof globalThis<"u"&&"indexedDB"in globalThis)return globalThis.indexedDB}function ws(t,e){let r=pu();return r?new Promise((n,i)=>{let s=r.open(t,1);s.onupgradeneeded=()=>{let{result:a}=s;a.objectStoreNames.contains(e)||a.createObjectStore(e,{keyPath:"key"})},s.onerror=()=>i(s.error??new Error("Unknown IndexedDB error")),s.onsuccess=()=>n(s.result)}):Promise.reject(new Error("IndexedDB is not available in this environment"))}function Ss(t,e,r,n){return new Promise((i,s)=>{let o=t.transaction(e,r).objectStore(e),d=n(o);d.onsuccess=()=>i(d.result),d.onerror=()=>s(d.error??new Error("IndexedDB transaction error"))})}function Ul(t,e){return`${ae(t)}:${e.toString(16)}`}function Wm(t){return t.map(e=>({...e}))}var Qa=class{constructor(e=Gm,r=Vm){this.dbName=e;this.storeName=r}get isSupported(){return!!pu()}async persist(e){if(!this.isSupported)return;let r=e.validate(),n={...r,key:Ul(e.name,r.checksum),name:e.name,size:e.size,persistedAt:Date.now(),entries:Wm(r.entries)},i=await ws(this.dbName,this.storeName);return await Ss(i,this.storeName,"readwrite",s=>s.put(n)),i.close(),n}async find(e,r){if(!this.isSupported)return;let n=await ws(this.dbName,this.storeName),i=r!==void 0?Ul(e,r):void 0,s=await Ss(n,this.storeName,"readonly",a=>i?a.get(i):a.getAll());if(n.close(),!!s){if(Array.isArray(s)){let a=ae(e),o=s.filter(d=>ae(d.name)===a);return o.length===0?void 0:o.sort((d,l)=>l.persistedAt-d.persistedAt)[0]}return s}}async remove(e,r){if(!this.isSupported)return!1;let n=await ws(this.dbName,this.storeName),i=r!==void 0?Ul(e,r):void 0,s=await Ss(n,this.storeName,"readwrite",a=>{if(i)return a.delete(i);let o=`${ae(e)}:`;return a.delete(IDBKeyRange.bound(o,`${o}\uFFFF`,!1,!0))});return n.close(),typeof s=="number"?s>0:!0}async clear(){if(!this.isSupported)return;let e=await ws(this.dbName,this.storeName);await Ss(e,this.storeName,"readwrite",r=>r.clear()),e.close()}async list(){if(!this.isSupported)return[];let e=await ws(this.dbName,this.storeName),r=await Ss(e,this.storeName,"readonly",n=>n.getAll());return e.close(),r.sort((n,i)=>i.persistedAt-n.persistedAt)}};var on=class extends Error{constructor(r,n){super(n??`Missing dependencies: ${r.join(", ")}`);this.missing=r;this.name="AssetDependencyError"}},As=class{constructor(){this.nodes=new Map}register(e,r=[]){let n=this.nodes.get(e)??{dependencies:new Set,loaded:!1};r.forEach(i=>n.dependencies.add(i)),this.nodes.set(e,n),r.forEach(i=>{this.nodes.has(i)||this.nodes.set(i,{dependencies:new Set,loaded:!1})})}markLoaded(e){let r=this.nodes.get(e)??{dependencies:new Set,loaded:!1},n=this.getMissingDependencies(e,r);if(n.length>0)throw new on(n,`Asset ${e} is missing dependencies: ${n.join(", ")}`);r.loaded=!0,this.nodes.set(e,r)}markUnloaded(e){let r=this.nodes.get(e);r&&(r.loaded=!1)}isLoaded(e){return this.nodes.get(e)?.loaded??!1}missingDependencies(e){let r=this.nodes.get(e);return r?this.getMissingDependencies(e,r):[]}reset(){this.nodes.clear()}getMissingDependencies(e,r){let n=[];for(let i of r.dependencies)this.nodes.get(i)?.loaded||n.push(i);return n}},Ja=class{constructor(e,r={}){this.vfs=e;this.maps=new Map;this.loadQueue=[];this.activeLoads=0;this.textures=new Fn({capacity:r.textureCacheCapacity??128,maxMemory:r.textureMemoryLimit}),this.audio=new Qn(e,{cacheSize:r.audioCacheSize??64}),this.dependencyTracker=r.dependencyTracker??new As,this.resourceTracker=r.resourceTracker,this.md2=new kn(e),this.md3=new Rn(e),this.sprite=new Pn(e),this.bsp=new In(e),this.maxConcurrentLoads=r.maxConcurrentLoads??4,this.palette=new Uint8Array(768);for(let n=0;n<256;n++)this.palette[n*3]=n,this.palette[n*3+1]=n,this.palette[n*3+2]=n}async loadPalette(e="pics/colormap.pcx"){try{let r=await this.vfs.readFile(e),n=Ci(r);n.palette&&(this.palette=n.palette)}catch(r){console.warn(`Failed to load palette from ${e}:`,r)}}isAssetLoaded(e,r){return this.dependencyTracker.isLoaded(this.makeKey(e,r))}registerTexture(e,r){this.textures.set(e,r);let n=this.makeKey("texture",e);this.dependencyTracker.register(n),this.dependencyTracker.markLoaded(n)}async loadTexture(e){if(this.resourceTracker){let a=this.vfs.stat(e);this.resourceTracker.recordLoad("texture",e,a?.size,a?.sourcePak)}let r=this.textures.get(e);if(r)return r;let n=await this.vfs.readFile(e),i=e.split(".").pop()?.toLowerCase(),s;if(i==="wal")s=xa(n,this.palette);else if(i==="pcx")s=ba(Ci(n));else if(i==="tga")s=Nd(bl(n));else throw new Error(`Unsupported texture format for loadTexture: ${i}`);return this.registerTexture(e,s),s}async loadSound(e){if(this.resourceTracker){let i=this.vfs.stat(e);this.resourceTracker.recordLoad("sound",e,i?.size,i?.sourcePak)}let r=await this.audio.load(e),n=this.makeKey("sound",e);return this.dependencyTracker.register(n),this.dependencyTracker.markLoaded(n),r}async loadMd2Model(e,r=[]){if(this.resourceTracker){let o=this.vfs.stat(e);this.resourceTracker.recordLoad("model",e,o?.size,o?.sourcePak)}let n=this.makeKey("model",e),i=r.map(o=>this.makeKey("texture",o));this.dependencyTracker.register(n,i);let s=this.dependencyTracker.missingDependencies(n);if(s.length>0)throw new on(s,`Asset ${n} is missing dependencies: ${s.join(", ")}`);let a=await this.md2.load(e);return this.dependencyTracker.markLoaded(n),a}getMd2Model(e){if(this.resourceTracker){let r=this.vfs.stat(e);this.resourceTracker.recordLoad("model",e,r?.size,r?.sourcePak)}return this.md2.get(e)}async loadMd3Model(e,r=[]){if(this.resourceTracker){let o=this.vfs.stat(e);this.resourceTracker.recordLoad("model",e,o?.size,o?.sourcePak)}let n=this.makeKey("model",e),i=r.map(o=>this.makeKey("texture",o));this.dependencyTracker.register(n,i);let s=this.dependencyTracker.missingDependencies(n);if(s.length>0)throw new on(s,`Asset ${n} is missing dependencies: ${s.join(", ")}`);let a=await this.md3.load(e);return this.dependencyTracker.markLoaded(n),a}getMd3Model(e){if(this.resourceTracker){let r=this.vfs.stat(e);this.resourceTracker.recordLoad("model",e,r?.size,r?.sourcePak)}return this.md3.get(e)}async loadSprite(e){if(this.resourceTracker){let i=this.vfs.stat(e);this.resourceTracker.recordLoad("sprite",e,i?.size,i?.sourcePak)}let r=this.makeKey("sprite",e);this.dependencyTracker.register(r);let n=await this.sprite.load(e);return this.dependencyTracker.markLoaded(r),n}async loadMap(e){if(this.resourceTracker){let i=this.vfs.stat(e);this.resourceTracker.recordLoad("map",e,i?.size,i?.sourcePak)}let r=this.makeKey("map",e);if(this.maps.has(e))return this.maps.get(e);this.dependencyTracker.register(r);let n=await this.bsp.load(e);return this.maps.set(e,n),this.dependencyTracker.markLoaded(r),n}getMap(e){return this.maps.get(e)}listFiles(e){return this.vfs.findByExtension(e)}resetForLevelChange(){this.textures.clear(),this.audio.clearAll(),this.dependencyTracker.reset(),this.maps.clear(),this.loadQueue.length=0}getMemoryUsage(){let e=0,r=0;if(typeof process<"u"&&process.memoryUsage){let n=process.memoryUsage();e=n.heapTotal,r=n.heapUsed}return{textures:this.textures.memoryUsage,audio:0,heapTotal:e,heapUsed:r}}clearCache(e){switch(e){case"texture":this.textures.clear();break;case"sound":this.audio.clearAll();break;case"map":this.maps.clear();break}}async preloadAssets(e){let r=e.map(n=>{let i=this.detectAssetType(n);return i?this.queueLoad(n,i,0):Promise.resolve()});await Promise.all(r)}queueLoad(e,r,n=1){return r==="texture"&&this.textures.get(e)?Promise.resolve(this.textures.get(e)):new Promise((i,s)=>{this.loadQueue.push({path:e,type:r,priority:n,resolve:i,reject:s}),this.loadQueue.sort((a,o)=>o.priority-a.priority),this.processQueue()})}async processQueue(){if(this.activeLoads>=this.maxConcurrentLoads||this.loadQueue.length===0)return;let e=this.loadQueue.shift();this.activeLoads++;try{let r;switch(e.type){case"texture":r=await this.loadTexture(e.path);break;case"sound":r=await this.loadSound(e.path);break;case"model":e.path.endsWith(".md2")?r=await this.loadMd2Model(e.path):e.path.endsWith(".md3")&&(r=await this.loadMd3Model(e.path));break;case"sprite":r=await this.loadSprite(e.path);break;case"map":r=await this.loadMap(e.path);break;default:throw new Error(`Unknown asset type ${e.type}`)}e.resolve(r)}catch(r){e.reject(r)}finally{this.activeLoads--,this.processQueue()}}detectAssetType(e){let r=e.split(".").pop()?.toLowerCase();return r?["wal","pcx","tga","png","jpg"].includes(r)?"texture":["wav","ogg"].includes(r)?"sound":["md2","md3"].includes(r)?"model":["sp2"].includes(r)?"sprite":["bsp"].includes(r)?"map":null:null}makeKey(e,r){return`${e}:${ae(r)}`}};var eo=class{constructor(e){this.factory=e}getContext(){return this.context||(this.context=this.factory()),this.context}async resume(){let e=this.getContext();e.state==="suspended"&&await e.resume()}getState(){return this.context?.state??"suspended"}};function to(t){let e=t.getContext(),r=e.createGain();r.gain.value=1;let n=e.createDynamicsCompressor(),i=e.createBiquadFilter?.(),s;if(e.createConvolver&&e.createGain){let a=e.createConvolver(),o=e.createGain(),d=e.createGain();o.connect(a),a.connect(d),s={convolver:a,input:o,output:d}}return i?(i.type="lowpass",i.frequency.value=2e4,i.Q.value=.707,r.connect(i),i.connect(n),s&&s.output.connect(i)):(r.connect(n),s&&s.output.connect(n)),n.connect(e.destination),{context:e,master:r,compressor:n,filter:i,reverb:s}}var ro=class{constructor(e=new Tn){this.configStrings=e;this.buffers=new Map}registerName(e){return this.configStrings.soundIndex(e)}register(e,r){let n=this.registerName(e);return this.buffers.set(n,r),n}find(e){return this.configStrings.findSoundIndex(e)}get(e){return this.buffers.get(e)}has(e){return this.buffers.has(e)}getName(e){return this.configStrings.getName(e)}};var no=class{constructor(e){this.vfs=e.vfs,this.registry=e.registry,this.contextController=e.context,this.soundRoot=e.soundRoot??"sound/",this.decodeAudio=e.decodeAudio??((r,n)=>{if(!r.decodeAudioData)throw new Error("decodeAudioData is not available on the provided audio context");return r.decodeAudioData(n)})}async precache(e){let r=[...new Set(e.map(s=>this.normalize(s)))],n={loaded:[],skipped:[],missing:[],errors:{}},i=this.contextController.getContext();for(let s of r)try{let a=this.registry.find(s);if(a!==void 0&&this.registry.has(a)){n.skipped.push(s);continue}if(!this.vfs.stat(s)){n.missing.push(s);continue}let l=(await this.vfs.readFile(s)).slice().buffer,c=await this.decodeAudio(i,l);this.registry.register(s,c),n.loaded.push(s)}catch(a){let o=a instanceof Error?a:new Error(String(a));n.errors[s]=o}return n}normalize(e){let r=ae(e.replace(/^\//,""));return r.startsWith(this.soundRoot)?r:ae(`${this.soundRoot}${r}`)}};var Xm=7,Ms=t=>t&Xm;function io(t){return Array.from({length:vi},()=>({entnum:0,entchannel:at.Auto,endTimeMs:0,isPlayer:!1,active:!1})).map(e=>({...e,isPlayer:e.entnum===t}))}function so(t,e,r,n){if(r<0)throw new Error("pickChannel: entchannel must be non-negative");let i=Ms(r),s=-1,a=Number.POSITIVE_INFINITY;for(let o=0;o<t.length;o+=1){let d=t[o],l=Ms(d.entchannel);if(i!==at.Auto&&d.entnum===e&&l===i){s=o;break}if(d.active&&d.entnum===n.playerEntity&&e!==n.playerEntity)continue;let c=d.endTimeMs-n.nowMs;(s===-1||c<a)&&(a=c,s=o)}return s===-1?void 0:s}var ao=class{constructor(e){this.activePreset=null;this.enabled=!0;this.node=e,this.node.input.gain.value=.5,this.node.output.gain.value=1}setPreset(e){this.activePreset=e,this.node.convolver.buffer!==(e?.buffer??null)&&(this.node.convolver.buffer=e?.buffer??null),e&&e.gain!==void 0?this.node.output.gain.value=e.gain:this.node.output.gain.value=1}setEnabled(e){this.enabled=e,e?this.node.input.gain.value=.5:this.node.input.gain.value=0}getOutputNode(){return this.node.output}getInputNode(){return this.node.input}};var oo=class{constructor(e){this.activeSources=new Map;this.playbackRate=1;this.contextController=e.context,this.registry=e.registry,this.playerEntity=e.playerEntity,this.channels=io(e.playerEntity),this.listener=e.listener??{origin:id,right:{x:1,y:0,z:0}},this.sfxVolume=e.sfxVolume??1,this.masterVolume=e.masterVolume??1,this.resolveOcclusion=e.resolveOcclusion,this.graph=to(this.contextController),this.graph.master.gain.value=this.masterVolume,this.graph.reverb&&(this.reverb=new ao(this.graph.reverb))}setListener(e){this.listener=e}setMasterVolume(e){this.masterVolume=e,this.graph.master.gain.value=e}setSfxVolume(e){this.sfxVolume=e}setPlaybackRate(e){this.playbackRate=e;for(let r of this.activeSources.values())r.source.playbackRate&&(r.source.playbackRate.value=e),this.updateSourceGain(r)}async ensureRunning(){await this.contextController.resume()}setReverbPreset(e){this.reverb?.setPreset(e)}play(e){let r=this.registry.get(e.soundIndex);if(!r)return;let n=this.graph.context,i=n.currentTime*1e3,s=so(this.channels,e.entity,e.channel,{nowMs:i,playerEntity:this.playerEntity});if(s===void 0)return;let a=this.activeSources.get(s);a&&(a.source.onended=null,a.source.stop(),this.activeSources.delete(s));let o=n.createBufferSource();o.buffer=r,o.loop=e.looping??!1,o.playbackRate&&(o.playbackRate.value=this.playbackRate);let d=e.origin??this.listener.origin,l=n.createGain(),c=this.createPanner(n,e.attenuation),f=this.resolveOcclusion?.(this.listener,d,e.attenuation),u=gu(f?.gainScale??1),h=this.resolveOcclusion?this.createOcclusionFilter(n,f?.lowpassHz??2e4):void 0;this.applyOriginToPanner(c,d);let g=e.volume/255*this.sfxVolume,p=Math.abs(this.playbackRate-1)<.001?1:0;l.gain.value=g*u*p;let y=n.currentTime+(e.timeOffsetMs??0)/1e3,_=(e.looping?Number.POSITIVE_INFINITY:r.duration*1e3)+y*1e3;o.connect(c);let x=c;h?(c.connect(h),h.connect(l),x=l):(c.connect(l),x=l),l.connect(this.graph.master),this.reverb&&l.connect(this.reverb.getInputNode()),o.start(y),o.onended=()=>{this.channels[s].active=!1,this.activeSources.delete(s)};let b={channelIndex:s,entnum:e.entity,entchannel:Ms(e.channel),endTimeMs:_,source:o,panner:c,gain:l,baseGain:g,origin:d,attenuation:e.attenuation,occlusion:h?{scale:u,lowpassHz:f?.lowpassHz,filter:h}:f?{scale:u,lowpassHz:f.lowpassHz}:void 0};return this.channels[s]={entnum:e.entity,entchannel:Ms(e.channel),endTimeMs:_,isPlayer:e.entity===this.playerEntity,active:!0},this.activeSources.set(s,b),b}stop(e){let r=this.activeSources.get(e);r&&(r.source.stop(),this.channels[e].active=!1,this.activeSources.delete(e))}stopEntitySounds(e){for(let[r,n]of[...this.activeSources.entries()])n.entnum===e&&(n.source.stop(),this.channels[r].active=!1,this.activeSources.delete(r))}updateEntityPosition(e,r){for(let n of this.activeSources.values())if(n.entnum===e&&(this.applyOriginToPanner(n.panner,r),n.origin=r,this.resolveOcclusion)){let i=this.resolveOcclusion(this.listener,r,n.attenuation);this.applyOcclusion(n,i)}}positionedSound(e,r,n,i){return this.play({entity:0,channel:at.Auto,soundIndex:r,volume:n,attenuation:i,origin:e})}ambientSound(e,r,n){return this.play({entity:0,channel:at.Auto,soundIndex:r,volume:n,attenuation:wi,origin:e,looping:!0})}getChannelState(e){return this.channels[e]}getDiagnostics(){return{activeChannels:this.activeSources.size,masterVolume:this.masterVolume,sfxVolume:this.sfxVolume,channels:[...this.channels],activeSounds:[...this.activeSources.values()].map(e=>({entnum:e.entnum,entchannel:e.entchannel,channelIndex:e.channelIndex,origin:e.origin,gain:e.gain.gain.value,baseGain:e.baseGain,attenuation:e.attenuation,maxDistance:e.panner.maxDistance,distanceModel:e.panner.distanceModel,occlusion:e.occlusion?{scale:e.occlusion.scale,lowpassHz:e.occlusion.lowpassHz}:void 0}))}}setUnderwater(e,r=400){let n=this.graph.filter;n&&(n.type="lowpass",n.Q.value=.707,n.frequency.value=e?r:2e4)}createPanner(e,r){let n=e.createPanner?e.createPanner():Object.assign(e.createGain(),{positionX:{value:this.listener.origin.x},positionY:{value:this.listener.origin.y},positionZ:{value:this.listener.origin.z}});return this.configurePanner(n,r)}configurePanner(e,r){let n=An(r);return e.refDistance=Sn,e.maxDistance=Vr(r),e.rolloffFactor=n,e.distanceModel="linear",e.positionX.value=this.listener.origin.x,e.positionY.value=this.listener.origin.y,e.positionZ.value=this.listener.origin.z,e}applyOriginToPanner(e,r){e.positionX.value=r.x,e.positionY.value=r.y,e.positionZ.value=r.z}createOcclusionFilter(e,r){if(!e.createBiquadFilter)return;let n=e.createBiquadFilter();return n.type="lowpass",n.Q.value=.707,n.frequency.value=Hl(r,10,2e4),n}updateSourceGain(e){let r=e.occlusion?.scale??1,n=Math.abs(this.playbackRate-1)<.001?1:0;e.gain.gain.value=e.baseGain*r*n}applyOcclusion(e,r){let n=gu(r?.gainScale??1),i=Math.abs(this.playbackRate-1)<.001?1:0;if(e.gain.gain.value=e.baseGain*n*i,e.occlusion?.filter){let s=r?.lowpassHz??2e4;e.occlusion.filter.frequency.value=Hl(s,10,2e4)}e.occlusion?(e.occlusion.scale=n,e.occlusion.lowpassHz=r?.lowpassHz):r&&(e.occlusion={scale:n,lowpassHz:r.lowpassHz})}},Hl=(t,e,r)=>Math.min(r,Math.max(e,t)),gu=t=>Hl(t,0,1);var Es=class{constructor(e){this.trace=e;this.resolve=(e,r,n)=>{let i=Yo(sd(r,e.origin)),s=Vr(n),d=2e4*(1-Math.min(i,s)/Math.max(1,s)*.9),l=this.trace(e.origin,r,void 0,void 0),c=1,f=2e4;l.fraction<1&&(c=.3,f=400);let u=Math.min(d,f);if(c<1||u<2e4)return{gainScale:c,lowpassHz:u}}}};function yu(t){return new Es(t).resolve}var lo=class{constructor(e){this.createElement=e.createElement,this.resolveSource=e.resolveSource??(async r=>r),this.volume=e.volume??1,this.crossfadeDuration=e.crossfadeDuration??1}async playTrack(e){let r=`music/track${e.toString().padStart(2,"0")}.ogg`;return this.play(r)}async play(e,{loop:r=!0,restart:n=!1}={}){if(this.track===e&&this.currentElement){this.currentElement.loop=r,this.cancelFade(),this.fadingElement&&(this.fadingElement.pause(),this.fadingElement=void 0),this.currentElement.volume=this.volume,n&&(this.currentElement.currentTime=0),(this.currentElement.paused||n)&&await this.currentElement.play();return}let i=await this.resolveSource(e);this.cancelFade(),this.fadingElement&&(this.fadingElement.pause(),this.fadingElement=void 0),this.currentElement&&(this.fadingElement=this.currentElement,this.currentElement=void 0);let s=this.createElement();s.src=i,s.loop=r,s.volume=0,s.currentTime=0,s.load();try{await s.play()}catch(a){console.warn(`MusicSystem: Failed to play ${e}`,a),this.fadingElement}this.currentElement=s,this.track=e,this.startCrossfade()}pause(){this.cancelFade(),this.currentElement&&!this.currentElement.paused&&this.currentElement.pause(),this.fadingElement&&(this.fadingElement.pause(),this.fadingElement=void 0)}async resume(){!this.currentElement||!this.currentElement.paused||(await this.currentElement.play(),this.currentElement.volume=this.volume)}stop(){this.cancelFade(),this.currentElement&&(this.currentElement.pause(),this.currentElement.currentTime=0,this.currentElement=void 0),this.fadingElement&&(this.fadingElement.pause(),this.fadingElement=void 0),this.track=void 0}setVolume(e){this.volume=e,this.currentElement&&!this.fadeInterval&&(this.currentElement.volume=e)}getState(){let e=!!(this.currentElement&&!this.currentElement.paused&&!this.currentElement.ended),r=!!this.currentElement?.paused;return{track:this.track,paused:r,playing:e,volume:this.volume}}startCrossfade(){let r=this.crossfadeDuration*1e3/50,n=this.volume/r,i=0,s=this.fadingElement?this.fadingElement.volume:0,a=()=>{let o=!1;this.currentElement&&(i=Math.min(this.volume,i+n),this.currentElement.volume=i,i<this.volume&&(o=!0)),this.fadingElement&&(s=Math.max(0,s-n),this.fadingElement.volume=s,s>0?o=!0:(this.fadingElement.pause(),this.fadingElement=void 0)),o||this.cancelFade()};a(),(this.currentElement&&this.currentElement.volume<this.volume||this.fadingElement)&&(this.fadeInterval=setInterval(a,50))}cancelFade(){this.fadeInterval&&(clearInterval(this.fadeInterval),this.fadeInterval=void 0)}};function Km(t){t.enable(t.DEPTH_TEST),t.depthFunc(t.LEQUAL),t.enable(t.CULL_FACE),t.cullFace(t.BACK),t.enable(t.BLEND),t.blendFuncSeparate(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA)}function $m(t,e,r,n){for(let i of e){let s=t.getExtension(i);if(!s)throw new Error(`Missing required WebGL extension: ${i}`);n.set(i,s)}for(let i of r){let s=t.getExtension(i);s&&n.set(i,s)}}function bu(t,e={}){let{contextAttributes:r,requiredExtensions:n=[],optionalExtensions:i=[]}=e,s=t.getContext("webgl2",r??{antialias:!0});if(!s)throw new Error("WebGL2 not supported or failed to initialize");Km(s);let a=new Map;$m(s,n,i,a);let o=!1,d=new Set,l=new Set,c=u=>{o=!0,u.preventDefault();for(let h of d)h()},f=()=>{o=!1;for(let u of l)u()};return t.addEventListener("webglcontextlost",c),t.addEventListener("webglcontextrestored",f),{gl:s,extensions:a,isLost:()=>o,onLost(u){return d.add(u),()=>d.delete(u)},onRestored(u){return l.add(u),()=>l.delete(u)},dispose(){t.removeEventListener("webglcontextlost",c),t.removeEventListener("webglcontextrestored",f),d.clear(),l.clear(),a.clear()}}}function xu(t,e,r){let n=t.createShader(e);if(!n)throw new Error("Failed to allocate shader");if(t.shaderSource(n,r),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS)){let s=t.getShaderInfoLog(n)??"Unknown shader compile failure";throw t.deleteShader(n),new Error(s)}return n}function Zm(t,e,r,n){let i=t.createProgram();if(!i)throw new Error("Failed to allocate shader program");if(t.attachShader(i,e),t.attachShader(i,r),n)for(let[a,o]of Object.entries(n))t.bindAttribLocation(i,o,a);if(t.linkProgram(i),!t.getProgramParameter(i,t.LINK_STATUS)){let a=t.getProgramInfoLog(i)??"Unknown shader link failure";throw t.deleteProgram(i),new Error(a)}return i}var Te=class t{constructor(e,r,n){this.uniformLocations=new Map;this.attributeLocations=new Map;this.gl=e,this.program=r,this.sourceSize=n}static create(e,r,n){let i=xu(e,e.VERTEX_SHADER,r.vertex),s=xu(e,e.FRAGMENT_SHADER,r.fragment);try{let a=Zm(e,i,s,n),o=r.vertex.length+r.fragment.length;return new t(e,a,o)}finally{e.deleteShader(i),e.deleteShader(s)}}use(){this.gl.useProgram(this.program)}getUniformLocation(e){if(!this.uniformLocations.has(e)){let r=this.gl.getUniformLocation(this.program,e);this.uniformLocations.set(e,r)}return this.uniformLocations.get(e)??null}getAttributeLocation(e){if(!this.attributeLocations.has(e)){let r=this.gl.getAttribLocation(this.program,e);this.attributeLocations.set(e,r)}return this.attributeLocations.get(e)??-1}dispose(){this.gl.deleteProgram(this.program),this.uniformLocations.clear(),this.attributeLocations.clear()}};function _u(t,e,r){return Te.create(t,e,r)}var Ce=class{constructor(e,r=e.STATIC_DRAW,n){this.gl=e,this.target=n??e.ARRAY_BUFFER;let i=e.createBuffer();if(!i)throw new Error("Failed to allocate buffer");this.buffer=i,e.bindBuffer(this.target,this.buffer),e.bufferData(this.target,0,r)}bind(){this.gl.bindBuffer(this.target,this.buffer)}upload(e,r=this.gl.STATIC_DRAW){this.bind(),this.gl.bufferData(this.target,e,r)}update(e,r=0){this.bind(),this.gl.bufferSubData(this.target,r,e)}dispose(){this.gl.deleteBuffer(this.buffer)}},_e=class extends Ce{constructor(e,r=e.STATIC_DRAW){super(e,r,e.ELEMENT_ARRAY_BUFFER)}},Pe=class{constructor(e){this.gl=e;let r=e.createVertexArray();if(!r)throw new Error("Failed to allocate vertex array object");this.vao=r}bind(){this.gl.bindVertexArray(this.vao)}configureAttributes(e,r){this.bind(),r&&r.bind();for(let n of e)this.gl.enableVertexAttribArray(n.index),this.gl.vertexAttribPointer(n.index,n.size,n.type,n.normalized??!1,n.stride??0,n.offset??0),n.divisor!==void 0&&this.gl.vertexAttribDivisor(n.index,n.divisor)}dispose(){this.gl.deleteVertexArray(this.vao)}},Jn=class{constructor(e,r=e.TEXTURE_2D){this.width=0;this.height=0;this.gl=e,this.target=r;let n=e.createTexture();if(!n)throw new Error("Failed to allocate texture");this.texture=n}bind(e=0){this.gl.activeTexture(this.gl.TEXTURE0+e),this.gl.bindTexture(this.target,this.texture)}setParameters(e){this.bind(),e.wrapS!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_S,e.wrapS),e.wrapT!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_T,e.wrapT),e.minFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MIN_FILTER,e.minFilter),e.magFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MAG_FILTER,e.magFilter)}upload(e,r,n){this.width=e,this.height=r,this.uploadImage(0,this.gl.RGBA,e,r,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,n)}uploadImage(e,r,n,i,s,a,o,d){this.bind(),this.gl.texImage2D(this.target,e,r,n,i,s,a,o,d)}dispose(){this.gl.deleteTexture(this.texture)}},ei=class{constructor(e){this.gl=e,this.target=e.TEXTURE_CUBE_MAP;let r=e.createTexture();if(!r)throw new Error("Failed to allocate cubemap texture");this.texture=r}bind(e=0){this.gl.activeTexture(this.gl.TEXTURE0+e),this.gl.bindTexture(this.target,this.texture)}setParameters(e){this.bind(),e.wrapS!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_S,e.wrapS),e.wrapT!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_T,e.wrapT),e.minFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MIN_FILTER,e.minFilter),e.magFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MAG_FILTER,e.magFilter)}uploadFace(e,r,n,i,s,a,o,d,l){this.bind(),this.gl.texImage2D(e,r,n,i,s,a,o,d,l)}dispose(){this.gl.deleteTexture(this.texture)}},co=class{constructor(e){this.gl=e;let r=e.createFramebuffer();if(!r)throw new Error("Failed to allocate framebuffer");this.framebuffer=r}bind(e=this.gl.FRAMEBUFFER){this.gl.bindFramebuffer(e,this.framebuffer)}attachTexture2D(e,r,n=0){this.bind(),this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,e,r.target,r.texture,n)}dispose(){this.gl.deleteFramebuffer(this.framebuffer)}};var Vl=4,Gl=7*Vl,Wl=[{index:0,size:3,type:5126,stride:Gl,offset:0},{index:1,size:2,type:5126,stride:Gl,offset:3*Vl},{index:2,size:2,type:5126,stride:Gl,offset:5*Vl}];function Ym(t,e){return{width:t,height:t,padding:e,data:new Uint8Array(t*t*4),cursorX:0,cursorY:0,rowHeight:0}}function qm(t){let e=t.width*t.height;if(e===0)throw new Error("Invalid lightmap with zero area");let r=t.samples.byteLength/e;if(!Number.isInteger(r)||r<3||r>4)throw new Error("Unsupported lightmap channel count");return r}function jm(t,e,r){let n=qm(r),i=t.width*4,s=e.x+t.padding,a=e.y+t.padding,o=0;for(let d=0;d<r.height;d++){let l=(a+d)*i+s*4;for(let c=0;c<r.width;c++){let f=l+c*4;t.data[f]=r.samples[o],t.data[f+1]=r.samples[o+1],t.data[f+2]=r.samples[o+2],t.data[f+3]=n===4?r.samples[o+3]:255,o+=n}}}function Qm(t,e,r){let n=e.width+r.lightmapPadding*2,i=e.height+r.lightmapPadding*2;if(n>r.atlasSize||i>r.atlasSize)throw new Error("Lightmap too large for atlas");for(let o of t){if(o.cursorX+n>o.width&&(o.cursorX=0,o.cursorY+=o.rowHeight+r.lightmapPadding,o.rowHeight=0),o.cursorY+i>o.height)continue;let d={atlasIndex:t.indexOf(o),x:o.cursorX,y:o.cursorY,width:e.width,height:e.height};return o.cursorX+=n+r.lightmapPadding,o.rowHeight=Math.max(o.rowHeight,i),{placement:d,atlas:o}}let s=Ym(r.atlasSize,r.lightmapPadding);t.push(s);let a={atlasIndex:t.length-1,x:0,y:0,width:e.width,height:e.height};return s.cursorX=n+r.lightmapPadding,s.rowHeight=i,{placement:a,atlas:s}}function uo(t){return t instanceof Float32Array?t:new Float32Array(t)}function Jm(t,e){if(!t){let n=new Uint16Array(e);for(let i=0;i<e;i++)n[i]=i;return n}return t instanceof Uint16Array?t:new Uint16Array(t)}function ep(t,e){let r=new Float32Array(t.length);for(let n=0;n<t.length;n+=2)r[n]=e.offset[0]+t[n]*e.scale[0],r[n+1]=e.offset[1]+t[n+1]*e.scale[1];return r}function tp(t,e){let r=uo(t.vertices),n=uo(t.textureCoords),i=e?ep(uo(t.lightmapCoords??t.textureCoords),e):uo(t.lightmapCoords??new Float32Array(n.length)),s=r.length/3;if(n.length/2!==s)throw new Error("Texture coordinates count mismatch");if(i.length/2!==s)throw new Error("Lightmap coordinates count mismatch");let a=new Float32Array(s*7);for(let o=0;o<s;o++){let d=o*3,l=o*2,c=o*7;a[c]=r[d],a[c+1]=r[d+1],a[c+2]=r[d+2],a[c+3]=n[l],a[c+4]=n[l+1],a[c+5]=i[l],a[c+6]=i[l+1]}return a}function vu(t){let e=[];for(let r=0;r<t.faces.length;r++){let n=t.faces[r];if(n.texInfo<0)continue;let i=t.texInfo[n.texInfo],s=[],a=[],o=[];for(let u=0;u<n.numEdges;u++){let h=t.surfEdges[n.firstEdge+u],m=t.edges[Math.abs(h)],g=h>=0?m.vertices[0]:m.vertices[1],p=t.vertices[g];s.push(p[0],p[1],p[2]);let y=p[0]*i.s[0]+p[1]*i.s[1]+p[2]*i.s[2]+i.sOffset,_=p[0]*i.t[0]+p[1]*i.t[1]+p[2]*i.t[2]+i.tOffset;a.push(y,_),o.push(y,_)}let d=[],l=s.length/3;for(let u=1;u<l-1;u++)d.push(0,u,u+1);let c,f=t.lightMapInfo[r];if(f){let u=1/0,h=-1/0,m=1/0,g=-1/0;for(let v=0;v<a.length;v+=2){let S=a[v],w=a[v+1];S<u&&(u=S),S>h&&(h=S),w<m&&(m=w),w>g&&(g=w)}let p=Math.floor(u/16),y=Math.floor(m/16),_=Math.ceil(h/16)-p+1,x=Math.ceil(g/16)-y+1,b=ma(n,t.lightMaps,f);if(b&&b.length===_*x*3){c={width:_,height:x,samples:b};for(let v=0;v<o.length;v+=2)o[v]=a[v]/16-p+.5,o[v+1]=a[v+1]/16-y+.5}}e.push({vertices:new Float32Array(s),textureCoords:new Float32Array(a),lightmapCoords:new Float32Array(o),indices:new Uint16Array(d),texture:i.texture,surfaceFlags:i.flags,lightmap:c,faceIndex:r})}return e}function wu(t,e,r,n={}){let i=e;if(r&&n.hiddenClassnames&&n.hiddenClassnames.size>0){let c=new Set;for(let f of r.entities.entities)if(f.classname&&n.hiddenClassnames.has(f.classname)){let u=f.properties.model;if(u&&u.startsWith("*")){let h=parseInt(u.substring(1),10);if(!isNaN(h)&&h>=0&&h<r.models.length){let m=r.models[h];for(let g=0;g<m.numFaces;g++)c.add(m.firstFace+g)}}}c.size>0&&(i=e.filter(f=>!c.has(f.faceIndex)))}let s={atlasSize:n.atlasSize??1024,lightmapPadding:n.lightmapPadding??1,hiddenClassnames:n.hiddenClassnames??new Set},a=[],o=new Map;i.forEach((c,f)=>{if(!c.lightmap)return;let{placement:u,atlas:h}=Qm(a,c.lightmap,s);jm(h,u,c.lightmap),o.set(f,{atlasIndex:u.atlasIndex,offset:[(u.x+s.lightmapPadding)/s.atlasSize,(u.y+s.lightmapPadding)/s.atlasSize],scale:[u.width/s.atlasSize,u.height/s.atlasSize]})});let d=a.map(c=>{let f=new Jn(t);return f.setParameters({wrapS:t.CLAMP_TO_EDGE,wrapT:t.CLAMP_TO_EDGE,minFilter:t.LINEAR,magFilter:t.LINEAR}),f.uploadImage(0,t.RGBA,c.width,c.height,0,t.RGBA,t.UNSIGNED_BYTE,c.data),{texture:f,width:c.width,height:c.height,pixels:c.data}});return{surfaces:i.map((c,f)=>{let u=o.get(f),h=tp(c,u),m=Jm(c.indices,h.length/7),g=new Ce(t,t.STATIC_DRAW,t.ARRAY_BUFFER);g.upload(h);let p=new _e(t,t.STATIC_DRAW);p.upload(m);let y=new Pe(t);return y.configureAttributes(Wl,g),{vao:y,vertexBuffer:g,indexBuffer:p,indexCount:m.length,vertexCount:h.length/7,texture:c.texture,surfaceFlags:c.surfaceFlags??_i,lightmap:u,vertexData:h,indexData:m}}),lightmaps:d}}function ti(t){let{normal:e,distance:r}=t,n=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);if(n===0)return t;let i=1/n;return{normal:{x:e.x*i,y:e.y*i,z:e.z*i},distance:r*i}}function Su(t){if(t.length!==16)throw new Error("View-projection matrix must contain 16 elements");let e=t[0],r=t[4],n=t[8],i=t[12],s=t[1],a=t[5],o=t[9],d=t[13],l=t[2],c=t[6],f=t[10],u=t[14],h=t[3],m=t[7],g=t[11],p=t[15];return[ti({normal:{x:h+e,y:m+r,z:g+n},distance:p+i}),ti({normal:{x:h-e,y:m-r,z:g-n},distance:p-i}),ti({normal:{x:h+s,y:m+a,z:g+o},distance:p+d}),ti({normal:{x:h-s,y:m-a,z:g-o},distance:p-d}),ti({normal:{x:h+l,y:m+c,z:g+f},distance:p+u}),ti({normal:{x:h-l,y:m-c,z:g-f},distance:p-u})]}function rp(t,e){return t.normal.x*e.x+t.normal.y*e.y+t.normal.z*e.z+t.distance}function Ls(t,e,r){for(let n of r){let i=n.normal.x>=0?e.x:t.x,s=n.normal.y>=0?e.y:t.y,a=n.normal.z>=0?e.z:t.z;if(rp(n,{x:i,y:s,z:a})<0)return!1}return!0}function Au(t){return t<0}function Mu(t){return-t-1}function Eu(t,e){return t.normal[0]*e.x+t.normal[1]*e.y+t.normal[2]*e.z-t.dist}function np(t,e,r){if(!t||e<0||r<0)return!0;let n=Math.ceil(t.numClusters/8),i=t.clusters[e].pvs,s=Math.floor(r/8),a=1<<r%8;return s<0||s>=n?!1:(i[s]&a)!==0}function ip(t,e){let r={x:t.mins[0],y:t.mins[1],z:t.mins[2]},n={x:t.maxs[0],y:t.maxs[1],z:t.maxs[2]};return Ls(r,n,e)}function Kl(t,e){let r=0;for(;r>=0;){let n=t.nodes[r],i=t.planes[n.planeIndex],a=Eu(i,e)>=0?0:1,o=n.children[a];if(Au(o))return Mu(o);r=o}return-1}function sp(t,e){let r=t.leafs[e],n=[];for(let i=0;i<r.numLeafFaces;i+=1)n.push(t.leafLists.leafFaces[e][i]);return n}function Xl(t,e,r,n,i,s,a){if(Au(e)){let u=Mu(e),h=t.leafs[u];if(!np(t.visibility,i,h.cluster)||!ip(h,n))return;let m={x:(h.mins[0]+h.maxs[0])*.5,y:(h.mins[1]+h.maxs[1])*.5,z:(h.mins[2]+h.maxs[2])*.5},g=m.x-r.x,p=m.y-r.y,y=m.z-r.z,_=-(g*g+p*p+y*y);for(let x of sp(t,u))a.has(x)||(a.add(x),s.push({faceIndex:x,leafIndex:u,sortKey:_}));return}let o=t.nodes[e],d=t.planes[o.planeIndex],l=Eu(d,r),c=l>=0?o.children[0]:o.children[1],f=l>=0?o.children[1]:o.children[0];Ls({x:o.mins[0],y:o.mins[1],z:o.mins[2]},{x:o.maxs[0],y:o.maxs[1],z:o.maxs[2]},n)&&(Xl(t,c,r,n,i,s,a),Xl(t,f,r,n,i,s,a))}function Lu(t,e,r){let n=Kl(t,e),i=n>=0?t.leafs[n].cluster:-1,s=[];return Xl(t,0,e,r,i,s,new Set),s}var ur=32,fo=class{constructor(){this.lights=[]}addLight(e,r){if(e.key!==void 0){let n=this.lights.findIndex(i=>i.key===e.key);if(n!==-1){this.lights[n]=e;return}}this.lights.push(e)}clear(){this.lights=[]}update(e,r=0){if(this.lights=this.lights.filter(n=>n.die>e),r>0)for(let n of this.lights)n.radiusSpeed!==void 0&&n.radiusSpeed!==0&&(n.intensity+=n.radiusSpeed*r,n.intensity<0&&(n.intensity=0))}getActiveLights(){return this.lights}};function ri(t){let e=[];for(let r=0;r<t.length;r+=3){let n=t[r],i=t[r+1],s=t[r+2];e.push(n,i,i,s,s,n)}return t instanceof Uint32Array||Math.max(...e)>65535?new Uint32Array(e):new Uint16Array(e)}var $l=`#version 300 es
|
|
142
142
|
precision highp float;
|
|
143
143
|
|
|
144
144
|
layout(location = 0) in vec3 a_position;
|
|
@@ -583,7 +583,7 @@ void main() {
|
|
|
583
583
|
`;)r++;return s()}let a=r;for(;r<n&&!/\s/.test(t[r])&&t[r]!=="}"&&t[r]!=="{";)r++;return t.substring(a,r)}}}for(;r<n;){let a=s();if(a===null)break;if(a==="{"){let o={};for(;;){let d=r,l=s();if(l==="}"||l===null)break;if(l==="{"){r=d;break}let c=s();if(c===null||c==="}"||c==="{"){c==="}"&&r--,c==="{"&&r--;break}o[l]=c}e.push({classname:o.classname,properties:o})}}return e}function Fh(t){let e="";for(let r of t){e+=`{
|
|
584
584
|
`;let i=Object.keys(r.properties).sort((s,a)=>s==="classname"?-1:a==="classname"?1:s==="origin"?-1:a==="origin"?1:s.localeCompare(a));for(let s of i){let a=r.properties[s];e+=`"${s}" "${a}"
|
|
585
585
|
`}e+=`}
|
|
586
|
-
`}return e}function Bh(t){let e=[],r=[];if(t.properties.classname||e.push('Missing "classname" property'),t.properties.origin){let n=t.properties.origin.split(" ");(n.length!==3||n.some(i=>isNaN(parseFloat(i))))&&e.push(`Invalid origin format: "${t.properties.origin}"`)}return t.properties.angle&&isNaN(parseFloat(t.properties.angle))&&e.push(`Invalid angle format: "${t.properties.angle}"`),{valid:e.length===0,errors:e,warnings:r}}async function Dh(t,e){if(!navigator.gpu)throw new Error("WebGPU is not supported in this environment");let r={powerPreference:e?.powerPreference
|
|
586
|
+
`}return e}function Bh(t){let e=[],r=[];if(t.properties.classname||e.push('Missing "classname" property'),t.properties.origin){let n=t.properties.origin.split(" ");(n.length!==3||n.some(i=>isNaN(parseFloat(i))))&&e.push(`Invalid origin format: "${t.properties.origin}"`)}return t.properties.angle&&isNaN(parseFloat(t.properties.angle))&&e.push(`Invalid angle format: "${t.properties.angle}"`),{valid:e.length===0,errors:e,warnings:r}}async function Dh(t,e){if(!navigator.gpu)throw new Error("WebGPU is not supported in this environment");let r=await navigator.gpu.requestAdapter({powerPreference:e?.powerPreference||"high-performance"});if(!r)throw new Error("No appropriate GPUAdapter found");if(e?.requiredFeatures){for(let l of e.requiredFeatures)if(!r.features.has(l))throw new Error(`Required feature not available: ${l}`)}let n={requiredFeatures:e?.requiredFeatures,requiredLimits:e?.requiredLimits},i=await r.requestDevice(n),s,a="bgra8unorm",o=!0;if(t){if(s=t.getContext("webgpu"),!s)throw new Error("Failed to get WebGPU context from canvas");o=!1,a=navigator.gpu.getPreferredCanvasFormat(),s.configure({device:i,format:a,alphaMode:"opaque"})}let d=new Set;for(let l of r.features)d.add(l);return{adapter:r,device:i,context:s,format:a,features:d,limits:i.limits,isHeadless:o}}function Oh(t){let{features:e,limits:r}=t;return{hasTimestampQuery:e.has("timestamp-query"),hasDepthClipControl:e.has("depth-clip-control"),hasTextureCompressionBC:e.has("texture-compression-bc"),hasTextureCompressionETC2:e.has("texture-compression-etc2"),hasTextureCompressionASTC:e.has("texture-compression-astc"),maxTextureDimension2D:r.maxTextureDimension2D,maxBindGroups:r.maxBindGroups,maxUniformBufferBindingSize:r.maxUniformBufferBindingSize,maxStorageBufferBindingSize:r.maxStorageBufferBindingSize}}function zh(t,e,r,n="rgba8unorm"){let i=typeof GPUTextureUsage<"u"?GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC:17,s=t.createTexture({size:{width:e,height:r,depthOrArrayLayers:1},format:n,usage:i}),a=s.createView();return{texture:s,view:a,width:e,height:r}}async function Nh(t,e){let r=e.width,n=e.height,i=4,s=r*i,a=256,o=Math.max(i*r,Math.ceil(r*i/a)*a),d=o*n,l=typeof GPUBufferUsage<"u"?GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ:9,c=t.createBuffer({size:d,usage:l}),f=t.createCommandEncoder();f.copyTextureToBuffer({texture:e},{buffer:c,bytesPerRow:o},{width:r,height:n,depthOrArrayLayers:1}),t.queue.submit([f.finish()]);let u=typeof GPUMapMode<"u"?GPUMapMode.READ:1;await c.mapAsync(u);let h=c.getMappedRange(),m=new Uint8Array(h),g=new Uint8ClampedArray(r*n*4);if(o===s)g.set(m);else for(let p=0;p<n;p++){let y=p*o,_=p*s;g.set(m.subarray(y,y+s),_)}return c.unmap(),g}function Jb(t){return{init(){t.trace({x:0,y:0,z:0},{x:0,y:0,z:0})},shutdown(){},createMainLoop(e,r){return new Hr(e,r)}}}return Yh(ex);})();
|
|
587
587
|
/*! Bundled license information:
|
|
588
588
|
|
|
589
589
|
pako/dist/pako.esm.mjs:
|